Ignore:
Timestamp:
08/04/08 19:23:59 (5 years ago)
Author:
sam
Message:
  • Dithering algorithms no longer modify the original image.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/dither/dbs.c

    r2666 r2670  
    3636 * guaranteed stop condition here. */ 
    3737 
    38 pipi_image_t *pipi_dither_dbs(pipi_image_t *src) 
     38pipi_image_t *pipi_dither_dbs(pipi_image_t *img) 
    3939{ 
    4040    double kernel[NN * NN]; 
    4141    double t = 0.; 
    42     pipi_image_t *dst, *tmp1, *tmp2; 
    43     pipi_pixels_t *srcp, *dstp, *tmp1p, *tmp2p; 
     42    pipi_image_t *src, *dst, *tmp1, *tmp2; 
     43    pipi_pixels_t *dstp, *tmp1p, *tmp2p; 
    4444    int *changelist; 
    45     float *srcdata, *dstdata, *tmp1data, *tmp2data; 
     45    float *dstdata, *tmp1data, *tmp2data; 
    4646    int i, j, x, y, w, h, cw, ch; 
    4747 
     
    6262            kernel[j * NN + i] /= t; 
    6363 
    64     w = src->w; 
    65     h = src->h; 
     64    w = img->w; 
     65    h = img->h; 
    6666 
    6767    cw = (w + CELL - 1) / CELL; 
     
    7070    memset(changelist, 0, cw * ch * sizeof(int)); 
    7171 
    72     srcp = pipi_getpixels(src, PIPI_PIXELS_Y_F); 
    73     srcdata = (float *)srcp->pixels; 
     72    src = pipi_copy(img); 
     73    pipi_getpixels(src, PIPI_PIXELS_Y_F); 
    7474 
    7575    tmp1 = pipi_convolution(src, NN, NN, kernel); 
     
    7777    tmp1data = (float *)tmp1p->pixels; 
    7878 
    79     /* The initial dither is an empty image. So is its blurred version, 
    80      * but I leave the pipi_convolution() call here in case we choose 
    81      * to change the way to create the initial dither. */ 
    82     dst = pipi_new(w, h); 
     79    dst = pipi_dither_floydsteinberg(src, PIPI_SCAN_SERPENTINE); 
    8380    dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F); 
    8481    dstdata = (float *)dstp->pixels; 
    8582 
    86     for(y = 0; y < h; y++) 
    87         for(x = 0; x < w; x++) 
    88             dstdata[y * w + x] = srcdata[y * w + x] > 0.5 ? 1.0 : 0.0; 
     83    pipi_free(src); 
    8984 
    9085    tmp2 = pipi_convolution(dst, NN, NN, kernel); 
Note: See TracChangeset for help on using the changeset viewer.