Because screenshots of menus in Tahoe are even darker than before I added an option to my little png optimiser app.
The code for the level function in GraphicsMagicMBS is quite simple:
for currentImage as Integer = 0 to PngFilesToWork.LastIndex
Dim pic As Picture = Picture.Open(PngFilesToWork(currentImage))
dim mask as Picture = pic.CopyMask
If pic = Nil Then Continue
dim image as new GMImageMBS(pic)
image.level (0, 150.0)
dim newPic as Picture = image.CopyPicture
newPic.ApplyMask(mask)
newPic.Save(PngFilesToWork(currentImage), Picture.SaveAsPNG)
next
But as usual Apple makes things more complicated. By using the mask of the original screenshot I avoid having the result having black edges. But the edges are not 100% okay:
It gives you a perfectly cut out menu, which you can do anything you like with. It shouldn’t show any artefacts around the edge when processed. Run your code and try the Control version image?
It could. possibly, be caused if you are using a non-standard colour profile on the Mac. Perhaps try using “Colour LCD” and see if that makes a difference to the screenshot?
While it does give you the menu cutout correctly, I’ve found that on Sequoia it no longer includes the hover-item highlight. You must do cmd-shift-3 to get the whole screen to capture the highlight. Has that been fixed in Tahoe?
Well, I would recommend to read file directly into GMImageMBS without picture.
You can check on GMImageMBS, whether you have an alpha channel.
And check if matte property is true. Or type has on with alpha.
@Christian Schmitz: The screenshots usually have an alpha channel. But what do I do with this information? Should the level function work correctly on a picture with an alpha channel?
% LevelImage() adjusts the levels of an image by scaling the colors falling
% between specified white and black points to the full available quantum
% range. The parameters provided represent the black, mid (gamma), and white
% points. The black point specifies the darkest color in the image. Colors
% darker than the black point are set to zero. Mid point specifies a gamma
% correction to apply to the image. White point specifies the lightest color
% in the image. Colors brighter than the white point are set to the maximum
% quantum value.
%
% The format of the LevelImage method is:
%
% unsigned int LevelImage(Image *image,const char *level)
%
% A description of each parameter follows:
%
% o image: The image.
%
% o levels: Specify the levels as a string of the form "black/mid/white"
% (e.g. "10,1.0,65000) where black and white have the range of 0-MaxRGB,
% and mid has the range 0-10.
So it builds a color map and then applies it.
From the code, it seems like all includes opacity.
Thinking about it, this function may not do what you think it does. Your screenshot may just have wrong gamma value in the header. Or the color space makes the difference.
Gamma shouldn’t be brightening the dark areas. Yours looks like it has, which isn’t what I know as Gamma. Here’s a before and after from Photoshop.
Unfortunately, I don’t know how that translates to “what value to adjust in GraphicsMagick”. I do, however, get extremely readable results: levels-adjusted.png
(“Auto Levels” will get you most of the way there!)
Circling back around to this:
I think it’s important to determine why the original design is not loading the image directly into GMImageMBS. (Beatrix?) Since the problem seems to be the mask, I think if GMImageMBS has the original image to work with and no masks are applied later, the results could be usable.
I hadn’t seen the other constructor, that is all. The different constructor doesn’t change the result. I still think that the result of the levels function should keep the mask of the original picture.
My thought was that if you are using the alpha channel within GMImageMBS, you wouldn’t need the Mask procedure at all. You would be able to get a properly transparent image from GMImageMBS.