Examples of Paletted8Image


Examples of net.sourceforge.jiu.data.Paletted8Image

    quantizer.setMapping(true); // we want the quantizer to create an output image
    quantizer.setTruecolorOutput(false); // that output image must be paletted
    quantizer.process();
    for (int currentPass = 0; currentPass < numPasses; currentPass++)
    {
      Paletted8Image palImage = (Paletted8Image)quantizer.getOutputImage();
      palette = palImage.getPalette();
      // create co-occurrence matrix for paletted image
      CoOccurrenceMatrix com = MatrixCreator.createCoOccurrenceMatrix(palImage);
      // create co-occurrence frequency matrix for co-occurrence matrix
      CoOccurrenceFrequencyMatrix cofm = MatrixCreator.createCoOccurrenceFrequencyMatrix(com);
      // compute certain statistics from the co-occurrence frequency matrix
      computeStatistics(cofm);
      // find pairs of contouring and compressible colors
      leaves = quantizer.createLeafList();
      findColorPairs(cofm, com);
      if (compressibleNodes.size() == 0 ||
          contouringPairs.size() == 0)
      {
        //System.out.println("Compressible=" + compressibleNodes.size() + contouring=" + contouringPairs.size() + " in iteration " + currentPass);
        break;
      }
      // adjust Median-Cut-specific data structures:
      // merge compressible and split contouring nodes
      System.out.println((currentPass + 1) + " " +
        compressibleNodes.size() + " " + contouringPairs.size());
      mergeAndSplit();
      // create a new version of the paletted image:
      // (1) reassign palette index values for the nodes
      quantizer.setAllPaletteIndexValues();
      // (2) make it recompute the representative colors
      quantizer.findAllRepresentativeColors();
      // (3) create a new Palette object
      palette = quantizer.createPalette();
      // (4) give that to the paletted image
      Paletted8Image out = (Paletted8Image)quantizer.getOutputImage();
      out.setPalette(palette);
      // (5) map original to that new palette
      quantizer.mapImage(originalImage, out);
    }
    setOutputImage(quantizer.getOutputImage());
  }
View Full Code Here

Examples of net.sourceforge.jiu.data.Paletted8Image

            index++;
          }
        }
      }
    }
    Paletted8Image out = new MemoryPaletted8Image(in.getWidth(), in.getHeight(), palette);
    for (int y = 0; y < in.getHeight(); y++)
    {
      for (int x = 0; x < in.getWidth(); x++)
      {
        int red = in.getSample(RGBIndex.INDEX_RED, x, y);
        int green = in.getSample(RGBIndex.INDEX_GREEN, x, y);
        int blue = in.getSample(RGBIndex.INDEX_BLUE, x, y);
        out.putSample(0, x, y, hist.getEntry(red, green, blue));
      }
      setProgress(y, in.getHeight());
    }
    outputImage = out;
  }
View Full Code Here

Examples of net.sourceforge.jiu.data.Paletted8Image

            index++;
          }
        }
      }
    }
    Paletted8Image out = new MemoryPaletted8Image(in.getWidth(), in.getHeight(), palette);
    for (int y = 0; y < in.getHeight(); y++)
    {
      for (int x = 0; x < in.getWidth(); x++)
      {
        int red = in.getSample(RGBIndex.INDEX_RED, x, y) >> 8;
        int green = in.getSample(RGBIndex.INDEX_GREEN, x, y) >> 8;
        int blue = in.getSample(RGBIndex.INDEX_BLUE, x, y) >> 8;
        out.putSample(0, x, y, hist.getEntry(red, green, blue));
      }
      setProgress(y, in.getHeight());
    }
    outputImage = out;
  }
View Full Code Here

Examples of net.sourceforge.jiu.data.Paletted8Image

    }
    else
    // PALETTED8
    if (inputImage instanceof Paletted8Image)
    {
      Paletted8Image in = (Paletted8Image)inputImage;
      Palette palette = in.getPalette();
      if (palette.isBlackAndWhite())
      {
        type = TYPE_BILEVEL;
        if (doConvert)
        {
          createBilevelFromPaletted(in);
        }
      }
      else
      if (palette.isGray())
      {
        type = TYPE_GRAY8;
        if (doConvert)
        {
          Gray8Image out = new MemoryGray8Image(in.getWidth(), in.getHeight());
          createGray8FromPaletted8(in, out);
        }
      }
    }
    else
