gfxgfxFreeBASIC Games Directory Forumgfxgfx
gfx gfx
gfx
Welcome, Guest. Please login or register. May 25, 2013, 12:47:43 AM

Login with username, password and session length
11.5.2013 - Added a webpage for the latest FBGD competition.

13.3.2013 - Members registrations temporary disabled. For all membership requests, please email me: lachie13@yahoo.com

30.11.2012 - The ninth issue of BASIC Gaming is out! Read it here: http://games.freebasic.net/forum/index.php?topic=560.0

22.11.2012 - Be sure to check our currently running annual FBGD game making competition. This year's theme is SEASONS OF THE YEAR, 300 $ first place prize, and the competition runs till 18th of February. Link: http://games.freebasic.net/forum/index.php?topic=559.0
gfx
gfx
*
gfxgfx
gfxgfx gfxgfx
gfxgfx Home Help Search Login Register   gfxgfx
gfx gfx
gfx
Pages: [1]
Print
Author Topic: Scale2x by Mysoft.  (Read 2837 times)
Lachie Dazdarian
Double dipper
Administrator
Forum Sage
*****
Gender: Male
Posts: 1195


lachie13
View Profile WWW Email
« on: January 05, 2008, 09:24:28 PM »

It's just some code I rescently mooched from Mysoft. It works great on my crummy PC (48 FPS in 32-bit mode, scaling from 320,240 to 640,480). Supports 8-bit, 16-bit and 32-bit mode.

#define SC2X_X 320
#define SC2X_Y 240
#define MYBPP 32
#include "fbgfx.bi"
Using FB

const fpslimit = 160
 
#if MYBPP = 8
declare sub scale2x_8(PTORG as any ptr, PTDST as any ptr)
 
sub scale2x_8(PTORG as any ptr, PTDST as any ptr)
  static as integer Y 
  Y = SC2X_Y
 
  const PILI = SC2X_X
  const OPI = 1
  const TPI = OPI*2
  const PILIS = PILI-1
  const OLIS = PILI-1
  const OLIA = PILI+1
  const TLISS = (PILI*2)-2
  const TLIS = (PILI*2)-1
  const TLI = (PILI*2)
  const TLIA = (PILI*2)+1
 
  ' **** Inicio do código asm fixo para dobrar 256x192 ****
  asm       
    mov ESI,[PTORG]     ' ESI = Ponteiro de Origem
    mov EDI,[PTDST]     ' EDI = Ponteiro de Destino
    lodsb               ' \
    stosb               ' | Copia e aumenta
    stosb               ' | o primeiro Pixel
    mov [EDI+TLISS],AL   ' | (borda)
    mov [EDI+TLIS],AL   ' /
    ' *************** Primeira Linha (borda) **************
    mov ECX,PILIS         ' (255 pixels na linha (256-borda))
    _FLNEXTPOINT_:      ' Label de Próximo Pixel
    lodsb                ' Carrega Pixel central (E)
    mov BL,[ESI]        ' Carrega Pixel Superior (B)
    mov DL,[ESI]        ' Carrega Pixel Direito (F)
    cmp BL,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _FLBEHODEF_      ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],DL      ' | Compara igualgade dos pixels D & F
    je _FLBEHODEF_      ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp BL,[ESI-TPI]      ' Compara Pixels B & D       \
    je _FLNOCHGE0_      ' iguais entom E0 = D        | iif(B=D,D,E)
    mov BL,AL           ' diferentes entom E0 = E    |
    _FLNOCHGE0_:        ' Label Qndo Iguais (ignora) /
    mov [EDI],BL        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI],DL        ' Compara Pixels B & F       \
    je _FLNOCHGE1_      ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov DL,AL           ' Diferentes? entom E1 = E   |
    _FLNOCHGE1_:        ' Label qndo iguais (ignora) /
    mov [EDI+OPI],DL      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov BL,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov DL,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp BL,DL           ' Compara Pixels H & D       \
    je _FLNOCHGE2_      ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov BL,AL           ' Diferentes? entom E2=E     |
    _FLNOCHGE2_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLI],BL   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp DL,[ESI]        ' Compara Pixels H & F       \
    je _FLNOCHGE3_      ' Iguais entom E3=F          | iif(H=F,F,E)
    mov DL,AL           ' Diferentes? entom E3=E     |
    _FLNOCHGE3_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],DL   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    jnz _NEXTLINE_      ' / (adianta pq 1Ş linha = borda)
    ' ************ 4 pontos da escala normal ************
    _FLBEHODEF_:        ' Label para escala normal
    stosb               ' \
    stosb               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],AL   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],AL   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine   
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    ' ***************** Linhas Seguintes *****************
    _NEXTLINE_:         ' Label de próxima linha
    mov ECX,PILI         ' 256 pixels (borda provisória)
    _NEXTPOINT_:        ' Label de Próximo Ponto
    lodsb               ' Carrega Pixel central (E)
    mov BL,[ESI-OLIA]    ' Carrega Pixel Superior (B)
    mov DL,[ESI]        ' Carrega Pixel Direito (F)
    cmp BL,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _BEHODEF_        ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],DL      ' | Compara igualgade dos pixels D & F
    je _BEHODEF_        ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp BL,[ESI-TPI]      ' Compara Pixels B & D       \
    je _NOCHGE0_        ' iguais entom E0 = D        | iif(B=D,D,E)
    mov BL,AL           ' diferentes entom E0 = E    |
    _NOCHGE0_:          ' Label Qndo Iguais (ignora) /
    mov [EDI],BL        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI-OLIA],DL    ' Compara Pixels B & F       \
    je _NOCHGE1_        ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov DL,AL           ' Diferentes? entom E1 = E   |
    _NOCHGE1_:          ' Label qndo iguais (ignora) /
    mov [EDI+OPI],DL      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov BL,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov DL,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp BL,DL           ' Compara Pixels H & D       \
    je _NOCHGE2_        ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov BL,AL           ' Diferentes? entom E2 = E   |
    _NOCHGE2_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLI],BL   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp DL,[ESI]        ' Compara Pixels H & F       \
    je _NOCHGE3_        ' Iguais entom E3=F          | iif(H=F,F,E)
    mov DL,AL           ' Diferentes? entom E3 = E   |
    _NOCHGE3_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],DL   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    jmp _FINALEND_      ' Vai para o fim caso termine com escala especial
    ' ************ 4 pontos da escala normal ************
    _BEHODEF_:          ' Label de Escala Normal
    stosb               ' \
    stosb               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],AL   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],AL   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    _FINALEND_:         ' Label de fim =)
  end asm 
