audittool/test-lib/src/main/java/io/bdrc/audit/audittests/ImageAttributeTests.java
private void TestImages(final Path imageGroupParent) throws IOException, UnsupportedFormatException {

            debugImageReaders();
            DirectoryStream.Filter<Path> filter =
                    entry -> (entry.toFile().isFile()
                            && !(entry.toFile().isHidden()
                            || entry.toString().endsWith("json")));

            try (DirectoryStream<Path> imageFiles = Files.newDirectoryStream(imageGroupParent, filter)) {
                for (Path imageFile : imageFiles) {
                    File fileObject = imageFile.toAbsolutePath().toFile();
                    java.lang.String fileObjectPathString = imageFile.toAbsolutePath().toString();

                    boolean validatedFile = false;

                    try {
                        
                        // sysLogger.debug("Got reader from ImageReadersBySuffix");
                        ImageInputStream imageInputStream = ImageIO.createImageInputStream(fileObject);
                        // this idea from https://github.com/haraldk/TwelveMonkeys/issues/428
                        Iterator<ImageReader> readers = ImageIO.getImageReaders(imageInputStream);

                        while (!validatedFile && readers.hasNext()) {
                            ImageReader reader = readers.next();

                            // We need a certain reader. Try the next one in the list if
                            // this reader doesnt work
                            try {
                                ImageAttributes readerAttribs = new ImageAttributes(reader);
                                try {
                                    reader.setInput(imageInputStream);

                                    // Slow - take out of loop
                                    if (reader.getNumImages(true) < 1) {
                                        continue;
                                    }
                                    // Later - do multiple images
                                    readerAttribs.InternalImageAtts = new InternalImageAtts(reader, 0);
                                } finally {
                                    // jimk asset-manager-73
                                    imageInputStream.close();
                                    reader.dispose();
                                }

                                // Phew. We got image data!!!!

                                String validationErrors = validate(readerAttribs);
                                if (validationErrors.length() > 0) {
                                    FailTest(LibOutcome.INVALID_TIFF, fileObjectPathString, validationErrors);
                                }
                                validatedFile = true;  // break out of readers loop - we validated this file

                            } catch (UnsupportedFormatException usfx) {

                                // All this means is that the reader is not one of the ones we care
                                // about. Try another reader
                            }
                        }    // for each reader
                    } catch (NoSuchFileException nsfe) {
                        String badPath = nsfe.getFile();
                        sysLogger.error("No such file {}", badPath);
                        FailTest(LibOutcome.ROOT_NOT_FOUND, badPath);
                    } catch (Exception eek) {
                        FailTest(Outcome.SYS_EXC, "ImageAttributeTest", " in " + fileObjectPathString + ":" + eek
                                .getMessage
                                        ());
                    }

                    // None of the available readers could read this file
                    if (!validatedFile) {
                        FailTest(LibOutcome.NO_IMAGE_READER, fileObjectPathString);
                    }

                    // TODO:  1 image / file !!!!
                 }
            }

            sysLogger.debug("Test outcome {} error count {}", getTestResult().getOutcome(),
                    getTestResult()
                            .getErrors().size());
            if (!IsTestFailed()) {
                PassTest();
            }

        }
/**
         * Image Testing.
         * Tests images for various quality metrics.
         * References for field values are from
         * https://docs.oracle.com/javase/10/docs/api/javax/imageio/metadata/doc-files/tiff_metadata.html
         * Collect image properties for validation:
         * from
         * PIL Image class.
         * See github.com/buda-base/volume-manifest-tool, It tests PIL Image fields:
         * See https://pillow.readthedocs.io/en/3.1.x/handbook/concepts.html?highlight=modes
         * .format (values "TIFF" "JPEG")
         * .mode (value "1") means (1-bit pixels, black and white, stored with one pixel per byte)
         * .info["compression"]
         * <p>
         * The Java analogues of this are:
         * Pil Image.format = ImageIo.Reader type reader instanceof TIFFImageReader orJPEGImageReader
         * (see ImageAttributes ctor)
         * <p>
         * .info["compression"] = IIOMetadata node "CompressionTypeName"
         * .mode = ImageTypeSpecifier.getBufferedImageType (see BufferImage.java for constants)
         *
         * @param imageGroupParent folder containing imageGroups
         * @throws IOException If io error
         */
Image Testing.
Tests images for various quality metrics.

