How do you make the background of a video or picture clear in Quartz Composer? - osx-leopard

I'd like to remove all of the black from a picture attached to a sprite so that it becomes transparent.

I'll copy and paste in case that link dies:
" I used a 'Color Matrix' patch, setting 'Alpha Vector (W)' and 'Bias Vector(X,Y,Z)' to 1 and all other to 0.
You will then find the alpha channel from the input image at the output."
I found this before, but I can't figure out exactly how to do it.
I found another solution using core image filter:
kernel vec4 darkToTransparent(sampler image)
{
vec4 color = sample(image, samplerCoord(image));
color.a = (color.r+color.g+color.b) > 0.005 ? 1.0:0.;
return color;
}

This looks like it'll do the trick:
http://www.quartzcompositions.com/phpBB2/viewtopic.php?t=281

Related

TintColor does not apply to my Complication when using rendering Mode "Template" (CLKComplicationTemplateGraphicCircularClosedGaugeImage)

I am currently trying to implement a
CLKComplicationTemplateGraphicCircularClosedGaugeImage
but for some reason my icon keeps getting tinted blue.
When I change the tintColor of the WatchFace everything seems to be tinted the right way. But when I disable tinting on the WatchFace my Image will be colored blue for some reason.
I enabled the rendering Mode: alwaystemplate inside the asset catalog because my image is just black in the original version and I tint it in other parts of my app.
let gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: color, fillFraction: progress)
let template = CLKComplicationTemplateGraphicCircularClosedGaugeImage(gaugeProvider: gaugeProvider, imageProvider: CLKFullColorImageProvider(fullColorImage: image))
I tried to apply a tintColor on the template and I also tried to apply a tintColor direclty to the image before passing it to the ImageProvider. Both Ideas doesnt result in the expected output.
let gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: color, fillFraction: progress)
let imageProvider = CLKFullColorImageProvider(fullColorImage: image)
let template = CLKComplicationTemplateGraphicCircularClosedGaugeImage(gaugeProvider: gaugeProvider, imageProvider: imageProvider)
template.tintColor = .white // this has no effect
How can I set a default tint color when using alwaysTemplate as the rendering mode?
I found a Solution by myself.
I am now tinting the Image white and also rerendering it as a originalImage.
let imageProvider = CLKFullColorImageProvider(fullColorImage: image.withTintColor(.white, renderingMode: .alwaysTemplate).withRenderingMode(.alwaysOriginal))

QML Canvas/Context2D fillText() unexpected behaviour

I am trying to code a text editor from scratch in C++ using Qt/QML. For drawing the text I use a Canvas with a Context2D , which looks roughly like this:
function drawString(text, x, y, font) {
var ctx = getContext("2d");
ctx.font = font;
ctx.fillStyle = "black";
ctx.fillText(qsTr(text), x, y);
ctx.stroke();
}
In order to graphically represent a selected area, I want to invert the selecion, for instance place a black rectangle over an area and make the text white.
For this I will use ctx.globalCompositeOperation = "xor"
So the problem I ran into is: when I draw a text with the function above in black, and then afterwards paint the same text in the same location in white I would expect this canvas to be white again. Instead there is still some kind of outline of the text visible (like there is a shadow).
I already tried switching off all shadow parameters but it didn't solve my problem.
Here is a screenshot so you get a better idea of what it looks like:
Nevermind, I found the problem myself. The antialiasing property was set to true, which caused the effect. By setting it to false the text doesn't look as pretty but the shadow is gone.

GTK+ caret-color CSS property in Evince

