public byte Pixel(int x, int y)
 {
     if (x >= 0 && y >= 0 &&
         x < (int)_rasterBuffer.Width() &&
         y < (int)_rasterBuffer.Height())
     {
         unsafe
         {
             return(*(_rasterBuffer.GetPixelPointer(y) + x * _step + _offset));
         }
     }
     return(0);
 }
Beispiel #2
0
        public void CopyFrom(RasterBuffer src,
                             RectI rect_src_ptr,
                             int dx,
                             int dy)
        {
            RectI rsrc = new RectI(rect_src_ptr.x1, rect_src_ptr.y1, rect_src_ptr.x2 + 1, rect_src_ptr.y2 + 1);

            // Version with xdst, ydst (absolute positioning)
            //RectI rdst(xdst, ydst, xdst + rsrc.x2 - rsrc.x1, ydst + rsrc.y2 - rsrc.y1);

            // Version with dx, dy (relative positioning)
            RectI rdst = new RectI(rsrc.x1 + dx, rsrc.y1 + dy, rsrc.x2 + dx, rsrc.y2 + dy);

            RectI rc = ClipRectangleArea(ref rdst, ref rsrc, (int)src.Width(), (int)src.Height());

            if (rc.x2 > 0)
            {
                int incy = 1;
                if (rdst.y1 > rsrc.y1)
                {
                    rsrc.y1 += rc.y2 - 1;
                    rdst.y1 += rc.y2 - 1;
                    incy     = -1;
                }
                while (rc.y2 > 0)
                {
                    base.CopyFrom(src,
                                  rdst.x1, rdst.y1,
                                  rsrc.x1, rsrc.y1,
                                  (uint)rc.x2);
                    rdst.y1 += incy;
                    rsrc.y1 += incy;
                    --rc.y2;
                }
            }
        }
Beispiel #3
0
        public void CopyFrom(RasterBuffer src,
					   RectI rect_src_ptr,
					   int dx,
					   int dy)
        {
            RectI rsrc = new RectI(rect_src_ptr.x1, rect_src_ptr.y1, rect_src_ptr.x2 + 1, rect_src_ptr.y2 + 1);

            // Version with xdst, ydst (absolute positioning)
            //RectI rdst(xdst, ydst, xdst + rsrc.x2 - rsrc.x1, ydst + rsrc.y2 - rsrc.y1);

            // Version with dx, dy (relative positioning)
            RectI rdst = new RectI(rsrc.x1 + dx, rsrc.y1 + dy, rsrc.x2 + dx, rsrc.y2 + dy);

            RectI rc = ClipRectangleArea(ref rdst, ref rsrc, (int)src.Width(), (int)src.Height());

            if (rc.x2 > 0)
            {
                int incy = 1;
                if (rdst.y1 > rsrc.y1)
                {
                    rsrc.y1 += rc.y2 - 1;
                    rdst.y1 += rc.y2 - 1;
                    incy = -1;
                }
                while (rc.y2 > 0)
                {
                    base.CopyFrom(src,
                                     rdst.x1, rdst.y1,
                                     rsrc.x1, rsrc.y1,
                                     (uint)rc.x2);
                    rdst.y1 += incy;
                    rsrc.y1 += incy;
                    --rc.y2;
                }
            }
        }