end sub
 
#endif
 
#if MYBPP = 16
declare sub scale2x_16(PTORG as any ptr, PTDST as any ptr)
sub scale2x_16(PTORG as any ptr, PTDST as any ptr)
  static as integer Y 
  Y = SC2X_Y
 
  #define ESZ 2 
 
  const PILI = SC2X_X
  const PILIS = SC2X_X-1
  const OPI = ESZ
  const TPI = ESZ*2 
  const OLIS = (SC2X_X-1)*ESZ
  const OLIA = (SC2X_X+1)*ESZ
  const TLISS = ((SC2X_X*2)-2)*ESZ
  const TLIS = ((SC2X_X*2)-1)*ESZ
  const TLI = ((SC2X_X*2))*ESZ
  const TLIA = ((SC2X_X*2)+1)*ESZ
 
  ' **** Inicio do código asm fixo para dobrar 256x192 ****
  asm       
    mov ESI,[PTORG]     ' ESI = Ponteiro de Origem
    mov EDI,[PTDST]     ' EDI = Ponteiro de Destino
    lodsw               ' \
    stosw               ' | Copia e aumenta
    stosw               ' | o primeiro Pixel
    mov [EDI+TLISS],AX   ' | (borda)
    mov [EDI+TLIS],AX   ' /
    ' *************** Primeira Linha (borda) **************
    mov ECX,PILIS         ' (255 pixels na linha (256-borda))
    _FLNEXTPOINT_:      ' Label de Próximo Pixel
    lodsw                ' Carrega Pixel central (E)
    mov BX,[ESI]        ' Carrega Pixel Superior (B)
    mov DX,[ESI]        ' Carrega Pixel Direito (F)
    cmp BX,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _FLBEHODEF_      ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],DX      ' | Compara igualgade dos pixels D & F
    je _FLBEHODEF_      ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp BX,[ESI-TPI]      ' Compara Pixels B & D       \
    je _FLNOCHGE0_      ' iguais entom E0 = D        | iif(B=D,D,E)
    mov BX,AX           ' diferentes entom E0 = E    |
    _FLNOCHGE0_:        ' Label Qndo Iguais (ignora) /
    mov [EDI],BX        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI],DX        ' Compara Pixels B & F       \
    je _FLNOCHGE1_      ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov DX,AX           ' Diferentes? entom E1 = E   |
    _FLNOCHGE1_:        ' Label qndo iguais (ignora) /
    mov [EDI+OPI],DX      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov BX,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov DX,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp BX,DX           ' Compara Pixels H & D       \
    je _FLNOCHGE2_      ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov BX,AX           ' Diferentes? entom E2=E     |
    _FLNOCHGE2_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLI],BX   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp DX,[ESI]        ' Compara Pixels H & F       \
    je _FLNOCHGE3_      ' Iguais entom E3=F          | iif(H=F,F,E)
    mov DX,AX           ' Diferentes? entom E3=E     |
    _FLNOCHGE3_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],DX   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    jnz _NEXTLINE_      ' / (adianta pq 1Ş linha = borda)
    ' ************ 4 pontos da escala normal ************
    _FLBEHODEF_:        ' Label para escala normal
    stosw               ' \
    stosw               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],AX   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],AX   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine   
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    ' ***************** Linhas Seguintes *****************
    _NEXTLINE_:         ' Label de próxima linha
    mov ECX,PILI         ' 256 pixels (borda provisória)
    _NEXTPOINT_:        ' Label de Próximo Ponto
    lodsw               ' Carrega Pixel central (E)
    mov BX,[ESI-OLIA]    ' Carrega Pixel Superior (B)
    mov DX,[ESI]        ' Carrega Pixel Direito (F)
    cmp BX,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _BEHODEF_        ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],DX      ' | Compara igualgade dos pixels D & F
    je _BEHODEF_        ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp BX,[ESI-TPI]      ' Compara Pixels B & D       \
    je _NOCHGE0_        ' iguais entom E0 = D        | iif(B=D,D,E)
    mov BX,AX           ' diferentes entom E0 = E    |
    _NOCHGE0_:          ' Label Qndo Iguais (ignora) /
    mov [EDI],BX        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI-OLIA],DX    ' Compara Pixels B & F       \
    je _NOCHGE1_        ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov DX,AX           ' Diferentes? entom E1 = E   |
    _NOCHGE1_:          ' Label qndo iguais (ignora) /
    mov [EDI+OPI],DX      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov BX,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov DX,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp BX,DX           ' Compara Pixels H & D       \
    je _NOCHGE2_        ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov BX,AX           ' Diferentes? entom E2 = E   |
    _NOCHGE2_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLI],BX   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp DX,[ESI]        ' Compara Pixels H & F       \
    je _NOCHGE3_        ' Iguais entom E3=F          | iif(H=F,F,E)
    mov DX,AX           ' Diferentes? entom E3 = E   |
    _NOCHGE3_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],DX   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    jmp _FINALEND_      ' Vai para o fim caso termine com escala especial
    ' ************ 4 pontos da escala normal ************
    _BEHODEF_:          ' Label de Escala Normal
    stosw               ' \
    stosw               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],AX   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],AX   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    _FINALEND_:         ' Label de fim =)
  end asm 
end sub
#endif
 
