Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
9.0 KiB

  1. /*
  2. * @DEC_COPYRIGHT@
  3. */
  4. /*
  5. * HISTORY
  6. * $Log: scon_api.c,v $
  7. * $EndLog$
  8. */
  9. /*****************************************************************************
  10. ** Copyright (c) Digital Equipment Corporation, 1997 **
  11. ** **
  12. ** All Rights Reserved. Unpublished rights reserved under the copyright **
  13. ** laws of the United States. **
  14. ** **
  15. ** The software contained on this media is proprietary to and embodies **
  16. ** the confidential technology of Digital Equipment Corporation. **
  17. ** Possession, use, duplication or dissemination of the software and **
  18. ** media is authorized only pursuant to a valid written license from **
  19. ** Digital Equipment Corporation. **
  20. ** **
  21. ** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S. **
  22. ** Government is subject to restrictions as set forth in Subparagraph **
  23. ** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable. **
  24. ******************************************************************************/
  25. /*
  26. * SLIB Conversion API
  27. */
  28. /*
  29. #define _SLIBDEBUG_
  30. */
  31. #include "scon_int.h"
  32. #include "SC_err.h"
  33. #include "SC_conv.h"
  34. #ifdef WIN32
  35. #include <mmsystem.h>
  36. #endif
  37. #ifdef _SLIBDEBUG_
  38. #include "sc_debug.h"
  39. #define _DEBUG_ 1 /* detailed debuging statements */
  40. #define _VERBOSE_ 1 /* show progress */
  41. #define _VERIFY_ 1 /* verify correct operation */
  42. #define _WARN_ 1 /* warnings about strange behavior */
  43. #endif
  44. static unsigned dword sconTranslateFourCC(unsigned dword FourCC)
  45. {
  46. switch (FourCC)
  47. {
  48. case BI_DECYUVDIB: /* YUV 4:2:2 Packed */
  49. case BI_YUY2: /* YUV 4:2:2 Packed */
  50. return(BI_YUY2);
  51. case BI_YU16SEP: /* YUV 4:2:2 Planar */
  52. case BI_DECSEPYUVDIB: /* YUV 4:2:2 Planar */
  53. return(BI_YU16SEP);
  54. case BI_YU12SEP: /* YUV 4:1:1 Planar */
  55. case BI_RGB: /* RGB */
  56. case BI_BITFIELDS: /* RGB masked */
  57. #ifndef WIN32
  58. case BI_DECXIMAGEDIB: /* Unix Ximage RGB */
  59. #endif /* !WIN32 */
  60. case BI_YVU9SEP: /* YUV 16:1:1 Planar */
  61. default:
  62. return(FourCC);
  63. }
  64. }
  65. static void sconInitInfo(SconInfo_t *Info)
  66. {
  67. _SlibDebug(_DEBUG_, printf("sconInitInfo()\n") );
  68. Info->Mode = SCON_MODE_NONE;
  69. Info->InputInited = FALSE;
  70. Info->OutputInited = FALSE;
  71. Info->Flip = FALSE;
  72. Info->SameFormat = TRUE;
  73. Info->ScaleUp = FALSE;
  74. Info->ScaleDown = FALSE;
  75. Info->FImage = NULL;
  76. Info->FImageSize = 0;
  77. Info->SImage = NULL;
  78. Info->SImageSize = 0;
  79. Info->Table = NULL;
  80. Info->TableSize = 0;
  81. Info->dbg = NULL;
  82. }
  83. static void sconValidateInfo(SconInfo_t *Info)
  84. {
  85. if (Info->Mode==SCON_MODE_VIDEO)
  86. {
  87. if (Info->InputInited && Info->OutputInited)
  88. {
  89. SconVideoInfo_t *in_vinfo=&Info->Input.vinfo;
  90. SconVideoInfo_t *out_vinfo=&Info->Output.vinfo;
  91. Info->Flip=(in_vinfo->NegHeight!=out_vinfo->NegHeight)?TRUE:FALSE;
  92. sconCalcImageSize(in_vinfo);
  93. sconCalcImageSize(out_vinfo);
  94. Info->ScaleDown=(in_vinfo->Pixels>out_vinfo->Pixels)?TRUE:FALSE;
  95. Info->ScaleUp=(in_vinfo->Pixels<out_vinfo->Pixels)?TRUE:FALSE;
  96. if (!Info->ScaleDown && !Info->ScaleUp && in_vinfo->Width>out_vinfo->Width)
  97. Info->ScaleUp=TRUE;
  98. in_vinfo->FourCC=sconTranslateFourCC(in_vinfo->FourCC);
  99. out_vinfo->FourCC=sconTranslateFourCC(out_vinfo->FourCC);
  100. if (in_vinfo->BPP==out_vinfo->BPP &&
  101. in_vinfo->FourCC==out_vinfo->FourCC)
  102. Info->SameFormat=TRUE;
  103. else
  104. Info->SameFormat=FALSE;
  105. }
  106. }
  107. }
  108. static void sconBMHtoVideoInfo(BITMAPINFOHEADER *bmh, SconVideoInfo_t *vinfo)
  109. {
  110. vinfo->Width=bmh->biWidth;
  111. if (bmh->biHeight<0) /* height is negative */
  112. {
  113. vinfo->Height=-bmh->biHeight;
  114. vinfo->NegHeight=TRUE;
  115. }
  116. else /* height is positive */
  117. {
  118. vinfo->Height=bmh->biHeight;
  119. vinfo->NegHeight=FALSE;
  120. }
  121. vinfo->FourCC=bmh->biCompression;
  122. vinfo->BPP=bmh->biBitCount;
  123. vinfo->Stride=vinfo->Width*((vinfo->BPP+7)>>3);
  124. /* RGB bit masks */
  125. vinfo->Rmask=0;
  126. vinfo->Gmask=0;
  127. vinfo->Bmask=0;
  128. vinfo->RGBmasks=0;
  129. if (vinfo->FourCC==BI_BITFIELDS || vinfo->FourCC==BI_RGB ||
  130. vinfo->FourCC==BI_DECXIMAGEDIB)
  131. {
  132. if (vinfo->BPP==32 || vinfo->BPP==24)
  133. {
  134. vinfo->Rmask=0xFF0000;
  135. vinfo->Gmask=0x00FF00;
  136. vinfo->Bmask=0x0000FF;
  137. }
  138. else if (vinfo->BPP==16) /* RGB 565 */
  139. {
  140. vinfo->Rmask=0xF800;
  141. vinfo->Gmask=0x07E0;
  142. vinfo->Bmask=0x001F;
  143. }
  144. if (vinfo->FourCC==BI_BITFIELDS &&
  145. bmh->biSize>=sizeof(BITMAPINFOHEADER)+3*4)
  146. {
  147. DWORD *MaskPtr = (DWORD *)&bmh[1];
  148. if (MaskPtr[0] && MaskPtr[1] && MaskPtr[2])
  149. {
  150. /* get bit masks */
  151. vinfo->Rmask=MaskPtr[0];
  152. vinfo->Gmask=MaskPtr[1];
  153. vinfo->Bmask=MaskPtr[2];
  154. }
  155. }
  156. if (vinfo->Rmask==0xF800 && vinfo->Gmask==0x07E0 && vinfo->Bmask==0x001F)
  157. vinfo->RGBmasks=565;
  158. else if (vinfo->Rmask==0x001F && vinfo->Gmask==0x07E0 && vinfo->Bmask==0xF800)
  159. vinfo->RGBmasks=565;
  160. else if (vinfo->Rmask==0x7C00 && vinfo->Gmask==0x03E0 && vinfo->Bmask==0x001F)
  161. vinfo->RGBmasks=555;
  162. else if (vinfo->Rmask==0x001F && vinfo->Gmask==0x03E0 && vinfo->Bmask==0x7C00)
  163. vinfo->RGBmasks=555;
  164. else if (vinfo->Rmask==0xFF0000 && vinfo->Gmask==0x00FF00 && vinfo->Bmask==0x0000FF)
  165. vinfo->RGBmasks=888;
  166. else if (vinfo->Rmask==0x0000FF && vinfo->Gmask==0x00FF00 && vinfo->Bmask==0xFF0000)
  167. vinfo->RGBmasks=888;
  168. }
  169. }
  170. SconStatus_t SconOpen(SconHandle_t *handle, SconMode_t smode,
  171. void *informat, void *outformat)
  172. {
  173. SconInfo_t *Info;
  174. if (smode==SCON_MODE_VIDEO)
  175. {
  176. if ((Info = (SconInfo_t *)ScAlloc(sizeof(SconInfo_t))) == NULL)
  177. return(SconErrorMemory);
  178. sconInitInfo(Info);
  179. Info->Mode=smode;
  180. if (informat)
  181. {
  182. sconBMHtoVideoInfo((BITMAPINFOHEADER *)informat, &Info->Input.vinfo);
  183. Info->InputInited = TRUE;
  184. }
  185. if (outformat)
  186. {
  187. sconBMHtoVideoInfo((BITMAPINFOHEADER *)outformat, &Info->Output.vinfo);
  188. Info->OutputInited = TRUE;
  189. }
  190. sconValidateInfo(Info);
  191. *handle=(SconHandle_t)Info;
  192. return(SconErrorNone);
  193. }
  194. else
  195. return(SconErrorBadMode);
  196. }
  197. SconStatus_t SconClose(SconHandle_t handle)
  198. {
  199. SconInfo_t *Info=(SconInfo_t *)handle;
  200. _SlibDebug(_VERBOSE_, printf("SconClose()\n") );
  201. if (!handle)
  202. return(SconErrorBadHandle);
  203. if (Info->Table)
  204. ScPaFree(Info->Table);
  205. if (Info->FImage)
  206. ScPaFree(Info->FImage);
  207. if (Info->SImage)
  208. ScPaFree(Info->SImage);
  209. ScFree(Info);
  210. return(SconErrorNone);
  211. }
  212. /*
  213. ** Name: SconIsSame
  214. ** Desc: Return true if input and output formats are identical.
  215. ** Return: TRUE input == output format
  216. ** FALSE input != out format
  217. */
  218. SconBoolean_t SconIsSame(SconHandle_t handle)
  219. {
  220. if (handle)
  221. {
  222. SconInfo_t *Info=(SconInfo_t *)handle;
  223. if (Info->Mode==SCON_MODE_VIDEO)
  224. {
  225. if (Info->SameFormat && !Info->Flip && !Info->ScaleUp && !Info->ScaleDown)
  226. return(TRUE);
  227. }
  228. }
  229. return(FALSE);
  230. }
  231. SconStatus_t SconConvert(SconHandle_t handle, void *inbuf, dword inbufsize,
  232. void *outbuf, dword outbufsize)
  233. {
  234. SconInfo_t *Info=(SconInfo_t *)handle;
  235. SconStatus_t status;
  236. _SlibDebug(_VERBOSE_, printf("SconConvert()\n") );
  237. if (!handle)
  238. return(SconErrorBadHandle);
  239. if (inbuf==NULL || outbuf==NULL)
  240. return(SconErrorBadArgument);
  241. if (Info->Mode==SCON_MODE_VIDEO)
  242. status=sconConvertVideo(Info, inbuf, inbufsize, outbuf, outbufsize);
  243. else
  244. status=SconErrorBadMode;
  245. return(status);
  246. }
  247. SconStatus_t SconSetParamInt(SconHandle_t handle, SconParamType_t ptype,
  248. SconParameter_t param, long value)
  249. {
  250. SconInfo_t *Info=(SconInfo_t *)handle;
  251. SconStatus_t status=SconErrorNone;
  252. if (!handle)
  253. return(SconErrorBadHandle);
  254. _SlibDebug(_DEBUG_, printf("SconSetParamInt(stream=%d, param=%d, %d)\n",
  255. stream, param, value) );
  256. switch (param)
  257. {
  258. case SCON_PARAM_STRIDE:
  259. _SlibDebug(_DEBUG_,
  260. printf("SconSetParamInt(SCON_PARAM_STRIDE)\n") );
  261. if (Info->Mode==SCON_MODE_VIDEO)
  262. {
  263. if (ptype==SCON_INPUT || ptype==SCON_INPUT_AND_OUTPUT)
  264. Info->Input.vinfo.Stride=(long)value;
  265. if (ptype==SCON_OUTPUT || ptype==SCON_INPUT_AND_OUTPUT)
  266. Info->Output.vinfo.Stride=(long)value;
  267. }
  268. else
  269. status=SconErrorBadMode;
  270. break;
  271. default:
  272. return(SconErrorUnsupportedParam);
  273. }
  274. return(status);
  275. }