I’m trying to model a data Photo and wondering what type to use for the image data:
data Photo =
Photo
{ photoUploaderId :: AccountId
, photoWidth :: Int
, photoHeight :: Int
, photoData :: ByteString
}
I’m using Data.ByteString here. Are there any better choice?
Background: I’m going to store the image data in a database, and retrieve and send it over a network connection. On inserting the photo into the database for the first time, I may need to manipulate it a bit, like scaling, etc.
If you’re going to access arbitrary pixels of photos use an unboxed array. It will give you O(1) indexing and a minimal space overhead.
UArray (Int, Int) Word32should be what you are looking for. Remeber that unboxed arrays are strict. If you’re looking for non-strictness use anArray, but keep in mind that values of pixels will be boxed which degrades the performance.Another types of similar capabilities and worth considering are vectors.
On the other hand, if you are not going to manipulate pixels and you’ll treat the image just as a blob,
ByteStringis a good choice. That’s what it was designed for: blobs of binary data.In summary: manipulate using either
ArrayorVector, store and transfer asByteString.