Recent

Author Topic: New version of BGRABitmap  (Read 284696 times)

Phoenix

  • Jr. Member
  • **
  • Posts: 87
Re: New version of BGRABitmap
« Reply #630 on: August 21, 2022, 02:27:11 pm »
Thanks for the current version and also for the previous releases  :D!

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: New version of BGRABitmap
« Reply #631 on: August 21, 2022, 07:23:23 pm »
You're very welcome  :)
Conscience is the debugger of the mind

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Re: New version of BGRABitmap
« Reply #632 on: August 29, 2022, 11:30:10 am »
New OS installed, Linux Debian 11 based. Lazarus 2.2.2., fpc 3.2.3 fixes.
I try to install BGRA from OPM, I get an error in the .inc auto generated files:

generatedcolorspace.inc:
Code: Pascal  [Select][+][-]
  1. class function TColorColorspace.GetChannel(AColor: Pointer; AIndex: integer): single;
  2. begin
  3.   case AIndex of
  4.   0: result := TColor(AColor^).red;

Error is:
generatedcolorspace.inc(2684,32) Error: Illegal qualifier
pointing to red (green and blue).
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: New version of BGRABitmap
« Reply #633 on: August 31, 2022, 07:38:55 pm »
Seems that in dev version of FPC type helpers don’t work with scalar. Not sure if this is a bug or a feature.
Conscience is the debugger of the mind

ginky

  • Newbie
  • Posts: 6
Re: New version of BGRABitmap
« Reply #634 on: October 05, 2022, 04:34:28 pm »
Hi

I found a bug but not sure.

Loading BMP image file with compresson method OS22XBITMAPHEADER: Huffman 1D (Offset 1E, Value 3) results in colors artifacts on drawed image.
With HEX editor I've changed Value to 0 (Compression method - none). After that the image drawed perfect.

Lools like BGRABitmap does not have support for older compression methods.

edit1. How I can fix that?

Thanks
« Last Edit: October 05, 2022, 06:06:46 pm by ginky »

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: New version of BGRABitmap
« Reply #635 on: October 05, 2022, 08:17:35 pm »
Hi,

I am a bit confused. Are you saying that changing the number indicating the compression method shows the image perfectly? That would mean that in fact the bitmap is not compressed.

Can you provide the image as attachment?

It is possible to change the reader to handle new formats.

Regards
Conscience is the debugger of the mind

ginky

  • Newbie
  • Posts: 6
Re: New version of BGRABitmap
« Reply #636 on: October 05, 2022, 08:37:52 pm »
Hi,

I am a bit confused. Are you saying that changing the number indicating the compression method shows the image perfectly? That would mean that in fact the bitmap is not compressed.

Can you provide the image as attachment?

It is possible to change the reader to handle new formats.

Regards

I don't know bmp format well enough but image viewers open my file without errors (before and after editing).

File too big so compressed (it's texture).

https://drive.google.com/file/d/1EvXnqMiJkYZ79Qw3BQaKcD6f-HdYA1pn/view?usp=sharing


circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: New version of BGRABitmap
« Reply #637 on: October 06, 2022, 07:50:12 am »
Ok so this is not a compressed image. Method 3 indicated at position 30 is BI_BITFIELDS which specifies where to get the red/green/blue components in each pixel data. But those bit fields (at position 138) are not set properly, they indicate RGB order whereas this file, as it is generally the case for BMP, is in BGR order. So when you load it you get those colors swapped.

In LazPaint, you can see that by swapping red and blue colors using "filter function". Or by code using SwapRedBlue function.

You can indeed fix the file either by setting 0 as compression method, or by changing the bit fields to 0000FF00 00FF0000 FF000000 instead of FF000000 00FF0000 0000FF00.
Conscience is the debugger of the mind

ginky

  • Newbie
  • Posts: 6
Re: New version of BGRABitmap
« Reply #638 on: October 06, 2022, 09:55:23 am »
Hi,

Thanks for explanation.

I have no way to fix the file in production so is there any way to fix this by BGRABitmap?

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: New version of BGRABitmap
« Reply #639 on: October 06, 2022, 01:32:19 pm »
Yes, as I mentioned, you can call bmp.SwapRedBlue after loading the file where bmp is your TBGRABitmap object.
Conscience is the debugger of the mind

ginky

  • Newbie
  • Posts: 6
Re: New version of BGRABitmap
« Reply #640 on: October 06, 2022, 02:27:31 pm »
Yes, as I mentioned, you can call bmp.SwapRedBlue after loading the file where bmp is your TBGRABitmap object.

Hmm....but how I can detect wrong RGB order? :)

edit.1 Solved a problem. Before displaying the file, first I read it in memory and change the compression flag.
« Last Edit: October 07, 2022, 11:17:28 am by ginky »

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: New version of BGRABitmap
« Reply #641 on: October 08, 2022, 11:02:14 am »
Ok yeah that's one way to solve the problem as it seems anyway the data is always in the BGR order.
Conscience is the debugger of the mind

