3x3rgbavg.cpp

来自「barcode readers [ from Image]」· C++ 代码 · 共 100 行

CPP
100
字号
//
// 3x3RgbAVg
//   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 "3x3RgbAVg.h"

#include "Debug.h"
#include "Image.h"
#include "ImageSize.h"
#include "RGBIndex.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 C3x3RgbAvg* C3x3RgbAvg::NewL()
	{	
		return new (ELeave) C3x3RgbAvg();	
	}

	C3x3RgbAvg::~C3x3RgbAvg()
	{
	}

	C3x3RgbAvg::C3x3RgbAvg() : ibEmpty(true)
	{
	}

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

	void C3x3RgbAvg::PushL(CImage image)
	{
		image.LockLC();
		IRgbIndex rRGB(image);
		IImageSize rSize(image);
		int i = 0;
		for (; i<rSize.Height(); i++) {
			int j = 0;
			for (; j<rSize.Width(); j++) {
				TRgbVal c = B;
				for (; c <= R; c++) {
					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 += rRGB[k][l][c];
						}
					}
					rRGB[i][j][c] = (unsigned char) (sum/9);
				}
			}
		}
		CleanupStack::PopAndDestroy(); // unlock bitmaps
		iImage = image;
		CDebug::ShowImage(iImage);
		ibEmpty = false;
	}

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

};

⌨️ 快捷键说明

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