It is currently December 11th, 2018, 8:02 am

Mask Image

Changes made during the Rainmeter 3.2 beta cycle.
User avatar
jsmorley
Developer
Posts: 18445
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Mask Image

jsmorley » August 22nd, 2014, 12:32 am

We are happy to announce a new D2D Image Masking feature for the Image Meter.

The documentation is at Image Meter - Mask Image.

What this will allow you to do is to define a MaskImageName on the meter, and then the primary image, defined as normal by ImageName or the value of MeasureName, will be "masked" into the image defined by MaskImageName, preserving any transparency in MaskImageName.

The end result is that you can mask an image into a "shape". The sample below will demonstrate.

Let's use three images for now:

This will be our primary image
Abbey.jpg
This is an image we will use as a "mask"
Circle.png
And another image to use as a "mask"
Apple.png

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

;Abbey.jpg is 300 X 300
;Circle.png is 300 X 300
;Apple.png is 491 X 480

[MeterMaskedImage]
Meter=Image
W=250
ImagePath=#@#Images\
MaskImagePath=#@#Masks\
ImageName=Abbey.jpg
MaskImageName=Apple.png

[MeterSize]
Meter=String
Y=5R
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=W: [MeterMaskedImage:W] | H: [MeterMaskedImage:H]
DynamicVariables=1
The result with no MaskImageName
01.png
The result with MaskImageName=Circle.png
02.png
The result with MaskImageName=Apple.png
03.png
Things to remember:

MaskImageName

Mask Image is only supported on systems using D2D. This means that it will not work on Windows XP or when D2D is turned off in the Rainmeter settings.

While all image formats are supported for MaskImageName, it is entirely pointless to use any formats except .png or .gif, as the idea is to get a "shape", which requires that some areas of the mask image be transparent or partially transparent.

MaskImagePath can be used to define the path where images specified with MaskImageName can be found. For instance MaskImagePath=#@#Masks\. Alternatively, you can just specify a full or relative path when setting MaskImageName.

Sizing

When MaskImageName is defined, then W and H define the size of the mask image, and the resulting size of the meter. If you define both W and H, then the mask image will be sized to those specific dimensions. If you define only W or H, then the mask image will be sized to the dimension you define, while automatically preserving the aspect ratio. If neither W or H is defined, the size of the mask will be the original image size.

The ImageName defined, either specifically or by binding the meter to a measure with MeasureName, will be sized to fit in the mask image. It will "fill" the image by sizing and cropping as needed, similar to the PreserveAspectRatio=2 setting on a normal image meter.

The result is that if only one of W or H is specified, the code automatically "fits" the mask image while preserving the aspect ratio. It always automatically "fills" the primary image while preserving the aspect ratio. Any PreserveAspectRatio set on the meter is ignored.

While just like with PreserveApectRatio=2 there is no control over the "origin" when the ImageName image is cropped to fit in the MaskImageName image, some control over what part of the image is used when masked can be had by creating a mask image with transparent areas of any size on the left, right, top or bottom as desired. This in effect will allow for some control over what part of the image is "displayed" when the image is sized and cropped to fit the mask. The size of the meter itself will be the full size of the mask image of course, as defined by W and / or H.

So in a sense W and H are used to size both images. Then the ImageName image is masked onto the MaskImageName image, only displaying in non-transparent areas of MaskImageName.

Transparency

If either the primary image or the mask image has areas of transparency or partial transparency, those "alpha channel" values are applied to the final image. When both images have a shared area with full or partial transparency, the "most transparent" value is applied.

Transformations

The mask image can be rotated or flipped, using MaskImageRotate and MaskImageFlip. These work the same as their ImageRotate / ImageFlip counterparts, only they operate on the mask image instead of the primary image.

It should be said though, that transformations with ImageRotate / MaskImageRotate are going to be tricky to get right, given that the W and H of the meter is defined by the non-rotated images, and then the images are rotated inside that existing "container". It is easy to have undesirable clipping of the final image if any rotation causes the primary image to no longer fit the mask image, or the mask image to no longer fit the meter.

While admittedly complex, TransformationMatrix is probably a better approach for manipulating the rotation, skew, etc. of the entire final image. With TransformationMatrix, the entire meter is transformed rather than the image being transformed "inside" the original meter size and shape. As with any use of TransformationMatrix, care should be taken that the meter still fits in the boundaries of the skin when transformed.

