1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 04:20:27 +01:00

- fixed code in wrlib dependant on the order of evaluation.

code like
    *ptr++ = *ptr++ = *ptr++ = color;
  is wrong, because there is no guarantee that ptr will be incremented
  _between_ the assignment operations. it can be incremented after all
  assignment operations as well. Because of this both of these are valid
  implementations for a compiler:
    a. assign, increment, assign, increment, assign, increment
    b. assign, assign, assign, increment by 3
  In case b. only the first memory location of the 3 will be modified, being
  assigned 3 times the same value, while the other 2 remain unchanged.
  For example egcs-2.91.66 (and possibly gcc-2.95.x too) implement this in
  the second way (like in case b.)
  Also the order in which the assignement is made is undefined (left to right
  or right to left).

this fixed the problem we had with greyscale jpegs showing up in red,
and possibly other problems related to pseudocolor and greyscale displays.
This commit is contained in:
dan
2000-11-06 04:21:25 +00:00
parent f7b4e85525
commit e7ce6468fc
6 changed files with 38 additions and 17 deletions

View File

@@ -25,6 +25,9 @@ Changes since version 0.62.1:
startup.
- replaced free() with wfree() wherever appropriate
- fixed some memory leaks generated by wstrappend()
- fixed code that was dependant on the order of evaluation in wrlib. This
fixed a number of problems, like greyscale jpegs that showed up in red
and possibly the problems with pseudocolor displays.
Changes since version 0.62.0:

View File

@@ -1,3 +1,18 @@
- fixed code dependant on the order of evaluation. code like
*ptr++ = *ptr++ = *ptr++ = color;
is wrong, because there is no guarantee that ptr will be incremented
_between_ the assignment operations. it can be incremented after all
assignment operations as well. Because of this both of these are valid
implementations for a compiler:
a. assign, increment, assign, increment, assign, increment
b. assign, assign, assign, increment by 3
In case b. only the first memory location of the 3 will be modified, being
assigned 3 times the same value, while the other 2 remain unchanged.
For example egcs-2.91.66 (and possibly gcc-2.95.x too) implement this in
the second way (like in case b.)
Also the order in which the assignement is made is undefined (left to right
or right to left).
- added RMakeCenteredImage()
- Added code to draw pixels and lines. Both writing absolute values, or

View File

@@ -593,10 +593,10 @@ image2StandardPseudoColor(RContext *ctx, RImage *image)
if (ctx->attribs->render_mode == RBestMatchRendering) {
for (y=0; y<image->height; y++) {
for (x=0; x<image->width; x++, ptr+=channels-3) {
for (x=0; x<image->width; x++, ptr+=channels) {
/* reduce pixel */
pixel = (rtable[*ptr++] + gtable[*ptr++]
+ btable[*ptr++] + base_pixel) & 0xffffffff;
pixel = (rtable[*ptr] + gtable[*(ptr+1)]
+ btable[*(ptr+2)] + base_pixel) & 0xffffffff;
XPutPixel(ximg->image, x, y, pixel);
}
@@ -625,7 +625,8 @@ image2StandardPseudoColor(RContext *ctx, RImage *image)
err[x++] = ptr[x1++];
err[x++] = ptr[x1++];
}
err[x++] = err[x++] = err[x++] = 0;
err[x] = err[x+1] = err[x+2] = 0;
x += 3;
/* convert and dither the image to XImage */
for (y=0, ofs=0; y<image->height; y++) {
if (y<image->height-1) {
@@ -742,8 +743,8 @@ image2GrayScale(RContext *ctx, RImage *image)
for (y=0; y<image->height; y++) {
for (x=0; x<image->width; x++) {
/* reduce pixel */
g = table[(*ptr++ * 30 + *ptr++ * 59 + *ptr++ * 11)/100];
g = table[(*ptr * 30 + *(ptr+1) * 59 + *(ptr+2) * 11)/100];
ptr += 3;
/*data[ofs] = ctx->colors[g].pixel;*/
XPutPixel(ximg->image, x, y, ctx->colors[g].pixel);
}
@@ -776,14 +777,12 @@ image2GrayScale(RContext *ctx, RImage *image)
for (y=0; y<image->height; y++) {
if (y<image->height-1) {
int x1;
for (x=0, x1=(y+1)*image->width*3;
x<image->width;
x1+=channels-3) {
ngerr[x] = (ptr[x1++]*30 + ptr[x1++]*59 + ptr[x1++]*11)/100;
for (x=0, x1=(y+1)*image->width*3; x<image->width; x1+=channels) {
ngerr[x] = (ptr[x1]*30 + ptr[x1+1]*59 + ptr[x1+2]*11)/100;
}
/* last column */
x1-=channels;
ngerr[x] = (ptr[x1++]*30 + ptr[x1++]*59 + ptr[x1++]*11)/100;
ngerr[x] = (ptr[x1]*30 + ptr[x1+1]*59 + ptr[x1+2]*11)/100;
}
for (x=0; x<image->width; x++) {
/* reduce pixel */

View File

@@ -98,9 +98,9 @@ RPutPixel(RImage *image, int x, int y, RColor *color)
alpha = color->alpha;
nalpha = 255 - alpha;
*ptr++ = (((int)*ptr * nalpha) + (r * alpha))/256;
*ptr++ = (((int)*ptr * nalpha) + (g * alpha))/256;
*ptr++ = (((int)*ptr * nalpha) + (b * alpha))/256;
*ptr = (((int)*ptr * nalpha) + (r * alpha))/256; ptr++;
*ptr = (((int)*ptr * nalpha) + (g * alpha))/256; ptr++;
*ptr = (((int)*ptr * nalpha) + (b * alpha))/256; ptr++;
if (image->format == RRGBAFormat) {
*ptr = alpha + ((int)*ptr * nalpha)/256;
}

View File

@@ -185,7 +185,9 @@ RLoadJPEG(RContext *context, char *file_name, int index)
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
bptr = buffer[0];
for (i=0; i<cinfo.image_width; i++) {
*ptr++ = *ptr++ = *ptr++ = *bptr++;
*ptr = *(ptr+1) = *(ptr+2) = *bptr;
bptr++;
ptr += 3;
}
}
}

View File

@@ -11,7 +11,8 @@ Pixmap pix;
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
RContextAttributes attr;
@@ -82,5 +83,6 @@ int main(int argc, char **argv)
XMapRaised(dpy, win);
XFlush(dpy);
getchar();
exit(0);
return 0;
}