/************************************************************************
*Function Name : Userinfo_Allonline *
*Description : °´Ôͼ·Å´ó»òÕßËõСͼƬ£¬Ö»ÄܶÔÕÛËõ·Å£¬Ôݲ»Ö§³ÖÆäËûËõ·Å *
±ÈÀý£¬×¢Ò⣬Ëõ·ÅµÄʱºònewx»òÕßnewyÖ»ÌîÒ»¸ö£¬ÁíÒ»¸öÌî0 *
Èç¹ûÁ½¸ö¶¼Ìî0, ±íʾÒÔԳߴçÊä³ö *
*Newx : Ä¿±êͼÏñµÄxÖ᳤¶È *
*Newy : Ä¿±êͼÏñµÄyÖ᳤¶È *
*Bmpfd : ÒѾ´ò¿ªµÄͼƬÃèÊö·û *
*Ops : LCD²Ù×÷½á¹¹Ì壬Ïê¼ûµç×ÓÏà²áÏîÄ¿ *
*ReturnValue : ÊÇÕûÐλº´æµØÖ·£¬´Ë±£´æÁËͼƬµÄÈ«²¿ÑÕÉ«ÐÅÏ¢£¬ÊǽâÂëºÃµÄ *
RGBÊý¾Ý£¬½ÓÊÕµ½Ö®ºó¼´¿É°´Ô³ß´ç´òӡͼƬ *
*Author & date : Han Yang & 2018-02-24 *
************************************************************************/
struct Display_Operations //FB½á¹¹ÌåÔÐÍ
{
char *name;
int width;
int height;
int (*display_init)(void);
void (*pixel_drawpoint)(int xpos, int ypos, int color);
void (*pixel_drawline)(int xstart, int ystart, int xend, int yend, int color);
void (*pixel_rectangle)(int x, int y, int lenth, int heigh, int color);
void (*pixel_erectangle)(int x, int y, int lenth, int heigh, int color);
void (*pixel_ecircle)(int x, int y, int r, int color);
void (*pixel_circle)(int x, int y, int r, int color);
void (*display_clean)(int bkcolor);
void (*display_destroy)(void);
struct Display_Operations *pnext;
};
unsigned int *zoomin_zoomout(int newx, int newy, int bmpfd, struct Display_Operations *ops)
{
int i, j; //Ñ»·Ê¹ÓÃ
int m, n; //ͼƬ·Å´óÓÃ
int count; //Ô´»º´æ³¤¶È¼ÆÊý
int number; //Ô´Êý¾ÝµãÊýÁ¿
short tempbmp; //µ±Î»ÊýÊÇ16bitµÄʱºòÔÝ´æÑÕÉ«Êý¾Ý
char *data; //dataÔͼƬ»º´æ
unsigned int *buffer; //ÓÃÀ´´æ·ÅÕæÕýµÄÔ´ÑÕÉ«Êý¾Ý
unsigned int *desbuf; //ÓÃÀ´´æ·ÅÕæÕýµÄÄ¿±êÑÕÉ«Êý¾Ý
unsigned int *srctemp; //ËõСµÄʱºòÓÃÀ´ÁÙʱ±£´æ»º´æµØÖ·
unsigned int *deshold = desbuf; //±£´æÄ¿µÄͼƬ»º´æµÄÊ×µØÖ·
int scale; //µÃµ½±ÈÀý
BITMAPFILEHEADER bmpheader; //¶¨ÒåÎļþÍ·½á¹¹Ìå
BITMAPINFOHEADER bmpinfo; //¶¨ÒåÎļþÐÅÏ¢½á¹¹Ìå
read(bmpfd, &bmpheader, sizeof(BITMAPFILEHEADER)); //¶ÁÈ¡HEADÍ·Îļþ³¤¶ÈµÄÊý¾Ý
read(bmpfd, &bmpinfo, sizeof(BITMAPINFOHEADER)); //¶ÁÈ¡INFOÍ·Îļþ³¤¶ÈµÄÊý¾Ý
number = bmpinfo.ciWidth * bmpinfo.ciHeight * 4; //Ô´Êý¾ÝµãµÄÊýÁ¿
buffer = (unsigned int *)malloc(number); //µÃµ½¿ÉÒÔ´æ·ÅÏÂËùÓеãµÄ¿Õ¼ä
number = bmpinfo.ciWidth * bmpinfo.ciHeight; //ÏÖÔÚ´æ·ÅµÄÊÇÕæÕýµÄµãÊýÁ¿
srctemp = buffer; //±£´æÊý¾ÝÊ×µØÖ·
switch(bmpinfo.ciBitCount) //µÃµ½´æ·ÅÔͼƬÐèÒª¶à´óµÄ»º´æ
{
case 16: //16µÄ½âÂë¿ÉÄÜÓÐÎÊÌ⣬Óöµ½Ê±ÔÙ½â¾ö
count = bmpinfo.ciWidth * bmpinfo.ciHeight * 2;
data = (char *)malloc(count);
if(data == NULL)
{
printf("source data alloc error\r\n");
return NULL;
}
read(bmpfd, data, count); //½«Ô´»º´æ¶ÁÈ¡³öÀ´·Åµ½dataÀïÃæ
if(!bmpinfo.ciCompress)
{
for(i = 0; i < bmpinfo.ciWidth * bmpinfo.ciHeight; i++)
{
tempbmp = ((data[i * 2 + 1] >> 1 & 0x1f) << 11) | ((((data[i * 2] & 0x07) << 2) | (data[i * 2 + 1] & 0xc0) >> 6) << 6)
| (data[i * 2] >> 3);
*buffer++ = (((unsigned int)tempbmp & 0xf800) << 16) | (((unsigned int)tempbmp & 0x7e0) << 8) | ((unsigned int)tempbmp & 0x1f); //µÃµ½intÐÍÑÕÉ«ÐÅÏ¢
}
}
if(bmpinfo.ciCompress)
{
for(i = 0; i < bmpinfo.ciWidth * bmpinfo.ciHeight; i++)
{
tempbmp = (data[i * 2] << 8) | data[i * 2 + 1];
*buffer++ = (((unsigned int)tempbmp & 0xf800) << 16) | (((unsigned int)tempbmp & 0x7e0) << 8) | ((unsigned int)tempbmp & 0x1f); //µÃµ½intÐÍÑÕÉ«ÐÅÏ¢
}
}
free(data); //ÊͷŵôÔ´»º´æ
break;
case 24: //24µÄ½âÂëûÓÐÎÊÌ⣬¿ÉÒÔÕý³£Ê¹ÓÃ
count = bmpinfo.ciWidth * bmpinfo.ciHeight * 3;
data = (char *)malloc(count);
if(data == NULL)
{
printf("source data alloc error\r\n");
return NULL;
}
read(bmpfd, data, count); //¶ÁÈ¡Õû¸öÎļþµÄÊý¾Ý
for(i = 0; i < bmpinfo.ciWidth * bmpinfo.ciHeight; i++)
{
*buffer++ = data[i * 3] | (data[i * 3 + 1] << 8) | (data[i * 3 + 2] << 16); //µÃµ½Êý¾ÝλÊý
}
free(data);
break;
case 32: //32µÄ½âÂëÓÐÎÊÌ⣬Óöµ½Ê±ÔÙ½â¾ö
count = bmpinfo.ciWidth * bmpinfo.ciHeight * 4;
data = (char *)malloc(count);
if(data == NULL)
{
printf("source data alloc error\r\n");
return NULL;
}
read(bmpfd, data, count); //¶ÁÈ¡Ò»ÐеÄÊý¾Ý
for(i = 0; i < bmpinfo.ciWidth * bmpinfo.ciHeight; i++)
{
*buffer++ = data[i * 4] | (data[i * 4 + 1] << 8) | (data[i * 4 + 2] << 16); //ת»»Îª0:8:8:8
}
free(data);
break;
}
//ÏÖÔÚÒѾ»ñµÃÁËÈ«²¿µÄÑÕÉ«Êý¾Ý
if((newx == 0) && (newy == 0)) //Èç¹ûÓÐÁ½¸ö·½Ïò¶¼Îª0,±íʾԻÊä³ö
{
return srctemp; //·µ»ØÄ¿±ê»º´æ£¬Ä¿±ê»º´æµÄÄÚÈݺÍÔ´»º´æÊÇÒ»ÑùµÄ
}
if(newx == 0) //ÒÔY·½ÏòµÄ±ÈÀýÀ´Ëõ·Å
{
printf("this is newx\r\n");
newx = (double)bmpinfo.ciWidth * newy / bmpinfo.ciHeight; //µÃµ½X·½ÏòµÄÐÂÖµ
if(newy < bmpinfo.ciHeight) //Èç¹ûлÃæСÓÚÔ»Ãæ
{
scale = (double)bmpinfo.ciHeight / newy; //µÃµ½ËõС±ÈÀý
}
else //Èç¹ûлÃæ´óÓÚÔ»Ãæ
{
scale = (double)newy /bmpinfo.ciHeight; //µÃµ½·Å´ó±ÈÀý
}
}
else if(newy == 0) //ÒÔX·½ÏòµÄ±ÈÀýÀ´Ëõ·Å
{
printf("this is newy\r\n");
newy = (double)bmpinfo.ciHeight * newx / bmpinfo.ciWidth; //µÃµ½Y·½ÏòµÄÐÂÖµ
if(newx < bmpinfo.ciWidth) //Èç¹ûлÃæСÓÚÔ»Ãæ
{
scale = (double)bmpinfo.ciWidth / newx; //µÃµ½ËõС±ÈÀý
}
else //Èç¹ûлÃæ´óÓÚÔ»Ãæ
{
scale = (double)newx / bmpinfo.ciWidth; //µÃµ½·Å´ó±ÈÀý
}
}
printf("newx = %d newy = %d\r\n", newx, newy);
desbuf = (unsigned int *)malloc(newx * newy * 4); //µÃµ½Ä¿±ê»º´æ
if(desbuf == NULL) //Èç¹û»º´æΪ¿Õ
{
free(buffer); //ÊͷŵôÔ´»º´æ
return NULL;
}
//´ËʱdesbufΪ¿ÕµÄÄ¿±ê»º´æ£¬bufferΪԴ»º´æ,¶¼ÊÇintÐ͵Ä
deshold = desbuf; //±£´æÄ¿±ê»º´æÊ×µØÖ·
if(newx < bmpinfo.ciWidth) //Èç¹ûÊÇËõСµÄÇé¿ö
{
for(i = 0; i < newy; i++) //»ñµÃÄ¿±êͼƬ£¬desholdΪĿ±êͼƬ
{
buffer = srctemp + i * scale * bmpinfo.ciWidth; //µÚ¶àÉÙÐпªÊ¼
for(j = 0; j < newx; j++)
{
*desbuf++ = *(buffer + j * scale); //È¡ÖмäµÄijЩµã
}
desbuf = desbuf - 1; //ÐÞÕýÇãб½Ç¶È
}
}
else //Èç¹ûÊÇ·Å´óµÄÇé¿ö
{
for(i = 0; i < bmpinfo.ciHeight; i++) //ÏÈÈ·¶¨ÐÐ
{
buffer = srctemp + i * bmpinfo.ciWidth; //µÚ¶àÉÙÐпªÊ¼
for(j = 0; j < scale; j++) //ÿһÐÐҪȡֵ¶àÉÙ´Î
{
for(m = 0; m < bmpinfo.ciWidth; m++) //ÿһÐеÄÈ¡Öµ·¶Î§
{
for(n = 0; n < scale; n++) //ÿһÐеÄÿ¸öµãҪȡֵ¶àÉÙ´Î
{
*desbuf++ = *(buffer + m); //È¡µã
}
}
}
desbuf = desbuf - 2; //ÐÞÕýͼƬÏñËØ£¬·ÀÖ¹Çãб
}
}
free(srctemp); //ÊÍ·ÅͼƬԴ»º´æ
return deshold; //·µ»ØÄ¿±ê»º´æ£¬´æµÄÊÇËõСºóµÄͼƬÊý¾Ý
}
}