ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Getting the BitDepth (32, 24, 8, 4) after an Undo
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

w2m

USA
1990 Posts

Posted - Jul 20 2012 :  06:26:31  Show Profile  Reply
One of the problems I have had for years is getting the bitdepth of a bitmap in ImageEnView when converting from 32-bit to 24-bit, 8-bit and 4-bit after an undo.

After an undo you can use if ImageEnView1.IEBitmap.HasAlphaChannel then iBitDepth := 32 so it it easy to know if the image is 32-bit. But if the image does not have an alphachannel after an undo, how can you get the bitdepth?

IEBitmap BitCount is always 24 after an undo if the image does not have an alphachannel so the following does not work:

if ImageEnView1.IEBitmap.HasAlphaChannel then begin
  iBitDepth := 32;
  ImageEnView1.IO.Params.BitsPerSample := 8;
  ImageEnView1.IO.Params.SamplesPerPixel := 4;
end
else
begin
  iBitDepth := ImageEnView1.IEBitmap.BitCount;
  if iBitDepth = 24 then
  begin
    ImageEnView1.IO.Params.BitsPerSample := 8;
    ImageEnView1.IO.Params.SamplesPerPixel := 3;
  end
  else if iBitDepth = 8 then
  begin
    ImageEnView1.IO.Params.BitsPerSample := 8;
    ImageEnView1.IO.Params.SamplesPerPixel := 1;
  end
  else if iBitDepth = 4 then
  begin
    ImageEnView1.IO.Params.BitsPerSample := 4;
    ImageEnView1.IO.Params.SamplesPerPixel := 1;
  end;
end;

The question is how to get the correct bitdepth of an image after an undo?

William Miller

fab

1310 Posts

Posted - Jul 20 2012 :  12:42:07  Show Profile  Reply
You could check ImageEnView1.IEBitmap.PixelFormat:

case ImageEnView1.PixelFormat of
  ie1g:
    begin
      ImageEnView1.IO.Params.BitsPerSample := 1;
      ImageEnView1.IO.Params.SamplesPerPixel := 1;
    end;
  ie8p, ie8g:
    begin
      ImageEnView1.IO.Params.BitsPerSample := 8;
      ImageEnView1.IO.Params.SamplesPerPixel := 1;
    end;
  ie16g:
    begin
      ImageEnView1.IO.Params.BitsPerSample := 16;
      ImageEnView1.IO.Params.SamplesPerPixel := 1;
    end;
  ie24RGB, ie32RGB, ieCIELab:
    begin
      ImageEnView1.IO.Params.BitsPerSample := 8;
      ImageEnView1.IO.Params.SamplesPerPixel := 3;
    end;
  ie32f:
    begin
      ImageEnView1.IO.Params.BitsPerSample := 32;
      ImageEnView1.IO.Params.SamplesPerPixel := 1;
    end;
  ieCMYK:
    begin
      ImageEnView1.IO.Params.BitsPerSample := 8;
      ImageEnView1.IO.Params.SamplesPerPixel := 4;
    end;
  ie48RGB:
    begin
      ImageEnView1.IO.Params.BitsPerSample := 16;
      ImageEnView1.IO.Params.SamplesPerPixel := 3;
    end;
end;
if ImageEnView1.IEBitmap.HasAlphaChannel then
  ImageEnView1.IO.Params.SamplesPerPixel  := ImageEnView1.IO.Params.SamplesPerPixel  + 1;

Go to Top of Page

w2m

USA
1990 Posts

Posted - Jul 20 2012 :  14:23:48  Show Profile  Reply
Thanks Fabrizio... Is there no way to determine 4-bit?
ImageEnView.IO.Params.BitsPerSample := 4;
ImageEnView.IO.Params.SamplesPerPixel := 1;

William Miller
Go to Top of Page

fab

1310 Posts

Posted - Jul 21 2012 :  00:57:34  Show Profile  Reply
If the image has been loaded with following parameters...
ImageEnView.LegacyBitmap := false;
ImageEnView.IO.NativePixelFormat := true;

...then you can use PaletteUsed property of TIEBitmap:

ImageEnView1.IO.Params.BitsPerSample := trunc(log2( ImageEnView1.IEBitmap.PaletteUsed));

PaletteUsed returns number of colors used in the palette. So, if it is 16, then log2(16) = 4, that is 4 bits.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Jul 21 2012 :  06:53:22  Show Profile  Reply
It is possible to get the bitdepth of 4-bit if using the default of ImageEnView.LegacyBitmap := true and ImageEnView.IO.NativePixelFormat := false?

The images are loaded with ImageEnView.IO.LoadFromFile();

I set 4-bit by:
ImageEnView.IO.Params.BitsPerSample := 4;
ImageEnView.IO.Params.SamplesPerPixel := 1;
ImageEnView.IO.Params.ICO_BitCount[cxPageControl1.ActivePageIndex] := 4;
if ImageEnView.HasAlphaChannel then
ImageEnView.RemoveAlphaChannel;


William Miller
Go to Top of Page

fab

1310 Posts

Posted - Jul 21 2012 :  23:10:21  Show Profile  Reply
quote:
It is possible to get the bitdepth of 4-bit if using the default of ImageEnView.LegacyBitmap := true and ImageEnView.IO.NativePixelFormat := false?


Unfortunately no, because when LegacyBitmap=true and NativePixelFormat=false pixels formats can be only ie24RGB (pf24bit) or ie1g (pf1bit).
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: