Bitmap* decodeJpg(unsigned char* in,u64 size)
{
Bitmap* result;
struct jpeg_decompress_struct cinfo;
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, in, size);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
int width = cinfo.output_width;
int height = cinfo.output_height;
int row_bytes = width * 3;
u8* bgr_buffer = (u8*) malloc(width*height*3);
while (cinfo.output_scanline < cinfo.output_height) {
u8* buffer_array[1];
buffer_array[0] = bgr_buffer + (cinfo.output_scanline) * row_bytes;
jpeg_read_scanlines(&cinfo, buffer_array, 1);
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
result->bitperpixel = 24;
result->width = width;
result->height = height;
result->pixels = bgr_buffer;
return result;
}