Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2011 Google Inc.
//
// This code is licensed under the same terms as WebM:
//  Software License Agreement:  http://www.webmproject.org/license/software/
//  Additional IP Rights Grant:  http://www.webmproject.org/license/additional/
// -----------------------------------------------------------------------------
//
// Alpha-plane decompression.
//
// Author: Skal (pascal.massimino@gmail.com)

#include <stdlib.h>
#include "vp8i.h"

#ifdef WEBP_EXPERIMENTAL_FEATURES

#include "zlib.h"

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

//------------------------------------------------------------------------------

const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
                                      int row, int num_rows) {
  uint8_t* output = dec->alpha_plane_;
  const int stride = dec->pic_hdr_.width_;
  if (row < 0 || row + num_rows > dec->pic_hdr_.height_) {
    return NULL;    // sanity check
  }
  if (row == 0) {
    // TODO(skal): for now, we just decompress everything during the first call.
    // Later, we'll decode progressively, but we need to store the
    // z_stream state.
    const uint8_t* data = dec->alpha_data_;
    size_t data_size = dec->alpha_data_size_;
    const size_t output_size = stride * dec->pic_hdr_.height_;
    int ret = Z_OK;
    z_stream strm;

    memset(&strm, 0, sizeof(strm));
    if (inflateInit(&strm) != Z_OK) {
      return 0;
    }
    strm.avail_in = data_size;
    strm.next_in = (unsigned char*)data;
    do {
      strm.avail_out = output_size;
      strm.next_out = output;
      ret = inflate(&strm, Z_NO_FLUSH);
      if (ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) {
        break;
      }
    } while (strm.avail_out == 0);

    inflateEnd(&strm);
    if (ret != Z_STREAM_END) {
      return NULL;    // error
    }
  }
  return output + row * stride;
}

#if defined(__cplusplus) || defined(c_plusplus)
}    // extern "C"
#endif

#endif    // WEBP_EXPERIMENTAL_FEATURES

Commits for Nextrek/Android/LibrerieNextrek/jni/src/dec/alpha.c

Diff revisions: vs.
Revision Author Commited Message
4 FMMortaroli picture FMMortaroli Fri 19 Apr, 2013 16:54:38 +0000