Package org.apache.sanselan

Examples of org.apache.sanselan.ImageReadException


                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


                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

        {
            ArrayList segments = readSegments(byteSource, null, false);

            if (segments == null)
                throw new ImageReadException("No Segments Found.");

            for (int d = 0; d < segments.size(); d++)
            {

                Segment segment = (Segment) segments.get(d);
View Full Code Here

                    if (!hadBackSlash)
                        return token.toString();
                    hadBackSlash = false;
                }
                else if (c == '\r' || c == '\n')
                    throw new ImageReadException("Unterminated string in XPM file");
                else
                {
                    token.append((char)c);
                    hadBackSlash = false;
                }
            }
            else if (inIdentifier)
            {
                if (Character.isLetterOrDigit(c) || c == '_')
                    token.append((char)c);
                else
                {
                    is.unread(c);
                    return token.toString();
                }
            }
            else
            {
                if (c == '"')
                {
                    token.append('"');
                    inString = true;
                }
                else if (Character.isLetterOrDigit(c) || c == '_')
                {
                    token.append((char)c);
                    inIdentifier = true;
                }
                else if (c == '{' || c == '}' ||
                        c == '[' || c == ']' ||
                        c == '*' || c == ';' ||
                        c == '=' || c == ',')
                {
                    token.append((char)c);
                    return token.toString();
                }
                else if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
                    ;
                else
                    throw new ImageReadException("Unhandled/invalid character '" +
                            ((char)c) + "' found in XPM file");
            }
        }

        if (inIdentifier)
            return token.toString();
        if (inString)
            throw new ImageReadException("Unterminated string ends XMP file");
        return null;
    }
View Full Code Here

                    else
                        inString = false;
                    out.write('"');
                }
                else if (c == '\r' || c == '\n')
                    throw new ImageReadException("Unterminated string in file");
                else
                {
                    if (hadBackSlash)
                    {
                        out.write('\\');
                        hadBackSlash = false;
                    }
                    out.write(c);
                }
            }
            else if (inDirective)
            {
                if (c == '\r' || c == '\n')
                {
                    inDirective = false;
                    String[] tokens = tokenizeRow(directiveBuffer.toString());
                    if (tokens.length < 2 || tokens.length > 3)
                        throw new ImageReadException("Bad preprocessor directive");
                    if (!tokens[0].equals("define"))
                        throw new ImageReadException("Invalid/unsupported " +
                                "preprocessor directive '" + tokens[0] + "'");
                    defines.put(tokens[1], (tokens.length == 3) ? tokens[2] : null);
                    directiveBuffer.setLength(0);
                }
                else
                    directiveBuffer.append((char)c);
            }
            else
            {
                if (c == '/')
                {
                    if (hadSlash)
                        out.write('/');
                    hadSlash = true;
                }
                else if (c == '*')
                {
                    if (hadSlash)
                    {
                        inComment = true;
                        hadSlash = false;
                    }
                    else
                        out.write(c);
                }
                else if (c == '"')
                {
                    if (hadSlash)
                        out.write('/');
                    hadSlash = false;
                    out.write(c);
                    inString = true;
                }
                else if (c == '#')
                {
                    if (defines == null)
                        throw new ImageReadException("Unexpected preprocessor directive");
                    inDirective = true;
                }
                else
                {
                    if (hadSlash)
                        out.write('/');
                    hadSlash = false;
                    out.write(c);
                    // Only whitespace allowed before first comment:
                    if (c != ' ' && c != '\t' && c != '\r' && c != '\n')
                        seenFirstComment = true;
                }
            }
        }
        if (hadSlash)
            out.write('/');
        if (hadStar)
            out.write('*');
        if (inString)
            throw new ImageReadException("Unterminated string at the end of file");
        if (inComment)
            throw new ImageReadException("Unterminated comment at the end of file");
        return out;
    }
