diff options
| -rw-r--r-- | docstring.c | 1 | ||||
| -rw-r--r-- | flam3-render.c | 191 | ||||
| -rw-r--r-- | flam3.c | 16 | ||||
| -rw-r--r-- | flam3.h | 1 | 
4 files changed, 35 insertions, 174 deletions
| diff --git a/docstring.c b/docstring.c index c992fe8..b86a44d 100644 --- a/docstring.c +++ b/docstring.c @@ -61,7 +61,6 @@ static char *the_docstring1 =  "template        NA          apply defaults based on this genome (genome only)\n"  "dtime           1           time between frames (animate only)\n"  "fields          0           if 1 then render fields, ie odd scanlines at time+0.5\n" -"nstrips         1           number of strips, ie render fractions of a frame at once (render only)\n"  "qs              1           quality scale, multiply quality of all frames by this\n"  "ss              1           size scale, multiply size (in pixels) of all frames by this\n"  "pixel_aspect    1.0         aspect ratio of pixels (width over height), eg 0.90909 for NTSC\n" diff --git a/flam3-render.c b/flam3-render.c index a4f8d93..8f1084d 100644 --- a/flam3-render.c +++ b/flam3-render.c @@ -22,51 +22,6 @@  #include "private.h"  #include "img.h" - -int calc_nstrips(flam3_frame *spec) { -  double mem_required; -  double mem_available; -  int nstrips,ninc; -  char *testmalloc; -#if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) -  mem_available = -      (double)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE); -#else -  fprintf(stderr, "warning: unable to determine physical memory.\n"); -  mem_available = 2e9; -#endif -#if 0 -  fprintf(stderr,"available phyical memory is %lu\n", -	  (unsigned long)mem_available); -#endif -  mem_available *= 0.8; -  if (getenv("use_mem")) { -      mem_available = atof(getenv("use_mem")); -  } -  mem_required = flam3_render_memory_required(spec); -  if (mem_available >= mem_required) return 1; -  nstrips = (int) ceil(mem_required / mem_available); - -if (0) { -  /* Attempt to malloc a strip, and if it fails, try adding additional strips */ -  ninc=-1; -  testmalloc = NULL; -  while(NULL==testmalloc && ninc<3) { -     ninc++; -	  testmalloc = (char *)malloc((int)ceil(mem_required / (nstrips+ninc))); -  } -  if (NULL==testmalloc) { -     fprintf(stderr,"Unable to allocate memory for render.  Please close some running programs and try to render again.\n"); -     exit(1); -  } else { -     free(testmalloc); -     nstrips = nstrips + ninc; -  } -} -   -  return nstrips; -} -  int print_progress(void *foo, double fraction, int stage, double eta) {      fprintf(stderr, "stage=%s progress=%g eta=%g\n", stage?"filtering":"chaos", fraction, eta);    return 0; @@ -81,19 +36,13 @@ int main(int argc, char **argv) {     void *image=NULL;     FILE *fp;     char fname[256]; -   size_t this_size, last_size = -1; -   double imgmem; -   unsigned int strip; -   double center_y, center_base; -   unsigned int nstrips; -   randctx savectx; +   size_t this_size;     char *prefix = args("prefix", "");     char *out = args("out", NULL);     const char *format = "png";     int verbose = argi("verbose", 1);     int bits = argi("bits", 33);     int bpc = argi("bpc",8); -   int seed = argi("seed", 0);     int transparency = argi("transparency", 0);     char *inf = getenv("in");     double qs = argf("qs", 1.0); @@ -104,7 +53,6 @@ int main(int argc, char **argv) {     int num_threads = argi("nthreads",0);     int earlyclip = argi("earlyclip",0);     FILE *in; -   double zoom_scale;     unsigned int channels;     long start_time = (long)time(0);     flam3_img_comments fpc; @@ -188,8 +136,6 @@ int main(int argc, char **argv) {     for (i = 0; i < ncps; i++) { -      int real_height; -        if (verbose && ncps > 1) {           fprintf(stderr, "flame = %d/%d ", i+1, ncps);        } @@ -212,123 +158,56 @@ int main(int argc, char **argv) {           f.bytes_per_channel = 1; -      if (getenv("nstrips")) { -         nstrips = atoi(getenv("nstrips")); -      } else { -         nstrips = calc_nstrips(&f); -      } +      this_size = (size_t)channels * (size_t)cps[i].width  +                  * (size_t)cps[i].height * f.bytes_per_channel; +	  image = (void *) calloc(this_size, sizeof(char)); -      if (nstrips > cps[i].height) { -         fprintf(stderr, "cannot have more strips than rows but %d>%d.\n", -         nstrips, cps[i].height); -         exit(1); +      if (verbose && ncps > 1) { +         fprintf(stderr, "\n");        } -       -      imgmem = (double)channels * (double)cps[i].width  -               * (double)cps[i].height * f.bytes_per_channel; -       -      if (imgmem > ULONG_MAX) { -         fprintf(stderr,"Image size > ULONG_MAX.  Aborting.\n"); +      cps[i].ntemporal_samples = 1; +      if (flam3_render(&f, image, flam3_field_both, channels, transparency, &stats)) { +         fprintf(stderr,"error rendering image: aborting.\n");           exit(1);        } -      this_size = (size_t)channels * (size_t)cps[i].width  -                  * (size_t)cps[i].height * f.bytes_per_channel; -      if (this_size != last_size) { -         if (last_size != -1) -            free(image); -         last_size = this_size; -         image = (void *) calloc(this_size, sizeof(char)); -         if (NULL==image) { -            fprintf(stderr,"Error allocating memory for image.  Aborting\n"); -            exit(1); -         } +      if (NULL != out) { +         strcpy(fname,out); +      } else if (name_enable && cps[i].flame_name[0]>0) { +         sprintf(fname, "%s.%s",cps[i].flame_name,format);        } else { -         memset(image, 0, this_size); +         sprintf(fname, "%s%05d.%s", prefix, i, format); +      } +      if (verbose) { +         fprintf(stderr, "writing %s...", fname); +      } +      fp = fopen(fname, "wb"); +      if (NULL == fp) { +         perror(fname); +         exit(1);        } -      cps[i].sample_density *= nstrips; -      real_height = cps[i].height; -      cps[i].height = (int) ceil(cps[i].height / (double) nstrips); -      center_y = cps[i].center[1]; -      zoom_scale = pow(2.0, cps[i].zoom); -      center_base = center_y - ((nstrips - 1) * cps[i].height) / -      (2 * cps[i].pixels_per_unit * zoom_scale); +      /* Generate temp file with genome */ +      fpc.genome = flam3_print_to_string(f.genomes); -      /* Copy off random context to use for each strip */ -      memcpy(&savectx, &f.rc, sizeof(randctx)); +      sprintf(badval_string,"%g",stats.badvals/(double)stats.num_iters); +      fpc.badvals = badval_string; +      sprintf(numiter_string,"%g",(double)stats.num_iters); +      fpc.numiters = numiter_string; +      sprintf(rtime_string,"%d",stats.render_seconds); +      fpc.rtime = rtime_string; -      for (strip = 0; strip < nstrips; strip++) { -         size_t ssoff = (size_t)cps[i].height * strip * cps[i].width * channels * f.bytes_per_channel; -         void *strip_start = image + ssoff; -         cps[i].center[1] = center_base + cps[i].height * (double) strip / (cps[i].pixels_per_unit * zoom_scale); -          -         if ((cps[i].height * (strip + 1)) > real_height) { -            int oh = cps[i].height; -            cps[i].height = real_height - oh * strip; -            cps[i].center[1] -= -            (oh - cps[i].height) * 0.5 / -            (cps[i].pixels_per_unit * zoom_scale); -         } -          -         /* Use the same random context for each strip */ -         memcpy(&f.rc, &savectx, sizeof(randctx)); - -         if (verbose && nstrips > 1) { -            fprintf(stderr, "strip = %d/%d\n", strip+1, nstrips); -         } -         if (verbose && (1 == nstrips) && (ncps > 1)) { -            fprintf(stderr, "\n"); -         } -         cps[i].ntemporal_samples = 1; -         if (flam3_render(&f, strip_start, flam3_field_both, channels, transparency, &stats)) { -            fprintf(stderr,"error rendering image: aborting.\n"); -            exit(1); -         } - -         if (NULL != out) { -            strcpy(fname,out); -         } else if (name_enable && cps[i].flame_name[0]>0) { -            sprintf(fname, "%s.%s",cps[i].flame_name,format); -         } else { -            sprintf(fname, "%s%05d.%s", prefix, i, format); -         } -         if (verbose) { -            fprintf(stderr, "writing %s...", fname); -         } -         fp = fopen(fname, "wb"); -         if (NULL == fp) { -            perror(fname); -            exit(1); -         } - -         /* Generate temp file with genome */ -         fpc.genome = flam3_print_to_string(f.genomes); -          -         sprintf(badval_string,"%g",stats.badvals/(double)stats.num_iters); -         fpc.badvals = badval_string; -         sprintf(numiter_string,"%g",(double)stats.num_iters); -         fpc.numiters = numiter_string; -         sprintf(rtime_string,"%d",stats.render_seconds); -         fpc.rtime = rtime_string; - -		 write_png(fp, image, cps[i].width, real_height, &fpc, f.bytes_per_channel); -         /* Free string */ -         free(fpc.genome); - -         fclose(fp); -      } +      write_png(fp, image, cps[i].width, cps[i].height, &fpc, f.bytes_per_channel); +      /* Free string */ +      free(fpc.genome); -      /* restore the cps values to their original values */ -      cps[i].sample_density /= nstrips; -      cps[i].height = real_height; -      cps[i].center[1] = center_y; +      fclose(fp);        if (verbose) {           fprintf(stderr, "done.\n");        }     } -   if (verbose && ((ncps > 1) || (nstrips > 1))) { +   if (verbose && (ncps > 1)) {        long total_time = (long)time(0) - start_time;        if (total_time > 100) @@ -3420,22 +3420,6 @@ typedef float abucket_float[4];  #undef de_thread_helper  #undef de_thread - -double flam3_render_memory_required(flam3_frame *spec) -{ -  flam3_genome *cps = spec->genomes; -  int real_bits = spec->bits; -  int real_bytes; - -  if (33 == real_bits) real_bits = 32; - -  real_bytes = real_bits / 8; - -  return -    (double) cps[0].spatial_oversample * cps[0].spatial_oversample * -    (double) cps[0].width * cps[0].height * real_bytes * 9.0; -} -  int flam3_render(flam3_frame *spec, void *out,          int field, int nchan, int trans, stat_struct *stats) { @@ -611,7 +611,6 @@ typedef struct {     pixels are rgb or rgba if nchan is 3 or 4. */  int flam3_render(flam3_frame *f, void *out, int field, int nchan, int transp, stat_struct *stats); -double flam3_render_memory_required(flam3_frame *f);  void rotate_by(double *p, double *center, double by); | 
