SDLImage.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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 <tbb/parallel_for.h>
  21. #include <SDL_surface.h>
  22. #include <SDL_image.h>
  23. class SDLImageLoader;
  24. //First 8 colors in def palette used for transparency
  25. static constexpr std::array<SDL_Color, 8> sourcePalette = {{
  26. {0, 255, 255, SDL_ALPHA_OPAQUE},
  27. {255, 150, 255, SDL_ALPHA_OPAQUE},
  28. {255, 100, 255, SDL_ALPHA_OPAQUE},
  29. {255, 50, 255, SDL_ALPHA_OPAQUE},
  30. {255, 0, 255, SDL_ALPHA_OPAQUE},
  31. {255, 255, 0, SDL_ALPHA_OPAQUE},
  32. {180, 0, 255, SDL_ALPHA_OPAQUE},
  33. {0, 255, 0, SDL_ALPHA_OPAQUE}
  34. }};
  35. static constexpr std::array<ColorRGBA, 8> targetPalette = {{
  36. {0, 0, 0, 0 }, // 0 - transparency ( used in most images )
  37. {0, 0, 0, 64 }, // 1 - shadow border ( used in battle, adventure map def's )
  38. {0, 0, 0, 64 }, // 2 - shadow border ( used in fog-of-war def's )
  39. {0, 0, 0, 128}, // 3 - shadow body ( used in fog-of-war def's )
  40. {0, 0, 0, 128}, // 4 - shadow body ( used in battle, adventure map def's )
  41. {0, 0, 0, 0 }, // 5 - selection / owner flag ( used in battle, adventure map def's )
  42. {0, 0, 0, 128}, // 6 - shadow body below selection ( used in battle def's )
  43. {0, 0, 0, 64 } // 7 - shadow border below selection ( used in battle def's )
  44. }};
  45. static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2)
  46. {
  47. return c1*a1 / 256 + c2*a2*(255 - a1) / 256 / 256;
  48. }
  49. static ColorRGBA addColors(const ColorRGBA & base, const ColorRGBA & over)
  50. {
  51. return ColorRGBA(
  52. mixChannels(over.r, base.r, over.a, base.a),
  53. mixChannels(over.g, base.g, over.a, base.a),
  54. mixChannels(over.b, base.b, over.a, base.a),
  55. static_cast<ui8>(over.a + base.a * (255 - over.a) / 256)
  56. );
  57. }
  58. static bool colorsSimilar (const SDL_Color & lhs, const SDL_Color & rhs)
  59. {
  60. // it seems that H3 does not requires exact match to replace colors -> (255, 103, 255) gets interpreted as shadow
  61. // exact logic is not clear and requires extensive testing with image editing
  62. // 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
  63. static const int threshold = 8;
  64. int diffR = static_cast<int>(lhs.r) - rhs.r;
  65. int diffG = static_cast<int>(lhs.g) - rhs.g;
  66. int diffB = static_cast<int>(lhs.b) - rhs.b;
  67. int diffA = static_cast<int>(lhs.a) - rhs.a;
  68. return std::abs(diffR) < threshold && std::abs(diffG) < threshold && std::abs(diffB) < threshold && std::abs(diffA) < threshold;
  69. }
  70. int IImage::width() const
  71. {
  72. return dimensions().x;
  73. }
  74. int IImage::height() const
  75. {
  76. return dimensions().y;
  77. }
  78. SDLImageShared::SDLImageShared(const CDefFile * data, size_t frame, size_t group, int preScaleFactor)
  79. : surf(nullptr),
  80. margins(0, 0),
  81. fullSize(0, 0),
  82. originalPalette(nullptr),
  83. preScaleFactor(preScaleFactor)
  84. {
  85. SDLImageLoader loader(this);
  86. data->loadFrame(frame, group, loader);
  87. if(surf == nullptr)
  88. return;
  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, (surf->w / preScaleFactor) * factor, (surf->h / preScaleFactor) * factor);
  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 = margins.x * factor;
  263. ret->margins.y = margins.y * factor;
  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. Point SDLImageShared::dimensions() const
  317. {
  318. return fullSize / preScaleFactor;
  319. }
  320. std::shared_ptr<IImage> SDLImageShared::createImageReference(EImageBlitMode mode) const
  321. {
  322. if (surf && surf->format->palette)
  323. return std::make_shared<SDLImageIndexed>(shared_from_this(), originalPalette, mode);
  324. else
  325. return std::make_shared<SDLImageRGB>(shared_from_this(), mode);
  326. }
  327. std::shared_ptr<const ISharedImage> SDLImageShared::horizontalFlip() const
  328. {
  329. SDL_Surface * flipped = CSDL_Ext::horizontalFlip(surf);
  330. auto ret = std::make_shared<SDLImageShared>(flipped, preScaleFactor);
  331. ret->fullSize = fullSize;
  332. ret->margins.x = margins.x;
  333. ret->margins.y = fullSize.y - surf->h - margins.y;
  334. ret->fullSize = fullSize;
  335. return ret;
  336. }
  337. std::shared_ptr<const ISharedImage> SDLImageShared::verticalFlip() const
  338. {
  339. SDL_Surface * flipped = CSDL_Ext::verticalFlip(surf);
  340. auto ret = std::make_shared<SDLImageShared>(flipped, preScaleFactor);
  341. ret->fullSize = fullSize;
  342. ret->margins.x = fullSize.x - surf->w - margins.x;
  343. ret->margins.y = margins.y;
  344. ret->fullSize = fullSize;
  345. return ret;
  346. }
  347. // Keep the original palette, in order to do color switching operation
  348. void SDLImageShared::savePalette()
  349. {
  350. // For some images that don't have palette, skip this
  351. if(surf->format->palette == nullptr)
  352. return;
  353. if(originalPalette == nullptr)
  354. originalPalette = SDL_AllocPalette(surf->format->palette->ncolors);
  355. SDL_SetPaletteColors(originalPalette, surf->format->palette->colors, 0, surf->format->palette->ncolors);
  356. }
  357. void SDLImageIndexed::shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove)
  358. {
  359. std::vector<SDL_Color> shifterColors(colorsToMove);
  360. for(uint32_t i=0; i<colorsToMove; ++i)
  361. shifterColors[(i+distanceToMove)%colorsToMove] = originalPalette->colors[firstColorID + i];
  362. SDL_SetPaletteColors(currentPalette, shifterColors.data(), firstColorID, colorsToMove);
  363. }
  364. void SDLImageIndexed::adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask)
  365. {
  366. // If shadow is enabled, following colors must be skipped unconditionally
  367. if (blitMode == EImageBlitMode::WITH_SHADOW || blitMode == EImageBlitMode::WITH_SHADOW_AND_OVERLAY)
  368. colorsToSkipMask |= (1 << 0) + (1 << 1) + (1 << 4);
  369. // Note: here we skip first colors in the palette that are predefined in H3 images
  370. for(int i = 0; i < currentPalette->ncolors; i++)
  371. {
  372. if (i < std::size(sourcePalette) && colorsSimilar(sourcePalette[i], originalPalette->colors[i]))
  373. continue;
  374. if(i < std::numeric_limits<uint32_t>::digits && ((colorsToSkipMask >> i) & 1) == 1)
  375. continue;
  376. currentPalette->colors[i] = CSDL_Ext::toSDL(shifter.shiftColor(CSDL_Ext::fromSDL(originalPalette->colors[i])));
  377. }
  378. }
  379. SDLImageIndexed::SDLImageIndexed(const std::shared_ptr<const ISharedImage> & image, SDL_Palette * originalPalette, EImageBlitMode mode)
  380. :SDLImageBase::SDLImageBase(image, mode)
  381. ,originalPalette(originalPalette)
  382. {
  383. currentPalette = SDL_AllocPalette(originalPalette->ncolors);
  384. SDL_SetPaletteColors(currentPalette, originalPalette->colors, 0, originalPalette->ncolors);
  385. preparePalette();
  386. }
  387. SDLImageIndexed::~SDLImageIndexed()
  388. {
  389. SDL_FreePalette(currentPalette);
  390. }
  391. void SDLImageIndexed::setShadowTransparency(float factor)
  392. {
  393. ColorRGBA shadow50(0, 0, 0, 128 * factor);
  394. ColorRGBA shadow25(0, 0, 0, 64 * factor);
  395. std::array<SDL_Color, 5> colorsSDL = {
  396. originalPalette->colors[0],
  397. originalPalette->colors[1],
  398. originalPalette->colors[2],
  399. originalPalette->colors[3],
  400. originalPalette->colors[4]
  401. };
  402. // seems to be used unconditionally
  403. colorsSDL[0] = CSDL_Ext::toSDL(Colors::TRANSPARENCY);
  404. colorsSDL[1] = CSDL_Ext::toSDL(shadow25);
  405. colorsSDL[4] = CSDL_Ext::toSDL(shadow50);
  406. // seems to be used only if color matches
  407. if (colorsSimilar(originalPalette->colors[2], sourcePalette[2]))
  408. colorsSDL[2] = CSDL_Ext::toSDL(shadow25);
  409. if (colorsSimilar(originalPalette->colors[3], sourcePalette[3]))
  410. colorsSDL[3] = CSDL_Ext::toSDL(shadow50);
  411. SDL_SetPaletteColors(currentPalette, colorsSDL.data(), 0, colorsSDL.size());
  412. }
  413. void SDLImageIndexed::setOverlayColor(const ColorRGBA & color)
  414. {
  415. currentPalette->colors[5] = CSDL_Ext::toSDL(addColors(targetPalette[5], color));
  416. for (int i : {6,7})
  417. {
  418. if (colorsSimilar(originalPalette->colors[i], sourcePalette[i]))
  419. currentPalette->colors[i] = CSDL_Ext::toSDL(addColors(targetPalette[i], color));
  420. }
  421. }
  422. void SDLImageIndexed::preparePalette()
  423. {
  424. switch(blitMode)
  425. {
  426. case EImageBlitMode::ONLY_SHADOW:
  427. case EImageBlitMode::ONLY_OVERLAY:
  428. adjustPalette(ColorFilter::genAlphaShifter(0), 0);
  429. break;
  430. }
  431. switch(blitMode)
  432. {
  433. case EImageBlitMode::SIMPLE:
  434. case EImageBlitMode::WITH_SHADOW:
  435. case EImageBlitMode::ONLY_SHADOW:
  436. case EImageBlitMode::WITH_SHADOW_AND_OVERLAY:
  437. setShadowTransparency(1.0);
  438. break;
  439. case EImageBlitMode::ONLY_BODY:
  440. case EImageBlitMode::ONLY_BODY_IGNORE_OVERLAY:
  441. case EImageBlitMode::ONLY_OVERLAY:
  442. setShadowTransparency(0.0);
  443. break;
  444. }
  445. switch(blitMode)
  446. {
  447. case EImageBlitMode::ONLY_OVERLAY:
  448. case EImageBlitMode::WITH_SHADOW_AND_OVERLAY:
  449. setOverlayColor(Colors::WHITE_TRUE);
  450. break;
  451. case EImageBlitMode::ONLY_SHADOW:
  452. case EImageBlitMode::ONLY_BODY:
  453. setOverlayColor(Colors::TRANSPARENCY);
  454. break;
  455. }
  456. }
  457. SDLImageShared::~SDLImageShared()
  458. {
  459. SDL_FreeSurface(surf);
  460. SDL_FreePalette(originalPalette);
  461. }
  462. SDLImageBase::SDLImageBase(const std::shared_ptr<const ISharedImage> & image, EImageBlitMode mode)
  463. :image(image)
  464. , alphaValue(SDL_ALPHA_OPAQUE)
  465. , blitMode(mode)
  466. {}
  467. std::shared_ptr<const ISharedImage> SDLImageBase::getSharedImage() const
  468. {
  469. return image;
  470. }
  471. void SDLImageRGB::draw(SDL_Surface * where, const Point & pos, const Rect * src) const
  472. {
  473. image->draw(where, nullptr, pos, src, Colors::WHITE_TRUE, alphaValue, blitMode);
  474. }
  475. void SDLImageIndexed::draw(SDL_Surface * where, const Point & pos, const Rect * src) const
  476. {
  477. image->draw(where, currentPalette, pos, src, Colors::WHITE_TRUE, alphaValue, blitMode);
  478. }
  479. void SDLImageIndexed::exportBitmap(const boost::filesystem::path & path) const
  480. {
  481. image->exportBitmap(path, currentPalette);
  482. }
  483. void SDLImageIndexed::scaleTo(const Point & size)
  484. {
  485. image = image->scaleTo(size, currentPalette);
  486. }
  487. void SDLImageRGB::scaleTo(const Point & size)
  488. {
  489. image = image->scaleTo(size, nullptr);
  490. }
  491. void SDLImageIndexed::scaleInteger(int factor)
  492. {
  493. image = image->scaleInteger(factor, currentPalette, blitMode);
  494. }
  495. void SDLImageRGB::scaleInteger(int factor)
  496. {
  497. image = image->scaleInteger(factor, nullptr, blitMode);
  498. }
  499. void SDLImageRGB::exportBitmap(const boost::filesystem::path & path) const
  500. {
  501. image->exportBitmap(path, nullptr);
  502. }
  503. bool SDLImageBase::isTransparent(const Point & coords) const
  504. {
  505. return image->isTransparent(coords);
  506. }
  507. Point SDLImageBase::dimensions() const
  508. {
  509. return image->dimensions();
  510. }
  511. void SDLImageBase::setAlpha(uint8_t value)
  512. {
  513. alphaValue = value;
  514. }
  515. void SDLImageBase::setBlitMode(EImageBlitMode mode)
  516. {
  517. blitMode = mode;
  518. }
  519. void SDLImageRGB::setOverlayColor(const ColorRGBA & color)
  520. {}
  521. void SDLImageRGB::playerColored(PlayerColor player)
  522. {}
  523. void SDLImageRGB::shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove)
  524. {}
  525. void SDLImageRGB::adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask)
  526. {}