Package ar.com.hjg.pngj

Examples of ar.com.hjg.pngj.PngjException


  }

  @Override
  public ChunkRaw createRawChunk() {
    if (!imgInfo.indexed)
      throw new PngjException("only indexed images accept a HIST chunk");
    ChunkRaw c = null;
    c = createEmptyChunk(hist.length * 2, true);
    for (int i = 0; i < hist.length; i++) {
      PngHelperInternal.writeInt2tobytes(hist[i], c.data, i * 2);
    }
 
View Full Code Here


  }

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

    this.len = len;
    this.id = id;
    this.idbytes = ChunkHelper.toBytes(id);
    for (int i = 0; i < 4; i++) {
      if (idbytes[i] < 65 || idbytes[i] > 122 || (idbytes[i] > 90 && idbytes[i] < 97))
        throw new PngjException("Bad id chunk: must be ascii letters " + id);
    }
    if (alloc)
      allocData();
  }
View Full Code Here

  }

  @Override
  public void parseFromRaw(ChunkRaw chunk) {
    if (chunk.len != 1)
      throw new PngjException("bad chunk length " + chunk);
    mode = chunk.data[0];
  }
View Full Code Here

  }

  @Override
  public void parseFromRaw(ChunkRaw c) {
    if (c.len != 13)
      throw new PngjException("Bad IDHR len " + c.len);
    ByteArrayInputStream st = c.getAsByteStream();
    cols = PngHelperInternal.readInt4(st);
    rows = PngHelperInternal.readInt4(st);
    // bit depth: number of bits per channel
    bitspc = PngHelperInternal.readByte(st);
View Full Code Here

  }

  @Override
  public void parseFromRaw(ChunkRaw chunk) {
    if (chunk.len != 4)
      throw new PngjException("bad chunk " + chunk);
    int g = PngHelperInternal.readInt4fromBytes(chunk.data, 0);
    gamma = ((double) g) / 100000.0;
  }
View Full Code Here

      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

        t = i;
        break;
      }
    }
    if (t <= 0 || t > c.data.length - 2)
      throw new PngjException("bad sPLT chunk: no separator found");
    palName = ChunkHelper.toString(c.data, 0, t);
    sampledepth = PngHelperInternal.readInt1fromByte(c.data, t + 1);
    t += 2;
    int nentries = (c.data.length - t) / (sampledepth == 8 ? 6 : 10);
    palette = new int[nentries * 5];
 
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(0); // compression method: 0
      byte[] textbytes = ChunkHelper.compressBytes(ChunkHelper.toBytes(val), 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

        continue;
      nullsep = i;
      break;
    }
    if (nullsep < 0 || nullsep > c.data.length - 2)
      throw new PngjException("bad zTXt chunk: no separator found");
    key = ChunkHelper.toString(c.data, 0, nullsep);
    int compmet = (int) c.data[nullsep + 1];
    if (compmet != 0)
      throw new PngjException("bad zTXt chunk: unknown compression method");
    byte[] uncomp = ChunkHelper.compressBytes(c.data, nullsep + 2, c.data.length - nullsep - 2, false); // uncompress
    val = ChunkHelper.toString(uncomp);
  }
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.