Page 6 sur 6

Re: Image Optimizer

Publié : mar. 08/mars/2016 8:14
par Micoute
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.

Re: Image Optimizer

Publié : mar. 08/mars/2016 9:22
par Shadow
Sauf que ça marche pas ça hein.
Plusieurs pixel peuvent avoir un canal alpha différent fais attention à ça !

Re: Image Optimizer

Publié : mar. 08/mars/2016 9:33
par djes
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.

Ceux qui disent que dans un fichier, on en revient toujours à des données codées sur des octets, ont tort. Je leur conseille de faire par eux-mêmes un packer type LZH, et ils verront qu'on travaille par bit, et non pas par octet. C'est d'ailleurs pour cela que la plupart de ces compresseurs sont lents. L'adressage se fait par octet, les données peuvent avoir des tailles variables, en bits.

Par contre, Shadow s'embrouille avec les fichiers, passe par du texte, ne fait pas vraiment la différence entre la compression utilisée dans un png, un jpeg, un 7zip, un zip, etc. Ce n'est pas bien grave, il apprendra.

Re: Image Optimizer

Publié : mar. 08/mars/2016 10:32
par Micoute
Tu as raison djes, c'est en forgeant qu'on devient forgeron, quand j'ai mal à l'intestin, je n'appelle pas le plombier, car ce ne sont pas les mêmes tuyaux !

Re: Image Optimizer

Publié : mar. 08/mars/2016 11:32
par Shadow
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.
Exactement, c'est tout à fait ça !

Alors, l'or de l'encodage, tu enlève un bit par composante (Le dernier).
L'or du décodage, tu rajoute un bit (A la fin) par composante.
Le tour est jouer !

Tu pers au maximum 1 par composante en faisant ça.
La qualité de l'image est encore excellente, presque indeme.

Re: Image Optimizer

Publié : dim. 13/mars/2016 7:06
par SPH
Bon, je ne sais pas ou ca a buggué mais voici le resultat mediocre de mes recherches :

Image

Image



Code pour compresser :

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 pour decompresser :

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
                         
               
;========================================
                 
                 

Re: Image Optimizer

Publié : dim. 13/mars/2016 9:47
par Ollivier
Acid wash effect...

Re: Image Optimizer

Publié : dim. 13/mars/2016 10:28
par SPH
Le bmp fait 2359350 octets
Le format data fait 1769480 octets

Ca compresse donc d'un quart mais comme la qualité n'est pas au rendez vous, j'abandonne le projet.

Ca devrais pourtant marcher mieux mais je ne trouve pas le bug :|

Ca a le merite de m'avoir replongé dans l'ASM et ca, c'est cool 8)