Esempio n. 1
0
void
jpeg_data_set_header_data (JPEGData *data, JPEGMarker marker,
			   unsigned char *buf, unsigned int size)
{
	JPEGSection *section;
	int i;
	
	section = jpeg_data_get_section (data, marker);
	if (!section) {
		jpeg_data_append_section (data);
		for (i = 0; i < data->count - 1; i++) {
			JPEGMarker m = data->sections[i].marker;
			if (m != JPEG_MARKER_SOI &&
			    (m < JPEG_MARKER_APP0 ||
			     m > JPEG_MARKER_APP15)) {
				memmove (&data->sections[i+1],
					 &data->sections[i],
					 sizeof (JPEGSection) *
					 (data->count - i - 1));
				break;
			}
		}
		section = &data->sections[i];
	} else {
		free (section->content.generic.data);
	}

	section->marker = marker;
	section->content.generic.data = malloc (size);
	memcpy (section->content.generic.data, buf, size);
	section->content.generic.size = size;
}
ExifData *
jpeg_data_get_exif_data (JPEGData *data)
{
	JPEGSection *section;

	if (!data)
		return NULL;

	section = jpeg_data_get_section (data, JPEG_MARKER_APP1);
	if (section) {
		exif_data_ref (section->content.app1);
		return (section->content.app1);
	}

	return (NULL);
}
void
jpeg_data_set_exif_data (JPEGData *data, ExifData *exif_data)
{
	JPEGSection *section;

	section = jpeg_data_get_section (data, JPEG_MARKER_APP1);
	if (!section) {
		jpeg_data_append_section (data);
		memmove (&data->sections[2], &data->sections[1],
			 data->count - 2);
		section = &data->sections[1];
	}
	section->marker = JPEG_MARKER_APP1;
	section->content.app1 = exif_data;
	exif_data_ref (exif_data);
}
void
jpeg_data_set_exif_data (JPEGData *data, ExifData *exif_data)
{
	JPEGSection *section;

	if (!data) return;

	section = jpeg_data_get_section (data, JPEG_MARKER_APP1);
	if (!section) {
		jpeg_data_append_section (data);
		if (data->count < 2) return;
		memmove (&data->sections[2], &data->sections[1],
			 sizeof (JPEGSection) * (data->count - 2));
		section = &data->sections[1];
	} else {
		exif_data_unref (section->content.app1);
	}
	section->marker = JPEG_MARKER_APP1;
	section->content.app1 = exif_data;
	exif_data_ref (exif_data);
}