139 QTransform t; |
137 QTransform t; |
140 t.scale(-1, 1); |
138 t.scale(-1, 1); |
141 pixmap = pixmap.transformed(t); |
139 pixmap = pixmap.transformed(t); |
142 } |
140 } |
143 |
141 |
|
142 // Apply color if valid |
|
143 if (iconKey.color.isValid()) { |
|
144 if (!pixmap.isNull()) { |
|
145 QPixmap mask = pixmap.alphaChannel(); |
|
146 pixmap.fill(iconKey.color); |
|
147 pixmap.setAlphaChannel(mask); |
|
148 } |
|
149 } |
144 // Apply mode |
150 // Apply mode |
145 if (iconKey.mode != QIcon::Normal) { |
151 if (iconKey.mode != QIcon::Normal) { |
146 QStyleOption opt(0); |
152 QStyleOption opt(0); |
147 opt.palette = QApplication::palette(); |
153 opt.palette = QApplication::palette(); |
148 pixmap = QApplication::style()->generatedIconPixmap(iconKey.mode, pixmap, &opt); |
154 pixmap = QApplication::style()->generatedIconPixmap(iconKey.mode, pixmap, &opt); |
149 } |
155 } |
150 /* Apply color if valid*/ |
|
151 |
|
152 if (iconKey.color.isValid() && (iconKey.mode != QIcon::Disabled)) { |
|
153 if (!pixmap.isNull()) { |
|
154 QPixmap mask = pixmap.alphaChannel(); |
|
155 pixmap.fill(iconKey.color); |
|
156 pixmap.setAlphaChannel(mask); |
|
157 } |
|
158 } |
|
159 } |
156 } |
160 |
157 |
161 return isIconCreated; |
158 return isIconCreated; |
162 } |
159 } |
163 |
160 |
|
161 #if defined (HB_NVG_CS_ICON) |
|
162 |
|
163 bool HbPixmapIconProcessor::renderNvgToPixmap(const QString& iconPath) |
|
164 { |
|
165 bool success = false; |
|
166 HbNvgRasterizer * nvgRasterizer = HbNvgRasterizer::global(); |
|
167 |
|
168 bool isDefaultSize = iconKey.size.isNull(); |
|
169 HbIconSource *source = HbThemeServerUtils::getIconSource(iconPath); |
|
170 if (!source) { |
|
171 return success; |
|
172 } |
|
173 QByteArray *sourceByteArray = source->byteArray(); |
|
174 if( !sourceByteArray ) { |
|
175 return success; |
|
176 } |
|
177 QByteArray nvgArray = *sourceByteArray; |
|
178 QSizeF renderSize = source->defaultSize(); |
|
179 defaultSize = renderSize.toSize(); |
|
180 if (!isDefaultSize) { |
|
181 renderSize.scale(iconKey.size,iconKey.aspectRatioMode); |
|
182 } |
|
183 |
|
184 QSize iconSize = renderSize.toSize(); |
|
185 |
|
186 QImage image(iconSize, QImage::Format_ARGB32_Premultiplied); |
|
187 QImage::Format imageFormat = image.format(); |
|
188 image.fill(0); |
|
189 |
|
190 int stride = image.bytesPerLine(); |
|
191 void * rasterizedData = image.bits(); |
|
192 success = nvgRasterizer->rasterize(nvgArray, iconSize, |
|
193 iconKey.aspectRatioMode, |
|
194 rasterizedData, stride,imageFormat); |
|
195 |
|
196 pixmap = QPixmap::fromImage(image); |
|
197 return success; |
|
198 } |
|
199 |
|
200 #endif |
164 /*! |
201 /*! |
165 \fn HbPixmapIconProcessor::renderSvgToPixmap() |
202 \fn HbPixmapIconProcessor::renderSvgToPixmap() |
166 \a iconpath |
203 \a iconpath |
167 */ |
204 */ |
168 bool HbPixmapIconProcessor::renderSvgToPixmap(const QString& iconPath) |
205 bool HbPixmapIconProcessor::renderSvgToPixmap(const QString& iconPath) |
337 QPainter painter; |
374 QPainter painter; |
338 painter.begin(&finalPixmap); |
375 painter.begin(&finalPixmap); |
339 |
376 |
340 |
377 |
341 for (int i = 0; i < multiPieceIconParams.multiPartIconList.count(); i++) { |
378 for (int i = 0; i < multiPieceIconParams.multiPartIconList.count(); i++) { |
342 |
379 #if defined (HB_NVG_CS_ICON) |
343 if ((multiPieceIconInfo[i].type != INVALID_FORMAT) && multiPieceIconInfo[i].type == OTHER_SUPPORTED_FORMATS) { |
380 if ((multiPieceIconInfo[i].type != INVALID_FORMAT) && multiPieceIconInfo[i].type == NVG) { |
344 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
381 |
345 QImage image((const uchar*) |
382 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
|
383 const QByteArray nvgData = QByteArray::fromRawData((char*)manager->base() + multiPieceIconInfo[i].nvgData.offset, |
|
384 multiPieceIconInfo[i].nvgData.dataSize); |
|
385 QSize contentSize = QSize(multiPieceIconInfo[i].nvgData.width, multiPieceIconInfo[i].nvgData.height); |
|
386 HbNvgRasterizer * nvgRasterizer = HbNvgRasterizer::global(); |
|
387 |
|
388 QImage image(contentSize, QImage::Format_ARGB32_Premultiplied); |
|
389 if(nvgRasterizer->rasterize(nvgData, contentSize, |
|
390 (Qt::AspectRatioMode)multiPieceIconParams.aspectRatioMode, |
|
391 image)) { |
|
392 QPixmap tempPixmap = QPixmap::fromImage(image); |
|
393 painter.drawPixmap( |
|
394 multiPieceIconParams.multiPartIconData.targets[i].topLeft(), |
|
395 tempPixmap, |
|
396 tempPixmap.rect()); |
|
397 } else { |
|
398 // consolidated pixmap creation falied. |
|
399 painter.end(); |
|
400 return false; |
|
401 } |
|
402 } else { |
|
403 #endif |
|
404 if ((multiPieceIconInfo[i].type != INVALID_FORMAT) && multiPieceIconInfo[i].type == OTHER_SUPPORTED_FORMATS) { |
|
405 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
|
406 QImage image((const uchar*) |
346 ((char *)manager->base() + multiPieceIconInfo[i].pixmapData.offset), |
407 ((char *)manager->base() + multiPieceIconInfo[i].pixmapData.offset), |
347 multiPieceIconParams.multiPartIconData.pixmapSizes[i].width(), |
408 multiPieceIconParams.multiPartIconData.pixmapSizes[i].width(), |
348 multiPieceIconParams.multiPartIconData.pixmapSizes[i].height(), |
409 multiPieceIconParams.multiPartIconData.pixmapSizes[i].height(), |
349 multiPieceIconInfo[i].pixmapData.format); |
410 multiPieceIconInfo[i].pixmapData.format); |
350 |
411 |
351 QPixmap pixmap = QPixmap::fromImage((image)); |
412 QPixmap pixmap = QPixmap::fromImage((image)); |
352 painter.drawPixmap(multiPieceIconParams.multiPartIconData.targets[i].topLeft(), pixmap, pixmap.rect()); |
413 painter.drawPixmap(multiPieceIconParams.multiPartIconData.targets[i].topLeft(), pixmap, pixmap.rect()); |
353 } |
414 } |
|
415 #if defined (HB_NVG_CS_ICON) |
|
416 } |
|
417 #endif |
354 } |
418 } |
355 |
419 |
356 painter.end(); |
420 painter.end(); |
357 if (multiPieceIconParams.mirrored) { |
421 if (multiPieceIconParams.mirrored) { |
358 QTransform t; |
422 QTransform t; |
359 t.scale(-1, 1); |
423 t.scale(-1, 1); |
360 finalPixmap = finalPixmap.transformed(t); |
424 finalPixmap = finalPixmap.transformed(t); |
361 } |
425 } |
362 setPixmap(finalPixmap); |
426 setPixmap(finalPixmap); |
|
427 |
363 return true; |
428 return true; |
364 } |
429 } |
365 |
430 |
366 #if defined (HB_NVG_CS_ICON) |
431 |
367 |
432 |
368 VGIColorBufferFormat HbPixmapIconProcessor::mapToVgiDisplayFormat( QImage::Format imageFormat ) const |
433 |
369 { |
|
370 VGIColorBufferFormat format; |
|
371 switch(imageFormat) |
|
372 { |
|
373 case QImage::Format_Mono: |
|
374 case QImage::Format_RGB32: |
|
375 case QImage::Format_ARGB32: |
|
376 format = VGI_COLOR_BUFFER_FORMAT_ARGB8888; |
|
377 break; |
|
378 case QImage::Format_ARGB32_Premultiplied: |
|
379 format = VGI_COLOR_BUFFER_FORMAT_ARGB8888_PRE; |
|
380 break; |
|
381 case QImage::Format_RGB16: |
|
382 case QImage::Format_ARGB8565_Premultiplied: |
|
383 case QImage::Format_RGB666: |
|
384 case QImage::Format_ARGB6666_Premultiplied: |
|
385 case QImage::Format_RGB555: |
|
386 case QImage::Format_ARGB8555_Premultiplied: |
|
387 break; |
|
388 case QImage::Format_RGB888: |
|
389 format = VGI_COLOR_BUFFER_FORMAT_RGB888; |
|
390 break; |
|
391 case QImage::Format_RGB444: |
|
392 case QImage::Format_ARGB4444_Premultiplied: |
|
393 case QImage::Format_Invalid: |
|
394 break; |
|
395 } |
|
396 return format; |
|
397 } |
|
398 |
|
399 /** |
|
400 * HbNvgIconProcessor::renderNvgToPixmap() |
|
401 * This is used to render NVG data to a pixmap using the Software OpenVG |
|
402 * \a iconPath |
|
403 */ |
|
404 bool HbPixmapIconProcessor::renderNvgToPixmap(const QString& iconPath) |
|
405 { |
|
406 bool isIconCreated = false; |
|
407 |
|
408 CNvgEngine* nvgengine = 0; |
|
409 TRAPD(error, nvgengine = CNvgEngine::NewL()); |
|
410 if (error != KErrNone) { |
|
411 return isIconCreated; |
|
412 } |
|
413 QScopedPointer<CNvgEngine> nvgEngine(nvgengine); |
|
414 |
|
415 bool isDefaultSize = iconKey.size.isNull(); |
|
416 HbIconSource *source = HbThemeServerUtils::getIconSource(iconPath); |
|
417 QByteArray *sourceByteArray = source->byteArray(); |
|
418 if( !sourceByteArray ) { |
|
419 return false; |
|
420 } |
|
421 QByteArray byteArray = *sourceByteArray; |
|
422 QSizeF renderSize = source->defaultSize(); |
|
423 defaultSize = renderSize.toSize(); |
|
424 if (!isDefaultSize) { |
|
425 renderSize.scale(iconKey.size,iconKey.aspectRatioMode); |
|
426 } |
|
427 size = renderSize.toSize(); |
|
428 TSize surfaceSize(TSize(size.width(), size.height())); |
|
429 |
|
430 /* QImage img(size,QImage::Format_ARGB32_Premultiplied); |
|
431 |
|
432 VGIColorBufferFormat format; |
|
433 TInt stride = img.bytesPerLine(); |
|
434 TUint8* imageBuffer = img.bits(); // get the pointer to image buffer. |
|
435 // Map Qimage display modes to the VGI display modes. |
|
436 format = mapToVgiDisplayFormat(img.format()); |
|
437 qDebug()<<"Format = " <<format; */ |
|
438 |
|
439 QScopedPointer<CFbsBitmap> bitmapData(new CFbsBitmap()); |
|
440 |
|
441 TInt err = bitmapData.data()->Create(surfaceSize, EColor16MA); |
|
442 if(err != KErrNone) { |
|
443 return isIconCreated; |
|
444 } |
|
445 |
|
446 |
|
447 //Reset the surface incase already present |
|
448 VGISymbianTerminate(); |
|
449 |
|
450 // Surface creation |
|
451 /*TInt*/ err = VGISymbianInitialize( surfaceSize, VGI_COLORSPACE_SRGB ); |
|
452 if( err != KErrNone) { |
|
453 return isIconCreated; |
|
454 } |
|
455 |
|
456 HbNvgAspectRatioSettings settings = mapKeyAspectRatioToNvgAspectRatio(iconKey.aspectRatioMode); |
|
457 nvgEngine.data()->SetPreserveAspectRatio(settings.nvgAlignStatusAndAspectRatio, settings.type); |
|
458 // Rendering onto active surface |
|
459 TPtr8 data ((unsigned char*)byteArray.data(), byteArray.length(), byteArray.length()); |
|
460 err = nvgEngine.data()->DrawNvg(data, surfaceSize, 0, 0); |
|
461 if(err !=KErrNone) { |
|
462 return isIconCreated; |
|
463 } |
|
464 |
|
465 //Copy the data from the surface |
|
466 /* err = VGICopyToTarget(format, stride, imageBuffer, 0, NULL, VGI_COPY_TRANSPARENT_PIXELS); |
|
467 #ifdef __DEBUG |
|
468 qDebug() << "error code for VGICopyToTarget()"<< err; |
|
469 #endif |
|
470 //Get Pixmap from the Qimage. |
|
471 pixmap = QPixmap::fromImage(img); */ |
|
472 |
|
473 err = VGISymbianCopyToBitmap(bitmapData.data(), 0, VGI_COPY_TRANSPARENT_PIXELS); |
|
474 if(err !=KErrNone) { |
|
475 return isIconCreated; |
|
476 } |
|
477 //Get Pixmap from the Symbian Native format. |
|
478 pixmap = QPixmap::fromSymbianCFbsBitmap(bitmapData.data()); |
|
479 |
|
480 isIconCreated = true; |
|
481 |
|
482 //Clean Up |
|
483 VGISymbianTerminate(); |
|
484 return isIconCreated; |
|
485 } |
|
486 |
|
487 /*! |
|
488 \fn HbPixmapIconProcessor::mapKeyAspectRatioToNvgAspectRatio() |
|
489 \a aspectRatio |
|
490 */ |
|
491 HbNvgAspectRatioSettings HbPixmapIconProcessor::mapKeyAspectRatioToNvgAspectRatio( |
|
492 Qt::AspectRatioMode aspectRatio) const |
|
493 { |
|
494 HbNvgAspectRatioSettings settings; |
|
495 switch(aspectRatio) { |
|
496 |
|
497 case Qt::IgnoreAspectRatio: { |
|
498 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_None; |
|
499 settings.type = ENvgMeet; |
|
500 break; |
|
501 } |
|
502 case Qt::KeepAspectRatio: { |
|
503 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_XmidYmid; |
|
504 settings.type = ENvgMeet; |
|
505 break; |
|
506 } |
|
507 case Qt::KeepAspectRatioByExpanding: { |
|
508 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_XmidYmid; |
|
509 settings.type = ENvgSlice; |
|
510 break; |
|
511 } |
|
512 default: { |
|
513 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_XmidYmid; |
|
514 settings.type = ENvgMeet; |
|
515 break; |
|
516 } |
|
517 } |
|
518 return settings; |
|
519 } |
|
520 #endif //HB_NVG_CS_ICON |
|
521 |
|