Ejemplo n.º 1
0
static void gx_knob_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
	g_assert(GX_IS_KNOB(widget));
	GdkPixbuf *pb = gtk_widget_render_icon(widget, get_stock_id(widget), GtkIconSize(-1), NULL);
	if (GDK_IS_PIXBUF (pb)) {
		gint fcount;
		GdkRectangle rect;
		get_image_dimensions (widget, pb, &rect, &fcount);
		requisition->width = rect.width;
		requisition->height = rect.height;
		_gx_regler_calc_size_request(GX_REGLER(widget), requisition);
		g_object_unref(pb);
	}
}
Ejemplo n.º 2
0
static gboolean gx_knob_expose(GtkWidget *widget, GdkEventExpose *event)
{
	g_assert(GX_IS_KNOB(widget));
	GdkRectangle image_rect, value_rect;
	GdkPixbuf *pb = gtk_widget_render_icon(widget, get_stock_id(widget), GtkIconSize(-1), NULL);
	if (GDK_IS_PIXBUF (pb)) {
		gint fcount;
		get_image_dimensions (widget, pb, &image_rect, &fcount);
		gdouble knobstate = _gx_regler_get_step_pos(GX_REGLER(widget), 1);
		_gx_regler_get_positions(GX_REGLER(widget), &image_rect, &value_rect);
		_gx_knob_expose(widget, &image_rect, knobstate, pb, fcount, gtk_widget_has_focus(widget));
		_gx_regler_display_value(GX_REGLER(widget), &value_rect);
		g_object_unref(pb);
	}
	return FALSE;
}
Ejemplo n.º 3
0
static gboolean gx_knob_leave_out (GtkWidget *widget, GdkEventCrossing *event)
{
	g_assert(GX_IS_KNOB(widget));
	if (gtk_widget_has_grab(widget) || gtk_widget_has_focus(widget)== TRUE) {
		return TRUE;
	}
	GdkRectangle image_rect;
	GdkPixbuf *pb = gtk_widget_render_icon(widget, get_stock_id(widget), GtkIconSize(-1), NULL);
	gint fcount;
	get_image_dimensions (widget, pb, &image_rect, &fcount);
	g_object_unref(pb);
	gdouble knobstate = _gx_regler_get_step_pos(GX_REGLER(widget), 1);
	_gx_regler_get_positions(GX_REGLER(widget), &image_rect, NULL);
	if (fcount == -1) {
		_gx_knob_expose(widget, &image_rect, knobstate, pb, fcount, FALSE);
	}
	return TRUE;
}
Ejemplo n.º 4
0
static int get_jpeg_image_dimensions(ImageSize *is, int *width, int *height)
{
	int marker = -1, jpeg_ok = 0;

	*width = *height = -1;

	if (is->infile || !is->file) {
		/* Expect SOI at start of file */
		if (first_marker(is) == M_SOI) {
			jpeg_ok = 1;
			/* Scan miscellaneous markers until we reach SOS. */
			for (; marker != M_SOS && marker != M_EOI; ) {
				marker = next_marker(is);
				switch (marker) {
				/* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
				 * treated as SOFn.  C4 in particular is actually DHT.
				 */
				case M_SOF0:		/* Baseline */
				case M_SOF1:		/* Extended sequential, Huffman */
				case M_SOF2:		/* Progressive, Huffman */
				case M_SOF3:		/* Lossless, Huffman */
				case M_SOF5:		/* Differential sequential, Huffman */
				case M_SOF6:		/* Differential progressive, Huffman */
				case M_SOF7:		/* Differential lossless, Huffman */
				case M_SOF9:		/* Extended sequential, arithmetic */
				case M_SOF10:		/* Progressive, arithmetic */
				case M_SOF11:		/* Lossless, arithmetic */
				case M_SOF13:		/* Differential sequential, arithmetic */
				case M_SOF14:		/* Differential progressive, arithmetic */
				case M_SOF15:		/* Differential lossless, arithmetic */
					get_image_dimensions(is, width, height);
					break;
				default:			/* Anything else just gets skipped */
					if (skip_variable(is) < 0)
						return -1;
					break;
				}
			}
		}
	}
	return jpeg_ok;
}
Ejemplo n.º 5
0
gboolean _gx_knob_pointer_event(GtkWidget *widget, gdouble x, gdouble y, const gchar *icon,
                                gboolean drag, int state, int button, GdkEventButton *event)
{
	int fcount;
	bool finemode = ((state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) != 0);
	GdkRectangle image_rect, value_rect;
	
	GxKnob *knob = GX_KNOB(widget);
	GdkPixbuf *pb = gtk_widget_render_icon(widget, icon, GtkIconSize(-1), NULL);
	GxKnobPrivate *priv = knob->priv;
	
	get_image_dimensions (widget, pb, &image_rect, &fcount);
	
	g_object_unref(pb);
	x += widget->allocation.x;
	y += widget->allocation.y;
	_gx_regler_get_positions(GX_REGLER(widget), &image_rect, &value_rect);
	if (!drag) {
		if (_gx_regler_check_display_popup(GX_REGLER(widget), &image_rect, &value_rect, event)) {
			return FALSE;
		}
	}
	static double last_y = 2e20;
		GtkAdjustment *adj = gtk_range_get_adjustment(GTK_RANGE(widget));
	double radius =  min(image_rect.width, image_rect.height) / 2;
	double posx = radius - x + image_rect.x; // x axis right -> left
	double posy = radius - y + image_rect.y; // y axis top -> bottom
	double value;
	if (!drag) {
		if (event && event->type == GDK_2BUTTON_PRESS) {
			last_y = 2e20;
		} else {
			last_y = posy;
			return TRUE;
		}
	}
	if (last_y < 1e20) { // in drag started in linear mode
		const double scaling = 0.005;
		double scal = (finemode ? scaling*0.1 : scaling);
		value = (posy - last_y) * scal;
		last_y = posy;
		gtk_range_set_value(GTK_RANGE(widget), adj->value + value * (adj->upper - adj->lower));
		return TRUE;
	}

	double angle = atan2(-posx, posy) + M_PI; // clockwise, zero at 6 o'clock, 0 .. 2*M_PI
	if (drag) {
		// block "forbidden zone" and direct moves between quadrant 1 and 4
		int quadrant = 1 + (int)(angle/M_PI_2);
		if (priv->last_quadrant == 1 && (quadrant == 3 || quadrant == 4)) {
			angle = scale_zero;
		} else if (priv->last_quadrant == 4 && (quadrant == 1 || quadrant == 2)) {
			angle = 2*M_PI - scale_zero;
		} else {
			if (angle < scale_zero) {
				angle = scale_zero;
			} else if (angle > 2*M_PI - scale_zero) {
				angle = 2*M_PI - scale_zero;
			}
			priv->last_quadrant = quadrant;
		}
	} else {
		if (angle < scale_zero) {
			angle = scale_zero;
		} else if (angle > 2*M_PI - scale_zero) {
			angle = 2*M_PI - scale_zero;
		}
		priv->last_quadrant = 0;
	}
	angle = (angle - scale_zero) / (2 * (M_PI-scale_zero)); // normalize to 0..1
	gtk_range_set_value(GTK_RANGE(widget), adj->lower + angle * (adj->upper - adj->lower));
	return TRUE;
}
Ejemplo n.º 6
0
int main(void)
{

    for (int flags = 0; flags < 4; flags++) {
        int64_t start = flow_get_high_precision_ticks();
        for (int i = 2; i < 8; i++) {
            flow_c * c = flow_context_create();

            if ((flags & 2) == 0) {
                flow_context_set_floatspace(c, flow_working_floatspace_as_is, 0, 0, 0);
            }

            size_t bytes_count = 0;
            uint8_t * bytes = get_bytes_cached(
                c, &bytes_count, "http://s3-us-west-2.amazonaws.com/imageflow-resources/test_inputs/u6.jpg");

            struct flow_graph * g = flow_graph_create(c, 10, 10, 200, 2.0);
            ERR2(c);

            int32_t last, input_placeholder = 0;

            struct flow_job * job = flow_job_create(c);
            ERR2(c);
            // flow_job_configure_recording(c, job, true, true, true, true, true);

            struct flow_io * input
                = flow_io_create_from_memory(c, flow_io_mode_read_seekable, bytes, bytes_count, job, NULL);
            flow_job_add_io(c, job, input, input_placeholder, FLOW_INPUT);

            int original_width, original_height;
            if (!get_image_dimensions(c, bytes, bytes_count, &original_width, &original_height))
                ERR2(c);

            int min_factor = 3;

            int32_t target_w = original_width / i;
            int32_t target_h = (int32_t)ceil((float)target_w / (float)original_width * (float)original_height);

            if (!flow_job_decoder_set_downscale_hints_by_placeholder_id(
                    c, job, input_placeholder, (target_w - 1) * min_factor, (target_h - 1) * min_factor,
                    (target_w - 1) * min_factor, (target_h - 1) * min_factor, (flags & 2) > 0, (flags & 2) > 0)) {
                ERR2(c);
            }

            last = flow_node_create_decoder(c, &g, -1, input_placeholder);
            last = flow_node_create_scale(c, &g, last, target_w, target_h, (flow_interpolation_filter_Robidoux),
                                          (flow_interpolation_filter_Robidoux), flags, 0);

            struct flow_bitmap_bgra * b;
            last = flow_node_create_bitmap_bgra_reference(c, &g, last, &b);

            if (!flow_job_execute(c, job, &g)) {
                ERR2(c);
            }

            // flow_graph_print_to_dot(c, g, stdout, "");
            flow_job_destroy(c, job);

            flow_context_destroy(c);
        }
        int64_t end = flow_get_high_precision_ticks();
        int64_t ms = (end - start) * 1000 / flow_get_profiler_ticks_per_second();
        fprintf(stdout, "With flags=%d, took %dms\n", flags, (int32_t)ms);
        fflush(stdout);
        // code
    }
    return 0; // Zero indicates success, while any
    // Non-Zero value indicates a failure/error

    /*  Before changing idct_fast
     *  With flags=0, took 839ms: srgb, standard
        With flags=1, took 743ms: srgb, reducev
        With flags=2, took 3778ms: linear, standard
        With flags=3, took 1703ms: srgb, reducev


        Using fastpow in linear_to_srgb

        With flags=0, took 819ms
        With flags=1, took 738ms
        With flags=2, took 1588ms
        With flags=3, took 1062ms



     */
}
Ejemplo n.º 7
0
Archivo: image.c Proyecto: pts/pts-qiv
/*
 *    Load & display image
 */
void qiv_load_image(qiv_image *q) {
  /* Don't initialize most variables here, initialize them after load_next_image: */
  struct stat st;
  const char *image_name;
  Imlib_Image *im;
  struct timeval load_before, load_after;

  char is_stat_ok;
  /* Used to omit slow disk operations if image_file doesn't exist or isn't
   * a file.
   */
  char is_maybe_image_file;
  char is_first_error = 1;

 load_next_image:
  is_stat_ok = 0;
  is_maybe_image_file = 1;
  image_name = image_names[image_idx];
  gettimeofday(&load_before, 0);

  if (imlib_context_get_image())
    imlib_free_image();

  q->real_w = q->real_h = -2;
  q->has_thumbnail = FALSE;
  if (!do_omit_load_stat) {
    is_stat_ok = 0 == stat(image_name, &st);
    is_maybe_image_file = is_stat_ok && S_ISREG(st.st_mode);
  }
  current_mtime = is_stat_ok ? st.st_mtime : 0;
  im = NULL;
  if (thumbnail && fullscreen && (is_stat_ok || maxpect)) {
    char *th_image_name =
        is_maybe_image_file ?
        get_thumbnail_filename(image_name, &is_maybe_image_file) : NULL;
    if (th_image_name) {
      im = imlib_load_image(th_image_name);
      if (im && maxpect) {
        get_image_dimensions(image_name, th_image_name,
                             &q->real_w, &q->real_h);
      }
      free(th_image_name);
      th_image_name = NULL;
    }
  }
  if (im) {  /* We have a dumb thumbnail in im. */
    if (maxpect) {
      current_mtime = 0;
      q->has_thumbnail = TRUE;
      /* Now im still has the thumbnail image. Keep it. */
    } else {  /* Use the real, non-thumbnail image instead. */
      imlib_context_set_image(im);
      imlib_free_image();
      im = is_maybe_image_file ? imlib_load_image((char*)image_name) : NULL;
    }
  } else {
    im = is_maybe_image_file ? imlib_load_image((char*)image_name) : NULL;
  }

  if (!im) { /* error */
    q->error = 1;
    q->orig_w = 400;
    q->orig_h = 300;

    if (to_root || to_root_t || to_root_s) {
      fprintf(stderr, "qiv: cannot load background_image\n");
      qiv_exit(1);
    }

    /* Shortcut to speed up lots of subsequent load failures. */
    if (is_first_error) {
      check_size(q, TRUE);
      if (first) {
        setup_win(q);
        first = 0;
      }
      gdk_window_set_background(q->win, &error_bg);
      gdk_beep();
      is_first_error = 0;
    }

    /* TODO(pts): Avoid the slow loop of copying pointers around in update_image_on_error. */
    update_image_on_error(q);
    /* This is a shortcut to avoid stack overflow in the recursion of
     * qiv_load_image -> update_image -> qiv_load_image -> update_image -> ...
     * if there are errors loading many subsequent images.
     */
    goto load_next_image;
  }

  if (thumbnail && !q->has_thumbnail && q->real_w < 0 && is_maybe_image_file) {
    FILE *f = fopen(image_name, "rb");
    if (f) {
      get_real_dimensions_fast(f, &q->real_w, &q->real_h);
      fclose(f);
    }
  }

  /* Retrieve image properties */
  imlib_context_set_image(im);
  q->error = 0;
  q->orig_w = imlib_image_get_width();
  q->orig_h = imlib_image_get_height();
  if (q->orig_w >= (1 << 23) / q->orig_h) {
    /* Workaround for Imlib2 1.4.6 on Ubuntu Trusty: PNG images with an
     * alpha channel and pixel count >= (1 << 23) are displayed as black.
     * imlib_image_query_pixel returns the correct value, but
     * imlib_render_pixmaps_for_whole_image_at_size renders only black
     * pixels if unzoomed.
     */
    Imlib_Color c;
    /* Without this call, imlib_image_set_has_alpha(0) is too early, and
     * it has no effect.
     */
    imlib_image_query_pixel(0, 0, &c);
    imlib_image_set_has_alpha(0);
  }
#ifdef HAVE_EXIF
  if (autorotate) {
    transform( q, orient( image_name));
  }
#endif

  check_size(q, TRUE);

  if (first) {
    setup_win(q);
    first = 0;
  }

  /* desktop-background -> exit */
  if (to_root || to_root_t || to_root_s) {
    set_desktop_image(q);
    if(slide)
      return;
    else
      qiv_exit(0);
  }

  gdk_window_set_background(q->win, &image_bg);

  if (do_grab || (fullscreen && !disable_grab) ) {
    gdk_keyboard_grab(q->win, FALSE, CurrentTime);
    gdk_pointer_grab(q->win, FALSE,
      GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK |
      GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, CurrentTime);
  }

  gettimeofday(&load_after, 0);
  /* load_elapsed used by update_image. */
  load_elapsed = ((load_after.tv_sec +  load_after.tv_usec / 1.0e6) -
                 (load_before.tv_sec + load_before.tv_usec / 1.0e6));

  update_image(q, FULL_REDRAW);
//    if (magnify && !fullscreen) {  // [lc]
//     setup_magnify(q, &magnify_img);
//     update_magnify(q, &magnify_img, FULL_REDRAW, 0, 0);
//    }
}