src/gui/image/qpixmap_x11.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
   312 
   312 
   313 static int qt_pixmap_serial = 0;
   313 static int qt_pixmap_serial = 0;
   314 int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth = 0;
   314 int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth = 0;
   315 
   315 
   316 QX11PixmapData::QX11PixmapData(PixelType type)
   316 QX11PixmapData::QX11PixmapData(PixelType type)
   317     : QPixmapData(type, X11Class), hd(0),
   317     : QPixmapData(type, X11Class), gl_surface(0), hd(0),
   318       flags(Uninitialized), x11_mask(0), picture(0), mask_picture(0), hd2(0), gl_surface(0),
   318       flags(Uninitialized), x11_mask(0), picture(0), mask_picture(0), hd2(0),
   319       share_mode(QPixmap::ImplicitlyShared), pengine(0)
   319       share_mode(QPixmap::ImplicitlyShared), pengine(0)
   320 {
   320 {
   321 }
   321 }
   322 
   322 
   323 QPixmapData *QX11PixmapData::createCompatiblePixmapData() const
   323 QPixmapData *QX11PixmapData::createCompatiblePixmapData() const
  1140         QBitmap m = QBitmap::fromImage(image.createAlphaMask(flags));
  1140         QBitmap m = QBitmap::fromImage(image.createAlphaMask(flags));
  1141         setMask(m);
  1141         setMask(m);
  1142     }
  1142     }
  1143 }
  1143 }
  1144 
  1144 
  1145 void QX11PixmapData::bitmapFromImage(const QImage &image)
  1145 Qt::HANDLE QX11PixmapData::createBitmapFromImage(const QImage &image)
  1146 {
  1146 {
  1147     QImage img = image.convertToFormat(QImage::Format_MonoLSB);
  1147     QImage img = image.convertToFormat(QImage::Format_MonoLSB);
  1148     const QRgb c0 = QColor(Qt::black).rgb();
  1148     const QRgb c0 = QColor(Qt::black).rgb();
  1149     const QRgb c1 = QColor(Qt::white).rgb();
  1149     const QRgb c1 = QColor(Qt::white).rgb();
  1150     if (img.color(0) == c0 && img.color(1) == c1) {
  1150     if (img.color(0) == c0 && img.color(1) == c1) {
  1153         img.setColor(1, c0);
  1153         img.setColor(1, c0);
  1154     }
  1154     }
  1155 
  1155 
  1156     char  *bits;
  1156     char  *bits;
  1157     uchar *tmp_bits;
  1157     uchar *tmp_bits;
  1158     w = img.width();
  1158     int w = img.width();
  1159     h = img.height();
  1159     int h = img.height();
  1160     d = 1;
       
  1161     is_null = (w <= 0 || h <= 0);
       
  1162     int bpl = (w + 7) / 8;
  1160     int bpl = (w + 7) / 8;
  1163     int ibpl = img.bytesPerLine();
  1161     int ibpl = img.bytesPerLine();
  1164     if (bpl != ibpl) {
  1162     if (bpl != ibpl) {
  1165         tmp_bits = new uchar[bpl*h];
  1163         tmp_bits = new uchar[bpl*h];
  1166         bits = (char *)tmp_bits;
  1164         bits = (char *)tmp_bits;
  1175         }
  1173         }
  1176     } else {
  1174     } else {
  1177         bits = (char *)img.bits();
  1175         bits = (char *)img.bits();
  1178         tmp_bits = 0;
  1176         tmp_bits = 0;
  1179     }
  1177     }
  1180     hd = (Qt::HANDLE)XCreateBitmapFromData(xinfo.display(),
  1178     Qt::HANDLE hd = (Qt::HANDLE)XCreateBitmapFromData(X11->display,
  1181                                            RootWindow(xinfo.display(), xinfo.screen()),
  1179                                            QX11Info::appRootWindow(),
  1182                                            bits, w, h);
  1180                                            bits, w, h);
  1183 
  1181     if (tmp_bits)                                // Avoid purify complaint
       
  1182         delete [] tmp_bits;
       
  1183     return hd;
       
  1184 }
       
  1185 
       
  1186 void QX11PixmapData::bitmapFromImage(const QImage &image)
       
  1187 {
       
  1188     w = image.width();
       
  1189     h = image.height();
       
  1190     d = 1;
       
  1191     is_null = (w <= 0 || h <= 0);
       
  1192     hd = createBitmapFromImage(image);
  1184 #ifndef QT_NO_XRENDER
  1193 #ifndef QT_NO_XRENDER
  1185     if (X11->use_xrender)
  1194     if (X11->use_xrender)
  1186         picture = XRenderCreatePicture(X11->display, hd,
  1195         picture = XRenderCreatePicture(X11->display, hd,
  1187                                        XRenderFindStandardFormat(X11->display, PictStandardA1), 0, 0);
  1196                                        XRenderFindStandardFormat(X11->display, PictStandardA1), 0, 0);
  1188 #endif // QT_NO_XRENDER
  1197 #endif // QT_NO_XRENDER
  1189 
       
  1190     if (tmp_bits)                                // Avoid purify complaint
       
  1191         delete [] tmp_bits;
       
  1192 }
  1198 }
  1193 
  1199 
  1194 void QX11PixmapData::fill(const QColor &fillColor)
  1200 void QX11PixmapData::fill(const QColor &fillColor)
  1195 {
  1201 {
  1196     if (fillColor.alpha() != 255) {
  1202     if (fillColor.alpha() != 255) {