/* compute local smoothness weight as a sigmoid on image gradient*/ image_t* compute_dpsis_weight(color_image_t *im, float coef, const convolution_t *deriv) { image_t* lum = image_new(im->width, im->height), *lum_x = image_new(im->width, im->height), *lum_y = image_new(im->width, im->height); int i; // ocompute luminance v4sf *im1p = (v4sf*) im->c1, *im2p = (v4sf*) im->c2, *im3p = (v4sf*) im->c3, *lump = (v4sf*) lum->data; for( i=0 ; i<im->height*im->stride/4 ; i++){ *lump = (0.299f*(*im1p) + 0.587f*(*im2p) + 0.114f*(*im3p))/255.0f; lump+=1; im1p+=1; im2p+=1; im3p+=1; } // compute derivatives with five-point tencil convolve_horiz(lum_x, lum, deriv); convolve_vert(lum_y, lum, deriv); // compute lum norm lump = (v4sf*) lum->data; v4sf *lumxp = (v4sf*) lum_x->data, *lumyp = (v4sf*) lum_y->data; for( i=0 ; i<lum->height*lum->stride/4 ; i++){ *lump = -coef*__builtin_ia32_sqrtps( (*lumxp)*(*lumxp) + (*lumyp)*(*lumyp)); lump[0][0] = 0.5f*expf(lump[0][0]); lump[0][1] = 0.5f*expf(lump[0][1]); lump[0][2] = 0.5f*expf(lump[0][2]); lump[0][3] = 0.5f*expf(lump[0][3]); lump+=1; lumxp+=1; lumyp+=1; } image_delete(lum_x); image_delete(lum_y); return lum; }
/* resize an image with bilinear interpolation to fit the new weidht, height ; reallocation is done if necessary */ void image_resize_bilinear_newsize(image_t *dst, const image_t *src, const int new_width, const int new_height){ resize_if_needed_newsize(dst,new_width,new_height); if(new_width < new_height){ image_t *tmp = image_new(new_width,src->height); image_resize_horiz(tmp,src); image_resize_vert(dst,tmp); image_delete(tmp); }else{ image_t *tmp = image_new(src->width,new_height); image_resize_vert(tmp,src); image_resize_horiz(dst,tmp); image_delete(tmp); } }
int main(int argc, char **argv) { unsigned short *image565 = screen_init(); struct image *image = image_new(WIDTH, HEIGHT); struct image *font = image_new(BLOCK_X, BLOCK_Y*50); struct Glyph glyph[50]; int i; recognize_init(); event_init(); image_load(font, "data.raw"); memset(glyph, 0, sizeof(glyph)); printf("Press any key to start..."); getc(stdin); printf("Recognizing 1~25 ...\n"); screen_capture(image565); rgb565_to_rgb24(image->buf, image565); threshold(THRESHOLD, image->buf); recognize(image, font, glyph, 0); for (i = 0; i < 25; ++i) { send_touch(glyph[i].x, glyph[i].y); usleep(100); } printf("\n\nPress any key to continue..."); getc(stdin); printf("Recognizing 26~50 ...\n"); screen_capture(image565); rgb565_to_rgb24(image->buf, image565); threshold(THRESHOLD, image->buf); recognize(image, font, glyph, 1); for (i = 24; i < 50; ++i) { send_touch(glyph[i].x, glyph[i].y); usleep(100); } image_destroy(font); event_destroy(); image_destroy(image); screen_destroy(image565); return 0; }
int recognize_font(struct image *block, struct image *font, int range) { int i, ret = 0; unsigned int weight = ~0U, w; struct image *tmpblk = image_new(BLOCK_X, BLOCK_Y); int from, stop; if (range == 0) { from = 0; stop = 25; } else { from = 24; stop = 50; } for (i = from; i < stop; ++i) { // for (i = 0; i < 50; ++i) { if (font_array[i] == 1) continue; font_getimage(font, tmpblk, i); w = image_weight(tmpblk, block); // printf("[%d] weight: %d\n", i, w); if (w < weight) { weight = w; ret = i; } } // printf("[%d] = %d\n", ret+1, w); image_destroy(tmpblk); font_array[ret] = 1; return ret; }
void filter_threshold(struct image *img, int threshold) { struct image *dst; int x, y; int r, g, b; int min = 0, max = 255; dst = image_new(img->width, img->height); if(threshold < 0) { min = 255; max = 0; threshold = -threshold; } threshold *= 3; for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getpixel(img, x, y, &r, &g, &b); if(r + g + b < threshold) setpixel(dst, x, y, min, min, min); else setpixel(dst, x, y, max, max, max); } image_swap(img, dst); image_free(dst); }
void filter_crop(struct image *img, int xmin, int ymin, int xmax, int ymax) { struct image *dst; int x, y; int r, g, b; if(xmin < 0) xmin = 0; if(ymin < 0) ymin = 0; if(xmax >= img->width) xmax = img->width - 1; if(ymax >= img->height) ymax = img->height - 1; if(xmin >= xmax || ymin >= ymax) return; dst = image_new(xmax - xmin, ymax - ymin); for(y = 0; y < dst->height; y++) for(x = 0; x < dst->width; x++) { getpixel(img, xmin + x, ymin + y, &r, &g, &b); setpixel(dst, x, y, r, g, b); } image_swap(img, dst); image_free(dst); }
/*------------------------------------------------- image_init ----- | Function image_init | | Purpose: Reads serialized image data from a multidimensional | array and deserializes it into an Image instance. One | line of data per array element. | | | Parameters: pixel_arr (IN) -- Multidimensional array of pixels | width (IN) -- Image width retrieved from the header | height (IN) -- Image height retrieved from the header | | | Returns: New Image instance *-------------------------------------------------------------------*/ Image * image_init(char ** pixel_chars, size_t height, size_t width) { Image * retval = image_new(); retval->height = height; retval->width = width; unsigned int rowsize = sizeof(char) * (width + 1); unsigned int row_mem_size = sizeof(char) * (width + 1); unsigned int row_actual_size = row_mem_size + 8 - ((row_mem_size + 8) % 16); debug("Using actual size %u", row_actual_size); int row; for (row = 0; row < height; row++) { int col; char * row_data = *(pixel_chars) + (row * row_actual_size); for (col = 0; col < width; col++) { char c = *(row_data + (col * sizeof(char))); Pixel * pixel = pixel_init(retval, row, col, c); } debug("pixel alloc %u", retval->pixels); } return retval; }
void filter_contrast(struct image *img) { struct image *dst; int histo[256]; int x, y, i, min = 255, max = 0; int r, g, b; dst = image_new(img->width, img->height); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getgray(img, x, y, &r); if(r < min) min = r; if(r > max) max = r; } if(min == max) histo[min] = 127; else for(i = min; i < max + 1; i++) histo[i] = (i - min) * 255 / (max - min); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getgray(img, x, y, &r); setpixel(dst, x, y, histo[r], histo[r], histo[r]); } image_swap(img, dst); image_free(dst); }
/** * Returns a new layer (flat_layer) with all "layer" rendered frame by * frame from "frmin" to "frmax" (inclusive). "layer" can be a set of * layers, so the routine flattens all children to an unique output * layer. * * @param dst_sprite The sprite where to put the new flattened layer. * @param src_layer Generally a set of layers to be flattened. */ LayerImage* layer_new_flatten_copy(Sprite* dst_sprite, const Layer* src_layer, int x, int y, int w, int h, int frmin, int frmax) { UniquePtr<LayerImage> flatLayer(new LayerImage(dst_sprite)); for (int frame=frmin; frame<=frmax; frame++) { // Does this frame have cels to render? if (has_cels(src_layer, frame)) { // Create a new image Image* image = image_new(flatLayer->getSprite()->getImgType(), w, h); try { // Create the new cel for the output layer (add the image to stock too). Cel* cel = new Cel(frame, flatLayer->getSprite()->getStock()->addImage(image)); cel->setPosition(x, y); // Clear the image and render this frame. image_clear(image, 0); layer_render(src_layer, image, -x, -y, frame); flatLayer->addCel(cel); } catch (...) { delete image; throw; } } } return flatLayer.release(); }
void imagetest_write(void) { struct image *image; uint32_t i; struct rect rect; image = image_new(IMAGE_TYPE_8, 640, 480); image_putline(image, 20, 460, 620, 20, 60); image_putellipse(image, 320, 240, 300, 200, 64, 180); image_putcircle(image, 320, 240, 80, 64, 195); rect.x = 60; rect.y = 300; rect.w = 580; rect.h = 180; image_putrect(image, &rect, 80); for(i = 0; i < 256; i++) image_putpixel(image, 20 + i, 50, i); /* image_putstr(image, &image_font_6x10, 100, 40, 12, IMAGE_ALIGN_LEFT, "libchaos rocks!"); image_putstr(image, &image_font_6x10, 160, 80, 11, IMAGE_ALIGN_LEFT, "dschoint");*/ image_save_gif(image, "lala.gif"); image_delete(image); }
static image_t *image_add_padding(image_t *src, int padding) { int i, j; image_t *img = image_new(src->width + 2*padding, src->height + 2*padding); memset(img->data, 0x00, img->stride*img->height*sizeof(float)); for(j = 0; j < src->height; j++) { for(i = 0; i < src->width; i++) { img->data[(j+padding)*img->stride+i+padding] = src->data[j*src->stride+i]; } } for(j = 0; j < padding; j++) { for(i = 0; i < src->width; i++) { img->data[j*img->stride+i+padding] = src->data[(padding-j-1)*src->stride+i]; img->data[(j+padding+src->height)*img->stride+i+padding] = src->data[(src->height-j-1)*src->stride+i]; } } for(j = 0; j < img->height; j++) { for(i = 0; i < padding; i++) { img->data[j*img->stride+i] = img->data[j*img->stride+padding+padding-i-1]; img->data[j*img->stride+i+padding+src->width] = img->data[j*img->stride+img->width-padding-i-1]; } } return img; }
/* return a resize version of the image with bilinear interpolation */ image_t *image_resize_bilinear(const image_t *src, const float scale){ const int width = src->width, height = src->height; const int newwidth = (int) (1.5f + (width-1) / scale); // 0.5f for rounding instead of flooring, and the remaining comes from scale = (dst-1)/(src-1) const int newheight = (int) (1.5f + (height-1) / scale); image_t *dst = image_new(newwidth,newheight); if(height*newwidth < width*newheight){ image_t *tmp = image_new(newwidth,height); image_resize_horiz(tmp,src); image_resize_vert(dst,tmp); image_delete(tmp); }else{ image_t *tmp = image_new(width,newheight); image_resize_vert(tmp,src); image_resize_horiz(dst,tmp); image_delete(tmp); } return dst; }
/** * @brief Copies all image data to a new allocated Image struct. * * @param imagep the source image * * @return pointer to the new allocated image */ struct Image* image_clone(struct Image* imagep) { assert(imagep); struct Image* newimage = image_new(imagep->width, imagep->height); image_map(imagep, newimage, image_clone_mapfunc); return newimage; }
static PyObject* image_get( PyObject* self, PyObject* args ) { static PyObject* cache = NULL; PyObject* argobj; static PyObject* ospath = NULL; PyObject* key; PyObject* item; if( !PyArg_ParseTuple( args, "O", &argobj ) ) return NULL; if ( cache == NULL ) cache = PyDict_New(); if ( PyString_Check( argobj ) ) { // arg is a string; assume it's a filename if ( ospath == NULL ) { PyObject* name = PyString_FromString( "os.path" ); ospath = PyImport_Import( name ); Py_DECREF( name ); if ( ospath == NULL ) return NULL; } if ( !(key = PyObject_CallMethod( ospath, "abspath", "O", argobj )) ) return NULL; } else { key = argobj; Py_INCREF( key ); } if ( ( item = PyDict_GetItem( cache, key ) ) != 0 ) { // hooray, in the cache Py_DECREF( key ); Py_INCREF( item ); return item; } else { argobj = PyTuple_New( 1 ); PyTuple_SetItem( argobj, 0, key ); item = image_new( NULL, argobj ); Py_DECREF( argobj ); if ( item != NULL ) { Py_INCREF( item ); PyDict_SetItem( cache, key, item ); } return item; } }
struct image *get_cam_image(struct caminfo *cam) { static struct image *img = NULL; int len = 0; if(cam->o.use_read) { if(img == NULL) { img = image_new(cam->o.width, cam->o.height); if(img == NULL) { perror("malloc: get_cam_image()"); return NULL; } } /* read an image from camera */ len = read(cam->dev, img->buf, img->bufsize); if(len != img->bufsize) printf("get_cam_image(): len != img->bufsize, just letting you know\n"); if(len <= 0) return NULL; } else { int res; img = (struct image*)malloc(sizeof(struct image)); img->width = cam->o.width; img->height = cam->o.height; img->bufsize = img->width * img->height * 3; img->buf = NULL; cam->vid_v4lmmap.format = cam->pal->val; cam->vid_v4lmmap.frame = 0; cam->vid_v4lmmap.width = cam->o.width; cam->vid_v4lmmap.height = cam->o.height; /* read an image from camera */ res = ioctl(cam->dev, VIDIOCMCAPTURE, &cam->vid_v4lmmap); if(res != 0) return NULL; res = ioctl(cam->dev, VIDIOCSYNC, &cam->vid_v4lmmap); if(res != 0) return NULL; img->buf = cam->mmap; } return img; }
image_t*synth_simple(image_t*alpha, image_t*img) { matrix_t*dst = image_extractchannel(img, IMAGE_YUV_Y); statistics_t*st = statistics_new_frommatrix(dst); complex_matrix_t*c = matrix_fft(dst); matrix_t*m = matrix_new_gaussrandom(dst->width, dst->height, 0, 1); int it; for(it=0;it<10;it++) { complex_matrix_t*s = matrix_fft(m); int t; for(t=0;t<s->width*s->height;t++) { double r = sqrt(c->data[t].real*c->data[t].real + c->data[t].imag*c->data[t].imag); double r2 = sqrt(s->data[t].real*s->data[t].real + s->data[t].imag*s->data[t].imag); if(r2) { s->data[t].real *= r / r2 / (s->width*s->height); s->data[t].imag *= r / r2 / (s->width*s->height); } //s->data[t].imag = 0; } matrix_delete(m); m = complex_matrix_ifft_real(s); matrix_adjust_statistics(m, st); matrix_adjust_minmax(m, st); complex_matrix_delete(s); } //image_t*result = image_from_matrix(m,IMAGE_CLAMP); matrix_t*dst_u = image_extractchannel(img, IMAGE_YUV_U); matrix_t*dst_v = image_extractchannel(img, IMAGE_YUV_V); int u = getmean(img, dst_u); int v = getmean(img, dst_v); image_t*result = image_new(img->width, img->height); int t; for(t=0;t<img->width*img->height;t++) { int yy = m->data[t]; //result->data[t].r = clamp00ff(yy); //result->data[t].g = clamp00ff(yy); //result->data[t].b = clamp00ff(yy); //u = 128; //v = 128; result->data[t].r = clamp00ff(yy + ((360*(v-128))>>8)); result->data[t].g = clamp00ff(yy - ((88*(u-128)+183*(v-128))>>8)); result->data[t].b = clamp00ff(yy + ((455 * (u-128))>>8)); result->data[t].a = 255; } matrix_delete(m); matrix_delete(dst); matrix_delete(dst_u); matrix_delete(dst_v); complex_matrix_delete(c); statistics_delete(st); return result; }
int main(int argc, char** argv) { image_t img; image_new(&img); load_ppm("a.ppm", &img); image_median_filter(&img); save_ppm("b.ppm", &img); image_free(&img); return 0; }
int main_taiji (int argc, char *argv[]) { Image *image; image = image_new (800, 800); image_fill (image, 0xaa);//先将图片的数据区域填满背景色(灰色) draw_Taijitu (image, 300, 0);//填满背景色(灰色)后再在上面画太极图 value值是0(黑色) image_save (image, "taiji_6.pgm");//保存图片 image_free (image); return 0; }
void filter_smooth(struct image *img) { #define SSIZE 3 struct image *dst; int x, y, i, j, val; int r, g, b; dst = image_new(img->width, img->height); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getpixel(img, x, y, &r, &g, &b); setpixel(dst, x, y, r, g, b); } for(y = SSIZE/2; y < img->height - SSIZE/2; y++) for(x = SSIZE/2; x < img->width - SSIZE/2; x++) { val = 0; for(i = 0; i < SSIZE; i++) for(j = 0; j < SSIZE; j++) { getpixel(img, x + j - SSIZE/2, y + i - SSIZE/2, &r, &g, &b); val += r; } i = val / (SSIZE * SSIZE); setpixel(dst, x, y, i, i, i); } /* Remove border */ for(y = 0; y < dst->height; y++) { getpixel(dst, 1, y, &r, &g, &b); setpixel(dst, 0, y, r, g, b); getpixel(dst, dst->width - 2, y, &r, &g, &b); setpixel(dst, dst->width - 1, y, r, g, b); } for(x = 0; x < dst->width; x++) { getpixel(dst, x, 1, &r, &g, &b); setpixel(dst, x, 0, r, g, b); getpixel(dst, x, dst->height - 2, &r, &g, &b); setpixel(dst, x, dst->height - 1, r, g, b); } image_swap(img, dst); image_free(dst); }
void filter_fill_holes(struct image *img) { struct image *dst; int x, y; int r, g, b; dst = image_new(img->width, img->height); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getpixel(img, x, y, &r, &g, &b); setpixel(dst, x, y, r, g, b); } for(y = 0; y < dst->height; y++) for(x = 2; x < dst->width - 2; x++) { int c1, c2, c3, c4, c5; getpixel(img, x-2, y, &c1, &g, &b); getpixel(img, x-1, y, &c2, &g, &b); getpixel(img, x, y, &c3, &g, &b); getpixel(img, x+1, y, &c4, &g, &b); getpixel(img, x+2, y, &c5, &g, &b); if(c1 < 127 && c2 < 127 && c3 > 128 && c4 < 127) c3 = (c1 + c2 + c4) / 3; else if(c2 < 127 && c3 > 128 && c4 < 127 && c5 < 127) c3 = (c2 + c4 + c5) / 3; setpixel(dst, x, y, c3, c3, c3); } for(x = 0; x < dst->width; x++) for(y = 2; y < dst->height - 2; y++) { int c1, c2, c3, c4, c5; getpixel(img, x, y-2, &c1, &g, &b); getpixel(img, x, y-1, &c2, &g, &b); getpixel(img, x, y, &c3, &g, &b); getpixel(img, x, y+1, &c4, &g, &b); getpixel(img, x, y+2, &c5, &g, &b); if(c1 < 127 && c2 < 127 && c3 > 128 && c4 < 127) c3 = (c1 + c2 + c4) / 3; else if(c2 < 127 && c3 > 128 && c4 < 127 && c5 < 127) c3 = (c2 + c4 + c5) / 3; setpixel(dst, x, y, c3, c3, c3); } image_swap(img, dst); image_free(dst); }
struct image *image_load(const char *name) { struct image *img; #if defined(HAVE_SDL_IMAGE_H) SDL_Surface *priv = IMG_Load(name); #elif defined(HAVE_IMLIB2_H) Imlib_Image priv = imlib_load_image(name); #elif defined(HAVE_CV_H) IplImage *priv = cvLoadImage(name, -1); #endif if(!priv) return NULL; #if defined(HAVE_SDL_IMAGE_H) if(priv->format->BytesPerPixel == 1) { img = image_new(priv->w, priv->h); SDL_BlitSurface(priv, NULL, img->priv, NULL); SDL_FreeSurface(priv); return img; } #endif img = (struct image *)malloc(sizeof(struct image)); #if defined(HAVE_SDL_IMAGE_H) img->width = priv->w; img->height = priv->h; img->pitch = priv->pitch; img->channels = priv->format->BytesPerPixel; img->pixels = priv->pixels; #elif defined(HAVE_IMLIB2_H) imlib_context_set_image(priv); img->width = imlib_image_get_width(); img->height = imlib_image_get_height(); img->pitch = 4 * imlib_image_get_width(); img->channels = 4; img->pixels = (char *)imlib_image_get_data(); #elif defined(HAVE_CV_H) img->width = priv->width; img->height = priv->height; img->pitch = priv->widthStep; img->channels = priv->nChannels; img->pixels = priv->imageData; #endif img->priv = (void *)priv; return img; }
t_image *image_copy( t_image *image_src) { t_image *image = image_new( image_src->id.name); image->width = image_src->width; image->height = image_src->height; image->bpp = image_src->bpp; image->size = image_src->size; image->vlst = vlst_copy( image_src->vlst); image->color_type = image_src->color_type; image->data_type = image_src->data_type; image->file_type = image_src->file_type; return image; }
void inorm(const struct image_t *src, struct image_t *dst) { struct fmat_t *fm = fmat_new(src->w, src->h); struct fmat_t *tfm = fmat_new(src->w, src->h); struct image_t *timg = image_new(src->w, src->h); gamma_correction(src, fm); difference_of_gaussian(fm); tanh_smooth(fm, tfm); rescale_to_image(tfm, dst); image_free(&timg); fmat_free(&fm); fmat_free(&tfm); }
static void get_window() { if (!host.inited) { host.tw = image_new(NULL, NULL); /* create and add to list */ if (host.tw) { image_open(host.tw); UpdateWindow(host.tw->hwnd); } host.hdc = NULL; host.count_GetDC = 0; host.window_height = 100; host.line_width = 1; host.color = 0; host.inited = true; } }
struct image *image_dup(struct image *img) { struct image *dst; int x, y; dst = image_new(img->width, img->height); for(y = 0; y < img->height; y++) { for(x = 0; x < img->width; x++) { int r, g, b; getpixel(img, x, y, &r, &g, &b); setpixel(dst, x, y, r, g, b); } } return dst; }
int main (int argc, char *argv[]) { Image *image; image = image_new (2048, 2048); image_fill (image, 0); draw_circle (image, 256, 256, 256, 50); // Draw Label 1 draw_circle (image, 256, 1792, 256, 50); // Draw Label 2 draw_circle (image, 1792, 256, 256, 50); // Draw Label 3 draw_circle (image, 1792, 1792, 256, 50); // Draw Label 4 draw_circle (image, 1024, 1024, 512, 100); // Draw Label 5 image_save (image, "sample.intensities.pgm"); image_free (image); return 0; }
void filter_trick(struct image *img) { #define TSIZE 3 struct image *dst; int x, y, i, j, val, m, more, l, less; int r, g, b; dst = image_new(img->width, img->height); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) setpixel(dst, x, y, 255, 255, 255); for(y = TSIZE/2; y < img->height - TSIZE/2; y++) for(x = TSIZE/2; x < img->width - TSIZE/2; x++) { getpixel(img, x + TSIZE - TSIZE/2, y + TSIZE - TSIZE/2, &val, &g, &b); m = more = l = less = 0; for(i = 0; i < TSIZE; i++) for(j = 0; j < TSIZE; j++) { getpixel(img, x + j - TSIZE/2, y + i - TSIZE/2, &r, &g, &b); if(r > val) { more += r; m++; } else if(r < val) { less += r; l++; } } if(l >= 6) i = less / l; else if(m >= 6) i = more / m; else i = val; setpixel(dst, x, y, i, i, i); } image_swap(img, dst); image_free(dst); }
image_t *image_read(FILE *fp) { JSAMPARRAY buffer; int row_stride; struct jpeg_decompress_struct jpg; struct jpeg_error_mgr jerr; image_t *p; global_image_resize_fun = image_resize_interpolation; jpg.err = jpeg_std_error(&jerr); jpeg_create_decompress(&jpg); jpeg_stdio_src(&jpg, fp); jpeg_read_header(&jpg, TRUE); jpeg_start_decompress(&jpg); if (jpg.data_precision != 8) { fprintf(stderr, "jp2a: can only handle 8-bit color channels\n"); exit(1); } row_stride = jpg.output_width * jpg.output_components; buffer = (*jpg.mem->alloc_sarray)((j_common_ptr) &jpg, JPOOL_IMAGE, row_stride, 1); aspect_ratio(jpg.output_width, jpg.output_height); p = image_new(jpg.output_width, jpg.output_height); while (jpg.output_scanline < jpg.output_height) { jpeg_read_scanlines(&jpg, buffer, 1); if (jpg.output_components == 3) { memcpy(&p->pixels[(jpg.output_scanline-1)*p->w], &buffer[0][0], sizeof(rgb_t)*p->w); } else { rgb_t *pixels = &p->pixels[(jpg.output_scanline-1) * p->w]; // grayscale for (int x = 0; x < (int)jpg.output_width; ++x) pixels[x].r = pixels[x].g = pixels[x].b = buffer[0][x]; } } jpeg_finish_decompress(&jpg); jpeg_destroy_decompress(&jpg); return p; }
char *ascii_read() { FILE *jpeg = webcam_read(); image_t *original = image_read(jpeg), *resized = image_new(opt_width, opt_height); fclose(jpeg); image_clear(resized); image_resize(original, resized); char *ascii = image_print(resized); image_destroy(original); image_destroy(resized); return ascii; }
void filter_greyscale(struct image *img) { struct image *dst; int x, y, i, min = 255, max = 0; int r, g, b; dst = image_new(img->width, img->height); for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { getpixel(img, x, y, &r, &g, &b); int gray = (r + g + b) / 3; setpixel(dst, x, y, gray, gray, gray); } image_swap(img, dst); image_free(dst); }