コード例 #1
0
        ActualBitmap GetTransformedBitmapNoInterpolation()
        {
            var    destCB     = new ActualBitmap(_destBounds.Width, _destBounds.Height);
            var    destWriter = new MyBitmapBlender(destCB);
            PointF ptInPlane  = new PointF();

            int    x1, y1;
            double dab, dbc, dcd, dda;

            int    rectWidth  = _destBounds.Width;
            int    rectHeight = _destBounds.Height;
            Vector ab_vec     = this.AB;
            Vector bc_vec     = this.BC;
            Vector cd_vec     = this.CD;
            Vector da_vec     = this.DA;
            int    rectLeft   = this._destBounds.Left;
            int    rectTop    = this._destBounds.Top;

            TempMemPtr bufferPtr = _srcBmp.GetBufferPtr();

            unsafe
            {
                BufferReader4 reader = new BufferReader4((int *)bufferPtr.Ptr, _srcBmp.Width, _srcBmp.Height);

                for (int y = 0; y < rectHeight; ++y)
                {
                    for (int x = 0; x < rectWidth; ++x)
                    {
                        PointF srcPt = new PointF(x, y);
                        srcPt.Offset(rectLeft, rectTop);
                        if (!IsOnPlaneABCD(srcPt))
                        {
                            continue;
                        }
                        x1 = (int)ptInPlane.X;
                        y1 = (int)ptInPlane.Y;

                        reader.SetStartPixel(x1, y1);
                        destWriter.SetPixel(x, y, reader.Read1());
                        //-------------------------------------
                        dab         = Math.Abs((MyVectorHelper.NewFromTwoPoints(_p0, srcPt)).CrossProduct(ab_vec));
                        dbc         = Math.Abs((MyVectorHelper.NewFromTwoPoints(_p1, srcPt)).CrossProduct(bc_vec));
                        dcd         = Math.Abs((MyVectorHelper.NewFromTwoPoints(_p2, srcPt)).CrossProduct(cd_vec));
                        dda         = Math.Abs((MyVectorHelper.NewFromTwoPoints(_p3, srcPt)).CrossProduct(da_vec));
                        ptInPlane.X = (float)(srcW * (dda / (dda + dbc)));
                        ptInPlane.Y = (float)(srcH * (dab / (dab + dcd)));
                    }
                }
                return(destCB);
            }
        }
コード例 #2
0
        public void Sharpen(IBitmapSrc img, int radius)
        {
            unsafe
            {
                TempMemPtr bufferPtr = img.GetBufferPtr();
                int[]      output    = new int[bufferPtr.LengthInBytes / 4]; //TODO: review here again

                fixed(int *outputPtr = &output[0])
                {
                    byte *srcBuffer     = (byte *)bufferPtr.Ptr;
                    int * srcBuffer1    = (int *)srcBuffer;
                    int * outputBuffer1 = (int *)outputPtr;
                    int   stride        = img.Stride;
                    int   w             = img.Width;
                    int   h             = img.Height;

                    MemHolder srcMemHolder = new MemHolder((IntPtr)srcBuffer1, bufferPtr.LengthInBytes / 4);//
                    Surface   srcSurface   = new Surface(stride, w, h, srcMemHolder);
                    //
                    MemHolder destMemHolder = new MemHolder((IntPtr)outputPtr, bufferPtr.LengthInBytes / 4);
                    Surface   destSurface   = new Surface(stride, w, h, destMemHolder);
                    //
                    SharpenRenderer shRenderer1 = new SharpenRenderer();

                    shRenderer1.Amount = radius;
                    shRenderer1.Render(srcSurface, destSurface, new PixelFarm.Drawing.Rectangle[] {
                        new PixelFarm.Drawing.Rectangle(0, 0, w, h)
                    }, 0, 1);
                }

                bufferPtr.Release();
                //ActualImage.SaveImgBufferToPngFile(output, img.Stride, img.Width + 1, img.Height + 1, "d:\\WImageTest\\test_1.png");
                img.ReplaceBuffer(output);
            }
        }
