procedure GuardarImagen;
var
vBuf: v4l2_buffer;
VideoBufferIndex: __u32;
FramePtr: PByte;
x, y, i, size, f: integer;
Datos: TMemoryStream;
Imagen: TFPMemoryImage;
MiPaleta: TFPColor;
j: TFPWriterJPEG;
Convertido, src: PRGB24Pixel;
Blue, Green, Red, g, r, b: byte;
h, by, pixel: longint;
d, RgbColor: longword;
buffer: TRGB24Pixel;
color: TColor;
dest: Pointer;
begin
repeat
begin
FillChar(vBuf, sizeof(v4l2_buffer), 0);
vbuf._type := V4L2_BUF_TYPE_VIDEO_CAPTURE;
vbuf.memory := V4L2_MEMORY_MMAP;
//Capturar imagen
if DynIoctl(videohandle, VIDIOC_DQBUF, @vbuf) < 0 then
begin
raise Exception.Create('Fallo durante la captura');
end;
end;
until vBuf.bytesused > 0;
Sleep(2000);
VideoBufferIndex := vbuf.index;
FramePtr := VideoBuffer[VideoBufferIndex];
Datos := TMemoryStream.Create;
//Datos.SetSize(vHeight * vWidth);
Datos.Position := 0;
size := vHeight * vWidth * 3;
case PixelFormat of
uvcpf_YUYV:
writeln('uvcpf_YUYV');
uvcpf_YUV420:
writeln('uvcpf_YUV420');
uvcpf_RGB24:
writeln('uvcpf_RGB24');
uvcpf_BGR24:
WriteLn('uvcpf_BGR24');
end;
//convers format uvcpf_BGR24
src := PRGB24Pixel(FramePtr);
for I := 0 to size - 1 do
begin
RgbColor := PLongWord(@src[I])^;
datos.Write(RgbColor,1);
end;
Imagen := TFPMemoryImage.Create(vWidth, vHeight);
Imagen.UsePalette := True;
for I := 0 to 255 do
begin
MiPaleta.Alpha := $FFFF;
MiPaleta.Blue := I * $0101;
MiPaleta.Green := I * $0101;
MiPaleta.Red := I * $0101;
f := Imagen.Palette.Add(MiPaleta);
end;
Datos.Position := 0;
for X := 0 to Imagen.Width - 1 do
begin
for Y := 0 to Imagen.Height - 1 do
begin
Datos.Read(RgbColor,1);
Imagen.Pixels[x, y] := RgbColor;
end;
end;
j := TFPWriterJPEG.Create;
j.CompressionQuality := 100;
Imagen.SaveToFile('pepe.jpg', j);
end;
I attach the program complete. And two image. The "original" and the image that saves my program
Any Idea
Thanks
/BlueIcaro