Skip to content

1.4.3 release changed compression in dataset profile to "YCbCr JPEG" which is not a valid compression type for GDAL #3311

@trharris78

Description

@trharris78

Expected behavior and actual behavior.

With rasterio==1.4.2, this code to use the profile of one dataset to create another worked just fine:

import rasterio
with rasterio.open("input.tif", "r") as src:
    profile = src.profile
# profile["compress"] == "jpeg" and profile["photometric"] == "ycbcr"
with rasterio.open("output.tif", "w", **profile) as dst:
    pass
# no error

It looks like #3259 changed the behavior (which caused cogeotiff/rio-cogeo#299, fixed by cogeotiff/rio-cogeo#300) such that the value of profile["compress"] is no longer valid for these types of JPEGs.

import rasterio
with rasterio.open("input.tif", "r") as src:
    profile = src.profile
# profile["compress"] == "YCbCr JPEG" and profile["photometric"] == "ycbcr"
with rasterio.open("output.tif", "w", **profile) as dst:
    pass
# throws exception:
# CPLE_NotSupportedError: output.tif: Currently, PHOTOMETRIC=YCBCR requires COMPRESS=JPEG

It seems to be confused by the value in profile["compress"] because the only value there that makes sense is "JPEG", as long as profile["photometric"] is set to ycbcr.

Steps to reproduce the problem.

Create an example TIF with JPEG compression using the YCbCr color space:

rio create -f GTiff -n 3 -h 100 -w 100 -t uint8 --co COMPRESS=JPEG --co PHOTOMETRIC=YCBCR input.tif

Then try to use the profile of that TIF to create another TIF:

import rasterio
with rasterio.open("input.tif", "r") as src:
    profile = src.profile
# profile["compress"] == "YCbCr JPEG" and profile["photometric"] == "ycbcr"
with rasterio.open("output.tif", "w", **profile) as dst:
    pass
# throws exception:
# CPLE_NotSupportedError: output.tif: Currently, PHOTOMETRIC=YCBCR requires COMPRESS=JPEG

Environment Information

Output from rio --show-versions:

rasterio info:
  rasterio: 1.4.3
      GDAL: 3.10.1
      PROJ: 9.5.1
      GEOS: 3.12.1
 PROJ DATA: /root/.local/share/proj:/usr/local/share/proj:/usr/local/share/proj
 GDAL DATA: None

System:
    python: 3.12.3 (main, Nov  6 2024, 18:32:19) [GCC 13.2.0]
executable: /usr/bin/python3
   machine: Linux-5.15.167-112.166.amzn2.x86_64-x86_64-with-glibc2.39

Python deps:
    affine: 2.4.0
     attrs: 25.1.0
   certifi: 2025.01.31
     click: 8.1.8
     cligj: 0.7.2
    cython: 3.0.12
     numpy: 1.26.4
click-plugins: None
setuptools: None

Installation Method

Pip installed rasterio in the base GDAL Docker image ghcr.io/osgeo/gdal:ubuntu-small-3.10.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions