gui.c

00001 /*******************************************************************************
00002 #                 uvcview: Sdl video Usb Video Class grabber           .         #
00003 #This package work with the Logitech UVC based webcams with the mjpeg feature. #
00004 #All the decoding is in user space with the embedded jpeg decoder              #
00005 #.                                                                             #
00006 #                 Copyright (C) 2005 2006 Laurent Pinchart &&  Michel Xhaard     #
00007 #                                                                              #
00008 # This program is free software; you can redistribute it and/or modify         #
00009 # it under the terms of the GNU General Public License as published by         #
00010 # the Free Software Foundation; either version 2 of the License, or            #
00011 # (at your option) any later version.                                          #
00012 #                                                                              #
00013 # This program is distributed in the hope that it will be useful,              #
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of               #
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
00016 # GNU General Public License for more details.                                 #
00017 #                                                                              #
00018 # You should have received a copy of the GNU General Public License            #
00019 # along with this program; if not, write to the Free Software                  #
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    #
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 /* Each pixels in the resulting figure need to be set. For each one take the nearest available in the original surface
00046 If the last Chroma component is U take a V else take U by moving the index in the nearest pixel from the left
00047 This routine only deal with X axis you need to make the original picture with the good height */
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     /* at start Cc mean a U component so LastCc should be a V */
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;                // find V component
00068             else
00069                 Cc = 0;
00070             if (lastCc == Cc) {
00071                 /* no Chroma interleave correct by moving the index */
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 }
Generated on Sun May 8 08:41:22 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3