Author Topic: Chasing a paint bug  (Read 1046 times)

LiaoMi

  • Member
  • ****
  • Posts: 508
Re: Chasing a paint bug
« Reply #45 on: June 11, 2019, 12:46:34 AM »
Both problems should be solved now, please try again :thup:

SmoothingModeAntiAlias8x8 sounds nice, but I never saw a difference. Perhaps in Gdi+ 1.1, but how to get it to work?

8th version works great!  :thumbsup: Now we can write programs for forex exchanges  :eusa_dance:

Code: [Select]
  invoke GdipCreateFromHDC,[ps.hdc],hGraphics
  invoke GdipSetSmoothingMode,hGraphics,SmoothingModeAntiAlias8x8
  invoke GdipGraphicsClear,hGraphics,0ffffffffh
  invoke GdipDrawEllipseI,hGraphics,hPen,100,100,200,200
  invoke GdipDeleteGraphics,hGraphics


You are right there are problems with the version ... But who in our time uses the old version of Gdiplus? I'll try to use a newer version .. Below you can download an interesting example of a clock  :biggrin:

Quote
SmoothingMode   TYPEDEF DWORD ;enum

;SmoothingMode   UNION DEFALIGNMASM
   SmoothingModeInvalid   EQU <QualityModeInvalid >
   SmoothingModeDefault   EQU <QualityModeDefault >
   SmoothingModeHighSpeed   EQU <QualityModeLow >
   SmoothingModeHighQuality   EQU <QualityModeHigh >
   SmoothingModeNone   EQU <0H>
   SmoothingModeAntiAlias   EQU <01H>
IF ( GDIPVER GE 00110h)
   SmoothingModeAntiAlias8x4   EQU <SmoothingModeAntiAlias >
   SmoothingModeAntiAlias8x8   EQU <02H>   ;(GDIPVER >= 0x0110)
ENDIF
;SmoothingMode      ENDS

jj2007

  • Member
  • *****
  • Posts: 9513
  • Assembler is fun ;-)
    • MasmBasic
Re: Chasing a paint bug
« Reply #46 on: June 11, 2019, 01:54:17 AM »
Some time ago I tried to use a newer gdi+ version but no luck. With a proper manifest, it should load. However, apparently nobody ever succeeded in making it work, see e.g. Is SmoothingModeAntiAlias8x8 available? (yes it is, see replies further down)
« Last Edit: June 11, 2019, 08:03:45 AM by jj2007 »

LiaoMi

  • Member
  • ****
  • Posts: 508
Re: Chasing a paint bug
« Reply #47 on: June 11, 2019, 06:17:59 AM »
Some time ago I tried to use a newer gdi+ version but no luck. With a proper manifest, it should load. However, apparently nobody ever succeeded in making it work, see e.g. Is SmoothingModeAntiAlias8x8 available?

P.S.: GOTCHA! See attachment. Press Q repeatedly to see various smoothing modes. There is a tiny difference between 8x4 and 8x8, visible in particular in the lower right corner control  :tongue:

 :biggrin: You revealed a secret!  :thumbsup: The difference is almost invisible, I also made an example ...

Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
  <asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>True/PM</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>
 <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32"
      name="Microsoft.Windows.GdiPlus"
      processorArchitecture="*"
      version="1.1.0.0"
      publicKeyToken="6595b64144ccf1df"
      language="*"/>
    </dependentAssembly>
  </dependency>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates app support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates app support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--The ID below indicates app support for Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--The ID below indicates app support for Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--The ID below indicates app support for Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>

+

Code: [Select]
GDIPVER equ 0x0110

    include C:\masm64\VS2017\include_x86_x64\translate32.inc
    include C:\masm64\sdkrc100\um\windows.inc
    include C:\masm64\sdkrc100\um\gdiplusinit.inc
    include C:\masm64\sdkrc100\um\gdiplusflat.inc
    include C:\masm64\sdkrc100\um\gdiplusenums.inc
    include C:\masm64\sdkrc100\um\CommCtrl.inc
 
includelib gdiplus.lib
includelib user32.lib
includelib kernel32.lib
includelib ComCtl32.lib

+

Code: [Select]
        invoke GdipSetSmoothingMode, hGraphics, SmoothingModeAntiAlias8x8;SmoothingModeAntiAlias8x8;SmoothingModeHighQuality
    invoke GdipSetInterpolationMode,hGraphics,InterpolationModeHighQualityBicubic

In my case, the difference is completely invisible, where api dont return errors ... The project can be downloaded below and as a result, we can achieve perfect smoothing with tricks only, one of which is a custom anti-aliasing option, which is not suitable due to slow speed. I do not know other tricks, but I will finish the custom version  :skrewy:


hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6389
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Chasing a paint bug
« Reply #48 on: June 11, 2019, 07:59:48 AM »
That is one of the first good clocks I have seen.  :thumbsup:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 9513
  • Assembler is fun ;-)
    • MasmBasic
Re: Chasing a paint bug
« Reply #49 on: June 11, 2019, 08:05:40 AM »
Just for fun, I added another test: Press I for interpolation mode, Q for quality, and H for haha
When going from 8x4 to 8x8, watch the upper part of the blue dot in the upper left corner control.
Btw Gdi+ version 1.1.0.0 gets loaded on Win7-64 independently of the manifest.

LiaoMi

  • Member
  • ****
  • Posts: 508
Re: Chasing a paint bug
« Reply #50 on: June 11, 2019, 09:02:50 AM »
 :biggrin: :biggrin: :biggrin:

I'm going crazy about the smoothing technique in GDI, I present to your attention another technique ..

Xiaolin Wu's line algorithm - https://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm
Anti-aliased Line | Xiaolin Wu’s algorithm https://www.geeksforgeeks.org/anti-aliased-line-xiaolin-wus-algorithm/ (There are many other algorithms on the site with examples and descriptions - the site is very good)

lib files for project, no dependency on external libraries ...
SFML 2.5.1 https://www.sfml-dev.org/download/sfml/2.5.1/

The example demonstrates the line algorithm, but besides that I attached an algorithm for circles (Xiaolin Wu's ANTI-ALIASED CIRCLE GENERATION.pdf) ... The release folder contains the executable file, to draw the lines you need to click on the mouse.

Xiaolin Wu's ANTI-ALIASED CIRCLE GENERATION - https://www.solidfiles.com/v/gnwB4PnvKBngV

Quote
That is one of the first good clocks I have seen.  :thumbsup:
:biggrin:  :thup:

jj2007

  • Member
  • *****
  • Posts: 9513
  • Assembler is fun ;-)
    • MasmBasic

LiaoMi

  • Member
  • ****
  • Posts: 508
Re: Chasing a paint bug
« Reply #52 on: June 11, 2019, 09:26:46 PM »
It's time to look at the source - 40 lines of code :smiley:

 :thumbsup: looks great!


We continue the epic with anti-aliasing  :tongue:

NVIDIA DLSS AI-Powered Anti-Aliasing In Action For Great Visuals And Performance https://www.youtube.com/watch?v=x-mVK3mj_xk

 :arrow_right: There is an AI-example (cuda neural network.zip) on the forum which should define letters, what if instead of letters, use limited geometric space ?! For use in adjusting the smoothing pattern ...  :icon_idea:

DLSS, Is it Upscaling, Super Sampling, or Anti Aliasing?? - https://www.reddit.com/r/nvidia/comments/9a55pk/dlss_is_it_upscaling_super_sampling_or_anti/

NVIDIA researchers Marco Salvi and Anjul Patney trained a neural network to recognize these artifacts and replace those pixels with smooth anti-aliased pixels. The AI-based technology produces sharper images than existing algorithms.

The left inset shows an aliased image that is jaggy and pixelated. NVIDIA’s AI anti-aliasing algorithm produced the larger image and inset on the right by learning the mapping from aliased to anti-aliased images. Image courtesy of Epic Games.

Nvidia DLSS: An Early Investigation Deep Learning Super-Sampling - https://www.techspot.com/article/1712-nvidia-dlss/

Nvidia DLSS analysis: how AI tech can make PC games run 40 per cent faster - https://www.eurogamer.net/articles/digitalfoundry-2018-dlss-turing-tech-analysis



 :arrow_right: The clock example can be combined with the example of Xiaolin.zip, in this way we can compare the implementation of the clock in different ways ... I think a very interesting idea!  :icon_idea:

Xiaolin Wu circle algorithm renders circle with holes inside https://stackoverflow.com/questions/54594822/xiaolin-wu-circle-algorithm-renders-circle-with-holes-inside


Anti-Aliased Curve Algorithms (Java Source Code) - http://www.landkey.net/d/antialiased/wu4_RF/
1. "Wu-style" circle anti-aliased algorithm. Source. Demo.
2. "Linear-constraint" circle algoritm. Source. Demo.
3. Implicit curve anti-aliased algorithm. Draft. Source. Concept-Demo.

Fast, Antialiased Circles and Ellipses from Xiaolin Wu’s concepts - https://yellowsplash.wordpress.com/2009/10/23/fast-antialiased-circles-and-ellipses-from-xiaolin-wus-concepts/


C# implementation Bresenham and Xiaolin wu's algorithms - https://github.com/nejcgalof/Rasterization

LiaoMi

  • Member
  • ****
  • Posts: 508
