| 99 | } |
| 100 | |
| 101 | void ImageDisplayDriver::imageData( const Box2i &box, const float *data, size_t dataSize ) |
| 102 | { |
| 103 | Box2i tmpBox = box; |
| 104 | Box2i dataWindow = m_image->getDataWindow(); |
| 105 | tmpBox.extendBy( dataWindow ); |
| 106 | if ( tmpBox != dataWindow ) |
| 107 | { |
| 108 | throw Exception("The box is outside image data window."); |
| 109 | } |
| 110 | |
| 111 | int pixelSize = channelNames().size(); |
| 112 | if ( dataSize != (box.max.x - box.min.x + 1) * (box.max.y - box.min.y + 1) * channelNames().size() ) |
| 113 | { |
| 114 | throw Exception("Invalid dataSize value."); |
| 115 | } |
| 116 | |
| 117 | int channelId, targetX, targetY, sourceWidth, sourceHeight, targetWidth; |
| 118 | sourceWidth = box.max.x - box.min.x + 1; |
| 119 | sourceHeight = box.max.y - box.min.y + 1; |
| 120 | targetWidth = dataWindow.max.x - dataWindow.min.x + 1; |
| 121 | channelId = 0; |
| 122 | targetX = box.min.x - dataWindow.min.x; |
| 123 | targetY = box.min.y - dataWindow.min.y; |
| 124 | |
| 125 | for( const auto &name : channelNames() ) |
| 126 | { |
| 127 | vector< float > &target = boost::static_pointer_cast< FloatVectorData >( m_image->channels[name] )->writable(); |
| 128 | vector< float >::iterator targetIt; |
| 129 | const float *sourceIt = data+channelId; |
| 130 | targetIt = target.begin()+targetWidth*targetY+targetX; |
| 131 | |
| 132 | for ( int y = 0; y < sourceHeight; y++ ) |
| 133 | { |
| 134 | for ( int x = 0; x < sourceWidth; x++ ) |
| 135 | { |
| 136 | *targetIt = *sourceIt; |
| 137 | sourceIt += pixelSize; |
| 138 | targetIt++; |
| 139 | } |
| 140 | targetIt += targetWidth - sourceWidth; |
| 141 | } |
| 142 | |
| 143 | ++channelId; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void ImageDisplayDriver::imageClose() |
| 148 | { |