@param imageGroupParent folder containing imageGroups
@throws IOException If io error
Image Testing . Tests images for various quality metrics . @param imageGroupParent folder containing imageGroups @throws IOException If io error
private void TestImages(final Path imageGroupParent) throws IOException, UnsupportedFormatException {
            debugImageReaders();
            DirectoryStream.Filter<Path> filter =
                    entry -> (entry.toFile().isFile()
                            && !(entry.toFile().isHidden()
                            || entry.toString().endsWith("json")));
            try (DirectoryStream<Path> imageFiles = Files.newDirectoryStream(imageGroupParent, filter)) {
                for (Path imageFile : imageFiles) {
                    File fileObject = imageFile.toAbsolutePath().toFile();
                    java.lang.String fileObjectPathString = imageFile.toAbsolutePath().toString();
                    boolean validatedFile = false;
                    try {
                        ImageInputStream imageInputStream = ImageIO.createImageInputStream(fileObject);
                        Iterator<ImageReader> readers = ImageIO.getImageReaders(imageInputStream);
                        while (!validatedFile && readers.hasNext()) {
                            ImageReader reader = readers.next();
                            try {
                                ImageAttributes readerAttribs = new ImageAttributes(reader);
                                try {
                                    reader.setInput(imageInputStream);
                                    if (reader.getNumImages(true) < 1) {
                                        continue;
                                    }
                                    readerAttribs.InternalImageAtts = new InternalImageAtts(reader, 0);
                                } finally {
                                    imageInputStream.close();
                                    reader.dispose();
                                }
                                String validationErrors = validate(readerAttribs);
                                if (validationErrors.length() > 0) {
                                    FailTest(LibOutcome.INVALID_TIFF, fileObjectPathString, validationErrors);
                                }
                                validatedFile = true;  
                            } catch (UnsupportedFormatException usfx) {
                            }
                        }    
                    } catch (NoSuchFileException nsfe) {
                        String badPath = nsfe.getFile();
                        sysLogger.error("No such file {}", badPath);
                        FailTest(LibOutcome.ROOT_NOT_FOUND, badPath);
                    } catch (Exception eek) {
                        FailTest(Outcome.SYS_EXC, "ImageAttributeTest", " in " + fileObjectPathString + ":" + eek
                                .getMessage
                                        ());
                    }
                    if (!validatedFile) {
                        FailTest(LibOutcome.NO_IMAGE_READER, fileObjectPathString);
                    }
                 }
            }
            sysLogger.debug("Test outcome {} error count {}", getTestResult().getOutcome(),
                    getTestResult()
                            .getErrors().size());
            if (!IsTestFailed()) {
                PassTest();
            }
        }
private void TestImages ( final Path imageGroupParent ) throws IOException , UnsupportedFormatException { debugImageReaders ( ) ; DirectoryStream . Filter < Path > filter = entry -> ( entry . toFile ( ) . isFile ( ) && ! ( entry . toFile ( ) . isHidden ( ) || entry . toString ( ) . endsWith ( "json" ) ) ) ; try ( DirectoryStream < Path > imageFiles = Files . newDirectoryStream ( imageGroupParent , filter ) ) { for ( Path imageFile : imageFiles ) { File fileObject = imageFile . toAbsolutePath ( ) . toFile ( ) ; java . lang . String fileObjectPathString = imageFile . toAbsolutePath ( ) . toString ( ) ; boolean validatedFile = false ; try { ImageInputStream imageInputStream = ImageIO . createImageInputStream ( fileObject ) ; Iterator < ImageReader > readers = ImageIO . getImageReaders ( imageInputStream ) ; while ( ! validatedFile && readers . hasNext ( ) ) { ImageReader reader = readers . next ( ) ; try { ImageAttributes readerAttribs = new ImageAttributes ( reader ) ; try { reader . setInput ( imageInputStream ) ; if ( reader . getNumImages ( true ) < 1 ) { continue ; } readerAttribs . InternalImageAtts = new InternalImageAtts ( reader , 0 ) ; } finally { imageInputStream . close ( ) ; reader . dispose ( ) ; } String validationErrors = validate ( readerAttribs ) ; if ( validationErrors . length ( ) > 0 ) { FailTest ( LibOutcome . INVALID_TIFF , fileObjectPathString , validationErrors ) ; } validatedFile = true ; } catch ( UnsupportedFormatException usfx ) { } } } catch ( NoSuchFileException nsfe ) { String badPath = nsfe . getFile ( ) ; sysLogger . error ( "No such file {}" , badPath ) ; FailTest ( LibOutcome . ROOT_NOT_FOUND , badPath ) ; } catch ( Exception eek ) { FailTest ( Outcome . SYS_EXC , "ImageAttributeTest" , " in " + fileObjectPathString + ":" + eek . getMessage ( ) ) ; } if ( ! validatedFile ) { FailTest ( LibOutcome . NO_IMAGE_READER , fileObjectPathString ) ; } } } sysLogger . debug ( "Test outcome {} error count {}" , getTestResult ( ) . getOutcome ( ) , getTestResult ( ) . getErrors ( ) . size ( ) ) ; if ( ! IsTestFailed ( ) ) { PassTest ( ) ; } }
Image Testing.
Image Testing .
// sysLogger.debug("Got reader from ImageReadersBySuffix"); // this idea from https://github.com/haraldk/TwelveMonkeys/issues/428 // We need a certain reader. Try the next one in the list if // this reader doesnt work // Slow - take out of loop // Later - do multiple images // jimk asset-manager-73 // Phew. We got image data!!!! // break out of readers loop - we validated this file // All this means is that the reader is not one of the ones we care // about. Try another reader // for each reader // None of the available readers could read this file // TODO:  1 image / file !!!!