Exemplo n.º 1
0
void
image_set_draw(i32 x, i32 y, ImageSet *set, u16 index, u8 mode, u8 mask)
{
    ASSERT(index < set->count);

    V4i r = v4i_make_size(x - set->pivot_x, y - set->pivot_y, set->cw, set->ch);

    rect_tr(&r, PROGRAM->tx, PROGRAM->ty);
    // clip_rect(&r, &program->bitmap_rect);
    i32 ox = 0;
    i32 oy = 0;
    if (clip_rect_with_offsets(&r, &PROGRAM->bitmap_rect, &ox, &oy))
    {
        i32 w = r.max_x - r.min_x;
        i32 h = r.max_y - r.min_y;
        i32 sw = set->cw;
        i32 sh = set->ch;

        u32 dst_fill = PROGRAM->bitmap_rect.max_x - PROGRAM->bitmap_rect.min_x;
        u8 *dst = PROGRAM->bitmap->data + r.min_x + (r.min_y * dst_fill);

        i32 _x, _y;
        if ((mode & DrawSpriteMode_FlipH) == 0)
        {
            u32 src_fill = sw - w;
            u8 *src = image_set_data(set)
                     + (index * (sw * sh))
                     + (ox + (oy * sw));
            if (mode & DrawSpriteMode_Mask) {
                _BLIT(mask, src++);
            } else {
                _BLIT(*src, src++);
            }
        }
        else
        {
            u32 src_fill = sw + w;
            u8 *src = image_set_data(set)
                     + (index * (sw * sh))
                     + (ox + (oy * sw))
                     + (w - 1);

            if (mode & DrawSpriteMode_Mask) {
                _BLIT(mask, src--);
            } else {
                _BLIT(*src, src--);
            }
        }
    }
}
Exemplo n.º 2
0
static int
image_init (zbarImage *self,
            PyObject *args,
            PyObject *kwds)
{
    int width = -1, height = -1;
    PyObject  *format = NULL, *data = NULL;
    static char *kwlist[] = { "width", "height", "format", "data", NULL };
    if(!PyArg_ParseTupleAndKeywords(args, kwds, "|iiOO", kwlist,
                                    &width, &height, &format, &data))
        return(-1);

    if(width > 0 && height > 0)
        zbar_image_set_size(self->zimg, width, height);
    if(format && image_set_format(self, format, NULL))
        return(-1);
    if(data && image_set_data(self, data, NULL))
        return(-1);
    return(0);
}