< prev index next >

test/javax/imageio/plugins/shared/BitDepth.java

Print this page




 113     };
 114 
 115     private int width = 80;
 116     private int height = 80;
 117     private String[] format = { "png", "jpeg", "tif", "bmp", "gif" };
 118 
 119     public BitDepth(String[] args) throws IOException {
 120         if (args.length > 0) {
 121             format = args;
 122         }
 123 
 124         for (int i = 0; i < format.length; i++) {
 125             testFormat(format[i]);
 126         }
 127     }
 128 
 129     private void testFormat(String format) throws IOException {
 130 
 131         boolean allOK = true;
 132 
 133         for (int i = 0; i < biRGBTypes.length; i++) {
 134 
 135             int type = biRGBTypes[i];
 136 
 137 
 138             // TODO: remove the following 'if' block after the 8147448 fix
 139             if ( format.toLowerCase().equals("bmp") && (
 140                 (type == BufferedImage.TYPE_INT_ARGB       ) ||
 141                 (type == BufferedImage.TYPE_INT_ARGB_PRE   ) ||
 142                 (type == BufferedImage.TYPE_4BYTE_ABGR     ) ||
 143                 (type == BufferedImage.TYPE_4BYTE_ABGR_PRE ))) {
 144 
 145                 System.err.println("cannot use " + biTypeNames[type] +
 146                 " for bmp because of JDK-8147448.\t" +
 147                 " please update the test after fix of this bug!");
 148                 continue;
 149             }
 150 
 151 
 152             System.out.println("Testing " + format +
 153                                " writer for type " + biTypeNames[type]);
 154             File f = testWriteRGB(format, type);
 155             boolean ok = testReadRGB(f);











 156             if (ok) {
 157                 f.delete();
 158             }
 159             allOK = allOK && ok;

 160         }
 161 
 162 
 163 
 164         if (format.equals("png")) {
 165             System.out.println("Testing png writer for black stripe");
 166             boolean ok = testPNGByteBinary();
 167             allOK = allOK && ok;
 168         }
 169 
 170         if (!allOK) {
 171             throw new RuntimeException("Test failed");
 172         }
 173     }
 174 
 175     private File testWriteRGB(String format, int type) throws IOException {
 176 
 177         BufferedImage bi = new BufferedImage(width, height, type);
 178         Graphics2D g = bi.createGraphics();
 179 




 113     };
 114 
 115     private int width = 80;
 116     private int height = 80;
 117     private String[] format = { "png", "jpeg", "tif", "bmp", "gif" };
 118 
 119     public BitDepth(String[] args) throws IOException {
 120         if (args.length > 0) {
 121             format = args;
 122         }
 123 
 124         for (int i = 0; i < format.length; i++) {
 125             testFormat(format[i]);
 126         }
 127     }
 128 
 129     private void testFormat(String format) throws IOException {
 130 
 131         boolean allOK = true;
 132 
 133         for (int type : biRGBTypes) {




 134             // TODO: remove the following 'if' block after the 8147448 fix
 135             if ( format.toLowerCase().equals("bmp") && (
 136                 (type == BufferedImage.TYPE_INT_ARGB       ) ||
 137                 (type == BufferedImage.TYPE_INT_ARGB_PRE   ) ||
 138                 (type == BufferedImage.TYPE_4BYTE_ABGR     ) ||
 139                 (type == BufferedImage.TYPE_4BYTE_ABGR_PRE ))) {
 140 
 141                 System.err.println("cannot use " + biTypeNames[type] +
 142                 " for bmp because of JDK-8147448.\t" +
 143                 " please update the test after fix of this bug!");
 144                 continue;
 145             }
 146 
 147 
 148             System.out.println("Testing " + format +
 149                                " writer for type " + biTypeNames[type]);
 150             boolean ok = false;
 151             File f = null;
 152             try {
 153                 f = testWriteRGB(format, type);
 154                 ok = testReadRGB(f);
 155             } catch (javax.imageio.IIOException e) {
 156                 // The follow two formats are not supported on OpenJDK
 157                 // for jpg files.
 158                 if (format.toLowerCase().equals("jpg") &&
 159                     (type == BufferedImage.TYPE_4BYTE_ABGR ||
 160                      type == BufferedImage.TYPE_4BYTE_ABGR_PRE))
 161                     continue;
 162             } finally {
 163                 if (ok) {
 164                     f.delete();
 165                 }
 166                 allOK = allOK && (ok || f == null);
 167             }
 168         }
 169 
 170 
 171 
 172         if (format.equals("png")) {
 173             System.out.println("Testing png writer for black stripe");
 174             boolean ok = testPNGByteBinary();
 175             allOK = allOK && ok;
 176         }
 177 
 178         if (!allOK) {
 179             throw new RuntimeException("Test failed");
 180         }
 181     }
 182 
 183     private File testWriteRGB(String format, int type) throws IOException {
 184 
 185         BufferedImage bi = new BufferedImage(width, height, type);
 186         Graphics2D g = bi.createGraphics();
 187 


< prev index next >