Toshihiro Shimizu 890ddd
#include <string></string>
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
#include <limits>	// std::numeric_limits</limits>
Toshihiro Shimizu 890ddd
#include <stdexcept> // std::domain_error()</stdexcept>
Toshihiro Shimizu 890ddd
#include <algorithm> // std::max(),std::rotate()</algorithm>
Toshihiro Shimizu 890ddd
#include "igs_resource_multithread.h"
Toshihiro Shimizu 890ddd
#include "igs_ifx_common.h"
Toshihiro Shimizu 890ddd
#include "igs_fog.h"
Toshihiro Shimizu 890ddd
#include "igs_attenuation_distribution.cpp"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{ //---------------------------------------------------------
Toshihiro Shimizu 890ddd
void sl_track_render_dark_(
Toshihiro Shimizu 890ddd
	double *in_out /* RorGorBorA元かつ結果値(0...1) */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double *alpha /* Alpha元値(0...1) */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int width /* 画像幅 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **lens /* lensの外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **track /* 参照画外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int *sizes /* lens及び参照scanline毎の長さ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int size /* lens及び参照scanline数 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double power = 1.0 /* 0無  0...1散暗  1強暗  1...2最強暗 */
Toshihiro Shimizu 890ddd
	)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < width; ++xx) { /* 画像のScanlineループ */
Toshihiro Shimizu 890ddd
		/* Alphaがないか、Alpha値ゼロより大きいと処理しRGB変化 */
Toshihiro Shimizu 890ddd
		if ((0 == alpha) || (0.0 < alpha[xx])) {
Toshihiro Shimizu 890ddd
			double total = 0.0;
Toshihiro Shimizu 890ddd
			for (int y2 = 0; y2 < size; ++y2) {
Toshihiro Shimizu 890ddd
				for (int x2 = 0; x2 < sizes[y2]; ++x2) {
Toshihiro Shimizu 890ddd
					if (track[y2][x2] < in_out[xx]) {
Toshihiro Shimizu 890ddd
						/* より暗いpixelにのみ暗さの影響を受ける */
Toshihiro Shimizu 890ddd
						total += lens[y2][x2] * track[y2][x2];
Toshihiro Shimizu 890ddd
					} else {
Toshihiro Shimizu 890ddd
						/* より明るいpixelから影響を受けないようにする */
Toshihiro Shimizu 890ddd
						total += lens[y2][x2] * in_out[xx];
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			/* !!!lensによる値の蓄積が0-1とならなければならない!!! */
Toshihiro Shimizu 890ddd
			/* 変化を、強弱を付けて、AlphaでMaskし、元値に加える */
Toshihiro Shimizu 890ddd
			total -= in_out[xx]; /* 変化を */
Toshihiro Shimizu 890ddd
			total *= power;		 /* 強弱を付けて */
Toshihiro Shimizu 890ddd
			if ((0 != alpha) && (alpha[xx] < 1.0)) {
Toshihiro Shimizu 890ddd
				total *= alpha[xx]; /* AlphaでMaskし */
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			total += in_out[xx]; /* 元値に加える */
Toshihiro Shimizu 890ddd
			/* 0-1にclampし保存 */
Toshihiro Shimizu 890ddd
			in_out[xx] = ((total < 0.0) ? 0.0 : ((1.0 < total) ? 1.0 : total));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		for (int y2 = 0; y2 < size; ++y2) {
Toshihiro Shimizu 890ddd
			if (0 < sizes[y2]) {
Toshihiro Shimizu 890ddd
				++track[y2];
Toshihiro Shimizu 890ddd
			} /* 次位置へずらしとく */
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
void sl_track_render_light_( // = fog = default
Toshihiro Shimizu 890ddd
	double *in_out			 /* RorGorBorA元かつ結果値(0...1) */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double *alpha /* Alpha元値(0...1) */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int width /* 画像幅 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **lens /* lensの外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **track /* 参照画外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int *sizes /* lens及び参照scanline毎の長さ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int size /* lens及び参照scanline数 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double power = 1.0 /* 0無  0...1散光  1強光  1...2最強光 */
Toshihiro Shimizu 890ddd
	)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < width; ++xx) { /* 画像のScanlineループ */
Toshihiro Shimizu 890ddd
		/* Alphaがないか、Alpha値ゼロより大きいと処理しRGB変化 */
Toshihiro Shimizu 890ddd
		if ((0 == alpha) || (0.0 < alpha[xx])) {
Toshihiro Shimizu 890ddd
			double total = 0.0;
Toshihiro Shimizu 890ddd
			for (int y2 = 0; y2 < size; ++y2) {
Toshihiro Shimizu 890ddd
				for (int x2 = 0; x2 < sizes[y2]; ++x2) {
Toshihiro Shimizu 890ddd
					if (in_out[xx] < track[y2][x2]) {
Toshihiro Shimizu 890ddd
						/* より明るいpixelにのみ明るさの影響を受ける */
Toshihiro Shimizu 890ddd
						total += lens[y2][x2] * track[y2][x2];
Toshihiro Shimizu 890ddd
					} else {
Toshihiro Shimizu 890ddd
						/* より暗いpixelから影響を受けないようにする */
Toshihiro Shimizu 890ddd
						total += lens[y2][x2] * in_out[xx];
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			/* !!!lensによる値の蓄積が0-1とならなければならない!!! */
Toshihiro Shimizu 890ddd
			/* 変化を、強弱を付けて、AlphaでMaskし、元値に加える */
Toshihiro Shimizu 890ddd
			total -= in_out[xx]; /* 変化を */
Toshihiro Shimizu 890ddd
			total *= power;		 /* 強弱を付けて */
Toshihiro Shimizu 890ddd
			if ((0 != alpha) && (alpha[xx] < 1.0)) {
Toshihiro Shimizu 890ddd
				total *= alpha[xx]; /* AlphaでMaskし */
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			total += in_out[xx]; /* 元値に加える */
Toshihiro Shimizu 890ddd
			/* 0-1にclampし保存 */
Toshihiro Shimizu 890ddd
			in_out[xx] = ((total < 0.0) ? 0.0 : ((1.0 < total) ? 1.0 : total));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		for (int y2 = 0; y2 < size; ++y2) {
Toshihiro Shimizu 890ddd
			if (0 < sizes[y2]) {
Toshihiro Shimizu 890ddd
				++track[y2];
Toshihiro Shimizu 890ddd
			} /* 次位置へずらしとく */
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
void sl_track_render_threshold_(
Toshihiro Shimizu 890ddd
	double *in_out /* RorGorBorA元かつ結果値(0...1) */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double *alpha /* Alpha元値(0...1) */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int width /* 画像幅 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **lens /* lensの外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **track /* 参照画外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **thres /* 影響画外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int *sizes /* lens及び参照scanline毎の長さ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int size /* lens及び参照scanline数 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double power = 1.0 /* 0無  0...1散光  1強光  1...2最強光 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double threshold_min = 0.0 /* 0Cut無 0...1部分 1.01全Cut */
Toshihiro Shimizu 890ddd
	)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < width; ++xx) { /* 画像のScanlineループ */
Toshihiro Shimizu 890ddd
		/* Alphaがないか、Alpha値ゼロより大きいと処理しRGB変化 */
Toshihiro Shimizu 890ddd
		if ((0 == alpha) || (0.0 < alpha[xx])) {
Toshihiro Shimizu 890ddd
			double total = 0.0;
Toshihiro Shimizu 890ddd
			for (int y2 = 0; y2 < size; ++y2) {
Toshihiro Shimizu 890ddd
				for (int x2 = 0; x2 < sizes[y2]; ++x2) {
Toshihiro Shimizu 890ddd
					if ((in_out[xx] < track[y2][x2]) &&
Toshihiro Shimizu 890ddd
						(threshold_min <= thres[y2][x2])) {
Toshihiro Shimizu 890ddd
						/* より明るいpixelにのみ明るさの影響を受ける */
Toshihiro Shimizu 890ddd
						total += lens[y2][x2] * track[y2][x2];
Toshihiro Shimizu 890ddd
					} else {
Toshihiro Shimizu 890ddd
						/* より暗いpixelから影響を受けないようにする */
Toshihiro Shimizu 890ddd
						total += lens[y2][x2] * in_out[xx];
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			/* !!!lensによる値の蓄積が0-1とならなければならない!!! */
Toshihiro Shimizu 890ddd
			/* 変化を、強弱を付けて、AlphaでMaskし、元値に加える */
Toshihiro Shimizu 890ddd
			total -= in_out[xx]; /* 変化を */
Toshihiro Shimizu 890ddd
			total *= power;		 /* 強弱を付けて */
Toshihiro Shimizu 890ddd
			if ((0 != alpha) && (alpha[xx] < 1.0)) {
Toshihiro Shimizu 890ddd
				total *= alpha[xx]; /* AlphaでMaskし */
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			total += in_out[xx]; /* 元値に加える */
Toshihiro Shimizu 890ddd
			/* 0-1にclampし保存 */
Toshihiro Shimizu 890ddd
			in_out[xx] = ((total < 0.0) ? 0.0 : ((1.0 < total) ? 1.0 : total));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		for (int y2 = 0; y2 < size; ++y2) {
Toshihiro Shimizu 890ddd
			if (0 < sizes[y2]) {
Toshihiro Shimizu 890ddd
				++track[y2]; /* 次の画像位置へずらしとく */
Toshihiro Shimizu 890ddd
				++thres[y2]; /* 次の画像位置へずらしとく */
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
void sl_track_render_thrminmax_(
Toshihiro Shimizu 890ddd
	double *in_out /* RorGorBorA元かつ結果値(0...1) */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double *alpha /* Alpha元値(0...1) */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int width /* 画像幅 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **lens /* lensの外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **track /* 参照画外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double **thres /* 影響画外周の左開始位置ポインタ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int *sizes /* lens及び参照scanline毎の長さ配列 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int size /* lens及び参照scanline数 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double power = 1.0 /* 0無  0...1散光  1強光  1...2最強光 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double threshold_min = 0.0 /* 0Cut無 0...1部分 1.01全Cut */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double threshold_max = 0.0 /* 0Cut無 0...1部分 1.01全Cut */
Toshihiro Shimizu 890ddd
	)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const double thr_range = threshold_max - threshold_min;
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < width; ++xx) { /* 画像のScanlineループ */
Toshihiro Shimizu 890ddd
		/* Alphaがないか、Alpha値ゼロより大きいと処理しRGB変化 */
Toshihiro Shimizu 890ddd
		if ((0 == alpha) || (0.0 < alpha[xx])) {
Toshihiro Shimizu 890ddd
			double total = 0.0;
Toshihiro Shimizu 890ddd
			for (int y2 = 0; y2 < size; ++y2) {
Toshihiro Shimizu 890ddd
				for (int x2 = 0; x2 < sizes[y2]; ++x2) {
Toshihiro Shimizu 890ddd
					if ((in_out[xx] < track[y2][x2]) &&
Toshihiro Shimizu 890ddd
						(threshold_min <= thres[y2][x2])) {
Toshihiro Shimizu 890ddd
						/* より明るくかつminより大きい値のpixelにのみ
Toshihiro Shimizu 890ddd
			明るさの影響を受ける */
Toshihiro Shimizu 890ddd
						if (thres[y2][x2] < threshold_max) {
Toshihiro Shimizu 890ddd
							/* maxよりは小さい値のpixelは比で影響する */
Toshihiro Shimizu 890ddd
							total += lens[y2][x2] * (in_out[xx] +
Toshihiro Shimizu 890ddd
													 (track[y2][x2] - in_out[xx]) *
Toshihiro Shimizu 890ddd
														 (thres[y2][x2] - threshold_min) / thr_range);
Toshihiro Shimizu 890ddd
						} else {
Toshihiro Shimizu 890ddd
							/* maxより大きい値のpixelは明るさ影響を受ける */
Toshihiro Shimizu 890ddd
							total += lens[y2][x2] * track[y2][x2];
Toshihiro Shimizu 890ddd
						}
Toshihiro Shimizu 890ddd
					} else {
Toshihiro Shimizu 890ddd
						/* より暗いか、minより小さい値のpixelから
Toshihiro Shimizu 890ddd
			影響を受けないようにする */
Toshihiro Shimizu 890ddd
						total += lens[y2][x2] * in_out[xx];
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			/* !!!lensによる値の蓄積が0-1とならなければならない!!! */
Toshihiro Shimizu 890ddd
			/* 変化を、強弱を付けて、AlphaでMaskし、元値に加える */
Toshihiro Shimizu 890ddd
			total -= in_out[xx]; /* 変化を */
Toshihiro Shimizu 890ddd
			total *= power;		 /* 強弱を付けて */
Toshihiro Shimizu 890ddd
			if ((0 != alpha) && (alpha[xx] < 1.0)) {
Toshihiro Shimizu 890ddd
				total *= alpha[xx]; /* AlphaでMaskし */
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			total += in_out[xx]; /* 元値に加える */
Toshihiro Shimizu 890ddd
			/* 0-1にclampし保存 */
Toshihiro Shimizu 890ddd
			in_out[xx] = ((total < 0.0) ? 0.0 : ((1.0 < total) ? 1.0 : total));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		for (int y2 = 0; y2 < size; ++y2) {
Toshihiro Shimizu 890ddd
			if (0 < sizes[y2]) {
Toshihiro Shimizu 890ddd
				++track[y2]; /* 次の画像位置へずらしとく */
Toshihiro Shimizu 890ddd
				++thres[y2]; /* 次の画像位置へずらしとく */
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{ //---------------------------------------------------------
Toshihiro Shimizu 890ddd
void sl_track_resize_(
Toshihiro Shimizu 890ddd
	const int odd_diameter, const int width, std::vector<std::vector<double>> &pixe_tracks, const bool thr_sw, std::vector<std::vector<double>> &thre_tracks, std::vector<double *=""> &pixe_starts, std::vector<double *=""> &thre_starts, std::vector<double> &result, std::vector<double> &alpha_ref)</double></double></double></double></std::vector<double></std::vector<double>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	pixe_tracks.resize(odd_diameter);
Toshihiro Shimizu 890ddd
	for (int yy = 0; yy < odd_diameter; ++yy) {
Toshihiro Shimizu 890ddd
		pixe_tracks.at(yy).resize(width + odd_diameter - 1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (thr_sw) {
Toshihiro Shimizu 890ddd
		thre_tracks.resize(odd_diameter);
Toshihiro Shimizu 890ddd
		for (int yy = 0; yy < odd_diameter; ++yy) {
Toshihiro Shimizu 890ddd
			thre_tracks.at(yy).resize(width + odd_diameter - 1);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	pixe_starts.resize(odd_diameter);
Toshihiro Shimizu 890ddd
	thre_starts.resize(odd_diameter);
Toshihiro Shimizu 890ddd
	result.resize(width);
Toshihiro Shimizu 890ddd
	alpha_ref.clear(); /* 今はクリア!!!あとで使うとき確保!!! */
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
void sl_track_render_(
Toshihiro Shimizu 890ddd
	//std::vector< std::vector<double> >&lens_matrix</double>
Toshihiro Shimizu 890ddd
	std::vector<int> &lens_offsets, std::vector<double *=""> &lens_starts, std::vector<int> &lens_sizes</int></double></int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	std::vector<std::vector<double>> &pixe_tracks, std::vector<std::vector<double>> &thre_tracks, const std::vector<double> &alpha_ref, std::vector<double> &result, std::vector<double *=""> &pixe_starts, std::vector<double *=""> &thre_starts</double></double></double></double></std::vector<double></std::vector<double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double power, const double threshold_min, const double threshold_max)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*--- scanline初期位置 ---*/
Toshihiro Shimizu 890ddd
	for (unsigned int yy = 0; yy < pixe_starts.size(); ++yy) {
Toshihiro Shimizu 890ddd
		if (lens_offsets.at(yy) < 0) {
Toshihiro Shimizu 890ddd
			pixe_starts.at(yy) = 0;
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			pixe_starts.at(yy) =
Toshihiro Shimizu 890ddd
				&pixe_tracks.at(yy).at(lens_offsets.at(yy));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (0 < thre_tracks.size()) {
Toshihiro Shimizu 890ddd
		for (unsigned int yy = 0; yy < thre_starts.size(); ++yy) {
Toshihiro Shimizu 890ddd
			if (lens_offsets.at(yy) < 0) {
Toshihiro Shimizu 890ddd
				thre_starts.at(yy) = 0;
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				thre_starts.at(yy) =
Toshihiro Shimizu 890ddd
					&thre_tracks.at(yy).at(lens_offsets.at(yy));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- 自分より暗いpixelから収光 ---*/
Toshihiro Shimizu 890ddd
	if (power < 0.0) {
Toshihiro Shimizu 890ddd
		sl_track_render_dark_(
Toshihiro Shimizu 890ddd
			&result.at(0), ((0 < alpha_ref.size()) ? &alpha_ref.at(0) : 0), static_cast<int>(result.size())</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																				,
Toshihiro Shimizu 890ddd
			&lens_starts.at(0), &pixe_starts.at(0), &lens_sizes.at(0), static_cast<int>(lens_sizes.size())</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																		   ,
Toshihiro Shimizu 890ddd
			-power);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- 自分より明るいpixelから収光し光量によってfogが変化 ---*/
Toshihiro Shimizu 890ddd
	if ((0.0 < threshold_min) || (0.0 < threshold_max)) {
Toshihiro Shimizu 890ddd
		if (threshold_min < threshold_max) {
Toshihiro Shimizu 890ddd
			sl_track_render_thrminmax_(
Toshihiro Shimizu 890ddd
				&result.at(0), ((0 < alpha_ref.size()) ? &alpha_ref.at(0) : 0), static_cast<int>(result.size())</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																					,
Toshihiro Shimizu 890ddd
				&lens_starts.at(0), &pixe_starts.at(0), &thre_starts.at(0), &lens_sizes.at(0), static_cast<int>(lens_sizes.size())</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																								   ,
Toshihiro Shimizu 890ddd
				power, threshold_min, threshold_max);
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			/*--- 自分より明るいpixelから収光し、
Toshihiro Shimizu 890ddd
		ある光量以上からいきなりfogがかかる ---*/
Toshihiro Shimizu 890ddd
			sl_track_render_threshold_(
Toshihiro Shimizu 890ddd
				&result.at(0), ((0 < alpha_ref.size()) ? &alpha_ref.at(0) : 0), static_cast<int>(result.size())</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																					,
Toshihiro Shimizu 890ddd
				&lens_starts.at(0), &pixe_starts.at(0), &thre_starts.at(0), &lens_sizes.at(0), static_cast<int>(lens_sizes.size())</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																								   ,
Toshihiro Shimizu 890ddd
				power, threshold_min);
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- 自分より明るいpixelから収光 ---*/
Toshihiro Shimizu 890ddd
	sl_track_render_light_(
Toshihiro Shimizu 890ddd
		&result.at(0), ((0 < alpha_ref.size()) ? &alpha_ref.at(0) : 0), static_cast<int>(result.size())</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																			,
Toshihiro Shimizu 890ddd
		&lens_starts.at(0), &pixe_starts.at(0), &lens_sizes.at(0), static_cast<int>(lens_sizes.size())</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																	   ,
Toshihiro Shimizu 890ddd
		power);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
void sl_track_shift_(
Toshihiro Shimizu 890ddd
	std::vector<std::vector<double>> &pixe_tracks, std::vector<std::vector<double>> &thre_tracks)</std::vector<double></std::vector<double>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::rotate(pixe_tracks.begin(), pixe_tracks.end() - 1, pixe_tracks.end());
Toshihiro Shimizu 890ddd
	if (0 < thre_tracks.size()) {
Toshihiro Shimizu 890ddd
		std::rotate(thre_tracks.begin(), thre_tracks.end() - 1, thre_tracks.end());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
void sl_track_clear_(
Toshihiro Shimizu 890ddd
	std::vector<std::vector<double>> &pixe_tracks, std::vector<std::vector<double>> &thre_tracks, std::vector<double *=""> &pixe_starts, std::vector<double *=""> &thre_starts, std::vector<double> &result, std::vector<double> &alpha_ref)</double></double></double></double></std::vector<double></std::vector<double>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!alpha_ref.empty()) {
Toshihiro Shimizu 890ddd
		alpha_ref.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!result.empty()) {
Toshihiro Shimizu 890ddd
		result.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!thre_starts.empty()) {
Toshihiro Shimizu 890ddd
		thre_starts.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!pixe_starts.empty()) {
Toshihiro Shimizu 890ddd
		pixe_starts.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!thre_tracks.empty()) {
Toshihiro Shimizu 890ddd
		thre_tracks.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!pixe_tracks.empty()) {
Toshihiro Shimizu 890ddd
		pixe_tracks.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{ //--------------------------------------------------------
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void rgb_to_lightness_image_(
Toshihiro Shimizu 890ddd
	const T *image,
Toshihiro Shimizu 890ddd
	const int height,
Toshihiro Shimizu 890ddd
	const int width,
Toshihiro Shimizu 890ddd
	const int channels,
Toshihiro Shimizu 890ddd
	double *lightness)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const double val_max = static_cast<double>(</double>
Toshihiro Shimizu 890ddd
		std::numeric_limits<t>::max());</t>
Toshihiro Shimizu 890ddd
	for (int yy = 0; yy < height; ++yy) {
Toshihiro Shimizu 890ddd
		for (int xx = 0; xx < width; ++xx, image += channels, ++lightness) {
Toshihiro Shimizu 890ddd
			if (1 == channels) {
Toshihiro Shimizu 890ddd
				*lightness = static_cast<double>(image[0]) / val_max;</double>
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				const double red = static_cast<double>(image[0]) / val_max;</double>
Toshihiro Shimizu 890ddd
				const double gre = static_cast<double>(image[1]) / val_max;</double>
Toshihiro Shimizu 890ddd
				const double blu = static_cast<double>(image[2]) / val_max;</double>
Toshihiro Shimizu 890ddd
				/* rgb --> hls のl(明度(lightness))のみの計算 */
Toshihiro Shimizu 890ddd
				*lightness = (std::max(std::max(red, gre), blu) +
Toshihiro Shimizu 890ddd
							  std::min(std::min(red, gre), blu)) /
Toshihiro Shimizu 890ddd
							 2.0;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{ //--------------------------------------------------------
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
	画像配列の高さ位置を、実際の範囲内にclampし、scanlineの先頭を返す
Toshihiro Shimizu 890ddd
	TP is 'unsigned char *' or 'unsigned short *'
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
template <class tp=""></class>
Toshihiro Shimizu 890ddd
TP sl_top_clamped_in_h_(
Toshihiro Shimizu 890ddd
	TP sl, const int height, const int width, const int channels, const int yy)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (height <= yy) {
Toshihiro Shimizu 890ddd
		return sl + (channels * width * (height - 1));
Toshihiro Shimizu 890ddd
	} else if (yy < 0) {
Toshihiro Shimizu 890ddd
		return sl;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return sl + (channels * width * yy);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
	trackの左右の余白を画像の端の色で塗りつぶす
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void paint_margin_(
Toshihiro Shimizu 890ddd
	const int width, const int margin, std::vector<t> &track)</t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (width <= (margin * 2)) {
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	} /* 余白太すぎ */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < margin; ++xx) {
Toshihiro Shimizu 890ddd
		track.at(xx) = track.at(margin); /* 始点側の余白を塗る */
Toshihiro Shimizu 890ddd
		track.at(track.size() - 1 - xx) =
Toshihiro Shimizu 890ddd
			track.at(track.size() - margin - 1); /* 終端側の余白を塗る */
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{ //--------------------------------------------------------
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
	T is 'unsigned char' or 'unsigned short'
Toshihiro Shimizu 890ddd
	alphaは先に処理して結果(out_image_array)に入れ、
Toshihiro Shimizu 890ddd
		その後rgbのために参照する
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void get_first_sl_ch_(
Toshihiro Shimizu 890ddd
	const T *in_image_array, const T *out_image_array /* 処理結果alpha値の参照のため必要 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double *ref_thres_array /* threshold値の参照のため必要 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int hh, const int ww, const int ch, const int yy, const int zz, const int margin, std::vector<std::vector<double>> &pixe_tracks, std::vector<std::vector<double>> &thre_tracks, std::vector<double> &result, std::vector<double> &alpha_ref)</double></double></std::vector<double></std::vector<double>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const double val_max = static_cast<double>(</double>
Toshihiro Shimizu 890ddd
		std::numeric_limits<t>::max());</t>
Toshihiro Shimizu 890ddd
	/*--- 入力画像を(マージン含めた1scanline分)得る ---*/
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		int yp = -margin + yy;
Toshihiro Shimizu 890ddd
		int ii = margin * 2;
Toshihiro Shimizu 890ddd
		for (; yp <= margin + yy; ++yp, --ii) {
Toshihiro Shimizu 890ddd
			const T *
Toshihiro Shimizu 890ddd
				ss = sl_top_clamped_in_h_(in_image_array, hh, ww, ch, yp) + zz;
Toshihiro Shimizu 890ddd
			std::vector<double> &track = pixe_tracks.at(ii);</double>
Toshihiro Shimizu 890ddd
			for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
				track.at(margin + xx) =
Toshihiro Shimizu 890ddd
					static_cast<double>(ss[xx * ch]) / val_max;</double>
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			paint_margin_(ww, margin, track);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- (閾値として)参照する画像を(マージン含めた1scanline分)得る -*/
Toshihiro Shimizu 890ddd
	if ((0 != ref_thres_array) && (0 < thre_tracks.size())) {
Toshihiro Shimizu 890ddd
		int yp = -margin + yy;
Toshihiro Shimizu 890ddd
		int ii = margin * 2;
Toshihiro Shimizu 890ddd
		for (; yp <= margin + yy; ++yp, --ii) {
Toshihiro Shimizu 890ddd
			const double *
Toshihiro Shimizu 890ddd
				ss = sl_top_clamped_in_h_(ref_thres_array, hh, ww, 1, yp);
Toshihiro Shimizu 890ddd
			std::vector<double> &track = thre_tracks.at(ii);</double>
Toshihiro Shimizu 890ddd
			for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
				track.at(margin + xx) = ss[xx * 1];
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			paint_margin_(ww, margin, track);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- 入力画像を保存画像エリアに1scanline分入れる ---*/
Toshihiro Shimizu 890ddd
	const T *
Toshihiro Shimizu 890ddd
		ss = sl_top_clamped_in_h_(in_image_array, hh, ww, ch, yy) + zz;
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
		result.at(xx) = static_cast<double>(ss[xx * ch]) / val_max;</double>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- 処理結果としてのalpha画像エリアを1scanline分入れる ---*/
Toshihiro Shimizu 890ddd
	if ((alpha_ref.size() <= 0) || (ch < 4)) {
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	const T *
Toshihiro Shimizu 890ddd
		dd = sl_top_clamped_in_h_(out_image_array, hh, ww, ch, yy) + 3;
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
		alpha_ref.at(xx) = static_cast<double>(dd[xx * ch]) / val_max;</double>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void get_next_sl_ch_(
Toshihiro Shimizu 890ddd
	const T *in_image_array, const T *out_image_array /* 処理結果alpha値の参照のため必要 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double *ref_thres_array /* threshold値の参照のため必要 */
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int hh, const int ww, const int ch, const int yy, const int zz, const int margin, std::vector<std::vector<double>> &pixe_tracks, std::vector<std::vector<double>> &thre_tracks, std::vector<double> &result, std::vector<double> &alpha_ref)</double></double></std::vector<double></std::vector<double>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const double val_max = static_cast<double>(</double>
Toshihiro Shimizu 890ddd
		std::numeric_limits<t>::max());</t>
Toshihiro Shimizu 890ddd
	/*--- 入力画像を(1scanline分)得る ---*/
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		const T *
Toshihiro Shimizu 890ddd
			mm = sl_top_clamped_in_h_(in_image_array, hh, ww, ch, yy + margin) + zz;
Toshihiro Shimizu 890ddd
		std::vector<double> &track = pixe_tracks.at(0);</double>
Toshihiro Shimizu 890ddd
		for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
			track.at(margin + xx) =
Toshihiro Shimizu 890ddd
				static_cast<double>(mm[xx * ch]) / val_max;</double>
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		paint_margin_(ww, margin, track);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- (閾値として)参照する画像を(1scanline分)得る --*/
Toshihiro Shimizu 890ddd
	if ((0 != ref_thres_array) && (0 < thre_tracks.size())) {
Toshihiro Shimizu 890ddd
		const double *
Toshihiro Shimizu 890ddd
			mm = sl_top_clamped_in_h_(ref_thres_array, hh, ww, 1, yy + margin);
Toshihiro Shimizu 890ddd
		std::vector<double> &track = thre_tracks.at(0);</double>
Toshihiro Shimizu 890ddd
		for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
			track.at(margin + xx) = mm[xx * 1];
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		paint_margin_(ww, margin, track);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- 入力画像を保存画像エリアに1scanline分入れる ---*/
Toshihiro Shimizu 890ddd
	const T *
Toshihiro Shimizu 890ddd
		ss = sl_top_clamped_in_h_(in_image_array, hh, ww, ch, yy) + zz;
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
		result.at(xx) = static_cast<double>(ss[xx * ch]) / val_max;</double>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- 処理結果としてのalpha画像エリアを1scanline分入れる ---*/
Toshihiro Shimizu 890ddd
	if ((alpha_ref.size() <= 0) || (ch < 4)) {
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	const T *
Toshihiro Shimizu 890ddd
		dd = sl_top_clamped_in_h_(out_image_array, hh, ww, ch, yy) + 3;
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
		alpha_ref.at(xx) = static_cast<double>(dd[xx * ch]) / val_max;</double>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
template <class tp=""></class>
Toshihiro Shimizu 890ddd
void copy_sl_ch_(
Toshihiro Shimizu 890ddd
	const TP in_image_array, TP out_image_array, const int hh, const int ww, const int ch, const int yy, const int zz)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const TP ss = sl_top_clamped_in_h_(in_image_array, hh, ww, ch, yy) + zz;
Toshihiro Shimizu 890ddd
	TP dd = sl_top_clamped_in_h_(out_image_array, hh, ww, ch, yy) + zz;
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
		dd[ch * xx] = ss[ch * xx];
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void put_sl_ch_(
Toshihiro Shimizu 890ddd
	std::vector<double> &result, const int hh, const int ww, const int ch, const int yy, const int zz, T *out_image_array)</double>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const double val_max = static_cast<double>(</double>
Toshihiro Shimizu 890ddd
		std::numeric_limits<t>::max());</t>
Toshihiro Shimizu 890ddd
	T *dd = sl_top_clamped_in_h_(out_image_array, hh, ww, ch, yy) + zz;
Toshihiro Shimizu 890ddd
	for (int xx = 0; xx < ww; ++xx) {
Toshihiro Shimizu 890ddd
		dd[ch * xx] =
Toshihiro Shimizu 890ddd
			static_cast<t>(result.at(xx) * (val_max + 0.999999));</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{ //--------------------------------------------------------
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class one_thread_ : public igs::resource::thread_execute_interface
Toshihiro Shimizu 890ddd
{ /* thread単位の実行設定 */
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	one_thread_() {}
Toshihiro Shimizu 890ddd
	void setup(
Toshihiro Shimizu 890ddd
		T in_image, T out_image, double *ref_thresh
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const int height, const int width, const int channels
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const int y_begin, const int y_end
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// , std::vector< std::vector<double> > *lens_matrix_p</double>
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		std::vector<int> *lens_offsets_p, std::vector<double *=""> *lens_starts_p, std::vector<int> *lens_sizes_p</int></double></int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const double power, const double threshold_min, const double threshold_max, const bool alpha_rendering_sw)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		this->in_image_ = in_image;
Toshihiro Shimizu 890ddd
		this->out_image_ = out_image;
Toshihiro Shimizu 890ddd
		this->ref_thresh_ = ref_thresh;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		this->height_ = height;
Toshihiro Shimizu 890ddd
		this->width_ = width;
Toshihiro Shimizu 890ddd
		this->channels_ = channels;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		this->y_begin_ = y_begin;
Toshihiro Shimizu 890ddd
		this->y_end_ = y_end;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// this->lens_matrix_p_ = lens_matrix_p;
Toshihiro Shimizu 890ddd
		this->lens_offsets_p_ = lens_offsets_p;
Toshihiro Shimizu 890ddd
		this->lens_starts_p_ = lens_starts_p;
Toshihiro Shimizu 890ddd
		this->lens_sizes_p_ = lens_sizes_p;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		this->power_ = power;
Toshihiro Shimizu 890ddd
		this->threshold_min_ = threshold_min;
Toshihiro Shimizu 890ddd
		this->threshold_max_ = threshold_max;
Toshihiro Shimizu 890ddd
		this->alpha_rendering_sw_ = alpha_rendering_sw;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		sl_track_resize_(
Toshihiro Shimizu 890ddd
			static_cast<int>(this->lens_offsets_p_->size()), this->width_, this->pixe_tracks_, ((0 == ref_thresh) ? false : true), this->thre_tracks_, this->pixe_starts_, this->thre_starts_, this->result_, this->alpha_ref_);</int>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void run(void)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		bool rgb_rendering_sw = true;
Toshihiro Shimizu 890ddd
		bool alpha_rendering_sw = this->alpha_rendering_sw_;
Toshihiro Shimizu 890ddd
		if (this->pixe_tracks_.size() <= 1) {
Toshihiro Shimizu 890ddd
			rgb_rendering_sw = false;
Toshihiro Shimizu 890ddd
			alpha_rendering_sw = false;
Toshihiro Shimizu 890ddd
		} // not render,then copy
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/* first scanline-->next scanlineで処理するので
Toshihiro Shimizu 890ddd
	かならすchannel毎にまとめてループする */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int yy;
Toshihiro Shimizu 890ddd
		if (igs::image::rgba::siz == this->channels_) {
Toshihiro Shimizu 890ddd
			using namespace igs::image::rgba;
Toshihiro Shimizu 890ddd
			for (yy = this->y_begin_; yy <= this->y_end_; ++yy) {
Toshihiro Shimizu 890ddd
				this->rendering_sl_ch_(yy, alp, alpha_rendering_sw);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			/* alpha処理後にalpha参照用設定をする */
Toshihiro Shimizu 890ddd
			this->alpha_ref_.resize(this->width_);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			for (yy = this->y_begin_; yy <= this->y_end_; ++yy) {
Toshihiro Shimizu 890ddd
				this->rendering_sl_ch_(yy, blu, rgb_rendering_sw);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			for (yy = this->y_begin_; yy <= this->y_end_; ++yy) {
Toshihiro Shimizu 890ddd
				this->rendering_sl_ch_(yy, gre, rgb_rendering_sw);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			for (yy = this->y_begin_; yy <= this->y_end_; ++yy) {
Toshihiro Shimizu 890ddd
				this->rendering_sl_ch_(yy, red, rgb_rendering_sw);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else if (igs::image::rgb::siz == this->channels_) {
Toshihiro Shimizu 890ddd
			using namespace igs::image::rgb;
Toshihiro Shimizu 890ddd
			for (yy = this->y_begin_; yy <= this->y_end_; ++yy) {
Toshihiro Shimizu 890ddd
				this->rendering_sl_ch_(yy, blu, rgb_rendering_sw);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			for (yy = this->y_begin_; yy <= this->y_end_; ++yy) {
Toshihiro Shimizu 890ddd
				this->rendering_sl_ch_(yy, gre, rgb_rendering_sw);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			for (yy = this->y_begin_; yy <= this->y_end_; ++yy) {
Toshihiro Shimizu 890ddd
				this->rendering_sl_ch_(yy, red, rgb_rendering_sw);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else if (1 == this->channels_) { /* grayscale */
Toshihiro Shimizu 890ddd
			for (yy = this->y_begin_; yy <= this->y_end_; ++yy) {
Toshihiro Shimizu 890ddd
				this->rendering_sl_ch_(yy, 0, rgb_rendering_sw);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void clear(void)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		sl_track_clear_(
Toshihiro Shimizu 890ddd
			this->pixe_tracks_, this->thre_tracks_, this->pixe_starts_, this->thre_starts_, this->result_, this->alpha_ref_);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	T in_image_;
Toshihiro Shimizu 890ddd
	T out_image_;
Toshihiro Shimizu 890ddd
	double *ref_thresh_;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int height_;
Toshihiro Shimizu 890ddd
	int width_;
Toshihiro Shimizu 890ddd
	int channels_;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int y_begin_;
Toshihiro Shimizu 890ddd
	int y_end_;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// std::vector< std::vector<double> > *lens_matrix_p_;</double>
Toshihiro Shimizu 890ddd
	std::vector<int> *lens_offsets_p_;</int>
Toshihiro Shimizu 890ddd
	std::vector<double *=""> *lens_starts_p_;</double>
Toshihiro Shimizu 890ddd
	std::vector<int> *lens_sizes_p_;</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double power_;
Toshihiro Shimizu 890ddd
	double threshold_min_;
Toshihiro Shimizu 890ddd
	double threshold_max_;
Toshihiro Shimizu 890ddd
	bool alpha_rendering_sw_;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<std::vector<double>> pixe_tracks_;</std::vector<double>
Toshihiro Shimizu 890ddd
	std::vector<std::vector<double>> thre_tracks_;</std::vector<double>
Toshihiro Shimizu 890ddd
	std::vector<double *=""> pixe_starts_;</double>
Toshihiro Shimizu 890ddd
	std::vector<double *=""> thre_starts_;</double>
Toshihiro Shimizu 890ddd
	std::vector<double> result_;</double>
Toshihiro Shimizu 890ddd
	std::vector<double> alpha_ref_;</double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void rendering_sl_ch_(int yy, int zz, bool rendering_sw)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!rendering_sw) {
Toshihiro Shimizu 890ddd
			copy_sl_ch_(
Toshihiro Shimizu 890ddd
				this->in_image_,
Toshihiro Shimizu 890ddd
				this->out_image_,
Toshihiro Shimizu 890ddd
				this->height_,
Toshihiro Shimizu 890ddd
				this->width_,
Toshihiro Shimizu 890ddd
				this->channels_,
Toshihiro Shimizu 890ddd
				yy, zz);
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (yy == this->y_begin_) {
Toshihiro Shimizu 890ddd
			get_first_sl_ch_(
Toshihiro Shimizu 890ddd
				this->in_image_,
Toshihiro Shimizu 890ddd
				this->out_image_,
Toshihiro Shimizu 890ddd
				this->ref_thresh_,
Toshihiro Shimizu 890ddd
				this->height_,
Toshihiro Shimizu 890ddd
				this->width_,
Toshihiro Shimizu 890ddd
				this->channels_,
Toshihiro Shimizu 890ddd
				yy, zz,
Toshihiro Shimizu 890ddd
				static_cast<int>(this->pixe_tracks_.size() / 2),</int>
Toshihiro Shimizu 890ddd
				this->pixe_tracks_,
Toshihiro Shimizu 890ddd
				this->thre_tracks_,
Toshihiro Shimizu 890ddd
				this->result_,
Toshihiro Shimizu 890ddd
				this->alpha_ref_);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			sl_track_shift_(
Toshihiro Shimizu 890ddd
				this->pixe_tracks_,
Toshihiro Shimizu 890ddd
				this->thre_tracks_);
Toshihiro Shimizu 890ddd
			get_next_sl_ch_(
Toshihiro Shimizu 890ddd
				this->in_image_,
Toshihiro Shimizu 890ddd
				this->out_image_,
Toshihiro Shimizu 890ddd
				this->ref_thresh_,
Toshihiro Shimizu 890ddd
				this->height_,
Toshihiro Shimizu 890ddd
				this->width_,
Toshihiro Shimizu 890ddd
				this->channels_,
Toshihiro Shimizu 890ddd
				yy, zz,
Toshihiro Shimizu 890ddd
				static_cast<int>(this->pixe_tracks_.size() / 2),</int>
Toshihiro Shimizu 890ddd
				this->pixe_tracks_,
Toshihiro Shimizu 890ddd
				this->thre_tracks_,
Toshihiro Shimizu 890ddd
				this->result_,
Toshihiro Shimizu 890ddd
				this->alpha_ref_);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		sl_track_render_(
Toshihiro Shimizu 890ddd
			//  *(this->lens_matrix_p_)
Toshihiro Shimizu 890ddd
			*(this->lens_offsets_p_), *(this->lens_starts_p_), *(this->lens_sizes_p_)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																   ,
Toshihiro Shimizu 890ddd
			this->pixe_tracks_, this->thre_tracks_, this->alpha_ref_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			,
Toshihiro Shimizu 890ddd
			this->result_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			,
Toshihiro Shimizu 890ddd
			this->pixe_starts_, this->thre_starts_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			,
Toshihiro Shimizu 890ddd
			this->power_, this->threshold_min_, this->threshold_max_);
Toshihiro Shimizu 890ddd
		put_sl_ch_(
Toshihiro Shimizu 890ddd
			this->result_,
Toshihiro Shimizu 890ddd
			this->height_,
Toshihiro Shimizu 890ddd
			this->width_,
Toshihiro Shimizu 890ddd
			this->channels_,
Toshihiro Shimizu 890ddd
			yy, zz,
Toshihiro Shimizu 890ddd
			this->out_image_);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{ //--------------------------------------------------------
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class multi_thread_
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	multi_thread_(
Toshihiro Shimizu 890ddd
		T in_image, T out_image, double *ref_thres, const int height, const int width, const int channels
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const int number_of_thread // 1 ... INT_MAX
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const double radius // 25.0(0...100(DOUBLE_MAX))
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const double curve // 1.00(0.01 ... 100)
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const int polygon_number // 2(2 ... 16(INT_MAX))
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const double degree // 0(0 ... DOUBLE_MAX)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const double power // 1.00(-2.00 ... 2.00)
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const double threshold_min // 0.00(0.00 ... 1.01)
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const double threshold_max // 0.00(0.00 ... 1.01)
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		const bool alpha_rendering_sw // false(true,false)
Toshihiro Shimizu 890ddd
		)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		/*--------------スレッド数の設定--------------------*/
Toshihiro Shimizu 890ddd
		int thread_num = number_of_thread;
Toshihiro Shimizu 890ddd
		if ((thread_num < 1) || (height < thread_num)) {
Toshihiro Shimizu 890ddd
			thread_num = 1;
Toshihiro Shimizu 890ddd
		} /* ゼロ以下か、高さより多い */
Toshihiro Shimizu 890ddd
		/*--------------メモリ確保--------------------------*/
Toshihiro Shimizu 890ddd
		int odd_diameter = 0;
Toshihiro Shimizu 890ddd
		attenuation_distribution_(
Toshihiro Shimizu 890ddd
			this->lens_matrix_, this->lens_offsets_, this->lens_starts_, this->lens_sizes_, odd_diameter, radius /* 直径(radiusの2倍)1以下ならエラーthrow */
Toshihiro Shimizu 890ddd
			,
Toshihiro Shimizu 890ddd
			curve /* curveがゼロならエラーthrow */
Toshihiro Shimizu 890ddd
			,
Toshihiro Shimizu 890ddd
			polygon_number, degree);
Toshihiro Shimizu 890ddd
		this->threads_.resize(thread_num);
Toshihiro Shimizu 890ddd
		/*-------スレッド毎の処理指定-----------------------*/
Toshihiro Shimizu 890ddd
		int h_sub = height / thread_num;
Toshihiro Shimizu 890ddd
		if (0 != (height % thread_num)) {
Toshihiro Shimizu 890ddd
			++h_sub; /* 割り切れないときは一つ増やす */
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		int yy = 0;
Toshihiro Shimizu 890ddd
		for (int ii = 0; ii < thread_num; ++ii, yy += h_sub) {
Toshihiro Shimizu 890ddd
			/*
Toshihiro Shimizu 890ddd
			5 h_scanline,4 thread --> h_count is 2
Toshihiro Shimizu 890ddd
			thread	1	2	3	4
Toshihiro Shimizu 890ddd
			h_count	2	2	1	0
Toshihiro Shimizu 890ddd
			*/
Toshihiro Shimizu 890ddd
			if (height < (yy + h_sub)) {
Toshihiro Shimizu 890ddd
				h_sub = height - yy;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			this->threads_.at(ii).setup(
Toshihiro Shimizu 890ddd
				in_image, out_image, ref_thres
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				,
Toshihiro Shimizu 890ddd
				height, width, channels
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				,
Toshihiro Shimizu 890ddd
				yy, yy + h_sub - 1
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				// , &(this->lens_matrix_)
Toshihiro Shimizu 890ddd
				,
Toshihiro Shimizu 890ddd
				&(this->lens_offsets_), &(this->lens_starts_), &(this->lens_sizes_)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
																   ,
Toshihiro Shimizu 890ddd
				power, threshold_min, threshold_max, alpha_rendering_sw);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		/*------スレッド毎のスレッド指定------*/
Toshihiro Shimizu 890ddd
		for (int ii = 0; ii < thread_num; ++ii) {
Toshihiro Shimizu 890ddd
			this->mthread_.add(&(this->threads_.at(ii)));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void run(void)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		this->mthread_.run();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void clear()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		this->mthread_.clear();
Toshihiro Shimizu 890ddd
		this->threads_.clear();
Toshihiro Shimizu 890ddd
		this->lens_sizes_.clear();
Toshihiro Shimizu 890ddd
		this->lens_starts_.clear();
Toshihiro Shimizu 890ddd
		this->lens_offsets_.clear();
Toshihiro Shimizu 890ddd
		this->lens_matrix_.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	std::vector<std::vector<double>> lens_matrix_;</std::vector<double>
Toshihiro Shimizu 890ddd
	std::vector<int> lens_offsets_;</int>
Toshihiro Shimizu 890ddd
	std::vector<double *=""> lens_starts_;</double>
Toshihiro Shimizu 890ddd
	std::vector<int> lens_sizes_;</int>
Toshihiro Shimizu 890ddd
	std::vector<one_thread_<t>> threads_;</one_thread_<t>
Toshihiro Shimizu 890ddd
	igs::resource::multithread mthread_;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/* パラメータの指定を見て、画像に変化の無い場合、
Toshihiro Shimizu 890ddd
呼び出し側で、fog処理するか判断する。fog処理しないときの処理も忘れずに */
Toshihiro Shimizu 890ddd
bool igs::fog::have_change(
Toshihiro Shimizu 890ddd
	const double radius // 25.0(0 ... 100(DOUBLE_MAX))
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double power // 1.00(-2.00 ... 2.00)
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double threshold_min // 0.00(0.00 ... 1.01)
Toshihiro Shimizu 890ddd
	)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/* 収光(変化)しない
Toshihiro Shimizu 890ddd
		場合1  直径が1以下
Toshihiro Shimizu 890ddd
		場合2  powerがゼロ(マイナスは有効としている)
Toshihiro Shimizu 890ddd
		場合3  powerがプラスで、threshold_minが1よりも大きい
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	if ((static_cast<int>(ceil(radius * 2.0)) <= 1) ||</int>
Toshihiro Shimizu 890ddd
		(0.0 == power) ||
Toshihiro Shimizu 890ddd
		((0.0 < power) && (1.0 < threshold_min))) {
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/* fog処理する */
Toshihiro Shimizu 890ddd
void igs::fog::convert(
Toshihiro Shimizu 890ddd
	void *in // no margin
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	void *out // no margin
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	double *buffer // no margin
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int height, const int width, const int channels, const int bits
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int number_of_thread // 1 ... INT_MAX
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double radius // 25.0(0 ... 100(DOUBLE_MAX))
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double curve // 1.00(0.01 ... 100)
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const int polygon_number // 2(2 ... 16(INT_MAX))
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double degree // 0(0 ... DOUBLE_MAX)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double power // 1.00(-2.00 ... 2.00)
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double threshold_min // 0.00(0.00 ... 1.01)
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const double threshold_max // 0.00(0.00 ... 1.01)
Toshihiro Shimizu 890ddd
	,
Toshihiro Shimizu 890ddd
	const bool alpha_rendering_sw // false(true,false)
Toshihiro Shimizu 890ddd
	)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if ((igs::image::rgba::siz != channels) &&
Toshihiro Shimizu 890ddd
		(igs::image::rgb::siz != channels) &&
Toshihiro Shimizu 890ddd
		(1 != channels) /* grayscale */
Toshihiro Shimizu 890ddd
		) {
Toshihiro Shimizu 890ddd
		throw std::domain_error("Bad channels,Not rgba/rgb/grayscale");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (std::numeric_limits<unsigned char="">::digits == bits) {</unsigned>
Toshihiro Shimizu 890ddd
		if (0 != buffer) {
Toshihiro Shimizu 890ddd
			rgb_to_lightness_image_(
Toshihiro Shimizu 890ddd
				static_cast<const *="" char="" unsigned="">(in), height, width, channels, buffer);</const>
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		multi_thread_<unsigned *="" char=""> mthread(</unsigned>
Toshihiro Shimizu 890ddd
			static_cast<unsigned *="" char="">(in), static_cast<unsigned *="" char="">(out), buffer, height, width, channels, number_of_thread, radius, curve, polygon_number, degree, power, threshold_min, threshold_max, alpha_rendering_sw);</unsigned></unsigned>
Toshihiro Shimizu 890ddd
		mthread.run();
Toshihiro Shimizu 890ddd
		mthread.clear();
Toshihiro Shimizu 890ddd
	} else if (std::numeric_limits<unsigned short="">::digits == bits) {</unsigned>
Toshihiro Shimizu 890ddd
		if (0 != buffer) {
Toshihiro Shimizu 890ddd
			rgb_to_lightness_image_(
Toshihiro Shimizu 890ddd
				static_cast<const *="" short="" unsigned="">(in), height, width, channels, buffer);</const>
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		multi_thread_<unsigned *="" short=""> mthread(</unsigned>
Toshihiro Shimizu 890ddd
			static_cast<unsigned *="" short="">(in), static_cast<unsigned *="" short="">(out), buffer, height, width, channels, number_of_thread, radius, curve, polygon_number, degree, power, threshold_min, threshold_max, alpha_rendering_sw);</unsigned></unsigned>
Toshihiro Shimizu 890ddd
		mthread.run();
Toshihiro Shimizu 890ddd
		mthread.clear();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		throw std::domain_error("Bad bits,Not uchar/ushort");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}