Exemplo n.º 1
0
  // save a screenshot icon
  void SaveScreenShotPreview()
  {
    const int w = Vision::Video.GetXRes();
    const int h = Vision::Video.GetYRes();

    unsigned char *pTempBuffer = new unsigned char [w*h*3];
    char pszPreviewFileName[FS_MAX_PATH];
    sprintf(pszPreviewFileName, SAVEGAME_PREVIEW, m_iSlotIndex + 1);

    // write the screen buffer to memory buffer
    if (Vision::Game.WriteScreenToBuffer(0,0,w,h,(UBYTE *)pTempBuffer))
    {
      // use VTEX to scale and save the image
      Image_cl image;
      ImageMap_cl colorMap(w,h,24, (UBYTE*)pTempBuffer);
      image.AddColorMap(colorMap);
      image.Scale(128,128);
      image.SaveBMP(pszPreviewFileName,Vision::File.GetOutputManager());
    }
    delete []pTempBuffer;

    // make sure texture is reloaded next time
    if (m_spPreviewMask->GetTextureObject())
      m_spPreviewMask->GetTextureObject()->EnsureUnloaded();
  }
void VRestoreScreen::SaveBackgroundScreenshot()
{
  // GrabBackgroundScreenshot() needs to be called before
  if (m_pScreenshotBuffer == NULL)
    return;

  const int iScreenWidth = Vision::Video.GetXRes();
  const int iScreenHeight = Vision::Video.GetYRes();
  ColorCorrect(m_pScreenshotBuffer, iScreenWidth, iScreenHeight, m_fBrightness, m_fSaturation);

  // use VTEX to scale and save the image
  Image_cl image;
  ImageMap_cl colorMap(iScreenWidth, iScreenHeight, 24, static_cast<UBYTE*>(m_pScreenshotBuffer));
  image.AddColorMap(colorMap);

  // Decide which resolution to use for the saved image.
  int iScaledWidth = 512;
  while (iScaledWidth > iScreenWidth || iScaledWidth > iScreenHeight)
  {
    iScaledWidth /= 2;
    VASSERT(iScaledWidth > 0);
  }

  image.Scale(iScaledWidth, iScaledWidth);

  const char* szFilename = ":app_cache/vision_background.bmp";
  IVFileOutStream* pOut = Vision::File.Create(szFilename);
  const bool bSaved = (image.SaveBMP(pOut) == VERR_NOERROR);
  V_SAFE_DELETE_ARRAY(m_pScreenshotBuffer);

  if (pOut != NULL)
    pOut->Close();

  if (bSaved)
  {
    // Set up loading screen settings.
    Settings settings(szFilename);
    settings.m_eAspectRatioAlignment = ALIGN_NONE;
    SetSettings(settings);
  }
  else
  {
    hkvLog::Dev("VRestoreScreen: Could not save backgrounding screenshot\n");
  }
}
bool VTerrainSectorRenderer::SaveRenderTarget(VTerrainSector* pSector, VisRenderableTexture_cl *pTex, const char *szFilePath)
{
  VASSERT(pSector);

  // since the functions below require an absolute path, we somehow need to get from a relative path to an absolute path
  // opening a file and getting its then final path is the only way, that I found, to accomplish this
  char szAbsFilename[FS_MAX_PATH];

  // create the file and convert the relative path into an absolute path
  IVFileOutStream* pStream = Vision::File.Create (szFilePath);
  if (!pStream)
    return false;

  strcpy (szAbsFilename, pStream->GetFileName());
  pStream->Close();

  VRCSHelper::RCSEditFile(szAbsFilename);

  if (pTex==NULL)
    return false;

  int sx = pTex->GetTextureWidth();
  int sy = pTex->GetTextureHeight();

  Image_cl image;
  VMemoryTempBuffer<512*512*3> buffer(sx*sy*3);
  UBYTE* pDest = (UBYTE*)buffer.GetBuffer();
  Vision::Game.WriteScreenToBuffer(0, 0, sx, sy, pDest, pTex);
  if(Vision::Renderer.GetSRGBMode() == V_SRGB_ASSUME_FOR_DIFFUSE)
  {
    for (int i = 0; i < sx*sy*3; ++i)
      pDest[i] = (UBYTE) (LinearToSrgb (((float) pDest[i]) / 255.0f) * 255.0f);
  }

  // The terrain sector renderer leaves a border area around the sector being rendered,
  // this is required to ensure proper texture filtering on sector edges. Into this border area
  // the neighbor sectors are rendered to, but not each sector has a neighbor on each side, thus the next
  // step fills all the pixels where nothing has been rendered to.
  FillBorders(pSector, sx, sy, m_iBorderWidth, pDest);

  image.AddColorMap(sx,sy,COLORDEPTH_24BPP,pDest);

  int iSavingResult = -1;

  if (VFileHelper::HasExtension(szAbsFilename,"BMP"))
    iSavingResult = image.SaveBMP(szAbsFilename);
  else if (VFileHelper::HasExtension(szAbsFilename,"JPG"))
    iSavingResult = image.SaveJPEG(szAbsFilename);
  else if (VFileHelper::HasExtension(szAbsFilename,"JPEG"))
    iSavingResult = image.SaveJPEG(szAbsFilename);
  else if (VFileHelper::HasExtension(szAbsFilename,"TGA"))
    iSavingResult = image.SaveTGA(szAbsFilename);
  else if (VFileHelper::HasExtension(szAbsFilename,"DDS"))
    iSavingResult = image.SaveUncompressedDDS(szAbsFilename);

  VRCSHelper::RCSAddFile(szAbsFilename, true /* Binary file */);

  return iSavingResult == 0;
}
Exemplo n.º 4
0
void LightmapPageTweakInfo::Save(UBYTE *pDestBuffer)
{
  for (int i=0;i<4;i++)
  {
    if (!MixSingleChannel(i,pDestBuffer,true))
      continue;

    int iSizeX = m_spLightmapChannel[i]->GetTextureWidth();
    int iSizeY = m_spLightmapChannel[i]->GetTextureHeight();

    // use vtex to save dds texture
    Image_cl image;
    VString sAbsFilename;
    const char *szFilename = m_spLightmapChannel[i]->GetFilename();
    String ^absPath = EditorManager::EngineManager->File_MakeAbsolute(ConversionUtils::VStringToString(szFilename));
    ConversionUtils::StringToVString( absPath, sAbsFilename );
    if (sAbsFilename.IsEmpty())
      continue;
    image.AddColorMap( iSizeX, iSizeY, COLORDEPTH_24BPP, (UBYTE *) pDestBuffer );
    image.Save(sAbsFilename);
  }
}