Jump to content

XCF and PAM file format plugins


midora

Recommended Posts

I like to update the old XCF filetype plugin (GIMP native file format) because it just supports XCF <= v3 and needs an additional exe which converts the xcf to pdn which is then loaded. The current GIMP v2.10.x typically creates v11 or v12 XCF files.  These versions support 16/32bit channels (int or float) and zlib compression.

 

As an intermediate step I like to improve and extend the PAM filetype plugin. Because it is so easy to write and read. Just perfect for quick tests of the XCF compression.

PAM allows multiple images in a file but it does not support layers. So I like to extend the format keeping the compatibility to the PAM specification (which is quite old).

 

I'm adding some code here just to show how easy it is to write a single layer.

WIDTH, HEIGHT, DEPTH, MAXVAL, and TUPLTYPE are the keywords used in the standard.

I like to add MAXLAYER, LNAME, LVISIBLE, LMAXOPAC, LOPACITY, and LCOMBINE.

A layered PAM file will contain MAXLAYER+1 layer images.

// A PAM file consists of a sequence of one or more PAM images.
// MO: We may use this to support layers. Layer order in file should be bottom to top.
// There are no data, delimiters, or padding before, after, or between images.
// Each PAM image consists of a header followed immediately by a raster.
// The header begins with the ASCII characters "P7" followed by newline.This is the magic number.
// The header continues with an arbitrary number of lines of ASCII text.
// MO: But we may use UTF-8
// Each line ends with and is delimited by a newline character.
// Each header line consists of zero or more whitespace-delimited tokens or begins with "#".
// If it begins with "#" it is a comment and the rest of this specification does not apply to it.
// The type of header line is identified by its first token, which is 8 characters or less.
// A line with a first token ENDHDR is the last line in the header.
// MO: Should we add new TUPLTYPEs BGR and BGR_ALPHA?

// Start of PAM header and a comment
pamfs.Write(Encoding.UTF8.GetBytes("P7\n"));
pamfs.Write(Encoding.UTF8.GetBytes("# Generated by xcf2pam\n"));
// Standard PAM header lines
pamfs.Write(Encoding.UTF8.GetBytes("WIDTH " + layerPixelWidth + "\n"));
pamfs.Write(Encoding.UTF8.GetBytes("HEIGHT " + layePixelHeight + "\n"));
pamfs.Write(Encoding.UTF8.GetBytes("DEPTH " + layerChannelCount + "\n"));
pamfs.Write(Encoding.UTF8.GetBytes("MAXVAL " + ((1UL << (layerChannelBytesPerPixel * 8)) - 1) + "\n"));
pamfs.Write(Encoding.UTF8.GetBytes("TUPLTYPE " + "RGB_ALPHA" + "\n"));
// Additional Layered PAM header lines
pamfs.Write(Encoding.UTF8.GetBytes("MAXLAYER " + (layerPointers.Count - 1) + "\n"));
pamfs.Write(Encoding.UTF8.GetBytes("LNAME " + layerName + "\n"));
pamfs.Write(Encoding.UTF8.GetBytes("LVISIBLE " + (layerProperties.visible ? 1 : 0) + "\n"));
pamfs.Write(Encoding.UTF8.GetBytes("LMAXOPAC " + 255 + "\n"));
pamfs.Write(Encoding.UTF8.GetBytes("LOPACITY " + (int)(layerProperties.opacity * 255) + "\n"));
pamfs.Write(Encoding.UTF8.GetBytes("LCOMBINE " + layerProperties.blendMode.ToString().ToUpper() + "\n"));
// End of header
pamfs.Write(Encoding.UTF8.GetBytes("ENDHDR\n"));
// Raster data
pamfs.Write(layerRaster);

Feel free to add all kind of comments about this proposed extension of the PAM format (or none ;-).

 

 

 

midoras signature.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...