Changeset 10496
- Timestamp:
- 07/17/09 09:47:48 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp
r9637 r10496 620 620 class ReaderWriterJPEG : public osgDB::ReaderWriter 621 621 { 622 623 WriteResult::WriteStatus write_JPEG_file (std::ostream &fout,int image_width,int image_height,JSAMPLE* image_buffer,int quality = 100) const 624 { 622 623 WriteResult::WriteStatus write_JPEG_file (std::ostream &fout, const osg::Image &img, int quality = 100) const 624 { 625 int image_width = img.s(); 626 int image_height = img.t(); 625 627 if ( (image_width == 0) || (image_height == 0) ) 626 628 return WriteResult::ERROR_IN_WRITING_FILE; 629 630 J_COLOR_SPACE image_color_space = JCS_RGB; 631 int image_components = 3; 632 // Only cater for gray, alpha and RGB for now 633 switch(img.getPixelFormat()) { 634 case(GL_LUMINANCE): 635 case(GL_ALPHA): { 636 image_color_space = JCS_GRAYSCALE; 637 image_components = 1; 638 break; 639 } 640 case(GL_RGB): { 641 image_color_space = JCS_RGB; 642 image_components = 3; 643 break; 644 } 645 default: return WriteResult::ERROR_IN_WRITING_FILE; break; 646 } 647 648 JSAMPLE* image_buffer = (JSAMPLE*)(img.data()); 627 649 628 650 /* This struct contains the JPEG compression parameters and pointers to … … 681 703 cinfo.image_width = image_width; /* image width and height, in pixels */ 682 704 cinfo.image_height = image_height; 683 cinfo.input_components = 3; /* # of color components per pixel */684 cinfo.in_color_space = JCS_RGB; /* colorspace of input image */705 cinfo.input_components = image_components; /* # of color components per pixel */ 706 cinfo.in_color_space = image_color_space; /* colorspace of input image */ 685 707 /* Now use the library's routine to set default compression parameters. 686 708 * (You must set at least cinfo.in_color_space before calling this, … … 708 730 * more if you wish, though. 709 731 */ 710 row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */732 row_stride = image_width * image_components; /* JSAMPLEs per row in image_buffer */ 711 733 712 734 while (cinfo.next_scanline < cinfo.image_height) … … 834 856 osg::ref_ptr<osg::Image> tmp_img = new osg::Image(img); 835 857 tmp_img->flipVertical(); 836 WriteResult::WriteStatus ws = write_JPEG_file(fout, img.s(),img.t(),(JSAMPLE*)(tmp_img->data()),getQuality(options));858 WriteResult::WriteStatus ws = write_JPEG_file(fout, *(tmp_img.get()), getQuality(options)); 837 859 return ws; 838 860 }
