-
Notifications
You must be signed in to change notification settings - Fork 0
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
Extract remaining image specific meta data into additional AbstractImageProviderWrapper #171
Comments
Some results on the further analysis of the Image class. There are currently the following types of images:
I would group them up into: Dynamic Images (1 & 3):All OS handles with those images could be created only on demand -> reduce number of handles. As the bounds (in points) of the image is needed in some places, those values could be calculated on creation time with a temporary handle, that is disposed afterwards. Currently one persistent handle is created is retained. Static Images (4 -8):For each Static image the OS handle is created in the constructor Images with concrete sizeCommon use case of those images is using them together with a GC, like
As the drawing will be done on the OS bitmap in the end, this bitmap must be initialized with a concrete size in pixels. The zoom to identify the scale factor from points to pixels is currently DPIUtil.getNativeDeviceZoom(). An additional constructor with the desired target zoom is necessary to have a support for multi-zoom scenario. #143 is designed so most of the usages of this constructor into Dynamic Images with ImageDrawingProvider. Tasks regarding this kinds of images Image with ImageDataThere are two kinds of constructors: only with ImageData or with ImageData source + ImageData mask. These Images will intialize an OS handle with the passed data. As ImageData is always in pixels an assumption about how the ImageData was created must be done. The existing implementation assumes the passed ImageData is created for a zoom of 100. This data will be scaled to target zoom (again DPIUtil.getNativeDeviceZoom()) and then used for the initialization of the handle. This whole process be adaptable to a dynamic approach by wrapping it into an ImageDataProvider -> Assumption about ImageData being passed at zoom of 100 will still hold here. This will always lead to destructive scaling! Tasks regarding this kinds of images
Image with InputStreamThe Image will intialize an OS handle with the passed stream as image data. As the passed data is always in pixels an assumption about how the data was created must be done. The existing implementation assumes the passed datais created for a zoom of 100. This data will be scaled to target zoom (again DPIUtil.getNativeDeviceZoom()) and then used for the initialization of the handle. Tasks regarding this kinds of images
Image with file nameThe Image will intialize an OS handle with the passed filename loaded as image data. As the passed data is always in pixels an assumption about how the data was created must be done. The existing implementation assumes the passed datais created for a zoom of 100. This data will be scaled to target zoom (again DPIUtil.getNativeDeviceZoom()) and then used for the initialization of the handle. Image with other ImageThis will copy the specified Image or an adapted (e.g. greyed) variant of the Images and will inherit the attributes of the passed Image. I don't see any changes necessary here. ConclusionBest scenario would be to get rid of all Static Images if possible and provide simple ways to translate them into Dynamic Images Steps to do
|
The analysis appears overall sound to me. I completely agree with the conclusion that static images should, as far as possible, be replaced by dynamic ones. This is also a good chance of getting rid of outdated constructors and the API up to only provide reasonable, dynamic way of creating images. When deprecating constructors, we should provide examples for how to replace their usage with proper, dynamic ways of creating the according image. So far, we completely agree. Taking a look at the analysis and the image implementation again, I got a slightly extended / different understanding of the overall issue. I try to summarize the questions arising for me and a provide a concrete proposal (not deeply thought through) in the following. Central Question(s)But I have one central comprehension question: is the problem really about dynamic vs. static images? So isn't the issue rather about the necessity to modify (or create) an image than about whether it is static or dynamic? Given that, I would expect most (if not all) images that will be modified to be created explicitly, i.e., via a constructor only taking a size, which is the scenario that #143 addresses, if I am not mistaken. So for me the first question to answer is: given an image, what zoom can or should I expect it to conform to? Should that be the same for every image? Should it be the ProposalAs a completely new idea: what if we stick to the current behavior of initializing every image with some zoom and provide some method to change the zoom of that image. This would mean that a dynamic image would replace its "default" data with the one conforming to the zoom to change to (which could then be overwritten with a GC, even though that is not recommended) and a static image would be scaled (just like the constructor does now). We could then even say that with monitor-specific scaling enabled (where is nothing like a As an example: Image selfPaintedImage = new Image(device, 16, 16); // will be 16x16, no matter what native zoom we currently have
selfPaintedImage.changeZoom(getZoom()); // adapts the image to the zoom of the current context, e.g., a control
GC gc = new GC(selfPaintedImage);
// ... do some painting
gc.dispose(); Additional QuestionsI have few questions:
|
Additional note from today's discussion: we should log an error or at least a warning when creating a GC on any image that is not supposed to be used for modifying it. This includes at least:
|
I created sub-tickets out of the discussion here:
This ticket will be used for its original task to extract one or more additional AbstractImageProviderWrapper subclass for the non-dynamic image cases |
As ImageDataProvider and ImageFileNameProvider details were refactored into internal sub classes already, attributes that are only used for the "standard case" remain in the Image class. Those should be extracted into a third AbstractImageProviderWrapper.
Some usages of package protected attributes in other parts of SWT must be evaluated and probably adapted in the same step to make this possible
The text was updated successfully, but these errors were encountered: