SDLImage.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * SDLImage.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "SDLImage.h"
  12. #include "SDLImageLoader.h"
  13. #include "SDL_Extensions.h"
  14. #include "../render/ColorFilter.h"
  15. #include "../render/Colors.h"
  16. #include "../render/CBitmapHandler.h"
  17. #include "../render/CDefFile.h"
  18. #include "../render/Graphics.h"
  19. #include "../xBRZ/xbrz.h"
  20. #include "../gui/CGuiHandler.h"
  21. #include "../render/IScreenHandler.h"
  22. #include <tbb/parallel_for.h>
  23. #include <SDL_surface.h>
  24. #include <SDL_image.h>
  25. class SDLImageLoader;
  26. //First 8 colors in def palette used for transparency
  27. static constexpr std::array<SDL_Color, 8> sourcePalette = {{
  28. {0, 255, 255, SDL_ALPHA_OPAQUE},
  29. {255, 150, 255, SDL_ALPHA_OPAQUE},
  30. {255, 100, 255, SDL_ALPHA_OPAQUE},
  31. {255, 50, 255, SDL_ALPHA_OPAQUE},
  32. {255, 0, 255, SDL_ALPHA_OPAQUE},
  33. {255, 255, 0, SDL_ALPHA_OPAQUE},
  34. {180, 0, 255, SDL_ALPHA_OPAQUE},
  35. {0, 255, 0, SDL_ALPHA_OPAQUE}
  36. }};
  37. static constexpr std::array<ColorRGBA, 8> targetPalette = {{
  38. {0, 0, 0, 0 }, // 0 - transparency ( used in most images )
  39. {0, 0, 0, 64 }, // 1 - shadow border ( used in battle, adventure map def's )
  40. {0, 0, 0, 64 }, // 2 - shadow border ( used in fog-of-war def's )
  41. {0, 0, 0, 128}, // 3 - shadow body ( used in fog-of-war def's )
  42. {0, 0, 0, 128}, // 4 - shadow body ( used in battle, adventure map def's )
  43. {0, 0, 0, 0 }, // 5 - selection / owner flag ( used in battle, adventure map def's )
  44. {0, 0, 0, 128}, // 6 - shadow body below selection ( used in battle def's )
  45. {0, 0, 0, 64 } // 7 - shadow border below selection ( used in battle def's )
  46. }};
  47. static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2)
  48. {
  49. return c1*a1 / 256 + c2*a2*(255 - a1) / 256 / 256;
  50. }
  51. static ColorRGBA addColors(const ColorRGBA & base, const ColorRGBA & over)
  52. {
  53. return ColorRGBA(
  54. mixChannels(over.r, base.r, over.a, base.a),
  55. mixChannels(over.g, base.g, over.a, base.a),
  56. mixChannels(over.b, base.b, over.a, base.a),
  57. static_cast<ui8>(over.a + base.a * (255 - over.a) / 256)
  58. );
  59. }
  60. static bool colorsSimilar (const SDL_Color & lhs, const SDL_Color & rhs)
  61. {
  62. // it seems that H3 does not requires exact match to replace colors -> (255, 103, 255) gets interpreted as shadow
  63. // exact logic is not clear and requires extensive testing with image editing
  64. // potential reason is that H3 uses 16-bit color format (565 RGB bits), meaning that 3 least significant bits are lost in red and blue component
  65. static const int threshold = 8;
  66. int diffR = static_cast<int>(lhs.r) - rhs.r;
  67. int diffG = static_cast<int>(lhs.g) - rhs.g;
  68. int diffB = static_cast<int>(lhs.b) - rhs.b;
  69. int diffA = static_cast<int>(lhs.a) - rhs.a;
  70. return std::abs(diffR) < threshold && std::abs(diffG) < threshold && std::abs(diffB) < threshold && std::abs(diffA) < threshold;
  71. }
  72. int IImage::width() const
  73. {
  74. return dimensions().x;
  75. }
  76. int IImage::height() const
  77. {
  78. return dimensions().y;
  79. }
  80. SDLImageShared::SDLImageShared(const CDefFile * data, size_t frame, size_t group, int preScaleFactor)
  81. : surf(nullptr),
  82. margins(0, 0),
  83. fullSize(0, 0),
  84. originalPalette(nullptr),
  85. preScaleFactor(preScaleFactor)
  86. {
  87. SDLImageLoader loader(this);
  88. data->loadFrame(frame, group, loader);
  89. savePalette();
  90. }
  91. SDLImageShared::SDLImageShared(SDL_Surface * from, int preScaleFactor)
  92. : surf(nullptr),
  93. margins(0, 0),
  94. fullSize(0, 0),
  95. originalPalette(nullptr),
  96. preScaleFactor(preScaleFactor)
  97. {
  98. surf = from;
  99. if (surf == nullptr)
  100. return;
  101. savePalette();
  102. surf->refcount++;
  103. fullSize.x = surf->w;
  104. fullSize.y = surf->h;
  105. }
  106. SDLImageShared::SDLImageShared(const ImagePath & filename, int preScaleFactor)
  107. : surf(nullptr),
  108. margins(0, 0),
  109. fullSize(0, 0),
  110. originalPalette(nullptr),
  111. preScaleFactor(preScaleFactor)
  112. {
  113. surf = BitmapHandler::loadBitmap(filename);
  114. if(surf == nullptr)
  115. {
  116. logGlobal->error("Error: failed to load image %s", filename.getOriginalName());
  117. return;
  118. }
  119. else
  120. {
  121. savePalette();
  122. fullSize.x = surf->w;
  123. fullSize.y = surf->h;
  124. optimizeSurface();
  125. }
  126. }
  127. void SDLImageShared::draw(SDL_Surface * where, SDL_Palette * palette, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const
  128. {
  129. if (!surf)
  130. return;
  131. Rect sourceRect(0, 0, surf->w, surf->h);
  132. Point destShift(0, 0);
  133. if(src)
  134. {
  135. if(src->x < margins.x)
  136. destShift.x += margins.x - src->x;
  137. if(src->y < margins.y)
  138. destShift.y += margins.y - src->y;
  139. sourceRect = Rect(*src).intersect(Rect(margins.x, margins.y, surf->w, surf->h));
  140. sourceRect -= margins;
  141. }
  142. else
  143. destShift = margins;
  144. destShift += dest;
  145. SDL_SetSurfaceColorMod(surf, colorMultiplier.r, colorMultiplier.g, colorMultiplier.b);
  146. SDL_SetSurfaceAlphaMod(surf, alpha);
  147. if (alpha != SDL_ALPHA_OPAQUE || (mode != EImageBlitMode::OPAQUE && surf->format->Amask != 0))
  148. SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_BLEND);
  149. else
  150. SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE);
  151. if (palette && surf->format->palette)
  152. SDL_SetSurfacePalette(surf, palette);
  153. if(surf->format->palette && mode != EImageBlitMode::OPAQUE && mode != EImageBlitMode::COLORKEY)
  154. {
  155. CSDL_Ext::blit8bppAlphaTo24bpp(surf, sourceRect, where, destShift, alpha);
  156. }
  157. else
  158. {
  159. CSDL_Ext::blitSurface(surf, sourceRect, where, destShift);
  160. }
  161. if (surf->format->palette)
  162. SDL_SetSurfacePalette(surf, originalPalette);
  163. }
  164. void SDLImageShared::optimizeSurface()
  165. {
  166. if (!surf)
  167. return;
  168. int left = surf->w;
  169. int top = surf->h;
  170. int right = 0;
  171. int bottom = 0;
  172. // locate fully-transparent area around image
  173. // H3 hadles this on format level, but mods or images scaled in runtime do not
  174. if (surf->format->palette)
  175. {
  176. for (int y = 0; y < surf->h; ++y)
  177. {
  178. const uint8_t * row = static_cast<uint8_t *>(surf->pixels) + y * surf->pitch;
  179. for (int x = 0; x < surf->w; ++x)
  180. {
  181. if (row[x] != 0)
  182. {
  183. // opaque or can be opaque (e.g. disabled shadow)
  184. top = std::min(top, y);
  185. left = std::min(left, x);
  186. right = std::max(right, x);
  187. bottom = std::max(bottom, y);
  188. }
  189. }
  190. }
  191. }
  192. else
  193. {
  194. for (int y = 0; y < surf->h; ++y)
  195. {
  196. for (int x = 0; x < surf->w; ++x)
  197. {
  198. ColorRGBA color;
  199. SDL_GetRGBA(CSDL_Ext::getPixel(surf, x, y), surf->format, &color.r, &color.g, &color.b, &color.a);
  200. if (color.a != SDL_ALPHA_TRANSPARENT)
  201. {
  202. // opaque
  203. top = std::min(top, y);
  204. left = std::min(left, x);
  205. right = std::max(right, x);
  206. bottom = std::max(bottom, y);
  207. }
  208. }
  209. }
  210. }
  211. if (left == surf->w)
  212. {
  213. // empty image - simply delete it
  214. SDL_FreeSurface(surf);
  215. surf = nullptr;
  216. return;
  217. }
  218. if (left != 0 || top != 0 || right != surf->w - 1 || bottom != surf->h - 1)
  219. {
  220. // non-zero border found
  221. Rect newDimensions(left, top, right - left + 1, bottom - top + 1);
  222. SDL_Rect rectSDL = CSDL_Ext::toSDL(newDimensions);
  223. auto newSurface = CSDL_Ext::newSurface(newDimensions.dimensions(), surf);
  224. SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE);
  225. SDL_BlitSurface(surf, &rectSDL, newSurface, nullptr);
  226. if (SDL_HasColorKey(surf))
  227. {
  228. uint32_t colorKey;
  229. SDL_GetColorKey(surf, &colorKey);
  230. SDL_SetColorKey(newSurface, SDL_TRUE, colorKey);
  231. }
  232. SDL_FreeSurface(surf);
  233. surf = newSurface;
  234. margins.x += left;
  235. margins.y += top;
  236. }
  237. }
  238. std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL_Palette * palette, EImageBlitMode mode) const
  239. {
  240. if (factor <= 0)
  241. throw std::runtime_error("Unable to scale by integer value of " + std::to_string(factor));
  242. if (!surf)
  243. return shared_from_this();
  244. if (palette && surf->format->palette)
  245. SDL_SetSurfacePalette(surf, palette);
  246. SDL_Surface * scaled = nullptr;
  247. if(preScaleFactor == factor)
  248. return shared_from_this();
  249. else if(preScaleFactor == 1)
  250. {
  251. // dump heuristics to differentiate tileable UI elements from map object / combat assets
  252. if (mode == EImageBlitMode::OPAQUE || mode == EImageBlitMode::COLORKEY || mode == EImageBlitMode::SIMPLE)
  253. scaled = CSDL_Ext::scaleSurfaceIntegerFactor(surf, factor, EScalingAlgorithm::XBRZ_OPAQUE);
  254. else
  255. scaled = CSDL_Ext::scaleSurfaceIntegerFactor(surf, factor, EScalingAlgorithm::XBRZ_ALPHA);
  256. }
  257. else
  258. scaled = CSDL_Ext::scaleSurface(surf, (int) round((float)surf->w * factor / preScaleFactor), (int) round((float)surf->h * factor / preScaleFactor));
  259. auto ret = std::make_shared<SDLImageShared>(scaled, preScaleFactor);
  260. ret->fullSize.x = fullSize.x * factor;
  261. ret->fullSize.y = fullSize.y * factor;
  262. ret->margins.x = (int) round((float)margins.x * factor / preScaleFactor);
  263. ret->margins.y = (int) round((float)margins.y * factor / preScaleFactor);
  264. ret->optimizeSurface();
  265. // erase our own reference
  266. SDL_FreeSurface(scaled);
  267. if (surf->format->palette)
  268. SDL_SetSurfacePalette(surf, originalPalette);
  269. return ret;
  270. }
  271. std::shared_ptr<const ISharedImage> SDLImageShared::scaleTo(const Point & size, SDL_Palette * palette) const
  272. {
  273. float scaleX = static_cast<float>(size.x) / fullSize.x;
  274. float scaleY = static_cast<float>(size.y) / fullSize.y;
  275. if (palette && surf->format->palette)
  276. SDL_SetSurfacePalette(surf, palette);
  277. auto scaled = CSDL_Ext::scaleSurface(surf, (int)(surf->w * scaleX), (int)(surf->h * scaleY));
  278. if (scaled->format && scaled->format->palette) // fix color keying, because SDL loses it at this point
  279. CSDL_Ext::setColorKey(scaled, scaled->format->palette->colors[0]);
  280. else if(scaled->format && scaled->format->Amask)
  281. SDL_SetSurfaceBlendMode(scaled, SDL_BLENDMODE_BLEND);//just in case
  282. else
  283. CSDL_Ext::setDefaultColorKey(scaled);//just in case
  284. auto ret = std::make_shared<SDLImageShared>(scaled, preScaleFactor);
  285. ret->fullSize.x = (int) round((float)fullSize.x * scaleX);
  286. ret->fullSize.y = (int) round((float)fullSize.y * scaleY);
  287. ret->margins.x = (int) round((float)margins.x * scaleX);
  288. ret->margins.y = (int) round((float)margins.y * scaleY);
  289. // erase our own reference
  290. SDL_FreeSurface(scaled);
  291. if (surf->format->palette)
  292. SDL_SetSurfacePalette(surf, originalPalette);
  293. return ret;
  294. }
  295. void SDLImageShared::exportBitmap(const boost::filesystem::path& path, SDL_Palette * palette) const
  296. {
  297. if (!surf)
  298. return;
  299. if (palette && surf->format->palette)
  300. SDL_SetSurfacePalette(surf, palette);
  301. IMG_SavePNG(surf, path.string().c_str());
  302. if (palette && surf->format->palette)
  303. SDL_SetSurfacePalette(surf, originalPalette);
  304. }
  305. void SDLImageIndexed::playerColored(PlayerColor player)
  306. {
  307. graphics->setPlayerPalette(currentPalette, player);
  308. }
  309. bool SDLImageShared::isTransparent(const Point & coords) const
  310. {
  311. if (surf)
  312. return CSDL_Ext::isTransparent(surf, coords.x - margins.x, coords.y - margins.y);
  313. else
  314. return true;
  315. }
  316. Rect SDLImageShared::contentRect() const
  317. {
  318. auto tmpMargins = margins / preScaleFactor;
  319. auto tmpSize = Point(surf->w, surf->h) / preScaleFactor;
  320. return Rect(tmpMargins, tmpSize);
  321. }
  322. Point SDLImageShared::dimensions() const
  323. {
  324. return fullSize / preScaleFactor;
  325. }
  326. std::shared_ptr<IImage> SDLImageShared::createImageReference(EImageBlitMode mode) const
  327. {
  328. if (surf && surf->format->palette)
  329. return std::make_shared<SDLImageIndexed>(shared_from_this(), originalPalette, mode);
  330. else
  331. return std::make_shared<SDLImageRGB>(shared_from_this(), mode);
  332. }
  333. std::shared_ptr<const ISharedImage> SDLImageShared::horizontalFlip() const
  334. {
  335. if (!surf)
  336. return shared_from_this();
  337. SDL_Surface * flipped = CSDL_Ext::horizontalFlip(surf);
  338. auto ret = std::make_shared<SDLImageShared>(flipped, preScaleFactor);
  339. ret->fullSize = fullSize;
  340. ret->margins.x = margins.x;
  341. ret->margins.y = fullSize.y - surf->h - margins.y;
  342. ret->fullSize = fullSize;
  343. return ret;
  344. }
  345. std::shared_ptr<const ISharedImage> SDLImageShared::verticalFlip() const
  346. {
  347. if (!surf)
  348. return shared_from_this();
  349. SDL_Surface * flipped = CSDL_Ext::verticalFlip(surf);
  350. auto ret = std::make_shared<SDLImageShared>(flipped, preScaleFactor);
  351. ret->fullSize = fullSize;
  352. ret->margins.x = fullSize.x - surf->w - margins.x;
  353. ret->margins.y = margins.y;
  354. ret->fullSize = fullSize;
  355. return ret;
  356. }
  357. // Keep the original palette, in order to do color switching operation
  358. void SDLImageShared::savePalette()
  359. {
  360. // For some images that don't have palette, skip this
  361. if(surf->format->palette == nullptr)
  362. return;
  363. if(originalPalette == nullptr)
  364. originalPalette = SDL_AllocPalette(surf->format->palette->ncolors);
  365. SDL_SetPaletteColors(originalPalette, surf->format->palette->colors, 0, surf->format->palette->ncolors);
  366. }
  367. void SDLImageIndexed::shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove)
  368. {
  369. std::vector<SDL_Color> shifterColors(colorsToMove);
  370. for(uint32_t i=0; i<colorsToMove; ++i)
  371. shifterColors[(i+distanceToMove)%colorsToMove] = originalPalette->colors[firstColorID + i];
  372. SDL_SetPaletteColors(currentPalette, shifterColors.data(), firstColorID, colorsToMove);
  373. }
  374. void SDLImageIndexed::adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask)
  375. {
  376. // If shadow is enabled, following colors must be skipped unconditionally
  377. if (blitMode == EImageBlitMode::WITH_SHADOW || blitMode == EImageBlitMode::WITH_SHADOW_AND_OVERLAY)
  378. colorsToSkipMask |= (1 << 0) + (1 << 1) + (1 << 4);
  379. // Note: here we skip first colors in the palette that are predefined in H3 images
  380. for(int i = 0; i < currentPalette->ncolors; i++)
  381. {
  382. if (i < std::size(sourcePalette) && colorsSimilar(sourcePalette[i], originalPalette->colors[i]))
  383. continue;
  384. if(i < std::numeric_limits<uint32_t>::digits && ((colorsToSkipMask >> i) & 1) == 1)
  385. continue;
  386. currentPalette->colors[i] = CSDL_Ext::toSDL(shifter.shiftColor(CSDL_Ext::fromSDL(originalPalette->colors[i])));
  387. }
  388. }
  389. SDLImageIndexed::SDLImageIndexed(const std::shared_ptr<const ISharedImage> & image, SDL_Palette * originalPalette, EImageBlitMode mode)
  390. :SDLImageBase::SDLImageBase(image, mode)
  391. ,originalPalette(originalPalette)
  392. {
  393. currentPalette = SDL_AllocPalette(originalPalette->ncolors);
  394. SDL_SetPaletteColors(currentPalette, originalPalette->colors, 0, originalPalette->ncolors);
  395. preparePalette();
  396. }
  397. SDLImageIndexed::~SDLImageIndexed()
  398. {
  399. SDL_FreePalette(currentPalette);
  400. }
  401. void SDLImageIndexed::setShadowTransparency(float factor)
  402. {
  403. ColorRGBA shadow50(0, 0, 0, 128 * factor);
  404. ColorRGBA shadow25(0, 0, 0, 64 * factor);
  405. std::array<SDL_Color, 5> colorsSDL = {
  406. originalPalette->colors[0],
  407. originalPalette->colors[1],
  408. originalPalette->colors[2],
  409. originalPalette->colors[3],
  410. originalPalette->colors[4]
  411. };
  412. // seems to be used unconditionally
  413. colorsSDL[0] = CSDL_Ext::toSDL(Colors::TRANSPARENCY);
  414. colorsSDL[1] = CSDL_Ext::toSDL(shadow25);
  415. colorsSDL[4] = CSDL_Ext::toSDL(shadow50);
  416. // seems to be used only if color matches
  417. if (colorsSimilar(originalPalette->colors[2], sourcePalette[2]))
  418. colorsSDL[2] = CSDL_Ext::toSDL(shadow25);
  419. if (colorsSimilar(originalPalette->colors[3], sourcePalette[3]))
  420. colorsSDL[3] = CSDL_Ext::toSDL(shadow50);
  421. SDL_SetPaletteColors(currentPalette, colorsSDL.data(), 0, colorsSDL.size());
  422. }
  423. void SDLImageIndexed::setOverlayColor(const ColorRGBA & color)
  424. {
  425. currentPalette->colors[5] = CSDL_Ext::toSDL(addColors(targetPalette[5], color));
  426. for (int i : {6,7})
  427. {
  428. if (colorsSimilar(originalPalette->colors[i], sourcePalette[i]))
  429. currentPalette->colors[i] = CSDL_Ext::toSDL(addColors(targetPalette[i], color));
  430. }
  431. }
  432. void SDLImageIndexed::preparePalette()
  433. {
  434. switch(blitMode)
  435. {
  436. case EImageBlitMode::ONLY_SHADOW:
  437. case EImageBlitMode::ONLY_OVERLAY:
  438. adjustPalette(ColorFilter::genAlphaShifter(0), 0);
  439. break;
  440. }
  441. switch(blitMode)
  442. {
  443. case EImageBlitMode::SIMPLE:
  444. case EImageBlitMode::WITH_SHADOW:
  445. case EImageBlitMode::ONLY_SHADOW:
  446. case EImageBlitMode::WITH_SHADOW_AND_OVERLAY:
  447. setShadowTransparency(1.0);
  448. break;
  449. case EImageBlitMode::ONLY_BODY:
  450. case EImageBlitMode::ONLY_BODY_IGNORE_OVERLAY:
  451. case EImageBlitMode::ONLY_OVERLAY:
  452. setShadowTransparency(0.0);
  453. break;
  454. }
  455. switch(blitMode)
  456. {
  457. case EImageBlitMode::ONLY_OVERLAY:
  458. case EImageBlitMode::WITH_SHADOW_AND_OVERLAY:
  459. setOverlayColor(Colors::WHITE_TRUE);
  460. break;
  461. case EImageBlitMode::ONLY_SHADOW:
  462. case EImageBlitMode::ONLY_BODY:
  463. setOverlayColor(Colors::TRANSPARENCY);
  464. break;
  465. }
  466. }
  467. SDLImageShared::~SDLImageShared()
  468. {
  469. SDL_FreeSurface(surf);
  470. SDL_FreePalette(originalPalette);
  471. }
  472. SDLImageBase::SDLImageBase(const std::shared_ptr<const ISharedImage> & image, EImageBlitMode mode)
  473. :image(image)
  474. , alphaValue(SDL_ALPHA_OPAQUE)
  475. , blitMode(mode)
  476. {}
  477. std::shared_ptr<const ISharedImage> SDLImageBase::getSharedImage() const
  478. {
  479. return image;
  480. }
  481. void SDLImageRGB::draw(SDL_Surface * where, const Point & pos, const Rect * src) const
  482. {
  483. image->draw(where, nullptr, pos, src, Colors::WHITE_TRUE, alphaValue, blitMode);
  484. }
  485. void SDLImageIndexed::draw(SDL_Surface * where, const Point & pos, const Rect * src) const
  486. {
  487. image->draw(where, currentPalette, pos, src, Colors::WHITE_TRUE, alphaValue, blitMode);
  488. }
  489. void SDLImageIndexed::exportBitmap(const boost::filesystem::path & path) const
  490. {
  491. image->exportBitmap(path, currentPalette);
  492. }
  493. void SDLImageIndexed::scaleTo(const Point & size)
  494. {
  495. image = image->scaleTo(size, currentPalette);
  496. }
  497. void SDLImageRGB::scaleTo(const Point & size)
  498. {
  499. image = image->scaleTo(size, nullptr);
  500. }
  501. void SDLImageIndexed::scaleInteger(int factor)
  502. {
  503. image = image->scaleInteger(factor, currentPalette, blitMode);
  504. }
  505. void SDLImageRGB::scaleInteger(int factor)
  506. {
  507. image = image->scaleInteger(factor, nullptr, blitMode);
  508. }
  509. void SDLImageRGB::exportBitmap(const boost::filesystem::path & path) const
  510. {
  511. image->exportBitmap(path, nullptr);
  512. }
  513. bool SDLImageBase::isTransparent(const Point & coords) const
  514. {
  515. return image->isTransparent(coords);
  516. }
  517. Rect SDLImageBase::contentRect() const
  518. {
  519. return image->contentRect();
  520. }
  521. Point SDLImageBase::dimensions() const
  522. {
  523. return image->dimensions();
  524. }
  525. void SDLImageBase::setAlpha(uint8_t value)
  526. {
  527. alphaValue = value;
  528. }
  529. void SDLImageBase::setBlitMode(EImageBlitMode mode)
  530. {
  531. blitMode = mode;
  532. }
  533. void SDLImageRGB::setOverlayColor(const ColorRGBA & color)
  534. {}
  535. void SDLImageRGB::playerColored(PlayerColor player)
  536. {}
  537. void SDLImageRGB::shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove)
  538. {}
  539. void SDLImageRGB::adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask)
  540. {}