Ejemplo n.º 1
0
TEST(algorithmTest, transform_image)
{
    const int width = 10;
    const int height = 10;
    cv::Mat_<int> src1(height, width);
    for(int y=0; y<src1.rows; ++y) {
        for(int x=0; x<src1.cols; ++x) {
            src1(y, x) = y*src1.cols + x;
        }
    }
    cv::Mat_<int> src2(height, width);
    for(int y=0; y<src2.rows; ++y) {
        for(int x=0; x<src2.cols; ++x) {
            src2(y, x) = x*src2.cols + y;
        }
    }
    cv::Mat_<int> src3(height, width);
    for(int y=0; y<src3.rows; ++y) {
        for(int x=0; x<src3.cols; ++x) {
            src3(y, x) = x*y;
        }
    }
    cv::Mat_<int> dst1(height, width);
    cv::Mat_<int> dst2(height, width);

    cvutil::transform_image(src1, dst1, [](int x){ return x*2; });
    for(int y=0; y<dst2.rows; ++y) {
        for(int x=0; x<dst2.cols; ++x) {
            dst2(y, x) = src1(y, x)*2;
        }
    }
    ASSERT_TRUE(std::equal(dst2.begin(), dst2.end(), dst2.begin()));
    
    cvutil::transform_image(src1, src2, dst1,
        [](int x, int y){ return x*2 + y*2; });
    for(int y=0; y<dst2.rows; ++y) {
        for(int x=0; x<dst2.cols; ++x) {
            dst2(y, x) = src1(y, x)*2 + src2(y, x)*2;
        }
    }
    ASSERT_TRUE(std::equal(dst2.begin(), dst2.end(), dst2.begin()));

    cvutil::transform_image(src1, src2, src3, dst1,
        [](int x, int y, int z){ return x + y + z; });
    for(int y=0; y<dst2.rows; ++y) {
        for(int x=0; x<dst2.cols; ++x) {
            dst2(y, x) = src1(y, x) + src2(y, x) + src3(y, x);
        }
    }
    ASSERT_TRUE(std::equal(dst2.begin(), dst2.end(), dst2.begin()));
}
Ejemplo n.º 2
0
	bool YuvToAnyAutoTest(int width, int height, bool is420, View::Format dstType, const Func & f1, const Func & f2)
	{
		bool result = true;

		std::cout << "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]." << std::endl;

		const int uvWidth = is420 ? width/2 : width;
		const int uvHeight = is420 ? height/2 : height;

		View y(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		FillRandom(y);
		View u(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));
		FillRandom(u);
		View v(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));
		FillRandom(v);

		View dst1(width, height, dstType, NULL, TEST_ALIGN(width));
		View dst2(width, height, dstType, NULL, TEST_ALIGN(width));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(y, u, v, dst1));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(y, u, v, dst2));

		result = result && Compare(dst1, dst2, 0, true, 64);

		return result;
	}
Ejemplo n.º 3
0
void tst_QPalette::moveSemantics()
{
#ifdef Q_COMPILER_RVALUE_REFS
    QPalette src(Qt::red), dst;
    const QPalette control = src;
    QVERIFY(src != dst);
    QCOMPARE(src, control);
    QVERIFY(!dst.isCopyOf(src));
    QVERIFY(!dst.isCopyOf(control));
    dst = qMove(src); // move assignment
    QVERIFY(!dst.isCopyOf(src)); // isCopyOf() works on moved-from palettes, too
    QVERIFY(dst.isCopyOf(control));
    QCOMPARE(dst, control);
    src = control; // check moved-from 'src' can still be assigned to (doesn't crash)
    QVERIFY(src.isCopyOf(dst));
    QVERIFY(src.isCopyOf(control));
    QPalette dst2(qMove(src)); // move construction
    QVERIFY(!src.isCopyOf(dst));
    QVERIFY(!src.isCopyOf(dst2));
    QVERIFY(!src.isCopyOf(control));
    QCOMPARE(dst2, control);
    QVERIFY(dst2.isCopyOf(dst));
    QVERIFY(dst2.isCopyOf(control));
    // check moved-from 'src' can still be destroyed (doesn't crash)
#else
    QSKIP("Compiler doesn't support C++11 move semantics");
#endif
}
Ejemplo n.º 4
0
static void xLz(float c,float x,float y,float d){
	if(T==MT)
		glTriangle(x,y,x+cos(d+M_PI/64)*c,y+sin(d+M_PI/64)*c,x+cos(d-M_PI/64)*c,y+sin(d-M_PI/64)*c);
	c*=c;
	for(int i=0;i<2;i++)
		if(dst2(x,y,Px[i],Py[i])<c&&fabsf(rnorm(d-dir(x,y,Px[i],Py[i])))<M_PI/64)Ph[i]--;
}
Ejemplo n.º 5
0
static int rinpb(float x,float y,int r){
	r*=r;
	int n=0;
	for(bxy*b=PB;b<PBtop;b++){
		if(0)killpb:if(killpb(b))break;
		if(dst2(x,y,b->x,b->y)<=r){
			n+=b->p?256:1;
			goto killpb;
		}
	}
	return n;
}
void test_direct_trans()
{
	const index_t m = M == 0 ? DM : M;
	const index_t n = N == 0 ? DN : N;

	// M x N ==> N x M

	typedef typename mat_host<Tag1, double, M, N>::cmat_t cmat_t;
	typedef typename mat_host<Tag2, double, N, M>::mat_t mat_t;

	mat_host<Tag1, double, M, N> src(m, n);
	mat_host<Tag2, double, N, M> dst(n, m);

	src.fill_lin();

	cmat_t smat = src.get_cmat();
	mat_t dmat = dst.get_mat();

	transpose(smat, dmat);

	dense_matrix<double, N, M> rmat(n, m);
	for (index_t i = 0; i < m; ++i)
	{
		for (index_t j = 0; j < n; ++j) rmat(j, i) = smat(i, j);
	}

	ASSERT_MAT_EQ(n, m, dmat, rmat);

	// N x M ==> M x N

	typedef typename mat_host<Tag1, double, N, M>::cmat_t cmat2_t;
	typedef typename mat_host<Tag2, double, M, N>::mat_t mat2_t;

	mat_host<Tag1, double, N, M> src2(n, m);
	mat_host<Tag2, double, M, N> dst2(m, n);

	src2.fill_lin();

	cmat2_t smat2 = src2.get_cmat();
	mat2_t dmat2 = dst2.get_mat();

	transpose(smat2, dmat2);

	dense_matrix<double, M, N> rmat2(m, n);
	for (index_t i = 0; i < m; ++i)
	{
		for (index_t j = 0; j < n; ++j) rmat2(i, j) = smat2(j, i);
	}

	ASSERT_MAT_EQ(m, n, dmat2, rmat2);

}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
	//if (argc != 3) return 1;
	IoChannel src1(argv[1], "r");
	IoChannel dst1(argv[2], "w");
	IoChannel src2(argv[1], "r");
	IoChannel dst2(argv[3], "w");
	CopyChannel cc1(src1, dst1);
	CopyChannel cc2(src2, dst2, 2000);
	GMainLoop *loop = g_main_loop_new(NULL, FALSE);
	g_main_loop_run(loop);
	return 0;
}
Ejemplo n.º 8
0
TEST(algorithmTest, transform_image_xy)
{
    const int width = 10;
    const int height = 10;
    cv::Mat_<int> src1(height, width);
    for(int y=0; y<src1.rows; ++y) {
        for(int x=0; x<src1.cols; ++x) {
            src1(y, x) = y * x;
        }
    }
    cv::Mat_<int> src2(height, width);
    for(int y=0; y<src2.rows; ++y) {
        for(int x=0; x<src2.cols; ++x) {
            src2(y, x) = 2*x + 3*y;
        }
    }

    cv::Mat_<int> dst1(height, width);
    cvutil::transform_image_xy(src1, dst1,
        [](int p, int x, int y){ return p + x + 3*y; });
    cv::Mat_<int> dst2(height, width);
    for(int y=0; y<dst2.rows; ++y) {
        for(int x=0; x<dst2.cols; ++x) {
            dst2(y, x) = x*y + x + 3*y;
        }
    }
    ASSERT_TRUE(std::equal(dst1.begin(), dst1.end(), dst2.begin()));

    cvutil::transform_image_xy(src1, src2, dst1,
        [](int p1, int p2, int x, int y){ return p1*p2 + x + 5*y; });
    for(int y=0; y<dst2.rows; ++y) {
        for(int x=0; x<dst2.cols; ++x) {
            dst2(y, x) = x*y*(2*x + 3*y) + x + 5*y;
        }
    }
    ASSERT_TRUE(std::equal(dst1.begin(), dst1.end(), dst2.begin()));
}
Ejemplo n.º 9
0
    bool YuvToAnyDataTest(bool create, int width, int height, bool is420, View::Format dstType, const Func & f)
    {
        bool result = true;

        Data data(f.description);

        std::cout << (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]." << std::endl;

        const int uvWidth = is420 ? width/2 : width;
        const int uvHeight = is420 ? height/2 : height;

        View y(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View u(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));
        View v(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));

        View dst1(width, height, dstType, NULL, TEST_ALIGN(width));
        View dst2(width, height, dstType, NULL, TEST_ALIGN(width));

        if(create)
        {
            FillRandom(y);
            FillRandom(u);
            FillRandom(v);

            TEST_SAVE(y);
            TEST_SAVE(u);
            TEST_SAVE(v);

            f.Call(y, u, v, dst1);

            TEST_SAVE(dst1);
        }
        else
        {
            TEST_LOAD(y);
            TEST_LOAD(u);
            TEST_LOAD(v);

            TEST_LOAD(dst1);

            f.Call(y, u, v, dst2);

            TEST_SAVE(dst2);

            result = result && Compare(dst1, dst2, 0, true, 64);
        }

        return result;
    }
