Ignore:
Timestamp:
09/01/08 01:05:50 (5 years ago)
Author:
sam
Message:
  • ordered.c: allow to rotate the dither pattern, using nearest-neighbour rotation interpolation.
File:
1 edited

Legend:

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

    r2790 r2811  
    2121 
    2222#include <stdlib.h> 
     23#include <math.h> 
    2324 
    2425#include "pipi.h" 
     
    2728pipi_image_t *pipi_dither_ordered(pipi_image_t *img, pipi_image_t *kernel) 
    2829{ 
     30    return pipi_dither_ordered_ext(img, kernel, 0.0); 
     31} 
     32 
     33pipi_image_t *pipi_dither_ordered_ext(pipi_image_t *img, pipi_image_t *kernel, 
     34                                      double angle) 
     35{ 
     36    double sint, cost; 
    2937    pipi_image_t *dst; 
    3038    pipi_pixels_t *dstp, *kernelp; 
    3139    float *dstdata, *kerneldata; 
    32     int x, y, w, h, kw, kh; 
     40    int x, y, w, h, kx, ky, kw, kh; 
    3341 
    3442    w = img->w; 
     
    3644    kw = kernel->w; 
    3745    kh = kernel->h; 
     46 
     47    cost = cos(angle * (M_PI / 180)); 
     48    sint = sin(angle * (M_PI / 180)); 
    3849 
    3950    dst = pipi_copy(img); 
     
    5061            float p, q; 
    5162 
     63            kx = (int)(cost * x - sint * y + 2 * w * h) % kw; 
     64            ky = (int)(cost * y + sint * x + 2 * w * h) % kh; 
     65 
    5266            p = dstdata[y * w + x]; 
    53             q = p > kerneldata[(y % kh) * kw + (x % kw)] ? 1. : 0.; 
     67            q = p > kerneldata[ky * kw + kx] ? 1. : 0.; 
    5468            dstdata[y * w + x] = q; 
    5569        } 
Note: See TracChangeset for help on using the changeset viewer.