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;
        }
 public unsafe void create_pmap(uint width, uint height, RasterBuffer wnd)
 {
     m_pmap_window = new PixelMap();
     m_pmap_window.Create(width, height, PlatformSupportAbstract.GetBitDepthForPixelFormat(m_format));
     wnd.Attach(m_pmap_window.buf(),
         m_pmap_window.Width(),
         m_pmap_window.Height(),
         m_RenderOrigin == PlatformSupportAbstract.ERenderOrigin.OriginBottomLeft ? -m_pmap_window.stride() : m_pmap_window.stride(),
         m_pmap_window.bpp());
 }
        public void display_pmap(Graphics displayGraphics, RasterBuffer src)
        {
            if (m_sys_format == m_format)
            {
                m_pmap_window.Draw(displayGraphics);
            }
            else
            {
                PixelMap pmap_tmp = new PixelMap();
                pmap_tmp.Create(m_pmap_window.Width(),
                    m_pmap_window.Height(), PlatformSupportAbstract.GetBitDepthForPixelFormat(m_sys_format));

                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());
                }

                convert_pmap(rbuf_tmp, src, m_format);
                pmap_tmp.Draw(displayGraphics);

                throw new System.NotImplementedException();
            }
        }
Exemple #4
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);
        }