From: Brian P. <br...@va...> - 2000-10-05 16:51:07
|
Christian Fremgen wrote: > > Hi there! > > I have written a little application under Windows 2000 which draws > a color-indexed pixmap with predefined color-maps to the rendering > context (provided by Qt), which is defined to use RGB. > With the mentioned OS and its OpenGL-support it works > really nice, so I tried to port it to Linux with Mesa-3.3. > > The same code produces a SIGSEGV under Linux, when glDrawPixels > is called. > > A short code-description: > initialization: > ... > float r[256], g[256], b[256]; > > // definition of the r, g and b colortable omitted > > glPixelTransferi (GL_MAP_COLOR, TRUE); > glPixelMapfv (GL_PIXEL_MAP_I_TO_R, 256, r); > glPixelMapfv (GL_PIXEL_MAP_I_TO_G, 256, g); > glPixelMapfv (GL_PIXEL_MAP_I_TO_B, 256, b); > ... > > painting: > .... > // pixelData is defined as: unsigned char* or Glubyte* > glDrawPixels (512, 512, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, pixelData); > // never comes to this line.... but gets a SIGSEGV > > After several hours of trying I tried the following in "painting": > glPixelTransferi (GL_MAP_COLOR, FALSE); > glDrawPixels (512, 512, GL_RED, GL_UNSIGNED_BYTE, pixelData); > > and see.. it works this way... my whole information.. in red.. :) > > The problem is that I need color-maps to do efficient manipulation of the > colors > in my pixelData. And it would be really nice to develop with Linux and > Mesa-3.3 > and not with Windows....... Well, I didn't get a segfault in my test, but I got a black image instead of the expected result. The problem was that Index->Index mapping was happening by mistake, effectively converting all color indexes to zero. Here's a patch to fix the problem: --- image.c.orig Thu Oct 5 10:25:13 2000 +++ image.c Thu Oct 5 10:14:12 2000 @@ -2281,7 +2281,7 @@ unpacking); if (applyTransferOps) { - if (ctx->Pixel.MapColorFlag) { + if (dstFormat == GL_COLOR_INDEX && ctx->Pixel.MapColorFlag) { _mesa_map_ci(ctx, n, indexes); } if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset) { @@ -2550,7 +2550,7 @@ unpacking); if (applyTransferOps) { - if (ctx->Pixel.MapColorFlag) { + if (dstFormat == GL_COLOR_INDEX && ctx->Pixel.MapColorFlag) { _mesa_map_ci(ctx, n, indexes); } if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset) { This next patch fixes a problem which prevented the fast-path glDrawPixels operation from being used in this case: --- drawpix.c.orig Thu Oct 5 10:37:49 2000 +++ drawpix.c Thu Oct 5 10:43:11 2000 @@ -122,11 +122,10 @@ && ctx->ColorMatrix.type == MATRIX_IDENTITY && !ctx->Pixel.ColorTableEnabled && !ctx->Pixel.PostColorMatrixColorTableEnabled - && ctx->Pixel.PostConvolutionColorTableEnabled + && !ctx->Pixel.PostConvolutionColorTableEnabled && !ctx->Pixel.MinMaxEnabled && !ctx->Pixel.HistogramEnabled && ctx->Pixel.IndexShift==0 && ctx->Pixel.IndexOffset==0 - && ctx->Pixel.MapColorFlag==0 && ctx->Texture.ReallyEnabled == 0 && unpack->Alignment==1 && !unpack->SwapBytes @@ -197,7 +196,8 @@ * skip "skipRows" rows and skip "skipPixels" pixels/row. */ - if (format==GL_RGBA && type==GL_UNSIGNED_BYTE) { + if (format==GL_RGBA && type==GL_UNSIGNED_BYTE + && ctx->Pixel.MapColorFlag==0) { if (ctx->Visual->RGBAflag) { GLubyte *src = (GLubyte *) pixels + (skipRows * rowLength + skipPixels) * 4; @@ -224,7 +224,8 @@ } return GL_TRUE; } - else if (format==GL_RGB && type==GL_UNSIGNED_BYTE) { + else if (format==GL_RGB && type==GL_UNSIGNED_BYTE + && ctx->Pixel.MapColorFlag==0) { if (ctx->Visual->RGBAflag) { GLubyte *src = (GLubyte *) pixels + (skipRows * rowLength + skipPixels) * 3; @@ -250,7 +251,8 @@ } return GL_TRUE; } - else if (format==GL_LUMINANCE && type==GL_UNSIGNED_BYTE) { + else if (format==GL_LUMINANCE && type==GL_UNSIGNED_BYTE + && ctx->Pixel.MapColorFlag==0) { if (ctx->Visual->RGBAflag) { GLubyte *src = (GLubyte *) pixels + (skipRows * rowLength + skipPixels); @@ -291,7 +293,8 @@ } return GL_TRUE; } - else if (format==GL_LUMINANCE_ALPHA && type==GL_UNSIGNED_BYTE) { + else if (format==GL_LUMINANCE_ALPHA && type==GL_UNSIGNED_BYTE + && ctx->Pixel.MapColorFlag==0) { if (ctx->Visual->RGBAflag) { GLubyte *src = (GLubyte *) pixels + (skipRows * rowLength + skipPixels)*2; This will also be fixed in Mesa 3.4 (which I hope to release in a few weeks). -Brian |