Example #1
0
 /*     */ MarkerSegment(JPEGBuffer paramJPEGBuffer) /*     */ throws IOException /*     */ {
   /*  58 */ paramJPEGBuffer.loadBuf(3);
   /*  59 */ this.tag = (paramJPEGBuffer.buf[(paramJPEGBuffer.bufPtr++)] & 0xFF);
   /*  60 */ this.length = ((paramJPEGBuffer.buf[(paramJPEGBuffer.bufPtr++)] & 0xFF) << 8);
   /*  61 */ this.length |= paramJPEGBuffer.buf[(paramJPEGBuffer.bufPtr++)] & 0xFF;
   /*  62 */ this.length -= 2;
   /*  63 */ paramJPEGBuffer.bufAvail -= 3;
   /*     */
   /*  66 */ paramJPEGBuffer.loadBuf(this.length);
   /*     */ }
Example #2
0
 JFIFThumbJPEG(JPEGBuffer buffer, int length, JPEGImageReader reader) throws IOException {
   super(buffer);
   // Compute the final stream position
   long finalPos = streamPos + (length - PREAMBLE_SIZE);
   // Set the stream back to the start of the thumbnail
   // and read its metadata (but don't decode the image)
   buffer.iis.seek(streamPos);
   thumbMetadata = new JPEGMetadata(false, true, buffer.iis, reader);
   // Set the stream to the computed final position
   buffer.iis.seek(finalPos);
   // Clear the now invalid buffer
   buffer.bufAvail = 0;
   buffer.bufPtr = 0;
 }
Example #3
0
 JFIFThumbUncompressed(JPEGBuffer buffer, int width, int height, int skip, String name)
     throws IOException {
   super(buffer);
   thumbWidth = width;
   thumbHeight = height;
   // Now skip the thumbnail data
   buffer.skipData(skip);
   this.name = name;
 }
Example #4
0
  /** Constructs a JFIF header by reading from a stream wrapped in a JPEGBuffer. */
  JFIFMarkerSegment(JPEGBuffer buffer) throws IOException {
    super(buffer);
    buffer.bufPtr += ID_SIZE; // skip the id, we already checked it

    majorVersion = buffer.buf[buffer.bufPtr++];
    minorVersion = buffer.buf[buffer.bufPtr++];
    resUnits = buffer.buf[buffer.bufPtr++];
    Xdensity = (buffer.buf[buffer.bufPtr++] & 0xff) << 8;
    Xdensity |= buffer.buf[buffer.bufPtr++] & 0xff;
    Ydensity = (buffer.buf[buffer.bufPtr++] & 0xff) << 8;
    Ydensity |= buffer.buf[buffer.bufPtr++] & 0xff;
    thumbWidth = buffer.buf[buffer.bufPtr++] & 0xff;
    thumbHeight = buffer.buf[buffer.bufPtr++] & 0xff;
    buffer.bufAvail -= DATA_SIZE;
    if (thumbWidth > 0) {
      thumb = new JFIFThumbRGB(buffer, thumbWidth, thumbHeight);
    }
  }
 DQTMarkerSegment(JPEGBuffer buffer) throws IOException {
   super(buffer);
   int count = length;
   while (count > 0) {
     Qtable newGuy = new Qtable(buffer);
     tables.add(newGuy);
     count -= newGuy.data.length + 1;
   }
   buffer.bufAvail -= length;
 }
Example #6
0
    JFIFExtensionMarkerSegment(JPEGBuffer buffer, JPEGImageReader reader) throws IOException {

      super(buffer);
      buffer.bufPtr += ID_SIZE; // skip the id, we already checked it

      code = buffer.buf[buffer.bufPtr++] & 0xff;
      buffer.bufAvail -= DATA_SIZE;
      if (code == THUMB_JPEG) {
        thumb = new JFIFThumbJPEG(buffer, length, reader);
      } else {
        buffer.loadBuf(2);
        int thumbX = buffer.buf[buffer.bufPtr++] & 0xff;
        int thumbY = buffer.buf[buffer.bufPtr++] & 0xff;
        buffer.bufAvail -= 2;
        // following constructors handle bufAvail
        if (code == THUMB_PALETTE) {
          thumb = new JFIFThumbPalette(buffer, thumbX, thumbY);
        } else {
          thumb = new JFIFThumbRGB(buffer, thumbX, thumbY);
        }
      }
    }
 Qtable(JPEGBuffer buffer) throws IIOException {
   elementPrecision = buffer.buf[buffer.bufPtr] >>> 4;
   tableID = buffer.buf[buffer.bufPtr++] & 0xf;
   if (elementPrecision != 0) {
     // IJG is compiled for 8-bits, so this shouldn't happen
     throw new IIOException("Unsupported element precision");
   }
   data = new int[QTABLE_SIZE];
   // Read from zig-zag order to natural order
   for (int i = 0; i < QTABLE_SIZE; i++) {
     data[i] = buffer.buf[buffer.bufPtr + zigzag[i]] & 0xff;
   }
   buffer.bufPtr += QTABLE_SIZE;
 }
