Re: pixbuf outermost pixels are white

2013-08-23 Thread Søren Sandmann
Jan Kratochvil j...@jankratochvil.net writes:

 Hi,

 I found somewhere on web how to draw custom data images into a widget using
 Pixbuf.  It basically works.

 Unfortunately the image always has the outermost source pixels mixed with
 white border.  I want the whole window to be just blue but it is not:
   http://www.jankratochvil.net/t/pixbuf.png
   Fedora 19 x86_64: gtk3-3.8.2-2.fc19.x86_64
 gtkmm30-3.8.1-1.fc19.x86_64

You probably want to set the extend mode to CAIRO_EXTEND_PAD by doing
the C++ equivalent of this:

cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);

after setting the pixbuf as the cairo source.


Søren
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: pixbuf outermost pixels are white

2013-08-23 Thread Jan Kratochvil
On Fri, 23 Aug 2013 21:15:14 +0200, Søren Sandmann wrote:
 You probably want to set the extend mode to CAIRO_EXTEND_PAD by doing
 the C++ equivalent of this:
 
 cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
 
 after setting the pixbuf as the cairo source.

It really works, thanks!

Moreover I can even turn off the smoothing (not appropriate in my case):
auto 
surfacepattern(Cairo::RefPtrCairo::SurfacePattern::cast_dynamic(cr-get_source()));
surfacepattern-set_extend(Cairo::EXTEND_PAD);
surfacepattern-set_filter(Cairo::FILTER_NEAREST);

http://www.jankratochvil.net/t/2.png


Regards,
Jan Kratochvil


/*
g++ -o 1 1.C -Wall -Werror -std=gnu++11 -g $(pkg-config --cflags --libs 
gtkmm-3.0);./1
*/
#include gdkmm/general.h
#include gtkmm/main.h
#include gtkmm/window.h
#include gtkmm/drawingarea.h
#include vector
#include stdio.h
using namespace std;

class Area:public Gtk::DrawingArea {
  bool on_draw(const Cairo::RefPtrCairo::Context cr) {
//cr-translate(+0.5,+0.5);
class RGB {
public:
  guint8 r=0,g=0,b=0;
};
vectorRGB data24;
RGB rgb;
rgb.r=255; rgb.g=0  ; rgb.b=0  ; data24.push_back(rgb);
rgb.r=0  ; rgb.g=255; rgb.b=255; data24.push_back(rgb);
rgb.r=0  ; rgb.g=0  ; rgb.b=255; data24.push_back(rgb);
rgb.r=255; rgb.g=255; rgb.b=0  ; data24.push_back(rgb);
Glib::RefPtrGdk::Pixbuf pixbuf;
pixbuf=Gdk::Pixbuf::create_from_data((const guint8 
*)data24.data(),Gdk::COLORSPACE_RGB,false/*has_alpha*/,8/*bits_per_sample*/,
  2 /*width*/,
  2 /*height*/,
  2*3/*rowstride==width*/);
//cr-set_identity_matrix();
{
  cr-save();
  // Does not work: cr-set_antialias(Cairo::ANTIALIAS_NONE);
  // Does not work: cr-set_fill_rule(Cairo::FILL_RULE_EVEN_ODD);
  cr-scale(double(get_allocation().get_width ())/pixbuf-get_width (),
double(get_allocation().get_height())/pixbuf-get_height());
  Gdk::Cairo::set_source_pixbuf(cr,pixbuf);
  auto 
surfacepattern(Cairo::RefPtrCairo::SurfacePattern::cast_dynamic(cr-get_source()));
  surfacepattern-set_extend(Cairo::EXTEND_PAD);
  surfacepattern-set_filter(Cairo::FILTER_NEAREST);
  cr-rectangle(0,0,pixbuf-get_width(),pixbuf-get_height());
  cr-fill();
  cr-restore();
}
return true;
  }
};

int main() {
  Gtk::Main *app=new Gtk::Main();
  Gtk::Window *win=new Gtk::Window();
  win-set_default_size(500,500);
  win-maximize();
  win-add(*new Area());
  win-show_all();
  app-run(*win);
}
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list