Re: Image Optimizer
Publié : mar. 08/mars/2016 8:14
Je pense qu'une image codée en RGBA, je note la valeur du canal Alpha, je recode en RGB et je rajoute la valeur Alpha au chargement de l'image.
Exactement, c'est tout à fait ça !Je vais vous décevoir, mais Shadow a raison sur un point. Son principe de compression est valable. C'est une compression avec perte, il fait perdre un bit à chaque pixel (ou à chaque composante), ce qui fait qu'il y a bien réduction de taille, au détriment de la qualité de l'image.
Code : Tout sélectionner
;#################################################################################,
#src=0
#dst=1
Fichier$ = OpenFileRequester("Choisissez un BMP a compresser", "*.bmp", "c:\Users\SPH\Desktop\", 0)
If Fichier$=""
End
EndIf
LoadImage(#src,fichier$)
larg=ImageWidth(#src)
haut=ImageHeight(#src)
;;;;;;;;;
CreateFile(#dst, fichier$+".rvb")
WriteLong(#dst,larg)
WriteLong(#dst,haut)
;;;;;;;;;
Dim pr.b(4)
Dim pv.b(4)
Dim pb.b(4)
p1=0
p2=0
StartDrawing(ImageOutput(0))
For u=0 To haut-1
For i=0 To larg-1
x=Point(i,u)
r=Red(x)/4
v=Green(x)/4
b=Blue(x)/4
; Debug r
; Debug v
; Debug b
; Debug("===")
For n=0 To 5
bit = (r>>n)%2
pr(p2)!(bit<<p1)
bit = (v>>n)%2
pv(p2)!(bit<<p1)
bit = (b>>n)%2
pb(p2)!(bit<<p1)
p1+1
If p1=8
p1=0
p2+1
If p2=3
;ecrire:
For ecrire=0 To 2
WriteByte(#dst,pr(ecrire))
WriteByte(#dst,pv(ecrire))
WriteByte(#dst,pb(ecrire))
Next
p1=0
p2=0
Dim pr.b(4)
Dim pv.b(4)
Dim pb.b(4)
;Return
EndIf
EndIf
Next
Next
Next
StopDrawing()
CloseFile(#dst)
End
;##############################################################
;##############################################################
;##############################################################
;##############################################################
Code : Tout sélectionner
;#################################################################################,
#src=0
#dst=1
sph1.b
sph2.b
sph3.b
sph4.b
sph5.b
sph6.b
sph7.b
sph11.b
sph12.b
sph13.b
sph14.b
sph15.b
sph16.b
sph17.b
sph21.b
sph22.b
sph23.b
sph24.b
sph25.b
sph26.b
sph27.b
Fichier$ = OpenFileRequester("Choisissez un '.rvb' a décompresser", "*.rvb", "c:\Users\SPH\Desktop\", 0)
If ReadFile(#src,fichier$)
Else
End
EndIf
Larg=ReadLong(#src)
Haut=ReadLong(#src)
If CreateImage(0, Larg, Haut)
Else
End
EndIf
sph=-1
StartDrawing(ImageOutput(0))
For u=0 To haut-1
For i=0 To larg-1
sph+1
If sph=4
sph=0
EndIf
If sph=0
Gosub lire
EndIf
If sph=0
Plot(i,u,RGB(sph2,sph4,sph6))
EndIf
If sph=1
Plot(i,u,RGB(sph7,sph12,sph14))
EndIf
If sph=2
Plot(i,u,RGB(sph16,sph17,sph22))
EndIf
If sph=3
Plot(i,u,RGB(sph24,sph26,sph27))
EndIf
Next
Next
StopDrawing()
SaveImage(0,"c:\Users\SPH\Desktop\24.bmp.rvb.bmp")
;##############################################################
;##############################################################
;##############################################################
;##############################################################
End
lire:
sph1=ReadByte(#src)
sph3=ReadByte(#src)
sph5=ReadByte(#src)
sph11=ReadByte(#src)
sph13=ReadByte(#src)
sph15=ReadByte(#src)
sph21=ReadByte(#src)
sph23=ReadByte(#src)
sph25=ReadByte(#src)
!MOV byte al,[v_sph1]
!shr al,2
!MOV byte [v_sph2],al
!MOV byte ah,[v_sph1]
!MOV byte al,[v_sph3]
!shl ax,6
!shr ax,10
!MOV byte [v_sph4],al
!MOV byte ah,[v_sph3]
!MOV byte al,[v_sph5]
!shl ax,4
!shr ax,10
!MOV byte [v_sph6],al
!MOV byte al,[v_sph5]
!shl al,2
!shr al,2
!MOV byte [v_sph7],al
;===============
!MOV byte al,[v_sph11]
!shr al,2
!MOV byte [v_sph12],al
!MOV byte ah,[v_sph11]
!MOV byte al,[v_sph13]
!shl ax,6
!shr ax,10
!MOV byte [v_sph14],al
!MOV byte ah,[v_sph13]
!MOV byte al,[v_sph15]
!shl ax,4
!shr ax,10
!MOV byte [v_sph16],al
!MOV byte al,[v_sph15]
!shl al,2
!shr al,2
!MOV byte [v_sph17],al
;===============
!MOV byte al,[v_sph21]
!shr al,2
!MOV byte [v_sph22],al
!MOV byte ah,[v_sph21]
!MOV byte al,[v_sph23]
!shl ax,6
!shr ax,10
!MOV byte [v_sph24],al
!MOV byte ah,[v_sph23]
!MOV byte al,[v_sph25]
!shl ax,4
!shr ax,10
!MOV byte [v_sph26],al
!MOV byte al,[v_sph25]
!shl al,2
!shr al,2
!MOV byte [v_sph27],al
;===============
sph2*4
sph4*4
sph6*4
sph7*4
sph12*4
sph14*4
sph16*4
sph17*4
sph22*4
sph24*4
sph26*4
sph27*4
Return
;========================================