/** * Helper function to write a bitmap subset to a file. Only called if subsets were created * and a writePath was provided. Behaves differently depending on * FLAGS_writeChecksumBasedFilenames. If true: * Writes the image to a PNG file named according to the digest hash, as described in * write_bitmap. * If false: * Creates a subdirectory called 'subsets' and writes a PNG to that directory. Also * creates a subdirectory called 'extracted' and writes a bitmap created using * extractSubset to a PNG in that directory. Both files will represent the same * subrectangle and have the same name for convenient comparison. In this case, the * digest is ignored. * * @param writePath Parent directory to hold the folders for the PNG files to write. Must * not be NULL. * @param subsetName Basename of the original file, with the dimensions of the subset tacked * on. Used to name the new file/folder. * @param bitmapAndDigestFromDecodeSubset SkBitmap (with digest) created by * SkImageDecoder::DecodeSubset, using rect as the area to decode. * @param rect Rectangle of the area decoded into bitmapFromDecodeSubset. Used to call * extractSubset on originalBitmap to create a bitmap with the same dimensions/pixels as * bitmapFromDecodeSubset (assuming decodeSubset worked properly). * @param originalBitmap SkBitmap decoded from the same stream as bitmapFromDecodeSubset, * using SkImageDecoder::decode to get the entire image. Used to create a PNG file for * comparison to the PNG created by bitmapAndDigestFromDecodeSubset's bitmap. * @return bool Whether the function succeeded at drawing the decoded subset and the extracted * subset to files. */ static bool write_subset(const char* writePath, const SkString& subsetName, const skiagm::BitmapAndDigest bitmapAndDigestFromDecodeSubset, SkIRect rect, const SkBitmap& originalBitmap) { // All parameters must be valid. SkASSERT(writePath != NULL); SkString subsetPath; if (FLAGS_writeChecksumBasedFilenames) { subsetPath.set(writePath); } else { // Create a subdirectory to hold the results of decodeSubset. subsetPath = SkOSPath::SkPathJoin(writePath, "subsets"); if (!sk_mkdir(subsetPath.c_str())) { gFailedSubsetDecodes.push_back().printf("Successfully decoded subset %s, but " "failed to create a directory to write to.", subsetName.c_str()); return false; } } SkAssertResult(write_bitmap(subsetPath.c_str(), subsetName.c_str(), bitmapAndDigestFromDecodeSubset)); gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", subsetName.c_str()); if (!FLAGS_writeChecksumBasedFilenames) { // FIXME: The goal of extracting the subset is for visual comparison/using skdiff/skpdiff. // Currently disabling for writeChecksumBasedFilenames since it will be trickier to // determine which files to compare. // Also use extractSubset from the original for visual comparison. // Write the result to a file in a separate subdirectory. SkBitmap extractedSubset; if (!originalBitmap.extractSubset(&extractedSubset, rect)) { gFailedSubsetDecodes.push_back().printf("Successfully decoded subset %s, but failed " "to extract a similar subset for comparison.", subsetName.c_str()); return false; } SkString dirExtracted = SkOSPath::SkPathJoin(writePath, "extracted"); if (!sk_mkdir(dirExtracted.c_str())) { gFailedSubsetDecodes.push_back().printf("Successfully decoded subset%s, but failed " "to create a directory for extractSubset " "comparison.", subsetName.c_str()); return false; } skiagm::BitmapAndDigest bitmapAndDigestFromExtractSubset(extractedSubset); SkAssertResult(write_bitmap(dirExtracted.c_str(), subsetName.c_str(), bitmapAndDigestFromExtractSubset)); } return true; }
void create_and_write_diff_image(DiffRecord* drp, DiffMetricProc dmp, const int colorThreshold, const SkString& outputDir, const SkString& filename) { const int w = drp->fBase.fBitmap.width(); const int h = drp->fBase.fBitmap.height(); if (w != drp->fComparison.fBitmap.width() || h != drp->fComparison.fBitmap.height()) { drp->fResult = DiffRecord::kDifferentSizes_Result; } else { drp->fDifference.fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); drp->fDifference.fBitmap.allocPixels(); drp->fWhite.fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); drp->fWhite.fBitmap.allocPixels(); SkASSERT(DiffRecord::kUnknown_Result == drp->fResult); compute_diff(drp, dmp, colorThreshold); SkASSERT(DiffRecord::kUnknown_Result != drp->fResult); } if (outputDir.isEmpty()) { drp->fDifference.fStatus = DiffResource::kUnspecified_Status; drp->fWhite.fStatus = DiffResource::kUnspecified_Status; } else { drp->fDifference.fFilename = filename_to_diff_filename(filename); drp->fDifference.fFullPath = outputDir; drp->fDifference.fFullPath.append(drp->fDifference.fFilename); drp->fDifference.fStatus = DiffResource::kSpecified_Status; drp->fWhite.fFilename = filename_to_white_filename(filename); drp->fWhite.fFullPath = outputDir; drp->fWhite.fFullPath.append(drp->fWhite.fFilename); drp->fWhite.fStatus = DiffResource::kSpecified_Status; if (DiffRecord::kDifferentPixels_Result == drp->fResult) { if (write_bitmap(drp->fDifference.fFullPath, drp->fDifference.fBitmap)) { drp->fDifference.fStatus = DiffResource::kExists_Status; } else { drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status; } if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) { drp->fWhite.fStatus = DiffResource::kExists_Status; } else { drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status; } } } }
int main() { int scale = 2048; int* bitmap = synth_cell(scale * 3, scale * 2, 100); FILE* f = fopen("test1.bmp", "wb"); write_bitmap(f, scale * 3, scale * 2, bitmap); fclose(f); }
static int vbfs_format_device() { int ret = 0; vbfs_prepare_superblock(); ret = write_root_dentry(); if (ret < 0) return -1; ret = write_bad_extend(); if (ret < 0) return -1; ret = write_bitmap(); if (ret < 0) return -1; ret = write_superblock(); if (ret < 0) return -1; fsync(vbfs_params.fd); close(vbfs_params.fd); return 0; }
void TimerTick() { uint32_t ms; if (held_keys(ANY_KEY, &ms) == BUTTON4) { if (ms > 3000) { amx.debug = debughook; } if (ms > 3500) { ABORT = true; } } else if (held_keys(ANY_KEY, &ms) == (BUTTON3 | BUTTON4)) { if (ms > 3000) { // It's quite ugly to do such a long task in an // interrupt handler. Furthermore, it may access // the filesystem at the wrong time. write_bitmap(select_filename("SSHOT%03d.BMP"), bmp_default_palette); __Set(BEEP_VOLUME, 20); while ((~__Get(KEY_STATUS)) & BUTTON4); __Set(BEEP_VOLUME, 0); } } }
/* linear control flow */ int main(int argc, const char *argv[]) { apr_pool_t *pool = NULL; apr_file_t *file = NULL; apr_initialize(); atexit(apr_terminate); pool = svn_pool_create(NULL); files = apr_hash_make(pool); handles = apr_hash_make(pool); if (argc == 2) apr_file_open(&file, argv[1], APR_READ | APR_BUFFERED, APR_OS_DEFAULT, pool); if (file == NULL) { print_usage(); return 0; } parse_file(file); apr_file_close(file); print_stats(pool); apr_file_open(&file, "access.bmp", APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BUFFERED, APR_OS_DEFAULT, pool); write_bitmap(get_rev_files(pool), 0, file, pool); apr_file_close(file); apr_file_open(&file, "access_scaled.bmp", APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BUFFERED, APR_OS_DEFAULT, pool); write_bitmap(get_rev_files(pool), 1024, file, pool); apr_file_close(file); apr_file_open(&file, "scale.bmp", APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BUFFERED, APR_OS_DEFAULT, pool); write_scale(file); apr_file_close(file); return 0; }
void xaml_device::raster(unsigned int *raster, int w, int h, double x, double y, double width, double height, double rot, Rboolean interpolate, const pGEcontext gc) { auto path = get_raster_file_path(); double left = x; double top = _height - y; std::ofstream f(path, std::ofstream::out); write_bitmap(f, raster, w, h); f.close(); _xaml.bitmap_external_file(top, left, width, 0.0 - height, 0.0 - rot, interpolate != R_FALSE, path); }
void menu_connect(GtkWidget *widget, t_map *map) { if (ft_strsearch("Open scene", (char*)gtk_widget_get_name(widget)) != -1) choose_file(widget, map); else if (ft_strsearch("Quitter", (char*)gtk_widget_get_name(widget)) != -1) exit_rt(map); else if (ft_strsearch("Save picture", (char*)gtk_widget_get_name(widget)) != -1) write_bitmap(map); else if (ft_strsearch("Ouvrir generateur de scene", (char*)gtk_widget_get_name(widget)) != -1) open_generateur_scene(map); }
static cell AMX_NATIVE_CALL amx_save_bitmap(AMX *amx, const cell *params) { char *fname; amx_StrParam(amx, params[1], fname); uint32_t palette[16]; memcpy(palette, bmp_default_palette, sizeof(palette)); for (int i = 0; i < params[3]; i++) palette[15 - i] = ((cell*)params[2])[i]; return write_bitmap(fname, palette); }
int main(int argc, char **argv) /* Read parameters from command line here */ { int bmp_size=DEFAULT_BMP_SIZE; int q; FILE *image_data_fp=stdout; struct transmission_line_properties not_used_currently; int verbose_level=0; /* The following jut keeps compilers happy. SGI's is very fussy!! */ not_used_currently.W=1; while((q=get_options(argc,argv,"b:v")) != -1) switch (q) { case 'b': bmp_size=atol(my_optarg); break; case 'v': verbose_level=1; break; case '?': printf("read a ? exiting\n"); } if(argc-my_optind ==11) { WW=atof(argv[my_optind]); HH=atof(argv[my_optind+1]); aa=atof(argv[my_optind+2]); bb=atof(argv[my_optind+3]); cc=atof(argv[my_optind+4]); dd=atof(argv[my_optind+5]); ww=atof(argv[my_optind+6]); hh=atof(argv[my_optind+7]); Er1=atof(argv[my_optind+8]); Er2=atof(argv[my_optind+9]); if((image_data_fp=fopen(argv[my_optind+10],"wb"))==NULL) exit_with_msg_and_exit_code("Cant't open file for writing in create_bmp_for_rect_in_rect.c",CANT_OPEN_FOR_WRITING); if(verbose_level==1) printf("WW=%f HH=%f aa=%f bb=%f cc=%f dd=%f ww=%f hh=%f Er1=%f Er2=%f\n",WW,HH,aa,bb,cc,dd,ww,hh,Er1,Er2); check_parameters_of_create_bmp_for_rect_in_rect(); convert_create_bmp_for_rect_in_rect_dimensions_to_integers(bmp_size); if(verbose_level==1) printf("W=%d H=%d a=%d b=%d c=%d d=%d w=%d h=%d\n",W,H,a,b,c,d,w,h); write_bitmap(image_data_fp, not_used_currently); } else usage_create_bmp_for_rect_in_rect(); return(OKAY); }
extern int main(int argc, char **argv) /* Read parameters from command line here */ { int bmp_size=DEFAULT_BMP_SIZE; int q; struct transmission_line_properties not_used; FILE *image_data_fp=stdout; not_used.W=1; /* Keeps SGI's MipsPro compiler happy */ while((q=get_options(argc,argv,"b:f:v")) != -1) switch (q) { case 'b': bmp_size=atol(my_optarg); break; case 'f': /* By default bitmap image goes to stdout, but we can send to a file with the -f option. */ if((image_data_fp=fopen(my_optarg,"wb"))==NULL) { fprintf(stderr,"Can't write to %s. Exiting ...\n",my_optarg); exit_with_msg_and_exit_code("",CANT_OPEN_FOR_WRITING); } fileflag=TRUE; break; case 'v': verbose=TRUE; break; case '?': printf("read a ? exiting\n"); } /*usage_create_bmp_for_rect_in_circ();*/ fprintf(stderr,"SORRY create_bmp_for_rect_in_circ IS NOT YET WORKING, SO HAS BEEN DISABLED. IT\n"); exit_with_msg_and_exit_code("BE ENABLED ON A FORTHCOMING VERSION",PROGRAM_NOT_IMPLEMENTED); if(argc-my_optind == 6) { DD=atof(argv[my_optind]); ww=atof(argv[my_optind+1]); hh=atof(argv[my_optind+2]); xx=atof(argv[my_optind+3]); yy=atof(argv[my_optind+4]); Er1=atof(argv[my_optind+5]); check_parameters_of_create_bmp_for_rect_in_circ(); convert_create_bmp_for_rect_in_circ_dimensions_to_integers(bmp_size); write_bitmap(image_data_fp, not_used); } else usage_create_bmp_for_rect_in_circ(); return(0); }
int main(int argc, char *argv[]) { setvbuf(stdout, NULL, _IONBF, 0); if (argc != 2) { fprintf(stderr, "Wrong argument count!\n"); return 1; } struct bitmap_file original = read_bitmap(argv[1]); struct bitmap_file fuzzed = fuzz(original); write_bitmap(argv[1], fuzzed); free(original.fh); free(original.ih); free(original.ih_cont); free(original.pixels); free(fuzzed.pixels); return 0; }
bool write_bmpfile(string f_name,char *bitmap,int height,int width) { fout.open(f_name.c_str(),ios::out | ios::binary); if (!fout.is_open()) return 0; h=height; w=width; sz=h*w/8; cout<<sz<<'\n'; cout<<h<<'\n'; cout<<w<<'\n'; if (!write_fileheader(6)) return 0; cout<<"ok\n"; if (!write_dibheader(1)) return 0; cout<<"ok\n"; if (!write_coltable()) return 0; cout<<"ok\n"; if (!write_bitmap(bitmap)) return 0; cout<<"ok\n"; fout.close(); return 1; }
static void decodeFileAndWrite(const char srcPath[]) { SkBitmap bitmap; SkFILEStream stream(srcPath); if (!stream.isValid()) { return; } SkImageDecoder* codec = SkImageDecoder::Factory(&stream); if (NULL == codec) { return; } SkAutoTDelete<SkImageDecoder> ad(codec); stream.rewind(); if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config, SkImageDecoder::kDecodePixels_Mode)) { return; } write_bitmap(srcPath, bitmap); }
int main() { int* bitmap = synth_mandel(6144, 4096, -0.185, -0.1775, 0.66, 0.665); FILE* f = fopen("test1.bmp", "wb"); write_bitmap(f, 6144, 4096, bitmap); fclose(f); }