Changeset 2703
- Timestamp:
- Aug 12, 2008, 12:57:21 AM (12 years ago)
- Location:
- libpipi/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libpipi/trunk/pipi/context.c
r2702 r2703 132 132 ctx->images[ctx->nimages - 1] = dst; 133 133 } 134 else if(!strcmp(cmd, "wrap")) 135 { 136 if(ctx->nimages <= 0) 137 return -1; 138 ctx->images[ctx->nimages - 1]->wrap = 1; 139 } 134 140 else if(!strcmp(cmd, "gray")) 135 141 { -
libpipi/trunk/pipi/filter/convolution.c
r2701 r2703 28 28 #include "pipi_internals.h" 29 29 30 #define FLAG_GRAY ((FLAGS) & SET_FLAG_GRAY) 31 #define FLAG_WRAP ((FLAGS) & SET_FLAG_WRAP) 32 33 #define SET_FLAG_GRAY 0x01 34 #define SET_FLAG_WRAP 0x02 35 30 36 static pipi_image_t *conv_std_rgba_f(pipi_image_t *src, 31 37 int m, int n, double mat[]); … … 36 42 #undef FUNC2 37 43 #undef PIXEL 38 #undef GRAY44 #undef FLAGS 39 45 #define FUNC1 conv_std_rgba_f 40 46 #define FUNC2 conv_sep_rgba_f 41 47 #define PIXEL float 42 #define GRAY048 #define FLAGS 0 43 49 #include "convolution_template.h" 44 50 … … 51 57 #undef FUNC2 52 58 #undef PIXEL 53 #undef GRAY59 #undef FLAGS 54 60 #define FUNC1 conv_std_y_f 55 61 #define FUNC2 conv_sep_y_f 56 62 #define PIXEL float 57 #define GRAY 1 63 #define FLAGS SET_FLAG_GRAY 64 #include "convolution_template.h" 65 66 static pipi_image_t *wrap_std_rgba_f(pipi_image_t *src, 67 int m, int n, double mat[]); 68 static pipi_image_t *wrap_sep_rgba_f(pipi_image_t *src, 69 int m, double hvec[], 70 int n, double vvec[]); 71 #undef FUNC1 72 #undef FUNC2 73 #undef PIXEL 74 #undef FLAGS 75 #define FUNC1 wrap_std_rgba_f 76 #define FUNC2 wrap_sep_rgba_f 77 #define PIXEL float 78 #define FLAGS SET_FLAG_WRAP 79 #include "convolution_template.h" 80 81 static pipi_image_t *wrap_std_y_f(pipi_image_t *src, 82 int m, int n, double mat[]); 83 static pipi_image_t *wrap_sep_y_f(pipi_image_t *src, 84 int m, double hvec[], 85 int n, double vvec[]); 86 #undef FUNC1 87 #undef FUNC2 88 #undef PIXEL 89 #undef FLAGS 90 #define FUNC1 wrap_std_y_f 91 #define FUNC2 wrap_sep_y_f 92 #define PIXEL float 93 #define FLAGS SET_FLAG_GRAY|SET_FLAG_WRAP 58 94 #include "convolution_template.h" 59 95 … … 98 134 { 99 135 if(src->last_modified == PIPI_PIXELS_Y_F) 136 { 137 if(src->wrap) 138 return wrap_std_y_f(src, m, n, mat); 100 139 return conv_std_y_f(src, m, n, mat); 140 } 101 141 else 142 { 143 if(src->wrap) 144 return wrap_std_rgba_f(src, m, n, mat); 102 145 return conv_std_rgba_f(src, m, n, mat); 146 } 103 147 } 104 148 } … … 116 160 117 161 if(src->last_modified == PIPI_PIXELS_Y_F) 118 ret = conv_sep_y_f(src, m, hvec, n, vvec); 162 ret = src->wrap ? wrap_sep_y_f(src, m, hvec, n, vvec) 163 : conv_sep_y_f(src, m, hvec, n, vvec); 119 164 else 120 ret = conv_sep_rgba_f(src, m, hvec, n, vvec); 165 ret = src->wrap ? wrap_sep_rgba_f(src, m, hvec, n, vvec) 166 : conv_sep_rgba_f(src, m, hvec, n, vvec); 121 167 122 168 free(hvec); -
libpipi/trunk/pipi/filter/convolution_template.h
r2701 r2703 19 19 * FUNC2 separable function name 20 20 * PIXEL pixel type 21 * GRAY 1 (grayscale) or 0 (classic RGBA) 21 * FLAGS 1 (grayscale) 22 * 2 (loop) 22 23 */ 23 24 … … 32 33 h = src->h; 33 34 34 srcp = GRAY ? pipi_getpixels(src, PIPI_PIXELS_Y_F)35 : pipi_getpixels(src, PIPI_PIXELS_RGBA_F);35 srcp = FLAG_GRAY ? pipi_getpixels(src, PIPI_PIXELS_Y_F) 36 : pipi_getpixels(src, PIPI_PIXELS_RGBA_F); 36 37 srcdata = (PIXEL *)srcp->pixels; 37 38 38 39 dst = pipi_new(w, h); 39 dstp = GRAY ? pipi_getpixels(dst, PIPI_PIXELS_Y_F)40 : pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);40 dstp = FLAG_GRAY ? pipi_getpixels(dst, PIPI_PIXELS_Y_F) 41 : pipi_getpixels(dst, PIPI_PIXELS_RGBA_F); 41 42 dstdata = (PIXEL *)dstp->pixels; 42 43 … … 45 46 for(x = 0; x < w; x++) 46 47 { 47 if( GRAY)48 if(FLAG_GRAY) 48 49 { 49 50 double Y = 0.; … … 53 54 { 54 55 y2 = y + j - n / 2; 55 if(y2 < 0) y2 = 0;56 else if(y2 >= h) y2 = h - 1;56 if(y2 < 0) y2 = FLAG_WRAP ? (h - 1 - (-y2 - 1) % h) : 0; 57 else if(y2 >= h) y2 = FLAG_WRAP ? y2 % h : h - 1; 57 58 58 59 for(i = 0; i < m; i++) 59 60 { 60 61 x2 = x + i - m / 2; 61 if(x2 < 0) x2 = 0;62 else if(x2 >= w) x2 = w - 1;62 if(x2 < 0) x2 = FLAG_WRAP ? (w - 1 - (-x2 - 1) % w) : 0; 63 else if(x2 >= w) x2 = FLAG_WRAP ? x2 % w : w - 1; 63 64 64 65 Y += mat[j * m + i] * srcdata[y2 * w + x2]; … … 76 77 { 77 78 y2 = y + j - n / 2; 78 if(y2 < 0) y2 = 0;79 else if(y2 >= h) y2 = h - 1;79 if(y2 < 0) y2 = FLAG_WRAP ? (h - 1 - (-y2 - 1) % h) : 0; 80 else if(y2 >= h) y2 = FLAG_WRAP ? y2 % h : h - 1; 80 81 81 82 for(i = 0; i < m; i++) … … 84 85 85 86 x2 = x + i - m / 2; 86 if(x2 < 0) x2 = 0;87 else if(x2 >= w) x2 = w - 1;87 if(x2 < 0) x2 = FLAG_WRAP ? (w - 1 - (-x2 - 1) % w) : 0; 88 else if(x2 >= w) x2 = FLAG_WRAP ? x2 % w : w - 1; 88 89 89 90 R += f * srcdata[(y2 * w + x2) * 4]; … … 115 116 h = src->h; 116 117 117 srcp = GRAY ? pipi_getpixels(src, PIPI_PIXELS_Y_F)118 : pipi_getpixels(src, PIPI_PIXELS_RGBA_F);118 srcp = FLAG_GRAY ? pipi_getpixels(src, PIPI_PIXELS_Y_F) 119 : pipi_getpixels(src, PIPI_PIXELS_RGBA_F); 119 120 srcdata = (PIXEL *)srcp->pixels; 120 121 121 122 dst = pipi_new(w, h); 122 dstp = GRAY ? pipi_getpixels(dst, PIPI_PIXELS_Y_F)123 : pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);123 dstp = FLAG_GRAY ? pipi_getpixels(dst, PIPI_PIXELS_Y_F) 124 : pipi_getpixels(dst, PIPI_PIXELS_RGBA_F); 124 125 dstdata = (PIXEL *)dstp->pixels; 125 126 126 buffer = malloc(w * h * ( GRAY ? 1 : 4) * sizeof(double));127 buffer = malloc(w * h * (FLAG_GRAY ? 1 : 4) * sizeof(double)); 127 128 128 129 for(y = 0; y < h; y++) … … 130 131 for(x = 0; x < w; x++) 131 132 { 132 if( GRAY)133 if(FLAG_GRAY) 133 134 { 134 135 double Y = 0.; … … 138 139 { 139 140 x2 = x + i - m / 2; 140 if(x2 < 0) x2 = 0;141 else if(x2 >= w) x2 = w - 1;141 if(x2 < 0) x2 = FLAG_WRAP ? (w - 1 - (-x2 - 1) % w) : 0; 142 else if(x2 >= w) x2 = FLAG_WRAP ? x2 % w : w - 1; 142 143 143 144 Y += hvec[i] * srcdata[y * w + x2]; … … 156 157 157 158 x2 = x + i - m / 2; 158 if(x2 < 0) x2 = 0;159 else if(x2 >= w) x2 = w - 1;159 if(x2 < 0) x2 = FLAG_WRAP ? (w - 1 - (-x2 - 1) % w) : 0; 160 else if(x2 >= w) x2 = FLAG_WRAP ? x2 % w : w - 1; 160 161 161 162 R += f * srcdata[(y * w + x2) * 4]; … … 175 176 for(x = 0; x < w; x++) 176 177 { 177 if( GRAY)178 if(FLAG_GRAY) 178 179 { 179 180 double Y = 0.; … … 183 184 { 184 185 y2 = y + j - n / 2; 185 if(y2 < 0) y2 = 0;186 else if(y2 >= h) y2 = h - 1;186 if(y2 < 0) y2 = FLAG_WRAP ? (h - 1 - (-y2 - 1) % h) : 0; 187 else if(y2 >= h) y2 = FLAG_WRAP ? y2 % h : h - 1; 187 188 188 189 Y += vvec[j] * buffer[y2 * w + x]; … … 201 202 202 203 y2 = y + j - n / 2; 203 if(y2 < 0) y2 = 0;204 else if(y2 >= h) y2 = h - 1;204 if(y2 < 0) y2 = FLAG_WRAP ? (h - 1 - (-y2 - 1) % h) : 0; 205 else if(y2 >= h) y2 = FLAG_WRAP ? y2 % h : h - 1; 205 206 206 207 R += f * buffer[(y2 * w + x) * 4]; -
libpipi/trunk/pipi/pipi.c
r2669 r2703 58 58 pipi_image_t *dst = pipi_new(src->w, src->h); 59 59 60 /* Copy properties */ 61 dst->wrap = src->wrap; 62 63 /* Copy pixels, if any */ 60 64 if(src->last_modified != PIPI_PIXELS_UNINITIALISED) 61 65 { -
libpipi/trunk/pipi/pipi_internals.h
r2692 r2703 26 26 { 27 27 int w, h, pitch; 28 int wrap; 28 29 pipi_format_t codec_format, last_modified; 29 30 -
libpipi/trunk/src/pipi.c
r2702 r2703 42 42 return EXIT_FAILURE; 43 43 } 44 else if(!strcmp(argv[0], "--wrap")) 45 { 46 if(pipi_command(ctx, "wrap") != 0) 47 return EXIT_FAILURE; 48 } 44 49 else if(!strcmp(argv[0], "--output") || !strcmp(argv[0], "-o")) 45 50 {
Note: See TracChangeset
for help on using the changeset viewer.