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.

633 lines
23 KiB

  1. /*
  2. * @DEC_COPYRIGHT@
  3. */
  4. /*
  5. * HISTORY
  6. * $Log: scon_video.h,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 - Video
  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. unsigned dword sconCalcImageSize(SconVideoInfo_t *vinfo)
  45. {
  46. vinfo->Pixels=vinfo->Width*vinfo->Height;
  47. switch (vinfo->FourCC)
  48. {
  49. case BI_YVU9SEP: /* YUV 16:1:1 Planar */
  50. vinfo->ImageSize = (vinfo->Pixels*5)/4;
  51. break;
  52. case BI_YU12SEP: /* YUV 4:1:1 Planar */
  53. vinfo->ImageSize = (vinfo->Pixels*3)/2;
  54. break;
  55. case BI_DECYUVDIB: /* YUV 4:2:2 Packed */
  56. case BI_YUY2: /* YUV 4:2:2 Packed */
  57. case BI_YU16SEP: /* YUV 4:2:2 Planar */
  58. vinfo->ImageSize = vinfo->Pixels*2;
  59. break;
  60. #ifndef WIN32
  61. case BI_DECXIMAGEDIB:
  62. vinfo->ImageSize = vinfo->Pixels*(vinfo->BPP==24 ? 4 : 1);
  63. break;
  64. #endif /* !WIN32 */
  65. case BI_RGB:
  66. case BI_BITFIELDS:
  67. vinfo->ImageSize = vinfo->Pixels*((vinfo->BPP+7)/8);
  68. break;
  69. default:
  70. vinfo->ImageSize = vinfo->Pixels;
  71. }
  72. return(vinfo->ImageSize);
  73. }
  74. static void sconScaleFrame(unsigned word bytesperpixel,
  75. void *inbuf, int inw, int inh,
  76. void *outbuf, int outw, int outh, int stride)
  77. {
  78. int inx, outx, iny=0, outy=0;
  79. int deltax, deltay;
  80. _SlibDebug(_VERBOSE_,
  81. ScDebugPrintf(NULL, "sconScaleFrame(byteperpixel=%d) %dx%d -> %dx%d\n",
  82. bytesperpixel, inw, inh, outw, outh) );
  83. if (inh<0) inh=-inh; /* no flipping supported */
  84. if (outh<0) outh=-outh; /* no flipping supported */
  85. if (bytesperpixel==4)
  86. {
  87. unsigned dword *inscan, *outscan;
  88. deltay=0;
  89. while (iny<inh)
  90. {
  91. inscan=(unsigned dword *)inbuf;
  92. while (deltay<outh)
  93. {
  94. outscan=(unsigned dword *)outbuf;
  95. inx=0; outx=0;
  96. deltax=0;
  97. while (inx<inw)
  98. {
  99. while (deltax<outw)
  100. {
  101. outscan[outx]=inscan[inx];
  102. deltax+=inw;
  103. outx++;
  104. }
  105. inx++;
  106. deltax-=outw;
  107. }
  108. outy++;
  109. deltay+=inh;
  110. (unsigned char *)outbuf+=stride;
  111. }
  112. iny++;
  113. deltay-=outh;
  114. ((unsigned dword *)inbuf)+=inw;
  115. }
  116. }
  117. else if (bytesperpixel==3)
  118. {
  119. unsigned char *inscan, *outscan;
  120. deltay=0;
  121. inw*=3;
  122. outw*=3;
  123. while (iny<inh)
  124. {
  125. inscan=(unsigned char *)inbuf;
  126. _SlibDebug(_DEBUG_>1,
  127. ScDebugPrintf(NULL, "deltay=%d iny=%d outy=%d inh=%d outh=%d\n",
  128. deltay, iny, outy, inh, outh) );
  129. while (deltay<outh)
  130. {
  131. outscan=(unsigned char *)outbuf;
  132. inx=0; outx=0;
  133. deltax=0;
  134. while (inx<inw)
  135. {
  136. while (deltax<outw)
  137. {
  138. outscan[outx]=inscan[inx];
  139. outscan[outx+1]=inscan[inx+1];
  140. outscan[outx+2]=inscan[inx+2];
  141. deltax+=inw;
  142. outx+=3;
  143. }
  144. inx+=3;
  145. deltax-=outw;
  146. }
  147. outy++;
  148. deltay+=inh;
  149. (unsigned char *)outbuf+=stride;
  150. }
  151. iny++;
  152. deltay-=outh;
  153. ((unsigned char *)inbuf)+=inw;
  154. }
  155. }
  156. else if (bytesperpixel==2)
  157. {
  158. unsigned word *inscan, *outscan;
  159. deltay=0;
  160. while (iny<inh)
  161. {
  162. inscan=(unsigned word *)inbuf;
  163. while (deltay<outh)
  164. {
  165. outscan=(unsigned word *)outbuf;
  166. inx=0; outx=0;
  167. deltax=0;
  168. while (inx<inw)
  169. {
  170. while (deltax<outw)
  171. {
  172. outscan[outx]=inscan[inx];
  173. deltax+=inw;
  174. outx++;
  175. }
  176. inx++;
  177. deltax-=outw;
  178. }
  179. outy++;
  180. deltay+=inh;
  181. (unsigned char *)outbuf+=stride;
  182. }
  183. iny++;
  184. deltay-=outh;
  185. ((unsigned word *)inbuf)+=inw;
  186. }
  187. }
  188. else /* bytesperpixel==1 */
  189. {
  190. unsigned char *inscan, *outscan;
  191. deltay=0;
  192. while (iny<inh)
  193. {
  194. inscan=(unsigned char *)inbuf;
  195. _SlibDebug(_DEBUG_>1,
  196. ScDebugPrintf(NULL, "deltay=%d iny=%d outy=%d inh=%d outh=%d\n",
  197. deltay, iny, outy, inh, outh) );
  198. while (deltay<outh)
  199. {
  200. outscan=(unsigned char *)outbuf;
  201. inx=0; outx=0;
  202. deltax=0;
  203. while (inx<inw)
  204. {
  205. while (deltax<outw)
  206. {
  207. outscan[outx]=inscan[inx];
  208. deltax+=inw;
  209. outx++;
  210. }
  211. inx++;
  212. deltax-=outw;
  213. }
  214. outy++;
  215. deltay+=inh;
  216. (unsigned char *)outbuf+=stride;
  217. }
  218. iny++;
  219. deltay-=outh;
  220. ((unsigned char *)inbuf)+=inw;
  221. }
  222. }
  223. }
  224. SconStatus_t sconConvertVideo(SconInfo_t *Info, void *inbuf, dword inbufsize,
  225. void *outbuf, dword outbufsize)
  226. {
  227. unsigned dword informat, outformat;
  228. unsigned char *prescalebuf=inbuf;
  229. dword inwidth, inheight, outwidth, outheight, inbpp, outbpp, stride;
  230. SconStatus_t retval=SconErrorNone;
  231. SconBoolean_t scale, flip, sameformat;
  232. _SlibDebug(_VERBOSE_, printf("sconConvertVideo()\n") );
  233. if (inbuf==NULL || outbuf==NULL)
  234. return(SconErrorBadArgument);
  235. inwidth=Info->Input.vinfo.Width;
  236. inheight=Info->Input.vinfo.Height;
  237. informat=Info->Input.vinfo.FourCC;
  238. inbpp=Info->Input.vinfo.BPP;
  239. outwidth=Info->Output.vinfo.Width,
  240. outheight=Info->Output.vinfo.Height;
  241. outformat=Info->Output.vinfo.FourCC;
  242. outbpp=Info->Output.vinfo.BPP;
  243. scale=(Info->ScaleUp || Info->ScaleDown)?TRUE:FALSE;
  244. flip=Info->Flip;
  245. sameformat=Info->SameFormat;
  246. _SlibDebug(_VERBOSE_, ScDebugPrintf(NULL, "SconConvert() %dx%d(%c%c%c%c)->%dx%d(%c%c%c%c)\n",
  247. inwidth, inheight, informat&0xFF, (informat>>8)&0xFF, (informat>>16)&0xFF, (informat>>24)&0xFF,
  248. outwidth, outheight, outformat&0xFF, (outformat>>8)&0xFF, (outformat>>16)&0xFF, (outformat>>24)&0xFF) );
  249. _SlibDebug(_DEBUG_, ScDebugPrintf(NULL, "SconConvert() scale=%d flip=%d sameformat=%d\n",
  250. scale, flip, sameformat) );
  251. if (scale || flip)
  252. {
  253. if (Info->SImage==NULL && !sameformat)
  254. {
  255. SconVideoInfo_t int_vinfo;
  256. memcpy(&int_vinfo, &Info->Output.vinfo, sizeof(SconVideoInfo_t));
  257. int_vinfo.Width=inwidth;
  258. int_vinfo.Height=inheight;
  259. Info->SImageSize=sconCalcImageSize(&int_vinfo);
  260. if ((Info->SImage=ScPaMalloc(Info->SImageSize))==NULL)
  261. return(SconErrorMemory);
  262. }
  263. }
  264. else if (sameformat)
  265. {
  266. memcpy(outbuf, inbuf, Info->Input.vinfo.ImageSize);
  267. return(SconErrorNone);
  268. }
  269. if (sameformat)
  270. prescalebuf=(unsigned char *)inbuf;
  271. else
  272. {
  273. prescalebuf=(unsigned char *)(scale?Info->SImage:outbuf);
  274. stride=scale?(inwidth*((outbpp+7)>>3)):Info->Output.vinfo.Stride;
  275. if (flip) stride=-stride;
  276. if (IsYUV411Sep(informat)) /* YUV 4:1:1 Planar */
  277. {
  278. switch (outformat)
  279. {
  280. case BI_DECYUVDIB: /* YUV 4:2:2 Packed */
  281. case BI_YUY2: /* YUV 4:2:2 Packed */
  282. _SlibDebug(_VERBOSE_,
  283. ScDebugPrintf(NULL, "SconConvert() BI_YU12SEP->BI_YUY2\n") );
  284. ScSepYUVto422i((unsigned char *)inbuf,
  285. (unsigned char *)inbuf+(inwidth*inheight),
  286. (unsigned char *)inbuf+(inwidth*inheight*5)/4,
  287. (unsigned char *)prescalebuf, inwidth, inheight);
  288. break;
  289. case BI_YU16SEP: /* YUV 4:2:2 Planar */
  290. case BI_DECSEPYUVDIB:
  291. _SlibDebug(_VERBOSE_,
  292. ScDebugPrintf(NULL, "SconConvert() BI_YU12SEP->BI_YU16SEP\n") );
  293. {
  294. register int i;
  295. unsigned char *Ue=(unsigned char *)prescalebuf+inwidth*inheight,
  296. *Uo=Ue+inwidth/2;
  297. memcpy(prescalebuf, inbuf, inwidth*inheight);
  298. ((unsigned char *)inbuf)+=inwidth*inheight;
  299. for (i=inheight; i; i--)
  300. {
  301. memcpy(Ue, inbuf, inwidth/2);
  302. memcpy(Uo, inbuf, inwidth/2);
  303. ((unsigned char *)inbuf)+=inwidth/2;
  304. Ue+=inwidth;
  305. Uo+=inwidth;
  306. }
  307. }
  308. break;
  309. case BI_YVU9SEP: /* YUV 16:1:1 Planar */
  310. _SlibDebug(_VERBOSE_,
  311. ScDebugPrintf(NULL, "SconConvert() BI_YU12SEP->BI_YVU9\n") );
  312. ScConvert411sTo1611s((unsigned char *)inbuf,
  313. (unsigned char *)prescalebuf,
  314. ((unsigned char *)prescalebuf)+(outwidth*outheight),
  315. ((unsigned char *)prescalebuf)+(outwidth*outheight*9)/8,
  316. inwidth, flip?-inheight:inheight);
  317. break;
  318. case BI_RGB:
  319. case BI_BITFIELDS:
  320. case BI_DECXIMAGEDIB:
  321. if (outbpp==16)
  322. {
  323. if (Info->Table==NULL)
  324. sconInitYUVtoRGB(Info);
  325. if (Info->Output.vinfo.RGBmasks==565)
  326. scon420ToRGB565((unsigned char *)inbuf,
  327. (unsigned char *)prescalebuf,
  328. inwidth, inheight, stride, Info->Table);
  329. }
  330. else if (outbpp=24)
  331. {
  332. if (Info->Table==NULL)
  333. sconInitYUVtoRGB(Info);
  334. scon420ToRGB888((unsigned char *)inbuf,
  335. (unsigned char *)prescalebuf,
  336. inwidth, inheight, stride, Info->Table);
  337. }
  338. else
  339. {
  340. BITMAPINFOHEADER outbmh;
  341. outbmh.biWidth=inwidth;
  342. outbmh.biHeight=inheight;
  343. outbmh.biCompression=outformat;
  344. outbmh.biBitCount=(WORD)outbpp;
  345. stride=scale?inwidth:outwidth;
  346. _SlibDebug(_VERBOSE_,
  347. ScDebugPrintf(NULL, "SconConvert() BI_YU12SEP->RGB\n") );
  348. ScYuv411ToRgb(&outbmh, (unsigned char *)inbuf,
  349. (unsigned char *)inbuf+(inwidth*inheight),
  350. (unsigned char *)inbuf+(inwidth*inheight*5)/4,
  351. (unsigned char *)prescalebuf,
  352. inwidth, inheight, stride);
  353. }
  354. break;
  355. default:
  356. _SlibDebug(_VERBOSE_,
  357. ScDebugPrintf(NULL, "SconConvert() BI_YU12SEP->Unsupported\n") );
  358. }
  359. }
  360. else if (IsYUV422Sep(informat)) /* YUV 4:2:2 Planar */
  361. {
  362. switch (outformat)
  363. {
  364. case BI_YU12SEP: /* YUV 4:1:1 Planar */
  365. _SlibDebug(_VERBOSE_,
  366. ScDebugPrintf(NULL, "SconConvert() 422 Planar->BI_YU12SEP\n") );
  367. ScConvert422PlanarTo411_C((unsigned char *)inbuf,
  368. (unsigned char *)prescalebuf,
  369. ((unsigned char *)prescalebuf)+(outwidth*outheight),
  370. ((unsigned char *)prescalebuf)+(outwidth*outheight*5)/4,
  371. inwidth, inheight);
  372. break;
  373. case BI_DECYUVDIB: /* YUV 4:2:2 Packed */
  374. case BI_YUY2:
  375. ScConvert422PlanarTo422i_C((unsigned char *)inbuf,
  376. ((unsigned char *)inbuf)+(inwidth*inheight),
  377. ((unsigned char *)inbuf)+(inwidth*inheight*3)/2,
  378. (unsigned char *)prescalebuf,
  379. inwidth, inheight);
  380. break;
  381. case BI_RGB:
  382. case BI_BITFIELDS:
  383. case BI_DECXIMAGEDIB:
  384. _SlibDebug(_VERBOSE_,
  385. ScDebugPrintf(NULL, "SconConvert() BI_YU16SEP->BI_RGB Unsupported\n") );
  386. if (outbpp==16)
  387. {
  388. if (Info->Table==NULL)
  389. sconInitYUVtoRGB(Info);
  390. if (Info->Output.vinfo.RGBmasks==565)
  391. scon422ToRGB565((unsigned char *)inbuf,
  392. (unsigned char *)prescalebuf,
  393. inwidth, inheight, stride, Info->Table);
  394. }
  395. else if (outbpp==24)
  396. {
  397. if (Info->Table==NULL)
  398. sconInitYUVtoRGB(Info);
  399. scon422ToRGB888((unsigned char *)inbuf,
  400. (unsigned char *)prescalebuf,
  401. inwidth, inheight, stride, Info->Table);
  402. }
  403. else
  404. retval=SconErrorUnsupportedFormat;
  405. break;
  406. default:
  407. retval=SconErrorUnsupportedFormat;
  408. _SlibDebug(_VERBOSE_,
  409. ScDebugPrintf(NULL, "SconConvert() BI_YU16SEP->Unsupported\n") );
  410. }
  411. }
  412. else if (IsYUV422Packed(informat)) /* YUV 4:2:2 Packed */
  413. {
  414. switch (outformat)
  415. {
  416. case BI_YU12SEP: /* YUV 4:1:1 Planar */
  417. _SlibDebug(_VERBOSE_,
  418. ScDebugPrintf(NULL, "SconConvert() 422 Packed->BI_YU12SEP\n") );
  419. ScConvert422ToYUV_char((unsigned char *)inbuf,
  420. (unsigned char *)prescalebuf,
  421. ((unsigned char *)prescalebuf)+(outwidth*outheight),
  422. ((unsigned char *)prescalebuf)+(outwidth*outheight*5)/4,
  423. inwidth, flip?-inheight:inheight);
  424. break;
  425. case BI_YU16SEP: /* 4:2:2 Packed -> 4:2:2 Planar */
  426. case BI_DECSEPYUVDIB:
  427. _SlibDebug(_VERBOSE_,
  428. ScDebugPrintf(NULL, "SconConvert() BI_YUY2->BI_YU16SEP\n") );
  429. {
  430. register int i;
  431. unsigned char *Y=prescalebuf,
  432. *U=(unsigned char *)prescalebuf+(inwidth*inheight),
  433. *V=U+(inwidth*inheight)/2;
  434. for (i=(inwidth*inheight)/2; i; i--)
  435. {
  436. *Y++ = *((unsigned char *)inbuf)++;
  437. *U++ = *((unsigned char *)inbuf)++;
  438. *Y++ = *((unsigned char *)inbuf)++;
  439. *V++ = *((unsigned char *)inbuf)++;
  440. }
  441. }
  442. break;
  443. case BI_RGB: /* 4:2:2 Packed -> RGB */
  444. if (outbpp!=16)
  445. return(SconErrorUnsupportedFormat);
  446. else
  447. {
  448. u_short *Sout;
  449. int i, Y1, Y2, U, V, Luma;
  450. int R1,R2, G1,G2, B1,B2;
  451. _SlibDebug(_VERBOSE_,
  452. ScDebugPrintf(NULL, "SconConvert() BI_YUY2->BI_RGB\n") );
  453. Sout = (u_short *)prescalebuf;
  454. for (i=(inwidth*inheight)/4; i; i--)
  455. {
  456. Y1=(int)*((unsigned char *)inbuf)++;
  457. U=(int)(*((unsigned char *)inbuf)++) - 128;
  458. Y2=(int)*((unsigned char *)inbuf)++;
  459. V=(int)(*((unsigned char *)inbuf)++) - 128;
  460. if (U || V) {
  461. R1 = R2 = (int) ( + (1.596 * V));
  462. G1 = G2 = (int) (- (0.391 * U) - (0.813 * V));
  463. B1 = B2 = (int) (+ (2.018 * U) );
  464. } else { R1=R2=G1=G2=B1=B2=0; }
  465. Luma = (int) ((float)(Y1 - 16) * (float)1.164);
  466. R1 += Luma; G1 += Luma; B1 += Luma;
  467. Luma = (int) ((float)(Y2 - 16) * (float)1.164);
  468. R2 += Luma; G2 += Luma; B2 += Luma;
  469. if ((R1 | G1 | B1 | R2 | G2 | B2) & 0xffffff00) {
  470. if (R1<0) R1=0; else if (R1>255) R1=255;
  471. if (G1<0) G1=0; else if (G1>255) G1=255;
  472. if (B1<0) B1=0; else if (B1>255) B1=255;
  473. if (R2<0) R2=0; else if (R2>255) R2=255;
  474. if (G2<0) G2=0; else if (G2>255) G2=255;
  475. if (B2<0) B2=0; else if (B2>255) B2=255;
  476. }
  477. #if 1 /* RGB 565 - 16 bit */
  478. *(Sout++) = ((R1&0xf8)<<8)|((G1&0xfC)<<3)|((B1&0xf8)>>3);
  479. *(Sout++) = ((R2&0xf8)<<8)|((G2&0xfC)<<3)|((B2&0xf8)>>3);
  480. #else /* RGB 555 - 15 bit */
  481. *(Sout++) = ((R1&0xf8)<<7)|((G1&0xf8)<<2)|((B1&0xf8)>>3);
  482. *(Sout++) = ((R2&0xf8)<<7)|((G2&0xf8)<<2)|((B2&0xf8)>>3);
  483. #endif
  484. }
  485. }
  486. break;
  487. default:
  488. retval=SconErrorUnsupportedFormat;
  489. _SlibDebug(_VERBOSE_,
  490. ScDebugPrintf(NULL, "SconConvert() BI_YUY2->Unsupported\n") );
  491. }
  492. }
  493. else if (IsRGBPacked(informat)) /* RGB Packed */
  494. {
  495. switch (outformat)
  496. {
  497. case BI_YU12SEP: /* YUV 4:1:1 Planar */
  498. if (inbpp==16)
  499. ScConvertRGB555To411s((unsigned char *)inbuf,
  500. (unsigned char *)prescalebuf,
  501. inwidth, flip?-inheight:inheight);
  502. else
  503. {
  504. if (Info->Table==NULL)
  505. sconInitRGBtoYUV(Info);
  506. sconRGB888To420((unsigned char *)inbuf,
  507. (unsigned char *)prescalebuf,
  508. inwidth, inheight, (flip?-inwidth:inwidth)*3, Info->Table);
  509. // ScConvertRGB24To411s((unsigned char *)inbuf,
  510. // (unsigned char *)prescalebuf,
  511. // ((unsigned char *)prescalebuf)+(inwidth*inheight),
  512. // ((unsigned char *)prescalebuf)+(inwidth*inheight*5)/4,
  513. // inwidth, flip?-inheight:inheight);
  514. }
  515. break;
  516. case BI_RGB: /* RGB */
  517. retval=SconErrorUnsupportedFormat;
  518. break;
  519. default:
  520. retval=SconErrorUnsupportedFormat;
  521. _SlibDebug(_VERBOSE_,
  522. ScDebugPrintf(NULL, "SconConvert() BI_RGB->Unsupported\n") );
  523. }
  524. }
  525. else if (IsYUV1611Sep(informat)) /* YUV 16:1:1 Planar */
  526. {
  527. switch (outformat)
  528. {
  529. case BI_YU12SEP: /* YUV 4:1:1 Planar */
  530. _SlibDebug(_VERBOSE_,
  531. ScDebugPrintf(NULL, "SconConvert() BI_YVU9->BI_YU12SEP\n") );
  532. ScConvert1611sTo411s((unsigned char *)inbuf,
  533. (unsigned char *)prescalebuf,
  534. ((unsigned char *)prescalebuf)+(outwidth*outheight),
  535. ((unsigned char *)prescalebuf)+(outwidth*outheight*5)/4,
  536. inwidth, flip?-inheight:inheight);
  537. break;
  538. case BI_YU16SEP: /* YUV 4:2:2 Planar */
  539. _SlibDebug(_VERBOSE_,
  540. ScDebugPrintf(NULL, "SconConvert() BI_YVU9->BI_YU16SEP\n") );
  541. ScConvert1611sTo422s((unsigned char *)inbuf,
  542. (unsigned char *)prescalebuf,
  543. ((unsigned char *)prescalebuf)+(outwidth*outheight),
  544. ((unsigned char *)prescalebuf)+(outwidth*outheight*3)/2,
  545. inwidth, flip?-inheight:inheight);
  546. break;
  547. case BI_DECYUVDIB: /* YUV 4:2:2 Packed */
  548. case BI_YUY2:
  549. _SlibDebug(_VERBOSE_,
  550. ScDebugPrintf(NULL, "SconConvert() BI_YVU9->BI_YUY2\n") );
  551. ScConvert1611sTo422i((unsigned char *)inbuf,
  552. (unsigned char *)prescalebuf, inwidth, flip?-inheight:inheight);
  553. break;
  554. default:
  555. retval=SconErrorUnsupportedFormat;
  556. _SlibDebug(_VERBOSE_,
  557. ScDebugPrintf(NULL, "SconConvert() BI_YVU9->Unsupported\n") );
  558. }
  559. }
  560. _SlibDebug(_VERBOSE_ && retval==SconErrorUnsupportedFormat,
  561. ScDebugPrintf(NULL, "SconConvert() Unsupported->Unsupported\n"));
  562. }
  563. if (retval==SconErrorNone && scale)
  564. {
  565. if (IsRGBPacked(outformat))
  566. {
  567. /* Scaling RGB */
  568. _SlibDebug(_VERBOSE_,
  569. ScDebugPrintf(NULL, "SconConvert() Scaling BI_RGB\n") );
  570. stride=Info->Output.vinfo.Stride;
  571. sconScaleFrame((unsigned word)((outbpp+7)>>3),
  572. prescalebuf, inwidth, inheight,
  573. outbuf, outwidth, outheight, stride);
  574. }
  575. else if (IsYUV411Sep(outformat)) /* YUV 4:1:1 Planar */
  576. {
  577. _SlibDebug(_VERBOSE_, ScDebugPrintf(NULL, "SconConvert() Scaling BI_YU12SEP\n") );
  578. sconScaleFrame(1,
  579. prescalebuf, inwidth, inheight,
  580. outbuf, outwidth, outheight, outwidth);
  581. sconScaleFrame(1,
  582. ((unsigned char *)prescalebuf)+(inwidth*inheight),
  583. inwidth/2, inheight,
  584. ((unsigned char *)outbuf)+(outwidth*outheight),
  585. outwidth/2, outheight, outwidth/2);
  586. }
  587. else if (IsYUV422Packed(outformat)) /* YUV 4:2:2 Packed */
  588. {
  589. stride=Info->Output.vinfo.Stride;
  590. sconScaleFrame(4,
  591. prescalebuf, inwidth/2, inheight,
  592. outbuf, outwidth/2, outheight, stride);
  593. }
  594. else if (IsYUV422Sep(outformat)) /* YUV 4:2:2 Planar */
  595. {
  596. sconScaleFrame(1,
  597. prescalebuf, inwidth, inheight,
  598. outbuf, outwidth, outheight, outwidth);
  599. sconScaleFrame(1,
  600. ((unsigned char *)prescalebuf)+(inwidth*inheight),
  601. inwidth, inheight,
  602. ((unsigned char *)outbuf)+(outwidth*outheight),
  603. outwidth, outheight, outwidth);
  604. }
  605. else if (IsYUV1611Sep(outformat)) /* YUV 16:1:1 Planar */
  606. {
  607. sconScaleFrame(1,
  608. prescalebuf, inwidth, inheight,
  609. outbuf, outwidth, outheight, outwidth);
  610. sconScaleFrame(1,
  611. ((unsigned char *)prescalebuf)+(inwidth*inheight),
  612. inwidth/8, inheight,
  613. ((unsigned char *)outbuf)+(outwidth*outheight),
  614. outwidth/8, outheight, outwidth/8);
  615. }
  616. else
  617. {
  618. retval=SconErrorUnsupportedFormat;
  619. _SlibDebug(_VERBOSE_,
  620. ScDebugPrintf(NULL, "SconConvert() Scaling Unsupported\n") );
  621. }
  622. }
  623. return(retval);
  624. }
  625.