90 \fn HbPixmapIconProcessor::sharedIconData() |
90 \fn HbPixmapIconProcessor::sharedIconData() |
91 Copies the pixmap raster data to the shared memory |
91 Copies the pixmap raster data to the shared memory |
92 */ |
92 */ |
93 HbSharedIconInfo HbPixmapIconProcessor::sharedIconData()const |
93 HbSharedIconInfo HbPixmapIconProcessor::sharedIconData()const |
94 { |
94 { |
95 HbSharedIconInfo data; |
|
96 data.type = INVALID_FORMAT; |
|
97 const QImage image = pixmap.toImage(); |
95 const QImage image = pixmap.toImage(); |
98 |
96 |
99 if (!image.isNull()) { |
97 if (!image.isNull() && (data.type == INVALID_FORMAT)) { |
100 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
98 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
101 try { |
99 try { |
102 //alloc function of memory manager can throw |
100 //alloc function of memory manager can throw |
103 data.pixmapData.offset = manager->alloc(image.numBytes()); |
101 data.pixmapData.offset = manager->alloc(image.numBytes()); |
104 data.type = OTHER_SUPPORTED_FORMATS; |
102 data.type = OTHER_SUPPORTED_FORMATS; |
158 } |
156 } |
159 |
157 |
160 return isIconCreated; |
158 return isIconCreated; |
161 } |
159 } |
162 |
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 |
163 /*! |
201 /*! |
164 \fn HbPixmapIconProcessor::renderSvgToPixmap() |
202 \fn HbPixmapIconProcessor::renderSvgToPixmap() |
165 \a iconpath |
203 \a iconpath |
166 */ |
204 */ |
167 bool HbPixmapIconProcessor::renderSvgToPixmap(const QString& iconPath) |
205 bool HbPixmapIconProcessor::renderSvgToPixmap(const QString& iconPath) |
338 |
376 |
339 |
377 |
340 for (int i = 0; i < multiPieceIconParams.multiPartIconList.count(); i++) { |
378 for (int i = 0; i < multiPieceIconParams.multiPartIconList.count(); i++) { |
341 #if defined (HB_NVG_CS_ICON) |
379 #if defined (HB_NVG_CS_ICON) |
342 if ((multiPieceIconInfo[i].type != INVALID_FORMAT) && multiPieceIconInfo[i].type == NVG) { |
380 if ((multiPieceIconInfo[i].type != INVALID_FORMAT) && multiPieceIconInfo[i].type == NVG) { |
|
381 QPixmap tempPixmap; |
343 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
382 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
344 const QByteArray nvgData = QByteArray::fromRawData((char*)manager->base() + multiPieceIconInfo[i].nvgData.offset, |
383 const QByteArray nvgData = QByteArray::fromRawData((char*)manager->base() + multiPieceIconInfo[i].nvgData.offset, |
345 multiPieceIconInfo[i].nvgData.dataSize); |
384 multiPieceIconInfo[i].nvgData.dataSize); |
346 QSize contentSize = QSize(multiPieceIconInfo[i].nvgData.width, multiPieceIconInfo[i].nvgData.height); |
385 QSize contentSize = QSize(multiPieceIconInfo[i].nvgData.width, multiPieceIconInfo[i].nvgData.height); |
347 |
386 HbNvgRasterizer * nvgRasterizer = HbNvgRasterizer::global(); |
348 if(pixmapFromByteArray(nvgData, contentSize, (Qt::AspectRatioMode)multiPieceIconParams.aspectRatioMode)) { |
387 |
349 painter.drawPixmap(multiPieceIconParams.multiPartIconData.targets[i].topLeft(), pixmap, pixmap.rect()); |
388 QImage image = tempPixmap.toImage(); |
|
389 if(nvgRasterizer->rasterize(nvgData, contentSize, |
|
390 (Qt::AspectRatioMode)multiPieceIconParams.aspectRatioMode, |
|
391 image)) { |
|
392 painter.drawPixmap( |
|
393 multiPieceIconParams.multiPartIconData.targets[i].topLeft(), |
|
394 tempPixmap, |
|
395 tempPixmap.rect()); |
350 } else { |
396 } else { |
351 // consolidated pixmap creation falied. |
397 // consolidated pixmap creation falied. |
352 painter.end(); |
398 painter.end(); |
353 return false; |
399 return false; |
354 } |
400 } |
355 } else { |
401 } else { |
356 #endif |
402 #endif |
357 if ((multiPieceIconInfo[i].type != INVALID_FORMAT) && multiPieceIconInfo[i].type == OTHER_SUPPORTED_FORMATS) { |
403 if ((multiPieceIconInfo[i].type != INVALID_FORMAT) && multiPieceIconInfo[i].type == OTHER_SUPPORTED_FORMATS) { |
358 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
404 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
359 QImage image((const uchar*) |
405 QImage image((const uchar*) |
360 ((char *)manager->base() + multiPieceIconInfo[i].pixmapData.offset), |
406 ((char *)manager->base() + multiPieceIconInfo[i].pixmapData.offset), |
361 multiPieceIconParams.multiPartIconData.pixmapSizes[i].width(), |
407 multiPieceIconParams.multiPartIconData.pixmapSizes[i].width(), |
362 multiPieceIconParams.multiPartIconData.pixmapSizes[i].height(), |
408 multiPieceIconParams.multiPartIconData.pixmapSizes[i].height(), |
363 multiPieceIconInfo[i].pixmapData.format); |
409 multiPieceIconInfo[i].pixmapData.format); |
364 |
410 |
365 QPixmap pixmap = QPixmap::fromImage((image)); |
411 QPixmap pixmap = QPixmap::fromImage((image)); |
366 painter.drawPixmap(multiPieceIconParams.multiPartIconData.targets[i].topLeft(), pixmap, pixmap.rect()); |
412 painter.drawPixmap(multiPieceIconParams.multiPartIconData.targets[i].topLeft(), pixmap, pixmap.rect()); |
367 } |
413 } |
368 #if defined (HB_NVG_CS_ICON) |
414 #if defined (HB_NVG_CS_ICON) |
369 } |
415 } |
370 #endif |
416 #endif |
378 } |
424 } |
379 setPixmap(finalPixmap); |
425 setPixmap(finalPixmap); |
380 return true; |
426 return true; |
381 } |
427 } |
382 |
428 |
383 #if defined (HB_NVG_CS_ICON) |
429 |
384 |
430 |
385 VGIColorBufferFormat HbPixmapIconProcessor::mapToVgiDisplayFormat( QImage::Format imageFormat ) const |
431 |
386 { |
|
387 VGIColorBufferFormat format; |
|
388 switch(imageFormat) |
|
389 { |
|
390 case QImage::Format_Mono: |
|
391 case QImage::Format_RGB32: |
|
392 case QImage::Format_ARGB32: |
|
393 format = VGI_COLOR_BUFFER_FORMAT_ARGB8888; |
|
394 break; |
|
395 case QImage::Format_ARGB32_Premultiplied: |
|
396 format = VGI_COLOR_BUFFER_FORMAT_ARGB8888_PRE; |
|
397 break; |
|
398 case QImage::Format_RGB16: |
|
399 case QImage::Format_ARGB8565_Premultiplied: |
|
400 case QImage::Format_RGB666: |
|
401 case QImage::Format_ARGB6666_Premultiplied: |
|
402 case QImage::Format_RGB555: |
|
403 case QImage::Format_ARGB8555_Premultiplied: |
|
404 break; |
|
405 case QImage::Format_RGB888: |
|
406 format = VGI_COLOR_BUFFER_FORMAT_RGB888; |
|
407 break; |
|
408 case QImage::Format_RGB444: |
|
409 case QImage::Format_ARGB4444_Premultiplied: |
|
410 case QImage::Format_Invalid: |
|
411 break; |
|
412 } |
|
413 return format; |
|
414 } |
|
415 |
|
416 /** |
|
417 * HbNvgIconProcessor::renderNvgToPixmap() |
|
418 * This is used to render NVG data to a pixmap using the Software OpenVG |
|
419 * \a iconPath |
|
420 */ |
|
421 bool HbPixmapIconProcessor::renderNvgToPixmap(const QString& iconPath) |
|
422 { |
|
423 bool isIconCreated = false; |
|
424 |
|
425 bool isDefaultSize = iconKey.size.isNull(); |
|
426 HbIconSource *source = HbThemeServerUtils::getIconSource(iconPath); |
|
427 QByteArray *sourceByteArray = source->byteArray(); |
|
428 if( !sourceByteArray ) { |
|
429 return isIconCreated; |
|
430 } |
|
431 QByteArray byteArray = *sourceByteArray; |
|
432 QSizeF renderSize = source->defaultSize(); |
|
433 defaultSize = renderSize.toSize(); |
|
434 if (!isDefaultSize) { |
|
435 renderSize.scale(iconKey.size,iconKey.aspectRatioMode); |
|
436 } |
|
437 size = renderSize.toSize(); |
|
438 |
|
439 isIconCreated = pixmapFromByteArray(byteArray, size, iconKey.aspectRatioMode); |
|
440 |
|
441 return isIconCreated; |
|
442 } |
|
443 |
|
444 /** |
|
445 * HbNvgIconProcessor::pixmapFromByteArray() |
|
446 * This is used to get the pixmap from ByteArray |
|
447 * \a iconPath |
|
448 */ |
|
449 bool HbPixmapIconProcessor::pixmapFromByteArray(const QByteArray &byteArray, |
|
450 const QSize iconSize, |
|
451 Qt::AspectRatioMode aspectRatioMode) |
|
452 { |
|
453 bool isIconCreated = false; |
|
454 |
|
455 CNvgEngine* nvgengine = 0; |
|
456 TRAPD(error, nvgengine = CNvgEngine::NewL()); |
|
457 if (error != KErrNone) { |
|
458 return isIconCreated; |
|
459 } |
|
460 QScopedPointer<CNvgEngine> nvgEngine(nvgengine); |
|
461 |
|
462 TSize surfaceSize(TSize(iconSize.width(), iconSize.height())); |
|
463 |
|
464 QImage img(iconSize,QImage::Format_ARGB32_Premultiplied); |
|
465 |
|
466 VGIColorBufferFormat format; |
|
467 TInt stride = img.bytesPerLine(); |
|
468 TUint8* imageBuffer = img.bits(); // get the pointer to image buffer. |
|
469 // Map Qimage display modes to the VGI display modes. |
|
470 format = mapToVgiDisplayFormat(img.format()); |
|
471 |
|
472 |
|
473 HbNvgAspectRatioSettings settings = mapKeyAspectRatioToNvgAspectRatio(aspectRatioMode); |
|
474 nvgEngine.data()->SetPreserveAspectRatio(settings.nvgAlignStatusAndAspectRatio, settings.type); |
|
475 |
|
476 // Surface creation |
|
477 TInt err = VGISymbianInitialize( surfaceSize, VGI_COLORSPACE_SRGB ); |
|
478 if( err == KErrAlreadyExists ) { |
|
479 //Clean Up |
|
480 VGISymbianTerminate(); |
|
481 // Surface creation |
|
482 err = VGISymbianInitialize( surfaceSize, VGI_COLORSPACE_SRGB ); |
|
483 } |
|
484 if( err != KErrNone) { |
|
485 return isIconCreated; |
|
486 } |
|
487 |
|
488 // Rendering onto active surface |
|
489 TPtr8 data ((unsigned char*)byteArray.data(), byteArray.length(), byteArray.length()); |
|
490 err = nvgEngine.data()->DrawNvg(data, surfaceSize, 0, 0); |
|
491 if(err !=KErrNone) { |
|
492 return isIconCreated; |
|
493 } |
|
494 |
|
495 //Copy the data from the surface |
|
496 err = VGICopyToTarget(format, stride, imageBuffer, 0, NULL, VGI_COPY_TRANSPARENT_PIXELS); |
|
497 #ifdef __DEBUG |
|
498 qDebug() << "error code for VGICopyToTarget()"<< err; |
|
499 #endif |
|
500 //Get Pixmap from the Qimage. |
|
501 pixmap = QPixmap::fromImage(img); |
|
502 isIconCreated = true; |
|
503 |
|
504 //Clean Up |
|
505 VGISymbianTerminate(); |
|
506 return isIconCreated; |
|
507 } |
|
508 |
|
509 /*! |
|
510 \fn HbPixmapIconProcessor::mapKeyAspectRatioToNvgAspectRatio() |
|
511 \a aspectRatio |
|
512 */ |
|
513 HbNvgAspectRatioSettings HbPixmapIconProcessor::mapKeyAspectRatioToNvgAspectRatio( |
|
514 Qt::AspectRatioMode aspectRatio) const |
|
515 { |
|
516 HbNvgAspectRatioSettings settings; |
|
517 switch(aspectRatio) { |
|
518 |
|
519 case Qt::IgnoreAspectRatio: { |
|
520 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_None; |
|
521 settings.type = ENvgMeet; |
|
522 break; |
|
523 } |
|
524 case Qt::KeepAspectRatio: { |
|
525 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_XmidYmid; |
|
526 settings.type = ENvgMeet; |
|
527 break; |
|
528 } |
|
529 case Qt::KeepAspectRatioByExpanding: { |
|
530 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_XmidYmid; |
|
531 settings.type = ENvgSlice; |
|
532 break; |
|
533 } |
|
534 default: { |
|
535 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_XmidYmid; |
|
536 settings.type = ENvgMeet; |
|
537 break; |
|
538 } |
|
539 } |
|
540 return settings; |
|
541 } |
|
542 #endif //HB_NVG_CS_ICON |
|
543 |
|