예제 #1
0
inline int import_image_data(T2 const& image,
                             WebPPicture & pic,
                             bool alpha)
{
    // Reason for copy: https://github.com/mapnik/mapnik/issues/2024
    // TODO - figure out way to pass view pixels directly to webp importer
    image_data_32 im(image.width(),image.height());
    for (unsigned y = 0; y < image.height(); ++y)
    {
        typename T2::pixel_type const * row_from = image.getRow(y);
        image_data_32::pixel_type * row_to = im.getRow(y);
        for (unsigned x = 0; x < image.width(); ++x)
        {
            row_to[x] = row_from[x];
        }
    }
    int stride = sizeof(typename T2::pixel_type) * im.width();
    if (alpha)
    {
        return WebPPictureImportRGBA(&pic, im.getBytes(), stride);
    }
    else
    {
#if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
        return WebPPictureImportRGBX(&pic, im.getBytes(), stride);
#else
        return WebPPictureImportRGBA(&pic, im.getBytes(), stride);
#endif
    }
}
예제 #2
0
T cmpconv( const T2 &in) {
#pragma HLS inline
	T2 valIn = in;
	T val(valIn.real(), valIn.imag());
return val;

}
예제 #3
0
void UpdateItem(WORD32 dwKey, T2 &vec, T1 *pData)
{
	T1 *pInfo = NULL;
	SNMP_PERF_VEC_IT it;
	for(it = vec.begin(); it != vec.end(); it++)
	{
		if((*it).dwKey == dwKey)
		{
			pInfo = &(*it);
			check_paranullpt(pInfo);
			memset(pInfo, 0, sizeof(*pInfo));
			memcpy(pInfo, pData, sizeof(*pInfo));
			printf("updateitem, update data, key:%#x\n", dwKey);
			return;
		}
	}
	
	// pInfo = new T1();
	pInfo = &g_snmptest;
	check_paranullpt(pInfo);
	memset(pInfo, 0, sizeof(*pInfo));
	memcpy(pInfo, pData, sizeof(*pInfo));
	vec.push_back(*pInfo);
	printf("updateitem, create data, key:%#x, new addr:%p\n", dwKey, pInfo);

}
예제 #4
0
void composite(T1 & im, T2 & im2, composite_mode_e mode,
               float opacity,
               int dx,
               int dy,
               bool premultiply_src,
               bool premultiply_dst)
{
    typedef agg::rgba8 color;
    typedef agg::order_rgba order;
    typedef agg::pixel32_type pixel_type;
    typedef agg::comp_op_adaptor_rgba<color, order> blender_type;
    typedef agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer> pixfmt_type;
    typedef agg::renderer_base<pixfmt_type> renderer_type;

    agg::rendering_buffer source(im.getBytes(),im.width(),im.height(),im.width() * 4);
    agg::rendering_buffer mask(im2.getBytes(),im2.width(),im2.height(),im2.width() * 4);

    pixfmt_type pixf(source);
    pixf.comp_op(static_cast<agg::comp_op_e>(mode));

    agg::pixfmt_rgba32 pixf_mask(mask);
    if (premultiply_src)  pixf_mask.premultiply();
    if (premultiply_dst)  pixf.premultiply();
    renderer_type ren(pixf);
    // TODO - is this really opacity, or agg::cover?
    ren.blend_from(pixf_mask,0, dx,dy,unsigned(255*opacity));
}
예제 #5
0
파일: p7.cpp 프로젝트: ardraeiss/Tutorials
template<class T1, class T2> bool isIntersecting(T1& mA, T2& mB)
{
	return mA.right() >= mB.left() && 
			mA.left() <= mB.right() &&
			mA.bottom() >= mB.top() && 
			mA.top() <= mB.bottom();
}
예제 #6
0
	void add(T1 from, T2 to, Lambda lambda) {
		if (from.empty() || to.empty())
			return;
		size_t iFrom = rand() % from.size();
		size_t iTo = rand() % to.size();
		lambda(iFrom, iTo);
	}
예제 #7
0
  ConstIterator Find(const T2& value)const
  {
	  uint32_t hashCode=value.getHashCode();
	  uint32_t hidx = hashCode%hashSize;

	  Node*const* nodePtr=&hash[hidx];
	  if(!*nodePtr)
		  return ConstIterator(0);

	  if(value.IsSameState(*((*nodePtr)->m_UserState)))
	  {
		  return ConstIterator(this,hidx,*nodePtr,nodePtr);
	  }
	  Node*const* parentPtr=nodePtr;
	  Node* node=(Node*)(*nodePtr)->ihsNextNode;
	  while(node)
	  {
		  if(value.IsSameState(*(node->m_UserState)))
		  {
			  return ConstIterator(this,hidx,node,parentPtr);
		  }
		  parentPtr=nodePtr;
		  nodePtr=(Node**)&node->ihsNextNode;
		  node=(Node*)node->ihsNextNode;
	  }
	  return ConstIterator(0);
  }
예제 #8
0
        static bool compress( T2 &buffer_out, const T1 &buffer_in, bool highest_compression = true )
        {
            static const bool verbose = false;

            bool ret = false;

            if( 1 )
            {
                // resize to worst case
                buffer_out.resize( LZ4_compressBound((int)(buffer_in.size())) );

                // compress
                size_t compressed_size = highest_compression ?
                    LZ4_compressHC( &buffer_in.at(0), &buffer_out.at(0), buffer_in.size() )
                    :
                    LZ4_compress( &buffer_in.at(0), &buffer_out.at(0), buffer_in.size() );

                ret = ( compressed_size > 0 && compressed_size < buffer_in.size() );

                if( ret )
                {
                    // if ok, resize properly to unused space
                    buffer_out.resize( compressed_size );
                }

                if( verbose )
                {
//                    std::cout << moon9::echo( ret, compressed_size, buffer_in.size() );
                }
            }

            return ret;
        }
예제 #9
0
        static bool compress( T2 &buffer_out, const T1 &buffer_in, bool highest_compression = true )
        {
            static const bool verbose = false;

            bool ret = false;

            if( buffer_in.size() >= 70 )
            {
                buffer_out.resize( std::max<size_t>( size_t(buffer_in.size() * 1.05), 70 ) );

                size_t compressed_size = fastlz_compress_level( highest_compression ? 2 : 1, &buffer_in.at(0), buffer_in.size(), &buffer_out.at(0) );

                ret = ( compressed_size > 0 && compressed_size < buffer_in.size() );

                if( ret )
                {
                    buffer_out.resize( compressed_size );
                }

                if( verbose )
                {
//                    std::cout << moon9::echo( ret, compressed_size, buffer_in.size() );
                }
            }

            return ret;
        }
예제 #10
0
 static bool isIntersecting(const T1& mA, const T2& mB) noexcept
 {
     return mA.right()  >= mB.left() 
         && mA.left()   <= mB.right()
         && mA.bottom() >= mB.top() 
         && mA.top()    <= mB.bottom();
 }
예제 #11
0
double SokalSimilarity(const T1& bv1, const T2& bv2) {
  if (bv1.getNumBits() != bv2.getNumBits())
    throw ValueErrorException("BitVects must be same length");
  double x = NumOnBitsInCommon(bv1, bv2);
  double y = bv1.getNumOnBits();
  double z = bv2.getNumOnBits();

  return x / (2 * y + 2 * z - 3 * x);
}
예제 #12
0
void save_as_png8(T1 & file, T2 const& image, T3 const & tree,
                  std::vector<mapnik::rgb> const& palette, std::vector<unsigned> const& alphaTable,
                  int compression = Z_DEFAULT_COMPRESSION, int strategy = Z_DEFAULT_STRATEGY)
{
    unsigned width = image.width();
    unsigned height = image.height();

    if (palette.size() > 16 )
    {
        // >16 && <=256 colors -> write 8-bit color depth
        image_data_8 reduced_image(width, height);

        for (unsigned y = 0; y < height; ++y)
        {
            mapnik::image_data_32::pixel_type const * row = image.getRow(y);
            mapnik::image_data_8::pixel_type  * row_out = reduced_image.getRow(y);

            for (unsigned x = 0; x < width; ++x)
            {
                row_out[x] = tree.quantize(row[x]);
            }
        }
        save_as_png(file, palette, reduced_image, width, height, 8, compression, strategy, alphaTable);
    }
    else if (palette.size() == 1)
    {
        // 1 color image ->  write 1-bit color depth PNG
        unsigned image_width  = width > 7 ? (int(0.125*width) + 1)&~1 : 1;
        unsigned image_height = height;
        image_data_8 reduced_image(image_width, image_height);
        reduced_image.set(0);
        save_as_png(file, palette, reduced_image, width, height, 1, compression, strategy, alphaTable);
    }
    else
    {
        // <=16 colors -> write 4-bit color depth PNG
        unsigned image_width  = width > 3 ? (int(0.5*width) + 3)&~3 : 4;
        unsigned image_height = height;
        image_data_8 reduced_image(image_width, image_height);
        for (unsigned y = 0; y < height; ++y)
        {
            mapnik::image_data_32::pixel_type const * row = image.getRow(y);
            mapnik::image_data_8::pixel_type  * row_out = reduced_image.getRow(y);
            byte index = 0;

            for (unsigned x = 0; x < width; ++x)
            {

                index = tree.quantize(row[x]);
                if (x%2 == 0) index = index<<4;
                row_out[x>>1] |= index;
            }
        }
        save_as_png(file, palette, reduced_image, width, height, 4, compression, strategy, alphaTable);
    }
}
    int getSmallestDACIndexInScope(int forbiddenScopeIndex)
	{
        assert(forbiddenScopeIndex >= 0); assert(forbiddenScopeIndex < 3);
		switch (forbiddenScopeIndex) {
            case 0: return min(y->getDACOrder(),z->getDACOrder()); break;
            case 1: return min(x->getDACOrder(),z->getDACOrder()); break;
            case 2: return min(x->getDACOrder(),y->getDACOrder()); break;
            default: exit(EXIT_FAILURE);
        }
	}
예제 #14
0
DoubleVect OffBitProjSimilarity(const T1& bv1, const T2& bv2) {
  if (bv1.getNumBits() != bv2.getNumBits())
    throw ValueErrorException("BitVects must be same length");
  DoubleVect res(2, 0.0);
  double num = (bv1 | bv2).getNumOffBits();
  if (num) {
    res[0] = num / bv1.getNumOffBits();
    res[1] = num / bv2.getNumOffBits();
  }
  return res;
}
예제 #15
0
double TanimotoSimilarity(const T1& bv1, const T2& bv2) {
  if (bv1.getNumBits() != bv2.getNumBits())
    throw ValueErrorException("BitVects must be same length");
  double x = NumOnBitsInCommon(bv1, bv2);
  double y = bv1.getNumOnBits();
  double z = bv2.getNumOnBits();
  if ((y + z - x) == 0.0)
    return 1.0;
  else
    return x / (y + z - x);
}
예제 #16
0
   void save_as_jpeg(T1 & file,int quality, T2 const& image)
   {  
      struct jpeg_compress_struct cinfo;
      struct jpeg_error_mgr jerr;

      int width=image.width();
      int height=image.height();
	
      cinfo.err = jpeg_std_error(&jerr);
      jpeg_create_compress(&cinfo);
    
      cinfo.dest = (struct jpeg_destination_mgr *)(*cinfo.mem->alloc_small)
         ((j_common_ptr) &cinfo, JPOOL_PERMANENT, sizeof(dest_mgr));
      dest_mgr * dest = (dest_mgr*) cinfo.dest;
      dest->pub.init_destination = init_destination;
      dest->pub.empty_output_buffer = empty_output_buffer;
      dest->pub.term_destination = term_destination;
      dest->out = &file;
      
      //jpeg_stdio_dest(&cinfo, fp);
      cinfo.image_width = width;
      cinfo.image_height = height;
      cinfo.input_components = 3;
      cinfo.in_color_space = JCS_RGB; 
      jpeg_set_defaults(&cinfo);
      jpeg_set_quality(&cinfo, quality,1);
      jpeg_start_compress(&cinfo, 1);
      JSAMPROW row_pointer[1];
      JSAMPLE* row=reinterpret_cast<JSAMPLE*>( ::operator new (sizeof(JSAMPLE) * width*3));
      while (cinfo.next_scanline < cinfo.image_height) 
      {
         const unsigned* imageRow=image.getRow(cinfo.next_scanline);
         int index=0;
         for (int i=0;i<width;++i)
         {
#ifdef MAPNIK_BIG_ENDIAN
            row[index++]=(imageRow[i]>>24)&0xff;
            row[index++]=(imageRow[i]>>16)&0xff;
            row[index++]=(imageRow[i]>>8)&0xff;
#else
            row[index++]=(imageRow[i])&0xff;
            row[index++]=(imageRow[i]>>8)&0xff;
            row[index++]=(imageRow[i]>>16)&0xff;
#endif
         }
         row_pointer[0] = &row[0];
         (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
      }
      ::operator delete(row);
      
      jpeg_finish_compress(&cinfo);
      jpeg_destroy_compress(&cinfo);
   }  
예제 #17
0
 inline bool check_multiplicable(const char* function,
                                 const char* name1,
                                 const T1& y1,
                                 const char* name2,
                                 const T2& y2) {
   check_positive_size(function, name1, "rows()", y1.rows());
   check_positive_size(function, name2, "cols()", y2.cols());
   check_size_match(function,
                    "Columns of ", name1, y1.cols(),
                    "Rows of ", name2, y2.rows());
   check_positive_size(function, name1, "cols()", y1.cols());
   return true;
 }
예제 #18
0
  inline void tensor_product(const T1& v1, const T2& v2, T3& m)
  {
    cf3_assert(m.getNbRows()    == v1.size());
    cf3_assert(m.getNbColumns() == v2.size());

    const Uint v1size = v1.size();
    const Uint v2size = v2.size();
    for (Uint i = 0; i < v1size; ++i) {
      for (Uint j = 0; j < v2size; ++j) {
        m(i,j) = v1[i]*v2[j];
      }
    }
  }
예제 #19
0
double RogotGoldbergSimilarity(const T1& bv1, const T2& bv2) {
  if (bv1.getNumBits() != bv2.getNumBits())
    throw ValueErrorException("BitVects must be same length");
  double x = NumOnBitsInCommon(bv1, bv2);
  double y = bv1.getNumOnBits();
  double z = bv2.getNumOnBits();
  double l = bv1.getNumBits();
  double d = l - y - z + x;
  if ((x == l) || (d == l))
    return 1.0;
  else
    return (x / (y + z) + (d) / (2 * l - y - z));
}
예제 #20
0
double BraunBlanquetSimilarity(const T1& bv1, const T2& bv2) {
  if (bv1.getNumBits() != bv2.getNumBits())
    throw ValueErrorException("BitVects must be same length");
  double x = NumOnBitsInCommon(bv1, bv2);
  double y = bv1.getNumOnBits();
  double z = bv2.getNumOnBits();

  if (tmax(y, z) > 0) {
    return x / tmax(y, z);
  } else {
    return 0.0;
  }
}
예제 #21
0
static void add_vector(T& A, T2& B, const T3& V, const int a, const int b) {
	      typename T::value_type * restrict A1ptr = B.get_tile_unitialized(a,b);
	const typename T::value_type * restrict Aptr  = A.get_tile(a,b);
	
	for (int i=0; i<TILE_SIZE; ++i) {
		for (int j=0; j<TILE_SIZE; ++j) {
			A1ptr[i*TILE_SIZE+j] = Aptr[i*TILE_SIZE+j] + V[a*TILE_SIZE+i];
		}
	}
	
	
	B.set_tile(A1ptr, a, b);
}
예제 #22
0
double CosineSimilarity(const T1& bv1, const T2& bv2) {
  if (bv1.getNumBits() != bv2.getNumBits())
    throw ValueErrorException("BitVects must be same length");
  double x = NumOnBitsInCommon(bv1, bv2);
  double y = bv1.getNumOnBits();
  double z = bv2.getNumOnBits();

  if (y * z > 0.0) {
    return x / sqrt(y * z);
  } else {
    return 0.0;
  }
}
예제 #23
0
double McConnaugheySimilarity(const T1& bv1, const T2& bv2) {
  if (bv1.getNumBits() != bv2.getNumBits())
    throw ValueErrorException("BitVects must be same length");
  double x = NumOnBitsInCommon(bv1, bv2);
  double y = bv1.getNumOnBits();
  double z = bv2.getNumOnBits();

  if (y * z > 0.0) {
    return (x * (y + z) - (y * z)) / (y * z);
  } else {
    return 0.0;
  }
}
예제 #24
0
void insertSort( T1& nums, T2& vecnum)
{
	for(auto lit = nums.begin(); lit!=nums.end(); lit++)
	{
		if(vecnum.size()==0) vecnum.push_back(*lit);
		else
		{
			auto vit = vecnum.begin(); //vector iterator
			while(*vit<*lit && vit!=vecnum.end())
				vit++;
			vecnum.insert(vit, *lit);
		}
	}
}
예제 #25
0
double TverskySimilarity(const T1& bv1, const T2& bv2, double a, double b) {
  RANGE_CHECK(0, a, 1);
  RANGE_CHECK(0, b, 1);
  if (bv1.getNumBits() != bv2.getNumBits())
    throw ValueErrorException("BitVects must be same length");
  double x = NumOnBitsInCommon(bv1, bv2);
  double y = bv1.getNumOnBits();
  double z = bv2.getNumOnBits();
  double denom = a * y + b * z + (1 - a - b) * x;
  if (denom == 0.0)
    return 1.0;
  else
    return x / denom;
}
예제 #26
0
void save_as_png(T1 & file,
                T2 const& image,
                png_options const& opts)

{
    png_voidp error_ptr=0;
    png_structp png_ptr=png_create_write_struct(PNG_LIBPNG_VER_STRING,
                                                error_ptr,0, 0);

    if (!png_ptr) return;

    // switch on optimization only if supported
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200) && defined(PNG_MMX_CODE_SUPPORTED)
    png_uint_32 mask, flags;
    flags = png_get_asm_flags(png_ptr);
    mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
    png_set_asm_flags(png_ptr, flags | mask);
#endif
    png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_FILTER_NONE);
    png_infop info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr)
    {
        png_destroy_write_struct(&png_ptr,static_cast<png_infopp>(0));
        return;
    }
    jmp_buf* jmp_context = static_cast<jmp_buf*>(png_get_error_ptr(png_ptr));
    if (jmp_context)
    {
        png_destroy_write_struct(&png_ptr, &info_ptr);
        return;
    }
    png_set_write_fn (png_ptr, &file, &write_data<T1>, &flush_data<T1>);

    png_set_compression_level(png_ptr, opts.compression);
    png_set_compression_strategy(png_ptr, opts.strategy);
    png_set_compression_buffer_size(png_ptr, 32768);

    png_set_IHDR(png_ptr, info_ptr,image.width(),image.height(),8,
                 (opts.trans_mode == 0) ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGB_ALPHA,PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT);
    const std::unique_ptr<png_bytep[]> row_pointers(new png_bytep[image.height()]);
    for (unsigned int i = 0; i < image.height(); i++)
    {
        row_pointers[i] = const_cast<png_bytep>(reinterpret_cast<const unsigned char *>(image.get_row(i)));
    }
    png_set_rows(png_ptr, info_ptr, row_pointers.get());
    png_write_png(png_ptr, info_ptr, (opts.trans_mode == 0) ? PNG_TRANSFORM_STRIP_FILLER_AFTER : PNG_TRANSFORM_IDENTITY, nullptr);
    png_destroy_write_struct(&png_ptr, &info_ptr);
}
예제 #27
0
        static bool decompress( T2 &buffer_out, const T1 &buffer_in )
        {
            static const bool verbose = false;

            size_t bytes_read = LZ4_uncompress( &buffer_in.at(0), &buffer_out.at(0), buffer_out.size() );

            bool ret = ( bytes_read == buffer_in.size() );

            if( verbose )
            {
//                std::cout << moon9::echo( ret, decompressed_size, buffer_out.size() );
            }

            return ret;
        }