コード例 #3
0
ファイル: TempMemPtr.cs プロジェクト: FeyoungL/Typography
        public unsafe static TempMemPtr FromBmp(IBitmapSrc actualBmp, out int *headPtr)
        {
            TempMemPtr ptr = actualBmp.GetBufferPtr();

            headPtr = (int *)ptr.Ptr;
            return(ptr);
        }
コード例 #4
0
        void Attach(IBitmapSrc sourceImage,
                    PixelBlender32 outputPxBlender,
                    int distanceBetweenPixelsInclusive,
                    int arrayElemOffset,
                    int bitsPerPixel)
        {
            _sourceImage = sourceImage;
            SetDimmensionAndFormat(sourceImage.Width,
                                   sourceImage.Height,
                                   sourceImage.Stride,
                                   bitsPerPixel,
                                   distanceBetweenPixelsInclusive);

            int srcOffset32 = sourceImage.GetBufferOffsetXY32(0, 0);

            SetBuffer(sourceImage.GetBufferPtr(), srcOffset32 + arrayElemOffset);
            this.OutputPixelBlender = outputPxBlender;
        }
コード例 #5
0
        internal unsafe static void NN_StepXBy1(IBitmapSrc bmpsrc, int srcIndex, Drawing.Color[] outputColors, int dstIndex, int len)
        {
            using (CpuBlit.TempMemPtr srcBufferPtr = bmpsrc.GetBufferPtr())
            {
                int *pSource = (int *)srcBufferPtr.Ptr + srcIndex;
                do
                {
                    int srcColor = *pSource;
                    //separate each component
                    //TODO: review here, color from source buffer
                    //should be in 'pre-multiplied' format.
                    //so it should be converted to 'straight' color by call something like ..'FromPreMult()'
                    outputColors[dstIndex++] = Drawing.Color.FromArgb(
                        (srcColor >> CO.A_SHIFT) & 0xff,  //a
                        (srcColor >> CO.R_SHIFT) & 0xff,  //r
                        (srcColor >> CO.G_SHIFT) & 0xff,  //g
                        (srcColor >> CO.B_SHIFT) & 0xff); //b

                    pSource++;                            //move next
                } while (--len != 0);
            }
        }
コード例 #6
0
 //public int GetByteBufferOffsetXY(int x, int y)
 //{
 //    throw new NotImplementedException();
 //}
 public TempMemPtr GetBufferPtr()
 {
     return(_src.GetBufferPtr());
 }
コード例 #7
0
        public void Fill(IBitmapSrc bufferToFillOn, int x, int y)
        {
            y -= imageHeight;
            unchecked // this way we can overflow the uint on negative and get a big number
            {
                if ((uint)x >= bufferToFillOn.Width || (uint)y >= bufferToFillOn.Height)
                {
                    return;
                }
            }
            _destImgRW = bufferToFillOn;
            TempMemPtr destBufferPtr = bufferToFillOn.GetBufferPtr();

            unsafe
            {
                imageWidth  = bufferToFillOn.Width;
                imageHeight = bufferToFillOn.Height;
                //reset new buffer, clear mem?
                pixelsChecked = new bool[imageWidth * imageHeight];

                int *destBuffer             = (int *)destBufferPtr.Ptr;
                int  startColorBufferOffset = bufferToFillOn.GetBufferOffsetXY32(x, y);

                int start_color = *(destBuffer + startColorBufferOffset);

                fillRule.SetStartColor(Drawing.Color.FromArgb(
                                           (start_color >> 16) & 0xff,
                                           (start_color >> 8) & 0xff,
                                           (start_color) & 0xff));


                LinearFill(destBuffer, x, y);

                while (ranges.Count > 0)
                {
                    Range range           = ranges.Dequeue();
                    int   downY           = range.y - 1;
                    int   upY             = range.y + 1;
                    int   downPixelOffset = (imageWidth * (range.y - 1)) + range.startX;
                    int   upPixelOffset   = (imageWidth * (range.y + 1)) + range.startX;
                    for (int rangeX = range.startX; rangeX <= range.endX; rangeX++)
                    {
                        if (range.y > 0)
                        {
                            if (!pixelsChecked[downPixelOffset])
                            {
                                int bufferOffset = bufferToFillOn.GetBufferOffsetXY32(rangeX, downY);

                                if (fillRule.CheckPixel(*(destBuffer + bufferOffset)))
                                {
                                    LinearFill(destBuffer, rangeX, downY);
                                }
                            }
                        }

                        if (range.y < (imageHeight - 1))
                        {
                            if (!pixelsChecked[upPixelOffset])
                            {
                                int bufferOffset = bufferToFillOn.GetBufferOffsetXY32(rangeX, upY);
                                if (fillRule.CheckPixel(*(destBuffer + bufferOffset)))
                                {
                                    LinearFill(destBuffer, rangeX, upY);
                                }
                            }
                        }
                        upPixelOffset++;
                        downPixelOffset++;
                    }
                }
            }
            destBufferPtr.Release();
        }
