ximage.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. //==========================================================================
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright (c) 1999 - 2001 On2 Technologies Inc. All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------
  11. #include "duck_mem.h"
  12. #include "dxl_main.h"
  13. int DXL_SetXImageCSize(DXL_XIMAGE_HANDLE src, int temp)
  14. {
  15. src->fSize = temp;
  16. return temp;
  17. }
  18. void DXL_DestroyXImage(DXL_XIMAGE_HANDLE src)
  19. {
  20. {
  21. #pragma warning(disable:4210) //nonstandard extension used : function given file scope
  22. void DXL_AccurateTime(UINT64* time);
  23. #pragma warning(default:4210) //nonstandard extension used : function given file scope
  24. UINT64 clocksTotal;
  25. double ratio, ratio2;
  26. DXL_AccurateTime(&src->prof.profileEnd);
  27. clocksTotal = (src->prof.profileEnd - src->prof.profileStart);
  28. if (clocksTotal)
  29. {
  30. ratio = src->prof.dxClocks * 1.0 / clocksTotal;
  31. ratio2 = (double)(src->prof.dxClocks / src->prof.frameCount);
  32. }
  33. }
  34. if (src != NULL)
  35. {
  36. if (src->dkFlags.inUse)
  37. {
  38. src->destroy(src);
  39. }
  40. }
  41. }
  42. int DXL_MoveXImage(DXL_XIMAGE_HANDLE src,enum OFFSETXY mode, int x,int y)
  43. {
  44. validate(src);
  45. if (mode != DXL_RELATIVE){
  46. src->x = 0;
  47. src->y = 0;
  48. }
  49. src->x = (short)(src->x + x);
  50. src->y = (short)(src->y + y);
  51. return DXL_OK;
  52. }
  53. int DXL_AlterXImageData(DXL_XIMAGE_HANDLE src, unsigned char *data)
  54. {
  55. validate(src);
  56. src->addr = data;
  57. src->dkFlags.DXed = 0;
  58. if (data == NULL) return DXL_OK;
  59. if (src->seedData)
  60. return src->seedData(src);
  61. else
  62. return 0;
  63. }
  64. int DXL_GetXImageXYWH(DXL_XIMAGE_HANDLE src,int *x,int *y,int *w, int *h)
  65. {
  66. validate(src);
  67. *x = src->x;
  68. *y = src->y;
  69. *w = src->w;
  70. *h = src->h;
  71. return DXL_OK;
  72. }
  73. int DXL_IsXImageKeyFrame(DXL_XIMAGE_HANDLE src)
  74. {
  75. validate(src);
  76. return src->dkFlags.keyFrame;
  77. }
  78. /* typedef DXL_XIMAGE_HANDLE (*createFunc)(unsigned char *data); */
  79. #define NUM_ALG 16
  80. static createFunc creator[NUM_ALG];
  81. static unsigned long fourCC[NUM_ALG];
  82. DXL_XIMAGE_HANDLE DXL_CreateXImage(unsigned char *data)
  83. {
  84. int i;
  85. DXL_XIMAGE_HANDLE nImage = NULL;
  86. for(i = 0; i < NUM_ALG; i++){
  87. if (fourCC[i]){
  88. nImage = creator[i](data);
  89. if ( nImage )
  90. break;
  91. }else
  92. break;
  93. }
  94. if (nImage)
  95. {
  96. nImage->dkFlags.inUse = 1;
  97. nImage->addr = data;
  98. nImage->create = (struct tXImage *(__cdecl *)(void *))creator[i];
  99. }
  100. return nImage;
  101. }
  102. DXL_XIMAGE_HANDLE DXL_CreateXImageOfType(unsigned char *data,unsigned long type)
  103. {
  104. int i;
  105. DXL_XIMAGE_HANDLE nImage = NULL;
  106. for(i = 0; i < NUM_ALG; i++){
  107. if (fourCC[i] == type){
  108. nImage = creator[i](data);
  109. if ( nImage )
  110. break;
  111. }
  112. }
  113. if (nImage)
  114. {
  115. nImage->dkFlags.inUse = 1;
  116. nImage->addr = data;
  117. nImage->prof.profileStart = 0;
  118. nImage->prof.dxClocks = 0;
  119. nImage->prof.frameCount = 0;
  120. }
  121. return nImage;
  122. }
  123. DXL_XIMAGE_HANDLE DXL_CreateXImageFromBMI(
  124. unsigned char *data,
  125. unsigned long fcc,
  126. DK_BITMAPINFOHEADER *srcAndDest /* There will always be two Obiwan */
  127. )
  128. {
  129. int i;
  130. DXL_XIMAGE_HANDLE nImage = NULL;
  131. for(i = 0; i < NUM_ALG; i++){
  132. if (fourCC[i] == fcc){
  133. nImage = creator[i]((unsigned char *) srcAndDest);
  134. if ( nImage )
  135. break;
  136. }
  137. }
  138. if (nImage)
  139. {
  140. nImage->dkFlags.inUse = 1;
  141. nImage->addr = data;
  142. duck_memset(&nImage->prof,0,sizeof(DXL_PROFILEPACK)); /* probably redundent */
  143. }
  144. return nImage;
  145. }
  146. int DXL_RegisterXImage(createFunc myCreator,unsigned long fourcc, DXL_INTERNAL_FORMAT xFormat)
  147. {
  148. int i;
  149. if (!fourcc){
  150. duck_memset(creator,0,sizeof(creator));
  151. duck_memset(fourCC,0,sizeof(fourCC));
  152. return 0;
  153. }
  154. for (i = 0; i < sizeof(fourCC)/sizeof(unsigned long);i++){
  155. if (!fourCC[i]){
  156. creator[i] = myCreator;
  157. fourCC[i] = fourcc;
  158. dxl_RegisterInternalFormat(i, xFormat);
  159. return i;
  160. }
  161. }
  162. return -1;
  163. }
  164. unsigned long *DXL_GetFourCCList(void)
  165. {
  166. /*********
  167. return a list of all supported fourccs
  168. *********/
  169. return fourCC;
  170. }
  171. int dxl_GetAlgHandle(unsigned long fourcc)
  172. {
  173. /*********
  174. search through the fourcc table to find a dx'er's index
  175. *********/
  176. int i;
  177. for (i = 0; i < sizeof(fourCC)/sizeof(unsigned long);i++)
  178. if (fourCC[i] == fourcc) return i;
  179. return -1;
  180. }
  181. unsigned long DXL_GetXImageFOURCC(DXL_XIMAGE_HANDLE src)
  182. {
  183. /*********
  184. find an ximages fourcc (by comparing creator functions)
  185. *********/
  186. int i;
  187. for (i = 0; i < sizeof(fourCC)/sizeof(unsigned long);i++)
  188. if (creator[i] == (createFunc)src->create)
  189. return fourCC[i];
  190. return 0L;
  191. }
  192. unsigned char *DXL_GetDestAddress(DXL_XIMAGE_HANDLE src, DXL_VSCREEN_HANDLE dst)
  193. {
  194. /*********
  195. get the address within the vscreen to start writing at
  196. *********/
  197. unsigned char *scrnDest = (unsigned char *)0L;
  198. int x,y;
  199. y = dst->viewY + src->y;
  200. x = dst->viewX + src->x;
  201. scrnDest = (unsigned char *) dst->addr;
  202. scrnDest += (x * DXL_GetVScreenSizeOfPixel(dst)) + (y * dst->pitch);
  203. return scrnDest;
  204. }
  205. int DXL_dxImageToVScreen(DXL_XIMAGE_HANDLE src, DXL_VSCREEN_HANDLE dst)
  206. {
  207. int dxvCode;
  208. validate(src);
  209. if (!src->dx)
  210. return -1;
  211. #pragma warning(disable:4054) // typecase from function pointer to data pointer
  212. if(dst && ((void *)(src->internalFormat) != NULL)) {
  213. /* get your hamdy damdy((c)1997 Duck North) registered blitter setup */
  214. dst->blitSetup = DXL_GetBlitSetupFunc(src,dst);
  215. dst->blitExit = DXL_GetBlitExitFunc(src,dst);
  216. dst->blitter = DXL_GetBlitFunc(src, dst);
  217. if (dst->blitter == (void *) -1)
  218. return DXL_INVALID_BLIT;
  219. }
  220. #pragma warning(default:4054) // typecase from function pointer to data pointer
  221. // if (!src->addr)
  222. // return 1;
  223. #if 1 /* we want to profile ... this should constitute no performance hit to profile */
  224. {
  225. UINT64 timerStart;
  226. UINT64 timerEnd;
  227. void DXL_AccurateTime(UINT64* time);
  228. DXL_AccurateTime(&timerStart);
  229. if (src->prof.profileStart == 0)
  230. src->prof.profileStart = timerStart;
  231. dxvCode = src->dx(src,dst);
  232. DXL_AccurateTime(&timerEnd);
  233. src->prof.dxClocks += (timerEnd - timerStart);
  234. src->prof.frameCount += 1;
  235. }
  236. #else
  237. dxvCode = src->dx(src,dst);
  238. #endif
  239. return dxvCode;
  240. }
  241. long DXL_GetXImageCSize(DXL_XIMAGE_HANDLE src)
  242. {
  243. if (src == NULL) return -1;
  244. if (!src->GetXImageCSize)
  245. return -2;
  246. return(src->GetXImageCSize(src));
  247. }
  248. /***********************************************/
  249. DXL_XIMAGE_HANDLE DXL_AlterXImage(DXL_XIMAGE_HANDLE src,
  250. unsigned char *data,int type,
  251. enum BITDEPTH bitDepth,int width,int height)
  252. {
  253. if (src == NULL)
  254. {
  255. if (type) /* if type specified, try using it as the fourcc */
  256. src = DXL_CreateXImageOfType(data,type);
  257. if (src == NULL) /* if still null, try creating it blind from the data */
  258. src = DXL_CreateXImage(data);
  259. if (src == NULL) /* if still null, give up */
  260. return NULL;
  261. }
  262. if (!src->recreate) /* no way to recreate, assume create is good enough */
  263. return src;
  264. return(src->recreate(src,data,type,bitDepth,width,height));
  265. }
  266. void DXL_SetParameter(DXL_XIMAGE_HANDLE src, int Command, unsigned long Parameter )
  267. {
  268. src->setParameter(src,Command,Parameter);
  269. }