public int sceZlibDecompress(byte *OutBuffer, int OutBufferLength, byte *InBuffer, uint *Crc32Addr) { var InStream = new PointerStream(InBuffer); var OutStream = new PointerStream(OutBuffer, OutBufferLength); _Decompress(InStream, OutStream); var OutLength = (int)OutStream.Position; if (Crc32Addr != null) { *Crc32Addr = Crc32.Compute(PointerUtils.PointerToByteArray(OutBuffer, OutLength)); } return(OutLength); }
public unsafe static BitmapSource Read(ref BITMAP_READ_DETAILS info, byte *pixels, uint bcrFlags) { // we do this parsing here since BitmapCore has no references to PresentationCore if (info.compression == BitmapCompressionMode.BI_PNG) { var stream = new PointerStream(pixels, info.imgDataSize); var png = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); return(png.Frames[0]); } else if (info.compression == BitmapCompressionMode.BI_JPEG) { var stream = new PointerStream(pixels, info.imgDataSize); var jpg = new JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); return(jpg.Frames[0]); } PixelFormat wpfFmt = PixelFormats.Bgra32; BitmapCorePixelFormat coreFmt = BitmapCorePixelFormat.Bgra32; bool forceBgra32 = (bcrFlags & BitmapCore.BC_READ_FORCE_BGRA32) > 0; if (!forceBgra32 && info.imgSourceFmt != null) { var origFmt = info.imgSourceFmt; var pxarr = Formats.Where(m => m.coreFmt == origFmt).ToArray(); if (pxarr.Length > 0) { var px = pxarr.First(); wpfFmt = px.wpfFmt; coreFmt = px.coreFmt; } } BitmapPalette palette = null; if (info.imgColorTable.Length > 0) { var clrs = info.imgColorTable.Select(c => Color.FromRgb(c.rgbRed, c.rgbGreen, c.rgbBlue)); if (info.imgColorTable.Length > 256) // wpf throws on oversized palettes { clrs = clrs.Take(256); } palette = new BitmapPalette(clrs.ToList()); } var bitmap = new WriteableBitmap( info.imgWidth, info.imgHeight, info.dpiX, info.dpiY, wpfFmt, palette); var buf = (byte *)bitmap.BackBuffer; bitmap.Lock(); BitmapCore.ReadPixels(ref info, coreFmt, pixels, buf, bcrFlags); bitmap.AddDirtyRect(new System.Windows.Int32Rect(0, 0, info.imgWidth, info.imgHeight)); bitmap.Unlock(); bitmap.Freeze(); // dispose back buffer return(bitmap); }