Ejemplo n.º 1
0
Fl_Image *make_bg(int w, int h)
{
#ifdef GENERATE_16BIT
    Fl_Image *ret = new Fl_Image(w, h, 16, 0, true, 0x0000F000, 0x00000F00, 0x000000F0, 0x0000000F);
#else
    Fl_Image *ret = new Fl_Image(w, h, 32, 0, true, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
#endif

    printf("BG Format:\n Rmask: 0x%08x\n Gmask: 0x%08x\n Bmask: 0x%08x\n", ret->format()->Rmask, ret->format()->Gmask, ret->format()->Bmask);

    // pitch = WORD alignment bits per line
    int pitch=Fl_Renderer::calc_pitch(ret->format()->bytespp, w);
    int skip = pitch - w * ret->format()->bytespp;

    uint8 *p = ret->data();
    uint8 r,g,b;

    for (int y = 0; y < h; y++) {
        double Y = double(y)/(h-1);
        for (int x = 0; x < w; x++) {
            double X = double(x)/(w-1);
            r = uchar(255*((1-X)*(1-Y))); // red in upper-left
            g = uchar(255*((1-X)*Y));	// green in lower-left
            b = uchar(255*(X*Y));	// blue in lower-right
            fl_assemble_rgb(p,
                            ret->format()->bytespp, ret->format(),
                            r, g, b);
            p+=ret->format()->bytespp;
        }
        p+=skip;
    }
    return ret;
}
Ejemplo n.º 2
0
Fl_Image *Fl_Image_Filter::apply_to_new(Fl_Image *image, Fl_Rect *rect, Fl_Image_Filter *filter, float val1, float val2, float val3)
{
    Fl_Rect r(0,0,image->width(),image->height());
    if(!rect) { rect = &r; }
    Fl_Image *ret = new Fl_Image(*image);

    uint8 *data = ret->data();
    if(!filter->execute(&data, *rect, ret->pitch(), ret->format(), val1, val2, val3)) {
        delete ret;
        return 0;
    }
    return ret;
}
Ejemplo n.º 3
0
Fl_Image *Fl_Image::scale(int W, int H)
{
    Fl_Image *ret = new Fl_Image(W, H, bitspp());
    ret->format()->copy(format());

    Fl_Rect olds(0,0,width(),height()); Fl_Rect news(0,0,W,H);
    bool success = Fl_Renderer::stretch(m_data, bytespp(), pitch(), &olds,
                                        ret->data(), bytespp(), ret->pitch(), &news);
    if(!success) {
        delete ret;
        ret = 0;
    }
    return ret;
}
Ejemplo n.º 4
0
WPaper *make_image(Fl_Color bg_color,
                     Fl_Image *im,
                     int w, int h,
                     int mode,
                     uchar opacity=255)
{
    // secret box render function from Fl_Image :)
    extern uint8 *render_box(int w, int h, int bitspp, uint color, Fl_Colormap *pal, uint8 *buffer);

    Fl_PixelFormat *fmt = Fl_Renderer::system_format();
    WPaper *bg_image = new WPaper(w, h, Fl_Renderer::system_format());

    int iw=im->width(), ih=im->height();
    int ix=0, iy=0;
    int xoff=0, yoff=0;
    Fl_Image *newim = im;

    switch(mode) {
    //CENTER
    case 0: {
        ix=(w/2)-(iw/2);
        iy=(h/2)-(ih/2);
        if(ix<0) xoff=-ix; if(iy<0) yoff=-iy;
        if(ix<0) ix=0; if(iy<0) iy=0;
    }
    break;

    //STRECH
    case 1: {
        ix=0, iy=0, iw=w, ih=h;
        if(w!=im->width()||h!=im->height()) {
            newim = im->scale(w,h);
        }
    }
    break;

    //STRETCH ASPECT
    case 2: {
        int pbw = w, pbh = h;
        iw = pbw;
        ih = iw * im->height() / im->width();
        if(ih > pbh) {
            ih = pbh;
            iw = ih * im->width() / im->height();
        }
        ix=(w/2)-(iw/2), iy=(h/2)-(ih/2);
        if(ix<0) ix=0; if(iy<0) iy=0;
        if(iw>w) iw=w; if(ih>h) ih=h;
        if(iw!=im->width()||ih!=im->height()) {
            newim = im->scale(iw,ih);
        }
    }
    break;
    }

    // This could be an option, opacity
    newim->format()->alpha = opacity;

    if( (iw<w || ih<h) || newim->format()->alpha!=255) {
        // If image doesnt fill the whole screen, or opacity < 255
        // fill image first with bg color.
        render_box(w, h, fmt->bitspp, bg_color, fmt->palette, bg_image->data());
    }

    if(iw>w) iw=w; if(ih>h) ih=h;
    Fl_Rect r(xoff, yoff, iw, ih);
    Fl_Rect r2(ix,iy, iw, ih);

    if(newim->format()->alpha>0) {
        // Blit image data to our bg_image
        bg_image->check_map(newim->format());
        Fl_Renderer::alpha_blit(newim->data(), &r, newim->format(), newim->pitch(),
                                bg_image->data(), &r2, bg_image->format(), bg_image->pitch(),
                                0);
    }

    if(newim!=im)
        delete newim;

    return bg_image;
}
Ejemplo n.º 5
0
Fl_Image *make_ball(int radius)
{
    uint8  trans, alphamask;
    int    range, addition;
    int    xdist, ydist;
    uint16 x, y;
    uint16 skip;
    uint32 pixel;
    Fl_Image *light;

#ifdef GENERATE_16BIT
    uint16 *buf;
    /* Create a 16 (4/4/4/4) bpp square with a full 4-bit alpha channel */
    /* Note: this isn't any faster than a 32 bit alpha surface */
    alphamask = 0x0000000F;
    light = new Fl_Image(2*radius, 2*radius, 16, 0, true,
                         0x0000F000, 0x00000F00, 0x000000F0, alphamask);
#else
    uint32 *buf;
    /* Create a 32 (8/8/8/8) bpp square with a full 8-bit alpha channel */
    alphamask = 0x000000FF;
    light = new Fl_Image(2*radius, 2*radius, 32, 0, true,
                         0xFF000000, 0x00FF0000, 0x0000FF00, alphamask);
#endif

    /* Fill with a light yellow-orange color */
    skip = light->pitch()-(light->width()*light->format()->bytespp);
#ifdef GENERATE_16BIT
    buf = (uint16 *)light->data();
#else
    buf = (uint32 *)light->data();
#endif
    /* Get a tranparent pixel value - we'll add alpha later */
    pixel = light->format()->map_rgba(0xFF, 0xDD, 0x88, 0);
    for ( y=0; y<light->height(); ++y ) {
        for ( x=0; x<light->width(); ++x ) {
            *buf++ = pixel;
        }
        buf += skip;	/* Almost always 0, but just in case... */
    }

    /* Calculate alpha values for the surface. */
#ifdef GENERATE_16BIT
    buf = (uint16 *)light->data();
#else
    buf = (uint32 *)light->data();
#endif
    for ( y=0; y<light->height(); ++y ) {
        for ( x=0; x<light->width(); ++x ) {
            /* Slow distance formula (from center of light) */
            xdist = x-(light->width()/2);
            ydist = y-(light->height()/2);
            range = (int)sqrt(xdist*xdist+ydist*ydist);

            /* Scale distance to range of transparency (0-255) */
            if ( range > radius ) {
                trans = alphamask;
            } else {
                /* Increasing transparency with distance */
                trans = (uint8)((range*alphamask)/radius);

                /* Lights are very transparent */
                addition = (alphamask+1)/16;
                if ( (int)trans+addition > alphamask ) {
                    trans = alphamask;
                } else {
                    trans += addition;
                }
            }
            /* We set the alpha component as the right N bits */
            *buf++ |= (255-trans);
        }
        buf += skip;	/* Almost always 0, but just in case... */
    }

    return light;
}