Lighten menu screenshots with GraphicsMagicMBS level

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:

I still get some darker pixels around the corners which looks like smudging. Any idea how to improve this?

Run your app and try this:

  • Open a menu
  • Press Control-Shift-4
  • press space bar
  • Hold Control and then click on the menu.

Without control you get this (with the shadow out side of the menu):

With Control pressed you get this (without the shadow outside of the menu):

Sometimes menus change when you press Option or Command. You can press those along with Control to get those menu variants too.

What does this have to do with the background color of the screenshots?

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?

I always do the screenshots without shadows. And this does show the artifacts at the outer edges.

I had a look in Affinity Photo at the screenshot and the result:

The original:

There is some lighter grey visible around the edges.

Level adjustment in Affinity Photo:

This looks correct.

Level adjustment with the MBS plugin:

The outer edge now looks darker because it’s next to the white. I can play around with the mask of the original image.

@Tim Parnell: if you tell me what a “hover-item highlight” is then I can check it.

Pretty sure he means the (normally) blue effect when you are pointing at a menu item.

That looks like the MBS function is doing a poor job of brightening the image. Affinity Photo didn’t suffer the same issue.

That’s probably to do with the masking stuff. I had issues like that when a small setting in Affinity Photo was pallatizing my icons during export.

Is GMImageMBS not opening the image with transparency?

Also, I stand corrected, it’s finally fixed in 15.6!

The problem seems to be the mask. The level function doesn’t account for the mask.

@Christian_Schmitz : is this a bug or a feature? This is the direct result of the level function:

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?

I am not sure. From documentation:

%  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 is what I would have used in Photoshop to address this issue.

Yes, I know what this function does. Gamma is not what I want:

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.

Gamma seems to be losing the contrast of the text on the menu. I would tweak white & back points, which can be done in Preview.app with these sliders:

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.

It’s a good idea to combine levels and gamma.

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.

Having a senior moment. How would I do that?

@Christian_Schmitz said to avoid using Picture, so my guess from the docs is the GMImageMBS.write(f as FolderItem) function.