Jump to content

Sepcot

Members
  • Posts

    63
  • Joined

  • Last visited

Posts posted by Sepcot

  1. HEADACHE STEP 1 !

    Now I want to have the same effect verticaly!

    ...any suggestion ?

    Warning: The code below doesn't work!

    The renderer runs several threads with small

    parts of the image (rect) and each thread seems

    to be independant (no info from others threads).

    int Amount1=50;   //[0,100]% lenght ratio
    
    [ThreadStatic]
    private static Random threadRand = new Random();
    
    void Render(Surface dst, Surface src, Rectangle rect) {
     float ratio = (float)Amount1 / 100.0f;  
     PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
     Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
     ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
     ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
     if (threadRand == null)
     {
       threadRand = new Random(unchecked(System.Threading.Thread.CurrentThread.GetHashCode() ^ unchecked((int)DateTime.Now.Ticks)));
     }
    
     Random localRand = threadRand;
    
     for (int x = rect.Left; x < rect.Right; x++)   {
       int m = (int)(ratio * (float)(localRand.Next(rect.Bottom - rect.Top) + rect.Top));    
       int n = localRand.Next(Math.Abs(m - rect.Top)) + rect.Top;    
       for (int y = rect.Top; y < rect.Bottom; y++)   { 
         if (y<=n) dst[x,y] = SecondaryColor;
         if ((y>n)&&(y<=m)) dst[x,y] = PrimaryColor;
       }
     }
    }
    

    Result: All image is filled with SecondaryColor.

    Moving from Horizontal to Vertical is not as easy as just changing Left and Right to Bottom and Top.

    Paint.NET currently passes scanlines into the Render loop (and as Rick has said, this might not always be the case, so your Horizontal code could be wrong in the future). Since scanlines are going into your render loop, rect.Bottom - rect.Top [height] is going to be equal to 1. So far starters, use selection instead of rect when calculating the width and height of the total selection.

    This does NOT solve how to draw vertically, since each pass into the render function will generate a new random number, but this should help you understand where you are going wrong and get back on track.

  2. HEADACHE STEP 1 !

    Now I want to have the same effect verticaly!

    ...any suggestion ?

    Warning: The code below doesn't work!

    The renderer runs several threads with small

    parts of the image (rect) and each thread seems

    to be independant (no info from others threads).

    int Amount1=50;   //[0,100]% lenght ratio
    
    [ThreadStatic]
    private static Random threadRand = new Random();
    
    void Render(Surface dst, Surface src, Rectangle rect) {
     float ratio = (float)Amount1 / 100.0f;  
     PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
     Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
     ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
     ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
     if (threadRand == null)
     {
       threadRand = new Random(unchecked(System.Threading.Thread.CurrentThread.GetHashCode() ^ unchecked((int)DateTime.Now.Ticks)));
     }
    
     Random localRand = threadRand;
    
     for (int x = rect.Left; x < rect.Right; x++)   {
       int m = (int)(ratio * (float)(localRand.Next(rect.Bottom - rect.Top) + rect.Top));    
       int n = localRand.Next(Math.Abs(m - rect.Top)) + rect.Top;    
       for (int y = rect.Top; y < rect.Bottom; y++)   { 
         if (y<=n) dst[x,y] = SecondaryColor;
         if ((y>n)&&(y<=m)) dst[x,y] = PrimaryColor;
       }
     }
    }
    

    Result: All image is filled with SecondaryColor.

    Moving from Horizontal to Vertical is not as easy as just changing Left and Right to Bottom and Top.

    Paint.NET currently passes scanlines into the Render loop (and as Rick has said, this might not always be the case, so your Horizontal code could be wrong in the future). Since scanlines are going into your render loop, rect.Bottom - rect.Top [height] is going to be equal to 1. So far starters, use selection instead of rect when calculating the width and height of the total selection.

    This does NOT solve how to draw vertically, since each pass into the render function will generate a new random number, but this should help you understand where you are going wrong and get back on track.

  3. By the way, Sepcot, my previous comment about irregular selections was not a "bizarre observation": your plugin is actually written incorrectly, and its rendering will end up incorrect if changes are made to the rendering framework and how the region of interests are passed to effects. (Like what if I start dividing up the rendering based on rectangle tiles, instead of scanlines? etc)

    Fixed. I refractored a lot of my code and added a BarcodeSurface class to pre-render a given barcode before it gets drawn to the destination surface.

    Dude! I deal with barcodes all day. Can you make it output a POSTNET barcode w/Check digit?

    POSTNET support added.

    See original post for download links.

  4. By the way, Sepcot, my previous comment about irregular selections was not a "bizarre observation": your plugin is actually written incorrectly, and its rendering will end up incorrect if changes are made to the rendering framework and how the region of interests are passed to effects. (Like what if I start dividing up the rendering based on rectangle tiles, instead of scanlines? etc)

    Ah, I think I have figured out a fix for this, but I don't have Visual Studio at work... look for an update next week...

    Dude! I deal with barcodes all day. Can you make it output a POSTNET barcode w/Check digit?

    If my fix works, I should be able to implement POSTNET as well.

  5. I print and read this one : sepcot;com

    -> no capital letter

    -> semi column instead dot

    (Well I'm using a french keyboard so I'm sure it's a matter of configuring the BC reader)

    Well, 'Sepcot.com' was encoded with Code 39, so it should be read in as 'SEPCOT.COM' (all uppercase, no lower case letters in Code 39) and there is no ';' character in Code 39 (there is in Full ASCII Code 39) so that is probably related to the language.

  6. MODERATORS NOTE:  this plugin has been superseded by a newer version:

    https://forums.getpaint.net/topic/31559-barcode-v14-nov-14-2015/

     

     

     

    Version 1.1.x of my Paint.NET Barcode Plugin is completed. Note: I do not have access to a barcode reader and have not checked the validity of the barcodes, but they should be accurate ?

    Version 1.1.x supports Code 39 and POSTNET barcodes, as well as fixes some rendering issues.

    Barcode-Dialog-v1.png

    Barcode-Sepcot.com.png

    'Sepcot.com' encoded with Code 39

    Barcode-12345-Postnet.png

    '12345' encoded with POSTNET

    Quote

    DLL Download Link (version 1.1.1): http://www.sepcot.co...rcodeEffect.zip (Unzip - Drop the Barcode.dll file into your Paint.NET Effects folder)

    Source Download Link (version 1.1.1): http://www.sepcot.co...ffectSource.zip

     

    For more information about what is going on in the code you can visit:

    http://www.sepcot.co...-Barcode-Plugin
    http://www.sepcot.co...ode-Plugin-v1_1

     

  7. Sepcot, I would recommend the following changes to your template:

    1. [*:58569]Add the code from my project listed above to your template for adding the effect to a submenu. There is some code and the reference to it.
      [*:58569]The OK and Cancel buttons should be anchored bottom & right instead of top & left.
      [*:58569]Add a "// place your public variables here" and "// set your default values here" to the token file.
      [*:58569]Add a few "using" lines to open up access to various controls (like I did in the project linked above.)

    Nice template, by the way! Thanks!

    Updated! Effects Plugin Template

    All of BoltBait's points above have been addressed.

    • [*:58569]Added SubMenu Option.
      [*:58569]Buttons anchored.
      [*:58569]Token file updated. Added getter/setter example.
      [*:58569]Added reference to PaintDotNet in Configuration Dialog

  8. At angle: 180, you can see the image actually moves 1px to the right and 1px down...

    To reproduce: create 30x30 image, gradient filled. Duplicate layer. Resize canvas to 36x36 (any even increase will work). Rotate top layer.

    @90, the top layer moves down one pixel. @180 it also moves right one pixel.

  9. Note: this is not a Paint.NET effect. This is a Visual Studio 2005 template that can be used to create further Paint.NET effects.

    This template is here to help speed the development process of creating Paint.NET effect plugins. It contains the C# code skeleton necessary to build your own effect.

    Effects Plugin Template - Save this zip file into your Visual Studio 2005 "Project Templates" directory (typically: My Documents\Visual Studio 2005\Templates\ProjectTemplates\). Do NOT unzip the file, just drop it into the ProjectTemplates directory.

    You can go here: http://www.sepcot.com/blog/2006/11/PDN-EffectPluginTemplate for a brief walkthrough of the code contained within the template.

    Note: the code contained in the template can be built as is, but it won't yeild you any interesting effects. In fact, it will just render a configuration dialog box with "OK" and "Cancel" buttons that do nothing to alter the canvas.

    I think this should go here rather than the Tutorial forum because of this is specifically related to creating plugins for Paint.NET rather than using Paint.NET to achieve some effect.

  10. If you then resize the Layers window, does it redraw and then display correctly?
    Yes.
    Also, it looks like at step 8 you are answering 'no' to the dialog that asks you to expand the canvas size. Correct?
    In the above example, yes, but not necessary. I have imported an image of the same size and still get the bug to happen.
×
×
  • Create New...