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
142 | 142 |
#include "FXRbIdVirtuals.h"
|
143 | 143 |
#include "FXRbDrawableVirtuals.h"
|
144 | 144 |
#include "FXRbImageVirtuals.h"
|
145 | |
|
146 | |
VALUE data_string;
|
147 | 145 |
public:
|
148 | 146 |
/// 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){
|
150 | 148 |
FXRbRegisterAppSensitiveObject(this);
|
151 | 149 |
}
|
152 | 150 |
|
695 | 695 |
=end
|
696 | 696 |
|
697 | 697 |
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
|
698 | 712 |
end
|
699 | 713 |
|
63 | 63 |
}
|
64 | 64 |
pix=FXRbConvertToFXColors(string_or_ary, &opts);
|
65 | 65 |
}
|
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);
|
69 | 67 |
}
|
70 | 68 |
|
71 | 69 |
/// To get to the pixel data
|
|
100 | 98 |
}
|
101 | 99 |
|
102 | 100 |
FXColor* pix=FXRbConvertToFXColors(string_or_ary, &opts);
|
103 | |
(dynamic_cast<FXRbImage*>(self))->data_string = (opts & IMAGE_OWNED) ? Qnil : string_or_ary;
|
104 | 101 |
if( NIL_P(w) || NIL_P(h) ){
|
105 | 102 |
self->setData(pix,opts);
|
106 | 103 |
}else{
|
11 | 11 |
def test_fileExt
|
12 | 12 |
assert_equal("bmp", FXBMPImage.fileExt)
|
13 | 13 |
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
|
14 | 27 |
end
|