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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 ColorReduce with Dithering to 9bit colors

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
HeartWare Posted - May 19 2020 : 06:11:07

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...
6   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - May 21 2020 : 21:37:21
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
HeartWare Posted - May 20 2020 : 22:53:52
> 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.
xequte Posted - May 20 2020 : 20:31:33
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
HeartWare Posted - May 20 2020 : 12:33:31
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;

HeartWare Posted - May 20 2020 : 01:29:29
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?
xequte Posted - May 19 2020 : 16:48:33
Hi

Please see the examples for ConvertTo:

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


Nigel
Xequte Software
www.imageen.com