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. if(preScaleFactor > 1 && preScaleFactor != GH.screenHandler().getScalingFactor())
  238. {
  239. margins.x = margins.x * GH.screenHandler().getScalingFactor() / preScaleFactor;
  240. margins.y = margins.y * GH.screenHandler().getScalingFactor() / preScaleFactor;
  241. }
  242. }
  243. std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL_Palette * palette, EImageBlitMode mode) const
  244. {
  245. if (factor <= 0)
  246. throw std::runtime_error("Unable to scale by integer value of " + std::to_string(factor));
  247. if (!surf)
  248. return shared_from_this();
  249. if (palette && surf->format->palette)
  250. SDL_SetSurfacePalette(surf, palette);
  251. SDL_Surface * scaled = nullptr;
  252. if(preScaleFactor == factor)
  253. return shared_from_this();
  254. else if(preScaleFactor == 1)
  255. {
  256. // dump heuristics to differentiate tileable UI elements from map object / combat assets
  257. if (mode == EImageBlitMode::OPAQUE || mode == EImageBlitMode::COLORKEY || mode == EImageBlitMode::SIMPLE)
  258. scaled = CSDL_Ext::scaleSurfaceIntegerFactor(surf, factor, EScalingAlgorithm::XBRZ_OPAQUE);
  259. else
  260. scaled = CSDL_Ext::scaleSurfaceIntegerFactor(surf, factor, EScalingAlgorithm::XBRZ_ALPHA);
  261. }
  262. else
  263. scaled = CSDL_Ext::scaleSurface(surf, (surf->w / preScaleFactor) * factor, (surf->h / preScaleFactor) * factor);
  264. auto ret = std::make_shared<SDLImageShared>(scaled, preScaleFactor);
  265. ret->fullSize.x = fullSize.x * factor;
  266. ret->fullSize.y = fullSize.y * factor;
  267. ret->margins.x = margins.x * factor;
  268. ret->margins.y = margins.y * factor;
  269. ret->optimizeSurface();
  270. // erase our own reference
  271. SDL_FreeSurface(scaled);
  272. if (surf->format->palette)
  273. SDL_SetSurfacePalette(surf, originalPalette);
  274. return ret;
  275. }
  276. std::shared_ptr<const ISharedImage> SDLImageShared::scaleTo(const Point & size, SDL_Palette * palette) const
  277. {
  278. float scaleX = static_cast<float>(size.x) / fullSize.x;
  279. float scaleY = static_cast<float>(size.y) / fullSize.y;
  280. if (palette && surf->format->palette)
  281. SDL_SetSurfacePalette(surf, palette);
  282. auto scaled = CSDL_Ext::scaleSurface(surf, (int)(surf->w * scaleX), (int)(surf->h * scaleY));
  283. if (scaled->format && scaled->format->palette) // fix color keying, because SDL loses it at this point
  284. CSDL_Ext::setColorKey(scaled, scaled->format->palette->colors[0]);
  285. else if(scaled->format && scaled->format->Amask)
  286. SDL_SetSurfaceBlendMode(scaled, SDL_BLENDMODE_BLEND);//just in case
  287. else
  288. CSDL_Ext::setDefaultColorKey(scaled);//just in case
  289. auto ret = std::make_shared<SDLImageShared>(scaled, preScaleFactor);
  290. ret->fullSize.x = (int) round((float)fullSize.x * scaleX);
  291. ret->fullSize.y = (int) round((float)fullSize.y * scaleY);
  292. ret->margins.x = (int) round((float)margins.x * scaleX);
  293. ret->margins.y = (int) round((float)margins.y * scaleY);
  294. // erase our own reference
  295. SDL_FreeSurface(scaled);
  296. if (surf->format->palette)
  297. SDL_SetSurfacePalette(surf, originalPalette);
  298. return ret;
  299. }
  300. void SDLImageShared::exportBitmap(const boost::filesystem::path& path, SDL_Palette * palette) const
  301. {
  302. if (!surf)
  303. return;
  304. if (palette && surf->format->palette)
  305. SDL_SetSurfacePalette(surf, palette);
  306. IMG_SavePNG(surf, path.string().c_str());
  307. if (palette && surf->format->palette)
  308. SDL_SetSurfacePalette(surf, originalPalette);
  309. }
  310. void SDLImageIndexed::playerColored(PlayerColor player)
  311. {
  312. graphics->setPlayerPalette(currentPalette, player);
  313. }
  314. bool SDLImageShared::isTransparent(const Point & coords) const
  315. {
  316. if (surf)
  317. return CSDL_Ext::isTransparent(surf, coords.x - margins.x, coords.y - margins.y);
  318. else
  319. return true;
  320. }
  321. Rect SDLImageShared::contentRect() const
  322. {
  323. auto tmpMargins = margins / preScaleFactor;
  324. auto tmpSize = Point(surf->w, surf->h) / preScaleFactor;
  325. return Rect(tmpMargins, tmpSize);
  326. }
  327. Point SDLImageShared::dimensions() const
  328. {
  329. return fullSize / preScaleFactor;
  330. }
  331. std::shared_ptr<IImage> SDLImageShared::createImageReference(EImageBlitMode mode) const
  332. {
  333. if (surf && surf->format->palette)
  334. return std::make_shared<SDLImageIndexed>(shared_from_this(), originalPalette, mode);
  335. else
  336. return std::make_shared<SDLImageRGB>(shared_from_this(), mode);
  337. }
  338. std::shared_ptr<const ISharedImage> SDLImageShared::horizontalFlip() const
  339. {
  340. SDL_Surface * flipped = CSDL_Ext::horizontalFlip(surf);
  341. auto ret = std::make_shared<SDLImageShared>(flipped, preScaleFactor);
  342. ret->fullSize = fullSize;
  343. ret->margins.x = margins.x;
  344. ret->margins.y = fullSize.y - surf->h - margins.y;
  345. ret->fullSize = fullSize;
  346. return ret;
  347. }
  348. std::shared_ptr<const ISharedImage> SDLImageShared::verticalFlip() const
  349. {
  350. SDL_Surface * flipped = CSDL_Ext::verticalFlip(surf);
  351. auto ret = std::make_shared<SDLImageShared>(flipped, preScaleFactor);
  352. ret->fullSize = fullSize;
  353. ret->margins.x = fullSize.x - surf->w - margins.x;
  354. ret->margins.y = margins.y;
  355. ret->fullSize = fullSize;
  356. return ret;
  357. }
  358. // Keep the original palette, in order to do color switching operation
  359. void SDLImageShared::savePalette()
  360. {
  361. // For some images that don't have palette, skip this
  362. if(surf->format->palette == nullptr)
  363. return;
  364. if(originalPalette == nullptr)
  365. originalPalette = SDL_AllocPalette(surf->format->palette->ncolors);
  366. SDL_SetPaletteColors(originalPalette, surf->format->palette->colors, 0, surf->format->palette->ncolors);
  367. }
  368. void SDLImageIndexed::shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove)
  369. {
  370. std::vector<SDL_Color> shifterColors(colorsToMove);
  371. for(uint32_t i=0; i<colorsToMove; ++i)
  372. shifterColors[(i+distanceToMove)%colorsToMove] = originalPalette->colors[firstColorID + i];
  373. SDL_SetPaletteColors(currentPalette, shifterColors.data(), firstColorID, colorsToMove);
  374. }
  375. void SDLImageIndexed::adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask)
  376. {
  377. // If shadow is enabled, following colors must be skipped unconditionally
  378. if (blitMode == EImageBlitMode::WITH_SHADOW || blitMode == EImageBlitMode::WITH_SHADOW_AND_OVERLAY)
  379. colorsToSkipMask |= (1 << 0) + (1 << 1) + (1 << 4);
  380. // Note: here we skip first colors in the palette that are predefined in H3 images
  381. for(int i = 0; i < currentPalette->ncolors; i++)
  382. {
  383. if (i < std::size(sourcePalette) && colorsSimilar(sourcePalette[i], originalPalette->colors[i]))
  384. continue;
  385. if(i < std::numeric_limits<uint32_t>::digits && ((colorsToSkipMask >> i) & 1) == 1)
  386. continue;
  387. currentPalette->colors[i] = CSDL_Ext::toSDL(shifter.shiftColor(CSDL_Ext::fromSDL(originalPalette->colors[i])));
  388. }
  389. }
  390. SDLImageIndexed::SDLImageIndexed(const std::shared_ptr<const ISharedImage> & image, SDL_Palette * originalPalette, EImageBlitMode mode)
  391. :SDLImageBase::SDLImageBase(image, mode)
  392. ,originalPalette(originalPalette)
  393. {
  394. currentPalette = SDL_AllocPalette(originalPalette->ncolors);
  395. SDL_SetPaletteColors(currentPalette, originalPalette->colors, 0, originalPalette->ncolors);
  396. preparePalette();
  397. }
  398. SDLImageIndexed::~SDLImageIndexed()
  399. {
  400. SDL_FreePalette(currentPalette);
  401. }
  402. void SDLImageIndexed::setShadowTransparency(float factor)
  403. {
  404. ColorRGBA shadow50(0, 0, 0, 128 * factor);
  405. ColorRGBA shadow25(0, 0, 0, 64 * factor);
  406. std::array<SDL_Color, 5> colorsSDL = {
  407. originalPalette->colors[0],
  408. originalPalette->colors[1],
  409. originalPalette->colors[2],
  410. originalPalette->colors[3],
  411. originalPalette->colors[4]
  412. };
  413. // seems to be used unconditionally
  414. colorsSDL[0] = CSDL_Ext::toSDL(Colors::TRANSPARENCY);
  415. colorsSDL[1] = CSDL_Ext::toSDL(shadow25);
  416. colorsSDL[4] = CSDL_Ext::toSDL(shadow50);
  417. // seems to be used only if color matches
  418. if (colorsSimilar(originalPalette->colors[2], sourcePalette[2]))
  419. colorsSDL[2] = CSDL_Ext::toSDL(shadow25);
  420. if (colorsSimilar(originalPalette->colors[3], sourcePalette[3]))
  421. colorsSDL[3] = CSDL_Ext::toSDL(shadow50);
  422. SDL_SetPaletteColors(currentPalette, colorsSDL.data(), 0, colorsSDL.size());
  423. }
  424. void SDLImageIndexed::setOverlayColor(const ColorRGBA & color)
  425. {
  426. currentPalette->colors[5] = CSDL_Ext::toSDL(addColors(targetPalette[5], color));
  427. for (int i : {6,7})
  428. {
  429. if (colorsSimilar(originalPalette->colors[i], sourcePalette[i]))
  430. currentPalette->colors[i] = CSDL_Ext::toSDL(addColors(targetPalette[i], color));
  431. }
  432. }
  433. void SDLImageIndexed::preparePalette()
  434. {
  435. switch(blitMode)
  436. {
  437. case EImageBlitMode::ONLY_SHADOW:
  438. case EImageBlitMode::ONLY_OVERLAY:
  439. adjustPalette(ColorFilter::genAlphaShifter(0), 0);
  440. break;
  441. }
  442. switch(blitMode)
  443. {
  444. case EImageBlitMode::SIMPLE:
  445. case EImageBlitMode::WITH_SHADOW:
  446. case EImageBlitMode::ONLY_SHADOW:
  447. case EImageBlitMode::WITH_SHADOW_AND_OVERLAY:
  448. setShadowTransparency(1.0);
  449. break;
  450. case EImageBlitMode::ONLY_BODY:
  451. case EImageBlitMode::ONLY_BODY_IGNORE_OVERLAY:
  452. case EImageBlitMode::ONLY_OVERLAY:
  453. setShadowTransparency(0.0);
  454. break;
  455. }
  456. switch(blitMode)
  457. {
  458. case EImageBlitMode::ONLY_OVERLAY:
  459. case EImageBlitMode::WITH_SHADOW_AND_OVERLAY:
  460. setOverlayColor(Colors::WHITE_TRUE);
  461. break;
  462. case EImageBlitMode::ONLY_SHADOW:
  463. case EImageBlitMode::ONLY_BODY:
  464. setOverlayColor(Colors::TRANSPARENCY);
  465. break;
  466. }
  467. }
  468. SDLImageShared::~SDLImageShared()
  469. {
  470. SDL_FreeSurface(surf);
  471. SDL_FreePalette(originalPalette);
  472. }
  473. SDLImageBase::SDLImageBase(const std::shared_ptr<const ISharedImage> & image, EImageBlitMode mode)
  474. :image(image)
  475. , alphaValue(SDL_ALPHA_OPAQUE)
  476. , blitMode(mode)
  477. {}
  478. std::shared_ptr<const ISharedImage> SDLImageBase::getSharedImage() const
  479. {
  480. return image;
  481. }
  482. void SDLImageRGB::draw(SDL_Surface * where, const Point & pos, const Rect * src) const
  483. {
  484. image->draw(where, nullptr, pos, src, Colors::WHITE_TRUE, alphaValue, blitMode);
  485. }
  486. void SDLImageIndexed::draw(SDL_Surface * where, const Point & pos, const Rect * src) const
  487. {
  488. image->draw(where, currentPalette, pos, src, Colors::WHITE_TRUE, alphaValue, blitMode);
  489. }
  490. void SDLImageIndexed::exportBitmap(const boost::filesystem::path & path) const
  491. {
  492. image->exportBitmap(path, currentPalette);
  493. }
  494. void SDLImageIndexed::scaleTo(const Point & size)
  495. {
  496. image = image->scaleTo(size, currentPalette);
  497. }
  498. void SDLImageRGB::scaleTo(const Point & size)
  499. {
  500. image = image->scaleTo(size, nullptr);
  501. }
  502. void SDLImageIndexed::scaleInteger(int factor)
  503. {
  504. image = image->scaleInteger(factor, currentPalette, blitMode);
  505. }
  506. void SDLImageRGB::scaleInteger(int factor)
  507. {
  508. image = image->scaleInteger(factor, nullptr, blitMode);
  509. }
  510. void SDLImageRGB::exportBitmap(const boost::filesystem::path & path) const
  511. {
  512. image->exportBitmap(path, nullptr);
  513. }
  514. bool SDLImageBase::isTransparent(const Point & coords) const
  515. {
  516. return image->isTransparent(coords);
  517. }
  518. Rect SDLImageBase::contentRect() const
  519. {
  520. return image->contentRect();
  521. }
  522. Point SDLImageBase::dimensions() const
  523. {
  524. return image->dimensions();
  525. }
  526. void SDLImageBase::setAlpha(uint8_t value)
  527. {
  528. alphaValue = value;
  529. }
  530. void SDLImageBase::setBlitMode(EImageBlitMode mode)
  531. {
  532. blitMode = mode;
  533. }
  534. void SDLImageRGB::setOverlayColor(const ColorRGBA & color)
  535. {}
  536. void SDLImageRGB::playerColored(PlayerColor player)
  537. {}
  538. void SDLImageRGB::shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove)
  539. {}
  540. void SDLImageRGB::adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask)
  541. {}