コード例 #1
0
ファイル: Pixel.cs プロジェクト: unhammer/gimp-sharp
        static internal Pixel[,] ConvertToPixelArray(IntPtr src,
                                                     Dimensions dimensions,
                                                     int bpp)
        {
            int width  = dimensions.Width;
            int height = dimensions.Height;
            var dest   = new byte[width * height * bpp];

            Marshal.Copy(src, dest, 0, width * height * bpp);

            var thumbnail = new Pixel[height, width];

            int index = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    var pixel = new Pixel(bpp);
                    pixel.CopyFrom(dest, index);
                    index          += bpp;
                    thumbnail[y, x] = pixel;
                }
            }
            return(thumbnail);
        }
コード例 #2
0
ファイル: TestPixel.cs プロジェクト: unhammer/gimp-sharp
        public void CopyFrom()
        {
            var pixel = new Pixel(3);
            var src   = new byte[] { 11, 12, 13 };

            pixel.CopyFrom(src, 0);
            Assert.AreEqual(src, pixel.Bytes);
        }
コード例 #3
0
ファイル: Pixel.cs プロジェクト: unhammer/gimp-sharp
        internal static Pixel[,] ConvertToPixelArray(IntPtr src, 
            Dimensions dimensions,
            int bpp)
        {
            int width = dimensions.Width;
              int height = dimensions.Height;
              var dest = new byte[width * height * bpp];
              Marshal.Copy(src, dest, 0, width * height * bpp);

              var thumbnail = new Pixel[height, width];

              int index = 0;
              for (int y = 0; y < height; y++)
            {
              for (int x = 0; x < width; x++)
            {
              var pixel = new Pixel(bpp);
              pixel.CopyFrom(dest, index);
              index += bpp;
              thumbnail[y, x] = pixel;
            }
            }
              return thumbnail;
        }
コード例 #4
0
ファイル: TestPixel.cs プロジェクト: unhammer/gimp-sharp
 public void CopyFrom()
 {
     var pixel = new Pixel(3);
       var src = new byte[]{11, 12, 13};
       pixel.CopyFrom(src, 0);
       Assert.AreEqual(src, pixel.Bytes);
 }
コード例 #5
0
ファイル: GSImage.cs プロジェクト: bzamecnik/HalftoneLab
        public override void IterateSrcDestByRows(
            IterFuncSrcDest pixelFunc,
            ScanningOrder scanOrder)
        {
            //PixelRgn srcPR = new PixelRgn(_drawable, _rectangle, false, false);
            //PixelRgn destPR = new PixelRgn(_drawable, _rectangle, true, true);

            //_imageBuffer = new byte[_rectangle.Width * _rectangle.Height * _drawable.Bpp];

            initBuffer();

            int bufferIndexY = 0;
            int rowstride = _rectangle.Width * _drawable.Bpp;
            //byte[] row = new byte[rowstride];
            Pixel tmpPixel = new Pixel(_drawable.Bpp);
            byte[] pixelBytes = new byte[_drawable.Bpp];

            int blockCount = 100;
            double progressPercentage = 0;
            double progressUnit = (double)blockCount / (double)_rectangle.Height;

            for (int y = _rectangle.Y1; y < _rectangle.Y2;
                y++, bufferIndexY += rowstride)
            {
                //Array.Copy(_imageBuffer, bufferIndexY, row, 0, rowstride);
                //Pixel[] pixelRow = srcPR.GetRow(_rectangle.X1, y, _rectangle.Width);
                //Pixel[] row = srcPR.GetRow(_rectangle.X1, y, srcPR.W);
                for (int x = 0, bufferIndex = bufferIndexY; x < _rectangle.Width;
                    x++, bufferIndex += _drawable.Bpp)
                {
                    // setPixel(x, y, pixelFunc(pixelRow[x]));

                    tmpPixel.CopyFrom(_imageBuffer, bufferIndex);
                    tmpPixel.X = x; tmpPixel.Y = y;
                    tmpPixel = pixelFunc(tmpPixel);
                    tmpPixel.CopyTo(_imageBuffer, bufferIndex);
                }
                if ((y % blockCount) == 0) {
                    progressPercentage += progressUnit;
                    Progress.Update(progressPercentage);
                }
            }
            flushBuffer();

            //_drawable.Flush();
            //_drawable.MergeShadow(true);
            //_drawable.Update(_rectangle);
        }
コード例 #6
0
ファイル: GSImage.cs プロジェクト: bzamecnik/HalftoneLab
 // TODO: doesn't work properly, debug!
 //public override void IterateSrcDestNoOrder(
 //    IterFuncSrcDest pixelFunc)
 //{
 //    PixelRgn srcPR = new PixelRgn(_drawable, _rectangle, false, false);
 //    PixelRgn destPR = new PixelRgn(_drawable, _rectangle, true, true);
 //    double progressPercentage = 0;
 //    double progressUnit = (double)(Gimp.Gimp.TileWidth * Gimp.Gimp.TileHeight) / (double)(Width * Height);
 //    for (IntPtr pr = PixelRgn.Register(srcPR, destPR); pr != IntPtr.Zero;
 //        pr = PixelRgn.Process(pr))
 //    {
 //        int yEnd = destPR.Y + destPR.H;
 //        int xEnd = destPR.X + destPR.W;
 //        for (int y = destPR.Y; y < yEnd; y++) {
 //            for (int x = destPR.X; x < xEnd; x++) {
 //                destPR[y, x] = pixelFunc(srcPR[y, x]);
 //            }
 //        }
 //        progressPercentage += progressUnit;
 //        Progress.Update(progressPercentage);
 //    }
 //    _drawable.Flush();
 //    _drawable.MergeShadow(true);
 //    _drawable.Update(_rectangle);
 //}
 public override Pixel getPixel(int x, int y)
 {
     Pixel pixel = new Pixel(_drawable.Bpp);
     pixel.X = x;
     pixel.Y = y;
     pixel.CopyFrom(_imageBuffer, (y * _rectangle.Width + x) * _drawable.Bpp);
     return pixel;
 }