#ifndef __IMAGESCALE__ #define __IMAGESCALE__ #include "fbgfx.bi" Using fb function ImageScale(byval s as fb.Image ptr, byval w as integer, byval h as integer) as fb.Image ptr ' no source image if s = 0 then return 0 ' source with or height legal ? if s->width < 1 then return 0 if s->height < 1 then return 0 ' target min size ok ? if w < 2 then w=1 if h < 2 then h=1 ' create new scaled image dim as fb.Image ptr t = ImageCreate(w, h, RGB(0, 0, 0)) ' x and y steps in fixed point 12:20 dim as integer xs = &H100000 * (s->width / t->width ) dim as integer ys = &H100000 * (s->height / t->height) dim as integer x, y, sy, ty, tx #macro SCALELOOP() for ty = 0 to t->height - 1 ' address of the row src = ps + (sy shr 20) * sp x = 0 ' first column for tx = 0 to t->Width - 1 *pt = src[x shr 20] pt += 1 ' next column x += xs ' add xstep value next pt += tp ' next row sy += ys ' add ystep value next #endmacro select case as const s->bpp case 1 ' color palette dim as ubyte ptr ps = cptr(ubyte ptr, s) + 32 dim as ubyte ptr pt = cptr(ubyte ptr, t) + 32 dim as ubyte ptr src dim as uinteger sp = s->pitch dim as uinteger tp = t->pitch - t->width SCALELOOP() case 2 ' 15/16 bit dim as ushort ptr ps = cptr(ushort ptr, s) + 16 dim as ushort ptr pt = cptr(ushort ptr, t) + 16 dim as ushort ptr src dim as uinteger sp = (s->pitch shr 1) dim as uinteger tp = (t->pitch shr 1) - t->width SCALELOOP() case 4 ' 24/32 bit dim as ulong ptr ps = cptr(uinteger ptr, s) + 8 dim as ulong ptr pt = cptr(uinteger ptr, t) + 8 dim as ulong ptr src dim as uinteger sp = (s->pitch shr 2) dim as uinteger tp = (t->pitch shr 2) - t->width SCALELOOP() end Select #undef SCALELOOP return t End Function #endif