void write( string const& fn, tImgViewLinear const& img ) { try { vector<uint8_t> buf; if( img.is_mono8() ) { buf.resize( offsetpixeldata8 + img.bytes() ); write_mono8( buf, img.size(), img.rows() ); } if( img.is_rgb() ) { uint32_t aligned_line_size = bmp_intern::align32( img.size().x() * sizeof( tBGR ) ); uint32_t filesize = header_size + aligned_line_size * img.size().y(); buf.resize( filesize ); write_rgb( buf, img.size(), img.rows() ); } if( img.is_rgba() ) { uint32_t aligned_line_size = bmp_intern::align32( img.size().x() * sizeof( tBGRA ) ); uint32_t filesize = header_size + aligned_line_size * img.size().y(); buf.resize( filesize ); write_rgba( buf, img.size(), img.rows() ); } bin_data::tWriteBin()( fn, buf ); } catch( bin_data::tBinWriteEx& ) { throw tImgWriteEx( bin_data::msg::write_file( fn ) ); } }
// write one stroke to file system unsigned char write_stroke (FILE * file, PtrStroke stroke) { if (file == NULL || stroke == NULL || stroke->nPoints == 0) { return 0; } //write pen size if ( !write_integer(stroke->iPenSize,file,WRITEINT_LINEEND) ) { SB_INKERRPRINTF("write failed, iPenSize= %d \n",stroke->iPenSize); return 0; } //write rgb if ( !write_rgb(&stroke->gdkColor,file) ) { SB_INKERRPRINTF("failed write rgb\n"); return 0; } if ( !write_integer(stroke->nPoints,file,WRITEINT_LINEEND) ) { SB_INKERRPRINTF("write failed, nPoints= %d \n",stroke->nPoints); return 0; } SB_INKPRINTF("stroke->nPoints=%d \n", stroke->nPoints); PtrInkPoint point = stroke->firstPoint; while (point) { if ( !write_integer(point->x, file, WRITEINT_2SPACES) ) { SB_INKERRPRINTF("fwrite failed, point->x= %d \n", point->x); return 0; } if ( !write_integer(point->y, file, WRITEINT_LINEEND) ) { SB_INKERRPRINTF("fwrite failed, point->y= %d \n", point->y); return 0; } SB_INKPRINTF("point(%d,%d) \n", point->x, point->y); point = point->nextPoint; } return 1; }