| 69 | } |
| 70 | |
| 71 | void ImageSourceFileRadiance::loadStream( IStreamRef stream ) |
| 72 | { |
| 73 | setDataType( ImageIo::FLOAT32 ); |
| 74 | setColorModel( ImageIo::CM_RGB ); |
| 75 | setChannelOrder( ImageIo::RGB ); |
| 76 | |
| 77 | char str[200]; |
| 78 | stream->readData( str, 10 ); |
| 79 | if (memcmp(str, "#?RADIANCE", 10)) { |
| 80 | // check RBGE |
| 81 | if (memcmp(str, "#?RGBE", 6)) { |
| 82 | throw ImageSourceFileRadianceException("Invalid header"); |
| 83 | } |
| 84 | else { |
| 85 | // move back the stream and continue parsing |
| 86 | stream->seekRelative(-4); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | stream->seekRelative( 1 ); |
| 91 | |
| 92 | char cmd[200]; |
| 93 | int i = 0; |
| 94 | char c = 0, oldc; |
| 95 | while( true ) { |
| 96 | oldc = c; |
| 97 | stream->read( &c ); |
| 98 | if( c == 0xa && oldc == 0xa ) |
| 99 | break; |
| 100 | cmd[i++] = c; |
| 101 | } |
| 102 | |
| 103 | char resolution[200]; |
| 104 | i = 0; |
| 105 | while( true ) { |
| 106 | stream->read( &c ); |
| 107 | resolution[i++] = c; |
| 108 | if( c == 0xa ) |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | int width, height; |
| 113 | if( ! sscanf( resolution, "-Y %d +X %d", &height, &width ) ) |
| 114 | throw ImageSourceFileRadianceException( "Unable to parse size" ); |
| 115 | setSize( width, height ); |
| 116 | |
| 117 | mRgbData = std::unique_ptr<float[]>( new float[width * height * 3] ); |
| 118 | std::unique_ptr<RgbePixel[]> scanline( new RgbePixel[width] ); |
| 119 | |
| 120 | // convert image |
| 121 | float *cols = mRgbData.get(); |
| 122 | for( int y = height - 1; y >= 0; y-- ) { |
| 123 | if( ! decrunchScanline( scanline.get(), width, stream.get() ) ) |
| 124 | break; |
| 125 | workOnRgbeScanline( scanline.get(), width, cols ); |
| 126 | cols += width * 3; |
| 127 | } |
| 128 | } |
nothing calls this directly
no test coverage detected