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

📄 bmp.h

📁 下载来的一个看图软件的源代码
💻 H
📖 第 1 页 / 共 3 页
字号:
	ReadBMPImage (API,bmp,&source);	if (ERR (API))	{	if (API->flags & WMF_OPT_IGNORE_NONFATAL)		{	API->err = wmf_E_None;			bmp->data = 0;		}	}}void wmf_ipa_bmp_free (wmfAPI* API,wmfBMP* bmp){	BMPData* data;	WMF_DEBUG (API,"~~~~~~~~wmf_[ipa_]bmp_free");	if (bmp->data == 0) return;	data = (BMPData*) bmp->data;	if (data->rgb)   wmf_free (API,(void*) data->rgb  );	if (data->image) wmf_free (API,(void*) data->image);	wmf_free (API,bmp->data);	bmp->data = 0;}wmfBMP wmf_ipa_bmp_copy (wmfAPI* API,wmfBMP* bmp,unsigned int width,unsigned int height){	wmfBMP copy;	wmfRGB rgb;	BMPData* copy_data = 0;	BMPData* data = 0;	float x;	float y;	int i;	int j;	int opacity;	size_t size;	WMF_DEBUG (API,"~~~~~~~~wmf_[ipa_]bmp_copy");	copy.width  = width;	copy.height = height;	copy.data = 0;	if (bmp->data == 0) return (copy);	data = (BMPData*) bmp->data;	copy.data = wmf_malloc (API,sizeof (BMPData));	if (ERR (API))	{	WMF_DEBUG (API,"bailing...");		return (copy);	}	copy_data = (BMPData*) copy.data;	if (data->rgb)	{	copy_data->NColors = data->NColors;		copy_data->rgb = (wmfRGB*) wmf_malloc (API,data->NColors * sizeof (wmfRGB));		if (ERR (API))		{	WMF_DEBUG (API,"bailing...");			wmf_free (API,copy.data);			copy.data = 0;			return (copy);		}	}	else	{	copy_data->NColors = 0;		copy_data->rgb = 0;	}	copy_data->bits_per_pixel = data->bits_per_pixel;	copy_data->bytes_per_line = 4 * ((width * copy_data->bits_per_pixel + 31) / 32);	size = height * copy_data->bytes_per_line * sizeof (unsigned char);	copy_data->image = (unsigned char*) wmf_malloc (API,size);	if (ERR (API))	{	WMF_DEBUG (API,"bailing...");		if (copy_data->rgb) wmf_free (API,copy_data->rgb);		wmf_free (API,copy.data);		copy.data = 0;		return (copy);	}	copy_data->masked = data->masked;	copy_data->flipped = data->flipped;	/* Data structure is complete, now to copy the image... */	for (j = 0; j < height; j++)	{	y = (float) ((double) j * (double) bmp->height / (double) height);		for (i = 0; i < width; i++)		{	x = (float) ((double) i * (double) bmp->width / (double) width);			opacity = wmf_ipa_bmp_interpolate (API,bmp,&rgb,x,y);			if (opacity < 0) break; /* Shouldn't occur, I think */			wmf_ipa_bmp_setcolor (API,&copy,&rgb,(unsigned char) opacity,i,j);		}	}	return (copy);}int wmf_ipa_bmp_color (wmfAPI* API,wmfBMP* bmp,wmfRGB* rgb,unsigned int x,unsigned int y){	int status = -1; /* error value *//*	WMF_DEBUG (API,"~~~~~~~~wmf_[ipa_]bmp_color"); */	rgb->r = 0;	rgb->g = 0;	rgb->b = 0;	if (bmp->data && (x >= 0) && (x < bmp->width) && (y >= 0) && (y < bmp->height))	{	status = ExtractColor (API,bmp,rgb,x,y);	}	else if ((API->flags & WMF_OPT_IGNORE_NONFATAL) == 0)	{	WMF_ERROR (API,"Point outside bitmap");		API->err = wmf_E_Glitch;	}	return (status);}int wmf_ipa_bmp_interpolate (wmfAPI* API,wmfBMP* bmp,wmfRGB* rgb,float x,float y){	int status = -1; /* error value */	unsigned int i1;	unsigned int i2;	unsigned int j1;	unsigned int j2;	unsigned char o_11;	unsigned char o_12;	unsigned char o_21;	unsigned char o_22;	float f_11;	float f_12;	float f_21;	float f_22;	wmfRGB rgb_11;	wmfRGB rgb_12;	wmfRGB rgb_21;	wmfRGB rgb_22;/*	WMF_DEBUG (API,"~~~~~~~~wmf_[ipa_]bmp_interpolate"); */	i1 = (unsigned int) floor (x);	i2 = (unsigned int) ceil (x);	j1 = (unsigned int) floor (y);	j2 = (unsigned int) ceil (y);	if (i1 >= (bmp->width - 2))	{	i1 = bmp->width - 2;		i2 = bmp->width - 1;	}	if (i1 < 0)	{	i1 = 0;		i2 = 1;	}	if (j1 >= (bmp->height - 2))	{	j1 = bmp->height - 2;		j2 = bmp->height - 1;	}	if (j1 < 0)	{	j1 = 0;		j2 = 1;	}	if ((i1 == i2) && (j1 == j2)) return (wmf_ipa_bmp_color (API,bmp,rgb,i1,j1));	i2 = i1 + 1;	j2 = j1 + 1;	rgb->r = 0;	rgb->g = 0;	rgb->b = 0;	status = wmf_ipa_bmp_color (API,bmp,&rgb_11,i1,j1);	if (status < 0) return (status);	o_11 = (unsigned char) status;	status = wmf_ipa_bmp_color (API,bmp,&rgb_12,i2,j1);	if (status < 0) return (status);	o_12 = (unsigned char) status;	status = wmf_ipa_bmp_color (API,bmp,&rgb_21,i1,j2);	if (status < 0) return (status);	o_21 = (unsigned char) status;	status = wmf_ipa_bmp_color (API,bmp,&rgb_22,i2,j2);	if (status < 0) return (status);	o_22 = (unsigned char) status;	x -= (float) i1;	y -= (float) j1;	f_11 = (1 - x) * (1 - y);	f_12 = x * (1 - y);	f_22 = x * y;	f_21 = (1 - x) * y;	status = (int) (rgb_11.r * f_11 + rgb_21.r * f_21 + rgb_22.r * f_22 + rgb_12.r * f_12);	rgb->r = (unsigned char) ((status < 0) ? 0 : ((status > 255) ? 255 : status));	status = (int) (rgb_11.g * f_11 + rgb_21.g * f_21 + rgb_22.g * f_22 + rgb_12.g * f_12);	rgb->g = (unsigned char) ((status < 0) ? 0 : ((status > 255) ? 255 : status));	status = (int) (rgb_11.b * f_11 + rgb_21.b * f_21 + rgb_22.b * f_22 + rgb_12.b * f_12);	rgb->b = (unsigned char) ((status < 0) ? 0 : ((status > 255) ? 255 : status));	status = (int) (o_11 * f_11 + o_21 * f_21 + o_22 * f_22 + o_12 * f_12);	status = ((status < 0) ? 0 : ((status > 255) ? 255 : status));	return (status);}void wmf_ipa_bmp_setcolor (wmfAPI* API,wmfBMP* bmp,wmfRGB* rgb,unsigned char opacity,                           unsigned int x,unsigned int y){	/* WMF_DEBUG (API,"~~~~~~~~wmf_[ipa_]bmp_setcolor"); */	if (bmp->data && (x >= 0) && (x < bmp->width) && (y >= 0) && (y < bmp->height))	{	SetColor (API,bmp,rgb,opacity,x,y);	}	else if ((API->flags & WMF_OPT_IGNORE_NONFATAL) == 0)	{	WMF_ERROR (API,"Point outside bitmap");		API->err = wmf_E_Glitch;	}}/* Following source adapted from ImageMagick-5.2.7's coders/bmp.c, hence:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                                                                             %%                                                                             %%                            BBBB   M   M  PPPP                               %%                            B   B  MM MM  P   P                              %%                            BBBB   M M M  PPPP                               %%                            B   B  M   M  P                                  %%                            BBBB   M   M  P                                  %%                                                                             %%                                                                             %%                    Read/Write ImageMagick Image Format.                     %%                                                                             %%                                                                             %%                              Software Design                                %%                                John Cristy                                  %%                                 July 1992                                   %%                                                                             %%                                                                             %%  Copyright (C) 2001 ImageMagick Studio, a non-profit organization dedicated %%  to making software imaging solutions freely available.                     %%                                                                             %%  Permission is hereby granted, free of charge, to any person obtaining a    %%  copy of this software and associated documentation files ("ImageMagick"),  %%  to deal in ImageMagick without restriction, including without limitation   %%  the rights to use, copy, modify, merge, publish, distribute, sublicense,   %%  and/or sell copies of ImageMagick, and to permit persons to whom the       %%  ImageMagick is furnished to do so, subject to the following conditions:    %%                                                                             %%  The above copyright notice and this permission notice shall be included in %%  all copies or substantial portions of ImageMagick.                         %%                                                                             %%  The software is provided "as is", without warranty of any kind, express or %%  implied, including but not limited to the warranties of merchantability,   %%  fitness for a particular purpose and noninfringement.  In no event shall   %%  ImageMagick Studio be liable for any claim, damages or other liability,    %%  whether in an action of contract, tort or otherwise, arising from, out of  %%  or in connection with ImageMagick or the use or other dealings in          %%  ImageMagick.                                                               %%                                                                             %%  Except as contained in this notice, the name of the ImageMagick Studio     %%  shall not be used in advertising or otherwise to promote the sale, use or  %%  other dealings in ImageMagick without prior written authorization from the %%  ImageMagick Studio.                                                        %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/static size_t ReadBlob (BMPSource* src,size_t length,unsigned char* buffer){	size_t count = 0;	for (count = 0; count < length; count++)	{	if (src->ptr >= src->end) break;		buffer[count] = (*(src->ptr));		src->ptr++;	}	return (count);}static int ReadBlobByte (BMPSource* src){	int byte;	if (src->ptr >= src->end) return (EOF);	byte = (int) (*(src->ptr));	src->ptr++;	return (byte);}static unsigned short ReadBlobLSBShort (BMPSource* src){	unsigned short value;	unsigned char buffer[2];	value = ReadBlob (src,2,buffer);	if (value < 2) return (~value);	value  = buffer[1] << 8;	value |= buffer[0];	return (value);}static unsigned long ReadBlobLSBLong (BMPSource* src){	unsigned long value;	unsigned char buffer[4];	value = ReadBlob (src,4,buffer);	if (value < 4) return (~value); /* i.e., = -1 */	value  = buffer[3] << 24;	value |= buffer[2] << 16;	value |= buffer[1] <<  8;	value |= buffer[0];	return (value);}static long TellBlob (BMPSource* src){	return ((long) (src->ptr - src->begin));}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                                                                             %%                                                                             %%   D e c o d e I m a g e                                                     %%                                                                             %%                                                                             %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Method DecodeImage unpacks the packed image pixels into runlength-encoded%  pixel packets.%%  A description of each parameter follows:%%    o compression:  A value of 1 means the compressed pixels are runlength%      encoded for a 256-color bitmap.  A value of 2 means a 16-color bitmap.%%    o pixels:  The address of a byte (8 bits) array of pixel data created by%      the decoding process.%%*/static void DecodeImage (wmfAPI* API,wmfBMP* bmp,BMPSource* src,unsigned int compression,unsigned char* pixels){	int byte;	int count;	int i;	U16 x;	U16 y;	U32 u;	unsigned char* q;	for (u = 0; u < ((U32) bmp->width * (U32) bmp->height); u++) pixels[u] = 0;	byte = 0;	x = 0;	q = pixels;	for (y = 0; y < bmp->height; )	{	count = ReadBlobByte (src);		if (count == EOF) break;		if (count != 0)		{	/* Encoded mode. */			byte = ReadBlobByte (src);			for (i = 0; i < count; i++)			{	if (compression == 1)				{	(*(q++)) = (unsigned char) byte;				}				else				{	(*(q++)) = ((i & 0x01) ? (byte & 0x0f) : ((byte >> 4) & 0x0f));					x++;				}			}		}		else		{	/* Escape mode. */			count = ReadBlobByte (src);			if (count == 0x01) return;			switch (count)			{			case 0x00:			 {	/* End of line. */				x = 0;				y++;				q = pixels + y * bmp->width;				break;			 }			case 0x02:			 {	/* Delta mode. */				x += ReadBlobByte (src);				y += ReadBlobByte (src);				q = pixels + y * bmp->width + x;				break;			 }			default:			 {	/* Absolute mode. */				for (i = 0; i < count; i++)				{	if (compression == 1)					{	(*(q++)) = ReadBlobByte (src);					}					else					{	if ((i & 0x01) == 0) byte = ReadBlobByte (src);						(*(q++)) = ((i & 0x01) ? (byte & 0x0f) : ((byte >> 4) & 0x0f));					}					x++;				}				/* Read pad byte. */				if (compression == 1)				{	if (count & 0x01) byte = ReadBlobByte (src);				}				else				{	if (((count & 0x03) == 1) || ((count & 0x03) == 2))					{	byte = ReadBlobByte (src);					}				}				break;			 }			}		}/* ?? TODO 	if (QuantumTick (y,image->rows)) MagickMonitor (LoadImageText,y,image->rows); */	}	byte = ReadBlobByte (src);  /* end of line */	byte = ReadBlobByte (src);	return;}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

⌨️ 快捷键说明

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