Glow and Glow Highlights - RealWorld forums

Log-in or register.

Glow and Glow Highlights

PAEz
on October 28th 2013

Glow

Code
Configuration

Configuration.AddEditBox("blurRadius", "Blur Radius", "Blur Radius - decimal values are allowed", 5);
Configuration.AddEditBox("amount", "Amount", "Percentage of blurred pixel to add to source (really should be between 0 and 1)", 0.5);

Execution

var blurRadius = Configuration.blurRadius;
var amount = Configuration.amount;

var image = Document.RasterImage;
var clone = Document.Duplicate();
clone = clone.RasterImage;

var blur = Operation.Create("Raster Image - Blur");
blur.Type = 0;
blur.Radius = blurRadius;
Operation.Execute(blur, clone);

var w = image.sizeX;
var h = image.sizeY;
var c,r,g,b,a,x,y;
var cS, sR, sB, sG, sA;
var cB, bR, bB, bG;

for (x=0; x<w; x++){
for (y=0; y<h; y++){

cS = image.GetPixel(x,y,0,0);

sB = cS & 255;
sG = cS >> 8 & 255;
sR = cS >> 16 & 255;
sA = cS >> 24 & 255;

cB = clone.GetPixel(x,y,0,0);

bB = cB & 255;
bG = cB >> 8 & 255;
bR = cB >> 16 & 255;
bA = cB >> 24 & 255;

if ((sR += amount * bR) > 255) sR = 255;
if ((sG += amount * bG) > 255) sG = 255;
if ((sB += amount * bB) > 255) sB = 255;

r = sR;
g = sG;
b = sB;
a = sA;

if (r < 0) r = 0; if (r > 255) r = 255;
if (g < 0) g = 0; if (g > 255) g = 255;
if (b < 0) b = 0; if (b > 255) b = 255;

c=(a << 24) |
  (r << 16) |
  (g <<  8) |
   b;

image.SetPixel(x, y, 0, 0, c);

}
}

Source
Pixtastic
http://www.pixastic.com/
http://www.pixastic.com/lib/git/pixastic/actions/glow.js

Notes
I really wasnt sure what he was doing with the blur image, but looking around it seemed a Glow is just a blurred copy Add mixed with the original by a percentage, so thats what I tried to do....looks right to me ;-)

PAEz
on October 29th 2013

Glow Highlights
for the lack of a better name

Code
Configuration

Configuration.AddEditBox("blurRadius", "Blur Radius", "Blur Radius - decimal values are allowed", 30);
Configuration.AddEditBox("lightnessMinimum", "Minimum Lightness", "The minimum lightness of pixels to use", 0.55);
Configuration.AddEditBox("amount", "Mix Amount", "Percentage of blurred pixel to add to source (really should be between 0 and 1)", 0.5);
var options = ["RGB","Lightness"];
Configuration.Add1ofNPicker("mixType", "Mix Type", "Whether to mix colours or just the lightnes", options, 0);

Execution

var minimumL = Configuration.lightnessMinimum;
var blurRadius = Configuration.blurRadius;
var amount = Configuration.amount;
var steps = 3;

var c,r,g,b,a,x,y;
var cS, sR, sB, sG, sA;
var cB, bR, bB, bG;

var image = Document.RasterImage;
var w = image.sizeX;
var h = image.sizeY;

var clone;
clone = Document.Duplicate();
clone = clone.RasterImage;
// Remove any pixel thats under the Lightness Threshhold and then blur
for (x=0; x<w; x++){
for (y=0; y<h; y++){
cL = clone.GetPixelL(x, y, 0, 0);
if(cL<minimumL)clone.SetPixel(x, y, 0, 0, 0);
}}
var blur = Operation.Create("Raster Image - Blur");
blur.Type = 0;
blur.Radius = blurRadius;
Operation.Execute(blur, clone);

var mixType = Configuration.mixType;

for (x=0; x<w; x++){
for (y=0; y<h; y++){

if (mixType==1){
var cL, cH, cS, sL, oSL;

cH = image.GetPixelH(x, y, 0, 0);
cS = image.GetPixelS(x, y, 0, 0);
cL = clone.GetPixelL(x, y, 0, 0);
bA = clone.GetPixelAlpha(x, y, 0, 0);

oSL = sL = image.GetPixelL(x, y, 0, 0);

if ((sL += ( (amount * cL)*(bA/255) )) > 1) sL = 1;
image.SetPixelHLS(x, y, 0, 0, cH, sL, cS);

} else {

cS = image.GetPixel(x,y,0,0);

sB = cS & 255;
sG = cS >> 8 & 255;
sR = cS >> 16 & 255;
sA = cS >> 24 & 255;

cB = clone.GetPixel(x,y,0,0);

bB = cB & 255;
bG = cB >> 8 & 255;
bR = cB >> 16 & 255;
bA = cB >> 24 & 255;

oSL = sL = image.GetPixelL(x, y, 0, 0);
//if (bA>0){
if ((sR += (amount * bR)*(bA/255)) > 255) sR = 255;
if ((sG += (amount * bG)*(bA/255)) > 255) sG = 255;
if ((sB += (amount * bB)*(bA/255)) > 255) sB = 255;
//}
r = sR;
g = sG;
b = sB;
a = sA;

if (r < 0) r = 0; if (r > 255) r = 255;
if (g < 0) g = 0; if (g > 255) g = 255;
if (b < 0) b = 0; if (b > 255) b = 255;

c=(a << 24) |
  (r << 16) |
  (g <<  8) |
   b;

image.SetPixel(x, y, 0, 0, c);
}

}
}

Notes
I wanted to be able to glow/bloom only the highlight areas.
Using a setting of .75 for Minimum Lightness does that and .50 or .55 for a more general glow.
Couldnt find the exact code I wanted so just did what I thought would work ;-)....once again, looks good to me ;P

Page views: 1029       Posts: 2      
I wish there were...
Vista & Win 7 icons
What about ICL files?