This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 

  Batch DDS Converter Tool
  Submitted by



Not much, but here's something you can throw onto the pile as a code of the day sample. Little windows app that lets you batch convert a bunch of .BMP and .TGA files into .DDS format.

John


Currently browsing [ddstool.zip] (145,216 bytes) - [ddstool/source/dds.h] - (317 bytes)


#if !defined(AFX_DDS_H__4AA235F8_B878_473F_B991_0986ADE8BA6F__INCLUDED_)
#define AFX_DDS_H__4AA235F8_B878_473F_B991_0986ADE8BA6F__INCLUDED_

#if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "resource.h"

#endif // !defined(AFX_DDS_H__4AA235F8_B878_473F_B991_0986ADE8BA6F__INCLUDED_)

Currently browsing [ddstool.zip] (145,216 bytes) - [ddstool/source/dds.cpp] - (3,238 bytes)

#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <commdlg.h>
#include <stdio.h>
#include <process.h>
#include <direct.h>
#include <string.h>

static char gWorkDirectory[1024];

int CreateDDS(const char *fname,bool alpha) { const char *arg[6];

char scratch[2048]; sprintf(scratch,"%s\\s3tc.exe",gWorkDirectory);

arg[0] = scratch; arg[1] = "/M";

if ( alpha ) arg[2] = "/5"; else arg[2] = "/1";

arg[3] = fname; arg[4] = 0;

int ret = _spawnv(_P_WAIT,scratch,arg);

Sleep(100);

return ret;

}



// Function name :OPT_SelectFile // Description : // // Return type : BOOL // Argument : HWND hWndParent - handle to the owner window - can be NULL // Argument : char* pszDestBuffer - Destination buffer to store the selected file & path. Assumed to be 256 chars // Argument : const char* pszInitialDir - initial directory to display. Can be empty string // Argument : const char* pszTitle - title for the dialog, e.g "Select source file to use" BOOL OPT_SelectFile(HWND hWndParent, char* pszDestBuffer, const char* pszInitialDir, const char* pszTitle) { OPENFILENAME ofn;



char szFilter[1024] = "Image Files (*.bmp,*.tga)\0*.bmp;*.tga\0\0";

// seems that dest buffer must be null terminated for GetOpenFileName..... *pszDestBuffer = '\0';

memset(&ofn, 0, sizeof(ofn));

ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hWndParent; ofn.lpstrFilter = szFilter;

ofn.lpstrInitialDir = pszInitialDir; ofn.hInstance = NULL; ofn.lpstrTitle = pszTitle; ofn.lpstrFileTitle = NULL; ofn.lpstrFile = pszDestBuffer; ofn.nMaxFile = 32768; ofn.lpstrDefExt = ""; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT;

BOOL bRet = GetOpenFileName(&ofn);

if (0 == bRet) { DWORD dwError = CommDlgExtendedError(); //_ASSERTE(SUCCEEDED(dwError)); }

return bRet; }

const char * GetNextString(const char *next) { if ( *next == 0 ) return 0; while ( *next ) next++; next++; if ( *next == 0 ) return 0; return next; }

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hInstPrev, TCHAR* pszCmdLine, int nShowCmd ) {

_getcwd(gWorkDirectory,1024);

char scratch[2048]; sprintf(scratch,"%s\\s3tc.exe",gWorkDirectory);

char szDestBuffer[32768]; memset(szDestBuffer,32768,0);

OPT_SelectFile(NULL, szDestBuffer, "c:\\", "Select Files To Convert To .DDS File Format");

const char *next = GetNextString(szDestBuffer);

FILE *fph = fopen("dds.log", "wb");

while ( next ) { int len = strlen(next); if ( len > 4 ) { bool alpha = false; if ( stricmp( &next[len-4],".tga") == 0 ) alpha = true; int ret = CreateDDS(next,alpha); fprintf(fph,"CreateDDS: %s RetCode: %d Alpha: %d\n",next,ret,alpha);

} next = GetNextString(next); }

fclose(fph);

return 0; }

The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.