Friday, May 13, 2011

Assignment 4.1 - Photoshop Tutorial and Color Blind Image Scripting-Week 11

Part 1:

Week 9- Best Tutorial Recommendation- For Loops in Photoshop Javascript

This website: http://babbage.cs.qc.edu/courses/cs081/Javascript_Tutorial/index.xhtml#navTarget_2
has the fundamental breakdown on Javascript concepts.

The example in this tutorial discusses that for loops can be employed to use arrays in various ways.
Addition of simple variable numbers in an array is the utilization for this example. First, the selected numbers have to be chosen and put into an array, which is not shown in the example. The variable sum will hold the added amount of all the variables from within the array. Sum has been declared at the top of the for loop to be recognized and used later on. The variable i within the for loop is a generic variable used as a counter also called a loop control variable. The variable i is used three times in the first line of the for loop. The value is always set to zero because that is the number programmers always use to and signifies the beginning of array elements and for loops . An ending has to be specified as well. This for loop can run the number of times stated in the array defined, which is four. The method call anArray.length measures the amount of elements in the for loop, which becomes the amount of times the for loops functions.  Lastly, i++ is the code that specifies that i should add one to every element in the array and add the element values, as demonstrated by the linking of  i to the array in the statement anArray[i].

This is the full code I came up with after I changed the numbers in the example and reviewed the loops and
arrays section also provided on the website. I set up four variables for numbers in the array and the array itself. I made the mistake the first time of not properly declaring the type var for the loop and the array and the new type for the array as well. The types of everything have to be defined in a similar manner to regular Java programming, which I learned from my Java class last semester and made me familiar with for loops and their functions.

//For loop array example with a result of 135.
Every element value in the array is added to the
one before to come out with the result of 135.

var a= 20; //element 0, #1
var b= 35;// element 1, #2
var c= 55; //element 2, #3
var d = 25; //element 3, #4

var anArray = new Array (a, b, c, d);
var sum = 0;
for (var i = 0; i < anArray.length; i++)
{
           sum = sum + anArray[i];
}

Part 2-Photoshop Script:

// Accesses the red channel by selecting it
var channelRef = app.activeDocument.channels.getbyName("red");
channelRef.opacity = 100;
var idslct = charIDToTypeID( "slct" );
    var desc5 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref4 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idRd = charIDToTypeID( "Rd  " );
        ref4.putEnumerated( idChnl, idChnl, idRd );
    desc5.putReference( idnull, ref4 );
executeAction( idslct, desc5, DialogModes.NO );

//Duplicate the red channel
var idDplc = charIDToTypeID( "Dplc" );
    var desc6 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref5 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref5.putEnumerated( idChnl, idOrdn, idTrgt );
    desc6.putReference( idnull, ref5 );
executeAction( idDplc, desc6, DialogModes.NO );

// select the green channel
var channelRef = app.activeDocument.channels.getbyName("green");
channelRef.opacity = 100;
var idslct = charIDToTypeID( "slct" );
    var desc7 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref6 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idGrn = charIDToTypeID( "Grn " );
        ref6.putEnumerated( idChnl, idChnl, idGrn );
    desc7.putReference( idnull, ref6 );
executeAction( idslct, desc7, DialogModes.NO );

//Duplicate the green channel
var idDplc = charIDToTypeID( "Dplc" );
    var desc8 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref7 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref7.putEnumerated( idChnl, idOrdn, idTrgt );
    desc8.putReference( idnull, ref7 );
executeAction( idDplc, desc8, DialogModes.NO );

// Make the red channel into a layer.

//select the Red copy
var idslct = charIDToTypeID( "slct" );
    var desc9 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref8 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        ref8.putName( idChnl, "Red copy" );
    desc9.putReference( idnull, ref8 );
executeAction( idslct, desc9, DialogModes.NO );

//Go to the select menu and choose All
var idsetd = charIDToTypeID( "setd" );
    var desc10 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref9 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idfsel = charIDToTypeID( "fsel" );
        ref9.putProperty( idChnl, idfsel );
    desc10.putReference( idnull, ref9 );
    var idT = charIDToTypeID( "T   " );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idAl = charIDToTypeID( "Al  " );
    desc10.putEnumerated( idT, idOrdn, idAl );
executeAction( idsetd, desc10, DialogModes.NO );

//Go to the Edit menu and select copy
var idcopy = charIDToTypeID( "copy" );
executeAction( idcopy, undefined, DialogModes.NO );
//Go to the Select menu and choose Deselect
var idsetd = charIDToTypeID( "setd" );
    var desc11 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref10 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idfsel = charIDToTypeID( "fsel" );
        ref10.putProperty( idChnl, idfsel );
    desc11.putReference( idnull, ref10 );
    var idT = charIDToTypeID( "T   " );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idNone = charIDToTypeID( "None" );
    desc11.putEnumerated( idT, idOrdn, idNone );
