These methods are from old Photoshop scripts I made ~10 years ago, but they might be helpful. There are two functions, one to perform a eyedropper click on a x,y point to get the color and another to perform a magic wand click on a x,y point. For your example, you could eyedrop a point and if it returns black, you can magic wand the same point to make a selection of the area, then perform a fill on that selection.
function eyedropper(doc,x,y) {
// don't mess with spacing inside function, seesm to braek it
Stdlib = function() {};
Stdlib.selectBounds = function(doc, b, type, feather, antialias) {
doc.selection.select([[ b[0], b[1] ],
[ b[2], b[1] ],
[ b[2], b[3] ],
[ b[0], b[3] ]],
type, feather, antialias);
};
// getColorAt
// based on:
// fazstp@adobeforums.com wrote:
// news://adobeforums.com:119/3bb84060.0@webx.la2eafNXanI
//
// make new 1 pixel selection
x = Math.floor(x);
y = Math.floor(y);
Stdlib.selectBounds(doc, [x, y, x+1, y+1]);
try {
function findPV(h) {
for (var i = 0; i <= 255; i++ ) {
if (h[i]) { return i; }
}
return 0;
}
var pColour = new SolidColor();
pColour.rgb.red = findPV(doc.channels["Red"].histogram);
pColour.rgb.green = findPV(doc.channels["Green"].histogram);
pColour.rgb.blue = findPV(doc.channels["Blue"].histogram);
} finally {
doc.selection.deselect();
}
return pColour;
};
Also, here is my function for performing the magic wand:
function wand(x,y,tol,option)
{
// options:
// setd = initial selection
// AddT = add to selection
var id9466 = charIDToTypeID( option );
var desc1828 = new ActionDescriptor();
var id9467 = charIDToTypeID( "null" );
var ref1340 = new ActionReference();
var id9468 = charIDToTypeID( "Chnl" );
var id9469 = charIDToTypeID( "fsel" );
ref1340.putProperty( id9468, id9469 );
desc1828.putReference( id9467, ref1340 );
var id9470 = charIDToTypeID( "T " );
var desc1829 = new ActionDescriptor();
var id9471 = charIDToTypeID( "Hrzn" );
var id9472 = charIDToTypeID( "#Pxl" );
desc1829.putUnitDouble( id9471, id9472, x );
var id9473 = charIDToTypeID( "Vrtc" );
var id9474 = charIDToTypeID( "#Pxl" );
desc1829.putUnitDouble( id9473, id9474, y );
var id9475 = charIDToTypeID( "Pnt " );
desc1828.putObject( id9470, id9475, desc1829 );
var id9476 = charIDToTypeID( "Tlrn" );
desc1828.putInteger( id9476, tol );
var id9477 = charIDToTypeID( "AntA" );
desc1828.putBoolean( id9477, true );
executeAction( id9466, desc1828, DialogModes.NO );
};