31 #define nullpointerabort(pointer,name,val) \
32 if (pointer==NULL) { printf(name " does not exist\n"); return val; }
35 #define nullpointerabortvoid(pointer,name) \
36 if (pointer==NULL) { printf(name " does not exist\n"); return; }
38 #define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}
41 #define countof(array) (sizeof(array) / sizeof((array)[0]))
50 "Start",
"Comment",
"APPO",
51 "Quantization table",
"Huffman table",
"SOFC0",
52 "SsSeAhAl",
"End of image"
58 printf(
"Entered gpi_jpeg_chunk_new\n");
61 printf(
"Failed to allocate new chunk!\n");
66 mychunk->
data = malloc(length);
73 printf(
"Entered gpi_jpeg_chunk_new_filled\n");
77 printf(
"Filling the chunk data via chunk_new_filled\n");
78 memcpy(mychunk->
data, data, length);
96 for (x=0; x<mychunk->
size; x++)
97 printf(
"%hhX ", mychunk->
data[x]);
105 while(*location<picture->size)
108 if (picture->
data[*location]==0xff)
124 if (picture->
data[*location+1]) {
125 *
id=picture->
data[*location+1];
143 return "Undefined marker";
149 temp=malloc(
sizeof(
jpeg));
157 for (count=0; count<myjpeg->
count; count++)
167 length=(int)(end-start+1);
180 printf(
"Entered gpi_jpeg_add_chunk\n");
192 if (picture->
data[0]!=0xff)
196 lastposition=position;
201 lastposition=position;
205 lastposition=position;
208 while (position<picture->size)
212 lastposition=position;
216 if (position<picture->size)
223 printf(
"There are %i markers\n", myjpeg->
count);
224 for (c=0; c < myjpeg->
count; c++)
237 "\xFF\xE0\x00\x10\x4A\x46\x49\x46" "\x00\x01\x01\x00\x00\x01\x00\x02" "\x00\x00");
246 0xFF, 0xC0, 0x00, 0x11, 0x08, 0x00, 0x80, 0x01,
247 0x40, 0x03, 0x01, 0x11, 0x00, 0x02, 0x21, 0x01, 0x03, 0x11, 0x00
250 if (target==NULL) { printf(
"New SOFC failed allocation\n");
return target; }
251 memcpy(target->
data, sofc_data,
sizeof(sofc_data));
252 target->
data[5] = (height&0xff00) >> 8;
253 target->
data[6] = height&0xff;
254 target->
data[7] = (width&0xff00) >> 8;
255 target->
data[8] = width&0xff;
256 target->
data[11]= vh1;
257 target->
data[12]= q1;
258 target->
data[14]= vh2;
259 target->
data[15]= q2;
260 target->
data[17]= vh3;
261 target->
data[18]= q3;
268 printf(
"About to call gpi_jpeg_chunk_new_filled\n");
270 "\x00\x03\x00\x00\x3F\x00");
271 if (!target)
return NULL;
272 target->
data[6] = huffset1;
273 target->
data[8] = huffset2;
274 target->
data[10] = huffset3;
288 printf(
"%3i ", (*table)[x]);
299 if (!temp)
return NULL;
300 memcpy(temp->
data,
"\xFF\xDB\x00\x43\x01", 5);
302 for (c=z=0; z<8; z++)
304 for (y=0,x=z; y<=z; x--,y++)
306 temp->
data[5+c] = (*table)[x+y*8];
307 temp->
data[5+63-c++] = (*table)[63-x-y*8];
310 for (x=0,y=z; x<=z; x++,y--)
312 temp->
data[5+c] = (*table)[x+y*8];
313 temp->
data[5+63-c++] = (*table)[63-x-y*8];
323 for (c=z=0; z<8; z++)
325 for (y=0,x=z; y<=z; x--,y++)
327 (*table)[63-x-y*8] = qmarker->
data[5+63-c];
328 (*table)[x+y*8] = qmarker->
data[5+c++];
331 for (x=0,y=z; x<=z; x++,y--)
333 (*table)[63-x-y*8] = qmarker->
data[5+63-c];
334 (*table)[x+y*8] = qmarker->
data[5+c++];
341 char vh1,
char vh2,
char vh3,
342 char q1,
char q2,
char q3,
344 char huffset1,
char huffset2,
char huffset3,
357 printf(
"About to make and add the SsSeAhAl marker\n");
364 #ifndef TESTING_JPEG_C
370 for (x=0; x<myjpeg->
count; x++)
376 #ifdef TESTING_JPEG_C
379 0xFF,0xD8, 0xFF,0xE0, 0xff,0xDB, 0xFF,0xC4, 0xFF,0xDA,
380 0xFF,0xC0, 0xff,0xff};
383 2, 3, 4, 5, 6, 7, 8, 9,
384 3, 4, 5, 6, 7, 8, 9, 10,
385 4, 5, 6, 7, 8, 9, 10, 11,
386 5, 6, 7, 8, 9, 10, 11, 12,
387 6, 7, 8, 9, 10, 11, 12, 13,
388 7, 8, 9, 10, 11, 12, 13, 14,
389 8, 9, 10, 11, 12, 13, 14, 15,
390 9, 10, 11, 12, 13, 14, 15, 16};
398 printf(
"Print the test quantization table\n");
402 picture->
data=testdata;
403 picture->
size=
sizeof(testdata);
404 printf(
"testdata size is %i\n",picture->
size);
406 printf(
"Call jpeg_parse!!!!!!!!!!!!!!!!!!!!!!!\n");
409 printf(
"\nPrint the jpeg table\n");
411 printf(
"\nCall gpi_jpeg_destroy\n");
417 printf(
"gpi_jpeg_chunk_new and gpi_jpeg_chunk_destroy tests\n");
419 for (x=0; x<10; x++) picture->
data[x]=x;
420 for (x=0; x<10; x++) printf(
"%hX ",picture->
data[x]);
int gp_file_append(CameraFile *file, const char *data, unsigned long int size)
int gp_file_set_mime_type(CameraFile *file, const char *mime_type)
int gp_file_set_name(CameraFile *file, const char *name)
Abstracted gphoto2 file operations.
char gpi_jpeg_findactivemarker(char *id, int *location, chunk *picture)
#define CHECK_RESULT(result)
chunk * gpi_jpeg_chunk_new(int length)
char gpi_jpeg_write(CameraFile *file, const char *filename, jpeg *myjpeg)
chunk * gpi_jpeg_chunk_new_filled(int length, char *data)
chunk * gpi_jpeg_make_SOFC(int width, int height, char vh1, char vh2, char vh3, char q1, char q2, char q3)
char gpi_jpeg_findff(int *location, chunk *picture)
const jpegmarker JPEG_MARKERS[]
chunk * gpi_jpeg_makeSsSeAhAl(int huffset1, int huffset2, int huffset3)
void gpi_jpeg_chunk_destroy(chunk *mychunk)
void gpi_jpeg_print_quantization_table(jpeg_quantization_table *table)
#define nullpointerabortvoid(pointer, name)
#define nullpointerabort(pointer, name, val)
char * gpi_jpeg_markername(unsigned int c)
void gpi_jpeg_add_chunk(jpeg *myjpeg, chunk *source)
void gpi_jpeg_destroy(jpeg *myjpeg)
void gpi_jpeg_parse(jpeg *myjpeg, chunk *picture)
chunk * gpi_jpeg_make_quantization(const jpeg_quantization_table *table, char number)
chunk * gpi_jpeg_make_start()
const char * JPEG_MARKERNAMES[]
void gpi_jpeg_chunk_print(chunk *mychunk)
jpeg_quantization_table * gpi_jpeg_quantization2table(chunk *qmarker)
void gpi_jpeg_add_marker(jpeg *myjpeg, chunk *picture, int start, int end)
jpeg * gpi_jpeg_header(int width, int height, char vh1, char vh2, char vh3, char q1, char q2, char q3, const jpeg_quantization_table *quant1, const jpeg_quantization_table *quant2, char huffset1, char huffset2, char huffset3, chunk *huff1, chunk *huff2, chunk *huff3, chunk *huff4)
void gpi_jpeg_print(jpeg *myjpeg)
char jpeg_quantization_table[64]
struct chunk * marker[20]