xcf

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

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

Go to latest
Published: Apr 4, 2018 License: MIT Imports: 7 Imported by: 2

README

xcf

Package xcf is a pure Go implementation of a basic XCF (standard format used by GIMP) image file reader. It reads layers with names, visibility and opacity properties and the RGBA image data. It currently supports RGB and RGBA pixel formats.

Installation

You can go get the xcf package by typing the following command into your command line: go get github.com/gonutz/xcf

Example

package main

import (
	"fmt"
	"github.com/gonutz/xcf"
	"os"
)

func main() {
	if len(os.Args) != 2 {
		fmt.Println("please provide an XCF as the first parameter")
		return
	}

	canvas, err := xcf.LoadFromFile(os.Args[1])
	if err != nil {
		panic(err)
	}

	for _, layer := range canvas.Layers {
		fmt.Println(layer.Name, layer.Bounds())
	}
}

See the documentation for details. This document is the same as the draft.txt file included in this repo.

Documentation

Overview

Package xcf implements a simple reader for XCF files. This is the native format of the GIMP program.

The current implementation only supports loading RGB and RGBA layers.

The implementation uses information from

http://henning.makholm.net/xcftools/xcfspec-saved

as a reference.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Canvas

type Canvas struct {
	Width, Height uint32
	Layers        []Layer
}

A Canvas contains all the image's layers. It is not itself an image, it just has a size and its top-left corner has the coordinates 0,0. The layers' bounds are relative to that. Layers are ordered top-most first and bottom-most last in the Layers slice.

func Decode

func Decode(r io.ReadSeeker) (canvas Canvas, finalErr error)

Decode reads a canvas from the given ReadSeeker. It currently supports RGB and RGBA pixel formats, file format version "file" and RLE encoded data only.

func LoadFromFile

func LoadFromFile(path string) (Canvas, error)

LoadFromFile opens the given file and reads the XCF data using the Decode function. See that function for restrictions.

func (*Canvas) GetLayerByName

func (c *Canvas) GetLayerByName(name string) *Layer

GetLayerByName searches all layers for one with the given name and reutrns it. If no layer with that name exists, nil is returned.

type Layer

type Layer struct {
	*image.RGBA
	Name    string
	Visible bool
	Opacity uint8
}

A Layer is a rectangular pixel area. Its bounds are relative to the Canvas' origin, which is at 0,0. The bounds can lie outside the canvas. Each layer is itself an image.Image (*image.RGBA is an image.Image). The image data contains the unmodified pixels, the Visibility and Opacity are stored separately. You have to mask in the opacity if you want to draw the layer onto another image.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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