コード例 #8
0
        public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len)
        {
            ISpanInterpolator spanInterpolator = Interpolator;

            spanInterpolator.Begin(x + dx, y + dy, len);
            int x_hr;
            int y_hr;

            spanInterpolator.GetCoord(out x_hr, out y_hr);
            int x_lr = x_hr >> img_subpix_const.SHIFT;
            int y_lr = y_hr >> img_subpix_const.SHIFT;

            int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr);

            unsafe
            {
                using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = _bmpSrc.GetBufferPtr())
                {
                    int *pSource = (int *)srcBufferPtr.Ptr + bufferIndex;

                    do
                    {
                        int src_value = *pSource;
                        //separate each component
                        //TODO: review here, color from source buffer
                        //should be in 'pre-multiplied' format.
                        //so it should be converted to 'straight' color by call something like ..'FromPreMult()'

                        outputColors[startIndex++] = Drawing.Color.FromArgb(
                            (byte)((src_value >> 24) & 0xff), //a
                            (byte)((src_value >> 16) & 0xff), //r
                            (byte)((src_value >> 8) & 0xff),  //g
                            (byte)((src_value) & 0xff));      //b

                        pSource++;                            //move next
                    } while (--len != 0);
                }
            }



            //version 1 , incorrect
            //ISpanInterpolator spanInterpolator = Interpolator;
            //spanInterpolator.Begin(x + dx, y + dy, len);
            //int x_hr;
            //int y_hr;
            //spanInterpolator.GetCoord(out x_hr, out y_hr);
            //int x_lr = x_hr >> img_subpix_const.SHIFT;
            //int y_lr = y_hr >> img_subpix_const.SHIFT;
            //int bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr);
            //byte[] srcBuffer = srcRW.GetBuffer();
            //unsafe
            //{
            //    fixed (byte* pSource = srcBuffer)
            //    {
            //        do
            //        {
            //            outputColors[startIndex++] = *(Drawing.Color*)&(pSource[bufferIndex]);
            //            bufferIndex += 4;
            //        } while (--len != 0);
            //    }
            //}
        }