#if MYBPP = 32
declare sub scale2x_32(PTORG as any ptr, PTDST as any ptr)
sub scale2x_32(PTORG as any ptr, PTDST as any ptr)
  static as integer Y 
  Y = SC2X_Y
 
  #define ESZ 4 
 
  const PILI = SC2X_X
  const PILIS = SC2X_X-1
  const OPI = ESZ
  const TPI = ESZ*2 
  const OLIS = (SC2X_X-1)*ESZ
  const OLIA = (SC2X_X+1)*ESZ
  const TLISS = ((SC2X_X*2)-2)*ESZ
  const TLIS = ((SC2X_X*2)-1)*ESZ
  const TLI = ((SC2X_X*2))*ESZ
  const TLIA = ((SC2X_X*2)+1)*ESZ
 
  ' **** Inicio do código asm fixo para dobrar 256x192 ****
  asm       
    mov ESI,[PTORG]     ' ESI = Ponteiro de Origem
    mov EDI,[PTDST]     ' EDI = Ponteiro de Destino
    lodsd               ' \
    stosd               ' | Copia e aumenta
    stosd               ' | o primeiro Pixel
    mov [EDI+TLISS],EAX   ' | (borda)
    mov [EDI+TLIS],EAX   ' /
    ' *************** Primeira Linha (borda) **************
    mov ECX,PILIS         ' (255 pixels na linha (256-borda))
    _FLNEXTPOINT_:      ' Label de Próximo Pixel
    lodsd                ' Carrega Pixel central (E)
    mov EBX,[ESI]        ' Carrega Pixel Superior (B)
    mov EDX,[ESI]        ' Carrega Pixel Direito (F)
    cmp EBX,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _FLBEHODEF_      ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],EDX      ' | Compara igualgade dos pixels D & F
    je _FLBEHODEF_      ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp EBX,[ESI-TPI]      ' Compara Pixels B & D       \
    je _FLNOCHGE0_      ' iguais entom E0 = D        | iif(B=D,D,E)
    mov EBX,EAX           ' diferentes entom E0 = E    |
    _FLNOCHGE0_:        ' Label Qndo Iguais (ignora) /
    mov [EDI],EBX        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI],EDX        ' Compara Pixels B & F       \
    je _FLNOCHGE1_      ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov EDX,EAX           ' Diferentes? entom E1 = E   |
    _FLNOCHGE1_:        ' Label qndo iguais (ignora) /
    mov [EDI+OPI],EDX      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov EBX,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov EDX,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp EBX,EDX           ' Compara Pixels H & D       \
    je _FLNOCHGE2_      ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov EBX,EAX           ' Diferentes? entom E2=E     |
    _FLNOCHGE2_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLI],EBX   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp EDX,[ESI]        ' Compara Pixels H & F       \
    je _FLNOCHGE3_      ' Iguais entom E3=F          | iif(H=F,F,E)
    mov EDX,EAX           ' Diferentes? entom E3=E     |
    _FLNOCHGE3_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],EDX   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    jnz _NEXTLINE_      ' / (adianta pq 1Ş linha = borda)
    ' ************ 4 pontos da escala normal ************
    _FLBEHODEF_:        ' Label para escala normal
    stosd               ' \
    stosd               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],EAX   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],EAX   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine   
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    ' ***************** Linhas Seguintes *****************
    _NEXTLINE_:         ' Label de próxima linha
    mov ECX,PILI         ' 256 pixels (borda provisória)
    _NEXTPOINT_:        ' Label de Próximo Ponto
    lodsd               ' Carrega Pixel central (E)
    mov EBX,[ESI-OLIA]    ' Carrega Pixel Superior (B)
    mov EDX,[ESI]        ' Carrega Pixel Direito (F)
    cmp EBX,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _BEHODEF_        ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],EDX      ' | Compara igualgade dos pixels D & F
    je _BEHODEF_        ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp EBX,[ESI-TPI]      ' Compara Pixels B & D       \
    je _NOCHGE0_        ' iguais entom E0 = D        | iif(B=D,D,E)
    mov EBX,EAX           ' diferentes entom E0 = E    |
    _NOCHGE0_:          ' Label Qndo Iguais (ignora) /
    mov [EDI],EBX        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI-OLIA],EDX    ' Compara Pixels B & F       \
    je _NOCHGE1_        ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov EDX,EAX           ' Diferentes? entom E1 = E   |
    _NOCHGE1_:          ' Label qndo iguais (ignora) /
    mov [EDI+OPI],EDX      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov EBX,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov EDX,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp EBX,EDX           ' Compara Pixels H & D       \
    je _NOCHGE2_        ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov EBX,EAX           ' Diferentes? entom E2 = E   |
    _NOCHGE2_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLI],EBX   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp EDX,[ESI]        ' Compara Pixels H & F       \
    je _NOCHGE3_        ' Iguais entom E3=F          | iif(H=F,F,E)
    mov EDX,EAX           ' Diferentes? entom E3 = E   |
    _NOCHGE3_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],EDX   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    jmp _FINALEND_      ' Vai para o fim caso termine com escala especial
    ' ************ 4 pontos da escala normal ************
    _BEHODEF_:          ' Label de Escala Normal
    stosd               ' \
    stosd               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],EAX   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],EAX   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    _FINALEND_:         ' Label de fim =)
  end asm 
end sub
#endif
 
DIM SHARED IMG as any ptr
dim shared SCRPTR as any ptr
DIM SHARED AS INTEGER FPS2, FPS
DIM SHARED AS DOUBLE stt, StartTime
DIM SHARED frameintvl As Double = 1.0/fpslimit
DIM SHARED sleepintvl As Integer

SCREENRES 640,480, 32, 1,1
SETMOUSE 0,0,0 
 
IMG = ImageCreate(320, 240)
 
DO
   
stt = Timer

FPS = FPS + 1                 
if StartTime + 1 < timer then
 FPS2 = FPS
 FPS = 0
 StartTime = timer
end if
   
 
screenlock

LINE (0,0)-(320,240), RGB(0,0,0), BF

LINE (0,0)-(319, 239), RGB(255,0,0), B
CIRCLE (70,70), 30, RGB(0,255,0),,,,F

LOCATE 1,1
PRINT "FPS:"; FPS2
PRINT "Bit-depth:"; MYBPP
 
GET (0,0)-(319, 239), IMG
 
Scale2x_32(IMG+sizeof(fb.image),screenptr)
 
screenunlock

' Keep the FPS value within fpslimit (set above).
sleepintvl = Cint((stt + frameintvl - Timer)*1000.0)
If sleepintvl>1 Then
  Sleep sleepintvl
else
    sleep 1
end if
 
LOOP UNTIL MULTIKEY(SC_ESCAPE)

Hope someone will find it useful.
Logged

"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist
mysoft
Recruit
**
Gender: Male
Posts: 38


mysoft@bol.com.br
View Profile WWW Email
« Reply #1 on: January 06, 2008, 04:21:44 AM »

hum... i have added also a normal 2x scale....

#define SC2X_X 320
#define SC2X_Y 240
#define MYBPP 32
#include "fbgfx.bi"
using FB

#if MYBPP = 8
declare sub scale2x_8(PTORG as any ptr, PTDST as any ptr)

sub Resize2x_8(PTORG as any ptr,PTDST as any ptr)
 
  const OPI = 1
  const OPIB = OPI*2
  const PILI = SC2X_X*2
 
  asm
    mov ESI,[PTORG]
    mov EDI,[PTDST]
    mov EBX,SC2X_X
    mov EDX,SC2X_Y
    _R2X8_NEXTLINE_:
    mov ECX,EBX
    _R2X8_NEXTPOINT_:
    lodsb
    mov AH,AL   
    mov [EDI],AX
    mov [EDI+PILI],AX
    add EDI,OPIB
    dec ecx
    jnz _R2X8_NEXTPOINT_
    add EDI,PILI
    dec edx
    jnz _R2X8_NEXTLINE_
  end asm
 
end sub

sub scale2x_8(PTORG as any ptr, PTDST as any ptr)
  static as integer Y 
  Y = SC2X_Y
 
  const PILI = SC2X_X
  const OPI = 1
  const TPI = OPI*2
  const PILIS = PILI-1
  const OLIS = PILI-1
  const OLIA = PILI+1
  const TLISS = (PILI*2)-2
  const TLIS = (PILI*2)-1
  const TLI = (PILI*2)
  const TLIA = (PILI*2)+1
 
  ' **** Inicio do código asm fixo para dobrar 256x192 ****
  asm       
    mov ESI,[PTORG]     ' ESI = Ponteiro de Origem
    mov EDI,[PTDST]     ' EDI = Ponteiro de Destino
    lodsb               ' \
    stosb               ' | Copia e aumenta
    stosb               ' | o primeiro Pixel
    mov [EDI+TLISS],AL   ' | (borda)
    mov [EDI+TLIS],AL   ' /
    ' *************** Primeira Linha (borda) **************
    mov ECX,PILIS         ' (255 pixels na linha (256-borda))
    _FLNEXTPOINT_:      ' Label de Próximo Pixel
    lodsb                ' Carrega Pixel central (E)
    mov BL,[ESI]        ' Carrega Pixel Superior (B)
    mov DL,[ESI]        ' Carrega Pixel Direito (F)
    cmp BL,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _FLBEHODEF_      ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],DL      ' | Compara igualgade dos pixels D & F
    je _FLBEHODEF_      ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp BL,[ESI-TPI]      ' Compara Pixels B & D       \
    je _FLNOCHGE0_      ' iguais entom E0 = D        | iif(B=D,D,E)
    mov BL,AL           ' diferentes entom E0 = E    |
    _FLNOCHGE0_:        ' Label Qndo Iguais (ignora) /
    mov [EDI],BL        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI],DL        ' Compara Pixels B & F       \
    je _FLNOCHGE1_      ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov DL,AL           ' Diferentes? entom E1 = E   |
    _FLNOCHGE1_:        ' Label qndo iguais (ignora) /
    mov [EDI+OPI],DL      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov BL,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov DL,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp BL,DL           ' Compara Pixels H & D       \
    je _FLNOCHGE2_      ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov BL,AL           ' Diferentes? entom E2=E     |
    _FLNOCHGE2_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLI],BL   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp DL,[ESI]        ' Compara Pixels H & F       \
    je _FLNOCHGE3_      ' Iguais entom E3=F          | iif(H=F,F,E)
    mov DL,AL           ' Diferentes? entom E3=E     |
    _FLNOCHGE3_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],DL   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    jnz _NEXTLINE_      ' / (adianta pq 1ª linha = borda)
    ' ************ 4 pontos da escala normal ************
    _FLBEHODEF_:        ' Label para escala normal
    stosb               ' \
    stosb               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],AL   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],AL   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine   
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    ' ***************** Linhas Seguintes *****************
    _NEXTLINE_:         ' Label de próxima linha
    mov ECX,PILI         ' 256 pixels (borda provisória)
    _NEXTPOINT_:        ' Label de Próximo Ponto
    lodsb               ' Carrega Pixel central (E)
    mov BL,[ESI-OLIA]    ' Carrega Pixel Superior (B)
    mov DL,[ESI]        ' Carrega Pixel Direito (F)
    cmp BL,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _BEHODEF_        ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],DL      ' | Compara igualgade dos pixels D & F
    je _BEHODEF_        ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp BL,[ESI-TPI]      ' Compara Pixels B & D       \
    je _NOCHGE0_        ' iguais entom E0 = D        | iif(B=D,D,E)
    mov BL,AL           ' diferentes entom E0 = E    |
    _NOCHGE0_:          ' Label Qndo Iguais (ignora) /
    mov [EDI],BL        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI-OLIA],DL    ' Compara Pixels B & F       \
    je _NOCHGE1_        ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov DL,AL           ' Diferentes? entom E1 = E   |
    _NOCHGE1_:          ' Label qndo iguais (ignora) /
    mov [EDI+OPI],DL      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov BL,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov DL,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp BL,DL           ' Compara Pixels H & D       \
    je _NOCHGE2_        ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov BL,AL           ' Diferentes? entom E2 = E   |
    _NOCHGE2_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLI],BL   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp DL,[ESI]        ' Compara Pixels H & F       \
    je _NOCHGE3_        ' Iguais entom E3=F          | iif(H=F,F,E)
    mov DL,AL           ' Diferentes? entom E3 = E   |
    _NOCHGE3_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],DL   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    jmp _FINALEND_      ' Vai para o fim caso termine com escala especial
    ' ************ 4 pontos da escala normal ************
    _BEHODEF_:          ' Label de Escala Normal
    stosb               ' \
    stosb               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],AL   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],AL   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    _FINALEND_:         ' Label de fim =)
  end asm 
end sub

#endif

#if MYBPP = 16
declare sub scale2x_16(PTORG as any ptr, PTDST as any ptr)

sub Resize2x_16(PTORG as any ptr,PTDST as any ptr)
 
  #define ESZ 2
 
  const OPI = ESZ
  const OPIB = OPI*2
  const PILI = (SC2X_X*2)*ESZ
 
  asm
    mov ESI,[PTORG]
    mov EDI,[PTDST]
    mov BX,SC2X_Y
    shl EBX,16
    mov CX,SC2X_X
    _R2X16_NEXTLINE_:
    mov BX,CX
    _R2X16_NEXTPOINT_:
    lodsw
    mov DX,AX
    shl EAX,16
    mov AX,DX   
    mov [EDI],EAX
    mov [EDI+PILI],EAX
    add EDI,OPIB
    dec BX
    jnz _R2X16_NEXTPOINT_
    add EDI,PILI
    sub EBX,65536   
    jnz _R2X16_NEXTLINE_
  end asm
 
end sub

sub scale2x_16(PTORG as any ptr, PTDST as any ptr)
  static as integer Y 
  Y = SC2X_Y
 
  #define ESZ 2 
 
  const PILI = SC2X_X
  const PILIS = SC2X_X-1
  const OPI = ESZ
  const TPI = ESZ*2 
  const OLIS = (SC2X_X-1)*ESZ
  const OLIA = (SC2X_X+1)*ESZ
  const TLISS = ((SC2X_X*2)-2)*ESZ
  const TLIS = ((SC2X_X*2)-1)*ESZ
  const TLI = ((SC2X_X*2))*ESZ
  const TLIA = ((SC2X_X*2)+1)*ESZ
 
  ' **** Inicio do código asm fixo para dobrar 256x192 ****
  asm       
    mov ESI,[PTORG]     ' ESI = Ponteiro de Origem
    mov EDI,[PTDST]     ' EDI = Ponteiro de Destino
    lodsw               ' \
    stosw               ' | Copia e aumenta
    stosw               ' | o primeiro Pixel
    mov [EDI+TLISS],AX   ' | (borda)
    mov [EDI+TLIS],AX   ' /
    ' *************** Primeira Linha (borda) **************
    mov ECX,PILIS         ' (255 pixels na linha (256-borda))
    _FLNEXTPOINT_:      ' Label de Próximo Pixel
    lodsw                ' Carrega Pixel central (E)
    mov BX,[ESI]        ' Carrega Pixel Superior (B)
    mov DX,[ESI]        ' Carrega Pixel Direito (F)
    cmp BX,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _FLBEHODEF_      ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],DX      ' | Compara igualgade dos pixels D & F
    je _FLBEHODEF_      ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp BX,[ESI-TPI]      ' Compara Pixels B & D       \
    je _FLNOCHGE0_      ' iguais entom E0 = D        | iif(B=D,D,E)
    mov BX,AX           ' diferentes entom E0 = E    |
    _FLNOCHGE0_:        ' Label Qndo Iguais (ignora) /
    mov [EDI],BX        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI],DX        ' Compara Pixels B & F       \
    je _FLNOCHGE1_      ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov DX,AX           ' Diferentes? entom E1 = E   |
    _FLNOCHGE1_:        ' Label qndo iguais (ignora) /
    mov [EDI+OPI],DX      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov BX,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov DX,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp BX,DX           ' Compara Pixels H & D       \
    je _FLNOCHGE2_      ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov BX,AX           ' Diferentes? entom E2=E     |
    _FLNOCHGE2_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLI],BX   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp DX,[ESI]        ' Compara Pixels H & F       \
    je _FLNOCHGE3_      ' Iguais entom E3=F          | iif(H=F,F,E)
    mov DX,AX           ' Diferentes? entom E3=E     |
    _FLNOCHGE3_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],DX   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    jnz _NEXTLINE_      ' / (adianta pq 1ª linha = borda)
    ' ************ 4 pontos da escala normal ************
    _FLBEHODEF_:        ' Label para escala normal
    stosw               ' \
    stosw               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],AX   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],AX   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine   
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    ' ***************** Linhas Seguintes *****************
    _NEXTLINE_:         ' Label de próxima linha
    mov ECX,PILI         ' 256 pixels (borda provisória)
    _NEXTPOINT_:        ' Label de Próximo Ponto
    lodsw               ' Carrega Pixel central (E)
    mov BX,[ESI-OLIA]    ' Carrega Pixel Superior (B)
    mov DX,[ESI]        ' Carrega Pixel Direito (F)
    cmp BX,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _BEHODEF_        ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],DX      ' | Compara igualgade dos pixels D & F
    je _BEHODEF_        ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp BX,[ESI-TPI]      ' Compara Pixels B & D       \
    je _NOCHGE0_        ' iguais entom E0 = D        | iif(B=D,D,E)
    mov BX,AX           ' diferentes entom E0 = E    |
    _NOCHGE0_:          ' Label Qndo Iguais (ignora) /
    mov [EDI],BX        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI-OLIA],DX    ' Compara Pixels B & F       \
    je _NOCHGE1_        ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov DX,AX           ' Diferentes? entom E1 = E   |
    _NOCHGE1_:          ' Label qndo iguais (ignora) /
    mov [EDI+OPI],DX      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov BX,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov DX,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp BX,DX           ' Compara Pixels H & D       \
    je _NOCHGE2_        ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov BX,AX           ' Diferentes? entom E2 = E   |
    _NOCHGE2_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLI],BX   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp DX,[ESI]        ' Compara Pixels H & F       \
    je _NOCHGE3_        ' Iguais entom E3=F          | iif(H=F,F,E)
    mov DX,AX           ' Diferentes? entom E3 = E   |
    _NOCHGE3_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],DX   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    jmp _FINALEND_      ' Vai para o fim caso termine com escala especial
    ' ************ 4 pontos da escala normal ************
    _BEHODEF_:          ' Label de Escala Normal
    stosw               ' \
    stosw               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],AX   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],AX   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    _FINALEND_:         ' Label de fim =)
  end asm 
