Examples of TIFFTag


Examples of com.sun.media.imageio.plugins.tiff.TIFFTag

            int tag = stream.readUnsignedShort();
            int type = stream.readUnsignedShort();
            int count = (int)stream.readUnsignedInt();

            // Get the associated TIFFTag.
            TIFFTag tiffTag = getTag(tag, tagSetList);

            // Ignore unknown fields.
            if(ignoreUnknownFields && tiffTag == null) {
                // Skip the value/offset so as to leave the stream
                // position at the start of the next IFD entry.
                stream.skipBytes(4);

                // XXX Warning message ...

                // Continue with the next IFD entry.
                continue;
            }
           
            long nextTagOffset = stream.getStreamPosition() + 4;
           
            int sizeOfType = TIFFTag.getSizeOfType(type);
            if (count*sizeOfType > 4) {
                long value = stream.readUnsignedInt();
                stream.seek(value);
            }
           
            if (tag == BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS ||
                tag == BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS ||
                tag == BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH) {
                this.stripOrTileByteCountsPosition =
                    stream.getStreamPosition();
            } else if (tag == BaselineTIFFTagSet.TAG_STRIP_OFFSETS ||
                       tag == BaselineTIFFTagSet.TAG_TILE_OFFSETS ||
                       tag == BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT) {
                this.stripOrTileOffsetsPosition =
                    stream.getStreamPosition();
            }

            Object obj = null;

            try {
                switch (type) {
                case TIFFTag.TIFF_BYTE:
                case TIFFTag.TIFF_SBYTE:
                case TIFFTag.TIFF_UNDEFINED:
                case TIFFTag.TIFF_ASCII:
                    byte[] bvalues = new byte[count];
                    stream.readFully(bvalues, 0, count);
               
                    if (type == TIFFTag.TIFF_ASCII) {
                        // Can be multiple strings
                        Vector v = new Vector();
                        boolean inString = false;
                        int prevIndex = 0;
                        for (int index = 0; index <= count; index++) {
                            if (index < count && bvalues[index] != 0) {
                                if (!inString) {
                                // start of string
                                    prevIndex = index;
                                    inString = true;
                                }
                            } else { // null or special case at end of string
                                if (inString) {
                                // end of string
                                    String s = new String(bvalues, prevIndex,
                                                          index - prevIndex);
                                    v.add(s);
                                    inString = false;
                                }
                            }
                        }

                        count = v.size();
                        String[] strings;
                        if(count != 0) {
                            strings = new String[count];
                            for (int c = 0 ; c < count; c++) {
                                strings[c] = (String)v.elementAt(c);
                            }
                        } else {
                            // This case has been observed when the value of
                            // 'count' recorded in the field is non-zero but
                            // the value portion contains all nulls.
                            count = 1;
                            strings = new String[] {""};
                        }
                   
                        obj = strings;
                    } else {
                        obj = bvalues;
                    }
                    break;
               
                case TIFFTag.TIFF_SHORT:
                    char[] cvalues = new char[count];
                    for (int j = 0; j < count; j++) {
                        cvalues[j] = (char)(stream.readUnsignedShort());
                    }
                    obj = cvalues;
                    break;
               
                case TIFFTag.TIFF_LONG:
                case TIFFTag.TIFF_IFD_POINTER:
                    long[] lvalues = new long[count];
                    for (int j = 0; j < count; j++) {
                        lvalues[j] = stream.readUnsignedInt();
                    }
                    obj = lvalues;
                    break;
               
                case TIFFTag.TIFF_RATIONAL:
                    long[][] llvalues = new long[count][2];
                    for (int j = 0; j < count; j++) {
                        llvalues[j][0] = stream.readUnsignedInt();
                        llvalues[j][1] = stream.readUnsignedInt();
                    }
                    obj = llvalues;
                    break;
               
                case TIFFTag.TIFF_SSHORT:
                    short[] svalues = new short[count];
                    for (int j = 0; j < count; j++) {
                        svalues[j] = stream.readShort();
                    }
                    obj = svalues;
                    break;
               
                case TIFFTag.TIFF_SLONG:
                    int[] ivalues = new int[count];
                    for (int j = 0; j < count; j++) {
                        ivalues[j] = stream.readInt();
                    }
                    obj = ivalues;
                    break;
               
                case TIFFTag.TIFF_SRATIONAL:
                    int[][] iivalues = new int[count][2];
                    for (int j = 0; j < count; j++) {
                        iivalues[j][0] = stream.readInt();
                        iivalues[j][1] = stream.readInt();
                    }
                    obj = iivalues;
                    break;
               
                case TIFFTag.TIFF_FLOAT:
                    float[] fvalues = new float[count];
                    for (int j = 0; j < count; j++) {
                        fvalues[j] = stream.readFloat();
                    }
                    obj = fvalues;
                    break;
               
                case TIFFTag.TIFF_DOUBLE:
                    double[] dvalues = new double[count];
                    for (int j = 0; j < count; j++) {
                        dvalues[j] = stream.readDouble();
                    }
                    obj = dvalues;
                    break;
               
                default:
                    // XXX Warning
                    break;
                }
            } catch(EOFException eofe) {
                // The TIFF 6.0 fields have tag numbers less than or equal
                // to 532 (ReferenceBlackWhite) or equal to 33432 (Copyright).
                // If there is an error reading a baseline tag, then re-throw
                // the exception and fail; otherwise continue with the next
                // field.
                if(BaselineTIFFTagSet.getInstance().getTag(tag) == null) {
                    throw eofe;
                }
            }
           
            if (tiffTag == null) {
                // XXX Warning: unknown tag
            } else if (!tiffTag.isDataTypeOK(type)) {
                // XXX Warning: bad data type
            } else if (tiffTag.isIFDPointer() && obj != null) {
                stream.mark();
                stream.seek(((long[])obj)[0]);

                List tagSets = new ArrayList(1);
                tagSets.add(tiffTag.getTagSet());
                TIFFIFD subIFD = new TIFFIFD(tagSets);

                // XXX Use same ignore policy for sub-IFD fields?
                subIFD.initialize(stream, ignoreUnknownFields);
                obj = subIFD;
                stream.reset();
            }

            if (tiffTag == null) {
                tiffTag = new TIFFTag(null, tag, 1 << type, null);
            }

            // Add the field if its contents have been initialized which
            // will not be the case if an EOF was ignored above.
            if(obj != null) {
View Full Code Here

Examples of com.sun.media.imageio.plugins.tiff.TIFFTag

        Iterator iter = iterator();
        while (iter.hasNext()) {
            TIFFField f = (TIFFField)iter.next();
           
            TIFFTag tag = f.getTag();

            int type = f.getType();
            int count = f.getCount();

            // Hack to deal with unknown tags
            if (type == 0) {
                type = TIFFTag.TIFF_UNDEFINED;
            }
            int size = count*TIFFTag.getSizeOfType(type);

            if (type == TIFFTag.TIFF_ASCII) {
                int chars = 0;
                for (int i = 0; i < count; i++) {
                    chars += f.getAsString(i).length() + 1;
                }
                count = chars;
                size = count;
            }

            int tagNumber = f.getTagNumber();
            stream.writeShort(tagNumber);
            stream.writeShort(type);
            stream.writeInt(count);

            // Write a dummy value to fill space
            stream.writeInt(0);
            stream.mark(); // Mark beginning of next field
            stream.skipBytes(-4);

            long pos;

            if (size > 4 || tag.isIFDPointer()) {
                // Ensure IFD or value is written on a word boundary
                nextSpace = (nextSpace + 3) & ~0x3;

                stream.writeInt((int)nextSpace);
                stream.seek(nextSpace);
                pos = nextSpace;

                if (tag.isIFDPointer()) {
                    TIFFIFD subIFD = (TIFFIFD)f.getData();
                    subIFD.writeToStream(stream);
                    nextSpace = subIFD.lastPosition;
                } else {
                    writeTIFFFieldToStream(f, stream);
View Full Code Here

Examples of it.geosolutions.imageio.plugins.tiff.TIFFTag

          set = setIdPair[0].toUpperCase();
        }
        String keyName = setIdPair[setIdPair.length - 1];
        if (GeoTiffConstants.isNumeric(keyName)){
          final String value = tiffTagsMetadata.get(key);
          final TIFFTag tag = getAsciiTag(set, Integer.valueOf(keyName));
          if (tag != null){
            Element field = createFieldElement(tag);
                Element data = new Element(GeoTiffConstants.GEOTIFF_ASCIIS_TAG);
                field.addContent(data);
                data.addContent(createAsciiElement(value));
View Full Code Here

Examples of it.geosolutions.imageio.plugins.tiff.TIFFTag

          set = setIdPair[0].toUpperCase();
        }
        String keyName = setIdPair[setIdPair.length - 1];
        if (GeoTiffConstants.isNumeric(keyName)){
          final String value = tiffTagsMetadata.get(key);
          final TIFFTag tag = getAsciiTag(set, Integer.valueOf(keyName));
          if (tag != null){
            Element field = createFieldElement(tag);
                Element data = new Element(GeoTiffConstants.GEOTIFF_ASCIIS_TAG);
                field.addContent(data);
                data.addContent(createAsciiElement(value));
View Full Code Here

Examples of net.sourceforge.jiu.codecs.tiff.TIFFTag

    UnsupportedTypeException
  {
    int index = 0;
    while (index < tags.size())
    {
      TIFFTag tag = (TIFFTag)tags.elementAt(index++);
      int id = tag.getId();
      int count = tag.getCount();
      int type = tag.getType();
      boolean isNotInt = !tag.isInt();
      switch(id)
      {
        case(TAG_ARTIST):
        {
          artist = tag.getString();
          break;
        }
        case(TAG_BITS_PER_SAMPLE):
        {
          if (isNotInt)
          {
            throw new InvalidFileStructureException("Bits per " +
              "sample value(s) must be byte/short/long; type=" +
              type);
          }
          if (count == 1)
          {
            bitsPerSample = new int[1];
            bitsPerSample[0] = tag.getOffset();
            bitsPerPixel = bitsPerSample[0];
          }
          else
          {
            bitsPerPixel = 0;
            bitsPerSample = new int[count];
            for (int i = 0; i < count; i++)
            {
              bitsPerSample[i] = tag.getElementAsInt(i);
              if (bitsPerSample[i] < 1)
              {
                throw new InvalidFileStructureException("Bits per " +
                  "sample value #" + i + " is smaller than 1.");
              }
              bitsPerPixel += bitsPerSample[i];
            }
          }
          break;
        }
        case(TAG_COLOR_MAP):
        {
          if ((count % 3) != 0)
          {
            throw new InvalidFileStructureException("Number of palette entries must be divideable by three without rest; " + count);
          }
          if (count < 3 || count > 768)
          {
            throw new UnsupportedTypeException("Unsupported number of palette entries: " + count + ".");
          }
          if (type != TAG_TYPE_SHORT)
          {
            throw new UnsupportedTypeException("Unsupported number type for palette entries: " + type);
          }
          int numEntries = count / 3;
          palette = new Palette(numEntries, 255);
          int vectorIndex = 0;
          for (int paletteIndex = 0; paletteIndex < numEntries; paletteIndex++)
          {
            palette.putSample(RGBIndex.INDEX_RED, paletteIndex, tag.getElementAsInt(vectorIndex++) >> 8);
          }
          for (int paletteIndex = 0; paletteIndex < numEntries; paletteIndex++)
          {
            palette.putSample(RGBIndex.INDEX_GREEN, paletteIndex, tag.getElementAsInt(vectorIndex++) >> 8);
          }
          for (int paletteIndex = 0; paletteIndex < numEntries; paletteIndex++)
          {
            palette.putSample(RGBIndex.INDEX_BLUE, paletteIndex, tag.getElementAsInt(vectorIndex++) >> 8);
          }
          break;
        }
        case(TAG_COMPRESSION):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              " single byte/short/long value for compression " +
              "(count=" + count + ", type=" + type + ").");
          }
          compression = tag.getOffset();
          break;
        }
        case(TAG_DATE_TIME):
        {
          dateTime = tag.getString();
          if (dateTime != null)
          {
            dateTime = dateTime.trim();
          }
          if (dateTime != null)
          {
            SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
            if (timeZone != null)
            {
              format.setCalendar(new GregorianCalendar(timeZone));
            }
            try
            {
              date = format.parse(dateTime);
            }
            catch (ParseException pe)
            {
              date = null;
            }
          }
          break;
        }
        case(TAG_HOST_COMPUTER):
        {
          hostComputer = tag.getString();
          break;
        }
        case(TAG_IMAGE_DESCRIPTION):
        {
          imageDescription = tag.getString();
          break;
        }
        case(TAG_IMAGE_WIDTH):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for image width " +
              "(count=" + count + ", type=" + type + ").");
          }
          width = tag.getOffset();
          break;
        }
        case(TAG_IMAGE_LENGTH):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for image height " +
              "(count=" + count + ", type=" + type + ").");
          }
          height = tag.getOffset();
          break;
        }
        case(TAG_MAKE):
        {
          make = tag.getString();
          break;
        }
        case(TAG_MODEL):
        {
          model = tag.getString();
          break;
        }
        case(TAG_ORIENTATION):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for image height " +
              "(count=" + count + ", type=" + type + ").");
          }
          orientation = tag.getOffset();
          break;
        }
        case(TAG_PHOTOMETRIC_INTERPRETATION):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for photometric interpretation.");
          }
          photometricInterpretation = tag.getOffset();
          break;
        }
        case(TAG_RESOLUTION_UNIT):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for planar configuration.");
          }
          resolutionUnit = tag.getOffset();
          break;
        }
        case(TAG_RESOLUTION_X):
        {
          if (count != 1 || type != TAG_TYPE_RATIONAL)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for planar configuration.");
          }
          Object o = tag.getObject(0);
          if (o != null && o instanceof TIFFRational)
          {
            TIFFRational rational = (TIFFRational)o;
            resolutionX = rational.getAsDouble();
          }
          break;
        }
        case(TAG_RESOLUTION_Y):
        {
          if (count != 1 || type != TAG_TYPE_RATIONAL)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for planar configuration.");
          }
          Object o = tag.getObject(0);
          if (o != null && o instanceof TIFFRational)
          {
            TIFFRational rational = (TIFFRational)o;
            resolutionY = rational.getAsDouble();
          }
          break;
        }
        case(TAG_PLANAR_CONFIGURATION):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for planar configuration.");
          }
          planarConfiguration = tag.getOffset();
          break;
        }
        case(TAG_ROWS_PER_STRIP):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for image height.");
          }
          rowsPerStrip = tag.getOffset();
          break;
        }
        case(TAG_SAMPLES_PER_PIXEL):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for samples per pixel.");
          }
          samplesPerPixel = tag.getOffset();
          break;
        }
        case(TAG_SOFTWARE):
        {
          software = tag.getString();
          break;
        }
        case(TAG_STRIP_BYTE_COUNTS):
        {
          if (count < 1)
          {
            throw new InvalidFileStructureException("Need at least one strip offset.");
          }
          if (count == 1)
          {
            if (isNotInt)
            {
              throw new InvalidFileStructureException("There is " +
                "only one strip offset, but its type is not integer.");
            }
            stripByteCounts = new Vector();
            stripByteCounts.addElement(new Long(tag.getOffset()));
          }
          else
          {
            stripByteCounts = tag.getVector();
          }
          break;
        }
        case(TAG_STRIP_OFFSETS):
        {
          if (count < 1)
          {
            throw new InvalidFileStructureException("Need at least one strip offset.");
          }
          if (count == 1)
          {
            if (isNotInt)
            {
              throw new InvalidFileStructureException("There is " +
                "only one strip offset, but its type is not integer.");
            }
            stripOffsets = new Vector();
            stripOffsets.addElement(new Long(tag.getOffset()));
          }
          else
          {
            stripOffsets = tag.getVector();
          }
          numStrips = count;
          numTiles = count;
          horizontalTiles = 1;
          verticalTiles = count;
          break;
        }
        case(TAG_T4_OPTIONS):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for T4 Options.");
          }
          t4Options = tag.getOffset();
          break;
        }
        case(TAG_T6_OPTIONS):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for T6 Options.");
          }
          t6Options = tag.getOffset();
          break;
        }
        case(TAG_TILE_HEIGHT):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for image height " +
              "(count=" + count + ", type=" + type + ").");
          }
          tileHeight = tag.getOffset();
          if (tileHeight < 1)
          {
            throw new InvalidFileStructureException("Tile height must be one or larger.");
          }
          verticalTiles = height / tileHeight;
          if ((height % tileHeight) != 0)
          {
            verticalTiles++;
          }
          break;
        }
        case(TAG_TILE_OFFSETS):
        {
          if (count < 1)
          {
            throw new InvalidFileStructureException("Need at least one tile offset.");
          }
          if (count == 1)
          {
            if (isNotInt)
            {
              throw new InvalidFileStructureException("There is " +
                "only one tile offset, but its type is not integer.");
            }
            tileOffsets = new Vector();
            tileOffsets.addElement(new Long(tag.getOffset()));
          }
          else
          {
            tileOffsets = tag.getVector();
          }
          numStrips = count;
          numTiles = count;
          horizontalTiles = 1;
          verticalTiles = count;
          break;
        }
        case(TAG_TILE_WIDTH):
        {
          if (count != 1 || isNotInt)
          {
            throw new InvalidFileStructureException("Expected " +
              "single byte/short/long value for image height " +
              "(count=" + count + ", type=" + type + ").");
          }
          tileWidth = tag.getOffset();
          if (tileWidth < 1)
          {
            throw new InvalidFileStructureException("Tile width must be one or larger.");
          }
          horizontalTiles = width / tileWidth;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.