< 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 


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 


1715                  * IJG assumes all unidentified 3-channels are YCbCr.
1716                  * We assume that only if the second two channels are
1717                  * subsampled (either horizontally or vertically).  If not,
1718                  * we assume RGB.
1719                  *
1720                  * 4776576: Some digital cameras output YCbCr JPEG images
1721                  * that do not contain a JFIF APP0 marker but are only
1722                  * vertically subsampled (no horizontal subsampling).
1723                  * We should only assume this is RGB data if the subsampling
1724                  * factors for the second two channels are the same as the
1725                  * first (check both horizontal and vertical factors).
1726                  */
1727                 h_samp0 = cinfo->comp_info[0].h_samp_factor;
1728                 h_samp1 = cinfo->comp_info[1].h_samp_factor;
1729                 h_samp2 = cinfo->comp_info[2].h_samp_factor;
1730 
1731                 v_samp0 = cinfo->comp_info[0].v_samp_factor;
1732                 v_samp1 = cinfo->comp_info[1].v_samp_factor;
1733                 v_samp2 = cinfo->comp_info[2].v_samp_factor;
1734 
1735                 cid0 = cinfo->comp_info[0].component_id;
1736                 cid1 = cinfo->comp_info[1].component_id;
1737                 cid2 = cinfo->comp_info[2].component_id;
1738 
1739                 /*
1740                  * 8041501 : Added extra check to verify component ID's
1741                  * before checking sampling factors, because if we dont
1742                  * check component ID's we will be overwriting decision
1743                  * made in jdapimin.c to set default compression parameters.
1744                  */
1745 
1746                 if ((!(cid0 == 1 && cid1 == 2 && cid2 == 3)) &&
1747                     ((h_samp1 == h_samp0) && (h_samp2 == h_samp0) &&
1748                     (v_samp1 == v_samp0) && (v_samp2 == v_samp0)))
1749                 {
1750                     cinfo->jpeg_color_space = JCS_RGB;
1751                     /* output is already RGB, so it stays the same */
1752                 }
1753             }
1754             break;
1755 #ifdef YCCALPHA
1756         case JCS_YCC:
1757             cinfo->out_color_space = JCS_YCC;
1758             break;
1759 #endif
1760         case JCS_YCCK:
1761             if ((cinfo->saw_Adobe_marker) && (cinfo->Adobe_transform != 2)) {
1762                 /*
1763                  * IJG guesses this is YCCK and emits a warning
1764                  * We would rather not guess.  Then the user knows
1765                  * To read this as a Raster if at all
1766                  */
1767                 cinfo->jpeg_color_space = JCS_UNKNOWN;
1768                 cinfo->out_color_space = JCS_UNKNOWN;


< prev index next >