Example #1
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);
    }
}
Example #2
0
runall_result test_main()
{
    const int _rank = 1;
    const int _D0 = 10;

    std::map<int, double> data;
    typedef std::pair <int, double> data_pair;
    for (int i = 0; i < _D0; i++)
        data.insert( data_pair(i, (double)rand()));

    Concurrency::array<double, _rank> src1(_D0, data.begin(), data.end());
    Concurrency::array<double, _rank> src2(_D0, data.begin());

	// We shouldn't compile
    return runall_fail;
}
Example #3
0
 void Bitwise_notTest::testManual1()
 {
     m_operator->setParameter(Bitwise_not::PARAMETER_DATA_FLOW, runtime::Enum(Bitwise_not::MANUAL));
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer src1(new cvsupport::Image("lenna.jpg", cvsupport::Image::GRAYSCALE));
     runtime::DataContainer dst(new cvsupport::Image(5000000));
     
     m_operator->setInputData(Bitwise_not::INPUT_SRC_1, src1);
     m_operator->setInputData(Bitwise_not::INPUT_DST, dst);
     
     runtime::DataContainer dstResult = m_operator->getOutputData(Bitwise_not::OUTPUT_DST);
     
     runtime::ReadAccess dstAccess(dstResult);
     cvsupport::Image::save("Bitwise_notTest_testManual1_dst.png", dstAccess.get<runtime::Image>());
 }
Example #4
0
 void MergeTest::testAllocate1()
 {
     m_operator->setParameter(Merge::PARAMETER_DATA_FLOW, runtime::Enum(Merge::ALLOCATE));
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer src1(new cvsupport::Matrix("row_32f.npy"));
     runtime::DataContainer src2(new cvsupport::Matrix("row_32f.npy"));
     
     m_operator->setInputData(Merge::INPUT_SRC_1, src1);
     m_operator->setInputData(Merge::INPUT_SRC_2, src2);
     
     runtime::DataContainer dstResult = m_operator->getOutputData(Merge::OUTPUT_DST);
     
     runtime::ReadAccess dstAccess(dstResult);
     cvsupport::Matrix::save("MergeTest_testAllocate1_dst.npy", dstAccess.get<runtime::Matrix>());
 }
Example #5
0
 void Bitwise_andTest::testAllocate0()
 {
     m_operator->setParameter(Bitwise_and::DATA_FLOW, runtime::Enum(Bitwise_and::ALLOCATE));
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer src1(new cvsupport::Image("lenna.jpg", cvsupport::Image::DEPTH_16));
     runtime::DataContainer src2(new cvsupport::Image("barbara.jpg", cvsupport::Image::DEPTH_16));
     
     m_operator->setInputData(Bitwise_and::SRC_1, src1);
     m_operator->setInputData(Bitwise_and::SRC_2, src2);
     
     runtime::DataContainer dstResult = m_operator->getOutputData(Bitwise_and::DST);
     
     runtime::ReadAccess dstAccess(dstResult);
     cvsupport::Image::save("Bitwise_andTest_testAllocate0_dst.png", dstAccess.get<runtime::Image>());
 }
int
main(int argc, char **argv)
{
  if (argc < 4) {
    std::cerr << "Usage: test_image_rgb_mask " <<
                 "<ifile> <mfile> <ofile> [r] [g] [b]" << std::endl;
    exit(1);
  }

  CFile ifile(argv[1]);
  CFile mfile(argv[2]);
  CFile ofile(argv[3]);

  double r, g, b;

  if (argc >= 5 && ! CStrUtil::toReal(argv[4], &r)) exit(1);
  if (argc >= 6 && ! CStrUtil::toReal(argv[5], &g)) exit(1);
  if (argc >= 7 && ! CStrUtil::toReal(argv[6], &b)) exit(1);

  CImageFileSrc src1(ifile);

  CImagePtr src_image = CImageMgrInst->createImage(src1);

  CImageFileSrc src2(mfile);

  CImagePtr merge_image = CImageMgrInst->createImage(src2);

  CImagePtr merge_image1;

  if (argc >= 5) {
    CRGBA rgba(r, g, b);

    merge_image1 = merge_image->createRGBAMask(rgba);
  }
  else
    merge_image1 = merge_image->createRGBAMask();

  src_image->combineAlpha(merge_image1);

  CFileType type = CFileUtil::getImageTypeFromName(argv[3]);

  src_image->write(&ofile, type);

  exit(0);
}
Example #7
0
OCL_PERF_TEST_P(AddFixture, Add,
            ::testing::Combine(OCL_TEST_SIZES,
                               OCL_TEST_TYPES))
{
    const Size srcSize = GET_PARAM(0);
    const int type = GET_PARAM(1);

    checkDeviceMaxMemoryAllocSize(srcSize, type);

    UMat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
    randu(src1);
    randu(src2);
    declare.in(src1, src2).out(dst);

    OCL_TEST_CYCLE() cv::add(src1, src2, dst);

    SANITY_CHECK(dst);
}
Example #8
0
 void AbsdiffTest::testManual1()
 {
     m_operator->setParameter(Absdiff::DATA_FLOW, runtime::Enum(Absdiff::MANUAL));
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer src1(new cvsupport::Image("lenna.jpg", cvsupport::Image::GRAYSCALE));
     runtime::DataContainer src2(new cvsupport::Image("barbara.jpg", cvsupport::Image::GRAYSCALE));
     runtime::DataContainer dst(new cvsupport::Image(5000000));
     
     m_operator->setInputData(Absdiff::SRC_1, src1);
     m_operator->setInputData(Absdiff::SRC_2, src2);
     m_operator->setInputData(Absdiff::DST, dst);
     
     runtime::DataContainer dstResult = m_operator->getOutputData(Absdiff::DST);
     
     runtime::ReadAccess dstAccess(dstResult);
     cvsupport::Image::save("AbsdiffTest_testManual1_dst.png", dstAccess.get<runtime::Image>());
 }
Example #9
0
 void MergeTest::testManual0()
 {
     m_operator->setParameter(Merge::PARAMETER_DATA_FLOW, runtime::Enum(Merge::MANUAL));
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer src1(new cvsupport::Matrix("column_32f.npy"));
     runtime::DataContainer src2(new cvsupport::Matrix("column_32f.npy"));
     runtime::DataContainer dst(new cvsupport::Image(5000000));
     
     m_operator->setInputData(Merge::INPUT_SRC_1, src1);
     m_operator->setInputData(Merge::INPUT_SRC_2, src2);
     m_operator->setInputData(Merge::INPUT_DST, dst);
     
     runtime::DataContainer dstResult = m_operator->getOutputData(Merge::OUTPUT_DST);
     
     runtime::ReadAccess dstAccess(dstResult);
     cvsupport::Matrix::save("MergeTest_testManual0_dst.npy", dstAccess.get<runtime::Matrix>());
 }
