Opened 15 years ago
Closed 12 years ago
#1377 closed Patches (wontfix)
Add ability to save RGBA image as TIFF with associated-alpha (premultiplied) transparency channel.
Reported by: | Owned by: | Hailin Jin | |
---|---|---|---|
Milestone: | To Be Determined | Component: | gil USE GITHUB |
Version: | Boost Development Trunk | Severity: | Not Applicable |
Keywords: | GIL | Cc: | mateusz@… |
Description
At the moment, GIL cannot save an image with an "A" channel to a TIFF file. This patch adds this ability.
I added "GIL" as a keyword, since there's still no "GIL" component in the drop-down list.
Attachments (3)
Change History (8)
by , 15 years ago
Attachment: | GIL-TIFF-SaveRGBA.patch added |
---|
comment:1 by , 15 years ago
Component: | None → GIL |
---|---|
Owner: | set to |
comment:2 by , 14 years ago
You can not read TIFF images with alpha either.
I posted something to the mailing list: http://lists.boost.org/boost-users/2008/08/39259.php
comment:3 by , 14 years ago
I could not attach the dang patch, "Akismet" says it is spam.
Here is is cut-and-pasted into the wiki:
-
png_io_private.hpp
===================================================================
291 291 default: io_error("png_reader_color_convert::apply(): unknown combination of color type and bit depth"); 292 292 } 293 293 break; 294 case PNG_COLOR_TYPE_PALETTE: 295 io_error("png_reader_color_convert::apply(): cannot read png images with a pallette (yet)"); 296 294 297 default: io_error("png_reader_color_convert::apply(): unknown color type"); 295 298 } 296 299 png_read_end(_png_ptr,NULL); -
tiff_dynamic_io.hpp
===================================================================
56 56 class tiff_type_format_checker { 57 57 int _bit_depth; 58 58 int _color_type; 59 unsigned short _samples_per_pixel; 59 60 public: 60 tiff_type_format_checker(int bit_depth_in,int color_type_in) : 61 _bit_depth(bit_depth_in),_color_type(color_type_in) {} 61 tiff_type_format_checker( int bit_depth_in 62 , int color_type_in 63 , unsigned short samples_per_pixel_in 64 ) 65 : _bit_depth(bit_depth_in) 66 , _color_type(color_type_in) 67 , _samples_per_pixel(samples_per_pixel_in) 68 {} 62 69 template <typename Image> 63 70 bool apply() { 64 return tiff_read_support<typename Image::view_t>::bit_depth==_bit_depth && 65 tiff_read_support<typename Image::view_t>::color_type==_color_type; 71 typedef tiff_read_support<typename Image::view_t> traits; 72 73 int my_samples_per_pixel = size<typename Image::value_type>(); 74 75 bool same_bit_depth = traits::bit_depth == _bit_depth; 76 bool same_color_type = traits::color_type == _color_type; 77 bool same_samples_per_pixel = my_samples_per_pixel == _samples_per_pixel; 78 79 bool result = same_bit_depth && same_color_type; 80 81 if (_samples_per_pixel) 82 result = result && same_samples_per_pixel; 83 84 return result; 66 85 } 67 86 }; 68 87 … … 77 96 78 97 template <typename Images> 79 98 void read_image(any_image<Images>& im) { 80 int width,height; 81 unsigned short bps,photometric; 82 TIFFGetField(_tp,TIFFTAG_IMAGEWIDTH,&width); 83 TIFFGetField(_tp,TIFFTAG_IMAGELENGTH,&height); 84 TIFFGetField(_tp,TIFFTAG_BITSPERSAMPLE,&bps); 85 TIFFGetField(_tp,TIFFTAG_PHOTOMETRIC,&photometric); 86 if (!construct_matched(im,tiff_type_format_checker(bps,photometric))) { 99 int width; 100 int height; 101 unsigned short bps=1; 102 unsigned short photometric = 1; 103 unsigned short samples_per_pixel = 0; 104 TIFFGetField(_tp, TIFFTAG_IMAGEWIDTH, &width); 105 TIFFGetField(_tp, TIFFTAG_IMAGELENGTH, &height); 106 TIFFGetField(_tp, TIFFTAG_BITSPERSAMPLE,&bps); 107 TIFFGetField(_tp, TIFFTAG_PHOTOMETRIC, &photometric); 108 TIFFGetField(_tp, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel); 109 if (!construct_matched(im, tiff_type_format_checker(bps,photometric, samples_per_pixel))) { 87 110 io_error("tiff_reader_dynamic::read_image(): no matching image type between those of the given any_image and that of the file"); 88 111 } else { 89 112 im.recreate(width,height); -
tiff_io.hpp
===================================================================
1 1 /* 2 2 Copyright 2005-2007 Adobe Systems Incorporated 3 3 4 4 Use, modification and distribution are subject to the Boost Software License, 5 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 6 http://www.boost.org/LICENSE_1_0.txt). … … 51 51 BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); 52 52 }; 53 53 template <> 54 struct tiff_read_support_private<bits8,rgba_t> { 55 BOOST_STATIC_CONSTANT(bool,is_supported=true); 56 BOOST_STATIC_CONSTANT(int,bit_depth=8); 57 BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); 58 }; 59 template <> 54 60 struct tiff_read_support_private<bits16,gray_t> { 55 61 BOOST_STATIC_CONSTANT(bool,is_supported=true); 56 62 BOOST_STATIC_CONSTANT(int,bit_depth=16); … … 94 100 BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); 95 101 }; 96 102 template <> 103 struct tiff_write_support_private<bits8,rgba_t> { 104 BOOST_STATIC_CONSTANT(bool,is_supported=true); 105 BOOST_STATIC_CONSTANT(int,bit_depth=8); 106 BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB); 107 }; 108 template <> 97 109 struct tiff_write_support_private<bits16,gray_t> { 98 110 BOOST_STATIC_CONSTANT(bool,is_supported=true); 99 111 BOOST_STATIC_CONSTANT(int,bit_depth=16); … … 129 141 ~tiff_reader() { TIFFClose(_tp); } 130 142 template <typename View> 131 143 void apply(const View& view) { 132 unsigned short bps, photometric;144 unsigned short bps,spp, photometric; 133 145 point2<std::ptrdiff_t> dims=get_dimensions(); 134 146 io_error_if(TIFFGetField(_tp,TIFFTAG_BITSPERSAMPLE,&bps)!=1); 135 147 io_error_if(TIFFGetField(_tp,TIFFTAG_PHOTOMETRIC,&photometric)!=1); 148 io_error_if(TIFFGetField(_tp,TIFFTAG_SAMPLESPERPIXEL,&spp)!=1); 136 149 io_error_if(dims!=view.dimensions(), 137 150 "tiff_read_view: input view size does not match TIFF file size"); 138 151 io_error_if(tiff_read_support_private<typename channel_type<View>::type, 139 152 typename color_space_type<View>::type>::bit_depth!=bps || 140 153 tiff_read_support_private<typename channel_type<View>::type, 141 typename color_space_type<View>::type>::color_type!=photometric, 154 typename color_space_type<View>::type>::color_type!=photometric || 155 mpl::size<typename color_space_type<View>::type>::value != spp, 142 156 "tiff_read_view: input view type is incompatible with the image type"); 143 157 std::size_t element_size=sizeof(pixel<typename channel_type<View>::type, 144 158 layout<typename color_space_type<View>::type> >); … … 166 180 }; 167 181 168 182 // This code will be simplified... 169 template <typename CC> 183 template <typename CC> 170 184 class tiff_reader_color_convert : public tiff_reader { 171 185 private: 172 186 CC _cc; 173 187 public: 174 tiff_reader_color_convert(const char* filename) : 188 tiff_reader_color_convert(const char* filename) : 175 189 tiff_reader(filename) {} 176 tiff_reader_color_convert(const char* filename,CC cc_in) : 190 tiff_reader_color_convert(const char* filename,CC cc_in) : 177 191 tiff_reader(filename),_cc(cc_in) {} 178 192 template <typename View> 179 193 void apply(const View& view) { … … 273 287 default: { 274 288 // reads an image in incompatible format via TIFFReadRGBAImage 275 289 rgba8_image_t rgbaImg(dims); 276 io_error_if(!TIFFReadRGBAImage(_tp, dims.x, dims.y, (uint32*)&gil::view(rgbaImg)(0,0), 0), 290 io_error_if(!TIFFReadRGBAImage(_tp, dims.x, dims.y, (uint32*)&gil::view(rgbaImg)(0,0), 0), 277 291 "tiff_reader_color_convert::unsupported image format"); 278 292 copy_and_convert_pixels(flipped_up_down_view(const_view(rgbaImg)), view, _cc); 279 293 } … … 353 367 /// \ingroup TIFF_IO 354 368 /// \brief Loads the image specified by the given tiff image file name into the given view. 355 369 /// Triggers a compile assert if the view color space and channel depth are not supported by the TIFF library or by the I/O extension. 356 /// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not 370 /// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not 357 371 /// compatible with the ones specified by View, or if its dimensions don't match the ones of the view. 358 372 template <typename View> 359 373 inline void tiff_read_view(const char* filename,const View& view) { … … 372 386 /// \ingroup TIFF_IO 373 387 /// \brief Allocates a new image whose dimensions are determined by the given tiff image file, and loads the pixels into it. 374 388 /// Triggers a compile assert if the image color space or channel depth are not supported by the TIFF library or by the I/O extension. 375 /// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not 389 /// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not 376 390 /// compatible with the ones specified by Image 377 391 template <typename Image> 378 392 void tiff_read_image(const char* filename,Image& im) {
comment:4 by , 13 years ago
Cc: | added |
---|
comment:5 by , 12 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Please ise the new io extension. It provides you with all the features asked for in this ticket.
Note:
See TracTickets
for help on using tickets.
Patch which adds ability to save alpha channel as premultiplied alpha in TIFF file.