Jump to content

Recommended Posts

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 by PixelArt
Link to post
Share on other sites
/* 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 post
Share on other sites

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 post
Share on other sites
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 post
Share on other sites
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.

Link to post
Share on other sites

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 post
Share on other sites
  • 3 weeks later...
  • 2 weeks later...

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.

  • Like 1

ketenksEsignatureSmall2.png.f74cf40145e3a072030b070615ef1b93.png

Link to post
Share on other sites
  • 2 months later...
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 post
Share on other sites

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

forumSig_bmwE60.jpg

Link to post
Share on other sites
Guest
This topic is now closed to further replies.
×
×
  • Create New...