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
 ColorReduce with Dithering to 9bit colors
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

HeartWare

Denmark
46 Posts

Posted - May 19 2020 :  06:11:07  Show Profile  Reply

How to I color-reduce a 24bit (8 bits per primary color) image to an 8bit (with 256 colors from a palette consisting of 3 bits per primary color)?

Ie. I have a 9-bit palette and need to reduce a 24bit image to an 8bit image with optimal 256 colors selected from this 9bit palette, and dithering applied where needed...

xequte

38182 Posts

Posted - May 19 2020 :  16:48:33  Show Profile  Reply
Hi

Please see the examples for ConvertTo:

https://www.imageen.com/help/TImageEnProc.ConvertTo.html


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

HeartWare

Denmark
46 Posts

Posted - May 20 2020 :  01:29:29  Show Profile  Reply
Already have...

I don't see an option to use optimized 256-color palette from a 3-3-3 (512 entries) RGB palette. Could you elaborate?
Go to Top of Page

HeartWare

Denmark
46 Posts

Posted - May 20 2020 :  12:33:31  Show Profile  Reply
I have tried this, but it doesn't work (produces an all-black image):

FUNCTION ConvertTo9bit(BMP : TBitMap) : TBitMap;
  VAR
    Palette	: ARRAY[0..511] OF TRGB;
    I		: Cardinal;
    R,G,B	: BYTE;

  BEGIN
    I:=LOW(Palette);
    FOR R:=0 TO 2 DO FOR G:=0 TO 2 DO FOR B:=0 TO 2 DO Palette[PostInc(I)].Initialize(R,G,B);
    PROC.AtttachedBitMap:=BMP;
    PROC.ConvertTo(TIEPixelFormat.ie8p,Palette,TIEDitherType.iedtErrorDiffusion);
    Result:=BMP
  END;

Go to Top of Page

xequte

38182 Posts

Posted - May 20 2020 :  20:31:33  Show Profile  Reply
Hi

To clarify, you only specify an output palette. ImageEn uses the existing colors as the input palette.

But you are not generating a valid output palette.

For ie8p format the array should be array[0..255] of TRGB.

Also your for next loop only generates 3^3=27 entries all of which are very close to black.


Are any of these built-in palettes suitable:

https://www.imageen.com/help/TIEPaletteType.html


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

HeartWare

Denmark
46 Posts

Posted - May 20 2020 :  22:53:52  Show Profile  Reply
> For ie8p format the array should be array[0..255] of TRGB.

No - because I want the routine to select the 256 colors from an available palette of 512 colors...

> Also your for next loop only generates 3^3=27 entries all of which are very close to black.

A transcription error when trying to simplify the actual routine. Here's an update:

FUNCTION ConvertTo9bit(BMP : TBitMap) : TBitMap;
  CONST
    Intensity	: ARRAY[0..7] OF BYTE = (0,36,73,109,146,182,219,255);

  VAR
    Palette	: ARRAY[0..511] OF TRGB;
    I		: Cardinal;
    R,G,B	: BYTE;

  BEGIN
    I:=LOW(Palette);
    FOR R:=0 TO 7 DO FOR G:=0 TO 7 DO FOR B:=0 TO 7 DO Palette[PostInc(I)].Initialize(Intensity[R],Intensity[G],Intensity[B]);
    PROC.SetBMP(BMP);
    PROC.ConvertTo(TIEPixelFormat.ie8p,Palette,TIEDitherType.iedtErrorDiffusion);
    Result:=BMP
  END;

As you can see (now), the palette I'm making is 512 entries, each with 8 different levels of Red, Green and Blue components. I would like the image color reduced to 256 of these 512 possible values (chosen by the ConvertTo method based on the current pixels in the image) and using dithering among these selected 256 colors to simulate the remaining 2^24-256 colors.

> https://www.imageen.com/help/TIEPaletteType.html

None of these palettes are 512 entries of variying levels of RGB, so no.
Go to Top of Page

xequte

38182 Posts

Posted - May 21 2020 :  21:37:21  Show Profile  Reply
OK, thanks. I see what you mean. The Conversion methods only support palettes of up to 256 colors. So you will either need to reduce the size of your palette, or iterate through the image updating the color of each pixel with the nearest one from your 512 color palette.


Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: