Hi all,
Next job is to get transparency working (for transparent GIFs etc - so only on/off type transparency). Unfortunately I can't use a fast method of blitting such as memcpy because each pixel needs to be processed individually.
My idea is as follows:
1) On loading the gif, create a transparency mask (0 or 65535 for 16bpp colour) and store it with the gif itself. This will increase the mem, but hopefully the speed increase will override this.
2) Go through each pixel with the following formula which uses an add and a few bitwise operations, but NO mult or division:
D = Destination pixel (currently on screen)
S = Source pixel (from GIF)
M = Mask pixel (either 000..0 or 111...1)
Code:
/* psuedo code */
for (each pixel){
D = (S & M) + (D & (M &/ M));
}
What this does is:
(S & M)
This will AND the source pixel and the mask. If the image is transparent at this point (mask = 0) then the result will be 0, otherwise S. If the result is S, the result of the second part will always be 0.
(M &/ M)
The bitwise operator &/ is NAND. All this does is invert the mask (if it was 0 it becomes 65535, if it was 65535 it becomes 0)
(D & (M &/ M))
This will AND the dest pixel and the inverted mask. If the image is transparent at this point, then the result will be D, otherwise 0. If the result is D, the result of the first part will always be 0.
example
Code:
S=10; D=20; M=true;
(S & M) = 10;
(S & !M) = 0;
result = 10; // show source pixel
S=10; D=20; M=false;
(S & M) = 0;
(S & !M) = 20;
result = 20; // show dest pixel
Does anyone see any reason why this won't work, or see a faster way of doing it? I want to avoid all conditional statements (if...then) and all mult and div.