public unsafe void Hq2x() { CImage in24 = new CImage(); in24.Init(image.Width, image.Height, 24); for (int row = 0; row < image.Height; row++) { for (int col = 0; col < image.Width; col++) { Color c = image.GetPixel(col, row); *(in24.m_pBitmap + ((row) * in24.m_Xres * 3) + ((col) * 3)) = c.B; *(in24.m_pBitmap + ((row) * in24.m_Xres * 3) + ((col) * 3 + 1)) = c.G; *(in24.m_pBitmap + ((row) * in24.m_Xres * 3) + ((col) * 3 + 2)) = c.R; } } in24.ConvertTo16(); CImage out32 = new CImage(); out32.Init(in24.m_Xres * 2, in24.m_Yres * 2, 32); CImage.InitLUTs(); CImage.hq2x_32(in24.m_pBitmap, out32.m_pBitmap, in24.m_Xres, in24.m_Yres, out32.m_Xres * 4); out32.ConvertTo24(); PckImage.scale = 2; Bitmap b = new Bitmap(out32.m_Xres, out32.m_Yres, PixelFormat.Format24bppRgb); Rectangle rect = new Rectangle(0, 0, b.Width, b.Height); BitmapData bitmapData = b.LockBits(rect, ImageLockMode.WriteOnly, b.PixelFormat); IntPtr pixels = bitmapData.Scan0; byte *pBits; if (bitmapData.Stride > 0) { pBits = (byte *)pixels.ToPointer(); } else { pBits = (byte *)pixels.ToPointer() + bitmapData.Stride * (b.Height - 1); } byte *srcBits = out32.m_pBitmap; for (int i = 0; i < b.Width * b.Height; i++) { *(pBits++) = *(srcBits++); *(pBits++) = *(srcBits++); *(pBits++) = *(srcBits++); } b.UnlockBits(bitmapData); image.Dispose(); in24.__dtor(); out32.__dtor(); b.MakeTransparent(b.GetPixel(0, 0)); image = b; }
public static unsafe Bitmap Hq2x(Bitmap image) { #if hq2xWorks CImage in24 = new CImage(); in24.Init(image.Width, image.Height, 24); for (int row = 0; row < image.Height; row++) { for (int col = 0; col < image.Width; col++) { Color c = image.GetPixel(col, row); *(in24.m_pBitmap + (row * in24.m_Xres * 3) + (col * 3 + 0)) = c.B; *(in24.m_pBitmap + (row * in24.m_Xres * 3) + (col * 3 + 1)) = c.G; *(in24.m_pBitmap + (row * in24.m_Xres * 3) + (col * 3 + 2)) = c.R; } } in24.ConvertTo16(); CImage out32 = new CImage(); out32.Init(in24.m_Xres * 2, in24.m_Yres * 2, 32); CImage.InitLUTs(); CImage.hq2x_32( in24.m_pBitmap, out32.m_pBitmap, in24.m_Xres, in24.m_Yres, out32.m_Xres * 4); out32.ConvertTo24(); Bitmap b = new Bitmap( out32.m_Xres, out32.m_Yres, PixelFormat.Format24bppRgb); // Rectangle rect = new Rectangle(0, 0, b.Width, b.Height); BitmapData bitmapData = b.LockBits( new Rectangle( 0, 0, b.Width, b.Height), ImageLockMode.WriteOnly, b.PixelFormat); IntPtr pixels = bitmapData.Scan0; byte *pBits; if (bitmapData.Stride > 0) { pBits = (byte *)pixels.ToPointer(); } else { pBits = (byte *)pixels.ToPointer() + bitmapData.Stride * (b.Height - 1); } byte *srcBits = out32.m_pBitmap; for (int i = 0; i < b.Width * b.Height; i++) { *(pBits++) = *(srcBits++); *(pBits++) = *(srcBits++); *(pBits++) = *(srcBits++); } b.UnlockBits(bitmapData); image.Dispose(); in24.__dtor(); out32.__dtor(); return(b); #else return(null); #endif }