Ejemplo n.º 1
0
static void SetScene (int pos)
{
	char filename[32];
	Timeline* timeline;
	maxpal = 0;

	if (background)
		TLN_DeleteBitmap (background);
	sprintf (filename, "%s.PNG", scenes[pos].bitmap);
	background = TLN_LoadBitmap (filename);
	TLN_SetBGBitmap (background);
	TLN_SetBGPalette (palette);

	if (sp)
		TLN_DeleteSequencePack (sp);
	sprintf (filename, "%s.SQX", scenes[pos].sequence);
	sp = TLN_LoadSequencePack (filename);

	maxpal = 0;
	timeline = scenes[pos].timeline;
	while (timeline->palette)
	{
		TLN_Palette palette;

		if (palettes[maxpal].palette)
			TLN_DeletePalette (palettes[maxpal].palette);
		sprintf(filename, "%s.ACT", timeline->palette);
		palettes[maxpal].palette = TLN_LoadPalette (filename);
		palettes[maxpal].sequence = TLN_FindSequence (sp, timeline->palette);
		palettes[maxpal].time = timeline->seconds*MAX_TIME/86400;

		/* remap: patch errors in original LBMs */
		palette = palettes[maxpal].palette;
		if (pos == 12)
			TLN_SetPaletteColor (palette, 0, 0,0,0);
		else if (pos == 13 || pos == 14)
			TLN_SetPaletteColor (palette, 252, 11,11,11);
		else if (pos == 15 || pos == 16 || pos == 17)
		{
			TLN_SetPaletteColor (palette, 0, 11,11,11);
			TLN_SetPaletteColor (palette, 254, 0,0,0);
		}

		maxpal++;
		timeline++;
	}

	frame = 18000*MAX_TIME/86400;;
	pal = 0;
	TLN_DisableAnimation (0);
}
Ejemplo n.º 2
0
/* Loads PNG using libpng */
static TLN_Bitmap LoadPNG (char *filename)
{
    png_image image;
    TLN_Bitmap bitmap = NULL;

    /* Only the image structure version number needs to be set. */
    memset (&image, 0, sizeof image);
    image.version = PNG_IMAGE_VERSION;

    if (png_image_begin_read_from_file (&image, filename))
    {
        int src_line_size = image.width * PNG_IMAGE_PIXEL_SIZE(image.format);
        int lut_size = PNG_IMAGE_COLORMAP_SIZE(image);
        BYTE* data = malloc (src_line_size * image.height);
        BYTE* lut = malloc (lut_size);

        bitmap = TLN_CreateBitmap (image.width, image.height, PNG_IMAGE_PIXEL_SIZE(image.format)<<3);

        /* Change this to try different formats!  If you set a colormap format
        * then you must also supply a colormap below.
        */
        image.format = PNG_FORMAT_RGB_COLORMAP;
        if (png_image_finish_read (&image, NULL, data, 0, lut))
        {
            BYTE *src, *dst;
            unsigned int c;

            png_image_free (&image);

            /* copy scanlines */
            src = data;
            for (c=0; c<image.height; c++)
            {
                dst = TLN_GetBitmapPtr (bitmap, 0, c);
                memcpy (dst, src, src_line_size);
                src += src_line_size;
            }

            /* get palette */
            {
                BYTE *src = lut;
                png_uint_32 c;
                TLN_Palette palette;
                palette = TLN_CreatePalette (image.colormap_entries);
                for (c=0; c<image.colormap_entries; c++)
                {
                    TLN_SetPaletteColor (palette, c, src[0], src[1], src[2]);
                    src += 3;
                }
                TLN_SetBitmapPalette (bitmap, palette);
            }
        }
        free (lut);
        free (data);
    }
    return bitmap;
}
Ejemplo n.º 3
0
/*!
 * \brief
 * Loads a palette from a standard .act file
 * 
 * \param filename
 * ACT file containing the palette to load
 * 
 * \returns
 * A reference to the newly loaded palette, or NULL if error
 * 
 * \remarks
 * Palettes are also automatically created when loading tilesets and spritesets.
 * Use the functions TLN_GetTilesetPalette() and TLN_GetSpritesetPalette() to retrieve them.
 * 
 * \see
 * TLN_GetTilesetPalette(), TLN_GetSpritesetPalette()
 */
