From: Wouter V. <wou...@pi...> - 2003-04-29 17:23:25
|
On Tue, 29 Apr 2003, Maarten ter Huurne wrote: > Hi, > > I want to improve the handling of SCREEN6 border and sprite pixels. On SDLLo, > two adjecent narrow pixels are blended into a single wide pixel to cope with > the low resolution. Wouter created a nice blending method that I want to > re-use. > > Currently the blending method is duplicated in CharacterConverter and > BitmapConverter. Since SpriteConverter and SDLRenderer need it as well, it is > a good idea to isolate the blending method. The blending method depends on a > blending mask which is calculated once at initialisation. Even though that > state is very small, I decided to make a class especially for Blending. I did > something similar before with DisplayMode and that worked out fine. Sounds like a good idea. The algorithm is small but, as you describe below, not trivial. So it certainly makes sense to put it in a seperate class. > It took me a while to figure out how the algorithm worked, but once understood > I think it's nice and efficient. However, it cannot handle the case where the > most significant bit of a pixel is used: the result of the addition "colour1 > + colour2" is clipped before it is divided by 2. When the pixel format is > 24bpp or 15bpp with the highest bits unused, this is not a problem. However, > on big endian RGBA could have the lowest bits unused and the highest used, > and 16bpp has all bits used. So the current blend implementation can fail for > some pixel formats. > > I tried to correct this problem without changing the algorithm too much. I > think I succeeded, but this is complex code, so I would like a second > opinion. Wouter (or anyone else interested), please review the code. The > Blender class is attached. Looks ok to me. Wouter |