-
Notifications
You must be signed in to change notification settings - Fork 1
/
decode_logl.go
39 lines (32 loc) · 996 Bytes
/
decode_logl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package tiff
import (
"image"
"github.com/mdouchement/hdr"
"github.com/mdouchement/hdr/format"
"github.com/mdouchement/hdr/hdrcolor"
)
func (d *decoder) decodeLogL(dst image.Image, xmin, ymin, xmax, ymax int) error {
// Apply horizontal predictor if necessary.
// In this case, p contains the color difference to the preceding pixel.
// See page 64-65 of the spec.
if d.firstVal(tPredictor) > prNone {
return UnsupportedError("predictor")
}
rMaxX := minInt(xmax, dst.Bounds().Max.X)
rMaxY := minInt(ymax, dst.Bounds().Max.Y)
var offset uint
stonits := d.features[tStonits].double(0)
if stonits == 0 {
stonits = 1
}
m := dst.(*hdr.XYZ)
for y := ymin; y < rMaxY; y++ {
for x := xmin; x < rMaxX; x++ {
SLe := format.BytesToUint16(d.buf[offset], d.buf[offset+1])
Y := format.SLeToY(SLe)
m.SetXYZ(x, y, hdrcolor.XYZ{X: Y * stonits, Y: Y * stonits, Z: Y * stonits})
offset += 2 // LogL is hold on 2 bytes (the luminance used in GrayScale)
}
}
return nil
}