Class PngModule

  • All Implemented Interfaces:
    Module

    public class PngModule
    extends ModuleBase
    Module for validation and metadata extraction on PNG files.
    Author:
    Gary McGath An earlier PNG module was submitted by Gian Uberto Lauri. A few bits of code are copied from it. It validates files but doesn't do much metadata extraction. I noticed it only after making a significant start on my own version. -- GDM
    • Constructor Detail

      • PngModule

        public PngModule()
        Instantiate a PngModule object.
    • Method Detail

      • checkSignatures

        public void checkSignatures​(File file,
                                    InputStream stream,
                                    RepInfo info)
        Check if the digital object conforms to this Module's internal signature information.
        Specified by:
        checkSignatures in interface Module
        Overrides:
        checkSignatures in class ModuleBase
        Parameters:
        file - A RandomAccessFile, positioned at its beginning, which is generated from the object to be parsed
        stream - An InputStream, positioned at its beginning, which is generated from the object to be parsed
        info - A fresh RepInfo object which will be modified to reflect the results of the test
      • parse

        public int parse​(InputStream stream,
                         RepInfo info,
                         int parseIndex)
                  throws IOException
        Parse the content of a purported JPEG stream digital object and store the results in RepInfo. This function uses the JPEG-L method of detecting a marker following a data stream, checking for a 0 high bit rather than an entire 0 byte. So long at no JPEG markers are defined with a value from 0 through 7F, this is valid for all JPEG files.
        Specified by:
        parse in interface Module
        Overrides:
        parse in class ModuleBase
        Parameters:
        stream - An InputStream, positioned at its beginning, which is generated from the object to be parsed
        info - A fresh RepInfo object which will be modified to reflect the results of the parsing
        parseIndex - Must be 0 in first call to parse. If parse returns a nonzero value, it must be called again with parseIndex equal to that return value.
        Throws:
        IOException
      • eatChunk

        public void eatChunk​(PNGChunk chnk)
                      throws IOException
        This lets the module skip over the remainder of a chunk, not including the name, length,and CRC. It updates the CRC.
        Throws:
        IOException
      • addKeyword

        public void addKeyword​(String keywd,
                               String val)
        Add a keyword and value. Creating arbitrary properties on the fly doesn't go well with JHOVE's approach, so we make each property a Map, with keys Keyword, Value, and optionally Language.
      • addKeyword

        public void addKeyword​(String keywd,
                               String translatedKeywd,
                               String val,
                               String language)
        Add a keyword, value, and language.
      • addSplt

        public void addSplt​(String name,
                            int sampleDepth,
                            int numSamples)
        Add a suggested palette
      • initParse

        protected void initParse()
        Initializes the state of the module for parsing.
        Overrides:
        initParse in class ModuleBase
      • setIhdrSeen

        public void setIhdrSeen​(boolean b)
        Note that an IHDR chunk has been seen
      • isIhdrSeen

        public boolean isIhdrSeen()
        Returns true if IHDR chunk has been seen
      • setIdatSeen

        public void setIdatSeen​(boolean b)
        Note that an IDAT chunk has been seen
      • setPlteSeen

        public void setPlteSeen​(boolean b)
        Note that a PLTE chunk has been seen
      • setIendSeen

        public void setIendSeen​(boolean b)
        Note that an IEND chunk has been seen
      • isIdatSeen

        public boolean isIdatSeen()
        Return true if IDAT chunk has been seen
      • isIdatFinished

        public boolean isIdatFinished()
        Return true if a non-IDAT chunk has been seen after an IDAT chunk
      • isPlteSeen

        public boolean isPlteSeen()
        Return true if PLTE chunk has been seen
      • setChunkSeen

        public void setChunkSeen​(int chunkType)
      • isChunkSeen

        public boolean isChunkSeen​(int chunkType)
      • setColorType

        public void setColorType​(int ct)
        Set the color type. The IHDR processing will set this for the benefit of chunks that need it.
      • getColorType

        public int getColorType()
        Get the color type that was recorded from the IHDR chunk.