I would like to do some standard color transformation on a Loader object (Which is used to display a picture) like Sepia, Black & White etc...
I'm currently using methods like this one :
var colorTransformer:ColorTransform = selectedItm.transform.colorTransform;
colorTransformer.redMultiplier = 1/6;
colorTransformer.greenMultiplier = 1/5;
colorTransformer.blueMultiplier = 1/3;
selectedItm.transform.colorTransform = colorTransformer;
But I dont know how obtain a Sepia or a Black and White effect. Is there a function to do this ? If not is there some kind of database which contains "multiplier" to obtains effect ?
You'll have to explore to fine tune a sepia filter:
var sepia = new flash.filters.ColorMatrixFilter();
sepia.matrix = [0.3930000066757202, 0.7689999938011169,
0.1889999955892563, 0, 0, 0.3490000069141388,
0.6859999895095825, 0.1679999977350235, 0, 0,
0.2720000147819519, 0.5339999794960022,
0.1309999972581863, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
Online color transform generators can help for real time tuning:
Online matrix generator:
http://www.onebyonedesign.com/flash/matrixGenerator/
Related
Is it possible to set value of alpha channel when providing fill and stroke colors in PDFlib?
$p->setlinewidth(20);
$p->setcolor('fill', 'rgb', 1, 0, 0, null);
$p->setcolor('stroke', 'rgb', 0, 1, 0, null);
$p->rect(0, 0, 100, 100);
$p->fill_stroke();
Is it possible to make rectangle's red fill and thick green border to be semi-transparent?
Is it possible to make rectangle's red fill and thick green border to be semi-transparent?
sure, please use GState for this task. You find a complete sample code within the PDFlib cookbook: Transparent Graphics
/* Save the current graphics state. The save/restore of the current
* state is not necessarily required, but it will help you get back to
* a graphics state without any transparency.
*/
$gstate = $p->create_gstate("opacityfill=.5 opacitystroke=.5");
$p->save();
$p->set_gstate($gstate);
$p->setlinewidth(20);
$p->setcolor('fill', 'rgb', 1, 0, 0, null);
$p->setcolor('stroke', 'rgb', 0, 1, 0, null);
$p->rect(0, 0, 100, 100);
$p->fill_stroke();
$p->restore();
For a powerful path generation, you might use the Path object. See PDFlib 9.2 Documentation as well the samples within PDFlib Cookbook - path objects.
page.drawText(WATERMARK.LABEL, {
x: 180,
y: 400,
size: 30,
font: helveticaFont,
color: rgb(220 / 255, 220 / 255, 220 / 255),
rotate: degrees(-315),
opacity: 0.6
})
// add opacity field only
After adding intersection box for sectional viewing of model using sectional analysis tool, is it possible to get its bounding box information?
original model
intersect box view whose bounding box needs to be extracted
You can access the geometry info of the section box via sectionExtension.tool:
const sb = viewer.getExtension('Autodesk.Section')
sb.tool.getSectionBoxValues()
//sectionBox: (6) [-2.8294310569763184, -6.648449420928955, -9.332106590270996, -0.0652092695236206, -1.3873761892318726, -3.4865833520889282]
//sectionBoxTransform: (16) [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
I have a B/W picture and I need to make some adjustments to it - I need to increase it's 'visibility' (it is too gray, I need to make it darker). Does anybody know how to reproduce Photoshop's brightness adjust in AS3? Please note that this is NOT the same as adjusting the brightness in Flash. The difference is:
in PS: brightness adjusts only the pixels that have a color different to white. It does not do anything to white pixels, so white pixels actually stay white
in PS: lightness adjusts all the pixels, so it affects the white pixels as well. Bringing lightness down makes all the image darker; this is unusable for me and this is exactly what Flash does as well (although it is called 'brightness' there)
I could reproduce Flash's brightness with this matrix:
var m:Array = new Array();
m = m.concat([1, 0, 0, 0, value]); // red
m = m.concat([0, 1, 0, 0, value]); // green
m = m.concat([0, 0, 1, 0, value]); // blue
m = m.concat([0, 0, 0, 1, 0]); // alpha
new ColorMatrixFilter(m);
...however this is exactly what doesn't work well as it sets all the image darker, including the white parts.
Any ideas how to reproduce PS's brigthness setting? Or any other matrix that actually keeps white/light pixels light while darkening the darker ones? Thank you!
I doubt this replicates Photoshop's "brightness" exactly (it's more like adjusting the contrast), but you could try scaling the RGB values, then adjusting them so that whites remain white:
var scaling:Number = 4;
var adjustment:Number = 255 * (1 - scaling);
var m:Array = new Array();
m = m.concat([scaling, 0, 0, 0, adjustment]); // red
m = m.concat([0, scaling, 0, 0, adjustment]); // green
m = m.concat([0, 0, scaling, 0, adjustment]); // blue
m = m.concat([0, 0, 0, 1, 0]); // alpha
new ColorMatrixFilter(m);
If you wanted a more traditional contrast, the adjustment would be:
var value:Number = 255 * (1 - scaling) * 0.5;
Is there an easy way to grey out a sprite? I'm disabling a button, and I know how to do that, but wants to convey that in the GUI.
You can apply the ColorMatrixFilter to your Sprite with the approximate values that makes color greyscaled.
sprite.filters = [ new ColorMatrixFilter([0.3086, 0.6094, 0.0820, 0, 0, 0.3086, 0.6094, 0.0820, 0, 0, 0.3086, 0.6094, 0.0820, 0, 0, 0, 0, 0, 1, 0]) ];
I'm drawing stuff on a bitmapData and I need to continuously fade every pixel to 0x808080 while still drawing (its for a DisplacementMapFilter)...
I think this illustrates my problem:
http://www.ventdaval.com/lab/grey.swf
The simpler approach I tried was drawing a semi-transparent grey box on it, but it never reaches a single color (i.e. 0x808081 will never be turned to 0x808080)... The same kind of thing happens with a ColorMatrixFilter trying to progressively reduce the saturation and/or contrast. (the example above is applying a filter with -10 contrast every frame).
I'm trying paletteMap now, and I'm sensing this could be the way to go, but I haven't been able to get it... any ideas?
You can try to fade it slightly more than you are fading it now, so color will go to 0x808080, you just need to do some calculations.
Yes, you can do this with paletteMap.
The third way will be to write PixelBender shader for it.
You can also use your normal fading and do paletteMap or PixelBender one once in a few frames, to speed-up all this.
I think the easiest way to do this would be with two successive color filters. That is:
var n:Number = 0.9;
var off:Number = 0x80;
var filter:ColorMatrixFilter = new ColorMatrixFilter( [
1, 0, 0, 0, -off,
0, 1, 0, 0, -off,
0, 0, 1, 0, -off,
0, 0, 0, 1, -off ] );
var filter2:ColorMatrixFilter = new ColorMatrixFilter( [
n, 0, 0, 0, off,
0, n, 0, 0, off,
0, 0, n, 0, off,
0, 0, 0, n, off ] );
function onFrame( e:Event ) {
myBMD.applyFilter( myBMD, myBMD.rect, new Point(), filter );
myBMD.applyFilter( myBMD, myBMD.rect, new Point(), filter2 );
}
The first filter offsets each channel value downwards by 128 - turning your gray-based image into a black-based image. The second filter multiplies each channel value by the modulator (0.9 in my example), and then offsets the values back up by 128.
I wound up solving this by filling the texture with 0xFF808080 every frame, then drawing my dynamic stuff to a second, transparent bitmap, doing a colortransform on it with a lower alpha multiplier (say 0.98), and then copypixeling that bitmap to the main bitmap with mergealpha on. Works a treat:
public function update():void
{
lock();
fillRect(rect, 0xFF808080);
drawTarget.lock();
drawTarget.colorTransform(rect, fadeTransform);
drawTarget.applyFilter(drawTarget, rect, pt, blurFilter);
drawTarget.unlock();
copyPixels(drawTarget, rect, pt, null, null, true);
unlock();
}