| 474 | } |
| 475 | |
| 476 | void ImageWriter::doWrite( const CompoundObject *operands ) |
| 477 | { |
| 478 | const ImagePrimitive *image = getImage(); |
| 479 | if( !image->channelsValid() ) |
| 480 | { |
| 481 | throw InvalidArgumentException( "ImageWriter: Invalid channels on image" ); |
| 482 | } |
| 483 | |
| 484 | const Box2i &dataWindow = image->getDataWindow(); |
| 485 | const Box2i &displayWindow = image->getDisplayWindow(); |
| 486 | |
| 487 | /// \todo: nearly everything below this point is copied from GafferImage::ImageWriter |
| 488 | /// Can we consolidate some of this into IECoreImage::OpenImageIOAlgo? |
| 489 | |
| 490 | ImageOutputPtr out = createImageOutput( fileName() ); |
| 491 | if( !out ) |
| 492 | { |
| 493 | throw IECore::Exception( OIIO::geterror() ); |
| 494 | } |
| 495 | |
| 496 | const std::string fileFormatName = out->format_name(); |
| 497 | const bool supportsDisplayWindow = (bool)out->supports( "displaywindow" ) && fileFormatName != "dpx"; |
| 498 | |
| 499 | ImageSpec spec( TypeDesc::UNKNOWN ); |
| 500 | |
| 501 | // Specify the display window. |
| 502 | spec.full_x = displayWindow.min.x; |
| 503 | spec.full_y = displayWindow.min.y; |
| 504 | spec.full_width = displayWindow.size().x + 1; |
| 505 | spec.full_height = displayWindow.size().y + 1; |
| 506 | |
| 507 | bool validDisplayWindow = supportsDisplayWindow && dataWindow.hasVolume(); |
| 508 | if( validDisplayWindow ) |
| 509 | { |
| 510 | spec.x = dataWindow.min.x; |
| 511 | spec.y = dataWindow.min.y; |
| 512 | spec.width = dataWindow.size().x + 1; |
| 513 | spec.height = dataWindow.size().y + 1; |
| 514 | } |
| 515 | else |
| 516 | { |
| 517 | spec.x = spec.full_x; |
| 518 | spec.y = spec.full_y; |
| 519 | spec.width = spec.full_width; |
| 520 | spec.height = spec.full_height; |
| 521 | } |
| 522 | |
| 523 | // Cleanse the image blindData and then add it to the spec |
| 524 | CompoundDataPtr metadata = image->blindData()->copy(); |
| 525 | metadata->writable().erase( "oiio:ColorSpace" ); |
| 526 | metadata->writable().erase( "oiio:Gamma" ); |
| 527 | metadata->writable().erase( "oiio:UnassociatedAlpha" ); |
| 528 | metadata->writable().erase( "fileFormat" ); |
| 529 | metadata->writable().erase( "dataType" ); |
| 530 | |
| 531 | metadataToImageSpecAttributes( metadata.get(), &spec ); |
| 532 | |
| 533 | setImageSpecFormatOptions( operands->member<const CompoundObject>( "formatSettings" ), &spec, out->format_name() ); |
nothing calls this directly
no test coverage detected