Changeset 2656


Ignore:
Timestamp:
Aug 3, 2008, 1:48:07 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Error diffusion methods now support either raster or serpentine scan.
Location:
libpipi/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/examples/dither.c

    r2655 r2656  
    1818        fprintf(stderr, "Usage: %s <src> <method> <dest>\n", argv[0]);
    1919        fprintf(stderr, "Where <method> is one of:\n");
    20         fprintf(stderr, "  1   Floyd-Steinberg (serpentine)\n");
    21         fprintf(stderr, "  2   Ostromoukhov (serpentine)\n");
    22         fprintf(stderr, "  3   Direct binary search\n");
     20        fprintf(stderr, "  1   Floyd-Steinberg (raster)\n");
     21        fprintf(stderr, "  2   Floyd-Steinberg (serpentine)\n");
     22        fprintf(stderr, "  3   Ostromoukhov (raster)\n");
     23        fprintf(stderr, "  4   Ostromoukhov (serpentine)\n");
     24        fprintf(stderr, "  5   Direct binary search\n");
    2325        return EXIT_FAILURE;
    2426    }
     
    3133    switch(atoi(argv[2]))
    3234    {
     35        case 5:
     36            newimg = pipi_dbs(img); break;
     37        case 4:
     38            newimg = pipi_ostromoukhov(img, PIPI_SCAN_SERPENTINE); break;
    3339        case 3:
    34             newimg = pipi_dbs(img); break;
     40            newimg = pipi_ostromoukhov(img, PIPI_SCAN_RASTER); break;
    3541        case 2:
    36             newimg = pipi_ostromoukhov(img); break;
     42            newimg = pipi_floydsteinberg(img, PIPI_SCAN_SERPENTINE); break;
    3743        case 1:
    3844        default:
    39             newimg = pipi_floydsteinberg(img); break;
     45            newimg = pipi_floydsteinberg(img, PIPI_SCAN_RASTER); break;
    4046    }
    4147
  • libpipi/trunk/examples/edd.c

    r2655 r2656  
    5353    pipi_getpixels(img, PIPI_PIXELS_Y_F);
    5454    gauss = pipi_gaussian_blur(img, sigma);
    55     dither = pipi_floydsteinberg(img);
     55    dither = pipi_floydsteinberg(img, PIPI_SCAN_RASTER);
    5656    pipi_free(img);
    5757
  • libpipi/trunk/pipi/dither/floydsteinberg.c

    r2653 r2656  
    2323#include "pipi_internals.h"
    2424
    25 pipi_image_t *pipi_floydsteinberg(pipi_image_t *src)
     25pipi_image_t *pipi_floydsteinberg(pipi_image_t *src, pipi_scan_t scan)
    2626{
    2727    pipi_image_t *dst;
     
    4242    for(y = 0; y < h; y++)
    4343    {
     44        int reverse = (y & 1) && (scan == PIPI_SCAN_SERPENTINE);
     45
    4446        for(x = 0; x < w; x++)
    4547        {
    4648            float p, q, e;
    47             int x2 = (y & 1) ? x : w - 1 - x;
    48             int s = (y & 1) ? 1 : -1;
     49            int x2 = reverse ? w - 1 - x : x;
     50            int s = reverse ? -1 : 1;
    4951
    5052            p = srcdata[y * w + x2];
  • libpipi/trunk/pipi/dither/ostromoukhov.c

    r2654 r2656  
    6767};
    6868
    69 pipi_image_t *pipi_ostromoukhov(pipi_image_t *src)
     69pipi_image_t *pipi_ostromoukhov(pipi_image_t *src, pipi_scan_t scan)
    7070{
    7171    pipi_image_t *dst;
     
    8686    for(y = 0; y < h; y++)
    8787    {
     88        int reverse = (y & 1) && (scan == PIPI_SCAN_SERPENTINE);
     89
    8890        for(x = 0; x < w; x++)
    8991        {
     
    9193            int x2, s, i;
    9294
    93             x2 = (y & 1) ? x : w - 1 - x;
    94             s = (y & 1) ? 1 : -1;
     95            x2 = reverse ? w - 1 - x : x;
     96            s = reverse ? -1 : 1;
    9597
    9698            p = srcdata[y * w + x2];
  • libpipi/trunk/pipi/pipi.h

    r2654 r2656  
    2424{
    2525#endif
     26
     27/* pipi_scan_t: this enum is a list of all possible scanning methods when
     28 * parsing an image’s pixels. Not all functions support all scanning paths. */
     29typedef enum
     30{
     31    PIPI_SCAN_RASTER = 0,
     32    PIPI_SCAN_SERPENTINE = 1
     33}
     34pipi_scan_t;
    2635
    2736/* pipi_format_t: this enum is a list of all possible pixel formats for
     
    6978                                            float, float, float, float);
    7079
    71 extern pipi_image_t *pipi_floydsteinberg(pipi_image_t *);
    72 extern pipi_image_t *pipi_ostromoukhov(pipi_image_t *);
     80extern pipi_image_t *pipi_floydsteinberg(pipi_image_t *, pipi_scan_t);
     81extern pipi_image_t *pipi_ostromoukhov(pipi_image_t *, pipi_scan_t);
    7382extern pipi_image_t *pipi_dbs(pipi_image_t *);
    7483extern void pipi_dither_24to16(pipi_image_t *);
Note: See TracChangeset for help on using the changeset viewer.