void opreport_formatter::output(ostream & out, symbol_entry const * symb) { do_output(out, *symb, symb->sample, counts); if (need_details) output_details(out, symb); }
int square_by_grains(int grains_required, bool output){ constexpr int grains_on_first_square{1}; int square = 1; // current square number int amount{grains_on_first_square}; // amount of grains on current square` int total{grains_on_first_square}; // total amount of all grains int prev_amount{grains_on_first_square}; // amount of grains on previous square while(amount < grains_required) { ++square; // next square // calc amount on current square, total amount amount = prev_amount * 2; total += amount; prev_amount = amount; // output calculation details if(output){ output_details(square, amount, total); } } return square; }
static int setup_test(int argc, char **argv) { const char *dumpfile = NULL; SDL_Surface *bmp = NULL; Uint32 dstbpp = 32; Uint32 dstrmask = 0x00FF0000; Uint32 dstgmask = 0x0000FF00; Uint32 dstbmask = 0x000000FF; Uint32 dstamask = 0x00000000; Uint32 dstflags = 0; int dstw = 640; int dsth = 480; Uint32 srcbpp = 32; Uint32 srcrmask = 0x00FF0000; Uint32 srcgmask = 0x0000FF00; Uint32 srcbmask = 0x000000FF; Uint32 srcamask = 0x00000000; Uint32 srcflags = 0; int srcw = 640; int srch = 480; Uint32 origsrcalphaflags = 0; Uint32 origdstalphaflags = 0; Uint32 srcalphaflags = 0; Uint32 dstalphaflags = 0; int srcalpha = 255; int dstalpha = 255; int screenSurface = 0; int i = 0; for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (strcmp(arg, "--dstbpp") == 0) dstbpp = atoi(argv[++i]); else if (strcmp(arg, "--dstrmask") == 0) dstrmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--dstgmask") == 0) dstgmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--dstbmask") == 0) dstbmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--dstamask") == 0) dstamask = atoi_hex(argv[++i]); else if (strcmp(arg, "--dstwidth") == 0) dstw = atoi(argv[++i]); else if (strcmp(arg, "--dstheight") == 0) dsth = atoi(argv[++i]); else if (strcmp(arg, "--dsthwsurface") == 0) dstflags |= SDL_HWSURFACE; else if (strcmp(arg, "--srcbpp") == 0) srcbpp = atoi(argv[++i]); else if (strcmp(arg, "--srcrmask") == 0) srcrmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--srcgmask") == 0) srcgmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--srcbmask") == 0) srcbmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--srcamask") == 0) srcamask = atoi_hex(argv[++i]); else if (strcmp(arg, "--srcwidth") == 0) srcw = atoi(argv[++i]); else if (strcmp(arg, "--srcheight") == 0) srch = atoi(argv[++i]); else if (strcmp(arg, "--srchwsurface") == 0) srcflags |= SDL_HWSURFACE; else if (strcmp(arg, "--seconds") == 0) testSeconds = atoi(argv[++i]); else if (strcmp(arg, "--screen") == 0) screenSurface = 1; else if (strcmp(arg, "--dumpfile") == 0) dumpfile = argv[++i]; /* !!! FIXME: set colorkey. */ else if (0) /* !!! FIXME: we handle some commandlines elsewhere now */ { fprintf(stderr, "Unknown commandline option: %s\n", arg); return(0); } } if (SDL_Init(SDL_INIT_VIDEO) == -1) { fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); return(0); } bmp = SDL_LoadBMP("sample.bmp"); if (bmp == NULL) { fprintf(stderr, "SDL_LoadBMP failed: %s\n", SDL_GetError()); SDL_Quit(); return(0); } if ((dstflags & SDL_HWSURFACE) == 0) dstflags |= SDL_SWSURFACE; if ((srcflags & SDL_HWSURFACE) == 0) srcflags |= SDL_SWSURFACE; if (screenSurface) dest = SDL_SetVideoMode(dstw, dsth, dstbpp, dstflags); else { dest = SDL_CreateRGBSurface(dstflags, dstw, dsth, dstbpp, dstrmask, dstgmask, dstbmask, dstamask); } if (dest == NULL) { fprintf(stderr, "dest surface creation failed: %s\n", SDL_GetError()); SDL_Quit(); return(0); } src = SDL_CreateRGBSurface(srcflags, srcw, srch, srcbpp, srcrmask, srcgmask, srcbmask, srcamask); if (src == NULL) { fprintf(stderr, "src surface creation failed: %s\n", SDL_GetError()); SDL_Quit(); return(0); } /* handle alpha settings... */ srcalphaflags = (src->flags&SDL_SRCALPHA) | (src->flags&SDL_RLEACCEL); dstalphaflags = (dest->flags&SDL_SRCALPHA) | (dest->flags&SDL_RLEACCEL); origsrcalphaflags = srcalphaflags; origdstalphaflags = dstalphaflags; srcalpha = src->format->alpha; dstalpha = dest->format->alpha; for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (strcmp(arg, "--srcalpha") == 0) srcalpha = atoi(argv[++i]); else if (strcmp(arg, "--dstalpha") == 0) dstalpha = atoi(argv[++i]); else if (strcmp(arg, "--srcsrcalpha") == 0) srcalphaflags |= SDL_SRCALPHA; else if (strcmp(arg, "--srcnosrcalpha") == 0) srcalphaflags &= ~SDL_SRCALPHA; else if (strcmp(arg, "--srcrleaccel") == 0) srcalphaflags |= SDL_RLEACCEL; else if (strcmp(arg, "--srcnorleaccel") == 0) srcalphaflags &= ~SDL_RLEACCEL; else if (strcmp(arg, "--dstsrcalpha") == 0) dstalphaflags |= SDL_SRCALPHA; else if (strcmp(arg, "--dstnosrcalpha") == 0) dstalphaflags &= ~SDL_SRCALPHA; else if (strcmp(arg, "--dstrleaccel") == 0) dstalphaflags |= SDL_RLEACCEL; else if (strcmp(arg, "--dstnorleaccel") == 0) dstalphaflags &= ~SDL_RLEACCEL; } if ((dstalphaflags != origdstalphaflags) || (dstalpha != dest->format->alpha)) SDL_SetAlpha(dest, dstalphaflags, (Uint8) dstalpha); if ((srcalphaflags != origsrcalphaflags) || (srcalpha != src->format->alpha)) SDL_SetAlpha(src, srcalphaflags, (Uint8) srcalpha); /* set some sane defaults so we can see if the blit code is broken... */ SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0)); SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 0, 0, 0)); blitCentered(src, bmp); SDL_FreeSurface(bmp); if (dumpfile) SDL_SaveBMP(src, dumpfile); /* make sure initial convert is sane. */ output_details(); return(1); }
static int setup_test(int argc, char **argv) { const char *dumpfile = NULL; SDL_Surface *bmp = NULL; Uint32 dstbpp = 32; Uint32 dstrmask = 0x00FF0000; Uint32 dstgmask = 0x0000FF00; Uint32 dstbmask = 0x000000FF; Uint32 dstamask = 0x00000000; Uint32 dstflags = 0; int dstw = 640; int dsth = 480; Uint32 srcbpp = 32; Uint32 srcrmask = 0x00FF0000; Uint32 srcgmask = 0x0000FF00; Uint32 srcbmask = 0x000000FF; Uint32 srcamask = 0x00000000; Uint32 srcflags = 0; int srcw = 640; int srch = 480; int screenSurface = 0; int i; for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (strcmp(arg, "--dstbpp") == 0) dstbpp = atoi(argv[++i]); else if (strcmp(arg, "--dstrmask") == 0) dstrmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--dstgmask") == 0) dstgmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--dstbmask") == 0) dstbmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--dstamask") == 0) dstamask = atoi_hex(argv[++i]); else if (strcmp(arg, "--dstwidth") == 0) dstw = atoi(argv[++i]); else if (strcmp(arg, "--dstheight") == 0) dsth = atoi(argv[++i]); else if (strcmp(arg, "--dsthwsurface") == 0) dstflags |= SDL_HWSURFACE; else if (strcmp(arg, "--srcbpp") == 0) srcbpp = atoi(argv[++i]); else if (strcmp(arg, "--srcrmask") == 0) srcrmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--srcgmask") == 0) srcgmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--srcbmask") == 0) srcbmask = atoi_hex(argv[++i]); else if (strcmp(arg, "--srcamask") == 0) srcamask = atoi_hex(argv[++i]); else if (strcmp(arg, "--srcwidth") == 0) srcw = atoi(argv[++i]); else if (strcmp(arg, "--srcheight") == 0) srch = atoi(argv[++i]); else if (strcmp(arg, "--srchwsurface") == 0) srcflags |= SDL_HWSURFACE; else if (strcmp(arg, "--seconds") == 0) testSeconds = atoi(argv[++i]); else if (strcmp(arg, "--screen") == 0) screenSurface = 1; else if (strcmp(arg, "--dumpfile") == 0) dumpfile = argv[++i]; else { fprintf(stderr, "Unknown commandline option: %s\n", arg); return(0); } } if (SDL_Init(SDL_INIT_VIDEO) == -1) { fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); return(0); } bmp = SDL_LoadBMP("sample.bmp"); if (bmp == NULL) { fprintf(stderr, "SDL_LoadBMP failed: %s\n", SDL_GetError()); SDL_Quit(); return(0); } if ((dstflags & SDL_HWSURFACE) == 0) dstflags |= SDL_SWSURFACE; if ((srcflags & SDL_HWSURFACE) == 0) srcflags |= SDL_SWSURFACE; if (screenSurface) dest = SDL_SetVideoMode(dstw, dsth, dstbpp, dstflags); else { dest = SDL_CreateRGBSurface(dstflags, dstw, dsth, dstbpp, dstrmask, dstgmask, dstbmask, dstamask); } if (dest == NULL) { fprintf(stderr, "dest surface creation failed: %s\n", SDL_GetError()); SDL_Quit(); return(0); } src = SDL_CreateRGBSurface(srcflags, srcw, srch, srcbpp, srcrmask, srcgmask, srcbmask, srcamask); if (src == NULL) { fprintf(stderr, "src surface creation failed: %s\n", SDL_GetError()); SDL_Quit(); return(0); } /* set some sane defaults so we can see if the blit code is broken... */ SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0)); SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 0, 0, 0)); blitCentered(src, bmp); SDL_FreeSurface(bmp); if (dumpfile) SDL_SaveBMP(src, dumpfile); /* make sure initial convert is sane. */ output_details(); return(1); }