Skip to content

Commit

Permalink
Add support for other color spaces
Browse files Browse the repository at this point in the history
Currently, the writer refuses to encode images that aren't in the
RGB color space. This change allows for images in other color
spaces to be accepted. They are first converted to RGB then
encoded.
  • Loading branch information
kadensharpin committed Dec 16, 2023
1 parent e16df3a commit 535a33f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ public open class WebPImageWriterSpi :
return false
}
}
val colorSpace = colorModel.colorSpace
if (!colorSpace.isCS_sRGB) {
return false
}
val sampleSize = sampleModel.sampleSize
for (i in sampleSize.indices) {
if (sampleSize[i] > 8) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ internal class WebPWriter(originatingProvider: ImageWriterSpi?) : ImageWriter(or
val width = aRi.width
val height = aRi.height
val colorModel = aRi.colorModel
return if (colorModel is ComponentColorModel) {
val colorSpace = colorModel.colorSpace
return if (colorSpace.isCS_sRGB && colorModel is ComponentColorModel) {
val sampleModel = aRi.sampleModel as ComponentSampleModel
when (sampleModel.transferType) {
DataBuffer.TYPE_BYTE -> extractComponentRGBByte(
Expand All @@ -116,7 +117,7 @@ internal class WebPWriter(originatingProvider: ImageWriterSpi?) : ImageWriter(or

else -> throw IOException("Incompatible image: $aRi")
}
} else if (colorModel is DirectColorModel) {
} else if (colorSpace.isCS_sRGB && colorModel is DirectColorModel) {
val sampleModel = aRi.sampleModel as SinglePixelPackedSampleModel
val type = sampleModel.transferType
if (type == DataBuffer.TYPE_INT) {
Expand Down

0 comments on commit 535a33f

Please sign in to comment.