< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java

Print this page




 916         // returns an empty Iterator.
 917 
 918         // Get the raw ITS, if there is one.  Note that this
 919         // won't always be the same as the default.
 920         ImageTypeProducer raw = getImageType(colorSpaceCode);
 921 
 922         // Given the encoded colorspace, build a list of ITS's
 923         // representing outputs you could handle starting
 924         // with the default.
 925 
 926         ArrayList<ImageTypeProducer> list = new ArrayList<ImageTypeProducer>(1);
 927 
 928         switch (colorSpaceCode) {
 929         case JPEG.JCS_GRAYSCALE:
 930             list.add(raw);
 931             list.add(getImageType(JPEG.JCS_RGB));
 932             break;
 933         case JPEG.JCS_RGB:
 934             list.add(raw);
 935             list.add(getImageType(JPEG.JCS_GRAYSCALE));
 936             list.add(getImageType(JPEG.JCS_YCC));
 937             break;
 938         case JPEG.JCS_RGBA:
 939             list.add(raw);
 940             break;
 941         case JPEG.JCS_YCC:
 942             if (raw != null) {  // Might be null if PYCC.pf not installed
 943                 list.add(raw);
 944                 list.add(getImageType(JPEG.JCS_RGB));
 945             }
 946             break;
 947         case JPEG.JCS_YCCA:
 948             if (raw != null) {  // Might be null if PYCC.pf not installed
 949                 list.add(raw);
 950             }
 951             break;
 952         case JPEG.JCS_YCbCr:
 953             // As there is no YCbCr ColorSpace, we can't support
 954             // the raw type.
 955 
 956             // due to 4705399, use RGB as default in order to avoid
 957             // slowing down of drawing operations with result image.
 958             list.add(getImageType(JPEG.JCS_RGB));
 959 
 960             if (iccCS != null) {
 961                 list.add(new ImageTypeProducer() {
 962                     protected ImageTypeSpecifier produce() {
 963                         return ImageTypeSpecifier.createInterleaved
 964                          (iccCS,
 965                           JPEG.bOffsRGB,  // Assume it's for RGB
 966                           DataBuffer.TYPE_BYTE,
 967                           false,
 968                           false);
 969                     }
 970                 });
 971 
 972             }
 973 
 974             list.add(getImageType(JPEG.JCS_GRAYSCALE));
 975             list.add(getImageType(JPEG.JCS_YCC));
 976             break;
 977         case JPEG.JCS_YCbCrA:  // Default is to convert to RGBA
 978             // As there is no YCbCr ColorSpace, we can't support
 979             // the raw type.
 980             list.add(getImageType(JPEG.JCS_RGBA));
 981             break;
 982         }
 983 
 984         return new ImageTypeIterator(list.iterator());
 985     }
 986 
 987     /**
 988      * Checks the implied color conversion between the stream and
 989      * the target image, altering the IJG output color space if necessary.
 990      * If a java color conversion is required, then this sets up
 991      * {@code convert}.
 992      * If bands are being rearranged at all (either source or destination
 993      * bands are specified in the param), then the default color
 994      * conversions are assumed to be correct.
 995      * Throws an IIOException if there is no conversion available.
 996      */
 997     private void checkColorConversion(BufferedImage image,
 998                                       ImageReadParam param)
 999         throws IIOException {
1000 


1048                     // in the native part of decoder.
1049                     outColorSpaceCode = JPEG.JCS_GRAYSCALE;
1050                     numComponents = 1;
1051                 }
1052             } else if ((iccCS != null) &&
1053                        (cm.getNumComponents() == numComponents) &&
1054                        (cs != iccCS)) {
1055                 // We have an ICC profile but it isn't used in the dest
1056                 // image.  So convert from the profile cs to the target cs
1057                 convert = new ColorConvertOp(iccCS, cs, null);
1058                 // Leave IJG conversion in place; we still need it
1059             } else if ((iccCS == null) &&
1060                        (!cs.isCS_sRGB()) &&
1061                        (cm.getNumComponents() == numComponents)) {
1062                 // Target isn't sRGB, so convert from sRGB to the target
1063                 convert = new ColorConvertOp(JPEG.JCS.sRGB, cs, null);
1064             } else if (csType != ColorSpace.TYPE_RGB) {
1065                 throw new IIOException("Incompatible color conversion");
1066             }
1067             break;
1068         case JPEG.JCS_RGBA:
1069             // No conversions available; image must be RGBA
1070             if ((csType != ColorSpace.TYPE_RGB) ||
1071                 (cm.getNumComponents() != numComponents)) {
1072                 throw new IIOException("Incompatible color conversion");
1073             }
1074             break;
1075         case JPEG.JCS_YCC:
1076             {
1077                 ColorSpace YCC = JPEG.JCS.getYCC();
1078                 if (YCC == null) { // We can't do YCC at all
1079                     throw new IIOException("Incompatible color conversion");
1080                 }
1081                 if ((cs != YCC) &&
1082                     (cm.getNumComponents() == numComponents)) {
1083                     convert = new ColorConvertOp(YCC, cs, null);
1084                 }
1085             }
1086             break;
1087         case JPEG.JCS_YCCA:
1088             {
1089                 ColorSpace YCC = JPEG.JCS.getYCC();
1090                 // No conversions available; image must be YCCA
1091                 if ((YCC == null) || // We can't do YCC at all
1092                     (cs != YCC) ||
1093                     (cm.getNumComponents() != numComponents)) {
1094                     throw new IIOException("Incompatible color conversion");
1095                 }
1096             }
1097             break;
1098         default:
1099             // Anything else we can't handle at all
1100             throw new IIOException("Incompatible color conversion");
1101         }
1102     }
1103 
1104     /**
1105      * Set the IJG output space to the given value.  The library will
1106      * perform the appropriate colorspace conversions.
1107      */
1108     private native void setOutColorSpace(long structPointer, int id);
1109 
1110     /////// End of Color Conversion & Image Types
1111 
1112     public ImageReadParam getDefaultReadParam() {
1113         return new JPEGImageReadParam();
1114     }
1115 
1116     public IIOMetadata getStreamMetadata() throws IOException {
1117         setThreadLock();


1912         }
1913         if (defaultTypes[csCode] == null) {
1914             defaultTypes[csCode] = new ImageTypeProducer(csCode);
1915         }
1916         return defaultTypes[csCode];
1917     }
1918 
1919     protected ImageTypeSpecifier produce() {
1920         switch (csCode) {
1921             case JPEG.JCS_GRAYSCALE:
1922                 return ImageTypeSpecifier.createFromBufferedImageType
1923                         (BufferedImage.TYPE_BYTE_GRAY);
1924             case JPEG.JCS_YCbCr:
1925             //there is no YCbCr raw type so by default we assume it as RGB
1926             case JPEG.JCS_RGB:
1927                 return ImageTypeSpecifier.createInterleaved(JPEG.JCS.sRGB,
1928                         JPEG.bOffsRGB,
1929                         DataBuffer.TYPE_BYTE,
1930                         false,
1931                         false);
1932             case JPEG.JCS_RGBA:
1933                 return ImageTypeSpecifier.createPacked(JPEG.JCS.sRGB,
1934                         0xff000000,
1935                         0x00ff0000,
1936                         0x0000ff00,
1937                         0x000000ff,
1938                         DataBuffer.TYPE_INT,
1939                         false);
1940             case JPEG.JCS_YCC:
1941                 if (JPEG.JCS.getYCC() != null) {
1942                     return ImageTypeSpecifier.createInterleaved(
1943                             JPEG.JCS.getYCC(),
1944                         JPEG.bandOffsets[2],
1945                         DataBuffer.TYPE_BYTE,
1946                         false,
1947                         false);
1948                 } else {
1949                     return null;
1950                 }
1951             case JPEG.JCS_YCCA:
1952                 if (JPEG.JCS.getYCC() != null) {
1953                     return ImageTypeSpecifier.createInterleaved(
1954                             JPEG.JCS.getYCC(),
1955                         JPEG.bandOffsets[3],
1956                         DataBuffer.TYPE_BYTE,
1957                         true,
1958                         false);
1959                 } else {
1960                     return null;
1961                 }
1962             default:
1963                 return null;
1964         }
1965     }
1966 }


 916         // returns an empty Iterator.
 917 
 918         // Get the raw ITS, if there is one.  Note that this
 919         // won't always be the same as the default.
 920         ImageTypeProducer raw = getImageType(colorSpaceCode);
 921 
 922         // Given the encoded colorspace, build a list of ITS's
 923         // representing outputs you could handle starting
 924         // with the default.
 925 
 926         ArrayList<ImageTypeProducer> list = new ArrayList<ImageTypeProducer>(1);
 927 
 928         switch (colorSpaceCode) {
 929         case JPEG.JCS_GRAYSCALE:
 930             list.add(raw);
 931             list.add(getImageType(JPEG.JCS_RGB));
 932             break;
 933         case JPEG.JCS_RGB:
 934             list.add(raw);
 935             list.add(getImageType(JPEG.JCS_GRAYSCALE));















 936             break;
 937         case JPEG.JCS_YCbCr:
 938             // As there is no YCbCr ColorSpace, we can't support
 939             // the raw type.
 940 
 941             // due to 4705399, use RGB as default in order to avoid
 942             // slowing down of drawing operations with result image.
 943             list.add(getImageType(JPEG.JCS_RGB));
 944 
 945             if (iccCS != null) {
 946                 list.add(new ImageTypeProducer() {
 947                     protected ImageTypeSpecifier produce() {
 948                         return ImageTypeSpecifier.createInterleaved
 949                          (iccCS,
 950                           JPEG.bOffsRGB,  // Assume it's for RGB
 951                           DataBuffer.TYPE_BYTE,
 952                           false,
 953                           false);
 954                     }
 955                 });
 956 
 957             }
 958 
 959             list.add(getImageType(JPEG.JCS_GRAYSCALE));






 960             break;
 961         }
 962 
 963         return new ImageTypeIterator(list.iterator());
 964     }
 965 
 966     /**
 967      * Checks the implied color conversion between the stream and
 968      * the target image, altering the IJG output color space if necessary.
 969      * If a java color conversion is required, then this sets up
 970      * {@code convert}.
 971      * If bands are being rearranged at all (either source or destination
 972      * bands are specified in the param), then the default color
 973      * conversions are assumed to be correct.
 974      * Throws an IIOException if there is no conversion available.
 975      */
 976     private void checkColorConversion(BufferedImage image,
 977                                       ImageReadParam param)
 978         throws IIOException {
 979 


1027                     // in the native part of decoder.
1028                     outColorSpaceCode = JPEG.JCS_GRAYSCALE;
1029                     numComponents = 1;
1030                 }
1031             } else if ((iccCS != null) &&
1032                        (cm.getNumComponents() == numComponents) &&
1033                        (cs != iccCS)) {
1034                 // We have an ICC profile but it isn't used in the dest
1035                 // image.  So convert from the profile cs to the target cs
1036                 convert = new ColorConvertOp(iccCS, cs, null);
1037                 // Leave IJG conversion in place; we still need it
1038             } else if ((iccCS == null) &&
1039                        (!cs.isCS_sRGB()) &&
1040                        (cm.getNumComponents() == numComponents)) {
1041                 // Target isn't sRGB, so convert from sRGB to the target
1042                 convert = new ColorConvertOp(JPEG.JCS.sRGB, cs, null);
1043             } else if (csType != ColorSpace.TYPE_RGB) {
1044                 throw new IIOException("Incompatible color conversion");
1045             }
1046             break;






























