📄 calibrate.c
字号:
/* * Copyright (c) 2003 Century Software, Inc. All Rights Reserved. * * This file is part of the PIXIL Operating Environment * * The use, copying and distribution of this file is governed by one * of two licenses, the PIXIL Commercial License, or the GNU General * Public License, version 2. * * Licensees holding a valid PIXIL Commercial License may use this file * in accordance with the PIXIL Commercial License Agreement provided * with the Software. Others are governed under the terms of the GNU * General Public License version 2. * * This file may be distributed and/or modified under the terms of the * GNU General Public License version 2 as published by the Free * Software Foundation and appearing in the file LICENSE.GPL included * in the packaging of this file. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the government is subject to * restriction as set forth in paragraph (b)(3)(b) of the Rights in * Technical Data and Computer Software clause in DAR 7-104.9(a). * * See http://www.pixil.org/gpl/ for GPL licensing * information. * * See http://www.pixil.org/license.html or * email cetsales@centurysoftware.com for information about the PIXIL * Commercial License Agreement, or if any conditions of this licensing * are not clear to you. *//* Feature test switches *//* System header files */#include <errno.h>#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>/* Local header files */#include <h3600_ts.h>#include <pixlib/pixlib.h>/* Typedef, macros, enum/struct/union defintions */#define CAL_GETX(f,p) (((f) == 0) ? ((p).x) : ((p).y))#define CAL_GETY(f,p) (((f) == 0) ? ((p).y) : ((p).x))#define CAL_FLAGS_EHAND 0x01 /* Exit handler has been registered */#define CAL_FLAGS_DEVOPEN 0X02 /* Device file has been opened */#define CAL_DFLT_DEVNAME "/dev/h3600_tsraw" /* Default FQPN of the device file */#define CAL_MAX_SAMPLE 5#define CAL_NUM_CTRLPTS 5#define CAL_OFFVAL1 30#define CAL_OFFVAL2 50/* Global scope variables *//* Local scope variables */static char *devname; /* Device name */static unsigned char cal_flags = 0; /* Global flags variable */static int devfd = -1, /* Device file descriptor */ rotated = 1, /* Default to the color ipaq */ screen_h, /* Screen height */ screen_w; /* Screen width *//* Static function prototypes */static void cal_ExitHandler(void);static int cal_OpenDev();/*-----------------------------------------------------------------------------*\---- Static function definitions--\*-----------------------------------------------------------------------------*//*******************************************************************************\**** Function: void cal_ExitHandler()** Desc: Exit handler for this module, responsible for closing the** file descriptor** Accepts: Nothing (void)** Returns: Nothing (void)**\*******************************************************************************/static voidcal_ExitHandler(void){ /* Close the open file descriptor for the device */ if ((cal_flags & CAL_FLAGS_DEVOPEN) && devfd > -1) close(devfd); return;} /* end of cal_ExitHandler() *//*******************************************************************************\**** Function: int cal_OpenDev()** Desc: Opens the device file and sets up the appropriate global flags** to handle clean up.** Accepts: Nothing (void)** Returns: int; >= 0 the fd, or -1 on error**\*******************************************************************************/static intcal_OpenDev(void){ int fd = -1; /* File descriptor to pass back */ /* Check the environment variable to see if we are overriding the default device file */ if ((devname = getenv("CAL_DEVICE")) == NULL) devname = CAL_DFLT_DEVNAME; if ((fd = open(devname, O_RDONLY)) != -1) { cal_flags |= CAL_FLAGS_DEVOPEN; if (!(cal_flags & CAL_FLAGS_EHAND)) { if (atexit(cal_ExitHandler) == 0) cal_flags |= CAL_FLAGS_EHAND; } /* end of if */ } /* end of if */ return (fd);} /* end of cal_OpenDev() *//*-----------------------------------------------------------------------------*\---- External function definitions--\*-----------------------------------------------------------------------------*//*******************************************************************************\**** Function: int pix_cal_GetCtrlPts()** Desc: Gets the calibration control points for this device** Accepts: int *npts = Ptr to storage for number of poitns** CalPt_t **ctrldata = Ptr to Ptr of address to dynamically allocate** memory** int w = screen width** int h = screen height** int bpp = Bits per pixel** Returns: int; 0 on success -1 on error**\*******************************************************************************/intpix_cal_GetCtrlPts(int *npts, CalPt_t ** ctrldata, int w, int h, int bpp){ /* Assign the memory */ if (ctrldata == NULL) return (-1); /* We are allocating CAL_NUM_CTRLPTS */ if ((*ctrldata = (CalPt_t *) calloc(CAL_NUM_CTRLPTS, sizeof(CalPt_t))) == NULL) return (-1); if (npts) *npts = CAL_NUM_CTRLPTS; /* Determine the rotation */ /* ** NOTE: This is a big time hack...Apparently the B/W ipaqs are rotated 180 degrees ** from their color counterparts... */ if (bpp == 4) rotated = 2; if (rotated) { screen_w = h; screen_h = w; } /* end of if */ else { screen_w = w; screen_h = h; } /* end of else */ (*ctrldata)[0].x = CAL_OFFVAL1; (*ctrldata)[0].y = CAL_OFFVAL1; (*ctrldata)[1].x = screen_w - CAL_OFFVAL2 - 1; (*ctrldata)[1].y = CAL_OFFVAL2; (*ctrldata)[2].x = CAL_OFFVAL2; (*ctrldata)[2].y = screen_h - CAL_OFFVAL2 - 1; (*ctrldata)[3].x = screen_w - CAL_OFFVAL1 - 1; (*ctrldata)[3].y = screen_h - CAL_OFFVAL1 - 1; (*ctrldata)[4].x = screen_w / 2; (*ctrldata)[4].y = screen_h / 2; return (0);} /* end of pix_cal_GetCtrlPts() *//*******************************************************************************\**** Function: int pix_cal_GetDrawpt()** Desc: Gets the draw points (based on any rotation that is necessary)** Accepts: CalPt_t *ctrlpt = Ptr to the Control point** CalPt_t *drawpt = Ptr to the storage for draw point** Returns: int; 0 on success, -1 on error**\*******************************************************************************/intpix_cal_GetDrawPt(CalPt_t * ctrlpt, CalPt_t * drawpt){ if (ctrlpt == NULL || drawpt == NULL) return (-1); if (rotated == 1) { /* This is the color ipaq */ drawpt->x = ctrlpt->y; drawpt->y = screen_w - ctrlpt->x; } /* end of if */ else if (rotated == 2) { /* This is the gray-scale ipaq */ drawpt->x = screen_h - ctrlpt->y; drawpt->y = screen_w - (screen_w - ctrlpt->x); } /* end of else if */ else { /* No rotation necessary */ drawpt->x = ctrlpt->x; drawpt->y = ctrlpt->y; } /* end of else */ return (0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -