Changeset 2703


Ignore:
Timestamp:
08/12/08 00:57:21 (5 years ago)
Author:
sam
Message:
  • convolution.c: support for wrap-around in convolutions.
  • pipi.c: add the "--wrap" flag to tell libpipi that a given image wraps around.
Location:
libpipi/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/context.c

    r2702 r2703  
    132132        ctx->images[ctx->nimages - 1] = dst; 
    133133    } 
     134    else if(!strcmp(cmd, "wrap")) 
     135    { 
     136        if(ctx->nimages <= 0) 
     137            return -1; 
     138        ctx->images[ctx->nimages - 1]->wrap = 1; 
     139    } 
    134140    else if(!strcmp(cmd, "gray")) 
    135141    { 
  • libpipi/trunk/pipi/filter/convolution.c

    r2701 r2703  
    2828#include "pipi_internals.h" 
    2929 
     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 
    3036static pipi_image_t *conv_std_rgba_f(pipi_image_t *src, 
    3137                                     int m, int n, double mat[]); 
     
    3642#undef FUNC2 
    3743#undef PIXEL 
    38 #undef GRAY 
     44#undef FLAGS 
    3945#define FUNC1 conv_std_rgba_f 
    4046#define FUNC2 conv_sep_rgba_f 
    4147#define PIXEL float 
    42 #define GRAY 0 
     48#define FLAGS 0 
    4349#include "convolution_template.h" 
    4450 
     
    5157#undef FUNC2 
    5258#undef PIXEL 
    53 #undef GRAY 
     59#undef FLAGS 
    5460#define FUNC1 conv_std_y_f 
    5561#define FUNC2 conv_sep_y_f 
    5662#define PIXEL float 
    57 #define GRAY 1 
     63#define FLAGS SET_FLAG_GRAY 
     64#include "convolution_template.h" 
     65 
     66static pipi_image_t *wrap_std_rgba_f(pipi_image_t *src, 
     67                                     int m, int n, double mat[]); 
     68static 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 
     81static pipi_image_t *wrap_std_y_f(pipi_image_t *src, 
     82                                  int m, int n, double mat[]); 
     83static 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 
    5894#include "convolution_template.h" 
    5995 
     
    98134            { 
    99135                if(src->last_modified == PIPI_PIXELS_Y_F) 
     136                { 
     137                    if(src->wrap) 
     138                        return wrap_std_y_f(src, m, n, mat); 
    100139                    return conv_std_y_f(src, m, n, mat); 
     140                } 
    101141                else 
     142                { 
     143                    if(src->wrap) 
     144                        return wrap_std_rgba_f(src, m, n, mat); 
    102145                    return conv_std_rgba_f(src, m, n, mat); 
     146                } 
    103147            } 
    104148        } 
     
    116160 
    117161    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); 
    119164    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); 
    121167 
    122168    free(hvec); 
  • libpipi/trunk/pipi/filter/convolution_template.h

    r2701 r2703  
    1919 *   FUNC2  separable function name 
    2020 *   PIXEL  pixel type 
    21  *   GRAY   1 (grayscale) or 0 (classic RGBA) 
     21 *   FLAGS  1 (grayscale) 
     22 *          2 (loop) 
    2223 */ 
    2324 
     
    3233    h = src->h; 
    3334 
    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); 
    3637    srcdata = (PIXEL *)srcp->pixels; 
    3738 
    3839    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); 
    4142    dstdata = (PIXEL *)dstp->pixels; 
    4243 
     
    4546        for(x = 0; x < w; x++) 
    4647        { 
    47             if(GRAY) 
     48            if(FLAG_GRAY) 
    4849            { 
    4950                double Y = 0.; 
     
    5354                { 
    5455                    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; 
    5758 
    5859                    for(i = 0; i < m; i++) 
    5960                    { 
    6061                        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; 
    6364 
    6465                        Y += mat[j * m + i] * srcdata[y2 * w + x2]; 
     
    7677                { 
    7778                    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; 
    8081 
    8182                    for(i = 0; i < m; i++) 
     
    8485 
    8586                        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; 
    8889 
    8990                        R += f * srcdata[(y2 * w + x2) * 4]; 
     
    115116    h = src->h; 
    116117 
    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); 
    119120    srcdata = (PIXEL *)srcp->pixels; 
    120121 
    121122    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); 
    124125    dstdata = (PIXEL *)dstp->pixels; 
    125126 
    126     buffer = malloc(w * h * (GRAY ? 1 : 4) * sizeof(double)); 
     127    buffer = malloc(w * h * (FLAG_GRAY ? 1 : 4) * sizeof(double)); 
    127128 
    128129    for(y = 0; y < h; y++) 
     
    130131        for(x = 0; x < w; x++) 
    131132        { 
    132             if(GRAY) 
     133            if(FLAG_GRAY) 
    133134            { 
    134135                double Y = 0.; 
     
    138139                { 
    139140                    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; 
    142143 
    143144                    Y += hvec[i] * srcdata[y * w + x2]; 
     
    156157 
    157158                    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; 
    160161 
    161162                    R += f * srcdata[(y * w + x2) * 4]; 
     
    175176        for(x = 0; x < w; x++) 
    176177        { 
    177             if(GRAY) 
     178            if(FLAG_GRAY) 
    178179            { 
    179180                double Y = 0.; 
     
    183184                { 
    184185                    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; 
    187188 
    188189                    Y += vvec[j] * buffer[y2 * w + x]; 
     
    201202 
    202203                    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; 
    205206 
    206207                    R += f * buffer[(y2 * w + x) * 4]; 
  • libpipi/trunk/pipi/pipi.c

    r2669 r2703  
    5858    pipi_image_t *dst = pipi_new(src->w, src->h); 
    5959 
     60    /* Copy properties */ 
     61    dst->wrap = src->wrap; 
     62 
     63    /* Copy pixels, if any */ 
    6064    if(src->last_modified != PIPI_PIXELS_UNINITIALISED) 
    6165    { 
  • libpipi/trunk/pipi/pipi_internals.h

    r2692 r2703  
    2626{ 
    2727    int w, h, pitch; 
     28    int wrap; 
    2829    pipi_format_t codec_format, last_modified; 
    2930 
  • libpipi/trunk/src/pipi.c

    r2702 r2703  
    4242                return EXIT_FAILURE; 
    4343        } 
     44        else if(!strcmp(argv[0], "--wrap")) 
     45        { 
     46            if(pipi_command(ctx, "wrap") != 0) 
     47                return EXIT_FAILURE; 
     48        } 
    4449        else if(!strcmp(argv[0], "--output") || !strcmp(argv[0], "-o")) 
    4550        { 
Note: See TracChangeset for help on using the changeset viewer.