git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2671 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
@@ -17,11 +17,12 @@ int main(int argc, char *argv[]) | |||||
fprintf(stderr, "%s: too few arguments\n", argv[0]); | fprintf(stderr, "%s: too few arguments\n", argv[0]); | ||||
fprintf(stderr, "Usage: %s <src> <method> <dest>\n", argv[0]); | fprintf(stderr, "Usage: %s <src> <method> <dest>\n", argv[0]); | ||||
fprintf(stderr, "Where <method> is one of:\n"); | fprintf(stderr, "Where <method> is one of:\n"); | ||||
fprintf(stderr, " 1 Floyd-Steinberg (raster)\n"); | |||||
fprintf(stderr, " 2 Floyd-Steinberg (serpentine)\n"); | |||||
fprintf(stderr, " 3 Ostromoukhov (raster)\n"); | |||||
fprintf(stderr, " 4 Ostromoukhov (serpentine)\n"); | |||||
fprintf(stderr, " 5 Direct binary search\n"); | |||||
fprintf(stderr, " 1 random dithering\n"); | |||||
fprintf(stderr, " 2 Floyd-Steinberg (raster)\n"); | |||||
fprintf(stderr, " 3 Floyd-Steinberg (serpentine)\n"); | |||||
fprintf(stderr, " 4 Ostromoukhov (raster)\n"); | |||||
fprintf(stderr, " 5 Ostromoukhov (serpentine)\n"); | |||||
fprintf(stderr, " 6 Direct binary search\n"); | |||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
@@ -32,24 +33,27 @@ int main(int argc, char *argv[]) | |||||
switch(atoi(argv[2])) | switch(atoi(argv[2])) | ||||
{ | { | ||||
case 6: | |||||
case 7: | |||||
newimg = pipi_dither_dbs(img); | newimg = pipi_dither_dbs(img); | ||||
break; | break; | ||||
case 5: | |||||
case 6: | |||||
newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_SERPENTINE); | newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_SERPENTINE); | ||||
break; | break; | ||||
case 4: | |||||
case 5: | |||||
newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_RASTER); | newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_RASTER); | ||||
break; | break; | ||||
case 3: | |||||
case 4: | |||||
newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_SERPENTINE); | newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_SERPENTINE); | ||||
break; | break; | ||||
case 2: | |||||
case 3: | |||||
newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_RASTER); | newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_RASTER); | ||||
break; | break; | ||||
case 2: | |||||
newimg = pipi_dither_ordered(img); | |||||
break; | |||||
case 1: | case 1: | ||||
default: | default: | ||||
newimg = pipi_dither_ordered(img); | |||||
newimg = pipi_dither_random(img); | |||||
break; | break; | ||||
} | } | ||||
@@ -34,6 +34,7 @@ libpipi_la_SOURCES = \ | |||||
dither/ordered.c \ | dither/ordered.c \ | ||||
dither/ostromoukhov.c \ | dither/ostromoukhov.c \ | ||||
dither/dbs.c \ | dither/dbs.c \ | ||||
dither/random.c \ | |||||
$(NULL) | $(NULL) | ||||
libpipi_la_CFLAGS = $(codec_cflags) | libpipi_la_CFLAGS = $(codec_cflags) | ||||
libpipi_la_LDFLAGS = $(codec_libs) \ | libpipi_la_LDFLAGS = $(codec_libs) \ | ||||
@@ -0,0 +1,61 @@ | |||||
/* | |||||
* libpipi Proper image processing implementation library | |||||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id$ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
/* | |||||
* random.c: random dithering functions | |||||
*/ | |||||
#include "config.h" | |||||
#include "common.h" | |||||
#include "pipi.h" | |||||
#include "pipi_internals.h" | |||||
pipi_image_t *pipi_dither_random(pipi_image_t *img) | |||||
{ | |||||
pipi_image_t *dst; | |||||
pipi_pixels_t *dstp; | |||||
float *dstdata; | |||||
unsigned int ctx = 1; | |||||
int x, y, w, h; | |||||
w = img->w; | |||||
h = img->h; | |||||
dst = pipi_copy(img); | |||||
dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F); | |||||
dstdata = (float *)dstp->pixels; | |||||
for(y = 0; y < h; y++) | |||||
{ | |||||
for(x = 0; x < w; x++) | |||||
{ | |||||
long hi, lo; | |||||
float p, q; | |||||
hi = ctx / 12773L; | |||||
lo = ctx % 12773L; | |||||
ctx = 16807L * lo - 2836L * hi; | |||||
if(ctx <= 0) | |||||
ctx += 0x7fffffffL; | |||||
p = dstdata[y * w + x]; | |||||
q = p > (double)((ctx % 65536) / 65535.) ? 1. : 0.; | |||||
dstdata[y * w + x] = q; | |||||
} | |||||
} | |||||
return dst; | |||||
} | |||||
@@ -84,6 +84,7 @@ extern pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *, | |||||
extern pipi_image_t *pipi_dither_floydsteinberg(pipi_image_t *, pipi_scan_t); | extern pipi_image_t *pipi_dither_floydsteinberg(pipi_image_t *, pipi_scan_t); | ||||
extern pipi_image_t *pipi_dither_ordered(pipi_image_t *); | extern pipi_image_t *pipi_dither_ordered(pipi_image_t *); | ||||
extern pipi_image_t *pipi_dither_random(pipi_image_t *); | |||||
extern pipi_image_t *pipi_dither_ostromoukhov(pipi_image_t *, pipi_scan_t); | extern pipi_image_t *pipi_dither_ostromoukhov(pipi_image_t *, pipi_scan_t); | ||||
extern pipi_image_t *pipi_dither_dbs(pipi_image_t *); | extern pipi_image_t *pipi_dither_dbs(pipi_image_t *); | ||||
extern void pipi_dither_24to16(pipi_image_t *); | extern void pipi_dither_24to16(pipi_image_t *); | ||||