Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor bitmap support #85

Open
noelwelsh opened this issue Nov 22, 2019 · 0 comments
Open

Refactor bitmap support #85

noelwelsh opened this issue Nov 22, 2019 · 0 comments

Comments

@noelwelsh
Copy link
Contributor

noelwelsh commented Nov 22, 2019

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 the F in the algebra but in the current implementation this basically means Picture). 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 Bitmap algebra 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 Bitmap algebra so that the main method reflects the possibility of failure (e.g. returns an IO, Either, or a Try. Probably an Either is better as it doesn't fix the error to be an Exception, and so works across different backends with different error handling strategies. Could abstract over error handling with the MonadError type class but I'm not convinced it's warranted.) Probably returning an IO is best as that is used in other parts of Doodle.
  • add some utilities to Bitmap to load a bitmap when you don't care about errors.
  • backends should implement ToPicture to convert a particular bitmap type into the backend specific Picture type.

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant