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

📄 callback.c

📁 data matrix 编码过程分析采用reed-solomn算法的应用
💻 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: mblaughton@users.sourceforge.net*//* $Id: callback.c,v 1.9 2006/10/13 01:54:35 mblaughton Exp $ */#include <stdlib.h>#include "gltest.h"#include "callback.h"#include "display.h"#include "image.h"#include "dmtx.h"/** * * */void StepScanCallback(DmtxDecode *info, DmtxScanRange *range, DmtxJumpScan *scan){   int i;   float frac;   float scale;   DmtxColor3 color;   DmtxPixel pxl;   if(scan->region.jumpCount > DMTX_MIN_JUMP_COUNT &&         abs(scan->region.anchor2 - scan->region.anchor1) > DMTX_MIN_STEP_RANGE) {      for(i = scan->region.anchor1; i < scan->region.anchor2; i++) {         frac = (float)(i - scan->region.anchor1)/(float)(scan->region.anchor2 - scan->region.anchor1);         scale = frac * (scan->region.gradient.tMax - scan->region.gradient.tMin) + scan->region.gradient.tMin;         color = dmtxColor3AlongRay3(&(scan->region.gradient.ray), scale);         dmtxPixelFromColor3(&pxl, &color);         if(range->dir & DmtxDirHorizontal)            passOneImage.pxl[range->lineNbr * info->image.width + i] = pxl;         else            passOneImage.pxl[i * info->image.width + range->lineNbr] = pxl;      }   }}/** * * */void CrossScanCallback(DmtxScanRange *range, DmtxGradient *gradient, DmtxEdgeScan *scan){   if(range->dir & DmtxDirHorizontal)      plotPoint(&passOneImage, range->lineNbr, scan->edge.offset + scan->subPixelOffset, ColorWhite);   else      plotPoint(&passOneImage, scan->edge.offset + scan->subPixelOffset, range->lineNbr, ColorWhite);}/** * * */void FollowScanCallback(DmtxEdgeFollower *follower){   int color;   switch(follower->dir) {      case DmtxDirUp:         color = ColorRed;         break;      case DmtxDirDown:         color = ColorGreen;         break;      case DmtxDirLeft:         color = ColorBlue;         break;      case DmtxDirRight:         color = ColorYellow;         break;      default:         color = ColorWhite;         break;   }   if(follower->dir & DmtxDirVertical)      plotPoint(&passOneImage, follower->paraOffset, follower->perpOffset, color);   else      plotPoint(&passOneImage, follower->perpOffset, follower->paraOffset, color);}/** * * */void FinderBarCallback(DmtxRay2 *ray){   DmtxVector2 p0, p1, pTmp;   if(ray->isDefined == 0)      return;   dmtxVector2Add(&p0, &(ray->p), dmtxVector2Scale(&pTmp, &(ray->v), ray->tMin));   dmtxVector2Add(&p1, &(ray->p), dmtxVector2Scale(&pTmp, &(ray->v), ray->tMax));   glViewport(646, 324, 320, 320);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   glOrtho(-0.5, 319.5, -0.5, 319.5, -1.0, 10.0);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   glDisable(GL_TEXTURE_2D);   glPolygonMode(GL_FRONT, GL_LINE);   glColor3f(1.0, 1.0, 1.0);   glBegin(GL_LINES);   glVertex2f(p0.X, p0.Y);   glVertex2f(p1.X, p1.Y);   glEnd();}/** * * */void BuildMatrixCallback2(DmtxFinderBar *bar, DmtxMatrixRegion *matrixRegion){   int i, j;   int xInt, yInt;   float xFrac, yFrac;   float scale = 100.0/200.0;   DmtxColor3 clr, clrLL, clrLR, clrUL, clrUR;   DmtxVector2 point;   DmtxMatrix3 m0, m1, mInv;   dmtxMatrix3Translate(m0, -(320 - 200)/2.0, -(320 - 200)/2.0);   dmtxMatrix3Scale(m1, scale, scale);   dmtxMatrix3Multiply(mInv, m0, m1);   dmtxMatrix3MultiplyBy(mInv, matrixRegion->fit2raw);   glDisable(GL_TEXTURE_2D);   glPolygonMode(GL_FRONT, GL_LINE);   for(i = 0; i < 320; i++) {      for(j = 0; j < 320; j++) {         point.X = j;         point.Y = i;         dmtxMatrix3VMultiplyBy(&point, mInv);// XXX this is the exact same thing as dmtxColorFromImage2()         xInt = (int)point.X;         yInt = (int)point.Y;         xFrac = point.X - xInt;         yFrac = point.Y - yInt;         dmtxColor3FromImage(&clrLL, captured, xInt,   yInt);         dmtxColor3FromImage(&clrLR, captured, xInt+1, yInt);         dmtxColor3FromImage(&clrUL, captured, xInt,   yInt+1);         dmtxColor3FromImage(&clrUR, captured, xInt+1, yInt+1);         dmtxColor3ScaleBy(&clrLL, (1 - xFrac) * (1 - yFrac));         dmtxColor3ScaleBy(&clrLR, xFrac * (1 - yFrac));         dmtxColor3ScaleBy(&clrUL, (1 - xFrac) * yFrac);         dmtxColor3ScaleBy(&clrUR, xFrac * yFrac);         clr = clrLL;         dmtxColor3AddTo(&clr, &clrLR);         dmtxColor3AddTo(&clr, &clrUL);         dmtxColor3AddTo(&clr, &clrUR);         dmtxPixelFromColor3(&(passTwoImage.pxl[i*320+j]), &clr);      }   }   DrawPane3(NULL, &passTwoImage);   glViewport(646, 324, 320, 320);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   glOrtho(-0.5, 319.5, -0.5, 319.5, -1.0, 10.0);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   glColor3f(0.0, 1.0, 0.0);   glBegin(GL_QUADS);   glVertex2f( 60.0,  60.0);   glVertex2f(260.0,  60.0);   glVertex2f(260.0, 260.0);   glVertex2f( 60.0, 260.0);   glEnd();}/** * * */void BuildMatrixCallback3(DmtxMatrix3 mChainInv){   int i, j;   int xInt, yInt;   float xFrac, yFrac;   float scale = 100.0/200.0;   DmtxColor3 clr, clrLL, clrLR, clrUL, clrUR;   DmtxVector2 point;   DmtxMatrix3 m0, m1, mInv;   dmtxMatrix3Scale(m0, scale, scale);   dmtxMatrix3Translate(m1, -(320 - 200)/2.0, -(320 - 200)/2.0);   dmtxMatrix3Multiply(mInv, m1, m0);   dmtxMatrix3MultiplyBy(mInv, mChainInv);   glDisable(GL_TEXTURE_2D);   glPolygonMode(GL_FRONT, GL_LINE);   for(i = 0; i < 320; i++) {      for(j = 0; j < 320; j++) {         point.X = j;         point.Y = i;         dmtxMatrix3VMultiplyBy(&point, mInv);         xInt = (int)point.X;         yInt = (int)point.Y;         xFrac = point.X - xInt;         yFrac = point.Y - yInt;         dmtxColor3FromImage(&clrLL, captured, xInt,   yInt);         dmtxColor3FromImage(&clrLR, captured, xInt+1, yInt);         dmtxColor3FromImage(&clrUL, captured, xInt,   yInt+1);         dmtxColor3FromImage(&clrUR, captured, xInt+1, yInt+1);         dmtxColor3ScaleBy(&clrLL, (1 - xFrac) * (1 - yFrac));         dmtxColor3ScaleBy(&clrLR, xFrac * (1 - yFrac));         dmtxColor3ScaleBy(&clrUL, (1 - xFrac) * yFrac);         dmtxColor3ScaleBy(&clrUR, xFrac * yFrac);         clr = clrLL;         dmtxColor3AddTo(&clr, &clrLR);         dmtxColor3AddTo(&clr, &clrUL);         dmtxColor3AddTo(&clr, &clrUR);         dmtxPixelFromColor3(&(passTwoImage.pxl[i*320+j]), &clr);      }   }   DrawPane4(NULL, &passTwoImage);   glViewport(2, 2, 320, 320);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   glOrtho(-0.5, 319.5, -0.5, 319.5, -1.0, 10.0);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   glColor3f(0.0, 1.0, 0.0);   glBegin(GL_QUADS);   glVertex2f( 60.0,  60.0);   glVertex2f(260.0,  60.0);   glVertex2f(260.0, 260.0);   glVertex2f( 60.0, 260.0);   glEnd();}/** * * */void BuildMatrixCallback4(DmtxMatrix3 mChainInv){   int i, j;   int xInt, yInt;   float xFrac, yFrac;   float scale = 100.0/200.0;   DmtxColor3 clr, clrLL, clrLR, clrUL, clrUR;   DmtxVector2 point;   DmtxMatrix3 m0, m1, mInv;   dmtxMatrix3Scale(m0, scale, scale);   dmtxMatrix3Translate(m1, -(320 - 200)/2.0, -(320 - 200)/2.0);   dmtxMatrix3Multiply(mInv, m1, m0);   dmtxMatrix3MultiplyBy(mInv, mChainInv);   glDisable(GL_TEXTURE_2D);   glPolygonMode(GL_FRONT, GL_LINE);   for(i = 0; i < 320; i++) {      for(j = 0; j < 320; j++) {         point.X = j;         point.Y = i;         dmtxMatrix3VMultiplyBy(&point, mInv);         xInt = (int)point.X;         yInt = (int)point.Y;         xFrac = point.X - xInt;         yFrac = point.Y - yInt;         dmtxColor3FromImage(&clrLL, captured, xInt,   yInt);         dmtxColor3FromImage(&clrLR, captured, xInt+1, yInt);         dmtxColor3FromImage(&clrUL, captured, xInt,   yInt+1);         dmtxColor3FromImage(&clrUR, captured, xInt+1, yInt+1);         dmtxColor3ScaleBy(&clrLL, (1 - xFrac) * (1 - yFrac));         dmtxColor3ScaleBy(&clrLR, xFrac * (1 - yFrac));         dmtxColor3ScaleBy(&clrUL, (1 - xFrac) * yFrac);         dmtxColor3ScaleBy(&clrUR, xFrac * yFrac);         clr = clrLL;         dmtxColor3AddTo(&clr, &clrLR);         dmtxColor3AddTo(&clr, &clrUL);         dmtxColor3AddTo(&clr, &clrUR);         dmtxPixelFromColor3(&(passTwoImage.pxl[i*320+j]), &clr);      }   }   DrawPane5(NULL, &passTwoImage);   glViewport(324, 2, 320, 320);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   glOrtho(-0.5, 319.5, -0.5, 319.5, -1.0, 10.0);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   glColor3f(0.0, 1.0, 0.0);   glBegin(GL_QUADS);   glVertex2f( 60.0,  60.0);   glVertex2f(260.0,  60.0);   glVertex2f(260.0, 260.0);   glVertex2f( 60.0, 260.0);   glEnd();}/** * * */void PlotPointCallback(DmtxVector2 point, int colorInt, int paneNbr, int dispType){   int color;   DmtxImage *image = NULL;   switch(paneNbr) {      case 1:         glViewport(2, 324, 320, 320);         break;      case 2:         glViewport(324, 324, 320, 320);         image = &passOneImage;         break;      case 3:         glViewport(646, 324, 320, 320);         break;      case 4:         glViewport(2, 2, 320, 320);         break;      case 5:         glViewport(324, 2, 320, 320);         break;      case 6:         glViewport(646, 2, 320, 320);         break;   }   if(image != NULL) {      switch(colorInt) {         case 1:            color = ColorRed;            break;         case 2:            color = ColorGreen;            break;         case 3:            color = ColorBlue;            break;         case 4:            color = ColorYellow;            break;         default:            color = ColorWhite;            break;      }      plotPoint(image, point.Y, point.X, color);      plotPoint(image, point.Y + 1, point.X - 1, color);      plotPoint(image, point.Y + 1, point.X + 1, color);      plotPoint(image, point.Y - 1, point.X - 1, color);      plotPoint(image, point.Y - 1, point.X + 1, color);   }   else {      glMatrixMode(GL_PROJECTION);      glLoadIdentity();      glOrtho(-0.5, 319.5, -0.5, 319.5, -1.0, 10.0);      glMatrixMode(GL_MODELVIEW);      glLoadIdentity();      glDisable(GL_TEXTURE_2D);      glPolygonMode(GL_FRONT, GL_LINE);      glColor3f(0.0, 0.0, 1.0);      if(dispType == DMTX_DISPLAY_SQUARE) {         glBegin(GL_QUADS);         glVertex2f(point.X - 3, point.Y - 3);         glVertex2f(point.X + 3, point.Y - 3);         glVertex2f(point.X + 3, point.Y + 3);         glVertex2f(point.X - 3, point.Y + 3);         glEnd();      }      else if(dispType == DMTX_DISPLAY_POINT) {         int x = (int)(point.X + 0.5);         int y = (int)(point.Y + 0.5);         glBegin(GL_POINTS);         glVertex2f(x, y);         glEnd();      }   }}/** * * */void XfrmPlotPointCallback(DmtxVector2 point, DmtxMatrix3 xfrm, int paneNbr, int dispType){   float scale = 200.0/100.0;   DmtxMatrix3 m, m0, m1;   if(xfrm != NULL) {      dmtxMatrix3Copy(m, xfrm);   }   else {      dmtxMatrix3Identity(m);   }   dmtxMatrix3Scale(m0, scale, scale);   dmtxMatrix3Translate(m1, (320 - 200)/2.0, (320 - 200)/2.0);   dmtxMatrix3MultiplyBy(m, m0);   dmtxMatrix3MultiplyBy(m, m1);   dmtxMatrix3VMultiplyBy(&point, m);   PlotPointCallback(point, 1, paneNbr, dispType);}/** * * */void FinalCallback(DmtxMatrixRegion *matrixRegion){   int i, j;   int xInt, yInt;   float xFrac, yFrac;   float scale = 100.0/200.0;   DmtxColor3 clr, clrLL, clrLR, clrUL, clrUR;   DmtxVector2 point;   DmtxMatrix3 m0, m1, mInv;   dmtxMatrix3Scale(m0, scale, scale);   dmtxMatrix3Translate(m1, -(320 - 200)/2.0, -(320 - 200)/2.0);   dmtxMatrix3Multiply(mInv, m1, m0);   dmtxMatrix3MultiplyBy(mInv, matrixRegion->fit2raw);   glDisable(GL_TEXTURE_2D);   glPolygonMode(GL_FRONT, GL_LINE);   for(i = 0; i < 320; i++) {      for(j = 0; j < 320; j++) {         point.X = j;         point.Y = i;         dmtxMatrix3VMultiplyBy(&point, mInv);         xInt = (int)point.X;         yInt = (int)point.Y;         xFrac = point.X - xInt;         yFrac = point.Y - yInt;         dmtxColor3FromImage(&clrLL, captured, xInt,   yInt);         dmtxColor3FromImage(&clrLR, captured, xInt+1, yInt);         dmtxColor3FromImage(&clrUL, captured, xInt,   yInt+1);         dmtxColor3FromImage(&clrUR, captured, xInt+1, yInt+1);         dmtxColor3ScaleBy(&clrLL, (1 - xFrac) * (1 - yFrac));         dmtxColor3ScaleBy(&clrLR, xFrac * (1 - yFrac));         dmtxColor3ScaleBy(&clrUL, (1 - xFrac) * yFrac);         dmtxColor3ScaleBy(&clrUR, xFrac * yFrac);         clr = clrLL;         dmtxColor3AddTo(&clr, &clrLR);         dmtxColor3AddTo(&clr, &clrUL);         dmtxColor3AddTo(&clr, &clrUR);         dmtxPixelFromColor3(&(passTwoImage.pxl[i*320+j]), &clr);      }   }   DrawPane5(NULL, &passTwoImage);   glViewport(324, 2, 320, 320);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   glOrtho(-0.5, 319.5, -0.5, 319.5, -1.0, 10.0);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   glColor3f(0.0, 1.0, 0.0);   glBegin(GL_QUADS);   glVertex2f( 60.0,  60.0);   glVertex2f(260.0,  60.0);   glVertex2f(260.0, 260.0);   glVertex2f( 60.0, 260.0);   glEnd();}/** * * */void PlotModuleCallback(DmtxDecode *info, DmtxMatrixRegion *matrixRegion, int row, int col, DmtxColor3 color){   int modSize, halfModsize, padSize;// float t;   // Adjust for addition of finder bar   row++;   col++;   halfModsize = (int)(100.0 / (matrixRegion->dataCols + 2) + 0.5); // Because 100 == 200/2   modSize = 2 * halfModsize;   padSize = (320 - ((matrixRegion->dataCols + 2) * modSize))/2;   // Set for 6th pane   DrawPaneBorder(645, 1, 322, 322);   glRasterPos2i(1, 1);   glPolygonMode(GL_FRONT, GL_FILL);   // Clamp color to extreme foreground or background color// t = dmtxDistanceAlongRay3(&(matrixRegion->gradient.ray), &color);// t = (t < matrixRegion->gradient.tMid) ? matrixRegion->gradient.tMin : matrixRegion->gradient.tMax;// dmtxPointAlongRay3(&color, &(matrixRegion->gradient.ray), t);   glColor3f(color.R/255, color.G/255, color.B/255);   glBegin(GL_QUADS);   glVertex2f(modSize*(col+0.5) + padSize - halfModsize, modSize*(row+0.5) + padSize - halfModsize);   glVertex2f(modSize*(col+0.5) + padSize + halfModsize, modSize*(row+0.5) + padSize - halfModsize);   glVertex2f(modSize*(col+0.5) + padSize + halfModsize, modSize*(row+0.5) + padSize + halfModsize);   glVertex2f(modSize*(col+0.5) + padSize - halfModsize, modSize*(row+0.5) + padSize + halfModsize);   glEnd();}

⌨️ 快捷键说明

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