src/plugins/gfxdrivers/directfb/qdirectfbpixmap.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 33 3e2da88830cd
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
   172 
   172 
   173 #ifdef QT_DIRECTFB_IMAGEPROVIDER
   173 #ifdef QT_DIRECTFB_IMAGEPROVIDER
   174 bool QDirectFBPixmapData::fromFile(const QString &filename, const char *format,
   174 bool QDirectFBPixmapData::fromFile(const QString &filename, const char *format,
   175                                    Qt::ImageConversionFlags flags)
   175                                    Qt::ImageConversionFlags flags)
   176 {
   176 {
       
   177     if (!QFile::exists(filename))
       
   178         return false;
   177     if (flags == Qt::AutoColor) {
   179     if (flags == Qt::AutoColor) {
   178         if (filename.startsWith(QLatin1Char(':'))) { // resource
   180         if (filename.startsWith(QLatin1Char(':'))) { // resource
   179             QFile file(filename);
   181             QFile file(filename);
   180             if (!file.open(QIODevice::ReadOnly))
   182             if (!file.open(QIODevice::ReadOnly))
   181                 return false;
   183                 return false;
   286 #endif
   288 #endif
   287 
   289 
   288 void QDirectFBPixmapData::fromImage(const QImage &img,
   290 void QDirectFBPixmapData::fromImage(const QImage &img,
   289                                     Qt::ImageConversionFlags flags)
   291                                     Qt::ImageConversionFlags flags)
   290 {
   292 {
   291     if (img.depth() == 1 || img.format() == QImage::Format_RGB32) {
   293     if (img.depth() == 1) {
   292         fromImage(img.convertToFormat(screen->alphaPixmapFormat()), flags);
   294         alpha = true;
   293         return;
       
   294     }
       
   295 
       
   296     if (img.hasAlphaChannel()
       
   297 #ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION
   295 #ifndef QT_NO_DIRECTFB_OPAQUE_DETECTION
   298         && (flags & Qt::NoOpaqueDetection || QDirectFBPixmapData::hasAlphaChannel(img))
   296     } else if (flags & Qt::NoOpaqueDetection || QDirectFBPixmapData::hasAlphaChannel(img)) {
   299 #endif
       
   300         ) {
       
   301         alpha = true;
   297         alpha = true;
   302         imageFormat = screen->alphaPixmapFormat();
   298 #else
   303     } else {
   299     } else if (img.hasAlphaChannel()) {
   304         alpha = false;
   300         alpha = true;
   305         imageFormat = screen->pixelFormat();
   301 #endif
   306     }
   302     }
       
   303     imageFormat = alpha ? screen->alphaPixmapFormat() : screen->pixelFormat();
   307     QImage image;
   304     QImage image;
   308     if (flags != Qt::AutoColor) {
   305     if ((flags & ~Qt::NoOpaqueDetection) != Qt::AutoColor) {
   309         image = img.convertToFormat(imageFormat, flags);
   306         image = img.convertToFormat(imageFormat, flags);
   310         flags = Qt::AutoColor;
   307         flags = Qt::AutoColor;
   311     } else if (img.format() == QImage::Format_RGB32) {
   308     } else if (img.format() == QImage::Format_RGB32 || img.depth() == 1) {
   312         image = img.convertToFormat(imageFormat, flags);
   309         image = img.convertToFormat(imageFormat, flags);
   313     } else {
   310     } else {
   314         image = img;
   311         image = img;
   315     }
   312     }
   316 
   313 
   423     if (!serialNumber())
   420     if (!serialNumber())
   424         return;
   421         return;
   425 
   422 
   426     Q_ASSERT(dfbSurface);
   423     Q_ASSERT(dfbSurface);
   427 
   424 
   428     alpha = (color.alpha() < 255);
   425     alpha |= (color.alpha() < 255);
   429 
   426 
   430     if (alpha && isOpaqueFormat(imageFormat)) {
   427     if (alpha && isOpaqueFormat(imageFormat)) {
   431         QSize size;
   428         QSize size;
   432         dfbSurface->GetSize(dfbSurface, &size.rwidth(), &size.rheight());
   429         dfbSurface->GetSize(dfbSurface, &size.rwidth(), &size.rheight());
   433         screen->releaseDFBSurface(dfbSurface);
   430         screen->releaseDFBSurface(dfbSurface);