Пример #1
0
      void read_raw_data( string const& fn, uint32_t w, uint32_t h, tImgLinear& rimg ) {

         vector<uint8_t> buf;

         try {
            bin_data::tReadBin()( fn, buf );
         }  catch( bin_data::tBinReadEx& ) {
            throw;
         }

         if( w * h == buf.size() ) {
            rimg.set_mono8();
         }

         if( w * h * 3  == buf.size() ) {
            rimg.set_rgb();
         }

         if( rimg.is_none() ) {
            string s = "Couldn't read raw file: '" + fn + "'";
            throw tImgReadEx( s );
         }

         rimg.size() = tSize( w, h );
         rimg.alloc_data_buffer();
         rimg.insert_data( buf, 0 );

      }
Пример #2
0
      void read( string fn, tImgLinear& rimg ) {


         std::vector<uint8_t> buf;

         bin_read::t_bin_read reader;
         reader( fn, buf );


         FILEHEADER const* fileheader = referenceToFILEHEADER( buf );
         uint16_t sig = fileheader->signature;


         if( sig != BMP_signature ) {
            return ;
         }

         if( buf.size() == fileheader->size ) {
            try {
               INFO const* bitmapinfoheader = referenceToINFO( buf );
               uint32_t w = info_width( bitmapinfoheader );
               uint32_t h = info_height( bitmapinfoheader );
               // copy data to tImgLinear
               rimg.size() = tSize( w, h );

               uint8_t const* pbuf = &buf[0];
               uint8_t const* dataptr = pbuf + fileheader->offset_bits;


               // 8 bit
               if( bitmapinfoheader->bit_count == 8 ) {
                  // LUT is not supported, convert to rgb, if lut is not an gray ramp lut
                  tBGRA const* lut = referenceToLUT( buf );

                  if( is_ramp( lut ) ) {
                     rimg.set_mono8();
                     rimg.alloc_data_buffer();
                     read_8bit( dataptr, rimg.size(), rimg.rows() );
                     return;
                  }

                  if( is_zero( lut ) ) {
                     rimg.set_mono8();
                     rimg.alloc_data_buffer();
                     read_8bit( dataptr, rimg.size(), rimg.rows() );
                     return;
                  }

                  rimg.set_rgb();
                  rimg.alloc_data_buffer();
                  read_8bit_as_rgb( lut, dataptr, rimg.size(), rimg.rows() );
                  return;
               }

               // 24 bit
               if( bitmapinfoheader->bit_count == 24 ) {
                  rimg.set_rgb();
                  rimg.alloc_data_buffer();
                  read_rgb( dataptr, rimg.size(), rimg.rows() );
               }

               if( bitmapinfoheader->bit_count == 32 ) {
                  // read an rgba image, write an rgb image, alpha is lost
                  rimg.set_rgba();
                  rimg.alloc_data_buffer();
                  read_rgba( dataptr, rimg.size(), rimg.rows() );
               }



            } catch( tImgAllocEx& ex ) {
               throw tImgReadEx( ex.what() );
            }

         }
      }