Results 1 to 2 of 2
Hi,
I am new in x11 programming. I want the solution for the problem of viewing multiple (4) images of movie in X11 window.
Presently I am working on a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 06-20-2006 #1Just Joined!
- Join Date
- Jun 2006
- Posts
- 1
image display on X11 window
Hi,
I am new in x11 programming. I want the solution for the problem of viewing multiple (4) images of movie in X11 window.
Presently I am working on a movie player that decodes the mpeg2 formatted file and display the movie on the screen using X11 window. But here I face following problem.
1) multiple (4) images viewing on X11 window
2) image quality is not so good
I am sure that if my first problem of viewing multiple images will solve then second problem of image quality will be solve.
So if any one will have idea about multiple images view, please help me or give some tips so I can able to solve this problem. For more detailed information about my code is given below
Over all general information is:
Screen depth is 24.
Display image format is yuv 4:2:0
Step 1: First of all I am creating the X child window one the default display screen is as follow
p_dec_DisplayPtr = XOpenDisplay(pp_Name);
if (p_dec_DisplayPtr == NULL)
dec_Error("Can not open display\n");
screen = DefaultScreen(p_dec_DisplayPtr);
visual = DefaultVisual (p_dec_DisplayPtr, screen);
v_dec_WindowInstance = XCreateWindow (p_dec_DisplayPtr, DefaultRootWindow (p_dec_DisplayPtr),
hint.x, hint.y, hint.width, hint.height, 4, DefaultDepth (p_dec_DisplayPtr, screen),
InputOutput, CopyFromParent, windowMask, &winAttrib);
Step 2: And here is the color space conversion code
Here I observed that else body is never executed so that XCreateColormap() and XSetWindowColormap() functions never call here
/* matrix coefficients */
crv = a_dec_Inverse_Table_6_9[v_dec_MatrixCoefficients][0];
cbu = a_dec_Inverse_Table_6_9[v_dec_MatrixCoefficients][1];
cgu = a_dec_Inverse_Table_6_9[v_dec_MatrixCoefficients][2];
cgv = a_dec_Inverse_Table_6_9[v_dec_MatrixCoefficients][3];
/* allocate colors */
v_dec_GCInstance = DefaultGC(p_dec_DisplayPtr, screen);
cmap = DefaultColormap(p_dec_DisplayPtr, screen);
for (i=16; i<240; i++)
{
/* color space conversion */
Y = 16*((i>>4)&15) + 8;
Cb = 32*((i>>2)&3) - 48;
Cr = 32*(i&3) - 48;
Y = 76309 * (Y - 16); /* (255/219)*65536 */
R = p_dec_Clip[(Y + crv*Cr + 3276
>>16];
G = p_dec_Clip[(Y - cgu*Cb - cgv*Cr + 3276
>>16];
B = p_dec_Clip[(Y + cbu*Cb + 32786)>>16];
/* X11 colors are 16 bit */
xcolor.red = R << 8;
xcolor.green = G << 8;
xcolor.blue = B << 8;
if (XAllocColor(p_dec_DisplayPtr, cmap, &xcolor) != 0)
a_dec_Pixel[i] = xcolor.pixel;
else
{
//printf("\nin else body");
/* allocation failed, have to use a private colormap */
if (private)
dec_Error("Couldn't allocate private colormap");
private = 1;
if (!v_dec_QuietFlag)
fprintf(stderr, "Using private colormap (%d colors were available).\n",
i-16);
/* Free colors. */
while (--i >= 16)
{
tmp_pixel = a_dec_Pixel[i]; /* because XFreeColors expects unsigned long */
XFreeColors(p_dec_DisplayPtr, cmap, &tmp_pixel, 1, 0);
}
/* i is now 15, this restarts the outer loop */
/* create private colormap */
XGetWindowAttributes(p_dec_DisplayPtr, v_dec_WindowInstance, &xwa);
cmap = XCreateColormap(p_dec_DisplayPtr, v_dec_WindowInstance, xwa.visual, AllocNone);
XSetWindowColormap(p_dec_DisplayPtr, v_dec_WindowInstance, cmap);
}
}
Step 3: After color space conversion immediately I am preparing to create the image, code is as follow
DEPTH = DefaultDepth (p_dec_DisplayPtr, screen);
OFFSET =0;
Dummy = NULL;
BITMAP_PAD =16;
BYTES_PER_LINE= 0;
p_dec_XimagePtr = XCreateImage(p_dec_DisplayPtr,visual/*None*/,DEPTH,ZPixmap,OFFSET,&dummy,
v_dec_CodedPictureWidth,v_dec_CodedPictureHeight,B ITMAP_PAD,BYTES_PER_LINE);
XInitImage(p_dec_XimagePtr);
if (!(p_dec_DitheredImage = (unsigned char *)malloc(4*v_dec_CodedPictureWidth*
v_dec_CodedPictureHeight)))
dec_Error("malloc failed");
Step 4: and following is the function that is used for displaying the image on my X window
static void dec_DisplayImage(XImage *pp_XimagePtr,unsigned char *pp_DitheredImage)
{
/* display dithered image */
static int i=0;
pp_XimagePtr->data = (char *) pp_DitheredImage;
XPutImage(p_dec_DisplayPtr, v_dec_WindowInstance, v_dec_GCInstance, pp_XimagePtr, 0,
0, 0, 0, pp_XimagePtr->width, pp_XimagePtr->height);
//printf("\nNo of frame read: %d", i++);
//usleep(75000);
}
step 5 : actual image data is parse for display using the following function. Here arg pp_Src[] contain the actual decoded image data.
static void dec_DitherFrame(unsigned char *pp_Src[])
{
int i,j;
int y,u,v;
unsigned char *py,*pu,*pv,*dst;
py = pp_Src[0];
pu = pp_Src[1];
pv = pp_Src[2];
dst = p_dec_DitheredImage;
for (j=0; j<v_dec_CodedPictureHeight; j+=4)
{
/* line j + 0 */
for (i=0; i<v_dec_CodedPictureWidth; i+=4)
{
y = *py++;
u = *pu++ >> 1;
v = *pv++ >> 1;
*dst++ = a_dec_Pixel[a_dec_YTable[y]|a_dec_CbTable[u]|a_dec_CrTable[v]];
y = *py++;
if (v_dec_ChromaFormat==CHROMA444)
{
u = *pu++ >> 1;
v = *pv++ >> 1;
}
*dst++ = a_dec_Pixel[a_dec_YTable[y+8]|a_dec_CbTable[u+8]|a_dec_CrTable[v+8]];
y = *py++;
u = *pu++ >> 1;
v = *pv++ >> 1;
*dst++ = a_dec_Pixel[a_dec_YTable[y+2]|a_dec_CbTable[u+2]|a_dec_CrTable[v+2]];
y = *py++;
if (v_dec_ChromaFormat==CHROMA444)
{
u = *pu++ >> 1;
v = *pv++ >> 1;
}
*dst++ = a_dec_Pixel[a_dec_YTable[y+10]|a_dec_CbTable[u+10]|a_dec_CrTable[v+10]];
}
if (v_dec_ChromaFormat==CHROMA420)
{
pu -= v_dec_ChromaWidth;
pv -= v_dec_ChromaWidth;
}
#if 1
/* line j + 1 */
for (i=0; i<v_dec_CodedPictureWidth; i+=4)
{
y = *py++;
u = *pu++ >> 1;
v = *pv++ >> 1;
*dst++ = a_dec_Pixel[a_dec_YTable[y+12]|a_dec_CbTable[u+12]|a_dec_CrTable[v+12]];
y = *py++;
if (v_dec_ChromaFormat==CHROMA444)
{
u = *pu++ >> 1;
v = *pv++ >> 1;
}
*dst++ = a_dec_Pixel[a_dec_YTable[y+4]|a_dec_CbTable[u+4]|a_dec_CrTable[v+4]];
y = *py++;
u = *pu++ >> 1;
v = *pv++ >> 1;
*dst++ = a_dec_Pixel[a_dec_YTable[y+14]|a_dec_CbTable[u+14]|a_dec_CrTable[v+14]];
y = *py++;
if (v_dec_ChromaFormat==CHROMA444)
{
u = *pu++ >> 1;
v = *pv++ >> 1;
}
*dst++ = a_dec_Pixel[a_dec_YTable[y+6]|a_dec_CbTable[u+6]|a_dec_CrTable[v+6]];
}
/* line j + 2 */
for (i=0; i<v_dec_CodedPictureWidth; i+=4)
{
y = *py++;
u = *pu++ >> 1;
v = *pv++ >> 1;
*dst++ = a_dec_Pixel[a_dec_YTable[y+3]|a_dec_CbTable[u+3]|a_dec_CrTable[v+3]];
y = *py++;
if (v_dec_ChromaFormat==CHROMA444)
{
u = *pu++ >> 1;
v = *pv++ >> 1;
}
*dst++ = a_dec_Pixel[a_dec_YTable[y+11]|a_dec_CbTable[u+11]|a_dec_CrTable[v+11]];
y = *py++;
u = *pu++ >> 1;
v = *pv++ >> 1;
*dst++ = a_dec_Pixel[a_dec_YTable[y+1]|a_dec_CbTable[u+1]|a_dec_CrTable[v+1]];
y = *py++;
if (v_dec_ChromaFormat==CHROMA444)
{
u = *pu++ >> 1;
v = *pv++ >> 1;
}
*dst++ = a_dec_Pixel[a_dec_YTable[y+9]|a_dec_CbTable[u+9]|a_dec_CrTable[v+9]];
}
if (v_dec_ChromaFormat==CHROMA420)
{
pu -= v_dec_ChromaWidth;
pv -= v_dec_ChromaWidth;
}
/* line j + 3 */
for (i=0; i<v_dec_CodedPictureWidth; i+=4)
{
y = *py++;
u = *pu++ >> 1;
v = *pv++ >> 1;
*dst++ = a_dec_Pixel[a_dec_YTable[y+15]|a_dec_CbTable[u+15]|a_dec_CrTable[v+15]];
y = *py++;
if (v_dec_ChromaFormat==CHROMA444)
{
u = *pu++ >> 1;
v = *pv++ >> 1;
}
*dst++ = a_dec_Pixel[a_dec_YTable[y+7]|a_dec_CbTable[u+7]|a_dec_CrTable[v+7]];
y = *py++;
u = *pu++ >> 1;
v = *pv++ >> 1;
*dst++ = a_dec_Pixel[a_dec_YTable[y+13]|a_dec_CbTable[u+13]|a_dec_CrTable[v+13]];
y = *py++;
if (v_dec_ChromaFormat==CHROMA444)
{
u = *pu++ >> 1;
v = *pv++ >> 1;
}
*dst++ = a_dec_Pixel[a_dec_YTable[y+5]|a_dec_CbTable[u+5]|a_dec_CrTable[v+5]];
}
#endif
}
}
well this all my code information and hope some will give me at least hint.
Thanks in advance
- 06-23-2006 #2
Hi, I don't have the answer you're looking for, but just to inform you that for long amounts of code like you have there, please use code blocks, as follows;
When writing a post you will find the code blocks as the hash symbol, 3rd from the end, from the available options above the input box, this helps to keep things readable.Code:step 5 : actual image data is parse for display using the following function. Here arg pp_Src[] contain the actual decoded image data. static void dec_DitherFrame(unsigned char *pp_Src[]) { int i,j; int y,u,v; unsigned char *py,*pu,*pv,*dst; py = pp_Src[0]; pu = pp_Src[1]; pv = pp_Src[2]; dst = p_dec_DitheredImage; for (j=0; j<v_dec_CodedPictureHeight; j+=4) { /* line j + 0 */ for (i=0; i<v_dec_CodedPictureWidth; i+=4) { y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = a_dec_Pixel[a_dec_YTable[y]|a_dec_CbTable[u]|a_dec_CrTable[v]]; y = *py++; if (v_dec_ChromaFormat==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = a_dec_Pixel[a_dec_YTable[y+8]|a_dec_CbTable[u+8]|a_dec_CrTable[v+8]]; y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = a_dec_Pixel[a_dec_YTable[y+2]|a_dec_CbTable[u+2]|a_dec_CrTable[v+2]]; y = *py++; if (v_dec_ChromaFormat==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = a_dec_Pixel[a_dec_YTable[y+10]|a_dec_CbTable[u+10]|a_dec_CrTable[v+10]]; } if (v_dec_ChromaFormat==CHROMA420) { pu -= v_dec_ChromaWidth; pv -= v_dec_ChromaWidth; } #if 1 /* line j + 1 */ for (i=0; i<v_dec_CodedPictureWidth; i+=4) { y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = a_dec_Pixel[a_dec_YTable[y+12]|a_dec_CbTable[u+12]|a_dec_CrTable[v+12]]; y = *py++; if (v_dec_ChromaFormat==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = a_dec_Pixel[a_dec_YTable[y+4]|a_dec_CbTable[u+4]|a_dec_CrTable[v+4]]; y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = a_dec_Pixel[a_dec_YTable[y+14]|a_dec_CbTable[u+14]|a_dec_CrTable[v+14]]; y = *py++; if (v_dec_ChromaFormat==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = a_dec_Pixel[a_dec_YTable[y+6]|a_dec_CbTable[u+6]|a_dec_CrTable[v+6]]; }Great GNU/Linux references and resources:
The Linux Documentation Project
Rute User's Tutorial and Exposition
GNU/Linux Man Pages


Reply With Quote
