ZBar bar code reader . http://zbar.sourceforge.net/ ZBar is licensed under the GNU LGPL 2.1 to enable development of both open source and commercial projects.

Dependents:   GR-PEACH_Camera_in_barcode levkov_ov7670

LICENSE

The ZBar Bar Code Reader is Copyright (C) 2007-2009 Jeff Brown <spadix@users.sourceforge.net> The QR Code reader is Copyright (C) 1999-2009 Timothy B. Terriberry <tterribe@xiph.org>

You can redistribute this library 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 (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 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 Street, Fifth Floor, Boston, MA 02110-1301 USA

ISAAC is based on the public domain implementation by Robert J. Jenkins Jr., and is itself public domain.

Portions of the bit stream reader are copyright (C) The Xiph.Org Foundation 1994-2008, and are licensed under a BSD-style license.

The Reed-Solomon decoder is derived from an implementation (C) 1991-1995 Henry Minsky (hqm@ua.com, hqm@ai.mit.edu), and is licensed under the LGPL with permission.

Committer:
RyoheiHagimoto
Date:
Tue Apr 19 02:19:39 2016 +0000
Revision:
1:500d42699c34
Parent:
0:56c5742b9e2b
Add copying.txt and license.txt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:56c5742b9e2b 1 /*Written by Timothy B. Terriberry (tterribe@xiph.org) 1999-2009 public domain.
RyoheiHagimoto 0:56c5742b9e2b 2 Based on the public domain implementation by Robert J. Jenkins Jr.*/
RyoheiHagimoto 0:56c5742b9e2b 3 #include <float.h>
RyoheiHagimoto 0:56c5742b9e2b 4 #include <math.h>
RyoheiHagimoto 0:56c5742b9e2b 5 #include <string.h>
RyoheiHagimoto 0:56c5742b9e2b 6 #include "isaac.h"
RyoheiHagimoto 0:56c5742b9e2b 7
RyoheiHagimoto 0:56c5742b9e2b 8
RyoheiHagimoto 0:56c5742b9e2b 9
RyoheiHagimoto 0:56c5742b9e2b 10 #define ISAAC_MASK (0xFFFFFFFFU)
RyoheiHagimoto 0:56c5742b9e2b 11
RyoheiHagimoto 0:56c5742b9e2b 12
RyoheiHagimoto 0:56c5742b9e2b 13
RyoheiHagimoto 0:56c5742b9e2b 14 static void isaac_update(isaac_ctx *_ctx){
RyoheiHagimoto 0:56c5742b9e2b 15 unsigned *m;
RyoheiHagimoto 0:56c5742b9e2b 16 unsigned *r;
RyoheiHagimoto 0:56c5742b9e2b 17 unsigned a;
RyoheiHagimoto 0:56c5742b9e2b 18 unsigned b;
RyoheiHagimoto 0:56c5742b9e2b 19 unsigned x;
RyoheiHagimoto 0:56c5742b9e2b 20 unsigned y;
RyoheiHagimoto 0:56c5742b9e2b 21 int i;
RyoheiHagimoto 0:56c5742b9e2b 22 m=_ctx->m;
RyoheiHagimoto 0:56c5742b9e2b 23 r=_ctx->r;
RyoheiHagimoto 0:56c5742b9e2b 24 a=_ctx->a;
RyoheiHagimoto 0:56c5742b9e2b 25 b=_ctx->b+(++_ctx->c)&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 26 for(i=0;i<ISAAC_SZ/2;i++){
RyoheiHagimoto 0:56c5742b9e2b 27 x=m[i];
RyoheiHagimoto 0:56c5742b9e2b 28 a=(a^a<<13)+m[i+ISAAC_SZ/2]&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 29 m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 30 r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 31 x=m[++i];
RyoheiHagimoto 0:56c5742b9e2b 32 a=(a^a>>6)+m[i+ISAAC_SZ/2]&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 33 m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 34 r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 35 x=m[++i];
RyoheiHagimoto 0:56c5742b9e2b 36 a=(a^a<<2)+m[i+ISAAC_SZ/2]&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 37 m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 38 r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 39 x=m[++i];
RyoheiHagimoto 0:56c5742b9e2b 40 a=(a^a>>16)+m[i+ISAAC_SZ/2]&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 41 m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 42 r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 43 }
RyoheiHagimoto 0:56c5742b9e2b 44 for(i=ISAAC_SZ/2;i<ISAAC_SZ;i++){
RyoheiHagimoto 0:56c5742b9e2b 45 x=m[i];
RyoheiHagimoto 0:56c5742b9e2b 46 a=(a^a<<13)+m[i-ISAAC_SZ/2]&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 47 m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 48 r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 49 x=m[++i];
RyoheiHagimoto 0:56c5742b9e2b 50 a=(a^a>>6)+m[i-ISAAC_SZ/2]&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 51 m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 52 r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 53 x=m[++i];
RyoheiHagimoto 0:56c5742b9e2b 54 a=(a^a<<2)+m[i-ISAAC_SZ/2]&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 55 m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 56 r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 57 x=m[++i];
RyoheiHagimoto 0:56c5742b9e2b 58 a=(a^a>>16)+m[i-ISAAC_SZ/2]&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 59 m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 60 r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
RyoheiHagimoto 0:56c5742b9e2b 61 }
RyoheiHagimoto 0:56c5742b9e2b 62 _ctx->b=b;
RyoheiHagimoto 0:56c5742b9e2b 63 _ctx->a=a;
RyoheiHagimoto 0:56c5742b9e2b 64 _ctx->n=ISAAC_SZ;
RyoheiHagimoto 0:56c5742b9e2b 65 }
RyoheiHagimoto 0:56c5742b9e2b 66
RyoheiHagimoto 0:56c5742b9e2b 67 static void isaac_mix(unsigned _x[8]){
RyoheiHagimoto 0:56c5742b9e2b 68 static const unsigned char SHIFT[8]={11,2,8,16,10,4,8,9};
RyoheiHagimoto 0:56c5742b9e2b 69 int i;
RyoheiHagimoto 0:56c5742b9e2b 70 for(i=0;i<8;i++){
RyoheiHagimoto 0:56c5742b9e2b 71 _x[i]^=_x[i+1&7]<<SHIFT[i];
RyoheiHagimoto 0:56c5742b9e2b 72 _x[i+3&7]+=_x[i];
RyoheiHagimoto 0:56c5742b9e2b 73 _x[i+1&7]+=_x[i+2&7];
RyoheiHagimoto 0:56c5742b9e2b 74 i++;
RyoheiHagimoto 0:56c5742b9e2b 75 _x[i]^=_x[i+1&7]>>SHIFT[i];
RyoheiHagimoto 0:56c5742b9e2b 76 _x[i+3&7]+=_x[i];
RyoheiHagimoto 0:56c5742b9e2b 77 _x[i+1&7]+=_x[i+2&7];
RyoheiHagimoto 0:56c5742b9e2b 78 }
RyoheiHagimoto 0:56c5742b9e2b 79 }
RyoheiHagimoto 0:56c5742b9e2b 80
RyoheiHagimoto 0:56c5742b9e2b 81
RyoheiHagimoto 0:56c5742b9e2b 82 void isaac_init(isaac_ctx *_ctx,const void *_seed,int _nseed){
RyoheiHagimoto 0:56c5742b9e2b 83 const unsigned char *seed;
RyoheiHagimoto 0:56c5742b9e2b 84 unsigned *m;
RyoheiHagimoto 0:56c5742b9e2b 85 unsigned *r;
RyoheiHagimoto 0:56c5742b9e2b 86 unsigned x[8];
RyoheiHagimoto 0:56c5742b9e2b 87 int i;
RyoheiHagimoto 0:56c5742b9e2b 88 int j;
RyoheiHagimoto 0:56c5742b9e2b 89 _ctx->a=_ctx->b=_ctx->c=0;
RyoheiHagimoto 0:56c5742b9e2b 90 m=_ctx->m;
RyoheiHagimoto 0:56c5742b9e2b 91 r=_ctx->r;
RyoheiHagimoto 0:56c5742b9e2b 92 x[0]=x[1]=x[2]=x[3]=x[4]=x[5]=x[6]=x[7]=0x9E3779B9;
RyoheiHagimoto 0:56c5742b9e2b 93 for(i=0;i<4;i++)isaac_mix(x);
RyoheiHagimoto 0:56c5742b9e2b 94 if(_nseed>ISAAC_SEED_SZ_MAX)_nseed=ISAAC_SEED_SZ_MAX;
RyoheiHagimoto 0:56c5742b9e2b 95 seed=(const unsigned char *)_seed;
RyoheiHagimoto 0:56c5742b9e2b 96 for(i=0;i<_nseed>>2;i++){
RyoheiHagimoto 0:56c5742b9e2b 97 r[i]=seed[i<<2|3]<<24|seed[i<<2|2]<<16|seed[i<<2|1]<<8|seed[i<<2];
RyoheiHagimoto 0:56c5742b9e2b 98 }
RyoheiHagimoto 0:56c5742b9e2b 99 if(_nseed&3){
RyoheiHagimoto 0:56c5742b9e2b 100 r[i]=seed[i<<2];
RyoheiHagimoto 0:56c5742b9e2b 101 for(j=1;j<(_nseed&3);j++)r[i]+=seed[i<<2|j]<<(j<<3);
RyoheiHagimoto 0:56c5742b9e2b 102 i++;
RyoheiHagimoto 0:56c5742b9e2b 103 }
RyoheiHagimoto 0:56c5742b9e2b 104 memset(r+i,0,(ISAAC_SZ-i)*sizeof(*r));
RyoheiHagimoto 0:56c5742b9e2b 105 for(i=0;i<ISAAC_SZ;i+=8){
RyoheiHagimoto 0:56c5742b9e2b 106 for(j=0;j<8;j++)x[j]+=r[i+j];
RyoheiHagimoto 0:56c5742b9e2b 107 isaac_mix(x);
RyoheiHagimoto 0:56c5742b9e2b 108 memcpy(m+i,x,sizeof(x));
RyoheiHagimoto 0:56c5742b9e2b 109 }
RyoheiHagimoto 0:56c5742b9e2b 110 for(i=0;i<ISAAC_SZ;i+=8){
RyoheiHagimoto 0:56c5742b9e2b 111 for(j=0;j<8;j++)x[j]+=m[i+j];
RyoheiHagimoto 0:56c5742b9e2b 112 isaac_mix(x);
RyoheiHagimoto 0:56c5742b9e2b 113 memcpy(m+i,x,sizeof(x));
RyoheiHagimoto 0:56c5742b9e2b 114 }
RyoheiHagimoto 0:56c5742b9e2b 115 isaac_update(_ctx);
RyoheiHagimoto 0:56c5742b9e2b 116 }
RyoheiHagimoto 0:56c5742b9e2b 117
RyoheiHagimoto 0:56c5742b9e2b 118 unsigned isaac_next_uint32(isaac_ctx *_ctx){
RyoheiHagimoto 0:56c5742b9e2b 119 if(!_ctx->n)isaac_update(_ctx);
RyoheiHagimoto 0:56c5742b9e2b 120 return _ctx->r[--_ctx->n];
RyoheiHagimoto 0:56c5742b9e2b 121 }
RyoheiHagimoto 0:56c5742b9e2b 122
RyoheiHagimoto 0:56c5742b9e2b 123 /*Returns a uniform random integer less than the given maximum value.
RyoheiHagimoto 0:56c5742b9e2b 124 _n: The upper bound on the range of numbers returned (not inclusive).
RyoheiHagimoto 0:56c5742b9e2b 125 This must be strictly less than 2**32.
RyoheiHagimoto 0:56c5742b9e2b 126 Return: An integer uniformly distributed between 0 (inclusive) and _n
RyoheiHagimoto 0:56c5742b9e2b 127 (exclusive).*/
RyoheiHagimoto 0:56c5742b9e2b 128 unsigned isaac_next_uint(isaac_ctx *_ctx,unsigned _n){
RyoheiHagimoto 0:56c5742b9e2b 129 unsigned r;
RyoheiHagimoto 0:56c5742b9e2b 130 unsigned v;
RyoheiHagimoto 0:56c5742b9e2b 131 unsigned d;
RyoheiHagimoto 0:56c5742b9e2b 132 do{
RyoheiHagimoto 0:56c5742b9e2b 133 r=isaac_next_uint32(_ctx);
RyoheiHagimoto 0:56c5742b9e2b 134 v=r%_n;
RyoheiHagimoto 0:56c5742b9e2b 135 d=r-v;
RyoheiHagimoto 0:56c5742b9e2b 136 }
RyoheiHagimoto 0:56c5742b9e2b 137 while((d+_n-1&ISAAC_MASK)<d);
RyoheiHagimoto 0:56c5742b9e2b 138 return v;
RyoheiHagimoto 0:56c5742b9e2b 139 }
RyoheiHagimoto 0:56c5742b9e2b 140