Example #1
0
int
main(int argc, char ** argv)
{
	struct ppm * picture;
	color_t pixel;
	int i, j;

	picture = ppm_init(WIDTH, HEIGHT);

	for(i = 0; i < WIDTH; i++)
	{
		for(j = 0; j < HEIGHT; j++)
		{
			pixel.red = (float)i * j / (WIDTH * HEIGHT) * 255;
			//i == 2 && j == 2 ? 255 : 0;
			pixel.green = 0;
			pixel.blue = pixel.green;

			ppm_write(picture, i, j, pixel);
		}
	}

	ppm_save(picture, "picture.ppm");

	return 0;
}
Example #2
0
int main (int argc, char **argv)
{
  char * out_dir;
  char out_file[128];
  int i;
  seek_table_type table;
  fas_error_type video_error;
  fas_context_ref_type context, seek_context;

  cmdname = argv[0];

  if (argc < 3) {
    show_help();
    fail("arguments\n");
  }

  table = read_table_file(argv[2]);
  if (table.num_entries == 0)
    fail("bad table\n");

  fas_initialize (FAS_FALSE, FAS_RGB24);

  video_error = fas_open_video (&context, argv[1]);
  if (video_error != FAS_SUCCESS)    fail("fail on open\n");

  video_error = fas_put_seek_table(context, table);
  if (video_error != FAS_SUCCESS)    fail("fail on put_seek_table\n");

  video_error = fas_open_video (&seek_context, argv[1]);
  if (video_error != FAS_SUCCESS)    fail("fail on open\n");


  if (argc >= 4) {
    out_dir = argv[3];
    create_dir(out_dir);
  } else {
    out_dir = ".";
  }

  for(i=0;i<table.num_entries;i++)
    {
      fas_raw_image_type image_buffer;
      //      int frame_index = table.array[table.num_entries - i - 1].display_index;
      int frame_index = table.array[i].display_index;
      if (FAS_SUCCESS != fas_seek_to_frame(context, frame_index))
	fail("failed on seek");

      if (FAS_SUCCESS != fas_get_frame (context, &image_buffer))
	fail("failed on rgb image\n");

      sprintf(out_file, "%s/frame_%04d.ppm", out_dir, frame_index);

      fprintf(stderr, "Writing %s (seek_table_value=%d frame_index=%d)\n", out_file, frame_index, fas_get_frame_index(context));
      ppm_save(&image_buffer, out_file);

      fas_free_frame (image_buffer);
    }

  success();
}
Example #3
0
static int grab_save(unsigned long now)
{
  int ret;

  if ( grab_fname != NULL )
    free(grab_fname);
  grab_fname = NULL;

  if ( grab_fname_size <= 0 )
    return -1;
  if ( grab_fname_fmt == NULL )
    return -1;

  grab_fname = (char *) malloc(grab_fname_size);
  snprintf(grab_fname, grab_fname_size, grab_fname_fmt, now);

  if ( grab_ppm )
    ret = ppm_save(&(grab_frame->hdr.fb->rgb), &grab_window, grab_fname);
  else
    ret = png_save(&(grab_frame->hdr.fb->rgb), &grab_window, grab_fname);

  if ( ret == 0 )
    grab_n++;

  return ret;
}
int
main(int argc, char ** argv)
{
  struct mandelbrot_param param;

  param.height = HEIGHT;
  param.width = WIDTH;
  param.lower_r = LOWER_R;
  param.upper_r = UPPER_R;
  param.lower_i = LOWER_I;
  param.upper_i = UPPER_I;
  param.maxiter = MAXITER;
  param.mandelbrot_color.red = (MANDELBROT_COLOR >> 16) & 255;
  param.mandelbrot_color.green = (MANDELBROT_COLOR >> 8) & 255;
  param.mandelbrot_color.blue = MANDELBROT_COLOR & 255;

  // Initializes the mandelbrot computation framework. Among other, spawns the threads in thread pool
  init_mandelbrot(&param);

#ifdef MEASURE
  struct mandelbrot_timing ** thread, global;
  GETTIME(&global.start);

  thread = compute_mandelbrot(param);

  GETTIME(&global.stop);
#elif GLUT == 1
  srand(time(NULL));
  gl_mandelbrot_init(argc, argv);
  gl_mandelbrot_start(&param);
#else
  compute_mandelbrot(param);
  ppm_save(param.picture, "mandelbrot.ppm");
#endif

#ifdef MEASURE
#if NB_THREADS > 0
  int i;

  for (i = 0; i < NB_THREADS; i++)
    {
      printf("%i %li %li %li %li %li %li %li %li\n", i + 1, thread[i]->start.tv_sec, thread[i]->start.tv_nsec, thread[i]->stop.tv_sec, thread[i]->stop.tv_nsec, global.start.tv_sec, global.start.tv_nsec, global.stop.tv_sec, global.stop.tv_nsec);
    }
#else
  printf("0 %li %li %li %li %li %li %li %li\n", thread[0]->start.tv_sec, thread[0]->start.tv_nsec, thread[0]->stop.tv_sec, thread[0]->stop.tv_nsec, global.start.tv_sec, global.start.tv_nsec, global.stop.tv_sec, global.stop.tv_nsec);
#endif
#endif

  // Final: deallocate structures
  destroy_mandelbrot(param);

  return EXIT_SUCCESS;
}
Example #5
0
static void
savebrush_response (GtkWidget *dialog,
                    gint       response_id,
                    gpointer   data)
{
  if (response_id == GTK_RESPONSE_OK)
    {
      gchar *name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));

      ppm_save (&brushppm, name);
      brushlistrefresh ();

      g_free (name);
    }

  gtk_widget_destroy (dialog);
}
Example #6
0
int main(int argc, char** argv)
{	
	Image* image = ppm_create(1024, 1024);
	Image* smaller = ppm_create(128, 128);
	
	int x, y;
	for(y = 0; y < image->header.height; y++) {
		for(x = 0; x < image->header.width; x++) {
			Point2D pix = point2(x, y);
			float x_scale = image->header.width / 8.0f;
			float y_scale = image->header.height / 8.0f;
			Point2D samp = point2((pix.x + 512) / x_scale, (pix.y + 512) / y_scale);
			//ColorRGB color = color_field(samp);
			ColorRGB height = heightmap(samp);
			//ColorRGB blended = blend(color, height, 0.1f);
			draw_point(image, pix, height);
		}
	}

	for(y = 0; y < smaller->header.height; y++) {
		for(x = 0; x < image->header.width; x++) {
			Point2D pix = point2(x, y);
			float x_scale = image->header.width / 8.0f;
			float y_scale = image->header.height / 8.0f;
			Point2D sample = point2((pix.x) / x_scale, (pix.y) / y_scale);
			ColorRGB color = heightmap(sample);
			draw_point(smaller, pix, color);
		}
	}
	
	Rect2D src_rect, dest_rect;
	src_rect = (Rect2D) { point2(0, 0), point2(smaller->header.width, smaller->header.height) };
	dest_rect = (Rect2D) { point2(128, 128), point2(448, 448) };
	blit_alpha(image, dest_rect, smaller, src_rect, 0.1f);
	
	ppm_save(image, "overlay.ppm");

	ppm_destroy(smaller);
	ppm_destroy(image);
	
	return 0;
}
Example #7
0
int main(int argc, char **argv)
{
    FILE *f;
    BPGDecoderContext *img;
    uint8_t *buf;
    int buf_len, bit_depth, c, show_info;
    const char *outfilename, *filename, *p;
    
    outfilename = "out.png";
    bit_depth = 8;
    show_info = 0;
    for(;;) {
        c = getopt(argc, argv, "ho:b:i");
        if (c == -1)
            break;
        switch(c) {
        case 'h':
        show_help:
            help();
            break;
        case 'o':
            outfilename = optarg;
            break;
        case 'b':
            bit_depth = atoi(optarg);
            break;
        case 'i':
            show_info = 1;
            break;
        default:
            exit(1);
        }
    }

    if (optind >= argc)
        goto show_help;

    filename = argv[optind++];

    if (show_info) {
        bpg_show_info(filename, 1);
        return 0;
    }

    f = fopen(filename, "rb");
    if (!f) {
        fprintf(stderr, "Could not open %s\n", filename);
        exit(1);
    }

    fseek(f, 0, SEEK_END);
    buf_len = ftell(f);
    fseek(f, 0, SEEK_SET);

    buf = malloc(buf_len);
    if (fread(buf, 1, buf_len, f) != buf_len) {
        fprintf(stderr, "Error while reading file\n");
        exit(1);
    }
    
    fclose(f);

    img = bpg_decoder_open();

    if (bpg_decoder_decode(img, buf, buf_len) < 0) {
        fprintf(stderr, "Could not decode image\n");
        exit(1);
    }
    free(buf);

#ifdef USE_PNG
    p = strrchr(outfilename, '.');
    if (p)
        p++;

    if (p && strcasecmp(p, "ppm") != 0) {
        png_save(img, outfilename, bit_depth);
    } else 
#endif
    {
        ppm_save(img, outfilename);
    }

    bpg_decoder_close(img);

    return 0;
}
Example #8
0
void
repaint (ppm_t *p, ppm_t *a)
{
  int         x, y;
  int         tx = 0, ty = 0;
  ppm_t       tmp = {0, 0, NULL};
  ppm_t       atmp = {0, 0, NULL};
  int         r, g, b, h, i, j, on, sn;
  int         num_brushes, maxbrushwidth, maxbrushheight;
  guchar      back[3] = {0, 0, 0};
  ppm_t      *brushes, *shadows;
  ppm_t      *brush, *shadow = NULL;
  double     *brushes_sum;
  int         cx, cy, maxdist;
  double      scale, relief, startangle, anglespan, density, bgamma;
  int         max_progress;
  ppm_t       paper_ppm = {0, 0, NULL};
  ppm_t       dirmap = {0, 0, NULL};
  ppm_t       sizmap = {0, 0, NULL};
  int        *xpos = NULL, *ypos = NULL;
  int         progstep;
  static int  running = 0;

  int dropshadow = pcvals.general_drop_shadow;
  int shadowblur = pcvals.general_shadow_blur;

  if (running)
    return;
  running++;

  runningvals = pcvals;

  /* Shouldn't be necessary, but... */
  if (img_has_alpha)
    if ((p->width != a->width) || (p->height != a->height))
      {
        g_printerr ("Huh? Image size != alpha size?\n");
        return;
      }

  num_brushes = runningvals.orient_num * runningvals.size_num;
  startangle = runningvals.orient_first;
  anglespan = runningvals.orient_last;

  density = runningvals.brush_density;

  if (runningvals.place_type == PLACEMENT_TYPE_EVEN_DIST)
    density /= 3.0;

  bgamma = runningvals.brushgamma;

  brushes = g_malloc (num_brushes * sizeof (ppm_t));
  brushes_sum = g_malloc (num_brushes * sizeof (double));

  if (dropshadow)
    shadows = g_malloc (num_brushes * sizeof (ppm_t));
  else
    shadows = NULL;

  brushes[0].col = NULL;
  brush_get_selected (&brushes[0]);

  resize (&brushes[0],
          brushes[0].width,
          brushes[0].height * pow (10, runningvals.brush_aspect));
  scale = runningvals.size_last / MAX (brushes[0].width, brushes[0].height);

  if (bgamma != 1.0)
    ppm_apply_gamma (&brushes[0], 1.0 / bgamma, 1,1,1);

  resize (&brushes[0], brushes[0].width * scale, brushes[0].height * scale);
  i = 1 + sqrt (brushes[0].width  * brushes[0].width +
                brushes[0].height * brushes[0].height);
  ppm_pad (&brushes[0], i-brushes[0].width, i-brushes[0].width,
           i - brushes[0].height, i - brushes[0].height, back);

  for (i = 1; i < num_brushes; i++)
    {
      brushes[i].col = NULL;
      ppm_copy (&brushes[0], &brushes[i]);
    }

    for (i = 0; i < runningvals.size_num; i++)
      {
      double sv;
      if (runningvals.size_num > 1)
        sv = i / (runningvals.size_num - 1.0);
      else sv = 1.0;
      for (j = 0; j < runningvals.orient_num; j++)
        {
          h = j + i * runningvals.orient_num;
          free_rotate (&brushes[h],
                       startangle + j * anglespan / runningvals.orient_num);
          rescale (&brushes[h],
                   ( sv      * runningvals.size_first +
                    (1.0-sv) * runningvals.size_last    ) / runningvals.size_last);
          autocrop (&brushes[h],1);
        }
    }

  /* Brush-debugging */
#if 0
  for (i = 0; i < num_brushes; i++)
    {
      char tmp[1000];
      g_snprintf (tmp, sizeof (tmp), "/tmp/_brush%03d.ppm", i);
      ppm_save (&brushes[i], tmp);
    }
#endif

  for (i = 0; i < num_brushes; i++)
    {
      if (!runningvals.color_brushes)
        prepare_brush (&brushes[i]);
      brushes_sum[i] = sum_brush (&brushes[i]);
    }

  brush = &brushes[0];

  maxbrushwidth = maxbrushheight = 0;
  for (i = 0; i < num_brushes; i++)
    {
      if (brushes[i].width > maxbrushwidth)
        maxbrushwidth = brushes[i].width;
      if (brushes[i].height > maxbrushheight)
        maxbrushheight = brushes[i].height;
    }

  for (i = 0; i < num_brushes; i++)
    {
      int xp, yp;
      guchar blk[3] = {0, 0, 0};

      xp = maxbrushwidth - brushes[i].width;
      yp = maxbrushheight - brushes[i].height;
      if (xp || yp)
        ppm_pad (&brushes[i], xp / 2, xp - xp / 2, yp / 2, yp - yp / 2, blk);
    }

  if (dropshadow)
    {
      for (i = 0; i < num_brushes; i++)
        {
          shadows[i].col = NULL;
          ppm_copy (&brushes[i], &shadows[i]);
          ppm_apply_gamma (&shadows[i], 0, 1,1,0);
          ppm_pad (&shadows[i], shadowblur*2, shadowblur*2,
                   shadowblur*2, shadowblur*2, back);
          for (j = 0; j < shadowblur; j++)
            blur (&shadows[i], 2, 2);
#if 0
          autocrop (&shadows[i],1);
#endif
        }
#if 0
      maxbrushwidth += shadowdepth*3;
      maxbrushheight += shadowdepth*3;
#endif
    }

  /* For extra annoying debugging :-) */
#if 0
  ppm_save (brushes, "/tmp/__brush.ppm");
  if (shadows) ppm_save (shadows, "/tmp/__shadow.ppm");
  system ("xv /tmp/__brush.ppm & xv /tmp/__shadow.ppm & ");
#endif

  if (runningvals.general_paint_edges)
    {
      edgepad (p, maxbrushwidth, maxbrushwidth,
               maxbrushheight, maxbrushheight);
      if (img_has_alpha)
        edgepad (a, maxbrushwidth, maxbrushwidth,
                 maxbrushheight, maxbrushheight);
    }

  if (img_has_alpha)
    {
    /* Initially fully transparent */
      if (runningvals.general_background_type == BG_TYPE_TRANSPARENT)
        {
          guchar tmpcol[3] = {255, 255, 255};

          ppm_new (&atmp, a->width, a->height);
          fill (&atmp, tmpcol);
        }
      else
        {
          ppm_copy (a, &atmp);
        }
    }

  if (runningvals.general_background_type == BG_TYPE_SOLID)
    {
      guchar tmpcol[3];

      ppm_new (&tmp, p->width, p->height);
      gimp_rgb_get_uchar (&runningvals.color,
                          &tmpcol[0], &tmpcol[1], &tmpcol[2]);
      fill (&tmp, tmpcol);
    }
  else if (runningvals.general_background_type == BG_TYPE_KEEP_ORIGINAL)
    {
      ppm_copy (p, &tmp);
    }
  else
    {
      int dx, dy;

      ppm_new (&tmp, p->width, p->height);
      ppm_load (runningvals.selected_paper, &paper_ppm);

      if (runningvals.paper_scale != 100.0)
        {
          scale = runningvals.paper_scale / 100.0;
          resize (&paper_ppm, paper_ppm.width * scale, paper_ppm.height * scale);
        }

      if (runningvals.paper_invert)
        ppm_apply_gamma (&paper_ppm, -1.0, 1, 1, 1);

      dx = runningvals.general_paint_edges ? paper_ppm.width - maxbrushwidth : 0;
      dy = runningvals.general_paint_edges ? paper_ppm.height - maxbrushheight : 0;

      for (y = 0; y < tmp.height; y++)
        {
          int lx;
          int ry = (y + dy) % paper_ppm.height;

          for (x = 0; x < tmp.width; x+=lx)
            {
              int rx = (x + dx) % paper_ppm.width;

              lx = MIN (tmp.width - x, paper_ppm.width - rx);

              memcpy (&tmp.col[y * tmp.width * 3 + x * 3],
                      &paper_ppm.col[ry * paper_ppm.width * 3 + rx * 3],
                      3 * lx);
            }
        }
    }

  cx = p->width / 2;
  cy = p->height / 2;
  maxdist = sqrt (cx * cx + cy * cy);

  switch (runningvals.orient_type)
    {
    case ORIENTATION_VALUE:
      ppm_new (&dirmap, p->width, p->height);
      for (y = 0; y < dirmap.height; y++)
        {
          guchar *dstrow = &dirmap.col[y * dirmap.width * 3];
          guchar *srcrow = &p->col[y * p->width * 3];
          for (x = 0; x < dirmap.width; x++)
            {
              dstrow[x * 3] =
                (srcrow[x * 3] + srcrow[x * 3 + 1] + srcrow[x * 3 + 2]) / 3;
            }
        }
      break;

    case ORIENTATION_RADIUS:
      ppm_new (&dirmap, p->width, p->height);
      for (y = 0; y < dirmap.height; y++)
        {
          guchar *dstrow = &dirmap.col[y * dirmap.width * 3];
          double ysqr = (cy - y) * (cy - y);

          for (x = 0; x < dirmap.width; x++)
            {
              dstrow[x*3] = sqrt ((cx - x) * (cx - x) + ysqr) * 255 / maxdist;
            }
        }
      break;

    case ORIENTATION_RADIAL:
      ppm_new (&dirmap, p->width, p->height);
      for (y = 0; y < dirmap.height; y++)
        {
          guchar *dstrow = &dirmap.col[y * dirmap.width * 3];

          for (x = 0; x < dirmap.width; x++)
            {
              dstrow[x * 3] = (G_PI + atan2 (cy - y, cx - x)) *
                              255.0 / (G_PI * 2);
            }
        }
      break;

    case ORIENTATION_FLOWING:
      ppm_new (&dirmap, p->width / 6 + 5, p->height / 6 + 5);
      mkgrayplasma (&dirmap, 15);
      blur (&dirmap, 2, 2);
      blur (&dirmap, 2, 2);
      resize (&dirmap, p->width, p->height);
      blur (&dirmap, 2, 2);
      if (runningvals.general_paint_edges)
        edgepad (&dirmap, maxbrushwidth, maxbrushheight,
                 maxbrushwidth, maxbrushheight);
      break;

    case ORIENTATION_HUE:
      ppm_new (&dirmap, p->width, p->height);
      for (y = 0; y < dirmap.height; y++)
        {
          guchar *dstrow = &dirmap.col[y * dirmap.width * 3];
          guchar *srcrow = &p->col[y * p->width * 3];

          for (x = 0; x < dirmap.width; x++)
            {
              dstrow[x * 3] = get_hue (&srcrow[x * 3]);
            }
        }
      break;

    case ORIENTATION_ADAPTIVE:
      {
        guchar tmpcol[3] = {0, 0, 0};

        ppm_new (&dirmap, p->width, p->height);
        fill (&dirmap, tmpcol);
      }
      break;

    case ORIENTATION_MANUAL:
      ppm_new (&dirmap, p->width-maxbrushwidth*2, p->height-maxbrushheight*2);
      for (y = 0; y < dirmap.height; y++)
        {
          guchar *dstrow = &dirmap.col[y * dirmap.width * 3];
          double tmpy = y / (double)dirmap.height;
          for (x = 0; x < dirmap.width; x++)
            {
              dstrow[x * 3] = get_pixel_value(90 -
                                              get_direction(x /
                                                            (double)dirmap.width,
                                                            tmpy, 1));
            }
        }
      edgepad (&dirmap,
               maxbrushwidth, maxbrushwidth,
               maxbrushheight, maxbrushheight);
    break;
  }

  if (runningvals.size_type == SIZE_TYPE_VALUE)
    {
      ppm_new (&sizmap, p->width, p->height);
      for (y = 0; y < sizmap.height; y++)
        {
          guchar *dstrow = &sizmap.col[y * sizmap.width * 3];
          guchar *srcrow = &p->col[y * p->width * 3];

          for (x = 0; x < sizmap.width; x++)
            {
              dstrow[x * 3] =
                (srcrow[x * 3] + srcrow[x * 3 + 1] + srcrow[x * 3 + 2]) / 3;
            }
        }
    }
  else if (runningvals.size_type == SIZE_TYPE_RADIUS)
    {
      ppm_new (&sizmap, p->width, p->height);
      for (y = 0; y < sizmap.height; y++)
        {
          guchar *dstrow = &sizmap.col[y * sizmap.width * 3];
          double ysqr = (cy - y) * (cy - y);

          for (x = 0; x < sizmap.width; x++)
            {
              dstrow[x * 3] =
                sqrt ((cx - x) * (cx - x) + ysqr) * 255 / maxdist;
            }
        }
    }
  else if (runningvals.size_type == SIZE_TYPE_RADIAL)
    {
      ppm_new (&sizmap, p->width, p->height);
      for (y = 0; y < sizmap.height; y++)
        {
          guchar *dstrow = &sizmap.col[y * sizmap.width * 3];

          for (x = 0; x < sizmap.width; x++)
            {
              dstrow[x * 3] = (G_PI + atan2 (cy - y, cx - x)) *
                              255.0 / (G_PI * 2);
            }
        }
    }
  else if (runningvals.size_type == SIZE_TYPE_FLOWING)
    {
      ppm_new (&sizmap, p->width / 6 + 5, p->height / 6 + 5);
      mkgrayplasma (&sizmap, 15);
      blur (&sizmap, 2, 2);
      blur (&sizmap, 2, 2);
      resize (&sizmap, p->width, p->height);
      blur (&sizmap, 2, 2);
      if (runningvals.general_paint_edges)
        edgepad (&sizmap,
                 maxbrushwidth, maxbrushheight,
                 maxbrushwidth, maxbrushheight);
    }
  else if (runningvals.size_type == SIZE_TYPE_HUE)
    {
      ppm_new (&sizmap, p->width, p->height);
      for (y = 0; y < sizmap.height; y++)
        {
          guchar *dstrow = &sizmap.col[y * sizmap.width * 3];
          guchar *srcrow = &p->col[y * p->width * 3];

          for (x = 0; x < sizmap.width; x++)
            {
              dstrow[ x * 3] = get_hue (&srcrow[x * 3]);
            }
        }
    }
  else if (runningvals.size_type == SIZE_TYPE_ADAPTIVE)
    {
      guchar tmpcol[3] = {0, 0, 0};

      ppm_new (&sizmap, p->width, p->height);
      fill (&sizmap, tmpcol);
    }
  else if (runningvals.size_type == SIZE_TYPE_MANUAL)
    {
      ppm_new (&sizmap,
               p->width-maxbrushwidth * 2,
               p->height-maxbrushheight * 2);

      for (y = 0; y < sizmap.height; y++)
        {
          guchar *dstrow = &sizmap.col[y * sizmap.width * 3];
          double tmpy = y / (double)sizmap.height;

          for (x = 0; x < sizmap.width; x++)
            {
              dstrow[x * 3] = 255 * (1.0 - get_siz_from_pcvals (x / (double)sizmap.width, tmpy));
            }
        }
      edgepad (&sizmap,
               maxbrushwidth, maxbrushwidth,
               maxbrushheight, maxbrushheight);
    }
#if 0
  ppm_save(&sizmap, "/tmp/_sizmap.ppm");
#endif
  if (runningvals.place_type == PLACEMENT_TYPE_RANDOM)
    {
      i = tmp.width * tmp.height / (maxbrushwidth * maxbrushheight);
      i *= density;
    }
  else if (runningvals.place_type == PLACEMENT_TYPE_EVEN_DIST)
    {
      i = (int)(tmp.width * density / maxbrushwidth) *
          (int)(tmp.height * density / maxbrushheight);
#if 0
    g_printerr("i=%d\n", i);
#endif
    }

  if (i < 1)
    i = 1;

  max_progress = i;
  progstep = max_progress / 30;
  if (progstep < 10)
    progstep = 10;

  if (runningvals.place_type == PLACEMENT_TYPE_EVEN_DIST)
    {
      int j;

      xpos = g_new (int, i);
      ypos = g_new (int, i);
      for (j = 0; j < i; j++)
        {
          int factor = (int)(tmp.width * density / maxbrushwidth + 0.5);

          if (factor < 1)
            factor = 1;
          xpos[j] = maxbrushwidth/2 + (j % factor) * maxbrushwidth / density;
          ypos[j] = maxbrushheight/2 + (j / factor) * maxbrushheight / density;
        }
      for (j = 0; j < i; j++)
        {
          int a, b;

          a = g_rand_int_range (random_generator, 0, i);
          b = xpos[j]; xpos[j] = xpos[a]; xpos[a] = b;
          b = ypos[j]; ypos[j] = ypos[a]; ypos[a] = b;
        }
    }
Example #9
0
static int grab_command(shell_t *shell, shell_argv_t *cmd_argv, char *tag)
{
  int argc = cmd_argv->argc;
  char **argv = cmd_argv->argv;
  char *hdr = log_hdr_(tag);
  int ret = -1;

  /* Set error reporting tag */
  error_default_tag(tag);

  /* The 'stop' qualifier */
  if ( (argc > 1) && (strcmp(argv[1], "stop") == 0) ) {
    /* Check number of arguments */
    if ( check_argc(shell, cmd_argv, tag, 2, 2) )
      return -1;

    grab_end = 0;

    if ( grab_n > 0 ) {
      printf("%s%d frames recorded\n", hdr, grab_n);
      grab_n = 0;
    }
    else {
      printf("%sNo recording in progress\n", hdr);
    }

    ret = 0;
  }

  /* Unknown qualifier */
  else {
    frame_t *frame = grab_display->root;
    char *window_str = NULL;
    frame_geometry_t window;
    char *fname = NULL;
    int grab_animation = 0;
    long grab_dt = 0;
    int n;

    /* Check number of arguments */
    if ( check_argc(shell, cmd_argv, tag, 1, 4) )
      return -1;

    for (n = 1; n < argc; n++) {
      char *str = argv[n];
      char *eq = strchr(str, '=');

      if ( eq != NULL ) {
	*(eq++) = '\0';
	if ( strcmp(str, "frame") == 0 ) {
	  frame = frame_get_child_by_id(grab_display->root, eq);
	  if ( frame == NULL ) {
	    error(NULL, "Unknown frame '%s'", eq);
	    return -1;
	  }
	}
	else if ( strcmp(str, "window") == 0 ) {
	  window_str = eq;
	}
	else if ( strcmp(str, "t") == 0 ) {
	  grab_begin = (tstamp_get() / 1000);
	  grab_end = 0;
	  grab_n = 0;
	  grab_dt = (atoi(eq) * 1000);
	  if ( grab_dt < 0 )
	    grab_dt = 0;

	  grab_end = grab_begin + grab_dt;
	  grab_animation = 1;
	}
	else {
	  error(tag, "Illegal qualifier '%s'", str);
	  return -1;
	}
      }
      else {
	fname = str;
      }
    }

    /* Set source frame */
    if ( window_str != NULL ) {
      if ( frame_rgb_parse_geometry(&(frame->hdr.fb->rgb), window_str, &window) ) {
	error(NULL, "Syntax error in window geometry");
	return -1;
      }
    }
    else {
      window = frame->g;
      window.x = 0;
      window.y = 0;
    }

    /* Retrieve output format */
    grab_ppm = (ppm_filename_suffix(fname) != NULL);

    /* Construct an image file name */
    fname = grab_ppm ? ppm_filename(fname) : png_filename(fname);
    if ( fname == NULL ) {
      error(tag, "Failed to construct a valid image file name");
      return -1;
    }

    if ( grab_animation ) {
      char *suffix_str;
      char *suffix;

      if ( grab_ppm ) {
	suffix_str = PPM_SUFFIX;
	suffix = ppm_filename_suffix(fname);
      }
      else {
	suffix_str = PNG_SUFFIX;
	suffix = png_filename_suffix(fname);
      }

      if ( suffix != NULL )
	*suffix = '\0';

      grab_fname_size = strlen(fname) + 16;
      if ( grab_fname_fmt != NULL )
	free(grab_fname_fmt);
      grab_fname_fmt = (char *) malloc(grab_fname_size);
      snprintf(grab_fname_fmt, grab_fname_size, "%s.%%09lu%s", fname, suffix_str);

      grab_frame = frame;
      grab_window = window;

      ret = grab_save(0);
      if ( ret == 0 ) {
	printf("%sframe=%s window=%s t=%ld %s.*%s\n", hdr,
	       frame->hdr.id, frame_geometry_str(&window),
	       grab_dt / 1000, fname, suffix_str);
      }
      else {
	printf("%sFailed to write image file '%s'", hdr, grab_fname);

	grab_end = 0;
      }
    }
    else {
      if ( grab_ppm )
	ret = ppm_save(&(frame->hdr.fb->rgb), &window, fname);
      else
	ret = png_save(&(frame->hdr.fb->rgb), &window, fname);

      if ( ret == 0 )
	printf("%sframe=%s window=%s %s\n", hdr, frame->hdr.id, frame_geometry_str(&window), fname);
      else
	printf("%sFailed to write image file '%s'", hdr, fname);
    }

    free(fname);
  }

  return ret;
}
Example #10
0
void do_random_test(fas_context_ref_type context, int start, int stop, int count)
{
  //  printf ("start: %d  stop: %d\n", start, stop );

  while (fas_get_frame_index(context) < start)
    if (FAS_SUCCESS != fas_step_forward(context))
      fail("failed on advancement\n");

  fas_raw_image_type *ref_frames = malloc( (stop - start + 1)* sizeof(fas_raw_image_type));
  
  int i;
  fas_error_type video_error;

  while (fas_get_frame_index(context) <= stop)
    {
      i = fas_get_frame_index(context) - start;

      video_error = fas_get_frame(context, &(ref_frames[i]));
      if (video_error != FAS_SUCCESS)    fail("fail on test(1)\n");

      video_error = fas_step_forward(context);
      if (video_error != FAS_SUCCESS)    fail("fail on test(2)\n");

    }

  int index = -1;
  int prev_index;

  for (i=0;i<count;i++)
    {
      int offset = random() % (stop - start + 1);
      prev_index = index;
      index = start + offset;

      video_error = fas_seek_to_frame(context, index);
      if (video_error != FAS_SUCCESS)    fail("fail on test(seek)\n");


      fas_raw_image_type test_frame;
      video_error = fas_get_frame(context, &test_frame);
      if (video_error != FAS_SUCCESS)    fail("fail on test(seek2)\n");

      //      printf("offset: %d / %d\n", offset, stop - start + 1);
      
      if (!compare_frames(test_frame, ref_frames[offset]))
	{	  
	  char buffer[70];
	  
	  sprintf(buffer, "fail-%d-test.ppm", index);
	  ppm_save(&test_frame, buffer);
	  sprintf(buffer, "fail-%d-ref.ppm", index);
	  ppm_save(&ref_frames[offset], buffer);
	  sprintf(buffer, "failed on compare after seeking (%d->%d)\n", prev_index, index);
	  
	  fail(buffer);
	}
      
      fas_free_frame(test_frame);
    }
  
  for (i=0;i<stop - start + 1;i++)
    free(ref_frames[i].data);
    
  free(ref_frames);
}