github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/draw/draw_pyrdown_test.go (about) 1 // Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package draw 6 7 import ( 8 "image" 9 "image/color" 10 "image/draw" 11 "testing" 12 13 image_ext "github.com/chai2010/gopkg/image" 14 color_ext "github.com/chai2010/gopkg/image/color" 15 ) 16 17 type tDrawPyrDownTester struct { 18 BgdImage draw.Image 19 BgdColor color.Color 20 FgdImage draw.Image 21 FgdColor color.Color 22 DrawRect image.Rectangle 23 DrawSp image.Point 24 FgdRect image.Rectangle 25 } 26 27 func TestDrawPyrDown_Average(t *testing.T) { 28 for i, v := range tDrawPyrDownTesterList { 29 tClearImage(v.BgdImage, v.BgdColor) 30 tClearImage(v.FgdImage, v.FgdColor) 31 DrawPyrDown(v.BgdImage, v.DrawRect, v.FgdImage, v.DrawSp, Filter_Average) 32 err := tCheckImageColor(v.BgdImage, v.FgdRect, v.FgdColor, v.BgdColor) 33 if err != nil { 34 t.Fatalf("%d: %v", i, err) 35 } 36 } 37 } 38 39 func TestDrawPyrDown_Interlace(t *testing.T) { 40 for i, v := range tDrawPyrDownTesterList { 41 tClearImage(v.BgdImage, v.BgdColor) 42 tClearImage(v.FgdImage, v.FgdColor) 43 DrawPyrDown(v.BgdImage, v.DrawRect, v.FgdImage, v.DrawSp, Filter_Interlace) 44 err := tCheckImageColor(v.BgdImage, v.FgdRect, v.FgdColor, v.BgdColor) 45 if err != nil { 46 t.Fatalf("%d: %v", i, err) 47 } 48 } 49 } 50 51 var tDrawPyrDownTesterList = []tDrawPyrDownTester{ 52 // Gray 53 tDrawPyrDownTester{ 54 BgdImage: image.NewGray(image.Rect(0, 0, 10, 10)), 55 BgdColor: color.Gray{100}, 56 FgdImage: image.NewGray(image.Rect(0, 0, 10, 10)), 57 FgdColor: color.Gray{250}, 58 DrawRect: image.Rect(0, 0, 5, 5), 59 DrawSp: image.Pt(0, 0), 60 FgdRect: image.Rect(0, 0, 5, 5), 61 }, 62 tDrawPyrDownTester{ 63 BgdImage: image.NewGray(image.Rect(0, 0, 10, 10)), 64 BgdColor: color.Gray{100}, 65 FgdImage: image.NewGray(image.Rect(0, 0, 10, 10)), 66 FgdColor: color.Gray{250}, 67 DrawRect: image.Rect(0, 0, 10, 10), 68 DrawSp: image.Pt(0, 0), 69 FgdRect: image.Rect(0, 0, 5, 5), 70 }, 71 tDrawPyrDownTester{ 72 BgdImage: image.NewGray(image.Rect(0, 0, 10, 10)), 73 BgdColor: color.Gray{100}, 74 FgdImage: image.NewGray(image.Rect(0, 0, 10, 10)), 75 FgdColor: color.Gray{250}, 76 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 77 DrawSp: image.Pt(0, 0), 78 FgdRect: image.Rect(0, 0, 5, 5), 79 }, 80 tDrawPyrDownTester{ 81 BgdImage: image.NewGray(image.Rect(0, 0, 10, 10)), 82 BgdColor: color.Gray{100}, 83 FgdImage: image.NewGray(image.Rect(0, 0, 10, 10)), 84 FgdColor: color.Gray{250}, 85 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 86 DrawSp: image.Pt(4, 4), // +overflow 87 FgdRect: image.Rect(0, 0, 3, 3), 88 }, 89 tDrawPyrDownTester{ 90 BgdImage: image.NewGray(image.Rect(0, 0, 10, 10)), 91 BgdColor: color.Gray{100}, 92 FgdImage: image.NewGray(image.Rect(0, 0, 8, 8)), 93 FgdColor: color.Gray{250}, 94 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 95 DrawSp: image.Pt(6, 6), // +overflow 96 FgdRect: image.Rect(0, 0, 1, 1), 97 }, 98 99 // Gray16 100 tDrawPyrDownTester{ 101 BgdImage: image.NewGray16(image.Rect(0, 0, 10, 10)), 102 BgdColor: color.Gray16{100 << 8}, 103 FgdImage: image.NewGray16(image.Rect(0, 0, 10, 10)), 104 FgdColor: color.Gray16{250 << 8}, 105 DrawRect: image.Rect(0, 0, 5, 5), 106 DrawSp: image.Pt(0, 0), 107 FgdRect: image.Rect(0, 0, 5, 5), 108 }, 109 tDrawPyrDownTester{ 110 BgdImage: image.NewGray16(image.Rect(0, 0, 10, 10)), 111 BgdColor: color.Gray16{100 << 8}, 112 FgdImage: image.NewGray16(image.Rect(0, 0, 10, 10)), 113 FgdColor: color.Gray16{250 << 8}, 114 DrawRect: image.Rect(0, 0, 10, 10), 115 DrawSp: image.Pt(0, 0), 116 FgdRect: image.Rect(0, 0, 5, 5), 117 }, 118 tDrawPyrDownTester{ 119 BgdImage: image.NewGray16(image.Rect(0, 0, 10, 10)), 120 BgdColor: color.Gray16{100 << 8}, 121 FgdImage: image.NewGray16(image.Rect(0, 0, 10, 10)), 122 FgdColor: color.Gray16{250 << 8}, 123 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 124 DrawSp: image.Pt(0, 0), 125 FgdRect: image.Rect(0, 0, 5, 5), 126 }, 127 tDrawPyrDownTester{ 128 BgdImage: image.NewGray16(image.Rect(0, 0, 10, 10)), 129 BgdColor: color.Gray16{100 << 8}, 130 FgdImage: image.NewGray16(image.Rect(0, 0, 10, 10)), 131 FgdColor: color.Gray16{250 << 8}, 132 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 133 DrawSp: image.Pt(4, 4), // +overflow 134 FgdRect: image.Rect(0, 0, 3, 3), 135 }, 136 tDrawPyrDownTester{ 137 BgdImage: image.NewGray16(image.Rect(0, 0, 10, 10)), 138 BgdColor: color.Gray16{100 << 8}, 139 FgdImage: image.NewGray16(image.Rect(0, 0, 8, 8)), 140 FgdColor: color.Gray16{250 << 8}, 141 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 142 DrawSp: image.Pt(6, 6), // +overflow 143 FgdRect: image.Rect(0, 0, 1, 1), 144 }, 145 146 // Gray32f 147 tDrawPyrDownTester{ 148 BgdImage: image_ext.NewGray32f(image.Rect(0, 0, 10, 10)), 149 BgdColor: color_ext.Gray32f{Y: 100 << 8}, 150 FgdImage: image_ext.NewGray32f(image.Rect(0, 0, 10, 10)), 151 FgdColor: color_ext.Gray32f{Y: 250 << 8}, 152 DrawRect: image.Rect(0, 0, 5, 5), 153 DrawSp: image.Pt(0, 0), 154 FgdRect: image.Rect(0, 0, 5, 5), 155 }, 156 tDrawPyrDownTester{ 157 BgdImage: image_ext.NewGray32f(image.Rect(0, 0, 10, 10)), 158 BgdColor: color_ext.Gray32f{Y: 100 << 8}, 159 FgdImage: image_ext.NewGray32f(image.Rect(0, 0, 10, 10)), 160 FgdColor: color_ext.Gray32f{Y: 250 << 8}, 161 DrawRect: image.Rect(0, 0, 10, 10), 162 DrawSp: image.Pt(0, 0), 163 FgdRect: image.Rect(0, 0, 5, 5), 164 }, 165 tDrawPyrDownTester{ 166 BgdImage: image_ext.NewGray32f(image.Rect(0, 0, 10, 10)), 167 BgdColor: color_ext.Gray32f{Y: 100 << 8}, 168 FgdImage: image_ext.NewGray32f(image.Rect(0, 0, 10, 10)), 169 FgdColor: color_ext.Gray32f{Y: 250 << 8}, 170 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 171 DrawSp: image.Pt(0, 0), 172 FgdRect: image.Rect(0, 0, 5, 5), 173 }, 174 tDrawPyrDownTester{ 175 BgdImage: image_ext.NewGray32f(image.Rect(0, 0, 10, 10)), 176 BgdColor: color_ext.Gray32f{Y: 100 << 8}, 177 FgdImage: image_ext.NewGray32f(image.Rect(0, 0, 10, 10)), 178 FgdColor: color_ext.Gray32f{Y: 250 << 8}, 179 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 180 DrawSp: image.Pt(4, 4), // +overflow 181 FgdRect: image.Rect(0, 0, 3, 3), 182 }, 183 tDrawPyrDownTester{ 184 BgdImage: image_ext.NewGray32f(image.Rect(0, 0, 10, 10)), 185 BgdColor: color_ext.Gray32f{Y: 100 << 8}, 186 FgdImage: image_ext.NewGray32f(image.Rect(0, 0, 8, 8)), 187 FgdColor: color_ext.Gray32f{Y: 250 << 8}, 188 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 189 DrawSp: image.Pt(6, 6), // +overflow 190 FgdRect: image.Rect(0, 0, 1, 1), 191 }, 192 193 // RGBA, drawPyrDownRGBA_Average_fast only has 7bit for uint8 194 tDrawPyrDownTester{ 195 BgdImage: image.NewRGBA(image.Rect(0, 0, 10, 10)), 196 BgdColor: color.RGBA{100, 101, 102, 103}, 197 FgdImage: image.NewRGBA(image.Rect(0, 0, 10, 10)), 198 FgdColor: color.RGBA{150, 152, 154, 156}, 199 DrawRect: image.Rect(0, 0, 5, 5), 200 DrawSp: image.Pt(0, 0), 201 FgdRect: image.Rect(0, 0, 5, 5), 202 }, 203 tDrawPyrDownTester{ 204 BgdImage: image.NewRGBA(image.Rect(0, 0, 10, 10)), 205 BgdColor: color.RGBA{100, 101, 102, 103}, 206 FgdImage: image.NewRGBA(image.Rect(0, 0, 10, 10)), 207 FgdColor: color.RGBA{150, 152, 154, 156}, 208 DrawRect: image.Rect(0, 0, 10, 10), 209 DrawSp: image.Pt(0, 0), 210 FgdRect: image.Rect(0, 0, 5, 5), 211 }, 212 tDrawPyrDownTester{ 213 BgdImage: image.NewRGBA(image.Rect(0, 0, 10, 10)), 214 BgdColor: color.RGBA{100, 101, 102, 103}, 215 FgdImage: image.NewRGBA(image.Rect(0, 0, 10, 10)), 216 FgdColor: color.RGBA{150, 152, 154, 156}, 217 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 218 DrawSp: image.Pt(0, 0), 219 FgdRect: image.Rect(0, 0, 5, 5), 220 }, 221 tDrawPyrDownTester{ 222 BgdImage: image.NewRGBA(image.Rect(0, 0, 10, 10)), 223 BgdColor: color.RGBA{100, 101, 102, 103}, 224 FgdImage: image.NewRGBA(image.Rect(0, 0, 10, 10)), 225 FgdColor: color.RGBA{150, 152, 154, 156}, 226 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 227 DrawSp: image.Pt(4, 4), // +overflow 228 FgdRect: image.Rect(0, 0, 3, 3), 229 }, 230 tDrawPyrDownTester{ 231 BgdImage: image.NewRGBA(image.Rect(0, 0, 10, 10)), 232 BgdColor: color.RGBA{100, 101, 102, 103}, 233 FgdImage: image.NewRGBA(image.Rect(0, 0, 8, 8)), 234 FgdColor: color.RGBA{150, 152, 154, 156}, 235 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 236 DrawSp: image.Pt(6, 6), // +overflow 237 FgdRect: image.Rect(0, 0, 1, 1), 238 }, 239 240 // RGBA64 241 tDrawPyrDownTester{ 242 BgdImage: image.NewRGBA64(image.Rect(0, 0, 10, 10)), 243 BgdColor: color.RGBA64{100 << 8, 101 << 8, 102 << 8, 103 << 8}, 244 FgdImage: image.NewRGBA64(image.Rect(0, 0, 10, 10)), 245 FgdColor: color.RGBA64{250 << 8, 251 << 8, 252 << 8, 253 << 8}, 246 DrawRect: image.Rect(0, 0, 5, 5), 247 DrawSp: image.Pt(0, 0), 248 FgdRect: image.Rect(0, 0, 5, 5), 249 }, 250 tDrawPyrDownTester{ 251 BgdImage: image.NewRGBA64(image.Rect(0, 0, 10, 10)), 252 BgdColor: color.RGBA64{100 << 8, 101 << 8, 102 << 8, 103 << 8}, 253 FgdImage: image.NewRGBA64(image.Rect(0, 0, 10, 10)), 254 FgdColor: color.RGBA64{250 << 8, 251 << 8, 252 << 8, 253 << 8}, 255 DrawRect: image.Rect(0, 0, 10, 10), 256 DrawSp: image.Pt(0, 0), 257 FgdRect: image.Rect(0, 0, 5, 5), 258 }, 259 tDrawPyrDownTester{ 260 BgdImage: image.NewRGBA64(image.Rect(0, 0, 10, 10)), 261 BgdColor: color.RGBA64{100 << 8, 101 << 8, 102 << 8, 103 << 8}, 262 FgdImage: image.NewRGBA64(image.Rect(0, 0, 10, 10)), 263 FgdColor: color.RGBA64{250 << 8, 251 << 8, 252 << 8, 253 << 8}, 264 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 265 DrawSp: image.Pt(0, 0), 266 FgdRect: image.Rect(0, 0, 5, 5), 267 }, 268 tDrawPyrDownTester{ 269 BgdImage: image.NewRGBA64(image.Rect(0, 0, 10, 10)), 270 BgdColor: color.RGBA64{100 << 8, 101 << 8, 102 << 8, 103 << 8}, 271 FgdImage: image.NewRGBA64(image.Rect(0, 0, 10, 10)), 272 FgdColor: color.RGBA64{250 << 8, 251 << 8, 252 << 8, 253 << 8}, 273 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 274 DrawSp: image.Pt(4, 4), // +overflow 275 FgdRect: image.Rect(0, 0, 3, 3), 276 }, 277 tDrawPyrDownTester{ 278 BgdImage: image.NewRGBA64(image.Rect(0, 0, 10, 10)), 279 BgdColor: color.RGBA64{100 << 8, 101 << 8, 102 << 8, 103 << 8}, 280 FgdImage: image.NewRGBA64(image.Rect(0, 0, 8, 8)), 281 FgdColor: color.RGBA64{250 << 8, 251 << 8, 252 << 8, 253 << 8}, 282 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 283 DrawSp: image.Pt(6, 6), // +overflow 284 FgdRect: image.Rect(0, 0, 1, 1), 285 }, 286 287 // RGBA128f 288 tDrawPyrDownTester{ 289 BgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 10, 10)), 290 BgdColor: color_ext.RGBA128f{R: 100 << 8, G: 101 << 8, B: 102 << 8, A: 103 << 8}, 291 FgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 10, 10)), 292 FgdColor: color_ext.RGBA128f{R: 250 << 8, G: 251 << 8, B: 252 << 8, A: 253 << 8}, 293 DrawRect: image.Rect(0, 0, 5, 5), 294 DrawSp: image.Pt(0, 0), 295 FgdRect: image.Rect(0, 0, 5, 5), 296 }, 297 tDrawPyrDownTester{ 298 BgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 10, 10)), 299 BgdColor: color_ext.RGBA128f{R: 100 << 8, G: 101 << 8, B: 102 << 8, A: 103 << 8}, 300 FgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 10, 10)), 301 FgdColor: color_ext.RGBA128f{R: 250 << 8, G: 251 << 8, B: 252 << 8, A: 253 << 8}, 302 DrawRect: image.Rect(0, 0, 10, 10), 303 DrawSp: image.Pt(0, 0), 304 FgdRect: image.Rect(0, 0, 5, 5), 305 }, 306 tDrawPyrDownTester{ 307 BgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 10, 10)), 308 BgdColor: color_ext.RGBA128f{R: 100 << 8, G: 101 << 8, B: 102 << 8, A: 103 << 8}, 309 FgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 10, 10)), 310 FgdColor: color_ext.RGBA128f{R: 250 << 8, G: 251 << 8, B: 252 << 8, A: 253 << 8}, 311 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 312 DrawSp: image.Pt(0, 0), 313 FgdRect: image.Rect(0, 0, 5, 5), 314 }, 315 tDrawPyrDownTester{ 316 BgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 10, 10)), 317 BgdColor: color_ext.RGBA128f{R: 100 << 8, G: 101 << 8, B: 102 << 8, A: 103 << 8}, 318 FgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 10, 10)), 319 FgdColor: color_ext.RGBA128f{R: 250 << 8, G: 251 << 8, B: 252 << 8, A: 253 << 8}, 320 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 321 DrawSp: image.Pt(4, 4), // +overflow 322 FgdRect: image.Rect(0, 0, 3, 3), 323 }, 324 tDrawPyrDownTester{ 325 BgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 10, 10)), 326 BgdColor: color_ext.RGBA128f{R: 100 << 8, G: 101 << 8, B: 102 << 8, A: 103 << 8}, 327 FgdImage: image_ext.NewRGBA128f(image.Rect(0, 0, 8, 8)), 328 FgdColor: color_ext.RGBA128f{R: 250 << 8, G: 251 << 8, B: 252 << 8, A: 253 << 8}, 329 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 330 DrawSp: image.Pt(6, 6), // +overflow 331 FgdRect: image.Rect(0, 0, 1, 1), 332 }, 333 334 // YCbCr 335 tDrawPyrDownTester{ 336 BgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 10, 10), image.YCbCrSubsampleRatio444), 337 BgdColor: color.YCbCr{100, 101, 102}, 338 FgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 10, 10), image.YCbCrSubsampleRatio444), 339 FgdColor: color.YCbCr{150, 152, 154}, 340 DrawRect: image.Rect(0, 0, 5, 5), 341 DrawSp: image.Pt(0, 0), 342 FgdRect: image.Rect(0, 0, 5, 5), 343 }, 344 tDrawPyrDownTester{ 345 BgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 10, 10), image.YCbCrSubsampleRatio444), 346 BgdColor: color.YCbCr{100, 101, 102}, 347 FgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 10, 10), image.YCbCrSubsampleRatio444), 348 FgdColor: color.YCbCr{150, 152, 154}, 349 DrawRect: image.Rect(0, 0, 10, 10), 350 DrawSp: image.Pt(0, 0), 351 FgdRect: image.Rect(0, 0, 5, 5), 352 }, 353 tDrawPyrDownTester{ 354 BgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 10, 10), image.YCbCrSubsampleRatio444), 355 BgdColor: color.YCbCr{100, 101, 102}, 356 FgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 10, 10), image.YCbCrSubsampleRatio444), 357 FgdColor: color.YCbCr{150, 152, 154}, 358 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 359 DrawSp: image.Pt(0, 0), 360 FgdRect: image.Rect(0, 0, 5, 5), 361 }, 362 tDrawPyrDownTester{ 363 BgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 10, 10), image.YCbCrSubsampleRatio444), 364 BgdColor: color.YCbCr{100, 101, 102}, 365 FgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 10, 10), image.YCbCrSubsampleRatio444), 366 FgdColor: color.YCbCr{150, 152, 154}, 367 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 368 DrawSp: image.Pt(4, 4), // +overflow 369 FgdRect: image.Rect(0, 0, 3, 3), 370 }, 371 tDrawPyrDownTester{ 372 BgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 10, 10), image.YCbCrSubsampleRatio444), 373 BgdColor: color.YCbCr{100, 101, 102}, 374 FgdImage: image_ext.NewYCbCr(image.Rect(0, 0, 8, 8), image.YCbCrSubsampleRatio444), 375 FgdColor: color.YCbCr{150, 152, 154}, 376 DrawRect: image.Rect(0, 0, 15, 15), // +overflow 377 DrawSp: image.Pt(6, 6), // +overflow 378 FgdRect: image.Rect(0, 0, 1, 1), 379 }, 380 }