예제 #28
0
typename T1::ScalarType scalarProduct(const T1& v1,const T2& v2)
{
  if(v1.dimension()!=v2.dimension())
    throw std::range_error("chomp::vectalg::scalarProduct: Incompatible dimensions");
  typename T1::ScalarType result(0);
  typename T1::const_iterator b1=v1.begin();
  typename T2::const_iterator b2=v2.begin(), e2=v2.end();
  while(b2!=e2)
  {
    result += (*b1) * (*b2);
    ++b1;
    ++b2;
  }
  return result;
}
예제 #29
0
파일: webp_io.hpp 프로젝트: cquest/mapnik
inline int import_image(T2 const& im_in,
                             WebPPicture & pic,
                             bool alpha)
{
    image<typename T2::pixel> const& data = im_in.data();
    std::size_t width = im_in.width();
    std::size_t height = im_in.height();
    std::size_t stride = sizeof(typename T2::pixel_type) * width;
    if (data.width() == width &&
        data.height() == height)
    {
        if (alpha)
        {
            return WebPPictureImportRGBA(&pic, data.bytes(), static_cast<int>(stride));
        }
        else
        {
    #if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
            return WebPPictureImportRGBX(&pic, data.bytes(), static_cast<int>(stride));
    #else
            return WebPPictureImportRGBA(&pic, data.bytes(), static_cast<int>(stride));
    #endif
        }
    }
    else
    {
        // need to copy: https://github.com/mapnik/mapnik/issues/2024
        image_rgba8 im(width,height);
        for (unsigned y = 0; y < height; ++y)
        {
            typename T2::pixel_type const * row_from = im_in.get_row(y);
            image_rgba8::pixel_type * row_to = im.get_row(y);
            std::copy(row_from, row_from + width, row_to);
        }
        if (alpha)
        {
            return WebPPictureImportRGBA(&pic, im.bytes(), static_cast<int>(stride));
        }
        else
        {
    #if (WEBP_ENCODER_ABI_VERSION >> 8) >= 1
            return WebPPictureImportRGBX(&pic, im.bytes(), static_cast<int>(stride));
    #else
            return WebPPictureImportRGBA(&pic, im.bytes(), static_cast<int>(stride));
    #endif
        }
    }
}
 multiple_unique_lock2(T1& m1, T2& m2) :
     m_p1(boost::addressof(m1)),
     m_p2(boost::addressof(m2))
 {
     std::less< void* > order;
     if (order(m_p1, m_p2))
     {
         m_p1->lock();
         m_p2->lock();
     }
     else
     {
         m_p2->lock();
         m_p1->lock();
     }
 }