< prev index next >

src/java.desktop/share/native/libjavajpeg/imageioJPEG.c

Print this page




1593 
1594 /*
1595  * For EXIF images, the APP1 will appear immediately after the SOI,
1596  * so it's safe to only look at the first marker in the list.
1597  * (see http://www.exif.org/Exif2-2.PDF, section 4.7, page 58)
1598  */
1599 #define IS_EXIF(c) \
1600     (((c)->marker_list != NULL) && ((c)->marker_list->marker == JPEG_APP1))
1601 
1602 JNIEXPORT jboolean JNICALL
1603 Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader
1604     (JNIEnv *env,
1605      jobject this,
1606      jlong ptr,
1607      jboolean clearFirst,
1608      jboolean reset) {
1609 
1610     int ret;
1611     int h_samp0, h_samp1, h_samp2;
1612     int v_samp0, v_samp1, v_samp2;

1613     jboolean retval = JNI_FALSE;
1614     imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr);
1615     j_decompress_ptr cinfo;
1616     struct jpeg_source_mgr *src;
1617     sun_jpeg_error_ptr jerr;
1618     jbyteArray profileData = NULL;
1619 
1620     if (data == NULL) {
1621         JNU_ThrowByName(env,
1622                         "java/lang/IllegalStateException",
1623                         "Attempting to use reader after dispose()");
1624         return JNI_FALSE;
1625     }
1626 
1627     cinfo = (j_decompress_ptr) data->jpegObj;
1628     src = cinfo->src;
1629 
1630     /* Establish the setjmp return context for sun_jpeg_error_exit to use. */
1631     jerr = (sun_jpeg_error_ptr) cinfo->err;
1632 


