static void moveBlackToIndex0(colorhist_vector const chv, int const colors) { /*---------------------------------------------------------------------------- If black is in the palette, make it at Index 0. -----------------------------------------------------------------------------*/ pixel blackPixel; unsigned int i; bool blackPresent; PPM_ASSIGN(blackPixel, 0, 0, 0); blackPresent = FALSE; /* initial assumption */ for (i = 0; i < colors; ++i) if (PPM_EQUAL(chv[i].color, blackPixel)) blackPresent = TRUE; if (blackPresent) { /* We use a trick here. ppm_addtocolorhist() always adds to the beginning of the table and if the color is already elsewhere in the table, removes it. */ int colors2; colors2 = colors; ppm_addtocolorhist(chv, &colors2, MAXCOLORS, &blackPixel, 0, 0); assert(colors2 == colors); } }
static bool colorIsInSet(pixel const color, pixval const maxval, struct cmdlineInfo const cmdline) { bool isInSet; unsigned int i; for (i = 0, isInSet = FALSE; i < cmdline.colorCount && !isInSet; ++i) { assert(i < ARRAY_SIZE(cmdline.maskColor)); switch(cmdline.maskColor[i].matchType) { case MATCH_EXACT: if (PPM_EQUAL(color, cmdline.maskColor[i].u.color)) isInSet = TRUE; break; case MATCH_BK: if (isBkColor(color, maxval, cmdline.maskColor[i].u.bkColor)) isInSet = TRUE; break; } } return isInSet; }
static void out_splines(FILE * const fileP, spline_list_array_type const shape, unsigned int const height) { unsigned listSeq; pixel lastColor; PPM_ASSIGN(lastColor, 0, 0, 0); for (listSeq = 0; listSeq < SPLINE_LIST_ARRAY_LENGTH(shape); ++listSeq) { spline_list_type const splineList = SPLINE_LIST_ARRAY_ELT(shape, listSeq); spline_type const first = SPLINE_LIST_ELT(splineList, 0); if (listSeq == 0 || !PPM_EQUAL(splineList.color, lastColor)) { if (listSeq > 0) { /* Close previous <path> element */ if (!(shape.centerline || splineList.open)) fputs("z", fileP); fputs("\"/>\n", fileP); } /* Open new <path> element */ fprintf(fileP, "<path style=\"%s:#%02x%02x%02x; %s:none;\" d=\"", (shape.centerline || splineList.open) ? "stroke" : "fill", PPM_GETR(splineList.color), PPM_GETG(splineList.color), PPM_GETB(splineList.color), (shape.centerline || splineList.open) ? "fill" : "stroke"); } fprintf(fileP, "M%g %g", START_POINT(first).x, height - START_POINT(first).y); outSplineList(fileP, splineList, height); lastColor = splineList.color; } if (SPLINE_LIST_ARRAY_LENGTH(shape) > 0) { spline_list_type const lastSplineList = SPLINE_LIST_ARRAY_ELT(shape, SPLINE_LIST_ARRAY_LENGTH(shape)-1); if (!(shape.centerline || lastSplineList.open)) fputs("z", fileP); /* Close last <path> element */ fputs("\"/>\n", fileP); } }
int pnm_ppm_numOfPix(ppm_t *ppm, pixel bg) { int i,n; for (i=0,n=0;i <ppm->rows;i++){ int j; pixel * current_row = ppm->pixels[i]; for (j=0;j<ppm->cols;j++){ if (!PPM_EQUAL(current_row[j],bg)) n++; } } return (n); }
static void print_clut256_data(xel **pnm, int cols, int rows, int clut_len) { int i, j, k, l; for (i = 0, k = 0; i < rows; i++) for (j = 0; j < cols; j++, k = (k+1) % 12) { if (k == 0) printf(" "); for (l = 0; l < clut_len; l++) if (PPM_EQUAL(pnm[i][j], clut[l])) break; printf(" 0x%02x,", l); if (k == 11) putchar('\n'); } if (k != 0) putchar('\n'); }
static int fill_clut(xel **pnm, int cols, int rows) { int clut_len = 0; int i, j, k; for (i = 0 ; i < rows; i++) for (j = 0; j < cols; j++) { for (k = 0; k < clut_len; k++) if (PPM_EQUAL(pnm[i][j], clut[k])) break; if (k == clut_len) { if (clut_len == 256) return 257; PPM_ASSIGN(clut[clut_len], PPM_GETR(pnm[i][j]), PPM_GETG(pnm[i][j]), PPM_GETB(pnm[i][j])); clut_len++; } } return clut_len; }
int pnm_ppm_bbox(int *x_min, int *y_min, int *x_max, int *y_max, float *x_center, float *y_center, ppm_t *ppm, pixel bg) { int i,n; *x_min =ppm->cols; *y_min =ppm->rows; *x_max =0; *y_max =0; *x_center = 0.0; *y_center = 0.0; for (i=0,n=0;i <ppm->rows;i++){ int j; pixel * current_row = ppm->pixels[i]; for (j=0;j<ppm->cols;j++){ if (!PPM_EQUAL(bg,current_row[j])) { *x_center += j; *y_center += i; n++; if (j< *x_min){ *x_min = j; } if (i< *y_min){ *y_min = i; } if (j>*x_max){ *x_max = j; } *y_max = i; } } } if (n > 0) { *x_center /= (float) n; *y_center /= (float) n; } return n; }
float pnm_ppm_sigWeight(ppm_t *ppm, float x, float y, float x_max, float y_max, float scale2, pixel bg) { int i,i_max,n=0; float result =0,bpix=0; int first_y=1; // Rand-Pixel duerfen nur zum Teil gezaehlt werden !! -- swachsmu //size = (size<(x2-x1)*(y2-y1))? (x2-x1)*(y2-y1) :size; /* Innerer ganzer Kasten */ for (i=(int)y+1, i_max=(int)y_max; i<i_max; i++){ int j, j_max; pixel *current_row = ppm->pixels[i]; for (j=(int)x+1, j_max=(int)x_max; j<j_max; j++){ bpix += (!PPM_EQUAL(current_row[j],bg)); n++; } } n=0; /* Hier ist irgendwo noch ein Fehler -- ffrenser */ { int j; float dx1, dx2, dy1, dy2; pixel *current_row = ppm->pixels[(int)y]; /* obere fehlende Teilzeile addieren */ dy1 = ceil(y) - y; for (i=(int)x+1, i_max=(int)x_max; i<i_max; i++){ bpix += dy1 * (!PPM_EQUAL(current_row[i],bg)); n++; } n=0; current_row = ppm->pixels[(int)y_max]; /* untere fehlende Teilzeile addieren */ dy2 = y_max - floor(y_max); for (i=(int)x+1, i_max=(int)x_max; i<i_max; i++){ bpix += dy2 * (!PPM_EQUAL(current_row[i],bg)); n++; } n=0; /* linke fehlende Teilspalte addieren */ dx1 = (ceil(x) - x); for (i=(int)y+1, i_max=(int)y_max, j=(int)x; i<i_max; i++){ bpix += dx1 * (!PPM_EQUAL(ppm->pixels[i][j],bg)); n++; } n=0; /* rechte fehlende Teilspalte addieren */ dx2 = (x_max - floor(x_max)); for (i=(int)y+1, i_max=(int)y_max, j=(int)x_max; i<i_max; i++){ bpix += dx2 * (!PPM_EQUAL(ppm->pixels[i][j],bg)); n++; } n=0; /* linke obere Ecke */ bpix += (dy1 * dx1) * (!PPM_EQUAL(ppm->pixels[(int)y][(int)x],bg)); /* rechte obere Ecke */ bpix += (dy1 * dx2) * (!PPM_EQUAL(ppm->pixels[(int)y][(int)x_max],bg)); /* linke untere Ecke */ bpix += (dy2 * dx1) * (!PPM_EQUAL(ppm->pixels[(int)y_max][(int)x],bg)); /* rechte untere Ecke */ bpix += (dy2 * dx2) * (!PPM_EQUAL(ppm->pixels[(int)y_max][(int)x_max],bg)); result = bpix / scale2; return result; } }