10
10
//! NOTE: Something is probably broken about how clustering is
11
11
//! implemented. Sometimes results converge, and other times
12
12
//! they /diverge/. This probably needs to be investigated.
13
- #define MAX_PALETTE_INDICES_PASSES 8
14
- #define MAX_PALETTE_QUANTIZATION_PASSES 8
13
+ #define DEFAULT_TILECLUSTER_PASSES 8
14
+ #define DEFAULT_COLOURCLUSTER_PASSES 8
15
15
16
16
/**************************************/
17
17
#define ALIGN2N (x ,N ) (((x) + (N)-1) &~ ((N)-1))
@@ -125,11 +125,23 @@ struct TilesData_t *TilesData_FromBitmap(const struct BmpCtx_t *Ctx, int TileW,
125
125
/**************************************/
126
126
127
127
//! Create quantized palette
128
- int TilesData_QuantizePalettes (struct TilesData_t * TilesData , struct BGRAf_t * Palette , int MaxTilePals , int MaxPalSize , int PalUnusedEntries ) {
128
+ int TilesData_QuantizePalettes (
129
+ struct TilesData_t * TilesData ,
130
+ struct BGRAf_t * Palette ,
131
+ int MaxTilePals ,
132
+ int MaxPalSize ,
133
+ int PalUnusedEntries ,
134
+ int nTileClusterPasses ,
135
+ int nColourClusterPasses
136
+ ) {
129
137
int i , j , k ;
130
138
int nPxTile = TilesData -> TileW * TilesData -> TileH ;
131
139
int nTiles = TilesData -> TilesX * TilesData -> TilesY ;
132
140
141
+ //! Set default passes as needed
142
+ if (nTileClusterPasses == 0 ) nTileClusterPasses = DEFAULT_TILECLUSTER_PASSES ;
143
+ if (nColourClusterPasses == 0 ) nColourClusterPasses = DEFAULT_COLOURCLUSTER_PASSES ;
144
+
133
145
//! Unused entries should not count towards
134
146
//! the maximum palette size
135
147
MaxPalSize -= PalUnusedEntries ;
@@ -143,7 +155,7 @@ int TilesData_QuantizePalettes(struct TilesData_t *TilesData, struct BGRAf_t *Pa
143
155
}
144
156
145
157
//! Categorize tiles by palette
146
- QuantCluster_Quantize (Clusters , MaxTilePals , TilesData -> TileValue , nTiles , TilesData -> TilePalIdx , MAX_PALETTE_INDICES_PASSES );
158
+ QuantCluster_Quantize (Clusters , MaxTilePals , TilesData -> TileValue , nTiles , TilesData -> TilePalIdx , nTileClusterPasses );
147
159
148
160
//! Quantize tile palettes
149
161
for (i = 0 ;i < MaxTilePals ;i ++ ) {
@@ -161,7 +173,7 @@ int TilesData_QuantizePalettes(struct TilesData_t *TilesData, struct BGRAf_t *Pa
161
173
if (!PxCnt ) continue ;
162
174
163
175
//! Perform quantization
164
- QuantCluster_Quantize (Clusters , MaxPalSize , PxTemp , PxCnt , TilesData -> PxTempIdx , MAX_PALETTE_QUANTIZATION_PASSES );
176
+ QuantCluster_Quantize (Clusters , MaxPalSize , PxTemp , PxCnt , TilesData -> PxTempIdx , nColourClusterPasses );
165
177
166
178
//! Extract palette from cluster centroids
167
179
for (j = 0 ;j < PalUnusedEntries ;j ++ ) * Palette ++ = (struct BGRAf_t ){0 ,0 ,0 ,0 };
0 commit comments