⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qrcode_dev.js

📁 在线生成手机二维码的源程序
💻 JS
📖 第 1 页 / 共 2 页
字号:
	rs_block_order=rso.unpack("C*")	format_information_x2=fi_x.unpack("C*")	format_information_y2=fi_y.unpack("C*")	format_information_x1=[0,1,2,3,4,5,7,8,8,8,8,8,8,8,8]	format_information_y1=[8,8,8,8,8,8,8,8,7,5,4,3,2,1,0]	max_data_codewords=(max_data_bits >>3)	filename = this.path+"/rsc"+rs_ecc_codewords.to_s()+".dat"	fp =File.open(filename, "rb_bin")	i=0	rs_cal_table_array=[]	while (i<256){		rs_cal_table_array[i]=fp.read(rs_ecc_codewords)		i += 1	}//	fp.close///* -- read frame data  -- */	filename = this.path+"/qrvfr"+this.qrcode_version.to_s()+".dat"	fp = File.open(filename, "rb")		frame_data = fp.read(65535);//	fp.close}catch(e){	throw e}///*  --- set terminator */	if (total_data_bits<=max_data_bits-4) {		data_value[data_counter]=0		data_bits[data_counter]=4	} else if  (total_data_bits<max_data_bits) {		data_value[data_counter]=0			data_bits[data_counter]=max_data_bits-total_data_bits		} else if (total_data_bits>max_data_bits) {				throw "Overflow error"			return 0	}///* ----divide data by 8bit */	i=0	codewords_counter=0	codewords=[]	codewords[0]=0	remaining_bits=8	while ((i <= data_counter)){		buffer=data_value[i]		buffer_bits=data_bits[i]		flag=1		while (flag!=0 ){			if (remaining_bits>buffer_bits) { 				if(codewords[codewords_counter] ==nil){codewords[codewords_counter]=0}				codewords[codewords_counter]=((codewords[codewords_counter]<<buffer_bits) | buffer)				remaining_bits-=buffer_bits				flag=0			} else { 				buffer_bits-=remaining_bits				codewords[codewords_counter]=((codewords[codewords_counter] << remaining_bits) | (buffer >> buffer_bits))				if (buffer_bits==0) {					flag=0				} else { 					buffer= (buffer & ((1 << buffer_bits)-1) )					flag=1				}				codewords_counter += 1				if (codewords_counter<max_data_codewords-1) {					codewords[codewords_counter]=0				}				remaining_bits=8			}		}		i += 1	}	if (remaining_bits!=8) {		codewords[codewords_counter]=codewords[codewords_counter] << remaining_bits	} else {		codewords_counter-=1	}///* ----  set padding character */	if (codewords_counter<max_data_codewords-1) {		flag=1		while (codewords_counter<max_data_codewords-1){			codewords_counter += 1			if (flag==1)  {				codewords[codewords_counter]=236			} else { 				codewords[codewords_counter]=17			}			flag=flag*(-1)		}	}///* ---- RS-ECC prepare */	i=0	j=0	rs_block_number=0	rs_temp=[]	rs_temp[0]=""	while (i<max_data_codewords){		rs_temp[rs_block_number] += codewords[i].chr()		j += 1		if (j>=rs_block_order[rs_block_number]-rs_ecc_codewords) {			j=0			rs_block_number += 1			rs_temp[rs_block_number]=""		}		i += 1	}///*//// RS-ECC main////*///alert(rs_block_order.join(" "));//alert(rs_temp[0].unpack("C*"));//alert(rs_cal_table_array.join("\n"));	rs_block_number=0	rs_block_order_num=rs_block_order.length	while (rs_block_number<rs_block_order_num){		rs_codewords=rs_block_order[rs_block_number]		rs_data_codewords=rs_codewords-rs_ecc_codewords		rstemp=rs_temp[rs_block_number]				j=rs_data_codewords		while (j>0){			first=rstemp.charCodeAt(0)			if(first!=0){				left_chr=rstemp[1,rstemp.length-1]				cal=rs_cal_table_array[first]				rstemp=this.string_bit_cal(left_chr,cal,"xor")			} else {				rstemp=rstemp[1,rstemp.length-1]			}			j-=1		}		codewords = codewords.concat(rstemp.unpack("C*"))		rs_block_number += 1	}//---- ///* ---- flash matrix */	matrix_content=new Range(0,max_modules_1side,true).collect(function(){		 return new Array(max_modules_1side).fill(0)	})///* --- attach data */	i=0	while (i<max_codewords){		codeword_i=codewords[i]		j=7		while (j>=0){			codeword_bits_number=(i << 3) +  j			matrix_content[ matrix_x_array[codeword_bits_number] ][ matrix_y_array[codeword_bits_number] ]=((255*(codeword_i & 1)) ^ mask_array[codeword_bits_number] )			codeword_i= codeword_i >> 1			j-=1		}		i += 1	}	matrix_remain=matrix_remain_bit[this.qrcode_version]	while (matrix_remain>0){		remain_bit_temp = matrix_remain + ( max_codewords << 3)-1		matrix_content[ matrix_x_array[remain_bit_temp] ][ matrix_y_array[remain_bit_temp] ]  =  ( 255 ^ mask_array[remain_bit_temp] )		matrix_remain-=1	}//--- mask select	min_demerit_score=0		hor_master=""		ver_master=""		k=0		while (k<max_modules_1side){			l=0			while (l<max_modules_1side){				hor_master  +=  matrix_content[l][k].to_int().chr()				ver_master  +=  matrix_content[k][l].to_int().chr()				l += 1			}			k += 1		}	i=0	all_matrix=max_modules_1side*max_modules_1side//alert(matrix_content[l]);//alert(ver_master.unpack("C*"));//throw arguments.callee;//alert(mask_number);	while (i<8){		demerit_n1=0		ptn_temp=[]		bit= 1<< i		bit_r=(~bit) & 255		bit_mask=bit.chr().x(all_matrix)		hor = this.string_bit_cal(hor_master,bit_mask,"and")		ver = this.string_bit_cal(ver_master,bit_mask,"and")		ver_and = this.string_bit_cal(			(((170).chr() .x(max_modules_1side)) + ver),			(ver + ((170).chr().x(max_modules_1side))),			"and"		)		ver_or =  this.string_bit_cal(			(((170).chr() .x(max_modules_1side)) + ver),			(ver + ((170).chr() .x(max_modules_1side))),			"or"		)		hor= this.string_bit_not(hor)		ver= this.string_bit_not(ver)		ver_and = this.string_bit_not(ver_and)		ver_or  = this.string_bit_not(ver_or)		ver_and[all_matrix,0] = (170).chr()		ver_or[all_matrix,0] = (170).chr()		k = max_modules_1side - 1		while (k>=0){		   hor[k * max_modules_1side,0] = (170).chr()		   ver[k * max_modules_1side,0] = (170).chr()		   ver_and[k * max_modules_1side,0] = (170).chr()		   ver_or[k * max_modules_1side,0] = (170).chr()		   k-=1		}		hor=hor + (170).chr() + ver		n1_search=((255).chr() * 5)+"+|"+(bit_r.chr() * 5) + "+"		n2_search1=bit_r.chr() + bit_r.chr() + "+"		n2_search2=(255).chr() + (255).chr() + "+"		n3_search=bit_r.chr() + (255).chr() + bit_r.chr() + bit_r.chr() + bit_r.chr() + (255).chr() + bit_r.chr()		n4_search=bit_r.chr()		hor_temp=hor		demerit_n3 = (hor_temp.scan(Regexp.compile(n3_search)).length)*40//alert("n4 " + n4_search.unpack("C*"));		demerit_n4 = ((((ver.count(n4_search)*100) / byte_num)-50)/5).abs().to_i() * 10		demerit_n2=0		ptn_temp=ver_and.scan(Regexp.compile(n2_search1))		ptn_temp.each(function(te){			demerit_n2 += (te.length-1)		})		ptn_temp=ver_or.scan(Regexp.compile(n2_search2))		ptn_temp.each(function(te){			demerit_n2 += (te.length-1)		})		demerit_n2*=3		ptn_temp=hor.scan(Regexp.compile(n1_search))		ptn_temp.each(function(te){			demerit_n1 += (te.length-2)		})		demerit_score=demerit_n1+demerit_n2+demerit_n3+demerit_n4		if (demerit_score<=min_demerit_score || i==0) {			mask_number=i			min_demerit_score=demerit_score		}	i += 1	}	mask_content=1 << mask_number// --- format information	format_information_value = ((ec << 3) | mask_number)	format_information_array = [		"101010000010010","101000100100101",		"101111001111100","101101101001011","100010111111001","100000011001110",		"100111110010111","100101010100000","111011111000100","111001011110011",		"111110110101010","111100010011101","110011000101111","110001100011000",		"110110001000001","110100101110110","001011010001001","001001110111110",		"001110011100111","001100111010000","000011101100010","000001001010101",		"000110100001100","000100000111011","011010101011111","011000001101000",		"011111100110001","011101000000110","010010010110100","010000110000011",		"010111011011010","010101111101101"	]	i=0	while (i<15){		content=format_information_array[format_information_value][i,1].to_i()		matrix_content[format_information_x1[i]][format_information_y1[i]]=content * 255		matrix_content[format_information_x2[i]][format_information_y2[i]]=content * 255		i += 1	}	out=""	mxe=max_modules_1side	i=0	while (i<mxe){		j=0		while (j<mxe){			if ((matrix_content[j][i].to_i() & mask_content)!=0) {				out += "1"			} else { 				out += "0"			}			j += 1		}		out += "\n"		i += 1	}	out=this.string_bit_cal (out,frame_data ,"or")	return (out)}});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -