File: dmtx_ext.cpp

package info (click to toggle)
falconpl 0.9.6.9-git20120606-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,176 kB
  • sloc: cpp: 181,389; ansic: 109,025; yacc: 2,310; xml: 1,218; sh: 403; objc: 245; makefile: 82; sql: 20
file content (136 lines) | stat: -rw-r--r-- 3,125 bytes parent folder | download | duplicates (2)
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
/*
 *  Falcon DataMatrix - Extension
 */

#include "dmtx_ext.h"
#include "dmtx_mod.h"
//#include "dmtx_srv.h"
//#include "dmtx_st.h"

#include <falcon/engine.h>
#include <falcon/vm.h>

#include <stdio.h>//debug..

//extern Falcon::DataMatrixService theDataMatrixService;

/*#
    @beginmodule dmtx
 */

namespace Falcon
{
namespace Ext
{

/*#
    @class DataMatrixError
    @brief Error generated DataMatrix operations.
    @optparam code The error code
    @optparam desc The description for the error code
    @optparam extra Extra information specifying the error conditions.
    @from Error( code, desc, extra )
*/
FALCON_FUNC DataMatrixError_init( VMachine* vm )
{
    CoreObject *einst = vm->self().asObject();

    if ( einst->getUserData() == 0 )
        einst->setUserData( new DataMatrixError );

    ::Falcon::core::Error_init( vm );
}


/*#
    @class DataMatrix
    @brief DataMatrix codec

    @prop module_size
    @prop margin_size
    @prop gap_size
    @prop scheme
    @prop shape
    @prop timeout
    @prop shrink
    @prop deviation
    @prop threshold
    @prop min_edge
    @prop max_edge
    @prop corrections
    @prop max_count
 */
#if 0
FALCON_FUNC DataMatrix_init( VMachine* vm )
{
    Dmtx::DataMatrix* self = static_cast<Dmtx::DataMatrix*>( vm->self().asObjectSafe() );
    vm->retval( self );
}
#endif


/*#
    @method encode DataMatrix
    @param data A string or membuf
    @param context A context object
    @return true on success
 */
FALCON_FUNC DataMatrix_encode( VMachine* vm )
{
    Item* i_data = vm->param( 0 );
    Item* i_ctxt = vm->param( 1 );

    if ( !i_data || !( i_data->isString() || i_data->isMemBuf() )
        || !i_ctxt || !i_ctxt->isObject() )
    {
        throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                .extra( "S|M,O" ) );
    }

    Dmtx::DataMatrix* self = static_cast<Dmtx::DataMatrix*>( vm->self().asObjectSafe() );
    vm->retval( self->encode( *i_data, *i_ctxt ) );
}


/*#
    @method decode DataMatrix
    @param data A string or membuf
    @param width Width of scanned image
    @param height Height of scanned image
    @return An array of results, or nil on error
 */
FALCON_FUNC DataMatrix_decode( VMachine* vm )
{
    Item* i_data = vm->param( 0 );
    Item* i_w = vm->param( 1 );
    Item* i_h = vm->param( 2 );

    if ( !i_data || !( i_data->isString() || i_data->isMemBuf() )
        || !i_w || !i_w->isInteger()
        || !i_h || !i_h->isInteger() )
    {
        throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                .extra( "S|M,I,I" ) );
    }

    Dmtx::DataMatrix* self = static_cast<Dmtx::DataMatrix*>( vm->self().asObjectSafe() );
    CoreArray* res;
    if ( self->decode( *i_data, i_w->asInteger(), i_h->asInteger(), &res ) )
        vm->retval( res );
    else
        vm->retnil();
}


/*#
    @method resetOptions
    @brief Reset the options (properties).
 */
FALCON_FUNC DataMatrix_resetOptions( VMachine* vm )
{
    Dmtx::DataMatrix* self = static_cast<Dmtx::DataMatrix*>( vm->self().asObjectSafe() );
    self->resetOptions();
}

} /* !namespace Ext */
} /* !namespace Falcon */