Category: cpp

  • Counting transitions in a bit string

    We need to count a number of transitions in a bit string from 0->1 and 1->0. I needed this in order to determine Uniform Descriptor in Local Binary Patterns(LBP)

    Samples

    0000 0000  (0 Transitions : Uniform)    0x0
    1110 0011  (2 Transitions : Uniform)    0xE3
    0101 0000  (4 Transitions : NonUniform) 0x50
    0000 1010  (4 Transitions : NonUniform) 0xA
    0000 1001  (3 Transitions : NonUniform) 0x9
    

    Sample run (0xE3)

    0x      e3 :      227 :: 00000000000000000000000011100011
    0x      71 :      113 :: 00000000000000000000000001110001
    0x      92 :      146 :: 00000000000000000000000010010010
    Transition : 3
    

    Implemenation

    We are going to shift the value to the right and then XOR it with the original value to get the number of transitions. From there we going to use population count to get the count of the on bits.

    XOR Truth table

    INPUT	         OUTPUT
    -----------------------
    A	B	A XOR B
    0	0	0
    0	1	1
    1	0	1
    1	1	0
    
    template  void bitstr(const T& out) noexcept;
    template  int  popcnt(const T& val) noexcept;
    
    int main()
    {
        // Uniform descriptors
        // 0000 0000  (0 Transitions : Uniform)    0x0
        // 1110 0011  (2 Transitions : Uniform)    0xE3
        // 0101 0000  (4 Transitions : NonUniform) 0x50
        // 0000 1010  (4 Transitions : NonUniform) 0xA
        // 0000 1001  (3 Transitions : NonUniform) 0x9
    
        int a = 0xE3;
        int b = a >> 1;
        int c = a ^ b;
        int count = popcnt(c);
    
        bitstr(a);
        bitstr(b);
        bitstr(c);
    
        std::cout << "Transition : " <<count; return="" 0;="" }="" template="" <class="" t="">
    int popcnt(const T& val) noexcept
    {
        int bitcount;
        __asm__ ("popcnt %1, %1" : "=r" (bitcount) : "0" (val));
        return bitcount;
    }
    
    template 
    void bitstr(const T& out) noexcept
    {
        std::bitset bs(out);
        auto val =  static_cast(out);
        std::cout << "0x"
                  << std::setw(8) << std::hex << val << " : "
                  << std::setw(8) << std::dec << val<< " :: " << bs << std::endl;
    }
    </count;>

    Gist

  • Dump leptonica pix data to console

    Small utility for dumping Leptonica Pix data to the screen.

    void dump(PIX* pix)
    {
        int_t w = pix->w;
        int_t h = pix->h;
    
        int_t wpl = pixGetWpl(pix);
        l_uint32* data = pixGetData(pix);
        l_uint32* line;
    
        printf("\n");
        printf("Depth : %d \n", pix->d);
    
        for (int_t y = 0; y < h; ++y)
        {
            printf("%04d  :  ", y);
            line = data + y * wpl;
            for (int_t x = 0; x < w; ++x)
            {
                l_uint32 val = 0;
    
                if(pix->d == 1)
                    val = GET_DATA_BIT(line, x);
                else if(pix->d == 2)
                    val = GET_DATA_DIBIT(line, x);
                else if(pix->d == 4)
                    val = GET_DATA_QBIT(line, x);
                else // 8, 16, 32
                    val = GET_DATA_BYTE(line, x);
    
                printf("%03d ", val);
            }
            printf("\n");
        }
    }
    
  • Overloading by return value in C++

    Here we have a method that allows us to determine return parameter type using templates and operator overloading in C++. This is something that I needed for a project that I am working on where a method call would give me the expected type based on the return type.

    Usage

    There is two way of using this. First one is by calling the para method and second one is by invoking the conversion method directly parameter.
    Personally, I prefer the first one as this one allows me to use it with auto keyword.

    
    std::string p0   = param<std::string>(arguments, 0);
    auto        p0_a = param<std::string>(arguments, 0);
    
    int         p1   = param<int>(arguments, 1);
    auto        p1_a = param<int>(arguments, 1);
    
    // Invoking parameter conversion directly
    std::string p0_p = parameter(arguments, 0); 
    int         p1_p = parameter(arguments, 1);
    

    Implemenation

    struct parameter
    {
    	parameter(const CefV8ValueList & arguments, int index) 
    		:_arg (arguments.at(index)) 
    	{
    	};
    
    	operator std::string() { return _arg->GetStringValue().ToString(); }
    	operator int() { return _arg->GetIntValue();}
    	operator bool() { return _arg->GetBoolValue(); }
    	operator double() { return _arg->GetDoubleValue();}
    
    	CefRefPtr _arg;
    };
    
    template
    T param(const CefV8ValueList & arguments, int index)
    {
    	return parameter(arguments, index);
    }
    

    Reference :
    http://en.cppreference.com/w/cpp/language/cast_operator

  • Creating Javascript accessible object from C++ / CEF

    Example with Chromium Embedded Framework (CEF) on how to create an object in C++ and make it accessible via Javascript.

    console.inof(api)
    Object {ready: true, version: "psql.0.0.1", info: Object, getVersion: function}
    
    void ExtractEngineApp::OnContextCreated(
    	CefRefPtr browser, 
    	CefRefPtr frame, 
    	CefRefPtr context)
    {
    
    	auto info = CefV8Value::CreateObject(NULL, NULL);
    	info->SetValue("major", CefV8Value::CreateString("0"), V8_PROPERTY_ATTRIBUTE_READONLY);
    	info->SetValue("minor", CefV8Value::CreateString("1"), V8_PROPERTY_ATTRIBUTE_READONLY);
    	
    	auto global = context->GetGlobal();
    	auto api = CefV8Value::CreateObject(NULL, NULL);
    
    	global->SetValue("api", api, V8_PROPERTY_ATTRIBUTE_NONE);
    
    	auto fun = CefV8Value::CreateFunction("getVersion", new engine:: PhantomExtensionHandler(this));
    	api->SetValue("getVersion", fun, V8_PROPERTY_ATTRIBUTE_NONE);
    	
    	// Readonly properties
    	api->SetValue("ready", CefV8Value::CreateBool(true), V8_PROPERTY_ATTRIBUTE_READONLY);
    	api->SetValue("version", CefV8Value::CreateString("psql.0.0.1"), V8_PROPERTY_ATTRIBUTE_READONLY);
    
    	// Readonly Object access
    	api->SetValue("info", info, V8_PROPERTY_ATTRIBUTE_READONLY);
    }
    
    
    class PhantomExtensionHandler : public CefV8Handler
    	{
    	public:
    		explicit PhantomExtensionHandler(CefRefPtr client_app)
    			: client_app(client_app)
    			, messageId(0)
    		{
    
    		}
    
    		virtual bool Execute(const CefString& name,
    			CefRefPtr object,
    			const CefV8ValueList& arguments,
    			CefRefPtr& retval,
    			CefString& exception)
    		{
    			if (name == "getVersion")
    			{
    				retval = CefV8Value::CreateString("Version(SemVer) # 0.0.1");
    			}
    
    			return true;
    		}
    
    	private:
    		CefRefPtr client_app;
    		int32 messageId;
    
    		IMPLEMENT_REFCOUNTING(PhantomExtensionHandler);
    	};
    
  • Accessing data of leptonica PIX data

    This is mainly as a reference

    
    /**
     * Get Pixel value at given  point
     */
    l_uint32 pixAtGet(PIX* pix, int_t x, int_t y)
    {
        l_int32 wpl    = pixGetWpl(pix);
        l_uint32* data = pixGetData(pix);
        l_uint32* line = data + y * wpl;
        l_uint32 value = GET_DATA_BYTE(line, x);
        return value;
    }
    
    

    To set a pixel value we can use this

    /**
     * Set Pixel value at given  point
     */
    void pixAtSet(PIX* pix, int_t x, int_t y, byte_t value)
    {
    	l_int32 wpl     = pixGetWpl(pix);
    	l_uint32* data  = pixGetData(pix);
    	l_uint32* line  = data + y * wpl;
    	SET_DATA_BYTE(line, x, value);
    }
    
  • Tokenizing/splitting string in c++

    This method uses strtok to tokeninze our string given a specific delimeter, results of that are put into supplied vector. There are few other ways we can do this but this one is straight forward.

    #include 
    #include 
    #include 
    
    #include 
    #include 
    #include 
    #include 
    #include 
    
    using namespace std;
    
    void split(vector& out, const string& in, const string& delim)
    {
      char* lc = (char*) malloc(in.size());
      strcpy(lc, in.c_str());
      strtok(lc, delim.c_str());
      while (lc)
        {
          string s = lc;
          out.push_back(s);
          lc = strtok(NULL, delim.c_str());
        }
      free(lc);
    }
    
    int main(int argc, char* args[])
    {
      string str = "apple,organge,cherry";
      vector o1;
      split(o1, str, ",");
    
      for (int i = 0; i < o1.size(); ++i)
      {
         cout << "token = " << o1[i] <
    

    Results

    Supplied string : apple,organge,cherry
    Delemeter : ","
    Output

    • apple
    • organge
    • cherry
  • Calculating partial Hausdorff Distance

    
    struct Point
    {
    	Point(int_t _x, int_t _y) : x(_x), y (_y)
    	{
    
    	}
    
    	int_t x;
    	int_t y;
    };
    
    
    typedef std::list points_t;
    
    double euclideanDistance(const Point& lhs,const Point& rhs)
    {
    	 double p1 = std::pow((float)(rhs.x - lhs.x), 2);
    	 double p2 =  std::pow((float)(rhs.y - lhs.y), 2);
    	 double vd =  std::sqrt(p1 + p2);
    
    	 return vd;
    }
    
    
    double hausdorffPHD(points_t seta, points_t setb)
    {
        double maxDistance = 0;
    
        points_t::iterator afront = seta.begin();
        points_t::iterator aback  = seta.end();
    
        std::vector ranking;
    
        for(int_t i=0; afront != aback ; ++afront, ++i)
        {
        	Point* a = *afront;
            double minDistance = std::numeric_limits::max();
    
            points_t::iterator bfront = setb.begin();
            points_t::iterator bback  = setb.end();
    
        	for(; bfront != bback ; ++bfront)
    	    {
        		Point* b = *bfront;
        		double ed = euclideanDistance(*a, *b);
    
                if (ed < minDistance)
                    minDistance = ed;
    	    }
    
        	ranking.push_back(minDistance);
        }
    
        std::sort(ranking.begin(), ranking.end());
    
        double fraction = .7;
        int k = (int) (seta.size() * fraction);
        return ranking[k];
    }
    
    
    double hausdorff(points_t seta, points_t setb)
    {
        double habPHD = hausdorffPHD( seta, setb);
        double hbaPHD = hausdorffPHD( setb, seta);
        double distancePHD = std::max(habPHD, hbaPHD);
        printf("hd = %0.4f\t %0.4f\t %0.4f\t \n", distancePHD, habPHD, hbaPHD);
        return distancePHD;
    }
    
    
    int_t main(int_t argc, char_t** args)
    {
    
    	points_t seta;
    	points_t setb;
    
    	seta.push_back(new Point(1,2));
    	seta.push_back(new Point(2, 4));
    
    	setb.push_back(new Point(2, 4));
    	setb.push_back(new Point(3, 4));
    
    	double val = hausdorff(seta, setb);
    }
    
  • Compiling Webkit on Windows using Visual Studio 2012

    Just some notes on compiling WebKit on windows with visual studio.

    Issues :

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xrefwrap(431): error C2064: term does not evaluate to a function taking 1 arguments (..\..\win\WebCoreSupport\WebFrameLoaderClient.cpp)
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(239) : see reference to function template instantiation '_Ret std::_Callable_obj<_Ty>::_ApplyX<_Rx,WebCore::PolicyAction>(_V0_t &&)' being compiled
    25>          with
    25>          [
    25>              _Ret=void,
    25>              _Ty=int,
    25>              _Rx=void,
    25>              _V0_t=WebCore::PolicyAction
    25>          ]
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(239) : see reference to function template instantiation '_Ret std::_Callable_obj<_Ty>::_ApplyX<_Rx,WebCore::PolicyAction>(_V0_t &&)' being compiled
    25>          with
    25>          [
    25>              _Ret=void,
    25>              _Ty=int,
    25>              _Rx=void,
    25>              _V0_t=WebCore::PolicyAction
    25>          ]
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(239) : while compiling class template member function 'void std::_Func_impl<_Callable,_Alloc,_Rx,_V0_t>::_Do_call(_V0_t &&)'
    25>          with
    25>          [
    25>              _Callable=_MyWrapper,
    25>              _Alloc=std::allocator>,
    25>              _Rx=void,
    25>              _V0_t=WebCore::PolicyAction
    25>          ]
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(515) : see reference to class template instantiation 'std::_Func_impl<_Callable,_Alloc,_Rx,_V0_t>' being compiled
    25>          with
    25>          [
    25>              _Callable=_MyWrapper,
    25>              _Alloc=std::allocator>,
    25>              _Rx=void,
    25>              _V0_t=WebCore::PolicyAction
    25>          ]
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(515) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t>::_Do_alloc<_Myimpl,_Ty,_Alloc>(_Fty &&,_Alloc)' being compiled
    25>          with
    25>          [
    25>              _Ret=void,
    25>              _V0_t=WebCore::PolicyAction,
    25>              _Ty=int,
    25>              _Alloc=std::allocator>,
    25>              _Fty=int
    25>          ]
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(515) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t>::_Do_alloc<_Myimpl,_Ty,_Alloc>(_Fty &&,_Alloc)' being compiled
    25>          with
    25>          [
    25>              _Ret=void,
    25>              _V0_t=WebCore::PolicyAction,
    25>              _Ty=int,
    25>              _Alloc=std::allocator>,
    25>              _Fty=int
    25>          ]
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(515) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t>::_Reset_alloc<_Ty,std::allocator>>(_Fty &&,_Alloc)' being compiled
    25>          with
    25>          [
    25>              _Ret=void,
    25>              _V0_t=WebCore::PolicyAction,
    25>              _Ty=int,
    25>              _Fty=int,
    25>              _Alloc=std::allocator>
    25>          ]
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(515) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t>::_Reset_alloc<_Ty,std::allocator>>(_Fty &&,_Alloc)' being compiled
    25>          with
    25>          [
    25>              _Ret=void,
    25>              _V0_t=WebCore::PolicyAction,
    25>              _Ty=int,
    25>              _Fty=int,
    25>              _Alloc=std::allocator>
    25>          ]
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(675) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t>::_Reset<_Ty>(_Fty &&)' being compiled
    25>          with
    25>          [
    25>              _Ret=void,
    25>              _V0_t=WebCore::PolicyAction,
    25>              _Ty=int,
    25>              _Fty=int
    25>          ]
    25>          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional(675) : see reference to function template instantiation 'void std::_Func_class<_Ret,_V0_t>::_Reset<_Ty>(_Fty &&)' being compiled
    25>          with
    25>          [
    25>              _Ret=void,
    25>              _V0_t=WebCore::PolicyAction,
    25>              _Ty=int,
    25>              _Fty=int
    25>          ]
    25>          ..\..\win\WebCoreSupport\WebFrameLoaderClient.cpp(97) : see reference to function template instantiation 'std::function<_Fty>::function(_Fx &&)' being compiled
    25>          with
    25>          [
    25>              _Fty=void (WebCore::PolicyAction),
    25>              _Fx=int
    25>          ]
    25>          ..\..\win\WebCoreSupport\WebFrameLoaderClient.cpp(97) : see reference to function template instantiation 'std::function<_Fty>::function(_Fx &&)' being compiled
    25>          with
    25>          [
    25>              _Fty=void (WebCore::PolicyAction),
    25>              _Fx=int
    25>          ]
    

    Patch
    WebFrameLoaderClient.cpp
    Line 97
    – : m_policyFunction(0)
    + : m_policyFunction(nullptr)

    Issue:

    25>WebKitGUID.lib(WebKit_i.obj) : error LNK2005: _IID_IDOMDocumentType already defined in uuid.lib(i_mshtml.obj)
    25>WebKitGUID.lib(WebKit_i.obj) : error LNK2005: _IID_IDOMProcessingInstruction already defined in uuid.lib(i_mshtml.obj)
    25>WebKitGUID.lib(WebKit_i.obj) : error LNK2005: _IID_IDOMEvent already defined in uuid.lib(i_mshtml.obj)
    25>WebKitGUID.lib(WebKit_i.obj) : error LNK2005: _IID_IDOMUIEvent already defined in uuid.lib(i_mshtml.obj)
    25>WebKitGUID.lib(WebKit_i.obj) : error LNK2005: _IID_IDOMKeyboardEvent already defined in uuid.lib(i_mshtml.obj)
    25>WebKitGUID.lib(WebKit_i.obj) : error LNK2005: _IID_IDOMMouseEvent already defined in uuid.lib(i_mshtml.obj)
    25>WebKitGUID.lib(WebKit_i.obj) : error LNK2005: _IID_IDOMMutationEvent already defined in uuid.lib(i_mshtml.obj)
    25>WebKitGUID.lib(WebKit_i.obj) : error LNK2005: _IID_IDOMWheelEvent already defined in uuid.lib(i_mshtml.obj)
    

    Added linker option to WebKitGUID /FORCE:MULTIPLE
    Now we get warning instead of errors;

    13>WebKitGUID.lib(WebKit_i.obj) : warning LNK4006: _IID_IDOMDocumentType already defined in uuid.lib(i_mshtml.obj); second definition ignored
    13>WebKitGUID.lib(WebKit_i.obj) : warning LNK4006: _IID_IDOMProcessingInstruction already defined in uuid.lib(i_mshtml.obj); second definition ignored
    13>WebKitGUID.lib(WebKit_i.obj) : warning LNK4006: _IID_IDOMEvent already defined in uuid.lib(i_mshtml.obj); second definition ignored
    13>WebKitGUID.lib(WebKit_i.obj) : warning LNK4006: _IID_IDOMUIEvent already defined in uuid.lib(i_mshtml.obj); second definition ignored
    13>WebKitGUID.lib(WebKit_i.obj) : warning LNK4006: _IID_IDOMKeyboardEvent already defined in uuid.lib(i_mshtml.obj); second definition ignored
    13>WebKitGUID.lib(WebKit_i.obj) : warning LNK4006: _IID_IDOMMouseEvent already defined in uuid.lib(i_mshtml.obj); second definition ignored
    13>WebKitGUID.lib(WebKit_i.obj) : warning LNK4006: _IID_IDOMMutationEvent already defined in uuid.lib(i_mshtml.obj); second definition ignored
    13>WebKitGUID.lib(WebKit_i.obj) : warning LNK4006: _IID_IDOMWheelEvent already defined in uuid.lib(i_mshtml.obj); second definition ignored
    13>C:\cygwin\home\gbugaj\WebKit\WebKitBuild\Debug_WinCairo\bin32\WebKit.dll : warning LNK4088: image being generated due to /FORCE option; image may not run
    
    

    Building Dependencies

    Cairo

    Issue

    gbugaj@LTRMS7GB /cygdrive/c/cygwin/home/gbugaj/cairo
    $ make -f Makefile.win32  CFG=release
    
    make[1]: Entering directory '/cygdrive/c/cygwin/home/gbugaj/cairo/src'
    
    cairo-deflate-stream.c
    e:\source\c-libraries\zlib-1.2.3-lib\include\zconf.h(289) : fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
    ../build/Makefile.win32.common:55: recipe for target 'release/cairo-deflate-stream.obj' failed
    make[1]: *** [release/cairo-deflate-stream.obj] Error 2
    make[1]: Leaving directory '/cygdrive/c/cygwin/home/gbugaj/cairo/src'
    Makefile.win32:12: recipe for target 'cairo' failed
    make: *** [cairo] Error 2
    

    Fix is to add empty ‘unistd.h’ to zlib include directory

  • Leptonica barcode generation

    Leptonica provides us with easy way to read barcodes but it does not offer a way to create them(as far as I know). Here is a leptonica function that will allow us to generate CODABAR barcode, in the feature I am planning on adding more type and more options but for now this was all I needed.

    Sample Usage

    l_int32 res = 300;
    l_int32 bar_width = .02 * res;
    l_int32 bar_height = .35 * res;
    
    // Barcode is bitonal
    PIX* barcode= pixCreateBarcodeCodebar("C3853110009C", bar_width, bar_height, 10, 10, 2, 2);
    if (barcode == NULL)
    {
    	printf("\n******** ERROR ***********");
    	return;
    }
    pixWritePng("c:/temp/barcode.png", barcode, 0);
    

    Implementation

    /**
     * Barcode Generator
     * @author : greg
     */
    #ifndef CREATEBARCODE_H_
    #define CREATEBARCODE_H_
    
    #include 
    
    #if !defined(LEPTONICA_ALLHEADERS_H)
    #   include 
    #endif
    
    #if !defined(LEPTONICA_READBARCODE_H)
    #	include 
    #endif
    
    /* ----------------------------------------------------------------- *
     * Codabar symbology                         *
     * Data  B  S  B  S  B  S  B   Value
     * 0     0  0  0  0  0  1  1     0
     * 1     0  0  0  0  1  1  0     1
     * 2     0  0  0  1  0  0  1     2
     * @ref http://www.barcodesymbols.com/codabar.htm
     * @ref leptonica/readbarcode.h
     * ----------------------------------------------------------------- */
    static const char *CodabarCodes[] =
    { "1111122", "1111221", "1112112", "2211111", "1121121", /* 0: 0 - 4      */
    "2111121", "1211112", "1211211", "1221111", "2112111", /* 5: 5 - 9      */
    "1112211", "1122111", "2111212", "2121112", "2121211", /* 10: -,$,:,/,. */
    "1121212", "1122121", "1212112", "1112122", "1112221" /* 15: +,A,B,C,D */
    };
    
    int mapCodebarToIndex(const char c)
    {
    	switch (toupper(c))
    	{
    	case '0':
    	case '1':
    	case '2':
    	case '3':
    	case '4':
    	case '5':
    	case '6':
    	case '7':
    	case '8':
    	case '9':
    		return atoi(&c);
    	case '-':
    		return 10;
    	case '$':
    		return 11;
    	case ':':
    		return 12;
    	case '/':
    		return 13;
    	case '.':
    		return 14;
    	case '+':
    		return 15;
    	case 'A':
    		return 16;
    	case 'B':
    		return 17;
    	case 'C':
    	case '*':
    		return 18;
    	case 'E':
    	case 'D':
    		return 19;
    
    	}
    	return 0;
    }
    
    /**
     * Crate 8 bpp Codebar barcode
     */
    PIX* pixCreateBarcodeCodebar(const char* code, l_int32 bar_width, l_int32 bar_height, l_int32 margin_left,
    		l_int32 margin_right, l_int32 margin_top, l_int32 margin_bottom)
    {
    	PROCNAME("pixCreateBarcodeCodebar");
    
    	printf("\n Rendering : %s", code);
    	//The width ratio between narrow and wide can be chosen between 1:2.25 and 1:3
    	l_float32 ratio = 2;
    	l_int32 width_wide = bar_width * ratio;
    	l_int32 narrow_space = bar_width;
    	// Calculate size
    	l_int32 size = 0;
    	for (int i = 0; code[i] != '\0'; ++i, ++size)
    	{
    		// NOOP
    	}
    	// allocate big enough image
    	PIX* pix = pixCreate(size * width_wide * 7, bar_height, 1);
    	pixSetResolution(pix, 300, 300);
    
    	l_int32 xpos = margin_left;
    	for (int i = 0; i < size; ++i)
    	{
    		const char* encoding = CodabarCodes[mapCodebarToIndex(code[i])];
    		for (l_uint16 j = 0; j < 7; j++)
    		{
    			l_int32 renderwidth = bar_width;
    			if (encoding[j] == '2')
    			{
    				renderwidth = width_wide;
    			}
    			if ((j % 2 == 0))
    			{
    				for (l_int32 k = 0; k < renderwidth; ++k)
    				{
    //					pixRenderLineArb(pix, xpos+k, 0, xpos+k, height, 1, 0, 0, 0);
    					pixRenderLine(pix, xpos + k, margin_top, xpos + k, bar_height - margin_bottom, 1, L_SET_PIXELS);
    				}
    			}
    			xpos += renderwidth;
    		}
    
    		// Each character is separated by narrow space
    		if (i < size - 1)
    			xpos += narrow_space;
    	}
    
    	// Clip
    	BOX* bounds = boxCreate(0, 0, xpos + margin_right, bar_height);
    	pix = pixClipRectangle(pix, bounds, NULL);
    	boxDestroy(&bounds);
    	return pix;
    }
    
    #endif /* CREATEBARCODE_H_ */
    
    

    I think I will make this my first GIT project and share it with all, trying to move away from google code.