// save anim set file
BOOL CSeriousSkaStudioApp::SaveAnimSetFile(CAnimSet &as, BOOL bConvert)
{
  DisableRendering();
  CTFileName fnAnimSet = as.GetName();
  fnAnimSet = fnAnimSet.NoExt() + ".aal";
  try {
    fnAnimSet.RemoveApplicationPath_t();
  } catch(char *){}

  // back up current skeleton list file
  CTString strBackUp;
  try {
    strBackUp.Load_t(fnAnimSet); 
  } catch(char*){}

  CTFileStream ostrFile;
  try {
    ostrFile.Create_t(fnAnimSet,CTStream::CM_TEXT);
    SaveAnimSet_t(as,ostrFile);
    ostrFile.Close();
  } catch(char *strError) {
    ErrorMessage(strError);
    EnableRendering();
    return FALSE;
  }

  if(bConvert) {
    ConvertAnimSet(fnAnimSet);
  }

  EnableRendering();
  return TRUE;
}
void CPlayerCharacter::Load_t( const CTFileName &fnFile) // throw char *
{
  CTFileStream strm;
  strm.Open_t(fnFile);
  Read_t(&strm);
  strm.Close();
}
示例#3
0
extern void WriteFont_t(CFontData &fdFont, const CImageInfo &iiFont, const CImageInfo &iiGrid, const CTFileName &fnFont)
{
  MEX inMex = Max(iiFont.ii_Height,iiFont.ii_Width);
  INDEX ctMipmaps = 0;// GetNoOfMipmaps(iiFont.ii_Width,iiFont.ii_Height);

  CTFileName fnName = fnFont.NoExt();
  try {
    fnName.RemoveApplicationPath_t();
  } catch(char *) {
  }
  // save font tga file
  iiFont.SaveTGA_t(fnName + ".tga");
  iiGrid.SaveTGA_t(fnName + "G.tga");
  // create tex file from saved targa
  CreateTexture_t( fnName+".tga",  fnName+".tex",  inMex, ctMipmaps, TEX_CONSTANT);
  CreateTexture_t( fnName+"G.tga", fnName+"G.tex", inMex, ctMipmaps);
  
  // set texture source to saved font
  fdFont.fd_ptdTextureData = _pTextureStock->Obtain_t(fnName+".tex");
  fdFont.fd_ptdTextureData->Reload();
  fdFont.fd_ptdTextureData->Force(TEX_CONSTANT); // don't mess with created textures
  fdFont.fd_fnTexture = fnName+".tex";

  _ptdGrid = _pTextureStock->Obtain_t(fnName + "G.tex");
  if(_ptdGrid!=NULL) {
    _ptdGrid->Reload();
    _ptdGrid->Force(TEX_CONSTANT); // don't mess with created textures
  }

  // finaly save fnt file
  CTFileStream ostr;
  ostr.Create_t(fnName + ".fnt");
  fdFont.Write_t(&ostr);
}
// Save smc file
void CSeriousSkaStudioApp::SaveSmcFile(CModelInstance &mi,BOOL bSaveChildren)
{
	CSeriousSkaStudioDoc *pDoc = GetDocument();

  // first get first model instance that has its file
  CModelInstance *pmiParent=NULL;
  CModelInstance *pmiFirst=&mi;
  CTFileName fnSmc = mi.mi_fnSourceFile;
  CModelInstance *pfmi = mi.GetFirstNonReferencedParent(GetDocument()->m_ModelInstance);
  if(pfmi!=NULL) {
    pmiParent = pfmi->GetParent(pDoc->m_ModelInstance);
    pmiFirst = pfmi;
    fnSmc = pfmi->mi_fnSourceFile;
  }

  DisableRendering();
  try
  {
    fnSmc.RemoveApplicationPath_t();
  }
  catch(char *){}

  CTFileStream ostrFile;
  // try to save model instance
  try {
    ostrFile.Create_t(fnSmc,CTStream::CM_TEXT);
    SaveModelInstance_t(pmiFirst,pmiParent,ostrFile,bSaveChildren);
    ostrFile.Close();
    NotificationMessage("Smc '%s' saved.",pmiFirst->mi_fnSourceFile); 
  } catch(char *strError) {
    ErrorMessage(strError);
  }
  EnableRendering();
}
示例#5
0
void CAM_Start(const CTFileName &fnmDemo)
{
  _bCameraOn = FALSE;
  CTFileName fnmScript = fnmDemo.NoExt()+".ini";
  if( cam_bRecord) {
    try {
      _strScript.Create_t(fnmScript);
    } catch(char *strError) {
      CPrintF("Camera: %s\n", strError);
      return;
    };
    _cp.cp_vPos = FLOAT3D(0,0,0);
    _cp.cp_aRot = ANGLE3D(0,0,0);
    _cp.cp_aFOV = 90.0f;
    _cp.cp_fSpeed = 1;
    _cp.cp_tmTick = 0.0f;
  } else {
    try {
      _strScript.Open_t(fnmScript);
    } catch(char *strError) {
      (void)strError;
      return;
    };
  }
  _bCameraOn = TRUE;
  _bInitialized = FALSE;
}
void CPlayerCharacter::Save_t( const CTFileName &fnFile) // throw char *
{
  CTFileStream strm;
  strm.Create_t(fnFile);
  Write_t(&strm);
  strm.Close();
}
示例#7
0
/*
 * Load entire world (both brushes and current state).
 */
void CWorld::Load_t(const CTFileName &fnmWorld) // throw char *
{
  // remember the file
  wo_fnmFileName = fnmWorld;
  // open the file
  CTFileStream strmFile;
  strmFile.Open_t(fnmWorld);

  // check engine build allowing reinit
  BOOL bNeedsReinit;
  _pNetwork->CheckVersion_t(strmFile, TRUE, bNeedsReinit);

  // read the world from the file
  Read_t(&strmFile);

  // close the file
  strmFile.Close();

  // if reinit is needed
  if (bNeedsReinit) {
    // reinitialize
    SetProgressDescription(TRANS("converting from old version"));
    CallProgressHook_t(0.0f);
    ReinitializeEntities();
    CallProgressHook_t(1.0f);
    // reinitialize
    SetProgressDescription(TRANS("saving converted file"));
    CallProgressHook_t(0.0f);
    Save_t(fnmWorld);
    CallProgressHook_t(1.0f);
  }
}
示例#8
0
// enable dictionary in writable file from this point
void CTStream::DictionaryWriteBegin_t(const CTFileName &fnmImportFrom, SLONG slImportOffset)
{
  ASSERT(strm_slDictionaryPos==0);
  ASSERT(strm_dmDictionaryMode == DM_NONE);
  strm_ntDictionary.SetAllocationParameters(100, 5, 5);
  strm_ctDictionaryImported = 0;

  // if importing an existing dictionary to start with
  if (fnmImportFrom!="") {
    // open that file
    CTFileStream strmOther;
    strmOther.Open_t(fnmImportFrom);
    // read the dictionary in that stream
    strmOther.ReadDictionary_intenal_t(slImportOffset);
    // copy the dictionary here
    CopyDictionary(strmOther);
    // write dictionary importing data
    WriteID_t("DIMP");  // dictionary import
    *this<<fnmImportFrom<<slImportOffset;
    // remember how many filenames were imported
    strm_ctDictionaryImported = strm_afnmDictionary.Count();
  }

  // write dictionary position chunk id
  WriteID_t("DPOS");  // dictionary position
  // remember where position will be placed
  strm_slDictionaryPos = GetPos_t();
  // leave space for position
  *this<<SLONG(0);

  // start dictionary
  strm_dmDictionaryMode = DM_ENABLED;
}
示例#9
0
/*
 * Save entire world (both brushes  current state).
 */
