Examples of ImageWriteException


Examples of org.apache.sanselan.ImageWriteException

        {
            Object value = params.get(PARAM_KEY_COMPRESSION);
            if (value != null)
            {
                if (!(value instanceof Number))
                    throw new ImageWriteException(
                            "Invalid compression parameter: " + value);
                compression = ((Number) value).intValue();
            }
            params.remove(PARAM_KEY_COMPRESSION);
        }

        final int samplesPerPixel = 3; // TODO:
        final int bitsPerSample = 8; // TODO:

        // int fRowsPerStrip; // TODO:
        int rowsPerStrip = 8000 / (width * samplesPerPixel); // TODO:
        rowsPerStrip = Math.max(1, rowsPerStrip); // must have at least one.

        byte strips[][] = getStrips(src, samplesPerPixel, bitsPerSample,
                rowsPerStrip);

        // int stripCount = (height + fRowsPerStrip - 1) / fRowsPerStrip;
        // int stripCount = strips.length;

        if (params.size() > 0)
        {
            Object firstKey = params.keySet().iterator().next();
            throw new ImageWriteException("Unknown parameter: " + firstKey);
        }

        // System.out.println("width: " + width);
        // System.out.println("height: " + height);
        // System.out.println("fRowsPerStrip: " + fRowsPerStrip);
        // System.out.println("fSamplesPerPixel: " + fSamplesPerPixel);
        // System.out.println("stripCount: " + stripCount);

        if (compression == TIFF_COMPRESSION_PACKBITS)
        {
            for (int i = 0; i < strips.length; i++)
                strips[i] = new PackBits().compress(strips[i]);
        } else if (compression == TIFF_COMPRESSION_LZW)
        {
            for (int i = 0; i < strips.length; i++)
            {
                byte uncompressed[] = strips[i];

                int LZW_MINIMUM_CODE_SIZE = 8;

                MyLZWCompressor compressor = new MyLZWCompressor(
                        LZW_MINIMUM_CODE_SIZE, BYTE_ORDER_MSB, true);
                byte compressed[] = compressor.compress(uncompressed);

                strips[i] = compressed;
            }
        } else if (compression == TIFF_COMPRESSION_UNCOMPRESSED)
        {
            // do nothing.
        } else
            throw new ImageWriteException(
                    "Invalid compression parameter (Only LZW, Packbits and uncompressed supported).");

        TiffElement.DataElement imageData[] = new TiffElement.DataElement[strips.length];
        for (int i = 0; i < strips.length; i++)
            imageData[i] = new TiffImageData.Data(0, strips[i].length,
View Full Code Here

Examples of org.apache.sanselan.ImageWriteException

            params.remove(PARAM_KEY_FORMAT);

        if (params.size() > 0)
        {
            Object firstKey = params.keySet().iterator().next();
            throw new ImageWriteException("Unknown parameter: " + firstKey);
        }

        writeMultiByteInteger(os, 0); // typeField
        os.write(0); // fixHeaderField
        writeMultiByteInteger(os, src.getWidth());
View Full Code Here

Examples of org.apache.sanselan.ImageWriteException

    if (params.containsKey(PARAM_KEY_FORMAT))
      params.remove(PARAM_KEY_FORMAT);

    if (params.size() > 0) {
      Object firstKey = params.keySet().iterator().next();
      throw new ImageWriteException("Unknown parameter: " + firstKey);
    }

    writer.writeImage(src, os, params);
  }
View Full Code Here

Examples of org.apache.sanselan.ImageWriteException

    if (o instanceof byte[])
      return (byte[]) o;
    else if (o instanceof String)
      return ((String) o).getBytes();
    else
      throw new ImageWriteException("Unknown data type: " + o);
  }
View Full Code Here

Examples of org.apache.sanselan.ImageWriteException

  public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
      Number number) throws ImageWriteException
  {
    if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
      throw new ImageWriteException("Tag has no default data type.");
    FieldType fieldType = tagInfo.dataTypes[0];

    if (tagInfo.length != 1)
      throw new ImageWriteException("Tag does not expect a single value.");

    byte bytes[] = fieldType.writeData(number, byteOrder);

    return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
  }
View Full Code Here

Examples of org.apache.sanselan.ImageWriteException

  public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
      Number value[]) throws ImageWriteException
  {
    if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
      throw new ImageWriteException("Tag has no default data type.");
    FieldType fieldType = tagInfo.dataTypes[0];

    if (tagInfo.length != value.length)
      throw new ImageWriteException("Tag does not expect a single value.");

    byte bytes[] = fieldType.writeData(value, byteOrder);

    return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, value.length, bytes);
  }
View Full Code Here

Examples of org.apache.sanselan.ImageWriteException

    if (tagInfo.dataTypes == null)
      fieldType = FIELD_TYPE_ASCII;
    else if (tagInfo.dataTypes == FIELD_TYPE_DESCRIPTION_ASCII)
      fieldType = FIELD_TYPE_ASCII;
    else
      throw new ImageWriteException("Tag has unexpected data type.");

    byte bytes[] = fieldType.writeData(value, byteOrder);

    return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
  }
View Full Code Here

Examples of org.apache.sanselan.ImageWriteException

    bos.write4Bytes(count);

    if (isLocalValue())
    {
      if (separateValueItem != null)
        throw new ImageWriteException("Unexpected separate value item.");

      bos.writeByteArray(bytes);
      int remainder = TIFF_ENTRY_MAX_VALUE_LENGTH - bytes.length;
      for (int i = 0; i < remainder; i++)
        bos.write(0);
    }
    else
    {
      if (separateValueItem == null)
        throw new ImageWriteException("Missing separate value item.");

      bos.write4Bytes(separateValueItem.getOffset());

      int written = bytes.length;
      if ((written % 2) != 0)
View Full Code Here

Examples of org.apache.sanselan.ImageWriteException

    //    if(tagInfo.isUnknown())
    //      Debug.debug("unknown tag(0x" + Integer.toHexString(tag)
    //          + ") setData", bytes);

    if (this.bytes.length != bytes.length)
      throw new ImageWriteException("Cannot change size of value.");

    //    boolean wasLocalValue = isLocalValue();
    this.bytes = bytes;
    //    if (isLocalValue() != wasLocalValue)
    //      throw new Error("Bug. Locality disrupted! "
View Full Code Here

Examples of org.apache.sanselan.ImageWriteException

  protected void setByteOrder(int a, int b) throws ImageWriteException,
      IOException
  {
    if (a != b)
      throw new ImageWriteException("Byte Order bytes don't match (" + a
          + ", " + b + ").");

    if (a == BYTE_ORDER_MOTOROLA)
      byteOrder = a;
    else if (a == BYTE_ORDER_INTEL)
      byteOrder = a;
    else
      throw new ImageWriteException("Unknown Byte Order hint: " + a);
  }
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.