View Full Code Here

Examples of net.sourceforge.jiu.data.Paletted8Image

  }

  private void process(Paletted8Image in)
  {
    // prepare(PixelImage) has made sure that we have a compatible output image
    Paletted8Image out = (Paletted8Image)getOutputImage();

    // invert palette of output image
    Palette pal = out.getPalette();
    final int MAX = pal.getMaxValue();
    for (int entryIndex = 0; entryIndex < pal.getNumEntries(); entryIndex++)
    {
      for (int channelIndex = 0; channelIndex < 3; channelIndex++)
      {
        pal.putSample(channelIndex, entryIndex, MAX - pal.getSample(channelIndex, entryIndex));
      }
    }

    // copy image content
    final int WIDTH = in.getWidth();
    final int HEIGHT = in.getHeight();
    for (int y = 0; y < HEIGHT; y++)
    {
      for (int x = 0; x < WIDTH; x++)
      {
        out.putSample(0, x, y, in.getSample(0, x, y));
      }
      setProgress(y, HEIGHT);
    }
  }
View Full Code Here

Examples of net.sourceforge.jiu.data.Paletted8Image

    MissingParameterException,
    WrongParameterException
  {
    PixelImage in = getInputImage();
    prepare(in);
    Paletted8Image out = (Paletted8Image)getOutputImage();
    if (in instanceof BilevelImage)
    {
      process((BilevelImage)in, out);
    }
    else
View Full Code Here

Examples of net.sourceforge.jiu.data.Paletted8Image

  private IntegerImage readImage() throws
    InvalidFileStructureException,
    java.io.IOException
  {
    RGB24Image rgb24Image = null;
    Paletted8Image paletted8Image = null;
    IntegerImage result = null;
    int numChannels = 1;
    int bytesPerRow = 0;
    switch(depth)
    {
      case(8):
      {
        paletted8Image = new MemoryPaletted8Image(width, height, palette);
        result = paletted8Image;
        numChannels = 1;
        bytesPerRow = width;
        break;
      }
      case(24):
      {
        rgb24Image = new MemoryRGB24Image(width, height);
        result = rgb24Image;
        numChannels = 3;
        bytesPerRow = width;
        break;
      }
    }
    setImage(result);
    byte[][] buffer = new byte[numChannels][];
    for (int i = 0; i < numChannels; i++)
    {
      buffer[i] = new byte[bytesPerRow];
    }
    for (int y = 0, destY = -getBoundsY1(); destY <= getBoundsY2(); y++, destY++)
    {
      if (rgb24Image != null)
      {
        for (int x = 0; x < width; x++)
        {
          buffer[RGBIndex.INDEX_BLUE][x] = in.readByte();
          buffer[RGBIndex.INDEX_GREEN][x] = in.readByte();
          buffer[RGBIndex.INDEX_RED][x] = in.readByte();
        }
        rgb24Image.putByteSamples(RGBIndex.INDEX_RED, 0, destY, getBoundsWidth(), 1, buffer[0], getBoundsX1());
        rgb24Image.putByteSamples(RGBIndex.INDEX_GREEN, 0, destY, getBoundsWidth(), 1, buffer[1], getBoundsX1());
        rgb24Image.putByteSamples(RGBIndex.INDEX_BLUE, 0, destY, getBoundsWidth(), 1, buffer[2], getBoundsX1());
      }
      else
      if (paletted8Image != null)
      {
        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 + ".");
View Full Code Here

Examples of net.sourceforge.jiu.data.Paletted8Image

    }
    out.writeInt(mapType);
    out.writeInt(mapLength);
    if (image instanceof Paletted8Image)
    {
      Paletted8Image pal = (Paletted8Image)image;
      savePalette(pal.getPalette());
    }
  }
View Full Code Here

Examples of net.sourceforge.jiu.data.Paletted8Image

  private void mapImage()
  {
    RGB24Image in = (RGB24Image)getInputImage();
    Palette palette = createPalette();
    Paletted8Image out = new MemoryPaletted8Image(in.getWidth(), in.getHeight(), palette);
    int[] origRgb = new int[3];
    int[] quantizedRgb = new int[3];
    for (int y = 0; y < in.getHeight(); y++)
    {
      for (int x = 0; x < in.getWidth(); x++)
      {
        origRgb[INDEX_RED] = in.getSample(INDEX_RED, x, y);
        origRgb[INDEX_GREEN] = in.getSample(INDEX_GREEN, x, y);
        origRgb[INDEX_BLUE] = in.getSample(INDEX_BLUE, x, y);
        int index = map(origRgb, quantizedRgb);
        out.putSample(0, x, y, index);
      }
    }
    setOutputImage(out);
  }
View Full Code Here

Examples of net.sourceforge.jiu.data.Paletted8Image

    {
      createExtraHalfbritePalette();
    }
    int numBytesPerPlane = (width + 7) / 8;
    PixelImage image = null;
    Paletted8Image palettedImage = null;
    RGB24Image rgbImage = null;
    if (numPlanes == 24 || ham)
    {
      rgbImage = new MemoryRGB24Image(getBoundsWidth(), getBoundsHeight());
      image = rgbImage;
    }
    else
    {
      palettedImage = new MemoryPaletted8Image(getBoundsWidth(), getBoundsHeight(), palette);
      image = palettedImage;
    }
    /* only matters for uncompressed files;
       will be true if the number of bytes is odd;
       is computed differently for PBM and ILBM types
    */
    boolean oddBytesPerRow = (((numBytesPerPlane * numPlanes) % 2) != 0);
    if (type == MAGIC_PBM)
    {
      oddBytesPerRow = ((width % 2) == 1);
    }
    // plane data will have numPlanes planes for ILBM and 1 plane for PBM
    byte[][] planes = null;
    int numChannels = 1;
   
    if (type == MAGIC_ILBM)
    {
      int allocBytes = numBytesPerPlane;
      if ((numBytesPerPlane % 2) == 1)
      {
        allocBytes++;
      }
      // allocate numPlanes byte arrays
      planes = new byte[numPlanes][];
      if (rgb24 || ham)
      {
        numChannels = 3;
      }
      // for each of these byte arrays allocate numBytesPerPlane bytes
      for (int i = 0; i < numPlanes; i++)
      {
        planes[i] = new byte[allocBytes];
      }
    }
    else
    {
      // only one plane, but each plane has width bytes instead of
      // numBytesPerPlane
      planes = new byte[1][];
      planes[0] = new byte[width];
    }
    byte[][] dest = new byte[numChannels][];
    for (int i = 0; i < numChannels; i++)
    {
      dest[i] = new byte[width];
    }
    for (int y = 0, destY = 0 - getBoundsY1(); y <= getBoundsY2(); y++, destY++)
    {
      // load one row, different approach for PBM and ILBM
      if (type == MAGIC_ILBM)
      {
        // decode all planes for a complete row
        for (int p = 0; p < numPlanes; p++)
        {
          loadBytes(in, planes[p], numBytesPerPlane, y);
        }
      }
      else
      if (type == MAGIC_PBM)
      {
        loadBytes(in, planes[0], numBytesPerPlane, y);
      }
      /* all uncompressed rows must have an even number of bytes
         so in case the number of bytes per row is odd, one byte
         is read and dropped */
      if (compression == COMPRESSION_NONE && oddBytesPerRow)
      {
        in.readByte();
      }
      setProgress(y, getBoundsY2() + 1);
      // if we do not need the row we just loaded we continue loading
      // the next row
      if (!isRowRequired(y))
      {
        continue;
      }
      //System.out.println("storing row " + y + " as " + destY + ", numPlanes="+ numPlanes + ",type=" + type);
      // compute offset into pixel data array
      if (type == MAGIC_ILBM)
      {
        convertRow(planes, dest);
        if (rgb24 || ham)
        {
          rgbImage.putByteSamples(RGB24Image.INDEX_RED, 0, destY,
            getBoundsWidth(), 1, dest[0], getBoundsX1());
          rgbImage.putByteSamples(RGB24Image.INDEX_GREEN, 0, destY,
            getBoundsWidth(), 1, dest[1], getBoundsX1());
          rgbImage.putByteSamples(RGB24Image.INDEX_BLUE, 0, destY,
            getBoundsWidth(), 1, dest[2], getBoundsX1());
        }
        else
        {
          palettedImage.putByteSamples(0, 0, destY,
            getBoundsWidth(), 1, dest[0], getBoundsX1());
        }
      }
      else
      if (type == MAGIC_PBM)
      {
        palettedImage.putByteSamples(0, 0, destY, getBoundsWidth(), 1,
          planes[0], getBoundsX1());
      }
    }
    return image;
  }
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.