Package org.apache.sanselan

Examples of org.apache.sanselan.ImageReadException


    private WbmpHeader readWbmpHeader(InputStream is)
            throws ImageReadException, IOException
    {
        int typeField = readMultiByteInteger(is);
        if (typeField != 0)
            throw new ImageReadException("Invalid/unsupported WBMP type " + typeField);

        byte fixHeaderField = readByte("FixHeaderField", is, "Invalid WBMP File");
        if ((fixHeaderField & 0x9f) != 0)
            throw new ImageReadException("Invalid/unsupported WBMP FixHeaderField 0x" +
                    Integer.toHexString(0xff & fixHeaderField));

        int width = readMultiByteInteger(is);

        int height = readMultiByteInteger(is);
View Full Code Here


    Sanselan.getMetadata(bytes, null);
    byte[] iccBytes = Sanselan.getICCProfileBytes(bytes);
    if (iccBytes != null && iccBytes.length > 0) {
      ICC_Profile iccProfile = Sanselan.getICCProfile(bytes, null);
      if (iccProfile == null) {
        throw new ImageReadException("Image has ICC but it is corrupt and cannot be read");
      }
    }
    return ImageIO.read(new ByteArrayInputStream(bytes));
  }
View Full Code Here

    } else if (imageFormat == ImageFormat.IMAGE_FORMAT_JPEG) {
      return readJpeg(response);
    } else if (imageFormat == ImageFormat.IMAGE_FORMAT_BMP) {
      return readBmp(response);
    } else {
      throw new ImageReadException("Unsupported format " + imageFormat.name);
    }
  }
View Full Code Here

    {
      if (cached_bit_count < bhi.bitsPerPixel)
      {
        if (cached_bit_count != 0)
          throw new ImageReadException("Unexpected leftover bits: "
              + cached_bit_count + "/" + bhi.bitsPerPixel);

        //        cached_byte = 0;

        cached_bit_count += 8;
        cached_byte =
        //          (cached_byte << 8)
        //            |
        (0xff & imageData[bytecount]);
        //        if (pixel_count < 500)
        //          System.out.println("reading byte on pixel # "
        //              + (pixel_count - 1));
        bytecount++;
      }
      int cache_mask = (1 << bhi.bitsPerPixel) - 1;
      int sample = cache_mask & (cached_byte >> (8 - bhi.bitsPerPixel));
      cached_byte = 0xff & (cached_byte << bhi.bitsPerPixel);
      cached_bit_count -= bhi.bitsPerPixel;

      int rgb = getColorTableRGB(sample);

      return rgb;
    }
    else if (bhi.bitsPerPixel == 8) // always grayscale?
    {
      int sample = 0xff & imageData[bytecount + 0];

      int rgb = getColorTableRGB(sample);

      bytecount += 1;

      return rgb;
    }
    else if (bhi.bitsPerPixel == 16)
    {
      int data = bfp.read2Bytes("Pixel", is, "BMP Image Data");

      int blue = (0x1f & (data >> 0)) << 3;
      int green = (0x1f & (data >> 5)) << 3;
      int red = (0x1f & (data >> 10)) << 3;
      int alpha = 0xff;

      int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);

      bytecount += 2;

      return rgb;
    }
    else if (bhi.bitsPerPixel == 24)
    {
      int blue = 0xff & imageData[bytecount + 0];
      int green = 0xff & imageData[bytecount + 1];
      int red = 0xff & imageData[bytecount + 2];
      int alpha = 0xff;

      int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);

      bytecount += 3;

      return rgb;
    }
    else if (bhi.bitsPerPixel == 32)
    {
      int blue = 0xff & imageData[bytecount + 0];
      int green = 0xff & imageData[bytecount + 1];
      int red = 0xff & imageData[bytecount + 2];
      int alpha = 0xff;

      int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);

      bytecount += 4;

      return rgb;
    }

    throw new ImageReadException("Unknown BitsPerPixel: "
        + bhi.bitsPerPixel);
  }
View Full Code Here

  }

  public final BufferedImage getBufferedImage(ByteSource byteSource,
      Map params) throws ImageReadException, IOException
  {
    throw new ImageReadException(
        "Sanselan cannot read or write JPEG images.");
  }
View Full Code Here

  private byte[] assembleSegments(ArrayList v, boolean start_with_zero)
      throws ImageReadException, IOException
  {
    if (v.size() < 1)
      throw new ImageReadException("No App2 Segments Found.");

    int markerCount = ((App2Segment) v.get(0)).num_markers;

    //    if (permissive && (markerCount == 0))
    //      markerCount = v.size();

    if (v.size() != markerCount)
      throw new ImageReadException("App2 Segments Missing.  Found: "
          + v.size() + ", Expected: " + markerCount + ".");

    Collections.sort(v);

    int offset = start_with_zero ? 0 : 1;

    int total = 0;
    for (int i = 0; i < v.size(); i++)
    {
      App2Segment segment = (App2Segment) v.get(i);

      if ((i + offset) != segment.cur_marker)
      {
        dumpSegments(v);
        throw new ImageReadException(
            "Incoherent App2 Segment Ordering.  i: " + i
                + ", segment[" + i + "].cur_marker: "
                + segment.cur_marker + ".");
      }

      if (markerCount != segment.num_markers)
      {
        dumpSegments(v);
        throw new ImageReadException(
            "Inconsistent App2 Segment Count info.  markerCount: "
                + markerCount + ", segment[" + i
                + "].num_markers: " + segment.num_markers + ".");
      }
View Full Code Here

    // TODO: concatenate if multiple segments, need example.
    if (exifSegments.size() < 1)
      return null;
    if (exifSegments.size() > 1)
      throw new ImageReadException(
          "Sanselan currently can't parse EXIF metadata split across multiple APP1 segments.  "
              + "Please send this image to the Sanselan project.");

    GenericSegment segment = (GenericSegment) exifSegments.get(0);
    byte bytes[] = segment.bytes;
View Full Code Here

        SOF14Marker, SOF15Marker,

    }, true);

    if ((segments == null) || (segments.size() < 1))
      throw new ImageReadException("No JFIF Data Found.");

    if (segments.size() > 1)
      throw new ImageReadException("Redundant JFIF Data Found.");

    SOFNSegment fSOFNSegment = (SOFNSegment) segments.get(0);

    return new Dimension(fSOFNSegment.width, fSOFNSegment.height);
  }
View Full Code Here

    // LayerAndMaskDataLength, is, "Not a Valid PSD File");

    if (section == PSD_SECTION_IMAGE_DATA)
      return is;

    throw new ImageReadException("getInputStream: Unknown Section: "
        + section);
  }
View Full Code Here

        SOF13Marker, SOF14Marker, SOF15Marker,

    }, false);

    if (SOF_segments == null)
      throw new ImageReadException("No SOFN Data Found.");

    //    if (SOF_segments.size() != 1)
    //      System.out.println("Incoherent SOFN Data Found: "
    //          + SOF_segments.size());

    ArrayList jfifSegments = readSegments(byteSource, new int[]{
      JFIFMarker,
    }, true);

    SOFNSegment fSOFNSegment = (SOFNSegment) SOF_segments.get(0);
    //    SOFNSegment fSOFNSegment = (SOFNSegment) findSegment(segments, SOFNmarkers);

    if (fSOFNSegment == null)
      throw new ImageReadException("No SOFN Data Found.");

    int Width = fSOFNSegment.width;
    int Height = fSOFNSegment.height;

    JFIFSegment jfifSegment = null;
View Full Code Here

TOP

Related Classes of org.apache.sanselan.ImageReadException

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.