Package ar.com.hjg.pngj

Examples of ar.com.hjg.pngj.PngjException


  public void parseFromRaw(ChunkRaw chunk) {
    int pos0 = ChunkHelper.posNullByte(chunk.data);
    profileName = ChunkHelper.toString(chunk.data, 0, pos0);
    int comp = (chunk.data[pos0 + 1] & 0xff);
    if (comp != 0)
      throw new PngjException("bad compression for ChunkTypeICCP");
    int compdatasize = chunk.data.length - (pos0 + 2);
    compressedProfile = new byte[compdatasize];
    System.arraycopy(chunk.data, pos0 + 2, compressedProfile, 0, compdatasize);
  }
View Full Code Here


   *
   * @param gray
   */
  public void setGray(int gray) {
    if (!imgInfo.greyscale)
      throw new PngjException("only gray images support this");
    this.gray = gray;
  }
View Full Code Here

    this.gray = gray;
  }

  public int getGray() {
    if (!imgInfo.greyscale)
      throw new PngjException("only gray images support this");
    return gray;
  }
View Full Code Here

   * Set pallette index
   *
   */
  public void setPaletteIndex(int i) {
    if (!imgInfo.indexed)
      throw new PngjException("only indexed (pallete) images support this");
    this.paletteIndex = i;
  }
View Full Code Here

    this.paletteIndex = i;
  }

  public int getPaletteIndex() {
    if (!imgInfo.indexed)
      throw new PngjException("only indexed (pallete) images support this");
    return paletteIndex;
  }
View Full Code Here

   * Set rgb values
   *
   */
  public void setRGB(int r, int g, int b) {
    if (imgInfo.greyscale || imgInfo.indexed)
      throw new PngjException("only rgb or rgba images support this");
    red = r;
    green = g;
    blue = b;
  }
View Full Code Here

    blue = b;
  }

  public int[] getRGB() {
    if (imgInfo.greyscale || imgInfo.indexed)
      throw new PngjException("only rgb or rgba images support this");
    return new int[] {red, green, blue};
  }
View Full Code Here

  }

  @Override
  public ChunkRaw createRawChunk() {
    if (key == null || key.trim().length() == 0)
      throw new PngjException("Text chunk key must be non empty");
    try {
      ByteArrayOutputStream ba = new ByteArrayOutputStream();
      ba.write(ChunkHelper.toBytes(key));
      ba.write(0); // separator
      ba.write(compressed ? 1 : 0);
      ba.write(0); // compression method (always 0)
      ba.write(ChunkHelper.toBytes(langTag));
      ba.write(0); // separator
      ba.write(ChunkHelper.toBytesUTF8(translatedTag));
      ba.write(0); // separator
      byte[] textbytes = ChunkHelper.toBytesUTF8(val);
      if (compressed) {
        textbytes = ChunkHelper.compressBytes(textbytes, true);
      }
      ba.write(textbytes);
      byte[] b = ba.toByteArray();
      ChunkRaw chunk = createEmptyChunk(b.length, false);
      chunk.data = b;
      return chunk;
    } catch (IOException e) {
      throw new PngjException(e);
    }
  }
View Full Code Here

        i += 2;
      if (nullsFound == 3)
        break;
    }
    if (nullsFound != 3)
      throw new PngjException("Bad formed PngChunkITXT chunk");
    key = ChunkHelper.toString(c.data, 0, nullsIdx[0]);
    int i = nullsIdx[0] + 1;
    compressed = c.data[i] == 0 ? false : true;
    i++;
    if (compressed && c.data[i] != 0)
      throw new PngjException("Bad formed PngChunkITXT chunk - bad compression method ");
    langTag = ChunkHelper.toString(c.data, i, nullsIdx[1] - i);
    translatedTag =
        ChunkHelper.toStringUTF8(c.data, nullsIdx[1] + 1, nullsIdx[2] - nullsIdx[1] - 1);
    i = nullsIdx[2] + 1;
    if (compressed) {
View Full Code Here

  }

  public void setNentries(int n) {
    nentries = n;
    if (nentries < 1 || nentries > 256)
      throw new PngjException("invalid pallette - nentries=" + nentries);
    if (entries == null || entries.length != nentries) { // alloc
      entries = new int[nentries];
    }
  }
View Full Code Here

TOP

Related Classes of ar.com.hjg.pngj.PngjException

Copyright © 2018 www.massapicom. 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.