openexr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Openexr-devel] Finding out if a file contains all tiles


From: Ken McGaugh
Subject: Re: [Openexr-devel] Finding out if a file contains all tiles
Date: Mon, 24 Apr 2006 18:33:38 +0100
User-agent: Thunderbird 1.5.0.2 (X11/20060420)

David Larsson wrote:
Hi,
I wonder if there is a fast way to figure out if an exr-file is missing any tiles, preferably not involving reading all tiles.


We have a little utility which checks exr's to see if they
are complete, and I've attached the source below.  It is
fast and works on both scanline and tiled exr's so long as
the exrs are *not* stored with RANDOM_Y line order.  For
those cases I think you will have to read every scanline/tile.

Basically all it does it try to read the last scanline that
should have been stored in the exr.  If it fails then the file
isn't complete.

--Ken
//-----------------------------------------------------------------------------
//
//      Utility program to check if a file is a valid and complete exr.
//  If exr is OK, 0 is returned and there is no output.
//  If exr is not OK, 1 is returned and there is output to stderr.
//
//-----------------------------------------------------------------------------

#include <ImfInputFile.h>
#include <ImathBox.h>
#include <half.h>
#include <exception>
#include <iostream>
#include <iomanip>

using namespace Imf;
using namespace Imath;
using namespace Iex;
using std::cout;
using std::cerr;
using std::endl;


int
main( int argc, char **argv )
{
    half *buf = NULL;

    if ( argc < 2 )
    {
        cerr << "usage: " << argv[0] << " imagefile" << endl;
        return 1;
    }

    try
    {
        //
        // Open the file
        //

        InputFile in (argv[1]);

        const Box2i &dw = in.header().dataWindow();
        const int width = dw.max.x - dw.min.x + 1;
        int scanLine;


        //
        // Determine which scanline is the
        // last one in the file.
        //
        // TODO: figure out how to handle RANDOM_Y
        // scanline images and tiled images.
        //

        switch ( in.header().lineOrder() )
        {
        case INCREASING_Y:
            scanLine = dw.max.y;
            break;
        case DECREASING_Y:
            scanLine = dw.min.y;
            break;
        default:
            cerr << "Unknown lineOrder: " << in.header().lineOrder() << endl;
            return 1;
        }


        //
        // Allocate a buffer large enough to hold one
        // scanline worth of single-channel pixels
        //

        buf = new half [width*2];
        FrameBuffer frameBuffer;

        frameBuffer.insert( "R",                                               
// name
                            Slice( HALF,                   // type
                                   (char *) (buf -         // base
                                             dw.min.x -
                                             scanLine * width),
                                   sizeof(half),           // xStride
                                   sizeof(half) * width)); // yStride
        in.setFrameBuffer( frameBuffer );


        //
        // Read the last scanline in the file
        //

        in.readPixels( scanLine );

    }
        catch ( const std::exception &e )
        {
            cerr << e.what() << endl;
            return 1;
        }

    delete buf;

    return 0;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]