@@ -36,7 +36,7 @@ static inline int rgb2int(uint8_t r, uint8_t g, uint8_t b, uint8_t a=0xFF)
36
36
37
37
static inline int color2int (Color c)
38
38
{
39
- return rgb2int (c.r , c.g , c.b , c.a );
39
+ return rgb2int (c.r , c.g , c.b , c.a );
40
40
}
41
41
42
42
// rounds n (away from 0) to a multiple of f while preserving the sign of n
@@ -87,15 +87,15 @@ static inline int colorSafeBounds(int color)
87
87
88
88
static inline Color mixColors (Color a, Color b)
89
89
{
90
- Color result;
91
- double a1 = a.a / 255.0 ;
92
- double a2 = b.a / 255.0 ;
90
+ Color result;
91
+ double a1 = a.a / 255.0 ;
92
+ double a2 = b.a / 255.0 ;
93
93
94
- result.r = (int ) (a1 * a.r + a2 * (1 - a1) * b.r );
95
- result.g = (int ) (a1 * a.g + a2 * (1 - a1) * b.g );
96
- result.b = (int ) (a1 * a.b + a2 * (1 - a1) * b.b );
97
- result.a = (int ) (255 * (a1 + a2 * (1 - a1)));
98
- return result;
94
+ result.r = (int ) (a1 * a.r + a2 * (1 - a1) * b.r );
95
+ result.g = (int ) (a1 * a.g + a2 * (1 - a1) * b.g );
96
+ result.b = (int ) (a1 * a.b + a2 * (1 - a1) * b.b );
97
+ result.a = (int ) (255 * (a1 + a2 * (1 - a1)));
98
+ return result;
99
99
}
100
100
101
101
TileGenerator::TileGenerator ():
@@ -120,7 +120,8 @@ TileGenerator::TileGenerator():
120
120
m_geomX(-2048 ),
121
121
m_geomY(-2048 ),
122
122
m_geomX2(2048 ),
123
- m_geomY2(2048 )
123
+ m_geomY2(2048 ),
124
+ m_zoom(1 )
124
125
{
125
126
}
126
127
@@ -148,6 +149,14 @@ void TileGenerator::setPlayerColor(const std::string &playerColor)
148
149
m_playerColor = parseColor (playerColor);
149
150
}
150
151
152
+ void TileGenerator::setZoom (int zoom)
153
+ {
154
+ if (zoom < 1 ) {
155
+ throw std::runtime_error (" Zoom level needs to be a number: 1 or higher" );
156
+ }
157
+ m_zoom = zoom;
158
+ }
159
+
151
160
Color TileGenerator::parseColor (const std::string &color)
152
161
{
153
162
Color parsed;
@@ -186,7 +195,7 @@ void TileGenerator::setDrawScale(bool drawScale)
186
195
187
196
void TileGenerator::setDrawAlpha (bool drawAlpha)
188
197
{
189
- m_drawAlpha = drawAlpha;
198
+ m_drawAlpha = drawAlpha;
190
199
}
191
200
192
201
void TileGenerator::setShading (bool shading)
@@ -346,10 +355,10 @@ void TileGenerator::createImage()
346
355
{
347
356
m_mapWidth = (m_xMax - m_xMin + 1 ) * 16 ;
348
357
m_mapHeight = (m_zMax - m_zMin + 1 ) * 16 ;
349
- m_image = gdImageCreateTrueColor (m_mapWidth + m_border, m_mapHeight + m_border);
358
+ m_image = gdImageCreateTrueColor (( m_mapWidth * m_zoom) + m_border, ( m_mapHeight * m_zoom) + m_border);
350
359
m_blockPixelAttributes.setWidth (m_mapWidth);
351
360
// Background
352
- gdImageFilledRectangle (m_image, 0 , 0 , m_mapWidth + m_border - 1 , m_mapHeight + m_border -1 , color2int (m_bgColor));
361
+ gdImageFilledRectangle (m_image, 0 , 0 , ( m_mapWidth * m_zoom) + m_border - 1 , ( m_mapHeight * m_zoom) + m_border -1 , color2int (m_bgColor));
353
362
}
354
363
355
364
void TileGenerator::renderMap ()
@@ -497,12 +506,12 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo
497
506
int minY = (pos.y * 16 > m_yMin) ? 0 : m_yMin - pos.y * 16 ;
498
507
int maxY = (pos.y * 16 < m_yMax) ? 15 : m_yMax - pos.y * 16 ;
499
508
for (int z = 0 ; z < 16 ; ++z) {
500
- int imageY = getImageY ( zBegin + 15 - z) ;
509
+ int imageY = zBegin + 15 - z;
501
510
for (int x = 0 ; x < 16 ; ++x) {
502
511
if (m_readPixels[z] & (1 << x)) {
503
512
continue ;
504
513
}
505
- int imageX = getImageX ( xBegin + x) ;
514
+ int imageX = xBegin + x;
506
515
507
516
for (int y = maxY; y >= minY; --y) {
508
517
int position = x + (y << 4 ) + (z << 8 );
@@ -523,15 +532,15 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo
523
532
else
524
533
m_color[z][x] = mixColors (m_color[z][x], c);
525
534
if (m_color[z][x].a == 0xFF ) {
526
- m_image-> tpixels [ imageY][ imageX] = color2int (m_color[z][x]);
535
+ setZoomed ( m_image, imageY, imageX, color2int (m_color[z][x]) );
527
536
m_readPixels[z] |= (1 << x);
528
537
m_blockPixelAttributes.attribute (15 - z, xBegin + x).thickness = m_thickness[z][x];
529
538
} else {
530
539
m_thickness[z][x] = (m_thickness[z][x] + color->second .t ) / 2.0 ;
531
540
continue ;
532
541
}
533
542
} else {
534
- m_image-> tpixels [ imageY][ imageX] = color2int (c);
543
+ setZoomed ( m_image, imageY, imageX, color2int (c) );
535
544
m_readPixels[z] |= (1 << x);
536
545
}
537
546
if (!(m_readInfo[z] & (1 << x))) {
@@ -553,15 +562,15 @@ inline void TileGenerator::renderMapBlockBottom(const BlockPos &pos)
553
562
int xBegin = (pos.x - m_xMin) * 16 ;
554
563
int zBegin = (m_zMax - pos.z ) * 16 ;
555
564
for (int z = 0 ; z < 16 ; ++z) {
556
- int imageY = getImageY ( zBegin + 15 - z) ;
565
+ int imageY = zBegin + 15 - z;
557
566
for (int x = 0 ; x < 16 ; ++x) {
558
567
if (m_readPixels[z] & (1 << x)) {
559
568
continue ;
560
569
}
561
- int imageX = getImageX ( xBegin + x) ;
570
+ int imageX = xBegin + x;
562
571
563
572
if (m_drawAlpha) {
564
- m_image-> tpixels [ imageY][ imageX] = color2int (m_color[z][x]);
573
+ setZoomed ( m_image, imageY, imageX, color2int (m_color[z][x]) );
565
574
m_readPixels[z] |= (1 << x);
566
575
m_blockPixelAttributes.attribute (15 - z, xBegin + x).thickness = m_thickness[z][x];
567
576
}
@@ -577,7 +586,6 @@ inline void TileGenerator::renderShading(int zPos)
577
586
if (imageY >= m_mapHeight) {
578
587
continue ;
579
588
}
580
- imageY = getImageY (imageY);
581
589
for (int x = 0 ; x < m_mapWidth; ++x) {
582
590
if (!m_blockPixelAttributes.attribute (z, x).valid_height () || !m_blockPixelAttributes.attribute (z, x - 1 ).valid_height () || !m_blockPixelAttributes.attribute (z - 1 , x).valid_height ()) {
583
591
continue ;
@@ -592,15 +600,14 @@ inline void TileGenerator::renderShading(int zPos)
592
600
// more thickness -> less visible shadows: t=0 -> 100% visible, t=255 -> 0% visible
593
601
if (m_drawAlpha)
594
602
d = d * ((0xFF - m_blockPixelAttributes.attribute (z, x).thickness ) / 255.0 );
595
- int sourceColor = m_image->tpixels [imageY][getImageX (x)] & 0xffffff ;
603
+ int sourceColor = m_image->tpixels [getImageY ( imageY) ][getImageX (x)] & 0xffffff ;
596
604
uint8_t r = (sourceColor & 0xff0000 ) >> 16 ;
597
605
uint8_t g = (sourceColor & 0x00ff00 ) >> 8 ;
598
606
uint8_t b = (sourceColor & 0x0000ff );
599
607
r = colorSafeBounds (r + d);
600
608
g = colorSafeBounds (g + d);
601
609
b = colorSafeBounds (b + d);
602
-
603
- m_image->tpixels [imageY][getImageX (x)] = rgb2int (r, g, b);
610
+ setZoomed (m_image,imageY,x, rgb2int (r, g, b));
604
611
}
605
612
}
606
613
m_blockPixelAttributes.scroll ();
@@ -619,7 +626,7 @@ void TileGenerator::renderScale()
619
626
buf << i * 16 ;
620
627
scaleText = buf.str ();
621
628
622
- int xPos = m_xMin * -16 + i * 16 + m_border;
629
+ int xPos = ( m_xMin * -16 + i * 16 )*m_zoom + m_border;
623
630
gdImageString (m_image, gdFontGetMediumBold (), xPos + 2 , 0 , reinterpret_cast <unsigned char *>(const_cast <char *>(scaleText.c_str ())), color);
624
631
gdImageLine (m_image, xPos, 0 , xPos, m_border - 1 , color);
625
632
}
@@ -629,16 +636,16 @@ void TileGenerator::renderScale()
629
636
buf << i * 16 ;
630
637
scaleText = buf.str ();
631
638
632
- int yPos = m_mapHeight - 1 - (i * 16 - m_zMin * 16 ) + m_border;
639
+ int yPos = ( m_mapHeight - 1 - (i * 16 - m_zMin * 16 ))*m_zoom + m_border;
633
640
gdImageString (m_image, gdFontGetMediumBold (), 2 , yPos, reinterpret_cast <unsigned char *>(const_cast <char *>(scaleText.c_str ())), color);
634
641
gdImageLine (m_image, 0 , yPos, m_border - 1 , yPos, color);
635
642
}
636
643
}
637
644
638
645
void TileGenerator::renderOrigin ()
639
646
{
640
- int imageX = -m_xMin * 16 + m_border;
641
- int imageY = m_mapHeight - m_zMin * -16 + m_border;
647
+ int imageX = ( -m_xMin * 16 )*m_zoom + m_border;
648
+ int imageY = ( m_mapHeight - m_zMin * -16 )*m_zoom + m_border;
642
649
gdImageArc (m_image, imageX, imageY, 12 , 12 , 0 , 360 , color2int (m_originColor));
643
650
}
644
651
@@ -648,8 +655,8 @@ void TileGenerator::renderPlayers(const std::string &inputPath)
648
655
649
656
PlayerAttributes players (inputPath);
650
657
for (PlayerAttributes::Players::iterator player = players.begin (); player != players.end (); ++player) {
651
- int imageX = player->x / 10 - m_xMin * 16 + m_border;
652
- int imageY = m_mapHeight - (player->z / 10 - m_zMin * 16 ) + m_border;
658
+ int imageX = ( player->x / 10 - m_xMin * 16 )*m_zoom + m_border;
659
+ int imageY = ( m_mapHeight - (player->z / 10 - m_zMin * 16 ))*m_zoom + m_border;
653
660
654
661
gdImageArc (m_image, imageX, imageY, 5 , 5 , 0 , 360 , color);
655
662
gdImageString (m_image, gdFontGetMediumBold (), imageX + 2 , imageY + 2 , reinterpret_cast <unsigned char *>(const_cast <char *>(player->name .c_str ())), color);
@@ -694,10 +701,19 @@ void TileGenerator::printUnknown()
694
701
695
702
inline int TileGenerator::getImageX (int val) const
696
703
{
697
- return val + m_border;
704
+ return (m_zoom* val) + m_border;
698
705
}
699
706
700
707
inline int TileGenerator::getImageY (int val) const
701
708
{
702
- return val + m_border;
709
+ return (m_zoom*val) + m_border;
710
+ }
711
+
712
+ inline void TileGenerator::setZoomed (gdImagePtr image, int y, int x, int color) {
713
+ int xx,yy;
714
+ for (xx = 0 ; xx < m_zoom; xx++) {
715
+ for (yy = 0 ; yy < m_zoom; yy++) {
716
+ image->tpixels [m_border + (y*m_zoom) + xx][m_border + (x*m_zoom) + yy] = color;
717
+ }
718
+ }
703
719
}
0 commit comments