rgba4444

package module
v0.0.0-...-7d3c494 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2015 License: MIT Imports: 2 Imported by: 0

README

go-rgba4444

Build Status

go-rgba4444 represents RGBA4444 format images. RGBA4444 format is often used for textures of Unity.

The following code is simple RGBA4444 converter.

package main

import (
	"flag"
	"image"
	"image/draw"
	_ "image/gif"
	_ "image/jpeg"
	"image/png"
	"log"
	"os"

	"github.com/shogo82148/go-rgba4444"
)

func main() {
	flag.Parse()
	if flag.NArg() < 2 {
		log.Println("rgba4444 input output")
		return
	}
	input := flag.Arg(0)
	output := flag.Arg(1)

	reader, err := os.Open(input)
	if err != nil {
		log.Fatal(err)
	}
	defer reader.Close()

	img, _, err := image.Decode(reader)
	if err != nil {
		log.Fatal(err)
	}

	f, err := os.Create(output)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	newImg := rgba4444.New(img.Bounds())
	draw.FloydSteinberg.Draw(newImg, img.Bounds(), img, image.ZP)

	err = png.Encode(f, newImg)
	if err != nil {
		log.Fatal(err)
	}
}

LICENSE

This software is released under the MIT License, see LICENSE.txt.

godoc

See godoc for more imformation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Model color.Model = color.ModelFunc(rgba4444Model)

Functions

This section is empty.

Types

type Color

type Color struct {
	R, G, B, A uint8
}

RGBA represents a traditional 16-bit alpha-premultiplied color, having 4 bits for each of red, green, blue and alpha.

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

type Image

type Image struct {
	// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*2].
	Pix []uint8
	// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
	Stride int
	// Rect is the image's bounds.
	Rect image.Rectangle
}

Image is an in-memory image whose At method returns rgba4444.Color values.

func New

func New(r image.Rectangle) *Image

func (*Image) At

func (p *Image) At(x, y int) color.Color

func (*Image) Bounds

func (p *Image) Bounds() image.Rectangle

func (*Image) ColorModel

func (p *Image) ColorModel() color.Model

func (*Image) Opaque

func (p *Image) Opaque() bool

Opaque scans the entire image and reports whether it is fully opaque.

func (*Image) PixOffset

func (p *Image) PixOffset(x, y int) int

PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).

func (*Image) RGBA4444At

func (p *Image) RGBA4444At(x, y int) Color

func (*Image) Set

func (p *Image) Set(x, y int, c color.Color)

func (*Image) SetRGBA4444

func (p *Image) SetRGBA4444(x, y int, c Color)

func (*Image) SubImage

func (p *Image) SubImage(r image.Rectangle) image.Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL