Commit ca0c20e1 authored by Claes Sjofors's avatar Claes Sjofors

Ge image bugfix for not keeping rotation and color tone, and float position for images implemented

parent 746c23fa
......@@ -1859,6 +1859,47 @@ int GlowDrawGtk::image( GlowWind *wind, int x, int y, int width, int height,
return 1;
}
int GlowDrawGtk::image_d( GlowWind *wind, double x, double y, int width, int height,
glow_tImImage image, glow_tPixmap pixmap, glow_tPixmap clip_mask)
{
DrawWindGtk *w = (DrawWindGtk *) wind->window;
cairo_t *cr;
if ( ctx->nodraw) return 1;
if ( width == 0 || height == 0)
return 1;
cr = gdk_cairo_create( w->window);
if ( clip_mask)
set_image_clip_mask( clip_mask, x, y);
else if ( w->clip_on) {
set_clip( w, get_gc( this, glow_eDrawType_Line, 0));
set_cairo_clip( w, cr);
}
if ( !w->draw_buffer_only) {
gdk_cairo_set_source_pixbuf( cr, (GdkPixbuf *)image, x, y);
cairo_paint( cr);
}
if ( w->double_buffer_on) {
cairo_t *cr2;
cr2 = gdk_cairo_create( w->buffer);
gdk_cairo_set_source_pixbuf( cr2, (GdkPixbuf *)image, x, y);
cairo_paint( cr2);
cairo_destroy( cr2);
}
if ( clip_mask)
reset_image_clip_mask();
else if ( w->clip_on) {
reset_clip( w, get_gc( this, glow_eDrawType_Line, 0));
reset_cairo_clip( w, cr);
}
cairo_destroy(cr);
return 1;
}
int GlowDrawGtk::fill_rect( GlowWind *wind, int x, int y, int w, int h,
glow_eDrawType gc_type)
......@@ -2902,13 +2943,13 @@ void GlowDrawGtk::image_flip_horizontal( glow_tImImage *image)
#endif
}
void GlowDrawGtk::image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
int GlowDrawGtk::image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tImData *im_data,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask)
{
if ( width == gdk_pixbuf_get_width((GdkPixbuf *)*im) &&
height == gdk_pixbuf_get_height((GdkPixbuf *)*im))
return;
return 0;
if ( width == 0 && height == 0) {
width = gdk_pixbuf_get_width((GdkPixbuf *)*im);
height = gdk_pixbuf_get_height((GdkPixbuf *)*im);
......@@ -2917,7 +2958,7 @@ void GlowDrawGtk::image_scale( int width, int height, glow_tImImage orig_im, glo
if ( !orig_im) {
// Scale from im
if ( !*im)
return;
return 0;
GdkPixbuf *im_old = (GdkPixbuf *)*im;
*im = gdk_pixbuf_scale_simple( (GdkPixbuf *)*im, width, height, GDK_INTERP_NEAREST);
......@@ -2925,14 +2966,14 @@ void GlowDrawGtk::image_scale( int width, int height, glow_tImImage orig_im, glo
}
else {
// Scale from orig_im
if ( *im)
gdk_pixbuf_unref( (GdkPixbuf *)*im);
#if defined PWRE_CONF_RSVG
if (im_data && *im_data && *im) {
RsvgHandle *handle;
const char *imagefile;
gdk_pixbuf_unref( (GdkPixbuf *)*im);
handle = (RsvgHandle *) *im_data;
imagefile = rsvg_handle_get_base_uri( handle);
*im = rsvg_pixbuf_from_file_at_size(imagefile, width, height, NULL);
......@@ -2941,9 +2982,12 @@ void GlowDrawGtk::image_scale( int width, int height, glow_tImImage orig_im, glo
#else
{
#endif
if ( *im)
gdk_pixbuf_unref( (GdkPixbuf *)*im);
*im = gdk_pixbuf_scale_simple( (GdkPixbuf *)orig_im, width, height, GDK_INTERP_NEAREST);
}
}
return 1;
}
int GlowDrawGtk::image_load( char *imagefile,
......
......@@ -160,6 +160,8 @@ class GlowDrawGtk : public GlowDraw {
void *pixmaps, glow_eDrawType gc_type, int idx, int line);
virtual int image( GlowWind *w, int x, int y, int width, int height,
glow_tImImage image, glow_tPixmap pixmap, glow_tPixmap clip_mask);
virtual int image_d( GlowWind *wind, double x, double y, int width, int height,
glow_tImImage image, glow_tPixmap pixmap, glow_tPixmap clip_mask);
virtual void set_cursor( GlowWind *w, glow_eDrawCursor cursor);
virtual int get_text_extent( const char *text, int len,
......@@ -206,7 +208,7 @@ class GlowDrawGtk : public GlowDraw {
void image_rotate( glow_tImImage *image, int to_rotation, int from_rotation);
void image_flip_vertical( glow_tImImage *image);
void image_flip_horizontal( glow_tImImage *image);
void image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
int image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tImData *im_data,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask);
int image_load( char *imagefile,
......
......@@ -2898,9 +2898,9 @@ void GlowDrawXLib::image_flip_horizontal( glow_tImImage *image)
#endif
}
void GlowDrawXLib::image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tImData *im_data,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask)
int GlowDrawXLib::image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tImData *im_data,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask)
{
#if 0
#if defined IMLIB
......@@ -2915,6 +2915,7 @@ void GlowDrawXLib::image_scale( int width, int height, glow_tImImage orig_im, gl
*im_mask = (glow_tPixmap) Imlib_move_mask( (ImlibData *)imlib, (ImlibImage *)*im);
#endif
#endif
return 0;
}
int GlowDrawXLib::image_load( char *imagefile,
......
......@@ -231,7 +231,7 @@ class GlowDrawXLib : public GlowDraw {
void image_rotate( glow_tImImage *image, int to_rotation, int from_rotation);
void image_flip_vertical( glow_tImImage *image);
void image_flip_horizontal( glow_tImImage *image);
void image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
int image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tImData *im_data,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask);
int image_load( char *imagefile,
......
......@@ -113,6 +113,9 @@ class GlowDraw {
void *pixmaps, glow_eDrawType gc_type, int idx, int line) {return 1;}
virtual int image( GlowWind *w, int x, int y, int width, int height,
glow_tImImage image, glow_tPixmap pixmap, glow_tPixmap clip_mask) {return 1;}
virtual int image_d( GlowWind *wind, double x, double y, int width, int height,
glow_tImImage img, glow_tPixmap pixmap, glow_tPixmap clip_mask) {
return image(wind,(int)x, (int)y, width, height, img, pixmap, clip_mask);}
virtual void set_cursor( GlowWind *w, glow_eDrawCursor cursor) {}
virtual void set_nav_cursor( glow_eDrawCursor cursor) {}
......@@ -155,9 +158,9 @@ class GlowDraw {
virtual void image_rotate( glow_tImImage *image, int to_rotation, int from_rotation) {}
virtual void image_flip_vertical( glow_tImImage *image) {}
virtual void image_flip_horizontal( glow_tImImage *image) {}
virtual void image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tImData *im_data,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask) {}
virtual int image_scale( int width, int height, glow_tImImage orig_im, glow_tImImage *im,
glow_tImData *im_data,
glow_tPixmap *im_pixmap, glow_tPixmap *im_mask) {return 0;}
virtual int image_load( char *imagefile,
glow_tImImage *orig_im, glow_tImImage *im, glow_tImData *im_data) {return 0;}
virtual int image_render( int width, int height,
......
......@@ -80,7 +80,8 @@ GrowImage::GrowImage( GrowCtx *glow_ctx, const char *name, double x, double y,
current_nav_color_inverse(0), current_nav_direction(0),
flip_vertical(false), flip_horizontal(false),
current_flip_vertical(false), current_flip_horizontal(false),
rotation(0), current_rotation(0), fixposition(0)
rotation(0), current_rotation(0), fixposition(0),
original_width(0), original_height(0)
{
strcpy( n_name, name);
strcpy( image_filename, "");
......@@ -112,6 +113,7 @@ void GrowImage::copy_from( const GrowImage& im)
{
memcpy( this, &im, sizeof(im));
image = 0;
original_image = 0;
pixmap = 0;
nav_pixmap = 0;
clip_mask = 0;
......@@ -200,25 +202,53 @@ int GrowImage::insert_image( const char *imagefile)
return 0;
current_width = int( ctx->mw.zoom_factor_x / ctx->mw.base_zoom_factor *
ctx->gdraw->image_get_width( image));
ctx->gdraw->image_get_width( image) + 0.5);
current_height = int( ctx->mw.zoom_factor_y / ctx->mw.base_zoom_factor *
ctx->gdraw->image_get_height( image));
ctx->gdraw->image_get_height( image) + 0.5);
current_color_tone = color_tone;
current_color_lightness = color_lightness;
current_color_intensity = color_intensity;
current_color_shift = color_shift;
current_color_inverse = color_inverse;
original_width = ctx->gdraw->image_get_width( original_image);
original_height = ctx->gdraw->image_get_height( original_image);
#if 0
set_image_color( image, NULL);
ctx->gdraw->image_scale( current_width, current_height,
original_image, &image, &image_data, &pixmap, &clip_mask);
ctx->gdraw->image_render( current_width, current_height,
original_image, &image, &pixmap, &clip_mask);
#endif
ur.posit( ll.x + double( current_width) / ctx->mw.zoom_factor_x,
ll.y + double( current_height) / ctx->mw.zoom_factor_y);
get_node_borders();
int w,h;
if ( abs(rotation) % 180 == 90) {
w = current_height;
h = current_width;
}
else {
w = current_width;
h = current_height;
}
ctx->gdraw->image_render( w, h, &original_image, &image, &pixmap, &clip_mask);
ctx->gdraw->image_scale( w, h, original_image, &image, &image_data, &pixmap, &clip_mask);
if ( current_color_tone != glow_eDrawTone_No ||
current_color_lightness != 0 ||
current_color_intensity != 0 ||
current_color_shift != 0 ||
current_color_inverse != 0)
set_image_color( image, 0);
if ( abs(rotation)%360 != 0)
ctx->gdraw->image_rotate( &image, rotation, 0);
if ( current_flip_vertical)
ctx->gdraw->image_flip_vertical( &image);
else if ( current_flip_horizontal)
ctx->gdraw->image_flip_horizontal( &image);
return 1;
}
......@@ -848,19 +878,19 @@ void GrowImage::draw( GlowWind *w, GlowTransform *t, int highlight, int hot, voi
hot = 0;
}
int x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y;
double x1, y1, x2, y2, ll_x, ll_y, ur_x, ur_y;
if (!t) {
x1 = int( trf.x( ll.x, ll.y) * w->zoom_factor_x) - w->offset_x;
y1 = int( trf.y( ll.x, ll.y) * w->zoom_factor_y) - w->offset_y;
x2 = int( trf.x( ur.x, ur.y) * w->zoom_factor_x) - w->offset_x;
y2 = int( trf.y( ur.x, ur.y) * w->zoom_factor_y) - w->offset_y;
x1 = ( trf.x( ll.x, ll.y) * w->zoom_factor_x) - w->offset_x;
y1 = ( trf.y( ll.x, ll.y) * w->zoom_factor_y) - w->offset_y;
x2 = ( trf.x( ur.x, ur.y) * w->zoom_factor_x) - w->offset_x;
y2 = ( trf.y( ur.x, ur.y) * w->zoom_factor_y) - w->offset_y;
}
else {
x1 = int( trf.x( t, ll.x, ll.y) * w->zoom_factor_x) - w->offset_x;
y1 = int( trf.y( t, ll.x, ll.y) * w->zoom_factor_y) - w->offset_y;
x2 = int( trf.x( t, ur.x, ur.y) * w->zoom_factor_x) - w->offset_x;
y2 = int( trf.y( t, ur.x, ur.y) * w->zoom_factor_y) - w->offset_y;
x1 = ( trf.x( t, ll.x, ll.y) * w->zoom_factor_x) - w->offset_x;
y1 = ( trf.y( t, ll.x, ll.y) * w->zoom_factor_y) - w->offset_y;
x2 = ( trf.x( t, ur.x, ur.y) * w->zoom_factor_x) - w->offset_x;
y2 = ( trf.y( t, ur.x, ur.y) * w->zoom_factor_y) - w->offset_y;
}
ll_x = min( x1, x2);
......@@ -887,9 +917,13 @@ void GrowImage::draw( GlowWind *w, GlowTransform *t, int highlight, int hot, voi
else {
if ( pixmap || image) {
int sts = 0;
int sts_rotate = 0;
int sts_color = 0;
int sts_flip_vert = 0;
int sts_flip_horiz = 0;
int sts_scale = 0;
int flip_vert, flip_horiz;
glow_tImImage om = original_image;
glow_tImImage old_image = image;
if ( colornode) {
flip_vert = (( ((GrowNode *)node)->flip_vertical && !flip_vertical) ||
......@@ -902,22 +936,15 @@ void GrowImage::draw( GlowWind *w, GlowTransform *t, int highlight, int hot, voi
flip_horiz = flip_horizontal;
}
if ( ur_x - ll_x != current_width || ur_y - ll_y != current_height) {
ctx->gdraw->image_scale( ur_x - ll_x, ur_y - ll_y, om,
&image, &image_data, &pixmap, &clip_mask);
current_width = ctx->gdraw->image_get_width( image);
current_height = ctx->gdraw->image_get_height( image);
sts = 1;
om = 0;
if ( rotation != current_rotation)
current_rotation = 0;
if ( int(ur_x - ll_x + 0.5) != current_width || int(ur_y - ll_y + 0.5) != current_height) {
sts_scale = 1;
sts = 1;
}
if ( rotation != current_rotation) {
ctx->gdraw->image_rotate( &image, rotation, current_rotation);
current_rotation = rotation;
om = 0;
sts = 1;
sts_rotate = 1;
sts = 1;
}
if ( (colornode && !(current_color_tone == ((GrowNode *)node)->color_tone &&
......@@ -929,47 +956,33 @@ void GrowImage::draw( GlowWind *w, GlowTransform *t, int highlight, int hot, voi
current_color_lightness == color_lightness &&
current_color_intensity == color_intensity &&
current_color_shift == color_shift &&
current_color_inverse == color_inverse)) ||
( image != old_image &&
((colornode && (glow_eDrawTone_No != ((GrowNode *)node)->color_tone ||
((GrowNode *)node)->color_lightness ||
((GrowNode *)node)->color_intensity ||
((GrowNode *)node)->color_shift ||
((GrowNode *)node)->color_inverse)) ||
( !colornode && (glow_eDrawTone_No != color_tone ||
color_lightness ||
color_intensity ||
color_shift ||
color_inverse))))) {
set_image_color( original_image, colornode);
if ( ctx->gdraw->image_get_width( image) != current_width ||
ctx->gdraw->image_get_height( image) != current_height) {
ctx->gdraw->image_scale( ur_x - ll_x, ur_y - ll_y, 0,
&image, &image_data, &pixmap, &clip_mask);
current_width = ctx->gdraw->image_get_width( image);
current_height = ctx->gdraw->image_get_height( image);
}
om = 0;
current_color_inverse == color_inverse))) {
sts_color = 1;
sts = 1;
}
if ( flip_vert != current_flip_vertical) {
ctx->gdraw->image_flip_vertical( &image);
current_flip_vertical = flip_vert;
sts_flip_vert = 1;
sts = 1;
}
if ( flip_horiz != current_flip_horizontal) {
ctx->gdraw->image_flip_horizontal( &image);
current_flip_horizontal = flip_horiz;
sts_flip_horiz = 1;
sts = 1;
}
if ( sts) {
ctx->gdraw->image_render( ur_x - ll_x, ur_y - ll_y, &original_image,
&image, &pixmap, &clip_mask);
om = 0;
current_width = ctx->gdraw->image_get_width( image);
current_height = ctx->gdraw->image_get_height( image);
int w,h;
if ( abs(rotation) % 180 == 90) {
w = int(ur_y - ll_y + 0.5);
h = int(ur_x - ll_x + 0.5);
}
else {
w = int(ur_x - ll_x + 0.5);
h = int(ur_y - ll_y + 0.5);
}
if ( colornode) {
current_color_tone = ((GrowNode *)colornode)->color_tone;
current_color_lightness = ((GrowNode *)colornode)->color_lightness;
......@@ -984,9 +997,35 @@ void GrowImage::draw( GlowWind *w, GlowTransform *t, int highlight, int hot, voi
current_color_shift = color_shift;
current_color_inverse = color_inverse;
}
ctx->gdraw->image_render( w, h, &original_image, &image, &pixmap, &clip_mask);
if ( w != original_width || h != original_height) {
int sts2 = ctx->gdraw->image_scale( w, h, om, &image, &image_data, &pixmap, &clip_mask);
if ( sts2 == 0) {
ctx->gdraw->image_copy( om, &image);
ctx->gdraw->image_scale( w, h, om, &image, &image_data, &pixmap, &clip_mask);
}
}
else
ctx->gdraw->image_copy( om, &image);
if ( current_color_tone != glow_eDrawTone_No ||
current_color_lightness != 0 ||
current_color_intensity != 0 ||
current_color_shift != 0 ||
current_color_inverse != 0)
set_image_color( image, colornode);
if ( abs(rotation)%360 != 0)
ctx->gdraw->image_rotate( &image, rotation, 0);
if ( flip_vert)
ctx->gdraw->image_flip_vertical( &image);
else if ( flip_horiz)
ctx->gdraw->image_flip_horizontal( &image);
om = 0;
current_width = ctx->gdraw->image_get_width( image);
current_height = ctx->gdraw->image_get_height( image);
}
ctx->gdraw->image( w, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y,
ctx->gdraw->image_d( w, ll_x, ll_y, ur_x - ll_x, ur_y - ll_y,
image, pixmap, clip_mask);
}
else
......@@ -1218,10 +1257,8 @@ int GrowImage::set_image_color( glow_tImImage om, void *n)
if ( !(c_color_tone == glow_eDrawTone_No || c_color_tone >= glow_eDrawTone__) ||
c_color_shift || c_color_intensity || c_color_lightness || inverse) {
ctx->gdraw->image_pixel_iter( om, &image, pixel_cb, this);
ctx->gdraw->image_pixel_iter( 0, &image, pixel_cb, this);
}
else if ( image != om)
ctx->gdraw->image_copy( om, &image);
return 1;
}
......
......@@ -334,6 +334,8 @@ class GrowImage : public GlowArrayElem {
float factor_intens;
float factor_light;
int fixposition; //!< Can't be moved.
int original_width;
int original_height;
//! Read the image file and create pixmaps for the image.
/*!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment