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
This commit is contained in:
@@ -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 <stdio.h>
|
||||
|
||||
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; count<myjpeg->count; 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; position<picture.length; position++)
|
||||
for (position=start; position<picture.size; position++)
|
||||
if (picture.data[position]==0xff)
|
||||
{
|
||||
*id=picture.data[position+1];
|
||||
@@ -36,7 +53,7 @@ char jpeg_findamarker(char *id, long *location, chunk picture, long start) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char jpeg_findactivemarker(char *id, long *location, chunk picture, long start) {
|
||||
char jpeg_findactivemarker(char *id, long *location, struct chunk picture, long start) {
|
||||
long position=start;
|
||||
char temp=*id;
|
||||
while(jpeg_findamarker(&temp, &position, picture, position))
|
||||
@@ -48,26 +65,29 @@ char jpeg_findactivemarker(char *id, long *location, chunk picture, long start)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void jpeg_add_marker(jpeg *myjpeg, chunk picture, long location)
|
||||
void jpeg_add_marker(struct jpeg *myjpeg, struct chunk picture, long location)
|
||||
{
|
||||
long length;
|
||||
long position=location;
|
||||
long position = location;
|
||||
char id=0;
|
||||
if (jpeg_findactivemarker(&id, &position, picture, position))
|
||||
length=position-location+1;
|
||||
else
|
||||
length=picture.size-location+1;
|
||||
myjpeg.marker[count].size=length;
|
||||
myjpeg.marker[count].data = malloc(length);
|
||||
myjpeg->marker[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);
|
||||
|
||||
Reference in New Issue
Block a user