gui.c
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <unistd.h>
00027 #include <sys/types.h>
00028 #include <sys/stat.h>
00029 #include <sys/file.h>
00030 #include <string.h>
00031
00032 #include "gui.h"
00033 #include "utils.h"
00034 #include "button.h"
00035
00036 #define ADDRESSE(x,y,w) (((y)*(w))+(x))
00037
00038 unsigned char *YUYVbutt = NULL;
00039
00040 typedef struct YUYV {
00041 unsigned char Y0;
00042 unsigned char U0;
00043 } YUYV;
00044
00045
00046
00047
00048
00049 static int resize(unsigned char *INbuff, unsigned char *OUTbuff,
00050 int Owidth, int Oheight, int width, int height)
00051 {
00052 int rx;
00053 int xscale;
00054 int x, y;
00055 int Cc, lastCc;
00056 YUYV *input = (YUYV *) INbuff;
00057 YUYV *output = (YUYV *) OUTbuff;
00058 if (!width || !height)
00059 return -1;
00060
00061 lastCc = 1;
00062 xscale = (Owidth << 16) / width;
00063 for (y = 0; y < height; y++) {
00064 for (x = 0; x < width; x++) {
00065 rx = x * xscale >> 16;
00066 if (((2 * rx + 1) & 0x03) == 3)
00067 Cc = 1;
00068 else
00069 Cc = 0;
00070 if (lastCc == Cc) {
00071
00072 rx -= 1;
00073 Cc = !Cc;
00074 }
00075 memcpy(output++, &input[ADDRESSE((int) rx, (int) y, Owidth)],
00076 sizeof(YUYV));
00077 lastCc = Cc;
00078 }
00079 }
00080 return 0;
00081 }
00082
00083 int creatButt(int width, int height)
00084 {
00085 int wOrg = 0;
00086 int hOrg = 0;
00087 jpeg_decode(&YUYVbuttOrg, bouttons, &wOrg, &hOrg);
00088 if (wOrg != BUTTWIDTH || hOrg != BUTTHEIGHT) {
00089 printf(" alloc jpeg Button fail !!\n");
00090 goto err;
00091 }
00092 YUYVbutt = (unsigned char *) calloc(1, width * height << 1);
00093 if (!YUYVbutt) {
00094 printf(" alloc Button fail !!\n");
00095 goto err;
00096 }
00097 if (resize(YUYVbuttOrg, YUYVbutt, BUTTWIDTH, BUTTHEIGHT, width, height)
00098 < 0) {
00099 printf(" resize Button fail !!\n");
00100 goto err;
00101 }
00102 return 0;
00103 err:
00104 exit(0);
00105 }
00106 int destroyButt(void)
00107 {
00108 free(YUYVbutt);
00109 YUYVbutt = NULL;
00110 free(YUYVbuttOrg);
00111 YUYVbuttOrg = NULL;
00112 }