Color Lookup

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

undavide

Color Lookup

Post by undavide »

Have you ever noticed that you can't ask a Color Lookup adjustment layer (CS6 only) which kind it is?
There are supported kinds ranging from LayerKind.BLACKANDWHITE to LayerKind.VIDEO (in alphabetic order), yet if you try:

Code: Select all$.writeln(app.activeDocument.activeLayer.kind)

on a Color Lookup adjustment layer it gives you an internal error. Weird.

Davide

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Color Lookup

Post by Mike Hale »

Yes, in another thread Paul pointed out that you can't get it with Action Manager either. I don't have CS6 but I wonder if you could tell by looking at the raw adjustment data.
undavide

Color Lookup

Post by undavide »

Mike,
as far as I can tell (and with the invaluable help of Jacob ), with action manager you can do it.

Code: Select allvar isColorLookup = function() {
    var selected_layer_ref = new ActionReference();
    selected_layer_ref.putEnumerated(app.stringIDToTypeID('contentLayer'), app.stringIDToTypeID('ordinal'), app.stringIDToTypeID('targetEnum'));
    var adjustment_type = adjustmentTypeForLayerRef(selected_layer_ref);
    if (app.typeIDToStringID(adjustment_type) == "colorLookup") {
        return true;
    }
    else {
        return false;
    }
}

var adjustmentTypeForLayerRef = function(layer_ref) {
    var layer_desc;
    var adjustment_list;

    try {
        layer_desc = app.executeActionGet(layer_ref);
    } catch(error) {
        $.writeln("Error: " + error.message);
        return;
    }

    if (!layer_desc.hasKey(app.stringIDToTypeID('adjustment'))) {
        return;
    }
    adjustment_list = layer_desc.getList(app.stringIDToTypeID('adjustment'));
    if (adjustment_list.count == 0) {
        return;
    }
    return adjustment_list.getObjectType(0);
}

isColorLookup();

Davide
Paul MR

Color Lookup

Post by Paul MR »

I have logged this as a bug with Adobe.
jacobolus

Color Lookup

Post by jacobolus »

There was none of my help here! Davide figured this one out himself, and deserves all the credit.

Anyway, as Davide’s code points out, you can get it by looking at the type of the first descriptor in the 'adjustment' list.

Here’s my serialization of a descriptor for a Color Lookup adjustment layer:

Code: Select all$desc {
    name: 'Color Lookup 1'
    color: $enum 'color.none'
    visible: true
    mode: $enum 'blendMode.normal'
    opacity: $int 255
    layerID: $int 3
    itemIndex: $int 2
    count: $int 3
    preserveTransparency: false
    userMaskEnabled: true
    userMaskLinked: true
    layerFXVisible: false
    globalAngle: $int 120
    background: false
    layerSection: $enum 'layerSectionType.layerSectionContent'
    layerLocking: $desc 'layerLocking', {
        protectTransparency: false
        protectComposite: false
        protectPosition: false
        protectAll: false
    }
    group: false
    targetChannels: $list [
        $ref.index('channel', 4)
    ]
    visibleChannels: $list [
        $ref.index('channel', 1)
        $ref.index('channel', 2)
        $ref.index('channel', 3)
    ]
    channelRestrictions: $list [
        $enum 'channel.lightness'
        $enum 'channel.a'
        $enum 'channel.b'
    ]
    fillOpacity: $int 255
    hasUserMask: true
    hasVectorMask: false
    hasFilterMask: false
    userMaskDensity: $int 255
    userMaskFeather: 0
    vectorMaskDensity: $int 255
    vectorMaskFeather: 0
    adjustment: $list [
        $desc 'colorLookup', {
            legacyContentData: $data ... giant blob of profile data
        }
    ]
    bounds: $desc 'rectangle', {
        top: $unit 'pixelsUnit', 0
        left: $unit 'pixelsUnit', 0
        bottom: $unit 'pixelsUnit', 360
        right: $unit 'pixelsUnit', 504
    }
    useAlignedRendering: false
}

The actual data inside the legacyContentData blob consists of a descriptor itself, which looks like:

Code: Select all$desc {
    lookupType: $enum 'colorLookupType.abstractProfile'
    name: 'Blue Tone'
    dither: true
    profile: $data ... 30 kb of raw data
}
Mike Hale

Color Lookup

Post by Mike Hale »

Yes, I misread the post from Paul. It's not that you can't determine the type of layer using Action Manager. It's the layer kind enum for that layer type that is missing from the DOM.