Package net.sourceforge.jiu.data

Examples of net.sourceforge.jiu.data.PixelImage


    MissingParameterException,
    OperationFailedException,
    UnsupportedTypeException,
    WrongParameterException
  {
    PixelImage image = getImage();
    if (image == null)
    {
      throw new MissingParameterException("No image available for saving.");
    }
    width = image.getWidth();
    height = image.getHeight();
    setBoundsIfNecessary(width, height);
    width = getBoundsWidth();
    height = getBoundsHeight();
    if (image instanceof Paletted8Image)
    {
      Palette palette = ((Paletted8Image)image).getPalette();
      int numEntries = palette.getNumEntries();
      if (numEntries < 1 || numEntries > 256)
      {
        throw new WrongParameterException("Palette of image to be saved must have 1..256 entries.");
      }
      bitsPerPixel = 8;
      // determine minimum number of bits per pixel necessary to store image
      for (int i = 1; i <= 8; i++)
      {
        if ((1 << i) >= numEntries)
        {
          bitsPerPixel = i;
          break;
        }
      }
    }
    else
    if (image instanceof Gray8Image)
    {
      bitsPerPixel = 8;
    }
    else
    if (image instanceof BilevelImage)
    {
      bitsPerPixel = 1;
    }
    else
    {
      throw new UnsupportedTypeException("Unsupported image type: " + image.getClass().getName());
    }
    out = getOutputAsDataOutput();
    if (out == null)
    {
      throw new MissingParameterException("Output stream / random access file parameter missing.");
View Full Code Here


    writeBlock();
  }

  private void writePalette() throws IOException
  {
    PixelImage image = getImage();
    if (image instanceof Paletted8Image)
    {
      Palette palette = ((Paletted8Image)image).getPalette();
      int numEntries = 1 << bitsPerPixel;
      for (int i = 0; i < numEntries; i++)
View Full Code Here

      }
    }
    // 4. check if we have an image object that we are supposed to reuse
    //    if there is one, check if it has the correct type
    //    if there is none, create a new one
    PixelImage image = getImage();
    if (image == null)
    {
      switch(colorDepth)
      {
        case(1):
View Full Code Here

    UnsupportedTypeException
  {
    // check parameters of this operation
    // 1 image to be saved
    // 1.1 is it available?
    PixelImage image = getImage();
    if (image == null)
    {
      throw new MissingParameterException("No image available.");
    }
    // 1.2 is it supported?
    if (!(image instanceof Paletted8Image ||
          image instanceof Gray8Image ||
          image instanceof BilevelImage ||
          image instanceof RGB24Image))
    {
      throw new UnsupportedTypeException("Unsupported image type: " + image.getClass().getName());
    }
    // 2 is output stream available?
    out = getOutputAsDataOutput();
    if (out == null)
    {
View Full Code Here

   * but also for BilevelImage and Grayscale8Image.
   * For the latter two the palette values must be explicitly written into the file.
   */
  private void writePalette() throws IOException
  {
    PixelImage pi = getImage();
    if (pi == null)
    {
      return;
    }
    if (pi instanceof Paletted8Image)
View Full Code Here

    out.write((value >> 8) & 0xff);
  }

  private void writeStream() throws IOException
  {
    PixelImage image = getImage();
    setBoundsIfNecessary(image.getWidth(), image.getHeight());
    int width = getBoundsWidth();
    int height = getBoundsHeight();
    ByteChannelImage bcimg = null;
    BilevelImage bilevelImage = null;
    RGB24Image rgbimg = null;
View Full Code Here

    WrongFileFormatException,
    WrongParameterException
  {
    setBoundsIfNecessary(width, height);
    checkBounds(width, height);
    PixelImage image = getImage();
    /* if there is no image to be reused (image == null), create one;
       otherwise check if the provided image is of the right type
       and throw an exception if not */
    if (palette != null)
    {
      // paletted image
      if (image == null)
      {
        image = new MemoryPaletted8Image(getBoundsWidth(), getBoundsHeight(), palette);
      }
      else
      {
        if (!(image instanceof Paletted8Image))
        {
          throw new WrongParameterException("Image to be used for loading must be paletted for this file.");
        }
        ((Paletted8Image)image).setPalette(palette);
      }
    }
    else
    {
      switch(bitsPerPixel)
      {
        case(1): // bilevel image (black and white)
        {
          if (image == null)
          {
            image = new MemoryBilevelImage(getBoundsWidth(), getBoundsHeight());
          }
          else
          {
            if (!(image instanceof BilevelImage))
            {
              throw new WrongParameterException("Image to be used for " +
                "loading must implement BilevelImage for this file.");
            }
          }
          break;
        }
        case(16): // RGB direct color
        {
          if (image == null)
          {
            image = new MemoryRGB24Image(getBoundsWidth(), getBoundsHeight());
          }
          else
          {
            if (!(image instanceof RGB24Image))
            {
              throw new WrongParameterException("Image to be used for " +
                "loading must implement RGB24Image.");
            }
          }
          rgb = new byte[width * 3];
          break;
        }
        default: // grayscale, 2, 4 or 8 bits per pixel
        {
          if (image == null)
          {
            image = new MemoryGray8Image(getBoundsWidth(), getBoundsHeight());
          }
          else
          {
            if (!(image instanceof Gray8Image))
            {
              throw new WrongParameterException("Image to be used for " +
                "loading must implement Gray8Image for this file.");
            }
          }
        }
      }
    }
    setImage(image);
    // check if image has the correct pixel resolution
    if (image.getWidth() != getBoundsWidth() || image.getHeight() != getBoundsHeight())
    {
      throw new WrongParameterException("Image to be reused has wrong resolution (must have " +
        getBoundsWidth() + " x " + getBoundsHeight() + " pixels).");
    }
    loadImageData(in);
View Full Code Here

  private void loadImageData(DataInput in) throws
    InvalidFileStructureException,
    IOException
  {
    PixelImage image = getImage();
    // if compression is used, read a short with the compressed data size
    if (compression != COMPRESSION_NONE)
    {
      //int compressedDataSize = in.readShort() & 0xffff;
      in.readShort();
View Full Code Here

    IOException,
    OperationFailedException,
    UnsupportedTypeException
  {
    // get image, set bounds if necessary and check existing bounds
    PixelImage image = getImage();
    if (image == null)
    {
      throw new MissingParameterException("Need image to save.");
    }
    setBoundsIfNecessary(image.getWidth(), image.getHeight());
    checkBounds(image.getWidth(), image.getHeight());
    // get output object
    DataOutput out = getOutputAsDataOutput();
    if (out == null)
    {
      throw new MissingParameterException("Could not get DataOutput object when saving in Palm file format.");
    }
    // initialize fields to be written to the header
    width = getBoundsWidth();
    height = getBoundsHeight();
    flags = 0;
    if (hasTransparencyIndex())
    {
      flags |= FLAG_TRANSPARENCY;
    }
    if (compression != COMPRESSION_NONE)
    {
      flags |= FLAG_COMPRESSED;
    }
    version = 0;
    if (bitsPerPixel > 1)
    {
      version = 1;
    }
    if (hasTransparencyIndex() || compression != COMPRESSION_NONE)
    {
      version = 2;
    }
    //nextImageOffset = 0;
    compressedDataOffset = 0;
    // check image types
    if (image instanceof BilevelImage)
    {
      save(out, (BilevelImage)image);
    }
    else
    if (image instanceof Gray8Image)
    {
      save(out, (Gray8Image)image);
    }
    else
    if (image instanceof Paletted8Image)
    {
      save(out, (Paletted8Image)image);
    }
    else
    if (image instanceof RGB24Image)
    {
      save(out, (RGB24Image)image);
    }
    else
    {
      throw new UnsupportedTypeException("Unsupported image type: " + image.getClass().getName());
    }
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.jiu.data.PixelImage

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.