jpegdechdrs.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*------------------------------------------------------------------------------
  2. -- --
  3. -- This software is confidential and proprietary and may be used --
  4. -- only as expressly authorized by a licensing agreement from --
  5. -- --
  6. -- Hantro Products Oy. --
  7. -- --
  8. -- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
  9. -- ALL RIGHTS RESERVED --
  10. -- --
  11. -- The entire notice above must be reproduced --
  12. -- on all copies and should not be removed. --
  13. -- --
  14. --------------------------------------------------------------------------------
  15. --
  16. -- Description : Jpeg decoder header decoding source code
  17. --
  18. ------------------------------------------------------------------------------
  19. --
  20. -- Version control information, please leave untouched.
  21. --
  22. -- $RCSfile: jpegdechdrs.c,v $
  23. -- $Revision: 1.10 $
  24. -- $Date: 2010/05/12 11:58:33 $
  25. --
  26. ------------------------------------------------------------------------------*/
  27. /*------------------------------------------------------------------------------
  28. Table of contents
  29. 1. Include headers
  30. 2. External compiler flags
  31. 3. Module defines
  32. 4. Local function prototypes
  33. 5. Functions
  34. - JpegDecDecodeFrame
  35. - JpegDecDecodeQuantTables
  36. - JpegDecDecodeHuffmanTables
  37. ------------------------------------------------------------------------------*/
  38. /*------------------------------------------------------------------------------
  39. 1. Include headers
  40. ------------------------------------------------------------------------------*/
  41. #include "jpegdechdrs.h"
  42. #include "jpegdecutils.h"
  43. #include "jpegdecmarkers.h"
  44. #include "jpegdecinternal.h"
  45. #include "jpegdecscan.h"
  46. #include "jpegdecapi.h"
  47. #include "dwl.h"
  48. /*------------------------------------------------------------------------------
  49. 2. External compiler flags
  50. --------------------------------------------------------------------------------
  51. --------------------------------------------------------------------------------
  52. 3. Module defines
  53. ------------------------------------------------------------------------------*/
  54. /*------------------------------------------------------------------------------
  55. 4. Local function prototypes
  56. ------------------------------------------------------------------------------*/
  57. /*------------------------------------------------------------------------------
  58. 5. Functions
  59. ------------------------------------------------------------------------------*/
  60. /*------------------------------------------------------------------------------
  61. Function name: JpegDecDecodeFrame
  62. Functional description:
  63. Decodes frame headers
  64. Inputs:
  65. JpegDecContainer *pDecData Pointer to JpegDecContainer structure
  66. Outputs:
  67. OK/NOK
  68. ------------------------------------------------------------------------------*/
  69. JpegDecRet JpegDecDecodeFrameHdr(JpegDecContainer * pDecData)
  70. {
  71. u32 i;
  72. u32 width, height;
  73. u32 tmp1, tmp2;
  74. u32 Hmax = 0;
  75. u32 Vmax = 0;
  76. u32 size = 0;
  77. JpegDecRet retCode;
  78. retCode = JPEGDEC_OK;
  79. /* frame header length */
  80. pDecData->frame.Lf = JpegDecGet2Bytes(&(pDecData->stream));
  81. /* check if there is enough data */
  82. if(((pDecData->stream.readBits / 8) + pDecData->frame.Lf) >
  83. pDecData->stream.streamLength)
  84. return (JPEGDEC_STRM_ERROR);
  85. /* Sample precision */
  86. pDecData->frame.P = JpegDecGetByte(&(pDecData->stream));
  87. if(pDecData->frame.P != 8)
  88. {
  89. JPEGDEC_TRACE_INTERNAL(("if ( pDecData->frame.P != 8)\n"));
  90. return (JPEGDEC_UNSUPPORTED);
  91. }
  92. /* Number of Lines */
  93. pDecData->frame.Y = JpegDecGet2Bytes(&(pDecData->stream));
  94. if(pDecData->frame.Y < 1)
  95. {
  96. return (JPEGDEC_UNSUPPORTED);
  97. }
  98. pDecData->frame.hwY = pDecData->frame.Y;
  99. /* round up to next multiple-of-16 */
  100. pDecData->frame.hwY += 0xf;
  101. pDecData->frame.hwY &= ~(0xf);
  102. /* Number of samples per line */
  103. pDecData->frame.X = JpegDecGet2Bytes(&(pDecData->stream));
  104. if(pDecData->frame.X < 1)
  105. {
  106. return (JPEGDEC_UNSUPPORTED);
  107. }
  108. pDecData->frame.hwX = pDecData->frame.X;
  109. /* round up to next multiple-of-16 */
  110. pDecData->frame.hwX += 0xf;
  111. pDecData->frame.hwX &= ~(0xf);
  112. /* for internal() */
  113. pDecData->info.X = pDecData->frame.hwX;
  114. pDecData->info.Y = pDecData->frame.hwY;
  115. /* check for minimum and maximum dimensions */
  116. if(pDecData->frame.hwX < pDecData->minSupportedWidth ||
  117. pDecData->frame.hwY < pDecData->minSupportedHeight ||
  118. pDecData->frame.hwX > pDecData->maxSupportedWidth ||
  119. pDecData->frame.hwY > pDecData->maxSupportedHeight ||
  120. (pDecData->frame.hwX * pDecData->frame.hwY) >
  121. pDecData->maxSupportedPixelAmount)
  122. {
  123. JPEGDEC_TRACE_INTERNAL(("FRAME: Unsupported size\n"));
  124. return (JPEGDEC_UNSUPPORTED);
  125. }
  126. /* Number of components */
  127. pDecData->frame.Nf = JpegDecGetByte(&(pDecData->stream));
  128. if((pDecData->frame.Nf != 3) && (pDecData->frame.Nf != 1))
  129. {
  130. JPEGDEC_TRACE_INTERNAL(("pDecData->frame.Nf != 3 && pDecData->frame.Nf != 1\n"));
  131. return (JPEGDEC_UNSUPPORTED);
  132. }
  133. /* save component specific data */
  134. /* Nf == number of components */
  135. for(i = 0; i < pDecData->frame.Nf; i++)
  136. {
  137. pDecData->frame.component[i].C = JpegDecGetByte(&(pDecData->stream));
  138. if(i == 0) /* for the first component */
  139. {
  140. /* if first component id is something else than 1 (jfif) */
  141. pDecData->scan.index = pDecData->frame.component[i].C;
  142. }
  143. else
  144. {
  145. /* if component ids 'jumps' */
  146. if((pDecData->frame.component[i - 1].C + 1) !=
  147. pDecData->frame.component[i].C)
  148. {
  149. JPEGDEC_TRACE_INTERNAL(("component ids 'jumps'\n"));
  150. return (JPEGDEC_UNSUPPORTED);
  151. }
  152. }
  153. tmp1 = JpegDecGetByte(&(pDecData->stream));
  154. pDecData->frame.component[i].H = tmp1 >> 4;
  155. if(pDecData->frame.component[i].H > Hmax)
  156. {
  157. Hmax = pDecData->frame.component[i].H;
  158. }
  159. pDecData->frame.component[i].V = tmp1 & 0xF;
  160. if(pDecData->frame.component[i].V > Vmax)
  161. {
  162. Vmax = pDecData->frame.component[i].V;
  163. }
  164. pDecData->frame.component[i].Tq = JpegDecGetByte(&(pDecData->stream));
  165. }
  166. if(pDecData->frame.Nf == 1)
  167. {
  168. Hmax = Vmax = 1;
  169. pDecData->frame.component[0].H = 1;
  170. pDecData->frame.component[0].V = 1;
  171. }
  172. else if(Hmax == 0 || Vmax == 0)
  173. {
  174. JPEGDEC_TRACE_INTERNAL(("Hmax == 0 || Vmax == 0 \n"));
  175. return (JPEGDEC_UNSUPPORTED);
  176. }
  177. /* JPEG_YCBCR411 horizontal size has to be multiple of 32 pels */
  178. if(Hmax == 4 && (pDecData->frame.hwX & 0x1F))
  179. {
  180. /* round up to next multiple-of-32 */
  181. pDecData->frame.hwX += 16;
  182. pDecData->info.X = pDecData->frame.hwX;
  183. /* check for minimum and maximum dimensions */
  184. if(pDecData->frame.hwX > pDecData->maxSupportedWidth ||
  185. (pDecData->frame.hwX * pDecData->frame.hwY) >
  186. pDecData->maxSupportedPixelAmount)
  187. {
  188. JPEGDEC_TRACE_INTERNAL(("FRAME: Unsupported size\n"));
  189. return (JPEGDEC_UNSUPPORTED);
  190. }
  191. }
  192. /* set image pointers, calculate pixelPerRow for each component */
  193. width = ((pDecData->frame.hwX + Hmax * 8 - 1) / (Hmax * 8)) * Hmax * 8;
  194. height = ((pDecData->frame.hwY + Vmax * 8 - 1) / (Vmax * 8)) * Vmax * 8;
  195. /* calculate numMcuInRow and numMcuInFrame */
  196. ASSERT(Hmax != 0);
  197. ASSERT(Vmax != 0);
  198. pDecData->frame.numMcuInRow = width / (8 * Hmax);
  199. pDecData->frame.numMcuInFrame = pDecData->frame.numMcuInRow *
  200. (height / (8 * Vmax));
  201. /* reset mcuNumbers */
  202. pDecData->frame.mcuNumber = 0;
  203. pDecData->frame.row = pDecData->frame.col = 0;
  204. for(i = 0; i < pDecData->frame.Nf; i++)
  205. {
  206. ASSERT(i <= 2);
  207. tmp1 = (width * pDecData->frame.component[i].H + Hmax - 1) / Hmax;
  208. tmp2 = (height * pDecData->frame.component[i].V + Vmax - 1) / Vmax;
  209. size += tmp1 * tmp2;
  210. /* pixels per row */
  211. pDecData->image.pixelsPerRow[i] = tmp1;
  212. pDecData->image.columns[i] = tmp2;
  213. pDecData->frame.numBlocks[i] =
  214. (((pDecData->frame.hwX * pDecData->frame.component[i].H) / Hmax +
  215. 7) >> 3) * (((pDecData->frame.hwY *
  216. pDecData->frame.component[i].V) / Vmax + 7) >> 3);
  217. if(i == 0)
  218. {
  219. pDecData->image.sizeLuma = size;
  220. }
  221. }
  222. pDecData->image.size = size;
  223. pDecData->image.sizeChroma = size - pDecData->image.sizeLuma;
  224. /* set mode & calculate rlc tmp size */
  225. retCode = JpegDecMode(pDecData);
  226. if(retCode != JPEGDEC_OK)
  227. {
  228. return (retCode);
  229. }
  230. return (JPEGDEC_OK);
  231. }
  232. /*------------------------------------------------------------------------------
  233. Function name: JpegDecDecodeQuantTables
  234. Functional description:
  235. Decodes quantisation tables from the stream
  236. Inputs:
  237. JpegDecContainer *pDecData Pointer to JpegDecContainer structure
  238. Outputs:
  239. OK (0)
  240. NOK (-1)
  241. ------------------------------------------------------------------------------*/
  242. JpegDecRet JpegDecDecodeQuantTables(JpegDecContainer * pDecData)
  243. {
  244. u32 t, tmp, i;
  245. StreamStorage *pStream = &(pDecData->stream);
  246. pDecData->quant.Lq = JpegDecGet2Bytes(pStream);
  247. /* check if there is enough data for tables */
  248. if(((pStream->readBits / 8) + pDecData->quant.Lq) > pStream->streamLength)
  249. return (JPEGDEC_STRM_ERROR);
  250. t = 4;
  251. while(t < pDecData->quant.Lq)
  252. {
  253. /* Tq value selects what table the components use */
  254. /* read tables and write to decData->quant */
  255. tmp = JpegDecGetByte(pStream);
  256. t++;
  257. /* supporting only 8 bits / sample */
  258. if((tmp >> 4) != 0)
  259. {
  260. return (JPEGDEC_UNSUPPORTED);
  261. }
  262. tmp &= 0xF;
  263. /* set the quantisation table pointer */
  264. if(tmp == 0)
  265. {
  266. JPEGDEC_TRACE_INTERNAL(("qtable0\n"));
  267. pDecData->quant.table = pDecData->quant.table0;
  268. }
  269. else if(tmp == 1)
  270. {
  271. JPEGDEC_TRACE_INTERNAL(("qtable1\n"));
  272. pDecData->quant.table = pDecData->quant.table1;
  273. }
  274. else if(tmp == 2)
  275. {
  276. JPEGDEC_TRACE_INTERNAL(("qtable2\n"));
  277. pDecData->quant.table = pDecData->quant.table2;
  278. }
  279. else if(tmp == 3)
  280. {
  281. JPEGDEC_TRACE_INTERNAL(("qtable3\n"));
  282. pDecData->quant.table = pDecData->quant.table3;
  283. }
  284. else
  285. {
  286. return (JPEGDEC_UNSUPPORTED);
  287. }
  288. for(i = 0; i < 64; i++)
  289. {
  290. pDecData->quant.table[i] = JpegDecGetByte(pStream);
  291. t++;
  292. }
  293. }
  294. return (JPEGDEC_OK);
  295. }
  296. /*------------------------------------------------------------------------------
  297. Function name: JpegDecDecodeHuffmanTables
  298. Functional description:
  299. Decodes huffman tables from the stream
  300. Inputs:
  301. DecData *JpegDecContainer Pointer to JpegDecContainer structure
  302. Outputs:
  303. OK (0)
  304. NOK (-1)
  305. ------------------------------------------------------------------------------*/
  306. JpegDecRet JpegDecDecodeHuffmanTables(JpegDecContainer * pDecData)
  307. {
  308. u32 i, len, Tc, Th, tmp;
  309. i32 j;
  310. StreamStorage *pStream = &(pDecData->stream);
  311. pDecData->vlc.Lh = JpegDecGet2Bytes(pStream);
  312. /* check if there is enough data for tables */
  313. if(((pStream->readBits / 8) + pDecData->vlc.Lh) > pStream->streamLength)
  314. return (JPEGDEC_STRM_ERROR);
  315. /* four bytes already read in */
  316. len = 4;
  317. while(len < pDecData->vlc.Lh)
  318. {
  319. tmp = JpegDecGetByte(pStream);
  320. len++;
  321. Tc = tmp >> 4; /* Table class */
  322. if(Tc != 0 && Tc != 1)
  323. {
  324. return (JPEGDEC_UNSUPPORTED);
  325. }
  326. Th = tmp & 0xF; /* Huffman table identifier */
  327. /* only two tables in baseline allowed */
  328. if((pDecData->frame.codingType == SOF0) && (Th > 1))
  329. {
  330. return (JPEGDEC_UNSUPPORTED);
  331. }
  332. /* four tables in progressive allowed */
  333. if((pDecData->frame.codingType == SOF2) && (Th > 3))
  334. {
  335. return (JPEGDEC_UNSUPPORTED);
  336. }
  337. /* set the table pointer */
  338. if(Tc)
  339. {
  340. /* Ac table */
  341. switch (Th)
  342. {
  343. case 0:
  344. JPEGDEC_TRACE_INTERNAL(("ac0\n"));
  345. pDecData->vlc.table = &(pDecData->vlc.acTable0);
  346. break;
  347. case 1:
  348. JPEGDEC_TRACE_INTERNAL(("ac1\n"));
  349. pDecData->vlc.table = &(pDecData->vlc.acTable1);
  350. break;
  351. case 2:
  352. JPEGDEC_TRACE_INTERNAL(("ac2\n"));
  353. pDecData->vlc.table = &(pDecData->vlc.acTable2);
  354. break;
  355. case 3:
  356. JPEGDEC_TRACE_INTERNAL(("ac3\n"));
  357. pDecData->vlc.table = &(pDecData->vlc.acTable3);
  358. break;
  359. default:
  360. return (JPEGDEC_UNSUPPORTED);
  361. }
  362. }
  363. else
  364. {
  365. /* Dc table */
  366. switch (Th)
  367. {
  368. case 0:
  369. JPEGDEC_TRACE_INTERNAL(("dc0\n"));
  370. pDecData->vlc.table = &(pDecData->vlc.dcTable0);
  371. break;
  372. case 1:
  373. JPEGDEC_TRACE_INTERNAL(("dc1\n"));
  374. pDecData->vlc.table = &(pDecData->vlc.dcTable1);
  375. break;
  376. case 2:
  377. JPEGDEC_TRACE_INTERNAL(("dc2\n"));
  378. pDecData->vlc.table = &(pDecData->vlc.dcTable2);
  379. break;
  380. case 3:
  381. JPEGDEC_TRACE_INTERNAL(("dc3\n"));
  382. pDecData->vlc.table = &(pDecData->vlc.dcTable3);
  383. break;
  384. default:
  385. return (JPEGDEC_UNSUPPORTED);
  386. }
  387. }
  388. tmp = 0;
  389. /* read in the values of list BITS */
  390. for(i = 0; i < 16; i++)
  391. {
  392. tmp += pDecData->vlc.table->bits[i] = JpegDecGetByte(pStream);
  393. len++;
  394. }
  395. /* allocate memory for HUFFVALs */
  396. if(pDecData->vlc.table->vals != NULL)
  397. {
  398. /* free previously reserved table */
  399. DWLfree(pDecData->vlc.table->vals);
  400. }
  401. pDecData->vlc.table->vals = (u32 *) DWLmalloc(sizeof(u32) * tmp);
  402. /* set the table length */
  403. pDecData->vlc.table->tableLength = tmp;
  404. /* read in the HUFFVALs */
  405. for(i = 0; i < tmp; i++)
  406. {
  407. pDecData->vlc.table->vals[i] = JpegDecGetByte(pStream);
  408. len++;
  409. }
  410. /* first and last lengths */
  411. for(i = 0; i < 16; i++)
  412. {
  413. if(pDecData->vlc.table->bits[i] != 0)
  414. {
  415. pDecData->vlc.table->start = i;
  416. break;
  417. }
  418. }
  419. for(j = 15; j >= 0; j--)
  420. {
  421. if(pDecData->vlc.table->bits[j] != 0)
  422. {
  423. pDecData->vlc.table->last = ((u32) j + 1);
  424. break;
  425. }
  426. }
  427. }
  428. return (JPEGDEC_OK);
  429. }
  430. /*------------------------------------------------------------------------------
  431. Function name: JpegDecMode
  432. Functional description:
  433. check YCBCR mode
  434. Inputs:
  435. JpegDecContainer *pDecData Pointer to JpegDecContainer structure
  436. Outputs:
  437. OK/NOK
  438. ------------------------------------------------------------------------------*/
  439. JpegDecRet JpegDecMode(JpegDecContainer * pDecData)
  440. {
  441. /* check input format */
  442. if(pDecData->frame.Nf == 3)
  443. {
  444. /* JPEG_YCBCR420 */
  445. if(pDecData->frame.component[0].H == 2 &&
  446. pDecData->frame.component[0].V == 2 &&
  447. pDecData->frame.component[1].H == 1 &&
  448. pDecData->frame.component[1].V == 1 &&
  449. pDecData->frame.component[2].H == 1 &&
  450. pDecData->frame.component[2].V == 1)
  451. {
  452. pDecData->info.yCbCrMode = JPEGDEC_YUV420;
  453. pDecData->info.X = pDecData->frame.hwX;
  454. pDecData->info.Y = pDecData->frame.hwY;
  455. /* calculate new output size if slice mode used */
  456. if(pDecData->info.sliceMbSetValue)
  457. {
  458. /* Y */
  459. pDecData->image.sizeLuma = (pDecData->info.X *
  460. (pDecData->info.sliceMbSetValue *
  461. 16));
  462. /* CbCr */
  463. pDecData->image.sizeChroma = pDecData->image.sizeLuma / 2;
  464. }
  465. }
  466. /* JPEG_YCBCR422 */
  467. else if(pDecData->frame.component[0].H == 2 &&
  468. pDecData->frame.component[0].V == 1 &&
  469. pDecData->frame.component[1].H == 1 &&
  470. pDecData->frame.component[1].V == 1 &&
  471. pDecData->frame.component[2].H == 1 &&
  472. pDecData->frame.component[2].V == 1)
  473. {
  474. pDecData->info.yCbCrMode = JPEGDEC_YUV422;
  475. pDecData->info.X = (pDecData->frame.hwX);
  476. pDecData->info.Y = (pDecData->frame.hwY);
  477. /* check if fill needed */
  478. if((pDecData->frame.Y & 0xF) && (pDecData->frame.Y & 0xF) <= 8)
  479. pDecData->info.fillBottom = 1;
  480. /* calculate new output size if slice mode used */
  481. if(pDecData->info.sliceMbSetValue)
  482. {
  483. /* Y */
  484. pDecData->image.sizeLuma = (pDecData->info.X *
  485. (pDecData->info.sliceMbSetValue *
  486. 16));
  487. /* CbCr */
  488. pDecData->image.sizeChroma = pDecData->image.sizeLuma;
  489. }
  490. }
  491. /* JPEG_YCBCR440 */
  492. else if(pDecData->frame.component[0].H == 1 &&
  493. pDecData->frame.component[0].V == 2 &&
  494. pDecData->frame.component[1].H == 1 &&
  495. pDecData->frame.component[1].V == 1 &&
  496. pDecData->frame.component[2].H == 1 &&
  497. pDecData->frame.component[2].V == 1)
  498. {
  499. pDecData->info.yCbCrMode = JPEGDEC_YUV440;
  500. pDecData->info.X = (pDecData->frame.hwX);
  501. pDecData->info.Y = (pDecData->frame.hwY);
  502. /* check if fill needed */
  503. if((pDecData->frame.X & 0xF) && (pDecData->frame.X & 0xF) <= 8)
  504. pDecData->info.fillRight = 1;
  505. /* calculate new output size if slice mode used */
  506. if(pDecData->info.sliceMbSetValue)
  507. {
  508. /* Y */
  509. pDecData->image.sizeLuma = (pDecData->info.X *
  510. (pDecData->info.sliceMbSetValue *
  511. 16));
  512. /* CbCr */
  513. pDecData->image.sizeChroma = pDecData->image.sizeLuma;
  514. }
  515. }
  516. /* JPEG_YCBCR444 : NOT SUPPORTED */
  517. else if(pDecData->frame.component[0].H == 1 &&
  518. pDecData->frame.component[0].V == 1 &&
  519. pDecData->frame.component[1].H == 1 &&
  520. pDecData->frame.component[1].V == 1 &&
  521. pDecData->frame.component[2].H == 1 &&
  522. pDecData->frame.component[2].V == 1)
  523. {
  524. pDecData->info.yCbCrMode = JPEGDEC_YUV444;
  525. pDecData->info.X = pDecData->frame.hwX;
  526. pDecData->info.Y = pDecData->frame.hwY;
  527. /* check if fill needed */
  528. if((pDecData->frame.X & 0xF) && (pDecData->frame.X & 0xF) <= 8)
  529. pDecData->info.fillRight = 1;
  530. if((pDecData->frame.Y & 0xF) && (pDecData->frame.Y & 0xF) <= 8)
  531. pDecData->info.fillBottom = 1;
  532. /* calculate new output size if slice mode used */
  533. if(pDecData->info.sliceMbSetValue)
  534. {
  535. /* Y */
  536. pDecData->image.sizeLuma = (pDecData->info.X *
  537. (pDecData->info.sliceMbSetValue *
  538. 16));
  539. /* CbCr */
  540. pDecData->image.sizeChroma = pDecData->image.sizeLuma * 2;
  541. }
  542. }
  543. /* JPEG_YCBCR411 */
  544. else if(pDecData->frame.component[0].H == 4 &&
  545. pDecData->frame.component[0].V == 1 &&
  546. pDecData->frame.component[1].H == 1 &&
  547. pDecData->frame.component[1].V == 1 &&
  548. pDecData->frame.component[2].H == 1 &&
  549. pDecData->frame.component[2].V == 1)
  550. {
  551. pDecData->info.yCbCrMode = JPEGDEC_YUV411;
  552. pDecData->info.X = (pDecData->frame.hwX);
  553. pDecData->info.Y = (pDecData->frame.hwY);
  554. /* check if fill needed */
  555. if((pDecData->frame.Y & 0xF) && (pDecData->frame.Y & 0xF) <= 8)
  556. pDecData->info.fillBottom = 1;
  557. /* calculate new output size if slice mode used */
  558. if(pDecData->info.sliceMbSetValue)
  559. {
  560. /* Y */
  561. pDecData->image.sizeLuma = (pDecData->info.X *
  562. (pDecData->info.sliceMbSetValue *
  563. 16));
  564. /* CbCr */
  565. pDecData->image.sizeChroma = pDecData->image.sizeLuma / 2;
  566. }
  567. }
  568. else
  569. {
  570. return (JPEGDEC_UNSUPPORTED);
  571. }
  572. }
  573. else if(pDecData->frame.Nf == 1)
  574. {
  575. /* 4:0:0 */
  576. if((pDecData->frame.component[0].V == 1) ||
  577. (pDecData->frame.component[0].H == 1))
  578. {
  579. pDecData->info.yCbCrMode = JPEGDEC_YUV400;
  580. pDecData->info.X = (pDecData->frame.hwX);
  581. pDecData->info.Y = (pDecData->frame.hwY);
  582. /* check if fill needed */
  583. if((pDecData->frame.X & 0xF) && (pDecData->frame.X & 0xF) <= 8)
  584. pDecData->info.fillRight = 1;
  585. if((pDecData->frame.Y & 0xF) && (pDecData->frame.Y & 0xF) <= 8)
  586. pDecData->info.fillBottom = 1;
  587. /* calculate new output size if slice mode used */
  588. if(pDecData->info.sliceMbSetValue)
  589. {
  590. /* Y */
  591. pDecData->image.sizeLuma =
  592. ((((pDecData->info.X +
  593. 15) / 16) * 16) * (pDecData->info.sliceMbSetValue *
  594. 16));
  595. /* CbCr */
  596. pDecData->image.sizeChroma = 0;
  597. }
  598. }
  599. else
  600. {
  601. return (JPEGDEC_UNSUPPORTED);
  602. }
  603. }
  604. else
  605. {
  606. return (JPEGDEC_UNSUPPORTED);
  607. }
  608. #ifdef JPEGDEC_ERROR_RESILIENCE
  609. if(pDecData->info.fillBottom)
  610. {
  611. pDecData->info.Y -= 16;
  612. pDecData->frame.hwY -= 16;
  613. }
  614. #endif /* JPEGDEC_ERROR_RESILIENCE */
  615. /* save the original sampling format for progressive use */
  616. pDecData->info.yCbCrModeOrig = pDecData->info.yCbCrMode;
  617. return (JPEGDEC_OK);
  618. }