/* * qrencode - QR Code encoder * * Masking for Micro QR Code. * Copyright (C) 2006-2011 Kentaro Fukuchi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #if HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include "qrencode.h" #include "mqrspec.h" #include "mmask.h" __STATIC void MMask_writeFormatInformation(int version, int width, unsigned char *frame, int mask, QRecLevel level) { unsigned int format; unsigned char v; int i; format = MQRspec_getFormatInfo(mask, version, level); for(i=0; i<8; i++) { v = 0x84 | (format & 1); frame[width * (i + 1) + 8] = v; format = format >> 1; } for(i=0; i<7; i++) { v = 0x84 | (format & 1); frame[width * 8 + 7 - i] = v; format = format >> 1; } } #define MASKMAKER(__exp__) \ int x, y;\ \ for(y=0; y= maskNum) { errno = EINVAL; return NULL; } width = MQRspec_getWidth(version); masked = (unsigned char *)malloc(width * width); if(masked == NULL) return NULL; maskMakers[mask](width, frame, masked); MMask_writeFormatInformation(version, width, masked, mask, level); return masked; } __STATIC int MMask_evaluateSymbol(int width, unsigned char *frame) { int x, y; unsigned char *p; int sum1 = 0, sum2 = 0; p = frame + width * (width - 1); for(x=1; x maxScore) { maxScore = score; free(bestMask); bestMask = mask; mask = (unsigned char *)malloc(width * width); if(mask == NULL) break; } } free(mask); return bestMask; }