ximage.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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 "../include/dxl_plugin.h"
  13. #include <ctype.h> /* toupper */
  14. static CREATE_FUNC creator[NUM_ALG];
  15. static unsigned int fourCC[NUM_ALG];
  16. static DXL_OBJECT_VERSION thisVersion = 0x01000001;
  17. typedef struct tagflgs
  18. {
  19. unsigned inUse : 1;
  20. unsigned DXed : 1;
  21. unsigned clutOwner: 1;
  22. unsigned doCompleteBlit : 1;
  23. unsigned keyFrame : 1;
  24. unsigned nullFrame : 1;
  25. unsigned interframe : 1;
  26. unsigned logo : 1;
  27. unsigned allocated : 1;
  28. } dkInfoFlags;
  29. typedef struct tXImageBase
  30. {
  31. dkInfoFlags dkFlags;
  32. //short x,y,w,h;
  33. unsigned char *addr;
  34. enum BITDEPTH *bdPrefs;
  35. CREATE_FUNC create;
  36. RECREATE_FUNC recreate;
  37. DESTROY_FUNC destroy;
  38. SEND_VMSG_FUNC sendVideoMessage;
  39. DX_FUNC dx;
  40. int fSize;
  41. SET_PARAMETER_FUNC setParameter;
  42. GET_PARAMETER_FUNC getParameter;
  43. } DXL_XIMAGE_BASE;
  44. typedef struct tXImage
  45. {
  46. DXL_OBJECT_VERSION version;
  47. DXL_XIMAGE_BASE * xImageBasePtr;
  48. DXL_HANDLE algorithmBasePtr;
  49. } DXL_XIMAGE;
  50. #define validateXImage(x) \
  51. { \
  52. if (!x) \
  53. return (int) DXL_NULLSOURCE; \
  54. if (!x->xImageBasePtr->dkFlags.inUse) \
  55. return (int) DXL_NOTINUSE; \
  56. }
  57. // if (!x->version != thisVersion)
  58. // return (int) DXL_INVALID_DATA;
  59. static //inline
  60. unsigned int toUpperFOURCC(unsigned int type)
  61. {
  62. return (
  63. (toupper((char)((type >> 24) & 0xff)) << 24) |
  64. (toupper((char)((type >> 16) & 0xff)) << 16) |
  65. (toupper((char)((type >> 8) & 0xff)) << 8) |
  66. toupper((char)((type >> 0) & 0xff))
  67. );
  68. }
  69. int
  70. DXL_SetXImageCSize(DXL_XIMAGE_HANDLE src, int temp)
  71. {
  72. if(src == NULL)
  73. return DXL_NOTINUSE;
  74. src->xImageBasePtr->fSize = temp;
  75. return DXL_OK;
  76. }
  77. int
  78. DXL_GetXImageCSize(DXL_XIMAGE_HANDLE src)
  79. {
  80. if(src == NULL)
  81. return 0;
  82. return src->xImageBasePtr->fSize;
  83. }
  84. unsigned char *
  85. DXL_GetXImageCDataAddr(DXL_XIMAGE_HANDLE src)
  86. {
  87. if(src == NULL)
  88. return NULL;
  89. return src->xImageBasePtr->addr;
  90. }
  91. /*
  92. int
  93. DXL_MoveXImage(DXL_XIMAGE_HANDLE src, enum OFFSETXY mode, int x, int y)
  94. {
  95. validateXImage(src);
  96. if (mode != DXL_RELATIVE)
  97. {
  98. src->xImageBasePtr->x = 0;
  99. src->xImageBasePtr->y = 0;
  100. }
  101. src->xImageBasePtr->x += (short) x;
  102. src->xImageBasePtr->y += (short) y;
  103. return DXL_OK;
  104. }
  105. */
  106. int
  107. DXL_AlterXImageData(DXL_XIMAGE_HANDLE src, unsigned char *data)
  108. {
  109. validateXImage(src);
  110. src->xImageBasePtr->addr = data;
  111. src->xImageBasePtr->dkFlags.DXed = 0;
  112. if (data == NULL)
  113. return DXL_OK;
  114. return DXL_OK;
  115. }
  116. int
  117. DXL_IsXImageKeyFrame(DXL_XIMAGE_HANDLE src)
  118. {
  119. validateXImage(src);
  120. return src->xImageBasePtr->dkFlags.keyFrame;
  121. }
  122. void
  123. DXL_DestroyXImage(DXL_XIMAGE_HANDLE src)
  124. {
  125. if (src != NULL)
  126. {
  127. if (src->xImageBasePtr->dkFlags.inUse)
  128. {
  129. src->xImageBasePtr->destroy(src);
  130. }
  131. duck_free(src->xImageBasePtr);
  132. duck_free(src);
  133. }
  134. }
  135. DXL_XIMAGE_HANDLE DXL_CreateXImageOfType(unsigned char *data, unsigned int type)
  136. {
  137. int i;
  138. DXL_XIMAGE_HANDLE nImage = NULL;
  139. /* alloc our ximage */
  140. nImage = (DXL_XIMAGE_HANDLE) duck_calloc(1, sizeof(DXL_XIMAGE), DMEM_GENERAL);
  141. if(nImage == NULL)
  142. {
  143. return NULL;
  144. }
  145. nImage->version = thisVersion;
  146. /* alloc our generic ximage base */
  147. nImage->xImageBasePtr = (DXL_XIMAGE_BASE *) duck_calloc(1, sizeof(DXL_XIMAGE_BASE), DMEM_GENERAL);
  148. if(nImage->xImageBasePtr == NULL)
  149. {
  150. duck_free(nImage);
  151. return NULL;
  152. }
  153. /* clear out just in case calloc does not really work */
  154. nImage->algorithmBasePtr = NULL;
  155. /*
  156. //convert fourCC to uppercase, fixes problem with calls to DXV with
  157. //lowercase fourCC's
  158. */
  159. type = toUpperFOURCC(type);
  160. /* try to match the fourcc to a registered algorithm */
  161. for(i = 0; i < NUM_ALG; i++)
  162. {
  163. if(fourCC[i] == type)
  164. {
  165. if(nImage->algorithmBasePtr = creator[i](nImage, data))
  166. {
  167. nImage->xImageBasePtr->create = creator[i];
  168. break;
  169. }
  170. }
  171. }
  172. /* was a valid registered alogrith found ? */
  173. if(nImage->algorithmBasePtr == NULL)
  174. {
  175. /* nope, so we are going to bail */
  176. duck_free(nImage->xImageBasePtr);
  177. duck_free(nImage);
  178. return NULL;
  179. }
  180. nImage->xImageBasePtr->dkFlags.inUse = 1;
  181. nImage->xImageBasePtr->addr = data;
  182. return nImage;
  183. }
  184. unsigned int *
  185. DXL_GetFourCCList(void)
  186. {
  187. /*********
  188. return a list of all supported fourccs
  189. *********/
  190. return fourCC;
  191. }
  192. int
  193. DXL_GetAlgHandle(unsigned int fourcc)
  194. {
  195. /*********
  196. search through the fourcc table to find a dx'er's index
  197. *********/
  198. int i;
  199. for (i = 0; i < NUM_ALG; i++)
  200. if (fourCC[i] == fourcc)
  201. return i;
  202. return DXL_NOTINUSE;
  203. }
  204. unsigned int
  205. DXL_GetXImageFOURCC(DXL_XIMAGE_HANDLE src)
  206. {
  207. /*********
  208. find an ximages fourcc (by comparing creator functions)
  209. *********/
  210. int i;
  211. for (i = 0; i < NUM_ALG; i++)
  212. if (creator[i] == (CREATE_FUNC) src->xImageBasePtr->create)
  213. {
  214. return fourCC[i];
  215. }
  216. return 0;
  217. }
  218. int
  219. DXL_dxImageToVScreen(DXL_XIMAGE_HANDLE src, DXL_VSCREEN_HANDLE dst)
  220. {
  221. int dxvCode;
  222. validateXImage(src);
  223. /*
  224. after a ximage is created, it must always be altered.... this check will
  225. catch programmers who do not follow the api
  226. */
  227. if(!src->xImageBasePtr->dkFlags.allocated)
  228. return DXL_NOTINUSE;
  229. if(!src->xImageBasePtr->dx)
  230. return DXL_NOTINUSE;
  231. //if(!src->xImageBasePtr->addr)
  232. // return DXL_HOLD_FRAME;
  233. dxvCode = src->xImageBasePtr->dx(src, dst);
  234. return dxvCode;
  235. }
  236. /*-------------------------------------------------------------------
  237. -------------------------------------------------------------------*/
  238. int
  239. DXL_InitVideo(void)
  240. {
  241. /* this will force the internal fourcc and creator arrays to be set to 0 */
  242. DXL_RegisterXImage(NULL, 0L);
  243. return DXL_OK;
  244. }
  245. void
  246. DXL_ExitVideo(void)
  247. {
  248. }
  249. DXL_XIMAGE_HANDLE
  250. DXL_AlterXImage(DXL_XIMAGE_HANDLE src, unsigned char *data, int type,
  251. enum BITDEPTH bitDepth, int width, int height)
  252. {
  253. type = toUpperFOURCC(type);
  254. if (src == NULL)
  255. {
  256. if(type) /* if type specified, try using it as the fourcc */
  257. src = DXL_CreateXImageOfType(data,type);
  258. if (src == NULL) /* if still null, give up */
  259. return NULL;
  260. }
  261. /* no way to recreate, assume create is good enough */
  262. if (!src->xImageBasePtr->recreate)
  263. return src;
  264. src->xImageBasePtr->addr = data;
  265. src->algorithmBasePtr = src->xImageBasePtr->recreate(src, data, type, bitDepth, width, height);
  266. /* was a valid registered alogrith found ? */
  267. if(src->algorithmBasePtr == NULL)
  268. {
  269. /* nope, so we are going to bail */
  270. duck_free(src->xImageBasePtr);
  271. duck_free(src);
  272. return NULL;
  273. }
  274. src->xImageBasePtr->dkFlags.allocated = 1;
  275. return src;
  276. }
  277. int
  278. DXL_SetParameter(DXL_XIMAGE_HANDLE src, int Command, unsigned int Parameter )
  279. {
  280. if (src == NULL)
  281. return DXL_NULLSOURCE;
  282. if (src->xImageBasePtr == NULL)
  283. return DXL_NULLSOURCE;
  284. if(src->xImageBasePtr->setParameter == NULL)
  285. return DXL_NULLSOURCE;
  286. src->xImageBasePtr->setParameter(src, Command, Parameter);
  287. return DXL_OK;
  288. }
  289. int
  290. DXL_GetParameter(DXL_XIMAGE_HANDLE src, int Command, unsigned int Parameter )
  291. {
  292. if (src == NULL)
  293. return DXL_NULLSOURCE;
  294. if (src->xImageBasePtr == NULL)
  295. return DXL_NULLSOURCE;
  296. if(src->xImageBasePtr->getParameter == NULL)
  297. return DXL_NULLSOURCE;
  298. return src->xImageBasePtr->getParameter(src, Command, Parameter);
  299. }
  300. DXL_HANDLE
  301. DXL_GetAlgorithmBasePtr(DXL_XIMAGE_HANDLE src)
  302. {
  303. return src->algorithmBasePtr;
  304. }
  305. int
  306. DXL_SendVideoMessage(DXL_XIMAGE_HANDLE src, void *msgHandle, unsigned int msgSize)
  307. {
  308. validateXImage(src);
  309. if(src->xImageBasePtr->sendVideoMessage != NULL)
  310. return src->xImageBasePtr->sendVideoMessage(src, msgHandle, msgSize);
  311. return DXL_OK;
  312. }
  313. /*-------------------------------------------------------------------
  314. CALLBACK REGISTRATION SECTION
  315. -------------------------------------------------------------------*/
  316. int
  317. DXL_RegisterXImage(CREATE_FUNC myCreator, unsigned int fourcc)
  318. {
  319. int i;
  320. /* special case -- a fourcc of zero will set the creator and fourcc arrays to 0 */
  321. if (!fourcc)
  322. {
  323. duck_memset(creator, 0, sizeof(creator));
  324. duck_memset(fourCC, 0, sizeof(fourCC));
  325. return DXL_OK;
  326. }
  327. for (i = 0; i < NUM_ALG; i++)
  328. {
  329. if (!fourCC[i])
  330. {
  331. creator[i] = myCreator;
  332. fourCC[i] = fourcc;
  333. return i;
  334. }
  335. }
  336. return DXL_NOTINUSE;
  337. }
  338. int
  339. DXL_RegisterXImageRecreate(DXL_XIMAGE_HANDLE src, RECREATE_FUNC thisFunc)
  340. {
  341. src->xImageBasePtr->recreate = thisFunc;
  342. return DXL_OK;
  343. }
  344. int
  345. DXL_RegisterXImageDestroy(DXL_XIMAGE_HANDLE src, DESTROY_FUNC thisFunc)
  346. {
  347. src->xImageBasePtr->destroy = thisFunc;
  348. return DXL_OK;
  349. }
  350. int
  351. DXL_RegisterXImageDx(DXL_XIMAGE_HANDLE src, DX_FUNC thisFunc)
  352. {
  353. src->xImageBasePtr->dx = thisFunc;
  354. return DXL_OK;
  355. }
  356. int
  357. DXL_RegisterXImageSetParameter(DXL_XIMAGE_HANDLE src, SET_PARAMETER_FUNC thisFunc)
  358. {
  359. src->xImageBasePtr->setParameter = thisFunc;
  360. return DXL_OK;
  361. }
  362. int
  363. DXL_RegisterXImageGetParameter(DXL_XIMAGE_HANDLE src, GET_PARAMETER_FUNC thisFunc)
  364. {
  365. src->xImageBasePtr->getParameter = thisFunc;
  366. return DXL_OK;
  367. }
  368. int
  369. DXL_RegisterXImageSendVideoMessage(DXL_XIMAGE_HANDLE src, SEND_VMSG_FUNC thisFunc)
  370. {
  371. src->xImageBasePtr->sendVideoMessage = thisFunc;
  372. return DXL_OK;
  373. }
  374. /*-------------------------------------------------------------------
  375. -------------------------------------------------------------------*/