Josh

  • Hero Member
  • *****
  • Posts: 1270
Re: New version of BGRABitmap
« Reply #642 on: November 08, 2022, 06:42:03 pm »
Hi

Just tried to update my fpc and laz fixes to latest using fpcupdeluxe
andam getting

Code: Pascal  [Select][+][-]
  1. M:\LazarusFixes32\config_lazarus\onlinepackagemanager\packages\bgrabitmap-master\bgrabitmap\generatedcolorspace.inc(2684,32) Error: (3205) Illegal qualifier
  2. (3104) Compiling fpdbghardcodedfreepascalinfo.pas
  3. (3104) Compiling syncompletion.pas
  4. (3104) Compiling synedit.pp
  5. (3104) Compiling lazsynimmbase.pas
  6. (3104) Compiling lazsynimm.pas
  7. (3104) Compiling syntextdrawer.pp
  8. M:\LazarusFixes32\config_lazarus\onlinepackagemanager\packages\bgrabitmap-master\bgrabitmap\generatedcolorspace.inc(2685,32) Error: (3205) Illegal qualifier
  9. M:\LazarusFixes32\config_lazarus\onlinepackagemanager\packages\bgrabitmap-master\bgrabitmap\generatedcolorspace.inc(2686,32) Error: (3205) Illegal qualifier
  10. M:\LazarusFixes32\config_lazarus\onlinepackagemanager\packages\bgrabitmap-master\bgrabitmap\generatedcolorspace.inc(2694,22) Error: (3205) Illegal qualifier
  11. M:\LazarusFixes32\config_lazarus\onlinepackagemanager\packages\bgrabitmap-master\bgrabitmap\generatedcolorspace.inc(2695,22) Error: (3205) Illegal qualifier
  12. M:\LazarusFixes32\config_lazarus\onlinepackagemanager\packages\bgrabitmap-master\bgrabitmap\generatedcolorspace.inc(2696,22) Error: (3205) Illegal qualifier

Any fix for this
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: New version of BGRABitmap
« Reply #643 on: November 12, 2022, 07:16:53 am »
Hello Josh,

This is a bug with development version of FPC:
https://gitlab.com/freepascal.org/fpc/source/-/issues/38678

You can avoid this problem by replacing the functions TColorColorspace.GetChannel and TColorColorspace.SetChannel by the following:
Code: Pascal  [Select][+][-]
  1. class function TColorColorspace.GetChannel(AColor: Pointer; AIndex: integer): single;
  2. begin
  3.   case AIndex of
  4.   0: result := {$IFDEF TCOLOR_BLUE_IN_LOW_BYTE}(TColor(AColor^) shr 16) and $ff{$ELSE}TColor(AColor^) and $ff{$ENDIF};
  5.   1: result := (TColor(AColor^) shr 8) and $ff;
  6.   2: result := {$IFDEF TCOLOR_BLUE_IN_LOW_BYTE}TColor(AColor^) and $ff{$ELSE}(TColor(AColor^) shr 16) and $ff{$ENDIF};
  7.   else raise ERangeError.Create('Index out of bounds');
  8.   end;
  9. end;
  10.  
  11. class procedure TColorColorspace.SetChannel(AColor: Pointer; AIndex: integer; AValue: single);
  12. var channelValue: byte;
  13. begin
  14.   channelValue := Round(Clamp(AValue,0,255));
  15.   case AIndex of
  16.   0: TColor(AColor^) := {$IFDEF TCOLOR_BLUE_IN_LOW_BYTE}(LongWord(AColor^) and $00ffff) or (channelValue shl 16){$ELSE}(LongWord(AColor^) and $ffff00) or channelValue{$ENDIF};
  17.   1: TColor(AColor^) := (LongWord(AColor^) and $ff00ff) or (channelValue shl 8);
  18.   2: TColor(AColor^) := {$IFDEF TCOLOR_BLUE_IN_LOW_BYTE}(LongWord(AColor^) and $ffff00) or channelValue{$ELSE}(LongWord(AColor^) and $00ffff) or (channelValue shl 16){$ENDIF};
  19.   else raise ERangeError.Create('Index out of bounds');
  20.   end;
  21. end;

I have patched temporarily the file on the dev branch:
https://github.com/bgrabitmap/bgrabitmap/commit/fe96b8371178cf9cd8c980ced92f3d2f4051e457
« Last Edit: November 12, 2022, 07:22:40 am by circular »
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: New version of BGRABitmap
« Reply #644 on: November 12, 2022, 07:19:05 am »
New version of BGRABitmap (11.5.3) :
https://github.com/bgrabitmap/bgrabitmap/releases

It is an update to handle latest version of LibAvif. Thanks to DomingoGP for the pull request  :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018