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

📄 dmtxwrite.c

📁 Datamatrix二维码库和测试程序,运行于linux,仔细研究可以很容易转化成VC程序,有这就没必要化钱买个控件了,本人libdmtx-0.3版本转化过,的确可行,现在把找到该版本的libdmtx
💻 C
📖 第 1 页 / 共 2 页
字号:
/*libdmtx - Data Matrix Encoding/Decoding LibraryCopyright (c) 2008 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: dmtxwrite.c 503 2008-11-07 18:37:35Z mblaughton $ */#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include <stdlib.h>#include <stdio.h>#include <string.h>#include <getopt.h>#include <errno.h>#include <ctype.h>#include <stdarg.h>#include <assert.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <png.h>#include <dmtx.h>#include "dmtxwrite.h"#include "../common/dmtxutil.h"char *programName;/** * @brief  Main function for the dmtxwrite Data Matrix scanning utility. * @param  argc count of arguments passed from command line * @param  argv list of argument passed strings from command line * @return Numeric exit code */intmain(int argc, char *argv[]){   int err;   UserOptions opt;   DmtxEncode enc;   unsigned char codeBuffer[DMTXWRITE_BUFFER_SIZE];   int codeBufferSize = sizeof codeBuffer;   InitUserOptions(&opt);   /* Create and initialize libdmtx structures */   enc = dmtxEncodeStructInit();   /* Process user options */   err = HandleArgs(&opt, &argc, &argv, &enc);   if(err != DMTX_SUCCESS)      ShowUsage(err);   /* Read input data into buffer */   ReadData(&opt, &codeBufferSize, codeBuffer);   /* Create barcode image */   if(opt.mosaic)      err = dmtxEncodeDataMosaic(&enc, codeBufferSize, codeBuffer, opt.sizeIdx);   else      err = dmtxEncodeDataMatrix(&enc, codeBufferSize, codeBuffer, opt.sizeIdx);   if(err == DMTX_FAILURE)      FatalError(1, _("Unable to encode message (possibly too large for requested size)"));   /* Write barcode image to requested format */   switch(opt.format) {      case 'p':         WriteImagePng(&opt, &enc);         break;      case 'm':         WriteImagePnm(&opt, &enc);         break;      case 'a':         WriteAsciiBarcode(&enc);         break;      case 'c':         WriteCodewords(&enc);         break;   }   /* Clean up */   dmtxEncodeStructDeInit(&enc);   exit(0);}/** * * */static voidInitUserOptions(UserOptions *opt){   memset(opt, 0x00, sizeof(UserOptions));/* opt->color = ""; *//* opt->bgColor = ""; */   opt->format = 'p';   opt->inputPath = NULL;    /* default stdin */   opt->outputPath = NULL;   /* default stdout */   opt->rotate = 0;   opt->sizeIdx = DmtxSymbolSquareAuto;   opt->verbose = 0;   opt->mosaic = 0;   opt->dpi = 0; /* default to native resolution of requested image format */}/** * @brief  Set and validate user-requested options from command line arguments. * @param  opt runtime options from defaults or command line * @param  argcp pointer to argument count * @param  argvp pointer to argument list * @return DMTX_SUCCESS | DMTX_FAILURE */static intHandleArgs(UserOptions *opt, int *argcp, char **argvp[], DmtxEncode *enc){   int err;   int i;   int optchr;   int longIndex;   char *ptr;   struct option longOptions[] = {         {"color",       required_argument, NULL, 'c'},         {"bg-color",    required_argument, NULL, 'b'},         {"module",      required_argument, NULL, 'd'},         {"margin",      required_argument, NULL, 'm'},         {"encoding",    required_argument, NULL, 'e'},         {"format",      required_argument, NULL, 'f'},         {"output",      required_argument, NULL, 'o'},         {"rotate",      required_argument, NULL, 'r'},         {"symbol-size", required_argument, NULL, 's'},         {"verbose",     no_argument,       NULL, 'v'},         {"mosaic",      no_argument,       NULL, 'M'},         {"resolution",  required_argument, NULL, 'R'},         {"version",     no_argument,       NULL, 'V'},         {"help",        no_argument,       NULL,  0 },         {0, 0, 0, 0}   };   programName = Basename((*argvp)[0]);   /* Set default values before considering arguments */   enc->moduleSize = 5;   enc->marginSize = 10;   enc->scheme = DmtxSchemeEncodeAscii;   for(;;) {      optchr = getopt_long(*argcp, *argvp, "c:b:d:m:e:f:o:r:s:vMR:V", longOptions, &longIndex);      if(optchr == -1)         break;      switch(optchr) {         case 0: /* --help */            ShowUsage(0);            break;         case 'c':            opt->color[0] = 0;            opt->color[1] = 0;            opt->color[2] = 0;            fprintf(stdout, "Option \"%c\" not implemented\n", optchr);            break;         case 'b':            opt->bgColor[0] = 255;            opt->bgColor[1] = 255;            opt->bgColor[2] = 255;            fprintf(stdout, "Option \"%c\" not implemented\n", optchr);            break;         case 'd':            err = StringToInt(&(enc->moduleSize), optarg, &ptr);            if(err != DMTX_SUCCESS || enc->moduleSize <= 0 || *ptr != '\0')               FatalError(1, _("Invalid module size specified \"%s\""), optarg);            break;         case 'm':            err = StringToInt(&(enc->marginSize), optarg, &ptr);            if(err != DMTX_SUCCESS || enc->marginSize <= 0 || *ptr != '\0')               FatalError(1, _("Invalid margin size specified \"%s\""), optarg);            break;         case 'e':            if(strlen(optarg) != 1) {               fprintf(stdout, "Invalid encodation scheme \"%s\"\n", optarg);               return DMTX_FAILURE;            }            switch(*optarg) {               case 'b':                  enc->scheme = DmtxSchemeEncodeAutoBest;                  break;               case 'f':                  enc->scheme = DmtxSchemeEncodeAutoFast;                  fprintf(stdout, "\"Fast optimized\" not implemented\n");                  return DMTX_FAILURE;                  break;               case 'a':                  enc->scheme = DmtxSchemeEncodeAscii;                  break;               case 'c':                  enc->scheme = DmtxSchemeEncodeC40;                  break;               case 't':                  enc->scheme = DmtxSchemeEncodeText;                  break;               case 'x':                  enc->scheme = DmtxSchemeEncodeX12;                  break;               case 'e':                  enc->scheme = DmtxSchemeEncodeEdifact;                  break;               case '8':                  enc->scheme = DmtxSchemeEncodeBase256;                  break;               default:                  fprintf(stdout, "Invalid encodation scheme \"%s\"\n", optarg);                  return DMTX_FAILURE;                  break;            }            break;         case 'f':            opt->format = *optarg;            if(opt->format != 'p' && opt->format != 'm' &&                  opt->format != 'a' && opt->format != 'c') {               fprintf(stdout, "Invalid output format \"%c\"\n", opt->format);               return DMTX_FAILURE;            }            break;         case 'o':            opt->outputPath = optarg;            break;         case 'r':            err = StringToInt(&(opt->rotate), optarg, &ptr);            if(err != DMTX_SUCCESS || *ptr != '\0')               FatalError(1, _("Invalid rotation angle specified \"%s\""), optarg);            break;         case 's':            /* Determine correct barcode size and/or shape */            if(*optarg == 's') {               opt->sizeIdx = DmtxSymbolSquareAuto;            }            else if(*optarg == 'r') {               opt->sizeIdx = DmtxSymbolRectAuto;            }            else {               for(i = 0; i < DMTX_SYMBOL_SQUARE_COUNT + DMTX_SYMBOL_RECT_COUNT; i++) {                  if(strncmp(optarg, symbolSizes[i], 8) == 0) {                     opt->sizeIdx = i;                     break;                  }               }               if(i == DMTX_SYMBOL_SQUARE_COUNT + DMTX_SYMBOL_RECT_COUNT)                  return DMTX_FAILURE;            }            break;         case 'v':            opt->verbose = 1;            break;         case 'M':            opt->mosaic = 1;            break;         case 'R':            err = StringToInt(&(opt->dpi), optarg, &ptr);            if(err != DMTX_SUCCESS || opt->dpi <= 0 || *ptr != '\0')               FatalError(1, _("Invalid dpi specified \"%s\""), optarg);            break;         case 'V':            fprintf(stdout, "%s version %s\n", programName, DMTX_VERSION);

⌨️ 快捷键说明

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