end sub
#endif

#if MYBPP = 32
declare sub scale2x_32(PTORG as any ptr, PTDST as any ptr)

sub Resize2x_32(PTORG as any ptr,PTDST as any ptr)
 
  #define ESZ 4
 
  const OPI = ESZ
  const OPIB = OPI*2
  const PILI = (SC2X_X*2)*ESZ
  const PILIB = PILI+OPI
 
  asm
    mov ESI,[PTORG]
    mov EDI,[PTDST]
    mov EDX,SC2X_Y   
    mov EBX,SC2X_X
    _R2X32_NEXTLINE_:
    mov ECX,EBX
    _R2X32_NEXTPOINT_:
    lodsd   
    mov [EDI],EAX
    mov [EDI+OPI],EAX
    mov [EDI+PILI],EAX
    mov [EDI+PILIB],EAX
    add EDI,OPIB
    dec ECX
    jnz _R2X32_NEXTPOINT_
    add EDI,PILI
    dec EDX
    jnz _R2X32_NEXTLINE_
  end asm
 
end sub


sub scale2x_32(PTORG as any ptr, PTDST as any ptr)
  static as integer Y 
  Y = SC2X_Y
 
  #define ESZ 4 
 
  const PILI = SC2X_X
  const PILIS = SC2X_X-1
  const OPI = ESZ
  const TPI = ESZ*2 
  const OLIS = (SC2X_X-1)*ESZ
  const OLIA = (SC2X_X+1)*ESZ
  const TLISS = ((SC2X_X*2)-2)*ESZ
  const TLIS = ((SC2X_X*2)-1)*ESZ
  const TLI = ((SC2X_X*2))*ESZ
  const TLIA = ((SC2X_X*2)+1)*ESZ
 
  ' **** Inicio do código asm fixo para dobrar 256x192 ****
  asm       
    mov ESI,[PTORG]     ' ESI = Ponteiro de Origem
    mov EDI,[PTDST]     ' EDI = Ponteiro de Destino
    lodsd               ' \
    stosd               ' | Copia e aumenta
    stosd               ' | o primeiro Pixel
    mov [EDI+TLISS],EAX   ' | (borda)
    mov [EDI+TLIS],EAX   ' /
    ' *************** Primeira Linha (borda) **************
    mov ECX,PILIS         ' (255 pixels na linha (256-borda))
    _FLNEXTPOINT_:      ' Label de Próximo Pixel
    lodsd                ' Carrega Pixel central (E)
    mov EBX,[ESI]        ' Carrega Pixel Superior (B)
    mov EDX,[ESI]        ' Carrega Pixel Direito (F)
    cmp EBX,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _FLBEHODEF_      ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],EDX      ' | Compara igualgade dos pixels D & F
    je _FLBEHODEF_      ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp EBX,[ESI-TPI]      ' Compara Pixels B & D       \
    je _FLNOCHGE0_      ' iguais entom E0 = D        | iif(B=D,D,E)
    mov EBX,EAX           ' diferentes entom E0 = E    |
    _FLNOCHGE0_:        ' Label Qndo Iguais (ignora) /
    mov [EDI],EBX        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI],EDX        ' Compara Pixels B & F       \
    je _FLNOCHGE1_      ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov EDX,EAX           ' Diferentes? entom E1 = E   |
    _FLNOCHGE1_:        ' Label qndo iguais (ignora) /
    mov [EDI+OPI],EDX      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov EBX,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov EDX,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp EBX,EDX           ' Compara Pixels H & D       \
    je _FLNOCHGE2_      ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov EBX,EAX           ' Diferentes? entom E2=E     |
    _FLNOCHGE2_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLI],EBX   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp EDX,[ESI]        ' Compara Pixels H & F       \
    je _FLNOCHGE3_      ' Iguais entom E3=F          | iif(H=F,F,E)
    mov EDX,EAX           ' Diferentes? entom E3=E     |
    _FLNOCHGE3_:        ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],EDX   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    jnz _NEXTLINE_      ' / (adianta pq 1ª linha = borda)
    ' ************ 4 pontos da escala normal ************
    _FLBEHODEF_:        ' Label para escala normal
    stosd               ' \
    stosd               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],EAX   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],EAX   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _FLNEXTPOINT_   ' / até que termine   
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próximo linha
    ' ***************** Linhas Seguintes *****************
    _NEXTLINE_:         ' Label de próxima linha
    mov ECX,PILI         ' 256 pixels (borda provisória)
    _NEXTPOINT_:        ' Label de Próximo Ponto
    lodsd               ' Carrega Pixel central (E)
    mov EBX,[ESI-OLIA]    ' Carrega Pixel Superior (B)
    mov EDX,[ESI]        ' Carrega Pixel Direito (F)
    cmp EBX,[ESI+OLIS]    ' \ Compara igualdade dos pixels B & H
    je _BEHODEF_        ' | Iguais? Entom pula para escala normal
    cmp [ESI-TPI],EDX      ' | Compara igualgade dos pixels D & F
    je _BEHODEF_        ' / Iguais? Entom pula para escala normal
    ' ************ 4 pontos da escala especial ************
    cmp EBX,[ESI-TPI]      ' Compara Pixels B & D       \
    je _NOCHGE0_        ' iguais entom E0 = D        | iif(B=D,D,E)
    mov EBX,EAX           ' diferentes entom E0 = E    |
    _NOCHGE0_:          ' Label Qndo Iguais (ignora) /
    mov [EDI],EBX        ' Coloca ponto E0 (superior esquerdo) no buffer de destino
    cmp [ESI-OLIA],EDX    ' Compara Pixels B & F       \
    je _NOCHGE1_        ' Iguais? entom E1=F         | iif(B=F,F,E)
    mov EDX,EAX           ' Diferentes? entom E1 = E   |
    _NOCHGE1_:          ' Label qndo iguais (ignora) /
    mov [EDI+OPI],EDX      ' Coloca ponto E1 (superior direito) no buffer de destino
    mov EBX,[ESI-TPI]      ' Carrega Pixel Esquerdo (D)
    mov EDX,[ESI+OLIS]    ' Carrega Pixel Inferior (H)
    cmp EBX,EDX           ' Compara Pixels H & D       \
    je _NOCHGE2_        ' Iguais? entom E2=D         | iif(H=D,D,E)
    mov EBX,EAX           ' Diferentes? entom E2 = E   |
    _NOCHGE2_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLI],EBX   ' Coloca ponto E2 (inferior esquerdo) no buffer de destino
    cmp EDX,[ESI]        ' Compara Pixels H & F       \
    je _NOCHGE3_        ' Iguais entom E3=F          | iif(H=F,F,E)
    mov EDX,EAX           ' Diferentes? entom E3 = E   |
    _NOCHGE3_:          ' Label qndo iguais (ignora) /
    mov [EDI+TLIA],EDX   ' Coloca ponto E3 (inferior direito) no buffer de destino
    add EDI,TPI           ' Aponta para próximo pixel de destino
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    jmp _FINALEND_      ' Vai para o fim caso termine com escala especial
    ' ************ 4 pontos da escala normal ************
    _BEHODEF_:          ' Label de Escala Normal
    stosd               ' \
    stosd               ' | Coloca os 4 pontos no buffer de destino
    mov [EDI+TLISS],EAX   ' | E0,E1,E2,E3 ( = E (ponto central )
    mov [EDI+TLIS],EAX   ' /
    dec ECX             ' \ Próximo pixel da linha
    jnz _NEXTPOINT_     ' / até que termine
    add EDI,TLI        ' Aponta para próxima linha de destino
    dec dword ptr [Y]   ' \ Próxima linha
    jnz _NEXTLINE_      ' / das 191 restantes (menos borda)
    _FINALEND_:         ' Label de fim =)
  end asm 
end sub
#endif

dim shared IMG as any ptr
dim shared SCRPTR as any ptr
dim as integer XX,YY,XS=10,YS=10
dim as byte METH

screenres 640,480,MYBPP, 2
setmouse 0,0,0    ' We hide the deafult mouse cursor.

IMG = ImageCreate(320, 240)

screenset 1,1
SCRPTR = screenptr
screenset 0,1

do
 
  screenset 0,1
 
  screenlock
 
  cls
  line (0,0)-(319, 239), rgb(255,0,0), B
  circle (XX,YY), 30, rgb(0,255,0),,,,F
  'LINE (0,0)-(319, 239), 12, B
  'CIRCLE (XX,YY), 30, 10,,,,F
 
 
  get (0,0)-(319, 239), IMG
 
  screenset 1,1
 
  METH = 1-METH
  if METH then
    Scale2x_32(IMG+sizeof(fb.image),SCRPTR)
  else
    Resize2x_32(IMG+sizeof(fb.image),SCRPTR)
  end if
 
  screenunlock
 
  XX += XS:YY += YS
  if XX = 0 or XX = 320 then XS = -XS
  if YY = 0 or YY = 240 then YS = -YS
 
  sleep 500
  'screensync
 
loop until multikey(SC_ESCAPE)
Logged

Programming is like love... you will never acomplish anything by treating your language as if it was a tool, or a slave of yours...
notthecheatr
Global Moderator
Forum Sage
*****
Gender: Male
Posts: 351


Who's the guy from 21 Jump Street?

notthecheatr TheMysteriousStrangerFromMars
View Profile WWW Email
« Reply #2 on: January 06, 2008, 09:31:36 AM »

Not bad!
Logged

The funniest thing happened yesterday.
Lachie Dazdarian
Double dipper
Administrator
Forum Sage
*****
Gender: Male
Posts: 1195


lachie13
View Profile WWW Email
« Reply #3 on: January 06, 2008, 03:12:29 PM »

Thanks mysoft. For some reason I also get 48 FPS with simple Resize2X (don't worry, I changed the code to match the Scale2X speed test), but I don't mind. I wanted to give the user a choice to choose 2X scaling with pixel matching and without it. Now I have both. Thanks!
Logged

"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist
Leonheart
Guest
« Reply #4 on: January 08, 2008, 07:15:35 AM »

I can do better, just use a magnifier glass than it can scale up to 10x until you see Red Green and Blue pixel dot   Tongue

Just kidding around.... This cool Lachie!
I will save this html.
Logged
notthecheatr
Global Moderator
Forum Sage
*****
Gender: Male
Posts: 351


Who's the guy from 21 Jump Street?

notthecheatr TheMysteriousStrangerFromMars
View Profile WWW Email
« Reply #5 on: January 21, 2008, 10:07:53 PM »

I don't imagine there's any possibility of making this more flexible, for example allowing to choose where the images are drawn?  In particular, it'd be nice to have something like

Scale2x_32 (src As FB.Image Ptr, dest As FB.Image Ptr, x As uInteger, y As uInteger)

So I could draw the image elsewhere on the screen - and in the example above, I also use FB.Image Ptr rather than any other sort of Ptr.  This would be nicer, so the routine could detect the size automatically:

Dim As Integer w, h
If src = 0 Then
  ScreenInfo w, h
Else
  w = src->Width
  h = src->Height
End If

I don't know how feasible it would be, but it would be nice - the reason is that I might want to use this in a resolution that is higher than twice the size of the box I'm drawing to, so I would want to be able to center the image on the screen if it's smaller than the total size of the screen.

If you can do this, thank you - if not, that's fine  Smiley
Logged

The funniest thing happened yesterday.
mysoft
Recruit
**
Gender: Male
Posts: 38


mysoft@bol.com.br
View Profile WWW Email
« Reply #6 on: January 22, 2008, 09:29:31 AM »

i have 2 choices here... one is simple change the constants to variables (im not sure what will happen with the pitch...)
and the second option is use self modifying asm (i will make tests to see what option will give me better results)

i will see thigs as soons as i finish the new algo for the collision detect Tongue
Logged

Programming is like love... you will never acomplish anything by treating your language as if it was a tool, or a slave of yours...
notthecheatr
Global Moderator
Forum Sage
*****
Gender: Male
Posts: 351


Who's the guy from 21 Jump Street?

notthecheatr TheMysteriousStrangerFromMars
View Profile WWW Email
« Reply #7 on: January 22, 2008, 10:28:17 AM »

Probably switching the constants to variables will work just fine.  I also just realized that it doesn't really need to have (x, y) coordinates as I can simply draw to a buffer and draw the buffer to the screen anywhere I need it.  This also means that it doesn't even need to detect the size of anything, since I can set up the buffer to be the right size automatically.


If you want to do it, though, don't forget you can always check the destination like this:

Sub scale2x_32 (src As FB.Image Ptr, dest As FB.Image Ptr)
Dim As uInteger width, height
  If dest = 0 Then
    ScreenInfo width, height
  Else
    width = dest->Width
    height = dest->Height
  End If

  '...
End Sub
I use this in all my image modifying routines, it makes things much more versatile Smiley
Logged

The funniest thing happened yesterday.
mysoft
Recruit
**
Gender: Male
Posts: 38


mysoft@bol.com.br
View Profile WWW Email
« Reply #8 on: January 22, 2008, 12:38:14 PM »

yeah it will be called Scale2xEx, but yeah, i only used constants for speed =], but i need to check if there are some optimization that i can make (more experienced now than before)

