@@ -190,15 +190,15 @@ LibtiffImage* LibtiffImage::create_to_read ( std::string filename, BoundingBox<
190190 int width=0 , height=0 , channels=0 , planarconfig=0 , bitspersample=0 , sf=0 , ph=0 , comp=0 , rowsperstrip=0 ;
191191 bool tiled = false , palette = false ;
192192 TIFF* tif = TIFFOpen ( filename.c_str (), " r" );
193-
194-
193+
194+
195195 /* ************* RECUPERATION DES INFORMATIONS **************/
196196
197197 if ( tif == NULL ) {
198198 BOOST_LOG_TRIVIAL (error) << " Unable to open TIFF (to read) " << filename ;
199199 return NULL ;
200200 }
201-
201+
202202 if ( TIFFGetField ( tif, TIFFTAG_IMAGEWIDTH, &width ) < 1 ) {
203203 BOOST_LOG_TRIVIAL (error) << " Unable to read pixel width for file " << filename ;
204204 TIFFClose ( tif );
@@ -256,8 +256,8 @@ LibtiffImage* LibtiffImage::create_to_read ( std::string filename, BoundingBox<
256256 TIFFClose ( tif );
257257 return NULL ;
258258 }
259-
260- if (to_rok4_photometric ( ph ) == Photometric::PALETTE) {
259+
260+ if (to_rok4_photometric ( ph ) == Photometric::PALETTE) {
261261 palette = true ;
262262 }
263263
@@ -294,7 +294,7 @@ LibtiffImage* LibtiffImage::create_to_read ( std::string filename, BoundingBox<
294294 TIFFClose ( tif );
295295 return NULL ;
296296 }
297-
297+
298298 /* ********************* CONTROLES **************************/
299299
300300 if ( to_rok4_sampleformat ( sf, bitspersample ) == SampleFormat::UNKNOWN ) {
@@ -315,7 +315,7 @@ LibtiffImage* LibtiffImage::create_to_read ( std::string filename, BoundingBox<
315315 resx = 1 .;
316316 resy = 1 .;
317317 }
318-
318+
319319 /* ******************* CRÉATION DE L'OBJET ******************/
320320
321321 return new LibtiffImage (
@@ -343,12 +343,12 @@ LibtiffImage* LibtiffImage::create_to_write (
343343 BOOST_LOG_TRIVIAL (error) << " One dimension is not valid for the output image " << filename << " : " << width << " , " << height ;
344344 return NULL ;
345345 }
346-
346+
347347 if ( channels <= 0 ) {
348348 BOOST_LOG_TRIVIAL (error) << " Number of samples per pixel is not valid for the output image " << filename << " : " << channels ;
349349 return NULL ;
350350 }
351-
351+
352352 if ( resx > 0 && resy > 0 ) {
353353 // Vérification de la cohérence entre les résolutions et bbox fournies et les dimensions (en pixel) de l'image
354354 // Arrondi a la valeur entiere la plus proche
@@ -470,9 +470,9 @@ LibtiffImage::LibtiffImage (
470470 ),
471471
472472 tif ( tif ), rowsperstrip ( rowsperstrip ), tiled (tiled), palette (palette) {
473-
473+
474474 // Ce constructeur permet de déterminer si la conversion de 1 à 8 bits est nécessaire, et de savoir si 0 est blanc ou noir
475-
475+
476476 if ( bps == 1 ) {
477477 // On fera la conversion en entiers sur 8 bits à la volée.
478478 // Cette image sera comme une image sur 8 bits.
@@ -501,7 +501,7 @@ LibtiffImage::LibtiffImage (
501501 current_strip = -1 ;
502502 int stripSize = width*rowsperstrip*pixel_size;
503503 strip_buffer = new uint8_t [stripSize];
504-
504+
505505 if (bit_to_byte) {
506506 // On a besoin d'un buffer supplémentaire pour faire la conversion à la volée à la lecture
507507 bit_to_byte_buffer = new uint8_t [stripSize];
@@ -516,7 +516,7 @@ LibtiffImage::LibtiffImage (
516516 FileImage ( width, height, resx, resy, channels, bbox, name, sampleformat, photometric, compression, extra_sample_type ),
517517
518518 tif ( tif ), rowsperstrip ( rowsperstrip ) {
519-
519+
520520 bit_to_byte = 0 ;
521521
522522 current_strip = -1 ;
@@ -530,9 +530,9 @@ LibtiffImage::LibtiffImage (
530530template <typename T>
531531int LibtiffImage::_getline ( T* buffer, int line ) {
532532 // buffer doit déjà être alloué, et assez grand, en tenant compte de la conversion
533-
533+
534534 if ( line / rowsperstrip != current_strip ) {
535-
535+
536536 // Les données n'ont pas encore été lue depuis l'image (strip pas en mémoire).
537537 current_strip = line / rowsperstrip;
538538
@@ -559,7 +559,8 @@ int LibtiffImage::_getline ( T* buffer, int line ) {
559559
560560 for (int t = 0 ; t < tilenumber_widthwise; t++) {
561561
562- if (palette) {
562+ // Si l'image a une photometrie Palette ou bien YCBCR --> TIFFReadRGBATile
563+ if (palette || photometric == Photometric::YCBCR) {
563564 uint32* palette_buffer = new uint32[width * rowsperstrip];
564565
565566 size = TIFFReadRGBATile (tif, t * tile_width, current_strip * tile_height, palette_buffer );
@@ -604,7 +605,8 @@ int LibtiffImage::_getline ( T* buffer, int line ) {
604605
605606 _TIFFfree (tile_buf);
606607 } else {
607- if (palette) {
608+ // Si l'image a une photometrie Palette ou bien YCBCR --> TIFFReadRGBAStrip
609+ if (palette || photometric == Photometric::YCBCR) {
608610 uint32* palette_buffer = new uint32[width * rowsperstrip];
609611 size = TIFFReadRGBAStrip ( tif, line, palette_buffer);
610612 if ( size == 0 ) {
@@ -625,7 +627,7 @@ int LibtiffImage::_getline ( T* buffer, int line ) {
625627 if (line / rowsperstrip == (height - 1 ) / rowsperstrip) {
626628 rows_count = height % rowsperstrip;
627629 }
628-
630+
629631 for (int l = 0 ; l < rows_count; l++) {
630632 for (int i = 0 ; i < width; i++) {
631633 memcpy ( strip_buffer + (width * l + i) * pixel_size, palette_buffer + (rows_count - 1 - l) * width + i, 3 );
@@ -641,19 +643,19 @@ int LibtiffImage::_getline ( T* buffer, int line ) {
641643 }
642644 }
643645 }
644-
646+
645647 if (bit_to_byte == 1 ) {
646648 OneBitConverter::minwhiteToGray (bit_to_byte_buffer, strip_buffer, size);
647649 } else if (bit_to_byte == 2 ) {
648650 OneBitConverter::minblackToGray (bit_to_byte_buffer, strip_buffer, size);
649651 }
650652 }
651-
653+
652654
653655 T buffertmp[width * channels];
654656
655657 /* ************ SI CONVERSION 1 bit -> 8 bits **************/
656-
658+
657659 if (bit_to_byte) {
658660 memcpy ( buffertmp, bit_to_byte_buffer + ( line%rowsperstrip ) * width * pixel_size, width * pixel_size );
659661 } else {
@@ -672,7 +674,7 @@ int LibtiffImage::_getline ( T* buffer, int line ) {
672674 memcpy (buffer, buffertmp, pixel_size * width);
673675 }
674676
675-
677+
676678 return width * get_channels ();
677679}
678680
@@ -698,7 +700,7 @@ int LibtiffImage::get_line ( uint8_t* buffer, int line ) {
698700}
699701
700702int LibtiffImage::get_line ( uint16_t * buffer, int line ) {
701-
703+
702704 if ( sample_format == SampleFormat::UINT8 ) {
703705 // On veut la ligne en entier 16 bits mais l'image lue est sur 8 bits : on convertit
704706 uint8_t * buffer_t = new uint8_t [width * get_channels ()];
@@ -707,7 +709,7 @@ int LibtiffImage::get_line ( uint16_t* buffer, int line ) {
707709 delete [] buffer_t ;
708710 return width * get_channels ();
709711 } else if ( sample_format == SampleFormat::UINT16 ) { // uint16
710- return _getline ( buffer,line );
712+ return _getline ( buffer,line );
711713 } else if ( sample_format == SampleFormat::FLOAT32 ) { // float
712714 /* On ne convertit pas les nombres flottants en entier sur 16 bits (aucun intérêt)
713715 * On va copier le buffer flottant sur le buffer entier 16 bits, de même taille en octet (2 fois plus grand en "nombre de cases")*/
@@ -733,7 +735,7 @@ int LibtiffImage::get_line ( float* buffer, int line ) {
733735 _getline ( buffer_t ,line );
734736 convert ( buffer, buffer_t , width * get_channels () );
735737 delete [] buffer_t ;
736- return width * get_channels ();
738+ return width * get_channels ();
737739 } else if ( sample_format == SampleFormat::FLOAT32 ) { // float
738740 return _getline ( buffer, line );
739741 }
@@ -798,7 +800,7 @@ int LibtiffImage::write_image ( Image* pIn ) {
798800}
799801
800802int LibtiffImage::write_image ( uint8_t * buffer) {
801-
803+
802804 // Si l'image à écrire n'a pas des canaux en entiers sur 8 bits, on sort en erreur
803805
804806 // Ecriture de l'image
@@ -813,14 +815,14 @@ int LibtiffImage::write_image ( uint8_t* buffer) {
813815 } else {
814816 BOOST_LOG_TRIVIAL (error) << " Image to write (from a buffer) has not 8-bit uint samples : " << filename;
815817 print ();
816- return -1 ;
818+ return -1 ;
817819 }
818820
819821 return 0 ;
820822}
821823
822824int LibtiffImage::write_image ( uint16_t * buffer) {
823-
825+
824826 // Si l'image à écrire n'a pas des canaux en entiers sur 16 bits, on sort en erreur
825827
826828 // Ecriture de l'image
@@ -835,14 +837,14 @@ int LibtiffImage::write_image ( uint16_t* buffer) {
835837 } else {
836838 BOOST_LOG_TRIVIAL (error) << " Image to write (from a buffer) has not 16-bit uint samples : " << filename;
837839 print ();
838- return -1 ;
840+ return -1 ;
839841 }
840842
841843 return 0 ;
842844}
843845
844846int LibtiffImage::write_image ( float * buffer) {
845-
847+
846848 // Si l'image à écrire n'a pas des canaux en flottant sur 32 bits, on sort en erreur
847849
848850 if ( sample_format == SampleFormat::FLOAT32 ) {
@@ -874,10 +876,10 @@ int LibtiffImage::write_line ( uint8_t* buffer, int line) {
874876 } else {
875877 BOOST_LOG_TRIVIAL (error) << " Image to write (line by line) has not 8-bit uint samples : " << filename;
876878 print ();
877- return -1 ;
879+ return -1 ;
878880 }
879-
880-
881+
882+
881883 return 0 ;
882884}
883885
@@ -894,15 +896,15 @@ int LibtiffImage::write_line ( uint16_t* buffer, int line) {
894896 } else {
895897 BOOST_LOG_TRIVIAL (error) << " Image to write (line by line) has not 16-bit uint samples : " << filename;
896898 print ();
897- return -1 ;
899+ return -1 ;
898900 }
899901
900902 return 0 ;
901903}
902904
903905int LibtiffImage::write_line ( float * buffer, int line) {
904906 // Si l'image à écrire n'a pas des canaux en flottant sur 32 bits, on sort en erreur
905-
907+
906908 if ( sample_format == SampleFormat::FLOAT32 ) {
907909 if ( TIFFWriteScanline ( tif, buffer, line, 0 ) < 0 ) {
908910 BOOST_LOG_TRIVIAL (error) << " Cannot write file " << TIFFFileName ( tif ) << " , line " << line ;
@@ -916,4 +918,3 @@ int LibtiffImage::write_line ( float* buffer, int line) {
916918
917919 return 0 ;
918920}
919-
0 commit comments