yv12格式?我只会YUY2格式的.....而且要预先知道宽跟高
function BMPFromYUV2(aWidth, aheight: Integer;
MemBuf: TMemoryStream): TBitmap;
type
TYUY2Word = record
Y: BYTE;
UV: Byte;
end;
TRGBTripleArray = array[0..32767] of TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray;
var
BufferYUV: array[0..32767] of TYUY2Word;
I, J: Integer;
Row: pRGBTripleArray;
Y, U, V: Byte;
function FixValue(const x: DOUBLE): BYTE;
var
i: INTEGER;
begin
i := ROUND(x);
if i > 255 then
RESULT := 255
else if i < 0 then
RESULT := 0
else
RESULT := BYTE(i)
end;
begin
Result := TBitmap.Create;
Result.PixelFormat := pf24Bit;
Result.Width := aWidth;
Result.Height := aHeight;
MemBuf.Position := 0;
for j := 0 to Result.Height - 1 do
begin
MemBuf.Read(BufferYUV, Round((SizeOf(BufferYUV) / 32768) * Result.Width));
Row := Result.Scanline[j];
for i := 0 to Result.Width - 1 do
begin
if i mod 2 = 0 then
begin
Y := BufferYUV.Y;
U := BufferYUV.UV;
V := BufferYUV[i + 1].UV;
end
else
begin
Y := BufferYUV.Y;
U := BufferYUV[i - 1].UV;
V := BufferYUV.UV
end;
with Row do
begin
rgbtRed := FixValue(1.164383 * (Y - 16) + 1.596027 * (V - 128));
rgbtGreen := FixValue(1.164383 * (Y - 16) - (0.391762 * (U - 128)) -
(0.812968 * (v - 128)));
rgbtBlue := FixValue(1.164383 * (Y - 16) + 2.017232 * (U - 128));
end;
end;
end;
end;