Changeset 342
- Timestamp:
- Nov 23, 2009, 11:35:40 PM (15 years ago)
- Location:
- trunk/src/gui/image
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/gui/image/qpixmap.h ¶
r267 r342 151 151 #if defined(Q_WS_PM) 152 152 HBITMAP toPmHBITMAP(HBITMAP *mask = 0, bool embedRealAlpha = false) const; 153 static QPixmap fromPmHBITMAP(HBITMAP hbm); 153 154 static HPOINTER toPmHPOINTER(const QIcon &icon, bool isPointer = false, 154 155 int hotX = 0, int hotY = 0, -
TabularUnified trunk/src/gui/image/qpixmap_pm.cpp ¶
r267 r342 115 115 116 116 \warning This function is only available on OS/2. 117 118 \sa fromPmHBITMAP(), toPmHPOINTER() 117 119 */ 118 120 HBITMAP QPixmap::toPmHBITMAP(HBITMAP *mask, bool embedRealAlpha) const … … 120 122 if (data->classId() != QPixmapData::RasterClass) { 121 123 QPixmapData *data = new QRasterPixmapData(depth() == 1 ? 122 QPixmapData::BitmapType : QPixmapData::PixmapType); 124 QPixmapData::BitmapType : 125 QPixmapData::PixmapType); 123 126 data->fromImage(toImage(), Qt::AutoColor); 124 return QPixmap(data).toPmHBITMAP(mask );127 return QPixmap(data).toPmHBITMAP(mask, embedRealAlpha); 125 128 } 126 129 … … 230 233 231 234 /*! 235 Returns a QPixmap that is equivalent to the given \a bitmap. 236 237 \warning This function is only available on OS/2. 238 239 \sa toPmHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} 240 241 */ 242 // static 243 QPixmap QPixmap::fromPmHBITMAP(HBITMAP hbm) 244 { 245 QPixmap res; 246 247 if (hbm == NULLHANDLE) 248 return res; 249 250 // bitmap header + 2 palette entries (for the monochrome bitmap) 251 char bmi[sizeof(BITMAPINFOHEADER2) + 4 * 2]; 252 memset(bmi, 0, sizeof(bmi)); 253 BITMAPINFOHEADER2 &bmh = *(PBITMAPINFOHEADER2)bmi; 254 bmh.cbFix = sizeof(BITMAPINFOHEADER2); 255 PULONG pal = (PULONG)(bmi + sizeof(BITMAPINFOHEADER2)); 256 257 if (!GpiQueryBitmapInfoHeader(hbm, &bmh)) 258 return res; 259 260 HPS hps = qt_alloc_mem_ps(bmh.cx, bmh.cy); 261 if (hps == NULLHANDLE) 262 return res; 263 264 GpiSetBitmap(hps, hbm); 265 266 QImage img; 267 bool succeeded = false; 268 269 if (bmh.cPlanes == 1 && bmh.cBitCount == 1) { 270 // monochrome bitmap 271 img = QImage(bmh.cx, bmh.cy, QImage::Format_Mono); 272 if (GpiQueryBitmapBits(hps, 0, bmh.cy, (PBYTE)img.bits(), 273 (PBITMAPINFO2)&bmi) != GPI_ALTERROR) { 274 succeeded = true; 275 // take the palette 276 QVector<QRgb> colors(2); 277 colors[0] = QRgb(pal[0]); 278 colors[1] = QRgb(pal[1]); 279 } 280 } else { 281 // always convert to 32-bit otherwise 282 img = QImage(bmh.cx, bmh.cy, QImage::Format_RGB32); 283 bmh.cPlanes = 1; 284 bmh.cBitCount = 32; 285 if (GpiQueryBitmapBits(hps, 0, bmh.cy, (PBYTE)img.bits(), 286 (PBITMAPINFO2)&bmi) != GPI_ALTERROR) { 287 succeeded = true; 288 // try to auto-detect if there is a real alpha channel 289 bool allZero = true; 290 for (int i = 0; i < img.numBytes(); ++i) { 291 if (img.bits()[i] & 0xFF000000) { 292 allZero = false; 293 break; 294 } 295 } 296 if (!allZero) { 297 // assume we've got the alpha channel 298 QImage alphaImg = QImage(bmh.cx, bmh.cy, QImage::Format_ARGB32); 299 memcpy(alphaImg.bits(), img.bits(), img.numBytes()); 300 img = alphaImg; 301 } 302 } 303 } 304 305 qt_free_mem_ps(hps); 306 307 if (succeeded) { 308 // flip the bitmap top to bottom to cancel PM inversion 309 img = img.mirrored(); 310 res = QPixmap::fromImage(img); 311 } 312 313 return res; 314 } 315 316 /*! 232 317 Creates a \c HPOINTER from the given QIcon. Returns the \c HPOINTER handle. 233 318 … … 252 337 253 338 \warning This function is only available on OS/2. 339 340 \sa toPmHBITMAP() 254 341 */ 255 342 // static
Note:
See TracChangeset
for help on using the changeset viewer.