Alien-FreeImage

 view release on metacpan or  search on metacpan

src/Source/OpenEXR/IlmImf/ImfOutputFile.cpp  view on Meta::CPAN



LineBuffer::~LineBuffer ()
{
    delete compressor;
}

} // namespace

struct OutputFile::Data
{
    Header		 header;		// the image header
    bool                 multiPart;		// is the file multipart?
    int			 version;               // version attribute \todo NOT BEING WRITTEN PROPERLY
    Int64		 previewPosition;       // file position for preview
    FrameBuffer		 frameBuffer;           // framebuffer to write into
    int			 currentScanLine;       // next scanline to be written
    int			 missingScanLines;      // number of lines to write
    LineOrder		 lineOrder;		// the file's lineorder
    int			 minX;			// data window's min x coord
    int			 maxX;			// data window's max x coord
    int			 minY;			// data window's min y coord
    int			 maxY;			// data window's max x coord
    vector<Int64>	 lineOffsets;		// stores offsets in file for
						// each scanline
    vector<size_t>	 bytesPerLine;          // combined size of a line over
                                                // all channels
    vector<size_t>	 offsetInLineBuffer;    // offset for each scanline in
                                                // its linebuffer
    Compressor::Format	 format;                // compressor's data format
    vector<OutSliceInfo> slices;		// info about channels in file
    Int64		 lineOffsetsPosition;   // file position for line
                                                // offset table

    vector<LineBuffer*>  lineBuffers;           // each holds one line buffer
    int			 linesInBuffer;         // number of scanlines each
                                                // buffer holds
    size_t		 lineBufferSize;        // size of the line buffer

    int                  partNumber;            // the output part number
    OutputStreamMutex *  _streamData;         
    bool                 _deleteStream;
     Data (int numThreads);
    ~Data ();


    inline LineBuffer *	getLineBuffer (int number); // hash function from line
    						    // buffer indices into our
						    // vector of line buffers
};


OutputFile::Data::Data (int numThreads):
    lineOffsetsPosition (0),
    partNumber (-1),
    _streamData(0),
    _deleteStream(false)
{
    //
    // We need at least one lineBuffer, but if threading is used,
    // to keep n threads busy we need 2*n lineBuffers.
    //

    lineBuffers.resize (max (1, 2 * numThreads));
}


OutputFile::Data::~Data ()
{
    for (size_t i = 0; i < lineBuffers.size(); i++)
        delete lineBuffers[i];
}


LineBuffer*
OutputFile::Data::getLineBuffer (int number)
{
    return lineBuffers[number % lineBuffers.size()];
}

namespace {

Int64
writeLineOffsets (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, const vector<Int64> &lineOffsets)
{
    Int64 pos = os.tellp();

    if (pos == -1)
	IEX_NAMESPACE::throwErrnoExc ("Cannot determine current file position (%T).");
    
    for (unsigned int i = 0; i < lineOffsets.size(); i++)
	Xdr::write<StreamIO> (os, lineOffsets[i]);

    return pos;
}


void
writePixelData (OutputStreamMutex *filedata,
                OutputFile::Data *partdata,
                int lineBufferMinY,
                const char pixelData[],
                int pixelDataSize)
{
    //
    // Store a block of pixel data in the output file, and try
    // to keep track of the current writing position the file
    // without calling tellp() (tellp() can be fairly expensive).
    //

    Int64 currentPosition = filedata->currentPosition;
    filedata->currentPosition = 0;

    if (currentPosition == 0)
        currentPosition = filedata->os->tellp();

    partdata->lineOffsets[(partdata->currentScanLine - partdata->minY) / partdata->linesInBuffer] =
        currentPosition;

    #ifdef DEBUG



( run in 0.837 second using v1.01-cache-2.11-cpan-5a3173703d6 )