- for (int x = 0; x < width; ++x) {
- int pixel = rgbaf2argb(data[(y * width + x) * 4 + 0],
- data[(y * width + x) * 4 + 1],
- data[(y * width + x) * 4 + 2],
- data[(y * width + x) * 4 + 3]);
- pixelData[y * width + x] = pixel;
+ QRgb *dst = (QRgb *)m_image.scanLine(y);
+
+ if (image->channelType == image::TYPE_UNORM8) {
+ const unsigned char *src = srcRow;
+ for (int x = 0; x < width; ++x) {
+ unsigned char rgba[4];
+ for (int c = 0; c < image->channels; ++c) {
+ rgba[c] = *src++;
+ }
+ if (image->channels == 1) {
+ // Use gray-scale instead of red
+ rgba[1] = rgba[0];
+ rgba[2] = rgba[0];
+ }
+ dst[x] = qRgba(rgba[0], rgba[1], rgba[2], rgba[3]);
+ }
+ } else {
+ const float *src = (const float *)srcRow;
+ for (int x = 0; x < width; ++x) {
+ unsigned char rgba[4] = {0, 0, 0, 0xff};
+ for (int c = 0; c < image->channels; ++c) {
+ float f = *src++;
+ unsigned char u;
+ if (f >= 1.0f) {
+ u = 255;
+ } else if (f <= 0.0f) {
+ u = 0;
+ } else {
+ u = f * 255 + 0.5;
+ }
+ rgba[c] = u;
+ }
+ if (image->channels == 1) {
+ // Use gray-scale instead of red
+ rgba[1] = rgba[0];
+ rgba[2] = rgba[0];
+ }
+ dst[x] = qRgba(rgba[0], rgba[1], rgba[2], rgba[3]);
+ }