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

📄 bmp.h

📁 下载来的一个看图软件的源代码
💻 H
📖 第 1 页 / 共 3 页
字号:
/* libwmf ("ipa/ipa/bmp.h"): library for wmf conversion   Copyright (C) 2000 - various; see CREDITS, ChangeLog, and sources   The libwmf Library is free software; you can redistribute it and/or   modify it under the terms of the GNU Library General Public License as   published by the Free Software Foundation; either version 2 of the   License, or (at your option) any later version.   The libwmf Library 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   Library General Public License for more details.   You should have received a copy of the GNU Library General Public   License along with the libwmf Library; see the file COPYING.  If not,   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,   Boston, MA 02111-1307, USA.  */#ifndef HAVE_GD/* png stuff below adapted from stuff sent to me [fjf] by Lennard D. Rosenthal; * probably used in ImageMagick and may not be covered, therefore, by the LGPL - (fjf) *  * utility routine for saving a pixbuf to a png file. * This was adapted from Iain Holmes' code in gnome-iconedit, and probably * should be in a utility library, possibly in gdk-pixbuf itself. */static void ldr_bmp_png (wmfAPI* API,wmfBMP_Draw_t* bmp_draw,FILE* out){#ifdef HAVE_LIBPNG	wmfRGB rgb;	png_structp png_ptr = 0;	png_infop info_ptr = 0;	png_text text[2];	int i;	int j;	int x;	int y;	int width  = (int) bmp_draw->crop.w;	int height = (int) bmp_draw->crop.h;	int depth = 8; /* ?? bit depth (bits per sample) */	int opacity;	char* ptr = 0;	char* buffer = (char*) wmf_malloc (API,4 * width);	if (ERR (API))	{	WMF_DEBUG (API,"bailing...");		return;	}	png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING,0,0,0);	if (png_ptr == 0) 	{	WMF_DEBUG (API,"Failed to write bitmap as PNG! (png_create_write_struct failed)");		wmf_free (API,buffer);		return;	}	info_ptr = png_create_info_struct (png_ptr);	if (info_ptr == 0)	{	WMF_DEBUG (API,"Failed to write bitmap as PNG! (png_create_info_struct failed)");		png_destroy_write_struct (&png_ptr,0);		wmf_free (API,buffer);		return;	}	if (setjmp (png_ptr->jmpbuf))	{	WMF_DEBUG (API,"Failed to write bitmap as PNG! (setjmp failed)");		png_destroy_write_struct (&png_ptr,&info_ptr);		wmf_free (API,buffer);		return;	}	png_init_io (png_ptr,out);	png_set_IHDR (png_ptr,info_ptr,width,height,depth,		      PNG_COLOR_TYPE_RGB_ALPHA,PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT);	/* Some text to go with the png image */	text[0].key = "Title";	text[0].text = "A converted bitmap";	text[0].compression = PNG_TEXT_COMPRESSION_NONE;	text[1].key = "Software";	text[1].text = "libwmf2";	text[1].compression = PNG_TEXT_COMPRESSION_NONE;	png_set_text (png_ptr,info_ptr,text,2);	/* Write header data	 */	png_write_info (png_ptr,info_ptr);	/* pump the raster data into libpng, one scan line at a time	 */		x = (int) bmp_draw->crop.x;	y = (int) bmp_draw->crop.y;	for (j = 0; j < height; j++)	{	ptr = buffer;		for (i = 0; i < width; i++)		{	opacity = wmf_ipa_bmp_color (API,&(bmp_draw->bmp),&rgb,x+i,y+j);			*ptr++ = (char) rgb.r;			*ptr++ = (char) rgb.g;			*ptr++ = (char) rgb.b;			*ptr++ = (char) ((unsigned char) (opacity & 0xff));		}		png_write_row (png_ptr,(png_bytep) buffer);			}		png_write_end (png_ptr,info_ptr);	png_destroy_write_struct (&png_ptr,&info_ptr);	wmf_free (API,buffer);#else /* HAVE_LIBPNG */	WMF_ERROR (API,"Glitch? No PNG support!");	API->err = wmf_E_Glitch;#endif /* HAVE_LIBPNG */	return;}#endif /* ! HAVE_GD */#ifdef HAVE_GDstatic int ipa_b64_sink (void* context,const char* buffer,int length){	ipa_b64_t* b64 = (ipa_b64_t*) context;	int i = 0;	while (i < length)	{	b64->buffer[b64->length] = buffer[i];		i++;		b64->length++;		if (b64->length == IPA_B64_BUFLEN) ipa_b64_flush (context);	}	return (i);}#endif /* HAVE_GD */#ifdef HAVE_GDstatic void ipa_b64_flush (void* context){	ipa_b64_t* b64 = (ipa_b64_t*) context;	static char B64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";	char buffer[IPA_B64_LEQUIV];	unsigned long ulc1;	unsigned long ulc2;	unsigned long ulc3;	unsigned long ulc;	int triplets = (b64->length + 2) / 3;	int triplen;	int i;	char* ptr = b64->buffer;	char* btr = buffer;	if (b64->length == 0) return;	triplen = triplets * 3;	for (i = b64->length; i < triplen; i++) b64->buffer[i] = 0;	(*btr) = '\n';	btr++;	for (i = 0; i < triplets; i++)	{	ulc1 = (unsigned long) ((unsigned char) (*ptr));		ptr++;		ulc2 = (unsigned long) ((unsigned char) (*ptr));		ptr++;		ulc3 = (unsigned long) ((unsigned char) (*ptr));		ptr++;		ulc = (ulc1 << 16) | (ulc2 << 8) | ulc3;		ulc1 = (ulc & (0x3f << 18)) >> 18;		ulc2 = (ulc & (0x3f << 12)) >> 12;		ulc3 = (ulc & (0x3f <<  6)) >>  6;		ulc &= 0x3f;		(*btr) = B64[ulc1];		btr++;		(*btr) = B64[ulc2];		btr++;		(*btr) = B64[ulc3];		btr++;		(*btr) = B64[ulc ];		btr++;	}	if ((triplen - b64->length) > 1) (*(btr-2)) = '=';	if ((triplen - b64->length) > 0) (*(btr-1)) = '=';	(*btr) = '\0';	wmf_stream_printf (b64->API,b64->out,buffer);	b64->length = 0;}#endif /* HAVE_GD */void wmf_ipa_bmp_b64 (wmfAPI* API,wmfBMP_Draw_t* bmp_draw,wmfStream* out){#ifdef HAVE_GD	gdImage* image = 0;	gdSink sink;	ipa_b64_t b64;	WMF_DEBUG (API,"~~~~~~~~wmf_ipa_bmp_b64");#ifndef HAVE_LIBPNG	WMF_DEBUG (API,"No support for PNG, sorry!");	API->err = wmf_E_DeviceError;	return;#endif /* HAVE_LIBPNG */	image = ipa_bmp_gd (API,bmp_draw);	if (image == 0) return;	b64.API = API;	b64.out = out;	b64.length = 0;	sink.context = (void*) (&b64);	sink.sink = ipa_b64_sink;	gdImagePngToSink (image,&sink);	gdImageDestroy (image);	ipa_b64_flush (sink.context);#endif /* HAVE_GD */}void wmf_ipa_bmp_png (wmfAPI* API,wmfBMP_Draw_t* bmp_draw,char* name){	FILE* file = 0;#ifdef HAVE_GD	gdImage* image = 0;#endif /* HAVE_GD */	WMF_DEBUG (API,"~~~~~~~~wmf_ipa_bmp_png");#ifndef HAVE_LIBPNG	WMF_DEBUG (API,"No support for PNG, sorry!");	API->err = wmf_E_DeviceError;	return;#endif /* HAVE_LIBPNG */	file = fopen (name,"wb");	if (file == 0)	{	WMF_ERROR (API,"Failed to open file to write GD image!");		return;	}#ifdef HAVE_GD	image = ipa_bmp_gd (API,bmp_draw);	if (image)	{	gdImagePng (image,file);		gdImageDestroy (image);	}#else /* HAVE_GD */	ldr_bmp_png (API,bmp_draw,file);	#endif /* HAVE_GD */	fclose (file);}void wmf_ipa_bmp_jpg (wmfAPI* API,wmfBMP_Draw_t* bmp_draw,char* name){#ifdef HAVE_GD	FILE* file = 0;	gdImage* image = 0;	WMF_DEBUG (API,"~~~~~~~~wmf_ipa_bmp_jpg");#ifndef HAVE_LIBJPEG	WMF_DEBUG (API,"No support for JPEG, sorry!");	API->err = wmf_E_DeviceError;	return;#endif /* HAVE_LIBJPEG */	file = fopen (name,"wb");	if (file == 0)	{	WMF_ERROR (API,"Failed to open file to write GD image!");		return;	}	image = ipa_bmp_gd (API,bmp_draw);	if (image)	{	gdImageJpeg (image,file,-1); /* Default quality. */		gdImageDestroy (image);	}	fclose (file);#endif /* HAVE_GD */}#ifdef HAVE_GDstatic gdImage* ipa_bmp_gd (wmfAPI* API,wmfBMP_Draw_t* bmp_draw){	wmfRGB rgb;	int color;	unsigned int ui_x;	unsigned int ui_y;	unsigned int i;	unsigned int j;	gdImage* image = 0;	WMF_DEBUG (API,"~~~~~~~~ipa_bmp_gd");	if (bmp_draw->bmp.data == 0)	{	WMF_ERROR (API,"Glitch! Attempt to write non-existant bitmap.");		API->err = wmf_E_Glitch;		return (0);	}	image = gdImageCreateTrueColor ((int) bmp_draw->crop.w,(int) bmp_draw->crop.h);	if (image == 0)	{	WMF_ERROR (API,"Failed to create GD image!");		API->err = wmf_E_DeviceError;		return (0);	}	ui_x = (unsigned int) bmp_draw->crop.x;	ui_y = (unsigned int) bmp_draw->crop.y;	for (j = 0; j < (unsigned int) bmp_draw->crop.h; j++)	{	for (i = 0; i < (unsigned int) bmp_draw->crop.w; i++)		{	wmf_ipa_bmp_color (API,&(bmp_draw->bmp),&rgb,ui_x+i,ui_y+j);			color = gdImageColorResolve (image,rgb.r,rgb.g,rgb.b);			gdImageSetPixel (image,(int) i,(int) (bmp_draw->crop.h-1-j),color);		}	}	return (image);}#endif /* HAVE_GD */void wmf_ipa_bmp_eps (wmfAPI* API,wmfBMP_Draw_t* bmp_draw,char* name){	wmfRGB rgb;	unsigned int i;	unsigned int j;	unsigned int k;	unsigned int ui_x;	unsigned int ui_y;	unsigned int width;	unsigned int height;	static char hex[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};	char buffer[80];	FILE* file = 0;	WMF_DEBUG (API,"~~~~~~~~wmf_ipa_bmp_eps");	if (bmp_draw->bmp.data == 0)	{	WMF_ERROR (API,"Glitch! Attempt to write non-existant bitmap.");		API->err = wmf_E_Glitch;		return;	}	file = fopen (name,"w");	if (file == 0)	{	WMF_ERROR (API,"Failed to open file to write EPS image!");		API->err = wmf_E_BadFile;		return;	}	ui_x = (unsigned int) bmp_draw->crop.x;	ui_y = (unsigned int) bmp_draw->crop.y;	width  = (unsigned int) bmp_draw->crop.w;	height = (unsigned int) bmp_draw->crop.h;	/* Output as an embedded eps */	fputs ("%!PS-Adobe-2.0 EPSF-2.0\n",file);	fputs ("%%BoundingBox: ",file);	fprintf (file," 0 0 %u %u\n",width,height);		fprintf (file," 0 %d translate\n",1);	fprintf (file," %u %u scale\n",width,height);	/* I'm going to assume it's a color image - TODO: monochrome */	fprintf (file," /picstr %u 3 mul string def\n",width);	fprintf (file," %u %u 8\n",width,height);	fprintf (file," [ %u 0 0 %u 0 0 ]\n",width,height);	fputs (" { currentfile picstr readhexstring pop } false 3\n",file);	fputs (" colorimage\n",file);				for (j = 0; j < height; j++)	{	k = 0;		for (i = 0; i < width; i++)		{	if (k == 78)			{	buffer[k++] = '\n';				buffer[k] = 0;				fputs (buffer,file);				k = 0;			}			wmf_ipa_bmp_color (API,&(bmp_draw->bmp),&rgb,ui_x+i,ui_y+j);			buffer[k++] = hex[(rgb.r & 0xf0) >> 4];			buffer[k++] = hex[ rgb.r & 0x0f      ];			buffer[k++] = hex[(rgb.g & 0xf0) >> 4];			buffer[k++] = hex[ rgb.g & 0x0f      ];			buffer[k++] = hex[(rgb.b & 0xf0) >> 4];			buffer[k++] = hex[ rgb.b & 0x0f      ];		}		if (k > 0)		{	buffer[k++] = '\n';			buffer[k] = 0;			fputs (buffer,file);		}	}	fputs ("showpage\n",file);	fclose (file);	return;}void wmf_ipa_bmp_read (wmfAPI* API,wmfBMP_Read_t* bmp_read){	wmfBMP* bmp = 0;	BMPSource source;	BMPData* data;	WMF_DEBUG (API,"~~~~~~~~wmf_[ipa_]bmp_read");	bmp = &(bmp_read->bmp);	bmp->data = 0;	data = (BMPData*) wmf_malloc (API,sizeof (BMPData));	if (ERR (API))	{	if (API->flags & WMF_OPT_IGNORE_NONFATAL)		{	API->err = wmf_E_None;			bmp->data = 0;		}		WMF_DEBUG (API,"bailing...");		return;	}	data->NColors = 0;	data->rgb = 0;	data->image = 0;	bmp->width  = bmp_read->width;	bmp->height = bmp_read->height;	bmp->data = (void*) data;	source.begin = bmp_read->buffer;	source.end   = bmp_read->buffer + bmp_read->length;	source.ptr   = bmp_read->buffer;

⌨️ 快捷键说明

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