Repository: rasterio/rasterio

Issue:
YCbCr JPEG-in-TIFF breaks rio-info
One creates a YCbCr JPEG-in-TIFF with GDAL using `photometric=YCbCr` and `compress=JPEG` options. But reading the TIFFs tags to get the compression method returns "YCbCr JPEG", a value that's not in `rasterio.enums.Compression`.

Reference: http://www.gdal.org/frmt_gtiff.html

Solution: normalize "YCbCr JPEG" to "JPEG" and add source color space to rio-info's output.



Discussion:

Resolving patch:
diff --git a/rasterio/enums.py b/rasterio/enums.py
--- a/rasterio/enums.py
+++ b/rasterio/enums.py
@@ -18,6 +18,9 @@ class ColorInterp(IntEnum):
     magenta=11
     yellow=12
     black=13
+    Y=14
+    Cb=15
+    Cr=16
 
 
 class Resampling(Enum):
@@ -53,3 +56,14 @@ class MaskFlags(IntEnum):
     per_dataset=2
     alpha=4
     nodata=8
+
+
+class PhotometricInterp(Enum):
+    black='MINISBLACK'
+    white='MINISWHITE'
+    rgb='RGB'
+    cmyk='CMYK'
+    ycbcr='YCbCr'
+    cielab='CIELAB'
+    icclab='ICCLAB'
+    itulab='ITULAB'


Test patch:
diff --git a/tests/test_colorinterp.py b/tests/test_colorinterp.py
--- a/tests/test_colorinterp.py
+++ b/tests/test_colorinterp.py
@@ -1,25 +1,52 @@
+import pytest
 
 import rasterio
-from rasterio.enums import ColorInterp
+from rasterio.enums import ColorInterp, PhotometricInterp
 
 
-def test_colorinterp(tmpdir):
-    
+def test_cmyk_interp(tmpdir):
+    """A CMYK TIFF has cyan, magenta, yellow, black bands."""
     with rasterio.drivers():
-
         with rasterio.open('tests/data/RGB.byte.tif') as src:
-            assert src.colorinterp(1) == ColorInterp.red
-            assert src.colorinterp(2) == ColorInterp.green
-            assert src.colorinterp(3) == ColorInterp.blue
-            
-        tiffname = str(tmpdir.join('foo.tif'))
-        
-        meta = src.meta
+            meta = src.meta
         meta['photometric'] = 'CMYK'
         meta['count'] = 4
+        tiffname = str(tmpdir.join('foo.tif'))
         with rasterio.open(tiffname, 'w', **meta) as dst:
+            assert dst.profile['photometric'] == 'cmyk'
             assert dst.colorinterp(1) == ColorInterp.cyan
             assert dst.colorinterp(2) == ColorInterp.magenta
             assert dst.colorinterp(3) == ColorInterp.yellow
             assert dst.colorinterp(4) == ColorInterp.black
 
+
+def test_ycbcr_interp(tmpdir):
+    """A YCbCr TIFF has red, green, blue bands."""
+    with rasterio.drivers():
+        with rasterio.open('tests/data/RGB.byte.tif') as src:
+            meta = src.meta
+        meta['photometric'] = 'ycbcr'
+        meta['compress'] = 'jpeg'
+        meta['count'] = 3
+        tiffname = str(tmpdir.join('foo.tif'))
+        with rasterio.open(tiffname, 'w', **meta) as dst:
+            assert dst.colorinterp(1) == ColorInterp.red
+            assert dst.colorinterp(2) == ColorInterp.green
+            assert dst.colorinterp(3) == ColorInterp.blue
+
+
+@pytest.mark.xfail()
+def test_ycbcr_no_convert(tmpdir):
+    """An unconverted YCbCr TIFF has Y, Cb, Cr bands."""
+    with rasterio.drivers(GDAL_JPEG_TO_RGB=False):
+        with rasterio.open('tests/data/RGB.byte.tif') as src:
+            meta = src.meta
+        meta['photometric'] = 'ycbcr'
+        meta['compress'] = 'jpeg'
+        meta['count'] = 3
+        tiffname = str(tmpdir.join('foo.tif'))
+        with rasterio.open(tiffname, 'w', **meta) as dst:
+            assert dst.profile['photometric'] == 'ycbcr'
+            assert dst.colorinterp(1) == ColorInterp.Y
+            assert dst.colorinterp(2) == ColorInterp.Cb
+            assert dst.colorinterp(3) == ColorInterp.Cr