Thanks for help!
I don't think which i have a problem with "Image" type, because i use it as
library and i did several test. But problems occurs in interface.
Below some of simplifyed code:
class ImageWindow{
Gtk::Window *imagewindow;
Gtk::Image *image;
//interface image
Glib::RefPtr<Gdk::Pixbuf> interfaceimage;
//Images
Image* workimage;
public:
//constructors
ImageWindow(string imagepath,MainWindow* main);
//One kind of image process
virtual void erosion();
}
ImageWindow::ImageWindow(string imagepath){
//interface load
Glib::RefPtr<Gnome::Glade::Xml> Widgetstree =
Gnome::Glade::Xml::create("interface2.glade");
Widgetstree->get_widget("imagewindow", imagewindow);
Widgetstree->get_widget("image", image);
//Initializations
interfaceimage = Gdk::Pixbuf::create_from_file(imagepath);
workimage=pixbuftoImage(interfaceimage);
image->set(interfaceimage);
imagewindow->show_all();
}
void ImageWindow::erosion(){
Image *temp;
//Do image process
temp=MOperator::erosion(workimage,NULL...);
//image atualization
delete workimage;
workimage=temp;
image->clear();
interfaceimage.reset();
interfaceimage=imagetoPixbuf(workimage);
image->set(interfaceimage);
}
Image* pixbuftoImage(Glib::RefPtr<Gdk::Pixbuf> img){
Color_Image* out;
out = new Color_Image(img->get_height(),img->get_width());
ColorPixel **pixelmap = out->pixelmap;
unsigned char *pixel,*pixel_aux;
int bitesfactor,bitesperpixel;
pixel=img->get_pixels();
switch(img->get_bits_per_sample()){
case 8:
bitesfactor = 1;
bitesperpixel=bitesfactor*img->get_n_channels();
for(int i=0;i<img->get_height();i++)
for(int j=0;j<img->get_width();j++){
pixel_aux=pixel+i*img->get_rowstride() +
bitesperpixel*j;
pixelmap[i][j]=ColorPixel(*pixel_aux,*(pixel_aux+1),*(pixel_aux+2));
}
break;
default:
//Error: Too much bits per pixel
break;
}
return out;
}
Glib::RefPtr<Gdk::Pixbuf> imagetoPixbuf(Image* img){
Glib::RefPtr<Gdk::Pixbuf> out;
unsigned char *data;
data=new unsigned char[img->getHeight()*(img->getWidth())*3];
for(unsigned int i=0;i<img->getHeight();i++)
for(unsigned int j=0;j<img->getWidth();j++)
for(unsigned int k=0;k<3;k++)
data[3*i*(img->getWidth())+3*j+k]=(unsigned
char)(((float)256/img->getGreyLevels())*img->getPixel(j,i));
out =
Gdk::Pixbuf::create_from_data((guint8*)data,Gdk::COLORSPACE_RGB,false,8,img->getWidth(),img->getHeight(),3*img->getWidth());
return out;
}
My program treats with images and image processing, and i think that manual
memory management is better for me. Exist one way to do this, without
RefPtr<>?
Thanks again!
2009/5/25 Allen <[email protected]>
> Agree with Mark Roberts very much.
>
> On Mon, May 25, 2009 at 6:49 PM, Mark Roberts <[email protected]> wrote:
>
>> Dear Marcel!
>>
>> > I have memory leaks with use of images...
>> >
>> > Glib::RefPtr<Gdk::Pixbuf> interfaceimage;
>> > Image* workimage;
>> > Gtk::Image *image;
>> > interfaceimage = Gdk::Pixbuf::create_from_file(imagepath);
>> > workimage=pixbuftoImage(interfaceimage);
>> > image->set(interfaceimage);
>> >
>> > Image is my type for images...
>> >
>> > image->clear();
>> > interfaceimage.reset();
>> > interfaceimage=imagetoPixbuf(workimage);
>> > image->set(interfaceimage);
>>
>> It seems strange to call image->set() on an uninitialised pointer. This is
>> surely not how Gtk::Image::set(Glib::RefPtr<Gdk::Pixbuf>) is supposed to
>> be used.
>>
>> If you do similar things inside your own type "Image", it is possible that
>> you manage to circumvent the automatic memory mangement provided by
>> RefPtr<>. How about posting a small but complete program which includes
>> your type "Image"? I'm sure we can spot a memory leak, if there is one.
>>
>> All the best,
>> Mark
>> _______________________________________________
>> gtkmm-list mailing list
>> [email protected]
>> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>>
>
>
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list