PixelArt Posted April 8, 2020 Share Posted April 8, 2020 (edited) Could someone add pixel-perfect drawing mode for freehand tools? https://rickyhan.com/jekyll/update/2018/11/22/pixel-art-algorithm-pixel-perfect.html https://deepnight.net/blog/tools/pixel-perfect-drawing/ https://github.com/aseprite/aseprite/commit/15548756180eb78872718d54acde3fbcfe833303 pub fn pixel_perfect(path: &[Pixel]) -> Vec<Pixel> { if path.len() == 1 || path.len() == 0 { return path.iter().cloned().collect(); } let mut ret = Vec::new(); let mut c = 0; while c < path.len() { if c > 0 && c+1 < path.len() && (path[c-1].point.x == path[c].point.x || path[c-1].point.y == path[c].point.y) && (path[c+1].point.x == path[c].point.x || path[c+1].point.y == path[c].point.y) && path[c-1].point.x != path[c+1].point.x && path[c-1].point.y != path[c+1].point.y { c += 1; } ret.push(path[c]); c += 1; } ret } Edited April 8, 2020 by PixelArt Link to comment Share on other sites More sharing options...
PixelArt Posted April 8, 2020 Author Share Posted April 8, 2020 /* Aseprite * Copyright (C) 2001-2013 David Capello * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ class IntertwineAsPixelPerfect : public Intertwine { struct PPData { Points& pts; ToolLoop* loop; PPData(Points& pts, ToolLoop* loop) : pts(pts), loop(loop) { } }; static void pixelPerfectLine(int x, int y, PPData* data) { gfx::Point newPoint(x, y); if (data->pts.empty() || data->pts[data->pts.size()-1] != newPoint) { data->pts.push_back(newPoint); } } Points m_pts; public: void prepareIntertwine() OVERRIDE { m_pts.clear(); } void joinPoints(ToolLoop* loop, const Points& points) OVERRIDE { if (points.size() == 0) return; else if (m_pts.empty() && points.size() == 1) { m_pts = points; } else { PPData data(m_pts, loop); for (size_t c=0; c+1<points.size(); ++c) { int x1 = points[c].x; int y1 = points[c].y; int x2 = points[c+1].x; int y2 = points[c+1].y; algo_line(x1, y1, x2, y2, (void*)&data, (AlgoPixel)&IntertwineAsPixelPerfect::pixelPerfectLine); } } for (size_t c=0; c<m_pts.size(); ++c) { // We ignore a pixel that is between other two pixels in the // corner of a L-like shape. if (c > 0 && c+1 < m_pts.size() && (m_pts[c-1].x == m_pts[c].x || m_pts[c-1].y == m_pts[c].y) && (m_pts[c+1].x == m_pts[c].x || m_pts[c+1].y == m_pts[c].y) && m_pts[c-1].x != m_pts[c+1].x && m_pts[c-1].y != m_pts[c+1].y) { ++c; } doPointshapePoint(m_pts[c].x, m_pts[c].y, loop); } } void fillPoints(ToolLoop* loop, const Points& points) { if (points.size() < 3) { joinPoints(loop, points); return; } // Contour joinPoints(loop, points); // Fill content algo_polygon(points.size(), (const int*)&points[0], loop, (AlgoHLine)doPointshapeHline); } }; Link to comment Share on other sites More sharing options...
MJW Posted April 9, 2020 Share Posted April 9, 2020 Rick Brewster is the only one who has any control over what the freehand tools do. Link to comment Share on other sites More sharing options...
PixelArt Posted April 9, 2020 Author Share Posted April 9, 2020 So plugins with drawing area isn't possible? Link to comment Share on other sites More sharing options...
MJW Posted April 9, 2020 Share Posted April 9, 2020 I'm not sure what you mean by " plugins with drawing area." If you mean would it be possible to make a tool-type plugin that lets you draw on a canvas it creates (the way Brush Factory does), then yes it would. That's not how I interpreted your original request. I thought you wanted to add a pixel-perfect mode to the existing freehand tools. Link to comment Share on other sites More sharing options...
PixelArt Posted April 9, 2020 Author Share Posted April 9, 2020 2 hours ago, MJW said: I thought you wanted to add a pixel-perfect mode to the existing freehand tools. This would be definitely the best solution. Hope Rick Brewster will add this feature (checkbox for pixel-perfect) to all freehand tools. Surely that tool-type plugin that lets you draw on a canvas would be better than nothing. Is there tutorial for that kind of plugin? Link to comment Share on other sites More sharing options...
toe_head2001 Posted April 9, 2020 Share Posted April 9, 2020 2 hours ago, PixelArt said: Is there tutorial for that kind of plugin? You mean for someone who wants to do the programming work to create the plugin? I'm not sure if you fully understand the code snippets that you posted, but the C++ snippet is bloated with extra data types and references to helper functions. The Rust snippet on the other hand, is very succinct and easy to follow. By the way, Paint.NET plugins are typically made using C#; not C++ or Rust. (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
PixelArt Posted April 9, 2020 Author Share Posted April 9, 2020 Is there any tutorial for Paint.NET plugin where you could draw on a canvas? It would be nice, if you could add plugin-buttons directly to Tools (F5) window. Or even make new tools-window just for plugins. Link to comment Share on other sites More sharing options...
toe_head2001 Posted April 9, 2020 Share Posted April 9, 2020 To reiterate what MJW has already said: No, that kind of plugin (a Tool that interacts directly with the canvas) is not possible in Paint.NET. The plugin would need to an Effect and provide its own canvas; similar to how the Brush Factory plugin works. (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
PixelArt Posted April 10, 2020 Author Share Posted April 10, 2020 Ok, got it. Hope developer will catch this and implement it natively. Link to comment Share on other sites More sharing options...
Rick Brewster Posted April 26, 2020 Share Posted April 26, 2020 Seems interesting, I might check it out at some point ... always did kinda dislike the way pencil drawing turns out 3 1 The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Ketenks Posted May 8, 2020 Share Posted May 8, 2020 I second this motion of PixelArt to make freehand tools that draw perfectly to snapin grids and things. It'd be great if every tool came with user input parameters in the tool bar where you can simply input the numbers to make the drawn item exactly as you want, pixel for pixel coordinates. And free hand drawing could use the grid snap ins I guess. 1 Link to comment Share on other sites More sharing options...
PixelArt Posted August 5, 2020 Author Share Posted August 5, 2020 On 4/27/2020 at 1:13 AM, Rick Brewster said: Seems interesting, I might check it out at some point ... always did kinda dislike the way pencil drawing turns out Any news about this would be appreciated thanks. Link to comment Share on other sites More sharing options...
Rick Brewster Posted August 6, 2020 Share Posted August 6, 2020 There's no news. Likely won't be for quite awhile. No need to bump this -- just pay attention to the release notes whenever I put out an update. https://blog.getpaint.net/ The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Recommended Posts