Ejemplo n.º 1
0
static Ret ftk_canvas_default_draw_bitmap_normal(FtkCanvas* thiz, FtkBitmap* bitmap, FtkRect* s, FtkRect* d)
{
    int i = 0;
    int j = 0;
    int k = 0;
    int x = s->x;
    int y = s->y;
    int w = s->width;
    int h = s->height;
    int xoffset = d->x;
    int yoffset = d->y;
    FtkColor* src = NULL;
    FtkColor* dst = NULL;
    FtkColor* psrc = NULL;
    FtkColor* pdst = NULL;
    unsigned char alpha = 0;
    DECL_PRIV(thiz, priv);
    int width  = priv->w;
    int height = priv->h;
    int bitmap_width   = ftk_bitmap_width(bitmap);
    int bitmap_height  = ftk_bitmap_height(bitmap);

    return_val_if_fail(thiz != NULL && bitmap != NULL, RET_FAIL);
    return_val_if_fail(x < bitmap_width, RET_FAIL);
    return_val_if_fail(y < bitmap_height, RET_FAIL);
    return_val_if_fail(xoffset < width, RET_FAIL);
    return_val_if_fail(yoffset < height, RET_FAIL);

    src = ftk_bitmap_lock(bitmap);
    dst = priv->bits;

    w = (x + w) < bitmap_width  ? w : bitmap_width - x;
    w = (xoffset + w) < width  ? w : width  - xoffset;
    h = (y + h) < bitmap_height ? h : bitmap_height - y;
    h = (yoffset + h) < height ? h : height - yoffset;

    w += x;
    h += y;

    src += y * bitmap_width;
    dst += yoffset * width;

    if(thiz->gc.mask & FTK_GC_ALPHA)
    {
        for(i = y; i < h; i++)
        {
            for(j = x, k = xoffset; j < w; j++, k++)
            {
                pdst = dst+k;
                psrc = src+j;
                alpha = (psrc->a * thiz->gc.alpha) >> 8;
                PUT_PIXEL(pdst, psrc, alpha);
            }
            src += bitmap_width;
            dst += width;
        }
    }
    else
    {
        for(i = y; i < h; i++)
Ejemplo n.º 2
0
static Ret ftk_canvas_default_draw_hline(FtkCanvas* thiz, int x, int y, int w)
{
    int i = 0;
    int width = 0;
    int height = 0;
    FtkColor* bits = NULL;
    unsigned char alpha = 0;
    FtkColor* pdst = NULL;
    FtkColor* color = NULL;
    DECL_PRIV(thiz, priv);
    width  = priv->w;
    height = priv->h;
    bits   = priv->bits;
    return_val_if_fail(bits != NULL && x < width, RET_FAIL);
    return_val_if_fail(y < height, RET_FAIL);
    alpha = thiz->gc.mask & FTK_GC_ALPHA ? thiz->gc.alpha :  thiz->gc.fg.a;

    x = x < 0 ? 0 : x;
    y = y < 0 ? 0 : y;
    w = (x + w) < width ? w : width - x;
    color = &(thiz->gc.fg);
    pdst = bits + y * width + x;

    for(i = w; i > 0; i--, pdst++)
    {
        PUT_PIXEL(pdst, color, alpha);
    }

    return RET_OK;
}
Ejemplo n.º 3
0
static Ret ftk_canvas_default_draw_vline(FtkCanvas* thiz, int x, int y, int h)
{
    int i = 0;
    int width = 0;
    int height = 0;
    FtkColor* bits = NULL;
    unsigned char alpha = 0;
    FtkColor* pdst = NULL;
    FtkColor* color = NULL;
    DECL_PRIV(thiz, priv);
    width  = priv->w;
    height = priv->h;
    bits   = priv->bits;
    return_val_if_fail(bits != NULL && y < height, RET_FAIL);
    alpha = thiz->gc.mask & FTK_GC_ALPHA ? thiz->gc.alpha :  thiz->gc.fg.a;

    x = x < 0 ? 0 : x;
    y = y < 0 ? 0 : y;
    h = (y + h) < height ? h : (height - y);

    pdst = bits + width * y + x;
    color = &(thiz->gc.fg);

    for(i = h; i > 0; i--, pdst+=width)
    {
        PUT_PIXEL(pdst, color, alpha);
    }

    return RET_OK;
}
Ejemplo n.º 4
0
void convertYUV444ToRGB(byte *dstPtr, int dstPitch, const YUVToRGBLookup *lookup, int16 *colorTab, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) {
	// Keep the tables in pointers here to avoid a dereference on each pixel
	const int16 *Cr_r_tab = colorTab;
	const int16 *Cr_g_tab = Cr_r_tab + 256;
	const int16 *Cb_g_tab = Cr_g_tab + 256;
	const int16 *Cb_b_tab = Cb_g_tab + 256;
	const uint32 *rgbToPix = lookup->getRGBToPix();

	for (int h = 0; h < yHeight; h++) {
		for (int w = 0; w < yWidth; w++) {
			register const uint32 *L;

			int16 cr_r  = Cr_r_tab[*vSrc];
			int16 crb_g = Cr_g_tab[*vSrc] + Cb_g_tab[*uSrc];
			int16 cb_b  = Cb_b_tab[*uSrc];
			++uSrc;
			++vSrc;

			PUT_PIXEL(*ySrc, dstPtr);
			ySrc++;
			dstPtr += sizeof(PixelInt);
		}

		dstPtr += dstPitch - yWidth * sizeof(PixelInt);
		ySrc += yPitch - yWidth;
		uSrc += uvPitch - yWidth;
		vSrc += uvPitch - yWidth;
	}
}
Ejemplo n.º 5
0
void MoviePlayer::drawTextObject(uint32 index, Graphics::Surface *screen, uint16 pitch) {
	MovieText *text = &_movieTexts[index];

	uint32 white = getWhiteColor();
	uint32 black = getBlackColor();

	if (text->_textMem && _textSurface) {
		byte *src = text->_textSprite.data;
		uint16 width = text->_textSprite.w;
		uint16 height = text->_textSprite.h;

		// Resize text sprites for PSX version
		byte *psxSpriteBuffer = 0;
		if (Sword2Engine::isPsx()) {
			height *= 2;
			psxSpriteBuffer = (byte *)malloc(width * height);
			Screen::resizePsxSprite(psxSpriteBuffer, src, width, height);
			src = psxSpriteBuffer;
		}

		for (int y = 0; y < height; y++) {
			byte *dst = (byte *)screen->getBasePtr(_textX, _textY + y);

			for (int x = 0; x < width; x++) {
				if (src[x] == 1) {
					PUT_PIXEL(black);
				} else if (src[x] == 255) {
					PUT_PIXEL(white);
				}

				dst += screen->format.bytesPerPixel;
			}

			src += width;
		}

		// Free buffer used to resize psx sprite
		if (Sword2Engine::isPsx())
			free(psxSpriteBuffer);
	}
}
Ejemplo n.º 6
0
void convertYUV420ToRGB(byte *dstPtr, int dstPitch, const YUVToRGBLookup *lookup, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) {
	int halfHeight = yHeight >> 1;
	int halfWidth = yWidth >> 1;

	// Keep the tables in pointers here to avoid a dereference on each pixel
	const int16 *Cr_r_tab = lookup->_colorTab;
	const int16 *Cr_g_tab = Cr_r_tab + 256;
	const int16 *Cb_g_tab = Cr_g_tab + 256;
	const int16 *Cb_b_tab = Cb_g_tab + 256;
	const uint32 *rgbToPix = lookup->_rgbToPix;

	for (int h = 0; h < halfHeight; h++) {
		for (int w = 0; w < halfWidth; w++) {
			register const uint32 *L;

			int16 cr_r  = Cr_r_tab[*vSrc];
			int16 crb_g = Cr_g_tab[*vSrc] + Cb_g_tab[*uSrc];
			int16 cb_b  = Cb_b_tab[*uSrc];
			++uSrc;
			++vSrc;

			PUT_PIXEL(*ySrc, dstPtr);
			PUT_PIXEL(*(ySrc + yPitch), dstPtr + dstPitch);
			ySrc++;
			dstPtr += sizeof(PixelInt);
			PUT_PIXEL(*ySrc, dstPtr);
			PUT_PIXEL(*(ySrc + yPitch), dstPtr + dstPitch);
			ySrc++;
			dstPtr += sizeof(PixelInt);
		}

		dstPtr += dstPitch;
		ySrc += (yPitch << 1) - yWidth;
		uSrc += uvPitch - halfWidth;
		vSrc += uvPitch - halfWidth;
	}
}
Ejemplo n.º 7
0
static Ret ftk_canvas_default_draw_pixels(FtkCanvas* thiz, FtkPoint* points, int nr)
{
    int x = 0;
    int y = 0;
    int i = 0;
    DECL_PRIV(thiz, priv);
    FtkColor* pdst = NULL;
    FtkColor* color = &(thiz->gc.fg);
    FtkRect clip = priv->clip->rect;
    unsigned char alpha = thiz->gc.mask & FTK_GC_ALPHA ? thiz->gc.alpha :  thiz->gc.fg.a;

    for(i = 0; i < nr; i++)
    {
        x = points[i].x;
        y = points[i].y;
        if(FTK_POINT_IN_RECT(x, y, clip))
        {
            pdst = priv->bits + y * priv->w + x;
            PUT_PIXEL(pdst, color, alpha);
        }
    }

    return RET_OK;
}
Ejemplo n.º 8
0
static Ret ftk_canvas_default_draw_normal_line(FtkCanvas* thiz, int x1, int y1, int x2, int y2)
{
    int v = 0;
    int x = 0;
    int y = 0;
    int dx = abs(x2 - x1);
    int dy = abs(y2 - y1);
    int direction = 0;
    int inc_x = 0;
    int inc_y = 0;
    int cur_x = x1;
    int cur_y = y1;
    int two_dy = 0;
    int two_dy_dx = 0;
    int init_d = 0;
    DECL_PRIV(thiz, priv);
    FtkColor* pdst = NULL;
    FtkColor* color = &(thiz->gc.fg);
    unsigned char alpha = thiz->gc.mask & FTK_GC_ALPHA ? thiz->gc.alpha :  thiz->gc.fg.a;

    if (dx < dy)
    {
        // y direction is step direction
        swap_int(x1, y1);
        swap_int(dx, dy);
        swap_int(x2, y2);
        direction = 1;
    }

    // calculate the x, y increment
    inc_x = (x2 - x1) > 0  ? 1 : -1;
    inc_y = (y2 - y1) > 0  ? 1 : -1;

    cur_x = x1;
    cur_y = y1;
    two_dy = 2 * dy;
    two_dy_dx = 2 * (dy - dx);
    init_d = 2 * dy - dx;

    while (cur_x !=  x2)  // cur_x == x2 can not use in bitmap
    {
        if(init_d < 0)
        {
            init_d += two_dy;
        }
        else
        {
            cur_y += inc_y;
            init_d += two_dy_dx;
        }
        if (direction)
        {
            x = cur_y;
            y = cur_x;
        }
        else
        {
            x = cur_x;
            y = cur_y;
        }
        pdst = priv->bits + y * priv->w + x;
        PUT_PIXEL(pdst, color, alpha);

        cur_x += inc_x;
    }

    return RET_OK;
}