Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. Anti-Aliasing routine needed

Anti-Aliasing routine needed

Scheduled Pinned Locked Moved Graphics
graphicscomhelptutorial
7 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Force Code
    wrote on last edited by
    #1

    I need a routine that, given a target bitmap and a mask, will smooth the contours of the portion of the target indicated by the mask, e.g. "AntiAlias(HBITMAP hbmp, HBITMAP mask))" I phrase it this way, because the little I understand about anti-aliasing, it needs to know the target background to achieve optimal effect. The mask could be a piece of text for example, (e.g for font smoothing), or some other shape on a monochrome bitmap, corresponding to the item on the target bitmap whose outline is to be anti-aliased. Supposedly, the anti-aliasing capabilities of The AGG Project[^] are the best, but their package looks very complex. However something based on their algorithms would be good. There is also a Code Project article[^] on anti-aliasing as well but it concerns straight lines exclusively. Thanks for any help.

    C 1 Reply Last reply
    0
    • F Force Code

      I need a routine that, given a target bitmap and a mask, will smooth the contours of the portion of the target indicated by the mask, e.g. "AntiAlias(HBITMAP hbmp, HBITMAP mask))" I phrase it this way, because the little I understand about anti-aliasing, it needs to know the target background to achieve optimal effect. The mask could be a piece of text for example, (e.g for font smoothing), or some other shape on a monochrome bitmap, corresponding to the item on the target bitmap whose outline is to be anti-aliased. Supposedly, the anti-aliasing capabilities of The AGG Project[^] are the best, but their package looks very complex. However something based on their algorithms would be good. There is also a Code Project article[^] on anti-aliasing as well but it concerns straight lines exclusively. Thanks for any help.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Looks to me like you're asking for a blur filter, because you want to 'antialias' a bitmap, when the method really works when you're in the process of drawing lines. If you read my image prcoessing articles, I talk about bilinear and bicubic filters there. Basically, what antialiasing does, is it says for an edge pixel, I really want to only draw on x% of this pixel, but as that's not possible, I merge the color of the underlying pixel with the color I want to draw, so it's x% the color I want to draw, and 100-x% the color that it was before. The issue you will have is working out both which areas you're antialiasing ( assume all the pixels that differ ), and how much they need to be antialiased, which is probably impossible to work out. Some sort of general algorithm that does a good enough job to improve your image is probably fairly easy, however.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      F 1 Reply Last reply
      0
      • C Christian Graus

        Looks to me like you're asking for a blur filter, because you want to 'antialias' a bitmap, when the method really works when you're in the process of drawing lines. If you read my image prcoessing articles, I talk about bilinear and bicubic filters there. Basically, what antialiasing does, is it says for an edge pixel, I really want to only draw on x% of this pixel, but as that's not possible, I merge the color of the underlying pixel with the color I want to draw, so it's x% the color I want to draw, and 100-x% the color that it was before. The issue you will have is working out both which areas you're antialiasing ( assume all the pixels that differ ), and how much they need to be antialiased, which is probably impossible to work out. Some sort of general algorithm that does a good enough job to improve your image is probably fairly easy, however.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        F Offline
        F Offline
        Force Code
        wrote on last edited by
        #3

        "Looks to me like you're asking for a blur filter, because you want to 'antialias' a bitmap, when the method really works when you're in the process of drawing lines." Say you have some text or other shape on a monochrome bitmap. Are you saying its not feasible are hasn't been conceived of for an algorithm to examine the contour (i.e. border) of this shape and produce a smooth (anti-aliased) version as output, on a target bitmap? Or are you saying this is what a "blur filter" would achieve? OK here's my application: bitblt-ing textured text to the printer. The resolution of the screen doesn't come close to matching the printer resolution, so I have to smooth it out somehow. I'm using NT, actually, not a newer windows variant. Actually, the texture on the text is rendered correctly on the printer, but the outline of the font is jagged.

        C 1 Reply Last reply
        0
        • F Force Code

          "Looks to me like you're asking for a blur filter, because you want to 'antialias' a bitmap, when the method really works when you're in the process of drawing lines." Say you have some text or other shape on a monochrome bitmap. Are you saying its not feasible are hasn't been conceived of for an algorithm to examine the contour (i.e. border) of this shape and produce a smooth (anti-aliased) version as output, on a target bitmap? Or are you saying this is what a "blur filter" would achieve? OK here's my application: bitblt-ing textured text to the printer. The resolution of the screen doesn't come close to matching the printer resolution, so I have to smooth it out somehow. I'm using NT, actually, not a newer windows variant. Actually, the texture on the text is rendered correctly on the printer, but the outline of the font is jagged.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Force Code wrote:

          Are you saying its not feasible are hasn't been conceived of for an algorithm to examine the contour (i.e. border) of this shape and produce a smooth (anti-aliased) version as output, on a target bitmap?

          No, I"m saying it's bloody hard work, and if you also have the bitmap WITHOUT the text, to provide the background, you'll get a better result for less hassle if you just rewrite the text with anti aliasing.

          Force Code wrote:

          Or are you saying this is what a "blur filter" would achieve?

          A blur filter will recolor all pixels based on the surrounding colours, which will in effect do what anti aliasing does, but blindly and everywhere. Depending on the nature of the image, a gaussian blur, or similar, may produce an improved result. It may also make it worse :-) Is the text the only black area on the bitmap ? Do you know where it is ? If you know the area to look, or can identify text, then you can write some code to blur the edges, pretty trivially, which will not be quite what you're looknig for, but it's what I had in mind when I said you could write something easily that won't be 100% what you want, but could give enough of the effect to solve your issue.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          F 1 Reply Last reply
          0
          • C Christian Graus

            Force Code wrote:

            Are you saying its not feasible are hasn't been conceived of for an algorithm to examine the contour (i.e. border) of this shape and produce a smooth (anti-aliased) version as output, on a target bitmap?

            No, I"m saying it's bloody hard work, and if you also have the bitmap WITHOUT the text, to provide the background, you'll get a better result for less hassle if you just rewrite the text with anti aliasing.

            Force Code wrote:

            Or are you saying this is what a "blur filter" would achieve?

            A blur filter will recolor all pixels based on the surrounding colours, which will in effect do what anti aliasing does, but blindly and everywhere. Depending on the nature of the image, a gaussian blur, or similar, may produce an improved result. It may also make it worse :-) Is the text the only black area on the bitmap ? Do you know where it is ? If you know the area to look, or can identify text, then you can write some code to blur the edges, pretty trivially, which will not be quite what you're looknig for, but it's what I had in mind when I said you could write something easily that won't be 100% what you want, but could give enough of the effect to solve your issue.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            F Offline
            F Offline
            Force Code
            wrote on last edited by
            #5

            As it turns out the AGG project does have some code that I can pretty much paste directly into my project. Actually, its a five hundred line Hello World program[^] that renders text utilizing their Anti-Aliasing process.

            F 1 Reply Last reply
            0
            • F Force Code

              As it turns out the AGG project does have some code that I can pretty much paste directly into my project. Actually, its a five hundred line Hello World program[^] that renders text utilizing their Anti-Aliasing process.

              F Offline
              F Offline
              Force Code
              wrote on last edited by
              #6

              Force Code wrote:

              As it turns out the AGG project does have some code that I can pretty much paste directly into my project. Actually, its a five hundred line Hello World program[^] that renders text utilizing their Anti-Aliasing process.

              I copied this into a test program, compiled it, and it did nothing. So, I replaced their "render_text(ras, ren, sl, gl, 10, 100, "Hello, World!")" with a straight win32 TextOut, and got impeccably rendered "Hello World" output indistinguishable from what AGG supposedly produces. But then, I noticed in their code they were calling the Win32 CreateFont with ANTIALIASED_QUALITY specified. So, I have no idea what AGG achieves on its own. As it turns out, ANTIALIASED_QUALITY was all I needed in my own project to begin with. I was utilizing someone else's code in which CreateFont was called with DEFAULT_QUALITY. So anyway, nevermind.

              F 1 Reply Last reply
              0
              • F Force Code

                Force Code wrote:

                As it turns out the AGG project does have some code that I can pretty much paste directly into my project. Actually, its a five hundred line Hello World program[^] that renders text utilizing their Anti-Aliasing process.

                I copied this into a test program, compiled it, and it did nothing. So, I replaced their "render_text(ras, ren, sl, gl, 10, 100, "Hello, World!")" with a straight win32 TextOut, and got impeccably rendered "Hello World" output indistinguishable from what AGG supposedly produces. But then, I noticed in their code they were calling the Win32 CreateFont with ANTIALIASED_QUALITY specified. So, I have no idea what AGG achieves on its own. As it turns out, ANTIALIASED_QUALITY was all I needed in my own project to begin with. I was utilizing someone else's code in which CreateFont was called with DEFAULT_QUALITY. So anyway, nevermind.

                F Offline
                F Offline
                Force Code
                wrote on last edited by
                #7

                Force Code wrote:

                I copied this into a test program, compiled it, and it did nothing. So, I replaced their "render_text(ras, ren, sl, gl, 10, 100, "Hello, World!")" with a straight win32 TextOut, and got impeccably rendered "Hello World" output indistinguishable from what AGG supposedly produces. But then, I noticed in their code they were calling the Win32 CreateFont with ANTIALIASED_QUALITY specified. So, I have no idea what AGG achieves on its own. As it turns out, ANTIALIASED_QUALITY was all I needed in my own project to begin with. I was utilizing someone else's code in which CreateFont was called with DEFAULT_QUALITY.

                Here's an interesting epilogue to this story. I recently downloaded GDI+ which I haven't used before. As I said above, just using the straight GDI CreateFont (or actually CreateFontIndirect) and specifying ANTIALIASED_QUALITY, gives you as good text quality for large fonts as could possibly be imagined. So I was curious about the capabilities of GDI+. With it, you call, graphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit), which gives you the highest quality fonts available through GDI+ for non XP systems (I am using Win 2000.) So I tried it and amazingly, the quality was *much* worse than with straight GDI. It looked like it wasn't anti-aliased at all, until you notice that yeah, it is a *little* bit smoother (This was on 72 point Times New Roman; bold, italic). This is very strange, since GDI+ itself uses over 180 GDI functions. There is one higher quality font level available in GDI+, only for XP and Win Server 2003 - TextRenderingHintClearTypeGridFit. It supposedly uses revolutionary "ClearType" technology. I think its clear that what happened is that Microsoft just downgraded font rendering for everything prior to XP, and made their old anti-aliasing algorithm only available for XP or higher, and gave it a new name - "ClearType". Maybe this has been observed before.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups