// from kis_image.cc void KisImage::convertTileToPixmap(KisLayer *lay, int tileNo, QPixmap *pix) { /* Copy the composite image into a QImage so it can be converted to a QPixmap. Note: surprisingly it is not quicker to render directly into a QImage probably due to the CPU cache, it's also useless wrt (writing?) to other colour spaces */ // too confusing - easier to use variables with color names #if 0 uchar *ptr0 = lay->channelMem(2, tileNo, 0, 0); // blue uchar *ptr1 = lay->channelMem(1, tileNo, 0, 0); // green uchar *ptr2 = lay->channelMem(0, tileNo, 0, 0); // red #endif uchar *ptrBlue = lay->channelMem(2, tileNo, 0, 0); // blue uchar *ptrGreen = lay->channelMem(1, tileNo, 0, 0); // green uchar *ptrRed = lay->channelMem(0, tileNo, 0, 0); // red uchar *ptrAlpha = 0; if (m_cMode == cm_RGBA) ptrAlpha = lay->channelMem(3, tileNo, 0, 0); // alpha for(int y = 0; y < TILE_SIZE; y++) { // this directly equates what is in each channel to a QImage scanline // offset backwards to front which hardcodes it to littlendian architecture #if 0 uchar *ptr = m_img.scanLine(y); for(int x = TILE_SIZE; x; x--) { *ptr++ = *ptr0++; // blue *ptr++ = *ptr1++; // green *ptr++ = *ptr2++; // red ptr++; // alpha - ptr incremented, but value not used here } #endif // this may be somewhat more inefficient for littlendian systems but // should also work with bigendian. It lets Qt determine the color values // for each channel which automatically takes into account endianness for // 32 bit images like these. The intermediate variable can be removed // later with the pointer increment taking place inside the qRgb( ) // phrase, I think, achieving the same performance. uchar iblue, ired, igreen, ialpha; uint *ptr = (uint *)m_img.scanLine(y); for(int x = TILE_SIZE; x; x--) { iblue = *ptrBlue++; igreen = *ptrGreen++; ired = *ptrRed++; if (m_cMode == cm_RGBA) { ialpha = *ptrAlpha++; // note - to duplicate (sortof) bigendian bug on littleendian // system, comment out next line and uncomment out the // one after - for testing only - john *ptr = qRgba(ired, igreen, iblue, ialpha); //*ptr = qRgb(ired, igreen, 255 - ialpha); } else { *ptr = qRgb(ired, igreen, iblue); } ptr++; } } // Construct the relevant pixmap convertImageToPixmap(&m_img, pix); }