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

📄 3x3avg.cpp

📁 barcode readers [ from Image]
💻 CPP
字号:
//
// 3x3Avg
//   Averages the 9 pixels surrounding a central pixel.
//
// Copyright (C) 2003, 2006 by Jon A. Webb (Contact via GMail; username is jonawebb)
//
// This library is free software; you can redistribute it 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
//

//
#include "3x3Avg.h"

#include "Debug.h"
#include "GrayIndex.h"
#include "Image.h"
#include "ImageSize.h"

#include <e32std.h>
#include <fbs.h>

#define max(a,b) ((a)>(b)? (a) : (b))
#define min(a,b) ((a)<(b)? (a) : (b))

using namespace Core;

namespace Algorithm
{

	EXPORT_C C3x3Avg* C3x3Avg::NewL()
	{	
		return new (ELeave) C3x3Avg();	
	}

	C3x3Avg::~C3x3Avg()
	{
	}

	C3x3Avg::C3x3Avg() : ibEmpty(true)
	{
	}

	CImage C3x3Avg::FrontL() 
	{
		if (ibEmpty) {
			User::Leave(KErrGeneral);
			return CImage();
		} else {
			ibEmpty = true;
			return iImage;
		}
	}

	void C3x3Avg::PushL(CImage image)
	{
		image.LockLC();
		IGrayIndex rGray(image);
		IImageSize rSize(image);
		int i = 0;
		for (; i<rSize.Height(); i++) {
			int j = 0;
			for (; j<rSize.Width(); j++) {
				int sum = 0;
				int k = max(0, i-1);
				for (; k < min(rSize.Height(), i+2); k++) {
					int l = max(0, j-1);
					for (; l < min(rSize.Width(), j+2); l++) {
						sum += rGray[k][l];
					}
				}
				rGray[i][j] = (unsigned char) (sum/9);
			}
		}
		CleanupStack::PopAndDestroy(); // unlock bitmaps
		iImage = image;
		CDebug::ShowImage(iImage);
		ibEmpty = false;
	}

	bool C3x3Avg::Empty() const
	{
		return ibEmpty;
	}

};

⌨️ 快捷键说明

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