Skip navigation
Currently Being Moderated

BUG in getting layer's bounds

Mar 25, 2013 4:41 AM

Tags: #photoshop #adobe #bug #c++ #plugin #plug-in

Hi all! This code contains weird bug:

 

    //

    // GET LAYER BOUNDS

    //

    error = PIUGetInfoByIndex(LayerCounter,classLayer,0,&descLayer,NULL);

    if (error) goto returnAutoError;

 

    error = sPSActionControl->StringIDToTypeID("bounds", &runtimeKeyID);

         if (error) goto returnAutoError;

 

    error = sPSActionControl->StringIDToTypeID("classRectangle", &runtimeClassID);

        if (error) goto returnAutoError;

 

    error = PIUGetSingleItemFromDescriptor(descLayer,runtimeKeyID,&descPosition,& descClass);

    if (error) goto returnAutoError;

 

    error = sPSActionDescriptor->GetFloat(descPosition, keyTop, &top);

    if (error) goto returnAutoError;

    error = sPSActionDescriptor->GetFloat(descPosition, keyLeft, &left);

    if (error) goto returnAutoError;

    error = sPSActionDescriptor->GetFloat(descPosition, keyBottom, &bottom);

    if (error) goto returnAutoError;

    error = sPSActionDescriptor->GetFloat(descPosition, keyRight, &right);

    if (error) goto returnAutoError;

 

I have a PSD with several layers, and this code returns different values that depend on layer order. This bug can not be reproduced if this is layer in layer group.

 

I'm generating XML:

 

<?xml version="1.0" encoding="UTF-8"?>

<LayerGroup name="tile" index="6">

          <Layer name="bg_tile@" top="222.000000" left="0.000000" bottom="542.000000" right="1070.000000" hasFile="bg_tile.png" index="2"/>

          <Layer name="bg_tile4!" top="222.000000" left="0.000000" bottom="713.000000" right="1070.000000" index="3"/>

          <Layer name="bg_tile3!" top="325.000000" left="0.000000" bottom="1178.000000" right="1070.000000" index="4"/>

          <Layer name="layer!" top="540.000000" left="0.000000" bottom="1178.000000" right="1070.000000" index="5"/>

</LayerGroup>

 

then change the order:

 

<?xml version="1.0" encoding="UTF-8"?>

<LayerGroup name="tile" index="6">

          <Layer name="bg_tile@" top="222.000000" left="0.000000" bottom="542.000000" right="1070.000000" hasFile="bg_tile.png" index="2"/>

          <Layer name="bg_tile4!" top="222.000000" left="0.000000" bottom="713.000000" right="1070.000000" index="3"/>

          <Layer name="layer!" top="325.000000" left="0.000000" bottom="860.000000" right="1070.000000" index="4"/>

          <Layer name="bg_tile3!" top="540.000000" left="0.000000" bottom="1178.000000" right="1070.000000" index="5"/>

</LayerGroup>

 

and one more time:

 

<?xml version="1.0" encoding="UTF-8"?>

<LayerGroup name="tile" index="6">

          <Layer name="bg_tile4!" top="325.000000" left="163.000000" bottom="713.000000" right="792.000000" index="2"/>

          <Layer name="layer!" top="325.000000" left="0.000000" bottom="860.000000" right="1070.000000" index="3"/>

          <Layer name="bg_tile3!" top="540.000000" left="0.000000" bottom="1178.000000" right="1070.000000" index="4"/>

          <Layer name="bg_tile@" top="222.000000" left="0.000000" bottom="1178.000000" right="1070.000000" hasFile="bg_tile.png" index="5"/>

</LayerGroup>

 

Can send you my PSD.

 

So, how I should get layer coords? I'm doing merge then calling the code in the beginning of the topic.

 
Replies
  • Currently Being Moderated
    Mar 25, 2013 5:19 AM   in reply to juradrgtg

    Code is OK. It will get you result of whatever is acessed by:

    error = PIUGetInfoByIndex(LayerCounter,classLayer,0,&descLayer,NULL); // where LayerCounter is int;

    Pay attention what you get as a result of merge and how that change indexes, try something like SelectLayerByIndex(int iLayerCounter) then GetBounds(int iLayerCounter...).

    Use Listner for making functions and getter to check results of your code.

     

    regards,

    Momir

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 10:14 AM   in reply to juradrgtg

    Your code returns bounds of whatever layer is currently active (selected). Be careful here.

     

    However, I ALWAYS explicitly select layer by index before performing any operation or try to get any property of it.

     

    Regards,

    Momir

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 9, 2013 8:48 AM   in reply to juradrgtg

    Keep in mind that layer bounds will ignore transparent pixels, so you end up with a smallest fit rectangle around your layer's pixel data.  If

    you have stray pixels that have some very small (invisible to your eyes) value in any channel, those will be included in the layer's bounds.

     

    Hope that helps

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points