void CWorld::Save_t(const CTFileName &fnmWorld) // throw char *
{
  // create the file
  CTFileStream strmFile;
  strmFile.Create_t(fnmWorld);

  // save engine build
  _pNetwork->WriteVersion_t(strmFile);

  // write the world to the file
  Write_t(&strmFile);
}
示例#10
0
static void LoadOneFile(const CTFileName &fnm)
{
  try {
    // open the file
    CTFileStream strm;
    strm.Open_t(fnm);

    // count number of lines
    INDEX ctLines = 0;
    while(!strm.AtEOF()) {
      CTString strLine;
      strm.GetLine_t(strLine);
      ctLines++;
    }
    strm.SetPos_t(0);

    // allocate that much
    CTString *astr = _astrCredits.Push(ctLines);
    // load all lines
    for(INDEX iLine = 0; iLine<ctLines && !strm.AtEOF(); iLine++) {
      strm.GetLine_t(astr[iLine]);
    }

    strm.Close();

    _bCreditsOn = TRUE;
  } catch (char *strError) {
    CPrintF("%s\n", strError);
  }
}
示例#11
0
static void SaveSettings(const CTFileName &fnConfgin)
{
  if(!_bInitialized) return;
  try {
    CTFileStream ostr;
    ostr.Create_t(fnConfgin);

    INDEX iVersion=CONFIG_VERSION;
    ULONG ulFlags = GetFontFlags();
    INDEX iFontSize = GetIntFromControl(IEC_FONT_SIZE);
    INDEX iFirstChar = GetIntFromControl(IEC_FIRST_CHAR);
    INDEX iLastChar = GetIntFromControl(IEC_LAST_CHAR);
    INDEX iAlignH  = GetComboIndex(IDC_ALIGN_H);
    INDEX iAlignV  = GetComboIndex(IDC_ALIGN_V);
    INDEX iPaddingX = GetIntFromControl(IEC_PADDINGX);
    INDEX iPaddingY = GetIntFromControl(IEC_PADDINGY);
    INDEX iWidthAdd = GetIntFromControl(IEC_WIDTH_ADD);
    INDEX iHeightAdd = GetIntFromControl(IEC_HEIGHT_ADD);
    INDEX ctShadows = GetIntFromControl(IEC_SHADOW_PASSES);
    INDEX iTexWidth = GetIntFromControl(ICB_TEX_WIDTH);
    INDEX iTexHeight = GetIntFromControl(ICB_TEX_HEIGHT);
    const CTString strFontName = GetStringFromControl(ICB_FONT_NAMES);
    const CTString strSampleText = GetStringFromControl(IEC_SAMPLE_TEXT);

  
    ostr<<iVersion;
    ostr<<ulFlags;
    ostr<<iFontSize;
    ostr<<iFirstChar;
    ostr<<iLastChar;
    ostr<<iAlignH;
    ostr<<iAlignV;
    ostr<<iPaddingX;
    ostr<<iPaddingY;
    ostr<<iWidthAdd;
    ostr<<iHeightAdd;
    ostr<<ctShadows;
    ostr<<iTexWidth;
    ostr<<iTexHeight;
    ostr<<strFontName;
    ostr<<strSampleText;
    ostr<<_bShowTexture;
    ostr<<_bShowGrid;
    ostr<<_fnCharacterTable;
  } catch(char *strErr) {
    MessageBox(_hWnd,strErr,0,0);
  }
}
示例#12
0
void CAM_Stop(void)
{
  if (_bCameraOn) {
    _strScript.Close();
  }
  _bCameraOn = FALSE;
}
示例#13
0
// save TGA routine
void CImageInfo::SaveTGA_t( const CTFileName &strFileName) const // throw char *
{
  TGAHeader *pTGAHdr;
  UBYTE *pTGABuffer, *pTGAImage;
  SLONG slFileSize;
  PIX pixBitmapSize = ii_Width*ii_Height;
  CTFileStream TGAFile;

  // determine and check image info format
  SLONG slBytesPerPixel = ii_BitsPerPixel/8;
  ASSERT( slBytesPerPixel==3 || slBytesPerPixel==4);
  if( slBytesPerPixel!=3 && slBytesPerPixel!=4) throw( TRANS( "Unsupported BitsPerPixel in ImageInfo header."));

  // determine TGA file size and allocate memory
  slFileSize = sizeof(struct TGAHeader) + pixBitmapSize *slBytesPerPixel;
  pTGABuffer = (UBYTE*)AllocMemory( slFileSize);
  pTGAHdr    = (struct TGAHeader*)pTGABuffer;
  pTGAImage  = pTGABuffer + sizeof(struct TGAHeader);

  // set TGA picture size dimensions
  memset( pTGABuffer, 0x0, sizeof(struct TGAHeader));
  pTGAHdr->Width        = (UWORD)ii_Width;
  pTGAHdr->Height       = (UWORD)ii_Height;
  pTGAHdr->BitsPerPixel = (UBYTE)ii_BitsPerPixel;
  pTGAHdr->ImageType    = 2;

  // flip image vertically
  BOOL bAlphaChannel = (slBytesPerPixel==4);
  FlipBitmap( ii_Picture, pTGAImage, ii_Width, ii_Height, 1, bAlphaChannel);

  // convert CroTeam's pixel format to TGA format
  UBYTE *pubTmp = pTGAImage;  // need 'walking' pointer
  for( INDEX iPix=0; iPix<pixBitmapSize; iPix++)
  { // flip bytes
    Swap( pubTmp[0], pubTmp[2]);  // R & B channels
    pubTmp += slBytesPerPixel; 
  }

  // save entire TGA memory to file and close it
  TGAFile.Create_t( strFileName);
  TGAFile.Write_t( pTGABuffer, slFileSize);
  TGAFile.Close();

  // free temorary allocated memory for TGA image format
  FreeMemory( pTGABuffer);
}
示例#14
0
/*
 * Load just world brushes from a file with entire world information.
 */
void CWorld::LoadBrushes_t(const CTFileName &fnmWorld) // throw char *
{
  // remember the file
  wo_fnmFileName = fnmWorld;
  // open the file
  CTFileStream strmFile;
  strmFile.Open_t(fnmWorld);

  // check engine build disallowing reinit
  BOOL bNeedsReinit;
  _pNetwork->CheckVersion_t(strmFile, FALSE, bNeedsReinit);
  ASSERT(!bNeedsReinit);

  strmFile.ExpectID_t("WRLD"); // 'world'
  // read the world brushes from the file
  ReadBrushes_t(&strmFile);
}
void CDlgCreateSpecularTexture::CreateTexture( CTFileName fnTexture, FLOAT fExp)
{
  CImageInfo II;
  CTFileStream fsFile;
  CTextureData TD;

  INDEX iSelectedSize = m_comboSizeInPixels.GetCurSel();
  ASSERT( iSelectedSize != CB_ERR);
  PIX pixSize = 1UL<<iSelectedSize;
  PIX pixSizeI = pixSize;
  PIX pixSizeJ = pixSize;
  UBYTE *pubImage = (UBYTE *)AllocMemory(pixSize*pixSize*3);
  II.Attach(pubImage, pixSize, pixSize, 24);
  for (PIX pixI=0; pixI<pixSizeI; pixI++) {
    for (PIX pixJ=0; pixJ<pixSizeJ; pixJ++) {
      FLOAT fS = pixI*2.0f/pixSizeI-1;
      FLOAT fT = pixJ*2.0f/pixSizeJ-1;
      FLOAT fZ = Sqrt(1-2*fS*fS-2*fT*fT);
      fZ = Clamp(fZ, 0.0f, 1.0f);
      FLOAT fZN = FLOAT(pow(fZ, fExp));
      ASSERT(fZN>=0 && fZN<=1);
      UBYTE ub = UBYTE(fZN*255);
      pubImage[(pixJ*pixSize+pixI)*3+0] = ub;
      pubImage[(pixJ*pixSize+pixI)*3+1] = ub;
      pubImage[(pixJ*pixSize+pixI)*3+2] = ub;
    }
  }

  try
  {
    TD.Create_t( &II, pixSize, 1, FALSE);
    fsFile.Create_t( fnTexture);
    TD.Write_t( &fsFile);
    fsFile.Close();
  }
  // if failed
  catch (char *strError)
  {
    // report error
    AfxMessageBox(CString(strError));
  }
  II.Detach();
  FreeMemory(pubImage);
}
// save skeleton list file 
BOOL CSeriousSkaStudioApp::SaveSkeletonListFile(CSkeleton &skl, BOOL bConvert)
{
  DisableRendering();
  CTFileName fnSkeletonList = skl.GetName();
  fnSkeletonList = fnSkeletonList.NoExt() + ".asl";
  try {
    fnSkeletonList.RemoveApplicationPath_t();
  }
  catch(char *){}

  // back up current skeleton list file
  CTString strBackUp;
  try {
    strBackUp.Load_t(fnSkeletonList);
  }
  catch(char*){}

  CTFileStream ostrFile;
  try {
    ostrFile.Create_t(fnSkeletonList,CTStream::CM_TEXT);
    SaveSkeletonList_t(skl,ostrFile);
    ostrFile.Close();
  } catch(char *strError) {
    ErrorMessage(strError);
    EnableRendering();
    return FALSE;
  }

  if(bConvert) {
    if(!ConvertSkeleton(fnSkeletonList)) {
      // convert failed
      if(strBackUp.Length()>0) {
        // try returning old mesh list file
        try {
          strBackUp.Save_t(fnSkeletonList);
        }
        catch(char*){}
      }
    }
  }
  EnableRendering();
  return TRUE;
}
// save mesh list file
BOOL CSeriousSkaStudioApp::SaveMeshListFile(MeshInstance &mshi, BOOL bConvert)
{
  DisableRendering();
  // get mesh list filename
  CTFileName fnMeshList = mshi.mi_pMesh->GetName();
  fnMeshList = fnMeshList.NoExt() + ".aml";
  try {
    fnMeshList.RemoveApplicationPath_t();
  } catch(char *){}
  CTString strBackUp;
  try {
    // back up current mesh list file
    strBackUp.Load_t(fnMeshList);
  } catch(char*){}
  // save mesh instance in new mesh list file
  CTFileStream ostrFile;
  try {
    ostrFile.Create_t(fnMeshList,CTStream::CM_TEXT);
    SaveMeshInstance_t(mshi,ostrFile);
    ostrFile.Close();
  } catch(char *strError) {
    ErrorMessage(strError);
    EnableRendering();
    return FALSE;
  }

  // if new mesh list file needs to be converted
  if(bConvert) {
    if(!ConvertMesh(fnMeshList)) {
      // convert failed
      if(strBackUp.Length()>0) {
        // try returning old mesh list file
        try {
          strBackUp.Save_t(fnMeshList);
        } catch(char*){}
      }
    }
  }
  EnableRendering();
  return TRUE;
}
示例#18
0
// load a filelist
static BOOL LoadFileList(CDynamicStackArray<CTFileName> &afnm, const CTFileName &fnmList)
{
  afnm.PopAll();
  try {
    CTFileStream strm;
    strm.Open_t(fnmList);
    while(!strm.AtEOF()) {
      CTString strLine;
      strm.GetLine_t(strLine);
      strLine.TrimSpacesLeft();
      strLine.TrimSpacesRight();
      if (strLine!="") {
        afnm.Push() = strLine;
      }
    }
    return TRUE;
  } catch(char *strError) {
    CPrintF("%s\n", strError);
    return FALSE;
  }
}
示例#19
0
void ReadPos(CCameraPos &cp)
{
  try {
    CTString strLine;
    _strScript.GetLine_t(strLine);
    strLine.ScanF("%g: %g: %g %g %g:%g %g %g:%g", 
      &cp.cp_tmTick,
      &cp.cp_fSpeed,
      &cp.cp_vPos(1), &cp.cp_vPos(2), &cp.cp_vPos(3),
      &cp.cp_aRot(1), &cp.cp_aRot(2), &cp.cp_aRot(3),
      &cp.cp_aFOV);

  } catch (char *strError) {
    CPrintF("Camera: %s\n", strError);
  }
}
示例#20
0
void WritePos(CCameraPos &cp)
{
  try {
    CTString strLine;
    strLine.PrintF("%g: %g: %g %g %g:%g %g %g:%g", 
      _pTimer->GetLerpedCurrentTick()-_fStartTime,
      1.0f,
      cp.cp_vPos(1), cp.cp_vPos(2), cp.cp_vPos(3),
      cp.cp_aRot(1), cp.cp_aRot(2), cp.cp_aRot(3),
      cp.cp_aFOV);
    _strScript.PutLine_t(strLine);

  } catch (char *strError) {
    CPrintF("Camera: %s\n", strError);
  }
}
示例#21
0
// sets image info structure members with info form file of any supported graphic format
//  (CT RAW, PCX8, PCX24, TGA32 uncompressed), but does not load picture content nor palette
INDEX CImageInfo::GetGfxFileInfo_t( const CTFileName &strFileName) // throw char *
{
  CTFileStream GfxFile;
  TGAHeader TGAhdr;
  PCXHeader PCXhdr;

  // lets assume it's a TGA file
  GfxFile.Open_t( strFileName, CTStream::OM_READ);
  GfxFile.Read_t( &TGAhdr, sizeof( struct TGAHeader));
  GfxFile.Close();

  // check for supported targa format
  if( (TGAhdr.ImageType==2 || TGAhdr.ImageType==10) && TGAhdr.BitsPerPixel>=24) {
    // targa it is, so clear image info and set new values
    Clear();
    ii_Width  = TGAhdr.Width;
    ii_Height = TGAhdr.Height;
    ii_BitsPerPixel = TGAhdr.BitsPerPixel;
    // we done here, no need to check further
    return TGA_FILE;
  }

  // we miss Targa, so lets check for supported PCX format
  GfxFile.Open_t( strFileName, CTStream::OM_READ);
  GfxFile.Read_t( &PCXhdr, sizeof( struct PCXHeader));
  GfxFile.Close();

  // check for supported PCX format
  if( (PCXhdr.MagicID == 10) && (PCXhdr.PixelBits == 8)) {
    // PCX it is, so clear image info and set new values
    Clear();
    ii_Width = PCXhdr.Xmax - PCXhdr.Xmin + 1;
    ii_Height = PCXhdr.Ymax - PCXhdr.Ymin + 1;
    ii_BitsPerPixel = PCXhdr.PixelBits * PCXhdr.Planes;
    // we done here, no need to check further
    return PCX_FILE;
  }

  // we didn't found a supported gfx format, sorry ...
  return UNSUPPORTED_FILE;
}
示例#22
0
// get level info for given filename
BOOL GetLevelInfo(CLevelInfo &li, const CTFileName &fnm)
{
  // try to
  try {
    // open the world file
    CTFileStream strm;
    strm.Open_t(fnm);
    // skip initial chunk ids
    strm.ExpectID_t("BUIV"); // 'build version'
    INDEX iDummy;
    strm>>iDummy; // the version number
    strm.ExpectID_t("WRLD"); // 'world'
    strm.ExpectID_t("WLIF"); // 'world info'
    if (strm.PeekID_t()==CChunkID("DTRS")) {
      strm.ExpectID_t("DTRS"); // 'world info'
    }
    // read the name
    strm>>li.li_strName;
    // read the flags
    strm>>li.li_ulSpawnFlags;

    // translate name
    li.li_strName = TranslateConst(li.li_strName, 0);

    // if dummy name
    if (li.li_strName=="") {
      // use filename
      li.li_strName = fnm.FileName();
    }

    // remember filename
    li.li_fnLevel = fnm;

    // succeed
    return TRUE;

  // if failed
  } catch (char *strError) {
    (void) strError;
    //CPrintF("Invalid world file '%s': %s\n", (const char*) fnm, strError);
    // set dummy info
    li = CLevelInfo();
    // fail
    return FALSE;
  }
}
示例#23
0
/* PCX ***********************************************************************
 * This routine reads file with given file name and if it is valid PCX file it
 * loads it into given ImageInfo structure in CroTeam true-color format.
 * (and, if the one exists, loads the palette)
 */
void CImageInfo::LoadPCX_t( const CTFileName &strFileName) // throw char *
{
  PCXHeader *pPCXHdr;
  UBYTE *pPCXBuffer, *pPCXImage, *pPCXDecodedImage, *pTmp;
  UBYTE data, counter;
  SLONG pic_size, PCX_size, slFileSize;
  CTFileStream PCXFile;

  Clear();

  // inconvinent way to determine file size
  PCXFile.Open_t( strFileName, CTStream::OM_READ);
  slFileSize = PCXFile.GetStreamSize();

  // load entire PCX file to memory, as is, and close it (no further usage)
  pPCXBuffer = (UBYTE*)AllocMemory( slFileSize);
  PCXFile.Read_t( pPCXBuffer, slFileSize);
  PCXFile.Close();

  // PCX header starts at the begining of the PCX file
  pPCXHdr = (struct PCXHeader*)pPCXBuffer;
  // PCX image bytes definition follows up
  pPCXImage = pPCXBuffer + sizeof( struct PCXHeader);

  // detremine picture size dimensions
  ii_Width  = (SLONG)(pPCXHdr->Xmax - pPCXHdr->Xmin +1);
  ii_Height = (SLONG)(pPCXHdr->Ymax - pPCXHdr->Ymin +1);
  ii_BitsPerPixel = (SLONG)pPCXHdr->Planes*8;
  pic_size = ii_Width * ii_Height * ii_BitsPerPixel/8;

  // allocate memory for image content
  ii_Picture = (UBYTE*)AllocMemory( pic_size);

  // allocate memory for decoded PCX file that hasn't been converted to CT RAW Image format
  PCX_size = (SLONG)(pPCXHdr->BytesPerLine * ii_Height * ii_BitsPerPixel/8);
  pPCXDecodedImage = (UBYTE*)AllocMemory( PCX_size);
  pTmp = pPCXDecodedImage;  // save pointer for latter usage

  // decode PCX file
  for( INDEX i=0; i<PCX_size; )   // i is incremented by counter value  at the and of the loop
  {
    // read one byte from PCX image in memory
    data = *pPCXImage++;
    // check byte-run mark
    if( (data & 0xC0) == 0xC0) {
      counter = data & 0x3F;              // determine repeat value
      data = *pPCXImage++;                // read repeated data
      // put several bytes of PCX image to decoded image area in memory
      for( INDEX j=0; j<counter; j++)
        *pPCXDecodedImage++ = data;
    } else {
      // put just one byte from PCX image to decoded image area in memory
      counter = 1;
      *pPCXDecodedImage++ = data;
    }

    // increment encoded image counter
    i += counter;
  }
  pPCXDecodedImage = pTmp;  // reset pointer

  // convert decoded PCX image to CroTeam RAW Image Info format
  SLONG slBytesPerPixel = ii_BitsPerPixel/8;
  for( INDEX y=0; y<ii_Height; y++)
  {
    SLONG slYSrcOfs = y * ii_Width * slBytesPerPixel;
    SLONG slYDstOfs = y * pPCXHdr->BytesPerLine * slBytesPerPixel;
    // channel looper
    for( INDEX p=0; p<slBytesPerPixel; p++)
    {
      SLONG slPOffset = p * pPCXHdr->BytesPerLine;
      // byte looper
      for( INDEX x=0; x<ii_Width; x++)
        *(ii_Picture + slYSrcOfs + x*slBytesPerPixel + p) =
        *(pPCXDecodedImage + slYDstOfs + slPOffset + x);
    }
  }

  // free temorary allocated memory for PCX encoded and decoded image
  FreeMemory( pPCXBuffer);
  FreeMemory( pPCXDecodedImage);
}
示例#24
0
void CImageInfo::LoadTGA_t( const CTFileName &strFileName) // throw char *
{
  TGAHeader *pTGAHdr;
  UBYTE *pTGABuffer, *pTGAImage;
  SLONG slFileSize;
  CTFileStream TGAFile;

  Clear();

  // determine file size
  TGAFile.Open_t( strFileName, CTStream::OM_READ);
  slFileSize = TGAFile.GetStreamSize();

  // load entire TGA file to memory, as is, and close it (no further usage)
  pTGABuffer = (UBYTE*)AllocMemory( slFileSize);
  TGAFile.Read_t( pTGABuffer, slFileSize);
  TGAFile.Close();

  // TGA header starts at the begining of the TGA file
  pTGAHdr = (struct TGAHeader*)pTGABuffer;
  // TGA image bytes definition follows up
  pTGAImage = pTGABuffer + sizeof(struct TGAHeader) + pTGAHdr->IdLenght;

  // detremine picture size dimensions
  ii_Width        = (SLONG)pTGAHdr->Width;
  ii_Height       = (SLONG)pTGAHdr->Height;
  ii_BitsPerPixel = (SLONG)pTGAHdr->BitsPerPixel;
  SLONG slBytesPerPixel = ii_BitsPerPixel/8;
  PIX pixBitmapSize     = ii_Width*ii_Height;
  BOOL bAlphaChannel    = (slBytesPerPixel==4);

  // check for supported file types
  ASSERT( slBytesPerPixel==3 || slBytesPerPixel==4);
  if( slBytesPerPixel!=3 && slBytesPerPixel!=4) throw( TRANS("Unsupported BitsPerPixel in TGA format."));

  // allocate memory for image content
  ii_Picture = (UBYTE*)AllocMemory( ii_Width*ii_Height *slBytesPerPixel);
  UBYTE *pubSrc = pTGAImage;  // need 'walking' pointers
  UBYTE *pubDst = ii_Picture;

  // determine TGA image type
  if( pTGAHdr->ImageType==10) {
    // RLE encoded
    UBYTE ubControl;
    INDEX iBlockSize;
    BOOL  bRepeat;
    PIX pixCurrentSize=0;
    // loop thru blocks
    while( pixCurrentSize<pixBitmapSize)
    { // readout control byte
      ubControl  = *pubSrc++;
      bRepeat    =  ubControl&0x80;
      iBlockSize = (ubControl&0x7F) +1;
      // repeat or copy color values
      for( INDEX i=0; i<iBlockSize; i++) {
        *pubDst++ = pubSrc[0]; 
        *pubDst++ = pubSrc[1]; 
        *pubDst++ = pubSrc[2]; 
        if( bAlphaChannel) *pubDst++ = pubSrc[3];
        if( !bRepeat) pubSrc += slBytesPerPixel;
      }
      // advance for next block if repeated
      if( bRepeat) pubSrc += slBytesPerPixel;
      // update image size
      pixCurrentSize += iBlockSize;
    }
    // mark that image was encoded to ImageInfo buffer
    pTGAImage = ii_Picture; 
  } 
  // not true-colored?
  else if( pTGAHdr->ImageType!=2) {
    // whoops!
    ASSERTALWAYS("Unsupported TGA format.");
    throw( TRANS("Unsupported TGA format."));
  }

  // determine image flipping
  INDEX iFlipType;
  switch( (pTGAHdr->Descriptor&0x30)>>4) {
  case 0:  iFlipType = 1;  break; // vertical flipping
  case 1:  iFlipType = 3;  break; // diagonal flipping
  case 3:  iFlipType = 2;  break; // horizontal flipping
  default: iFlipType = 0;  break; // no flipping (just copying)
  }
  // do flipping
  FlipBitmap( pTGAImage, ii_Picture, ii_Width, ii_Height, iFlipType, bAlphaChannel);

  // convert TGA pixel format to CroTeam
  pubSrc = ii_Picture;  // need 'walking' pointer again
  for( INDEX iPix=0; iPix<pixBitmapSize; iPix++)
  { // flip bytes
    Swap( pubSrc[0], pubSrc[2]);  // R & B channels
    pubSrc += slBytesPerPixel; 
  }

  // free temorary allocated memory for TGA image format
  FreeMemory( pTGABuffer);
}
示例#25
0
static void LoadSettings(const CTFileName &fnConfig)
{
  if(!_bInitialized) return;
  if(!FileExists(fnConfig)) return;

  try {
    CTFileStream istr;
    istr.Open_t(fnConfig,CTFileStream::OM_READ);

    INDEX iVersion;
    ULONG ulFlags;
    INDEX iFontSize;
    INDEX iFirstChar;
    INDEX iLastChar;
    INDEX iAlignH;
    INDEX iAlignV;
    INDEX iPaddingX;
    INDEX iPaddingY;
    INDEX iWidthAdd;
    INDEX iHeightAdd;
    INDEX ctShadows;
    INDEX iTexWidth;
    INDEX iTexHeight;
    CTString strFontName;
    CTString strSampleText;

    istr>>iVersion;
    if(iVersion!=CONFIG_VERSION) {
      WarningMessage("Invalid config version.\nExpected Ver \"%d\" but found \"%d\"\n", CONFIG_VERSION, iVersion);
      return;
    }

    istr>>ulFlags;
    istr>>iFontSize;
    istr>>iFirstChar;
    istr>>iLastChar;
    istr>>iAlignH;
    istr>>iAlignV;
    istr>>iPaddingX;
    istr>>iPaddingY;
    istr>>iWidthAdd;
    istr>>iHeightAdd;
    istr>>ctShadows;
    istr>>iTexWidth;
    istr>>iTexHeight;
    istr>>strFontName;
    istr>>strSampleText;
    istr>>_bShowTexture;
    istr>>_bShowGrid;
    istr>>_fnCharacterTable;

    UpdatePreviewButton();
    SetFontFlags(ulFlags);
    SetControlInt(IEC_FONT_SIZE,iFontSize);
    SetControlInt(IEC_FIRST_CHAR,iFirstChar);
    SetControlInt(IEC_LAST_CHAR,iLastChar);
    SetComboIndex(IDC_ALIGN_H,iAlignH);
    SetComboIndex(IDC_ALIGN_V,iAlignV);
    SetControlInt(IEC_PADDINGX,iPaddingX);
    SetControlInt(IEC_PADDINGY,iPaddingY);
    SetControlInt(IEC_WIDTH_ADD,iWidthAdd);
    SetControlInt(IEC_HEIGHT_ADD,iHeightAdd);
    SetControlInt(IEC_SHADOW_PASSES,ctShadows);

    SetComboInt(ICB_TEX_WIDTH,iTexWidth);
    SetComboInt(ICB_TEX_HEIGHT,iTexHeight);
    SetComboString(ICB_FONT_NAMES,strFontName);
    SetStringToControl(IEC_SAMPLE_TEXT,strSampleText);

    LoadCharTable(_fnCharacterTable);
    GenerateFont();
  } catch(char *strErr) {
    WarningMessage("%s", strErr);
  }
}