Other image transformations, like ScaleMargins and Tile, are not supported at all on the meter if MaskImageName is defined.

Other notes

The Mask Image functionality cannot be used with an Image meter that is drawing a square or rectangle using only SolidColor, and no ImageName. Setting W and H and SolidColor actually only "colors" the meter container itself, and no actual "image" is ever created.
You do not have the required permissions to view the files attached to this post.
User avatar
Dank420
Posts: 147
Joined: April 3rd, 2013, 1:04 am
Location: O-High-O

Re: Image Masking

Dank420 » August 22nd, 2014, 1:09 am


Great job Rainmeter team!!!
Last edited by Dank420 on August 22nd, 2014, 1:10 am, edited 1 time in total.
User avatar
VasTex
Posts: 408
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana

Re: Image Masking

VasTex » August 22nd, 2014, 1:10 am

This looks very useful. I remember it being discussed in a thread not too long ago actually. Should go well with those Media Player skins people are so fond of and I've a few ideas myself for this.

Nice work guys, impressive as usual.
01010100 01100101 01100011 01101000 01101110 01101111 01101100 01101111 01100111 01101001
01100011 01100001 01101100 00100000 01000010 01100001 01100100 01100001 01110011 01110011
User avatar
jsmorley
Developer
Posts: 18445
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Image Masking

jsmorley » August 22nd, 2014, 1:12 am

VasTex wrote:This looks very useful. I remember it being discussed in a thread not too long ago actually. Should go well with those Media Player skins people are so fond of and I've a few ideas myself for this.

Nice work guys, impressive as usual.
Thanks. I can see it being particularly useful with media players and "album art".
User avatar
VasTex
Posts: 408
Joined: September 20th, 2012, 3:17 pm
Location: USA - Montana

Re: Image Masking

VasTex » August 22nd, 2014, 1:13 am

Exactly my thoughts. May go well with some Icon-Based application launchers as well...

Will have to play with it some when I get a chance.
01010100 01100101 01100011 01101000 01101110 01101111 01101100 01101111 01100111 01101001
01100011 01100001 01101100 00100000 01000010 01100001 01100100 01100001 01110011 01110011
User avatar
Dank420
Posts: 147
Joined: April 3rd, 2013, 1:04 am
Location: O-High-O

Re: Image Masking

Dank420 » August 22nd, 2014, 1:47 am

...makes me happy...oh, the places/ways to use it!!!!!
You do not have the required permissions to view the files attached to this post.
User avatar
killall-q
Posts: 285
Joined: August 14th, 2009, 8:04 am

Re: Image Masking

killall-q » August 22nd, 2014, 1:56 am

You've opened Pandora's box, now Rainmeter will only be used for making heart-shaped picture slideshows.

Where in the order of image transformations does masking fall under?
User avatar
Dank420
Posts: 147
Joined: April 3rd, 2013, 1:04 am
Location: O-High-O

Re: Image Masking

Dank420 » August 22nd, 2014, 2:18 am

i was thinking tie emotions to weather..... or tech-ier borders( i assume all the jarvas and ironman suits will be getting a Tuneup/upgrade.... good question thou on where it falls...
You do not have the required permissions to view the files attached to this post.
User avatar
Brian
Developer
Posts: 1793
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Image Masking

Brian » August 22nd, 2014, 3:51 am

killall-q wrote:Where in the order of image transformations does masking fall under?
The image is masked at draw time.



There are a couple things that jsmorley didn't talk about:
  1. This option is only for D2D rendering. Sorry XP and GDI+ folks.
  2. Certain image options like ScaleMargins and Tile are not supported.
  3. PerserveAspectRatio has no effect on the MaskImageName, although the ImageName is drawn as if PerserveAspectRatio=2 was used as jsmorley pointed out. This choice was made because there are too many ways in which the ImageName would not "fit" in the space of the mask.
-Brian
User avatar
fonpaolo
Moderator
Posts: 1351
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: Image Masking

fonpaolo » August 22nd, 2014, 8:19 am

Hooray!!! :great: :D
A great addition, however I'll have to wait until the next official release.