TLN_Palette TLN_LoadPalette (char *filename)
{
	FILE *pf;
	TLN_Palette palette = NULL;
	int size;
	int c;

	/* open file */
	pf = fopen (filename, "rb");
	if (!pf)
	{
		TLN_SetLastError (TLN_ERR_FILE_NOT_FOUND);
		return NULL;
	}

	/* check size */
	fseek (pf, 0, SEEK_END);
	size = ftell (pf);

	/* load trailing and get number of entries */
	if (size == ACT_SIZE)
	{
		fseek (pf, - (int)sizeof(trailing), SEEK_END);
		fread (&trailing, sizeof(trailing), 1, pf);
		trailing.entries = SWAP(trailing.entries);
		trailing.transparent = SWAP(trailing.transparent);
	}
	else
		trailing.entries = size/3;

	/* create palette and load from file */
	palette = TLN_CreatePalette (trailing.entries);
	fseek (pf, 0, SEEK_SET);
	for (c=0; c<trailing.entries; c++)
	{
		BYTE src[3];
		fread (src, sizeof(src), 1, pf);
		TLN_SetPaletteColor (palette, c, src[0], src[1], src[2]);
	}

	fclose (pf);
	TLN_SetLastError (TLN_ERR_OK);
	return palette;
}
Ejemplo n.º 4
0
JNIEXPORT jboolean JNICALL Java_Tilengine_SetPaletteColor (JNIEnv* env, jobject thisobj, jint palette , jint entry, jbyte r, jbyte g, jbyte b)
{
	return TLN_SetPaletteColor ((TLN_Palette)palette, entry, r, g, b);
}
Ejemplo n.º 5
0
/* loads BMP */
static TLN_Bitmap LoadBMP (char *filename)
{
    BITMAPFILEHEADER bfh;
    BITMAPV5HEADER bv5;
    DWORD StructSize;
    FILE* pf;
    TLN_Bitmap bitmap = NULL;
    unsigned int c;
    int pitch;

    /* open file */
    pf = fopen (filename, "rb");
    if (!pf)
        return NULL;

    /* read BMP header */
    fread (&bfh, sizeof(bfh), 1, pf);
    if (bfh.Type != 0x4D42)
    {
        fclose (pf);
        return NULL;
    }

    /* load info structure */
    memset (&bv5, 0, sizeof(bv5));
    fread (&StructSize, 4, 1, pf);
    fseek (pf, sizeof(bfh), SEEK_SET);
    fread (&bv5, StructSize, 1, pf);

    /* create */
    bitmap = TLN_CreateBitmap (bv5.bV5Width, bv5.bV5Height, bv5.bV5BitCount);
    if (!bitmap)
    {
        fclose (pf);
        return NULL;
    }

    /* load scanlines */
    pitch = TLN_GetBitmapPitch (bitmap);
    fseek (pf, bfh.OffsetData, SEEK_SET);
    for (c=0; c<bv5.bV5Height; c++)
    {
        BYTE* line = TLN_GetBitmapPtr (bitmap, 0, bv5.bV5Height - c - 1);
        fread (line, pitch, 1, pf);
    }

    /* load palette */
    if (bv5.bV5BitCount == 8)
    {
        TLN_Palette palette;

        /* HACK: some editors don't set the bV5ClrUsed field, compute from size */
        if (bv5.bV5ClrUsed == 0)
            bv5.bV5ClrUsed = (bfh.OffsetData - sizeof(bfh) - bv5.bV5Size) / sizeof(RGBQUAD);

        fseek (pf, sizeof(BITMAPFILEHEADER) + bv5.bV5Size, SEEK_SET);
        palette = TLN_CreatePalette (bv5.bV5ClrUsed);
        for (c=0; c<(int)bv5.bV5ClrUsed; c++)
        {
            RGBQUAD color;
            fread (&color, sizeof(RGBQUAD), 1, pf);
            TLN_SetPaletteColor (palette, c, color.r, color.g, color.b);
        }
        TLN_SetBitmapPalette (bitmap, palette);
    }

    fclose (pf);
    return bitmap;
}