QImage qt_imageToQImage(int M, int N, coordval* image, t_imagecolor color_mode) { QImage qimage(QSize(M, N), QImage::Format_ARGB32_Premultiplied); rgb_color rgb1; rgb255_color rgb255; // TrueColor 24-bit color mode if (color_mode == IC_RGB) for (int n = 0; n < N; n++) { QRgb* line = (QRgb*)(qimage.scanLine(n)); for (int m = 0; m < M; m++) { rgb1.r = *image++; rgb1.g = *image++; rgb1.b = *image++; rgb255_from_rgb1(rgb1, &rgb255); *line++ = qRgb(rgb255.r, rgb255.g, rgb255.b); } } else if (color_mode == IC_RGBA) for (int n = 0; n < N; n++) { QRgb* line = (QRgb*)(qimage.scanLine(n)); for (int m = 0; m < M; m++) { unsigned char alpha255 = *(image + 3); float alpha1 = float(alpha255 / 255.); rgb1.r = alpha1 * (*image++); rgb1.g = alpha1 * (*image++); rgb1.b = alpha1 * (*image++); image++; rgb255_from_rgb1(rgb1, &rgb255); *line++ = qRgba(rgb255.r, rgb255.g, rgb255.b, alpha255); } } // Palette color lookup from gray value else for (int n = 0; n < N; n++) { QRgb* line = (QRgb*)(qimage.scanLine(n)); for (int m = 0; m < M; m++) { if (isnan(*image)) { image++; *line++ = 0x00000000; } else { rgb255maxcolors_from_gray(*image++, &rgb255); *line++ = qRgb(rgb255.r, rgb255.g, rgb255.b); } } } return qimage; }
unsigned int * gp_cairo_helper_coordval_to_chars(coordval* image, int M, int N, t_imagecolor color_mode) { int m,n; unsigned int *image255, *image255copy; rgb_color rgb1; rgb255_color rgb255; /* cairo image buffer, upper bits are alpha, then r, g and b * Depends on endianess */ image255 = (unsigned int*) gp_alloc(M*N*sizeof(unsigned int), "gp_cairo : draw image"); image255copy = image255; /* TrueColor 24-bit plot->color mode */ if (color_mode == IC_RGB) { for (n=0; n<N; n++) { for (m=0; m<M; m++) { rgb1.r = *image++; rgb1.g = *image++; rgb1.b = *image++; rgb255_from_rgb1( rgb1, &rgb255 ); *image255copy++ = (0xFF<<24) + (rgb255.r<<16) + (rgb255.g<<8) + rgb255.b; } } } else if (color_mode == IC_RGBA) { unsigned char alpha255; double alpha1; for (n=0; n<N; n++) { for (m=0; m<M; m++) { alpha255 = *(image+3); alpha1 = (float)alpha255 / 255.; rgb1.r = alpha1 * (*image++); rgb1.g = alpha1 * (*image++); rgb1.b = alpha1 * (*image++); image++; rgb255_from_rgb1( rgb1, &rgb255 ); *image255copy++ = (alpha255<<24) + (rgb255.r<<16) + (rgb255.g<<8) + rgb255.b; } } /* Palette plot->color lookup from gray value */ } else { for (n=0; n<N; n++) { for (m=0; m<M; m++) { if (isnan(*image)) { image++; *image255copy++ = 0x00000000; } else { rgb255maxcolors_from_gray( *image++, &rgb255 ); *image255copy++ = (0xFF<<24) + (rgb255.r<<16) + (rgb255.g<<8) + rgb255.b; } } } } return image255; }