...
Tawesoft Logo

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

Documentation: src/tawesoft.co.uk/go/ximage/xcolor/rgb.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  // RGB represents an 8-bit Red 8-bit Green 8-bit Blue color.
    13  type RGB struct {
    14      R uint8
    15      G uint8
    16      B uint8
    17  }
    18  
    19  func (c RGB) RGBA() (r, g, b, a uint32) {
    20  	r = uint32(c.R)
    21      r |= r << 8
    22      g = uint32(c.G)
    23      g |= g << 8
    24      b = uint32(c.B)
    25      b |= b << 8
    26  	return r, g, b, 0xFFFF
    27  }
    28  
    29  var RGBModel color.Model = color.ModelFunc(rgbModel)
    30  
    31  func rgbModel(c color.Color) color.Color {
    32  	if _, ok := c.(color.RGBA); ok {
    33  		return c
    34  	}
    35  	r, g, b, _ := c.RGBA()
    36  	return RGB{uint8(r >> 8), uint8(g >> 8), uint8(b >> 8)}
    37  }
    38  

View as plain text