Paint Colours Half Pixel Offsets
Andy S (2979) 504 posts |
I’ve been looking over how Paint draws the Colours window and found a slight oddity: x = xpos + (1 << x_eig)/2; y = ypos - coloursize + (1 << y_eig)/2; It sits in a loop, generating xpos and ypos to position each colour button in the grid. The question is why someone saw the need to then add a half pixel’s worth of OS units, (1 << eig)/2, to each of the coordinates? I tried commenting the adjustment out and the colours window looks pixel for pixel identical, under Mode 15, to how it did before. Can anyone think of a situation where it would make a difference? I thought the OS will just always round it down to the nearest whole pixel. x and y are reassigned every iteration so the adjustment never accumulates. The only other place the adjusted coordinates get used is they’re passed to OS_SpriteOp 52 to draw the ECFs onto the colours window as well. The ECF sprites may get scaled, but the x and y position shouldn’t be relevant there, should it? |
Jeffrey Lee (213) 6048 posts |
I can’t think of any reason why a half-pixel offset should be required. Maybe it’s just some leftovers from a prototype version of the code. |
Andy S (2979) 504 posts |
Thanks for confirming what I’m thinking. One thing I thought of was for Small Colours, coloursize gets chopped in half. Which in some modes, would not be a whole number of pixels. For example in Mode 13, it would be 60 OS units / 2 = 30 OS units = 7.5 pixels. So this may have been an early attempt to round that 0.5 up to a whole pixel (Edit: That wouldn’t ever work, as it’s just translating, not scaling!). AFAICT such rounding is no longer necessary because there’s already code higher up that seems to always round coloursize up to the nearest whole number of pixels (took me a little while to figure out exactly what it was doing): if (x_eig > y_eig) max_eig = x_eig; else max_eig = y_eig; coloursize = (coloursize - 1 >> max_eig) + 1 << max_eig; So, yeah maybe it was just old code. |
Chris Evans (457) 1614 posts |
Probably rubbish, but I wonder if the code was also used in the sprite rendering part of PDumpers! I have a vague recollection of reading that offsets were used for print rendering. |