Exemple #1
0
bool PicPxIsEdge(const Pic *pic, const Vec2i pos, const bool isPixel)
{
	const bool isTopOrBottomEdge = pos.y == -1 || pos.y == pic->size.y;
	const bool isLeftOrRightEdge = pos.x == -1 || pos.x == pic->size.x;
	const bool isLeft =
		pos.x > 0 && !isTopOrBottomEdge &&
		PIXEL2COLOR(*(pic->Data + pos.x - 1 + pos.y * pic->size.x)).a;
	const bool isRight =
		pos.x < pic->size.x - 1 && !isTopOrBottomEdge &&
		PIXEL2COLOR(*(pic->Data + pos.x + 1 + pos.y * pic->size.x)).a;
	const bool isAbove =
		pos.y > 0 && !isLeftOrRightEdge &&
		PIXEL2COLOR(*(pic->Data + pos.x + (pos.y - 1) * pic->size.x)).a;
	const bool isBelow =
		pos.y < pic->size.y - 1 && !isLeftOrRightEdge &&
		PIXEL2COLOR(*(pic->Data + pos.x + (pos.y + 1) * pic->size.x)).a;
	if (isPixel)
	{
		return !(isLeft && isRight && isAbove && isBelow);
	}
	else
	{
		return isLeft || isRight || isAbove || isBelow;
	}
}
Exemple #2
0
void Draw_Point(const int x, const int y, color_t c)
{
	Uint32 *screen = gGraphicsDevice.buf;
	int idx = PixelIndex(
		x,
		y,
		gGraphicsDevice.cachedConfig.Res.x,
		gGraphicsDevice.cachedConfig.Res.y);
	if (x < gGraphicsDevice.clipping.left ||
		x > gGraphicsDevice.clipping.right ||
		y < gGraphicsDevice.clipping.top ||
		y > gGraphicsDevice.clipping.bottom)
	{
		return;
	}
	if (c.a == 255)
	{
		screen[idx] = COLOR2PIXEL(c);
	}
	else
	{
		const color_t existing = PIXEL2COLOR(screen[idx]);
		screen[idx] = COLOR2PIXEL(ColorAlphaBlend(existing, c));
	}
}
Exemple #3
0
static void DrawGuideImage(
    DrawBuffer *b, SDL_Surface *guideImage, Uint8 alpha)
{
    SDL_LockSurface(guideImage);
    // Scale based on ratio between map size and guide image size,
    // so that the guide image stretches to the map size
    double xScale = (double)guideImage->w / (gMap.Size.x * TILE_WIDTH);
    double yScale = (double)guideImage->h / (gMap.Size.y * TILE_HEIGHT);
    for (int j = 0; j < b->g->cachedConfig.Res.y; j++)
    {
        int y = (int)round((j + b->yTop) * yScale);
        for (int i = 0; i < b->g->cachedConfig.Res.x; i++)
        {
            int x = (int)round((i + b->xTop) * xScale);
            if (x >= 0 && x < guideImage->w && y >= 0 && y < guideImage->h)
            {
                int imgIndex = y * guideImage->w + x;
                Uint32 p = ((Uint32 *)guideImage->pixels)[imgIndex];
                color_t c = PIXEL2COLOR(p);
                c.a = alpha;
                Draw_Point(i, j, c);
            }
        }
    }
    SDL_UnlockSurface(guideImage);
}
Exemple #4
0
void PicTrim(Pic *pic, const bool xTrim, const bool yTrim)
{
	// Scan all pixels looking for the min/max of x and y
	Vec2i min = pic->size;
	Vec2i max = Vec2iZero();
	for (Vec2i pos = Vec2iZero(); pos.y < pic->size.y; pos.y++)
	{
		for (pos.x = 0; pos.x < pic->size.x; pos.x++)
		{
			const Uint32 pixel = *(pic->Data + pos.x + pos.y * pic->size.x);
			if (PIXEL2COLOR(pixel).a > 0)
			{
				min.x = MIN(min.x, pos.x);
				min.y = MIN(min.y, pos.y);
				max.x = MAX(max.x, pos.x);
				max.y = MAX(max.y, pos.y);
			}
		}
	}
	// If no opaque pixels found, don't trim
	Vec2i newSize = pic->size;
	Vec2i offset = Vec2iZero();
	if (min.x < max.x && min.y < max.y)
	{
		if (xTrim)
		{
			newSize.x = max.x - min.x + 1;
			offset.x = min.x;
		}
		if (yTrim)
		{
			newSize.y = max.y - min.y + 1;
			offset.y = min.y;
		}
	}
	// Trim by copying pixels
	Uint32 *newData;
	CMALLOC(newData, newSize.x * newSize.y * sizeof *newData);
	for (Vec2i pos = Vec2iZero(); pos.y < newSize.y; pos.y++)
	{
		for (pos.x = 0; pos.x < newSize.x; pos.x++)
		{
			Uint32 *target = newData + pos.x + pos.y * newSize.x;
			const int srcIdx =
				pos.x + offset.x + (pos.y + offset.y) * pic->size.x;
			*target = *(pic->Data + srcIdx);
		}
	}
	// Replace the old data
	CFREE(pic->Data);
	pic->Data = newData;
	pic->size = newSize;
	pic->offset = Vec2iZero();
}
Exemple #5
0
void DrawPointTint(GraphicsDevice *device, Vec2i pos, HSV tint)
{
	Uint32 *screen = device->buf;
	int idx = PixelIndex(
		pos.x, pos.y,
		device->cachedConfig.Res.x,
		device->cachedConfig.Res.y);
	color_t c;
	if (pos.x < device->clipping.left || pos.x > device->clipping.right ||
		pos.y < device->clipping.top || pos.y > device->clipping.bottom)
	{
		return;
	}
	c = PIXEL2COLOR(screen[idx]);
	c = ColorTint(c, tint);
	screen[idx] = COLOR2PIXEL(c);
}
Exemple #6
0
void DrawPointMask(GraphicsDevice *device, Vec2i pos, color_t mask)
{
	Uint32 *screen = device->buf;
	int idx = PixelIndex(
		pos.x, pos.y,
		device->cachedConfig.Res.x,
		device->cachedConfig.Res.y);
	color_t c;
	if (pos.x < gGraphicsDevice.clipping.left ||
		pos.x > gGraphicsDevice.clipping.right ||
		pos.y < gGraphicsDevice.clipping.top ||
		pos.y > gGraphicsDevice.clipping.bottom)
	{
		return;
	}
	c = PIXEL2COLOR(screen[idx]);
	c = ColorMult(c, mask);
	screen[idx] = COLOR2PIXEL(c);
}