...
Tawesoft Logo

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

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

View as plain text