hedgewars/uStore.pas
changeset 3341 3de60a5986e9
parent 3333 560e2766c445
child 3376 faee68a28b82
equal deleted inserted replaced
3340:96dd168b080b 3341:3de60a5986e9
  1308 end;
  1308 end;
  1309 
  1309 
  1310 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt);
  1310 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt);
  1311 var srcX, srcY, i, j, maxDest: LongInt;
  1311 var srcX, srcY, i, j, maxDest: LongInt;
  1312     srcPixels, destPixels: PLongWordArray;
  1312     srcPixels, destPixels: PLongWordArray;
       
  1313     r0, g0, b0, a0, r1, g1, b1, a1: Byte;
  1313 begin
  1314 begin
  1314 maxDest:= (dest^.pitch div 4) * dest^.h;
  1315 maxDest:= (dest^.pitch div 4) * dest^.h;
  1315 srcPixels:= src^.pixels;
  1316 srcPixels:= src^.pixels;
  1316 destPixels:= dest^.pixels;
  1317 destPixels:= dest^.pixels;
  1317 
  1318 
  1318 for srcX:= 0 to src^.w - 1 do
  1319 for srcX:= 0 to src^.w - 1 do
  1319    for srcY:= 0 to src^.h - 1 do
  1320    for srcY:= 0 to src^.h - 1 do
  1320       begin
  1321       begin
  1321       i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX;
  1322       i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX;
  1322       j:= srcY * (src^.pitch div 4) + srcX;
  1323       j:= srcY * (src^.pitch div 4) + srcX;
  1323       // basic skip of transparent pixels - cleverness would be to do true alpha
  1324       if (i < maxDest) and (srcPixels^[j] and AMask <> 0) then
  1324       if (i < maxDest) and (AMask and srcPixels^[j] <> 0) then destPixels^[i]:= srcPixels^[j];
  1325          begin
       
  1326          SDL_GetRGBA(destPixels^[i], dest^.format, @r0, @g0, @b0, @a0);
       
  1327          SDL_GetRGBA(srcPixels^[j], src^.format, @r1, @g1, @b1, @a1);
       
  1328          destPixels^[i]:= SDL_MapRGBA(dest^.format, (r0 * (255 - a1) + r1 * a1) div 255, (g0 * (255 - a1) + g1 * a1) div 255, (b0 * (255 - a1) + b1 * a1) div 255, (a0 * (255 - a1) + a1 * a1) div 255);
       
  1329          end;
  1325       end;
  1330       end;
  1326 end;
  1331 end;
  1327 
  1332 
  1328 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently
  1333 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently
  1329 var y, x, i, j: LongInt;
  1334 var y, x, i, j: LongInt;