OpenImageIO/oiio — pull request #490 by lgritz (2013-01-19 04:47:31+00:00)
Title: Break out maketx functionality into callable ImageBufAlgo::make_texture()

It's been long requested to have an API call that converts an image to a texture without having to launch maketx as a separate process.

This is a pretty big overhaul, and here is part 1: split much of the guts of maketx into src/libOpenImageIO/maketexture.cpp, callable as

ImageBufAlgo::make_texture (mode, inputfilename, outputfilename, config, outstream)

The 'config' argument is an ImageSpec, and that's how you pass all the extra information about how to do the maketx process (some is naturally metadata all along, like the wrap modes, others that control the process are prefixed like "maketx:constant_color_detect", which controls the process but does not actually store the metadata in the resulting file). The beauty of this is that future functionality can be added without changing the call signature of this function -- it just recognizes additional metadata signals in the 'config'. That makes it much easier to change or add maketx functionality without breaking link compatibility.

I'd like to backport this to 1.1, since some people really need it, and it only adds a new call and does not break backward compatibility or change old behavior.

I even make sure that there's no danger of breaking the old 'maketx' as follows: for now, BOTH the old code (all in maketx.cpp) and the new code (in maketexture.cpp, and maketx.cpp just is a thin wrapper to set up the config and call make_texture()) exist in maketx.cpp. In master, I will check it in so that by default it uses the new (wrapper) code, but you can use "maketx --old" to use the old code path (mainly as a hedge in case I've broken something, eventually this will be removed entirely), but when I backport to 1.1 I will reverse it so that by default it uses only old code (no risk) but you can try/test the new code with "maketx --new".

You can probably now surmise that my last pull request -- which set up the testsuite/maketx test of nearly all maketx functionality, and a small number of code fixes to make that possible -- was all specifically to enable this patch, and more specifically, to make sure I had a way to test maketx and be sure I wasn't breaking anything along the way or in the future as it undergoes additional refactoring.

There are three more phases to the project that are not yet done, and that in all likelihood will only be put in master (someday to be 1.2) and not backported to 1.1 because it's too invasive: (1) more extensive refactoring and improvement of the code in maketexture.cpp -- right now it's a very straightforward move of existing code from maketx.cpp, but it's crying out for reorganization; (2) massive performance and memory improvement of that code (already underway, with good results to be posted soon); (3) in addition to this patch giving a filename-to-filename way to make a texture, probably I will eventually additionally expose a way to write out a full MIPmapped texture starting from an ImageBuf (versus a filename of a saved file).