A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/houz/libxcf.git below:

houz/libxcf: Small library for writing GIMP XCF files

libxcf is a small stand alone library for writing GIMP XCF files. Reading of XCF files is not in the scope right now. Rendering will never be.

If you don't want to use CMake it should be straight forward to add the files to whatever you use instead.

You can either build the library as a stand alone lib or copy it into your source tree and add it as a sub directory to your CMake project. The latter is preferred as long as the API is not considered stable. Also there is no install target yet ...

$ git clone ...
$ cd libxcf
$ mkdir build
$ cd build
$ cmake ..
$ make

This should leave you with a static library in libxcf.a.

The API is somewhat inspired by libtiff in the sense that you open an XCF file, set properties and add data and close it in the end.

The XCF file is always in some specific internal state, depending on which you can set some things. The basic control flow is

  1. create the image
  2. set everything at image level
  3. create layer or channel
  4. set everything at the layer/channel level
  5. add pixel data
  6. go to 3 until all layers and channels were added
  7. close the image

The functions to do so are:

All functions return 0 on error.

By default a version 12 file with ZLIB compression will be generated.

For ease of reading almost all error handling was omitted.

#include "xcf.h"

void write_image(const char *filename,
                 const float *data,
                 const int width,
                 const int height,
                 const int channels)
{
  XCF *xcf = xcf_open(filename);

  if(!xcf)
  {
    fprintf(stderr, "error: can't open '%s'\n", filename);
    return;
  }

  // we have created the file but didn't add a layer or channel yet.
  // this is the time for setting image level things
  xcf_set(xcf, XCF_BASE_TYPE, XCF_BASE_TYPE_RGB);
  xcf_set(xcf, XCF_WIDTH, width);
  xcf_set(xcf, XCF_HEIGHT, height);
  xcf_set(xcf, XCF_PRECISION, XCF_PRECISION_F_32_L);
  xcf_set(xcf, XCF_N_LAYERS, 1);

  // set a property
  xcf_set(xcf, XCF_PROP, XCF_PROP_COMPRESSION, XCF_PROP_COMPRESSION_NONE);

  // when setting parasites make sure to pass the
  // correct size, including the '\0' for strings!
  const char *comment = "this file was generated by libxcf";
  xcf_set(xcf,
          XCF_PROP,                // the field to set
          XCF_PROP_PARASITES,      // it's a parasite
          "gimp-comment",          // name of the parasite
          XCF_PARASITE_PERSISTENT, // parasite flags
          strlen(comment) + 1,     // size of payload
          comment);                // pointer to payload

  // add the layer and then change settings on the layer level
  xcf_add_layer(xcf);
  xcf_set(xcf, XCF_WIDTH, width);
  xcf_set(xcf, XCF_HEIGHT, height);
  xcf_set(xcf, XCF_NAME, "base layer");
  xcf_add_data(xcf, data, channels);

  // done
  xcf_close(xcf);
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4