コード例 #1
0
 /**
  * Constructs a color map for specified values.
  * The integers 0 and 255 must be valid pixels for the color model.
  * @param vmin the minimum value.
  * @param vmax the maximum value.
  * @param colorModel the index color model.
  */
 public ColorMap(double vmin, double vmax, IndexColorModel colorModel)
 {
     //Check.argument(colorModel.isValid(0),"0 is valid for color model");
     //Check.argument(colorModel.isValid(255),"255 is valid for color model");
     _vmin       = vmin;
     _vmax       = vmax;
     _colorModel = colorModel;
     cacheColors();
 }
コード例 #2
0
 public static bool IsFilterableICM(ColorModel cm)
 {
     if (cm is IndexColorModel)
     {
         IndexColorModel icm = (IndexColorModel)cm;
         if (icm.MapSize <= 256)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #3
0
ファイル: IconFactory.cs プロジェクト: moayyaed/ikvm
        /// <summary>
        /// Writes the colour map resulting from the source <tt>IndexColorModel</tt>.
        /// </summary>
        /// <param name="icm">
        ///            the source <tt>IndexColorModel</tt> </param>
        private void WriteColorMap(IndexColorModel icm)
        {
            int mapSize = icm.getMapSize();

            for (int i = 0; i < mapSize; i++)
            {
                int  rgb = icm.getRGB(i);
                byte r   = (byte)(rgb >> 16);
                byte g   = (byte)(rgb >> 8);
                byte b   = (byte)(rgb);
                writer.Write(b);
                writer.Write(g);
                writer.Write(r);
                writer.Write((byte)0);
            }
        }
コード例 #4
0
ファイル: IconFactory.cs プロジェクト: moayyaed/ikvm
        /// <summary>
        /// Encodes and writes multiple images without colour depth conversion.
        /// </summary>
        /// <param name="images">
        ///            the list of source images to be encoded </param>
        /// <param name="stream">
        ///            the output to which the encoded image will be written </param>
        internal void Write(java.util.List images, System.IO.Stream stream)
        {
            writer = new BinaryWriter(stream);

            int count = images.size();

            // file header 6
            WriteFileHeader(count, TYPE_ICON);

            // file offset where images start
            int fileOffset = 6 + count * 16;

            // icon entries 16 * count
            for (int i = 0; i < count; i++)
            {
                BufferedImage imgc = (BufferedImage)images.get(i);
                fileOffset += WriteIconEntry(imgc, fileOffset);
            }

            // images
            for (int i = 0; i < count; i++)
            {
                BufferedImage imgc = (BufferedImage)images.get(i);

                // info header
                WriteInfoHeader(imgc);
                // color map
                if (imgc.getColorModel().getPixelSize() <= 8)
                {
                    IndexColorModel icm = (IndexColorModel)imgc.getColorModel();
                    WriteColorMap(icm);
                }
                // xor bitmap
                WriteXorBitmap(imgc);
                // and bitmap
                WriteAndBitmap(imgc);
            }
        }
コード例 #5
0
        /// <summary>
        /// Filters an IndexColorModel object by running each entry in its
        /// color tables through the filterRGB function that RGBImageFilter
        /// subclasses must provide.  Uses coordinates of -1 to indicate that
        /// a color table entry is being filtered rather than an actual
        /// pixel value. </summary>
        /// <param name="icm"> the IndexColorModel object to be filtered </param>
        /// <exception cref="NullPointerException"> if <code>icm</code> is null </exception>
        /// <returns> a new IndexColorModel representing the filtered colors </returns>
        public virtual IndexColorModel FilterIndexColorModel(IndexColorModel icm)
        {
            int mapsize = icm.MapSize;

            sbyte[] r = new sbyte[mapsize];
            sbyte[] g = new sbyte[mapsize];
            sbyte[] b = new sbyte[mapsize];
            sbyte[] a = new sbyte[mapsize];
            icm.GetReds(r);
            icm.GetGreens(g);
            icm.GetBlues(b);
            icm.GetAlphas(a);
            int  trans     = icm.TransparentPixel;
            bool needalpha = false;

            for (int i = 0; i < mapsize; i++)
            {
                int rgb = FilterRGB(-1, -1, icm.GetRGB(i));
                a[i] = (sbyte)(rgb >> 24);
                if (a[i] != (unchecked ((sbyte)0xff)) && i != trans)
                {
                    needalpha = true;
                }
                r[i] = (sbyte)(rgb >> 16);
                g[i] = (sbyte)(rgb >> 8);
                b[i] = (sbyte)(rgb >> 0);
            }
            if (needalpha)
            {
                return(new IndexColorModel(icm.PixelSize, mapsize, r, g, b, a));
            }
            else
            {
                return(new IndexColorModel(icm.PixelSize, mapsize, r, g, b, trans));
            }
        }
コード例 #6
0
        void makeInverseMap(int[] hist, int ncubes)
        {
            // For each cube in the list of cubes, computes the centroid
            // (average value) of the colors enclosed by that cube, and
            // then loads the centroids in the color map. Next loads
            // "hist" with indices into the color map

            int   r, g, b;
            int   color;
            float rsum, gsum, bsum;
            Cube  cube;

            byte[] rLUT = new byte[256];
            byte[] gLUT = new byte[256];
            byte[] bLUT = new byte[256];

            for (int k = 0; k <= ncubes - 1; k++)
            {
                cube = list[k];
                rsum = gsum = bsum = (float)0.0;
                for (int i = cube.lower; i <= cube.upper; i++)
                {
                    color = histPtr[i];
                    r     = red(color);
                    rsum += (float)r * (float)hist[color];
                    g     = green(color);
                    gsum += (float)g * (float)hist[color];
                    b     = blue(color);
                    bsum += (float)b * (float)hist[color];
                }

                // Update the color map
                r = (int)(rsum / (float)cube.count);
                g = (int)(gsum / (float)cube.count);
                b = (int)(bsum / (float)cube.count);
#if false
                if (r == 248 && g == 248 && b == 248)
                {
                    r = g = b = 255;                // Restore white (255,255,255)
                }
#endif
                rLUT[k] = (byte)r;
                gLUT[k] = (byte)g;
                bLUT[k] = (byte)b;
            }
#if false
            cm = new IndexColorModel(8, ncubes, rLUT, gLUT, bLUT);
#else
            Color[] aclr = new Color[ncubes];
            for (int iclr = 0; iclr < ncubes; iclr++)
            {
                aclr[iclr] = Color.FromArgb(rLUT[iclr], gLUT[iclr], bLUT[iclr]);
            }
            m_pal = new Palette(aclr);
#endif

            // For each color in each cube, load the corre-
            // sponding slot in "hist" with the centroid of the cube.
            for (int k = 0; k <= ncubes - 1; k++)
            {
                cube = list[k];
                for (int i = cube.lower; i <= cube.upper; i++)
                {
                    color       = histPtr[i];
                    hist[color] = k;
                }
            }
        }
コード例 #7
0
 /// <summary>
 /// Writes the colour map resulting from the source <tt>IndexColorModel</tt>.
 /// </summary>
 /// <param name="icm">
 ///            the source <tt>IndexColorModel</tt> </param>
 private void WriteColorMap(IndexColorModel icm)
 {
     int mapSize = icm.getMapSize();
     for (int i = 0; i < mapSize; i++)
     {
         int rgb = icm.getRGB(i);
         byte r = (byte)(rgb >> 16);
         byte g = (byte)(rgb >> 8);
         byte b = (byte)(rgb);
         writer.Write(b);
         writer.Write(g);
         writer.Write(r);
         writer.Write((byte)0);
     }
 }
コード例 #8
0
ファイル: IconFactory.cs プロジェクト: moayyaed/ikvm
        /// <summary>
        /// Encodes the <em>AND</em> bitmap for the given image according the its
        /// alpha channel (transparency) and writes it to the given output.
        /// </summary>
        /// <param name="img">
        ///            the image to encode as the <em>AND</em> bitmap. </param>
        private void WriteAndBitmap(BufferedImage img)
        {
            WritableRaster alpha = img.getAlphaRaster();

            // indexed transparency (eg. GIF files)
            if (img.getColorModel() is IndexColorModel && img.getColorModel().hasAlpha())
            {
                int w = img.getWidth();
                int h = img.getHeight();

                int bytesPerLine = GetBytesPerLine1(w);

                byte[] line = new byte[bytesPerLine];

                IndexColorModel icm    = (IndexColorModel)img.getColorModel();
                Raster          raster = img.getRaster();

                for (int y = h - 1; y >= 0; y--)
                {
                    for (int x = 0; x < w; x++)
                    {
                        int bi = x / 8;
                        int i  = x % 8;
                        // int a = alpha.getSample(x, y, 0);
                        int p = raster.getSample(x, y, 0);
                        int a = icm.getAlpha(p);
                        // invert bit since and mask is applied to xor mask
                        int b = ~a & 1;
                        line[bi] = SetBit(line[bi], i, b);
                    }

                    writer.Write(line);
                }
            }
            // no transparency
            else if (alpha == null)
            {
                int h = img.getHeight();
                int w = img.getWidth();
                // calculate number of bytes per line, including 32-bit padding
                int bytesPerLine = GetBytesPerLine1(w);

                byte[] line = new byte[bytesPerLine];
                for (int i = 0; i < bytesPerLine; i++)
                {
                    line[i] = (byte)0;
                }

                for (int y = h - 1; y >= 0; y--)
                {
                    writer.Write(line);
                }
            }
            // transparency (ARGB, etc. eg. PNG)
            else
            {
                int w = img.getWidth();
                int h = img.getHeight();

                int bytesPerLine = GetBytesPerLine1(w);

                byte[] line = new byte[bytesPerLine];

                for (int y = h - 1; y >= 0; y--)
                {
                    for (int x = 0; x < w; x++)
                    {
                        int bi = x / 8;
                        int i  = x % 8;
                        int a  = alpha.getSample(x, y, 0);
                        // invert bit since and mask is applied to xor mask
                        int b = ~a & 1;
                        line[bi] = SetBit(line[bi], i, b);
                    }

                    writer.Write(line);
                }
            }
        }
コード例 #9
0
		/// <summary>
		/// Constructs a <code>BufferedImage</code> of one of the predefined
		/// image types:
		/// TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.
		/// </summary>
		public BufferedImage(int @width, int @height, int @imageType, IndexColorModel @cm)
		{
		}
コード例 #10
0
 /**
  * Constructs a color map for values in [0,1].
  * The integers 0 and 255 must be valid pixels for the color model.
  * @param colorModel the index color model.
  */
 public ColorMap(IndexColorModel colorModel)
 {
     this(0.0, 1.0, colorModel);
 }
コード例 #11
0
 /**
  * Sets the index color model for this color map.
  * @param colorModel the index color model.
  */
 public void setColorModel(IndexColorModel colorModel)
 {
     _colorModel = colorModel;
     cacheColors();
     fireColorMapChanged();
 }