View Full Code Here

    public static void unescapeString(StringBuilder stringBuilder, String string)
            throws ImageReadException
    {
        if (string.length() < 2)
            throw new ImageReadException("Parsing XPM file failed, " +
                    "string is too short");
        if (string.charAt(0) != '"' || string.charAt(string.length() - 1) != '"')
            throw new ImageReadException("Parsing XPM file failed, " +
                    "string not surrounded by '\"'");
        boolean hadBackSlash = false;
        for (int i = 1; i < (string.length() - 1); i++)
        {
            char c = string.charAt(i);
            if (hadBackSlash)
            {
                if (c == '\\')
                    stringBuilder.append('\\');
                else if (c == '"')
                    stringBuilder.append('"');
                else if (c == '\'')
                    stringBuilder.append('\'');
                else if (c == 'x')
                {
                    if (i + 2 >= string.length())
                        throw new ImageReadException("Parsing XPM file failed, " +
                                "hex constant in string too short");
                    char hex1 = string.charAt(i + 1);
                    char hex2 = string.charAt(i + 2);
                    i += 2;
                    int constant;
                    try
                    {
                        constant =  Integer.parseInt("" + hex1 + hex2, 16);
                    }
                    catch (NumberFormatException nfe)
                    {
                        throw new ImageReadException("Parsing XPM file failed, " +
                                "hex constant invalid", nfe);
                    }
                    stringBuilder.append((char)constant);
                }
                else if (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
                        c == '5' || c == '6' || c == '7')
                {
                    int length = 1;
                    if (i+1 < string.length() && '0' <= string.charAt(i+1) &&
                            string.charAt(i+1) <= '7')
                        ++length;
                    if (i+2 < string.length() && '0' <= string.charAt(i+2) &&
                            string.charAt(i+2) <= '7')
                        ++length;
                    int constant = 0;
                    for (int j = 0; j < length; j++)
                    {
                        constant *= 8;
                        constant += (string.charAt(i + j) - '0');
                    }
                    i += length - 1;
                    stringBuilder.append((char)constant);
                }
                else if (c == 'a')
                    stringBuilder.append((char)0x07);
                else if (c == 'b')
                    stringBuilder.append((char)0x08);
                else if (c == 'f')
                    stringBuilder.append((char)0x0c);
                else if (c == 'n')
                    stringBuilder.append((char)0x0a);
                else if (c == 'r')
                    stringBuilder.append((char)0x0d);
                else if (c == 't')
                    stringBuilder.append((char)0x09);
                else if (c == 'v')
                    stringBuilder.append((char)0x0b);
                else
                    throw new ImageReadException("Parsing XPM file failed, " +
                            "invalid escape sequence");
                hadBackSlash = false;
            }
            else
            {
                if (c == '\\')
                    hadBackSlash = true;
                else if (c == '"')
                    throw new ImageReadException("Parsing XPM file failed, " +
                            "extra '\"' found in string");
                else
                    stringBuilder.append(c);
            }
        }
        if (hadBackSlash)
            throw new ImageReadException("Parsing XPM file failed, " +
                    "unterminated escape sequence found in string");
    }
View Full Code Here

            if (longitudeRef.trim().equalsIgnoreCase("e"))
                return result;
            else if (longitudeRef.trim().equalsIgnoreCase("w"))
                return -result;
            else
                throw new ImageReadException("Unknown longitude ref: \""
                        + longitudeRef + "\"");
        }
View Full Code Here

            if (latitudeRef.trim().equalsIgnoreCase("n"))
                return result;
            else if (latitudeRef.trim().equalsIgnoreCase("s"))
                return -result;
            else
                throw new ImageReadException("Unknown latitude ref: \""
                        + latitudeRef + "\"");
        }
View Full Code Here

    // 1 bit icon types have image data followed by mask data in the same entry
    int totalBytes = (bufferedImage.getWidth() * bufferedImage.getHeight() + 7) / 8;
    if (maskData.length >= 2*totalBytes)
      position = totalBytes;
    else
      throw new ImageReadException("1 BPP mask underrun parsing ICNS file");

    for (int y = 0; y < bufferedImage.getHeight(); y++)
    {
      for (int x = 0; x < bufferedImage.getWidth(); x++)
      {
View Full Code Here

        {
          imageData = Rle24Compression.decompress(imageType.getWidth(),
              imageType.getHeight(), imageElement.data);
        }
        else
          throw new ImageReadException(
              "Short image data but not a 32 bit compressed type");
      }
      else
        imageData = imageElement.data;

      BufferedImage bufferedImage = new BufferedImage(imageType.getWidth(),
          imageType.getHeight(), BufferedImage.TYPE_INT_ARGB);
      switch (imageType.getBitsPerPixel())
      {
        case 1:
          decode1BPPImage(imageType, imageData, bufferedImage);
          break;
        case 4:
          decode4BPPImage(imageType, imageData, bufferedImage);
          break;
        case 8:
          decode8BPPImage(imageType, imageData, bufferedImage);
          break;
        case 32:
          decode32BPPImage(imageType, imageData, bufferedImage);
          break;
        default:
          throw new ImageReadException(
            "Unsupported bit depth " + imageType.getBitsPerPixel());
      }

      if (maskElement != null)
      {
        if (maskType.getBitsPerPixel() == 1)
          apply1BPPMask(maskElement.data, bufferedImage);
        else if (maskType.getBitsPerPixel() == 8)
          apply8BPPMask(maskElement.data, bufferedImage);
        else
          throw new ImageReadException("Unsupport mask bit depth " +
              maskType.getBitsPerPixel());
      }

      result.add(bufferedImage);
    }
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.