c - Drawing images compensation algorithm -
in old/regular environments choice render image using base drawing functions
putpixel(x, y);
(puts pixel in x/y location of canvas)lineto(x, y);
(draws line offset x/y location of canvas)moveto(x, y);
(moves offset x/y location of canvas)setpen(r, g, b, transp, size);
but slow, if lot has drawn @ once.
i willing invent compensation algorithm accords picture exemplified:
what can see predict more appropriate use lineto
instead putpixel
save iterations. in example, skips more 50% of iterations. (the red line indicates offset not drawn putpixel, part of already-drawn line) decides whether vertical or horizontal line better. hard , slow buffering if has done sin/cosin
functionions determine angle?
is there advice can receive simplify work (or if there existing similar mechanisms), before start?
what kind of crazy api processing involved apply such algorithm more compensates api calling overhead? more restrictive tricks had use during days of single-buffered 4-color cga graphics!
there's no image blitter function whatsoever can draw offscreen buffer , blit in advance compensate slow drawing routines?
in case, granting kind of pathological example, i'd first suggest trying instead merely breaking down image horizontal scanlines , consolidated putpixel
lineto
calls within single horizontal scanline. might better you're doing since it's more memory/cache-friendly, may count more reducing number of api calls.
if that's not enough , want try full-blown route, similar done in 3d/gaming industry compute efficient triangle strips meshes provide more compact rep. example: http://www.codercorner.com/strips.htm
your algorithm has similar idea, don't need bother creating adjacency structure since it's neighboring pixels (up/down/left/right). want prioritize neighbors going in same direction (ex: if previous neighbor down, favor neighbor when possible).
Comments
Post a Comment