Skip to content

Commit

Permalink
b2s: remove grills from direct2bs images
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm174 committed Oct 3, 2023
1 parent b1c82b0 commit dc944f2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
50 changes: 24 additions & 26 deletions VPXDisplayServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,8 @@ void VPXDisplayServer::RenderDisplay(VPXDisplay* pDisplay)
SDL_SetRenderDrawColor(pDisplay->pRenderer, 0, 0, 0, 255);
SDL_RenderClear(pDisplay->pRenderer);

if (pDisplay->pTexture) {
int textureWidth;
int textureHeight;
SDL_QueryTexture(pDisplay->pTexture, NULL, NULL, &textureWidth, &textureHeight);

float aspectRatio = (float)textureWidth / textureHeight;

int destWidth;
int destHeight;
if (pDisplay->width / aspectRatio < pDisplay->height) {
destWidth = pDisplay->width;
destHeight = pDisplay->width / aspectRatio;
}
else {
destWidth = pDisplay->height * aspectRatio;
destHeight = pDisplay->height;
}

SDL_Rect destRect = { (pDisplay->width - destWidth) / 2, (pDisplay->height - destHeight) / 2, destWidth, destHeight };
SDL_RenderCopy(pDisplay->pRenderer, pDisplay->pTexture, NULL, &destRect);
}
if (pDisplay->pTexture)
SDL_RenderCopy(pDisplay->pRenderer, pDisplay->pTexture, NULL, NULL);

SDL_RenderPresent(pDisplay->pRenderer);
}
Expand Down Expand Up @@ -376,12 +357,8 @@ SDL_Surface* VPXDisplayServer::GetB2SImage(const string& szVpx)

auto topnode = b2sTree.FirstChildElement("DirectB2SData");

int grillHeight = std::max(topnode->FirstChildElement("GrillHeight")->IntAttribute("Value"), 0);
int smallGrillHeight = 0;
int backglassGrillHeight = std::max(topnode->FirstChildElement("GrillHeight")->IntAttribute("Value"), 0);

if (topnode->FirstChildElement("GrillHeight")->FindAttribute("Small") && grillHeight > 0)
smallGrillHeight = std::max(topnode->FirstChildElement("GrillHeight")->IntAttribute("Small"), 0);

if (topnode->FirstChildElement("Images")) {
if (topnode->FirstChildElement("Images")->FirstChildElement("BackglassOffImage")) {
pImage = Base64ToImage(topnode->FirstChildElement("Images")->FirstChildElement("BackglassOffImage")->Attribute("Value"));
Expand All @@ -396,6 +373,14 @@ SDL_Surface* VPXDisplayServer::GetB2SImage(const string& szVpx)
if (topnode->FirstChildElement("Images")->FirstChildElement("BackglassImage"))
pImage = Base64ToImage(topnode->FirstChildElement("Images")->FirstChildElement("BackglassImage")->Attribute("Value"));
}

if (pImage && backglassGrillHeight > 0) {
SDL_Surface* pResizedImage = ResizeImage(pImage, backglassGrillHeight);
if (pResizedImage) {
SDL_FreeSurface(pImage);
pImage = pResizedImage;
}
}
}
}

Expand Down Expand Up @@ -464,3 +449,16 @@ vector<unsigned char> VPXDisplayServer::Base64Decode(const string &encoded_strin

return ret;
}

SDL_Surface* VPXDisplayServer::ResizeImage(SDL_Surface* pSourceImage, int grillheight)
{
SDL_Surface* pImageWithoutGrill = SDL_CreateRGBSurface(0, pSourceImage->w, pSourceImage->h - grillheight, pSourceImage->format->BitsPerPixel,
pSourceImage->format->Rmask, pSourceImage->format->Gmask, pSourceImage->format->Bmask, pSourceImage->format->Amask);

if (!pImageWithoutGrill)
return NULL;

SDL_BlitSurface(pSourceImage, NULL, pImageWithoutGrill, NULL);

return pImageWithoutGrill;
}
1 change: 1 addition & 0 deletions VPXDisplayServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class VPXDisplayServer
SDL_Surface* GetB2SImage(const string& filename);
SDL_Surface* Base64ToImage(const string& image);
vector<unsigned char> Base64Decode(const string &encoded_string);
SDL_Surface* ResizeImage(SDL_Surface* pSourceImage, int grillheight);

VPXDisplay* m_pBackglassDisplay;
VPXDisplay* m_pDMDDisplay;
Expand Down

0 comments on commit dc944f2

Please sign in to comment.