Beispiel #4
0
 public void CopyFrom(RasterBuffer src)
 {
     CopyFrom(src, new RectI(0, 0, (int)src.Width(), (int)src.Height()), 0, 0);
 }
        // Create
        //--------------------------------------------------------------------
        public void create(RasterBuffer src)
        {
            m_height          = (int)agg_basics.uceil(src.Height());
            m_width           = (int)agg_basics.uceil(src.Width());
            m_width_hr        = (int)agg_basics.uround(src.Width() * LineAABasics.line_subpixel_scale);
            m_half_height_hr  = (int)agg_basics.uround(src.Height() * LineAABasics.line_subpixel_scale / 2);
            m_offset_y_hr     = m_dilation_hr + m_half_height_hr - LineAABasics.line_subpixel_scale / 2;
            m_half_height_hr += LineAABasics.line_subpixel_scale / 2;

            int NewSizeInBytes = (m_width + m_dilation * 2) * (m_height + m_dilation * 2);

            if (m_DataSizeInBytes < NewSizeInBytes)
            {
                if (m_data != null)
                {
                    System.Runtime.InteropServices.Marshal.FreeHGlobal(m_data);
                }
                m_DataSizeInBytes = NewSizeInBytes;
                m_data            = System.Runtime.InteropServices.Marshal.AllocHGlobal(m_DataSizeInBytes);
            }

            unsafe
            {
                m_buf.attach((byte *)m_data,
                             (uint)(m_width + m_dilation * 2),
                             (uint)(m_height + m_dilation * 2),
                             (int)(m_width + m_dilation * 2),
                             32);

                int         x, y;
                RGBA_Bytes *d1;
                RGBA_Bytes *d2;
                for (y = 0; y < m_height; y++)
                {
                    d1 = (RGBA_Bytes *)m_buf.GetPixelPointer(y + m_dilation) + m_dilation;
                    for (x = 0; x < m_width; x++)
                    {
                        *d1++ = *(RGBA_Bytes *)src.GetPixelPointer(x, y);
                    }
                }

                RGBA_Bytes *s1;
                RGBA_Bytes *s2;
                RGBA_Bytes  noColor = (RGBA_Bytes)RGBA_Bytes.no_color();
                for (y = 0; y < m_dilation; y++)
                {
                    //s1 = m_buf.GetPixelPointer(m_height + m_dilation - 1) + m_dilation;
                    //s2 = m_buf.GetPixelPointer(m_dilation) + m_dilation;
                    d1 = (RGBA_Bytes *)m_buf.GetPixelPointer(m_dilation + m_height + y) + m_dilation;
                    d2 = (RGBA_Bytes *)m_buf.GetPixelPointer(m_dilation - y - 1) + m_dilation;
                    for (x = 0; x < m_width; x++)
                    {
                        //*d1++ = RGBA_Bytes(*s1++, 0);
                        //*d2++ = RGBA_Bytes(*s2++, 0);
                        *d1++ = noColor;
                        *d2++ = noColor;
                    }
                }

                int h = m_height + m_dilation * 2;
                for (y = 0; y < h; y++)
                {
                    s1 = (RGBA_Bytes *)m_buf.GetPixelPointer(y) + m_dilation;
                    s2 = (RGBA_Bytes *)m_buf.GetPixelPointer(y) + m_dilation + m_width;
                    d1 = (RGBA_Bytes *)m_buf.GetPixelPointer(y) + m_dilation + m_width;
                    d2 = (RGBA_Bytes *)m_buf.GetPixelPointer(y) + m_dilation;

                    for (x = 0; x < m_dilation; x++)
                    {
                        *d1++ = *s1++;
                        *--d2 = *--s2;
                    }
                }
            }
        }
        public bool load_pmap(string fn, uint idx, RasterBuffer dst)
        {
            PixelMap pmap_tmp = new PixelMap();
            if (!pmap_tmp.load_from_bmp(fn)) return false;

            RasterBuffer rbuf_tmp = new RasterBuffer();
            unsafe
            {
                rbuf_tmp.Attach(pmap_tmp.buf(),
                                pmap_tmp.Width(),
                                pmap_tmp.Height(),
                                m_app.FlipY() ?
                                  pmap_tmp.stride() :
                                 -pmap_tmp.stride(),
                                 pmap_tmp.bpp());

                m_pmap_img[idx] = new PixelMap();
                m_pmap_img[idx].Create(pmap_tmp.Width(), pmap_tmp.Height(),
                    PlatformSupportAbstract.GetBitDepthForPixelFormat(m_format),
                    0);

                dst.Attach(m_pmap_img[idx].buf(),
                    m_pmap_img[idx].Width(),
                    m_pmap_img[idx].Height(),
                    m_app.FlipY() ?
                    m_pmap_img[idx].stride() :
                    -m_pmap_img[idx].stride(), m_pmap_img[idx].bpp());

                switch (m_format)
                {
                    case PlatformSupportAbstract.PixelFormats.Bgr24:
                        switch (pmap_tmp.bpp())
                        {
                            case 24:
                                unsafe
                                {
                                    for (uint y = 0; y < rbuf_tmp.Height(); y++)
                                    {
                                        byte* sourceBuffer = rbuf_tmp.GetPixelPointer((int)rbuf_tmp.Height() - (int)y - 1);
                                        byte* destBuffer = dst.GetPixelPointer((int)y);
                                        for (uint x = 0; x < rbuf_tmp.Width(); x++)
                                        {
                                            *destBuffer++ = sourceBuffer[0];
                                            *destBuffer++ = sourceBuffer[1];
                                            *destBuffer++ = sourceBuffer[2];
                                            sourceBuffer += 3;
                                        }
                                    }
                                }
                                break;

                            default:
                                throw new System.NotImplementedException();
                        }
                        break;

                    case PlatformSupportAbstract.PixelFormats.Rgb24:
                        switch (pmap_tmp.bpp())
                        {
                            //                 case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgb24()); break;
                            case 24:

                                //color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgba32());
                                unsafe
                                {
                                    for (uint y = 0; y < rbuf_tmp.Height(); y++)
                                    {
                                        byte* sourceBuffer = rbuf_tmp.GetPixelPointer((int)rbuf_tmp.Height() - (int)y - 1);
                                        byte* destBuffer = dst.GetPixelPointer((int)y);
                                        for (uint x = 0; x < rbuf_tmp.Width(); x++)
                                        {
                                            *destBuffer++ = sourceBuffer[2];
                                            *destBuffer++ = sourceBuffer[1];
                                            *destBuffer++ = sourceBuffer[0];
                                            sourceBuffer += 3;
                                        }
                                    }
                                }
                                break;

                            //                 case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb24()); break;
                            default:
                                throw new System.NotImplementedException();
                        }
                        break;

                    case PlatformSupportAbstract.PixelFormats.Bgra32:
                        switch (pmap_tmp.bpp())
                        {
                            case 24:
                                unsafe
                                {
                                    for (uint y = 0; y < rbuf_tmp.Height(); y++)
                                    {
                                        byte* sourceBuffer = rbuf_tmp.GetPixelPointer((int)rbuf_tmp.Height() - (int)y - 1);
                                        byte* destBuffer = dst.GetPixelPointer((int)y);
                                        for (uint x = 0; x < rbuf_tmp.Width(); x++)
                                        {
                                            *destBuffer++ = sourceBuffer[0];
                                            *destBuffer++ = sourceBuffer[1];
                                            *destBuffer++ = sourceBuffer[2];
                                            *destBuffer++ = 255;
                                            sourceBuffer += 3;
                                        }
                                    }
                                }
                                break;
                        }
                        break;

                    case PlatformSupportAbstract.PixelFormats.Rgba32:
                        switch (pmap_tmp.bpp())
                        {
                            //                 case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgba32()); break;
                            case 24:

                                //color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgba32());
                                unsafe
                                {
                                    for (uint y = 0; y < rbuf_tmp.Height(); y++)
                                    {
                                        byte* sourceBuffer = rbuf_tmp.GetPixelPointer((int)rbuf_tmp.Height() - (int)y - 1);
                                        byte* destBuffer = dst.GetPixelPointer((int)y);
                                        for (uint x = 0; x < rbuf_tmp.Width(); x++)
                                        {
                                            *destBuffer++ = sourceBuffer[2];
                                            *destBuffer++ = sourceBuffer[1];
                                            *destBuffer++ = sourceBuffer[0];
                                            *destBuffer++ = 255;
                                            sourceBuffer += 3;
                                        }
                                    }
                                }
                                break;

                            //                 case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgba32()); break;
                            default:
                                throw new System.NotImplementedException();
                        }
                        break;

                    default:
                        throw new System.NotImplementedException();
                }
            }

            return true;
        }
        // Create
        //--------------------------------------------------------------------
        public void create(RasterBuffer src)
        {
            m_height = (int)agg_basics.uceil(src.Height());
            m_width = (int)agg_basics.uceil(src.Width());
            m_width_hr = (int)agg_basics.uround(src.Width() * LineAABasics.line_subpixel_scale);
            m_half_height_hr = (int)agg_basics.uround(src.Height() * LineAABasics.line_subpixel_scale / 2);
            m_offset_y_hr = m_dilation_hr + m_half_height_hr - LineAABasics.line_subpixel_scale / 2;
            m_half_height_hr += LineAABasics.line_subpixel_scale / 2;

            int NewSizeInBytes = (m_width + m_dilation * 2) * (m_height + m_dilation * 2);
            if (m_DataSizeInBytes < NewSizeInBytes)
            {
                if (m_data != null)
                {
                    System.Runtime.InteropServices.Marshal.FreeHGlobal(m_data);
                }
                m_DataSizeInBytes = NewSizeInBytes;
                m_data = System.Runtime.InteropServices.Marshal.AllocHGlobal(m_DataSizeInBytes);
            }

            unsafe
            {
                m_buf.attach((byte*)m_data,
                    (uint)(m_width + m_dilation * 2),
                    (uint)(m_height + m_dilation * 2),
                    (int)(m_width + m_dilation * 2),
                    32);

                int x, y;
                RGBA_Bytes* d1;
                RGBA_Bytes* d2;
                for (y = 0; y < m_height; y++)
                {
                    d1 = (RGBA_Bytes*)m_buf.GetPixelPointer(y + m_dilation) + m_dilation;
                    for (x = 0; x < m_width; x++)
                    {
                        *d1++ = *(RGBA_Bytes*)src.GetPixelPointer(x, y);
                    }
                }

                RGBA_Bytes* s1;
                RGBA_Bytes* s2;
                RGBA_Bytes noColor = (RGBA_Bytes)RGBA_Bytes.no_color();
                for (y = 0; y < m_dilation; y++)
                {
                    //s1 = m_buf.GetPixelPointer(m_height + m_dilation - 1) + m_dilation;
                    //s2 = m_buf.GetPixelPointer(m_dilation) + m_dilation;
                    d1 = (RGBA_Bytes*)m_buf.GetPixelPointer(m_dilation + m_height + y) + m_dilation;
                    d2 = (RGBA_Bytes*)m_buf.GetPixelPointer(m_dilation - y - 1) + m_dilation;
                    for (x = 0; x < m_width; x++)
                    {
                        //*d1++ = RGBA_Bytes(*s1++, 0);
                        //*d2++ = RGBA_Bytes(*s2++, 0);
                        *d1++ = noColor;
                        *d2++ = noColor;
                    }
                }

                int h = m_height + m_dilation * 2;
                for (y = 0; y < h; y++)
                {
                    s1 = (RGBA_Bytes*)m_buf.GetPixelPointer(y) + m_dilation;
                    s2 = (RGBA_Bytes*)m_buf.GetPixelPointer(y) + m_dilation + m_width;
                    d1 = (RGBA_Bytes*)m_buf.GetPixelPointer(y) + m_dilation + m_width;
                    d2 = (RGBA_Bytes*)m_buf.GetPixelPointer(y) + m_dilation;

                    for (x = 0; x < m_dilation; x++)
                    {
                        *d1++ = *s1++;
                        *--d2 = *--s2;
                    }
                }
            }
        }
