+#include <stdio.h>
#include <string.h>
#include <netpbm/pnm.h>
+#include <jpeglib.h>
#include "kds_s2000w_image_converter.h"
#define SPACE 0x0a
#define SPACE_WIDTH_HEIGHT 0x20
#define MAXBUFFER 6
+#define RGB 3
int _kds_s2000w_image_converter_find_char(blobdata* image, int start, const char cfind)
{
void kds_s2000w_image_converter_jpg_to_pnm(blobdata* in, blobdata* out, int depth)
{
- return;
+ FILE* jpeg_stream = fmemopen(in->data, in->size, "r");
+
+ struct jpeg_decompress_struct cinfo;
+ struct jpeg_error_mgr err;
+
+ cinfo.err = jpeg_std_error(&err);
+ jpeg_create_decompress(&cinfo);
+ jpeg_stdio_src(&cinfo, jpeg_stream);
+ jpeg_read_header(&cinfo, TRUE);
+ jpeg_start_decompress(&cinfo);
+
+ int decompress_size = RGB * cinfo.output_width * cinfo.output_height;
+ unsigned char* decompress_data = malloc(sizeof(unsigned char) * decompress_size);
+
+ unsigned char* row = NULL;
+ while (cinfo.output_scanline < cinfo.output_height) {
+ row = &decompress_data[cinfo.output_width * cinfo.output_scanline];
+ jpeg_read_scanlines(&cinfo, &row, 1);
+ }
+ fclose(jpeg_stream);
+
+ xel** pixels = malloc(sizeof(xel*) * cinfo.output_height);
+ for (int i = 0; i < cinfo.output_height; i++) {
+ pixels[i] = malloc(sizeof(xel) * cinfo.output_width);
+ }
+
+ int currwidth = 0;
+ int currheight = 0;
+ for (int i = 0; i < decompress_size; i += RGB) {
+ pixels[currheight][currwidth].r = decompress_data[i];
+ pixels[currheight][currwidth].g = decompress_data[i + 1];
+ pixels[currheight][currwidth].b = decompress_data[i + 2];
+ currwidth++;
+ if (currwidth >= cinfo.output_width) {
+ currwidth = 0;
+ currheight++;
+ }
+ }
+
+ char* outdata = (char*) out->data;
+ FILE* pnm_stream = open_memstream(&outdata, &out->size);
+ pnm_writepnm(pnm_stream, pixels, cinfo.output_width, cinfo.output_height, PNM_MAXMAXVAL, PPM_FORMAT, 0);
+ fclose(pnm_stream);
+
+ jpeg_finish_decompress(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
}
void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out)