Example #10
0
int main()
{
    std::ifstream src1("src1");
    if (!src1.is_open()) {													// checking
   	    	std::cout << "Error in openning file " <<std::endl;
   	    	return -1;
   	  }
    std::ifstream src2("src2");
    if (!src2.is_open()) {													// checking
      	    	std::cout << "Error in openning file " <<std::endl;
      	    	return -1;
      	  }
    std::ofstream dest("dest");
    if (!dest.is_open()) {													// checking
      	    	std::cout << "Error in openning file " <<std::endl;
      	    	return -1;
      	  }

    std::string line_buf;

    while (src1.good() || src2.good())
    {

    		if (src1.good()) {
    			std::getline(src1, line_buf);
    	    	dest << line_buf << " ";
    		}
    		if (src2.good()) {
    			std::getline(src2, line_buf);
    	    	dest << line_buf << " ";
    		}
    		dest << std::endl;
    }

    src1.close();
	src2.close();
	dest.close();

	std::cout << "All done" << std::endl;

    return 0;
}
Example #11
0
OCL_PERF_TEST_P(BlendLinearFixture, BlendLinear, ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134))
{
    Size_MatType_t params = GetParam();
    const Size srcSize = get<0>(params);
    const int srcType = get<1>(params);
    const double eps = CV_MAT_DEPTH(srcType) <= CV_32S ? 1.0 : 0.2;

    checkDeviceMaxMemoryAllocSize(srcSize, srcType);

    UMat src1(srcSize, srcType), src2(srcSize, srcType), dst(srcSize, srcType);
    UMat weights1(srcSize, CV_32FC1), weights2(srcSize, CV_32FC1);

    declare.in(src1, src2, WARMUP_RNG).in(weights1, weights2, WARMUP_READ).out(dst);
    randu(weights1, 0, 1);
    randu(weights2, 0, 1);

    OCL_TEST_CYCLE() cv::blendLinear(src1, src2, weights1, weights2, dst);

    SANITY_CHECK(dst, eps);
}
Example #12
0
static sample_t diff_resampled(const SRCParams &params, sample_t *buf1, sample_t *buf2, size_t size)
{
  /////////////////////////////////////////////////////////////////////////////
  // After resample only q*nyquist of the bandwidth is preserved. Therefore,
  // to compare output of the resampler with the original signal we must feed
  // the resampler with the bandlimited signal. Bandlimiting filter has a
  // transition band and we must guarantee:
  // passband + transition_band <= q*nyquist.
  //
  // It looks reasonable to make the transition band of the bandlimiting filter
  // to be equal to the transition band of the resampler. In this case we have:
  // passband + (1-q)*nyquist <= q*nyquist
  // passband <= (2q - 1)*nyquist
  //
  // In normalized form nyquist = 0.5, so we have following parameters of the
  // bandlimiting filter: passband = q-0.5, transition band = 0.5*(1-q)

  ParamFIR low_pass(ParamFIR::low_pass, params.q-0.5, 0, 0.5*(1-params.q), params.a + 10, true);

  const FIRInstance *fir = low_pass.make(params.fs);
  BOOST_REQUIRE(fir != 0);
  int trans_len = fir->length * 2;
  delete fir;

  Speakers spk(FORMAT_LINEAR, MODE_MONO, params.fs);
  samples_t s1, s2;
  s1.zero(); s1[0] = buf1;
  s2.zero(); s2[0] = buf2;

  ChunkSource src1(spk, Chunk(s1, size));
  ChunkSource src2(spk, Chunk(s2, size));
  Convolver   conv1(&low_pass);
  Convolver   conv2(&low_pass);
  SliceFilter slice1(trans_len, size - trans_len);
  SliceFilter slice2(trans_len, size - trans_len);
  FilterChain chain1(&conv1, &slice1);
  FilterChain chain2(&conv2, &slice2);
  return calc_diff(&src1, &chain1, &src2, &chain2);
}
Example #13
0
GPU_PERF_TEST(Min, cv::gpu::DeviceInfo, cv::Size, perf::MatType)
{
    cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
    cv::Size size = GET_PARAM(1);
    int type = GET_PARAM(2);

    cv::gpu::setDevice(devInfo.deviceID());

    cv::Mat src1_host(size, type);
    cv::Mat src2_host(size, type);

    declare.in(src1_host, src2_host, WARMUP_RNG);

    cv::gpu::GpuMat src1(src1_host);
    cv::gpu::GpuMat src2(src2_host);
    cv::gpu::GpuMat dst(size, type);

    TEST_CYCLE()
    {
        cv::gpu::min(src1, src2, dst);
    }
}
Example #14
0
GPU_PERF_TEST(NormDiff, cv::gpu::DeviceInfo, cv::Size, NormType)
{
    cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
    cv::Size size = GET_PARAM(1);
    int normType = GET_PARAM(2);

    cv::gpu::setDevice(devInfo.deviceID());

    cv::Mat src1_host(size, CV_8UC1);
    cv::Mat src2_host(size, CV_8UC1);

    declare.in(src1_host, src2_host, WARMUP_RNG);

    cv::gpu::GpuMat src1(src1_host);
    cv::gpu::GpuMat src2(src2_host);
    double dst;

    TEST_CYCLE()
    {
        dst = cv::gpu::norm(src1, src2, normType);
    }
}
Example #15
0
 void AddWeightedTest::testAllocate0()
 {
     m_operator->setParameter(AddWeighted::DATA_FLOW, runtime::Enum(AddWeighted::ALLOCATE));
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer src1(new cvsupport::Image("lenna.jpg", cvsupport::Image::DEPTH_16));
     runtime::Float64 alpha(-1.0);
     runtime::DataContainer src2(new cvsupport::Image("barbara.jpg", cvsupport::Image::DEPTH_16));
     runtime::Float64 beta(10.0);
     runtime::Float64 gamma(2.0);
     
     m_operator->setInputData(AddWeighted::SRC_1, src1);
     m_operator->setParameter(AddWeighted::ALPHA, alpha);
     m_operator->setInputData(AddWeighted::SRC_2, src2);
     m_operator->setParameter(AddWeighted::BETA, beta);
     m_operator->setParameter(AddWeighted::GAMMA, gamma);
     
     runtime::DataContainer dstResult = m_operator->getOutputData(AddWeighted::DST);
     
     runtime::ReadAccess dstAccess(dstResult);
     cvsupport::Image::save("AddWeightedTest_testAllocate0_dst.png", dstAccess.get<runtime::Image>());
 }
Example #16
0
GPU_PERF_TEST(AddMat, cv::gpu::DeviceInfo, cv::Size, perf::MatType)
{
    cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
    cv::Size size = GET_PARAM(1);
    int type = GET_PARAM(2);

    cv::gpu::setDevice(devInfo.deviceID());

    cv::Mat src1_host(size, type);
    cv::Mat src2_host(size, type);

    fill(src1_host, 0.0, 100.0);
    fill(src2_host, 0.0, 100.0);

    cv::gpu::GpuMat src1(src1_host);
    cv::gpu::GpuMat src2(src2_host);
    cv::gpu::GpuMat dst;

    TEST_CYCLE()
    {
        cv::gpu::add(src1, src2, dst);
    }
}
Example #17
0
static void
testMask2()
{
  CFile *ifile1 = new CFile("data/transparent.png");
  CFile *ifile2 = new CFile("data/png_mask.png");

  CFile *ofile = new CFile("transparent1.png");

  CImageFileSrc src1(*ifile1);

  CImagePtr image1 = CImageMgrInst->createImage(src1);

  CImageFileSrc src2(*ifile2);

  CImagePtr image2 = CImageMgrInst->createImage(src2);

  image1->alphaMask(image2);

  image1->writePNG(ofile);

  delete ifile1;
  delete ifile2;
  delete ofile;
}
Example #18
0
void Hud::renderRadar(const float dt, sdlx::Surface &window, const std::vector<v3<int> > &specials, const std::vector<v3<int> > &flags, const sdlx::Rect &viewport) {
    if (!Map->loaded()) {
        _radar.free();
        _radar_bg.free();
        return;
    }

    if (_map_mode == MapNone || !_enable_radar)
        return;

    if (!_radar.isNull() && !_update_radar.tick(dt)) {
        const int x = window.get_width() - _radar.get_width(), y = _background->get_height();
        window.blit(_radar, x, y);
        return;
    }

    if (_radar_bg.isNull())
        generateRadarBG(viewport); //needed for destructable layers.

    v2<int> radar_size;

    if (_map_mode == MapSmall) {
        radar_size.x = math::min(window.get_width() / 8, _radar_bg.get_width());
        radar_size.y = math::min(window.get_height() / 8, _radar_bg.get_height());
    } else {
        radar_size.x = _radar_bg.get_width();
        radar_size.y = _radar_bg.get_height();
    }

    if (_radar.isNull()) {
        _radar.create_rgb(radar_size.x, radar_size.y, 32);
        _radar.display_format_alpha();
    }

    const int x = window.get_width() - _radar.get_width(), y = _background->get_height();
    v2<int> msize = Map->get_size();

    v2<int> radar_shift;
    if (_map_mode == MapSmall || Map->torus()) {
        radar_shift.x = viewport.x + viewport.w / 2 - msize.x / 2 - msize.x * (_radar.get_width() - _radar_bg.get_width()) / 2 / _radar_bg.get_width();
        radar_shift.y = viewport.y + viewport.h / 2 - msize.y / 2 - msize.y * (_radar.get_height() - _radar_bg.get_height()) / 2 / _radar_bg.get_height();
        Map->validate(radar_shift);
    }

    if (Map->torus()) {
        /* 2x2 split
        [12]
        [34]
        */
        v2<int> split = radar_shift;
        //LOG_DEBUG(("split: %d %d %d %d", split.x, split.y, viewport.x, viewport.y));
        split *= v2<int>(_radar_bg.get_width(), _radar_bg.get_height());
        split /= msize;
        //int split_x = (viewport.w - viewport.x) * _radar_bg.get_width() / msize.x, split_y = (viewport.h - viewport.y) * _radar_bg.get_width() / msize.x;

        _radar.fill(_radar.map_rgba(0,0,0,255));
        sdlx::Rect src1(split.x - _radar_bg.get_width(), split.y - _radar_bg.get_height(), _radar_bg.get_width(), _radar_bg.get_height());
        sdlx::Rect src2(split.x, split.y - _radar_bg.get_height(), _radar_bg.get_width(), _radar_bg.get_height());
        sdlx::Rect src3(split.x - _radar_bg.get_width(), split.y, _radar_bg.get_width(), _radar_bg.get_height());
        sdlx::Rect src4(split.x, split.y, _radar_bg.get_width(), _radar_bg.get_height());
        _radar.blit(_radar_bg, src1, 0, 0);
        _radar.blit(_radar_bg, src2, 0, 0);
        _radar.blit(_radar_bg, src3, 0, 0);
        _radar.blit(_radar_bg, src4, 0, 0);
    } else {
        if (radar_shift.x < 0)
            radar_shift.x = 0;
        if (radar_shift.y < 0)
            radar_shift.y = 0;
        v2<int> radar_map_size = radar_size * msize / v2<int>(_radar_bg.get_width(), _radar_bg.get_height());

        if (radar_shift.x + radar_map_size.x > msize.x)
            radar_shift.x = msize.x - radar_map_size.x;

        if (radar_shift.y + radar_map_size.y > msize.y)
            radar_shift.y = msize.y - radar_map_size.y;

        v2<int> shift = radar_shift * v2<int>(_radar_bg.get_width(), _radar_bg.get_height()) / msize;
        sdlx::Rect src(shift.x, shift.y, _radar.get_width(), _radar.get_height());
        _radar.blit(_radar_bg, src, 0, 0);
    }

    //LOG_DEBUG(("radar shift: %d %d", radar_shift.x, radar_shift.y));

    _radar.lock();

    size_t n = PlayerManager->get_slots_count();
    for(size_t i = 0; i < n; ++i) {
        PlayerSlot &slot = PlayerManager->get_slot(i);
        const Object *obj = slot.getObject();
        if (obj == NULL)
            continue;

        v2<int> pos;
        obj->get_center_position(pos);
        pos -= radar_shift;
        Map->validate(pos);

        _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x, pos.y * _radar_bg.get_height() / msize.y, index2color(_radar, i + 1, 255));
        _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x, pos.y * _radar_bg.get_height() / msize.y + 1, index2color(_radar, i + 1, 200));
        _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x, pos.y * _radar_bg.get_height() / msize.y - 1, index2color(_radar, i + 1, 200));
        _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x + 1, pos.y * _radar_bg.get_height() / msize.y, index2color(_radar, i + 1, 200));
        _radar.put_pixel(pos.x * _radar_bg.get_width() / msize.x - 1, pos.y * _radar_bg.get_height() / msize.y, index2color(_radar, i + 1, 200));
    }

    static bool blink;

    blink = !blink;
    if (blink) {
        //format me
        n = specials.size();
        for(size_t i = 0; i < n; ++i) {
            v3<int> pos = specials[i];
            {
                v2<int> p(pos.x, pos.y);
                p -= radar_shift;
                Map->validate(p);
                pos.x = p.x;
                pos.y = p.y;
            }

            Uint32 color[2];
            color[0] = index2color(_radar, i + 1, 255);
            color[1] = index2color(_radar, i + 1, 200);
            for(int b = 0; b < 2; ++b) {
                _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x, pos.y * _radar_bg.get_height() / msize.y, color[b]);
                for(int l = 1; l <= 2; ++l) {
                    _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x + l, pos.y * _radar_bg.get_height() / msize.y + l, color[b]);
                    _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x - l, pos.y * _radar_bg.get_height() / msize.y - l, color[b]);
                    _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x + l, pos.y * _radar_bg.get_height() / msize.y - l, color[b]);
                    _radar.put_pixel(b + pos.x * _radar_bg.get_width() / msize.x - l, pos.y * _radar_bg.get_height() / msize.y + l, color[b]);
                }
            }
        }


        n = flags.size();
        if (n > 2)
            n = 2;

        for(size_t i = 0; i < n; ++i) {
            v3<int> pos = flags[i];
            {
                v2<int> p(pos.x, pos.y);
                p -= radar_shift;
                Map->validate(p);
                pos.x = p.x;
                pos.y = p.y;
            }

            Uint32 color[2] = { _radar.map_rgb(255, 0, 0), _radar.map_rgb(0, 255, 0), };
            _radar.put_pixel(0 + pos.x * _radar_bg.get_width() / msize.x, 0 + pos.y * _radar_bg.get_height() / msize.y, color[i]);
            _radar.put_pixel(1 + pos.x * _radar_bg.get_width() / msize.x, 0 + pos.y * _radar_bg.get_height() / msize.y, color[i]);
            _radar.put_pixel(2 + pos.x * _radar_bg.get_width() / msize.x, 0 + pos.y * _radar_bg.get_height() / msize.y, color[i]);
            _radar.put_pixel(0 + pos.x * _radar_bg.get_width() / msize.x, 1 + pos.y * _radar_bg.get_height() / msize.y, color[i]);
            _radar.put_pixel(1 + pos.x * _radar_bg.get_width() / msize.x, 1 + pos.y * _radar_bg.get_height() / msize.y, color[i]);
            _radar.put_pixel(0 + pos.x * _radar_bg.get_width() / msize.x, 2 + pos.y * _radar_bg.get_height() / msize.y, color[i]);
            _radar.put_pixel(1 + pos.x * _radar_bg.get_width() / msize.x, 2 + pos.y * _radar_bg.get_height() / msize.y, color[i]);
            _radar.put_pixel(2 + pos.x * _radar_bg.get_width() / msize.x, 2 + pos.y * _radar_bg.get_height() / msize.y, color[i]);
            _radar.put_pixel(0 + pos.x * _radar_bg.get_width() / msize.x, 3 + pos.y * _radar_bg.get_height() / msize.y, color[i]);
        }

    } //blink

    _radar.unlock();

    window.blit(_radar, x, y);
}
Example #19
0
bool test_feature(const vector<accelerator>& devices)
{
	int edata[_rank];
	for (int i = 0; i < _rank; i++)
		edata[i] = 3;
	
	printf("Found %d devices\n", devices.size());

	for (size_t i = 0; i < devices.size()-1; i++)
	{
		accelerator device1 = devices[i];
		accelerator device2 = devices[i+1];

		if (_rank > 0)
		{
			const int rank = 1;
			Concurrency::array<_type, rank> src1(edata[0], device1.get_default_view());
			Concurrency::array<_type, rank> src2(edata[0], device2.get_default_view());

			// let the kernel initialize data;
			extent<1> e1(edata);
			parallel_for_each(e1, [&](index<rank> idx) __GPU_ONLY
			{
				src1[idx] = _rank;
				src2[idx] = _rank;
			});

			// Copy data to CPU
			vector<_type> opt1(e1.size());
			opt1 = src1;
			vector<_type> opt2(e1.size());
			opt2 = src2;

			for (unsigned int i = 0; i < e1.size(); i++)
			{
				if ((opt1[i] != _rank) || (opt2[i] != _rank))
					return false;
			}
			printf ("Passed for rank %d\n", rank);
			rank_step = rank;
		}
		if (_rank > 1)
		{
			const int rank = 2;
			rank_step = rank;
			Concurrency::array<_type, rank> src1(edata[0], edata[1], device1.get_default_view());
			Concurrency::array<_type, rank> src2(edata[0], edata[1], device2.get_default_view());

			// let the kernel initialize data;
			extent<rank> e1(edata);
			parallel_for_each(e1, [&](index<rank> idx) __GPU_ONLY
			{
				src1[idx] = _rank;
				src2[idx] = _rank;
			});

			// Copy data to CPU
			vector<_type> opt1(e1.size());
			opt1 = src1;
			vector<_type> opt2(e1.size());
			opt2 = src2;

			for (unsigned int i = 0; i < e1.size(); i++)
			{
				if ((opt1[i] != _rank) || (opt2[i] != _rank))
					return false;
			}
			printf ("Passed for rank %d\n", rank);
			rank_step = rank;
		}
Example #20
0
int brw_disasm (FILE *file, struct brw_instruction *inst, int gen)
{
    int	err = 0;
    int space = 0;

    if (inst->header.predicate_control) {
	string (file, "(");
	err |= control (file, "predicate inverse", pred_inv, inst->header.predicate_inverse, NULL);
	string (file, "f0");
	if (inst->bits2.da1.flag_reg_nr)
	    format (file, ".%d", inst->bits2.da1.flag_reg_nr);
	if (inst->header.access_mode == BRW_ALIGN_1)
	    err |= control (file, "predicate control align1", pred_ctrl_align1,
			    inst->header.predicate_control, NULL);
	else
	    err |= control (file, "predicate control align16", pred_ctrl_align16,
			    inst->header.predicate_control, NULL);
	string (file, ") ");
    }

    err |= print_opcode (file, inst->header.opcode);
    err |= control (file, "saturate", saturate, inst->header.saturate, NULL);
    err |= control (file, "debug control", debug_ctrl, inst->header.debug_control, NULL);

    if (inst->header.opcode == BRW_OPCODE_MATH) {
	string (file, " ");
	err |= control (file, "function", math_function,
			inst->header.destreg__conditionalmod, NULL);
    } else if (inst->header.opcode != BRW_OPCODE_SEND &&
	       inst->header.opcode != BRW_OPCODE_SENDC)
	err |= control (file, "conditional modifier", conditional_modifier,
			inst->header.destreg__conditionalmod, NULL);

    if (inst->header.opcode != BRW_OPCODE_NOP) {
	string (file, "(");
	err |= control (file, "execution size", exec_size, inst->header.execution_size, NULL);
	string (file, ")");
    }

    if (inst->header.opcode == BRW_OPCODE_SEND && gen < 6)
	format (file, " %d", inst->header.destreg__conditionalmod);

    if (opcode[inst->header.opcode].ndst > 0) {
	pad (file, 16);
	err |= dest (file, inst);
    } else if (gen >= 6 && (inst->header.opcode == BRW_OPCODE_IF ||
			    inst->header.opcode == BRW_OPCODE_ELSE ||
			    inst->header.opcode == BRW_OPCODE_ENDIF ||
			    inst->header.opcode == BRW_OPCODE_WHILE)) {
       format (file, " %d", inst->bits1.branch_gen6.jump_count);
    }

    if (opcode[inst->header.opcode].nsrc > 0) {
	pad (file, 32);
	err |= src0 (file, inst);
    }
    if (opcode[inst->header.opcode].nsrc > 1) {
	pad (file, 48);
	err |= src1 (file, inst);
    }

    if (inst->header.opcode == BRW_OPCODE_SEND ||
	inst->header.opcode == BRW_OPCODE_SENDC) {
	int target;

	if (gen >= 6)
	    target = inst->header.destreg__conditionalmod;
	else if (gen == 5)
	    target = inst->bits2.send_gen5.sfid;
	else
	    target = inst->bits3.generic.msg_target;

	newline (file);
	pad (file, 16);
	space = 0;

	if (gen >= 6) {
	   err |= control (file, "target function", target_function_gen6,
			   target, &space);
	} else {
	   err |= control (file, "target function", target_function,
			   target, &space);
	}

	switch (target) {
	case BRW_MESSAGE_TARGET_MATH:
	    err |= control (file, "math function", math_function,
			    inst->bits3.math.function, &space);
	    err |= control (file, "math saturate", math_saturate,
			    inst->bits3.math.saturate, &space);
	    err |= control (file, "math signed", math_signed,
			    inst->bits3.math.int_type, &space);
	    err |= control (file, "math scalar", math_scalar,
			    inst->bits3.math.data_type, &space);
	    err |= control (file, "math precision", math_precision,
			    inst->bits3.math.precision, &space);
	    break;
	case BRW_MESSAGE_TARGET_SAMPLER:
	    if (gen >= 5) {
		format (file, " (%d, %d, %d, %d)",
			inst->bits3.sampler_gen5.binding_table_index,
			inst->bits3.sampler_gen5.sampler,
			inst->bits3.sampler_gen5.msg_type,
			inst->bits3.sampler_gen5.simd_mode);
	    } else if (0 /* FINISHME: is_g4x */) {
		format (file, " (%d, %d)",
			inst->bits3.sampler_g4x.binding_table_index,
			inst->bits3.sampler_g4x.sampler);
	    } else {
		format (file, " (%d, %d, ",
			inst->bits3.sampler.binding_table_index,
			inst->bits3.sampler.sampler);
		err |= control (file, "sampler target format",
				sampler_target_format,
				inst->bits3.sampler.return_format, NULL);
		string (file, ")");
	    }
	    break;
	case BRW_MESSAGE_TARGET_DATAPORT_READ:
	    if (gen >= 6) {
		format (file, " (%d, %d, %d, %d, %d, %d)",
			inst->bits3.gen6_dp.binding_table_index,
			inst->bits3.gen6_dp.msg_control,
			inst->bits3.gen6_dp.msg_type,
			inst->bits3.gen6_dp.send_commit_msg,
			inst->bits3.gen6_dp.msg_length,
			inst->bits3.gen6_dp.response_length);
	    } else if (gen >= 5 /* FINISHME: || is_g4x */) {
		format (file, " (%d, %d, %d)",
			inst->bits3.dp_read_gen5.binding_table_index,
			inst->bits3.dp_read_gen5.msg_control,
			inst->bits3.dp_read_gen5.msg_type);
	    } else {
		format (file, " (%d, %d, %d)",
			inst->bits3.dp_read.binding_table_index,
			inst->bits3.dp_read.msg_control,
			inst->bits3.dp_read.msg_type);
	    }
	    break;

	case BRW_MESSAGE_TARGET_DATAPORT_WRITE:
	    if (gen >= 6) {
		format (file, " (");

		err |= control (file, "DP rc message type",
				dp_rc_msg_type_gen6,
				inst->bits3.gen6_dp.msg_type, &space);

		format (file, ", %d, %d, %d, %d, %d, %d)",
			inst->bits3.gen6_dp.binding_table_index,
			inst->bits3.gen6_dp.msg_control,
			inst->bits3.gen6_dp.msg_type,
			inst->bits3.gen6_dp.send_commit_msg,
			inst->bits3.gen6_dp.msg_length,
			inst->bits3.gen6_dp.response_length);
	    } else {
		format (file, " (%d, %d, %d, %d)",
			inst->bits3.dp_write.binding_table_index,
			(inst->bits3.dp_write.pixel_scoreboard_clear << 3) |
			inst->bits3.dp_write.msg_control,
			inst->bits3.dp_write.msg_type,
			inst->bits3.dp_write.send_commit_msg);
	    }
	    break;

	case BRW_MESSAGE_TARGET_URB:
	    if (gen >= 5) {
		format (file, " %d", inst->bits3.urb_gen5.offset);
	    } else {
		format (file, " %d", inst->bits3.urb.offset);
	    }

	    space = 1;
	    if (gen >= 5) {
		err |= control (file, "urb opcode", urb_opcode,
				inst->bits3.urb_gen5.opcode, &space);
	    }
	    err |= control (file, "urb swizzle", urb_swizzle,
			    inst->bits3.urb.swizzle_control, &space);
	    err |= control (file, "urb allocate", urb_allocate,
			    inst->bits3.urb.allocate, &space);
	    err |= control (file, "urb used", urb_used,
			    inst->bits3.urb.used, &space);
	    err |= control (file, "urb complete", urb_complete,
			    inst->bits3.urb.complete, &space);
	    if (gen >= 5) {
		format (file, " mlen %d, rlen %d\n",
			inst->bits3.urb_gen5.msg_length,
			inst->bits3.urb_gen5.response_length);
	    }
	    break;
	case BRW_MESSAGE_TARGET_THREAD_SPAWNER:
	    break;
	default:
	    format (file, "unsupported target %d", target);
	    break;
	}
	if (space)
	    string (file, " ");
	if (gen >= 5) {
	   format (file, "mlen %d",
		   inst->bits3.generic_gen5.msg_length);
	   format (file, " rlen %d",
		   inst->bits3.generic_gen5.response_length);
	} else {
	   format (file, "mlen %d",
		   inst->bits3.generic.msg_length);
	   format (file, " rlen %d",
		   inst->bits3.generic.response_length);
	}
    }
    pad (file, 64);
    if (inst->header.opcode != BRW_OPCODE_NOP) {
	string (file, "{");
	space = 1;
	err |= control(file, "access mode", access_mode, inst->header.access_mode, &space);
	if (gen >= 6)
	    err |= control (file, "write enable control", wectrl, inst->header.mask_control, &space);
	else
	    err |= control (file, "mask control", mask_ctrl, inst->header.mask_control, &space);
	err |= control (file, "dependency control", dep_ctrl, inst->header.dependency_control, &space);

	if (gen >= 6)
	    err |= qtr_ctrl (file, inst);
	else {
	    if (inst->header.compression_control == BRW_COMPRESSION_COMPRESSED &&
		opcode[inst->header.opcode].ndst > 0 &&
		inst->bits1.da1.dest_reg_file == BRW_MESSAGE_REGISTER_FILE &&
		inst->bits1.da1.dest_reg_nr & (1 << 7)) {
		format (file, " compr4");
	    } else {
		err |= control (file, "compression control", compr_ctrl,
				inst->header.compression_control, &space);
	    }
	}

	err |= control (file, "thread control", thread_ctrl, inst->header.thread_control, &space);
	if (gen >= 6)
	    err |= control (file, "acc write control", accwr, inst->header.acc_wr_control, &space);
	if (inst->header.opcode == BRW_OPCODE_SEND ||
	    inst->header.opcode == BRW_OPCODE_SENDC)
	    err |= control (file, "end of thread", end_of_thread,
			    inst->bits3.generic.end_of_thread, &space);
	if (space)
	    string (file, " ");
	string (file, "}");
    }
    string (file, ";");
    newline (file);
    return err;
}
int sc_main (int argc , char *argv[])
{
	/*
	int	quantization[64] = { 8,  6,  6,  7,  6,  5,  8,  7,
							 7,  7,  9,  9,  8, 10, 12, 20,
							13, 12, 11, 11, 12, 25, 18, 19,
							15, 20, 29, 26, 31, 30, 29, 26,
							28, 28, 32, 36, 46, 39, 32, 34,
							44, 35, 28, 28, 40, 55, 41, 44,
							48, 49, 52, 52, 52, 31, 39, 57,
							61, 56, 50, 60, 46, 51, 52, 50 };
	 */

	int	quantization[64] = {16, 11, 10, 16, 24, 40, 51, 61,
							12, 12, 14, 19, 26, 58, 60, 55,
							14, 13, 16, 24, 40, 57, 69, 56,
							14, 17, 22, 29, 51, 87, 80, 62,
							18, 22, 37, 56, 68,109,103, 77,
							24, 35, 55, 64, 81,104,113, 92,
							49, 64, 78, 87,103,121,120,101,
							72, 92, 95, 98,112,100,103, 99};


	sc_ufixed<14,-2,SC_TRN,SC_WRAP> quantization_i[64] = {
			0.0625000000000000, 0.0909090909090909, 0.100000000000000, 0.0625000000000000, 0.0416666666666667, 0.0250000000000000, 0.0196078431372549, 0.0163934426229508,
			0.0833333333333333, 0.0833333333333333, 0.0714285714285714, 0.0526315789473684, 0.0384615384615385, 0.0172413793103448, 0.0166666666666667, 0.0181818181818182,
			0.0714285714285710, 0.0769230769230769, 0.0625000000000000, 0.0416666666666667, 0.0250000000000000, 0.0175438596491228, 0.0144927536231884, 0.0178571428571429,
			0.0714285714285714, 0.0588235294117647, 0.0454545454545455, 0.0344827586206897, 0.0196078431372549, 0.0114942528735632, 0.0125000000000000, 0.0161290322580645,
			0.0555555555555560, 0.0454545454545455, 0.0270270270270270, 0.0178571428571429, 0.0147058823529412, 0.00917431192660551, 0.00970873786407767, 0.0129870129870130,
			0.0416666666666667, 0.0285714285714286, 0.0181818181818182, 0.0156250000000000, 0.0123456790123457, 0.00961538461538462, 0.00884955752212389, 0.0108695652173913,
			0.0204081632653060, 0.0156250000000000, 0.0128205128205128, 0.0114942528735632, 0.00970873786407767, 0.00826446280991736, 0.00833333333333333, 0.00990099009900990,
			0.0138888888888889, 0.0108695652173913, 0.0105263157894737, 0.0102040816326531, 0.00892857142857143, 0.0100000000000000, 0.00970873786407767, 0.0101010101010101
	};

	// definition of default files
	const char*	inputfile		= "datain.pgm";
	const char*	outputfile		= "dataout.pgm";
	const char* typefile 		= "types.txt";

	// definition of FIFO queues
	fifo_stat<int>	stimulus("stimulus",1);
	fifo_stat<int>	parameters("parameters",3);
	fifo_stat<int>	stimulus_dup1("stimulus_dup1",1);
	fifo_stat<int>	stimulus_dup2("stimulus_dup2",MAXWIDTH8*8+64+64+64+64+64);
	fifo_stat<int>	parameters_dup1("parameters_dup1",3);
	fifo_stat<int>	parameters_dup2("parameters_dup2",3);
	fifo_stat<int>	parameters_dup3("parameters_dup3",3);
	fifo_stat<int>	jpeg_dec_in("jpeg_dec_in",1);
	fifo_stat<int>	result("result",1);
	fifo_stat<int>	result_dup1("result_dup1",1);
	fifo_stat<int>	result_dup2("result_dup2",1);

	// definition of signals
	sc_clock 				clk("clock", 12, SC_NS);
	sc_signal<bool> 		ask;
	sc_signal<bool>			ready;
	sc_signal< sc_uint<8> > data;

	// processing of command-line arguments
	bool	detected;
	for(int i=3; i<=argc; i+=2) {
		cout << argv[i-2] << " " << argv[i-1] << endl;
		detected = 0;
		if (strcmp(argv[i-2],"-i")==0) {
			inputfile = argv[i-1];
			detected = 1;
		}
		if (strcmp(argv[i-2],"-o")==0) {
			outputfile = argv[i-1];
			detected = 1;
		}
		if (strcmp(argv[i-2],"-t")==0) {
			typefile = argv[i-1];
			detected = 1;
		}
		if (detected == 0) {
			cout << "option " << argv[i-2] << " not known " << endl;
		}
	}

	//	definition of modules
	src src1("src1", inputfile, MAXWIDTH);
	src1.output(stimulus);
	src1.parameters(parameters);

	df_fork<int,2> fork1("fork1");
	fork1.in(stimulus);
	fork1.out[0](stimulus_dup1);
	fork1.out[1](stimulus_dup2);

	df_fork<int,3> fork_param("fork_param");
	fork_param.in(parameters);
	fork_param.out[0](parameters_dup1);
	fork_param.out[1](parameters_dup2);
	fork_param.out[2](parameters_dup3);

//	jpeg_enc jpeg_enc_1("jpeg_enc_1", quantization, MAXWIDTH);
//	jpeg_enc_1.input(stimulus_dup1);
//	jpeg_enc_1.clk(clk);
//	jpeg_enc_1.parameters(parameters_dup1);
//	jpeg_enc_1.output(data);
//	jpeg_enc_1.ready(ready);
//	jpeg_enc_1.ask(ask);

	jpeg_enc_float jpeg_enc_1("jpeg_enc_1", quantization_i, MAXWIDTH);
	jpeg_enc_1.input(stimulus_dup1);
	jpeg_enc_1.clk(clk);
	jpeg_enc_1.parameters(parameters_dup1);
	jpeg_enc_1.output(data);
	jpeg_enc_1.ready(ready);
	jpeg_enc_1.ask(ask);

	jpeg_dec jpeg_dec_1("jpeg_dec_1", quantization, MAXWIDTH, typefile);
	jpeg_dec_1.input(data);
	jpeg_dec_1.clk(clk);
	jpeg_dec_1.ready(ready);
	jpeg_dec_1.ask(ask);
	jpeg_dec_1.parameters(parameters_dup2);
	jpeg_dec_1.output(result);

	df_fork<int,2> fork2("fork2");
	fork2.in(result);
	fork2.out[0](result_dup1);
	fork2.out[1](result_dup2);

	snk snk1("snk1", outputfile);
	snk1.input(result_dup1);
	snk1.parameters(parameters_dup3);

	test test1("test1");
	test1.reference(stimulus_dup2);
	test1.data(result_dup2);

	sc_start();

	return 0;
}
Example #22
0
int sc_main (int argc , char *argv[]) {

/*
	int	quantization[64] = { 8,  6,  6,  7,  6,  5,  8,  7,
								 7,  7,  9,  9,  8, 10, 12, 20,
								13, 12, 11, 11, 12, 25, 18, 19,
								15, 20, 29, 26, 31, 30, 29, 26,
								28, 28, 32, 36, 46, 39, 32, 34,
								44, 35, 28, 28, 40, 55, 41, 44,
								48, 49, 52, 52, 52, 31, 39, 57,
								61, 56, 50, 60, 46, 51, 52, 50 };
*/

	int	quantization[64] = { 16, 11, 10, 16, 24, 40, 51, 61,
								 12, 12, 14, 19, 26, 58, 60, 55,
								 14, 13, 16, 24, 40, 57, 69, 56,
								 14, 17, 22, 29, 51, 87, 80, 62,
								 18, 22, 37, 56, 68,109,103, 77,
								 24, 35, 55, 64, 81,104,113, 92,
								 49, 64, 78, 87,103,121,120,101,
								 72, 92, 95, 98,112,100,103, 99};

// definition of default files
	const char*	inputfile		= "datain.pgm";
	const char*	outputfile		= "dataout.pgm";
	const char* typefile 		= "types.txt";
	const char* costfilename;
	bool outputcost = false;

//	definition of FIFO queues
	fifo_stat<int>	stimulus("stimulus",1);
	fifo_stat<int>	parameters("parameters",3);
	fifo_stat<int>	stimulus_dup1("stimulus_dup1",1);
	fifo_stat<int>	stimulus_dup2("stimulus_dup2",MAXWIDTH8*8+64+64+64+64+64);
	fifo_stat<int>	parameters_dup1("parameters_dup1",3);
	fifo_stat<int>	parameters_dup2("parameters_dup2",3);
	fifo_stat<int>	parameters_dup3("parameters_dup3",3);
	fifo_stat<int>	jpeg_enc_out("jpeg_enc_out",1);
	fifo_stat<int>	result("result",1);
	fifo_stat<int>	result_dup1("result_dup1",1);
	fifo_stat<int>	result_dup2("result_dup2",1);


// processing of command-line arguments
	bool	detected;
	for(int i=3; i<=argc; i+=2) {
		cout << argv[i-2] << " " << argv[i-1] << endl;
		detected = 0;
		if (strcmp(argv[i-2],"-i")==0) {
			inputfile = argv[i-1];
			detected = 1;
		}
		if (strcmp(argv[i-2],"-o")==0) {
			outputfile = argv[i-1];
			detected = 1;
		}
		if (strcmp(argv[i-2],"-t")==0) {
			typefile = argv[i-1];
			detected = 1;
		}
		if (strcmp(argv[i-2],"-c")==0) {
			costfilename = argv[i-1];
			outputcost = true;
			detected = 1;
		}
		if (detected == 0) {
			cout << "option " << argv[i-2] << " not known " << endl;
		}
	}

//	definition of modules

	src src1("src1", inputfile, MAXWIDTH);
	src1.output(stimulus);
//	src1.output(stimulus_dup1);
//	src1.output(stimulus_dup2);
	src1.parameters(parameters);

	df_fork<int,2> fork1("fork1");
	fork1.in(stimulus);
	fork1.out[0](stimulus_dup1);
	fork1.out[1](stimulus_dup2);

	df_fork<int,3> fork_param("fork_param");
	fork_param.in(parameters);
	fork_param.out[0](parameters_dup1);
	fork_param.out[1](parameters_dup2);
	fork_param.out[2](parameters_dup3);

	jpeg_enc jpeg_enc_1("jpeg_enc_1", quantization, MAXWIDTH);
	jpeg_enc_1.input(stimulus_dup1);
	jpeg_enc_1.parameters(parameters_dup1);
	jpeg_enc_1.output(jpeg_enc_out);

	jpeg_dec jpeg_dec_1("jpeg_dec_1", quantization, MAXWIDTH, typefile);
	jpeg_dec_1.input(jpeg_enc_out);
	jpeg_dec_1.parameters(parameters_dup2);
	jpeg_dec_1.output(result);

	df_fork<int,2> fork2("fork2");
	fork2.in(result);
	fork2.out[0](result_dup1);
	fork2.out[1](result_dup2);

	snk snk1("snk1", outputfile);
	snk1.input(result_dup1);
	snk1.parameters(parameters_dup3);

	test test1("test1");
	test1.reference(stimulus_dup2);
	test1.data(result_dup2);

	sc_start();

	if (outputcost == true) {
		int cost = jpeg_dec_1.idct_1->hardware_cost();
		float snr = test1.snr();
		float psnr = test1.psnr();
		cout << "hardware cost IDCT 2nd " << cost << endl;
		ofstream *costfile;
		costfile = new ofstream(costfilename);
		if (!costfile->is_open()) cout << "Error opening file " << costfilename << endl;
		*costfile << cost << " " << snr << " " << psnr << endl;
		costfile->close();
	}
	return 0;
}
Example #23
0
int brw_disasm (FILE *file, struct brw_instruction *inst)
{
    int	err = 0;
    int space = 0;

    if (inst->header.predicate_control) {
	string (file, "(");
	err |= control (file, "predicate inverse", pred_inv, inst->header.predicate_inverse, NULL);
	string (file, "f0");
	if (inst->bits2.da1.flag_reg_nr)
	    format (file, ".%d", inst->bits2.da1.flag_reg_nr);
	if (inst->header.access_mode == BRW_ALIGN_1)
	    err |= control (file, "predicate control align1", pred_ctrl_align1,
			    inst->header.predicate_control, NULL);
	else
	    err |= control (file, "predicate control align16", pred_ctrl_align16,
			    inst->header.predicate_control, NULL);
	string (file, ") ");
    }

    err |= print_opcode (file, inst->header.opcode);
    err |= control (file, "saturate", saturate, inst->header.saturate, NULL);
    err |= control (file, "debug control", debug_ctrl, inst->header.debug_control, NULL);

    if (inst->header.opcode != BRW_OPCODE_SEND)
	err |= control (file, "conditional modifier", conditional_modifier,
			inst->header.destreg__conditionalmod, NULL);

    if (inst->header.opcode != BRW_OPCODE_NOP) {
	string (file, "(");
	err |= control (file, "execution size", exec_size, inst->header.execution_size, NULL);
	string (file, ")");
    }

    if (inst->header.opcode == BRW_OPCODE_SEND)
	format (file, " %d", inst->header.destreg__conditionalmod);

    if (opcode[inst->header.opcode].ndst > 0) {
	pad (file, 16);
	err |= dest (file, inst);
    }
    if (opcode[inst->header.opcode].nsrc > 0) {
	pad (file, 32);
	err |= src0 (file, inst);
    }
    if (opcode[inst->header.opcode].nsrc > 1) {
	pad (file, 48);
	err |= src1 (file, inst);
    }

    if (inst->header.opcode == BRW_OPCODE_SEND) {
	newline (file);
	pad (file, 16);
	space = 0;
	err |= control (file, "target function", target_function,
			inst->bits3.generic.msg_target, &space);
	switch (inst->bits3.generic.msg_target) {
	case BRW_MESSAGE_TARGET_MATH:
	    err |= control (file, "math function", math_function,
			    inst->bits3.math.function, &space);
	    err |= control (file, "math saturate", math_saturate,
			    inst->bits3.math.saturate, &space);
	    err |= control (file, "math signed", math_signed,
			    inst->bits3.math.int_type, &space);
	    err |= control (file, "math scalar", math_scalar,
			    inst->bits3.math.data_type, &space);
	    err |= control (file, "math precision", math_precision,
			    inst->bits3.math.precision, &space);
	    break;
	case BRW_MESSAGE_TARGET_SAMPLER:
	    format (file, " (%d, %d, ",
		    inst->bits3.sampler.binding_table_index,
		    inst->bits3.sampler.sampler);
	    err |= control (file, "sampler target format", sampler_target_format,
			    inst->bits3.sampler.return_format, NULL);
	    string (file, ")");
	    break;
	case BRW_MESSAGE_TARGET_DATAPORT_WRITE:
	    format (file, " (%d, %d, %d, %d)",
		    inst->bits3.dp_write.binding_table_index,
		    (inst->bits3.dp_write.pixel_scoreboard_clear << 3) |
		    inst->bits3.dp_write.msg_control,
		    inst->bits3.dp_write.msg_type,
		    inst->bits3.dp_write.send_commit_msg);
	    break;
	case BRW_MESSAGE_TARGET_URB:
	    format (file, " %d", inst->bits3.urb.offset);
	    space = 1;
	    err |= control (file, "urb swizzle", urb_swizzle,
			    inst->bits3.urb.swizzle_control, &space);
	    err |= control (file, "urb allocate", urb_allocate,
			    inst->bits3.urb.allocate, &space);
	    err |= control (file, "urb used", urb_used,
			    inst->bits3.urb.used, &space);
	    err |= control (file, "urb complete", urb_complete,
			    inst->bits3.urb.complete, &space);
	    break;
	case BRW_MESSAGE_TARGET_THREAD_SPAWNER:
	    break;
	default:
	    format (file, "unsupported target %d", inst->bits3.generic.msg_target);
	    break;
	}
	if (space)
	    string (file, " ");
	format (file, "mlen %d",
		inst->bits3.generic.msg_length);
	format (file, " rlen %d",
		inst->bits3.generic.response_length);
    }
    pad (file, 64);
    if (inst->header.opcode != BRW_OPCODE_NOP) {
	string (file, "{");
	space = 1;
	err |= control(file, "access mode", access_mode, inst->header.access_mode, &space);
	err |= control (file, "mask control", mask_ctrl, inst->header.mask_control, &space);
	err |= control (file, "dependency control", dep_ctrl, inst->header.dependency_control, &space);
	err |= control (file, "compression control", compr_ctrl, inst->header.compression_control, &space);
	err |= control (file, "thread control", thread_ctrl, inst->header.thread_control, &space);
	if (inst->header.opcode == BRW_OPCODE_SEND)
	    err |= control (file, "end of thread", end_of_thread,
			    inst->bits3.generic.end_of_thread, &space);
	if (space)
	    string (file, " ");
	string (file, "}");
    }
    string (file, ";");
    newline (file);
    return err;
}
int sc_main (int argc , char *argv[]) {

/*
	int	quantization[64] = { 8,  6,  6,  7,  6,  5,  8,  7,
								 7,  7,  9,  9,  8, 10, 12, 20,
								13, 12, 11, 11, 12, 25, 18, 19,
								15, 20, 29, 26, 31, 30, 29, 26,
								28, 28, 32, 36, 46, 39, 32, 34,
								44, 35, 28, 28, 40, 55, 41, 44,
								48, 49, 52, 52, 52, 31, 39, 57,
								61, 56, 50, 60, 46, 51, 52, 50 };
*/

	int	quantization[64] = { 16, 11, 10, 16, 24, 40, 51, 61,
								 12, 12, 14, 19, 26, 58, 60, 55,
								 14, 13, 16, 24, 40, 57, 69, 56,
								 14, 17, 22, 29, 51, 87, 80, 62,
								 18, 22, 37, 56, 68,109,103, 77,
								 24, 35, 55, 64, 81,104,113, 92,
								 49, 64, 78, 87,103,121,120,101,
								 72, 92, 95, 98,112,100,103, 99};

// definition of default files
	const char*	inputfile		= "datain.pgm";
	const char*	outputfile		= "dataout.pgm";
	const char* typefile 		= "types.txt";

//	definition of FIFO queues
	fifo_stat<int>	stimulus("stimulus",1);
	fifo_stat<int>	parameters("parameters",3);
	fifo_stat<int>	stimulus_dup1("stimulus_dup1",1);
	fifo_stat<int>	stimulus_dup2("stimulus_dup2",MAXWIDTH8*8+64+64+64+64+64);
	fifo_stat<int>	parameters_dup1("parameters_dup1",3);
	fifo_stat<int>	parameters_dup2("parameters_dup2",3);
	fifo_stat<int>	parameters_dup3("parameters_dup3",3);
	// fifo_stat<int>	jpeg_enc_out("jpeg_enc_out",1);
	fifo_stat<int>	jpeg_dec_in("jpeg_dec_in",1);
	fifo_stat<int>	result("result",1);
	fifo_stat<int>	result_dup1("result_dup1",1);
	fifo_stat<int>	result_dup2("result_dup2",1);

  sc_signal<bool> ask,ready;
  sc_signal<sc_int<9> > data;

// processing of command-line arguments
	bool	detected;
	for(int i=3; i<=argc; i+=2) {
		cout << argv[i-2] << " " << argv[i-1] << endl;
		detected = 0;
		if (strcmp(argv[i-2],"-i")==0) {
			inputfile = argv[i-1];
			detected = 1;
		}
		if (strcmp(argv[i-2],"-o")==0) {
			outputfile = argv[i-1];
			detected = 1;
		}
		if (strcmp(argv[i-2],"-t")==0) {
			typefile = argv[i-1];
			detected = 1;
		}
		if (detected == 0) {
			cout << "option " << argv[i-2] << " not known " << endl;
		}
	}

//	definition of modules

  sc_clock clk ( "clock",10, SC_NS ) ;

	src src1("src1", inputfile, MAXWIDTH);
	src1.output(stimulus);
	src1.parameters(parameters);

	df_fork<int,2> fork1("fork1");
	fork1.in(stimulus);
	fork1.out[0](stimulus_dup1);
	fork1.out[1](stimulus_dup2);

	df_fork<int,3> fork_param("fork_param");
	fork_param.in(parameters);
	fork_param.out[0](parameters_dup1);
	fork_param.out[1](parameters_dup2);
	fork_param.out[2](parameters_dup3);

	jpeg_enc jpeg_enc_1("jpeg_enc_1", quantization, MAXWIDTH);
	jpeg_enc_1.input(stimulus_dup1);
	jpeg_enc_1.clk(clk);
	jpeg_enc_1.parameters(parameters_dup1);
	jpeg_enc_1.output(data);
	jpeg_enc_1.ready(ready);
	jpeg_enc_1.ask(ask);
  
  // FF2P<int> FF2P_1("FF2P_1");
  // FF2P_1.input(jpeg_enc_out);
  // FF2P_1.clk(clk);
  // FF2P_1.ask(ask);
  // FF2P_1.ready(ready);
  // FF2P_1.output(data);
  
  // P2FF<int> P2FF_1("P2FF_1");
  // P2FF_1.input(data);
  // P2FF_1.clk(clk);
  // P2FF_1.ask(ask);
  // P2FF_1.ready(ready);
  // P2FF_1.output(jpeg_dec_in);

	jpeg_dec jpeg_dec_1("jpeg_dec_1", quantization, MAXWIDTH, typefile);
	jpeg_dec_1.input(data);
	jpeg_dec_1.clk(clk);
	jpeg_dec_1.ready(ready);
	jpeg_dec_1.ask(ask);
	jpeg_dec_1.parameters(parameters_dup2);
	jpeg_dec_1.output(result);

	df_fork<int,2> fork2("fork2");
	fork2.in(result);
	fork2.out[0](result_dup1);
	fork2.out[1](result_dup2);

	snk snk1("snk1", outputfile);
	snk1.input(result_dup1);
	snk1.parameters(parameters_dup3);

	test test1("test1");
	test1.reference(stimulus_dup2);
	test1.data(result_dup2);

	// sc_start();
	sc_start(200000,SC_NS);

	return 0;
}