Go to the documentation of this file.
29#include <netinet/in.h>
42static bool writeHeader(QIODevice *dev, std::string msg,
unsigned width,
unsigned height,
bool alpha) {
51 strncpy(h.
id,
"PICT", 4);
52 h.
width = htons(width);
56 count = dev->write((
const char*) & h,
sizeof (
PICHeader));
68 count = dev->write((
const char*) & c,
sizeof (
PICChannel));
76 count = dev->write((
const char*) & c,
sizeof (
PICChannel));
85 unsigned r = pixel & 0xFF;
86 unsigned g = (pixel >> 8) & 0xFF;
87 unsigned b = (pixel >> 16) & 0xFF;
88 unsigned a = (pixel >> 24) & 0xFF;
89 return a | (b << 8) | (g << 16) | (r << 24);
103static bool encodeRLE(
const unsigned *image,
unsigned char *output,
bool rgb,
unsigned max,
unsigned &oConsumed,
unsigned &oProduced) {
104 const unsigned *in = image;
105 unsigned char *out = output;
107 unsigned channels = 3;
109 unsigned mask = 0x00FFFFFF;
115 for (; (*in & mask) == (*image & mask) && count < 65536 && count < max; in++, count++) {
121 *out++ = count & 0xFF;
123 memcpy(out, ((
char*) & pixel) + offset, channels);
126 oProduced = out - output;
128 else if (count > 1) {
130 *out++ = (count + 127);
132 memcpy(out, ((
char*) & pixel) + offset, channels);
135 oProduced = out - output;
139 unsigned previous = *image;
141 while ((*in & mask) != (previous & mask) && count < 128 && count < max) {
150 *out++ = (count - 1);
152 for (
unsigned c = 0; c < count; ++c) {
154 memcpy(out, ((
char*) & pixel) + offset, channels);
159 oProduced = out - output;
168static bool writeRow(QIODevice *dev,
unsigned *row,
unsigned width,
bool alpha) {
169 unsigned char *buf =
new unsigned char[width * 4];
173 memset(buf, 0, width * 4);
175 unsigned consumed = 0;
176 unsigned produced = 0;
179 while (posIn < width) {
180 if (!
encodeRLE(row + posIn, buf + posOut,
true, width - posIn, consumed, produced)) {
191 while (posIn < width) {
192 if (!
encodeRLE(row + posIn, buf + posOut,
false, width - posIn, consumed, produced)) {
201 dev->write((
const char*) buf, posOut);
207 std::cout << "ERROR Writing PIC!" << std::endl; \
214 bool alpha = img->hasAlphaChannel();
215 if (!
writeHeader(dev,
"Created with KDE", img->width(), img->height(), alpha)) {
219 for (
int r = 0; r < img->height(); r++) {
220 unsigned *row = (
unsigned*) img->scanLine(r);
221 if (!
writeRow(dev, row, img->width(), alpha)) {
#define PIC_MAGIC_NUMBER
PIC_RW - Qt PIC Support Copyright (C) 2007 Ruben Lopez r.lopez@bren.es
static bool encodeRLE(const unsigned *image, unsigned char *output, bool rgb, unsigned max, unsigned &oConsumed, unsigned &oProduced)
Encodes a portion of the image in RLE coding.
unsigned convertABGRtoRGBA(unsigned pixel)
void pic_write(QIODevice *dev, const QImage *img)
Pic write handler for Qt / KDE.
static bool writeHeader(QIODevice *dev, std::string msg, unsigned width, unsigned height, bool alpha)
PIC_RW - Qt PIC Support Copyright (C) 2007 Ruben Lopez r.lopez@bren.es
static bool writeRow(QIODevice *dev, unsigned *row, unsigned width, bool alpha)
Writes a row to the file.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Jul 18 2024 00:00:00 by
doxygen 1.11.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.