Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int is_color_inside(png_bytep *all_colors, png_bytep color, int kl) {
- for (int i = 0; i < kl; i++) {
- if (all_colors[i][0]==color[0] && all_colors[i][1]==color[1] &&
- all_colors[i][2]==color[2] && all_colors[i][3]==color[3]){
- return 1;
- }
- }
- return 0;
- }
- int count_colors(struct Png *image) {
- int kl = 0;
- int clr = 100;
- int colour_width = 4;
- png_bytep *all_colors = malloc(clr * sizeof(png_bytep));
- for (int i = 0; i < clr; i++) {
- all_colors[i] = malloc(colour_width * sizeof(png_byte));
- }
- for (int y = 0; y < image->height; y++) {
- png_bytep row = image->row_pointers[y];
- for (int x = 0; x < image->width; x++) {
- png_bytep ptr = &(row[x * 4]);
- if(!is_color_inside(all_colors, ptr, kl)){
- all_colors[kl] = ptr;
- kl++;
- if(kl==(clr-1)){
- clr+=10;
- all_colors = realloc(all_colors, clr * sizeof(png_bytep));
- }
- }
- }
- }
- puts("Все цвета изображения:");
- for (int i = 0; i < kl; i++) {
- printf("%d %d %d %d\n", all_colors[i][0], all_colors[i][1], all_colors[i][2],
- all_colors[i][3]);
- }
- return kl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement