Beispiel #1
0
 /**
  * This will perform a lookup into the color lookup table.
  *
  * @param componentNumber The component number, probably 1,2,3,3.
  * @param lookupIndex The zero-based index into the table, should not exceed the high value.
  * @return The value that was from the lookup table.
  * @throws IOException If there is an error looking up the color.
  */
 public int lookupColor(int componentNumber, int lookupIndex) throws IOException {
   COSBase lookupTable = array.getObject(3);
   PDColorSpace baseColor = getBaseColorSpace();
   byte[] data = getLookupData();
   int numberOfComponents = baseColor.getNumberOfComponents();
   return (data[componentNumber * numberOfComponents + lookupIndex] + 256) % 256;
 }
Beispiel #2
0
  /**
   * This will get the color space that acts as the index for this color space.
   *
   * @return The base color space.
   * @throws IOException If there is error creating the base color space.
   */
  public PDColorSpace getBaseColorSpace() throws IOException {
    PDColorSpace retval = null;
    COSBase base = array.getObject(1);
    if (base instanceof COSName) {
      retval = PDColorSpaceFactory.createColorSpace((COSName) base);
    } else {
      throw new IOException("Error:unknown base colorspace");
    }

    return retval;
  }
Beispiel #3
0
 private byte[] getLookupData() throws IOException {
   COSBase lookupTable = array.getObject(3);
   byte[] data = null;
   if (lookupTable instanceof COSString) {
     data = ((COSString) lookupTable).getBytes();
   } else if (lookupTable instanceof COSStream) {
     // Data will be small so just load the whole thing into memory for
     // easier processing
     COSStream lookupStream = (COSStream) lookupTable;
     InputStream input = lookupStream.getUnfilteredStream();
     ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
     byte[] buffer = new byte[1024];
     int amountRead;
     while ((amountRead = input.read(buffer, 0, buffer.length)) != -1) {
       output.write(buffer, 0, amountRead);
     }
     data = output.toByteArray();
   } else if (lookupTable == null) {
     data = new byte[0];
   } else {
     throw new IOException("Error: Unknown type for lookup table " + lookupTable);
   }
   return data;
 }
Beispiel #4
0
 /**
  * Constructor.
  *
  * @param iccArray The ICC stream object.
  */
 public PDICCBased(COSArray iccArray) {
   array = iccArray;
   stream = (COSStream) iccArray.getObject(1);
 }
Beispiel #5
0
 /**
  * Get the highest value for the lookup.
  *
  * @return The hival entry.
  */
 public int getHighValue() {
   return ((COSNumber) array.getObject(2)).intValue();
 }