Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 3 TIFF compression modes #2970

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions backend/src/packages/chaiNNer_standard/image/io/save_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ class TiffColorDepth(Enum):
F32 = "f32"


class TiffCompression(Enum):
NONE = 1
LZW = 5
ZIP = 8

@property
def cv2_code(self) -> int:
# OpenCV is a beautiful piece of software, so surely they won't forget to define the TIFF compression constants, right?
return self.value


SUPPORTED_DDS_FORMATS: list[tuple[DDSFormat, str]] = [
("BC1_UNORM_SRGB", "BC1 (4bpp, sRGB, 1-bit Alpha)"),
("BC1_UNORM", "BC1 (4bpp, Linear, 1-bit Alpha)"),
Expand Down Expand Up @@ -232,6 +243,18 @@ def DdsMipMapsDropdown() -> DropDownInput:
TiffColorDepth.F32: "32 Bits/Channel (Float)",
},
).with_id(16),
if_enum_group(16, (TiffColorDepth.U8, TiffColorDepth.U16))(
EnumInput(
TiffCompression,
"Compression",
default=TiffCompression.LZW,
option_labels={
TiffCompression.NONE: "None",
TiffCompression.LZW: "LZW (lossless)",
TiffCompression.ZIP: "ZIP (lossless)",
},
).with_id(18),
),
),
if_enum_group(4, ImageFormat.DDS)(
DdsFormatDropdown().with_id(6),
Expand Down Expand Up @@ -302,6 +325,7 @@ def save_image_node(
jpeg_chroma_subsampling: JpegSubsampling,
jpeg_progressive: bool,
tiff_color_depth: TiffColorDepth,
tiff_compression: TiffCompression,
dds_format: DDSFormat,
dds_bc7_compression: BC7Compression,
dds_error_metric: DDSErrorMetric,
Expand Down Expand Up @@ -386,6 +410,10 @@ def save_image_node(
]
elif image_format == ImageFormat.WEBP:
params = [cv2.IMWRITE_WEBP_QUALITY, 101 if webp_lossless else quality]
elif (
image_format == ImageFormat.TIFF and tiff_color_depth != TiffColorDepth.F32
):
params = [cv2.IMWRITE_TIFF_COMPRESSION, tiff_compression.cv2_code]
else:
params = []

Expand Down
Loading