Jump to content

How do I select/resize a layer?


Recommended Posts

 

Tell this MS ;-)

What's their email address? :lol:

I've only ever written my own method for doing this. ;) "A little knowledge is a dangerous thing!". :D

Clipwarp and Squirklewarp both use it to avoid the hard edges if simply repeating or clamping.

I was working on a tiling plugin with some other interesting tesselation patterns (examples recently in my gallery) but (as usual) I started over complicating things. :roll:

I'll be happy to share the code when/if it gets finished but at the moment it needs a lot of annotation before being understandable.

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Instead of a simple on/off switch for tiling you may add the typical flip modes for tiling.

No tiling, tiling, flip tiles hor, flip tiles ver, flip tiles hor & ver

I would have to calculate those by hand. Ugh. To many chances for +1/-1 errors.

Link to comment
Share on other sites

If you implemented tiling already then I expect that you calculate a tileX/tileY positions for each dstX/dstY.

Flipping just means that you have to modify the position for every second tile.

I.e.   if (tileFlipX && ((tileCol % 2 != 0)) tileX = tileW - tileX;

midoras signature.gif

Link to comment
Share on other sites

If you implemented tiling already then I expect that you calculate a tileX/tileY positions for each dstX/dstY.

The tiling code looks like this:

// see if we are tiling
if (Amount6)
{
    dst[x, y] = img.GetBilinearSampleWrapped(px, py); // tiled
}
else
{
    dst[x, y] = img.GetBilinearSample(px, py); // not tiled
}
Link to comment
Share on other sites

Untested

        static ColorBgra GetBilinearSampleWrappedWithMode(Surface tile, float x, float y, WrapMode wrapMode)
        {
            int tileW = tile.Width;
            int tileX = (int)Math.Floor(x / tileW);  // index of the tile horizontal
            x = x - tileX * tileW;                   // offset in the tile

            int tileH = tile.Height;
            int tileY = (int)Math.Floor(y / tileH);  // index of the tile vertical
            y = y - tileY * tileH;                   // offset in the tile

            switch (wrapMode)
            {
                case WrapMode.Tile:
                    break;
                case WrapMode.TileFlipX:
                    if ((tileX % 2) != 0) x = tileW - (x+1); 
                    break;
                case WrapMode.TileFlipY:
                    if ((tileY % 2) != 0) y = tileH - (y+1);
                    break;
                case WrapMode.TileFlipXY:
                    if ((tileY % 2) != 0) y = tileH - (y+1);
                    if ((tileX % 2) != 0) x = tileW - (x+1);
                    break;
            }

            return tile.GetBilinearSampleClamped(x, y);
        }

Edited by BoltBait
Tested and fixed your code.
  • Upvote 1

midoras signature.gif

Link to comment
Share on other sites

I'm trying to find where it stopped being about what I posted and evolved into something completely different.

 

Or if it really is all about what I posted, can someone sum it up for me?  :)

 

We are sorry.

 

You may use Boltbaits 'Fill from file' plugin w/o tiling mode to place and size each image of your collage on a new layer.

midoras signature.gif

Link to comment
Share on other sites

@ BoltBait: The canvas size on this image is 800x600 and the tiled picture is 200x200. When I run the effect with a zoom of 1, I would expect to see on the canvas 12 full circles, but as you see there are small parts of other circles on the right and bottom edges. Is this normal?

 

bb-fill-43-4c512b7.png

Link to comment
Share on other sites

See? This is why I hate calculating stuff myself. :D

Yes, it is normal for the algorithm MJW/midora came up with as it ignores a 1 pixel border in the image. This prevents semi-transparent bands in the resulting image.

Well, I'm not fixing it. So, either live with it or use Layer > Rotate / Zoom to do your tiling. *FIXED*

EDIT: I just noticed that if you call it with a tile of 1px by 1px it will crash. *FIXED*

Link to comment
Share on other sites

Here's the code I posted earlier that I had doubts about, but which I now believe works:

 

I use what I refer to as "Alternately Tiled" in Texture Shader. The version I use reduces the tile size, relative to normal tiling, by one pixel on each side, since I don't duplicate the edge  pixels. I think that's the sensible choice. The code's pretty simple:
 
The setup is:

float tileMaxX = (float)(img.Width - 1);
float tileMaxY = (float)(img.Height - 1);
float tileSizeX = 2.0f * tileMaxX;
float tileSizeY = 2.0f * tileMaxY;

The mapping routine is:

ColorBgra GetImageSampleAlternatelyTiled(float x, float y)
{
    x = (float)Math.Abs(x) % tileSizeX;
    if (x > tileMaxX)
        x = tileSizeX - x;
    y = (float)Math.Abs(y) % tileSizeY;
    if (y > tileMaxY)
        y = tileSizeY - y;
    return img.GetBilinearSample(x, y);
}