Beispiel #8
0
 public void CopyFrom(RasterBuffer src)
 {
     CopyFrom(src, new RectI(0, 0, (int)src.Width(), (int)src.Height()), 0, 0);
 }
Beispiel #9
0
        public bool load_pmap(string fn, uint idx, RasterBuffer dst)
        {
            PixelMap pmap_tmp = new PixelMap();

            if (!pmap_tmp.load_from_bmp(fn))
            {
                return(false);
            }

            RasterBuffer rbuf_tmp = new RasterBuffer();

            unsafe
            {
                rbuf_tmp.Attach(pmap_tmp.buf(),
                                pmap_tmp.Width(),
                                pmap_tmp.Height(),
                                m_app.FlipY() ?
                                pmap_tmp.stride() :
                                -pmap_tmp.stride(),
                                pmap_tmp.bpp());

                m_pmap_img[idx] = new PixelMap();
                m_pmap_img[idx].Create(pmap_tmp.Width(), pmap_tmp.Height(),
                                       PlatformSupportAbstract.GetBitDepthForPixelFormat(m_format),
                                       0);

                dst.Attach(m_pmap_img[idx].buf(),
                           m_pmap_img[idx].Width(),
                           m_pmap_img[idx].Height(),
                           m_app.FlipY() ?
                           m_pmap_img[idx].stride() :
                           -m_pmap_img[idx].stride(), m_pmap_img[idx].bpp());

                switch (m_format)
                {
                case PlatformSupportAbstract.PixelFormats.Bgr24:
                    switch (pmap_tmp.bpp())
                    {
                    case 24:
                        unsafe
                        {
                            for (uint y = 0; y < rbuf_tmp.Height(); y++)
                            {
                                byte *sourceBuffer = rbuf_tmp.GetPixelPointer((int)rbuf_tmp.Height() - (int)y - 1);
                                byte *destBuffer   = dst.GetPixelPointer((int)y);
                                for (uint x = 0; x < rbuf_tmp.Width(); x++)
                                {
                                    *destBuffer++ = sourceBuffer[0];
                                    *destBuffer++ = sourceBuffer[1];
                                    *destBuffer++ = sourceBuffer[2];
                                    sourceBuffer += 3;
                                }
                            }
                        }
                        break;

                    default:
                        throw new System.NotImplementedException();
                    }
                    break;

                case PlatformSupportAbstract.PixelFormats.Rgb24:
                    switch (pmap_tmp.bpp())
                    {
                    //                 case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgb24()); break;
                    case 24:
                        //color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgba32());
                        unsafe
                        {
                            for (uint y = 0; y < rbuf_tmp.Height(); y++)
                            {
                                byte *sourceBuffer = rbuf_tmp.GetPixelPointer((int)rbuf_tmp.Height() - (int)y - 1);
                                byte *destBuffer   = dst.GetPixelPointer((int)y);
                                for (uint x = 0; x < rbuf_tmp.Width(); x++)
                                {
                                    *destBuffer++ = sourceBuffer[2];
                                    *destBuffer++ = sourceBuffer[1];
                                    *destBuffer++ = sourceBuffer[0];
                                    sourceBuffer += 3;
                                }
                            }
                        }
                        break;

                    //                 case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb24()); break;
                    default:
                        throw new System.NotImplementedException();
                    }
                    break;


                case PlatformSupportAbstract.PixelFormats.Bgra32:
                    switch (pmap_tmp.bpp())
                    {
                    case 24:
                        unsafe
                        {
                            for (uint y = 0; y < rbuf_tmp.Height(); y++)
                            {
                                byte *sourceBuffer = rbuf_tmp.GetPixelPointer((int)rbuf_tmp.Height() - (int)y - 1);
                                byte *destBuffer   = dst.GetPixelPointer((int)y);
                                for (uint x = 0; x < rbuf_tmp.Width(); x++)
                                {
                                    *destBuffer++ = sourceBuffer[0];
                                    *destBuffer++ = sourceBuffer[1];
                                    *destBuffer++ = sourceBuffer[2];
                                    *destBuffer++ = 255;
                                    sourceBuffer += 3;
                                }
                            }
                        }
                        break;
                    }
                    break;

                case PlatformSupportAbstract.PixelFormats.Rgba32:
                    switch (pmap_tmp.bpp())
                    {
                    //                 case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgba32()); break;
                    case 24:
                        //color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgba32());
                        unsafe
                        {
                            for (uint y = 0; y < rbuf_tmp.Height(); y++)
                            {
                                byte *sourceBuffer = rbuf_tmp.GetPixelPointer((int)rbuf_tmp.Height() - (int)y - 1);
                                byte *destBuffer   = dst.GetPixelPointer((int)y);
                                for (uint x = 0; x < rbuf_tmp.Width(); x++)
                                {
                                    *destBuffer++ = sourceBuffer[2];
                                    *destBuffer++ = sourceBuffer[1];
                                    *destBuffer++ = sourceBuffer[0];
                                    *destBuffer++ = 255;
                                    sourceBuffer += 3;
                                }
                            }
                        }
                        break;


                    //                 case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgba32()); break;
                    default:
                        throw new System.NotImplementedException();
                    }
                    break;



                default:
                    throw new System.NotImplementedException();
                }
            }

            return(true);
        }