1047         default:
1048             // Anything else we can't handle at all
1049             throw new IIOException("Incompatible color conversion");
1050         }
1051     }
1052 
1053     /**
1054      * Set the IJG output space to the given value.  The library will
1055      * perform the appropriate colorspace conversions.
1056      */
1057     private native void setOutColorSpace(long structPointer, int id);
1058 
1059     /////// End of Color Conversion & Image Types
1060 
1061     public ImageReadParam getDefaultReadParam() {
1062         return new JPEGImageReadParam();
1063     }
1064 
1065     public IIOMetadata getStreamMetadata() throws IOException {
1066         setThreadLock();


1861         }
1862         if (defaultTypes[csCode] == null) {
1863             defaultTypes[csCode] = new ImageTypeProducer(csCode);
1864         }
1865         return defaultTypes[csCode];
1866     }
1867 
1868     protected ImageTypeSpecifier produce() {
1869         switch (csCode) {
1870             case JPEG.JCS_GRAYSCALE:
1871                 return ImageTypeSpecifier.createFromBufferedImageType
1872                         (BufferedImage.TYPE_BYTE_GRAY);
1873             case JPEG.JCS_YCbCr:
1874             //there is no YCbCr raw type so by default we assume it as RGB
1875             case JPEG.JCS_RGB:
1876                 return ImageTypeSpecifier.createInterleaved(JPEG.JCS.sRGB,
1877                         JPEG.bOffsRGB,
1878                         DataBuffer.TYPE_BYTE,
1879                         false,
1880                         false);






























1881             default:
1882                 return null;
1883         }
1884     }
1885 }
< prev index next >