Loading

Paste #pvhndva52

  1. diff --git a/CorsixTH/Src/th_gfx_sdl.cpp b/CorsixTH/Src/th_gfx_sdl.cpp
  2. index a989ac4..06d5cd8 100644
  3. --- a/CorsixTH/Src/th_gfx_sdl.cpp
  4. +++ b/CorsixTH/Src/th_gfx_sdl.cpp
  5. @@ -59,7 +59,7 @@ static inline uint32_t makeGreyScale(uint8_t iOpacity, uint8_t iR, uint8_t iG, u
  6.      // 0.7152 * 65536 = 46871.3472
  7.      // 0.0722 * 65536 =  4731.6992 -> 4732
  8.      // 13933 + 46871 + 4732 = 65536 = 2**16
  9. -    uint8_t iGrey = (13933 * iR + 46871 * iG + 4732 * iB) >> 16;
  10. +    uint8_t iGrey = static_cast<uint8_t>((13933 * iR + 46871 * iG + 4732 * iB) >> 16);
  11.      return THPalette::packARGB(iOpacity, iGrey, iGrey, iGrey);
  12.  }
  13.  
  14. @@ -78,11 +78,11 @@ static inline uint32_t makeSwapRedBlue(uint8_t iOpacity, uint8_t iR, uint8_t iG,
  15.      // Simple swapping channels will thus distort the balance. This code compensates for that by computing
  16.      // red  = blue * 0.0722 / 0.2126 = blue * 1083 / 3189
  17.      // blue = red  * 0.2126 / 0.0722 = red  * 1063 / 361 (clipped at max blue, 255)
  18. -    uint8_t iNewRed = iB * 1083 / 3189;
  19. +    uint8_t iNewRed = static_cast<uint8_t>(iB * 1083 / 3189);
  20.      int iNewBlue = iR * 1063 / 361;
  21.      if (iNewBlue > 255)
  22.          iNewBlue = 255;
  23. -    return THPalette::packARGB(iOpacity, iNewRed, iG, iNewBlue);
  24. +    return THPalette::packARGB(iOpacity, iNewRed, iG, static_cast<uint8_t>(iNewBlue));
  25.  }
  26.  
  27.  bool FullColourRenderer::decodeImage(const uint8_t* pImg, const THPalette *pPalette, uint32_t iSpriteFlags)
  28. @@ -351,8 +351,8 @@ bool THRenderTarget::setScaleFactor(float fScale, THScaledItems eWhatToScale)
  29.          //Draw everything from now until the next scale to m_pZoomTexture
  30.          //with the appropriate virtual size, which will be copied scaled to
  31.          //fit the window.
  32. -        float virtWidth = static_cast<float>(m_iWidth) / fScale;
  33. -        float virtHeight = static_cast<float>(m_iHeight) / fScale;
  34. +        int virtWidth = static_cast<int>(static_cast<float>(m_iWidth) / fScale + 0.5);
  35. +        int virtHeight = static_cast<int>(static_cast<float>(m_iHeight) / fScale + 0.5);
  36.  
  37.          m_pZoomTexture = SDL_CreateTexture(m_pRenderer,
  38.                                             SDL_PIXELFORMAT_ABGR8888,
  39. @@ -416,7 +416,7 @@ bool THRenderTarget::endFrame()
  40.      if(m_bBlueFilterActive)
  41.      {
  42.          SDL_SetRenderDrawBlendMode(m_pRenderer, SDL_BLENDMODE_BLEND);
  43. -        SDL_SetRenderDrawColor(m_pRenderer, 255*0.2f, 255*0.2f, 255*1.0f, 255*0.5f);
  44. +        SDL_SetRenderDrawColor(m_pRenderer, 51, 51, 255, 128); // r=0.2, g=0.2, b=1, a=0.5 .
  45.          SDL_RenderFillRect(m_pRenderer, NULL);
  46.      }
  47.  
  48. @@ -599,7 +599,7 @@ static uint8_t *convertLegacySprite(const uint8_t* pPixelData, size_t iPixelData
  49.      while (iPixelDataLength > 0)
  50.      {
  51.          size_t iLength = (iPixelDataLength >= 63) ? 63 : iPixelDataLength;
  52. -        *pDest++ = iLength + 0xC0; // Recolour layer type of block.
  53. +        *pDest++ = static_cast<uint8_t>(iLength + 0xC0); // Recolour layer type of block.
  54.          *pDest++ = 0xFF; // Use special table 0xFF (which uses the palette as table).
  55.          *pDest++ = 0xFF; // Non-transparent.
  56.          memcpy(pDest, pPixelData, iLength);
  57. @@ -632,7 +632,7 @@ SDL_Texture* THRenderTarget::createTexture(int iWidth, int iHeight,
  58.                                             const uint32_t* pPixels) const
  59.  {
  60.      SDL_Texture *pTexture = SDL_CreateTexture(m_pRenderer, m_pFormat->format, SDL_TEXTUREACCESS_STATIC, iWidth, iHeight
  61. );
  62. -    SDL_UpdateTexture(pTexture, NULL, pPixels, sizeof(*pPixels) * iWidth);
  63. +    SDL_UpdateTexture(pTexture, NULL, pPixels, static_cast<int>(sizeof(*pPixels) * iWidth));
  64.      SDL_SetTextureBlendMode(pTexture, SDL_BLENDMODE_BLEND);
  65.      SDL_SetTextureColorMod(pTexture, 0xFF, 0xFF, 0xFF);
  66.      SDL_SetTextureAlphaMod(pTexture, 0xFF);
  67. @@ -677,7 +677,10 @@ void THRenderTarget::drawLine(THLine *pLine, int iX, int iY)
  68.      THLine::THLineOperation* op = (THLine::THLineOperation*)(pLine->m_pFirstOp->m_pNext);
  69.      while (op) {
  70.          if (op->type == THLine::THLOP_LINE) {
  71. -            SDL_RenderDrawLine(m_pRenderer, lastX + iX, lastY + iY, op->m_fX + iX, op->m_fY + iY);
  72. +            SDL_RenderDrawLine(m_pRenderer, static_cast<int>(lastX + iX),
  73. +                                            static_cast<int>(lastY + iY),
  74. +                                            static_cast<int>(op->m_fX + iX),
  75. +                                            static_cast<int>(op->m_fY + iY));
  76.          }
  77.  
  78.          lastX = op->m_fX;
  79. @@ -879,8 +882,8 @@ void THRawBitmap::draw(THRenderTarget* pCanvas, int iX, int iY,
  80.      const SDL_Rect rcSrc  = { iSrcX, iSrcY, iWidth, iHeight };
  81.      const SDL_Rect rcDest = { iX,
  82.                                iY,
  83. -                              static_cast<int>(iWidth * fScaleFactor),
  84. -                              static_cast<int>(iHeight * fScaleFactor) };
  85. +                              static_cast<int>(iWidth  * static_cast<double>(fScaleFactor)),
  86. +                              static_cast<int>(iHeight * static_cast<double>(fScaleFactor)) };
  87.  
  88.      pCanvas->draw(m_pTexture, &rcSrc, &rcDest, 0);
  89.  }

Comments