github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/draw/draw_pyrdown_interlace.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/draw"
    10  
    11  	image_ext "github.com/chai2010/gopkg/image"
    12  )
    13  
    14  func drawPyrDownGray_Interlace(dst *image.Gray, r image.Rectangle, src image.Image, sp image.Point) {
    15  	switch src := src.(type) {
    16  	case *image.Gray:
    17  		for y := r.Min.Y; y < r.Max.Y; y++ {
    18  			for x := r.Min.X; x < r.Max.X; x++ {
    19  				x0 := (x-r.Min.X)*2 + sp.X
    20  				y0 := (y-r.Min.Y)*2 + sp.Y
    21  
    22  				dst.SetGray(x, y, src.GrayAt(x0, y0))
    23  			}
    24  		}
    25  	default:
    26  		drawPyrDown_Interlace(dst, r, src, sp)
    27  	}
    28  }
    29  
    30  func drawPyrDownGray16_Interlace(dst *image.Gray16, r image.Rectangle, src image.Image, sp image.Point) {
    31  	switch src := src.(type) {
    32  	case *image.Gray16:
    33  		for y := r.Min.Y; y < r.Max.Y; y++ {
    34  			for x := r.Min.X; x < r.Max.X; x++ {
    35  				x0 := (x-r.Min.X)*2 + sp.X
    36  				y0 := (y-r.Min.Y)*2 + sp.Y
    37  
    38  				dst.SetGray16(x, y, src.Gray16At(x0, y0))
    39  			}
    40  		}
    41  	default:
    42  		drawPyrDown_Interlace(dst, r, src, sp)
    43  	}
    44  }
    45  
    46  func drawPyrDownGray32f_Interlace(dst *image_ext.Gray32f, r image.Rectangle, src image.Image, sp image.Point) {
    47  	switch src := src.(type) {
    48  	case *image_ext.Gray32f:
    49  		for y := r.Min.Y; y < r.Max.Y; y++ {
    50  			for x := r.Min.X; x < r.Max.X; x++ {
    51  				x0 := (x-r.Min.X)*2 + sp.X
    52  				y0 := (y-r.Min.Y)*2 + sp.Y
    53  
    54  				dst.SetGray32f(x, y, src.Gray32fAt(x0, y0))
    55  			}
    56  		}
    57  	default:
    58  		drawPyrDown_Interlace(dst, r, src, sp)
    59  	}
    60  }
    61  
    62  func drawPyrDownRGB_Interlace(dst *image_ext.RGB, r image.Rectangle, src image.Image, sp image.Point) {
    63  	switch src := src.(type) {
    64  	case *image_ext.RGB:
    65  		for y := r.Min.Y; y < r.Max.Y; y++ {
    66  			for x := r.Min.X; x < r.Max.X; x++ {
    67  				x0 := (x-r.Min.X)*2 + sp.X
    68  				y0 := (y-r.Min.Y)*2 + sp.Y
    69  
    70  				dst.SetRGB(x, y, src.RGBAt(x0, y0))
    71  			}
    72  		}
    73  	default:
    74  		drawPyrDown_Interlace(dst, r, src, sp)
    75  	}
    76  }
    77  
    78  func drawPyrDownRGB48_Interlace(dst *image_ext.RGB48, r image.Rectangle, src image.Image, sp image.Point) {
    79  	switch src := src.(type) {
    80  	case *image_ext.RGB48:
    81  		for y := r.Min.Y; y < r.Max.Y; y++ {
    82  			for x := r.Min.X; x < r.Max.X; x++ {
    83  				x0 := (x-r.Min.X)*2 + sp.X
    84  				y0 := (y-r.Min.Y)*2 + sp.Y
    85  
    86  				dst.SetRGB48(x, y, src.RGB48At(x0, y0))
    87  			}
    88  		}
    89  	default:
    90  		drawPyrDown_Interlace(dst, r, src, sp)
    91  	}
    92  }
    93  
    94  func drawPyrDownRGB96f_Interlace(dst *image_ext.RGB96f, r image.Rectangle, src image.Image, sp image.Point) {
    95  	switch src := src.(type) {
    96  	case *image_ext.RGB96f:
    97  		for y := r.Min.Y; y < r.Max.Y; y++ {
    98  			for x := r.Min.X; x < r.Max.X; x++ {
    99  				x0 := (x-r.Min.X)*2 + sp.X
   100  				y0 := (y-r.Min.Y)*2 + sp.Y
   101  
   102  				dst.SetRGB96f(x, y, src.RGB96fAt(x0, y0))
   103  			}
   104  		}
   105  	default:
   106  		drawPyrDown_Interlace(dst, r, src, sp)
   107  	}
   108  }
   109  
   110  func drawPyrDownRGBA_Interlace(dst *image.RGBA, r image.Rectangle, src image.Image, sp image.Point) {
   111  	switch src := src.(type) {
   112  	case *image.RGBA:
   113  		for y := r.Min.Y; y < r.Max.Y; y++ {
   114  			for x := r.Min.X; x < r.Max.X; x++ {
   115  				x0 := (x-r.Min.X)*2 + sp.X
   116  				y0 := (y-r.Min.Y)*2 + sp.Y
   117  
   118  				dst.SetRGBA(x, y, src.RGBAAt(x0, y0))
   119  			}
   120  		}
   121  	default:
   122  		drawPyrDown_Interlace(dst, r, src, sp)
   123  	}
   124  }
   125  
   126  func drawPyrDownRGBA64_Interlace(dst *image.RGBA64, r image.Rectangle, src image.Image, sp image.Point) {
   127  	switch src := src.(type) {
   128  	case *image.RGBA64:
   129  		for y := r.Min.Y; y < r.Max.Y; y++ {
   130  			for x := r.Min.X; x < r.Max.X; x++ {
   131  				x0 := (x-r.Min.X)*2 + sp.X
   132  				y0 := (y-r.Min.Y)*2 + sp.Y
   133  
   134  				dst.SetRGBA64(x, y, src.RGBA64At(x0, y0))
   135  			}
   136  		}
   137  	default:
   138  		drawPyrDown_Interlace(dst, r, src, sp)
   139  	}
   140  }
   141  
   142  func drawPyrDownRGBA128f_Interlace(dst *image_ext.RGBA128f, r image.Rectangle, src image.Image, sp image.Point) {
   143  	switch src := src.(type) {
   144  	case *image_ext.RGBA128f:
   145  		for y := r.Min.Y; y < r.Max.Y; y++ {
   146  			for x := r.Min.X; x < r.Max.X; x++ {
   147  				x0 := (x-r.Min.X)*2 + sp.X
   148  				y0 := (y-r.Min.Y)*2 + sp.Y
   149  
   150  				dst.SetRGBA128f(x, y, src.RGBA128fAt(x0, y0))
   151  			}
   152  		}
   153  	default:
   154  		drawPyrDown_Interlace(dst, r, src, sp)
   155  	}
   156  }
   157  
   158  func drawPyrDownYCbCr_Interlace(dst *yCbCr, r image.Rectangle, src image.Image, sp image.Point) {
   159  	drawPyrDown_Interlace(dst, r, src, sp)
   160  }
   161  
   162  func drawPyrDown_Interlace(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point) {
   163  	for y := r.Min.Y; y < r.Max.Y; y++ {
   164  		for x := r.Min.X; x < r.Max.X; x++ {
   165  			x0 := (x-r.Min.X)*2 + sp.X
   166  			y0 := (y-r.Min.Y)*2 + sp.Y
   167  			dst.Set(x, y, src.At(x0+0, y0+0))
   168  		}
   169  	}
   170  }