-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with data_w,data_h, w, h of Fl_Image #427
Comments
@ZJUGKC : Good catch. |
@ManoloFLTK Commit bfae813 breaks existing code. I'm not sure what and how it can break code, but there's one specific thing I noticed: if you scale() an image and then copy(w, h) the image to another image, then the resulting image does not fulfill the expectations that I'll post a test program that shows the issue soon. |
Background: in FLTK 1.3
The last two lines show that
The last line shows that More background: Fl_Image::copy(W, H) used to be a valid means to convert an image to another size and use its data() array to access the image data for instance to write a PNG file. I used What I described above can perhaps be resolved differently (how?) because it's internal stuff (caused by introducing Fl_Image::scale(), BTW) but the issue remains that user code might want to "convert" an image to another size to use its data array in that new size. Demo program: |
None of this indicates a break of the API compatibility between FLTK 1.3 and 1.4, because Fl_Image::scale() appears with 1.4, so if an app uses only 1.3 means, Fl_Image::copy() produces in 1.4 the same results as in 1.3. A consequence of using Fl_Image::scale() is that it's often but not always possible to ignore that images have 2 sizes It's true that the doc presently states "The values [w() and h()] are equal to data_w() and data_h() when the image is created". The recent commit makes Fl_Image::copy() violate this statement. I see 2 ways out:
|
Solution 2) above is now committed. It's good to have with Fl_Image::copy() a means to set an image data size. |
@ManoloFLTK Thanks for the update, this looks much better now and works well for me. FTR, you wrote:
Yes, this is strictly correct and I was aware of this. However, users tend to "interpolate" and use both features in their programs. The icon issue discussed in another thread was such an issue:
Conclusion: in FLTK 1.4 we have an ambiguity in the general feature
I think we need to document (specify!) this not only for users but also for developers of future changes and I think point (2) above is the correct implementation (as you did already in the update). |
@ZJUGKC Manolo asked in #427 (comment) whether you see remaining problems. From my side the issue can be closed (documentation questions are now handled in issue #431). Do you agree? If yes, please close this issue. TIA. |
There are some remaining problems:
|
@Albrecht-S Following point 4. above, do you agree for me to modify the 3-argument
|
@ManoloFLTK Yes, I agree, this looks correct. Thanks. |
Fix Fl_Tiled_Image made from scaled source image. Fix Fl_Shared_Image::update() to allow scaled source image. Correct handling of default value (-1) of 3rd argument of 3-argument Fl_BMP_Image constructor.
@ZJUGKC Many thanks for your extremely valuable input. I believe all "remaining problems" you pointed are now fixed in the git repo. Nevertheless, I don't agree with your point 5. because Fl_Image::copy(W, H) is documented to produce an image where w() == data_w() == W and h() == data_h() == H. I therefore did not change the source code of class Fl_SVG_Image. Please, close this issue if you agree. |
Thanks for fixing 3 points. But I still have problems about point 2 and point 5. 1 In Fl_Shared_Image.cxx, line 474,
the temp object using in
These statements are in mthod |
@ZJUGKC Point 1: Thank you very much for investigating and reporting this. I believe what you found is a very good point but I don't know what solution would be the best. Basically we have a conflict between the "old" (1.3.x) @ZJUGKC, @ManoloFLTK: I believe that there are probably more issues WRT |
The code at Fl_SVG_Image.cxx, line 178-179 is correct because it's used only by the private Fl_SVG_Image constructor with a |
@ManoloFLTK OK, you are right, this is not a problem. So the remaining problem is POINT 1 (Fl_Shared_Image). |
@ZJUGKC @ManoloFLTK If everything but point 1 (the issue of Fl_Shared_Image) is resolved now, then I suggest to close this issue. The remaining Fl_Shared_Image issue has been referred to in issue #188 and will be resolved in this context. Closing this issue will avoid having two issues open for "the same thing". @ZJUGKC If you agree, please close. |
About the "remaining issue" in class Fl_Shared_Image : I believe the current FLTK source code is correct for the reasons detailed below. The instruction under discussion corresponds to this part of the doc of the get() member function :
I believe the size mentionned in the doc is the drawing size, that is, the get() member function wants to produce a shared image whose drawing size is WxH. If the find() member function has found one with this drawing size, it's not necessary to do the copy() operation to produce a new shared image with the required drawing size : we already have it. Therefore, the instruction under discussion is correct to compare W and H with the drawing size (w() and h()) rather than with the data size (data_w() and data_h()). That is visible, I believe, slightly modifying FLTK's test/pixmap_browser program as follows:
after line 52 : and also comment out the call to the scale() member function below: The modified code produces with the added scale() call a shared image with drawing size 100x150 and with data size whatever is the size of the read image file. The following get() call calls the instruction under discussion, and the test made is negative so the program flow skips the copy() call, because it's not needed. If the source code were modified as suggested by the OP, a copy of the image would be done and the copy would be memorized, although these tasks are not necessary. |
@ManoloFLTK and others: please avoid using |
Yes, that's basically true, but ... @ManoloFLTK This documentation was written when only one size existed, and all Fl_Shared_Image's had to be copied (not scaled) to create another size. In current FLTK 1.4 this is ambiguous and that's why issue #188 exists. I doubt that the current implementation works as it should [1], and based on this, analyzing existing code is mute. But anyway, if your analysis is correct for whatever code exists now, then this is another reason to close this issue - and investigate this further when evaluating issue #188. [1] I have some ideas what to test to verify or falsify my gut feeling but this would need more time than I can afford now. Sorry. |
@ManoloFLTK If we consider This difficult position is caused by no following a principle of separation between data-storage and data-presentation. If a new drawing class containing OK, I agree to close this issue. |
@ZJUGKC Thanks. |
data_w
anddata_h
are added to Fl_Image from version 1.4. This causes some problems:w()
andh()
may not equal todata_w()
anddata_h()
after callingscale()
, so onlydata_w()
anddata_h()
would be used when accessingdata()
directly.color_average
,copy
anddesaturate
will create new array and generate data from old array. Sodata_w()
anddata_h()
should be used in these functions. Butw()
andh()
are still used in these functions.The text was updated successfully, but these errors were encountered: