image.c

来自「网络摄像头的webserver」· C语言 代码 · 共 62 行

C
62
字号
#include <stdlib.h>#include "config.h"#include "image.h"voidimage_copy(struct image *dst, const struct image *src){	image_dup(dst, src);	if (src->buf)		memcpy(dst->buf, src->buf, dst->bufsize);	else	{		image_destroy(dst);		dst->buf = NULL;	}}voidimage_new(struct image *img, unsigned int x, unsigned int y){	img->x = x;	img->y = y;	img->bufsize = x * y * 3;	img->buf = malloc(img->bufsize);}voidimage_destroy(struct image *img){	free(img->buf);}voidimage_dup(struct image *dst, const struct image *src){	memcpy(dst, src, sizeof(*dst));	dst->buf = malloc(dst->bufsize);}voidimage_move(struct image *dst, const struct image *src){	image_destroy(dst);	memcpy(dst, src, sizeof(*dst));}floatimage_brightness(struct image *img){	int i;	float sum = 0;	unsigned char *p = img->buf;	for (i=0; i<img->x*img->y; i++) {		sum += *p;		p++;	}	sum /= (img->x * img->y * 3);	return sum;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?