Examples of PNGChunkPLTE


Examples of org.apache.commons.imaging.formats.png.chunks.PngChunkPlte

                } else if (chunkType == ChunkType.zTXt.value) {
                    result.add(new PngChunkZtxt(length, chunkType, crc, bytes));
                } else if (chunkType == ChunkType.IHDR.value) {
                    result.add(new PngChunkIhdr(length, chunkType, crc, bytes));
                } else if (chunkType == ChunkType.PLTE.value) {
                    result.add(new PngChunkPlte(length, chunkType, crc, bytes));
                } else if (chunkType == ChunkType.pHYs.value) {
                    result.add(new PngChunkPhys(length, chunkType, crc, bytes));
                } else if (chunkType == ChunkType.IDAT.value) {
                    result.add(new PngChunkIdat(length, chunkType, crc, bytes));
                } else if (chunkType == ChunkType.gAMA.value) {
View Full Code Here

Examples of org.apache.commons.imaging.formats.png.chunks.PngChunkPlte

        final List<PngChunk> PLTEs = filterChunks(chunks, ChunkType.PLTE);
        if (PLTEs.size() > 1) {
            throw new ImageReadException("PNG contains more than one Palette");
        }

        PngChunkPlte pngChunkPLTE = null;
        if (PLTEs.size() == 1) {
            pngChunkPLTE = (PngChunkPlte) PLTEs.get(0);
        }

        // -----

        final List<PngChunk> IDATs = filterChunks(chunks, ChunkType.IDAT);
        if (IDATs.isEmpty()) {
            throw new ImageReadException("PNG missing image data");
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        for (PngChunk IDAT : IDATs) {
            final PngChunkIdat pngChunkIDAT = (PngChunkIdat) IDAT;
            final byte[] bytes = pngChunkIDAT.getBytes();
            // System.out.println(i + ": bytes: " + bytes.length);
            baos.write(bytes);
        }

        final byte[] compressed = baos.toByteArray();

        baos = null;

        TransparencyFilter transparencyFilter = null;

        final List<PngChunk> tRNSs = filterChunks(chunks, ChunkType.tRNS);
        if (!tRNSs.isEmpty()) {
            final PngChunk pngChunktRNS = tRNSs.get(0);
            transparencyFilter = getTransparencyFilter(pngChunkIHDR.colorType, pngChunktRNS);
        }

        ICC_Profile iccProfile = null;
        GammaCorrection gammaCorrection = null;
        {
            final List<PngChunk> sRGBs = filterChunks(chunks, ChunkType.sRGB);
            final List<PngChunk> gAMAs = filterChunks(chunks, ChunkType.gAMA);
            final List<PngChunk> iCCPs = filterChunks(chunks, ChunkType.iCCP);
            if (sRGBs.size() > 1) {
                throw new ImageReadException("PNG: unexpected sRGB chunk");
            }
            if (gAMAs.size() > 1) {
                throw new ImageReadException("PNG: unexpected gAMA chunk");
            }
            if (iCCPs.size() > 1) {
                throw new ImageReadException("PNG: unexpected iCCP chunk");
            }

            if (sRGBs.size() == 1) {
                // no color management neccesary.
                if (getDebug()) {
                    System.out.println("sRGB, no color management neccesary.");
                }
            } else if (iCCPs.size() == 1) {
                if (getDebug()) {
                    System.out.println("iCCP.");
                }

                final PngChunkIccp pngChunkiCCP = (PngChunkIccp) iCCPs.get(0);
                final byte[] bytes = pngChunkiCCP.uncompressedProfile;

                iccProfile = ICC_Profile.getInstance(bytes);
            } else if (gAMAs.size() == 1) {
                final PngChunkGama pngChunkgAMA = (PngChunkGama) gAMAs.get(0);
                final double gamma = pngChunkgAMA.getGamma();

                // charles: what is the correct target value here?
                // double targetGamma = 2.2;
                final double targetGamma = 1.0;
                final double diff = Math.abs(targetGamma - gamma);
                if (diff >= 0.5) {
                    gammaCorrection = new GammaCorrection(gamma, targetGamma);
                }

                if (gammaCorrection != null) {
                    if (pngChunkPLTE != null) {
                        pngChunkPLTE.correct(gammaCorrection);
                    }
                }

            }
        }
View Full Code Here

Examples of org.apache.sanselan.formats.png.chunks.PNGChunkPLTE

                else if (chunkType == zTXt)
                    result.add(new PNGChunkzTXt(length, chunkType, CRC, bytes));
                else if (chunkType == IHDR)
                    result.add(new PNGChunkIHDR(length, chunkType, CRC, bytes));
                else if (chunkType == PLTE)
                    result.add(new PNGChunkPLTE(length, chunkType, CRC, bytes));
                else if (chunkType == pHYs)
                    result.add(new PNGChunkpHYs(length, chunkType, CRC, bytes));
                else if (chunkType == IDAT)
                    result.add(new PNGChunkIDAT(length, chunkType, CRC, bytes));
                else if (chunkType == gAMA)
View Full Code Here

Examples of org.apache.sanselan.formats.png.chunks.PNGChunkPLTE

        ArrayList PLTEs = filterChunks(chunks, PLTE);
        if (PLTEs.size() > 1)
            throw new ImageReadException("PNG contains more than one Palette");

        PNGChunkPLTE pngChunkPLTE = null;
        if (PLTEs.size() == 1)
            pngChunkPLTE = (PNGChunkPLTE) PLTEs.get(0);

        // -----

        ArrayList IDATs = filterChunks(chunks, IDAT);
        if (IDATs.size() < 1)
            throw new ImageReadException("PNG missing image data");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        for (int i = 0; i < IDATs.size(); i++)
        {
            PNGChunkIDAT pngChunkIDAT = (PNGChunkIDAT) IDATs.get(i);
            byte bytes[] = pngChunkIDAT.bytes;
            // System.out.println(i + ": bytes: " + bytes.length);
            baos.write(bytes);
        }

        byte compressed[] = baos.toByteArray();

        baos = null;

        TransparencyFilter transparencyFilter = null;

        ArrayList tRNSs = filterChunks(chunks, tRNS);
        if (tRNSs.size() > 0)
        {
            PNGChunk pngChunktRNS = (PNGChunk) tRNSs.get(0);
            transparencyFilter = getTransparencyFilter(pngChunkIHDR.colorType,
                    pngChunktRNS);
        }

        ICC_Profile icc_profile = null;
        GammaCorrection gammaCorrection = null;
        {
            ArrayList sRGBs = filterChunks(chunks, sRGB);
            ArrayList gAMAs = filterChunks(chunks, gAMA);
            ArrayList iCCPs = filterChunks(chunks, iCCP);
            if (sRGBs.size() > 1)
                throw new ImageReadException("PNG: unexpected sRGB chunk");
            if (gAMAs.size() > 1)
                throw new ImageReadException("PNG: unexpected gAMA chunk");
            if (iCCPs.size() > 1)
                throw new ImageReadException("PNG: unexpected iCCP chunk");

            if (sRGBs.size() == 1)
            {
                // no color management neccesary.
                if (debug)
                    System.out.println("sRGB, no color management neccesary.");
            } else if (iCCPs.size() == 1)
            {
                if (debug)
                    System.out.println("iCCP.");

                PNGChunkiCCP pngChunkiCCP = (PNGChunkiCCP) iCCPs.get(0);
                byte bytes[] = pngChunkiCCP.UncompressedProfile;

                icc_profile = ICC_Profile.getInstance(bytes);
            } else if (gAMAs.size() == 1)
            {
                PNGChunkgAMA pngChunkgAMA = (PNGChunkgAMA) gAMAs.get(0);
                double gamma = pngChunkgAMA.getGamma();

                // charles: what is the correct target value here?
                // double targetGamma = 2.2;
                double targetGamma = 1.0;
                double diff = Math.abs(targetGamma - gamma);
                if (diff >= 0.5)
                    gammaCorrection = new GammaCorrection(gamma, targetGamma);

                if (gammaCorrection != null)
                    if (pngChunkPLTE != null)
                        pngChunkPLTE.correct(gammaCorrection);

            }
        }

        {
View Full Code Here

Examples of org.apache.sanselan.formats.png.chunks.PNGChunkPLTE

        else if (chunkType == zTXt)
          result.add(new PNGChunkzTXt(length, chunkType, CRC, bytes));
        else if (chunkType == IHDR)
          result.add(new PNGChunkIHDR(length, chunkType, CRC, bytes));
        else if (chunkType == PLTE)
          result.add(new PNGChunkPLTE(length, chunkType, CRC, bytes));
        else if (chunkType == pHYs)
          result.add(new PNGChunkpHYs(length, chunkType, CRC, bytes));
        else if (chunkType == IDAT)
          result.add(new PNGChunkIDAT(length, chunkType, CRC, bytes));
        else if (chunkType == gAMA)
View Full Code Here

Examples of org.apache.sanselan.formats.png.chunks.PNGChunkPLTE

    ArrayList PLTEs = filterChunks(chunks, PLTE);
    if (PLTEs.size() > 1)
      throw new ImageReadException("PNG contains more than one Palette");

    PNGChunkPLTE pngChunkPLTE = null;
    if (PLTEs.size() == 1)
      pngChunkPLTE = (PNGChunkPLTE) PLTEs.get(0);

    // -----

    ArrayList IDATs = filterChunks(chunks, IDAT);
    if (IDATs.size() < 1)
      throw new ImageReadException("PNG missing image data");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (int i = 0; i < IDATs.size(); i++)
    {
      PNGChunkIDAT pngChunkIDAT = (PNGChunkIDAT) IDATs.get(i);
      byte bytes[] = pngChunkIDAT.bytes;
      // System.out.println(i + ": bytes: " + bytes.length);
      baos.write(bytes);
    }

    byte compressed[] = baos.toByteArray();

    baos = null;

    TransparencyFilter transparencyFilter = null;

    ArrayList tRNSs = filterChunks(chunks, tRNS);
    if (tRNSs.size() > 0)
    {
      PNGChunk pngChunktRNS = (PNGChunk) tRNSs.get(0);
      transparencyFilter = getTransparencyFilter(pngChunkIHDR.colorType,
          pngChunktRNS);
    }

    ICC_Profile icc_profile = null;
    GammaCorrection gammaCorrection = null;
    {
      ArrayList sRGBs = filterChunks(chunks, sRGB);
      ArrayList gAMAs = filterChunks(chunks, gAMA);
      ArrayList iCCPs = filterChunks(chunks, iCCP);
      if (sRGBs.size() > 1)
        throw new ImageReadException("PNG: unexpected sRGB chunk");
      if (gAMAs.size() > 1)
        throw new ImageReadException("PNG: unexpected gAMA chunk");
      if (iCCPs.size() > 1)
        throw new ImageReadException("PNG: unexpected iCCP chunk");

      if (sRGBs.size() == 1)
      {
        // no color management neccesary.
        if (debug)
          System.out.println("sRGB, no color management neccesary.");
      } else if (iCCPs.size() == 1)
      {
        if (debug)
          System.out.println("iCCP.");

        PNGChunkiCCP pngChunkiCCP = (PNGChunkiCCP) iCCPs.get(0);
        byte bytes[] = pngChunkiCCP.UncompressedProfile;

        icc_profile = ICC_Profile.getInstance(bytes);
      } else if (gAMAs.size() == 1)
      {
        PNGChunkgAMA pngChunkgAMA = (PNGChunkgAMA) gAMAs.get(0);
        double gamma = pngChunkgAMA.getGamma();

        // charles: what is the correct target value here?
        // double targetGamma = 2.2;
        double targetGamma = 1.0;
        double diff = Math.abs(targetGamma - gamma);
        if (diff >= 0.5)
          gammaCorrection = new GammaCorrection(gamma, targetGamma);

        if (gammaCorrection != null)
          if (pngChunkPLTE != null)
            pngChunkPLTE.correct(gammaCorrection);

      }
    }

    {
View Full Code Here

Examples of org.apache.sanselan.formats.png.chunks.PNGChunkPLTE

        else if (chunkType == zTXt)
          result.add(new PNGChunkzTXt(length, chunkType, CRC, bytes));
        else if (chunkType == IHDR)
          result.add(new PNGChunkIHDR(length, chunkType, CRC, bytes));
        else if (chunkType == PLTE)
          result.add(new PNGChunkPLTE(length, chunkType, CRC, bytes));
        else if (chunkType == pHYs)
          result.add(new PNGChunkpHYs(length, chunkType, CRC, bytes));
        else if (chunkType == IDAT)
          result.add(new PNGChunkIDAT(length, chunkType, CRC, bytes));
        else if (chunkType == gAMA)
View Full Code Here

Examples of org.apache.sanselan.formats.png.chunks.PNGChunkPLTE

    ArrayList PLTEs = filterChunks(chunks, PLTE);
    if (PLTEs.size() > 1)
      throw new ImageReadException("PNG contains more than one Palette");

    PNGChunkPLTE pngChunkPLTE = null;
    if (PLTEs.size() == 1)
      pngChunkPLTE = (PNGChunkPLTE) PLTEs.get(0);

    // -----

    ArrayList IDATs = filterChunks(chunks, IDAT);
    if (IDATs.size() < 1)
      throw new ImageReadException("PNG missing image data");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (int i = 0; i < IDATs.size(); i++)
    {
      PNGChunkIDAT pngChunkIDAT = (PNGChunkIDAT) IDATs.get(i);
      byte bytes[] = pngChunkIDAT.bytes;
      // System.out.println(i + ": bytes: " + bytes.length);
      baos.write(bytes);
    }

    byte compressed[] = baos.toByteArray();

    baos = null;

    TransparencyFilter transparencyFilter = null;

    ArrayList tRNSs = filterChunks(chunks, tRNS);
    if (tRNSs.size() > 0)
    {
      PNGChunk pngChunktRNS = (PNGChunk) tRNSs.get(0);
      transparencyFilter = getTransparencyFilter(pngChunkIHDR.colorType,
          pngChunktRNS);
    }

    ICC_Profile icc_profile = null;
    GammaCorrection gammaCorrection = null;
    {
      ArrayList sRGBs = filterChunks(chunks, sRGB);
      ArrayList gAMAs = filterChunks(chunks, gAMA);
      ArrayList iCCPs = filterChunks(chunks, iCCP);
      if (sRGBs.size() > 1)
        throw new ImageReadException("PNG: unexpected sRGB chunk");
      if (gAMAs.size() > 1)
        throw new ImageReadException("PNG: unexpected gAMA chunk");
      if (iCCPs.size() > 1)
        throw new ImageReadException("PNG: unexpected iCCP chunk");

      if (sRGBs.size() == 1)
      {
        // no color management neccesary.
        if (debug)
          System.out.println("sRGB, no color management neccesary.");
      } else if (iCCPs.size() == 1)
      {
        if (debug)
          System.out.println("iCCP.");

        PNGChunkiCCP pngChunkiCCP = (PNGChunkiCCP) iCCPs.get(0);
        byte bytes[] = pngChunkiCCP.UncompressedProfile;

        icc_profile = ICC_Profile.getInstance(bytes);
      } else if (gAMAs.size() == 1)
      {
        PNGChunkgAMA pngChunkgAMA = (PNGChunkgAMA) gAMAs.get(0);
        double gamma = pngChunkgAMA.getGamma();

        // charles: what is the correct target value here?
        // double targetGamma = 2.2;
        double targetGamma = 1.0;
        double diff = Math.abs(targetGamma - gamma);
        if (diff >= 0.5)
          gammaCorrection = new GammaCorrection(gamma, targetGamma);

        if (gammaCorrection != null)
          if (pngChunkPLTE != null)
            pngChunkPLTE.correct(gammaCorrection);

      }
    }

    {
View Full Code Here

Examples of org.apache.sanselan.formats.png.chunks.PNGChunkPLTE

        else if (chunkType == zTXt)
          result.add(new PNGChunkzTXt(length, chunkType, CRC, bytes));
        else if (chunkType == IHDR)
          result.add(new PNGChunkIHDR(length, chunkType, CRC, bytes));
        else if (chunkType == PLTE)
          result.add(new PNGChunkPLTE(length, chunkType, CRC, bytes));
        else if (chunkType == pHYs)
          result.add(new PNGChunkpHYs(length, chunkType, CRC, bytes));
        else if (chunkType == IDAT)
          result.add(new PNGChunkIDAT(length, chunkType, CRC, bytes));
        else if (chunkType == gAMA)
View Full Code Here

Examples of org.apache.sanselan.formats.png.chunks.PNGChunkPLTE

    ArrayList PLTEs = filterChunks(chunks, PLTE);
    if (PLTEs.size() > 1)
      throw new ImageReadException("PNG contains more than one Palette");

    PNGChunkPLTE pngChunkPLTE = null;
    if (PLTEs.size() == 1)
      pngChunkPLTE = (PNGChunkPLTE) PLTEs.get(0);

    // -----

    ArrayList IDATs = filterChunks(chunks, IDAT);
    if (IDATs.size() < 1)
      throw new ImageReadException("PNG missing image data");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (int i = 0; i < IDATs.size(); i++)
    {
      PNGChunkIDAT pngChunkIDAT = (PNGChunkIDAT) IDATs.get(i);
      byte bytes[] = pngChunkIDAT.bytes;
      // System.out.println(i + ": bytes: " + bytes.length);
      baos.write(bytes);
    }

    byte compressed[] = baos.toByteArray();

    baos = null;

    TransparencyFilter transparencyFilter = null;

    ArrayList tRNSs = filterChunks(chunks, tRNS);
    if (tRNSs.size() > 0)
    {
      PNGChunk pngChunktRNS = (PNGChunk) tRNSs.get(0);
      transparencyFilter = getTransparencyFilter(pngChunkIHDR.colorType,
          pngChunktRNS);
    }

    GammaCorrection gammaCorrection = null;
    {
      ArrayList sRGBs = filterChunks(chunks, sRGB);
      ArrayList gAMAs = filterChunks(chunks, gAMA);
      ArrayList iCCPs = filterChunks(chunks, iCCP);
      if (sRGBs.size() > 1)
        throw new ImageReadException("PNG: unexpected sRGB chunk");
      if (gAMAs.size() > 1)
        throw new ImageReadException("PNG: unexpected gAMA chunk");
      if (iCCPs.size() > 1)
        throw new ImageReadException("PNG: unexpected iCCP chunk");

      if (sRGBs.size() == 1)
      {
        // no color management neccesary.
        if (debug)
          System.out.println("sRGB, no color management neccesary.");
      }
      else if (gAMAs.size() == 1)
      {
        PNGChunkgAMA pngChunkgAMA = (PNGChunkgAMA) gAMAs.get(0);
        double gamma = pngChunkgAMA.getGamma();

        // double targetGamma = 2.2;
        double targetGamma = 1.0;
        double diff = Math.abs(targetGamma - gamma);
        if (diff >= 0.5)
          gammaCorrection = new GammaCorrection(gamma, targetGamma);

        if (gammaCorrection != null)
          if (pngChunkPLTE != null)
            pngChunkPLTE.correct(gammaCorrection);

      }
    }

    {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.