Re: Chasing a paint bug
« Reply #53 on: June 12, 2019, 12:52:28 AM »
Just for fun, I added another test: Press I for interpolation mode, Q for quality, and H for haha
When going from 8x4 to 8x8, watch the upper part of the blue dot in the upper left corner control.
Btw Gdi+ version 1.1.0.0 gets loaded on Win7-64 independently of the manifest.

Hi jj2007,

everything is clear with anti-aliasing now ... now interpolation method .. it seems to me that I did not correctly use the interpolation technique, description from the documentation:

The InterpolationMode enumeration specifies the algorithm that is used when images are scaled or rotated. This enumeration is used by the Graphics::GetInterpolationMode and Graphics::SetInterpolationMode methods of the Graphics class.
InterpolationMode Enumeration https://docs.microsoft.com/en-us/windows/desktop/api/gdiplusenums/ne-gdiplusenums-interpolationmode

PlotMyDataV9.zip - I tested the interpolation method and could not see the difference in the picture, when I press the letter "I" and watch the clouds change, nothing happens ... this method depends on the implementation. The example (GDIPlus_GdipSetInterpolationMode.zip) on page three correctly demonstrates the interpolation technique. If you read a picture from a resource file, and then you change the size of the picture, then at this moment the interpolation method should work. I think the clouds should be smoothed, it all depends on how you redraw each graphic, whether vector graphics are processed with a picture or separately. Two options come to mind, the method should be applied to the image, or to the finished drawn graphics, this is clearly logically incorrect. Therefore, in your case, the method can only be applied to images, where for vector graphics it is necessary to create a custom GDI method, otherwise there is no size transformation. Maybe I still dont know something about the interpolation method, but my thoughts come to this conclusion.


 :arrow_right: Another opportunity for a new kind of graphics ..  :icon_idea: -  theoretically, the interpolation method can be used to plot the time frequency diagrams

Time–frequency analysis - https://en.wikipedia.org/wiki/Time%E2%80%93frequency_analysis







Interpolation - https://en.wikipedia.org/wiki/Interpolation







daydreamer

  • Member
  • ****
  • Posts: 830
  • watch Chebyshev on the backside of the Moon
Re: Chasing a paint bug
« Reply #54 on: June 12, 2019, 01:53:19 AM »
Very interesting thread,so maybe you could draw faster and rougher and apply hardware accelerated supersmooth antialias?
Also has some kind of paintbug,maybe handle all kinds of messages and first repaint when dragging windows
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*

LiaoMi

  • Member
  • ****
  • Posts: 508
Re: Chasing a paint bug
« Reply #55 on: June 21, 2019, 03:15:46 AM »
Hi,

going through all the smoothing options, here are the main techniques that I discovered:

1. Neural network based anti-aliasing - the main goal is speed optimization while improving quality
2. Manual rendering algorithms to optimize the smoothing, the pixels are drawn by hand.
3. A technique that uses image scaling, partially used in neural networks, the main disadvantage is massive memory usage and delay in drawing. For quick work, a compromise is required between the combination of the neural network and the size of the picture.
4. Windows built-in methods
5. Combination of several methods at once.

A couple more implementations:
Scanline edge-flag algorithm for antialiasing - http://mlab.uiah.fi/~kkallio/antialiasing/
Intel AVX Realization of Lanczos Interpolation in Intel IPP 2D Resize Transform - https://software.intel.com/sites/default/files/m/d/4/1/d/8/Intel_AVX_Realization_of_Lanczos_Interpolation_in_Intel_IPP_2D_Resize_Transform_WP.pdf

I decided to try "Lanczos Interpolation" method, how can I effectively replace the _mm256_permute2_ps instructions ?!

XOP instruction set
VPERMIL2PS   Permute Two-Source Single-Precision Floating-Point
Code: [Select]
Opcode/Instruction - VEX.NDS.256.66.0F3A.W1 48 /r /is4

VPERMIL2PS ymm1, ymm2, ymm3,ymm4/m256, imz2

Description - Permute single-precision floatingpoint values in ymm2 and ymm3 using controls from ymm4/mem,
the results are stored in ymm1 with selective zero-match controls.

Recent Intel(R) AVX Architectural Changes - Removed: VPERMIL2PS and VPERMIL2PD The compiler does not support the VPERMIL2PD and VPERMIL2PS instructions in the assembler.

https://software.intel.com/en-us/forums/intel-isa-extensions/topic/283576
IIRC vpermil2ps (_mm256_permute2_ps) was removed from the AVX specs at the same time than FMA4 was replaced by FMA3, vpermil2ps is now part of AMD's XOP (to be featured inupcoming Bulldozer products along FMA4), AFAIK no Intel CPU has been announced with support for it, though it looks like you want to shift values between the 2 128-bit lanes and I'm afraid there isn't any fast option available in standard AVX, yet