byte[] GetPixels(out int bufferByteOffset)
            {
                int x = m_x;
                int y = m_y;

                unchecked
                {
                    if ((uint)x >= (uint)m_src_width)
                    {
                        if (x < 0)
                        {
                            x = 0;
                        }
                        else
                        {
                            x = (int)m_src_width - 1;
                        }
                    }

                    if ((uint)y >= (uint)m_src_height)
                    {
                        if (y < 0)
                        {
                            y = 0;
                        }
                        else
                        {
                            y = (int)m_src_height - 1;
                        }
                    }
                }

                bufferByteOffset = imgRW.GetByteBufferOffsetXY(x, y);
                return(imgRW.GetBuffer());
            }
コード例 #2
0
 //--------------------------------------------------------------------
 public byte pixel(int x, int y)
 {
     unsafe
     {
         int        bufferIndex = m_rbuf.GetByteBufferOffsetXY(x, y);
         TempMemPtr tmpMem      = m_rbuf.GetBufferPtr();
         byte       value       = *((byte *)tmpMem.Ptr + bufferIndex);
         tmpMem.Release();
         return(value);
     }
 }
コード例 #3
0
        //--------------------------------------------------------------------
        public byte pixel(int x, int y)
        {
            unchecked
            {
                if ((uint)x < (uint)m_rbuf.Width &&
                    (uint)y < (uint)m_rbuf.Height)
                {
                    unsafe
                    {
                        int        bufferIndex = m_rbuf.GetByteBufferOffsetXY(x, y);
                        TempMemPtr tmpMem      = m_rbuf.GetBufferPtr();
                        byte       value       = *((byte *)tmpMem.Ptr + bufferIndex);
                        tmpMem.Release();
                        return(value);
                    }

                    //int bufferIndex = m_rbuf.GetByteBufferOffsetXY(x, y);
                    //byte[] buffer = m_rbuf.GetBuffer();
                    //return buffer[bufferIndex];
                }
            }

            return(0);
        }
コード例 #4
0
        /// <summary>
        /// This will create a new ImageBuffer that references the same memory as the image that you took the sub image from.
        /// It will modify the original main image when you draw to it.
        /// </summary>
        /// <param name="parentImage"></param>
        /// <param name="subImgBounds"></param>
        /// <returns></returns>
        public static SubImageRW CreateSubImgRW(IImageReaderWriter parentImage, RectInt subImgBounds)
        {
            if (subImgBounds.Left < 0 || subImgBounds.Bottom < 0 || subImgBounds.Right > parentImage.Width || subImgBounds.Top > parentImage.Height ||
                subImgBounds.Left >= subImgBounds.Right || subImgBounds.Bottom >= subImgBounds.Top)
            {
                throw new ArgumentException("The subImageBounds must be on the image and valid.");
            }

            int left   = Math.Max(0, subImgBounds.Left);
            int bottom = Math.Max(0, subImgBounds.Bottom);
            int width  = Math.Min(parentImage.Width - left, subImgBounds.Width);
            int height = Math.Min(parentImage.Height - bottom, subImgBounds.Height);
            int bufferOffsetToFirstPixel = parentImage.GetByteBufferOffsetXY(left, bottom);

            return(new SubImageRW(parentImage, bufferOffsetToFirstPixel / 4, width, height));
        }
コード例 #5
0
        void Attach(IImageReaderWriter sourceImage,
                    IPixelBlender recieveBlender,
                    int distanceBetweenPixelsInclusive,
                    int arrayElemOffset,
                    int bitsPerPixel)
        {
            _sourceImage = sourceImage;
            SetDimmensionAndFormat(sourceImage.Width,
                                   sourceImage.Height,
                                   sourceImage.Stride,
                                   bitsPerPixel,
                                   distanceBetweenPixelsInclusive);

            int srcOffset32 = sourceImage.GetByteBufferOffsetXY(0, 0) / 4;

            int[] buffer = sourceImage.GetInt32Buffer();
            SetBuffer(buffer, srcOffset32 + arrayElemOffset);
            SetRecieveBlender(recieveBlender);
        }
コード例 #6
0
        void CopyFromNoClipping(IImageReaderWriter sourceImage, RectInt 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.GetByteBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom);

                unsafe
                {
                    TempMemPtr memPtr  = sourceImage.GetBufferPtr();
                    TempMemPtr destPtr = this.GetBufferPtr();

                    byte *sourceBuffer = (byte *)memPtr.Ptr;
                    byte *destBuffer   = (byte *)destPtr.Ptr;
                    int   destOffset   = GetByteBufferOffsetXY(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + destYOffset);
                    for (int i = 0; i < clippedSourceImageRect.Height; i++)
                    {
                        AggMemMx.memmove(destBuffer, destOffset, sourceBuffer, sourceOffset, lengthInBytes);
                        sourceOffset += sourceImage.Stride;
                        destOffset   += Stride;
                    }

                    memPtr.Release();
                    destPtr.Release();
                }
            }
            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.GetByteBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i);

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

                            TempMemPtr srcMemPtr     = sourceImage.GetBufferPtr();
                            TempMemPtr destBufferPtr = this.GetBufferPtr();

                            int destOffset = GetByteBufferOffsetXY(
                                clippedSourceImageRect.Left + destXOffset,
                                clippedSourceImageRect.Bottom + i + destYOffset);
                            unsafe
                            {
                                byte *destBuffer   = (byte *)destBufferPtr.Ptr;
                                byte *sourceBuffer = (byte *)srcMemPtr.Ptr;
                                for (int x = 0; x < numPixelsToCopy; x++)
                                {
                                    destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                    destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                    destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                    destBuffer[destOffset++] = 255;
                                }
                            }


                            srcMemPtr.Release();
                            destBufferPtr.Release();
                        }
                    }
                    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");
                }
            }
        }
コード例 #7
0
ファイル: ProxyImage.cs プロジェクト: luislasonbra/PixelFarm
 public int GetByteBufferOffsetXY(int x, int y)
 {
     return(linkedImage.GetByteBufferOffsetXY(x, y));
 }
コード例 #8
0
        // Create
        //--------------------------------------------------------------------
        public void Create(IImageReaderWriter 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 SubImageRW(m_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel);

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

                byte *destBuffer = (byte *)destMemPtr.Ptr;
                byte *srcBuffer  = (byte *)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.GetByteBufferOffsetXY(x, y);
                        int destOffset   = m_buf.GetByteBufferOffsetXY(m_dilation, y + m_dilation);
                        for (int channel = 0; channel < bytesPerPixel; channel++)
                        {
                            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.GetByteBufferOffsetXY(0, y);
                    int d1Offset = m_buf.GetByteBufferOffsetXY(m_dilation + m_width, y);
                    int s2Offset = src.GetByteBufferOffsetXY(m_width - m_dilation, y);
                    int d2Offset = m_buf.GetByteBufferOffsetXY(0, y);
                    for (int x = 0; x < m_dilation; x++)
                    {
                        for (int channel = 0; channel < bytesPerPixel; channel++)
                        {
                            destBuffer[d1Offset++] = srcBuffer[s1Offset++];
                            destBuffer[d2Offset++] = srcBuffer[s2Offset++];
                        }
                    }
                }

                srcMemPtr.Release();
                destMemPtr.Release();
            }
        }