예제 #1
0
파일: gsmlogo.c 프로젝트: daladim/gammu
static GSM_Error savexpm(FILE *file, GSM_MultiBitmap *bitmap)
{
	size_t x,y;

	fprintf(file,"/* XPM */\n");
	fprintf(file,"static char * ala_xpm[] = {\n");
	fprintf(file,"\"%ld %ld 2 1\",\n",
		(long)bitmap->Bitmap[0].BitmapWidth,
		(long)bitmap->Bitmap[0].BitmapHeight);
	fprintf(file,"\".	s c	m #000000	g4 #000000	g #000000	c #000000\",\n");
	fprintf(file,"\"#	s c	m #ffffff	g4 #ffffff	g #ffffff	c #ffffff\",\n");

	for (y=0;y<bitmap->Bitmap[0].BitmapHeight;y++) {
		fprintf(file,"\"");
		for (x=0;x<bitmap->Bitmap[0].BitmapWidth;x++)
			if (GSM_IsPointBitmap(&bitmap->Bitmap[0],x,y)) {
				fprintf(file,".");
			} else {
				fprintf(file,"#");
			}
		fprintf(file,"\"");
		if (y==bitmap->Bitmap[0].BitmapHeight-1) {
			fprintf(file,"};\n");
		} else {
			fprintf(file,",\n");
		}
	}

	return ERR_NONE;
}
예제 #2
0
파일: gsmlogo.c 프로젝트: daladim/gammu
static GSM_Error PrivSaveNLMWBMP(FILE *file, GSM_Bitmap *Bitmap)
{
	unsigned char	buffer[1000];
	size_t		x,y,pos;
	ssize_t		pos2;
	div_t		division;

	pos=0;pos2=7;
	for (y=0;y<Bitmap->BitmapHeight;y++) {
		for (x=0;x<Bitmap->BitmapWidth;x++) {
			if (pos2==7) buffer[pos]=0;
      			if (GSM_IsPointBitmap(Bitmap,x,y)) buffer[pos]|=(1<<pos2);
			pos2--;
			/* going to new line */
			if (pos2<0) {pos2=7;pos++;}
		}
		/* for startup logos - new line with new byte */
		if (pos2!=7) {pos2=7;pos++;}
	}

	division=div(Bitmap->BitmapWidth,8);
	/* For startup logos */
	if (division.rem!=0) division.quot++;

	chk_fwrite(buffer,1,(size_t)(division.quot*Bitmap->BitmapHeight),file);
	return ERR_NONE;
fail:
	return ERR_WRITING_FILE;
}
예제 #3
0
파일: gsmlogo.c 프로젝트: daladim/gammu
static GSM_Error PrivSaveNGGNOL(FILE *file, GSM_MultiBitmap *bitmap)
{
	char 	*buffer=NULL;
	size_t	x=0,y=0;
	size_t	current=0;

	buffer = (char *)malloc(bitmap->Bitmap[0].BitmapHeight * bitmap->Bitmap[0].BitmapWidth);
	if (buffer == NULL) {
		return ERR_MOREMEMORY;
	}

	for (y=0;y<bitmap->Bitmap[0].BitmapHeight;y++) {
		for (x=0;x<bitmap->Bitmap[0].BitmapWidth;x++) {
			if (GSM_IsPointBitmap(&bitmap->Bitmap[0],x,y)) {
				buffer[current++] = '1';
			} else {
				buffer[current++] = '0';
			}
		}
	}
	chk_fwrite(buffer,1,current,file);
	free(buffer);
	buffer=NULL;
	return ERR_NONE;
fail:
	free(buffer);
	buffer=NULL;
	return ERR_WRITING_FILE;
}
예제 #4
0
파일: gsmlogo.c 프로젝트: daladim/gammu
void GSM_ResizeBitmap(GSM_Bitmap *dest, GSM_Bitmap *src, size_t width, size_t height)
{
	size_t startx=0,endx=0,setx=0, starty=0,endy=0,sety=0, x, y;

	if (src->BitmapWidth<=width) {
		startx	= 0;
		endx	= src->BitmapWidth;
		setx	= (width-src->BitmapWidth)/2;
	} else {
		startx	= (src->BitmapWidth-width)/2;
		endx	= startx + width;
		setx	= 0;
	}
	if (src->BitmapHeight<=height) {
		starty	= 0;
		endy	= src->BitmapHeight;
		sety	= (height-src->BitmapHeight)/2;
	} else {
		starty	= (src->BitmapHeight-height)/2;
		endy	= starty + height;
		sety	= 0;
	}
	dest->BitmapHeight	= height;
	dest->BitmapWidth	= width;
	GSM_ClearBitmap(dest);
	for (x=startx;x<endx;x++) {
		for (y=starty;y<endy;y++) {
			if (GSM_IsPointBitmap(src,x,y))
				GSM_SetPointBitmap(dest,setx+x-startx,sety+y-starty);
		}
	}
}
예제 #5
0
파일: gsmlogo.c 프로젝트: daladim/gammu
void GSM_ReverseBitmap(GSM_Bitmap *Bitmap)
{
	size_t x, y;

	for (x=0;x<Bitmap->BitmapWidth;x++) {
		for (y=0;y<Bitmap->BitmapHeight;y++) {
			if (GSM_IsPointBitmap(Bitmap,x,y)) {
				GSM_ClearPointBitmap(Bitmap, x, y);
			} else {
				GSM_SetPointBitmap(Bitmap, x, y);
			}
		}
	}
}
예제 #6
0
파일: gsmlogo.c 프로젝트: daladim/gammu
void GSM_PrintBitmap(FILE *file, GSM_Bitmap *bitmap)
{
	size_t x,y;

	for (y=0;y<bitmap->BitmapHeight;y++) {
		for (x=0;x<bitmap->BitmapWidth;x++) {
			if (GSM_IsPointBitmap(bitmap,x,y)) {
				fprintf(file,"#");
			} else {
				fprintf(file," ");
			}
		}
		fprintf(file,"\n");
	}
}
예제 #7
0
파일: gsmlogo.c 프로젝트: daladim/gammu
void PHONE_EncodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
{
	size_t		width, height, x, y;
	GSM_Bitmap	dest;

	PHONE_GetBitmapWidthHeight(Type, &width, &height);
	if (width == 0 && height == 0) {
		width  = Bitmap->BitmapWidth;
		height = Bitmap->BitmapHeight;
	}
	GSM_ResizeBitmap(&dest, Bitmap, width, height);
	PHONE_ClearBitmap(Type, buffer, width, height);

	for (x=0;x<width;x++) {
		for (y=0;y<height;y++) {
			if (GSM_IsPointBitmap(&dest,x,y)) PHONE_SetPointBitmap(Type, buffer, x, y, width, height);
		}
	}
}
예제 #8
0
파일: bitmap.c 프로젝트: Bakus/gammu
PyObject *BitmapToPython(GSM_Bitmap * bitmap)
{
	char buffer[1000];
	size_t x, y;
	PyObject *xpmval;
	PyObject *s;
	char *t;
	Py_UNICODE *txt;
	Py_UNICODE *sendr;
	PyObject *val;

	xpmval = PyList_New(0);
	if (xpmval == NULL)
		return NULL;

#if 0
	/* Not needed as BitmapWidth is char */
	if (bitmap->BitmapWidth > 999) {
		PyErr_SetString(PyExc_MemoryError,
				"Maximal supported bitmap width is 999 for now!");
		return NULL;
	}
#endif

	snprintf(buffer, 99, "%i %i 2 1", (int)bitmap->BitmapWidth,
		 (int)bitmap->BitmapHeight);
	s = PyString_FromString(buffer);
	if (s == NULL)
		return NULL;
	if (PyList_Append(xpmval, s) != 0) {
		Py_DECREF(xpmval);
		Py_DECREF(s);
		return NULL;
	}
	Py_DECREF(s);

	s = PyString_FromString("# c Black");
	if (s == NULL)
		return NULL;
	if (PyList_Append(xpmval, s) != 0) {
		Py_DECREF(xpmval);
		Py_DECREF(s);
		return NULL;
	}
	Py_DECREF(s);

	s = PyString_FromString("  c None");
	if (s == NULL)
		return NULL;
	if (PyList_Append(xpmval, s) != 0) {
		Py_DECREF(xpmval);
		Py_DECREF(s);
		return NULL;
	}
	Py_DECREF(s);

	buffer[bitmap->BitmapWidth] = 0;

	for (y = 0; y < bitmap->BitmapHeight; y++) {
		for (x = 0; x < bitmap->BitmapWidth; x++) {
			buffer[x] = GSM_IsPointBitmap(bitmap, x, y) ? '#' : ' ';
		}
		s = PyString_FromString(buffer);
		if (s == NULL)
			return NULL;
		if (PyList_Append(xpmval, s) != 0) {
			Py_DECREF(xpmval);
			Py_DECREF(s);
			return NULL;
		}
		Py_DECREF(s);
	}

	t = BitmapTypeToString(bitmap->Type);
	if (t == NULL) {
		Py_DECREF(xpmval);
		return NULL;
	}

	txt = strGammuToPython(bitmap->Text);
	if (txt == NULL) {
		Py_DECREF(xpmval);
		free(t);
		return NULL;
	}

	sendr = strGammuToPython(bitmap->Sender);
	if (sendr == NULL) {
		Py_DECREF(xpmval);
		free(t);
		free(txt);
		return NULL;
	}

	val = Py_BuildValue("{s:s,s:i,s:u,s:i,s:i,s:i,s:i,s:i,s:i,s:O,s:u,s:s}",
			    "Type", t,
			    "Location", (int)bitmap->Location,
			    "Text", txt,
			    "Enabled", (int)bitmap->BitmapEnabled,
			    "DefaultName", (int)bitmap->DefaultName,
			    "DefaultBitmap", (int)bitmap->DefaultBitmap,
			    "DefaultRingtone", (int)bitmap->DefaultRingtone,
			    "RingtoneID", (int)bitmap->RingtoneID,
			    "ID", (int)bitmap->ID,
			    "XPM", xpmval,
			    "Sender", sendr,
			    "NetworkCode", bitmap->NetworkCode);

	Py_DECREF(xpmval);
	free(t);
	free(txt);
	free(sendr);

	return val;
}
예제 #9
0
파일: gsmlogo.c 프로젝트: daladim/gammu
GSM_Error Bitmap2BMP(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap)
{
	size_t		x,i,sizeimage,buffpos=0;
	ssize_t		y, pos;
	unsigned char	buff[1];
	div_t		division;
	gboolean		isfile=FALSE;

	unsigned char header[]={
/*1'st header*/   'B','M',             /* BMP file ID */
                  0x00,0x00,0x00,0x00, /* Size of file */
		  0x00,0x00,           /* Reserved for future use */
		  0x00,0x00,           /* Reserved for future use */
	            62,0x00,0x00,0x00, /* Offset for image data */

/*2'nd header*/     40,0x00,0x00,0x00, /* Length of this part of header */
		  0x00,0x00,0x00,0x00, /* Width of image */
		  0x00,0x00,0x00,0x00, /* Height of image */
		     1,0x00,           /* How many planes in target device */
		     1,0x00,           /* How many colors in image. 1 means 2^1=2 colors */
		  0x00,0x00,0x00,0x00, /* Type of compression. 0 means no compression */
/*Sometimes */    0x00,0x00,0x00,0x00, /* Size of part with image data */
/*ttttttt...*/    0xE8,0x03,0x00,0x00, /* XPelsPerMeter */
/*hhiiiiissss*/   0xE8,0x03,0x00,0x00, /* YPelsPerMeter */
/*part of header*/0x02,0x00,0x00,0x00, /* How many colors from palette is used */
/*doesn't exist*/ 0x00,0x00,0x00,0x00, /* How many colors from palette is required to display image. 0 means all */

/*Color palette*/ 0x00,0x00,0x00,      /* First color in palette in Blue, Green, Red. Here white */
		  0x00,                /* Each color in palette is end by 4'th byte */
                   102, 204, 102,      /* Second color in palette in Blue, Green, Red. Here green */
		  0x00};               /* Each color in palette is end by 4'th byte */

	if (file!=NULL) isfile=TRUE;

	header[22]=bitmap->BitmapHeight;
	header[18]=bitmap->BitmapWidth;

	pos	  = 7;
	sizeimage = 0;
	/*lines are written from the last to the first*/
	for (y = bitmap->BitmapHeight - 1; y >= 0; y--) {
		i=1;
		for (x=0;x<bitmap->BitmapWidth;x++) {
			/*new byte !*/
			if (pos==7) {
				if (x!=0) sizeimage++;
				i++;
				/*each line is written in multiply of 4 bytes*/
				if(i==5) i=1;
			}
			pos--;
			/*going to new byte*/
			if (pos<0) pos=7;
		}
		/*going to new byte*/
		pos=7;
		sizeimage++;
		if (i!=1) {
			/*each line is written in multiply of 4 bytes*/
			while (i!=5) {
				sizeimage++;
				i++;
			}
		}
	}
	dbgprintf(NULL, "Data size in BMP file: %ld\n", (long)sizeimage);
	division=div(sizeimage,256);
	header[35]=division.quot;
	header[34]=sizeimage-(division.quot*256);
  	sizeimage=sizeimage+sizeof(header);
	dbgprintf(NULL, "Size of BMP file: %ld\n", (long)sizeimage);
	division=div(sizeimage,256);
	header[3]=division.quot;
	header[2]=sizeimage-(division.quot*256);

	if (isfile) {
		chk_fwrite(header,1,sizeof(header),file);
	} else {
		memcpy(buffer,header,sizeof(header));
		buffpos += sizeof(header);
	}

	pos=7;
	/*lines are written from the last to the first*/
	for (y=bitmap->BitmapHeight-1;y>=0;y--) {
		i=1;
		for (x=0;x<bitmap->BitmapWidth;x++) {
			/*new byte !*/
			if (pos==7) {
				if (x!=0) {
					if (isfile) {
						chk_fwrite(buff, 1, sizeof(buff), file);
					} else {
						memcpy (buffer+buffpos,buff,1);
						buffpos++;
					}
				}
				i++;
				/*each line is written in multiply of 4 bytes*/
				if(i==5) i=1;
				buff[0]=0;
			}
			if (!GSM_IsPointBitmap(bitmap,x,y)) buff[0]|=(1<<pos);
			pos--;
			/*going to new byte*/
			if (pos<0) pos=7;
		}
		/*going to new byte*/
		pos=7;
		if (isfile) {
			chk_fwrite(buff, 1, sizeof(buff), file);
		} else {
			memcpy (buffer+buffpos,buff,1);
			buffpos++;
		}
		if (i!=1) {
			/*each line is written in multiply of 4 bytes*/
			while (i!=5) {
				buff[0]=0;
				if (isfile) {
					chk_fwrite(buff, 1, sizeof(buff), file);
				} else {
					memcpy (buffer+buffpos,buff,1);
					buffpos++;
				}
				i++;
			}
		}
	}
	return ERR_NONE;
fail:
	return ERR_WRITING_FILE;
}