Red ochre Posted August 9, 2015 Share Posted August 9, 2015 Tell this MS ;-) What's their email address? I've only ever written my own method for doing this. "A little knowledge is a dangerous thing!". 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. 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. Quote Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings Link to comment Share on other sites More sharing options...
midora Posted August 9, 2015 Share Posted August 9, 2015 You are right DrawImage is not anti-aliased but you can use a TextureBrush with tiling. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted August 9, 2015 Share Posted August 9, 2015 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. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted August 9, 2015 Share Posted August 9, 2015 (edited) EDIT: Okay, this is getting past silly, but I need to make absolutely sure the tiling method I suggested works before I post it. So I re-removed the original comment. Edited August 9, 2015 by MJW Quote Link to comment Share on other sites More sharing options...
midora Posted August 9, 2015 Share Posted August 9, 2015 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; Quote Link to comment Share on other sites More sharing options...
BoltBait Posted August 9, 2015 Share Posted August 9, 2015 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 } Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
midora Posted August 9, 2015 Share Posted August 9, 2015 (edited) 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 August 9, 2015 by BoltBait Tested and fixed your code. 1 Quote Link to comment Share on other sites More sharing options...
BoltBait Posted August 9, 2015 Share Posted August 9, 2015 midora, that works really well. Expect an update to my plugins shortly. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
BoltBait Posted August 9, 2015 Share Posted August 9, 2015 OK, here is a copy of Fill > From File with all of the tile/mirror modes implemented. <snip - go download my plugin pack> Only one problem: the built-in help file has not been updated. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
kelemvor Posted August 9, 2015 Author Share Posted August 9, 2015 This is becoming a tonguetwister thread. 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? Quote Link to comment Share on other sites More sharing options...
BoltBait Posted August 9, 2015 Share Posted August 9, 2015 Someone needs to make a tutorial on how to use my plugin "Fill > From File" to make a collage. BTW, my plugin pack was just updated with all code described in this thread. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
midora Posted August 9, 2015 Share Posted August 9, 2015 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. Quote Link to comment Share on other sites More sharing options...
Eli Posted August 9, 2015 Share Posted August 9, 2015 @ 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? Quote Link to comment Share on other sites More sharing options...
BoltBait Posted August 9, 2015 Share Posted August 9, 2015 See? This is why I hate calculating stuff myself. 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* Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted August 9, 2015 Share Posted August 9, 2015 (edited) 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 August 9, 2015 by MJW Quote Link to comment Share on other sites More sharing options...
BoltBait Posted August 9, 2015 Share Posted August 9, 2015 Instead of using "GetBilinearSample(x, y)", would using "GetBilinearSampleClamped(x, y)" prevent you from having to subtract one from the tile size? Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted August 9, 2015 Share Posted August 9, 2015 (edited) 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 August 9, 2015 by MJW Quote Link to comment Share on other sites More sharing options...
MJW Posted August 9, 2015 Share Posted August 9, 2015 (edited) 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 August 9, 2015 by MJW Quote Link to comment Share on other sites More sharing options...
BoltBait Posted August 9, 2015 Share Posted August 9, 2015 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 Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
Eli Posted August 10, 2015 Share Posted August 10, 2015 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) . Quote Link to comment Share on other sites More sharing options...
BoltBait Posted August 10, 2015 Share Posted August 10, 2015 Small details disappearing are just a product of scaling the image. Not much I can do in that situation. I'm glad to know that the mirror math is working though. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted August 10, 2015 Share Posted August 10, 2015 (edited) 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 August 10, 2015 by MJW Quote Link to comment Share on other sites More sharing options...
MJW Posted August 16, 2015 Share Posted August 16, 2015 (edited) 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: 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 August 21, 2015 by MJW 3 Quote Link to comment Share on other sites More sharing options...
Eli Posted August 16, 2015 Share Posted August 16, 2015 MJW, Thanks for the effect! This is what I had in mind, but better. Maybe the width and height could be increased for a very large canvas to 7k? Quote Link to comment Share on other sites More sharing options...
MJW Posted August 16, 2015 Share Posted August 16, 2015 (edited) I can certainly increase the width and height easily. I wasn't sure what the maximum sizes should be. I'll probably increase the height and width to 8K. That should be big enough for about any image. Edited August 16, 2015 by MJW Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.