# package color
`import "image/color"`
color包实现了基本色彩库。
## Index
* [Variables](#pkg-variables)
* [type Color](#Color)
* [type Model](#Model)
* [func ModelFunc(f func(Color) Color) Model](#ModelFunc)
* [type Alpha](#Alpha)
* [func (c Alpha) RGBA() (r, g, b, a uint32)](#Alpha.RGBA)
* [type Alpha16](#Alpha16)
* [func (c Alpha16) RGBA() (r, g, b, a uint32)](#Alpha16.RGBA)
* [type Gray](#Gray)
* [func (c Gray) RGBA() (r, g, b, a uint32)](#Gray.RGBA)
* [type Gray16](#Gray16)
* [func (c Gray16) RGBA() (r, g, b, a uint32)](#Gray16.RGBA)
* [type RGBA](#RGBA)
* [func (c RGBA) RGBA() (r, g, b, a uint32)](#RGBA.RGBA)
* [type RGBA64](#RGBA64)
* [func (c RGBA64) RGBA() (r, g, b, a uint32)](#RGBA64.RGBA)
* [type NRGBA](#NRGBA)
* [func (c NRGBA) RGBA() (r, g, b, a uint32)](#NRGBA.RGBA)
* [type NRGBA64](#NRGBA64)
* [func (c NRGBA64) RGBA() (r, g, b, a uint32)](#NRGBA64.RGBA)
* [type YCbCr](#YCbCr)
* [func (c YCbCr) RGBA() (uint32, uint32, uint32, uint32)](#YCbCr.RGBA)
* [type Palette](#Palette)
* [func (p Palette) Convert(c Color) Color](#Palette.Convert)
* [func (p Palette) Index(c Color) int](#Palette.Index)
* [func RGBToYCbCr(r, g, b uint8) (uint8, uint8, uint8)](#RGBToYCbCr)
* [func YCbCrToRGB(y, cb, cr uint8) (uint8, uint8, uint8)](#YCbCrToRGB)
## Variables
```
var (
Black = Gray16{0} // 黑色
White = Gray16{0xffff} // 白色
Transparent = Alpha16{0} // 完全透明
Opaque = Alpha16{0xffff} // 完全不透明
)
```
标准色彩。
## type [Color](https://github.com/golang/go/blob/master/src/image/color/color.go#L10 "View Source")
```
type Color interface {
// 方法返回预乘了alpha的红、绿、蓝色彩值和alpha通道值,范围都在[0, 0xFFFF]。
// 返回值类型为uint32,这样当乘以接近0xFFFF的混合参数时,不会溢出。
RGBA() (r, g, b, a uint32)
}
```
实现了Color接口的类型可以将自身转化为预乘了alpha的16位通道的RGBA,转换可能会丢失色彩信息。
## type [Model](https://github.com/golang/go/blob/master/src/image/color/color.go#L133 "View Source")
```
type Model interface {
Convert(c Color) Color
}
```
Model接口可以将任意Color接口转换为采用自身色彩模型的Color接口。转换可能会丢失色彩信息。
```
var (
RGBAModel Model = ModelFunc(rgbaModel)
RGBA64Model Model = ModelFunc(rgba64Model)
NRGBAModel Model = ModelFunc(nrgbaModel)
NRGBA64Model Model = ModelFunc(nrgba64Model)
AlphaModel Model = ModelFunc(alphaModel)
Alpha16Model Model = ModelFunc(alpha16Model)
GrayModel Model = ModelFunc(grayModel)
Gray16Model Model = ModelFunc(gray16Model)
)
```
Models接口返回标准的Color接口类型。
```
var YCbCrModel Model = ModelFunc(yCbCrModel)
```
包变量YcbCrModel是Y'cbCr色彩模型的Model接口。
### func [ModelFunc](https://github.com/golang/go/blob/master/src/image/color/color.go#L138 "View Source")
```
func ModelFunc(f func(Color) Color) Model
```
函数ModelFunc返回一个调用函数f实现色彩转换的Model接口。
## type [Alpha](https://github.com/golang/go/blob/master/src/image/color/color.go#L90 "View Source")
```
type Alpha struct {
A uint8
}
```
Alpha类型代表一个8位的alpha通道(alpha通道表示透明度)。
### func (Alpha) [RGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L94 "View Source")
```
func (c Alpha) RGBA() (r, g, b, a uint32)
```
## type [Alpha16](https://github.com/golang/go/blob/master/src/image/color/color.go#L101 "View Source")
```
type Alpha16 struct {
A uint16
}
```
Alpha16类型代表一个16位的alpha通道。
### func (Alpha16) [RGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L105 "View Source")
```
func (c Alpha16) RGBA() (r, g, b, a uint32)
```
## type [Gray](https://github.com/golang/go/blob/master/src/image/color/color.go#L111 "View Source")
```
type Gray struct {
Y uint8
}
```
Gray类型代表一个8位的灰度色彩。
### func (Gray) [RGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L115 "View Source")
```
func (c Gray) RGBA() (r, g, b, a uint32)
```
## type [Gray16](https://github.com/golang/go/blob/master/src/image/color/color.go#L122 "View Source")
```
type Gray16 struct {
Y uint16
}
```
Gray16类型代表一个16位的灰度色彩。
### func (Gray16) [RGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L126 "View Source")
```
func (c Gray16) RGBA() (r, g, b, a uint32)
```
## type [RGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L20 "View Source")
```
type RGBA struct {
R, G, B, A uint8
}
```
RGBA类型代表传统的预乘了alpha通道的32位RGB色彩,Red、Green、Blue、Alpha各8位。
### func (RGBA) [RGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L24 "View Source")
```
func (c RGBA) RGBA() (r, g, b, a uint32)
```
## type [RGBA64](https://github.com/golang/go/blob/master/src/image/color/color.go#L38 "View Source")
```
type RGBA64 struct {
R, G, B, A uint16
}
```
RGBA64类型代表预乘了alpha通道的64位RGB色彩,Red、Green、Blue、Alpha各16位。
### func (RGBA64) [RGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L42 "View Source")
```
func (c RGBA64) RGBA() (r, g, b, a uint32)
```
## type [NRGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L47 "View Source")
```
type NRGBA struct {
R, G, B, A uint8
}
```
NRGBA类型代表没有预乘alpha通道的32位RGB色彩,Red、Green、Blue、Alpha各8位。
### func (NRGBA) [RGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L51 "View Source")
```
func (c NRGBA) RGBA() (r, g, b, a uint32)
```
## type [NRGBA64](https://github.com/golang/go/blob/master/src/image/color/color.go#L71 "View Source")
```
type NRGBA64 struct {
R, G, B, A uint16
}
```
NRGBA64类型代表没有预乘alpha通道的64位RGB色彩,Red、Green、Blue、Alpha各16位。
### func (NRGBA64) [RGBA](https://github.com/golang/go/blob/master/src/image/color/color.go#L75 "View Source")
```
func (c NRGBA64) RGBA() (r, g, b, a uint32)
```
## type [YCbCr](https://github.com/golang/go/blob/master/src/image/color/ycbcr.go#L80 "View Source")
```
type YCbCr struct {
Y, Cb, Cr uint8
}
```
YcbCr代表完全不透明的24位Y'CbCr色彩;每个色彩都有1个亮度成分和2个色度成分,分别用8位字节表示。
JPEG、VP8、MPEG家族和其他编码方式使用本色彩模型。这些编码通常将Y'CbCr 和YUV两个色彩模型等同使用(Y=Y'=黄、U=Cb=青、V=Cr=品红)。但严格来说,YUV模只用于模拟视频信号,Y'是经过伽玛校正的Y。RGB和Y'CbCr色彩模型之间的转换会丢失色彩信息。两个色彩模型之间的转换有多个存在细微区别的算法。本包采用JFIF算法,参见[http://www.w3.org/Graphics/JPEG/jfif3.pdf](http://www.w3.org/Graphics/JPEG/jfif3.pdf)
### func (YCbCr) [RGBA](https://github.com/golang/go/blob/master/src/image/color/ycbcr.go#L84 "View Source")
```
func (c YCbCr) RGBA() (uint32, uint32, uint32, uint32)
```
## type [Palette](https://github.com/golang/go/blob/master/src/image/color/color.go#L254 "View Source")
```
type Palette []Color
```
Palette类型代表一个色彩的调色板。
### func (Palette) [Convert](https://github.com/golang/go/blob/master/src/image/color/color.go#L257 "View Source")
```
func (p Palette) Convert(c Color) Color
```
返回调色板中与色彩c在欧几里德RGB色彩空间最接近的色彩。(实现了Model接口)
### func (Palette) [Index](https://github.com/golang/go/blob/master/src/image/color/color.go#L266 "View Source")
```
func (p Palette) Index(c Color) int
```
返回调色板中与色彩c在欧几里德RGB色彩空间最接近的色彩的索引。
## func [RGBToYCbCr](https://github.com/golang/go/blob/master/src/image/color/ycbcr.go#L8 "View Source")
```
func RGBToYCbCr(r, g, b uint8) (uint8, uint8, uint8)
```
函数将RGB三原色转换为Y'CbCr三原色。
## func [YCbCrToRGB](https://github.com/golang/go/blob/master/src/image/color/ycbcr.go#L39 "View Source")
```
func YCbCrToRGB(y, cb, cr uint8) (uint8, uint8, uint8)
```
函数将Y'CbCr三原色转换为RGB三原色。
- 库
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe