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

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.