Nick Bowler [Fri, 31 Jan 2014 03:32:28 +0000 (22:32 -0500)]
liblbx: Remove use of SEEK_CUR in the image reader.
Other than this one seek, all other seeks used by the library are of the
SEEK_SET type. Only requiring SEEK_SET will simplify implementations of
lbx_file_ops quite a lot, so let's get rid of this one.
The whole point of this seek is to skip just one byte — a normal read
works just as well.
Nick Bowler [Fri, 31 Jan 2014 03:17:43 +0000 (22:17 -0500)]
liblbx: Add a hard check for image leadin versus frame count.
Our "official" image spec says that the leadin is a frame number, so
it does not make sense for the leadin to be greater than or equal to
the frame count.
Convert the existing "soft" check into a hard failure.
Nick Bowler [Fri, 31 Jan 2014 03:00:27 +0000 (22:00 -0500)]
liblbx: Clean up embedded palette handling
We don't need to read the embedded palette information with the rest of
the header, we can defer that to much later when the palette is actually
needed. This makes more sense conceptually, simplifies the code a bit,
and saves some bytes in the image state structure.
Since we're basically rewriting lbx_img_getpalette anyway, take this
opportunity to give it a better interface. It now returns the number
of embedded palette entries, allowing us to eliminate the palette size
feature in lbx_img_getinfo.
Nick Bowler [Wed, 29 Jan 2014 00:34:17 +0000 (19:34 -0500)]
lbxgui: Use Cairo for drawing.
The GDK stuff is deprecated so let's convert all the GDK drawing bits to
Cairo. Unlike GDK, Cairo does not include an XBM loader so we have to
implement that from scratch.
Nick Bowler [Tue, 28 Jan 2014 02:43:42 +0000 (21:43 -0500)]
liblbx: Fix uninitialized value warning in pipe_seek.
If whence is invalid then we will proceed with an uninitialized value.
However, unlike the similar problem in lbx_file_seek, pipe_seek is an
internal function so this scenario can Never Happen™.
Nick Bowler [Tue, 28 Jan 2014 01:10:30 +0000 (20:10 -0500)]
tests: Enable shell traces early in all scripts.
The result_ function we snarfed from Automake turns on set -x in our
test suite, but since we do not enable it from the beginning the test
logs have traces starting from the first test result and not before.
The result is very strange; enable traces early so we see everything.
Nick Bowler [Tue, 28 Jan 2014 01:03:34 +0000 (20:03 -0500)]
lbximg: Fix management of external palette file handles.
We leak file handles for the external and override palettes because the
file is opened every time the --palette or --override options are set.
Fix that up, and also close the handles when finished.
Nick Bowler [Fri, 24 Jan 2014 00:06:08 +0000 (19:06 -0500)]
docs: Add palette information for the tanm_xxx animations.
I thought these all had embedded palettes but at least tanm_001
has some unspecified palette entries. The only palette for this
image that does not look horrible is fonts.lbx.002, so let's go
with that one.
Nick Bowler [Thu, 23 Jan 2014 03:04:38 +0000 (22:04 -0500)]
build: Remove call to AC_CONFIG_MACRO_DIR.
This macro never did anything useful and should not be used. The new-
fangled way is AC_CONFIG_MACRO_DIRS which might even work, but stick
with the tried-and-true method for now.
Nick Bowler [Thu, 23 Jan 2014 02:30:01 +0000 (21:30 -0500)]
lbximg: Convert to new decoding API.
Convert lbximg to the new API. The implementation looks a lot
like getframe, but we can make the memory usage much more compact.
Not really a coincidence because getframe was originally designed
to support this application.
Nick Bowler [Thu, 23 Jan 2014 02:13:45 +0000 (21:13 -0500)]
liblbx: Implement new image reading API.
Add a new API which allows the application to essentially loop over
the drawing commands in an LBX frame. This requires no runtime memory
allocations in the library, pushing all that out to the caller.
Conceptually this simplifies many applications because they can use
this to handle image data row-at-a-time.
For now, keep the old getframe function but change it to use the new
API under the hood.
Nick Bowler [Thu, 23 Jan 2014 01:50:33 +0000 (20:50 -0500)]
tests: Source image header in a subshell.
Use a subshell when sourcing the image header in pam-formats so that
the shell variables do not persist past the end of the test. While
unlikely, a value left over from an earlier test might result in
false positives in later tests.
Nick Bowler [Thu, 23 Jan 2014 01:14:16 +0000 (20:14 -0500)]
tests: Add info on what each MOO2 image is actually testing.
Each MOO2 test image was selected to test a particular feature of the
image decoder. That information was in the old regress.zsh script but
for some reason got dropped in the conversion. Add that information
back as a TAP diagnostic line for each image.
Nick Bowler [Thu, 23 Jan 2014 01:12:02 +0000 (20:12 -0500)]
tests: Zero out transparent pixels before calculating digest.
The colour value of transparent pixels is irrelevant from a correctness
perspective, but we are nevertheless including that information in the
tests. While we could zero out the values in the PAM output code it's
better to make the tests more robust.
This adds an external dependency on netpbm's pamarith and pamchannel
tools for the test suite. Restructure the tests so that these tools
are optional. If the tools are not available (or not working) then we
must accept the fact that images with an alpha channel may have false
negatives (but not false positives) -- record a SKIP result for an MD5
mismatch in that case.
Nick Bowler [Thu, 23 Jan 2014 01:06:27 +0000 (20:06 -0500)]
tests: Remove toplevel set -e usage.
Using set -e at the top level affects the entire script and makes it
difficult to work with commands that may legitimately return an error.
Regardless, set -e is still not so great for error checks because it
has some incredibly non-obvious semantics.
Better to just have correct error checks everywhere. Fortunately, this
is the case for almost all the existing test code -- only the testdir
creation needs fixing.
Nick Bowler [Thu, 2 Jan 2014 01:33:18 +0000 (20:33 -0500)]
liblbx: Expose image lead-in in public struct.
Since we've finally defined the meaning of this value it makes sense to
expose it to the user. This eliminates another need for lbx_img_getinfo,
but maintain the old functionality there for now.
Nick Bowler [Tue, 17 Dec 2013 04:49:30 +0000 (23:49 -0500)]
lbximg: Fix wart in frame scanline header format
The format of frame scanlines has been a little weird since day 1: We
had 2 "types" of scanline headers disambiguated by some non-trivial
logic, including whether or not it was the first decoded scanline in
the frame.
Here's a new, simpler approach, which has only one type of scanline
header, consistent meanings to the header fields, and by interpreting
the first 4 bytes as a "frame header" we get rid of the special case
for the first scanline, too.
Add a document in English which describes the LBX image file format, to
be used as the baseline format specification going forward.
Finally, update the contrived test cases for the new format. All the
test cases using actual MOO2 data still pass.
Nick Bowler [Tue, 17 Dec 2013 01:01:57 +0000 (20:01 -0500)]
lbximg: Return failure if there was a decoding error.
If any frame was not decoded because liblbx returned an error, we should
return a non-zero exit status from the tool. Previously this would only
happen if *all* frames failed.
Nick Bowler [Fri, 21 Jun 2013 14:22:48 +0000 (10:22 -0400)]
liblbx: Fix framebuffer allocation for 0x0 images.
The allocation strategy for the framebuffer is the "array2" method from
c-faq: an array of row pointers into a single large array containing all
rows. This was not being freed correctly in the case with 0 rows, since
there would be no pointer to the row data at all in order to free it.
Fix that up by simply allocating a 1x1 framebuffer when it would
otherwise be empty. While we're at it, also add an overflow check
on the multiplication.
Nick Bowler [Wed, 19 Jun 2013 01:07:51 +0000 (21:07 -0400)]
lbximg: Add an option to control the output filenames.
This will be needed for postmortem analysis of test cases that extract
multiple images, since otherwise there is no easy way to prevent the
tool from overwriting the earlier outputs.
This was clearly intended to be a user setting from the start but for
some reason it was never wired up to a command-line option.
Nick Bowler [Fri, 14 Jun 2013 22:15:25 +0000 (18:15 -0400)]
lbximg: Make libpng a soft dependency.
Now that we have Netpbm output formats which do not depend on
any external libraries, we can make it possible to build lbximg
without libpng. Adjust the build system so that lbximg is built
unconditionally and PNG output can be selectively disabled.
Nick Bowler [Fri, 14 Jun 2013 22:11:46 +0000 (18:11 -0400)]
lbximg: Add support for Netpbm output.
These netpbm formats are extremely simple image formats which can
be written with a very small amount of code. Implement the ASCII
PBM and PPM formats for eventual use in test scripts, and PAM as a
fully-featured format so that we can make libpng optional.
Nick Bowler [Fri, 14 Jun 2013 01:57:11 +0000 (21:57 -0400)]
liblbx: Don't scale palette values internally.
Output the 18-bit palette values unadulterated, leaving it up to the
users to do conversion if necessary. Push the conversion down into the
consumers (currently PNG output and the GTK GUI) where a 24-bit palette
is required.
While we're at it, adjust the conversion to scale to the full output
range of [0, 255]. This is a slight change to the output, so all the
image hashes need to be adjusted in the regression test.
Nick Bowler [Fri, 14 Jun 2013 01:23:52 +0000 (21:23 -0400)]
lbximg: Fix printf format string in identify mode.
One of the flag strings would never be printed because there was
simply not enough conversion specifiers in this format string. Fix
that up, and also adjust the length modifiers to match the actual
passed integer types.
Nick Bowler [Fri, 14 Jun 2013 01:16:36 +0000 (21:16 -0400)]
lbximg: Push no-palette mode down into the PNG writer.
This allows the writer to select the most appropriate output format to
support this mode. Switch the PNG writer to emit true grayscale images
in this case.
Nick Bowler [Wed, 12 Jun 2013 01:07:30 +0000 (21:07 -0400)]
liblbx: Properly report errors in lbx_(img_)fopen.
The lbx_fopen and lbx_img_fopen functions were not properly pushing an
error code when they failed, leading to extremely helpful messages of
the form:
lbximg: failed to open image: Success.
It further turns out that pushing negative errors (i.e., -errno) was
documented but never actually tested or used, so fix that up, too.
It is likely that many other sites are lacking appropriate calls to
lbx_error_raise, which can be added later.
Nick Bowler [Tue, 11 Jun 2013 22:29:07 +0000 (18:29 -0400)]
lbximg: Add a new PNG writing routine.
This splits out the PNG output from the rest of the lbximg processing,
so that it will be easier to add additional output formats (in par-
ticular, it would be nice to have some sort of text-based format to
facilitate automated testing).
Take this opportunity to vastly improve the error handling.
Nick Bowler [Thu, 11 Feb 2010 05:06:54 +0000 (00:06 -0500)]
lbxgui: Implement frame dropping for animation.
Currently, if it takes longer than 1/15th of a second to draw a frame,
the next frame will be queued before it has a chance to finish, which
then takes longer than 1/15th of a second to draw, so the next one gets
queued, ad infinitum.
We do two things to solve this problem. First, the timer runs at a
low priority so that a redraw doesn't get queued while a redraw is in
progress. Second, the timer skips queueing any frames that have missed
their time.
Nick Bowler [Thu, 11 Feb 2010 00:08:25 +0000 (19:08 -0500)]
build: Implement a better GTK+ detection macro.
This macro uses the same ideas behind the libpng detection, does not
suffer from the POSIXLY_CORRECT nonsense, doesn't duplicate checks
for pkg-config, supports caching, and properly fails when it should.
Nick Bowler [Wed, 10 Feb 2010 06:24:37 +0000 (01:24 -0500)]
lbxgui: Fix pointer type error.
The XBM format is an array of unsigned char, yet for some reason
unknown to me, the gdk_bitmap_create_from_data function wants a
char pointer. Add the appropriate cast.
Nick Bowler [Wed, 10 Feb 2010 05:40:17 +0000 (00:40 -0500)]
lbxgui: Compile in the glade UI description.
I don't think it makes any sense to try and jump through hoops to find
this data at runtime, given that the data and the code are so intimately
connected.
Nick Bowler [Tue, 9 Feb 2010 05:27:30 +0000 (00:27 -0500)]
liblbx: Add support for "chunked" images.
It appears that the frame count fields aren't actually two 16-bit
fields, but rather four 8-bit fields. The images in monster.lbx
appear to have "chunks" of animation and what was previously thought to
be the most significant byte of the lead-in now seems to be the length
of a "chunk".
These images are much like any other, except that the first frame of
every chunk is drawn on a clean slate. Examples are found in
monster.lbx.
Nick Bowler [Tue, 9 Feb 2010 04:14:16 +0000 (23:14 -0500)]
liblbx: Add support for "raw" LBX images.
There is a new image format in town. If a particular flag bit is set,
then there are no row headers and data for every pixel of a frame is
simply stored in row-major order. An example of such an image is
starbg.lbx.009, as well as several others in the same archive.
Don't you just *love* the designers of this format?
Nick Bowler [Mon, 8 Feb 2010 04:24:06 +0000 (23:24 -0500)]
liblbx: Add new flag.
Building images have a previously-unknown flag, 0x0800. The images have
a part that looks like a shadow, but it does not have any palette entry.
I suspect that this flag is related to that shadow.