コード例 #9
0
        public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len)
        {
#if DEBUG
            int tmp_len = len;
#endif
            unsafe
            {
                //TODO: review here

                if (_mode0)
                {
                    using (CpuBlit.Imaging.TempMemPtr.FromBmp(_imgsrc, out int *srcBuffer))
                    {
                        int bufferIndex = _imgsrc.GetBufferOffsetXY32(x, y);
                        //unsafe
                        {
#if true
                            do
                            {
                                //TODO: review here, match component?
                                //ORDER IS IMPORTANT!
                                //TODO : use CO (color order instead)
                                int color = srcBuffer[bufferIndex++];

                                //byte b = (byte)srcBuffer[bufferIndex++];
                                //byte g = (byte)srcBuffer[bufferIndex++];
                                //byte r = (byte)srcBuffer[bufferIndex++];
                                //byte a = (byte)srcBuffer[bufferIndex++];

                                //outputColors[startIndex] = Drawing.Color.FromArgb(a, r, g, b);
                                outputColors[startIndex] = Drawing.Color.FromArgb(
                                    (color >> 24) & 0xff, //a
                                    (color >> 16) & 0xff, //r
                                    (color >> 8) & 0xff,  //b
                                    (color) & 0xff        //b
                                    );

                                ++startIndex;
                            } while (--len != 0);
#else
                            fixed(byte *pSource = &fg_ptr[bufferIndex])
                            {
                                int *pSourceInt = (int *)pSource;

                                fixed(RGBA_Bytes *pDest = &span[spanIndex])
                                {
                                    int *pDestInt = (int *)pDest;

                                    do
                                    {
                                        *pDestInt++ = *pSourceInt++;
                                    } while (--len != 0);
                                }
                            }
#endif
                        }
                    }
                }
                else
                {
                    ISpanInterpolator spanInterpolator = base.Interpolator;
                    using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = _imgsrc.GetBufferPtr())
                    {
                        int *srcBuffer = (int *)srcBufferPtr.Ptr;

                        spanInterpolator.Begin(x + base.dx, y + base.dy, len);
                        int accColor0, accColor1, accColor2, accColor3;
                        int back_r = m_bgcolor.red;
                        int back_g = m_bgcolor.green;
                        int back_b = m_bgcolor.blue;
                        int back_a = m_bgcolor.alpha;
                        int maxx   = _imgsrc.Width - 1;
                        int maxy   = _imgsrc.Height - 1;
                        int color  = 0;

                        unchecked
                        {
                            do
                            {
                                int x_hr;
                                int y_hr;
                                spanInterpolator.GetCoord(out x_hr, out y_hr);
                                x_hr -= base.dxInt;
                                y_hr -= base.dyInt;
                                int x_lr = x_hr >> img_subpix_const.SHIFT;
                                int y_lr = y_hr >> img_subpix_const.SHIFT;
                                int weight;
                                if (x_lr >= 0 && y_lr >= 0 &&
                                    x_lr < maxx && y_lr < maxy)
                                {
                                    int bufferIndex = _imgsrc.GetBufferOffsetXY32(x_lr, y_lr);


                                    accColor0             =
                                        accColor1         =
                                            accColor2     =
                                                accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2;

                                    x_hr &= img_subpix_const.MASK;
                                    y_hr &= img_subpix_const.MASK;

                                    //bufferIndex = _imgsrc.GetBufferOffsetXY32(x_lr, y_lr);

                                    weight = ((img_subpix_const.SCALE - x_hr) *
                                              (img_subpix_const.SCALE - y_hr));
                                    if (weight > BASE_MASK)
                                    {
                                        color = srcBuffer[bufferIndex];

                                        accColor3 += weight * ((color >> 24) & 0xff); //a
                                        accColor0 += weight * ((color >> 16) & 0xff); //r
                                        accColor1 += weight * ((color >> 8) & 0xff);  //g
                                        accColor2 += weight * ((color) & 0xff);       //b
                                    }

                                    weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr));
                                    if (weight > BASE_MASK)
                                    {
                                        bufferIndex++;
                                        color = srcBuffer[bufferIndex];
                                        //
                                        accColor3 += weight * ((color >> 24) & 0xff); //a
                                        accColor0 += weight * ((color >> 16) & 0xff); //r
                                        accColor1 += weight * ((color >> 8) & 0xff);  //g
                                        accColor2 += weight * ((color) & 0xff);       //b
                                    }

                                    weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr);
                                    if (weight > BASE_MASK)
                                    {
                                        ++y_lr;
                                        //
                                        bufferIndex = _imgsrc.GetBufferOffsetXY32(x_lr, y_lr);
                                        color       = srcBuffer[bufferIndex];
                                        //
                                        accColor3 += weight * ((color >> 24) & 0xff); //a
                                        accColor0 += weight * ((color >> 16) & 0xff); //r
                                        accColor1 += weight * ((color >> 8) & 0xff);  //g
                                        accColor2 += weight * ((color) & 0xff);       //b
                                    }
                                    weight = (x_hr * y_hr);
                                    if (weight > BASE_MASK)
                                    {
                                        bufferIndex++;
                                        color = srcBuffer[bufferIndex];
                                        //
                                        accColor3 += weight * ((color >> 24) & 0xff); //a
                                        accColor0 += weight * ((color >> 16) & 0xff); //r
                                        accColor1 += weight * ((color >> 8) & 0xff);  //g
                                        accColor2 += weight * ((color) & 0xff);       //b
                                    }
                                    accColor0 >>= img_subpix_const.SHIFT * 2;
                                    accColor1 >>= img_subpix_const.SHIFT * 2;
                                    accColor2 >>= img_subpix_const.SHIFT * 2;
                                    accColor3 >>= img_subpix_const.SHIFT * 2;
                                }
                                else
                                {
                                    if (x_lr < -1 || y_lr < -1 ||
                                        x_lr > maxx || y_lr > maxy)
                                    {
                                        accColor0 = back_r;
                                        accColor1 = back_g;
                                        accColor2 = back_b;
                                        accColor3 = back_a;
                                    }
                                    else
                                    {
                                        accColor0             =
                                            accColor1         =
                                                accColor2     =
                                                    accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2;
                                        x_hr  &= (int)img_subpix_const.MASK;
                                        y_hr  &= (int)img_subpix_const.MASK;
                                        weight = (((int)img_subpix_const.SCALE - x_hr) *
                                                  ((int)img_subpix_const.SCALE - y_hr));
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(
                                                    ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                    srcBuffer,
                                                    _imgsrc.GetBufferOffsetXY32(x_lr, y_lr),
                                                    weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        x_lr++;
                                        weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr));
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                                   srcBuffer,
                                                                   _imgsrc.GetBufferOffsetXY32(x_lr, y_lr),
                                                                   weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        x_lr--;
                                        y_lr++;
                                        weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr);
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                                   srcBuffer,
                                                                   _imgsrc.GetBufferOffsetXY32(x_lr, y_lr),
                                                                   weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        x_lr++;
                                        weight = (x_hr * y_hr);
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                                   srcBuffer,
                                                                   _imgsrc.GetBufferOffsetXY32(x_lr, y_lr),
                                                                   weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        accColor0 >>= img_subpix_const.SHIFT * 2;
                                        accColor1 >>= img_subpix_const.SHIFT * 2;
                                        accColor2 >>= img_subpix_const.SHIFT * 2;
                                        accColor3 >>= img_subpix_const.SHIFT * 2;
                                    }
                                }

