Package ar.com.hjg.pngj

Examples of ar.com.hjg.pngj.PngjException


   *
   */
  public void setRGB(int r, int g, int b) {
    invalidateRaw();
    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) {
      byte[] bytes = ChunkHelper.compressBytes(c.data, i, c.data.length - i, false);
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

  }

  @Override
  public void parseFromRaw(ChunkRaw chunk) {
    if (chunk.len != 9)
      throw new PngjException("bad chunk length " + chunk);
    pixelsxUnitX = PngHelperInternal.readInt4fromBytes(chunk.data, 0);
    if (pixelsxUnitX < 0)
      pixelsxUnitX += 0x100000000L;
    pixelsxUnitY = PngHelperInternal.readInt4fromBytes(chunk.data, 4);
    if (pixelsxUnitY < 0)
View Full Code Here

  public PngChunk getQueuedById1(final String id, final String innerid, final boolean failIfMultiple) {
    List<? extends PngChunk> list = getQueuedById(id, innerid);
    if (list.isEmpty())
      return null;
    if (list.size() > 1 && (failIfMultiple || !list.get(0).allowsMultiple()))
      throw new PngjException("unexpected multiple chunks id=" + id);
    return list.get(list.size() - 1);
  }
View Full Code Here

  public PngChunk getById1(final String id, final String innerid, final boolean failIfMultiple) {
    List<? extends PngChunk> list = getById(id, innerid);
    if (list.isEmpty())
      return null;
    if (list.size() > 1 && (failIfMultiple || !list.get(0).allowsMultiple()))
      throw new PngjException("unexpected multiple chunks id=" + id);
    return list.get(list.size() - 1);
  }
View Full Code Here

      shovelInToOut(in, out);
      in.close();
      out.close();
      return outb.toByteArray();
    } catch (Exception e) {
      throw new PngjException(e);
    }
  }
View Full Code Here

  }

  @Override
  public void parseFromRaw(ChunkRaw c) {
    if (!imgInfo.indexed)
      throw new PngjException("only indexed images accept a HIST chunk");
    int nentries = c.data.length / 2;
    hist = new int[nentries];
    for (int i = 0; i < hist.length; i++) {
      hist[i] = PngHelperInternal.readInt2fromBytes(c.data, i * 2);
    }
 
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.