1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/**
* libdmtx - Data Matrix Encoding/Decoding Library
* Copyright 2010 Mike Laughton. All rights reserved.
*
* See LICENSE file in the main project directory for full
* terms of use and distribution.
*
* Contact: Mike Laughton <mike@dragonflylogic.com>
*
* \file dmtxaccel.c
*/
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <assert.h>
#include "../../dmtx.h"
#include "multi_test.h"
/**
*
*
*/
DmtxAccel *
AccelCreate(DmtxSobel *sobel)
{
int sWidth, sHeight;
int vWidth, vHeight;
int hWidth, hHeight;
DmtxAccel *accel;
accel = (DmtxAccel *)calloc(1, sizeof(DmtxAccel));
if(accel == NULL)
return NULL;
sWidth = dmtxValueGridGetWidth(sobel->v);
sHeight = dmtxValueGridGetHeight(sobel->v);
vWidth = sWidth - 1;
vHeight = sHeight;
hWidth = sWidth;
hHeight = sHeight - 1;
accel->vv = dmtxValueGridCreate(vWidth, vHeight, DmtxEdgeVertical, sobel->v);
accel->vb = dmtxValueGridCreate(vWidth, vHeight, DmtxEdgeVertical, sobel->b);
accel->vs = dmtxValueGridCreate(vWidth, vHeight, DmtxEdgeVertical, sobel->s);
accel->hb = dmtxValueGridCreate(hWidth, hHeight, DmtxEdgeHorizontal, sobel->b);
accel->hh = dmtxValueGridCreate(hWidth, hHeight, DmtxEdgeHorizontal, sobel->h);
accel->hs = dmtxValueGridCreate(hWidth, hHeight, DmtxEdgeHorizontal, sobel->s);
if(accel->vv == NULL || accel->vb == NULL || accel->vs == NULL ||
accel->hb == NULL || accel->hh == NULL || accel->hs == NULL)
{
AccelDestroy(&accel);
return NULL;
}
return accel;
}
/**
*
*
*/
DmtxPassFail
AccelDestroy(DmtxAccel **accel)
{
if(accel == NULL || *accel == NULL)
return DmtxFail;
dmtxValueGridDestroy(&((*accel)->vs));
dmtxValueGridDestroy(&((*accel)->hs));
dmtxValueGridDestroy(&((*accel)->hh));
dmtxValueGridDestroy(&((*accel)->hb));
dmtxValueGridDestroy(&((*accel)->vb));
dmtxValueGridDestroy(&((*accel)->vv));
free(*accel);
*accel = NULL;
return DmtxPass;
}
#define RETURN_FAIL_IF(c) if(c) { return DmtxFail; }
/**
*
*
*/
DmtxPassFail
AccelPopulate(DmtxDecode2 *dec)
{
DmtxAccel *accel;
assert(dec != NULL && dec->accel != NULL);
accel = dec->accel;
RETURN_FAIL_IF(AccelPopulateLocal(accel->vv) == DmtxFail);
RETURN_FAIL_IF(AccelPopulateLocal(accel->vb) == DmtxFail);
RETURN_FAIL_IF(AccelPopulateLocal(accel->hb) == DmtxFail);
RETURN_FAIL_IF(AccelPopulateLocal(accel->hh) == DmtxFail);
RETURN_FAIL_IF(AccelPopulateLocal(accel->hs) == DmtxFail);
RETURN_FAIL_IF(AccelPopulateLocal(accel->vs) == DmtxFail);
dec->fn.dmtxValueGridCallback(accel->vv, 4);
dec->fn.dmtxValueGridCallback(accel->vb, 5);
dec->fn.dmtxValueGridCallback(accel->hb, 7);
dec->fn.dmtxValueGridCallback(accel->hh, 8);
dec->fn.dmtxValueGridCallback(accel->hs, 9);
dec->fn.dmtxValueGridCallback(accel->vs, 6);
return DmtxPass;
}
#undef RETURN_FAIL_IF
/**
*
*
*/
DmtxPassFail
AccelPopulateLocal(DmtxValueGrid *acc)
{
int sWidth, sHeight;
int aWidth, aHeight;
int sIdx, sIdxNext, sInc, aIdx;
int x, y;
DmtxValueGrid *sob;
sob = acc->ref;
sWidth = dmtxValueGridGetWidth(sob);
sHeight = dmtxValueGridGetHeight(sob);
switch(acc->type) {
case DmtxEdgeVertical:
aWidth = sWidth - 1;
aHeight = sHeight;
sInc = 1;
break;
case DmtxEdgeHorizontal:
aWidth = sWidth;
aHeight = sHeight - 1;
sInc = sWidth;
break;
default:
return DmtxFail;
}
for(y = 0; y < aHeight; y++)
{
sIdx = y * sWidth;
aIdx = y * aWidth;
for(x = 0; x < aWidth; x++)
{
sIdxNext = sIdx + sInc;
acc->value[aIdx] = sob->value[sIdxNext] - sob->value[sIdx];
aIdx++;
sIdx++;
}
}
return DmtxPass;
}
|