From e54c8b5feb5d940fcd0120f323bfd8dd513a85da Mon Sep 17 00:00:00 2001 From: Nathan Stenzel Date: Wed, 12 Sep 2001 02:36:12 +0000 Subject: [PATCH] Completed more of the code. Fixed some problems. Added debugging output via a printf and a commented out gp_debug_printf This should be safe enough to be put in the Makefile now git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2232 67ed7778-7388-44ab-90cf-0a291f65f57c --- libgphoto2/jpeg.c | 54 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/libgphoto2/jpeg.c b/libgphoto2/jpeg.c index ac2ec3438..07faeb47c 100644 --- a/libgphoto2/jpeg.c +++ b/libgphoto2/jpeg.c @@ -1,32 +1,49 @@ /* This code was written by Nathan Stenzel for gphoto */ /* GPL */ +/* It might be safe enough to put this into the Makefile now */ /* jpeg_add_marker need to have the data copying code put in. memcpy? */ -struct chunk { +#include + +struct chunk{ long size; -char *data; +unsigned char *data; }; +chunk_destroy(struct chunk *mychunk) +{ + mychunk->size=0; + free(mychunk->data); +} + struct jpeg { int count; -chunk marker[20]; /* I think this should be big enough */ +struct chunk marker[20]; /* I think this should be big enough */ }; -jpeg_init(jpeg *myjpeg) +jpeg_init(struct jpeg *myjpeg) { -count=0; + myjpeg->count=0; +} + +jpeg_destroy(struct jpeg *myjpeg) +{ + int count; + for (count=0; countcount; count++) + chunk_destroy(&(myjpeg->marker[count])); + myjpeg->count=0; } enum jpegmarker {start, APPO, quantization, huffman, SsSeAhAl}; const char markers[] = { start, APPO, quantization, huffman, SsSeAhAl -} +}; -char jpeg_findamarker(char *id, long *location, chunk picture, long start) { +char jpeg_findamarker(char *id, long *location, struct chunk picture, long start) { long position; char x; - for (position=start; positionmarker[myjpeg->count].size=length; + myjpeg->marker[myjpeg->count].data = (char *)malloc(length); // copy info to marker chunk here - - myjpeg.count++; + memcpy(myjpeg->marker[myjpeg->count].data, picture.data+location, length); +// gp_debug_printf (GP_DEBUG_LOW, "jpeg.c", "JPEG marker 0xFF %c", picture.data[location+1]); + printf ("JPEG marker 0xFF %c", picture.data[location+1]); + myjpeg->count++; } -char jpeg_parse(jpeg *myjpeg, chunk picture) +char jpeg_parse(struct jpeg *myjpeg, struct chunk picture) { long position=0; - while (jpeg_findactivemarker(&position, picture, position)) + char id; + while (jpeg_findactivemarker(&id, &position, picture, position)) jpeg_add_marker(myjpeg, picture, position); /* add the last marker now */ jpeg_add_marker(myjpeg, picture, position);