MCPcopy Create free account
hub / github.com/HugoSmits86/nativewebp / applyColorTransform

Function applyColorTransform

transform.go:213–259  ·  view source on GitHub ↗
(pixels []color.NRGBA, width, height, transBits int)

Source from the content-addressed store, hash-verified

211}
212
213func applyColorTransform(pixels []color.NRGBA, width, height, transBits int) (int, int, []color.NRGBA) {
214 bw := (width + (1 << transBits) - 1) >> transBits
215 bh := (height + (1 << transBits) - 1) >> transBits
216
217 blocks := make([]color.NRGBA, bw * bh)
218 deltas := make([]color.NRGBA, width * height)
219
220 //TODO: analyze block and pick best Color transform Element (CTE)
221 cte := color.NRGBA {
222 R: 1, //red to blue
223 G: 2, //green to blue
224 B: 3, //green to red
225 A: 255,
226 }
227
228 for y := 0; y < bh; y++ {
229 for x := 0; x < bw; x++ {
230 mx := min((x + 1) << transBits, width)
231 my := min((y + 1) << transBits, height)
232
233 for tx := x << transBits; tx < mx; tx++ {
234 for ty := y << transBits; ty < my; ty++ {
235 off := ty * width + tx
236
237 r := int(int8(pixels[off].R))
238 g := int(int8(pixels[off].G))
239 b := int(int8(pixels[off].B))
240
241 b -= int(int8((int16(int8(cte.G)) * int16(g)) >> 5))
242 b -= int(int8((int16(int8(cte.R)) * int16(r)) >> 5))
243 r -= int(int8((int16(int8(cte.B)) * int16(g)) >> 5))
244
245 pixels[off].R = uint8(r & 0xff)
246 pixels[off].B = uint8(b & 0xff)
247
248 deltas[off] = pixels[off]
249 }
250 }
251
252 blocks[y * bw + x] = cte
253 }
254 }
255
256 copy(pixels, deltas)
257
258 return bw, bh, blocks
259}
260
261func applySubtractGreenTransform(pixels []color.NRGBA) {
262 for i, _ := range pixels {

Callers 2

TestApplyColorTransformFunction · 0.85
writeBitStreamDataFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestApplyColorTransformFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…