#if DEBUG
                                if (startIndex >= outputColors.Length)
                                {
                                }
#endif
                                outputColors[startIndex] = PixelFarm.Drawing.Color.FromArgb(
                                    (byte)accColor3,
                                    (byte)accColor0,
                                    (byte)accColor1,
                                    (byte)accColor2
                                    );

                                //outputColors[startIndex].red = (byte)accColor0;
                                //outputColors[startIndex].green = (byte)accColor1;
                                //outputColors[startIndex].blue = (byte)accColor2;
                                //outputColors[startIndex].alpha = (byte)accColor3;
                                ++startIndex;
                                spanInterpolator.Next();
                            } while (--len != 0);
                        }
                    }
                }
            }
        }
コード例 #10
0
        // Create
        //--------------------------------------------------------------------
        public void Create(IBitmapSrc src)
        {
            // we are going to create a dialated image for filtering
            // we add m_dilation pixels to every side of the image and then copy the image in the x
            // dirrection into each end so that we can sample into this image to get filtering on x repeating
            // if the original image look like this
            //
            // 123456
            //
            // the new image would look like this
            //
            // 0000000000
            // 0000000000
            // 5612345612
            // 0000000000
            // 0000000000

            _height          = (int)AggMath.uceil(src.Height);
            _width           = (int)AggMath.uceil(src.Width);
            _width_hr        = (int)AggMath.uround(src.Width * LineAA.SUBPIXEL_SCALE);
            _half_height_hr  = (int)AggMath.uround(src.Height * LineAA.SUBPIXEL_SCALE / 2);
            _offset_y_hr     = _dilation_hr + _half_height_hr - LineAA.SUBPIXEL_SCALE / 2;
            _half_height_hr += LineAA.SUBPIXEL_SCALE / 2;
            int bufferWidth    = _width + _dilation * 2;
            int bufferHeight   = _height + _dilation * 2;
            int bytesPerPixel  = src.BitDepth / 8;
            int newSizeInBytes = bufferWidth * bufferHeight * bytesPerPixel;

            if (_DataSizeInBytes < newSizeInBytes)
            {
                _DataSizeInBytes = newSizeInBytes;

                _data.Dispose();

                IntPtr nativeBuff = System.Runtime.InteropServices.Marshal.AllocHGlobal(_DataSizeInBytes);
                _data = new TempMemPtr(nativeBuff, _DataSizeInBytes);
            }

            _buf = new PixelProcessing.SubBitmapBlender(_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel);

            unsafe
            {
                using (TempMemPtr destMemPtr = _buf.GetBufferPtr())
                    using (TempMemPtr srcMemPtr = src.GetBufferPtr())
                    {
                        int *destBuffer = (int *)destMemPtr.Ptr;
                        int *srcBuffer  = (int *)srcMemPtr.Ptr;
                        // copy the image into the middle of the dest
                        for (int y = 0; y < _height; y++)
                        {
                            for (int x = 0; x < _width; x++)
                            {
                                int sourceOffset = src.GetBufferOffsetXY32(x, y);
                                int destOffset   = _buf.GetBufferOffsetXY32(_dilation, y + _dilation);
                                destBuffer[destOffset] = srcBuffer[sourceOffset];
                            }
                        }

                        // copy the first two pixels form the end into the begining and from the begining into the end
                        for (int y = 0; y < _height; y++)
                        {
                            int s1Offset = src.GetBufferOffsetXY32(0, y);
                            int d1Offset = _buf.GetBufferOffsetXY32(_dilation + _width, y);
                            int s2Offset = src.GetBufferOffsetXY32(_width - _dilation, y);
                            int d2Offset = _buf.GetBufferOffsetXY32(0, y);

                            for (int x = 0; x < _dilation; x++)
                            {
                                destBuffer[d1Offset++] = srcBuffer[s1Offset++];
                                destBuffer[d2Offset++] = srcBuffer[s2Offset++];
                            }
                        }
                    }
            }
        }
