コード例 #1
0
ファイル: msrle.cpp プロジェクト: 86400/scummvm
const Graphics::Surface *MSRLEDecoder::decodeFrame(Common::SeekableReadStream &stream) {
	if (_bitsPerPixel == 8) {
		decode8(stream);
	} else
		error("Unhandled %d bit Microsoft RLE encoding", _bitsPerPixel);

	return _surface;
}
コード例 #2
0
int sysUncrypt(char* src,int indexsrc,int len,int lensrc,unsigned int key,int alpha)
{
  if ((indexsrc<0)||(indexsrc+len>lensrc)||(len<=0)) return -1;
  return decode8(src+indexsrc,len,key,alpha);
}
コード例 #3
0
ファイル: ean.cpp プロジェクト: berak/opencv_smallfry
int sampleLine(const String &line, int y, String &code)
{
	double mean = 0;
	int i=0, x=0, w=line.size();
	// find quiet zones:
	Point sl = detail::quietZone(line, 0,   w/2,  1, mean );
	Point sr = detail::quietZone(line, w-1, w/2, -1, mean );
	int distance = sr.x - sl.x;
	if ( distance < 58 )
	{
		return 1; // too short
	}
	// try to sample a square wave from the grayscale data
	// between the quiet zones,
	// start at first black pixel
	bool last_state = true;
	vector<Point> pt(1,Point(0,0)); // pos,length, pos,length, ..
	for ( i = sl.x+1; i<sr.x; i++  )
	{
		// todo : proper nms
		bool state = (line[i] < mean);
		// toggle state:
		if ( state != last_state )
		{
			pt.push_back(Point(i, 1));
			last_state = state;
			continue;
		}
		// state unchanged, increase length of current section
		pt.back().y ++;
	}
	// ean13 has 95 bits and 58 state toggles,
	// ean8  has 67 bits and 42 state toggles.
	double siz = distance;
	if ( pt.size() == 58 )
	{
		siz /= 95.0; // ean13
	}
	else
	if ( pt.size() == 42 )
	{
		siz /= 67.0; // ean8
	}
	else
	{
		return 2; // no match to either ean8 or ean13
	}
	// scale pattern down to 1 pixel per bit:
	int sum = 0;
	double last = (sl.x+1);
	for( i=0; i<pt.size(); i++  )
	{
		double d = pt[i].x - last;
		last = pt[i].x;
		d = int( 0.5 + d/siz ); // floor ?
		sum += d;
		pt[i].y = d; // now holds bit count
	}
	if ( sum > 95 )
	{
		return 3; // too long
	}
	// make bitstring:
	bool bit = true;
	String bits = "";
	for( int i=0; i<pt.size(); i++ )
	{
		for( int j=0; j<pt[i].y; j++ )
		{
			bits += ( bit ? '1' : '0' );
			if ( bits.size() > 95 )
			{
				return 4; // still too long
			}
		}
		bit = ! bit;
	}
	bits += '1';
	if ( bits.size() == 67 )
		return decode8( bits, code );
	if ( bits.size() == 95 )
		return decode13( bits, code );
	return 4; // no match to either ean8 or ean13
}