executeAction( idsetd, desc11, DialogModes.NO );

//Go to Select  > Deselect
var idsetd = charIDToTypeID( "setd" );
    var desc27 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref27 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idfsel = charIDToTypeID( "fsel" );
        ref27.putProperty( idChnl, idfsel );
    desc27.putReference( idnull, ref27 );
    var idT = charIDToTypeID( "T   " );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idNone = charIDToTypeID( "None" );
    desc27.putEnumerated( idT, idOrdn, idNone );
executeAction( idsetd, desc27, DialogModes.NO );

//Select all the Channels for the overall image
var idslct = charIDToTypeID( "slct" );
    var desc22 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref23 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idRGB = charIDToTypeID( "RGB " );
        ref23.putEnumerated( idChnl, idChnl, idRGB );
    desc22.putReference( idnull, ref23 );
executeAction( idslct, desc22, DialogModes.NO );

//Go to Edit >Paste to Paste the channel into a layer.
var idpast = charIDToTypeID( "past" );
    var desc23 = new ActionDescriptor();
    var idAntA = charIDToTypeID( "AntA" );
    var idAnnt = charIDToTypeID( "Annt" );
    var idAnno = charIDToTypeID( "Anno" );
    desc23.putEnumerated( idAntA, idAnnt, idAnno );
executeAction( idpast, desc23, DialogModes.NO );

// Make the green channel into a layer.

//Select the Green channel layer
var idslct = charIDToTypeID( "slct" );
    var desc25 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref25 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        ref25.putName( idChnl, "Green copy" );
    desc25.putReference( idnull, ref25 );
executeAction( idslct, desc25, DialogModes.NO );

//Go to Select menu and choose All
var idsetd = charIDToTypeID( "setd" );
    var desc26 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref26 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idfsel = charIDToTypeID( "fsel" );
        ref26.putProperty( idChnl, idfsel );
    desc26.putReference( idnull, ref26 );
    var idT = charIDToTypeID( "T   " );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idAl = charIDToTypeID( "Al  " );
    desc26.putEnumerated( idT, idOrdn, idAl );
executeAction( idsetd, desc26, DialogModes.NO );

//Go to Edit and Select Copy
var idcopy = charIDToTypeID( "copy" );
executeAction( idcopy, undefined, DialogModes.NO );

//Go to Select  > Deselect
var idsetd = charIDToTypeID( "setd" );
    var desc27 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref27 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idfsel = charIDToTypeID( "fsel" );
        ref27.putProperty( idChnl, idfsel );
    desc27.putReference( idnull, ref27 );
    var idT = charIDToTypeID( "T   " );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idNone = charIDToTypeID( "None" );
    desc27.putEnumerated( idT, idOrdn, idNone );
executeAction( idsetd, desc27, DialogModes.NO );

//Select all the color channels
var idslct = charIDToTypeID( "slct" );
    var desc28 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref28 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idRGB = charIDToTypeID( "RGB " );
        ref28.putEnumerated( idChnl, idChnl, idRGB );
    desc28.putReference( idnull, ref28 );
executeAction( idslct, desc28, DialogModes.NO );

//Go to Edit > Paste
var idpast = charIDToTypeID( "past" );
    var desc29 = new ActionDescriptor();
    var idAntA = charIDToTypeID( "AntA" );
    var idAnnt = charIDToTypeID( "Annt" );
    var idAnno = charIDToTypeID( "Anno" );
    desc29.putEnumerated( idAntA, idAnnt, idAnno );
executeAction( idpast, desc29, DialogModes.NO );

// Create the average of the two images in Photoshop.

// Drop opacity on Layer one (red) to 50%.
var idslct = charIDToTypeID( "slct" );
    var desc151 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref144 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref144.putName( idLyr, "Layer 2" );
    desc151.putReference( idnull, ref144 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc151.putBoolean( idMkVs, false );
executeAction( idslct, desc151, DialogModes.NO );

app.activeDocument.activeLayer.fillOpacity = 50;

// Select Screen in the Layers Panel.
LayerSet.properties.blendmode(screen);

// Merge Down both layers into one yellow one.
var idslct = charIDToTypeID( "slct" );
    var desc185 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref170 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref170.putName( idLyr, "Layer 3" );
    desc185.putReference( idnull, ref170 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc185.putBoolean( idMkVs, false );
executeAction( idslct, desc185, DialogModes.NO );

var idMrgtwo = charIDToTypeID( "Mrg2" );
    var desc186 = new ActionDescriptor();
executeAction( idMrgtwo, desc186, DialogModes.NO );

This is the result:


















http://www.ehow.com/how_5894621_average-two-images-photoshop.html
http://www.ehow.com/how_5918950_convert-channel-layer-photoshop.html
I used these two websites and notes from class to solve the problem.

No comments:

Post a Comment