src/camera/bin/factory/capture.cc
// write image as grayscale png.
// If isBayer, output the top 2/3 (Y of YUV NV12 format) and use 16-bit gray
write image as grayscale png.
If isBayer, output the top 2/3 (Y of YUV NV12 format) and use 16-bit gray
write image as grayscale png . If isBayer output the top 2 / 3 ( Y of YUV NV12 format ) and use 16 - bit gray
void Capture::WritePNGUnprocessed(FILE* fp, bool isBayer) {
  auto& iformat = properties_.image_format;
  auto& pformat = iformat.pixel_format;
  FX_LOGS(INFO) << "writing format " << static_cast<int>(pformat.type) << " as unprocessed gray";
  uint32_t vmo_size = image_->size();
  uint32_t width = iformat.bytes_per_row;              
  uint32_t height = vmo_size / iformat.bytes_per_row;  
  uint32_t depth = 8;
  uint32_t scanline = iformat.bytes_per_row;
  auto png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  auto info_ptr = png_create_info_struct(png_ptr);
  uint8_t* pos = image_->data();
  if (setjmp(png_jmpbuf(png_ptr))) {
    FX_LOGS(ERROR) << "libpng failed";
    png_destroy_write_struct(&png_ptr, &info_ptr);
    return;
  }
  if (isBayer) {
    width = 2200;
    height = 2720 - 40;         
    depth = 16;
    scanline = 2208;            
  }
  png_init_io(png_ptr, fp);
  png_set_IHDR(png_ptr, info_ptr, width, height, depth, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE,
               PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
  png_write_info(png_ptr, info_ptr);
  std::vector<uint8_t> row;     
  row.resize(width*2);
  for (uint32_t i = 0; i < height; i++) {
    if (depth == 8) {
      png_write_row(png_ptr, pos);  
    } else {
      for (uint32_t j = 0; j < width; j++) {
        row[j*2] = pos[j];      
        row[j*2+1] = 0;         
      }
      png_write_row(png_ptr, row.data());
    }
    pos += scanline;
  }
  png_write_end(png_ptr, NULL);
  png_destroy_write_struct(&png_ptr, &info_ptr);
  fflush(fp);
  return;
}
void Capture :: WritePNGUnprocessed ( FILE * fp , bool isBayer ) { auto & iformat = properties_ . image_format ; auto & pformat = iformat . pixel_format ; FX_LOGS ( INFO ) << " " << static_cast < int > ( pformat . type ) << " " ; uint32_t vmo_size = image_ -> size ( ) ; uint32_t width = iformat . bytes_per_row ; uint32_t height = vmo_size / iformat . bytes_per_row ; uint32_t depth = 8 ; uint32_t scanline = iformat . bytes_per_row ; auto png_ptr = png_create_write_struct ( PNG_LIBPNG_VER_STRING , NULL , NULL , NULL ) ; auto info_ptr = png_create_info_struct ( png_ptr ) ; uint8_t * pos = image_ -> data ( ) ; if ( setjmp ( png_jmpbuf ( png_ptr ) ) ) { FX_LOGS ( ERROR ) << " " ; png_destroy_write_struct ( & png_ptr , & info_ptr ) ; return ; } if ( isBayer ) { width = 2200 ; height = 2720 - 40 ; depth = 16 ; scanline = 2208 ; } png_init_io ( png_ptr , fp ) ; png_set_IHDR ( png_ptr , info_ptr , width , height , depth , PNG_COLOR_TYPE_GRAY , PNG_INTERLACE_NONE , PNG_COMPRESSION_TYPE_BASE , PNG_FILTER_TYPE_BASE ) ; png_write_info ( png_ptr , info_ptr ) ; std :: vector < uint8_t > row ; row . resize ( width * 2 ) ; for ( uint32_t i = 0 ; i < height ; i ++ ) { if ( depth == 8 ) { png_write_row ( png_ptr , pos ) ; } else { for ( uint32_t j = 0 ; j < width ; j ++ ) { row [ j * 2 ] = pos [ j ] ; row [ j * 2 + 1 ] = 0 ; } png_write_row ( png_ptr , row . data ( ) ) ; } pos += scanline ; } png_write_end ( png_ptr , NULL ) ; png_destroy_write_struct ( & png_ptr , & info_ptr ) ; fflush ( fp ) ; return ; }
write image as grayscale png.
write image as grayscale png .
// pretend it's 8-bit gray // number of whole rows, could be non-image // TODO(fxbug.dev/58283) remove when stream format is accurate for bayer mode // 2200x2720 is from sensor config // -40 determined experimentally // pass to a multiple of 16 pixels? // only used for 16-bit case // consumes width bytes // MSB goes here // LSB is 0 // caller will fclose(fp)