aphillips

Members
  • Content Count

    49
  • Joined

  • Last visited

Community Reputation

0

About aphillips

  • Birthday 01/01/1970

Profile Information

  • Location
    Sydney

Contact Methods

  • Website URL
    http://hexedit.com

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Rick, Thanks for noticing the performance problem. I just got home and did some tests and immediately found that OnSetRenderInfo is being called 5 times when the dialog starts up. (Some of the control init is firing events that are causing FinishTokenUpdate() to be called.) I'll fix that and perhaps add some other performance tweaks.
  2. 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. 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.
  3. Thanks. The plugin is there now in the thread "new Clear Background plugin (was infer transprency)" The first posts I made did not appear, I guess because I attached a DLL not a ZIP file.
  4. 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. Image before effect applied. Clear Background effect using By Color option Clear Background effect using By Distance option ClearBackgroundPlugin.zip
  5. > 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.)
  6. I have written and tested this plugin now. How do I post it?
  7. 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).
  8. Great, I like your plugin. I really want to create a different (but in some ways similar) one. Any chance of seeing the source code?
  9. 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++.)
  10. 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?
  11. 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 ( that probably originally had no transparency 3. Use the color picker to get the RGBA value of ( 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.
  12. 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!
  13. 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.
  14. > You're asking for a plugin... Actually I was more saying this is a plugin I am going to create (unless someone else has already done it which I very much doubt), and here is how I would do it. And does it make sense?