34 #include "loaders/SILLYJPGImageLoader.h" 36 #ifndef SILLY_OPT_INLINE 38 #include "loaders/SILLYJPGImageLoader.icpp" 41 #include "loaders/SILLYJPGImageContext.h" 46 JPGImageLoader::JPGImageLoader()
47 : ImageLoader(
"JPG Image Loader based on jpeg-6b")
51 JPGImageLoader::~JPGImageLoader()
63 if (setjmp(jpg->setjmp_buffer))
68 jpeg_read_header(&(jpg->cinfo), TRUE);
69 if (! jpeg_start_decompress(&(jpg->cinfo)))
76 if (jpg->cinfo.output_components != 1 && jpg->cinfo.output_components != 3)
78 printf(
"JPG unsupported bpp: %d\n", jpg->cinfo.output_components );
79 jpeg_finish_decompress(& jpg->cinfo);
83 formatSource = PF_RGB;
97 int row_stride = jpg->getWidth() * jpg->cinfo.output_components;
98 JSAMPARRAY buffer = (* jpg->cinfo.mem->alloc_sarray)(
99 (j_common_ptr)(& jpg->cinfo),
103 bool finished =
true;
104 size_t height = jpg->getHeight();
105 size_t width = jpg->getWidth();
108 while(jpg->cinfo.output_scanline < height)
110 int num_rows = jpeg_read_scanlines(& jpg->cinfo, buffer, 1);
113 jpeg_finish_decompress(& jpg->cinfo);
119 const byte alpha = 0xff;
122 if (jpg->cinfo.output_components == 1)
124 for(
size_t i = 0 ; i < width * num_rows ; ++i)
136 for(
size_t i = 0 ; i < width * num_rows ; ++i)
145 jpeg_finish_decompress(& jpg->cinfo);
147 if (origin == PO_BOTTOM_LEFT)
PixelOrigin
List all pixel origin supported.
unsigned char byte
Typename for a byte.
This is an abstract class used to provide data to the loader.
ImageContext * loadHeader(PixelFormat &header, DataSource *data)
Parse the header of the image and fill the header struct.
bool loadImageData(PixelOrigin origin, DataSource *data, ImageContext *context)
Parse the pixels data of the image and fill the header struct.
void setNextPixel(byte red, byte green, byte bleu, byte alpha)
Set the next pixel of the image.
PixelFormat
List all pixel format supported.
bool flipVertically()
Flip pixel ordering.
Simple Image Loading LibrarY namespace.
Store the data needed by an ImageLoader object during the parsing of an image.
Image Context for JPG image loader.