(pixels []color.NRGBA, width, height, transBits int)
| 211 | } |
| 212 | |
| 213 | func 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 | |
| 261 | func applySubtractGreenTransform(pixels []color.NRGBA) { |
| 262 | for i, _ := range pixels { |
no outgoing calls
searching dependent graphs…