@@ -171,9 +171,9 @@ diff '--color=auto' -uNr patch/wu.h materialyoucolor/quantize/wu.h
171
171
172
172
namespace material_color_utilities {
173
173
174
- --- patch/ celebi.cc 2024-03-25 23:22:50.123427023 +0530
175
- +++ materialyoucolor/quantize/ celebi.cc 2024-03-25 23:20:03.277959473 +0530
176
- @@ -14,47 +14,78 @@
174
+ --- materialyoucolor/quantize/ celebi.cc 2025-01-09 12:10:34.733592839 +0530
175
+ +++ patch/ celebi.cc 2025-01-09 11:57:06.090837655 +0530
176
+ @@ -14,47 +14,81 @@
177
177
* limitations under the License.
178
178
*/
179
179
@@ -244,35 +244,38 @@ diff '--color=auto' -uNr patch/wu.h materialyoucolor/quantize/wu.h
244
244
+
245
245
+ return result.color_to_count;
246
246
+ }
247
- +
248
247
249
248
- return result;
250
- + std::vector<std::vector<int>> StbLoadImage(const char* image_path) {
249
+ +
250
+ + std::map<uint32_t, uint32_t> ImageQuantizeCelebi(const char* image_path, const int quality, int max_colors) {
251
251
+ int width, height, channels;
252
252
+ std::vector<std::vector<int>> pixel_array = {};
253
- + // Load the actual image
254
253
+ unsigned char* pixel_result = stbi_load(image_path, &width, &height, &channels, 4);
255
- + if (!pixel_result) {return pixel_array;}
256
- +
257
- + pixel_array.reserve(width * height);
254
+ + if (!pixel_result) {return QuantizeCelebi(pixel_array, max_colors);}
255
+ + pixel_array.reserve( (width * height) / quality );
258
256
+ unsigned char* pixel_position;
259
- +
257
+ + int _quality = quality;
260
258
+ for (int y = 0; y < height; ++y) {
261
- + for (int x = 0; x < width; ++x ) {
259
+ + for (int x = 0; x < width; x = x+_quality ) {
262
260
+ pixel_position = pixel_result + (x + y * width) * 4;
263
261
+ std::vector<int> current_color = {
264
262
+ pixel_position[0], pixel_position[1], pixel_position[2]};
265
263
+ if (channels > 3) {current_color.push_back(pixel_position[3]);}
266
264
+ pixel_array.push_back(current_color);
265
+ + if (_quality < quality) {_quality = quality;}
267
266
+ }
267
+ + if (y % 2 == 0) {
268
+ + _quality = quality / 2;
269
+ + } else {_quality = quality;}
268
270
+ }
269
271
+ stbi_image_free(pixel_result);
270
- + return pixel_array;
272
+ + return QuantizeCelebi( pixel_array, max_colors) ;
271
273
}
272
274
273
275
- } // namespace material_color_utilities
276
+ +
274
277
+ PYBIND11_MODULE(celebi, m) {
275
278
+ m.doc() = "Functions from cpp backend";
276
279
+ m.def("QuantizeCelebi", &QuantizeCelebi, "Get dominant colors");
277
- + m.def("StbLoadImage ", &StbLoadImage , "Get pixel array");
280
+ + m.def("ImageQuantizeCelebi ", &ImageQuantizeCelebi , "Get pixel array");
278
281
+ }
0 commit comments