Package net.sourceforge.jiu.codecs

Examples of net.sourceforge.jiu.codecs.UnsupportedTypeException


  {
    Integer compression = new Integer(ifd.getCompression());
    Class decoderClass = (Class)decoders.get(compression);
    if (decoderClass == null)
    {
      throw new UnsupportedTypeException("Could not create decoder for this compression type: " +
        compression.intValue());
    }
    Object instance;
    try
    {
      instance = decoderClass.newInstance();
    }
    catch (Exception e)
    {
      throw new UnsupportedTypeException("Could not create decoder for this compression type.");
    }
    if (instance instanceof TIFFDecoder)
    {
      TIFFDecoder decoder = (TIFFDecoder)instance;
      decoder.setCodec(codec);
      decoder.setTileIndex(tileIndex);
      decoder.setImageFileDirectory(ifd);
      try
      {
        decoder.initialize();
      }
      catch (MissingParameterException mpe)
      {
        throw new UnsupportedTypeException("Unable to initialize decoder: " + mpe.toString());
      }
      return decoder;
    }
    else
    {
      throw new UnsupportedTypeException("Could not create decoder for this compression type.");
    }
  }
View Full Code Here


          image = new MemoryRGB48Image(width, height);
          break;
        }
        default:
        {
          throw new UnsupportedTypeException("Unsupported image type.");
        }
      }
      setImage(image);
    }
    int tileIndex = 0;
View Full Code Here

        bytesPerRow = width * 3;
        break;
      }
      default:
      {
        throw new UnsupportedTypeException("Depths other than 1, 8 and 24 " +
          "unsupported when reading RAS stream; found " + depth);
      }
    }
    paddingBytes = (bytesPerRow % 2);
    numColors = 1 << depth;
    //length = ArrayConverter.getIntBE(header, 16);
    type = ArrayConverter.getIntBE(header, 20);
    if (type != COMPRESSION_NONE)
    {
      throw new UnsupportedTypeException("Only uncompressed " +
        "RAS streams are read; found " + type);
    }
    mapType = ArrayConverter.getIntBE(header, 24);
    mapLength = ArrayConverter.getIntBE(header, 28);
    if (mapLength != 0)
    {
      if (depth != 8)
      {
        throw new UnsupportedTypeException("Cannot handle Sun RAS " +
          "input streams with color maps and a depth other than " +
          "8 (found " + depth + ").");
      }
      if (mapLength != 768)
      {
        throw new UnsupportedTypeException("Cannot handle Sun RAS " +
          "input streams with color maps of a length different " +
          "than 768; found " + mapLength);
      }
      if (mapType != 1)
      {
        throw new UnsupportedTypeException("Cannot handle Sun RAS " +
          "input streams with color maps of a type other than " +
          "1; found " + mapType);
      }
      palette = readPalette();
    }
View Full Code Here

    WrongParameterException
  {
    PixelImage image = getImage();
    if (image == null || (!(image instanceof Paletted8Image)))
    {
      throw new UnsupportedTypeException("Must have non-null image that is a Paletted8Image.");
    }
    saveHeader(image);
    if (image instanceof Paletted8Image)
    {
      saveData((Paletted8Image)image);
View Full Code Here

      bytesPerRow = width * 3;
      depth = 24;
    }
    else
    {
      throw new UnsupportedTypeException("Cannot store image types " +
        "other than bilevel, gray8, paletted8 and RGB24.");
    }
    out.writeInt(depth);
    paddingBytes = (bytesPerRow % 2);
    numColors = 1 << depth;
View Full Code Here

          {
            imageType = TYPE_GRAY8;
          }
          else
          {
            throw new UnsupportedTypeException("Only bit depths 1, 4 and 8 are supported for bilevel and grayscale images.");
          }
        }
        break;
      }
      case(PHOTOMETRIC_PALETTED):
      {
        if (getPalette() == null)
        {
          throw new InvalidFileStructureException("No palette found in paletted image.");
        }
        break;
      }
      case(PHOTOMETRIC_TRUECOLOR_RGB):
      {
        if (planarConfiguration != PLANAR_CONFIGURATION_CHUNKY)
        {
          throw new UnsupportedTypeException("Cannot handle planar configuration other than chunky for RGB images.");
        }
        if (bitsPerSample.length != 3)
        {
          throw new UnsupportedTypeException("Found RGB truecolor image, but instead of three " + bitsPerSample.length + " component(s).");
        }
        if (bitsPerPixel == 24)
        {
          imageType = TYPE_RGB24_INTERLEAVED;
        }
        else
        if (bitsPerPixel == 48)
        {
          imageType = TYPE_RGB48_INTERLEAVED;
        }
        else
        {
          throw new UnsupportedTypeException("Unsupported RGB truecolor image color depth: " + bitsPerPixel + ".");
        }
        break;
      }
      case(PHOTOMETRIC_TRUECOLOR_LOGLUV):
      {
        if (planarConfiguration == PLANAR_CONFIGURATION_CHUNKY)
        {
          imageType = TYPE_LOGLUV32_INTERLEAVED;
        }
        else
        {
          throw new UnsupportedTypeException("Cannot handle planar configuration other than chunky for RGB images.");
        }
        break;
      }
      case(PHOTOMETRIC_LOGL):
      {
        imageType = TYPE_LOGL;
        break;
      }
      case(PHOTOMETRIC_TRUECOLOR_CMYK):
      {
        if (planarConfiguration == PLANAR_CONFIGURATION_CHUNKY)
        {
          imageType = TYPE_CMYK32_INTERLEAVED;
        }
        /*else
        if (planarConfiguration == PLANAR_CONFIGURATION_PLANAR)
        {
          imageType = TYPE_CMYK32_PLANAR;
        }*/
        else
        {
          throw new UnsupportedTypeException("Cannot handle planar configuration other than chunky for CMYK images.");
        }
        break;
      }
      default:
      {
        throw new UnsupportedTypeException("Unsupported color type: "  + photometricInterpretation + ".");
      }
    }
    if (compression == COMPRESSION_CCITT_GROUP3_1D_MODIFIED_HUFFMAN)
    {
      if (bitsPerPixel != 1)
      {
        throw new UnsupportedTypeException("Number of bits per pixel must be 1 for " +
          "compression type: " + getCompressionName(compression) + ".");
      }
      imageType = TYPE_BILEVEL_BYTE;
    }
    // TODO more validity checks
