97
97
src += ((c->bx * c->by * 2 + 3) & ~3);
100
for(y = 0; y < c->height; y += c->bh) {
100
for (y = 0; y < c->height; y += c->bh) {
101
101
bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
102
for(x = 0; x < c->width; x += c->bw) {
102
for (x = 0; x < c->width; x += c->bw) {
103
103
uint8_t *out, *tprev;
105
105
d = mvec[block] & 1;
114
114
tprev = prev + x + dx + dy * c->width;
117
for(j = 0; j < bh2; j++){
118
if((my + j < 0) || (my + j >= c->height)) {
117
for (j = 0; j < bh2; j++) {
118
if (my + j < 0 || my + j >= c->height) {
119
119
memset(out, 0, bw2);
121
for(i = 0; i < bw2; i++){
122
if((mx + i < 0) || (mx + i >= c->width))
121
for (i = 0; i < bw2; i++) {
122
if (mx + i < 0 || mx + i >= c->width)
125
125
out[i] = tprev[i];
129
129
tprev += c->width;
132
if(d) { /* apply XOR'ed difference */
132
if (d) { /* apply XOR'ed difference */
133
133
out = output + x;
134
for(j = 0; j < bh2; j++){
135
for(i = 0; i < bw2; i++)
134
for (j = 0; j < bh2; j++) {
135
for (i = 0; i < bw2; i++)
136
136
out[i] ^= *src++;
141
141
output += c->width * c->bh;
142
142
prev += c->width * c->bh;
144
if(src - c->decomp_buf != c->decomp_len)
145
av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len);
144
if (src - c->decomp_buf != c->decomp_len)
145
av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n",
146
src-c->decomp_buf, c->decomp_len);
168
169
src += ((c->bx * c->by * 2 + 3) & ~3);
171
for(y = 0; y < c->height; y += c->bh) {
172
for (y = 0; y < c->height; y += c->bh) {
172
173
bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
173
for(x = 0; x < c->width; x += c->bw) {
174
for (x = 0; x < c->width; x += c->bw) {
174
175
uint16_t *out, *tprev;
176
177
d = mvec[block] & 1;
185
186
tprev = prev + x + dx + dy * c->width;
188
for(j = 0; j < bh2; j++){
189
if((my + j < 0) || (my + j >= c->height)) {
189
for (j = 0; j < bh2; j++) {
190
if (my + j < 0 || my + j >= c->height) {
190
191
memset(out, 0, bw2 * 2);
192
for(i = 0; i < bw2; i++){
193
if((mx + i < 0) || (mx + i >= c->width))
193
for (i = 0; i < bw2; i++) {
194
if (mx + i < 0 || mx + i >= c->width)
196
197
out[i] = tprev[i];
200
201
tprev += c->width;
203
if(d) { /* apply XOR'ed difference */
204
if (d) { /* apply XOR'ed difference */
204
205
out = output + x;
205
for(j = 0; j < bh2; j++){
206
for(i = 0; i < bw2; i++) {
206
for (j = 0; j < bh2; j++){
207
for (i = 0; i < bw2; i++) {
207
208
out[i] ^= *((uint16_t*)src);
214
215
output += c->width * c->bh;
215
216
prev += c->width * c->bh;
217
if(src - c->decomp_buf != c->decomp_len)
218
av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len);
218
if (src - c->decomp_buf != c->decomp_len)
219
av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n",
220
src-c->decomp_buf, c->decomp_len);
244
246
src += ((c->bx * c->by * 2 + 3) & ~3);
247
for(y = 0; y < c->height; y += c->bh) {
249
for (y = 0; y < c->height; y += c->bh) {
248
250
bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
249
for(x = 0; x < c->width; x += c->bw) {
251
for (x = 0; x < c->width; x += c->bw) {
250
252
uint8_t *out, *tprev;
252
254
d = mvec[block] & 1;
261
263
tprev = prev + (x + dx) * 3 + dy * stride;
264
for(j = 0; j < bh2; j++){
265
if((my + j < 0) || (my + j >= c->height)) {
266
for (j = 0; j < bh2; j++) {
267
if (my + j < 0 || my + j >= c->height) {
266
268
memset(out, 0, bw2 * 3);
268
for(i = 0; i < bw2; i++){
269
if((mx + i < 0) || (mx + i >= c->width)) {
270
for (i = 0; i < bw2; i++){
271
if (mx + i < 0 || mx + i >= c->width) {
270
272
out[i * 3 + 0] = 0;
271
273
out[i * 3 + 1] = 0;
272
274
out[i * 3 + 2] = 0;
284
if(d) { /* apply XOR'ed difference */
286
if (d) { /* apply XOR'ed difference */
285
287
out = output + x * 3;
286
for(j = 0; j < bh2; j++){
287
for(i = 0; i < bw2; i++) {
288
for (j = 0; j < bh2; j++) {
289
for (i = 0; i < bw2; i++) {
288
290
out[i * 3 + 0] ^= *src++;
289
291
out[i * 3 + 1] ^= *src++;
290
292
out[i * 3 + 2] ^= *src++;
296
298
output += stride * c->bh;
297
299
prev += stride * c->bh;
299
if(src - c->decomp_buf != c->decomp_len)
300
av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
301
if (src - c->decomp_buf != c->decomp_len)
302
av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n",
303
src-c->decomp_buf, c->decomp_len);
303
306
#endif //ZMBV_ENABLE_24BPP
324
327
src += ((c->bx * c->by * 2 + 3) & ~3);
327
for(y = 0; y < c->height; y += c->bh) {
330
for (y = 0; y < c->height; y += c->bh) {
328
331
bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
329
for(x = 0; x < c->width; x += c->bw) {
332
for (x = 0; x < c->width; x += c->bw) {
330
333
uint32_t *out, *tprev;
332
335
d = mvec[block] & 1;
341
344
tprev = prev + x + dx + dy * c->width;
344
for(j = 0; j < bh2; j++){
345
if((my + j < 0) || (my + j >= c->height)) {
347
for (j = 0; j < bh2; j++) {
348
if (my + j < 0 || my + j >= c->height) {
346
349
memset(out, 0, bw2 * 4);
348
for(i = 0; i < bw2; i++){
349
if((mx + i < 0) || (mx + i >= c->width))
351
for (i = 0; i < bw2; i++){
352
if (mx + i < 0 || mx + i >= c->width)
352
355
out[i] = tprev[i];
356
359
tprev += c->width;
359
if(d) { /* apply XOR'ed difference */
362
if (d) { /* apply XOR'ed difference */
360
363
out = output + x;
361
for(j = 0; j < bh2; j++){
362
for(i = 0; i < bw2; i++) {
363
out[i] ^= *((uint32_t*)src);
364
for (j = 0; j < bh2; j++){
365
for (i = 0; i < bw2; i++) {
366
out[i] ^= *((uint32_t *) src);
370
373
output += c->width * c->bh;
371
prev += c->width * c->bh;
374
prev += c->width * c->bh;
373
if(src - c->decomp_buf != c->decomp_len)
374
av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len);
376
if (src - c->decomp_buf != c->decomp_len)
377
av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n",
378
src-c->decomp_buf, c->decomp_len);
401
405
int len = buf_size;
402
406
int hi_ver, lo_ver;
405
409
avctx->release_buffer(avctx, &c->pic);
407
411
c->pic.reference = 1;
408
412
c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
409
if(avctx->get_buffer(avctx, &c->pic) < 0){
413
if (avctx->get_buffer(avctx, &c->pic) < 0) {
410
414
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
427
av_log(avctx, AV_LOG_DEBUG, "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh);
428
if(hi_ver != 0 || lo_ver != 1) {
429
av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\n", hi_ver, lo_ver);
432
if(c->bw == 0 || c->bh == 0) {
433
av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n", c->bw, c->bh);
436
if(c->comp != 0 && c->comp != 1) {
437
av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n", c->comp);
431
av_log(avctx, AV_LOG_DEBUG,
432
"Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",
433
c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh);
434
if (hi_ver != 0 || lo_ver != 1) {
435
av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\n",
439
if (c->bw == 0 || c->bh == 0) {
440
av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n",
444
if (c->comp != 0 && c->comp != 1) {
445
av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n",
442
451
case ZMBV_FMT_8BPP:
444
453
c->decode_intra = zmbv_decode_intra;
466
475
c->decode_intra = NULL;
467
476
c->decode_xor = NULL;
468
av_log(avctx, AV_LOG_ERROR, "Unsupported (for now) format %i\n", c->fmt);
477
av_log(avctx, AV_LOG_ERROR,
478
"Unsupported (for now) format %i\n", c->fmt);
473
483
if (zret != Z_OK) {
474
484
av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
478
c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8));
479
c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8));
480
c->bx = (c->width + c->bw - 1) / c->bw;
481
c->by = (c->height+ c->bh - 1) / c->bh;
484
if(c->decode_intra == NULL) {
485
av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n");
489
if(c->comp == 0) { //Uncompressed data
490
memcpy(c->decomp_buf, buf, len);
492
} else { // ZLIB-compressed data
488
c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8));
489
c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8));
490
c->bx = (c->width + c->bw - 1) / c->bw;
491
c->by = (c->height+ c->bh - 1) / c->bh;
494
if (c->decode_intra == NULL) {
495
av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n");
499
if (c->comp == 0) { //Uncompressed data
500
memcpy(c->decomp_buf, buf, len);
502
} else { // ZLIB-compressed data
493
503
c->zstream.total_in = c->zstream.total_out = 0;
494
504
c->zstream.next_in = buf;
495
505
c->zstream.avail_in = len;
498
508
inflate(&c->zstream, Z_FINISH);
499
509
c->decomp_len = c->zstream.total_out;
501
if(c->flags & ZMBV_KEYFRAME) {
511
if (c->flags & ZMBV_KEYFRAME) {
502
512
c->pic.key_frame = 1;
503
513
c->pic.pict_type = AV_PICTURE_TYPE_I;
504
514
c->decode_intra(c);
506
516
c->pic.key_frame = 0;
507
517
c->pic.pict_type = AV_PICTURE_TYPE_P;
509
519
c->decode_xor(c);
517
527
out = c->pic.data[0];
520
530
case ZMBV_FMT_8BPP:
521
for(j = 0; j < c->height; j++) {
522
for(i = 0; i < c->width; i++) {
531
for (j = 0; j < c->height; j++) {
532
for (i = 0; i < c->width; i++) {
523
533
out[i * 3 + 0] = c->pal[(*src) * 3 + 0];
524
534
out[i * 3 + 1] = c->pal[(*src) * 3 + 1];
525
535
out[i * 3 + 2] = c->pal[(*src) * 3 + 2];
531
541
case ZMBV_FMT_15BPP:
532
for(j = 0; j < c->height; j++) {
533
for(i = 0; i < c->width; i++) {
542
for (j = 0; j < c->height; j++) {
543
for (i = 0; i < c->width; i++) {
534
544
uint16_t tmp = AV_RL16(src);
536
546
out[i * 3 + 0] = (tmp & 0x7C00) >> 7;
543
553
case ZMBV_FMT_16BPP:
544
for(j = 0; j < c->height; j++) {
545
for(i = 0; i < c->width; i++) {
554
for (j = 0; j < c->height; j++) {
555
for (i = 0; i < c->width; i++) {
546
556
uint16_t tmp = AV_RL16(src);
548
558
out[i * 3 + 0] = (tmp & 0xF800) >> 8;
555
565
#ifdef ZMBV_ENABLE_24BPP
556
566
case ZMBV_FMT_24BPP:
557
for(j = 0; j < c->height; j++) {
567
for (j = 0; j < c->height; j++) {
558
568
memcpy(out, src, c->width * 3);
559
569
src += c->width * 3;
560
570
out += c->pic.linesize[0];
563
573
#endif //ZMBV_ENABLE_24BPP
564
574
case ZMBV_FMT_32BPP:
565
for(j = 0; j < c->height; j++) {
566
for(i = 0; i < c->width; i++) {
575
for (j = 0; j < c->height; j++) {
576
for (i = 0; i < c->width; i++) {
567
577
uint32_t tmp = AV_RL32(src);
569
579
AV_WB24(out+(i*3), tmp);
575
585
av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\n", c->fmt);
577
memcpy(c->prev, c->cur, c->width * c->height * (c->bpp / 8));
587
FFSWAP(uint8_t *, c->cur, c->prev);
579
589
*data_size = sizeof(AVFrame);
580
590
*(AVFrame*)data = c->pic;
603
613
c->bpp = avctx->bits_per_coded_sample;
605
615
// Needed if zlib unused or init aborted before inflateInit
606
memset(&(c->zstream), 0, sizeof(z_stream));
616
memset(&c->zstream, 0, sizeof(z_stream));
608
618
avctx->pix_fmt = PIX_FMT_RGB24;
609
619
c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64);
611
621
/* Allocate decompression buffer */
612
622
if (c->decomp_size) {
613
623
if ((c->decomp_buf = av_malloc(c->decomp_size)) == NULL) {
614
av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
624
av_log(avctx, AV_LOG_ERROR,
625
"Can't allocate decompression buffer.\n");
619
630
c->zstream.zalloc = Z_NULL;
620
631
c->zstream.zfree = Z_NULL;
621
632
c->zstream.opaque = Z_NULL;
622
zret = inflateInit(&(c->zstream));
633
zret = inflateInit(&c->zstream);
623
634
if (zret != Z_OK) {
624
635
av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
653
664
AVCodec ff_zmbv_decoder = {
666
.type = AVMEDIA_TYPE_VIDEO,
668
.priv_data_size = sizeof(ZmbvContext),
671
.decode = decode_frame,
672
.capabilities = CODEC_CAP_DR1,
663
673
.long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"),