Jump to content

aphillips

Members
  • Posts

    49
  • Joined

  • Last visited

Posts posted by aphillips

  1. Why in the world aren't you using IndirectUI :?: ...

    Thanks for the feedback. I have seen mention of IndirectUI but couldn't find any info on how to use it. I searched a few times in these forums and on Google. Actually, I couldn't really find much info about writing plugins at all, but found a template and just enough info to be dangerous.

    Also, the performance is veeeeerrrrrrrryyyyyyyyyy slow. ... Are you doing all your rendering in OnSetRenderInfo()?

    OnSetRenderInfo does do a bit of "global" work trying to find the edge of shape(s), but I believe I defer as much as I can to the Render calls. I didn't notice a speed problem, but I only tested on small images (biggest was 16 x 300). I haven't optimized for speed yet but I don't believe it is doing anything too inefficiently.

  2. Please find attached a beta version of my new "Clear Background" plugin. This was discussed in the "infer transparency" thread in this forum but I thought this name was better. It tries to recreate a transparent background for an antialiased image which has been rendered onto a plain (single colour) background. Please try it and tell me what you think.

    This plugin addresses the problem where the alpha channel of an image has been lost and needs to be recovered. I was creating some icons for my hex editor (see http://www.hexedit.com) and I had many icons with antialiased edges that had been rendered on a white background. This plugin does not always give perfect results but it can make a 20 minute job into a 2 minute one, which can save a lot of time if you have hundreds of images to fix. Note that the plugin makes it easy to extract images (such as toolbar icons) from commercial software, but please do not use it to infringe copyrights.

    I have called the plugin "Clear Background" as the whole point of it is to make a transparent background. I have placed it on the "Color" sub-menu as it is related to the "Color to Alpha Advanced" plugin there.

    Here are a few tips on its use.

    First, the pixels that are made completely transparent must all exactly match the chosen color. (I may add a tolerance in the future.) You should use a flood fill first if you have a slightly shaded background.

    Also, nicely designed icons usually have antialiased edges at angles but do not use transparency at all for straight (horizontal and vertical) edges. In this case you can "deselect" these areas to make sure they are not made transparent. In fact it is usually a good idea to select just the areas you want to be changed. The magic wand, with an appropriate tolerance, is great for this. You may still have to do a little bit of manual adjustment to get all of the edges that have been obviously antialiased.

    Some icons have holes in the image where the background shows through. This is the purpose of the "check for holes" option. However, there can also be parts of the "foreground" image that use the background color. Again, it is a good idea to use the selection to tell the plugin which parts are holes and which parts should not be touched.

    Finally, don't forget to try the "By distance" option. I thought that the "By Color" option would give better results but testing revealed otherwise.

    There are some obvious places for improvement. First, the dialog could do with a color selection control (as in other plugins) to select the background color, but I have not worked out how to add one. The "edge width" would also be better as a slider rather than having to enter a floating point number.

    I have also found that it would be useful to be able to preview the result with various background colors before clicking OK. This would make it much easier to find the right value for "edge width".

    There may also be room to improve the algorithm I use to set the color and transparency of the "edge" pixels. Anyone is welcome to the source code if they want to try and improve it.

    --------------------

    Here is an example. I did a screen capture and extracted the Paint.Net zoom toolbar button image. As this had a slightly shaded background I filled the background using a background pixel near the middle (RGB=249,249,249). Then I ran the effect with an edge width of 1.2 using both the By Distance and By Color options.

    Before.png

    Image before effect applied.

    ByColor.png

    Clear Background effect using By Color option

    ByDistance.png

    Clear Background effect using By Distance option

    ClearBackgroundPlugin.zip

  3. > Zip the .dll file up and add it as an attachment in a thread in the plugin section (or plugin developers' central if it's a beta.)

    Thanks. I initially did not see the "Upload attachment" pane (off the bottom of the screen), but I saw it and posted it in this forum in a new (Clear Background) thread.

    I forgot to zip it first though. I will do that and re-submit. If you are the moderator ignore the 2 earlier posts with the unzipped file. (I assume that posts with attachments have to be approved by the moderator.)

  4. pyrochild said:

    > ... anything that has to process on the entire image before anything else can be processed can be done in the OnSetRenderInfo method

    This is also what I was trying to do. That is, I have a large amount of initialization code which would make rendering the effect very slow if it was performed every time Render was called. I did not know about OnSetRenderInfo, so what I did was this:

    private bool firstCall = true;

    public override void Render(EffectConfigToken parameters, ...)

    {

    lock(this)

    {

    if (firstCall)

    {

    // Do time-consuming init here using srcArgs

    ....

    firstCall = false;

    }

    }

    for (int i = startIndex; i < startIndex + length; ++i)

    // render to current rect(s)

    }

    Note that this assumes that PDN itself does not lock have a lock on the effect instance at the time, which is a pretty safe bet (but Rick can confirm this). If this turns out to be a problem you can use a private member object to lock instead.

    The above will work even if you have not specified the EffectFlags.SingleThreaded flag in the ctor, since the lock means that the initialization is only performed once even if other threads are also executing the Render method.

    I have looked at the source code for a few effects and I have noticed 2 common problems:

    ** they specify EffectFlags.SingleThreaded when they do not need to

    ** they repeat a lot of initialization code each time Render is called which can be done once

    Back to the original question:

    codester said:

    > ... parts of the image have to be rendered in a predefined order ...

    I don't think turning off multithreaded rendering will help you. Even if you set the EffectFlags.SingleThreaded flag it is still not defined which order the rects are passed to consecutive calls to Render. All EffectFlags.SingleThreaded does is ensure that multiple Renders are not running at the same time (ie in different threads).

    I think what you really need to do is organise your code so that most of your code is done as above in an "init" block. Then render different parts appropriately in the specific calls to Render. You can always do this even if you have to create a temp surface in the "init" code, and then just copy the appropriate pixels (as spec'ed by rois, startIndex, length).

  5. Hi Boltbait,

    I spoke too soon (as usual). For colored icons (and a white background) your CodeLab script is great but for ones with gray borders it makes the border almost completely transparent. Not what I wanted. (Some icons seem to have the bottom/right side more gray as a shadow, and some icons seems to have a gray line drawn all the way around them.)

    I can see why that happens from your code. I am still thinking how to create a plugin to do what I want. (I have written some of this sort of thing before in C++.)

  6. Hi BoltBait,

    I just tried your CodeLab script. It works very nicely adjusting the color (not just the alpha as was my problem with the Color To Alpha plugin). Thanks very much.

    I still have to select the area first since it tends to affect a lot of pixels inside shapes which I don't want changed. I usually try the magic wand, but it does not usually give good results (when I increase the tolerance to get enough of the borders to be transparent it tends to "leak" into the shapes first), so I have to manually adjust the selection.

    Also your script works brilliantly for a white background (which is what I have most of the time) but how do I change it to work for other colours, eg a gray (192,192,192) background?

  7. I have been using the "Color To Advanced Plugin" for a while and it is not as useful as I first thought. Comparing some images I fixed manually with its results reveals the problem:

    Since I have a white background the RGB values are lighter than they should be which when combined with the transparency which makes the edges almost disappear. I usually try to compensate for this by increasing the "Alpha Amount" using the slider (making the pixel less transparent) but there appears to be a bug that causes the alpha value to overflow 8 bits and wrap back to zero. In any case the edges end up too white when overlaid on a dark background.

    Another problem is that the plugin keeps crashing.

    So I have gone back to my manual method (until I write my plugin). FYI my manual method is fairly simple:

    1. Create a layer behind and fill it with the background color (usually white in my case).

    2. Find an edge pixel (A) to adjust and an adjacent pixel (B) that probably originally had no transparency

    3. Use the color picker to get the RGBA value of (B) above.

    4. Reduce the alpha of the color just picked to try to match what was probably the transparency of (A).

    5. Use the pencil tool to set pixel (A). As the alpha value is < 255 the background layer should show through a bit.

    6. If the pixel color does not change too much then the alpha value OK and I move on to the next pixel.

    7. Otherwise I undo the change and go back to step 4.

    A plugin to do something similar should be fairly simple. The main problem will be detecting edges I think. My strategy would be that everything of the chosen background would be made fully transparent. Any adjacent pixels that are not exactly the same RGB value are considered an edge.

    I am not sure whether to make the "width" of an edge user definable (in pixels) or try to determine the width by looking at how much the RGB values vary from the background. My inclination is the first as the image may be a similar color to the background and it allows the user to control the behavior.

  8. Hi barkbark00. Thanks for the pointer to the "Color to Alpha Advanced" plugin. It is quite a bit simpler than the plugin I was thinking of (but it has saved me some time).

    First it changes the alpha of almost every pixel of my icons, especially if they have muted colors. I only want to make the background fully transparent and make edges of any shapes detected partially transparent. Using the magic wand to select the area to work on avoids this problem most of the time.

    Second it never changes the color (RGB) value only the alpha channel. My plugin will adjust each pixel based on the background color and also the color of adjacent pixels. So if the background is blue and an icon is mainly red then the purple edge pixels get made into a transparent red. In my case the existing backgrounds are white and the new backgrounds are mainly light gray (except where the image is placed on top of another one) so there are only a few small areas that need to be fixed up.

    So I can use the "Color to Alpha Advanced" plugin to save me perhaps 90% of my work, but it is not exactly what I wanted.

    I think I will still create my plugin. I think it will give much better results by only changing the transparency (and color) of pixels on the borders of shapes. It would need an option to say how far to go into shapes (default probably about 1.4 pixels), plus checkbox for looking for "holes".

    Rick, Could you move this back to the plugin development forum? Thanks!

  9. I have tried this plugin and found it very useful, thanks. I have been using it to "re-add" a transparent background to icons that have been rendered over a colored background (white or gray). One thing I always do first is use the magic wand to select the area to be affected otherwise just about every pixel gets some transparency.

    One thing - can you default the color to the color of the bottom left or top left pixel? That is almost always the color I want to make transparent.

  10. I have some icons with antialiased/dithered edges that have been rendered on a white background. I don't have the original icons with the alpha channel. I need transparent edges so I can render onto a different background.

    Is there a filter around that I can use that will try to work out transparency from the colours? If not I might try to write one.

    I guess it would:

    1. Work out the pure background areas and convert them to fully transparent. This could be done by the user choosing the background colour (default to colour of top-left pixel?).

    2. For pixels next to background areas look at the adjoining (non-background area pixels) and try to work out what colour and alpha value the pixel is likely to have had to generate its actual RGB value.

    I have been doing this by hand (with reasonable results). What I have been doing *seems* mechanical enough that it could be automated. I know the results would not be perfect but they would be good enough for my needs.

  11. Hmm... is this kind of tool possible as an upgrade or separate plugin?

    [sorry I only just saw this thread]

    If you are interested I have been maintaining/porting the mods I made to PDN 3.1. (I actually originally made these changes in a 2.X version.) People keep emailing asking me for this stuff (polyline, polygon, corners, scale, rotate, skew etc) so I have ported it to 3.2 and 3.3 (not 3.31 yet).

    I don't think you can do all these things in a plug-in. But I would be pleased to learn otherwise - in which case I would start on the plugin right away.

  12. Do you mean you want to have a filter that tries to fix them automatically, or have some sort of interactive tool?

    The first would be very hard (but necessary I guess if you have a lot of pages to fix).

    The second would require some sort of mouse interaction with the image, which I don't think you can do in a PDN plug-in.

    You also can't do much in PDN as it is as the only transformations currently supported are affine.

  13. These seem to be linker errors, but why am I getting them?

    As nobody else replied I will guess that you do not have your library files directories for C++ set up correctly. Go into Visual Studio options and go to the Projects/VC++ Directories page. Select "Library files" under "Show driectories for". You must have these entries missing (as kernel32.lib is in both):

    $(VCInstallDir)lib

    $(VCInstallDir)PlatformSDK\lib

  14. When PDN loses focus it should stop doing any animation. This includes the marching ants and pulsing nubs.

    Reasons for this include that it is distracting to have an inactive program making changes on the screen (as peripheral receptors in the eye are very good at detecting movement). It is also a visual cue that the program is inactive. Also, an inactive program should not consume CPU time, for UI type activities.

×
×
  • Create New...