Example #1
0
bool THRawBitmap::_checkScaled(THRenderTarget* pCanvas, SDL_Rect& rcDest)
{
    float fFactor;
    if(!pCanvas->shouldScaleBitmaps(&fFactor))
        return false;
    int iScaledWidth = (int)((float)m_pBitmap->w * fFactor);
    if(!m_pCachedScaledBitmap || m_pCachedScaledBitmap->w != iScaledWidth)
    {
        SDL_FreeSurface(m_pCachedScaledBitmap);
        Uint32 iRMask, iGMask, iBMask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        iRMask = 0xff000000;
        iGMask = 0x00ff0000;
        iBMask = 0x0000ff00;
#else
        iRMask = 0x000000ff;
        iGMask = 0x0000ff00;
        iBMask = 0x00ff0000;
#endif

        m_pCachedScaledBitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, iScaledWidth, (int)((float)m_pBitmap->h * fFactor), 24, iRMask, iGMask, iBMask, 0);
        SDL_LockSurface(m_pCachedScaledBitmap);
        SDL_LockSurface(m_pBitmap);

        typedef agg::pixfmt_rgb24_pre pixfmt_pre_t;
        typedef agg::renderer_base<pixfmt_pre_t> renbase_pre_t;
        typedef image_accessor_clip_rgb24_pal8<pixfmt_pre_t> imgsrc_t;
        typedef agg::span_interpolator_linear<> interpolator_t;
        typedef agg::span_image_filter_rgb_2x2<imgsrc_t, interpolator_t> span_gen_type;
        agg::scanline_p8 sl;
        agg::span_allocator<pixfmt_pre_t::color_type> sa;
        agg::image_filter<agg::image_filter_bilinear> filter;
        agg::trans_affine_scaling img_mtx(1.0 / fFactor);
        agg::rendering_buffer rbuf_src(m_pData, m_pBitmap->w, m_pBitmap->h, m_pBitmap->pitch);
        imgsrc_t img_src(rbuf_src, *m_pPalette, agg::rgba(0.0, 0.0, 0.0));
        interpolator_t interpolator(img_mtx);
        span_gen_type sg(img_src, interpolator, filter);
        agg::rendering_buffer rbuf(reinterpret_cast<unsigned char*>(m_pCachedScaledBitmap->pixels), m_pCachedScaledBitmap->w, m_pCachedScaledBitmap->h, m_pCachedScaledBitmap->pitch);
        pixfmt_pre_t pixf_pre(rbuf);
        renbase_pre_t rbase_pre(pixf_pre);
        rasterizer_scanline_rect ras(0, 0, rbuf.width(), rbuf.height());
        rbase_pre.clear(agg::rgba(1.0,0,0,0));
        agg::render_scanlines_aa(ras, sl, rbase_pre, sa, sg);

        SDL_UnlockSurface(m_pBitmap);
        SDL_UnlockSurface(m_pCachedScaledBitmap);
    }
    rcDest.x = (Sint16)((float)rcDest.x * fFactor);
    rcDest.y = (Sint16)((float)rcDest.y * fFactor);
    return true;
}
Example #2
0
    virtual void on_draw()
    {
        pixfmt pixf(rbuf_window());
        renderer_base rb(pixf);

        rb.clear(agg::rgba(1.0, 1.0, 1.0));
        rb.copy_from(rbuf_img(0), 0, 110, 35);

        agg::rasterizer_scanline_aa<> ras;
        agg::scanline_u8 sl;

        agg::rendering_buffer img_rbuf(g_image, 4, 4, 4*4);

        double para[] = { 200, 40, 200+300, 40, 200+300, 40+300, 200, 40+300 };
        agg::trans_affine img_mtx(para, 0,0,4,4);

        typedef agg::span_interpolator_linear<> interpolator_type;
        interpolator_type interpolator(img_mtx);
        agg::span_allocator<agg::rgba8> sa;

        pixfmt img_pixf(img_rbuf);
        typedef agg::image_accessor_clone<pixfmt> img_source_type;
        img_source_type source(img_pixf);

        ras.reset();
        ras.move_to_d(para[0], para[1]);
        ras.line_to_d(para[2], para[3]);
        ras.line_to_d(para[4], para[5]);
        ras.line_to_d(para[6], para[7]);

        switch(m_filters.cur_item())
        {
        case 0:
        {
            typedef agg::span_image_filter_rgba_nn<img_source_type,
                    interpolator_type> span_gen_type;

            span_gen_type sg(source, interpolator);
            agg::render_scanlines_aa(ras, sl, rb, sa, sg);
        }
        break;

        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
        case 13:
        case 14:
        case 15:
        case 16:
        {
            agg::image_filter_lut filter;
            bool norm = m_normalize.status();
            switch(m_filters.cur_item())
            {
            case 1:
                filter.calculate(agg::image_filter_bilinear(),                 norm);
                break;
            case 2:
                filter.calculate(agg::image_filter_bicubic(),                  norm);
                break;
            case 3:
                filter.calculate(agg::image_filter_spline16(),                 norm);
                break;
            case 4:
                filter.calculate(agg::image_filter_spline36(),                 norm);
                break;
            case 5:
                filter.calculate(agg::image_filter_hanning(),                  norm);
                break;
            case 6:
                filter.calculate(agg::image_filter_hamming(),                  norm);
                break;
            case 7:
                filter.calculate(agg::image_filter_hermite(),                  norm);
                break;
            case 8:
                filter.calculate(agg::image_filter_kaiser(),                   norm);
                break;
            case 9:
                filter.calculate(agg::image_filter_quadric(),                  norm);
                break;
            case 10:
                filter.calculate(agg::image_filter_catrom(),                   norm);
                break;
            case 11:
                filter.calculate(agg::image_filter_gaussian(),                 norm);
                break;
            case 12:
                filter.calculate(agg::image_filter_bessel(),                   norm);
                break;
            case 13:
                filter.calculate(agg::image_filter_mitchell(),                 norm);
                break;
            case 14:
                filter.calculate(agg::image_filter_sinc(m_radius.value()),     norm);
                break;
            case 15:
                filter.calculate(agg::image_filter_lanczos(m_radius.value()),  norm);
                break;
            case 16:
                filter.calculate(agg::image_filter_blackman(m_radius.value()), norm);
                break;
            }

            typedef agg::span_image_filter_rgba<img_source_type,
                    interpolator_type> span_gen_type;

            span_gen_type sg(source, interpolator, filter);
            agg::render_scanlines_aa(ras, sl, rb, sa, sg);

            agg::gamma_lut<agg::int8u, agg::int8u, 8, 8> gamma(m_gamma.value());
            pixf.apply_gamma_inv(gamma);

            double x_start = 5.0;
            double x_end   = 195.0;
            double y_start = 235.0;
            double y_end   = initial_height() - 5.0;
            double x_center = (x_start + x_end) / 2;

            agg::path_storage p;
            agg::conv_stroke<agg::path_storage> stroke(p);
            stroke.width(0.8);

            unsigned i;
            for(i = 0; i <= 16; i++)
            {
                double x = x_start + (x_end - x_start) * i / 16.0;
                p.remove_all();
                p.move_to(x+0.5, y_start);
                p.line_to(x+0.5, y_end);
                ras.add_path(stroke);
                agg::render_scanlines_aa_solid(ras, sl, rb,
                                               agg::rgba8(0, 0, 0, i == 8 ? 255 : 100));
            }

            double ys = y_start + (y_end - y_start) / 6.0;
            p.remove_all();
            p.move_to(x_start, ys);
            p.line_to(x_end,   ys);
            ras.add_path(stroke);
            agg::render_scanlines_aa_solid(ras, sl, rb, agg::rgba8(0, 0, 0));

            double radius = filter.radius();
            unsigned n = unsigned(radius * 256 * 2);
            double dx = (x_end - x_start) * radius / 8.0;
            double dy = y_end - ys;

            const agg::int16* weights = filter.weight_array();
            double xs = (x_end + x_start)/2.0 - (filter.diameter() * (x_end - x_start) / 32.0);
            unsigned nn = filter.diameter() * 256;
            p.remove_all();
            p.move_to(xs+0.5, ys + dy * weights[0] / agg::image_filter_scale);
            for(i = 1; i < nn; i++)
            {
                p.line_to(xs + dx * i / n + 0.5,
                          ys + dy * weights[i] / agg::image_filter_scale);
            }
            ras.add_path(stroke);
            agg::render_scanlines_aa_solid(ras, sl, rb, agg::rgba8(100, 0, 0));
        }
        break;
        }

        agg::render_ctrl(ras, sl, rb, m_gamma);
        if(m_filters.cur_item() >= 14)
        {
            agg::render_ctrl(ras, sl, rb, m_radius);
        }
        agg::render_ctrl(ras, sl, rb, m_filters);
        agg::render_ctrl(ras, sl, rb, m_normalize);
    }