00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "avcodec.h"
00026 #include "bytestream.h"
00027 #include "internal.h"
00028 #include "libavutil/bswap.h"
00029 #include "libavcodec/dsputil.h"
00030 #include "sanm_data.h"
00031
00032 #define NGLYPHS 256
00033
00034 typedef struct {
00035 AVCodecContext *avctx;
00036 GetByteContext gb;
00037
00038 int version, subversion;
00039 uint32_t pal[256];
00040 int16_t delta_pal[768];
00041
00042 int pitch;
00043 int width, height;
00044 int aligned_width, aligned_height;
00045 int prev_seq;
00046
00047 AVFrame frame, *output;
00048 uint16_t *frm0, *frm1, *frm2;
00049 uint8_t *stored_frame;
00050 uint32_t frm0_size, frm1_size, frm2_size;
00051 uint32_t stored_frame_size;
00052
00053 uint8_t *rle_buf;
00054 unsigned int rle_buf_size;
00055
00056 int rotate_code;
00057
00058 long npixels, buf_size;
00059
00060 uint16_t codebook[256];
00061 uint16_t small_codebook[4];
00062
00063 int8_t p4x4glyphs[NGLYPHS][16];
00064 int8_t p8x8glyphs[NGLYPHS][64];
00065 } SANMVideoContext;
00066
00067 typedef struct {
00068 int seq_num, codec, rotate_code, rle_output_size;
00069
00070 uint16_t bg_color;
00071 uint32_t width, height;
00072 } SANMFrameHeader;
00073
00074 enum GlyphEdge {
00075 LEFT_EDGE,
00076 TOP_EDGE,
00077 RIGHT_EDGE,
00078 BOTTOM_EDGE,
00079 NO_EDGE
00080 };
00081
00082 enum GlyphDir {
00083 DIR_LEFT,
00084 DIR_UP,
00085 DIR_RIGHT,
00086 DIR_DOWN,
00087 NO_DIR
00088 };
00089
00097 static enum GlyphEdge which_edge(int x, int y, int edge_size)
00098 {
00099 const int edge_max = edge_size - 1;
00100
00101 if (!y) {
00102 return BOTTOM_EDGE;
00103 } else if (y == edge_max) {
00104 return TOP_EDGE;
00105 } else if (!x) {
00106 return LEFT_EDGE;
00107 } else if (x == edge_max) {
00108 return RIGHT_EDGE;
00109 } else {
00110 return NO_EDGE;
00111 }
00112 }
00113
00114 static enum GlyphDir which_direction(enum GlyphEdge edge0, enum GlyphEdge edge1)
00115 {
00116 if ((edge0 == LEFT_EDGE && edge1 == RIGHT_EDGE) ||
00117 (edge1 == LEFT_EDGE && edge0 == RIGHT_EDGE) ||
00118 (edge0 == BOTTOM_EDGE && edge1 != TOP_EDGE) ||
00119 (edge1 == BOTTOM_EDGE && edge0 != TOP_EDGE)) {
00120 return DIR_UP;
00121 } else if ((edge0 == TOP_EDGE && edge1 != BOTTOM_EDGE) ||
00122 (edge1 == TOP_EDGE && edge0 != BOTTOM_EDGE)) {
00123 return DIR_DOWN;
00124 } else if ((edge0 == LEFT_EDGE && edge1 != RIGHT_EDGE) ||
00125 (edge1 == LEFT_EDGE && edge0 != RIGHT_EDGE)) {
00126 return DIR_LEFT;
00127 } else if ((edge0 == TOP_EDGE && edge1 == BOTTOM_EDGE) ||
00128 (edge1 == TOP_EDGE && edge0 == BOTTOM_EDGE) ||
00129 (edge0 == RIGHT_EDGE && edge1 != LEFT_EDGE) ||
00130 (edge1 == RIGHT_EDGE && edge0 != LEFT_EDGE)) {
00131 return DIR_RIGHT;
00132 }
00133
00134 return NO_DIR;
00135 }
00136
00140 static void interp_point(int8_t *points, int x0, int y0, int x1, int y1,
00141 int pos, int npoints)
00142 {
00143 if (npoints) {
00144 points[0] = (x0 * pos + x1 * (npoints - pos) + (npoints >> 1)) / npoints;
00145 points[1] = (y0 * pos + y1 * (npoints - pos) + (npoints >> 1)) / npoints;
00146 } else {
00147 points[0] = x0;
00148 points[1] = y0;
00149 }
00150 }
00151
00160 static void make_glyphs(int8_t *pglyphs, const int8_t *xvec, const int8_t *yvec,
00161 const int side_length)
00162 {
00163 const int glyph_size = side_length * side_length;
00164 int8_t *pglyph = pglyphs;
00165
00166 int i, j;
00167 for (i = 0; i < GLYPH_COORD_VECT_SIZE; i++) {
00168 int x0 = xvec[i];
00169 int y0 = yvec[i];
00170 enum GlyphEdge edge0 = which_edge(x0, y0, side_length);
00171
00172 for (j = 0; j < GLYPH_COORD_VECT_SIZE; j++, pglyph += glyph_size) {
00173 int x1 = xvec[j];
00174 int y1 = yvec[j];
00175 enum GlyphEdge edge1 = which_edge(x1, y1, side_length);
00176 enum GlyphDir dir = which_direction(edge0, edge1);
00177 int npoints = FFMAX(FFABS(x1 - x0), FFABS(y1 - y0));
00178 int ipoint;
00179
00180 for (ipoint = 0; ipoint <= npoints; ipoint++) {
00181 int8_t point[2];
00182 int irow, icol;
00183
00184 interp_point(point, x0, y0, x1, y1, ipoint, npoints);
00185
00186 switch (dir) {
00187 case DIR_UP:
00188 for (irow = point[1]; irow >= 0; irow--)
00189 pglyph[point[0] + irow * side_length] = 1;
00190 break;
00191
00192 case DIR_DOWN:
00193 for (irow = point[1]; irow < side_length; irow++)
00194 pglyph[point[0] + irow * side_length] = 1;
00195 break;
00196
00197 case DIR_LEFT:
00198 for (icol = point[0]; icol >= 0; icol--)
00199 pglyph[icol + point[1] * side_length] = 1;
00200 break;
00201
00202 case DIR_RIGHT:
00203 for (icol = point[0]; icol < side_length; icol++)
00204 pglyph[icol + point[1] * side_length] = 1;
00205 break;
00206 }
00207 }
00208 }
00209 }
00210 }
00211
00212 static void init_sizes(SANMVideoContext *ctx, int width, int height)
00213 {
00214 ctx->width = width;
00215 ctx->height = height;
00216 ctx->npixels = width * height;
00217
00218 ctx->aligned_width = FFALIGN(width, 8);
00219 ctx->aligned_height = FFALIGN(height, 8);
00220
00221 ctx->buf_size = ctx->aligned_width * ctx->aligned_height * sizeof(ctx->frm0[0]);
00222 ctx->pitch = width;
00223 }
00224
00225 static void destroy_buffers(SANMVideoContext *ctx)
00226 {
00227 av_freep(&ctx->frm0);
00228 av_freep(&ctx->frm1);
00229 av_freep(&ctx->frm2);
00230 av_freep(&ctx->stored_frame);
00231 av_freep(&ctx->rle_buf);
00232 }
00233
00234 static av_cold int init_buffers(SANMVideoContext *ctx)
00235 {
00236 av_fast_padded_malloc(&ctx->frm0, &ctx->frm0_size, ctx->buf_size);
00237 av_fast_padded_malloc(&ctx->frm1, &ctx->frm1_size, ctx->buf_size);
00238 av_fast_padded_malloc(&ctx->frm2, &ctx->frm2_size, ctx->buf_size);
00239 if (!ctx->version)
00240 av_fast_padded_malloc(&ctx->stored_frame, &ctx->stored_frame_size, ctx->buf_size);
00241
00242 if (!ctx->frm0 || !ctx->frm1 || !ctx->frm2 || (!ctx->stored_frame && !ctx->version)) {
00243 destroy_buffers(ctx);
00244 return AVERROR(ENOMEM);
00245 }
00246
00247 return 0;
00248 }
00249
00250 static void rotate_bufs(SANMVideoContext *ctx, int rotate_code)
00251 {
00252 av_dlog(ctx->avctx, "rotate %d\n", rotate_code);
00253 if (rotate_code == 2)
00254 FFSWAP(uint16_t*, ctx->frm1, ctx->frm2);
00255 FFSWAP(uint16_t*, ctx->frm2, ctx->frm0);
00256 }
00257
00258 static av_cold int decode_init(AVCodecContext *avctx)
00259 {
00260 SANMVideoContext *ctx = avctx->priv_data;
00261
00262 ctx->avctx = avctx;
00263 ctx->version = !avctx->extradata_size;
00264
00265 avctx->pix_fmt = ctx->version ? AV_PIX_FMT_RGB565 : AV_PIX_FMT_PAL8;
00266
00267 init_sizes(ctx, avctx->width, avctx->height);
00268 if (init_buffers(ctx)) {
00269 av_log(avctx, AV_LOG_ERROR, "error allocating buffers\n");
00270 return AVERROR(ENOMEM);
00271 }
00272 ctx->output = &ctx->frame;
00273 ctx->output->data[0] = 0;
00274
00275 make_glyphs(ctx->p4x4glyphs[0], glyph4_x, glyph4_y, 4);
00276 make_glyphs(ctx->p8x8glyphs[0], glyph8_x, glyph8_y, 8);
00277
00278 if (!ctx->version) {
00279 int i;
00280
00281 if (avctx->extradata_size < 1026) {
00282 av_log(avctx, AV_LOG_ERROR, "not enough extradata\n");
00283 return AVERROR_INVALIDDATA;
00284 }
00285
00286 ctx->subversion = AV_RL16(avctx->extradata);
00287 for (i = 0; i < 256; i++)
00288 ctx->pal[i] = 0xFFU << 24 | AV_RL32(avctx->extradata + 2 + i * 4);
00289 }
00290
00291 return 0;
00292 }
00293
00294 static av_cold int decode_end(AVCodecContext *avctx)
00295 {
00296 SANMVideoContext *ctx = avctx->priv_data;
00297
00298 destroy_buffers(ctx);
00299
00300 if (ctx->frame.data[0]) {
00301 avctx->release_buffer(avctx, &ctx->frame);
00302 ctx->frame.data[0] = 0;
00303 }
00304
00305 return 0;
00306 }
00307
00308 static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, const int out_size)
00309 {
00310 int opcode, color, run_len, left = out_size;
00311
00312 while (left > 0) {
00313 opcode = bytestream2_get_byte(&ctx->gb);
00314 run_len = (opcode >> 1) + 1;
00315 if (run_len > left || bytestream2_get_bytes_left(&ctx->gb) <= 0)
00316 return AVERROR_INVALIDDATA;
00317
00318 if (opcode & 1) {
00319 color = bytestream2_get_byte(&ctx->gb);
00320 memset(dst, color, run_len);
00321 } else {
00322 if (bytestream2_get_bytes_left(&ctx->gb) < run_len)
00323 return AVERROR_INVALIDDATA;
00324 bytestream2_get_bufferu(&ctx->gb, dst, run_len);
00325 }
00326
00327 dst += run_len;
00328 left -= run_len;
00329 }
00330
00331 return 0;
00332 }
00333
00334 static int old_codec1(SANMVideoContext *ctx, int top,
00335 int left, int width, int height)
00336 {
00337 uint8_t *dst = ((uint8_t*)ctx->frm0) + left + top * ctx->pitch;
00338 int i, j, len, flag, code, val, pos, end;
00339
00340 for (i = 0; i < height; i++) {
00341 pos = 0;
00342
00343 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
00344 return AVERROR_INVALIDDATA;
00345
00346 len = bytestream2_get_le16u(&ctx->gb);
00347 end = bytestream2_tell(&ctx->gb) + len;
00348
00349 while (bytestream2_tell(&ctx->gb) < end) {
00350 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
00351 return AVERROR_INVALIDDATA;
00352
00353 code = bytestream2_get_byteu(&ctx->gb);
00354 flag = code & 1;
00355 code = (code >> 1) + 1;
00356 if (pos + code > width)
00357 return AVERROR_INVALIDDATA;
00358 if (flag) {
00359 val = bytestream2_get_byteu(&ctx->gb);
00360 if (val)
00361 memset(dst + pos, val, code);
00362 pos += code;
00363 } else {
00364 if (bytestream2_get_bytes_left(&ctx->gb) < code)
00365 return AVERROR_INVALIDDATA;
00366 for (j = 0; j < code; j++) {
00367 val = bytestream2_get_byteu(&ctx->gb);
00368 if (val)
00369 dst[pos] = val;
00370 pos++;
00371 }
00372 }
00373 }
00374 dst += ctx->pitch;
00375 }
00376 ctx->rotate_code = 0;
00377
00378 return 0;
00379 }
00380
00381 static inline void codec37_mv(uint8_t *dst, const uint8_t *src,
00382 int height, int stride, int x, int y)
00383 {
00384 int pos, i, j;
00385
00386 pos = x + y * stride;
00387 for (j = 0; j < 4; j++) {
00388 for (i = 0; i < 4; i++) {
00389 if ((pos + i) < 0 || (pos + i) >= height * stride)
00390 dst[i] = 0;
00391 else
00392 dst[i] = src[i];
00393 }
00394 dst += stride;
00395 src += stride;
00396 pos += stride;
00397 }
00398 }
00399
00400 static int old_codec37(SANMVideoContext *ctx, int top,
00401 int left, int width, int height)
00402 {
00403 int stride = ctx->pitch;
00404 int i, j, k, t;
00405 int skip_run = 0;
00406 int compr, mvoff, seq, flags;
00407 uint32_t decoded_size;
00408 uint8_t *dst, *prev;
00409
00410 compr = bytestream2_get_byte(&ctx->gb);
00411 mvoff = bytestream2_get_byte(&ctx->gb);
00412 seq = bytestream2_get_le16(&ctx->gb);
00413 decoded_size = bytestream2_get_le32(&ctx->gb);
00414 bytestream2_skip(&ctx->gb, 4);
00415 flags = bytestream2_get_byte(&ctx->gb);
00416 bytestream2_skip(&ctx->gb, 3);
00417
00418 ctx->rotate_code = 0;
00419
00420 if (((seq & 1) || !(flags & 1)) && (compr && compr != 2))
00421 rotate_bufs(ctx, 1);
00422
00423 dst = ((uint8_t*)ctx->frm0) + left + top * stride;
00424 prev = ((uint8_t*)ctx->frm2) + left + top * stride;
00425
00426 if (mvoff > 2) {
00427 av_log(ctx->avctx, AV_LOG_ERROR, "invalid motion base value %d\n", mvoff);
00428 return AVERROR_INVALIDDATA;
00429 }
00430 av_dlog(ctx->avctx, "compression %d\n", compr);
00431 switch (compr) {
00432 case 0:
00433 for (i = 0; i < height; i++) {
00434 bytestream2_get_buffer(&ctx->gb, dst, width);
00435 dst += stride;
00436 }
00437 memset(ctx->frm1, 0, ctx->height * stride);
00438 memset(ctx->frm2, 0, ctx->height * stride);
00439 break;
00440 case 2:
00441 if (rle_decode(ctx, dst, decoded_size))
00442 return AVERROR_INVALIDDATA;
00443 memset(ctx->frm1, 0, ctx->frm1_size);
00444 memset(ctx->frm2, 0, ctx->frm2_size);
00445 break;
00446 case 3:
00447 case 4:
00448 if (flags & 4) {
00449 for (j = 0; j < height; j += 4) {
00450 for (i = 0; i < width; i += 4) {
00451 int code;
00452 if (skip_run) {
00453 skip_run--;
00454 copy_block4(dst + i, prev + i, stride, stride, 4);
00455 continue;
00456 }
00457 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
00458 return AVERROR_INVALIDDATA;
00459 code = bytestream2_get_byteu(&ctx->gb);
00460 switch (code) {
00461 case 0xFF:
00462 if (bytestream2_get_bytes_left(&ctx->gb) < 16)
00463 return AVERROR_INVALIDDATA;
00464 for (k = 0; k < 4; k++)
00465 bytestream2_get_bufferu(&ctx->gb, dst + i + k * stride, 4);
00466 break;
00467 case 0xFE:
00468 if (bytestream2_get_bytes_left(&ctx->gb) < 4)
00469 return AVERROR_INVALIDDATA;
00470 for (k = 0; k < 4; k++)
00471 memset(dst + i + k * stride, bytestream2_get_byteu(&ctx->gb), 4);
00472 break;
00473 case 0xFD:
00474 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
00475 return AVERROR_INVALIDDATA;
00476 t = bytestream2_get_byteu(&ctx->gb);
00477 for (k = 0; k < 4; k++)
00478 memset(dst + i + k * stride, t, 4);
00479 break;
00480 default:
00481 if (compr == 4 && !code) {
00482 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
00483 return AVERROR_INVALIDDATA;
00484 skip_run = bytestream2_get_byteu(&ctx->gb) + 1;
00485 i -= 4;
00486 } else {
00487 int mx, my;
00488
00489 mx = c37_mv[(mvoff * 255 + code) * 2 ];
00490 my = c37_mv[(mvoff * 255 + code) * 2 + 1];
00491 codec37_mv(dst + i, prev + i + mx + my * stride,
00492 ctx->height, stride, i + mx, j + my);
00493 }
00494 }
00495 }
00496 dst += stride * 4;
00497 prev += stride * 4;
00498 }
00499 } else {
00500 for (j = 0; j < height; j += 4) {
00501 for (i = 0; i < width; i += 4) {
00502 int code;
00503 if (skip_run) {
00504 skip_run--;
00505 copy_block4(dst + i, prev + i, stride, stride, 4);
00506 continue;
00507 }
00508 code = bytestream2_get_byte(&ctx->gb);
00509 if (code == 0xFF) {
00510 if (bytestream2_get_bytes_left(&ctx->gb) < 16)
00511 return AVERROR_INVALIDDATA;
00512 for (k = 0; k < 4; k++)
00513 bytestream2_get_bufferu(&ctx->gb, dst + i + k * stride, 4);
00514 } else if (compr == 4 && !code) {
00515 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
00516 return AVERROR_INVALIDDATA;
00517 skip_run = bytestream2_get_byteu(&ctx->gb) + 1;
00518 i -= 4;
00519 } else {
00520 int mx, my;
00521
00522 mx = c37_mv[(mvoff * 255 + code) * 2];
00523 my = c37_mv[(mvoff * 255 + code) * 2 + 1];
00524 codec37_mv(dst + i, prev + i + mx + my * stride,
00525 ctx->height, stride, i + mx, j + my);
00526 }
00527 }
00528 dst += stride * 4;
00529 prev += stride * 4;
00530 }
00531 }
00532 break;
00533 default:
00534 av_log(ctx->avctx, AV_LOG_ERROR,
00535 "subcodec 37 compression %d not implemented\n", compr);
00536 return AVERROR_PATCHWELCOME;
00537 }
00538
00539 return 0;
00540 }
00541
00542 static int process_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *prev1,
00543 uint8_t *prev2, int stride, int tbl, int size)
00544 {
00545 int code, k, t;
00546 uint8_t colors[2];
00547 int8_t *pglyph;
00548
00549 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
00550 return AVERROR_INVALIDDATA;
00551
00552 code = bytestream2_get_byteu(&ctx->gb);
00553 if (code >= 0xF8) {
00554 switch (code) {
00555 case 0xFF:
00556 if (size == 2) {
00557 if (bytestream2_get_bytes_left(&ctx->gb) < 4)
00558 return AVERROR_INVALIDDATA;
00559 dst[0] = bytestream2_get_byteu(&ctx->gb);
00560 dst[1] = bytestream2_get_byteu(&ctx->gb);
00561 dst[0+stride] = bytestream2_get_byteu(&ctx->gb);
00562 dst[1+stride] = bytestream2_get_byteu(&ctx->gb);
00563 } else {
00564 size >>= 1;
00565 if (process_block(ctx, dst, prev1, prev2, stride, tbl, size))
00566 return AVERROR_INVALIDDATA;
00567 if (process_block(ctx, dst + size, prev1 + size, prev2 + size,
00568 stride, tbl, size))
00569 return AVERROR_INVALIDDATA;
00570 dst += size * stride;
00571 prev1 += size * stride;
00572 prev2 += size * stride;
00573 if (process_block(ctx, dst, prev1, prev2, stride, tbl, size))
00574 return AVERROR_INVALIDDATA;
00575 if (process_block(ctx, dst + size, prev1 + size, prev2 + size,
00576 stride, tbl, size))
00577 return AVERROR_INVALIDDATA;
00578 }
00579 break;
00580 case 0xFE:
00581 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
00582 return AVERROR_INVALIDDATA;
00583
00584 t = bytestream2_get_byteu(&ctx->gb);
00585 for (k = 0; k < size; k++)
00586 memset(dst + k * stride, t, size);
00587 break;
00588 case 0xFD:
00589 if (bytestream2_get_bytes_left(&ctx->gb) < 3)
00590 return AVERROR_INVALIDDATA;
00591
00592 code = bytestream2_get_byteu(&ctx->gb);
00593 pglyph = (size == 8) ? ctx->p8x8glyphs[code] : ctx->p4x4glyphs[code];
00594 bytestream2_get_bufferu(&ctx->gb, colors, 2);
00595
00596 for (k = 0; k < size; k++)
00597 for (t = 0; t < size; t++)
00598 dst[t + k * stride] = colors[!*pglyph++];
00599 break;
00600 case 0xFC:
00601 for (k = 0; k < size; k++)
00602 memcpy(dst + k * stride, prev1 + k * stride, size);
00603 break;
00604 default:
00605 k = bytestream2_tell(&ctx->gb);
00606 bytestream2_seek(&ctx->gb, tbl + (code & 7), SEEK_SET);
00607 t = bytestream2_get_byte(&ctx->gb);
00608 bytestream2_seek(&ctx->gb, k, SEEK_SET);
00609 for (k = 0; k < size; k++)
00610 memset(dst + k * stride, t, size);
00611 }
00612 } else {
00613 int mx = motion_vectors[code][0];
00614 int my = motion_vectors[code][1];
00615 for (k = 0; k < size; k++)
00616 memcpy(dst + k * stride, prev2 + mx + (my + k) * stride, size);
00617 }
00618
00619 return 0;
00620 }
00621
00622 static int old_codec47(SANMVideoContext *ctx, int top,
00623 int left, int width, int height)
00624 {
00625 int i, j, seq, compr, new_rot, tbl_pos, skip;
00626 int stride = ctx->pitch;
00627 uint8_t *dst = ((uint8_t*)ctx->frm0) + left + top * stride;
00628 uint8_t *prev1 = (uint8_t*)ctx->frm1;
00629 uint8_t *prev2 = (uint8_t*)ctx->frm2;
00630 uint32_t decoded_size;
00631
00632 tbl_pos = bytestream2_tell(&ctx->gb);
00633 seq = bytestream2_get_le16(&ctx->gb);
00634 compr = bytestream2_get_byte(&ctx->gb);
00635 new_rot = bytestream2_get_byte(&ctx->gb);
00636 skip = bytestream2_get_byte(&ctx->gb);
00637 bytestream2_skip(&ctx->gb, 9);
00638 decoded_size = bytestream2_get_le32(&ctx->gb);
00639 bytestream2_skip(&ctx->gb, 8);
00640
00641 if (skip & 1)
00642 bytestream2_skip(&ctx->gb, 0x8080);
00643 if (!seq) {
00644 ctx->prev_seq = -1;
00645 memset(prev1, 0, ctx->height * stride);
00646 memset(prev2, 0, ctx->height * stride);
00647 }
00648 av_dlog(ctx->avctx, "compression %d\n", compr);
00649 switch (compr) {
00650 case 0:
00651 if (bytestream2_get_bytes_left(&ctx->gb) < width * height)
00652 return AVERROR_INVALIDDATA;
00653 for (j = 0; j < height; j++) {
00654 for (i = 0; i < width; i++)
00655 bytestream2_get_bufferu(&ctx->gb, dst, width);
00656 dst += stride;
00657 }
00658 break;
00659 case 1:
00660 if (bytestream2_get_bytes_left(&ctx->gb) < ((width + 1) >> 1) * ((height + 1) >> 1))
00661 return AVERROR_INVALIDDATA;
00662 for (j = 0; j < height; j += 2) {
00663 for (i = 0; i < width; i += 2) {
00664 dst[i] = dst[i + 1] =
00665 dst[stride + i] = dst[stride + i + 1] = bytestream2_get_byteu(&ctx->gb);
00666 }
00667 dst += stride * 2;
00668 }
00669 break;
00670 case 2:
00671 if (seq == ctx->prev_seq + 1) {
00672 for (j = 0; j < height; j += 8) {
00673 for (i = 0; i < width; i += 8) {
00674 if (process_block(ctx, dst + i, prev1 + i, prev2 + i, stride,
00675 tbl_pos + 8, 8))
00676 return AVERROR_INVALIDDATA;
00677 }
00678 dst += stride * 8;
00679 prev1 += stride * 8;
00680 prev2 += stride * 8;
00681 }
00682 }
00683 break;
00684 case 3:
00685 memcpy(ctx->frm0, ctx->frm2, ctx->pitch * ctx->height);
00686 break;
00687 case 4:
00688 memcpy(ctx->frm0, ctx->frm1, ctx->pitch * ctx->height);
00689 break;
00690 case 5:
00691 if (rle_decode(ctx, dst, decoded_size))
00692 return AVERROR_INVALIDDATA;
00693 break;
00694 default:
00695 av_log(ctx->avctx, AV_LOG_ERROR,
00696 "subcodec 47 compression %d not implemented\n", compr);
00697 return AVERROR_PATCHWELCOME;
00698 }
00699 if (seq == ctx->prev_seq + 1)
00700 ctx->rotate_code = new_rot;
00701 else
00702 ctx->rotate_code = 0;
00703 ctx->prev_seq = seq;
00704
00705 return 0;
00706 }
00707
00708 static int process_frame_obj(SANMVideoContext *ctx)
00709 {
00710 uint16_t codec, top, left, w, h;
00711
00712 codec = bytestream2_get_le16u(&ctx->gb);
00713 left = bytestream2_get_le16u(&ctx->gb);
00714 top = bytestream2_get_le16u(&ctx->gb);
00715 w = bytestream2_get_le16u(&ctx->gb);
00716 h = bytestream2_get_le16u(&ctx->gb);
00717
00718 if (ctx->width < left + w || ctx->height < top + h) {
00719 ctx->avctx->width = FFMAX(left + w, ctx->width);
00720 ctx->avctx->height = FFMAX(top + h, ctx->height);
00721 init_sizes(ctx, left + w, top + h);
00722 if (init_buffers(ctx)) {
00723 av_log(ctx->avctx, AV_LOG_ERROR, "error resizing buffers\n");
00724 return AVERROR(ENOMEM);
00725 }
00726 }
00727 bytestream2_skip(&ctx->gb, 4);
00728
00729 av_dlog(ctx->avctx, "subcodec %d\n", codec);
00730 switch (codec) {
00731 case 1:
00732 case 3:
00733 return old_codec1(ctx, top, left, w, h);
00734 break;
00735 case 37:
00736 return old_codec37(ctx, top, left, w, h);
00737 break;
00738 case 47:
00739 return old_codec47(ctx, top, left, w, h);
00740 break;
00741 default:
00742 av_log_ask_for_sample(ctx->avctx, "unknown subcodec %d\n", codec);
00743 return AVERROR_PATCHWELCOME;
00744 }
00745 }
00746
00747 static int decode_0(SANMVideoContext *ctx)
00748 {
00749 uint16_t *frm = ctx->frm0;
00750 int x, y;
00751
00752 if (bytestream2_get_bytes_left(&ctx->gb) < ctx->width * ctx->height * 2) {
00753 av_log(ctx->avctx, AV_LOG_ERROR, "insufficient data for raw frame\n");
00754 return AVERROR_INVALIDDATA;
00755 }
00756 for (y = 0; y < ctx->height; y++) {
00757 for (x = 0; x < ctx->width; x++)
00758 frm[x] = bytestream2_get_le16u(&ctx->gb);
00759 frm += ctx->pitch;
00760 }
00761 return 0;
00762 }
00763
00764 static int decode_nop(SANMVideoContext *ctx)
00765 {
00766 av_log_ask_for_sample(ctx->avctx, "unknown/unsupported compression type\n");
00767 return AVERROR_PATCHWELCOME;
00768 }
00769
00770 static void copy_block(uint16_t *pdest, uint16_t *psrc, int block_size, int pitch)
00771 {
00772 uint8_t *dst = (uint8_t *)pdest;
00773 uint8_t *src = (uint8_t *)psrc;
00774 int stride = pitch * 2;
00775
00776 switch (block_size) {
00777 case 2:
00778 copy_block4(dst, src, stride, stride, 2);
00779 break;
00780 case 4:
00781 copy_block8(dst, src, stride, stride, 4);
00782 break;
00783 case 8:
00784 copy_block16(dst, src, stride, stride, 8);
00785 break;
00786 }
00787 }
00788
00789 static void fill_block(uint16_t *pdest, uint16_t color, int block_size, int pitch)
00790 {
00791 int x, y;
00792
00793 pitch -= block_size;
00794 for (y = 0; y < block_size; y++, pdest += pitch)
00795 for (x = 0; x < block_size; x++)
00796 *pdest++ = color;
00797 }
00798
00799 static int draw_glyph(SANMVideoContext *ctx, uint16_t *dst, int index, uint16_t fg_color,
00800 uint16_t bg_color, int block_size, int pitch)
00801 {
00802 int8_t *pglyph;
00803 uint16_t colors[2] = { fg_color, bg_color };
00804 int x, y;
00805
00806 if (index >= NGLYPHS) {
00807 av_log(ctx->avctx, AV_LOG_ERROR, "ignoring nonexistent glyph #%u\n", index);
00808 return AVERROR_INVALIDDATA;
00809 }
00810
00811 pglyph = block_size == 8 ? ctx->p8x8glyphs[index] : ctx->p4x4glyphs[index];
00812 pitch -= block_size;
00813
00814 for (y = 0; y < block_size; y++, dst += pitch)
00815 for (x = 0; x < block_size; x++)
00816 *dst++ = colors[*pglyph++];
00817 return 0;
00818 }
00819
00820 static int opcode_0xf7(SANMVideoContext *ctx, int cx, int cy, int block_size, int pitch)
00821 {
00822 uint16_t *dst = ctx->frm0 + cx + cy * ctx->pitch;
00823
00824 if (block_size == 2) {
00825 uint32_t indices;
00826
00827 if (bytestream2_get_bytes_left(&ctx->gb) < 4)
00828 return AVERROR_INVALIDDATA;
00829
00830 indices = bytestream2_get_le32u(&ctx->gb);
00831 dst[0] = ctx->codebook[indices & 0xFF]; indices >>= 8;
00832 dst[1] = ctx->codebook[indices & 0xFF]; indices >>= 8;
00833 dst[pitch] = ctx->codebook[indices & 0xFF]; indices >>= 8;
00834 dst[pitch + 1] = ctx->codebook[indices & 0xFF];
00835 } else {
00836 uint16_t fgcolor, bgcolor;
00837 int glyph;
00838
00839 if (bytestream2_get_bytes_left(&ctx->gb) < 3)
00840 return AVERROR_INVALIDDATA;
00841
00842 glyph = bytestream2_get_byteu(&ctx->gb);
00843 bgcolor = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
00844 fgcolor = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
00845
00846 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
00847 }
00848 return 0;
00849 }
00850
00851 static int opcode_0xf8(SANMVideoContext *ctx, int cx, int cy, int block_size, int pitch)
00852 {
00853 uint16_t *dst = ctx->frm0 + cx + cy * ctx->pitch;
00854
00855 if (block_size == 2) {
00856 if (bytestream2_get_bytes_left(&ctx->gb) < 8)
00857 return AVERROR_INVALIDDATA;
00858
00859 dst[0] = bytestream2_get_le16u(&ctx->gb);
00860 dst[1] = bytestream2_get_le16u(&ctx->gb);
00861 dst[pitch] = bytestream2_get_le16u(&ctx->gb);
00862 dst[pitch + 1] = bytestream2_get_le16u(&ctx->gb);
00863 } else {
00864 uint16_t fgcolor, bgcolor;
00865 int glyph;
00866
00867 if (bytestream2_get_bytes_left(&ctx->gb) < 5)
00868 return AVERROR_INVALIDDATA;
00869
00870 glyph = bytestream2_get_byteu(&ctx->gb);
00871 bgcolor = bytestream2_get_le16u(&ctx->gb);
00872 fgcolor = bytestream2_get_le16u(&ctx->gb);
00873
00874 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
00875 }
00876 return 0;
00877 }
00878
00879 static int good_mvec(SANMVideoContext *ctx, int cx, int cy, int mx, int my,
00880 int block_size)
00881 {
00882 int start_pos = cx + mx + (cy + my) * ctx->pitch;
00883 int end_pos = start_pos + (block_size - 1) * (ctx->pitch + 1);
00884
00885 int good = start_pos >= 0 && end_pos < (ctx->buf_size >> 1);
00886
00887 if (!good) {
00888 av_log(ctx->avctx, AV_LOG_ERROR, "ignoring invalid motion vector (%i, %i)->(%u, %u), block size = %u\n",
00889 cx + mx, cy + my, cx, cy, block_size);
00890 }
00891
00892 return good;
00893 }
00894
00895 static int codec2subblock(SANMVideoContext *ctx, int cx, int cy, int blk_size)
00896 {
00897 int16_t mx, my, index;
00898 int opcode;
00899
00900 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
00901 return AVERROR_INVALIDDATA;
00902
00903 opcode = bytestream2_get_byteu(&ctx->gb);
00904
00905 av_dlog(ctx->avctx, "opcode 0x%0X cx %d cy %d blk %d\n", opcode, cx, cy, blk_size);
00906 switch (opcode) {
00907 default:
00908 mx = motion_vectors[opcode][0];
00909 my = motion_vectors[opcode][1];
00910
00911 if (good_mvec(ctx, cx, cy, mx, my, blk_size)) {
00912 copy_block(ctx->frm0 + cx + ctx->pitch * cy,
00913 ctx->frm2 + cx + mx + ctx->pitch * (cy + my),
00914 blk_size, ctx->pitch);
00915 }
00916 break;
00917 case 0xF5:
00918 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
00919 return AVERROR_INVALIDDATA;
00920 index = bytestream2_get_le16u(&ctx->gb);
00921
00922 mx = index % ctx->width;
00923 my = index / ctx->width;
00924
00925 if (good_mvec(ctx, cx, cy, mx, my, blk_size)) {
00926 copy_block(ctx->frm0 + cx + ctx->pitch * cy,
00927 ctx->frm2 + cx + mx + ctx->pitch * (cy + my),
00928 blk_size, ctx->pitch);
00929 }
00930 break;
00931 case 0xF6:
00932 copy_block(ctx->frm0 + cx + ctx->pitch * cy,
00933 ctx->frm1 + cx + ctx->pitch * cy,
00934 blk_size, ctx->pitch);
00935 break;
00936 case 0xF7:
00937 opcode_0xf7(ctx, cx, cy, blk_size, ctx->pitch);
00938 break;
00939
00940 case 0xF8:
00941 opcode_0xf8(ctx, cx, cy, blk_size, ctx->pitch);
00942 break;
00943 case 0xF9:
00944 case 0xFA:
00945 case 0xFB:
00946 case 0xFC:
00947 fill_block(ctx->frm0 + cx + cy * ctx->pitch,
00948 ctx->small_codebook[opcode - 0xf9], blk_size, ctx->pitch);
00949 break;
00950 case 0xFD:
00951 if (bytestream2_get_bytes_left(&ctx->gb) < 1)
00952 return AVERROR_INVALIDDATA;
00953 fill_block(ctx->frm0 + cx + cy * ctx->pitch,
00954 ctx->codebook[bytestream2_get_byteu(&ctx->gb)], blk_size, ctx->pitch);
00955 break;
00956 case 0xFE:
00957 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
00958 return AVERROR_INVALIDDATA;
00959 fill_block(ctx->frm0 + cx + cy * ctx->pitch,
00960 bytestream2_get_le16u(&ctx->gb), blk_size, ctx->pitch);
00961 break;
00962 case 0xFF:
00963 if (blk_size == 2) {
00964 opcode_0xf8(ctx, cx, cy, blk_size, ctx->pitch);
00965 } else {
00966 blk_size >>= 1;
00967 if (codec2subblock(ctx, cx , cy , blk_size))
00968 return AVERROR_INVALIDDATA;
00969 if (codec2subblock(ctx, cx + blk_size, cy , blk_size))
00970 return AVERROR_INVALIDDATA;
00971 if (codec2subblock(ctx, cx , cy + blk_size, blk_size))
00972 return AVERROR_INVALIDDATA;
00973 if (codec2subblock(ctx, cx + blk_size, cy + blk_size, blk_size))
00974 return AVERROR_INVALIDDATA;
00975 }
00976 break;
00977 }
00978 return 0;
00979 }
00980
00981 static int decode_2(SANMVideoContext *ctx)
00982 {
00983 int cx, cy, ret;
00984
00985 for (cy = 0; cy < ctx->aligned_height; cy += 8) {
00986 for (cx = 0; cx < ctx->aligned_width; cx += 8) {
00987 if (ret = codec2subblock(ctx, cx, cy, 8))
00988 return ret;
00989 }
00990 }
00991
00992 return 0;
00993 }
00994
00995 static int decode_3(SANMVideoContext *ctx)
00996 {
00997 memcpy(ctx->frm0, ctx->frm2, ctx->frm2_size);
00998 return 0;
00999 }
01000
01001 static int decode_4(SANMVideoContext *ctx)
01002 {
01003 memcpy(ctx->frm0, ctx->frm1, ctx->frm1_size);
01004 return 0;
01005 }
01006
01007 static int decode_5(SANMVideoContext *ctx)
01008 {
01009 #if HAVE_BIGENDIAN
01010 uint16_t *frm;
01011 int npixels;
01012 #endif
01013 uint8_t *dst = (uint8_t*)ctx->frm0;
01014
01015 if (rle_decode(ctx, dst, ctx->buf_size))
01016 return AVERROR_INVALIDDATA;
01017
01018 #if HAVE_BIGENDIAN
01019 npixels = ctx->npixels;
01020 frm = ctx->frm0;
01021 while (npixels--)
01022 *frm++ = av_bswap16(*frm);
01023 #endif
01024
01025 return 0;
01026 }
01027
01028 static int decode_6(SANMVideoContext *ctx)
01029 {
01030 int npixels = ctx->npixels;
01031 uint16_t *frm = ctx->frm0;
01032
01033 if (bytestream2_get_bytes_left(&ctx->gb) < npixels) {
01034 av_log(ctx->avctx, AV_LOG_ERROR, "insufficient data for frame\n");
01035 return AVERROR_INVALIDDATA;
01036 }
01037 while (npixels--)
01038 *frm++ = ctx->codebook[bytestream2_get_byteu(&ctx->gb)];
01039
01040 return 0;
01041 }
01042
01043 static int decode_8(SANMVideoContext *ctx)
01044 {
01045 uint16_t *pdest = ctx->frm0;
01046 uint8_t *rsrc;
01047 long npixels = ctx->npixels;
01048
01049 av_fast_malloc(&ctx->rle_buf, &ctx->rle_buf_size, npixels);
01050 if (!ctx->rle_buf) {
01051 av_log(ctx->avctx, AV_LOG_ERROR, "RLE buffer allocation failed\n");
01052 return AVERROR(ENOMEM);
01053 }
01054 rsrc = ctx->rle_buf;
01055
01056 if (rle_decode(ctx, rsrc, npixels))
01057 return AVERROR_INVALIDDATA;
01058
01059 while (npixels--)
01060 *pdest++ = ctx->codebook[*rsrc++];
01061
01062 return 0;
01063 }
01064
01065 typedef int (*frm_decoder)(SANMVideoContext *ctx);
01066
01067 static const frm_decoder v1_decoders[] = {
01068 decode_0, decode_nop, decode_2, decode_3, decode_4, decode_5,
01069 decode_6, decode_nop, decode_8
01070 };
01071
01072 static int read_frame_header(SANMVideoContext *ctx, SANMFrameHeader *hdr)
01073 {
01074 int i, ret;
01075
01076 if ((ret = bytestream2_get_bytes_left(&ctx->gb)) < 560) {
01077 av_log(ctx->avctx, AV_LOG_ERROR, "too short input frame (%d bytes)\n",
01078 ret);
01079 return AVERROR_INVALIDDATA;
01080 }
01081 bytestream2_skip(&ctx->gb, 8);
01082
01083 hdr->width = bytestream2_get_le32u(&ctx->gb);
01084 hdr->height = bytestream2_get_le32u(&ctx->gb);
01085
01086 if (hdr->width != ctx->width || hdr->height != ctx->height) {
01087 av_log(ctx->avctx, AV_LOG_ERROR, "variable size frames are not implemented\n");
01088 return AVERROR_PATCHWELCOME;
01089 }
01090
01091 hdr->seq_num = bytestream2_get_le16u(&ctx->gb);
01092 hdr->codec = bytestream2_get_byteu(&ctx->gb);
01093 hdr->rotate_code = bytestream2_get_byteu(&ctx->gb);
01094
01095 bytestream2_skip(&ctx->gb, 4);
01096
01097 for (i = 0; i < 4; i++)
01098 ctx->small_codebook[i] = bytestream2_get_le16u(&ctx->gb);
01099 hdr->bg_color = bytestream2_get_le16u(&ctx->gb);
01100
01101 bytestream2_skip(&ctx->gb, 2);
01102
01103 hdr->rle_output_size = bytestream2_get_le32u(&ctx->gb);
01104 for (i = 0; i < 256; i++)
01105 ctx->codebook[i] = bytestream2_get_le16u(&ctx->gb);
01106
01107 bytestream2_skip(&ctx->gb, 8);
01108
01109 av_dlog(ctx->avctx, "subcodec %d\n", hdr->codec);
01110 return 0;
01111 }
01112
01113 static void fill_frame(uint16_t *pbuf, int buf_size, uint16_t color)
01114 {
01115 while (buf_size--)
01116 *pbuf++ = color;
01117 }
01118
01119 static int copy_output(SANMVideoContext *ctx, SANMFrameHeader *hdr)
01120 {
01121 uint8_t *dst;
01122 const uint8_t *src = (uint8_t*) ctx->frm0;
01123 int ret, dstpitch, height = ctx->height;
01124 int srcpitch = ctx->pitch * (hdr ? sizeof(ctx->frm0[0]) : 1);
01125
01126 if ((ret = ff_get_buffer(ctx->avctx, ctx->output)) < 0) {
01127 av_log(ctx->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
01128 return ret;
01129 }
01130
01131 dst = ctx->output->data[0];
01132 dstpitch = ctx->output->linesize[0];
01133
01134 while (height--) {
01135 memcpy(dst, src, srcpitch);
01136 src += srcpitch;
01137 dst += dstpitch;
01138 }
01139
01140 return 0;
01141 }
01142
01143 static int decode_frame(AVCodecContext *avctx, void *data,
01144 int *got_frame_ptr, AVPacket *pkt)
01145 {
01146 SANMVideoContext *ctx = avctx->priv_data;
01147 int i, ret;
01148
01149 bytestream2_init(&ctx->gb, pkt->data, pkt->size);
01150 if (ctx->output->data[0])
01151 avctx->release_buffer(avctx, ctx->output);
01152
01153 if (!ctx->version) {
01154 int to_store = 0;
01155
01156 while (bytestream2_get_bytes_left(&ctx->gb) >= 8) {
01157 uint32_t sig, size;
01158 int pos;
01159
01160 sig = bytestream2_get_be32u(&ctx->gb);
01161 size = bytestream2_get_be32u(&ctx->gb);
01162 pos = bytestream2_tell(&ctx->gb);
01163
01164 if (bytestream2_get_bytes_left(&ctx->gb) < size) {
01165 av_log(avctx, AV_LOG_ERROR, "incorrect chunk size %d\n", size);
01166 break;
01167 }
01168 switch (sig) {
01169 case MKBETAG('N', 'P', 'A', 'L'):
01170 if (size != 256 * 3) {
01171 av_log(avctx, AV_LOG_ERROR, "incorrect palette block size %d\n",
01172 size);
01173 return AVERROR_INVALIDDATA;
01174 }
01175 for (i = 0; i < 256; i++)
01176 ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb);
01177 break;
01178 case MKBETAG('F', 'O', 'B', 'J'):
01179 if (size < 16)
01180 return AVERROR_INVALIDDATA;
01181 if (ret = process_frame_obj(ctx))
01182 return ret;
01183 break;
01184 case MKBETAG('X', 'P', 'A', 'L'):
01185 if (size == 6 || size == 4) {
01186 uint8_t tmp[3];
01187 int j;
01188
01189 for (i = 0; i < 256; i++) {
01190 for (j = 0; j < 3; j++) {
01191 int t = (ctx->pal[i] >> (16 - j * 8)) & 0xFF;
01192 tmp[j] = av_clip_uint8((t * 129 + ctx->delta_pal[i * 3 + j]) >> 7);
01193 }
01194 ctx->pal[i] = 0xFFU << 24 | AV_RB24(tmp);
01195 }
01196 } else {
01197 if (size < 768 * 2 + 4) {
01198 av_log(avctx, AV_LOG_ERROR, "incorrect palette change block size %d\n",
01199 size);
01200 return AVERROR_INVALIDDATA;
01201 }
01202 bytestream2_skipu(&ctx->gb, 4);
01203 for (i = 0; i < 768; i++)
01204 ctx->delta_pal[i] = bytestream2_get_le16u(&ctx->gb);
01205 if (size >= 768 * 5 + 4) {
01206 for (i = 0; i < 256; i++)
01207 ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb);
01208 } else {
01209 memset(ctx->pal, 0, sizeof(ctx->pal));
01210 }
01211 }
01212 break;
01213 case MKBETAG('S', 'T', 'O', 'R'):
01214 to_store = 1;
01215 break;
01216 case MKBETAG('F', 'T', 'C', 'H'):
01217 memcpy(ctx->frm0, ctx->stored_frame, ctx->buf_size);
01218 break;
01219 default:
01220 bytestream2_skip(&ctx->gb, size);
01221 av_log(avctx, AV_LOG_DEBUG, "unknown/unsupported chunk %x\n", sig);
01222 break;
01223 }
01224
01225 bytestream2_seek(&ctx->gb, pos + size, SEEK_SET);
01226 if (size & 1)
01227 bytestream2_skip(&ctx->gb, 1);
01228 }
01229 if (to_store)
01230 memcpy(ctx->stored_frame, ctx->frm0, ctx->buf_size);
01231 if ((ret = copy_output(ctx, NULL)))
01232 return ret;
01233 memcpy(ctx->output->data[1], ctx->pal, 1024);
01234 } else {
01235 SANMFrameHeader header;
01236
01237 if ((ret = read_frame_header(ctx, &header)))
01238 return ret;
01239
01240 ctx->rotate_code = header.rotate_code;
01241 if ((ctx->output->key_frame = !header.seq_num)) {
01242 ctx->output->pict_type = AV_PICTURE_TYPE_I;
01243 fill_frame(ctx->frm1, ctx->npixels, header.bg_color);
01244 fill_frame(ctx->frm2, ctx->npixels, header.bg_color);
01245 } else {
01246 ctx->output->pict_type = AV_PICTURE_TYPE_P;
01247 }
01248
01249 if (header.codec < FF_ARRAY_ELEMS(v1_decoders)) {
01250 if ((ret = v1_decoders[header.codec](ctx))) {
01251 av_log(avctx, AV_LOG_ERROR,
01252 "subcodec %d: error decoding frame\n", header.codec);
01253 return ret;
01254 }
01255 } else {
01256 av_log_ask_for_sample(avctx, "subcodec %d is not implemented\n",
01257 header.codec);
01258 return AVERROR_PATCHWELCOME;
01259 }
01260
01261 if ((ret = copy_output(ctx, &header)))
01262 return ret;
01263 }
01264 if (ctx->rotate_code)
01265 rotate_bufs(ctx, ctx->rotate_code);
01266
01267 *got_frame_ptr = 1;
01268 *(AVFrame*)data = *ctx->output;
01269
01270 return pkt->size;
01271 }
01272
01273 AVCodec ff_sanm_decoder = {
01274 .name = "sanm",
01275 .type = AVMEDIA_TYPE_VIDEO,
01276 .id = AV_CODEC_ID_SANM,
01277 .priv_data_size = sizeof(SANMVideoContext),
01278 .init = decode_init,
01279 .close = decode_end,
01280 .decode = decode_frame,
01281 .capabilities = CODEC_CAP_DR1,
01282 .long_name = NULL_IF_CONFIG_SMALL("LucasArts SMUSH video"),
01283 };