Unlimited Point Samplers

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: Tom, Kukurykus

User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Unlimited Point Samplers

Post by Kukurykus »

If you want to use more than only up to 4 point samplers use this script as follows:

1) run script to set environment it will work in

2) make point sampler(s) and run script again

3) if you need to make more point samplers repeat 2nd point as many times you need

4) at end of 2nd point or instead of 3rd point select 'move tool' and run script once again


At the end of process 'Color Range' selection will be made basing on all point samplers there were made.
If you want to use other fuzziness value you have to change it manually in 97 line where it's set to 50.


Note: It's good practise to make workspace for using this script with some shortcut bound to,
as you have to run this script minimum 2 times durring one script session.

When you want to use it again in a nutshell you have to:

- run script, make point sampler(s)
- choose 'move tool' and run script
- or run script and make another point sampler(s) again and again
(to finally choose 'move tool' and run script, or run script and then choose 'move tool' to run script last time)


Like at every first time of another script session you have to initially run script to set environment,
so you have at the end of script session choose 'move tool' to give information to the script that you finished your job.


PS. this script works together with Adobe Bridge. it'll be opened to get information about data of document bitmap!

Code: Select all

BT = '(function BT(v1, v2) {bt = new BridgeTalk(), bt.target = v1, \
bt.body = v2, bt.onResult = function(v) {return res = v.body} bt.send(2)})'

function rw(v1, v2, v3) {
v2.open(v1), v1 < 'w' ? v3 = v2.read() : v2.write(v3), v2.close(); return v3
}

function sTT(v) {return stringIDToTypeID(v)} fle = File('~/Desktop/Log.txt')

function del() {
(ref1 = new ActionReference()).putEnumerated(
sTT('colorSampler'), sTT('ordinal'), sTT('allEnum'));
(dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1)
executeAction(sTT('delete'), dsc1, DialogModes.NO)
}

function log(v) {
(prf = preferences).useHistoryLog = false, fle.remove()
if (v) {
prf.saveLogItems = SaveLogItemsType.LOGFILE
prf.editLogItems = EditLogItemsType.DETAILED
prf .useHistoryLog = true, prf.saveLogItemsFile = fle
}
}

var len; if (dL = documents.length) len = (aD = activeDocument).colorSamplers.length

function CON() {
if (con = dL && !(/\.[^\.]+$/.test(String(aD.name)))
|| (preferences.rulerUnits != Units.PIXELS) || !fle.exists) {
alrt = 'To use this script ruler untis were changed to pixels.\n'
alrt +='Clear color samplers, make new ones and run script.\n'
alrt += 'Documents not existing as files won\'t be processed!'
preferences.rulerUnits = Units.PIXELS, log(true); if (len) del()/*, alert(alrt)*/
}
return con
}

if (!CON() && len && c = rw('r', fle).match(/[\d+,]{5,}(?= p)/g)) {
for(i in c) if (i < 8) c[i] = (c[i].replace(/,/, '.'))
for(str = '', i = 0; i <= (c.length) - 1; i += 2) {
str += ('[' + c[i] + ', ' + c[i + 1] + '], ')
}

if (!eval($.getenv('arr'))) $.setenv('arr', eval('"[' + str.slice(0, -2) + ']"'))
else {
ARR = eval($.getenv('arr')), ARR = uneval(ARR.concat(eval
(eval('"[' + str.slice(0, -2) + ']"')))), $.setenv('arr', ARR)
}

for(i = 0; i < (pnt = eval(eval('"[' + str.slice(0, -2) + ']"'))).length; i++) {
wh = pnt[i], w = wh[0], h = wh[1], aD.selection.select([[w - .5, h - .5],
[w + .5, h - .5], [w + .5, h + .5], [w - .5, h + .5]], SelectionType.EXTEND)
}

log(true), del()
}

if ((ref = new ActionReference()).putProperty(sTT('property'), sTT('tool')),
ref.putClass(sTT('application')), (typeIDToStringID(executeActionGet(ref)
.getEnumerationType(sTT('tool'))) == 'moveTool') && eval($.getenv('arr'))) {

dst = '"' + (aD = activeDocument).path
+ '/.jpg' + '"'; aD.duplicate(' ', true),
(jpg = new JPEGSaveOptions()).quality = 12,
(D = activeDocument).saveAs(F = File(eval(dst)), jpg)
D.close(), log()

ENV = (function ENV(v, v1, v2) {
for (arr = [], i = 0; i < v2.length; i++) {
arr.push("'" + new Color((new BitmapData
(new Thumbnail(File(v1)).spec, true))
.getPixel(v2[i][0] , v2[i][1])).toString().slice(3) + "'")
}

arr = '"' + arr + '"', colR = (function colR(v) {
function sTT(v) {return stringIDToTypeID(v)}; function cR(f, l0, a0, b0, l1, a1, b1) {
(dsc1 = new ActionDescriptor()).putInteger(sTT('fuzziness'), f)
for(i = 0, n = 2; i < (arr = ['minimum', 'maximum']).length; i++) {
ln = "(D = dsc" + n + " = new ActionDescriptor()).putDouble"
ln +="(sTT('luminance'), arguments[1 + p = l1 ? (i * 3) : 0])"
eval(ln), n++, eval("D.putDouble(sTT('a'), arguments[2 + p])")
eval("D.putDouble(sTT('b'), arguments[3 + p])")
dsc1.putObject(sTT(arr[i]), sTT('labColor'), D)
}
dsc1.putInteger(sTT('colorModel'), 0)
executeAction(sTT('colorRange'), dsc1, DialogModes.NO);
}
for(L = A = B = j = 0; j < (arr = eval('[' + v + ']')).length; j++) {
(col = new SolidColor).rgb.hexValue = arr[j]
L += col.lab.l, A += col.lab.a, B += col.lab.b
}
function div(v) {return v / j}; cR(50, div(L), div(A), div(B))
})
eval("(" + v + ")('photoshop', '(' + " + colR.toString() + " + ')' + '([' + arr + '])')" )
})

aD.selection.deselect(), eval(BT + "('bridge', '(' + " + ENV.toString() + " + ')' + \
'(' + BT + ', ' + dst + ', ' + $.getenv('arr') + ')')"), $.setenv('arr', null), F.remove()
}

else {log(true); if (len) del()}
Attachments
Point Samplers.rar
(1.99 KiB) Downloaded 685 times