?? image.c
字號:
/*############################################################################# * 文件名:image.c * 功能: 實現了指紋圖像的基本操作 * modified by PRTsinghua@hotmail.com#############################################################################*/#include <stdlib.h>#include <stdio.h>#include <string.h>#include "image.h"/* 指紋圖像結構。256級灰度圖 */typedef struct iFvsImage_t{ FvsByte_t *pimg; /* 8-bit圖像數組 */ FvsInt_t w; /* 寬度 */ FvsInt_t h; /* 高度 */ FvsInt_t pitch; /* 傾斜度 */ FvsImageFlag_t flags; /* 標記 */} iFvsImage_t;/****************************************************************************** * 功能:創建一個新的圖像對象 * 參數:無 * 返回:失敗返回空,否則返回新的圖像對象******************************************************************************/FvsImage_t ImageCreate(){ iFvsImage_t* p = NULL; p = (FvsImage_t)malloc(sizeof(iFvsImage_t)); if (p!=NULL) { p->h = 0; p->w = 0; p->pitch = 0; p->pimg = NULL; p->flags = FvsImageGray; /* 缺省的標記 */ } return (FvsImage_t)p;}/****************************************************************************** * 功能:銷毀一個圖像對象 * 參數:image 指向圖像對象的指針 * 返回:無******************************************************************************/void ImageDestroy(FvsImage_t image){ iFvsImage_t* p = NULL; if (image==NULL) return; (void)ImageSetSize(image, 0, 0); p = image; free(p);}/****************************************************************************** * 功能:設置圖像標記,該操作大部分由庫函數自動完成 * 參數:image 指向圖像對象的指針 * flag 標記 * 返回:錯誤編號******************************************************************************/FvsError_t ImageSetFlag(FvsImage_t img, const FvsImageFlag_t flag){ iFvsImage_t* image = (iFvsImage_t*)img; image->flags = flag; return FvsOK;}/****************************************************************************** * 功能:獲得圖像標記 * 參數:image 指向圖像對象的指針 * 返回:圖像標記******************************************************************************/FvsImageFlag_t ImageGetFlag(const FvsImage_t img){ iFvsImage_t* image = (iFvsImage_t*)img; return image->flags; }/****************************************************************************** * 功能:設置一個圖像對象的大小 * 參數:image 指向圖像對象的指針 * width 圖像寬度 * height 圖像高度 * 返回:錯誤編號******************************************************************************/FvsError_t ImageSetSize(FvsImage_t img, const FvsInt_t width, const FvsInt_t height){ iFvsImage_t* image = (iFvsImage_t*)img; FvsError_t nRet = FvsOK; FvsInt_t newsize = width*height; /* size為0的情況 */ if (newsize==0) { if (image->pimg!=NULL) { free(image->pimg); image->pimg = NULL; image->w = 0; image->h = 0; image->pitch = 0; } return FvsOK; } if (image->h*image->w != newsize) { free(image->pimg); image->w = 0; image->h = 0; image->pitch = 0; /* 申請內存 */ image->pimg = (uint8_t*)malloc((size_t)newsize); } if (image->pimg == NULL) nRet = FvsMemory; else { image->h = height; image->w = width; image->pitch = width; } return nRet;}/****************************************************************************** * 功能:拷貝圖像 * 參數:destination 指向目標圖像對象的指針 * source 指向源圖像對象的指針 * 返回:錯誤編號******************************************************************************/FvsError_t ImageCopy(FvsImage_t destination, const FvsImage_t source){ iFvsImage_t* dest = (iFvsImage_t*)destination; iFvsImage_t* src = (iFvsImage_t*)source; FvsError_t nRet = FvsOK; nRet = ImageSetSize(dest, src->w, src->h); if (nRet==FvsOK) memcpy(dest->pimg, src->pimg, (size_t)src->h*src->w); /* 拷貝標記 */ dest->flags = src->flags; return nRet;}/****************************************************************************** * 功能:清空圖像 * 參數:image 指向圖像對象的指針 * 返回:錯誤編號******************************************************************************/FvsError_t ImageClear(FvsImage_t img){ return ImageFlood(img, 0);}/****************************************************************************** * 功能:設置圖像中所有象素為特定值 * 參數:image 指向圖像對象的指針 * value 要設定的值 * 返回:錯誤編號******************************************************************************/FvsError_t ImageFlood(FvsImage_t img, const FvsByte_t value){ FvsError_t nRet = FvsOK; iFvsImage_t* image = (iFvsImage_t*)img; if (image==NULL) return FvsMemory; if (image->pimg!=NULL) memset(image->pimg, (int)value, (size_t)(image->h*image->w)); return nRet;}/****************************************************************************** * 功能:設置圖像中某個象素的值 * 參數:image 指向圖像對象的指針 * x X軸坐標 * y Y軸坐標 * val 要設定的值 * 返回:無******************************************************************************/void ImageSetPixel(FvsImage_t img, const FvsInt_t x, const FvsInt_t y, const FvsByte_t val){ iFvsImage_t* image = (iFvsImage_t*)img; int address = y * image->w + x; image->pimg[address] = val;}/****************************************************************************** * 功能:獲得圖像中某個象素的值 * 參數:image 指向圖像對象的指針 * x X軸坐標 * y Y軸坐標 * 返回:象素的值******************************************************************************/FvsByte_t ImageGetPixel(const FvsImage_t img, const FvsInt_t x, const FvsInt_t y){ iFvsImage_t* image = (iFvsImage_t*)img; /* 數組中的位置 */ int address = y * image->pitch + x; return image->pimg[address];}/****************************************************************************** * 功能:獲得圖像緩沖區指針 * 參數:image 指向圖像對象的指針 * 返回:指向圖像內存緩沖區的指針******************************************************************************/FvsByte_t* ImageGetBuffer(FvsImage_t img){ iFvsImage_t* image = (iFvsImage_t*)img; if (image==NULL) return NULL; return image->pimg;}/****************************************************************************** * 功能:獲得圖像寬度 * 參數:image 指向圖像對象的指針 * 返回:圖像寬度******************************************************************************/FvsInt_t ImageGetWidth(const FvsImage_t img){ iFvsImage_t* image = (iFvsImage_t*)img; if (image==NULL) return -1; return image->w;}/****************************************************************************** * 功能:獲得圖像高度 * 參數:image 指向圖像對象的指針 * 返回:圖像高度******************************************************************************/FvsInt_t ImageGetHeight(const FvsImage_t img){ iFvsImage_t* image = (iFvsImage_t*)img; if (image==NULL) return -1; return image->h;}/****************************************************************************** * 功能:獲得圖像緩沖區的大小 * 參數:image 指向圖像對象的指針 * 返回:緩沖區大小******************************************************************************/FvsInt_t ImageGetSize(const FvsImage_t img){ iFvsImage_t* image = (iFvsImage_t*)img; if (image==NULL) return 0; return image->h * image->w;}/****************************************************************************** * 功能:獲得圖像傾斜度 * 參數:image 指向圖像對象的指針 * 返回:傾斜度******************************************************************************/FvsInt_t ImageGetPitch(const FvsImage_t img){ iFvsImage_t* image = (iFvsImage_t*)img; if (image==NULL) return -1; return image->pitch;}/****************************************************************************** * 功能:比較兩個圖像大小 * 參數:image1 指向圖像對象1的指針 * image2 指向圖像對象2的指針 * 返回:若兩個圖像大小相等,返回true;否則返回false******************************************************************************/FvsBool_t ImageCompareSize(const FvsImage_t image1, const FvsImage_t image2){ if (ImageGetWidth(image1)!=ImageGetWidth(image2)) return FvsFalse; if (ImageGetHeight(image1)!=ImageGetHeight(image2)) return FvsFalse; return FvsTrue;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -