Recent

Author Topic: problems with pf32bit in linux version of a TBitmap.  (Read 5898 times)

dcelso

  • Full Member
  • ***
  • Posts: 158
problems with pf32bit in linux version of a TBitmap.
« on: January 28, 2013, 01:30:41 pm »
Hello to all,
I have problems in linux converting a 32 tbitmap in a tlazintfimage and after reconverting it  in 32bit tbitmap.
After of the conversion form tlazfintfimage to TBitma, the bitmat is a 24bit black image.
In lazarus windows this does not happen.
The example code is the next:
Code: [Select]
*unit1.lfm*
********
object Form1: TForm1
  Left = 247
  Height = 402
  Top = 208
  Width = 546
  Caption = 'Form1'
  ClientHeight = 402
  ClientWidth = 546
  LCLVersion = '1.1'
  object Image1: TImage
    Left = 32
    Height = 250
    Top = 48
    Width = 224
  end
  object Label1: TLabel
    Left = 320
    Height = 15
    Top = 176
    Width = 34
    Caption = 'Label1'
    ParentColor = False
  end
  object Label2: TLabel
    Left = 320
    Height = 15
    Top = 212
    Width = 34
    Caption = 'Label2'
    ParentColor = False
  end
  object Label3: TLabel
    Left = 323
    Height = 15
    Top = 244
    Width = 34
    Caption = 'Label3'
    ParentColor = False
  end
  object Button1: TButton
    Left = 312
    Height = 25
    Top = 96
    Width = 75
    Caption = 'Button1'
    OnClick = Button1Click
    TabOrder = 0
  end
  object Button2: TButton
    Left = 408
    Height = 25
    Top = 96
    Width = 75
    Caption = 'Button2'
    OnClick = Button2Click
    TabOrder = 1
  end
end


* unit.pas*
*********^

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  Buttons, FPimage,IntfGraphics, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }



procedure TForm1.Button1Click(Sender: TObject);
var
   bmp: TBitmap;
   i,j : integer;
   lazBMP: TLazIntfImage;
begin
     bmp:= TBitmap.Create;
     bmp.PixelFormat:=pf32bit;
     bmp.SetSize(100,100);
     lazBMP:=bmp.CreateIntfImage;
     Label1.Caption:='before:'+inttostr(PIXELFORMAT_BPP[bmp.PixelFormat]);

     for i:=0 to 99 do
          for j:=0 to 99 do
                  lazBMP.Colors[i,j] := colYellow;

     for i:=40 to 89 do
          for j:=40 to 89 do
                  lazBMP.Colors[i,j] := colRed;

     for i:=45 to 55 do
          for j:=45 to 55 do
                  lazBMP.Colors[i,j] := colTransparent;

     bmp.LoadFromIntfImage(lazBMP);
     Label2.Caption:='after:'+inttostr(PIXELFORMAT_BPP[bmp.PixelFormat]);
     lazBMP.free;
     Image1.Picture.Assign(bmp);
     Label3.Caption:='in Timage:'+inttostr(PIXELFORMAT_BPP[bmp.PixelFormat]);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
   bmp: TBitmap;
   i,j : integer;
begin
     bmp:= TBitmap.Create;
     bmp.PixelFormat:=pf32bit;
     bmp.SetSize(100,100);
     Label1.Caption:='before:'+inttostr(PIXELFORMAT_BPP[bmp.PixelFormat]);

     for i:=0 to 99 do
          for j:=0 to 99 do
                  bmp.canvas.Colors[i,j] := colYellow;

     for i:=40 to 89 do
          for j:=40 to 89 do
                  bmp.canvas.Colors[i,j] := colRed;

     for i:=45 to 55 do
          for j:=45 to 55 do
                  bmp.canvas.Colors[i,j] := colTransparent;

     bmp.LoadFromIntfImage(bmp.CreateIntfImage);
     Image1.Picture.Assign(bmp);

     label2.Caption:='';
     Label3.Caption:='in Timage:'+inttostr(PIXELFORMAT_BPP[bmp.PixelFormat]);
end;

end.
In the example if you press button 1 on linux version, you can see that after of loadfromintfimage, the bitmat is wrong. On windows version it run correcly.

Any one know what is the problem?




User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: problems with pf32bit in linux version of a TBitmap.
« Reply #1 on: January 28, 2013, 01:59:00 pm »
That would be weird if it works on Windows. TBitmap or BMP format in general, does not support transparency. You can have transparent key though for 1 color value, but nothing like PNG's true alpha channel.

dcelso

  • Full Member
  • ***
  • Posts: 158
Re: problems with pf32bit in linux version of a TBitmap.
« Reply #2 on: January 28, 2013, 03:27:49 pm »
That would be weird if it works on Windows. TBitmap or BMP format in general, does not support transparency. You can have transparent key though for 1 color value, but nothing like PNG's true alpha channel.
You are very very uninformed. TBitmap (and bmp format) alway supports alpha channel.
« Last Edit: January 28, 2013, 03:30:08 pm by dcelso »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: problems with pf32bit in linux version of a TBitmap.
« Reply #3 on: January 28, 2013, 04:18:55 pm »
You're partially right it seems. Gimp can save and load alpha-channeled bmp's, and TImage on Windows at least can draw them aswell. Explorer and Windows (7) Photo Viewer can't show them with alpha. You might have encountered a bug.

dcelso

  • Full Member
  • ***
  • Posts: 158
Re: problems with pf32bit in linux version of a TBitmap.
« Reply #4 on: January 28, 2013, 05:33:41 pm »
You're partially right it seems. Gimp can save and load alpha-channeled bmp's, and TImage on Windows at least can draw them aswell. Explorer and Windows (7) Photo Viewer can't show them with alpha. You might have encountered a bug.
:'(

ddemarco

  • Newbie
  • Posts: 2
Re: problems with pf32bit in linux version of a TBitmap.
« Reply #5 on: May 17, 2013, 05:25:54 am »
I confirm this problem, with an addition: it seems to depend on the size of the bitmap in question. Working on a 200 x 200 pixels image is fine, but if fails on a 199 x 200 bitmap. Several tests I've performed show that transparency seems to work only if the width is a multiple of 8, so I guess it could have to do with alignment or something of the sort.

I also confirm that the problem seems to exist only in linux. Running the same in Win32 works fine every time.

If a bug is not reported yet in relation to this, I'll go ahead and post one now.

Cheers,
Diego


ddemarco

  • Newbie
  • Posts: 2
Re: problems with pf32bit in linux version of a TBitmap.
« Reply #6 on: May 17, 2013, 06:59:40 am »
I've found an ADMITTEDLY DIRTY workaround:
1) Create your Bitmap as needed, ensuring that its width IS A MULITPLE OF 8 PIXELS.
2) Work on your bitmap as needed.
3) Obtain a TLazIntfImage from the bitmap.
4) Create another graphical object (I tried only with TPortableNetworkGraphic)
5) Load from the TLazInfImage obtained in step 3.
6) Resize as needed (for instance, reduce the width so that it's no longer a multiple of 8 ).
7) Save this graphic.
8 ) At this point, the image saved will retain its transparency, even though its width is no longer a multiple of 8 pixels.

I tried this workaround in Ubuntu, and it certainly does the trick. Yes, it's dirty, but at least I got my problem solved...

Cheers,
Diego

 

TinyPortal © 2005-2018