Note that there are some explanatory texts on larger screens.

plurals
  1. POanti-aliased pixel rendering
    primarykey
    data
    text
    <p>I'm trying to implement anti-aliased pixel rendering. My basic idea is to render 4 pixels instead of 1, and give each "real" pixel a weight based on its distance to the "virtual" pixel:</p> <pre><code>void put_aa_pixel(double x, double y) { int x0 = int(x); int x1 = x0 + 1; int y0 = int(y); int y1 = y0 + 1; double weight_x1 = x - x0; double weight_x0 = 1 - weight_x1; double weight_y1 = y - y0; double weight_y0 = 1 - weight_x1; put_pixel(x0, y0, int((weight_x0 * weight_y0) * 255)); put_pixel(x1, y0, int((weight_x1 * weight_y0) * 255)); put_pixel(x0, y1, int((weight_x0 * weight_y1) * 255)); put_pixel(x1, y1, int((weight_x1 * weight_y1) * 255)); } </code></pre> <p>Multiplying the x and y weights gives me the overlapping area of the virtual pixel inside each real pixel. I naively assumed this would give me a perfect anti-aliasing effect, but the moving pixels inside my test program just display an aweful flicker. It looks much worse then simple pixels without any anti-aliasing.</p> <p>However, when I switch from multiplication to addition, it looks much better:</p> <pre><code> put_pixel(x0, y0, int((weight_x0 + weight_y0) * 127.5)); put_pixel(x1, y0, int((weight_x1 + weight_y0) * 127.5)); put_pixel(x0, y1, int((weight_x0 + weight_y1) * 127.5)); put_pixel(x1, y1, int((weight_x1 + weight_y1) * 127.5)); </code></pre> <p>Adding the weights doesn't seem to have any geometric significance. So why does this work better? What's wrong with the first version? And is there an even better approach?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload