Mensaje    Asunto: Array de punteros, YUV->RGB Responder citando

Hola a todos!!


Os explico, tengo tres ficheros *.y, *.u, *.v(que corresponden a un formato de imagen en YUV o YCbCr), y quiero que a partir de estos
se cree un Bitmap (en formato RGB).

Cuando leo estos tres archivos los guardo en esta estructura:
unsigned char *structure[3];

que tiene 3 punteros a cadenas de char.

Y cada puntero debe apuntar a un array(cadena) que guardará los datos de cada fichero.
Así structure[0]= contenido dl fichero "*.y";
structure[1]= contenido dl fichero "*.u";
structure[2]= contenido dl fichero "*.v";


Con esta función guardo los ficheros para poder acceder después byte a byte a cada componente de la imagen.

Cómo accedo a los datos que guardo en structure[0]?, si es un puntero a un array de unsigned char?




file://pasamos el nombre del fichero "*.y","*.u","*.v", estructura donde guardaré estos tres ficheros y dimensión

void read_y_u_v(char *pathy,char *pathu,char *pathv, unsigned char * frame[],int iWidth, int iHeight)
{

int i;
int chrom_width, chrom_height;
int ancho,alto;
char name[128];
FILE *fd;

file://dimensiones luminancia
ancho=iWidth;
alto=iHeight;

file://#define FORMATO_420
chrom_width=iWidth>>1;
chrom_height=iHeight>>1;

frame[0]=new unsigned char[ancho*alto];
frame[1]=new unsigned char[chrom_width*chrom_height];
frame[2]=new unsigned char[chrom_width*chrom_height];


file://abro fichero .y
if (!(fd=fopen(pathy, "rb")))
ShowMessage("No se pudo abrir fichero .y");

for(int i=0;i<alto;i++)
fread(frame[0]+i*ancho,1,ancho,fd);
fclose(fd);

// Abrir fichero .u
if (!(fd=fopen(pathu, "rb")))
ShowMessage("No se pudo abrir fichero .u");

for(int i=0;i<chrom_height;i++)
fread(frame[1]+i*chrom_width,1,chrom_width,fd);
fclose(fd);

file://Abrir fichero .v
if (!(fd=fopen(pathv, "rb")))
ShowMessage("No se pudo abrir fichero .v");

for(int i=0;i<chrom_height;i++)
fread(frame[2]+i*chrom_width,1,chrom_width,fd);
fclose(fd);
}


Esta función lo que hará será acceder a esta estructura para coger byte a byte los elementos que guardé antes, aplicarles una fórmula y guardarlos en el objeto Imagen.

Quiero saber si el acceso a frame está bien hecho, porque cuando se ejecuta esta función
aparece un Bitmap en blanco, en vez de contener la imagen original.

void YCbCr2RGB(unsigned char * frame[],int iHeight, Graphics::TBitmap *imagen)
{
Byte *ptr1,*ptr2;
float R,G,B;
float Y,Cb,Cr;
int v=0,w=0;
int chr_w=(imagen->Width)>>1;


for(int y=0; y<iHeight; y++)
{
ptr2 = (unsigned char *)imagen->ScanLine[y];

for (int x = 0,par=0; x < (imagen->Width); x++)
{
float Cb_aux,Cr_aux;

Y = *frame[0]+v; file://Y
Y = ((Y-16)*(255.0/219.0)); file://Y'
v++;

Cb=0;
Cr=0;

// Escalado de las señales
Cb = ((Cb-128)*(255.0/224.0)); file://Cb'
Cr = ((Cr-128)*(255.0/224.0)); file://Cr'

// Conversión de YCbCr a RGB
R = (Cr/0.713)+Y;
B = (Cb/0.564)+Y;
G = (Y-0.299*R-0.114*B)/0.587;

// Guardamos los datos
ptr2[3*x] = no_neg(ROUND(B,0)); file://B
ptr2[3*x+1] = no_neg(ROUND(G,0)); file://G
ptr2[3*x+2] = no_neg(ROUND(R,0)); file://R


}
}


pictureRGB->Bitmap=imagen;

Form2->Image1->Picture=pictureRGB;
Form2->Image1->Stretch=true;
Form2->Image1->Canvas->Draw(0,0,imagen);
Form2->Caption="Original Image";
Form2->ClientWidth=Form2->Image1->Picture->Width;
Form2->ClientHeight=Form2->Image1->Picture->Height;
Form2->Image1->Canvas->Draw(0,0,Bitmap2);
Form2->Visible=true;
}