27 #define ONE_HALF (1 << (SCALEBITS - 1))
28 #define FIX(x) ((int) ((x) * (1 << SCALEBITS) + 0.5))
30 #define err_if(expr) do { \
32 fprintf(stderr, "%s\n", strerror(errno)); \
38 unsigned char *
cr,
const unsigned char *
src,
41 int wrap, wrap3, x,
y;
42 int r,
g,
b, r1, g1, b1;
43 const unsigned char *p;
48 for (y = 0; y <
height; y += 2) {
49 for (x = 0; x <
width; x += 2) {
56 lum[0] = (
FIX(0.29900) * r +
FIX(0.58700) * g +
64 lum[1] = (
FIX(0.29900) * r +
FIX(0.58700) * g +
75 lum[0] = (
FIX(0.29900) * r +
FIX(0.58700) * g +
83 lum[1] = (
FIX(0.29900) * r +
FIX(0.58700) * g +
86 cb[0] = ((-
FIX(0.16874) * r1 -
FIX(0.33126) * g1 +
88 cr[0] = ((
FIX(0.50000) * r1 -
FIX(0.41869) * g1 -
102 #define DEFAULT_WIDTH 352
103 #define DEFAULT_HEIGHT 288
104 #define DEFAULT_NB_PICT 50
111 unsigned char *
cb, *
cr;
112 unsigned char *lum_tab, *cb_tab, *cr_tab;
114 lum_tab = malloc(w * h);
115 cb_tab = malloc(w * h / 4);
116 cr_tab = malloc(w * h / 4);
121 f = fopen(filename,
"wb");
122 fprintf(f,
"P5\n%d %d\n%d\n", w, h * 3 / 2, 255);
127 err_if(fwrite(lum_tab, 1, w * h, f) != w * h);
134 for (i = 0; i < h2; i++) {
135 err_if(fwrite(cb, 1, w2, f) != w2);
136 err_if(fwrite(cr, 1, w2, f) != w2);
142 for (i = 0; i < h2; i++) {
143 err_if(fwrite(cb, 1, w2, f) != w2);
146 for (i = 0; i < h2; i++) {
147 err_if(fwrite(cr, 1, w2, f) != w2);
164 if (x < 0 || x >=
width ||
static void pgmyuv_save(const char *filename, int w, int h, const unsigned char *rgb_tab)
static void put_pixel(int x, int y, int r, int g, int b)
static double cb(void *priv, double x, double y)
static unsigned char * rgb_tab
static double lum(void *priv, double x, double y, int plane)
static void rgb24_to_yuv420p(unsigned char *lum, unsigned char *cb, unsigned char *cr, const unsigned char *src, int width, int height)
static double cr(void *priv, double x, double y)