| 97 | const int BITS_PER_SAMPLE = 8; |
| 98 | |
| 99 | FreedesktopImage::FreedesktopImage(const QImage &img): |
| 100 | width(img.width()), |
| 101 | height(img.height()), |
| 102 | stride(img.width() * BYTES_PER_PIXEL), |
| 103 | hasAlpha(true), |
| 104 | channels(CHANNELS), |
| 105 | bitsPerSample(BITS_PER_SAMPLE) |
| 106 | { |
| 107 | // Convert 00xAARRGGBB to RGBA bytewise (endian-independent) format |
| 108 | QImage tmp = img.convertToFormat(QImage::Format_ARGB32); |
| 109 | const uint32_t *data = reinterpret_cast<const uint32_t*>(tmp.bits()); |
| 110 | |
| 111 | unsigned int num_pixels = width * height; |
| 112 | image.resize(num_pixels * BYTES_PER_PIXEL); |
| 113 | |
| 114 | for(unsigned int ptr = 0; ptr < num_pixels; ++ptr) |
| 115 | { |
| 116 | image[ptr*BYTES_PER_PIXEL+0] = data[ptr] >> 16; // R |
| 117 | image[ptr*BYTES_PER_PIXEL+1] = data[ptr] >> 8; // G |
| 118 | image[ptr*BYTES_PER_PIXEL+2] = data[ptr]; // B |
| 119 | image[ptr*BYTES_PER_PIXEL+3] = data[ptr] >> 24; // A |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImage &i) |
| 124 | { |