Browse Source

- image_bitmap

master
Alex 'AdUser' Z 11 years ago
parent
commit
d07970d8d9
  1. 52
      src/image.c
  2. 6
      src/image.h

52
src/image.c

@ -90,55 +90,3 @@ image_from_file(const char *path, const char **errstr)
return img;
}
int
image_bitmap(bitmap_t *bitmap, image_t *image, char **errstr)
{
gdImagePtr src, dst = (NULL, NULL);
int16_t res_x, res_y = (160, 160);
int16_t i, j;
int oldcolor, newcolor, index;
assert((dst = gdImageCreateTrueColor(res_x, res_y)) != NULL);
/* resample to 160x160 */
gdImageCopyResampled(dst, image->data,
0, 0, /* dstX, dstY */
0, 0, /* srcX, srcY */
res_x, res_y, /* dstW, dstH */
image->res_x, image->res_y); /* srcW, srcH */
/* grayscale */
gdFree(src);
src = dst;
assert((dst = gdImageCreateTrueColor(res_x, res_y)) != NULL);
for (i = 0; i < res_x; i++) {
for (j = 0; j < res_x; j++) {
/* WTF: begin */
oldcolor = gdImageGetPixel(src, i, j);
newcolor = 0;
newcolor += 2 * gdImageGreen (src, oldcolor);
newcolor += 3 * gdImageRed (src, oldcolor);
newcolor += 4 * gdImageBlue (src, oldcolor);
newcolor /= 9;
/* WTF: end */
if ((index = gdImageColorExact(dst,newcolor,newcolor,newcolor)) == -1) {
index = gdImageColorAllocate(dst,newcolor,newcolor,newcolor);
}
gdImageSetPixel(dst, i, j, index);
}
}
/* blur */
gdFree(src);
src = dst;
assert((dst = gdImageCreateTrueColor(res_x, res_y)) != NULL);
/* normalize (intensity) */
/* equalize (contrast) (sharpen?) */
/* resample to 16x16 */
/* convert to b&w (treshold?) */
/* make bitmap */
return 0;
}

6
src/image.h

@ -11,11 +11,5 @@ typedef struct
*/
image_t *
image_from_file(const char *path, const char **errstr);
/**
* @returns: 0 on success, -1 on error
*/
int
image_bitmap(bitmap_t *bitmap, image_t *image, char **errstr);
#endif
#define HAS_IMAGE_H 1

Loading…
Cancel
Save