Mercurial > hg > wm
comparison Meerwald-dir/coeff.c @ 24:9f20bce6184e v0.7
move directories, support netpbm 11
| author | Peter Meerwald-Stadler <pmeerw@pmeerw.net> | 
|---|---|
| date | Fri, 20 Dec 2024 13:08:59 +0100 | 
| parents | Meerwald/coeff.c@acb6967ee76d | 
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 23:71dd4b96221b | 24:9f20bce6184e | 
|---|---|
| 1 #include "wm.h" | |
| 2 #include "coeff.h" | |
| 3 | |
| 4 double **alloc_coeffs(int cols, int rows) { | |
| 5 double **p; | |
| 6 int i; | |
| 7 | |
| 8 p = (double **)malloc(rows * sizeof(double *)); | |
| 9 if (!p) { | |
| 10 #ifdef DEBUG | |
| 11 fprintf(stderr, "alloc_coeffs(): malloc() failed\n"); | |
| 12 exit(1); | |
| 13 #else | |
| 14 return NULL; | |
| 15 #endif | |
| 16 } | |
| 17 p[0] = malloc(rows * cols * sizeof(double)); | |
| 18 if (!p[0]) { | |
| 19 #ifdef DEBUG | |
| 20 fprintf(stderr, "alloc_coeffs(): malloc() failed\n"); | |
| 21 exit(1); | |
| 22 #else | |
| 23 free(p); | |
| 24 return NULL; | |
| 25 #endif | |
| 26 } | |
| 27 for (i = 1; i < rows; i++) { | |
| 28 p[i] = &(p[0][i * cols]); | |
| 29 } | |
| 30 | |
| 31 return p; | |
| 32 } | |
| 33 | |
| 34 void free_coeffs(double **coeffs) { | |
| 35 free(coeffs[0]); | |
| 36 free(coeffs); | |
| 37 } | |
| 38 | |
| 39 double **alloc_coeffs_8x8() { | |
| 40 return alloc_coeffs(8, 8); | |
| 41 } | |
| 42 | |
| 43 void print_coeffs_8x8(double **coeffs) { | |
| 44 int i, j; | |
| 45 | |
| 46 for (i = 0; i < 8; i++) { | |
| 47 for (j = 0; j < 8; j++) | |
| 48 fprintf(stderr, "%8.2f ", coeffs[i][j]); | |
| 49 fprintf(stderr, "\n"); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 void print_coeffs(double **coeffs, int c, int r, int w, int h) { | |
| 54 int i, j; | |
| 55 double *p; | |
| 56 | |
| 57 #ifdef DEBUG | |
| 58 if (!coeffs) { | |
| 59 fprintf(stderr, "print_coeffs(): NULL pixels\n"); | |
| 60 } | |
| 61 if (w <= 0 || h <= 0 || c < 0 || r < 0) { | |
| 62 fprintf(stderr, "print_coeffs(): block dimension out of range\n"); | |
| 63 } | |
| 64 #endif | |
| 65 | |
| 66 for (j = r; j < r + h; j++) { | |
| 67 p = &coeffs[j][c]; | |
| 68 for (i = 0; i < w; i++) | |
| 69 fprintf(stderr, "%8.2f ", *(p++)); | |
| 70 fprintf(stderr, "\n"); | |
| 71 } | |
| 72 } | 
