bitcoin-atm

bitcoin atm for pyc inc.

git clone https://9o.is/git/bitcoin-atm.git

bitmat.js

(2644B)


      1 /*
      2   Ported to JavaScript by Lazar Laszlo 2011 
      3   
      4   lazarsoft@gmail.com, www.lazarsoft.info
      5   
      6 */
      7 
      8 /*
      9 *
     10 * Copyright 2007 ZXing authors
     11 *
     12 * Licensed under the Apache License, Version 2.0 (the "License");
     13 * you may not use this file except in compliance with the License.
     14 * You may obtain a copy of the License at
     15 *
     16 *      http://www.apache.org/licenses/LICENSE-2.0
     17 *
     18 * Unless required by applicable law or agreed to in writing, software
     19 * distributed under the License is distributed on an "AS IS" BASIS,
     20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     21 * See the License for the specific language governing permissions and
     22 * limitations under the License.
     23 */
     24 
     25 
     26 function BitMatrix( width,  height)
     27 {
     28 	if(!height)
     29 		height=width;
     30 	if (width < 1 || height < 1)
     31 	{
     32 		throw "Both dimensions must be greater than 0";
     33 	}
     34 	this.width = width;
     35 	this.height = height;
     36 	var rowSize = width >> 5;
     37 	if ((width & 0x1f) != 0)
     38 	{
     39 		rowSize++;
     40 	}
     41 	this.rowSize = rowSize;
     42 	this.bits = new Array(rowSize * height);
     43 	for(var i=0;i<this.bits.length;i++)
     44 		this.bits[i]=0;
     45 	
     46 	this.__defineGetter__("Width", function()
     47 	{
     48 		return this.width;
     49 	});
     50 	this.__defineGetter__("Height", function()
     51 	{
     52 		return this.height;
     53 	});
     54 	this.__defineGetter__("Dimension", function()
     55 	{
     56 		if (this.width != this.height)
     57 		{
     58 			throw "Can't call getDimension() on a non-square matrix";
     59 		}
     60 		return this.width;
     61 	});
     62 	
     63 	this.get_Renamed=function( x,  y)
     64 		{
     65 			var offset = y * this.rowSize + (x >> 5);
     66 			return ((URShift(this.bits[offset], (x & 0x1f))) & 1) != 0;
     67 		}
     68 	this.set_Renamed=function( x,  y)
     69 		{
     70 			var offset = y * this.rowSize + (x >> 5);
     71 			this.bits[offset] |= 1 << (x & 0x1f);
     72 		}
     73 	this.flip=function( x,  y)
     74 		{
     75 			var offset = y * this.rowSize + (x >> 5);
     76 			this.bits[offset] ^= 1 << (x & 0x1f);
     77 		}
     78 	this.clear=function()
     79 		{
     80 			var max = this.bits.length;
     81 			for (var i = 0; i < max; i++)
     82 			{
     83 				this.bits[i] = 0;
     84 			}
     85 		}
     86 	this.setRegion=function( left,  top,  width,  height)
     87 		{
     88 			if (top < 0 || left < 0)
     89 			{
     90 				throw "Left and top must be nonnegative";
     91 			}
     92 			if (height < 1 || width < 1)
     93 			{
     94 				throw "Height and width must be at least 1";
     95 			}
     96 			var right = left + width;
     97 			var bottom = top + height;
     98 			if (bottom > this.height || right > this.width)
     99 			{
    100 				throw "The region must fit inside the matrix";
    101 			}
    102 			for (var y = top; y < bottom; y++)
    103 			{
    104 				var offset = y * this.rowSize;
    105 				for (var x = left; x < right; x++)
    106 				{
    107 					this.bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
    108 				}
    109 			}
    110 		}
    111 }