Package net.sourceforge.jiu.codecs

Examples of net.sourceforge.jiu.codecs.InvalidFileStructureException


    RandomAccessFile in = getRandomAccessFile();
    in.seek(nextIfdOffset);
    short numTags = readShort();
    if (numTags < 0)
    {
      throw new InvalidFileStructureException("Number of tags in IFD " +
        "smaller than 1 @" + nextIfdOffset + ": " + numTags);
    }
    for (int i = 0; i < numTags; i++)
    {
      TIFFTag tag = readTag();
View Full Code Here


      short numTags = readShort();
      in.skipBytes(numTags * 12);
      nextIfdOffset = readInt();
      if (nextIfdOffset == 0)
      {
        throw new InvalidFileStructureException("Could only skip " +
          skipped + " image file directories, no more images in file.");
      }
      skipped++;
    }
  }
View Full Code Here

    }
    width = ArrayConverter.getIntBE(header, 4);
    height = ArrayConverter.getIntBE(header, 8);
    if (width < 1 || height < 1)
    {
      throw new InvalidFileStructureException("Width and height must both " +
        "be larger than zero; found width=" + width + ", height=" +
        height + ".");
    }
    setBoundsIfNecessary(width, height);
    checkBounds(width, height);
View Full Code Here

        in.readFully(buffer[0], 0, width);
        paletted8Image.putByteSamples(0, 0, destY, getBoundsWidth(), 1, buffer[0], getBoundsX1());
      }
      if (in.skipBytes(paddingBytes) != paddingBytes)
      {
        throw new InvalidFileStructureException("Could not skip " +
          "byte after row " + y + ".");
      }
      setProgress(y, getBoundsY2() + 1);
    }
    return result;
View Full Code Here

      for (int i = 0; i < numColors; i++)
      {
        int value = in.readUnsignedByte();
        if (value == -1)
        {
          throw new InvalidFileStructureException("Unexpected end " +
            "of file when reading Sun RAS palette.");
        }
        result.putSample(channelIndex, i, value);
      }
    }
View Full Code Here

    InvalidFileStructureException,
    UnsupportedTypeException
  {
    if (width < 1)
    {
      throw new InvalidFileStructureException("No valid width available.");
    }
    if (height < 1)
    {
      throw new InvalidFileStructureException("No valid width available.");
    }
    if (stripOffsets != null)
    {
      pixelsPerRow = width;
    }
    else
    if (tileOffsets != null)
    {
      pixelsPerRow = tileWidth;
    }
    if (rowsPerStrip == -1 && stripOffsets != null && stripOffsets.size() == 1)
    {
      rowsPerStrip = height;
    }
    // do more checks based on color type
    switch (photometricInterpretation)
    {
      case(PHOTOMETRIC_BLACK_IS_ZERO):
      case(PHOTOMETRIC_WHITE_IS_ZERO):
      {
        if (bitsPerSample[0] == 1)
        {
          imageType = TYPE_BILEVEL_PACKED;
        }
        else
        {
          if (bitsPerSample[0] == 4)
          {
            imageType = TYPE_GRAY4;
          }
          else
          if (bitsPerSample[0] == 8)
          {
            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):
      {
View Full Code Here

        }
        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;
          if ((width % tileWidth) != 0)
          {
            horizontalTiles++;
View Full Code Here

            offset += BYTES_PER_PIXEL;
          }
        }
        if (compressedSize < 0)
        {
          throw new InvalidFileStructureException("Ran out of compressed input bytes before completing the decoding process.");
        }
      }
      while (numPixels > 0);
    }
  }
View Full Code Here

      {
        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);
          hasBMHD = true;
          break;
        }
        case(MAGIC_BODY):
        {
          if (!hasBMHD)
          {
            // width still has its initialization value -1; no
            // bitmap chunk was encountered
            throw new InvalidFileStructureException("Cannot load image. Error in " +
              "IFF input stream: No bitmap header chunk " +
              "encountered before image body chunk.");
          }
          if (palette == null && (!rgb24))
          {
            // a missing color map is allowed only for truecolor images
            throw new InvalidFileStructureException("Cannot load image. Error in " +
              "IFF input stream: No colormap chunk " +
              "encountered before image body chunk.");
          }
          result = loadImage(in);
          break;
        }
        case(MAGIC_CAMG):
        {
          if (hasCAMG)
          {
            throw new InvalidFileStructureException("Cannot load image. Error in " +
              "IFF input stream: More than one CAMG chunk.");
          }
          hasCAMG = true;
          if (size < 4)
          {
            throw new InvalidFileStructureException("Cannot load" +
              " image. CAMG must be at least four bytes large; " +
              "found: " + size);
          }
          camg = in.readInt();
          ham = (camg & 0x800) != 0;
          ehb = (camg & 0x80) != 0;
          //System.out.println("ham=" + ham);
          in.skipBytes(size - 4);
          break;
        }
        case(MAGIC_CMAP): // palette (color map)
        {
          if (palette != null)
          {
            throw new InvalidFileStructureException("Cannot " +
              "load image. Error in IFF " +
              "input stream: More than one palette.");
          }
          if (size < 3 || (size % 3) != 0)
          {
            throw new InvalidFileStructureException("Cannot " +
              "load image. The size of the colormap is " +
              "invalid: " + size);
          }
          int numColors = size / 3;
          palette = new Palette(numColors, 255);
View Full Code Here

               this would result in an ArrayIndexOutOfBoundsException
               thrown by the virtual machine;
               to give a more understandable error message to the
               user, this exception is caught here and a
               explanatory InvalidFileStructureException is thrown */
            throw new InvalidFileStructureException("Error: " +
              "RLE-compressed image " +
              "file seems to be corrupt (compressed=" + compressed +
              ", x=" + x + ", y=" + y +
              ", count=" + (compressed ? (-((int)n) + 1) : n) +
              ", array length=" + data.length + ").");
          }
        }
        break;
      }
      default:
      {
        throw new InvalidFileStructureException("Error loading " +
          "image; unknown compression type (" + compression + ")");
      }
    }
  }
View Full Code Here

TOP

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

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.