コード例 #1
0
ファイル: image_xyz.cpp プロジェクト: FaithFeather/Player
void ImageXYZ::ReadXYZ(const uint8_t* data, unsigned len, bool transparent,
					int& width, int& height, void*& pixels) {
	pixels = NULL;

    if (len < 8) {
		Output::Error("Not a valid XYZ file.");
		return;
    }

    unsigned short w = data[4] + (data[5] << 8);
    unsigned short h = data[6] + (data[7] << 8);

	uLongf src_size = len - 8;
    Bytef* src_buffer = (Bytef*)&data[8];
    uLongf dst_size = 768 + (w * h);
	std::vector<Bytef> dst_buffer(dst_size);

    int status = uncompress(&dst_buffer.front(), &dst_size, src_buffer, src_size);
	if (status != Z_OK) {
		Output::Error("Error decompressing XYZ file.");
		return;
	}
    const uint8_t (*palette)[3] = (const uint8_t(*)[3]) &dst_buffer.front();

	width = w;
	height = h;
	pixels = malloc(w * h * 4);

    uint8_t* dst = (uint8_t*) pixels;
    const uint8_t* src = (const uint8_t*) &dst_buffer[768];
    for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			uint8_t pix = *src++;
			const uint8_t* color = palette[pix];
			*dst++ = color[0];
			*dst++ = color[1];
			*dst++ = color[2];
			*dst++ = (transparent && pix == 0) ? 0 : 255;
		}
    }
}
コード例 #2
0
ファイル: image_compositing.cpp プロジェクト: mapycz/mapnik
MAPNIK_DECL void composite(image_gray32f & dst, image_gray32f const& src, composite_mode_e /*mode*/,
               float /*opacity*/,
               int dx,
               int dy
#ifdef MAPNIK_STATS_RENDER
               , std::ostream * log_stream
#endif
                     )
{
    using const_rendering_buffer = util::rendering_buffer<image_gray32f>;
    using src_pixfmt_type = agg::pixfmt_alpha_blend_gray<agg::blender_gray<agg::gray32>, const_rendering_buffer, 1, 0>;
    using dst_pixfmt_type = agg::pixfmt_alpha_blend_gray<agg::blender_gray<agg::gray32>, agg::rendering_buffer, 1, 0>;
    using renderer_type = agg::renderer_base<dst_pixfmt_type>;

    agg::rendering_buffer dst_buffer(dst.bytes(),safe_cast<unsigned>(dst.width()),safe_cast<unsigned>(dst.height()),safe_cast<int>(dst.width()));
    const_rendering_buffer src_buffer(src);
    dst_pixfmt_type pixf(dst_buffer);
    src_pixfmt_type pixf_mask(src_buffer);
    renderer_type ren(pixf);
    ren.copy_from(pixf_mask,0,dx,dy);
}
コード例 #3
0
void composite(T1 & dst, T2 & src, composite_mode_e mode,
               float opacity,
               int dx,
               int dy,
               bool premultiply_src)
{
    using color = agg::rgba8;
    using order = agg::order_rgba;
    using blender_type = agg::comp_op_adaptor_rgba_pre<color, order>;
    using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
    using renderer_type = agg::renderer_base<pixfmt_type>;

    agg::rendering_buffer dst_buffer(dst.getBytes(),dst.width(),dst.height(),dst.width() * 4);
    agg::rendering_buffer src_buffer(src.getBytes(),src.width(),src.height(),src.width() * 4);

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

    agg::pixfmt_rgba32 pixf_mask(src_buffer);
    if (premultiply_src)  pixf_mask.premultiply();
    renderer_type ren(pixf);
    ren.blend_from(pixf_mask,0,dx,dy,unsigned(255*opacity));
}
コード例 #4
0
ファイル: image_compositing.cpp プロジェクト: mapycz/mapnik
    void operator()(unsigned begin, unsigned end)
    {
        using color = agg::rgba8;
        using order = agg::order_rgba;
        using const_rendering_buffer = util::rendering_buffer<image_rgba8>;
        using blender_type = agg::comp_op_adaptor_rgba_pre<color, order>;
        using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
        using renderer_type = agg::renderer_base<pixfmt_type>;

        agg::rendering_buffer dst_buffer(
            dst.bytes(),
            safe_cast<unsigned>(dst.width()),
            safe_cast<unsigned>(dst.height()),
            safe_cast<int>(dst.row_size()));
        const_rendering_buffer src_buffer(src);
        pixfmt_type pixf(dst_buffer);
        pixf.comp_op(static_cast<agg::comp_op_e>(mode));
        agg::pixfmt_alpha_blend_rgba<agg::blender_rgba32_pre,
                                     const_rendering_buffer,
                                     agg::pixel32_type> pixf_mask(src_buffer);
        renderer_type ren(pixf);
        agg::rect_i src_area(0, begin, src.width() - 1, end - 1);
        ren.blend_from(pixf_mask, &src_area, dx, dy, safe_cast<agg::cover_type>(255 * opacity));
    }