ase

package module
v0.0.0-...-8810463 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2015 License: MIT Imports: 8 Imported by: 3

README

ase

Golang package for decoding and encoding ASE (Adobe Swatch Exchange) files.

The ASE specification can be found here.

Install

$ go get github.com/arolek/ase

Getting started

The ASE package exposes a Decode and Encode method. You simply pass an io.Reader interface to ase.Decode and it will return an ASE struct of the decoded data. For convenience, a DecodeFile method is available to decode an existing ASE file. For encoding, simply initialize an ASE struct and populate it with the appropriate Groups and Colors data.

Examples

Decoding
package main

import (
	"log"

	"github.com/ARolek/ase"
)

func main() {
	//	open the file
	f, err := os.Open("/path/to/test.ase")
	if err != nil {
		log.Println(err)
	}

	//	decode can take in any io.Reader
	ase, err := ase.Decode(f)
	if err != nil {
		log.Println(err)
	}

	log.Printf("%+v\n", ase)
}

Encoding

package main

import (
	"os"

	"github.com/ARolek/ase"
)

var testColors = []ase.Color{
	ase.Color{
		Name:   "RGB",
		Model:  "RGB",
		Values: []float32{1, 1, 1},
		Type:   "Normal",
	},
	ase.Color{
		Name:   "Grayscale",
		Model:  "CMYK",
		Values: []float32{0, 0, 0, 0.47},
		Type:   "Spot",
	},
	ase.Color{
		Name:   "cmyk",
		Model:  "CMYK",
		Values: []float32{0, 1, 0, 0},
		Type:   "Spot",
	},
	ase.Color{
		Name:   "LAB",
		Model:  "RGB",
		Values: []float32{0, 0.6063648, 0.524658},
		Type:   "Global",
	},
	ase.Color{
		Name:   "PANTONE P 1-8 C",
		Model:  "LAB",
		Values: []float32{0.9137255, -5, 94},
		Type:   "Spot",
	},
}

var testGroup = ase.Group{
	Name: "A Color Group",
	Colors: []ase.Color{
		ase.Color{
			Name:   "Red",
			Model:  "RGB",
			Values: []float32{1, 0, 0},
			Type:   "Global",
		},
		ase.Color{
			Name:   "Green",
			Model:  "RGB",
			Values: []float32{0, 1, 0},
			Type:   "Global",
		},
		ase.Color{
			Name:   "Blue",
			Model:  "RGB",
			Values: []float32{0, 0, 1},
			Type:   "Global",
		},
	},
}

func main() {
	// Initialize a sample ASE
	sampleAse := ase.ASE{}
	sampleAse.Colors = testColors
	sampleAse.Groups = append(sampleAse.Groups, testGroup)

	// Create the file to write the encoded ASE
	f, err := os.Create("./encoded.ase")
	if err != nil {
		panic(err)
	}

	// It’s idiomatic to defer a Close immediately after opening a file.
	defer f.Close()

	//	encode our ASE file
	if err = ase.Encode(sampleAse, f){
		panic(err)
	}
}
Credits

Thanks to francistmakes for the killer work on the Encoding part of the package!

License

See LICENSE file in repository.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFile      = errors.New("ase: file not an ASE file")
	ErrInvalidVersion   = errors.New("ase: version is not 1.0")
	ErrInvalidBlockType = errors.New("ase: invalid block type")
)
View Source
var (
	ErrInvalidColorType  = errors.New("ase: invalid color type")
	ErrInvalidColorValue = errors.New("ase: invalid color value")
	ErrInvalidColorModel = errors.New("ase: invalid color model")
)

Functions

func Encode

func Encode(ase ASE, w io.Writer) (err error)

Encodes an ASE into any `w` that satisfies the io.Writer interface.

Types

type ASE

type ASE struct {
	Colors []Color
	Groups []Group
	// contains filtered or unexported fields
}

func Decode

func Decode(r io.Reader) (ase ASE, err error)

Decodes a valid ASE input.

func DecodeFile

func DecodeFile(file string) (ase ASE, err error)

Helper function that decodes a file into an ASE.

func (*ASE) Signature

func (ase *ASE) Signature() string

Returns the file signature in a human readable format.

func (*ASE) Version

func (ase *ASE) Version() string

Returns the file version in a human readable format.

type Color

type Color struct {
	Name   string
	Model  string // CMYK, RGB, LAB or Gray
	Values []float32
	Type   string // Global, Spot, Normal
	// contains filtered or unexported fields
}

func (*Color) NameLen

func (color *Color) NameLen() uint16

Helper function that returns the length of a color's name.

type Group

type Group struct {
	Name   string
	Colors []Color
	// contains filtered or unexported fields
}

func (*Group) NameLen

func (group *Group) NameLen() uint16

Helper function that returns the length of a group's name.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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