WindowsTest.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  1. //--------------------------------------------------------------------------------
  2. //
  3. // ImageLib Windows (GDI) Test Source
  4. // Copyright (C) 2000-2008 by Denton Woods
  5. // Last modified: 02/14/2009
  6. //
  7. // Filename: testil/windowstest/windowstest.c
  8. //
  9. // Description: Full GDI test application for DevIL.
  10. //
  11. // Note: This requires FluidStudio's Colour Picker library to compile
  12. // properly (available at http://www.fluidstudios.com/publications.html).
  13. //
  14. //--------------------------------------------------------------------------------
  15. #ifdef _DEBUG
  16. #define IL_DEBUG
  17. #endif//_DEBUG
  18. #define _UNICODE
  19. // Memory leak detection
  20. #ifdef _DEBUG
  21. #define _CRTDBG_MAP_ALLOC
  22. #include <stdlib.h>
  23. #include <crtdbg.h>
  24. #endif
  25. //#define ILUT_USE_WIN32
  26. #include <windows.h>
  27. #include <IL/il.h>
  28. #include <IL/ilu.h>
  29. #include <IL/ilut.h>
  30. #ifdef ILUT_USE_SDL
  31. #include <sdl.h>
  32. #endif
  33. #include "resource.h"
  34. #include <stdlib.h>
  35. #include <wchar.h>
  36. //#pragma comment(lib, "sdl.lib")
  37. //#pragma comment(lib, "sdlmain.lib")
  38. //#pragma comment(lib, "colorpicker.lib")
  39. // Evil globals!
  40. HINSTANCE hInstance;
  41. HBITMAP hBitmap;
  42. BITMAPINFOHEADER BmpInfo;
  43. HDC hDC = 0, hMemDC = 0;
  44. HWND HWnd;
  45. HBRUSH BackBrush;
  46. #define BORDER_W 16 //8
  47. #define MENU_H 58 //54
  48. #define MIN_W 450 // Accomodate the menu bar.
  49. //#define MAX_W 400
  50. //#define MAX_H 400
  51. #define TITLE L"DevIL Windows Test"
  52. ILuint NumUndosAllowed = 4, UndoSize = 0;
  53. ILuint Undos[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  54. ILuint Width, Height, Depth, Size; // Main image
  55. ILint CurImage;
  56. TCHAR CurFileName[2048];
  57. ILint XOff, YOff;
  58. ILdouble last_elapsed, cur_elapsed, elapsed;
  59. ILuint FilterType;
  60. ILuint FilterParamInt;
  61. ILfloat FilterParamFloat;
  62. TCHAR FilterEditString[255];
  63. TCHAR OpenFileName[2048];
  64. TCHAR SaveFileName[2048];
  65. TCHAR NewTitle[512];
  66. TCHAR *ExtList[] = {
  67. L"pix", L"cut", L"dcx", L"gif", L"mdl", L"lif", L"jpe", L"jpg", L"jpeg", L"lif", L"bmp",
  68. L"ico", L"pbm", L"pgm", L"ppm", L"png", L"bw", L"rgb", L"rgba", L"sgi", L"tga", L"tif",
  69. L"tiff", L"xpm", L"psp", L"psd", L"iwi", L"exr", L"blp", L"tpl", L"wdp", L"pcx", L"dcm",
  70. L"rot", L"iwi", L"ftx", L"dds", L"dpx", L"vtf",
  71. NULL
  72. };
  73. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  74. INT_PTR APIENTRY AboutDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  75. INT_PTR APIENTRY PropertiesDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  76. INT_PTR APIENTRY FilterDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  77. INT_PTR APIENTRY ResizeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  78. INT_PTR APIENTRY BatchDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  79. void BatchConv(TCHAR *Directory, TCHAR *ExtList, TCHAR *ConvExt, bool Recurse);
  80. void GenFilterString(TCHAR *Out, TCHAR **Strings);
  81. void ResizeWin(void);
  82. void CreateGDI(void);
  83. bool IsOpenable(TCHAR *FileName);
  84. bool GetPrevImage(void);
  85. bool GetNextImage(void);
  86. TCHAR *GetExtension(const TCHAR *FileName);
  87. bool CheckExtension(TCHAR *Arg, TCHAR *Ext);
  88. //extern "C"
  89. //// Colour picker export
  90. //__declspec( dllimport ) bool WINAPI FSColorPickerDoModal(unsigned int * currentColor, const bool currentColorIsDefault, unsigned int * originalColor, const bool originalColorIsDefault, const int initialExpansionState);
  91. ILAPI ILubyte* ILAPIENTRY ilNVidiaCompressDXT(ILubyte *Data, ILuint Width, ILuint Height, ILenum DxtType);
  92. int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  93. {
  94. MSG msg;
  95. WNDCLASSEX wcex;
  96. HACCEL hAccelTable;
  97. hInstance = hInst;
  98. memset(OpenFileName, 0, 2048 * sizeof(TCHAR));
  99. BackBrush = CreateSolidBrush(RGB(128,128,128));
  100. wcex.cbSize = sizeof(WNDCLASSEX);
  101. wcex.style = CS_HREDRAW | CS_VREDRAW;
  102. wcex.lpfnWndProc = (WNDPROC)WndProc;
  103. wcex.cbClsExtra = 0;
  104. wcex.cbWndExtra = 0;
  105. wcex.hInstance = hInstance;
  106. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
  107. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  108. wcex.hbrBackground = BackBrush;
  109. wcex.lpszMenuName = (LPCWSTR)IDR_MENU1; //@TODO: (LPCSTR)IDR_MENU1;
  110. wcex.lpszClassName = TITLE;
  111. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);
  112. RegisterClassEx(&wcex);
  113. HWnd = CreateWindow(TITLE, TITLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  114. 50, 50, 400, 300, NULL, NULL, hInstance, NULL);
  115. if (HWnd == NULL)
  116. return FALSE;
  117. //if (SDL_Init(SDL_INIT_TIMER) < 0)
  118. // return FALSE;
  119. //atexit(SDL_Quit);
  120. // Display the window
  121. ShowWindow(HWnd, nCmdShow);
  122. UpdateWindow(HWnd);
  123. // Initialize DevIL
  124. ilInit();
  125. iluInit();
  126. ilutRenderer(ILUT_WIN32);
  127. // Is there a file to load from the command-line?
  128. if (__argc > 1) {
  129. ilGenImages(1, Undos);
  130. ilBindImage(Undos[0]);
  131. /*if (ilLoadImage(__argv[1])) {
  132. CurImage = 0;
  133. //ilConvertImage(IL_BGRA);
  134. ilutRenderer(ILUT_WIN32);
  135. ResizeWin();
  136. CreateGDI();
  137. sprintf(NewTitle, "%s - %s", TITLE, __argv[1]);
  138. SetWindowText(HWnd, NewTitle);
  139. }*/
  140. }
  141. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDR_MENU1);
  142. while (GetMessage(&msg, NULL, 0, 0)) {
  143. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
  144. TranslateMessage(&msg);
  145. DispatchMessage(&msg);
  146. }
  147. }
  148. #ifdef _DEBUG
  149. _CrtDumpMemoryLeaks();
  150. #endif
  151. return (int)msg.wParam;
  152. }
  153. void CreateGDI()
  154. {
  155. ILuint CopyName, CurName, CurImg, CurMip;
  156. hDC = GetDC(HWnd);
  157. hMemDC = CreateCompatibleDC(hDC);
  158. CurName = ilGetInteger(IL_CUR_IMAGE);
  159. CurImg = ilGetInteger(IL_ACTIVE_IMAGE);
  160. CurMip = ilGetInteger(IL_ACTIVE_MIPMAP);
  161. CopyName = ilCloneCurImage();
  162. ilBindImage(CopyName);
  163. //ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
  164. hBitmap = ilutConvertToHBitmap(hDC);
  165. ilutGetBmpInfo((BITMAPINFO*)&BmpInfo);
  166. DeleteObject(SelectObject(hMemDC, hBitmap));
  167. ilBindImage(CurName);
  168. if (CurImg)
  169. ilActiveImage(CurImg);//ilBindImage(Undos[0]);
  170. if (CurMip)
  171. ilActiveMipmap(CurMip);
  172. ilDeleteImages(1, &CopyName);
  173. return;
  174. }
  175. void DestroyGDI()
  176. {
  177. if (hMemDC) {
  178. DeleteObject(hBitmap);
  179. DeleteDC(hMemDC);
  180. }
  181. if (hDC) {
  182. ReleaseDC(HWnd, hDC);
  183. }
  184. hBitmap = NULL;
  185. hMemDC = NULL;
  186. hDC = NULL;
  187. return;
  188. }
  189. void ResizeWin()
  190. {
  191. static RECT Rect1, Rect2;
  192. static ILint NewW, NewH;
  193. SystemParametersInfo(SPI_GETWORKAREA, 0, &Rect1, 0);
  194. GetWindowRect(HWnd, &Rect2);
  195. Width = ilGetInteger(IL_IMAGE_WIDTH);
  196. Height = ilGetInteger(IL_IMAGE_HEIGHT);
  197. Depth = ilGetInteger(IL_IMAGE_DEPTH);
  198. NewW = Width < MIN_W ? MIN_W : Width + BORDER_W;
  199. if (NewW + Rect2.left > Rect1.right)
  200. NewW = Rect1.right - Rect2.left;
  201. NewH = Height + MENU_H;
  202. if (NewH + Rect2.top > Rect1.bottom)
  203. NewH = Rect1.bottom - Rect2.top;
  204. SetWindowPos(HWnd, HWND_TOP, Rect2.left, Rect2.top, NewW, NewH, SWP_SHOWWINDOW);
  205. InvalidateRect(HWnd, NULL, FALSE);
  206. return;
  207. }
  208. // Window procedure, handles all messages for this program
  209. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  210. {
  211. static HMENU hMenu;
  212. static ILuint Colours;
  213. static RECT Rect;
  214. static PAINTSTRUCT ps;
  215. static HDROP hDrop;
  216. static TCHAR OpenFilter[2048];
  217. static TCHAR SaveFilter[2048];
  218. static TCHAR *OFilter[] = {
  219. L"All Files (*.*)", L"*.*",
  220. L"Alias|Wavefront Files (*.pix)", L"*.pix",
  221. L"Cut Files (*.cut)", L"*.cut",
  222. L"Dcx Files (*.dcx)", L"*.dcx",
  223. L"Graphics Interchange Format (*.gif)", L"*.gif",
  224. L"Half-Life Model Files (*.mdl)", L"*.mdl",
  225. L"Homeworld Image Files (*.lif)", L"*.lif",
  226. L"Image Files (All Supported Types)", L"*.jpe;*.jpg;*.jpeg;*.lif;*.bmp;*.ico;*.pbm;*.pgm;*.pnm;*.ppm;*.png;*.bw;*.rgb;*.rgba;*.sgi;*.tga;*.tif;*.tiff;*.pcx;*.xpm;*.psp;*.psd;*.pix;*.pxr;*.cut;*.dcx",
  227. L"Jpeg Files (*.jpe, *.jpg, *.jpeg)", L"*.jpe;*.jpg;*.jpeg",
  228. L"Kodak Photo CD Files (*.pcd)", L"*.pcd",
  229. L"Microsoft Bitmap Files (*.bmp)", L"*.bmp",
  230. L"Microsoft DirectDraw Surface (*.dds)", L"*.dds",
  231. L"Microsoft Icon Files (*.ico, *.cur)", L"*.ico, *.cur",
  232. L"Multiple Network Graphics Files (*.mng)", L"*.mng",
  233. L"Paint Shop Pro Files (*.psp)", L"*.psp",
  234. L"PhotoShop Files (*.psd)", L"*.psd",
  235. L"Pic Files (*.pic)", L"*.pic",
  236. L"Pixar Files (*.pix)", L"*.pix",
  237. L"Portable AnyMap Files (*.pbm, *.pgm, *.pnm, *.ppm)", L"*.pbm;*.pgm;*.pnm;*.ppm",
  238. L"Portable Network Graphics Files (*.png)", L"*.png",
  239. L"Sgi Files (*.sgi)", L"*.bw;*.rgb;*.rgba;*.sgi",
  240. L"Targa Files (*.tga, *.vda, *.icb, *.vst)", L"*.tga;*.vda;*.icb;*.vst",
  241. L"Tiff Files (*.tif)", L"*.tif;*.tiff",
  242. L"Valve Texture Files (*.vtf)", L"*.vtf",
  243. L"Quake Wal Files (*.wal)", L"*.wal",
  244. L"X PixelMap (*.xpm)", L"*.xpm",
  245. L"ZSoft Pcx Files (*.pcx)", L"*.pcx",
  246. L"\0\0"
  247. };
  248. static TCHAR *SFilter[] = {
  249. L"All Files (*.*)", L"*.*",
  250. L"C-Style Header (*.h)", L"*.h",
  251. L"Jpeg Files (*.jpe, *.jpg, *.jpeg)", L"*.jpe;*.jpg;*.jpeg",
  252. L"Microsoft Bitmap Files (*.bmp)", L"*.bmp",
  253. L"Microsoft DirectDraw Surface (*.dds)", L"*.dds",
  254. L"PhotoShop Files (*.psd)", L"*.psd",
  255. L"Portable AnyMap Files (*.pbm, *.pgm, *.ppm)", L"*.pbm;*.pgm;*.ppm",
  256. L"Portable Network Graphics Files (*.png)", L"*.png",
  257. L"Sgi Files (*.sgi)", L"*.bw;*.rgb;*.rgba;*.sgi",
  258. L"Targa Files (*.tga)", L"*.tga",
  259. L"Tiff Files (*.tif)", L"*.tif",
  260. L"ZSoft Pcx Files (*.pcx)", L"*.pcx",
  261. L"\0\0"
  262. };
  263. static OPENFILENAME Ofn = {
  264. sizeof(OPENFILENAME),
  265. hWnd,
  266. NULL,
  267. OpenFilter,
  268. NULL,
  269. 0,
  270. 0,
  271. OpenFileName,
  272. 2048,
  273. NULL,
  274. 0,
  275. NULL,
  276. NULL,
  277. OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
  278. 0,
  279. 0,
  280. NULL,
  281. NULL,
  282. NULL,
  283. NULL
  284. };
  285. POINT CurMouse;
  286. static POINT PrevMouse;
  287. static ILboolean MouseDown = IL_FALSE;
  288. static RECT WinSize;
  289. unsigned int currentColor = 0x80000000;
  290. unsigned int originalColor = 0x80000000;
  291. bool userClickedOK;
  292. ILclampf Red = 255, Green = 255, Blue = 255;
  293. ILubyte *AlphaChannel;
  294. ILenum Origin;
  295. switch (message)
  296. {
  297. case WM_CREATE:
  298. GenFilterString(OpenFilter, OFilter);
  299. GenFilterString(SaveFilter, SFilter);
  300. hDC = GetDC(hWnd);
  301. DragAcceptFiles(hWnd, TRUE);
  302. ReleaseDC(hWnd, hDC);
  303. break;
  304. case WM_CLOSE:
  305. #ifdef _DEBUG
  306. _CrtDumpMemoryLeaks();
  307. #endif
  308. DestroyGDI();
  309. DestroyWindow(hWnd);
  310. UnregisterClass(TITLE, hInstance);
  311. break;
  312. case WM_DESTROY:
  313. PostQuitMessage(0);
  314. break;
  315. case WM_PAINT:
  316. GetWindowRect(HWnd, &WinSize); // Shouldn't be here!
  317. hDC = BeginPaint(hWnd, &ps);
  318. //StretchBlt(hDC, 0, 0, WinSize.right - WinSize.left,
  319. // WinSize.bottom - WinSize.top, BackHDC, 0, 0, 1, 1, SRCCOPY);
  320. WinSize.right -= WinSize.left;
  321. WinSize.bottom -= WinSize.top;
  322. WinSize.top = 0;
  323. WinSize.left = 0;
  324. FillRect(hDC, &WinSize, BackBrush);
  325. BitBlt(hDC, XOff, YOff, (WORD)BmpInfo.biWidth, (WORD)BmpInfo.biHeight,
  326. hMemDC, 0, 0, SRCCOPY);
  327. EndPaint(hWnd, &ps);
  328. ValidateRect(hWnd, NULL);
  329. break;
  330. case WM_KEYDOWN:
  331. if (wParam == VK_ESCAPE)
  332. PostQuitMessage(0);
  333. // View the next image in the animation chain.
  334. if (wParam == VK_RIGHT) {
  335. ilBindImage(Undos[0]); // @TODO: Implement undos better with this.
  336. CurImage++;
  337. if (CurImage > ilGetInteger(IL_NUM_IMAGES))
  338. CurImage = 0; // Go back to the beginning of the animation.
  339. ilActiveImage(CurImage);
  340. ilutRenderer(ILUT_WIN32);
  341. ResizeWin();
  342. CreateGDI();
  343. }
  344. if (wParam == '0') {
  345. ilBindImage(Undos[0]); // @TODO: Implement undos better with this.
  346. ilutRenderer(ILUT_WIN32);
  347. ResizeWin();
  348. CreateGDI();
  349. }
  350. if (wParam == '1') {
  351. ilActiveMipmap(1);
  352. ilutRenderer(ILUT_WIN32);
  353. ResizeWin();
  354. CreateGDI();
  355. }
  356. else if (wParam == '2') {
  357. ilActiveMipmap(2);
  358. ilutRenderer(ILUT_WIN32);
  359. ResizeWin();
  360. CreateGDI();
  361. }
  362. else if (wParam == '3') {
  363. ilActiveMipmap(3);
  364. ilutRenderer(ILUT_WIN32);
  365. ResizeWin();
  366. CreateGDI();
  367. }
  368. else if (wParam == '4') {
  369. ilActiveMipmap(4);
  370. ilutRenderer(ILUT_WIN32);
  371. ResizeWin();
  372. CreateGDI();
  373. }
  374. else if (wParam == '5') {
  375. ilActiveMipmap(5);
  376. ilutRenderer(ILUT_WIN32);
  377. ResizeWin();
  378. CreateGDI();
  379. }
  380. else if (wParam == '6') {
  381. ilActiveMipmap(6);
  382. ilutRenderer(ILUT_WIN32);
  383. ResizeWin();
  384. CreateGDI();
  385. }
  386. else if (wParam == '7') {
  387. ilActiveMipmap(7);
  388. ilutRenderer(ILUT_WIN32);
  389. ResizeWin();
  390. CreateGDI();
  391. }
  392. else if (wParam == '8') {
  393. ilActiveMipmap(8);
  394. ilutRenderer(ILUT_WIN32);
  395. ResizeWin();
  396. CreateGDI();
  397. }
  398. else if (wParam == '9') {
  399. ilActiveMipmap(9);
  400. ilutRenderer(ILUT_WIN32);
  401. ResizeWin();
  402. CreateGDI();
  403. }
  404. // View the previous image in the animation chain.
  405. if (wParam == VK_LEFT) {
  406. ilBindImage(Undos[0]); // @TODO: Implement undos better with this.
  407. CurImage--;
  408. if (CurImage < 0)
  409. CurImage = 0;
  410. ilActiveImage(CurImage);
  411. ilutRenderer(ILUT_WIN32);
  412. ResizeWin();
  413. CreateGDI();
  414. }
  415. if (wParam == VK_PRIOR) {
  416. if (!GetPrevImage())
  417. break;
  418. DestroyGDI();
  419. if (UndoSize == 0)
  420. UndoSize = 1;
  421. ilDeleteImages(UndoSize, Undos);
  422. UndoSize = 0;
  423. XOff = 0;
  424. YOff = 0;
  425. ilGenImages(1, Undos);
  426. ilBindImage(Undos[0]);
  427. //last_elapsed = SDL_GetTicks();
  428. if (!ilLoadImage(OpenFileName)) {
  429. wsprintf(CurFileName, L"%s", OpenFileName);
  430. wsprintf(NewTitle, L"%s - Could not open %s", TITLE, OpenFileName);
  431. SetWindowText(hWnd, NewTitle);
  432. return (0L);
  433. }
  434. CurImage = 0;
  435. //cur_elapsed = SDL_GetTicks();
  436. elapsed = cur_elapsed - last_elapsed;
  437. last_elapsed = cur_elapsed;
  438. ilutRenderer(ILUT_WIN32);
  439. ResizeWin();
  440. CreateGDI();
  441. wsprintf(CurFileName, L"%s", OpenFileName);
  442. wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, OpenFileName, (unsigned int)elapsed);
  443. SetWindowText(hWnd, NewTitle);
  444. }
  445. if (wParam == VK_NEXT) {
  446. if (!GetNextImage())
  447. break;
  448. DestroyGDI();
  449. if (UndoSize == 0)
  450. UndoSize = 1;
  451. ilDeleteImages(UndoSize, Undos);
  452. UndoSize = 0;
  453. XOff = 0;
  454. YOff = 0;
  455. ilGenImages(1, Undos);
  456. ilBindImage(Undos[0]);
  457. //last_elapsed = SDL_GetTicks();
  458. if (!ilLoadImage(OpenFileName)) {
  459. wsprintf(CurFileName, L"%s", OpenFileName);
  460. wsprintf(NewTitle, L"%s - Could not open %s", TITLE, OpenFileName);
  461. SetWindowText(hWnd, NewTitle);
  462. return (0L);
  463. }
  464. CurImage = 0;
  465. //cur_elapsed = SDL_GetTicks();
  466. elapsed = cur_elapsed - last_elapsed;
  467. last_elapsed = cur_elapsed;
  468. ilutRenderer(ILUT_WIN32);
  469. ResizeWin();
  470. CreateGDI();
  471. wsprintf(CurFileName, L"%s", OpenFileName);
  472. wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, OpenFileName, (unsigned int)elapsed);
  473. SetWindowText(hWnd, NewTitle);
  474. }
  475. InvalidateRect(hWnd, NULL, FALSE);
  476. break;
  477. // Moves the "viewport"
  478. case WM_MOUSEMOVE:
  479. if (!MouseDown)
  480. break;
  481. GetCursorPos(&CurMouse);
  482. XOff += CurMouse.x - PrevMouse.x;
  483. YOff += CurMouse.y - PrevMouse.y;
  484. PrevMouse.x = CurMouse.x;
  485. PrevMouse.y = CurMouse.y;
  486. InvalidateRect(hWnd, NULL, FALSE);
  487. break;
  488. case WM_LBUTTONDOWN:
  489. MouseDown = IL_TRUE;
  490. GetCursorPos(&PrevMouse);
  491. break;
  492. case WM_LBUTTONUP:
  493. MouseDown = IL_FALSE;
  494. break;
  495. case WM_DROPFILES:
  496. hDrop = (HDROP)wParam;
  497. DragQueryFile(hDrop, 0, OpenFileName, 512);
  498. DestroyGDI();
  499. ilDeleteImages(UndoSize, Undos);
  500. UndoSize = 0;
  501. ilGenImages(1, Undos);
  502. ilBindImage(Undos[0]);
  503. ilLoadImage(OpenFileName);
  504. CurImage = 0;
  505. ilutRenderer(ILUT_WIN32);
  506. ResizeWin();
  507. CreateGDI();
  508. wsprintf(CurFileName, L"%s", OpenFileName);
  509. wsprintf(NewTitle, L"%s - %s", TITLE, OpenFileName);
  510. SetWindowText(hWnd, NewTitle);
  511. DragFinish(hDrop);
  512. return 0;
  513. case WM_COMMAND:
  514. FilterType = LOWORD(wParam);
  515. switch (LOWORD(wParam))
  516. {
  517. case ID_FILE_EXIT:
  518. PostMessage(hWnd, WM_CLOSE, 0, 0);
  519. return (0L);
  520. case ID_HELP_ABOUT:
  521. DialogBox (hInstance,
  522. MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
  523. hWnd,
  524. AboutDlgProc);
  525. return (0L);
  526. case ID_FILE_PROPERTIES:
  527. DialogBox (hInstance,
  528. MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES),
  529. hWnd,
  530. PropertiesDlgProc);
  531. return (0L);
  532. case ID_BATCHCONVERT:
  533. DialogBox (hInstance,
  534. MAKEINTRESOURCE(IDD_DIALOG_BATCHCONV),
  535. hWnd,
  536. BatchDlgProc);
  537. return (0L);
  538. case ID_EFFECTS_COUNTCOLORS:
  539. Colours = iluColoursUsed();
  540. TCHAR ColourString[255];
  541. wsprintf(ColourString, L"The number of colours in this image is: %d", Colours);
  542. MessageBox(NULL, ColourString, L"Colour Count", MB_OK);
  543. return (0L);
  544. case ID_EFFECTSTOOLS_BACKGROUNDCOLOUR:
  545. //userClickedOK = FSColorPickerDoModal(&currentColor, true, &originalColor, true, 0);
  546. userClickedOK = 0;
  547. if (userClickedOK) {
  548. Red = (ILfloat)((currentColor & 0xff0000) >> 16) / 255.0f;
  549. Green = (ILfloat)((currentColor & 0xff00) >> 8) / 255.0f;
  550. Blue = (ILfloat)(currentColor & 0xff) / 255.0f;
  551. ilClearColour(Red, Green, Blue, 1.0f);
  552. }
  553. return (0L);
  554. case ID_EDIT_COPY:
  555. ilutSetWinClipboard();
  556. return (0L);
  557. case ID_EDIT_PASTE:
  558. ILuint Test;
  559. ilGenImages(1, &Test);
  560. ilBindImage(Test);
  561. // Check if there's anything in the clipboard.
  562. if (!ilutGetWinClipboard()) {
  563. ilDeleteImages(1, &Test);
  564. return (0L);
  565. }
  566. ilDeleteImages(1, &Test);
  567. DestroyGDI();
  568. ilDeleteImages(UndoSize, Undos);
  569. UndoSize = 0;
  570. XOff = 0;
  571. YOff = 0;
  572. ilGenImages(1, Undos);
  573. ilBindImage(Undos[0]);
  574. ilutGetWinClipboard();
  575. wsprintf(CurFileName, L"Clipboard Paste");
  576. wsprintf(NewTitle, L"%s - Pasted from the Clipboard", TITLE);
  577. SetWindowText(hWnd, NewTitle);
  578. //ilConvertImage(IL_BGRA);
  579. ilutRenderer(ILUT_WIN32);
  580. ResizeWin();
  581. CreateGDI();
  582. return (0L);
  583. // @TODO: Will probably fail if no image loaded!
  584. case ID_FILE_PRINT:
  585. /*PRINTDLG Pd;
  586. DOCINFO Di;
  587. //HDC PrintDC;
  588. //HBITMAP PrintReplace;
  589. memset(&Pd, 0, sizeof(PRINTDLG));
  590. Pd.lStructSize = sizeof(PRINTDLG);
  591. Pd.hwndOwner = hWnd;
  592. Pd.Flags = PD_RETURNDC;
  593. Pd.nCopies = 1;
  594. Pd.nFromPage = 0xFFFF;
  595. Pd.nToPage = 0xFFFF;
  596. Pd.nMinPage = 1;
  597. Pd.nMaxPage = 0xFFFF;
  598. if (!PrintDlg(&Pd))
  599. return (0L);
  600. Di.cbSize = sizeof(DOCINFO);
  601. Di.lpszDocName = L"DevIL Printing Test";
  602. Di.lpszOutput = NULL;
  603. Di.lpszDatatype = NULL;
  604. Di.fwType = 0;
  605. StartDoc(Pd.hDC, &Di);
  606. StartPage(Pd.hDC);
  607. //PrintDC = CreateCompatibleDC(Pd.hDC);
  608. //PrintReplace = (HBITMAP)SelectObject(PrintDC, hBitmap);
  609. StretchBlt(Pd.hDC, 0, 0, Width * 2, Height * 2, hMemDC, 0, 0, Width, Height, SRCCOPY);
  610. EndPage(Pd.hDC);
  611. EndDoc(Pd.hDC);
  612. //DeleteObject(PrintReplace);
  613. //DeleteDC(PrintDC);
  614. DeleteDC(Pd.hDC);*/
  615. ilutWinPrint(0, 0, ilGetInteger(IL_IMAGE_WIDTH) * 2, ilGetInteger(IL_IMAGE_HEIGHT) * 2, hDC);
  616. return (0L);
  617. case ID_FILE_LOAD:
  618. wsprintf(OpenFileName, L"*.*");
  619. Ofn.lpstrFilter = OpenFilter;
  620. Ofn.lpstrFile = OpenFileName;
  621. Ofn.lpstrTitle = L"Open File";
  622. Ofn.nFilterIndex = 1;
  623. Ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
  624. if (!GetOpenFileName(&Ofn))
  625. return (0L);
  626. DestroyGDI();
  627. if (UndoSize == 0)
  628. UndoSize = 1;
  629. ilDeleteImages(UndoSize, Undos);
  630. UndoSize = 0;
  631. XOff = 0;
  632. YOff = 0;
  633. ilGenImages(1, Undos);
  634. ilBindImage(Undos[0]);
  635. //last_elapsed = SDL_GetTicks();
  636. if (!ilLoadImage(OpenFileName))
  637. return (0L);
  638. CurImage = 0;
  639. //cur_elapsed = SDL_GetTicks();
  640. elapsed = cur_elapsed - last_elapsed;
  641. last_elapsed = cur_elapsed;
  642. //iluBuildMipmaps();
  643. //ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
  644. //ilEnable(IL_NVIDIA_COMPRESS);
  645. //ilEnable(IL_SQUISH_COMPRESS);
  646. //ilSetInteger(IL_DXTC_FORMAT, IL_DXT5);
  647. //free(ilCompressDXT(ilGetData(), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 1, IL_DXT5, &Size));
  648. //free(ilNVidiaCompressDXT(ilGetData(), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 1, IL_DXT5));
  649. ilutRenderer(ILUT_WIN32);
  650. ResizeWin();
  651. CreateGDI();
  652. wsprintf(CurFileName, L"%s", OpenFileName);
  653. wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, OpenFileName, (unsigned int)elapsed);
  654. SetWindowText(hWnd, NewTitle);
  655. return (0L);
  656. case ID_FILE_OPENURL:
  657. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  658. hWnd, FilterDlgProc) != TRUE) {
  659. return (0L);
  660. }
  661. DestroyGDI();
  662. ilDeleteImages(UndoSize, Undos);
  663. UndoSize = 0;
  664. XOff = 0;
  665. YOff = 0;
  666. ilGenImages(1, Undos);
  667. ilBindImage(Undos[0]);
  668. /*if (!ilutWinLoadUrl(FilterEditString))
  669. return (0L);*/
  670. ilutRenderer(ILUT_WIN32);
  671. ResizeWin();
  672. CreateGDI();
  673. wsprintf(NewTitle, L"%s - %s", TITLE, FilterEditString);
  674. SetWindowText(hWnd, NewTitle);
  675. return (0L);
  676. case ID_FILE_SAVE:
  677. wsprintf(SaveFileName, L"monkey.tga");
  678. Ofn.lpstrFilter = SaveFilter;
  679. Ofn.lpstrFile = SaveFileName;
  680. Ofn.lpstrTitle = L"Save File";
  681. Ofn.nFilterIndex = 1;
  682. Ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  683. if (!GetSaveFileName(&Ofn))
  684. return (0L);
  685. ilEnable(IL_FILE_OVERWRITE);
  686. //ilBindImage(Undos[0]); //@TODO: Do better here...
  687. //last_elapsed = SDL_GetTicks();
  688. ilSaveImage(SaveFileName);
  689. //cur_elapsed = SDL_GetTicks();
  690. elapsed = cur_elapsed - last_elapsed;
  691. last_elapsed = cur_elapsed;
  692. wsprintf(CurFileName, L"%s", SaveFileName);
  693. wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, SaveFileName, (unsigned int)elapsed);
  694. SetWindowText(hWnd, NewTitle);
  695. return (0L);
  696. case ID_EDIT_UNDOLEVEL:
  697. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  698. hWnd, FilterDlgProc) == TRUE) {
  699. NumUndosAllowed = FilterParamInt <= 10 ? FilterParamInt : 10;
  700. }
  701. return (0L);
  702. case ID_EDIT_UNDO:
  703. if (UndoSize && NumUndosAllowed) {
  704. ilDeleteImages(1, &Undos[UndoSize]);
  705. ilBindImage(Undos[--UndoSize]);
  706. ResizeWin();
  707. CreateGDI();
  708. }
  709. return (0L);
  710. case ID_EDIT_VIEWIMAGENUM:
  711. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  712. hWnd, FilterDlgProc) == TRUE) {
  713. ilBindImage(Undos[0]); // @TODO: Implement undos better with this.
  714. ilActiveImage(FilterParamInt);
  715. ilutRenderer(ILUT_WIN32);
  716. ResizeWin();
  717. CreateGDI();
  718. }
  719. return (0L);
  720. case ID_EDIT_VIEWFACE:
  721. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  722. hWnd, FilterDlgProc) == TRUE) {
  723. ilActiveFace(FilterParamInt);
  724. ilutRenderer(ILUT_WIN32);
  725. ResizeWin();
  726. CreateGDI();
  727. }
  728. return (0L);
  729. case ID_EDIT_VIEWMIPMAP:
  730. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  731. hWnd, FilterDlgProc) == TRUE) {
  732. ilActiveMipmap(FilterParamInt);
  733. ilutRenderer(ILUT_WIN32);
  734. ResizeWin();
  735. CreateGDI();
  736. }
  737. return (0L);
  738. case ID_EDIT_NEXT:
  739. ilBindImage(Undos[0]); // @TODO: Implement undos better with this.
  740. CurImage++;
  741. ilActiveImage(CurImage);
  742. ilutRenderer(ILUT_WIN32);
  743. ResizeWin();
  744. CreateGDI();
  745. return (0L);
  746. case ID_EDIT_PREV:
  747. ilBindImage(Undos[0]); // @TODO: Implement undos better with this.
  748. CurImage--;
  749. ilActiveImage(CurImage);
  750. ilutRenderer(ILUT_WIN32);
  751. ResizeWin();
  752. CreateGDI();
  753. return (0L);
  754. }
  755. if (++UndoSize > NumUndosAllowed) {
  756. if (NumUndosAllowed > 0) {
  757. UndoSize = NumUndosAllowed;
  758. ilDeleteImages(1, &Undos[0]);
  759. memcpy(Undos, Undos+1, NumUndosAllowed * sizeof(ILuint));
  760. ilBindImage(Undos[UndoSize]);
  761. }
  762. }
  763. if (NumUndosAllowed > 0) {
  764. ilGetIntegerv(IL_ACTIVE_IMAGE, (ILint*)&Undos[UndoSize]);
  765. /*ilGenImages(1, &Undos[UndoSize]);
  766. ilBindImage(Undos[UndoSize]);
  767. ilCopyImage(Undos[UndoSize-1]);*/
  768. Undos[UndoSize] = ilCloneCurImage();
  769. ilBindImage(Undos[UndoSize]);
  770. }
  771. DestroyGDI();
  772. switch (LOWORD(wParam))
  773. {
  774. case ID_CONVERT_PALETTE:
  775. ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE);
  776. break;
  777. case ID_CONVERT_RGB:
  778. ilConvertImage(IL_RGB, ilGetInteger(IL_IMAGE_TYPE));
  779. break;
  780. case ID_CONVERT_RGBA:
  781. ilConvertImage(IL_RGBA, ilGetInteger(IL_IMAGE_TYPE));
  782. break;
  783. case ID_CONVERT_BGR:
  784. ilConvertImage(IL_BGR, ilGetInteger(IL_IMAGE_TYPE));
  785. break;
  786. case ID_CONVERT_BGRA:
  787. ilConvertImage(IL_BGRA, ilGetInteger(IL_IMAGE_TYPE));
  788. break;
  789. case ID_CONVERT_LUMINANCE:
  790. ilConvertImage(IL_LUMINANCE, ilGetInteger(IL_IMAGE_TYPE));
  791. break;
  792. case ID_CONVERT_LUMINANCEALPHA:
  793. ilConvertImage(IL_LUMINANCE_ALPHA, ilGetInteger(IL_IMAGE_TYPE));
  794. break;
  795. case ID_EDIT_VIEWALPHA:
  796. Origin = ilGetInteger(IL_ORIGIN_MODE);
  797. AlphaChannel = ilGetAlpha(IL_UNSIGNED_BYTE);
  798. ilTexImage(ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
  799. ilGetInteger(IL_IMAGE_DEPTH), 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, AlphaChannel);
  800. free(AlphaChannel);
  801. ilRegisterOrigin(Origin);
  802. break;
  803. case ID_EFFECTS_FLIP:
  804. iluFlipImage();
  805. break;
  806. case ID_EFFECTS_MIRROR:
  807. iluMirror();
  808. break;
  809. case ID_FILTER_EMBOSS:
  810. iluEmboss();
  811. break;
  812. case ID_FILTER_EQUALIZE:
  813. iluEqualize();
  814. break;
  815. case ID_FILTER_ALIENIFY:
  816. iluAlienify();
  817. break;
  818. case ID_FILTER_NEGATIVE:
  819. iluNegative();
  820. break;
  821. case ID_EFFECTS_FILTERS_EDGEDETECT_EMBOSS:
  822. iluEdgeDetectE();
  823. break;
  824. case ID_EFFECTS_FILTERS_EDGEDETECT_SOBEL:
  825. iluEdgeDetectS();
  826. break;
  827. case ID_EFFECTS_FILTERS_EDGEDETECT_PREWITT:
  828. iluEdgeDetectP();
  829. break;
  830. case ID_FILTER_NOISE:
  831. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  832. hWnd, FilterDlgProc) == TRUE) {
  833. iluNoisify(FilterParamFloat);
  834. }
  835. break;
  836. case ID_EFFECTS_FILTERS_WAVE:
  837. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  838. hWnd, FilterDlgProc) == TRUE) {
  839. iluWave(FilterParamFloat);
  840. }
  841. break;
  842. case ID_FILTER_PIXELIZE:
  843. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  844. hWnd, FilterDlgProc) == TRUE) {
  845. iluPixelize(FilterParamInt);
  846. }
  847. break;
  848. case ID_FILTERS_BLUR_AVERAGE:
  849. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  850. hWnd, FilterDlgProc) == TRUE) {
  851. iluBlurAvg(FilterParamInt);
  852. }
  853. break;
  854. case ID_FILTERS_BLUR_GAUSSIAN:
  855. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  856. hWnd, FilterDlgProc) == TRUE) {
  857. iluBlurGaussian(FilterParamInt);
  858. /*iluMatrixMode(ILU_CONVOLUTION_MATRIX);
  859. iluLoadFilter(ILU_FILTER_GAUSSIAN_5X5);
  860. iluApplyMatrix();*/
  861. }
  862. break;
  863. case ID_FILTER_GAMMACORRECT:
  864. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  865. hWnd, FilterDlgProc) == TRUE) {
  866. iluGammaCorrect(FilterParamFloat);
  867. }
  868. break;
  869. case ID_FILTER_SHARPEN:
  870. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  871. hWnd, FilterDlgProc) == TRUE) {
  872. iluSharpen(FilterParamFloat, 1);
  873. }
  874. break;
  875. case ID_EFFECTS_FILTERS_ROTATE:
  876. if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER),
  877. hWnd, FilterDlgProc) == TRUE) {
  878. iluRotate(FilterParamFloat);
  879. ResizeWin();
  880. }
  881. break;
  882. case ID_EFFECTS_FILTERS_SCALE:
  883. HWnd = hWnd;
  884. iluImageParameter(ILU_FILTER, ILU_BILINEAR);
  885. DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_RESIZE), hWnd, ResizeDlgProc);
  886. break;
  887. }
  888. CreateGDI();
  889. InvalidateRect(hWnd, NULL, FALSE);
  890. break;
  891. default:
  892. return (DefWindowProc(hWnd, message, wParam, lParam));
  893. }
  894. return (0L);
  895. }
  896. void GenFilterString(TCHAR *Out, TCHAR **Strings)
  897. {
  898. int OutPos = 0, StringPos = 0;
  899. while (Strings[StringPos][0] != 0) {
  900. wsprintf(Out + OutPos, Strings[StringPos]);
  901. OutPos += (int)wcslen(Strings[StringPos++]) + 1;
  902. }
  903. Out[OutPos++] = 0;
  904. Out[OutPos] = 0;
  905. return;
  906. }
  907. INT_PTR APIENTRY AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  908. {
  909. switch (message)
  910. {
  911. case WM_INITDIALOG:
  912. {
  913. int i;
  914. ILenum ilError;
  915. TCHAR VersionNum[256];
  916. wsprintf(VersionNum, L"Num: %d", ilGetInteger(IL_VERSION_NUM));
  917. SetDlgItemText(hDlg, IDC_ABOUT_VENDOR, ilGetString(IL_VENDOR));
  918. SetDlgItemText(hDlg, IDC_ABOUT_VER_STRING, ilGetString(IL_VERSION_NUM));
  919. SetDlgItemText(hDlg, IDC_ABOUT_VER_NUM, VersionNum);
  920. for (i = 0; i < 6; i++) {
  921. ilError = ilGetError();
  922. if (ilError == IL_NO_ERROR)
  923. break;
  924. SetDlgItemText(hDlg, IDC_ERROR1+i, iluErrorString(ilError));
  925. }
  926. return (TRUE);
  927. }
  928. break;
  929. case WM_COMMAND:
  930. {
  931. if (LOWORD(wParam) == IDOK)
  932. EndDialog(hDlg, TRUE);
  933. if (LOWORD(wParam) == IDCANCEL)
  934. EndDialog(hDlg, FALSE);
  935. }
  936. break;
  937. case WM_CLOSE:
  938. EndDialog(hDlg, TRUE);
  939. break;
  940. }
  941. return FALSE;
  942. }
  943. INT_PTR APIENTRY PropertiesDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  944. {
  945. switch (message)
  946. {
  947. case WM_INITDIALOG:
  948. {
  949. TCHAR Temp[256];
  950. SetDlgItemText(hDlg, IDC_PROP_FILENAME, CurFileName);
  951. wsprintf(Temp, L"%d", ilGetInteger(IL_IMAGE_WIDTH));
  952. SetDlgItemText(hDlg, IDC_PROP_WIDTH, Temp);
  953. wsprintf(Temp, L"%d", ilGetInteger(IL_IMAGE_HEIGHT));
  954. SetDlgItemText(hDlg, IDC_PROP_HEIGHT, Temp);
  955. wsprintf(Temp, L"%d", ilGetInteger(IL_IMAGE_DEPTH));
  956. SetDlgItemText(hDlg, IDC_PROP_DEPTH, Temp);
  957. wsprintf(Temp, L"%d", ilGetInteger(IL_IMAGE_SIZE_OF_DATA));
  958. SetDlgItemText(hDlg, IDC_PROP_SIZE, Temp);
  959. return (TRUE);
  960. }
  961. break;
  962. case WM_COMMAND:
  963. {
  964. if (LOWORD(wParam) == IDOK)
  965. EndDialog(hDlg, TRUE);
  966. if (LOWORD(wParam) == IDCANCEL)
  967. EndDialog(hDlg, FALSE);
  968. }
  969. break;
  970. case WM_CLOSE:
  971. EndDialog(hDlg, TRUE);
  972. break;
  973. }
  974. return FALSE;
  975. }
  976. INT_PTR APIENTRY FilterDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  977. {
  978. switch (message)
  979. {
  980. case WM_INITDIALOG:
  981. {
  982. switch (FilterType)
  983. {
  984. case ID_FILTER_PIXELIZE:
  985. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Width of pixelized block:");
  986. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"1");
  987. break;
  988. case ID_FILTER_NOISE:
  989. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Amount of noise threshold:");
  990. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"1.0");
  991. break;
  992. case ID_EFFECTS_FILTERS_WAVE:
  993. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Angle of wave to apply:");
  994. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"0.0");
  995. break;
  996. case ID_FILTERS_BLUR_AVERAGE:
  997. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Number of iterations:");
  998. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"1");
  999. break;
  1000. case ID_FILTERS_BLUR_GAUSSIAN:
  1001. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Number of iterations:");
  1002. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"1");
  1003. break;
  1004. case ID_FILTER_GAMMACORRECT:
  1005. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Amount of gamma correction:");
  1006. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"1.0");
  1007. break;
  1008. case ID_FILTER_SHARPEN:
  1009. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Sharpening factor:");
  1010. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"1.0");
  1011. break;
  1012. case ID_EFFECTS_FILTERS_ROTATE:
  1013. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Number of degress to rotate:");
  1014. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"0.0");
  1015. break;
  1016. case ID_EDIT_UNDOLEVEL:
  1017. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Set level of undo:");
  1018. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"4");
  1019. break;
  1020. case ID_EDIT_VIEWIMAGENUM:
  1021. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Enter image number:");
  1022. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"0");
  1023. break;
  1024. case ID_EDIT_VIEWMIPMAP:
  1025. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Enter mipmap number:");
  1026. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"0");
  1027. break;
  1028. case ID_FILE_OPENURL:
  1029. SetDlgItemText(hDlg, IDC_FILTER_DESC_TEXT, L"Enter url of image:");
  1030. SetDlgItemText(hDlg, IDC_FILTER_EDIT, L"");
  1031. break;
  1032. }
  1033. return TRUE;
  1034. }
  1035. break;
  1036. case WM_COMMAND:
  1037. {
  1038. if (LOWORD(wParam) == IDOK) {
  1039. GetDlgItemText(hDlg, IDC_FILTER_EDIT, FilterEditString, 255);
  1040. FilterParamInt = _wtoi(FilterEditString);
  1041. FilterParamFloat = (float)_wtof(FilterEditString);
  1042. EndDialog(hDlg, TRUE);
  1043. }
  1044. if (LOWORD(wParam) == IDCANCEL) {
  1045. EndDialog(hDlg, FALSE);
  1046. }
  1047. }
  1048. break;
  1049. case WM_CLOSE:
  1050. EndDialog(hDlg, TRUE);
  1051. break;
  1052. }
  1053. return FALSE;
  1054. }
  1055. INT_PTR APIENTRY ResizeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1056. {
  1057. static TCHAR x[255], y[255], z[255];
  1058. static ILuint xsize, ysize, zsize;
  1059. static RECT Rect;
  1060. switch (message)
  1061. {
  1062. case WM_INITDIALOG:
  1063. {
  1064. wsprintf(x, L"%d", Width);
  1065. wsprintf(y, L"%d", Height);
  1066. wsprintf(z, L"%d", Depth);
  1067. SetDlgItemText(hDlg, IDC_EDIT_RESIZE_X, x);
  1068. SetDlgItemText(hDlg, IDC_EDIT_RESIZE_Y, y);
  1069. SetDlgItemText(hDlg, IDC_EDIT_RESIZE_Z, z);
  1070. return TRUE;
  1071. }
  1072. break;
  1073. case WM_COMMAND:
  1074. {
  1075. if (LOWORD(wParam) == IDOK) {
  1076. GetDlgItemText(hDlg, IDC_EDIT_RESIZE_X, x, 255);
  1077. GetDlgItemText(hDlg, IDC_EDIT_RESIZE_Y, y, 255);
  1078. GetDlgItemText(hDlg, IDC_EDIT_RESIZE_Z, z, 255);
  1079. xsize = _wtoi(x);
  1080. ysize = _wtoi(y);
  1081. zsize = _wtoi(z);
  1082. if (xsize && ysize && zsize) {
  1083. iluScale(xsize, ysize, zsize);
  1084. Width = ilGetInteger(IL_IMAGE_WIDTH);
  1085. Height = ilGetInteger(IL_IMAGE_HEIGHT);
  1086. Depth = ilGetInteger(IL_IMAGE_DEPTH);
  1087. GetWindowRect(HWnd, &Rect);
  1088. SetWindowPos(HWnd, HWND_TOP, Rect.left, Rect.top,
  1089. Width < MIN_W ? MIN_W + BORDER_W : Width + BORDER_W,
  1090. Height + MENU_H, SWP_SHOWWINDOW);
  1091. InvalidateRect(HWnd, NULL, FALSE);
  1092. }
  1093. EndDialog(hDlg, TRUE);
  1094. }
  1095. if (LOWORD(wParam) == IDCANCEL) {
  1096. EndDialog(hDlg, FALSE);
  1097. }
  1098. }
  1099. break;
  1100. case WM_CLOSE:
  1101. EndDialog(hDlg, TRUE);
  1102. break;
  1103. }
  1104. return FALSE;
  1105. }
  1106. INT_PTR APIENTRY BatchDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1107. {
  1108. static TCHAR Dir[255], NewExt[255];
  1109. static bool Recurse;
  1110. static RECT Rect;
  1111. switch (message)
  1112. {
  1113. case WM_INITDIALOG:
  1114. {
  1115. wsprintf(Dir, L"");
  1116. wsprintf(NewExt, L"tga");
  1117. SetDlgItemText(hDlg, IDC_BATCH_DIR, Dir);
  1118. SetDlgItemText(hDlg, IDC_BATCH_NEWEXT, NewExt);
  1119. return TRUE;
  1120. }
  1121. break;
  1122. case WM_COMMAND:
  1123. {
  1124. if (LOWORD(wParam) == IDOK) {
  1125. GetDlgItemText(hDlg, IDC_BATCH_DIR, Dir, 255);
  1126. GetDlgItemText(hDlg, IDC_BATCH_NEWEXT, NewExt, 255);
  1127. Recurse = IsDlgButtonChecked(hDlg, IDC_BATCH_CHECK1) == BST_CHECKED;
  1128. // Do shit here.
  1129. //BatchConv(Dir, NULL, NewExt, Recurse);
  1130. EndDialog(hDlg, TRUE);
  1131. }
  1132. if (LOWORD(wParam) == IDCANCEL) {
  1133. EndDialog(hDlg, FALSE);
  1134. }
  1135. }
  1136. break;
  1137. case WM_CLOSE:
  1138. EndDialog(hDlg, TRUE);
  1139. break;
  1140. }
  1141. return FALSE;
  1142. }
  1143. bool GetPrevImage()
  1144. {
  1145. HANDLE Search;
  1146. WIN32_FIND_DATA FindData;
  1147. int i = 0, j, Total = 0, FileNamePos = -1;
  1148. TCHAR *Ext, *CurName;
  1149. Search = FindFirstFile(L"*.*", &FindData);
  1150. CurName = wcsrchr(CurFileName, '\\');
  1151. if (CurName == NULL) {
  1152. CurName = CurFileName;
  1153. }
  1154. else {
  1155. CurName++; // Skip the '\'
  1156. }
  1157. do {
  1158. if (!_wcsicmp(FindData.cFileName, L".") || !_wcsicmp(FindData.cFileName, L".."))
  1159. continue;
  1160. Ext = GetExtension(FindData.cFileName);
  1161. if (Ext == NULL)
  1162. continue;
  1163. for (j = 0; ExtList[j] != NULL; j++) {
  1164. if (CheckExtension(FindData.cFileName, ExtList[j])) {
  1165. if (!_wcsicmp(FindData.cFileName, CurName))
  1166. FileNamePos = Total;
  1167. Total++;
  1168. break;
  1169. }
  1170. }
  1171. } while (FindNextFile(Search, &FindData));
  1172. FindClose(Search);
  1173. Search = FindFirstFile(L"*.*", &FindData);
  1174. if (Total == 0 || FileNamePos == -1)
  1175. return false;
  1176. if (FileNamePos == 0)
  1177. FileNamePos = Total;
  1178. do {
  1179. if (!_wcsicmp(FindData.cFileName, L".") || !_wcsicmp(FindData.cFileName, L".."))
  1180. continue;
  1181. Ext = GetExtension(FindData.cFileName);
  1182. if (Ext == NULL)
  1183. continue;
  1184. for (j = 0; ExtList[j] != NULL; j++) {
  1185. if (CheckExtension(FindData.cFileName, ExtList[j])) {
  1186. if (FileNamePos == i+1) {
  1187. wcscpy(OpenFileName, FindData.cFileName);
  1188. i++;
  1189. break;
  1190. }
  1191. i++;
  1192. break;
  1193. }
  1194. }
  1195. } while (FindNextFile(Search, &FindData));
  1196. FindClose(Search);
  1197. return true;
  1198. }
  1199. bool GetNextImage()
  1200. {
  1201. HANDLE Search;
  1202. WIN32_FIND_DATA FindData;
  1203. int i = 0, j, Total = 0, FileNamePos = -1;
  1204. TCHAR *Ext, *CurName;
  1205. Search = FindFirstFile(L"*.*", &FindData);
  1206. CurName = wcsrchr(CurFileName, '\\');
  1207. if (CurName == NULL) {
  1208. CurName = CurFileName;
  1209. }
  1210. else {
  1211. CurName++; // Skip the '\'
  1212. }
  1213. do {
  1214. if (!_wcsicmp(FindData.cFileName, L".") || !_wcsicmp(FindData.cFileName, L".."))
  1215. continue;
  1216. Ext = GetExtension(FindData.cFileName);
  1217. if (Ext == NULL)
  1218. continue;
  1219. for (j = 0; ExtList[j] != NULL; j++) {
  1220. if (CheckExtension(FindData.cFileName, ExtList[j])) {
  1221. if (!_wcsicmp(FindData.cFileName, CurName))
  1222. FileNamePos = Total;
  1223. Total++;
  1224. break;
  1225. }
  1226. }
  1227. } while (FindNextFile(Search, &FindData));
  1228. FindClose(Search);
  1229. Search = FindFirstFile(L"*.*", &FindData);
  1230. if (Total == 0 || FileNamePos == -1)
  1231. return false;
  1232. if (FileNamePos == Total-1)
  1233. FileNamePos = -1;
  1234. do {
  1235. if (!_wcsicmp(FindData.cFileName, L".") || !_wcsicmp(FindData.cFileName, L".."))
  1236. continue;
  1237. Ext = GetExtension(FindData.cFileName);
  1238. if (Ext == NULL)
  1239. continue;
  1240. for (j = 0; ExtList[j] != NULL; j++) {
  1241. if (CheckExtension(FindData.cFileName, ExtList[j])) {
  1242. if (FileNamePos == i-1) {
  1243. wcscpy(OpenFileName, FindData.cFileName);
  1244. i++;
  1245. break;
  1246. }
  1247. i++;
  1248. break;
  1249. }
  1250. }
  1251. } while (FindNextFile(Search, &FindData));
  1252. FindClose(Search);
  1253. return true;
  1254. }