Ejemplo n.º 10
0
void copy_channels_node_t::do_process( const render::context_t& context)
{
    Imath::Box2i src1_area( ImathExt::intersect( input_as<image_node_t>(0)->defined(), defined()));
    image::const_image_view_t src1( input_as<image_node_t>(0)->const_subimage_view( src1_area));

    Imath::Box2i src2_area( ImathExt::intersect( input_as<image_node_t>(1)->defined(), defined()));
    image::const_image_view_t src2( input_as<image_node_t>(1)->const_subimage_view( src2_area));

    image::image_view_t dst1( subimage_view( src1_area));
    image::image_view_t dst2( subimage_view( src2_area));

    int ch = get_value<int>( param( "red"));
	if( ch == copy_source)
		copy_channel( src1, 0, dst1, 0);
	else
		copy_channel( src2, ch-1, dst2, 0);
	
    ch = get_value<int>( param( "green"));
	if( ch == copy_source)
		copy_channel( src1, 1, dst1, 1);
	else
		copy_channel( src2, ch-1, dst2, 1);

    ch = get_value<int>( param( "blue"));
	if( ch == copy_source)
		copy_channel( src1, 2, dst1, 2);
	else
		copy_channel( src2, ch-1, dst2, 2);

    ch = get_value<int>( param( "alpha"));
    switch( ch)
    {
		case copy_source:
			copy_channel( src1, 3, dst1, 3);
		break;
	
		case set_one:
		case set_zero:
		{
			Imath::Box2i area( ImathExt::intersect( defined(), format()));
			copy_channel( src1, ch-1, subimage_view( area), 3);
		}
		break;
	
		default:
			copy_channel( src2, ch-1, dst2, 3);
    }
}
Ejemplo n.º 11
0
int test_layer_reverse()
{
	// Blog: http://blog.csdn.net/fengbingchun/article/details/77160872
#ifdef __linux__
	std::string image_name{ "test_data/images/lena.png" };
#else
	std::string image_name{ "E:/GitCode/CUDA_Test/test_data/images/lena.png" };
#endif
	cv::Mat matSrc = cv::imread(image_name);
	CHECK(matSrc.data);

	cv::cvtColor(matSrc, matSrc, CV_BGR2GRAY);
	const int width{ 1511 }, height{ 1473 };
	const auto length = width * height;
	cv::resize(matSrc, matSrc, cv::Size(width, height));
	cv::Mat matTmp1;
	matSrc.convertTo(matTmp1, CV_32FC1);

	float elapsed_time1{ 0.f }, elapsed_time2{ 0.f }; // milliseconds
	const std::vector<int> vec{ 5, 7};
	std::unique_ptr<float[]> dst1(new float[length]), dst2(new float[length]);
	std::for_each(dst1.get(), dst1.get() + length, [](float& n) {n = 0.f; });
	std::for_each(dst2.get(), dst2.get() + length, [](float& n) {n = 0.f; });

	int ret = layer_reverse_cpu((float*)matTmp1.data, dst1.get(), length, vec, &elapsed_time1);
	if (ret != 0) PRINT_ERROR_INFO(image_reverse_cpu);

	ret = layer_reverse_gpu((float*)matTmp1.data, dst2.get(), length, vec, &elapsed_time2);
	if (ret != 0) PRINT_ERROR_INFO(image_reverse_gpu);

	compare_result(dst1.get(), dst2.get(), length);

	cv::Mat matTmp2(height, width, CV_32FC1, dst2.get()), matDst;
	matTmp2.convertTo(matDst, CV_8UC1);

#ifdef __linux__
	save_image(matSrc, matDst, 400, 200, "test_data/images/image_reverse.png");
#else
	save_image(matSrc, matDst, 400, 200, "E:/GitCode/CUDA_Test/test_data/images/image_reverse.png");
#endif

	fprintf(stderr, "test layer reverse: cpu run time: %f ms, gpu run time: %f ms\n", elapsed_time1, elapsed_time2);

	return 0;
}
Ejemplo n.º 12
0
    bool AveragingBinarizationDataTest(bool create, int width, int height, SimdCompareType type, const Func2 & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        View dst1(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View dst2(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        const uint8_t value = 127;
        const size_t neighborhood = 17;
        const uint8_t threshold = 128;
        const uint8_t positive = 7;
        const uint8_t negative = 3;

        if(create)
        {
            FillRandom(src);

            TEST_SAVE(src);

            f.Call(src, value, neighborhood, threshold, positive, negative, dst1, type);

            TEST_SAVE(dst1);
        }
        else
        {
            TEST_LOAD(src);

            TEST_LOAD(dst1);

            f.Call(src, value, neighborhood, threshold, positive, negative, dst2, type);

            TEST_SAVE(dst2);

            result = result && Compare(dst1, dst2, 0, true, 64);
        }

        return result;
    }
Ejemplo n.º 13
0
    bool ContourMetricsMaskedDataTest(bool create, int width, int height, const FuncM & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View mask(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        View dst1(width, height, View::Int16, NULL, TEST_ALIGN(width));
        View dst2(width, height, View::Int16, NULL, TEST_ALIGN(width));

        if(create)
        {
            FillRandom(src);
            FillRandom(mask);

            TEST_SAVE(src);
            TEST_SAVE(mask);

            f.Call(src, mask, 128, dst1);

            TEST_SAVE(dst1);
        }
        else
        {
            TEST_LOAD(src);
            TEST_LOAD(mask);

            TEST_LOAD(dst1);

            f.Call(src, mask, 128, dst2);

            TEST_SAVE(dst2);

            result = result && Compare(dst1, dst2, 0, true, 32, 0);
        }

        return result;
    }
Ejemplo n.º 14
0
    bool TexturePerformCompensationAutoTest(int width, int height, int shift, const Func4 & f1, const Func4 & f2)
    {
        bool result = true;

        TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "] <" << shift << ">.");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(src);

        View dst1(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View dst2(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, shift, dst1));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, shift, dst2));

        result = result && Compare(dst1, dst2, 0, true, 32, 0);

        return result;
    }