about the parameters... they will be optional =]

function Scale2xEx32(SRC,DST,SWID=-1,SHEI=-1,DWID=-1,DHEI=-1,BITS=-1)
Logged

Programming is like love... you will never acomplish anything by treating your language as if it was a tool, or a slave of yours...
notthecheatr
Global Moderator
Forum Sage
*****
Gender: Male
Posts: 351


Who's the guy from 21 Jump Street?

notthecheatr TheMysteriousStrangerFromMars
View Profile WWW Email
« Reply #9 on: January 22, 2008, 12:53:49 PM »

You could probably use FB.Image Ptrs instead, I'm sure it would be as fast:

Sub scale2x_32 (src As FB.Image Ptr, dest As FB.Image Ptr)
  'Direct pointers to the source and destination buffers (use these in assembly code)
  Dim As uInteger Ptr srcPixels
  Dim As uInteger Ptr destPixels

  'Width and height of the src and dest buffers
  Dim As uInteger oldW, newW, oldH, newH

  ' 0 means it's the screen
  If dest = 0 Then
    destPixels = ScreenPtr
  Else
    destPixels = CPtr(uInteger Ptr, dest+1)
  End If

  If src = 0 Then
    srcPixels = ScreenPtr
    ScreenInfo oldW, oldH
  Else
    srcPixels = CPtr(uInteger Ptr, src+1)
    oldW = src->Width
    oldH = src->Height
  End If

  newW = oldW * 2
  newH = oldH * 2

  '... now the asm routines
End Sub
Logged

The funniest thing happened yesterday.
notthecheatr
Global Moderator
Forum Sage
*****
Gender: Male
Posts: 351


Who's the guy from 21 Jump Street?

notthecheatr TheMysteriousStrangerFromMars
View Profile WWW Email
« Reply #10 on: January 22, 2008, 01:02:27 PM »

Here's a question:  does the scaler only support certain image sizes?  Because I would expect

#define SC2X_X 65
#define SC2X_Y 58
#define MYBPP 32
#include "fbgfx.bi"
using FB


'SCALER ROUTINES HERE


dim shared IMG as any ptr
dim shared SCRPTR as any ptr
Dim as any Ptr newimg
dim as integer XX,YY,XS=10,YS=10
dim as byte METH

screenres 640,480,MYBPP, 2
setmouse 0,0,0    ' We hide the deafult mouse cursor.

IMG = ImageCreate(65, 58, 0, 32)
newimg = ImageCreate(130, 116, 0, 32)

BLoad "ntc.bmp", IMG

screenset 1,1
SCRPTR = screenptr
screenset 0,1

do
 
  screenset 0,1
 
  screenlock
 
  cls
 
  'line (0,0)-(319, 239), rgb(255,0,0), B
  'circle (XX,YY), 30, rgb(0,255,0),,,,F
  'LINE (0,0)-(319, 239), 12, B
  'CIRCLE (XX,YY), 30, 10,,,,F
 
 
  'get (0,0)-(319, 239), IMG
 
  screenset 1,1
 
  METH = 1-METH
  if METH then
    Scale2x_32(IMG+sizeof(FB.Image),newimg+sizeof(FB.Image))
  else
    Resize2x_32(IMG+sizeof(FB.Image),newimg+sizeof(FB.Image))
  end if
 
  Put (0, 0), newimg, PSet
 
  Put (300, 300), img
 
  screenunlock
 
  XX += XS:YY += YS
  if XX = 0 or XX = 320 then XS = -XS
  if YY = 0 or YY = 240 then YS = -YS
 
  sleep 500
  'screensync
 
loop until multikey(SC_ESCAPE)

to work properly (I'm using a 65x58 image to test) but it doesn't.  I can do it if I draw directly to the screen, but since the screen is the wrong size it just looks like a mess all over the screen.  This is why I prefer to be able to use FB.Image Ptr instead of Any Ptr, because then the routine could detect the width and height of both buffers automatically.
Logged

The funniest thing happened yesterday.
mysoft
Recruit
**
Gender: Male
Posts: 38


mysoft@bol.com.br
View Profile WWW Email
« Reply #11 on: January 22, 2008, 06:32:24 PM »

yeah... it will be a problem if the PITCH is different than the number of pixels*bpp, (then the width need to be multiply of 16), also it will be fixed in the Scale2xEx
Logged

Programming is like love... you will never acomplish anything by treating your language as if it was a tool, or a slave of yours...
notthecheatr
Global Moderator
Forum Sage
*****
Gender: Male
Posts: 351


Who's the guy from 21 Jump Street?

notthecheatr TheMysteriousStrangerFromMars
View Profile WWW Email
« Reply #12 on: January 22, 2008, 06:38:08 PM »

Oh, OK.  Great then, looking forward to Scale2xEx.
Logged

The funniest thing happened yesterday.
Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Cerberus design by Bloc
Valid XHTML 1.0! Valid CSS!
gfx
gfxgfx gfxgfx