示例#1
0
  private static int getPictureBytesStartOffset(
      int dataBlockStartOffset, byte[] _dataStream, int dataBlockSize) {
    int realPicoffset = dataBlockStartOffset;
    final int dataBlockEndOffset = dataBlockSize + dataBlockStartOffset;

    // Skip over the PICT block
    int PICTFBlockSize =
        LittleEndian.getShort(
            _dataStream, dataBlockStartOffset + PICT_HEADER_OFFSET); // Should be 68 bytes

    // Now the PICTF1
    int PICTF1BlockOffset = PICTFBlockSize + PICT_HEADER_OFFSET;
    short MM_TYPE =
        LittleEndian.getShort(_dataStream, dataBlockStartOffset + PICT_HEADER_OFFSET + 2);
    if (MM_TYPE == 0x66) {
      // Skip the stPicName
      int cchPicName = LittleEndian.getUnsignedByte(_dataStream, PICTF1BlockOffset);
      PICTF1BlockOffset += 1 + cchPicName;
    }
    int PICTF1BlockSize =
        LittleEndian.getShort(_dataStream, dataBlockStartOffset + PICTF1BlockOffset);

    int unknownHeaderOffset =
        (PICTF1BlockSize + PICTF1BlockOffset) < dataBlockEndOffset
            ? (PICTF1BlockSize + PICTF1BlockOffset)
            : PICTF1BlockOffset;
    realPicoffset += (unknownHeaderOffset + UNKNOWN_HEADER_SIZE);
    if (realPicoffset >= dataBlockEndOffset) {
      realPicoffset -= UNKNOWN_HEADER_SIZE;
    }
    return realPicoffset;
  }
  void serialize(byte[] mainStream, int offset) {
    LittleEndian.putShort(mainStream, offset, (short) _longs.length);
    offset += LittleEndian.SHORT_SIZE;

    for (int x = 0; x < _longs.length; x++) {
      LittleEndian.putInt(mainStream, offset, _longs[x]);
      offset += LittleEndian.INT_SIZE;
    }
  }
  public FIBLongHandler(byte[] mainStream, int offset) {
    int longCount = LittleEndian.getShort(mainStream, offset);
    offset += LittleEndian.SHORT_SIZE;
    _longs = new int[longCount];

    for (int x = 0; x < longCount; x++) {
      _longs[x] = LittleEndian.getInt(mainStream, offset + (x * LittleEndian.INT_SIZE));
    }
  }
  /**
   * For an existing set of text properties, build the list of properties coded for in a given run
   * of properties.
   *
   * @return the number of bytes that were used encoding the properties list
   */
  public int buildTextPropList(
      int containsField, TextProp[] potentialProperties, byte[] data, int dataOffset) {
    int bytesPassed = 0;

    // For each possible entry, see if we match the mask
    // If we do, decode that, save it, and shuffle on
    for (int i = 0; i < potentialProperties.length; i++) {
      // Check there's still data left to read

      // Check if this property is found in the mask
      if ((containsField & potentialProperties[i].getMask()) != 0) {
        if (dataOffset + bytesPassed >= data.length) {
          // Out of data, can't be any more properties to go
          // remember the mask and return
          maskSpecial |= potentialProperties[i].getMask();
          return bytesPassed;
        }

        // Bingo, data contains this property
        TextProp prop = (TextProp) potentialProperties[i].clone();
        int val = 0;
        if (prop.getSize() == 2) {
          val = LittleEndian.getShort(data, dataOffset + bytesPassed);
        } else if (prop.getSize() == 4) {
          val = LittleEndian.getInt(data, dataOffset + bytesPassed);
        } else if (prop.getSize() == 0) {
          // remember "special" bits.
          maskSpecial |= potentialProperties[i].getMask();
          continue;
        }
        prop.setValue(val);
        bytesPassed += prop.getSize();
        textPropList.add(prop);
      }
    }

    // Return how many bytes were used
    return bytesPassed;
  }
示例#5
0
  public Picture(int dataBlockStartOfsset, byte[] _dataStream, boolean fillBytes) {
    this._dataStream = _dataStream;
    this.dataBlockStartOfsset = dataBlockStartOfsset;
    this.dataBlockSize = LittleEndian.getInt(_dataStream, dataBlockStartOfsset);
    this.pictureBytesStartOffset =
        getPictureBytesStartOffset(dataBlockStartOfsset, _dataStream, dataBlockSize);
    this.size = dataBlockSize - (pictureBytesStartOffset - dataBlockStartOfsset);

    if (size < 0) {}

    this.aspectRatioX = extractAspectRatioX(_dataStream, dataBlockStartOfsset);
    this.aspectRatioY = extractAspectRatioY(_dataStream, dataBlockStartOfsset);

    if (fillBytes) {
      fillImageContent();
    }
  }
示例#6
0
 private static int extractAspectRatioY(byte[] _dataStream, int dataBlockStartOffset) {
   return LittleEndian.getShort(_dataStream, dataBlockStartOffset + 0x22) / 10;
 }