I now understand why I was confused, so I don't feel so silly. The point that confused me was where GetBilinearSample considers the pixel to be located: at the corner or at the center of the pixel squares. I believe I would prefer it be considered to be at the center, which means the outer half of the edge pixels wouldn't be interpolated, but would take the pixel color. That doesn't seem to be the way it works, though. It appears the corner of the pixel is considered its location, which means the left and top edge pixels are interpolated over the full pixel, and the right and bottom edge pixels are constant over the entire pixel. If the pixels were considered to be at the center of the pixel squares, I would need an extra half-pixel offset.

 

EDIT (as if I mark all my edits!): Changing tileMaxX = (float)(img.Width - 1) to tileMaxX = (float)img.Width (and the same for y) would, I believe, result in tiles of the same size as normal tiling; however it would result in an extra right edge being added, rather than the better result of having an extra half left and right edge. Adding the half-edges would require somewhat more complex code.

Edited by MJW
Link to comment
Share on other sites

Using GetBilinearSampleClamped, along with the suggestion I posted in my previous edit, would be a good way to achieve a tile size that matches other tiling. I think you'd need to subtract half a pixel before the call; i.e., GetBilinearSampleClamped(x - 0.5f, y - 0.5f).

 

I believe the reduced-by-one tile size is more sensible, though. I don't see a good reason for widening the edges relative to the other rows and columns.

Edited by MJW
Link to comment
Share on other sites

EDIT: I just noticed that if you call it with a tile of 1px by 1px it will crash.

 

That's something I need to check for, too.

 

Something like:

float tileMaxX = (img.Width < 2) ? 1.0f : (float)(img.Width - 1);
float tileMaxY =  (img.Height < 2) ? 1.0f : (float)(img.Height - 1);
float tileSizeX = 2.0f * tileMaxX;
float tileSizeY = 2.0f * tileMaxY;

EDIT: On second thought, I'm not really sure it's a problem. While integer division by 0 results in an exception, float division by 0 (and similar) results in Infinity or NaN. I know that the Bilinear routines return Transparent pixels for such arguments.

 

Edited by MJW
Link to comment
Share on other sites

OK, I think I got all the math working properly.

Eli, redownload my plugin pack and try your sample image again.

If you're curious, I fixed the code in this post: http://forums.getpaint.net/index.php?/topic/32119-how-do-i-selectresize-a-layer/?p=429498

Link to comment
Share on other sites

Boltbait, I tried the same tile and works pretty well with zoom factors of 1, 2, 4, 5, (7 and 8 are to small to see). However, using 3 and 6 the crosshairs dissapear on some of the tiles.

 

Then, I tried using a larger canvas (double or tripple) The cross hairs are there when I need as many tiles as with zoom factors of 3 and 6. Then I reduced the canvas back to (800x600) :) .

Link to comment
Share on other sites

Small details disappearing are just a product of scaling the image. Not much I can do in that situation.

 

 

There's always the option of supersample antialiasing. It's not perfect, but can help quite a bit. It wouldn't be too difficult to choose the number of subsamples per pixel automatically, based on the zoom factor.

Edited by MJW
Link to comment
Share on other sites

Here is a beta version of the plugin Eli suggested. It allows the user to frame a rectangle within the canvas. It will eventually (soon, in fact)  be published as a finished plugin, but I thought I'd post the current version first for comments and suggestions. If there are options you'd like added, or too many unnecessary options, please let me know. Also, tell me if there are better choices for the default values (but keeping in mind that for CodeLab plugins the defaults can't depend on, for instance, the window size).

 

Perhaps it would be useful to allow it to blend the view frame into the current layer. I'm not sure that makes sense, since it would obviously change the image, but maybe there's some reason for doing so. The current version allows only black or white for the background color. Perhaps there's some use for more color choices. I always have a hard time resisting adding every option I can think of, but that tends to make the plugins more difficult to use. I think View Framer is a decent name, but other suggestions are welcome.

 

A small example image is: post-53337-0-15465900-1439694383_thumb.p

 

The plugin is here: ViewFramer .zip

 

The plugin is called View Framer and is under Effects>Render>View Framer. The idea of the plugin is that the user adds a new layer then generates the view frame.

 

I wish I could make the maximum rectangle size depend on the image size, but that's not possible in CodeLab plugins. Though inelegant, I don't think it's a big disadvantage. If it is, I could make it a Visual Studio plugin. I prefer CodeLab plugins when possible, so the code can be more easily built and modified by others.

 

The guidelines are one pixel above and below the view region, so they don't cover the edges. Note one of the guideline color options is None. Selecting None will make the corresponding guidelines disappear.

 

Though my example shows an off-center rectangle, the default position of the rectangle is centered (or as close to centered as possible).

 

The plugin has a stub Help menu. I'll complete the menu once I finalize the interface.

 

If anyone wants the current code, I'll be happy to post it. I will, as is my usual practice, post the code when I publish the plugin.

 

EDIT: Changed plugin to version 1.1, which allows wider view windows (8000 pixels), guideline width control, and constrains the view window to the canvas. It also makes the smallest view window size 1 instead of 0.

Edited by MJW
  • Upvote 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...