コード例 #11
0
        // Create
        //--------------------------------------------------------------------
        public void Create(IBitmapSrc src)
        {
            // we are going to create a dialated image for filtering
            // we add m_dilation pixels to every side of the image and then copy the image in the x
            // dirrection into each end so that we can sample into this image to get filtering on x repeating
            // if the original image look like this
            //
            // 123456
            //
            // the new image would look like this
            //
            // 0000000000
            // 0000000000
            // 5612345612
            // 0000000000
            // 0000000000

            m_height          = (int)AggMath.uceil(src.Height);
            m_width           = (int)AggMath.uceil(src.Width);
            m_width_hr        = (int)AggMath.uround(src.Width * LineAA.SUBPIXEL_SCALE);
            m_half_height_hr  = (int)AggMath.uround(src.Height * LineAA.SUBPIXEL_SCALE / 2);
            m_offset_y_hr     = m_dilation_hr + m_half_height_hr - LineAA.SUBPIXEL_SCALE / 2;
            m_half_height_hr += LineAA.SUBPIXEL_SCALE / 2;
            int bufferWidth    = m_width + m_dilation * 2;
            int bufferHeight   = m_height + m_dilation * 2;
            int bytesPerPixel  = src.BitDepth / 8;
            int newSizeInBytes = bufferWidth * bufferHeight * bytesPerPixel;

            if (m_DataSizeInBytes < newSizeInBytes)
            {
                m_DataSizeInBytes = newSizeInBytes;
                m_data            = new int[m_DataSizeInBytes / 4];
            }


            m_buf = new PixelProcessing.SubBitmapBlender(m_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel);

            unsafe
            {
                CpuBlit.Imaging.TempMemPtr destMemPtr = m_buf.GetBufferPtr();
                CpuBlit.Imaging.TempMemPtr srcMemPtr  = src.GetBufferPtr();

                int *destBuffer = (int *)destMemPtr.Ptr;
                int *srcBuffer  = (int *)srcMemPtr.Ptr;
                // copy the image into the middle of the dest
                for (int y = 0; y < m_height; y++)
                {
                    for (int x = 0; x < m_width; x++)
                    {
                        int sourceOffset = src.GetBufferOffsetXY32(x, y);
                        int destOffset   = m_buf.GetBufferOffsetXY32(m_dilation, y + m_dilation);
                        destBuffer[destOffset] = srcBuffer[sourceOffset];
                    }
                }

                // copy the first two pixels form the end into the begining and from the begining into the end
                for (int y = 0; y < m_height; y++)
                {
                    int s1Offset = src.GetBufferOffsetXY32(0, y);
                    int d1Offset = m_buf.GetBufferOffsetXY32(m_dilation + m_width, y);
                    int s2Offset = src.GetBufferOffsetXY32(m_width - m_dilation, y);
                    int d2Offset = m_buf.GetBufferOffsetXY32(0, y);

                    for (int x = 0; x < m_dilation; x++)
                    {
                        destBuffer[d1Offset++] = srcBuffer[s1Offset++];
                        destBuffer[d2Offset++] = srcBuffer[s2Offset++];
                    }
                }

                srcMemPtr.Release();
                destMemPtr.Release();
            }
        }