Example #8
0
    ICCMarkerSegment(JPEGBuffer buffer) throws IOException {
      super(buffer); // gets whole segment or fills the buffer
      if (debug) {
        System.out.println("Creating new ICC segment");
      }
      buffer.bufPtr += ID_SIZE; // Skip the id
      buffer.bufAvail -= ID_SIZE;
      /*
       * Reduce the stored length by the id size.  The stored
       * length is used to store the length of the profile
       * data only.
       */
      length -= ID_SIZE;

      // get the chunk number
      int chunkNum = buffer.buf[buffer.bufPtr] & 0xff;
      // get the total number of chunks
      numChunks = buffer.buf[buffer.bufPtr + 1] & 0xff;

      if (chunkNum > numChunks) {
        throw new IIOException("Image format Error; chunk num > num chunks");
      }

      // if there are no more chunks, set up the data
      if (numChunks == 1) {
        // reduce the stored length by the two chunk numbering bytes
        length -= 2;
        profile = new byte[length];
        buffer.bufPtr += 2;
        buffer.bufAvail -= 2;
        buffer.readData(profile);
        inICC = false;
      } else {
        // If we store them away, include the chunk numbering bytes
        byte[] profileData = new byte[length];
        // Now reduce the stored length by the
        // two chunk numbering bytes
        length -= 2;
        buffer.readData(profileData);
        chunks = new ArrayList();
        chunks.add(profileData);
        chunksRead = 1;
        inICC = true;
      }
    }
Example #9
0
 /*     */ void loadData(JPEGBuffer paramJPEGBuffer) /*     */ throws IOException /*     */ {
   /* 127 */ this.data = new byte[this.length];
   /* 128 */ paramJPEGBuffer.readData(this.data);
   /*     */ }
Example #10
0
 protected JFIFThumb(JPEGBuffer buffer) throws IOException {
   // Save the stream position for reading the thumbnail later
   streamPos = buffer.getStreamPosition();
 }
Example #11
0
    boolean addData(JPEGBuffer buffer) throws IOException {
      if (debug) {
        System.out.println("Adding to ICC segment");
      }
      // skip the tag
      buffer.bufPtr++;
      buffer.bufAvail--;
      // Get the length, but not in length
      int dataLen = (buffer.buf[buffer.bufPtr++] & 0xff) << 8;
      dataLen |= buffer.buf[buffer.bufPtr++] & 0xff;
      buffer.bufAvail -= 2;
      // Don't include length itself
      dataLen -= 2;
      // skip the id
      buffer.bufPtr += ID_SIZE; // Skip the id
      buffer.bufAvail -= ID_SIZE;
      /*
       * Reduce the stored length by the id size.  The stored
       * length is used to store the length of the profile
       * data only.
       */
      dataLen -= ID_SIZE;

      // get the chunk number
      int chunkNum = buffer.buf[buffer.bufPtr] & 0xff;
      if (chunkNum > numChunks) {
        throw new IIOException("Image format Error; chunk num > num chunks");
      }

      // get the number of chunks, which should match
      int newNumChunks = buffer.buf[buffer.bufPtr + 1] & 0xff;
      if (numChunks != newNumChunks) {
        throw new IIOException("Image format Error; icc num chunks mismatch");
      }
      dataLen -= 2;
      if (debug) {
        System.out.println(
            "chunkNum: " + chunkNum + ", numChunks: " + numChunks + ", dataLen: " + dataLen);
      }
      boolean retval = false;
      byte[] profileData = new byte[dataLen];
      buffer.readData(profileData);
      chunks.add(profileData);
      length += dataLen;
      chunksRead++;
      if (chunksRead < numChunks) {
        inICC = true;
      } else {
        if (debug) {
          System.out.println("Completing profile; total length is " + length);
        }
        // create an array for the whole thing
        profile = new byte[length];
        // copy the existing chunks, releasing them
        // Note that they may be out of order

        int index = 0;
        for (int i = 1; i <= numChunks; i++) {
          boolean foundIt = false;
          for (int chunk = 0; chunk < chunks.size(); chunk++) {
            byte[] chunkData = (byte[]) chunks.get(chunk);
            if (chunkData[0] == i) { // Right one
              System.arraycopy(chunkData, 2, profile, index, chunkData.length - 2);
              index += chunkData.length - 2;
              foundIt = true;
            }
          }
          if (foundIt == false) {
            throw new IIOException("Image Format Error: Missing ICC chunk num " + i);
          }
        }

        chunks = null;
        chunksRead = 0;
        numChunks = 0;
        inICC = false;
        retval = true;
      }
      return retval;
    }