1 pièce(s) jointe(s)
Problèmes de rendu avec TLazIntfImage
Bonsoir,
Je me suis récemment créé un fichier graphique pour faire des tests, et je suis tombé sur un comportement curieux avec TLazInftImage et le code fourni dans l'aide pour lire/écrire un fichier .xpm.
Partant de ce fichier de tests créé avec The Gimp, j'en ai généré ensuite un .bmp ainsi qu'un .xpm, qu'on va appeler "original" et qui m'a servi de point de départ pour tester le code fourni dans l'aide (après corrections, voir mon post à ce propos).
Le code Lazarus a bien créé un fichier copié_par_code.xpm et il a juste 21 bytes de moins que l'original.
L'original ayant une taille de 800x600, le .bmp pèse 1 920 122 octets et le .xpm 3 036 754 octets.
Je résume les soucis dans ce tableau, mais déjà un mot à titre de comparaison, concernant la rapidité d'ouverture de The Gimp : un fichier .jp2 (fichier de vue aérienne fourni par l'IGN, qui serait un .jpeg surcompressé) de 7 Mo s'ouvre en 5 à 7 secondes, et regardez maintenant le tableau :
Code:
1 2 3 4 5
| Ouverture avec | Fichier original | Fichier copié_par_code
---------------|-----------------------|--------------------------
The Gimp |instantanée | rendu OK |35 secondes | rendu OK
ImageMagick |instantanée | rendu OK |instantanée | rendu abimé
Code Lazarus |instantanée | rendu OK |instantanée | rendu OK |
En ce qui concerne le "rendu abimé", vous pouvez le voir au bas de ce montage où se trouve en haut l'original :
Pièce jointe 252278
Note : le montage de ces deux images est réduit de moitié, inutile d'encombrer. Si quelqu'un veut les fichiers originaux, il suffit de demander.
Voilà.
Entre The Gimp qui met 35 secondes (une éternité quand on est devant l'écran...) et ImageMagick qui me massacre le bas, j'aurais tendance à penser que le fichier généré par le code Lazarus n'est peut-être pas au mieux de sa forme.
Et à partir de là, que faire ? Que chercher ? Où ?
J'ai fait deux tests sous XP, avec ImageMagick (version un poil plus récente que celle du tableau sous Linux) et avec XnView : l'original comme la copie s'ouvrent vite et parfaitement.
Annexe : les codes -- le premier c'est celui de l'aide, le second c'est juste la partie "lecture" du premier.
1 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| uses
GraphType, IntfGraphics;
procedure TForm1.Button8Click(Sender: TObject);
var
BmpHnd, MaskHnd: HBitmap;
Bitmap1 : TBitmap;
IntfImg1: TLazIntfImage;
Reader: TLazReaderXPM;
Writer: TLazWriterXPM;
begin
//1. Loading a .xpm file into a TBitmap:
Bitmap1 := TBitmap.Create; // create a bitmap (or use an existing one)
IntfImg1 := TLazIntfImage.Create(0,0); // create the raw image
IntfImg1.DataDescription := GetDescriptionFromDevice(0);
Reader := TLazReaderXPM.Create; // create the XPM reader
IntfImg1.LoadFromFile('bmp4test255.xpm', Reader); // load the image
IntfImg1.CreateBitmaps(BmpHnd, MaskHnd, True); // True au pif - concerne SkipMask
Bitmap1.Handle := BmpHnd; // apply handles to the Bitmap1
Bitmap1.MaskHandle := MaskHnd;
Reader.Free; // clean up
// do something with the Bitmap1
//...
//2. Saving a TBitmap to a .xpm file:
IntfImg1.LoadFromBitmap(Bitmap1.Handle,Bitmap1.MaskHandle); // load the raw image from the bitmap handles
Writer := TLazWriterXPM.Create; // create the XPM writer
IntfImg1.SaveToFile('filename.xpm', Writer); // save image to file
// OK, juste un poil long à écrire,
// et très looooooooooooooong à ouvrir avec The Gimp (env. 35 sec !)
Writer.Free; // clean up
IntfImg1.Free;
Bitmap1.Free;
end; |
2 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| procedure TForm1.Button9Click(Sender: TObject);
var
BmpHnd, MaskHnd: HBitmap;
Bitmap1 : TBitmap;
IntfImg1: TLazIntfImage;
Reader: TLazReaderXPM;
begin
//1. Loading a .xpm file into a TBitmap:
Bitmap1 := TBitmap.Create; // create a bitmap (or use an existing one)
IntfImg1 := TLazIntfImage.Create(0,0); // create the raw image
IntfImg1.DataDescription := GetDescriptionFromDevice(0);
Reader := TLazReaderXPM.Create; // create the XPM reader
// IntfImg1.LoadFromFile('filename.xpm', Reader); // load the image
// aussi rapide avec l'original dessous qu'avec la copie dessus
IntfImg1.LoadFromFile('bmp4test255.xpm', Reader); // load the image
IntfImg1.CreateBitmaps(BmpHnd, MaskHnd, False); // False dans wiki - concerne SkipMask
Bitmap1.Handle := BmpHnd; // apply handles to the Bitmap1
Bitmap1.MaskHandle := MaskHnd;
Reader.Free; // clean up
// do something with the Bitmap1
//...
Image1.Picture.Bitmap.LoadFromIntfImage(IntfImg1);
IntfImg1.Free;
Bitmap1.Free;
end; |