private static void PutPixel(FastBitmap bmp, int index, int color, BluRaySupPalette palette) { int x = index % bmp.Width; int y = index / bmp.Width; if (x < bmp.Width && y < bmp.Height) { bmp.SetPixel(x, y, Color.FromArgb(palette.GetArgb(color))); } }
private static void PutPixel(FastBitmap bmp, int index, int color, BluRaySupPalette palette) { int x = index % bmp.Width; int y = index / bmp.Width; if (x < bmp.Width && y < bmp.Height) bmp.SetPixel(x, y, Color.FromArgb(palette.GetArgb(color))); }
/// <summary> /// Decode caption from the input stream /// </summary> /// <returns>bitmap of the decoded caption</returns> public static Bitmap DecodeImage(PcsObject pcs, IList <OdsData> data, List <PaletteInfo> palettes) { long ticks = DateTime.Now.Ticks; if (pcs == null || data == null || data.Count == 0) { return(new Bitmap(1, 1)); } int w = data[0].Size.Width; int h = data[0].Size.Height; var bm = new FastBitmap(new Bitmap(w, h)); bm.LockImage(); BluRaySupPalette pal = DecodePalette(palettes); int index = 0; int ofs = 0; int xpos = 0; byte[] buf = data[0].Fragment.ImageBuffer; index = 0; do { int b = buf[index++] & 0xff; if (b == 0 && index < buf.Length) { b = buf[index++] & 0xff; if (b == 0) { // next line ofs = (ofs / w) * w; if (xpos < w) { ofs += w; } xpos = 0; } else { int size; if ((b & 0xC0) == 0x40) { if (index < buf.Length) { // 00 4x xx -> xxx zeroes size = ((b - 0x40) << 8) + (buf[index++] & 0xff); Color c = Color.FromArgb(pal.GetArgb(0)); for (int i = 0; i < size; i++) { PutPixel(bm, ofs++, c); } xpos += size; } } else if ((b & 0xC0) == 0x80) { if (index < buf.Length) { // 00 8x yy -> x times value y size = (b - 0x80); b = buf[index++] & 0xff; Color c = Color.FromArgb(pal.GetArgb(b)); for (int i = 0; i < size; i++) { PutPixel(bm, ofs++, c); } xpos += size; } } else if ((b & 0xC0) != 0) { if (index < buf.Length) { // 00 cx yy zz -> xyy times value z size = ((b - 0xC0) << 8) + (buf[index++] & 0xff); b = buf[index++] & 0xff; Color c = Color.FromArgb(pal.GetArgb(b)); for (int i = 0; i < size; i++) { PutPixel(bm, ofs++, c); } xpos += size; } } else { // 00 xx -> xx times 0 Color c = Color.FromArgb(pal.GetArgb(0)); for (int i = 0; i < b; i++) { PutPixel(bm, ofs++, c); } xpos += b; } } } else { PutPixel(bm, ofs++, b, pal); xpos++; } } while (index < buf.Length); bm.UnlockImage(); return(bm.GetBitmap()); }