コード例 #12
0
        void CopyFromNoClipping(IBitmapSrc sourceImage, Q1Rect clippedSourceImageRect, int destXOffset, int destYOffset)
        {
            if (BytesBetweenPixelsInclusive != BitDepth / 8 ||
                sourceImage.BytesBetweenPixelsInclusive != sourceImage.BitDepth / 8)
            {
                throw new Exception("WIP we only support packed pixel formats at this time.");
            }

            if (BitDepth == sourceImage.BitDepth)
            {
                int lengthInBytes = clippedSourceImageRect.Width * BytesBetweenPixelsInclusive;
                int sourceOffset  = sourceImage.GetBufferOffsetXY32(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom);

                unsafe
                {
                    using (TempMemPtr memPtr = sourceImage.GetBufferPtr())
                        using (TempMemPtr destPtr = this.GetBufferPtr())
                        {
                            byte *sourceBuffer = (byte *)memPtr.Ptr;
                            byte *destBuffer   = (byte *)destPtr.Ptr;
                            int   destOffset   = GetBufferOffsetXY32(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + destYOffset);

                            for (int i = 0; i < clippedSourceImageRect.Height; i++)
                            {
                                PixelFarm.Drawing.Internal.MemMx.memmove(destBuffer, destOffset * 4, sourceBuffer, sourceOffset, lengthInBytes);
                                sourceOffset += sourceImage.Stride;
                                destOffset   += Stride;
                            }
                        }
                }
            }
            else
            {
                bool haveConversion = true;
                switch (sourceImage.BitDepth)
                {
                case 24:
                    switch (BitDepth)
                    {
                    case 32:
                    {
                        //TODO: review here, this may not correct
                        int numPixelsToCopy = clippedSourceImageRect.Width;
                        for (int i = clippedSourceImageRect.Bottom; i < clippedSourceImageRect.Top; i++)
                        {
                            int sourceOffset = sourceImage.GetBufferOffsetXY32(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i);

                            //byte[] sourceBuffer = sourceImage.GetBuffer();
                            //byte[] destBuffer = GetBuffer();

                            using (TempMemPtr srcMemPtr = sourceImage.GetBufferPtr())
                                using (TempMemPtr destBufferPtr = this.GetBufferPtr())
                                {
                                    int destOffset = GetBufferOffsetXY32(
                                        clippedSourceImageRect.Left + destXOffset,
                                        clippedSourceImageRect.Bottom + i + destYOffset);
                                    unsafe
                                    {
                                        int *destBuffer   = (int *)destBufferPtr.Ptr;
                                        int *sourceBuffer = (int *)srcMemPtr.Ptr;
                                        for (int x = 0; x < numPixelsToCopy; x++)
                                        {
                                            int color = sourceBuffer[sourceOffset++];

                                            destBuffer[destOffset++] =
                                                (255 << 24) |          //a
                                                (color & 0xff0000) |   //b
                                                (color & 0x00ff00) |   //g
                                                (color & 0xff);

                                            //destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                            //destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                            //destBuffer[destOffset++] = 255;
                                        }
                                    }
                                }
                        }
                    }
                    break;

                    default:
                        haveConversion = false;
                        break;
                    }
                    break;

                default:
                    haveConversion = false;
                    break;
                }

                if (!haveConversion)
                {
                    throw new NotImplementedException("You need to write the " + sourceImage.BitDepth.ToString() + " to " + BitDepth.ToString() + " conversion");
                }
            }
        }