- Timestamp:
- Aug 25, 2008, 9:13:50 PM (13 years ago)
- Location:
- libpipi/trunk/pipi
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libpipi/trunk/pipi/codec.c
r2759 r2767 31 31 if(!strncmp(name, "random:", 7) || 32 32 !strncmp(name, "ediff:", 6) || 33 !strncmp(name, "halftone:", 6) || 33 34 !strncmp(name, "bayer:", 6)) 34 35 return pipi_load_stock(name); -
libpipi/trunk/pipi/pipi.h
r2765 r2767 108 108 extern pipi_image_t *pipi_render_random(int, int); 109 109 extern pipi_image_t *pipi_render_bayer(int, int); 110 extern pipi_image_t *pipi_render_halftone(int, int); 110 111 111 112 extern pipi_image_t *pipi_rgb(pipi_image_t *, pipi_image_t *, pipi_image_t *); -
libpipi/trunk/pipi/render/screen.c
r2765 r2767 23 23 #include <stdlib.h> 24 24 #include <string.h> 25 #include <math.h> 25 26 26 27 #include "pipi.h" … … 65 66 } 66 67 68 typedef struct 69 { 70 int x, y; 71 double dist; 72 } 73 dot_t; 74 75 static int cmpdot(const void *p1, const void *p2) 76 { 77 return ((dot_t const *)p1)->dist > ((dot_t const *)p2)->dist; 78 } 79 80 pipi_image_t *pipi_render_halftone(int w, int h) 81 { 82 pipi_image_t *ret; 83 pipi_pixels_t *pix; 84 float *data; 85 dot_t *circle; 86 int x, y, n; 87 88 if(w <= 0 || h <= 0) 89 return NULL; 90 91 circle = malloc(w * h * sizeof(dot_t)); 92 93 for(y = 0; y < h; y++) 94 for(x = 0; x < w; x++) 95 { 96 double dy = ((double)y + .07) / h - .5; 97 double dx = (double)x / w - .5; 98 /* Using dx²+dy² here creates another interesting halftone. */ 99 double r = - cos(M_PI * (dx - dy)) - cos(M_PI * (dx + dy)); 100 circle[y * w + x].x = x; 101 circle[y * w + x].y = y; 102 circle[y * w + x].dist = r; 103 } 104 qsort(circle, w * h, sizeof(dot_t), cmpdot); 105 106 ret = pipi_new(w * 2, h * 2); 107 pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F); 108 data = (float *)pix->pixels; 109 110 for(n = 0; n < w * h; n++) 111 { 112 x = circle[n].x; 113 y = circle[n].y; 114 115 data[y * (2 * w) + x] = (float)(2 * n + 1) / (w * h * 4 + 1); 116 data[(y + h) * (2 * w) + x + w] = (float)(2 * n + 2) / (w * h * 4 + 1); 117 data[(y + h) * (2 * w) + x] = 1. - (float)(2 * n + 1) / (w * h * 4 + 1); 118 data[y * (2 * w) + x + w] = 1. - (float)(2 * n + 2) / (w * h * 4 + 1); 119 } 120 121 free(circle); 122 123 return ret; 124 } 125 -
libpipi/trunk/pipi/stock.c
r2766 r2767 47 47 } 48 48 49 /* Generate a clustered dithering pattern. */ 50 if(!strncmp(name, "halftone:", 9)) 51 { 52 int w, h = 0; 53 54 w = atoi(name + 9); 55 name = strchr(name + 9, 'x'); 56 if(name) 57 h = atoi(name + 1); 58 if(!h) 59 h = w; 60 61 return pipi_render_halftone(w, h); 62 } 63 49 64 /* Generate an error diffusion matrix. */ 50 65 if(!strncmp(name, "ediff:", 6))
Note: See TracChangeset
for help on using the changeset viewer.