Skip to content

Commit e199eb6

Browse files
committed
Apply dithering pre-pass prior to clustering...
... and make -20/Log[10] constant decimal instead of hexadecimal for compatibility
1 parent 1ba15c4 commit e199eb6

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

tilequant.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int main(int argc, const char *argv[]) {
149149

150150
//! Perform processing
151151
//! NOTE: PxData and Palette will be assigned to image; do NOT destroy
152-
struct TilesData_t *TilesData = TilesData_FromBitmap(&Image, TileW, TileH);
152+
struct TilesData_t *TilesData = TilesData_FromBitmap(&Image, TileW, TileH, &BitRange, DitherMode, DitherLevel);
153153
uint8_t *PxData = malloc(Image.Width * Image.Height * sizeof(uint8_t));
154154
struct BGRAf_t *Palette = calloc(BMP_PALETTE_COLOURS, sizeof(struct BGRAf_t));
155155
if(!TilesData || !PxData || !Palette) {
@@ -179,10 +179,10 @@ int main(int argc, const char *argv[]) {
179179

180180
//! Output PSNR
181181
#if MEASURE_PSNR
182-
RMSE.b = -0x1.15F2CFp3f*logf(RMSE.b / 255.0f); //! -20*Log10[RMSE/255] == -20/Log[10] * Log[RMSE/255]
183-
RMSE.g = -0x1.15F2CFp3f*logf(RMSE.g / 255.0f);
184-
RMSE.r = -0x1.15F2CFp3f*logf(RMSE.r / 255.0f);
185-
RMSE.a = -0x1.15F2CFp3f*logf(RMSE.a / 255.0f);
182+
RMSE.b = -8.68588963f*logf(RMSE.b / 255.0f); //! -20*Log10[RMSE/255] == -20/Log[10] * Log[RMSE/255]
183+
RMSE.g = -8.68588963f*logf(RMSE.g / 255.0f);
184+
RMSE.r = -8.68588963f*logf(RMSE.r / 255.0f);
185+
RMSE.a = -8.68588963f*logf(RMSE.a / 255.0f);
186186
printf("PSNR = {%.3fdB, %.3fdB, %.3fdB, %.3fdB}\n", RMSE.b, RMSE.g, RMSE.r, RMSE.a);
187187
#else
188188
(void)RMSE;

tilequantDLL.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ DECLSPEC int QualetizeFromRawImage(
6161
//! Do processing
6262
//! NOTE: Do NOT allow image replacing, or things will go
6363
//! very wrong when Qualetize() tries to free the pointers.
64-
struct TilesData_t *TilesData = TilesData_FromBitmap(&Ctx, TileW, TileH);
64+
struct TilesData_t *TilesData = TilesData_FromBitmap(&Ctx, TileW, TileH, (const struct BGRA8_t*)BitRange, DitherMode, DitherLevel);
6565
if(!TilesData) return 0;
6666
(void)Qualetize(
6767
&Ctx, TilesData,

0 commit comments

Comments
 (0)