| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 5 | <title>libjpeg Interoperability: libiptcdata Reference Manual</title> |
| 6 | <meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> |
| 7 | <link rel="home" href="index.html" title="libiptcdata Reference Manual"> |
| 8 | <link rel="up" href="index.html" title="libiptcdata Reference Manual"> |
| 9 | <link rel="prev" href="iptc-overview.html" title="libiptcdata Overview"> |
| 10 | <link rel="next" href="iptc-i18n.html" title="Internationalization"> |
| 11 | <meta name="generator" content="GTK-Doc V1.28 (XML mode)"> |
| 12 | <link rel="stylesheet" href="style.css" type="text/css"> |
| 13 | </head> |
| 14 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 15 | <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle"> |
| 16 | <td width="100%" align="left" class="shortcuts"></td> |
| 17 | <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td> |
| 18 | <td><img src="up-insensitive.png" width="16" height="16" border="0"></td> |
| 19 | <td><a accesskey="p" href="iptc-overview.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td> |
| 20 | <td><a accesskey="n" href="iptc-i18n.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td> |
| 21 | </tr></table> |
| 22 | <div class="refentry"> |
| 23 | <a name="iptc-libjpeg"></a><div class="titlepage"></div> |
| 24 | <div class="refnamediv"><table width="100%"><tr> |
| 25 | <td valign="top"> |
| 26 | <h2><span class="refentrytitle">libjpeg Interoperability</span></h2> |
| 27 | <p>libjpeg Interoperability — an example of using libiptcdata together with libjpeg</p> |
| 28 | </td> |
| 29 | <td class="gallery_image" valign="top" align="right"></td> |
| 30 | </tr></table></div> |
| 31 | <div class="refsect1"> |
| 32 | <a name="jpeg-reading"></a><h2>Reading IPTC data from a file parsed with libjpeg</h2> |
| 33 | <p> |
| 34 | libjpeg is a popular library for parsing jpeg files because |
| 35 | it is free, fast, and widely available on many platforms. It |
| 36 | is easy to combine libiptcdata with code that already uses |
| 37 | libjpeg to decompress a jpeg file. The following example shows |
| 38 | how to extract IPTC data while a file is being parsed by libjpeg: |
| 39 | </p> |
| 40 | <pre class="programlisting"> |
| 41 | IptcData *d; |
| 42 | struct jpeg_decompress_struct cinfo; |
| 43 | struct jpeg_error_mgr jerr; |
| 44 | FILE * infile; |
| 45 | int ps3_pos = 0, ps3_len; |
| 46 | jpeg_saved_marker_ptr marker; |
| 47 | |
| 48 | infile = fopen (path, "r"); |
| 49 | if (!infile) |
| 50 | return -1; |
| 51 | |
| 52 | /* decompress the jpeg */ |
| 53 | cinfo.err = jpeg_std_error (&jerr); |
| 54 | jpeg_create_decompress (&cinfo); |
| 55 | jpeg_stdio_src (&cinfo, infile); |
| 56 | /* be sure to save the APP13 header, which might contain IPTC data */ |
| 57 | jpeg_save_markers (&cinfo, JPEG_APP0+13, 0xffff); |
| 58 | jpeg_read_header (&cinfo, TRUE); |
| 59 | |
| 60 | /* look for an IPTC header */ |
| 61 | marker = cinfo.marker_list; |
| 62 | while (marker) { |
| 63 | if (marker->marker == JPEG_APP0+13) { |
| 64 | ps3_pos = iptc_jpeg_ps3_find_iptc (marker->data, |
| 65 | marker->data_length, &ps3_len); |
| 66 | if (ps3_pos > 0) |
| 67 | break; |
| 68 | } |
| 69 | marker = marker->next; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | if (!marker) { |
| 74 | /* clean up if we don't find IPTC data */ |
| 75 | jpeg_destroy_decompress (&cinfo); |
| 76 | fclose (infile); |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | /* parse the IPTC data */ |
| 81 | d = iptc_data_new_from_data (marker->data + ps3_pos, ps3_len); |
| 82 | |
| 83 | /* clean up */ |
| 84 | jpeg_destroy_decompress (&cinfo); |
| 85 | fclose (infile); |
| 86 | </pre> |
| 87 | </div> |
| 88 | </div> |
| 89 | <div class="footer"> |
| 90 | <hr>Generated by GTK-Doc V1.28</div> |
| 91 | </body> |
| 92 | </html> |