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.

700 lines
20KB

  1. /*
  2. * Dxtory decoder
  3. *
  4. * Copyright (c) 2011 Konstantin Shishkov
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * Libav is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with Libav; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <inttypes.h>
  23. #define BITSTREAM_READER_LE
  24. #include "avcodec.h"
  25. #include "bytestream.h"
  26. #include "get_bits.h"
  27. #include "internal.h"
  28. #include "unary.h"
  29. #include "libavutil/common.h"
  30. #include "libavutil/intreadwrite.h"
  31. static int dxtory_decode_v1_rgb(AVCodecContext *avctx, AVFrame *pic,
  32. const uint8_t *src, int src_size,
  33. int id, int bpp)
  34. {
  35. int h;
  36. uint8_t *dst;
  37. int ret;
  38. if (src_size < avctx->width * avctx->height * bpp) {
  39. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  40. return AVERROR_INVALIDDATA;
  41. }
  42. avctx->pix_fmt = id;
  43. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  44. return ret;
  45. dst = pic->data[0];
  46. for (h = 0; h < avctx->height; h++) {
  47. memcpy(dst, src, avctx->width * bpp);
  48. src += avctx->width * bpp;
  49. dst += pic->linesize[0];
  50. }
  51. return 0;
  52. }
  53. static int dxtory_decode_v1_410(AVCodecContext *avctx, AVFrame *pic,
  54. const uint8_t *src, int src_size)
  55. {
  56. int h, w;
  57. uint8_t *Y1, *Y2, *Y3, *Y4, *U, *V;
  58. int ret;
  59. if (src_size < avctx->width * avctx->height * 18 / 16) {
  60. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  61. return AVERROR_INVALIDDATA;
  62. }
  63. avctx->pix_fmt = AV_PIX_FMT_YUV410P;
  64. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  65. return ret;
  66. Y1 = pic->data[0];
  67. Y2 = pic->data[0] + pic->linesize[0];
  68. Y3 = pic->data[0] + pic->linesize[0] * 2;
  69. Y4 = pic->data[0] + pic->linesize[0] * 3;
  70. U = pic->data[1];
  71. V = pic->data[2];
  72. for (h = 0; h < avctx->height; h += 4) {
  73. for (w = 0; w < avctx->width; w += 4) {
  74. AV_COPY32(Y1 + w, src);
  75. AV_COPY32(Y2 + w, src + 4);
  76. AV_COPY32(Y3 + w, src + 8);
  77. AV_COPY32(Y4 + w, src + 12);
  78. U[w >> 2] = src[16] + 0x80;
  79. V[w >> 2] = src[17] + 0x80;
  80. src += 18;
  81. }
  82. Y1 += pic->linesize[0] << 2;
  83. Y2 += pic->linesize[0] << 2;
  84. Y3 += pic->linesize[0] << 2;
  85. Y4 += pic->linesize[0] << 2;
  86. U += pic->linesize[1];
  87. V += pic->linesize[2];
  88. }
  89. return 0;
  90. }
  91. static int dxtory_decode_v1_420(AVCodecContext *avctx, AVFrame *pic,
  92. const uint8_t *src, int src_size)
  93. {
  94. int h, w;
  95. uint8_t *Y1, *Y2, *U, *V;
  96. int ret;
  97. if (src_size < avctx->width * avctx->height * 3 / 2) {
  98. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  99. return AVERROR_INVALIDDATA;
  100. }
  101. avctx->pix_fmt = AV_PIX_FMT_YUV420P;
  102. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  103. return ret;
  104. Y1 = pic->data[0];
  105. Y2 = pic->data[0] + pic->linesize[0];
  106. U = pic->data[1];
  107. V = pic->data[2];
  108. for (h = 0; h < avctx->height; h += 2) {
  109. for (w = 0; w < avctx->width; w += 2) {
  110. AV_COPY16(Y1 + w, src);
  111. AV_COPY16(Y2 + w, src + 2);
  112. U[w >> 1] = src[4] + 0x80;
  113. V[w >> 1] = src[5] + 0x80;
  114. src += 6;
  115. }
  116. Y1 += pic->linesize[0] << 1;
  117. Y2 += pic->linesize[0] << 1;
  118. U += pic->linesize[1];
  119. V += pic->linesize[2];
  120. }
  121. return 0;
  122. }
  123. static int dxtory_decode_v1_444(AVCodecContext *avctx, AVFrame *pic,
  124. const uint8_t *src, int src_size)
  125. {
  126. int h, w;
  127. uint8_t *Y, *U, *V;
  128. int ret;
  129. if (src_size < avctx->width * avctx->height * 3) {
  130. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  131. return AVERROR_INVALIDDATA;
  132. }
  133. avctx->pix_fmt = AV_PIX_FMT_YUV444P;
  134. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  135. return ret;
  136. Y = pic->data[0];
  137. U = pic->data[1];
  138. V = pic->data[2];
  139. for (h = 0; h < avctx->height; h++) {
  140. for (w = 0; w < avctx->width; w++) {
  141. Y[w] = *src++;
  142. U[w] = *src++ ^ 0x80;
  143. V[w] = *src++ ^ 0x80;
  144. }
  145. Y += pic->linesize[0];
  146. U += pic->linesize[1];
  147. V += pic->linesize[2];
  148. }
  149. return 0;
  150. }
  151. const uint8_t def_lru[8] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xFF };
  152. const uint8_t def_lru_555[8] = { 0x00, 0x08, 0x10, 0x18, 0x1F };
  153. const uint8_t def_lru_565[8] = { 0x00, 0x08, 0x10, 0x20, 0x30, 0x3F };
  154. static inline uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8])
  155. {
  156. uint8_t c, val;
  157. c = get_unary(gb, 0, 8);
  158. if (!c) {
  159. val = get_bits(gb, 8);
  160. memmove(lru + 1, lru, sizeof(*lru) * (8 - 1));
  161. } else {
  162. val = lru[c - 1];
  163. memmove(lru + 1, lru, sizeof(*lru) * (c - 1));
  164. }
  165. lru[0] = val;
  166. return val;
  167. }
  168. static int check_slice_size(AVCodecContext *avctx,
  169. const uint8_t *src, int src_size,
  170. int slice_size, int off)
  171. {
  172. int cur_slice_size;
  173. if (slice_size > src_size - off) {
  174. av_log(avctx, AV_LOG_ERROR,
  175. "invalid slice size %"PRIu32" (only %"PRIu32" bytes left)\n",
  176. slice_size, src_size - off);
  177. return AVERROR_INVALIDDATA;
  178. }
  179. if (slice_size <= 16) {
  180. av_log(avctx, AV_LOG_ERROR, "invalid slice size %"PRIu32"\n",
  181. slice_size);
  182. return AVERROR_INVALIDDATA;
  183. }
  184. cur_slice_size = AV_RL32(src + off);
  185. if (cur_slice_size != slice_size - 16) {
  186. av_log(avctx, AV_LOG_ERROR,
  187. "Slice sizes mismatch: got %"PRIu32" instead of %"PRIu32"\n",
  188. cur_slice_size, slice_size - 16);
  189. }
  190. return 0;
  191. }
  192. static int load_buffer(AVCodecContext *avctx,
  193. const uint8_t *src, int src_size,
  194. GetByteContext *gb,
  195. int *nslices, int *off)
  196. {
  197. bytestream2_init(gb, src, src_size);
  198. *nslices = bytestream2_get_le16(gb);
  199. *off = FFALIGN(*nslices * 4 + 2, 16);
  200. if (src_size < *off) {
  201. av_log(avctx, AV_LOG_ERROR, "no slice data\n");
  202. return AVERROR_INVALIDDATA;
  203. }
  204. if (!*nslices || avctx->height % *nslices) {
  205. avpriv_request_sample(avctx, "%d slices for %dx%d", *nslices,
  206. avctx->width, avctx->height);
  207. return AVERROR_PATCHWELCOME;
  208. }
  209. return 0;
  210. }
  211. static inline uint8_t decode_sym_565(GetBitContext *gb, uint8_t lru[8],
  212. int bits)
  213. {
  214. uint8_t c, val;
  215. c = get_unary(gb, 0, bits);
  216. if (!c) {
  217. val = get_bits(gb, bits);
  218. memmove(lru + 1, lru, sizeof(*lru) * (6 - 1));
  219. } else {
  220. val = lru[c - 1];
  221. memmove(lru + 1, lru, sizeof(*lru) * (c - 1));
  222. }
  223. lru[0] = val;
  224. return val;
  225. }
  226. static int dx2_decode_slice_565(GetBitContext *gb, int width, int height,
  227. uint8_t *dst, int stride, int is_565)
  228. {
  229. int x, y;
  230. int r, g, b;
  231. uint8_t lru[3][8];
  232. memcpy(lru[0], def_lru_555, 8 * sizeof(*def_lru));
  233. memcpy(lru[1], is_565 ? def_lru_565 : def_lru_555, 8 * sizeof(*def_lru));
  234. memcpy(lru[2], def_lru_555, 8 * sizeof(*def_lru));
  235. for (y = 0; y < height; y++) {
  236. for (x = 0; x < width; x++) {
  237. b = decode_sym_565(gb, lru[0], 5);
  238. g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5);
  239. r = decode_sym_565(gb, lru[2], 5);
  240. dst[x * 3 + 0] = (r << 3) | (r >> 2);
  241. dst[x * 3 + 1] = is_565 ? (g << 2) | (g >> 4) : (g << 3) | (g >> 2);
  242. dst[x * 3 + 2] = (b << 3) | (b >> 2);
  243. }
  244. dst += stride;
  245. }
  246. return 0;
  247. }
  248. static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic,
  249. const uint8_t *src, int src_size, int is_565)
  250. {
  251. GetByteContext gb;
  252. GetBitContext gb2;
  253. int nslices, slice, slice_height;
  254. uint32_t off, slice_size;
  255. uint8_t *dst;
  256. int ret;
  257. ret = load_buffer(avctx, src, src_size, &gb, &nslices, &off);
  258. if (ret < 0)
  259. return ret;
  260. slice_height = avctx->height / nslices;
  261. avctx->pix_fmt = AV_PIX_FMT_RGB24;
  262. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  263. return ret;
  264. dst = pic->data[0];
  265. for (slice = 0; slice < nslices; slice++) {
  266. slice_size = bytestream2_get_le32(&gb);
  267. ret = check_slice_size(avctx, src, src_size, slice_size, off);
  268. if (ret < 0)
  269. return ret;
  270. init_get_bits(&gb2, src + off + 16, (slice_size - 16) * 8);
  271. dx2_decode_slice_565(&gb2, avctx->width, slice_height, dst,
  272. pic->linesize[0], is_565);
  273. dst += pic->linesize[0] * slice_height;
  274. off += slice_size;
  275. }
  276. return 0;
  277. }
  278. static int dx2_decode_slice_rgb(GetBitContext *gb, int width, int height,
  279. uint8_t *dst, int stride)
  280. {
  281. int x, y, i;
  282. uint8_t lru[3][8];
  283. for (i = 0; i < 3; i++)
  284. memcpy(lru[i], def_lru, 8 * sizeof(*def_lru));
  285. for (y = 0; y < height; y++) {
  286. for (x = 0; x < width; x++) {
  287. dst[x * 3 + 0] = decode_sym(gb, lru[0]);
  288. dst[x * 3 + 1] = decode_sym(gb, lru[1]);
  289. dst[x * 3 + 2] = decode_sym(gb, lru[2]);
  290. }
  291. dst += stride;
  292. }
  293. return 0;
  294. }
  295. static int dxtory_decode_v2_rgb(AVCodecContext *avctx, AVFrame *pic,
  296. const uint8_t *src, int src_size)
  297. {
  298. GetByteContext gb;
  299. GetBitContext gb2;
  300. int nslices, slice, slice_height;
  301. uint32_t off, slice_size;
  302. uint8_t *dst;
  303. int ret;
  304. ret = load_buffer(avctx, src, src_size, &gb, &nslices, &off);
  305. if (ret < 0)
  306. return ret;
  307. slice_height = avctx->height / nslices;
  308. avctx->pix_fmt = AV_PIX_FMT_BGR24;
  309. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  310. return ret;
  311. dst = pic->data[0];
  312. for (slice = 0; slice < nslices; slice++) {
  313. slice_size = bytestream2_get_le32(&gb);
  314. ret = check_slice_size(avctx, src, src_size, slice_size, off);
  315. if (ret < 0)
  316. return ret;
  317. init_get_bits(&gb2, src + off + 16, (slice_size - 16) * 8);
  318. dx2_decode_slice_rgb(&gb2, avctx->width, slice_height, dst,
  319. pic->linesize[0]);
  320. dst += pic->linesize[0] * slice_height;
  321. off += slice_size;
  322. }
  323. return 0;
  324. }
  325. static int dx2_decode_slice_410(GetBitContext *gb, int width, int height,
  326. uint8_t *Y, uint8_t *U, uint8_t *V,
  327. int ystride, int ustride, int vstride)
  328. {
  329. int x, y, i, j;
  330. uint8_t lru[3][8];
  331. for (i = 0; i < 3; i++)
  332. memcpy(lru[i], def_lru, 8 * sizeof(*def_lru));
  333. for (y = 0; y < height; y += 4) {
  334. for (x = 0; x < width; x += 4) {
  335. for (j = 0; j < 4; j++)
  336. for (i = 0; i < 4; i++)
  337. Y[x + i + j * ystride] = decode_sym(gb, lru[0]);
  338. U[x >> 2] = decode_sym(gb, lru[1]) ^ 0x80;
  339. V[x >> 2] = decode_sym(gb, lru[2]) ^ 0x80;
  340. }
  341. Y += ystride << 2;
  342. U += ustride;
  343. V += vstride;
  344. }
  345. return 0;
  346. }
  347. static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic,
  348. const uint8_t *src, int src_size)
  349. {
  350. GetByteContext gb;
  351. GetBitContext gb2;
  352. int nslices, slice, slice_height, ref_slice_height;
  353. int cur_y, next_y;
  354. uint32_t off, slice_size;
  355. uint8_t *Y, *U, *V;
  356. int ret;
  357. ret = load_buffer(avctx, src, src_size, &gb, &nslices, &off);
  358. if (ret < 0)
  359. return ret;
  360. ref_slice_height = avctx->height / nslices;
  361. if ((avctx->width & 3) || (avctx->height & 3)) {
  362. avpriv_request_sample(avctx, "Frame dimensions %dx%d",
  363. avctx->width, avctx->height);
  364. }
  365. avctx->pix_fmt = AV_PIX_FMT_YUV410P;
  366. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  367. return ret;
  368. Y = pic->data[0];
  369. U = pic->data[1];
  370. V = pic->data[2];
  371. cur_y = 0;
  372. next_y = ref_slice_height;
  373. for (slice = 0; slice < nslices; slice++) {
  374. slice_size = bytestream2_get_le32(&gb);
  375. slice_height = (next_y & ~3) - (cur_y & ~3);
  376. ret = check_slice_size(avctx, src, src_size, slice_size, off);
  377. if (ret < 0)
  378. return ret;
  379. init_get_bits(&gb2, src + off + 16, (slice_size - 16) * 8);
  380. dx2_decode_slice_410(&gb2, avctx->width, slice_height, Y, U, V,
  381. pic->linesize[0], pic->linesize[1],
  382. pic->linesize[2]);
  383. Y += pic->linesize[0] * slice_height;
  384. U += pic->linesize[1] * (slice_height >> 2);
  385. V += pic->linesize[2] * (slice_height >> 2);
  386. off += slice_size;
  387. cur_y = next_y;
  388. next_y += ref_slice_height;
  389. }
  390. return 0;
  391. }
  392. static int dx2_decode_slice_420(GetBitContext *gb, int width, int height,
  393. uint8_t *Y, uint8_t *U, uint8_t *V,
  394. int ystride, int ustride, int vstride)
  395. {
  396. int x, y, i;
  397. uint8_t lru[3][8];
  398. for (i = 0; i < 3; i++)
  399. memcpy(lru[i], def_lru, 8 * sizeof(*def_lru));
  400. for (y = 0; y < height; y+=2) {
  401. for (x = 0; x < width; x += 2) {
  402. Y[x + 0 + 0 * ystride] = decode_sym(gb, lru[0]);
  403. Y[x + 1 + 0 * ystride] = decode_sym(gb, lru[0]);
  404. Y[x + 0 + 1 * ystride] = decode_sym(gb, lru[0]);
  405. Y[x + 1 + 1 * ystride] = decode_sym(gb, lru[0]);
  406. U[x >> 1] = decode_sym(gb, lru[1]) ^ 0x80;
  407. V[x >> 1] = decode_sym(gb, lru[2]) ^ 0x80;
  408. }
  409. Y += ystride << 1;
  410. U += ustride;
  411. V += vstride;
  412. }
  413. return 0;
  414. }
  415. static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,
  416. const uint8_t *src, int src_size)
  417. {
  418. GetByteContext gb;
  419. GetBitContext gb2;
  420. int nslices, slice, slice_height, ref_slice_height;
  421. int cur_y, next_y;
  422. uint32_t off, slice_size;
  423. uint8_t *Y, *U, *V;
  424. int ret;
  425. ret = load_buffer(avctx, src, src_size, &gb, &nslices, &off);
  426. if (ret < 0)
  427. return ret;
  428. ref_slice_height = avctx->height / nslices;
  429. if ((avctx->width & 1) || (avctx->height & 1)) {
  430. avpriv_request_sample(avctx, "Frame dimensions %dx%d",
  431. avctx->width, avctx->height);
  432. }
  433. avctx->pix_fmt = AV_PIX_FMT_YUV420P;
  434. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  435. return ret;
  436. Y = pic->data[0];
  437. U = pic->data[1];
  438. V = pic->data[2];
  439. cur_y = 0;
  440. next_y = ref_slice_height;
  441. for (slice = 0; slice < nslices; slice++) {
  442. slice_size = bytestream2_get_le32(&gb);
  443. slice_height = (next_y & ~1) - (cur_y & ~1);
  444. ret = check_slice_size(avctx, src, src_size, slice_size, off);
  445. if (ret < 0)
  446. return ret;
  447. init_get_bits(&gb2, src + off + 16, (slice_size - 16) * 8);
  448. dx2_decode_slice_420(&gb2, avctx->width, slice_height, Y, U, V,
  449. pic->linesize[0], pic->linesize[1],
  450. pic->linesize[2]);
  451. Y += pic->linesize[0] * slice_height;
  452. U += pic->linesize[1] * (slice_height >> 1);
  453. V += pic->linesize[2] * (slice_height >> 1);
  454. off += slice_size;
  455. cur_y = next_y;
  456. next_y += ref_slice_height;
  457. }
  458. return 0;
  459. }
  460. static int dx2_decode_slice_444(GetBitContext *gb, int width, int height,
  461. uint8_t *Y, uint8_t *U, uint8_t *V,
  462. int ystride, int ustride, int vstride)
  463. {
  464. int x, y, i;
  465. uint8_t lru[3][8];
  466. for (i = 0; i < 3; i++)
  467. memcpy(lru[i], def_lru, 8 * sizeof(*def_lru));
  468. for (y = 0; y < height; y++) {
  469. for (x = 0; x < width; x++) {
  470. Y[x] = decode_sym(gb, lru[0]);
  471. U[x] = decode_sym(gb, lru[1]) ^ 0x80;
  472. V[x] = decode_sym(gb, lru[2]) ^ 0x80;
  473. }
  474. Y += ystride;
  475. U += ustride;
  476. V += vstride;
  477. }
  478. return 0;
  479. }
  480. static int dxtory_decode_v2_444(AVCodecContext *avctx, AVFrame *pic,
  481. const uint8_t *src, int src_size)
  482. {
  483. GetByteContext gb;
  484. GetBitContext gb2;
  485. int nslices, slice, slice_height;
  486. uint32_t off, slice_size;
  487. uint8_t *Y, *U, *V;
  488. int ret;
  489. ret = load_buffer(avctx, src, src_size, &gb, &nslices, &off);
  490. if (ret < 0)
  491. return ret;
  492. slice_height = avctx->height / nslices;
  493. avctx->pix_fmt = AV_PIX_FMT_YUV444P;
  494. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  495. return ret;
  496. Y = pic->data[0];
  497. U = pic->data[1];
  498. V = pic->data[2];
  499. for (slice = 0; slice < nslices; slice++) {
  500. slice_size = bytestream2_get_le32(&gb);
  501. ret = check_slice_size(avctx, src, src_size, slice_size, off);
  502. if (ret < 0)
  503. return ret;
  504. init_get_bits(&gb2, src + off + 16, (slice_size - 16) * 8);
  505. dx2_decode_slice_444(&gb2, avctx->width, slice_height, Y, U, V,
  506. pic->linesize[0], pic->linesize[1],
  507. pic->linesize[2]);
  508. Y += pic->linesize[0] * slice_height;
  509. U += pic->linesize[1] * slice_height;
  510. V += pic->linesize[2] * slice_height;
  511. off += slice_size;
  512. }
  513. return 0;
  514. }
  515. static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
  516. AVPacket *avpkt)
  517. {
  518. AVFrame *pic = data;
  519. const uint8_t *src = avpkt->data;
  520. int ret;
  521. if (avpkt->size < 16) {
  522. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  523. return AVERROR_INVALIDDATA;
  524. }
  525. switch (AV_RB32(src)) {
  526. case 0x01000001:
  527. ret = dxtory_decode_v1_rgb(avctx, pic, src + 16, avpkt->size - 16,
  528. AV_PIX_FMT_BGR24, 3);
  529. break;
  530. case 0x01000009:
  531. ret = dxtory_decode_v2_rgb(avctx, pic, src + 16, avpkt->size - 16);
  532. break;
  533. case 0x02000001:
  534. ret = dxtory_decode_v1_420(avctx, pic, src + 16, avpkt->size - 16);
  535. break;
  536. case 0x02000009:
  537. ret = dxtory_decode_v2_420(avctx, pic, src + 16, avpkt->size - 16);
  538. break;
  539. case 0x03000001:
  540. ret = dxtory_decode_v1_410(avctx, pic, src + 16, avpkt->size - 16);
  541. break;
  542. case 0x03000009:
  543. ret = dxtory_decode_v2_410(avctx, pic, src + 16, avpkt->size - 16);
  544. break;
  545. case 0x04000001:
  546. ret = dxtory_decode_v1_444(avctx, pic, src + 16, avpkt->size - 16);
  547. break;
  548. case 0x04000009:
  549. ret = dxtory_decode_v2_444(avctx, pic, src + 16, avpkt->size - 16);
  550. break;
  551. case 0x17000001:
  552. ret = dxtory_decode_v1_rgb(avctx, pic, src + 16, avpkt->size - 16,
  553. AV_PIX_FMT_RGB565LE, 2);
  554. break;
  555. case 0x17000009:
  556. ret = dxtory_decode_v2_565(avctx, pic, src + 16, avpkt->size - 16, 1);
  557. break;
  558. case 0x18000001:
  559. case 0x19000001:
  560. ret = dxtory_decode_v1_rgb(avctx, pic, src + 16, avpkt->size - 16,
  561. AV_PIX_FMT_RGB555LE, 2);
  562. break;
  563. case 0x18000009:
  564. case 0x19000009:
  565. ret = dxtory_decode_v2_565(avctx, pic, src + 16, avpkt->size - 16, 0);
  566. break;
  567. default:
  568. avpriv_request_sample(avctx, "Frame header %"PRIX32, AV_RB32(src));
  569. return AVERROR_PATCHWELCOME;
  570. }
  571. if (ret)
  572. return ret;
  573. pic->pict_type = AV_PICTURE_TYPE_I;
  574. pic->key_frame = 1;
  575. *got_frame = 1;
  576. return avpkt->size;
  577. }
  578. AVCodec ff_dxtory_decoder = {
  579. .name = "dxtory",
  580. .long_name = NULL_IF_CONFIG_SMALL("Dxtory"),
  581. .type = AVMEDIA_TYPE_VIDEO,
  582. .id = AV_CODEC_ID_DXTORY,
  583. .decode = decode_frame,
  584. .capabilities = AV_CODEC_CAP_DR1,
  585. };