Skip to content

Commit

Permalink
Merge pull request #18 from nomacs/color-format
Browse files Browse the repository at this point in the history
maps color format from HEIF to Qt (i.e. RGB88)
  • Loading branch information
jakar authored Jun 22, 2020
2 parents 671166e + 3288ae6 commit 3ab3539
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/qheifhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,31 @@ bool QHeifHandler::read(QImage* destImage)
qWarning("QHeifHandler::read() invalid stride: %d", stride);
return false;
}

// map image format
heif_chroma heifFormat = heif_image_get_chroma_format(srcImage.get());
QImage::Format qtFormat;

switch (heifFormat) {
case heif_chroma_interleaved_RGB: {
qtFormat = QImage::Format_RGB888;
break;
}
case heif_chroma_interleaved_RGBA: {
qtFormat = QImage::Format_RGBA8888;
break;
}
// TODO: add other formats i.e. heif_chroma_monochrome here
default:
qtFormat = QImage::Format_RGBA8888;
}

// move data ownership to QImage
heif_image* dataImage = srcImage.release();

*destImage = QImage(
data, imgSize.width(), imgSize.height(),
stride, QImage::Format_RGBA8888,
stride, qtFormat,
[](void* img) { heif_image_release(static_cast<heif_image*>(img)); },
dataImage
);
Expand Down

0 comments on commit 3ab3539

Please sign in to comment.