Using a dark theme, the caret in Evince (press F7 to get to caret mode) is a very light colour and therefore doesn't show up well against the usual white background of a document.
I'd like to fix this, and I was going to hack a theme to do it, but on digging, it seems evince is using a deprecated property: cursor-color (at ev-view.c:4260):
gtk_style_context_get_style (context,
"cursor-color",
&style_color,
NULL);
The fallback is:
gtk_style_context_save (context);
gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
gtk_style_context_restore (context);
The deprecation was done here. So I want to try to update evince to use the CSS property, and then update my theme to set this for EvView objects to apply it to evince's main document view:
I set the following CSS in ~/.config/gtk-3.0/gtk.css as a test:
* {
caret-color: rgba(0,255,0,1.0);
}
This does work for gedit, for example - the caret in the main editor and the dialogs are all green.
I then tried to read this out, using similar logic to the used internally by GTK for the caret colour (c.f. gtk/gtkstylecontext.c # 9b86d6da2)
gtk_style_context_get (context,
gtk_style_context_get_state (context),
"caret-color", color,
NULL);
However, this doesn't work and my colour is transparent black, not opaque green as expected. However, the call to gtk_style_context_get() is actually setting the colour to transparent black, not just leaving it alone.
Using just GTK_STATE_FLAG_NORMAL instead of gtk_style_context_get_state (context) as the fallback used to doesn't work either.
What is the correct way to read this property such that I can set it in my theme and have it picked up?
To obtain the caret color, you should do something like:
GdkRGBA *caret_color;
gtk_style_context_get (context,
gtk_style_context_get_state (context),
"caret-color",
&caret_color,
NULL);
Later in the code, in Evince you had:
if (style_color) {
color->red = style_color->red / 65535.0;
color->green = style_color->green / 65535.0;
color->blue = style_color->blue / 65535.0;
color->alpha = 1;
Where the color values were converted from GdkColor to GdkRGBA. That conversion is not needed once you obtain "caret-color", and I guess that may have changed the color as you expected.

Programmatically fading in an image in PlayN

I'm working on a game using PlayN, and there's a bit where I would like to take an image (which is currently in PNG format, with 8-bit alpha already) and I would like to multiply the image by an additional alpha factor, based on a value from my code.
Specifically, I have a picture of a face that currently lives in an ImageLayer, and the effect that I would like would be to have something like this:
void init() {
faceImage = assetManager().getImage("images/face.png");
graphics().rootLayer().add(faceImage);
}
void update(float deltaMilliseconds) {
// start at fully transparent, fade to fully opaque
float transparency = calcTransparency(deltaMilliseconds);
faceImage.setTransparency(transparency);
}
I expect that there's some way to do some trickiness with GroupLayers and blend modes, perhaps blending the image with a CanvasLayer painted with a solid white rectangle with transparency controlled by my code, but it's not obvious to me if that's the best way to achieve what seems like a pretty common effect.
If you just want to fade the image in from fully-transparent to fully-opaque, then just do the following:
ImageLayer faceLayer;
void init() {
Image faceImage = assetManager().getImage("images/face.png");
faceLayer = graphics().createImageLayer(faceImage);
graphics().rootLayer().add(faceLayer);
}
void update(float delta) {
float alpha = calcAlpha(delta);
faceLayer.setAlpha(alpha);
}
Where alpha ranges from 0 (fully transparent) to 1 (fully opaque).

Photoshop PhotoFilter pixel Math

Has anyone used the photo filter in Photoshop? Edit > Adjustments > Photo Filter...
It produces a really nice image tint that I've been unable to reproduce with blending modes. Has anyone got any idea of the pixel maths behind this filter? - So I can build a shader based on it.
It seems to basically be a luminosity preserving colour tint.
Has variables: Color, Amount and Preserve Luminosity.
Any ideas?
Filters (in light) are multiplicative, as in:
red_filter = ( 1 , 0 , 0 ) * color
I don't think any blend-modes exist for it, since any transparent overlay with that system would darken the image to some degree.
It's incredibly simple, but if anyone wants the hlsl code for this:
// Photoshop PhotoFilter style effect.
// Input filter color.
float4 FilterColor;
// Implicit texture sampler.
sampler TextureSampler : register(s0);
float4 PhotoFilter(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
return tex2D(TextureSampler, texCoord) * FilterColor;
}
technique GeneralEffect
{
pass Pass1
{
PixelShader = compile ps_2_0 PhotoFilter();
}
}

Resources