doodle
doodle copied to clipboard
Refactor bitmap support
The Bitmap algebra provides some basic support for loading bitmaps but it is limited in the following ways:
- It doesn't represent that loading a bitmap can fail for various reasons (file not found, incorrect format, etc.)
- It loads bitmaps as a
Picture(strictly speaking, it is loaded as theFin the algebra but in the current implementation this basically meansPicture). This means we don't have a separate type representing bitmaps, which is a problem because bitmaps are distinct from the vector graphics model of the rest of Doodle and we can do interesting operations on them that don't make sense on vector images and vice versa.
What it should do instead:
- the
Bitmapalgebra should be parameterized by at least one type, the type of bitmaps, and possibly by an effect type. I don't think we've abstracted over effect types elsewhere in Doodle so the effect type can be ignored if it adds too much complexity. - change the
Bitmapalgebra so that the main method reflects the possibility of failure (e.g. returns anIO,Either, or aTry. ~~Probably anEitheris better as it doesn't fix the error to be anException, and so works across different backends with different error handling strategies. Could abstract over error handling with theMonadErrortype class but I'm not convinced it's warranted.)~~ Probably returning anIOis best as that is used in other parts of Doodle. - add some utilities to
Bitmapto load a bitmap when you don't care about errors. - backends should implement
ToPictureto convert a particular bitmap type into the backend specificPicturetype.
Concretely, we're looking at an interface like
trait LoadBitmap[Specifier, Bitmap] {
def load(specifier: Specifier): IO[Bitmap]
}
where Specifier is the type of information that we used to specify where to find a bitmap (e.g. File on the JVM, String on the browser) and Bitmap is the type of the resulting bitmap (BufferedImage on the JVM.) Backend specific implementations could provide their own utility methods that augment the above.
Here are some links to relevant backend information:
Please use email, not issues, for GSoC communication. I can't manage it if everything is spread out across lots of different issues.