bitmap.h 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  1. //-----------------------------------------------------------------------------
  2. // -------------------
  3. // File ....: bitmap.h
  4. // -------------------
  5. // Author...: Tom Hudson
  6. // Date ....: Sptember 1994
  7. //
  8. // History .: Sep, 01 1994 - Started serious coding
  9. // Oct, 18 1994 - First major revision for DLLs, restructuring
  10. // Jul, 10 1995 - Began working with it (Gus J Grubba)
  11. //
  12. //-----------------------------------------------------------------------------
  13. #ifndef BITMAP_H_DEFINED
  14. #define BITMAP_H_DEFINED
  15. #define NOAVIFILE
  16. #include <vfw.h>
  17. #undef NOAVIFILE
  18. #include "linklist.h"
  19. //-- Defines that may change with compiler
  20. #define INTBITS (sizeof(int) * 8)
  21. //-- Class ID's for various DLL's
  22. #define IMGCLASSID 1
  23. #define CYCLECLASSID 2
  24. #define FLICCLASSID 5
  25. #define TARGACLASSID 6
  26. #define YUVCLASSID 7
  27. #define FBCLASSID 8
  28. #define WSDCLASSID 9
  29. #define IFLCLASSID 10
  30. #define BMPCLASSID 11
  31. #define JPEGCLASSID 12
  32. #define TARGAPLSCLASSID 13
  33. #define AVICLASSID 14
  34. #define RLACLASSID 15
  35. //-- local definitions
  36. class BitmapManager;
  37. class BitmapStorage;
  38. class BitmapFilter;
  39. class BitmapDither;
  40. class BitmapInfo;
  41. class BitmapPicker;
  42. class BitmapIO;
  43. class Bitmap;
  44. //-- Temporary definitions to make the compiler happy
  45. class GraphicsWindow;
  46. class BMMInterface;
  47. class DllDir;
  48. //-- External data
  49. extern int TheSystemFrame; // TO DO: Move to App data structure?
  50. //-----------------------------------------------------------------------------
  51. //-- The Primary Bitmap Manager Object
  52. //
  53. extern BMMExport BitmapManager *TheManager; // TO DO: Move to App data structure?
  54. //-- Common Macros ------------------------------------------------------------
  55. //-- Just to make it shorter
  56. #define bVirtual BMMExport virtual
  57. //-- Set up a NULL macro
  58. #ifndef NULL
  59. #define NULL (0)
  60. #endif
  61. //-- Pixel storage classes ----------------------------------------------------
  62. typedef struct {
  63. BYTE r,g,b;
  64. } BMM_Color_24;
  65. typedef struct {
  66. BYTE r,g,b,a;
  67. } BMM_Color_32;
  68. typedef struct {
  69. WORD r,g,b;
  70. } BMM_Color_48;
  71. typedef struct {
  72. WORD r,g,b,a;
  73. } BMM_Color_64;
  74. //-- Generic bitmap information structure -------------------------------------
  75. typedef struct {
  76. int width,height;
  77. float aspect,gamma;
  78. DWORD flags;
  79. } BMMImageInfo;
  80. //-- Basic bitmap types supported by Bitmap Manager
  81. #define BMM_NO_TYPE 0 // Not allocated yet
  82. #define BMM_LINE_ART 1
  83. #define BMM_PALETTED 2
  84. #define BMM_GRAY_8 3
  85. #define BMM_GRAY_16 4
  86. #define BMM_TRUE_16 5
  87. #define BMM_TRUE_32 6
  88. #define BMM_TRUE_64 7
  89. //-- Information Only
  90. #define BMM_TRUE_24 8
  91. #define BMM_TRUE_48 9
  92. #define BMM_YUV_422 10
  93. #define BMM_BMP_4 11 //-- Windows BMP 16 color bitmap
  94. #define BMM_PAD_24 12 //-- Padded 24 bit (in a 32 bit register)
  95. //-- Textual Limits
  96. #define MAX_DESCRIPTION 256
  97. //-- The number of bitmap formats supported internally
  98. //#define BMM_FORMATS 6
  99. //-- File types
  100. //#define BMM_NOTYPE 0
  101. //#define BMM_TARGA 1 // System Targa I/O driver
  102. //#define BMM_GIF 2 // System GIF I.O driver
  103. //-- Gamma limits
  104. #define MINGAMMA 0.2f
  105. #define MAXGAMMA 5.0f
  106. //-- openMode values
  107. #define BMM_NOT_OPEN 0 // Not opened yet
  108. #define BMM_OPEN_R 1 // Read-only
  109. #define BMM_OPEN_W 2 // Write
  110. //-----------------------------------------------------------------------------
  111. //-----------------------------------------------------------------------------
  112. //-- Error Codes for BMMRES type functions
  113. typedef unsigned short BMMRES; // Traps the use of int or BOOL
  114. #define BMMRES_SUCCESS 0
  115. #define BMMRES_ERRORTAKENCARE 1 // Error - Function has already taken action
  116. #define BMMRES_FILENOTFOUND 2
  117. #define BMMRES_MEMORYERROR 3
  118. #define BMMRES_NODRIVER 4 // Device driver responsible for image not present
  119. #define BMMRES_IOERROR 5
  120. #define BMMRES_INVALIDFORMAT 6
  121. #define BMMRES_CORRUPTFILE 7
  122. #define BMMRES_SINGLEFRAME 8 // Goto request on a single frame image
  123. #define BMMRES_INVALIDUSAGE 9 // Bad argument passed to function (Developer Mistake)
  124. #define BMMRES_ERRORRETRY 10 // User selected "Retry" from error dialogue
  125. #define BMMRES_NUMBEREDFILENAMEERROR 11
  126. #define BMMRES_INTERNALERROR 12
  127. #define BMMRES_BADFILEHEADER 13
  128. #define BMMRES_CANTSTORAGE 14
  129. #define BMMRES_RETRY 15
  130. #define BMMRES_BADFRAME 16 // Invalid Frame Number Requested
  131. //-----------------------------------------------------------------------------
  132. //-----------------------------------------------------------------------------
  133. //-- BitmapIO usage types ( returned by BitmapIO::Capability() )
  134. #define BMMIO_NONE 0 // Not defined yet
  135. #define BMMIO_READER (1<<0) // Reads images
  136. #define BMMIO_WRITER (1<<1) // Writes images
  137. #define BMMIO_EXTENSION (1<<2) // Uses file extension (File Filter Type)
  138. #define BMMIO_MULTIFRAME (1<<3) // "File" contains multiple frames (i.e. FLC, AVI)
  139. #define BMMIO_THREADED (1<<4) // Thread aware plug-in
  140. #define BMMIO_RANDOM_ACCESS (1<<5) // Can read and/or write frames in any order
  141. #define BMMIO_NON_CONCURRENT_ACCESS (1<<6) // Cannot handle multiple, concurrent requests (FLC, AVI, VTR's, etc)
  142. #define BMMIO_OWN_VIEWER (1<<7) // Driver has its own image viewer for its image type.
  143. //-- Frame Buffers
  144. #define BMMIO_FRAMEBUFFER (1<<7) // Frame Buffer Driver
  145. #define BMMIO_GRABBER (1<<8) // Device Grabs Video
  146. //-- If the device is able to show its own image info dialogue this flag will be
  147. // set. Otherwise, the host must use BitmapManager::GetImageInfo() and display
  148. // a generic info dialogue.
  149. #define BMMIO_INFODLG (1<<9) // Has Info Dialog
  150. //-- Special IFL device
  151. #define BMMIO_IFL (1<<28)
  152. //-- There is only a single call to the plug-in's control panel but the call specifies
  153. // the nature of the operation going on. It's up to the plug-in to provide different
  154. // interfaces if needed. If one control serves two or more services, all the pertinent
  155. // flags should be set.
  156. #define BMMIO_CONTROLREAD (1<<29) // Device Driver has Control Panel for Read Operations
  157. #define BMMIO_CONTROLWRITE (1<<30) // Device Driver has Control Panel for Write Operations
  158. #define BMMIO_CONTROLGENERIC (1<<31) // Device Driver has a generic Control Panel
  159. //-----------------------------------------------------------------------------
  160. //-- Bitmap close options
  161. #define BMM_CLOSE_COMPLETE 0
  162. #define BMM_CLOSE_ABANDON 1
  163. //-- Filter Types
  164. #define BMM_FILTER_NONE 0
  165. #define BMM_FILTER_DUMMY 1
  166. #define BMM_FILTER_SUM 2
  167. #define BMM_FILTER_PYRAMID 3
  168. //-- Filter Flag values
  169. #define BMM_FILTER_NOFLAGS ((DWORD)0)
  170. #define BMM_FILTER_LERP_WRAP ((DWORD)(1<<0))
  171. //-- Dither Types
  172. #define BMM_DITHER_NONE 0
  173. #define BMM_DITHER_FLOYD 1
  174. //-- Pyramidal filter information
  175. #define MAX_PYRAMID_DEPTH 12
  176. #define LAYER_DIM MAX_PYRAMID_DEPTH+1
  177. typedef struct {
  178. WORD dmax;
  179. void *map[LAYER_DIM];
  180. void *alpha[LAYER_DIM];
  181. } BMM_Pyramid;
  182. //-- Summed-area table information
  183. typedef struct {
  184. DWORD *sat_r,*sat_g,*sat_b,*sat_a;
  185. } BMM_SAT;
  186. //-- Bitmap::CopyImage options
  187. #define COPY_IMAGE_CROP 0 // Copy image to current map size w/cropping if necessary
  188. #define COPY_IMAGE_RESIZE_LO_QUALITY 1 // Resize source image to destination map size (draft)
  189. #define COPY_IMAGE_RESIZE_HI_QUALITY 2 // Resize source image to destination map size (final)
  190. #define COPY_IMAGE_USE_CUSTOM 3 // Based on Image Input Options (BitmapInfo *)
  191. // Class for storing a linked list of file extension strings
  192. MakeLinkedList(TSTR);
  193. //-----------------------------------------------------------------------------
  194. //-- GBuffer defines
  195. //
  196. // Recognized types of channels
  197. #define BMM_CHAN_TYPE_UNKNOWN 0
  198. #define BMM_CHAN_TYPE_1 1 // 1 bit per pixel
  199. #define BMM_CHAN_TYPE_8 2 // 1 byte per pixel
  200. #define BMM_CHAN_TYPE_16 3 // 1 word per pixel
  201. #define BMM_CHAN_TYPE_32 4 // 2 words per pixel
  202. #define BMM_CHAN_TYPE_48 5 // 3 words per pixel
  203. #define BMM_CHAN_TYPE_64 6 // 4 words per pixel
  204. // Recognized channel ID's (number of bits in parentheses in comments)
  205. #define BMM_CHAN_NONE 0
  206. #define BMM_CHAN_Z (1<<0) // (32) Z-buffer depth, float
  207. #define BMM_CHAN_MTL_ID (1<<1) // ( 8) ID assigned to mtl via mtl editor
  208. #define BMM_CHAN_NODE_ID (1<<2) // (16) ID assigned to node via properties
  209. #define BMM_CHAN_UV (1<<3) // (64) UV coordinates - Point2
  210. #define BMM_CHAN_NORMAL (1<<4) // (32) Normal vector in view space, compressed
  211. #define BMM_CHAN_REALPIX (1<<5) // (32) Non clamped colors in "RealPixel" format
  212. //-----------------------------------------------------------------------------
  213. //-- I/O Handler
  214. //
  215. class BMM_IOHandler {
  216. //-- Name and Capabilities ------------------------
  217. TCHAR ioShortDesc[MAX_DESCRIPTION];
  218. TCHAR ioLongDesc[MAX_DESCRIPTION];
  219. DWORD ioCapabilities;
  220. //-- Extension for file types
  221. TSTRList ioExtension;
  222. //-- DLL Handler ----------------------------------
  223. ClassDesc *cd;
  224. public:
  225. BMMExport BMM_IOHandler();
  226. BMMExport TCHAR *ShortDescription ( const TCHAR *d = NULL );
  227. BMMExport TCHAR *LongDescription ( const TCHAR *d = NULL );
  228. BMMExport TCHAR *Extension ( int index, const TCHAR *e = NULL );
  229. BMMExport int NumExtensions ( ) { return ioExtension.Count(); }
  230. BMMExport void SetCD ( ClassDesc *dll ) { cd = dll;};
  231. BMMExport ClassDesc *GetCD ( ) { return cd;};
  232. BMMExport void SetCapabilities ( DWORD cap ) { ioCapabilities |= cap;};
  233. BMMExport DWORD GetCapabilities ( ) { return (ioCapabilities);};
  234. BMMExport BOOL TestCapabilities ( DWORD cap ) { return (ioCapabilities & cap);};
  235. BMMExport BMM_IOHandler& operator=(BMM_IOHandler &from);
  236. };
  237. //-----------------------------------------------------------------------------
  238. //-- List of I/O Handlers
  239. //
  240. // Class for storing a linked list of Bitmap Manager BMM_IOHandler objects
  241. MakeLinkedList(BMM_IOHandler);
  242. class BMM_IOList: public BMM_IOHandlerList {
  243. BOOL listed;
  244. public:
  245. BMM_IOList ( ) { listed = FALSE; }
  246. BOOL Listed ( BOOL f) { listed = f; return (listed);};
  247. BOOL Listed ( ) { return (listed);};
  248. BMMExport int FindDevice ( const TCHAR *name);
  249. BMMExport int FindDeviceFromFilename ( const TCHAR *name);
  250. BMMExport int ResolveDevice ( BitmapInfo *bi );
  251. BMMExport DWORD GetDeviceCapabilities ( const TCHAR *name);
  252. //-- This Creates an Instance - Make sure to "delete" it after use.
  253. BMMExport BitmapIO *CreateDevInstance( const TCHAR *d );
  254. BMMExport BitmapIO *CreateDevInstance( int idx );
  255. };
  256. //-----------------------------------------------------------------------------
  257. //-- RenderInfo Class
  258. //
  259. enum ProjectionType { ProjPerspective=0, ProjParallel=1 };
  260. class RenderInfo {
  261. public:
  262. RenderInfo();
  263. ProjectionType projType;
  264. float kx,ky; // 3D to 2D projection scale factor
  265. float xc,yc; // screen origin
  266. BOOL fieldRender; // field rendered?
  267. BOOL fieldOdd; // if true, the first field is Odd lines
  268. // Render time and tranformations for the 2 fields, if field rendering.
  269. // If not, use renderTime[0], etc.
  270. TimeValue renderTime[2];
  271. Matrix3 worldToCam[2];
  272. Matrix3 camToWorld[2];
  273. BMMExport Point2 MapWorldToScreen(Point3 p, int field=0) { return MapCamToScreen(worldToCam[field]*p);}
  274. BMMExport Point2 MapCamToScreen(Point3 p); // map point in camera space to screen
  275. BMMExport Ray MapScreenToCamRay(Point2 p); // get viewing ray through screen point, in camera space
  276. BMMExport Ray MapScreenToWorldRay(Point2 p, int field=0); // get viewing ray through screen point, in world space
  277. };
  278. //-----------------------------------------------------------------------------
  279. //-- Bitmap Info Class
  280. //
  281. //-- Bitmap flags
  282. #define MAP_NOFLAGS ((DWORD)0)
  283. #define MAP_READY ((DWORD)(1<<0))
  284. #define MAP_HAS_ALPHA ((DWORD)(1<<1))
  285. #define MAP_ALPHA_PREMULTIPLIED ((DWORD)(1<<2))
  286. #define MAP_PALETTED ((DWORD)(1<<3))
  287. #define MAP_FRAME_SYSTEM_LOCKED ((DWORD)(1<<4))
  288. #define MAP_DITHERED ((DWORD)(1<<5))
  289. #define MAP_FLIPPED ((DWORD)(1<<6)) // Flipped horizontally
  290. #define MAP_INVERTED ((DWORD)(1<<7)) // Flipped vertically
  291. //#define MAP_CUSTOMSIZE ((DWORD)(1<<8)) // Custom size for input
  292. //#define MAP_RESIZE ((DWORD)(1<<9)) // Resize when input
  293. #define MAP_VIEW_FILTERED ((DWORD)(1<<31)) // Test stuff
  294. #define MAP_ALL_FLAGS 0xFFFFFFFF
  295. //-----------------------------------------------------------------------------
  296. //-- Messages sent back by various (client) methods
  297. //-- Sent by the plug-in to notify host of current progress. The host should
  298. // return TRUE if it's ok to continue or FALSE to abort process.
  299. #define BMM_PROGRESS WM_USER + 0x120 //-- wParam: Current lParam: Total
  300. //-- Sent by the plug-in to check for process interruption. The host should
  301. // return FALSE (by setting lParam) if it's ok to continue or TRUE to abort
  302. // process.
  303. #define BMM_CHECKABORT WM_USER + 0x121 //-- wParam: 0 lParam: *BOOL
  304. //-- Sent by the plug-in to display an optional textual message (for progress
  305. // report).
  306. #define BMM_TEXTMSG WM_USER + 0x122 //-- wParam: 0 lParam: LPCTSTR
  307. class BitmapInfo {
  308. //-- Image name in case of named images such as files -------
  309. TCHAR name[MAX_PATH];
  310. //-- Device name gotten from BMM_IOHandler::LongDescription()
  311. TCHAR device[MAX_DESCRIPTION];
  312. //-- Window Handle to send BMM_UPDATE messages --------------
  313. HWND hWnd;
  314. //-- Plug-In Parameter Block --------------------------------
  315. void *pidata;
  316. DWORD pisize;
  317. //-- Basic Image Data ---------------------------------------
  318. //
  319. // When reading an image, or asking for image info, these
  320. // fields will tell the user what the image is like.
  321. //
  322. // When creating an image the user will set these fields to
  323. // the desired parameters.
  324. //
  325. WORD width,height;
  326. float aspect,gamma;
  327. int fstart,fend;
  328. DWORD flags,type;
  329. //-- User data (what user wants) ----------------------------
  330. //
  331. // Custom dimmensions, custom start and end point when
  332. // reading sequence of imges, frame to fetch/save, etc.
  333. //
  334. WORD cwidth,cheight;
  335. int custxpos,custypos;
  336. int start,end;
  337. int step,preset_al;
  338. float custgamma;
  339. #define BMM_CUSTOM_GAMMA ((DWORD)(1 << 0))
  340. #define BMM_CUSTOM_SIZE ((DWORD)(1 << 1))
  341. #define BMM_CUSTOM_RESFIT ((DWORD)(1 << 2))
  342. #define BMM_CUSTOM_POS ((DWORD)(1 << 3))
  343. #define BMM_CUSTOM_FILEGAMMA ((DWORD)(1 << 4))
  344. #define BMM_CUSTOM_POSNW 0
  345. #define BMM_CUSTOM_POSN 1
  346. #define BMM_CUSTOM_POSNE 2
  347. #define BMM_CUSTOM_POSW 3
  348. #define BMM_CUSTOM_POSCN 4
  349. #define BMM_CUSTOM_POSE 5
  350. #define BMM_CUSTOM_POSSW 6
  351. #define BMM_CUSTOM_POSS 7
  352. #define BMM_CUSTOM_POSSE 8
  353. DWORD customflags;
  354. int fnumber; //-- Defines frame to
  355. // read or write.
  356. //-- When reading a sequence of frames, loopflag indicates what to
  357. // do when reading beyond the end of available frames. It
  358. // defaults to BMM_SEQ_WRAP.
  359. #define BMM_SEQ_WRAP 0 //-- Wraps around back to start point
  360. #define BMM_SEQ_ERROR 1 //-- Generates an error
  361. #define BMM_SEQ_HOLD 2 //-- Holds last frame when done
  362. WORD loopflag;
  363. void doConstruct ( );
  364. public:
  365. BMMExport BitmapInfo ( );
  366. BMMExport BitmapInfo ( TCHAR *n );
  367. BMMExport ~BitmapInfo ( );
  368. //-- Bitmap Flags
  369. BMMExport DWORD Flags ( ) { return (flags); }
  370. BMMExport DWORD SetFlags ( DWORD f ) { flags |= f; return (flags); }
  371. BMMExport DWORD ResetFlags ( DWORD f ) { flags &= ~f; return (flags); }
  372. BMMExport BOOL TestFlags ( DWORD f ) { return (flags & f); }
  373. //-- Generic Read
  374. BMMExport WORD Width ( ) { return (width); }
  375. BMMExport WORD Height ( ) { return (height); }
  376. BMMExport float Gamma ( ) { return (gamma); }
  377. BMMExport float Aspect ( ) { return (aspect);}
  378. BMMExport int Type ( ) { return (type); }
  379. BMMExport int FirstFrame ( ) { return (fstart); }
  380. BMMExport int LastFrame ( ) { return (fend); }
  381. BMMExport int NumberFrames ( ) { return (fend - fstart + 1); }
  382. BMMExport int CurrentFrame ( ) { return (fnumber); }
  383. BMMExport WORD SequenceOutBound ( ) { return (loopflag); }
  384. //-- "Name" returns full path of image file
  385. BMMExport const TCHAR *Name ( ) { return (const TCHAR *)name; }
  386. //-- "Filename" returns just the name of image file
  387. BMMExport const TCHAR *Filename ( );
  388. //-- "Device" is the device reponsible for producing this image.
  389. // For file types, this is just informative. For non file types
  390. // this is the way this image is identified. Therefore, it is
  391. // important to save both name and device in order to properly
  392. // identify an image.
  393. BMMExport const TCHAR *Device ( ) { return (const TCHAR *)device; }
  394. //-- Compare Two Bitmaps
  395. BMMExport BOOL CompareName ( BitmapInfo *bi );
  396. //-- Copy Image info. Only name, device and image characteristics are
  397. // copied. User info, such as Custom Width, etc. is not copied.
  398. BMMExport void CopyImageInfo ( BitmapInfo *from );
  399. //-- Generic Write
  400. BMMExport int SetFirstFrame ( int m ) { int o = fstart; fstart = m; return (o);}
  401. BMMExport int SetLastFrame ( int s ) { int o = fend; fend = s; return (o);}
  402. BMMExport int SetCurrentFrame ( int v ) { int o = fnumber; fnumber = v; return (o);}
  403. BMMExport WORD SetSequenceOutBound ( WORD c ) { WORD o = loopflag; loopflag = c; return (o);}
  404. BMMExport WORD SetWidth ( WORD s ) { WORD o = width; width = s; return (o);}
  405. BMMExport WORD SetHeight ( WORD u ) { WORD o = height; height = u; return (o);}
  406. BMMExport float SetGamma ( float c ) { float o = gamma; gamma = c; return (o);}
  407. BMMExport float SetAspect ( float k ) { float o = aspect; aspect = k; return (o);}
  408. BMMExport int SetType ( int s ) { int o = type; type = s; return (o);}
  409. BMMExport const TCHAR *SetName ( const TCHAR *n );
  410. BMMExport const TCHAR *SetDevice ( const TCHAR *d );
  411. //-- Custom Input Processing
  412. BMMExport WORD CustWidth ( ) { return (cwidth); }
  413. BMMExport WORD CustHeight ( ) { return (cheight); }
  414. BMMExport void SetCustWidth ( WORD w ) { cwidth = w; }
  415. BMMExport void SetCustHeight ( WORD h ) { cheight = h; }
  416. BMMExport int StartFrame ( ) { return (start); }
  417. BMMExport int EndFrame ( ) { return (end); }
  418. BMMExport void SetStartFrame ( int s ) { start = s; }
  419. BMMExport void SetEndFrame ( int e ) { end = e; }
  420. BMMExport void SetCustomX ( int x ) { custxpos = x; }
  421. BMMExport void SetCustomY ( int y ) { custypos = y; }
  422. BMMExport int GetCustomX ( ) { return custxpos; }
  423. BMMExport int GetCustomY ( ) { return custypos; }
  424. BMMExport void SetCustomGamma ( float g ) { custgamma = g; }
  425. BMMExport float GetCustomGamma ( ) { return custgamma; }
  426. BMMExport void SetCustomStep ( int s ) { step = s; }
  427. BMMExport int GetCustomStep ( ) { return step; }
  428. BMMExport void SetPresetAlignment ( int p ) { preset_al = p; }
  429. BMMExport int GetPresetAlignment ( ) { return preset_al; }
  430. //-- Custom Input Flags
  431. BMMExport DWORD GetCustomFlags ( ) { return (customflags); }
  432. BMMExport void SetCustomFlag ( DWORD f ) { customflags |= f; }
  433. BMMExport void ResetCustomFlag ( DWORD f ) { customflags &= ~f; }
  434. BMMExport BOOL TestCustomFlags ( DWORD f ) { return (customflags & f); }
  435. //-- Plug-In Parameter Block
  436. BMMExport void *GetPiData ( ) { return pidata; }
  437. BMMExport void SetPiData ( void *ptr ) { pidata = ptr; }
  438. BMMExport DWORD GetPiDataSize ( ) { return pisize; }
  439. BMMExport void SetPiDataSize ( DWORD s ) { pisize = s; }
  440. BMMExport void ResetPiData ( );
  441. BMMExport BOOL AllocPiData ( DWORD size );
  442. BMMExport void Copy ( BitmapInfo *from ); //\\-- OBSOLETE --\\//
  443. BMMExport BitmapInfo &operator= ( BitmapInfo &from );
  444. //-- Load/Save
  445. BMMExport IOResult Save ( ISave *isave );
  446. BMMExport IOResult Load ( ILoad *iload );
  447. BMMExport void EnumAuxFiles ( NameEnumCallback& nameEnum, DWORD flags);
  448. //-- Miscelaneous
  449. BMMExport BOOL Validate ( );
  450. BMMExport HWND GetUpdateWindow ( ) { return hWnd; }
  451. BMMExport void SetUpdateWindow ( HWND hwnd ) { hWnd = hwnd; }
  452. BMMExport DWORD GetGChannels ( );
  453. BMMExport DWORD GetDeviceFlags ( );
  454. };
  455. //-----------------------------------------------------------------------------
  456. //-- Bitmap I/O Class
  457. //
  458. // None of these methods are to be used directly. Use the BitmapManager for
  459. // any image I/O.
  460. //
  461. class BitmapIO {
  462. private:
  463. UWORD* outputGammaTab; // this may be owned by gammaMgr
  464. UWORD* privGammaTab; // private gamma table owned by the BitmapIO.
  465. protected:
  466. float gamma;
  467. Bitmap *map; // The bitmap using this OUTPUT handler
  468. BitmapStorage *storage; // The storage used by this INPUT handler
  469. int openMode; // See above
  470. //-- Linked list pointers for multiple output of a single bitmap
  471. BitmapIO *prevIO;
  472. BitmapIO *nextIO;
  473. public:
  474. // Used by the subclassed BitmapIO's to get pixels for output with
  475. // the appropriate output gamma correction.
  476. BMMExport int GetOutputPixels ( int x,int y,int pixels,BMM_Color_64 *ptr);
  477. // Used by the subclassed BitmapIO's to get 32 bit pixels for output with
  478. // the appropriate output gamma correction and dither.
  479. BMMExport int GetDitheredOutputPixels ( int x,int y,int pixels,BMM_Color_32 *ptr);
  480. // Used by the subclassed BitmapIO's to get a DIB for output with
  481. // the appropriate output gamma correction.
  482. BMMExport PBITMAPINFO GetOutputDib ( int depth = 24 );
  483. // Used by the subclassed BitmapIO's to get a DIB for output with
  484. // the appropriate output gamma correction and dither
  485. BMMExport PBITMAPINFO GetDitheredOutputDib ( int depth = 24 );
  486. BMMExport float OutputGamma();
  487. // If a BitmapIO wants to do its own dithering, it should call
  488. // these to find out if dithering is wanted. If it is a 24 bit or
  489. // 32 bit format, it would usually just call GetDitheredOutputPixels instead.
  490. BMMExport BOOL DitherTrueColor();
  491. BMMExport BOOL DitherPaletted();
  492. // Calculate a color palette for output color packing: gamma corrects
  493. BMMExport int CalcOutputPalette(int palsize, BMM_Color_48 *pal);
  494. BMMExport BitmapIO ( );
  495. bVirtual ~BitmapIO ( );
  496. BitmapInfo bi;
  497. inline int OpenMode ( ) { return (openMode); }
  498. inline void SetPrev ( BitmapIO *prev) { prevIO = prev; };
  499. inline void SetNext ( BitmapIO *next) { nextIO = next; };
  500. inline BitmapIO *Prev ( ) { return prevIO; };
  501. inline BitmapIO *Next ( ) { return nextIO; };
  502. BMMExport BitmapStorage *Storage ( );
  503. inline Bitmap *Map ( ) { return map; };
  504. bVirtual int ExtCount ( ) = 0; // Number of extemsions supported
  505. bVirtual const TCHAR *Ext ( int n ) = 0; // Extension #n (i.e. "3DS")
  506. bVirtual const TCHAR *LongDesc ( ) = 0; // Long ASCII description (i.e. "Targa 2.0 Image File")
  507. bVirtual const TCHAR *ShortDesc ( ) = 0; // Short ASCII description (i.e. "Targa")
  508. bVirtual const TCHAR *AuthorName ( ) = 0; // ASCII Author name
  509. bVirtual const TCHAR *CopyrightMessage ( ) = 0; // ASCII Copyright message
  510. bVirtual UINT Version ( ) = 0; // Version number * 100 (i.e. v3.01 = 301)
  511. bVirtual int Capability ( ) = 0; // Returns IO module ability flags (see above)
  512. bVirtual void ShowAbout ( HWND hWnd ) = 0; // Show DLL's "About..." box
  513. //-- If the BMMIO_OWN_VIEWER flag is set, this method will be called
  514. // whenever the user wants to view an image for this device. This
  515. // is for devices which can "play" image sequences such as AVI's, FLIC's, etc.
  516. //-- TH 2/26/96 -- Added BOOL return to indicate if view worked. If it didn't,
  517. // it returns FALSE and the caller can view by the normal mechanism.
  518. bVirtual BOOL ShowImage ( HWND hWnd, BitmapInfo *bi ) { return FALSE; }
  519. //-- Show DLL's Control Panel
  520. //
  521. // If the user exists through an Ok, this function will return TRUE.
  522. // If the user cancels out, it will return FALSE. False indicates
  523. // nothing has changed so the system won't bother asking the plug-in
  524. // if it wants to save data.
  525. //
  526. // This function is only called if the plug-in has defined it supports
  527. // it (through the Capability flag above). The flag will indicate to
  528. // the plug-in what operation is this control for (read, write, or
  529. // generic).
  530. //
  531. bVirtual BOOL ShowControl ( HWND hWnd, DWORD flag ) { return FALSE; }
  532. //-- Parameter Block Load and Save ------------------------------------
  533. //
  534. // The host will call EvaluateConfigure() to determine the buffer size
  535. // required by the plug-in.
  536. //
  537. // SaveConfigure() will be called so the plug-in can transfer its
  538. // parameter block to the host ( ptr is a pre-allocated buffer).
  539. //
  540. // LoadConfigure() will be called so the plug-in can load its
  541. // parameter block back.
  542. //
  543. // Memory management is performed by the host using standard
  544. // LocalAlloc() and LocalFree().
  545. //
  546. bVirtual DWORD EvaluateConfigure ( ) = 0;
  547. bVirtual BOOL LoadConfigure ( void *ptr ) = 0;
  548. bVirtual BOOL SaveConfigure ( void *ptr ) = 0;
  549. //-- Used internaly to make sure current block belongs to Plug-In
  550. bVirtual BOOL ValidatePiData ( BitmapInfo *bi );
  551. //-- System Interface
  552. BMMExport BOOL SilentMode ( );
  553. //-- Calculate Desired Frame
  554. //
  555. // This is for multiframe sequences. It processes the desired frame
  556. // based on user options. It is used at the Load() function to find
  557. // out which frame to load.
  558. //
  559. // "fbi" is the one passed to Load()
  560. // "frame" is a pointer to an integer to receive the frame number
  561. BMMExport BMMRES GetFrame ( BitmapInfo *fbi, int *frame);
  562. //-- Critical Error Handling
  563. BMMExport BMMRES ProcessImageIOError ( BitmapInfo *bi, TCHAR *string = NULL);
  564. BMMExport BMMRES ProcessImageIOError ( BitmapInfo *bi, int errorcode);
  565. //---------------------------------------------------------------------
  566. //-- Channels Required (for Output)
  567. //
  568. // By setting this flag, the plug-in can request the host to generate
  569. // the given channels. Prior to Rendering, the host will scan the
  570. // plug-ins in the chain of events and list all types of channels
  571. // being requested. The plug-in, at the time of the Write() call, will
  572. // have access to these channels through the channel interface
  573. // described below in BitmapStorage().
  574. //
  575. // The generation of these channels should not, normally, be a
  576. // default setting for a plug-in. These channels are memory hungry and
  577. // if the plug-in won't use it, it should not ask for it. Normally
  578. // the plug-in would ask the user which channels to save and set only
  579. // the proper flags.
  580. //
  581. bVirtual DWORD ChannelsRequired ( ) { return BMM_CHAN_NONE; }
  582. //-- Image Info
  583. bVirtual BMMRES GetImageInfoDlg ( HWND hWnd, BitmapInfo *bi, const TCHAR *filename = NULL ) {return BMMRES_NODRIVER;}
  584. bVirtual BMMRES GetImageInfo ( BitmapInfo *bi ) = 0;
  585. //-- Image File Loaders (IFL handlers)
  586. bVirtual BMMRES GetImageName ( BitmapInfo *bi, TCHAR *filename) {filename[0]=0; return (BMMRES_SUCCESS);}
  587. //-- Image I/O (Not to use directly)
  588. bVirtual BitmapStorage *Load ( BitmapInfo *bi, Bitmap *map, BMMRES *status ) = 0;
  589. bVirtual BMMRES OpenOutput ( BitmapInfo *bi, Bitmap *map );
  590. bVirtual BMMRES Write ( int frame );
  591. bVirtual int Close ( int flag );
  592. bVirtual PAVIFILE GetPaviFile ( ) { return NULL; }
  593. // used internally to build output gamma table
  594. BMMExport void InitOutputGammaTable(BitmapInfo*bi);
  595. };
  596. //-----------------------------------------------------------------------------
  597. //-- Bitmap Storage Class
  598. //
  599. // None of these methods are to be used directly. Use the Bitmap class for
  600. // any image read/write.
  601. //
  602. //-- Channel Operations (for Get/Put16Channel)
  603. #define BMM_CHANNEL_RED 0 //-- Get/Put only Red
  604. #define BMM_CHANNEL_GREEN 1 //-- Get/Put only Green
  605. #define BMM_CHANNEL_BLUE 3 //-- Get/Put only Blue
  606. #define BMM_CHANNEL_ALPHA 4 //-- Get/Put only Alpha
  607. #define BMM_CHANNEL_Z 5 //-- Get/Put only Z
  608. #define BMM_CHANNEL_LUMINANCE 6 //-- Get (R+G+B)/3
  609. class BitmapStorage {
  610. protected:
  611. int openMode; // See above
  612. UINT usageCount; // Number of Bitmaps using this storage
  613. BitmapManager *manager;
  614. int flags;
  615. int type; // See "Basic bitmap types", below
  616. BMM_Color_48 palette[256]; // 256 palette entries max
  617. int paletteSlots;
  618. UWORD *gammaTable; // Gamma correction table
  619. RenderInfo *rendInfo;
  620. public:
  621. BMMExport BitmapStorage ( );
  622. bVirtual ~BitmapStorage ( );
  623. BitmapInfo bi;
  624. // gamma
  625. BMMExport float SetGamma(float gam);
  626. inline int HasGamma ( ) { return (gammaTable!=NULL) ? 1:0; };
  627. BMMExport void SetHasGamma(BOOL onOff);
  628. void UpdateGammaTable();
  629. BMMExport UWORD *GetInputGammaTable();
  630. inline BitmapManager *Manager ( ) { return manager; }
  631. inline int OpenMode ( ) { return openMode; }
  632. inline int Width ( ) { return bi.Width(); }
  633. inline int Height ( ) { return bi.Height(); }
  634. inline float Aspect ( ) { return bi.Aspect(); }
  635. inline float Gamma ( ) { return bi.Gamma(); }
  636. inline int Paletted ( ) { return (flags & MAP_PALETTED) ? paletteSlots:0; }
  637. inline int IsDithered ( ) { return (flags & MAP_DITHERED) ? 1:0; };
  638. inline int PreMultipliedAlpha ( ) { return (flags & MAP_ALPHA_PREMULTIPLIED) ? 1:0; };
  639. inline int HasAlpha ( ) { return (flags & MAP_HAS_ALPHA) ? 1:0; };
  640. inline int UsageCount ( ) { return usageCount; };
  641. inline int Type ( ) { return type; };
  642. inline int Flags ( ) { return flags; };
  643. inline void SetFlags ( DWORD f ) { flags |= f; }
  644. bVirtual int MaxRGBLevel ( ) = 0;
  645. bVirtual int MaxAlphaLevel ( ) = 0;
  646. //-- Scaling Tools
  647. bVirtual void Scale ( WORD *, int, WORD *, int );
  648. bVirtual BOOL GetSRow ( WORD *, int, WORD *, int );
  649. bVirtual BOOL PutSRow ( WORD *, int, WORD *, int );
  650. bVirtual BOOL GetSCol ( WORD *, WORD *, int, int );
  651. bVirtual BOOL PutSCol ( WORD *, WORD *, int, int );
  652. bVirtual BOOL ScaleY ( Bitmap *, BMM_Color_64 *, WORD *, WORD *, HWND, int cw = 0, int ch = 0 );
  653. bVirtual BOOL ScaleX ( Bitmap *, BMM_Color_64 *, WORD *, WORD *, HWND, int cw = 0, int ch = 0 );
  654. //-- This method will try to get a pointer to the begining of the image
  655. // storage. Not all storage types can return a valid pointer. In those
  656. // cases, this call will fail and the user should use some other method
  657. // described below (GG);
  658. //
  659. bVirtual void *GetStoragePtr ( int *type ) { *type = BMM_NO_TYPE; return (NULL); }
  660. //-- These methods will handle a single, 16 bit channel. See BMM_CHANNEL above
  661. // for the different options (GG)
  662. // bVirtual int Get16Channel ( int x,int y,int pixels,unsigned short *ptr, int channel) = 0;
  663. // bVirtual int Put16Channel ( int x,int y,int pixels,unsigned short *ptr, int channel) = 0;
  664. //-- These are the standard methods for accessing image pixels
  665. bVirtual int Get16Gray ( int x,int y,int pixels,WORD *ptr) = 0;
  666. bVirtual int Put16Gray ( int x,int y,int pixels,WORD *ptr) = 0;
  667. bVirtual int GetLinearPixels ( int x,int y,int pixels,BMM_Color_64 *ptr) = 0;
  668. bVirtual int GetPixels ( int x,int y,int pixels,BMM_Color_64 *ptr) = 0;
  669. bVirtual int PutPixels ( int x,int y,int pixels,BMM_Color_64 *ptr) = 0;
  670. bVirtual int GetIndexPixels ( int x,int y,int pixels,unsigned char *ptr) = 0;
  671. bVirtual int PutIndexPixels ( int x,int y,int pixels,unsigned char *ptr) = 0;
  672. bVirtual int CropImage ( int width,int height,BMM_Color_64 fillcolor) = 0;
  673. bVirtual int CropImage ( int width,int height,int fillindex) = 0;
  674. bVirtual int ResizeImage ( int width,int height,int newpalette) = 0;
  675. bVirtual int CopyCrop ( Bitmap *from, BMM_Color_64 fillcolor );
  676. bVirtual int CopyScaleLow ( Bitmap *from );
  677. bVirtual int CopyScaleHigh ( Bitmap *from, HWND hWnd, BMM_Color_64 **buf = NULL, int w=0, int h=0 );
  678. bVirtual int CopyImage ( Bitmap *from,int operation,BMM_Color_64 fillcolor, BitmapInfo *bi = NULL);
  679. bVirtual int CopyImage ( Bitmap *from,int operation,int fillindex);
  680. bVirtual int GetPalette ( int start,int count,BMM_Color_48 *ptr) = 0;
  681. bVirtual int SetPalette ( int start,int count,BMM_Color_48 *ptr) = 0;
  682. bVirtual int GetFiltered ( float u,float v,float du,float dv,BMM_Color_64 *ptr) = 0;
  683. //-- User Interface
  684. bVirtual int Allocate ( BitmapInfo *bi,BitmapManager *manager,int openMode) = 0;
  685. bVirtual int Connect ( ) = 0;
  686. bVirtual int Disconnect ( ) = 0;
  687. bVirtual int MapReady ( ) = 0;
  688. bVirtual int ClosestColor ( BMM_Color_48 color);
  689. bVirtual int ClosestColor ( int r,int g,int b);
  690. // GBuffer methods ----------------------
  691. // get a pointer to specified channel: also determine its type for check
  692. bVirtual void* GetChannel(ULONG channelID, ULONG& chanType) { return NULL;}
  693. // create the specified channels -- return channels present:
  694. bVirtual ULONG CreateChannels(ULONG channelIDs) { return 0;}
  695. // delete all the channels in channelIDs
  696. bVirtual void DeleteChannels(ULONG channelIDs) {}
  697. // query which channels are present
  698. bVirtual ULONG ChannelsPresent() { return 0; }
  699. // For output bitmaps, can get RenderInfo, which is written by the
  700. // renderer
  701. // AllocRenderInfo will alloc only if RenderInfo doesn't yet exist.
  702. BMMExport RenderInfo* AllocRenderInfo();
  703. // GetRenderInfo just hands back RenderInfo pointer
  704. BMMExport RenderInfo* GetRenderInfo();
  705. };
  706. //-----------------------------------------------------------------------------
  707. //-- Bitmap Filter Class
  708. //
  709. // Private class not to be documented
  710. //
  711. class BitmapFilter {
  712. protected:
  713. UINT usageCount; // Number of Bitmaps using this storage
  714. BitmapManager *manager; // Pointer to bitmap manager
  715. BitmapStorage *storage; // Pointer to storage itself
  716. DWORD flags; // Filter flags
  717. int dirty; // Needs updating flag
  718. UINT type; // Type index of filter
  719. public:
  720. BMMExport BitmapFilter();
  721. bVirtual ~BitmapFilter();
  722. inline DWORD Flags ( ) { return flags; };
  723. inline void SetFlag ( DWORD flag) { flags |= flag; dirty = 1; };
  724. inline void ToggleFlag ( DWORD flag) { flags ^= flag; dirty = 1; };
  725. inline void ClearFlag ( DWORD flag) { flags &= (~flag); dirty = 1; };
  726. inline UINT Type ( ) { return type; };
  727. inline void SetType ( UINT t) { type = t; };
  728. BMMExport int Initialize ( BitmapManager *m,BitmapStorage *s);
  729. virtual int GetFiltered ( float u,float v,float du,float dv,BMM_Color_64 *ptr) = 0;
  730. virtual void Free ( ) {};
  731. BMMExport int Connect ( );
  732. BMMExport int Disconnect ( );
  733. BMMExport int SetStorage ( BitmapStorage *storage);
  734. inline BitmapStorage *GetStorage ( ) { return storage; };
  735. inline void MakeDirty ( ) { dirty = 1; };
  736. };
  737. //-----------------------------------------------------------------------------
  738. //-- Bitmap Dither Class
  739. //
  740. // Private class not to be documented
  741. class BitmapDither {
  742. protected:
  743. BitmapStorage *storage; // Pointer to storage itself
  744. int type; // Type index of filter
  745. public:
  746. BMMExport BitmapDither ( );
  747. bVirtual ~BitmapDither ( );
  748. inline UINT Type ( ) { return type; };
  749. inline void SetType ( UINT t) { type = t; };
  750. BMMExport int Initialize ( BitmapStorage *s);
  751. virtual int PutPixels ( int x,int y,int pixels,BMM_Color_64 *ptr) = 0;
  752. virtual void Free ( ) {};
  753. BMMExport int SetStorage ( BitmapStorage *storage);
  754. };
  755. //-----------------------------------------------------------------------------
  756. //-- Bitmap Picker Class
  757. //
  758. /*
  759. class BitmapPicker {
  760. protected:
  761. BitmapManager *manager;
  762. public:
  763. bVirtual BitmapPicker ( ) {};
  764. bVirtual ~BitmapPicker ( ) {};
  765. bVirtual SetManager ( BitmapManager *m ) { manager = m; }
  766. bVirtual BitmapManager *GetManager ( ) { return (manager); }
  767. bVirtual BOOL ImageInputOptions ( BitmapInfo *bi, HWND hWnd )=0;
  768. bVirtual BOOL SelectDeviceInput ( BitmapInfo *bi, HWND hWnd )=0;
  769. bVirtual BOOL SelectDeviceOutput ( BitmapInfo *bi, HWND hWnd )=0;
  770. bVirtual BOOL SelectFileOutput ( BitmapInfo *bi,
  771. HWND hWnd,
  772. TCHAR *title = NULL)=0;
  773. bVirtual BOOL SelectFileInput ( BitmapInfo *bi,
  774. HWND hWnd,
  775. TCHAR *title = NULL)=0;
  776. bVirtual BOOL SelectFileInputEx ( BitmapInfo *bi,
  777. HWND hWnd,
  778. TCHAR *title = NULL)=0;
  779. };
  780. */
  781. //-----------------------------------------------------------------------------
  782. //-- Basic Bitmap Class
  783. //
  784. //
  785. #define BMM_SINGLEFRAME -2000000L
  786. class Bitmap {
  787. private:
  788. DWORD flags; // See above
  789. BitmapManager *manager; // Manager of this bitmap
  790. BitmapIO *output; // Head of output handler list
  791. BitmapFilter *filter; // Filtered access methods
  792. BitmapDither *dither; // Dither methods
  793. BitmapStorage *storage; // Actual storage
  794. ICustToolbar *iTool; // Display Window Toolbar
  795. HWND hWnd,hTool; // Window handle (Display and Toolbar)
  796. UINT filterType; // Filtered access type
  797. UINT ditherType; // Dither type
  798. int currentBits; // Device Context NUMBITS (Display())
  799. int Free();
  800. HWND hList;
  801. ICustButton *iR,*iG,*iB,*iA;
  802. ICustStatus *iText;
  803. ICustButton *iClear,*iSave;
  804. TCHAR curTitle[128];
  805. int curPosition;
  806. int bitx,bity;
  807. BOOL autonomous;
  808. //-- Channel Display in VFB
  809. #define BMM_MASK_R 0x1
  810. #define BMM_MASK_G 0x2
  811. #define BMM_MASK_B 0x4
  812. #define BMM_MASK_A 0x8
  813. #define BMM_MODE_RGBA 0
  814. #define BMM_MODE_Z 1
  815. #define BMM_MODE_MTL 2
  816. #define BMM_MODE_NODE 3
  817. #define BMM_MODE_UV 4
  818. #define BMM_MODE_NORMAL 5
  819. #define BMM_MODE_NONCLAMP 6
  820. WORD channelMode;
  821. WORD channelMask;
  822. friend LRESULT CALLBACK InputWndProc ( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
  823. public:
  824. BMMExport Bitmap ( BitmapManager *manager = TheManager );
  825. BMMExport ~Bitmap ( );
  826. inline BitmapManager *Manager ( ) { return manager; };
  827. //-- Don't use these unless you know what you're doing ----------------
  828. BMMExport int Create ( BitmapInfo *bi );
  829. BMMExport BOOL FixDeviceName ( BitmapInfo *bi );
  830. inline int MapReady ( ) { if (storage) return storage->MapReady(); return 0; };
  831. BMMExport void AddOutput ( BitmapIO *out );
  832. BMMExport void RemoveOutput ( BitmapIO *out );
  833. BMMExport BitmapIO * FindOutput ( BitmapInfo *bi );
  834. BMMExport PAVIFILE GetPaviFile ( BitmapInfo *bi );
  835. //-- Display Bitmap (Data and Methods) - Internal Use Only ------------
  836. HDRAWDIB dispHDR;
  837. HANDLE dispDIB;
  838. LRESULT Command ( WORD notify, WORD id, HWND hCtrl );
  839. LRESULT WMNotify ( LPNMHDR hdr );
  840. LRESULT BimpWndProc ( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  841. void UpdateToolBar ( );
  842. BOOL InitBuffer ( );
  843. BOOL VfbFit ( int *w, int *h );
  844. //-- Public Interface -------------------------------------------------
  845. inline DWORD Flags ( ) { return flags; };
  846. inline void SetFlag ( DWORD flag ) { flags |= flag; };
  847. inline void ToggleFlag ( DWORD flag ) { flags ^= flag; };
  848. inline void ClearFlag ( DWORD flag ) { flags &= (~flag); };
  849. inline int Width ( ) { if (storage) return storage->Width(); return 0; };
  850. inline int Height ( ) { if (storage) return storage->Height(); return 0; };
  851. inline float Aspect ( ) { if (storage) return storage->Aspect(); return (float)0.0; };
  852. inline float Gamma ( ) { if (storage) return storage->Gamma(); return (float)0.0; };
  853. inline int Paletted ( ) { if (storage) return storage->Paletted(); return 0; };
  854. inline int IsDithered ( ) { if (storage) return storage->IsDithered(); return 0; };
  855. inline int PreMultipliedAlpha ( ) { if (storage) return storage->PreMultipliedAlpha(); return 0; };
  856. inline int HasAlpha ( ) { if (storage) return storage->HasAlpha(); return 0; };
  857. inline int MaxRGBLevel ( ) { if (storage) return storage->MaxRGBLevel(); return 0; };
  858. inline int MaxAlphaLevel ( ) { if (storage) return storage->MaxAlphaLevel(); return 0; };
  859. int Put16Gray ( int x,int y,int pixels,WORD *ptr )
  860. { if (storage) return storage->Put16Gray(x,y,pixels,ptr); return 0; };
  861. inline void *GetStoragePtr ( int *type )
  862. { if (storage) return storage->GetStoragePtr(type); return NULL; };
  863. inline int Get16Gray ( int x,int y,int pixels,WORD *ptr )
  864. { if (storage) return storage->Get16Gray(x,y,pixels,ptr); return 0; };
  865. inline int GetPixels ( int x,int y,int pixels,BMM_Color_64 *ptr )
  866. { if (storage) return storage->GetPixels(x,y,pixels,ptr); return 0; };
  867. BMMExport int PutPixels ( int x,int y,int pixels,BMM_Color_64 *ptr );
  868. inline int GetLinearPixels ( int x,int y,int pixels,BMM_Color_64 *ptr )
  869. { if (storage) return storage->GetLinearPixels(x,y,pixels,ptr); return 0; };
  870. inline int GetIndexPixels ( int x,int y,int pixels,BYTE *ptr )
  871. { if (storage) return storage->GetIndexPixels(x,y,pixels,ptr); return 0; };
  872. inline int PutIndexPixels ( int x,int y,int pixels,BYTE *ptr )
  873. { if (storage) return storage->PutIndexPixels(x,y,pixels,ptr); return 0; };
  874. inline int CropImage ( int width,int height,BMM_Color_64 fillcolor)
  875. { if (storage) return storage->CropImage(width,height,fillcolor); return 0; };
  876. inline int CropImage ( int width,int height,int fillindex)
  877. { if (storage) return storage->CropImage(width,height,fillindex); return 0; };
  878. inline int ResizeImage ( int width,int height,int newpalette)
  879. { if (storage) return storage->ResizeImage(width,height,newpalette);return 0; };
  880. inline int CopyImage ( Bitmap *from,int operation,BMM_Color_64 fillcolor, BitmapInfo *bi = NULL)
  881. { if (storage) return storage->CopyImage(from,operation,fillcolor,bi); return 0; };
  882. inline int CopyImage ( Bitmap *from,int operation,int fillindex)
  883. { if (storage) return storage->CopyImage(from,operation,fillindex); return 0; };
  884. inline int GetPalette ( int start,int count,BMM_Color_48 *ptr)
  885. { if (storage) return storage->GetPalette(start,count,ptr); return 0; };
  886. inline int SetPalette ( int start,int count,BMM_Color_48 *ptr)
  887. { if (storage) return storage->SetPalette(start,count,ptr); return 0; };
  888. // GBuffer methods ---------------------
  889. inline void *GetChannel ( ULONG channelID, ULONG& chanType )
  890. { if (storage) return storage->GetChannel(channelID, chanType); return NULL; }
  891. inline ULONG CreateChannels ( ULONG channelIDs )
  892. { if (storage) return storage->CreateChannels(channelIDs); return 0; }
  893. inline void DeleteChannels ( ULONG channelIDs )
  894. { if (storage) storage->DeleteChannels(channelIDs); }
  895. inline ULONG ChannelsPresent ( )
  896. { if (storage) return storage->ChannelsPresent(); return 0; }
  897. inline RenderInfo* GetRenderInfo() { if (storage) return storage->GetRenderInfo(); return NULL; }
  898. inline RenderInfo* AllocRenderInfo() { if (storage) return storage->AllocRenderInfo(); return NULL; }
  899. //---------------------------------------------------------------------
  900. //
  901. // This call will check with the plug-in (file or device) defined in
  902. // the given BitmapInfo and prepare (create) the proper channels. If
  903. // a given channel already exists, no new channel will be created.
  904. //
  905. // After creating a bitmap, use this function to define the optional
  906. // channels that may be required by the given handler.
  907. //
  908. BMMExport BOOL PrepareGChannels ( BitmapInfo *bi );
  909. BMMExport BOOL PrepareGChannels ( DWORD channels );
  910. BMMExport int GetFiltered ( float u,float v,float du,float dv,BMM_Color_64 *ptr );
  911. BMMExport int SetDither ( UINT ditherType );
  912. BMMExport int SetFilter ( UINT filterType );
  913. inline int HasFilter ( ) { return (filter) ? 1:0; };
  914. inline BitmapFilter *Filter ( ) { return filter; };
  915. BMMExport int SetStorage ( BitmapStorage *storage);
  916. inline BitmapStorage *Storage ( ) { return storage; };
  917. inline void NullStorage ( ) { storage = NULL; };
  918. //-- Windows DIB Conversion -------------------------------------------
  919. //
  920. // Where depth is either 24 (BGR) or 32 (BGR0)
  921. //
  922. BMMExport PBITMAPINFO ToDib ( int depth = 24, UWORD *gam=NULL, BOOL dither=FALSE);
  923. //-- Do not use this directly. Instead, use BitmapManager::Create(PBITMAPINFO)
  924. BMMExport BOOL FromDib ( PBITMAPINFO pbmi );
  925. //-- Image output operations ------------------------------------------
  926. //
  927. // To write a single image to a file/device:
  928. //
  929. // *> Create BitmapInfo class: BitmapInfo bi;
  930. //
  931. // *> Define output file/device:
  932. //
  933. // Directly: bi.SetName("file.tga");
  934. // or
  935. // User Interface: BitmapManager::SelectFileOutput( ... &bi ...)
  936. //
  937. // *> Define bitmap:
  938. //
  939. // bi.SetWidth(x)
  940. // bi.SetHeight(y)
  941. // etc...
  942. //
  943. // *> Create bitmap: Bitmap *map = BitmapManager::Create(&bi);
  944. //
  945. //
  946. // *> Do something: map->Fill({0,0,0});
  947. //
  948. // *> OpenOutput: map->OpenOutput(&bi);
  949. //
  950. // *> Write: map->Write(&bi)
  951. //
  952. // *> Close: map->Close(&bi)
  953. //
  954. // To write a multiframe file, just keep doing something different to
  955. // the bimap and keep writting.
  956. //
  957. // To write a sequence of images to a file/device:
  958. //
  959. // *> Create BitmapInfo class: BitmapInfo bi;
  960. //
  961. // *> Define output file/device:
  962. //
  963. // Directly: bi.SetName("file.tga");
  964. // or
  965. // User Interface: BitmapManager::SelectFileOutput( ... &bi ...)
  966. //
  967. // *> Define bitmap:
  968. //
  969. // bi.SetWidth(x)
  970. // bi.SetHeight(y)
  971. //
  972. // bi.SetFirstFrame(0)
  973. // bi.SetLastFrame(29)
  974. //
  975. // etc...
  976. //
  977. // *> Create bitmap: Bitmap *map = BitmapManager::Create(&bi);
  978. //
  979. //
  980. // *> OpenOutput: map->OpenOutput(&bi);
  981. //
  982. // for (x = 0 to 29) {
  983. // *> Do something to image...
  984. // *> Write: map->Write(&bi,x);
  985. // }
  986. //
  987. // *> Close: map->Close(&bi)
  988. //
  989. //
  990. // Note: You can add any number of outputs to a bitmap. Just keep
  991. // calling map->OpenInput() with different outputs (Targa file AND
  992. // Frame Buffer for instance). To write or close a specific output,
  993. // use Write() and Close(). To write and close them all at once,
  994. // use WriteAll() and CloseAll().
  995. //
  996. // It is ok to use WriteAll() and CloseAll() if you have just one
  997. // output defined.
  998. //
  999. BMMExport BMMRES OpenOutput ( BitmapInfo *bi ); // Open output
  1000. BMMExport BMMRES Write ( BitmapInfo *bi, int frame = BMM_SINGLEFRAME ); // Write frame to file
  1001. BMMExport BMMRES WriteAll ( int frame = BMM_SINGLEFRAME ); // Write all open outputs
  1002. BMMExport int Close ( BitmapInfo *bi, int flag = BMM_CLOSE_COMPLETE ); // Close an open output
  1003. BMMExport int CloseAll ( int flag = BMM_CLOSE_COMPLETE); // Close all open outputs
  1004. //-- Window gravity
  1005. #define BMM_UL 1 //-- Upper Left
  1006. #define BMM_LL 2 //-- Lower Left
  1007. #define BMM_UR 3 //-- Upper Right
  1008. #define BMM_LR 4 //-- Upper Left
  1009. #define BMM_CN 5 //-- Center
  1010. #define BMM_RND 10 //-- Renderer (Save/Restore)
  1011. #define BMM_VPP 11 //-- Video Post Primary (Save/Restore)
  1012. #define BMM_VPS 12 //-- Video Post Secondary (Save/Restore)
  1013. BMMExport int Display ( TCHAR *title = NULL, int position = BMM_CN, BOOL autonomous = FALSE );
  1014. BMMExport int UnDisplay ( );
  1015. BMMExport HWND GetWindow ( );
  1016. BMMExport void RefreshWindow ( RECT *rect = NULL );
  1017. BMMExport void SetWindowTitle ( TCHAR *title );
  1018. //-- Get a Different Frame -------------------------------------------
  1019. //
  1020. // For multifrane bitmaps (FLI's, AVI's, DDR devices, etc.), if you
  1021. // simply want to load another frame replacing a previously "Load"ed
  1022. // image.
  1023. //
  1024. // If used with single frame drivers or if the driver doesn't support
  1025. // this function, it returns BMMRES_SINGLEFRAME. If the return value
  1026. // is BMMRES_SUCCESS, a new frame has been loaded into the given
  1027. // bitmap.
  1028. //
  1029. // To define desired frame, use bi->SetCurrentFrame( frame );
  1030. //
  1031. BMMExport BMMRES GoTo ( BitmapInfo *bi );
  1032. //-- Handy built-in functions
  1033. BMMExport int Fill ( int r,int g,int b,int alpha);
  1034. };
  1035. //-- Various Bitmap In-Memory Lists -------------------------------------------
  1036. typedef struct {
  1037. BitmapStorage *ptr;
  1038. void *next;
  1039. } BMMStorageList;
  1040. typedef struct {
  1041. BitmapFilter *ptr;
  1042. void *next;
  1043. } BMMFilterList;
  1044. typedef struct {
  1045. Bitmap *ptr;
  1046. void *next;
  1047. } BMMBitmapList;
  1048. typedef struct tag_BMMGammaSettings {
  1049. BitmapManager *mgr;
  1050. BitmapInfo *bi;
  1051. BOOL out;
  1052. } BMMGammaSettings;
  1053. typedef struct tag_BMMVfbPalette {
  1054. BYTE r,g,b;
  1055. } BMMVfbPalette;
  1056. //-----------------------------------------------------------------------------
  1057. //-- Main Bitmap Manager Class
  1058. //
  1059. class BitmapManager {
  1060. BitmapInfo *bi;
  1061. BMMInterface *iface;
  1062. Interface *max;
  1063. TCHAR name[MAX_DESCRIPTION];
  1064. BMMStorageList *storageList;
  1065. BMMFilterList *filterList;
  1066. BMMBitmapList *bitmapList;
  1067. TCHAR *windowTitle;
  1068. int storageCount;
  1069. int filterCount;
  1070. int bitmapCount;
  1071. BOOL listdevices;
  1072. BOOL viewonly;
  1073. BOOL silentmode;
  1074. DWORD loglevel;
  1075. HWND hWnd;
  1076. void DoConstruct ( BMMInterface *i, const TCHAR *n );
  1077. void BrowseInput ( HWND hWnd, TCHAR *device );
  1078. void BrowseOutput ( HWND hWnd, TCHAR *device );
  1079. public:
  1080. int channelMagn;
  1081. BMMVfbPalette *pal;
  1082. //-- Construction/Destruction
  1083. BMMExport BitmapManager ( BMMInterface *i);
  1084. BMMExport BitmapManager ( BMMInterface *i,const TCHAR *name);
  1085. BMMExport ~BitmapManager ( );
  1086. friend void DoConstruct ( BitmapManager *m, BMMInterface *i, const TCHAR *name);
  1087. //-- These are for internal use only
  1088. BMMExport int DeleteAllMaps ( );
  1089. BMMExport int AddStorage ( BitmapStorage *s);
  1090. BMMExport int AddFilter ( BitmapFilter *a);
  1091. BMMExport int AddBitmap ( Bitmap *b);
  1092. BMMExport int DelStorage ( BitmapStorage *s);
  1093. BMMExport int DelFilter ( BitmapFilter *a);
  1094. BMMExport int DelBitmap ( Bitmap *b);
  1095. BMMExport BitmapFilter *FindFilter ( BitmapStorage *s,UINT type);
  1096. BMMExport BitmapStorage *FindStorage ( BitmapInfo *bi, int openMode);
  1097. BMMExport int FnametoBitMapInfo ( BitmapInfo *bi );
  1098. BMMExport void FixFileExt ( OPENFILENAME &ofn, const TCHAR *extension);
  1099. BMMExport void MakeVfbPalette ( );
  1100. BMM_IOList ioList;
  1101. BMMExport void ListIO ( );
  1102. //-- File Read/Write Processes (internal use only)
  1103. BOOL InputOptionsControl ( HWND,UINT,WPARAM,LPARAM );
  1104. BOOL DeviceInputControl ( HWND,UINT,WPARAM,LPARAM );
  1105. BOOL DeviceOutputControl ( HWND,UINT,WPARAM,LPARAM );
  1106. BOOL ImageInfoDlg ( HWND,UINT,WPARAM,LPARAM );
  1107. BOOL BrowseFiles ( BitmapInfo *, HWND, TCHAR *);
  1108. BOOL OpenFileHook ( HWND,UINT,WPARAM,LPARAM );
  1109. BOOL WriteFileHook ( HWND,UINT,WPARAM,LPARAM );
  1110. BOOL GammaControl ( HWND,UINT,WPARAM,LPARAM, BMMGammaSettings *gs);
  1111. void BuildIFL ( BitmapInfo *bi );
  1112. //---------------------------------------------------------------------
  1113. //-- Public Interface -------------------------------------------------
  1114. //-- Host Interface
  1115. BMMExport HINSTANCE AppInst ( );
  1116. BMMExport HWND AppWnd ( );
  1117. BMMExport DllDir *AppDllDir ( );
  1118. BMMExport TCHAR *GetDir (int i);
  1119. BMMExport BOOL AddMapDir (TCHAR *dir,int update);
  1120. BMMExport int GetMapDirCount ( );
  1121. BMMExport TCHAR *GetMapDir (int i);
  1122. BMMExport Interface *Max () { return max; }
  1123. //-- These won't stay here. Error handling will be dealt in a couple of
  1124. // different ways. There will be a "Silent" flag that will be set by
  1125. // the client and tested here in order to know if an error dialog should
  1126. // go up. Normally, if the user is sitting in front of the computer
  1127. // this flag will be FALSE. When rendering in the background, or network
  1128. // rendering, etc., this flag will be TRUE. There should be some kind of
  1129. // "preferences" configuration for this behavior.
  1130. //
  1131. // There also will be a method for logging errors. This method will check
  1132. // for a "loggin on/off" flag and either add the entry or ignore it. The
  1133. // bitmap manager and its devices will log everything that goes wrong.
  1134. // When silent mode is on and logging is also on, this is the method to
  1135. // check what went bad. Having each device logging its own error will
  1136. // enable a more accurate description of the problem (as opposed to "I/O
  1137. // error").
  1138. //
  1139. // Gus
  1140. //
  1141. BMMExport int Status ( int *sCount, int *aCount, int *bCount);
  1142. BMMExport int Error ( const TCHAR *string);
  1143. //-- Error handling ---------------------------------------------------
  1144. //
  1145. //
  1146. //-- Max Interface (means no logging)
  1147. #define LG_NOLOG 0
  1148. //-- User Interface
  1149. #define LG_FATAL ((DWORD)(1 << 0))
  1150. #define LG_INFO ((DWORD)(1 << 1))
  1151. #define LG_DEBUG ((DWORD)(1 << 2))
  1152. #define LG_WARN ((DWORD)(1 << 3))
  1153. //-- User Interface
  1154. BMMExport BOOL SilentMode ( ) { return silentmode; }
  1155. BMMExport void SysLog ( int type, char *format, ... );
  1156. //-- Max Interface (used internally)
  1157. BMMExport BOOL SetSilentMode ( BOOL s );
  1158. BMMExport void SetLogLevel ( DWORD level ) { loglevel = level; }
  1159. BMMExport DWORD GetLogLevel ( ) { return (loglevel); }
  1160. //-- Creating a new bitmap from scracth -------------------------------
  1161. //
  1162. // Make sure the given BitmapInfo class has the proper data for the
  1163. // creation of the bitmap. If you used the BitmapManager function to
  1164. // define the bitmap (SelectBitmapOutput()), both filename and device
  1165. // driver have been defined for you.
  1166. //
  1167. // Make sure to set the type of bimap using bi.SetType(). This will
  1168. // define the storage type as in (so far):
  1169. //
  1170. // BMM_LINE_ART
  1171. // BMM_PALETTED
  1172. // BMM_GRAY_8
  1173. // BMM_GRAY_16
  1174. // BMM_TRUE_16
  1175. // BMM_TRUE_32
  1176. // BMM_TRUE_64
  1177. //
  1178. // Do NOT use BMM_TRUE_24 nor BMM_TRUE_48. These are read only types.
  1179. //
  1180. // Example code is in src/app/vpexecut.cpp
  1181. //
  1182. //
  1183. // Once a bitmap has been created, use its own methods for adding
  1184. // outputs and writing it (i.e. map->OpenOutput(), map->Write() and
  1185. // map->Close()).
  1186. //
  1187. // Gus
  1188. //
  1189. BMMExport Bitmap *Create ( BitmapInfo *bi );
  1190. //-- Creating a new bitmap from an existing Windows DIB ---------------
  1191. //
  1192. // To Convert a Bitmap to a Windows DIB check Bitmap::ToDib()
  1193. //
  1194. BMMExport Bitmap *Create ( PBITMAPINFO pbmi );
  1195. //-- Loads Bitmap -----------------------------------------------------
  1196. //
  1197. // Loads a bitmap.
  1198. //
  1199. // Like most other bitmap functions, you should define the image to
  1200. // to load (either setting the name/device directly in BitmapInfo bi,
  1201. // or having SelectFileInput() do it for you). Once bi has the name
  1202. // of the image you want to load, call Load() to create a new Bitmap
  1203. // which contains the image. Additional options may be set by calling
  1204. // ImageInputOptions() before calling Load(). That will as the user
  1205. // for special details such as positioning of smaller/larger images,
  1206. // etc. All this does is to set the proper fields in BitmapInfo. It's
  1207. // up to you to use those.
  1208. //
  1209. // BitmapInfo defaults to frame "zero". For multifrane files, such as
  1210. // *.avi, *.ifl, *.flc, etc. you should specify the frame number you
  1211. // want. Do it by using bi.SetCurrentFrame(f) before calling Load().
  1212. //
  1213. //
  1214. // Note: If loading images from a device, make sure bi.Name() is
  1215. // empty (bi.SetName(_T(""));). This is automatic if you use
  1216. // SelectDeviceInput(). If you just create a BitmapInfo
  1217. // instance and set the device name by hand (bi.SetDevice()),
  1218. // this is also automatic as both name and device names are
  1219. // by default empty. This should only be a concern if you
  1220. // reuse a BitmapInfo class previously used for image files.
  1221. //
  1222. //
  1223. // One of the methods in BitmapInfo returns a window handle to send
  1224. // progress report messages. If you want to receive these messages,
  1225. // set the window handle ( bi->SetUpdateWindow(hWnd) ) and process
  1226. // BMM_PROGRESS messages (see above).
  1227. //
  1228. // Gus
  1229. //
  1230. BMMExport Bitmap *Load ( BitmapInfo *bi, BMMRES *status = NULL);
  1231. //-- Load Image into an existing Bitmap (Internal Use) ----------------
  1232. BMMExport BMMRES LoadInto ( BitmapInfo *bi, Bitmap **map );
  1233. //-- General User Interface -------------------------------------------
  1234. BMMExport BMMRES GetImageInfoDlg ( HWND hWnd, BitmapInfo *bi, const TCHAR *filename = NULL );
  1235. BMMExport BMMRES GetImageInfo ( BitmapInfo *bi, const TCHAR *filename = NULL );
  1236. BMMExport BOOL ImageInputOptions ( BitmapInfo *bi, HWND hWnd );
  1237. BMMExport BOOL SelectDeviceInput ( BitmapInfo *bi, HWND hWnd );
  1238. BMMExport BOOL SelectDeviceOutput ( BitmapInfo *bi, HWND hWnd );
  1239. BMMExport BOOL SelectFileOutput ( BitmapInfo *bi,
  1240. HWND hWnd,
  1241. TCHAR *title = NULL);
  1242. BMMExport BOOL SelectFileInput ( BitmapInfo *bi,
  1243. HWND hWnd,
  1244. TCHAR *title = NULL);
  1245. BMMExport BOOL SelectFileInputEx ( BitmapInfo *bi,
  1246. HWND hWnd,
  1247. TCHAR *title = NULL,
  1248. BOOL viewonly = FALSE);
  1249. };
  1250. //-----------------------------------------------------------------------------
  1251. //-- Forward References for Bitmap Functions
  1252. //
  1253. // Internal Use
  1254. //
  1255. extern int ValidBitmapType ( int type );
  1256. extern BMMExport BitmapStorage *BMMCreateStorage ( BitmapManager *manager,UINT type );
  1257. extern BMMExport BitmapFilter *BMMCreateFilter ( BitmapManager *manager,UINT type );
  1258. extern BMMExport BitmapDither *BMMCreateDither ( BitmapManager *manager,UINT type );
  1259. extern BMMExport int BMMCalcPalette ( Bitmap *map,int colors,BMM_Color_48 *palette );
  1260. extern BMMExport BYTE BMMClosestColor ( BMM_Color_64 *color,BMM_Color_48 *palette,int colors );
  1261. extern BMMExport void OpenBMM ( BMMInterface *i );
  1262. extern BMMExport void CloseBMM ( );
  1263. extern BOOL CALLBACK BMMGammaDlgProc (HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
  1264. extern void ExtractExtension ( TCHAR *string, TCHAR *ext );
  1265. //-----------------------------------------------------------------------------
  1266. //-- Handy-dandy pixel buffer class
  1267. //
  1268. class PixelBuf {
  1269. private:
  1270. BMM_Color_64 *buf;
  1271. int width;
  1272. public:
  1273. inline PixelBuf ( int width) { buf = (BMM_Color_64 *)calloc(width,sizeof(BMM_Color_64)); this->width=width; };
  1274. inline ~PixelBuf ( ) { if(buf) free(buf); };
  1275. inline BMM_Color_64 *Ptr ( ) { return buf; };
  1276. int Fill ( int start, int count, BMM_Color_64 color ) {
  1277. int ix,jx=start+count;
  1278. if (jx > width)
  1279. return 0;
  1280. for(ix=start; ix<jx; buf[ix++]=color);
  1281. return 1;
  1282. };
  1283. };
  1284. //-- Public Utilities ---------------------------------------------------------
  1285. BMMExport int BMMCreateNumberedFilename ( const TCHAR *namein,int frame,TCHAR *nameout );
  1286. BMMExport int BMMGetFullFilename ( BitmapInfo *bi );
  1287. BMMExport BOOL BMMIsFile ( const TCHAR *filename );
  1288. BMMExport void BMMSplitFilename ( const TCHAR *name,TCHAR *p,TCHAR *f,TCHAR *e );
  1289. BMMExport void BMMAppendSlash ( TCHAR *path );
  1290. BMMExport BOOL BMMGetUniversalName ( TCHAR *szUniv, const TCHAR *szDrive );
  1291. BMMExport LPTSTR BMMGetLastErrorText ( LPTSTR lpszBuf, DWORD dwSize );
  1292. //-- 256 color dithering-----------------------------------------------------
  1293. // For packing colors into 256 color paletted representation.
  1294. // Create one with BMMNewColorPacker
  1295. class ColorPacker {
  1296. public:
  1297. virtual void EnableDither(BOOL onoff)=0; // default: MAX default
  1298. virtual void PropogateErrorBetweenLines(BOOL onoff)=0; // default ON;
  1299. virtual void PackLine( BMM_Color_64* in, BYTE *out, int w)=0;
  1300. virtual void PackLine( BMM_Color_48* in, BYTE *out, int w)=0;
  1301. virtual void DeleteThis()=0;
  1302. };
  1303. // Get a color packer. When done, be sure to call its DeleteThis();
  1304. BMMExport ColorPacker *BMMNewColorPacker(
  1305. int w, // width of bitmap to be packed
  1306. BMM_Color_48 *pal, // palette to use
  1307. int npal, // number of entries in the palette
  1308. BYTE* remap=NULL // optional remap done at last stage.
  1309. );
  1310. //---------------------------------------------------------------------
  1311. // Color quantizer, for doing true-color to paletted conversion
  1312. //
  1313. class Quantizer {
  1314. public:
  1315. virtual int AllocHistogram(void)=0;
  1316. virtual int Partition(BMM_Color_48 *pal, int palsize, BMM_Color_64 *forceCol)=0;
  1317. virtual void AddToHistogram(BMM_Color_64 *image, int npix)=0;
  1318. virtual void AddToHistogram(BMM_Color_48 *image, int npix)=0;
  1319. virtual void AddToHistogram(BMM_Color_24 *image, int npix)=0;
  1320. virtual void DeleteThis()=0;
  1321. };
  1322. BMMExport Quantizer *BMMNewQuantizer();
  1323. // Rearrange palette "pal" ( which has colors 0..ncols-1 occupied,
  1324. // in descending order of frequency), into "newpal" so that the colors 10-245 are
  1325. // populated first, then 0-9, then 246-255. Sets optional array "remap" to map the
  1326. // old palette index values to the new ones
  1327. BMMExport void FixPaletteForWindows(BMM_Color_48 *pal, BMM_Color_48 *newpal,int ncols, BYTE *remap=NULL);
  1328. //-- Cleanup ------------------------------------------------------------------
  1329. #undef bVirtual
  1330. #endif BITMAP_H_DEFINED
  1331. //-- EOF: bitmap.h ------------------------------------------------------------