~ubuntu-branches/ubuntu/trusty/teeworlds/trusty-updates

« back to all changes in this revision

Viewing changes to .pc/system-libs.patch/src/tools/tileset_borderset.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-05-05 09:49:34 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20130505094934-uidw42ov1t0jlvrz
Tags: 0.6.2+dfsg-1
* New upstream release.
  - Update patches.
* Pass $CPPFLAGS to the build system.
* Switch to my @debian.org email address.
* Bump Standards-Version to 3.9.4, no changes needed.
* Change Vcs host to anonscm.debian.org.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
 
2
/* If you are missing that file, acquire a complete release at teeworlds.com.                */
 
3
#include <base/math.h>
 
4
#include <base/system.h>
 
5
#include <engine/external/pnglite/pnglite.h>
 
6
 
 
7
typedef struct
 
8
{
 
9
        unsigned char r, g, b, a;
 
10
} CPixel;
 
11
 
 
12
static void TilesetBorderset(int w, int h, CPixel *pSrc, CPixel *pDest)
 
13
{
 
14
        int TileW = w/16;
 
15
        int TileH = h/16;
 
16
 
 
17
        for(int tx = 0; tx < 16; tx++)
 
18
        {
 
19
                for(int ty = 0; ty < 16; ty++)
 
20
                {
 
21
                        for(int x = 0; x < TileW; x++)
 
22
                        {
 
23
                                for(int y = 0; y < TileH; y++)
 
24
                                {
 
25
                                        #define TILE_INDEX(tx_, ty_, x_, y_) (((ty_) * TileH + (y_)) * w + (tx_) * TileW + (x_))
 
26
                                        pDest[TILE_INDEX(tx, ty, x, y)] = pSrc[TILE_INDEX(tx, ty, clamp(x, 2, TileW - 3), clamp(y, 2, TileH - 3))];
 
27
                                }
 
28
                        }
 
29
                }
 
30
        }
 
31
}
 
32
 
 
33
 
 
34
int FixFile(const char *pFileName)
 
35
{
 
36
        png_t Png;
 
37
        CPixel *pBuffer[2] = {0,0};
 
38
 
 
39
        png_init(0, 0);
 
40
        png_open_file(&Png, pFileName);
 
41
 
 
42
        if(Png.color_type != PNG_TRUECOLOR_ALPHA)
 
43
        {
 
44
                dbg_msg("tileset_borderset", "%s: not an RGBA image", pFileName);
 
45
                return 1;
 
46
        }
 
47
 
 
48
        int w = Png.width;
 
49
        int h = Png.height;
 
50
 
 
51
        pBuffer[0] = (CPixel*)mem_alloc(w*h*sizeof(CPixel), 1);
 
52
        pBuffer[1] = (CPixel*)mem_alloc(w*h*sizeof(CPixel), 1);
 
53
        png_get_data(&Png, (unsigned char *)pBuffer[0]);
 
54
        png_close_file(&Png);
 
55
 
 
56
        TilesetBorderset(w, h, pBuffer[0], pBuffer[1]);
 
57
 
 
58
        // save here
 
59
        png_open_file_write(&Png, pFileName);
 
60
        png_set_data(&Png, w, h, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)pBuffer[1]);
 
61
        png_close_file(&Png);
 
62
 
 
63
        return 0;
 
64
}
 
65
 
 
66
int main(int argc, const char **argv)
 
67
{
 
68
        dbg_logger_stdout();
 
69
        if(argc == 1)
 
70
        {
 
71
                dbg_msg("Usage", "%s FILE1 [ FILE2... ]", argv[0]);
 
72
                return -1;
 
73
        }
 
74
 
 
75
        for(int i = 1; i < argc; i++)
 
76
                FixFile(argv[i]);
 
77
        return 0;
 
78
}