View Full Code Here

          {
            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;
          if ((width % tileWidth) != 0)
          {
            horizontalTiles++;
          }
          break;
        }
      }
    }
    if (planarConfiguration == -1)
    {
      planarConfiguration = PLANAR_CONFIGURATION_CHUNKY;
    }
    if (photometricInterpretation == TIFFConstants.PHOTOMETRIC_PALETTED)
    {
      if (bitsPerPixel == 4)
      {
        imageType = TYPE_PALETTED4;
      }
      else
      if (bitsPerPixel == 8)
      {
        imageType = TYPE_PALETTED8;
      }
      else
      {
        throw new UnsupportedTypeException("Only paletted images with 4 or 8 bits per sample are supported.");
      }
    }
    if (resolutionUnit == 2 && resolutionX > 0.0 && resolutionY > 0.0)
    {
      dpiX = (int)resolutionX;
View Full Code Here

  {
    if (resolutionIndex != PCD_RESOLUTION_1 &&
        resolutionIndex != PCD_RESOLUTION_2 &&
        resolutionIndex != PCD_RESOLUTION_3)
    {
      throw new UnsupportedTypeException("Error reading PCD input " +
        "stream. Only the three lowest resolutions are supported.");
    }
    if (in == null)
    {
      throw new IllegalArgumentException("Input file is missing " +
View Full Code Here

    {
      throw new MissingParameterException("RandomAccessFile object needed in PCDCodec.");
    }
    if (getMode() != CodecMode.LOAD)
    {
      throw new UnsupportedTypeException("PCDCodec can only load images.");
    }
    try
    {
      load();
    }
View Full Code Here

    }
    in.readInt(); // read and discard "file size" field
    type = in.readInt();
    if (type != MAGIC_ILBM && type != MAGIC_PBM)
    {
      throw new UnsupportedTypeException("Cannot load image. The " +
        "input stream is an IFF file, but not of type ILBM or PBM" +
        " (" + getChunkName(type) + ")");
    }
    PixelImage result = null;
    boolean hasBMHD = false;
    boolean hasCAMG = false;
    do
    {
      int magic = in.readInt();
      //System.out.println(chunkNameToString(magic));
      int size = in.readInt();
      // chunks must always have an even number of bytes
      if ((size & 1) == 1)
      {
        size++;
      }
      //System.out.println("Chunk " + getChunkName(magic) + ", size=" + size);
      switch(magic)
      {
        case(MAGIC_BMHD): // main header with width, height, bit depth
        {
          if (hasBMHD)
          {
            throw new InvalidFileStructureException("Error in " +
              "IFF file: more than one BMHD chunk.");
          }
          if (size != SIZE_BMHD)
          {
            throw new InvalidFileStructureException("Cannot " +
              "load image. The bitmap header chunk does not " +
              "have the expected size.");
          }
          // image resolution in pixels
          width = in.readShort();
          height = in.readShort();
          if (width < 1 || height < 1)
          {
            throw new InvalidFileStructureException("Cannot " +
              "load image. The IFF file's bitmap header " +
              "contains invalid width and height values: " +
              width + ", " + height);
          }
          // next four bytes don't matter
          in.skipBytes(4);
          // color depth, 1..8 or 24
          numPlanes = in.readByte();
          if ((numPlanes != 24) && (numPlanes < 1 || numPlanes > 8))
          {
            throw new UnsupportedTypeException("Cannot load " +
              "image, unsupported number of bits per pixel: " +
              numPlanes);
          }
          //System.out.println("\nnum planes=" + numPlanes);
          in.readByte(); // discard "masking" value
          // compression type, must be 0 or 1
          compression = in.readByte();
          if (compression != COMPRESSION_NONE &&
              compression != COMPRESSION_RLE)
          {
            throw new UnsupportedTypeException("Cannot load " +
              "image, unsupported compression type: " +
              compression);
          }
          //System.out.println(getCompressionName(compression));
          in.skipBytes(9);
View Full Code Here

TOP

Related Classes of net.sourceforge.jiu.codecs.UnsupportedTypeException

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.