167
defaultFormat (Compressor * compressor)
169
return compressor? compressor->format(): Compressor::XDR;
174
numLinesInBuffer (Compressor * compressor)
176
return compressor? compressor->numScanLines(): 1;
181
copyIntoFrameBuffer (const char *& readPtr,
187
Compressor::Format format,
188
PixelType typeInFrameBuffer,
189
PixelType typeInFile)
192
// Copy a horizontal row of pixels from an input
193
// file's line or tile buffer to a frame buffer.
199
// The file contains no data for this channel.
200
// Store a default value in the frame buffer.
203
switch (typeInFrameBuffer)
208
unsigned int fillVal = (unsigned int) (fillValue);
210
while (writePtr <= endPtr)
212
*(unsigned int *) writePtr = fillVal;
221
half fillVal = half (fillValue);
223
while (writePtr <= endPtr)
225
*(half *) writePtr = fillVal;
234
float fillVal = float (fillValue);
236
while (writePtr <= endPtr)
238
*(float *) writePtr = fillVal;
246
throw Iex::ArgExc ("Unknown pixel data type.");
249
else if (format == Compressor::XDR)
252
// The the line or tile buffer is in XDR format.
254
// Convert the pixels from the file's machine-
255
// independent representation, and store the
256
// results in the frame buffer.
259
switch (typeInFrameBuffer)
267
while (writePtr <= endPtr)
269
Xdr::read <CharPtrIO> (readPtr, *(unsigned int *) writePtr);
276
while (writePtr <= endPtr)
279
Xdr::read <CharPtrIO> (readPtr, h);
280
*(unsigned int *) writePtr = halfToUint (h);
287
while (writePtr <= endPtr)
290
Xdr::read <CharPtrIO> (readPtr, f);
291
*(unsigned int *)writePtr = floatToUint (f);
304
while (writePtr <= endPtr)
307
Xdr::read <CharPtrIO> (readPtr, ui);
308
*(half *) writePtr = uintToHalf (ui);
315
while (writePtr <= endPtr)
317
Xdr::read <CharPtrIO> (readPtr, *(half *) writePtr);
324
while (writePtr <= endPtr)
327
Xdr::read <CharPtrIO> (readPtr, f);
328
*(half *) writePtr = floatToHalf (f);
341
while (writePtr <= endPtr)
344
Xdr::read <CharPtrIO> (readPtr, ui);
345
*(float *) writePtr = float (ui);
352
while (writePtr <= endPtr)
355
Xdr::read <CharPtrIO> (readPtr, h);
356
*(float *) writePtr = float (h);
363
while (writePtr <= endPtr)
365
Xdr::read <CharPtrIO> (readPtr, *(float *) writePtr);
374
throw Iex::ArgExc ("Unknown pixel data type.");
380
// The the line or tile buffer is in NATIVE format.
381
// Copy the results into the frame buffer.
384
switch (typeInFrameBuffer)
392
while (writePtr <= endPtr)
394
for (size_t i = 0; i < sizeof (unsigned int); ++i)
395
writePtr[i] = readPtr[i];
397
readPtr += sizeof (unsigned int);
404
while (writePtr <= endPtr)
406
half h = *(half *) readPtr;
407
*(unsigned int *) writePtr = halfToUint (h);
408
readPtr += sizeof (half);
415
while (writePtr <= endPtr)
419
for (size_t i = 0; i < sizeof (float); ++i)
420
((char *)&f)[i] = readPtr[i];
422
*(unsigned int *)writePtr = floatToUint (f);
423
readPtr += sizeof (float);
436
while (writePtr <= endPtr)
440
for (size_t i = 0; i < sizeof (unsigned int); ++i)
441
((char *)&ui)[i] = readPtr[i];
443
*(half *) writePtr = uintToHalf (ui);
444
readPtr += sizeof (unsigned int);
451
while (writePtr <= endPtr)
453
*(half *) writePtr = *(half *)readPtr;
454
readPtr += sizeof (half);
461
while (writePtr <= endPtr)
465
for (size_t i = 0; i < sizeof (float); ++i)
466
((char *)&f)[i] = readPtr[i];
468
*(half *) writePtr = floatToHalf (f);
469
readPtr += sizeof (float);
482
while (writePtr <= endPtr)
486
for (size_t i = 0; i < sizeof (unsigned int); ++i)
487
((char *)&ui)[i] = readPtr[i];
489
*(float *) writePtr = float (ui);
490
readPtr += sizeof (unsigned int);
497
while (writePtr <= endPtr)
499
half h = *(half *) readPtr;
500
*(float *) writePtr = float (h);
501
readPtr += sizeof (half);
508
while (writePtr <= endPtr)
510
for (size_t i = 0; i < sizeof (float); ++i)
511
writePtr[i] = readPtr[i];
513
readPtr += sizeof (float);
522
throw Iex::ArgExc ("Unknown pixel data type.");
529
skipChannel (const char *& readPtr,
530
PixelType typeInFile,
537
Xdr::skip <CharPtrIO> (readPtr, Xdr::size <unsigned int> () * xSize);
542
Xdr::skip <CharPtrIO> (readPtr, Xdr::size <half> () * xSize);
547
Xdr::skip <CharPtrIO> (readPtr, Xdr::size <float> () * xSize);
552
throw Iex::ArgExc ("Unknown pixel data type.");
558
convertInPlace (char *& writePtr,
559
const char *& readPtr,
567
for (int j = 0; j < numPixels; ++j)
569
Xdr::write <CharPtrIO> (writePtr, *(const unsigned int *) readPtr);
570
readPtr += sizeof(unsigned int);
576
for (int j = 0; j < numPixels; ++j)
578
Xdr::write <CharPtrIO> (writePtr, *(const half *) readPtr);
579
readPtr += sizeof(half);
585
for (int j = 0; j < numPixels; ++j)
587
Xdr::write <CharPtrIO> (writePtr, *(const float *) readPtr);
588
readPtr += sizeof(float);
594
throw Iex::ArgExc ("Unknown pixel data type.");
600
copyFromFrameBuffer (char *& writePtr,
601
const char *& readPtr,
604
Compressor::Format format,
608
// Copy a horizontal row of pixels from a frame
609
// buffer to an output file's line or tile buffer.
612
if (format == Compressor::XDR)
615
// The the line or tile buffer is in XDR format.
622
while (readPtr <= endPtr)
624
Xdr::write <CharPtrIO> (writePtr,
625
*(const unsigned int *) readPtr);
632
while (readPtr <= endPtr)
634
Xdr::write <CharPtrIO> (writePtr, *(const half *) readPtr);
641
while (readPtr <= endPtr)
643
Xdr::write <CharPtrIO> (writePtr, *(const float *) readPtr);
650
throw Iex::ArgExc ("Unknown pixel data type.");
656
// The the line or tile buffer is in NATIVE format.
663
while (readPtr <= endPtr)
665
for (size_t i = 0; i < sizeof (unsigned int); ++i)
666
*writePtr++ = readPtr[i];
674
while (readPtr <= endPtr)
676
*(half *) writePtr = *(const half *) readPtr;
677
writePtr += sizeof (half);
684
while (readPtr <= endPtr)
686
for (size_t i = 0; i < sizeof (float); ++i)
687
*writePtr++ = readPtr[i];
695
throw Iex::ArgExc ("Unknown pixel data type.");
702
fillChannelWithZeroes (char *& writePtr,
703
Compressor::Format format,
707
if (format == Compressor::XDR)
710
// Fill with data in XDR format.
717
for (int j = 0; j < xSize; ++j)
718
Xdr::write <CharPtrIO> (writePtr, (unsigned int) 0);
724
for (int j = 0; j < xSize; ++j)
725
Xdr::write <CharPtrIO> (writePtr, (half) 0);
731
for (int j = 0; j < xSize; ++j)
732
Xdr::write <CharPtrIO> (writePtr, (float) 0);
738
throw Iex::ArgExc ("Unknown pixel data type.");
744
// Fill with data in NATIVE format.
751
for (int j = 0; j < xSize; ++j)
753
static const unsigned int ui = 0;
755
for (size_t i = 0; i < sizeof (ui); ++i)
756
*writePtr++ = ((char *) &ui)[i];
762
for (int j = 0; j < xSize; ++j)
764
*(half *) writePtr = half (0);
765
writePtr += sizeof (half);
771
for (int j = 0; j < xSize; ++j)
773
static const float f = 0;
775
for (size_t i = 0; i < sizeof (f); ++i)
776
*writePtr++ = ((char *) &f)[i];
782
throw Iex::ArgExc ("Unknown pixel data type.");
154
787
} // namespace Imf