1694              *  - we got JFIF image
1695              *     Must be YCbCr (see http://www.w3.org/Graphics/JPEG/jfif3.pdf, page 2)
1696              *  - we got EXIF image
1697              *     Must be YCbCr (see http://www.exif.org/Exif2-2.PDF, section 4.7, page 63)
1698              *  - something else
1699              *     Apply heuristical rules to identify actual colorspace.
1700              */
1701 
1702             if (cinfo->saw_Adobe_marker) {
1703                 if (cinfo->Adobe_transform != 1) {
1704                     /*
1705                      * IJG guesses this is YCbCr and emits a warning
1706                      * We would rather not guess.  Then the user knows
1707                      * To read this as a Raster if at all
1708                      */
1709                     cinfo->jpeg_color_space = JCS_UNKNOWN;
1710                     cinfo->out_color_space = JCS_UNKNOWN;
1711                 }
1712             } else if (!cinfo->saw_JFIF_marker && !IS_EXIF(cinfo)) {
1713                 /*
1714                  * IJG assumes all unidentified 3-channels are YCbCr.
1715                  * We assume that only if the second two channels are
1716                  * subsampled (either horizontally or vertically).  If not,
1717                  * we assume RGB.
1718                  *
1719                  * 4776576: Some digital cameras output YCbCr JPEG images
1720                  * that do not contain a JFIF APP0 marker but are only
1721                  * vertically subsampled (no horizontal subsampling).
1722                  * We should only assume this is RGB data if the subsampling
1723                  * factors for the second two channels are the same as the
1724                  * first (check both horizontal and vertical factors).
1725                  */
1726                 h_samp0 = cinfo->comp_info[0].h_samp_factor;
1727                 h_samp1 = cinfo->comp_info[1].h_samp_factor;
1728                 h_samp2 = cinfo->comp_info[2].h_samp_factor;
1729 
1730                 v_samp0 = cinfo->comp_info[0].v_samp_factor;
1731                 v_samp1 = cinfo->comp_info[1].v_samp_factor;
1732                 v_samp2 = cinfo->comp_info[2].v_samp_factor;
1733 
1734                 if ((h_samp1 == h_samp0) && (h_samp2 == h_samp0) &&
1735                     (v_samp1 == v_samp0) && (v_samp2 == v_samp0))





1736                 {
1737                     cinfo->jpeg_color_space = JCS_RGB;
1738                     /* output is already RGB, so it stays the same */
1739                 }
1740             }
1741             break;
1742 #ifdef YCCALPHA
1743         case JCS_YCC:
1744             cinfo->out_color_space = JCS_YCC;
1745             break;
1746 #endif
1747         case JCS_YCCK:
1748             if ((cinfo->saw_Adobe_marker) && (cinfo->Adobe_transform != 2)) {
1749                 /*
1750                  * IJG guesses this is YCCK and emits a warning
1751                  * We would rather not guess.  Then the user knows
1752                  * To read this as a Raster if at all
1753                  */
1754                 cinfo->jpeg_color_space = JCS_UNKNOWN;
1755                 cinfo->out_color_space = JCS_UNKNOWN;




1593 
1594 /*
1595  * For EXIF images, the APP1 will appear immediately after the SOI,
1596  * so it's safe to only look at the first marker in the list.
1597  * (see http://www.exif.org/Exif2-2.PDF, section 4.7, page 58)
1598  */
1599 #define IS_EXIF(c) \
1600     (((c)->marker_list != NULL) && ((c)->marker_list->marker == JPEG_APP1))
1601 
1602 JNIEXPORT jboolean JNICALL
1603 Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader
1604     (JNIEnv *env,
1605      jobject this,
1606      jlong ptr,
1607      jboolean clearFirst,
1608      jboolean reset) {
1609 
1610     int ret;
1611     int h_samp0, h_samp1, h_samp2;
1612     int v_samp0, v_samp1, v_samp2;
1613     int cid0, cid1, cid2;
1614     jboolean retval = JNI_FALSE;
1615     imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr);
1616     j_decompress_ptr cinfo;
1617     struct jpeg_source_mgr *src;
1618     sun_jpeg_error_ptr jerr;
1619     jbyteArray profileData = NULL;
1620 
1621     if (data == NULL) {
1622         JNU_ThrowByName(env,
1623                         "java/lang/IllegalStateException",
1624                         "Attempting to use reader after dispose()");
1625         return JNI_FALSE;
1626     }
1627 
1628     cinfo = (j_decompress_ptr) data->jpegObj;
1629     src = cinfo->src;
1630 
1631     /* Establish the setjmp return context for sun_jpeg_error_exit to use. */
1632     jerr = (sun_jpeg_error_ptr) cinfo->err;
1633 


1695              *  - we got JFIF image
1696              *     Must be YCbCr (see http://www.w3.org/Graphics/JPEG/jfif3.pdf, page 2)
1697              *  - we got EXIF image
1698              *     Must be YCbCr (see http://www.exif.org/Exif2-2.PDF, section 4.7, page 63)
1699              *  - something else
1700              *     Apply heuristical rules to identify actual colorspace.
1701              */
1702 
1703             if (cinfo->saw_Adobe_marker) {
1704                 if (cinfo->Adobe_transform != 1) {
1705                     /*
1706                      * IJG guesses this is YCbCr and emits a warning
1707                      * We would rather not guess.  Then the user knows
1708                      * To read this as a Raster if at all
1709                      */
1710                     cinfo->jpeg_color_space = JCS_UNKNOWN;
1711                     cinfo->out_color_space = JCS_UNKNOWN;
1712                 }
1713             } else if (!cinfo->saw_JFIF_marker && !IS_EXIF(cinfo)) {
1714                 /*
1715                  * In the absence of certain markers, IJG has interpreted
1716                  * component id's of [1,2,3] as meaning YCbCr.We follow that
1717                  * interpretation, which is additionally described in the Image
1718                  * I/O JPEG metadata spec.If that condition is not met here the
1719                  * next step will be to examine the subsampling factors, if
1720                  * there is any difference in subsampling factors we also assume
1721                  * YCbCr, only if both horizontal and vertical subsampling
1722                  * is same we assume JPEG color space as RGB.
1723                  * This is also described in the Image I/O JPEG metadata spec.


1724                  */
1725                 h_samp0 = cinfo->comp_info[0].h_samp_factor;
1726                 h_samp1 = cinfo->comp_info[1].h_samp_factor;
1727                 h_samp2 = cinfo->comp_info[2].h_samp_factor;
1728 
1729                 v_samp0 = cinfo->comp_info[0].v_samp_factor;
1730                 v_samp1 = cinfo->comp_info[1].v_samp_factor;
1731                 v_samp2 = cinfo->comp_info[2].v_samp_factor;
1732 
1733                 cid0 = cinfo->comp_info[0].component_id;
1734                 cid1 = cinfo->comp_info[1].component_id;
1735                 cid2 = cinfo->comp_info[2].component_id;
1736 
1737                 if ((!(cid0 == 1 && cid1 == 2 && cid2 == 3)) &&
1738                     ((h_samp1 == h_samp0) && (h_samp2 == h_samp0) &&
1739                     (v_samp1 == v_samp0) && (v_samp2 == v_samp0)))
1740                 {
1741                     cinfo->jpeg_color_space = JCS_RGB;
1742                     /* output is already RGB, so it stays the same */
1743                 }
1744             }
1745             break;
1746 #ifdef YCCALPHA
1747         case JCS_YCC:
1748             cinfo->out_color_space = JCS_YCC;
1749             break;
1750 #endif
1751         case JCS_YCCK:
1752             if ((cinfo->saw_Adobe_marker) && (cinfo->Adobe_transform != 2)) {
1753                 /*
1754                  * IJG guesses this is YCCK and emits a warning
1755                  * We would rather not guess.  Then the user knows
1756                  * To read this as a Raster if at all
1757                  */
1758                 cinfo->jpeg_color_space = JCS_UNKNOWN;
1759                 cinfo->out_color_space = JCS_UNKNOWN;


< prev index next >