Ejemplo n.º 15
0
    bool AnyToAnyAutoTest(int width, int height, View::Format srcType, View::Format dstType, const Func & f1, const Func & f2)
    {
        bool result = true;

        TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << width << "," << height << "].");

        View src(width, height, srcType, NULL, TEST_ALIGN(width));
        FillRandom(src);

        View dst1(width, height, dstType, NULL, TEST_ALIGN(width));
        View dst2(width, height, dstType, NULL, TEST_ALIGN(width));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, dst1));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, dst2));

        result = result && Compare(dst1, dst2, 0, true, 64);

        return result;
    }
Ejemplo n.º 16
0
    bool TexturePerformCompensationDataTest(bool create, int width, int height, const Func4 & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(src);

        View dst1(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View dst2(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        const int shift = -7;

        if(create)
        {
            FillRandom(src);

            TEST_SAVE(src);

            f.Call(src, shift, dst1);

            TEST_SAVE(dst1);
        }
        else
        {
            TEST_LOAD(src);

            TEST_LOAD(dst1);

            f.Call(src, shift, dst2);

            TEST_SAVE(dst2);

            result = result && Compare(dst1, dst2, 0, true, 32, 0);
        }

        return result;
    }
Ejemplo n.º 17
0
    bool AnyToAnyDataTest(bool create, int width, int height, View::Format srcType, View::Format dstType, const Func & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View src(width, height, srcType, NULL, TEST_ALIGN(width));

        View dst1(width, height, dstType, NULL, TEST_ALIGN(width));
        View dst2(width, height, dstType, NULL, TEST_ALIGN(width));

        if(create)
        {
            FillRandom(src);

            TEST_SAVE(src);

            f.Call(src, dst1);

            TEST_SAVE(dst1);
        }
        else
        {
            TEST_LOAD(src);

            TEST_LOAD(dst1);

            f.Call(src, dst2);

            TEST_SAVE(dst2);

            result = result && Compare(dst1, dst2, 0, true, 64, 0);
        }

        return result;
    }
Ejemplo n.º 18
0
/**
 * @function cropFace
 * @brief Scales and rotates image, so that a image of the upright head of the size dstSize is returned.
 */
inline void cropFace(const cv::Mat& src, cv::Mat& dst, cv::Point& leftEye, cv::Point& rightEye, float offsetXPct, float offsetYPct, cv::Size& dstSize)
{
  float offsetX = std::floor(offsetXPct * dstSize.width);
  float offsetY = std::floor(offsetYPct * dstSize.height);
  float rotation = std::atan2(float(rightEye.y - leftEye.y), float(rightEye.x - leftEye.x));
  float rotationDeg = rotation * 180.0 / M_PI;
  float dist = euclideanDistance(leftEye, rightEye);
  float refDist = float(dstSize.width) - 2.0 * offsetX;
  float scale = dist / refDist;
  cv::Mat rotMat = cv::getRotationMatrix2D(leftEye, rotationDeg, 1.0);
  cv::Mat dst2 = cv::Mat::zeros(src.rows, src.cols, src.type());
  cv::warpAffine(src, dst2, rotMat, dst2.size());
  float cropX = leftEye.x - scale * offsetX;
  float cropY = leftEye.y - scale * offsetY;
  float cropSizeWidth = float(dstSize.width) * scale;
  float cropSizeHeight = float(dstSize.height) * scale;
  
  cv::Rect roi(cropX, cropY, cropSizeWidth, cropSizeHeight);
  if (roi.x + roi.width >= dst2.cols)
    roi.width = dst2.cols - roi.x - 1;
  if (roi.y + roi.height >= dst2.rows)
    roi.height = dst2.rows - roi.y - 1;
  if (roi.x < 0)
    roi.x = 0;
  if (roi.y < 0)
    roi.y = 0;

  cv::Rect insideROI = roi & cv::Rect(0, 0, dst2.cols, dst2.rows);
  if(insideROI.area() > 0)
  {
  	cv::Mat cropped = dst2(insideROI);
  	cv::resize(cropped, dst, dstSize);
  }
  else
  {
  	cv::resize(dst2, dst, dstSize);
  }
};
Ejemplo n.º 19
0
int test_image_process_bgr2gray()
{
	// Blog: http://blog.csdn.net/fengbingchun/article/details/78821765
#ifdef __linux__
	const std::string image_name{ "test_data/images/lena.png" };
#else
	const std::string image_name{ "E:/GitCode/CUDA_Test/test_data/images/lena.png" };
#endif
	cv::Mat mat = cv::imread(image_name);
	CHECK(mat.data);

	const int width{ 1513 }, height{ 1473 };
	cv::resize(mat, mat, cv::Size(width, height));

	std::unique_ptr<unsigned char[]> data1(new unsigned char[width * height]), data2(new unsigned char[width * height]);
	float elapsed_time1{ 0.f }, elapsed_time2{ 0.f }; // milliseconds

	CHECK(bgr2gray_cpu(mat.data, width, height, data1.get(), &elapsed_time1) == 0);
	CHECK(bgr2gray_gpu(mat.data, width, height, data2.get(), &elapsed_time2) == 0);

	cv::Mat dst(height, width, CV_8UC1, data1.get());
#ifdef __linux__
	cv::imwrite("test_data/images/bgr2gray_cpu.png", dst);
#else
	cv::imwrite("E:/GitCode/CUDA_Test/test_data/images/bgr2gray_cpu.png", dst);
#endif
	cv::Mat dst2(height, width, CV_8UC1, data2.get());
#ifdef __linux__
	cv::imwrite("test_data/images/bgr2gray_gpu.png", dst2);
#else
	cv::imwrite("E:/GitCode/CUDA_Test/test_data/images/bgr2gray_gpu.png", dst2);
#endif
	fprintf(stdout, "image bgr to gray: cpu run time: %f ms, gpu run time: %f ms\n", elapsed_time1, elapsed_time2);

	CHECK(compare_result(data1.get(), data2.get(), width*height) == 0);

	return 0;
}
void dng_image::GetRepeat (dng_pixel_buffer &buffer,
				           const dng_rect &srcArea,
				           const dng_rect &dstArea) const
	{
	
	// If we already have the entire srcArea in the
	// buffer, we can just repeat that.
	
	if ((srcArea & buffer.fArea) == srcArea)
		{
		
		buffer.RepeatArea (srcArea,
						   dstArea);
		
		}
		
	// Else we first need to get the srcArea into the buffer area.
	
	else
		{
		
		// Find repeating pattern size.
		
		dng_point repeat = srcArea.Size ();
		
		// Find pattern phase at top-left corner of destination area.
		
		dng_point phase = dng_pixel_buffer::RepeatPhase (srcArea,
													     dstArea);
			
		// Find new source area at top-left of dstArea.
		
		dng_rect newArea = srcArea + (dstArea.TL () -
								      srcArea.TL ());
										 
		// Find quadrant split coordinates.
		
		int32 splitV = newArea.t + repeat.v - phase.v;
		int32 splitH = newArea.l + repeat.h - phase.h;
			
		// Top-left quadrant.
		
		dng_rect dst1 (dng_rect (newArea.t,
					   			 newArea.l,
					   			 splitV,
					   			 splitH) & dstArea);
					    
		if (dst1.NotEmpty ())
			{
			
			dng_pixel_buffer temp (buffer);
			
			temp.fArea = dst1 + (srcArea.TL () -
								 dstArea.TL () +
								 dng_point (phase.v, phase.h));
			
			temp.fData = buffer.DirtyPixel (dst1.t,
									        dst1.l,
									        buffer.fPlane);
									        
			DoGet (temp);
			
			}
			
		// Top-right quadrant.
		
		dng_rect dst2 (dng_rect (newArea.t,
								 splitH,
								 splitV,
								 newArea.r) & dstArea);
								 
		if (dst2.NotEmpty ())
			{
			
			dng_pixel_buffer temp (buffer);
			
			temp.fArea = dst2 + (srcArea.TL () -
								 dstArea.TL () +
								 dng_point (phase.v, -phase.h));
			
			temp.fData = buffer.DirtyPixel (dst2.t,
									        dst2.l,
									        buffer.fPlane);
									        
			DoGet (temp);
			
			}
			
		// Bottom-left quadrant.
		
		dng_rect dst3 (dng_rect (splitV,
								 newArea.l,
								 newArea.b,
								 splitH) & dstArea);
								 
		if (dst3.NotEmpty ())
			{
			
			dng_pixel_buffer temp (buffer);
			
			temp.fArea = dst3 + (srcArea.TL () -
								 dstArea.TL () +
								 dng_point (-phase.v, phase.h));
			
			temp.fData = buffer.DirtyPixel (dst3.t,
									        dst3.l,
									        buffer.fPlane);
									        
			DoGet (temp);
			
			}
			
		// Bottom-right quadrant.
		
		dng_rect dst4 (dng_rect (splitV,
								 splitH,
								 newArea.b,
								 newArea.r) & dstArea);
								 
		if (dst4.NotEmpty ())
			{
			
			dng_pixel_buffer temp (buffer);
			
			temp.fArea = dst4 + (srcArea.TL () -
								 dstArea.TL () +
								 dng_point (-phase.v, -phase.h));
			
			temp.fData = buffer.DirtyPixel (dst4.t,
									        dst4.l,
									        buffer.fPlane);
									        
			DoGet (temp);
			
			} 
					   
		// Replicate this new source area.
		
		buffer.RepeatArea (newArea,
						   dstArea);
		
		}
			
	}
Ejemplo n.º 21
0
ERcExitCode CResourceCompilerHelper::InvokeResourceCompiler(const char* szSrcFilePath, const char* szDstFilePath, const bool bUserDialog) 
{
	const char* szAdjustedFilename = szSrcFilePath;
#if defined(USE_GAMESTREAM)
	char szFullSrcPathBuf[ICryPak::g_nMaxPath];
	if (gEnv && gEnv->pGameStream)
	{
		szAdjustedFilename = gEnv->pCryPak->AdjustFileName(szSrcFilePath, szFullSrcPathBuf, ICryPak::FLAGS_RESOLVE_TO_CACHE);
	}
#endif

	ERcExitCode eRet = eRcExitCode_Pending;

	// make command for execution
	wchar_t szProjectDir[512];
	GetCurrentDirectoryW(sizeof(szProjectDir) / sizeof(szProjectDir[0]), szProjectDir);

	SettingsManagerHelpers::CFixedString<wchar_t, 512> wRemoteCmdLine;
	SettingsManagerHelpers::CFixedString<wchar_t, 512> wDir;
	CSettingsManagerTools smTools = CSettingsManagerTools();

	const char* const szRcParentDir =
		(smTools.Is64bitWindows() && (DirectoryExists(L"Bin64/rc") || !DirectoryExists(L"Bin32/rc")))
		? "Bin64" 
		: "Bin32";

	wchar_t szRegSettingsBuffer[1024];
	smTools.GetEngineSettingsManager()->GetValueByRef("RC_Parameters", SettingsManagerHelpers::CWCharBuffer(szRegSettingsBuffer, sizeof(szRegSettingsBuffer)));

	wRemoteCmdLine.appendAscii(szRcParentDir);
	wRemoteCmdLine.appendAscii("/rc/");
	wRemoteCmdLine.appendAscii(RC_EXECUTABLE);
	wRemoteCmdLine.appendAscii(" \"");
	wRemoteCmdLine.append(szProjectDir);
	wRemoteCmdLine.appendAscii("\\");
	wRemoteCmdLine.appendAscii(szAdjustedFilename);
	wRemoteCmdLine.appendAscii("\" /userdialog=0 ");
	wRemoteCmdLine.append(szRegSettingsBuffer);

	// make it write to a filename of our choice
	char szDstFilename[512];
	char szDstPath[512];

	RemovePath(szDstFilePath, szDstFilename, 512);
	RemoveFilename(szDstFilePath, szDstPath, 512);

	wRemoteCmdLine.appendAscii(" /overwritefilename=\"");
	wRemoteCmdLine.appendAscii(szDstFilename);
	wRemoteCmdLine.appendAscii("\"");
	wRemoteCmdLine.appendAscii(" /targetroot=\"");
	wRemoteCmdLine.append(szProjectDir);
	wRemoteCmdLine.appendAscii("\\");
	wRemoteCmdLine.appendAscii(szDstPath);
	wRemoteCmdLine.appendAscii("\"");

	wDir.append(szProjectDir);
	wDir.appendAscii("\\");
	wDir.appendAscii(szRcParentDir);
	wDir.appendAscii("\\rc");

	STARTUPINFOW si;
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	si.dwX = 100;
	si.dwY = 100;
	si.dwFlags = STARTF_USEPOSITION;

	PROCESS_INFORMATION pi;
	ZeroMemory(&pi, sizeof(pi));

#if defined(DEBUG) && !defined(NDEBUG) && defined(_RENDERER)
	extern ILog *iLog;

	char tmp1[512];
	char tmp2[512];
	SettingsManagerHelpers::CCharBuffer dst1(tmp1, 512); SettingsManagerHelpers::ConvertUtf16ToUtf8(wDir.c_str(), dst1);
	SettingsManagerHelpers::CCharBuffer dst2(tmp2, 512); SettingsManagerHelpers::ConvertUtf16ToUtf8(wRemoteCmdLine.c_str(), dst2);

	iLog->Log("Debug: RC: dir \"%s\", cmd \"%s\"\n", tmp1, tmp2);
#endif

	if (!CreateProcessW( 
		NULL,     // No module name (use command line). 
		const_cast<wchar_t*>(wRemoteCmdLine.c_str()), // Command line. 
		NULL,     // Process handle not inheritable. 
		NULL,     // Thread handle not inheritable. 
		FALSE,    // Set handle inheritance to FALSE. 
		BELOW_NORMAL_PRIORITY_CLASS + (bUserDialog ? 0 : CREATE_NO_WINDOW),	// creation flags. 
		NULL,     // Use parent's environment block. 
		wDir.c_str(),  // Set starting directory. 
		&si,      // Pointer to STARTUPINFO structure.
		&pi))     // Pointer to PROCESS_INFORMATION structure.
	{
		eRet = eRcExitCode_FatalError;
	}
	else
	{
		// Wait until child process exits.
		WaitForSingleObject(pi.hProcess, INFINITE);

		DWORD exitCode;
		if (GetExitCodeProcess(pi.hProcess, &exitCode) == 0)
		{
			eRet = eRcExitCode_Error;
		}
		else
		{
			eRet = (ERcExitCode)exitCode;
		}
	}

	// Close process and thread handles. 
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);

	return eRet;
}
Ejemplo n.º 22
0
const std::string convU16StrToCharStr(const U16Char_t* src, const char* Encoding)
{
    //static char const* const tocode = CHARCONV_ICONV_UTF16;
    char const* const tocode = getPlatformEncoding(Encoding);

    UErrorCode status = U_ZERO_ERROR;

#ifdef ENCCONV_DEBUG
    std::cout << "\t" "convString" << std::endl;
    std::cout << "\t\t" "tocode   = " << tocode   << std::endl;
    //std::cout << "\t\t" "fromcode = " << fromcode << std::endl;
#endif

    //iconv_t cd = iconv_open(tocode, fromcode);
    // Initializing ICU converter
    UConverter *conv = ucnv_open(tocode, &status);

#ifdef CHARCONV_DEBUG
    std::cout << "\t\t" "aft ucnv_open: status = " << status << std::endl;
#endif
    if (conv == NULL)
    {   // try default encoding "ISO-8859-1"
        //throw std::runtime_error("Unable to create Unicode converter object");
        status = U_ZERO_ERROR;
        conv = ucnv_open("ISO-8859-1", &status);
    }

    //still if conv is null simply return blank string

    if (conv == NULL)
    {
        return std::string("");
    }

    U16Char_t const* srcWrk = src;
    const size_t srcSizeInUnits = GetNumOfUnits(src);
    const size_t srcSizeInBytes = srcSizeInUnits * sizeof(U16Char_t);
    const size_t dstSizeInBytes = MAX(256, (srcSizeInUnits + 1)) * 4;	// How much byte buffer is needed? (UTF16 --> MBCS)
    char* dst = new char [dstSizeInBytes];
    if(dst==NULL)
    {
        //Fix for #3211945
        ucnv_close(conv);
        return std::string("");
    }
    char* dstWrk =(char*)(dst);
    size_t srcLeftInBytes = srcSizeInBytes;
    size_t dstLeftInBytes = dstSizeInBytes - sizeof(char);
    status = U_ZERO_ERROR;

    ucnv_fromUChars(conv, dstWrk, dstLeftInBytes, (UChar*)srcWrk, -1, &status);
    U16Char_t* reverseConvertedVal = convCharStrToU16Str(dstWrk,Encoding);
    if(strcmp((char*)reverseConvertedVal,(char*)src)!=0)
    {
        EncConv::releaseU16Str(reverseConvertedVal);
        //Fix for #3211945
        dstWrk = NULL;
        ucnv_close(conv);
        delete[] dst;

        return std::string("");
    }
    EncConv::releaseU16Str(reverseConvertedVal);


#ifdef CHARCONV_DEBUG
    std::cout << "\t\t" "aft iconv: status = " << status << std::endl;
#endif
    if (status != U_ZERO_ERROR )
    {
        //	throw std::runtime_error("Unable to convert to string");
        *dstWrk = 0;
    }


    std::string dst2(dst);
    //Fix for #3211945
    dstWrk = NULL;
    delete[] dst;
    //const int err = iconv_close(cd);

    ucnv_close(conv);

    //if (err == -1)
    //	throw std::runtime_error("Unable to deallocate iconv_t object");

    return dst2;
}
Ejemplo n.º 23
0
static int rinlz(float x,float y,int r){
	return Lzo&&x>=Px[1]-r&&x<=Px[1]+r&&(y>=Py[1]||dst2(x,y,Px[1],Py[1])<=sqr(r));
}
Ejemplo n.º 24
0
	float Vector2::dst2(Vector2 * other)
	{
		return dst2(other->getX(), other->getY());
	}
Ejemplo n.º 25
0
	float Vector2::dst2(cocos2d::Vec2 other)
	{
		return dst2(other.x, other.y);
	}
Ejemplo n.º 26
0
static int rinbo(float x,float y,int r){
	return Bor&&dst2(x,y,Box,Boy)<=sqr(r+Bor);
}
Ejemplo n.º 27
0
int main(int argc, char** argv)
{
	bool srcbin = 0;
	bool invbk = 0;
	if(argc < 3){
		printf("Not enough args!\narg1: target image\narg2: source image\narg3: do source image adaptive threshold or not\narg4: invert back ground or not\n");
		getchar();
		return 1;
	}
	if(argc >= 4){
		if(!strcmp(argv[3], "1"))
			srcbin = 1;
	}
	if(argc >= 5){
		if(!strcmp(argv[4], "1"))
			invbk = 1;
	}

	IplImage* srcimg= 0, *srcimgb= 0, *srcimgb2 = 0, *bimg = 0, *b2img = 0,*bugimg = 0, *alg2dst = 0;
	srcimg= cvLoadImage(argv[2], 1);
	if (!srcimg)
	{
		printf("src img %s load failed!\n", argv[2]);
		getchar();
		return 1;
	}
	
	//choosing the parameters for our ccl
	int bn = 8; //how many partitions
	int nwidth = 512;
	if(srcimg->width > 512){
		nwidth = 1024;
		bn = 6;
	}
	if(srcimg->width > 1024){
		nwidth = 2048;
		bn = 3;
	}
	if(srcimg->width > 2048){
		printf("warning, image too wide, max support 2048. image is truncated.\n");
		getchar();
		return 1;
	}
	
	//start selection gpu devices
	int devCount;
	int smCnt = 0;
    cudaGetDeviceCount(&devCount);
 
    // Iterate through devices
	int devChosen = 0;
    for (int i = 0; i < devCount; ++i)
    {
        cudaDeviceProp devProp;
        cudaGetDeviceProperties(&devProp, i);
		if(devProp.major >= 2){//only one device supported
			smCnt = max(smCnt, devProp.multiProcessorCount);
			if(devProp.multiProcessorCount == smCnt)
				devChosen = i;
		}
    }
	
	if(smCnt == 0){
		//our ccl require CUDA cap 2.0 or above, but the Ostava's ccl can be run on any CUDA gpu
		printf("Error, no device with cap 2.x found. Only cpu alg will be run.\n");
		getchar();
		return 1;
	}
	
	if(smCnt != 0){
		cudaSetDevice(devChosen);
		bn = bn * smCnt;
	}

	int nheight = (cvGetSize(srcimg).height-2) / (2*bn);
	if((nheight*2*bn+2) < cvGetSize(srcimg).height)
		nheight++;
	nheight = nheight*2*bn+2;

	if(smCnt != 0)
		printf("gpu ccl for image width 512, 1024, 2048.\nchoosing device %d, width %d, height %d, blocks %d\n", devChosen, nwidth, nheight, bn);

	srcimgb= cvCreateImage(cvSize(nwidth, cvGetSize(srcimg).height),IPL_DEPTH_8U,1);
	srcimgb2= cvCreateImage(cvSize(nwidth, cvGetSize(srcimg).height),IPL_DEPTH_8U,1);
	cvSetImageROI(srcimg, cvRect(0, 0, min(cvGetSize(srcimg).width, nwidth), cvGetSize(srcimg).height));
	cvSetImageROI(srcimgb2, cvRect(0, 0, min(cvGetSize(srcimg).width, nwidth), cvGetSize(srcimg).height));
	cvSet(srcimgb2, cvScalar(0,0,0));
	cvCvtColor(srcimg, srcimgb2, CV_BGRA2GRAY);
	cvResetImageROI(srcimgb2);
	cvReleaseImage(&srcimg);
	if(srcbin)
		cvAdaptiveThreshold(srcimgb2, srcimgb, 1.0, CV_ADAPTIVE_THRESH_MEAN_C, invbk ? CV_THRESH_BINARY_INV :  CV_THRESH_BINARY);
	else
		cvThreshold(srcimgb2, srcimgb, 0.0, 1.0, invbk ? CV_THRESH_BINARY_INV :  CV_THRESH_BINARY);
	boundCheck(srcimgb);

	cvScale(srcimgb, srcimgb2, 255);
	//the source binary image to be labeled is saved as bsrc.bmp
	cvSaveImage("bsrc.bmp", srcimgb2);
	cvSet(srcimgb2, cvScalar(0,0,0));
	
	float elapsedMilliSeconds1;
	{//begin cpu labeling algorithm, the SBLA proposed by Zhao
		LABELDATATYPE *data=(LABELDATATYPE *)malloc(srcimgb->width * srcimgb->height * sizeof(LABELDATATYPE));
	
		for(int j = 0; j<srcimgb->height; j++)
			for(int i = 0; i<srcimgb->width; i++)
				data[i + j*srcimgb->width] = (srcimgb->imageData[i + j*srcimgb->widthStep]) ? 1 : 0;

		int iNumLabels;
		CPerformanceCounter perf;
		perf.Start();
    	iNumLabels = LabelSBLA(data, srcimgb->width, srcimgb->height);
		elapsedMilliSeconds1 = (float)perf.GetElapsedMilliSeconds();
		printf("cpu SBLA used %f ms, total labels %u\n", elapsedMilliSeconds1, iNumLabels);
		free(data);
	}
	
	IplImage *src2(0),*dst2(0);
	int iNumLabels;
	float elapsedMilliSeconds2;
	{//begin cpu labeling algorithm, the BBDT proposed by C. Grana, D. Borghesani, R. Cucchiara
		CPerformanceCounter perf;
		src2 = cvCreateImage( cvGetSize(srcimgb), IPL_DEPTH_8U, 1 );
		cvCopyImage(srcimgb,src2);
		dst2 = cvCreateImage( cvGetSize(srcimgb), IPL_DEPTH_32S, 1 );
		perf.Start();
		cvLabelingImageLab(src2, dst2, 1, &iNumLabels);
		elapsedMilliSeconds2 = (float)perf.GetElapsedMilliSeconds();
		printf("cpu BBDT used %f ms, total labels %u\n", elapsedMilliSeconds2, iNumLabels);
		cvSaveImage("bbdt.bmp", dst2);
//		cvReleaseImage(&src2);
//		cvReleaseImage(&dst2);
	}

	if(smCnt != 0){

	bugimg = cvCreateImage(cvSize(nwidth, 9*bn),IPL_DEPTH_8U,1);
	bimg = cvCreateImage(cvSize(nwidth, 2*bn),IPL_DEPTH_8U,1);
	b2img = cvCreateImage(cvSize(nwidth, 2*bn),IPL_DEPTH_8U,1);

//    cvNamedWindow("src",CV_WINDOW_AUTOSIZE);
//	cvShowImage("src",srcimg);

	//prepare buffers for our gpu algorithm
	CudaBuffer srcBuf, dstBuf, dstBuf2, bBuf, b2Buf, errBuf, glabel;
	srcBuf.Create2D(nwidth, nheight);		//the binary image to be processed
	dstBuf.Create2D(nwidth, (nheight-2)/2); //the label result, only about 1/4 the size of source image contains the final labels
	dstBuf2.Create2D(nwidth,(nheight-2)/2);	//a copy of the pass1 temp result, for debug purpose
	glabel.Create2D(4, 1);					//a int size global buffer for unique final label
	errBuf.Create2D(nwidth, 9*bn);			//a buffer for debug info
	bBuf.Create2D(nwidth, 2 * bn);			//the intersection info used by pass2
	b2Buf.Create2D(nwidth, 2 * bn);			//a copy of bBuf for debug purpose

	srcBuf.SetZeroData();
	srcBuf.CopyFrom(srcimgb->imageData, srcimgb->widthStep, nwidth, cvGetSize(srcimgb).height);

	float elapsedTimeInMs = 0.0f;
    
	//-------------------gpu part----------------------------
    cudaEvent_t start, stop;
    cutilSafeCall  ( cudaEventCreate( &start ) );
    cutilSafeCall  ( cudaEventCreate( &stop ) );
    cutilSafeCall( cudaEventRecord( start, 0 ) );  
	
	if(nwidth == 512)
		label_512(&dstBuf, &dstBuf2, &srcBuf, &bBuf, &b2Buf, &glabel, nheight, bn, &errBuf);
	else if(nwidth == 1024)
		label_1024(&dstBuf, &dstBuf2, &srcBuf, &bBuf, &b2Buf, &glabel, nheight, bn, &errBuf);
	else if(nwidth == 2048)
		label_2048(&dstBuf, &dstBuf2, &srcBuf, &bBuf, &b2Buf, &glabel, nheight, bn, &errBuf);

    cutilSafeCall( cudaEventRecord( stop, 0 ) );
//	cutilCheckMsg("kernel launch failure");
	cudaEventSynchronize(stop);
	cutilSafeCall( cudaEventElapsedTime( &elapsedTimeInMs, start, stop ) );
	uint tlabel = 0;

	cudaMemcpy(&tlabel, glabel.GetData(), 4, cudaMemcpyDeviceToHost);
	printf("gpu alg 1 used %f ms, total labels %u\n", elapsedTimeInMs, tlabel);

	dstBuf.CopyToHost(srcimgb->imageData, srcimgb->widthStep, nwidth, (nheight-2)/2);
	dstBuf2.CopyToHost(srcimgb2->imageData, srcimgb->widthStep, nwidth, (nheight-2)/2);
	errBuf.CopyToHost(bugimg->imageData, bugimg->widthStep, nwidth, 9*bn);
	bBuf.CopyToHost(bimg->imageData, bimg->widthStep, nwidth, 2*bn);
	b2Buf.CopyToHost(b2img->imageData, bimg->widthStep, nwidth, 2*bn);

//	cvNamedWindow("gpu",CV_WINDOW_AUTOSIZE);
//	cvShowImage("gpu",srcimgb);
	cvSaveImage(argv[1], srcimgb);
	cvSaveImage("gpu2.bmp", srcimgb2);	//the final labels of our algorithm
	cvSaveImage("bug.bmp", bugimg);
	cvSaveImage("b.bmp", bimg);
	cvSaveImage("b2.bmp", b2img);
	
	//now start the gpu ccl implemented by Ostava
	alg2dst= cvCreateImage(cvSize(nwidth*4, cvGetSize(srcimgb).height),IPL_DEPTH_8U,1);
	CCLBase* m_ccl;
	m_ccl = new CCL();	

	m_ccl->FindRegions(nwidth, cvGetSize(srcimgb).height, &srcBuf);
	m_ccl->GetConnectedRegionsBuffer()->CopyToHost(alg2dst->imageData, alg2dst->widthStep, nwidth*4, cvGetSize(srcimgb).height);
	delete m_ccl;
	cvSaveImage("alg2.bmp", alg2dst);

	cvReleaseImage(&bugimg);
	cvReleaseImage(&bimg);
	cvReleaseImage(&b2img);
	cvReleaseImage(&alg2dst);
//	}
	//cvWaitKey(0);
	
	//now start cross compare label results of our ccl and the BBDT, to check the correctness
//	if(smCnt != 0){
		ushort *gpures, *cpures;
		uint sz = nwidth * (cvGetSize(srcimgb).height/2);
		gpures = (ushort*)malloc(sz);
		cpures = (ushort*)malloc(sz);
		dstBuf.CopyToHost(gpures, nwidth, nwidth, (cvGetSize(srcimgb).height/2));
		
		//first, reduce cpu labels from one label for each pixel to one label for a 2x2 block, assuming 8-connectivity
		for(int j = 0; j < (cvGetSize(srcimgb).height/2); j++)
			for(int i = 0; i < (nwidth/2); i++){
				uint* cpup;
				ushort res = LBMAX;
				uint y = j*2, x = i*2;
				cpup = (uint*)(dst2->imageData + y*dst2->widthStep);
//				if(y < cvGetSize(srcimgb).height){
					if(cpup[x] != 0)
						res = cpup[x]-1;
					if(cpup[x+1] != 0)
						res = cpup[x+1]-1;
//				}
				y++;
				cpup = (uint*)(dst2->imageData + y*dst2->widthStep);
//				if(y < cvGetSize(srcimgb).height){
					if(cpup[x] != 0)
						res = cpup[x]-1;
					if(cpup[x+1] != 0)
						res = cpup[x+1]-1;
//				}
				cpures[i + j*(nwidth/2)] = res;
			}
		
		//our algo use unsigned short to represent a label, the first label starts a 0, and maximun labels is LBMAX
		if(iNumLabels > LBMAX)
			printf("too much cc, compare abort.\n");
		else{
			//create a error
			//cpures[5] = 12;
			//cpures[15] = 18;
			printf("Checking correctness of gpu alg1\nChecking gpu ref by cpu.\n");
			checkLabels(cpures, gpures, nwidth/2, cvGetSize(srcimgb).height/2, iNumLabels);

			printf("Checking cpu ref by gpu.\n");
			checkLabels(gpures, cpures, nwidth/2, cvGetSize(srcimgb).height/2, tlabel);
		}

		free(gpures);
		free(cpures);
		printf("speedup is %f, %f, %f\n", gpu2time/elapsedTimeInMs, elapsedMilliSeconds1/elapsedTimeInMs, elapsedMilliSeconds2/elapsedTimeInMs);
	}

	cvReleaseImage(&srcimgb);
	cvReleaseImage(&srcimgb2);
	cvReleaseImage(&dst2);
	cvReleaseImage(&src2);

    cutilSafeCall( cudaThreadExit() );
	return 0;

}
Ejemplo n.º 28
0
static float dtop(int p,float x,float y){
	return dst2(x,y,Px[p],Py[p]);
}
Ejemplo n.º 29
0
void eloop(){
	if(Btop>B||Etop>E)marke();
	for(bxy*b=B;b<Btop;b++){
		if(0)killb:if(killb(b))break;
		float bx=b->x,by=b->y;
		b->x+=b->xd;
		b->y+=b->yd;
		if(b->y<0||b->x<0||b->x>128||b->y>256)goto killb;
		if(T==MT){
			glLine(bx,by,b->x,b->y);
			glRect(b->x-1,b->y-1,b->x+1,b->y+1);
		}
		for(int i=0;i<2;i++)
			if(btop(i,b)<256){
				if(Php[i]!=b->p){
					Ph[i]--;
					Php[i]=b->p;
				}
				goto killb;
			}
	}
	for(obje*e=E;e<Etop;e++){
		if(0)kille:if(kille(e))break;
		float x=e->x,y=e->y,r;
		int et=!!(e->t&128);
		switch(e->t&127){
		case(CAN)
			e->x=x+=e->xd;
			e->y=y+=e->yd;
			et=nerdest(e);
			erotxy(e,Px[et],Py[et],M_PI/16);
			if(!(T-e->c&3))
				mkbd(e->c,x+cos(e->d)*r*2,y+sin(e->d)*r*2,6,e->d);
			if(x<-5||x>133||y<-5||y>261||e->h<1)goto kille;
			else(e->h<4||rdmg(x,y,e->h*3/2)){
				deceh(e);
			}
			if(T==MT){
				float r=min(T-e->c,e->h);
				glColor(wht);
				glLine(x,y,x+cos(e->d)*r*2,y+sin(e->d)*r*2);
				glColor(red+et);
				glCirc(x,y,r);
			}
		case(TAR)
			r=min(T-e->c,abs(e->h));
			et=e->h<6?4:rdmg(x,y,r);
			if(et)
				seteh(e,e->h-et);
			setexdyd(e,rrotxy(e->xd,x,y,Px[0],Py[0],M_PI/72),rrotxy(e->yd,x,y,Px[1],Py[1],M_PI/72));
			if(e->h<-120)goto kille;
			if(T==MT){
				glColor(wht);
				glCirc(x,y,r);
				rndcol();
				glCirc(x,y,min(r,24));
				glColor(wht);
				glCirc(x,y,min(r,16));
				rndcol();
				glCirc(x,y,min(r,8));
			}
			for(int i=0;i<2;i++)
				xLz(min(T-e->c,127+e->h),x,y,i?e->yd:e->xd);
		case(ROT)
			e->x=x+=e->xd;
			e->y=y+=e->yd;
			e->d+=M_PI/(et?128:-128);
			for(int i=0;i<3;i++)
				mkbd(e->c,x+cos(e->d+i*M_PI*2/3)*32,y+sin(e->d+i*M_PI*2/3)*32,8,e->d+i*M_PI*2/3);
			if(x<-5||x>133||y<-5||y>261||e->h<1)goto kille;
			else(e->h<8||rdmg(x,y,e->h)){
				deceh(e);
			}
			if(T==MT){
				rndcol();
				glCirc(x,y,e->h);
				glColor(wht);
				for(int i=0;i<3;i++)
					glLine(x+cos(e->d+i*M_PI*2/3)*(32-e->h*3),y+sin(e->d+i*M_PI*2/3)*(32-e->h*3),x+cos(e->d+i*M_PI*2/3)*32,y+sin(e->d+i*M_PI*2/3)*32);
			}
		case(DOG)
			et=nearest(e);
			if(dst2(x,y,Px[et],Py[et])<64){
				setPx(et,e->x);
				setPy(et,e->y);
			}else{
				erotxy(e,Px[et],Py[et],M_PI/32);
				setexy(e,x+=cos(e->d)*e->xd,y+=sin(e->d)*e->xd);
				et=2;
			}
			if(rdmg2(x,y,16)&(et==2?0xFFFF:et==1?0x00FF:0xFF00)){
				deceh(e);
				if(!e->h)goto kille;
			}
			if(T==MT){
				glColor(et==2?wht:red+et);
				glCirc(x,y,min(e->h,T-e->c));
			}
		case(POO)
			et=nearest(e);
			erotxy(e,Px[et],Py[et],M_PI/48);
			setexy(e,x+=cos(e->d)*e->xd,y+=sin(e->d)*e->xd);
			if(!(T-e->c&7))
				mkbd(e->c,x,y,0,0);
			if(T==MT){
				rndcol();
				glCirc(x,y,min(T-e->c,e->h)/2);
			}
			if(dst2(x,y,Px[et],Py[et])<sqr(e->h)||e->h<16){
				deceh(e);
				if(!e->h)goto kille;
			}
		case(B1)
			if(y<64){
				add2ey(e);
				y+=2;
			}
			mkbxy(e->c,x,y,Px[0],Py[0],4);
			mkbxy(e->c+1,x,y,Px[1],Py[1],4);
			mkbxy(e->c+2,x,y,Px[!(e->h&8)],Py[!(e->h&8)],1);
			et=rdmg2(x,y,e->h);
			if((e->h&7)!=7&&getb(et,e->h&8))
				seteh(e,e->h+1);
			else(getb(et,!(e->h&8))||e->h<7){
				deceh(e);
				if(!e->h)goto kille;
			}
Ejemplo n.º 30
0
static int nearest(obje*e){
	return dst2(e->x,e->y,Px[0],Py[0])>dst2(e->x,e->y,Px[1],Py[1]);
}