geotiffjs / geotiff.js

geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.
https://geotiffjs.github.io/
MIT License
859 stars 179 forks source link

Bug: GeoTIFF compressed with WEBP with 3 channels R, G and B is rendered incorrectly #373

Open REASY opened 1 year ago

REASY commented 1 year ago

WebImageDecoder should take into consideration fileDirectory.SamplesPerPixel. If it is equal to 3 it must convert buffer from RGB to RGBA.

RGB example, file webp_rgb.tif

The output of gdalinfo on attached webp_rgb.tif (webp.zip)

Data axis to CRS axis mapping: 1,2
Origin = (-13044819.684176461771131,3859305.558118546847254)
Pixel Size = (0.074645535434684,-0.074645535434684)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=WEBP
  INTERLEAVE=PIXEL
  LAYOUT=COG
Corner Coordinates:
Upper Left  (-13044819.684, 3859305.558) (117d11' 0.99"W, 32d43'42.15"N)
Lower Left  (-13044819.684, 3859229.121) (117d11' 0.99"W, 32d43'40.07"N)
Upper Right (-13044743.247, 3859305.558) (117d10'58.52"W, 32d43'42.15"N)
Lower Right (-13044743.247, 3859229.121) (117d10'58.52"W, 32d43'40.07"N)
Center      (-13044781.466, 3859267.340) (117d10'59.76"W, 32d43'41.11"N)
Band 1 Block=512x512 Type=Byte, ColorInterp=Red
  NoData Value=0
  Overviews: 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, 4x4
Band 2 Block=512x512 Type=Byte, ColorInterp=Green
  NoData Value=0
  Overviews: 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, 4x4
Band 3 Block=512x512 Type=Byte, ColorInterp=Blue
  NoData Value=0
  Overviews: 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, 4x4

When I try to render it (using cog-explorer running locally): image

RGBA example, file webp_rgba.tif

The output of gdalinfo on attached webp_rgba.tif (webp.zip)

Data axis to CRS axis mapping: 1,2
Origin = (-13044819.684176461771131,3859305.558118546847254)
Pixel Size = (0.074645535434684,-0.074645535434684)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=WEBP
  INTERLEAVE=PIXEL
  LAYOUT=COG
Corner Coordinates:
Upper Left  (-13044819.684, 3859305.558) (117d11' 0.99"W, 32d43'42.15"N)
Lower Left  (-13044819.684, 3859229.121) (117d11' 0.99"W, 32d43'40.07"N)
Upper Right (-13044743.247, 3859305.558) (117d10'58.52"W, 32d43'42.15"N)
Lower Right (-13044743.247, 3859229.121) (117d10'58.52"W, 32d43'40.07"N)
Center      (-13044781.466, 3859267.340) (117d10'59.76"W, 32d43'41.11"N)
Band 1 Block=512x512 Type=Byte, ColorInterp=Red
  NoData Value=0
  Overviews: 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, 4x4
Band 2 Block=512x512 Type=Byte, ColorInterp=Green
  NoData Value=0
  Overviews: 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, 4x4
Band 3 Block=512x512 Type=Byte, ColorInterp=Blue
  NoData Value=0
  Overviews: 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, 4x4
Band 4 Block=512x512 Type=Byte, ColorInterp=Alpha
  NoData Value=0
  Overviews: 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, 4x4

When I try to render it (using cog-explorer running locally), it looks fine : image

https://github.com/geotiffjs/geotiff.js/blob/f15d7709efd5e519dc2834386305218208cecd9c/src/compression/webimage.js#L35-L36

Environment

Attached two GeoTIFF files as an example webp.zip