⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 writefile.c

📁 Nemesis a complete Linux video security system. It s idea is a cheap replacement for your commercia
💻 C
字号:
/* Nemesis * Copyright (C) 1999 John Ferlito <johnf@inodes.org> * Copyright (C) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *//* * save pictures to disk (ppm,pgm,jpeg) * * */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <ctype.h>#include <errno.h>#include <jpeglib.h>#include "writefile.h"/* ---------------------------------------------------------------------- *//* * count up the latest block of digits in the passed string * (used for filename numbering */void patch_up(char *name){	char *ptr;		for (ptr = name+strlen(name); ptr >= name; ptr--)		if (isdigit(*ptr))	    		break;	if (ptr < name)		return;	while (*ptr == '9' && ptr >= name)		*(ptr--) = '0';	if (ptr < name)		return;	if (isdigit(*ptr))		(*ptr)++;}int write_jpeg(char *filename, char *data, int width, int height){	struct jpeg_compress_struct cinfo;	struct jpeg_error_mgr jerr;	FILE *fp;	int i;	unsigned char *line;		if (NULL == (fp = fopen(filename,"w"))) {		fprintf(stderr,"grab: can't open %s: %s\n",filename,strerror(errno));		exit(1);		return -1;	}		cinfo.err = jpeg_std_error(&jerr);	jpeg_create_compress(&cinfo);	jpeg_stdio_dest(&cinfo, fp);	cinfo.image_width = width;	cinfo.image_height = height;	cinfo.input_components = 3;	cinfo.in_color_space = JCS_RGB;	jpeg_set_defaults(&cinfo);	jpeg_set_quality(&cinfo, 75, TRUE);	jpeg_start_compress(&cinfo, TRUE);		for (i = 0, line = data; i < height; i++, line += width*3)		jpeg_write_scanlines(&cinfo, &line, 1);		jpeg_finish_compress(&(cinfo));	jpeg_destroy_compress(&(cinfo));	fclose(fp);		return 0;}

⌨️ 快捷键说明

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