24 static RGB from(
const QRgb color)
37 void setColor(
int i,
const QRgb color)
45 QRgb color(
int i)
const
47 return qRgb(rgb[i].r, rgb[i].g, rgb[i].b);
58 inline int width()
const
60 return (XMax - XMin) + 1;
62 inline int height()
const
64 return (YMax - YMin) + 1;
66 inline bool isCompressed()
const
68 return (Encoding == 1);
123 for (
int i = 0; i < 16; ++i) {
136 s >> m >> ver >> enc >> bpp;
145 s >> xmin >> ymin >> xmax >> ymax;
158 s >> colorMap >> res >> np;
159 ph.ColorMap = colorMap;
162 quint16 bytesperline;
164 ph.BytesPerLine = bytesperline;
167 ph.PaletteInfo = paletteinfo;
171 ph.HScreenSize = hscreensize;
173 ph.VScreenSize = vscreensize;
177 for (
auto i = 0; i < 54; ++i) {
186 s << rgb.r << rgb.g << rgb.b;
193 for (
int i = 0; i < 16; ++i) {
202 s << ph.Manufacturer;
206 s << ph.XMin << ph.YMin << ph.XMax << ph.YMax;
207 s << ph.HDpi << ph.YDpi;
211 s << ph.BytesPerLine;
217 for (
int i = 0; i < 54; ++i) {
224PCXHEADER::PCXHEADER()
236 quint32 size = buf.
size();
240 if (header.isCompressed()) {
249 while (count-- && i < size) {
272 qWarning() <<
"Failed to allocate image, invalid dimensions?" <<
QSize(header.width(), header.height());
276 for (
int y = 0; y < header.height(); ++y) {
281 if (!readLine(s, buf, header)) {
286 unsigned int bpl = qMin((quint16)((header.width() + 7) / 8), header.BytesPerLine);
287 for (
unsigned int x = 0; x < bpl; ++x) {
294 img.
setColor(1, qRgb(255, 255, 255));
307 qWarning() <<
"Failed to allocate image, invalid dimensions?" <<
QSize(header.width(), header.height());
311 for (
int y = 0; y < header.height(); ++y) {
317 if (!readLine(s, buf, header)) {
321 for (
int i = 0; i < 4; i++) {
322 quint32 offset = i * header.BytesPerLine;
323 for (
int x = 0; x < header.width(); ++x) {
324 if (buf[offset + (x / 8)] & (128 >> (x % 8))) {
325 pixbuf[x] = (int)(pixbuf[x]) + (1 << i);
332 qWarning() <<
"Failed to get scanline for" << y <<
"might be out of bounds";
334 for (
int x = 0; x < header.width(); ++x) {
340 for (
int i = 0; i < 16; ++i) {
341 img.
setColor(i, header.ColorMap.color(i));
355 qWarning() <<
"Failed to allocate image, invalid dimensions?" <<
QSize(header.width(), header.height());
359 for (
int y = 0; y < header.height(); ++y) {
364 if (!readLine(s, buf, header)) {
373 unsigned int bpl = qMin(header.BytesPerLine, (quint16)header.width());
374 for (
unsigned int x = 0; x < bpl; ++x) {
381 if (
auto device = s.
device()) {
382 if (device->isSequential()) {
388 device->seek(device->size() - 769);
394 if (flag == 12 && (header.Version == 5 || header.Version == 2)) {
399 for (
int i = 0; i < 256; ++i) {
417 qWarning() <<
"Failed to allocate image, invalid dimensions?" <<
QSize(header.width(), header.height());
421 for (
int y = 0; y < header.height(); ++y) {
426 if (!readLine(s, r_buf, header)) {
429 if (!readLine(s, g_buf, header)) {
432 if (!readLine(s, b_buf, header)) {
437 for (
int x = 0; x < header.width(); ++x) {
438 p[x] = qRgb(r_buf[x], g_buf[x], b_buf[x]);
448 quint32 size = buf.
size();
457 while ((i < size) && (
byte == buf[i]) && (count < 63)) {
464 if (count > 1 || data >= 0xc0) {
482 auto rgb = img.
color(0);
483 auto minIsBlack = (qRed(rgb) + qGreen(rgb) + qBlue(rgb)) / 3 < 127;
488 if (header.BytesPerLine == 0) {
496 for (
int y = 0; y < header.height(); ++y) {
500 for (
int i = 0; i < header.BytesPerLine; ++i) {
501 buf[i] = minIsBlack ? p[i] : ~p[i];
504 if (!writeLine(s, buf)) {
515 header.BytesPerLine = header.width() / 8;
516 if (header.BytesPerLine == 0) {
520 for (
int i = 0; i < 16; ++i) {
521 header.ColorMap.setColor(i, img.
color(i));
528 for (
int i = 0; i < 4; ++i) {
529 buf[i].
resize(header.BytesPerLine);
532 for (
int y = 0; y < header.height(); ++y) {
535 for (
int i = 0; i < 4; ++i) {
539 for (
int x = 0; x < header.width(); ++x) {
540 for (
int i = 0; i < 4; ++i) {
541 if (*(p + x) & (1 << i)) {
542 buf[i][x / 8] = (int)(buf[i][x / 8]) | 1 << (7 - x % 8);
547 for (
int i = 0; i < 4; ++i) {
548 if (!writeLine(s, buf[i])) {
561 if (header.BytesPerLine == 0) {
569 for (
int y = 0; y < header.height(); ++y) {
572 for (
int i = 0; i < header.BytesPerLine; ++i) {
576 if (!writeLine(s, buf)) {
586 for (
int i = 0; i < 256; ++i) {
587 s << RGB::from(img.
color(i));
597 header.BytesPerLine = header.width();
598 if (header.BytesPerLine == 0) {
615 for (
int y = 0; y < header.height(); ++y) {
618 for (
int x = 0; x < header.width(); ++x) {
620 r_buf[x] = qRed(rgb);
621 g_buf[x] = qGreen(rgb);
622 b_buf[x] = qBlue(rgb);
625 if (!writeLine(s, r_buf)) {
628 if (!writeLine(s, g_buf)) {
631 if (!writeLine(s, b_buf)) {
639PCXHandler::PCXHandler()
643bool PCXHandler::canRead()
const
645 if (canRead(device())) {
652bool PCXHandler::read(
QImage *outImage)
665 if (header.Manufacturer != 10 || header.BytesPerLine == 0 || s.
atEnd()) {
671 if (header.Bpp == 1 && header.NPlanes == 1) {
672 ok = readImage1(img, s, header);
673 }
else if (header.Bpp == 1 && header.NPlanes == 4) {
674 ok = readImage4(img, s, header);
675 }
else if (header.Bpp == 8 && header.NPlanes == 1) {
676 ok = readImage8(img, s, header);
677 }
else if (header.Bpp == 8 && header.NPlanes == 3) {
678 ok = readImage24(img, s, header);
681 if (img.
isNull() || !ok) {
691bool PCXHandler::write(
const QImage &image)
698 const int w = img.
width();
699 const int h = img.
height();
701 if (w > 65536 || h > 65536) {
707 header.Manufacturer = 10;
717 header.PaletteInfo = 1;
720 if (img.
depth() == 1) {
721 ok = writeImage1(img, s, header);
723 ok = writeImage4(img, s, header);
724 }
else if (img.
depth() == 8) {
725 ok = writeImage8(img, s, header);
726 }
else if (img.
depth() >= 24) {
727 ok = writeImage24(img, s, header);
733bool PCXHandler::canRead(
QIODevice *device)
736 qWarning(
"PCXHandler::canRead() called with no device");
740 qint64 oldPos = device->
pos();
743 qint64 readBytes = device->
read(head,
sizeof(head));
744 if (readBytes !=
sizeof(head)) {
746 while (readBytes > 0) {
747 device->
ungetChar(head[readBytes-- - 1]);
750 device->
seek(oldPos);
756 while (readBytes > 0) {
757 device->
ungetChar(head[readBytes-- - 1]);
760 device->
seek(oldPos);
763 return qstrncmp(head,
"\012", 1) == 0;
768 if (format ==
"pcx") {
779 if (device->
isReadable() && PCXHandler::canRead(device)) {
796#include "moc_pcx_p.cpp"
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
QFlags< Capability > Capabilities
QDebug operator<<(QDebug dbg, const PerceptualColor::LchaDouble &value)
QByteArray & fill(char ch, qsizetype size)
bool isEmpty() const const
void resize(qsizetype newSize, char c)
qsizetype size() const const
QIODevice * device() const const
void setByteOrder(ByteOrder bo)
Status status() const const
qsizetype bytesPerLine() const const
QRgb color(int i) const const
int colorCount() const const
int dotsPerMeterX() const const
int dotsPerMeterY() const const
bool isNull() const const
void setColor(int index, QRgb colorValue)
void setColorCount(int colorCount)
void setDotsPerMeterX(int x)
void setDotsPerMeterY(int y)
void setDevice(QIODevice *device)
bool isOpen() const const
bool isReadable() const const
virtual bool isSequential() const const
bool isWritable() const const
virtual qint64 pos() const const
QByteArray read(qint64 maxSize)
virtual bool seek(qint64 pos)
virtual qint64 size() const const