Codebase list ruby-fxruby / 1a8478a
FXImage: Move code that ensures, that non owned pixel data isn't GC'ed to Ruby space. This way it also works for derived classes like FXJPGImage. Lars Kanis 10 years ago
5 changed file(s) with 29 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
142142 #include "FXRbIdVirtuals.h"
143143 #include "FXRbDrawableVirtuals.h"
144144 #include "FXRbImageVirtuals.h"
145
146 VALUE data_string;
147145 public:
148146 /// Create an image
149 FXRbImage(FXApp* a,const FXColor* pix=NULL,FXuint opts=0,FXint w=1,FXint h=1):FXImage(a,pix,opts,w,h),data_string(Qnil){
147 FXRbImage(FXApp* a,const FXColor* pix=NULL,FXuint opts=0,FXint w=1,FXint h=1):FXImage(a,pix,opts,w,h){
150148 FXRbRegisterAppSensitiveObject(this);
151149 }
152150
120120
121121 void FXRbImage::markfunc(FXImage* image){
122122 FXRbDrawable::markfunc(image);
123 if( image ){
124 rb_gc_mark(dynamic_cast<FXRbImage*>(image)->data_string);
125 }
126123 }
127124
128125
695695 =end
696696
697697 end
698
699 class FXImage
700 alias initialize_without_data_string initialize
701 def initialize(a, pix, *args)
702 initialize_without_data_string(a, pix, *args)
703 @data_string = (options & IMAGE_OWNED) != 0 ? nil : pix
704 end
705
706 alias setPixels_without_data_string setPixels
707 def setPixels(pix, *args)
708 setPixels_without_data_string(pix, *args)
709 @data_string = (options & IMAGE_OWNED) != 0 ? nil : pix
710 end
711 end
698712 end
699713
6363 }
6464 pix=FXRbConvertToFXColors(string_or_ary, &opts);
6565 }
66 FXRbImage *img = new FXRbImage(a,pix,opts,w,h);
67 img->data_string = (opts & IMAGE_OWNED) ? Qnil : string_or_ary;
68 return img;
66 return new FXRbImage(a,pix,opts,w,h);
6967 }
7068
7169 /// To get to the pixel data
10098 }
10199
102100 FXColor* pix=FXRbConvertToFXColors(string_or_ary, &opts);
103 (dynamic_cast<FXRbImage*>(self))->data_string = (opts & IMAGE_OWNED) ? Qnil : string_or_ary;
104101 if( NIL_P(w) || NIL_P(h) ){
105102 self->setData(pix,opts);
106103 }else{
1111 def test_fileExt
1212 assert_equal("bmp", FXBMPImage.fileExt)
1313 end
14
15 def test_image_from_pixel_data
16 img = FXBMPImage.new app
17 img.setPixels "rgbaRGBA", 0, 1, 2
18 bmp_data = FXMemoryStream.open(FXStreamSave, nil) do |outfile|
19 img.savePixels(outfile)
20 outfile.takeBuffer
21 end
22 assert_not_equal "rgbaRGBA", bmp_data
23
24 img2 = FXBMPImage.new app, bmp_data
25 assert_equal "rgbaRGBA", img2.pixel_string
26 end
1427 end