@@ -2308,13 +2308,6 @@ namespace ojph {
23082308 }
23092309 }
23102310
2311- if (bit_depth[comp_num] != 16 )
2312- {
2313- fprintf (stderr, " ERROR in file %s on line %d in function %s:\n bit_depth[%d] = %d, this software currently only supports reading 16-bit files\n " ,
2314- __FILE__, __LINE__, __FUNCTION__, comp_num, bit_depth[comp_num]);
2315- return 0 ;
2316- }
2317-
23182311 switch (comp_num)
23192312 {
23202313 case 0 :
@@ -2362,8 +2355,31 @@ namespace ojph {
23622355 {
23632356 fname = filename;
23642357 cur_line = 0 ;
2365- // allocate a framebuffer to hold decoded data
2366- pixels.resizeErase (height, width);
2358+ if (true == is_use_Rgba_interface)
2359+ {
2360+ // allocate a scanline to hold a line of decoded data
2361+ pixels.resizeErase (1 , width);
2362+
2363+ Imath::Box2i display_window (Imath::V2i (0 , 0 ), Imath::V2i (width - 1 , height - 1 ));
2364+ data_window.min .x = 0 ;
2365+ data_window.min .y = 0 ;
2366+ data_window.max .x = width - 1 ;
2367+ data_window.max .y = height - 1 ;
2368+ if (num_components == 4 )
2369+ {
2370+ rgba_output_file = new Imf::RgbaOutputFile (fname, display_window, data_window, Imf::WRITE_RGBA);
2371+ }
2372+ else if (num_components == 3 )
2373+ {
2374+ rgba_output_file = new Imf::RgbaOutputFile (fname, display_window, data_window, Imf::WRITE_RGB);
2375+ }
2376+ else
2377+ {
2378+ fprintf (stderr, " this software currently only supports writing EXR files with 3 or 4 components\n " );
2379+ exit (-1 );
2380+ }
2381+ }
2382+
23672383 is_open = true ;
23682384 return ;
23692385 }
@@ -2403,37 +2419,45 @@ namespace ojph {
24032419 fprintf (stderr, " not using RGBA interface\n " );
24042420 }
24052421
2422+
2423+
24062424 return ;
24072425 }
24082426
24092427 ui32 exr_out::write (const line_buf* line, ui32 comp_num)
24102428 {
24112429 if (true == this ->is_use_Rgba_interface )
24122430 {
2431+ // set framebuffer for first component
2432+ if (0 == comp_num)
2433+ {
2434+ rgba_output_file->setFrameBuffer (&pixels[0 ][0 ] - data_window.min .x - data_window.min .y * width, 1 , width);
2435+ }
2436+
24132437 switch (comp_num)
24142438 {
24152439 case 0 :
24162440 for (ui32 i = 0 ; i < width; i++)
24172441 {
2418- pixels[cur_line ][i].r .setBits ((si16)line->i32 [i]);
2442+ pixels[0 ][i].r .setBits ((si16)line->i32 [i]);
24192443 }
24202444 break ;
24212445 case 1 :
24222446 for (ui32 i = 0 ; i < width; i++)
24232447 {
2424- pixels[cur_line ][i].g .setBits ((si16)line->i32 [i]);
2448+ pixels[0 ][i].g .setBits ((si16)line->i32 [i]);
24252449 }
24262450 break ;
24272451 case 2 :
24282452 for (ui32 i = 0 ; i < width; i++)
24292453 {
2430- pixels[cur_line ][i].b .setBits ((si16)line->i32 [i]);
2454+ pixels[0 ][i].b .setBits ((si16)line->i32 [i]);
24312455 }
24322456 break ;
24332457 case 3 :
24342458 for (ui32 i = 0 ; i < width; i++)
24352459 {
2436- pixels[cur_line ][i].a .setBits ((si16)line->i32 [i]);
2460+ pixels[0 ][i].a .setBits ((si16)line->i32 [i]);
24372461 }
24382462 break ;
24392463 default :
@@ -2442,6 +2466,14 @@ namespace ojph {
24422466 return 0 ;
24432467 break ;
24442468 }
2469+
2470+ // write to file after last component has been populated in this line
2471+ if (comp_num == num_components - 1 )
2472+ {
2473+ rgba_output_file->writePixels (1 );
2474+ data_window.min .y ++;
2475+ }
2476+
24452477 }
24462478 else
24472479 {
@@ -2460,21 +2492,10 @@ namespace ojph {
24602492 {
24612493 if (true == is_use_Rgba_interface)
24622494 {
2463- Imf::RgbaOutputFile* file = NULL ;
2464- if (num_components == 4 )
2465- file = new Imf::RgbaOutputFile (fname, width, height, Imf::WRITE_RGBA);
2466- else if (num_components == 3 )
2467- file = new Imf::RgbaOutputFile (fname, width, height, Imf::WRITE_RGB);
2468- else
2469- {
2470- fprintf (stderr, " this software currently only supports writing EXR files with 3 or 4 components\n " );
2471- exit (-1 );
2472- }
2473- file->setFrameBuffer (&pixels[0 ][0 ], 1 , width);
2474- file->writePixels (height);
2495+ pixels.resizeErase (0 , 0 );
24752496
2476- if (NULL != file )
2477- delete file ;
2497+ if (NULL != rgba_output_file )
2498+ delete rgba_output_file ;
24782499 }
24792500 else
24802501 {
0 commit comments