func (p *RGB64) Size() int {
	return p.Bounds().Dx() * p.Bounds().Dy()
}
Size implements Image.
package hdr
import (
	"image"
	"image/color"
	"github.com/mdouchement/hdr/hdrcolor"
)
type Image interface {
	image.Image
	HDRAt(x, y int) hdrcolor.Color
	Size() int
}
type ImageSet interface {
	Set(x, y int, c color.Color)
}
func EmptyAs(src Image) Image {
	switch m := src.(type) {
	case *RGB:
		return NewRGB(m.Bounds())
	case *RGB64:
		return NewRGB64(m.Bounds())
	case *XYZ:
		return NewXYZ(m.Bounds())
	case *XYZ64:
		return NewXYZ64(m.Bounds())
	default:
		return NewRGB64(m.Bounds())
	}
}
func Copy(src Image) Image {
	switch m := src.(type) {
	case *RGB:
		dst := NewRGB(m.Bounds())
		copy(dst.Pix, m.Pix)
		return dst
	case *RGB64:
		dst := NewRGB64(m.Bounds())
		copy(dst.Pix, m.Pix)
		return dst
	case *XYZ:
		dst := NewXYZ(m.Bounds())
		copy(dst.Pix, m.Pix)
		return dst
	case *XYZ64:
		dst := NewXYZ64(m.Bounds())
		copy(dst.Pix, m.Pix)
		return dst
	default:
		dst := NewRGB64(m.Bounds())
		for y := 0; y < m.Bounds().Dy(); y++ {
			for x := 0; x < m.Bounds().Dx(); x++ {
				dst.Set(x, y, src.HDRAt(x, y))
			}
		}
		return dst
	}
}
type RGB struct {
	Pix []float32
	Stride int
	Rect image.Rectangle
}
func NewRGB(r image.Rectangle) *RGB {
	w, h := r.Dx(), r.Dy()
	buf := make([]float32, 3*w*h)
	return &RGB{buf, 3 * w, r}
}
func (p *RGB) ColorModel() color.Model { return hdrcolor.RGBModel }
func (p *RGB) Bounds() image.Rectangle { return p.Rect }
func (p *RGB) Size() int {
	return p.Bounds().Dx() * p.Bounds().Dy()
}
func (p *RGB) At(x, y int) color.Color {
	return p.RGBAt(x, y)
}
func (p *RGB) HDRAt(x, y int) hdrcolor.Color {
	return p.RGBAt(x, y)
}
func (p *RGB) RGBAt(x, y int) hdrcolor.RGB {
	if !(image.Point{x, y}.In(p.Rect)) {
		return hdrcolor.RGB{}
	}
	i := p.PixOffset(x, y)
	return hdrcolor.RGB{
		R: float64(p.Pix[i+0]),
		G: float64(p.Pix[i+1]),
		B: float64(p.Pix[i+2]),
	}
}
func (p *RGB) PixOffset(x, y int) int {
	return (y-p.Rect.Min.Y)*p.Stride + (x-p.Rect.Min.X)*3
}
func (p *RGB) Set(x, y int, c color.Color) {
	if !(image.Point{x, y}.In(p.Rect)) {
		return
	}
	i := p.PixOffset(x, y)
	c1 := hdrcolor.RGBModel.Convert(c).(hdrcolor.RGB)
	p.Pix[i+0] = float32(c1.R)
	p.Pix[i+1] = float32(c1.G)
	p.Pix[i+2] = float32(c1.B)
}
func (p *RGB) SetRGB(x, y int, c hdrcolor.RGB) {
	if !(image.Point{x, y}.In(p.Rect)) {
		return
	}
	i := p.PixOffset(x, y)
	p.Pix[i+0] = float32(c.R)
	p.Pix[i+1] = float32(c.G)
	p.Pix[i+2] = float32(c.B)
}
type RGB64 struct {
	Pix []float64
	Stride int
	Rect image.Rectangle
}
func NewRGB64(r image.Rectangle) *RGB64 {
	w, h := r.Dx(), r.Dy()
	buf := make([]float64, 3*w*h)
	return &RGB64{buf, 3 * w, r}
}
func (p *RGB64) ColorModel() color.Model { return hdrcolor.RGBModel }
func (p *RGB64) Bounds() image.Rectangle { return p.Rect }