⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dmtxcolor3.c

📁 Linux系统下,二维码生成源代码.希望对大家有所帮助.
💻 C
字号:
/*libdmtx - Data Matrix Encoding/Decoding LibraryCopyright (C) 2006 Mike LaughtonThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USAContact: mike@dragonflylogic.com*//* $Id: dmtxcolor3.c,v 1.3 2006/10/12 18:04:27 mblaughton Exp $ *//** * * */extern voiddmtxColor3FromImage(DmtxColor3 *color, DmtxImage *image, int x, int y){   if(x >= 0 && x < image->width && y >= 0 && y < image->height) {      dmtxColor3FromPixel(color, &(image->pxl[y * image->width + x]));   }   else { // XXX this isn't right.  library shouldn't have color to aid graphical visualization      color->R =  0.0;      color->G =  0.0;      color->B = 30.0;   }}/** * * */extern voiddmtxColor3FromImage2(DmtxColor3 *color, DmtxImage *image, DmtxVector2 p){   int xInt, yInt;   float xFrac, yFrac;   DmtxColor3 clrLL, clrLR, clrUL, clrUR;   xInt = (int)p.X;   yInt = (int)p.Y;   xFrac = p.X - xInt;   yFrac = p.Y - yInt;   dmtxColor3FromImage(&clrLL, image, xInt,   yInt);   dmtxColor3FromImage(&clrLR, image, xInt+1, yInt);   dmtxColor3FromImage(&clrUL, image, xInt,   yInt+1);   dmtxColor3FromImage(&clrUR, image, xInt+1, yInt+1);   dmtxColor3ScaleBy(&clrLL, (1 - xFrac) * (1 - yFrac));   dmtxColor3ScaleBy(&clrLR, xFrac * (1 - yFrac));   dmtxColor3ScaleBy(&clrUL, (1 - xFrac) * yFrac);   dmtxColor3ScaleBy(&clrUR, xFrac * yFrac);   *color = clrLL;   dmtxColor3AddTo(color, &clrLR);   dmtxColor3AddTo(color, &clrUL);   dmtxColor3AddTo(color, &clrUR);}/** * * */extern voiddmtxColor3FromPixel(DmtxColor3 *color, DmtxPixel *pxl){   color->R = pxl->R;   color->G = pxl->G;   color->B = pxl->B;}/** * * */extern voiddmtxPixelFromColor3(DmtxPixel *pxl, DmtxColor3 *color){   pxl->R = (int)(color->R + 0.5);   pxl->G = (int)(color->G + 0.5);   pxl->B = (int)(color->B + 0.5);}/** * * */extern DmtxColor3dmtxColor3AlongRay3(DmtxRay3 *ray, float dist){   DmtxColor3 color;   DmtxColor3 cTmp;   color = ray->p;   dmtxColor3AddTo(&color, dmtxColor3Scale(&cTmp, &(ray->c), dist));   return(color);}/** * * */extern DmtxColor3 *dmtxColor3AddTo(DmtxColor3 *c1, DmtxColor3 *c2){   c1->R += c2->R;   c1->G += c2->G;   c1->B += c2->B;   return c1;}/** * * */extern DmtxColor3 *dmtxColor3Add(DmtxColor3 *cOut, DmtxColor3 *c1, DmtxColor3 *c2){   *cOut = *c1;   return dmtxColor3AddTo(cOut, c2);}/** * * */extern DmtxColor3 *dmtxColor3SubFrom(DmtxColor3 *c1, DmtxColor3 *c2){   c1->R -= c2->R;   c1->G -= c2->G;   c1->B -= c2->B;   return c1;}/** * * */extern DmtxColor3 *dmtxColor3Sub(DmtxColor3 *cOut, DmtxColor3 *c1, DmtxColor3 *c2){   *cOut = *c1;   return dmtxColor3SubFrom(cOut, c2);}/** * * */extern DmtxColor3 *dmtxColor3ScaleBy(DmtxColor3 *c, float s){   c->R *= s;   c->G *= s;   c->B *= s;   return c;}/** * * */extern DmtxColor3 *dmtxColor3Scale(DmtxColor3 *cOut, DmtxColor3 *c, float s){   *cOut = *c;   return dmtxColor3ScaleBy(cOut, s);}/** * * */extern DmtxColor3 *dmtxColor3Cross(DmtxColor3 *cOut, DmtxColor3 *c1, DmtxColor3 *c2){   cOut->R = c1->G * c2->B - c2->G * c1->B;   cOut->G = c2->R * c1->B - c1->R * c2->B;   cOut->B = c1->R * c2->G - c2->R * c1->G;   return cOut;}/** * * */extern floatdmtxColor3Norm(DmtxColor3 *c){   double mag;   mag = dmtxColor3Mag(c);   if(mag == 0)      ; // Div/0 Error   dmtxColor3ScaleBy(c, 1/mag);   return mag;}/** * * */extern floatdmtxColor3Dot(DmtxColor3 *c1, DmtxColor3 *c2){   // XXX double check that this is right   return (c1->R * c2->R) + (c1->G * c2->G) + (c1->B * c2->B);}/** * * */extern floatdmtxColor3Mag(DmtxColor3 *c){   return sqrt(c->R * c->R + c->G * c->G + c->B * c->B);}/** * * */extern floatdmtxDistanceFromRay3(DmtxRay3 *r, DmtxColor3 *q){   DmtxColor3 cSubTmp;   DmtxColor3 cCrossTmp;   // Assume that ray has a unit length of 1   assert(fabs(1.0 - dmtxColor3Mag(&(r->c))) < DMTX_ALMOST_ZERO);   return dmtxColor3Mag(dmtxColor3Cross(&cCrossTmp, &(r->c), dmtxColor3Sub(&cSubTmp, q, &(r->p))));}/** * * */extern floatdmtxDistanceAlongRay3(DmtxRay3 *r, DmtxColor3 *q){   DmtxColor3 cSubTmp;   // Assume that ray has a unit length of 1   assert(fabs(1.0 - dmtxColor3Mag(&(r->c))) < DMTX_ALMOST_ZERO);   return dmtxColor3Dot(dmtxColor3Sub(&cSubTmp, q, &(r->p)), &(r->c));}/** * * */extern intdmtxPointAlongRay3(DmtxColor3 *point, DmtxRay3 *r, float t){   DmtxColor3 cTmp;   // Assume that ray has a unit length of 1   assert(fabs(1.0 - dmtxColor3Mag(&(r->c))) < DMTX_ALMOST_ZERO);   dmtxColor3Scale(&cTmp, &(r->c), t);   dmtxColor3Add(point, &(r->p), &cTmp);   return DMTX_SUCCESS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -