...
Tawesoft Logo

Source file src/tawesoft.co.uk/go/ximage/xcolor/red.go

Documentation: src/tawesoft.co.uk/go/ximage/xcolor/red.go

     1  // Based on https://golang.org/src/image/color/color.go
     2  // Copyright 2009 The Go Authors. All rights reserved.
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package xcolor
     7  
     8  import (
     9      "image/color"
    10  )
    11  
    12  // Red represents an 8-bit red color.
    13  type Red struct {
    14  	R uint8
    15  }
    16  
    17  func (c Red) RGBA() (r, g, b, a uint32) {
    18  	r = uint32(c.R)
    19  	r |= r << 8
    20  	return r, 0, 0, 0xFFFF
    21  }
    22  
    23  
    24  var RedModel color.Model = color.ModelFunc(redModel)
    25  
    26  func redModel(c color.Color) color.Color {
    27  	if _, ok := c.(color.RGBA); ok {
    28  		return c
    29  	}
    30  	r, _, _, _ := c.RGBA()
    31  	return Red{uint8(r >> 8)}
    32  }
    33  

View as plain text