fork download
  1. public void Test()
  2. {
  3. var nv12Binary = File.ReadAllBytes(@"C:\NV12.dat");
  4. var height = 256; //BitmapInfoHeaderより
  5. var width = 320; //BitmapInfoHeaderより
  6. var uvStartIndex = height * width; //UVの開始位置を取得
  7. var rgbBuffer = new byte[height * width * 3];
  8.  
  9. for (var h = 0; h < height; h++)
  10. {
  11. for (var w = 0; w < width; w += 2)
  12. {
  13. var u = nv12Binary[uvStartIndex + w + 0];
  14. var v = nv12Binary[uvStartIndex + w + 1];
  15.  
  16. for (int cnt = 0; cnt < 2; cnt++)
  17. {
  18. var y = nv12Binary[h * width + h + cnt];
  19.  
  20.  
  21. //var r = ((298 * (y - 16) + 409 * (v - 128) + 128) >> 8);
  22. //var g = ((298 * (y - 16) - 100 * (u - 128) - 208 * (v - 128) + 128) >> 8);
  23. //var b = ((298 * (y - 16) + 516 * (u - 128) + 128) >> 8);
  24. var r = y + (1.370705 * (v - 128));
  25. var g = y - (0.698001 * (v - 128)) - (0.337633 * (u - 128));
  26. var b = y + (1.732446 * (u - 128));
  27.  
  28. rgbBuffer[(h * width + w + cnt) * 3 + 0] = ConvertByte(b);
  29. rgbBuffer[(h * width + w + cnt) * 3 + 1] = ConvertByte(g);
  30. rgbBuffer[(h * width + w + cnt) * 3 + 2] = ConvertByte(r);
  31. }
  32. }
  33. uvStartIndex += width * (h % 2);//UV位置を移動
  34. }
  35.  
  36. using (var img = new Bitmap(width, height, PixelFormat.Format24bppRgb))
  37. {
  38. var bitmapData = img.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
  39. Marshal.Copy(rgbBuffer, 0, bitmapData.Scan0, rgbBuffer.Length);
  40. img.UnlockBits(bitmapData);
  41. img.Save(@"C:\Image.bmp",ImageFormat.Bmp);
  42. }
  43. }
  44.  
  45. private static byte ConvertByte(double value)
  46. => value > byte.MaxValue ? byte.MaxValue : (value < byte.MinValue ? byte.MinValue : (byte)value);
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,15): error CS1525: Unexpected symbol `void', expecting `class', `delegate', `enum', `interface', `partial', or `struct'
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty