1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
<refentry id="iptc-libjpeg" revision="6 Sep 2005">
<refmeta>
<refentrytitle>libjpeg Interoperability</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>libiptcdata Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>libjpeg Interoperability</refname>
<refpurpose>an example of using libiptcdata together with libjpeg</refpurpose>
</refnamediv>
<refsect1 id="jpeg-reading">
<title>Reading IPTC data from a file parsed with libjpeg</title>
<para>
libjpeg is a popular library for parsing jpeg files because
it is free, fast, and widely available on many platforms. It
is easy to combine libiptcdata with code that already uses
libjpeg to decompress a jpeg file. The following example shows
how to extract IPTC data while a file is being parsed by libjpeg:
</para>
<programlisting>
IptcData *d;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * infile;
int ps3_pos = 0, ps3_len;
jpeg_saved_marker_ptr marker;
infile = fopen (path, "r");
if (!infile)
return -1;
/* decompress the jpeg */
cinfo.err = jpeg_std_error (&jerr);
jpeg_create_decompress (&cinfo);
jpeg_stdio_src (&cinfo, infile);
/* be sure to save the APP13 header, which might contain IPTC data */
jpeg_save_markers (&cinfo, JPEG_APP0+13, 0xffff);
jpeg_read_header (&cinfo, TRUE);
/* look for an IPTC header */
marker = cinfo.marker_list;
while (marker) {
if (marker->marker == JPEG_APP0+13) {
ps3_pos = iptc_jpeg_ps3_find_iptc (marker->data,
marker->data_length, &ps3_len);
if (ps3_pos > 0)
break;
}
marker = marker->next;
}
if (!marker) {
/* clean up if we don't find IPTC data */
jpeg_destroy_decompress (&cinfo);
fclose (infile);
return 0;
}
/* parse the IPTC data */
d = iptc_data_new_from_data (marker->data + ps3_pos, ps3_len);
/* clean up */
jpeg_destroy_decompress (&cinfo);
fclose (infile);
</programlisting>
</refsect1>
</refentry>
|