' Put Flipped! v1.0 ' (C) 2008 Innova and Kristopher Windsor ' ' Fast Put() Alternative with Horizontal / Vertical Flipping - freebasic.net ' https://www.freebasic.net/forum/viewtopic.php?t=11374 #ifndef __PUTFLIPPED__ #define __PUTFLIPPED__ #include once "fbgfx.bi" ' Const true = -1 ' Const false = 0 Sub putflipped ( _ Byval source As fb.image Ptr, _ Byval xpos As Integer, Byval ypos As Integer, _ Byval xflip As Integer = FALSE, Byval yflip As Integer = FALSE) Static As Integer screenx, screeny Dim As Integer xl, yl, xstart, ystart, xend, yend, ypos_original, pitch, bpp, xstep, ystep Dim As fb.image Ptr sptr If screenx = 0 Or screeny = 0 Then Screeninfo(screenx, screeny) xstart = 0 xend = source -> Width - 1 If xflip Then xstep = -1 xpos += xend - xstart If xpos > screenx - 1 Then xstart += xpos - screenx + 1: xpos = screenx - 1 If xpos + xstart - xend < 0 Then xend = xpos + xstart Else xstep = 1 If xpos < 0 Then xstart -= xpos: xpos = 0 If xpos + xend - xstart > screenx - 1 Then xend = xstart - xpos + screenx - 1 End If ystart = 0 yend = source -> height - 1 If yflip Then ystep = -1 ypos += yend - ystart If ypos > screeny - 1 Then ystart += ypos - screeny + 1: ypos = screeny - 1 If ypos + ystart - yend < 0 Then yend = ypos + ystart Else ystep = 1 If ypos < 0 Then ystart -= ypos: ypos = 0 If ypos + yend - ystart > screeny - 1 Then yend = ystart - ypos + screeny - 1 End If pitch = source -> pitch bpp = source -> bpp - 1 If bpp = 3 Then bpp = 2 sptr = Screenptr 'reset ypos every x-loop; (screenx shl bpp) is used here instead of in the loop for optimization ypos_original = ypos * (screenx Shl bpp) ystep *= (screenx Shl bpp) 'more optimization (removing this math from the loops) ystart *= pitch yend *= pitch For xl = xstart To xend ypos = ypos_original For yl = ystart To yend Step pitch Dim As Integer c = *cast(Integer Ptr, cast(Ubyte Ptr, source + 1) + xl Shl bpp + yl) If (c And &H00FFFFFF) <> &H00FF00FF Then *cast(Integer Ptr, cast(Ubyte Ptr, sptr) + xpos Shl bpp + ypos) = c End If ypos += ystep Next yl xpos += xstep Next xl End Sub #endif