interface JPGLib {
int loadImage(byte fdata[], PixelMap b)
byte[] saveImage(PixelMap b)
}
component provides ImageEncoder:jpg requires native JPGLib lib {
PixelMap map
ImageEncoder:ImageEncoder()
{
}
PixelMap ImageEncoder:getPixels()
{
return map
}
void ImageEncoder:setPixels(store PixelMap pm)
{
map = pm
}
bool ImageEncoder:loadImage(File fd)
{
map = new PixelMap(new WH())
int pos = fd.getPos()
byte fdata[] = fd.read(fd.getSize() - pos)
int flen = lib.loadImage(fdata, map)
if (flen == 0)
throw new Exception("failed to load PNG")
return true
}
bool ImageEncoder:saveImage(File fd)
{
if (map == null || map.size == null) throw new Exception("no image data to encode")
if (map.size.width == 0 || map.size.height == 0) throw new Exception("image data has a zero dimension")
byte fdata[] = lib.saveImage(map)
if (fdata == null)
throw new Exception("failed to encode PNG")
fd.write(fdata)
return true
}
}To propose a new revision to this entity, use dana source put -uc your/new/version.dn -n media.image.ImageEncoder:jpg -m "reason for update" -u yourUsername
Version 2 (this version) by barry
Notes for this version: Updates to prepare for upcoming compiler strictness changes in function parameter qualifier equivalence