• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kpixmapio.cpp
1/*
2 *
3 *
4 * This file is part of the KDE project, module tdeui.
5 * Copyright (C) 2000 Geert Jansen <jansen@kde.org>.
6 *
7 * You can Freely distribute this program under the GNU Library General
8 * Public License. See the file "COPYING.LIB" for the exact licensing terms.
9 *
10 * kpixmapio.cpp: Fast pixmap <-> image conversion.
11 */
12
13#include "kpixmapio.h"
14#include "config.h"
15
16#include <tqimage.h>
17#include <tqpixmap.h>
18#include <tqcolor.h>
19#include <tqglobal.h>
20
21#include <tdeglobal.h>
22#include <tdeconfig.h>
23#include <kdebug.h>
24
25#include <sys/types.h>
26#ifdef Q_OS_UNIX
27#include <sys/ipc.h>
28#include <sys/shm.h>
29#endif
30
31#ifdef TQ_WS_X11
32#include <X11/X.h>
33#include <X11/Xlib.h>
34#include <X11/Xutil.h>
35#ifdef HAVE_MITSHM
36#include <X11/extensions/XShm.h>
37#endif
38#else
39#undef HAVE_MITSHM
40#endif
41
42// d pointer
43
44struct KPixmapIOPrivate
45{
46 int shmsize;
47 int shmpolicy;
48 int threshold;
49 int bpp;
50 int byteorder;
51#ifdef TQ_WS_X11
52 XImage *ximage;
53#ifdef HAVE_MITSHM
54 XShmSegmentInfo *shminfo;
55 bool first_try;
56#endif
57#else
58 void *ximage;
59#endif
60};
61
62
63// From Qt: Returns the position of the lowest set bit in val.
64
65typedef unsigned char uchar;
66typedef unsigned int uint;
67
68#ifdef HAVE_MITSHM
69static int lowest_bit(uint val)
70{
71 int i;
72 uint test = 1;
73 for (i=0; (!(val & test)) && i<32; i++, test<<=1);
74 return (i == 32) ? -1 : i;
75}
76#endif
77
78/*** KPixmapIO ***/
79
80KPixmapIO::KPixmapIO()
81{
82 m_bShm = false;
83 d = new KPixmapIOPrivate;
84
85#ifdef HAVE_MITSHM
86 setShmPolicy(ShmDontKeep);
87 TDEConfig *config = TDEGlobal::config();
88 if (!config->readBoolEntry("UseMitShm", true))
89 return;
90
91 int ignore;
92 if (XQueryExtension(tqt_xdisplay(), "MIT-SHM", &ignore, &ignore, &ignore))
93 {
94 if (XShmQueryExtension(tqt_xdisplay()))
95 m_bShm = true;
96 }
97 if (!m_bShm)
98 {
99 kdDebug(290) << k_lineinfo << "MIT-SHM not available!\n";
100 d->ximage = 0;
101 d->shminfo = 0;
102 d->shmsize = 0;
103 return;
104 }
105
106 // Sort out bit format. Create a temporary XImage for this.
107 d->shminfo = new XShmSegmentInfo;
108 d->ximage = XShmCreateImage(tqt_xdisplay(), (Visual *) TQPaintDevice::x11AppVisual(),
109 TQPaintDevice::x11AppDepth(), ZPixmap, 0L, d->shminfo, 10, 10);
110 d->bpp = d->ximage->bits_per_pixel;
111 d->first_try = true;
112 int bpp = d->bpp;
113 if (d->ximage->byte_order == LSBFirst)
114 bpp++;
115 int red_shift = lowest_bit(d->ximage->red_mask);
116 int green_shift = lowest_bit(d->ximage->green_mask);
117 int blue_shift = lowest_bit(d->ximage->blue_mask);
118 XDestroyImage(d->ximage); d->ximage = 0L;
119 d->shmsize = 0;
120
121 // Offer discrete possibilities for the bitformat. Each will have its
122 // own routine. The general algorithm using bitshifts is much too slow;
123 // this has to be done for every pixel!
124
125 if ((bpp == 32) && (red_shift == 16) && (green_shift == 8) &&
126 (blue_shift == 0))
127 d->byteorder = bo32_ARGB;
128 else if ((bpp == 32) && (red_shift == 0) && (green_shift == 8) &&
129 (blue_shift == 16))
130 d->byteorder = bo32_BGRA;
131 else if ((bpp == 33) && (red_shift == 16) && (green_shift == 8) &&
132 (blue_shift == 0))
133 d->byteorder = bo32_BGRA;
134 else if ((bpp == 24) && (red_shift == 16) && (green_shift == 8) &&
135 (blue_shift == 0))
136 d->byteorder = bo24_RGB;
137 else if ((bpp == 24) && (red_shift == 0) && (green_shift == 8) &&
138 (blue_shift == 16))
139 d->byteorder = bo24_BGR;
140 else if ((bpp == 25) && (red_shift == 16) && (green_shift == 8) &&
141 (blue_shift == 0))
142 d->byteorder = bo24_BGR;
143 else if ((bpp == 16) && (red_shift == 11) && (green_shift == 5) &&
144 (blue_shift == 0))
145 d->byteorder = bo16_RGB_565;
146 else if ((bpp == 16) && (red_shift == 10) && (green_shift == 5) &&
147 (blue_shift == 0))
148 d->byteorder = bo16_RGB_555;
149 else if ((bpp == 17) && (red_shift == 11) && (green_shift == 5) &&
150 (blue_shift == 0))
151 d->byteorder = bo16_BGR_565;
152 else if ((bpp == 17) && (red_shift == 10) && (green_shift == 5) &&
153 (blue_shift == 0))
154 d->byteorder = bo16_BGR_555;
155 else if ((bpp == 8) || (bpp == 9))
156 d->byteorder = bo8;
157 else
158 {
159 m_bShm = false;
160 kdWarning(290) << "Byte order not supported!" << endl;
161 kdWarning(290) << "red = " << red_shift
162 << ", green = " << green_shift
163 << ", blue = " << blue_shift << endl;
164 kdWarning(290) << "Please report to <jansen@kde.org>\n";
165 }
166#else
167 d->shmsize = 0;
168 d->ximage = 0;
169#endif
170}
171
172
173KPixmapIO::~KPixmapIO()
174{
175 destroyXImage();
176 destroyShmSegment();
177#ifdef HAVE_MITSHM
178 delete d->shminfo;
179#endif
180 delete d;
181}
182
183
184TQPixmap KPixmapIO::convertToPixmap(const TQImage &img)
185{
186 int size = img.width() * img.height();
187 if (m_bShm && (img.depth() > 1) && (d->bpp > 8) && (size > d->threshold))
188 {
189 TQPixmap dst(img.width(), img.height());
190 putImage(&dst, 0, 0, &img);
191 return dst;
192 } else
193 {
194 TQPixmap dst;
195 dst.convertFromImage(img);
196 return dst;
197 }
198
199}
200
201
202TQImage KPixmapIO::convertToImage(const TQPixmap &pm)
203{
204 TQImage image;
205 int size = pm.width() * pm.height();
206 if (m_bShm && (d->bpp >= 8) && (size > d->threshold))
207 image = getImage(&pm, 0, 0, pm.width(), pm.height());
208 else
209 image = pm.convertToImage();
210 return image;
211}
212
213
214void KPixmapIO::putImage(TQPixmap *dst, const TQPoint &offset,
215 const TQImage *src)
216{
217 putImage(dst, offset.x(), offset.y(), src);
218}
219
220
221void KPixmapIO::putImage(TQPixmap *dst, int dx, int dy, const TQImage *src)
222{
223 int size = src->width() * src->height();
224 bool fallback = true;
225 if (m_bShm && (src->depth() > 1) && (d->bpp > 8) && (size > d->threshold))
226 {
227#ifdef HAVE_MITSHM
228 if( initXImage(src->width(), src->height()))
229 {
230 convertToXImage(*src);
231 XShmPutImage(tqt_xdisplay(), dst->handle(), tqt_xget_temp_gc(tqt_xscreen(), false), d->ximage,
232 dx, dy, 0, 0, src->width(), src->height(), false);
233 // coolo: do we really need this here? I see no good for it
234 XSync(tqt_xdisplay(), false);
235 doneXImage();
236 fallback = false;
237 }
238#endif
239 }
240 if( fallback )
241 {
242 TQPixmap pix;
243 pix.convertFromImage(*src);
244 bitBlt(dst, dx, dy, &pix, 0, 0, pix.width(), pix.height());
245 }
246}
247
248
249TQImage KPixmapIO::getImage(const TQPixmap *src, const TQRect &rect)
250{
251 return getImage(src, rect.x(), rect.y(), rect.width(), rect.height());
252}
253
254
255TQImage KPixmapIO::getImage(const TQPixmap *src, int sx, int sy, int sw, int sh)
256{
257 TQImage image;
258 int size = src->width() * src->height();
259 bool fallback = true;
260 if ((m_bShm) && (d->bpp >= 8) && (size > d->threshold))
261 {
262#ifdef HAVE_MITSHM
263 if( initXImage(sw, sh))
264 {
265 XShmGetImage(tqt_xdisplay(), src->handle(), d->ximage, sx, sy, AllPlanes);
266 image = convertFromXImage();
267 doneXImage();
268 fallback = false;
269 }
270#endif
271 }
272 if( fallback )
273 {
274 TQPixmap pix(sw, sh);
275 bitBlt(&pix, 0, 0, src, sx, sy, sw, sh);
276 image = pix.convertToImage();
277 }
278 return image;
279}
280
281
282#ifdef HAVE_MITSHM
283
284void KPixmapIO::preAllocShm(int size)
285{
286 destroyXImage();
287 createShmSegment(size);
288}
289
290
291void KPixmapIO::setShmPolicy(int policy)
292{
293 switch (policy)
294 {
295 case ShmDontKeep:
296 d->shmpolicy = ShmDontKeep;
297 d->threshold = 5000;
298 break;
299 case ShmKeepAndGrow:
300 d->shmpolicy = ShmKeepAndGrow;
301 d->threshold = 2000;
302 break;
303 default:
304 break;
305 }
306}
307
308
309bool KPixmapIO::initXImage(int w, int h)
310{
311 if (d->ximage && (w == d->ximage->width) && (h == d->ximage->height))
312 return true;
313
314 if( !createXImage(w, h))
315 return false;
316 int size = d->ximage->bytes_per_line * d->ximage->height;
317 if (size > d->shmsize)
318 {
319 if( !createShmSegment(size))
320 {
321 destroyXImage();
322 return false;
323 }
324 }
325 d->ximage->data = d->shminfo->shmaddr;
326 return true;
327}
328
329
330void KPixmapIO::doneXImage()
331{
332 if (d->shmpolicy == ShmDontKeep)
333 {
334 destroyXImage();
335 destroyShmSegment();
336 }
337}
338
339
340void KPixmapIO::destroyXImage()
341{
342 if (d->ximage)
343 {
344 XDestroyImage(d->ximage);
345 d->ximage = 0L;
346 }
347}
348
349
350bool KPixmapIO::createXImage(int w, int h)
351{
352 destroyXImage();
353 d->ximage = XShmCreateImage(tqt_xdisplay(), (Visual *) TQPaintDevice::x11AppVisual(),
354 TQPaintDevice::x11AppDepth(), ZPixmap, 0L, d->shminfo, w, h);
355 return d->ximage != None;
356}
357
358
359void KPixmapIO::destroyShmSegment()
360{
361 if (d->shmsize)
362 {
363 XShmDetach(tqt_xdisplay(), d->shminfo);
364 shmdt(d->shminfo->shmaddr);
365 shmctl(d->shminfo->shmid, IPC_RMID, 0);
366 d->shmsize = 0;
367 }
368}
369
370static bool use_xshm = true;
371static unsigned long kpixmapio_serial;
372static int (*old_errhandler)(Display *dpy, XErrorEvent *ev) = 0;
373
374static int kpixmapio_errorhandler(Display *dpy, XErrorEvent *ev)
375{
376 if(ev->serial == kpixmapio_serial) {
377 /* assuming that xshm errors mean it can't be used at all
378 (e.g. remote display) */
379 use_xshm = false;
380 kdDebug(290) << "Disabling Xshm" << endl;
381 return 0;
382 } else {
383 // another error
384 return old_errhandler(dpy, ev);
385 }
386}
387
388bool KPixmapIO::createShmSegment(int size)
389{
390 destroyShmSegment();
391 d->shminfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0600);
392 if ( d->shminfo->shmid < 0)
393 {
394 kdWarning(290) << "Could not get shared memory segment.\n";
395 m_bShm = false;
396 return false;
397 }
398
399 d->shminfo->shmaddr = (char *) shmat(d->shminfo->shmid, 0, 0);
400 if (d->shminfo->shmaddr == (char *)-1)
401 {
402 kdWarning(290) << "Could not attach shared memory segment.\n";
403 m_bShm = false;
404 shmctl(d->shminfo->shmid, IPC_RMID, 0);
405 return false;
406 }
407
408 d->shminfo->readOnly = false;
409
410 if (d->first_try) {
411 // make sure that we don't get errors of old stuff
412 XSync(tqt_xdisplay(), False);
413 old_errhandler = XSetErrorHandler(kpixmapio_errorhandler);
414 kpixmapio_serial = NextRequest(tqt_xdisplay());
415 }
416
417 if ( !XShmAttach(tqt_xdisplay(), d->shminfo))
418 {
419 kdWarning() << "X-Server could not attach shared memory segment.\n";
420 m_bShm = false;
421 shmdt(d->shminfo->shmaddr);
422 shmctl(d->shminfo->shmid, IPC_RMID, 0);
423 }
424
425 if (d->first_try) {
426 XSync(tqt_xdisplay(), false);
427
428 if (!use_xshm)
429 m_bShm = false;
430
431 XSetErrorHandler(old_errhandler);
432 d->first_try = false;
433 }
434 d->shmsize = size;
435
436 return m_bShm;
437}
438
439
440/*
441 * The following functions convertToXImage/convertFromXImage are a little
442 * long. This is because of speed, I want to get as much out of the inner
443 * loop as possible.
444 */
445
446TQImage KPixmapIO::convertFromXImage()
447{
448 int x, y;
449 int width = d->ximage->width, height = d->ximage->height;
450 int bpl = d->ximage->bytes_per_line;
451 char *data = d->ximage->data;
452
453 TQImage image;
454 if (d->bpp == 8)
455 {
456 image.create(width, height, 8);
457
458 // Query color map. Don't remove unused entries as a speed
459 // optmization.
460 int i, ncells = 256;
461 XColor *cmap = new XColor[ncells];
462 for (i=0; i<ncells; i++)
463 cmap[i].pixel = i;
464 XQueryColors(tqt_xdisplay(), TQPaintDevice::x11AppColormap(),
465 cmap, ncells);
466 image.setNumColors(ncells);
467 for (i=0; i<ncells; i++)
468 image.setColor(i, tqRgb(cmap[i].red, cmap[i].green, cmap[i].blue >> 8));
469 } else
470 image.create(width, height, 32);
471
472 switch (d->byteorder)
473 {
474
475 case bo8:
476 {
477 for (y=0; y<height; y++)
478 memcpy(image.scanLine(y), data + y*bpl, width);
479 break;
480 }
481
482 case bo16_RGB_565:
483 case bo16_BGR_565:
484 {
485 TQ_INT32 pixel, *src;
486 TQRgb *dst, val;
487 for (y=0; y<height; y++)
488 {
489 src = (TQ_INT32 *) (data + y*bpl);
490 dst = (TQRgb *) image.scanLine(y);
491 for (x=0; x<width/2; x++)
492 {
493 pixel = *src++;
494 val = ((pixel & 0xf800) << 8) | ((pixel & 0x7e0) << 5) |
495 ((pixel & 0x1f) << 3);
496 *dst++ = val;
497 pixel >>= 16;
498 val = ((pixel & 0xf800) << 8) | ((pixel & 0x7e0) << 5) |
499 ((pixel & 0x1f) << 3);
500 *dst++ = val;
501 }
502 if (width%2)
503 {
504 pixel = *src++;
505 val = ((pixel & 0xf800) << 8) | ((pixel & 0x7e0) << 5) |
506 ((pixel & 0x1f) << 3);
507 *dst++ = val;
508 }
509 }
510 break;
511 }
512
513 case bo16_RGB_555:
514 case bo16_BGR_555:
515 {
516 TQ_INT32 pixel, *src;
517 TQRgb *dst, val;
518 for (y=0; y<height; y++)
519 {
520 src = (TQ_INT32 *) (data + y*bpl);
521 dst = (TQRgb *) image.scanLine(y);
522 for (x=0; x<width/2; x++)
523 {
524 pixel = *src++;
525 val = ((pixel & 0x7c00) << 9) | ((pixel & 0x3e0) << 6) |
526 ((pixel & 0x1f) << 3);
527 *dst++ = val;
528 pixel >>= 16;
529 val = ((pixel & 0x7c00) << 9) | ((pixel & 0x3e0) << 6) |
530 ((pixel & 0x1f) << 3);
531 *dst++ = val;
532 }
533 if (width%2)
534 {
535 pixel = *src++;
536 val = ((pixel & 0x7c00) << 9) | ((pixel & 0x3e0) << 6) |
537 ((pixel & 0x1f) << 3);
538 *dst++ = val;
539 }
540 }
541 break;
542 }
543
544 case bo24_RGB:
545 {
546 char *src;
547 TQRgb *dst;
548 int w1 = width/4;
549 TQ_INT32 d1, d2, d3;
550 for (y=0; y<height; y++)
551 {
552 src = data + y*bpl;
553 dst = (TQRgb *) image.scanLine(y);
554 for (x=0; x<w1; x++)
555 {
556 d1 = *((TQ_INT32 *)src);
557 d2 = *((TQ_INT32 *)src + 1);
558 d3 = *((TQ_INT32 *)src + 2);
559 src += 12;
560 *dst++ = d1;
561 *dst++ = (d1 >> 24) | (d2 << 8);
562 *dst++ = (d3 << 16) | (d2 >> 16);
563 *dst++ = d3 >> 8;
564 }
565 for (x=w1*4; x<width; x++)
566 {
567 d1 = *src++ << 16;
568 d1 += *src++ << 8;
569 d1 += *src++;
570 *dst++ = d1;
571 }
572 }
573 break;
574 }
575
576 case bo24_BGR:
577 {
578 char *src;
579 TQRgb *dst;
580 int w1 = width/4;
581 TQ_INT32 d1, d2, d3;
582 for (y=0; y<height; y++)
583 {
584 src = data + y*bpl;
585 dst = (TQRgb *) image.scanLine(y);
586 for (x=0; x<w1; x++)
587 {
588 d1 = *((TQ_INT32 *)src);
589 d2 = *((TQ_INT32 *)src + 1);
590 d3 = *((TQ_INT32 *)src + 2);
591 src += 12;
592 *dst++ = d1;
593 *dst++ = (d1 >> 24) | (d2 << 8);
594 *dst++ = (d3 << 16) | (d2 >> 16);
595 *dst++ = d3 >> 8;
596 }
597 for (x=w1*4; x<width; x++)
598 {
599 d1 = *src++;
600 d1 += *src++ << 8;
601 d1 += *src++ << 16;
602 *dst++ = d1;
603 }
604 }
605 break;
606 }
607
608 case bo32_ARGB:
609 case bo32_BGRA:
610 {
611 for (y=0; y<height; y++)
612 memcpy(image.scanLine(y), data + y*bpl, width*4);
613 break;
614 }
615
616 }
617
618 return image;
619}
620
621
622void KPixmapIO::convertToXImage(const TQImage &img)
623{
624 int x, y;
625 int width = d->ximage->width, height = d->ximage->height;
626 int bpl = d->ximage->bytes_per_line;
627 char *data = d->ximage->data;
628
629 switch (d->byteorder)
630 {
631
632 case bo16_RGB_555:
633 case bo16_BGR_555:
634
635 if (img.depth() == 32)
636 {
637 TQRgb *src, pixel;
638 TQ_INT32 *dst, val;
639 for (y=0; y<height; y++)
640 {
641 src = (TQRgb *) img.scanLine(y);
642 dst = (TQ_INT32 *) (data + y*bpl);
643 for (x=0; x<width/2; x++)
644 {
645 pixel = *src++;
646 val = ((pixel & 0xf80000) >> 9) | ((pixel & 0xf800) >> 6) |
647 ((pixel & 0xff) >> 3);
648 pixel = *src++;
649 val |= (((pixel & 0xf80000) >> 9) | ((pixel & 0xf800) >> 6) |
650 ((pixel & 0xff) >> 3)) << 16;
651 *dst++ = val;
652 }
653 if (width%2)
654 {
655 pixel = *src++;
656 *((TQ_INT16 *)dst) = ((pixel & 0xf80000) >> 9) |
657 ((pixel & 0xf800) >> 6) | ((pixel & 0xff) >> 3);
658 }
659 }
660 } else
661 {
662 uchar *src;
663 TQ_INT32 val, *dst;
664 TQRgb pixel, *clut = img.colorTable();
665 for (y=0; y<height; y++)
666 {
667 src = const_cast<TQImage&>(img).scanLine(y);
668 dst = (TQ_INT32 *) (data + y*bpl);
669 for (x=0; x<width/2; x++)
670 {
671 pixel = clut[*src++];
672 val = ((pixel & 0xf80000) >> 9) | ((pixel & 0xf800) >> 6) |
673 ((pixel & 0xff) >> 3);
674 pixel = clut[*src++];
675 val |= (((pixel & 0xf80000) >> 9) | ((pixel & 0xf800) >> 6) |
676 ((pixel & 0xff) >> 3)) << 16;
677 *dst++ = val;
678 }
679 if (width%2)
680 {
681 pixel = clut[*src++];
682 *((TQ_INT16 *)dst) = ((pixel & 0xf80000) >> 9) |
683 ((pixel & 0xf800) >> 6) | ((pixel & 0xff) >> 3);
684 }
685 }
686 }
687 break;
688
689 case bo16_RGB_565:
690 case bo16_BGR_565:
691
692 if (img.depth() == 32)
693 {
694 TQRgb *src, pixel;
695 TQ_INT32 *dst, val;
696 for (y=0; y<height; y++)
697 {
698 src = (TQRgb *) img.scanLine(y);
699 dst = (TQ_INT32 *) (data + y*bpl);
700 for (x=0; x<width/2; x++)
701 {
702 pixel = *src++;
703 val = ((pixel & 0xf80000) >> 8) | ((pixel & 0xfc00) >> 5) |
704 ((pixel & 0xff) >> 3);
705 pixel = *src++;
706 val |= (((pixel & 0xf80000) >> 8) | ((pixel & 0xfc00) >> 5) |
707 ((pixel & 0xff) >> 3)) << 16;
708 *dst++ = val;
709 }
710 if (width%2)
711 {
712 pixel = *src++;
713 *((TQ_INT16 *)dst) = ((pixel & 0xf80000) >> 8) |
714 ((pixel & 0xfc00) >> 5) | ((pixel & 0xff) >> 3);
715 }
716 }
717 } else
718 {
719 uchar *src;
720 TQ_INT32 val, *dst;
721 TQRgb pixel, *clut = img.colorTable();
722 for (y=0; y<height; y++)
723 {
724 src = const_cast<TQImage&>(img).scanLine(y);
725 dst = (TQ_INT32 *) (data + y*bpl);
726 for (x=0; x<width/2; x++)
727 {
728 pixel = clut[*src++];
729 val = ((pixel & 0xf80000) >> 8) | ((pixel & 0xfc00) >> 5) |
730 ((pixel & 0xff) >> 3);
731 pixel = clut[*src++];
732 val |= (((pixel & 0xf80000) >> 8) | ((pixel & 0xfc00) >> 5) |
733 ((pixel & 0xff) >> 3)) << 16;
734 *dst++ = val;
735 }
736 if (width%2)
737 {
738 pixel = clut[*src++];
739 *((TQ_INT16 *)dst) = ((pixel & 0xf80000) >> 8) |
740 ((pixel & 0xfc00) >> 5) | ((pixel & 0xff) >> 3);
741 }
742 }
743 }
744 break;
745
746 case bo24_RGB:
747
748 if (img.depth() == 32)
749 {
750 char *dst;
751 int w1 = width/4;
752 TQRgb *src, d1, d2, d3, d4;
753 for (y=0; y<height; y++)
754 {
755 src = (TQRgb *) img.scanLine(y);
756 dst = data + y*bpl;
757 for (x=0; x<w1; x++)
758 {
759 d1 = (*src++ & 0xffffff);
760 d2 = (*src++ & 0xffffff);
761 d3 = (*src++ & 0xffffff);
762 d4 = (*src++ & 0xffffff);
763 *((TQ_INT32 *)dst) = d1 | (d2 << 24);
764 *((TQ_INT32 *)dst+1) = (d2 >> 8) | (d3 << 16);
765 *((TQ_INT32 *)dst+2) = (d4 << 8) | (d3 >> 16);
766 dst += 12;
767 }
768 for (x=w1*4; x<width; x++)
769 {
770 d1 = *src++;
771 *dst++ = tqRed(d1);
772 *dst++ = tqGreen(d1);
773 *dst++ = tqBlue(d1);
774 }
775 }
776 } else
777 {
778 uchar *src, *dst;
779 int w1 = width/4;
780 TQRgb *clut = img.colorTable(), d1, d2, d3, d4;
781 for (y=0; y<height; y++)
782 {
783 src = const_cast<TQImage&>(img).scanLine(y);
784 dst = (uchar *) data + y*bpl;
785 for (x=0; x<w1; x++)
786 {
787 d1 = (clut[*src++] & 0xffffff);
788 d2 = (clut[*src++] & 0xffffff);
789 d3 = (clut[*src++] & 0xffffff);
790 d4 = (clut[*src++] & 0xffffff);
791 *((TQ_INT32 *)dst) = d1 | (d2 << 24);
792 *((TQ_INT32 *)dst+1) = (d2 >> 8) | (d3 << 16);
793 *((TQ_INT32 *)dst+2) = (d4 << 8) | (d3 >> 16);
794 dst += 12;
795 }
796 for (x=w1*4; x<width; x++)
797 {
798 d1 = clut[*src++];
799 *dst++ = tqRed(d1);
800 *dst++ = tqGreen(d1);
801 *dst++ = tqBlue(d1);
802 }
803 }
804 }
805 break;
806
807 case bo24_BGR:
808
809 if (img.depth() == 32)
810 {
811 char *dst;
812 TQRgb *src, d1, d2, d3, d4;
813 int w1 = width/4;
814 for (y=0; y<height; y++)
815 {
816 src = (TQRgb *) img.scanLine(y);
817 dst = data + y*bpl;
818 for (x=0; x<w1; x++)
819 {
820 d1 = (*src++ & 0xffffff);
821 d2 = (*src++ & 0xffffff);
822 d3 = (*src++ & 0xffffff);
823 d4 = (*src++ & 0xffffff);
824 *((TQ_INT32 *)dst) = d1 | (d2 << 24);
825 *((TQ_INT32 *)dst+1) = (d2 >> 8) | (d3 << 16);
826 *((TQ_INT32 *)dst+2) = (d4 << 8) | (d3 >> 16);
827 dst += 12;
828 }
829 for (x=w1*4; x<width; x++)
830 {
831 d1 = *src++;
832 *dst++ = tqBlue(d1);
833 *dst++ = tqGreen(d1);
834 *dst++ = tqRed(d1);
835 }
836 }
837 } else
838 {
839 uchar *src, *dst;
840 int w1 = width/4;
841 TQRgb *clut = img.colorTable(), d1, d2, d3, d4;
842 for (y=0; y<height; y++)
843 {
844 src = const_cast<TQImage&>(img).scanLine(y);
845 dst = (uchar *) data + y*bpl;
846 for (x=0; x<w1; x++)
847 {
848 d1 = (clut[*src++] & 0xffffff);
849 d2 = (clut[*src++] & 0xffffff);
850 d3 = (clut[*src++] & 0xffffff);
851 d4 = (clut[*src++] & 0xffffff);
852 *((TQ_INT32 *)dst) = d1 | (d2 << 24);
853 *((TQ_INT32 *)dst+1) = (d2 >> 8) | (d3 << 16);
854 *((TQ_INT32 *)dst+2) = (d4 << 8) | (d3 >> 16);
855 dst += 12;
856 }
857 for (x=w1*4; x<width; x++)
858 {
859 d1 = clut[*src++];
860 *dst++ = tqBlue(d1);
861 *dst++ = tqGreen(d1);
862 *dst++ = tqRed(d1);
863 }
864 }
865 }
866 break;
867
868 case bo32_ARGB:
869 case bo32_BGRA:
870
871 if (img.depth() == 32)
872 {
873 for (y=0; y<height; y++)
874 memcpy(data + y*bpl, img.scanLine(y), width*4);
875 } else
876 {
877 uchar *src;
878 TQRgb *dst, *clut = img.colorTable();
879 for (y=0; y<height; y++)
880 {
881 src = const_cast<TQImage&>(img).scanLine(y);
882 dst = (TQRgb *) (data + y*bpl);
883 for (x=0; x<width; x++)
884 *dst++ = clut[*src++];
885 }
886 }
887 break;
888
889 }
890}
891
892#else
893
894void KPixmapIO::preAllocShm(int) {}
895void KPixmapIO::setShmPolicy(int) {}
896bool KPixmapIO::initXImage(int, int) { return false; }
897void KPixmapIO::doneXImage() {}
898bool KPixmapIO::createXImage(int, int) { return false; }
899void KPixmapIO::destroyXImage() {}
900bool KPixmapIO::createShmSegment(int) { return false; }
901void KPixmapIO::destroyShmSegment() {}
902TQImage KPixmapIO::convertFromXImage() { return TQImage(); }
903void KPixmapIO::convertToXImage(const TQImage &) {}
904
905#endif // HAVE_MITSHM
KPixmapIO::setShmPolicy
void setShmPolicy(int policy)
Set the shared memory allocation policy.
Definition: kpixmapio.cpp:895
KPixmapIO::preAllocShm
void preAllocShm(int size)
Pre-allocate shared memory.
Definition: kpixmapio.cpp:894
KPixmapIO::convertToPixmap
TQPixmap convertToPixmap(const TQImage &image)
Convert an image to a pixmap.
Definition: kpixmapio.cpp:184
KPixmapIO::putImage
void putImage(TQPixmap *dst, int dx, int dy, const TQImage *src)
Bitblt an image onto a pixmap.
Definition: kpixmapio.cpp:221
KPixmapIO::getImage
TQImage getImage(const TQPixmap *src, int sx, int sy, int sw, int sh)
Transfer (a part of) a pixmap to an image.
Definition: kpixmapio.cpp:255
KPixmapIO::convertToImage
TQImage convertToImage(const TQPixmap &pixmap)
Convert a pixmap to an image.
Definition: kpixmapio.cpp:202
TDEConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
TDEConfig
TDEGlobal::config
static TDEConfig * config()
kdWarning
kdbgstream kdWarning(int area=0)
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.