diff --git a/.gitea/workflows/build-and-test.yml b/.gitea/workflows/build-and-test.yml new file mode 100644 index 0000000..c2d0daa --- /dev/null +++ b/.gitea/workflows/build-and-test.yml @@ -0,0 +1,46 @@ +name: Test openperf + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + checkout_repos: + runs-on: nix + + strategy: + matrix: + arch: ["native"] # Define architectures here + test_name: ["stream"] # Define test names here + + steps: + - name: Checkout Main Repo (openperf) + uses: actions/checkout@v4 + with: + repository: openperf/openperf + path: openperf + + - name: Checkout Abstract Machine Repo + uses: actions/checkout@v4 + with: + repository: openperf/abstract-machine + path: abstract-machine + + - name: Checkout Nemu Repo + uses: actions/checkout@v4 + with: + repository: openperf/nemu + path: nemu + + - name: Build and Run with Matrix + working-directory: openperf + env: + AM_HOME: "${{ github.workspace }}/abstract-machine" + NEMU_HOME: "${{ github.workspace }}/nemu" + run: | + nix develop .#native --impure --command make ARCH=${{ matrix.arch }} ALL=${{ matrix.test_name }} run + diff --git a/.gitignore b/.gitignore index 0cac01f..f70ee43 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ _* build/ !.gitignore .vscode -!mersenne-riscv32e.bin +abstract-machine/ diff --git a/Makefile b/Makefile index 0692992..6649009 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ BENCH_LIBS := bench openlibm soft-fp -$(BENCH_LIBS): %: latest +$(BENCH_LIBS): %: $(MAKE) -s -C ./src/common/$* archive COLOR_RED = \033[1;31m @@ -11,38 +11,78 @@ COLOR_NONE = \033[0m RESULT = .result $(shell > $(RESULT)) -ALL = cpuemu mcf x264 tcc stream linpack gemm whetstone +KEEP_LOG_FAILED ?= true +KEEP_LOG_SUCCEED ?= false +TIME := $(shell date --iso=seconds) + +ALL = mcf x264 tcc stream linpack gemm whetstone all: $(BENCH_LIBS) $(ALL) - @echo "test list [$(words $(ALL)) item(s)]:" $(ALL) + @echo "OpenPerf [$(words $(ALL)) item(s)]:" $(ALL) + @if [ -z "$(mainargs)" ]; then \ + echo "Empty mainargs, use \"ref\" by default"; \ + echo "====== Running OpenPerf [input *ref*] ======"; \ + else \ + echo "====== Running OpenPerf [input *$${mainargs}*] ======"; \ + fi -$(ALL): %: $(BENCH_LIBS) latest +$(ALL): %: $(BENCH_LIBS) @{\ TMP=$*.tmp;\ - make -C ./src/$* ARCH=$(ARCH) run 2>&1 | tee -a $$TMP;\ - if [ $${PIPESTATUS[0]} -eq 0 ]; then \ + $(MAKE) -C ./src/$* ARCH=$(ARCH) run 2>&1 | tee -a $$TMP;\ + if [ $${PIPESTATUS[0]} -eq 0 ]; then \ printf "[%14s] $(COLOR_GREEN)PASS$(COLOR_NONE) " $* >> $(RESULT); \ - cat $$TMP | grep -E -i -e "time: ([0-9]*\.)?[0-9]* ms" >> $(RESULT); \ - rm $$TMP;\ + cat $$TMP | grep -E -i -e "OpenPerf time: ([0-9]*\.)?[0-9]*" >> $(RESULT); \ + if $(KEEP_LOG_SUCCEED); then \ + mkdir -p "logs/$(TIME)/"; \ + mv $$TMP "logs/$(TIME)/"; \ + else \ + rm $$TMP; \ + fi \ else \ printf "[%14s] $(COLOR_RED)***FAIL***$(COLOR_NONE)\n" $* >> $(RESULT); \ - rm $$TMP; \ + if $(KEEP_LOG_FAILED); then \ + mkdir -p "logs/$(TIME)/"; \ + mv $$TMP "logs/$(TIME)/"; \ + else \ + rm $$TMP; \ + fi \ fi \ } run: $(BENCH_LIBS) all @cat $(RESULT) - @cat $(RESULT) | grep -E -o "time: ([0-9]*\.[0-9]*) ms" | awk '{sum += $$2} END {print sum " ms"}' + @echo "=============================================" + @if grep -q -i -e "fail" "$(RESULT)"; then \ + echo "OpenPerf FAIL"; \ + else \ + echo "OpenPerf PASS"; \ + fi + @awk '\ + { \ + h = min = s = ms = us = 0;\ + if (match($$0, /([0-9]+) h/, arr)) h = arr[1]; \ + if (match($$0, /([0-9]+) min/, arr)) min = arr[1]; \ + if (match($$0, /([0-9]+) s/, arr)) s = arr[1]; \ + if (match($$0, /([0-9]+)\.([0-9]*) ms/, arr)) {ms = arr[1]; us = arr[2]} \ + total_ms += h * 3600000 + min * 60000 + s * 1000 + ms; \ + } \ + END { \ + printf "Total time: %d h %d min %d s %d.%d ms\n", \ + int(total_ms / 3600000), \ + int((total_ms % 3600000) / 60000), \ + int((total_ms % 60000) / 1000), \ + total_ms % 1000, \ + us; \ + } \ + ' $(RESULT) @rm $(RESULT) - CLEAN_ALL = $(dir $(shell find . -mindepth 2 -name Makefile)) clean-all: $(CLEAN_ALL) $(CLEAN_ALL): -@$(MAKE) -s -C $@ clean -.PHONY: $(BENCH_LIBS) $(CLEAN_ALL) $(ALL) all run clean-all latest - -latest: +.PHONY: $(BENCH_LIBS) $(CLEAN_ALL) $(ALL) all run clean-all diff --git a/src/common/bench/bench.c b/src/common/bench/bench.c index 09afe2a..75744a0 100644 --- a/src/common/bench/bench.c +++ b/src/common/bench/bench.c @@ -1,13 +1,42 @@ #include -#include +#include #include +#include -uint64_t uptime() -{ - return (io_read(AM_TIMER_UPTIME).us); -} +uint64_t uptime() { return (io_read(AM_TIMER_UPTIME).us); } char *format_time(uint64_t us) { + + static char buf[128]; + uint64_t ms = us / 1000; + uint64_t s = ms / 1000; + uint64_t min = s / 60; + uint64_t h = min / 60; + + us %= 1000; + ms %= 1000; + s %= 60; + min %= 60; + + int len = 0; + if (h > 0) { + len = bench_sprintf(buf, "%ld h %ld min %ld s %ld.000 ms", h, min, s, ms); + } else if (min > 0) { + len = bench_sprintf(buf, "%ld min %ld s, %ld.000 ms", min, s, ms); + } else if (s > 0) { + len = bench_sprintf(buf, "%ld s, %ld.000 ms", s, ms); + } else { + len = bench_sprintf(buf, "%ld.000 ms", ms); + } + char *p = &buf[len - 4]; + while (us > 0) { + *(p--) = '0' + us % 10; + us /= 10; + } + + return buf; +} +/* char *format_time(uint64_t us) { static char buf[32]; uint64_t ms = us / 1000; us -= ms * 1000; @@ -19,14 +48,14 @@ char *format_time(uint64_t us) { us /= 10; } return buf; -} +} */ // FNV hash uint32_t checksum(void *start, void *end) { const uint32_t x = 16777619; uint32_t h1 = 2166136261u; - for (uint8_t *p = (uint8_t*)start; p + 4 < (uint8_t*)end; p += 4) { - for (int i = 0; i < 4; i ++) { + for (uint8_t *p = (uint8_t *)start; p + 4 < (uint8_t *)end; p += 4) { + for (int i = 0; i < 4; i++) { h1 = (h1 ^ p[i]) * x; } } diff --git a/src/common/bench/bench_debug.c b/src/common/bench/bench_debug.c new file mode 100644 index 0000000..cb85ec0 --- /dev/null +++ b/src/common/bench/bench_debug.c @@ -0,0 +1,438 @@ +#include +#include +#include +#include + +#define ZEROPAD 1 +#define SIGN 2 +#define PLUS 4 +#define SPACE 8 +#define LEFT 16 +#define SPECIAL 32 +#define LARGE 64 + +#define is_digit(c) ((c) >= '0' && (c) <= '9') + +#define SZ_NUM_BUF 32 +static char sprint_fe[SZ_NUM_BUF + 1]; +#define PRINT_BUF_SIZE 512 + +static const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz"; +static const char *upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +static size_t strnlen(const char *s, size_t count) { + const char *sc; + for (sc = s; *sc != '\0' && count--; ++sc) + ; + return sc - s; +} + +static int skip_atoi(const char **s) { + int i = 0; + while (is_digit(**s)) + i = i * 10 + *((*s)++) - '0'; + return i; +} + +static char *number(char *str, long num, int base, int size, int precision, + int type) { + char c, sign, tmp[66]; + const char *dig = digits; + int i; + if (type & LARGE) + dig = upper_digits; + if (type & LEFT) + type &= ~ZEROPAD; + if (base < 2 || base > 36) + return 0; + c = (type & ZEROPAD) ? '0' : ' '; + sign = 0; + if (type & SIGN) { + if (num < 0) { + sign = '-'; + num = -num; + size--; + } else if (type & PLUS) { + sign = '+'; + size--; + } else if (type & SPACE) { + sign = ' '; + size--; + } + } + + if (type & SPECIAL) { + if (base == 16) + size -= 2; + else if (base == 8) + size--; + } + i = 0; + if (num == 0) + tmp[i++] = '0'; + else { + while (num != 0) { + tmp[i++] = dig[((unsigned long)num) % (unsigned)base]; + num = ((unsigned long)num) / (unsigned)base; + } + } + + if (i > precision) + precision = i; + size -= precision; + if (!(type & (ZEROPAD | LEFT))) + while (size-- > 0) + *str++ = ' '; + if (sign) + *str++ = sign; + if (type & SPECIAL) { + if (base == 8) + *str++ = '0'; // 0 + else if (base == 16) { + *str++ = '0'; + *str++ = digits[33]; // 0x + } + } + if (!(type & LEFT)) + while (size-- > 0) + *str++ = c; + while (i < precision--) + *str++ = '0'; + while (i-- > 0) + *str++ = tmp[i]; + while (size-- > 0) + *str++ = ' '; + return str; +} +static int ilog10(double n) { + int rv = 0; + + while (n >= 10) { + if (n >= 100000) { + n /= 100000; + rv += 5; + } else { + n /= 10; + rv++; + } + } + while (n < 1) { + if (n < 0.00001) { + n *= 100000; + rv -= 5; + } else { + n *= 10; + rv--; + } + } + return rv; +} + +static double i10x(int n) { + double rv = 1; + + while (n > 0) { + if (n >= 5) { + rv *= 100000; + n -= 5; + } else { + rv *= 10; + n--; + } + } + while (n < 0) { /* Right shift */ + if (n <= -5) { + rv /= 100000; + n += 5; + } else { + rv /= 10; + n++; + } + } + return rv; +} + +static void ftoa(char *buf, double val, int prec, char fmt) { + int d; + int e = 0, m = 0; + char sign = 0; + double w; + const char *er = 0; + const char ds = '.'; + unsigned int *pu = (unsigned int *)&val; + + if (((pu[1] & 0x7ff00000) == 0x7ff00000) && + (((pu[1] & 0xfffff) != 0) || (pu[0] != 0))) { + er = "NaN"; + } else { + if (prec < 0) + prec = 6; + if (val < 0) { + val = 0 - val; + sign = '-'; + } else { + sign = '+'; + } + if (((pu[1] & 0x7fffffff) == 0x7ff00000) && (pu[0] == 0)) { + er = "INF"; + } else { + if (fmt == 'f') { + val += i10x(0 - prec) / 2; + m = ilog10(val); + if (m < 0) + m = 0; + if (m + prec + 3 >= SZ_NUM_BUF) + er = "OV"; + } else { + if (val != 0) { + val += i10x(ilog10(val) - prec) / 2; + e = ilog10(val); + + if (e > 99 || prec + 7 >= SZ_NUM_BUF) { + er = "OV"; + } else { + if (e < -99) + e = -99; + val /= i10x(e); + } + } + } + } + if (!er) { + if (sign == '-') + *buf++ = sign; + + do { + if (m == -1) + *buf++ = ds; + w = i10x(m); + d = (int)(val / w); + val -= d * w; + + *buf++ = (char)('0' + d); + + } while (--m >= -prec); + + if (fmt != 'f') { + *buf++ = (char)fmt; + if (e < 0) { + e = 0 - e; + *buf++ = '-'; + } else { + *buf++ = '+'; + } + *buf++ = (char)('0' + e / 10); + *buf++ = (char)('0' + e % 10); + } + } + } + if (er) { + if (sign) + *buf++ = sign; + do { + *buf++ = *er++; + } while (*er); + } + *buf = 0; +} +int bench_vsprintf(char *buf, const char *fmt, va_list args) { + int len = 0; + unsigned long long num = 0; + int i = 0, j = 0, base = 0; + char *str; + const char *s; + int flags; /* flags to number() */ + int field_width; /* width of output field */ + int precision; /* min. # of digits for integers; max number of chars for from + string */ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + /* 'z' support added 23/7/1999 S.H. */ + /* 'z' changed to 'Z' --davidm 1/25/99 */ + + for (str = buf; *fmt; ++fmt) { + if (*fmt != '%') { + *str++ = *fmt; + continue; + } + /* flags */ + flags = 0; + repeat: + ++fmt; + switch (*fmt) { + case '-': + flags |= LEFT; + goto repeat; + case '+': + flags |= PLUS; + goto repeat; + case ' ': + flags |= SPACE; + goto repeat; + case '#': + flags |= SPECIAL; + goto repeat; + case '0': + flags |= ZEROPAD; + goto repeat; + } + + field_width = -1; + if ('0' <= *fmt && *fmt <= '9') + field_width = skip_atoi(&fmt); + else if (*fmt == '*') { + ++fmt; /*skip '*' */ + /* it's the next argument */ + field_width = va_arg(args, int); + if (field_width < 0) { + field_width = -field_width; + flags |= LEFT; + } + } + precision = -1; + if (*fmt == '.') { + ++fmt; + if ('0' <= *fmt && *fmt <= '9') + precision = skip_atoi(&fmt); + else if (*fmt == '*') { + ++fmt; + /* it's the next argument */ + precision = va_arg(args, int); + } + if (precision < 0) + precision = 0; + } + qualifier = -1; + if (*fmt == 'l' && *(fmt + 1) == 'l') { + qualifier = 'q'; + fmt += 2; + } else if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'Z') { + qualifier = *fmt; + ++fmt; + } + /* default base */ + base = 10; + switch (*fmt) { + case 'c': + if (!(flags & LEFT)) + while (--field_width > 0) + *str++ = ' '; + *str++ = (unsigned char)va_arg(args, int); + while (--field_width > 0) + *str++ = ' '; + continue; + case 's': + s = va_arg(args, char *); + if (!s) + s = ""; + len = strnlen(s, precision); + if (!(flags & LEFT)) + while (len < field_width--) + *str++ = ' '; + for (i = 0; i < len; ++i) + *str++ = *s++; + while (len < field_width--) + *str++ = ' '; + continue; + case 'p': + if (field_width == -1) { + field_width = 2 * sizeof(void *); + flags |= ZEROPAD; + } + str = number(str, (unsigned long)va_arg(args, void *), 16, field_width, + precision, flags); + continue; + case 'n': + if (qualifier == 'l') { + long *ip = va_arg(args, long *); + *ip = (str - buf); + } else if (qualifier == 'Z') { + size_t *ip = va_arg(args, size_t *); + *ip = (str - buf); + } else { + int *ip = va_arg(args, int *); + *ip = (str - buf); + } + continue; + case 'f': /* Floating point (decimal) */ + case 'e': /* Floating point (e) */ + case 'E': /* Floating point (E) */ + ftoa(sprint_fe, va_arg(args, double), precision, *fmt); /* 浮点转字符串*/ + if (!(flags & LEFT)) { + for (j = strnlen(sprint_fe, SZ_NUM_BUF); j < field_width; j++) + *str++ = ' '; + } + i = 0; + while (sprint_fe[i]) + *str++ = sprint_fe[i++]; /* 主体 */ + while (j++ < field_width) + *str++ = ' '; + + continue; + case '%': + *str++ = '%'; + continue; + case 'o': + base = 8; + break; + case 'X': + flags |= LARGE; + case 'x': + base = 16; + break; + case 'd': + case 'i': + flags |= SIGN; + case 'u': + break; + default: + *str++ = '%'; + if (*fmt) + *str++ = *fmt; + else + --fmt; + continue; + } + if (qualifier == 'l') { + num = va_arg(args, unsigned long); + if (flags & SIGN) + num = (signed long)num; + } else if (qualifier == 'q') { + num = va_arg(args, unsigned long long); + if (flags & SIGN) + num = (signed long long)num; + } else if (qualifier == 'Z') { + num = va_arg(args, size_t); + } else if (qualifier == 'h') { + num = (unsigned short)va_arg(args, int); + if (flags & SIGN) + num = (signed short)num; + } else { + num = va_arg(args, unsigned int); + if (flags & SIGN) + num = (signed int)num; + } + str = number(str, num, base, field_width, precision, flags); + } + *str = '\0'; + return str - buf; +} + +int bench_sprintf(char *s, const char *fmt, ...) { + va_list arg; + va_start(arg, fmt); + int length = bench_vsprintf(s, fmt, arg); + va_end(arg); + return length; +} + +int bench_printf(const char *fmt, ...) { + char s[PRINT_BUF_SIZE]; + va_list arg; + va_start(arg, fmt); + int length = bench_vsprintf(s, fmt, arg); + va_end(arg); + for (int i = 0; s[i] != '\0'; i++) { + putch(s[i]); + } + return length; +} diff --git a/src/common/bench/bench_malloc.c b/src/common/bench/bench_malloc.c index f0c9fb3..4f63db7 100644 --- a/src/common/bench/bench_malloc.c +++ b/src/common/bench/bench_malloc.c @@ -1,6 +1,6 @@ +#include #include #include -#include #include static intptr_t program_break = 0; @@ -21,139 +21,136 @@ static void *sbrk(intptr_t increment) { // } static inline size_t word_align(size_t size) { - return ( size + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1); + return (size + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1); } struct chunk { - struct chunk *next, *prev; - size_t size; - size_t free; - void *data; + struct chunk *next, *prev; + size_t size; + size_t free; + void *data; }; typedef struct chunk *Chunk; static void *malloc_base() { - static Chunk b = NULL; - if (!b) { - b = sbrk(word_align(sizeof(struct chunk))); - if (b == (void*) -1) { - // _exit(127); - assert(0); - } - b->next = NULL; - b->prev = NULL; - b->size = 0; - b->free = 0; - b->data = NULL; + static Chunk b = NULL; + if (!b) { + b = sbrk(word_align(sizeof(struct chunk))); + if (b == (void *)-1) { + // _exit(127); + assert(0); } - return b; + b->next = NULL; + b->prev = NULL; + b->size = 0; + b->free = 0; + b->data = NULL; + } + return b; } -//We need this function because we use variable `heap` -//and it is initialized in run time. -void bench_malloc_init() { - program_break = (intptr_t)heap.start; -} +// We need this function because the variable `heap` is used +// and initialized at runtime. +void bench_malloc_init() { program_break = (intptr_t)heap.start; } static Chunk malloc_chunk_find(size_t s, Chunk *heap) { - Chunk c = malloc_base(); - for (; c && (!c->free || c->size < s); *heap = c, c = c->next); - return c; + Chunk c = malloc_base(); + for (; c && (!c->free || c->size < s); *heap = c, c = c->next) + ; + return c; } static void malloc_merge_next(Chunk c) { - c->size = c->size + c->next->size + sizeof(struct chunk); - c->next = c->next->next; - if (c->next) { - c->next->prev = c; - } + c->size = c->size + c->next->size + sizeof(struct chunk); + c->next = c->next->next; + if (c->next) { + c->next->prev = c; + } } static void malloc_split_next(Chunk c, size_t size) { - Chunk newc = (Chunk)((char*) c + size); - newc->prev = c; - newc->next = c->next; - newc->size = c->size - size; - newc->free = 1; - newc->data = newc + 1; - if (c->next) { - c->next->prev = newc; - } - c->next = newc; - c->size = size - sizeof(struct chunk); + Chunk newc = (Chunk)((char *)c + size); + newc->prev = c; + newc->next = c->next; + newc->size = c->size - size; + newc->free = 1; + newc->data = newc + 1; + if (c->next) { + c->next->prev = newc; + } + c->next = newc; + c->size = size - sizeof(struct chunk); } void *bench_malloc(size_t size) { - if (!size) return NULL; - size_t length = word_align(size + sizeof(struct chunk)); - Chunk prev = NULL; - Chunk c = malloc_chunk_find(size, &prev); - if (!c) { - Chunk newc = sbrk(length); - if (newc == (void*) -1) { - return NULL; - } - newc->next = NULL; - newc->prev = prev; - newc->size = length - sizeof(struct chunk); - newc->data = newc + 1; - prev->next = newc; - c = newc; - } else if (length + sizeof(size_t) < c->size) { - malloc_split_next(c, length); + if (!size) + return NULL; + size_t length = word_align(size + sizeof(struct chunk)); + Chunk prev = NULL; + Chunk c = malloc_chunk_find(size, &prev); + if (!c) { + Chunk newc = sbrk(length); + if (newc == (void *)-1) { + return NULL; } - c->free = 0; - return c->data; + newc->next = NULL; + newc->prev = prev; + newc->size = length - sizeof(struct chunk); + newc->data = newc + 1; + prev->next = newc; + c = newc; + } else if (length + sizeof(size_t) < c->size) { + malloc_split_next(c, length); + } + c->free = 0; + return c->data; } void bench_free(void *ptr) { - if (!ptr || ptr < malloc_base() || ptr > sbrk(0)) return; - Chunk c = (Chunk) ptr - 1; - if (c->data != ptr) return; - c->free = 1; + if (!ptr || ptr < malloc_base() || ptr > sbrk(0)) + return; + Chunk c = (Chunk)ptr - 1; + if (c->data != ptr) + return; + c->free = 1; - if (c->next && c->next->free) { - malloc_merge_next(c); - } - if (c->prev->free) { - malloc_merge_next(c = c->prev); - } - if (!c->next) { - c->prev->next = NULL; - sbrk(- c->size - sizeof(struct chunk)); - } + if (c->next && c->next->free) { + malloc_merge_next(c); + } + if (c->prev->free) { + malloc_merge_next(c = c->prev); + } + if (!c->next) { + c->prev->next = NULL; + sbrk(-c->size - sizeof(struct chunk)); + } } void *bench_calloc(size_t nmemb, size_t size) { - size_t length = nmemb * size; - void *ptr = bench_malloc(length); - if (ptr) { - char *dst = ptr; - for (size_t i = 0; i < length; *dst = 0, ++dst, ++i); - } - return ptr; + size_t length = nmemb * size; + void *ptr = bench_malloc(length); + if (ptr) { + char *dst = ptr; + for (size_t i = 0; i < length; *dst = 0, ++dst, ++i) + ; + } + return ptr; } void *bench_realloc(void *ptr, size_t size) { - void *newptr = bench_malloc(size); - if (newptr && ptr && ptr >= malloc_base() && ptr <= sbrk(0)) { - Chunk c = (Chunk) ptr - 1; - if (c->data == ptr) { - size_t length = c->size > size ? size : c->size; - char *dst = newptr, *src = ptr; - for (size_t i = 0; i < length; *dst = *src, ++src, ++dst, ++i); - bench_free(ptr); - } + void *newptr = bench_malloc(size); + if (newptr && ptr && ptr >= malloc_base() && ptr <= sbrk(0)) { + Chunk c = (Chunk)ptr - 1; + if (c->data == ptr) { + size_t length = c->size > size ? size : c->size; + char *dst = newptr, *src = ptr; + for (size_t i = 0; i < length; *dst = *src, ++src, ++dst, ++i) + ; + bench_free(ptr); } - return newptr; + } + return newptr; } -void bench_all_free() { - program_break = (intptr_t)heap.start; -} - - - - - +void bench_all_free() { program_break = (intptr_t)heap.start; } diff --git a/src/common/bench/bench_strings.c b/src/common/bench/bench_strings.c index 6f3e2ac..9613b0e 100644 --- a/src/common/bench/bench_strings.c +++ b/src/common/bench/bench_strings.c @@ -1,456 +1,418 @@ -#include #include +#include - -#define __tolower(c) ((('A' <= (c))&&((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c)) -int strcasecmp(const char *s1, const char *s2) -{ - if(s1 == NULL || s2 == NULL) +#define __tolower(c) ((('A' <= (c)) && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c)) +int strcasecmp(const char *s1, const char *s2) { + if (s1 == NULL || s2 == NULL) return 0; - while((*s1 != '\0') && (__tolower(*s1) == __tolower(*s2))) - { - s1++; s2++; + while ((*s1 != '\0') && (__tolower(*s1) == __tolower(*s2))) { + s1++; + s2++; } return (*s1 - *s2); } -int strncasecmp(const char *s1, const char *s2, size_t n) -{ - if(s1 == NULL || s2 == NULL) +int strncasecmp(const char *s1, const char *s2, size_t n) { + if (s1 == NULL || s2 == NULL) return 0; - while((*s1 != '\0') && (__tolower(*s1) == __tolower(*s2)) && (n > 1)) - { - s1++; s2++; + while ((*s1 != '\0') && (__tolower(*s1) == __tolower(*s2)) && (n > 1)) { + s1++; + s2++; n--; } return (*s1 - *s2); } -char* strdup(const char* str) -{ - if(str == NULL) +char *strdup(const char *str) { + if (str == NULL) return NULL; - char* strat = (char*)str; + char *strat = (char *)str; int len = 0; while (*str++ != '\0') len++; - char* ret = (char*)bench_malloc(len + 1); + char *ret = (char *)bench_malloc(len + 1); - while ((*ret++ = *strat++) != '\0') - {} + while ((*ret++ = *strat++) != '\0') { + } return ret - (len + 1); } -size_t strspn(const char *str, const char *group) -{ - const char *p = NULL; - const char *a = NULL; - size_t count = 0; +size_t strspn(const char *str, const char *group) { + const char *p = NULL; + const char *a = NULL; + size_t count = 0; - for (p = str; *p != '\0'; ++p) - { - for (a = group; *a != '\0'; ++a) - { - if (*p == *a) - { - ++count; - break; - } - } + for (p = str; *p != '\0'; ++p) { + for (a = group; *a != '\0'; ++a) { + if (*p == *a) { + ++count; + break; + } + } - if (*a == '\0') - { - return count; - } - } + if (*a == '\0') { + return count; + } + } - return count; + return count; } -size_t strcspn ( const char * str1, const char * str2 ) { +size_t strcspn(const char *str1, const char *str2) { char *p1 = (char *)str1; char *p2; while (*p1 != '\0') { p2 = (char *)str2; while (*p2 != '\0') { - if (*p2 == *p1) return p1-str1; - ++p2; + if (*p2 == *p1) + return p1 - str1; + ++p2; } ++p1; } - return p1 - str1; + return p1 - str1; } -unsigned long strtoul(const char *pstart, char **pend, int base) -{ - const char *s = pstart; - unsigned long result = 0; - char c; +unsigned long strtoul(const char *pstart, char **pend, int base) { + const char *s = pstart; + unsigned long result = 0; + char c; - assert (base > 2 && base < 36); + assert(base > 2 && base < 36); - do { - c = *s++; - } while (c == ' '); - if (c == '-' || c == '+'){ - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X') && - ((s[1] >= '0' && s[1] <= '9') || - (s[1] >= 'A' && s[1] <= 'F') || - (s[1] >= 'a' && s[1] <= 'f'))) { - c = s[1]; - s += 2; - base = 16; - } + do { + c = *s++; + } while (c == ' '); + if (c == '-' || c == '+') { + c = *s++; + } + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X') && + ((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'A' && s[1] <= 'F') || + (s[1] >= 'a' && s[1] <= 'f'))) { + c = s[1]; + s += 2; + base = 16; + } if (base == 0) { - base = c == '0' ? 8 : 10; + base = c == '0' ? 8 : 10; } - for ( ; *s; c = *s++) { + for (; *s; c = *s++) { if (c >= '0' && c <= '9') { - c -= '0'; + c -= '0'; } else if (c >= 'A' && c <= 'Z') { - c -= 'A' - 10; + c -= 'A' - 10; } else if (c >= 'a' && c <= 'z') { - c -= 'a' - 10; + c -= 'a' - 10; } else { - break; + break; } - result *= base; - result += c; - } - if (pend != NULL) { - *pend = (char *)(s - 1); + result *= base; + result += c; } - return result; + if (pend != NULL) { + *pend = (char *)(s - 1); + } + return result; } -unsigned long long strtoull(const char *pstart, char **pend, int base) -{ - const char *s = pstart; - unsigned long long result = 0; - char c; +unsigned long long strtoull(const char *pstart, char **pend, int base) { + const char *s = pstart; + unsigned long long result = 0; + char c; - assert (base > 2 && base < 36); + assert(base > 2 && base < 36); - do { - c = *s++; - } while ((c == ' ')); - if (c == '-' || c == '+'){ - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X') && - ((s[1] >= '0' && s[1] <= '9') || - (s[1] >= 'A' && s[1] <= 'F') || - (s[1] >= 'a' && s[1] <= 'f'))) { - c = s[1]; - s += 2; - base = 16; - } + do { + c = *s++; + } while ((c == ' ')); + if (c == '-' || c == '+') { + c = *s++; + } + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X') && + ((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'A' && s[1] <= 'F') || + (s[1] >= 'a' && s[1] <= 'f'))) { + c = s[1]; + s += 2; + base = 16; + } if (base == 0) { - base = c == '0' ? 8 : 10; + base = c == '0' ? 8 : 10; } - for ( ; *s; c = *s++) { + for (; *s; c = *s++) { if (c >= '0' && c <= '9') { - c -= '0'; + c -= '0'; } else if (c >= 'A' && c <= 'Z') { - c -= 'A' - 10; + c -= 'A' - 10; } else if (c >= 'a' && c <= 'z') { - c -= 'a' - 10; + c -= 'a' - 10; } else { - break; + break; } - result *= base; - result += c; - } - if (pend != NULL) { - *pend = (char *)(s - 1); + result *= base; + result += c; } - return result; + if (pend != NULL) { + *pend = (char *)(s - 1); + } + return result; } -long strtol(const char *pstart, char **pend, int base) -{ - const char *s = pstart; - long result = 0; - char c; +long strtol(const char *pstart, char **pend, int base) { + const char *s = pstart; + long result = 0; + char c; long sign = 1; - assert (base > 2 && base < 36); + assert(base > 2 && base < 36); - do { - c = *s++; - } while ((c == ' ')); - if (c == '-' || c == '+'){ - sign = (c == '-') ? -1: 1; - c = *s++; - } + do { + c = *s++; + } while ((c == ' ')); + if (c == '-' || c == '+') { + sign = (c == '-') ? -1 : 1; + c = *s++; + } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X') && - ((s[1] >= '0' && s[1] <= '9') || - (s[1] >= 'A' && s[1] <= 'F') || - (s[1] >= 'a' && s[1] <= 'f'))) { - c = s[1]; - s += 2; - base = 16; - } + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X') && + ((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'A' && s[1] <= 'F') || + (s[1] >= 'a' && s[1] <= 'f'))) { + c = s[1]; + s += 2; + base = 16; + } if (base == 0) { - base = c == '0' ? 8 : 10; + base = c == '0' ? 8 : 10; } - for ( ; *s; c = *s++) { + for (; *s; c = *s++) { if (c >= '0' && c <= '9') { - c -= '0'; + c -= '0'; } else if (c >= 'A' && c <= 'Z') { - c -= 'A' - 10; + c -= 'A' - 10; } else if (c >= 'a' && c <= 'z') { - c -= 'a' - 10; + c -= 'a' - 10; } else { - break; + break; } - result *= base; - result += c; - } - if (pend != NULL) { - *pend = (char *)(s - 1); + result *= base; + result += c; } - return sign * result; + if (pend != NULL) { + *pend = (char *)(s - 1); + } + return sign * result; } -long long strtoll(const char *pstart, char **pend, int base) -{ - const char *s = pstart; - long long result = 0; - char c; +long long strtoll(const char *pstart, char **pend, int base) { + const char *s = pstart; + long long result = 0; + char c; long long sign = 1; - assert (base > 2 && base < 36); + assert(base > 2 && base < 36); - do { - c = *s++; - } while ((c == ' ')); - if (c == '-' || c == '+'){ - sign = (c == '-') ? -1: 1; - c = *s++; - } + do { + c = *s++; + } while ((c == ' ')); + if (c == '-' || c == '+') { + sign = (c == '-') ? -1 : 1; + c = *s++; + } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X') && - ((s[1] >= '0' && s[1] <= '9') || - (s[1] >= 'A' && s[1] <= 'F') || - (s[1] >= 'a' && s[1] <= 'f'))) { - c = s[1]; - s += 2; - base = 16; - } + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X') && + ((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'A' && s[1] <= 'F') || + (s[1] >= 'a' && s[1] <= 'f'))) { + c = s[1]; + s += 2; + base = 16; + } if (base == 0) { - base = c == '0' ? 8 : 10; + base = c == '0' ? 8 : 10; } - for ( ; *s; c = *s++) { + for (; *s; c = *s++) { if (c >= '0' && c <= '9') { - c -= '0'; + c -= '0'; } else if (c >= 'A' && c <= 'Z') { - c -= 'A' - 10; + c -= 'A' - 10; } else if (c >= 'a' && c <= 'z') { - c -= 'a' - 10; + c -= 'a' - 10; } else { - break; + break; } - result *= base; - result += c; - } - if (pend != NULL) { - *pend = (char *)(s - 1); + result *= base; + result += c; } - return sign * result; + if (pend != NULL) { + *pend = (char *)(s - 1); + } + return sign * result; } -double strtod(const char *pstart, char **pend) -{ - const char *s = pstart; - double result = 0; - char c; +double strtod(const char *pstart, char **pend) { + const char *s = pstart; + double result = 0; + char c; double sign = 1.0; double frac = 0.1; - do { - c = *s++; - } while ((c == ' ')); - if (c == '-' || c == '+'){ - sign = (c == '-') ? -1.0 : 1.0; - c = *s++; - } - - for ( ; ; c = *s++) { - if (c >= '0' && c <= '9') { - c -= '0'; - } else { - break; - } - result *= 10; - result += c; - } - if(c == '.') { + do { + c = *s++; + } while ((c == ' ')); + if (c == '-' || c == '+') { + sign = (c == '-') ? -1.0 : 1.0; c = *s++; - for ( ; ; c = *s++) { - if (c >= '0' && c <= '9') { - c -= '0'; - } else { - break; - } - result += c * frac; - frac *= 0.1; - } } - if (pend != NULL) { - *pend = (char *)(s - 1); + for (;; c = *s++) { + if (c >= '0' && c <= '9') { + c -= '0'; + } else { + break; + } + result *= 10; + result += c; } - return (sign * result); + if (c == '.') { + c = *s++; + for (;; c = *s++) { + if (c >= '0' && c <= '9') { + c -= '0'; + } else { + break; + } + result += c * frac; + frac *= 0.1; + } + } + + if (pend != NULL) { + *pend = (char *)(s - 1); + } + return (sign * result); } -long double strtold(const char *pstart, char **pend) -{ - const char *s = pstart; - long double result = 0; - char c; +long double strtold(const char *pstart, char **pend) { + const char *s = pstart; + long double result = 0; + char c; long double sign = 1.0; long double frac = 0.1; - do { - c = *s++; - } while ((c == ' ')); - if (c == '-' || c == '+'){ - sign = (c == '-') ? -1.0 : 1.0; - c = *s++; - } - - for ( ; ; c = *s++) { - if (c >= '0' && c <= '9') { - c -= '0'; - } else { - break; - } - result *= 10; - result += c; - } - if(c == '.') { + do { + c = *s++; + } while ((c == ' ')); + if (c == '-' || c == '+') { + sign = (c == '-') ? -1.0 : 1.0; c = *s++; - for ( ; ; c = *s++) { - if (c >= '0' && c <= '9') { - c -= '0'; - } else { - break; - } - result += c * frac; - frac *= 0.1; - } } - if (pend != NULL) { - *pend = (char *)(s - 1); + for (;; c = *s++) { + if (c >= '0' && c <= '9') { + c -= '0'; + } else { + break; + } + result *= 10; + result += c; } - return (sign * result); + if (c == '.') { + c = *s++; + for (;; c = *s++) { + if (c >= '0' && c <= '9') { + c -= '0'; + } else { + break; + } + result += c * frac; + frac *= 0.1; + } + } + + if (pend != NULL) { + *pend = (char *)(s - 1); + } + return (sign * result); } -float strtof(const char *pstart, char **pend) -{ - const char *s = pstart; - float result = 0; - char c; +float strtof(const char *pstart, char **pend) { + const char *s = pstart; + float result = 0; + char c; float sign = 1.0; float frac = 0.1; - do { - c = *s++; - } while ((c == ' ')); - if (c == '-' || c == '+'){ - sign = (c == '-') ? -1.0 : 1.0; - c = *s++; - } - - for ( ; ; c = *s++) { - if (c >= '0' && c <= '9') { - c -= '0'; - } else { - break; - } - result *= 10; - result += c; - } - if(c == '.') { + do { + c = *s++; + } while ((c == ' ')); + if (c == '-' || c == '+') { + sign = (c == '-') ? -1.0 : 1.0; c = *s++; - for ( ; ; c = *s++) { - if (c >= '0' && c <= '9') { - c -= '0'; - } else { - break; - } - result += c * frac; - frac *= 0.1; - } } - if (pend != NULL) { - *pend = (char *)(s - 1); + for (;; c = *s++) { + if (c >= '0' && c <= '9') { + c -= '0'; + } else { + break; + } + result *= 10; + result += c; } - return (sign * result); + if (c == '.') { + c = *s++; + for (;; c = *s++) { + if (c >= '0' && c <= '9') { + c -= '0'; + } else { + break; + } + result += c * frac; + frac *= 0.1; + } + } + + if (pend != NULL) { + *pend = (char *)(s - 1); + } + return (sign * result); } -char *strchr(const char *s, const char ch) -{ +char *strchr(const char *s, const char ch) { if (NULL == s) - return NULL; - + return NULL; + const char *pSrc = s; - while ('\0' != *pSrc) - { - if (*pSrc == ch) - { + while ('\0' != *pSrc) { + if (*pSrc == ch) { return (char *)pSrc; - } + } pSrc++; - } - if(ch == 0) - { + } + if (ch == 0) { return (char *)pSrc; } return NULL; } -char *strrchr(const char *s, const char ch) -{ - if(s == NULL) - { - return NULL; +char *strrchr(const char *s, const char ch) { + if (s == NULL) { + return NULL; } char *p_char = NULL; - while(*s != '\0') - { - if(*s == ch) - { - p_char = (char *)s; + while (*s != '\0') { + if (*s == ch) { + p_char = (char *)s; } s++; } - if(ch == 0) - { + if (ch == 0) { p_char = (char *)s; } return p_char; } -char* strstr(const char* dest, const char* src) -{ - assert(0); -} - - - +char *strstr(const char *dest, const char *src) { assert(0); } diff --git a/src/common/bench/include/bench.h b/src/common/bench/include/bench.h index 8207441..66ba809 100644 --- a/src/common/bench/include/bench.h +++ b/src/common/bench/include/bench.h @@ -1,8 +1,8 @@ #ifndef __BENCH_COMMON #define __BENCH_COMMON -#include #include +#include uint64_t uptime(); char *format_time(uint64_t us); @@ -14,6 +14,6 @@ typedef struct { uint64_t ref_time; uint32_t checksum; size_t repeat_time; -} Setting; +} Setting; #endif diff --git a/src/common/bench/include/bench_debug.h b/src/common/bench/include/bench_debug.h new file mode 100644 index 0000000..7abb209 --- /dev/null +++ b/src/common/bench/include/bench_debug.h @@ -0,0 +1,35 @@ +#ifndef __BENCH_DEBUG_H +#define __BENCH_DEBUG_H +#include + +#define ANSI_ERROR "\33[1;31m" +#define ANSI_WARN "\33[1;93m" +#define ANSI_INFO "\33[1;34m" +#define ANSI_DEBUG "\33[1;32m" +#define ANSI_TRACE "\33[1;90m" +#define ANSI_NONE "\33[0m" + +#ifndef LOG_LEVEL +#define LOG_LEVEL 2 +#endif + +#define LOG_LEVEL_ERROR 0 +#define LOG_LEVEL_WARN 1 +#define LOG_LEVEL_INFO 2 +#define LOG_LEVEL_DEBUG 3 +#define LOG_LEVEL_TRACE 4 + +#define ANSI_FMT(str, fmt) fmt str ANSI_NONE "\n" + +#define BENCH_LOG(level, str, ...) \ + do { \ + if (LOG_LEVEL >= LOG_LEVEL_##level) { \ + bench_printf(ANSI_FMT(str, ANSI_##level), ##__VA_ARGS__); \ + } \ + } while (0) + +int bench_vsprintf(char *buf, const char *fmt, va_list args); +int bench_sprintf(char *s, const char *fmt, ...); +int bench_printf(const char *fmt, ...); + +#endif diff --git a/src/common/bench/include/bench_malloc.h b/src/common/bench/include/bench_malloc.h index 4daabb8..8094a8b 100644 --- a/src/common/bench/include/bench_malloc.h +++ b/src/common/bench/include/bench_malloc.h @@ -5,11 +5,10 @@ #include void bench_malloc_init(); -void *bench_malloc (size_t size); -void *bench_calloc (size_t number, size_t size); -void *bench_realloc (void *p, size_t size); -void bench_free (void *ptr); -void bench_all_free (void); +void *bench_malloc(size_t size); +void *bench_calloc(size_t number, size_t size); +void *bench_realloc(void *p, size_t size); +void bench_free(void *ptr); +void bench_all_free(void); #endif - diff --git a/src/common/bench/include/bench_strings.h b/src/common/bench/include/bench_strings.h index 638df03..fe2b7cd 100644 --- a/src/common/bench/include/bench_strings.h +++ b/src/common/bench/include/bench_strings.h @@ -3,12 +3,11 @@ #include -int strcasecmp (const char *s1, const char *s2); -int strncasecmp (const char *s1, const char *s2, size_t n); -char* strdup (const char* str); -size_t strspn (const char *str, const char *group); -size_t strcspn ( const char * str1, const char * str2 ); - +int strcasecmp(const char *s1, const char *s2); +int strncasecmp(const char *s1, const char *s2, size_t n); +char *strdup(const char *str); +size_t strspn(const char *str, const char *group); +size_t strcspn(const char *str1, const char *str2); unsigned long strtoul(const char *pstart, char **pend, int base); unsigned long long strtoull(const char *pstart, char **pend, int base); @@ -18,9 +17,7 @@ double strtod(const char *pstart, char **pend); long double strtold(const char *pstart, char **pend); float strtof(const char *pstart, char **pend); char *strchr(const char *s, const char ch); -char* strstr(const char* dest, const char* src); +char *strstr(const char *dest, const char *src); char *strrchr(const char *s, const char ch); - #endif - diff --git a/src/common/ldecod_src/annexb.c b/src/common/ldecod_src/annexb.c index ef79493..646332a 100644 --- a/src/common/ldecod_src/annexb.c +++ b/src/common/ldecod_src/annexb.c @@ -7,34 +7,30 @@ * Annex B Byte Stream format * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger ************************************************************************************* */ -#include "global.h" #include "annexb.h" -#include "memalloc.h" #include "fast_memory.h" +#include "global.h" +#include "memalloc.h" -static const int IOBUFFERSIZE = 512*1024; //65536; +static const int IOBUFFERSIZE = 512 * 1024; // 65536; -void malloc_annex_b(VideoParameters *p_Vid) -{ - if ( (p_Vid->annex_b = (ANNEXB_t *) calloc(1, sizeof(ANNEXB_t))) == NULL) - { +void malloc_annex_b(VideoParameters *p_Vid) { + if ((p_Vid->annex_b = (ANNEXB_t *)calloc(1, sizeof(ANNEXB_t))) == NULL) { snprintf(errortext, ET_SIZE, "Memory allocation for Annex_B file failed"); - error(errortext,100); + error(errortext, 100); } - if ((p_Vid->annex_b->Buf = (byte*) malloc(p_Vid->nalu->max_size)) == NULL) - { + if ((p_Vid->annex_b->Buf = (byte *)malloc(p_Vid->nalu->max_size)) == NULL) { error("GetAnnexbNALU: Buf", 101); } } - -void init_annex_b(ANNEXB_t *annex_b) -{ +void init_annex_b(ANNEXB_t *annex_b) { annex_b->BitStreamFile = -1; annex_b->iobuffer = NULL; annex_b->iobufferread = NULL; @@ -44,12 +40,11 @@ void init_annex_b(ANNEXB_t *annex_b) annex_b->nextstartcodebytes = 0; } -void free_annex_b(VideoParameters *p_Vid) -{ +void free_annex_b(VideoParameters *p_Vid) { free(p_Vid->annex_b->Buf); p_Vid->annex_b->Buf = NULL; free(p_Vid->annex_b); - p_Vid->annex_b = NULL; + p_Vid->annex_b = NULL; } /*! @@ -58,11 +53,10 @@ void free_annex_b(VideoParameters *p_Vid) * fill IO buffer ************************************************************************ */ -static inline int getChunk(ANNEXB_t *annex_b) -{ - unsigned int readbytes = read (annex_b->BitStreamFile, annex_b->iobuffer, annex_b->iIOBufferSize); - if (0==readbytes) - { +static inline int getChunk(ANNEXB_t *annex_b) { + unsigned int readbytes = + read(annex_b->BitStreamFile, annex_b->iobuffer, annex_b->iIOBufferSize); + if (0 == readbytes) { annex_b->is_eof = TRUE; return 0; } @@ -78,10 +72,8 @@ static inline int getChunk(ANNEXB_t *annex_b) * returns a byte from IO buffer ************************************************************************ */ -static inline byte getfbyte(ANNEXB_t *annex_b) -{ - if (0 == annex_b->bytesinbuffer) - { +static inline byte getfbyte(ANNEXB_t *annex_b) { + if (0 == annex_b->bytesinbuffer) { if (0 == getChunk(annex_b)) return 0; } @@ -105,25 +97,21 @@ static inline byte getfbyte(ANNEXB_t *annex_b) * indicates number of 0x00 bytes in start-code. ************************************************************************ */ -static inline int FindStartCode (unsigned char *Buf, int zeros_in_startcode) -{ +static inline int FindStartCode(unsigned char *Buf, int zeros_in_startcode) { int i; - for (i = 0; i < zeros_in_startcode; i++) - { - if(*(Buf++) != 0) - { + for (i = 0; i < zeros_in_startcode; i++) { + if (*(Buf++) != 0) { return 0; } } - if(*Buf != 1) + if (*Buf != 1) return 0; return 1; } - /*! ************************************************************************ * \brief @@ -143,8 +131,7 @@ static inline int FindStartCode (unsigned char *Buf, int zeros_in_startcode) ************************************************************************ */ -int GetAnnexbNALU (VideoParameters *p_Vid, NALU_t *nalu) -{ +int GetAnnexbNALU(VideoParameters *p_Vid, NALU_t *nalu) { ANNEXB_t *annex_b = p_Vid->annex_b; int i; int info2 = 0, info3 = 0, pos = 0; @@ -152,150 +139,139 @@ int GetAnnexbNALU (VideoParameters *p_Vid, NALU_t *nalu) int LeadingZero8BitsCount = 0; byte *pBuf = annex_b->Buf; - if (annex_b->nextstartcodebytes != 0) - { - for (i=0; inextstartcodebytes-1; i++) - { + if (annex_b->nextstartcodebytes != 0) { + for (i = 0; i < annex_b->nextstartcodebytes - 1; i++) { (*pBuf++) = 0; pos++; } (*pBuf++) = 1; pos++; - } - else - { - while(!annex_b->is_eof) - { + } else { + while (!annex_b->is_eof) { pos++; - if ((*(pBuf++)= getfbyte(annex_b))!= 0) + if ((*(pBuf++) = getfbyte(annex_b)) != 0) break; } } - if(annex_b->is_eof == TRUE) - { - if(pos==0) - { + if (annex_b->is_eof == TRUE) { + if (pos == 0) { return 0; - } - else - { - printf( "GetAnnexbNALU can't read start code\n"); + } else { + printf("GetAnnexbNALU can't read start code\n"); return -1; } - } + } - if(*(pBuf - 1) != 1 || pos < 3) - { - printf ("GetAnnexbNALU: no Start Code at the beginning of the NALU, return -1\n"); + if (*(pBuf - 1) != 1 || pos < 3) { + printf("GetAnnexbNALU: no Start Code at the beginning of the NALU, return " + "-1\n"); return -1; } - if (pos == 3) - { + if (pos == 3) { nalu->startcodeprefix_len = 3; - } - else - { + } else { LeadingZero8BitsCount = pos - 4; nalu->startcodeprefix_len = 4; } - //the 1st byte stream NAL unit can has leading_zero_8bits, but subsequent ones are not - //allowed to contain it since these zeros(if any) are considered trailing_zero_8bits - //of the previous byte stream NAL unit. - if(!annex_b->IsFirstByteStreamNALU && LeadingZero8BitsCount > 0) - { - printf ("GetAnnexbNALU: The leading_zero_8bits syntax can only be present in the first byte stream NAL unit, return -1\n"); + // the 1st byte stream NAL unit can has leading_zero_8bits, but subsequent + // ones are not allowed to contain it since these zeros(if any) are considered + // trailing_zero_8bits of the previous byte stream NAL unit. + if (!annex_b->IsFirstByteStreamNALU && LeadingZero8BitsCount > 0) { + printf("GetAnnexbNALU: The leading_zero_8bits syntax can only be present " + "in the first byte stream NAL unit, return -1\n"); return -1; } LeadingZero8BitsCount = pos; annex_b->IsFirstByteStreamNALU = 0; - while (!StartCodeFound) - { - if (annex_b->is_eof == TRUE) - { + while (!StartCodeFound) { + if (annex_b->is_eof == TRUE) { pBuf -= 2; - while(*(pBuf--)==0) + while (*(pBuf--) == 0) pos--; nalu->len = (pos - 1) - LeadingZero8BitsCount; - memcpy (nalu->buf, annex_b->Buf + LeadingZero8BitsCount, nalu->len); - nalu->forbidden_bit = (*(nalu->buf) >> 7) & 1; - nalu->nal_reference_idc = (NalRefIdc) ((*(nalu->buf) >> 5) & 3); - nalu->nal_unit_type = (NaluType) ((*(nalu->buf)) & 0x1f); + memcpy(nalu->buf, annex_b->Buf + LeadingZero8BitsCount, nalu->len); + nalu->forbidden_bit = (*(nalu->buf) >> 7) & 1; + nalu->nal_reference_idc = (NalRefIdc)((*(nalu->buf) >> 5) & 3); + nalu->nal_unit_type = (NaluType)((*(nalu->buf)) & 0x1f); annex_b->nextstartcodebytes = 0; - // printf ("GetAnnexbNALU, eof case: pos %d nalu->len %d, nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len, nalu->nal_reference_idc, nalu->nal_unit_type); + // printf ("GetAnnexbNALU, eof case: pos %d nalu->len %d, + // nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len, + // nalu->nal_reference_idc, nalu->nal_unit_type); #if TRACE - fprintf (p_Dec->p_trace, "\n\nLast NALU in File\n\n"); - fprintf (p_Dec->p_trace, "Annex B NALU w/ %s startcode, len %d, forbidden_bit %d, nal_reference_idc %d, nal_unit_type %d\n\n", - nalu->startcodeprefix_len == 4?"long":"short", nalu->len, nalu->forbidden_bit, nalu->nal_reference_idc, nalu->nal_unit_type); - fflush (p_Dec->p_trace); + fprintf(p_Dec->p_trace, "\n\nLast NALU in File\n\n"); + fprintf(p_Dec->p_trace, + "Annex B NALU w/ %s startcode, len %d, forbidden_bit %d, " + "nal_reference_idc %d, nal_unit_type %d\n\n", + nalu->startcodeprefix_len == 4 ? "long" : "short", nalu->len, + nalu->forbidden_bit, nalu->nal_reference_idc, + nalu->nal_unit_type); + fflush(p_Dec->p_trace); #endif return (pos - 1); } pos++; - *(pBuf ++) = getfbyte(annex_b); + *(pBuf++) = getfbyte(annex_b); info3 = FindStartCode(pBuf - 4, 3); - if(info3 != 1) - { + if (info3 != 1) { info2 = FindStartCode(pBuf - 3, 2); StartCodeFound = info2 & 0x01; - } - else + } else StartCodeFound = 1; } - // Here, we have found another start code (and read length of startcode bytes more than we should - // have. Hence, go back in the file - if(info3 == 1) //if the detected start code is 00 00 01, trailing_zero_8bits is sure not to be present + // Here, we have found another start code (and read length of startcode bytes + // more than we should have. Hence, go back in the file + if (info3 == 1) // if the detected start code is 00 00 01, trailing_zero_8bits + // is sure not to be present { pBuf -= 5; - while(*(pBuf--) == 0) + while (*(pBuf--) == 0) pos--; annex_b->nextstartcodebytes = 4; - } - else if (info2 == 1) + } else if (info2 == 1) annex_b->nextstartcodebytes = 3; - else - { + else { printf(" Panic: Error in next start code search \n"); return -1; } pos -= annex_b->nextstartcodebytes; - // Here the leading zeros(if any), Start code, the complete NALU, trailing zeros(if any) - // and the next start code is in the Buf. - // The size of Buf is pos - rewind, pos are the number of bytes excluding the next - // start code, and (pos) - LeadingZero8BitsCount - // is the size of the NALU. + // Here the leading zeros(if any), Start code, the complete NALU, trailing + // zeros(if any) and the next start code is in the Buf. The size of Buf is pos + // - rewind, pos are the number of bytes excluding the next start code, and + // (pos) - LeadingZero8BitsCount is the size of the NALU. nalu->len = pos - LeadingZero8BitsCount; - fast_memcpy (nalu->buf, annex_b->Buf + LeadingZero8BitsCount, nalu->len); - nalu->forbidden_bit = (*(nalu->buf) >> 7) & 1; - nalu->nal_reference_idc = (NalRefIdc) ((*(nalu->buf) >> 5) & 3); - nalu->nal_unit_type = (NaluType) ((*(nalu->buf)) & 0x1f); + fast_memcpy(nalu->buf, annex_b->Buf + LeadingZero8BitsCount, nalu->len); + nalu->forbidden_bit = (*(nalu->buf) >> 7) & 1; + nalu->nal_reference_idc = (NalRefIdc)((*(nalu->buf) >> 5) & 3); + nalu->nal_unit_type = (NaluType)((*(nalu->buf)) & 0x1f); nalu->lost_packets = 0; - - //printf ("GetAnnexbNALU, regular case: pos %d nalu->len %d, nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len, nalu->nal_reference_idc, nalu->nal_unit_type); + // printf ("GetAnnexbNALU, regular case: pos %d nalu->len %d, + // nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len, + // nalu->nal_reference_idc, nalu->nal_unit_type); #if TRACE - fprintf (p_Dec->p_trace, "\n\nAnnex B NALU w/ %s startcode, len %d, forbidden_bit %d, nal_reference_idc %d, nal_unit_type %d\n\n", - nalu->startcodeprefix_len == 4?"long":"short", nalu->len, nalu->forbidden_bit, nalu->nal_reference_idc, nalu->nal_unit_type); - fflush (p_Dec->p_trace); + fprintf(p_Dec->p_trace, + "\n\nAnnex B NALU w/ %s startcode, len %d, forbidden_bit %d, " + "nal_reference_idc %d, nal_unit_type %d\n\n", + nalu->startcodeprefix_len == 4 ? "long" : "short", nalu->len, + nalu->forbidden_bit, nalu->nal_reference_idc, nalu->nal_unit_type); + fflush(p_Dec->p_trace); #endif return (pos); - } - - /*! ************************************************************************ * \brief @@ -304,51 +280,43 @@ int GetAnnexbNALU (VideoParameters *p_Vid, NALU_t *nalu) * none ************************************************************************ */ -void OpenAnnexBFile (VideoParameters *p_Vid, char *fn) -{ +void OpenAnnexBFile(VideoParameters *p_Vid, char *fn) { ANNEXB_t *annex_b = p_Vid->annex_b; - if (NULL != annex_b->iobuffer) - { - error ("OpenAnnexBFile: tried to open Annex B file twice",500); + if (NULL != annex_b->iobuffer) { + error("OpenAnnexBFile: tried to open Annex B file twice", 500); } - if ((annex_b->BitStreamFile = open(fn, OPENFLAGS_READ)) == -1) - { - snprintf (errortext, ET_SIZE, "Cannot open Annex B ByteStream file '%s'", fn); - error(errortext,500); + if ((annex_b->BitStreamFile = open(fn, OPENFLAGS_READ)) == -1) { + snprintf(errortext, ET_SIZE, "Cannot open Annex B ByteStream file '%s'", + fn); + error(errortext, 500); } - annex_b->iIOBufferSize = IOBUFFERSIZE * sizeof (byte); - annex_b->iobuffer = malloc (annex_b->iIOBufferSize); - if (NULL == annex_b->iobuffer) - { - error ("OpenAnnexBFile: cannot allocate IO buffer",500); + annex_b->iIOBufferSize = IOBUFFERSIZE * sizeof(byte); + annex_b->iobuffer = malloc(annex_b->iIOBufferSize); + if (NULL == annex_b->iobuffer) { + error("OpenAnnexBFile: cannot allocate IO buffer", 500); } annex_b->is_eof = FALSE; getChunk(annex_b); } - /*! ************************************************************************ * \brief * Closes the bit stream file ************************************************************************ */ -void CloseAnnexBFile(VideoParameters *p_Vid) -{ +void CloseAnnexBFile(VideoParameters *p_Vid) { ANNEXB_t *annex_b = p_Vid->annex_b; - if (annex_b->BitStreamFile != -1) - { + if (annex_b->BitStreamFile != -1) { close(annex_b->BitStreamFile); - annex_b->BitStreamFile = - 1; + annex_b->BitStreamFile = -1; } - free (annex_b->iobuffer); + free(annex_b->iobuffer); annex_b->iobuffer = NULL; } - -void ResetAnnexB(ANNEXB_t *annex_b) -{ +void ResetAnnexB(ANNEXB_t *annex_b) { annex_b->is_eof = FALSE; annex_b->bytesinbuffer = 0; annex_b->iobufferread = annex_b->iobuffer; diff --git a/src/common/ldecod_src/biaridecod.c b/src/common/ldecod_src/biaridecod.c index e4f7612..8aa5eb0 100644 --- a/src/common/ldecod_src/biaridecod.c +++ b/src/common/ldecod_src/biaridecod.c @@ -5,27 +5,27 @@ * \brief * Binary arithmetic decoder routines. * - * This modified implementation of the M Coder is based on JVT-U084 + * This modified implementation of the M Coder is based on JVT-U084 * with the choice of M_BITS = 16. * * \date * 21. Oct 2000 * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Detlev Marpe * - Gabi Blaettermann * - Gunnar Marten ************************************************************************************* */ +#include "biaridecod.h" #include "global.h" #include "memalloc.h" -#include "biaridecod.h" - -#define B_BITS 10 // Number of bits to represent the whole coding interval -#define HALF 0x01FE //(1 << (B_BITS-1)) - 2 -#define QUARTER 0x0100 //(1 << (B_BITS-2)) +#define B_BITS 10 // Number of bits to represent the whole coding interval +#define HALF 0x01FE //(1 << (B_BITS-1)) - 2 +#define QUARTER 0x0100 //(1 << (B_BITS-2)) /*! ************************************************************************ @@ -35,30 +35,25 @@ * allocates memory ************************************************************************ */ -DecodingEnvironmentPtr arideco_create_decoding_environment() -{ +DecodingEnvironmentPtr arideco_create_decoding_environment() { DecodingEnvironmentPtr dep; - if ((dep = calloc(1,sizeof(DecodingEnvironment))) == NULL) + if ((dep = calloc(1, sizeof(DecodingEnvironment))) == NULL) no_mem_exit("arideco_create_decoding_environment: dep"); return dep; } - /*! *********************************************************************** * \brief * Frees memory of the DecodingEnvironment struct *********************************************************************** */ -void arideco_delete_decoding_environment(DecodingEnvironmentPtr dep) -{ - if (dep == NULL) - { +void arideco_delete_decoding_environment(DecodingEnvironmentPtr dep) { + if (dep == NULL) { snprintf(errortext, ET_SIZE, "Error freeing dep (NULL pointer)"); - error (errortext, 200); - } - else + error(errortext, 200); + } else free(dep); } @@ -68,10 +63,9 @@ void arideco_delete_decoding_environment(DecodingEnvironmentPtr dep) * finalize arithetic decoding(): ************************************************************************ */ -void arideco_done_decoding(DecodingEnvironmentPtr dep) -{ +void arideco_done_decoding(DecodingEnvironmentPtr dep) { (*dep->Dcodestrm_len)++; -#if(TRACE==2) +#if (TRACE == 2) fprintf(p_trace, "done_decoding: %d\n", *dep->Dcodestrm_len); #endif } @@ -82,9 +76,8 @@ void arideco_done_decoding(DecodingEnvironmentPtr dep) * read one byte from the bitstream ************************************************************************ */ -unsigned int getbyte(DecodingEnvironmentPtr dep) -{ -#if(TRACE==2) +unsigned int getbyte(DecodingEnvironmentPtr dep) { +#if (TRACE == 2) fprintf(p_trace, "get_byte: %d\n", (*dep->Dcodestrm_len)); #endif return dep->Dcodestrm[(*dep->Dcodestrm_len)++]; @@ -96,15 +89,14 @@ unsigned int getbyte(DecodingEnvironmentPtr dep) * read two bytes from the bitstream ************************************************************************ */ -unsigned int getword(DecodingEnvironmentPtr dep) -{ +unsigned int getword(DecodingEnvironmentPtr dep) { int d = *dep->Dcodestrm_len; -#if(TRACE==2) +#if (TRACE == 2) fprintf(p_trace, "get_byte: %d\n", d); fprintf(p_trace, "get_byte: %d\n", d + 1); #endif *dep->Dcodestrm_len += 2; - return ((dep->Dcodestrm[d]<<8) | dep->Dcodestrm[d+1]); + return ((dep->Dcodestrm[d] << 8) | dep->Dcodestrm[d + 1]); } /*! ************************************************************************ @@ -112,43 +104,43 @@ unsigned int getword(DecodingEnvironmentPtr dep) * Initializes the DecodingEnvironment for the arithmetic coder ************************************************************************ */ -void arideco_start_decoding(DecodingEnvironmentPtr dep, unsigned char *code_buffer, - int firstbyte, int *code_len) -{ +void arideco_start_decoding(DecodingEnvironmentPtr dep, + unsigned char *code_buffer, int firstbyte, + int *code_len) { - dep->Dcodestrm = code_buffer; - dep->Dcodestrm_len = code_len; + dep->Dcodestrm = code_buffer; + dep->Dcodestrm_len = code_len; *dep->Dcodestrm_len = firstbyte; dep->Dvalue = getbyte(dep); - dep->Dvalue = (dep->Dvalue << 16) | getword(dep); // lookahead of 2 bytes: always make sure that bitstream buffer - // contains 2 more bytes than actual bitstream + dep->Dvalue = + (dep->Dvalue << 16) | + getword(dep); // lookahead of 2 bytes: always make sure that bitstream + // buffer contains 2 more bytes than actual bitstream dep->DbitsLeft = 15; dep->Drange = HALF; -#if (2==TRACE) - fprintf(p_trace, "value: %d firstbyte: %d code_len: %d\n", dep->Dvalue >> dep->DbitsLeft, firstbyte, *code_len); +#if (2 == TRACE) + fprintf(p_trace, "value: %d firstbyte: %d code_len: %d\n", + dep->Dvalue >> dep->DbitsLeft, firstbyte, *code_len); #endif } - /*! ************************************************************************ * \brief * arideco_bits_read ************************************************************************ */ -int arideco_bits_read(DecodingEnvironmentPtr dep) -{ +int arideco_bits_read(DecodingEnvironmentPtr dep) { int tmp = ((*dep->Dcodestrm_len) << 3) - dep->DbitsLeft; -#if (2==TRACE) +#if (2 == TRACE) fprintf(p_trace, "tmp: %d\n", tmp); #endif return tmp; } - /*! ************************************************************************ * \brief @@ -157,53 +149,48 @@ int arideco_bits_read(DecodingEnvironmentPtr dep) * the decoded symbol ************************************************************************ */ -unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, BiContextTypePtr bi_ct ) -{ - unsigned int bit = bi_ct->MPS; +unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, + BiContextTypePtr bi_ct) { + unsigned int bit = bi_ct->MPS; unsigned int *value = &dep->Dvalue; - unsigned int *range = &dep->Drange; - uint16 *state = &bi_ct->state; - unsigned int rLPS = rLPS_table_64x4[*state][(*range>>6) & 0x03]; + unsigned int *range = &dep->Drange; + uint16 *state = &bi_ct->state; + unsigned int rLPS = rLPS_table_64x4[*state][(*range >> 6) & 0x03]; int *DbitsLeft = &dep->DbitsLeft; *range -= rLPS; - if(*value < (*range << *DbitsLeft)) //MPS + if (*value < (*range << *DbitsLeft)) // MPS { - *state = AC_next_state_MPS_64[*state]; // next state + *state = AC_next_state_MPS_64[*state]; // next state - if( *range >= QUARTER ) - { + if (*range >= QUARTER) { return (bit); - } - else + } else *range <<= 1; (*DbitsLeft)--; - } - else // LPS + } else // LPS { - int renorm = renorm_table_32[(rLPS>>3) & 0x1F]; + int renorm = renorm_table_32[(rLPS >> 3) & 0x1F]; *value -= (*range << dep->DbitsLeft); *range = (rLPS << renorm); (*DbitsLeft) -= renorm; bit ^= 0x01; - if (!(*state)) // switch meaning of MPS if necessary - bi_ct->MPS ^= 0x01; + if (!(*state)) // switch meaning of MPS if necessary + bi_ct->MPS ^= 0x01; - *state = AC_next_state_LPS_64[*state]; // next state + *state = AC_next_state_LPS_64[*state]; // next state } - if( *DbitsLeft > 0 ) - { + if (*DbitsLeft > 0) { return (bit); - } - else - { + } else { *value <<= 16; - *value |= getword(dep); // lookahead of 2 bytes: always make sure that bitstream buffer + *value |= getword( + dep); // lookahead of 2 bytes: always make sure that bitstream buffer // contains 2 more bytes than actual bitstream (*DbitsLeft) += 16; @@ -211,7 +198,6 @@ unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, BiContextTypePtr bi } } - /*! ************************************************************************ * \brief @@ -220,26 +206,23 @@ unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, BiContextTypePtr bi * the decoded symbol ************************************************************************ */ -unsigned int biari_decode_symbol_eq_prob(DecodingEnvironmentPtr dep) -{ - int tmp_value; - unsigned int *value = &dep->Dvalue; - int *DbitsLeft = &dep->DbitsLeft; +unsigned int biari_decode_symbol_eq_prob(DecodingEnvironmentPtr dep) { + int tmp_value; + unsigned int *value = &dep->Dvalue; + int *DbitsLeft = &dep->DbitsLeft; - if(--(*DbitsLeft) == 0) - { - *value = (*value << 16) | getword( dep ); // lookahead of 2 bytes: always make sure that bitstream buffer - // contains 2 more bytes than actual bitstream + if (--(*DbitsLeft) == 0) { + *value = + (*value << 16) | + getword(dep); // lookahead of 2 bytes: always make sure that bitstream + // buffer contains 2 more bytes than actual bitstream *DbitsLeft = 16; } - tmp_value = *value - (dep->Drange << *DbitsLeft); + tmp_value = *value - (dep->Drange << *DbitsLeft); - if (tmp_value < 0) - { + if (tmp_value < 0) { return 0; - } - else - { + } else { *value = tmp_value; return 1; } @@ -253,35 +236,30 @@ unsigned int biari_decode_symbol_eq_prob(DecodingEnvironmentPtr dep) * the decoded symbol ************************************************************************ */ -unsigned int biari_decode_final(DecodingEnvironmentPtr dep) -{ - unsigned int range = dep->Drange - 2; - int value = dep->Dvalue; +unsigned int biari_decode_final(DecodingEnvironmentPtr dep) { + unsigned int range = dep->Drange - 2; + int value = dep->Dvalue; value -= (range << dep->DbitsLeft); - if (value < 0) - { - if( range >= QUARTER ) - { + if (value < 0) { + if (range >= QUARTER) { dep->Drange = range; return 0; - } - else - { + } else { dep->Drange = (range << 1); - if( --(dep->DbitsLeft) > 0 ) + if (--(dep->DbitsLeft) > 0) return 0; - else - { - dep->Dvalue = (dep->Dvalue << 16) | getword( dep ); // lookahead of 2 bytes: always make sure that bitstream buffer - // contains 2 more bytes than actual bitstream + else { + dep->Dvalue = + (dep->Dvalue << 16) | + getword( + dep); // lookahead of 2 bytes: always make sure that bitstream + // buffer contains 2 more bytes than actual bitstream dep->DbitsLeft = 16; return 0; } } - } - else - { + } else { return 1; } } @@ -292,21 +270,16 @@ unsigned int biari_decode_final(DecodingEnvironmentPtr dep) * Initializes a given context with some pre-defined probability state ************************************************************************ */ -void biari_init_context (int qp, BiContextTypePtr ctx, const signed char* ini) -{ - int pstate = ((ini[0]* qp )>>4) + ini[1]; +void biari_init_context(int qp, BiContextTypePtr ctx, const signed char *ini) { + int pstate = ((ini[0] * qp) >> 4) + ini[1]; - if ( pstate >= 64 ) - { + if (pstate >= 64) { pstate = imin(126, pstate); - ctx->state = (uint16) (pstate - 64); - ctx->MPS = 1; - } - else - { + ctx->state = (uint16)(pstate - 64); + ctx->MPS = 1; + } else { pstate = imax(1, pstate); - ctx->state = (uint16) (63 - pstate); - ctx->MPS = 0; + ctx->state = (uint16)(63 - pstate); + ctx->MPS = 0; } } - diff --git a/src/common/ldecod_src/blk_prediction.c b/src/common/ldecod_src/blk_prediction.c index 8eed0be..0cb7968 100644 --- a/src/common/ldecod_src/blk_prediction.c +++ b/src/common/ldecod_src/blk_prediction.c @@ -6,7 +6,8 @@ * Block Prediction related functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Alexis Michael Tourapis * ************************************************************************************* @@ -14,49 +15,48 @@ #include "contributors.h" -#include #include #include #include +#include #include "block.h" #include "global.h" -#include "macroblock.h" -#include "mc_prediction.h" #include "image.h" +#include "macroblock.h" #include "mb_access.h" +#include "mc_prediction.h" -void compute_residue (imgpel **curImg, imgpel **mpr, int **mb_rres, int mb_x, int opix_x, int width, int height) -{ +void compute_residue(imgpel **curImg, imgpel **mpr, int **mb_rres, int mb_x, + int opix_x, int width, int height) { imgpel *imgOrg, *imgPred; - int *m7; + int *m7; int i, j; - for (j = 0; j < height; j++) - { - imgOrg = &curImg[j][opix_x]; + for (j = 0; j < height; j++) { + imgOrg = &curImg[j][opix_x]; imgPred = &mpr[j][mb_x]; - m7 = &mb_rres[j][mb_x]; - for (i = 0; i < width; i++) - { + m7 = &mb_rres[j][mb_x]; + for (i = 0; i < width; i++) { *m7++ = *imgOrg++ - *imgPred++; } } } -void sample_reconstruct (imgpel **curImg, imgpel **mpr, int **mb_rres, int mb_x, int opix_x, int width, int height, int max_imgpel_value, int dq_bits) -{ +void sample_reconstruct(imgpel **curImg, imgpel **mpr, int **mb_rres, int mb_x, + int opix_x, int width, int height, int max_imgpel_value, + int dq_bits) { imgpel *imgOrg, *imgPred; - int *m7; + int *m7; int i, j; - for (j = 0; j < height; j++) - { + for (j = 0; j < height; j++) { imgOrg = &curImg[j][opix_x]; imgPred = &mpr[j][mb_x]; - m7 = &mb_rres[j][mb_x]; - for (i=0;i * - Rickard Sjoberg *********************************************************************** @@ -16,14 +17,14 @@ #include "contributors.h" -#include "global.h" -#include "block.h" #include "blk_prediction.h" +#include "block.h" +#include "global.h" #include "image.h" #include "mb_access.h" -#include "transform.h" -#include "quant.h" #include "memalloc.h" +#include "quant.h" +#include "transform.h" /*! *********************************************************************** @@ -31,17 +32,20 @@ * Inverse 4x4 transformation, transforms cof to mb_rres *********************************************************************** */ -void itrans4x4(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< used color plane - int ioff, //!< index to 4x4 block - int joff) //!< index to 4x4 block +void itrans4x4(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< used color plane + int ioff, //!< index to 4x4 block + int joff) //!< index to 4x4 block { Slice *currSlice = currMB->p_Slice; - int **mb_rres = currSlice->mb_rres[pl]; + int **mb_rres = currSlice->mb_rres[pl]; - inverse4x4(currSlice->cof[pl],mb_rres,joff,ioff); + inverse4x4(currSlice->cof[pl], mb_rres, joff, ioff); - sample_reconstruct (&currSlice->mb_rec[pl][joff], &currSlice->mb_pred[pl][joff], &mb_rres[joff], ioff, ioff, BLOCK_SIZE, BLOCK_SIZE, currMB->p_Vid->max_pel_value_comp[pl], DQ_BITS); + sample_reconstruct(&currSlice->mb_rec[pl][joff], + &currSlice->mb_pred[pl][joff], &mb_rres[joff], ioff, ioff, + BLOCK_SIZE, BLOCK_SIZE, + currMB->p_Vid->max_pel_value_comp[pl], DQ_BITS); } /*! @@ -50,26 +54,25 @@ void itrans4x4(Macroblock *currMB, //!< current macroblock * Inverse 4x4 lossless_qpprime transformation, transforms cof to mb_rres **************************************************************************** */ -void itrans4x4_ls(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< Color plane (for 4:4:4) - int ioff, //!< index to 4x4 block - int joff) //!< index to 4x4 block +void itrans4x4_ls(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< Color plane (for 4:4:4) + int ioff, //!< index to 4x4 block + int joff) //!< index to 4x4 block { - int i,j; + int i, j; Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; imgpel **mb_pred = currSlice->mb_pred[pl]; - imgpel **mb_rec = currSlice->mb_rec[pl]; - int **mb_rres = currSlice->mb_rres [pl]; + imgpel **mb_rec = currSlice->mb_rec[pl]; + int **mb_rres = currSlice->mb_rres[pl]; - for (j = joff; j < joff + BLOCK_SIZE; ++j) - { - for (i = ioff; i < ioff + BLOCK_SIZE; ++i) - { - mb_rec[j][i] = (imgpel) iClip1(max_imgpel_value, mb_pred[j][i] + mb_rres[j][i]); + for (j = joff; j < joff + BLOCK_SIZE; ++j) { + for (i = ioff; i < ioff + BLOCK_SIZE; ++i) { + mb_rec[j][i] = + (imgpel)iClip1(max_imgpel_value, mb_pred[j][i] + mb_rres[j][i]); } } } @@ -81,67 +84,56 @@ void itrans4x4_ls(Macroblock *currMB, //!< current macroblock * ************************************************************************ */ -void Inv_Residual_trans_4x4(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< used color plane - int ioff, //!< index to 4x4 block - int joff) //!< index to 4x4 block +void Inv_Residual_trans_4x4(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< used color plane + int ioff, //!< index to 4x4 block + int joff) //!< index to 4x4 block { - int i,j; + int i, j; int temp[4][4]; Slice *currSlice = currMB->p_Slice; imgpel **mb_pred = currSlice->mb_pred[pl]; - imgpel **mb_rec = currSlice->mb_rec[pl]; - int **mb_rres = currSlice->mb_rres[pl]; - int **cof = currSlice->cof[pl]; + imgpel **mb_rec = currSlice->mb_rec[pl]; + int **mb_rres = currSlice->mb_rres[pl]; + int **cof = currSlice->cof[pl]; - if(currMB->ipmode_DPCM == VERT_PRED) - { - for(i=0; i<4; ++i) - { + if (currMB->ipmode_DPCM == VERT_PRED) { + for (i = 0; i < 4; ++i) { temp[0][i] = cof[joff + 0][ioff + i]; temp[1][i] = cof[joff + 1][ioff + i] + temp[0][i]; temp[2][i] = cof[joff + 2][ioff + i] + temp[1][i]; temp[3][i] = cof[joff + 3][ioff + i] + temp[2][i]; } - for(i=0; i<4; ++i) - { - mb_rres[joff ][ioff + i]=temp[0][i]; - mb_rres[joff + 1][ioff + i]=temp[1][i]; - mb_rres[joff + 2][ioff + i]=temp[2][i]; - mb_rres[joff + 3][ioff + i]=temp[3][i]; + for (i = 0; i < 4; ++i) { + mb_rres[joff][ioff + i] = temp[0][i]; + mb_rres[joff + 1][ioff + i] = temp[1][i]; + mb_rres[joff + 2][ioff + i] = temp[2][i]; + mb_rres[joff + 3][ioff + i] = temp[3][i]; } - } - else if(currMB->ipmode_DPCM == HOR_PRED) - { - for(j=0; j<4; ++j) - { - temp[j][0] = cof[joff + j][ioff ]; + } else if (currMB->ipmode_DPCM == HOR_PRED) { + for (j = 0; j < 4; ++j) { + temp[j][0] = cof[joff + j][ioff]; temp[j][1] = cof[joff + j][ioff + 1] + temp[j][0]; temp[j][2] = cof[joff + j][ioff + 2] + temp[j][1]; temp[j][3] = cof[joff + j][ioff + 3] + temp[j][2]; } - for(j=0; j<4; ++j) - { - mb_rres[joff + j][ioff ]=temp[j][0]; - mb_rres[joff + j][ioff + 1]=temp[j][1]; - mb_rres[joff + j][ioff + 2]=temp[j][2]; - mb_rres[joff + j][ioff + 3]=temp[j][3]; + for (j = 0; j < 4; ++j) { + mb_rres[joff + j][ioff] = temp[j][0]; + mb_rres[joff + j][ioff + 1] = temp[j][1]; + mb_rres[joff + j][ioff + 2] = temp[j][2]; + mb_rres[joff + j][ioff + 3] = temp[j][3]; } - } - else - { + } else { for (j = joff; j < joff + BLOCK_SIZE; ++j) for (i = ioff; i < ioff + BLOCK_SIZE; ++i) mb_rres[j][i] = cof[j][i]; } - for (j = joff; j < joff + BLOCK_SIZE; ++j) - { - for (i = ioff; i < ioff + BLOCK_SIZE; ++i) - { - mb_rec[j][i] = (imgpel) (mb_rres[j][i] + mb_pred[j][i]); + for (j = joff; j < joff + BLOCK_SIZE; ++j) { + for (i = ioff; i < ioff + BLOCK_SIZE; ++i) { + mb_rec[j][i] = (imgpel)(mb_rres[j][i] + mb_pred[j][i]); } } } @@ -155,20 +147,18 @@ void Inv_Residual_trans_4x4(Macroblock *currMB, //!< current macroblock * ioff_x,joff_y: Block position inside a macro block (0,8). ************************************************************************ */ -//For residual DPCM -void Inv_Residual_trans_8x8(Macroblock *currMB, ColorPlane pl, int ioff,int joff) -{ +// For residual DPCM +void Inv_Residual_trans_8x8(Macroblock *currMB, ColorPlane pl, int ioff, + int joff) { Slice *currSlice = currMB->p_Slice; int i, j; int temp[8][8]; imgpel **mb_pred = currSlice->mb_pred[pl]; - imgpel **mb_rec = currSlice->mb_rec[pl]; - int **mb_rres = currSlice->mb_rres[pl]; + imgpel **mb_rec = currSlice->mb_rec[pl]; + int **mb_rres = currSlice->mb_rres[pl]; - if(currMB->ipmode_DPCM == VERT_PRED) - { - for(i=0; i<8; ++i) - { + if (currMB->ipmode_DPCM == VERT_PRED) { + for (i = 0; i < 8; ++i) { temp[0][i] = mb_rres[joff + 0][ioff + i]; temp[1][i] = mb_rres[joff + 1][ioff + i] + temp[0][i]; temp[2][i] = mb_rres[joff + 2][ioff + i] + temp[1][i]; @@ -178,22 +168,19 @@ void Inv_Residual_trans_8x8(Macroblock *currMB, ColorPlane pl, int ioff,int joff temp[6][i] = mb_rres[joff + 6][ioff + i] + temp[5][i]; temp[7][i] = mb_rres[joff + 7][ioff + i] + temp[6][i]; } - for(i=0; i<8; ++i) - { - mb_rres[joff ][ioff+i]=temp[0][i]; - mb_rres[joff+1][ioff+i]=temp[1][i]; - mb_rres[joff+2][ioff+i]=temp[2][i]; - mb_rres[joff+3][ioff+i]=temp[3][i]; - mb_rres[joff+4][ioff+i]=temp[4][i]; - mb_rres[joff+5][ioff+i]=temp[5][i]; - mb_rres[joff+6][ioff+i]=temp[6][i]; - mb_rres[joff+7][ioff+i]=temp[7][i]; + for (i = 0; i < 8; ++i) { + mb_rres[joff][ioff + i] = temp[0][i]; + mb_rres[joff + 1][ioff + i] = temp[1][i]; + mb_rres[joff + 2][ioff + i] = temp[2][i]; + mb_rres[joff + 3][ioff + i] = temp[3][i]; + mb_rres[joff + 4][ioff + i] = temp[4][i]; + mb_rres[joff + 5][ioff + i] = temp[5][i]; + mb_rres[joff + 6][ioff + i] = temp[6][i]; + mb_rres[joff + 7][ioff + i] = temp[7][i]; } - } - else if(currMB->ipmode_DPCM == HOR_PRED)//HOR_PRED + } else if (currMB->ipmode_DPCM == HOR_PRED) // HOR_PRED { - for(i=0; i<8; ++i) - { + for (i = 0; i < 8; ++i) { temp[i][0] = mb_rres[joff + i][ioff + 0]; temp[i][1] = mb_rres[joff + i][ioff + 1] + temp[i][0]; temp[i][2] = mb_rres[joff + i][ioff + 2] + temp[i][1]; @@ -203,30 +190,25 @@ void Inv_Residual_trans_8x8(Macroblock *currMB, ColorPlane pl, int ioff,int joff temp[i][6] = mb_rres[joff + i][ioff + 6] + temp[i][5]; temp[i][7] = mb_rres[joff + i][ioff + 7] + temp[i][6]; } - for(i=0; i<8; ++i) - { - mb_rres[joff+i][ioff+0]=temp[i][0]; - mb_rres[joff+i][ioff+1]=temp[i][1]; - mb_rres[joff+i][ioff+2]=temp[i][2]; - mb_rres[joff+i][ioff+3]=temp[i][3]; - mb_rres[joff+i][ioff+4]=temp[i][4]; - mb_rres[joff+i][ioff+5]=temp[i][5]; - mb_rres[joff+i][ioff+6]=temp[i][6]; - mb_rres[joff+i][ioff+7]=temp[i][7]; + for (i = 0; i < 8; ++i) { + mb_rres[joff + i][ioff + 0] = temp[i][0]; + mb_rres[joff + i][ioff + 1] = temp[i][1]; + mb_rres[joff + i][ioff + 2] = temp[i][2]; + mb_rres[joff + i][ioff + 3] = temp[i][3]; + mb_rres[joff + i][ioff + 4] = temp[i][4]; + mb_rres[joff + i][ioff + 5] = temp[i][5]; + mb_rres[joff + i][ioff + 6] = temp[i][6]; + mb_rres[joff + i][ioff + 7] = temp[i][7]; } } - for (j = joff; j < joff + BLOCK_SIZE*2; ++j) - { - for (i = ioff; i < ioff + BLOCK_SIZE*2; ++i) - { - mb_rec [j][i] = (imgpel) (mb_rres[j][i] + mb_pred[j][i]); + for (j = joff; j < joff + BLOCK_SIZE * 2; ++j) { + for (i = ioff; i < ioff + BLOCK_SIZE * 2; ++i) { + mb_rec[j][i] = (imgpel)(mb_rres[j][i] + mb_pred[j][i]); } } } - - /*! ************************************************************************ * \brief @@ -234,64 +216,52 @@ void Inv_Residual_trans_8x8(Macroblock *currMB, ColorPlane pl, int ioff,int joff * ************************************************************************ */ -void Inv_Residual_trans_16x16(Macroblock *currMB, //!< current macroblock - ColorPlane pl) //!< used color plane +void Inv_Residual_trans_16x16(Macroblock *currMB, //!< current macroblock + ColorPlane pl) //!< used color plane { - int i,j; + int i, j; int temp[16][16]; Slice *currSlice = currMB->p_Slice; imgpel **mb_pred = currSlice->mb_pred[pl]; - imgpel **mb_rec = currSlice->mb_rec[pl]; - int **mb_rres = currSlice->mb_rres[pl]; - int **cof = currSlice->cof[pl]; + imgpel **mb_rec = currSlice->mb_rec[pl]; + int **mb_rres = currSlice->mb_rres[pl]; + int **cof = currSlice->cof[pl]; - if(currMB->ipmode_DPCM == VERT_PRED_16) - { - for(i=0; iipmode_DPCM == VERT_PRED_16) { + for (i = 0; i < MB_BLOCK_SIZE; ++i) { temp[0][i] = cof[0][i]; - for(j = 1; j < MB_BLOCK_SIZE; j++) - temp[j][i] = cof[j][i] + temp[j-1][i]; + for (j = 1; j < MB_BLOCK_SIZE; j++) + temp[j][i] = cof[j][i] + temp[j - 1][i]; } - for(i=0; iipmode_DPCM == HOR_PRED_16) - { - for(j=0; jipmode_DPCM == HOR_PRED_16) { + for (j = 0; j < MB_BLOCK_SIZE; ++j) { + temp[j][0] = cof[j][0]; + for (i = 1; i < MB_BLOCK_SIZE; i++) + temp[j][i] = cof[j][i] + temp[j][i - 1]; } - for(j=0; jp_Slice; - //imgpel **mb_pred = currSlice->mb_pred[uv+1]; - //imgpel **mb_rec = currSlice->mb_rec[uv+1]; - int **mb_rres = currSlice->mb_rres[uv+1]; - int **cof = currSlice->cof[uv+1]; - int width, height; + // imgpel **mb_pred = currSlice->mb_pred[uv+1]; + // imgpel **mb_rec = currSlice->mb_rec[uv+1]; + int **mb_rres = currSlice->mb_rres[uv + 1]; + int **cof = currSlice->cof[uv + 1]; + int width, height; width = currMB->p_Vid->mb_cr_size_x; height = currMB->p_Vid->mb_cr_size_y; - if(currMB->c_ipred_mode == VERT_PRED_8) - { - for(i=0; ic_ipred_mode == VERT_PRED_8) { + for (i = 0; i < width; i++) { temp[0][i] = cof[0][i]; - for(j = 1; j < height; j++) - temp[j][i] = temp[j-1][i] + cof[j][i]; + for (j = 1; j < height; j++) + temp[j][i] = temp[j - 1][i] + cof[j][i]; } - for(i=0; ip_Slice; VideoParameters *p_Vid = currMB->p_Vid; int j; - int transform_pl = (p_Vid->separate_colour_plane_flag != 0) ? PLANE_Y /*p_Vid->colour_plane_id*/ : pl; + int transform_pl = (p_Vid->separate_colour_plane_flag != 0) + ? PLANE_Y /*p_Vid->colour_plane_id*/ + : pl; int **cof = currSlice->cof[transform_pl]; int qp_scaled = currMB->qp_scaled[pl]; - int qp_per = p_Vid->qp_per_matrix[ qp_scaled ]; - int qp_rem = p_Vid->qp_rem_matrix[ qp_scaled ]; + int qp_per = p_Vid->qp_per_matrix[qp_scaled]; + int qp_rem = p_Vid->qp_rem_matrix[qp_scaled]; int invLevelScale = currSlice->InvLevelScale4x4_Intra[pl][qp_rem][0][0]; int **M4; get_mem2Dint(&M4, BLOCK_SIZE, BLOCK_SIZE); - + // horizontal - for (j=0; j < 4;++j) - { - M4[j][0]=cof[j<<2][0]; - M4[j][1]=cof[j<<2][4]; - M4[j][2]=cof[j<<2][8]; - M4[j][3]=cof[j<<2][12]; + for (j = 0; j < 4; ++j) { + M4[j][0] = cof[j << 2][0]; + M4[j][1] = cof[j << 2][4]; + M4[j][2] = cof[j << 2][8]; + M4[j][3] = cof[j << 2][12]; } ihadamard4x4(M4, M4); // vertical - for (j=0; j < 4;++j) - { - cof[j<<2][0] = rshift_rnd((( M4[j][0] * invLevelScale) << qp_per), 6); - cof[j<<2][4] = rshift_rnd((( M4[j][1] * invLevelScale) << qp_per), 6); - cof[j<<2][8] = rshift_rnd((( M4[j][2] * invLevelScale) << qp_per), 6); - cof[j<<2][12] = rshift_rnd((( M4[j][3] * invLevelScale) << qp_per), 6); + for (j = 0; j < 4; ++j) { + cof[j << 2][0] = rshift_rnd(((M4[j][0] * invLevelScale) << qp_per), 6); + cof[j << 2][4] = rshift_rnd(((M4[j][1] * invLevelScale) << qp_per), 6); + cof[j << 2][8] = rshift_rnd(((M4[j][2] * invLevelScale) << qp_per), 6); + cof[j << 2][12] = rshift_rnd(((M4[j][3] * invLevelScale) << qp_per), 6); } free_mem2Dint(M4); } - -void itrans_sp(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< used color plane - int ioff, //!< index to 4x4 block - int joff) //!< index to 4x4 block +void itrans_sp(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< used color plane + int ioff, //!< index to 4x4 block + int joff) //!< index to 4x4 block { VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; - int i,j; + int i, j; int ilev, icof; int qp = (currSlice->slice_type == SI_SLICE) ? currSlice->qs : currSlice->qp; - int qp_per = p_Vid->qp_per_matrix[ qp ]; - int qp_rem = p_Vid->qp_rem_matrix[ qp ]; + int qp_per = p_Vid->qp_per_matrix[qp]; + int qp_rem = p_Vid->qp_rem_matrix[qp]; - int qp_per_sp = p_Vid->qp_per_matrix[ currSlice->qs ]; - int qp_rem_sp = p_Vid->qp_rem_matrix[ currSlice->qs ]; + int qp_per_sp = p_Vid->qp_per_matrix[currSlice->qs]; + int qp_rem_sp = p_Vid->qp_rem_matrix[currSlice->qs]; int q_bits_sp = Q_BITS + qp_per_sp; imgpel **mb_pred = currSlice->mb_pred[pl]; - imgpel **mb_rec = currSlice->mb_rec[pl]; - int **mb_rres = currSlice->mb_rres[pl]; - int **cof = currSlice->cof[pl]; + imgpel **mb_rec = currSlice->mb_rec[pl]; + int **mb_rres = currSlice->mb_rres[pl]; + int **cof = currSlice->cof[pl]; int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; - const int (*InvLevelScale4x4) [4] = dequant_coef[qp_rem]; - const int (*InvLevelScale4x4SP)[4] = dequant_coef[qp_rem_sp]; - int **PBlock; + const int(*InvLevelScale4x4)[4] = dequant_coef[qp_rem]; + const int(*InvLevelScale4x4SP)[4] = dequant_coef[qp_rem_sp]; + int **PBlock; get_mem2Dint(&PBlock, MB_BLOCK_SIZE, MB_BLOCK_SIZE); - for (j=0; j< BLOCK_SIZE; ++j) - { - PBlock[j][0] = mb_pred[j+joff][ioff ]; - PBlock[j][1] = mb_pred[j+joff][ioff + 1]; - PBlock[j][2] = mb_pred[j+joff][ioff + 2]; - PBlock[j][3] = mb_pred[j+joff][ioff + 3]; + for (j = 0; j < BLOCK_SIZE; ++j) { + PBlock[j][0] = mb_pred[j + joff][ioff]; + PBlock[j][1] = mb_pred[j + joff][ioff + 1]; + PBlock[j][2] = mb_pred[j + joff][ioff + 2]; + PBlock[j][3] = mb_pred[j + joff][ioff + 3]; } forward4x4(PBlock, PBlock, 0, 0); - if(currSlice->sp_switch || currSlice->slice_type==SI_SLICE) - { - for (j=0;jsp_switch || currSlice->slice_type == SI_SLICE) { + for (j = 0; j < BLOCK_SIZE; ++j) { + for (i = 0; i < BLOCK_SIZE; ++i) { // recovering coefficient since they are already dequantized earlier icof = (cof[joff + j][ioff + i] >> qp_per) / InvLevelScale4x4[j][i]; - //icof = ((cof[joff + j][ioff + i] * quant_coef[qp_rem][j][i])>> (qp_per + 15)) ; - // icof = rshift_rnd_sf(cof[joff + j][ioff + i] * quant_coef[qp_rem][j][i], qp_per + 15); - ilev = rshift_rnd_sf(iabs(PBlock[j][i]) * quant_coef[qp_rem_sp][j][i], q_bits_sp); - ilev = isignab(ilev, PBlock[j][i]) + icof; + // icof = ((cof[joff + j][ioff + i] * quant_coef[qp_rem][j][i])>> + // (qp_per + 15)) ; + // icof = rshift_rnd_sf(cof[joff + j][ioff + i] * + // quant_coef[qp_rem][j][i], qp_per + 15); + ilev = rshift_rnd_sf(iabs(PBlock[j][i]) * quant_coef[qp_rem_sp][j][i], + q_bits_sp); + ilev = isignab(ilev, PBlock[j][i]) + icof; cof[joff + j][ioff + i] = ilev * InvLevelScale4x4SP[j][i] << qp_per_sp; } } - } - else - { - for (j=0;j> qp_per) / InvLevelScale4x4[j][i]; - //icof = cof[joff + j][ioff + i]; - //icof = rshift_rnd_sf(cof[joff + j][ioff + i] * quant_coef[qp_rem][j][i], qp_per + 15); - ilev = PBlock[j][i] + ((icof * InvLevelScale4x4[j][i] * A[j][i] << qp_per) >> 6); - ilev = isign(ilev) * rshift_rnd_sf(iabs(ilev) * quant_coef[qp_rem_sp][j][i], q_bits_sp); - //cof[joff + j][ioff + i] = ilev * InvLevelScale4x4SP[j][i] << qp_per_sp; + // icof = cof[joff + j][ioff + i]; + // icof = rshift_rnd_sf(cof[joff + j][ioff + i] * + // quant_coef[qp_rem][j][i], qp_per + 15); + ilev = PBlock[j][i] + + ((icof * InvLevelScale4x4[j][i] * A[j][i] << qp_per) >> 6); + ilev = + isign(ilev) * + rshift_rnd_sf(iabs(ilev) * quant_coef[qp_rem_sp][j][i], q_bits_sp); + // cof[joff + j][ioff + i] = ilev * InvLevelScale4x4SP[j][i] << + // qp_per_sp; cof[joff + j][ioff + i] = ilev * InvLevelScale4x4SP[j][i] << qp_per_sp; } } @@ -468,56 +429,56 @@ void itrans_sp(Macroblock *currMB, //!< current macroblock inverse4x4(cof, mb_rres, joff, ioff); - for (j=joff; jp_Slice; VideoParameters *p_Vid = currMB->p_Vid; - int i,j,ilev, icof, n2,n1; + int i, j, ilev, icof, n2, n1; int mp1[BLOCK_SIZE]; - int qp_per,qp_rem; - int qp_per_sp,qp_rem_sp,q_bits_sp; + int qp_per, qp_rem; + int qp_per_sp, qp_rem_sp, q_bits_sp; imgpel **mb_pred = currSlice->mb_pred[uv + 1]; - int **cof = currSlice->cof[uv + 1]; + int **cof = currSlice->cof[uv + 1]; int **PBlock = new_mem2Dint(MB_BLOCK_SIZE, MB_BLOCK_SIZE); - qp_per = p_Vid->qp_per_matrix[ ((currSlice->qp < 0 ? currSlice->qp : QP_SCALE_CR[currSlice->qp]))]; - qp_rem = p_Vid->qp_rem_matrix[ ((currSlice->qp < 0 ? currSlice->qp : QP_SCALE_CR[currSlice->qp]))]; + qp_per = p_Vid->qp_per_matrix[( + (currSlice->qp < 0 ? currSlice->qp : QP_SCALE_CR[currSlice->qp]))]; + qp_rem = p_Vid->qp_rem_matrix[( + (currSlice->qp < 0 ? currSlice->qp : QP_SCALE_CR[currSlice->qp]))]; - qp_per_sp = p_Vid->qp_per_matrix[ ((currSlice->qs < 0 ? currSlice->qs : QP_SCALE_CR[currSlice->qs]))]; - qp_rem_sp = p_Vid->qp_rem_matrix[ ((currSlice->qs < 0 ? currSlice->qs : QP_SCALE_CR[currSlice->qs]))]; - q_bits_sp = Q_BITS + qp_per_sp; + qp_per_sp = p_Vid->qp_per_matrix[( + (currSlice->qs < 0 ? currSlice->qs : QP_SCALE_CR[currSlice->qs]))]; + qp_rem_sp = p_Vid->qp_rem_matrix[( + (currSlice->qs < 0 ? currSlice->qs : QP_SCALE_CR[currSlice->qs]))]; + q_bits_sp = Q_BITS + qp_per_sp; - if (currSlice->slice_type == SI_SLICE) - { + if (currSlice->slice_type == SI_SLICE) { qp_per = qp_per_sp; qp_rem = qp_rem_sp; } - for (j=0; j < p_Vid->mb_cr_size_y; ++j) - { - for (i=0; i < p_Vid->mb_cr_size_x; ++i) - { + for (j = 0; j < p_Vid->mb_cr_size_y; ++j) { + for (i = 0; i < p_Vid->mb_cr_size_x; ++i) { PBlock[j][i] = mb_pred[j][i]; mb_pred[j][i] = 0; } } - for (n2=0; n2 < p_Vid->mb_cr_size_y; n2 += BLOCK_SIZE) - { - for (n1=0; n1 < p_Vid->mb_cr_size_x; n1 += BLOCK_SIZE) - { + for (n2 = 0; n2 < p_Vid->mb_cr_size_y; n2 += BLOCK_SIZE) { + for (n1 = 0; n1 < p_Vid->mb_cr_size_x; n1 += BLOCK_SIZE) { forward4x4(PBlock, PBlock, n2, n1); } } @@ -528,73 +489,76 @@ void itrans_sp_cr(Macroblock *currMB, int uv) mp1[2] = (PBlock[0][0] + PBlock[4][0] - PBlock[0][4] - PBlock[4][4]); mp1[3] = (PBlock[0][0] - PBlock[4][0] - PBlock[0][4] + PBlock[4][4]); - if (currSlice->sp_switch || currSlice->slice_type == SI_SLICE) - { - for (n2=0; n2 < 2; ++n2 ) - { - for (n1=0; n1 < 2; ++n1 ) - { - //quantization fo predicted block - ilev = rshift_rnd_sf(iabs (mp1[n1+n2*2]) * quant_coef[qp_rem_sp][0][0], q_bits_sp + 1); - //addition - ilev = isignab(ilev, mp1[n1+n2*2]) + cof[n2<<2][n1<<2]; - //dequantization - mp1[n1+n2*2] =ilev * dequant_coef[qp_rem_sp][0][0] << qp_per_sp; + if (currSlice->sp_switch || currSlice->slice_type == SI_SLICE) { + for (n2 = 0; n2 < 2; ++n2) { + for (n1 = 0; n1 < 2; ++n1) { + // quantization fo predicted block + ilev = + rshift_rnd_sf(iabs(mp1[n1 + n2 * 2]) * quant_coef[qp_rem_sp][0][0], + q_bits_sp + 1); + // addition + ilev = isignab(ilev, mp1[n1 + n2 * 2]) + cof[n2 << 2][n1 << 2]; + // dequantization + mp1[n1 + n2 * 2] = ilev * dequant_coef[qp_rem_sp][0][0] << qp_per_sp; } } - for (n2 = 0; n2 < p_Vid->mb_cr_size_y; n2 += BLOCK_SIZE) - { - for (n1 = 0; n1 < p_Vid->mb_cr_size_x; n1 += BLOCK_SIZE) - { - for (j = 0; j < BLOCK_SIZE; ++j) - { - for (i = 0; i < BLOCK_SIZE; ++i) - { + for (n2 = 0; n2 < p_Vid->mb_cr_size_y; n2 += BLOCK_SIZE) { + for (n1 = 0; n1 < p_Vid->mb_cr_size_x; n1 += BLOCK_SIZE) { + for (j = 0; j < BLOCK_SIZE; ++j) { + for (i = 0; i < BLOCK_SIZE; ++i) { // recovering coefficient since they are already dequantized earlier - cof[n2 + j][n1 + i] = (cof[n2 + j][n1 + i] >> qp_per) / dequant_coef[qp_rem][j][i]; + cof[n2 + j][n1 + i] = + (cof[n2 + j][n1 + i] >> qp_per) / dequant_coef[qp_rem][j][i]; - //quantization of the predicted block - ilev = rshift_rnd_sf(iabs(PBlock[n2 + j][n1 + i]) * quant_coef[qp_rem_sp][j][i], q_bits_sp); - //addition of the residual - ilev = isignab(ilev,PBlock[n2 + j][n1 + i]) + cof[n2 + j][n1 + i]; + // quantization of the predicted block + ilev = rshift_rnd_sf(iabs(PBlock[n2 + j][n1 + i]) * + quant_coef[qp_rem_sp][j][i], + q_bits_sp); + // addition of the residual + ilev = isignab(ilev, PBlock[n2 + j][n1 + i]) + cof[n2 + j][n1 + i]; // Inverse quantization - cof[n2 + j][n1 + i] = ilev * dequant_coef[qp_rem_sp][j][i] << qp_per_sp; + cof[n2 + j][n1 + i] = ilev * dequant_coef[qp_rem_sp][j][i] + << qp_per_sp; } } } } - } - else - { - for (n2=0; n2 < 2; ++n2 ) - { - for (n1=0; n1 < 2; ++n1 ) - { - ilev = mp1[n1+n2*2] + (((cof[n2<<2][n1<<2] * dequant_coef[qp_rem][0][0] * A[0][0]) << qp_per) >> 5); - ilev = isign(ilev) * rshift_rnd_sf(iabs(ilev) * quant_coef[qp_rem_sp][0][0], q_bits_sp + 1); - //ilev = isignab(rshift_rnd_sf(iabs(ilev)* quant_coef[qp_rem_sp][0][0], q_bits_sp + 1), ilev); - mp1[n1+n2*2] = ilev * dequant_coef[qp_rem_sp][0][0] << qp_per_sp; + } else { + for (n2 = 0; n2 < 2; ++n2) { + for (n1 = 0; n1 < 2; ++n1) { + ilev = mp1[n1 + n2 * 2] + + (((cof[n2 << 2][n1 << 2] * dequant_coef[qp_rem][0][0] * A[0][0]) + << qp_per) >> + 5); + ilev = isign(ilev) * + rshift_rnd_sf(iabs(ilev) * quant_coef[qp_rem_sp][0][0], + q_bits_sp + 1); + // ilev = isignab(rshift_rnd_sf(iabs(ilev)* quant_coef[qp_rem_sp][0][0], + // q_bits_sp + 1), ilev); + mp1[n1 + n2 * 2] = ilev * dequant_coef[qp_rem_sp][0][0] << qp_per_sp; } } - for (n2 = 0; n2 < p_Vid->mb_cr_size_y; n2 += BLOCK_SIZE) - { - for (n1 = 0; n1 < p_Vid->mb_cr_size_x; n1 += BLOCK_SIZE) - { - for (j = 0; j< BLOCK_SIZE; ++j) - { - for (i = 0; i< BLOCK_SIZE; ++i) - { + for (n2 = 0; n2 < p_Vid->mb_cr_size_y; n2 += BLOCK_SIZE) { + for (n1 = 0; n1 < p_Vid->mb_cr_size_x; n1 += BLOCK_SIZE) { + for (j = 0; j < BLOCK_SIZE; ++j) { + for (i = 0; i < BLOCK_SIZE; ++i) { // recovering coefficient since they are already dequantized earlier - //icof = ((((cof[n2 + j][n1 + i] << 4) + qp_per/2)>> qp_per) + dequant_coef[qp_rem][j][i]/2) / dequant_coef[qp_rem][j][i]; + // icof = ((((cof[n2 + j][n1 + i] << 4) + qp_per/2)>> qp_per) + + // dequant_coef[qp_rem][j][i]/2) / dequant_coef[qp_rem][j][i]; icof = (cof[n2 + j][n1 + i] >> qp_per) / dequant_coef[qp_rem][j][i]; - //dequantization and addition of the predicted block - ilev = PBlock[n2 + j][n1 + i] + ((icof * dequant_coef[qp_rem][j][i] * A[j][i] << qp_per) >> 6); - //quantization and dequantization - ilev = isign(ilev) * rshift_rnd_sf(iabs(ilev) * quant_coef[qp_rem_sp][j][i], q_bits_sp); - cof[n2 + j][n1 + i] = ilev * dequant_coef[qp_rem_sp][j][i] << qp_per_sp; - //printf( " %d %d %d\n", j, i, quant_coef[qp_rem_sp][j][i]); + // dequantization and addition of the predicted block + ilev = + PBlock[n2 + j][n1 + i] + + ((icof * dequant_coef[qp_rem][j][i] * A[j][i] << qp_per) >> 6); + // quantization and dequantization + ilev = isign(ilev) * + rshift_rnd_sf(iabs(ilev) * quant_coef[qp_rem_sp][j][i], + q_bits_sp); + cof[n2 + j][n1 + i] = ilev * dequant_coef[qp_rem_sp][j][i] + << qp_per_sp; + // printf( " %d %d %d\n", j, i, quant_coef[qp_rem_sp][j][i]); } } } @@ -609,64 +573,61 @@ void itrans_sp_cr(Macroblock *currMB, int uv) free_mem2Dint(PBlock); } -void iMBtrans4x4(Macroblock *currMB, ColorPlane pl, int smb) -{ +void iMBtrans4x4(Macroblock *currMB, ColorPlane pl, int smb) { Slice *currSlice = currMB->p_Slice; - //VideoParameters *p_Vid = currMB->p_Vid; + // VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currMB->p_Slice->dec_picture; int jj, ii; int block8x8; - int k; + int k; - imgpel **curr_img = pl ? dec_picture->imgUV[pl - 1]: dec_picture->imgY; + imgpel **curr_img = pl ? dec_picture->imgUV[pl - 1] : dec_picture->imgY; // =============== 4x4 itrans ================ // ------------------------------------------- - if (currMB->is_lossless && currMB->mb_type == I16MB) - { - Inv_Residual_trans_16x16(currMB, pl) ; - } - else - if (smb || currMB->is_lossless == TRUE) - { - currMB->itrans_4x4 = (smb) ? itrans_sp : ((currMB->is_lossless == FALSE) ? itrans4x4 : Inv_Residual_trans_4x4); - for (block8x8=0; block8x8 < MB_BLOCK_SIZE; block8x8 += 4) - { - for (k = block8x8; k < block8x8 + 4; ++k ) - { + if (currMB->is_lossless && currMB->mb_type == I16MB) { + Inv_Residual_trans_16x16(currMB, pl); + } else if (smb || currMB->is_lossless == TRUE) { + currMB->itrans_4x4 = + (smb) ? itrans_sp + : ((currMB->is_lossless == FALSE) ? itrans4x4 + : Inv_Residual_trans_4x4); + for (block8x8 = 0; block8x8 < MB_BLOCK_SIZE; block8x8 += 4) { + for (k = block8x8; k < block8x8 + 4; ++k) { jj = ((decode_block_scan[k] >> 2) & 3) << BLOCK_SHIFT; ii = (decode_block_scan[k] & 3) << BLOCK_SHIFT; - currMB->itrans_4x4(currMB, pl, ii, jj); // use integer transform and make 4x4 block mb_rres from prediction block mb_pred + currMB->itrans_4x4(currMB, pl, ii, + jj); // use integer transform and make 4x4 block + // mb_rres from prediction block mb_pred } } - } - else - { + } else { int **cof = currSlice->cof[pl]; int **mb_rres = currSlice->mb_rres[pl]; - for (jj = 0; jj < MB_BLOCK_SIZE; jj += BLOCK_SIZE) - { + for (jj = 0; jj < MB_BLOCK_SIZE; jj += BLOCK_SIZE) { inverse4x4(cof, mb_rres, jj, 0); inverse4x4(cof, mb_rres, jj, 4); inverse4x4(cof, mb_rres, jj, 8); inverse4x4(cof, mb_rres, jj, 12); } - sample_reconstruct (currSlice->mb_rec[pl], currSlice->mb_pred[pl], mb_rres, 0, 0, MB_BLOCK_SIZE, MB_BLOCK_SIZE, currMB->p_Vid->max_pel_value_comp[pl], DQ_BITS); + sample_reconstruct(currSlice->mb_rec[pl], currSlice->mb_pred[pl], mb_rres, + 0, 0, MB_BLOCK_SIZE, MB_BLOCK_SIZE, + currMB->p_Vid->max_pel_value_comp[pl], DQ_BITS); } // construct picture from 4x4 blocks - copy_image_data_16x16(&curr_img[currMB->pix_y], currSlice->mb_rec[pl], currMB->pix_x, 0); + copy_image_data_16x16(&curr_img[currMB->pix_y], currSlice->mb_rec[pl], + currMB->pix_x, 0); } -void iMBtrans8x8(Macroblock *currMB, ColorPlane pl) -{ - //VideoParameters *p_Vid = currMB->p_Vid; +void iMBtrans8x8(Macroblock *currMB, ColorPlane pl) { + // VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currMB->p_Slice->dec_picture; - imgpel **curr_img = pl ? dec_picture->imgUV[pl - 1]: dec_picture->imgY; + imgpel **curr_img = pl ? dec_picture->imgUV[pl - 1] : dec_picture->imgY; // Perform 8x8 idct itrans8x8(currMB, pl, 0, 0); @@ -674,109 +635,97 @@ void iMBtrans8x8(Macroblock *currMB, ColorPlane pl) itrans8x8(currMB, pl, 0, 8); itrans8x8(currMB, pl, 8, 8); - copy_image_data_16x16(&curr_img[currMB->pix_y], currMB->p_Slice->mb_rec[pl], currMB->pix_x, 0); + copy_image_data_16x16(&curr_img[currMB->pix_y], currMB->p_Slice->mb_rec[pl], + currMB->pix_x, 0); } -void iTransform(Macroblock *currMB, ColorPlane pl, int smb) -{ +void iTransform(Macroblock *currMB, ColorPlane pl, int smb) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; imgpel **curr_img; - int uv = pl-1; + int uv = pl - 1; - if ((currMB->cbp & 15) != 0 || smb) - { - if(currMB->luma_transform_size_8x8_flag == 0) // 4x4 inverse transform + if ((currMB->cbp & 15) != 0 || smb) { + if (currMB->luma_transform_size_8x8_flag == 0) // 4x4 inverse transform { - iMBtrans4x4(currMB, pl, smb); + iMBtrans4x4(currMB, pl, smb); + } else // 8x8 inverse transform + { + iMBtrans8x8(currMB, pl); } - else // 8x8 inverse transform - { - iMBtrans8x8(currMB, pl); - } - } - else - { + } else { curr_img = pl ? dec_picture->imgUV[uv] : dec_picture->imgY; - copy_image_data_16x16(&curr_img[currMB->pix_y], currSlice->mb_pred[pl], currMB->pix_x, 0); + copy_image_data_16x16(&curr_img[currMB->pix_y], currSlice->mb_pred[pl], + currMB->pix_x, 0); } - - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { imgpel **curUV; int b8; int ioff, joff; imgpel **mb_rec; - for(uv = PLANE_U; uv <= PLANE_V; ++uv) - { + for (uv = PLANE_U; uv <= PLANE_V; ++uv) { // =============== 4x4 itrans ================ // ------------------------------------------- - curUV = &dec_picture->imgUV[uv - 1][currMB->pix_c_y]; + curUV = &dec_picture->imgUV[uv - 1][currMB->pix_c_y]; mb_rec = currSlice->mb_rec[uv]; - if (!smb && (currMB->cbp>>4)) - { - if (currMB->is_lossless == FALSE) - { + if (!smb && (currMB->cbp >> 4)) { + if (currMB->is_lossless == FALSE) { const unsigned char *x_pos, *y_pos; - //const unsigned char *xx_pos = subblk_offset_x[1]; - //const unsigned char *xy_pos = subblk_offset_y[1]; + // const unsigned char *xx_pos = subblk_offset_x[1]; + // const unsigned char *xy_pos = subblk_offset_y[1]; - for (b8 = 0; b8 < (p_Vid->num_uv_blocks); ++b8) - { + for (b8 = 0; b8 < (p_Vid->num_uv_blocks); ++b8) { x_pos = subblk_offset_x[1][b8]; y_pos = subblk_offset_y[1][b8]; itrans4x4(currMB, uv, *x_pos++, *y_pos++); itrans4x4(currMB, uv, *x_pos++, *y_pos++); itrans4x4(currMB, uv, *x_pos++, *y_pos++); - itrans4x4(currMB, uv, *x_pos , *y_pos ); - //itrans4x4(currMB, uv, *(*xx_pos ), *(*xy_pos )); - //itrans4x4(currMB, uv, *(*xx_pos + 1), *(*xy_pos + 1)); - //itrans4x4(currMB, uv, *(*xx_pos + 2), *(*xy_pos + 2)); - //itrans4x4(currMB, uv, *(*xx_pos++ + 3), *(*xy_pos++ + 3)); - + itrans4x4(currMB, uv, *x_pos, *y_pos); + // itrans4x4(currMB, uv, *(*xx_pos ), *(*xy_pos )); + // itrans4x4(currMB, uv, *(*xx_pos + 1), *(*xy_pos + 1)); + // itrans4x4(currMB, uv, *(*xx_pos + 2), *(*xy_pos + 2)); + // itrans4x4(currMB, uv, *(*xx_pos++ + 3), *(*xy_pos++ + 3)); } - sample_reconstruct (mb_rec, currSlice->mb_pred[uv], currSlice->mb_rres[uv], 0, 0, - p_Vid->mb_size[1][0], p_Vid->mb_size[1][1], currMB->p_Vid->max_pel_value_comp[uv], DQ_BITS); - } - else - { + sample_reconstruct(mb_rec, currSlice->mb_pred[uv], + currSlice->mb_rres[uv], 0, 0, p_Vid->mb_size[1][0], + p_Vid->mb_size[1][1], + currMB->p_Vid->max_pel_value_comp[uv], DQ_BITS); + } else { const unsigned char *x_pos, *y_pos; - for (b8 = 0; b8 < (p_Vid->num_uv_blocks); ++b8) - { + for (b8 = 0; b8 < (p_Vid->num_uv_blocks); ++b8) { x_pos = subblk_offset_x[1][b8]; y_pos = subblk_offset_y[1][b8]; itrans4x4_ls(currMB, uv, *x_pos++, *y_pos++); itrans4x4_ls(currMB, uv, *x_pos++, *y_pos++); itrans4x4_ls(currMB, uv, *x_pos++, *y_pos++); - itrans4x4_ls(currMB, uv, *x_pos , *y_pos ); + itrans4x4_ls(currMB, uv, *x_pos, *y_pos); } } - copy_image_data(curUV, mb_rec, currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); - } - else if (smb) - { - currMB->itrans_4x4 = (currMB->is_lossless == FALSE) ? itrans4x4 : itrans4x4_ls; + copy_image_data(curUV, mb_rec, currMB->pix_c_x, 0, p_Vid->mb_size[1][0], + p_Vid->mb_size[1][1]); + } else if (smb) { + currMB->itrans_4x4 = + (currMB->is_lossless == FALSE) ? itrans4x4 : itrans4x4_ls; itrans_sp_cr(currMB, uv - 1); - for (joff = 0; joff < p_Vid->mb_cr_size_y; joff += BLOCK_SIZE) - { - for(ioff = 0; ioff < p_Vid->mb_cr_size_x ;ioff += BLOCK_SIZE) - { + for (joff = 0; joff < p_Vid->mb_cr_size_y; joff += BLOCK_SIZE) { + for (ioff = 0; ioff < p_Vid->mb_cr_size_x; ioff += BLOCK_SIZE) { currMB->itrans_4x4(currMB, uv, ioff, joff); } } - copy_image_data(curUV, mb_rec, currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); - } - else - { - copy_image_data(curUV, currSlice->mb_pred[uv], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + copy_image_data(curUV, mb_rec, currMB->pix_c_x, 0, p_Vid->mb_size[1][0], + p_Vid->mb_size[1][1]); + } else { + copy_image_data(curUV, currSlice->mb_pred[uv], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); } } } @@ -788,15 +737,18 @@ void iTransform(Macroblock *currMB, ColorPlane pl, int smb) * Copy ImgPel Data from one structure to another (16x16) ************************************************************************************* */ -void copy_image_data_16x16(imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2) -{ +void copy_image_data_16x16(imgpel **imgBuf1, imgpel **imgBuf2, int off1, + int off2) { int j; - for(j = 0; j < MB_BLOCK_SIZE; j += 4) - { - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), MB_BLOCK_SIZE * sizeof (imgpel)); - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), MB_BLOCK_SIZE * sizeof (imgpel)); - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), MB_BLOCK_SIZE * sizeof (imgpel)); - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), MB_BLOCK_SIZE * sizeof (imgpel)); + for (j = 0; j < MB_BLOCK_SIZE; j += 4) { + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), + MB_BLOCK_SIZE * sizeof(imgpel)); + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), + MB_BLOCK_SIZE * sizeof(imgpel)); + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), + MB_BLOCK_SIZE * sizeof(imgpel)); + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), + MB_BLOCK_SIZE * sizeof(imgpel)); } } @@ -806,58 +758,59 @@ void copy_image_data_16x16(imgpel **imgBuf1, imgpel **imgBuf2, int off1, int o * Copy ImgPel Data from one structure to another (8x8) ************************************************************************************* */ -void copy_image_data_8x8(imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2) -{ +void copy_image_data_8x8(imgpel **imgBuf1, imgpel **imgBuf2, int off1, + int off2) { int j; - for(j = 0; j < BLOCK_SIZE_8x8; j+=4) - { - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE_8x8 * sizeof (imgpel)); - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE_8x8 * sizeof (imgpel)); - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE_8x8 * sizeof (imgpel)); - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE_8x8 * sizeof (imgpel)); + for (j = 0; j < BLOCK_SIZE_8x8; j += 4) { + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), + BLOCK_SIZE_8x8 * sizeof(imgpel)); + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), + BLOCK_SIZE_8x8 * sizeof(imgpel)); + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), + BLOCK_SIZE_8x8 * sizeof(imgpel)); + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), + BLOCK_SIZE_8x8 * sizeof(imgpel)); } } - /*! ************************************************************************************* * \brief * Copy ImgPel Data from one structure to another (4x4) ************************************************************************************* */ -void copy_image_data_4x4(imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2) -{ - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE * sizeof (imgpel)); - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE * sizeof (imgpel)); - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE * sizeof (imgpel)); - memcpy((*imgBuf1 + off1), (*imgBuf2 + off2), BLOCK_SIZE * sizeof (imgpel)); +void copy_image_data_4x4(imgpel **imgBuf1, imgpel **imgBuf2, int off1, + int off2) { + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE * sizeof(imgpel)); + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE * sizeof(imgpel)); + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), BLOCK_SIZE * sizeof(imgpel)); + memcpy((*imgBuf1 + off1), (*imgBuf2 + off2), BLOCK_SIZE * sizeof(imgpel)); } -int CheckVertMV(Macroblock *currMB, int vec1_y, int block_size_y) -{ - VideoParameters *p_Vid = currMB->p_Vid; +int CheckVertMV(Macroblock *currMB, int vec1_y, int block_size_y) { + VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currMB->p_Slice->dec_picture; - int y_pos = vec1_y>>2; - int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 : dec_picture->size_y_m1; + int y_pos = vec1_y >> 2; + int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 + : dec_picture->size_y_m1; - if(y_pos < (-p_Vid->iLumaPadY + 2) || y_pos > (maxold_y + p_Vid->iLumaPadY - block_size_y - 2)) + if (y_pos < (-p_Vid->iLumaPadY + 2) || + y_pos > (maxold_y + p_Vid->iLumaPadY - block_size_y - 2)) return 1; else return 0; } - /*! ************************************************************************************* * \brief * Copy ImgPel Data from one structure to another (8x8) ************************************************************************************* */ -void copy_image_data(imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2, int width, int height) -{ +void copy_image_data(imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2, + int width, int height) { int j; - for(j = 0; j < height; ++j) - { - memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), width * sizeof (imgpel)); + for (j = 0; j < height; ++j) { + memcpy((*imgBuf1++ + off1), (*imgBuf2++ + off2), width * sizeof(imgpel)); } } diff --git a/src/common/ldecod_src/cabac.c b/src/common/ldecod_src/cabac.c index 6f47ccd..04c947f 100644 --- a/src/common/ldecod_src/cabac.c +++ b/src/common/ldecod_src/cabac.c @@ -6,66 +6,85 @@ * CABAC entropy coding routines * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Detlev Marpe ************************************************************************************** */ -#include "global.h" #include "cabac.h" -#include "memalloc.h" -#include "elements.h" -#include "image.h" #include "biaridecod.h" +#include "elements.h" +#include "global.h" +#include "image.h" #include "mb_access.h" +#include "memalloc.h" #include "vlc.h" #if TRACE int symbolCount = 0; #endif -static const short maxpos [] = {15, 14, 63, 31, 31, 15, 3, 14, 7, 15, 15, 14, 63, 31, 31, 15, 15, 14, 63, 31, 31, 15}; -static const short c1isdc [] = { 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1}; -static const short type2ctx_bcbp[] = { 0, 1, 2, 3, 3, 4, 5, 6, 5, 5, 10, 11, 12, 13, 13, 14, 16, 17, 18, 19, 19, 20}; -static const short type2ctx_map [] = { 0, 1, 2, 3, 4, 5, 6, 7, 6, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; // 8 -static const short type2ctx_last[] = { 0, 1, 2, 3, 4, 5, 6, 7, 6, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; // 8 -static const short type2ctx_one [] = { 0, 1, 2, 3, 3, 4, 5, 6, 5, 5, 10, 11, 12, 13, 13, 14, 16, 17, 18, 19, 19, 20}; // 7 -static const short type2ctx_abs [] = { 0, 1, 2, 3, 3, 4, 5, 6, 5, 5, 10, 11, 12, 13, 13, 14, 16, 17, 18, 19, 19, 20}; // 7 -static const short max_c2 [] = { 4, 4, 4, 4, 4, 4, 3, 4, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}; // 9 +static const short maxpos[] = {15, 14, 63, 31, 31, 15, 3, 14, 7, 15, 15, + 14, 63, 31, 31, 15, 15, 14, 63, 31, 31, 15}; +static const short c1isdc[] = {1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1}; +static const short type2ctx_bcbp[] = {0, 1, 2, 3, 3, 4, 5, 6, + 5, 5, 10, 11, 12, 13, 13, 14, + 16, 17, 18, 19, 19, 20}; +static const short type2ctx_map[] = {0, 1, 2, 3, 4, 5, 6, 7, + 6, 6, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21}; // 8 +static const short type2ctx_last[] = {0, 1, 2, 3, 4, 5, 6, 7, + 6, 6, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21}; // 8 +static const short type2ctx_one[] = {0, 1, 2, 3, 3, 4, 5, 6, + 5, 5, 10, 11, 12, 13, 13, 14, + 16, 17, 18, 19, 19, 20}; // 7 +static const short type2ctx_abs[] = {0, 1, 2, 3, 3, 4, 5, 6, + 5, 5, 10, 11, 12, 13, 13, 14, + 16, 17, 18, 19, 19, 20}; // 7 +static const short max_c2[] = {4, 4, 4, 4, 4, 4, 3, 4, 3, 3, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}; // 9 /*********************************************************************** * L O C A L L Y D E F I N E D F U N C T I O N P R O T O T Y P E S *********************************************************************** */ -static unsigned int unary_bin_decode ( DecodingEnvironmentPtr dep_dp, BiContextTypePtr ctx, int ctx_offset); -static unsigned int unary_bin_max_decode ( DecodingEnvironmentPtr dep_dp, BiContextTypePtr ctx, int ctx_offset, unsigned int max_symbol); -static unsigned int unary_exp_golomb_level_decode( DecodingEnvironmentPtr dep_dp, BiContextTypePtr ctx); -static unsigned int unary_exp_golomb_mv_decode ( DecodingEnvironmentPtr dep_dp, BiContextTypePtr ctx, unsigned int max_bin); +static unsigned int unary_bin_decode(DecodingEnvironmentPtr dep_dp, + BiContextTypePtr ctx, int ctx_offset); +static unsigned int unary_bin_max_decode(DecodingEnvironmentPtr dep_dp, + BiContextTypePtr ctx, int ctx_offset, + unsigned int max_symbol); +static unsigned int unary_exp_golomb_level_decode(DecodingEnvironmentPtr dep_dp, + BiContextTypePtr ctx); +static unsigned int unary_exp_golomb_mv_decode(DecodingEnvironmentPtr dep_dp, + BiContextTypePtr ctx, + unsigned int max_bin); -void CheckAvailabilityOfNeighborsCABAC(Macroblock *currMB) -{ +void CheckAvailabilityOfNeighborsCABAC(Macroblock *currMB) { VideoParameters *p_Vid = currMB->p_Vid; PixelPos up, left; int *mb_size = p_Vid->mb_size[IS_LUMA]; - p_Vid->getNeighbour(currMB, -1, 0, mb_size, &left); - p_Vid->getNeighbour(currMB, 0, -1, mb_size, &up); + p_Vid->getNeighbour(currMB, -1, 0, mb_size, &left); + p_Vid->getNeighbour(currMB, 0, -1, mb_size, &up); if (up.available) - currMB->mb_up = &currMB->p_Slice->mb_data[up.mb_addr]; //&p_Vid->mb_data[up.mb_addr]; + currMB->mb_up = + &currMB->p_Slice->mb_data[up.mb_addr]; //&p_Vid->mb_data[up.mb_addr]; else currMB->mb_up = NULL; if (left.available) - currMB->mb_left = &currMB->p_Slice->mb_data[left.mb_addr]; //&p_Vid->mb_data[left.mb_addr]; + currMB->mb_left = + &currMB->p_Slice + ->mb_data[left.mb_addr]; //&p_Vid->mb_data[left.mb_addr]; else currMB->mb_left = NULL; } -void cabac_new_slice(Slice *currSlice) -{ - currSlice->last_dquant = 0; -} +void cabac_new_slice(Slice *currSlice) { currSlice->last_dquant = 0; } /*! ************************************************************************ @@ -75,18 +94,16 @@ void cabac_new_slice(Slice *currSlice) * ************************************************************************ */ -MotionInfoContexts* create_contexts_MotionInfo(void) -{ +MotionInfoContexts *create_contexts_MotionInfo(void) { MotionInfoContexts *deco_ctx; - deco_ctx = (MotionInfoContexts*) calloc(1, sizeof(MotionInfoContexts) ); - if( deco_ctx == NULL ) + deco_ctx = (MotionInfoContexts *)calloc(1, sizeof(MotionInfoContexts)); + if (deco_ctx == NULL) no_mem_exit("create_contexts_MotionInfo: deco_ctx"); return deco_ctx; } - /*! ************************************************************************ * \brief @@ -94,18 +111,16 @@ MotionInfoContexts* create_contexts_MotionInfo(void) * used for arithmetic decoding ************************************************************************ */ -TextureInfoContexts* create_contexts_TextureInfo(void) -{ +TextureInfoContexts *create_contexts_TextureInfo(void) { TextureInfoContexts *deco_ctx; - deco_ctx = (TextureInfoContexts*) calloc(1, sizeof(TextureInfoContexts) ); - if( deco_ctx == NULL ) + deco_ctx = (TextureInfoContexts *)calloc(1, sizeof(TextureInfoContexts)); + if (deco_ctx == NULL) no_mem_exit("create_contexts_TextureInfo: deco_ctx"); return deco_ctx; } - /*! ************************************************************************ * \brief @@ -113,15 +128,13 @@ TextureInfoContexts* create_contexts_TextureInfo(void) * used for arithmetic decoding of the motion info. ************************************************************************ */ -void delete_contexts_MotionInfo(MotionInfoContexts *deco_ctx) -{ - if( deco_ctx == NULL ) +void delete_contexts_MotionInfo(MotionInfoContexts *deco_ctx) { + if (deco_ctx == NULL) return; - free( deco_ctx ); + free(deco_ctx); } - /*! ************************************************************************ * \brief @@ -129,210 +142,220 @@ void delete_contexts_MotionInfo(MotionInfoContexts *deco_ctx) * used for arithmetic decoding of the texture info. ************************************************************************ */ -void delete_contexts_TextureInfo(TextureInfoContexts *deco_ctx) -{ - if( deco_ctx == NULL ) +void delete_contexts_TextureInfo(TextureInfoContexts *deco_ctx) { + if (deco_ctx == NULL) return; - free( deco_ctx ); + free(deco_ctx); } -void readFieldModeInfo_CABAC(Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readFieldModeInfo_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; - //VideoParameters *p_Vid = currMB->p_Vid; - MotionInfoContexts *ctx = currSlice->mot_ctx; + // VideoParameters *p_Vid = currMB->p_Vid; + MotionInfoContexts *ctx = currSlice->mot_ctx; int a = currMB->mbAvailA ? currSlice->mb_data[currMB->mbAddrA].mb_field : 0; int b = currMB->mbAvailB ? currSlice->mb_data[currMB->mbAddrB].mb_field : 0; int act_ctx = a + b; - se->value1 = biari_decode_symbol (dep_dp, &ctx->mb_aff_contexts[act_ctx]); + se->value1 = biari_decode_symbol(dep_dp, &ctx->mb_aff_contexts[act_ctx]); #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } - -int check_next_mb_and_get_field_mode_CABAC_p_slice( Slice *currSlice, - SyntaxElement *se, - DataPartition *act_dp) -{ +int check_next_mb_and_get_field_mode_CABAC_p_slice(Slice *currSlice, + SyntaxElement *se, + DataPartition *act_dp) { VideoParameters *p_Vid = currSlice->p_Vid; - BiContextTypePtr mb_type_ctx_copy[3]; - BiContextTypePtr mb_aff_ctx_copy; - DecodingEnvironmentPtr dep_dp_copy; - MotionInfoContexts *mot_ctx = currSlice->mot_ctx; + BiContextTypePtr mb_type_ctx_copy[3]; + BiContextTypePtr mb_aff_ctx_copy; + DecodingEnvironmentPtr dep_dp_copy; + MotionInfoContexts *mot_ctx = currSlice->mot_ctx; int length; - DecodingEnvironmentPtr dep_dp = &(act_dp->de_cabac); + DecodingEnvironmentPtr dep_dp = &(act_dp->de_cabac); - int skip = 0; - int field = 0; + int skip = 0; + int field = 0; int i; Macroblock *currMB; - //get next MB + // get next MB ++currSlice->current_mb_nr; // ++p_Vid->current_mb_nr; - + currMB = &currSlice->mb_data[currSlice->current_mb_nr]; - currMB->p_Vid = p_Vid; - currMB->p_Slice = currSlice; + currMB->p_Vid = p_Vid; + currMB->p_Slice = currSlice; currMB->slice_nr = currSlice->current_slice_nr; - currMB->mb_field = currSlice->mb_data[currSlice->current_mb_nr-1].mb_field; - currMB->mbAddrX = currSlice->current_mb_nr; - currMB->list_offset = ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? (currMB->mbAddrX&0x01) ? 4 : 2 : 0; + currMB->mb_field = currSlice->mb_data[currSlice->current_mb_nr - 1].mb_field; + currMB->mbAddrX = currSlice->current_mb_nr; + currMB->list_offset = ((currSlice->mb_aff_frame_flag) && (currMB->mb_field)) + ? (currMB->mbAddrX & 0x01) ? 4 : 2 + : 0; CheckAvailabilityOfNeighbors(currMB); CheckAvailabilityOfNeighborsCABAC(currMB); - //create - dep_dp_copy = (DecodingEnvironmentPtr) calloc(1, sizeof(DecodingEnvironment) ); - for (i=0;i<3;++i) - mb_type_ctx_copy[i] = (BiContextTypePtr) calloc(NUM_MB_TYPE_CTX, sizeof(BiContextType) ); - mb_aff_ctx_copy = (BiContextTypePtr) calloc(NUM_MB_AFF_CTX, sizeof(BiContextType) ); + // create + dep_dp_copy = (DecodingEnvironmentPtr)calloc(1, sizeof(DecodingEnvironment)); + for (i = 0; i < 3; ++i) + mb_type_ctx_copy[i] = + (BiContextTypePtr)calloc(NUM_MB_TYPE_CTX, sizeof(BiContextType)); + mb_aff_ctx_copy = + (BiContextTypePtr)calloc(NUM_MB_AFF_CTX, sizeof(BiContextType)); - //copy - memcpy(dep_dp_copy,dep_dp,sizeof(DecodingEnvironment)); + // copy + memcpy(dep_dp_copy, dep_dp, sizeof(DecodingEnvironment)); length = *(dep_dp_copy->Dcodestrm_len) = *(dep_dp->Dcodestrm_len); - for (i=0;i<3;++i) - memcpy(mb_type_ctx_copy[i], mot_ctx->mb_type_contexts[i],NUM_MB_TYPE_CTX*sizeof(BiContextType) ); - memcpy(mb_aff_ctx_copy, mot_ctx->mb_aff_contexts,NUM_MB_AFF_CTX*sizeof(BiContextType) ); + for (i = 0; i < 3; ++i) + memcpy(mb_type_ctx_copy[i], mot_ctx->mb_type_contexts[i], + NUM_MB_TYPE_CTX * sizeof(BiContextType)); + memcpy(mb_aff_ctx_copy, mot_ctx->mb_aff_contexts, + NUM_MB_AFF_CTX * sizeof(BiContextType)); - //check_next_mb + // check_next_mb #if TRACE - strncpy(se->tracestring, "mb_skip_flag (of following bottom MB)", TRACESTRING_SIZE); + strncpy(se->tracestring, "mb_skip_flag (of following bottom MB)", + TRACESTRING_SIZE); #endif currSlice->last_dquant = 0; read_skip_flag_CABAC_p_slice(currMB, se, dep_dp); - skip = (se->value1==0); + skip = (se->value1 == 0); - if (!skip) - { + if (!skip) { #if TRACE - strncpy(se->tracestring, "mb_field_decoding_flag (of following bottom MB)", TRACESTRING_SIZE); + strncpy(se->tracestring, "mb_field_decoding_flag (of following bottom MB)", + TRACESTRING_SIZE); #endif - readFieldModeInfo_CABAC( currMB, se,dep_dp); + readFieldModeInfo_CABAC(currMB, se, dep_dp); field = se->value1; - currSlice->mb_data[currSlice->current_mb_nr-1].mb_field = field; + currSlice->mb_data[currSlice->current_mb_nr - 1].mb_field = field; } - //reset + // reset currSlice->current_mb_nr--; - memcpy(dep_dp,dep_dp_copy,sizeof(DecodingEnvironment)); + memcpy(dep_dp, dep_dp_copy, sizeof(DecodingEnvironment)); *(dep_dp->Dcodestrm_len) = length; - for (i=0;i<3;++i) - memcpy(mot_ctx->mb_type_contexts[i],mb_type_ctx_copy[i], NUM_MB_TYPE_CTX*sizeof(BiContextType) ); - memcpy( mot_ctx->mb_aff_contexts,mb_aff_ctx_copy,NUM_MB_AFF_CTX*sizeof(BiContextType) ); + for (i = 0; i < 3; ++i) + memcpy(mot_ctx->mb_type_contexts[i], mb_type_ctx_copy[i], + NUM_MB_TYPE_CTX * sizeof(BiContextType)); + memcpy(mot_ctx->mb_aff_contexts, mb_aff_ctx_copy, + NUM_MB_AFF_CTX * sizeof(BiContextType)); CheckAvailabilityOfNeighborsCABAC(currMB); - //delete + // delete free(dep_dp_copy); - for (i=0;i<3;++i) + for (i = 0; i < 3; ++i) free(mb_type_ctx_copy[i]); free(mb_aff_ctx_copy); return skip; } -int check_next_mb_and_get_field_mode_CABAC_b_slice( Slice *currSlice, - SyntaxElement *se, - DataPartition *act_dp) -{ +int check_next_mb_and_get_field_mode_CABAC_b_slice(Slice *currSlice, + SyntaxElement *se, + DataPartition *act_dp) { VideoParameters *p_Vid = currSlice->p_Vid; - BiContextTypePtr mb_type_ctx_copy[3]; - BiContextTypePtr mb_aff_ctx_copy; - DecodingEnvironmentPtr dep_dp_copy; + BiContextTypePtr mb_type_ctx_copy[3]; + BiContextTypePtr mb_aff_ctx_copy; + DecodingEnvironmentPtr dep_dp_copy; int length; - DecodingEnvironmentPtr dep_dp = &(act_dp->de_cabac); - MotionInfoContexts *mot_ctx = currSlice->mot_ctx; + DecodingEnvironmentPtr dep_dp = &(act_dp->de_cabac); + MotionInfoContexts *mot_ctx = currSlice->mot_ctx; - int skip = 0; - int field = 0; + int skip = 0; + int field = 0; int i; Macroblock *currMB; - //get next MB + // get next MB ++currSlice->current_mb_nr; // ++p_Vid->current_mb_nr; - + currMB = &currSlice->mb_data[currSlice->current_mb_nr]; - currMB->p_Vid = p_Vid; - currMB->p_Slice = currSlice; + currMB->p_Vid = p_Vid; + currMB->p_Slice = currSlice; currMB->slice_nr = currSlice->current_slice_nr; - currMB->mb_field = currSlice->mb_data[currSlice->current_mb_nr-1].mb_field; - currMB->mbAddrX = currSlice->current_mb_nr; - currMB->list_offset = ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? (currMB->mbAddrX & 0x01) ? 4 : 2 : 0; + currMB->mb_field = currSlice->mb_data[currSlice->current_mb_nr - 1].mb_field; + currMB->mbAddrX = currSlice->current_mb_nr; + currMB->list_offset = ((currSlice->mb_aff_frame_flag) && (currMB->mb_field)) + ? (currMB->mbAddrX & 0x01) ? 4 : 2 + : 0; CheckAvailabilityOfNeighbors(currMB); CheckAvailabilityOfNeighborsCABAC(currMB); - //create - dep_dp_copy = (DecodingEnvironmentPtr) calloc(1, sizeof(DecodingEnvironment) ); - for (i=0;i<3;++i) - mb_type_ctx_copy[i] = (BiContextTypePtr) calloc(NUM_MB_TYPE_CTX, sizeof(BiContextType) ); - mb_aff_ctx_copy = (BiContextTypePtr) calloc(NUM_MB_AFF_CTX, sizeof(BiContextType) ); + // create + dep_dp_copy = (DecodingEnvironmentPtr)calloc(1, sizeof(DecodingEnvironment)); + for (i = 0; i < 3; ++i) + mb_type_ctx_copy[i] = + (BiContextTypePtr)calloc(NUM_MB_TYPE_CTX, sizeof(BiContextType)); + mb_aff_ctx_copy = + (BiContextTypePtr)calloc(NUM_MB_AFF_CTX, sizeof(BiContextType)); - //copy - memcpy(dep_dp_copy,dep_dp,sizeof(DecodingEnvironment)); + // copy + memcpy(dep_dp_copy, dep_dp, sizeof(DecodingEnvironment)); length = *(dep_dp_copy->Dcodestrm_len) = *(dep_dp->Dcodestrm_len); - for (i=0;i<3;++i) - memcpy(mb_type_ctx_copy[i], mot_ctx->mb_type_contexts[i],NUM_MB_TYPE_CTX*sizeof(BiContextType) ); + for (i = 0; i < 3; ++i) + memcpy(mb_type_ctx_copy[i], mot_ctx->mb_type_contexts[i], + NUM_MB_TYPE_CTX * sizeof(BiContextType)); - memcpy(mb_aff_ctx_copy, mot_ctx->mb_aff_contexts,NUM_MB_AFF_CTX*sizeof(BiContextType) ); + memcpy(mb_aff_ctx_copy, mot_ctx->mb_aff_contexts, + NUM_MB_AFF_CTX * sizeof(BiContextType)); - //check_next_mb + // check_next_mb #if TRACE - strncpy(se->tracestring, "mb_skip_flag (of following bottom MB)", TRACESTRING_SIZE); + strncpy(se->tracestring, "mb_skip_flag (of following bottom MB)", + TRACESTRING_SIZE); #endif currSlice->last_dquant = 0; read_skip_flag_CABAC_b_slice(currMB, se, dep_dp); - skip = (se->value1==0 && se->value2==0); - if (!skip) - { + skip = (se->value1 == 0 && se->value2 == 0); + if (!skip) { #if TRACE - strncpy(se->tracestring, "mb_field_decoding_flag (of following bottom MB)", TRACESTRING_SIZE); + strncpy(se->tracestring, "mb_field_decoding_flag (of following bottom MB)", + TRACESTRING_SIZE); #endif - readFieldModeInfo_CABAC( currMB, se,dep_dp); + readFieldModeInfo_CABAC(currMB, se, dep_dp); field = se->value1; - currSlice->mb_data[currSlice->current_mb_nr-1].mb_field = field; + currSlice->mb_data[currSlice->current_mb_nr - 1].mb_field = field; } - //reset + // reset currSlice->current_mb_nr--; - memcpy(dep_dp,dep_dp_copy,sizeof(DecodingEnvironment)); + memcpy(dep_dp, dep_dp_copy, sizeof(DecodingEnvironment)); *(dep_dp->Dcodestrm_len) = length; - - for (i=0;i<3;++i) - memcpy(mot_ctx->mb_type_contexts[i],mb_type_ctx_copy[i], NUM_MB_TYPE_CTX * sizeof(BiContextType) ); - memcpy( mot_ctx->mb_aff_contexts, mb_aff_ctx_copy, NUM_MB_AFF_CTX * sizeof(BiContextType) ); + for (i = 0; i < 3; ++i) + memcpy(mot_ctx->mb_type_contexts[i], mb_type_ctx_copy[i], + NUM_MB_TYPE_CTX * sizeof(BiContextType)); + + memcpy(mot_ctx->mb_aff_contexts, mb_aff_ctx_copy, + NUM_MB_AFF_CTX * sizeof(BiContextType)); CheckAvailabilityOfNeighborsCABAC(currMB); - //delete + // delete free(dep_dp_copy); - for (i=0;i<3;++i) + for (i = 0; i < 3; ++i) free(mb_type_ctx_copy[i]); free(mb_aff_ctx_copy); return skip; } - - - /*! ************************************************************************ * \brief @@ -340,10 +363,8 @@ int check_next_mb_and_get_field_mode_CABAC_b_slice( Slice *currSlice, * vector data of a B-frame MB. ************************************************************************ */ -void read_MVD_CABAC( Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void read_MVD_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; MotionInfoContexts *ctx = currSlice->mot_ctx; @@ -351,34 +372,36 @@ void read_MVD_CABAC( Macroblock *currMB, int j = currMB->subblock_y; int a = 0, b = 0; int act_ctx; - int act_sym; + int act_sym; int list_idx = se->value2 & 0x01; int k = (se->value2 >> 1); // MVD component PixelPos block_a, block_b; - get4x4NeighbourBase(currMB, i - 1, j , p_Vid->mb_size[IS_LUMA], &block_a); - if (block_a.available) - { - a = iabs(currSlice->mb_data[block_a.mb_addr].mvd[list_idx][block_a.y][block_a.x][k]); - if (currSlice->mb_aff_frame_flag && (k==1)) - { - if ((currMB->mb_field==0) && (currSlice->mb_data[block_a.mb_addr].mb_field==1)) + get4x4NeighbourBase(currMB, i - 1, j, p_Vid->mb_size[IS_LUMA], &block_a); + if (block_a.available) { + a = iabs(currSlice->mb_data[block_a.mb_addr] + .mvd[list_idx][block_a.y][block_a.x][k]); + if (currSlice->mb_aff_frame_flag && (k == 1)) { + if ((currMB->mb_field == 0) && + (currSlice->mb_data[block_a.mb_addr].mb_field == 1)) a *= 2; - else if ((currMB->mb_field==1) && (currSlice->mb_data[block_a.mb_addr].mb_field==0)) + else if ((currMB->mb_field == 1) && + (currSlice->mb_data[block_a.mb_addr].mb_field == 0)) a /= 2; } } - get4x4NeighbourBase(currMB, i , j - 1, p_Vid->mb_size[IS_LUMA], &block_b); - if (block_b.available) - { - b = iabs(currSlice->mb_data[block_b.mb_addr].mvd[list_idx][block_b.y][block_b.x][k]); - if (currSlice->mb_aff_frame_flag && (k==1)) - { - if ((currMB->mb_field==0) && (currSlice->mb_data[block_b.mb_addr].mb_field==1)) + get4x4NeighbourBase(currMB, i, j - 1, p_Vid->mb_size[IS_LUMA], &block_b); + if (block_b.available) { + b = iabs(currSlice->mb_data[block_b.mb_addr] + .mvd[list_idx][block_b.y][block_b.x][k]); + if (currSlice->mb_aff_frame_flag && (k == 1)) { + if ((currMB->mb_field == 0) && + (currSlice->mb_data[block_b.mb_addr].mb_field == 1)) b *= 2; - else if ((currMB->mb_field==1) && (currSlice->mb_data[block_b.mb_addr].mb_field==0)) + else if ((currMB->mb_field == 1) && + (currSlice->mb_data[block_b.mb_addr].mb_field == 0)) b /= 2; } } @@ -393,131 +416,113 @@ void read_MVD_CABAC( Macroblock *currMB, se->context = act_ctx; - act_sym = biari_decode_symbol(dep_dp,&ctx->mv_res_contexts[0][act_ctx] ); + act_sym = biari_decode_symbol(dep_dp, &ctx->mv_res_contexts[0][act_ctx]); - if (act_sym != 0) - { + if (act_sym != 0) { act_ctx = 5 * k; - act_sym = unary_exp_golomb_mv_decode(dep_dp, ctx->mv_res_contexts[1] + act_ctx, 3) + 1; + act_sym = unary_exp_golomb_mv_decode(dep_dp, + ctx->mv_res_contexts[1] + act_ctx, 3) + + 1; - if(biari_decode_symbol_eq_prob(dep_dp)) + if (biari_decode_symbol_eq_prob(dep_dp)) act_sym = -act_sym; } se->value1 = act_sym; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } - /*! ************************************************************************ * \brief * This function is used to arithmetically decode the 8x8 block type. ************************************************************************ */ -void readB8_typeInfo_CABAC_p_slice (Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readB8_typeInfo_CABAC_p_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; int act_sym = 0; MotionInfoContexts *ctx = currSlice->mot_ctx; BiContextType *b8_type_contexts = &ctx->b8_type_contexts[0][1]; - if (biari_decode_symbol (dep_dp, b8_type_contexts++)) + if (biari_decode_symbol(dep_dp, b8_type_contexts++)) act_sym = 0; - else - { - if (biari_decode_symbol (dep_dp, ++b8_type_contexts)) - { - if (biari_decode_symbol (dep_dp, ++b8_type_contexts)) + else { + if (biari_decode_symbol(dep_dp, ++b8_type_contexts)) { + if (biari_decode_symbol(dep_dp, ++b8_type_contexts)) act_sym = 2; else act_sym = 3; - } - else - { + } else { act_sym = 1; } - } + } se->value1 = act_sym; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } - /*! ************************************************************************ * \brief * This function is used to arithmetically decode the 8x8 block type. ************************************************************************ */ -void readB8_typeInfo_CABAC_b_slice (Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readB8_typeInfo_CABAC_b_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; int act_sym = 0; MotionInfoContexts *ctx = currSlice->mot_ctx; BiContextType *b8_type_contexts = ctx->b8_type_contexts[1]; - if (biari_decode_symbol (dep_dp, b8_type_contexts++)) - { - if (biari_decode_symbol (dep_dp, b8_type_contexts++)) - { - if (biari_decode_symbol (dep_dp, b8_type_contexts++)) - { - if (biari_decode_symbol (dep_dp, b8_type_contexts)) - { + if (biari_decode_symbol(dep_dp, b8_type_contexts++)) { + if (biari_decode_symbol(dep_dp, b8_type_contexts++)) { + if (biari_decode_symbol(dep_dp, b8_type_contexts++)) { + if (biari_decode_symbol(dep_dp, b8_type_contexts)) { act_sym = 10; - if (biari_decode_symbol (dep_dp, b8_type_contexts)) + if (biari_decode_symbol(dep_dp, b8_type_contexts)) act_sym++; - } - else - { + } else { act_sym = 6; - if (biari_decode_symbol (dep_dp, b8_type_contexts)) + if (biari_decode_symbol(dep_dp, b8_type_contexts)) act_sym += 2; - if (biari_decode_symbol (dep_dp, b8_type_contexts)) + if (biari_decode_symbol(dep_dp, b8_type_contexts)) act_sym++; } - } - else - { + } else { act_sym = 2; - if (biari_decode_symbol (dep_dp, b8_type_contexts)) + if (biari_decode_symbol(dep_dp, b8_type_contexts)) act_sym += 2; - if (biari_decode_symbol (dep_dp, b8_type_contexts)) + if (biari_decode_symbol(dep_dp, b8_type_contexts)) act_sym += 1; } - } - else - { - if (biari_decode_symbol (dep_dp, ++b8_type_contexts)) + } else { + if (biari_decode_symbol(dep_dp, ++b8_type_contexts)) act_sym = 1; - else + else act_sym = 0; } ++act_sym; - } - else - { + } else { act_sym = 0; } se->value1 = act_sym; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } @@ -529,14 +534,12 @@ void readB8_typeInfo_CABAC_b_slice (Macroblock *currMB, * type info of a given MB. ************************************************************************ */ -void read_skip_flag_CABAC_p_slice( Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void read_skip_flag_CABAC_p_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; - MotionInfoContexts *ctx = currSlice->mot_ctx; + MotionInfoContexts *ctx = currSlice->mot_ctx; int a = (currMB->mb_left != NULL) ? (currMB->mb_left->skip_flag == 0) : 0; - int b = (currMB->mb_up != NULL) ? (currMB->mb_up ->skip_flag == 0) : 0; + int b = (currMB->mb_up != NULL) ? (currMB->mb_up->skip_flag == 0) : 0; int act_ctx = a + b; if (biari_decode_symbol(dep_dp, &ctx->mb_type_contexts[1][act_ctx]) == 1) @@ -545,11 +548,11 @@ void read_skip_flag_CABAC_p_slice( Macroblock *currMB, se->value1 = 1; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif - if (!se->value1) - { + if (!se->value1) { currSlice->last_dquant = 0; } } @@ -561,27 +564,25 @@ void read_skip_flag_CABAC_p_slice( Macroblock *currMB, * type info of a given MB. ************************************************************************ */ -void read_skip_flag_CABAC_b_slice( Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void read_skip_flag_CABAC_b_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; - MotionInfoContexts *ctx = currSlice->mot_ctx; + MotionInfoContexts *ctx = currSlice->mot_ctx; int a = (currMB->mb_left != NULL) ? (currMB->mb_left->skip_flag == 0) : 0; - int b = (currMB->mb_up != NULL) ? (currMB->mb_up ->skip_flag == 0) : 0; + int b = (currMB->mb_up != NULL) ? (currMB->mb_up->skip_flag == 0) : 0; int act_ctx = 7 + a + b; - if (biari_decode_symbol (dep_dp, &ctx->mb_type_contexts[2][act_ctx]) == 1) + if (biari_decode_symbol(dep_dp, &ctx->mb_type_contexts[2][act_ctx]) == 1) se->value1 = se->value2 = 0; else - se->value1 = se->value2 = 1; + se->value1 = se->value2 = 1; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif - if (!se->value1) - { + if (!se->value1) { currSlice->last_dquant = 0; } } @@ -594,26 +595,28 @@ void read_skip_flag_CABAC_b_slice( Macroblock *currMB, *************************************************************************** */ -void readMB_transform_size_flag_CABAC( Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readMB_transform_size_flag_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; - TextureInfoContexts*ctx = currSlice->tex_ctx; + TextureInfoContexts *ctx = currSlice->tex_ctx; - int b = (currMB->mb_up == NULL) ? 0 : currMB->mb_up->luma_transform_size_8x8_flag; - int a = (currMB->mb_left == NULL) ? 0 : currMB->mb_left->luma_transform_size_8x8_flag; + int b = + (currMB->mb_up == NULL) ? 0 : currMB->mb_up->luma_transform_size_8x8_flag; + int a = (currMB->mb_left == NULL) + ? 0 + : currMB->mb_left->luma_transform_size_8x8_flag; int act_ctx = a + b; - int act_sym = biari_decode_symbol(dep_dp, ctx->transform_size_contexts + act_ctx ); + int act_sym = + biari_decode_symbol(dep_dp, ctx->transform_size_contexts + act_ctx); se->value1 = act_sym; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif - } /*! @@ -623,10 +626,8 @@ void readMB_transform_size_flag_CABAC( Macroblock *currMB, * type info of a given MB. ************************************************************************ */ -void readMB_typeInfo_CABAC_i_slice(Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readMB_typeInfo_CABAC_i_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; MotionInfoContexts *ctx = currSlice->mot_ctx; @@ -636,120 +637,124 @@ void readMB_typeInfo_CABAC_i_slice(Macroblock *currMB, int mode_sym; int curr_mb_type = 0; - if(currSlice->slice_type == I_SLICE) // INTRA-frame + if (currSlice->slice_type == I_SLICE) // INTRA-frame { if (currMB->mb_up != NULL) - b = (((currMB->mb_up)->mb_type != I4MB && currMB->mb_up->mb_type != I8MB) ? 1 : 0 ); + b = (((currMB->mb_up)->mb_type != I4MB && currMB->mb_up->mb_type != I8MB) + ? 1 + : 0); if (currMB->mb_left != NULL) - a = (((currMB->mb_left)->mb_type != I4MB && currMB->mb_left->mb_type != I8MB) ? 1 : 0 ); + a = (((currMB->mb_left)->mb_type != I4MB && + currMB->mb_left->mb_type != I8MB) + ? 1 + : 0); act_ctx = a + b; act_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); se->context = act_ctx; // store context - if (act_sym==0) // 4x4 Intra + if (act_sym == 0) // 4x4 Intra { curr_mb_type = act_sym; - } - else // 16x16 Intra + } else // 16x16 Intra { mode_sym = biari_decode_final(dep_dp); - if(mode_sym == 1) - { + if (mode_sym == 1) { curr_mb_type = 25; - } - else - { + } else { act_sym = 1; act_ctx = 4; - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); // decoding of AC/no AC - act_sym += mode_sym*12; + mode_sym = biari_decode_symbol( + dep_dp, ctx->mb_type_contexts[0] + act_ctx); // decoding of AC/no AC + act_sym += mode_sym * 12; act_ctx = 5; // decoding of cbp: 0,1,2 - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); - if (mode_sym!=0) - { - act_ctx=6; - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); - act_sym+=4; - if (mode_sym!=0) - act_sym+=4; + mode_sym = + biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); + if (mode_sym != 0) { + act_ctx = 6; + mode_sym = + biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); + act_sym += 4; + if (mode_sym != 0) + act_sym += 4; } // decoding of I pred-mode: 0,1,2,3 act_ctx = 7; - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); - act_sym += mode_sym*2; + mode_sym = + biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); + act_sym += mode_sym * 2; act_ctx = 8; - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); + mode_sym = + biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); act_sym += mode_sym; curr_mb_type = act_sym; } } - } - else if(currSlice->slice_type == SI_SLICE) // SI-frame + } else if (currSlice->slice_type == SI_SLICE) // SI-frame { // special ctx's for SI4MB if (currMB->mb_up != NULL) - b = (( (currMB->mb_up)->mb_type != SI4MB) ? 1 : 0 ); + b = (((currMB->mb_up)->mb_type != SI4MB) ? 1 : 0); if (currMB->mb_left != NULL) - a = (( (currMB->mb_left)->mb_type != SI4MB) ? 1 : 0 ); + a = (((currMB->mb_left)->mb_type != SI4MB) ? 1 : 0); act_ctx = a + b; act_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[1] + act_ctx); se->context = act_ctx; // store context - if (act_sym==0) // SI 4x4 Intra + if (act_sym == 0) // SI 4x4 Intra { curr_mb_type = 0; - } - else // analog INTRA_IMG + } else // analog INTRA_IMG { if (currMB->mb_up != NULL) - b = (( (currMB->mb_up)->mb_type != I4MB) ? 1 : 0 ); + b = (((currMB->mb_up)->mb_type != I4MB) ? 1 : 0); if (currMB->mb_left != NULL) - a = (( (currMB->mb_left)->mb_type != I4MB) ? 1 : 0 ); + a = (((currMB->mb_left)->mb_type != I4MB) ? 1 : 0); act_ctx = a + b; act_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); se->context = act_ctx; // store context - if (act_sym==0) // 4x4 Intra + if (act_sym == 0) // 4x4 Intra { curr_mb_type = 1; - } - else // 16x16 Intra + } else // 16x16 Intra { mode_sym = biari_decode_final(dep_dp); - if( mode_sym==1 ) - { + if (mode_sym == 1) { curr_mb_type = 26; - } - else - { + } else { act_sym = 2; act_ctx = 4; - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); // decoding of AC/no AC - act_sym += mode_sym*12; + mode_sym = + biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + + act_ctx); // decoding of AC/no AC + act_sym += mode_sym * 12; act_ctx = 5; // decoding of cbp: 0,1,2 - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); - if (mode_sym!=0) - { - act_ctx=6; - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); - act_sym+=4; - if (mode_sym!=0) - act_sym+=4; + mode_sym = + biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); + if (mode_sym != 0) { + act_ctx = 6; + mode_sym = + biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); + act_sym += 4; + if (mode_sym != 0) + act_sym += 4; } // decoding of I pred-mode: 0,1,2,3 act_ctx = 7; - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); - act_sym += mode_sym*2; + mode_sym = + biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); + act_sym += mode_sym * 2; act_ctx = 8; - mode_sym = biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx ); + mode_sym = + biari_decode_symbol(dep_dp, ctx->mb_type_contexts[0] + act_ctx); act_sym += mode_sym; curr_mb_type = act_sym; } @@ -760,12 +765,12 @@ void readMB_typeInfo_CABAC_i_slice(Macroblock *currMB, se->value1 = curr_mb_type; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } - /*! ************************************************************************ * \brief @@ -773,10 +778,8 @@ void readMB_typeInfo_CABAC_i_slice(Macroblock *currMB, * type info of a given MB. ************************************************************************ */ -void readMB_typeInfo_CABAC_p_slice(Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readMB_typeInfo_CABAC_p_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; MotionInfoContexts *ctx = currSlice->mot_ctx; @@ -786,64 +789,53 @@ void readMB_typeInfo_CABAC_p_slice(Macroblock *currMB, int curr_mb_type; BiContextType *mb_type_contexts = ctx->mb_type_contexts[1]; - if (biari_decode_symbol(dep_dp, &mb_type_contexts[4] )) - { - if (biari_decode_symbol(dep_dp, &mb_type_contexts[7] )) + if (biari_decode_symbol(dep_dp, &mb_type_contexts[4])) { + if (biari_decode_symbol(dep_dp, &mb_type_contexts[7])) act_sym = 7; - else + else act_sym = 6; - } - else - { - if (biari_decode_symbol(dep_dp, &mb_type_contexts[5] )) - { - if (biari_decode_symbol(dep_dp, &mb_type_contexts[7] )) + } else { + if (biari_decode_symbol(dep_dp, &mb_type_contexts[5])) { + if (biari_decode_symbol(dep_dp, &mb_type_contexts[7])) act_sym = 2; else act_sym = 3; - } - else - { - if (biari_decode_symbol(dep_dp, &mb_type_contexts[6] )) + } else { + if (biari_decode_symbol(dep_dp, &mb_type_contexts[6])) act_sym = 4; - else + else act_sym = 1; } } - if (act_sym <= 6) - { + if (act_sym <= 6) { curr_mb_type = act_sym; - } - else // additional info for 16x16 Intra-mode + } else // additional info for 16x16 Intra-mode { mode_sym = biari_decode_final(dep_dp); - if( mode_sym==1 ) - { + if (mode_sym == 1) { curr_mb_type = 31; - } - else - { + } else { act_ctx = 8; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); // decoding of AC/no AC - act_sym += mode_sym*12; + mode_sym = biari_decode_symbol( + dep_dp, mb_type_contexts + act_ctx); // decoding of AC/no AC + act_sym += mode_sym * 12; // decoding of cbp: 0,1,2 act_ctx = 9; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); - if (mode_sym != 0) - { - act_sym+=4; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); + mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx); + if (mode_sym != 0) { + act_sym += 4; + mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx); if (mode_sym != 0) - act_sym+=4; + act_sym += 4; } // decoding of I pred-mode: 0,1,2,3 act_ctx = 10; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); - act_sym += mode_sym*2; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); + mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx); + act_sym += mode_sym * 2; + mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx); act_sym += mode_sym; curr_mb_type = act_sym; } @@ -852,12 +844,12 @@ void readMB_typeInfo_CABAC_p_slice(Macroblock *currMB, se->value1 = curr_mb_type; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } - /*! ************************************************************************ * \brief @@ -865,10 +857,8 @@ void readMB_typeInfo_CABAC_p_slice(Macroblock *currMB, * type info of a given MB. ************************************************************************ */ -void readMB_typeInfo_CABAC_b_slice(Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readMB_typeInfo_CABAC_b_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; MotionInfoContexts *ctx = currSlice->mot_ctx; @@ -880,98 +870,82 @@ void readMB_typeInfo_CABAC_b_slice(Macroblock *currMB, BiContextType *mb_type_contexts = ctx->mb_type_contexts[2]; if (currMB->mb_up != NULL) - b = (( (currMB->mb_up)->mb_type != 0) ? 1 : 0 ); + b = (((currMB->mb_up)->mb_type != 0) ? 1 : 0); if (currMB->mb_left != NULL) - a = (( (currMB->mb_left)->mb_type != 0) ? 1 : 0 ); + a = (((currMB->mb_left)->mb_type != 0) ? 1 : 0); act_ctx = a + b; - if (biari_decode_symbol (dep_dp, &mb_type_contexts[act_ctx])) - { - if (biari_decode_symbol (dep_dp, &mb_type_contexts[4])) - { - if (biari_decode_symbol (dep_dp, &mb_type_contexts[5])) - { + if (biari_decode_symbol(dep_dp, &mb_type_contexts[act_ctx])) { + if (biari_decode_symbol(dep_dp, &mb_type_contexts[4])) { + if (biari_decode_symbol(dep_dp, &mb_type_contexts[5])) { act_sym = 12; - if (biari_decode_symbol (dep_dp, &mb_type_contexts[6])) + if (biari_decode_symbol(dep_dp, &mb_type_contexts[6])) act_sym += 8; - if (biari_decode_symbol (dep_dp, &mb_type_contexts[6])) + if (biari_decode_symbol(dep_dp, &mb_type_contexts[6])) act_sym += 4; - if (biari_decode_symbol (dep_dp, &mb_type_contexts[6])) + if (biari_decode_symbol(dep_dp, &mb_type_contexts[6])) act_sym += 2; - if (act_sym == 24) - act_sym=11; - else if (act_sym == 26) + if (act_sym == 24) + act_sym = 11; + else if (act_sym == 26) act_sym = 22; - else - { - if (act_sym == 22) + else { + if (act_sym == 22) act_sym = 23; - if (biari_decode_symbol (dep_dp, &mb_type_contexts[6])) + if (biari_decode_symbol(dep_dp, &mb_type_contexts[6])) act_sym += 1; } - } - else - { + } else { act_sym = 3; - if (biari_decode_symbol (dep_dp, &mb_type_contexts[6])) + if (biari_decode_symbol(dep_dp, &mb_type_contexts[6])) act_sym += 4; - if (biari_decode_symbol (dep_dp, &mb_type_contexts[6])) + if (biari_decode_symbol(dep_dp, &mb_type_contexts[6])) act_sym += 2; - if (biari_decode_symbol (dep_dp, &mb_type_contexts[6])) + if (biari_decode_symbol(dep_dp, &mb_type_contexts[6])) act_sym += 1; } - } - else - { - if (biari_decode_symbol (dep_dp, &mb_type_contexts[6])) - act_sym=2; + } else { + if (biari_decode_symbol(dep_dp, &mb_type_contexts[6])) + act_sym = 2; else - act_sym=1; + act_sym = 1; } - } - else - { + } else { act_sym = 0; } - - if (act_sym <= 23) - { + if (act_sym <= 23) { curr_mb_type = act_sym; - } - else // additional info for 16x16 Intra-mode + } else // additional info for 16x16 Intra-mode { mode_sym = biari_decode_final(dep_dp); - if( mode_sym == 1 ) - { + if (mode_sym == 1) { curr_mb_type = 48; - } - else - { + } else { mb_type_contexts = ctx->mb_type_contexts[1]; act_ctx = 8; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); // decoding of AC/no AC - act_sym += mode_sym*12; + mode_sym = biari_decode_symbol( + dep_dp, mb_type_contexts + act_ctx); // decoding of AC/no AC + act_sym += mode_sym * 12; // decoding of cbp: 0,1,2 act_ctx = 9; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); - if (mode_sym != 0) - { - act_sym+=4; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); + mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx); + if (mode_sym != 0) { + act_sym += 4; + mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx); if (mode_sym != 0) - act_sym+=4; + act_sym += 4; } // decoding of I pred-mode: 0,1,2,3 act_ctx = 10; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); - act_sym += mode_sym*2; - mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx ); + mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx); + act_sym += mode_sym * 2; + mode_sym = biari_decode_symbol(dep_dp, mb_type_contexts + act_ctx); act_sym += mode_sym; curr_mb_type = act_sym; } @@ -980,7 +954,8 @@ void readMB_typeInfo_CABAC_b_slice(Macroblock *currMB, se->value1 = curr_mb_type; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } @@ -992,27 +967,25 @@ void readMB_typeInfo_CABAC_b_slice(Macroblock *currMB, * intra prediction modes of a given MB. ************************************************************************ */ -void readIntraPredMode_CABAC( Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readIntraPredMode_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; - TextureInfoContexts *ctx = currSlice->tex_ctx; + TextureInfoContexts *ctx = currSlice->tex_ctx; // use_most_probable_mode int act_sym = biari_decode_symbol(dep_dp, ctx->ipr_contexts); // remaining_mode_selector if (act_sym == 1) se->value1 = -1; - else - { - se->value1 = (biari_decode_symbol(dep_dp, ctx->ipr_contexts + 1) ); + else { + se->value1 = (biari_decode_symbol(dep_dp, ctx->ipr_contexts + 1)); se->value1 |= (biari_decode_symbol(dep_dp, ctx->ipr_contexts + 1) << 1); se->value1 |= (biari_decode_symbol(dep_dp, ctx->ipr_contexts + 1) << 2); } #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } @@ -1023,74 +996,87 @@ void readIntraPredMode_CABAC( Macroblock *currMB, * parameter of a given MB. ************************************************************************ */ -void readRefFrame_CABAC(Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readRefFrame_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; MotionInfoContexts *ctx = currSlice->mot_ctx; Macroblock *neighborMB = NULL; - int addctx = 0; - int a = 0, b = 0; - int act_ctx; - int act_sym; - int list = se->value2; + int addctx = 0; + int a = 0, b = 0; + int act_ctx; + int act_sym; + int list = se->value2; PixelPos block_a, block_b; - get4x4Neighbour(currMB, currMB->subblock_x - 1, currMB->subblock_y , p_Vid->mb_size[IS_LUMA], &block_a); - get4x4Neighbour(currMB, currMB->subblock_x, currMB->subblock_y - 1, p_Vid->mb_size[IS_LUMA], &block_b); + get4x4Neighbour(currMB, currMB->subblock_x - 1, currMB->subblock_y, + p_Vid->mb_size[IS_LUMA], &block_a); + get4x4Neighbour(currMB, currMB->subblock_x, currMB->subblock_y - 1, + p_Vid->mb_size[IS_LUMA], &block_b); - if (block_b.available) - { - int b8b=((block_b.x >> 1) & 0x01)+(block_b.y & 0x02); + if (block_b.available) { + int b8b = ((block_b.x >> 1) & 0x01) + (block_b.y & 0x02); neighborMB = &currSlice->mb_data[block_b.mb_addr]; - if (!( (neighborMB->mb_type==IPCM) || IS_DIRECT(neighborMB) || (neighborMB->b8mode[b8b]==0 && neighborMB->b8pdir[b8b]==2))) - { - if (currSlice->mb_aff_frame_flag && (currMB->mb_field == FALSE) && (neighborMB->mb_field == TRUE)) - b = (dec_picture->mv_info[block_b.pos_y][block_b.pos_x].ref_idx[list] > 1 ? 2 : 0); + if (!((neighborMB->mb_type == IPCM) || IS_DIRECT(neighborMB) || + (neighborMB->b8mode[b8b] == 0 && neighborMB->b8pdir[b8b] == 2))) { + if (currSlice->mb_aff_frame_flag && (currMB->mb_field == FALSE) && + (neighborMB->mb_field == TRUE)) + b = (dec_picture->mv_info[block_b.pos_y][block_b.pos_x].ref_idx[list] > + 1 + ? 2 + : 0); else - b = (dec_picture->mv_info[block_b.pos_y][block_b.pos_x].ref_idx[list] > 0 ? 2 : 0); + b = (dec_picture->mv_info[block_b.pos_y][block_b.pos_x].ref_idx[list] > + 0 + ? 2 + : 0); } } - if (block_a.available) - { - int b8a=((block_a.x >> 1) & 0x01)+(block_a.y & 0x02); + if (block_a.available) { + int b8a = ((block_a.x >> 1) & 0x01) + (block_a.y & 0x02); neighborMB = &currSlice->mb_data[block_a.mb_addr]; - if (!((neighborMB->mb_type==IPCM) || IS_DIRECT(neighborMB) || (neighborMB->b8mode[b8a]==0 && neighborMB->b8pdir[b8a]==2))) - { - if (currSlice->mb_aff_frame_flag && (currMB->mb_field == FALSE) && (neighborMB->mb_field == 1)) - a = (dec_picture->mv_info[block_a.pos_y][block_a.pos_x].ref_idx[list] > 1 ? 1 : 0); + if (!((neighborMB->mb_type == IPCM) || IS_DIRECT(neighborMB) || + (neighborMB->b8mode[b8a] == 0 && neighborMB->b8pdir[b8a] == 2))) { + if (currSlice->mb_aff_frame_flag && (currMB->mb_field == FALSE) && + (neighborMB->mb_field == 1)) + a = (dec_picture->mv_info[block_a.pos_y][block_a.pos_x].ref_idx[list] > + 1 + ? 1 + : 0); else - a = (dec_picture->mv_info[block_a.pos_y][block_a.pos_x].ref_idx[list] > 0 ? 1 : 0); + a = (dec_picture->mv_info[block_a.pos_y][block_a.pos_x].ref_idx[list] > + 0 + ? 1 + : 0); } } act_ctx = a + b; se->context = act_ctx; // store context - act_sym = biari_decode_symbol(dep_dp,ctx->ref_no_contexts[addctx] + act_ctx ); + act_sym = biari_decode_symbol(dep_dp, ctx->ref_no_contexts[addctx] + act_ctx); - if (act_sym != 0) - { + if (act_sym != 0) { act_ctx = 4; - act_sym = unary_bin_decode(dep_dp,ctx->ref_no_contexts[addctx] + act_ctx,1); + act_sym = + unary_bin_decode(dep_dp, ctx->ref_no_contexts[addctx] + act_ctx, 1); ++act_sym; } se->value1 = act_sym; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); -// fprintf(p_Dec->p_trace," c: %d :%d \n",ctx->ref_no_contexts[addctx][act_ctx].cum_freq[0],ctx->ref_no_contexts[addctx][act_ctx].cum_freq[1]); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); + // fprintf(p_Dec->p_trace," c: %d :%d + // \n",ctx->ref_no_contexts[addctx][act_ctx].cum_freq[0],ctx->ref_no_contexts[addctx][act_ctx].cum_freq[1]); fflush(p_Dec->p_trace); #endif } - /*! ************************************************************************ * \brief @@ -1098,32 +1084,29 @@ void readRefFrame_CABAC(Macroblock *currMB, * of a given MB. ************************************************************************ */ -void read_dQuant_CABAC( Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void read_dQuant_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; MotionInfoContexts *ctx = currSlice->mot_ctx; int *dquant = &se->value1; int act_ctx = ((currSlice->last_dquant != 0) ? 1 : 0); - int act_sym = biari_decode_symbol(dep_dp,ctx->delta_qp_contexts + act_ctx ); + int act_sym = biari_decode_symbol(dep_dp, ctx->delta_qp_contexts + act_ctx); - if (act_sym != 0) - { + if (act_sym != 0) { act_ctx = 2; - act_sym = unary_bin_decode(dep_dp,ctx->delta_qp_contexts + act_ctx,1); + act_sym = unary_bin_decode(dep_dp, ctx->delta_qp_contexts + act_ctx, 1); ++act_sym; *dquant = (act_sym + 1) >> 1; - if((act_sym & 0x01)==0) // lsb is signed bit + if ((act_sym & 0x01) == 0) // lsb is signed bit *dquant = -*dquant; - } - else + } else *dquant = 0; currSlice->last_dquant = *dquant; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } @@ -1134,14 +1117,12 @@ void read_dQuant_CABAC( Macroblock *currMB, * block pattern of a given MB. ************************************************************************ */ -void read_CBP_CABAC(Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void read_CBP_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currMB->p_Slice->dec_picture; Slice *currSlice = currMB->p_Slice; - TextureInfoContexts *ctx = currSlice->tex_ctx; + TextureInfoContexts *ctx = currSlice->tex_ctx; Macroblock *neighborMB = NULL; int mb_x, mb_y; @@ -1153,110 +1134,102 @@ void read_CBP_CABAC(Macroblock *currMB, PixelPos block_a; // coding of luma part (bit by bit) - for (mb_y=0; mb_y < 4; mb_y += 2) - { - if (mb_y == 0) - { + for (mb_y = 0; mb_y < 4; mb_y += 2) { + if (mb_y == 0) { neighborMB = currMB->mb_up; b = 0; } - for (mb_x=0; mb_x < 4; mb_x += 2) - { - if (mb_y == 0) - { - if (neighborMB != NULL) - { - if(neighborMB->mb_type!=IPCM) - b = (( (neighborMB->cbp & (1<<(2 + (mb_x>>1)))) == 0) ? 2 : 0); + for (mb_x = 0; mb_x < 4; mb_x += 2) { + if (mb_y == 0) { + if (neighborMB != NULL) { + if (neighborMB->mb_type != IPCM) + b = (((neighborMB->cbp & (1 << (2 + (mb_x >> 1)))) == 0) ? 2 : 0); } - } - else - b = ( ((cbp & (1<<(mb_x/2))) == 0) ? 2: 0); + } else + b = (((cbp & (1 << (mb_x / 2))) == 0) ? 2 : 0); - if (mb_x == 0) - { - get4x4Neighbour(currMB, (mb_x<<2) - 1, (mb_y << 2), p_Vid->mb_size[IS_LUMA], &block_a); - if (block_a.available) - { - if(currSlice->mb_data[block_a.mb_addr].mb_type==IPCM) + if (mb_x == 0) { + get4x4Neighbour(currMB, (mb_x << 2) - 1, (mb_y << 2), + p_Vid->mb_size[IS_LUMA], &block_a); + if (block_a.available) { + if (currSlice->mb_data[block_a.mb_addr].mb_type == IPCM) a = 0; else - a = (( (currSlice->mb_data[block_a.mb_addr].cbp & (1<<(2*(block_a.y/2)+1))) == 0) ? 1 : 0); - } - else - a=0; - } - else - a = ( ((cbp & (1<mb_data[block_a.mb_addr].cbp & + (1 << (2 * (block_a.y / 2) + 1))) == 0) + ? 1 + : 0); + } else + a = 0; + } else + a = (((cbp & (1 << mb_y)) == 0) ? 1 : 0); curr_cbp_ctx = a + b; mask = (1 << (mb_y + (mb_x >> 1))); - cbp_bit = biari_decode_symbol(dep_dp, ctx->cbp_contexts[0] + curr_cbp_ctx ); - if (cbp_bit) + cbp_bit = + biari_decode_symbol(dep_dp, ctx->cbp_contexts[0] + curr_cbp_ctx); + if (cbp_bit) cbp += mask; } } - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { // coding of chroma part // CABAC decoding for BinIdx 0 b = 0; neighborMB = currMB->mb_up; - if (neighborMB != NULL) - { - if (neighborMB->mb_type==IPCM || (neighborMB->cbp > 15)) + if (neighborMB != NULL) { + if (neighborMB->mb_type == IPCM || (neighborMB->cbp > 15)) b = 2; } a = 0; neighborMB = currMB->mb_left; - if (neighborMB != NULL) - { - if (neighborMB->mb_type==IPCM || (neighborMB->cbp > 15)) + if (neighborMB != NULL) { + if (neighborMB->mb_type == IPCM || (neighborMB->cbp > 15)) a = 1; } curr_cbp_ctx = a + b; - cbp_bit = biari_decode_symbol(dep_dp, ctx->cbp_contexts[1] + curr_cbp_ctx ); + cbp_bit = biari_decode_symbol(dep_dp, ctx->cbp_contexts[1] + curr_cbp_ctx); // CABAC decoding for BinIdx 1 if (cbp_bit) // set the chroma bits { b = 0; neighborMB = currMB->mb_up; - if (neighborMB != NULL) - { - //if ((neighborMB->mb_type == IPCM) || ((neighborMB->cbp > 15) && ((neighborMB->cbp >> 4) == 2))) + if (neighborMB != NULL) { + // if ((neighborMB->mb_type == IPCM) || ((neighborMB->cbp > 15) && + // ((neighborMB->cbp >> 4) == 2))) if ((neighborMB->mb_type == IPCM) || ((neighborMB->cbp >> 4) == 2)) b = 2; } - a = 0; neighborMB = currMB->mb_left; - if (neighborMB != NULL) - { + if (neighborMB != NULL) { if ((neighborMB->mb_type == IPCM) || ((neighborMB->cbp >> 4) == 2)) a = 1; } curr_cbp_ctx = a + b; - cbp_bit = biari_decode_symbol(dep_dp, ctx->cbp_contexts[2] + curr_cbp_ctx ); + cbp_bit = + biari_decode_symbol(dep_dp, ctx->cbp_contexts[2] + curr_cbp_ctx); cbp += (cbp_bit == 1) ? 32 : 16; } } se->value1 = cbp; - if (!cbp) - { + if (!cbp) { currSlice->last_dquant = 0; } #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif } @@ -1268,282 +1241,260 @@ void read_CBP_CABAC(Macroblock *currMB, * intra prediction mode of a given MB. ************************************************************************ */ -void readCIPredMode_CABAC(Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readCIPredMode_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; TextureInfoContexts *ctx = currSlice->tex_ctx; - int *act_sym = &se->value1; + int *act_sym = &se->value1; - Macroblock *MbUp = currMB->mb_up; - Macroblock *MbLeft = currMB->mb_left; + Macroblock *MbUp = currMB->mb_up; + Macroblock *MbLeft = currMB->mb_left; - int b = (MbUp != NULL) ? (((MbUp->c_ipred_mode != 0) && (MbUp->mb_type != IPCM)) ? 1 : 0) : 0; - int a = (MbLeft != NULL) ? (((MbLeft->c_ipred_mode != 0) && (MbLeft->mb_type != IPCM)) ? 1 : 0) : 0; + int b = (MbUp != NULL) + ? (((MbUp->c_ipred_mode != 0) && (MbUp->mb_type != IPCM)) ? 1 : 0) + : 0; + int a = + (MbLeft != NULL) + ? (((MbLeft->c_ipred_mode != 0) && (MbLeft->mb_type != IPCM)) ? 1 : 0) + : 0; int act_ctx = a + b; - *act_sym = biari_decode_symbol(dep_dp, ctx->cipr_contexts + act_ctx ); + *act_sym = biari_decode_symbol(dep_dp, ctx->cipr_contexts + act_ctx); if (*act_sym != 0) *act_sym = unary_bin_max_decode(dep_dp, ctx->cipr_contexts + 3, 0, 1) + 1; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, se->tracestring, se->value1); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, se->tracestring, + se->value1); fflush(p_Dec->p_trace); #endif - } - /*! ************************************************************************ * \brief * Read CBP4-BIT ************************************************************************ -*/ -static int read_and_store_CBP_block_bit_444 (Macroblock *currMB, - DecodingEnvironmentPtr dep_dp, - int type) -{ + */ +static int read_and_store_CBP_block_bit_444(Macroblock *currMB, + DecodingEnvironmentPtr dep_dp, + int type) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; TextureInfoContexts *tex_ctx = currSlice->tex_ctx; Macroblock *mb_data = currSlice->mb_data; - int y_ac = (type==LUMA_16AC || type==LUMA_8x8 || type==LUMA_8x4 || type==LUMA_4x8 || type==LUMA_4x4 - || type==CB_16AC || type==CB_8x8 || type==CB_8x4 || type==CB_4x8 || type==CB_4x4 - || type==CR_16AC || type==CR_8x8 || type==CR_8x4 || type==CR_4x8 || type==CR_4x4); - int y_dc = (type==LUMA_16DC || type==CB_16DC || type==CR_16DC); - int u_ac = (type==CHROMA_AC && !currMB->is_v_block); - int v_ac = (type==CHROMA_AC && currMB->is_v_block); - int chroma_dc = (type==CHROMA_DC || type==CHROMA_DC_2x4 || type==CHROMA_DC_4x4); - int u_dc = (chroma_dc && !currMB->is_v_block); - int v_dc = (chroma_dc && currMB->is_v_block); - int j = (y_ac || u_ac || v_ac ? currMB->subblock_y : 0); - int i = (y_ac || u_ac || v_ac ? currMB->subblock_x : 0); - int bit = (y_dc ? 0 : y_ac ? 1 : u_dc ? 17 : v_dc ? 18 : u_ac ? 19 : 35); + int y_ac = (type == LUMA_16AC || type == LUMA_8x8 || type == LUMA_8x4 || + type == LUMA_4x8 || type == LUMA_4x4 || type == CB_16AC || + type == CB_8x8 || type == CB_8x4 || type == CB_4x8 || + type == CB_4x4 || type == CR_16AC || type == CR_8x8 || + type == CR_8x4 || type == CR_4x8 || type == CR_4x4); + int y_dc = (type == LUMA_16DC || type == CB_16DC || type == CR_16DC); + int u_ac = (type == CHROMA_AC && !currMB->is_v_block); + int v_ac = (type == CHROMA_AC && currMB->is_v_block); + int chroma_dc = + (type == CHROMA_DC || type == CHROMA_DC_2x4 || type == CHROMA_DC_4x4); + int u_dc = (chroma_dc && !currMB->is_v_block); + int v_dc = (chroma_dc && currMB->is_v_block); + int j = (y_ac || u_ac || v_ac ? currMB->subblock_y : 0); + int i = (y_ac || u_ac || v_ac ? currMB->subblock_x : 0); + int bit = (y_dc ? 0 : y_ac ? 1 : u_dc ? 17 : v_dc ? 18 : u_ac ? 19 : 35); int default_bit = (currMB->is_intra_block ? 1 : 0); - int upper_bit = default_bit; - int left_bit = default_bit; - int cbp_bit = 1; // always one for 8x8 mode + int upper_bit = default_bit; + int left_bit = default_bit; + int cbp_bit = 1; // always one for 8x8 mode int ctx; - int bit_pos_a = 0; - int bit_pos_b = 0; - + int bit_pos_a = 0; + int bit_pos_b = 0; + PixelPos block_a, block_b; - if (y_ac) - { - get4x4Neighbour(currMB, i - 1, j , p_Vid->mb_size[IS_LUMA], &block_a); - get4x4Neighbour(currMB, i , j - 1, p_Vid->mb_size[IS_LUMA], &block_b); + if (y_ac) { + get4x4Neighbour(currMB, i - 1, j, p_Vid->mb_size[IS_LUMA], &block_a); + get4x4Neighbour(currMB, i, j - 1, p_Vid->mb_size[IS_LUMA], &block_b); if (block_a.available) - bit_pos_a = 4*block_a.y + block_a.x; - if (block_b.available) - bit_pos_b = 4*block_b.y + block_b.x; - } - else if (y_dc) - { - get4x4Neighbour(currMB, i - 1, j , p_Vid->mb_size[IS_LUMA], &block_a); - get4x4Neighbour(currMB, i , j - 1, p_Vid->mb_size[IS_LUMA], &block_b); - } - else if (u_ac||v_ac) - { - get4x4Neighbour(currMB, i - 1, j , p_Vid->mb_size[IS_CHROMA], &block_a); - get4x4Neighbour(currMB, i , j - 1, p_Vid->mb_size[IS_CHROMA], &block_b); - if (block_a.available) - bit_pos_a = 4*block_a.y + block_a.x; + bit_pos_a = 4 * block_a.y + block_a.x; if (block_b.available) - bit_pos_b = 4*block_b.y + block_b.x; + bit_pos_b = 4 * block_b.y + block_b.x; + } else if (y_dc) { + get4x4Neighbour(currMB, i - 1, j, p_Vid->mb_size[IS_LUMA], &block_a); + get4x4Neighbour(currMB, i, j - 1, p_Vid->mb_size[IS_LUMA], &block_b); + } else if (u_ac || v_ac) { + get4x4Neighbour(currMB, i - 1, j, p_Vid->mb_size[IS_CHROMA], &block_a); + get4x4Neighbour(currMB, i, j - 1, p_Vid->mb_size[IS_CHROMA], &block_b); + if (block_a.available) + bit_pos_a = 4 * block_a.y + block_a.x; + if (block_b.available) + bit_pos_b = 4 * block_b.y + block_b.x; + } else { + get4x4Neighbour(currMB, i - 1, j, p_Vid->mb_size[IS_CHROMA], &block_a); + get4x4Neighbour(currMB, i, j - 1, p_Vid->mb_size[IS_CHROMA], &block_b); } - else - { - get4x4Neighbour(currMB, i - 1, j , p_Vid->mb_size[IS_CHROMA], &block_a); - get4x4Neighbour(currMB, i , j - 1, p_Vid->mb_size[IS_CHROMA], &block_b); - } - - if (dec_picture->chroma_format_idc!=YUV444) - { - if (type!=LUMA_8x8) - { + + if (dec_picture->chroma_format_idc != YUV444) { + if (type != LUMA_8x8) { //--- get bits from neighboring blocks --- - if (block_b.available) - { - if(mb_data[block_b.mb_addr].mb_type==IPCM) - upper_bit=1; - else - upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits[0], bit + bit_pos_b); - } - - if (block_a.available) - { - if(mb_data[block_a.mb_addr].mb_type==IPCM) - left_bit=1; - else - left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits[0],bit + bit_pos_a); - } - - - ctx = 2 * upper_bit + left_bit; - //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); - } - } - else if( (p_Vid->separate_colour_plane_flag != 0) ) - { - if (type!=LUMA_8x8) - { - //--- get bits from neighbouring blocks --- - if (block_b.available) - { - if(mb_data[block_b.mb_addr].mb_type==IPCM) + if (block_b.available) { + if (mb_data[block_b.mb_addr].mb_type == IPCM) upper_bit = 1; else - upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits[0],bit+bit_pos_b); + upper_bit = + get_bit(mb_data[block_b.mb_addr].cbp_bits[0], bit + bit_pos_b); } - - - if (block_a.available) - { - if(mb_data[block_a.mb_addr].mb_type==IPCM) + + if (block_a.available) { + if (mb_data[block_a.mb_addr].mb_type == IPCM) left_bit = 1; else - left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits[0],bit+bit_pos_a); + left_bit = + get_bit(mb_data[block_a.mb_addr].cbp_bits[0], bit + bit_pos_a); } - - - ctx = 2 * upper_bit + left_bit; + + ctx = 2 * upper_bit + left_bit; //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); } - } - else { - if (block_b.available) - { - if(mb_data[block_b.mb_addr].mb_type==IPCM) - upper_bit=1; - else - { - if(type==LUMA_8x8) - upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits_8x8[0], bit + bit_pos_b); - else if (type==CB_8x8) - upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits_8x8[1], bit + bit_pos_b); - else if (type==CR_8x8) - upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits_8x8[2], bit + bit_pos_b); - else if ((type==CB_4x4)||(type==CB_4x8)||(type==CB_8x4)||(type==CB_16AC)||(type==CB_16DC)) - upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits[1],bit+bit_pos_b); - else if ((type==CR_4x4)||(type==CR_4x8)||(type==CR_8x4)||(type==CR_16AC)||(type==CR_16DC)) - upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits[2],bit+bit_pos_b); + } else if ((p_Vid->separate_colour_plane_flag != 0)) { + if (type != LUMA_8x8) { + //--- get bits from neighbouring blocks --- + if (block_b.available) { + if (mb_data[block_b.mb_addr].mb_type == IPCM) + upper_bit = 1; else - upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits[0],bit+bit_pos_b); + upper_bit = + get_bit(mb_data[block_b.mb_addr].cbp_bits[0], bit + bit_pos_b); + } + + if (block_a.available) { + if (mb_data[block_a.mb_addr].mb_type == IPCM) + left_bit = 1; + else + left_bit = + get_bit(mb_data[block_a.mb_addr].cbp_bits[0], bit + bit_pos_a); + } + + ctx = 2 * upper_bit + left_bit; + //===== encode symbol ===== + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + } + } else { + if (block_b.available) { + if (mb_data[block_b.mb_addr].mb_type == IPCM) + upper_bit = 1; + else { + if (type == LUMA_8x8) + upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits_8x8[0], + bit + bit_pos_b); + else if (type == CB_8x8) + upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits_8x8[1], + bit + bit_pos_b); + else if (type == CR_8x8) + upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits_8x8[2], + bit + bit_pos_b); + else if ((type == CB_4x4) || (type == CB_4x8) || (type == CB_8x4) || + (type == CB_16AC) || (type == CB_16DC)) + upper_bit = + get_bit(mb_data[block_b.mb_addr].cbp_bits[1], bit + bit_pos_b); + else if ((type == CR_4x4) || (type == CR_4x8) || (type == CR_8x4) || + (type == CR_16AC) || (type == CR_16DC)) + upper_bit = + get_bit(mb_data[block_b.mb_addr].cbp_bits[2], bit + bit_pos_b); + else + upper_bit = + get_bit(mb_data[block_b.mb_addr].cbp_bits[0], bit + bit_pos_b); } } - - - if (block_a.available) - { - if(mb_data[block_a.mb_addr].mb_type==IPCM) - left_bit=1; - else - { - if(type==LUMA_8x8) - left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits_8x8[0],bit+bit_pos_a); - else if (type==CB_8x8) - left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits_8x8[1],bit+bit_pos_a); - else if (type==CR_8x8) - left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits_8x8[2],bit+bit_pos_a); - else if ((type==CB_4x4)||(type==CB_4x8)||(type==CB_8x4)||(type==CB_16AC)||(type==CB_16DC)) - left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits[1],bit+bit_pos_a); - else if ((type==CR_4x4)||(type==CR_4x8)||(type==CR_8x4)||(type==CR_16AC)||(type==CR_16DC)) - left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits[2],bit+bit_pos_a); + + if (block_a.available) { + if (mb_data[block_a.mb_addr].mb_type == IPCM) + left_bit = 1; + else { + if (type == LUMA_8x8) + left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits_8x8[0], + bit + bit_pos_a); + else if (type == CB_8x8) + left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits_8x8[1], + bit + bit_pos_a); + else if (type == CR_8x8) + left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits_8x8[2], + bit + bit_pos_a); + else if ((type == CB_4x4) || (type == CB_4x8) || (type == CB_8x4) || + (type == CB_16AC) || (type == CB_16DC)) + left_bit = + get_bit(mb_data[block_a.mb_addr].cbp_bits[1], bit + bit_pos_a); + else if ((type == CR_4x4) || (type == CR_4x8) || (type == CR_8x4) || + (type == CR_16AC) || (type == CR_16DC)) + left_bit = + get_bit(mb_data[block_a.mb_addr].cbp_bits[2], bit + bit_pos_a); else - left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits[0],bit+bit_pos_a); + left_bit = + get_bit(mb_data[block_a.mb_addr].cbp_bits[0], bit + bit_pos_a); } } - + ctx = 2 * upper_bit + left_bit; //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); } - - //--- set bits for current block --- - bit = (y_dc ? 0 : y_ac ? 1 + j + (i >> 2) : u_dc ? 17 : v_dc ? 18 : u_ac ? 19 + j + (i >> 2) : 35 + j + (i >> 2)); - if (cbp_bit) - { - if (type==LUMA_8x8) - { - currMB->cbp_bits[0] |= ((int64) 0x33 << bit ); - - if (dec_picture->chroma_format_idc==YUV444) - { - currMB->cbp_bits_8x8[0] |= ((int64) 0x33 << bit ); + //--- set bits for current block --- + bit = (y_dc ? 0 + : y_ac ? 1 + j + (i >> 2) + : u_dc ? 17 + : v_dc ? 18 + : u_ac ? 19 + j + (i >> 2) + : 35 + j + (i >> 2)); + + if (cbp_bit) { + if (type == LUMA_8x8) { + currMB->cbp_bits[0] |= ((int64)0x33 << bit); + + if (dec_picture->chroma_format_idc == YUV444) { + currMB->cbp_bits_8x8[0] |= ((int64)0x33 << bit); } - } - else if (type==CB_8x8) - { - currMB->cbp_bits_8x8[1] |= ((int64) 0x33 << bit ); - currMB->cbp_bits[1] |= ((int64) 0x33 << bit ); - } - else if (type==CR_8x8) - { - currMB->cbp_bits_8x8[2] |= ((int64) 0x33 << bit ); - currMB->cbp_bits[2] |= ((int64) 0x33 << bit ); - } - else if (type==LUMA_8x4) - { - currMB->cbp_bits[0] |= ((int64) 0x03 << bit ); - } - else if (type==CB_8x4) - { - currMB->cbp_bits[1] |= ((int64) 0x03 << bit ); - } - else if (type==CR_8x4) - { - currMB->cbp_bits[2] |= ((int64) 0x03 << bit ); - } - else if (type==LUMA_4x8) - { - currMB->cbp_bits[0] |= ((int64) 0x11<< bit ); - } - else if (type==CB_4x8) - { - currMB->cbp_bits[1] |= ((int64)0x11<< bit ); - } - else if (type==CR_4x8) - { - currMB->cbp_bits[2] |= ((int64)0x11<< bit ); - } - else if ((type==CB_4x4)||(type==CB_16AC)||(type==CB_16DC)) - { - currMB->cbp_bits[1] |= i64_power2(bit); - } - else if ((type==CR_4x4)||(type==CR_16AC)||(type==CR_16DC)) - { - currMB->cbp_bits[2] |= i64_power2(bit); - } - else - { - currMB->cbp_bits[0] |= i64_power2(bit); + } else if (type == CB_8x8) { + currMB->cbp_bits_8x8[1] |= ((int64)0x33 << bit); + currMB->cbp_bits[1] |= ((int64)0x33 << bit); + } else if (type == CR_8x8) { + currMB->cbp_bits_8x8[2] |= ((int64)0x33 << bit); + currMB->cbp_bits[2] |= ((int64)0x33 << bit); + } else if (type == LUMA_8x4) { + currMB->cbp_bits[0] |= ((int64)0x03 << bit); + } else if (type == CB_8x4) { + currMB->cbp_bits[1] |= ((int64)0x03 << bit); + } else if (type == CR_8x4) { + currMB->cbp_bits[2] |= ((int64)0x03 << bit); + } else if (type == LUMA_4x8) { + currMB->cbp_bits[0] |= ((int64)0x11 << bit); + } else if (type == CB_4x8) { + currMB->cbp_bits[1] |= ((int64)0x11 << bit); + } else if (type == CR_4x8) { + currMB->cbp_bits[2] |= ((int64)0x11 << bit); + } else if ((type == CB_4x4) || (type == CB_16AC) || (type == CB_16DC)) { + currMB->cbp_bits[1] |= i64_power2(bit); + } else if ((type == CR_4x4) || (type == CR_16AC) || (type == CR_16DC)) { + currMB->cbp_bits[2] |= i64_power2(bit); + } else { + currMB->cbp_bits[0] |= i64_power2(bit); } } return cbp_bit; } - -static inline int set_cbp_bit(Macroblock *neighbor_mb) -{ - if(neighbor_mb->mb_type == IPCM) - return 1; - else - return (int) (neighbor_mb->cbp_bits[0] & 0x01); -} - -static inline int set_cbp_bit_ac(Macroblock *neighbor_mb, PixelPos *block) -{ +static inline int set_cbp_bit(Macroblock *neighbor_mb) { if (neighbor_mb->mb_type == IPCM) return 1; else - { + return (int)(neighbor_mb->cbp_bits[0] & 0x01); +} + +static inline int set_cbp_bit_ac(Macroblock *neighbor_mb, PixelPos *block) { + if (neighbor_mb->mb_type == IPCM) + return 1; + else { int bit_pos = 1 + (block->y << 2) + block->x; return get_bit(neighbor_mb->cbp_bits[0], bit_pos); } @@ -1555,373 +1506,350 @@ static inline int set_cbp_bit_ac(Macroblock *neighbor_mb, PixelPos *block) * Read CBP4-BIT ************************************************************************ */ -static int read_and_store_CBP_block_bit_normal (Macroblock *currMB, - DecodingEnvironmentPtr dep_dp, - int type) -{ +static int read_and_store_CBP_block_bit_normal(Macroblock *currMB, + DecodingEnvironmentPtr dep_dp, + int type) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; TextureInfoContexts *tex_ctx = currSlice->tex_ctx; - int cbp_bit = 1; // always one for 8x8 mode + int cbp_bit = 1; // always one for 8x8 mode Macroblock *mb_data = currSlice->mb_data; - if (type==LUMA_16DC) - { - int upper_bit = 1; - int left_bit = 1; + if (type == LUMA_16DC) { + int upper_bit = 1; + int left_bit = 1; int ctx; PixelPos block_a, block_b; - get4x4NeighbourBase(currMB, -1, 0, p_Vid->mb_size[IS_LUMA], &block_a); - get4x4NeighbourBase(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &block_b); + get4x4NeighbourBase(currMB, -1, 0, p_Vid->mb_size[IS_LUMA], &block_a); + get4x4NeighbourBase(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &block_b); //--- get bits from neighboring blocks --- - if (block_b.available) - { + if (block_b.available) { upper_bit = set_cbp_bit(&mb_data[block_b.mb_addr]); } - if (block_a.available) - { + if (block_a.available) { left_bit = set_cbp_bit(&mb_data[block_a.mb_addr]); } - ctx = 2 * upper_bit + left_bit; + ctx = 2 * upper_bit + left_bit; //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); //--- set bits for current block --- - if (cbp_bit) - { + if (cbp_bit) { currMB->cbp_bits[0] |= 1; } - } - else if (type==LUMA_16AC) - { - int j = currMB->subblock_y; - int i = currMB->subblock_x; - int bit = 1; + } else if (type == LUMA_16AC) { + int j = currMB->subblock_y; + int i = currMB->subblock_x; + int bit = 1; int default_bit = (currMB->is_intra_block ? 1 : 0); - int upper_bit = default_bit; - int left_bit = default_bit; + int upper_bit = default_bit; + int left_bit = default_bit; int ctx; PixelPos block_a, block_b; - get4x4NeighbourBase(currMB, i - 1, j , p_Vid->mb_size[IS_LUMA], &block_a); - get4x4NeighbourBase(currMB, i , j - 1, p_Vid->mb_size[IS_LUMA], &block_b); + get4x4NeighbourBase(currMB, i - 1, j, p_Vid->mb_size[IS_LUMA], &block_a); + get4x4NeighbourBase(currMB, i, j - 1, p_Vid->mb_size[IS_LUMA], &block_b); //--- get bits from neighboring blocks --- - if (block_b.available) - { + if (block_b.available) { upper_bit = set_cbp_bit_ac(&mb_data[block_b.mb_addr], &block_b); } - if (block_a.available) - { + if (block_a.available) { left_bit = set_cbp_bit_ac(&mb_data[block_a.mb_addr], &block_a); } - ctx = 2 * upper_bit + left_bit; + ctx = 2 * upper_bit + left_bit; //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); - if (cbp_bit) - { + if (cbp_bit) { //--- set bits for current block --- - bit = 1 + j + (i >> 2); - currMB->cbp_bits[0] |= i64_power2(bit); + bit = 1 + j + (i >> 2); + currMB->cbp_bits[0] |= i64_power2(bit); } - } - else if (type==LUMA_8x4) - { - int j = currMB->subblock_y; - int i = currMB->subblock_x; - int bit = 1; + } else if (type == LUMA_8x4) { + int j = currMB->subblock_y; + int i = currMB->subblock_x; + int bit = 1; int default_bit = (currMB->is_intra_block ? 1 : 0); - int upper_bit = default_bit; - int left_bit = default_bit; + int upper_bit = default_bit; + int left_bit = default_bit; int ctx; PixelPos block_a, block_b; - get4x4NeighbourBase(currMB, i - 1, j , p_Vid->mb_size[IS_LUMA], &block_a); - get4x4NeighbourBase(currMB, i , j - 1, p_Vid->mb_size[IS_LUMA], &block_b); + get4x4NeighbourBase(currMB, i - 1, j, p_Vid->mb_size[IS_LUMA], &block_a); + get4x4NeighbourBase(currMB, i, j - 1, p_Vid->mb_size[IS_LUMA], &block_b); //--- get bits from neighboring blocks --- - if (block_b.available) - { + if (block_b.available) { upper_bit = set_cbp_bit_ac(&mb_data[block_b.mb_addr], &block_b); } - if (block_a.available) - { + if (block_a.available) { left_bit = set_cbp_bit_ac(&mb_data[block_a.mb_addr], &block_a); } - ctx = 2 * upper_bit + left_bit; + ctx = 2 * upper_bit + left_bit; //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); - if (cbp_bit) - { + if (cbp_bit) { //--- set bits for current block --- - bit = 1 + j + (i >> 2); - currMB->cbp_bits[0] |= ((int64) 0x03 << bit ); + bit = 1 + j + (i >> 2); + currMB->cbp_bits[0] |= ((int64)0x03 << bit); } - } - else if (type==LUMA_4x8) - { - int j = currMB->subblock_y; - int i = currMB->subblock_x; - int bit = 1; + } else if (type == LUMA_4x8) { + int j = currMB->subblock_y; + int i = currMB->subblock_x; + int bit = 1; int default_bit = (currMB->is_intra_block ? 1 : 0); - int upper_bit = default_bit; - int left_bit = default_bit; + int upper_bit = default_bit; + int left_bit = default_bit; int ctx; PixelPos block_a, block_b; - get4x4NeighbourBase(currMB, i - 1, j , p_Vid->mb_size[IS_LUMA], &block_a); - get4x4NeighbourBase(currMB, i , j - 1, p_Vid->mb_size[IS_LUMA], &block_b); + get4x4NeighbourBase(currMB, i - 1, j, p_Vid->mb_size[IS_LUMA], &block_a); + get4x4NeighbourBase(currMB, i, j - 1, p_Vid->mb_size[IS_LUMA], &block_b); //--- get bits from neighboring blocks --- - if (block_b.available) - { + if (block_b.available) { upper_bit = set_cbp_bit_ac(&mb_data[block_b.mb_addr], &block_b); } - if (block_a.available) - { + if (block_a.available) { left_bit = set_cbp_bit_ac(&mb_data[block_a.mb_addr], &block_a); } - ctx = 2 * upper_bit + left_bit; + ctx = 2 * upper_bit + left_bit; //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); - if (cbp_bit) - { + if (cbp_bit) { //--- set bits for current block --- - bit = 1 + j + (i >> 2); + bit = 1 + j + (i >> 2); - currMB->cbp_bits[0] |= ((int64) 0x11 << bit ); + currMB->cbp_bits[0] |= ((int64)0x11 << bit); } - } - else if (type==LUMA_4x4) - { - int j = currMB->subblock_y; - int i = currMB->subblock_x; - int bit = 1; + } else if (type == LUMA_4x4) { + int j = currMB->subblock_y; + int i = currMB->subblock_x; + int bit = 1; int default_bit = (currMB->is_intra_block ? 1 : 0); - int upper_bit = default_bit; - int left_bit = default_bit; + int upper_bit = default_bit; + int left_bit = default_bit; int ctx; PixelPos block_a, block_b; - get4x4NeighbourBase(currMB, i - 1, j , p_Vid->mb_size[IS_LUMA], &block_a); - get4x4NeighbourBase(currMB, i , j - 1, p_Vid->mb_size[IS_LUMA], &block_b); + get4x4NeighbourBase(currMB, i - 1, j, p_Vid->mb_size[IS_LUMA], &block_a); + get4x4NeighbourBase(currMB, i, j - 1, p_Vid->mb_size[IS_LUMA], &block_b); //--- get bits from neighboring blocks --- - if (block_b.available) - { + if (block_b.available) { upper_bit = set_cbp_bit_ac(&mb_data[block_b.mb_addr], &block_b); } - if (block_a.available) - { + if (block_a.available) { left_bit = set_cbp_bit_ac(&mb_data[block_a.mb_addr], &block_a); } - ctx = 2 * upper_bit + left_bit; + ctx = 2 * upper_bit + left_bit; //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); - if (cbp_bit) - { + if (cbp_bit) { //--- set bits for current block --- - bit = 1 + j + (i >> 2); + bit = 1 + j + (i >> 2); - currMB->cbp_bits[0] |= i64_power2(bit); + currMB->cbp_bits[0] |= i64_power2(bit); } - } - else if (type == LUMA_8x8) - { - int j = currMB->subblock_y; - int i = currMB->subblock_x; + } else if (type == LUMA_8x8) { + int j = currMB->subblock_y; + int i = currMB->subblock_x; //--- set bits for current block --- - int bit = 1 + j + (i >> 2); + int bit = 1 + j + (i >> 2); - currMB->cbp_bits[0] |= ((int64) 0x33 << bit ); - } - else if (type==CHROMA_DC || type==CHROMA_DC_2x4 || type==CHROMA_DC_4x4) - { - int u_dc = (!currMB->is_v_block); - int j = 0; - int i = 0; - int bit = (u_dc ? 17 : 18); + currMB->cbp_bits[0] |= ((int64)0x33 << bit); + } else if (type == CHROMA_DC || type == CHROMA_DC_2x4 || + type == CHROMA_DC_4x4) { + int u_dc = (!currMB->is_v_block); + int j = 0; + int i = 0; + int bit = (u_dc ? 17 : 18); int default_bit = (currMB->is_intra_block ? 1 : 0); - int upper_bit = default_bit; - int left_bit = default_bit; + int upper_bit = default_bit; + int left_bit = default_bit; int ctx; PixelPos block_a, block_b; - get4x4NeighbourBase(currMB, i - 1, j , p_Vid->mb_size[IS_CHROMA], &block_a); - get4x4NeighbourBase(currMB, i , j - 1, p_Vid->mb_size[IS_CHROMA], &block_b); + get4x4NeighbourBase(currMB, i - 1, j, p_Vid->mb_size[IS_CHROMA], &block_a); + get4x4NeighbourBase(currMB, i, j - 1, p_Vid->mb_size[IS_CHROMA], &block_b); //--- get bits from neighboring blocks --- - if (block_b.available) - { - if(mb_data[block_b.mb_addr].mb_type==IPCM) + if (block_b.available) { + if (mb_data[block_b.mb_addr].mb_type == IPCM) upper_bit = 1; else upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits[0], bit); } - if (block_a.available) - { - if(mb_data[block_a.mb_addr].mb_type==IPCM) + if (block_a.available) { + if (mb_data[block_a.mb_addr].mb_type == IPCM) left_bit = 1; else left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits[0], bit); } - ctx = 2 * upper_bit + left_bit; + ctx = 2 * upper_bit + left_bit; //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); - if (cbp_bit) - { + if (cbp_bit) { //--- set bits for current block --- - bit = (u_dc ? 17 : 18); - currMB->cbp_bits[0] |= i64_power2(bit); + bit = (u_dc ? 17 : 18); + currMB->cbp_bits[0] |= i64_power2(bit); } - } - else - { - int u_ac = (!currMB->is_v_block); - int j = currMB->subblock_y; - int i = currMB->subblock_x; - int bit = (u_ac ? 19 : 35); + } else { + int u_ac = (!currMB->is_v_block); + int j = currMB->subblock_y; + int i = currMB->subblock_x; + int bit = (u_ac ? 19 : 35); int default_bit = (currMB->is_intra_block ? 1 : 0); - int upper_bit = default_bit; - int left_bit = default_bit; + int upper_bit = default_bit; + int left_bit = default_bit; int ctx; PixelPos block_a, block_b; - get4x4NeighbourBase(currMB, i - 1, j , p_Vid->mb_size[IS_CHROMA], &block_a); - get4x4NeighbourBase(currMB, i , j - 1, p_Vid->mb_size[IS_CHROMA], &block_b); + get4x4NeighbourBase(currMB, i - 1, j, p_Vid->mb_size[IS_CHROMA], &block_a); + get4x4NeighbourBase(currMB, i, j - 1, p_Vid->mb_size[IS_CHROMA], &block_b); //--- get bits from neighboring blocks --- - if (block_b.available) - { - if(mb_data[block_b.mb_addr].mb_type==IPCM) - upper_bit=1; - else - { - int bit_pos_b = 4*block_b.y + block_b.x; - upper_bit = get_bit(mb_data[block_b.mb_addr].cbp_bits[0], bit + bit_pos_b); + if (block_b.available) { + if (mb_data[block_b.mb_addr].mb_type == IPCM) + upper_bit = 1; + else { + int bit_pos_b = 4 * block_b.y + block_b.x; + upper_bit = + get_bit(mb_data[block_b.mb_addr].cbp_bits[0], bit + bit_pos_b); } } - if (block_a.available) - { - if(mb_data[block_a.mb_addr].mb_type==IPCM) - left_bit=1; - else - { - int bit_pos_a = 4*block_a.y + block_a.x; - left_bit = get_bit(mb_data[block_a.mb_addr].cbp_bits[0],bit + bit_pos_a); + if (block_a.available) { + if (mb_data[block_a.mb_addr].mb_type == IPCM) + left_bit = 1; + else { + int bit_pos_a = 4 * block_a.y + block_a.x; + left_bit = + get_bit(mb_data[block_a.mb_addr].cbp_bits[0], bit + bit_pos_a); } } - ctx = 2 * upper_bit + left_bit; + ctx = 2 * upper_bit + left_bit; //===== encode symbol ===== - cbp_bit = biari_decode_symbol (dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); + cbp_bit = biari_decode_symbol( + dep_dp, tex_ctx->bcbp_contexts[type2ctx_bcbp[type]] + ctx); - if (cbp_bit) - { + if (cbp_bit) { //--- set bits for current block --- - bit = (u_ac ? 19 + j + (i >> 2) : 35 + j + (i >> 2)); - currMB->cbp_bits[0] |= i64_power2(bit); + bit = (u_ac ? 19 + j + (i >> 2) : 35 + j + (i >> 2)); + currMB->cbp_bits[0] |= i64_power2(bit); } } return cbp_bit; } - -void set_read_and_store_CBP(Macroblock **currMB, int chroma_format_idc) -{ +void set_read_and_store_CBP(Macroblock **currMB, int chroma_format_idc) { if (chroma_format_idc == YUV444) (*currMB)->read_and_store_CBP_block_bit = read_and_store_CBP_block_bit_444; else - (*currMB)->read_and_store_CBP_block_bit = read_and_store_CBP_block_bit_normal; + (*currMB)->read_and_store_CBP_block_bit = + read_and_store_CBP_block_bit_normal; } - - - //===== position -> ctx for MAP ===== //--- zig-zag scan ---- -static const byte pos2ctx_map8x8 [] = { 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5, - 4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9, 10, 9, 8, 7, - 7, 6, 11, 12, 13, 11, 6, 7, 8, 9, 14, 10, 9, 8, 6, 11, - 12, 13, 11, 6, 9, 14, 10, 9, 11, 12, 13, 11 ,14, 10, 12, 14}; // 15 CTX -static const byte pos2ctx_map8x4 [] = { 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 9, 8, 6, 7, 8, - 9, 10, 11, 9, 8, 6, 12, 8, 9, 10, 11, 9, 13, 13, 14, 14}; // 15 CTX -static const byte pos2ctx_map4x4 [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14}; // 15 CTX -static const byte pos2ctx_map2x4c[] = { 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; // 15 CTX -static const byte pos2ctx_map4x4c[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2}; // 15 CTX -static const byte* pos2ctx_map [] = {pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8, pos2ctx_map8x4, - pos2ctx_map8x4, pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map4x4, - pos2ctx_map2x4c, pos2ctx_map4x4c, - pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8,pos2ctx_map8x4, - pos2ctx_map8x4, pos2ctx_map4x4, - pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8,pos2ctx_map8x4, - pos2ctx_map8x4,pos2ctx_map4x4}; +static const byte pos2ctx_map8x8[] = { + 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5, + 4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9, 10, 9, 8, 7, + 7, 6, 11, 12, 13, 11, 6, 7, 8, 9, 14, 10, 9, 8, 6, 11, + 12, 13, 11, 6, 9, 14, 10, 9, 11, 12, 13, 11, 14, 10, 12, 14}; // 15 CTX +static const byte pos2ctx_map8x4[] = { + 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 9, 8, 6, 7, 8, + 9, 10, 11, 9, 8, 6, 12, 8, 9, 10, 11, 9, 13, 13, 14, 14}; // 15 CTX +static const byte pos2ctx_map4x4[] = {0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 14}; // 15 CTX +static const byte pos2ctx_map2x4c[] = {0, 0, 1, 1, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2}; // 15 CTX +static const byte pos2ctx_map4x4c[] = {0, 0, 0, 0, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2}; // 15 CTX +static const byte *pos2ctx_map[] = { + pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8, pos2ctx_map8x4, + pos2ctx_map8x4, pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map4x4, + pos2ctx_map2x4c, pos2ctx_map4x4c, pos2ctx_map4x4, pos2ctx_map4x4, + pos2ctx_map8x8, pos2ctx_map8x4, pos2ctx_map8x4, pos2ctx_map4x4, + pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8, pos2ctx_map8x4, + pos2ctx_map8x4, pos2ctx_map4x4}; //--- interlace scan ---- -//taken from ABT -static const byte pos2ctx_map8x8i[] = { 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5, - 6, 9, 10, 10, 8, 11, 12, 11, 9, 9, 10, 10, 8, 11, 12, 11, - 9, 9, 10, 10, 8, 11, 12, 11, 9, 9, 10, 10, 8, 13, 13, 9, - 9, 10, 10, 8, 13, 13, 9, 9, 10, 10, 14, 14, 14, 14, 14, 14}; // 15 CTX -static const byte pos2ctx_map8x4i[] = { 0, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 7, 6, 8, - 9, 7, 6, 8, 9, 10, 11, 12, 12, 10, 11, 13, 13, 14, 14, 14}; // 15 CTX -static const byte pos2ctx_map4x8i[] = { 0, 1, 1, 1, 2, 3, 3, 4, 4, 4, 5, 6, 2, 7, 7, 8, - 8, 8, 5, 6, 9, 10, 10, 11, 11, 11, 12, 13, 13, 14, 14, 14}; // 15 CTX -static const byte* pos2ctx_map_int[] = {pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8i,pos2ctx_map8x4i, - pos2ctx_map4x8i,pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map4x4, - pos2ctx_map2x4c, pos2ctx_map4x4c, - pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8i,pos2ctx_map8x4i, - pos2ctx_map8x4i,pos2ctx_map4x4, - pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8i,pos2ctx_map8x4i, - pos2ctx_map8x4i,pos2ctx_map4x4}; +// taken from ABT +static const byte pos2ctx_map8x8i[] = { + 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5, + 6, 9, 10, 10, 8, 11, 12, 11, 9, 9, 10, 10, 8, 11, 12, 11, + 9, 9, 10, 10, 8, 11, 12, 11, 9, 9, 10, 10, 8, 13, 13, 9, + 9, 10, 10, 8, 13, 13, 9, 9, 10, 10, 14, 14, 14, 14, 14, 14}; // 15 CTX +static const byte pos2ctx_map8x4i[] = { + 0, 1, 2, 3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 7, 6, 8, + 9, 7, 6, 8, 9, 10, 11, 12, 12, 10, 11, 13, 13, 14, 14, 14}; // 15 CTX +static const byte pos2ctx_map4x8i[] = { + 0, 1, 1, 1, 2, 3, 3, 4, 4, 4, 5, 6, 2, 7, 7, 8, + 8, 8, 5, 6, 9, 10, 10, 11, 11, 11, 12, 13, 13, 14, 14, 14}; // 15 CTX +static const byte *pos2ctx_map_int[] = { + pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8i, pos2ctx_map8x4i, + pos2ctx_map4x8i, pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map4x4, + pos2ctx_map2x4c, pos2ctx_map4x4c, pos2ctx_map4x4, pos2ctx_map4x4, + pos2ctx_map8x8i, pos2ctx_map8x4i, pos2ctx_map8x4i, pos2ctx_map4x4, + pos2ctx_map4x4, pos2ctx_map4x4, pos2ctx_map8x8i, pos2ctx_map8x4i, + pos2ctx_map8x4i, pos2ctx_map4x4}; //===== position -> ctx for LAST ===== -static const byte pos2ctx_last8x8 [] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, - 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8}; // 9 CTX -static const byte pos2ctx_last8x4 [] = { 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8}; // 9 CTX - -static const byte pos2ctx_last4x4 [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; // 15 CTX -static const byte pos2ctx_last2x4c[] = { 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; // 15 CTX -static const byte pos2ctx_last4x4c[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2}; // 15 CTX -static const byte* pos2ctx_last [] = {pos2ctx_last4x4, pos2ctx_last4x4, pos2ctx_last8x8, pos2ctx_last8x4, - pos2ctx_last8x4, pos2ctx_last4x4, pos2ctx_last4x4, pos2ctx_last4x4, - pos2ctx_last2x4c, pos2ctx_last4x4c, - pos2ctx_last4x4, pos2ctx_last4x4, pos2ctx_last8x8,pos2ctx_last8x4, - pos2ctx_last8x4, pos2ctx_last4x4, - pos2ctx_last4x4, pos2ctx_last4x4, pos2ctx_last8x8,pos2ctx_last8x4, - pos2ctx_last8x4, pos2ctx_last4x4}; - +static const byte pos2ctx_last8x8[] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, + 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8}; // 9 CTX +static const byte pos2ctx_last8x4[] = {0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, + 4, 4, 5, 5, 6, 6, 7, 7, 8, 8}; // 9 CTX +static const byte pos2ctx_last4x4[] = {0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15}; // 15 CTX +static const byte pos2ctx_last2x4c[] = {0, 0, 1, 1, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2}; // 15 CTX +static const byte pos2ctx_last4x4c[] = {0, 0, 0, 0, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2}; // 15 CTX +static const byte *pos2ctx_last[] = { + pos2ctx_last4x4, pos2ctx_last4x4, pos2ctx_last8x8, pos2ctx_last8x4, + pos2ctx_last8x4, pos2ctx_last4x4, pos2ctx_last4x4, pos2ctx_last4x4, + pos2ctx_last2x4c, pos2ctx_last4x4c, pos2ctx_last4x4, pos2ctx_last4x4, + pos2ctx_last8x8, pos2ctx_last8x4, pos2ctx_last8x4, pos2ctx_last4x4, + pos2ctx_last4x4, pos2ctx_last4x4, pos2ctx_last8x8, pos2ctx_last8x4, + pos2ctx_last8x4, pos2ctx_last4x4}; /*! ************************************************************************ @@ -1929,51 +1857,46 @@ static const byte* pos2ctx_last [] = {pos2ctx_last4x4, pos2ctx_last4x4, pos2c * Read Significance MAP ************************************************************************ */ -static int read_significance_map (Macroblock *currMB, - DecodingEnvironmentPtr dep_dp, - int type, - int coeff[]) -{ +static int read_significance_map(Macroblock *currMB, + DecodingEnvironmentPtr dep_dp, int type, + int coeff[]) { Slice *currSlice = currMB->p_Slice; - int fld = ( currSlice->structure!=FRAME || currMB->mb_field ); + int fld = (currSlice->structure != FRAME || currMB->mb_field); const byte **pos2ctx_Map = (fld) ? pos2ctx_map_int : pos2ctx_map; - BiContextTypePtr map_ctx = currSlice->tex_ctx->map_contexts [fld][type2ctx_map [type]]; - BiContextTypePtr last_ctx = currSlice->tex_ctx->last_contexts[fld][type2ctx_last[type]]; + BiContextTypePtr map_ctx = + currSlice->tex_ctx->map_contexts[fld][type2ctx_map[type]]; + BiContextTypePtr last_ctx = + currSlice->tex_ctx->last_contexts[fld][type2ctx_last[type]]; - int i; - int coeff_ctr = 0; - int i0 = 0; - int i1 = maxpos[type]; + int i; + int coeff_ctr = 0; + int i0 = 0; + int i1 = maxpos[type]; - if (!c1isdc[type]) - { - ++i0; - ++i1; + if (!c1isdc[type]) { + ++i0; + ++i1; } - for (i=i0; i < i1; ++i) // if last coeff is reached, it has to be significant + for (i = i0; i < i1; + ++i) // if last coeff is reached, it has to be significant { //--- read significance symbol --- - if (biari_decode_symbol (dep_dp, map_ctx + pos2ctx_Map [type][i])) - { + if (biari_decode_symbol(dep_dp, map_ctx + pos2ctx_Map[type][i])) { *(coeff++) = 1; ++coeff_ctr; //--- read last coefficient symbol --- - if (biari_decode_symbol (dep_dp, last_ctx + pos2ctx_last[type][i])) - { + if (biari_decode_symbol(dep_dp, last_ctx + pos2ctx_last[type][i])) { memset(coeff, 0, (i1 - i) * sizeof(int)); i = i1; } - } - else - { + } else { *(coeff++) = 0; } } //--- last coefficient must be significant if no last symbol was received --- - if (i < i1 + 1) - { + if (i < i1 + 1) { *coeff = 1; ++coeff_ctr; } @@ -1981,47 +1904,37 @@ static int read_significance_map (Macroblock *currMB, return coeff_ctr; } - - /*! ************************************************************************ * \brief * Read Levels ************************************************************************ */ -static void read_significant_coefficients (DecodingEnvironmentPtr dep_dp, - TextureInfoContexts *tex_ctx, - int type, - int coeff[]) -{ - int i, ctx; - int c1 = 1; - int c2 = 0; +static void read_significant_coefficients(DecodingEnvironmentPtr dep_dp, + TextureInfoContexts *tex_ctx, + int type, int coeff[]) { + int i, ctx; + int c1 = 1; + int c2 = 0; BiContextType *one_contexts = tex_ctx->one_contexts[type2ctx_one[type]]; BiContextType *abs_contexts = tex_ctx->abs_contexts[type2ctx_abs[type]]; int max_type = max_c2[type]; int *cof = &coeff[maxpos[type]]; - for (i=maxpos[type]; i>=0; i--) - { - if (*cof != 0) - { - ctx = imin (c1, 4); - *cof += biari_decode_symbol (dep_dp, one_contexts + ctx); + for (i = maxpos[type]; i >= 0; i--) { + if (*cof != 0) { + ctx = imin(c1, 4); + *cof += biari_decode_symbol(dep_dp, one_contexts + ctx); - if (*cof == 2) - { - ctx = imin (c2++, max_type); - *cof += unary_exp_golomb_level_decode (dep_dp, abs_contexts + ctx); + if (*cof == 2) { + ctx = imin(c2++, max_type); + *cof += unary_exp_golomb_level_decode(dep_dp, abs_contexts + ctx); c1 = 0; - } - else if (c1) - { + } else if (c1) { ++c1; } - if (biari_decode_symbol_eq_prob(dep_dp)) - { + if (biari_decode_symbol_eq_prob(dep_dp)) { *cof *= -1; } } @@ -2029,52 +1942,50 @@ static void read_significant_coefficients (DecodingEnvironmentPtr dep_dp, } } - /*! ************************************************************************ * \brief * Read Block-Transform Coefficients ************************************************************************ */ -void readRunLevel_CABAC (Macroblock *currMB, - SyntaxElement *se, - DecodingEnvironmentPtr dep_dp) -{ +void readRunLevel_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp) { Slice *currSlice = currMB->p_Slice; - int *coeff_ctr = &currSlice->coeff_ctr; + int *coeff_ctr = &currSlice->coeff_ctr; //--- read coefficients for whole block --- - if (*coeff_ctr < 0) - { + if (*coeff_ctr < 0) { //===== decode CBP-BIT ===== - if ((*coeff_ctr = currMB->read_and_store_CBP_block_bit (currMB, dep_dp, se->context) ) != 0) - { + if ((*coeff_ctr = currMB->read_and_store_CBP_block_bit(currMB, dep_dp, + se->context)) != 0) { //===== decode significance map ===== - *coeff_ctr = read_significance_map (currMB, dep_dp, se->context, currSlice->coeff); + *coeff_ctr = + read_significance_map(currMB, dep_dp, se->context, currSlice->coeff); //===== decode significant coefficients ===== - read_significant_coefficients (dep_dp, currSlice->tex_ctx, se->context, currSlice->coeff); + read_significant_coefficients(dep_dp, currSlice->tex_ctx, se->context, + currSlice->coeff); } } //--- set run and level --- - if (*coeff_ctr) - { + if (*coeff_ctr) { //--- set run and level (coefficient) --- - for (se->value2 = 0; currSlice->coeff[currSlice->pos] == 0; ++currSlice->pos, ++se->value2); + for (se->value2 = 0; currSlice->coeff[currSlice->pos] == 0; + ++currSlice->pos, ++se->value2) + ; se->value1 = currSlice->coeff[currSlice->pos++]; - } - else - { + } else { //--- set run and level (EOB) --- se->value1 = se->value2 = 0; } //--- decrement coefficient counter and re-set position --- - if ((*coeff_ctr)-- == 0) + if ((*coeff_ctr)-- == 0) currSlice->pos = 0; #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-53s %3d %3d\n",symbolCount++, se->tracestring, se->value1,se->value2); + fprintf(p_Dec->p_trace, "@%-6d %-53s %3d %3d\n", symbolCount++, + se->tracestring, se->value1, se->value2); fflush(p_Dec->p_trace); #endif } @@ -2085,25 +1996,24 @@ void readRunLevel_CABAC (Macroblock *currMB, * arithmetic decoding ************************************************************************ */ -int readSyntaxElement_CABAC(Macroblock *currMB, SyntaxElement *se, DataPartition *this_dataPart) -{ +int readSyntaxElement_CABAC(Macroblock *currMB, SyntaxElement *se, + DataPartition *this_dataPart) { DecodingEnvironmentPtr dep_dp = &(this_dataPart->de_cabac); int curr_len = arideco_bits_read(dep_dp); // perform the actual decoding by calling the appropriate method se->reading(currMB, se, dep_dp); - //read again and minus curr_len = arideco_bits_read(dep_dp); from above + // read again and minus curr_len = arideco_bits_read(dep_dp); from above se->len = (arideco_bits_read(dep_dp) - curr_len); -#if (TRACE==2) - fprintf(p_Dec->p_trace, "curr_len: %d\n",curr_len); - fprintf(p_Dec->p_trace, "se_len: %d\n",se->len); +#if (TRACE == 2) + fprintf(p_Dec->p_trace, "curr_len: %d\n", curr_len); + fprintf(p_Dec->p_trace, "se_len: %d\n", se->len); #endif - return (se->len); + return (se->len); } - /*! ************************************************************************ * \brief @@ -2113,25 +2023,20 @@ int readSyntaxElement_CABAC(Macroblock *currMB, SyntaxElement *se, DataPartition *********************************************************************** */ static unsigned int unary_bin_max_decode(DecodingEnvironmentPtr dep_dp, - BiContextTypePtr ctx, - int ctx_offset, - unsigned int max_symbol) -{ - unsigned int symbol = biari_decode_symbol(dep_dp, ctx ); + BiContextTypePtr ctx, int ctx_offset, + unsigned int max_symbol) { + unsigned int symbol = biari_decode_symbol(dep_dp, ctx); if (symbol == 0 || (max_symbol == 0)) return symbol; - else - { + else { unsigned int l; ctx += ctx_offset; symbol = 0; - do - { + do { l = biari_decode_symbol(dep_dp, ctx); ++symbol; - } - while( (l != 0) && (symbol < max_symbol) ); + } while ((l != 0) && (symbol < max_symbol)); if ((l != 0) && (symbol == max_symbol)) ++symbol; @@ -2139,7 +2044,6 @@ static unsigned int unary_bin_max_decode(DecodingEnvironmentPtr dep_dp, } } - /*! ************************************************************************ * \brief @@ -2148,29 +2052,24 @@ static unsigned int unary_bin_max_decode(DecodingEnvironmentPtr dep_dp, *********************************************************************** */ static unsigned int unary_bin_decode(DecodingEnvironmentPtr dep_dp, - BiContextTypePtr ctx, - int ctx_offset) -{ - unsigned int symbol = biari_decode_symbol(dep_dp, ctx ); + BiContextTypePtr ctx, int ctx_offset) { + unsigned int symbol = biari_decode_symbol(dep_dp, ctx); if (symbol == 0) return 0; - else - { + else { unsigned int l; - ctx += ctx_offset;; + ctx += ctx_offset; + ; symbol = 0; - do - { + do { l = biari_decode_symbol(dep_dp, ctx); ++symbol; - } - while( l != 0 ); + } while (l != 0); return symbol; } } - /*! ************************************************************************ * \brief @@ -2182,25 +2081,22 @@ static unsigned int unary_bin_decode(DecodingEnvironmentPtr dep_dp, * StW, 8.7.02 ************************************************************************ */ -int cabac_startcode_follows(Slice *currSlice, int eos_bit) -{ - unsigned int bit; +int cabac_startcode_follows(Slice *currSlice, int eos_bit) { + unsigned int bit; - if( eos_bit ) - { - const byte *partMap = assignSE2partition[currSlice->dp_mode]; - DataPartition *dP = &(currSlice->partArr[partMap[SE_MBTYPE]]); + if (eos_bit) { + const byte *partMap = assignSE2partition[currSlice->dp_mode]; + DataPartition *dP = &(currSlice->partArr[partMap[SE_MBTYPE]]); DecodingEnvironmentPtr dep_dp = &(dP->de_cabac); - bit = biari_decode_final (dep_dp); //GB + bit = biari_decode_final(dep_dp); // GB #if TRACE - fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n",symbolCount++, "end_of_slice_flag", bit); + fprintf(p_Dec->p_trace, "@%-6d %-63s (%3d)\n", symbolCount++, + "end_of_slice_flag", bit); fflush(p_Dec->p_trace); #endif - } - else - { + } else { bit = 0; } @@ -2214,68 +2110,56 @@ int cabac_startcode_follows(Slice *currSlice, int eos_bit) * with prob. of 0.5 ************************************************************************ */ -static unsigned int exp_golomb_decode_eq_prob( DecodingEnvironmentPtr dep_dp, - int k) -{ +static unsigned int exp_golomb_decode_eq_prob(DecodingEnvironmentPtr dep_dp, + int k) { unsigned int l; int symbol = 0; int binary_symbol = 0; - do - { + do { l = biari_decode_symbol_eq_prob(dep_dp); - if (l == 1) - { - symbol += (1<p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; - Bitstream* currStream = dP->bitstream; + Bitstream *currStream = dP->bitstream; DecodingEnvironmentPtr dep = &(dP->de_cabac); byte *buf = currStream->streamBuffer; int BitstreamLengthInBits = (dP->bitstream->bitstream_length << 3) + 7; @@ -2337,22 +2216,20 @@ void readIPCM_CABAC(Slice *currSlice, struct datapartition *dP) int bitoffset, bitdepth; int uv, i, j; - while (dep->DbitsLeft >= 8) - { - dep->Dvalue >>= 8; + while (dep->DbitsLeft >= 8) { + dep->Dvalue >>= 8; dep->DbitsLeft -= 8; (*dep->Dcodestrm_len)--; } - + bitoffset = (*dep->Dcodestrm_len) << 3; // read luma values bitdepth = p_Vid->bitdepth_luma; - for(i=0;ibitdepth_chroma; - if ((dec_picture->chroma_format_idc != YUV400) && (p_Vid->separate_colour_plane_flag == 0)) - { - for (uv = 1; uv < 3; ++uv) - { - for(i = 0; i < p_Vid->mb_cr_size_y; ++i) - { - for(j = 0; j < p_Vid->mb_cr_size_x; ++j) - { - bits_read += GetBits(buf, bitoffset, &val, BitstreamLengthInBits, bitdepth); + if ((dec_picture->chroma_format_idc != YUV400) && + (p_Vid->separate_colour_plane_flag == 0)) { + for (uv = 1; uv < 3; ++uv) { + for (i = 0; i < p_Vid->mb_cr_size_y; ++i) { + for (j = 0; j < p_Vid->mb_cr_size_x; ++j) { + bits_read += + GetBits(buf, bitoffset, &val, BitstreamLengthInBits, bitdepth); #if TRACE tracebits2("pcm_byte chroma", bitdepth, val); #endif @@ -2384,10 +2259,8 @@ void readIPCM_CABAC(Slice *currSlice, struct datapartition *dP) } } - (*dep->Dcodestrm_len) += ( bits_read >> 3); - if (bits_read & 7) - { + (*dep->Dcodestrm_len) += (bits_read >> 3); + if (bits_read & 7) { ++(*dep->Dcodestrm_len); } } - diff --git a/src/common/ldecod_src/config_common.c b/src/common/ldecod_src/config_common.c index 65fa5f5..d66b8fb 100644 --- a/src/common/ldecod_src/config_common.c +++ b/src/common/ldecod_src/config_common.c @@ -6,39 +6,36 @@ * \brief * Configuration handling. * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and affiliation + *details) * - Stephan Wenger * \note * In the future this module should hide the Parameters and offer only - * Functions for their access. Modules which make frequent use of some parameters - * (e.g. picture size in macroblocks) are free to buffer them on local variables. - * This will not only avoid global variable and make the code more readable, but also - * speed it up. It will also greatly facilitate future enhancements such as the - * handling of different picture sizes in the same sequence. \n - * \n - * For now, everything is just copied to the inp_par structure (gulp) + * Functions for their access. Modules which make frequent use of some + *parameters (e.g. picture size in macroblocks) are free to buffer them on local + *variables. This will not only avoid global variable and make the code more + *readable, but also speed it up. It will also greatly facilitate future + *enhancements such as the handling of different picture sizes in the same + *sequence. \n \n For now, everything is just copied to + *the inp_par structure (gulp) * ************************************************************************************** * \par Configuration File Format ************************************************************************************** - * Format is line oriented, maximum of one parameter per line \n - * \n - * Lines have the following format: \n - * \ = \ # Comments \\n \n - * Whitespace is space and \\t - * \par - * \ are the predefined names for Parameters and are case sensitive. - * See configfile.h for the definition of those names and their mapping to - * cfgparams->values. - * \par + * Format is line oriented, maximum of one parameter per line \n \n Lines have + *the following format: \n + * \ = \ # Comments \\n \n Whitespace is space + *and \\t \par + * \ are the predefined names for Parameters and are case + *sensitive. See configfile.h for the definition of those names and their + *mapping to cfgparams->values. \par * \ are either integers [0..9]* or strings. - * Integers must fit into the wordlengths, signed values are generally assumed. - * Strings containing no whitespace characters can be used directly. Strings containing - * whitespace characters are to be inclosed in double quotes ("string with whitespace") - * The double quote character is forbidden (may want to implement something smarter here). - * \par - * Any Parameters whose ParameterName is undefined lead to the termination of the program - * with an error message. + * Integers must fit into the wordlengths, signed values are generally + *assumed. Strings containing no whitespace characters can be used directly. + *Strings containing whitespace characters are to be inclosed in double quotes + *("string with whitespace") The double quote character is forbidden (may want + *to implement something smarter here). \par Any Parameters whose ParameterName + *is undefined lead to the termination of the program with an error message. * * \par Known bug/Shortcoming: * zero-length strings (i.e. to signal an non-existing file @@ -46,29 +43,29 @@ * * \par Rules for using command files * \n - * All Parameters are initially taken from DEFAULTCONFIGFILENAME, defined in configfile.h. - * If an -f \ parameter is present in the command line then this file is used to - * update the defaults of DEFAULTCONFIGFILENAME. There can be more than one -f parameters - * present. If -p parameters are present then these - * override the default and the additional config file's settings, and are themselves - * overridden by future -p parameters. There must be whitespace between -f and -p commands - * and their respective parameters + * All Parameters are initially taken from DEFAULTCONFIGFILENAME, defined in + *configfile.h. If an -f \ parameter is present in the command line + *then this file is used to update the defaults of DEFAULTCONFIGFILENAME. There + *can be more than one -f parameters present. If -p parameters are present then these override the default and the + *additional config file's settings, and are themselves overridden by future -p + *parameters. There must be whitespace between -f and -p commands and their + *respective parameters *********************************************************************** */ #include -#include "global.h" #include "configfile.h" +#include "global.h" #include "memalloc.h" -static int ParameterNameToMapIndex (Mapping *Map, char *s); +static int ParameterNameToMapIndex(Mapping *Map, char *s); - -#define MAX_ITEMS_TO_PARSE 10000 +#define MAX_ITEMS_TO_PARSE 10000 #ifdef SPEC #ifdef SPEC_WINDOWS -#define STRCMP(x,y) _stricmp(x,y) +#define STRCMP(x, y) _stricmp(x, y) #else #define STRCMP strcmp #endif @@ -88,69 +85,66 @@ static int ParameterNameToMapIndex (Mapping *Map, char *s); * NULL in case of error. Error message will be set in errortext *********************************************************************** */ -char *GetConfigFileContent (char *Filename) -{ +char *GetConfigFileContent(char *Filename) { long FileSize; FILE *f; char *buf; - if (NULL == (f = fopen (Filename, "r"))) - { - snprintf (errortext, ET_SIZE, "Cannot open configuration file %s.", Filename); - return NULL; - } - - if (0 != fseek (f, 0, SEEK_END)) - { - snprintf (errortext, ET_SIZE, "Cannot fseek in configuration file %s.", Filename); + if (NULL == (f = fopen(Filename, "r"))) { + snprintf(errortext, ET_SIZE, "Cannot open configuration file %s.", + Filename); return NULL; } - FileSize = ftell (f); - if (FileSize < 0 || FileSize > 100000) - { - snprintf (errortext, ET_SIZE, "Unreasonable Filesize %ld reported by ftell for configuration file %s.", FileSize, Filename); - return NULL; - } - if (0 != fseek (f, 0, SEEK_SET)) - { - snprintf (errortext, ET_SIZE, "Cannot fseek in configuration file %s.", Filename); + if (0 != fseek(f, 0, SEEK_END)) { + snprintf(errortext, ET_SIZE, "Cannot fseek in configuration file %s.", + Filename); return NULL; } - if ((buf = malloc (FileSize + 1))==NULL) no_mem_exit("GetConfigFileContent: buf"); + FileSize = ftell(f); + if (FileSize < 0 || FileSize > 100000) { + snprintf(errortext, ET_SIZE, + "Unreasonable Filesize %ld reported by ftell for configuration " + "file %s.", + FileSize, Filename); + return NULL; + } + if (0 != fseek(f, 0, SEEK_SET)) { + snprintf(errortext, ET_SIZE, "Cannot fseek in configuration file %s.", + Filename); + return NULL; + } - // Note that ftell() gives us the file size as the file system sees it. The actual file size, - // as reported by fread() below will be often smaller due to CR/LF to CR conversion and/or - // control characters after the dos EOF marker in the file. + if ((buf = malloc(FileSize + 1)) == NULL) + no_mem_exit("GetConfigFileContent: buf"); - FileSize = (long) fread (buf, 1, FileSize, f); + // Note that ftell() gives us the file size as the file system sees it. The + // actual file size, as reported by fread() below will be often smaller due to + // CR/LF to CR conversion and/or control characters after the dos EOF marker + // in the file. + + FileSize = (long)fread(buf, 1, FileSize, f); buf[FileSize] = '\0'; - - fclose (f); + fclose(f); return buf; } - /*! *********************************************************************** * \brief - * Parses the character array buf and writes global variable input, which is defined in - * configfile.h. This hack will continue to be necessary to facilitate the addition of - * new parameters through the Map[] mechanism (Need compiler-generated addresses in map[]). - * \param p_Inp - * InputParameters of configuration - * \param Map - * Mapping structure to specify the name and value mapping relation - * \param buf - * buffer to be parsed - * \param bufsize - * buffer size of buffer + * Parses the character array buf and writes global variable input, which is + *defined in configfile.h. This hack will continue to be necessary to + *facilitate the addition of new parameters through the Map[] mechanism (Need + *compiler-generated addresses in map[]). \param p_Inp InputParameters of + *configuration \param Map Mapping structure to specify the name and value + *mapping relation \param buf buffer to be parsed \param bufsize buffer size of + *buffer *********************************************************************** */ -void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize) -{ +void ParseContent(InputParameters *p_Inp, Mapping *Map, char *buf, + int bufsize) { char *items[MAX_ITEMS_TO_PARSE] = {NULL}; int MapIdx; int item = 0; @@ -161,19 +155,20 @@ void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize) double DoubleContent; int i; - // Stage one: Generate an argc/argv-type list in items[], without comments and whitespace. - // This is context insensitive and could be done most easily with lex(1). + // Stage one: Generate an argc/argv-type list in items[], without comments and + // whitespace. This is context insensitive and could be done most easily with + // lex(1). - while (p < bufend) - { - switch (*p) - { + while (p < bufend) { + switch (*p) { case 13: ++p; break; - case '#': // Found comment - *p = '\0'; // Replace '#' with '\0' in case of comment immediately following integer or string - while (*p != '\n' && p < bufend) // Skip till EOL or EOF, whichever comes first + case '#': // Found comment + *p = '\0'; // Replace '#' with '\0' in case of comment immediately + // following integer or string + while (*p != '\n' && + p < bufend) // Skip till EOL or EOF, whichever comes first ++p; InString = 0; InItem = 0; @@ -181,34 +176,30 @@ void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize) case '\n': InItem = 0; InString = 0; - *p++='\0'; + *p++ = '\0'; break; case ' ': - case '\t': // Skip whitespace, leave state unchanged + case '\t': // Skip whitespace, leave state unchanged if (InString) p++; - else - { // Terminate non-strings once whitespace is found + else { // Terminate non-strings once whitespace is found *p++ = '\0'; InItem = 0; } break; - case '"': // Begin/End of String + case '"': // Begin/End of String *p++ = '\0'; - if (!InString) - { + if (!InString) { items[item++] = p; InItem = ~InItem; - } - else + } else InItem = 0; InString = ~InString; // Toggle break; default: - if (!InItem) - { + if (!InItem) { items[item++] = p; InItem = ~InItem; } @@ -218,53 +209,57 @@ void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize) item--; - for (i=0; i (MapIdx = ParameterNameToMapIndex (Map, items[i]))) - { - //snprintf (errortext, ET_SIZE, " Parsing error in config file: Parameter Name '%s' not recognized.", items[i]); - //error (errortext, 300); - printf ("\n\tParsing error in config file: Parameter Name '%s' not recognized.", items[i]); - i -= 2 ; + for (i = 0; i < item; i += 3) { + if (0 > (MapIdx = ParameterNameToMapIndex(Map, items[i]))) { + // snprintf (errortext, ET_SIZE, " Parsing error in config file: Parameter + // Name '%s' not recognized.", items[i]); error (errortext, 300); + printf("\n\tParsing error in config file: Parameter Name '%s' not " + "recognized.", + items[i]); + i -= 2; continue; } - if (STRCMP ("=", items[i+1])) - { - snprintf (errortext, ET_SIZE, " Parsing error in config file: '=' expected as the second token in each line."); - error (errortext, 300); + if (STRCMP("=", items[i + 1])) { + snprintf(errortext, ET_SIZE, + " Parsing error in config file: '=' expected as the second " + "token in each line."); + error(errortext, 300); } // Now interpret the Value, context sensitive... - switch (Map[MapIdx].Type) - { - case 0: // Numerical - if (1 != sscanf (items[i+2], "%d", &IntContent)) - { - snprintf (errortext, ET_SIZE, " Parsing error: Expected numerical value for Parameter of %s, found '%s'.", items[i], items[i+2]); - error (errortext, 300); + switch (Map[MapIdx].Type) { + case 0: // Numerical + if (1 != sscanf(items[i + 2], "%d", &IntContent)) { + snprintf(errortext, ET_SIZE, + " Parsing error: Expected numerical value for Parameter of " + "%s, found '%s'.", + items[i], items[i + 2]); + error(errortext, 300); } - * (int *) (Map[MapIdx].Place) = IntContent; - printf ("."); + *(int *)(Map[MapIdx].Place) = IntContent; + printf("."); break; case 1: if (items[i + 2] == NULL) - memset((char *) Map[MapIdx].Place, 0, Map[MapIdx].char_size); + memset((char *)Map[MapIdx].Place, 0, Map[MapIdx].char_size); else - strncpy ((char *) Map[MapIdx].Place, items [i+2], Map[MapIdx].char_size); - printf ("."); + strncpy((char *)Map[MapIdx].Place, items[i + 2], Map[MapIdx].char_size); + printf("."); break; - case 2: // Numerical double - if (1 != sscanf (items[i+2], "%lf", &DoubleContent)) - { - snprintf (errortext, ET_SIZE, " Parsing error: Expected numerical value for Parameter of %s, found '%s'.", items[i], items[i+2]); - error (errortext, 300); + case 2: // Numerical double + if (1 != sscanf(items[i + 2], "%lf", &DoubleContent)) { + snprintf(errortext, ET_SIZE, + " Parsing error: Expected numerical value for Parameter of " + "%s, found '%s'.", + items[i], items[i + 2]); + error(errortext, 300); } - * (double *) (Map[MapIdx].Place) = DoubleContent; - printf ("."); + *(double *)(Map[MapIdx].Place) = DoubleContent; + printf("."); break; default: - error ("Unknown value type in the map definition of configfile.h",-1); + error("Unknown value type in the map definition of configfile.h", -1); } } *p_Inp = cfgparams; @@ -283,12 +278,11 @@ void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize) * -1 for error *********************************************************************** */ -static int ParameterNameToMapIndex (Mapping *Map, char *s) -{ +static int ParameterNameToMapIndex(Mapping *Map, char *s) { int i = 0; while (Map[i].TokenName != NULL) - if (0==STRCMP (Map[i].TokenName, s)) + if (0 == STRCMP(Map[i].TokenName, s)) return i; else i++; @@ -303,17 +297,15 @@ static int ParameterNameToMapIndex (Mapping *Map, char *s) * -1 for error *********************************************************************** */ -int InitParams(Mapping *Map) -{ +int InitParams(Mapping *Map) { int i = 0; - while (Map[i].TokenName != NULL) - { + while (Map[i].TokenName != NULL) { if (Map[i].Type == 0) - * (int *) (Map[i].Place) = (int) Map[i].Default; + *(int *)(Map[i].Place) = (int)Map[i].Default; else if (Map[i].Type == 2) - * (double *) (Map[i].Place) = Map[i].Default; - i++; + *(double *)(Map[i].Place) = Map[i].Default; + i++; } return -1; } @@ -326,64 +318,65 @@ int InitParams(Mapping *Map) * -1 for error *********************************************************************** */ -int TestParams(Mapping *Map, int bitdepth_qp_scale[3]) -{ +int TestParams(Mapping *Map, int bitdepth_qp_scale[3]) { int i = 0; - while (Map[i].TokenName != NULL) - { - if (Map[i].param_limits == 1) - { - if (Map[i].Type == 0) - { - if ( * (int *) (Map[i].Place) < (int) Map[i].min_limit || * (int *) (Map[i].Place) > (int) Map[i].max_limit ) - { - snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should be in [%d, %d] range.", Map[i].TokenName, (int) Map[i].min_limit,(int)Map[i].max_limit ); - error (errortext, 400); + while (Map[i].TokenName != NULL) { + if (Map[i].param_limits == 1) { + if (Map[i].Type == 0) { + if (*(int *)(Map[i].Place) < (int)Map[i].min_limit || + *(int *)(Map[i].Place) > (int)Map[i].max_limit) { + snprintf(errortext, ET_SIZE, + "Error in input parameter %s. Check configuration file. " + "Value should be in [%d, %d] range.", + Map[i].TokenName, (int)Map[i].min_limit, + (int)Map[i].max_limit); + error(errortext, 400); } - } - else if (Map[i].Type == 2) - { - if ( * (double *) (Map[i].Place) < Map[i].min_limit || * (double *) (Map[i].Place) > Map[i].max_limit ) - { - snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should be in [%.2f, %.2f] range.", Map[i].TokenName,Map[i].min_limit ,Map[i].max_limit ); - error (errortext, 400); + } else if (Map[i].Type == 2) { + if (*(double *)(Map[i].Place) < Map[i].min_limit || + *(double *)(Map[i].Place) > Map[i].max_limit) { + snprintf(errortext, ET_SIZE, + "Error in input parameter %s. Check configuration file. " + "Value should be in [%.2f, %.2f] range.", + Map[i].TokenName, Map[i].min_limit, Map[i].max_limit); + error(errortext, 400); } } - } - else if (Map[i].param_limits == 2) + } else if (Map[i].param_limits == 2) { + if (Map[i].Type == 0) { + if (*(int *)(Map[i].Place) < (int)Map[i].min_limit) { + snprintf(errortext, ET_SIZE, + "Error in input parameter %s. Check configuration file. " + "Value should not be smaller than %d.", + Map[i].TokenName, (int)Map[i].min_limit); + error(errortext, 400); + } + } else if (Map[i].Type == 2) { + if (*(double *)(Map[i].Place) < Map[i].min_limit) { + snprintf(errortext, ET_SIZE, + "Error in input parameter %s. Check configuration file. " + "Value should not be smaller than %2.f.", + Map[i].TokenName, Map[i].min_limit); + error(errortext, 400); + } + } + } else if (Map[i].param_limits == 3) // Only used for QPs { - if (Map[i].Type == 0) - { - if ( * (int *) (Map[i].Place) < (int) Map[i].min_limit ) - { - snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should not be smaller than %d.", Map[i].TokenName, (int) Map[i].min_limit); - error (errortext, 400); - } - } - else if (Map[i].Type == 2) - { - if ( * (double *) (Map[i].Place) < Map[i].min_limit ) - { - snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should not be smaller than %2.f.", Map[i].TokenName,Map[i].min_limit); - error (errortext, 400); - } - } - } - else if (Map[i].param_limits == 3) // Only used for QPs - { - - if (Map[i].Type == 0) - { - int cur_qp = * (int *) (Map[i].Place); - int min_qp = (int) (Map[i].min_limit - (bitdepth_qp_scale? bitdepth_qp_scale[0]: 0)); - int max_qp = (int) Map[i].max_limit; - - if (( cur_qp < min_qp ) || ( cur_qp > max_qp )) - { - snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should be in [%d, %d] range.", Map[i].TokenName, min_qp, max_qp ); - error (errortext, 400); + + if (Map[i].Type == 0) { + int cur_qp = *(int *)(Map[i].Place); + int min_qp = (int)(Map[i].min_limit - + (bitdepth_qp_scale ? bitdepth_qp_scale[0] : 0)); + int max_qp = (int)Map[i].max_limit; + + if ((cur_qp < min_qp) || (cur_qp > max_qp)) { + snprintf(errortext, ET_SIZE, + "Error in input parameter %s. Check configuration file. " + "Value should be in [%d, %d] range.", + Map[i].TokenName, min_qp, max_qp); + error(errortext, 400); } } } @@ -393,8 +386,6 @@ int TestParams(Mapping *Map, int bitdepth_qp_scale[3]) return -1; } - - /*! *********************************************************************** * \brief @@ -403,24 +394,25 @@ int TestParams(Mapping *Map, int bitdepth_qp_scale[3]) * -1 for error *********************************************************************** */ -int DisplayParams(Mapping *Map, char *message) -{ +int DisplayParams(Mapping *Map, char *message) { int i = 0; printf("******************************************************\n"); printf("* %s *\n", message); printf("******************************************************\n"); - while (Map[i].TokenName != NULL) - { + while (Map[i].TokenName != NULL) { if (Map[i].Type == 0) - printf("Parameter %s = %d\n",Map[i].TokenName,* (int *) (Map[i].Place)); + printf("Parameter %s = %d\n", Map[i].TokenName, *(int *)(Map[i].Place)); else if (Map[i].Type == 1) - printf("Parameter %s = ""%s""\n",Map[i].TokenName,(char *) (Map[i].Place)); + printf("Parameter %s = " + "%s" + "\n", + Map[i].TokenName, (char *)(Map[i].Place)); else if (Map[i].Type == 2) - printf("Parameter %s = %.2f\n",Map[i].TokenName,* (double *) (Map[i].Place)); - i++; + printf("Parameter %s = %.2f\n", Map[i].TokenName, + *(double *)(Map[i].Place)); + i++; } printf("******************************************************\n"); return i; } - diff --git a/src/common/ldecod_src/configfile.c b/src/common/ldecod_src/configfile.c index 1f63638..8219104 100644 --- a/src/common/ldecod_src/configfile.c +++ b/src/common/ldecod_src/configfile.c @@ -6,39 +6,36 @@ * \brief * Configuration handling. * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and affiliation + *details) * - Stephan Wenger * \note * In the future this module should hide the Parameters and offer only - * Functions for their access. Modules which make frequent use of some parameters - * (e.g. picture size in macroblocks) are free to buffer them on local variables. - * This will not only avoid global variable and make the code more readable, but also - * speed it up. It will also greatly facilitate future enhancements such as the - * handling of different picture sizes in the same sequence. \n - * \n - * For now, everything is just copied to the inp_par structure (gulp) + * Functions for their access. Modules which make frequent use of some + *parameters (e.g. picture size in macroblocks) are free to buffer them on local + *variables. This will not only avoid global variable and make the code more + *readable, but also speed it up. It will also greatly facilitate future + *enhancements such as the handling of different picture sizes in the same + *sequence. \n \n For now, everything is just copied to + *the inp_par structure (gulp) * ************************************************************************************** * \par Configuration File Format ************************************************************************************** - * Format is line oriented, maximum of one parameter per line \n - * \n - * Lines have the following format: \n - * \ = \ # Comments \\n \n - * Whitespace is space and \\t - * \par - * \ are the predefined names for Parameters and are case sensitive. - * See configfile.h for the definition of those names and their mapping to - * cfgparams->values. - * \par + * Format is line oriented, maximum of one parameter per line \n \n Lines have + *the following format: \n + * \ = \ # Comments \\n \n Whitespace is space + *and \\t \par + * \ are the predefined names for Parameters and are case + *sensitive. See configfile.h for the definition of those names and their + *mapping to cfgparams->values. \par * \ are either integers [0..9]* or strings. - * Integers must fit into the wordlengths, signed values are generally assumed. - * Strings containing no whitespace characters can be used directly. Strings containing - * whitespace characters are to be inclosed in double quotes ("string with whitespace") - * The double quote character is forbidden (may want to implement something smarter here). - * \par - * Any Parameters whose ParameterName is undefined lead to the termination of the program - * with an error message. + * Integers must fit into the wordlengths, signed values are generally + *assumed. Strings containing no whitespace characters can be used directly. + *Strings containing whitespace characters are to be inclosed in double quotes + *("string with whitespace") The double quote character is forbidden (may want + *to implement something smarter here). \par Any Parameters whose ParameterName + *is undefined lead to the termination of the program with an error message. * * \par Known bug/Shortcoming: * zero-length strings (i.e. to signal an non-existing file @@ -46,13 +43,14 @@ * * \par Rules for using command files * \n - * All Parameters are initially taken from DEFAULTCONFIGFILENAME, defined in configfile.h. - * If an -f \ parameter is present in the command line then this file is used to - * update the defaults of DEFAULTCONFIGFILENAME. There can be more than one -f parameters - * present. If -p parameters are present then these - * override the default and the additional config file's settings, and are themselves - * overridden by future -p parameters. There must be whitespace between -f and -p commands - * and their respective parameters + * All Parameters are initially taken from DEFAULTCONFIGFILENAME, defined in + *configfile.h. If an -f \ parameter is present in the command line + *then this file is used to update the defaults of DEFAULTCONFIGFILENAME. There + *can be more than one -f parameters present. If -p parameters are present then these override the default and the + *additional config file's settings, and are themselves overridden by future -p + *parameters. There must be whitespace between -f and -p commands and their + *respective parameters *********************************************************************** */ @@ -60,13 +58,13 @@ #include -#include "global.h" -#include "memalloc.h" #include "config_common.h" #include "configfile.h" -#define MAX_ITEMS_TO_PARSE 10000 +#include "global.h" +#include "memalloc.h" +#define MAX_ITEMS_TO_PARSE 10000 -static void PatchInp (InputParameters *p_Inp); +static void PatchInp(InputParameters *p_Inp); /*! *********************************************************************** @@ -74,43 +72,46 @@ static void PatchInp (InputParameters *p_Inp); * print help message and exit *********************************************************************** */ -void JMDecHelpExit (void) -{ - fprintf( stderr, "\n ldecod [-h] [-d defdec.cfg] {[-f curenc1.cfg]...[-f curencN.cfg]}" - " {[-p EncParam1=EncValue1]..[-p EncParamM=EncValueM]}\n\n" - "## Parameters\n\n" +void JMDecHelpExit(void) { + fprintf( + stderr, + "\n ldecod [-h] [-d defdec.cfg] {[-f curenc1.cfg]...[-f curencN.cfg]}" + " {[-p EncParam1=EncValue1]..[-p EncParamM=EncValueM]}\n\n" + "## Parameters\n\n" - "## Options\n" - " -h : prints function usage\n" - " -d : use as default file for parameter initializations.\n" - " If not used then file defaults to encoder.cfg in local directory.\n" - " -f : read for reseting selected encoder parameters.\n" - " Multiple files could be used that set different parameters\n" - " -p : Set parameter to .\n" - " See default decoder.cfg file for description of all parameters.\n\n" + "## Options\n" + " -h : prints function usage\n" + " -d : use as default file for parameter " + "initializations.\n" + " If not used then file defaults to encoder.cfg in local " + "directory.\n" + " -f : read for reseting selected encoder parameters.\n" + " Multiple files could be used that set different parameters\n" + " -p : Set parameter to .\n" + " See default decoder.cfg file for description of all " + "parameters.\n\n" - "## Examples of usage:\n" - " ldecod\n" - " ldecod -h\n" - " ldecod -d default.cfg\n" - " ldecod -f curenc1.cfg\n" - " ldecod -f curenc1.cfg -p InputFile=\"e:\\data\\container_qcif_30.264\" -p OutputFile=\"dec.yuv\" -p RefFile=\"Rec.yuv\"\n"); + "## Examples of usage:\n" + " ldecod\n" + " ldecod -h\n" + " ldecod -d default.cfg\n" + " ldecod -f curenc1.cfg\n" + " ldecod -f curenc1.cfg -p " + "InputFile=\"e:\\data\\container_qcif_30.264\" -p OutputFile=\"dec.yuv\" " + "-p RefFile=\"Rec.yuv\"\n"); exit(-1); } - /*! ************************************************************************ * \brief * exit with error message if reading from config file failed ************************************************************************ */ -static inline void conf_read_check (int val, int expected) -{ - if (val != expected) - { - error ("init_conf: error reading from config file", 500); +static inline void conf_read_check(int val, int expected) { + if (val != expected) { + error("init_conf: error reading from config file", 500); } } @@ -128,16 +129,13 @@ static inline void conf_read_check (int val, int expected) * command line parameters *********************************************************************** */ -void ParseCommand(InputParameters *p_Inp, int ac, char *av[]) -{ +void ParseCommand(InputParameters *p_Inp, int ac, char *av[]) { char *content = NULL; int CLcount, ContentLen, NumberParams; - char *filename=DEFAULTCONFIGFILENAME; + char *filename = DEFAULTCONFIGFILENAME; - if (ac==2) - { - if (0 == strncmp (av[1], "-v", 2)) - { + if (ac == 2) { + if (0 == strncmp(av[1], "-v", 2)) { #if !defined(SPEC) printf("JM " JM ": compiled " __DATE__ " " __TIME__ "\n"); #else @@ -146,103 +144,99 @@ void ParseCommand(InputParameters *p_Inp, int ac, char *av[]) exit(-1); } - if (0 == strncmp (av[1], "-h", 2)) - { + if (0 == strncmp(av[1], "-h", 2)) { JMDecHelpExit(); } } - memset (&cfgparams, 0, sizeof (InputParameters)); - //Set default parameters. - printf ("Setting Default Parameters...\n"); + memset(&cfgparams, 0, sizeof(InputParameters)); + // Set default parameters. + printf("Setting Default Parameters...\n"); InitParams(Map); // Process default config file CLcount = 1; - if (ac>=3) - { - if (0 == strncmp (av[1], "-d", 2)) - { - if(0 == strncmp (av[2], "null", 4)) - filename=NULL; + if (ac >= 3) { + if (0 == strncmp(av[1], "-d", 2)) { + if (0 == strncmp(av[2], "null", 4)) + filename = NULL; else - filename=av[2]; + filename = av[2]; CLcount = 3; } - if (0 == strncmp (av[1], "-h", 2)) - { + if (0 == strncmp(av[1], "-h", 2)) { JMDecHelpExit(); } } - if(filename) - { - printf ("Parsing Configfile %s\n", filename); - content = GetConfigFileContent (filename); - if (NULL != content) - { - //error (errortext, 300); - ParseContent (p_Inp, Map, content, (int) strlen(content)); - printf ("\n"); - free (content); + if (filename) { + printf("Parsing Configfile %s\n", filename); + content = GetConfigFileContent(filename); + if (NULL != content) { + // error (errortext, 300); + ParseContent(p_Inp, Map, content, (int)strlen(content)); + printf("\n"); + free(content); } } // Parse the command line - while (CLcount < ac) - { - if (0 == strncmp (av[CLcount], "-h", 2)) - { + while (CLcount < ac) { + if (0 == strncmp(av[CLcount], "-h", 2)) { JMDecHelpExit(); } - if (0 == strncmp (av[CLcount], "-f", 2) || 0 == strncmp (av[CLcount], "-F", 2)) // A file parameter? + if (0 == strncmp(av[CLcount], "-f", 2) || + 0 == strncmp(av[CLcount], "-F", 2)) // A file parameter? { - content = GetConfigFileContent (av[CLcount+1]); - if (NULL==content) - error (errortext, 300); - printf ("Parsing Configfile %s", av[CLcount+1]); - ParseContent (p_Inp, Map, content, (int) strlen (content)); - printf ("\n"); - free (content); + content = GetConfigFileContent(av[CLcount + 1]); + if (NULL == content) + error(errortext, 300); + printf("Parsing Configfile %s", av[CLcount + 1]); + ParseContent(p_Inp, Map, content, (int)strlen(content)); + printf("\n"); + free(content); CLcount += 2; - } - else if (0 == strncmp (av[CLcount], "-i", 2) || 0 == strncmp (av[CLcount], "-I", 2)) // A file parameter? + } else if (0 == strncmp(av[CLcount], "-i", 2) || + 0 == strncmp(av[CLcount], "-I", 2)) // A file parameter? { - strncpy(p_Inp->infile, av[CLcount+1], FILE_NAME_SIZE); + strncpy(p_Inp->infile, av[CLcount + 1], FILE_NAME_SIZE); CLcount += 2; - } - else if (0 == strncmp (av[CLcount], "-r", 2) || 0 == strncmp (av[CLcount], "-R", 2)) // A file parameter? + } else if (0 == strncmp(av[CLcount], "-r", 2) || + 0 == strncmp(av[CLcount], "-R", 2)) // A file parameter? { - strncpy(p_Inp->reffile, av[CLcount+1], FILE_NAME_SIZE); + strncpy(p_Inp->reffile, av[CLcount + 1], FILE_NAME_SIZE); CLcount += 2; - } - else if (0 == strncmp (av[CLcount], "-o", 2) || 0 == strncmp (av[CLcount], "-O", 2)) // A file parameter? + } else if (0 == strncmp(av[CLcount], "-o", 2) || + 0 == strncmp(av[CLcount], "-O", 2)) // A file parameter? { - strncpy(p_Inp->outfile, av[CLcount+1], FILE_NAME_SIZE); + strncpy(p_Inp->outfile, av[CLcount + 1], FILE_NAME_SIZE); CLcount += 2; - } - else if (0 == strncmp (av[CLcount], "-s", 2) || 0 == strncmp (av[CLcount], "-S", 2)) // A file parameter? + } else if (0 == strncmp(av[CLcount], "-s", 2) || + 0 == strncmp(av[CLcount], "-S", 2)) // A file parameter? { p_Inp->silent = 1; CLcount += 1; - } - else if (0 == strncmp (av[CLcount], "-n", 2) || 0 == strncmp (av[CLcount], "-N", 2)) // A file parameter? + } else if (0 == strncmp(av[CLcount], "-n", 2) || + 0 == strncmp(av[CLcount], "-N", 2)) // A file parameter? { - conf_read_check (sscanf(av[CLcount+1],"%d", &p_Inp->iDecFrmNum), 1); + conf_read_check(sscanf(av[CLcount + 1], "%d", &p_Inp->iDecFrmNum), 1); CLcount += 2; } #if (MVC_EXTENSION_ENABLE) - else if (0 == strncmp (av[CLcount], "-mpr", 4) || 0 == strncmp (av[CLcount], "-MPR", 4)) // A file parameter? + else if (0 == strncmp(av[CLcount], "-mpr", 4) || + 0 == strncmp(av[CLcount], "-MPR", 4)) // A file parameter? { - conf_read_check (sscanf(av[CLcount+1],"%d", &p_Inp->DecodeAllLayers), 1); + conf_read_check(sscanf(av[CLcount + 1], "%d", &p_Inp->DecodeAllLayers), + 1); CLcount += 2; - } + } #endif - else if (0 == strncmp (av[CLcount], "-p", 2) || 0 == strncmp (av[CLcount], "-P", 2)) // A config change? + else if (0 == strncmp(av[CLcount], "-p", 2) || + 0 == strncmp(av[CLcount], "-P", 2)) // A config change? { - // Collect all data until next parameter (starting with - (x is any character)), - // put it into content, and parse content. + // Collect all data until next parameter (starting with - (x is any + // character)), put it into content, and parse content. ++CLcount; ContentLen = 0; @@ -250,46 +244,49 @@ void ParseCommand(InputParameters *p_Inp, int ac, char *av[]) // determine the necessary size for content while (NumberParams < ac && av[NumberParams][0] != '-') - ContentLen += (int) strlen (av[NumberParams++]); // Space for all the strings - ContentLen += 1000; // Additional 1000 bytes for spaces and \0s + ContentLen += + (int)strlen(av[NumberParams++]); // Space for all the strings + ContentLen += 1000; // Additional 1000 bytes for spaces and \0s - - if ((content = malloc (ContentLen))==NULL) no_mem_exit("Configure: content");; + if ((content = malloc(ContentLen)) == NULL) + no_mem_exit("Configure: content"); + ; content[0] = '\0'; // concatenate all parameters identified before - while (CLcount < NumberParams) - { + while (CLcount < NumberParams) { char *source = &av[CLcount][0]; - char *destin = &content[(int) strlen (content)]; + char *destin = &content[(int)strlen(content)]; - while (*source != '\0') - { - if (*source == '=') // The Parser expects whitespace before and after '=' + while (*source != '\0') { + if (*source == + '=') // The Parser expects whitespace before and after '=' { - *destin++=' '; *destin++='='; *destin++=' '; // Hence make sure we add it - } - else - *destin++=*source; + *destin++ = ' '; + *destin++ = '='; + *destin++ = ' '; // Hence make sure we add it + } else + *destin++ = *source; source++; } *destin = '\0'; CLcount++; } - printf ("Parsing command line string '%s'", content); - ParseContent (p_Inp, Map, content, (int) strlen(content)); - free (content); - printf ("\n"); - } - else - { - snprintf (errortext, ET_SIZE, "Error in command line, ac %d, around string '%s', missing -f or -p parameters?", CLcount, av[CLcount]); - error (errortext, 300); + printf("Parsing command line string '%s'", content); + ParseContent(p_Inp, Map, content, (int)strlen(content)); + free(content); + printf("\n"); + } else { + snprintf(errortext, ET_SIZE, + "Error in command line, ac %d, around string '%s', missing -f " + "or -p parameters?", + CLcount, av[CLcount]); + error(errortext, 300); } } - printf ("\n"); - + printf("\n"); + PatchInp(p_Inp); cfgparams = *p_Inp; p_Inp->enable_32_pulldown = 0; @@ -297,19 +294,15 @@ void ParseCommand(InputParameters *p_Inp, int ac, char *av[]) DisplayParams(Map, "Decoder Parameters"); } - /*! *********************************************************************** * \brief * Checks the input parameters for consistency. *********************************************************************** */ -static void PatchInp (InputParameters *p_Inp) -{ - //int i; - //int storedBplus1; +static void PatchInp(InputParameters *p_Inp) { + // int i; + // int storedBplus1; TestParams(Map, NULL); - } - diff --git a/src/common/ldecod_src/context_ini.c b/src/common/ldecod_src/context_ini.c index 0f047a8..d698806 100644 --- a/src/common/ldecod_src/context_ini.c +++ b/src/common/ldecod_src/context_ini.c @@ -7,7 +7,8 @@ * CABAC context initializations * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Detlev Marpe * - Heiko Schwarz ************************************************************************************** @@ -15,108 +16,127 @@ #define CONTEXT_INI_C -#include "defines.h" -#include "global.h" #include "biaridecod.h" #include "ctx_tables.h" +#include "defines.h" +#include "global.h" +#define IBIARI_CTX_INIT2(ii, jj, ctx, tab, num, qp) \ + { \ + for (i = 0; i < ii; ++i) \ + for (j = 0; j < jj; ++j) { \ + biari_init_context(qp, &(ctx[i][j]), tab##_I[num][i][j]); \ + } \ + } -#define IBIARI_CTX_INIT2(ii,jj,ctx,tab,num, qp) \ -{ \ - for (i=0; imot_ctx; - TextureInfoContexts* tc = currSlice->tex_ctx; +void init_contexts(Slice *currSlice) { + MotionInfoContexts *mc = currSlice->mot_ctx; + TextureInfoContexts *tc = currSlice->tex_ctx; int i, j; - int qp = imax(0, currSlice->qp); //p_Vid->qp); + int qp = imax(0, currSlice->qp); // p_Vid->qp); int model_number = currSlice->model_number; - //printf("%d -", p_Vid->currentSlice->model_number); + // printf("%d -", p_Vid->currentSlice->model_number); //--- motion coding contexts --- - if ((currSlice->slice_type == I_SLICE)||(currSlice->slice_type == SI_SLICE)) - { - IBIARI_CTX_INIT2 (3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, model_number, qp); - IBIARI_CTX_INIT2 (2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, model_number, qp); - IBIARI_CTX_INIT2 (2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, model_number, qp); - IBIARI_CTX_INIT2 (2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, model_number, qp); - IBIARI_CTX_INIT1 ( NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, model_number, qp); - IBIARI_CTX_INIT1 ( NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, model_number, qp); + if ((currSlice->slice_type == I_SLICE) || + (currSlice->slice_type == SI_SLICE)) { + IBIARI_CTX_INIT2(3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, + model_number, qp); + IBIARI_CTX_INIT2(2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, + model_number, qp); + IBIARI_CTX_INIT2(2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, + model_number, qp); + IBIARI_CTX_INIT2(2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, + model_number, qp); + IBIARI_CTX_INIT1(NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, + model_number, qp); + IBIARI_CTX_INIT1(NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, + model_number, qp); //--- texture coding contexts --- - IBIARI_CTX_INIT1 ( NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, INIT_TRANSFORM_SIZE, model_number, qp); - IBIARI_CTX_INIT1 ( NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp); - IBIARI_CTX_INIT1 ( NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, qp); - IBIARI_CTX_INIT2 (3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, qp); - IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, INIT_BCBP, model_number, qp); - IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], INIT_MAP, model_number, qp); + IBIARI_CTX_INIT1(NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, + INIT_TRANSFORM_SIZE, model_number, qp); + IBIARI_CTX_INIT1(NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp); + IBIARI_CTX_INIT1(NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, + qp); + IBIARI_CTX_INIT2(3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, + qp); + IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, + INIT_BCBP, model_number, qp); + IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], + INIT_MAP, model_number, qp); #if ENABLE_FIELD_CTX - IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], INIT_FLD_MAP, model_number, qp); - IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], INIT_FLD_LAST, model_number, qp); + IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], + INIT_FLD_MAP, model_number, qp); + IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], + INIT_FLD_LAST, model_number, qp); #endif - IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], INIT_LAST, model_number, qp); - IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, model_number, qp); - IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, model_number, qp); - } - else - { - PBIARI_CTX_INIT2 (3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, model_number, qp); - PBIARI_CTX_INIT2 (2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, model_number, qp); - PBIARI_CTX_INIT2 (2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, model_number, qp); - PBIARI_CTX_INIT2 (2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, model_number, qp); - PBIARI_CTX_INIT1 ( NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, model_number, qp); - PBIARI_CTX_INIT1 ( NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, model_number, qp); + IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], + INIT_LAST, model_number, qp); + IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, + model_number, qp); + IBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, + model_number, qp); + } else { + PBIARI_CTX_INIT2(3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, + model_number, qp); + PBIARI_CTX_INIT2(2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, + model_number, qp); + PBIARI_CTX_INIT2(2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, + model_number, qp); + PBIARI_CTX_INIT2(2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, + model_number, qp); + PBIARI_CTX_INIT1(NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, + model_number, qp); + PBIARI_CTX_INIT1(NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, + model_number, qp); //--- texture coding contexts --- - PBIARI_CTX_INIT1 ( NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, INIT_TRANSFORM_SIZE, model_number, qp); - PBIARI_CTX_INIT1 ( NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp); - PBIARI_CTX_INIT1 ( NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, qp); - PBIARI_CTX_INIT2 (3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, qp); - PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, INIT_BCBP, model_number, qp); - PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], INIT_MAP, model_number, qp); + PBIARI_CTX_INIT1(NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, + INIT_TRANSFORM_SIZE, model_number, qp); + PBIARI_CTX_INIT1(NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp); + PBIARI_CTX_INIT1(NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, + qp); + PBIARI_CTX_INIT2(3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, + qp); + PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, + INIT_BCBP, model_number, qp); + PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], + INIT_MAP, model_number, qp); #if ENABLE_FIELD_CTX - PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], INIT_FLD_MAP, model_number, qp); - PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], INIT_FLD_LAST, model_number, qp); + PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], + INIT_FLD_MAP, model_number, qp); + PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], + INIT_FLD_LAST, model_number, qp); #endif - PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], INIT_LAST, model_number, qp); - PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, model_number, qp); - PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, model_number, qp); + PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], + INIT_LAST, model_number, qp); + PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, + model_number, qp); + PBIARI_CTX_INIT2(NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, + model_number, qp); } } - diff --git a/src/common/ldecod_src/decoder_test.c b/src/common/ldecod_src/decoder_test.c index b33e68c..d638c50 100644 --- a/src/common/ldecod_src/decoder_test.c +++ b/src/common/ldecod_src/decoder_test.c @@ -4,9 +4,10 @@ * \file * decoder_test.c * \brief - * H.264/AVC decoder test + * H.264/AVC decoder test * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Yuwen He *********************************************************************** */ @@ -15,44 +16,44 @@ #include -//#include "global.h" -#include "h264decoder.h" +// #include "global.h" #include "configfile.h" +#include "h264decoder.h" -#define DECOUTPUT_TEST 0 +#define DECOUTPUT_TEST 0 -#define PRINT_OUTPUT_POC 0 -#define BITSTREAM_FILENAME "test.264" -#define DECRECON_FILENAME "test_dec.yuv" -#define ENCRECON_FILENAME "test_rec.yuv" -#define DECOUTPUT_VIEW0_FILENAME "H264_Decoder_Output_View0.yuv" -#define DECOUTPUT_VIEW1_FILENAME "H264_Decoder_Output_View1.yuv" +#define PRINT_OUTPUT_POC 0 +#define BITSTREAM_FILENAME "test.264" +#define DECRECON_FILENAME "test_dec.yuv" +#define ENCRECON_FILENAME "test_rec.yuv" +#define DECOUTPUT_VIEW0_FILENAME "H264_Decoder_Output_View0.yuv" +#define DECOUTPUT_VIEW1_FILENAME "H264_Decoder_Output_View1.yuv" - -static void Configure(InputParameters *p_Inp, int ac, char *av[]) -{ - //char *config_filename=NULL; - //char errortext[ET_SIZE]; +static void Configure(InputParameters *p_Inp, int ac, char *av[]) { + // char *config_filename=NULL; + // char errortext[ET_SIZE]; memset(p_Inp, 0, sizeof(InputParameters)); strcpy(p_Inp->infile, BITSTREAM_FILENAME); //! set default bitstream name strcpy(p_Inp->outfile, DECRECON_FILENAME); //! set default output file name strcpy(p_Inp->reffile, ENCRECON_FILENAME); //! set default reference file name - + p_Inp->FileFormat = PAR_OF_ANNEXB; - p_Inp->ref_offset=0; - p_Inp->poc_scale=2; + p_Inp->ref_offset = 0; + p_Inp->poc_scale = 2; p_Inp->silent = FALSE; p_Inp->intra_profile_deblocking = 0; #ifdef _LEAKYBUCKET_ - p_Inp->R_decoder=500000; //! Decoder rate - p_Inp->B_decoder=104000; //! Decoder buffer size - p_Inp->F_decoder=73000; //! Decoder initial delay - strcpy(p_Inp->LeakyBucketParamFile,"leakybucketparam.cfg"); // file where Leaky Bucket parameters (computed by encoder) are stored + p_Inp->R_decoder = 500000; //! Decoder rate + p_Inp->B_decoder = 104000; //! Decoder buffer size + p_Inp->F_decoder = 73000; //! Decoder initial delay + strcpy(p_Inp->LeakyBucketParamFile, + "leakybucketparam.cfg"); // file where Leaky Bucket parameters + // (computed by encoder) are stored #endif p_Inp->iDecFrmNum = 0; - p_Inp->write_uv=1; + p_Inp->write_uv = 1; // picture error concealment p_Inp->conceal_mode = 0; p_Inp->ref_poc_gap = 2; @@ -60,116 +61,123 @@ static void Configure(InputParameters *p_Inp, int ac, char *av[]) ParseCommand(p_Inp, ac, av); - fprintf(stdout,"----------------------------- JM %s %s -----------------------------\n", VERSION, EXT_VERSION); - //fprintf(stdout," Decoder config file : %s \n",config_filename); - if(!p_Inp->bDisplayDecParams) - { - fprintf(stdout,"--------------------------------------------------------------------------\n"); - fprintf(stdout," Input H.264 bitstream : %s \n",p_Inp->infile); - fprintf(stdout," Output decoded YUV : %s \n",p_Inp->outfile); - //fprintf(stdout," Output status file : %s \n",LOGFILE); - fprintf(stdout," Input reference file : %s \n",p_Inp->reffile); + fprintf( + stdout, + "----------------------------- JM %s %s -----------------------------\n", + VERSION, EXT_VERSION); + // fprintf(stdout," Decoder config file : %s + // \n",config_filename); + if (!p_Inp->bDisplayDecParams) { + fprintf(stdout, "----------------------------------------------------------" + "----------------\n"); + fprintf(stdout, " Input H.264 bitstream : %s \n", + p_Inp->infile); + fprintf(stdout, " Output decoded YUV : %s \n", + p_Inp->outfile); + // fprintf(stdout," Output status file : %s + // \n",LOGFILE); + fprintf(stdout, " Input reference file : %s \n", + p_Inp->reffile); - fprintf(stdout,"--------------------------------------------------------------------------\n"); - #ifdef _LEAKYBUCKET_ - fprintf(stdout," Rate_decoder : %8ld \n",p_Inp->R_decoder); - fprintf(stdout," B_decoder : %8ld \n",p_Inp->B_decoder); - fprintf(stdout," F_decoder : %8ld \n",p_Inp->F_decoder); - fprintf(stdout," LeakyBucketParamFile: %s \n",p_Inp->LeakyBucketParamFile); // Leaky Bucket Param file + fprintf(stdout, "----------------------------------------------------------" + "----------------\n"); +#ifdef _LEAKYBUCKET_ + fprintf(stdout, " Rate_decoder : %8ld \n", p_Inp->R_decoder); + fprintf(stdout, " B_decoder : %8ld \n", p_Inp->B_decoder); + fprintf(stdout, " F_decoder : %8ld \n", p_Inp->F_decoder); + fprintf(stdout, " LeakyBucketParamFile: %s \n", + p_Inp->LeakyBucketParamFile); // Leaky Bucket Param file calc_buffer(p_Inp); - fprintf(stdout,"--------------------------------------------------------------------------\n"); - #endif + fprintf(stdout, "----------------------------------------------------------" + "----------------\n"); +#endif } - if (!p_Inp->silent) - { - fprintf(stdout,"POC must = frame# or field# for SNRs to be correct\n"); - fprintf(stdout,"--------------------------------------------------------------------------\n"); - fprintf(stdout," Frame POC Pic# QP SnrY SnrU SnrV Y:U:V Time(ms)\n"); - fprintf(stdout,"--------------------------------------------------------------------------\n"); + if (!p_Inp->silent) { + fprintf(stdout, "POC must = frame# or field# for SNRs to be correct\n"); + fprintf(stdout, "----------------------------------------------------------" + "----------------\n"); + fprintf(stdout, " Frame POC Pic# QP SnrY SnrU SnrV " + " Y:U:V Time(ms)\n"); + fprintf(stdout, "----------------------------------------------------------" + "----------------\n"); } - } /********************************************************* -if bOutputAllFrames is 1, then output all valid frames to file onetime; +if bOutputAllFrames is 1, then output all valid frames to file onetime; else output the first valid frame and move the buffer to the end of list; *********************************************************/ -static int WriteOneFrame(DecodedPicList *pDecPic, int hFileOutput0, int hFileOutput1, int bOutputAllFrames) -{ - int iOutputFrame=0; +static int WriteOneFrame(DecodedPicList *pDecPic, int hFileOutput0, + int hFileOutput1, int bOutputAllFrames) { + int iOutputFrame = 0; DecodedPicList *pPic = pDecPic; - if(pPic && (((pPic->iYUVStorageFormat==2) && pPic->bValid==3) || ((pPic->iYUVStorageFormat!=2) && pPic->bValid==1)) ) - { + if (pPic && (((pPic->iYUVStorageFormat == 2) && pPic->bValid == 3) || + ((pPic->iYUVStorageFormat != 2) && pPic->bValid == 1))) { int i, iWidth, iHeight, iStride, iWidthUV, iHeightUV, iStrideUV; - byte *pbBuf; + byte *pbBuf; int hFileOutput; - iWidth = pPic->iWidth*((pPic->iBitDepth+7)>>3); + iWidth = pPic->iWidth * ((pPic->iBitDepth + 7) >> 3); iHeight = pPic->iHeight; iStride = pPic->iYBufStride; - if(pPic->iYUVFormat != YUV444) - iWidthUV = pPic->iWidth>>1; + if (pPic->iYUVFormat != YUV444) + iWidthUV = pPic->iWidth >> 1; else iWidthUV = pPic->iWidth; - if(pPic->iYUVFormat == YUV420) - iHeightUV = pPic->iHeight>>1; + if (pPic->iYUVFormat == YUV420) + iHeightUV = pPic->iHeight >> 1; else iHeightUV = pPic->iHeight; - iWidthUV *= ((pPic->iBitDepth+7)>>3); + iWidthUV *= ((pPic->iBitDepth + 7) >> 3); iStrideUV = pPic->iUVBufStride; - - do - { - if(pPic->iYUVStorageFormat==2) - hFileOutput = (pPic->iViewId&0xffff)? hFileOutput1 : hFileOutput0; + + do { + if (pPic->iYUVStorageFormat == 2) + hFileOutput = (pPic->iViewId & 0xffff) ? hFileOutput1 : hFileOutput0; else hFileOutput = hFileOutput0; - if(hFileOutput >=0) - { - //Y; + if (hFileOutput >= 0) { + // Y; pbBuf = pPic->pY; - for(i=0; iiYUVFormat != YUV400) - { - //U; - pbBuf = pPic->pU; - for(i=0; ipV; - for(i=0; iiYUVFormat != YUV400) { + // U; + pbBuf = pPic->pU; + for (i = 0; i < iHeightUV; i++) + write(hFileOutput, pbBuf + i * iStrideUV, iWidthUV); + // V; + pbBuf = pPic->pV; + for (i = 0; i < iHeightUV; i++) + write(hFileOutput, pbBuf + i * iStrideUV, iWidthUV); } iOutputFrame++; } - if((pPic->iYUVStorageFormat==2)) - { - hFileOutput = ((pPic->iViewId>>16)&0xffff)? hFileOutput1 : hFileOutput0; - if(hFileOutput>=0) - { - int iPicSize =iHeight*iStride; - //Y; - pbBuf = pPic->pY+iPicSize; - for(i=0; iiYUVStorageFormat == 2)) { + hFileOutput = + ((pPic->iViewId >> 16) & 0xffff) ? hFileOutput1 : hFileOutput0; + if (hFileOutput >= 0) { + int iPicSize = iHeight * iStride; + // Y; + pbBuf = pPic->pY + iPicSize; + for (i = 0; i < iHeight; i++) + write(hFileOutput, pbBuf + i * iStride, iWidth); - if(pPic->iYUVFormat != YUV400) - { - iPicSize = iHeightUV*iStrideUV; - //U; - pbBuf = pPic->pU+iPicSize; - for(i=0; ipV+iPicSize; - for(i=0; iiYUVFormat != YUV400) { + iPicSize = iHeightUV * iStrideUV; + // U; + pbBuf = pPic->pU + iPicSize; + for (i = 0; i < iHeightUV; i++) + write(hFileOutput, pbBuf + i * iStrideUV, iWidthUV); + // V; + pbBuf = pPic->pV + iPicSize; + for (i = 0; i < iHeightUV; i++) + write(hFileOutput, pbBuf + i * iStrideUV, iWidthUV); } iOutputFrame++; @@ -181,7 +189,7 @@ static int WriteOneFrame(DecodedPicList *pDecPic, int hFileOutput0, int hFileOut #endif pPic->bValid = 0; pPic = pPic->pNext; - }while(pPic != NULL && pPic->bValid && bOutputAllFrames); + } while (pPic != NULL && pPic->bValid && bOutputAllFrames); } #if PRINT_OUTPUT_POC else @@ -197,65 +205,62 @@ static int WriteOneFrame(DecodedPicList *pDecPic, int hFileOutput0, int hFileOut * main function for JM decoder *********************************************************************** */ -int main(int argc, char **argv) -{ +int main(int argc, char **argv) { int iRet; DecodedPicList *pDecPicList; - int hFileDecOutput0=-1, hFileDecOutput1=-1; - int iFramesOutput=0, iFramesDecoded=0; + int hFileDecOutput0 = -1, hFileDecOutput1 = -1; + int iFramesOutput = 0, iFramesDecoded = 0; InputParameters InputParams; #if DECOUTPUT_TEST - hFileDecOutput0 = open(DECOUTPUT_VIEW0_FILENAME, OPENFLAGS_WRITE, OPEN_PERMISSIONS); + hFileDecOutput0 = + open(DECOUTPUT_VIEW0_FILENAME, OPENFLAGS_WRITE, OPEN_PERMISSIONS); fprintf(stdout, "Decoder output view0: %s\n", DECOUTPUT_VIEW0_FILENAME); - hFileDecOutput1 = open(DECOUTPUT_VIEW1_FILENAME, OPENFLAGS_WRITE, OPEN_PERMISSIONS); + hFileDecOutput1 = + open(DECOUTPUT_VIEW1_FILENAME, OPENFLAGS_WRITE, OPEN_PERMISSIONS); fprintf(stdout, "Decoder output view1: %s\n", DECOUTPUT_VIEW1_FILENAME); #endif - //get input parameters; + // get input parameters; Configure(&InputParams, argc, argv); - //open decoder; + // open decoder; iRet = OpenDecoder(&InputParams); - if(iRet != DEC_OPEN_NOERR) - { + if (iRet != DEC_OPEN_NOERR) { fprintf(stderr, "Open encoder failed: 0x%x!\n", iRet); - return -1; //failed; + return -1; // failed; } - //decoding; - do - { + // decoding; + do { iRet = DecodeOneFrame(&pDecPicList); - if(iRet==DEC_EOS || iRet==DEC_SUCCEED) - { - //process the decoded picture, output or display; - iFramesOutput += WriteOneFrame(pDecPicList, hFileDecOutput0, hFileDecOutput1, 0); + if (iRet == DEC_EOS || iRet == DEC_SUCCEED) { + // process the decoded picture, output or display; + iFramesOutput += + WriteOneFrame(pDecPicList, hFileDecOutput0, hFileDecOutput1, 0); iFramesDecoded++; - } - else - { - //error handling; + } else { + // error handling; fprintf(stderr, "Error in decoding process: 0x%x\n", iRet); } - }while((iRet == DEC_SUCCEED) && ((p_Dec->p_Inp->iDecFrmNum==0) || (iFramesDecodedp_Inp->iDecFrmNum))); + } while ((iRet == DEC_SUCCEED) && + ((p_Dec->p_Inp->iDecFrmNum == 0) || + (iFramesDecoded < p_Dec->p_Inp->iDecFrmNum))); iRet = FinitDecoder(&pDecPicList); - iFramesOutput += WriteOneFrame(pDecPicList, hFileDecOutput0, hFileDecOutput1 , 1); + iFramesOutput += + WriteOneFrame(pDecPicList, hFileDecOutput0, hFileDecOutput1, 1); iRet = CloseDecoder(); - //quit; - if(hFileDecOutput0>=0) - { + // quit; + if (hFileDecOutput0 >= 0) { close(hFileDecOutput0); } - if(hFileDecOutput1>=0) - { + if (hFileDecOutput1 >= 0) { close(hFileDecOutput1); } - //printf("%d frames are decoded.\n", iFramesDecoded); - //printf("%d frames are decoded, %d frames output.\n", iFramesDecoded, iFramesOutput); + // printf("%d frames are decoded.\n", iFramesDecoded); + // printf("%d frames are decoded, %d frames output.\n", iFramesDecoded, + // iFramesOutput); return 0; } - - diff --git a/src/common/ldecod_src/erc_api.c b/src/common/ldecod_src/erc_api.c index e5b6e7e..f29eab3 100644 --- a/src/common/ldecod_src/erc_api.c +++ b/src/common/ldecod_src/erc_api.c @@ -4,7 +4,8 @@ * \file erc_api.c * * \brief - * External (still inside video decoder) interface for error concealment module + * External (still inside video decoder) interface for error concealment + *module * * \author * - Ari Hourunranta @@ -14,11 +15,10 @@ ************************************************************************************* */ - -#include "global.h" -#include "memalloc.h" #include "erc_api.h" #include "fast_memory.h" +#include "global.h" +#include "memalloc.h" /*! ************************************************************************ @@ -26,11 +26,12 @@ * Initinize the error concealment module ************************************************************************ */ -void ercInit(VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag) -{ +void ercInit(VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag) { ercClose(p_Vid, p_Vid->erc_errorVar); - p_Vid->erc_object_list = (objectBuffer_t *) calloc((pic_sizex * pic_sizey) >> 6, sizeof(objectBuffer_t)); - if (p_Vid->erc_object_list == NULL) no_mem_exit("ercInit: erc_object_list"); + p_Vid->erc_object_list = (objectBuffer_t *)calloc( + (pic_sizex * pic_sizey) >> 6, sizeof(objectBuffer_t)); + if (p_Vid->erc_object_list == NULL) + no_mem_exit("ercInit: erc_object_list"); // the error concealment instance is allocated p_Vid->erc_errorVar = ercOpen(); @@ -47,12 +48,12 @@ void ercInit(VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag) * The allocated ercVariables_t is returned. ************************************************************************ */ -ercVariables_t *ercOpen( void ) -{ +ercVariables_t *ercOpen(void) { ercVariables_t *errorVar = NULL; - errorVar = (ercVariables_t *)malloc( sizeof(ercVariables_t)); - if ( errorVar == NULL ) no_mem_exit("ercOpen: errorVar"); + errorVar = (ercVariables_t *)malloc(sizeof(ercVariables_t)); + if (errorVar == NULL) + no_mem_exit("ercOpen: errorVar"); errorVar->nOfMBs = 0; errorVar->segments = NULL; @@ -82,49 +83,55 @@ ercVariables_t *ercOpen( void ) * Width of the frame in pixels. ************************************************************************ */ -void ercReset( ercVariables_t *errorVar, int nOfMBs, int numOfSegments, int picSizeX ) -{ +void ercReset(ercVariables_t *errorVar, int nOfMBs, int numOfSegments, + int picSizeX) { signed char *tmp = NULL; int i = 0; - if ( errorVar && errorVar->concealment ) - { + if (errorVar && errorVar->concealment) { ercSegment_t *segments = NULL; // If frame size has been changed - if ( nOfMBs != errorVar->nOfMBs && errorVar->yCondition != NULL ) - { - free( errorVar->yCondition ); + if (nOfMBs != errorVar->nOfMBs && errorVar->yCondition != NULL) { + free(errorVar->yCondition); errorVar->yCondition = NULL; - free( errorVar->prevFrameYCondition ); + free(errorVar->prevFrameYCondition); errorVar->prevFrameYCondition = NULL; - free( errorVar->uCondition ); + free(errorVar->uCondition); errorVar->uCondition = NULL; - free( errorVar->vCondition ); + free(errorVar->vCondition); errorVar->vCondition = NULL; - free( errorVar->segments ); + free(errorVar->segments); errorVar->segments = NULL; } - // If the structures are uninitialized (first frame, or frame size is changed) - if ( errorVar->yCondition == NULL ) - { - errorVar->segments = (ercSegment_t *)malloc( numOfSegments*sizeof(ercSegment_t) ); - if ( errorVar->segments == NULL ) no_mem_exit("ercReset: errorVar->segments"); - fast_memset( errorVar->segments, 0, numOfSegments*sizeof(ercSegment_t)); + // If the structures are uninitialized (first frame, or frame size is + // changed) + if (errorVar->yCondition == NULL) { + errorVar->segments = + (ercSegment_t *)malloc(numOfSegments * sizeof(ercSegment_t)); + if (errorVar->segments == NULL) + no_mem_exit("ercReset: errorVar->segments"); + fast_memset(errorVar->segments, 0, numOfSegments * sizeof(ercSegment_t)); errorVar->nOfSegments = numOfSegments; - errorVar->yCondition = (signed char *)malloc( 4*nOfMBs*sizeof(signed char) ); - if ( errorVar->yCondition == NULL ) no_mem_exit("ercReset: errorVar->yCondition"); - errorVar->prevFrameYCondition = (signed char *)malloc( 4*nOfMBs*sizeof(signed char) ); - if ( errorVar->prevFrameYCondition == NULL ) no_mem_exit("ercReset: errorVar->prevFrameYCondition"); - errorVar->uCondition = (signed char *)malloc( nOfMBs*sizeof(signed char) ); - if ( errorVar->uCondition == NULL ) no_mem_exit("ercReset: errorVar->uCondition"); - errorVar->vCondition = (signed char *)malloc( nOfMBs*sizeof(signed char) ); - if ( errorVar->vCondition == NULL ) no_mem_exit("ercReset: errorVar->vCondition"); + errorVar->yCondition = + (signed char *)malloc(4 * nOfMBs * sizeof(signed char)); + if (errorVar->yCondition == NULL) + no_mem_exit("ercReset: errorVar->yCondition"); + errorVar->prevFrameYCondition = + (signed char *)malloc(4 * nOfMBs * sizeof(signed char)); + if (errorVar->prevFrameYCondition == NULL) + no_mem_exit("ercReset: errorVar->prevFrameYCondition"); + errorVar->uCondition = + (signed char *)malloc(nOfMBs * sizeof(signed char)); + if (errorVar->uCondition == NULL) + no_mem_exit("ercReset: errorVar->uCondition"); + errorVar->vCondition = + (signed char *)malloc(nOfMBs * sizeof(signed char)); + if (errorVar->vCondition == NULL) + no_mem_exit("ercReset: errorVar->vCondition"); errorVar->nOfMBs = nOfMBs; - } - else - { + } else { // Store the yCondition struct of the previous frame tmp = errorVar->prevFrameYCondition; errorVar->prevFrameYCondition = errorVar->yCondition; @@ -132,26 +139,30 @@ void ercReset( ercVariables_t *errorVar, int nOfMBs, int numOfSegments, int picS } // Reset tables and parameters - fast_memset( errorVar->yCondition, 0, 4*nOfMBs*sizeof(*errorVar->yCondition)); - fast_memset( errorVar->uCondition, 0, nOfMBs*sizeof(*errorVar->uCondition)); - fast_memset( errorVar->vCondition, 0, nOfMBs*sizeof(*errorVar->vCondition)); + fast_memset(errorVar->yCondition, 0, + 4 * nOfMBs * sizeof(*errorVar->yCondition)); + fast_memset(errorVar->uCondition, 0, + nOfMBs * sizeof(*errorVar->uCondition)); + fast_memset(errorVar->vCondition, 0, + nOfMBs * sizeof(*errorVar->vCondition)); - if (errorVar->nOfSegments != numOfSegments) - { - free( errorVar->segments ); + if (errorVar->nOfSegments != numOfSegments) { + free(errorVar->segments); errorVar->segments = NULL; - errorVar->segments = (ercSegment_t *)malloc( numOfSegments*sizeof(ercSegment_t) ); - if ( errorVar->segments == NULL ) no_mem_exit("ercReset: errorVar->segments"); + errorVar->segments = + (ercSegment_t *)malloc(numOfSegments * sizeof(ercSegment_t)); + if (errorVar->segments == NULL) + no_mem_exit("ercReset: errorVar->segments"); errorVar->nOfSegments = numOfSegments; } - //memset( errorVar->segments, 0, errorVar->nOfSegments * sizeof(ercSegment_t)); + // memset( errorVar->segments, 0, errorVar->nOfSegments * + // sizeof(ercSegment_t)); segments = errorVar->segments; - for ( i = 0; i < errorVar->nOfSegments; i++ ) - { + for (i = 0; i < errorVar->nOfSegments; i++) { segments->startMBPos = 0; - segments->endMBPos = (short) (nOfMBs - 1); + segments->endMBPos = (short)(nOfMBs - 1); (segments++)->fCorrupted = 1; //! mark segments as corrupted } @@ -171,71 +182,57 @@ void ercReset( ercVariables_t *errorVar, int nOfMBs, int numOfSegments, int picS * Variables for error concealment ************************************************************************ */ -void ercClose(VideoParameters *p_Vid, ercVariables_t *errorVar ) -{ - if ( errorVar != NULL ) - { - if (errorVar->yCondition != NULL) - { - free( errorVar->segments ); - free( errorVar->yCondition ); - free( errorVar->uCondition ); - free( errorVar->vCondition ); - free( errorVar->prevFrameYCondition ); +void ercClose(VideoParameters *p_Vid, ercVariables_t *errorVar) { + if (errorVar != NULL) { + if (errorVar->yCondition != NULL) { + free(errorVar->segments); + free(errorVar->yCondition); + free(errorVar->uCondition); + free(errorVar->vCondition); + free(errorVar->prevFrameYCondition); } - free( errorVar ); + free(errorVar); errorVar = NULL; } - if (p_Vid->erc_object_list) - { + if (p_Vid->erc_object_list) { free(p_Vid->erc_object_list); - p_Vid->erc_object_list=NULL; + p_Vid->erc_object_list = NULL; } } /*! ************************************************************************ * \brief - * Sets error concealment ON/OFF. Can be invoked only between frames, not during a frame - * \param errorVar - * Variables for error concealment - * \param value + * Sets error concealment ON/OFF. Can be invoked only between frames, not + *during a frame \param errorVar Variables for error concealment \param value * New value ************************************************************************ */ -void ercSetErrorConcealment( ercVariables_t *errorVar, int value ) -{ - if ( errorVar != NULL ) +void ercSetErrorConcealment(ercVariables_t *errorVar, int value) { + if (errorVar != NULL) errorVar->concealment = value; } /*! ************************************************************************ * \brief - * Creates a new segment in the segment-list, and marks the start MB and bit position. - * If the end of the previous segment was not explicitly marked by "ercStopSegment", - * also marks the end of the previous segment. - * If needed, it reallocates the segment-list for a larger storage place. - * \param currMBNum - * The MB number where the new slice/segment starts - * \param segment - * Segment/Slice No. counted by the caller - * \param bitPos - * Bitstream pointer: number of bits read from the buffer. - * \param errorVar - * Variables for error detector + * Creates a new segment in the segment-list, and marks the start MB and + *bit position. If the end of the previous segment was not explicitly marked by + *"ercStopSegment", also marks the end of the previous segment. If needed, it + *reallocates the segment-list for a larger storage place. \param currMBNum The + *MB number where the new slice/segment starts \param segment Segment/Slice No. + *counted by the caller \param bitPos Bitstream pointer: number of bits read + *from the buffer. \param errorVar Variables for error detector ************************************************************************ */ -void ercStartSegment( int currMBNum, int segment, unsigned int bitPos, ercVariables_t *errorVar ) -{ - if ( errorVar && errorVar->concealment ) - { +void ercStartSegment(int currMBNum, int segment, unsigned int bitPos, + ercVariables_t *errorVar) { + if (errorVar && errorVar->concealment) { errorVar->currSegmentCorrupted = 0; - errorVar->segments[ segment ].fCorrupted = 0; - errorVar->segments[ segment ].startMBPos = (short) currMBNum; - + errorVar->segments[segment].fCorrupted = 0; + errorVar->segments[segment].startMBPos = (short)currMBNum; } } @@ -254,11 +251,10 @@ void ercStartSegment( int currMBNum, int segment, unsigned int bitPos, ercVariab * Variables for error detector ************************************************************************ */ -void ercStopSegment( int currMBNum, int segment, unsigned int bitPos, ercVariables_t *errorVar ) -{ - if ( errorVar && errorVar->concealment ) - { - errorVar->segments[ segment ].endMBPos = (short) currMBNum; +void ercStopSegment(int currMBNum, int segment, unsigned int bitPos, + ercVariables_t *errorVar) { + if (errorVar && errorVar->concealment) { + errorVar->segments[segment].endMBPos = (short)currMBNum; errorVar->currSegment++; } } @@ -274,26 +270,23 @@ void ercStopSegment( int currMBNum, int segment, unsigned int bitPos, ercVariabl * Variables for error detector ************************************************************************ */ -void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar ) -{ +void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar) { int j = 0; int current_segment; - current_segment = errorVar->currSegment-1; - if ( errorVar && errorVar->concealment ) - { - if (errorVar->currSegmentCorrupted == 0) - { + current_segment = errorVar->currSegment - 1; + if (errorVar && errorVar->concealment) { + if (errorVar->currSegmentCorrupted == 0) { errorVar->nOfCorruptedSegments++; errorVar->currSegmentCorrupted = 1; } - for ( j = errorVar->segments[current_segment].startMBPos; j <= errorVar->segments[current_segment].endMBPos; j++ ) - { - errorVar->yCondition[MBNum2YBlock (j, 0, picSizeX)] = ERC_BLOCK_CORRUPTED; - errorVar->yCondition[MBNum2YBlock (j, 1, picSizeX)] = ERC_BLOCK_CORRUPTED; - errorVar->yCondition[MBNum2YBlock (j, 2, picSizeX)] = ERC_BLOCK_CORRUPTED; - errorVar->yCondition[MBNum2YBlock (j, 3, picSizeX)] = ERC_BLOCK_CORRUPTED; + for (j = errorVar->segments[current_segment].startMBPos; + j <= errorVar->segments[current_segment].endMBPos; j++) { + errorVar->yCondition[MBNum2YBlock(j, 0, picSizeX)] = ERC_BLOCK_CORRUPTED; + errorVar->yCondition[MBNum2YBlock(j, 1, picSizeX)] = ERC_BLOCK_CORRUPTED; + errorVar->yCondition[MBNum2YBlock(j, 2, picSizeX)] = ERC_BLOCK_CORRUPTED; + errorVar->yCondition[MBNum2YBlock(j, 3, picSizeX)] = ERC_BLOCK_CORRUPTED; errorVar->uCondition[j] = ERC_BLOCK_CORRUPTED; errorVar->vCondition[j] = ERC_BLOCK_CORRUPTED; } @@ -312,21 +305,19 @@ void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar ) * Variables for error detector ************************************************************************ */ -void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar ) -{ +void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar) { int j = 0; int current_segment; - current_segment = errorVar->currSegment-1; - if ( errorVar && errorVar->concealment ) - { + current_segment = errorVar->currSegment - 1; + if (errorVar && errorVar->concealment) { // mark all the Blocks belonging to the segment as OK */ - for ( j = errorVar->segments[current_segment].startMBPos; j <= errorVar->segments[current_segment].endMBPos; j++ ) - { - errorVar->yCondition[MBNum2YBlock (j, 0, picSizeX)] = ERC_BLOCK_OK; - errorVar->yCondition[MBNum2YBlock (j, 1, picSizeX)] = ERC_BLOCK_OK; - errorVar->yCondition[MBNum2YBlock (j, 2, picSizeX)] = ERC_BLOCK_OK; - errorVar->yCondition[MBNum2YBlock (j, 3, picSizeX)] = ERC_BLOCK_OK; + for (j = errorVar->segments[current_segment].startMBPos; + j <= errorVar->segments[current_segment].endMBPos; j++) { + errorVar->yCondition[MBNum2YBlock(j, 0, picSizeX)] = ERC_BLOCK_OK; + errorVar->yCondition[MBNum2YBlock(j, 1, picSizeX)] = ERC_BLOCK_OK; + errorVar->yCondition[MBNum2YBlock(j, 2, picSizeX)] = ERC_BLOCK_OK; + errorVar->yCondition[MBNum2YBlock(j, 3, picSizeX)] = ERC_BLOCK_OK; errorVar->uCondition[j] = ERC_BLOCK_OK; errorVar->vCondition[j] = ERC_BLOCK_OK; } @@ -337,9 +328,8 @@ void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar ) /*! ************************************************************************ * \brief - * Marks the Blocks of the given component (YUV) of the current MB as concealed. - * \param currMBNum - * Selects the segment where this MB number is in. + * Marks the Blocks of the given component (YUV) of the current MB as + *concealed. \param currMBNum Selects the segment where this MB number is in. * \param comp * Component to mark (0:Y, 1:U, 2:V, <0:All) * \param picSizeX @@ -348,25 +338,26 @@ void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar ) * Variables for error detector ************************************************************************ */ -void ercMarkCurrMBConcealed( int currMBNum, int comp, int picSizeX, ercVariables_t *errorVar ) -{ +void ercMarkCurrMBConcealed(int currMBNum, int comp, int picSizeX, + ercVariables_t *errorVar) { int setAll = 0; - if ( errorVar && errorVar->concealment ) - { - if (comp < 0) - { + if (errorVar && errorVar->concealment) { + if (comp < 0) { setAll = 1; comp = 0; } - switch (comp) - { + switch (comp) { case 0: - errorVar->yCondition[MBNum2YBlock (currMBNum, 0, picSizeX)] = ERC_BLOCK_CONCEALED; - errorVar->yCondition[MBNum2YBlock (currMBNum, 1, picSizeX)] = ERC_BLOCK_CONCEALED; - errorVar->yCondition[MBNum2YBlock (currMBNum, 2, picSizeX)] = ERC_BLOCK_CONCEALED; - errorVar->yCondition[MBNum2YBlock (currMBNum, 3, picSizeX)] = ERC_BLOCK_CONCEALED; + errorVar->yCondition[MBNum2YBlock(currMBNum, 0, picSizeX)] = + ERC_BLOCK_CONCEALED; + errorVar->yCondition[MBNum2YBlock(currMBNum, 1, picSizeX)] = + ERC_BLOCK_CONCEALED; + errorVar->yCondition[MBNum2YBlock(currMBNum, 2, picSizeX)] = + ERC_BLOCK_CONCEALED; + errorVar->yCondition[MBNum2YBlock(currMBNum, 3, picSizeX)] = + ERC_BLOCK_CONCEALED; if (!setAll) break; case 1: diff --git a/src/common/ldecod_src/erc_do_i.c b/src/common/ldecod_src/erc_do_i.c index 6db20a5..9b9c803 100644 --- a/src/common/ldecod_src/erc_do_i.c +++ b/src/common/ldecod_src/erc_do_i.c @@ -15,11 +15,15 @@ ************************************************************************************* */ -#include "global.h" #include "erc_do.h" +#include "global.h" -static void concealBlocks ( VideoParameters *p_Vid, int lastColumn, int lastRow, int comp, frame *recfr, int picSizeX, signed char *condition ); -static void pixMeanInterpolateBlock( VideoParameters *p_Vid, imgpel *src[], imgpel *block, int blockSize, int frameWidth ); +static void concealBlocks(VideoParameters *p_Vid, int lastColumn, int lastRow, + int comp, frame *recfr, int picSizeX, + signed char *condition); +static void pixMeanInterpolateBlock(VideoParameters *p_Vid, imgpel *src[], + imgpel *block, int blockSize, + int frameWidth); /*! ************************************************************************ @@ -27,9 +31,8 @@ static void pixMeanInterpolateBlock( VideoParameters *p_Vid, imgpel *src[], imgp * The main function for Intra frame concealment. * Calls "concealBlocks" for each color component (Y,U,V) separately * \return - * 0, if the concealment was not successful and simple concealment should be used - * 1, otherwise (even if none of the blocks were concealed) - * \param p_Vid + * 0, if the concealment was not successful and simple concealment should + *be used 1, otherwise (even if none of the blocks were concealed) \param p_Vid * video encoding parameters for current picture * \param recfr * Reconstructed frame buffer @@ -41,32 +44,32 @@ static void pixMeanInterpolateBlock( VideoParameters *p_Vid, imgpel *src[], imgp * Variables for error concealment ************************************************************************ */ -int ercConcealIntraFrame( VideoParameters *p_Vid, frame *recfr, int picSizeX, int picSizeY, ercVariables_t *errorVar ) -{ +int ercConcealIntraFrame(VideoParameters *p_Vid, frame *recfr, int picSizeX, + int picSizeY, ercVariables_t *errorVar) { int lastColumn = 0, lastRow = 0; // if concealment is on - if ( errorVar && errorVar->concealment ) - { + if (errorVar && errorVar->concealment) { // if there are segments to be concealed - if ( errorVar->nOfCorruptedSegments ) - { + if (errorVar->nOfCorruptedSegments) { // Y - lastRow = (int) (picSizeY>>3); - lastColumn = (int) (picSizeX>>3); - concealBlocks( p_Vid, lastColumn, lastRow, 0, recfr, picSizeX, errorVar->yCondition ); + lastRow = (int)(picSizeY >> 3); + lastColumn = (int)(picSizeX >> 3); + concealBlocks(p_Vid, lastColumn, lastRow, 0, recfr, picSizeX, + errorVar->yCondition); // U (dimensions halved compared to Y) - lastRow = (int) (picSizeY>>4); - lastColumn = (int) (picSizeX>>4); - concealBlocks( p_Vid, lastColumn, lastRow, 1, recfr, picSizeX, errorVar->uCondition ); + lastRow = (int)(picSizeY >> 4); + lastColumn = (int)(picSizeX >> 4); + concealBlocks(p_Vid, lastColumn, lastRow, 1, recfr, picSizeX, + errorVar->uCondition); // V ( dimensions equal to U ) - concealBlocks( p_Vid, lastColumn, lastRow, 2, recfr, picSizeX, errorVar->vCondition ); + concealBlocks(p_Vid, lastColumn, lastRow, 2, recfr, picSizeX, + errorVar->vCondition); } return 1; - } - else + } else return 0; } @@ -84,38 +87,42 @@ int ercConcealIntraFrame( VideoParameters *p_Vid, frame *recfr, int picSizeX, in * \param column * x coordinate in blocks * \param predBlocks[] - * list of neighboring source blocks (numbering 0 to 7, 1 means: use the neighbor) - * \param frameWidth - * width of frame in pixels - * \param mbWidthInBlocks - * 2 for Y, 1 for U/V components + * list of neighboring source blocks (numbering 0 to 7, 1 means: use the + *neighbor) \param frameWidth width of frame in pixels \param mbWidthInBlocks 2 + *for Y, 1 for U/V components ************************************************************************ */ -void ercPixConcealIMB(VideoParameters *p_Vid, imgpel *currFrame, int row, int column, int predBlocks[], int frameWidth, int mbWidthInBlocks) -{ - imgpel *src[8]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; - imgpel *currBlock = NULL; +void ercPixConcealIMB(VideoParameters *p_Vid, imgpel *currFrame, int row, + int column, int predBlocks[], int frameWidth, + int mbWidthInBlocks) { + imgpel *src[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + imgpel *currBlock = NULL; - // collect the reliable neighboring blocks - if (predBlocks[0]) - src[0] = currFrame + (row-mbWidthInBlocks)*frameWidth*8 + (column+mbWidthInBlocks)*8; - if (predBlocks[1]) - src[1] = currFrame + (row-mbWidthInBlocks)*frameWidth*8 + (column-mbWidthInBlocks)*8; - if (predBlocks[2]) - src[2] = currFrame + (row+mbWidthInBlocks)*frameWidth*8 + (column-mbWidthInBlocks)*8; - if (predBlocks[3]) - src[3] = currFrame + (row+mbWidthInBlocks)*frameWidth*8 + (column+mbWidthInBlocks)*8; - if (predBlocks[4]) - src[4] = currFrame + (row-mbWidthInBlocks)*frameWidth*8 + column*8; - if (predBlocks[5]) - src[5] = currFrame + row*frameWidth*8 + (column-mbWidthInBlocks)*8; - if (predBlocks[6]) - src[6] = currFrame + (row+mbWidthInBlocks)*frameWidth*8 + column*8; - if (predBlocks[7]) - src[7] = currFrame + row*frameWidth*8 + (column+mbWidthInBlocks)*8; + // collect the reliable neighboring blocks + if (predBlocks[0]) + src[0] = currFrame + (row - mbWidthInBlocks) * frameWidth * 8 + + (column + mbWidthInBlocks) * 8; + if (predBlocks[1]) + src[1] = currFrame + (row - mbWidthInBlocks) * frameWidth * 8 + + (column - mbWidthInBlocks) * 8; + if (predBlocks[2]) + src[2] = currFrame + (row + mbWidthInBlocks) * frameWidth * 8 + + (column - mbWidthInBlocks) * 8; + if (predBlocks[3]) + src[3] = currFrame + (row + mbWidthInBlocks) * frameWidth * 8 + + (column + mbWidthInBlocks) * 8; + if (predBlocks[4]) + src[4] = currFrame + (row - mbWidthInBlocks) * frameWidth * 8 + column * 8; + if (predBlocks[5]) + src[5] = currFrame + row * frameWidth * 8 + (column - mbWidthInBlocks) * 8; + if (predBlocks[6]) + src[6] = currFrame + (row + mbWidthInBlocks) * frameWidth * 8 + column * 8; + if (predBlocks[7]) + src[7] = currFrame + row * frameWidth * 8 + (column + mbWidthInBlocks) * 8; - currBlock = currFrame + row*frameWidth*8 + column*8; - pixMeanInterpolateBlock( p_Vid, src, currBlock, mbWidthInBlocks*8, frameWidth ); + currBlock = currFrame + row * frameWidth * 8 + column * 8; + pixMeanInterpolateBlock(p_Vid, src, currBlock, mbWidthInBlocks * 8, + frameWidth); } /*! @@ -151,79 +158,80 @@ void ercPixConcealIMB(VideoParameters *p_Vid, imgpel *currFrame, int row, int co * No corner neighbors are considered ************************************************************************ */ -int ercCollect8PredBlocks( int predBlocks[], int currRow, int currColumn, signed char *condition, - int maxRow, int maxColumn, int step, byte fNoCornerNeigh ) -{ - int srcCounter = 0; +int ercCollect8PredBlocks(int predBlocks[], int currRow, int currColumn, + signed char *condition, int maxRow, int maxColumn, + int step, byte fNoCornerNeigh) { + int srcCounter = 0; int srcCountMin = (fNoCornerNeigh ? 2 : 4); - int threshold = ERC_BLOCK_OK; + int threshold = ERC_BLOCK_OK; - memset( predBlocks, 0, 8*sizeof(int) ); + memset(predBlocks, 0, 8 * sizeof(int)); // collect the reliable neighboring blocks - do - { + do { srcCounter = 0; // top - if (currRow > 0 && condition[ (currRow-1)*maxColumn + currColumn ] >= threshold ) - { //ERC_BLOCK_OK (3) or ERC_BLOCK_CONCEALED (2) - predBlocks[4] = condition[ (currRow-1)*maxColumn + currColumn ]; + if (currRow > 0 && + condition[(currRow - 1) * maxColumn + currColumn] >= + threshold) { // ERC_BLOCK_OK (3) or ERC_BLOCK_CONCEALED (2) + predBlocks[4] = condition[(currRow - 1) * maxColumn + currColumn]; srcCounter++; } // bottom - if ( currRow < (maxRow-step) && condition[ (currRow+step)*maxColumn + currColumn ] >= threshold ) - { - predBlocks[6] = condition[ (currRow+step)*maxColumn + currColumn ]; + if (currRow < (maxRow - step) && + condition[(currRow + step) * maxColumn + currColumn] >= threshold) { + predBlocks[6] = condition[(currRow + step) * maxColumn + currColumn]; srcCounter++; } - if ( currColumn > 0 ) - { + if (currColumn > 0) { // left - if ( condition[ currRow*maxColumn + currColumn - 1 ] >= threshold ) - { - predBlocks[5] = condition[ currRow*maxColumn + currColumn - 1 ]; + if (condition[currRow * maxColumn + currColumn - 1] >= threshold) { + predBlocks[5] = condition[currRow * maxColumn + currColumn - 1]; srcCounter++; } - if ( !fNoCornerNeigh ) - { + if (!fNoCornerNeigh) { // top-left - if ( currRow > 0 && condition[ (currRow-1)*maxColumn + currColumn - 1 ] >= threshold ) - { - predBlocks[1] = condition[ (currRow-1)*maxColumn + currColumn - 1 ]; + if (currRow > 0 && + condition[(currRow - 1) * maxColumn + currColumn - 1] >= + threshold) { + predBlocks[1] = condition[(currRow - 1) * maxColumn + currColumn - 1]; srcCounter++; } // bottom-left - if ( currRow < (maxRow-step) && condition[ (currRow+step)*maxColumn + currColumn - 1 ] >= threshold ) - { - predBlocks[2] = condition[ (currRow+step)*maxColumn + currColumn - 1 ]; + if (currRow < (maxRow - step) && + condition[(currRow + step) * maxColumn + currColumn - 1] >= + threshold) { + predBlocks[2] = + condition[(currRow + step) * maxColumn + currColumn - 1]; srcCounter++; } } } - if ( currColumn < (maxColumn-step) ) - { + if (currColumn < (maxColumn - step)) { // right - if ( condition[ currRow*maxColumn+currColumn + step ] >= threshold ) - { - predBlocks[7] = condition[ currRow*maxColumn+currColumn + step ]; + if (condition[currRow * maxColumn + currColumn + step] >= threshold) { + predBlocks[7] = condition[currRow * maxColumn + currColumn + step]; srcCounter++; } - if ( !fNoCornerNeigh ) - { + if (!fNoCornerNeigh) { // top-right - if ( currRow > 0 && condition[ (currRow-1)*maxColumn + currColumn + step ] >= threshold ) - { - predBlocks[0] = condition[ (currRow-1)*maxColumn + currColumn + step ]; + if (currRow > 0 && + condition[(currRow - 1) * maxColumn + currColumn + step] >= + threshold) { + predBlocks[0] = + condition[(currRow - 1) * maxColumn + currColumn + step]; srcCounter++; } // bottom-right - if ( currRow < (maxRow-step) && condition[ (currRow+step)*maxColumn + currColumn + step ] >= threshold ) - { - predBlocks[3] = condition[ (currRow+step)*maxColumn + currColumn + step ]; + if (currRow < (maxRow - step) && + condition[(currRow + step) * maxColumn + currColumn + step] >= + threshold) { + predBlocks[3] = + condition[(currRow + step) * maxColumn + currColumn + step]; srcCounter++; } } @@ -232,7 +240,7 @@ int ercCollect8PredBlocks( int predBlocks[], int currRow, int currColumn, signed threshold--; if (threshold < ERC_BLOCK_CONCEALED) break; - } while ( srcCounter < srcCountMin); + } while (srcCounter < srcCountMin); return srcCounter; } @@ -260,20 +268,19 @@ int ercCollect8PredBlocks( int predBlocks[], int currRow, int currColumn, signed * in vertical/horizontal direction. (Y:2 U,V:1) ************************************************************************ */ -int ercCollectColumnBlocks( int predBlocks[], int currRow, int currColumn, signed char *condition, int maxRow, int maxColumn, int step ) -{ +int ercCollectColumnBlocks(int predBlocks[], int currRow, int currColumn, + signed char *condition, int maxRow, int maxColumn, + int step) { int srcCounter = 0, threshold = ERC_BLOCK_CORRUPTED; - memset( predBlocks, 0, 8*sizeof(int) ); + memset(predBlocks, 0, 8 * sizeof(int)); // in this case, row > 0 and row < 17 - if ( condition[ (currRow-1)*maxColumn + currColumn ] > threshold ) - { + if (condition[(currRow - 1) * maxColumn + currColumn] > threshold) { predBlocks[4] = 1; srcCounter++; } - if ( condition[ (currRow+step)*maxColumn + currColumn ] > threshold ) - { + if (condition[(currRow + step) * maxColumn + currColumn] > threshold) { predBlocks[6] = 1; srcCounter++; } @@ -289,189 +296,177 @@ int ercCollectColumnBlocks( int predBlocks[], int currRow, int currColumn, signe * Finds the corrupted blocks and calls pixel interpolation functions * to correct them, one block at a time. * Scanning is done vertically and each corrupted column is corrected - * bi-directionally, i.e., first block, last block, first block+1, last block -1 ... - * \param p_Vid - * video encoding parameters for current picture - * \param lastColumn - * Number of block columns in the frame - * \param lastRow - * Number of block rows in the frame - * \param comp - * color component - * \param recfr - * Reconstructed frame buffer - * \param picSizeX - * Width of the frame in pixels - * \param condition - * The block condition (ok, lost) table + * bi-directionally, i.e., first block, last block, first block+1, last + *block -1 ... \param p_Vid video encoding parameters for current picture \param + *lastColumn Number of block columns in the frame \param lastRow Number of block + *rows in the frame \param comp color component \param recfr Reconstructed frame + *buffer \param picSizeX Width of the frame in pixels \param condition The block + *condition (ok, lost) table ************************************************************************ */ -static void concealBlocks( VideoParameters *p_Vid, int lastColumn, int lastRow, int comp, frame *recfr, int picSizeX, signed char *condition ) -{ - int row, column, srcCounter = 0, thr = ERC_BLOCK_CORRUPTED, - lastCorruptedRow = -1, firstCorruptedRow = -1, currRow = 0, - areaHeight = 0, i = 0, smoothColumn = 0; +static void concealBlocks(VideoParameters *p_Vid, int lastColumn, int lastRow, + int comp, frame *recfr, int picSizeX, + signed char *condition) { + int row, column, srcCounter = 0, thr = ERC_BLOCK_CORRUPTED, + lastCorruptedRow = -1, firstCorruptedRow = -1, currRow = 0, + areaHeight = 0, i = 0, smoothColumn = 0; int predBlocks[8], step = 1; // in the Y component do the concealment MB-wise (not block-wise): // this is useful if only whole MBs can be damaged or lost - if ( comp == 0 ) + if (comp == 0) step = 2; else step = 1; - for ( column = 0; column < lastColumn; column += step ) - { - for ( row = 0; row < lastRow; row += step ) - { - if ( condition[row*lastColumn+column] <= thr ) - { + for (column = 0; column < lastColumn; column += step) { + for (row = 0; row < lastRow; row += step) { + if (condition[row * lastColumn + column] <= thr) { firstCorruptedRow = row; - // find the last row which has corrupted blocks (in same continuous area) - for ( lastCorruptedRow = row+step; lastCorruptedRow < lastRow; lastCorruptedRow += step ) - { + // find the last row which has corrupted blocks (in same continuous + // area) + for (lastCorruptedRow = row + step; lastCorruptedRow < lastRow; + lastCorruptedRow += step) { // check blocks in the current column - if ( condition[ lastCorruptedRow*lastColumn + column ] > thr ) - { + if (condition[lastCorruptedRow * lastColumn + column] > thr) { // current one is already OK, so the last was the previous one lastCorruptedRow -= step; break; } } - if ( lastCorruptedRow >= lastRow ) - { + if (lastCorruptedRow >= lastRow) { // correct only from above - lastCorruptedRow = lastRow-step; - for ( currRow = firstCorruptedRow; currRow < lastRow; currRow += step ) - { - srcCounter = ercCollect8PredBlocks( predBlocks, currRow, column, condition, lastRow, lastColumn, step, 1 ); + lastCorruptedRow = lastRow - step; + for (currRow = firstCorruptedRow; currRow < lastRow; + currRow += step) { + srcCounter = + ercCollect8PredBlocks(predBlocks, currRow, column, condition, + lastRow, lastColumn, step, 1); - switch( comp ) - { - case 0 : - ercPixConcealIMB( p_Vid, recfr->yptr, currRow, column, predBlocks, picSizeX, 2 ); + switch (comp) { + case 0: + ercPixConcealIMB(p_Vid, recfr->yptr, currRow, column, predBlocks, + picSizeX, 2); break; - case 1 : - ercPixConcealIMB( p_Vid, recfr->uptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); + case 1: + ercPixConcealIMB(p_Vid, recfr->uptr, currRow, column, predBlocks, + (picSizeX >> 1), 1); break; - case 2 : - ercPixConcealIMB( p_Vid, recfr->vptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); + case 2: + ercPixConcealIMB(p_Vid, recfr->vptr, currRow, column, predBlocks, + (picSizeX >> 1), 1); break; } - if ( comp == 0 ) - { - condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED; - condition[ currRow*lastColumn+column + 1] = ERC_BLOCK_CONCEALED; - condition[ currRow*lastColumn+column + lastColumn] = ERC_BLOCK_CONCEALED; - condition[ currRow*lastColumn+column + lastColumn + 1] = ERC_BLOCK_CONCEALED; + if (comp == 0) { + condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED; + condition[currRow * lastColumn + column + 1] = + ERC_BLOCK_CONCEALED; + condition[currRow * lastColumn + column + lastColumn] = + ERC_BLOCK_CONCEALED; + condition[currRow * lastColumn + column + lastColumn + 1] = + ERC_BLOCK_CONCEALED; + } else { + condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED; } - else - { - condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED; - } - } row = lastRow; - } - else if ( firstCorruptedRow == 0 ) - { + } else if (firstCorruptedRow == 0) { // correct only from below - for ( currRow = lastCorruptedRow; currRow >= 0; currRow -= step ) - { - srcCounter = ercCollect8PredBlocks( predBlocks, currRow, column, condition, lastRow, lastColumn, step, 1 ); + for (currRow = lastCorruptedRow; currRow >= 0; currRow -= step) { + srcCounter = + ercCollect8PredBlocks(predBlocks, currRow, column, condition, + lastRow, lastColumn, step, 1); - switch( comp ) - { - case 0 : - ercPixConcealIMB( p_Vid, recfr->yptr, currRow, column, predBlocks, picSizeX, 2 ); + switch (comp) { + case 0: + ercPixConcealIMB(p_Vid, recfr->yptr, currRow, column, predBlocks, + picSizeX, 2); break; - case 1 : - ercPixConcealIMB( p_Vid, recfr->uptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); + case 1: + ercPixConcealIMB(p_Vid, recfr->uptr, currRow, column, predBlocks, + (picSizeX >> 1), 1); break; - case 2 : - ercPixConcealIMB( p_Vid, recfr->vptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); + case 2: + ercPixConcealIMB(p_Vid, recfr->vptr, currRow, column, predBlocks, + (picSizeX >> 1), 1); break; } - if ( comp == 0 ) - { - condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED; - condition[ currRow*lastColumn+column + 1] = ERC_BLOCK_CONCEALED; - condition[ currRow*lastColumn+column + lastColumn] = ERC_BLOCK_CONCEALED; - condition[ currRow*lastColumn+column + lastColumn + 1] = ERC_BLOCK_CONCEALED; + if (comp == 0) { + condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED; + condition[currRow * lastColumn + column + 1] = + ERC_BLOCK_CONCEALED; + condition[currRow * lastColumn + column + lastColumn] = + ERC_BLOCK_CONCEALED; + condition[currRow * lastColumn + column + lastColumn + 1] = + ERC_BLOCK_CONCEALED; + } else { + condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED; } - else - { - condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED; - } - } - row = lastCorruptedRow+step; - } - else - { + row = lastCorruptedRow + step; + } else { // correct bi-directionally - row = lastCorruptedRow+step; - areaHeight = lastCorruptedRow-firstCorruptedRow+step; + row = lastCorruptedRow + step; + areaHeight = lastCorruptedRow - firstCorruptedRow + step; - // Conceal the corrupted area switching between the up and the bottom rows - for ( i = 0; i < areaHeight; i += step ) - { - if ( i % 2 ) - { + // Conceal the corrupted area switching between the up and the bottom + // rows + for (i = 0; i < areaHeight; i += step) { + if (i % 2) { currRow = lastCorruptedRow; lastCorruptedRow -= step; - } - else - { + } else { currRow = firstCorruptedRow; firstCorruptedRow += step; } - if (smoothColumn > 0) - { - srcCounter = ercCollectColumnBlocks( predBlocks, currRow, column, condition, lastRow, lastColumn, step ); - } - else - { - srcCounter = ercCollect8PredBlocks( predBlocks, currRow, column, condition, lastRow, lastColumn, step, 1 ); + if (smoothColumn > 0) { + srcCounter = + ercCollectColumnBlocks(predBlocks, currRow, column, condition, + lastRow, lastColumn, step); + } else { + srcCounter = + ercCollect8PredBlocks(predBlocks, currRow, column, condition, + lastRow, lastColumn, step, 1); } - switch( comp ) - { - case 0 : - ercPixConcealIMB( p_Vid, recfr->yptr, currRow, column, predBlocks, picSizeX, 2 ); + switch (comp) { + case 0: + ercPixConcealIMB(p_Vid, recfr->yptr, currRow, column, predBlocks, + picSizeX, 2); break; - case 1 : - ercPixConcealIMB( p_Vid, recfr->uptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); + case 1: + ercPixConcealIMB(p_Vid, recfr->uptr, currRow, column, predBlocks, + (picSizeX >> 1), 1); break; - case 2 : - ercPixConcealIMB( p_Vid, recfr->vptr, currRow, column, predBlocks, (picSizeX>>1), 1 ); + case 2: + ercPixConcealIMB(p_Vid, recfr->vptr, currRow, column, predBlocks, + (picSizeX >> 1), 1); break; } - if ( comp == 0 ) - { - condition[ currRow*lastColumn+column] = ERC_BLOCK_CONCEALED; - condition[ currRow*lastColumn+column + 1] = ERC_BLOCK_CONCEALED; - condition[ currRow*lastColumn+column + lastColumn] = ERC_BLOCK_CONCEALED; - condition[ currRow*lastColumn+column + lastColumn + 1] = ERC_BLOCK_CONCEALED; - } - else - { - condition[ currRow*lastColumn+column ] = ERC_BLOCK_CONCEALED; + if (comp == 0) { + condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED; + condition[currRow * lastColumn + column + 1] = + ERC_BLOCK_CONCEALED; + condition[currRow * lastColumn + column + lastColumn] = + ERC_BLOCK_CONCEALED; + condition[currRow * lastColumn + column + lastColumn + 1] = + ERC_BLOCK_CONCEALED; + } else { + condition[currRow * lastColumn + column] = ERC_BLOCK_CONCEALED; } } } lastCorruptedRow = -1; firstCorruptedRow = -1; - } } } @@ -494,50 +489,47 @@ static void concealBlocks( VideoParameters *p_Vid, int lastColumn, int lastRow, * Width of the frame in pixels ************************************************************************ */ -static void pixMeanInterpolateBlock( VideoParameters *p_Vid, imgpel *src[], imgpel *block, int blockSize, int frameWidth ) -{ +static void pixMeanInterpolateBlock(VideoParameters *p_Vid, imgpel *src[], + imgpel *block, int blockSize, + int frameWidth) { int row, column, k, tmp, srcCounter = 0, weight = 0, bmax = blockSize - 1; k = 0; - for ( row = 0; row < blockSize; row++ ) - { - for ( column = 0; column < blockSize; column++ ) - { + for (row = 0; row < blockSize; row++) { + for (column = 0; column < blockSize; column++) { tmp = 0; srcCounter = 0; // above - if ( src[4] != NULL ) - { - weight = blockSize-row; - tmp += weight * (*(src[4]+bmax*frameWidth+column)); + if (src[4] != NULL) { + weight = blockSize - row; + tmp += weight * (*(src[4] + bmax * frameWidth + column)); srcCounter += weight; } // left - if ( src[5] != NULL ) - { - weight = blockSize-column; - tmp += weight * (*(src[5]+row*frameWidth+bmax)); + if (src[5] != NULL) { + weight = blockSize - column; + tmp += weight * (*(src[5] + row * frameWidth + bmax)); srcCounter += weight; } // below - if ( src[6] != NULL ) - { - weight = row+1; - tmp += weight * (*(src[6]+column)); + if (src[6] != NULL) { + weight = row + 1; + tmp += weight * (*(src[6] + column)); srcCounter += weight; } // right - if ( src[7] != NULL ) - { - weight = column+1; - tmp += weight * (*(src[7]+row*frameWidth)); + if (src[7] != NULL) { + weight = column + 1; + tmp += weight * (*(src[7] + row * frameWidth)); srcCounter += weight; } - if ( srcCounter > 0 ) - block[ k + column ] = (imgpel)(tmp/srcCounter); + if (srcCounter > 0) + block[k + column] = (imgpel)(tmp / srcCounter); else - block[ k + column ] = (imgpel) (blockSize == 8 ? p_Vid->dc_pred_value_comp[1] : p_Vid->dc_pred_value_comp[0]); + block[k + column] = + (imgpel)(blockSize == 8 ? p_Vid->dc_pred_value_comp[1] + : p_Vid->dc_pred_value_comp[0]); } k += frameWidth; } diff --git a/src/common/ldecod_src/erc_do_p.c b/src/common/ldecod_src/erc_do_p.c index 222b07d..78753a2 100644 --- a/src/common/ldecod_src/erc_do_p.c +++ b/src/common/ldecod_src/erc_do_p.c @@ -18,46 +18,49 @@ ************************************************************************************* */ -#include "global.h" -#include "mbuffer.h" -#include "memalloc.h" #include "erc_do.h" +#include "global.h" #include "image.h" -#include "mc_prediction.h" #include "macroblock.h" - +#include "mbuffer.h" +#include "mc_prediction.h" +#include "memalloc.h" // static function declarations -static int concealByCopy(frame *recfr, int currMBNum, objectBuffer_t *object_list, int picSizeX); -static int concealByTrial(frame *recfr, imgpel *predMB, - int currMBNum, objectBuffer_t *object_list, int predBlocks[], +static int concealByCopy(frame *recfr, int currMBNum, + objectBuffer_t *object_list, int picSizeX); +static int concealByTrial(frame *recfr, imgpel *predMB, int currMBNum, + objectBuffer_t *object_list, int predBlocks[], int picSizeX, int picSizeY, signed char *yCondition); -static int edgeDistortion (int predBlocks[], int currYBlockNum, imgpel *predMB, - imgpel *recY, int picSizeX, int regionSize); -static void copyBetweenFrames (frame *recfr, int currYBlockNum, int picSizeX, int regionSize); -static void buildPredRegionYUV(VideoParameters *p_Vid, int *mv, int x, int y, imgpel *predMB); +static int edgeDistortion(int predBlocks[], int currYBlockNum, imgpel *predMB, + imgpel *recY, int picSizeX, int regionSize); +static void copyBetweenFrames(frame *recfr, int currYBlockNum, int picSizeX, + int regionSize); +static void buildPredRegionYUV(VideoParameters *p_Vid, int *mv, int x, int y, + imgpel *predMB); // picture error concealment -static void buildPredblockRegionYUV(VideoParameters *p_Vid, int *mv, - int x, int y, imgpel *predMB, int list, int mb); -static void CopyImgData(imgpel **inputY, imgpel ***inputUV, imgpel **outputY, imgpel ***outputUV, - int img_width, int img_height, int img_width_cr, int img_height_cr); +static void buildPredblockRegionYUV(VideoParameters *p_Vid, int *mv, int x, + int y, imgpel *predMB, int list, int mb); +static void CopyImgData(imgpel **inputY, imgpel ***inputUV, imgpel **outputY, + imgpel ***outputUV, int img_width, int img_height, + int img_width_cr, int img_height_cr); -static void copyPredMB (int currYBlockNum, imgpel *predMB, frame *recfr, - int picSizeX, int regionSize); -static void add_node ( VideoParameters *p_Vid, struct concealment_node *ptr ); -static void delete_node( VideoParameters *p_Vid, struct concealment_node *ptr ); +static void copyPredMB(int currYBlockNum, imgpel *predMB, frame *recfr, + int picSizeX, int regionSize); +static void add_node(VideoParameters *p_Vid, struct concealment_node *ptr); +static void delete_node(VideoParameters *p_Vid, struct concealment_node *ptr); -static const int uv_div[2][4] = {{0, 1, 1, 0}, {0, 1, 0, 0}}; //[x/y][yuv_format] +static const int uv_div[2][4] = {{0, 1, 1, 0}, + {0, 1, 0, 0}}; //[x/y][yuv_format] /*! ************************************************************************ * \brief * The main function for Inter (P) frame concealment. * \return - * 0, if the concealment was not successful and simple concealment should be used - * 1, otherwise (even if none of the blocks were concealed) - * \param recfr + * 0, if the concealment was not successful and simple concealment should + *be used 1, otherwise (even if none of the blocks were concealed) \param recfr * Reconstructed frame buffer * \param object_list * Motion info for all MBs in the frame @@ -72,8 +75,8 @@ static const int uv_div[2][4] = {{0, 1, 1, 0}, {0, 1, 0, 0}}; //[x/y][yuv_format ************************************************************************ */ int ercConcealInterFrame(frame *recfr, objectBuffer_t *object_list, - int picSizeX, int picSizeY, ercVariables_t *errorVar, int chroma_format_idc ) -{ + int picSizeX, int picSizeY, ercVariables_t *errorVar, + int chroma_format_idc) { VideoParameters *p_Vid = recfr->p_Vid; int lastColumn = 0, lastRow = 0, predBlocks[8]; int lastCorruptedRow = -1, firstCorruptedRow = -1; @@ -81,127 +84,123 @@ int ercConcealInterFrame(frame *recfr, objectBuffer_t *object_list, imgpel *predMB; /* if concealment is on */ - if ( errorVar && errorVar->concealment ) - { + if (errorVar && errorVar->concealment) { /* if there are segments to be concealed */ - if ( errorVar->nOfCorruptedSegments ) - { + if (errorVar->nOfCorruptedSegments) { if (chroma_format_idc != YUV400) - predMB = (imgpel *) malloc ( (256 + (p_Vid->mb_cr_size_x * p_Vid->mb_cr_size_y)*2) * sizeof (imgpel)); + predMB = (imgpel *)malloc( + (256 + (p_Vid->mb_cr_size_x * p_Vid->mb_cr_size_y) * 2) * + sizeof(imgpel)); else - predMB = (imgpel *) malloc(256 * sizeof (imgpel)); + predMB = (imgpel *)malloc(256 * sizeof(imgpel)); - if ( predMB == NULL ) no_mem_exit("ercConcealInterFrame: predMB"); + if (predMB == NULL) + no_mem_exit("ercConcealInterFrame: predMB"); - lastRow = (int) (picSizeY>>4); - lastColumn = (int) (picSizeX>>4); + lastRow = (int)(picSizeY >> 4); + lastColumn = (int)(picSizeX >> 4); - for ( columnInd = 0; columnInd < lastColumn; columnInd ++) - { + for (columnInd = 0; columnInd < lastColumn; columnInd++) { - column = ((columnInd%2) ? (lastColumn - columnInd/2 -1) : (columnInd/2)); + column = ((columnInd % 2) ? (lastColumn - columnInd / 2 - 1) + : (columnInd / 2)); - for ( row = 0; row < lastRow; row++) - { + for (row = 0; row < lastRow; row++) { - if ( errorVar->yCondition[MBxy2YBlock(column, row, 0, picSizeX)] <= ERC_BLOCK_CORRUPTED ) - { // ERC_BLOCK_CORRUPTED (1) or ERC_BLOCK_EMPTY (0) + if (errorVar->yCondition[MBxy2YBlock(column, row, 0, picSizeX)] <= + ERC_BLOCK_CORRUPTED) { // ERC_BLOCK_CORRUPTED (1) or + // ERC_BLOCK_EMPTY (0) firstCorruptedRow = row; - /* find the last row which has corrupted blocks (in same continuous area) */ - for ( lastCorruptedRow = row+1; lastCorruptedRow < lastRow; lastCorruptedRow++) - { + /* find the last row which has corrupted blocks (in same continuous + * area) */ + for (lastCorruptedRow = row + 1; lastCorruptedRow < lastRow; + lastCorruptedRow++) { /* check blocks in the current column */ - if (errorVar->yCondition[MBxy2YBlock(column, lastCorruptedRow, 0, picSizeX)] > ERC_BLOCK_CORRUPTED) - { - /* current one is already OK, so the last was the previous one */ - lastCorruptedRow --; + if (errorVar->yCondition[MBxy2YBlock(column, lastCorruptedRow, 0, + picSizeX)] > + ERC_BLOCK_CORRUPTED) { + /* current one is already OK, so the last was the previous one + */ + lastCorruptedRow--; break; } } - if ( lastCorruptedRow >= lastRow ) - { + if (lastCorruptedRow >= lastRow) { /* correct only from above */ - lastCorruptedRow = lastRow-1; - for ( currRow = firstCorruptedRow; currRow < lastRow; currRow++ ) - { + lastCorruptedRow = lastRow - 1; + for (currRow = firstCorruptedRow; currRow < lastRow; currRow++) { - ercCollect8PredBlocks (predBlocks, (currRow<<1), (column<<1), - errorVar->yCondition, (lastRow<<1), (lastColumn<<1), 2, 0); + ercCollect8PredBlocks(predBlocks, (currRow << 1), (column << 1), + errorVar->yCondition, (lastRow << 1), + (lastColumn << 1), 2, 0); - if(p_Vid->erc_mvperMB >= MVPERMB_THR) - concealByTrial(recfr, predMB, - currRow*lastColumn+column, object_list, predBlocks, - picSizeX, picSizeY, - errorVar->yCondition); + if (p_Vid->erc_mvperMB >= MVPERMB_THR) + concealByTrial(recfr, predMB, currRow * lastColumn + column, + object_list, predBlocks, picSizeX, picSizeY, + errorVar->yCondition); else - concealByCopy(recfr, currRow*lastColumn+column, - object_list, picSizeX); + concealByCopy(recfr, currRow * lastColumn + column, + object_list, picSizeX); - ercMarkCurrMBConcealed (currRow*lastColumn+column, -1, picSizeX, errorVar); + ercMarkCurrMBConcealed(currRow * lastColumn + column, -1, + picSizeX, errorVar); } row = lastRow; - } - else if ( firstCorruptedRow == 0 ) - { + } else if (firstCorruptedRow == 0) { /* correct only from below */ - for ( currRow = lastCorruptedRow; currRow >= 0; currRow-- ) - { + for (currRow = lastCorruptedRow; currRow >= 0; currRow--) { - ercCollect8PredBlocks (predBlocks, (currRow<<1), (column<<1), - errorVar->yCondition, (lastRow<<1), (lastColumn<<1), 2, 0); + ercCollect8PredBlocks(predBlocks, (currRow << 1), (column << 1), + errorVar->yCondition, (lastRow << 1), + (lastColumn << 1), 2, 0); - if(p_Vid->erc_mvperMB >= MVPERMB_THR) - concealByTrial(recfr, predMB, - currRow*lastColumn+column, object_list, predBlocks, - picSizeX, picSizeY, - errorVar->yCondition); + if (p_Vid->erc_mvperMB >= MVPERMB_THR) + concealByTrial(recfr, predMB, currRow * lastColumn + column, + object_list, predBlocks, picSizeX, picSizeY, + errorVar->yCondition); else - concealByCopy(recfr, currRow*lastColumn+column, - object_list, picSizeX); + concealByCopy(recfr, currRow * lastColumn + column, + object_list, picSizeX); - ercMarkCurrMBConcealed (currRow*lastColumn+column, -1, picSizeX, errorVar); + ercMarkCurrMBConcealed(currRow * lastColumn + column, -1, + picSizeX, errorVar); } - row = lastCorruptedRow+1; - } - else - { + row = lastCorruptedRow + 1; + } else { /* correct bi-directionally */ - row = lastCorruptedRow+1; + row = lastCorruptedRow + 1; - areaHeight = lastCorruptedRow-firstCorruptedRow+1; + areaHeight = lastCorruptedRow - firstCorruptedRow + 1; /* - * Conceal the corrupted area switching between the up and the bottom rows - */ - for ( i = 0; i < areaHeight; i++) - { - if ( i % 2 ) - { + * Conceal the corrupted area switching between the up and the + * bottom rows + */ + for (i = 0; i < areaHeight; i++) { + if (i % 2) { currRow = lastCorruptedRow; - lastCorruptedRow --; - } - else - { + lastCorruptedRow--; + } else { currRow = firstCorruptedRow; - firstCorruptedRow ++; + firstCorruptedRow++; } - ercCollect8PredBlocks (predBlocks, (currRow<<1), (column<<1), - errorVar->yCondition, (lastRow<<1), (lastColumn<<1), 2, 0); + ercCollect8PredBlocks(predBlocks, (currRow << 1), (column << 1), + errorVar->yCondition, (lastRow << 1), + (lastColumn << 1), 2, 0); - if(p_Vid->erc_mvperMB >= MVPERMB_THR) - concealByTrial(recfr, predMB, - currRow*lastColumn+column, object_list, predBlocks, - picSizeX, picSizeY, - errorVar->yCondition); + if (p_Vid->erc_mvperMB >= MVPERMB_THR) + concealByTrial(recfr, predMB, currRow * lastColumn + column, + object_list, predBlocks, picSizeX, picSizeY, + errorVar->yCondition); else - concealByCopy(recfr, currRow*lastColumn+column, - object_list, picSizeX); - - ercMarkCurrMBConcealed (currRow*lastColumn+column, -1, picSizeX, errorVar); + concealByCopy(recfr, currRow * lastColumn + column, + object_list, picSizeX); + ercMarkCurrMBConcealed(currRow * lastColumn + column, -1, + picSizeX, errorVar); } } lastCorruptedRow = -1; @@ -213,20 +212,16 @@ int ercConcealInterFrame(frame *recfr, objectBuffer_t *object_list, free(predMB); } return 1; - } - else + } else return 0; } /*! ************************************************************************ * \brief - * It conceals a given MB by simply copying the pixel area from the reference image - * that is at the same location as the macroblock in the current image. This correcponds - * to COPY MBs. - * \return - * Always zero (0). - * \param recfr + * It conceals a given MB by simply copying the pixel area from the + *reference image that is at the same location as the macroblock in the current + *image. This correcponds to COPY MBs. \return Always zero (0). \param recfr * Reconstructed frame buffer * \param currMBNum * current MB index @@ -237,17 +232,16 @@ int ercConcealInterFrame(frame *recfr, objectBuffer_t *object_list, ************************************************************************ */ static int concealByCopy(frame *recfr, int currMBNum, - objectBuffer_t *object_list, int picSizeX) -{ + objectBuffer_t *object_list, int picSizeX) { objectBuffer_t *currRegion; - currRegion = object_list+(currMBNum<<2); + currRegion = object_list + (currMBNum << 2); currRegion->regionMode = REGMODE_INTER_COPY; - currRegion->xMin = (xPosMB(currMBNum,picSizeX)<<4); - currRegion->yMin = (yPosMB(currMBNum,picSizeX)<<4); + currRegion->xMin = (xPosMB(currMBNum, picSizeX) << 4); + currRegion->yMin = (yPosMB(currMBNum, picSizeX) << 4); - copyBetweenFrames (recfr, MBNum2YBlock(currMBNum,0,picSizeX), picSizeX, 16); + copyBetweenFrames(recfr, MBNum2YBlock(currMBNum, 0, picSizeX), picSizeX, 16); return 0; } @@ -255,110 +249,97 @@ static int concealByCopy(frame *recfr, int currMBNum, /*! ************************************************************************ * \brief - * Copies the co-located pixel values from the reference to the current frame. - * Used by concealByCopy - * \param recfr - * Reconstructed frame buffer - * \param currYBlockNum - * index of the block (8x8) in the Y plane - * \param picSizeX - * Width of the frame in pixels - * \param regionSize - * can be 16 or 8 to tell the dimension of the region to copy + * Copies the co-located pixel values from the reference to the current + *frame. Used by concealByCopy \param recfr Reconstructed frame buffer \param + *currYBlockNum index of the block (8x8) in the Y plane \param picSizeX Width of + *the frame in pixels \param regionSize can be 16 or 8 to tell the dimension of + *the region to copy ************************************************************************ */ -static void copyBetweenFrames (frame *recfr, int currYBlockNum, int picSizeX, int regionSize) -{ +static void copyBetweenFrames(frame *recfr, int currYBlockNum, int picSizeX, + int regionSize) { VideoParameters *p_Vid = recfr->p_Vid; StorablePicture *dec_picture = p_Vid->dec_picture; int j, k, location, xmin, ymin; - StorablePicture* refPic = p_Vid->ppSliceList[0]->listX[0][0]; + StorablePicture *refPic = p_Vid->ppSliceList[0]->listX[0][0]; /* set the position of the region to be copied */ - xmin = (xPosYBlock(currYBlockNum,picSizeX)<<3); - ymin = (yPosYBlock(currYBlockNum,picSizeX)<<3); + xmin = (xPosYBlock(currYBlockNum, picSizeX) << 3); + ymin = (yPosYBlock(currYBlockNum, picSizeX) << 3); for (j = ymin; j < ymin + regionSize; j++) - for (k = xmin; k < xmin + regionSize; k++) - { + for (k = xmin; k < xmin + regionSize; k++) { location = j * picSizeX + k; -//th recfr->yptr[location] = dec_picture->imgY[j][k]; + // th recfr->yptr[location] = dec_picture->imgY[j][k]; recfr->yptr[location] = refPic->imgY[j][k]; } - for (j = ymin >> uv_div[1][dec_picture->chroma_format_idc]; j < (ymin + regionSize) >> uv_div[1][dec_picture->chroma_format_idc]; j++) - for (k = xmin >> uv_div[0][dec_picture->chroma_format_idc]; k < (xmin + regionSize) >> uv_div[0][dec_picture->chroma_format_idc]; k++) - { -// location = j * picSizeX / 2 + k; - location = ((j * picSizeX) >> uv_div[0][dec_picture->chroma_format_idc]) + k; + for (j = ymin >> uv_div[1][dec_picture->chroma_format_idc]; + j < (ymin + regionSize) >> uv_div[1][dec_picture->chroma_format_idc]; + j++) + for (k = xmin >> uv_div[0][dec_picture->chroma_format_idc]; + k < (xmin + regionSize) >> uv_div[0][dec_picture->chroma_format_idc]; + k++) { + // location = j * picSizeX / 2 + k; + location = + ((j * picSizeX) >> uv_div[0][dec_picture->chroma_format_idc]) + k; -//th recfr->uptr[location] = dec_picture->imgUV[0][j][k]; -//th recfr->vptr[location] = dec_picture->imgUV[1][j][k]; - recfr->uptr[location] = refPic->imgUV[0][j][k]; - recfr->vptr[location] = refPic->imgUV[1][j][k]; - } + // th recfr->uptr[location] = dec_picture->imgUV[0][j][k]; + // th recfr->vptr[location] = dec_picture->imgUV[1][j][k]; + recfr->uptr[location] = refPic->imgUV[0][j][k]; + recfr->vptr[location] = refPic->imgUV[1][j][k]; + } } /*! ************************************************************************ * \brief - * It conceals a given MB by using the motion vectors of one reliable neighbor. That MV of a - * neighbor is selected wich gives the lowest pixel difference at the edges of the MB - * (see function edgeDistortion). This corresponds to a spatial smoothness criteria. - * \return - * Always zero (0). - * \param recfr - * Reconstructed frame buffer - * \param predMB - * memory area for storing temporary pixel values for a macroblock - * the Y,U,V planes are concatenated y = predMB, u = predMB+256, v = predMB+320 - * \param currMBNum - * current MB index + * It conceals a given MB by using the motion vectors of one reliable + *neighbor. That MV of a neighbor is selected wich gives the lowest pixel + *difference at the edges of the MB (see function edgeDistortion). This + *corresponds to a spatial smoothness criteria. \return Always zero (0). \param + *recfr Reconstructed frame buffer \param predMB memory area for storing + *temporary pixel values for a macroblock the Y,U,V planes are concatenated y = + *predMB, u = predMB+256, v = predMB+320 \param currMBNum current MB index * \param object_list * array of region structures storing region mode and mv for each region * \param predBlocks - * status array of the neighboring blocks (if they are OK, concealed or lost) - * \param picSizeX - * Width of the frame in pixels - * \param picSizeY - * Height of the frame in pixels - * \param yCondition - * array for conditions of Y blocks from ercVariables_t + * status array of the neighboring blocks (if they are OK, concealed or + *lost) \param picSizeX Width of the frame in pixels \param picSizeY Height of + *the frame in pixels \param yCondition array for conditions of Y blocks from + *ercVariables_t ************************************************************************ */ -static int concealByTrial(frame *recfr, imgpel *predMB, - int currMBNum, objectBuffer_t *object_list, int predBlocks[], - int picSizeX, int picSizeY, signed char *yCondition) -{ +static int concealByTrial(frame *recfr, imgpel *predMB, int currMBNum, + objectBuffer_t *object_list, int predBlocks[], + int picSizeX, int picSizeY, signed char *yCondition) { VideoParameters *p_Vid = recfr->p_Vid; - int predMBNum = 0, numMBPerLine, - compSplit1 = 0, compSplit2 = 0, compLeft = 1, comp = 0, compPred, order = 1, - fInterNeighborExists, numIntraNeighbours, - fZeroMotionChecked, predSplitted = 0, - threshold = ERC_BLOCK_OK, - minDist, currDist, i, k, bestDir; + int predMBNum = 0, numMBPerLine, compSplit1 = 0, compSplit2 = 0, compLeft = 1, + comp = 0, compPred, order = 1, fInterNeighborExists, numIntraNeighbours, + fZeroMotionChecked, predSplitted = 0, threshold = ERC_BLOCK_OK, minDist, + currDist, i, k, bestDir; int regionSize; objectBuffer_t *currRegion; int mvBest[3] = {0, 0, 0}, mvPred[3] = {0, 0, 0}, *mvptr; - numMBPerLine = (int) (picSizeX>>4); + numMBPerLine = (int)(picSizeX >> 4); comp = 0; regionSize = 16; - do - { /* 4 blocks loop */ + do { /* 4 blocks loop */ - currRegion = object_list+(currMBNum<<2)+comp; + currRegion = object_list + (currMBNum << 2) + comp; /* set the position of the region to be concealed */ - currRegion->xMin = (xPosYBlock(MBNum2YBlock(currMBNum,comp,picSizeX),picSizeX)<<3); - currRegion->yMin = (yPosYBlock(MBNum2YBlock(currMBNum,comp,picSizeX),picSizeX)<<3); + currRegion->xMin = + (xPosYBlock(MBNum2YBlock(currMBNum, comp, picSizeX), picSizeX) << 3); + currRegion->yMin = + (yPosYBlock(MBNum2YBlock(currMBNum, comp, picSizeX), picSizeX) << 3); - do - { /* reliability loop */ + do { /* reliability loop */ minDist = 0; fInterNeighborExists = 0; @@ -366,34 +347,31 @@ static int concealByTrial(frame *recfr, imgpel *predMB, fZeroMotionChecked = 0; /* loop the 4 neighbours */ - for (i = 4; i < 8; i++) - { + for (i = 4; i < 8; i++) { /* if reliable, try it */ - if (predBlocks[i] >= threshold) - { - switch (i) - { + if (predBlocks[i] >= threshold) { + switch (i) { case 4: - predMBNum = currMBNum-numMBPerLine; + predMBNum = currMBNum - numMBPerLine; compSplit1 = 2; compSplit2 = 3; break; case 5: - predMBNum = currMBNum-1; + predMBNum = currMBNum - 1; compSplit1 = 1; compSplit2 = 3; break; case 6: - predMBNum = currMBNum+numMBPerLine; + predMBNum = currMBNum + numMBPerLine; compSplit1 = 0; compSplit2 = 1; break; case 7: - predMBNum = currMBNum+1; + predMBNum = currMBNum + 1; compSplit1 = 0; compSplit2 = 2; break; @@ -401,135 +379,126 @@ static int concealByTrial(frame *recfr, imgpel *predMB, /* try the concealment with the Motion Info of the current neighbour only try if the neighbour is not Intra */ - if (isBlock(object_list,predMBNum,compSplit1,INTRA) || - isBlock(object_list,predMBNum,compSplit2,INTRA)) - { + if (isBlock(object_list, predMBNum, compSplit1, INTRA) || + isBlock(object_list, predMBNum, compSplit2, INTRA)) { numIntraNeighbours++; - } - else - { + } else { /* if neighbour MB is splitted, try both neighbour blocks */ for (predSplitted = isSplitted(object_list, predMBNum), - compPred = compSplit1; - predSplitted >= 0; - compPred = compSplit2, - predSplitted -= ((compSplit1 == compSplit2) ? 2 : 1)) - { + compPred = compSplit1; + predSplitted >= 0; compPred = compSplit2, + predSplitted -= ((compSplit1 == compSplit2) ? 2 : 1)) { - /* if Zero Motion Block, do the copying. This option is tried only once */ - if (isBlock(object_list, predMBNum, compPred, INTER_COPY)) - { + /* if Zero Motion Block, do the copying. This option is tried only + * once */ + if (isBlock(object_list, predMBNum, compPred, INTER_COPY)) { - if (fZeroMotionChecked) - { + if (fZeroMotionChecked) { continue; - } - else - { + } else { fZeroMotionChecked = 1; mvPred[0] = mvPred[1] = 0; mvPred[2] = 0; - buildPredRegionYUV(p_Vid->erc_img, mvPred, currRegion->xMin, currRegion->yMin, predMB); + buildPredRegionYUV(p_Vid->erc_img, mvPred, currRegion->xMin, + currRegion->yMin, predMB); } } /* build motion using the neighbour's Motion Parameters */ - else if (isBlock(object_list,predMBNum,compPred,INTRA)) - { + else if (isBlock(object_list, predMBNum, compPred, INTRA)) { continue; - } - else - { + } else { mvptr = getParam(object_list, predMBNum, compPred, mv); mvPred[0] = mvptr[0]; mvPred[1] = mvptr[1]; mvPred[2] = mvptr[2]; - buildPredRegionYUV(p_Vid->erc_img, mvPred, currRegion->xMin, currRegion->yMin, predMB); + buildPredRegionYUV(p_Vid->erc_img, mvPred, currRegion->xMin, + currRegion->yMin, predMB); } /* measure absolute boundary pixel difference */ - currDist = edgeDistortion(predBlocks, - MBNum2YBlock(currMBNum,comp,picSizeX), - predMB, recfr->yptr, picSizeX, regionSize); + currDist = edgeDistortion( + predBlocks, MBNum2YBlock(currMBNum, comp, picSizeX), predMB, + recfr->yptr, picSizeX, regionSize); /* if so far best -> store the pixels as the best concealment */ - if (currDist < minDist || !fInterNeighborExists) - { + if (currDist < minDist || !fInterNeighborExists) { minDist = currDist; bestDir = i; - for (k=0;k<3;k++) + for (k = 0; k < 3; k++) mvBest[k] = mvPred[k]; currRegion->regionMode = - (isBlock(object_list, predMBNum, compPred, INTER_COPY)) ? - ((regionSize == 16) ? REGMODE_INTER_COPY : REGMODE_INTER_COPY_8x8) : - ((regionSize == 16) ? REGMODE_INTER_PRED : REGMODE_INTER_PRED_8x8); + (isBlock(object_list, predMBNum, compPred, INTER_COPY)) + ? ((regionSize == 16) ? REGMODE_INTER_COPY + : REGMODE_INTER_COPY_8x8) + : ((regionSize == 16) ? REGMODE_INTER_PRED + : REGMODE_INTER_PRED_8x8); - copyPredMB(MBNum2YBlock(currMBNum,comp,picSizeX), predMB, recfr, - picSizeX, regionSize); + copyPredMB(MBNum2YBlock(currMBNum, comp, picSizeX), predMB, + recfr, picSizeX, regionSize); } fInterNeighborExists = 1; } } } - } + } - threshold--; + threshold--; } while ((threshold >= ERC_BLOCK_CONCEALED) && (fInterNeighborExists == 0)); /* always try zero motion */ - if (!fZeroMotionChecked) - { + if (!fZeroMotionChecked) { mvPred[0] = mvPred[1] = 0; mvPred[2] = 0; - buildPredRegionYUV(p_Vid->erc_img, mvPred, currRegion->xMin, currRegion->yMin, predMB); + buildPredRegionYUV(p_Vid->erc_img, mvPred, currRegion->xMin, + currRegion->yMin, predMB); - currDist = edgeDistortion(predBlocks, - MBNum2YBlock(currMBNum,comp,picSizeX), - predMB, recfr->yptr, picSizeX, regionSize); + currDist = + edgeDistortion(predBlocks, MBNum2YBlock(currMBNum, comp, picSizeX), + predMB, recfr->yptr, picSizeX, regionSize); - if (currDist < minDist || !fInterNeighborExists) - { + if (currDist < minDist || !fInterNeighborExists) { minDist = currDist; - for (k=0;k<3;k++) + for (k = 0; k < 3; k++) mvBest[k] = mvPred[k]; currRegion->regionMode = - ((regionSize == 16) ? REGMODE_INTER_COPY : REGMODE_INTER_COPY_8x8); + ((regionSize == 16) ? REGMODE_INTER_COPY : REGMODE_INTER_COPY_8x8); - copyPredMB(MBNum2YBlock(currMBNum,comp,picSizeX), predMB, recfr, - picSizeX, regionSize); + copyPredMB(MBNum2YBlock(currMBNum, comp, picSizeX), predMB, recfr, + picSizeX, regionSize); } } - for (i=0; i<3; i++) + for (i = 0; i < 3; i++) currRegion->mv[i] = mvBest[i]; - yCondition[MBNum2YBlock(currMBNum,comp,picSizeX)] = ERC_BLOCK_CONCEALED; - comp = (comp+order+4)%4; + yCondition[MBNum2YBlock(currMBNum, comp, picSizeX)] = ERC_BLOCK_CONCEALED; + comp = (comp + order + 4) % 4; compLeft--; - } while (compLeft); + } while (compLeft); - return 0; + return 0; } /*! ************************************************************************ * \brief -* Builds the motion prediction pixels from the given location (in 1/4 pixel units) -* of the reference frame. It not only copies the pixel values but builds the interpolation -* when the pixel positions to be copied from is not full pixel (any 1/4 pixel position). -* It copies the resulting pixel vlaues into predMB. +* Builds the motion prediction pixels from the given location (in 1/4 pixel +*units) of the reference frame. It not only copies the pixel values but builds +*the interpolation when the pixel positions to be copied from is not full pixel +*(any 1/4 pixel position). It copies the resulting pixel vlaues into predMB. * \param p_Vid * The pointer of video_par structure of current frame * \param mv @@ -540,174 +509,173 @@ static int concealByTrial(frame *recfr, imgpel *predMB, * The y-coordinate of the above-left corner pixel of the current MB * \param predMB * memory area for storing temporary pixel values for a macroblock -* the Y,U,V planes are concatenated y = predMB, u = predMB+256, v = predMB+320 +* the Y,U,V planes are concatenated y = predMB, u = predMB+256, v = +*predMB+320 ************************************************************************ */ -static void buildPredRegionYUV(VideoParameters *p_Vid, int *mv, int x, int y, imgpel *predMB) -{ +static void buildPredRegionYUV(VideoParameters *p_Vid, int *mv, int x, int y, + imgpel *predMB) { imgpel **tmp_block; - int i=0, j=0, ii=0, jj=0,i1=0,j1=0,j4=0,i4=0; - int jf=0; + int i = 0, j = 0, ii = 0, jj = 0, i1 = 0, j1 = 0, j4 = 0, i4 = 0; + int jf = 0; int uv; - int vec1_x=0,vec1_y=0; - int ioff,joff; + int vec1_x = 0, vec1_y = 0; + int ioff, joff; imgpel *pMB = predMB; - Slice *currSlice;// = p_Vid->currentSlice; + Slice *currSlice; // = p_Vid->currentSlice; StorablePicture *dec_picture = p_Vid->dec_picture; - int ii0,jj0,ii1,jj1,if1,jf1,if0,jf0; + int ii0, jj0, ii1, jj1, if1, jf1, if0, jf0; int mv_mul; - //FRExt + // FRExt int f1_x, f1_y, f2_x, f2_y, f3, f4, ifx; int b8, b4; int yuv = dec_picture->chroma_format_idc - 1; - int ref_frame = imax (mv[2], 0); // !!KS: quick fix, we sometimes seem to get negative ref_pic here, so restrict to zero and above - int mb_nr = y/16*(p_Vid->width/16)+x/16; ///currSlice->current_mb_nr; + int ref_frame = + imax(mv[2], 0); // !!KS: quick fix, we sometimes seem to get negative + // ref_pic here, so restrict to zero and above + int mb_nr = + y / 16 * (p_Vid->width / 16) + x / 16; /// currSlice->current_mb_nr; int **tmp_res = NULL; - - Macroblock *currMB = &p_Vid->mb_data[mb_nr]; // intialization code deleted, see below, StW + + Macroblock *currMB = + &p_Vid->mb_data[mb_nr]; // intialization code deleted, see below, StW currSlice = currMB->p_Slice; tmp_res = currSlice->tmp_res; - // This should be allocated only once. + // This should be allocated only once. get_mem2Dpel(&tmp_block, MB_BLOCK_SIZE, MB_BLOCK_SIZE); /* Update coordinates of the current concealed macroblock */ - currMB->mb.x = (short) (x/MB_BLOCK_SIZE); - currMB->mb.y = (short) (y/MB_BLOCK_SIZE); + currMB->mb.x = (short)(x / MB_BLOCK_SIZE); + currMB->mb.y = (short)(y / MB_BLOCK_SIZE); currMB->block_y = currMB->mb.y * BLOCK_SIZE; currMB->pix_c_y = currMB->mb.y * p_Vid->mb_cr_size_y; currMB->block_x = currMB->mb.x * BLOCK_SIZE; currMB->pix_c_x = currMB->mb.x * p_Vid->mb_cr_size_x; - mv_mul=4; + mv_mul = 4; // luma ******************************************************* - for(j=0;jblock_y+j; - for(i=0;iblock_x+i; + for (j = 0; j < MB_BLOCK_SIZE / BLOCK_SIZE; j++) { + joff = j * 4; + j4 = currMB->block_y + j; + for (i = 0; i < MB_BLOCK_SIZE / BLOCK_SIZE; i++) { + ioff = i * 4; + i4 = currMB->block_x + i; - vec1_x = i4*4*mv_mul + mv[0]; - vec1_y = j4*4*mv_mul + mv[1]; + vec1_x = i4 * 4 * mv_mul + mv[0]; + vec1_y = j4 * 4 * mv_mul + mv[1]; - get_block_luma(currSlice->listX[0][ref_frame], vec1_x, vec1_y, BLOCK_SIZE, BLOCK_SIZE, - tmp_block, - dec_picture->iLumaStride,dec_picture->size_x_m1, - (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 : dec_picture->size_y_m1,tmp_res, - p_Vid->max_pel_value_comp[PLANE_Y],(imgpel) p_Vid->dc_pred_value_comp[PLANE_Y], currMB); + get_block_luma(currSlice->listX[0][ref_frame], vec1_x, vec1_y, BLOCK_SIZE, + BLOCK_SIZE, tmp_block, dec_picture->iLumaStride, + dec_picture->size_x_m1, + (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 + : dec_picture->size_y_m1, + tmp_res, p_Vid->max_pel_value_comp[PLANE_Y], + (imgpel)p_Vid->dc_pred_value_comp[PLANE_Y], currMB); - for(ii=0;iimb_pred[LumaComp][jj+joff][ii+ioff]=tmp_block[jj][ii]; + for (ii = 0; ii < BLOCK_SIZE; ii++) + for (jj = 0; jj < MB_BLOCK_SIZE / BLOCK_SIZE; jj++) + currSlice->mb_pred[LumaComp][jj + joff][ii + ioff] = + tmp_block[jj][ii]; } } - - for (j = 0; j < 16; j++) - { - for (i = 0; i < 16; i++) - { - pMB[j*16+i] = currSlice->mb_pred[LumaComp][j][i]; + for (j = 0; j < 16; j++) { + for (i = 0; i < 16; i++) { + pMB[j * 16 + i] = currSlice->mb_pred[LumaComp][j][i]; } } pMB += 256; - if (dec_picture->chroma_format_idc != YUV400) - { + if (dec_picture->chroma_format_idc != YUV400) { // chroma ******************************************************* - f1_x = 64/p_Vid->mb_cr_size_x; - f2_x=f1_x-1; + f1_x = 64 / p_Vid->mb_cr_size_x; + f2_x = f1_x - 1; - f1_y = 64/p_Vid->mb_cr_size_y; - f2_y=f1_y-1; + f1_y = 64 / p_Vid->mb_cr_size_y; + f2_y = f1_y - 1; - f3=f1_x*f1_y; - f4=f3>>1; + f3 = f1_x * f1_y; + f4 = f3 >> 1; - for(uv=0;uv<2;uv++) - { - for (b8=0;b8<(p_Vid->num_uv_blocks);b8++) - { - for(b4=0;b4<4;b4++) - { + for (uv = 0; uv < 2; uv++) { + for (b8 = 0; b8 < (p_Vid->num_uv_blocks); b8++) { + for (b4 = 0; b4 < 4; b4++) { joff = subblk_offset_y[yuv][b8][b4]; - j4=currMB->pix_c_y+joff; + j4 = currMB->pix_c_y + joff; ioff = subblk_offset_x[yuv][b8][b4]; - i4=currMB->pix_c_x+ioff; + i4 = currMB->pix_c_x + ioff; - for(jj=0;jj<4;jj++) - { - jf=(j4+jj)/(p_Vid->mb_cr_size_y/4); // jf = Subblock_y-coordinate - for(ii=0;ii<4;ii++) - { - ifx=(i4+ii)/(p_Vid->mb_cr_size_x/4); // ifx = Subblock_x-coordinate + for (jj = 0; jj < 4; jj++) { + jf = (j4 + jj) / + (p_Vid->mb_cr_size_y / 4); // jf = Subblock_y-coordinate + for (ii = 0; ii < 4; ii++) { + ifx = (i4 + ii) / + (p_Vid->mb_cr_size_x / 4); // ifx = Subblock_x-coordinate - i1=(i4+ii)*f1_x + mv[0]; - j1=(j4+jj)*f1_y + mv[1]; + i1 = (i4 + ii) * f1_x + mv[0]; + j1 = (j4 + jj) * f1_y + mv[1]; - ii0=iClip3 (0, dec_picture->size_x_cr-1, i1/f1_x); - jj0=iClip3 (0, dec_picture->size_y_cr-1, j1/f1_y); - ii1=iClip3 (0, dec_picture->size_x_cr-1, ((i1+f2_x)/f1_x)); - jj1=iClip3 (0, dec_picture->size_y_cr-1, ((j1+f2_y)/f1_y)); + ii0 = iClip3(0, dec_picture->size_x_cr - 1, i1 / f1_x); + jj0 = iClip3(0, dec_picture->size_y_cr - 1, j1 / f1_y); + ii1 = iClip3(0, dec_picture->size_x_cr - 1, ((i1 + f2_x) / f1_x)); + jj1 = iClip3(0, dec_picture->size_y_cr - 1, ((j1 + f2_y) / f1_y)); - if1=(i1 & f2_x); - jf1=(j1 & f2_y); - if0=f1_x-if1; - jf0=f1_y-jf1; + if1 = (i1 & f2_x); + jf1 = (j1 & f2_y); + if0 = f1_x - if1; + jf0 = f1_y - jf1; - currSlice->mb_pred[uv + 1][jj+joff][ii+ioff] = (imgpel) - ((if0*jf0*currSlice->listX[0][ref_frame]->imgUV[uv][jj0][ii0]+ - if1*jf0*currSlice->listX[0][ref_frame]->imgUV[uv][jj0][ii1]+ - if0*jf1*currSlice->listX[0][ref_frame]->imgUV[uv][jj1][ii0]+ - if1*jf1*currSlice->listX[0][ref_frame]->imgUV[uv][jj1][ii1]+f4)/f3); + currSlice->mb_pred[uv + 1][jj + joff][ii + ioff] = + (imgpel)((if0 * jf0 * + currSlice->listX[0][ref_frame] + ->imgUV[uv][jj0][ii0] + + if1 * jf0 * + currSlice->listX[0][ref_frame] + ->imgUV[uv][jj0][ii1] + + if0 * jf1 * + currSlice->listX[0][ref_frame] + ->imgUV[uv][jj1][ii0] + + if1 * jf1 * + currSlice->listX[0][ref_frame] + ->imgUV[uv][jj1][ii1] + + f4) / + f3); } } } } - for (j = 0; j < 8; j++) - { - for (i = 0; i < 8; i++) - { - pMB[j*8+i] = currSlice->mb_pred[uv + 1][j][i]; + for (j = 0; j < 8; j++) { + for (i = 0; i < 8; i++) { + pMB[j * 8 + i] = currSlice->mb_pred[uv + 1][j][i]; } } pMB += 64; - } } // We should allocate this memory only once. - free_mem2Dpel(tmp_block); + free_mem2Dpel(tmp_block); } /*! ************************************************************************ * \brief - * Copies pixel values between a YUV frame and the temporary pixel value storage place. This is - * used to save some pixel values temporarily before overwriting it, or to copy back to a given - * location in a frame the saved pixel values. - * \param currYBlockNum - * index of the block (8x8) in the Y plane - * \param predMB - * memory area where the temporary pixel values are stored - * the Y,U,V planes are concatenated y = predMB, u = predMB+256, v = predMB+320 - * \param recfr - * pointer to a YUV frame - * \param picSizeX - * picture width in pixels - * \param regionSize - * can be 16 or 8 to tell the dimension of the region to copy + * Copies pixel values between a YUV frame and the temporary pixel value + *storage place. This is used to save some pixel values temporarily before + *overwriting it, or to copy back to a given location in a frame the saved pixel + *values. \param currYBlockNum index of the block (8x8) in the Y plane \param + *predMB memory area where the temporary pixel values are stored the Y,U,V + *planes are concatenated y = predMB, u = predMB+256, v = predMB+320 \param + *recfr pointer to a YUV frame \param picSizeX picture width in pixels \param + *regionSize can be 16 or 8 to tell the dimension of the region to copy ************************************************************************ */ -static void copyPredMB (int currYBlockNum, imgpel *predMB, frame *recfr, - int picSizeX, int regionSize) -{ +static void copyPredMB(int currYBlockNum, imgpel *predMB, frame *recfr, + int picSizeX, int regionSize) { VideoParameters *p_Vid = recfr->p_Vid; StorablePicture *dec_picture = p_Vid->dec_picture; int j, k, xmin, ymin, xmax, ymax; @@ -715,29 +683,25 @@ static void copyPredMB (int currYBlockNum, imgpel *predMB, frame *recfr, int uv_x = uv_div[0][dec_picture->chroma_format_idc]; int uv_y = uv_div[1][dec_picture->chroma_format_idc]; - xmin = (xPosYBlock(currYBlockNum,picSizeX)<<3); - ymin = (yPosYBlock(currYBlockNum,picSizeX)<<3); - xmax = xmin + regionSize -1; - ymax = ymin + regionSize -1; + xmin = (xPosYBlock(currYBlockNum, picSizeX) << 3); + ymin = (yPosYBlock(currYBlockNum, picSizeX) << 3); + xmax = xmin + regionSize - 1; + ymax = ymin + regionSize - 1; - for (j = ymin; j <= ymax; j++) - { - for (k = xmin; k <= xmax; k++) - { + for (j = ymin; j <= ymax; j++) { + for (k = xmin; k <= xmax; k++) { locationPred = j * picSizeX + k; - locationTmp = (j-ymin) * 16 + (k-xmin); + locationTmp = (j - ymin) * 16 + (k - xmin); dec_picture->imgY[j][k] = predMB[locationTmp]; } } - if (dec_picture->chroma_format_idc != YUV400) - { - for (j = (ymin>>uv_y); j <= (ymax>>uv_y); j++) - { - for (k = (xmin>>uv_x); k <= (xmax>>uv_x); k++) - { + if (dec_picture->chroma_format_idc != YUV400) { + for (j = (ymin >> uv_y); j <= (ymax >> uv_y); j++) { + for (k = (xmin >> uv_x); k <= (xmax >> uv_x); k++) { locationPred = ((j * picSizeX) >> uv_x) + k; - locationTmp = (j-(ymin>>uv_y)) * p_Vid->mb_cr_size_x + (k-(xmin>>1)) + 256; + locationTmp = (j - (ymin >> uv_y)) * p_Vid->mb_cr_size_x + + (k - (xmin >> 1)) + 256; dec_picture->imgUV[0][j][k] = predMB[locationTmp]; locationTmp += 64; @@ -751,81 +715,71 @@ static void copyPredMB (int currYBlockNum, imgpel *predMB, frame *recfr, /*! ************************************************************************ * \brief - * Calculates a weighted pixel difference between edge Y pixels of the macroblock stored in predMB - * and the pixels in the given Y plane of a frame (recY) that would become neighbor pixels if - * predMB was placed at currYBlockNum block position into the frame. This "edge distortion" value - * is used to determine how well the given macroblock in predMB would fit into the frame when - * considering spatial smoothness. If there are correctly received neighbor blocks (status stored - * in predBlocks) only they are used in calculating the edge distorion; otherwise also the already - * concealed neighbor blocks can also be used. - * \return - * The calculated weighted pixel difference at the edges of the MB. - * \param predBlocks - * status array of the neighboring blocks (if they are OK, concealed or lost) - * \param currYBlockNum - * index of the block (8x8) in the Y plane - * \param predMB - * memory area where the temporary pixel values are stored - * the Y,U,V planes are concatenated y = predMB, u = predMB+256, v = predMB+320 - * \param recY - * pointer to a Y plane of a YUV frame - * \param picSizeX + * Calculates a weighted pixel difference between edge Y pixels of the + *macroblock stored in predMB and the pixels in the given Y plane of a frame + *(recY) that would become neighbor pixels if predMB was placed at currYBlockNum + *block position into the frame. This "edge distortion" value is used to + *determine how well the given macroblock in predMB would fit into the frame + *when considering spatial smoothness. If there are correctly received neighbor + *blocks (status stored in predBlocks) only they are used in calculating the + *edge distorion; otherwise also the already concealed neighbor blocks can also + *be used. \return The calculated weighted pixel difference at the edges of the + *MB. \param predBlocks status array of the neighboring blocks (if they are OK, + *concealed or lost) \param currYBlockNum index of the block (8x8) in the Y + *plane \param predMB memory area where the temporary pixel values are stored + * the Y,U,V planes are concatenated y = predMB, u = predMB+256, v = + *predMB+320 \param recY pointer to a Y plane of a YUV frame \param picSizeX * picture width in pixels * \param regionSize * can be 16 or 8 to tell the dimension of the region to copy ************************************************************************ */ -static int edgeDistortion (int predBlocks[], int currYBlockNum, imgpel *predMB, - imgpel *recY, int picSizeX, int regionSize) -{ +static int edgeDistortion(int predBlocks[], int currYBlockNum, imgpel *predMB, + imgpel *recY, int picSizeX, int regionSize) { int i, j, distortion, numOfPredBlocks, threshold = ERC_BLOCK_OK; imgpel *currBlock = NULL, *neighbor = NULL; int currBlockOffset = 0; - currBlock = recY + (yPosYBlock(currYBlockNum,picSizeX)<<3)*picSizeX + (xPosYBlock(currYBlockNum,picSizeX)<<3); + currBlock = recY + (yPosYBlock(currYBlockNum, picSizeX) << 3) * picSizeX + + (xPosYBlock(currYBlockNum, picSizeX) << 3); - do - { + do { - distortion = 0; numOfPredBlocks = 0; + distortion = 0; + numOfPredBlocks = 0; // loop the 4 neighbors - for (j = 4; j < 8; j++) - { + for (j = 4; j < 8; j++) { /* if reliable, count boundary pixel difference */ - if (predBlocks[j] >= threshold) - { + if (predBlocks[j] >= threshold) { - switch (j) - { + switch (j) { case 4: neighbor = currBlock - picSizeX; - for ( i = 0; i < regionSize; i++ ) - { + for (i = 0; i < regionSize; i++) { distortion += iabs((int)(predMB[i] - neighbor[i])); } break; case 5: neighbor = currBlock - 1; - for ( i = 0; i < regionSize; i++ ) - { - distortion += iabs((int)(predMB[i*16] - neighbor[i*picSizeX])); + for (i = 0; i < regionSize; i++) { + distortion += iabs((int)(predMB[i * 16] - neighbor[i * picSizeX])); } break; case 6: - neighbor = currBlock + regionSize*picSizeX; - currBlockOffset = (regionSize-1)*16; - for ( i = 0; i < regionSize; i++ ) - { - distortion += iabs((int)(predMB[i+currBlockOffset] - neighbor[i])); + neighbor = currBlock + regionSize * picSizeX; + currBlockOffset = (regionSize - 1) * 16; + for (i = 0; i < regionSize; i++) { + distortion += + iabs((int)(predMB[i + currBlockOffset] - neighbor[i])); } break; case 7: neighbor = currBlock + regionSize; - currBlockOffset = regionSize-1; - for ( i = 0; i < regionSize; i++ ) - { - distortion += iabs((int)(predMB[i*16+currBlockOffset] - neighbor[i*picSizeX])); + currBlockOffset = regionSize - 1; + for (i = 0; i < regionSize; i++) { + distortion += iabs((int)(predMB[i * 16 + currBlockOffset] - + neighbor[i * picSizeX])); } break; } @@ -839,12 +793,11 @@ static int edgeDistortion (int predBlocks[], int currYBlockNum, imgpel *predMB, break; } while (numOfPredBlocks == 0); - if(numOfPredBlocks == 0) - { + if (numOfPredBlocks == 0) { return 0; // assert (numOfPredBlocks != 0); !!!KS hmm, trying to continue... } - return (distortion/numOfPredBlocks); + return (distortion / numOfPredBlocks); } // picture error concealment below @@ -858,122 +811,130 @@ static int edgeDistortion (int predBlocks[], int currYBlockNum, imgpel *predMB, * ************************************************************************* */ -static void buildPredblockRegionYUV(VideoParameters *p_Vid, int *mv, - int x, int y, imgpel *predMB, int list, int current_mb_nr) -{ +static void buildPredblockRegionYUV(VideoParameters *p_Vid, int *mv, int x, + int y, imgpel *predMB, int list, + int current_mb_nr) { imgpel **tmp_block; - int i=0,j=0,ii=0,jj=0,i1=0,j1=0,j4=0,i4=0; - int jf=0; + int i = 0, j = 0, ii = 0, jj = 0, i1 = 0, j1 = 0, j4 = 0, i4 = 0; + int jf = 0; int uv; - int vec1_x=0,vec1_y=0; - int ioff,joff; + int vec1_x = 0, vec1_y = 0; + int ioff, joff; StorablePicture *dec_picture = p_Vid->dec_picture; imgpel *pMB = predMB; - int ii0,jj0,ii1,jj1,if1,jf1,if0,jf0; + int ii0, jj0, ii1, jj1, if1, jf1, if0, jf0; int mv_mul; - //FRExt + // FRExt int f1_x, f1_y, f2_x, f2_y, f3, f4, ifx; int yuv = dec_picture->chroma_format_idc - 1; int ref_frame = mv[2]; int mb_nr = current_mb_nr; - - Macroblock *currMB = &p_Vid->mb_data[mb_nr]; // intialization code deleted, see below, StW + + Macroblock *currMB = + &p_Vid->mb_data[mb_nr]; // intialization code deleted, see below, StW Slice *currSlice = currMB->p_Slice; get_mem2Dpel(&tmp_block, MB_BLOCK_SIZE, MB_BLOCK_SIZE); /* Update coordinates of the current concealed macroblock */ - currMB->mb.x = (short) (x/BLOCK_SIZE); - currMB->mb.y = (short) (y/BLOCK_SIZE); + currMB->mb.x = (short)(x / BLOCK_SIZE); + currMB->mb.y = (short)(y / BLOCK_SIZE); currMB->block_y = currMB->mb.y * BLOCK_SIZE; - currMB->pix_c_y = currMB->mb.y * p_Vid->mb_cr_size_y/4; + currMB->pix_c_y = currMB->mb.y * p_Vid->mb_cr_size_y / 4; currMB->block_x = currMB->mb.x * BLOCK_SIZE; - currMB->pix_c_x = currMB->mb.x * p_Vid->mb_cr_size_x/4; + currMB->pix_c_x = currMB->mb.x * p_Vid->mb_cr_size_x / 4; - mv_mul=4; + mv_mul = 4; // luma ******************************************************* - vec1_x = x*mv_mul + mv[0]; - vec1_y = y*mv_mul + mv[1]; - get_block_luma(currSlice->listX[list][ref_frame], vec1_x, vec1_y, BLOCK_SIZE, BLOCK_SIZE, tmp_block, - dec_picture->iLumaStride,dec_picture->size_x_m1, (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 : dec_picture->size_y_m1,currSlice->tmp_res, - p_Vid->max_pel_value_comp[PLANE_Y],(imgpel) p_Vid->dc_pred_value_comp[PLANE_Y], currMB); + vec1_x = x * mv_mul + mv[0]; + vec1_y = y * mv_mul + mv[1]; + get_block_luma(currSlice->listX[list][ref_frame], vec1_x, vec1_y, BLOCK_SIZE, + BLOCK_SIZE, tmp_block, dec_picture->iLumaStride, + dec_picture->size_x_m1, + (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 + : dec_picture->size_y_m1, + currSlice->tmp_res, p_Vid->max_pel_value_comp[PLANE_Y], + (imgpel)p_Vid->dc_pred_value_comp[PLANE_Y], currMB); - for(jj=0;jjmb_pred[LumaComp][jj][ii]=tmp_block[jj][ii]; + for (jj = 0; jj < MB_BLOCK_SIZE / BLOCK_SIZE; jj++) + for (ii = 0; ii < BLOCK_SIZE; ii++) + currSlice->mb_pred[LumaComp][jj][ii] = tmp_block[jj][ii]; - - for (j = 0; j < 4; j++) - { - for (i = 0; i < 4; i++) - { - pMB[j*4+i] = currSlice->mb_pred[LumaComp][j][i]; + for (j = 0; j < 4; j++) { + for (i = 0; i < 4; i++) { + pMB[j * 4 + i] = currSlice->mb_pred[LumaComp][j][i]; } } pMB += 16; - if (dec_picture->chroma_format_idc != YUV400) - { + if (dec_picture->chroma_format_idc != YUV400) { // chroma ******************************************************* - f1_x = 64/(p_Vid->mb_cr_size_x); - f2_x=f1_x-1; + f1_x = 64 / (p_Vid->mb_cr_size_x); + f2_x = f1_x - 1; - f1_y = 64/(p_Vid->mb_cr_size_y); - f2_y=f1_y-1; + f1_y = 64 / (p_Vid->mb_cr_size_y); + f2_y = f1_y - 1; - f3=f1_x*f1_y; - f4=f3>>1; + f3 = f1_x * f1_y; + f4 = f3 >> 1; - for(uv=0;uv<2;uv++) - { + for (uv = 0; uv < 2; uv++) { joff = subblk_offset_y[yuv][0][0]; - j4=currMB->pix_c_y+joff; + j4 = currMB->pix_c_y + joff; ioff = subblk_offset_x[yuv][0][0]; - i4=currMB->pix_c_x+ioff; + i4 = currMB->pix_c_x + ioff; - for(jj=0;jj<2;jj++) - { - jf=(j4+jj)/(p_Vid->mb_cr_size_y/4); // jf = Subblock_y-coordinate - for(ii=0;ii<2;ii++) - { - ifx=(i4+ii)/(p_Vid->mb_cr_size_x/4); // ifx = Subblock_x-coordinate + for (jj = 0; jj < 2; jj++) { + jf = (j4 + jj) / + (p_Vid->mb_cr_size_y / 4); // jf = Subblock_y-coordinate + for (ii = 0; ii < 2; ii++) { + ifx = (i4 + ii) / + (p_Vid->mb_cr_size_x / 4); // ifx = Subblock_x-coordinate - i1=(i4+ii)*f1_x + mv[0]; - j1=(j4+jj)*f1_y + mv[1]; + i1 = (i4 + ii) * f1_x + mv[0]; + j1 = (j4 + jj) * f1_y + mv[1]; - ii0=iClip3 (0, dec_picture->size_x_cr-1, i1/f1_x); - jj0=iClip3 (0, dec_picture->size_y_cr-1, j1/f1_y); - ii1=iClip3 (0, dec_picture->size_x_cr-1, ((i1+f2_x)/f1_x)); - jj1=iClip3 (0, dec_picture->size_y_cr-1, ((j1+f2_y)/f1_y)); + ii0 = iClip3(0, dec_picture->size_x_cr - 1, i1 / f1_x); + jj0 = iClip3(0, dec_picture->size_y_cr - 1, j1 / f1_y); + ii1 = iClip3(0, dec_picture->size_x_cr - 1, ((i1 + f2_x) / f1_x)); + jj1 = iClip3(0, dec_picture->size_y_cr - 1, ((j1 + f2_y) / f1_y)); - if1=(i1 & f2_x); - jf1=(j1 & f2_y); - if0=f1_x-if1; - jf0=f1_y-jf1; + if1 = (i1 & f2_x); + jf1 = (j1 & f2_y); + if0 = f1_x - if1; + jf0 = f1_y - jf1; - currSlice->mb_pred[uv + 1][jj][ii]=(imgpel) ((if0*jf0*currSlice->listX[list][ref_frame]->imgUV[uv][jj0][ii0]+ - if1*jf0*currSlice->listX[list][ref_frame]->imgUV[uv][jj0][ii1]+ - if0*jf1*currSlice->listX[list][ref_frame]->imgUV[uv][jj1][ii0]+ - if1*jf1*currSlice->listX[list][ref_frame]->imgUV[uv][jj1][ii1]+f4)/f3); + currSlice->mb_pred[uv + 1][jj][ii] = + (imgpel)((if0 * jf0 * + currSlice->listX[list][ref_frame] + ->imgUV[uv][jj0][ii0] + + if1 * jf0 * + currSlice->listX[list][ref_frame] + ->imgUV[uv][jj0][ii1] + + if0 * jf1 * + currSlice->listX[list][ref_frame] + ->imgUV[uv][jj1][ii0] + + if1 * jf1 * + currSlice->listX[list][ref_frame] + ->imgUV[uv][jj1][ii1] + + f4) / + f3); } } - for (j = 0; j < 2; j++) - { - for (i = 0; i < 2; i++) - { - pMB[j*2+i] = currSlice->mb_pred[uv + 1][j][i]; + for (j = 0; j < 2; j++) { + for (i = 0; i < 2; i++) { + pMB[j * 2 + i] = currSlice->mb_pred[uv + 1][j][i]; } } pMB += 4; - } } free_mem2Dpel(tmp_block); @@ -982,14 +943,15 @@ static void buildPredblockRegionYUV(VideoParameters *p_Vid, int *mv, /*! ************************************************************************ * \brief -* compares two stored pictures by picture number for qsort in descending order +* compares two stored pictures by picture number for qsort in descending +*order * ************************************************************************ */ -static inline int compare_pic_by_pic_num_desc( const void *arg1, const void *arg2 ) -{ - int pic_num1 = (*(StorablePicture**)arg1)->pic_num; - int pic_num2 = (*(StorablePicture**)arg2)->pic_num; +static inline int compare_pic_by_pic_num_desc(const void *arg1, + const void *arg2) { + int pic_num1 = (*(StorablePicture **)arg1)->pic_num; + int pic_num2 = (*(StorablePicture **)arg2)->pic_num; if (pic_num1 < pic_num2) return 1; @@ -1002,18 +964,19 @@ static inline int compare_pic_by_pic_num_desc( const void *arg1, const void *arg /*! ************************************************************************ * \brief -* compares two stored pictures by picture number for qsort in descending order +* compares two stored pictures by picture number for qsort in descending +*order * ************************************************************************ */ -static inline int compare_pic_by_lt_pic_num_asc( const void *arg1, const void *arg2 ) -{ - int long_term_pic_num1 = (*(StorablePicture**)arg1)->long_term_pic_num; - int long_term_pic_num2 = (*(StorablePicture**)arg2)->long_term_pic_num; - if ( long_term_pic_num1 < long_term_pic_num2) +static inline int compare_pic_by_lt_pic_num_asc(const void *arg1, + const void *arg2) { + int long_term_pic_num1 = (*(StorablePicture **)arg1)->long_term_pic_num; + int long_term_pic_num2 = (*(StorablePicture **)arg2)->long_term_pic_num; + if (long_term_pic_num1 < long_term_pic_num2) return -1; - if ( long_term_pic_num1 > long_term_pic_num2) + if (long_term_pic_num1 > long_term_pic_num2) return 1; else return 0; @@ -1026,20 +989,18 @@ static inline int compare_pic_by_lt_pic_num_asc( const void *arg1, const void *a * ************************************************************************ */ -static inline int compare_pic_by_poc_asc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(StorablePicture**)arg1)->poc; - int poc2 = (*(StorablePicture**)arg2)->poc; +static inline int compare_pic_by_poc_asc(const void *arg1, const void *arg2) { + int poc1 = (*(StorablePicture **)arg1)->poc; + int poc2 = (*(StorablePicture **)arg2)->poc; - if ( poc1 < poc2) - return -1; - if ( poc1 > poc2) + if (poc1 < poc2) + return -1; + if (poc1 > poc2) return 1; else return 0; } - /*! ************************************************************************ * \brief @@ -1047,10 +1008,9 @@ static inline int compare_pic_by_poc_asc( const void *arg1, const void *arg2 ) * ************************************************************************ */ -static inline int compare_pic_by_poc_desc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(StorablePicture**)arg1)->poc; - int poc2 = (*(StorablePicture**)arg2)->poc; +static inline int compare_pic_by_poc_desc(const void *arg1, const void *arg2) { + int poc1 = (*(StorablePicture **)arg1)->poc; + int poc2 = (*(StorablePicture **)arg2)->poc; if (poc1 < poc2) return 1; @@ -1067,18 +1027,17 @@ static inline int compare_pic_by_poc_desc( const void *arg1, const void *arg2 ) ************************************************************************ */ -static void CopyImgData(imgpel **inputY, imgpel ***inputUV, imgpel **outputY, imgpel ***outputUV, - int img_width, int img_height, int img_width_cr, int img_height_cr) -{ +static void CopyImgData(imgpel **inputY, imgpel ***inputUV, imgpel **outputY, + imgpel ***outputUV, int img_width, int img_height, + int img_width_cr, int img_height_cr) { int x, y; - for (y=0; yused_size - 1; int i; - for(i = used_size; i >= 0; i--) - { - if (p_Dpb->fs[i]->is_used==3) - { + for (i = used_size; i >= 0; i--) { + if (p_Dpb->fs[i]->is_used == 3) { if (((p_Dpb->fs[i]->frame->used_for_reference) && (!p_Dpb->fs[i]->frame->is_long_term)) /*|| ((p_Dpb->fs[i]->frame->used_for_reference==0) && (p_Dpb->fs[i]->frame->slice_type == P_SLICE))*/ ) @@ -1121,13 +1077,13 @@ static StorablePicture* get_last_ref_pic_from_dpb(DecodedPictureBuffer *p_Dpb) ************************************************************************ */ -static void copy_to_conceal(StorablePicture *src, StorablePicture *dst, VideoParameters *p_Vid) -{ - int i=0; +static void copy_to_conceal(StorablePicture *src, StorablePicture *dst, + VideoParameters *p_Vid) { + int i = 0; int mv[3]; int multiplier; imgpel *predMB, *storeYUV; - int j, y, x, mb_height, mb_width, ii=0, jj=0; + int j, y, x, mb_height, mb_width, ii = 0, jj = 0; int uv; int mm, nn; int scale = 1; @@ -1136,21 +1092,23 @@ static void copy_to_conceal(StorablePicture *src, StorablePicture *dst, VideoPar int current_mb_nr = 0; - dst->PicSizeInMbs = src->PicSizeInMbs; + dst->PicSizeInMbs = src->PicSizeInMbs; dst->slice_type = src->slice_type = p_Vid->conceal_slice_type; - dst->idr_flag = FALSE; //since we do not want to clears the ref list + dst->idr_flag = FALSE; // since we do not want to clears the ref list dst->no_output_of_prior_pics_flag = src->no_output_of_prior_pics_flag; dst->long_term_reference_flag = src->long_term_reference_flag; - dst->adaptive_ref_pic_buffering_flag = src->adaptive_ref_pic_buffering_flag = 0; + dst->adaptive_ref_pic_buffering_flag = src->adaptive_ref_pic_buffering_flag = + 0; dst->chroma_format_idc = src->chroma_format_idc; dst->frame_mbs_only_flag = src->frame_mbs_only_flag; dst->frame_cropping_flag = src->frame_cropping_flag; dst->frame_cropping_rect_left_offset = src->frame_cropping_rect_left_offset; dst->frame_cropping_rect_right_offset = src->frame_cropping_rect_right_offset; - dst->frame_cropping_rect_bottom_offset = src->frame_cropping_rect_bottom_offset; + dst->frame_cropping_rect_bottom_offset = + src->frame_cropping_rect_bottom_offset; dst->frame_cropping_rect_top_offset = src->frame_cropping_rect_top_offset; dst->qp = src->qp; dst->slice_qp_delta = src->slice_qp_delta; @@ -1158,26 +1116,24 @@ static void copy_to_conceal(StorablePicture *src, StorablePicture *dst, VideoPar dec_picture = src; // Conceals the missing frame by frame copy concealment - if (p_Vid->conceal_mode==1) - { + if (p_Vid->conceal_mode == 1) { // We need these initializations for using deblocking filter for frame copy // concealment as well. dst->PicWidthInMbs = src->PicWidthInMbs; dst->PicSizeInMbs = src->PicSizeInMbs; - CopyImgData( src->imgY, src->imgUV, dst->imgY, dst->imgUV, p_Vid->width, p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); + CopyImgData(src->imgY, src->imgUV, dst->imgY, dst->imgUV, p_Vid->width, + p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); } // Conceals the missing frame by motion vector copy concealment - if (p_Vid->conceal_mode==2) - { - if (dec_picture->chroma_format_idc != YUV400) - { - storeYUV = (imgpel *) malloc ( (16 + (p_Vid->mb_cr_size_x*p_Vid->mb_cr_size_y)*2/16) * sizeof (imgpel)); - } - else - { - storeYUV = (imgpel *) malloc (16 * sizeof (imgpel)); + if (p_Vid->conceal_mode == 2) { + if (dec_picture->chroma_format_idc != YUV400) { + storeYUV = (imgpel *)malloc( + (16 + (p_Vid->mb_cr_size_x * p_Vid->mb_cr_size_y) * 2 / 16) * + sizeof(imgpel)); + } else { + storeYUV = (imgpel *)malloc(16 * sizeof(imgpel)); } p_Vid->erc_img = p_Vid; @@ -1185,67 +1141,64 @@ static void copy_to_conceal(StorablePicture *src, StorablePicture *dst, VideoPar dst->PicWidthInMbs = src->PicWidthInMbs; dst->PicSizeInMbs = src->PicSizeInMbs; mb_width = dst->PicWidthInMbs; - mb_height = (dst->PicSizeInMbs)/(dst->PicWidthInMbs); + mb_height = (dst->PicSizeInMbs) / (dst->PicWidthInMbs); scale = (p_Vid->conceal_slice_type == B_SLICE) ? 2 : 1; - if(p_Vid->conceal_slice_type == B_SLICE) - init_lists_for_non_reference_loss(p_Vid->p_Dpb, dst->slice_type, p_Vid->ppSliceList[0]->structure); + if (p_Vid->conceal_slice_type == B_SLICE) + init_lists_for_non_reference_loss(p_Vid->p_Dpb, dst->slice_type, + p_Vid->ppSliceList[0]->structure); else - init_lists(p_Vid->ppSliceList[0]); //p_Vid->currentSlice); + init_lists(p_Vid->ppSliceList[0]); // p_Vid->currentSlice); multiplier = BLOCK_SIZE; - for(i=0;imv_info[i][j].mv[LIST_0].mv_x / scale; mv[1] = src->mv_info[i][j].mv[LIST_0].mv_y / scale; mv[2] = src->mv_info[i][j].ref_idx[LIST_0]; - if(mv[2]<0) - mv[2]=0; + if (mv[2] < 0) + mv[2] = 0; - dst->mv_info[i][j].mv[LIST_0].mv_x = (short) mv[0]; - dst->mv_info[i][j].mv[LIST_0].mv_y = (short) mv[1]; - dst->mv_info[i][j].ref_idx[LIST_0] = (signed char) mv[2]; + dst->mv_info[i][j].mv[LIST_0].mv_x = (short)mv[0]; + dst->mv_info[i][j].mv[LIST_0].mv_y = (short)mv[1]; + dst->mv_info[i][j].ref_idx[LIST_0] = (signed char)mv[2]; - x = (j) * multiplier; - y = (i) * multiplier; + x = (j)*multiplier; + y = (i)*multiplier; - if ((mm%16==0) && (nn%16==0)) + if ((mm % 16 == 0) && (nn % 16 == 0)) current_mb_nr++; - buildPredblockRegionYUV(p_Vid->erc_img, mv, x, y, storeYUV, LIST_0, current_mb_nr); + buildPredblockRegionYUV(p_Vid->erc_img, mv, x, y, storeYUV, LIST_0, + current_mb_nr); predMB = storeYUV; - for(ii=0;iiimgY[i*multiplier+ii][j*multiplier+jj] = predMB[ii*(multiplier)+jj]; + for (ii = 0; ii < multiplier; ii++) { + for (jj = 0; jj < multiplier; jj++) { + dst->imgY[i * multiplier + ii][j * multiplier + jj] = + predMB[ii * (multiplier) + jj]; } } - predMB = predMB + (multiplier*multiplier); + predMB = predMB + (multiplier * multiplier); - if (dec_picture->chroma_format_idc != YUV400) - { + if (dec_picture->chroma_format_idc != YUV400) { - for(uv=0;uv<2;uv++) - { - for(ii=0;ii< (multiplier/2);ii++) - { - for(jj=0;jj< (multiplier/2);jj++) - { - dst->imgUV[uv][i*multiplier/2 +ii][j*multiplier/2 +jj] = predMB[ii*(multiplier/2)+jj]; + for (uv = 0; uv < 2; uv++) { + for (ii = 0; ii < (multiplier / 2); ii++) { + for (jj = 0; jj < (multiplier / 2); jj++) { + dst->imgUV[uv][i * multiplier / 2 + ii] + [j * multiplier / 2 + jj] = + predMB[ii * (multiplier / 2) + jj]; } } - predMB = predMB + (multiplier*multiplier/4); + predMB = predMB + (multiplier * multiplier / 4); } } } @@ -1262,9 +1215,8 @@ static void copy_to_conceal(StorablePicture *src, StorablePicture *dst, VideoPar ************************************************************************ */ -static void -copy_prev_pic_to_concealed_pic(StorablePicture *picture, DecodedPictureBuffer *p_Dpb) -{ +static void copy_prev_pic_to_concealed_pic(StorablePicture *picture, + DecodedPictureBuffer *p_Dpb) { VideoParameters *p_Vid = p_Dpb->p_Vid; /* get the last ref pic in dpb */ StorablePicture *ref_pic = get_last_ref_pic_from_dpb(p_Dpb); @@ -1276,7 +1228,6 @@ copy_prev_pic_to_concealed_pic(StorablePicture *picture, DecodedPictureBuffer *p copy_to_conceal(ref_pic, picture, p_Vid); } - /*! ************************************************************************ * \brief @@ -1287,8 +1238,7 @@ copy_prev_pic_to_concealed_pic(StorablePicture *picture, DecodedPictureBuffer *p ************************************************************************ */ -void conceal_lost_frames(DecodedPictureBuffer *p_Dpb, Slice *pSlice) -{ +void conceal_lost_frames(DecodedPictureBuffer *p_Dpb, Slice *pSlice) { VideoParameters *p_Vid = p_Dpb->p_Vid; int CurrFrameNum; int UnusedShortTermFrameNum; @@ -1301,22 +1251,20 @@ void conceal_lost_frames(DecodedPictureBuffer *p_Dpb, Slice *pSlice) // printf("A gap in frame number is found, try to fill it.\n"); - if(p_Vid->IDR_concealment_flag == 1) - { + if (p_Vid->IDR_concealment_flag == 1) { // Conceals an IDR frame loss. Uses the reference frame in the previous // GOP for concealment. UnusedShortTermFrameNum = 0; p_Vid->last_ref_pic_poc = -p_Vid->poc_gap; p_Vid->earlier_missing_poc = 0; - } - else + } else UnusedShortTermFrameNum = (p_Vid->pre_frame_num + 1) % p_Vid->MaxFrameNum; CurrFrameNum = pSlice->frame_num; - while (CurrFrameNum != UnusedShortTermFrameNum) - { - picture = alloc_storable_picture (p_Vid, FRAME, p_Vid->width, p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); + while (CurrFrameNum != UnusedShortTermFrameNum) { + picture = alloc_storable_picture(p_Vid, FRAME, p_Vid->width, p_Vid->height, + p_Vid->width_cr, p_Vid->height_cr); picture->coded_frame = 1; picture->pic_num = UnusedShortTermFrameNum; @@ -1330,17 +1278,16 @@ void conceal_lost_frames(DecodedPictureBuffer *p_Dpb, Slice *pSlice) pSlice->frame_num = UnusedShortTermFrameNum; - picture->top_poc=p_Vid->last_ref_pic_poc + p_Vid->ref_poc_gap; - picture->bottom_poc=picture->top_poc; - picture->frame_poc=picture->top_poc; - picture->poc=picture->top_poc; + picture->top_poc = p_Vid->last_ref_pic_poc + p_Vid->ref_poc_gap; + picture->bottom_poc = picture->top_poc; + picture->frame_poc = picture->top_poc; + picture->poc = picture->top_poc; p_Vid->last_ref_pic_poc = picture->poc; copy_prev_pic_to_concealed_pic(picture, p_Dpb); - //if (UnusedShortTermFrameNum == 0) - if(p_Vid->IDR_concealment_flag == 1) - { + // if (UnusedShortTermFrameNum == 0) + if (p_Vid->IDR_concealment_flag == 1) { picture->slice_type = I_SLICE; picture->idr_flag = TRUE; #if (MVC_EXTENSION_ENABLE) @@ -1348,24 +1295,24 @@ void conceal_lost_frames(DecodedPictureBuffer *p_Dpb, Slice *pSlice) #else flush_dpb(p_Dpb); #endif - picture->top_poc= 0; - picture->bottom_poc=picture->top_poc; - picture->frame_poc=picture->top_poc; - picture->poc=picture->top_poc; + picture->top_poc = 0; + picture->bottom_poc = picture->top_poc; + picture->frame_poc = picture->top_poc; + picture->poc = picture->top_poc; p_Vid->last_ref_pic_poc = picture->poc; } store_picture_in_dpb(p_Vid->p_Dpb, picture); - picture=NULL; + picture = NULL; p_Vid->pre_frame_num = UnusedShortTermFrameNum; - UnusedShortTermFrameNum = (UnusedShortTermFrameNum + 1) % p_Vid->MaxFrameNum; + UnusedShortTermFrameNum = + (UnusedShortTermFrameNum + 1) % p_Vid->MaxFrameNum; // update reference flags and set current flag. - for(i=16;i>0;i--) - { - pSlice->ref_flag[i] = pSlice->ref_flag[i-1]; + for (i = 16; i > 0; i--) { + pSlice->ref_flag[i] = pSlice->ref_flag[i - 1]; } pSlice->ref_flag[0] = 0; } @@ -1383,15 +1330,12 @@ void conceal_lost_frames(DecodedPictureBuffer *p_Dpb, Slice *pSlice) ************************************************************************ */ -void update_ref_list_for_concealment(DecodedPictureBuffer *p_Dpb) -{ +void update_ref_list_for_concealment(DecodedPictureBuffer *p_Dpb) { VideoParameters *p_Vid = p_Dpb->p_Vid; - unsigned i, j= 0; + unsigned i, j = 0; - for (i = 0; i < p_Dpb->used_size; i++) - { - if (p_Dpb->fs[i]->concealment_reference) - { + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->concealment_reference) { p_Dpb->fs_ref[j++] = p_Dpb->fs[i]; } } @@ -1403,13 +1347,14 @@ void update_ref_list_for_concealment(DecodedPictureBuffer *p_Dpb) ************************************************************************ * \brief * Initialize the list based on the B frame or non reference 'p' frame -* to be concealed. The function initialize currSlice->listX[0] and list 1 depending -* on current picture type +* to be concealed. The function initialize currSlice->listX[0] and list 1 +*depending on current picture type * ************************************************************************ */ -void init_lists_for_non_reference_loss(DecodedPictureBuffer *p_Dpb, int currSliceType, PictureStructure currPicStructure) -{ +void init_lists_for_non_reference_loss(DecodedPictureBuffer *p_Dpb, + int currSliceType, + PictureStructure currPicStructure) { VideoParameters *p_Vid = p_Dpb->p_Vid; seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; @@ -1423,14 +1368,12 @@ void init_lists_for_non_reference_loss(DecodedPictureBuffer *p_Dpb, int currSlic StorablePicture *tmp_s; - if (currPicStructure == FRAME) - { - for(i=0;iref_frames_in_buffer; i++) - { - if(p_Dpb->fs[i]->concealment_reference == 1) - { - if(p_Dpb->fs[i]->frame_num > p_Vid->frame_to_conceal) - p_Dpb->fs_ref[i]->frame_num_wrap = p_Dpb->fs[i]->frame_num - MaxFrameNum; + if (currPicStructure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs[i]->concealment_reference == 1) { + if (p_Dpb->fs[i]->frame_num > p_Vid->frame_to_conceal) + p_Dpb->fs_ref[i]->frame_num_wrap = + p_Dpb->fs[i]->frame_num - MaxFrameNum; else p_Dpb->fs_ref[i]->frame_num_wrap = p_Dpb->fs[i]->frame_num; p_Dpb->fs_ref[i]->frame->pic_num = p_Dpb->fs_ref[i]->frame_num_wrap; @@ -1438,104 +1381,105 @@ void init_lists_for_non_reference_loss(DecodedPictureBuffer *p_Dpb, int currSlic } } - if (currSliceType == P_SLICE) - { + if (currSliceType == P_SLICE) { // Calculate FrameNumWrap and PicNum - if (currPicStructure == FRAME) - { - for(i=0;iused_size; i++) - { - if(p_Dpb->fs[i]->concealment_reference == 1) - { + if (currPicStructure == FRAME) { + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->concealment_reference == 1) { p_Vid->ppSliceList[0]->listX[0][list0idx++] = p_Dpb->fs[i]->frame; } } // order list 0 by PicNum - qsort((void *)p_Vid->ppSliceList[0]->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_pic_num_desc); - p_Vid->ppSliceList[0]->listXsize[0] = (signed char) list0idx; + qsort((void *)p_Vid->ppSliceList[0]->listX[0], list0idx, + sizeof(StorablePicture *), compare_pic_by_pic_num_desc); + p_Vid->ppSliceList[0]->listXsize[0] = (signed char)list0idx; } } - if (currSliceType == B_SLICE) - { - if (currPicStructure == FRAME) - { + if (currSliceType == B_SLICE) { + if (currPicStructure == FRAME) { // for(i=0;iref_frames_in_buffer; i++) - for(i=0;iused_size; i++) - { - if(p_Dpb->fs[i]->concealment_reference == 1) - { - if(p_Vid->earlier_missing_poc > p_Dpb->fs[i]->frame->poc) + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->concealment_reference == 1) { + if (p_Vid->earlier_missing_poc > p_Dpb->fs[i]->frame->poc) p_Vid->ppSliceList[0]->listX[0][list0idx++] = p_Dpb->fs[i]->frame; } } - qsort((void *)p_Vid->ppSliceList[0]->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_poc_desc); + qsort((void *)p_Vid->ppSliceList[0]->listX[0], list0idx, + sizeof(StorablePicture *), compare_pic_by_poc_desc); list0idx_1 = list0idx; // for(i=0;iref_frames_in_buffer; i++) - for(i=0;iused_size; i++) - { - if(p_Dpb->fs[i]->concealment_reference == 1) - { - if(p_Vid->earlier_missing_poc < p_Dpb->fs[i]->frame->poc) + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->concealment_reference == 1) { + if (p_Vid->earlier_missing_poc < p_Dpb->fs[i]->frame->poc) p_Vid->ppSliceList[0]->listX[0][list0idx++] = p_Dpb->fs[i]->frame; } } - qsort((void *)&p_Vid->ppSliceList[0]->listX[0][list0idx_1], list0idx-list0idx_1, sizeof(StorablePicture*), compare_pic_by_poc_asc); + qsort((void *)&p_Vid->ppSliceList[0]->listX[0][list0idx_1], + list0idx - list0idx_1, sizeof(StorablePicture *), + compare_pic_by_poc_asc); - for (j=0; jppSliceList[0]->listX[1][list0idx-list0idx_1+j]=p_Vid->ppSliceList[0]->listX[0][j]; + for (j = 0; j < list0idx_1; j++) { + p_Vid->ppSliceList[0]->listX[1][list0idx - list0idx_1 + j] = + p_Vid->ppSliceList[0]->listX[0][j]; } - for (j=list0idx_1; jppSliceList[0]->listX[1][j-list0idx_1]=p_Vid->ppSliceList[0]->listX[0][j]; + for (j = list0idx_1; j < list0idx; j++) { + p_Vid->ppSliceList[0]->listX[1][j - list0idx_1] = + p_Vid->ppSliceList[0]->listX[0][j]; } - p_Vid->ppSliceList[0]->listXsize[0] = p_Vid->ppSliceList[0]->listXsize[1] = (signed char) list0idx; + p_Vid->ppSliceList[0]->listXsize[0] = + p_Vid->ppSliceList[0]->listXsize[1] = (signed char)list0idx; - qsort((void *)&p_Vid->ppSliceList[0]->listX[0][(short) p_Vid->ppSliceList[0]->listXsize[0]], list0idx-p_Vid->ppSliceList[0]->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - qsort((void *)&p_Vid->ppSliceList[0]->listX[1][(short) p_Vid->ppSliceList[0]->listXsize[0]], list0idx-p_Vid->ppSliceList[0]->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - p_Vid->ppSliceList[0]->listXsize[0] = p_Vid->ppSliceList[0]->listXsize[1] = (signed char) list0idx; + qsort((void *)&p_Vid->ppSliceList[0] + ->listX[0][(short)p_Vid->ppSliceList[0]->listXsize[0]], + list0idx - p_Vid->ppSliceList[0]->listXsize[0], + sizeof(StorablePicture *), compare_pic_by_lt_pic_num_asc); + qsort((void *)&p_Vid->ppSliceList[0] + ->listX[1][(short)p_Vid->ppSliceList[0]->listXsize[0]], + list0idx - p_Vid->ppSliceList[0]->listXsize[0], + sizeof(StorablePicture *), compare_pic_by_lt_pic_num_asc); + p_Vid->ppSliceList[0]->listXsize[0] = + p_Vid->ppSliceList[0]->listXsize[1] = (signed char)list0idx; } } - if ((p_Vid->ppSliceList[0]->listXsize[0] == p_Vid->ppSliceList[0]->listXsize[1]) && (p_Vid->ppSliceList[0]->listXsize[0] > 1)) - { + if ((p_Vid->ppSliceList[0]->listXsize[0] == + p_Vid->ppSliceList[0]->listXsize[1]) && + (p_Vid->ppSliceList[0]->listXsize[0] > 1)) { // check if lists are identical, if yes swap first two elements of listX[1] - diff=0; - for (j = 0; j< p_Vid->ppSliceList[0]->listXsize[0]; j++) - { - if (p_Vid->ppSliceList[0]->listX[0][j]!=p_Vid->ppSliceList[0]->listX[1][j]) - diff=1; + diff = 0; + for (j = 0; j < p_Vid->ppSliceList[0]->listXsize[0]; j++) { + if (p_Vid->ppSliceList[0]->listX[0][j] != + p_Vid->ppSliceList[0]->listX[1][j]) + diff = 1; } - if (!diff) - { + if (!diff) { tmp_s = p_Vid->ppSliceList[0]->listX[1][0]; - p_Vid->ppSliceList[0]->listX[1][0]=p_Vid->ppSliceList[0]->listX[1][1]; - p_Vid->ppSliceList[0]->listX[1][1]=tmp_s; + p_Vid->ppSliceList[0]->listX[1][0] = p_Vid->ppSliceList[0]->listX[1][1]; + p_Vid->ppSliceList[0]->listX[1][1] = tmp_s; } } // set max size - p_Vid->ppSliceList[0]->listXsize[0] = (signed char) imin (p_Vid->ppSliceList[0]->listXsize[0], (int)active_sps->num_ref_frames); - p_Vid->ppSliceList[0]->listXsize[1] = (signed char) imin (p_Vid->ppSliceList[0]->listXsize[1], (int)active_sps->num_ref_frames); + p_Vid->ppSliceList[0]->listXsize[0] = (signed char)imin( + p_Vid->ppSliceList[0]->listXsize[0], (int)active_sps->num_ref_frames); + p_Vid->ppSliceList[0]->listXsize[1] = (signed char)imin( + p_Vid->ppSliceList[0]->listXsize[1], (int)active_sps->num_ref_frames); p_Vid->ppSliceList[0]->listXsize[1] = 0; // set the unused list entries to NULL - for (i=p_Vid->ppSliceList[0]->listXsize[0]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = p_Vid->ppSliceList[0]->listXsize[0]; i < (MAX_LIST_SIZE); i++) { p_Vid->ppSliceList[0]->listX[0][i] = NULL; } - for (i=p_Vid->ppSliceList[0]->listXsize[1]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = p_Vid->ppSliceList[0]->listXsize[1]; i < (MAX_LIST_SIZE); i++) { p_Vid->ppSliceList[0]->listX[1][i] = NULL; } } - /*! ************************************************************************ * \brief @@ -1546,21 +1490,19 @@ void init_lists_for_non_reference_loss(DecodedPictureBuffer *p_Dpb, int currSlic ************************************************************************ */ -StorablePicture *get_pic_from_dpb(DecodedPictureBuffer *p_Dpb, int missingpoc, unsigned int *pos) -{ +StorablePicture *get_pic_from_dpb(DecodedPictureBuffer *p_Dpb, int missingpoc, + unsigned int *pos) { VideoParameters *p_Vid = p_Dpb->p_Vid; int used_size = p_Dpb->used_size - 1; int i, concealfrom = 0; - if(p_Vid->conceal_mode == 1) + if (p_Vid->conceal_mode == 1) concealfrom = missingpoc - p_Vid->poc_gap; else if (p_Vid->conceal_mode == 2) concealfrom = missingpoc + p_Vid->poc_gap; - for(i = used_size; i >= 0; i--) - { - if(p_Dpb->fs[i]->poc == concealfrom) - { + for (i = used_size; i >= 0; i--) { + if (p_Dpb->fs[i]->poc == concealfrom) { *pos = i; return p_Dpb->fs[i]->frame; } @@ -1578,10 +1520,7 @@ StorablePicture *get_pic_from_dpb(DecodedPictureBuffer *p_Dpb, int missingpoc, u ************************************************************************ */ -int comp(const void *i, const void *j) -{ - return *(int *)i - *(int *)j; -} +int comp(const void *i, const void *j) { return *(int *)i - *(int *)j; } /*! ************************************************************************ @@ -1592,14 +1531,13 @@ int comp(const void *i, const void *j) ************************************************************************ */ -struct concealment_node * init_node( StorablePicture* picture, int missingpoc ) -{ +struct concealment_node *init_node(StorablePicture *picture, int missingpoc) { struct concealment_node *ptr; - ptr = (struct concealment_node *) calloc( 1, sizeof(struct concealment_node ) ); + ptr = (struct concealment_node *)calloc(1, sizeof(struct concealment_node)); - if( ptr == NULL ) - return (struct concealment_node *) NULL; + if (ptr == NULL) + return (struct concealment_node *)NULL; else { ptr->picture = picture; ptr->missingpocs = missingpoc; @@ -1616,12 +1554,10 @@ struct concealment_node * init_node( StorablePicture* picture, int missingpoc ) ************************************************************************ */ -void print_node( struct concealment_node *ptr ) -{ - printf("Missing POC=%d\n", ptr->missingpocs ); +void print_node(struct concealment_node *ptr) { + printf("Missing POC=%d\n", ptr->missingpocs); } - /*! ************************************************************************ * \brief @@ -1630,11 +1566,9 @@ void print_node( struct concealment_node *ptr ) ************************************************************************ */ -void print_list( struct concealment_node *ptr ) -{ - while( ptr != NULL ) - { - print_node( ptr ); +void print_list(struct concealment_node *ptr) { + while (ptr != NULL) { + print_node(ptr); ptr = ptr->next; } } @@ -1647,11 +1581,9 @@ void print_list( struct concealment_node *ptr ) ************************************************************************ */ - -static void add_node( VideoParameters *p_Vid, struct concealment_node *concealment_new ) -{ - if( p_Vid->concealment_head == NULL ) - { +static void add_node(VideoParameters *p_Vid, + struct concealment_node *concealment_new) { + if (p_Vid->concealment_head == NULL) { p_Vid->concealment_end = p_Vid->concealment_head = concealment_new; return; } @@ -1659,7 +1591,6 @@ static void add_node( VideoParameters *p_Vid, struct concealment_node *concealme p_Vid->concealment_end = concealment_new; } - /*! ************************************************************************ * \brief @@ -1668,14 +1599,11 @@ static void add_node( VideoParameters *p_Vid, struct concealment_node *concealme ************************************************************************ */ - -static void delete_node( VideoParameters *p_Vid, struct concealment_node *ptr ) -{ +static void delete_node(VideoParameters *p_Vid, struct concealment_node *ptr) { // We only need to delete the first node in the linked list - if( ptr == p_Vid->concealment_head ) - { + if (ptr == p_Vid->concealment_head) { p_Vid->concealment_head = p_Vid->concealment_head->next; - if( p_Vid->concealment_end == ptr ) + if (p_Vid->concealment_end == ptr) p_Vid->concealment_end = p_Vid->concealment_end->next; free(ptr); } @@ -1689,30 +1617,26 @@ static void delete_node( VideoParameters *p_Vid, struct concealment_node *ptr ) ************************************************************************ */ -void delete_list( VideoParameters *p_Vid, struct concealment_node *ptr ) -{ +void delete_list(VideoParameters *p_Vid, struct concealment_node *ptr) { struct concealment_node *temp; - if( p_Vid->concealment_head == NULL ) return; + if (p_Vid->concealment_head == NULL) + return; - if( ptr == p_Vid->concealment_head ) - { + if (ptr == p_Vid->concealment_head) { p_Vid->concealment_head = NULL; p_Vid->concealment_end = NULL; - } - else - { + } else { temp = p_Vid->concealment_head; - while( temp->next != ptr ) + while (temp->next != ptr) temp = temp->next; p_Vid->concealment_end = temp; } - while( ptr != NULL ) - { + while (ptr != NULL) { temp = ptr->next; - free( ptr ); + free(ptr); ptr = temp; } } @@ -1728,8 +1652,7 @@ void delete_list( VideoParameters *p_Vid, struct concealment_node *ptr ) ************************************************************************ */ -void conceal_non_ref_pics(DecodedPictureBuffer *p_Dpb, int diff) -{ +void conceal_non_ref_pics(DecodedPictureBuffer *p_Dpb, int diff) { VideoParameters *p_Vid = p_Dpb->p_Vid; int missingpoc = 0; unsigned int i, pos = 0; @@ -1738,25 +1661,24 @@ void conceal_non_ref_pics(DecodedPictureBuffer *p_Dpb, int diff) struct concealment_node *concealment_ptr = NULL; int temp_used_size = p_Dpb->used_size; - if(p_Dpb->used_size == 0 ) + if (p_Dpb->used_size == 0) return; qsort(p_Vid->pocs_in_dpb, p_Dpb->size, sizeof(int), comp); - for(i=0;isize-diff;i++) - { + for (i = 0; i < p_Dpb->size - diff; i++) { p_Dpb->used_size = p_Dpb->size; - if((p_Vid->pocs_in_dpb[i+1] - p_Vid->pocs_in_dpb[i]) > p_Vid->poc_gap) - { - conceal_to_picture = alloc_storable_picture (p_Vid, FRAME, p_Vid->width, p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); + if ((p_Vid->pocs_in_dpb[i + 1] - p_Vid->pocs_in_dpb[i]) > p_Vid->poc_gap) { + conceal_to_picture = + alloc_storable_picture(p_Vid, FRAME, p_Vid->width, p_Vid->height, + p_Vid->width_cr, p_Vid->height_cr); missingpoc = p_Vid->pocs_in_dpb[i] + p_Vid->poc_gap; // Diagnostics // printf("\n missingpoc = %d\n",missingpoc); - if(missingpoc > p_Vid->earlier_missing_poc) - { - p_Vid->earlier_missing_poc = missingpoc; + if (missingpoc > p_Vid->earlier_missing_poc) { + p_Vid->earlier_missing_poc = missingpoc; conceal_to_picture->top_poc = missingpoc; conceal_to_picture->bottom_poc = missingpoc; conceal_to_picture->frame_poc = missingpoc; @@ -1772,7 +1694,7 @@ void conceal_non_ref_pics(DecodedPictureBuffer *p_Dpb, int diff) update_ref_list_for_concealment(p_Dpb); p_Vid->conceal_slice_type = B_SLICE; copy_to_conceal(conceal_from_picture, conceal_to_picture, p_Vid); - concealment_ptr = init_node( conceal_to_picture, missingpoc ); + concealment_ptr = init_node(conceal_to_picture, missingpoc); add_node(p_Vid, concealment_ptr); // Diagnostics // print_node(concealment_ptr); @@ -1780,8 +1702,8 @@ void conceal_non_ref_pics(DecodedPictureBuffer *p_Dpb, int diff) } } - //restore the original value - //p_Dpb->used_size = p_Dpb->size; + // restore the original value + // p_Dpb->used_size = p_Dpb->size; p_Dpb->used_size = temp_used_size; } @@ -1794,19 +1716,17 @@ void conceal_non_ref_pics(DecodedPictureBuffer *p_Dpb, int diff) ************************************************************************ */ -void sliding_window_poc_management(DecodedPictureBuffer *p_Dpb, StorablePicture *p) -{ - if (p_Dpb->used_size == p_Dpb->size) - { +void sliding_window_poc_management(DecodedPictureBuffer *p_Dpb, + StorablePicture *p) { + if (p_Dpb->used_size == p_Dpb->size) { VideoParameters *p_Vid = p_Dpb->p_Vid; unsigned int i; - for(i=0;isize-1; i++) - p_Vid->pocs_in_dpb[i] = p_Vid->pocs_in_dpb[i+1]; + for (i = 0; i < p_Dpb->size - 1; i++) + p_Vid->pocs_in_dpb[i] = p_Vid->pocs_in_dpb[i + 1]; } } - /*! ************************************************************************ * \brief @@ -1818,14 +1738,11 @@ void sliding_window_poc_management(DecodedPictureBuffer *p_Dpb, StorablePicture ************************************************************************ */ -void write_lost_non_ref_pic(DecodedPictureBuffer *p_Dpb, int poc, int p_out) -{ +void write_lost_non_ref_pic(DecodedPictureBuffer *p_Dpb, int poc, int p_out) { VideoParameters *p_Vid = p_Dpb->p_Vid; FrameStore concealment_fs; - if(poc > 0) - { - if((poc - p_Dpb->last_output_poc) > p_Vid->poc_gap) - { + if (poc > 0) { + if ((poc - p_Dpb->last_output_poc) > p_Vid->poc_gap) { concealment_fs.frame = p_Vid->concealment_head->picture; concealment_fs.is_output = 0; @@ -1847,21 +1764,19 @@ void write_lost_non_ref_pic(DecodedPictureBuffer *p_Dpb, int poc, int p_out) ************************************************************************ */ -void write_lost_ref_after_idr(DecodedPictureBuffer *p_Dpb, int pos) -{ +void write_lost_ref_after_idr(DecodedPictureBuffer *p_Dpb, int pos) { VideoParameters *p_Vid = p_Dpb->p_Vid; int temp = 1; - if(p_Vid->last_out_fs->frame == NULL) - { - p_Vid->last_out_fs->frame = alloc_storable_picture (p_Vid, FRAME, p_Vid->width, p_Vid->height, - p_Vid->width_cr, p_Vid->height_cr); + if (p_Vid->last_out_fs->frame == NULL) { + p_Vid->last_out_fs->frame = + alloc_storable_picture(p_Vid, FRAME, p_Vid->width, p_Vid->height, + p_Vid->width_cr, p_Vid->height_cr); p_Vid->last_out_fs->is_used = 3; } - if(p_Vid->conceal_mode == 2) - { + if (p_Vid->conceal_mode == 2) { temp = 2; p_Vid->conceal_mode = 1; } @@ -1869,4 +1784,3 @@ void write_lost_ref_after_idr(DecodedPictureBuffer *p_Dpb, int pos) p_Vid->conceal_mode = temp; } - diff --git a/src/common/ldecod_src/errorconcealment.c b/src/common/ldecod_src/errorconcealment.c index 9b906a1..a043604 100644 --- a/src/common/ldecod_src/errorconcealment.c +++ b/src/common/ldecod_src/errorconcealment.c @@ -16,24 +16,22 @@ * This simple error concealment implemented in this decoder uses * the existing dependencies of syntax elements. * In case that an element is detected as false this elements and all - * dependend elements are marked as elements to conceal in the p_Vid->ec_flag[] - * array. If the decoder requests a new element by the function - * readSyntaxElement_xxxx() this array is checked first if an error concealment has - * to be applied on this element. - * In case that an error occured a concealed element is given to the - * decoding function in macroblock(). + * dependend elements are marked as elements to conceal in the + *p_Vid->ec_flag[] array. If the decoder requests a new element by the function + * readSyntaxElement_xxxx() this array is checked first if an error + *concealment has to be applied on this element. In case that an error occured a + *concealed element is given to the decoding function in macroblock(). * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Sebastian Purreiter *********************************************************************** */ #include "contributors.h" -#include "global.h" #include "elements.h" - - +#include "global.h" /*! *********************************************************************** @@ -49,75 +47,71 @@ * EX_SYNC sync on next header *********************************************************************** */ -int set_ec_flag(VideoParameters *p_Vid, int se) -{ +int set_ec_flag(VideoParameters *p_Vid, int se) { /* if (p_Vid->ec_flag[se] == NO_EC) printf("Error concealment on element %s\n",SEtypes[se]); */ - switch (se) - { - case SE_HEADER : + switch (se) { + case SE_HEADER: p_Vid->ec_flag[SE_HEADER] = EC_REQ; - case SE_PTYPE : + case SE_PTYPE: p_Vid->ec_flag[SE_PTYPE] = EC_REQ; - case SE_MBTYPE : + case SE_MBTYPE: p_Vid->ec_flag[SE_MBTYPE] = EC_REQ; - case SE_REFFRAME : + case SE_REFFRAME: p_Vid->ec_flag[SE_REFFRAME] = EC_REQ; p_Vid->ec_flag[SE_MVD] = EC_REQ; // set all motion vectors to zero length - se = SE_CBP_INTER; // conceal also Inter texture elements + se = SE_CBP_INTER; // conceal also Inter texture elements break; - case SE_INTRAPREDMODE : + case SE_INTRAPREDMODE: p_Vid->ec_flag[SE_INTRAPREDMODE] = EC_REQ; - se = SE_CBP_INTRA; // conceal also Intra texture elements + se = SE_CBP_INTRA; // conceal also Intra texture elements break; - case SE_MVD : + case SE_MVD: p_Vid->ec_flag[SE_MVD] = EC_REQ; - se = SE_CBP_INTER; // conceal also Inter texture elements + se = SE_CBP_INTER; // conceal also Inter texture elements break; default: break; } - switch (se) - { - case SE_CBP_INTRA : + switch (se) { + case SE_CBP_INTRA: p_Vid->ec_flag[SE_CBP_INTRA] = EC_REQ; - case SE_LUM_DC_INTRA : + case SE_LUM_DC_INTRA: p_Vid->ec_flag[SE_LUM_DC_INTRA] = EC_REQ; - case SE_CHR_DC_INTRA : + case SE_CHR_DC_INTRA: p_Vid->ec_flag[SE_CHR_DC_INTRA] = EC_REQ; - case SE_LUM_AC_INTRA : + case SE_LUM_AC_INTRA: p_Vid->ec_flag[SE_LUM_AC_INTRA] = EC_REQ; - case SE_CHR_AC_INTRA : + case SE_CHR_AC_INTRA: p_Vid->ec_flag[SE_CHR_AC_INTRA] = EC_REQ; break; - case SE_CBP_INTER : + case SE_CBP_INTER: p_Vid->ec_flag[SE_CBP_INTER] = EC_REQ; - case SE_LUM_DC_INTER : + case SE_LUM_DC_INTER: p_Vid->ec_flag[SE_LUM_DC_INTER] = EC_REQ; - case SE_CHR_DC_INTER : + case SE_CHR_DC_INTER: p_Vid->ec_flag[SE_CHR_DC_INTER] = EC_REQ; - case SE_LUM_AC_INTER : + case SE_LUM_AC_INTER: p_Vid->ec_flag[SE_LUM_AC_INTER] = EC_REQ; - case SE_CHR_AC_INTER : + case SE_CHR_AC_INTER: p_Vid->ec_flag[SE_CHR_AC_INTER] = EC_REQ; break; - case SE_DELTA_QUANT_INTER : + case SE_DELTA_QUANT_INTER: p_Vid->ec_flag[SE_DELTA_QUANT_INTER] = EC_REQ; break; - case SE_DELTA_QUANT_INTRA : + case SE_DELTA_QUANT_INTRA: p_Vid->ec_flag[SE_DELTA_QUANT_INTRA] = EC_REQ; break; default: break; - } return EC_REQ; } @@ -129,14 +123,12 @@ int set_ec_flag(VideoParameters *p_Vid, int se) * *********************************************************************** */ -void reset_ec_flags(VideoParameters *p_Vid) -{ +void reset_ec_flags(VideoParameters *p_Vid) { int i; - for (i=0; iec_flag[i] = NO_EC; } - /*! *********************************************************************** * \brief @@ -148,59 +140,57 @@ void reset_ec_flags(VideoParameters *p_Vid) * EC_REQ if element requires error concealment *********************************************************************** */ -int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym) -{ +int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym) { if (p_Vid->ec_flag[sym->type] == NO_EC) return NO_EC; -/* -#if TRACE - printf("TRACE: get concealed element for %s!!!\n", SEtypes[sym->type]); -#endif -*/ - switch (sym->type) - { - case SE_HEADER : + /* + #if TRACE + printf("TRACE: get concealed element for %s!!!\n", SEtypes[sym->type]); + #endif + */ + switch (sym->type) { + case SE_HEADER: sym->len = 31; sym->inf = 0; // Picture Header break; - case SE_PTYPE : // inter_img_1 - case SE_MBTYPE : // set COPY_MB - case SE_REFFRAME : + case SE_PTYPE: // inter_img_1 + case SE_MBTYPE: // set COPY_MB + case SE_REFFRAME: sym->len = 1; sym->inf = 0; break; - case SE_INTRAPREDMODE : - case SE_MVD : + case SE_INTRAPREDMODE: + case SE_MVD: sym->len = 1; - sym->inf = 0; // set vector to zero length + sym->inf = 0; // set vector to zero length break; - case SE_CBP_INTRA : + case SE_CBP_INTRA: sym->len = 5; sym->inf = 0; // codenumber 3 <=> no CBP information for INTRA images break; - case SE_LUM_DC_INTRA : - case SE_CHR_DC_INTRA : - case SE_LUM_AC_INTRA : - case SE_CHR_AC_INTRA : + case SE_LUM_DC_INTRA: + case SE_CHR_DC_INTRA: + case SE_LUM_AC_INTRA: + case SE_CHR_AC_INTRA: sym->len = 1; - sym->inf = 0; // return EOB + sym->inf = 0; // return EOB break; - case SE_CBP_INTER : + case SE_CBP_INTER: sym->len = 1; sym->inf = 0; // codenumber 1 <=> no CBP information for INTER images break; - case SE_LUM_DC_INTER : - case SE_CHR_DC_INTER : - case SE_LUM_AC_INTER : - case SE_CHR_AC_INTER : + case SE_LUM_DC_INTER: + case SE_CHR_DC_INTER: + case SE_LUM_AC_INTER: + case SE_CHR_AC_INTER: sym->len = 1; - sym->inf = 0; // return EOB + sym->inf = 0; // return EOB break; case SE_DELTA_QUANT_INTER: @@ -217,4 +207,3 @@ int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym) return EC_REQ; } - diff --git a/src/common/ldecod_src/filehandle.c b/src/common/ldecod_src/filehandle.c index b7c7d7c..f092e91 100644 --- a/src/common/ldecod_src/filehandle.c +++ b/src/common/ldecod_src/filehandle.c @@ -6,7 +6,8 @@ * \brief * Trace file handling and standard error handling function. * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Karsten Suehring *************************************************************************************** */ @@ -15,7 +16,6 @@ #include "global.h" #include "mbuffer.h" - #if TRACE /*! @@ -24,10 +24,7 @@ * decrement trace p_Dec->bitcounter (used for special case in mb aff) ************************************************************************ */ -void dectracebitcnt(int count) -{ - p_Dec->bitcounter -= count; -} +void dectracebitcnt(int count) { p_Dec->bitcounter -= count; } /*! ************************************************************************ @@ -37,57 +34,54 @@ void dectracebitcnt(int count) ************************************************************************ */ void tracebits( - const signed char *trace_str, //!< tracing information, signed char array describing the symbol - int len, //!< length of syntax element in bits - int info, //!< infoword of syntax element - int value1) -{ + const signed char *trace_str, //!< tracing information, signed char array + //!< describing the symbol + int len, //!< length of syntax element in bits + int info, //!< infoword of syntax element + int value1) { int i, chars; // int outint = 1; - if(len>=64) - { - snprintf(errortext, ET_SIZE, "Length argument to put too long for trace to work"); - error (errortext, 600); + if (len >= 64) { + snprintf(errortext, ET_SIZE, + "Length argument to put too long for trace to work"); + error(errortext, 600); } putc('@', p_Dec->p_trace); chars = fprintf(p_Dec->p_trace, "%i", p_Dec->bitcounter); - while(chars++ < 5) - putc(' ',p_Dec->p_trace); + while (chars++ < 5) + putc(' ', p_Dec->p_trace); chars += fprintf(p_Dec->p_trace, " %s", trace_str); - while(chars++ < 55) - putc(' ',p_Dec->p_trace); + while (chars++ < 55) + putc(' ', p_Dec->p_trace); // Align bitpattern - if(len<15) - { - for(i=0 ; i<15-len ; i++) + if (len < 15) { + for (i = 0; i < 15 - len; i++) fputc(' ', p_Dec->p_trace); } // Print bitpattern - for(i=0 ; ip_trace); } // put 1 fprintf(p_Dec->p_trace, "1"); // Print bitpattern - for(i=0 ; i> ((len/2-i)-1))) - fputc('1', p_Dec->p_trace); - else - fputc('0', p_Dec->p_trace); + for (i = 0; i < len / 2; i++) { + if (0x01 & (info >> ((len / 2 - i) - 1))) + fputc('1', p_Dec->p_trace); + else + fputc('0', p_Dec->p_trace); } fprintf(p_Dec->p_trace, " (%3d) \n", value1); p_Dec->bitcounter += len; - fflush (p_Dec->p_trace); + fflush(p_Dec->p_trace); } /*! @@ -97,52 +91,48 @@ void tracebits( ************************************************************************ */ void tracebits2( - const signed char *trace_str, //!< tracing information, signed char array describing the symbol - int len, //!< length of syntax element in bits - int info) -{ + const signed char *trace_str, //!< tracing information, signed char array + //!< describing the symbol + int len, //!< length of syntax element in bits + int info) { int i, chars; // int outint = 1; - if(len>=64) - { - snprintf(errortext, ET_SIZE, "Length argument to put too long for trace to work"); - error (errortext, 600); + if (len >= 64) { + snprintf(errortext, ET_SIZE, + "Length argument to put too long for trace to work"); + error(errortext, 600); } putc('@', p_Dec->p_trace); chars = fprintf(p_Dec->p_trace, "%i", p_Dec->bitcounter); - while(chars++ < 5) - putc(' ',p_Dec->p_trace); + while (chars++ < 5) + putc(' ', p_Dec->p_trace); chars += fprintf(p_Dec->p_trace, " %s", trace_str); - while(chars++ < 55) - putc(' ',p_Dec->p_trace); + while (chars++ < 55) + putc(' ', p_Dec->p_trace); // Align bitpattern - if(len < 15) - { - for(i = 0; i < 15 - len; i++) + if (len < 15) { + for (i = 0; i < 15 - len; i++) fputc(' ', p_Dec->p_trace); } p_Dec->bitcounter += len; - while (len >= 32) - { - for(i = 0; i < 8; i++) - { + while (len >= 32) { + for (i = 0; i < 8; i++) { fputc('0', p_Dec->p_trace); } len -= 8; } // Print bitpattern - for(i=0 ; i> (len-i-1))) + for (i = 0; i < len; i++) { + if (0x01 & (info >> (len - i - 1))) fputc('1', p_Dec->p_trace); else fputc('0', p_Dec->p_trace); @@ -150,7 +140,6 @@ void tracebits2( fprintf(p_Dec->p_trace, " (%3d) \n", info); - fflush (p_Dec->p_trace); + fflush(p_Dec->p_trace); } #endif - diff --git a/src/common/ldecod_src/fmo.c b/src/common/ldecod_src/fmo.c index 40dbd6e..c2772f6 100644 --- a/src/common/ldecod_src/fmo.c +++ b/src/common/ldecod_src/fmo.c @@ -8,29 +8,39 @@ * Support for Flexible Macroblock Ordering (FMO) * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger stewe@cs.tu-berlin.de * - Karsten Suehring suehring@hhi.de ****************************************************************************** */ -#include "global.h" -#include "elements.h" -#include "defines.h" -#include "header.h" #include "fmo.h" +#include "defines.h" +#include "elements.h" #include "fast_memory.h" +#include "global.h" +#include "header.h" -//#define PRINT_FMO_MAPS - -static void FmoGenerateType0MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ); -static void FmoGenerateType1MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ); -static void FmoGenerateType2MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ); -static void FmoGenerateType3MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice ); -static void FmoGenerateType4MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice ); -static void FmoGenerateType5MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice ); -static void FmoGenerateType6MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ); +// #define PRINT_FMO_MAPS +static void FmoGenerateType0MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits); +static void FmoGenerateType1MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits); +static void FmoGenerateType2MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits); +static void FmoGenerateType3MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits, + Slice *currSlice); +static void FmoGenerateType4MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits, + Slice *currSlice); +static void FmoGenerateType5MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits, + Slice *currSlice); +static void FmoGenerateType6MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits); /*! ************************************************************************ @@ -43,69 +53,72 @@ static void FmoGenerateType6MapUnitMap (VideoParameters *p_Vid, unsigned PicSize * ************************************************************************ */ -static int FmoGenerateMapUnitToSliceGroupMap (VideoParameters *p_Vid, Slice *currSlice) -{ - seq_parameter_set_rbsp_t* sps = p_Vid->active_sps; - pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; +static int FmoGenerateMapUnitToSliceGroupMap(VideoParameters *p_Vid, + Slice *currSlice) { + seq_parameter_set_rbsp_t *sps = p_Vid->active_sps; + pic_parameter_set_rbsp_t *pps = p_Vid->active_pps; unsigned int NumSliceGroupMapUnits; - NumSliceGroupMapUnits = (sps->pic_height_in_map_units_minus1+1)* (sps->pic_width_in_mbs_minus1+1); + NumSliceGroupMapUnits = (sps->pic_height_in_map_units_minus1 + 1) * + (sps->pic_width_in_mbs_minus1 + 1); - if (pps->slice_group_map_type == 6) - { - if ((pps->pic_size_in_map_units_minus1 + 1) != NumSliceGroupMapUnits) - { - error ("wrong pps->pic_size_in_map_units_minus1 for used SPS and FMO type 6", 500); + if (pps->slice_group_map_type == 6) { + if ((pps->pic_size_in_map_units_minus1 + 1) != NumSliceGroupMapUnits) { + error( + "wrong pps->pic_size_in_map_units_minus1 for used SPS and FMO type 6", + 500); } } // allocate memory for p_Vid->MapUnitToSliceGroupMap if (p_Vid->MapUnitToSliceGroupMap) - free (p_Vid->MapUnitToSliceGroupMap); - if ((p_Vid->MapUnitToSliceGroupMap = malloc ((NumSliceGroupMapUnits) * sizeof (int))) == NULL) - { - printf ("cannot allocated %d bytes for p_Vid->MapUnitToSliceGroupMap, exit\n", (int) ( (pps->pic_size_in_map_units_minus1+1) * sizeof (int))); - exit (-1); + free(p_Vid->MapUnitToSliceGroupMap); + if ((p_Vid->MapUnitToSliceGroupMap = + malloc((NumSliceGroupMapUnits) * sizeof(int))) == NULL) { + printf( + "cannot allocated %d bytes for p_Vid->MapUnitToSliceGroupMap, exit\n", + (int)((pps->pic_size_in_map_units_minus1 + 1) * sizeof(int))); + exit(-1); } - if (pps->num_slice_groups_minus1 == 0) // only one slice group + if (pps->num_slice_groups_minus1 == 0) // only one slice group { - fast_memset (p_Vid->MapUnitToSliceGroupMap, 0, NumSliceGroupMapUnits * sizeof (int)); + fast_memset(p_Vid->MapUnitToSliceGroupMap, 0, + NumSliceGroupMapUnits * sizeof(int)); return 0; } - switch (pps->slice_group_map_type) - { + switch (pps->slice_group_map_type) { case 0: - FmoGenerateType0MapUnitMap (p_Vid, NumSliceGroupMapUnits); + FmoGenerateType0MapUnitMap(p_Vid, NumSliceGroupMapUnits); break; case 1: - FmoGenerateType1MapUnitMap (p_Vid, NumSliceGroupMapUnits); + FmoGenerateType1MapUnitMap(p_Vid, NumSliceGroupMapUnits); break; case 2: - FmoGenerateType2MapUnitMap (p_Vid, NumSliceGroupMapUnits); + FmoGenerateType2MapUnitMap(p_Vid, NumSliceGroupMapUnits); break; case 3: - FmoGenerateType3MapUnitMap (p_Vid, NumSliceGroupMapUnits, currSlice); + FmoGenerateType3MapUnitMap(p_Vid, NumSliceGroupMapUnits, currSlice); break; case 4: - FmoGenerateType4MapUnitMap (p_Vid, NumSliceGroupMapUnits, currSlice); + FmoGenerateType4MapUnitMap(p_Vid, NumSliceGroupMapUnits, currSlice); break; case 5: - FmoGenerateType5MapUnitMap (p_Vid, NumSliceGroupMapUnits, currSlice); + FmoGenerateType5MapUnitMap(p_Vid, NumSliceGroupMapUnits, currSlice); break; case 6: - FmoGenerateType6MapUnitMap (p_Vid, NumSliceGroupMapUnits); + FmoGenerateType6MapUnitMap(p_Vid, NumSliceGroupMapUnits); break; default: - printf ("Illegal slice_group_map_type %d , exit \n", (int) pps->slice_group_map_type); - exit (-1); + printf("Illegal slice_group_map_type %d , exit \n", + (int)pps->slice_group_map_type); + exit(-1); } return 0; } - /*! ************************************************************************ * \brief @@ -116,66 +129,58 @@ static int FmoGenerateMapUnitToSliceGroupMap (VideoParameters *p_Vid, Slice *cur * ************************************************************************ */ -static int FmoGenerateMbToSliceGroupMap (VideoParameters *p_Vid, Slice *pSlice) -{ - seq_parameter_set_rbsp_t* sps = p_Vid->active_sps; +static int FmoGenerateMbToSliceGroupMap(VideoParameters *p_Vid, Slice *pSlice) { + seq_parameter_set_rbsp_t *sps = p_Vid->active_sps; unsigned i; // allocate memory for p_Vid->MbToSliceGroupMap if (p_Vid->MbToSliceGroupMap) - free (p_Vid->MbToSliceGroupMap); + free(p_Vid->MbToSliceGroupMap); - if ((p_Vid->MbToSliceGroupMap = malloc ((p_Vid->PicSizeInMbs) * sizeof (int))) == NULL) - { - printf ("cannot allocate %d bytes for p_Vid->MbToSliceGroupMap, exit\n", (int) ((p_Vid->PicSizeInMbs) * sizeof (int))); - exit (-1); + if ((p_Vid->MbToSliceGroupMap = + malloc((p_Vid->PicSizeInMbs) * sizeof(int))) == NULL) { + printf("cannot allocate %d bytes for p_Vid->MbToSliceGroupMap, exit\n", + (int)((p_Vid->PicSizeInMbs) * sizeof(int))); + exit(-1); } - - if ((sps->frame_mbs_only_flag)|| pSlice->field_pic_flag) - { + if ((sps->frame_mbs_only_flag) || pSlice->field_pic_flag) { int *MbToSliceGroupMap = p_Vid->MbToSliceGroupMap; int *MapUnitToSliceGroupMap = p_Vid->MapUnitToSliceGroupMap; - for (i=0; iPicSizeInMbs; i++) - { + for (i = 0; i < p_Vid->PicSizeInMbs; i++) { *MbToSliceGroupMap++ = *MapUnitToSliceGroupMap++; } + } else if (sps->mb_adaptive_frame_field_flag && (!pSlice->field_pic_flag)) { + for (i = 0; i < p_Vid->PicSizeInMbs; i++) { + p_Vid->MbToSliceGroupMap[i] = p_Vid->MapUnitToSliceGroupMap[i / 2]; + } + } else { + for (i = 0; i < p_Vid->PicSizeInMbs; i++) { + p_Vid->MbToSliceGroupMap[i] = + p_Vid->MapUnitToSliceGroupMap[(i / (2 * p_Vid->PicWidthInMbs)) * + p_Vid->PicWidthInMbs + + (i % p_Vid->PicWidthInMbs)]; + } } - else - if (sps->mb_adaptive_frame_field_flag && (!pSlice->field_pic_flag)) - { - for (i=0; iPicSizeInMbs; i++) - { - p_Vid->MbToSliceGroupMap[i] = p_Vid->MapUnitToSliceGroupMap[i/2]; - } - } - else - { - for (i=0; iPicSizeInMbs; i++) - { - p_Vid->MbToSliceGroupMap[i] = p_Vid->MapUnitToSliceGroupMap[(i/(2*p_Vid->PicWidthInMbs))*p_Vid->PicWidthInMbs+(i%p_Vid->PicWidthInMbs)]; - } - } return 0; } - /*! ************************************************************************ * \brief - * FMO initialization: Generates p_Vid->MapUnitToSliceGroupMap and p_Vid->MbToSliceGroupMap. + * FMO initialization: Generates p_Vid->MapUnitToSliceGroupMap and + *p_Vid->MbToSliceGroupMap. * * \param p_Vid * video encoding parameters for current picture ************************************************************************ */ -int fmo_init(VideoParameters *p_Vid, Slice *pSlice) -{ - pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; +int fmo_init(VideoParameters *p_Vid, Slice *pSlice) { + pic_parameter_set_rbsp_t *pps = p_Vid->active_pps; #ifdef PRINT_FMO_MAPS - unsigned i,j; + unsigned i, j; #endif FmoGenerateMapUnitToSliceGroupMap(p_Vid, pSlice); @@ -187,22 +192,19 @@ int fmo_init(VideoParameters *p_Vid, Slice *pSlice) printf("\n"); printf("FMO Map (Units):\n"); - for (j=0; jPicHeightInMapUnits; j++) - { - for (i=0; iPicWidthInMbs; i++) - { - printf("%c",48+p_Vid->MapUnitToSliceGroupMap[i+j*p_Vid->PicWidthInMbs]); + for (j = 0; j < p_Vid->PicHeightInMapUnits; j++) { + for (i = 0; i < p_Vid->PicWidthInMbs; i++) { + printf("%c", + 48 + p_Vid->MapUnitToSliceGroupMap[i + j * p_Vid->PicWidthInMbs]); } printf("\n"); } printf("\n"); printf("FMO Map (Mb):\n"); - for (j=0; jPicHeightInMbs; j++) - { - for (i=0; iPicWidthInMbs; i++) - { - printf("%c",48 + p_Vid->MbToSliceGroupMap[i + j * p_Vid->PicWidthInMbs]); + for (j = 0; j < p_Vid->PicHeightInMbs; j++) { + for (i = 0; i < p_Vid->PicWidthInMbs; i++) { + printf("%c", 48 + p_Vid->MbToSliceGroupMap[i + j * p_Vid->PicWidthInMbs]); } printf("\n"); } @@ -213,29 +215,24 @@ int fmo_init(VideoParameters *p_Vid, Slice *pSlice) return 0; } - /*! ************************************************************************ * \brief * Free memory allocated by FMO functions ************************************************************************ */ -int FmoFinit(VideoParameters *p_Vid) -{ - if (p_Vid->MbToSliceGroupMap) - { - free (p_Vid->MbToSliceGroupMap); +int FmoFinit(VideoParameters *p_Vid) { + if (p_Vid->MbToSliceGroupMap) { + free(p_Vid->MbToSliceGroupMap); p_Vid->MbToSliceGroupMap = NULL; } - if (p_Vid->MapUnitToSliceGroupMap) - { - free (p_Vid->MapUnitToSliceGroupMap); + if (p_Vid->MapUnitToSliceGroupMap) { + free(p_Vid->MapUnitToSliceGroupMap); p_Vid->MapUnitToSliceGroupMap = NULL; } return 0; } - /*! ************************************************************************ * \brief @@ -245,12 +242,10 @@ int FmoFinit(VideoParameters *p_Vid) * VideoParameters ************************************************************************ */ -int FmoGetNumberOfSliceGroup(VideoParameters *p_Vid) -{ +int FmoGetNumberOfSliceGroup(VideoParameters *p_Vid) { return p_Vid->NumberOfSliceGroups; } - /*! ************************************************************************ * \brief @@ -263,12 +258,10 @@ int FmoGetNumberOfSliceGroup(VideoParameters *p_Vid) * None ************************************************************************ */ -int FmoGetLastMBOfPicture(VideoParameters *p_Vid) -{ - return FmoGetLastMBInSliceGroup (p_Vid, FmoGetNumberOfSliceGroup(p_Vid)-1); +int FmoGetLastMBOfPicture(VideoParameters *p_Vid) { + return FmoGetLastMBInSliceGroup(p_Vid, FmoGetNumberOfSliceGroup(p_Vid) - 1); } - /*! ************************************************************************ * \brief @@ -279,18 +272,15 @@ int FmoGetLastMBOfPicture(VideoParameters *p_Vid) ************************************************************************ */ -int FmoGetLastMBInSliceGroup (VideoParameters *p_Vid, int SliceGroup) -{ +int FmoGetLastMBInSliceGroup(VideoParameters *p_Vid, int SliceGroup) { int i; - for (i=p_Vid->PicSizeInMbs-1; i>=0; i--) - if (FmoGetSliceGroupId (p_Vid, i) == SliceGroup) + for (i = p_Vid->PicSizeInMbs - 1; i >= 0; i--) + if (FmoGetSliceGroupId(p_Vid, i) == SliceGroup) return i; return -1; - } - /*! ************************************************************************ * \brief @@ -302,14 +292,12 @@ int FmoGetLastMBInSliceGroup (VideoParameters *p_Vid, int SliceGroup) * Macroblock number (in scan order) ************************************************************************ */ -int FmoGetSliceGroupId (VideoParameters *p_Vid, int mb) -{ - assert (mb < (int) p_Vid->PicSizeInMbs); - assert (p_Vid->MbToSliceGroupMap != NULL); +int FmoGetSliceGroupId(VideoParameters *p_Vid, int mb) { + assert(mb < (int)p_Vid->PicSizeInMbs); + assert(p_Vid->MbToSliceGroupMap != NULL); return p_Vid->MbToSliceGroupMap[mb]; } - /*! ************************************************************************ * \brief @@ -322,20 +310,19 @@ int FmoGetSliceGroupId (VideoParameters *p_Vid, int mb) * number of the current macroblock ************************************************************************ */ -int FmoGetNextMBNr (VideoParameters *p_Vid, int CurrentMbNr) -{ - int SliceGroup = FmoGetSliceGroupId (p_Vid, CurrentMbNr); +int FmoGetNextMBNr(VideoParameters *p_Vid, int CurrentMbNr) { + int SliceGroup = FmoGetSliceGroupId(p_Vid, CurrentMbNr); - while (++CurrentMbNr<(int)p_Vid->PicSizeInMbs && p_Vid->MbToSliceGroupMap [CurrentMbNr] != SliceGroup) + while (++CurrentMbNr < (int)p_Vid->PicSizeInMbs && + p_Vid->MbToSliceGroupMap[CurrentMbNr] != SliceGroup) ; if (CurrentMbNr >= (int)p_Vid->PicSizeInMbs) - return -1; // No further MB in this slice (could be end of picture) + return -1; // No further MB in this slice (could be end of picture) else return CurrentMbNr; } - /*! ************************************************************************ * \brief @@ -343,25 +330,23 @@ int FmoGetNextMBNr (VideoParameters *p_Vid, int CurrentMbNr) * ************************************************************************ */ -static void FmoGenerateType0MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ) -{ - pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; +static void FmoGenerateType0MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits) { + pic_parameter_set_rbsp_t *pps = p_Vid->active_pps; unsigned iGroup, j; unsigned i = 0; - do - { - for( iGroup = 0; + do { + for (iGroup = 0; (iGroup <= pps->num_slice_groups_minus1) && (i < PicSizeInMapUnits); - i += pps->run_length_minus1[iGroup++] + 1 ) - { - for( j = 0; j <= pps->run_length_minus1[ iGroup ] && i + j < PicSizeInMapUnits; j++ ) - p_Vid->MapUnitToSliceGroupMap[i+j] = iGroup; + i += pps->run_length_minus1[iGroup++] + 1) { + for (j = 0; + j <= pps->run_length_minus1[iGroup] && i + j < PicSizeInMapUnits; + j++) + p_Vid->MapUnitToSliceGroupMap[i + j] = iGroup; } - } - while( i < PicSizeInMapUnits ); + } while (i < PicSizeInMapUnits); } - /*! ************************************************************************ * \brief @@ -369,47 +354,48 @@ static void FmoGenerateType0MapUnitMap (VideoParameters *p_Vid, unsigned PicSize * ************************************************************************ */ -static void FmoGenerateType1MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ) -{ - pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; +static void FmoGenerateType1MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits) { + pic_parameter_set_rbsp_t *pps = p_Vid->active_pps; unsigned i; - for( i = 0; i < PicSizeInMapUnits; i++ ) - { - p_Vid->MapUnitToSliceGroupMap[i] = ((i%p_Vid->PicWidthInMbs)+(((i/p_Vid->PicWidthInMbs)*(pps->num_slice_groups_minus1+1))/2)) - %(pps->num_slice_groups_minus1+1); + for (i = 0; i < PicSizeInMapUnits; i++) { + p_Vid->MapUnitToSliceGroupMap[i] = + ((i % p_Vid->PicWidthInMbs) + + (((i / p_Vid->PicWidthInMbs) * (pps->num_slice_groups_minus1 + 1)) / + 2)) % + (pps->num_slice_groups_minus1 + 1); } } /*! ************************************************************************ * \brief - * Generate foreground with left-over slice group map type MapUnit map (type 2) + * Generate foreground with left-over slice group map type MapUnit map (type + *2) * ************************************************************************ */ -static void FmoGenerateType2MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ) -{ - pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; +static void FmoGenerateType2MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits) { + pic_parameter_set_rbsp_t *pps = p_Vid->active_pps; int iGroup; unsigned i, x, y; unsigned yTopLeft, xTopLeft, yBottomRight, xBottomRight; - for( i = 0; i < PicSizeInMapUnits; i++ ) - p_Vid->MapUnitToSliceGroupMap[ i ] = pps->num_slice_groups_minus1; + for (i = 0; i < PicSizeInMapUnits; i++) + p_Vid->MapUnitToSliceGroupMap[i] = pps->num_slice_groups_minus1; - for( iGroup = pps->num_slice_groups_minus1 - 1 ; iGroup >= 0; iGroup-- ) - { - yTopLeft = pps->top_left[ iGroup ] / p_Vid->PicWidthInMbs; - xTopLeft = pps->top_left[ iGroup ] % p_Vid->PicWidthInMbs; - yBottomRight = pps->bottom_right[ iGroup ] / p_Vid->PicWidthInMbs; - xBottomRight = pps->bottom_right[ iGroup ] % p_Vid->PicWidthInMbs; - for( y = yTopLeft; y <= yBottomRight; y++ ) - for( x = xTopLeft; x <= xBottomRight; x++ ) - p_Vid->MapUnitToSliceGroupMap[ y * p_Vid->PicWidthInMbs + x ] = iGroup; - } + for (iGroup = pps->num_slice_groups_minus1 - 1; iGroup >= 0; iGroup--) { + yTopLeft = pps->top_left[iGroup] / p_Vid->PicWidthInMbs; + xTopLeft = pps->top_left[iGroup] % p_Vid->PicWidthInMbs; + yBottomRight = pps->bottom_right[iGroup] / p_Vid->PicWidthInMbs; + xBottomRight = pps->bottom_right[iGroup] % p_Vid->PicWidthInMbs; + for (y = yTopLeft; y <= yBottomRight; y++) + for (x = xTopLeft; x <= xBottomRight; x++) + p_Vid->MapUnitToSliceGroupMap[y * p_Vid->PicWidthInMbs + x] = iGroup; + } } - /*! ************************************************************************ * \brief @@ -417,74 +403,66 @@ static void FmoGenerateType2MapUnitMap (VideoParameters *p_Vid, unsigned PicSize * ************************************************************************ */ -static void FmoGenerateType3MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice ) -{ - pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; +static void FmoGenerateType3MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits, + Slice *currSlice) { + pic_parameter_set_rbsp_t *pps = p_Vid->active_pps; unsigned i, k; int leftBound, topBound, rightBound, bottomBound; int x, y, xDir, yDir; int mapUnitVacant; - unsigned mapUnitsInSliceGroup0 = imin((pps->slice_group_change_rate_minus1 + 1) * currSlice->slice_group_change_cycle, PicSizeInMapUnits); + unsigned mapUnitsInSliceGroup0 = + imin((pps->slice_group_change_rate_minus1 + 1) * + currSlice->slice_group_change_cycle, + PicSizeInMapUnits); - for( i = 0; i < PicSizeInMapUnits; i++ ) - p_Vid->MapUnitToSliceGroupMap[ i ] = 2; + for (i = 0; i < PicSizeInMapUnits; i++) + p_Vid->MapUnitToSliceGroupMap[i] = 2; - x = ( p_Vid->PicWidthInMbs - pps->slice_group_change_direction_flag ) / 2; - y = ( p_Vid->PicHeightInMapUnits - pps->slice_group_change_direction_flag ) / 2; + x = (p_Vid->PicWidthInMbs - pps->slice_group_change_direction_flag) / 2; + y = (p_Vid->PicHeightInMapUnits - pps->slice_group_change_direction_flag) / 2; - leftBound = x; - topBound = y; - rightBound = x; + leftBound = x; + topBound = y; + rightBound = x; bottomBound = y; - xDir = pps->slice_group_change_direction_flag - 1; - yDir = pps->slice_group_change_direction_flag; + xDir = pps->slice_group_change_direction_flag - 1; + yDir = pps->slice_group_change_direction_flag; - for( k = 0; k < PicSizeInMapUnits; k += mapUnitVacant ) - { - mapUnitVacant = ( p_Vid->MapUnitToSliceGroupMap[ y * p_Vid->PicWidthInMbs + x ] == 2 ); - if( mapUnitVacant ) - p_Vid->MapUnitToSliceGroupMap[ y * p_Vid->PicWidthInMbs + x ] = ( k >= mapUnitsInSliceGroup0 ); + for (k = 0; k < PicSizeInMapUnits; k += mapUnitVacant) { + mapUnitVacant = + (p_Vid->MapUnitToSliceGroupMap[y * p_Vid->PicWidthInMbs + x] == 2); + if (mapUnitVacant) + p_Vid->MapUnitToSliceGroupMap[y * p_Vid->PicWidthInMbs + x] = + (k >= mapUnitsInSliceGroup0); - if( xDir == -1 && x == leftBound ) - { - leftBound = imax( leftBound - 1, 0 ); + if (xDir == -1 && x == leftBound) { + leftBound = imax(leftBound - 1, 0); x = leftBound; xDir = 0; yDir = 2 * pps->slice_group_change_direction_flag - 1; + } else if (xDir == 1 && x == rightBound) { + rightBound = imin(rightBound + 1, (int)p_Vid->PicWidthInMbs - 1); + x = rightBound; + xDir = 0; + yDir = 1 - 2 * pps->slice_group_change_direction_flag; + } else if (yDir == -1 && y == topBound) { + topBound = imax(topBound - 1, 0); + y = topBound; + xDir = 1 - 2 * pps->slice_group_change_direction_flag; + yDir = 0; + } else if (yDir == 1 && y == bottomBound) { + bottomBound = imin(bottomBound + 1, (int)p_Vid->PicHeightInMapUnits - 1); + y = bottomBound; + xDir = 2 * pps->slice_group_change_direction_flag - 1; + yDir = 0; + } else { + x = x + xDir; + y = y + yDir; } - else - if( xDir == 1 && x == rightBound ) - { - rightBound = imin( rightBound + 1, (int)p_Vid->PicWidthInMbs - 1 ); - x = rightBound; - xDir = 0; - yDir = 1 - 2 * pps->slice_group_change_direction_flag; - } - else - if( yDir == -1 && y == topBound ) - { - topBound = imax( topBound - 1, 0 ); - y = topBound; - xDir = 1 - 2 * pps->slice_group_change_direction_flag; - yDir = 0; - } - else - if( yDir == 1 && y == bottomBound ) - { - bottomBound = imin( bottomBound + 1, (int)p_Vid->PicHeightInMapUnits - 1 ); - y = bottomBound; - xDir = 2 * pps->slice_group_change_direction_flag - 1; - yDir = 0; - } - else - { - x = x + xDir; - y = y + yDir; - } } - } /*! @@ -494,21 +472,28 @@ static void FmoGenerateType3MapUnitMap (VideoParameters *p_Vid, unsigned PicSize * ************************************************************************ */ -static void FmoGenerateType4MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice ) -{ - pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; +static void FmoGenerateType4MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits, + Slice *currSlice) { + pic_parameter_set_rbsp_t *pps = p_Vid->active_pps; - unsigned mapUnitsInSliceGroup0 = imin((pps->slice_group_change_rate_minus1 + 1) * currSlice->slice_group_change_cycle, PicSizeInMapUnits); - unsigned sizeOfUpperLeftGroup = pps->slice_group_change_direction_flag ? ( PicSizeInMapUnits - mapUnitsInSliceGroup0 ) : mapUnitsInSliceGroup0; + unsigned mapUnitsInSliceGroup0 = + imin((pps->slice_group_change_rate_minus1 + 1) * + currSlice->slice_group_change_cycle, + PicSizeInMapUnits); + unsigned sizeOfUpperLeftGroup = + pps->slice_group_change_direction_flag + ? (PicSizeInMapUnits - mapUnitsInSliceGroup0) + : mapUnitsInSliceGroup0; unsigned i; - for( i = 0; i < PicSizeInMapUnits; i++ ) - if( i < sizeOfUpperLeftGroup ) - p_Vid->MapUnitToSliceGroupMap[ i ] = pps->slice_group_change_direction_flag; + for (i = 0; i < PicSizeInMapUnits; i++) + if (i < sizeOfUpperLeftGroup) + p_Vid->MapUnitToSliceGroupMap[i] = pps->slice_group_change_direction_flag; else - p_Vid->MapUnitToSliceGroupMap[ i ] = 1 - pps->slice_group_change_direction_flag; - + p_Vid->MapUnitToSliceGroupMap[i] = + 1 - pps->slice_group_change_direction_flag; } /*! @@ -518,22 +503,30 @@ static void FmoGenerateType4MapUnitMap (VideoParameters *p_Vid, unsigned PicSize * ************************************************************************ */ -static void FmoGenerateType5MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits, Slice *currSlice ) -{ - pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; +static void FmoGenerateType5MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits, + Slice *currSlice) { + pic_parameter_set_rbsp_t *pps = p_Vid->active_pps; - unsigned mapUnitsInSliceGroup0 = imin((pps->slice_group_change_rate_minus1 + 1) * currSlice->slice_group_change_cycle, PicSizeInMapUnits); - unsigned sizeOfUpperLeftGroup = pps->slice_group_change_direction_flag ? ( PicSizeInMapUnits - mapUnitsInSliceGroup0 ) : mapUnitsInSliceGroup0; + unsigned mapUnitsInSliceGroup0 = + imin((pps->slice_group_change_rate_minus1 + 1) * + currSlice->slice_group_change_cycle, + PicSizeInMapUnits); + unsigned sizeOfUpperLeftGroup = + pps->slice_group_change_direction_flag + ? (PicSizeInMapUnits - mapUnitsInSliceGroup0) + : mapUnitsInSliceGroup0; - unsigned i,j, k = 0; - - for( j = 0; j < p_Vid->PicWidthInMbs; j++ ) - for( i = 0; i < p_Vid->PicHeightInMapUnits; i++ ) - if( k++ < sizeOfUpperLeftGroup ) - p_Vid->MapUnitToSliceGroupMap[ i * p_Vid->PicWidthInMbs + j ] = pps->slice_group_change_direction_flag; - else - p_Vid->MapUnitToSliceGroupMap[ i * p_Vid->PicWidthInMbs + j ] = 1 - pps->slice_group_change_direction_flag; + unsigned i, j, k = 0; + for (j = 0; j < p_Vid->PicWidthInMbs; j++) + for (i = 0; i < p_Vid->PicHeightInMapUnits; i++) + if (k++ < sizeOfUpperLeftGroup) + p_Vid->MapUnitToSliceGroupMap[i * p_Vid->PicWidthInMbs + j] = + pps->slice_group_change_direction_flag; + else + p_Vid->MapUnitToSliceGroupMap[i * p_Vid->PicWidthInMbs + j] = + 1 - pps->slice_group_change_direction_flag; } /*! @@ -543,13 +536,11 @@ static void FmoGenerateType5MapUnitMap (VideoParameters *p_Vid, unsigned PicSize * ************************************************************************ */ -static void FmoGenerateType6MapUnitMap (VideoParameters *p_Vid, unsigned PicSizeInMapUnits ) -{ - pic_parameter_set_rbsp_t* pps = p_Vid->active_pps; +static void FmoGenerateType6MapUnitMap(VideoParameters *p_Vid, + unsigned PicSizeInMapUnits) { + pic_parameter_set_rbsp_t *pps = p_Vid->active_pps; unsigned i; - for (i=0; iMapUnitToSliceGroupMap[i] = pps->slice_group_id[i]; } } - diff --git a/src/common/ldecod_src/header.c b/src/common/ldecod_src/header.c index 0eaed7a..904d4a3 100644 --- a/src/common/ldecod_src/header.c +++ b/src/common/ldecod_src/header.c @@ -9,19 +9,18 @@ ************************************************************************************* */ -#include "global.h" -#include "elements.h" -#include "defines.h" -#include "fmo.h" -#include "vlc.h" -#include "mbuffer.h" #include "header.h" +#include "defines.h" +#include "elements.h" +#include "fmo.h" +#include "global.h" +#include "mbuffer.h" +#include "vlc.h" #include "ctx_tables.h" - #if TRACE -#define SYMTRACESTRING(s) strncpy(sym.tracestring,s,TRACESTRING_SIZE) +#define SYMTRACESTRING(s) strncpy(sym.tracestring, s, TRACESTRING_SIZE) #else #define SYMTRACESTRING(s) // do nothing #endif @@ -32,33 +31,28 @@ static void pred_weight_table(Slice *currSlice); static void ref_pic_list_mvc_modification(Slice *currSlice); #endif - /*! ************************************************************************ * \brief * calculate Ceil(Log2(uiVal)) ************************************************************************ */ -unsigned CeilLog2( unsigned uiVal) -{ - unsigned uiTmp = uiVal-1; +unsigned CeilLog2(unsigned uiVal) { + unsigned uiTmp = uiVal - 1; unsigned uiRet = 0; - while( uiTmp != 0 ) - { + while (uiTmp != 0) { uiTmp >>= 1; uiRet++; } return uiRet; } -unsigned CeilLog2_sf( unsigned uiVal) -{ - unsigned uiTmp = uiVal-1; +unsigned CeilLog2_sf(unsigned uiVal) { + unsigned uiTmp = uiVal - 1; unsigned uiRet = 0; - while( uiTmp > 0 ) - { + while (uiTmp > 0) { uiTmp >>= 1; uiRet++; } @@ -73,29 +67,32 @@ unsigned CeilLog2_sf( unsigned uiVal) * Length of the first part of the slice header (in bits) ************************************************************************ */ -int FirstPartOfSliceHeader(Slice *currSlice) -{ +int FirstPartOfSliceHeader(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; byte dP_nr = assignSE2partition[currSlice->dp_mode][SE_HEADER]; DataPartition *partition = &(currSlice->partArr[dP_nr]); Bitstream *currStream = partition->bitstream; int tmp; - p_Dec->UsedBits= partition->bitstream->frame_bitoffset; // was hardcoded to 31 for previous start-code. This is better. + p_Dec->UsedBits = + partition->bitstream->frame_bitoffset; // was hardcoded to 31 for previous + // start-code. This is better. // Get first_mb_in_slice - currSlice->start_mb_nr = ue_v ("SH: first_mb_in_slice", currStream); + currSlice->start_mb_nr = ue_v("SH: first_mb_in_slice", currStream); - tmp = ue_v ("SH: slice_type", currStream); + tmp = ue_v("SH: slice_type", currStream); - if (tmp > 4) tmp -= 5; + if (tmp > 4) + tmp -= 5; - p_Vid->type = currSlice->slice_type = (SliceType) tmp; + p_Vid->type = currSlice->slice_type = (SliceType)tmp; - currSlice->pic_parameter_set_id = ue_v ("SH: pic_parameter_set_id", currStream); + currSlice->pic_parameter_set_id = + ue_v("SH: pic_parameter_set_id", currStream); - if( p_Vid->separate_colour_plane_flag ) - currSlice->colour_plane_id = u_v (2, "SH: colour_plane_id", currStream); + if (p_Vid->separate_colour_plane_flag) + currSlice->colour_plane_id = u_v(2, "SH: colour_plane_id", currStream); else currSlice->colour_plane_id = PLANE_Y; @@ -110,8 +107,7 @@ int FirstPartOfSliceHeader(Slice *currSlice) * Length of the second part of the Slice header in bits ************************************************************************ */ -int RestOfSliceHeader(Slice *currSlice) -{ +int RestOfSliceHeader(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; InputParameters *p_Inp = currSlice->p_Inp; seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; @@ -122,10 +118,11 @@ int RestOfSliceHeader(Slice *currSlice) int val, len; - currSlice->frame_num = u_v (active_sps->log2_max_frame_num_minus4 + 4, "SH: frame_num", currStream); + currSlice->frame_num = u_v(active_sps->log2_max_frame_num_minus4 + 4, + "SH: frame_num", currStream); /* Tian Dong: frame_num gap processing, if found */ - if(currSlice->idr_flag) //if (p_Vid->idr_flag) + if (currSlice->idr_flag) // if (p_Vid->idr_flag) { p_Vid->pre_frame_num = currSlice->frame_num; // picture error concealment @@ -133,100 +130,101 @@ int RestOfSliceHeader(Slice *currSlice) assert(currSlice->frame_num == 0); } - if (active_sps->frame_mbs_only_flag) - { + if (active_sps->frame_mbs_only_flag) { p_Vid->structure = FRAME; - currSlice->field_pic_flag=0; - } - else - { + currSlice->field_pic_flag = 0; + } else { // field_pic_flag u(1) currSlice->field_pic_flag = u_1("SH: field_pic_flag", currStream); - if (currSlice->field_pic_flag) - { + if (currSlice->field_pic_flag) { // bottom_field_flag u(1) - currSlice->bottom_field_flag = (byte) u_1("SH: bottom_field_flag", currStream); - p_Vid->structure = currSlice->bottom_field_flag ? BOTTOM_FIELD : TOP_FIELD; - } - else - { + currSlice->bottom_field_flag = + (byte)u_1("SH: bottom_field_flag", currStream); + p_Vid->structure = + currSlice->bottom_field_flag ? BOTTOM_FIELD : TOP_FIELD; + } else { p_Vid->structure = FRAME; currSlice->bottom_field_flag = FALSE; } } - currSlice->structure = (PictureStructure) p_Vid->structure; + currSlice->structure = (PictureStructure)p_Vid->structure; - currSlice->mb_aff_frame_flag = (active_sps->mb_adaptive_frame_field_flag && (currSlice->field_pic_flag==0)); - //currSlice->mb_aff_frame_flag = p_Vid->mb_aff_frame_flag; + currSlice->mb_aff_frame_flag = (active_sps->mb_adaptive_frame_field_flag && + (currSlice->field_pic_flag == 0)); + // currSlice->mb_aff_frame_flag = p_Vid->mb_aff_frame_flag; - if (p_Vid->structure == FRAME ) - assert (currSlice->field_pic_flag == 0); - if (p_Vid->structure == TOP_FIELD ) - assert (currSlice->field_pic_flag == 1 && (currSlice->bottom_field_flag == FALSE)); - if (p_Vid->structure == BOTTOM_FIELD) - assert (currSlice->field_pic_flag == 1 && (currSlice->bottom_field_flag == TRUE )); + if (p_Vid->structure == FRAME) + assert(currSlice->field_pic_flag == 0); + if (p_Vid->structure == TOP_FIELD) + assert(currSlice->field_pic_flag == 1 && + (currSlice->bottom_field_flag == FALSE)); + if (p_Vid->structure == BOTTOM_FIELD) + assert(currSlice->field_pic_flag == 1 && + (currSlice->bottom_field_flag == TRUE)); - if (currSlice->idr_flag) - { + if (currSlice->idr_flag) { currSlice->idr_pic_id = ue_v("SH: idr_pic_id", currStream); } - if (active_sps->pic_order_cnt_type == 0) - { - currSlice->pic_order_cnt_lsb = u_v(active_sps->log2_max_pic_order_cnt_lsb_minus4 + 4, "SH: pic_order_cnt_lsb", currStream); - if( p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag == 1 && !currSlice->field_pic_flag ) - currSlice->delta_pic_order_cnt_bottom = se_v("SH: delta_pic_order_cnt_bottom", currStream); + if (active_sps->pic_order_cnt_type == 0) { + currSlice->pic_order_cnt_lsb = + u_v(active_sps->log2_max_pic_order_cnt_lsb_minus4 + 4, + "SH: pic_order_cnt_lsb", currStream); + if (p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag == 1 && + !currSlice->field_pic_flag) + currSlice->delta_pic_order_cnt_bottom = + se_v("SH: delta_pic_order_cnt_bottom", currStream); else currSlice->delta_pic_order_cnt_bottom = 0; } - - if( active_sps->pic_order_cnt_type == 1) - { - if ( !active_sps->delta_pic_order_always_zero_flag ) - { - currSlice->delta_pic_order_cnt[ 0 ] = se_v("SH: delta_pic_order_cnt[0]", currStream); - if( p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag == 1 && !currSlice->field_pic_flag ) - currSlice->delta_pic_order_cnt[ 1 ] = se_v("SH: delta_pic_order_cnt[1]", currStream); + + if (active_sps->pic_order_cnt_type == 1) { + if (!active_sps->delta_pic_order_always_zero_flag) { + currSlice->delta_pic_order_cnt[0] = + se_v("SH: delta_pic_order_cnt[0]", currStream); + if (p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag == + 1 && + !currSlice->field_pic_flag) + currSlice->delta_pic_order_cnt[1] = + se_v("SH: delta_pic_order_cnt[1]", currStream); else - currSlice->delta_pic_order_cnt[ 1 ] = 0; // set to zero if not in stream - } - else - { - currSlice->delta_pic_order_cnt[ 0 ] = 0; - currSlice->delta_pic_order_cnt[ 1 ] = 0; + currSlice->delta_pic_order_cnt[1] = 0; // set to zero if not in stream + } else { + currSlice->delta_pic_order_cnt[0] = 0; + currSlice->delta_pic_order_cnt[1] = 0; } } //! redundant_pic_cnt is missing here - if (p_Vid->active_pps->redundant_pic_cnt_present_flag) - { - currSlice->redundant_pic_cnt = ue_v ("SH: redundant_pic_cnt", currStream); + if (p_Vid->active_pps->redundant_pic_cnt_present_flag) { + currSlice->redundant_pic_cnt = ue_v("SH: redundant_pic_cnt", currStream); } - if(currSlice->slice_type == B_SLICE) - { - currSlice->direct_spatial_mv_pred_flag = u_1 ("SH: direct_spatial_mv_pred_flag", currStream); + if (currSlice->slice_type == B_SLICE) { + currSlice->direct_spatial_mv_pred_flag = + u_1("SH: direct_spatial_mv_pred_flag", currStream); } - currSlice->num_ref_idx_active[LIST_0] = p_Vid->active_pps->num_ref_idx_l0_active_minus1 + 1; - currSlice->num_ref_idx_active[LIST_1] = p_Vid->active_pps->num_ref_idx_l1_active_minus1 + 1; + currSlice->num_ref_idx_active[LIST_0] = + p_Vid->active_pps->num_ref_idx_l0_active_minus1 + 1; + currSlice->num_ref_idx_active[LIST_1] = + p_Vid->active_pps->num_ref_idx_l1_active_minus1 + 1; - if(p_Vid->type==P_SLICE || p_Vid->type == SP_SLICE || p_Vid->type==B_SLICE) - { - val = u_1 ("SH: num_ref_idx_override_flag", currStream); - if (val) - { - currSlice->num_ref_idx_active[LIST_0] = 1 + ue_v ("SH: num_ref_idx_l0_active_minus1", currStream); + if (p_Vid->type == P_SLICE || p_Vid->type == SP_SLICE || + p_Vid->type == B_SLICE) { + val = u_1("SH: num_ref_idx_override_flag", currStream); + if (val) { + currSlice->num_ref_idx_active[LIST_0] = + 1 + ue_v("SH: num_ref_idx_l0_active_minus1", currStream); - if(p_Vid->type==B_SLICE) - { - currSlice->num_ref_idx_active[LIST_1] = 1 + ue_v ("SH: num_ref_idx_l1_active_minus1", currStream); + if (p_Vid->type == B_SLICE) { + currSlice->num_ref_idx_active[LIST_1] = + 1 + ue_v("SH: num_ref_idx_l1_active_minus1", currStream); } } } - if (currSlice->slice_type!=B_SLICE) - { + if (currSlice->slice_type != B_SLICE) { currSlice->num_ref_idx_active[LIST_1] = 0; } @@ -239,118 +237,122 @@ int RestOfSliceHeader(Slice *currSlice) ref_pic_list_reordering(currSlice); #endif - currSlice->weighted_pred_flag = (unsigned short) ((currSlice->slice_type == P_SLICE || currSlice->slice_type == SP_SLICE) - ? p_Vid->active_pps->weighted_pred_flag - : (currSlice->slice_type == B_SLICE && p_Vid->active_pps->weighted_bipred_idc == 1)); - currSlice->weighted_bipred_idc = (unsigned short) (currSlice->slice_type == B_SLICE && p_Vid->active_pps->weighted_bipred_idc > 0); + currSlice->weighted_pred_flag = + (unsigned short)((currSlice->slice_type == P_SLICE || + currSlice->slice_type == SP_SLICE) + ? p_Vid->active_pps->weighted_pred_flag + : (currSlice->slice_type == B_SLICE && + p_Vid->active_pps->weighted_bipred_idc == 1)); + currSlice->weighted_bipred_idc = + (unsigned short)(currSlice->slice_type == B_SLICE && + p_Vid->active_pps->weighted_bipred_idc > 0); - if ((p_Vid->active_pps->weighted_pred_flag&&(p_Vid->type==P_SLICE|| p_Vid->type == SP_SLICE))|| - (p_Vid->active_pps->weighted_bipred_idc==1 && (p_Vid->type==B_SLICE))) - { + if ((p_Vid->active_pps->weighted_pred_flag && + (p_Vid->type == P_SLICE || p_Vid->type == SP_SLICE)) || + (p_Vid->active_pps->weighted_bipred_idc == 1 && + (p_Vid->type == B_SLICE))) { pred_weight_table(currSlice); } if (currSlice->nal_reference_idc) dec_ref_pic_marking(p_Vid, currStream, currSlice); - if (p_Vid->active_pps->entropy_coding_mode_flag && p_Vid->type!=I_SLICE && p_Vid->type!=SI_SLICE) - { + if (p_Vid->active_pps->entropy_coding_mode_flag && p_Vid->type != I_SLICE && + p_Vid->type != SI_SLICE) { currSlice->model_number = ue_v("SH: cabac_init_idc", currStream); - } - else - { + } else { currSlice->model_number = 0; } currSlice->slice_qp_delta = val = se_v("SH: slice_qp_delta", currStream); - //currSlice->qp = p_Vid->qp = 26 + p_Vid->active_pps->pic_init_qp_minus26 + val; + // currSlice->qp = p_Vid->qp = 26 + p_Vid->active_pps->pic_init_qp_minus26 + + // val; currSlice->qp = 26 + p_Vid->active_pps->pic_init_qp_minus26 + val; if ((currSlice->qp < -p_Vid->bitdepth_luma_qp_scale) || (currSlice->qp > 51)) - error ("slice_qp_delta makes slice_qp_y out of range", 500); + error("slice_qp_delta makes slice_qp_y out of range", 500); - if(p_Vid->type==SP_SLICE || p_Vid->type == SI_SLICE) - { - if(p_Vid->type==SP_SLICE) - { - currSlice->sp_switch = u_1 ("SH: sp_for_switch_flag", currStream); + if (p_Vid->type == SP_SLICE || p_Vid->type == SI_SLICE) { + if (p_Vid->type == SP_SLICE) { + currSlice->sp_switch = u_1("SH: sp_for_switch_flag", currStream); } currSlice->slice_qs_delta = val = se_v("SH: slice_qs_delta", currStream); - currSlice->qs = 26 + p_Vid->active_pps->pic_init_qs_minus26 + val; + currSlice->qs = 26 + p_Vid->active_pps->pic_init_qs_minus26 + val; if ((currSlice->qs < 0) || (currSlice->qs > 51)) - error ("slice_qs_delta makes slice_qs_y out of range", 500); + error("slice_qs_delta makes slice_qs_y out of range", 500); } - if ( !HI_INTRA_ONLY_PROFILE || (HI_INTRA_ONLY_PROFILE && (p_Inp->intra_profile_deblocking == 1) )) - //then read flags and parameters from bistream + if (!HI_INTRA_ONLY_PROFILE || + (HI_INTRA_ONLY_PROFILE && (p_Inp->intra_profile_deblocking == 1))) + // then read flags and parameters from bistream { - if (p_Vid->active_pps->deblocking_filter_control_present_flag) - { - currSlice->DFDisableIdc = (short) ue_v ("SH: disable_deblocking_filter_idc", currStream); + if (p_Vid->active_pps->deblocking_filter_control_present_flag) { + currSlice->DFDisableIdc = + (short)ue_v("SH: disable_deblocking_filter_idc", currStream); - if (currSlice->DFDisableIdc!=1) - { - currSlice->DFAlphaC0Offset = (short) (2 * se_v("SH: slice_alpha_c0_offset_div2", currStream)); - currSlice->DFBetaOffset = (short) (2 * se_v("SH: slice_beta_offset_div2", currStream)); - } - else - { + if (currSlice->DFDisableIdc != 1) { + currSlice->DFAlphaC0Offset = + (short)(2 * se_v("SH: slice_alpha_c0_offset_div2", currStream)); + currSlice->DFBetaOffset = + (short)(2 * se_v("SH: slice_beta_offset_div2", currStream)); + } else { currSlice->DFAlphaC0Offset = currSlice->DFBetaOffset = 0; } + } else { + currSlice->DFDisableIdc = currSlice->DFAlphaC0Offset = + currSlice->DFBetaOffset = 0; } - else - { - currSlice->DFDisableIdc = currSlice->DFAlphaC0Offset = currSlice->DFBetaOffset = 0; - } - } - else //By default the Loop Filter is Off - { //444_TEMP_NOTE: change made below. 08/07/07 - //still need to parse the SEs (read flags and parameters from bistream) but will ignore - if (p_Vid->active_pps->deblocking_filter_control_present_flag) - { - currSlice->DFDisableIdc = (short) ue_v ("SH: disable_deblocking_filter_idc", currStream); + } else // By default the Loop Filter is Off + { // 444_TEMP_NOTE: change made below. 08/07/07 + // still need to parse the SEs (read flags and parameters from bistream) but + // will ignore + if (p_Vid->active_pps->deblocking_filter_control_present_flag) { + currSlice->DFDisableIdc = + (short)ue_v("SH: disable_deblocking_filter_idc", currStream); - if (currSlice->DFDisableIdc!=1) - { - currSlice->DFAlphaC0Offset = (short) (2 * se_v("SH: slice_alpha_c0_offset_div2", currStream)); - currSlice->DFBetaOffset = (short) (2 * se_v("SH: slice_beta_offset_div2", currStream)); + if (currSlice->DFDisableIdc != 1) { + currSlice->DFAlphaC0Offset = + (short)(2 * se_v("SH: slice_alpha_c0_offset_div2", currStream)); + currSlice->DFBetaOffset = + (short)(2 * se_v("SH: slice_beta_offset_div2", currStream)); } - }//444_TEMP_NOTE. the end of change. 08/07/07 - //Ignore the SEs, by default the Loop Filter is Off - currSlice->DFDisableIdc =1; + } // 444_TEMP_NOTE. the end of change. 08/07/07 + // Ignore the SEs, by default the Loop Filter is Off + currSlice->DFDisableIdc = 1; currSlice->DFAlphaC0Offset = currSlice->DFBetaOffset = 0; } + if (p_Vid->active_pps->num_slice_groups_minus1 > 0 && + p_Vid->active_pps->slice_group_map_type >= 3 && + p_Vid->active_pps->slice_group_map_type <= 5) { + len = (active_sps->pic_height_in_map_units_minus1 + 1) * + (active_sps->pic_width_in_mbs_minus1 + 1) / + (p_Vid->active_pps->slice_group_change_rate_minus1 + 1); + if (((active_sps->pic_height_in_map_units_minus1 + 1) * + (active_sps->pic_width_in_mbs_minus1 + 1)) % + (p_Vid->active_pps->slice_group_change_rate_minus1 + 1)) + len += 1; - if (p_Vid->active_pps->num_slice_groups_minus1>0 && p_Vid->active_pps->slice_group_map_type>=3 && - p_Vid->active_pps->slice_group_map_type<=5) - { - len = (active_sps->pic_height_in_map_units_minus1+1)*(active_sps->pic_width_in_mbs_minus1+1)/ - (p_Vid->active_pps->slice_group_change_rate_minus1+1); - if (((active_sps->pic_height_in_map_units_minus1+1)*(active_sps->pic_width_in_mbs_minus1+1))% - (p_Vid->active_pps->slice_group_change_rate_minus1+1)) - len +=1; + len = CeilLog2(len + 1); - len = CeilLog2(len+1); - - currSlice->slice_group_change_cycle = u_v (len, "SH: slice_group_change_cycle", currStream); + currSlice->slice_group_change_cycle = + u_v(len, "SH: slice_group_change_cycle", currStream); } - p_Vid->PicHeightInMbs = p_Vid->FrameHeightInMbs / ( 1 + currSlice->field_pic_flag ); - p_Vid->PicSizeInMbs = p_Vid->PicWidthInMbs * p_Vid->PicHeightInMbs; + p_Vid->PicHeightInMbs = + p_Vid->FrameHeightInMbs / (1 + currSlice->field_pic_flag); + p_Vid->PicSizeInMbs = p_Vid->PicWidthInMbs * p_Vid->PicHeightInMbs; p_Vid->FrameSizeInMbs = p_Vid->PicWidthInMbs * p_Vid->FrameHeightInMbs; return p_Dec->UsedBits; } - /*! ************************************************************************ * \brief * read the reference picture reordering information ************************************************************************ */ -static void ref_pic_list_reordering(Slice *currSlice) -{ +static void ref_pic_list_reordering(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; byte dP_nr = assignSE2partition[currSlice->dp_mode][SE_HEADER]; DataPartition *partition = &(currSlice->partArr[dP_nr]); @@ -359,25 +361,22 @@ static void ref_pic_list_reordering(Slice *currSlice) alloc_ref_pic_list_reordering_buffer(currSlice); - if (p_Vid->type!=I_SLICE && p_Vid->type!=SI_SLICE) - { - val = currSlice->ref_pic_list_reordering_flag[LIST_0] = u_1 ("SH: ref_pic_list_reordering_flag_l0", currStream); + if (p_Vid->type != I_SLICE && p_Vid->type != SI_SLICE) { + val = currSlice->ref_pic_list_reordering_flag[LIST_0] = + u_1("SH: ref_pic_list_reordering_flag_l0", currStream); - if (val) - { - i=0; - do - { - val = currSlice->reordering_of_pic_nums_idc[LIST_0][i] = ue_v("SH: reordering_of_pic_nums_idc_l0", currStream); - if (val==0 || val==1) - { - currSlice->abs_diff_pic_num_minus1[LIST_0][i] = ue_v("SH: abs_diff_pic_num_minus1_l0", currStream); - } - else - { - if (val==2) - { - currSlice->long_term_pic_idx[LIST_0][i] = ue_v("SH: long_term_pic_idx_l0", currStream); + if (val) { + i = 0; + do { + val = currSlice->reordering_of_pic_nums_idc[LIST_0][i] = + ue_v("SH: reordering_of_pic_nums_idc_l0", currStream); + if (val == 0 || val == 1) { + currSlice->abs_diff_pic_num_minus1[LIST_0][i] = + ue_v("SH: abs_diff_pic_num_minus1_l0", currStream); + } else { + if (val == 2) { + currSlice->long_term_pic_idx[LIST_0][i] = + ue_v("SH: long_term_pic_idx_l0", currStream); } } i++; @@ -386,25 +385,22 @@ static void ref_pic_list_reordering(Slice *currSlice) } } - if (p_Vid->type==B_SLICE) - { - val = currSlice->ref_pic_list_reordering_flag[LIST_1] = u_1 ("SH: ref_pic_list_reordering_flag_l1", currStream); + if (p_Vid->type == B_SLICE) { + val = currSlice->ref_pic_list_reordering_flag[LIST_1] = + u_1("SH: ref_pic_list_reordering_flag_l1", currStream); - if (val) - { - i=0; - do - { - val = currSlice->reordering_of_pic_nums_idc[LIST_1][i] = ue_v("SH: reordering_of_pic_nums_idc_l1", currStream); - if (val==0 || val==1) - { - currSlice->abs_diff_pic_num_minus1[LIST_1][i] = ue_v("SH: abs_diff_pic_num_minus1_l1", currStream); - } - else - { - if (val==2) - { - currSlice->long_term_pic_idx[LIST_1][i] = ue_v("SH: long_term_pic_idx_l1", currStream); + if (val) { + i = 0; + do { + val = currSlice->reordering_of_pic_nums_idc[LIST_1][i] = + ue_v("SH: reordering_of_pic_nums_idc_l1", currStream); + if (val == 0 || val == 1) { + currSlice->abs_diff_pic_num_minus1[LIST_1][i] = + ue_v("SH: abs_diff_pic_num_minus1_l1", currStream); + } else { + if (val == 2) { + currSlice->long_term_pic_idx[LIST_1][i] = + ue_v("SH: long_term_pic_idx_l1", currStream); } } i++; @@ -414,9 +410,9 @@ static void ref_pic_list_reordering(Slice *currSlice) } // set reference index of redundant slices. - if(currSlice->redundant_pic_cnt && (p_Vid->type != I_SLICE) ) - { - currSlice->redundant_slice_ref_idx = currSlice->abs_diff_pic_num_minus1[LIST_0][0] + 1; + if (currSlice->redundant_pic_cnt && (p_Vid->type != I_SLICE)) { + currSlice->redundant_slice_ref_idx = + currSlice->abs_diff_pic_num_minus1[LIST_0][0] + 1; } } @@ -427,96 +423,85 @@ static void ref_pic_list_reordering(Slice *currSlice) ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -static void ref_pic_list_mvc_modification(Slice *currSlice) -{ +static void ref_pic_list_mvc_modification(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; - byte dP_nr = assignSE2partition[currSlice->dp_mode][SE_HEADER]; - DataPartition *partition = &(currSlice->partArr[dP_nr]); - Bitstream *currStream = partition->bitstream; - int i, val; + byte dP_nr = assignSE2partition[currSlice->dp_mode][SE_HEADER]; + DataPartition *partition = &(currSlice->partArr[dP_nr]); + Bitstream *currStream = partition->bitstream; + int i, val; - alloc_ref_pic_list_reordering_buffer(currSlice); + alloc_ref_pic_list_reordering_buffer(currSlice); - if ((p_Vid->type % 5) != I_SLICE && (p_Vid->type % 5) != SI_SLICE) - { - val = currSlice->ref_pic_list_reordering_flag[LIST_0] = u_1 ("SH: ref_pic_list_modification_flag_l0", currStream); + if ((p_Vid->type % 5) != I_SLICE && (p_Vid->type % 5) != SI_SLICE) { + val = currSlice->ref_pic_list_reordering_flag[LIST_0] = + u_1("SH: ref_pic_list_modification_flag_l0", currStream); - if (val) - { - i=0; - do - { - val = currSlice->reordering_of_pic_nums_idc[LIST_0][i] = ue_v("SH: modification_of_pic_nums_idc_l0", currStream); - if (val==0 || val==1) - { - currSlice->abs_diff_pic_num_minus1[LIST_0][i] = ue_v("SH: abs_diff_pic_num_minus1_l0", currStream); - } - else - { - if (val==2) - { - currSlice->long_term_pic_idx[LIST_0][i] = ue_v("SH: long_term_pic_idx_l0", currStream); - } - else if (val==4 || val==5) - { - currSlice->abs_diff_view_idx_minus1[LIST_0][i] = ue_v("SH: abs_diff_view_idx_minus1_l0", currStream); - } - } - i++; - // assert (i>img->num_ref_idx_l0_active); - } while (val != 3); - } - } + if (val) { + i = 0; + do { + val = currSlice->reordering_of_pic_nums_idc[LIST_0][i] = + ue_v("SH: modification_of_pic_nums_idc_l0", currStream); + if (val == 0 || val == 1) { + currSlice->abs_diff_pic_num_minus1[LIST_0][i] = + ue_v("SH: abs_diff_pic_num_minus1_l0", currStream); + } else { + if (val == 2) { + currSlice->long_term_pic_idx[LIST_0][i] = + ue_v("SH: long_term_pic_idx_l0", currStream); + } else if (val == 4 || val == 5) { + currSlice->abs_diff_view_idx_minus1[LIST_0][i] = + ue_v("SH: abs_diff_view_idx_minus1_l0", currStream); + } + } + i++; + // assert (i>img->num_ref_idx_l0_active); + } while (val != 3); + } + } - if ((p_Vid->type % 5) == B_SLICE) - { - val = currSlice->ref_pic_list_reordering_flag[LIST_1] = u_1 ("SH: ref_pic_list_reordering_flag_l1", currStream); + if ((p_Vid->type % 5) == B_SLICE) { + val = currSlice->ref_pic_list_reordering_flag[LIST_1] = + u_1("SH: ref_pic_list_reordering_flag_l1", currStream); - if (val) - { - i=0; - do - { - val = currSlice->reordering_of_pic_nums_idc[LIST_1][i] = ue_v("SH: modification_of_pic_nums_idc_l1", currStream); - if (val==0 || val==1) - { - currSlice->abs_diff_pic_num_minus1[LIST_1][i] = ue_v("SH: abs_diff_pic_num_minus1_l1", currStream); - } - else - { - if (val==2) - { - currSlice->long_term_pic_idx[LIST_1][i] = ue_v("SH: long_term_pic_idx_l1", currStream); - } - else if (val==4 || val==5) - { - currSlice->abs_diff_view_idx_minus1[LIST_1][i] = ue_v("SH: abs_diff_view_idx_minus1_l1", currStream); - } - } - i++; - // assert (i>img->num_ref_idx_l1_active); - } while (val != 3); - } - } + if (val) { + i = 0; + do { + val = currSlice->reordering_of_pic_nums_idc[LIST_1][i] = + ue_v("SH: modification_of_pic_nums_idc_l1", currStream); + if (val == 0 || val == 1) { + currSlice->abs_diff_pic_num_minus1[LIST_1][i] = + ue_v("SH: abs_diff_pic_num_minus1_l1", currStream); + } else { + if (val == 2) { + currSlice->long_term_pic_idx[LIST_1][i] = + ue_v("SH: long_term_pic_idx_l1", currStream); + } else if (val == 4 || val == 5) { + currSlice->abs_diff_view_idx_minus1[LIST_1][i] = + ue_v("SH: abs_diff_view_idx_minus1_l1", currStream); + } + } + i++; + // assert (i>img->num_ref_idx_l1_active); + } while (val != 3); + } + } - // set reference index of redundant slices. - if(currSlice->redundant_pic_cnt && (p_Vid->type != I_SLICE) ) - { - currSlice->redundant_slice_ref_idx = currSlice->abs_diff_pic_num_minus1[LIST_0][0] + 1; - } + // set reference index of redundant slices. + if (currSlice->redundant_pic_cnt && (p_Vid->type != I_SLICE)) { + currSlice->redundant_slice_ref_idx = + currSlice->abs_diff_pic_num_minus1[LIST_0][0] + 1; + } } #endif -static void reset_wp_params(Slice *currSlice) -{ - int i,comp; +static void reset_wp_params(Slice *currSlice) { + int i, comp; int log_weight_denom; - for (i=0; iluma_log2_weight_denom : currSlice->chroma_log2_weight_denom; + for (i = 0; i < MAX_REFERENCE_PICTURES; i++) { + for (comp = 0; comp < 3; comp++) { + log_weight_denom = (comp == 0) ? currSlice->luma_log2_weight_denom + : currSlice->chroma_log2_weight_denom; currSlice->wp_weight[0][i][comp] = 1 << log_weight_denom; currSlice->wp_weight[1][i][comp] = 1 << log_weight_denom; } @@ -529,96 +514,93 @@ static void reset_wp_params(Slice *currSlice) * read the weighted prediction tables ************************************************************************ */ -static void pred_weight_table(Slice *currSlice) -{ +static void pred_weight_table(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; byte dP_nr = assignSE2partition[currSlice->dp_mode][SE_HEADER]; DataPartition *partition = &(currSlice->partArr[dP_nr]); Bitstream *currStream = partition->bitstream; - int luma_weight_flag_l0, luma_weight_flag_l1, chroma_weight_flag_l0, chroma_weight_flag_l1; - int i,j; + int luma_weight_flag_l0, luma_weight_flag_l1, chroma_weight_flag_l0, + chroma_weight_flag_l1; + int i, j; - currSlice->luma_log2_weight_denom = (unsigned short) ue_v ("SH: luma_log2_weight_denom", currStream); - currSlice->wp_round_luma = currSlice->luma_log2_weight_denom ? 1<<(currSlice->luma_log2_weight_denom - 1): 0; + currSlice->luma_log2_weight_denom = + (unsigned short)ue_v("SH: luma_log2_weight_denom", currStream); + currSlice->wp_round_luma = currSlice->luma_log2_weight_denom + ? 1 << (currSlice->luma_log2_weight_denom - 1) + : 0; - if ( 0 != active_sps->chroma_format_idc) - { - currSlice->chroma_log2_weight_denom = (unsigned short) ue_v ("SH: chroma_log2_weight_denom", currStream); - currSlice->wp_round_chroma = currSlice->chroma_log2_weight_denom ? 1<<(currSlice->chroma_log2_weight_denom - 1): 0; + if (0 != active_sps->chroma_format_idc) { + currSlice->chroma_log2_weight_denom = + (unsigned short)ue_v("SH: chroma_log2_weight_denom", currStream); + currSlice->wp_round_chroma = + currSlice->chroma_log2_weight_denom + ? 1 << (currSlice->chroma_log2_weight_denom - 1) + : 0; } reset_wp_params(currSlice); - for (i=0; inum_ref_idx_active[LIST_0]; i++) - { + for (i = 0; i < currSlice->num_ref_idx_active[LIST_0]; i++) { luma_weight_flag_l0 = u_1("SH: luma_weight_flag_l0", currStream); - if (luma_weight_flag_l0) - { - currSlice->wp_weight[0][i][0] = se_v ("SH: luma_weight_l0", currStream); - currSlice->wp_offset[0][i][0] = se_v ("SH: luma_offset_l0", currStream); - currSlice->wp_offset[0][i][0] = currSlice->wp_offset[0][i][0]<<(p_Vid->bitdepth_luma - 8); - } - else - { + if (luma_weight_flag_l0) { + currSlice->wp_weight[0][i][0] = se_v("SH: luma_weight_l0", currStream); + currSlice->wp_offset[0][i][0] = se_v("SH: luma_offset_l0", currStream); + currSlice->wp_offset[0][i][0] = currSlice->wp_offset[0][i][0] + << (p_Vid->bitdepth_luma - 8); + } else { currSlice->wp_weight[0][i][0] = 1 << currSlice->luma_log2_weight_denom; currSlice->wp_offset[0][i][0] = 0; } - if (active_sps->chroma_format_idc != 0) - { - chroma_weight_flag_l0 = u_1 ("SH: chroma_weight_flag_l0", currStream); + if (active_sps->chroma_format_idc != 0) { + chroma_weight_flag_l0 = u_1("SH: chroma_weight_flag_l0", currStream); - for (j=1; j<3; j++) - { - if (chroma_weight_flag_l0) - { - currSlice->wp_weight[0][i][j] = se_v("SH: chroma_weight_l0", currStream); - currSlice->wp_offset[0][i][j] = se_v("SH: chroma_offset_l0", currStream); - currSlice->wp_offset[0][i][j] = currSlice->wp_offset[0][i][j]<<(p_Vid->bitdepth_chroma-8); - } - else - { - currSlice->wp_weight[0][i][j] = 1<chroma_log2_weight_denom; + for (j = 1; j < 3; j++) { + if (chroma_weight_flag_l0) { + currSlice->wp_weight[0][i][j] = + se_v("SH: chroma_weight_l0", currStream); + currSlice->wp_offset[0][i][j] = + se_v("SH: chroma_offset_l0", currStream); + currSlice->wp_offset[0][i][j] = currSlice->wp_offset[0][i][j] + << (p_Vid->bitdepth_chroma - 8); + } else { + currSlice->wp_weight[0][i][j] = + 1 << currSlice->chroma_log2_weight_denom; currSlice->wp_offset[0][i][j] = 0; } } } } - if ((p_Vid->type == B_SLICE) && p_Vid->active_pps->weighted_bipred_idc == 1) - { - for (i=0; inum_ref_idx_active[LIST_1]; i++) - { + if ((p_Vid->type == B_SLICE) && p_Vid->active_pps->weighted_bipred_idc == 1) { + for (i = 0; i < currSlice->num_ref_idx_active[LIST_1]; i++) { luma_weight_flag_l1 = u_1("SH: luma_weight_flag_l1", currStream); - if (luma_weight_flag_l1) - { - currSlice->wp_weight[1][i][0] = se_v ("SH: luma_weight_l1", currStream); - currSlice->wp_offset[1][i][0] = se_v ("SH: luma_offset_l1", currStream); - currSlice->wp_offset[1][i][0] = currSlice->wp_offset[1][i][0]<<(p_Vid->bitdepth_luma-8); - } - else - { - currSlice->wp_weight[1][i][0] = 1<luma_log2_weight_denom; + if (luma_weight_flag_l1) { + currSlice->wp_weight[1][i][0] = se_v("SH: luma_weight_l1", currStream); + currSlice->wp_offset[1][i][0] = se_v("SH: luma_offset_l1", currStream); + currSlice->wp_offset[1][i][0] = currSlice->wp_offset[1][i][0] + << (p_Vid->bitdepth_luma - 8); + } else { + currSlice->wp_weight[1][i][0] = 1 << currSlice->luma_log2_weight_denom; currSlice->wp_offset[1][i][0] = 0; } - if (active_sps->chroma_format_idc != 0) - { - chroma_weight_flag_l1 = u_1 ("SH: chroma_weight_flag_l1", currStream); + if (active_sps->chroma_format_idc != 0) { + chroma_weight_flag_l1 = u_1("SH: chroma_weight_flag_l1", currStream); - for (j=1; j<3; j++) - { - if (chroma_weight_flag_l1) - { - currSlice->wp_weight[1][i][j] = se_v("SH: chroma_weight_l1", currStream); - currSlice->wp_offset[1][i][j] = se_v("SH: chroma_offset_l1", currStream); - currSlice->wp_offset[1][i][j] = currSlice->wp_offset[1][i][j]<<(p_Vid->bitdepth_chroma-8); - } - else - { - currSlice->wp_weight[1][i][j] = 1<chroma_log2_weight_denom; + for (j = 1; j < 3; j++) { + if (chroma_weight_flag_l1) { + currSlice->wp_weight[1][i][j] = + se_v("SH: chroma_weight_l1", currStream); + currSlice->wp_offset[1][i][j] = + se_v("SH: chroma_offset_l1", currStream); + currSlice->wp_offset[1][i][j] = currSlice->wp_offset[1][i][j] + << (p_Vid->bitdepth_chroma - 8); + } else { + currSlice->wp_weight[1][i][j] = + 1 << currSlice->chroma_log2_weight_denom; currSlice->wp_offset[1][i][j] = 0; } } @@ -627,79 +609,73 @@ static void pred_weight_table(Slice *currSlice) } } - /*! ************************************************************************ * \brief * read the memory control operations ************************************************************************ */ -void dec_ref_pic_marking(VideoParameters *p_Vid, Bitstream *currStream, Slice *pSlice) -{ +void dec_ref_pic_marking(VideoParameters *p_Vid, Bitstream *currStream, + Slice *pSlice) { int val; - DecRefPicMarking_t *tmp_drpm,*tmp_drpm2; + DecRefPicMarking_t *tmp_drpm, *tmp_drpm2; // free old buffer content - while (pSlice->dec_ref_pic_marking_buffer) - { - tmp_drpm=pSlice->dec_ref_pic_marking_buffer; + while (pSlice->dec_ref_pic_marking_buffer) { + tmp_drpm = pSlice->dec_ref_pic_marking_buffer; - pSlice->dec_ref_pic_marking_buffer=tmp_drpm->Next; - free (tmp_drpm); + pSlice->dec_ref_pic_marking_buffer = tmp_drpm->Next; + free(tmp_drpm); } - if (pSlice->idr_flag) - { - pSlice->no_output_of_prior_pics_flag = u_1("SH: no_output_of_prior_pics_flag", currStream); + if (pSlice->idr_flag) { + pSlice->no_output_of_prior_pics_flag = + u_1("SH: no_output_of_prior_pics_flag", currStream); p_Vid->no_output_of_prior_pics_flag = pSlice->no_output_of_prior_pics_flag; - pSlice->long_term_reference_flag = u_1("SH: long_term_reference_flag", currStream); - } - else - { - pSlice->adaptive_ref_pic_buffering_flag = u_1("SH: adaptive_ref_pic_buffering_flag", currStream); - if (pSlice->adaptive_ref_pic_buffering_flag) - { + pSlice->long_term_reference_flag = + u_1("SH: long_term_reference_flag", currStream); + } else { + pSlice->adaptive_ref_pic_buffering_flag = + u_1("SH: adaptive_ref_pic_buffering_flag", currStream); + if (pSlice->adaptive_ref_pic_buffering_flag) { // read Memory Management Control Operation - do - { - tmp_drpm=(DecRefPicMarking_t*)calloc (1,sizeof (DecRefPicMarking_t)); - tmp_drpm->Next=NULL; + do { + tmp_drpm = (DecRefPicMarking_t *)calloc(1, sizeof(DecRefPicMarking_t)); + tmp_drpm->Next = NULL; - val = tmp_drpm->memory_management_control_operation = ue_v("SH: memory_management_control_operation", currStream); + val = tmp_drpm->memory_management_control_operation = + ue_v("SH: memory_management_control_operation", currStream); - if ((val==1)||(val==3)) - { - tmp_drpm->difference_of_pic_nums_minus1 = ue_v("SH: difference_of_pic_nums_minus1", currStream); + if ((val == 1) || (val == 3)) { + tmp_drpm->difference_of_pic_nums_minus1 = + ue_v("SH: difference_of_pic_nums_minus1", currStream); } - if (val==2) - { - tmp_drpm->long_term_pic_num = ue_v("SH: long_term_pic_num", currStream); + if (val == 2) { + tmp_drpm->long_term_pic_num = + ue_v("SH: long_term_pic_num", currStream); } - if ((val==3)||(val==6)) - { - tmp_drpm->long_term_frame_idx = ue_v("SH: long_term_frame_idx", currStream); + if ((val == 3) || (val == 6)) { + tmp_drpm->long_term_frame_idx = + ue_v("SH: long_term_frame_idx", currStream); } - if (val==4) - { - tmp_drpm->max_long_term_frame_idx_plus1 = ue_v("SH: max_long_term_pic_idx_plus1", currStream); + if (val == 4) { + tmp_drpm->max_long_term_frame_idx_plus1 = + ue_v("SH: max_long_term_pic_idx_plus1", currStream); } // add command - if (pSlice->dec_ref_pic_marking_buffer==NULL) - { - pSlice->dec_ref_pic_marking_buffer=tmp_drpm; - } - else - { - tmp_drpm2=pSlice->dec_ref_pic_marking_buffer; - while (tmp_drpm2->Next!=NULL) tmp_drpm2=tmp_drpm2->Next; - tmp_drpm2->Next=tmp_drpm; + if (pSlice->dec_ref_pic_marking_buffer == NULL) { + pSlice->dec_ref_pic_marking_buffer = tmp_drpm; + } else { + tmp_drpm2 = pSlice->dec_ref_pic_marking_buffer; + while (tmp_drpm2->Next != NULL) + tmp_drpm2 = tmp_drpm2->Next; + tmp_drpm2->Next = tmp_drpm; } - } - while (val != 0); + } while (val != 0); } } } @@ -710,78 +686,69 @@ void dec_ref_pic_marking(VideoParameters *p_Vid, Bitstream *currStream, Slice *p * To calculate the poc values * based upon JVT-F100d2 * POC200301: Until Jan 2003, this function will calculate the correct POC - * values, but the management of POCs in buffered pictures may need more work. - * \return - * none + * values, but the management of POCs in buffered pictures may need more + *work. \return none ************************************************************************ */ -void decode_poc(VideoParameters *p_Vid, Slice *pSlice) -{ +void decode_poc(VideoParameters *p_Vid, Slice *pSlice) { seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; int i; // for POC mode 0: - unsigned int MaxPicOrderCntLsb = (1<<(active_sps->log2_max_pic_order_cnt_lsb_minus4+4)); + unsigned int MaxPicOrderCntLsb = + (1 << (active_sps->log2_max_pic_order_cnt_lsb_minus4 + 4)); - switch ( active_sps->pic_order_cnt_type ) - { + switch (active_sps->pic_order_cnt_type) { case 0: // POC MODE 0 // 1st - if(pSlice->idr_flag) - { + if (pSlice->idr_flag) { p_Vid->PrevPicOrderCntMsb = 0; p_Vid->PrevPicOrderCntLsb = 0; - } - else - { - if (p_Vid->last_has_mmco_5) - { - if (p_Vid->last_pic_bottom_field) - { + } else { + if (p_Vid->last_has_mmco_5) { + if (p_Vid->last_pic_bottom_field) { p_Vid->PrevPicOrderCntMsb = 0; p_Vid->PrevPicOrderCntLsb = 0; - } - else - { + } else { p_Vid->PrevPicOrderCntMsb = 0; p_Vid->PrevPicOrderCntLsb = pSlice->toppoc; } } } // Calculate the MSBs of current picture - if( pSlice->pic_order_cnt_lsb < p_Vid->PrevPicOrderCntLsb && - ( p_Vid->PrevPicOrderCntLsb - pSlice->pic_order_cnt_lsb ) >= ( MaxPicOrderCntLsb / 2 ) ) + if (pSlice->pic_order_cnt_lsb < p_Vid->PrevPicOrderCntLsb && + (p_Vid->PrevPicOrderCntLsb - pSlice->pic_order_cnt_lsb) >= + (MaxPicOrderCntLsb / 2)) pSlice->PicOrderCntMsb = p_Vid->PrevPicOrderCntMsb + MaxPicOrderCntLsb; - else if ( pSlice->pic_order_cnt_lsb > p_Vid->PrevPicOrderCntLsb && - ( pSlice->pic_order_cnt_lsb - p_Vid->PrevPicOrderCntLsb ) > ( MaxPicOrderCntLsb / 2 ) ) + else if (pSlice->pic_order_cnt_lsb > p_Vid->PrevPicOrderCntLsb && + (pSlice->pic_order_cnt_lsb - p_Vid->PrevPicOrderCntLsb) > + (MaxPicOrderCntLsb / 2)) pSlice->PicOrderCntMsb = p_Vid->PrevPicOrderCntMsb - MaxPicOrderCntLsb; else pSlice->PicOrderCntMsb = p_Vid->PrevPicOrderCntMsb; // 2nd - if(pSlice->field_pic_flag==0) - { //frame pix + if (pSlice->field_pic_flag == 0) { // frame pix pSlice->toppoc = pSlice->PicOrderCntMsb + pSlice->pic_order_cnt_lsb; pSlice->bottompoc = pSlice->toppoc + pSlice->delta_pic_order_cnt_bottom; - pSlice->ThisPOC = pSlice->framepoc = (pSlice->toppoc < pSlice->bottompoc)? pSlice->toppoc : pSlice->bottompoc; // POC200301 - } - else if (pSlice->bottom_field_flag == FALSE) - { //top field - pSlice->ThisPOC= pSlice->toppoc = pSlice->PicOrderCntMsb + pSlice->pic_order_cnt_lsb; - } - else - { //bottom field - pSlice->ThisPOC= pSlice->bottompoc = pSlice->PicOrderCntMsb + pSlice->pic_order_cnt_lsb; + pSlice->ThisPOC = pSlice->framepoc = (pSlice->toppoc < pSlice->bottompoc) + ? pSlice->toppoc + : pSlice->bottompoc; // POC200301 + } else if (pSlice->bottom_field_flag == FALSE) { // top field + pSlice->ThisPOC = pSlice->toppoc = + pSlice->PicOrderCntMsb + pSlice->pic_order_cnt_lsb; + } else { // bottom field + pSlice->ThisPOC = pSlice->bottompoc = + pSlice->PicOrderCntMsb + pSlice->pic_order_cnt_lsb; } pSlice->framepoc = pSlice->ThisPOC; p_Vid->ThisPOC = pSlice->ThisPOC; - if ( pSlice->frame_num != p_Vid->PreviousFrameNum) + if (pSlice->frame_num != p_Vid->PreviousFrameNum) p_Vid->PreviousFrameNum = pSlice->frame_num; - if(pSlice->nal_reference_idc) - { + if (pSlice->nal_reference_idc) { p_Vid->PrevPicOrderCntLsb = pSlice->pic_order_cnt_lsb; p_Vid->PrevPicOrderCntMsb = pSlice->PicOrderCntMsb; } @@ -790,123 +757,123 @@ void decode_poc(VideoParameters *p_Vid, Slice *pSlice) case 1: // POC MODE 1 // 1st - if(pSlice->idr_flag) - { - p_Vid->FrameNumOffset=0; // first pix of IDRGOP, - if(pSlice->frame_num) + if (pSlice->idr_flag) { + p_Vid->FrameNumOffset = 0; // first pix of IDRGOP, + if (pSlice->frame_num) error("frame_num not equal to zero in IDR picture", -1020); - } - else - { - if (p_Vid->last_has_mmco_5) - { + } else { + if (p_Vid->last_has_mmco_5) { p_Vid->PreviousFrameNumOffset = 0; p_Vid->PreviousFrameNum = 0; } - if (pSlice->frame_numPreviousFrameNum) - { //not first pix of IDRGOP - p_Vid->FrameNumOffset = p_Vid->PreviousFrameNumOffset + p_Vid->MaxFrameNum; - } - else - { + if (pSlice->frame_num < + p_Vid->PreviousFrameNum) { // not first pix of IDRGOP + p_Vid->FrameNumOffset = + p_Vid->PreviousFrameNumOffset + p_Vid->MaxFrameNum; + } else { p_Vid->FrameNumOffset = p_Vid->PreviousFrameNumOffset; } } // 2nd - if(active_sps->num_ref_frames_in_pic_order_cnt_cycle) - pSlice->AbsFrameNum = p_Vid->FrameNumOffset+pSlice->frame_num; + if (active_sps->num_ref_frames_in_pic_order_cnt_cycle) + pSlice->AbsFrameNum = p_Vid->FrameNumOffset + pSlice->frame_num; else - pSlice->AbsFrameNum=0; - if( (!pSlice->nal_reference_idc) && pSlice->AbsFrameNum > 0) + pSlice->AbsFrameNum = 0; + if ((!pSlice->nal_reference_idc) && pSlice->AbsFrameNum > 0) pSlice->AbsFrameNum--; // 3rd - p_Vid->ExpectedDeltaPerPicOrderCntCycle=0; + p_Vid->ExpectedDeltaPerPicOrderCntCycle = 0; - if(active_sps->num_ref_frames_in_pic_order_cnt_cycle) - for(i=0;i<(int) active_sps->num_ref_frames_in_pic_order_cnt_cycle;i++) - p_Vid->ExpectedDeltaPerPicOrderCntCycle += active_sps->offset_for_ref_frame[i]; + if (active_sps->num_ref_frames_in_pic_order_cnt_cycle) + for (i = 0; i < (int)active_sps->num_ref_frames_in_pic_order_cnt_cycle; + i++) + p_Vid->ExpectedDeltaPerPicOrderCntCycle += + active_sps->offset_for_ref_frame[i]; - if(pSlice->AbsFrameNum) - { - p_Vid->PicOrderCntCycleCnt = (pSlice->AbsFrameNum-1)/active_sps->num_ref_frames_in_pic_order_cnt_cycle; - p_Vid->FrameNumInPicOrderCntCycle = (pSlice->AbsFrameNum-1)%active_sps->num_ref_frames_in_pic_order_cnt_cycle; - p_Vid->ExpectedPicOrderCnt = p_Vid->PicOrderCntCycleCnt*p_Vid->ExpectedDeltaPerPicOrderCntCycle; - for(i=0;i<=(int)p_Vid->FrameNumInPicOrderCntCycle;i++) + if (pSlice->AbsFrameNum) { + p_Vid->PicOrderCntCycleCnt = + (pSlice->AbsFrameNum - 1) / + active_sps->num_ref_frames_in_pic_order_cnt_cycle; + p_Vid->FrameNumInPicOrderCntCycle = + (pSlice->AbsFrameNum - 1) % + active_sps->num_ref_frames_in_pic_order_cnt_cycle; + p_Vid->ExpectedPicOrderCnt = + p_Vid->PicOrderCntCycleCnt * p_Vid->ExpectedDeltaPerPicOrderCntCycle; + for (i = 0; i <= (int)p_Vid->FrameNumInPicOrderCntCycle; i++) p_Vid->ExpectedPicOrderCnt += active_sps->offset_for_ref_frame[i]; - } - else - p_Vid->ExpectedPicOrderCnt=0; + } else + p_Vid->ExpectedPicOrderCnt = 0; - if(!pSlice->nal_reference_idc) + if (!pSlice->nal_reference_idc) p_Vid->ExpectedPicOrderCnt += active_sps->offset_for_non_ref_pic; - if(pSlice->field_pic_flag==0) - { //frame pix - pSlice->toppoc = p_Vid->ExpectedPicOrderCnt + pSlice->delta_pic_order_cnt[0]; - pSlice->bottompoc = pSlice->toppoc + active_sps->offset_for_top_to_bottom_field + pSlice->delta_pic_order_cnt[1]; - pSlice->ThisPOC = pSlice->framepoc = (pSlice->toppoc < pSlice->bottompoc)? pSlice->toppoc : pSlice->bottompoc; // POC200301 + if (pSlice->field_pic_flag == 0) { // frame pix + pSlice->toppoc = + p_Vid->ExpectedPicOrderCnt + pSlice->delta_pic_order_cnt[0]; + pSlice->bottompoc = pSlice->toppoc + + active_sps->offset_for_top_to_bottom_field + + pSlice->delta_pic_order_cnt[1]; + pSlice->ThisPOC = pSlice->framepoc = (pSlice->toppoc < pSlice->bottompoc) + ? pSlice->toppoc + : pSlice->bottompoc; // POC200301 + } else if (pSlice->bottom_field_flag == FALSE) { // top field + pSlice->ThisPOC = pSlice->toppoc = + p_Vid->ExpectedPicOrderCnt + pSlice->delta_pic_order_cnt[0]; + } else { // bottom field + pSlice->ThisPOC = pSlice->bottompoc = + p_Vid->ExpectedPicOrderCnt + + active_sps->offset_for_top_to_bottom_field + + pSlice->delta_pic_order_cnt[0]; } - else if (pSlice->bottom_field_flag == FALSE) - { //top field - pSlice->ThisPOC = pSlice->toppoc = p_Vid->ExpectedPicOrderCnt + pSlice->delta_pic_order_cnt[0]; - } - else - { //bottom field - pSlice->ThisPOC = pSlice->bottompoc = p_Vid->ExpectedPicOrderCnt + active_sps->offset_for_top_to_bottom_field + pSlice->delta_pic_order_cnt[0]; - } - pSlice->framepoc=pSlice->ThisPOC; + pSlice->framepoc = pSlice->ThisPOC; - p_Vid->PreviousFrameNum=pSlice->frame_num; - p_Vid->PreviousFrameNumOffset=p_Vid->FrameNumOffset; + p_Vid->PreviousFrameNum = pSlice->frame_num; + p_Vid->PreviousFrameNumOffset = p_Vid->FrameNumOffset; break; - - case 2: // POC MODE 2 - if(pSlice->idr_flag) // IDR picture + case 2: // POC MODE 2 + if (pSlice->idr_flag) // IDR picture { - p_Vid->FrameNumOffset=0; // first pix of IDRGOP, - pSlice->ThisPOC = pSlice->framepoc = pSlice->toppoc = pSlice->bottompoc = 0; - if(pSlice->frame_num) + p_Vid->FrameNumOffset = 0; // first pix of IDRGOP, + pSlice->ThisPOC = pSlice->framepoc = pSlice->toppoc = pSlice->bottompoc = + 0; + if (pSlice->frame_num) error("frame_num not equal to zero in IDR picture", -1020); - } - else - { - if (p_Vid->last_has_mmco_5) - { + } else { + if (p_Vid->last_has_mmco_5) { p_Vid->PreviousFrameNum = 0; p_Vid->PreviousFrameNumOffset = 0; } - if (pSlice->frame_numPreviousFrameNum) - p_Vid->FrameNumOffset = p_Vid->PreviousFrameNumOffset + p_Vid->MaxFrameNum; + if (pSlice->frame_num < p_Vid->PreviousFrameNum) + p_Vid->FrameNumOffset = + p_Vid->PreviousFrameNumOffset + p_Vid->MaxFrameNum; else p_Vid->FrameNumOffset = p_Vid->PreviousFrameNumOffset; - - pSlice->AbsFrameNum = p_Vid->FrameNumOffset+pSlice->frame_num; - if(!pSlice->nal_reference_idc) - pSlice->ThisPOC = (2*pSlice->AbsFrameNum - 1); + pSlice->AbsFrameNum = p_Vid->FrameNumOffset + pSlice->frame_num; + if (!pSlice->nal_reference_idc) + pSlice->ThisPOC = (2 * pSlice->AbsFrameNum - 1); else - pSlice->ThisPOC = (2*pSlice->AbsFrameNum); + pSlice->ThisPOC = (2 * pSlice->AbsFrameNum); - if (pSlice->field_pic_flag==0) + if (pSlice->field_pic_flag == 0) pSlice->toppoc = pSlice->bottompoc = pSlice->framepoc = pSlice->ThisPOC; else if (pSlice->bottom_field_flag == FALSE) - pSlice->toppoc = pSlice->framepoc = pSlice->ThisPOC; - else + pSlice->toppoc = pSlice->framepoc = pSlice->ThisPOC; + else pSlice->bottompoc = pSlice->framepoc = pSlice->ThisPOC; } - p_Vid->PreviousFrameNum=pSlice->frame_num; - p_Vid->PreviousFrameNumOffset=p_Vid->FrameNumOffset; + p_Vid->PreviousFrameNum = pSlice->frame_num; + p_Vid->PreviousFrameNumOffset = p_Vid->FrameNumOffset; break; - default: - //error must occurs - assert( 1==0 ); + // error must occurs + assert(1 == 0); break; } } @@ -919,32 +886,49 @@ void decode_poc(VideoParameters *p_Vid, Slice *pSlice) * none ************************************************************************ */ -int dumppoc(VideoParameters *p_Vid) -{ +int dumppoc(VideoParameters *p_Vid) { seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; - printf ("\nPOC locals...\n"); - printf ("toppoc %d\n", (int) p_Vid->ppSliceList[0]->toppoc); - printf ("bottompoc %d\n", (int) p_Vid->ppSliceList[0]->bottompoc); - printf ("frame_num %d\n", (int) p_Vid->ppSliceList[0]->frame_num); - printf ("field_pic_flag %d\n", (int) p_Vid->ppSliceList[0]->field_pic_flag); - printf ("bottom_field_flag %d\n", (int) p_Vid->ppSliceList[0]->bottom_field_flag); - printf ("POC SPS\n"); - printf ("log2_max_frame_num_minus4 %d\n", (int) active_sps->log2_max_frame_num_minus4); // POC200301 - printf ("log2_max_pic_order_cnt_lsb_minus4 %d\n", (int) active_sps->log2_max_pic_order_cnt_lsb_minus4); - printf ("pic_order_cnt_type %d\n", (int) active_sps->pic_order_cnt_type); - printf ("num_ref_frames_in_pic_order_cnt_cycle %d\n", (int) active_sps->num_ref_frames_in_pic_order_cnt_cycle); - printf ("delta_pic_order_always_zero_flag %d\n", (int) active_sps->delta_pic_order_always_zero_flag); - printf ("offset_for_non_ref_pic %d\n", (int) active_sps->offset_for_non_ref_pic); - printf ("offset_for_top_to_bottom_field %d\n", (int) active_sps->offset_for_top_to_bottom_field); - printf ("offset_for_ref_frame[0] %d\n", (int) active_sps->offset_for_ref_frame[0]); - printf ("offset_for_ref_frame[1] %d\n", (int) active_sps->offset_for_ref_frame[1]); - printf ("POC in SLice Header\n"); - printf ("bottom_field_pic_order_in_frame_present_flag %d\n", (int) p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag); - printf ("delta_pic_order_cnt[0] %d\n", (int) p_Vid->ppSliceList[0]->delta_pic_order_cnt[0]); - printf ("delta_pic_order_cnt[1] %d\n", (int) p_Vid->ppSliceList[0]->delta_pic_order_cnt[1]); - printf ("idr_flag %d\n", (int) p_Vid->ppSliceList[0]->idr_flag); - printf ("MaxFrameNum %d\n", (int) p_Vid->MaxFrameNum); + printf("\nPOC locals...\n"); + printf("toppoc %d\n", + (int)p_Vid->ppSliceList[0]->toppoc); + printf("bottompoc %d\n", + (int)p_Vid->ppSliceList[0]->bottompoc); + printf("frame_num %d\n", + (int)p_Vid->ppSliceList[0]->frame_num); + printf("field_pic_flag %d\n", + (int)p_Vid->ppSliceList[0]->field_pic_flag); + printf("bottom_field_flag %d\n", + (int)p_Vid->ppSliceList[0]->bottom_field_flag); + printf("POC SPS\n"); + printf("log2_max_frame_num_minus4 %d\n", + (int)active_sps->log2_max_frame_num_minus4); // POC200301 + printf("log2_max_pic_order_cnt_lsb_minus4 %d\n", + (int)active_sps->log2_max_pic_order_cnt_lsb_minus4); + printf("pic_order_cnt_type %d\n", + (int)active_sps->pic_order_cnt_type); + printf("num_ref_frames_in_pic_order_cnt_cycle %d\n", + (int)active_sps->num_ref_frames_in_pic_order_cnt_cycle); + printf("delta_pic_order_always_zero_flag %d\n", + (int)active_sps->delta_pic_order_always_zero_flag); + printf("offset_for_non_ref_pic %d\n", + (int)active_sps->offset_for_non_ref_pic); + printf("offset_for_top_to_bottom_field %d\n", + (int)active_sps->offset_for_top_to_bottom_field); + printf("offset_for_ref_frame[0] %d\n", + (int)active_sps->offset_for_ref_frame[0]); + printf("offset_for_ref_frame[1] %d\n", + (int)active_sps->offset_for_ref_frame[1]); + printf("POC in SLice Header\n"); + printf("bottom_field_pic_order_in_frame_present_flag %d\n", + (int)p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag); + printf("delta_pic_order_cnt[0] %d\n", + (int)p_Vid->ppSliceList[0]->delta_pic_order_cnt[0]); + printf("delta_pic_order_cnt[1] %d\n", + (int)p_Vid->ppSliceList[0]->delta_pic_order_cnt[1]); + printf("idr_flag %d\n", + (int)p_Vid->ppSliceList[0]->idr_flag); + printf("MaxFrameNum %d\n", (int)p_Vid->MaxFrameNum); return 0; } @@ -956,13 +940,11 @@ int dumppoc(VideoParameters *p_Vid) * POC200301 ************************************************************************ */ -int picture_order( Slice *pSlice ) -{ - if (pSlice->field_pic_flag==0) // is a frame +int picture_order(Slice *pSlice) { + if (pSlice->field_pic_flag == 0) // is a frame return pSlice->framepoc; else if (pSlice->bottom_field_flag == FALSE) // top field return pSlice->toppoc; else // bottom field return pSlice->bottompoc; } - diff --git a/src/common/ldecod_src/image.c b/src/common/ldecod_src/image.c index 2f124c2..6209332 100644 --- a/src/common/ldecod_src/image.c +++ b/src/common/ldecod_src/image.c @@ -7,7 +7,8 @@ * Decode a Slice * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Inge Lille-Langoy * - Rickard Sjoberg * - Jani Lainema @@ -28,49 +29,47 @@ #include "contributors.h" -#include #include +#include -#include "global.h" -#include "image.h" -#include "fmo.h" #include "annexb.h" +#include "fmo.h" +#include "global.h" +#include "header.h" +#include "image.h" #include "nalu.h" #include "parset.h" -#include "header.h" -#include "sei.h" -#include "output.h" +#include "macroblock.h" #include "mb_access.h" #include "memalloc.h" -#include "macroblock.h" +#include "output.h" +#include "sei.h" #include "loopfilter.h" #include "biaridecod.h" -#include "context_ini.h" #include "cabac.h" -#include "vlc.h" +#include "context_ini.h" #include "quant.h" +#include "vlc.h" -#include "errorconcealment.h" #include "erc_api.h" -#include "mbuffer_mvc.h" +#include "errorconcealment.h" #include "fast_memory.h" +#include "mbuffer_mvc.h" #include "mc_prediction.h" extern int testEndian(void); void reorder_lists(Slice *currSlice); -static inline void reset_mbs(Macroblock *currMB) -{ - currMB->slice_nr = -1; - currMB->ei_flag = 1; - currMB->dpl_flag = 0; +static inline void reset_mbs(Macroblock *currMB) { + currMB->slice_nr = -1; + currMB->ei_flag = 1; + currMB->dpl_flag = 0; } -static inline void reset_mv_info(PicMotionParams *mv_info) -{ +static inline void reset_mv_info(PicMotionParams *mv_info) { mv_info->ref_pic[LIST_0] = NULL; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = zero_mv; @@ -85,28 +84,24 @@ static inline void reset_mv_info(PicMotionParams *mv_info) * init macroblock I and P frames ************************************************************************ */ -void init_all_macroblocks(StorablePicture *dec_picture) -{ +void init_all_macroblocks(StorablePicture *dec_picture) { int j; PicMotionParams *mv_info = dec_picture->mv_info[0]; // reset vectors and pred. modes - for(j = 0; j < ((dec_picture->size_x * dec_picture->size_y) >> 4); ++j) - { + for (j = 0; j < ((dec_picture->size_x * dec_picture->size_y) >> 4); ++j) { reset_mv_info(mv_info++); } } - - /*! ************************************************************************ * \brief * Initializes the parameters for a new picture ************************************************************************ */ -static void init_picture(VideoParameters *p_Vid, Slice *currSlice, InputParameters *p_Inp) -{ +static void init_picture(VideoParameters *p_Vid, Slice *currSlice, + InputParameters *p_Inp) { int i; int nplane; StorablePicture *dec_picture = NULL; @@ -120,311 +115,311 @@ static void init_picture(VideoParameters *p_Vid, Slice *currSlice, InputParamete exit_picture(p_Vid, &p_Vid->dec_picture); } if (p_Vid->recovery_point) - p_Vid->recovery_frame_num = (currSlice->frame_num + p_Vid->recovery_frame_cnt) % p_Vid->MaxFrameNum; + p_Vid->recovery_frame_num = + (currSlice->frame_num + p_Vid->recovery_frame_cnt) % p_Vid->MaxFrameNum; if (currSlice->idr_flag) p_Vid->recovery_frame_num = currSlice->frame_num; if (p_Vid->recovery_point == 0 && - currSlice->frame_num != p_Vid->pre_frame_num && - currSlice->frame_num != (p_Vid->pre_frame_num + 1) % p_Vid->MaxFrameNum) - { - if (active_sps->gaps_in_frame_num_value_allowed_flag == 0) - { + currSlice->frame_num != p_Vid->pre_frame_num && + currSlice->frame_num != (p_Vid->pre_frame_num + 1) % p_Vid->MaxFrameNum) { + if (active_sps->gaps_in_frame_num_value_allowed_flag == 0) { // picture error concealment - if(p_Inp->conceal_mode !=0) - { - if((currSlice->frame_num) < ((p_Vid->pre_frame_num + 1) % p_Vid->MaxFrameNum)) - { + if (p_Inp->conceal_mode != 0) { + if ((currSlice->frame_num) < + ((p_Vid->pre_frame_num + 1) % p_Vid->MaxFrameNum)) { /* Conceal lost IDR frames and any frames immediately following the IDR. Use frame copy for these since lists cannot be formed correctly for motion copy*/ p_Vid->conceal_mode = 1; p_Vid->IDR_concealment_flag = 1; conceal_lost_frames(p_Dpb, currSlice); - //reset to original concealment mode for future drops + // reset to original concealment mode for future drops p_Vid->conceal_mode = p_Inp->conceal_mode; - } - else - { - //reset to original concealment mode for future drops + } else { + // reset to original concealment mode for future drops p_Vid->conceal_mode = p_Inp->conceal_mode; p_Vid->IDR_concealment_flag = 0; conceal_lost_frames(p_Dpb, currSlice); } - } - else - { /* Advanced Error Concealment would be called here to combat unintentional loss of pictures. */ + } else { /* Advanced Error Concealment would be called here to combat + unintentional loss of pictures. */ error("An unintentional loss of pictures occurs! Exit\n", 100); } } - if(p_Vid->conceal_mode == 0) + if (p_Vid->conceal_mode == 0) fill_frame_num_gap(p_Vid, currSlice); } - if(currSlice->nal_reference_idc) - { + if (currSlice->nal_reference_idc) { p_Vid->pre_frame_num = currSlice->frame_num; } - //p_Vid->num_dec_mb = 0; + // p_Vid->num_dec_mb = 0; - //calculate POC + // calculate POC decode_poc(p_Vid, currSlice); - if (p_Vid->recovery_frame_num == (int) currSlice->frame_num && p_Vid->recovery_poc == 0x7fffffff) + if (p_Vid->recovery_frame_num == (int)currSlice->frame_num && + p_Vid->recovery_poc == 0x7fffffff) p_Vid->recovery_poc = currSlice->framepoc; - if(currSlice->nal_reference_idc) + if (currSlice->nal_reference_idc) p_Vid->last_ref_pic_poc = currSlice->framepoc; - // dumppoc (p_Vid); + // dumppoc (p_Vid); #ifndef SPEC - if (currSlice->structure==FRAME ||currSlice->structure==TOP_FIELD) - { - gettime (&(p_Vid->start_time)); // start time + if (currSlice->structure == FRAME || currSlice->structure == TOP_FIELD) { + gettime(&(p_Vid->start_time)); // start time } -#endif /* !SPEC */ - dec_picture = p_Vid->dec_picture = alloc_storable_picture (p_Vid, currSlice->structure, p_Vid->width, p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); - dec_picture->top_poc=currSlice->toppoc; - dec_picture->bottom_poc=currSlice->bottompoc; - dec_picture->frame_poc=currSlice->framepoc; +#endif /* !SPEC */ + dec_picture = p_Vid->dec_picture = + alloc_storable_picture(p_Vid, currSlice->structure, p_Vid->width, + p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); + dec_picture->top_poc = currSlice->toppoc; + dec_picture->bottom_poc = currSlice->bottompoc; + dec_picture->frame_poc = currSlice->framepoc; dec_picture->qp = currSlice->qp; dec_picture->slice_qp_delta = currSlice->slice_qp_delta; dec_picture->chroma_qp_offset[0] = p_Vid->active_pps->chroma_qp_index_offset; - dec_picture->chroma_qp_offset[1] = p_Vid->active_pps->second_chroma_qp_index_offset; - dec_picture->iCodingType = currSlice->structure==FRAME? (currSlice->mb_aff_frame_flag? FRAME_MB_PAIR_CODING:FRAME_CODING): FIELD_CODING; //currSlice->slice_type; + dec_picture->chroma_qp_offset[1] = + p_Vid->active_pps->second_chroma_qp_index_offset; + dec_picture->iCodingType = + currSlice->structure == FRAME + ? (currSlice->mb_aff_frame_flag ? FRAME_MB_PAIR_CODING : FRAME_CODING) + : FIELD_CODING; // currSlice->slice_type; #if (MVC_EXTENSION_ENABLE) - dec_picture->view_id = currSlice->view_id; + dec_picture->view_id = currSlice->view_id; dec_picture->inter_view_flag = currSlice->inter_view_flag; dec_picture->anchor_pic_flag = currSlice->anchor_pic_flag; #endif - // reset all variables of the error concealment instance before decoding of every frame. - // here the third parameter should, if perfectly, be equal to the number of slices per frame. - // using little value is ok, the code will allocate more memory if the slice number is larger - ercReset(p_Vid->erc_errorVar, p_Vid->PicSizeInMbs, p_Vid->PicSizeInMbs, dec_picture->size_x); + // reset all variables of the error concealment instance before decoding of + // every frame. here the third parameter should, if perfectly, be equal to the + // number of slices per frame. using little value is ok, the code will + // allocate more memory if the slice number is larger + ercReset(p_Vid->erc_errorVar, p_Vid->PicSizeInMbs, p_Vid->PicSizeInMbs, + dec_picture->size_x); p_Vid->erc_mvperMB = 0; - switch (currSlice->structure ) - { - case TOP_FIELD: - { - dec_picture->poc = currSlice->toppoc; - p_Vid->number *= 2; - break; - } - case BOTTOM_FIELD: - { - dec_picture->poc = currSlice->bottompoc; - p_Vid->number = p_Vid->number * 2 + 1; - break; - } - case FRAME: - { - dec_picture->poc = currSlice->framepoc; - break; - } + switch (currSlice->structure) { + case TOP_FIELD: { + dec_picture->poc = currSlice->toppoc; + p_Vid->number *= 2; + break; + } + case BOTTOM_FIELD: { + dec_picture->poc = currSlice->bottompoc; + p_Vid->number = p_Vid->number * 2 + 1; + break; + } + case FRAME: { + dec_picture->poc = currSlice->framepoc; + break; + } default: error("p_Vid->structure not initialized", 235); } - //p_Vid->current_slice_nr=0; + // p_Vid->current_slice_nr=0; - if (p_Vid->type > SI_SLICE) - { + if (p_Vid->type > SI_SLICE) { set_ec_flag(p_Vid, SE_PTYPE); - p_Vid->type = P_SLICE; // concealed element + p_Vid->type = P_SLICE; // concealed element } // CAVLC init - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC) - { - memset(p_Vid->nz_coeff[0][0][0], -1, p_Vid->PicSizeInMbs * 48 *sizeof(byte)); // 3 * 4 * 4 + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC) { + memset(p_Vid->nz_coeff[0][0][0], -1, + p_Vid->PicSizeInMbs * 48 * sizeof(byte)); // 3 * 4 * 4 } - // Set the slice_nr member of each MB to -1, to ensure correct when packet loss occurs - // TO set Macroblock Map (mark all MBs as 'have to be concealed') - if( (p_Vid->separate_colour_plane_flag != 0) ) - { - for( nplane=0; nplaneseparate_colour_plane_flag != 0)) { + for (nplane = 0; nplane < MAX_PLANE; ++nplane) { Macroblock *currMB = p_Vid->mb_data_JV[nplane]; signed char *intra_block = p_Vid->intra_block_JV[nplane]; - for(i=0; i<(int)p_Vid->PicSizeInMbs; ++i) - { + for (i = 0; i < (int)p_Vid->PicSizeInMbs; ++i) { reset_mbs(currMB++); } - fast_memset(p_Vid->ipredmode_JV[nplane][0], DC_PRED, 16 * p_Vid->FrameHeightInMbs * p_Vid->PicWidthInMbs * sizeof(char)); - if(p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0; i<(int)p_Vid->PicSizeInMbs; ++i) - { + fast_memset(p_Vid->ipredmode_JV[nplane][0], DC_PRED, + 16 * p_Vid->FrameHeightInMbs * p_Vid->PicWidthInMbs * + sizeof(char)); + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0; i < (int)p_Vid->PicSizeInMbs; ++i) { intra_block[i] = 1; } } } - } - else - { -#if 0 && (defined(_OPENMP) || defined(SPEC_OPENMP)) && !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) + } else { +#if 0 && (defined(_OPENMP) || defined(SPEC_OPENMP)) && \ + !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) #pragma omp parallel for for(i=0; i<(int)p_Vid->PicSizeInMbs; ++i) reset_mbs(&p_Vid->mb_data[i]); #else Macroblock *currMB = p_Vid->mb_data; - for(i=0; i<(int)p_Vid->PicSizeInMbs; ++i) + for (i = 0; i < (int)p_Vid->PicSizeInMbs; ++i) reset_mbs(currMB++); #endif - if(p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0; i<(int)p_Vid->PicSizeInMbs; ++i) - { + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0; i < (int)p_Vid->PicSizeInMbs; ++i) { p_Vid->intra_block[i] = 1; } } - fast_memset(p_Vid->ipredmode[0], DC_PRED, 16 * p_Vid->FrameHeightInMbs * p_Vid->PicWidthInMbs * sizeof(char)); - } + fast_memset(p_Vid->ipredmode[0], DC_PRED, + 16 * p_Vid->FrameHeightInMbs * p_Vid->PicWidthInMbs * + sizeof(char)); + } dec_picture->slice_type = p_Vid->type; dec_picture->used_for_reference = (currSlice->nal_reference_idc != 0); dec_picture->idr_flag = currSlice->idr_flag; - dec_picture->no_output_of_prior_pics_flag = currSlice->no_output_of_prior_pics_flag; - dec_picture->long_term_reference_flag = currSlice->long_term_reference_flag; - dec_picture->adaptive_ref_pic_buffering_flag = currSlice->adaptive_ref_pic_buffering_flag; + dec_picture->no_output_of_prior_pics_flag = + currSlice->no_output_of_prior_pics_flag; + dec_picture->long_term_reference_flag = currSlice->long_term_reference_flag; + dec_picture->adaptive_ref_pic_buffering_flag = + currSlice->adaptive_ref_pic_buffering_flag; - dec_picture->dec_ref_pic_marking_buffer = currSlice->dec_ref_pic_marking_buffer; - currSlice->dec_ref_pic_marking_buffer = NULL; + dec_picture->dec_ref_pic_marking_buffer = + currSlice->dec_ref_pic_marking_buffer; + currSlice->dec_ref_pic_marking_buffer = NULL; dec_picture->mb_aff_frame_flag = currSlice->mb_aff_frame_flag; - dec_picture->PicWidthInMbs = p_Vid->PicWidthInMbs; + dec_picture->PicWidthInMbs = p_Vid->PicWidthInMbs; - p_Vid->get_mb_block_pos = dec_picture->mb_aff_frame_flag ? get_mb_block_pos_mbaff : get_mb_block_pos_normal; - p_Vid->getNeighbour = dec_picture->mb_aff_frame_flag ? getAffNeighbour : getNonAffNeighbour; + p_Vid->get_mb_block_pos = dec_picture->mb_aff_frame_flag + ? get_mb_block_pos_mbaff + : get_mb_block_pos_normal; + p_Vid->getNeighbour = + dec_picture->mb_aff_frame_flag ? getAffNeighbour : getNonAffNeighbour; - dec_picture->pic_num = currSlice->frame_num; + dec_picture->pic_num = currSlice->frame_num; dec_picture->frame_num = currSlice->frame_num; - dec_picture->recovery_frame = (unsigned int) ((int) currSlice->frame_num == p_Vid->recovery_frame_num); + dec_picture->recovery_frame = + (unsigned int)((int)currSlice->frame_num == p_Vid->recovery_frame_num); - dec_picture->coded_frame = (currSlice->structure==FRAME); + dec_picture->coded_frame = (currSlice->structure == FRAME); dec_picture->chroma_format_idc = active_sps->chroma_format_idc; dec_picture->frame_mbs_only_flag = active_sps->frame_mbs_only_flag; dec_picture->frame_cropping_flag = active_sps->frame_cropping_flag; - if (dec_picture->frame_cropping_flag) - { - dec_picture->frame_cropping_rect_left_offset = active_sps->frame_cropping_rect_left_offset; - dec_picture->frame_cropping_rect_right_offset = active_sps->frame_cropping_rect_right_offset; - dec_picture->frame_cropping_rect_top_offset = active_sps->frame_cropping_rect_top_offset; - dec_picture->frame_cropping_rect_bottom_offset = active_sps->frame_cropping_rect_bottom_offset; + if (dec_picture->frame_cropping_flag) { + dec_picture->frame_cropping_rect_left_offset = + active_sps->frame_cropping_rect_left_offset; + dec_picture->frame_cropping_rect_right_offset = + active_sps->frame_cropping_rect_right_offset; + dec_picture->frame_cropping_rect_top_offset = + active_sps->frame_cropping_rect_top_offset; + dec_picture->frame_cropping_rect_bottom_offset = + active_sps->frame_cropping_rect_bottom_offset; } #if (ENABLE_OUTPUT_TONEMAPPING) // store the necessary tone mapping sei into StorablePicture structure - if (p_Vid->seiToneMapping->seiHasTone_mapping) - { - int coded_data_bit_max = (1 << p_Vid->seiToneMapping->coded_data_bit_depth); - dec_picture->seiHasTone_mapping = 1; + if (p_Vid->seiToneMapping->seiHasTone_mapping) { + int coded_data_bit_max = (1 << p_Vid->seiToneMapping->coded_data_bit_depth); + dec_picture->seiHasTone_mapping = 1; dec_picture->tone_mapping_model_id = p_Vid->seiToneMapping->model_id; - dec_picture->tonemapped_bit_depth = p_Vid->seiToneMapping->sei_bit_depth; - dec_picture->tone_mapping_lut = malloc(coded_data_bit_max * sizeof(int)); - if (NULL == dec_picture->tone_mapping_lut) - { + dec_picture->tonemapped_bit_depth = p_Vid->seiToneMapping->sei_bit_depth; + dec_picture->tone_mapping_lut = malloc(coded_data_bit_max * sizeof(int)); + if (NULL == dec_picture->tone_mapping_lut) { no_mem_exit("init_picture: tone_mapping_lut"); } - memcpy(dec_picture->tone_mapping_lut, p_Vid->seiToneMapping->lut, sizeof(imgpel) * coded_data_bit_max); + memcpy(dec_picture->tone_mapping_lut, p_Vid->seiToneMapping->lut, + sizeof(imgpel) * coded_data_bit_max); update_tone_mapping_sei(p_Vid->seiToneMapping); - } - else + } else dec_picture->seiHasTone_mapping = 0; #endif - if( (p_Vid->separate_colour_plane_flag != 0) ) - { + if ((p_Vid->separate_colour_plane_flag != 0)) { p_Vid->dec_picture_JV[0] = p_Vid->dec_picture; - p_Vid->dec_picture_JV[1] = alloc_storable_picture (p_Vid, (PictureStructure) currSlice->structure, p_Vid->width, p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); - copy_dec_picture_JV( p_Vid, p_Vid->dec_picture_JV[1], p_Vid->dec_picture_JV[0] ); - p_Vid->dec_picture_JV[2] = alloc_storable_picture (p_Vid, (PictureStructure) currSlice->structure, p_Vid->width, p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); - copy_dec_picture_JV( p_Vid, p_Vid->dec_picture_JV[2], p_Vid->dec_picture_JV[0] ); + p_Vid->dec_picture_JV[1] = alloc_storable_picture( + p_Vid, (PictureStructure)currSlice->structure, p_Vid->width, + p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); + copy_dec_picture_JV(p_Vid, p_Vid->dec_picture_JV[1], + p_Vid->dec_picture_JV[0]); + p_Vid->dec_picture_JV[2] = alloc_storable_picture( + p_Vid, (PictureStructure)currSlice->structure, p_Vid->width, + p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); + copy_dec_picture_JV(p_Vid, p_Vid->dec_picture_JV[2], + p_Vid->dec_picture_JV[0]); } } -static void update_mbaff_macroblock_data(imgpel **cur_img, imgpel (*temp)[16], int x0, int width, int height) -{ - imgpel (*temp_evn)[16] = temp; - imgpel (*temp_odd)[16] = temp + height; +static void update_mbaff_macroblock_data(imgpel **cur_img, imgpel (*temp)[16], + int x0, int width, int height) { + imgpel(*temp_evn)[16] = temp; + imgpel(*temp_odd)[16] = temp + height; imgpel **temp_img = cur_img; int y; for (y = 0; y < 2 * height; ++y) memcpy(*temp++, (*temp_img++ + x0), width * sizeof(imgpel)); - for (y = 0; y < height; ++y) - { + for (y = 0; y < height; ++y) { memcpy((*cur_img++ + x0), *temp_evn++, width * sizeof(imgpel)); memcpy((*cur_img++ + x0), *temp_odd++, width * sizeof(imgpel)); } } -static void MbAffPostProc(VideoParameters *p_Vid) -{ +static void MbAffPostProc(VideoParameters *p_Vid) { imgpel temp_buffer[32][16]; StorablePicture *dec_picture = p_Vid->dec_picture; - imgpel ** imgY = dec_picture->imgY; + imgpel **imgY = dec_picture->imgY; imgpel ***imgUV = dec_picture->imgUV; short i, x0, y0; - for (i=0; i<(int)dec_picture->PicSizeInMbs; i+=2) - { - if (dec_picture->motion.mb_field[i]) - { + for (i = 0; i < (int)dec_picture->PicSizeInMbs; i += 2) { + if (dec_picture->motion.mb_field[i]) { get_mb_pos(p_Vid, i, p_Vid->mb_size[IS_LUMA], &x0, &y0); - update_mbaff_macroblock_data(imgY + y0, temp_buffer, x0, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + update_mbaff_macroblock_data(imgY + y0, temp_buffer, x0, MB_BLOCK_SIZE, + MB_BLOCK_SIZE); - if (dec_picture->chroma_format_idc != YUV400) - { - x0 = (short) ((x0 * p_Vid->mb_cr_size_x) >> 4); - y0 = (short) ((y0 * p_Vid->mb_cr_size_y) >> 4); + if (dec_picture->chroma_format_idc != YUV400) { + x0 = (short)((x0 * p_Vid->mb_cr_size_x) >> 4); + y0 = (short)((y0 * p_Vid->mb_cr_size_y) >> 4); - update_mbaff_macroblock_data(imgUV[0] + y0, temp_buffer, x0, p_Vid->mb_cr_size_x, p_Vid->mb_cr_size_y); - update_mbaff_macroblock_data(imgUV[1] + y0, temp_buffer, x0, p_Vid->mb_cr_size_x, p_Vid->mb_cr_size_y); + update_mbaff_macroblock_data(imgUV[0] + y0, temp_buffer, x0, + p_Vid->mb_cr_size_x, p_Vid->mb_cr_size_y); + update_mbaff_macroblock_data(imgUV[1] + y0, temp_buffer, x0, + p_Vid->mb_cr_size_x, p_Vid->mb_cr_size_y); } } } } -static void fill_wp_params(Slice *currSlice) -{ - if (currSlice->slice_type == B_SLICE) - { +static void fill_wp_params(Slice *currSlice) { + if (currSlice->slice_type == B_SLICE) { int i, j, k; int comp; int log_weight_denom; - int tb, td; - int tx,DistScaleFactor; + int tb, td; + int tx, DistScaleFactor; int max_l0_ref = currSlice->num_ref_idx_active[LIST_0]; int max_l1_ref = currSlice->num_ref_idx_active[LIST_1]; - if (currSlice->active_pps->weighted_bipred_idc == 2) - { + if (currSlice->active_pps->weighted_bipred_idc == 2) { currSlice->luma_log2_weight_denom = 5; currSlice->chroma_log2_weight_denom = 5; - currSlice->wp_round_luma = 16; + currSlice->wp_round_luma = 16; currSlice->wp_round_chroma = 16; - for (i=0; iluma_log2_weight_denom : currSlice->chroma_log2_weight_denom; + for (i = 0; i < MAX_REFERENCE_PICTURES; ++i) { + for (comp = 0; comp < 3; ++comp) { + log_weight_denom = (comp == 0) ? currSlice->luma_log2_weight_denom + : currSlice->chroma_log2_weight_denom; currSlice->wp_weight[0][i][comp] = 1 << log_weight_denom; currSlice->wp_weight[1][i][comp] = 1 << log_weight_denom; currSlice->wp_offset[0][i][comp] = 0; @@ -433,37 +428,37 @@ static void fill_wp_params(Slice *currSlice) } } - for (i=0; iluma_log2_weight_denom : currSlice->chroma_log2_weight_denom; - if (currSlice->active_pps->weighted_bipred_idc == 1) - { - currSlice->wbp_weight[0][i][j][comp] = currSlice->wp_weight[0][i][comp]; - currSlice->wbp_weight[1][i][j][comp] = currSlice->wp_weight[1][j][comp]; - } - else if (currSlice->active_pps->weighted_bipred_idc == 2) - { - td = iClip3(-128,127,currSlice->listX[LIST_1][j]->poc - currSlice->listX[LIST_0][i]->poc); - if (td == 0 || currSlice->listX[LIST_1][j]->is_long_term || currSlice->listX[LIST_0][i]->is_long_term) - { + for (i = 0; i < max_l0_ref; ++i) { + for (j = 0; j < max_l1_ref; ++j) { + for (comp = 0; comp < 3; ++comp) { + log_weight_denom = (comp == 0) ? currSlice->luma_log2_weight_denom + : currSlice->chroma_log2_weight_denom; + if (currSlice->active_pps->weighted_bipred_idc == 1) { + currSlice->wbp_weight[0][i][j][comp] = + currSlice->wp_weight[0][i][comp]; + currSlice->wbp_weight[1][i][j][comp] = + currSlice->wp_weight[1][j][comp]; + } else if (currSlice->active_pps->weighted_bipred_idc == 2) { + td = iClip3(-128, 127, + currSlice->listX[LIST_1][j]->poc - + currSlice->listX[LIST_0][i]->poc); + if (td == 0 || currSlice->listX[LIST_1][j]->is_long_term || + currSlice->listX[LIST_0][i]->is_long_term) { currSlice->wbp_weight[0][i][j][comp] = 32; currSlice->wbp_weight[1][i][j][comp] = 32; - } - else - { - tb = iClip3(-128,127,currSlice->ThisPOC - currSlice->listX[LIST_0][i]->poc); + } else { + tb = + iClip3(-128, 127, + currSlice->ThisPOC - currSlice->listX[LIST_0][i]->poc); - tx = (16384 + iabs(td/2))/td; - DistScaleFactor = iClip3(-1024, 1023, (tx*tb + 32 )>>6); + tx = (16384 + iabs(td / 2)) / td; + DistScaleFactor = iClip3(-1024, 1023, (tx * tb + 32) >> 6); currSlice->wbp_weight[1][i][j][comp] = DistScaleFactor >> 2; - currSlice->wbp_weight[0][i][j][comp] = 64 - currSlice->wbp_weight[1][i][j][comp]; - if (currSlice->wbp_weight[1][i][j][comp] < -64 || currSlice->wbp_weight[1][i][j][comp] > 128) - { + currSlice->wbp_weight[0][i][j][comp] = + 64 - currSlice->wbp_weight[1][i][j][comp]; + if (currSlice->wbp_weight[1][i][j][comp] < -64 || + currSlice->wbp_weight[1][i][j][comp] > 128) { currSlice->wbp_weight[0][i][j][comp] = 32; currSlice->wbp_weight[1][i][j][comp] = 32; currSlice->wp_offset[0][i][comp] = 0; @@ -475,48 +470,51 @@ static void fill_wp_params(Slice *currSlice) } } - if (currSlice->mb_aff_frame_flag) - { - for (i=0; i<2*max_l0_ref; ++i) - { - for (j=0; j<2*max_l1_ref; ++j) - { - for (comp = 0; comp<3; ++comp) - { - for (k=2; k<6; k+=2) - { - currSlice->wp_offset[k+0][i][comp] = currSlice->wp_offset[0][i>>1][comp]; - currSlice->wp_offset[k+1][j][comp] = currSlice->wp_offset[1][j>>1][comp]; + if (currSlice->mb_aff_frame_flag) { + for (i = 0; i < 2 * max_l0_ref; ++i) { + for (j = 0; j < 2 * max_l1_ref; ++j) { + for (comp = 0; comp < 3; ++comp) { + for (k = 2; k < 6; k += 2) { + currSlice->wp_offset[k + 0][i][comp] = + currSlice->wp_offset[0][i >> 1][comp]; + currSlice->wp_offset[k + 1][j][comp] = + currSlice->wp_offset[1][j >> 1][comp]; - log_weight_denom = (comp == 0) ? currSlice->luma_log2_weight_denom : currSlice->chroma_log2_weight_denom; - if (currSlice->active_pps->weighted_bipred_idc == 1) - { - currSlice->wbp_weight[k+0][i][j][comp] = currSlice->wp_weight[0][i>>1][comp]; - currSlice->wbp_weight[k+1][i][j][comp] = currSlice->wp_weight[1][j>>1][comp]; - } - else if (currSlice->active_pps->weighted_bipred_idc == 2) - { - td = iClip3(-128, 127, currSlice->listX[k+LIST_1][j]->poc - currSlice->listX[k+LIST_0][i]->poc); - if (td == 0 || currSlice->listX[k+LIST_1][j]->is_long_term || currSlice->listX[k+LIST_0][i]->is_long_term) - { - currSlice->wbp_weight[k+0][i][j][comp] = 32; - currSlice->wbp_weight[k+1][i][j][comp] = 32; - } - else - { - tb = iClip3(-128,127,((k==2)?currSlice->toppoc:currSlice->bottompoc) - currSlice->listX[k+LIST_0][i]->poc); + log_weight_denom = (comp == 0) + ? currSlice->luma_log2_weight_denom + : currSlice->chroma_log2_weight_denom; + if (currSlice->active_pps->weighted_bipred_idc == 1) { + currSlice->wbp_weight[k + 0][i][j][comp] = + currSlice->wp_weight[0][i >> 1][comp]; + currSlice->wbp_weight[k + 1][i][j][comp] = + currSlice->wp_weight[1][j >> 1][comp]; + } else if (currSlice->active_pps->weighted_bipred_idc == 2) { + td = iClip3(-128, 127, + currSlice->listX[k + LIST_1][j]->poc - + currSlice->listX[k + LIST_0][i]->poc); + if (td == 0 || currSlice->listX[k + LIST_1][j]->is_long_term || + currSlice->listX[k + LIST_0][i]->is_long_term) { + currSlice->wbp_weight[k + 0][i][j][comp] = 32; + currSlice->wbp_weight[k + 1][i][j][comp] = 32; + } else { + tb = iClip3( + -128, 127, + ((k == 2) ? currSlice->toppoc : currSlice->bottompoc) - + currSlice->listX[k + LIST_0][i]->poc); - tx = (16384 + iabs(td/2))/td; - DistScaleFactor = iClip3(-1024, 1023, (tx*tb + 32 )>>6); + tx = (16384 + iabs(td / 2)) / td; + DistScaleFactor = iClip3(-1024, 1023, (tx * tb + 32) >> 6); - currSlice->wbp_weight[k+1][i][j][comp] = DistScaleFactor >> 2; - currSlice->wbp_weight[k+0][i][j][comp] = 64 - currSlice->wbp_weight[k+1][i][j][comp]; - if (currSlice->wbp_weight[k+1][i][j][comp] < -64 || currSlice->wbp_weight[k+1][i][j][comp] > 128) - { - currSlice->wbp_weight[k+1][i][j][comp] = 32; - currSlice->wbp_weight[k+0][i][j][comp] = 32; - currSlice->wp_offset[k+0][i][comp] = 0; - currSlice->wp_offset[k+1][j][comp] = 0; + currSlice->wbp_weight[k + 1][i][j][comp] = + DistScaleFactor >> 2; + currSlice->wbp_weight[k + 0][i][j][comp] = + 64 - currSlice->wbp_weight[k + 1][i][j][comp]; + if (currSlice->wbp_weight[k + 1][i][j][comp] < -64 || + currSlice->wbp_weight[k + 1][i][j][comp] > 128) { + currSlice->wbp_weight[k + 1][i][j][comp] = 32; + currSlice->wbp_weight[k + 0][i][j][comp] = 32; + currSlice->wp_offset[k + 0][i][comp] = 0; + currSlice->wp_offset[k + 1][j][comp] = 0; } } } @@ -528,39 +526,39 @@ static void fill_wp_params(Slice *currSlice) } } - - -static void init_picture_decoding(VideoParameters *p_Vid) -{ +static void init_picture_decoding(VideoParameters *p_Vid) { Slice *pSlice = p_Vid->ppSliceList[0]; - int j, i, iSliceNo, iDeblockMode=1; + int j, i, iSliceNo, iDeblockMode = 1; Macroblock *pMBData; - if(p_Vid->iSliceNumOfCurrPic >= MAX_NUM_SLICES) - { - error ("Maximum number of supported slices exceeded. \nPlease recompile with increased value for MAX_NUM_SLICES", 200); + if (p_Vid->iSliceNumOfCurrPic >= MAX_NUM_SLICES) { + error("Maximum number of supported slices exceeded. \nPlease recompile " + "with increased value for MAX_NUM_SLICES", + 200); } - if(p_Vid->pNextPPS->Valid && (int) p_Vid->pNextPPS->pic_parameter_set_id == pSlice->pic_parameter_set_id) - { + if (p_Vid->pNextPPS->Valid && (int)p_Vid->pNextPPS->pic_parameter_set_id == + pSlice->pic_parameter_set_id) { pic_parameter_set_rbsp_t tmpPPS; - memcpy(&tmpPPS, p_Vid->active_pps, sizeof (pic_parameter_set_rbsp_t)); + memcpy(&tmpPPS, p_Vid->active_pps, sizeof(pic_parameter_set_rbsp_t)); p_Vid->active_pps->slice_group_id = NULL; - MakePPSavailable (p_Vid, p_Vid->pNextPPS->pic_parameter_set_id, p_Vid->pNextPPS); - memcpy(p_Vid->pNextPPS, &tmpPPS, sizeof (pic_parameter_set_rbsp_t)); + MakePPSavailable(p_Vid, p_Vid->pNextPPS->pic_parameter_set_id, + p_Vid->pNextPPS); + memcpy(p_Vid->pNextPPS, &tmpPPS, sizeof(pic_parameter_set_rbsp_t)); tmpPPS.slice_group_id = NULL; } - UseParameterSet (pSlice); - if(pSlice->idr_flag) - p_Vid->number=0; + UseParameterSet(pSlice); + if (pSlice->idr_flag) + p_Vid->number = 0; - p_Vid->PicHeightInMbs = p_Vid->FrameHeightInMbs / ( 1 + pSlice->field_pic_flag ); - p_Vid->PicSizeInMbs = p_Vid->PicWidthInMbs * p_Vid->PicHeightInMbs; + p_Vid->PicHeightInMbs = + p_Vid->FrameHeightInMbs / (1 + pSlice->field_pic_flag); + p_Vid->PicSizeInMbs = p_Vid->PicWidthInMbs * p_Vid->PicHeightInMbs; p_Vid->FrameSizeInMbs = p_Vid->PicWidthInMbs * p_Vid->FrameHeightInMbs; p_Vid->structure = pSlice->structure; - fmo_init (p_Vid, pSlice); + fmo_init(p_Vid, pSlice); #if (MVC_EXTENSION_ENABLE) update_ref_list(p_Vid->p_Dpb, pSlice->view_id); @@ -572,136 +570,133 @@ static void init_picture_decoding(VideoParameters *p_Vid) i = 0; #endif init_Deblock(p_Vid, pSlice->mb_aff_frame_flag); - //init mb_data; + // init mb_data; - for(j=0; jiSliceNumOfCurrPic; j++) - { - if(p_Vid->ppSliceList[j]->DFDisableIdc == 0) - iDeblockMode=0; + for (j = 0; j < p_Vid->iSliceNumOfCurrPic; j++) { + if (p_Vid->ppSliceList[j]->DFDisableIdc == 0) + iDeblockMode = 0; #if (MVC_EXTENSION_ENABLE) assert(p_Vid->ppSliceList[j]->view_id == i); #endif } p_Vid->iDeblockMode = iDeblockMode; - if(p_Vid->iDeblockMode == 1) - { - for(j=0; jiSliceNumOfCurrPic; j++) - { + if (p_Vid->iDeblockMode == 1) { + for (j = 0; j < p_Vid->iSliceNumOfCurrPic; j++) { pSlice = p_Vid->ppSliceList[j]; iSliceNo = pSlice->current_slice_nr; - if((p_Vid->separate_colour_plane_flag != 0)) + if ((p_Vid->separate_colour_plane_flag != 0)) pMBData = p_Vid->mb_data_JV[pSlice->colour_plane_id]; else pMBData = p_Vid->mb_data; - for(i = pSlice->start_mb_nr * (1 + pSlice->mb_aff_frame_flag); i < pSlice->end_mb_nr_plus1 * (1 + pSlice->mb_aff_frame_flag); i++) - pMBData[i].slice_nr = (short) iSliceNo; + for (i = pSlice->start_mb_nr * (1 + pSlice->mb_aff_frame_flag); + i < pSlice->end_mb_nr_plus1 * (1 + pSlice->mb_aff_frame_flag); i++) + pMBData[i].slice_nr = (short)iSliceNo; } } } -void init_slice(VideoParameters *p_Vid, Slice *currSlice) -{ +void init_slice(VideoParameters *p_Vid, Slice *currSlice) { int i; p_Vid->active_sps = currSlice->active_sps; p_Vid->active_pps = currSlice->active_pps; #if (MVC_EXTENSION_ENABLE) - //update_ref_list(p_Vid->p_Dpb, currSlice->view_id); - //update_ltref_list(p_Vid->p_Dpb, currSlice->view_id); - //update_pic_num(currSlice); + // update_ref_list(p_Vid->p_Dpb, currSlice->view_id); + // update_ltref_list(p_Vid->p_Dpb, currSlice->view_id); + // update_pic_num(currSlice); currSlice->init_lists(currSlice); if (currSlice->svc_extension_flag == 0 || currSlice->svc_extension_flag == 1) - reorder_lists_mvc (currSlice, currSlice->ThisPOC); + reorder_lists_mvc(currSlice, currSlice->ThisPOC); else - reorder_lists (currSlice); + reorder_lists(currSlice); - if (currSlice->fs_listinterview0) - { + if (currSlice->fs_listinterview0) { free(currSlice->fs_listinterview0); currSlice->fs_listinterview0 = NULL; } - if (currSlice->fs_listinterview1) - { + if (currSlice->fs_listinterview1) { free(currSlice->fs_listinterview1); currSlice->fs_listinterview1 = NULL; } #else - //update_pic_num(currSlice); - currSlice->init_lists (currSlice); - reorder_lists (currSlice); + // update_pic_num(currSlice); + currSlice->init_lists(currSlice); + reorder_lists(currSlice); #endif - if (currSlice->structure==FRAME) - { + if (currSlice->structure == FRAME) { init_mbaff_lists(p_Vid, currSlice); } - //p_Vid->recovery_point = 0; + // p_Vid->recovery_point = 0; // update reference flags and set current p_Vid->ref_flag - if(!(currSlice->redundant_pic_cnt != 0 && p_Vid->previous_frame_num == currSlice->frame_num)) - { - for(i=16;i>0;i--) - { - currSlice->ref_flag[i] = currSlice->ref_flag[i-1]; + if (!(currSlice->redundant_pic_cnt != 0 && + p_Vid->previous_frame_num == currSlice->frame_num)) { + for (i = 16; i > 0; i--) { + currSlice->ref_flag[i] = currSlice->ref_flag[i - 1]; } } - currSlice->ref_flag[0] = currSlice->redundant_pic_cnt==0 ? p_Vid->Is_primary_correct : p_Vid->Is_redundant_correct; - //p_Vid->previous_frame_num = currSlice->frame_num; //p_Vid->frame_num; + currSlice->ref_flag[0] = currSlice->redundant_pic_cnt == 0 + ? p_Vid->Is_primary_correct + : p_Vid->Is_redundant_correct; + // p_Vid->previous_frame_num = currSlice->frame_num; //p_Vid->frame_num; - if((currSlice->active_sps->chroma_format_idc==0)||(currSlice->active_sps->chroma_format_idc==3)) - { + if ((currSlice->active_sps->chroma_format_idc == 0) || + (currSlice->active_sps->chroma_format_idc == 3)) { currSlice->linfo_cbp_intra = linfo_cbp_intra_other; currSlice->linfo_cbp_inter = linfo_cbp_inter_other; - } - else - { + } else { currSlice->linfo_cbp_intra = linfo_cbp_intra_normal; currSlice->linfo_cbp_inter = linfo_cbp_inter_normal; } } -void decode_slice(Slice *currSlice, int current_header) -{ +void decode_slice(Slice *currSlice, int current_header) { VideoParameters *p_Vid = currSlice->p_Vid; - int iScale = (1+currSlice->mb_aff_frame_flag); - if (currSlice->active_pps->entropy_coding_mode_flag) - { - init_contexts (currSlice); + int iScale = (1 + currSlice->mb_aff_frame_flag); + if (currSlice->active_pps->entropy_coding_mode_flag) { + init_contexts(currSlice); cabac_new_slice(currSlice); } - if ( (currSlice->active_pps->weighted_bipred_idc > 0 && (currSlice->slice_type == B_SLICE)) || (currSlice->active_pps->weighted_pred_flag && currSlice->slice_type !=I_SLICE)) + if ((currSlice->active_pps->weighted_bipred_idc > 0 && + (currSlice->slice_type == B_SLICE)) || + (currSlice->active_pps->weighted_pred_flag && + currSlice->slice_type != I_SLICE)) fill_wp_params(currSlice); - //printf("frame picture %d %d %d\n",currSlice->structure,currSlice->ThisPOC,currSlice->direct_spatial_mv_pred_flag); + // printf("frame picture %d %d + // %d\n",currSlice->structure,currSlice->ThisPOC,currSlice->direct_spatial_mv_pred_flag); // decode main slice information - if ((current_header == SOP || current_header == SOS) && currSlice->ei_flag == 0) + if ((current_header == SOP || current_header == SOS) && + currSlice->ei_flag == 0) decode_one_slice(currSlice); // setMB-Nr in case this slice was lost // if(currSlice->ei_flag) // p_Vid->current_mb_nr = currSlice->last_mb_nr + 1; - //deblocking for frame or field - if(p_Vid->iDeblockMode && (p_Vid->bDeblockEnable & (1<<(p_Vid->dec_picture->used_for_reference)))) - { - if((p_Vid->separate_colour_plane_flag != 0) ) - { + // deblocking for frame or field + if (p_Vid->iDeblockMode && + (p_Vid->bDeblockEnable & + (1 << (p_Vid->dec_picture->used_for_reference)))) { + if ((p_Vid->separate_colour_plane_flag != 0)) { change_plane_JV(p_Vid, currSlice->colour_plane_id, currSlice); - DeblockPicturePartially(p_Vid, currSlice->dec_picture, currSlice->start_mb_nr*iScale, currSlice->end_mb_nr_plus1*iScale); - } - else - { - DeblockPicturePartially(p_Vid, currSlice->dec_picture, currSlice->start_mb_nr*iScale, currSlice->end_mb_nr_plus1*iScale); + DeblockPicturePartially(p_Vid, currSlice->dec_picture, + currSlice->start_mb_nr * iScale, + currSlice->end_mb_nr_plus1 * iScale); + } else { + DeblockPicturePartially(p_Vid, currSlice->dec_picture, + currSlice->start_mb_nr * iScale, + currSlice->end_mb_nr_plus1 * iScale); } } } - /*! ************************************************************************ * \brief @@ -709,44 +704,37 @@ void decode_slice(Slice *currSlice, int current_header) * current frame is lost, current frame is incorrect. ************************************************************************ */ -static void Error_tracking(VideoParameters *p_Vid, Slice *currSlice) -{ +static void Error_tracking(VideoParameters *p_Vid, Slice *currSlice) { int i; - if(currSlice->redundant_pic_cnt == 0) - { + if (currSlice->redundant_pic_cnt == 0) { p_Vid->Is_primary_correct = p_Vid->Is_redundant_correct = 1; } - if(currSlice->redundant_pic_cnt == 0 && p_Vid->type != I_SLICE) - { - for(i=0;inum_ref_idx_active[LIST_0];++i) - { - if(currSlice->ref_flag[i] == 0) // any reference of primary slice is incorrect + if (currSlice->redundant_pic_cnt == 0 && p_Vid->type != I_SLICE) { + for (i = 0; i < currSlice->num_ref_idx_active[LIST_0]; ++i) { + if (currSlice->ref_flag[i] == + 0) // any reference of primary slice is incorrect { p_Vid->Is_primary_correct = 0; // primary slice is incorrect } } - } - else if(currSlice->redundant_pic_cnt != 0 && p_Vid->type != I_SLICE) - { - if(currSlice->ref_flag[currSlice->redundant_slice_ref_idx] == 0) // reference of redundant slice is incorrect + } else if (currSlice->redundant_pic_cnt != 0 && p_Vid->type != I_SLICE) { + if (currSlice->ref_flag[currSlice->redundant_slice_ref_idx] == + 0) // reference of redundant slice is incorrect { - p_Vid->Is_redundant_correct = 0; // redundant slice is incorrect + p_Vid->Is_redundant_correct = 0; // redundant slice is incorrect } } } -static void CopyPOC(Slice *pSlice0, Slice *currSlice) -{ - currSlice->framepoc = pSlice0->framepoc; - currSlice->toppoc = pSlice0->toppoc; - currSlice->bottompoc = pSlice0->bottompoc; - currSlice->ThisPOC = pSlice0->ThisPOC; +static void CopyPOC(Slice *pSlice0, Slice *currSlice) { + currSlice->framepoc = pSlice0->framepoc; + currSlice->toppoc = pSlice0->toppoc; + currSlice->bottompoc = pSlice0->bottompoc; + currSlice->ThisPOC = pSlice0->ThisPOC; } - - /*! *********************************************************************** * \brief @@ -754,145 +742,146 @@ static void CopyPOC(Slice *pSlice0, Slice *currSlice) * *********************************************************************** */ -int decode_one_frame(DecoderParams *pDecoder) -{ +int decode_one_frame(DecoderParams *pDecoder) { VideoParameters *p_Vid = pDecoder->p_Vid; InputParameters *p_Inp = p_Vid->p_Inp; int current_header, iRet; Slice *currSlice; // = p_Vid->currentSlice; Slice **ppSliceList = p_Vid->ppSliceList; int iSliceNo; - - //read one picture first; - p_Vid->iSliceNumOfCurrPic=0; - current_header=0; - p_Vid->iNumOfSlicesDecoded=0; + + // read one picture first; + p_Vid->iSliceNumOfCurrPic = 0; + current_header = 0; + p_Vid->iNumOfSlicesDecoded = 0; p_Vid->num_dec_mb = 0; - if(p_Vid->newframe) - { - if(p_Vid->pNextPPS->Valid && (int) p_Vid->pNextPPS->pic_parameter_set_id == p_Vid->pNextSlice->pic_parameter_set_id) - { - MakePPSavailable (p_Vid, p_Vid->pNextPPS->pic_parameter_set_id, p_Vid->pNextPPS); - p_Vid->pNextPPS->Valid=0; + if (p_Vid->newframe) { + if (p_Vid->pNextPPS->Valid && (int)p_Vid->pNextPPS->pic_parameter_set_id == + p_Vid->pNextSlice->pic_parameter_set_id) { + MakePPSavailable(p_Vid, p_Vid->pNextPPS->pic_parameter_set_id, + p_Vid->pNextPPS); + p_Vid->pNextPPS->Valid = 0; } - //get the first slice from currentslice; + // get the first slice from currentslice; assert(ppSliceList[p_Vid->iSliceNumOfCurrPic]); currSlice = ppSliceList[p_Vid->iSliceNumOfCurrPic]; ppSliceList[p_Vid->iSliceNumOfCurrPic] = p_Vid->pNextSlice; p_Vid->pNextSlice = currSlice; assert(ppSliceList[p_Vid->iSliceNumOfCurrPic]->current_slice_nr == 0); - + currSlice = ppSliceList[p_Vid->iSliceNumOfCurrPic]; - UseParameterSet (currSlice); + UseParameterSet(currSlice); init_picture(p_Vid, currSlice, p_Inp); - + p_Vid->iSliceNumOfCurrPic++; current_header = SOS; } - while(current_header != SOP && current_header !=EOS) - { - //no pending slices; - assert(p_Vid->iSliceNumOfCurrPic < p_Vid->iNumOfSlicesAllocated); - if(!ppSliceList[p_Vid->iSliceNumOfCurrPic]) - { + while (current_header != SOP && current_header != EOS) { + // no pending slices; + assert(p_Vid->iSliceNumOfCurrPic < p_Vid->iNumOfSlicesAllocated); + if (!ppSliceList[p_Vid->iSliceNumOfCurrPic]) { ppSliceList[p_Vid->iSliceNumOfCurrPic] = malloc_slice(p_Inp, p_Vid); - } + } currSlice = ppSliceList[p_Vid->iSliceNumOfCurrPic]; - //p_Vid->currentSlice = currSlice; + // p_Vid->currentSlice = currSlice; currSlice->p_Vid = p_Vid; currSlice->p_Inp = p_Inp; currSlice->p_Dpb = p_Vid->p_Dpb; currSlice->next_header = -8888; currSlice->num_dec_mb = 0; currSlice->coeff_ctr = -1; - currSlice->pos = 0; + currSlice->pos = 0; currSlice->is_reset_coeff = FALSE; current_header = read_new_slice(currSlice); - //init; + // init; currSlice->current_header = current_header; // error tracking of primary and redundant slices. Error_tracking(p_Vid, currSlice); - // If primary and redundant are received and primary is correct, discard the redundant - // else, primary slice will be replaced with redundant slice. - if(currSlice->frame_num == p_Vid->previous_frame_num && currSlice->redundant_pic_cnt !=0 - && p_Vid->Is_primary_correct !=0 && current_header != EOS) - { + // If primary and redundant are received and primary is correct, discard the + // redundant else, primary slice will be replaced with redundant slice. + if (currSlice->frame_num == p_Vid->previous_frame_num && + currSlice->redundant_pic_cnt != 0 && p_Vid->Is_primary_correct != 0 && + current_header != EOS) { continue; } - if((current_header != SOP && current_header !=EOS) || (p_Vid->iSliceNumOfCurrPic==0 && current_header == SOP)) - { - currSlice->current_slice_nr = (short) p_Vid->iSliceNumOfCurrPic; - p_Vid->dec_picture->max_slice_id = (short) imax(currSlice->current_slice_nr, p_Vid->dec_picture->max_slice_id); - if(p_Vid->iSliceNumOfCurrPic >0) - { - CopyPOC(*ppSliceList, currSlice); - ppSliceList[p_Vid->iSliceNumOfCurrPic-1]->end_mb_nr_plus1 = currSlice->start_mb_nr; - } - p_Vid->iSliceNumOfCurrPic++; - if(p_Vid->iSliceNumOfCurrPic >= p_Vid->iNumOfSlicesAllocated) - { - Slice **tmpSliceList = (Slice **)realloc(p_Vid->ppSliceList, (p_Vid->iNumOfSlicesAllocated+MAX_NUM_DECSLICES)*sizeof(Slice*)); - if(!tmpSliceList) - { - tmpSliceList = calloc((p_Vid->iNumOfSlicesAllocated+MAX_NUM_DECSLICES), sizeof(Slice*)); - memcpy(tmpSliceList, p_Vid->ppSliceList, p_Vid->iSliceNumOfCurrPic*sizeof(Slice*)); - //free; - free(p_Vid->ppSliceList); - ppSliceList = p_Vid->ppSliceList = tmpSliceList; - } - else - { - //assert(tmpSliceList == p_Vid->ppSliceList); - ppSliceList = p_Vid->ppSliceList = tmpSliceList; - memset(p_Vid->ppSliceList+p_Vid->iSliceNumOfCurrPic, 0, sizeof(Slice*)*MAX_NUM_DECSLICES); - } - p_Vid->iNumOfSlicesAllocated += MAX_NUM_DECSLICES; - } - current_header = SOS; - } - else - { - if(ppSliceList[p_Vid->iSliceNumOfCurrPic-1]->mb_aff_frame_flag) - ppSliceList[p_Vid->iSliceNumOfCurrPic-1]->end_mb_nr_plus1 = p_Vid->FrameSizeInMbs/2; + if ((current_header != SOP && current_header != EOS) || + (p_Vid->iSliceNumOfCurrPic == 0 && current_header == SOP)) { + currSlice->current_slice_nr = (short)p_Vid->iSliceNumOfCurrPic; + p_Vid->dec_picture->max_slice_id = (short)imax( + currSlice->current_slice_nr, p_Vid->dec_picture->max_slice_id); + if (p_Vid->iSliceNumOfCurrPic > 0) { + CopyPOC(*ppSliceList, currSlice); + ppSliceList[p_Vid->iSliceNumOfCurrPic - 1]->end_mb_nr_plus1 = + currSlice->start_mb_nr; + } + p_Vid->iSliceNumOfCurrPic++; + if (p_Vid->iSliceNumOfCurrPic >= p_Vid->iNumOfSlicesAllocated) { + Slice **tmpSliceList = (Slice **)realloc( + p_Vid->ppSliceList, + (p_Vid->iNumOfSlicesAllocated + MAX_NUM_DECSLICES) * + sizeof(Slice *)); + if (!tmpSliceList) { + tmpSliceList = + calloc((p_Vid->iNumOfSlicesAllocated + MAX_NUM_DECSLICES), + sizeof(Slice *)); + memcpy(tmpSliceList, p_Vid->ppSliceList, + p_Vid->iSliceNumOfCurrPic * sizeof(Slice *)); + // free; + free(p_Vid->ppSliceList); + ppSliceList = p_Vid->ppSliceList = tmpSliceList; + } else { + // assert(tmpSliceList == p_Vid->ppSliceList); + ppSliceList = p_Vid->ppSliceList = tmpSliceList; + memset(p_Vid->ppSliceList + p_Vid->iSliceNumOfCurrPic, 0, + sizeof(Slice *) * MAX_NUM_DECSLICES); + } + p_Vid->iNumOfSlicesAllocated += MAX_NUM_DECSLICES; + } + current_header = SOS; + } else { + if (ppSliceList[p_Vid->iSliceNumOfCurrPic - 1]->mb_aff_frame_flag) + ppSliceList[p_Vid->iSliceNumOfCurrPic - 1]->end_mb_nr_plus1 = + p_Vid->FrameSizeInMbs / 2; else - ppSliceList[p_Vid->iSliceNumOfCurrPic-1]->end_mb_nr_plus1 = p_Vid->FrameSizeInMbs/(1+ppSliceList[p_Vid->iSliceNumOfCurrPic-1]->field_pic_flag); - p_Vid->newframe = 1; - currSlice->current_slice_nr = 0; - //keep it in currentslice; - ppSliceList[p_Vid->iSliceNumOfCurrPic] = p_Vid->pNextSlice; - p_Vid->pNextSlice = currSlice; + ppSliceList[p_Vid->iSliceNumOfCurrPic - 1]->end_mb_nr_plus1 = + p_Vid->FrameSizeInMbs / + (1 + ppSliceList[p_Vid->iSliceNumOfCurrPic - 1]->field_pic_flag); + p_Vid->newframe = 1; + currSlice->current_slice_nr = 0; + // keep it in currentslice; + ppSliceList[p_Vid->iSliceNumOfCurrPic] = p_Vid->pNextSlice; + p_Vid->pNextSlice = currSlice; } CopySliceInfo(currSlice, p_Vid->old_slice); } iRet = current_header; - init_picture_decoding(p_Vid); + init_picture_decoding(p_Vid); - { - for(iSliceNo=0; iSliceNoiSliceNumOfCurrPic; iSliceNo++) - { - currSlice = ppSliceList[iSliceNo]; - current_header = currSlice->current_header; - //p_Vid->currentSlice = currSlice; - - assert(current_header != EOS); - assert(currSlice->current_slice_nr == iSliceNo); - - init_slice(p_Vid, currSlice); - decode_slice(currSlice, current_header); + { + for (iSliceNo = 0; iSliceNo < p_Vid->iSliceNumOfCurrPic; iSliceNo++) { + currSlice = ppSliceList[iSliceNo]; + current_header = currSlice->current_header; + // p_Vid->currentSlice = currSlice; - p_Vid->iNumOfSlicesDecoded++; - p_Vid->num_dec_mb += currSlice->num_dec_mb; - p_Vid->erc_mvperMB += currSlice->erc_mvperMB; - } - } - exit_picture(p_Vid, &p_Vid->dec_picture); + assert(current_header != EOS); + assert(currSlice->current_slice_nr == iSliceNo); + + init_slice(p_Vid, currSlice); + decode_slice(currSlice, current_header); + + p_Vid->iNumOfSlicesDecoded++; + p_Vid->num_dec_mb += currSlice->num_dec_mb; + p_Vid->erc_mvperMB += currSlice->erc_mvperMB; + } + } + exit_picture(p_Vid, &p_Vid->dec_picture); p_Vid->previous_frame_num = ppSliceList[0]->frame_num; return (iRet); } @@ -913,119 +902,101 @@ int decode_one_frame(DecoderParams *pDecoder) * number of bytes used per pel ************************************************************************ */ -void buffer2img (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int symbol_size_in_bytes) -{ - int i,j; +void buffer2img(imgpel **imgX, unsigned char *buf, int size_x, int size_y, + int symbol_size_in_bytes) { + int i, j; uint16 tmp16, ui16; - unsigned long tmp32, ui32; + unsigned long tmp32, ui32; - if (symbol_size_in_bytes> (int) sizeof(imgpel)) - { - error ("Source picture has higher bit depth than imgpel data type. \nPlease recompile with larger data type for imgpel.", 500); + if (symbol_size_in_bytes > (int)sizeof(imgpel)) { + error("Source picture has higher bit depth than imgpel data type. \nPlease " + "recompile with larger data type for imgpel.", + 500); } - if (( sizeof(char) == sizeof (imgpel)) && ( sizeof(char) == symbol_size_in_bytes)) - { + if ((sizeof(char) == sizeof(imgpel)) && + (sizeof(char) == symbol_size_in_bytes)) { // imgpel == pixel_in_file == 1 byte -> simple copy fast_memcpy(&imgX[0][0], buf, size_x * size_y); - } - else - { + } else { // sizeof (imgpel) > sizeof(char) - if (testEndian()) - { + if (testEndian()) { // big endian - switch (symbol_size_in_bytes) - { - case 1: - { - for(j = 0; j < size_y; ++j) - for(i = 0; i < size_x; ++i) - { - imgX[j][i]= buf[i+j*size_x]; - } - break; - } - case 2: - { - for(j=0;j> 8) | ((tmp16&0xFF)<<8)); - imgX[j][i] = (imgpel) ui16; - } - break; - } - case 4: - { - for(j=0;j>8) | ((tmp32&0xFF000000)>>24); - imgX[j][i] = (imgpel) ui32; - } - } - default: - { - error ("reading only from formats of 8, 16 or 32 bit allowed on big endian architecture", 500); - break; - } + switch (symbol_size_in_bytes) { + case 1: { + for (j = 0; j < size_y; ++j) + for (i = 0; i < size_x; ++i) { + imgX[j][i] = buf[i + j * size_x]; + } + break; + } + case 2: { + for (j = 0; j < size_y; ++j) + for (i = 0; i < size_x; ++i) { + memcpy(&tmp16, buf + ((i + j * size_x) * 2), 2); + ui16 = (uint16)((tmp16 >> 8) | ((tmp16 & 0xFF) << 8)); + imgX[j][i] = (imgpel)ui16; + } + break; + } + case 4: { + for (j = 0; j < size_y; ++j) + for (i = 0; i < size_x; ++i) { + memcpy(&tmp32, buf + ((i + j * size_x) * 4), 4); + ui32 = ((tmp32 & 0xFF00) << 8) | ((tmp32 & 0xFF) << 24) | + ((tmp32 & 0xFF0000) >> 8) | ((tmp32 & 0xFF000000) >> 24); + imgX[j][i] = (imgpel)ui32; + } + } + default: { + error("reading only from formats of 8, 16 or 32 bit allowed on big " + "endian architecture", + 500); + break; + } } - } - else - { + } else { // little endian - if (symbol_size_in_bytes == 1) - { - for (j=0; j < size_y; ++j) - { - for (i=0; i < size_x; ++i) - { - imgX[j][i]=*(buf++); + if (symbol_size_in_bytes == 1) { + for (j = 0; j < size_y; ++j) { + for (i = 0; i < size_x; ++i) { + imgX[j][i] = *(buf++); + } + } + } else { + for (j = 0; j < size_y; ++j) { + int jpos = j * size_x; + for (i = 0; i < size_x; ++i) { + imgX[j][i] = 0; + memcpy(&(imgX[j][i]), buf + ((i + jpos) * symbol_size_in_bytes), + symbol_size_in_bytes); } } } - else - { - for (j=0; j < size_y; ++j) - { - int jpos = j*size_x; - for (i=0; i < size_x; ++i) - { - imgX[j][i]=0; - memcpy(&(imgX[j][i]), buf +((i+jpos)*symbol_size_in_bytes), symbol_size_in_bytes); - } - } - } - } } } - /*! *********************************************************************** * \brief * compute generic SSE *********************************************************************** */ -int64 compute_SSE(imgpel **imgRef, imgpel **imgSrc, int xRef, int xSrc, int ySize, int xSize) -{ +int64 compute_SSE(imgpel **imgRef, imgpel **imgSrc, int xRef, int xSrc, + int ySize, int xSize) { int i, j; imgpel *lineRef, *lineSrc; int64 distortion = 0; - for (j = 0; j < ySize; j++) - { - lineRef = &imgRef[j][xRef]; + for (j = 0; j < ySize; j++) { + lineRef = &imgRef[j][xRef]; lineSrc = &imgSrc[j][xSrc]; for (i = 0; i < xSize; i++) - distortion += iabs2( *lineRef++ - *lineSrc++ ); + distortion += iabs2(*lineRef++ - *lineSrc++); } return distortion; } @@ -1035,23 +1006,25 @@ int64 compute_SSE(imgpel **imgRef, imgpel **imgSrc, int xRef, int xSrc, int ySiz * \brief * Calculate the value of frame_no ************************************************************************ -*/ -void calculate_frame_no(VideoParameters *p_Vid, StorablePicture *p) -{ + */ +void calculate_frame_no(VideoParameters *p_Vid, StorablePicture *p) { InputParameters *p_Inp = p_Vid->p_Inp; // calculate frame number - int psnrPOC = p_Vid->active_sps->mb_adaptive_frame_field_flag ? p->poc /(p_Inp->poc_scale) : p->poc/(p_Inp->poc_scale); - - if (psnrPOC==0)// && p_Vid->psnr_number) + int psnrPOC = p_Vid->active_sps->mb_adaptive_frame_field_flag + ? p->poc / (p_Inp->poc_scale) + : p->poc / (p_Inp->poc_scale); + + if (psnrPOC == 0) // && p_Vid->psnr_number) { - p_Vid->idr_psnr_number = p_Vid->number*p_Vid->ref_poc_gap/(p_Inp->poc_scale); + p_Vid->idr_psnr_number = + p_Vid->number * p_Vid->ref_poc_gap / (p_Inp->poc_scale); } - p_Vid->psnr_number=imax(p_Vid->psnr_number,p_Vid->idr_psnr_number+psnrPOC); + p_Vid->psnr_number = + imax(p_Vid->psnr_number, p_Vid->idr_psnr_number + psnrPOC); p_Vid->frame_no = p_Vid->idr_psnr_number + psnrPOC; } - /*! ************************************************************************ * \brief @@ -1065,200 +1038,220 @@ void calculate_frame_no(VideoParameters *p_Vid, StorablePicture *p) * file pointer piont to reference YUV reference file ************************************************************************ */ -void find_snr(VideoParameters *p_Vid, - StorablePicture *p, - int *p_ref) -{ +void find_snr(VideoParameters *p_Vid, StorablePicture *p, int *p_ref) { InputParameters *p_Inp = p_Vid->p_Inp; - SNRParameters *snr = p_Vid->snr; + SNRParameters *snr = p_Vid->snr; int k; int ret; int64 diff_comp[3] = {0}; - int64 status; + int64 status; int symbol_size_in_bytes = (p_Vid->pic_unit_bitsize_on_disk >> 3); int comp_size_x[3], comp_size_y[3]; int64 framesize_in_bytes; unsigned int max_pix_value_sqd[3]; - Boolean rgb_output = (Boolean) (p_Vid->active_sps->vui_seq_parameters.matrix_coefficients==0); + Boolean rgb_output = + (Boolean)(p_Vid->active_sps->vui_seq_parameters.matrix_coefficients == 0); unsigned char *buf; - imgpel **cur_ref [3]; - imgpel **cur_comp[3]; + imgpel **cur_ref[3]; + imgpel **cur_comp[3]; // picture error concealment - char yuv_types[4][6]= {"4:0:0","4:2:0","4:2:2","4:4:4"}; + char yuv_types[4][6] = {"4:0:0", "4:2:0", "4:2:2", "4:4:4"}; max_pix_value_sqd[0] = iabs2(p_Vid->max_pel_value_comp[0]); max_pix_value_sqd[1] = iabs2(p_Vid->max_pel_value_comp[1]); max_pix_value_sqd[2] = iabs2(p_Vid->max_pel_value_comp[2]); - cur_ref[0] = p_Vid->imgY_ref; - cur_ref[1] = p->chroma_format_idc != YUV400 ? p_Vid->imgUV_ref[0] : NULL; - cur_ref[2] = p->chroma_format_idc != YUV400 ? p_Vid->imgUV_ref[1] : NULL; + cur_ref[0] = p_Vid->imgY_ref; + cur_ref[1] = p->chroma_format_idc != YUV400 ? p_Vid->imgUV_ref[0] : NULL; + cur_ref[2] = p->chroma_format_idc != YUV400 ? p_Vid->imgUV_ref[1] : NULL; cur_comp[0] = p->imgY; - cur_comp[1] = p->chroma_format_idc != YUV400 ? p->imgUV[0] : NULL; - cur_comp[2] = p->chroma_format_idc!= YUV400 ? p->imgUV[1] : NULL; + cur_comp[1] = p->chroma_format_idc != YUV400 ? p->imgUV[0] : NULL; + cur_comp[2] = p->chroma_format_idc != YUV400 ? p->imgUV[1] : NULL; comp_size_x[0] = p_Inp->source.width[0]; comp_size_y[0] = p_Inp->source.height[0]; comp_size_x[1] = comp_size_x[2] = p_Inp->source.width[1]; comp_size_y[1] = comp_size_y[2] = p_Inp->source.height[1]; - framesize_in_bytes = (((int64) comp_size_x[0] * comp_size_y[0]) + ((int64) comp_size_x[1] * comp_size_y[1] ) * 2) * symbol_size_in_bytes; + framesize_in_bytes = (((int64)comp_size_x[0] * comp_size_y[0]) + + ((int64)comp_size_x[1] * comp_size_y[1]) * 2) * + symbol_size_in_bytes; - // KS: this buffer should actually be allocated only once, but this is still much faster than the previous version - buf = malloc ( comp_size_x[0] * comp_size_y[0] * symbol_size_in_bytes ); + // KS: this buffer should actually be allocated only once, but this is still + // much faster than the previous version + buf = malloc(comp_size_x[0] * comp_size_y[0] * symbol_size_in_bytes); - if (NULL == buf) - { + if (NULL == buf) { no_mem_exit("find_snr: buf"); } - status = lseek (*p_ref, framesize_in_bytes * p_Vid->frame_no, SEEK_SET); - if (status == -1) - { - fprintf(stderr, "Warning: Could not seek to frame number %d in reference file. Shown PSNR might be wrong.\n", p_Vid->frame_no); - free (buf); + status = lseek(*p_ref, framesize_in_bytes * p_Vid->frame_no, SEEK_SET); + if (status == -1) { + fprintf(stderr, + "Warning: Could not seek to frame number %d in reference file. " + "Shown PSNR might be wrong.\n", + p_Vid->frame_no); + free(buf); return; } - if(rgb_output) - lseek (*p_ref, framesize_in_bytes/3, SEEK_CUR); + if (rgb_output) + lseek(*p_ref, framesize_in_bytes / 3, SEEK_CUR); - for (k = 0; k < ((p->chroma_format_idc != YUV400) ? 3 : 1); ++k) - { + for (k = 0; k < ((p->chroma_format_idc != YUV400) ? 3 : 1); ++k) { - if(rgb_output && k == 2) - lseek (*p_ref, -framesize_in_bytes, SEEK_CUR); + if (rgb_output && k == 2) + lseek(*p_ref, -framesize_in_bytes, SEEK_CUR); - ret = read(*p_ref, buf, comp_size_x[k] * comp_size_y[k] * symbol_size_in_bytes); - if (ret != comp_size_x[k] * comp_size_y[k] * symbol_size_in_bytes) - { - printf ("Warning: could not read from reconstructed file\n"); - memset (buf, 0, comp_size_x[k] * comp_size_y[k] * symbol_size_in_bytes); + ret = read(*p_ref, buf, + comp_size_x[k] * comp_size_y[k] * symbol_size_in_bytes); + if (ret != comp_size_x[k] * comp_size_y[k] * symbol_size_in_bytes) { + printf("Warning: could not read from reconstructed file\n"); + memset(buf, 0, comp_size_x[k] * comp_size_y[k] * symbol_size_in_bytes); close(*p_ref); *p_ref = -1; break; } - buffer2img(cur_ref[k], buf, comp_size_x[k], comp_size_y[k], symbol_size_in_bytes); + buffer2img(cur_ref[k], buf, comp_size_x[k], comp_size_y[k], + symbol_size_in_bytes); // Compute SSE - diff_comp[k] = compute_SSE(cur_ref[k], cur_comp[k], 0, 0, comp_size_y[k], comp_size_x[k]); + diff_comp[k] = compute_SSE(cur_ref[k], cur_comp[k], 0, 0, comp_size_y[k], + comp_size_x[k]); // Collecting SNR statistics - snr->snr[k] = psnr( max_pix_value_sqd[k], comp_size_x[k] * comp_size_y[k], (float) diff_comp[k]); + snr->snr[k] = psnr(max_pix_value_sqd[k], comp_size_x[k] * comp_size_y[k], + (float)diff_comp[k]); if (snr->frame_ctr == 0) // first { - snr->snra[k] = snr->snr[k]; // keep luma snr for first frame - } - else - { - snr->snra[k] = (float)(snr->snra[k]*(snr->frame_ctr)+snr->snr[k])/(snr->frame_ctr + 1); // average snr chroma for all frames + snr->snra[k] = snr->snr[k]; // keep luma snr for first frame + } else { + snr->snra[k] = (float)(snr->snra[k] * (snr->frame_ctr) + snr->snr[k]) / + (snr->frame_ctr + 1); // average snr chroma for all frames } } - if(rgb_output) - lseek (*p_ref, framesize_in_bytes * 2 / 3, SEEK_CUR); + if (rgb_output) + lseek(*p_ref, framesize_in_bytes * 2 / 3, SEEK_CUR); - free (buf); + free(buf); // picture error concealment - if(p->concealed_pic) - { - fprintf(stdout,"%04d(P) %8d %5d %5d %7.4f %7.4f %7.4f %s %5d\n", - p_Vid->frame_no, p->frame_poc, p->pic_num, p->qp, - snr->snr[0], snr->snr[1], snr->snr[2], yuv_types[p->chroma_format_idc], 0); + if (p->concealed_pic) { + fprintf(stdout, "%04d(P) %8d %5d %5d %7.4f %7.4f %7.4f %s %5d\n", + p_Vid->frame_no, p->frame_poc, p->pic_num, p->qp, snr->snr[0], + snr->snr[1], snr->snr[2], yuv_types[p->chroma_format_idc], 0); } } - -void reorder_lists(Slice *currSlice) -{ +void reorder_lists(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; - if ((currSlice->slice_type != I_SLICE)&&(currSlice->slice_type != SI_SLICE)) - { - if (currSlice->ref_pic_list_reordering_flag[LIST_0]) - { + if ((currSlice->slice_type != I_SLICE) && + (currSlice->slice_type != SI_SLICE)) { + if (currSlice->ref_pic_list_reordering_flag[LIST_0]) { reorder_ref_pic_list(currSlice, LIST_0); } - if (p_Vid->no_reference_picture == currSlice->listX[0][currSlice->num_ref_idx_active[LIST_0] - 1]) - { + if (p_Vid->no_reference_picture == + currSlice->listX[0][currSlice->num_ref_idx_active[LIST_0] - 1]) { if (p_Vid->non_conforming_stream) - printf("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no reference picture'\n"); + printf("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no " + "reference picture'\n"); else - error("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no reference picture', invalid bitstream",500); + error("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no " + "reference picture', invalid bitstream", + 500); } // that's a definition - currSlice->listXsize[0] = (signed char) currSlice->num_ref_idx_active[LIST_0]; + currSlice->listXsize[0] = + (signed char)currSlice->num_ref_idx_active[LIST_0]; } - if (currSlice->slice_type == B_SLICE) - { - if (currSlice->ref_pic_list_reordering_flag[LIST_1]) - { + if (currSlice->slice_type == B_SLICE) { + if (currSlice->ref_pic_list_reordering_flag[LIST_1]) { reorder_ref_pic_list(currSlice, LIST_1); } - if (p_Vid->no_reference_picture == currSlice->listX[1][currSlice->num_ref_idx_active[LIST_1]-1]) - { + if (p_Vid->no_reference_picture == + currSlice->listX[1][currSlice->num_ref_idx_active[LIST_1] - 1]) { if (p_Vid->non_conforming_stream) - printf("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no reference picture'\n"); + printf("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no " + "reference picture'\n"); else - error("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no reference picture', invalid bitstream",500); + error("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no " + "reference picture', invalid bitstream", + 500); } // that's a definition - currSlice->listXsize[1] = (signed char) currSlice->num_ref_idx_active[LIST_1]; + currSlice->listXsize[1] = + (signed char)currSlice->num_ref_idx_active[LIST_1]; } free_ref_pic_list_reordering_buffer(currSlice); - if ( currSlice->slice_type == P_SLICE ) - { + if (currSlice->slice_type == P_SLICE) { #if PRINTREFLIST unsigned int i; #if (MVC_EXTENSION_ENABLE) // print out for debug purpose - if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && currSlice->current_slice_nr==0) - { - if(currSlice->listXsize[0]>0) - { + if ((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && + currSlice->current_slice_nr == 0) { + if (currSlice->listXsize[0] > 0) { printf("\n"); - printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[0]); i++) //ref list 0 + printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", + currSlice->view_id, + currSlice->structure == FRAME + ? "FRM" + : (currSlice->structure == TOP_FIELD ? "TOP" : "BOT")); + for (i = 0; i < (unsigned int)(currSlice->listXsize[0]); + i++) // ref list 0 { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, currSlice->listX[0][i]->view_id); + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, + currSlice->listX[0][i]->view_id); } } } #endif #endif - } - else if ( currSlice->slice_type == B_SLICE ) - { + } else if (currSlice->slice_type == B_SLICE) { #if PRINTREFLIST unsigned int i; #if (MVC_EXTENSION_ENABLE) // print out for debug purpose - if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && currSlice->current_slice_nr==0) - { - if((currSlice->listXsize[0]>0) || (currSlice->listXsize[1]>0)) + if ((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && + currSlice->current_slice_nr == 0) { + if ((currSlice->listXsize[0] > 0) || (currSlice->listXsize[1] > 0)) printf("\n"); - if(currSlice->listXsize[0]>0) - { - printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[0]); i++) //ref list 0 + if (currSlice->listXsize[0] > 0) { + printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", + currSlice->view_id, + currSlice->structure == FRAME + ? "FRM" + : (currSlice->structure == TOP_FIELD ? "TOP" : "BOT")); + for (i = 0; i < (unsigned int)(currSlice->listXsize[0]); + i++) // ref list 0 { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, currSlice->listX[0][i]->view_id); + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, + currSlice->listX[0][i]->view_id); } } - if(currSlice->listXsize[1]>0) - { - printf(" ** (CurViewID:%d) %s Ref Pic List 1 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[1]); i++) //ref list 1 + if (currSlice->listXsize[1] > 0) { + printf(" ** (CurViewID:%d) %s Ref Pic List 1 ****\n", + currSlice->view_id, + currSlice->structure == FRAME + ? "FRM" + : (currSlice->structure == TOP_FIELD ? "TOP" : "BOT")); + for (i = 0; i < (unsigned int)(currSlice->listXsize[1]); + i++) // ref list 1 { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[1][i]->poc, currSlice->listX[1][i]->pic_num, currSlice->listX[1][i]->view_id); + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[1][i]->poc, currSlice->listX[1][i]->pic_num, + currSlice->listX[1][i]->view_id); } } } @@ -1268,30 +1261,25 @@ void reorder_lists(Slice *currSlice) } } - - - /*! ************************************************************************ * \brief * Reads new slice from bit_stream ************************************************************************ */ -int read_new_slice(Slice *currSlice) -{ +int read_new_slice(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; InputParameters *p_Inp = currSlice->p_Inp; - NALU_t *nalu = p_Vid->nalu; + NALU_t *nalu = p_Vid->nalu; int current_header = 0; int BitsUsedByHeader; Bitstream *currStream = NULL; int slice_id_a, slice_id_b, slice_id_c; - int redundant_pic_cnt_b, redundant_pic_cnt_c; + int redundant_pic_cnt_b, redundant_pic_cnt_c; - for (;;) - { + for (;;) { #if (MVC_EXTENSION_ENABLE) currSlice->svc_extension_flag = -1; #endif @@ -1299,56 +1287,49 @@ int read_new_slice(Slice *currSlice) return EOS; #if (MVC_EXTENSION_ENABLE) - if(p_Inp->DecodeAllLayers == 1 && (nalu->nal_unit_type == NALU_TYPE_PREFIX || nalu->nal_unit_type == NALU_TYPE_SLC_EXT)) - { + if (p_Inp->DecodeAllLayers == 1 && + (nalu->nal_unit_type == NALU_TYPE_PREFIX || + nalu->nal_unit_type == NALU_TYPE_SLC_EXT)) { currStream = currSlice->partArr[0].bitstream; currStream->ei_flag = 0; currStream->frame_bitoffset = currStream->read_len = 0; - fast_memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); - currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1); + fast_memcpy(currStream->streamBuffer, &nalu->buf[1], nalu->len - 1); + currStream->code_len = currStream->bitstream_length = + RBSPtoSODB(currStream->streamBuffer, nalu->len - 1); - currSlice->svc_extension_flag = u_1 ("svc_extension_flag" , currStream); + currSlice->svc_extension_flag = u_1("svc_extension_flag", currStream); - if(currSlice->svc_extension_flag) - { + if (currSlice->svc_extension_flag) { nal_unit_header_svc_extension(); - } - else - { + } else { nal_unit_header_mvc_extension(&currSlice->NaluHeaderMVCExt, currStream); - currSlice->NaluHeaderMVCExt.iPrefixNALU = (nalu->nal_unit_type == NALU_TYPE_PREFIX); + currSlice->NaluHeaderMVCExt.iPrefixNALU = + (nalu->nal_unit_type == NALU_TYPE_PREFIX); } - if(nalu->nal_unit_type == NALU_TYPE_SLC_EXT) - { - if(currSlice->svc_extension_flag) - { - //to be implemented for Annex G; - } - else - { - nalu->nal_unit_type = currSlice->NaluHeaderMVCExt.non_idr_flag==0? NALU_TYPE_IDR: NALU_TYPE_SLICE; + if (nalu->nal_unit_type == NALU_TYPE_SLC_EXT) { + if (currSlice->svc_extension_flag) { + // to be implemented for Annex G; + } else { + nalu->nal_unit_type = currSlice->NaluHeaderMVCExt.non_idr_flag == 0 + ? NALU_TYPE_IDR + : NALU_TYPE_SLICE; } } } #endif -process_nalu: - switch (nalu->nal_unit_type) - { + process_nalu: + switch (nalu->nal_unit_type) { case NALU_TYPE_SLICE: case NALU_TYPE_IDR: - if (p_Vid->recovery_point || nalu->nal_unit_type == NALU_TYPE_IDR) - { - if (p_Vid->recovery_point_found == 0) - { - if (nalu->nal_unit_type != NALU_TYPE_IDR) - { + if (p_Vid->recovery_point || nalu->nal_unit_type == NALU_TYPE_IDR) { + if (p_Vid->recovery_point_found == 0) { + if (nalu->nal_unit_type != NALU_TYPE_IDR) { printf("Warning: Decoding does not start with an IDR picture.\n"); p_Vid->non_conforming_stream = 1; - } - else + } else p_Vid->non_conforming_stream = 0; } p_Vid->recovery_point_found = 1; @@ -1362,168 +1343,165 @@ process_nalu: currSlice->dp_mode = PAR_DP_1; currSlice->max_part_nr = 1; #if (MVC_EXTENSION_ENABLE) - if (currSlice->svc_extension_flag != 0) - { + if (currSlice->svc_extension_flag != 0) { currStream = currSlice->partArr[0].bitstream; currStream->ei_flag = 0; currStream->frame_bitoffset = currStream->read_len = 0; - fast_memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); - currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1); + fast_memcpy(currStream->streamBuffer, &nalu->buf[1], nalu->len - 1); + currStream->code_len = currStream->bitstream_length = + RBSPtoSODB(currStream->streamBuffer, nalu->len - 1); } -#else +#else currStream = currSlice->partArr[0].bitstream; currStream->ei_flag = 0; currStream->frame_bitoffset = currStream->read_len = 0; - memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); - currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1); + memcpy(currStream->streamBuffer, &nalu->buf[1], nalu->len - 1); + currStream->code_len = currStream->bitstream_length = + RBSPtoSODB(currStream->streamBuffer, nalu->len - 1); #endif - // Some syntax of the Slice Header depends on the parameter set, which depends on - // the parameter set ID of the SLice header. Hence, read the pic_parameter_set_id - // of the slice header first, then setup the active parameter sets, and then read - // the rest of the slice header + // Some syntax of the Slice Header depends on the parameter set, which + // depends on the parameter set ID of the SLice header. Hence, read the + // pic_parameter_set_id of the slice header first, then setup the active + // parameter sets, and then read the rest of the slice header BitsUsedByHeader = FirstPartOfSliceHeader(currSlice); - UseParameterSet (currSlice); + UseParameterSet(currSlice); currSlice->active_sps = p_Vid->active_sps; currSlice->active_pps = p_Vid->active_pps; currSlice->Transform8x8Mode = p_Vid->active_pps->transform_8x8_mode_flag; - currSlice->is_not_independent = (p_Vid->active_sps->chroma_format_idc==YUV444)&&((p_Vid->separate_colour_plane_flag == 0)); + currSlice->is_not_independent = + (p_Vid->active_sps->chroma_format_idc == YUV444) && + ((p_Vid->separate_colour_plane_flag == 0)); - BitsUsedByHeader += RestOfSliceHeader (currSlice); + BitsUsedByHeader += RestOfSliceHeader(currSlice); #if (MVC_EXTENSION_ENABLE) - if(currSlice->svc_extension_flag == 0) - { //MVC + if (currSlice->svc_extension_flag == 0) { // MVC currSlice->view_id = currSlice->NaluHeaderMVCExt.view_id; - currSlice->inter_view_flag = currSlice->NaluHeaderMVCExt.inter_view_flag; - currSlice->anchor_pic_flag = currSlice->NaluHeaderMVCExt.anchor_pic_flag; - } - else if(currSlice->svc_extension_flag == -1) //SVC and the normal AVC; - { - if(p_Vid->active_subset_sps == NULL) - { + currSlice->inter_view_flag = + currSlice->NaluHeaderMVCExt.inter_view_flag; + currSlice->anchor_pic_flag = + currSlice->NaluHeaderMVCExt.anchor_pic_flag; + } else if (currSlice->svc_extension_flag == -1) // SVC and the normal AVC; + { + if (p_Vid->active_subset_sps == NULL) { currSlice->view_id = GetBaseViewId(p_Vid, &p_Vid->active_subset_sps); - if(currSlice->NaluHeaderMVCExt.iPrefixNALU >0) - { + if (currSlice->NaluHeaderMVCExt.iPrefixNALU > 0) { assert(currSlice->view_id == currSlice->NaluHeaderMVCExt.view_id); - currSlice->inter_view_flag = currSlice->NaluHeaderMVCExt.inter_view_flag; - currSlice->anchor_pic_flag = currSlice->NaluHeaderMVCExt.anchor_pic_flag; - } - else - { + currSlice->inter_view_flag = + currSlice->NaluHeaderMVCExt.inter_view_flag; + currSlice->anchor_pic_flag = + currSlice->NaluHeaderMVCExt.anchor_pic_flag; + } else { currSlice->inter_view_flag = 1; currSlice->anchor_pic_flag = currSlice->idr_flag; } - } - else - { - assert(p_Vid->active_subset_sps->num_views_minus1 >=0); + } else { + assert(p_Vid->active_subset_sps->num_views_minus1 >= 0); // prefix NALU available - if(currSlice->NaluHeaderMVCExt.iPrefixNALU >0) - { + if (currSlice->NaluHeaderMVCExt.iPrefixNALU > 0) { currSlice->view_id = currSlice->NaluHeaderMVCExt.view_id; - currSlice->inter_view_flag = currSlice->NaluHeaderMVCExt.inter_view_flag; - currSlice->anchor_pic_flag = currSlice->NaluHeaderMVCExt.anchor_pic_flag; - } - else - { //no prefix NALU; + currSlice->inter_view_flag = + currSlice->NaluHeaderMVCExt.inter_view_flag; + currSlice->anchor_pic_flag = + currSlice->NaluHeaderMVCExt.anchor_pic_flag; + } else { // no prefix NALU; currSlice->view_id = p_Vid->active_subset_sps->view_id[0]; currSlice->inter_view_flag = 1; currSlice->anchor_pic_flag = currSlice->idr_flag; } - } + } } #endif - //fmo_init (p_Vid, currSlice); - //currSlice->frame_num = p_Vid->frame_num; - //currSlice->active_sps = p_Vid->active_sps; - //currSlice->active_pps = p_Vid->active_pps; + // fmo_init (p_Vid, currSlice); + // currSlice->frame_num = p_Vid->frame_num; + // currSlice->active_sps = p_Vid->active_sps; + // currSlice->active_pps = p_Vid->active_pps; - assign_quant_params (currSlice); + assign_quant_params(currSlice); - // if primary slice is replaced with redundant slice, set the correct image type - if(currSlice->redundant_pic_cnt && p_Vid->Is_primary_correct==0 && p_Vid->Is_redundant_correct) - { + // if primary slice is replaced with redundant slice, set the correct + // image type + if (currSlice->redundant_pic_cnt && p_Vid->Is_primary_correct == 0 && + p_Vid->Is_redundant_correct) { p_Vid->dec_picture->slice_type = p_Vid->type; } - if(is_new_picture(p_Vid->dec_picture, currSlice, p_Vid->old_slice)) - { - if(p_Vid->iSliceNumOfCurrPic==0) + if (is_new_picture(p_Vid->dec_picture, currSlice, p_Vid->old_slice)) { + if (p_Vid->iSliceNumOfCurrPic == 0) init_picture(p_Vid, currSlice, p_Inp); current_header = SOP; - //check zero_byte if it is also the first NAL unit in the access unit + // check zero_byte if it is also the first NAL unit in the access unit CheckZeroByteVCL(p_Vid, nalu); - } - else + } else current_header = SOS; - setup_slice_methods(currSlice); - // From here on, p_Vid->active_sps, p_Vid->active_pps and the slice header are valid + // From here on, p_Vid->active_sps, p_Vid->active_pps and the slice header + // are valid if (currSlice->mb_aff_frame_flag) currSlice->current_mb_nr = currSlice->start_mb_nr << 1; else currSlice->current_mb_nr = currSlice->start_mb_nr; - if (p_Vid->active_pps->entropy_coding_mode_flag) - { - int ByteStartPosition = currStream->frame_bitoffset/8; - if (currStream->frame_bitoffset%8 != 0) - { + if (p_Vid->active_pps->entropy_coding_mode_flag) { + int ByteStartPosition = currStream->frame_bitoffset / 8; + if (currStream->frame_bitoffset % 8 != 0) { ++ByteStartPosition; } - arideco_start_decoding (&currSlice->partArr[0].de_cabac, currStream->streamBuffer, ByteStartPosition, &currStream->read_len); + arideco_start_decoding(&currSlice->partArr[0].de_cabac, + currStream->streamBuffer, ByteStartPosition, + &currStream->read_len); } - // printf ("read_new_slice: returning %s\n", current_header == SOP?"SOP":"SOS"); - //FreeNALU(nalu); + // printf ("read_new_slice: returning %s\n", current_header == + // SOP?"SOP":"SOS"); + // FreeNALU(nalu); p_Vid->recovery_point = 0; return current_header; break; case NALU_TYPE_DPA: // read DP_A - currSlice->dpB_NotPresent =1; - currSlice->dpC_NotPresent =1; + currSlice->dpB_NotPresent = 1; + currSlice->dpC_NotPresent = 1; - currSlice->idr_flag = FALSE; + currSlice->idr_flag = FALSE; currSlice->nal_reference_idc = nalu->nal_reference_idc; - currSlice->dp_mode = PAR_DP_3; + currSlice->dp_mode = PAR_DP_3; currSlice->max_part_nr = 3; - currSlice->ei_flag = 0; - currStream = currSlice->partArr[0].bitstream; - currStream->ei_flag = 0; + currSlice->ei_flag = 0; + currStream = currSlice->partArr[0].bitstream; + currStream->ei_flag = 0; currStream->frame_bitoffset = currStream->read_len = 0; - memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); - currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1); + memcpy(currStream->streamBuffer, &nalu->buf[1], nalu->len - 1); + currStream->code_len = currStream->bitstream_length = + RBSPtoSODB(currStream->streamBuffer, nalu->len - 1); - BitsUsedByHeader = FirstPartOfSliceHeader(currSlice); - UseParameterSet (currSlice); - BitsUsedByHeader += RestOfSliceHeader (currSlice); + BitsUsedByHeader = FirstPartOfSliceHeader(currSlice); + UseParameterSet(currSlice); + BitsUsedByHeader += RestOfSliceHeader(currSlice); - fmo_init (p_Vid, currSlice); + fmo_init(p_Vid, currSlice); - if(is_new_picture(p_Vid->dec_picture, currSlice, p_Vid->old_slice)) - { + if (is_new_picture(p_Vid->dec_picture, currSlice, p_Vid->old_slice)) { init_picture(p_Vid, currSlice, p_Inp); current_header = SOP; CheckZeroByteVCL(p_Vid, nalu); - } - else + } else current_header = SOS; update_pic_num(currSlice); currSlice->init_lists(currSlice); - reorder_lists (currSlice); + reorder_lists(currSlice); - if (p_Vid->structure==FRAME) - { + if (p_Vid->structure == FRAME) { init_mbaff_lists(p_Vid, currSlice); } - // From here on, p_Vid->active_sps, p_Vid->active_pps and the slice header are valid + // From here on, p_Vid->active_sps, p_Vid->active_pps and the slice header + // are valid if (currSlice->mb_aff_frame_flag) currSlice->current_mb_nr = currSlice->start_mb_nr << 1; else @@ -1532,39 +1510,38 @@ process_nalu: // Now I need to read the slice ID, which depends on the value of // redundant_pic_cnt_present_flag - slice_id_a = ue_v("NALU: DP_A slice_id", currStream); + slice_id_a = ue_v("NALU: DP_A slice_id", currStream); if (p_Vid->active_pps->entropy_coding_mode_flag) - error ("received data partition with CABAC, this is not allowed", 500); + error("received data partition with CABAC, this is not allowed", 500); // continue with reading next DP if (0 == read_next_nalu(p_Vid, nalu)) return current_header; - if ( NALU_TYPE_DPB == nalu->nal_unit_type) - { + if (NALU_TYPE_DPB == nalu->nal_unit_type) { // we got a DPB - currStream = currSlice->partArr[1].bitstream; - currStream->ei_flag = 0; + currStream = currSlice->partArr[1].bitstream; + currStream->ei_flag = 0; currStream->frame_bitoffset = currStream->read_len = 0; - memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); - currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1); + memcpy(currStream->streamBuffer, &nalu->buf[1], nalu->len - 1); + currStream->code_len = currStream->bitstream_length = + RBSPtoSODB(currStream->streamBuffer, nalu->len - 1); - slice_id_b = ue_v("NALU: DP_B slice_id", currStream); + slice_id_b = ue_v("NALU: DP_B slice_id", currStream); - currSlice->dpB_NotPresent = 0; + currSlice->dpB_NotPresent = 0; - if ((slice_id_b != slice_id_a) || (nalu->lost_packets)) - { - printf ("Waning: got a data partition B which does not match DP_A (DP loss!)\n"); - currSlice->dpB_NotPresent =1; - currSlice->dpC_NotPresent =1; - } - else - { + if ((slice_id_b != slice_id_a) || (nalu->lost_packets)) { + printf("Waning: got a data partition B which does not match DP_A (DP " + "loss!)\n"); + currSlice->dpB_NotPresent = 1; + currSlice->dpC_NotPresent = 1; + } else { if (p_Vid->active_pps->redundant_pic_cnt_present_flag) - redundant_pic_cnt_b = ue_v("NALU: DP_B redudant_pic_cnt", currStream); + redundant_pic_cnt_b = + ue_v("NALU: DP_B redudant_pic_cnt", currStream); else redundant_pic_cnt_b = 0; @@ -1572,188 +1549,185 @@ process_nalu: if (0 == read_next_nalu(p_Vid, nalu)) return current_header; } - } - else - { - currSlice->dpB_NotPresent =1; + } else { + currSlice->dpB_NotPresent = 1; } // check if we got DP_C - if ( NALU_TYPE_DPC == nalu->nal_unit_type) - { - currStream = currSlice->partArr[2].bitstream; - currStream->ei_flag = 0; + if (NALU_TYPE_DPC == nalu->nal_unit_type) { + currStream = currSlice->partArr[2].bitstream; + currStream->ei_flag = 0; currStream->frame_bitoffset = currStream->read_len = 0; - memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); - currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1); + memcpy(currStream->streamBuffer, &nalu->buf[1], nalu->len - 1); + currStream->code_len = currStream->bitstream_length = + RBSPtoSODB(currStream->streamBuffer, nalu->len - 1); currSlice->dpC_NotPresent = 0; - slice_id_c = ue_v("NALU: DP_C slice_id", currStream); - if ((slice_id_c != slice_id_a)|| (nalu->lost_packets)) - { - printf ("Warning: got a data partition C which does not match DP_A(DP loss!)\n"); - //currSlice->dpB_NotPresent =1; - currSlice->dpC_NotPresent =1; + slice_id_c = ue_v("NALU: DP_C slice_id", currStream); + if ((slice_id_c != slice_id_a) || (nalu->lost_packets)) { + printf("Warning: got a data partition C which does not match DP_A(DP " + "loss!)\n"); + // currSlice->dpB_NotPresent =1; + currSlice->dpC_NotPresent = 1; } if (p_Vid->active_pps->redundant_pic_cnt_present_flag) - redundant_pic_cnt_c = ue_v("NALU:SLICE_C redudand_pic_cnt", currStream); + redundant_pic_cnt_c = + ue_v("NALU:SLICE_C redudand_pic_cnt", currStream); else redundant_pic_cnt_c = 0; - } - else - { - currSlice->dpC_NotPresent =1; + } else { + currSlice->dpC_NotPresent = 1; } // check if we read anything else than the expected partitions - if ((nalu->nal_unit_type != NALU_TYPE_DPB) && (nalu->nal_unit_type != NALU_TYPE_DPC)) - { + if ((nalu->nal_unit_type != NALU_TYPE_DPB) && + (nalu->nal_unit_type != NALU_TYPE_DPC)) { // we have a NALI that we can't process here, so restart processing goto process_nalu; - // yes, "goto" should not be used, but it's really the best way here before we restructure the decoding loop - // (which should be taken care of anyway) + // yes, "goto" should not be used, but it's really the best way here + // before we restructure the decoding loop (which should be taken care + // of anyway) } - //FreeNALU(nalu); + // FreeNALU(nalu); return current_header; break; case NALU_TYPE_DPB: - if (p_Inp->silent == FALSE) - { - printf ("found data partition B without matching DP A, discarding\n"); + if (p_Inp->silent == FALSE) { + printf("found data partition B without matching DP A, discarding\n"); } break; case NALU_TYPE_DPC: - if (p_Inp->silent == FALSE) - { - printf ("found data partition C without matching DP A, discarding\n"); + if (p_Inp->silent == FALSE) { + printf("found data partition C without matching DP A, discarding\n"); } break; case NALU_TYPE_SEI: - //printf ("read_new_slice: Found NALU_TYPE_SEI, len %d\n", nalu->len); - InterpretSEIMessage(nalu->buf,nalu->len,p_Vid, currSlice); + // printf ("read_new_slice: Found NALU_TYPE_SEI, len %d\n", nalu->len); + InterpretSEIMessage(nalu->buf, nalu->len, p_Vid, currSlice); break; case NALU_TYPE_PPS: - //printf ("Found NALU_TYPE_PPS\n"); + // printf ("Found NALU_TYPE_PPS\n"); ProcessPPS(p_Vid, nalu); break; case NALU_TYPE_SPS: - //printf ("Found NALU_TYPE_SPS\n"); + // printf ("Found NALU_TYPE_SPS\n"); ProcessSPS(p_Vid, nalu); break; case NALU_TYPE_AUD: - //printf ("Found NALU_TYPE_AUD\n"); - // printf ("read_new_slice: Found 'Access Unit Delimiter' NAL unit, len %d, ignored\n", nalu->len); + // printf ("Found NALU_TYPE_AUD\n"); + // printf ("read_new_slice: Found 'Access Unit Delimiter' NAL + // unit, len %d, ignored\n", nalu->len); break; case NALU_TYPE_EOSEQ: - // printf ("read_new_slice: Found 'End of Sequence' NAL unit, len %d, ignored\n", nalu->len); + // printf ("read_new_slice: Found 'End of Sequence' NAL unit, len + // %d, ignored\n", nalu->len); break; case NALU_TYPE_EOSTREAM: - // printf ("read_new_slice: Found 'End of Stream' NAL unit, len %d, ignored\n", nalu->len); + // printf ("read_new_slice: Found 'End of Stream' NAL unit, len %d, + // ignored\n", nalu->len); break; case NALU_TYPE_FILL: - if (p_Inp->silent == FALSE) - { - printf ("read_new_slice: Found NALU_TYPE_FILL, len %d\n", (int) nalu->len); - printf ("Skipping these filling bits, proceeding w/ next NALU\n"); + if (p_Inp->silent == FALSE) { + printf("read_new_slice: Found NALU_TYPE_FILL, len %d\n", + (int)nalu->len); + printf("Skipping these filling bits, proceeding w/ next NALU\n"); } break; #if (MVC_EXTENSION_ENABLE) case NALU_TYPE_VDRD: - //printf ("Found NALU_TYPE_VDRD\n"); - // printf ("read_new_slice: Found 'View and Dependency Representation Delimiter' NAL unit, len %d, ignored\n", nalu->len); + // printf ("Found NALU_TYPE_VDRD\n"); + // printf ("read_new_slice: Found 'View and Dependency + // Representation Delimiter' NAL unit, len %d, ignored\n", + // nalu->len); break; case NALU_TYPE_PREFIX: - //printf ("Found NALU_TYPE_PREFIX\n"); - if(currSlice->svc_extension_flag==1) + // printf ("Found NALU_TYPE_PREFIX\n"); + if (currSlice->svc_extension_flag == 1) prefix_nal_unit_svc(); - break; + break; case NALU_TYPE_SUB_SPS: - //printf ("Found NALU_TYPE_SUB_SPS\n"); - if (p_Inp->DecodeAllLayers== 1) + // printf ("Found NALU_TYPE_SUB_SPS\n"); + if (p_Inp->DecodeAllLayers == 1) ProcessSubsetSPS(p_Vid, nalu); - else - { + else { if (p_Inp->silent == FALSE) - printf ("Found Subsequence SPS NALU. Ignoring.\n"); + printf("Found Subsequence SPS NALU. Ignoring.\n"); } break; case NALU_TYPE_SLC_EXT: - //printf ("Found NALU_TYPE_SLC_EXT\n"); - if (p_Inp->DecodeAllLayers == 0 && (p_Inp->silent == FALSE)) - printf ("Found SVC extension NALU (%d). Ignoring.\n", (int) nalu->nal_unit_type); + // printf ("Found NALU_TYPE_SLC_EXT\n"); + if (p_Inp->DecodeAllLayers == 0 && (p_Inp->silent == FALSE)) + printf("Found SVC extension NALU (%d). Ignoring.\n", + (int)nalu->nal_unit_type); break; #endif - default: - { - if (p_Inp->silent == FALSE) - printf ("Found NALU type %d, len %d undefined, ignore NALU, moving on\n", (int) nalu->nal_unit_type, (int) nalu->len); - } - break; + default: { + if (p_Inp->silent == FALSE) + printf("Found NALU type %d, len %d undefined, ignore NALU, moving on\n", + (int)nalu->nal_unit_type, (int)nalu->len); + } break; } } } -void pad_buf(imgpel *pImgBuf, int iWidth, int iHeight, int iStride, int iPadX, int iPadY) -{ +void pad_buf(imgpel *pImgBuf, int iWidth, int iHeight, int iStride, int iPadX, + int iPadY) { int j; imgpel *pLine0 = pImgBuf - iPadX, *pLine; -#if (IMGTYPE==0) +#if (IMGTYPE == 0) int pad_width = iPadX + iWidth; fast_memset(pImgBuf - iPadX, *pImgBuf, iPadX * sizeof(imgpel)); - fast_memset(pImgBuf + iWidth, *(pImgBuf + iWidth - 1), iPadX * sizeof(imgpel)); + fast_memset(pImgBuf + iWidth, *(pImgBuf + iWidth - 1), + iPadX * sizeof(imgpel)); pLine = pLine0 - iPadY * iStride; - for(j = -iPadY; j < 0; j++) - { + for (j = -iPadY; j < 0; j++) { fast_memcpy(pLine, pLine0, iStride * sizeof(imgpel)); pLine += iStride; } - for(j = 1; j < iHeight; j++) - { + for (j = 1; j < iHeight; j++) { pLine += iStride; fast_memset(pLine, *(pLine + iPadX), iPadX * sizeof(imgpel)); - fast_memset(pLine + pad_width, *(pLine + pad_width - 1), iPadX * sizeof(imgpel)); + fast_memset(pLine + pad_width, *(pLine + pad_width - 1), + iPadX * sizeof(imgpel)); } pLine0 = pLine + iStride; - for(j = iHeight; j < iHeight + iPadY; j++) - { - fast_memcpy(pLine0, pLine, iStride * sizeof(imgpel)); + for (j = iHeight; j < iHeight + iPadY; j++) { + fast_memcpy(pLine0, pLine, iStride * sizeof(imgpel)); pLine0 += iStride; } #else int i; - for(i=-iPadX; i<0; i++) + for (i = -iPadX; i < 0; i++) pImgBuf[i] = *pImgBuf; - for(i=0; iiLumaPadX; int iPadY = p_Vid->iLumaPadY; int iWidth = dec_picture->size_x; @@ -1762,8 +1736,7 @@ void pad_dec_picture(VideoParameters *p_Vid, StorablePicture *dec_picture) pad_buf(*dec_picture->imgY, iWidth, iHeight, iStride, iPadX, iPadY); - if(dec_picture->chroma_format_idc != YUV400) - { + if (dec_picture->chroma_format_idc != YUV400) { iPadX = p_Vid->iChromaPadX; iPadY = p_Vid->iChromaPadY; iWidth = dec_picture->size_x_cr; @@ -1781,30 +1754,29 @@ void pad_dec_picture(VideoParameters *p_Vid, StorablePicture *dec_picture) * into the DPB ************************************************************************ */ -void exit_picture(VideoParameters *p_Vid, StorablePicture **dec_picture) -{ +void exit_picture(VideoParameters *p_Vid, StorablePicture **dec_picture) { InputParameters *p_Inp = p_Vid->p_Inp; - SNRParameters *snr = p_Vid->snr; - char yuv_types[4][6]= {"4:0:0","4:2:0","4:2:2","4:4:4"}; + SNRParameters *snr = p_Vid->snr; + char yuv_types[4][6] = {"4:0:0", "4:2:0", "4:2:2", "4:4:4"}; int ercStartMB; int ercSegment; frame recfr; - int structure, frame_poc, slice_type, refpic, qp, pic_num, chroma_format_idc, is_idr, top_poc, bottom_poc; - - int64 tmp_time; // time used by decoding the last frame - char yuvFormat[10]; + int structure, frame_poc, slice_type, refpic, qp, pic_num, chroma_format_idc, + is_idr, top_poc, bottom_poc; + int64 tmp_time; // time used by decoding the last frame + char yuvFormat[10]; // return if the last picture has already been finished - if (*dec_picture==NULL || (p_Vid->num_dec_mb != p_Vid->PicSizeInMbs && (p_Vid->yuv_format != YUV444 || !p_Vid->separate_colour_plane_flag))) - { + if (*dec_picture == NULL || + (p_Vid->num_dec_mb != p_Vid->PicSizeInMbs && + (p_Vid->yuv_format != YUV444 || !p_Vid->separate_colour_plane_flag))) { return; } recfr.p_Vid = p_Vid; recfr.yptr = &(*dec_picture)->imgY[0][0]; - if ((*dec_picture)->chroma_format_idc != YUV400) - { + if ((*dec_picture)->chroma_format_idc != YUV400) { recfr.uptr = &(*dec_picture)->imgUV[0][0][0]; recfr.vptr = &(*dec_picture)->imgUV[1][0][0]; } @@ -1815,31 +1787,31 @@ void exit_picture(VideoParameters *p_Vid, StorablePicture **dec_picture) //! mark the start of the first segment #if (DISABLE_ERC == 0) - if (!(*dec_picture)->mb_aff_frame_flag) - { + if (!(*dec_picture)->mb_aff_frame_flag) { int i; - ercStartSegment(0, ercSegment, 0 , p_Vid->erc_errorVar); + ercStartSegment(0, ercSegment, 0, p_Vid->erc_errorVar); //! generate the segments according to the macroblock map - for(i = 1; i<(*dec_picture)->PicSizeInMbs; ++i) - { - if(p_Vid->mb_data[i].ei_flag != p_Vid->mb_data[i-1].ei_flag) - { - ercStopSegment(i-1, ercSegment, 0, p_Vid->erc_errorVar); //! stop current segment + for (i = 1; i < (*dec_picture)->PicSizeInMbs; ++i) { + if (p_Vid->mb_data[i].ei_flag != p_Vid->mb_data[i - 1].ei_flag) { + ercStopSegment(i - 1, ercSegment, 0, + p_Vid->erc_errorVar); //! stop current segment //! mark current segment as lost or OK - if(p_Vid->mb_data[i-1].ei_flag) + if (p_Vid->mb_data[i - 1].ei_flag) ercMarkCurrSegmentLost((*dec_picture)->size_x, p_Vid->erc_errorVar); else ercMarkCurrSegmentOK((*dec_picture)->size_x, p_Vid->erc_errorVar); - ++ercSegment; //! next segment - ercStartSegment(i, ercSegment, 0 , p_Vid->erc_errorVar); //! start new segment - ercStartMB = i;//! save start MB for this segment + ++ercSegment; //! next segment + ercStartSegment(i, ercSegment, 0, + p_Vid->erc_errorVar); //! start new segment + ercStartMB = i; //! save start MB for this segment } } //! mark end of the last segment - ercStopSegment((*dec_picture)->PicSizeInMbs-1, ercSegment, 0, p_Vid->erc_errorVar); - if(p_Vid->mb_data[i-1].ei_flag) + ercStopSegment((*dec_picture)->PicSizeInMbs - 1, ercSegment, 0, + p_Vid->erc_errorVar); + if (p_Vid->mb_data[i - 1].ei_flag) ercMarkCurrSegmentLost((*dec_picture)->size_x, p_Vid->erc_errorVar); else ercMarkCurrSegmentOK((*dec_picture)->size_x, p_Vid->erc_errorVar); @@ -1849,38 +1821,36 @@ void exit_picture(VideoParameters *p_Vid, StorablePicture **dec_picture) p_Vid->erc_img = p_Vid; - if((*dec_picture)->slice_type == I_SLICE || (*dec_picture)->slice_type == SI_SLICE) // I-frame - ercConcealIntraFrame(p_Vid, &recfr, (*dec_picture)->size_x, (*dec_picture)->size_y, p_Vid->erc_errorVar); + if ((*dec_picture)->slice_type == I_SLICE || + (*dec_picture)->slice_type == SI_SLICE) // I-frame + ercConcealIntraFrame(p_Vid, &recfr, (*dec_picture)->size_x, + (*dec_picture)->size_y, p_Vid->erc_errorVar); else - ercConcealInterFrame(&recfr, p_Vid->erc_object_list, (*dec_picture)->size_x, (*dec_picture)->size_y, p_Vid->erc_errorVar, (*dec_picture)->chroma_format_idc); + ercConcealInterFrame(&recfr, p_Vid->erc_object_list, + (*dec_picture)->size_x, (*dec_picture)->size_y, + p_Vid->erc_errorVar, + (*dec_picture)->chroma_format_idc); } #endif - if(!p_Vid->iDeblockMode && (p_Vid->bDeblockEnable & (1<<(*dec_picture)->used_for_reference))) - { - //deblocking for frame or field - if( (p_Vid->separate_colour_plane_flag != 0) ) - { + if (!p_Vid->iDeblockMode && + (p_Vid->bDeblockEnable & (1 << (*dec_picture)->used_for_reference))) { + // deblocking for frame or field + if ((p_Vid->separate_colour_plane_flag != 0)) { int nplane; int colour_plane_id = p_Vid->ppSliceList[0]->colour_plane_id; - for( nplane=0; nplaneppSliceList[0]->colour_plane_id = nplane; - change_plane_JV( p_Vid, nplane, NULL ); - DeblockPicture( p_Vid, *dec_picture ); + change_plane_JV(p_Vid, nplane, NULL); + DeblockPicture(p_Vid, *dec_picture); } p_Vid->ppSliceList[0]->colour_plane_id = colour_plane_id; make_frame_picture_JV(p_Vid); + } else { + DeblockPicture(p_Vid, *dec_picture); } - else - { - DeblockPicture( p_Vid, *dec_picture ); - } - } - else - { - if( (p_Vid->separate_colour_plane_flag != 0) ) - { + } else { + if ((p_Vid->separate_colour_plane_flag != 0)) { make_frame_picture_JV(p_Vid); } } @@ -1888,124 +1858,120 @@ void exit_picture(VideoParameters *p_Vid, StorablePicture **dec_picture) if ((*dec_picture)->mb_aff_frame_flag) MbAffPostProc(p_Vid); - if (p_Vid->structure == FRAME) // buffer mgt. for frame mode + if (p_Vid->structure == FRAME) // buffer mgt. for frame mode frame_postprocessing(p_Vid); else - field_postprocessing(p_Vid); // reset all interlaced variables + field_postprocessing(p_Vid); // reset all interlaced variables #if (MVC_EXTENSION_ENABLE) - if((*dec_picture)->used_for_reference || ((*dec_picture)->inter_view_flag == 1)) + if ((*dec_picture)->used_for_reference || + ((*dec_picture)->inter_view_flag == 1)) pad_dec_picture(p_Vid, *dec_picture); #else - if((*dec_picture)->used_for_reference) + if ((*dec_picture)->used_for_reference) pad_dec_picture(p_Vid, *dec_picture); #endif - structure = (*dec_picture)->structure; + structure = (*dec_picture)->structure; slice_type = (*dec_picture)->slice_type; - frame_poc = (*dec_picture)->frame_poc; - top_poc = (*dec_picture)->top_poc; + frame_poc = (*dec_picture)->frame_poc; + top_poc = (*dec_picture)->top_poc; bottom_poc = (*dec_picture)->bottom_poc; - refpic = (*dec_picture)->used_for_reference; - qp = (*dec_picture)->qp; - pic_num = (*dec_picture)->pic_num; - is_idr = (*dec_picture)->idr_flag; + refpic = (*dec_picture)->used_for_reference; + qp = (*dec_picture)->qp; + pic_num = (*dec_picture)->pic_num; + is_idr = (*dec_picture)->idr_flag; chroma_format_idc = (*dec_picture)->chroma_format_idc; store_picture_in_dpb(p_Vid->p_Dpb, *dec_picture); - *dec_picture=NULL; + *dec_picture = NULL; - if (p_Vid->last_has_mmco_5) - { + if (p_Vid->last_has_mmco_5) { p_Vid->pre_frame_num = 0; } - if (p_Inp->silent == FALSE) - { - if (structure==TOP_FIELD || structure==FRAME) - { - if(slice_type == I_SLICE && is_idr) // IDR picture - strcpy(p_Vid->cslice_type,"IDR"); - else if(slice_type == I_SLICE) // I picture - strcpy(p_Vid->cslice_type," I "); - else if(slice_type == P_SLICE) // P pictures - strcpy(p_Vid->cslice_type," P "); - else if(slice_type == SP_SLICE) // SP pictures - strcpy(p_Vid->cslice_type,"SP "); + if (p_Inp->silent == FALSE) { + if (structure == TOP_FIELD || structure == FRAME) { + if (slice_type == I_SLICE && is_idr) // IDR picture + strcpy(p_Vid->cslice_type, "IDR"); + else if (slice_type == I_SLICE) // I picture + strcpy(p_Vid->cslice_type, " I "); + else if (slice_type == P_SLICE) // P pictures + strcpy(p_Vid->cslice_type, " P "); + else if (slice_type == SP_SLICE) // SP pictures + strcpy(p_Vid->cslice_type, "SP "); else if (slice_type == SI_SLICE) - strcpy(p_Vid->cslice_type,"SI "); - else if(refpic) // stored B pictures - strcpy(p_Vid->cslice_type," B "); + strcpy(p_Vid->cslice_type, "SI "); + else if (refpic) // stored B pictures + strcpy(p_Vid->cslice_type, " B "); else // B pictures - strcpy(p_Vid->cslice_type," b "); + strcpy(p_Vid->cslice_type, " b "); - if (structure==FRAME) - { - strncat(p_Vid->cslice_type,") ",8-strlen(p_Vid->cslice_type)); + if (structure == FRAME) { + strncat(p_Vid->cslice_type, ") ", 8 - strlen(p_Vid->cslice_type)); } - } - else if (structure==BOTTOM_FIELD) - { - if(slice_type == I_SLICE && is_idr) // IDR picture - strncat(p_Vid->cslice_type,"|IDR)",8-strlen(p_Vid->cslice_type)); - else if(slice_type == I_SLICE) // I picture - strncat(p_Vid->cslice_type,"| I )",8-strlen(p_Vid->cslice_type)); - else if(slice_type == P_SLICE) // P pictures - strncat(p_Vid->cslice_type,"| P )",8-strlen(p_Vid->cslice_type)); - else if(slice_type == SP_SLICE) // SP pictures - strncat(p_Vid->cslice_type,"|SP )",8-strlen(p_Vid->cslice_type)); + } else if (structure == BOTTOM_FIELD) { + if (slice_type == I_SLICE && is_idr) // IDR picture + strncat(p_Vid->cslice_type, "|IDR)", 8 - strlen(p_Vid->cslice_type)); + else if (slice_type == I_SLICE) // I picture + strncat(p_Vid->cslice_type, "| I )", 8 - strlen(p_Vid->cslice_type)); + else if (slice_type == P_SLICE) // P pictures + strncat(p_Vid->cslice_type, "| P )", 8 - strlen(p_Vid->cslice_type)); + else if (slice_type == SP_SLICE) // SP pictures + strncat(p_Vid->cslice_type, "|SP )", 8 - strlen(p_Vid->cslice_type)); else if (slice_type == SI_SLICE) - strncat(p_Vid->cslice_type,"|SI )",8-strlen(p_Vid->cslice_type)); - else if(refpic) // stored B pictures - strncat(p_Vid->cslice_type,"| B )",8-strlen(p_Vid->cslice_type)); + strncat(p_Vid->cslice_type, "|SI )", 8 - strlen(p_Vid->cslice_type)); + else if (refpic) // stored B pictures + strncat(p_Vid->cslice_type, "| B )", 8 - strlen(p_Vid->cslice_type)); else // B pictures - strncat(p_Vid->cslice_type,"| b )",8-strlen(p_Vid->cslice_type)); + strncat(p_Vid->cslice_type, "| b )", 8 - strlen(p_Vid->cslice_type)); } } - if ((structure==FRAME)||structure==BOTTOM_FIELD) - { + if ((structure == FRAME) || structure == BOTTOM_FIELD) { #ifndef SPEC - gettime (&(p_Vid->end_time)); // end time + gettime(&(p_Vid->end_time)); // end time - tmp_time = timediff(&(p_Vid->start_time), &(p_Vid->end_time)); + tmp_time = timediff(&(p_Vid->start_time), &(p_Vid->end_time)); p_Vid->tot_time += tmp_time; - tmp_time = timenorm(tmp_time); + tmp_time = timenorm(tmp_time); #else tmp_time = 0; #endif /* !SPEC */ - sprintf(yuvFormat,"%s", yuv_types[chroma_format_idc]); + sprintf(yuvFormat, "%s", yuv_types[chroma_format_idc]); - if (p_Inp->silent == FALSE) - { - SNRParameters *snr = p_Vid->snr; + if (p_Inp->silent == FALSE) { + SNRParameters *snr = p_Vid->snr; if (p_Vid->p_ref != -1) - fprintf(stdout,"%05d(%s%5d %5d %5d %8.4f %8.4f %8.4f %s %7d\n", - p_Vid->frame_no, p_Vid->cslice_type, frame_poc, pic_num, qp, snr->snr[0], snr->snr[1], snr->snr[2], yuvFormat, (int) tmp_time); + fprintf(stdout, "%05d(%s%5d %5d %5d %8.4f %8.4f %8.4f %s %7d\n", + p_Vid->frame_no, p_Vid->cslice_type, frame_poc, pic_num, qp, + snr->snr[0], snr->snr[1], snr->snr[2], yuvFormat, + (int)tmp_time); else - fprintf(stdout,"%05d(%s%5d %5d %5d %s %7d\n", - p_Vid->frame_no, p_Vid->cslice_type, frame_poc, pic_num, qp, yuvFormat, (int)tmp_time); - } - else - fprintf(stdout,"Completed Decoding frame %05d.\r",snr->frame_ctr); + fprintf(stdout, + "%05d(%s%5d %5d %5d %s %7d\n", + p_Vid->frame_no, p_Vid->cslice_type, frame_poc, pic_num, qp, + yuvFormat, (int)tmp_time); + } else + fprintf(stdout, "Completed Decoding frame %05d.\r", snr->frame_ctr); fflush(stdout); - if(slice_type == I_SLICE || slice_type == SI_SLICE || slice_type == P_SLICE || refpic) // I or P pictures + if (slice_type == I_SLICE || slice_type == SI_SLICE || + slice_type == P_SLICE || refpic) // I or P pictures { #if (MVC_EXTENSION_ENABLE) - if((p_Vid->ppSliceList[0])->view_id!=0) + if ((p_Vid->ppSliceList[0])->view_id != 0) #endif ++(p_Vid->number); - } - else - ++(p_Vid->Bframe_ctr); // B pictures + } else + ++(p_Vid->Bframe_ctr); // B pictures ++(snr->frame_ctr); ++(p_Vid->g_nFrame); } - //p_Vid->currentSlice->current_mb_nr = -4712; // impossible value for debugging, StW - //p_Vid->currentSlice->current_slice_nr = 0; + // p_Vid->currentSlice->current_mb_nr = -4712; // impossible value for + // debugging, StW p_Vid->currentSlice->current_slice_nr = 0; } /*! @@ -2016,85 +1982,102 @@ void exit_picture(VideoParameters *p_Vid, StorablePicture **dec_picture) ************************************************************************ */ -void ercWriteMBMODEandMV(Macroblock *currMB) -{ +void ercWriteMBMODEandMV(Macroblock *currMB) { VideoParameters *p_Vid = currMB->p_Vid; - int i, ii, jj, currMBNum = currMB->mbAddrX; //p_Vid->currentSlice->current_mb_nr; + int i, ii, jj, + currMBNum = currMB->mbAddrX; // p_Vid->currentSlice->current_mb_nr; StorablePicture *dec_picture = p_Vid->dec_picture; - int mbx = xPosMB(currMBNum, dec_picture->size_x), mby = yPosMB(currMBNum, dec_picture->size_x); + int mbx = xPosMB(currMBNum, dec_picture->size_x), + mby = yPosMB(currMBNum, dec_picture->size_x); objectBuffer_t *currRegion, *pRegion; - currRegion = p_Vid->erc_object_list + (currMBNum<<2); + currRegion = p_Vid->erc_object_list + (currMBNum << 2); - if(p_Vid->type != B_SLICE) //non-B frame + if (p_Vid->type != B_SLICE) // non-B frame { - for (i=0; i<4; ++i) - { - pRegion = currRegion + i; - pRegion->regionMode = (currMB->mb_type ==I16MB ? REGMODE_INTRA : - currMB->b8mode[i]==IBLOCK ? REGMODE_INTRA_8x8 : - currMB->b8mode[i]==0 ? REGMODE_INTER_COPY : - currMB->b8mode[i]==1 ? REGMODE_INTER_PRED : REGMODE_INTER_PRED_8x8); - if (currMB->b8mode[i]==0 || currMB->b8mode[i]==IBLOCK) // INTRA OR COPY + for (i = 0; i < 4; ++i) { + pRegion = currRegion + i; + pRegion->regionMode = (currMB->mb_type == I16MB ? REGMODE_INTRA + : currMB->b8mode[i] == IBLOCK ? REGMODE_INTRA_8x8 + : currMB->b8mode[i] == 0 ? REGMODE_INTER_COPY + : currMB->b8mode[i] == 1 ? REGMODE_INTER_PRED + : REGMODE_INTER_PRED_8x8); + if (currMB->b8mode[i] == 0 || + currMB->b8mode[i] == IBLOCK) // INTRA OR COPY { - pRegion->mv[0] = 0; - pRegion->mv[1] = 0; - pRegion->mv[2] = 0; - } - else - { - ii = 4*mbx + (i & 0x01)*2;// + BLOCK_SIZE; - jj = 4*mby + (i >> 1 )*2; - if (currMB->b8mode[i]>=5 && currMB->b8mode[i]<=7) // SMALL BLOCKS + pRegion->mv[0] = 0; + pRegion->mv[1] = 0; + pRegion->mv[2] = 0; + } else { + ii = 4 * mbx + (i & 0x01) * 2; // + BLOCK_SIZE; + jj = 4 * mby + (i >> 1) * 2; + if (currMB->b8mode[i] >= 5 && currMB->b8mode[i] <= 7) // SMALL BLOCKS { - pRegion->mv[0] = (dec_picture->mv_info[jj][ii].mv[LIST_0].mv_x + dec_picture->mv_info[jj][ii + 1].mv[LIST_0].mv_x + dec_picture->mv_info[jj + 1][ii].mv[LIST_0].mv_x + dec_picture->mv_info[jj + 1][ii + 1].mv[LIST_0].mv_x + 2)/4; - pRegion->mv[1] = (dec_picture->mv_info[jj][ii].mv[LIST_0].mv_y + dec_picture->mv_info[jj][ii + 1].mv[LIST_0].mv_y + dec_picture->mv_info[jj + 1][ii].mv[LIST_0].mv_y + dec_picture->mv_info[jj + 1][ii + 1].mv[LIST_0].mv_y + 2)/4; - } - else // 16x16, 16x8, 8x16, 8x8 + pRegion->mv[0] = + (dec_picture->mv_info[jj][ii].mv[LIST_0].mv_x + + dec_picture->mv_info[jj][ii + 1].mv[LIST_0].mv_x + + dec_picture->mv_info[jj + 1][ii].mv[LIST_0].mv_x + + dec_picture->mv_info[jj + 1][ii + 1].mv[LIST_0].mv_x + 2) / + 4; + pRegion->mv[1] = + (dec_picture->mv_info[jj][ii].mv[LIST_0].mv_y + + dec_picture->mv_info[jj][ii + 1].mv[LIST_0].mv_y + + dec_picture->mv_info[jj + 1][ii].mv[LIST_0].mv_y + + dec_picture->mv_info[jj + 1][ii + 1].mv[LIST_0].mv_y + 2) / + 4; + } else // 16x16, 16x8, 8x16, 8x8 { - pRegion->mv[0] = dec_picture->mv_info[jj][ii].mv[LIST_0].mv_x; - pRegion->mv[1] = dec_picture->mv_info[jj][ii].mv[LIST_0].mv_y; - // pRegion->mv[0] = dec_picture->motion.mv[LIST_0][4*mby+(i/2)*2][4*mbx+(i%2)*2+BLOCK_SIZE][0]; - // pRegion->mv[1] = dec_picture->motion.mv[LIST_0][4*mby+(i/2)*2][4*mbx+(i%2)*2+BLOCK_SIZE][1]; + pRegion->mv[0] = dec_picture->mv_info[jj][ii].mv[LIST_0].mv_x; + pRegion->mv[1] = dec_picture->mv_info[jj][ii].mv[LIST_0].mv_y; + // pRegion->mv[0] = + // dec_picture->motion.mv[LIST_0][4*mby+(i/2)*2][4*mbx+(i%2)*2+BLOCK_SIZE][0]; + // pRegion->mv[1] = + // dec_picture->motion.mv[LIST_0][4*mby+(i/2)*2][4*mbx+(i%2)*2+BLOCK_SIZE][1]; } - currMB->p_Slice->erc_mvperMB += iabs(pRegion->mv[0]) + iabs(pRegion->mv[1]); - pRegion->mv[2] = dec_picture->mv_info[jj][ii].ref_idx[LIST_0]; + currMB->p_Slice->erc_mvperMB += + iabs(pRegion->mv[0]) + iabs(pRegion->mv[1]); + pRegion->mv[2] = dec_picture->mv_info[jj][ii].ref_idx[LIST_0]; } } - } - else //B-frame + } else // B-frame { - for (i=0; i<4; ++i) - { - ii = 4*mbx + (i%2)*2;// + BLOCK_SIZE; - jj = 4*mby + (i/2)*2; - pRegion = currRegion + i; - pRegion->regionMode = (currMB->mb_type ==I16MB ? REGMODE_INTRA : - currMB->b8mode[i]==IBLOCK ? REGMODE_INTRA_8x8 : REGMODE_INTER_PRED_8x8); - if (currMB->mb_type==I16MB || currMB->b8mode[i]==IBLOCK) // INTRA - { - pRegion->mv[0] = 0; - pRegion->mv[1] = 0; - pRegion->mv[2] = 0; - } - else + for (i = 0; i < 4; ++i) { + ii = 4 * mbx + (i % 2) * 2; // + BLOCK_SIZE; + jj = 4 * mby + (i / 2) * 2; + pRegion = currRegion + i; + pRegion->regionMode = + (currMB->mb_type == I16MB ? REGMODE_INTRA + : currMB->b8mode[i] == IBLOCK ? REGMODE_INTRA_8x8 + : REGMODE_INTER_PRED_8x8); + if (currMB->mb_type == I16MB || currMB->b8mode[i] == IBLOCK) // INTRA { + pRegion->mv[0] = 0; + pRegion->mv[1] = 0; + pRegion->mv[2] = 0; + } else { int idx = (dec_picture->mv_info[jj][ii].ref_idx[0] < 0) ? 1 : 0; - // int idx = (currMB->b8mode[i]==0 && currMB->b8pdir[i]==2 ? LIST_0 : currMB->b8pdir[i]==1 ? LIST_1 : LIST_0); - // int idx = currMB->b8pdir[i]==0 ? LIST_0 : LIST_1; - pRegion->mv[0] = (dec_picture->mv_info[jj][ii].mv[idx].mv_x + - dec_picture->mv_info[jj][ii+1].mv[idx].mv_x + - dec_picture->mv_info[jj+1][ii].mv[idx].mv_x + - dec_picture->mv_info[jj+1][ii+1].mv[idx].mv_x + 2)/4; - pRegion->mv[1] = (dec_picture->mv_info[jj][ii].mv[idx].mv_y + - dec_picture->mv_info[jj][ii+1].mv[idx].mv_y + - dec_picture->mv_info[jj+1][ii].mv[idx].mv_y + - dec_picture->mv_info[jj+1][ii+1].mv[idx].mv_y + 2)/4; - currMB->p_Slice->erc_mvperMB += iabs(pRegion->mv[0]) + iabs(pRegion->mv[1]); + // int idx = (currMB->b8mode[i]==0 && currMB->b8pdir[i]==2 ? + // LIST_0 : currMB->b8pdir[i]==1 ? LIST_1 : LIST_0); int idx = + // currMB->b8pdir[i]==0 ? LIST_0 : LIST_1; + pRegion->mv[0] = + (dec_picture->mv_info[jj][ii].mv[idx].mv_x + + dec_picture->mv_info[jj][ii + 1].mv[idx].mv_x + + dec_picture->mv_info[jj + 1][ii].mv[idx].mv_x + + dec_picture->mv_info[jj + 1][ii + 1].mv[idx].mv_x + 2) / + 4; + pRegion->mv[1] = + (dec_picture->mv_info[jj][ii].mv[idx].mv_y + + dec_picture->mv_info[jj][ii + 1].mv[idx].mv_y + + dec_picture->mv_info[jj + 1][ii].mv[idx].mv_y + + dec_picture->mv_info[jj + 1][ii + 1].mv[idx].mv_y + 2) / + 4; + currMB->p_Slice->erc_mvperMB += + iabs(pRegion->mv[0]) + iabs(pRegion->mv[1]); - pRegion->mv[2] = (dec_picture->mv_info[jj][ii].ref_idx[idx]); + pRegion->mv[2] = (dec_picture->mv_info[jj][ii].ref_idx[idx]); /* - if (currMB->b8pdir[i]==0 || (currMB->b8pdir[i]==2 && currMB->b8mode[i]!=0)) // forward or bidirect + if (currMB->b8pdir[i]==0 || (currMB->b8pdir[i]==2 && + currMB->b8mode[i]!=0)) // forward or bidirect { pRegion->mv[2] = (dec_picture->motion.ref_idx[LIST_0][jj][ii]); ///???? is it right, not only "p_Vid->fw_refFrArr[jj][ii-4]" @@ -2117,8 +2100,7 @@ void ercWriteMBMODEandMV(Macroblock *currMB) * NAL unit of a picture" ************************************************************************ */ -void init_old_slice(OldSliceParams *p_old_slice) -{ +void init_old_slice(OldSliceParams *p_old_slice) { p_old_slice->field_pic_flag = 0; p_old_slice->pps_id = INT_MAX; @@ -2129,49 +2111,45 @@ void init_old_slice(OldSliceParams *p_old_slice) p_old_slice->idr_flag = FALSE; - p_old_slice->pic_oder_cnt_lsb = UINT_MAX; + p_old_slice->pic_oder_cnt_lsb = UINT_MAX; p_old_slice->delta_pic_oder_cnt_bottom = INT_MAX; p_old_slice->delta_pic_order_cnt[0] = INT_MAX; p_old_slice->delta_pic_order_cnt[1] = INT_MAX; } - -void CopySliceInfo(Slice *currSlice, OldSliceParams *p_old_slice) -{ +void CopySliceInfo(Slice *currSlice, OldSliceParams *p_old_slice) { VideoParameters *p_Vid = currSlice->p_Vid; - p_old_slice->pps_id = currSlice->pic_parameter_set_id; - p_old_slice->frame_num = currSlice->frame_num; //p_Vid->frame_num; - p_old_slice->field_pic_flag = currSlice->field_pic_flag; //p_Vid->field_pic_flag; + p_old_slice->pps_id = currSlice->pic_parameter_set_id; + p_old_slice->frame_num = currSlice->frame_num; // p_Vid->frame_num; + p_old_slice->field_pic_flag = + currSlice->field_pic_flag; // p_Vid->field_pic_flag; - if(currSlice->field_pic_flag) - { + if (currSlice->field_pic_flag) { p_old_slice->bottom_field_flag = currSlice->bottom_field_flag; } p_old_slice->nal_ref_idc = currSlice->nal_reference_idc; - p_old_slice->idr_flag = (byte) currSlice->idr_flag; + p_old_slice->idr_flag = (byte)currSlice->idr_flag; - if (currSlice->idr_flag) - { + if (currSlice->idr_flag) { p_old_slice->idr_pic_id = currSlice->idr_pic_id; } - if (p_Vid->active_sps->pic_order_cnt_type == 0) - { - p_old_slice->pic_oder_cnt_lsb = currSlice->pic_order_cnt_lsb; - p_old_slice->delta_pic_oder_cnt_bottom = currSlice->delta_pic_order_cnt_bottom; + if (p_Vid->active_sps->pic_order_cnt_type == 0) { + p_old_slice->pic_oder_cnt_lsb = currSlice->pic_order_cnt_lsb; + p_old_slice->delta_pic_oder_cnt_bottom = + currSlice->delta_pic_order_cnt_bottom; } - if (p_Vid->active_sps->pic_order_cnt_type == 1) - { + if (p_Vid->active_sps->pic_order_cnt_type == 1) { p_old_slice->delta_pic_order_cnt[0] = currSlice->delta_pic_order_cnt[0]; p_old_slice->delta_pic_order_cnt[1] = currSlice->delta_pic_order_cnt[1]; } #if (MVC_EXTENSION_ENABLE) p_old_slice->view_id = currSlice->view_id; - p_old_slice->inter_view_flag = currSlice->inter_view_flag; + p_old_slice->inter_view_flag = currSlice->inter_view_flag; p_old_slice->anchor_pic_flag = currSlice->anchor_pic_flag; #endif } @@ -2182,13 +2160,13 @@ void CopySliceInfo(Slice *currSlice, OldSliceParams *p_old_slice) * detect if current slice is "first VCL NAL unit of a picture" ************************************************************************ */ -int is_new_picture(StorablePicture *dec_picture, Slice *currSlice, OldSliceParams *p_old_slice) -{ +int is_new_picture(StorablePicture *dec_picture, Slice *currSlice, + OldSliceParams *p_old_slice) { VideoParameters *p_Vid = currSlice->p_Vid; - int result=0; + int result = 0; - result |= (NULL==dec_picture); + result |= (NULL == dec_picture); result |= (p_old_slice->pps_id != currSlice->pic_parameter_set_id); @@ -2196,36 +2174,37 @@ int is_new_picture(StorablePicture *dec_picture, Slice *currSlice, OldSliceParam result |= (p_old_slice->field_pic_flag != currSlice->field_pic_flag); - if(currSlice->field_pic_flag && p_old_slice->field_pic_flag) - { + if (currSlice->field_pic_flag && p_old_slice->field_pic_flag) { result |= (p_old_slice->bottom_field_flag != currSlice->bottom_field_flag); } - result |= (p_old_slice->nal_ref_idc != currSlice->nal_reference_idc) && ((p_old_slice->nal_ref_idc == 0) || (currSlice->nal_reference_idc == 0)); - result |= (p_old_slice->idr_flag != currSlice->idr_flag); + result |= + (p_old_slice->nal_ref_idc != currSlice->nal_reference_idc) && + ((p_old_slice->nal_ref_idc == 0) || (currSlice->nal_reference_idc == 0)); + result |= (p_old_slice->idr_flag != currSlice->idr_flag); - if (currSlice->idr_flag && p_old_slice->idr_flag) - { + if (currSlice->idr_flag && p_old_slice->idr_flag) { result |= (p_old_slice->idr_pic_id != currSlice->idr_pic_id); } - if (p_Vid->active_sps->pic_order_cnt_type == 0) - { - result |= (p_old_slice->pic_oder_cnt_lsb != currSlice->pic_order_cnt_lsb); - if( p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag == 1 && !currSlice->field_pic_flag ) - { - result |= (p_old_slice->delta_pic_oder_cnt_bottom != currSlice->delta_pic_order_cnt_bottom); + if (p_Vid->active_sps->pic_order_cnt_type == 0) { + result |= (p_old_slice->pic_oder_cnt_lsb != currSlice->pic_order_cnt_lsb); + if (p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag == 1 && + !currSlice->field_pic_flag) { + result |= (p_old_slice->delta_pic_oder_cnt_bottom != + currSlice->delta_pic_order_cnt_bottom); } } - if (p_Vid->active_sps->pic_order_cnt_type == 1) - { - if (!p_Vid->active_sps->delta_pic_order_always_zero_flag) - { - result |= (p_old_slice->delta_pic_order_cnt[0] != currSlice->delta_pic_order_cnt[0]); - if( p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag == 1 && !currSlice->field_pic_flag ) - { - result |= (p_old_slice->delta_pic_order_cnt[1] != currSlice->delta_pic_order_cnt[1]); + if (p_Vid->active_sps->pic_order_cnt_type == 1) { + if (!p_Vid->active_sps->delta_pic_order_always_zero_flag) { + result |= (p_old_slice->delta_pic_order_cnt[0] != + currSlice->delta_pic_order_cnt[0]); + if (p_Vid->active_pps->bottom_field_pic_order_in_frame_present_flag == + 1 && + !currSlice->field_pic_flag) { + result |= (p_old_slice->delta_pic_order_cnt[1] != + currSlice->delta_pic_order_cnt[1]); } } } @@ -2239,17 +2218,13 @@ int is_new_picture(StorablePicture *dec_picture, Slice *currSlice, OldSliceParam return result; } - - /*! ************************************************************************ * \brief * Prepare field and frame buffer after frame decoding ************************************************************************ */ -void frame_postprocessing(VideoParameters *p_Vid) -{ -} +void frame_postprocessing(VideoParameters *p_Vid) {} /*! ************************************************************************ @@ -2257,12 +2232,7 @@ void frame_postprocessing(VideoParameters *p_Vid) * Prepare field and frame buffer after field decoding ************************************************************************ */ -void field_postprocessing(VideoParameters *p_Vid) -{ - p_Vid->number /= 2; -} - - +void field_postprocessing(VideoParameters *p_Vid) { p_Vid->number /= 2; } /*! ************************************************************************ @@ -2271,76 +2241,75 @@ void field_postprocessing(VideoParameters *p_Vid) * for 4:4:4 Independent mode ************************************************************************ */ -void copy_dec_picture_JV( VideoParameters *p_Vid, StorablePicture *dst, StorablePicture *src ) -{ - dst->top_poc = src->top_poc; - dst->bottom_poc = src->bottom_poc; - dst->frame_poc = src->frame_poc; - dst->qp = src->qp; - dst->slice_qp_delta = src->slice_qp_delta; - dst->chroma_qp_offset[0] = src->chroma_qp_offset[0]; - dst->chroma_qp_offset[1] = src->chroma_qp_offset[1]; +void copy_dec_picture_JV(VideoParameters *p_Vid, StorablePicture *dst, + StorablePicture *src) { + dst->top_poc = src->top_poc; + dst->bottom_poc = src->bottom_poc; + dst->frame_poc = src->frame_poc; + dst->qp = src->qp; + dst->slice_qp_delta = src->slice_qp_delta; + dst->chroma_qp_offset[0] = src->chroma_qp_offset[0]; + dst->chroma_qp_offset[1] = src->chroma_qp_offset[1]; - dst->poc = src->poc; + dst->poc = src->poc; - dst->slice_type = src->slice_type; - dst->used_for_reference = src->used_for_reference; - dst->idr_flag = src->idr_flag; + dst->slice_type = src->slice_type; + dst->used_for_reference = src->used_for_reference; + dst->idr_flag = src->idr_flag; dst->no_output_of_prior_pics_flag = src->no_output_of_prior_pics_flag; dst->long_term_reference_flag = src->long_term_reference_flag; dst->adaptive_ref_pic_buffering_flag = src->adaptive_ref_pic_buffering_flag; dst->dec_ref_pic_marking_buffer = src->dec_ref_pic_marking_buffer; - dst->mb_aff_frame_flag = src->mb_aff_frame_flag; - dst->PicWidthInMbs = src->PicWidthInMbs; - dst->pic_num = src->pic_num; - dst->frame_num = src->frame_num; - dst->recovery_frame = src->recovery_frame; - dst->coded_frame = src->coded_frame; + dst->mb_aff_frame_flag = src->mb_aff_frame_flag; + dst->PicWidthInMbs = src->PicWidthInMbs; + dst->pic_num = src->pic_num; + dst->frame_num = src->frame_num; + dst->recovery_frame = src->recovery_frame; + dst->coded_frame = src->coded_frame; - dst->chroma_format_idc = src->chroma_format_idc; + dst->chroma_format_idc = src->chroma_format_idc; - dst->frame_mbs_only_flag = src->frame_mbs_only_flag; - dst->frame_cropping_flag = src->frame_cropping_flag; + dst->frame_mbs_only_flag = src->frame_mbs_only_flag; + dst->frame_cropping_flag = src->frame_cropping_flag; - dst->frame_cropping_rect_left_offset = src->frame_cropping_rect_left_offset; - dst->frame_cropping_rect_right_offset = src->frame_cropping_rect_right_offset; - dst->frame_cropping_rect_top_offset = src->frame_cropping_rect_top_offset; - dst->frame_cropping_rect_bottom_offset = src->frame_cropping_rect_bottom_offset; + dst->frame_cropping_rect_left_offset = src->frame_cropping_rect_left_offset; + dst->frame_cropping_rect_right_offset = src->frame_cropping_rect_right_offset; + dst->frame_cropping_rect_top_offset = src->frame_cropping_rect_top_offset; + dst->frame_cropping_rect_bottom_offset = + src->frame_cropping_rect_bottom_offset; #if (ENABLE_OUTPUT_TONEMAPPING) // store the necessary tone mapping sei into StorablePicture structure dst->seiHasTone_mapping = src->seiHasTone_mapping; - dst->seiHasTone_mapping = src->seiHasTone_mapping; + dst->seiHasTone_mapping = src->seiHasTone_mapping; dst->tone_mapping_model_id = src->tone_mapping_model_id; - dst->tonemapped_bit_depth = src->tonemapped_bit_depth; - if( src->tone_mapping_lut ) - { + dst->tonemapped_bit_depth = src->tonemapped_bit_depth; + if (src->tone_mapping_lut) { int coded_data_bit_max = (1 << p_Vid->seiToneMapping->coded_data_bit_depth); - dst->tone_mapping_lut = malloc(sizeof(int) * coded_data_bit_max); - if (NULL == dst->tone_mapping_lut) - { + dst->tone_mapping_lut = malloc(sizeof(int) * coded_data_bit_max); + if (NULL == dst->tone_mapping_lut) { no_mem_exit("copy_dec_picture_JV: tone_mapping_lut"); } - memcpy(dst->tone_mapping_lut, src->tone_mapping_lut, sizeof(imgpel) * coded_data_bit_max); + memcpy(dst->tone_mapping_lut, src->tone_mapping_lut, + sizeof(imgpel) * coded_data_bit_max); } #endif } - -// this is intended to make get_block_luma faster by doing this at a more appropriate level -// i.e. per slice rather than per MB -static void init_cur_imgy(Slice *currSlice, VideoParameters *p_Vid) -{ - int i,j; - if ((p_Vid->separate_colour_plane_flag != 0)) { +// this is intended to make get_block_luma faster by doing this at a more +// appropriate level i.e. per slice rather than per MB +static void init_cur_imgy(Slice *currSlice, VideoParameters *p_Vid) { + int i, j; + if ((p_Vid->separate_colour_plane_flag != 0)) { StorablePicture *vidref = p_Vid->no_reference_picture; int noref = (currSlice->framepoc < p_Vid->recovery_poc); - switch(currSlice->colour_plane_id) { + switch (currSlice->colour_plane_id) { case 0: - for (j = 0; j < 6; j++) { //for (j = 0; j < (currSlice->slice_type==B_SLICE?2:1); j++) { + for (j = 0; j < 6; j++) { // for (j = 0; j < + // (currSlice->slice_type==B_SLICE?2:1); j++) { for (i = 0; i < MAX_LIST_SIZE; i++) { StorablePicture *curr_ref = currSlice->listX[j][i]; if (curr_ref) { @@ -2375,21 +2344,21 @@ static void init_cur_imgy(Slice *currSlice, VideoParameters *p_Vid) break; #endif } - } - else - { + } else { StorablePicture *vidref = p_Vid->no_reference_picture; int noref = (currSlice->framepoc < p_Vid->recovery_poc); - int total_lists = currSlice->mb_aff_frame_flag ? 6 : (currSlice->slice_type==B_SLICE ? 2 : 1); - // for (j = 0; j < 6; j++) { //for (j = 0; j < (currSlice->slice_type==B_SLICE?2:1); j++) { - for (j = 0; j < total_lists; j++) - { - // note that if we always set this to MAX_LIST_SIZE, we avoid crashes with invalid ref_idx being set - // since currently this is done at the slice level, it seems safe to do so. - // Note for some reason I get now a mismatch between version 12 and this one in cabac. I wonder why. - //for (i = 0; i < currSlice->listXsize[j]; i++) - for (i = 0; i < MAX_LIST_SIZE; i++) - { + int total_lists = currSlice->mb_aff_frame_flag + ? 6 + : (currSlice->slice_type == B_SLICE ? 2 : 1); + // for (j = 0; j < 6; j++) { //for (j = 0; j < + // (currSlice->slice_type==B_SLICE?2:1); j++) { + for (j = 0; j < total_lists; j++) { + // note that if we always set this to MAX_LIST_SIZE, we avoid crashes with + // invalid ref_idx being set since currently this is done at the slice + // level, it seems safe to do so. Note for some reason I get now a + // mismatch between version 12 and this one in cabac. I wonder why. + // for (i = 0; i < currSlice->listXsize[j]; i++) + for (i = 0; i < MAX_LIST_SIZE; i++) { StorablePicture *curr_ref = currSlice->listX[j][i]; if (curr_ref) { curr_ref->no_ref = noref && (curr_ref == vidref); @@ -2400,27 +2369,21 @@ static void init_cur_imgy(Slice *currSlice, VideoParameters *p_Vid) } } - - /*! ************************************************************************ * \brief * decodes one slice ************************************************************************ */ -void decode_one_slice(Slice *currSlice) -{ +void decode_one_slice(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; Boolean end_of_slice = FALSE; Macroblock *currMB = NULL; - currSlice->cod_counter=-1; + currSlice->cod_counter = -1; - if( (p_Vid->separate_colour_plane_flag != 0) ) - { - change_plane_JV( p_Vid, currSlice->colour_plane_id, currSlice ); - } - else - { + if ((p_Vid->separate_colour_plane_flag != 0)) { + change_plane_JV(p_Vid, currSlice->colour_plane_id, currSlice); + } else { currSlice->mb_data = p_Vid->mb_data; currSlice->dec_picture = p_Vid->dec_picture; currSlice->siblock = p_Vid->siblock; @@ -2428,21 +2391,23 @@ void decode_one_slice(Slice *currSlice) currSlice->intra_block = p_Vid->intra_block; } - if (currSlice->slice_type == B_SLICE) - { + if (currSlice->slice_type == B_SLICE) { compute_colocated(currSlice, currSlice->listX); } if (currSlice->slice_type != I_SLICE && currSlice->slice_type != SI_SLICE) - init_cur_imgy(currSlice,p_Vid); + init_cur_imgy(currSlice, p_Vid); - //reset_ec_flags(p_Vid); + // reset_ec_flags(p_Vid); while (end_of_slice == FALSE) // loop over macroblocks { #if TRACE - fprintf(p_Dec->p_trace,"\n*********** POC: %i (I/P) MB: %i Slice: %i Type %d **********\n", currSlice->ThisPOC, currSlice->current_mb_nr, currSlice->current_slice_nr, currSlice->slice_type); + fprintf(p_Dec->p_trace, + "\n*********** POC: %i (I/P) MB: %i Slice: %i Type %d **********\n", + currSlice->ThisPOC, currSlice->current_mb_nr, + currSlice->current_slice_nr, currSlice->slice_type); #endif // Initializes the current macroblock @@ -2451,8 +2416,7 @@ void decode_one_slice(Slice *currSlice) currSlice->read_one_macroblock(currMB); decode_one_macroblock(currMB, currSlice->dec_picture); - if(currSlice->mb_aff_frame_flag && currMB->mb_field) - { + if (currSlice->mb_aff_frame_flag && currMB->mb_field) { currSlice->num_ref_idx_active[LIST_0] >>= 1; currSlice->num_ref_idx_active[LIST_1] >>= 1; } @@ -2461,42 +2425,45 @@ void decode_one_slice(Slice *currSlice) ercWriteMBMODEandMV(currMB); #endif - end_of_slice = exit_macroblock(currSlice, (!currSlice->mb_aff_frame_flag|| currSlice->current_mb_nr%2)); + end_of_slice = exit_macroblock(currSlice, (!currSlice->mb_aff_frame_flag || + currSlice->current_mb_nr % 2)); } - //reset_ec_flags(p_Vid); + // reset_ec_flags(p_Vid); } #if (MVC_EXTENSION_ENABLE) -int GetVOIdx(VideoParameters *p_Vid, int iViewId) -{ +int GetVOIdx(VideoParameters *p_Vid, int iViewId) { int iVOIdx = -1; int *piViewIdMap; - if(p_Vid->active_subset_sps) - { + if (p_Vid->active_subset_sps) { piViewIdMap = p_Vid->active_subset_sps->view_id; - for(iVOIdx = p_Vid->active_subset_sps->num_views_minus1; iVOIdx>=0; iVOIdx--) - if(piViewIdMap[iVOIdx] == iViewId) + for (iVOIdx = p_Vid->active_subset_sps->num_views_minus1; iVOIdx >= 0; + iVOIdx--) + if (piViewIdMap[iVOIdx] == iViewId) break; } return iVOIdx; } -int get_maxViewIdx (VideoParameters *p_Vid, int view_id, int anchor_pic_flag, int listidx) -{ +int get_maxViewIdx(VideoParameters *p_Vid, int view_id, int anchor_pic_flag, + int listidx) { int VOIdx; int maxViewIdx = 0; VOIdx = GetVOIdx(p_Vid, view_id); - if(VOIdx >= 0) - { - if(anchor_pic_flag) - maxViewIdx = listidx? p_Vid->active_subset_sps->num_anchor_refs_l1[VOIdx] : p_Vid->active_subset_sps->num_anchor_refs_l0[VOIdx]; + if (VOIdx >= 0) { + if (anchor_pic_flag) + maxViewIdx = listidx + ? p_Vid->active_subset_sps->num_anchor_refs_l1[VOIdx] + : p_Vid->active_subset_sps->num_anchor_refs_l0[VOIdx]; else - maxViewIdx = listidx? p_Vid->active_subset_sps->num_non_anchor_refs_l1[VOIdx] : p_Vid->active_subset_sps->num_non_anchor_refs_l0[VOIdx]; + maxViewIdx = + listidx ? p_Vid->active_subset_sps->num_non_anchor_refs_l1[VOIdx] + : p_Vid->active_subset_sps->num_non_anchor_refs_l0[VOIdx]; } - return maxViewIdx; + return maxViewIdx; } #endif diff --git a/src/common/ldecod_src/img_io.c b/src/common/ldecod_src/img_io.c index 28121bf..374ceca 100644 --- a/src/common/ldecod_src/img_io.c +++ b/src/common/ldecod_src/img_io.c @@ -7,13 +7,14 @@ * image I/O related functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Alexis Michael Tourapis ************************************************************************************* */ +#include "img_io.h" #include "contributors.h" #include "global.h" -#include "img_io.h" #include "report.h" #ifdef SPEC #define STRCMP strcmp @@ -22,19 +23,10 @@ #endif static const VIDEO_SIZE VideoRes[] = { - { "qcif" , 176, 144}, - { "qqvga" , 160, 128}, - { "qvga" , 320, 240}, - { "sif" , 352, 240}, - { "cif" , 352, 288}, - { "vga" , 640, 480}, - { "sd1" , 720, 480}, - { "sd2" , 704, 576}, - { "sd3" , 720, 576}, - { "720p" , 1280, 720}, - { "1080p" , 1920, 1080}, - { NULL, 0, 0} -}; + {"qcif", 176, 144}, {"qqvga", 160, 128}, {"qvga", 320, 240}, + {"sif", 352, 240}, {"cif", 352, 288}, {"vga", 640, 480}, + {"sd1", 720, 480}, {"sd2", 704, 576}, {"sd3", 720, 576}, + {"720p", 1280, 720}, {"1080p", 1920, 1080}, {NULL, 0, 0}}; /*! ************************************************************************ @@ -43,8 +35,8 @@ static const VIDEO_SIZE VideoRes[] = { * ************************************************************************ */ -int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, double *fps) -{ +int ParseSizeFromString(VideoDataFile *input_file, int *x_size, int *y_size, + double *fps) { char *p1, *p2, *tail; char *fn = input_file->fname; char c; @@ -52,27 +44,26 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do *x_size = *y_size = -1; p1 = p2 = fn; - while (p1 != NULL && p2 != NULL) - { + while (p1 != NULL && p2 != NULL) { // Search for first '_' - p1 = strstr( p1, "_"); + p1 = strstr(p1, "_"); if (p1 == NULL) break; // Search for end character of x_size (first 'x' after last '_') - p2 = strstr( p1, "x"); + p2 = strstr(p1, "x"); // If no 'x' is found, exit - if (p2 == NULL) + if (p2 == NULL) break; // Try conversion of number *p2 = 0; - *x_size = strtol( p1 + 1, &tail, 10); + *x_size = strtol(p1 + 1, &tail, 10); - // If there are characters left in the string, or the string is null, discard conversion - if (*tail != '\0' || *(p1 + 1) == '\0') - { + // If there are characters left in the string, or the string is null, + // discard conversion + if (*tail != '\0' || *(p1 + 1) == '\0') { *p2 = 'x'; p1 = tail; continue; @@ -82,10 +73,9 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do *p2 = 'x'; // Search for end character of y_size (first '_' or '.' after last 'x') - p1 = strpbrk( p2 + 1, "_."); + p1 = strpbrk(p2 + 1, "_."); // If no '_' or '.' is found, try again from current position - if (p1 == NULL) - { + if (p1 == NULL) { p1 = p2 + 1; continue; } @@ -93,11 +83,11 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do // Try conversion of number c = *p1; *p1 = 0; - *y_size = strtol( p2 + 1, &tail, 10); + *y_size = strtol(p2 + 1, &tail, 10); - // If there are characters left in the string, or the string is null, discard conversion - if (*tail != '\0' || *(p2 + 1) == '\0') - { + // If there are characters left in the string, or the string is null, + // discard conversion + if (*tail != '\0' || *(p2 + 1) == '\0') { *p1 = c; p1 = tail; continue; @@ -107,20 +97,20 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do *p1 = c; // Search for end character of y_size (first 'i' or 'p' after last '_') - p2 = strstr( p1 + 1, "ip"); + p2 = strstr(p1 + 1, "ip"); // If no 'i' or 'p' is found, exit - if (p2 == NULL) + if (p2 == NULL) break; // Try conversion of number c = *p2; *p2 = 0; - *fps = strtod( p1 + 1, &tail); + *fps = strtod(p1 + 1, &tail); - // If there are characters left in the string, or the string is null, discard conversion - if (*tail != '\0' || *(p1 + 1) == '\0') - { + // If there are characters left in the string, or the string is null, + // discard conversion + if (*tail != '\0' || *(p1 + 1) == '\0') { *p2 = c; p1 = tail; continue; @@ -132,21 +122,18 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do } // Now lets test some common video file formats - if (p1 == NULL || p2 == NULL) - { - for (i = 0; VideoRes[i].name != NULL; i++) - { - if (STRCMP (fn, VideoRes[i].name)) - { + if (p1 == NULL || p2 == NULL) { + for (i = 0; VideoRes[i].name != NULL; i++) { + if (STRCMP(fn, VideoRes[i].name)) { *x_size = VideoRes[i].x_size; - *y_size = VideoRes[i].y_size; + *y_size = VideoRes[i].y_size; // Should add frame rate support as well break; } } } - return (*x_size == -1 || *y_size == -1) ? 0 : 1; + return (*x_size == -1 || *y_size == -1) ? 0 : 1; } /*! @@ -156,45 +143,43 @@ int ParseSizeFromString (VideoDataFile *input_file, int *x_size, int *y_size, do * ************************************************************************ */ -void ParseFrameNoFormatFromString (VideoDataFile *input_file) -{ - char *p1, *p2, *tail; - char *fn = input_file->fname; - char *fhead = input_file->fhead; - char *ftail = input_file->ftail; - int *zero_pad = &input_file->zero_pad; - int *num_digits = &input_file->num_digits; +void ParseFrameNoFormatFromString(VideoDataFile *input_file) { + char *p1, *p2, *tail; + char *fn = input_file->fname; + char *fhead = input_file->fhead; + char *ftail = input_file->ftail; + int *zero_pad = &input_file->zero_pad; + int *num_digits = &input_file->num_digits; *zero_pad = 0; *num_digits = -1; p1 = p2 = fn; - while (p1 != NULL && p2 != NULL) - { + while (p1 != NULL && p2 != NULL) { // Search for first '_' - p1 = strstr( p1, "%"); + p1 = strstr(p1, "%"); if (p1 == NULL) break; strncpy(fhead, fn, p1 - fn); // Search for end character of x_size (first 'x' after last '_') - p2 = strstr( p1, "d"); + p2 = strstr(p1, "d"); // If no 'x' is found, exit - if (p2 == NULL) + if (p2 == NULL) break; - + // Try conversion of number *p2 = 0; if (*(p1 + 1) == '0') *zero_pad = 1; - *num_digits = strtol( p1 + 1, &tail, 10); + *num_digits = strtol(p1 + 1, &tail, 10); - // If there are characters left in the string, or the string is null, discard conversion - if (*tail != '\0' || *(p1 + 1) == '\0') - { + // If there are characters left in the string, or the string is null, + // discard conversion + if (*tail != '\0' || *(p1 + 1) == '\0') { *p2 = 'd'; p1 = tail; continue; @@ -204,15 +189,13 @@ void ParseFrameNoFormatFromString (VideoDataFile *input_file) *p2 = 'd'; tail++; - strncpy(ftail, tail, (int) strlen(tail)); + strncpy(ftail, tail, (int)strlen(tail)); break; } - if (input_file->vdtype == VIDEO_TIFF) - { + if (input_file->vdtype == VIDEO_TIFF) { input_file->is_concatenated = 0; - } - else + } else input_file->is_concatenated = (*num_digits == -1) ? 1 : 0; } @@ -222,31 +205,29 @@ void ParseFrameNoFormatFromString (VideoDataFile *input_file) * Open file containing a single frame ************************************************************************ */ -void OpenFrameFile( VideoDataFile *input_file, int FrameNumberInFile) -{ - char infile [FILE_NAME_SIZE], in_number[16]; +void OpenFrameFile(VideoDataFile *input_file, int FrameNumberInFile) { + char infile[FILE_NAME_SIZE], in_number[16]; int length = 0; - in_number[length]='\0'; - length = (int) strlen(input_file->fhead); + in_number[length] = '\0'; + length = (int)strlen(input_file->fhead); strncpy(infile, input_file->fhead, length); - infile[length]='\0'; - if (input_file->zero_pad) + infile[length] = '\0'; + if (input_file->zero_pad) snprintf(in_number, 16, "%0*d", input_file->num_digits, FrameNumberInFile); else snprintf(in_number, 16, "%*d", input_file->num_digits, FrameNumberInFile); strncat(infile, in_number, sizeof(in_number)); length += sizeof(in_number); - infile[length]='\0'; + infile[length] = '\0'; strncat(infile, input_file->ftail, strlen(input_file->ftail)); - length += (int) strlen(input_file->ftail); - infile[length]='\0'; + length += (int)strlen(input_file->ftail); + infile[length] = '\0'; - if ((input_file->f_num = open(infile, OPENFLAGS_READ)) == -1) - { - printf ("OpenFrameFile: cannot open file %s\n", infile); + if ((input_file->f_num = open(infile, OPENFLAGS_READ)) == -1) { + printf("OpenFrameFile: cannot open file %s\n", infile); report_stats_on_error(); - } + } } /*! @@ -255,20 +236,18 @@ void OpenFrameFile( VideoDataFile *input_file, int FrameNumberInFile) * Open file(s) containing the entire frame sequence ************************************************************************ */ -void OpenFiles( VideoDataFile *input_file) -{ - if (input_file->is_concatenated == 1) - { - if ((int) strlen(input_file->fname) == 0) - { - snprintf(errortext, ET_SIZE, "No input sequence name was provided. Please check settings."); - error (errortext, 500); +void OpenFiles(VideoDataFile *input_file) { + if (input_file->is_concatenated == 1) { + if ((int)strlen(input_file->fname) == 0) { + snprintf(errortext, ET_SIZE, + "No input sequence name was provided. Please check settings."); + error(errortext, 500); } - if ((input_file->f_num = open(input_file->fname, OPENFLAGS_READ)) == -1) - { - snprintf(errortext, ET_SIZE, "Input file %s does not exist",input_file->fname); - error (errortext, 500); + if ((input_file->f_num = open(input_file->fname, OPENFLAGS_READ)) == -1) { + snprintf(errortext, ET_SIZE, "Input file %s does not exist", + input_file->fname); + error(errortext, 500); } } } @@ -279,8 +258,7 @@ void OpenFiles( VideoDataFile *input_file) * Close input file ************************************************************************ */ -void CloseFiles(VideoDataFile *input_file) -{ +void CloseFiles(VideoDataFile *input_file) { if (input_file->f_num != -1) close(input_file->f_num); input_file->f_num = -1; @@ -291,38 +269,28 @@ void CloseFiles(VideoDataFile *input_file) * ParseVideoType * * ========================================================================== -*/ -VideoFileType ParseVideoType (VideoDataFile *input_file) -{ + */ +VideoFileType ParseVideoType(VideoDataFile *input_file) { char *format; - format = input_file->fname + (int) strlen(input_file->fname) - 3; + format = input_file->fname + (int)strlen(input_file->fname) - 3; - if (STRCMP (format, "yuv") == 0) - { + if (STRCMP(format, "yuv") == 0) { input_file->vdtype = VIDEO_YUV; input_file->format.yuv_format = YUV420; input_file->avi = NULL; - } - else if (STRCMP (format, "rgb") == 0) - { + } else if (STRCMP(format, "rgb") == 0) { input_file->vdtype = VIDEO_RGB; input_file->format.yuv_format = YUV444; input_file->avi = NULL; - } - else if (STRCMP (format, "tif") == 0) - { + } else if (STRCMP(format, "tif") == 0) { input_file->vdtype = VIDEO_TIFF; input_file->avi = NULL; - } - else if (STRCMP (format, "avi") == 0) - { + } else if (STRCMP(format, "avi") == 0) { input_file->vdtype = VIDEO_AVI; - } - else - { - //snprintf(errortext, ET_SIZE, "ERROR: video file format not supported"); - //error (errortext, 500); + } else { + // snprintf(errortext, ET_SIZE, "ERROR: video file format not supported"); + // error (errortext, 500); input_file->vdtype = VIDEO_YUV; input_file->format.yuv_format = YUV420; input_file->avi = NULL; diff --git a/src/common/ldecod_src/img_process.c b/src/common/ldecod_src/img_process.c index 9f4d9a9..bd36529 100644 --- a/src/common/ldecod_src/img_process.c +++ b/src/common/ldecod_src/img_process.c @@ -6,42 +6,40 @@ * Input data Image Processing functions * * \author -* Main contributors (see contributors.h for copyright, address and affiliation details) +* Main contributors (see contributors.h for copyright, address and +*affiliation details) * - Alexis Michael Tourapis * ************************************************************************************* */ -#include "contributors.h" -#include "global.h" #include "img_process.h" +#include "contributors.h" +#include "fast_memory.h" +#include "global.h" #include "io_image.h" #include "memalloc.h" -#include "fast_memory.h" +static inline void ResetImage(ImageData *imgOut) { + fast_memset(imgOut->frm_data[0][0], 0, + imgOut->format.height[0] * imgOut->format.width[0] * + sizeof(imgpel)); -static inline void ResetImage(ImageData *imgOut) -{ - fast_memset(imgOut->frm_data[0][0], 0, imgOut->format.height[0] * imgOut->format.width[0] * sizeof (imgpel)); - - if (imgOut->format.yuv_format != YUV400) - { - if (sizeof(imgpel) == sizeof(signed char)) - { - fast_memset(imgOut->frm_data[1][0], 128, imgOut->format.height[1] * imgOut->format.width[1] * sizeof (imgpel)); - fast_memset(imgOut->frm_data[2][0], 128, imgOut->format.height[1] * imgOut->format.width[1] * sizeof (imgpel)); - } - else - { + if (imgOut->format.yuv_format != YUV400) { + if (sizeof(imgpel) == sizeof(signed char)) { + fast_memset(imgOut->frm_data[1][0], 128, + imgOut->format.height[1] * imgOut->format.width[1] * + sizeof(imgpel)); + fast_memset(imgOut->frm_data[2][0], 128, + imgOut->format.height[1] * imgOut->format.width[1] * + sizeof(imgpel)); + } else { int i, j, k; imgpel med_value; - for (k = 1; k <=2; k++) - { - med_value = (imgpel) (imgOut->format.max_value[k] + 1) >> 1; - for (j = 0; j < imgOut->format.height[1]; j++) - { - for (i = 0; i < imgOut->format.width[1]; i++) - { + for (k = 1; k <= 2; k++) { + med_value = (imgpel)(imgOut->format.max_value[k] + 1) >> 1; + for (j = 0; j < imgOut->format.height[1]; j++) { + for (i = 0; i < imgOut->format.width[1]; i++) { imgOut->frm_data[k][j][i] = med_value; } } @@ -50,124 +48,129 @@ static inline void ResetImage(ImageData *imgOut) } } +static inline void CPImage(ImageData *imgOut, ImageData *imgIn) { + memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], + imgIn->format.height[0] * imgIn->format.width[0] * sizeof(imgpel)); -static inline void CPImage(ImageData *imgOut, ImageData *imgIn) -{ - memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], imgIn->format.height[0] * imgIn->format.width[0] * sizeof (imgpel)); - - if (imgIn->format.yuv_format != YUV400) - { - memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); - memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); + if (imgIn->format.yuv_format != YUV400) { + memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0], + imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel)); + memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0], + imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel)); } } // to be modified -static inline void FilterImage(ImageData *imgOut, ImageData *imgIn) -{ - memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], imgIn->format.height[0] * imgIn->format.width[0] * sizeof (imgpel)); +static inline void FilterImage(ImageData *imgOut, ImageData *imgIn) { + memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], + imgIn->format.height[0] * imgIn->format.width[0] * sizeof(imgpel)); - if (imgIn->format.yuv_format != YUV400) - { - memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); - memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); + if (imgIn->format.yuv_format != YUV400) { + memcpy(imgOut->frm_data[1][0], imgIn->frm_data[1][0], + imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel)); + memcpy(imgOut->frm_data[2][0], imgIn->frm_data[2][0], + imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel)); } } // Line interleaving for 3:2 pulldown -static inline void BlendImageLines(ImageData *imgIn0, ImageData *imgIn1) -{ +static inline void BlendImageLines(ImageData *imgIn0, ImageData *imgIn1) { int j; for (j = 1; j < imgIn1->format.height[0]; j += 2) - memcpy(imgIn0->frm_data[0][j], imgIn1->frm_data[0][j], imgIn1->format.width[0] * sizeof (imgpel)); + memcpy(imgIn0->frm_data[0][j], imgIn1->frm_data[0][j], + imgIn1->format.width[0] * sizeof(imgpel)); - if (imgIn1->format.yuv_format != YUV400) - { - for (j = 1; j < imgIn1->format.height[1]; j += 2) - { - memcpy(imgIn0->frm_data[1][j], imgIn1->frm_data[1][j], imgIn1->format.width[1] * sizeof (imgpel)); + if (imgIn1->format.yuv_format != YUV400) { + for (j = 1; j < imgIn1->format.height[1]; j += 2) { + memcpy(imgIn0->frm_data[1][j], imgIn1->frm_data[1][j], + imgIn1->format.width[1] * sizeof(imgpel)); } - for (j = 1; j < imgIn1->format.height[2]; j += 2) - { - memcpy(imgIn0->frm_data[2][j], imgIn1->frm_data[2][j], imgIn1->format.width[2] * sizeof (imgpel)); + for (j = 1; j < imgIn1->format.height[2]; j += 2) { + memcpy(imgIn0->frm_data[2][j], imgIn1->frm_data[2][j], + imgIn1->format.width[2] * sizeof(imgpel)); } } } // to be modified -static inline void FilterImageSep(ImageData *imgOut, ImageData *imgIn) -{ +static inline void FilterImageSep(ImageData *imgOut, ImageData *imgIn) { int i, j; static const int SepFilter[6] = {1, -5, 20, 20, -5, 1}; - int max_width = imgOut->format.width[0] - 1; + int max_width = imgOut->format.width[0] - 1; int max_height = imgOut->format.height[0] - 1; - int **temp_data = new_mem2Dint(imgIn->format.height[0], imgIn->format.width[0]); // temp memory for filtering. Could be allocated once to speed up code + int **temp_data = new_mem2Dint( + imgIn->format.height[0], + imgIn->format.width[0]); // temp memory for filtering. Could be allocated + // once to speed up code // implementation was not optimized. only just implemented as proof of concept // horizontal filtering - for (j = 0; j < imgOut->format.height[0]; j++) - { - for (i = 0; i < imgOut->format.width[0]; i++) - { - temp_data[j][i] = - SepFilter[0] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 2)] + - SepFilter[1] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 1)] + - SepFilter[2] * imgIn->frm_data[0][j][iClip3(0, max_width, i )] + - SepFilter[3] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 1)] + - SepFilter[4] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 2)] + - SepFilter[5] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 3)]; + for (j = 0; j < imgOut->format.height[0]; j++) { + for (i = 0; i < imgOut->format.width[0]; i++) { + temp_data[j][i] = + SepFilter[0] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 2)] + + SepFilter[1] * imgIn->frm_data[0][j][iClip3(0, max_width, i - 1)] + + SepFilter[2] * imgIn->frm_data[0][j][iClip3(0, max_width, i)] + + SepFilter[3] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 1)] + + SepFilter[4] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 2)] + + SepFilter[5] * imgIn->frm_data[0][j][iClip3(0, max_width, i + 3)]; } } - for (j = 0; j < imgOut->format.height[0]; j++) - { - for (i = 0; i < imgOut->format.width[0]; i++) - { - imgOut->frm_data[0][j][i] = (imgpel) iClip3(0, imgOut->format.max_value[0], rshift_rnd_sign( - SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] + - SepFilter[1] * temp_data[iClip3(0, max_height, j - 1)][i] + - SepFilter[2] * temp_data[iClip3(0, max_height, j )][i] + - SepFilter[3] * temp_data[iClip3(0, max_height, j + 1)][i] + - SepFilter[4] * temp_data[iClip3(0, max_height, j + 2)][i] + - SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i], 10)); + for (j = 0; j < imgOut->format.height[0]; j++) { + for (i = 0; i < imgOut->format.width[0]; i++) { + imgOut->frm_data[0][j][i] = (imgpel)iClip3( + 0, imgOut->format.max_value[0], + rshift_rnd_sign( + SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] + + SepFilter[1] * temp_data[iClip3(0, max_height, j - 1)][i] + + SepFilter[2] * temp_data[iClip3(0, max_height, j)][i] + + SepFilter[3] * temp_data[iClip3(0, max_height, j + 1)][i] + + SepFilter[4] * temp_data[iClip3(0, max_height, j + 2)][i] + + SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i], + 10)); } } - if (imgOut->format.yuv_format != YUV400) - { + if (imgOut->format.yuv_format != YUV400) { int k; - max_width = imgOut->format.width[1] - 1; + max_width = imgOut->format.width[1] - 1; max_height = imgOut->format.height[1] - 1; - for (k = 1; k <=2; k++) - { + for (k = 1; k <= 2; k++) { // horizontal filtering - for (j = 0; j < imgOut->format.height[1]; j++) - { - for (i = 0; i < imgOut->format.width[1]; i++) - { - temp_data[j][i] = - SepFilter[0] * imgIn->frm_data[k][j][iClip3(0, max_width, i - 2)] + - SepFilter[1] * imgIn->frm_data[k][j][iClip3(0, max_width, i - 1)] + - SepFilter[2] * imgIn->frm_data[k][j][iClip3(0, max_width, i )] + - SepFilter[3] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 1)] + - SepFilter[4] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 2)] + - SepFilter[5] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 3)]; + for (j = 0; j < imgOut->format.height[1]; j++) { + for (i = 0; i < imgOut->format.width[1]; i++) { + temp_data[j][i] = + SepFilter[0] * + imgIn->frm_data[k][j][iClip3(0, max_width, i - 2)] + + SepFilter[1] * + imgIn->frm_data[k][j][iClip3(0, max_width, i - 1)] + + SepFilter[2] * imgIn->frm_data[k][j][iClip3(0, max_width, i)] + + SepFilter[3] * + imgIn->frm_data[k][j][iClip3(0, max_width, i + 1)] + + SepFilter[4] * + imgIn->frm_data[k][j][iClip3(0, max_width, i + 2)] + + SepFilter[5] * imgIn->frm_data[k][j][iClip3(0, max_width, i + 3)]; } } - for (j = 0; j < imgOut->format.height[1]; j++) - { - for (i = 0; i < imgOut->format.width[1]; i++) - { - imgOut->frm_data[k][j][i] = (imgpel) iClip3(0, imgOut->format.max_value[k], rshift_rnd_sign( - SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] + - SepFilter[1] * temp_data[iClip3(0, max_height, j - 1)][i] + - SepFilter[2] * temp_data[iClip3(0, max_height, j )][i] + - SepFilter[3] * temp_data[iClip3(0, max_height, j + 1)][i] + - SepFilter[4] * temp_data[iClip3(0, max_height, j + 2)][i] + - SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i], 10)); + for (j = 0; j < imgOut->format.height[1]; j++) { + for (i = 0; i < imgOut->format.width[1]; i++) { + imgOut->frm_data[k][j][i] = (imgpel)iClip3( + 0, imgOut->format.max_value[k], + rshift_rnd_sign( + SepFilter[0] * temp_data[iClip3(0, max_height, j - 2)][i] + + SepFilter[1] * + temp_data[iClip3(0, max_height, j - 1)][i] + + SepFilter[2] * temp_data[iClip3(0, max_height, j)][i] + + SepFilter[3] * + temp_data[iClip3(0, max_height, j + 1)][i] + + SepFilter[4] * + temp_data[iClip3(0, max_height, j + 2)][i] + + SepFilter[5] * temp_data[iClip3(0, max_height, j + 3)][i], + 10)); } } } @@ -176,70 +179,66 @@ static inline void FilterImageSep(ImageData *imgOut, ImageData *imgIn) free_mem2Dint(temp_data); } - // to be modified -static inline void MuxImages(ImageData *imgOut, ImageData *imgIn0, ImageData *imgIn1, ImageData *Map) -{ +static inline void MuxImages(ImageData *imgOut, ImageData *imgIn0, + ImageData *imgIn1, ImageData *Map) { int i, j; - for (j = 0; j < imgOut->format.height[0]; j++) - { - for (i = 0; i < imgOut->format.width[0]; i++) - { - imgOut->frm_data[0][j][i] = (imgpel) rshift_rnd_sf(imgIn0->frm_data[0][j][i] * (Map->format.max_value[0] - Map->frm_data[0][j][i]) + imgIn1->frm_data[0][j][i] * Map->frm_data[0][j][i], Map->format.bit_depth[0]); + for (j = 0; j < imgOut->format.height[0]; j++) { + for (i = 0; i < imgOut->format.width[0]; i++) { + imgOut->frm_data[0][j][i] = (imgpel)rshift_rnd_sf( + imgIn0->frm_data[0][j][i] * + (Map->format.max_value[0] - Map->frm_data[0][j][i]) + + imgIn1->frm_data[0][j][i] * Map->frm_data[0][j][i], + Map->format.bit_depth[0]); } } - - if (imgOut->format.yuv_format != YUV400) - { + + if (imgOut->format.yuv_format != YUV400) { int k; - for (k = 1; k <=2; k++) - { - for (j = 0; j < imgOut->format.height[1]; j++) - { - for (i = 0; i < imgOut->format.width[1]; i++) - { - imgOut->frm_data[k][j][i] = (imgpel) rshift_rnd_sf(imgIn0->frm_data[k][j][i] * (Map->format.max_value[k] - Map->frm_data[k][j][i]) + imgIn1->frm_data[k][j][i] * Map->frm_data[k][j][i], Map->format.bit_depth[k]); + for (k = 1; k <= 2; k++) { + for (j = 0; j < imgOut->format.height[1]; j++) { + for (i = 0; i < imgOut->format.width[1]; i++) { + imgOut->frm_data[k][j][i] = (imgpel)rshift_rnd_sf( + imgIn0->frm_data[k][j][i] * + (Map->format.max_value[k] - Map->frm_data[k][j][i]) + + imgIn1->frm_data[k][j][i] * Map->frm_data[k][j][i], + Map->format.bit_depth[k]); } } } } } -static inline void YV12toYUV(ImageData *imgOut, ImageData *imgIn) -{ - memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], imgIn->format.height[0] * imgIn->format.width[0] * sizeof (imgpel)); +static inline void YV12toYUV(ImageData *imgOut, ImageData *imgIn) { + memcpy(imgOut->frm_data[0][0], imgIn->frm_data[0][0], + imgIn->format.height[0] * imgIn->format.width[0] * sizeof(imgpel)); - if (imgIn->format.yuv_format != YUV400) - { - memcpy(imgOut->frm_data[1][0], imgIn->frm_data[2][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); - memcpy(imgOut->frm_data[2][0], imgIn->frm_data[1][0], imgIn->format.height[1] * imgIn->format.width[1] * sizeof (imgpel)); + if (imgIn->format.yuv_format != YUV400) { + memcpy(imgOut->frm_data[1][0], imgIn->frm_data[2][0], + imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel)); + memcpy(imgOut->frm_data[2][0], imgIn->frm_data[1][0], + imgIn->format.height[1] * imgIn->format.width[1] * sizeof(imgpel)); } } -int init_process_image( VideoParameters *p_Vid, InputParameters *p_Inp) -{ +int init_process_image(VideoParameters *p_Vid, InputParameters *p_Inp) { int memory_size = 0; - switch( p_Inp->ProcessInput ) - { + switch (p_Inp->ProcessInput) { default: break; } return memory_size; } -void clear_process_image( VideoParameters *p_Vid, InputParameters *p_Inp) -{ - switch( p_Inp->ProcessInput ) - { +void clear_process_image(VideoParameters *p_Vid, InputParameters *p_Inp) { + switch (p_Inp->ProcessInput) { default: break; - } + } } -void process_image( VideoParameters *p_Vid, InputParameters *p_Inp ) -{ - switch( p_Inp->ProcessInput ) - { +void process_image(VideoParameters *p_Vid, InputParameters *p_Inp) { + switch (p_Inp->ProcessInput) { default: case 0: CPImage(&p_Vid->imgData, &p_Vid->imgData0); @@ -248,33 +247,31 @@ void process_image( VideoParameters *p_Vid, InputParameters *p_Inp ) break; case 1: FilterImage(&p_Vid->imgData, &p_Vid->imgData0); - if (p_Inp->enable_32_pulldown) - { + if (p_Inp->enable_32_pulldown) { FilterImage(&p_Vid->imgData32, &p_Vid->imgData4); BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32); } break; case 2: YV12toYUV(&p_Vid->imgData, &p_Vid->imgData0); - if (p_Inp->enable_32_pulldown) - { + if (p_Inp->enable_32_pulldown) { YV12toYUV(&p_Vid->imgData32, &p_Vid->imgData4); BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32); } break; case 3: - MuxImages(&p_Vid->imgData, &p_Vid->imgData0, &p_Vid->imgData1, &p_Vid->imgData2); - if (p_Inp->enable_32_pulldown) - { - MuxImages(&p_Vid->imgData32, &p_Vid->imgData4, &p_Vid->imgData5, &p_Vid->imgData6); + MuxImages(&p_Vid->imgData, &p_Vid->imgData0, &p_Vid->imgData1, + &p_Vid->imgData2); + if (p_Inp->enable_32_pulldown) { + MuxImages(&p_Vid->imgData32, &p_Vid->imgData4, &p_Vid->imgData5, + &p_Vid->imgData6); BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32); } break; case 4: FilterImageSep(&p_Vid->imgData, &p_Vid->imgData0); - if (p_Inp->enable_32_pulldown) - { + if (p_Inp->enable_32_pulldown) { FilterImageSep(&p_Vid->imgData, &p_Vid->imgData4); BlendImageLines(&p_Vid->imgData, &p_Vid->imgData32); } @@ -282,6 +279,3 @@ void process_image( VideoParameters *p_Vid, InputParameters *p_Inp ) break; } } - - - diff --git a/src/common/ldecod_src/inc/annexb.h b/src/common/ldecod_src/inc/annexb.h index 77ca28c..04cb8e9 100644 --- a/src/common/ldecod_src/inc/annexb.h +++ b/src/common/ldecod_src/inc/annexb.h @@ -14,9 +14,8 @@ #include "nalucommon.h" -typedef struct annex_b_struct -{ - int BitStreamFile; //!< the bit stream file +typedef struct annex_b_struct { + int BitStreamFile; //!< the bit stream file byte *iobuffer; byte *iobufferread; int bytesinbuffer; @@ -25,15 +24,14 @@ typedef struct annex_b_struct int IsFirstByteStreamNALU; int nextstartcodebytes; - byte *Buf; + byte *Buf; } ANNEXB_t; -extern int GetAnnexbNALU (VideoParameters *p_Vid, NALU_t *nalu); -extern void OpenAnnexBFile (VideoParameters *p_Vid, char *fn); +extern int GetAnnexbNALU(VideoParameters *p_Vid, NALU_t *nalu); +extern void OpenAnnexBFile(VideoParameters *p_Vid, char *fn); extern void CloseAnnexBFile(VideoParameters *p_Vid); -extern void malloc_annex_b (VideoParameters *p_Vid); -extern void free_annex_b (VideoParameters *p_Vid); -extern void init_annex_b (ANNEXB_t *annex_b); -extern void ResetAnnexB (ANNEXB_t *annex_b); +extern void malloc_annex_b(VideoParameters *p_Vid); +extern void free_annex_b(VideoParameters *p_Vid); +extern void init_annex_b(ANNEXB_t *annex_b); +extern void ResetAnnexB(ANNEXB_t *annex_b); #endif - diff --git a/src/common/ldecod_src/inc/biaridecod.h b/src/common/ldecod_src/inc/biaridecod.h index feb87fb..86ba8b5 100644 --- a/src/common/ldecod_src/inc/biaridecod.h +++ b/src/common/ldecod_src/inc/biaridecod.h @@ -20,116 +20,63 @@ #ifndef _BIARIDECOD_H_ #define _BIARIDECOD_H_ - /************************************************************************ * D e f i n i t i o n s *********************************************************************** */ /* Range table for LPS */ -static const byte rLPS_table_64x4[64][4]= -{ - { 128, 176, 208, 240}, - { 128, 167, 197, 227}, - { 128, 158, 187, 216}, - { 123, 150, 178, 205}, - { 116, 142, 169, 195}, - { 111, 135, 160, 185}, - { 105, 128, 152, 175}, - { 100, 122, 144, 166}, - { 95, 116, 137, 158}, - { 90, 110, 130, 150}, - { 85, 104, 123, 142}, - { 81, 99, 117, 135}, - { 77, 94, 111, 128}, - { 73, 89, 105, 122}, - { 69, 85, 100, 116}, - { 66, 80, 95, 110}, - { 62, 76, 90, 104}, - { 59, 72, 86, 99}, - { 56, 69, 81, 94}, - { 53, 65, 77, 89}, - { 51, 62, 73, 85}, - { 48, 59, 69, 80}, - { 46, 56, 66, 76}, - { 43, 53, 63, 72}, - { 41, 50, 59, 69}, - { 39, 48, 56, 65}, - { 37, 45, 54, 62}, - { 35, 43, 51, 59}, - { 33, 41, 48, 56}, - { 32, 39, 46, 53}, - { 30, 37, 43, 50}, - { 29, 35, 41, 48}, - { 27, 33, 39, 45}, - { 26, 31, 37, 43}, - { 24, 30, 35, 41}, - { 23, 28, 33, 39}, - { 22, 27, 32, 37}, - { 21, 26, 30, 35}, - { 20, 24, 29, 33}, - { 19, 23, 27, 31}, - { 18, 22, 26, 30}, - { 17, 21, 25, 28}, - { 16, 20, 23, 27}, - { 15, 19, 22, 25}, - { 14, 18, 21, 24}, - { 14, 17, 20, 23}, - { 13, 16, 19, 22}, - { 12, 15, 18, 21}, - { 12, 14, 17, 20}, - { 11, 14, 16, 19}, - { 11, 13, 15, 18}, - { 10, 12, 15, 17}, - { 10, 12, 14, 16}, - { 9, 11, 13, 15}, - { 9, 11, 12, 14}, - { 8, 10, 12, 14}, - { 8, 9, 11, 13}, - { 7, 9, 11, 12}, - { 7, 9, 10, 12}, - { 7, 8, 10, 11}, - { 6, 8, 9, 11}, - { 6, 7, 9, 10}, - { 6, 7, 8, 9}, - { 2, 2, 2, 2} -}; +static const byte rLPS_table_64x4[64][4] = { + {128, 176, 208, 240}, {128, 167, 197, 227}, {128, 158, 187, 216}, + {123, 150, 178, 205}, {116, 142, 169, 195}, {111, 135, 160, 185}, + {105, 128, 152, 175}, {100, 122, 144, 166}, {95, 116, 137, 158}, + {90, 110, 130, 150}, {85, 104, 123, 142}, {81, 99, 117, 135}, + {77, 94, 111, 128}, {73, 89, 105, 122}, {69, 85, 100, 116}, + {66, 80, 95, 110}, {62, 76, 90, 104}, {59, 72, 86, 99}, + {56, 69, 81, 94}, {53, 65, 77, 89}, {51, 62, 73, 85}, + {48, 59, 69, 80}, {46, 56, 66, 76}, {43, 53, 63, 72}, + {41, 50, 59, 69}, {39, 48, 56, 65}, {37, 45, 54, 62}, + {35, 43, 51, 59}, {33, 41, 48, 56}, {32, 39, 46, 53}, + {30, 37, 43, 50}, {29, 35, 41, 48}, {27, 33, 39, 45}, + {26, 31, 37, 43}, {24, 30, 35, 41}, {23, 28, 33, 39}, + {22, 27, 32, 37}, {21, 26, 30, 35}, {20, 24, 29, 33}, + {19, 23, 27, 31}, {18, 22, 26, 30}, {17, 21, 25, 28}, + {16, 20, 23, 27}, {15, 19, 22, 25}, {14, 18, 21, 24}, + {14, 17, 20, 23}, {13, 16, 19, 22}, {12, 15, 18, 21}, + {12, 14, 17, 20}, {11, 14, 16, 19}, {11, 13, 15, 18}, + {10, 12, 15, 17}, {10, 12, 14, 16}, {9, 11, 13, 15}, + {9, 11, 12, 14}, {8, 10, 12, 14}, {8, 9, 11, 13}, + {7, 9, 11, 12}, {7, 9, 10, 12}, {7, 8, 10, 11}, + {6, 8, 9, 11}, {6, 7, 9, 10}, {6, 7, 8, 9}, + {2, 2, 2, 2}}; +static const byte AC_next_state_MPS_64[64] = { + 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, 62, 63}; -static const byte AC_next_state_MPS_64[64] = -{ - 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,62,63 -}; +static const byte AC_next_state_LPS_64[64] = { + 0, 0, 1, 2, 2, 4, 4, 5, 6, 7, 8, 9, 9, 11, 11, 12, + 13, 13, 15, 15, 16, 16, 18, 18, 19, 19, 21, 21, 22, 22, 23, 24, + 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 30, 30, 31, 32, 32, 33, + 33, 33, 34, 34, 35, 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 63}; +static const byte renorm_table_32[32] = {6, 5, 4, 4, 3, 3, 3, 3, 2, 2, 2, + 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; -static const byte AC_next_state_LPS_64[64] = -{ - 0, 0, 1, 2, 2, 4, 4, 5, 6, 7, - 8, 9, 9,11,11,12,13,13,15,15, - 16,16,18,18,19,19,21,21,22,22, - 23,24,24,25,26,26,27,27,28,29, - 29,30,30,30,31,32,32,33,33,33, - 34,34,35,35,35,36,36,36,37,37, - 37,38,38,63 -}; - -static const byte renorm_table_32[32]={6,5,4,4,3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; - - -extern void arideco_start_decoding(DecodingEnvironmentPtr eep, unsigned char *code_buffer, int firstbyte, int *code_len); -extern int arideco_bits_read(DecodingEnvironmentPtr dep); +extern void arideco_start_decoding(DecodingEnvironmentPtr eep, + unsigned char *code_buffer, int firstbyte, + int *code_len); +extern int arideco_bits_read(DecodingEnvironmentPtr dep); extern void arideco_done_decoding(DecodingEnvironmentPtr dep); -extern void biari_init_context (int qp, BiContextTypePtr ctx, const signed char* ini); -extern unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, BiContextTypePtr bi_ct ); +extern void biari_init_context(int qp, BiContextTypePtr ctx, + const signed char *ini); +extern unsigned int biari_decode_symbol(DecodingEnvironmentPtr dep, + BiContextTypePtr bi_ct); extern unsigned int biari_decode_symbol_eq_prob(DecodingEnvironmentPtr dep); extern unsigned int biari_decode_final(DecodingEnvironmentPtr dep); extern unsigned int getbyte(DecodingEnvironmentPtr dep); extern unsigned int getword(DecodingEnvironmentPtr dep); -#endif // BIARIDECOD_H_ - +#endif // BIARIDECOD_H_ diff --git a/src/common/ldecod_src/inc/blk_prediction.h b/src/common/ldecod_src/inc/blk_prediction.h index 0ada43d..3809cb5 100644 --- a/src/common/ldecod_src/inc/blk_prediction.h +++ b/src/common/ldecod_src/inc/blk_prediction.h @@ -8,7 +8,7 @@ * block prediction header * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * @@ -19,7 +19,9 @@ #define _BLK_PREDICTION_H_ #include "mbuffer.h" -extern void compute_residue (imgpel **curImg, imgpel **mb_pred, int **mb_rres, int mb_x, int opix_x, int width, int height); -extern void sample_reconstruct (imgpel **curImg, imgpel **mb_pred, int **mb_rres, int mb_x, int opix_x, int width, int height, int max_imgpel_value, int dq_bits); +extern void compute_residue(imgpel **curImg, imgpel **mb_pred, int **mb_rres, + int mb_x, int opix_x, int width, int height); +extern void sample_reconstruct(imgpel **curImg, imgpel **mb_pred, int **mb_rres, + int mb_x, int opix_x, int width, int height, + int max_imgpel_value, int dq_bits); #endif - diff --git a/src/common/ldecod_src/inc/block.h b/src/common/ldecod_src/inc/block.h index 31158a7..8941412 100644 --- a/src/common/ldecod_src/inc/block.h +++ b/src/common/ldecod_src/inc/block.h @@ -21,111 +21,101 @@ #include "global.h" #include "transform8x8.h" -static const byte QP_SCALE_CR[52]= -{ - 0, 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,29,30,31,32,32,33,34,34,35,35,36,36,37,37, - 37,38,38,38,39,39,39,39 +static const byte QP_SCALE_CR[52] = { + 0, 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, 29, 30, 31, 32, 32, 33, + 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 39 }; //! look up tables for FRExt_chroma support -static const unsigned char subblk_offset_x[3][8][4] = -{ - { - {0, 4, 0, 4}, - {0, 4, 0, 4}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - }, - { - {0, 4, 0, 4}, - {0, 4, 0, 4}, - {0, 4, 0, 4}, - {0, 4, 0, 4}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - }, - { - {0, 4, 0, 4}, - {8,12, 8,12}, - {0, 4, 0, 4}, - {8,12, 8,12}, - {0, 4, 0, 4}, - {8,12, 8,12}, - {0, 4, 0, 4}, - {8,12, 8,12} - } -}; +static const unsigned char subblk_offset_x[3][8][4] = {{ + {0, 4, 0, 4}, + {0, 4, 0, 4}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + }, + { + {0, 4, 0, 4}, + {0, 4, 0, 4}, + {0, 4, 0, 4}, + {0, 4, 0, 4}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + }, + {{0, 4, 0, 4}, + {8, 12, 8, 12}, + {0, 4, 0, 4}, + {8, 12, 8, 12}, + {0, 4, 0, 4}, + {8, 12, 8, 12}, + {0, 4, 0, 4}, + {8, 12, 8, 12}}}; +static const unsigned char subblk_offset_y[3][8][4] = {{{0, 0, 4, 4}, + {0, 0, 4, 4}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}}, + {{0, 0, 4, 4}, + {8, 8, 12, 12}, + {0, 0, 4, 4}, + {8, 8, 12, 12}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}}, + {{0, 0, 4, 4}, + {0, 0, 4, 4}, + {8, 8, 12, 12}, + {8, 8, 12, 12}, + {0, 0, 4, 4}, + {0, 0, 4, 4}, + {8, 8, 12, 12}, + {8, 8, 12, 12}}}; -static const unsigned char subblk_offset_y[3][8][4] = -{ - { - {0, 0, 4, 4}, - {0, 0, 4, 4}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0} - }, - { - {0, 0, 4, 4}, - {8, 8,12,12}, - {0, 0, 4, 4}, - {8, 8,12,12}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0} - }, - { - {0, 0, 4, 4}, - {0, 0, 4, 4}, - {8, 8,12,12}, - {8, 8,12,12}, - {0, 0, 4, 4}, - {0, 0, 4, 4}, - {8, 8,12,12}, - {8, 8,12,12} - } -}; - -static const byte decode_block_scan[16] = {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15}; +static const byte decode_block_scan[16] = {0, 1, 4, 5, 2, 3, 6, 7, + 8, 9, 12, 13, 10, 11, 14, 15}; extern void iMBtrans4x4(Macroblock *currMB, ColorPlane pl, int smb); extern void iMBtrans8x8(Macroblock *currMB, ColorPlane pl); extern void itrans_sp_cr(Macroblock *currMB, int uv); -extern void intrapred_chroma (Macroblock *currMB); +extern void intrapred_chroma(Macroblock *currMB); extern void intrapred_chroma_mbaff(Macroblock *currMB); -extern void Inv_Residual_trans_4x4(Macroblock *currMB, ColorPlane pl, int ioff, int joff); -extern void Inv_Residual_trans_8x8(Macroblock *currMB, ColorPlane pl, int ioff,int joff); -extern void Inv_Residual_trans_16x16 (Macroblock *currMB, ColorPlane pl); +extern void Inv_Residual_trans_4x4(Macroblock *currMB, ColorPlane pl, int ioff, + int joff); +extern void Inv_Residual_trans_8x8(Macroblock *currMB, ColorPlane pl, int ioff, + int joff); +extern void Inv_Residual_trans_16x16(Macroblock *currMB, ColorPlane pl); extern void Inv_Residual_trans_Chroma(Macroblock *currMB, int uv); -extern void itrans4x4 (Macroblock *currMB, ColorPlane pl, int ioff, int joff); +extern void itrans4x4(Macroblock *currMB, ColorPlane pl, int ioff, int joff); extern void itrans4x4_ls(Macroblock *currMB, ColorPlane pl, int ioff, int joff); -extern void itrans_sp (Macroblock *currMB, ColorPlane pl, int ioff, int joff); -extern int intrapred (Macroblock *currMB, ColorPlane pl, int ioff,int joff,int i4,int j4); -extern void itrans_2 (Macroblock *currMB, ColorPlane pl); -extern void iTransform (Macroblock *currMB, ColorPlane pl, int smb); +extern void itrans_sp(Macroblock *currMB, ColorPlane pl, int ioff, int joff); +extern int intrapred(Macroblock *currMB, ColorPlane pl, int ioff, int joff, + int i4, int j4); +extern void itrans_2(Macroblock *currMB, ColorPlane pl); +extern void iTransform(Macroblock *currMB, ColorPlane pl, int smb); -extern void copy_image_data (imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2, int width, int height); -extern void copy_image_data_16x16 (imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2); -extern void copy_image_data_8x8 (imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2); -extern void copy_image_data_4x4 (imgpel **imgBuf1, imgpel **imgBuf2, int off1, int off2); +extern void copy_image_data(imgpel **imgBuf1, imgpel **imgBuf2, int off1, + int off2, int width, int height); +extern void copy_image_data_16x16(imgpel **imgBuf1, imgpel **imgBuf2, int off1, + int off2); +extern void copy_image_data_8x8(imgpel **imgBuf1, imgpel **imgBuf2, int off1, + int off2); +extern void copy_image_data_4x4(imgpel **imgBuf1, imgpel **imgBuf2, int off1, + int off2); extern int CheckVertMV(Macroblock *currMB, int vec1_y, int block_size_y); #endif - diff --git a/src/common/ldecod_src/inc/cabac.h b/src/common/ldecod_src/inc/cabac.h index 8510ffb..975b1a7 100644 --- a/src/common/ldecod_src/inc/cabac.h +++ b/src/common/ldecod_src/inc/cabac.h @@ -21,42 +21,61 @@ #include "global.h" -extern MotionInfoContexts* create_contexts_MotionInfo(void); -extern TextureInfoContexts* create_contexts_TextureInfo(void); +extern MotionInfoContexts *create_contexts_MotionInfo(void); +extern TextureInfoContexts *create_contexts_TextureInfo(void); extern void delete_contexts_MotionInfo(MotionInfoContexts *enco_ctx); extern void delete_contexts_TextureInfo(TextureInfoContexts *enco_ctx); extern void cabac_new_slice(Slice *currSlice); -extern void readMB_typeInfo_CABAC_i_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readMB_typeInfo_CABAC_p_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readMB_typeInfo_CABAC_b_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readB8_typeInfo_CABAC_p_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readB8_typeInfo_CABAC_b_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readIntraPredMode_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readRefFrame_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void read_MVD_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void read_CBP_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readRunLevel_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void read_dQuant_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readCIPredMode_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void read_skip_flag_CABAC_p_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void read_skip_flag_CABAC_b_slice (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readFieldModeInfo_CABAC (Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); -extern void readMB_transform_size_flag_CABAC(Macroblock *currMB, SyntaxElement *se, DecodingEnvironmentPtr dep_dp); +extern void readMB_typeInfo_CABAC_i_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readMB_typeInfo_CABAC_p_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readMB_typeInfo_CABAC_b_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readB8_typeInfo_CABAC_p_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readB8_typeInfo_CABAC_b_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readIntraPredMode_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readRefFrame_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void read_MVD_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void read_CBP_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readRunLevel_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void read_dQuant_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readCIPredMode_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void read_skip_flag_CABAC_p_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void read_skip_flag_CABAC_b_slice(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readFieldModeInfo_CABAC(Macroblock *currMB, SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); +extern void readMB_transform_size_flag_CABAC(Macroblock *currMB, + SyntaxElement *se, + DecodingEnvironmentPtr dep_dp); extern void readIPCM_CABAC(Slice *currSlice, struct datapartition *dP); -extern int cabac_startcode_follows(Slice *currSlice, int eos_bit); +extern int cabac_startcode_follows(Slice *currSlice, int eos_bit); -extern int readSyntaxElement_CABAC (Macroblock *currMB, SyntaxElement *se, DataPartition *this_dataPart); +extern int readSyntaxElement_CABAC(Macroblock *currMB, SyntaxElement *se, + DataPartition *this_dataPart); -extern int check_next_mb_and_get_field_mode_CABAC_p_slice( Slice *currSlice, SyntaxElement *se, DataPartition *act_dp); -extern int check_next_mb_and_get_field_mode_CABAC_b_slice( Slice *currSlice, SyntaxElement *se, DataPartition *act_dp); +extern int check_next_mb_and_get_field_mode_CABAC_p_slice( + Slice *currSlice, SyntaxElement *se, DataPartition *act_dp); +extern int check_next_mb_and_get_field_mode_CABAC_b_slice( + Slice *currSlice, SyntaxElement *se, DataPartition *act_dp); extern void CheckAvailabilityOfNeighborsCABAC(Macroblock *currMB); extern void set_read_and_store_CBP(Macroblock **currMB, int chroma_format_idc); -#endif // _CABAC_H_ - +#endif // _CABAC_H_ diff --git a/src/common/ldecod_src/inc/config_common.h b/src/common/ldecod_src/inc/config_common.h index d3d42d7..fe2ea89 100644 --- a/src/common/ldecod_src/inc/config_common.h +++ b/src/common/ldecod_src/inc/config_common.h @@ -7,7 +7,8 @@ * Common Config parsing functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Alexis Tourapis * ************************************************************************ @@ -17,19 +18,22 @@ //! Maps parameter name to its address, type etc. typedef struct { - char *TokenName; //!< name - void *Place; //!< address - int Type; //!< type: 0-int, 1-char[], 2-double - double Default; //!< default value - int param_limits; //!< 0: no limits, 1: both min and max, 2: only min (i.e. no negatives), 3: special case for QPs since min needs bitdepth_qp_scale + char *TokenName; //!< name + void *Place; //!< address + int Type; //!< type: 0-int, 1-char[], 2-double + double Default; //!< default value + int param_limits; //!< 0: no limits, 1: both min and max, 2: only min (i.e. no + //!< negatives), 3: special case for QPs since min needs + //!< bitdepth_qp_scale double min_limit; double max_limit; - int char_size; //!< Dimension of type char[] + int char_size; //!< Dimension of type char[] } Mapping; -extern char *GetConfigFileContent (char *Filename); -extern int InitParams (Mapping *Map); -extern int TestParams (Mapping *Map, int bitdepth_qp_scale[3]); -extern int DisplayParams (Mapping *Map, char *message); -extern void ParseContent (InputParameters *p_Inp, Mapping *Map, char *buf, int bufsize); +extern char *GetConfigFileContent(char *Filename); +extern int InitParams(Mapping *Map); +extern int TestParams(Mapping *Map, int bitdepth_qp_scale[3]); +extern int DisplayParams(Mapping *Map, char *message); +extern void ParseContent(InputParameters *p_Inp, Mapping *Map, char *buf, + int bufsize); #endif diff --git a/src/common/ldecod_src/inc/configfile.h b/src/common/ldecod_src/inc/configfile.h index 12ed1cc..3d72fb9 100644 --- a/src/common/ldecod_src/inc/configfile.h +++ b/src/common/ldecod_src/inc/configfile.h @@ -14,51 +14,86 @@ #define DEFAULTCONFIGFILENAME "decoder.cfg" #include "config_common.h" -//#define PROFILE_IDC 88 -//#define LEVEL_IDC 21 - +// #define PROFILE_IDC 88 +// #define LEVEL_IDC 21 InputParameters cfgparams; #ifdef INCLUDED_BY_CONFIGFILE_C // Mapping_Map Syntax: -// {NAMEinConfigFile, &cfgparams.VariableName, Type, InitialValue, LimitType, MinLimit, MaxLimit, CharSize} -// Types : {0:int, 1:text, 2: double} -// LimitType: {0:none, 1:both, 2:minimum, 3: QP based} -// We could separate this based on types to make it more flexible and allow also defaults for text types. +// {NAMEinConfigFile, &cfgparams.VariableName, Type, InitialValue, LimitType, +// MinLimit, MaxLimit, CharSize} Types : {0:int, 1:text, 2: double} LimitType: +// {0:none, 1:both, 2:minimum, 3: QP based} We could separate this based on +// types to make it more flexible and allow also defaults for text types. Mapping Map[] = { - {"InputFile", &cfgparams.infile, 1, 0.0, 0, 0.0, 0.0, FILE_NAME_SIZE, }, - {"OutputFile", &cfgparams.outfile, 1, 0.0, 0, 0.0, 0.0, FILE_NAME_SIZE, }, - {"RefFile", &cfgparams.reffile, 1, 0.0, 0, 0.0, 0.0, FILE_NAME_SIZE, }, - {"WriteUV", &cfgparams.write_uv, 0, 0.0, 1, 0.0, 1.0, 0 }, - {"FileFormat", &cfgparams.FileFormat, 0, 0.0, 1, 0.0, 1.0, 0 }, - {"RefOffset", &cfgparams.ref_offset, 0, 0.0, 1, 0.0, 256.0, 0 }, - {"POCScale", &cfgparams.poc_scale, 0, 2.0, 1, 1.0, 10.0, 0 }, + { + "InputFile", + &cfgparams.infile, + 1, + 0.0, + 0, + 0.0, + 0.0, + FILE_NAME_SIZE, + }, + { + "OutputFile", + &cfgparams.outfile, + 1, + 0.0, + 0, + 0.0, + 0.0, + FILE_NAME_SIZE, + }, + { + "RefFile", + &cfgparams.reffile, + 1, + 0.0, + 0, + 0.0, + 0.0, + FILE_NAME_SIZE, + }, + {"WriteUV", &cfgparams.write_uv, 0, 0.0, 1, 0.0, 1.0, 0}, + {"FileFormat", &cfgparams.FileFormat, 0, 0.0, 1, 0.0, 1.0, 0}, + {"RefOffset", &cfgparams.ref_offset, 0, 0.0, 1, 0.0, 256.0, 0}, + {"POCScale", &cfgparams.poc_scale, 0, 2.0, 1, 1.0, 10.0, 0}, #ifdef _LEAKYBUCKET_ - {"R_decoder", &cfgparams.R_decoder, 0, 0.0, 2, 0.0, 0.0, 0 }, - {"B_decoder", &cfgparams.B_decoder, 0, 0.0, 2, 0.0, 0.0, 0 }, - {"F_decoder", &cfgparams.F_decoder, 0, 0.0, 2, 0.0, 0.0, 0 }, - {"LeakyBucketParamFile", &cfgparams.LeakyBucketParamFile, 1, 0.0, 0, 0.0, 0.0, FILE_NAME_SIZE, }, + {"R_decoder", &cfgparams.R_decoder, 0, 0.0, 2, 0.0, 0.0, 0}, + {"B_decoder", &cfgparams.B_decoder, 0, 0.0, 2, 0.0, 0.0, 0}, + {"F_decoder", &cfgparams.F_decoder, 0, 0.0, 2, 0.0, 0.0, 0}, + { + "LeakyBucketParamFile", + &cfgparams.LeakyBucketParamFile, + 1, + 0.0, + 0, + 0.0, + 0.0, + FILE_NAME_SIZE, + }, #endif - {"DisplayDecParams", &cfgparams.bDisplayDecParams, 0, 1.0, 1, 0.0, 1.0, 0 }, - {"ConcealMode", &cfgparams.conceal_mode, 0, 0.0, 1, 0.0, 2.0, 0 }, - {"RefPOCGap", &cfgparams.ref_poc_gap, 0, 2.0, 1, 0.0, 4.0, 0 }, - {"POCGap", &cfgparams.poc_gap, 0, 2.0, 1, 0.0, 4.0, 0 }, - {"Silent", &cfgparams.silent, 0, 0.0, 1, 0.0, 1.0, 0 }, - {"IntraProfileDeblocking", &cfgparams.intra_profile_deblocking, 0, 1.0, 1, 0.0, 1.0, 0 }, - {"DecFrmNum", &cfgparams.iDecFrmNum, 0, 0.0, 2, 0.0, 0.0, 0 }, + {"DisplayDecParams", &cfgparams.bDisplayDecParams, 0, 1.0, 1, 0.0, 1.0, 0}, + {"ConcealMode", &cfgparams.conceal_mode, 0, 0.0, 1, 0.0, 2.0, 0}, + {"RefPOCGap", &cfgparams.ref_poc_gap, 0, 2.0, 1, 0.0, 4.0, 0}, + {"POCGap", &cfgparams.poc_gap, 0, 2.0, 1, 0.0, 4.0, 0}, + {"Silent", &cfgparams.silent, 0, 0.0, 1, 0.0, 1.0, 0}, + {"IntraProfileDeblocking", &cfgparams.intra_profile_deblocking, 0, 1.0, 1, + 0.0, 1.0, 0}, + {"DecFrmNum", &cfgparams.iDecFrmNum, 0, 0.0, 2, 0.0, 0.0, 0}, #if (MVC_EXTENSION_ENABLE) - {"DecodeAllLayers", &cfgparams.DecodeAllLayers, 0, 0.0, 1, 0.0, 1.0, 0 }, + {"DecodeAllLayers", &cfgparams.DecodeAllLayers, 0, 0.0, 1, 0.0, 1.0, 0}, #endif - {NULL, NULL, -1, 0.0, 0, 0.0, 0.0, 0 }, + {NULL, NULL, -1, 0.0, 0, 0.0, 0.0, 0}, }; #endif #ifndef INCLUDED_BY_CONFIGFILE_C extern Mapping Map[]; #endif -extern void JMDecHelpExit (); +extern void JMDecHelpExit(); extern void ParseCommand(InputParameters *p_Inp, int ac, char *av[]); #endif - diff --git a/src/common/ldecod_src/inc/context_ini.h b/src/common/ldecod_src/inc/context_ini.h index 73977be..3ac355a 100644 --- a/src/common/ldecod_src/inc/context_ini.h +++ b/src/common/ldecod_src/inc/context_ini.h @@ -7,17 +7,16 @@ * CABAC context initializations * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Detlev Marpe * - Heiko Schwarz ************************************************************************************** */ - #ifndef _CONTEXT_INI_ #define _CONTEXT_INI_ -extern void init_contexts (Slice *currslice); +extern void init_contexts(Slice *currslice); #endif - diff --git a/src/common/ldecod_src/inc/contributors.h b/src/common/ldecod_src/inc/contributors.h index 542d558..3a77ea6 100644 --- a/src/common/ldecod_src/inc/contributors.h +++ b/src/common/ldecod_src/inc/contributors.h @@ -15,10 +15,10 @@ Nokia Inc., USA Nokia Corporation, Finland Siemens AG, Germany - Fraunhofer-Institute for Telecommunications Heinrich-Hertz-Institut (HHI), Germany - University of Hannover, Institut of Communication Theory and Signal Processing, Germany - TICSP, Tampere University of Technology, Finland - Munich University of Technology, Institute for Communications Engineering, Germany + Fraunhofer-Institute for Telecommunications Heinrich-Hertz-Institut (HHI), + Germany University of Hannover, Institut of Communication Theory and Signal + Processing, Germany TICSP, Tampere University of Technology, Finland Munich + University of Technology, Institute for Communications Engineering, Germany Videolocus, Canada Motorola Inc., USA Microsoft Corp., USA @@ -30,12 +30,9 @@ \par Full Contact Information \verbatim - Lowell Winger - Guy Ct - Michael Gallant - VideoLocus Inc. - 97 Randall Dr. - Waterloo, ON, Canada N2V1C5 + Lowell Winger Guy Ct + Michael Gallant VideoLocus + Inc. 97 Randall Dr. Waterloo, ON, Canada N2V1C5 Inge Lille-Langy Telenor Satellite Services @@ -152,10 +149,8 @@ San Diego, CA 92121 USA Feng Wu - Xiaoyan Sun - Microsoft Research Asia - 3/F, Beijing Sigma Center - No.49, Zhichun Road, Hai Dian District, + Xiaoyan Sun Microsoft + Research Asia 3/F, Beijing Sigma Center No.49, Zhichun Road, Hai Dian District, Beijing China 100080 Yoshihiro Kikuchi @@ -211,22 +206,20 @@ 2 Independence Way Princeton, NJ 08540 - Shun-ichi Sekiguchi - Information Technology R&D Center, + Shun-ichi Sekiguchi + Information Technology R&D Center, Mitsubishi Electric Corporation 5-1-1, Ofuna, Kamakura, Japan Yung-Lyul Lee Ki-Hun Han - Department of Computer Engineering, + Department of Computer Engineering, Sejong University 98 Kunja-Dong, Kwangjin-Gu, Seoul 143-747, Korea - Jianhua Wu - Panasonic Singapore Laboratories Pte Ltd - Blk 1022 Tai Seng Ave #06-3530 Tai Seng Ind Est - Singapore 534415 + Jianhua Wu Panasonic + Singapore Laboratories Pte Ltd Blk 1022 Tai Seng Ave #06-3530 Tai Seng Ind Est + Singapore 534415 \endverbatim */ - diff --git a/src/common/ldecod_src/inc/ctx_tables.h b/src/common/ldecod_src/inc/ctx_tables.h index 7c7ff87..f2d7809 100644 --- a/src/common/ldecod_src/inc/ctx_tables.h +++ b/src/common/ldecod_src/inc/ctx_tables.h @@ -7,988 +7,3412 @@ * CABAC context initialization tables * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Detlev Marpe * - Heiko Schwarz ************************************************************************************** */ -#define CTX_UNUSED {0,64} -#define CTX_UNDEF {0,63} +#define CTX_UNUSED {0, 64} +#define CTX_UNDEF {0, 63} #ifdef CONTEXT_INI_C +#define NUM_CTX_MODELS_I 1 +#define NUM_CTX_MODELS_P 3 -#define NUM_CTX_MODELS_I 1 -#define NUM_CTX_MODELS_P 3 +static const signed char INIT_MB_TYPE_I[1][3][11][2] = { + //----- model 0 ----- + {{{20, -15}, + {2, 54}, + {3, 74}, + CTX_UNUSED, + {-28, 127}, + {-23, 104}, + {-6, 53}, + {-1, 54}, + {7, 51}, + CTX_UNUSED, + CTX_UNUSED}, + {{20, -15}, + {2, 54}, + {3, 74}, + {20, -15}, + {2, 54}, + {3, 74}, + {-28, 127}, + {-23, 104}, + {-6, 53}, + {-1, 54}, + {7, 51}}, // SI (unused at the moment) + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; +static const signed char INIT_MB_TYPE_P[3][3][11][2] = { + //----- model 0 ----- + {{CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{23, 33}, + {23, 2}, + {21, 0}, + CTX_UNUSED, + {1, 9}, + {0, 49}, + {-37, 118}, + {5, 57}, + {-13, 78}, + {-11, 65}, + {1, 62}}, + {{26, 67}, + {16, 90}, + {9, 104}, + CTX_UNUSED, + {-46, 127}, + {-20, 104}, + {1, 67}, + {18, 64}, + {9, 43}, + {29, 0}, + CTX_UNUSED}}, + //----- model 1 ----- + {{CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{22, 25}, + {34, 0}, + {16, 0}, + CTX_UNUSED, + {-2, 9}, + {4, 41}, + {-29, 118}, + {2, 65}, + {-6, 71}, + {-13, 79}, + {5, 52}}, + {{57, 2}, + {41, 36}, + {26, 69}, + CTX_UNUSED, + {-45, 127}, + {-15, 101}, + {-4, 76}, + {26, 34}, + {19, 22}, + {40, 0}, + CTX_UNUSED}}, + //----- model 2 ----- + {{CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{29, 16}, + {25, 0}, + {14, 0}, + CTX_UNUSED, + {-10, 51}, + {-3, 62}, + {-27, 99}, + {26, 16}, + {-4, 85}, + {-24, 102}, + {5, 57}}, + {{54, 0}, + {37, 42}, + {12, 97}, + CTX_UNUSED, + {-32, 127}, + {-22, 117}, + {-2, 74}, + {20, 40}, + {20, 10}, + {29, 0}, + CTX_UNUSED}}}; +static const signed char INIT_B8_TYPE_I[1][2][9][2] = { + //----- model 0 ----- + {{CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; -static const signed char INIT_MB_TYPE_I[1][3][11][2] = -{ - //----- model 0 ----- - { - { { 20, -15} , { 2, 54} , { 3, 74} , CTX_UNUSED , { -28, 127} , { -23, 104} , { -6, 53} , { -1, 54} , { 7, 51} , CTX_UNUSED , CTX_UNUSED }, - { { 20, -15} , { 2, 54} , { 3, 74} , { 20, -15} , { 2, 54} , { 3, 74} , { -28, 127} , { -23, 104} , { -6, 53} , { -1, 54} , { 7, 51} }, // SI (unused at the moment) - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; -static const signed char INIT_MB_TYPE_P[3][3][11][2] = -{ - //----- model 0 ----- - { - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 23, 33} , { 23, 2} , { 21, 0} , CTX_UNUSED , { 1, 9} , { 0, 49} , { -37, 118} , { 5, 57} , { -13, 78} , { -11, 65} , { 1, 62} }, - { { 26, 67} , { 16, 90} , { 9, 104} , CTX_UNUSED , { -46, 127} , { -20, 104} , { 1, 67} , { 18, 64} , { 9, 43} , { 29, 0} , CTX_UNUSED } - }, - //----- model 1 ----- - { - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 22, 25} , { 34, 0} , { 16, 0} , CTX_UNUSED , { -2, 9} , { 4, 41} , { -29, 118} , { 2, 65} , { -6, 71} , { -13, 79} , { 5, 52} }, - { { 57, 2} , { 41, 36} , { 26, 69} , CTX_UNUSED , { -45, 127} , { -15, 101} , { -4, 76} , { 26, 34} , { 19, 22} , { 40, 0} , CTX_UNUSED } - }, - //----- model 2 ----- - { - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 29, 16} , { 25, 0} , { 14, 0} , CTX_UNUSED , { -10, 51} , { -3, 62} , { -27, 99} , { 26, 16} , { -4, 85} , { -24, 102} , { 5, 57} }, - { { 54, 0} , { 37, 42} , { 12, 97} , CTX_UNUSED , { -32, 127} , { -22, 117} , { -2, 74} , { 20, 40} , { 20, 10} , { 29, 0} , CTX_UNUSED } - } -}; +static const signed char INIT_B8_TYPE_P[3][2][9][2] = { + //----- model 0 ----- + {{CTX_UNUSED, + {12, 49}, + CTX_UNUSED, + {-4, 73}, + {17, 50}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {{-6, 86}, + {-17, 95}, + {-6, 61}, + {9, 45}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}}, + //----- model 1 ----- + {{CTX_UNUSED, + {9, 50}, + CTX_UNUSED, + {-3, 70}, + {10, 54}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {{6, 69}, + {-13, 90}, + {0, 52}, + {8, 43}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}}, + //----- model 2 ----- + {{CTX_UNUSED, + {6, 57}, + CTX_UNUSED, + {-17, 73}, + {14, 57}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {{-6, 93}, + {-14, 88}, + {-6, 44}, + {4, 55}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}}}; -static const signed char INIT_B8_TYPE_I[1][2][9][2] = -{ - //----- model 0 ----- - { - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; +static const signed char INIT_MV_RES_I[1][2][10][2] = { + //----- model 0 ----- + {{CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; -static const signed char INIT_B8_TYPE_P[3][2][9][2] = -{ - //----- model 0 ----- - { - { CTX_UNUSED , { 12, 49} , CTX_UNUSED , { -4, 73} , { 17, 50} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -6, 86} , { -17, 95} , { -6, 61} , { 9, 45} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - }, - //----- model 1 ----- - { - { CTX_UNUSED , { 9, 50} , CTX_UNUSED , { -3, 70} , { 10, 54} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 6, 69} , { -13, 90} , { 0, 52} , { 8, 43} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - }, - //----- model 2 ----- - { - { CTX_UNUSED , { 6, 57} , CTX_UNUSED , { -17, 73} , { 14, 57} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -6, 93} , { -14, 88} , { -6, 44} , { 4, 55} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; +static const signed char INIT_MV_RES_P[3][2][10][2] = { + //----- model 0 ----- + {{{-3, 69}, + CTX_UNUSED, + {-6, 81}, + {-11, 96}, + CTX_UNUSED, + {0, 58}, + CTX_UNUSED, + {-3, 76}, + {-10, 94}, + CTX_UNUSED}, + {{6, 55}, + {7, 67}, + {-5, 86}, + {2, 88}, + CTX_UNUSED, + {5, 54}, + {4, 69}, + {-3, 81}, + {0, 88}, + CTX_UNUSED}}, + //----- model 1 ----- + {{{-2, 69}, + CTX_UNUSED, + {-5, 82}, + {-10, 96}, + CTX_UNUSED, + {1, 56}, + CTX_UNUSED, + {-3, 74}, + {-6, 85}, + CTX_UNUSED}, + {{2, 59}, + {2, 75}, + {-3, 87}, + {-3, 100}, + CTX_UNUSED, + {0, 59}, + {-3, 81}, + {-7, 86}, + {-5, 95}, + CTX_UNUSED}}, + //----- model 2 ----- + {{{-11, 89}, + CTX_UNUSED, + {-15, 103}, + {-21, 116}, + CTX_UNUSED, + {1, 63}, + CTX_UNUSED, + {-5, 85}, + {-13, 106}, + CTX_UNUSED}, + {{19, 57}, + {20, 58}, + {4, 84}, + {6, 96}, + CTX_UNUSED, + {5, 63}, + {6, 75}, + {-3, 90}, + {-1, 101}, + CTX_UNUSED}}}; -static const signed char INIT_MV_RES_I[1][2][10][2] = -{ - //----- model 0 ----- - { - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; +static const signed char INIT_REF_NO_I[1][2][6][2] = { + //----- model 0 ----- + {{CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; -static const signed char INIT_MV_RES_P[3][2][10][2] = -{ - //----- model 0 ----- - { - { { -3, 69} , CTX_UNUSED , { -6, 81} , { -11, 96} , CTX_UNUSED , { 0, 58} , CTX_UNUSED , { -3, 76} , { -10, 94} , CTX_UNUSED }, - { { 6, 55} , { 7, 67} , { -5, 86} , { 2, 88} , CTX_UNUSED , { 5, 54} , { 4, 69} , { -3, 81} , { 0, 88} , CTX_UNUSED } - }, - //----- model 1 ----- - { - { { -2, 69} , CTX_UNUSED , { -5, 82} , { -10, 96} , CTX_UNUSED , { 1, 56} , CTX_UNUSED , { -3, 74} , { -6, 85} , CTX_UNUSED }, - { { 2, 59} , { 2, 75} , { -3, 87} , { -3, 100} , CTX_UNUSED , { 0, 59} , { -3, 81} , { -7, 86} , { -5, 95} , CTX_UNUSED } - }, - //----- model 2 ----- - { - { { -11, 89} , CTX_UNUSED , { -15, 103} , { -21, 116} , CTX_UNUSED , { 1, 63} , CTX_UNUSED , { -5, 85} , { -13, 106} , CTX_UNUSED }, - { { 19, 57} , { 20, 58} , { 4, 84} , { 6, 96} , CTX_UNUSED , { 5, 63} , { 6, 75} , { -3, 90} , { -1, 101} , CTX_UNUSED } - } -}; +static const signed char INIT_REF_NO_P[3][2][6][2] = { + //----- model 0 ----- + {{{-7, 67}, {-5, 74}, {-4, 74}, {-5, 80}, {-7, 72}, {1, 58}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}, + //----- model 1 ----- + {{{-1, 66}, {-1, 77}, {1, 70}, {-2, 86}, {-5, 72}, {0, 61}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}, + //----- model 2 ----- + {{{3, 55}, {-4, 79}, {-2, 75}, {-12, 97}, {-7, 50}, {1, 60}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; -static const signed char INIT_REF_NO_I[1][2][6][2] = -{ - //----- model 0 ----- - { - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; +static const signed char INIT_TRANSFORM_SIZE_I[1][1][3][2] = { + //----- model 0 ----- + { + {{31, 21}, {31, 31}, {25, 50}}, + // { { 0, 41} , { 0, 63} , { 0, 63} }, + }}; -static const signed char INIT_REF_NO_P[3][2][6][2] = -{ - //----- model 0 ----- - { - { { -7, 67} , { -5, 74} , { -4, 74} , { -5, 80} , { -7, 72} , { 1, 58} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - }, - //----- model 1 ----- - { - { { -1, 66} , { -1, 77} , { 1, 70} , { -2, 86} , { -5, 72} , { 0, 61} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - }, - //----- model 2 ----- - { - { { 3, 55} , { -4, 79} , { -2, 75} , { -12, 97} , { -7, 50} , { 1, 60} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; +static const signed char INIT_TRANSFORM_SIZE_P[3][1][3][2] = { + //----- model 0 ----- + { + {{12, 40}, {11, 51}, {14, 59}}, + // { { 0, 41} , { 0, 63} , { 0, 63} }, + }, + //----- model 1 ----- + { + {{25, 32}, {21, 49}, {21, 54}}, + // { { 0, 41} , { 0, 63} , { 0, 63} }, + }, + //----- model 2 ----- + { + {{21, 33}, {19, 50}, {17, 61}}, + // { { 0, 41} , { 0, 63} , { 0, 63} }, + }}; +static const signed char INIT_DELTA_QP_I[1][1][4][2] = { + //----- model 0 ----- + { + {{0, 41}, {0, 63}, {0, 63}, {0, 63}}, + }}; +static const signed char INIT_DELTA_QP_P[3][1][4][2] = { + //----- model 0 ----- + { + {{0, 41}, {0, 63}, {0, 63}, {0, 63}}, + }, + //----- model 1 ----- + { + {{0, 41}, {0, 63}, {0, 63}, {0, 63}}, + }, + //----- model 2 ----- + { + {{0, 41}, {0, 63}, {0, 63}, {0, 63}}, + }}; -static const signed char INIT_TRANSFORM_SIZE_I[1][1][3][2]= -{ - //----- model 0 ----- - { - { { 31, 21} , { 31, 31} , { 25, 50} }, -// { { 0, 41} , { 0, 63} , { 0, 63} }, - } -}; +static const signed char INIT_MB_AFF_I[1][1][4][2] = { + //----- model 0 ----- + {{{0, 11}, {1, 55}, {0, 69}, CTX_UNUSED}}}; +static const signed char INIT_MB_AFF_P[3][1][4][2] = { + //----- model 0 ----- + {{{0, 45}, {-4, 78}, {-3, 96}, CTX_UNUSED}}, + //----- model 1 ----- + {{{13, 15}, {7, 51}, {2, 80}, CTX_UNUSED}}, + //----- model 2 ----- + {{{7, 34}, {-9, 88}, {-20, 127}, CTX_UNUSED}}}; -static const signed char INIT_TRANSFORM_SIZE_P[3][1][3][2]= -{ - //----- model 0 ----- - { - { { 12, 40} , { 11, 51} , { 14, 59} }, -// { { 0, 41} , { 0, 63} , { 0, 63} }, - }, - //----- model 1 ----- - { - { { 25, 32} , { 21, 49} , { 21, 54} }, -// { { 0, 41} , { 0, 63} , { 0, 63} }, - }, - //----- model 2 ----- - { - { { 21, 33} , { 19, 50} , { 17, 61} }, -// { { 0, 41} , { 0, 63} , { 0, 63} }, - } -}; +static const signed char INIT_IPR_I[1][1][2][2] = { + //----- model 0 ----- + {{{13, 41}, {3, 62}}}}; -static const signed char INIT_DELTA_QP_I[1][1][4][2]= -{ - //----- model 0 ----- - { - { { 0, 41} , { 0, 63} , { 0, 63} , { 0, 63} }, - } -}; -static const signed char INIT_DELTA_QP_P[3][1][4][2]= -{ - //----- model 0 ----- - { - { { 0, 41} , { 0, 63} , { 0, 63} , { 0, 63} }, - }, - //----- model 1 ----- - { - { { 0, 41} , { 0, 63} , { 0, 63} , { 0, 63} }, - }, - //----- model 2 ----- - { - { { 0, 41} , { 0, 63} , { 0, 63} , { 0, 63} }, - } -}; +static const signed char INIT_IPR_P[3][1][2][2] = { + //----- model 0 ----- + {{{13, 41}, {3, 62}}}, + //----- model 1 ----- + {{{13, 41}, {3, 62}}}, + //----- model 2 ----- + {{{13, 41}, {3, 62}}}}; -static const signed char INIT_MB_AFF_I[1][1][4][2] = -{ - //----- model 0 ----- - { - { { 0, 11} , { 1, 55} , { 0, 69} , CTX_UNUSED } - } -}; -static const signed char INIT_MB_AFF_P[3][1][4][2] = -{ - //----- model 0 ----- - { - { { 0, 45} , { -4, 78} , { -3, 96} , CTX_UNUSED } - }, - //----- model 1 ----- - { - { { 13, 15} , { 7, 51} , { 2, 80} , CTX_UNUSED } - }, - //----- model 2 ----- - { - { { 7, 34} , { -9, 88} , { -20, 127} , CTX_UNUSED } - } -}; +static const signed char INIT_CIPR_I[1][1][4][2] = { + //----- model 0 ----- + {{{-9, 83}, {4, 86}, {0, 97}, {-7, 72}}}}; -static const signed char INIT_IPR_I[1][1][2][2] = -{ - //----- model 0 ----- - { - { { 13, 41} , { 3, 62} } - } -}; +static const signed char INIT_CIPR_P[3][1][4][2] = { + //----- model 0 ----- + {{{-9, 83}, {4, 86}, {0, 97}, {-7, 72}}}, + //----- model 1 ----- + {{{-9, 83}, {4, 86}, {0, 97}, {-7, 72}}}, + //----- model 2 ----- + {{{-9, 83}, {4, 86}, {0, 97}, {-7, 72}}}}; -static const signed char INIT_IPR_P[3][1][2][2] = -{ - //----- model 0 ----- - { - { { 13, 41} , { 3, 62} } - }, - //----- model 1 ----- - { - { { 13, 41} , { 3, 62} } - }, - //----- model 2 ----- - { - { { 13, 41} , { 3, 62} } - } -}; +static const signed char INIT_CBP_I[1][3][4][2] = { + //----- model 0 ----- + {{{-17, 127}, {-13, 102}, {0, 82}, {-7, 74}}, + {{-21, 107}, {-27, 127}, {-31, 127}, {-24, 127}}, + {{-18, 95}, {-27, 127}, {-21, 114}, {-30, 127}}}}; -static const signed char INIT_CIPR_I[1][1][4][2] = -{ - //----- model 0 ----- - { - { { -9, 83} , { 4, 86} , { 0, 97} , { -7, 72} } - } -}; +static const signed char INIT_CBP_P[3][3][4][2] = { + //----- model 0 ----- + {{{-27, 126}, {-28, 98}, {-25, 101}, {-23, 67}}, + {{-28, 82}, {-20, 94}, {-16, 83}, {-22, 110}}, + {{-21, 91}, {-18, 102}, {-13, 93}, {-29, 127}}}, + //----- model 1 ----- + {{{-39, 127}, {-18, 91}, {-17, 96}, {-26, 81}}, + {{-35, 98}, {-24, 102}, {-23, 97}, {-27, 119}}, + {{-24, 99}, {-21, 110}, {-18, 102}, {-36, 127}}}, + //----- model 2 ----- + {{{-36, 127}, {-17, 91}, {-14, 95}, {-25, 84}}, + {{-25, 86}, {-12, 89}, {-17, 91}, {-31, 127}}, + {{-14, 76}, {-18, 103}, {-13, 90}, {-37, 127}}}}; -static const signed char INIT_CIPR_P[3][1][4][2] = -{ - //----- model 0 ----- - { - { { -9, 83} , { 4, 86} , { 0, 97} , { -7, 72} } - }, - //----- model 1 ----- - { - { { -9, 83} , { 4, 86} , { 0, 97} , { -7, 72} } - }, - //----- model 2 ----- - { - { { -9, 83} , { 4, 86} , { 0, 97} , { -7, 72} } - } -}; +static const signed char INIT_BCBP_I[1][22][4][2] = { + //----- model 0 ----- + {{{-17, 123}, {-12, 115}, {-16, 122}, {-11, 115}}, + {{-12, 63}, {-2, 68}, {-15, 84}, {-13, 104}}, + {{-3, 70}, {-8, 93}, {-10, 90}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-3, 70}, {-8, 93}, {-10, 90}, {-30, 127}}, + {{-1, 74}, {-6, 97}, {-7, 91}, {-20, 127}}, + {{-4, 56}, {-5, 82}, {-7, 76}, {-22, 125}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-17, 123}, {-12, 115}, {-16, 122}, {-11, 115}}, + {{-12, 63}, {-2, 68}, {-15, 84}, {-13, 104}}, + {{-3, 70}, {-8, 93}, {-10, 90}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-3, 70}, {-8, 93}, {-10, 90}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{-17, 123}, {-12, 115}, {-16, 122}, {-11, 115}}, + {{-12, 63}, {-2, 68}, {-15, 84}, {-13, 104}}, + {{-3, 70}, {-8, 93}, {-10, 90}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-3, 70}, {-8, 93}, {-10, 90}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; -static const signed char INIT_CBP_I[1][3][4][2] = -{ - //----- model 0 ----- - { - { { -17, 127} , { -13, 102} , { 0, 82} , { -7, 74} }, - { { -21, 107} , { -27, 127} , { -31, 127} , { -24, 127} }, - { { -18, 95} , { -27, 127} , { -21, 114} , { -30, 127} } - } -}; +static const signed char INIT_BCBP_P[3][22][4][2] = { + //----- model 0 ----- + {{{-7, 92}, {-5, 89}, {-7, 96}, {-13, 108}}, + {{-3, 46}, {-1, 65}, {-1, 57}, {-9, 93}}, + {{-3, 74}, {-9, 92}, {-8, 87}, {-23, 126}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-3, 74}, {-9, 92}, {-8, 87}, {-23, 126}}, + {{5, 54}, {6, 60}, {6, 59}, {6, 69}}, + {{-1, 48}, {0, 68}, {-4, 69}, {-8, 88}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-7, 92}, {-5, 89}, {-7, 96}, {-13, 108}}, + {{-3, 46}, {-1, 65}, {-1, 57}, {-9, 93}}, + {{-3, 74}, {-9, 92}, {-8, 87}, {-23, 126}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-3, 74}, {-9, 92}, {-8, 87}, {-23, 126}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{-7, 92}, {-5, 89}, {-7, 96}, {-13, 108}}, + {{-3, 46}, {-1, 65}, {-1, 57}, {-9, 93}}, + {{-3, 74}, {-9, 92}, {-8, 87}, {-23, 126}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-3, 74}, {-9, 92}, {-8, 87}, {-23, 126}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}, + //----- model 1 ----- + {{{0, 80}, {-5, 89}, {-7, 94}, {-4, 92}}, + {{0, 39}, {0, 65}, {-15, 84}, {-35, 127}}, + {{-2, 73}, {-12, 104}, {-9, 91}, {-31, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-2, 73}, {-12, 104}, {-9, 91}, {-31, 127}}, + {{3, 55}, {7, 56}, {7, 55}, {8, 61}}, + {{-3, 53}, {0, 68}, {-7, 74}, {-9, 88}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{0, 80}, {-5, 89}, {-7, 94}, {-4, 92}}, + {{0, 39}, {0, 65}, {-15, 84}, {-35, 127}}, + {{-2, 73}, {-12, 104}, {-9, 91}, {-31, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-2, 73}, {-12, 104}, {-9, 91}, {-31, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{0, 80}, {-5, 89}, {-7, 94}, {-4, 92}}, + {{0, 39}, {0, 65}, {-15, 84}, {-35, 127}}, + {{-2, 73}, {-12, 104}, {-9, 91}, {-31, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-2, 73}, {-12, 104}, {-9, 91}, {-31, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}, + //----- model 2 ----- + {{{11, 80}, {5, 76}, {2, 84}, {5, 78}}, + {{-6, 55}, {4, 61}, {-14, 83}, {-37, 127}}, + {{-5, 79}, {-11, 104}, {-11, 91}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-5, 79}, {-11, 104}, {-11, 91}, {-30, 127}}, + {{0, 65}, {-2, 79}, {0, 72}, {-4, 92}}, + {{-6, 56}, {3, 68}, {-8, 71}, {-13, 98}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{11, 80}, {5, 76}, {2, 84}, {5, 78}}, + {{-6, 55}, {4, 61}, {-14, 83}, {-37, 127}}, + {{-5, 79}, {-11, 104}, {-11, 91}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-5, 79}, {-11, 104}, {-11, 91}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{11, 80}, {5, 76}, {2, 84}, {5, 78}}, + {{-6, 55}, {4, 61}, {-14, 83}, {-37, 127}}, + {{-5, 79}, {-11, 104}, {-11, 91}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-5, 79}, {-11, 104}, {-11, 91}, {-30, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; -static const signed char INIT_CBP_P[3][3][4][2] = -{ - //----- model 0 ----- - { - { { -27, 126} , { -28, 98} , { -25, 101} , { -23, 67} }, - { { -28, 82} , { -20, 94} , { -16, 83} , { -22, 110} }, - { { -21, 91} , { -18, 102} , { -13, 93} , { -29, 127} } - }, - //----- model 1 ----- - { - { { -39, 127} , { -18, 91} , { -17, 96} , { -26, 81} }, - { { -35, 98} , { -24, 102} , { -23, 97} , { -27, 119} }, - { { -24, 99} , { -21, 110} , { -18, 102} , { -36, 127} } - }, - //----- model 2 ----- - { - { { -36, 127} , { -17, 91} , { -14, 95} , { -25, 84} }, - { { -25, 86} , { -12, 89} , { -17, 91} , { -31, 127} }, - { { -14, 76} , { -18, 103} , { -13, 90} , { -37, 127} } - } -}; +static const signed char INIT_MAP_I[1][22][15][2] = { + //----- model 0 ----- + {{{-7, 93}, + {-11, 87}, + {-3, 77}, + {-5, 71}, + {-4, 63}, + {-4, 68}, + {-12, 84}, + {-7, 62}, + {-7, 65}, + {8, 61}, + {5, 56}, + {-2, 66}, + {1, 64}, + {0, 61}, + {-2, 78}}, + {CTX_UNUSED, + {1, 50}, + {7, 52}, + {10, 35}, + {0, 44}, + {11, 38}, + {1, 45}, + {0, 46}, + {5, 44}, + {31, 17}, + {1, 51}, + {7, 50}, + {28, 19}, + {16, 33}, + {14, 62}}, + {{-17, 120}, + {-20, 112}, + {-18, 114}, + {-11, 85}, + {-15, 92}, + {-14, 89}, + {-26, 71}, + {-15, 81}, + {-14, 80}, + {0, 68}, + {-14, 70}, + {-24, 56}, + {-23, 68}, + {-24, 50}, + {-11, 74}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-13, 108}, + {-15, 100}, + {-13, 101}, + {-13, 91}, + {-12, 94}, + {-10, 88}, + {-16, 84}, + {-10, 86}, + {-7, 83}, + {-13, 87}, + {-19, 94}, + {1, 70}, + {0, 72}, + {-5, 74}, + {18, 59}}, + {{-8, 102}, + {-15, 100}, + {0, 95}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {-4, 75}, + {2, 72}, + {-11, 75}, + {-3, 71}, + {15, 46}, + {-13, 69}, + {0, 62}, + {0, 65}, + {21, 37}, + {-15, 72}, + {9, 57}, + {16, 54}, + {0, 62}, + {12, 72}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-7, 93}, + {-11, 87}, + {-3, 77}, + {-5, 71}, + {-4, 63}, + {-4, 68}, + {-12, 84}, + {-7, 62}, + {-7, 65}, + {8, 61}, + {5, 56}, + {-2, 66}, + {1, 64}, + {0, 61}, + {-2, 78}}, + {CTX_UNUSED, + {1, 50}, + {7, 52}, + {10, 35}, + {0, 44}, + {11, 38}, + {1, 45}, + {0, 46}, + {5, 44}, + {31, 17}, + {1, 51}, + {7, 50}, + {28, 19}, + {16, 33}, + {14, 62}}, + {{-17, 120}, + {-20, 112}, + {-18, 114}, + {-11, 85}, + {-15, 92}, + {-14, 89}, + {-26, 71}, + {-15, 81}, + {-14, 80}, + {0, 68}, + {-14, 70}, + {-24, 56}, + {-23, 68}, + {-24, 50}, + {-11, 74}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-13, 108}, + {-15, 100}, + {-13, 101}, + {-13, 91}, + {-12, 94}, + {-10, 88}, + {-16, 84}, + {-10, 86}, + {-7, 83}, + {-13, 87}, + {-19, 94}, + {1, 70}, + {0, 72}, + {-5, 74}, + {18, 59}}, + // Cr in the 4:4:4 common mode + {{-7, 93}, + {-11, 87}, + {-3, 77}, + {-5, 71}, + {-4, 63}, + {-4, 68}, + {-12, 84}, + {-7, 62}, + {-7, 65}, + {8, 61}, + {5, 56}, + {-2, 66}, + {1, 64}, + {0, 61}, + {-2, 78}}, + {CTX_UNUSED, + {1, 50}, + {7, 52}, + {10, 35}, + {0, 44}, + {11, 38}, + {1, 45}, + {0, 46}, + {5, 44}, + {31, 17}, + {1, 51}, + {7, 50}, + {28, 19}, + {16, 33}, + {14, 62}}, + {{-17, 120}, + {-20, 112}, + {-18, 114}, + {-11, 85}, + {-15, 92}, + {-14, 89}, + {-26, 71}, + {-15, 81}, + {-14, 80}, + {0, 68}, + {-14, 70}, + {-24, 56}, + {-23, 68}, + {-24, 50}, + {-11, 74}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-13, 108}, + {-15, 100}, + {-13, 101}, + {-13, 91}, + {-12, 94}, + {-10, 88}, + {-16, 84}, + {-10, 86}, + {-7, 83}, + {-13, 87}, + {-19, 94}, + {1, 70}, + {0, 72}, + {-5, 74}, + {18, 59}}}}; -static const signed char INIT_BCBP_I[1][22][4][2] = -{ - //----- model 0 ----- - { - { { -17, 123} , { -12, 115} , { -16, 122} , { -11, 115} }, - { { -12, 63} , { -2, 68} , { -15, 84} , { -13, 104} }, - { { -3, 70} , { -8, 93} , { -10, 90} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -3, 70} , { -8, 93} , { -10, 90} , { -30, 127} }, - { { -1, 74} , { -6, 97} , { -7, 91} , { -20, 127} }, - { { -4, 56} , { -5, 82} , { -7, 76} , { -22, 125} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - // Cb in the 4:4:4 common mode - { { -17, 123} , { -12, 115} , { -16, 122} , { -11, 115} }, - { { -12, 63} , { -2, 68} , { -15, 84} , { -13, 104} }, - { { -3, 70} , { -8, 93} , { -10, 90} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -3, 70} , { -8, 93} , { -10, 90} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - // Cr in the 4:4:4 common mode - { { -17, 123} , { -12, 115} , { -16, 122} , { -11, 115} }, - { { -12, 63} , { -2, 68} , { -15, 84} , { -13, 104} }, - { { -3, 70} , { -8, 93} , { -10, 90} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -3, 70} , { -8, 93} , { -10, 90} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; +static const signed char INIT_MAP_P[3][22][15][2] = { + //----- model 0 ----- + {{{-2, 85}, + {-6, 78}, + {-1, 75}, + {-7, 77}, + {2, 54}, + {5, 50}, + {-3, 68}, + {1, 50}, + {6, 42}, + {-4, 81}, + {1, 63}, + {-4, 70}, + {0, 67}, + {2, 57}, + {-2, 76}}, + {CTX_UNUSED, + {11, 35}, + {4, 64}, + {1, 61}, + {11, 35}, + {18, 25}, + {12, 24}, + {13, 29}, + {13, 36}, + {-10, 93}, + {-7, 73}, + {-2, 73}, + {13, 46}, + {9, 49}, + {-7, 100}}, + {{-4, 79}, + {-7, 71}, + {-5, 69}, + {-9, 70}, + {-8, 66}, + {-10, 68}, + {-19, 73}, + {-12, 69}, + {-16, 70}, + {-15, 67}, + {-20, 62}, + {-19, 70}, + {-16, 66}, + {-22, 65}, + {-20, 63}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{9, 53}, + {2, 53}, + {5, 53}, + {-2, 61}, + {0, 56}, + {0, 56}, + {-13, 63}, + {-5, 60}, + {-1, 62}, + {4, 57}, + {-6, 69}, + {4, 57}, + {14, 39}, + {4, 51}, + {13, 68}}, + {{3, 64}, + {1, 61}, + {9, 63}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {7, 50}, + {16, 39}, + {5, 44}, + {4, 52}, + {11, 48}, + {-5, 60}, + {-1, 59}, + {0, 59}, + {22, 33}, + {5, 44}, + {14, 43}, + {-1, 78}, + {0, 60}, + {9, 69}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-2, 85}, + {-6, 78}, + {-1, 75}, + {-7, 77}, + {2, 54}, + {5, 50}, + {-3, 68}, + {1, 50}, + {6, 42}, + {-4, 81}, + {1, 63}, + {-4, 70}, + {0, 67}, + {2, 57}, + {-2, 76}}, + {CTX_UNUSED, + {11, 35}, + {4, 64}, + {1, 61}, + {11, 35}, + {18, 25}, + {12, 24}, + {13, 29}, + {13, 36}, + {-10, 93}, + {-7, 73}, + {-2, 73}, + {13, 46}, + {9, 49}, + {-7, 100}}, + {{-4, 79}, + {-7, 71}, + {-5, 69}, + {-9, 70}, + {-8, 66}, + {-10, 68}, + {-19, 73}, + {-12, 69}, + {-16, 70}, + {-15, 67}, + {-20, 62}, + {-19, 70}, + {-16, 66}, + {-22, 65}, + {-20, 63}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{9, 53}, + {2, 53}, + {5, 53}, + {-2, 61}, + {0, 56}, + {0, 56}, + {-13, 63}, + {-5, 60}, + {-1, 62}, + {4, 57}, + {-6, 69}, + {4, 57}, + {14, 39}, + {4, 51}, + {13, 68}}, + // Cr in the 4:4:4 common mode + {{-2, 85}, + {-6, 78}, + {-1, 75}, + {-7, 77}, + {2, 54}, + {5, 50}, + {-3, 68}, + {1, 50}, + {6, 42}, + {-4, 81}, + {1, 63}, + {-4, 70}, + {0, 67}, + {2, 57}, + {-2, 76}}, + {CTX_UNUSED, + {11, 35}, + {4, 64}, + {1, 61}, + {11, 35}, + {18, 25}, + {12, 24}, + {13, 29}, + {13, 36}, + {-10, 93}, + {-7, 73}, + {-2, 73}, + {13, 46}, + {9, 49}, + {-7, 100}}, + {{-4, 79}, + {-7, 71}, + {-5, 69}, + {-9, 70}, + {-8, 66}, + {-10, 68}, + {-19, 73}, + {-12, 69}, + {-16, 70}, + {-15, 67}, + {-20, 62}, + {-19, 70}, + {-16, 66}, + {-22, 65}, + {-20, 63}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{9, 53}, + {2, 53}, + {5, 53}, + {-2, 61}, + {0, 56}, + {0, 56}, + {-13, 63}, + {-5, 60}, + {-1, 62}, + {4, 57}, + {-6, 69}, + {4, 57}, + {14, 39}, + {4, 51}, + {13, 68}}}, + //----- model 1 ----- + {{{-13, 103}, + {-13, 91}, + {-9, 89}, + {-14, 92}, + {-8, 76}, + {-12, 87}, + {-23, 110}, + {-24, 105}, + {-10, 78}, + {-20, 112}, + {-17, 99}, + {-78, 127}, + {-70, 127}, + {-50, 127}, + {-46, 127}}, + {CTX_UNUSED, + {-4, 66}, + {-5, 78}, + {-4, 71}, + {-8, 72}, + {2, 59}, + {-1, 55}, + {-7, 70}, + {-6, 75}, + {-8, 89}, + {-34, 119}, + {-3, 75}, + {32, 20}, + {30, 22}, + {-44, 127}}, + {{-5, 85}, + {-6, 81}, + {-10, 77}, + {-7, 81}, + {-17, 80}, + {-18, 73}, + {-4, 74}, + {-10, 83}, + {-9, 71}, + {-9, 67}, + {-1, 61}, + {-8, 66}, + {-14, 66}, + {0, 59}, + {2, 59}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{0, 54}, + {-5, 61}, + {0, 58}, + {-1, 60}, + {-3, 61}, + {-8, 67}, + {-25, 84}, + {-14, 74}, + {-5, 65}, + {5, 52}, + {2, 57}, + {0, 61}, + {-9, 69}, + {-11, 70}, + {18, 55}}, + {{-4, 71}, + {0, 58}, + {7, 61}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {9, 41}, + {18, 25}, + {9, 32}, + {5, 43}, + {9, 47}, + {0, 44}, + {0, 51}, + {2, 46}, + {19, 38}, + {-4, 66}, + {15, 38}, + {12, 42}, + {9, 34}, + {0, 89}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-13, 103}, + {-13, 91}, + {-9, 89}, + {-14, 92}, + {-8, 76}, + {-12, 87}, + {-23, 110}, + {-24, 105}, + {-10, 78}, + {-20, 112}, + {-17, 99}, + {-78, 127}, + {-70, 127}, + {-50, 127}, + {-46, 127}}, + {CTX_UNUSED, + {-4, 66}, + {-5, 78}, + {-4, 71}, + {-8, 72}, + {2, 59}, + {-1, 55}, + {-7, 70}, + {-6, 75}, + {-8, 89}, + {-34, 119}, + {-3, 75}, + {32, 20}, + {30, 22}, + {-44, 127}}, + {{-5, 85}, + {-6, 81}, + {-10, 77}, + {-7, 81}, + {-17, 80}, + {-18, 73}, + {-4, 74}, + {-10, 83}, + {-9, 71}, + {-9, 67}, + {-1, 61}, + {-8, 66}, + {-14, 66}, + {0, 59}, + {2, 59}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{0, 54}, + {-5, 61}, + {0, 58}, + {-1, 60}, + {-3, 61}, + {-8, 67}, + {-25, 84}, + {-14, 74}, + {-5, 65}, + {5, 52}, + {2, 57}, + {0, 61}, + {-9, 69}, + {-11, 70}, + {18, 55}}, + // Cr in the 4:4:4 common mode + {{-13, 103}, + {-13, 91}, + {-9, 89}, + {-14, 92}, + {-8, 76}, + {-12, 87}, + {-23, 110}, + {-24, 105}, + {-10, 78}, + {-20, 112}, + {-17, 99}, + {-78, 127}, + {-70, 127}, + {-50, 127}, + {-46, 127}}, + {CTX_UNUSED, + {-4, 66}, + {-5, 78}, + {-4, 71}, + {-8, 72}, + {2, 59}, + {-1, 55}, + {-7, 70}, + {-6, 75}, + {-8, 89}, + {-34, 119}, + {-3, 75}, + {32, 20}, + {30, 22}, + {-44, 127}}, + {{-5, 85}, + {-6, 81}, + {-10, 77}, + {-7, 81}, + {-17, 80}, + {-18, 73}, + {-4, 74}, + {-10, 83}, + {-9, 71}, + {-9, 67}, + {-1, 61}, + {-8, 66}, + {-14, 66}, + {0, 59}, + {2, 59}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{0, 54}, + {-5, 61}, + {0, 58}, + {-1, 60}, + {-3, 61}, + {-8, 67}, + {-25, 84}, + {-14, 74}, + {-5, 65}, + {5, 52}, + {2, 57}, + {0, 61}, + {-9, 69}, + {-11, 70}, + {18, 55}}}, + //----- model 2 ----- + {{{-4, 86}, + {-12, 88}, + {-5, 82}, + {-3, 72}, + {-4, 67}, + {-8, 72}, + {-16, 89}, + {-9, 69}, + {-1, 59}, + {5, 66}, + {4, 57}, + {-4, 71}, + {-2, 71}, + {2, 58}, + {-1, 74}}, + {CTX_UNUSED, + {-4, 44}, + {-1, 69}, + {0, 62}, + {-7, 51}, + {-4, 47}, + {-6, 42}, + {-3, 41}, + {-6, 53}, + {8, 76}, + {-9, 78}, + {-11, 83}, + {9, 52}, + {0, 67}, + {-5, 90}}, + {{-3, 78}, + {-8, 74}, + {-9, 72}, + {-10, 72}, + {-18, 75}, + {-12, 71}, + {-11, 63}, + {-5, 70}, + {-17, 75}, + {-14, 72}, + {-16, 67}, + {-8, 53}, + {-14, 59}, + {-9, 52}, + {-11, 68}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{1, 67}, + {-15, 72}, + {-5, 75}, + {-8, 80}, + {-21, 83}, + {-21, 64}, + {-13, 31}, + {-25, 64}, + {-29, 94}, + {9, 75}, + {17, 63}, + {-8, 74}, + {-5, 35}, + {-2, 27}, + {13, 91}}, + {{3, 65}, + {-7, 69}, + {8, 77}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {-10, 66}, + {3, 62}, + {-3, 68}, + {-20, 81}, + {0, 30}, + {1, 7}, + {-3, 23}, + {-21, 74}, + {16, 66}, + {-23, 124}, + {17, 37}, + {44, -18}, + {50, -34}, + {-22, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-4, 86}, + {-12, 88}, + {-5, 82}, + {-3, 72}, + {-4, 67}, + {-8, 72}, + {-16, 89}, + {-9, 69}, + {-1, 59}, + {5, 66}, + {4, 57}, + {-4, 71}, + {-2, 71}, + {2, 58}, + {-1, 74}}, + {CTX_UNUSED, + {-4, 44}, + {-1, 69}, + {0, 62}, + {-7, 51}, + {-4, 47}, + {-6, 42}, + {-3, 41}, + {-6, 53}, + {8, 76}, + {-9, 78}, + {-11, 83}, + {9, 52}, + {0, 67}, + {-5, 90}}, + {{-3, 78}, + {-8, 74}, + {-9, 72}, + {-10, 72}, + {-18, 75}, + {-12, 71}, + {-11, 63}, + {-5, 70}, + {-17, 75}, + {-14, 72}, + {-16, 67}, + {-8, 53}, + {-14, 59}, + {-9, 52}, + {-11, 68}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{1, 67}, + {-15, 72}, + {-5, 75}, + {-8, 80}, + {-21, 83}, + {-21, 64}, + {-13, 31}, + {-25, 64}, + {-29, 94}, + {9, 75}, + {17, 63}, + {-8, 74}, + {-5, 35}, + {-2, 27}, + {13, 91}}, + // Cr in the 4:4:4 common mode + {{-4, 86}, + {-12, 88}, + {-5, 82}, + {-3, 72}, + {-4, 67}, + {-8, 72}, + {-16, 89}, + {-9, 69}, + {-1, 59}, + {5, 66}, + {4, 57}, + {-4, 71}, + {-2, 71}, + {2, 58}, + {-1, 74}}, + {CTX_UNUSED, + {-4, 44}, + {-1, 69}, + {0, 62}, + {-7, 51}, + {-4, 47}, + {-6, 42}, + {-3, 41}, + {-6, 53}, + {8, 76}, + {-9, 78}, + {-11, 83}, + {9, 52}, + {0, 67}, + {-5, 90}}, + {{-3, 78}, + {-8, 74}, + {-9, 72}, + {-10, 72}, + {-18, 75}, + {-12, 71}, + {-11, 63}, + {-5, 70}, + {-17, 75}, + {-14, 72}, + {-16, 67}, + {-8, 53}, + {-14, 59}, + {-9, 52}, + {-11, 68}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{1, 67}, + {-15, 72}, + {-5, 75}, + {-8, 80}, + {-21, 83}, + {-21, 64}, + {-13, 31}, + {-25, 64}, + {-29, 94}, + {9, 75}, + {17, 63}, + {-8, 74}, + {-5, 35}, + {-2, 27}, + {13, 91}}}}; -static const signed char INIT_BCBP_P[3][22][4][2] = -{ - //----- model 0 ----- - { - { { -7, 92} , { -5, 89} , { -7, 96} , { -13, 108} }, - { { -3, 46} , { -1, 65} , { -1, 57} , { -9, 93} }, - { { -3, 74} , { -9, 92} , { -8, 87} , { -23, 126} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -3, 74} , { -9, 92} , { -8, 87} , { -23, 126} }, - { { 5, 54} , { 6, 60} , { 6, 59} , { 6, 69} }, - { { -1, 48} , { 0, 68} , { -4, 69} , { -8, 88} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - // Cb in the 4:4:4 common mode - { { -7, 92} , { -5, 89} , { -7, 96} , { -13, 108} }, - { { -3, 46} , { -1, 65} , { -1, 57} , { -9, 93} }, - { { -3, 74} , { -9, 92} , { -8, 87} , { -23, 126} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -3, 74} , { -9, 92} , { -8, 87} , { -23, 126} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - // Cr in the 4:4:4 common mode - { { -7, 92} , { -5, 89} , { -7, 96} , { -13, 108} }, - { { -3, 46} , { -1, 65} , { -1, 57} , { -9, 93} }, - { { -3, 74} , { -9, 92} , { -8, 87} , { -23, 126} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -3, 74} , { -9, 92} , { -8, 87} , { -23, 126} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - }, - //----- model 1 ----- - { - { { 0, 80} , { -5, 89} , { -7, 94} , { -4, 92} }, - { { 0, 39} , { 0, 65} , { -15, 84} , { -35, 127} }, - { { -2, 73} , { -12, 104} , { -9, 91} , { -31, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -2, 73} , { -12, 104} , { -9, 91} , { -31, 127} }, - { { 3, 55} , { 7, 56} , { 7, 55} , { 8, 61} }, - { { -3, 53} , { 0, 68} , { -7, 74} , { -9, 88} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - // Cb in the 4:4:4 common mode - { { 0, 80} , { -5, 89} , { -7, 94} , { -4, 92} }, - { { 0, 39} , { 0, 65} , { -15, 84} , { -35, 127} }, - { { -2, 73} , { -12, 104} , { -9, 91} , { -31, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -2, 73} , { -12, 104} , { -9, 91} , { -31, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - // Cr in the 4:4:4 common mode - { { 0, 80} , { -5, 89} , { -7, 94} , { -4, 92} }, - { { 0, 39} , { 0, 65} , { -15, 84} , { -35, 127} }, - { { -2, 73} , { -12, 104} , { -9, 91} , { -31, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -2, 73} , { -12, 104} , { -9, 91} , { -31, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - }, - //----- model 2 ----- - { - { { 11, 80} , { 5, 76} , { 2, 84} , { 5, 78} }, - { { -6, 55} , { 4, 61} , { -14, 83} , { -37, 127} }, - { { -5, 79} , { -11, 104} , { -11, 91} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -5, 79} , { -11, 104} , { -11, 91} , { -30, 127} }, - { { 0, 65} , { -2, 79} , { 0, 72} , { -4, 92} }, - { { -6, 56} , { 3, 68} , { -8, 71} , { -13, 98} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - // Cb in the 4:4:4 common mode - { { 11, 80} , { 5, 76} , { 2, 84} , { 5, 78} }, - { { -6, 55} , { 4, 61} , { -14, 83} , { -37, 127} }, - { { -5, 79} , { -11, 104} , { -11, 91} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -5, 79} , { -11, 104} , { -11, 91} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - // Cr in the 4:4:4 common mode - { { 11, 80} , { 5, 76} , { 2, 84} , { 5, 78} }, - { { -6, 55} , { 4, 61} , { -14, 83} , { -37, 127} }, - { { -5, 79} , { -11, 104} , { -11, 91} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -5, 79} , { -11, 104} , { -11, 91} , { -30, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; +static const signed char INIT_LAST_I[1][22][15][2] = { + //----- model 0 ----- + {{{24, 0}, + {15, 9}, + {8, 25}, + {13, 18}, + {15, 9}, + {13, 19}, + {10, 37}, + {12, 18}, + {6, 29}, + {20, 33}, + {15, 30}, + {4, 45}, + {1, 58}, + {0, 62}, + {7, 61}}, + {CTX_UNUSED, + {12, 38}, + {11, 45}, + {15, 39}, + {11, 42}, + {13, 44}, + {16, 45}, + {12, 41}, + {10, 49}, + {30, 34}, + {18, 42}, + {10, 55}, + {17, 51}, + {17, 46}, + {0, 89}}, + {{23, -13}, + {26, -13}, + {40, -15}, + {49, -14}, + {44, 3}, + {45, 6}, + {44, 34}, + {33, 54}, + {19, 82}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{26, -19}, + {22, -17}, + {26, -17}, + {30, -25}, + {28, -20}, + {33, -23}, + {37, -27}, + {33, -23}, + {40, -28}, + {38, -17}, + {33, -11}, + {40, -15}, + {41, -6}, + {38, 1}, + {41, 17}}, + {{30, -6}, + {27, 3}, + {26, 22}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {37, -16}, + {35, -4}, + {38, -8}, + {38, -3}, + {37, 3}, + {38, 5}, + {42, 0}, + {35, 16}, + {39, 22}, + {14, 48}, + {27, 37}, + {21, 60}, + {12, 68}, + {2, 97}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{24, 0}, + {15, 9}, + {8, 25}, + {13, 18}, + {15, 9}, + {13, 19}, + {10, 37}, + {12, 18}, + {6, 29}, + {20, 33}, + {15, 30}, + {4, 45}, + {1, 58}, + {0, 62}, + {7, 61}}, + {CTX_UNUSED, + {12, 38}, + {11, 45}, + {15, 39}, + {11, 42}, + {13, 44}, + {16, 45}, + {12, 41}, + {10, 49}, + {30, 34}, + {18, 42}, + {10, 55}, + {17, 51}, + {17, 46}, + {0, 89}}, + {{23, -13}, + {26, -13}, + {40, -15}, + {49, -14}, + {44, 3}, + {45, 6}, + {44, 34}, + {33, 54}, + {19, 82}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{26, -19}, + {22, -17}, + {26, -17}, + {30, -25}, + {28, -20}, + {33, -23}, + {37, -27}, + {33, -23}, + {40, -28}, + {38, -17}, + {33, -11}, + {40, -15}, + {41, -6}, + {38, 1}, + {41, 17}}, + // Cr in the 4:4:4 common mode + {{24, 0}, + {15, 9}, + {8, 25}, + {13, 18}, + {15, 9}, + {13, 19}, + {10, 37}, + {12, 18}, + {6, 29}, + {20, 33}, + {15, 30}, + {4, 45}, + {1, 58}, + {0, 62}, + {7, 61}}, + {CTX_UNUSED, + {12, 38}, + {11, 45}, + {15, 39}, + {11, 42}, + {13, 44}, + {16, 45}, + {12, 41}, + {10, 49}, + {30, 34}, + {18, 42}, + {10, 55}, + {17, 51}, + {17, 46}, + {0, 89}}, + {{23, -13}, + {26, -13}, + {40, -15}, + {49, -14}, + {44, 3}, + {45, 6}, + {44, 34}, + {33, 54}, + {19, 82}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{26, -19}, + {22, -17}, + {26, -17}, + {30, -25}, + {28, -20}, + {33, -23}, + {37, -27}, + {33, -23}, + {40, -28}, + {38, -17}, + {33, -11}, + {40, -15}, + {41, -6}, + {38, 1}, + {41, 17}}}}; -static const signed char INIT_MAP_I[1][22][15][2] = -{ - //----- model 0 ----- - { - { { -7, 93} , { -11, 87} , { -3, 77} , { -5, 71} , { -4, 63} , { -4, 68} , { -12, 84} , { -7, 62} , { -7, 65} , { 8, 61} , { 5, 56} , { -2, 66} , { 1, 64} , { 0, 61} , { -2, 78} }, - { CTX_UNUSED , { 1, 50} , { 7, 52} , { 10, 35} , { 0, 44} , { 11, 38} , { 1, 45} , { 0, 46} , { 5, 44} , { 31, 17} , { 1, 51} , { 7, 50} , { 28, 19} , { 16, 33} , { 14, 62} }, - { { -17, 120} , { -20, 112} , { -18, 114} , { -11, 85} , { -15, 92} , { -14, 89} , { -26, 71} , { -15, 81} , { -14, 80} , { 0, 68} , { -14, 70} , { -24, 56} , { -23, 68} , { -24, 50} , { -11, 74} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -13, 108} , { -15, 100} , { -13, 101} , { -13, 91} , { -12, 94} , { -10, 88} , { -16, 84} , { -10, 86} , { -7, 83} , { -13, 87} , { -19, 94} , { 1, 70} , { 0, 72} , { -5, 74} , { 18, 59} }, - { { -8, 102} , { -15, 100} , { 0, 95} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { -4, 75} , { 2, 72} , { -11, 75} , { -3, 71} , { 15, 46} , { -13, 69} , { 0, 62} , { 0, 65} , { 21, 37} , { -15, 72} , { 9, 57} , { 16, 54} , { 0, 62} , { 12, 72} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -7, 93} , { -11, 87} , { -3, 77} , { -5, 71} , { -4, 63} , { -4, 68} , { -12, 84} , { -7, 62} , { -7, 65} , { 8, 61} , { 5, 56} , { -2, 66} , { 1, 64} , { 0, 61} , { -2, 78} }, - { CTX_UNUSED , { 1, 50} , { 7, 52} , { 10, 35} , { 0, 44} , { 11, 38} , { 1, 45} , { 0, 46} , { 5, 44} , { 31, 17} , { 1, 51} , { 7, 50} , { 28, 19} , { 16, 33} , { 14, 62} }, - { { -17, 120} , { -20, 112} , { -18, 114} , { -11, 85} , { -15, 92} , { -14, 89} , { -26, 71} , { -15, 81} , { -14, 80} , { 0, 68} , { -14, 70} , { -24, 56} , { -23, 68} , { -24, 50} , { -11, 74} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -13, 108} , { -15, 100} , { -13, 101} , { -13, 91} , { -12, 94} , { -10, 88} , { -16, 84} , { -10, 86} , { -7, 83} , { -13, 87} , { -19, 94} , { 1, 70} , { 0, 72} , { -5, 74} , { 18, 59} }, - //Cr in the 4:4:4 common mode - { { -7, 93} , { -11, 87} , { -3, 77} , { -5, 71} , { -4, 63} , { -4, 68} , { -12, 84} , { -7, 62} , { -7, 65} , { 8, 61} , { 5, 56} , { -2, 66} , { 1, 64} , { 0, 61} , { -2, 78} }, - { CTX_UNUSED , { 1, 50} , { 7, 52} , { 10, 35} , { 0, 44} , { 11, 38} , { 1, 45} , { 0, 46} , { 5, 44} , { 31, 17} , { 1, 51} , { 7, 50} , { 28, 19} , { 16, 33} , { 14, 62} }, - { { -17, 120} , { -20, 112} , { -18, 114} , { -11, 85} , { -15, 92} , { -14, 89} , { -26, 71} , { -15, 81} , { -14, 80} , { 0, 68} , { -14, 70} , { -24, 56} , { -23, 68} , { -24, 50} , { -11, 74} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -13, 108} , { -15, 100} , { -13, 101} , { -13, 91} , { -12, 94} , { -10, 88} , { -16, 84} , { -10, 86} , { -7, 83} , { -13, 87} , { -19, 94} , { 1, 70} , { 0, 72} , { -5, 74} , { 18, 59} } - } -}; +static const signed char INIT_LAST_P[3][22][15][2] = { + //----- model 0 ----- + {{{11, 28}, + {2, 40}, + {3, 44}, + {0, 49}, + {0, 46}, + {2, 44}, + {2, 51}, + {0, 47}, + {4, 39}, + {2, 62}, + {6, 46}, + {0, 54}, + {3, 54}, + {2, 58}, + {4, 63}}, + {CTX_UNUSED, + {6, 51}, + {6, 57}, + {7, 53}, + {6, 52}, + {6, 55}, + {11, 45}, + {14, 36}, + {8, 53}, + {-1, 82}, + {7, 55}, + {-3, 78}, + {15, 46}, + {22, 31}, + {-1, 84}}, + {{9, -2}, + {26, -9}, + {33, -9}, + {39, -7}, + {41, -2}, + {45, 3}, + {49, 9}, + {45, 27}, + {36, 59}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{25, 7}, + {30, -7}, + {28, 3}, + {28, 4}, + {32, 0}, + {34, -1}, + {30, 6}, + {30, 6}, + {32, 9}, + {31, 19}, + {26, 27}, + {26, 30}, + {37, 20}, + {28, 34}, + {17, 70}}, + {{1, 67}, + {5, 59}, + {9, 67}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {16, 30}, + {18, 32}, + {18, 35}, + {22, 29}, + {24, 31}, + {23, 38}, + {18, 43}, + {20, 41}, + {11, 63}, + {9, 59}, + {9, 64}, + {-1, 94}, + {-2, 89}, + {-9, 108}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{11, 28}, + {2, 40}, + {3, 44}, + {0, 49}, + {0, 46}, + {2, 44}, + {2, 51}, + {0, 47}, + {4, 39}, + {2, 62}, + {6, 46}, + {0, 54}, + {3, 54}, + {2, 58}, + {4, 63}}, + {CTX_UNUSED, + {6, 51}, + {6, 57}, + {7, 53}, + {6, 52}, + {6, 55}, + {11, 45}, + {14, 36}, + {8, 53}, + {-1, 82}, + {7, 55}, + {-3, 78}, + {15, 46}, + {22, 31}, + {-1, 84}}, + {{9, -2}, + {26, -9}, + {33, -9}, + {39, -7}, + {41, -2}, + {45, 3}, + {49, 9}, + {45, 27}, + {36, 59}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{25, 7}, + {30, -7}, + {28, 3}, + {28, 4}, + {32, 0}, + {34, -1}, + {30, 6}, + {30, 6}, + {32, 9}, + {31, 19}, + {26, 27}, + {26, 30}, + {37, 20}, + {28, 34}, + {17, 70}}, + // Cr in the 4:4:4 common mode + {{11, 28}, + {2, 40}, + {3, 44}, + {0, 49}, + {0, 46}, + {2, 44}, + {2, 51}, + {0, 47}, + {4, 39}, + {2, 62}, + {6, 46}, + {0, 54}, + {3, 54}, + {2, 58}, + {4, 63}}, + {CTX_UNUSED, + {6, 51}, + {6, 57}, + {7, 53}, + {6, 52}, + {6, 55}, + {11, 45}, + {14, 36}, + {8, 53}, + {-1, 82}, + {7, 55}, + {-3, 78}, + {15, 46}, + {22, 31}, + {-1, 84}}, + {{9, -2}, + {26, -9}, + {33, -9}, + {39, -7}, + {41, -2}, + {45, 3}, + {49, 9}, + {45, 27}, + {36, 59}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{25, 7}, + {30, -7}, + {28, 3}, + {28, 4}, + {32, 0}, + {34, -1}, + {30, 6}, + {30, 6}, + {32, 9}, + {31, 19}, + {26, 27}, + {26, 30}, + {37, 20}, + {28, 34}, + {17, 70}}}, + //----- model 1 ----- + {{{4, 45}, + {10, 28}, + {10, 31}, + {33, -11}, + {52, -43}, + {18, 15}, + {28, 0}, + {35, -22}, + {38, -25}, + {34, 0}, + {39, -18}, + {32, -12}, + {102, -94}, + {0, 0}, + {56, -15}}, + {CTX_UNUSED, + {33, -4}, + {29, 10}, + {37, -5}, + {51, -29}, + {39, -9}, + {52, -34}, + {69, -58}, + {67, -63}, + {44, -5}, + {32, 7}, + {55, -29}, + {32, 1}, + {0, 0}, + {27, 36}}, + {{17, -10}, + {32, -13}, + {42, -9}, + {49, -5}, + {53, 0}, + {64, 3}, + {68, 10}, + {66, 27}, + {47, 57}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{33, -25}, + {34, -30}, + {36, -28}, + {38, -28}, + {38, -27}, + {34, -18}, + {35, -16}, + {34, -14}, + {32, -8}, + {37, -6}, + {35, 0}, + {30, 10}, + {28, 18}, + {26, 25}, + {29, 41}}, + {{0, 75}, + {2, 72}, + {8, 77}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {14, 35}, + {18, 31}, + {17, 35}, + {21, 30}, + {17, 45}, + {20, 42}, + {18, 45}, + {27, 26}, + {16, 54}, + {7, 66}, + {16, 56}, + {11, 73}, + {10, 67}, + {-10, 116}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{4, 45}, + {10, 28}, + {10, 31}, + {33, -11}, + {52, -43}, + {18, 15}, + {28, 0}, + {35, -22}, + {38, -25}, + {34, 0}, + {39, -18}, + {32, -12}, + {102, -94}, + {0, 0}, + {56, -15}}, + {CTX_UNUSED, + {33, -4}, + {29, 10}, + {37, -5}, + {51, -29}, + {39, -9}, + {52, -34}, + {69, -58}, + {67, -63}, + {44, -5}, + {32, 7}, + {55, -29}, + {32, 1}, + {0, 0}, + {27, 36}}, + {{17, -10}, + {32, -13}, + {42, -9}, + {49, -5}, + {53, 0}, + {64, 3}, + {68, 10}, + {66, 27}, + {47, 57}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{33, -25}, + {34, -30}, + {36, -28}, + {38, -28}, + {38, -27}, + {34, -18}, + {35, -16}, + {34, -14}, + {32, -8}, + {37, -6}, + {35, 0}, + {30, 10}, + {28, 18}, + {26, 25}, + {29, 41}}, + // Cr in the 4:4:4 common mode + {{4, 45}, + {10, 28}, + {10, 31}, + {33, -11}, + {52, -43}, + {18, 15}, + {28, 0}, + {35, -22}, + {38, -25}, + {34, 0}, + {39, -18}, + {32, -12}, + {102, -94}, + {0, 0}, + {56, -15}}, + {CTX_UNUSED, + {33, -4}, + {29, 10}, + {37, -5}, + {51, -29}, + {39, -9}, + {52, -34}, + {69, -58}, + {67, -63}, + {44, -5}, + {32, 7}, + {55, -29}, + {32, 1}, + {0, 0}, + {27, 36}}, + {{17, -10}, + {32, -13}, + {42, -9}, + {49, -5}, + {53, 0}, + {64, 3}, + {68, 10}, + {66, 27}, + {47, 57}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{33, -25}, + {34, -30}, + {36, -28}, + {38, -28}, + {38, -27}, + {34, -18}, + {35, -16}, + {34, -14}, + {32, -8}, + {37, -6}, + {35, 0}, + {30, 10}, + {28, 18}, + {26, 25}, + {29, 41}}}, + //----- model 2 ----- + {{{4, 39}, + {0, 42}, + {7, 34}, + {11, 29}, + {8, 31}, + {6, 37}, + {7, 42}, + {3, 40}, + {8, 33}, + {13, 43}, + {13, 36}, + {4, 47}, + {3, 55}, + {2, 58}, + {6, 60}}, + {CTX_UNUSED, + {8, 44}, + {11, 44}, + {14, 42}, + {7, 48}, + {4, 56}, + {4, 52}, + {13, 37}, + {9, 49}, + {19, 58}, + {10, 48}, + {12, 45}, + {0, 69}, + {20, 33}, + {8, 63}}, + {{9, -2}, + {30, -10}, + {31, -4}, + {33, -1}, + {33, 7}, + {31, 12}, + {37, 23}, + {31, 38}, + {20, 64}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{35, -18}, + {33, -25}, + {28, -3}, + {24, 10}, + {27, 0}, + {34, -14}, + {52, -44}, + {39, -24}, + {19, 17}, + {31, 25}, + {36, 29}, + {24, 33}, + {34, 15}, + {30, 20}, + {22, 73}}, + {{20, 34}, + {19, 31}, + {27, 44}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {19, 16}, + {15, 36}, + {15, 36}, + {21, 28}, + {25, 21}, + {30, 20}, + {31, 12}, + {27, 16}, + {24, 42}, + {0, 93}, + {14, 56}, + {15, 57}, + {26, 38}, + {-24, 127}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{4, 39}, + {0, 42}, + {7, 34}, + {11, 29}, + {8, 31}, + {6, 37}, + {7, 42}, + {3, 40}, + {8, 33}, + {13, 43}, + {13, 36}, + {4, 47}, + {3, 55}, + {2, 58}, + {6, 60}}, + {CTX_UNUSED, + {8, 44}, + {11, 44}, + {14, 42}, + {7, 48}, + {4, 56}, + {4, 52}, + {13, 37}, + {9, 49}, + {19, 58}, + {10, 48}, + {12, 45}, + {0, 69}, + {20, 33}, + {8, 63}}, + {{9, -2}, + {30, -10}, + {31, -4}, + {33, -1}, + {33, 7}, + {31, 12}, + {37, 23}, + {31, 38}, + {20, 64}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{35, -18}, + {33, -25}, + {28, -3}, + {24, 10}, + {27, 0}, + {34, -14}, + {52, -44}, + {39, -24}, + {19, 17}, + {31, 25}, + {36, 29}, + {24, 33}, + {34, 15}, + {30, 20}, + {22, 73}}, + // Cr in the 4:4:4 common mode + {{4, 39}, + {0, 42}, + {7, 34}, + {11, 29}, + {8, 31}, + {6, 37}, + {7, 42}, + {3, 40}, + {8, 33}, + {13, 43}, + {13, 36}, + {4, 47}, + {3, 55}, + {2, 58}, + {6, 60}}, + {CTX_UNUSED, + {8, 44}, + {11, 44}, + {14, 42}, + {7, 48}, + {4, 56}, + {4, 52}, + {13, 37}, + {9, 49}, + {19, 58}, + {10, 48}, + {12, 45}, + {0, 69}, + {20, 33}, + {8, 63}}, + {{9, -2}, + {30, -10}, + {31, -4}, + {33, -1}, + {33, 7}, + {31, 12}, + {37, 23}, + {31, 38}, + {20, 64}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{35, -18}, + {33, -25}, + {28, -3}, + {24, 10}, + {27, 0}, + {34, -14}, + {52, -44}, + {39, -24}, + {19, 17}, + {31, 25}, + {36, 29}, + {24, 33}, + {34, 15}, + {30, 20}, + {22, 73}}}}; -static const signed char INIT_MAP_P[3][22][15][2] = -{ - //----- model 0 ----- - { - { { -2, 85} , { -6, 78} , { -1, 75} , { -7, 77} , { 2, 54} , { 5, 50} , { -3, 68} , { 1, 50} , { 6, 42} , { -4, 81} , { 1, 63} , { -4, 70} , { 0, 67} , { 2, 57} , { -2, 76} }, - { CTX_UNUSED , { 11, 35} , { 4, 64} , { 1, 61} , { 11, 35} , { 18, 25} , { 12, 24} , { 13, 29} , { 13, 36} , { -10, 93} , { -7, 73} , { -2, 73} , { 13, 46} , { 9, 49} , { -7, 100} }, - { { -4, 79} , { -7, 71} , { -5, 69} , { -9, 70} , { -8, 66} , { -10, 68} , { -19, 73} , { -12, 69} , { -16, 70} , { -15, 67} , { -20, 62} , { -19, 70} , { -16, 66} , { -22, 65} , { -20, 63} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 9, 53} , { 2, 53} , { 5, 53} , { -2, 61} , { 0, 56} , { 0, 56} , { -13, 63} , { -5, 60} , { -1, 62} , { 4, 57} , { -6, 69} , { 4, 57} , { 14, 39} , { 4, 51} , { 13, 68} }, - { { 3, 64} , { 1, 61} , { 9, 63} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 7, 50} , { 16, 39} , { 5, 44} , { 4, 52} , { 11, 48} , { -5, 60} , { -1, 59} , { 0, 59} , { 22, 33} , { 5, 44} , { 14, 43} , { -1, 78} , { 0, 60} , { 9, 69} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -2, 85} , { -6, 78} , { -1, 75} , { -7, 77} , { 2, 54} , { 5, 50} , { -3, 68} , { 1, 50} , { 6, 42} , { -4, 81} , { 1, 63} , { -4, 70} , { 0, 67} , { 2, 57} , { -2, 76} }, - { CTX_UNUSED , { 11, 35} , { 4, 64} , { 1, 61} , { 11, 35} , { 18, 25} , { 12, 24} , { 13, 29} , { 13, 36} , { -10, 93} , { -7, 73} , { -2, 73} , { 13, 46} , { 9, 49} , { -7, 100} }, - { { -4, 79} , { -7, 71} , { -5, 69} , { -9, 70} , { -8, 66} , { -10, 68} , { -19, 73} , { -12, 69} , { -16, 70} , { -15, 67} , { -20, 62} , { -19, 70} , { -16, 66} , { -22, 65} , { -20, 63} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 9, 53} , { 2, 53} , { 5, 53} , { -2, 61} , { 0, 56} , { 0, 56} , { -13, 63} , { -5, 60} , { -1, 62} , { 4, 57} , { -6, 69} , { 4, 57} , { 14, 39} , { 4, 51} , { 13, 68} }, - //Cr in the 4:4:4 common mode - { { -2, 85} , { -6, 78} , { -1, 75} , { -7, 77} , { 2, 54} , { 5, 50} , { -3, 68} , { 1, 50} , { 6, 42} , { -4, 81} , { 1, 63} , { -4, 70} , { 0, 67} , { 2, 57} , { -2, 76} }, - { CTX_UNUSED , { 11, 35} , { 4, 64} , { 1, 61} , { 11, 35} , { 18, 25} , { 12, 24} , { 13, 29} , { 13, 36} , { -10, 93} , { -7, 73} , { -2, 73} , { 13, 46} , { 9, 49} , { -7, 100} }, - { { -4, 79} , { -7, 71} , { -5, 69} , { -9, 70} , { -8, 66} , { -10, 68} , { -19, 73} , { -12, 69} , { -16, 70} , { -15, 67} , { -20, 62} , { -19, 70} , { -16, 66} , { -22, 65} , { -20, 63} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 9, 53} , { 2, 53} , { 5, 53} , { -2, 61} , { 0, 56} , { 0, 56} , { -13, 63} , { -5, 60} , { -1, 62} , { 4, 57} , { -6, 69} , { 4, 57} , { 14, 39} , { 4, 51} , { 13, 68} } - }, - //----- model 1 ----- - { - { { -13, 103} , { -13, 91} , { -9, 89} , { -14, 92} , { -8, 76} , { -12, 87} , { -23, 110} , { -24, 105} , { -10, 78} , { -20, 112} , { -17, 99} , { -78, 127} , { -70, 127} , { -50, 127} , { -46, 127} }, - { CTX_UNUSED , { -4, 66} , { -5, 78} , { -4, 71} , { -8, 72} , { 2, 59} , { -1, 55} , { -7, 70} , { -6, 75} , { -8, 89} , { -34, 119} , { -3, 75} , { 32, 20} , { 30, 22} , { -44, 127} }, - { { -5, 85} , { -6, 81} , { -10, 77} , { -7, 81} , { -17, 80} , { -18, 73} , { -4, 74} , { -10, 83} , { -9, 71} , { -9, 67} , { -1, 61} , { -8, 66} , { -14, 66} , { 0, 59} , { 2, 59} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 0, 54} , { -5, 61} , { 0, 58} , { -1, 60} , { -3, 61} , { -8, 67} , { -25, 84} , { -14, 74} , { -5, 65} , { 5, 52} , { 2, 57} , { 0, 61} , { -9, 69} , { -11, 70} , { 18, 55} }, - { { -4, 71} , { 0, 58} , { 7, 61} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 9, 41} , { 18, 25} , { 9, 32} , { 5, 43} , { 9, 47} , { 0, 44} , { 0, 51} , { 2, 46} , { 19, 38} , { -4, 66} , { 15, 38} , { 12, 42} , { 9, 34} , { 0, 89} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -13, 103} , { -13, 91} , { -9, 89} , { -14, 92} , { -8, 76} , { -12, 87} , { -23, 110} , { -24, 105} , { -10, 78} , { -20, 112} , { -17, 99} , { -78, 127} , { -70, 127} , { -50, 127} , { -46, 127} }, - { CTX_UNUSED , { -4, 66} , { -5, 78} , { -4, 71} , { -8, 72} , { 2, 59} , { -1, 55} , { -7, 70} , { -6, 75} , { -8, 89} , { -34, 119} , { -3, 75} , { 32, 20} , { 30, 22} , { -44, 127} }, - { { -5, 85} , { -6, 81} , { -10, 77} , { -7, 81} , { -17, 80} , { -18, 73} , { -4, 74} , { -10, 83} , { -9, 71} , { -9, 67} , { -1, 61} , { -8, 66} , { -14, 66} , { 0, 59} , { 2, 59} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 0, 54} , { -5, 61} , { 0, 58} , { -1, 60} , { -3, 61} , { -8, 67} , { -25, 84} , { -14, 74} , { -5, 65} , { 5, 52} , { 2, 57} , { 0, 61} , { -9, 69} , { -11, 70} , { 18, 55} }, - //Cr in the 4:4:4 common mode - { { -13, 103} , { -13, 91} , { -9, 89} , { -14, 92} , { -8, 76} , { -12, 87} , { -23, 110} , { -24, 105} , { -10, 78} , { -20, 112} , { -17, 99} , { -78, 127} , { -70, 127} , { -50, 127} , { -46, 127} }, - { CTX_UNUSED , { -4, 66} , { -5, 78} , { -4, 71} , { -8, 72} , { 2, 59} , { -1, 55} , { -7, 70} , { -6, 75} , { -8, 89} , { -34, 119} , { -3, 75} , { 32, 20} , { 30, 22} , { -44, 127} }, - { { -5, 85} , { -6, 81} , { -10, 77} , { -7, 81} , { -17, 80} , { -18, 73} , { -4, 74} , { -10, 83} , { -9, 71} , { -9, 67} , { -1, 61} , { -8, 66} , { -14, 66} , { 0, 59} , { 2, 59} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 0, 54} , { -5, 61} , { 0, 58} , { -1, 60} , { -3, 61} , { -8, 67} , { -25, 84} , { -14, 74} , { -5, 65} , { 5, 52} , { 2, 57} , { 0, 61} , { -9, 69} , { -11, 70} , { 18, 55} } - }, - //----- model 2 ----- - { - { { -4, 86} , { -12, 88} , { -5, 82} , { -3, 72} , { -4, 67} , { -8, 72} , { -16, 89} , { -9, 69} , { -1, 59} , { 5, 66} , { 4, 57} , { -4, 71} , { -2, 71} , { 2, 58} , { -1, 74} }, - { CTX_UNUSED , { -4, 44} , { -1, 69} , { 0, 62} , { -7, 51} , { -4, 47} , { -6, 42} , { -3, 41} , { -6, 53} , { 8, 76} , { -9, 78} , { -11, 83} , { 9, 52} , { 0, 67} , { -5, 90} }, - { { -3, 78} , { -8, 74} , { -9, 72} , { -10, 72} , { -18, 75} , { -12, 71} , { -11, 63} , { -5, 70} , { -17, 75} , { -14, 72} , { -16, 67} , { -8, 53} , { -14, 59} , { -9, 52} , { -11, 68} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 1, 67} , { -15, 72} , { -5, 75} , { -8, 80} , { -21, 83} , { -21, 64} , { -13, 31} , { -25, 64} , { -29, 94} , { 9, 75} , { 17, 63} , { -8, 74} , { -5, 35} , { -2, 27} , { 13, 91} }, - { { 3, 65} , { -7, 69} , { 8, 77} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { -10, 66} , { 3, 62} , { -3, 68} , { -20, 81} , { 0, 30} , { 1, 7} , { -3, 23} , { -21, 74} , { 16, 66} , { -23, 124} , { 17, 37} , { 44, -18} , { 50, -34} , { -22, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -4, 86} , { -12, 88} , { -5, 82} , { -3, 72} , { -4, 67} , { -8, 72} , { -16, 89} , { -9, 69} , { -1, 59} , { 5, 66} , { 4, 57} , { -4, 71} , { -2, 71} , { 2, 58} , { -1, 74} }, - { CTX_UNUSED , { -4, 44} , { -1, 69} , { 0, 62} , { -7, 51} , { -4, 47} , { -6, 42} , { -3, 41} , { -6, 53} , { 8, 76} , { -9, 78} , { -11, 83} , { 9, 52} , { 0, 67} , { -5, 90} }, - { { -3, 78} , { -8, 74} , { -9, 72} , { -10, 72} , { -18, 75} , { -12, 71} , { -11, 63} , { -5, 70} , { -17, 75} , { -14, 72} , { -16, 67} , { -8, 53} , { -14, 59} , { -9, 52} , { -11, 68} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 1, 67} , { -15, 72} , { -5, 75} , { -8, 80} , { -21, 83} , { -21, 64} , { -13, 31} , { -25, 64} , { -29, 94} , { 9, 75} , { 17, 63} , { -8, 74} , { -5, 35} , { -2, 27} , { 13, 91} }, - //Cr in the 4:4:4 common mode - { { -4, 86} , { -12, 88} , { -5, 82} , { -3, 72} , { -4, 67} , { -8, 72} , { -16, 89} , { -9, 69} , { -1, 59} , { 5, 66} , { 4, 57} , { -4, 71} , { -2, 71} , { 2, 58} , { -1, 74} }, - { CTX_UNUSED , { -4, 44} , { -1, 69} , { 0, 62} , { -7, 51} , { -4, 47} , { -6, 42} , { -3, 41} , { -6, 53} , { 8, 76} , { -9, 78} , { -11, 83} , { 9, 52} , { 0, 67} , { -5, 90} }, - { { -3, 78} , { -8, 74} , { -9, 72} , { -10, 72} , { -18, 75} , { -12, 71} , { -11, 63} , { -5, 70} , { -17, 75} , { -14, 72} , { -16, 67} , { -8, 53} , { -14, 59} , { -9, 52} , { -11, 68} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 1, 67} , { -15, 72} , { -5, 75} , { -8, 80} , { -21, 83} , { -21, 64} , { -13, 31} , { -25, 64} , { -29, 94} , { 9, 75} , { 17, 63} , { -8, 74} , { -5, 35} , { -2, 27} , { 13, 91} } - } -}; +static const signed char INIT_ONE_I[1][22][5][2] = { + //----- model 0 ----- + {{{-3, 71}, {-6, 42}, {-5, 50}, {-3, 54}, {-2, 62}}, + {{-5, 67}, {-5, 27}, {-3, 39}, {-2, 44}, {0, 46}}, + {{-3, 75}, {-1, 23}, {1, 34}, {1, 43}, {0, 54}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-12, 92}, {-15, 55}, {-10, 60}, {-6, 62}, {-4, 65}}, + {{-11, 97}, {-20, 84}, {-11, 79}, {-6, 73}, {-4, 74}}, + {{-8, 78}, {-5, 33}, {-4, 48}, {-2, 53}, {-3, 62}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-3, 71}, {-6, 42}, {-5, 50}, {-3, 54}, {-2, 62}}, + {{-5, 67}, {-5, 27}, {-3, 39}, {-2, 44}, {0, 46}}, + {{-3, 75}, {-1, 23}, {1, 34}, {1, 43}, {0, 54}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-12, 92}, {-15, 55}, {-10, 60}, {-6, 62}, {-4, 65}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{-3, 71}, {-6, 42}, {-5, 50}, {-3, 54}, {-2, 62}}, + {{-5, 67}, {-5, 27}, {-3, 39}, {-2, 44}, {0, 46}}, + {{-3, 75}, {-1, 23}, {1, 34}, {1, 43}, {0, 54}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-12, 92}, {-15, 55}, {-10, 60}, {-6, 62}, {-4, 65}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; -static const signed char INIT_LAST_I[1][22][15][2] = -{ - //----- model 0 ----- - { - { { 24, 0} , { 15, 9} , { 8, 25} , { 13, 18} , { 15, 9} , { 13, 19} , { 10, 37} , { 12, 18} , { 6, 29} , { 20, 33} , { 15, 30} , { 4, 45} , { 1, 58} , { 0, 62} , { 7, 61} }, - { CTX_UNUSED , { 12, 38} , { 11, 45} , { 15, 39} , { 11, 42} , { 13, 44} , { 16, 45} , { 12, 41} , { 10, 49} , { 30, 34} , { 18, 42} , { 10, 55} , { 17, 51} , { 17, 46} , { 0, 89} }, - { { 23, -13} , { 26, -13} , { 40, -15} , { 49, -14} , { 44, 3} , { 45, 6} , { 44, 34} , { 33, 54} , { 19, 82} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 26, -19} , { 22, -17} , { 26, -17} , { 30, -25} , { 28, -20} , { 33, -23} , { 37, -27} , { 33, -23} , { 40, -28} , { 38, -17} , { 33, -11} , { 40, -15} , { 41, -6} , { 38, 1} , { 41, 17} }, - { { 30, -6} , { 27, 3} , { 26, 22} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 37, -16} , { 35, -4} , { 38, -8} , { 38, -3} , { 37, 3} , { 38, 5} , { 42, 0} , { 35, 16} , { 39, 22} , { 14, 48} , { 27, 37} , { 21, 60} , { 12, 68} , { 2, 97} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { 24, 0} , { 15, 9} , { 8, 25} , { 13, 18} , { 15, 9} , { 13, 19} , { 10, 37} , { 12, 18} , { 6, 29} , { 20, 33} , { 15, 30} , { 4, 45} , { 1, 58} , { 0, 62} , { 7, 61} }, - { CTX_UNUSED , { 12, 38} , { 11, 45} , { 15, 39} , { 11, 42} , { 13, 44} , { 16, 45} , { 12, 41} , { 10, 49} , { 30, 34} , { 18, 42} , { 10, 55} , { 17, 51} , { 17, 46} , { 0, 89} }, - { { 23, -13} , { 26, -13} , { 40, -15} , { 49, -14} , { 44, 3} , { 45, 6} , { 44, 34} , { 33, 54} , { 19, 82} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 26, -19} , { 22, -17} , { 26, -17} , { 30, -25} , { 28, -20} , { 33, -23} , { 37, -27} , { 33, -23} , { 40, -28} , { 38, -17} , { 33, -11} , { 40, -15} , { 41, -6} , { 38, 1} , { 41, 17} }, - //Cr in the 4:4:4 common mode - { { 24, 0} , { 15, 9} , { 8, 25} , { 13, 18} , { 15, 9} , { 13, 19} , { 10, 37} , { 12, 18} , { 6, 29} , { 20, 33} , { 15, 30} , { 4, 45} , { 1, 58} , { 0, 62} , { 7, 61} }, - { CTX_UNUSED , { 12, 38} , { 11, 45} , { 15, 39} , { 11, 42} , { 13, 44} , { 16, 45} , { 12, 41} , { 10, 49} , { 30, 34} , { 18, 42} , { 10, 55} , { 17, 51} , { 17, 46} , { 0, 89} }, - { { 23, -13} , { 26, -13} , { 40, -15} , { 49, -14} , { 44, 3} , { 45, 6} , { 44, 34} , { 33, 54} , { 19, 82} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 26, -19} , { 22, -17} , { 26, -17} , { 30, -25} , { 28, -20} , { 33, -23} , { 37, -27} , { 33, -23} , { 40, -28} , { 38, -17} , { 33, -11} , { 40, -15} , { 41, -6} , { 38, 1} , { 41, 17} } - } -}; - -static const signed char INIT_LAST_P[3][22][15][2] = -{ - //----- model 0 ----- - { - { { 11, 28} , { 2, 40} , { 3, 44} , { 0, 49} , { 0, 46} , { 2, 44} , { 2, 51} , { 0, 47} , { 4, 39} , { 2, 62} , { 6, 46} , { 0, 54} , { 3, 54} , { 2, 58} , { 4, 63} }, - { CTX_UNUSED , { 6, 51} , { 6, 57} , { 7, 53} , { 6, 52} , { 6, 55} , { 11, 45} , { 14, 36} , { 8, 53} , { -1, 82} , { 7, 55} , { -3, 78} , { 15, 46} , { 22, 31} , { -1, 84} }, - { { 9, -2} , { 26, -9} , { 33, -9} , { 39, -7} , { 41, -2} , { 45, 3} , { 49, 9} , { 45, 27} , { 36, 59} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 25, 7} , { 30, -7} , { 28, 3} , { 28, 4} , { 32, 0} , { 34, -1} , { 30, 6} , { 30, 6} , { 32, 9} , { 31, 19} , { 26, 27} , { 26, 30} , { 37, 20} , { 28, 34} , { 17, 70} }, - { { 1, 67} , { 5, 59} , { 9, 67} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 16, 30} , { 18, 32} , { 18, 35} , { 22, 29} , { 24, 31} , { 23, 38} , { 18, 43} , { 20, 41} , { 11, 63} , { 9, 59} , { 9, 64} , { -1, 94} , { -2, 89} , { -9, 108} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { 11, 28} , { 2, 40} , { 3, 44} , { 0, 49} , { 0, 46} , { 2, 44} , { 2, 51} , { 0, 47} , { 4, 39} , { 2, 62} , { 6, 46} , { 0, 54} , { 3, 54} , { 2, 58} , { 4, 63} }, - { CTX_UNUSED , { 6, 51} , { 6, 57} , { 7, 53} , { 6, 52} , { 6, 55} , { 11, 45} , { 14, 36} , { 8, 53} , { -1, 82} , { 7, 55} , { -3, 78} , { 15, 46} , { 22, 31} , { -1, 84} }, - { { 9, -2} , { 26, -9} , { 33, -9} , { 39, -7} , { 41, -2} , { 45, 3} , { 49, 9} , { 45, 27} , { 36, 59} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 25, 7} , { 30, -7} , { 28, 3} , { 28, 4} , { 32, 0} , { 34, -1} , { 30, 6} , { 30, 6} , { 32, 9} , { 31, 19} , { 26, 27} , { 26, 30} , { 37, 20} , { 28, 34} , { 17, 70} }, - //Cr in the 4:4:4 common mode - { { 11, 28} , { 2, 40} , { 3, 44} , { 0, 49} , { 0, 46} , { 2, 44} , { 2, 51} , { 0, 47} , { 4, 39} , { 2, 62} , { 6, 46} , { 0, 54} , { 3, 54} , { 2, 58} , { 4, 63} }, - { CTX_UNUSED , { 6, 51} , { 6, 57} , { 7, 53} , { 6, 52} , { 6, 55} , { 11, 45} , { 14, 36} , { 8, 53} , { -1, 82} , { 7, 55} , { -3, 78} , { 15, 46} , { 22, 31} , { -1, 84} }, - { { 9, -2} , { 26, -9} , { 33, -9} , { 39, -7} , { 41, -2} , { 45, 3} , { 49, 9} , { 45, 27} , { 36, 59} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 25, 7} , { 30, -7} , { 28, 3} , { 28, 4} , { 32, 0} , { 34, -1} , { 30, 6} , { 30, 6} , { 32, 9} , { 31, 19} , { 26, 27} , { 26, 30} , { 37, 20} , { 28, 34} , { 17, 70} } - }, - //----- model 1 ----- - { - { { 4, 45} , { 10, 28} , { 10, 31} , { 33, -11} , { 52, -43} , { 18, 15} , { 28, 0} , { 35, -22} , { 38, -25} , { 34, 0} , { 39, -18} , { 32, -12} , { 102, -94} , { 0, 0} , { 56, -15} }, - { CTX_UNUSED , { 33, -4} , { 29, 10} , { 37, -5} , { 51, -29} , { 39, -9} , { 52, -34} , { 69, -58} , { 67, -63} , { 44, -5} , { 32, 7} , { 55, -29} , { 32, 1} , { 0, 0} , { 27, 36} }, - { { 17, -10} , { 32, -13} , { 42, -9} , { 49, -5} , { 53, 0} , { 64, 3} , { 68, 10} , { 66, 27} , { 47, 57} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 33, -25} , { 34, -30} , { 36, -28} , { 38, -28} , { 38, -27} , { 34, -18} , { 35, -16} , { 34, -14} , { 32, -8} , { 37, -6} , { 35, 0} , { 30, 10} , { 28, 18} , { 26, 25} , { 29, 41} }, - { { 0, 75} , { 2, 72} , { 8, 77} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 14, 35} , { 18, 31} , { 17, 35} , { 21, 30} , { 17, 45} , { 20, 42} , { 18, 45} , { 27, 26} , { 16, 54} , { 7, 66} , { 16, 56} , { 11, 73} , { 10, 67} , { -10, 116} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { 4, 45} , { 10, 28} , { 10, 31} , { 33, -11} , { 52, -43} , { 18, 15} , { 28, 0} , { 35, -22} , { 38, -25} , { 34, 0} , { 39, -18} , { 32, -12} , { 102, -94} , { 0, 0} , { 56, -15} }, - { CTX_UNUSED , { 33, -4} , { 29, 10} , { 37, -5} , { 51, -29} , { 39, -9} , { 52, -34} , { 69, -58} , { 67, -63} , { 44, -5} , { 32, 7} , { 55, -29} , { 32, 1} , { 0, 0} , { 27, 36} }, - { { 17, -10} , { 32, -13} , { 42, -9} , { 49, -5} , { 53, 0} , { 64, 3} , { 68, 10} , { 66, 27} , { 47, 57} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 33, -25} , { 34, -30} , { 36, -28} , { 38, -28} , { 38, -27} , { 34, -18} , { 35, -16} , { 34, -14} , { 32, -8} , { 37, -6} , { 35, 0} , { 30, 10} , { 28, 18} , { 26, 25} , { 29, 41} }, - //Cr in the 4:4:4 common mode - { { 4, 45} , { 10, 28} , { 10, 31} , { 33, -11} , { 52, -43} , { 18, 15} , { 28, 0} , { 35, -22} , { 38, -25} , { 34, 0} , { 39, -18} , { 32, -12} , { 102, -94} , { 0, 0} , { 56, -15} }, - { CTX_UNUSED , { 33, -4} , { 29, 10} , { 37, -5} , { 51, -29} , { 39, -9} , { 52, -34} , { 69, -58} , { 67, -63} , { 44, -5} , { 32, 7} , { 55, -29} , { 32, 1} , { 0, 0} , { 27, 36} }, - { { 17, -10} , { 32, -13} , { 42, -9} , { 49, -5} , { 53, 0} , { 64, 3} , { 68, 10} , { 66, 27} , { 47, 57} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 33, -25} , { 34, -30} , { 36, -28} , { 38, -28} , { 38, -27} , { 34, -18} , { 35, -16} , { 34, -14} , { 32, -8} , { 37, -6} , { 35, 0} , { 30, 10} , { 28, 18} , { 26, 25} , { 29, 41} } - }, - //----- model 2 ----- - { - { { 4, 39} , { 0, 42} , { 7, 34} , { 11, 29} , { 8, 31} , { 6, 37} , { 7, 42} , { 3, 40} , { 8, 33} , { 13, 43} , { 13, 36} , { 4, 47} , { 3, 55} , { 2, 58} , { 6, 60} }, - { CTX_UNUSED , { 8, 44} , { 11, 44} , { 14, 42} , { 7, 48} , { 4, 56} , { 4, 52} , { 13, 37} , { 9, 49} , { 19, 58} , { 10, 48} , { 12, 45} , { 0, 69} , { 20, 33} , { 8, 63} }, - { { 9, -2} , { 30, -10} , { 31, -4} , { 33, -1} , { 33, 7} , { 31, 12} , { 37, 23} , { 31, 38} , { 20, 64} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 35, -18} , { 33, -25} , { 28, -3} , { 24, 10} , { 27, 0} , { 34, -14} , { 52, -44} , { 39, -24} , { 19, 17} , { 31, 25} , { 36, 29} , { 24, 33} , { 34, 15} , { 30, 20} , { 22, 73} }, - { { 20, 34} , { 19, 31} , { 27, 44} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 19, 16} , { 15, 36} , { 15, 36} , { 21, 28} , { 25, 21} , { 30, 20} , { 31, 12} , { 27, 16} , { 24, 42} , { 0, 93} , { 14, 56} , { 15, 57} , { 26, 38} , { -24, 127} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { 4, 39} , { 0, 42} , { 7, 34} , { 11, 29} , { 8, 31} , { 6, 37} , { 7, 42} , { 3, 40} , { 8, 33} , { 13, 43} , { 13, 36} , { 4, 47} , { 3, 55} , { 2, 58} , { 6, 60} }, - { CTX_UNUSED , { 8, 44} , { 11, 44} , { 14, 42} , { 7, 48} , { 4, 56} , { 4, 52} , { 13, 37} , { 9, 49} , { 19, 58} , { 10, 48} , { 12, 45} , { 0, 69} , { 20, 33} , { 8, 63} }, - { { 9, -2} , { 30, -10} , { 31, -4} , { 33, -1} , { 33, 7} , { 31, 12} , { 37, 23} , { 31, 38} , { 20, 64} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 35, -18} , { 33, -25} , { 28, -3} , { 24, 10} , { 27, 0} , { 34, -14} , { 52, -44} , { 39, -24} , { 19, 17} , { 31, 25} , { 36, 29} , { 24, 33} , { 34, 15} , { 30, 20} , { 22, 73} }, - //Cr in the 4:4:4 common mode - { { 4, 39} , { 0, 42} , { 7, 34} , { 11, 29} , { 8, 31} , { 6, 37} , { 7, 42} , { 3, 40} , { 8, 33} , { 13, 43} , { 13, 36} , { 4, 47} , { 3, 55} , { 2, 58} , { 6, 60} }, - { CTX_UNUSED , { 8, 44} , { 11, 44} , { 14, 42} , { 7, 48} , { 4, 56} , { 4, 52} , { 13, 37} , { 9, 49} , { 19, 58} , { 10, 48} , { 12, 45} , { 0, 69} , { 20, 33} , { 8, 63} }, - { { 9, -2} , { 30, -10} , { 31, -4} , { 33, -1} , { 33, 7} , { 31, 12} , { 37, 23} , { 31, 38} , { 20, 64} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 35, -18} , { 33, -25} , { 28, -3} , { 24, 10} , { 27, 0} , { 34, -14} , { 52, -44} , { 39, -24} , { 19, 17} , { 31, 25} , { 36, 29} , { 24, 33} , { 34, 15} , { 30, 20} , { 22, 73} } - } -}; - -static const signed char INIT_ONE_I[1][22][5][2] = -{ - //----- model 0 ----- - { - { { -3, 71} , { -6, 42} , { -5, 50} , { -3, 54} , { -2, 62} }, - { { -5, 67} , { -5, 27} , { -3, 39} , { -2, 44} , { 0, 46} }, - { { -3, 75} , { -1, 23} , { 1, 34} , { 1, 43} , { 0, 54} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -12, 92} , { -15, 55} , { -10, 60} , { -6, 62} , { -4, 65} }, - { { -11, 97} , { -20, 84} , { -11, 79} , { -6, 73} , { -4, 74} }, - { { -8, 78} , { -5, 33} , { -4, 48} , { -2, 53} , { -3, 62} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -3, 71} , { -6, 42} , { -5, 50} , { -3, 54} , { -2, 62} }, - { { -5, 67} , { -5, 27} , { -3, 39} , { -2, 44} , { 0, 46} }, - { { -3, 75} , { -1, 23} , { 1, 34} , { 1, 43} , { 0, 54} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -12, 92} , { -15, 55} , { -10, 60} , { -6, 62} , { -4, 65} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cr in the 4:4:4 common mode - { { -3, 71} , { -6, 42} , { -5, 50} , { -3, 54} , { -2, 62} }, - { { -5, 67} , { -5, 27} , { -3, 39} , { -2, 44} , { 0, 46} }, - { { -3, 75} , { -1, 23} , { 1, 34} , { 1, 43} , { 0, 54} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -12, 92} , { -15, 55} , { -10, 60} , { -6, 62} , { -4, 65} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; - -static const signed char INIT_ONE_P[3][22][5][2] = -{ - //----- model 0 ----- - { - { { -6, 76} , { -2, 44} , { 0, 45} , { 0, 52} , { -3, 64} }, - { { -9, 77} , { 3, 24} , { 0, 42} , { 0, 48} , { 0, 55} }, - { { -6, 66} , { -7, 35} , { -7, 42} , { -8, 45} , { -5, 48} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 1, 58} , { -3, 29} , { -1, 36} , { 1, 38} , { 2, 43} }, - { { 0, 70} , { -4, 29} , { 5, 31} , { 7, 42} , { 1, 59} }, - { { 0, 58} , { 8, 5} , { 10, 14} , { 14, 18} , { 13, 27} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -6, 76} , { -2, 44} , { 0, 45} , { 0, 52} , { -3, 64} }, - { { -9, 77} , { 3, 24} , { 0, 42} , { 0, 48} , { 0, 55} }, - { { -6, 66} , { -7, 35} , { -7, 42} , { -8, 45} , { -5, 48} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 1, 58} , { -3, 29} , { -1, 36} , { 1, 38} , { 2, 43} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cr in the 4:4:4 common mode - { { -6, 76} , { -2, 44} , { 0, 45} , { 0, 52} , { -3, 64} }, - { { -9, 77} , { 3, 24} , { 0, 42} , { 0, 48} , { 0, 55} }, - { { -6, 66} , { -7, 35} , { -7, 42} , { -8, 45} , { -5, 48} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 1, 58} , { -3, 29} , { -1, 36} , { 1, 38} , { 2, 43} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - }, - //----- model 1 ----- - { - { { -23, 112} , { -15, 71} , { -7, 61} , { 0, 53} , { -5, 66} }, - { { -21, 101} , { -3, 39} , { -5, 53} , { -7, 61} , { -11, 75} }, - { { -5, 71} , { 0, 24} , { -1, 36} , { -2, 42} , { -2, 52} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -11, 76} , { -10, 44} , { -10, 52} , { -10, 57} , { -9, 58} }, - { { 2, 66} , { -9, 34} , { 1, 32} , { 11, 31} , { 5, 52} }, - { { 3, 52} , { 7, 4} , { 10, 8} , { 17, 8} , { 16, 19} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -23, 112} , { -15, 71} , { -7, 61} , { 0, 53} , { -5, 66} }, - { { -21, 101} , { -3, 39} , { -5, 53} , { -7, 61} , { -11, 75} }, - { { -5, 71} , { 0, 24} , { -1, 36} , { -2, 42} , { -2, 52} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -11, 76} , { -10, 44} , { -10, 52} , { -10, 57} , { -9, 58} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cr in the 4:4:4 common mode - { { -23, 112} , { -15, 71} , { -7, 61} , { 0, 53} , { -5, 66} }, - { { -21, 101} , { -3, 39} , { -5, 53} , { -7, 61} , { -11, 75} }, - { { -5, 71} , { 0, 24} , { -1, 36} , { -2, 42} , { -2, 52} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -11, 76} , { -10, 44} , { -10, 52} , { -10, 57} , { -9, 58} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - }, - //----- model 2 ----- - { - { { -24, 115} , { -22, 82} , { -9, 62} , { 0, 53} , { 0, 59} }, - { { -21, 100} , { -14, 57} , { -12, 67} , { -11, 71} , { -10, 77} }, - { { -9, 71} , { -7, 37} , { -8, 44} , { -11, 49} , { -10, 56} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -10, 82} , { -8, 48} , { -8, 61} , { -8, 66} , { -7, 70} }, - { { -4, 79} , { -22, 69} , { -16, 75} , { -2, 58} , { 1, 58} }, - { { -13, 81} , { -6, 38} , { -13, 62} , { -6, 58} , { -2, 59} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -24, 115} , { -22, 82} , { -9, 62} , { 0, 53} , { 0, 59} }, - { { -21, 100} , { -14, 57} , { -12, 67} , { -11, 71} , { -10, 77} }, - { { -9, 71} , { -7, 37} , { -8, 44} , { -11, 49} , { -10, 56} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -10, 82} , { -8, 48} , { -8, 61} , { -8, 66} , { -7, 70} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cr in the 4:4:4 common mode - { { -24, 115} , { -22, 82} , { -9, 62} , { 0, 53} , { 0, 59} }, - { { -21, 100} , { -14, 57} , { -12, 67} , { -11, 71} , { -10, 77} }, - { { -9, 71} , { -7, 37} , { -8, 44} , { -11, 49} , { -10, 56} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -10, 82} , { -8, 48} , { -8, 61} , { -8, 66} , { -7, 70} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; - -static const signed char INIT_ABS_I[1][22][5][2] = -{ - //----- model 0 ----- - { - { { 0, 58} , { 1, 63} , { -2, 72} , { -1, 74} , { -9, 91} }, - { { -16, 64} , { -8, 68} , { -10, 78} , { -6, 77} , { -10, 86} }, - { { -2, 55} , { 0, 61} , { 1, 64} , { 0, 68} , { -9, 92} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -12, 73} , { -8, 76} , { -7, 80} , { -9, 88} , { -17, 110} }, - { { -13, 86} , { -13, 96} , { -11, 97} , { -19, 117} , CTX_UNUSED }, - { { -13, 71} , { -10, 79} , { -12, 86} , { -13, 90} , { -14, 97} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { 0, 58} , { 1, 63} , { -2, 72} , { -1, 74} , { -9, 91} }, - { { -16, 64} , { -8, 68} , { -10, 78} , { -6, 77} , { -10, 86} }, - { { -2, 55} , { 0, 61} , { 1, 64} , { 0, 68} , { -9, 92} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -12, 73} , { -8, 76} , { -7, 80} , { -9, 88} , { -17, 110} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cr in the 4:4:4 common mode - { { 0, 58} , { 1, 63} , { -2, 72} , { -1, 74} , { -9, 91} }, - { { -16, 64} , { -8, 68} , { -10, 78} , { -6, 77} , { -10, 86} }, - { { -2, 55} , { 0, 61} , { 1, 64} , { 0, 68} , { -9, 92} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -12, 73} , { -8, 76} , { -7, 80} , { -9, 88} , { -17, 110} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; - -static const signed char INIT_ABS_P[3][22][5][2] = -{ - //----- model 0 ----- - { - { { -2, 59} , { -4, 70} , { -4, 75} , { -8, 82} , { -17, 102} }, - { { -6, 59} , { -7, 71} , { -12, 83} , { -11, 87} , { -30, 119} }, - { { -12, 56} , { -6, 60} , { -5, 62} , { -8, 66} , { -8, 76} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -6, 55} , { 0, 58} , { 0, 64} , { -3, 74} , { -10, 90} }, - { { -2, 58} , { -3, 72} , { -3, 81} , { -11, 97} , CTX_UNUSED }, - { { 2, 40} , { 0, 58} , { -3, 70} , { -6, 79} , { -8, 85} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -2, 59} , { -4, 70} , { -4, 75} , { -8, 82} , { -17, 102} }, - { { -6, 59} , { -7, 71} , { -12, 83} , { -11, 87} , { -30, 119} }, - { { -12, 56} , { -6, 60} , { -5, 62} , { -8, 66} , { -8, 76} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -6, 55} , { 0, 58} , { 0, 64} , { -3, 74} , { -10, 90} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cr in the 4:4:4 common mode - { { -2, 59} , { -4, 70} , { -4, 75} , { -8, 82} , { -17, 102} }, - { { -6, 59} , { -7, 71} , { -12, 83} , { -11, 87} , { -30, 119} }, - { { -12, 56} , { -6, 60} , { -5, 62} , { -8, 66} , { -8, 76} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -6, 55} , { 0, 58} , { 0, 64} , { -3, 74} , { -10, 90} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - }, - //----- model 1 ----- - { - { { -11, 77} , { -9, 80} , { -9, 84} , { -10, 87} , { -34, 127} }, - { { -15, 77} , { -17, 91} , { -25, 107} , { -25, 111} , { -28, 122} }, - { { -9, 57} , { -6, 63} , { -4, 65} , { -4, 67} , { -7, 82} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -16, 72} , { -7, 69} , { -4, 69} , { -5, 74} , { -9, 86} }, - { { -2, 55} , { -2, 67} , { 0, 73} , { -8, 89} , CTX_UNUSED }, - { { 3, 37} , { -1, 61} , { -5, 73} , { -1, 70} , { -4, 78} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -11, 77} , { -9, 80} , { -9, 84} , { -10, 87} , { -34, 127} }, - { { -15, 77} , { -17, 91} , { -25, 107} , { -25, 111} , { -28, 122} }, - { { -9, 57} , { -6, 63} , { -4, 65} , { -4, 67} , { -7, 82} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -16, 72} , { -7, 69} , { -4, 69} , { -5, 74} , { -9, 86} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cr in the 4:4:4 common mode - { { -11, 77} , { -9, 80} , { -9, 84} , { -10, 87} , { -34, 127} }, - { { -15, 77} , { -17, 91} , { -25, 107} , { -25, 111} , { -28, 122} }, - { { -9, 57} , { -6, 63} , { -4, 65} , { -4, 67} , { -7, 82} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -16, 72} , { -7, 69} , { -4, 69} , { -5, 74} , { -9, 86} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - }, - //----- model 2 ----- - { - { { -14, 85} , { -13, 89} , { -13, 94} , { -11, 92} , { -29, 127} }, - { { -21, 85} , { -16, 88} , { -23, 104} , { -15, 98} , { -37, 127} }, - { { -12, 59} , { -8, 63} , { -9, 67} , { -6, 68} , { -10, 79} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -14, 75} , { -10, 79} , { -9, 83} , { -12, 92} , { -18, 108} }, - { { -13, 78} , { -9, 83} , { -4, 81} , { -13, 99} , CTX_UNUSED }, - { { -16, 73} , { -10, 76} , { -13, 86} , { -9, 83} , { -10, 87} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cb in the 4:4:4 common mode - { { -14, 85} , { -13, 89} , { -13, 94} , { -11, 92} , { -29, 127} }, - { { -21, 85} , { -16, 88} , { -23, 104} , { -15, 98} , { -37, 127} }, - { { -12, 59} , { -8, 63} , { -9, 67} , { -6, 68} , { -10, 79} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -14, 75} , { -10, 79} , { -9, 83} , { -12, 92} , { -18, 108} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - //Cr in the 4:4:4 common mode - { { -14, 85} , { -13, 89} , { -13, 94} , { -11, 92} , { -29, 127} }, - { { -21, 85} , { -16, 88} , { -23, 104} , { -15, 98} , { -37, 127} }, - { { -12, 59} , { -8, 63} , { -9, 67} , { -6, 68} , { -10, 79} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -14, 75} , { -10, 79} , { -9, 83} , { -12, 92} , { -18, 108} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED } - } -}; +static const signed char INIT_ONE_P[3][22][5][2] = { + //----- model 0 ----- + {{{-6, 76}, {-2, 44}, {0, 45}, {0, 52}, {-3, 64}}, + {{-9, 77}, {3, 24}, {0, 42}, {0, 48}, {0, 55}}, + {{-6, 66}, {-7, 35}, {-7, 42}, {-8, 45}, {-5, 48}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{1, 58}, {-3, 29}, {-1, 36}, {1, 38}, {2, 43}}, + {{0, 70}, {-4, 29}, {5, 31}, {7, 42}, {1, 59}}, + {{0, 58}, {8, 5}, {10, 14}, {14, 18}, {13, 27}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-6, 76}, {-2, 44}, {0, 45}, {0, 52}, {-3, 64}}, + {{-9, 77}, {3, 24}, {0, 42}, {0, 48}, {0, 55}}, + {{-6, 66}, {-7, 35}, {-7, 42}, {-8, 45}, {-5, 48}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{1, 58}, {-3, 29}, {-1, 36}, {1, 38}, {2, 43}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{-6, 76}, {-2, 44}, {0, 45}, {0, 52}, {-3, 64}}, + {{-9, 77}, {3, 24}, {0, 42}, {0, 48}, {0, 55}}, + {{-6, 66}, {-7, 35}, {-7, 42}, {-8, 45}, {-5, 48}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{1, 58}, {-3, 29}, {-1, 36}, {1, 38}, {2, 43}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}, + //----- model 1 ----- + {{{-23, 112}, {-15, 71}, {-7, 61}, {0, 53}, {-5, 66}}, + {{-21, 101}, {-3, 39}, {-5, 53}, {-7, 61}, {-11, 75}}, + {{-5, 71}, {0, 24}, {-1, 36}, {-2, 42}, {-2, 52}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-11, 76}, {-10, 44}, {-10, 52}, {-10, 57}, {-9, 58}}, + {{2, 66}, {-9, 34}, {1, 32}, {11, 31}, {5, 52}}, + {{3, 52}, {7, 4}, {10, 8}, {17, 8}, {16, 19}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-23, 112}, {-15, 71}, {-7, 61}, {0, 53}, {-5, 66}}, + {{-21, 101}, {-3, 39}, {-5, 53}, {-7, 61}, {-11, 75}}, + {{-5, 71}, {0, 24}, {-1, 36}, {-2, 42}, {-2, 52}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-11, 76}, {-10, 44}, {-10, 52}, {-10, 57}, {-9, 58}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{-23, 112}, {-15, 71}, {-7, 61}, {0, 53}, {-5, 66}}, + {{-21, 101}, {-3, 39}, {-5, 53}, {-7, 61}, {-11, 75}}, + {{-5, 71}, {0, 24}, {-1, 36}, {-2, 42}, {-2, 52}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-11, 76}, {-10, 44}, {-10, 52}, {-10, 57}, {-9, 58}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}, + //----- model 2 ----- + {{{-24, 115}, {-22, 82}, {-9, 62}, {0, 53}, {0, 59}}, + {{-21, 100}, {-14, 57}, {-12, 67}, {-11, 71}, {-10, 77}}, + {{-9, 71}, {-7, 37}, {-8, 44}, {-11, 49}, {-10, 56}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-10, 82}, {-8, 48}, {-8, 61}, {-8, 66}, {-7, 70}}, + {{-4, 79}, {-22, 69}, {-16, 75}, {-2, 58}, {1, 58}}, + {{-13, 81}, {-6, 38}, {-13, 62}, {-6, 58}, {-2, 59}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-24, 115}, {-22, 82}, {-9, 62}, {0, 53}, {0, 59}}, + {{-21, 100}, {-14, 57}, {-12, 67}, {-11, 71}, {-10, 77}}, + {{-9, 71}, {-7, 37}, {-8, 44}, {-11, 49}, {-10, 56}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-10, 82}, {-8, 48}, {-8, 61}, {-8, 66}, {-7, 70}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{-24, 115}, {-22, 82}, {-9, 62}, {0, 53}, {0, 59}}, + {{-21, 100}, {-14, 57}, {-12, 67}, {-11, 71}, {-10, 77}}, + {{-9, 71}, {-7, 37}, {-8, 44}, {-11, 49}, {-10, 56}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-10, 82}, {-8, 48}, {-8, 61}, {-8, 66}, {-7, 70}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; +static const signed char INIT_ABS_I[1][22][5][2] = { + //----- model 0 ----- + {{{0, 58}, {1, 63}, {-2, 72}, {-1, 74}, {-9, 91}}, + {{-16, 64}, {-8, 68}, {-10, 78}, {-6, 77}, {-10, 86}}, + {{-2, 55}, {0, 61}, {1, 64}, {0, 68}, {-9, 92}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-12, 73}, {-8, 76}, {-7, 80}, {-9, 88}, {-17, 110}}, + {{-13, 86}, {-13, 96}, {-11, 97}, {-19, 117}, CTX_UNUSED}, + {{-13, 71}, {-10, 79}, {-12, 86}, {-13, 90}, {-14, 97}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{0, 58}, {1, 63}, {-2, 72}, {-1, 74}, {-9, 91}}, + {{-16, 64}, {-8, 68}, {-10, 78}, {-6, 77}, {-10, 86}}, + {{-2, 55}, {0, 61}, {1, 64}, {0, 68}, {-9, 92}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-12, 73}, {-8, 76}, {-7, 80}, {-9, 88}, {-17, 110}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{0, 58}, {1, 63}, {-2, 72}, {-1, 74}, {-9, 91}}, + {{-16, 64}, {-8, 68}, {-10, 78}, {-6, 77}, {-10, 86}}, + {{-2, 55}, {0, 61}, {1, 64}, {0, 68}, {-9, 92}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-12, 73}, {-8, 76}, {-7, 80}, {-9, 88}, {-17, 110}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; +static const signed char INIT_ABS_P[3][22][5][2] = { + //----- model 0 ----- + { + {{-2, 59}, {-4, 70}, {-4, 75}, {-8, 82}, {-17, 102}}, + {{-6, 59}, {-7, 71}, {-12, 83}, {-11, 87}, {-30, 119}}, + {{-12, 56}, {-6, 60}, {-5, 62}, {-8, 66}, {-8, 76}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-6, 55}, {0, 58}, {0, 64}, {-3, 74}, {-10, 90}}, + {{-2, 58}, {-3, 72}, {-3, 81}, {-11, 97}, CTX_UNUSED}, + {{2, 40}, {0, 58}, {-3, 70}, {-6, 79}, {-8, 85}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-2, 59}, {-4, 70}, {-4, 75}, {-8, 82}, {-17, 102}}, + {{-6, 59}, {-7, 71}, {-12, 83}, {-11, 87}, {-30, 119}}, + {{-12, 56}, {-6, 60}, {-5, 62}, {-8, 66}, {-8, 76}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-6, 55}, {0, 58}, {0, 64}, {-3, 74}, {-10, 90}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{-2, 59}, {-4, 70}, {-4, 75}, {-8, 82}, {-17, 102}}, + {{-6, 59}, {-7, 71}, {-12, 83}, {-11, 87}, {-30, 119}}, + {{-12, 56}, {-6, 60}, {-5, 62}, {-8, 66}, {-8, 76}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-6, 55}, {0, 58}, {0, 64}, {-3, 74}, {-10, 90}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + }, + //----- model 1 ----- + { + {{-11, 77}, {-9, 80}, {-9, 84}, {-10, 87}, {-34, 127}}, + {{-15, 77}, {-17, 91}, {-25, 107}, {-25, 111}, {-28, 122}}, + {{-9, 57}, {-6, 63}, {-4, 65}, {-4, 67}, {-7, 82}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-16, 72}, {-7, 69}, {-4, 69}, {-5, 74}, {-9, 86}}, + {{-2, 55}, {-2, 67}, {0, 73}, {-8, 89}, CTX_UNUSED}, + {{3, 37}, {-1, 61}, {-5, 73}, {-1, 70}, {-4, 78}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-11, 77}, {-9, 80}, {-9, 84}, {-10, 87}, {-34, 127}}, + {{-15, 77}, {-17, 91}, {-25, 107}, {-25, 111}, {-28, 122}}, + {{-9, 57}, {-6, 63}, {-4, 65}, {-4, 67}, {-7, 82}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-16, 72}, {-7, 69}, {-4, 69}, {-5, 74}, {-9, 86}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{-11, 77}, {-9, 80}, {-9, 84}, {-10, 87}, {-34, 127}}, + {{-15, 77}, {-17, 91}, {-25, 107}, {-25, 111}, {-28, 122}}, + {{-9, 57}, {-6, 63}, {-4, 65}, {-4, 67}, {-7, 82}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-16, 72}, {-7, 69}, {-4, 69}, {-5, 74}, {-9, 86}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + }, + //----- model 2 ----- + {{{-14, 85}, {-13, 89}, {-13, 94}, {-11, 92}, {-29, 127}}, + {{-21, 85}, {-16, 88}, {-23, 104}, {-15, 98}, {-37, 127}}, + {{-12, 59}, {-8, 63}, {-9, 67}, {-6, 68}, {-10, 79}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-14, 75}, {-10, 79}, {-9, 83}, {-12, 92}, {-18, 108}}, + {{-13, 78}, {-9, 83}, {-4, 81}, {-13, 99}, CTX_UNUSED}, + {{-16, 73}, {-10, 76}, {-13, 86}, {-9, 83}, {-10, 87}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cb in the 4:4:4 common mode + {{-14, 85}, {-13, 89}, {-13, 94}, {-11, 92}, {-29, 127}}, + {{-21, 85}, {-16, 88}, {-23, 104}, {-15, 98}, {-37, 127}}, + {{-12, 59}, {-8, 63}, {-9, 67}, {-6, 68}, {-10, 79}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-14, 75}, {-10, 79}, {-9, 83}, {-12, 92}, {-18, 108}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + // Cr in the 4:4:4 common mode + {{-14, 85}, {-13, 89}, {-13, 94}, {-11, 92}, {-29, 127}}, + {{-21, 85}, {-16, 88}, {-23, 104}, {-15, 98}, {-37, 127}}, + {{-12, 59}, {-8, 63}, {-9, 67}, {-6, 68}, {-10, 79}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-14, 75}, {-10, 79}, {-9, 83}, {-12, 92}, {-18, 108}}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}}}; #if ENABLE_FIELD_CTX -static const signed char INIT_FLD_MAP_I[1][8][15][2] = -{ - //----- model 0 ----- - { - { { -6, 93} , { -6, 84} , { -8, 79} , { 0, 66} , { -1, 71} , { 0, 62} , { -2, 60} , { -2, 59} , { -5, 75} , { -3, 62} , { -4, 58} , { -9, 66} , { -1, 79} , { 0, 71} , { 3, 68} }, - { CTX_UNUSED , { 10, 44} , { -7, 62} , { 15, 36} , { 14, 40} , { 16, 27} , { 12, 29} , { 1, 44} , { 20, 36} , { 18, 32} , { 5, 42} , { 1, 48} , { 10, 62} , { 17, 46} , { 9, 64} }, - { { -14, 106} , { -13, 97} , { -15, 90} , { -12, 90} , { -18, 88} , { -10, 73} , { -9, 79} , { -14, 86} , { -10, 73} , { -10, 70} , { -10, 69} , { -5, 66} , { -9, 64} , { -5, 58} , { 2, 59} }, -// { { -1, 73} , { -7, 73} , { -6, 76} , { -7, 71} , { -9, 72} , { -5, 65} , { -14, 83} , { -8, 72} , { -10, 75} , { -5, 64} , { -4, 59} , { -13, 79} , { -9, 69} , { -8, 66} , { 3, 55} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -12, 104} , { -11, 97} , { -16, 96} , { -7, 88} , { -8, 85} , { -7, 85} , { -9, 85} , { -13, 88} , { 4, 66} , { -3, 77} , { -3, 76} , { -6, 76} , { 10, 58} , { -1, 76} , { -1, 83} }, - { { -7, 99} , { -14, 95} , { 2, 95} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 0, 76} , { -5, 74} , { 0, 70} , { -11, 75} , { 1, 68} , { 0, 65} , { -14, 73} , { 3, 62} , { 4, 62} , { -1, 68} , { -13, 75} , { 11, 55} , { 5, 64} , { 12, 70} } - } -}; +static const signed char INIT_FLD_MAP_I[1][8][15][2] = { + //----- model 0 ----- + {{{-6, 93}, + {-6, 84}, + {-8, 79}, + {0, 66}, + {-1, 71}, + {0, 62}, + {-2, 60}, + {-2, 59}, + {-5, 75}, + {-3, 62}, + {-4, 58}, + {-9, 66}, + {-1, 79}, + {0, 71}, + {3, 68}}, + {CTX_UNUSED, + {10, 44}, + {-7, 62}, + {15, 36}, + {14, 40}, + {16, 27}, + {12, 29}, + {1, 44}, + {20, 36}, + {18, 32}, + {5, 42}, + {1, 48}, + {10, 62}, + {17, 46}, + {9, 64}}, + {{-14, 106}, + {-13, 97}, + {-15, 90}, + {-12, 90}, + {-18, 88}, + {-10, 73}, + {-9, 79}, + {-14, 86}, + {-10, 73}, + {-10, 70}, + {-10, 69}, + {-5, 66}, + {-9, 64}, + {-5, 58}, + {2, 59}}, + // { { -1, 73} , { -7, 73} , { -6, 76} , { -7, 71} , { -9, 72} + // , { -5, 65} , { -14, 83} , { -8, 72} , { -10, 75} , { -5, 64} + // , { -4, 59} , { -13, 79} , { -9, 69} , { -8, 66} , { 3, 55} + // }, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-12, 104}, + {-11, 97}, + {-16, 96}, + {-7, 88}, + {-8, 85}, + {-7, 85}, + {-9, 85}, + {-13, 88}, + {4, 66}, + {-3, 77}, + {-3, 76}, + {-6, 76}, + {10, 58}, + {-1, 76}, + {-1, 83}}, + {{-7, 99}, + {-14, 95}, + {2, 95}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {0, 76}, + {-5, 74}, + {0, 70}, + {-11, 75}, + {1, 68}, + {0, 65}, + {-14, 73}, + {3, 62}, + {4, 62}, + {-1, 68}, + {-13, 75}, + {11, 55}, + {5, 64}, + {12, 70}}}}; -static const signed char INIT_FLD_MAP_P[3][8][15][2] = -{ - //----- model 0 ----- - { - { { -13, 106} , { -16, 106} , { -10, 87} , { -21, 114} , { -18, 110} , { -14, 98} , { -22, 110} , { -21, 106} , { -18, 103} , { -21, 107} , { -23, 108} , { -26, 112} , { -10, 96} , { -12, 95} , { -5, 91} }, - { CTX_UNUSED , { -9, 93} , { -22, 94} , { -5, 86} , { 9, 67} , { -4, 80} , { -10, 85} , { -1, 70} , { 7, 60} , { 9, 58} , { 5, 61} , { 12, 50} , { 15, 50} , { 18, 49} , { 17, 54} }, - { { -5, 85} , { -6, 81} , { -10, 77} , { -7, 81} , { -17, 80} , { -18, 73} , { -4, 74} , { -10, 83} , { -9, 71} , { -9, 67} , { -1, 61} , { -8, 66} , { -14, 66} , { 0, 59} , { 2, 59} }, -// { { -4, 60} , { -3, 49} , { -2, 50} , { -4, 49} , { -5, 48} , { -2, 46} , { -7, 54} , { -1, 45} , { -4, 49} , { 4, 39} , { 0, 42} , { 2, 43} , { 0, 44} , { 5, 32} , { 15, 30} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 10, 41} , { 7, 46} , { -1, 51} , { 7, 49} , { 8, 52} , { 9, 41} , { 6, 47} , { 2, 55} , { 13, 41} , { 10, 44} , { 6, 50} , { 5, 53} , { 13, 49} , { 4, 63} , { 6, 64} }, - { { -2, 69} , { -2, 59} , { 6, 70} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 10, 44} , { 9, 31} , { 12, 43} , { 3, 53} , { 14, 34} , { 10, 38} , { -3, 52} , { 13, 40} , { 17, 32} , { 7, 44} , { 7, 38} , { 13, 50} , { 10, 57} , { 26, 43} } - }, - //----- model 1 ----- - { - { { -21, 126} , { -23, 124} , { -20, 110} , { -26, 126} , { -25, 124} , { -17, 105} , { -27, 121} , { -27, 117} , { -17, 102} , { -26, 117} , { -27, 116} , { -33, 122} , { -10, 95} , { -14, 100} , { -8, 95} }, - { CTX_UNUSED , { -17, 111} , { -28, 114} , { -6, 89} , { -2, 80} , { -4, 82} , { -9, 85} , { -8, 81} , { -1, 72} , { 5, 64} , { 1, 67} , { 9, 56} , { 0, 69} , { 1, 69} , { 7, 69} }, - { { -3, 81} , { -3, 76} , { -7, 72} , { -6, 78} , { -12, 72} , { -14, 68} , { -3, 70} , { -6, 76} , { -5, 66} , { -5, 62} , { 0, 57} , { -4, 61} , { -9, 60} , { 1, 54} , { 2, 58} }, -// { { -4, 60} , { -3, 49} , { -2, 50} , { -4, 49} , { -5, 48} , { -2, 46} , { -7, 54} , { -1, 45} , { -4, 49} , { 4, 39} , { 0, 42} , { 2, 43} , { 0, 44} , { 5, 32} , { 15, 30} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { -7, 69} , { -6, 67} , { -16, 77} , { -2, 64} , { 2, 61} , { -6, 67} , { -3, 64} , { 2, 57} , { -3, 65} , { -3, 66} , { 0, 62} , { 9, 51} , { -1, 66} , { -2, 71} , { -2, 75} }, - { { -1, 70} , { -9, 72} , { 14, 60} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 16, 37} , { 0, 47} , { 18, 35} , { 11, 37} , { 12, 41} , { 10, 41} , { 2, 48} , { 12, 41} , { 13, 41} , { 0, 59} , { 3, 50} , { 19, 40} , { 3, 66} , { 18, 50} } - }, - //----- model 2 ----- - { - { { -22, 127} , { -25, 127} , { -25, 120} , { -27, 127} , { -19, 114} , { -23, 117} , { -25, 118} , { -26, 117} , { -24, 113} , { -28, 118} , { -31, 120} , { -37, 124} , { -10, 94} , { -15, 102} , { -10, 99} }, - { CTX_UNUSED , { -13, 106} , { -50, 127} , { -5, 92} , { 17, 57} , { -5, 86} , { -13, 94} , { -12, 91} , { -2, 77} , { 0, 71} , { -1, 73} , { 4, 64} , { -7, 81} , { 5, 64} , { 15, 57} }, - { { -3, 78} , { -8, 74} , { -9, 72} , { -10, 72} , { -18, 75} , { -12, 71} , { -11, 63} , { -5, 70} , { -17, 75} , { -14, 72} , { -16, 67} , { -8, 53} , { -14, 59} , { -9, 52} , { -11, 68} }, -// { { -4, 60} , { -3, 49} , { -2, 50} , { -4, 49} , { -5, 48} , { -2, 46} , { -7, 54} , { -1, 45} , { -4, 49} , { 4, 39} , { 0, 42} , { 2, 43} , { 0, 44} , { 5, 32} , { 15, 30} }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 1, 67} , { 0, 68} , { -10, 67} , { 1, 68} , { 0, 77} , { 2, 64} , { 0, 68} , { -5, 78} , { 7, 55} , { 5, 59} , { 2, 65} , { 14, 54} , { 15, 44} , { 5, 60} , { 2, 70} }, - { { -2, 76} , { -18, 86} , { 12, 70} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 5, 64} , { -12, 70} , { 11, 55} , { 5, 56} , { 0, 69} , { 2, 65} , { -6, 74} , { 5, 54} , { 7, 54} , { -6, 76} , { -11, 82} , { -2, 77} , { -2, 77} , { 25, 42} } - } -}; +static const signed char INIT_FLD_MAP_P[3][8][15][2] = { + //----- model 0 ----- + {{{-13, 106}, + {-16, 106}, + {-10, 87}, + {-21, 114}, + {-18, 110}, + {-14, 98}, + {-22, 110}, + {-21, 106}, + {-18, 103}, + {-21, 107}, + {-23, 108}, + {-26, 112}, + {-10, 96}, + {-12, 95}, + {-5, 91}}, + {CTX_UNUSED, + {-9, 93}, + {-22, 94}, + {-5, 86}, + {9, 67}, + {-4, 80}, + {-10, 85}, + {-1, 70}, + {7, 60}, + {9, 58}, + {5, 61}, + {12, 50}, + {15, 50}, + {18, 49}, + {17, 54}}, + {{-5, 85}, + {-6, 81}, + {-10, 77}, + {-7, 81}, + {-17, 80}, + {-18, 73}, + {-4, 74}, + {-10, 83}, + {-9, 71}, + {-9, 67}, + {-1, 61}, + {-8, 66}, + {-14, 66}, + {0, 59}, + {2, 59}}, + // { { -4, 60} , { -3, 49} , { -2, 50} , { -4, 49} , { -5, 48} + // , { -2, 46} , { -7, 54} , { -1, 45} , { -4, 49} , { 4, 39} + // , { 0, 42} , { 2, 43} , { 0, 44} , { 5, 32} , { 15, 30} + // }, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{10, 41}, + {7, 46}, + {-1, 51}, + {7, 49}, + {8, 52}, + {9, 41}, + {6, 47}, + {2, 55}, + {13, 41}, + {10, 44}, + {6, 50}, + {5, 53}, + {13, 49}, + {4, 63}, + {6, 64}}, + {{-2, 69}, + {-2, 59}, + {6, 70}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {10, 44}, + {9, 31}, + {12, 43}, + {3, 53}, + {14, 34}, + {10, 38}, + {-3, 52}, + {13, 40}, + {17, 32}, + {7, 44}, + {7, 38}, + {13, 50}, + {10, 57}, + {26, 43}}}, + //----- model 1 ----- + {{{-21, 126}, + {-23, 124}, + {-20, 110}, + {-26, 126}, + {-25, 124}, + {-17, 105}, + {-27, 121}, + {-27, 117}, + {-17, 102}, + {-26, 117}, + {-27, 116}, + {-33, 122}, + {-10, 95}, + {-14, 100}, + {-8, 95}}, + {CTX_UNUSED, + {-17, 111}, + {-28, 114}, + {-6, 89}, + {-2, 80}, + {-4, 82}, + {-9, 85}, + {-8, 81}, + {-1, 72}, + {5, 64}, + {1, 67}, + {9, 56}, + {0, 69}, + {1, 69}, + {7, 69}}, + {{-3, 81}, + {-3, 76}, + {-7, 72}, + {-6, 78}, + {-12, 72}, + {-14, 68}, + {-3, 70}, + {-6, 76}, + {-5, 66}, + {-5, 62}, + {0, 57}, + {-4, 61}, + {-9, 60}, + {1, 54}, + {2, 58}}, + // { { -4, 60} , { -3, 49} , { -2, 50} , { -4, 49} , { -5, 48} + // , { -2, 46} , { -7, 54} , { -1, 45} , { -4, 49} , { 4, 39} + // , { 0, 42} , { 2, 43} , { 0, 44} , { 5, 32} , { 15, 30} + // }, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{-7, 69}, + {-6, 67}, + {-16, 77}, + {-2, 64}, + {2, 61}, + {-6, 67}, + {-3, 64}, + {2, 57}, + {-3, 65}, + {-3, 66}, + {0, 62}, + {9, 51}, + {-1, 66}, + {-2, 71}, + {-2, 75}}, + {{-1, 70}, + {-9, 72}, + {14, 60}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {16, 37}, + {0, 47}, + {18, 35}, + {11, 37}, + {12, 41}, + {10, 41}, + {2, 48}, + {12, 41}, + {13, 41}, + {0, 59}, + {3, 50}, + {19, 40}, + {3, 66}, + {18, 50}}}, + //----- model 2 ----- + {{{-22, 127}, + {-25, 127}, + {-25, 120}, + {-27, 127}, + {-19, 114}, + {-23, 117}, + {-25, 118}, + {-26, 117}, + {-24, 113}, + {-28, 118}, + {-31, 120}, + {-37, 124}, + {-10, 94}, + {-15, 102}, + {-10, 99}}, + {CTX_UNUSED, + {-13, 106}, + {-50, 127}, + {-5, 92}, + {17, 57}, + {-5, 86}, + {-13, 94}, + {-12, 91}, + {-2, 77}, + {0, 71}, + {-1, 73}, + {4, 64}, + {-7, 81}, + {5, 64}, + {15, 57}}, + {{-3, 78}, + {-8, 74}, + {-9, 72}, + {-10, 72}, + {-18, 75}, + {-12, 71}, + {-11, 63}, + {-5, 70}, + {-17, 75}, + {-14, 72}, + {-16, 67}, + {-8, 53}, + {-14, 59}, + {-9, 52}, + {-11, 68}}, + // { { -4, 60} , { -3, 49} , { -2, 50} , { -4, 49} , { -5, 48} + // , { -2, 46} , { -7, 54} , { -1, 45} , { -4, 49} , { 4, 39} + // , { 0, 42} , { 2, 43} , { 0, 44} , { 5, 32} , { 15, 30} + // }, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{1, 67}, + {0, 68}, + {-10, 67}, + {1, 68}, + {0, 77}, + {2, 64}, + {0, 68}, + {-5, 78}, + {7, 55}, + {5, 59}, + {2, 65}, + {14, 54}, + {15, 44}, + {5, 60}, + {2, 70}}, + {{-2, 76}, + {-18, 86}, + {12, 70}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {5, 64}, + {-12, 70}, + {11, 55}, + {5, 56}, + {0, 69}, + {2, 65}, + {-6, 74}, + {5, 54}, + {7, 54}, + {-6, 76}, + {-11, 82}, + {-2, 77}, + {-2, 77}, + {25, 42}}}}; -static const signed char INIT_FLD_LAST_I[1][8][15][2] = -{ - //----- model 0 ----- - { - { { 15, 6} , { 6, 19} , { 7, 16} , { 12, 14} , { 18, 13} , { 13, 11} , { 13, 15} , { 15, 16} , { 12, 23} , { 13, 23} , { 15, 20} , { 14, 26} , { 14, 44} , { 17, 40} , { 17, 47} }, - { CTX_UNUSED , { 24, 17} , { 21, 21} , { 25, 22} , { 31, 27} , { 22, 29} , { 19, 35} , { 14, 50} , { 10, 57} , { 7, 63} , { -2, 77} , { -4, 82} , { -3, 94} , { 9, 69} , { -12, 109} }, - { { 21, -10} , { 24, -11} , { 28, -8} , { 28, -1} , { 29, 3} , { 29, 9} , { 35, 20} , { 29, 36} , { 14, 67} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, -// { { 12, 33} , { 5, 38} , { 9, 34} , { 18, 22} , { 19, 22} , { 23, 19} , { 26, 16} , { 14, 44} , { 40, 14} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 36, -35} , { 36, -34} , { 32, -26} , { 37, -30} , { 44, -32} , { 34, -18} , { 34, -15} , { 40, -15} , { 33, -7} , { 35, -5} , { 33, 0} , { 38, 2} , { 33, 13} , { 23, 35} , { 13, 58} }, - { { 29, -3} , { 26, 0} , { 22, 30} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 31, -7} , { 35, -15} , { 34, -3} , { 34, 3} , { 36, -1} , { 34, 5} , { 32, 11} , { 35, 5} , { 34, 12} , { 39, 11} , { 30, 29} , { 34, 26} , { 29, 39} , { 19, 66} } - } -}; +static const signed char INIT_FLD_LAST_I[1][8][15][2] = { + //----- model 0 ----- + {{{15, 6}, + {6, 19}, + {7, 16}, + {12, 14}, + {18, 13}, + {13, 11}, + {13, 15}, + {15, 16}, + {12, 23}, + {13, 23}, + {15, 20}, + {14, 26}, + {14, 44}, + {17, 40}, + {17, 47}}, + {CTX_UNUSED, + {24, 17}, + {21, 21}, + {25, 22}, + {31, 27}, + {22, 29}, + {19, 35}, + {14, 50}, + {10, 57}, + {7, 63}, + {-2, 77}, + {-4, 82}, + {-3, 94}, + {9, 69}, + {-12, 109}}, + {{21, -10}, + {24, -11}, + {28, -8}, + {28, -1}, + {29, 3}, + {29, 9}, + {35, 20}, + {29, 36}, + {14, 67}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + // { { 12, 33} , { 5, 38} , { 9, 34} , { 18, 22} , { 19, 22} + // , { 23, 19} , { 26, 16} , { 14, 44} , { 40, 14} , CTX_UNUSED + // , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED + // }, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{36, -35}, + {36, -34}, + {32, -26}, + {37, -30}, + {44, -32}, + {34, -18}, + {34, -15}, + {40, -15}, + {33, -7}, + {35, -5}, + {33, 0}, + {38, 2}, + {33, 13}, + {23, 35}, + {13, 58}}, + {{29, -3}, + {26, 0}, + {22, 30}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {31, -7}, + {35, -15}, + {34, -3}, + {34, 3}, + {36, -1}, + {34, 5}, + {32, 11}, + {35, 5}, + {34, 12}, + {39, 11}, + {30, 29}, + {34, 26}, + {29, 39}, + {19, 66}}}}; -static const signed char INIT_FLD_LAST_P[3][8][15][2] = -{ - //----- model 0 ----- - { - { { 14, 11} , { 11, 14} , { 9, 11} , { 18, 11} , { 21, 9} , { 23, -2} , { 32, -15} , { 32, -15} , { 34, -21} , { 39, -23} , { 42, -33} , { 41, -31} , { 46, -28} , { 38, -12} , { 21, 29} }, - { CTX_UNUSED , { 45, -24} , { 53, -45} , { 48, -26} , { 65, -43} , { 43, -19} , { 39, -10} , { 30, 9} , { 18, 26} , { 20, 27} , { 0, 57} , { -14, 82} , { -5, 75} , { -19, 97} , { -35, 125} }, - { { 21, -13} , { 33, -14} , { 39, -7} , { 46, -2} , { 51, 2} , { 60, 6} , { 61, 17} , { 55, 34} , { 42, 62} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, -// { { 17, 27} , { 23, 13} , { 24, 16} , { 22, 25} , { 23, 27} , { 23, 32} , { 17, 43} , { 17, 49} , { 2, 70} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 27, 0} , { 28, 0} , { 31, -4} , { 27, 6} , { 34, 8} , { 30, 10} , { 24, 22} , { 33, 19} , { 22, 32} , { 26, 31} , { 21, 41} , { 26, 44} , { 23, 47} , { 16, 65} , { 14, 71} }, - { { 8, 60} , { 6, 63} , { 17, 65} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 21, 24} , { 23, 20} , { 26, 23} , { 27, 32} , { 28, 23} , { 28, 24} , { 23, 40} , { 24, 32} , { 28, 29} , { 23, 42} , { 19, 57} , { 22, 53} , { 22, 61} , { 11, 86} } - }, - //----- model 1 ----- - { - { { 19, -6} , { 18, -6} , { 14, 0} , { 26, -12} , { 31, -16} , { 33, -25} , { 33, -22} , { 37, -28} , { 39, -30} , { 42, -30} , { 47, -42} , { 45, -36} , { 49, -34} , { 41, -17} , { 32, 9} }, - { CTX_UNUSED , { 69, -71} , { 63, -63} , { 66, -64} , { 77, -74} , { 54, -39} , { 52, -35} , { 41, -10} , { 36, 0} , { 40, -1} , { 30, 14} , { 28, 26} , { 23, 37} , { 12, 55} , { 11, 65} }, - { { 17, -10} , { 32, -13} , { 42, -9} , { 49, -5} , { 53, 0} , { 64, 3} , { 68, 10} , { 66, 27} , { 47, 57} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, -// { { 17, 27} , { 23, 13} , { 24, 16} , { 22, 25} , { 23, 27} , { 23, 32} , { 17, 43} , { 17, 49} , { 2, 70} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 37, -33} , { 39, -36} , { 40, -37} , { 38, -30} , { 46, -33} , { 42, -30} , { 40, -24} , { 49, -29} , { 38, -12} , { 40, -10} , { 38, -3} , { 46, -5} , { 31, 20} , { 29, 30} , { 25, 44} }, - { { 12, 48} , { 11, 49} , { 26, 45} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 22, 22} , { 23, 22} , { 27, 21} , { 33, 20} , { 26, 28} , { 30, 24} , { 27, 34} , { 18, 42} , { 25, 39} , { 18, 50} , { 12, 70} , { 21, 54} , { 14, 71} , { 11, 83} } - }, - //----- model 2 ----- - { - { { 17, -13} , { 16, -9} , { 17, -12} , { 27, -21} , { 37, -30} , { 41, -40} , { 42, -41} , { 48, -47} , { 39, -32} , { 46, -40} , { 52, -51} , { 46, -41} , { 52, -39} , { 43, -19} , { 32, 11} }, - { CTX_UNUSED , { 61, -55} , { 56, -46} , { 62, -50} , { 81, -67} , { 45, -20} , { 35, -2} , { 28, 15} , { 34, 1} , { 39, 1} , { 30, 17} , { 20, 38} , { 18, 45} , { 15, 54} , { 0, 79} }, - { { 9, -2} , { 30, -10} , { 31, -4} , { 33, -1} , { 33, 7} , { 31, 12} , { 37, 23} , { 31, 38} , { 20, 64} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, -// { { 17, 27} , { 23, 13} , { 24, 16} , { 22, 25} , { 23, 27} , { 23, 32} , { 17, 43} , { 17, 49} , { 2, 70} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { { 36, -16} , { 37, -14} , { 37, -17} , { 32, 1} , { 34, 15} , { 29, 15} , { 24, 25} , { 34, 22} , { 31, 16} , { 35, 18} , { 31, 28} , { 33, 41} , { 36, 28} , { 27, 47} , { 21, 62} }, - { { 18, 31} , { 19, 26} , { 36, 24} , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED }, - { CTX_UNUSED , { 24, 23} , { 27, 16} , { 24, 30} , { 31, 29} , { 22, 41} , { 22, 42} , { 16, 60} , { 15, 52} , { 14, 60} , { 3, 78} , { -16, 123} , { 21, 53} , { 22, 56} , { 25, 61} } - } -}; +static const signed char INIT_FLD_LAST_P[3][8][15][2] = { + //----- model 0 ----- + {{{14, 11}, + {11, 14}, + {9, 11}, + {18, 11}, + {21, 9}, + {23, -2}, + {32, -15}, + {32, -15}, + {34, -21}, + {39, -23}, + {42, -33}, + {41, -31}, + {46, -28}, + {38, -12}, + {21, 29}}, + {CTX_UNUSED, + {45, -24}, + {53, -45}, + {48, -26}, + {65, -43}, + {43, -19}, + {39, -10}, + {30, 9}, + {18, 26}, + {20, 27}, + {0, 57}, + {-14, 82}, + {-5, 75}, + {-19, 97}, + {-35, 125}}, + {{21, -13}, + {33, -14}, + {39, -7}, + {46, -2}, + {51, 2}, + {60, 6}, + {61, 17}, + {55, 34}, + {42, 62}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + // { { 17, 27} , { 23, 13} , { 24, 16} , { 22, 25} , { 23, 27} + // , { 23, 32} , { 17, 43} , { 17, 49} , { 2, 70} , CTX_UNUSED + // , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED + // }, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{27, 0}, + {28, 0}, + {31, -4}, + {27, 6}, + {34, 8}, + {30, 10}, + {24, 22}, + {33, 19}, + {22, 32}, + {26, 31}, + {21, 41}, + {26, 44}, + {23, 47}, + {16, 65}, + {14, 71}}, + {{8, 60}, + {6, 63}, + {17, 65}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {21, 24}, + {23, 20}, + {26, 23}, + {27, 32}, + {28, 23}, + {28, 24}, + {23, 40}, + {24, 32}, + {28, 29}, + {23, 42}, + {19, 57}, + {22, 53}, + {22, 61}, + {11, 86}}}, + //----- model 1 ----- + {{{19, -6}, + {18, -6}, + {14, 0}, + {26, -12}, + {31, -16}, + {33, -25}, + {33, -22}, + {37, -28}, + {39, -30}, + {42, -30}, + {47, -42}, + {45, -36}, + {49, -34}, + {41, -17}, + {32, 9}}, + {CTX_UNUSED, + {69, -71}, + {63, -63}, + {66, -64}, + {77, -74}, + {54, -39}, + {52, -35}, + {41, -10}, + {36, 0}, + {40, -1}, + {30, 14}, + {28, 26}, + {23, 37}, + {12, 55}, + {11, 65}}, + {{17, -10}, + {32, -13}, + {42, -9}, + {49, -5}, + {53, 0}, + {64, 3}, + {68, 10}, + {66, 27}, + {47, 57}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + // { { 17, 27} , { 23, 13} , { 24, 16} , { 22, 25} , { 23, 27} + // , { 23, 32} , { 17, 43} , { 17, 49} , { 2, 70} , CTX_UNUSED + // , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED + // }, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{37, -33}, + {39, -36}, + {40, -37}, + {38, -30}, + {46, -33}, + {42, -30}, + {40, -24}, + {49, -29}, + {38, -12}, + {40, -10}, + {38, -3}, + {46, -5}, + {31, 20}, + {29, 30}, + {25, 44}}, + {{12, 48}, + {11, 49}, + {26, 45}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {22, 22}, + {23, 22}, + {27, 21}, + {33, 20}, + {26, 28}, + {30, 24}, + {27, 34}, + {18, 42}, + {25, 39}, + {18, 50}, + {12, 70}, + {21, 54}, + {14, 71}, + {11, 83}}}, + //----- model 2 ----- + {{{17, -13}, + {16, -9}, + {17, -12}, + {27, -21}, + {37, -30}, + {41, -40}, + {42, -41}, + {48, -47}, + {39, -32}, + {46, -40}, + {52, -51}, + {46, -41}, + {52, -39}, + {43, -19}, + {32, 11}}, + {CTX_UNUSED, + {61, -55}, + {56, -46}, + {62, -50}, + {81, -67}, + {45, -20}, + {35, -2}, + {28, 15}, + {34, 1}, + {39, 1}, + {30, 17}, + {20, 38}, + {18, 45}, + {15, 54}, + {0, 79}}, + {{9, -2}, + {30, -10}, + {31, -4}, + {33, -1}, + {33, 7}, + {31, 12}, + {37, 23}, + {31, 38}, + {20, 64}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + // { { 17, 27} , { 23, 13} , { 24, 16} , { 22, 25} , { 23, 27} + // , { 23, 32} , { 17, 43} , { 17, 49} , { 2, 70} , CTX_UNUSED + // , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED , CTX_UNUSED + // }, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, CTX_UNUSED, + CTX_UNUSED, CTX_UNUSED, CTX_UNUSED}, + {{36, -16}, + {37, -14}, + {37, -17}, + {32, 1}, + {34, 15}, + {29, 15}, + {24, 25}, + {34, 22}, + {31, 16}, + {35, 18}, + {31, 28}, + {33, 41}, + {36, 28}, + {27, 47}, + {21, 62}}, + {{18, 31}, + {19, 26}, + {36, 24}, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED, + CTX_UNUSED}, + {CTX_UNUSED, + {24, 23}, + {27, 16}, + {24, 30}, + {31, 29}, + {22, 41}, + {22, 42}, + {16, 60}, + {15, 52}, + {14, 60}, + {3, 78}, + {-16, 123}, + {21, 53}, + {22, 56}, + {25, 61}}}}; #endif - #endif - diff --git a/src/common/ldecod_src/inc/defines.h b/src/common/ldecod_src/inc/defines.h index bedf436..a0ea54d 100644 --- a/src/common/ldecod_src/inc/defines.h +++ b/src/common/ldecod_src/inc/defines.h @@ -7,259 +7,272 @@ * Header file containing some useful global definitions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Detlev Marpe - * - Karsten Shring - * - Alexis Michael Tourapis - * + * - Karsten Shring + * - Alexis Michael Tourapis + * * * \date * 21. March 2001 ************************************************************************** */ - #ifndef _DEFINES_H_ #define _DEFINES_H_ #ifdef TRACE #undef TRACE #endif #if defined _DEBUG -# define TRACE 0 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information +#define TRACE 0 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information #else -# define TRACE 0 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information +#define TRACE 0 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information #endif -#define JM "17 (FRExt)" -#define VERSION "17.1" -#define EXT_VERSION "(FRExt)" +#define JM "17 (FRExt)" +#define VERSION "17.1" +#define EXT_VERSION "(FRExt)" -#define DUMP_DPB 0 //!< Dump DPB info for debug purposes -#define PRINTREFLIST 0 //!< Print ref list info for debug purposes -#define PAIR_FIELDS_IN_OUTPUT 0 //!< Pair field pictures for output purposes -#define IMGTYPE 1 //!< Define imgpel size type. 0 implies byte (cannot handle >8 bit depths) and 1 implies unsigned short -#define ENABLE_FIELD_CTX 1 //!< Enables Field mode related context types for CABAC -#define ENABLE_HIGH444_CTX 1 //!< Enables High 444 profile context types for CABAC. -#define ZEROSNR 0 //!< PSNR computation method -#define ENABLE_OUTPUT_TONEMAPPING 1 //!< enable tone map the output if tone mapping SEI present -#define JCOST_CALC_SCALEUP 1 //!< 1: J = (D<>LAMBDA_ACCURACY_BITS) -#define DISABLE_ERC 1 //!< Disable any error concealment processes -#define JM_PARALLEL_DEBLOCK 0 //!< Enables Parallel Deblocking +#define DUMP_DPB 0 //!< Dump DPB info for debug purposes +#define PRINTREFLIST 0 //!< Print ref list info for debug purposes +#define PAIR_FIELDS_IN_OUTPUT 0 //!< Pair field pictures for output purposes +#define IMGTYPE \ + 1 //!< Define imgpel size type. 0 implies byte (cannot handle >8 bit depths) + //!< and 1 implies unsigned short +#define ENABLE_FIELD_CTX \ + 1 //!< Enables Field mode related context types for CABAC +#define ENABLE_HIGH444_CTX \ + 1 //!< Enables High 444 profile context types for CABAC. +#define ZEROSNR 0 //!< PSNR computation method +#define ENABLE_OUTPUT_TONEMAPPING \ + 1 //!< enable tone map the output if tone mapping SEI present +#define JCOST_CALC_SCALEUP \ + 1 //!< 1: J = (D<>LAMBDA_ACCURACY_BITS) +#define DISABLE_ERC 1 //!< Disable any error concealment processes +#define JM_PARALLEL_DEBLOCK 0 //!< Enables Parallel Deblocking -#define MVC_EXTENSION_ENABLE 1 //!< enable support for the Multiview High Profile +#define MVC_EXTENSION_ENABLE \ + 1 //!< enable support for the Multiview High Profile #if (MVC_EXTENSION_ENABLE) -#define MVC_INIT_VIEW_ID -1 -#define MAX_VIEW_NUM 1024 -#define BASE_VIEW_IDX 0 -#define FREEPTR(ptr) { if(ptr) {free(ptr); (ptr)=NULL;} } +#define MVC_INIT_VIEW_ID -1 +#define MAX_VIEW_NUM 1024 +#define BASE_VIEW_IDX 0 +#define FREEPTR(ptr) \ + { \ + if (ptr) { \ + free(ptr); \ + (ptr) = NULL; \ + } \ + } #endif #include "typedefs.h" -#define SSE_MEMORY_ALIGNMENT 16 +#define SSE_MEMORY_ALIGNMENT 16 -//#define MAX_NUM_SLICES 150 -#define MAX_NUM_SLICES 50 -#define MAX_REFERENCE_PICTURES 32 //!< H.264 allows 32 fields -#define MAX_CODED_FRAME_SIZE 8000000 //!< bytes for one frame -#define MAX_NUM_DECSLICES 16 -#define MAX_DEC_THREADS 16 //16 core deocoding; -#define MCBUF_LUMA_PAD_X 32 -#define MCBUF_LUMA_PAD_Y 12 -#define MCBUF_CHROMA_PAD_X 16 -#define MCBUF_CHROMA_PAD_Y 8 +// #define MAX_NUM_SLICES 150 +#define MAX_NUM_SLICES 50 +#define MAX_REFERENCE_PICTURES 32 //!< H.264 allows 32 fields +#define MAX_CODED_FRAME_SIZE 8000000 //!< bytes for one frame +#define MAX_NUM_DECSLICES 16 +#define MAX_DEC_THREADS 16 // 16 core deocoding; +#define MCBUF_LUMA_PAD_X 32 +#define MCBUF_LUMA_PAD_Y 12 +#define MCBUF_CHROMA_PAD_X 16 +#define MCBUF_CHROMA_PAD_Y 8 -//AVC Profile IDC definitions +// AVC Profile IDC definitions typedef enum { - FREXT_CAVLC444 = 44, //!< YUV 4:4:4/14 "CAVLC 4:4:4" - BASELINE = 66, //!< YUV 4:2:0/8 "Baseline" - MAIN = 77, //!< YUV 4:2:0/8 "Main" - EXTENDED = 88, //!< YUV 4:2:0/8 "Extended" - FREXT_HP = 100, //!< YUV 4:2:0/8 "High" - FREXT_Hi10P = 110, //!< YUV 4:2:0/10 "High 10" - FREXT_Hi422 = 122, //!< YUV 4:2:2/10 "High 4:2:2" - FREXT_Hi444 = 244, //!< YUV 4:4:4/14 "High 4:4:4" - MVC_HIGH = 118, //!< YUV 4:2:0/8 "Multiview High" - STEREO_HIGH = 128 //!< YUV 4:2:0/8 "Stereo High" + FREXT_CAVLC444 = 44, //!< YUV 4:4:4/14 "CAVLC 4:4:4" + BASELINE = 66, //!< YUV 4:2:0/8 "Baseline" + MAIN = 77, //!< YUV 4:2:0/8 "Main" + EXTENDED = 88, //!< YUV 4:2:0/8 "Extended" + FREXT_HP = 100, //!< YUV 4:2:0/8 "High" + FREXT_Hi10P = 110, //!< YUV 4:2:0/10 "High 10" + FREXT_Hi422 = 122, //!< YUV 4:2:2/10 "High 4:2:2" + FREXT_Hi444 = 244, //!< YUV 4:4:4/14 "High 4:4:4" + MVC_HIGH = 118, //!< YUV 4:2:0/8 "Multiview High" + STEREO_HIGH = 128 //!< YUV 4:2:0/8 "Stereo High" } ProfileIDC; -#define FILE_NAME_SIZE 255 +#define FILE_NAME_SIZE 255 #define INPUT_TEXT_SIZE 1024 #if (ENABLE_HIGH444_CTX == 1) -# define NUM_BLOCK_TYPES 22 +#define NUM_BLOCK_TYPES 22 #else -# define NUM_BLOCK_TYPES 10 +#define NUM_BLOCK_TYPES 10 #endif +// #define _LEAKYBUCKET_ -//#define _LEAKYBUCKET_ - -#define BLOCK_SHIFT 2 -#define BLOCK_SIZE 4 -#define BLOCK_SIZE_8x8 8 -#define SMB_BLOCK_SIZE 8 -#define BLOCK_PIXELS 16 -#define MB_BLOCK_SIZE 16 -#define MB_PIXELS 256 // MB_BLOCK_SIZE * MB_BLOCK_SIZE -#define MB_PIXELS_SHIFT 8 // log2(MB_BLOCK_SIZE * MB_BLOCK_SIZE) -#define MB_BLOCK_SHIFT 4 -#define BLOCK_MULTIPLE 4 // (MB_BLOCK_SIZE/BLOCK_SIZE) -#define MB_BLOCK_PARTITIONS 16 // (BLOCK_MULTIPLE * BLOCK_MULTIPLE) -#define BLOCK_CONTEXT 64 // (4 * MB_BLOCK_PARTITIONS) +#define BLOCK_SHIFT 2 +#define BLOCK_SIZE 4 +#define BLOCK_SIZE_8x8 8 +#define SMB_BLOCK_SIZE 8 +#define BLOCK_PIXELS 16 +#define MB_BLOCK_SIZE 16 +#define MB_PIXELS 256 // MB_BLOCK_SIZE * MB_BLOCK_SIZE +#define MB_PIXELS_SHIFT 8 // log2(MB_BLOCK_SIZE * MB_BLOCK_SIZE) +#define MB_BLOCK_SHIFT 4 +#define BLOCK_MULTIPLE 4 // (MB_BLOCK_SIZE/BLOCK_SIZE) +#define MB_BLOCK_PARTITIONS 16 // (BLOCK_MULTIPLE * BLOCK_MULTIPLE) +#define BLOCK_CONTEXT 64 // (4 * MB_BLOCK_PARTITIONS) // These variables relate to the subpel accuracy supported by the software (1/4) -#define BLOCK_SIZE_SP 16 // BLOCK_SIZE << 2 -#define BLOCK_SIZE_8x8_SP 32 // BLOCK_SIZE8x8 << 2 +#define BLOCK_SIZE_SP 16 // BLOCK_SIZE << 2 +#define BLOCK_SIZE_8x8_SP 32 // BLOCK_SIZE8x8 << 2 // Available MB modes typedef enum { - PSKIP = 0, - BSKIP_DIRECT = 0, - P16x16 = 1, - P16x8 = 2, - P8x16 = 3, - SMB8x8 = 4, - SMB8x4 = 5, - SMB4x8 = 6, - SMB4x4 = 7, - P8x8 = 8, - I4MB = 9, - I16MB = 10, - IBLOCK = 11, - SI4MB = 12, - I8MB = 13, - IPCM = 14, - MAXMODE = 15 + PSKIP = 0, + BSKIP_DIRECT = 0, + P16x16 = 1, + P16x8 = 2, + P8x16 = 3, + SMB8x8 = 4, + SMB8x4 = 5, + SMB4x8 = 6, + SMB4x4 = 7, + P8x8 = 8, + I4MB = 9, + I16MB = 10, + IBLOCK = 11, + SI4MB = 12, + I8MB = 13, + IPCM = 14, + MAXMODE = 15 } MBModeTypes; // number of intra prediction modes -#define NO_INTRA_PMODE 9 +#define NO_INTRA_PMODE 9 // Direct Mode types typedef enum { DIR_TEMPORAL = 0, //!< Temporal Direct Mode - DIR_SPATIAL = 1 //!< Spatial Direct Mode + DIR_SPATIAL = 1 //!< Spatial Direct Mode } DirectModes; // CAVLC block types typedef enum { - LUMA = 0, - LUMA_INTRA16x16DC = 1, - LUMA_INTRA16x16AC = 2, - CB = 3, - CB_INTRA16x16DC = 4, - CB_INTRA16x16AC = 5, - CR = 8, - CR_INTRA16x16DC = 9, - CR_INTRA16x16AC = 10 + LUMA = 0, + LUMA_INTRA16x16DC = 1, + LUMA_INTRA16x16AC = 2, + CB = 3, + CB_INTRA16x16DC = 4, + CB_INTRA16x16AC = 5, + CR = 8, + CR_INTRA16x16DC = 9, + CR_INTRA16x16AC = 10 } CAVLCBlockTypes; // CABAC block types typedef enum { - LUMA_16DC = 0, - LUMA_16AC = 1, - LUMA_8x8 = 2, - LUMA_8x4 = 3, - LUMA_4x8 = 4, - LUMA_4x4 = 5, - CHROMA_DC = 6, - CHROMA_AC = 7, - CHROMA_DC_2x4 = 8, - CHROMA_DC_4x4 = 9, - CB_16DC = 10, - CB_16AC = 11, - CB_8x8 = 12, - CB_8x4 = 13, - CB_4x8 = 14, - CB_4x4 = 15, - CR_16DC = 16, - CR_16AC = 17, - CR_8x8 = 18, - CR_8x4 = 19, - CR_4x8 = 20, - CR_4x4 = 21 + LUMA_16DC = 0, + LUMA_16AC = 1, + LUMA_8x8 = 2, + LUMA_8x4 = 3, + LUMA_4x8 = 4, + LUMA_4x4 = 5, + CHROMA_DC = 6, + CHROMA_AC = 7, + CHROMA_DC_2x4 = 8, + CHROMA_DC_4x4 = 9, + CB_16DC = 10, + CB_16AC = 11, + CB_8x8 = 12, + CB_8x4 = 13, + CB_4x8 = 14, + CB_4x4 = 15, + CR_16DC = 16, + CR_16AC = 17, + CR_8x8 = 18, + CR_8x4 = 19, + CR_4x8 = 20, + CR_4x4 = 21 } CABACBlockTypes; // Macro defines -#define Q_BITS 15 -#define DQ_BITS 6 -#define Q_BITS_8 16 -#define DQ_BITS_8 6 +#define Q_BITS 15 +#define DQ_BITS 6 +#define Q_BITS_8 16 +#define DQ_BITS_8 6 +#define IS_I16MB(MB) ((MB)->mb_type == I16MB || (MB)->mb_type == IPCM) +#define IS_DIRECT(MB) ((MB)->mb_type == 0 && (currSlice->slice_type == B_SLICE)) -#define IS_I16MB(MB) ((MB)->mb_type==I16MB || (MB)->mb_type==IPCM) -#define IS_DIRECT(MB) ((MB)->mb_type==0 && (currSlice->slice_type == B_SLICE )) - -#define TOTRUN_NUM 15 -#define RUNBEFORE_NUM 7 -#define RUNBEFORE_NUM_M1 6 +#define TOTRUN_NUM 15 +#define RUNBEFORE_NUM 7 +#define RUNBEFORE_NUM_M1 6 // Quantization parameter range -#define MIN_QP 0 -#define MAX_QP 51 -// 4x4 intra prediction modes +#define MIN_QP 0 +#define MAX_QP 51 +// 4x4 intra prediction modes typedef enum { - VERT_PRED = 0, - HOR_PRED = 1, - DC_PRED = 2, - DIAG_DOWN_LEFT_PRED = 3, + VERT_PRED = 0, + HOR_PRED = 1, + DC_PRED = 2, + DIAG_DOWN_LEFT_PRED = 3, DIAG_DOWN_RIGHT_PRED = 4, - VERT_RIGHT_PRED = 5, - HOR_DOWN_PRED = 6, - VERT_LEFT_PRED = 7, - HOR_UP_PRED = 8 + VERT_RIGHT_PRED = 5, + HOR_DOWN_PRED = 6, + VERT_LEFT_PRED = 7, + HOR_UP_PRED = 8 } I4x4PredModes; // 16x16 intra prediction modes typedef enum { - VERT_PRED_16 = 0, - HOR_PRED_16 = 1, - DC_PRED_16 = 2, - PLANE_16 = 3 + VERT_PRED_16 = 0, + HOR_PRED_16 = 1, + DC_PRED_16 = 2, + PLANE_16 = 3 } I16x16PredModes; // 8x8 chroma intra prediction modes typedef enum { - DC_PRED_8 = 0, - HOR_PRED_8 = 1, - VERT_PRED_8 = 2, - PLANE_8 = 3 + DC_PRED_8 = 0, + HOR_PRED_8 = 1, + VERT_PRED_8 = 2, + PLANE_8 = 3 } I8x8PredModes; enum { - EOS = 1, //!< End Of Sequence - SOP = 2, //!< Start Of Picture - SOS = 3, //!< Start Of Slice + EOS = 1, //!< End Of Sequence + SOP = 2, //!< Start Of Picture + SOS = 3, //!< Start Of Slice SOS_CONT = 4 }; // MV Prediction types typedef enum { - MVPRED_MEDIAN = 0, - MVPRED_L = 1, - MVPRED_U = 2, - MVPRED_UR = 3 + MVPRED_MEDIAN = 0, + MVPRED_L = 1, + MVPRED_U = 2, + MVPRED_UR = 3 } MVPredTypes; -enum { - DECODING_OK = 0, - SEARCH_SYNC = 1, - PICTURE_DECODED = 2 -}; +enum { DECODING_OK = 0, SEARCH_SYNC = 1, PICTURE_DECODED = 2 }; -#define LAMBDA_ACCURACY_BITS 16 -#define INVALIDINDEX (-135792468) +#define LAMBDA_ACCURACY_BITS 16 +#define INVALIDINDEX (-135792468) -#define RC_MAX_TEMPORAL_LEVELS 5 +#define RC_MAX_TEMPORAL_LEVELS 5 -//Start code and Emulation Prevention need this to be defined in identical manner at encoder and decoder -#define ZEROBYTES_SHORTSTARTCODE 2 //indicates the number of zero bytes in the short start-code prefix +// Start code and Emulation Prevention need this to be defined in identical +// manner at encoder and decoder +#define ZEROBYTES_SHORTSTARTCODE \ + 2 // indicates the number of zero bytes in the short start-code prefix -#define MAX_PLANE 3 -#define IS_FREXT_PROFILE(profile_idc) ( profile_idc>=FREXT_HP || profile_idc == FREXT_CAVLC444 ) -#define HI_INTRA_ONLY_PROFILE (((p_Vid->active_sps->profile_idc>=FREXT_Hi10P)&&(p_Vid->active_sps->constrained_set3_flag))||(p_Vid->active_sps->profile_idc==FREXT_CAVLC444)) +#define MAX_PLANE 3 +#define IS_FREXT_PROFILE(profile_idc) \ + (profile_idc >= FREXT_HP || profile_idc == FREXT_CAVLC444) +#define HI_INTRA_ONLY_PROFILE \ + (((p_Vid->active_sps->profile_idc >= FREXT_Hi10P) && \ + (p_Vid->active_sps->constrained_set3_flag)) || \ + (p_Vid->active_sps->profile_idc == FREXT_CAVLC444)) #endif - diff --git a/src/common/ldecod_src/inc/distortion.h b/src/common/ldecod_src/inc/distortion.h index eb48810..5cebe09 100644 --- a/src/common/ldecod_src/inc/distortion.h +++ b/src/common/ldecod_src/inc/distortion.h @@ -1,11 +1,11 @@ /*! ************************************************************************** * \file distortion.h - * \brief + * \brief * Distortion data header file * \date 2.23.2009, * - * \author + * \author * Alexis Michael Tourapis * ************************************************************************** @@ -15,17 +15,15 @@ #define _DISTORTION_H_ // Distortion data structure. Could be extended in the future to support -// other data -typedef struct distortion_data -{ - int i4x4rd[4][4]; //! i4x4 rd cost - distblk i4x4 [4][4]; //! i4x4 cost - distblk i8x8 [2][2]; //! i8x8 cost - int i8x8rd[2][2]; //! i8x8 rd cost - int i16x16; - int i16x16rd; - double rd_cost; +// other data +typedef struct distortion_data { + int i4x4rd[4][4]; //! i4x4 rd cost + distblk i4x4[4][4]; //! i4x4 cost + distblk i8x8[2][2]; //! i8x8 cost + int i8x8rd[2][2]; //! i8x8 rd cost + int i16x16; + int i16x16rd; + double rd_cost; } DistortionData; #endif - diff --git a/src/common/ldecod_src/inc/elements.h b/src/common/ldecod_src/inc/elements.h index f115bff..1ef09c8 100644 --- a/src/common/ldecod_src/inc/elements.h +++ b/src/common/ldecod_src/inc/elements.h @@ -39,40 +39,40 @@ * TYPE_CBP | SE_CBP_INTRA, SE_CBP_INTER * SE_DELTA_QUANT_INTER * SE_DELTA_QUANT_INTRA - * TYPE_COEFF_Y | SE_LUM_DC_INTRA, SE_LUM_AC_INTRA, SE_LUM_DC_INTER, SE_LUM_AC_INTER - * TYPE_2x2DC | SE_CHR_DC_INTRA, SE_CHR_DC_INTER + * TYPE_COEFF_Y | SE_LUM_DC_INTRA, SE_LUM_AC_INTRA, SE_LUM_DC_INTER, + * SE_LUM_AC_INTER TYPE_2x2DC | SE_CHR_DC_INTRA, SE_CHR_DC_INTER * TYPE_COEFF_C | SE_CHR_AC_INTRA, SE_CHR_AC_INTER * TYPE_EOS | SE_EOS -*/ + */ -#define SE_HEADER 0 -#define SE_PTYPE 1 -#define SE_MBTYPE 2 -#define SE_REFFRAME 3 -#define SE_INTRAPREDMODE 4 -#define SE_MVD 5 -#define SE_CBP_INTRA 6 -#define SE_LUM_DC_INTRA 7 -#define SE_CHR_DC_INTRA 8 -#define SE_LUM_AC_INTRA 9 -#define SE_CHR_AC_INTRA 10 -#define SE_CBP_INTER 11 -#define SE_LUM_DC_INTER 12 -#define SE_CHR_DC_INTER 13 -#define SE_LUM_AC_INTER 14 -#define SE_CHR_AC_INTER 15 -#define SE_DELTA_QUANT_INTER 16 -#define SE_DELTA_QUANT_INTRA 17 -#define SE_BFRAME 18 -#define SE_EOS 19 -#define SE_MAX_ELEMENTS 20 +#define SE_HEADER 0 +#define SE_PTYPE 1 +#define SE_MBTYPE 2 +#define SE_REFFRAME 3 +#define SE_INTRAPREDMODE 4 +#define SE_MVD 5 +#define SE_CBP_INTRA 6 +#define SE_LUM_DC_INTRA 7 +#define SE_CHR_DC_INTRA 8 +#define SE_LUM_AC_INTRA 9 +#define SE_CHR_AC_INTRA 10 +#define SE_CBP_INTER 11 +#define SE_LUM_DC_INTER 12 +#define SE_CHR_DC_INTER 13 +#define SE_LUM_AC_INTER 14 +#define SE_CHR_AC_INTER 15 +#define SE_DELTA_QUANT_INTER 16 +#define SE_DELTA_QUANT_INTRA 17 +#define SE_BFRAME 18 +#define SE_EOS 19 +#define SE_MAX_ELEMENTS 20 +#define NO_EC 0 //!< no error concealment necessary +#define EC_REQ 1 //!< error concealment required +#define EC_SYNC 2 //!< search and sync on next header element -#define NO_EC 0 //!< no error concealment necessary -#define EC_REQ 1 //!< error concealment required -#define EC_SYNC 2 //!< search and sync on next header element - -#define MAXPARTITIONMODES 2 //!< maximum possible partition modes as defined in assignSE2partition[][] +#define MAXPARTITIONMODES \ + 2 //!< maximum possible partition modes as defined in assignSE2partition[][] /*! * \brief lookup-table to assign different elements to partition @@ -99,14 +99,14 @@ * outlined in document Q15-J-23. */ - -static const byte assignSE2partition[][SE_MAX_ELEMENTS] = -{ - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // element number (do not uncomment) - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, //!< all elements in one partition no data partitioning - { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 0, 0, 0, 0 } //!< three partitions per slice +static const byte assignSE2partition[][SE_MAX_ELEMENTS] = { + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // element + // number (do not uncomment) + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0}, //!< all elements in one partition no data + //!< partitioning + {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, + 1, 0, 2, 2, 2, 2, 0, 0, 0, 0} //!< three partitions per slice }; - #endif - diff --git a/src/common/ldecod_src/inc/enc_statistics.h b/src/common/ldecod_src/inc/enc_statistics.h index 0cb6112..d7ec2c8 100644 --- a/src/common/ldecod_src/inc/enc_statistics.h +++ b/src/common/ldecod_src/inc/enc_statistics.h @@ -6,7 +6,8 @@ * statistics reports for the encoding process. * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Alexis Tourapis * - Karsten Shring * @@ -17,52 +18,55 @@ #define _ENC_STATISTICS_H_ #include "global.h" -struct stat_parameters -{ - float bitrate; //!< average bit rate for the sequence except first frame - int64 bit_ctr; //!< counter for bit usage - int64 bit_ctr_n; //!< bit usage for the current frame - int64 bit_ctr_emulationprevention; //!< stored bits needed to prevent start code emulation - int bit_slice; //!< number of bits in current slice - int stored_bit_slice; //!< keep number of bits in current slice (to restore status in case of MB re-encoding) - int b8_mode_0_use [NUM_SLICE_TYPES][2]; - int64 mode_use_transform[NUM_SLICE_TYPES][MAXMODE][2]; - int64 intra_chroma_mode[4]; +struct stat_parameters { + float bitrate; //!< average bit rate for the sequence except first frame + int64 bit_ctr; //!< counter for bit usage + int64 bit_ctr_n; //!< bit usage for the current frame + int64 bit_ctr_emulationprevention; //!< stored bits needed to prevent start + //!< code emulation + int bit_slice; //!< number of bits in current slice + int stored_bit_slice; //!< keep number of bits in current slice (to restore + //!< status in case of MB re-encoding) + int b8_mode_0_use[NUM_SLICE_TYPES][2]; + int64 mode_use_transform[NUM_SLICE_TYPES][MAXMODE][2]; + int64 intra_chroma_mode[4]; // B pictures - int NumberBFrames; + int NumberBFrames; - int frame_counter; - int64 quant [NUM_SLICE_TYPES]; - int64 num_macroblocks [NUM_SLICE_TYPES]; - int frame_ctr [NUM_SLICE_TYPES]; - int64 bit_counter [NUM_SLICE_TYPES]; - float bitrate_st [NUM_SLICE_TYPES]; - int64 mode_use [NUM_SLICE_TYPES][MAXMODE]; //!< Macroblock mode usage for Intra frames - int64 bit_use_mode [NUM_SLICE_TYPES][MAXMODE]; //!< statistics of bit usage - int64 bit_use_mb_type [NUM_SLICE_TYPES]; - int64 bit_use_header [NUM_SLICE_TYPES]; - int64 tmp_bit_use_cbp [NUM_SLICE_TYPES]; - int64 bit_use_coeffC [NUM_SLICE_TYPES]; - int64 bit_use_coeff [3][NUM_SLICE_TYPES]; - int64 bit_use_delta_quant [NUM_SLICE_TYPES]; - int64 bit_use_stuffingBits[NUM_SLICE_TYPES]; + int frame_counter; + int64 quant[NUM_SLICE_TYPES]; + int64 num_macroblocks[NUM_SLICE_TYPES]; + int frame_ctr[NUM_SLICE_TYPES]; + int64 bit_counter[NUM_SLICE_TYPES]; + float bitrate_st[NUM_SLICE_TYPES]; + int64 mode_use[NUM_SLICE_TYPES] + [MAXMODE]; //!< Macroblock mode usage for Intra frames + int64 bit_use_mode[NUM_SLICE_TYPES][MAXMODE]; //!< statistics of bit usage + int64 bit_use_mb_type[NUM_SLICE_TYPES]; + int64 bit_use_header[NUM_SLICE_TYPES]; + int64 tmp_bit_use_cbp[NUM_SLICE_TYPES]; + int64 bit_use_coeffC[NUM_SLICE_TYPES]; + int64 bit_use_coeff[3][NUM_SLICE_TYPES]; + int64 bit_use_delta_quant[NUM_SLICE_TYPES]; + int64 bit_use_stuffingBits[NUM_SLICE_TYPES]; - int bit_ctr_parametersets; - int bit_ctr_parametersets_n; - int64 bit_ctr_filler_data; - int64 bit_ctr_filler_data_n; + int bit_ctr_parametersets; + int bit_ctr_parametersets_n; + int64 bit_ctr_filler_data; + int64 bit_ctr_filler_data_n; #if (MVC_EXTENSION_ENABLE) - float bitrate_v[2]; //!< average bit rate for the sequence except first frame - int64 bit_ctr_v[2]; //!< counter for bit usage - int64 bit_ctr_n_v[2]; //!< bit usage for the current frame - int64 bit_ctr_emulationprevention_v[2]; //!< stored bits needed to prevent start code emulation - int64 bit_counter_v[2][NUM_SLICE_TYPES]; - int bit_ctr_parametersets_v[2]; - int bit_ctr_parametersets_n_v[2]; - int64 bit_ctr_filler_data_v[2]; - int64 bit_ctr_filler_data_n_v[2]; + float bitrate_v[2]; //!< average bit rate for the sequence except first frame + int64 bit_ctr_v[2]; //!< counter for bit usage + int64 bit_ctr_n_v[2]; //!< bit usage for the current frame + int64 bit_ctr_emulationprevention_v[2]; //!< stored bits needed to prevent + //!< start code emulation + int64 bit_counter_v[2][NUM_SLICE_TYPES]; + int bit_ctr_parametersets_v[2]; + int bit_ctr_parametersets_n_v[2]; + int64 bit_ctr_filler_data_v[2]; + int64 bit_ctr_filler_data_n_v[2]; #endif }; typedef struct stat_parameters StatParameters; diff --git a/src/common/ldecod_src/inc/erc_api.h b/src/common/ldecod_src/inc/erc_api.h index 17bf5e2..6aa7a4f 100644 --- a/src/common/ldecod_src/inc/erc_api.h +++ b/src/common/ldecod_src/inc/erc_api.h @@ -4,7 +4,8 @@ * \file erc_api.h * * \brief - * External (still inside video decoder) interface for error concealment module + * External (still inside video decoder) interface for error concealment + *module * * \author * - Ari Hourunranta @@ -17,116 +18,117 @@ * ************************************************************************ */ - #ifndef _ERC_API_H_ #define _ERC_API_H_ #include "erc_globals.h" /* -* Defines -*/ + * Defines + */ -/* If the average motion vector of the correctly received macroblocks is less than the -threshold, concealByCopy is used, otherwise concealByTrial is used. */ +/* If the average motion vector of the correctly received macroblocks is less +than the threshold, concealByCopy is used, otherwise concealByTrial is used. */ #define MVPERMB_THR 8 -/* used to determine the size of the allocated memory for a temporal Region (MB) */ -#define DEF_REGION_SIZE 384 /* 8*8*6 */ - -#define ERC_BLOCK_OK 3 -#define ERC_BLOCK_CONCEALED 2 -#define ERC_BLOCK_CORRUPTED 1 -#define ERC_BLOCK_EMPTY 0 +/* used to determine the size of the allocated memory for a temporal Region (MB) + */ +#define DEF_REGION_SIZE 384 /* 8*8*6 */ +#define ERC_BLOCK_OK 3 +#define ERC_BLOCK_CONCEALED 2 +#define ERC_BLOCK_CORRUPTED 1 +#define ERC_BLOCK_EMPTY 0 /* -* Functions to convert MBNum representation to blockNum -*/ + * Functions to convert MBNum representation to blockNum + */ -#define xPosYBlock(currYBlockNum,picSizeX) \ -((currYBlockNum)%((picSizeX)>>3)) +#define xPosYBlock(currYBlockNum, picSizeX) \ + ((currYBlockNum) % ((picSizeX) >> 3)) -#define yPosYBlock(currYBlockNum,picSizeX) \ -((currYBlockNum)/((picSizeX)>>3)) +#define yPosYBlock(currYBlockNum, picSizeX) \ + ((currYBlockNum) / ((picSizeX) >> 3)) -#define xPosMB(currMBNum,picSizeX) \ -((currMBNum)%((picSizeX)>>4)) +#define xPosMB(currMBNum, picSizeX) ((currMBNum) % ((picSizeX) >> 4)) -#define yPosMB(currMBNum,picSizeX) \ -((currMBNum)/((picSizeX)>>4)) +#define yPosMB(currMBNum, picSizeX) ((currMBNum) / ((picSizeX) >> 4)) -#define MBxy2YBlock(currXPos,currYPos,comp,picSizeX) \ -((((currYPos)<<1)+((comp)>>1))*((picSizeX)>>3)+((currXPos)<<1)+((comp)&1)) - -#define MBNum2YBlock(currMBNum,comp,picSizeX) \ -MBxy2YBlock(xPosMB((currMBNum),(picSizeX)),yPosMB((currMBNum),(picSizeX)),(comp),(picSizeX)) +#define MBxy2YBlock(currXPos, currYPos, comp, picSizeX) \ + ((((currYPos) << 1) + ((comp) >> 1)) * ((picSizeX) >> 3) + \ + ((currXPos) << 1) + ((comp) & 1)) +#define MBNum2YBlock(currMBNum, comp, picSizeX) \ + MBxy2YBlock(xPosMB((currMBNum), (picSizeX)), \ + yPosMB((currMBNum), (picSizeX)), (comp), (picSizeX)) /* -* typedefs -*/ + * typedefs + */ /* segment data structure */ -typedef struct ercSegment_s -{ - short startMBPos; - short endMBPos; - signed char fCorrupted; +typedef struct ercSegment_s { + short startMBPos; + short endMBPos; + signed char fCorrupted; } ercSegment_t; /* Error detector & concealment instance data structure */ -typedef struct ercVariables_s -{ +typedef struct ercVariables_s { /* Number of macroblocks (size or size/4 of the arrays) */ - int nOfMBs; + int nOfMBs; /* Number of segments (slices) in frame */ - int nOfSegments; + int nOfSegments; /* Array for conditions of Y blocks */ - signed char *yCondition; + signed char *yCondition; /* Array for conditions of U blocks */ - signed char *uCondition; + signed char *uCondition; /* Array for conditions of V blocks */ - signed char *vCondition; + signed char *vCondition; /* Array for Slice level information */ ercSegment_t *segments; - int currSegment; + int currSegment; /* Conditions of the MBs of the previous frame */ - signed char *prevFrameYCondition; + signed char *prevFrameYCondition; /* Flag telling if the current segment was found to be corrupted */ - int currSegmentCorrupted; + int currSegmentCorrupted; /* Counter for corrupted segments per picture */ - int nOfCorruptedSegments; + int nOfCorruptedSegments; /* State variables for error detector and concealer */ - int concealment; + int concealment; } ercVariables_t; /* -* External function interface -*/ + * External function interface + */ -void ercInit (VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag); -ercVariables_t *ercOpen( void ); -void ercReset( ercVariables_t *errorVar, int nOfMBs, int numOfSegments, int picSizeX ); -void ercClose( VideoParameters *p_Vid, ercVariables_t *errorVar ); -void ercSetErrorConcealment( ercVariables_t *errorVar, int value ); +void ercInit(VideoParameters *p_Vid, int pic_sizex, int pic_sizey, int flag); +ercVariables_t *ercOpen(void); +void ercReset(ercVariables_t *errorVar, int nOfMBs, int numOfSegments, + int picSizeX); +void ercClose(VideoParameters *p_Vid, ercVariables_t *errorVar); +void ercSetErrorConcealment(ercVariables_t *errorVar, int value); -void ercStartSegment( int currMBNum, int segment, unsigned int bitPos, ercVariables_t *errorVar ); -void ercStopSegment( int currMBNum, int segment, unsigned int bitPos, ercVariables_t *errorVar ); -void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar ); -void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar ); -void ercMarkCurrMBConcealed( int currMBNum, int comp, int picSizeX, ercVariables_t *errorVar ); - -int ercConcealIntraFrame( VideoParameters *p_Vid, frame *recfr, int picSizeX, int picSizeY, ercVariables_t *errorVar ); -int ercConcealInterFrame( frame *recfr, objectBuffer_t *object_list, - int picSizeX, int picSizeY, ercVariables_t *errorVar, int chroma_format_idc ); +void ercStartSegment(int currMBNum, int segment, unsigned int bitPos, + ercVariables_t *errorVar); +void ercStopSegment(int currMBNum, int segment, unsigned int bitPos, + ercVariables_t *errorVar); +void ercMarkCurrSegmentLost(int picSizeX, ercVariables_t *errorVar); +void ercMarkCurrSegmentOK(int picSizeX, ercVariables_t *errorVar); +void ercMarkCurrMBConcealed(int currMBNum, int comp, int picSizeX, + ercVariables_t *errorVar); +int ercConcealIntraFrame(VideoParameters *p_Vid, frame *recfr, int picSizeX, + int picSizeY, ercVariables_t *errorVar); +int ercConcealInterFrame(frame *recfr, objectBuffer_t *object_list, + int picSizeX, int picSizeY, ercVariables_t *errorVar, + int chroma_format_idc); /* Thomson APIs for concealing entire frame loss */ @@ -134,25 +136,26 @@ int ercConcealInterFrame( frame *recfr, objectBuffer_t *object_list, #include "output.h" struct concealment_node { - StorablePicture* picture; - int missingpocs; - struct concealment_node *next; + StorablePicture *picture; + int missingpocs; + struct concealment_node *next; }; -extern struct concealment_node * init_node(StorablePicture* , int ); -extern void print_node( struct concealment_node * ); -extern void print_list( struct concealment_node * ); -extern void init_lists_for_non_reference_loss(DecodedPictureBuffer *p_Dpb, int , PictureStructure ); +extern struct concealment_node *init_node(StorablePicture *, int); +extern void print_node(struct concealment_node *); +extern void print_list(struct concealment_node *); +extern void init_lists_for_non_reference_loss(DecodedPictureBuffer *p_Dpb, int, + PictureStructure); extern void conceal_non_ref_pics(DecodedPictureBuffer *p_Dpb, int diff); -extern void conceal_lost_frames (DecodedPictureBuffer *p_Dpb, Slice *pSlice); +extern void conceal_lost_frames(DecodedPictureBuffer *p_Dpb, Slice *pSlice); -extern void sliding_window_poc_management(DecodedPictureBuffer *p_Dpb, StorablePicture *p); -extern void write_lost_non_ref_pic (DecodedPictureBuffer *p_Dpb, int poc, int p_out); -extern void write_lost_ref_after_idr (DecodedPictureBuffer *p_Dpb, int pos); +extern void sliding_window_poc_management(DecodedPictureBuffer *p_Dpb, + StorablePicture *p); +extern void write_lost_non_ref_pic(DecodedPictureBuffer *p_Dpb, int poc, + int p_out); +extern void write_lost_ref_after_idr(DecodedPictureBuffer *p_Dpb, int pos); extern int comp(const void *, const void *); - #endif - diff --git a/src/common/ldecod_src/inc/erc_do.h b/src/common/ldecod_src/inc/erc_do.h index 778580c..0f4b585 100644 --- a/src/common/ldecod_src/inc/erc_do.h +++ b/src/common/ldecod_src/inc/erc_do.h @@ -16,29 +16,35 @@ #ifndef _ERC_DO_H_ #define _ERC_DO_H_ - #include "erc_api.h" -void ercPixConcealIMB (VideoParameters *p_Vid, imgpel *currFrame, int row, int column, int predBlocks[], int frameWidth, int mbWidthInBlocks); +void ercPixConcealIMB(VideoParameters *p_Vid, imgpel *currFrame, int row, + int column, int predBlocks[], int frameWidth, + int mbWidthInBlocks); -int ercCollect8PredBlocks( int predBlocks[], int currRow, int currColumn, signed char *condition, - int maxRow, int maxColumn, int step, byte fNoCornerNeigh ); -int ercCollectColumnBlocks( int predBlocks[], int currRow, int currColumn, signed char *condition, int maxRow, int maxColumn, int step ); +int ercCollect8PredBlocks(int predBlocks[], int currRow, int currColumn, + signed char *condition, int maxRow, int maxColumn, + int step, byte fNoCornerNeigh); +int ercCollectColumnBlocks(int predBlocks[], int currRow, int currColumn, + signed char *condition, int maxRow, int maxColumn, + int step); -#define isSplitted(object_list,currMBNum) \ - ((object_list+((currMBNum)<<2))->regionMode >= REGMODE_SPLITTED) +#define isSplitted(object_list, currMBNum) \ + ((object_list + ((currMBNum) << 2))->regionMode >= REGMODE_SPLITTED) /* this can be used as isBlock(...,INTRA) or isBlock(...,INTER_COPY) */ -#define isBlock(object_list,currMBNum,comp,regMode) \ - (isSplitted(object_list,currMBNum) ? \ - ((object_list+((currMBNum)<<2)+(comp))->regionMode == REGMODE_##regMode##_8x8) : \ - ((object_list+((currMBNum)<<2))->regionMode == REGMODE_##regMode)) +#define isBlock(object_list, currMBNum, comp, regMode) \ + (isSplitted(object_list, currMBNum) \ + ? ((object_list + ((currMBNum) << 2) + (comp))->regionMode == \ + REGMODE_##regMode##_8x8) \ + : ((object_list + ((currMBNum) << 2))->regionMode == \ + REGMODE_##regMode)) -/* this can be used as getParam(...,mv) or getParam(...,xMin) or getParam(...,yMin) */ -#define getParam(object_list,currMBNum,comp,param) \ - (isSplitted(object_list,currMBNum) ? \ - ((object_list+((currMBNum)<<2)+(comp))->param) : \ - ((object_list+((currMBNum)<<2))->param)) +/* this can be used as getParam(...,mv) or getParam(...,xMin) or + * getParam(...,yMin) */ +#define getParam(object_list, currMBNum, comp, param) \ + (isSplitted(object_list, currMBNum) \ + ? ((object_list + ((currMBNum) << 2) + (comp))->param) \ + : ((object_list + ((currMBNum) << 2))->param)) #endif - diff --git a/src/common/ldecod_src/inc/erc_globals.h b/src/common/ldecod_src/inc/erc_globals.h index 2722cd5..d7cca39 100644 --- a/src/common/ldecod_src/inc/erc_globals.h +++ b/src/common/ldecod_src/inc/erc_globals.h @@ -20,33 +20,34 @@ /* "block" means an 8x8 pixel area */ /* Region modes */ -#define REGMODE_INTER_COPY 0 //!< Copy region -#define REGMODE_INTER_PRED 1 //!< Inter region with motion vectors -#define REGMODE_INTRA 2 //!< Intra region -#define REGMODE_SPLITTED 3 //!< Any region mode higher than this indicates that the region - //!< is splitted which means 8x8 block -#define REGMODE_INTER_COPY_8x8 4 -#define REGMODE_INTER_PRED_8x8 5 -#define REGMODE_INTRA_8x8 6 +#define REGMODE_INTER_COPY 0 //!< Copy region +#define REGMODE_INTER_PRED 1 //!< Inter region with motion vectors +#define REGMODE_INTRA 2 //!< Intra region +#define REGMODE_SPLITTED \ + 3 //!< Any region mode higher than this indicates that the region + //!< is splitted which means 8x8 block +#define REGMODE_INTER_COPY_8x8 4 +#define REGMODE_INTER_PRED_8x8 5 +#define REGMODE_INTRA_8x8 6 //! YUV pixel domain image arrays for a video frame -typedef struct frame_s -{ +typedef struct frame_s { VideoParameters *p_Vid; imgpel *yptr; imgpel *uptr; imgpel *vptr; } frame; -//! region structure stores information about a region that is needed for concealment -typedef struct object_buffer -{ - byte regionMode; //!< region mode as above - int xMin; //!< X coordinate of the pixel position of the top-left corner of the region - int yMin; //!< Y coordinate of the pixel position of the top-left corner of the region - int mv[3]; //!< motion vectors in 1/4 pixel units: mvx = mv[0], mvy = mv[1], - //!< and ref_frame = mv[2] +//! region structure stores information about a region that is needed for +//! concealment +typedef struct object_buffer { + byte regionMode; //!< region mode as above + int xMin; //!< X coordinate of the pixel position of the top-left corner of + //!< the region + int yMin; //!< Y coordinate of the pixel position of the top-left corner of + //!< the region + int mv[3]; //!< motion vectors in 1/4 pixel units: mvx = mv[0], mvy = mv[1], + //!< and ref_frame = mv[2] } objectBuffer_t; #endif - diff --git a/src/common/ldecod_src/inc/errorconcealment.h b/src/common/ldecod_src/inc/errorconcealment.h index 4d5620c..720af8b 100644 --- a/src/common/ldecod_src/inc/errorconcealment.h +++ b/src/common/ldecod_src/inc/errorconcealment.h @@ -13,9 +13,8 @@ #ifndef _ERRORCONCEALMENT_H_ #define _ERRORCONCEALMENT_H_ -extern int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym); -extern int set_ec_flag (VideoParameters *p_Vid, int se); -extern void reset_ec_flags (VideoParameters *p_Vid); +extern int get_concealed_element(VideoParameters *p_Vid, SyntaxElement *sym); +extern int set_ec_flag(VideoParameters *p_Vid, int se); +extern void reset_ec_flags(VideoParameters *p_Vid); #endif - diff --git a/src/common/ldecod_src/inc/fast_memory.h b/src/common/ldecod_src/inc/fast_memory.h index 68b51f0..80b8d4b 100644 --- a/src/common/ldecod_src/inc/fast_memory.h +++ b/src/common/ldecod_src/inc/fast_memory.h @@ -6,7 +6,8 @@ * Memory handling operations * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Chris Vogt * ************************************************************************** @@ -17,16 +18,12 @@ #include "typedefs.h" - -static inline void fast_memset(void *dst,int value,int width) -{ - memset(dst,value,width); +static inline void fast_memset(void *dst, int value, int width) { + memset(dst, value, width); } -static inline void fast_memcpy(void *dst,void *src,int width) -{ - memcpy(dst,src,width); +static inline void fast_memcpy(void *dst, void *src, int width) { + memcpy(dst, src, width); } -#endif - +#endif diff --git a/src/common/ldecod_src/inc/fmo.h b/src/common/ldecod_src/inc/fmo.h index ba54f51..d2ca72d 100644 --- a/src/common/ldecod_src/inc/fmo.h +++ b/src/common/ldecod_src/inc/fmo.h @@ -17,14 +17,13 @@ #ifndef _FMO_H_ #define _FMO_H_ - -extern int fmo_init (VideoParameters *p_Vid, Slice *pSlice); -extern int FmoFinit (VideoParameters *p_Vid); +extern int fmo_init(VideoParameters *p_Vid, Slice *pSlice); +extern int FmoFinit(VideoParameters *p_Vid); extern int FmoGetNumberOfSliceGroup(VideoParameters *p_Vid); -extern int FmoGetLastMBOfPicture (VideoParameters *p_Vid); +extern int FmoGetLastMBOfPicture(VideoParameters *p_Vid); extern int FmoGetLastMBInSliceGroup(VideoParameters *p_Vid, int SliceGroup); -extern int FmoGetSliceGroupId (VideoParameters *p_Vid, int mb); -extern int FmoGetNextMBNr (VideoParameters *p_Vid, int CurrentMbNr); +extern int FmoGetSliceGroupId(VideoParameters *p_Vid, int mb); +extern int FmoGetNextMBNr(VideoParameters *p_Vid, int CurrentMbNr); #endif diff --git a/src/common/ldecod_src/inc/frame.h b/src/common/ldecod_src/inc/frame.h index a2f3a9c..e61a3fb 100644 --- a/src/common/ldecod_src/inc/frame.h +++ b/src/common/ldecod_src/inc/frame.h @@ -12,43 +12,37 @@ #ifndef _FRAME_H_ #define _FRAME_H_ -typedef enum { - CM_UNKNOWN = -1, - CM_YUV = 0, - CM_RGB = 1, - CM_XYZ = 2 -} ColorModel; +typedef enum { CM_UNKNOWN = -1, CM_YUV = 0, CM_RGB = 1, CM_XYZ = 2 } ColorModel; typedef enum { - CF_UNKNOWN = -1, //!< Unknown color format - YUV400 = 0, //!< Monochrome - YUV420 = 1, //!< 4:2:0 - YUV422 = 2, //!< 4:2:2 - YUV444 = 3 //!< 4:4:4 + CF_UNKNOWN = -1, //!< Unknown color format + YUV400 = 0, //!< Monochrome + YUV420 = 1, //!< 4:2:0 + YUV422 = 2, //!< 4:2:2 + YUV444 = 3 //!< 4:4:4 } ColorFormat; -typedef struct frame_format -{ - ColorFormat yuv_format; //!< YUV format (0=4:0:0, 1=4:2:0, 2=4:2:2, 3=4:4:4) - ColorModel color_model; //!< 4:4:4 format (0: YUV, 1: RGB, 2: XYZ) - double frame_rate; //!< frame rate - int width[3]; //!< component frame width - int height[3]; //!< component frame height - int auto_crop_right; //!< luma component auto crop right - int auto_crop_bottom; //!< luma component auto crop bottom - int auto_crop_right_cr; //!< chroma component auto crop right - int auto_crop_bottom_cr; //!< chroma component auto crop bottom - int width_crop; //!< width after cropping consideration - int height_crop; //!< height after cropping consideration - int mb_width; //!< luma component frame width - int mb_height; //!< luma component frame height - int size_cmp[3]; //!< component sizes (width * height) - int size; //!< total image size (sum of size_cmp) - int bit_depth[3]; //!< component bit depth - int max_value[3]; //!< component max value - int max_value_sq[3]; //!< component max value squared - int pic_unit_size_on_disk; //!< picture sample unit size on storage medium - int pic_unit_size_shift3; //!< pic_unit_size_on_disk >> 3 +typedef struct frame_format { + ColorFormat yuv_format; //!< YUV format (0=4:0:0, 1=4:2:0, 2=4:2:2, 3=4:4:4) + ColorModel color_model; //!< 4:4:4 format (0: YUV, 1: RGB, 2: XYZ) + double frame_rate; //!< frame rate + int width[3]; //!< component frame width + int height[3]; //!< component frame height + int auto_crop_right; //!< luma component auto crop right + int auto_crop_bottom; //!< luma component auto crop bottom + int auto_crop_right_cr; //!< chroma component auto crop right + int auto_crop_bottom_cr; //!< chroma component auto crop bottom + int width_crop; //!< width after cropping consideration + int height_crop; //!< height after cropping consideration + int mb_width; //!< luma component frame width + int mb_height; //!< luma component frame height + int size_cmp[3]; //!< component sizes (width * height) + int size; //!< total image size (sum of size_cmp) + int bit_depth[3]; //!< component bit depth + int max_value[3]; //!< component max value + int max_value_sq[3]; //!< component max value squared + int pic_unit_size_on_disk; //!< picture sample unit size on storage medium + int pic_unit_size_shift3; //!< pic_unit_size_on_disk >> 3 } FrameFormat; #endif diff --git a/src/common/ldecod_src/inc/global.h b/src/common/ldecod_src/inc/global.h index d4f2b42..1d62c36 100644 --- a/src/common/ldecod_src/inc/global.h +++ b/src/common/ldecod_src/inc/global.h @@ -26,28 +26,29 @@ #ifndef _GLOBAL_H_ #define _GLOBAL_H_ -#include -#include -#include #include +#include +#include +#include #ifndef SPEC -#include #include +#include #endif /* !SPEC */ -#include "win32.h" #include "defines.h" +#include "distortion.h" +#include "frame.h" #include "ifunctions.h" +#include "io_image.h" +#include "io_video.h" #include "parsetcommon.h" #include "types.h" -#include "io_image.h" -#include "frame.h" -#include "distortion.h" -#include "io_video.h" +#include "win32.h" typedef struct bit_stream Bitstream; -#define ET_SIZE 300 //!< size of error text buffer -extern char errortext[ET_SIZE]; //!< buffer for error message for exit with error() +#define ET_SIZE 300 //!< size of error text buffer +extern char + errortext[ET_SIZE]; //!< buffer for error message for exit with error() struct pic_motion_params_old; struct pic_motion_params; @@ -56,28 +57,21 @@ struct pic_motion_params; * T y p e d e f i n i t i o n s f o r J M *********************************************************************** */ -typedef enum -{ - DEC_OPENED = 0, - DEC_STOPPED, -}DecoderStatus_e; +typedef enum { + DEC_OPENED = 0, + DEC_STOPPED, +} DecoderStatus_e; -typedef enum -{ - LumaComp = 0, - CrComp = 1, - CbComp = 2 -} Color_Component; +typedef enum { LumaComp = 0, CrComp = 1, CbComp = 2 } Color_Component; /*********************************************************************** * D a t a t y p e s f o r C A B A C *********************************************************************** */ -typedef struct pix_pos -{ - int available; - int mb_addr; +typedef struct pix_pos { + int available; + int mb_addr; short x; short y; short pos_x; @@ -85,28 +79,25 @@ typedef struct pix_pos } PixelPos; //! struct to characterize the state of the arithmetic coding engine -typedef struct -{ - unsigned int Drange; - unsigned int Dvalue; - int DbitsLeft; - byte *Dcodestrm; - int *Dcodestrm_len; +typedef struct { + unsigned int Drange; + unsigned int Dvalue; + int DbitsLeft; + byte *Dcodestrm; + int *Dcodestrm_len; } DecodingEnvironment; typedef DecodingEnvironment *DecodingEnvironmentPtr; // Motion Vector structure -typedef struct -{ +typedef struct { short mv_x; short mv_y; } MotionVector; static const MotionVector zero_mv = {0, 0}; -typedef struct -{ +typedef struct { short x; short y; } BlockPos; @@ -114,25 +105,23 @@ typedef struct extern BlockPos *PicPos; //! struct for context management -typedef struct -{ - uint16 state; // index into state-table CP - unsigned char MPS; // Least Probable Symbol 0/1 CP - unsigned char dummy; // for alignment +typedef struct { + uint16 state; // index into state-table CP + unsigned char MPS; // Least Probable Symbol 0/1 CP + unsigned char dummy; // for alignment } BiContextType; typedef BiContextType *BiContextTypePtr; - /********************************************************************** * C O N T E X T S F O R T M L S Y N T A X E L E M E N T S ********************************************************************** */ -#define NUM_MB_TYPE_CTX 11 -#define NUM_B8_TYPE_CTX 9 -#define NUM_MV_RES_CTX 10 -#define NUM_REF_NO_CTX 6 +#define NUM_MB_TYPE_CTX 11 +#define NUM_B8_TYPE_CTX 9 +#define NUM_MV_RES_CTX 10 +#define NUM_REF_NO_CTX 6 #define NUM_DELTA_QP_CTX 4 #define NUM_MB_AFF_CTX 4 #define NUM_TRANSFORM_SIZE_CTX 3 @@ -142,40 +131,38 @@ struct storable_picture; struct datapartition; struct syntaxelement; -typedef struct -{ - BiContextType mb_type_contexts [3][NUM_MB_TYPE_CTX]; - BiContextType b8_type_contexts [2][NUM_B8_TYPE_CTX]; - BiContextType mv_res_contexts [2][NUM_MV_RES_CTX]; - BiContextType ref_no_contexts [2][NUM_REF_NO_CTX]; +typedef struct { + BiContextType mb_type_contexts[3][NUM_MB_TYPE_CTX]; + BiContextType b8_type_contexts[2][NUM_B8_TYPE_CTX]; + BiContextType mv_res_contexts[2][NUM_MV_RES_CTX]; + BiContextType ref_no_contexts[2][NUM_REF_NO_CTX]; BiContextType delta_qp_contexts[NUM_DELTA_QP_CTX]; - BiContextType mb_aff_contexts [NUM_MB_AFF_CTX]; + BiContextType mb_aff_contexts[NUM_MB_AFF_CTX]; } MotionInfoContexts; -#define NUM_IPR_CTX 2 -#define NUM_CIPR_CTX 4 -#define NUM_CBP_CTX 4 -#define NUM_BCBP_CTX 4 -#define NUM_MAP_CTX 15 -#define NUM_LAST_CTX 15 -#define NUM_ONE_CTX 5 -#define NUM_ABS_CTX 5 +#define NUM_IPR_CTX 2 +#define NUM_CIPR_CTX 4 +#define NUM_CBP_CTX 4 +#define NUM_BCBP_CTX 4 +#define NUM_MAP_CTX 15 +#define NUM_LAST_CTX 15 +#define NUM_ONE_CTX 5 +#define NUM_ABS_CTX 5 -typedef struct -{ - BiContextType transform_size_contexts [NUM_TRANSFORM_SIZE_CTX]; - BiContextType ipr_contexts [NUM_IPR_CTX]; - BiContextType cipr_contexts[NUM_CIPR_CTX]; - BiContextType cbp_contexts [3][NUM_CBP_CTX]; - BiContextType bcbp_contexts[NUM_BLOCK_TYPES][NUM_BCBP_CTX]; - BiContextType map_contexts [2][NUM_BLOCK_TYPES][NUM_MAP_CTX]; - BiContextType last_contexts[2][NUM_BLOCK_TYPES][NUM_LAST_CTX]; - BiContextType one_contexts [NUM_BLOCK_TYPES][NUM_ONE_CTX]; - BiContextType abs_contexts [NUM_BLOCK_TYPES][NUM_ABS_CTX]; +typedef struct { + BiContextType transform_size_contexts[NUM_TRANSFORM_SIZE_CTX]; + BiContextType ipr_contexts[NUM_IPR_CTX]; + BiContextType cipr_contexts[NUM_CIPR_CTX]; + BiContextType cbp_contexts[3][NUM_CBP_CTX]; + BiContextType bcbp_contexts[NUM_BLOCK_TYPES][NUM_BCBP_CTX]; + BiContextType map_contexts[2][NUM_BLOCK_TYPES][NUM_MAP_CTX]; + BiContextType last_contexts[2][NUM_BLOCK_TYPES][NUM_LAST_CTX]; + BiContextType one_contexts[NUM_BLOCK_TYPES][NUM_ONE_CTX]; + BiContextType abs_contexts[NUM_BLOCK_TYPES][NUM_ABS_CTX]; } TextureInfoContexts; - -//*********************** end of data type definition for CABAC ******************* +//*********************** end of data type definition for CABAC +//******************* /*********************************************************************** * N e w D a t a t y p e s f o r T M L @@ -183,8 +170,7 @@ typedef struct */ /*! Buffer structure for decoded referenc picture marking commands */ -typedef struct DecRefPicMarking_s -{ +typedef struct DecRefPicMarking_s { int memory_management_control_operation; int difference_of_pic_nums_minus1; int long_term_pic_num; @@ -194,12 +180,11 @@ typedef struct DecRefPicMarking_s } DecRefPicMarking_t; //! Macroblock -typedef struct macroblock -{ - struct slice *p_Slice; //!< pointer to the current slice - struct video_par *p_Vid; //!< pointer to VideoParameters - struct inp_par *p_Inp; - int mbAddrX; //!< current MB address +typedef struct macroblock { + struct slice *p_Slice; //!< pointer to the current slice + struct video_par *p_Vid; //!< pointer to VideoParameters + struct inp_par *p_Inp; + int mbAddrX; //!< current MB address BlockPos mb; int block_x; int block_y; @@ -212,136 +197,145 @@ typedef struct macroblock int subblock_x; int subblock_y; - int qp; //!< QP luma - int qpc[2]; //!< QP chroma - int qp_scaled[MAX_PLANE]; //!< QP scaled for all comps. - Boolean is_lossless; - Boolean is_intra_block; - Boolean is_v_block; - Boolean DeblockCall; + int qp; //!< QP luma + int qpc[2]; //!< QP chroma + int qp_scaled[MAX_PLANE]; //!< QP scaled for all comps. + Boolean is_lossless; + Boolean is_intra_block; + Boolean is_v_block; + Boolean DeblockCall; - short slice_nr; - signed char ei_flag; //!< error indicator flag that enables concealment - signed char dpl_flag; //!< error indicator flag that signals a missing data partition - short delta_quant; //!< for rate control - short list_offset; + short slice_nr; + signed char ei_flag; //!< error indicator flag that enables concealment + signed char + dpl_flag; //!< error indicator flag that signals a missing data partition + short delta_quant; //!< for rate control + short list_offset; - struct macroblock *mb_up; //!< pointer to neighboring MB (CABAC) - struct macroblock *mb_left; //!< pointer to neighboring MB (CABAC) + struct macroblock *mb_up; //!< pointer to neighboring MB (CABAC) + struct macroblock *mb_left; //!< pointer to neighboring MB (CABAC) - struct macroblock *mbup; // neighbors for loopfilter - struct macroblock *mbleft; // neighbors for loopfilter + struct macroblock *mbup; // neighbors for loopfilter + struct macroblock *mbleft; // neighbors for loopfilter // some storage of macroblock syntax elements for global access - short mb_type; - short mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE][2]; //!< indices correspond to [forw,backw][block_y][block_x][x,y] - //short ****mvd; //!< indices correspond to [forw,backw][block_y][block_x][x,y] - int cbp; - int64 cbp_blk [3]; - int64 cbp_bits [3]; - int64 cbp_bits_8x8[3]; + short mb_type; + short mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE] + [2]; //!< indices correspond to [forw,backw][block_y][block_x][x,y] + // short ****mvd; //!< indices correspond to + // [forw,backw][block_y][block_x][x,y] + int cbp; + int64 cbp_blk[3]; + int64 cbp_bits[3]; + int64 cbp_bits_8x8[3]; - int i16mode; - signed char b8mode[4]; - signed char b8pdir[4]; - signed char ipmode_DPCM; - signed char c_ipred_mode; //!< chroma intra prediction mode - signed char skip_flag; - short DFDisableIdc; - short DFAlphaC0Offset; - short DFBetaOffset; + int i16mode; + signed char b8mode[4]; + signed char b8pdir[4]; + signed char ipmode_DPCM; + signed char c_ipred_mode; //!< chroma intra prediction mode + signed char skip_flag; + short DFDisableIdc; + short DFAlphaC0Offset; + short DFBetaOffset; - Boolean mb_field; + Boolean mb_field; int mbAddrA, mbAddrB, mbAddrC, mbAddrD; Boolean mbAvailA, mbAvailB, mbAvailC, mbAvailD; - Boolean luma_transform_size_8x8_flag; - Boolean NoMbPartLessThan8x8Flag; + Boolean luma_transform_size_8x8_flag; + Boolean NoMbPartLessThan8x8Flag; - void (*itrans_4x4)(struct macroblock *currMB, ColorPlane pl, int ioff, int joff); - void (*itrans_8x8)(struct macroblock *currMB, ColorPlane pl, int ioff, int joff); + void (*itrans_4x4)(struct macroblock *currMB, ColorPlane pl, int ioff, + int joff); + void (*itrans_8x8)(struct macroblock *currMB, ColorPlane pl, int ioff, + int joff); - void (*GetMVPredictor) (struct macroblock *currMB, PixelPos *block, - MotionVector *pmv, short ref_frame, struct pic_motion_params **mv_info, int list, int mb_x, int mb_y, int blockshape_x, int blockshape_y); + void (*GetMVPredictor)(struct macroblock *currMB, PixelPos *block, + MotionVector *pmv, short ref_frame, + struct pic_motion_params **mv_info, int list, int mb_x, + int mb_y, int blockshape_x, int blockshape_y); - int (*read_and_store_CBP_block_bit) (struct macroblock *currMB, DecodingEnvironmentPtr dep_dp, int type); - signed char (*readRefPictureIdx) (struct macroblock *currMB, struct syntaxelement *currSE, struct datapartition *dP, signed char b8mode, int list); + int (*read_and_store_CBP_block_bit)(struct macroblock *currMB, + DecodingEnvironmentPtr dep_dp, int type); + signed char (*readRefPictureIdx)(struct macroblock *currMB, + struct syntaxelement *currSE, + struct datapartition *dP, signed char b8mode, + int list); - //MBAFF case; + // MBAFF case; byte mixedModeEdgeFlag; } Macroblock; //! Syntaxelement -typedef struct syntaxelement -{ - int type; //!< type of syntax element for data part. - int value1; //!< numerical value of syntax element - int value2; //!< for blocked symbols, e.g. run/level - int len; //!< length of code - int inf; //!< info part of CAVLC code - unsigned int bitpattern; //!< CAVLC bitpattern - int context; //!< CABAC context - int k; //!< CABAC context for coeff_count,uv +typedef struct syntaxelement { + int type; //!< type of syntax element for data part. + int value1; //!< numerical value of syntax element + int value2; //!< for blocked symbols, e.g. run/level + int len; //!< length of code + int inf; //!< info part of CAVLC code + unsigned int bitpattern; //!< CAVLC bitpattern + int context; //!< CABAC context + int k; //!< CABAC context for coeff_count,uv #if TRACE - #define TRACESTRING_SIZE 100 //!< size of trace string - char tracestring[TRACESTRING_SIZE]; //!< trace string +#define TRACESTRING_SIZE 100 //!< size of trace string + char tracestring[TRACESTRING_SIZE]; //!< trace string #endif //! for mapping of CAVLC to syntaxElement - void (*mapping)(int len, int info, int *value1, int *value2); - //! used for CABAC: refers to actual coding method of each individual syntax element type - void (*reading)(Macroblock *currMB, struct syntaxelement *, DecodingEnvironmentPtr); + void (*mapping)(int len, int info, int *value1, int *value2); + //! used for CABAC: refers to actual coding method of each individual syntax + //! element type + void (*reading)(Macroblock *currMB, struct syntaxelement *, + DecodingEnvironmentPtr); } SyntaxElement; - //! Bitstream -struct bit_stream -{ +struct bit_stream { // CABAC Decoding - int read_len; //!< actual position in the codebuffer, CABAC only - int code_len; //!< overall codebuffer length, CABAC only + int read_len; //!< actual position in the codebuffer, CABAC only + int code_len; //!< overall codebuffer length, CABAC only // CAVLC Decoding - int frame_bitoffset; //!< actual position in the codebuffer, bit-oriented, CAVLC only - int bitstream_length; //!< over codebuffer lnegth, byte oriented, CAVLC only + int frame_bitoffset; //!< actual position in the codebuffer, bit-oriented, + //!< CAVLC only + int bitstream_length; //!< over codebuffer lnegth, byte oriented, CAVLC only // ErrorConcealment - byte *streamBuffer; //!< actual codebuffer for read bytes - int ei_flag; //!< error indication, 0: no error, else unspecified error + byte *streamBuffer; //!< actual codebuffer for read bytes + int ei_flag; //!< error indication, 0: no error, else unspecified error }; //! DataPartition -typedef struct datapartition -{ +typedef struct datapartition { - Bitstream *bitstream; + Bitstream *bitstream; DecodingEnvironment de_cabac; - int (*readSyntaxElement)(Macroblock *currMB, SyntaxElement *, struct datapartition *); - /*!< virtual function; - actual method depends on chosen data partition and - entropy coding method */ + int (*readSyntaxElement)(Macroblock *currMB, SyntaxElement *, + struct datapartition *); + /*!< virtual function; + actual method depends on chosen data partition and + entropy coding method */ } DataPartition; #if (MVC_EXTENSION_ENABLE) -typedef struct nalunitheadermvcext_tag -{ - unsigned int non_idr_flag; - unsigned int priority_id; - unsigned int view_id; - unsigned int temporal_id; - unsigned int anchor_pic_flag; - unsigned int inter_view_flag; - unsigned int reserved_one_bit; - unsigned int iPrefixNALU; +typedef struct nalunitheadermvcext_tag { + unsigned int non_idr_flag; + unsigned int priority_id; + unsigned int view_id; + unsigned int temporal_id; + unsigned int anchor_pic_flag; + unsigned int inter_view_flag; + unsigned int reserved_one_bit; + unsigned int iPrefixNALU; } NALUnitHeaderMVCExt_t; #endif //! Slice -typedef struct slice -{ - struct video_par *p_Vid; - struct inp_par *p_Inp; +typedef struct slice { + struct video_par *p_Vid; + struct inp_par *p_Inp; pic_parameter_set_rbsp_t *active_pps; seq_parameter_set_rbsp_t *active_sps; int svc_extension_flag; @@ -349,19 +343,19 @@ typedef struct slice // dpb pointer struct decoded_picture_buffer *p_Dpb; - //slice property; + // slice property; int idr_flag; int idr_pic_id; - int nal_reference_idc; //!< nal_reference_idc from NAL unit + int nal_reference_idc; //!< nal_reference_idc from NAL unit int Transform8x8Mode; Boolean is_not_independent; - int toppoc; //poc for this top field // POC200301 - int bottompoc; //poc of bottom field of frame - int framepoc; //poc of this frame // POC200301 + int toppoc; // poc for this top field // POC200301 + int bottompoc; // poc of bottom field of frame + int framepoc; // poc of this frame // POC200301 - //the following is for slice header syntax elements of poc - // for poc mode 0. + // the following is for slice header syntax elements of poc + // for poc mode 0. unsigned int pic_order_cnt_lsb; int delta_pic_order_cnt_bottom; // for poc mode 1. @@ -369,142 +363,149 @@ typedef struct slice // //////////////////////// // for POC mode 0: - signed int PicOrderCntMsb; + signed int PicOrderCntMsb; - //signed int PrevPicOrderCntMsb; - //unsigned int PrevPicOrderCntLsb; + // signed int PrevPicOrderCntMsb; + // unsigned int PrevPicOrderCntLsb; // for POC mode 1: unsigned int AbsFrameNum; int ThisPOC; - //signed int ExpectedPicOrderCnt, PicOrderCntCycleCnt, FrameNumInPicOrderCntCycle; - //unsigned int PreviousFrameNum, FrameNumOffset; - //int ExpectedDeltaPerPicOrderCntCycle; - //int PreviousFrameNumOffset; - // ///////////////////////// + // signed int ExpectedPicOrderCnt, PicOrderCntCycleCnt, + // FrameNumInPicOrderCntCycle; unsigned int PreviousFrameNum, FrameNumOffset; + // int ExpectedDeltaPerPicOrderCntCycle; + // int PreviousFrameNumOffset; + // ///////////////////////// - //information need to move to slice; + // information need to move to slice; unsigned int current_mb_nr; // bitstream order unsigned int num_dec_mb; - short current_slice_nr; - //int mb_x; - //int mb_y; - //int block_x; - //int block_y; - //int pix_c_x; - //int pix_c_y; - int cod_counter; //!< Current count of number of skipped macroblocks in a row + short current_slice_nr; + // int mb_x; + // int mb_y; + // int block_x; + // int block_y; + // int pix_c_x; + // int pix_c_y; + int cod_counter; //!< Current count of number of skipped macroblocks in a row int allrefzero; - //end; + // end; - int mb_aff_frame_flag; - int direct_spatial_mv_pred_flag; //!< Indicator for direct mode type (1 for Spatial, 0 for Temporal) - int num_ref_idx_active[2]; //!< number of available list references - //int num_ref_idx_l0_active; //!< number of available list 0 references - //int num_ref_idx_l1_active; //!< number of available list 1 references + int mb_aff_frame_flag; + int direct_spatial_mv_pred_flag; //!< Indicator for direct mode type (1 for + //!< Spatial, 0 for Temporal) + int num_ref_idx_active[2]; //!< number of available list references + // int num_ref_idx_l0_active; //!< number of + // available list 0 references int num_ref_idx_l1_active; //!< + // number of available list 1 references - int ei_flag; //!< 0 if the partArr[0] contains valid information - int qp; - int slice_qp_delta; - int qs; - int slice_qs_delta; - int slice_type; //!< slice type - int model_number; //!< cabac model number - unsigned int frame_num; //frame_num for this frame - unsigned int field_pic_flag; - byte bottom_field_flag; - PictureStructure structure; //!< Identify picture structure type - int start_mb_nr; //!< MUST be set by NAL even in case of ei_flag == 1 - int end_mb_nr_plus1; - int max_part_nr; - int dp_mode; //!< data partitioning mode - int current_header; - int next_header; - int last_dquant; + int ei_flag; //!< 0 if the partArr[0] contains valid information + int qp; + int slice_qp_delta; + int qs; + int slice_qs_delta; + int slice_type; //!< slice type + int model_number; //!< cabac model number + unsigned int frame_num; // frame_num for this frame + unsigned int field_pic_flag; + byte bottom_field_flag; + PictureStructure structure; //!< Identify picture structure type + int start_mb_nr; //!< MUST be set by NAL even in case of ei_flag == 1 + int end_mb_nr_plus1; + int max_part_nr; + int dp_mode; //!< data partitioning mode + int current_header; + int next_header; + int last_dquant; - //slice header information; - int colour_plane_id; //!< colour_plane_id of the current coded slice + // slice header information; + int colour_plane_id; //!< colour_plane_id of the current coded slice int redundant_pic_cnt; - int sp_switch; //!< 1 for switching sp, 0 for normal sp + int sp_switch; //!< 1 for switching sp, 0 for normal sp int slice_group_change_cycle; - int redundant_slice_ref_idx; //!< reference index of redundant slice + int redundant_slice_ref_idx; //!< reference index of redundant slice int no_output_of_prior_pics_flag; int long_term_reference_flag; int adaptive_ref_pic_buffering_flag; - DecRefPicMarking_t *dec_ref_pic_marking_buffer; //!< stores the memory management control operations + DecRefPicMarking_t + *dec_ref_pic_marking_buffer; //!< stores the memory management control + //!< operations signed char listXsize[6]; struct storable_picture **listX[6]; - // int last_mb_nr; //!< only valid when entropy coding == CABAC - DataPartition *partArr; //!< array of partitions - MotionInfoContexts *mot_ctx; //!< pointer to struct of context models for use in CABAC - TextureInfoContexts *tex_ctx; //!< pointer to struct of context models for use in CABAC + // int last_mb_nr; //!< only valid when entropy coding == + // CABAC + DataPartition *partArr; //!< array of partitions + MotionInfoContexts + *mot_ctx; //!< pointer to struct of context models for use in CABAC + TextureInfoContexts + *tex_ctx; //!< pointer to struct of context models for use in CABAC int mvscale[6][MAX_REFERENCE_PICTURES]; - int ref_pic_list_reordering_flag[2]; - int *reordering_of_pic_nums_idc[2]; - int *abs_diff_pic_num_minus1[2]; - int *long_term_pic_idx[2]; + int ref_pic_list_reordering_flag[2]; + int *reordering_of_pic_nums_idc[2]; + int *abs_diff_pic_num_minus1[2]; + int *long_term_pic_idx[2]; #if (MVC_EXTENSION_ENABLE) - int *abs_diff_view_idx_minus1[2]; + int *abs_diff_view_idx_minus1[2]; - int view_id; - int inter_view_flag; - int anchor_pic_flag; + int view_id; + int inter_view_flag; + int anchor_pic_flag; NALUnitHeaderMVCExt_t NaluHeaderMVCExt; #endif - short DFDisableIdc; //!< Disable deblocking filter on slice - short DFAlphaC0Offset; //!< Alpha and C0 offset for filtering slice - short DFBetaOffset; //!< Beta offset for filtering slice + short DFDisableIdc; //!< Disable deblocking filter on slice + short DFAlphaC0Offset; //!< Alpha and C0 offset for filtering slice + short DFBetaOffset; //!< Beta offset for filtering slice - int pic_parameter_set_id; //!=0 multiview[VIEW1|VIEW0]; +typedef struct decodedpic_t { + int bValid; // 0: invalid, 1: valid, 3: valid for 3D output; + int iViewId; //-1: single view, >=0 multiview[VIEW1|VIEW0]; int iPOC; - int iYUVFormat; //0: 4:0:0, 1: 4:2:0, 2: 4:2:2, 3: 4:4:4 - int iYUVStorageFormat; //0: YUV seperate; 1: YUV interleaved; 2: 3D output; + int iYUVFormat; // 0: 4:0:0, 1: 4:2:0, 2: 4:2:2, 3: 4:4:4 + int iYUVStorageFormat; // 0: YUV seperate; 1: YUV interleaved; 2: 3D output; int iBitDepth; - byte *pY; //if iPictureFormat is 1, [0]: top; [1] bottom; + byte *pY; // if iPictureFormat is 1, [0]: top; [1] bottom; byte *pU; byte *pV; - int iWidth; //frame width; - int iHeight; //frame height; - int iYBufStride; //stride of pY[0/1] buffer in bytes; - int iUVBufStride; //stride of pU[0/1] and pV[0/1] buffer in bytes; + int iWidth; // frame width; + int iHeight; // frame height; + int iYBufStride; // stride of pY[0/1] buffer in bytes; + int iUVBufStride; // stride of pU[0/1] and pV[0/1] buffer in bytes; int iSkipPicNum; struct decodedpic_t *pNext; } DecodedPicList; @@ -563,9 +566,8 @@ typedef struct decodedpic_t //****************************** ~DM *********************************** // video parameters -typedef struct video_par -{ - struct inp_par *p_Inp; +typedef struct video_par { + struct inp_par *p_Inp; pic_parameter_set_rbsp_t *active_pps; seq_parameter_set_rbsp_t *active_sps; seq_parameter_set_rbsp_t SeqParSet[MAXSPS]; @@ -573,7 +575,7 @@ typedef struct video_par #if (MVC_EXTENSION_ENABLE) subset_seq_parameter_set_rbsp_t *active_subset_sps; - //int svc_extension_flag; + // int svc_extension_flag; subset_seq_parameter_set_rbsp_t SubsetSeqParSet[MAXSPS]; int last_pic_width_in_mbs_minus1; int last_pic_height_in_map_units_minus1; @@ -581,43 +583,48 @@ typedef struct video_par int last_profile_idc; #endif - struct sei_params *p_SEI; + struct sei_params *p_SEI; struct old_slice_par *old_slice; - struct snr_par *snr; - int number; //!< frame number - - //current picture property; + struct snr_par *snr; + int number; //!< frame number + + // current picture property; unsigned int num_dec_mb; int iSliceNumOfCurrPic; int iNumOfSlicesAllocated; int iNumOfSlicesDecoded; Slice **ppSliceList; - signed char *intra_block; - signed char *intra_block_JV[MAX_PLANE]; - //int qp; //!< quant for the current frame + signed char *intra_block; + signed char *intra_block_JV[MAX_PLANE]; + // int qp; //!< quant for the current + // frame - //int sp_switch; //!< 1 for switching sp, 0 for normal sp - int type; //!< image type INTER/INTRA + // int sp_switch; //!< 1 for switching sp, 0 for + // normal sp + int type; //!< image type INTER/INTRA int width; int height; - int width_cr; //!< width chroma - int height_cr; //!< height chroma + int width_cr; //!< width chroma + int height_cr; //!< height chroma - byte **ipredmode; //!< prediction type [90][74] + byte **ipredmode; //!< prediction type [90][74] byte **ipredmode_JV[MAX_PLANE]; byte ****nz_coeff; int **siblock; int **siblock_JV[MAX_PLANE]; int newframe; - int structure; //!< Identify picture structure type + int structure; //!< Identify picture structure type - //Slice *currentSlice; //!< pointer to current Slice data struct - Slice *pNextSlice; //!< pointer to first Slice of next picture; - Macroblock *mb_data; //!< array containing all MBs of a whole frame - Macroblock *mb_data_JV[MAX_PLANE]; //!< mb_data to be used for 4:4:4 independent mode - //int colour_plane_id; //!< colour_plane_id of the current coded slice + // Slice *currentSlice; //!< pointer to current Slice data + // struct + Slice *pNextSlice; //!< pointer to first Slice of next picture; + Macroblock *mb_data; //!< array containing all MBs of a whole frame + Macroblock + *mb_data_JV[MAX_PLANE]; //!< mb_data to be used for 4:4:4 independent mode + // int colour_plane_id; //!< colour_plane_id of the current + // coded slice int ChromaArrayType; // picture error concealment @@ -626,16 +633,18 @@ typedef struct video_par struct concealment_node *concealment_head; struct concealment_node *concealment_end; - unsigned int pre_frame_num; //!< store the frame_num in the last decoded slice. For detecting gap in frame_num. + unsigned int pre_frame_num; //!< store the frame_num in the last decoded + //!< slice. For detecting gap in frame_num. int non_conforming_stream; // //////////////////////// // for POC mode 0: - signed int PrevPicOrderCntMsb; + signed int PrevPicOrderCntMsb; unsigned int PrevPicOrderCntLsb; // for POC mode 1: - signed int ExpectedPicOrderCnt, PicOrderCntCycleCnt, FrameNumInPicOrderCntCycle; + signed int ExpectedPicOrderCnt, PicOrderCntCycleCnt, + FrameNumInPicOrderCntCycle; unsigned int PreviousFrameNum, FrameNumOffset; int ExpectedDeltaPerPicOrderCntCycle; int ThisPOC; @@ -664,8 +673,12 @@ typedef struct video_par int bitdepth_scale[2]; int bitdepth_luma_qp_scale; int bitdepth_chroma_qp_scale; - unsigned int dc_pred_value_comp[MAX_PLANE]; //!< component value for DC prediction (depends on component pel bit depth) - int max_pel_value_comp[MAX_PLANE]; //!< max value that one picture element (pixel) can take (depends on pic_unit_bitdepth) + unsigned int + dc_pred_value_comp[MAX_PLANE]; //!< component value for DC prediction + //!< (depends on component pel bit depth) + int max_pel_value_comp[MAX_PLANE]; //!< max value that one picture element + //!< (pixel) can take (depends on + //!< pic_unit_bitdepth) int profile_idc; int yuv_format; @@ -677,8 +690,8 @@ typedef struct video_par int mb_cr_size_y; int mb_cr_size_x_blk; int mb_cr_size_y_blk; - int mb_size[3][2]; //!< component macroblock dimensions - int mb_size_blk[3][2]; //!< component macroblock dimensions + int mb_size[3][2]; //!< component macroblock dimensions + int mb_size_blk[3][2]; //!< component macroblock dimensions int mb_size_shift[3][2]; int subpel_x; int subpel_y; @@ -686,8 +699,10 @@ typedef struct video_par int shiftpel_y; int total_scale; - int max_vmv_r; //!< maximum vertical motion vector range in luma quarter frame pixel units for the current level_idc - //int max_mb_vmv_r; //!< maximum vertical motion vector range in luma quarter pixel units for the current level_idc + int max_vmv_r; //!< maximum vertical motion vector range in luma quarter frame + //!< pixel units for the current level_idc + // int max_mb_vmv_r; //!< maximum vertical motion + // vector range in luma quarter pixel units for the current level_idc int idr_psnr_number; int psnr_number; @@ -719,47 +734,47 @@ typedef struct video_par byte *buf; byte *ibuf; - ImageData imgData; //!< Image data to be encoded (dummy variable for now) - ImageData imgData0; //!< base layer input - ImageData imgData1; //!< temp buffer for left de-muxed view - ImageData imgData2; //!< temp buffer for right de-muxed view + ImageData imgData; //!< Image data to be encoded (dummy variable for now) + ImageData imgData0; //!< base layer input + ImageData imgData1; //!< temp buffer for left de-muxed view + ImageData imgData2; //!< temp buffer for right de-muxed view // Data needed for 3:2 pulldown or temporal interleaving - ImageData imgData32; //!< Image data to be encoded + ImageData imgData32; //!< Image data to be encoded ImageData imgData4; ImageData imgData5; ImageData imgData6; - - // Redundant slices. Should be moved to another structure and allocated only if extended profile + // Redundant slices. Should be moved to another structure and allocated only + // if extended profile unsigned int previous_frame_num; //!< frame number of previous slice //!< non-zero: i-th previous frame is correct - int Is_primary_correct; //!< if primary frame is correct, 0: incorrect - int Is_redundant_correct; //!< if redundant frame is correct, 0:incorrect + int Is_primary_correct; //!< if primary frame is correct, 0: incorrect + int Is_redundant_correct; //!< if redundant frame is correct, 0:incorrect - // Time + // Time int64 tot_time; - - // files - int p_out; //!< file descriptor to output YUV file -#if (MVC_EXTENSION_ENABLE) - int p_out_mvc[MAX_VIEW_NUM]; //!< file descriptor to output YUV file for MVC -#endif - int p_ref; //!< pointer to input original reference YUV file file - //FILE *p_log; //!< SNR file + // files + int p_out; //!< file descriptor to output YUV file +#if (MVC_EXTENSION_ENABLE) + int p_out_mvc[MAX_VIEW_NUM]; //!< file descriptor to output YUV file for MVC +#endif + int p_ref; //!< pointer to input original reference YUV file file + + // FILE *p_log; //!< SNR file int LastAccessUnitExists; int NALUCount; // B pictures - int Bframe_ctr; - int frame_no; + int Bframe_ctr; + int frame_no; - int g_nFrame; + int g_nFrame; Boolean global_init_done; // global picture format dependent buffers, memory allocation in decod.c - imgpel **imgY_ref; //!< reference frame find snr + imgpel **imgY_ref; //!< reference frame find snr imgpel ***imgUV_ref; int *qp_per_matrix; @@ -769,16 +784,19 @@ typedef struct video_par int pocs_in_dpb[100]; struct storable_picture *dec_picture; - struct storable_picture *dec_picture_JV[MAX_PLANE]; //!< dec_picture to be used during 4:4:4 independent mode decoding - struct storable_picture *no_reference_picture; //!< dummy storable picture for recovery point + struct storable_picture + *dec_picture_JV[MAX_PLANE]; //!< dec_picture to be used during 4:4:4 + //!< independent mode decoding + struct storable_picture + *no_reference_picture; //!< dummy storable picture for recovery point // Error parameters - struct object_buffer *erc_object_list; + struct object_buffer *erc_object_list; struct ercVariables_s *erc_errorVar; int erc_mvperMB; struct video_par *erc_img; - int ec_flag[SE_MAX_ELEMENTS]; //!< array to set errorconcealment + int ec_flag[SE_MAX_ELEMENTS]; //!< array to set errorconcealment struct annex_b_struct *annex_b; struct sBitsFile *bitsfile; @@ -786,46 +804,61 @@ typedef struct video_par struct frame_store *out_buffer; struct storable_picture *pending_output; - int pending_output_state; - int recovery_flag; + int pending_output_state; + int recovery_flag; int BitStreamFile; // dpb struct decoded_picture_buffer *p_Dpb; - struct decoded_picture_buffer *p_Dpb_legacy; // This is the old JM dpb method and will be removed at some point + struct decoded_picture_buffer + *p_Dpb_legacy; // This is the old JM dpb method and will be removed at + // some point struct decoded_picture_buffer *p_Dpb_layer[2]; - // report - char cslice_type[9]; + char cslice_type[9]; // FMO int *MbToSliceGroupMap; int *MapUnitToSliceGroupMap; - int NumberOfSliceGroups; // the number of slice groups -1 (0 == scan order, 7 == maximum) + int NumberOfSliceGroups; // the number of slice groups -1 (0 == scan order, 7 + // == maximum) #if (ENABLE_OUTPUT_TONEMAPPING) struct tone_mapping_struct_s *seiToneMapping; #endif - void (*buf2img) (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int o_size_x, int o_size_y, int symbol_size_in_bytes, int bitshift); - void (*getNeighbour) (Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix); - void (*get_mb_block_pos) (int mb_addr, short *x, short *y); - void (*GetStrengthVer) (byte Strength[16], Macroblock *MbQ, int edge, int mvlimit, struct storable_picture *p); - void (*GetStrengthHor) (byte Strength[16], Macroblock *MbQ, int edge, int mvlimit, struct storable_picture *p); - void (*EdgeLoopLumaVer) (ColorPlane pl, imgpel** Img, byte Strength[16], Macroblock *MbQ, int edge, struct storable_picture *p); - void (*EdgeLoopLumaHor) (ColorPlane pl, imgpel** Img, byte Strength[16], Macroblock *MbQ, int edge, struct storable_picture *p); - void (*EdgeLoopChromaVer)(imgpel** Img, byte Strength[16], Macroblock *MbQ, int edge, int uv, struct storable_picture *p); - void (*EdgeLoopChromaHor)(imgpel** Img, byte Strength[16], Macroblock *MbQ, int edge, int uv, struct storable_picture *p); - void (*img2buf) (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int symbol_size_in_bytes, int crop_left, int crop_right, int crop_top, int crop_bottom, int iOutStride); + void (*buf2img)(imgpel **imgX, unsigned char *buf, int size_x, int size_y, + int o_size_x, int o_size_y, int symbol_size_in_bytes, + int bitshift); + void (*getNeighbour)(Macroblock *currMB, int xN, int yN, int mb_size[2], + PixelPos *pix); + void (*get_mb_block_pos)(int mb_addr, short *x, short *y); + void (*GetStrengthVer)(byte Strength[16], Macroblock *MbQ, int edge, + int mvlimit, struct storable_picture *p); + void (*GetStrengthHor)(byte Strength[16], Macroblock *MbQ, int edge, + int mvlimit, struct storable_picture *p); + void (*EdgeLoopLumaVer)(ColorPlane pl, imgpel **Img, byte Strength[16], + Macroblock *MbQ, int edge, + struct storable_picture *p); + void (*EdgeLoopLumaHor)(ColorPlane pl, imgpel **Img, byte Strength[16], + Macroblock *MbQ, int edge, + struct storable_picture *p); + void (*EdgeLoopChromaVer)(imgpel **Img, byte Strength[16], Macroblock *MbQ, + int edge, int uv, struct storable_picture *p); + void (*EdgeLoopChromaHor)(imgpel **Img, byte Strength[16], Macroblock *MbQ, + int edge, int uv, struct storable_picture *p); + void (*img2buf)(imgpel **imgX, unsigned char *buf, int size_x, int size_y, + int symbol_size_in_bytes, int crop_left, int crop_right, + int crop_top, int crop_bottom, int iOutStride); DecodedPicList *pDecOuputPic; - int iDeblockMode; //0: deblock in picture, 1: deblock in slice; + int iDeblockMode; // 0: deblock in picture, 1: deblock in slice; struct nalu_t *nalu; int iLumaPadX; int iLumaPadY; int iChromaPadX; int iChromaPadY; - //control; + // control; int bDeblockEnable; int iPostProcess; int bFrameInit; @@ -836,48 +869,49 @@ typedef struct video_par } VideoParameters; // signal to noise ratio parameters -typedef struct snr_par -{ - int frame_ctr; - float snr[3]; //!< current SNR (component) - float snr1[3]; //!< SNR (dB) first frame (component) - float snra[3]; //!< Average component SNR (dB) remaining frames - float sse[3]; //!< component SSE - float msse[3]; //!< Average component SSE +typedef struct snr_par { + int frame_ctr; + float snr[3]; //!< current SNR (component) + float snr1[3]; //!< SNR (dB) first frame (component) + float snra[3]; //!< Average component SNR (dB) remaining frames + float sse[3]; //!< component SSE + float msse[3]; //!< Average component SSE } SNRParameters; // input parameters from configuration file -typedef struct inp_par -{ - char infile[FILE_NAME_SIZE]; //!< H.264 inputfile - char outfile[FILE_NAME_SIZE]; //!< Decoded YUV 4:2:0 output - char reffile[FILE_NAME_SIZE]; //!< Optional YUV 4:2:0 reference file for SNR measurement +typedef struct inp_par { + char infile[FILE_NAME_SIZE]; //!< H.264 inputfile + char outfile[FILE_NAME_SIZE]; //!< Decoded YUV 4:2:0 output + char reffile[FILE_NAME_SIZE]; //!< Optional YUV 4:2:0 reference file for SNR + //!< measurement - int FileFormat; //!< File format of the Input file, PAR_OF_ANNEXB or PAR_OF_RTP + int FileFormat; //!< File format of the Input file, PAR_OF_ANNEXB or + //!< PAR_OF_RTP int ref_offset; int poc_scale; int write_uv; int silent; - int intra_profile_deblocking; //!< Loop filter usage determined by flags and parameters in bitstream + int intra_profile_deblocking; //!< Loop filter usage determined by flags and + //!< parameters in bitstream // Input/output sequence format related variables - FrameFormat source; //!< source related information - FrameFormat output; //!< output related information + FrameFormat source; //!< source related information + FrameFormat output; //!< output related information - int ProcessInput; - int enable_32_pulldown; - VideoDataFile input_file1; //!< Input video file1 - VideoDataFile input_file2; //!< Input video file2 - VideoDataFile input_file3; //!< Input video file3 + int ProcessInput; + int enable_32_pulldown; + VideoDataFile input_file1; //!< Input video file1 + VideoDataFile input_file2; //!< Input video file2 + VideoDataFile input_file3; //!< Input video file3 #if (MVC_EXTENSION_ENABLE) - int DecodeAllLayers; + int DecodeAllLayers; #endif #ifdef _LEAKYBUCKET_ - unsigned long R_decoder; //!< Decoder Rate in HRD Model - unsigned long B_decoder; //!< Decoder Buffer size in HRD model - unsigned long F_decoder; //!< Decoder Initial buffer fullness in HRD model - char LeakyBucketParamFile[FILE_NAME_SIZE]; //!< LeakyBucketParamFile + unsigned long R_decoder; //!< Decoder Rate in HRD Model + unsigned long B_decoder; //!< Decoder Buffer size in HRD model + unsigned long F_decoder; //!< Decoder Initial buffer fullness in HRD model + char LeakyBucketParamFile[FILE_NAME_SIZE]; //!< LeakyBucketParamFile #endif // picture error concealment @@ -885,88 +919,87 @@ typedef struct inp_par int ref_poc_gap; int poc_gap; - // dummy for encoder int start_frame; - // Needed to allow compilation for decoder. May be used later for distortion computation operations - int stdRange; //!< 1 - standard range, 0 - full range - int videoCode; //!< 1 - 709, 3 - 601: See VideoCode in io_tiff. + // Needed to allow compilation for decoder. May be used later for distortion + // computation operations + int stdRange; //!< 1 - standard range, 0 - full range + int videoCode; //!< 1 - 709, 3 - 601: See VideoCode in io_tiff. int export_views; - + int iDecFrmNum; int bDisplayDecParams; } InputParameters; -typedef struct old_slice_par -{ - unsigned field_pic_flag; - unsigned frame_num; - int nal_ref_idc; - unsigned pic_oder_cnt_lsb; - int delta_pic_oder_cnt_bottom; - int delta_pic_order_cnt[2]; - byte bottom_field_flag; - byte idr_flag; - int idr_pic_id; - int pps_id; +typedef struct old_slice_par { + unsigned field_pic_flag; + unsigned frame_num; + int nal_ref_idc; + unsigned pic_oder_cnt_lsb; + int delta_pic_oder_cnt_bottom; + int delta_pic_order_cnt[2]; + byte bottom_field_flag; + byte idr_flag; + int idr_pic_id; + int pps_id; #if (MVC_EXTENSION_ENABLE) - int view_id; - int inter_view_flag; - int anchor_pic_flag; + int view_id; + int inter_view_flag; + int anchor_pic_flag; #endif } OldSliceParams; -typedef struct decoder_params -{ - InputParameters *p_Inp; //!< Input Parameters - VideoParameters *p_Vid; //!< Image Parameters - int64 bufferSize; //!< buffersize for tiff reads (not currently supported) - int UsedBits; // for internal statistics, is adjusted by se_v, ue_v, u_1 - FILE *p_trace; //!< Trace file - int bitcounter; +typedef struct decoder_params { + InputParameters *p_Inp; //!< Input Parameters + VideoParameters *p_Vid; //!< Image Parameters + int64 bufferSize; //!< buffersize for tiff reads (not currently supported) + int UsedBits; // for internal statistics, is adjusted by se_v, ue_v, u_1 + FILE *p_trace; //!< Trace file + int bitcounter; } DecoderParams; -typedef struct threadparameter -{ +typedef struct threadparameter { DecoderParams *pDecoder; int iThreadIdx; -}ThreadParam_t; +} ThreadParam_t; -extern DecoderParams *p_Dec; +extern DecoderParams *p_Dec; // prototypes extern void error(char *text, int code); // dynamic mem allocation -extern int init_global_buffers( VideoParameters *p_Vid ); -extern void free_global_buffers( VideoParameters *p_Vid ); +extern int init_global_buffers(VideoParameters *p_Vid); +extern void free_global_buffers(VideoParameters *p_Vid); extern int RBSPtoSODB(byte *streamBuffer, int last_byte_pos); extern int EBSPtoRBSP(byte *streamBuffer, int end_bytepos, int begin_bytepos); -extern void FreePartition (DataPartition *dp, int n); +extern void FreePartition(DataPartition *dp, int n); extern DataPartition *AllocPartition(int n); -extern void tracebits (const char *trace_str, int len, int info, int value1); +extern void tracebits(const char *trace_str, int len, int info, int value1); extern void tracebits2(const char *trace_str, int len, int info); -extern unsigned CeilLog2 ( unsigned uiVal); -extern unsigned CeilLog2_sf( unsigned uiVal); +extern unsigned CeilLog2(unsigned uiVal); +extern unsigned CeilLog2_sf(unsigned uiVal); // For 4:4:4 independent mode -extern void change_plane_JV ( VideoParameters *p_Vid, int nplane, Slice *pSlice); -extern void make_frame_picture_JV( VideoParameters *p_Vid ); +extern void change_plane_JV(VideoParameters *p_Vid, int nplane, Slice *pSlice); +extern void make_frame_picture_JV(VideoParameters *p_Vid); #if (MVC_EXTENSION_ENABLE) -extern void nal_unit_header_mvc_extension(NALUnitHeaderMVCExt_t *NaluHeaderMVCExt, struct bit_stream *bitstream); +extern void +nal_unit_header_mvc_extension(NALUnitHeaderMVCExt_t *NaluHeaderMVCExt, + struct bit_stream *bitstream); #endif -extern void FreeDecPicList ( DecodedPicList *pDecPicList ); -extern void ClearDecPicList( VideoParameters *p_Vid ); -extern DecodedPicList *GetOneAvailDecPicFromList(DecodedPicList *pDecPicList, int b3D); -extern Slice *malloc_slice( InputParameters *p_Inp, VideoParameters *p_Vid ); -extern void CopySliceInfo ( Slice *currSlice, OldSliceParams *p_old_slice ); +extern void FreeDecPicList(DecodedPicList *pDecPicList); +extern void ClearDecPicList(VideoParameters *p_Vid); +extern DecodedPicList *GetOneAvailDecPicFromList(DecodedPicList *pDecPicList, + int b3D); +extern Slice *malloc_slice(InputParameters *p_Inp, VideoParameters *p_Vid); +extern void CopySliceInfo(Slice *currSlice, OldSliceParams *p_old_slice); #endif - diff --git a/src/common/ldecod_src/inc/h264decoder.h b/src/common/ldecod_src/inc/h264decoder.h index 09f4eed..45c8154 100644 --- a/src/common/ldecod_src/inc/h264decoder.h +++ b/src/common/ldecod_src/inc/h264decoder.h @@ -8,7 +8,7 @@ * \author * Copyright (C) 2009 Dolby * Yuwen He (yhe@dolby.com) - * + * ************************************************************************ */ #ifndef _H264DECODER_H_ @@ -16,26 +16,24 @@ #include "global.h" -typedef enum -{ +typedef enum { DEC_GEN_NOERR = 0, DEC_OPEN_NOERR = 0, - DEC_CLOSE_NOERR = 0, + DEC_CLOSE_NOERR = 0, DEC_SUCCEED = 0, - DEC_EOS =1, + DEC_EOS = 1, DEC_NEED_DATA = 2, DEC_INVALID_PARAM = 3, DEC_ERRMASK = 0x8000 -// DEC_ERRMASK = 0x80000000 -}DecErrCode; + // DEC_ERRMASK = 0x80000000 +} DecErrCode; -typedef struct dec_set_t -{ +typedef struct dec_set_t { int iPostprocLevel; // valid interval are [0..100] int bDBEnable; int bAllLayers; int time_incr; - int bDecCompAdapt; + int bDecCompAdapt; } DecSet_t; #ifdef __cplusplus diff --git a/src/common/ldecod_src/inc/header.h b/src/common/ldecod_src/inc/header.h index d7269b1..1543828 100644 --- a/src/common/ldecod_src/inc/header.h +++ b/src/common/ldecod_src/inc/header.h @@ -11,12 +11,12 @@ #define _HEADER_H_ extern int FirstPartOfSliceHeader(Slice *currSlice); -extern int RestOfSliceHeader (Slice *currSlice); +extern int RestOfSliceHeader(Slice *currSlice); -extern void dec_ref_pic_marking(VideoParameters *p_Vid, Bitstream *currStream, Slice *pSlice); +extern void dec_ref_pic_marking(VideoParameters *p_Vid, Bitstream *currStream, + Slice *pSlice); extern void decode_poc(VideoParameters *p_Vid, Slice *pSlice); -extern int dumppoc (VideoParameters *p_Vid); +extern int dumppoc(VideoParameters *p_Vid); #endif - diff --git a/src/common/ldecod_src/inc/ifunctions.h b/src/common/ldecod_src/inc/ifunctions.h index 9f20dac..219d1cb 100644 --- a/src/common/ldecod_src/inc/ifunctions.h +++ b/src/common/ldecod_src/inc/ifunctions.h @@ -8,7 +8,8 @@ * define some inline functions that are used within the encoder. * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Karsten Shring * - Alexis Tourapis * @@ -19,308 +20,296 @@ #if !defined(SPEC) // For SPEC CPU always use static inline -# if !(defined(WIN32) || defined(WIN64)) && (__STDC_VERSION__ < 199901L) - #define static - #define inline +#if !(defined(WIN32) || defined(WIN64)) && (__STDC_VERSION__ < 199901L) +#define static +#define inline #endif #endif -#include #include +#include - -static inline short smin(short a, short b) -{ - return (short) (((a) < (b)) ? (a) : (b)); +static inline short smin(short a, short b) { + return (short)(((a) < (b)) ? (a) : (b)); } -static inline short smax(short a, short b) -{ - return (short) (((a) > (b)) ? (a) : (b)); +static inline short smax(short a, short b) { + return (short)(((a) > (b)) ? (a) : (b)); } -static inline int imin(int a, int b) -{ - return ((a) < (b)) ? (a) : (b); -} +static inline int imin(int a, int b) { return ((a) < (b)) ? (a) : (b); } -static inline int imax(int a, int b) -{ - return ((a) > (b)) ? (a) : (b); -} +static inline int imax(int a, int b) { return ((a) > (b)) ? (a) : (b); } -static inline int imedian(int a,int b,int c) -{ +static inline int imedian(int a, int b, int c) { if (a > b) // a > b - { - if (b > c) - return(b); // a > b > c - else if (a > c) - return(c); // a > c > b - else - return(a); // c > a > b - } - else // b > a - { - if (a > c) - return(a); // b > a > c - else if (b > c) - return(c); // b > c > a + { + if (b > c) + return (b); // a > b > c + else if (a > c) + return (c); // a > c > b else - return(b); // c > b > a + return (a); // c > a > b + } else // b > a + { + if (a > c) + return (a); // b > a > c + else if (b > c) + return (c); // b > c > a + else + return (b); // c > b > a } } -static inline int imedian_old(int a, int b, int c) -{ - return (a + b + c - imin(a, imin(b, c)) - imax(a, imax(b ,c))); +static inline int imedian_old(int a, int b, int c) { + return (a + b + c - imin(a, imin(b, c)) - imax(a, imax(b, c))); } -static inline double dmin(double a, double b) -{ +static inline double dmin(double a, double b) { return ((a) < (b)) ? (a) : (b); } -static inline double dmax(double a, double b) -{ +static inline double dmax(double a, double b) { return ((a) > (b)) ? (a) : (b); } -static inline int64 i64min(int64 a, int64 b) -{ +static inline int64 i64min(int64 a, int64 b) { return ((a) < (b)) ? (a) : (b); } + +static inline int64 i64max(int64 a, int64 b) { return ((a) > (b)) ? (a) : (b); } + +static inline distblk distblkmin(distblk a, distblk b) { return ((a) < (b)) ? (a) : (b); } -static inline int64 i64max(int64 a, int64 b) -{ +static inline distblk distblkmax(distblk a, distblk b) { return ((a) > (b)) ? (a) : (b); } -static inline distblk distblkmin(distblk a, distblk b) -{ - return ((a) < (b)) ? (a) : (b); -} - -static inline distblk distblkmax(distblk a, distblk b) -{ - return ((a) > (b)) ? (a) : (b); -} - -static inline short sabs(short x) -{ +static inline short sabs(short x) { static const short SHORT_BITS = (sizeof(short) * CHAR_BIT) - 1; - short y = (short) (x >> SHORT_BITS); - return (short) ((x ^ y) - y); + short y = (short)(x >> SHORT_BITS); + return (short)((x ^ y) - y); } -static inline int iabs(int x) -{ +static inline int iabs(int x) { static const int INT_BITS = (sizeof(int) * CHAR_BIT) - 1; int y = x >> INT_BITS; return (x ^ y) - y; } -static inline double dabs(double x) -{ - return ((x) < 0) ? -(x) : (x); -} +static inline double dabs(double x) { return ((x) < 0) ? -(x) : (x); } -static inline int64 i64abs(int64 x) -{ +static inline int64 i64abs(int64 x) { static const int64 INT64_BITS = (sizeof(int64) * CHAR_BIT) - 1; int64 y = x >> INT64_BITS; return (x ^ y) - y; } -static inline double dabs2(double x) -{ - return (x) * (x); -} +static inline double dabs2(double x) { return (x) * (x); } -static inline int iabs2(int x) -{ - return (x) * (x); -} +static inline int iabs2(int x) { return (x) * (x); } -static inline int64 i64abs2(int64 x) -{ - return (x) * (x); -} +static inline int64 i64abs2(int64 x) { return (x) * (x); } -static inline int isign(int x) -{ - return ( (x > 0) - (x < 0)); -} +static inline int isign(int x) { return ((x > 0) - (x < 0)); } -static inline int isignab(int a, int b) -{ +static inline int isignab(int a, int b) { return ((b) < 0) ? -iabs(a) : iabs(a); } -static inline int rshift_rnd(int x, int a) -{ - return (a > 0) ? ((x + (1 << (a-1) )) >> a) : (x << (-a)); +static inline int rshift_rnd(int x, int a) { + return (a > 0) ? ((x + (1 << (a - 1))) >> a) : (x << (-a)); } -static inline int rshift_rnd_sign(int x, int a) -{ - return (x > 0) ? ( ( x + (1 << (a-1)) ) >> a ) : (-( ( iabs(x) + (1 << (a-1)) ) >> a )); +static inline int rshift_rnd_sign(int x, int a) { + return (x > 0) ? ((x + (1 << (a - 1))) >> a) + : (-((iabs(x) + (1 << (a - 1))) >> a)); } -static inline unsigned int rshift_rnd_us(unsigned int x, unsigned int a) -{ - return (a > 0) ? ((x + (1 << (a-1))) >> a) : x; +static inline unsigned int rshift_rnd_us(unsigned int x, unsigned int a) { + return (a > 0) ? ((x + (1 << (a - 1))) >> a) : x; } -static inline int rshift_rnd_sf(int x, int a) -{ - return ((x + (1 << (a-1) )) >> a); +static inline int rshift_rnd_sf(int x, int a) { + return ((x + (1 << (a - 1))) >> a); } -static inline int shift_off_sf(int x, int o, int a) -{ - return ((x + o) >> a); +static inline int shift_off_sf(int x, int o, int a) { return ((x + o) >> a); } + +static inline unsigned int rshift_rnd_us_sf(unsigned int x, unsigned int a) { + return ((x + (1 << (a - 1))) >> a); } -static inline unsigned int rshift_rnd_us_sf(unsigned int x, unsigned int a) -{ - return ((x + (1 << (a-1))) >> a); -} - -static inline int iClip1(int high, int x) -{ +static inline int iClip1(int high, int x) { x = imax(x, 0); x = imin(x, high); return x; } -static inline int iClip3(int low, int high, int x) -{ +static inline int iClip3(int low, int high, int x) { x = imax(x, low); x = imin(x, high); return x; } -static inline short sClip3(short low, short high, short x) -{ +static inline short sClip3(short low, short high, short x) { x = smax(x, low); x = smin(x, high); return x; } -static inline double dClip3(double low, double high, double x) -{ +static inline double dClip3(double low, double high, double x) { x = dmax(x, low); x = dmin(x, high); return x; } - -static inline distblk weighted_cost(int factor, int bits) -{ +static inline distblk weighted_cost(int factor, int bits) { #if JCOST_CALC_SCALEUP - return (((distblk)(factor))*((distblk)(bits))); + return (((distblk)(factor)) * ((distblk)(bits))); #else #if (USE_RND_COST) return (rshift_rnd_sf((lambda) * (bits), LAMBDA_ACCURACY_BITS)); #else - return (((factor)*(bits))>>LAMBDA_ACCURACY_BITS); + return (((factor) * (bits)) >> LAMBDA_ACCURACY_BITS); #endif #endif } -static inline int RSD(int x) -{ - return ((x&2)?(x|1):(x&(~1))); -} +static inline int RSD(int x) { return ((x & 2) ? (x | 1) : (x & (~1))); } -static inline int power2(int x) -{ - return 1 << (x); -} +static inline int power2(int x) { return 1 << (x); } +static const uint64 po2[64] = {0x1, + 0x2, + 0x4, + 0x8, + 0x10, + 0x20, + 0x40, + 0x80, + 0x100, + 0x200, + 0x400, + 0x800, + 0x1000, + 0x2000, + 0x4000, + 0x8000, + 0x10000, + 0x20000, + 0x40000, + 0x80000, + 0x100000, + 0x200000, + 0x400000, + 0x800000, + 0x1000000, + 0x2000000, + 0x4000000, + 0x8000000, + 0x10000000, + 0x20000000, + 0x40000000, + 0x80000000, + 0x100000000, + 0x200000000, + 0x400000000, + 0x800000000, + 0x1000000000, + 0x2000000000, + 0x4000000000, + 0x8000000000, + 0x10000000000, + 0x20000000000, + 0x40000000000, + 0x80000000000, + 0x100000000000, + 0x200000000000, + 0x400000000000, + 0x800000000000, + 0x1000000000000, + 0x2000000000000, + 0x4000000000000, + 0x8000000000000, + 0x10000000000000, + 0x20000000000000, + 0x40000000000000, + 0x80000000000000, + 0x100000000000000, + 0x200000000000000, + 0x400000000000000, + 0x800000000000000, + 0x1000000000000000, + 0x2000000000000000, + 0x4000000000000000, + 0x8000000000000000}; -static const uint64 po2[64] = {0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000, - 0x10000,0x20000,0x40000,0x80000,0x100000,0x200000,0x400000,0x800000,0x1000000,0x2000000,0x4000000,0x8000000, - 0x10000000,0x20000000,0x40000000,0x80000000,0x100000000,0x200000000,0x400000000,0x800000000, - 0x1000000000,0x2000000000,0x4000000000,0x8000000000,0x10000000000,0x20000000000,0x40000000000,0x80000000000, - 0x100000000000,0x200000000000,0x400000000000,0x800000000000, - 0x1000000000000,0x2000000000000,0x4000000000000,0x8000000000000, - 0x10000000000000,0x20000000000000,0x40000000000000,0x80000000000000, - 0x100000000000000,0x200000000000000,0x400000000000000,0x800000000000000, - 0x1000000000000000,0x2000000000000000,0x4000000000000000,0x8000000000000000}; +static inline int64 i64_power2(int x) { return ((x > 63) ? 0 : po2[x]); } -static inline int64 i64_power2(int x) -{ - return((x > 63) ? 0 : po2[x]); -} - -static inline int float2int (float x) -{ +static inline int float2int(float x) { return (int)((x < 0) ? (x - 0.5f) : (x + 0.5f)); } -static inline int get_bit(int64 x,int n) -{ - return (int)(((x >> n) & 1)); -} +static inline int get_bit(int64 x, int n) { return (int)(((x >> n) & 1)); } #if ZEROSNR -static inline float psnr(int max_sample_sq, int samples, float sse_distortion ) -{ - return (float) (10.0 * log10(max_sample_sq * (double) ((double) samples / (sse_distortion < 1.0 ? 1.0 : sse_distortion)))); +static inline float psnr(int max_sample_sq, int samples, float sse_distortion) { + return ( + float)(10.0 * + log10(max_sample_sq * + (double)((double)samples / + (sse_distortion < 1.0 ? 1.0 : sse_distortion)))); } #else -static inline float psnr(int max_sample_sq, int samples, float sse_distortion ) -{ - return (float) (sse_distortion == 0.0 ? 0.0 : (10.0 * log10(max_sample_sq * (double) ((double) samples / sse_distortion)))); +static inline float psnr(int max_sample_sq, int samples, float sse_distortion) { + return ( + float)(sse_distortion == 0.0 + ? 0.0 + : (10.0 * log10(max_sample_sq * + (double)((double)samples / sse_distortion)))); } #endif -static inline int CheckCost_Shift(int64 mcost, int64 min_mcost) -{ - if((mcost<= min_mcost) +static inline int CheckCost_Shift(int64 mcost, int64 min_mcost) { + if ((mcost << LAMBDA_ACCURACY_BITS) >= min_mcost) return 1; else - return 0; + return 0; } -static inline int CheckCost(int64 mcost, int64 min_mcost) -{ +static inline int CheckCost(int64 mcost, int64 min_mcost) { return ((mcost) >= (min_mcost)); } -static inline void down_scale(distblk *pblkdistCost) -{ +static inline void down_scale(distblk *pblkdistCost) { #if JCOST_CALC_SCALEUP #if (IMGTYPE < 2) - *pblkdistCost = (*pblkdistCost)>>LAMBDA_ACCURACY_BITS; + *pblkdistCost = (*pblkdistCost) >> LAMBDA_ACCURACY_BITS; #else - *pblkdistCost = (*pblkdistCost)/(1<>LAMBDA_ACCURACY_BITS)); + return ((int)((blkdistCost) >> LAMBDA_ACCURACY_BITS)); #else - return ((int)(blkdistCost/((distblk) (1< ************************************************************************************* */ @@ -15,16 +16,16 @@ #ifndef _IMG_IO_H_ #define _IMG_IO_H_ -#include "io_video.h" #include "io_raw.h" #include "io_tiff.h" +#include "io_video.h" -extern int ParseSizeFromString (VideoDataFile *input_file, int *xlen, int *ylen, double *fps); -extern void ParseFrameNoFormatFromString (VideoDataFile *input_file); -extern void OpenFrameFile (VideoDataFile *input_file, int FrameNumberInFile); -extern void OpenFiles (VideoDataFile *input_file); -extern void CloseFiles (VideoDataFile *input_file); -extern VideoFileType ParseVideoType (VideoDataFile *input_file); +extern int ParseSizeFromString(VideoDataFile *input_file, int *xlen, int *ylen, + double *fps); +extern void ParseFrameNoFormatFromString(VideoDataFile *input_file); +extern void OpenFrameFile(VideoDataFile *input_file, int FrameNumberInFile); +extern void OpenFiles(VideoDataFile *input_file); +extern void CloseFiles(VideoDataFile *input_file); +extern VideoFileType ParseVideoType(VideoDataFile *input_file); #endif - diff --git a/src/common/ldecod_src/inc/img_process.h b/src/common/ldecod_src/inc/img_process.h index 062bef0..86c00c2 100644 --- a/src/common/ldecod_src/inc/img_process.h +++ b/src/common/ldecod_src/inc/img_process.h @@ -1,12 +1,13 @@ /*! - ************************************************************************ + ************************************************************************ * \file img_process.h * * \brief * Input data Image Processing functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Alexis Michael Tourapis * ************************************************************************ @@ -15,11 +16,8 @@ #ifndef _IMG_PROCESS_H_ #define _IMG_PROCESS_H_ - -extern int init_process_image ( VideoParameters *p_Vid, InputParameters *p_Inp ); -extern void clear_process_image( VideoParameters *p_Vid, InputParameters *p_Inp); -extern void process_image ( VideoParameters *p_Vid, InputParameters *p_Inp ); - - +extern int init_process_image(VideoParameters *p_Vid, InputParameters *p_Inp); +extern void clear_process_image(VideoParameters *p_Vid, InputParameters *p_Inp); +extern void process_image(VideoParameters *p_Vid, InputParameters *p_Inp); #endif diff --git a/src/common/ldecod_src/inc/img_process_types.h b/src/common/ldecod_src/inc/img_process_types.h index 4ac9ca7..5a32143 100644 --- a/src/common/ldecod_src/inc/img_process_types.h +++ b/src/common/ldecod_src/inc/img_process_types.h @@ -1,12 +1,13 @@ /*! - ************************************************************************ + ************************************************************************ * \file img_process_types.h * * \brief * Input data Image Processing Types * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Alexis Michael Tourapis * - Athanasios Leontaris * @@ -16,9 +17,9 @@ #ifndef _IMG_PROCESS_TYPES_H_ #define _IMG_PROCESS_TYPES_H_ -#define DEMUX_META_DEBUG 0 -#define MAX_NUM_PARTITIONS 32 -#define NUM_VIEWS 2 -#define NUM_COMPONENTS 3 +#define DEMUX_META_DEBUG 0 +#define MAX_NUM_PARTITIONS 32 +#define NUM_VIEWS 2 +#define NUM_COMPONENTS 3 #endif diff --git a/src/common/ldecod_src/inc/input.h b/src/common/ldecod_src/inc/input.h index f0a3cd9..7570e48 100644 --- a/src/common/ldecod_src/inc/input.h +++ b/src/common/ldecod_src/inc/input.h @@ -14,12 +14,18 @@ #define _INPUT_H_ extern int testEndian(void); -extern void initInput(VideoParameters *p_Vid, FrameFormat *source, FrameFormat *output); -extern void AllocateFrameMemory (VideoParameters *p_Vid, InputParameters *p_Inp, FrameFormat *source); -extern void DeleteFrameMemory (VideoParameters *p_Vid); +extern void initInput(VideoParameters *p_Vid, FrameFormat *source, + FrameFormat *output); +extern void AllocateFrameMemory(VideoParameters *p_Vid, InputParameters *p_Inp, + FrameFormat *source); +extern void DeleteFrameMemory(VideoParameters *p_Vid); -extern int read_one_frame (VideoParameters *p_Vid, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, FrameFormat *output, imgpel **pImage[3]); -extern void pad_borders ( FrameFormat output, int img_size_x, int img_size_y, int img_size_x_cr, int img_size_y_cr, imgpel **pImage[3]); +extern int read_one_frame(VideoParameters *p_Vid, VideoDataFile *input_file, + int FrameNoInFile, int HeaderSize, + FrameFormat *source, FrameFormat *output, + imgpel **pImage[3]); +extern void pad_borders(FrameFormat output, int img_size_x, int img_size_y, + int img_size_x_cr, int img_size_y_cr, + imgpel **pImage[3]); #endif - diff --git a/src/common/ldecod_src/inc/intra16x16_pred.h b/src/common/ldecod_src/inc/intra16x16_pred.h index 6680280..506b3fe 100644 --- a/src/common/ldecod_src/inc/intra16x16_pred.h +++ b/src/common/ldecod_src/inc/intra16x16_pred.h @@ -6,7 +6,7 @@ * definitions for intra 16x16 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * @@ -22,4 +22,3 @@ extern int intrapred16x16(Macroblock *currMB, ColorPlane pl, int b8); #endif - diff --git a/src/common/ldecod_src/inc/intra4x4_pred.h b/src/common/ldecod_src/inc/intra4x4_pred.h index a50c526..6c629dc 100644 --- a/src/common/ldecod_src/inc/intra4x4_pred.h +++ b/src/common/ldecod_src/inc/intra4x4_pred.h @@ -6,7 +6,7 @@ * definitions for intra 4x4 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * @@ -19,7 +19,7 @@ #include "global.h" #include "mbuffer.h" -extern int intrapred(Macroblock *currMB, ColorPlane pl, int ioff, int joff, int img_block_x, int img_block_y); +extern int intrapred(Macroblock *currMB, ColorPlane pl, int ioff, int joff, + int img_block_x, int img_block_y); #endif - diff --git a/src/common/ldecod_src/inc/intra8x8_pred.h b/src/common/ldecod_src/inc/intra8x8_pred.h index ff23846..c9ddcb2 100644 --- a/src/common/ldecod_src/inc/intra8x8_pred.h +++ b/src/common/ldecod_src/inc/intra8x8_pred.h @@ -6,7 +6,7 @@ * definitions for intra 8x8 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * @@ -22,4 +22,3 @@ extern int intrapred8x8(Macroblock *currMB, ColorPlane pl, int ioff, int joff); #endif - diff --git a/src/common/ldecod_src/inc/io_image.h b/src/common/ldecod_src/inc/io_image.h index a1706ff..b98a900 100644 --- a/src/common/ldecod_src/inc/io_image.h +++ b/src/common/ldecod_src/inc/io_image.h @@ -3,7 +3,7 @@ * \file io_image.h * * \brief - * Image I/O + * Image I/O * * \author * - Alexis Michael Tourapis @@ -17,20 +17,19 @@ #include "defines.h" #include "frame.h" -typedef struct image_data -{ - FrameFormat format; //!< image format +typedef struct image_data { + FrameFormat format; //!< image format // Standard data - imgpel **frm_data[MAX_PLANE]; //!< Frame Data - imgpel **top_data[MAX_PLANE]; //!< pointers to top field data - imgpel **bot_data[MAX_PLANE]; //!< pointers to bottom field data - + imgpel **frm_data[MAX_PLANE]; //!< Frame Data + imgpel **top_data[MAX_PLANE]; //!< pointers to top field data + imgpel **bot_data[MAX_PLANE]; //!< pointers to bottom field data + //! Optional data (could also add uint8 data in case imgpel is of type uint16) - //! These can be useful for enabling input/conversion of content of different types - //! while keeping optimal processing size. - uint16 **frm_uint16[MAX_PLANE]; //!< optional frame Data for uint16 - uint16 **top_uint16[MAX_PLANE]; //!< optional pointers to top field data - uint16 **bot_uint16[MAX_PLANE]; //!< optional pointers to bottom field data + //! These can be useful for enabling input/conversion of content of different + //! types while keeping optimal processing size. + uint16 **frm_uint16[MAX_PLANE]; //!< optional frame Data for uint16 + uint16 **top_uint16[MAX_PLANE]; //!< optional pointers to top field data + uint16 **bot_uint16[MAX_PLANE]; //!< optional pointers to bottom field data int frm_stride[MAX_PLANE]; int top_stride[MAX_PLANE]; @@ -38,4 +37,3 @@ typedef struct image_data } ImageData; #endif - diff --git a/src/common/ldecod_src/inc/io_raw.h b/src/common/ldecod_src/inc/io_raw.h index e476618..4ce01bc 100644 --- a/src/common/ldecod_src/inc/io_raw.h +++ b/src/common/ldecod_src/inc/io_raw.h @@ -15,8 +15,12 @@ #ifndef _IO_RAW_H_ #define _IO_RAW_H_ -extern int ReadFrameConcatenated (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf); -extern int ReadFrameSeparate (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf); +extern int ReadFrameConcatenated(InputParameters *p_Inp, + VideoDataFile *input_file, int FrameNoInFile, + int HeaderSize, FrameFormat *source, + unsigned char *buf); +extern int ReadFrameSeparate(InputParameters *p_Inp, VideoDataFile *input_file, + int FrameNoInFile, int HeaderSize, + FrameFormat *source, unsigned char *buf); #endif - diff --git a/src/common/ldecod_src/inc/io_tiff.h b/src/common/ldecod_src/inc/io_tiff.h index 4d1dd2d..ac7b6ee 100644 --- a/src/common/ldecod_src/inc/io_tiff.h +++ b/src/common/ldecod_src/inc/io_tiff.h @@ -18,7 +18,8 @@ // See TIFF 6.0 Specification // http://partners.adobe.com/public/developer/tiff/index.html - -extern int ReadTIFFImage (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, FrameFormat *source, unsigned char *buf); +extern int ReadTIFFImage(InputParameters *p_Inp, VideoDataFile *input_file, + int FrameNoInFile, FrameFormat *source, + unsigned char *buf); #endif diff --git a/src/common/ldecod_src/inc/io_video.h b/src/common/ldecod_src/inc/io_video.h index 732e8cf..9b9e174 100644 --- a/src/common/ldecod_src/inc/io_video.h +++ b/src/common/ldecod_src/inc/io_video.h @@ -3,7 +3,7 @@ * \file io_video.h * * \brief - * Video I/O + * Video I/O * * \author * - Alexis Michael Tourapis @@ -17,47 +17,47 @@ #include "frame.h" typedef struct video_size { - char* name; + char *name; int x_size; int y_size; } VIDEO_SIZE; typedef enum { VIDEO_UNKNOWN = -1, - VIDEO_YUV = 0, - VIDEO_RGB = 1, - VIDEO_XYZ = 2, - VIDEO_TIFF = 3, - VIDEO_AVI = 4 + VIDEO_YUV = 0, + VIDEO_RGB = 1, + VIDEO_XYZ = 2, + VIDEO_TIFF = 3, + VIDEO_AVI = 4 } VideoFileType; -typedef struct video_data_file -{ - //char* fname; //!< video file name - char fname[FILE_NAME_SIZE]; //!< video file name - char fhead[FILE_NAME_SIZE]; //!< header of video file - char ftail[FILE_NAME_SIZE]; //!< tail of video file - int f_num; //!< video file number - VideoFileType vdtype; //!< File format - FrameFormat format; //!< video format information - int is_concatenated; //!< Single or multifile input? - int is_interleaved; //!< Support for interleaved and non-interleaved input sources - int zero_pad; //!< Used when separate image files are used as input. Enables zero padding for file numbering - int num_digits; //!< Number of digits for file numbering - int start_frame; //!< start frame - int end_frame; //!< end frame - int nframes; //!< number of frames - int crop_x_size; //!< crop information (x component) - int crop_y_size; //!< crop information (y component) - int crop_x_offset; //!< crop offset (x component); - int crop_y_offset; //!< crop offset (y component); +typedef struct video_data_file { + // char* fname; //!< video file name + char fname[FILE_NAME_SIZE]; //!< video file name + char fhead[FILE_NAME_SIZE]; //!< header of video file + char ftail[FILE_NAME_SIZE]; //!< tail of video file + int f_num; //!< video file number + VideoFileType vdtype; //!< File format + FrameFormat format; //!< video format information + int is_concatenated; //!< Single or multifile input? + int is_interleaved; //!< Support for interleaved and non-interleaved input + //!< sources + int zero_pad; //!< Used when separate image files are used as input. Enables + //!< zero padding for file numbering + int num_digits; //!< Number of digits for file numbering + int start_frame; //!< start frame + int end_frame; //!< end frame + int nframes; //!< number of frames + int crop_x_size; //!< crop information (x component) + int crop_y_size; //!< crop information (y component) + int crop_x_offset; //!< crop offset (x component); + int crop_y_offset; //!< crop offset (y component); // AVI related information to be added here - int* avi; - //avi_t* avi; - //int header; - //char compressor[8]; + int *avi; + // avi_t* avi; + // int header; + // char compressor[8]; } VideoDataFile; #endif - diff --git a/src/common/ldecod_src/inc/lagrangian.h b/src/common/ldecod_src/inc/lagrangian.h index 5d84e53..29ac225 100644 --- a/src/common/ldecod_src/inc/lagrangian.h +++ b/src/common/ldecod_src/inc/lagrangian.h @@ -1,11 +1,11 @@ /*! ************************************************************************** * \file lagrangian.h - * \brief + * \brief * Distortion data header file * \date 2.23.2009, * - * \author + * \author * Alexis Michael Tourapis * ************************************************************************** @@ -14,12 +14,10 @@ #ifndef _LAGRANGIAN_H_ #define _LAGRANGIAN_H_ -typedef struct lambda_params -{ - double md; //!< Mode decision Lambda - double me[3]; //!< Motion Estimation Lambda - int mf[3]; //!< Integer formatted Motion Estimation Lambda +typedef struct lambda_params { + double md; //!< Mode decision Lambda + double me[3]; //!< Motion Estimation Lambda + int mf[3]; //!< Integer formatted Motion Estimation Lambda } LambdaParams; #endif - diff --git a/src/common/ldecod_src/inc/leaky_bucket.h b/src/common/ldecod_src/inc/leaky_bucket.h index ad605a6..6ba2152 100644 --- a/src/common/ldecod_src/inc/leaky_bucket.h +++ b/src/common/ldecod_src/inc/leaky_bucket.h @@ -7,7 +7,8 @@ * Header for Leaky Buffer parameters * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Shankar Regunathan ************************************************************************************* */ @@ -23,4 +24,3 @@ void calc_buffer(InputParameters *p_Inp); #endif #endif - diff --git a/src/common/ldecod_src/inc/loop_filter.h b/src/common/ldecod_src/inc/loop_filter.h index 439f973..9a1e80b 100644 --- a/src/common/ldecod_src/inc/loop_filter.h +++ b/src/common/ldecod_src/inc/loop_filter.h @@ -9,8 +9,9 @@ * \brief * Headerfile for loopfilter processing * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) - * - Alexis Michael Tourapis + * Main contributors (see contributors.h for copyright, address and + affiliation details) + * - Alexis Michael Tourapis ************************************************************************** */ @@ -20,49 +21,61 @@ #include "global.h" - -#define GROUP_SIZE 1 +#define GROUP_SIZE 1 /*********************************************************************************************************/ -// NOTE: In principle, the alpha and beta tables are calculated with the formulas below +// NOTE: In principle, the alpha and beta tables are calculated with the +// formulas below // Alpha( qp ) = 0.8 * (2^(qp/6) - 1) // Beta ( qp ) = 0.5 * qp - 7 -// The tables actually used have been "hand optimized" though (by Anthony Joch). So, the -// table values might be a little different to formula-generated values. Also, the first -// few values of both tables is set to zero to force the filter off at low qps +// The tables actually used have been "hand optimized" though (by Anthony Joch). +// So, the table values might be a little different to formula-generated values. +// Also, the first few values of both tables is set to zero to force the filter +// off at low qps -static const byte ALPHA_TABLE[52] = {0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,4,4,5,6, 7,8,9,10,12,13,15,17, 20,22,25,28,32,36,40,45, 50,56,63,71,80,90,101,113, 127,144,162,182,203,226,255,255} ; -static const byte BETA_TABLE[52] = {0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,2,2,2,3, 3,3,3, 4, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 11,11,12,12,13,13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18} ; -static const byte CLIP_TAB[52][5] = -{ - { 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0}, - { 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0},{ 0, 0, 0, 0, 0}, - { 0, 0, 0, 0, 0},{ 0, 0, 0, 1, 1},{ 0, 0, 0, 1, 1},{ 0, 0, 0, 1, 1},{ 0, 0, 0, 1, 1},{ 0, 0, 1, 1, 1},{ 0, 0, 1, 1, 1},{ 0, 1, 1, 1, 1}, - { 0, 1, 1, 1, 1},{ 0, 1, 1, 1, 1},{ 0, 1, 1, 1, 1},{ 0, 1, 1, 2, 2},{ 0, 1, 1, 2, 2},{ 0, 1, 1, 2, 2},{ 0, 1, 1, 2, 2},{ 0, 1, 2, 3, 3}, - { 0, 1, 2, 3, 3},{ 0, 2, 2, 3, 3},{ 0, 2, 2, 4, 4},{ 0, 2, 3, 4, 4},{ 0, 2, 3, 4, 4},{ 0, 3, 3, 5, 5},{ 0, 3, 4, 6, 6},{ 0, 3, 4, 6, 6}, - { 0, 4, 5, 7, 7},{ 0, 4, 5, 8, 8},{ 0, 4, 6, 9, 9},{ 0, 5, 7,10,10},{ 0, 6, 8,11,11},{ 0, 6, 8,13,13},{ 0, 7,10,14,14},{ 0, 8,11,16,16}, - { 0, 9,12,18,18},{ 0,10,13,20,20},{ 0,11,15,23,23},{ 0,13,17,25,25} -} ; +static const byte ALPHA_TABLE[52] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 4, 4, 5, 6, 7, 8, 9, 10, 12, 13, + 15, 17, 20, 22, 25, 28, 32, 36, 40, 45, 50, 56, 63, + 71, 80, 90, 101, 113, 127, 144, 162, 182, 203, 226, 255, 255}; +static const byte BETA_TABLE[52] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, + 2, 3, 3, 3, 3, 4, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, + 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18}; +static const byte CLIP_TAB[52][5] = { + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 1, 1}, + {0, 0, 0, 1, 1}, {0, 0, 0, 1, 1}, {0, 0, 0, 1, 1}, + {0, 0, 1, 1, 1}, {0, 0, 1, 1, 1}, {0, 1, 1, 1, 1}, + {0, 1, 1, 1, 1}, {0, 1, 1, 1, 1}, {0, 1, 1, 1, 1}, + {0, 1, 1, 2, 2}, {0, 1, 1, 2, 2}, {0, 1, 1, 2, 2}, + {0, 1, 1, 2, 2}, {0, 1, 2, 3, 3}, {0, 1, 2, 3, 3}, + {0, 2, 2, 3, 3}, {0, 2, 2, 4, 4}, {0, 2, 3, 4, 4}, + {0, 2, 3, 4, 4}, {0, 3, 3, 5, 5}, {0, 3, 4, 6, 6}, + {0, 3, 4, 6, 6}, {0, 4, 5, 7, 7}, {0, 4, 5, 8, 8}, + {0, 4, 6, 9, 9}, {0, 5, 7, 10, 10}, {0, 6, 8, 11, 11}, + {0, 6, 8, 13, 13}, {0, 7, 10, 14, 14}, {0, 8, 11, 16, 16}, + {0, 9, 12, 18, 18}, {0, 10, 13, 20, 20}, {0, 11, 15, 23, 23}, + {0, 13, 17, 25, 25}}; static const signed char chroma_edge[2][4][4] = //[dir][edge][yuv_format] -{ { {-4, 0, 0, 0}, - {-4,-4,-4, 4}, - {-4, 4, 4, 8}, - {-4,-4,-4, 12}}, + {{{-4, 0, 0, 0}, {-4, -4, -4, 4}, {-4, 4, 4, 8}, {-4, -4, -4, 12}}, - { {-4, 0, 0, 0}, - {-4,-4, 4, 4}, - {-4, 4, 8, 8}, - {-4,-4, 12, 12}}}; + {{-4, 0, 0, 0}, {-4, -4, 4, 4}, {-4, 4, 8, 8}, {-4, -4, 12, 12}}}; -static const int pelnum_cr[2][4] = {{0,8,16,16}, {0,8, 8,16}}; //[dir:0=vert, 1=hor.][yuv_format] +static const int pelnum_cr[2][4] = { + {0, 8, 16, 16}, {0, 8, 8, 16}}; //[dir:0=vert, 1=hor.][yuv_format] - -static inline int compare_mvs(const MotionVector *mv0, const MotionVector *mv1, int mvlimit) -{ - return ((iabs( mv0->mv_x - mv1->mv_x) >= 4) | (iabs( mv0->mv_y - mv1->mv_y) >= mvlimit)); +static inline int compare_mvs(const MotionVector *mv0, const MotionVector *mv1, + int mvlimit) { + return ((iabs(mv0->mv_x - mv1->mv_x) >= 4) | + (iabs(mv0->mv_y - mv1->mv_y) >= mvlimit)); } #endif diff --git a/src/common/ldecod_src/inc/loopfilter.h b/src/common/ldecod_src/inc/loopfilter.h index d102ef2..a5172a9 100644 --- a/src/common/ldecod_src/inc/loopfilter.h +++ b/src/common/ldecod_src/inc/loopfilter.h @@ -13,7 +13,8 @@ #include "global.h" #include "mbuffer.h" -extern void DeblockPicture(VideoParameters *p_Vid, StorablePicture *p) ; -extern void DeblockPicturePartially(VideoParameters *p_Vid, StorablePicture *p, int iStart, int iEnd) ; -void init_Deblock(VideoParameters *p_Vid, int mb_aff_frame_flag); +extern void DeblockPicture(VideoParameters *p_Vid, StorablePicture *p); +extern void DeblockPicturePartially(VideoParameters *p_Vid, StorablePicture *p, + int iStart, int iEnd); +void init_Deblock(VideoParameters *p_Vid, int mb_aff_frame_flag); #endif //_LOOPFILTER_H_ diff --git a/src/common/ldecod_src/inc/macroblock.h b/src/common/ldecod_src/inc/macroblock.h index 194fb63..ecf8749 100644 --- a/src/common/ldecod_src/inc/macroblock.h +++ b/src/common/ldecod_src/inc/macroblock.h @@ -14,139 +14,116 @@ #ifndef _MACROBLOCK_H_ #define _MACROBLOCK_H_ +#include "block.h" #include "global.h" #include "mbuffer.h" -#include "block.h" //! single scan pattern -static const byte SNGL_SCAN[16][2] = -{ - {0,0},{1,0},{0,1},{0,2}, - {1,1},{2,0},{3,0},{2,1}, - {1,2},{0,3},{1,3},{2,2}, - {3,1},{3,2},{2,3},{3,3} -}; +static const byte SNGL_SCAN[16][2] = { + {0, 0}, {1, 0}, {0, 1}, {0, 2}, {1, 1}, {2, 0}, {3, 0}, {2, 1}, + {1, 2}, {0, 3}, {1, 3}, {2, 2}, {3, 1}, {3, 2}, {2, 3}, {3, 3}}; //! field scan pattern -static const byte FIELD_SCAN[16][2] = -{ - {0,0},{0,1},{1,0},{0,2}, - {0,3},{1,1},{1,2},{1,3}, - {2,0},{2,1},{2,2},{2,3}, - {3,0},{3,1},{3,2},{3,3} -}; +static const byte FIELD_SCAN[16][2] = { + {0, 0}, {0, 1}, {1, 0}, {0, 2}, {0, 3}, {1, 1}, {1, 2}, {1, 3}, + {2, 0}, {2, 1}, {2, 2}, {2, 3}, {3, 0}, {3, 1}, {3, 2}, {3, 3}}; //! used to control block sizes : Not used/16x16/16x8/8x16/8x8/8x4/4x8/4x4 -static const int BLOCK_STEP[8][2]= -{ - {0,0},{4,4},{4,2},{2,4},{2,2},{2,1},{1,2},{1,1} -}; +static const int BLOCK_STEP[8][2] = {{0, 0}, {4, 4}, {4, 2}, {2, 4}, + {2, 2}, {2, 1}, {1, 2}, {1, 1}}; //! single scan pattern static const byte SNGL_SCAN8x8[64][2] = { - {0,0}, {1,0}, {0,1}, {0,2}, {1,1}, {2,0}, {3,0}, {2,1}, {1,2}, {0,3}, {0,4}, {1,3}, {2,2}, {3,1}, {4,0}, {5,0}, - {4,1}, {3,2}, {2,3}, {1,4}, {0,5}, {0,6}, {1,5}, {2,4}, {3,3}, {4,2}, {5,1}, {6,0}, {7,0}, {6,1}, {5,2}, {4,3}, - {3,4}, {2,5}, {1,6}, {0,7}, {1,7}, {2,6}, {3,5}, {4,4}, {5,3}, {6,2}, {7,1}, {7,2}, {6,3}, {5,4}, {4,5}, {3,6}, - {2,7}, {3,7}, {4,6}, {5,5}, {6,4}, {7,3}, {7,4}, {6,5}, {5,6}, {4,7}, {5,7}, {6,6}, {7,5}, {7,6}, {6,7}, {7,7} -}; - + {0, 0}, {1, 0}, {0, 1}, {0, 2}, {1, 1}, {2, 0}, {3, 0}, {2, 1}, + {1, 2}, {0, 3}, {0, 4}, {1, 3}, {2, 2}, {3, 1}, {4, 0}, {5, 0}, + {4, 1}, {3, 2}, {2, 3}, {1, 4}, {0, 5}, {0, 6}, {1, 5}, {2, 4}, + {3, 3}, {4, 2}, {5, 1}, {6, 0}, {7, 0}, {6, 1}, {5, 2}, {4, 3}, + {3, 4}, {2, 5}, {1, 6}, {0, 7}, {1, 7}, {2, 6}, {3, 5}, {4, 4}, + {5, 3}, {6, 2}, {7, 1}, {7, 2}, {6, 3}, {5, 4}, {4, 5}, {3, 6}, + {2, 7}, {3, 7}, {4, 6}, {5, 5}, {6, 4}, {7, 3}, {7, 4}, {6, 5}, + {5, 6}, {4, 7}, {5, 7}, {6, 6}, {7, 5}, {7, 6}, {6, 7}, {7, 7}}; //! field scan pattern -static const byte FIELD_SCAN8x8[64][2] = { // 8x8 - {0,0}, {0,1}, {0,2}, {1,0}, {1,1}, {0,3}, {0,4}, {1,2}, {2,0}, {1,3}, {0,5}, {0,6}, {0,7}, {1,4}, {2,1}, {3,0}, - {2,2}, {1,5}, {1,6}, {1,7}, {2,3}, {3,1}, {4,0}, {3,2}, {2,4}, {2,5}, {2,6}, {2,7}, {3,3}, {4,1}, {5,0}, {4,2}, - {3,4}, {3,5}, {3,6}, {3,7}, {4,3}, {5,1}, {6,0}, {5,2}, {4,4}, {4,5}, {4,6}, {4,7}, {5,3}, {6,1}, {6,2}, {5,4}, - {5,5}, {5,6}, {5,7}, {6,3}, {7,0}, {7,1}, {6,4}, {6,5}, {6,6}, {6,7}, {7,2}, {7,3}, {7,4}, {7,5}, {7,6}, {7,7} -}; +static const byte FIELD_SCAN8x8[64][2] = { // 8x8 + {0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1}, {0, 3}, {0, 4}, {1, 2}, + {2, 0}, {1, 3}, {0, 5}, {0, 6}, {0, 7}, {1, 4}, {2, 1}, {3, 0}, + {2, 2}, {1, 5}, {1, 6}, {1, 7}, {2, 3}, {3, 1}, {4, 0}, {3, 2}, + {2, 4}, {2, 5}, {2, 6}, {2, 7}, {3, 3}, {4, 1}, {5, 0}, {4, 2}, + {3, 4}, {3, 5}, {3, 6}, {3, 7}, {4, 3}, {5, 1}, {6, 0}, {5, 2}, + {4, 4}, {4, 5}, {4, 6}, {4, 7}, {5, 3}, {6, 1}, {6, 2}, {5, 4}, + {5, 5}, {5, 6}, {5, 7}, {6, 3}, {7, 0}, {7, 1}, {6, 4}, {6, 5}, + {6, 6}, {6, 7}, {7, 2}, {7, 3}, {7, 4}, {7, 5}, {7, 6}, {7, 7}}; //! single scan pattern -static const byte SCAN_YUV422[8][2] = -{ - {0,0},{0,1}, - {1,0},{0,2}, - {0,3},{1,1}, - {1,2},{1,3} -}; +static const byte SCAN_YUV422[8][2] = {{0, 0}, {0, 1}, {1, 0}, {0, 2}, + {0, 3}, {1, 1}, {1, 2}, {1, 3}}; -static const unsigned char cbp_blk_chroma[8][4] = -{ {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} -}; +static const unsigned char cbp_blk_chroma[8][4] = { + {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}}; -static const unsigned char cofuv_blk_x[3][8][4] = -{ { {0, 1, 0, 1}, - {0, 1, 0, 1}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0} }, +static const unsigned char cofuv_blk_x[3][8][4] = {{{0, 1, 0, 1}, + {0, 1, 0, 1}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}}, - { {0, 1, 0, 1}, - {0, 1, 0, 1}, - {0, 1, 0, 1}, - {0, 1, 0, 1}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0} }, + {{0, 1, 0, 1}, + {0, 1, 0, 1}, + {0, 1, 0, 1}, + {0, 1, 0, 1}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}}, - { {0, 1, 0, 1}, - {2, 3, 2, 3}, - {0, 1, 0, 1}, - {2, 3, 2, 3}, - {0, 1, 0, 1}, - {2, 3, 2, 3}, - {0, 1, 0, 1}, - {2, 3, 2, 3} } -}; + {{0, 1, 0, 1}, + {2, 3, 2, 3}, + {0, 1, 0, 1}, + {2, 3, 2, 3}, + {0, 1, 0, 1}, + {2, 3, 2, 3}, + {0, 1, 0, 1}, + {2, 3, 2, 3}}}; -static const unsigned char cofuv_blk_y[3][8][4] = -{ - { { 0, 0, 1, 1}, - { 0, 0, 1, 1}, - { 0, 0, 0, 0}, - { 0, 0, 0, 0}, - { 0, 0, 0, 0}, - { 0, 0, 0, 0}, - { 0, 0, 0, 0}, - { 0, 0, 0, 0} }, +static const unsigned char cofuv_blk_y[3][8][4] = {{{0, 0, 1, 1}, + {0, 0, 1, 1}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}}, - { { 0, 0, 1, 1}, - { 2, 2, 3, 3}, - { 0, 0, 1, 1}, - { 2, 2, 3, 3}, - { 0, 0, 0, 0}, - { 0, 0, 0, 0}, - { 0, 0, 0, 0}, - { 0, 0, 0, 0} }, - - { { 0, 0, 1, 1}, - { 0, 0, 1, 1}, - { 2, 2, 3, 3}, - { 2, 2, 3, 3}, - { 0, 0, 1, 1}, - { 0, 0, 1, 1}, - { 2, 2, 3, 3}, - { 2, 2, 3, 3}} -}; + {{0, 0, 1, 1}, + {2, 2, 3, 3}, + {0, 0, 1, 1}, + {2, 2, 3, 3}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}}, + {{0, 0, 1, 1}, + {0, 0, 1, 1}, + {2, 2, 3, 3}, + {2, 2, 3, 3}, + {0, 0, 1, 1}, + {0, 0, 1, 1}, + {2, 2, 3, 3}, + {2, 2, 3, 3}}}; extern void setup_slice_methods(Slice *currSlice); -extern void get_neighbors(Macroblock *currMB, PixelPos *block, int mb_x, int mb_y, int blockshape_x); - -extern void start_macroblock (Slice *currSlice, Macroblock **currMB); -extern int decode_one_macroblock(Macroblock *currMB, StorablePicture *dec_picture); -extern Boolean exit_macroblock (Slice *currSlice, int eos_bit); -extern void update_qp (Macroblock *currMB, int qp); +extern void get_neighbors(Macroblock *currMB, PixelPos *block, int mb_x, + int mb_y, int blockshape_x); +extern void start_macroblock(Slice *currSlice, Macroblock **currMB); +extern int decode_one_macroblock(Macroblock *currMB, + StorablePicture *dec_picture); +extern Boolean exit_macroblock(Slice *currSlice, int eos_bit); +extern void update_qp(Macroblock *currMB, int qp); #endif - diff --git a/src/common/ldecod_src/inc/mb_access.h b/src/common/ldecod_src/inc/mb_access.h index af4921c..f1449dd 100644 --- a/src/common/ldecod_src/inc/mb_access.h +++ b/src/common/ldecod_src/inc/mb_access.h @@ -7,9 +7,10 @@ * Functions for macroblock neighborhoods * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) - * - Karsten Shring - * - Alexis Michael Tourapis + * Main contributors (see contributors.h for copyright, address and + *affiliation details) + * - Karsten Shring + * - Alexis Michael Tourapis ************************************************************************************* */ @@ -18,14 +19,18 @@ extern void CheckAvailabilityOfNeighbors(Macroblock *currMB); -extern void getAffNeighbour (Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix); -extern void getNonAffNeighbour (Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix); -extern void get4x4Neighbour (Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix); -extern void get4x4NeighbourBase (Macroblock *currMB, int block_x, int block_y, int mb_size[2], PixelPos *pix); -extern Boolean mb_is_available (int mbAddr, Macroblock *currMB); -extern void get_mb_pos (VideoParameters *p_Vid, int mb_addr, int mb_size[2], short *x, short *y); -extern void get_mb_block_pos_normal (int mb_addr, short *x, short *y); -extern void get_mb_block_pos_mbaff (int mb_addr, short *x, short *y); - +extern void getAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], + PixelPos *pix); +extern void getNonAffNeighbour(Macroblock *currMB, int xN, int yN, + int mb_size[2], PixelPos *pix); +extern void get4x4Neighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], + PixelPos *pix); +extern void get4x4NeighbourBase(Macroblock *currMB, int block_x, int block_y, + int mb_size[2], PixelPos *pix); +extern Boolean mb_is_available(int mbAddr, Macroblock *currMB); +extern void get_mb_pos(VideoParameters *p_Vid, int mb_addr, int mb_size[2], + short *x, short *y); +extern void get_mb_block_pos_normal(int mb_addr, short *x, short *y); +extern void get_mb_block_pos_mbaff(int mb_addr, short *x, short *y); #endif diff --git a/src/common/ldecod_src/inc/mb_prediction.h b/src/common/ldecod_src/inc/mb_prediction.h index b77048c..4f415ba 100644 --- a/src/common/ldecod_src/inc/mb_prediction.h +++ b/src/common/ldecod_src/inc/mb_prediction.h @@ -7,29 +7,48 @@ * Functions for macroblock prediction * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) - * - Alexis Michael Tourapis + * Main contributors (see contributors.h for copyright, address and + *affiliation details) + * - Alexis Michael Tourapis ************************************************************************************* */ #ifndef _MB_PREDICTION_H_ #define _MB_PREDICTION_H_ -extern int mb_pred_intra4x4 (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -extern int mb_pred_intra16x16 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); -extern int mb_pred_intra8x8 (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); +extern int mb_pred_intra4x4(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, StorablePicture *dec_picture); +extern int mb_pred_intra16x16(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture); +extern int mb_pred_intra8x8(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, StorablePicture *dec_picture); -extern int mb_pred_skip (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -extern int mb_pred_sp_skip (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); -extern int mb_pred_p_inter8x8 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); -extern int mb_pred_p_inter16x16 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); -extern int mb_pred_p_inter16x8 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); -extern int mb_pred_p_inter8x16 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); -extern int mb_pred_b_d4x4spatial (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -extern int mb_pred_b_d8x8spatial (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -extern int mb_pred_b_d4x4temporal(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -extern int mb_pred_b_d8x8temporal(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -extern int mb_pred_b_inter8x8 (Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture); -extern int mb_pred_ipcm (Macroblock *currMB); +extern int mb_pred_skip(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, StorablePicture *dec_picture); +extern int mb_pred_sp_skip(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture); +extern int mb_pred_p_inter8x8(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture); +extern int mb_pred_p_inter16x16(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture); +extern int mb_pred_p_inter16x8(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture); +extern int mb_pred_p_inter8x16(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture); +extern int mb_pred_b_d4x4spatial(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, + StorablePicture *dec_picture); +extern int mb_pred_b_d8x8spatial(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, + StorablePicture *dec_picture); +extern int mb_pred_b_d4x4temporal(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, + StorablePicture *dec_picture); +extern int mb_pred_b_d8x8temporal(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, + StorablePicture *dec_picture); +extern int mb_pred_b_inter8x8(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture); +extern int mb_pred_ipcm(Macroblock *currMB); #endif diff --git a/src/common/ldecod_src/inc/mbuffer.h b/src/common/ldecod_src/inc/mbuffer.h index 228ee45..5d6b4f5 100644 --- a/src/common/ldecod_src/inc/mbuffer.h +++ b/src/common/ldecod_src/inc/mbuffer.h @@ -8,10 +8,11 @@ * Frame buffer functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + affiliation details) * - Karsten Shring * - Alexis Michael Tourapis - + * - Jill Boyce * - Saurav K Bandyopadhyay * - Zhenyu Wu * - Karsten Shring * - Alexis Michael Tourapis @@ -21,18 +22,24 @@ #include "global.h" #if (MVC_EXTENSION_ENABLE) -extern void reorder_lists_mvc (Slice * currSlice, int currPOC); -extern void init_lists_mvc (Slice *currSlice); +extern void reorder_lists_mvc(Slice *currSlice, int currPOC); +extern void init_lists_mvc(Slice *currSlice); extern void init_lists_p_slice_mvc(Slice *currSlice); extern void init_lists_b_slice_mvc(Slice *currSlice); extern void init_lists_i_slice_mvc(Slice *currSlice); -extern void reorder_ref_pic_list_mvc(Slice *currSlice, int cur_list, int **anchor_ref, int **non_anchor_ref, - int view_id, int anchor_pic_flag, int currPOC, int listidx); +extern void reorder_ref_pic_list_mvc(Slice *currSlice, int cur_list, + int **anchor_ref, int **non_anchor_ref, + int view_id, int anchor_pic_flag, + int currPOC, int listidx); -extern void reorder_short_term(Slice *currSlice, int cur_list, int num_ref_idx_lX_active_minus1, int picNumLX, int *refIdxLX, int currViewID); -extern void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX, int num_ref_idx_lX_active_minus1, int LongTermPicNum, int *refIdxLX, int currViewID); +extern void reorder_short_term(Slice *currSlice, int cur_list, + int num_ref_idx_lX_active_minus1, int picNumLX, + int *refIdxLX, int currViewID); +extern void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX, + int num_ref_idx_lX_active_minus1, + int LongTermPicNum, int *refIdxLX, + int currViewID); #endif #endif - diff --git a/src/common/ldecod_src/inc/mc_prediction.h b/src/common/ldecod_src/inc/mc_prediction.h index 1053c03..a92c453 100644 --- a/src/common/ldecod_src/inc/mc_prediction.h +++ b/src/common/ldecod_src/inc/mc_prediction.h @@ -7,7 +7,7 @@ * definitions for motion compensated prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * @@ -20,14 +20,22 @@ #include "global.h" #include "mbuffer.h" -extern int allocate_pred_mem(Slice *currSlice); -extern void free_pred_mem (Slice *currSlice); +extern int allocate_pred_mem(Slice *currSlice); +extern void free_pred_mem(Slice *currSlice); -extern void get_block_luma(StorablePicture *curr_ref, int x_pos, int y_pos, int hor_block_size, int ver_block_size, imgpel **block, - int shift_x,int maxold_x,int maxold_y,int **tmp_res,int max_imgpel_value,imgpel no_ref_value,Macroblock *currMB); +extern void get_block_luma(StorablePicture *curr_ref, int x_pos, int y_pos, + int hor_block_size, int ver_block_size, + imgpel **block, int shift_x, int maxold_x, + int maxold_y, int **tmp_res, int max_imgpel_value, + imgpel no_ref_value, Macroblock *currMB); -extern void intra_cr_decoding (Macroblock *currMB, int yuv); -extern void prepare_direct_params(Macroblock *currMB, StorablePicture *dec_picture, MotionVector *pmvl0, MotionVector *pmvl1,signed char *l0_rFrame, signed char *l1_rFrame); -extern void perform_mc (Macroblock *currMB, ColorPlane pl, StorablePicture *dec_picture, int pred_dir, int i, int j, int block_size_x, int block_size_y); +extern void intra_cr_decoding(Macroblock *currMB, int yuv); +extern void prepare_direct_params(Macroblock *currMB, + StorablePicture *dec_picture, + MotionVector *pmvl0, MotionVector *pmvl1, + signed char *l0_rFrame, + signed char *l1_rFrame); +extern void perform_mc(Macroblock *currMB, ColorPlane pl, + StorablePicture *dec_picture, int pred_dir, int i, int j, + int block_size_x, int block_size_y); #endif - diff --git a/src/common/ldecod_src/inc/memalloc.h b/src/common/ldecod_src/inc/memalloc.h index c5efc22..7fbbe84 100644 --- a/src/common/ldecod_src/inc/memalloc.h +++ b/src/common/ldecod_src/inc/memalloc.h @@ -7,9 +7,10 @@ * Memory allocation and free helper funtions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) - * - Karsten Shring - * - Alexis Michael Tourapis + * Main contributors (see contributors.h for copyright, address and + *affiliation details) + * - Karsten Shring + * - Alexis Michael Tourapis * ************************************************************************ */ @@ -17,164 +18,206 @@ #ifndef _MEMALLOC_H_ #define _MEMALLOC_H_ -#include "global.h" -#include "mbuffer.h" #include "distortion.h" +#include "global.h" #include "lagrangian.h" +#include "mbuffer.h" #include "quant_params.h" -extern int get_mem2Ddist(DistortionData ***array2D, int dim0, int dim1); +extern int get_mem2Ddist(DistortionData ***array2D, int dim0, int dim1); -extern int get_mem2Dlm (LambdaParams ***array2D, int dim0, int dim1); -extern int get_mem2Dolm (LambdaParams ***array2D, int dim0, int dim1, int offset); +extern int get_mem2Dlm(LambdaParams ***array2D, int dim0, int dim1); +extern int get_mem2Dolm(LambdaParams ***array2D, int dim0, int dim1, + int offset); -extern int get_mem2Dmp (PicMotionParams ***array2D, int dim0, int dim1); -extern int get_mem3Dmp (PicMotionParams ****array3D, int dim0, int dim1, int dim2); +extern int get_mem2Dmp(PicMotionParams ***array2D, int dim0, int dim1); +extern int get_mem3Dmp(PicMotionParams ****array3D, int dim0, int dim1, + int dim2); -extern int get_mem2Dquant(LevelQuantParams ***array2D, int dim0, int dim1); -extern int get_mem3Dquant(LevelQuantParams ****array3D, int dim0, int dim1, int dim2); -extern int get_mem4Dquant(LevelQuantParams *****array4D, int dim0, int dim1, int dim2, int dim3); -extern int get_mem5Dquant(LevelQuantParams ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4); +extern int get_mem2Dquant(LevelQuantParams ***array2D, int dim0, int dim1); +extern int get_mem3Dquant(LevelQuantParams ****array3D, int dim0, int dim1, + int dim2); +extern int get_mem4Dquant(LevelQuantParams *****array4D, int dim0, int dim1, + int dim2, int dim3); +extern int get_mem5Dquant(LevelQuantParams ******array5D, int dim0, int dim1, + int dim2, int dim3, int dim4); -extern int get_mem2Dmv (MotionVector ***array2D, int dim0, int dim1); -extern int get_mem3Dmv (MotionVector ****array3D, int dim0, int dim1, int dim2); -extern int get_mem4Dmv (MotionVector *****array4D, int dim0, int dim1, int dim2, int dim3); -extern int get_mem5Dmv (MotionVector ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4); -extern int get_mem6Dmv (MotionVector *******array6D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5); -extern int get_mem7Dmv (MotionVector ********array7D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5, int dim6); +extern int get_mem2Dmv(MotionVector ***array2D, int dim0, int dim1); +extern int get_mem3Dmv(MotionVector ****array3D, int dim0, int dim1, int dim2); +extern int get_mem4Dmv(MotionVector *****array4D, int dim0, int dim1, int dim2, + int dim3); +extern int get_mem5Dmv(MotionVector ******array5D, int dim0, int dim1, int dim2, + int dim3, int dim4); +extern int get_mem6Dmv(MotionVector *******array6D, int dim0, int dim1, + int dim2, int dim3, int dim4, int dim5); +extern int get_mem7Dmv(MotionVector ********array7D, int dim0, int dim1, + int dim2, int dim3, int dim4, int dim5, int dim6); -extern byte** new_mem2D(int dim0, int dim1); -extern int get_mem2D(byte ***array2D, int dim0, int dim1); -extern int get_mem3D(byte ****array3D, int dim0, int dim1, int dim2); -extern int get_mem4D(byte *****array4D, int dim0, int dim1, int dim2, int dim3); +extern byte **new_mem2D(int dim0, int dim1); +extern int get_mem2D(byte ***array2D, int dim0, int dim1); +extern int get_mem3D(byte ****array3D, int dim0, int dim1, int dim2); +extern int get_mem4D(byte *****array4D, int dim0, int dim1, int dim2, int dim3); -extern int** new_mem2Dint(int dim0, int dim1); -extern int get_mem2Dint(int ***array2D, int rows, int columns); -extern int get_mem2DintWithPad(int ***array2D, int dim0, int dim1, int iPadY, int iPadX); -extern int get_mem2Dint64(int64 ***array2D, int rows, int columns); -extern int get_mem3Dint(int ****array3D, int frames, int rows, int columns); -extern int get_mem3Dint64(int64 ****array3D, int frames, int rows, int columns); -extern int get_mem4Dint(int *****array4D, int idx, int frames, int rows, int columns ); -extern int get_mem4Dint64(int64 *****array4D, int idx, int frames, int rows, int columns ); -extern int get_mem5Dint(int ******array5D, int refs, int blocktype, int rows, int columns, int component); +extern int **new_mem2Dint(int dim0, int dim1); +extern int get_mem2Dint(int ***array2D, int rows, int columns); +extern int get_mem2DintWithPad(int ***array2D, int dim0, int dim1, int iPadY, + int iPadX); +extern int get_mem2Dint64(int64 ***array2D, int rows, int columns); +extern int get_mem3Dint(int ****array3D, int frames, int rows, int columns); +extern int get_mem3Dint64(int64 ****array3D, int frames, int rows, int columns); +extern int get_mem4Dint(int *****array4D, int idx, int frames, int rows, + int columns); +extern int get_mem4Dint64(int64 *****array4D, int idx, int frames, int rows, + int columns); +extern int get_mem5Dint(int ******array5D, int refs, int blocktype, int rows, + int columns, int component); -extern uint16** new_mem2Duint16(int dim0, int dim1); +extern uint16 **new_mem2Duint16(int dim0, int dim1); extern int get_mem2Duint16(uint16 ***array2D, int dim0, int dim1); -extern int get_mem3Duint16(uint16 ****array3D,int dim0, int dim1, int dim2); +extern int get_mem3Duint16(uint16 ****array3D, int dim0, int dim1, int dim2); -extern int get_mem2Ddistblk(distblk ***array2D, int rows, int columns); -extern int get_mem3Ddistblk(distblk ****array3D, int frames, int rows, int columns); -extern int get_mem4Ddistblk(distblk *****array4D, int idx, int frames, int rows, int columns ); +extern int get_mem2Ddistblk(distblk ***array2D, int rows, int columns); +extern int get_mem3Ddistblk(distblk ****array3D, int frames, int rows, + int columns); +extern int get_mem4Ddistblk(distblk *****array4D, int idx, int frames, int rows, + int columns); -extern int get_mem2Dshort(short ***array2D, int dim0, int dim1); -extern int get_mem3Dshort(short ****array3D, int dim0, int dim1, int dim2); -extern int get_mem4Dshort(short *****array4D, int dim0, int dim1, int dim2, int dim3); -extern int get_mem5Dshort(short ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4); -extern int get_mem6Dshort(short *******array6D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5); -extern int get_mem7Dshort(short ********array7D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5, int dim6); +extern int get_mem2Dshort(short ***array2D, int dim0, int dim1); +extern int get_mem3Dshort(short ****array3D, int dim0, int dim1, int dim2); +extern int get_mem4Dshort(short *****array4D, int dim0, int dim1, int dim2, + int dim3); +extern int get_mem5Dshort(short ******array5D, int dim0, int dim1, int dim2, + int dim3, int dim4); +extern int get_mem6Dshort(short *******array6D, int dim0, int dim1, int dim2, + int dim3, int dim4, int dim5); +extern int get_mem7Dshort(short ********array7D, int dim0, int dim1, int dim2, + int dim3, int dim4, int dim5, int dim6); -extern int get_mem1Dpel(imgpel **array2D, int rows); -extern int get_mem2Dpel(imgpel ***array2D, int rows, int columns); -extern int get_mem2DpelWithPad(imgpel ***array2D, int dim0, int dim1, int iPadY, int iPadX); +extern int get_mem1Dpel(imgpel **array2D, int rows); +extern int get_mem2Dpel(imgpel ***array2D, int rows, int columns); +extern int get_mem2DpelWithPad(imgpel ***array2D, int dim0, int dim1, int iPadY, + int iPadX); -extern int get_mem3Dpel(imgpel ****array3D, int frames, int rows, int columns); -extern int get_mem3DpelWithPad(imgpel ****array3D, int dim0, int dim1, int dim2, int iPadY, int iPadX); -extern int get_mem3DpelWithPadSeparately(imgpel ****array3D, int dim0, int dim1, int dim2, int iPadY, int iPadX); -extern int get_mem4Dpel(imgpel *****array4D, int sub_x, int sub_y, int rows, int columns); -extern int get_mem4DpelWithPad(imgpel *****array4D, int sub_x, int sub_y, int rows, int columns, int iPadY, int iPadX); -extern int get_mem4DpelWithPadSeparately(imgpel *****array4D, int dim0, int dim1, int dim2, int dim3, int iPadY, int iPadX); -extern int get_mem5Dpel(imgpel ******array5D, int dims, int sub_x, int sub_y, int rows, int columns); -extern int get_mem5DpelWithPad(imgpel ******array5D, int dims, int sub_x, int sub_y, int rows, int columns, int iPadY, int iPadX); -extern int get_mem5DpelWithPadSeparately(imgpel ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4, int iPadY, int iPadX); -extern int get_mem2Ddouble (double ***array2D, int rows, int columns); +extern int get_mem3Dpel(imgpel ****array3D, int frames, int rows, int columns); +extern int get_mem3DpelWithPad(imgpel ****array3D, int dim0, int dim1, int dim2, + int iPadY, int iPadX); +extern int get_mem3DpelWithPadSeparately(imgpel ****array3D, int dim0, int dim1, + int dim2, int iPadY, int iPadX); +extern int get_mem4Dpel(imgpel *****array4D, int sub_x, int sub_y, int rows, + int columns); +extern int get_mem4DpelWithPad(imgpel *****array4D, int sub_x, int sub_y, + int rows, int columns, int iPadY, int iPadX); +extern int get_mem4DpelWithPadSeparately(imgpel *****array4D, int dim0, + int dim1, int dim2, int dim3, + int iPadY, int iPadX); +extern int get_mem5Dpel(imgpel ******array5D, int dims, int sub_x, int sub_y, + int rows, int columns); +extern int get_mem5DpelWithPad(imgpel ******array5D, int dims, int sub_x, + int sub_y, int rows, int columns, int iPadY, + int iPadX); +extern int get_mem5DpelWithPadSeparately(imgpel ******array5D, int dim0, + int dim1, int dim2, int dim3, int dim4, + int iPadY, int iPadX); +extern int get_mem2Ddouble(double ***array2D, int rows, int columns); -extern int get_mem1Dodouble(double **array1D, int dim0, int offset); -extern int get_mem2Dodouble(double ***array2D, int rows, int columns, int offset); -extern int get_mem3Dodouble(double ****array2D, int rows, int columns, int pels, int offset); +extern int get_mem1Dodouble(double **array1D, int dim0, int offset); +extern int get_mem2Dodouble(double ***array2D, int rows, int columns, + int offset); +extern int get_mem3Dodouble(double ****array2D, int rows, int columns, int pels, + int offset); -extern int get_mem2Doint (int ***array2D, int rows, int columns, int offset); -extern int get_mem3Doint (int ****array3D, int rows, int columns, int pels, int offset); +extern int get_mem2Doint(int ***array2D, int rows, int columns, int offset); +extern int get_mem3Doint(int ****array3D, int rows, int columns, int pels, + int offset); -extern int get_offset_mem2Dshort(short ***array2D, int rows, int columns, int offset_y, int offset_x); +extern int get_offset_mem2Dshort(short ***array2D, int rows, int columns, + int offset_y, int offset_x); -extern void free_offset_mem2Dshort(short **array2D, int columns, int offset_x, int offset_y); +extern void free_offset_mem2Dshort(short **array2D, int columns, int offset_x, + int offset_y); -extern void free_mem2Ddist (DistortionData **array2D); +extern void free_mem2Ddist(DistortionData **array2D); -extern void free_mem2Dlm (LambdaParams **array2D); -extern void free_mem2Dolm (LambdaParams **array2D, int offset); +extern void free_mem2Dlm(LambdaParams **array2D); +extern void free_mem2Dolm(LambdaParams **array2D, int offset); -extern void free_mem2Dmp (PicMotionParams **array2D); -extern void free_mem3Dmp (PicMotionParams ***array2D); +extern void free_mem2Dmp(PicMotionParams **array2D); +extern void free_mem3Dmp(PicMotionParams ***array2D); -extern void free_mem2Dquant(LevelQuantParams **array2D); -extern void free_mem3Dquant(LevelQuantParams ***array2D); -extern void free_mem4Dquant(LevelQuantParams ****array2D); +extern void free_mem2Dquant(LevelQuantParams **array2D); +extern void free_mem3Dquant(LevelQuantParams ***array2D); +extern void free_mem4Dquant(LevelQuantParams ****array2D); extern void free_mem5Dquant(LevelQuantParams *****array2D); -extern void free_mem2Dmv (MotionVector **array2D); -extern void free_mem3Dmv (MotionVector ***array2D); -extern void free_mem4Dmv (MotionVector ****array2D); -extern void free_mem5Dmv (MotionVector *****array2D); -extern void free_mem6Dmv (MotionVector ******array2D); -extern void free_mem7Dmv (MotionVector *******array7D); +extern void free_mem2Dmv(MotionVector **array2D); +extern void free_mem3Dmv(MotionVector ***array2D); +extern void free_mem4Dmv(MotionVector ****array2D); +extern void free_mem5Dmv(MotionVector *****array2D); +extern void free_mem6Dmv(MotionVector ******array2D); +extern void free_mem7Dmv(MotionVector *******array7D); -extern int get_mem2D_spp(StorablePicturePtr ***array3D, int dim0, int dim1); -extern int get_mem3D_spp(StorablePicturePtr ****array3D, int dim0, int dim1, int dim2); +extern int get_mem2D_spp(StorablePicturePtr ***array3D, int dim0, int dim1); +extern int get_mem3D_spp(StorablePicturePtr ****array3D, int dim0, int dim1, + int dim2); -extern void free_mem2D_spp (StorablePicturePtr **array2D); -extern void free_mem3D_spp (StorablePicturePtr ***array2D); +extern void free_mem2D_spp(StorablePicturePtr **array2D); +extern void free_mem3D_spp(StorablePicturePtr ***array2D); -extern void free_mem2D (byte **array2D); -extern void free_mem3D (byte ***array3D); -extern void free_mem4D (byte ****array4D); +extern void free_mem2D(byte **array2D); +extern void free_mem3D(byte ***array3D); +extern void free_mem4D(byte ****array4D); -extern void free_mem2Dint (int **array2D); +extern void free_mem2Dint(int **array2D); extern void free_mem2DintWithPad(int **array2D, int iPadY, int iPadX); -extern void free_mem3Dint (int ***array3D); -extern void free_mem4Dint (int ****array4D); -extern void free_mem5Dint (int *****array5D); +extern void free_mem3Dint(int ***array3D); +extern void free_mem4Dint(int ****array4D); +extern void free_mem5Dint(int *****array5D); extern void free_mem2Duint16(uint16 **array2D); extern void free_mem3Duint16(uint16 ***array3D); -extern void free_mem2Dint64(int64 **array2D); -extern void free_mem3Dint64(int64 ***array3D); -extern void free_mem4Dint64(int64 ****array4D); +extern void free_mem2Dint64(int64 **array2D); +extern void free_mem3Dint64(int64 ***array3D); +extern void free_mem4Dint64(int64 ****array4D); -extern void free_mem2Ddistblk(distblk **array2D); -extern void free_mem3Ddistblk(distblk ***array3D); -extern void free_mem4Ddistblk(distblk ****array4D); +extern void free_mem2Ddistblk(distblk **array2D); +extern void free_mem3Ddistblk(distblk ***array3D); +extern void free_mem4Ddistblk(distblk ****array4D); -extern void free_mem2Dshort(short **array2D); -extern void free_mem3Dshort(short ***array3D); -extern void free_mem4Dshort(short ****array4D); -extern void free_mem5Dshort(short *****array5D); -extern void free_mem6Dshort(short ******array6D); +extern void free_mem2Dshort(short **array2D); +extern void free_mem3Dshort(short ***array3D); +extern void free_mem4Dshort(short ****array4D); +extern void free_mem5Dshort(short *****array5D); +extern void free_mem6Dshort(short ******array6D); extern void free_mem7Dshort(short *******array7D); -extern void free_mem1Dpel (imgpel *array1D); -extern void free_mem2Dpel (imgpel **array2D); +extern void free_mem1Dpel(imgpel *array1D); +extern void free_mem2Dpel(imgpel **array2D); extern void free_mem2DpelWithPad(imgpel **array2D, int iPadY, int iPadX); -extern void free_mem3Dpel (imgpel ***array3D); +extern void free_mem3Dpel(imgpel ***array3D); extern void free_mem3DpelWithPad(imgpel ***array3D, int iPadY, int iPadX); -extern void free_mem3DpelWithPadSeparately(imgpel ***array3D, int iDim12, int iPadY, int iPadX); -extern void free_mem4Dpel (imgpel ****array4D); -extern void free_mem4DpelWithPad(imgpel ****array4D, int iPadY, int iPadX); -extern void free_mem4DpelWithPadSeparately(imgpel ****array4D, int iFrames, int iPadY, int iPadX); -extern void free_mem5Dpel (imgpel *****array5D); +extern void free_mem3DpelWithPadSeparately(imgpel ***array3D, int iDim12, + int iPadY, int iPadX); +extern void free_mem4Dpel(imgpel ****array4D); +extern void free_mem4DpelWithPad(imgpel ****array4D, int iPadY, int iPadX); +extern void free_mem4DpelWithPadSeparately(imgpel ****array4D, int iFrames, + int iPadY, int iPadX); +extern void free_mem5Dpel(imgpel *****array5D); extern void free_mem5DpelWithPad(imgpel *****array5D, int iPadY, int iPadX); -extern void free_mem5DpelWithPadSeparately(imgpel *****array5D, int iFrames, int iPadY, int iPadX); +extern void free_mem5DpelWithPadSeparately(imgpel *****array5D, int iFrames, + int iPadY, int iPadX); extern void free_mem2Ddouble(double **array2D); extern void free_mem3Ddouble(double ***array3D); -extern void free_mem1Dodouble(double *array1D, int offset); +extern void free_mem1Dodouble(double *array1D, int offset); extern void free_mem2Dodouble(double **array2D, int offset); -extern void free_mem3Dodouble(double ***array3D, int rows, int columns, int offset); -extern void free_mem2Doint (int **array2D, int offset); -extern void free_mem3Doint (int ***array3D, int rows, int columns, int offset); +extern void free_mem3Dodouble(double ***array3D, int rows, int columns, + int offset); +extern void free_mem2Doint(int **array2D, int offset); +extern void free_mem3Doint(int ***array3D, int rows, int columns, int offset); -extern int init_top_bot_planes(imgpel **imgFrame, int height, imgpel ***imgTopField, imgpel ***imgBotField); +extern int init_top_bot_planes(imgpel **imgFrame, int height, + imgpel ***imgTopField, imgpel ***imgBotField); extern void free_top_bot_planes(imgpel **imgTopField, imgpel **imgBotField); extern void no_mem_exit(char *where); diff --git a/src/common/ldecod_src/inc/mv_prediction.h b/src/common/ldecod_src/inc/mv_prediction.h index deb6e7c..faa86f0 100644 --- a/src/common/ldecod_src/inc/mv_prediction.h +++ b/src/common/ldecod_src/inc/mv_prediction.h @@ -6,14 +6,16 @@ * Declarations for Motion Vector Prediction * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) - * - Alexis Michael Tourapis + * Main contributors (see contributors.h for copyright, address and + *affiliation details) + * - Alexis Michael Tourapis ************************************************************************************* */ #ifndef _MV_PREDICTION_H_ #define _MV_PREDICTION_H_ -extern void init_motion_vector_prediction(Macroblock *currMB, int mb_aff_frame_flag); +extern void init_motion_vector_prediction(Macroblock *currMB, + int mb_aff_frame_flag); #endif diff --git a/src/common/ldecod_src/inc/nalu.h b/src/common/ldecod_src/inc/nalu.h index 60a363e..90617c2 100644 --- a/src/common/ldecod_src/inc/nalu.h +++ b/src/common/ldecod_src/inc/nalu.h @@ -8,27 +8,26 @@ * * \date 25 November 2002 * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger *************************************************************************************** */ - #ifndef _NALU_H_ #define _NALU_H_ #include "nalucommon.h" -typedef struct sBitsFile -{ - void (*OpenBitsFile) (VideoParameters *p_Vid, char *filename); - void (*CloseBitsFile) (VideoParameters *p_Vid); - int (*GetNALU) (VideoParameters *p_Vid, NALU_t *nalu); +typedef struct sBitsFile { + void (*OpenBitsFile)(VideoParameters *p_Vid, char *filename); + void (*CloseBitsFile)(VideoParameters *p_Vid); + int (*GetNALU)(VideoParameters *p_Vid, NALU_t *nalu); } BitsFile; -extern void initBitsFile (VideoParameters *p_Vid, int filemode); +extern void initBitsFile(VideoParameters *p_Vid, int filemode); extern void CheckZeroByteNonVCL(VideoParameters *p_Vid, NALU_t *nalu); -extern void CheckZeroByteVCL (VideoParameters *p_Vid, NALU_t *nalu); +extern void CheckZeroByteVCL(VideoParameters *p_Vid, NALU_t *nalu); extern int read_next_nalu(VideoParameters *p_Vid, NALU_t *nalu); diff --git a/src/common/ldecod_src/inc/nalucommon.h b/src/common/ldecod_src/inc/nalucommon.h index 76ed36c..b9d9b9b 100644 --- a/src/common/ldecod_src/inc/nalucommon.h +++ b/src/common/ldecod_src/inc/nalucommon.h @@ -6,7 +6,8 @@ * \brief * NALU handling common to encoder and decoder * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger * - Karsten Suehring *************************************************************************************** @@ -22,54 +23,55 @@ //! values for nal_unit_type typedef enum { - NALU_TYPE_SLICE = 1, - NALU_TYPE_DPA = 2, - NALU_TYPE_DPB = 3, - NALU_TYPE_DPC = 4, - NALU_TYPE_IDR = 5, - NALU_TYPE_SEI = 6, - NALU_TYPE_SPS = 7, - NALU_TYPE_PPS = 8, - NALU_TYPE_AUD = 9, - NALU_TYPE_EOSEQ = 10, - NALU_TYPE_EOSTREAM = 11, - NALU_TYPE_FILL = 12, + NALU_TYPE_SLICE = 1, + NALU_TYPE_DPA = 2, + NALU_TYPE_DPB = 3, + NALU_TYPE_DPC = 4, + NALU_TYPE_IDR = 5, + NALU_TYPE_SEI = 6, + NALU_TYPE_SPS = 7, + NALU_TYPE_PPS = 8, + NALU_TYPE_AUD = 9, + NALU_TYPE_EOSEQ = 10, + NALU_TYPE_EOSTREAM = 11, + NALU_TYPE_FILL = 12, #if (MVC_EXTENSION_ENABLE) - NALU_TYPE_PREFIX = 14, - NALU_TYPE_SUB_SPS = 15, - NALU_TYPE_SLC_EXT = 20, - NALU_TYPE_VDRD = 24 // View and Dependency Representation Delimiter NAL Unit + NALU_TYPE_PREFIX = 14, + NALU_TYPE_SUB_SPS = 15, + NALU_TYPE_SLC_EXT = 20, + NALU_TYPE_VDRD = 24 // View and Dependency Representation Delimiter NAL Unit #endif } NaluType; //! values for nal_ref_idc typedef enum { - NALU_PRIORITY_HIGHEST = 3, - NALU_PRIORITY_HIGH = 2, - NALU_PRIORITY_LOW = 1, - NALU_PRIORITY_DISPOSABLE = 0 + NALU_PRIORITY_HIGHEST = 3, + NALU_PRIORITY_HIGH = 2, + NALU_PRIORITY_LOW = 1, + NALU_PRIORITY_DISPOSABLE = 0 } NalRefIdc; //! NAL unit structure -typedef struct nalu_t -{ - int startcodeprefix_len; //!< 4 for parameter sets and first slice in picture, 3 for everything else (suggested) - unsigned len; //!< Length of the NAL unit (Excluding the start code, which does not belong to the NALU) - unsigned max_size; //!< NAL Unit Buffer size - int forbidden_bit; //!< should be always FALSE - NaluType nal_unit_type; //!< NALU_TYPE_xxxx - NalRefIdc nal_reference_idc; //!< NALU_PRIORITY_xxxx - byte *buf; //!< contains the first byte followed by the EBSP - uint16 lost_packets; //!< true, if packet loss is detected +typedef struct nalu_t { + int startcodeprefix_len; //!< 4 for parameter sets and first slice in picture, + //!< 3 for everything else (suggested) + unsigned len; //!< Length of the NAL unit (Excluding the start code, which + //!< does not belong to the NALU) + unsigned max_size; //!< NAL Unit Buffer size + int forbidden_bit; //!< should be always FALSE + NaluType nal_unit_type; //!< NALU_TYPE_xxxx + NalRefIdc nal_reference_idc; //!< NALU_PRIORITY_xxxx + byte *buf; //!< contains the first byte followed by the EBSP + uint16 lost_packets; //!< true, if packet loss is detected #if (MVC_EXTENSION_ENABLE) - int svc_extension_flag; //!< should be always 0, for MVC - int non_idr_flag; //!< 0 = current is IDR - int priority_id; //!< a lower value of priority_id specifies a higher priority - int view_id; //!< view identifier for the NAL unit - int temporal_id; //!< temporal identifier for the NAL unit - int anchor_pic_flag; //!< anchor access unit - int inter_view_flag; //!< inter-view prediction enable - int reserved_one_bit; //!< shall be equal to 1 + int svc_extension_flag; //!< should be always 0, for MVC + int non_idr_flag; //!< 0 = current is IDR + int priority_id; //!< a lower value of priority_id specifies a higher priority + int view_id; //!< view identifier for the NAL unit + int temporal_id; //!< temporal identifier for the NAL unit + int anchor_pic_flag; //!< anchor access unit + int inter_view_flag; //!< inter-view prediction enable + int reserved_one_bit; //!< shall be equal to 1 #endif } NALU_t; diff --git a/src/common/ldecod_src/inc/output.h b/src/common/ldecod_src/inc/output.h index 555b182..3b91529 100644 --- a/src/common/ldecod_src/inc/output.h +++ b/src/common/ldecod_src/inc/output.h @@ -6,7 +6,8 @@ * \brief * Picture writing routine headers * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Karsten Suehring *************************************************************************************** */ @@ -14,11 +15,12 @@ #ifndef _OUTPUT_H_ #define _OUTPUT_H_ - -extern void write_stored_frame(VideoParameters *p_Vid, FrameStore *fs, int p_out); -extern void direct_output (VideoParameters *p_Vid, StorablePicture *p, int p_out); -extern void init_out_buffer (VideoParameters *p_Vid); -extern void uninit_out_buffer (VideoParameters *p_Vid); +extern void write_stored_frame(VideoParameters *p_Vid, FrameStore *fs, + int p_out); +extern void direct_output(VideoParameters *p_Vid, StorablePicture *p, + int p_out); +extern void init_out_buffer(VideoParameters *p_Vid); +extern void uninit_out_buffer(VideoParameters *p_Vid); #if (PAIR_FIELDS_IN_OUTPUT) extern void flush_pending_output(VideoParameters *p_Vid, int p_out); #endif diff --git a/src/common/ldecod_src/inc/params.h b/src/common/ldecod_src/inc/params.h index 41f7ece..1b1d9ed 100644 --- a/src/common/ldecod_src/inc/params.h +++ b/src/common/ldecod_src/inc/params.h @@ -14,85 +14,101 @@ #define _PARAMS_H_ #include "defines.h" -#include "types.h" -#include "vui_params.h" #include "frame.h" #include "io_video.h" +#include "types.h" +#include "vui_params.h" //! all input parameters -struct inp_par_enc -{ - int ProfileIDC; //!< value of syntax element profile_idc - int LevelIDC; //!< value of syntax element level_idc - int IntraProfile; //!< Enable Intra profiles - - int no_frames; //!< number of frames to be encoded - int qp[NUM_SLICE_TYPES]; //!< QP values for all slice types - int qp2frame; //!< frame in display order from which to apply the Change QP offsets - int qp2off[NUM_SLICE_TYPES]; //!< Change QP offset values for all slice types - int qpsp; //!< QPSP quantization value - int frame_skip; //!< number of frames to skip in input sequence (e.g 2 takes frame 0,3,6,9...) - int jumpd; /*!< number of frames to skip in input sequence including intermediate pictures - (e.g 2 takes frame 0,3,6,9...) */ - int DisableSubpelME; //!< Disable sub-pixel motion estimation - int search_range; /*!< search range - integer pel search and 16x16 blocks. The search window is - generally around the predicted vector. Max vector is 2xmcrange. */ - int num_ref_frames; //!< number of reference frames to be used - int P_List0_refs; //!< number of reference picture in list 0 in P pictures - int B_List0_refs; //!< number of reference picture in list 0 in B pictures - int B_List1_refs; //!< number of reference picture in list 1 in B pictures - int Log2MaxFNumMinus4; //!< value of syntax element log2_max_frame_num - int Log2MaxPOCLsbMinus4; //!< value of syntax element log2_max_pic_order_cnt_lsb_minus4 +struct inp_par_enc { + int ProfileIDC; //!< value of syntax element profile_idc + int LevelIDC; //!< value of syntax element level_idc + int IntraProfile; //!< Enable Intra profiles + + int no_frames; //!< number of frames to be encoded + int qp[NUM_SLICE_TYPES]; //!< QP values for all slice types + int qp2frame; //!< frame in display order from which to apply the Change QP + //!< offsets + int qp2off[NUM_SLICE_TYPES]; //!< Change QP offset values for all slice types + int qpsp; //!< QPSP quantization value + int frame_skip; //!< number of frames to skip in input sequence (e.g 2 takes + //!< frame 0,3,6,9...) + int jumpd; /*!< number of frames to skip in input sequence including + intermediate pictures (e.g 2 takes frame 0,3,6,9...) */ + int DisableSubpelME; //!< Disable sub-pixel motion estimation + int search_range; /*!< search range - integer pel search and 16x16 blocks. The + search window is generally around the predicted vector. + Max vector is 2xmcrange. */ + int num_ref_frames; //!< number of reference frames to be used + int P_List0_refs; //!< number of reference picture in list 0 in P pictures + int B_List0_refs; //!< number of reference picture in list 0 in B pictures + int B_List1_refs; //!< number of reference picture in list 1 in B pictures + int Log2MaxFNumMinus4; //!< value of syntax element log2_max_frame_num + int Log2MaxPOCLsbMinus4; //!< value of syntax element + //!< log2_max_pic_order_cnt_lsb_minus4 // Input/output sequence format related variables - FrameFormat source; //!< source related information - FrameFormat output; //!< output related information + FrameFormat source; //!< source related information + FrameFormat output; //!< output related information int is_interleaved; - int src_resize; //!< Control if input sequence will be resized (currently only cropping is supported) - int src_BitDepthRescale; //!< Control if input sequence bitdepth should be adjusted - int yuv_format; //!< YUV format (0=4:0:0, 1=4:2:0, 2=4:2:2, 3=4:4:4) - int intra_upd; /*!< For error robustness. 0: no special action. 1: One GOB/frame is intra coded - as regular 'update'. 2: One GOB every 2 frames is intra coded etc. - In connection with this intra update, restrictions is put on motion vectors - to prevent errors to propagate from the past */ + int src_resize; //!< Control if input sequence will be resized (currently only + //!< cropping is supported) + int src_BitDepthRescale; //!< Control if input sequence bitdepth should be + //!< adjusted + int yuv_format; //!< YUV format (0=4:0:0, 1=4:2:0, 2=4:2:2, 3=4:4:4) + int intra_upd; /*!< For error robustness. 0: no special action. 1: One + GOB/frame is intra coded as regular 'update'. 2: One GOB + every 2 frames is intra coded etc. In connection with this + intra update, restrictions is put on motion vectors to + prevent errors to propagate from the past */ - int slice_mode; //!< Indicate what algorithm to use for setting slices - int slice_argument; //!< Argument to the specified slice algorithm - int UseConstrainedIntraPred; //!< 0: Inter MB pixels are allowed for intra prediction 1: Not allowed - int SetFirstAsLongTerm; //!< Support for temporal considerations for CB plus encoding - int infile_header; //!< If input file has a header set this to the length of the header - int MultiSourceData; - VideoDataFile input_file2; //!< Input video file2 - VideoDataFile input_file3; //!< Input video file3 + int slice_mode; //!< Indicate what algorithm to use for setting slices + int slice_argument; //!< Argument to the specified slice algorithm + int UseConstrainedIntraPred; //!< 0: Inter MB pixels are allowed for intra + //!< prediction 1: Not allowed + int SetFirstAsLongTerm; //!< Support for temporal considerations for CB plus + //!< encoding + int infile_header; //!< If input file has a header set this to the length of + //!< the header + int MultiSourceData; + VideoDataFile input_file2; //!< Input video file2 + VideoDataFile input_file3; //!< Input video file3 #if (MVC_EXTENSION_ENABLE) - int num_of_views; //!< number of views to encode (1=1view, 2=2views) - int MVCInterViewReorder; //!< Reorder References according to interview pictures - int MVCFlipViews; //!< Reverse the order of the views in the bitstream (view 1 has VOIdx 0 and view 1 has VOIdx 0) - int MVCInterViewForceB; //!< Force B slices for enhancement layer - int View1QPOffset; //!< QP offset during rate control for View 1 - int enable_inter_view_flag; //!< Enables inter_view_flag (allows pictures that are to be used for inter-view only prediction) + int num_of_views; //!< number of views to encode (1=1view, 2=2views) + int MVCInterViewReorder; //!< Reorder References according to interview + //!< pictures + int MVCFlipViews; //!< Reverse the order of the views in the bitstream (view 1 + //!< has VOIdx 0 and view 1 has VOIdx 0) + int MVCInterViewForceB; //!< Force B slices for enhancement layer + int View1QPOffset; //!< QP offset during rate control for View 1 + int enable_inter_view_flag; //!< Enables inter_view_flag (allows pictures that + //!< are to be used for inter-view only + //!< prediction) #endif - VideoDataFile input_file1; //!< Input video file1 - signed char outfile [FILE_NAME_SIZE]; //!< H.264 compressed output bitstream - signed char ReconFile [FILE_NAME_SIZE]; //!< Reconstructed Pictures (view 0 for MVC profile) - signed char ReconFile2 [FILE_NAME_SIZE]; //!< Reconstructed Pictures (view 1) + VideoDataFile input_file1; //!< Input video file1 + signed char outfile[FILE_NAME_SIZE]; //!< H.264 compressed output bitstream + signed char ReconFile[FILE_NAME_SIZE]; //!< Reconstructed Pictures (view 0 for + //!< MVC profile) + signed char ReconFile2[FILE_NAME_SIZE]; //!< Reconstructed Pictures (view 1) - signed char TraceFile [FILE_NAME_SIZE]; //!< Trace Outputs - signed char StatsFile [FILE_NAME_SIZE]; //!< Stats File - signed char QmatrixFile [FILE_NAME_SIZE]; //!< Q matrix cfg file - int ProcessInput; //!< Filter Input Sequence - int EnableOpenGOP; //!< support for open gops. - int EnableIDRGOP; //!< support for IDR closed gops with no shared B coded pictures. - int grayscale; //!< encode in grayscale (Currently only works for 8 bit, YUV 420) + signed char TraceFile[FILE_NAME_SIZE]; //!< Trace Outputs + signed char StatsFile[FILE_NAME_SIZE]; //!< Stats File + signed char QmatrixFile[FILE_NAME_SIZE]; //!< Q matrix cfg file + int ProcessInput; //!< Filter Input Sequence + int EnableOpenGOP; //!< support for open gops. + int EnableIDRGOP; //!< support for IDR closed gops with no shared B coded + //!< pictures. + int grayscale; //!< encode in grayscale (Currently only works for 8 bit, YUV + //!< 420) - int idr_period; //!< IDR picture period - int intra_period; //!< intra picture period - int intra_delay; //!< IDR picture delay + int idr_period; //!< IDR picture period + int intra_period; //!< intra picture period + int intra_delay; //!< IDR picture delay int adaptive_idr_period; - int adaptive_intra_period; //!< reinitialize start of intra period + int adaptive_intra_period; //!< reinitialize start of intra period - int start_frame; //!< Encode sequence starting from Frame start_frame + int start_frame; //!< Encode sequence starting from Frame start_frame int enable_32_pulldown; @@ -103,77 +119,109 @@ struct inp_par_enc int ResendSPS; int ResendPPS; - int SendAUD; //!< send Access Unit Delimiter NALU - int skip_gl_stats; + int SendAUD; //!< send Access Unit Delimiter NALU + int skip_gl_stats; // B pictures - int NumberBFrames; //!< number of B frames that will be used + int NumberBFrames; //!< number of B frames that will be used int PReplaceBSlice; - int qpBRSOffset; //!< QP for reference B slice coded pictures - int direct_spatial_mv_pred_flag; //!< Direct Mode type to be used (0: Temporal, 1: Spatial) - int directInferenceFlag; //!< Direct Mode Inference Flag + int qpBRSOffset; //!< QP for reference B slice coded pictures + int direct_spatial_mv_pred_flag; //!< Direct Mode type to be used (0: + //!< Temporal, 1: Spatial) + int directInferenceFlag; //!< Direct Mode Inference Flag - int BiPredMotionEstimation; //!< Use of Bipredictive motion estimation - int BiPredSearch[4]; //!< Bipredictive motion estimation for modes 16x16, 16x8, 8x16, and 8x8 - int BiPredMERefinements; //!< Max number of Iterations for Bi-predictive motion estimation - int BiPredMESearchRange; //!< Search range of Bi-predictive motion estimation - int BiPredMESubPel; //!< Use of subpixel refinement for Bi-predictive motion estimation + int BiPredMotionEstimation; //!< Use of Bipredictive motion estimation + int BiPredSearch[4]; //!< Bipredictive motion estimation for modes 16x16, + //!< 16x8, 8x16, and 8x8 + int BiPredMERefinements; //!< Max number of Iterations for Bi-predictive + //!< motion estimation + int BiPredMESearchRange; //!< Search range of Bi-predictive motion estimation + int BiPredMESubPel; //!< Use of subpixel refinement for Bi-predictive motion + //!< estimation // SP/SI Pictures - int sp_periodicity; //!< The periodicity of SP-pictures - int sp_switch_period; //!< Switch period (in terms of switching SP/SI frames) between bitstream 1 and bitstream 2 - int si_frame_indicator; //!< Flag indicating whether SI frames should be encoded rather than SP frames (0: not used, 1: used) - int sp2_frame_indicator; //!< Flag indicating whether switching SP frames should be encoded rather than SP frames (0: not used, 1: used) - int sp_output_indicator; //!< Flag indicating whether coefficients are output to allow future encoding of switchin SP frames (0: not used, 1: used) - signed char sp_output_filename[FILE_NAME_SIZE]; //! *************************************************************************************** */ - #ifndef _PARSET_H_ #define _PARSET_H_ -#include "parsetcommon.h" #include "nalucommon.h" +#include "parsetcommon.h" -static const byte ZZ_SCAN[16] = -{ 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 -}; +static const byte ZZ_SCAN[16] = {0, 1, 4, 8, 5, 2, 3, 6, + 9, 12, 13, 10, 7, 11, 14, 15}; -static const byte ZZ_SCAN8[64] = -{ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, - 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, - 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, - 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63 -}; +static const byte ZZ_SCAN8[64] = { + 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, + 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, + 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, + 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63}; -extern void Scaling_List(int *scalingList, int sizeOfScalingList, Boolean *UseDefaultScalingMatrix, Bitstream *s); +extern void Scaling_List(int *scalingList, int sizeOfScalingList, + Boolean *UseDefaultScalingMatrix, Bitstream *s); extern void InitVUI(seq_parameter_set_rbsp_t *sps); -extern int ReadVUI(DataPartition *p, seq_parameter_set_rbsp_t *sps); -extern int ReadHRDParameters(DataPartition *p, hrd_parameters_t *hrd); +extern int ReadVUI(DataPartition *p, seq_parameter_set_rbsp_t *sps); +extern int ReadHRDParameters(DataPartition *p, hrd_parameters_t *hrd); -extern void PPSConsistencyCheck (pic_parameter_set_rbsp_t *pps); -extern void SPSConsistencyCheck (seq_parameter_set_rbsp_t *sps); +extern void PPSConsistencyCheck(pic_parameter_set_rbsp_t *pps); +extern void SPSConsistencyCheck(seq_parameter_set_rbsp_t *sps); -extern void MakePPSavailable (VideoParameters *p_Vid, int id, pic_parameter_set_rbsp_t *pps); -extern void MakeSPSavailable (VideoParameters *p_Vid, int id, seq_parameter_set_rbsp_t *sps); +extern void MakePPSavailable(VideoParameters *p_Vid, int id, + pic_parameter_set_rbsp_t *pps); +extern void MakeSPSavailable(VideoParameters *p_Vid, int id, + seq_parameter_set_rbsp_t *sps); -extern void ProcessSPS (VideoParameters *p_Vid, NALU_t *nalu); -extern void ProcessPPS (VideoParameters *p_Vid, NALU_t *nalu); +extern void ProcessSPS(VideoParameters *p_Vid, NALU_t *nalu); +extern void ProcessPPS(VideoParameters *p_Vid, NALU_t *nalu); extern void CleanUpPPS(VideoParameters *p_Vid); -extern void activate_sps (VideoParameters *p_Vid, seq_parameter_set_rbsp_t *sps); -extern void activate_pps (VideoParameters *p_Vid, pic_parameter_set_rbsp_t *pps); +extern void activate_sps(VideoParameters *p_Vid, seq_parameter_set_rbsp_t *sps); +extern void activate_pps(VideoParameters *p_Vid, pic_parameter_set_rbsp_t *pps); -extern void UseParameterSet (Slice *currSlice); +extern void UseParameterSet(Slice *currSlice); #if (MVC_EXTENSION_ENABLE) -extern void SubsetSPSConsistencyCheck (subset_seq_parameter_set_rbsp_t *subset_sps); -extern void ProcessSubsetSPS (VideoParameters *p_Vid, NALU_t *nalu); +extern void +SubsetSPSConsistencyCheck(subset_seq_parameter_set_rbsp_t *subset_sps); +extern void ProcessSubsetSPS(VideoParameters *p_Vid, NALU_t *nalu); extern void mvc_vui_parameters_extension(MVCVUI_t *pMVCVUI, Bitstream *s); -extern void seq_parameter_set_mvc_extension(subset_seq_parameter_set_rbsp_t *subset_sps, Bitstream *s); -extern void init_subset_sps_list(subset_seq_parameter_set_rbsp_t *subset_sps_list, int iSize); +extern void +seq_parameter_set_mvc_extension(subset_seq_parameter_set_rbsp_t *subset_sps, + Bitstream *s); +extern void +init_subset_sps_list(subset_seq_parameter_set_rbsp_t *subset_sps_list, + int iSize); extern void reset_subset_sps(subset_seq_parameter_set_rbsp_t *subset_sps); -extern int GetBaseViewId(VideoParameters *p_Vid, subset_seq_parameter_set_rbsp_t **subset_sps); +extern int GetBaseViewId(VideoParameters *p_Vid, + subset_seq_parameter_set_rbsp_t **subset_sps); extern void get_max_dec_frame_buf_size(seq_parameter_set_rbsp_t *sps); #endif diff --git a/src/common/ldecod_src/inc/parsetcommon.h b/src/common/ldecod_src/inc/parsetcommon.h index 0deea77..5685da9 100644 --- a/src/common/ldecod_src/inc/parsetcommon.h +++ b/src/common/ldecod_src/inc/parsetcommon.h @@ -4,17 +4,17 @@ * \file * parsetcommon.h * \brief - * Picture and Sequence Parameter Sets, structures common to encoder and decoder + * Picture and Sequence Parameter Sets, structures common to encoder and + *decoder * * \date 25 November 2002 * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger *************************************************************************************** */ - - // In the JVT syntax, frequently flags are used that indicate the presence of // certain pieces of information in the NALU. Here, these flags are also // present. In the encoder, those bits indicate that the values signaled to @@ -28,205 +28,196 @@ #include "defines.h" -#define MAXIMUMPARSETRBSPSIZE 1500 -#define MAXIMUMPARSETNALUSIZE 1500 +#define MAXIMUMPARSETRBSPSIZE 1500 +#define MAXIMUMPARSETNALUSIZE 1500 -#define MAXSPS 32 -#define MAXPPS 256 +#define MAXSPS 32 +#define MAXPPS 256 -#define MAXIMUMVALUEOFcpb_cnt 32 -typedef struct -{ - unsigned int cpb_cnt_minus1; // ue(v) - unsigned int bit_rate_scale; // u(4) - unsigned int cpb_size_scale; // u(4) - unsigned int bit_rate_value_minus1 [MAXIMUMVALUEOFcpb_cnt]; // ue(v) - unsigned int cpb_size_value_minus1 [MAXIMUMVALUEOFcpb_cnt]; // ue(v) - unsigned int cbr_flag [MAXIMUMVALUEOFcpb_cnt]; // u(1) - unsigned int initial_cpb_removal_delay_length_minus1; // u(5) - unsigned int cpb_removal_delay_length_minus1; // u(5) - unsigned int dpb_output_delay_length_minus1; // u(5) - unsigned int time_offset_length; // u(5) +#define MAXIMUMVALUEOFcpb_cnt 32 +typedef struct { + unsigned int cpb_cnt_minus1; // ue(v) + unsigned int bit_rate_scale; // u(4) + unsigned int cpb_size_scale; // u(4) + unsigned int bit_rate_value_minus1[MAXIMUMVALUEOFcpb_cnt]; // ue(v) + unsigned int cpb_size_value_minus1[MAXIMUMVALUEOFcpb_cnt]; // ue(v) + unsigned int cbr_flag[MAXIMUMVALUEOFcpb_cnt]; // u(1) + unsigned int initial_cpb_removal_delay_length_minus1; // u(5) + unsigned int cpb_removal_delay_length_minus1; // u(5) + unsigned int dpb_output_delay_length_minus1; // u(5) + unsigned int time_offset_length; // u(5) } hrd_parameters_t; - -typedef struct -{ - Boolean aspect_ratio_info_present_flag; // u(1) - unsigned int aspect_ratio_idc; // u(8) - unsigned short sar_width; // u(16) - unsigned short sar_height; // u(16) - Boolean overscan_info_present_flag; // u(1) - Boolean overscan_appropriate_flag; // u(1) - Boolean video_signal_type_present_flag; // u(1) - unsigned int video_format; // u(3) - Boolean video_full_range_flag; // u(1) - Boolean colour_description_present_flag; // u(1) - unsigned int colour_primaries; // u(8) - unsigned int transfer_characteristics; // u(8) - unsigned int matrix_coefficients; // u(8) - Boolean chroma_location_info_present_flag; // u(1) - unsigned int chroma_sample_loc_type_top_field; // ue(v) - unsigned int chroma_sample_loc_type_bottom_field; // ue(v) - Boolean timing_info_present_flag; // u(1) - unsigned int num_units_in_tick; // u(32) - unsigned int time_scale; // u(32) - Boolean fixed_frame_rate_flag; // u(1) - Boolean nal_hrd_parameters_present_flag; // u(1) - hrd_parameters_t nal_hrd_parameters; // hrd_paramters_t - Boolean vcl_hrd_parameters_present_flag; // u(1) - hrd_parameters_t vcl_hrd_parameters; // hrd_paramters_t +typedef struct { + Boolean aspect_ratio_info_present_flag; // u(1) + unsigned int aspect_ratio_idc; // u(8) + unsigned short sar_width; // u(16) + unsigned short sar_height; // u(16) + Boolean overscan_info_present_flag; // u(1) + Boolean overscan_appropriate_flag; // u(1) + Boolean video_signal_type_present_flag; // u(1) + unsigned int video_format; // u(3) + Boolean video_full_range_flag; // u(1) + Boolean colour_description_present_flag; // u(1) + unsigned int colour_primaries; // u(8) + unsigned int transfer_characteristics; // u(8) + unsigned int matrix_coefficients; // u(8) + Boolean chroma_location_info_present_flag; // u(1) + unsigned int chroma_sample_loc_type_top_field; // ue(v) + unsigned int chroma_sample_loc_type_bottom_field; // ue(v) + Boolean timing_info_present_flag; // u(1) + unsigned int num_units_in_tick; // u(32) + unsigned int time_scale; // u(32) + Boolean fixed_frame_rate_flag; // u(1) + Boolean nal_hrd_parameters_present_flag; // u(1) + hrd_parameters_t nal_hrd_parameters; // hrd_paramters_t + Boolean vcl_hrd_parameters_present_flag; // u(1) + hrd_parameters_t vcl_hrd_parameters; // hrd_paramters_t // if ((nal_hrd_parameters_present_flag || (vcl_hrd_parameters_present_flag)) - Boolean low_delay_hrd_flag; // u(1) - Boolean pic_struct_present_flag; // u(1) - Boolean bitstream_restriction_flag; // u(1) - Boolean motion_vectors_over_pic_boundaries_flag; // u(1) - unsigned int max_bytes_per_pic_denom; // ue(v) - unsigned int max_bits_per_mb_denom; // ue(v) - unsigned int log2_max_mv_length_vertical; // ue(v) - unsigned int log2_max_mv_length_horizontal; // ue(v) - unsigned int num_reorder_frames; // ue(v) - unsigned int max_dec_frame_buffering; // ue(v) + Boolean low_delay_hrd_flag; // u(1) + Boolean pic_struct_present_flag; // u(1) + Boolean bitstream_restriction_flag; // u(1) + Boolean motion_vectors_over_pic_boundaries_flag; // u(1) + unsigned int max_bytes_per_pic_denom; // ue(v) + unsigned int max_bits_per_mb_denom; // ue(v) + unsigned int log2_max_mv_length_vertical; // ue(v) + unsigned int log2_max_mv_length_horizontal; // ue(v) + unsigned int num_reorder_frames; // ue(v) + unsigned int max_dec_frame_buffering; // ue(v) } vui_seq_parameters_t; +#define MAXnum_slice_groups_minus1 8 +typedef struct { + Boolean Valid; // indicates the parameter set is valid + unsigned int pic_parameter_set_id; // ue(v) + unsigned int seq_parameter_set_id; // ue(v) + Boolean entropy_coding_mode_flag; // u(1) + Boolean transform_8x8_mode_flag; // u(1) -#define MAXnum_slice_groups_minus1 8 -typedef struct -{ - Boolean Valid; // indicates the parameter set is valid - unsigned int pic_parameter_set_id; // ue(v) - unsigned int seq_parameter_set_id; // ue(v) - Boolean entropy_coding_mode_flag; // u(1) - Boolean transform_8x8_mode_flag; // u(1) - - Boolean pic_scaling_matrix_present_flag; // u(1) - int pic_scaling_list_present_flag[12]; // u(1) - int ScalingList4x4[6][16]; // se(v) - int ScalingList8x8[6][64]; // se(v) - Boolean UseDefaultScalingMatrix4x4Flag[6]; - Boolean UseDefaultScalingMatrix8x8Flag[6]; + Boolean pic_scaling_matrix_present_flag; // u(1) + int pic_scaling_list_present_flag[12]; // u(1) + int ScalingList4x4[6][16]; // se(v) + int ScalingList8x8[6][64]; // se(v) + Boolean UseDefaultScalingMatrix4x4Flag[6]; + Boolean UseDefaultScalingMatrix8x8Flag[6]; // if( pic_order_cnt_type < 2 ) in the sequence parameter set - Boolean bottom_field_pic_order_in_frame_present_flag; // u(1) - unsigned int num_slice_groups_minus1; // ue(v) - unsigned int slice_group_map_type; // ue(v) + Boolean bottom_field_pic_order_in_frame_present_flag; // u(1) + unsigned int num_slice_groups_minus1; // ue(v) + unsigned int slice_group_map_type; // ue(v) // if( slice_group_map_type = = 0 ) unsigned int run_length_minus1[MAXnum_slice_groups_minus1]; // ue(v) // else if( slice_group_map_type = = 2 ) - unsigned int top_left[MAXnum_slice_groups_minus1]; // ue(v) - unsigned int bottom_right[MAXnum_slice_groups_minus1]; // ue(v) + unsigned int top_left[MAXnum_slice_groups_minus1]; // ue(v) + unsigned int bottom_right[MAXnum_slice_groups_minus1]; // ue(v) // else if( slice_group_map_type = = 3 || 4 || 5 - Boolean slice_group_change_direction_flag; // u(1) - unsigned int slice_group_change_rate_minus1; // ue(v) + Boolean slice_group_change_direction_flag; // u(1) + unsigned int slice_group_change_rate_minus1; // ue(v) // else if( slice_group_map_type = = 6 ) - unsigned int pic_size_in_map_units_minus1; // ue(v) - byte *slice_group_id; // complete MBAmap u(v) + unsigned int pic_size_in_map_units_minus1; // ue(v) + byte *slice_group_id; // complete MBAmap u(v) - int num_ref_idx_l0_active_minus1; // ue(v) - int num_ref_idx_l1_active_minus1; // ue(v) - Boolean weighted_pred_flag; // u(1) - unsigned int weighted_bipred_idc; // u(2) - int pic_init_qp_minus26; // se(v) - int pic_init_qs_minus26; // se(v) - int chroma_qp_index_offset; // se(v) + int num_ref_idx_l0_active_minus1; // ue(v) + int num_ref_idx_l1_active_minus1; // ue(v) + Boolean weighted_pred_flag; // u(1) + unsigned int weighted_bipred_idc; // u(2) + int pic_init_qp_minus26; // se(v) + int pic_init_qs_minus26; // se(v) + int chroma_qp_index_offset; // se(v) - int second_chroma_qp_index_offset; // se(v) + int second_chroma_qp_index_offset; // se(v) - Boolean deblocking_filter_control_present_flag; // u(1) - Boolean constrained_intra_pred_flag; // u(1) - Boolean redundant_pic_cnt_present_flag; // u(1) + Boolean deblocking_filter_control_present_flag; // u(1) + Boolean constrained_intra_pred_flag; // u(1) + Boolean redundant_pic_cnt_present_flag; // u(1) } pic_parameter_set_rbsp_t; +#define MAXnum_ref_frames_in_pic_order_cnt_cycle 256 +typedef struct { + Boolean Valid; // indicates the parameter set is valid -#define MAXnum_ref_frames_in_pic_order_cnt_cycle 256 -typedef struct -{ - Boolean Valid; // indicates the parameter set is valid - - unsigned int profile_idc; // u(8) - Boolean constrained_set0_flag; // u(1) - Boolean constrained_set1_flag; // u(1) - Boolean constrained_set2_flag; // u(1) - Boolean constrained_set3_flag; // u(1) + unsigned int profile_idc; // u(8) + Boolean constrained_set0_flag; // u(1) + Boolean constrained_set1_flag; // u(1) + Boolean constrained_set2_flag; // u(1) + Boolean constrained_set3_flag; // u(1) #if (MVC_EXTENSION_ENABLE) - Boolean constrained_set4_flag; // u(1) + Boolean constrained_set4_flag; // u(1) #endif - unsigned int level_idc; // u(8) - unsigned int seq_parameter_set_id; // ue(v) - unsigned int chroma_format_idc; // ue(v) + unsigned int level_idc; // u(8) + unsigned int seq_parameter_set_id; // ue(v) + unsigned int chroma_format_idc; // ue(v) - Boolean seq_scaling_matrix_present_flag; // u(1) - int seq_scaling_list_present_flag[12]; // u(1) - int ScalingList4x4[6][16]; // se(v) - int ScalingList8x8[6][64]; // se(v) - Boolean UseDefaultScalingMatrix4x4Flag[6]; - Boolean UseDefaultScalingMatrix8x8Flag[6]; + Boolean seq_scaling_matrix_present_flag; // u(1) + int seq_scaling_list_present_flag[12]; // u(1) + int ScalingList4x4[6][16]; // se(v) + int ScalingList8x8[6][64]; // se(v) + Boolean UseDefaultScalingMatrix4x4Flag[6]; + Boolean UseDefaultScalingMatrix8x8Flag[6]; - unsigned int bit_depth_luma_minus8; // ue(v) - unsigned int bit_depth_chroma_minus8; // ue(v) - unsigned int log2_max_frame_num_minus4; // ue(v) + unsigned int bit_depth_luma_minus8; // ue(v) + unsigned int bit_depth_chroma_minus8; // ue(v) + unsigned int log2_max_frame_num_minus4; // ue(v) unsigned int pic_order_cnt_type; // if( pic_order_cnt_type == 0 ) - unsigned int log2_max_pic_order_cnt_lsb_minus4; // ue(v) + unsigned int log2_max_pic_order_cnt_lsb_minus4; // ue(v) // else if( pic_order_cnt_type == 1 ) - Boolean delta_pic_order_always_zero_flag; // u(1) - int offset_for_non_ref_pic; // se(v) - int offset_for_top_to_bottom_field; // se(v) - unsigned int num_ref_frames_in_pic_order_cnt_cycle; // ue(v) - // for( i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ ) - int offset_for_ref_frame[MAXnum_ref_frames_in_pic_order_cnt_cycle]; // se(v) - unsigned int num_ref_frames; // ue(v) - Boolean gaps_in_frame_num_value_allowed_flag; // u(1) - unsigned int pic_width_in_mbs_minus1; // ue(v) - unsigned int pic_height_in_map_units_minus1; // ue(v) - Boolean frame_mbs_only_flag; // u(1) + Boolean delta_pic_order_always_zero_flag; // u(1) + int offset_for_non_ref_pic; // se(v) + int offset_for_top_to_bottom_field; // se(v) + unsigned int num_ref_frames_in_pic_order_cnt_cycle; // ue(v) + // for( i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ ) + int offset_for_ref_frame[MAXnum_ref_frames_in_pic_order_cnt_cycle]; // se(v) + unsigned int num_ref_frames; // ue(v) + Boolean gaps_in_frame_num_value_allowed_flag; // u(1) + unsigned int pic_width_in_mbs_minus1; // ue(v) + unsigned int pic_height_in_map_units_minus1; // ue(v) + Boolean frame_mbs_only_flag; // u(1) // if( !frame_mbs_only_flag ) - Boolean mb_adaptive_frame_field_flag; // u(1) - Boolean direct_8x8_inference_flag; // u(1) - Boolean frame_cropping_flag; // u(1) - unsigned int frame_cropping_rect_left_offset; // ue(v) - unsigned int frame_cropping_rect_right_offset; // ue(v) - unsigned int frame_cropping_rect_top_offset; // ue(v) - unsigned int frame_cropping_rect_bottom_offset; // ue(v) - Boolean vui_parameters_present_flag; // u(1) - vui_seq_parameters_t vui_seq_parameters; // vui_seq_parameters_t - unsigned separate_colour_plane_flag; // u(1) + Boolean mb_adaptive_frame_field_flag; // u(1) + Boolean direct_8x8_inference_flag; // u(1) + Boolean frame_cropping_flag; // u(1) + unsigned int frame_cropping_rect_left_offset; // ue(v) + unsigned int frame_cropping_rect_right_offset; // ue(v) + unsigned int frame_cropping_rect_top_offset; // ue(v) + unsigned int frame_cropping_rect_bottom_offset; // ue(v) + Boolean vui_parameters_present_flag; // u(1) + vui_seq_parameters_t vui_seq_parameters; // vui_seq_parameters_t + unsigned separate_colour_plane_flag; // u(1) #if (MVC_EXTENSION_ENABLE) - int max_dec_frame_buffering; + int max_dec_frame_buffering; #endif } seq_parameter_set_rbsp_t; #if (MVC_EXTENSION_ENABLE) -typedef struct mvcvui_tag -{ - int num_ops_minus1; - signed char *temporal_id; - int *num_target_output_views_minus1; - int **view_id; - signed char *timing_info_present_flag; - int *num_units_in_tick; - int *time_scale; - signed char *fixed_frame_rate_flag; - signed char *nal_hrd_parameters_present_flag; - signed char *vcl_hrd_parameters_present_flag; - signed char *low_delay_hrd_flag; - signed char *pic_struct_present_flag; +typedef struct mvcvui_tag { + int num_ops_minus1; + signed char *temporal_id; + int *num_target_output_views_minus1; + int **view_id; + signed char *timing_info_present_flag; + int *num_units_in_tick; + int *time_scale; + signed char *fixed_frame_rate_flag; + signed char *nal_hrd_parameters_present_flag; + signed char *vcl_hrd_parameters_present_flag; + signed char *low_delay_hrd_flag; + signed char *pic_struct_present_flag; - //hrd parameters; - signed char cpb_cnt_minus1; - signed char bit_rate_scale; - signed char cpb_size_scale; - int bit_rate_value_minus1[32]; - int cpb_size_value_minus1[32]; - signed char cbr_flag[32]; - signed char initial_cpb_removal_delay_length_minus1; - signed char cpb_removal_delay_length_minus1; - signed char dpb_output_delay_length_minus1; - signed char time_offset_length; -}MVCVUI_t; + // hrd parameters; + signed char cpb_cnt_minus1; + signed char bit_rate_scale; + signed char cpb_size_scale; + int bit_rate_value_minus1[32]; + int cpb_size_value_minus1[32]; + signed char cbr_flag[32]; + signed char initial_cpb_removal_delay_length_minus1; + signed char cpb_removal_delay_length_minus1; + signed char dpb_output_delay_length_minus1; + signed char time_offset_length; +} MVCVUI_t; -typedef struct -{ +typedef struct { seq_parameter_set_rbsp_t sps; unsigned int bit_equal_to_one; @@ -241,7 +232,7 @@ typedef struct int **non_anchor_ref_l0; int *num_non_anchor_refs_l1; int **non_anchor_ref_l1; - + int num_level_values_signalled_minus1; int *level_idc; int *num_applicable_ops_minus1; @@ -251,21 +242,23 @@ typedef struct int **applicable_op_num_views_minus1; unsigned int mvc_vui_parameters_present_flag; - Boolean Valid; // indicates the parameter set is valid - MVCVUI_t MVCVUIParams; + Boolean Valid; // indicates the parameter set is valid + MVCVUI_t MVCVUIParams; } subset_seq_parameter_set_rbsp_t; -subset_seq_parameter_set_rbsp_t *AllocSubsetSPS (void); -void FreeSubsetSPS (subset_seq_parameter_set_rbsp_t *subset_sps); +subset_seq_parameter_set_rbsp_t *AllocSubsetSPS(void); +void FreeSubsetSPS(subset_seq_parameter_set_rbsp_t *subset_sps); #endif -pic_parameter_set_rbsp_t *AllocPPS (void); -seq_parameter_set_rbsp_t *AllocSPS (void); +pic_parameter_set_rbsp_t *AllocPPS(void); +seq_parameter_set_rbsp_t *AllocSPS(void); -void FreePPS (pic_parameter_set_rbsp_t *pps); -void FreeSPS (seq_parameter_set_rbsp_t *sps); +void FreePPS(pic_parameter_set_rbsp_t *pps); +void FreeSPS(seq_parameter_set_rbsp_t *sps); -int sps_is_equal(seq_parameter_set_rbsp_t *sps1, seq_parameter_set_rbsp_t *sps2); -int pps_is_equal(pic_parameter_set_rbsp_t *pps1, pic_parameter_set_rbsp_t *pps2); +int sps_is_equal(seq_parameter_set_rbsp_t *sps1, + seq_parameter_set_rbsp_t *sps2); +int pps_is_equal(pic_parameter_set_rbsp_t *pps1, + pic_parameter_set_rbsp_t *pps2); #endif diff --git a/src/common/ldecod_src/inc/quant.h b/src/common/ldecod_src/inc/quant.h index d88905f..f2ebdae 100644 --- a/src/common/ldecod_src/inc/quant.h +++ b/src/common/ldecod_src/inc/quant.h @@ -15,155 +15,101 @@ #define _QUANT_H_ // exported variables -static const int dequant_coef8[6][8][8] = -{ - { - {20, 19, 25, 19, 20, 19, 25, 19}, - {19, 18, 24, 18, 19, 18, 24, 18}, - {25, 24, 32, 24, 25, 24, 32, 24}, - {19, 18, 24, 18, 19, 18, 24, 18}, - {20, 19, 25, 19, 20, 19, 25, 19}, - {19, 18, 24, 18, 19, 18, 24, 18}, - {25, 24, 32, 24, 25, 24, 32, 24}, - {19, 18, 24, 18, 19, 18, 24, 18} - }, - { - {22, 21, 28, 21, 22, 21, 28, 21}, - {21, 19, 26, 19, 21, 19, 26, 19}, - {28, 26, 35, 26, 28, 26, 35, 26}, - {21, 19, 26, 19, 21, 19, 26, 19}, - {22, 21, 28, 21, 22, 21, 28, 21}, - {21, 19, 26, 19, 21, 19, 26, 19}, - {28, 26, 35, 26, 28, 26, 35, 26}, - {21, 19, 26, 19, 21, 19, 26, 19} - }, - { - {26, 24, 33, 24, 26, 24, 33, 24}, - {24, 23, 31, 23, 24, 23, 31, 23}, - {33, 31, 42, 31, 33, 31, 42, 31}, - {24, 23, 31, 23, 24, 23, 31, 23}, - {26, 24, 33, 24, 26, 24, 33, 24}, - {24, 23, 31, 23, 24, 23, 31, 23}, - {33, 31, 42, 31, 33, 31, 42, 31}, - {24, 23, 31, 23, 24, 23, 31, 23} - }, - { - {28, 26, 35, 26, 28, 26, 35, 26}, - {26, 25, 33, 25, 26, 25, 33, 25}, - {35, 33, 45, 33, 35, 33, 45, 33}, - {26, 25, 33, 25, 26, 25, 33, 25}, - {28, 26, 35, 26, 28, 26, 35, 26}, - {26, 25, 33, 25, 26, 25, 33, 25}, - {35, 33, 45, 33, 35, 33, 45, 33}, - {26, 25, 33, 25, 26, 25, 33, 25} - }, - { - {32, 30, 40, 30, 32, 30, 40, 30}, - {30, 28, 38, 28, 30, 28, 38, 28}, - {40, 38, 51, 38, 40, 38, 51, 38}, - {30, 28, 38, 28, 30, 28, 38, 28}, - {32, 30, 40, 30, 32, 30, 40, 30}, - {30, 28, 38, 28, 30, 28, 38, 28}, - {40, 38, 51, 38, 40, 38, 51, 38}, - {30, 28, 38, 28, 30, 28, 38, 28} - }, - { - {36, 34, 46, 34, 36, 34, 46, 34}, - {34, 32, 43, 32, 34, 32, 43, 32}, - {46, 43, 58, 43, 46, 43, 58, 43}, - {34, 32, 43, 32, 34, 32, 43, 32}, - {36, 34, 46, 34, 36, 34, 46, 34}, - {34, 32, 43, 32, 34, 32, 43, 32}, - {46, 43, 58, 43, 46, 43, 58, 43}, - {34, 32, 43, 32, 34, 32, 43, 32} - } -}; - +static const int dequant_coef8[6][8][8] = {{{20, 19, 25, 19, 20, 19, 25, 19}, + {19, 18, 24, 18, 19, 18, 24, 18}, + {25, 24, 32, 24, 25, 24, 32, 24}, + {19, 18, 24, 18, 19, 18, 24, 18}, + {20, 19, 25, 19, 20, 19, 25, 19}, + {19, 18, 24, 18, 19, 18, 24, 18}, + {25, 24, 32, 24, 25, 24, 32, 24}, + {19, 18, 24, 18, 19, 18, 24, 18}}, + {{22, 21, 28, 21, 22, 21, 28, 21}, + {21, 19, 26, 19, 21, 19, 26, 19}, + {28, 26, 35, 26, 28, 26, 35, 26}, + {21, 19, 26, 19, 21, 19, 26, 19}, + {22, 21, 28, 21, 22, 21, 28, 21}, + {21, 19, 26, 19, 21, 19, 26, 19}, + {28, 26, 35, 26, 28, 26, 35, 26}, + {21, 19, 26, 19, 21, 19, 26, 19}}, + {{26, 24, 33, 24, 26, 24, 33, 24}, + {24, 23, 31, 23, 24, 23, 31, 23}, + {33, 31, 42, 31, 33, 31, 42, 31}, + {24, 23, 31, 23, 24, 23, 31, 23}, + {26, 24, 33, 24, 26, 24, 33, 24}, + {24, 23, 31, 23, 24, 23, 31, 23}, + {33, 31, 42, 31, 33, 31, 42, 31}, + {24, 23, 31, 23, 24, 23, 31, 23}}, + {{28, 26, 35, 26, 28, 26, 35, 26}, + {26, 25, 33, 25, 26, 25, 33, 25}, + {35, 33, 45, 33, 35, 33, 45, 33}, + {26, 25, 33, 25, 26, 25, 33, 25}, + {28, 26, 35, 26, 28, 26, 35, 26}, + {26, 25, 33, 25, 26, 25, 33, 25}, + {35, 33, 45, 33, 35, 33, 45, 33}, + {26, 25, 33, 25, 26, 25, 33, 25}}, + {{32, 30, 40, 30, 32, 30, 40, 30}, + {30, 28, 38, 28, 30, 28, 38, 28}, + {40, 38, 51, 38, 40, 38, 51, 38}, + {30, 28, 38, 28, 30, 28, 38, 28}, + {32, 30, 40, 30, 32, 30, 40, 30}, + {30, 28, 38, 28, 30, 28, 38, 28}, + {40, 38, 51, 38, 40, 38, 51, 38}, + {30, 28, 38, 28, 30, 28, 38, 28}}, + {{36, 34, 46, 34, 36, 34, 46, 34}, + {34, 32, 43, 32, 34, 32, 43, 32}, + {46, 43, 58, 43, 46, 43, 58, 43}, + {34, 32, 43, 32, 34, 32, 43, 32}, + {36, 34, 46, 34, 36, 34, 46, 34}, + {34, 32, 43, 32, 34, 32, 43, 32}, + {46, 43, 58, 43, 46, 43, 58, 43}, + {34, 32, 43, 32, 34, 32, 43, 32}}}; //! Dequantization coefficients static const int dequant_coef[6][4][4] = { - { - { 10, 13, 10, 13}, - { 13, 16, 13, 16}, - { 10, 13, 10, 13}, - { 13, 16, 13, 16}}, - { - { 11, 14, 11, 14}, - { 14, 18, 14, 18}, - { 11, 14, 11, 14}, - { 14, 18, 14, 18}}, - { - { 13, 16, 13, 16}, - { 16, 20, 16, 20}, - { 13, 16, 13, 16}, - { 16, 20, 16, 20}}, - { - { 14, 18, 14, 18}, - { 18, 23, 18, 23}, - { 14, 18, 14, 18}, - { 18, 23, 18, 23}}, - { - { 16, 20, 16, 20}, - { 20, 25, 20, 25}, - { 16, 20, 16, 20}, - { 20, 25, 20, 25}}, - { - { 18, 23, 18, 23}, - { 23, 29, 23, 29}, - { 18, 23, 18, 23}, - { 23, 29, 23, 29}} -}; + {{10, 13, 10, 13}, {13, 16, 13, 16}, {10, 13, 10, 13}, {13, 16, 13, 16}}, + {{11, 14, 11, 14}, {14, 18, 14, 18}, {11, 14, 11, 14}, {14, 18, 14, 18}}, + {{13, 16, 13, 16}, {16, 20, 16, 20}, {13, 16, 13, 16}, {16, 20, 16, 20}}, + {{14, 18, 14, 18}, {18, 23, 18, 23}, {14, 18, 14, 18}, {18, 23, 18, 23}}, + {{16, 20, 16, 20}, {20, 25, 20, 25}, {16, 20, 16, 20}, {20, 25, 20, 25}}, + {{18, 23, 18, 23}, {23, 29, 23, 29}, {18, 23, 18, 23}, {23, 29, 23, 29}}}; -static const int quant_coef[6][4][4] = { - { - { 13107, 8066, 13107, 8066}, - { 8066, 5243, 8066, 5243}, - { 13107, 8066, 13107, 8066}, - { 8066, 5243, 8066, 5243}}, - { - { 11916, 7490, 11916, 7490}, - { 7490, 4660, 7490, 4660}, - { 11916, 7490, 11916, 7490}, - { 7490, 4660, 7490, 4660}}, - { - { 10082, 6554, 10082, 6554}, - { 6554, 4194, 6554, 4194}, - { 10082, 6554, 10082, 6554}, - { 6554, 4194, 6554, 4194}}, - { - { 9362, 5825, 9362, 5825}, - { 5825, 3647, 5825, 3647}, - { 9362, 5825, 9362, 5825}, - { 5825, 3647, 5825, 3647}}, - { - { 8192, 5243, 8192, 5243}, - { 5243, 3355, 5243, 3355}, - { 8192, 5243, 8192, 5243}, - { 5243, 3355, 5243, 3355}}, - { - { 7282, 4559, 7282, 4559}, - { 4559, 2893, 4559, 2893}, - { 7282, 4559, 7282, 4559}, - { 4559, 2893, 4559, 2893}} -}; +static const int quant_coef[6][4][4] = {{{13107, 8066, 13107, 8066}, + {8066, 5243, 8066, 5243}, + {13107, 8066, 13107, 8066}, + {8066, 5243, 8066, 5243}}, + {{11916, 7490, 11916, 7490}, + {7490, 4660, 7490, 4660}, + {11916, 7490, 11916, 7490}, + {7490, 4660, 7490, 4660}}, + {{10082, 6554, 10082, 6554}, + {6554, 4194, 6554, 4194}, + {10082, 6554, 10082, 6554}, + {6554, 4194, 6554, 4194}}, + {{9362, 5825, 9362, 5825}, + {5825, 3647, 5825, 3647}, + {9362, 5825, 9362, 5825}, + {5825, 3647, 5825, 3647}}, + {{8192, 5243, 8192, 5243}, + {5243, 3355, 5243, 3355}, + {8192, 5243, 8192, 5243}, + {5243, 3355, 5243, 3355}}, + {{7282, 4559, 7282, 4559}, + {4559, 2893, 4559, 2893}, + {7282, 4559, 7282, 4559}, + {4559, 2893, 4559, 2893}}}; // SP decoding parameter (EQ. 8-425) static const int A[4][4] = { - { 16, 20, 16, 20}, - { 20, 25, 20, 25}, - { 16, 20, 16, 20}, - { 20, 25, 20, 25} -}; + {16, 20, 16, 20}, {20, 25, 20, 25}, {16, 20, 16, 20}, {20, 25, 20, 25}}; // exported functions // quantization initialization -extern void init_qp_process (VideoParameters *p_Vid); +extern void init_qp_process(VideoParameters *p_Vid); extern void free_qp_matrices(VideoParameters *p_Vid); // For Q-matrix -extern void assign_quant_params (Slice *currslice); +extern void assign_quant_params(Slice *currslice); extern void CalculateQuant4x4Param(Slice *currslice); extern void CalculateQuant8x8Param(Slice *currslice); #endif - diff --git a/src/common/ldecod_src/inc/quant_params.h b/src/common/ldecod_src/inc/quant_params.h index 00b7fa6..b29d2fd 100644 --- a/src/common/ldecod_src/inc/quant_params.h +++ b/src/common/ldecod_src/inc/quant_params.h @@ -15,8 +15,8 @@ #define _QUANT_PARAMS_H_ typedef struct level_quant_params { - int OffsetComp; - int ScaleComp; + int OffsetComp; + int ScaleComp; int InvScaleComp; } LevelQuantParams; @@ -37,12 +37,12 @@ typedef struct quant_params { } QuantParameters; typedef struct quant_methods { - int block_y; - int block_x; - int qp; - int* ACLevel; - int* ACRun; - int **fadjust; + int block_y; + int block_x; + int qp; + int *ACLevel; + int *ACRun; + int **fadjust; LevelQuantParams **q_params; int *coeff_cost; const byte (*pos_scan)[2]; @@ -51,4 +51,3 @@ typedef struct quant_methods { } QuantMethods; #endif - diff --git a/src/common/ldecod_src/inc/report.h b/src/common/ldecod_src/inc/report.h index 29b97fd..c06b576 100644 --- a/src/common/ldecod_src/inc/report.h +++ b/src/common/ldecod_src/inc/report.h @@ -13,13 +13,15 @@ #ifndef _REPORT_H_ #define _REPORT_H_ #include "contributors.h" -#include "global.h" #include "enc_statistics.h" +#include "global.h" -extern void report ( VideoParameters *p_Vid, InputParameters *p_Inp, StatParameters *p_Stats ); -extern void information_init ( VideoParameters *p_Vid, InputParameters *p_Inp, StatParameters *p_Stats ); -extern void report_frame_statistic( VideoParameters *p_Vid, InputParameters *p_Inp ); -extern void report_stats_on_error (void); +extern void report(VideoParameters *p_Vid, InputParameters *p_Inp, + StatParameters *p_Stats); +extern void information_init(VideoParameters *p_Vid, InputParameters *p_Inp, + StatParameters *p_Stats); +extern void report_frame_statistic(VideoParameters *p_Vid, + InputParameters *p_Inp); +extern void report_stats_on_error(void); #endif - diff --git a/src/common/ldecod_src/inc/rtp.h b/src/common/ldecod_src/inc/rtp.h index 5c193e2..2d17676 100644 --- a/src/common/ldecod_src/inc/rtp.h +++ b/src/common/ldecod_src/inc/rtp.h @@ -13,34 +13,36 @@ #include "nalucommon.h" -#define MAXRTPPAYLOADLEN (65536 - 40) //!< Maximum payload size of an RTP packet */ -#define MAXRTPPACKETSIZE (65536 - 28) //!< Maximum size of an RTP packet incl. header */ -#define H264PAYLOADTYPE 105 //!< RTP paylaod type fixed here for simplicity*/ -#define H264SSRC 0x12345678 //!< SSRC, chosen to simplify debugging */ -#define RTP_TR_TIMESTAMP_MULT 1000 //!< should be something like 27 Mhz / 29.97 Hz */ +#define MAXRTPPAYLOADLEN \ + (65536 - 40) //!< Maximum payload size of an RTP packet */ +#define MAXRTPPACKETSIZE \ + (65536 - 28) //!< Maximum size of an RTP packet incl. header */ +#define H264PAYLOADTYPE 105 //!< RTP paylaod type fixed here for simplicity*/ +#define H264SSRC 0x12345678 //!< SSRC, chosen to simplify debugging */ +#define RTP_TR_TIMESTAMP_MULT \ + 1000 //!< should be something like 27 Mhz / 29.97 Hz */ -typedef struct -{ - unsigned int v; //!< Version, 2 bits, MUST be 0x2 - unsigned int p; //!< Padding bit, Padding MUST NOT be used - unsigned int x; //!< Extension, MUST be zero - unsigned int cc; /*!< CSRC count, normally 0 in the absence - of RTP mixers */ - unsigned int m; //!< Marker bit - unsigned int pt; //!< 7 bits, Payload Type, dynamically established - uint16 seq; /*!< RTP sequence number, incremented by one for - each sent packet */ - unsigned int timestamp; //!< timestamp, 27 MHz for H.264 - unsigned int ssrc; //!< Synchronization Source, chosen randomly - byte * payload; //!< the payload including payload headers - unsigned int paylen; //!< length of payload in bytes - byte * packet; //!< complete packet including header and payload - unsigned int packlen; //!< length of packet, typically paylen+12 +typedef struct { + unsigned int v; //!< Version, 2 bits, MUST be 0x2 + unsigned int p; //!< Padding bit, Padding MUST NOT be used + unsigned int x; //!< Extension, MUST be zero + unsigned int cc; /*!< CSRC count, normally 0 in the absence + of RTP mixers */ + unsigned int m; //!< Marker bit + unsigned int pt; //!< 7 bits, Payload Type, dynamically established + uint16 seq; /*!< RTP sequence number, incremented by one for + each sent packet */ + unsigned int timestamp; //!< timestamp, 27 MHz for H.264 + unsigned int ssrc; //!< Synchronization Source, chosen randomly + byte *payload; //!< the payload including payload headers + unsigned int paylen; //!< length of payload in bytes + byte *packet; //!< complete packet including header and payload + unsigned int packlen; //!< length of packet, typically paylen+12 } RTPpacket_t; -void DumpRTPHeader (RTPpacket_t *p); -int GetRTPNALU (VideoParameters *p_Vid, NALU_t *nalu); -void OpenRTPFile (VideoParameters *p_Vid, char *fn); +void DumpRTPHeader(RTPpacket_t *p); +int GetRTPNALU(VideoParameters *p_Vid, NALU_t *nalu); +void OpenRTPFile(VideoParameters *p_Vid, char *fn); void CloseRTPFile(VideoParameters *p_Vid); #endif diff --git a/src/common/ldecod_src/inc/sei.h b/src/common/ldecod_src/inc/sei.h index 9145c4f..192e587 100644 --- a/src/common/ldecod_src/inc/sei.h +++ b/src/common/ldecod_src/inc/sei.h @@ -59,26 +59,26 @@ typedef enum { SEI_BASE_VIEW_TEMPORAL_HRD, SEI_FRAME_PACKING_ARRANGEMENT, - SEI_MAX_ELEMENTS //!< number of maximum syntax elements + SEI_MAX_ELEMENTS //!< number of maximum syntax elements } SEI_type; #define MAX_FN 256 // tone mapping information -#define MAX_CODED_BIT_DEPTH 12 -#define MAX_SEI_BIT_DEPTH 12 -#define MAX_NUM_PIVOTS (1< ************************************************************************************* */ @@ -18,20 +20,21 @@ #include "win32.h" -typedef unsigned char byte; //!< byte type definition -typedef unsigned char uint8; //!< type definition for unsigned char (same as byte, 8 bits) -typedef unsigned short uint16; //!< type definition for unsigned short (16 bits) -typedef unsigned int uint32; //!< type definition for unsigned int (32 bits) +typedef unsigned char byte; //!< byte type definition +typedef unsigned char + uint8; //!< type definition for unsigned char (same as byte, 8 bits) +typedef unsigned short uint16; //!< type definition for unsigned short (16 bits) +typedef unsigned int uint32; //!< type definition for unsigned int (32 bits) -typedef signed char int8; -typedef short int16; -typedef int int32; +typedef signed char int8; +typedef short int16; +typedef int int32; #if (IMGTYPE == 0) -typedef byte imgpel; //!< pixel type -typedef uint16 distpel; //!< distortion type (for pixels) -typedef int32 distblk; //!< distortion type (for Macroblock) -typedef int32 transpel; //!< transformed coefficient type +typedef byte imgpel; //!< pixel type +typedef uint16 distpel; //!< distortion type (for pixels) +typedef int32 distblk; //!< distortion type (for Macroblock) +typedef int32 transpel; //!< transformed coefficient type #elif (IMGTYPE == 2) typedef float imgpel; typedef float distpel; @@ -40,8 +43,8 @@ typedef int32 transpel; #else typedef uint16 imgpel; typedef uint32 distpel; -typedef int64 distblk; -typedef int32 transpel; +typedef int64 distblk; +typedef int32 transpel; #endif #ifdef SPEC @@ -55,17 +58,14 @@ typedef int32 transpel; #else //! Boolean Type #ifdef FALSE -# define Boolean int +#define Boolean int #else -typedef enum { - FALSE, - TRUE -} Boolean; +typedef enum { FALSE, TRUE } Boolean; #endif #endif #ifndef MAXINT64 -#define MAXINT64 0x7fffffffffffffff +#define MAXINT64 0x7fffffffffffffff #endif /* @@ -85,4 +85,3 @@ typedef enum { */ #endif - diff --git a/src/common/ldecod_src/inc/types.h b/src/common/ldecod_src/inc/types.h index 32d39fa..d8ed0aa 100644 --- a/src/common/ldecod_src/inc/types.h +++ b/src/common/ldecod_src/inc/types.h @@ -7,7 +7,8 @@ * type definitions. * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * ************************************************************************ */ @@ -19,63 +20,39 @@ *********************************************************************** */ -typedef enum -{ +typedef enum { // YUV - PLANE_Y = 0, // PLANE_Y - PLANE_U = 1, // PLANE_Cb - PLANE_V = 2, // PLANE_Cr - // RGB + PLANE_Y = 0, // PLANE_Y + PLANE_U = 1, // PLANE_Cb + PLANE_V = 2, // PLANE_Cr + // RGB PLANE_G = 0, PLANE_B = 1, PLANE_R = 2 } ColorPlane; -enum { - LIST_0 = 0, - LIST_1 = 1, - BI_PRED = 2, - BI_PRED_L0 = 3, - BI_PRED_L1 = 4 -}; +enum { LIST_0 = 0, LIST_1 = 1, BI_PRED = 2, BI_PRED_L0 = 3, BI_PRED_L1 = 4 }; -enum { - ERROR_SAD = 0, - ERROR_SSE = 1, - ERROR_SATD = 2, - ERROR_PSATD = 3 -}; +enum { ERROR_SAD = 0, ERROR_SSE = 1, ERROR_SATD = 2, ERROR_PSATD = 3 }; -enum { - ME_Y_ONLY = 0, - ME_YUV_FP = 1, - ME_YUV_FP_SP = 2 -}; - - -enum { - DISTORTION_MSE = 0 -}; +enum { ME_Y_ONLY = 0, ME_YUV_FP = 1, ME_YUV_FP_SP = 2 }; +enum { DISTORTION_MSE = 0 }; //! Data Partitioning Modes -typedef enum -{ - PAR_DP_1, //!< no data partitioning is supported - PAR_DP_3 //!< data partitioning with 3 partitions +typedef enum { + PAR_DP_1, //!< no data partitioning is supported + PAR_DP_3 //!< data partitioning with 3 partitions } PAR_DP_TYPE; - //! Output File Types -typedef enum -{ - PAR_OF_ANNEXB, //!< Annex B byte stream format - PAR_OF_RTP //!< RTP packets in outfile +typedef enum { + PAR_OF_ANNEXB, //!< Annex B byte stream format + PAR_OF_RTP //!< RTP packets in outfile } PAR_OF_TYPE; //! Field Coding Types -typedef enum -{ +typedef enum { FRAME_CODING, FIELD_CODING, ADAPTIVE_CODING, @@ -83,8 +60,7 @@ typedef enum } CodingType; //! definition of H.264 syntax elements -typedef enum -{ +typedef enum { SE_HEADER, SE_PTYPE, SE_MBTYPE, @@ -106,41 +82,25 @@ typedef enum SE_MAX_ELEMENTS = 20 //!< number of maximum syntax elements } SE_type; // substituting the definitions in elements.h +typedef enum { NO_SLICES, FIXED_MB, FIXED_RATE, CALL_BACK } SliceMode; -typedef enum -{ - NO_SLICES, - FIXED_MB, - FIXED_RATE, - CALL_BACK -} SliceMode; +typedef enum { CAVLC, CABAC } SymbolMode; - -typedef enum -{ - CAVLC, - CABAC -} SymbolMode; - -typedef enum -{ - FULL_SEARCH = -1, - FAST_FULL_SEARCH = 0, - UM_HEX = 1, - UM_HEX_SIMPLE = 2, - EPZS = 3 +typedef enum { + FULL_SEARCH = -1, + FAST_FULL_SEARCH = 0, + UM_HEX = 1, + UM_HEX_SIMPLE = 2, + EPZS = 3 } SearchType; - -typedef enum -{ +typedef enum { FRAME, TOP_FIELD, BOTTOM_FIELD -} PictureStructure; //!< New enum for field processing +} PictureStructure; //!< New enum for field processing -typedef enum -{ +typedef enum { P_SLICE = 0, B_SLICE = 1, I_SLICE = 2, @@ -149,55 +109,46 @@ typedef enum NUM_SLICE_TYPES = 5 } SliceType; -//Motion Estimation levels -typedef enum -{ - F_PEL, //!< Full Pel refinement - H_PEL, //!< Half Pel refinement - Q_PEL //!< Quarter Pel refinement +// Motion Estimation levels +typedef enum { + F_PEL, //!< Full Pel refinement + H_PEL, //!< Half Pel refinement + Q_PEL //!< Quarter Pel refinement } MELevel; -typedef enum -{ - FAST_ACCESS = 0, //!< Fast/safe reference access - UMV_ACCESS = 1 //!< unconstrained reference access +typedef enum { + FAST_ACCESS = 0, //!< Fast/safe reference access + UMV_ACCESS = 1 //!< unconstrained reference access } REF_ACCESS_TYPE; -typedef enum -{ - IS_LUMA = 0, - IS_CHROMA = 1 -} Component_Type; +typedef enum { IS_LUMA = 0, IS_CHROMA = 1 } Component_Type; -typedef enum -{ +typedef enum { RC_MODE_0 = 0, RC_MODE_1 = 1, RC_MODE_2 = 2, RC_MODE_3 = 3 } RCModeType; - typedef enum { - SSE = 0, - SSE_RGB = 1, - PSNR = 2, - PSNR_RGB = 3, - SSIM = 4, - SSIM_RGB = 5, - MS_SSIM = 6, - MS_SSIM_RGB = 7, + SSE = 0, + SSE_RGB = 1, + PSNR = 2, + PSNR_RGB = 3, + SSIM = 4, + SSIM_RGB = 5, + MS_SSIM = 6, + MS_SSIM_RGB = 7, TOTAL_DIST_TYPES = 8 } distortion_types; typedef enum { - WP_MCPREC_PLUS0 = 4, - WP_MCPREC_PLUS1 = 5, - WP_MCPREC_MINUS0 = 6, - WP_MCPREC_MINUS1 = 7, + WP_MCPREC_PLUS0 = 4, + WP_MCPREC_PLUS1 = 5, + WP_MCPREC_MINUS0 = 6, + WP_MCPREC_MINUS1 = 7, WP_MCPREC_MINUS_PLUS0 = 8, - WP_REGULAR = 9 + WP_REGULAR = 9 } weighted_prediction_types; - #endif diff --git a/src/common/ldecod_src/inc/vlc.h b/src/common/ldecod_src/inc/vlc.h index d0f2098..f848ad2 100644 --- a/src/common/ldecod_src/inc/vlc.h +++ b/src/common/ldecod_src/inc/vlc.h @@ -16,97 +16,101 @@ #define _VLC_H_ //! gives CBP value from codeword number, both for intra and inter -static const byte NCBP[2][48][2]= -{ - { // 0 1 2 3 4 5 6 7 8 9 10 11 - {15, 0},{ 0, 1},{ 7, 2},{11, 4},{13, 8},{14, 3},{ 3, 5},{ 5,10},{10,12},{12,15},{ 1, 7},{ 2,11}, - { 4,13},{ 8,14},{ 6, 6},{ 9, 9},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0}, - { 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0}, - { 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0},{ 0, 0} - }, - { - {47, 0},{31,16},{15, 1},{ 0, 2},{23, 4},{27, 8},{29,32},{30, 3},{ 7, 5},{11,10},{13,12},{14,15}, - {39,47},{43, 7},{45,11},{46,13},{16,14},{ 3, 6},{ 5, 9},{10,31},{12,35},{19,37},{21,42},{26,44}, - {28,33},{35,34},{37,36},{42,40},{44,39},{ 1,43},{ 2,45},{ 4,46},{ 8,17},{17,18},{18,20},{20,24}, - {24,19},{ 6,21},{ 9,26},{22,28},{25,23},{32,27},{33,29},{34,30},{36,22},{40,25},{38,38},{41,41} - } -}; +static const byte NCBP[2][48][2] = { + {// 0 1 2 3 4 5 6 7 8 9 10 + // 11 + {15, 0}, {0, 1}, {7, 2}, {11, 4}, {13, 8}, {14, 3}, {3, 5}, {5, 10}, + {10, 12}, {12, 15}, {1, 7}, {2, 11}, {4, 13}, {8, 14}, {6, 6}, {9, 9}, + {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, + {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, + {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, + {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, + {{47, 0}, {31, 16}, {15, 1}, {0, 2}, {23, 4}, {27, 8}, {29, 32}, + {30, 3}, {7, 5}, {11, 10}, {13, 12}, {14, 15}, {39, 47}, {43, 7}, + {45, 11}, {46, 13}, {16, 14}, {3, 6}, {5, 9}, {10, 31}, {12, 35}, + {19, 37}, {21, 42}, {26, 44}, {28, 33}, {35, 34}, {37, 36}, {42, 40}, + {44, 39}, {1, 43}, {2, 45}, {4, 46}, {8, 17}, {17, 18}, {18, 20}, + {20, 24}, {24, 19}, {6, 21}, {9, 26}, {22, 28}, {25, 23}, {32, 27}, + {33, 29}, {34, 30}, {36, 22}, {40, 25}, {38, 38}, {41, 41}}}; //! for the linfo_levrun_inter routine -static const byte NTAB1[4][8][2] = -{ - {{1,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, - {{1,1},{1,2},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, - {{2,0},{1,3},{1,4},{1,5},{0,0},{0,0},{0,0},{0,0}}, - {{3,0},{2,1},{2,2},{1,6},{1,7},{1,8},{1,9},{4,0}}, +static const byte NTAB1[4][8][2] = { + {{1, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, + {{1, 1}, {1, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, + {{2, 0}, {1, 3}, {1, 4}, {1, 5}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, + {{3, 0}, {2, 1}, {2, 2}, {1, 6}, {1, 7}, {1, 8}, {1, 9}, {4, 0}}, }; -static const byte LEVRUN1[16]= -{ - 4,2,2,1,1,1,1,1,1,1,0,0,0,0,0,0, +static const byte LEVRUN1[16] = { + 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, }; - -static const byte NTAB2[4][8][2] = -{ - {{1,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, - {{1,1},{2,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, - {{1,2},{3,0},{4,0},{5,0},{0,0},{0,0},{0,0},{0,0}}, - {{1,3},{1,4},{2,1},{3,1},{6,0},{7,0},{8,0},{9,0}}, +static const byte NTAB2[4][8][2] = { + {{1, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, + {{1, 1}, {2, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, + {{1, 2}, {3, 0}, {4, 0}, {5, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, + {{1, 3}, {1, 4}, {2, 1}, {3, 1}, {6, 0}, {7, 0}, {8, 0}, {9, 0}}, }; //! for the linfo_levrun__c2x2 routine -static const byte LEVRUN3[4] = -{ - 2,1,0,0 +static const byte LEVRUN3[4] = {2, 1, 0, 0}; + +static const byte NTAB3[2][2][2] = { + {{1, 0}, {0, 0}}, + {{2, 0}, {1, 1}}, }; -static const byte NTAB3[2][2][2] = -{ - {{1,0},{0,0}}, - {{2,0},{1,1}}, -}; - -extern int se_v (char *tracestring, Bitstream *bitstream); -extern int ue_v (char *tracestring, Bitstream *bitstream); -extern Boolean u_1 (char *tracestring, Bitstream *bitstream); -extern int u_v (int LenInBits, char *tracestring, Bitstream *bitstream); -extern int i_v (int LenInBits, char *tracestring, Bitstream *bitstream); +extern int se_v(char *tracestring, Bitstream *bitstream); +extern int ue_v(char *tracestring, Bitstream *bitstream); +extern Boolean u_1(char *tracestring, Bitstream *bitstream); +extern int u_v(int LenInBits, char *tracestring, Bitstream *bitstream); +extern int i_v(int LenInBits, char *tracestring, Bitstream *bitstream); // CAVLC mapping extern void linfo_ue(int len, int info, int *value1, int *dummy); extern void linfo_se(int len, int info, int *value1, int *dummy); -extern void linfo_cbp_intra_normal(int len,int info,int *cbp, int *dummy); -extern void linfo_cbp_inter_normal(int len,int info,int *cbp, int *dummy); -extern void linfo_cbp_intra_other(int len,int info,int *cbp, int *dummy); -extern void linfo_cbp_inter_other(int len,int info,int *cbp, int *dummy); +extern void linfo_cbp_intra_normal(int len, int info, int *cbp, int *dummy); +extern void linfo_cbp_inter_normal(int len, int info, int *cbp, int *dummy); +extern void linfo_cbp_intra_other(int len, int info, int *cbp, int *dummy); +extern void linfo_cbp_inter_other(int len, int info, int *cbp, int *dummy); -extern void linfo_levrun_inter(int len,int info,int *level,int *irun); -extern void linfo_levrun_c2x2(int len,int info,int *level,int *irun); +extern void linfo_levrun_inter(int len, int info, int *level, int *irun); +extern void linfo_levrun_c2x2(int len, int info, int *level, int *irun); -extern int uvlc_startcode_follows(Slice *currSlice, int dummy); +extern int uvlc_startcode_follows(Slice *currSlice, int dummy); -extern int readSyntaxElement_VLC (SyntaxElement *sym, Bitstream *currStream); -extern int readSyntaxElement_UVLC(Macroblock *currMB, SyntaxElement *sym, struct datapartition *dp); -extern int readSyntaxElement_Intra4x4PredictionMode(SyntaxElement *sym, Bitstream *currStream); +extern int readSyntaxElement_VLC(SyntaxElement *sym, Bitstream *currStream); +extern int readSyntaxElement_UVLC(Macroblock *currMB, SyntaxElement *sym, + struct datapartition *dp); +extern int readSyntaxElement_Intra4x4PredictionMode(SyntaxElement *sym, + Bitstream *currStream); -extern int GetVLCSymbol (byte buffer[],int totbitoffset,int *info, int bytecount); -extern int GetVLCSymbol_IntraMode (byte buffer[],int totbitoffset,int *info, int bytecount); +extern int GetVLCSymbol(byte buffer[], int totbitoffset, int *info, + int bytecount); +extern int GetVLCSymbol_IntraMode(byte buffer[], int totbitoffset, int *info, + int bytecount); -extern int readSyntaxElement_FLC (SyntaxElement *sym, Bitstream *currStream); -extern int readSyntaxElement_NumCoeffTrailingOnes (SyntaxElement *sym, Bitstream *currStream, signed char *type); -extern int readSyntaxElement_NumCoeffTrailingOnesChromaDC(VideoParameters *p_Vid, SyntaxElement *sym, Bitstream *currStream); -extern int readSyntaxElement_Level_VLC0 (SyntaxElement *sym, Bitstream *currStream); -extern int readSyntaxElement_Level_VLCN (SyntaxElement *sym, int vlc, Bitstream *currStream); -extern int readSyntaxElement_TotalZeros (SyntaxElement *sym, Bitstream *currStream); -extern int readSyntaxElement_TotalZerosChromaDC (VideoParameters *p_Vid, SyntaxElement *sym, Bitstream *currStream); -extern int readSyntaxElement_Run (SyntaxElement *sym, Bitstream *currStream); -extern int GetBits (byte buffer[],int totbitoffset,int *info, int bitcount, int numbits); -extern int ShowBits (byte buffer[],int totbitoffset,int bitcount, int numbits); - -extern int more_rbsp_data (byte buffer[],int totbitoffset,int bytecount); +extern int readSyntaxElement_FLC(SyntaxElement *sym, Bitstream *currStream); +extern int readSyntaxElement_NumCoeffTrailingOnes(SyntaxElement *sym, + Bitstream *currStream, + signed char *type); +extern int readSyntaxElement_NumCoeffTrailingOnesChromaDC( + VideoParameters *p_Vid, SyntaxElement *sym, Bitstream *currStream); +extern int readSyntaxElement_Level_VLC0(SyntaxElement *sym, + Bitstream *currStream); +extern int readSyntaxElement_Level_VLCN(SyntaxElement *sym, int vlc, + Bitstream *currStream); +extern int readSyntaxElement_TotalZeros(SyntaxElement *sym, + Bitstream *currStream); +extern int readSyntaxElement_TotalZerosChromaDC(VideoParameters *p_Vid, + SyntaxElement *sym, + Bitstream *currStream); +extern int readSyntaxElement_Run(SyntaxElement *sym, Bitstream *currStream); +extern int GetBits(byte buffer[], int totbitoffset, int *info, int bitcount, + int numbits); +extern int ShowBits(byte buffer[], int totbitoffset, int bitcount, int numbits); +extern int more_rbsp_data(byte buffer[], int totbitoffset, int bytecount); #endif - diff --git a/src/common/ldecod_src/inc/vui_params.h b/src/common/ldecod_src/inc/vui_params.h index e7f9242..d0de8d2 100644 --- a/src/common/ldecod_src/inc/vui_params.h +++ b/src/common/ldecod_src/inc/vui_params.h @@ -14,8 +14,7 @@ #define _VUI_PARAMS_H_ // VUI Parameters -typedef struct vui_parameters -{ +typedef struct vui_parameters { int aspect_ratio_info_present_flag; int aspect_ratio_idc; int sar_width; @@ -27,7 +26,7 @@ typedef struct vui_parameters int video_full_range_flag; int colour_description_present_flag; int colour_primaries; - int transfer_characteristics; + int transfer_characteristics; int matrix_coefficients; int chroma_location_info_present_flag; int chroma_sample_loc_type_top_field; @@ -71,4 +70,3 @@ typedef struct vui_parameters } VUIParameters; #endif - diff --git a/src/common/ldecod_src/inc/win32.h b/src/common/ldecod_src/inc/win32.h index 78acffd..730f7fc 100644 --- a/src/common/ldecod_src/inc/win32.h +++ b/src/common/ldecod_src/inc/win32.h @@ -14,104 +14,108 @@ #ifndef _WIN32_H_ #define _WIN32_H_ -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include -#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) -# define OPENMP -# define NUM_THREADS 8 +#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && \ + !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) +#define OPENMP +#define NUM_THREADS 8 #endif -#if defined(WIN32) || defined (WIN64) || defined(SPEC_WINDOWS) -# include +#if defined(WIN32) || defined(WIN64) || defined(SPEC_WINDOWS) +#include #ifndef SPEC -# include -# include +#include +#include #endif /* !SPEC */ -# include +#include #if (_MSC_VER < 1400) -typedef int intptr_t; +typedef int intptr_t; #else -# include +#include #endif -#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) -# include +#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && \ + !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) +#include #endif -# define strcmp _strcmpi +#define strcmp _strcmpi -# define snprintf _snprintf -# define open _open -# define close _close -# define read _read -# define write _write -# define lseek _lseeki64 -# define fsync _commit -# define tell _telli64 +#define snprintf _snprintf +#define open _open +#define close _close +#define read _read +#define write _write +#define lseek _lseeki64 +#define fsync _commit +#define tell _telli64 #ifndef SPEC -# define TIMEB _timeb -# define TIME_T LARGE_INTEGER +#define TIMEB _timeb +#define TIME_T LARGE_INTEGER #endif /*! SPEC */ -# define OPENFLAGS_WRITE _O_WRONLY|_O_CREAT|_O_BINARY|_O_TRUNC -# define OPEN_PERMISSIONS _S_IREAD | _S_IWRITE -# define OPENFLAGS_READ _O_RDONLY|_O_BINARY +#define OPENFLAGS_WRITE _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC +#define OPEN_PERMISSIONS _S_IREAD | _S_IWRITE +#define OPENFLAGS_READ _O_RDONLY | _O_BINARY #ifndef SPEC_NO_UNDERBAR_INLINE -# define inline _inline +#define inline _inline #endif -# define forceinline __forceinline +#define forceinline __forceinline #else -# include -# include -# include -# include -# include -#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) -# include +#include +#include +#include +#include +#include +#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && \ + !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) +#include #endif -# define TIMEB timeb -# define TIME_T struct timeval -# define tell(fd) lseek(fd, 0, SEEK_CUR) -# define OPENFLAGS_WRITE O_WRONLY|O_CREAT|O_TRUNC -# define OPENFLAGS_READ O_RDONLY -# define OPEN_PERMISSIONS S_IRUSR | S_IWUSR +#define TIMEB timeb +#define TIME_T struct timeval +#define tell(fd) lseek(fd, 0, SEEK_CUR) +#define OPENFLAGS_WRITE O_WRONLY | O_CREAT | O_TRUNC +#define OPENFLAGS_READ O_RDONLY +#define OPEN_PERMISSIONS S_IRUSR | S_IWUSR -# if __STDC_VERSION__ >= 199901L - /* "inline" is a keyword */ -# else -# define inline /* nothing */ -# endif -# define forceinline inline +#if __STDC_VERSION__ >= 199901L +/* "inline" is a keyword */ +#else +#define inline /* nothing */ +#endif +#define forceinline inline #endif -#if (defined(WIN32) || defined(WIN64) || defined(SPEC_WINDOWS)) && !defined(__GNUC__) -typedef __int64 int64; -typedef unsigned __int64 uint64; -# define FORMAT_OFF_T "I64d" -# ifndef INT64_MIN -# define INT64_MIN (-9223372036854775807i64 - 1i64) -# endif +#if (defined(WIN32) || defined(WIN64) || defined(SPEC_WINDOWS)) && \ + !defined(__GNUC__) +typedef __int64 int64; +typedef unsigned __int64 uint64; +#define FORMAT_OFF_T "I64d" +#ifndef INT64_MIN +#define INT64_MIN (-9223372036854775807i64 - 1i64) +#endif #else #if defined(SPEC_USE_LL_INT64) typedef long long int64; -typedef unsigned long long uint64; -# define FORMAT_OFF_T "lld" +typedef unsigned long long uint64; +#define FORMAT_OFF_T "lld" #else typedef int64_t int64; typedef uint64_t uint64; -# define FORMAT_OFF_T "ld" -#endif /* SPEC_USE_LL_INT64 */ -# ifndef INT64_MIN -# define INT64_MIN (-9223372036854775807LL - 1LL) -# endif +#define FORMAT_OFF_T "ld" +#endif /* SPEC_USE_LL_INT64 */ +#ifndef INT64_MIN +#define INT64_MIN (-9223372036854775807LL - 1LL) +#endif #endif #ifndef SPEC -void gettime(TIME_T* time); -int64 timediff(TIME_T* start, TIME_T* end); +void gettime(TIME_T *time); +int64 timediff(TIME_T *start, TIME_T *end); int64 timenorm(int64 cur_time); #endif diff --git a/src/common/ldecod_src/input.c b/src/common/ldecod_src/input.c index 7c69876..81e5c75 100644 --- a/src/common/ldecod_src/input.c +++ b/src/common/ldecod_src/input.c @@ -7,10 +7,11 @@ * Input related functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Karsten Shring * - Alexis Michael Tourapis - * + * ************************************************************************************* */ #include "contributors.h" @@ -19,14 +20,20 @@ #include #include "global.h" -#include "input.h" #include "img_io.h" +#include "input.h" #include "memalloc.h" -void buf2img_basic ( imgpel** imgX, unsigned char* buf, int size_x, int size_y, int o_size_x, int o_size_y, int symbol_size_in_bytes, int bitshift); -void buf2img_endian ( imgpel** imgX, unsigned char* buf, int size_x, int size_y, int o_size_x, int o_size_y, int symbol_size_in_bytes, int bitshift); -void buf2img_bitshift ( imgpel** imgX, unsigned char* buf, int size_x, int size_y, int o_size_x, int o_size_y, int symbol_size_in_bytes, int bitshift); -void fillPlane ( imgpel** imgX, int nVal, int size_x, int size_y); +void buf2img_basic(imgpel **imgX, unsigned char *buf, int size_x, int size_y, + int o_size_x, int o_size_y, int symbol_size_in_bytes, + int bitshift); +void buf2img_endian(imgpel **imgX, unsigned char *buf, int size_x, int size_y, + int o_size_x, int o_size_y, int symbol_size_in_bytes, + int bitshift); +void buf2img_bitshift(imgpel **imgX, unsigned char *buf, int size_x, int size_y, + int o_size_x, int o_size_y, int symbol_size_in_bytes, + int bitshift); +void fillPlane(imgpel **imgX, int nVal, int size_x, int size_y); /*! ************************************************************************ @@ -37,20 +44,18 @@ void fillPlane ( imgpel** imgX, int nVal, int size_x, int size_y); * 1, big-endian (e.g. SPARC, MIPS, PowerPC) ************************************************************************ */ -void initInput(VideoParameters *p_Vid, FrameFormat *source, FrameFormat *output) -{ - if (source->bit_depth[0] == output->bit_depth[0] && source->bit_depth[1] == output->bit_depth[1]) - { - if (( sizeof(signed char) != sizeof (imgpel)) && testEndian()) +void initInput(VideoParameters *p_Vid, FrameFormat *source, + FrameFormat *output) { + if (source->bit_depth[0] == output->bit_depth[0] && + source->bit_depth[1] == output->bit_depth[1]) { + if ((sizeof(signed char) != sizeof(imgpel)) && testEndian()) p_Vid->buf2img = buf2img_endian; else p_Vid->buf2img = buf2img_basic; - } - else + } else p_Vid->buf2img = buf2img_bitshift; } - /*! ************************************************************************ * \brief @@ -60,16 +65,15 @@ void initInput(VideoParameters *p_Vid, FrameFormat *source, FrameFormat *output) * 1, big-endian (e.g. SPARC, MIPS, PowerPC) ************************************************************************ */ -int testEndian(void) -{ +int testEndian(void) { short s; byte *p; - p=(byte*)&s; + p = (byte *)&s; - s=1; + s = 1; - return (*p==0); + return (*p == 0); } #if (DEBUG_BITDEPTH) @@ -79,15 +83,12 @@ int testEndian(void) * Masking to ensure data within appropriate range ************************************************************************ */ -static void MaskMSBs (imgpel** imgX, int mask, int width, int height) -{ - int i,j; +static void MaskMSBs(imgpel **imgX, int mask, int width, int height) { + int i, j; - for (j=0; j < height; j++) - { - for (i=0; i < width; i++) - { - imgX[j][i]=(imgpel) (imgX[j][i] & mask); + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + imgX[j][i] = (imgpel)(imgX[j][i] & mask); } } } @@ -99,25 +100,19 @@ static void MaskMSBs (imgpel** imgX, int mask, int width, int height) * Fill plane with constant value ************************************************************************ */ -void fillPlane ( imgpel** imgX, //!< Pointer to image plane - int nVal, //!< Fill value (currently 0 <= nVal < 256) - int size_x, //!< horizontal size of picture - int size_y //!< vertical size of picture - ) -{ +void fillPlane(imgpel **imgX, //!< Pointer to image plane + int nVal, //!< Fill value (currently 0 <= nVal < 256) + int size_x, //!< horizontal size of picture + int size_y //!< vertical size of picture +) { int j, i; - if (sizeof(imgpel) == sizeof(signed char)) - { + if (sizeof(imgpel) == sizeof(signed char)) { memset(imgX[0], nVal, size_y * size_x); - } - else - { - for (j = 0; j < size_y; j++) - { - for (i = 0; i < size_x; i++) - { - imgX[j][i] = (imgpel) nVal; + } else { + for (j = 0; j < size_y; j++) { + for (i = 0; i < size_x; i++) { + imgX[j][i] = (imgpel)nVal; } } } @@ -129,12 +124,12 @@ void fillPlane ( imgpel** imgX, //!< Pointer to image plane * Deinterleave file read buffer to source picture structure ************************************************************************ */ -static void deinterleave ( unsigned char** input, //!< input buffer - unsigned char** output, //!< output buffer - FrameFormat *source, //!< format of source buffer - int symbol_size_in_bytes //!< number of bytes per symbol - ) -{ +static void +deinterleave(unsigned char **input, //!< input buffer + unsigned char **output, //!< output buffer + FrameFormat *source, //!< format of source buffer + int symbol_size_in_bytes //!< number of bytes per symbol +) { // original buffer unsigned char *icmp0 = *input; // final buffer @@ -144,11 +139,10 @@ static void deinterleave ( unsigned char** input, //!< input buffer unsigned char *ocmp2 = ocmp1 + symbol_size_in_bytes * source->size_cmp[1]; int i; - - if (source->yuv_format == YUV420) // UYYVYY + + if (source->yuv_format == YUV420) // UYYVYY { - for (i = 0; i < source->size_cmp[1]; i++) - { + for (i = 0; i < source->size_cmp[1]; i++) { memcpy(ocmp1, icmp0, symbol_size_in_bytes); ocmp1 += symbol_size_in_bytes; icmp0 += symbol_size_in_bytes; @@ -164,14 +158,14 @@ static void deinterleave ( unsigned char** input, //!< input buffer } // flip buffers - icmp0 = *input; - *input = *output; + icmp0 = *input; + *input = *output; *output = icmp0; } - if (source->yuv_format == YUV422) // YUYV/YUY2. We should also maybe add UYVY given it's popularity + if (source->yuv_format == + YUV422) // YUYV/YUY2. We should also maybe add UYVY given it's popularity { - for (i = 0; i < source->size_cmp[1]; i++) - { + for (i = 0; i < source->size_cmp[1]; i++) { // Y memcpy(ocmp0, icmp0, symbol_size_in_bytes); ocmp0 += symbol_size_in_bytes; @@ -191,14 +185,11 @@ static void deinterleave ( unsigned char** input, //!< input buffer } // flip buffers - icmp0 = *input; - *input = *output; + icmp0 = *input; + *input = *output; *output = icmp0; - } - else if (source->yuv_format == YUV444) - { - for (i = 0; i < source->size_cmp[0]; i++) - { + } else if (source->yuv_format == YUV444) { + for (i = 0; i < source->size_cmp[0]; i++) { memcpy(ocmp0, icmp0, symbol_size_in_bytes); ocmp0 += symbol_size_in_bytes; icmp0 += symbol_size_in_bytes; @@ -210,8 +201,8 @@ static void deinterleave ( unsigned char** input, //!< input buffer icmp0 += symbol_size_in_bytes; } // flip buffers - icmp0 = *input; - *input = *output; + icmp0 = *input; + *input = *output; *output = icmp0; } } @@ -222,235 +213,236 @@ static void deinterleave ( unsigned char** input, //!< input buffer * Convert file read buffer to source picture structure ************************************************************************ */ -void buf2img_bitshift ( imgpel** imgX, //!< Pointer to image plane - unsigned char* buf, //!< Buffer for file output - int size_x, //!< horizontal size of picture - int size_y, //!< vertical size of picture - int o_size_x, //!< horizontal size of picture - int o_size_y, //!< vertical size of picture - int symbol_size_in_bytes, //!< number of bytes in file used for one pixel - int bitshift //!< variable for bitdepth expansion - ) -{ - int i,j; +void buf2img_bitshift( + imgpel **imgX, //!< Pointer to image plane + unsigned char *buf, //!< Buffer for file output + int size_x, //!< horizontal size of picture + int size_y, //!< vertical size of picture + int o_size_x, //!< horizontal size of picture + int o_size_y, //!< vertical size of picture + int symbol_size_in_bytes, //!< number of bytes in file used for one pixel + int bitshift //!< variable for bitdepth expansion +) { + int i, j; uint16 tmp16, ui16; - unsigned long tmp32, ui32; + unsigned long tmp32, ui32; // This test should be done once. - if (((symbol_size_in_bytes << 3) - bitshift) > (int) (sizeof(imgpel)<< 3)) - { - error ("Source picture has higher bit depth than imgpel data type. \nPlease recompile with larger data type for imgpel.", 500); + if (((symbol_size_in_bytes << 3) - bitshift) > (int)(sizeof(imgpel) << 3)) { + error("Source picture has higher bit depth than imgpel data type. \nPlease " + "recompile with larger data type for imgpel.", + 500); } - if (testEndian()) - { - if (size_x != o_size_x || size_y != o_size_y) - { - error ("Rescaling not supported in big endian architectures. ", 500); + if (testEndian()) { + if (size_x != o_size_x || size_y != o_size_y) { + error("Rescaling not supported in big endian architectures. ", 500); } // big endian - switch (symbol_size_in_bytes) - { - case 1: - { - for(j = 0; j < o_size_y; j++) - for(i = 0; i < o_size_x; i++) - { - imgX[j][i]= (imgpel) rshift_rnd(buf[i + j*size_x], bitshift); - } - break; + switch (symbol_size_in_bytes) { + case 1: { + for (j = 0; j < o_size_y; j++) + for (i = 0; i < o_size_x; i++) { + imgX[j][i] = (imgpel)rshift_rnd(buf[i + j * size_x], bitshift); + } + break; + } + case 2: { + for (j = 0; j < o_size_y; j++) + for (i = 0; i < o_size_x; i++) { + memcpy(&tmp16, buf + ((i + j * size_x) * 2), 2); + ui16 = (tmp16 >> 8) | ((tmp16 & 0xFF) << 8); + imgX[j][i] = (imgpel)rshift_rnd(ui16, bitshift); + } + break; + } + case 4: { + for (j = 0; j < o_size_y; j++) + for (i = 0; i < o_size_x; i++) { + memcpy(&tmp32, buf + ((i + j * size_x) * 4), 4); + ui32 = ((tmp32 & 0xFF00) << 8) | ((tmp32 & 0xFF) << 24) | + ((tmp32 & 0xFF0000) >> 8) | ((tmp32 & 0xFF000000) >> 24); + imgX[j][i] = (imgpel)rshift_rnd(ui32, bitshift); + } + } + default: { + error("reading only from formats of 8, 16 or 32 bit allowed on big " + "endian architecture", + 500); + break; + } + } + } else { + // little endian + int j_pos; + if (size_x == o_size_x && size_y == o_size_y) { + for (j = 0; j < o_size_y; j++) { + j_pos = j * size_x; + for (i = 0; i < o_size_x; i++) { + ui16 = 0; + memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), + symbol_size_in_bytes); + imgX[j][i] = (imgpel)rshift_rnd(ui16, bitshift); + } } - case 2: - { - for(j = 0; j < o_size_y; j++) - for(i = 0; i < o_size_x; i++) - { - memcpy(&tmp16, buf+((i+j*size_x)*2), 2); - ui16 = (tmp16 >> 8) | ((tmp16&0xFF)<<8); - imgX[j][i] = (imgpel) rshift_rnd(ui16, bitshift); - } - break; - } - case 4: - { - for(j = 0; j < o_size_y; j++) - for(i = 0; i < o_size_x; i++) - { - memcpy(&tmp32, buf+((i+j*size_x)*4), 4); - ui32 = ((tmp32&0xFF00)<<8) | ((tmp32&0xFF)<<24) | ((tmp32&0xFF0000)>>8) | ((tmp32&0xFF000000)>>24); - imgX[j][i] = (imgpel) rshift_rnd(ui32, bitshift); - } - } - default: - { - error ("reading only from formats of 8, 16 or 32 bit allowed on big endian architecture", 500); - break; + } else { + int iminwidth = imin(size_x, o_size_x); + int iminheight = imin(size_y, o_size_y); + int dst_offset_x = 0, dst_offset_y = 0; + int offset_x = 0, offset_y = 0; // currently not used + + // determine whether we need to center the copied frame or crop it + if (o_size_x >= size_x) + dst_offset_x = (o_size_x - size_x) >> 1; + + if (o_size_y >= size_y) + dst_offset_y = (o_size_y - size_y) >> 1; + + // check copied area to avoid copying memory garbage + // source + iminwidth = + ((offset_x + iminwidth) > size_x) ? (size_x - offset_x) : iminwidth; + iminheight = + ((offset_y + iminheight) > size_y) ? (size_y - offset_y) : iminheight; + // destination + iminwidth = ((dst_offset_x + iminwidth) > o_size_x) + ? (o_size_x - dst_offset_x) + : iminwidth; + iminheight = ((dst_offset_y + iminheight) > o_size_y) + ? (o_size_y - dst_offset_y) + : iminheight; + + for (j = 0; j < iminheight; j++) { + j_pos = (j + offset_y) * size_x + offset_x; + for (i = 0; i < iminwidth; i++) { + ui16 = 0; + memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), + symbol_size_in_bytes); + imgX[j + dst_offset_y][i + dst_offset_x] = + (imgpel)rshift_rnd(ui16, bitshift); + } } } } - else - { - // little endian - int j_pos; - if (size_x == o_size_x && size_y == o_size_y) - { - for (j = 0; j < o_size_y; j++) - { - j_pos = j*size_x; - for (i = 0; i < o_size_x; i++) - { - ui16=0; - memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), symbol_size_in_bytes); - imgX[j][i] = (imgpel) rshift_rnd(ui16,bitshift); - } - } - } - else - { - int iminwidth = imin(size_x, o_size_x); - int iminheight = imin(size_y, o_size_y); - int dst_offset_x = 0, dst_offset_y = 0; - int offset_x = 0, offset_y = 0; // currently not used - - // determine whether we need to center the copied frame or crop it - if ( o_size_x >= size_x ) - dst_offset_x = ( o_size_x - size_x ) >> 1; - - if (o_size_y >= size_y) - dst_offset_y = ( o_size_y - size_y ) >> 1; - - // check copied area to avoid copying memory garbage - // source - iminwidth = ( (offset_x + iminwidth ) > size_x ) ? (size_x - offset_x) : iminwidth; - iminheight = ( (offset_y + iminheight) > size_y ) ? (size_y - offset_y) : iminheight; - // destination - iminwidth = ( (dst_offset_x + iminwidth ) > o_size_x ) ? (o_size_x - dst_offset_x) : iminwidth; - iminheight = ( (dst_offset_y + iminheight) > o_size_y ) ? (o_size_y - dst_offset_y) : iminheight; - - for (j=0; j < iminheight; j++) - { - j_pos = (j + offset_y) * size_x + offset_x; - for (i=0; i < iminwidth; i++) - { - ui16=0; - memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), symbol_size_in_bytes); - imgX[j + dst_offset_y][i + dst_offset_x] = (imgpel) rshift_rnd(ui16,bitshift); - } - } - } - } } - /*! ************************************************************************ * \brief * Convert file read buffer to source picture structure ************************************************************************ */ -void buf2img_basic (imgpel** imgX, //!< Pointer to image plane - unsigned char* buf, //!< Buffer for file output - int size_x, //!< horizontal size of picture - int size_y, //!< vertical size of picture - int o_size_x, //!< horizontal size of picture - int o_size_y, //!< vertical size of picture - int symbol_size_in_bytes, //!< number of bytes in file used for one pixel - int dummy //!< dummy variable used for allowing function pointer use - ) -{ - int i,j; - unsigned char* temp_buf = buf; +void buf2img_basic( + imgpel **imgX, //!< Pointer to image plane + unsigned char *buf, //!< Buffer for file output + int size_x, //!< horizontal size of picture + int size_y, //!< vertical size of picture + int o_size_x, //!< horizontal size of picture + int o_size_y, //!< vertical size of picture + int symbol_size_in_bytes, //!< number of bytes in file used for one pixel + int dummy //!< dummy variable used for allowing function pointer use +) { + int i, j; + unsigned char *temp_buf = buf; - if (symbol_size_in_bytes> (int) sizeof(imgpel)) - { - error ("Source picture has higher bit depth than imgpel data type. \nPlease recompile with larger data type for imgpel.", 500); + if (symbol_size_in_bytes > (int)sizeof(imgpel)) { + error("Source picture has higher bit depth than imgpel data type. \nPlease " + "recompile with larger data type for imgpel.", + 500); } - if (( sizeof (imgpel) == symbol_size_in_bytes)) - { + if ((sizeof(imgpel) == symbol_size_in_bytes)) { // imgpel == pixel_in_file -> simple copy if (size_x == o_size_x && size_y == o_size_y) memcpy(&imgX[0][0], temp_buf, size_x * size_y * sizeof(imgpel)); - else - { - int iminwidth = imin(size_x, o_size_x); - int iminheight = imin(size_y, o_size_y); - int dst_offset_x = 0, dst_offset_y = 0; + else { + int iminwidth = imin(size_x, o_size_x); + int iminheight = imin(size_y, o_size_y); + int dst_offset_x = 0, dst_offset_y = 0; int offset_x = 0, offset_y = 0; // currently not used - - // determine whether we need to center the copied frame or crop it - if ( o_size_x >= size_x ) - dst_offset_x = ( o_size_x - size_x ) >> 1; - if (o_size_y >= size_y) - dst_offset_y = ( o_size_y - size_y ) >> 1; + // determine whether we need to center the copied frame or crop it + if (o_size_x >= size_x) + dst_offset_x = (o_size_x - size_x) >> 1; + + if (o_size_y >= size_y) + dst_offset_y = (o_size_y - size_y) >> 1; // check copied area to avoid copying memory garbage // source - iminwidth = ( (offset_x + iminwidth ) > size_x ) ? (size_x - offset_x) : iminwidth; - iminheight = ( (offset_y + iminheight) > size_y ) ? (size_y - offset_y) : iminheight; + iminwidth = + ((offset_x + iminwidth) > size_x) ? (size_x - offset_x) : iminwidth; + iminheight = + ((offset_y + iminheight) > size_y) ? (size_y - offset_y) : iminheight; // destination - iminwidth = ( (dst_offset_x + iminwidth ) > o_size_x ) ? (o_size_x - dst_offset_x) : iminwidth; - iminheight = ( (dst_offset_y + iminheight) > o_size_y ) ? (o_size_y - dst_offset_y) : iminheight; + iminwidth = ((dst_offset_x + iminwidth) > o_size_x) + ? (o_size_x - dst_offset_x) + : iminwidth; + iminheight = ((dst_offset_y + iminheight) > o_size_y) + ? (o_size_y - dst_offset_y) + : iminheight; - for (i=0; i= size_x ) - dst_offset_x = ( o_size_x - size_x ) >> 1; - if (o_size_y >= size_y) - dst_offset_y = ( o_size_y - size_y ) >> 1; + // determine whether we need to center the copied frame or crop it + if (o_size_x >= size_x) + dst_offset_x = (o_size_x - size_x) >> 1; + + if (o_size_y >= size_y) + dst_offset_y = (o_size_y - size_y) >> 1; // check copied area to avoid copying memory garbage // source - iminwidth = ( (offset_x + iminwidth ) > size_x ) ? (size_x - offset_x) : iminwidth; - iminheight = ( (offset_y + iminheight) > size_y ) ? (size_y - offset_y) : iminheight; + iminwidth = + ((offset_x + iminwidth) > size_x) ? (size_x - offset_x) : iminwidth; + iminheight = + ((offset_y + iminheight) > size_y) ? (size_y - offset_y) : iminheight; // destination - iminwidth = ( (dst_offset_x + iminwidth ) > o_size_x ) ? (o_size_x - dst_offset_x) : iminwidth; - iminheight = ( (dst_offset_y + iminheight) > o_size_y ) ? (o_size_y - dst_offset_y) : iminheight; + iminwidth = ((dst_offset_x + iminwidth) > o_size_x) + ? (o_size_x - dst_offset_x) + : iminwidth; + iminheight = ((dst_offset_y + iminheight) > o_size_y) + ? (o_size_y - dst_offset_y) + : iminheight; for (j = 0; j < iminheight; j++) { - memcpy(&imgX[j + dst_offset_y][dst_offset_x], &(temp_buf[(j + offset_y) * size_x + offset_x]), iminwidth * sizeof(imgpel)); + memcpy(&imgX[j + dst_offset_y][dst_offset_x], + &(temp_buf[(j + offset_y) * size_x + offset_x]), + iminwidth * sizeof(imgpel)); } - for (j=0; j < iminheight; j++) - { + for (j = 0; j < iminheight; j++) { j_pos = (j + offset_y) * size_x + offset_x; - for (i=0; i < iminwidth; i++) - { + for (i = 0; i < iminwidth; i++) { ui16 = 0; - memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), symbol_size_in_bytes); - imgX[j + dst_offset_y][i + dst_offset_x]= (imgpel) ui16; + memcpy(&(ui16), buf + ((i + j_pos) * symbol_size_in_bytes), + symbol_size_in_bytes); + imgX[j + dst_offset_y][i + dst_offset_x] = (imgpel)ui16; } - } + } } } } @@ -461,77 +453,69 @@ void buf2img_basic (imgpel** imgX, //!< Pointer to image plane * Convert file read buffer to source picture structure ************************************************************************ */ -void buf2img_endian (imgpel** imgX, //!< Pointer to image plane - unsigned char* buf, //!< Buffer for file output - int size_x, //!< horizontal size of picture - int size_y, //!< vertical size of picture - int o_size_x, //!< horizontal size of picture - int o_size_y, //!< vertical size of picture - int symbol_size_in_bytes, //!< number of bytes in file used for one pixel - int dummy //!< dummy variable used for allowing function pointer use - ) -{ - int i,j; +void buf2img_endian( + imgpel **imgX, //!< Pointer to image plane + unsigned char *buf, //!< Buffer for file output + int size_x, //!< horizontal size of picture + int size_y, //!< vertical size of picture + int o_size_x, //!< horizontal size of picture + int o_size_y, //!< vertical size of picture + int symbol_size_in_bytes, //!< number of bytes in file used for one pixel + int dummy //!< dummy variable used for allowing function pointer use +) { + int i, j; uint16 tmp16, ui16; - unsigned long tmp32, ui32; + unsigned long tmp32, ui32; - if (symbol_size_in_bytes > (int) sizeof(imgpel)) - { - error ("Source picture has higher bit depth than imgpel data type. \nPlease recompile with larger data type for imgpel.", 500); + if (symbol_size_in_bytes > (int)sizeof(imgpel)) { + error("Source picture has higher bit depth than imgpel data type. \nPlease " + "recompile with larger data type for imgpel.", + 500); } - if (size_x != o_size_x || size_y != o_size_y) - { - error ("Rescaling not supported in big endian architectures. ", 500); + if (size_x != o_size_x || size_y != o_size_y) { + error("Rescaling not supported in big endian architectures. ", 500); } // big endian - switch (symbol_size_in_bytes) - { - case 1: - { - for(j=0;j> 8) | ((tmp16&0xFF)<<8); - imgX[j][i] = (imgpel) ui16; - } + break; + } + case 2: { + for (j = 0; j < size_y; j++) { + for (i = 0; i < size_x; i++) { + memcpy(&tmp16, buf + ((i + j * size_x) * 2), 2); + ui16 = (tmp16 >> 8) | ((tmp16 & 0xFF) << 8); + imgX[j][i] = (imgpel)ui16; } - break; } - case 4: - { - for(j=0;j>8) | ((tmp32&0xFF000000)>>24); - imgX[j][i] = (imgpel) ui32; - } + break; + } + case 4: { + for (j = 0; j < size_y; j++) { + for (i = 0; i < size_x; i++) { + memcpy(&tmp32, buf + ((i + j * size_x) * 4), 4); + ui32 = ((tmp32 & 0xFF00) << 8) | ((tmp32 & 0xFF) << 24) | + ((tmp32 & 0xFF0000) >> 8) | ((tmp32 & 0xFF000000) >> 24); + imgX[j][i] = (imgpel)ui32; } - break; } - default: - { - error ("reading only from formats of 8, 16 or 32 bit allowed on big endian architecture", 500); - break; - } - } + break; + } + default: { + error("reading only from formats of 8, 16 or 32 bit allowed on big endian " + "architecture", + 500); + break; + } + } } /*! @@ -541,13 +525,14 @@ void buf2img_endian (imgpel** imgX, //!< Pointer to image plane * ************************************************************************ */ -void AllocateFrameMemory (VideoParameters *p_Vid, InputParameters *p_Inp, FrameFormat *source) -{ - if (NULL == (p_Vid->buf = malloc (source->size * source->pic_unit_size_shift3))) +void AllocateFrameMemory(VideoParameters *p_Vid, InputParameters *p_Inp, + FrameFormat *source) { + if (NULL == + (p_Vid->buf = malloc(source->size * source->pic_unit_size_shift3))) no_mem_exit("AllocateFrameMemory: p_Vid->buf"); - if (p_Inp->input_file1.is_interleaved) - { - if (NULL == (p_Vid->ibuf = malloc (source->size * source->pic_unit_size_shift3))) + if (p_Inp->input_file1.is_interleaved) { + if (NULL == + (p_Vid->ibuf = malloc(source->size * source->pic_unit_size_shift3))) no_mem_exit("AllocateFrameMemory: p_Vid->ibuf"); } } @@ -559,12 +544,11 @@ void AllocateFrameMemory (VideoParameters *p_Vid, InputParameters *p_Inp, FrameF * ************************************************************************ */ -void DeleteFrameMemory (VideoParameters *p_Vid) -{ +void DeleteFrameMemory(VideoParameters *p_Vid) { if (p_Vid->buf != NULL) - free (p_Vid->buf); + free(p_Vid->buf); if (p_Vid->ibuf != NULL) - free (p_Vid->ibuf); + free(p_Vid->ibuf); } /*! @@ -579,87 +563,98 @@ void DeleteFrameMemory (VideoParameters *p_Vid) * \param HeaderSize * Number of bytes in the source file to be skipped * \param source - * source file (on disk) information + * source file (on disk) information * \param output * output file (for encoding) information * \param pImage * Image planes ************************************************************************ */ -int read_one_frame (VideoParameters *p_Vid, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, FrameFormat *output, imgpel **pImage[3]) -{ +int read_one_frame(VideoParameters *p_Vid, VideoDataFile *input_file, + int FrameNoInFile, int HeaderSize, FrameFormat *source, + FrameFormat *output, imgpel **pImage[3]) { InputParameters *p_Inp = p_Vid->p_Inp; int file_read = 0; - unsigned int symbol_size_in_bytes = source->pic_unit_size_shift3; + unsigned int symbol_size_in_bytes = source->pic_unit_size_shift3; - const int bytes_y = source->size_cmp[0] * symbol_size_in_bytes; - const int bytes_uv = source->size_cmp[1] * symbol_size_in_bytes; - int bit_scale; + const int bytes_y = source->size_cmp[0] * symbol_size_in_bytes; + const int bytes_uv = source->size_cmp[1] * symbol_size_in_bytes; + int bit_scale; - Boolean rgb_input = (Boolean) (source->color_model == CM_RGB && source->yuv_format == YUV444); + Boolean rgb_input = + (Boolean)(source->color_model == CM_RGB && source->yuv_format == YUV444); - if (input_file->is_concatenated == 0) - { - if (input_file->vdtype == VIDEO_TIFF) - { - file_read = ReadTIFFImage (p_Inp, input_file, FrameNoInFile, source, p_Vid->buf); + if (input_file->is_concatenated == 0) { + if (input_file->vdtype == VIDEO_TIFF) { + file_read = + ReadTIFFImage(p_Inp, input_file, FrameNoInFile, source, p_Vid->buf); + } else { + file_read = ReadFrameSeparate(p_Inp, input_file, FrameNoInFile, + HeaderSize, source, p_Vid->buf); } - else - { - file_read = ReadFrameSeparate (p_Inp, input_file, FrameNoInFile, HeaderSize, source, p_Vid->buf); - } - } - else - { - file_read = ReadFrameConcatenated (p_Inp, input_file, FrameNoInFile, HeaderSize, source, p_Vid->buf); - } - if ( !file_read ) - { + } else { + file_read = ReadFrameConcatenated(p_Inp, input_file, FrameNoInFile, + HeaderSize, source, p_Vid->buf); + } + if (!file_read) { return 0; } - // Deinterleave input source - if (input_file->is_interleaved) - { - deinterleave ( &p_Vid->buf, &p_Vid->ibuf, source, symbol_size_in_bytes); - } + // Deinterleave input source + if (input_file->is_interleaved) { + deinterleave(&p_Vid->buf, &p_Vid->ibuf, source, symbol_size_in_bytes); + } - bit_scale = source->bit_depth[0] - output->bit_depth[0]; + bit_scale = source->bit_depth[0] - output->bit_depth[0]; - if(rgb_input) - p_Vid->buf2img(pImage[0], p_Vid->buf + bytes_y, source->width[0], source->height[0], output->width[0], output->height[0], symbol_size_in_bytes, bit_scale); - else - p_Vid->buf2img(pImage[0], p_Vid->buf, source->width[0], source->height[0], output->width[0], output->height[0], symbol_size_in_bytes, bit_scale); + if (rgb_input) + p_Vid->buf2img(pImage[0], p_Vid->buf + bytes_y, source->width[0], + source->height[0], output->width[0], output->height[0], + symbol_size_in_bytes, bit_scale); + else + p_Vid->buf2img(pImage[0], p_Vid->buf, source->width[0], source->height[0], + output->width[0], output->height[0], symbol_size_in_bytes, + bit_scale); #if (DEBUG_BITDEPTH) - MaskMSBs(pImage[0], ((1 << output->bit_depth[0]) - 1), output->width[0], output->height[0]); + MaskMSBs(pImage[0], ((1 << output->bit_depth[0]) - 1), output->width[0], + output->height[0]); #endif - if (p_Vid->yuv_format != YUV400) - { - bit_scale = source->bit_depth[1] - output->bit_depth[1]; + if (p_Vid->yuv_format != YUV400) { + bit_scale = source->bit_depth[1] - output->bit_depth[1]; #if (ALLOW_GRAYSCALE) - if (!p_Inp->grayscale) + if (!p_Inp->grayscale) #endif - { - if(rgb_input) - p_Vid->buf2img(pImage[1], p_Vid->buf + bytes_y + bytes_uv, source->width[1], source->height[1], output->width[1], output->height[1], symbol_size_in_bytes, bit_scale); - else - p_Vid->buf2img(pImage[1], p_Vid->buf + bytes_y, source->width[1], source->height[1], output->width[1], output->height[1], symbol_size_in_bytes, bit_scale); + { + if (rgb_input) + p_Vid->buf2img(pImage[1], p_Vid->buf + bytes_y + bytes_uv, + source->width[1], source->height[1], output->width[1], + output->height[1], symbol_size_in_bytes, bit_scale); + else + p_Vid->buf2img(pImage[1], p_Vid->buf + bytes_y, source->width[1], + source->height[1], output->width[1], output->height[1], + symbol_size_in_bytes, bit_scale); - bit_scale = source->bit_depth[2] - output->bit_depth[2]; - if(rgb_input) - p_Vid->buf2img(pImage[2], p_Vid->buf, source->width[1], source->height[1], output->width[1], output->height[1], symbol_size_in_bytes, bit_scale); - else - p_Vid->buf2img(pImage[2], p_Vid->buf + bytes_y + bytes_uv, source->width[1], source->height[1], output->width[1], output->height[1], symbol_size_in_bytes, bit_scale); - } + bit_scale = source->bit_depth[2] - output->bit_depth[2]; + if (rgb_input) + p_Vid->buf2img(pImage[2], p_Vid->buf, source->width[1], + source->height[1], output->width[1], output->height[1], + symbol_size_in_bytes, bit_scale); + else + p_Vid->buf2img(pImage[2], p_Vid->buf + bytes_y + bytes_uv, + source->width[1], source->height[1], output->width[1], + output->height[1], symbol_size_in_bytes, bit_scale); + } #if (DEBUG_BITDEPTH) - MaskMSBs(pImage[1], ((1 << output->bit_depth[1]) - 1), output->width[1], output->height[1]); - MaskMSBs(pImage[2], ((1 << output->bit_depth[2]) - 1), output->width[1], output->height[1]); + MaskMSBs(pImage[1], ((1 << output->bit_depth[1]) - 1), output->width[1], + output->height[1]); + MaskMSBs(pImage[2], ((1 << output->bit_depth[2]) - 1), output->width[1], + output->height[1]); #endif - } + } - return file_read; + return file_read; } /*! @@ -682,39 +677,38 @@ int read_one_frame (VideoParameters *p_Vid, VideoDataFile *input_file, int Frame * image planes ************************************************************************ */ -void pad_borders (FrameFormat output, int img_size_x, int img_size_y, int img_size_x_cr, int img_size_y_cr, imgpel **pImage[3]) -{ +void pad_borders(FrameFormat output, int img_size_x, int img_size_y, + int img_size_x_cr, int img_size_y_cr, imgpel **pImage[3]) { int x, y; // Luma or 1st component - //padding right border + // padding right border if (output.width[0] < img_size_x) - for (y=0; y < output.height[0]; y++) + for (y = 0; y < output.height[0]; y++) for (x = output.width[0]; x < img_size_x; x++) - pImage[0] [y][x] = pImage[0][y][x-1]; + pImage[0][y][x] = pImage[0][y][x - 1]; - //padding bottom border + // padding bottom border if (output.height[0] < img_size_y) - for (y = output.height[0]; y * ************************************************************************************* */ -#include "global.h" #include "intra16x16_pred.h" -#include "mb_access.h" +#include "global.h" #include "image.h" +#include "mb_access.h" - -extern int intrapred_16x16_mbaff (Macroblock *currMB, ColorPlane pl, int predmode); -extern int intrapred_16x16_normal(Macroblock *currMB, ColorPlane pl, int predmode); +extern int intrapred_16x16_mbaff(Macroblock *currMB, ColorPlane pl, + int predmode); +extern int intrapred_16x16_normal(Macroblock *currMB, ColorPlane pl, + int predmode); /*! *********************************************************************** * \brief - * makes and returns 16x16 intra prediction blocks + * makes and returns 16x16 intra prediction blocks * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * SEARCH_SYNC search next sync element as errors while decoding occured *********************************************************************** */ -int intrapred16x16(Macroblock *currMB, //!< Current Macroblock - ColorPlane pl, //!< Current colorplane (for 4:4:4) - int predmode) //!< prediction mode +int intrapred16x16(Macroblock *currMB, //!< Current Macroblock + ColorPlane pl, //!< Current colorplane (for 4:4:4) + int predmode) //!< prediction mode { - if (currMB->p_Slice->mb_aff_frame_flag) - { + if (currMB->p_Slice->mb_aff_frame_flag) { return intrapred_16x16_mbaff(currMB, pl, predmode); - } - else - { + } else { return intrapred_16x16_normal(currMB, pl, predmode); } } - diff --git a/src/common/ldecod_src/intra16x16_pred_mbaff.c b/src/common/ldecod_src/intra16x16_pred_mbaff.c index 9a202f1..50150cf 100644 --- a/src/common/ldecod_src/intra16x16_pred_mbaff.c +++ b/src/common/ldecod_src/intra16x16_pred_mbaff.c @@ -6,7 +6,7 @@ * Functions for intra 16x16 prediction (MBAFF) * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Yuri Vatis * - Jan Muenster @@ -15,9 +15,9 @@ ************************************************************************************* */ #include "global.h" +#include "image.h" #include "intra16x16_pred.h" #include "mb_access.h" -#include "image.h" /*! *********************************************************************** @@ -25,73 +25,69 @@ * makes and returns 16x16 DC prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra16x16_dc_pred_mbaff(Macroblock *currMB, ColorPlane pl) -{ +static int intra16x16_dc_pred_mbaff(Macroblock *currMB, ColorPlane pl) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int s0 = 0, s1 = 0, s2 = 0; - int i,j; + int i, j; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); - PixelPos b; //!< pixel position p(0,-1) - PixelPos left[17]; //!< pixel positions p(-1, -1..15) + PixelPos b; //!< pixel position p(0,-1) + PixelPos left[17]; //!< pixel positions p(-1, -1..15) int up_avail, left_avail, left_up_avail; - s1=s2=0; + s1 = s2 = 0; - for (i=0;i<17;++i) - { - p_Vid->getNeighbour(currMB, -1, i-1, p_Vid->mb_size[IS_LUMA], &left[i]); + for (i = 0; i < 17; ++i) { + p_Vid->getNeighbour(currMB, -1, i - 1, p_Vid->mb_size[IS_LUMA], &left[i]); } - p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); + p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - up_avail = b.available; - left_avail = left[1].available; + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + up_avail = b.available; + left_avail = left[1].available; left_up_avail = left[0].available; - } - else - { - up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; + } else { + up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; for (i = 1, left_avail = 1; i < 17; ++i) - left_avail &= left[i].available ? currSlice->intra_block[left[i].mb_addr]: 0; - left_up_avail = left[0].available ? currSlice->intra_block[left[0].mb_addr]: 0; + left_avail &= + left[i].available ? currSlice->intra_block[left[i].mb_addr] : 0; + left_up_avail = + left[0].available ? currSlice->intra_block[left[0].mb_addr] : 0; } - for (i = 0; i < MB_BLOCK_SIZE; ++i) - { + for (i = 0; i < MB_BLOCK_SIZE; ++i) { if (up_avail) - s1 += imgY[b.pos_y][b.pos_x+i]; // sum hor pix + s1 += imgY[b.pos_y][b.pos_x + i]; // sum hor pix if (left_avail) - s2 += imgY[left[i + 1].pos_y][left[i + 1].pos_x]; // sum vert pix + s2 += imgY[left[i + 1].pos_y][left[i + 1].pos_x]; // sum vert pix } if (up_avail && left_avail) - s0 = (s1 + s2 + 16)>>5; // no edge + s0 = (s1 + s2 + 16) >> 5; // no edge else if (!up_avail && left_avail) - s0 = (s2 + 8)>>4; // upper edge + s0 = (s2 + 8) >> 4; // upper edge else if (up_avail && !left_avail) - s0 = (s1 + 8)>>4; // left edge + s0 = (s1 + 8) >> 4; // left edge else - s0 = p_Vid->dc_pred_value_comp[pl]; // top left corner, nothing to predict from - - for(j = 0; j < MB_BLOCK_SIZE; ++j) - { + s0 = p_Vid->dc_pred_value_comp[pl]; // top left corner, nothing to predict + // from + + for (j = 0; j < MB_BLOCK_SIZE; ++j) { #if (IMGTYPE == 0) memset(mb_pred[j], s0, MB_BLOCK_SIZE * sizeof(imgpel)); #else - for(i = 0; i < MB_BLOCK_SIZE; ++i) - { - mb_pred[j][i]=(imgpel) s0; + for (i = 0; i < MB_BLOCK_SIZE; ++i) { + mb_pred[j][i] = (imgpel)s0; } #endif } @@ -99,51 +95,45 @@ static int intra16x16_dc_pred_mbaff(Macroblock *currMB, ColorPlane pl) return DECODING_OK; } - - /*! *********************************************************************** * \brief * makes and returns 16x16 vertical prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra16x16_vert_pred_mbaff(Macroblock *currMB, ColorPlane pl) -{ +static int intra16x16_vert_pred_mbaff(Macroblock *currMB, ColorPlane pl) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int j; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; - PixelPos b; //!< pixel position p(0,-1) + PixelPos b; //!< pixel position p(0,-1) int up_avail; - //getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); - p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); + // getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); + p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { + if (!p_Vid->active_pps->constrained_intra_pred_flag) { up_avail = b.available; - } - else - { + } else { up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; } if (!up_avail) - error ("invalid 16x16 intra pred Mode VERT_PRED_16",500); + error("invalid 16x16 intra pred Mode VERT_PRED_16", 500); { imgpel **prd = &currSlice->mb_pred[pl][0]; imgpel *src = &(imgY[b.pos_y][b.pos_x]); - for(j=0;jp_Slice; VideoParameters *p_Vid = currMB->p_Vid; - int i,j; + int i, j; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); imgpel prediction; - PixelPos left[17]; //!< pixel positions p(-1, -1..15) + PixelPos left[17]; //!< pixel positions p(-1, -1..15) int left_avail, left_up_avail; - for (i=0;i<17;++i) - { - p_Vid->getNeighbour(currMB, -1, i-1, p_Vid->mb_size[IS_LUMA], &left[i]); + for (i = 0; i < 17; ++i) { + p_Vid->getNeighbour(currMB, -1, i - 1, p_Vid->mb_size[IS_LUMA], &left[i]); } - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - left_avail = left[1].available; + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + left_avail = left[1].available; left_up_avail = left[0].available; - } - else - { + } else { for (i = 1, left_avail = 1; i < 17; ++i) - left_avail &= left[i].available ? currSlice->intra_block[left[i].mb_addr]: 0; - left_up_avail = left[0].available ? currSlice->intra_block[left[0].mb_addr]: 0; + left_avail &= + left[i].available ? currSlice->intra_block[left[i].mb_addr] : 0; + left_up_avail = + left[0].available ? currSlice->intra_block[left[0].mb_addr] : 0; } if (!left_avail) - error ("invalid 16x16 intra pred Mode HOR_PRED_16",500); + error("invalid 16x16 intra pred Mode HOR_PRED_16", 500); - for(j = 0; j < MB_BLOCK_SIZE; ++j) - { - prediction = imgY[left[j+1].pos_y][left[j+1].pos_x]; - for(i = 0; i < MB_BLOCK_SIZE; ++i) - mb_pred[j][i]= prediction; // store predicted 16x16 block + for (j = 0; j < MB_BLOCK_SIZE; ++j) { + prediction = imgY[left[j + 1].pos_y][left[j + 1].pos_x]; + for (i = 0; i < MB_BLOCK_SIZE; ++i) + mb_pred[j][i] = prediction; // store predicted 16x16 block } return DECODING_OK; @@ -215,74 +201,72 @@ static int intra16x16_hor_pred_mbaff(Macroblock *currMB, ColorPlane pl) * makes and returns 16x16 horizontal prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra16x16_plane_pred_mbaff(Macroblock *currMB, ColorPlane pl) -{ +static int intra16x16_plane_pred_mbaff(Macroblock *currMB, ColorPlane pl) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - - int i,j; + + int i, j; int ih = 0, iv = 0; - int ib,ic,iaa; + int ib, ic, iaa; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); imgpel *mpr_line; int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; - PixelPos b; //!< pixel position p(0,-1) - PixelPos left[17]; //!< pixel positions p(-1, -1..15) + PixelPos b; //!< pixel position p(0,-1) + PixelPos left[17]; //!< pixel positions p(-1, -1..15) int up_avail, left_avail, left_up_avail; - for (i=0;i<17; ++i) - { - p_Vid->getNeighbour(currMB, -1, i-1, p_Vid->mb_size[IS_LUMA], &left[i]); + for (i = 0; i < 17; ++i) { + p_Vid->getNeighbour(currMB, -1, i - 1, p_Vid->mb_size[IS_LUMA], &left[i]); } - p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); + p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - up_avail = b.available; - left_avail = left[1].available; + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + up_avail = b.available; + left_avail = left[1].available; left_up_avail = left[0].available; - } - else - { - up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; + } else { + up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; for (i = 1, left_avail = 1; i < 17; ++i) - left_avail &= left[i].available ? currSlice->intra_block[left[i].mb_addr]: 0; - left_up_avail = left[0].available ? currSlice->intra_block[left[0].mb_addr]: 0; + left_avail &= + left[i].available ? currSlice->intra_block[left[i].mb_addr] : 0; + left_up_avail = + left[0].available ? currSlice->intra_block[left[0].mb_addr] : 0; } - if (!up_avail || !left_up_avail || !left_avail) - error ("invalid 16x16 intra pred Mode PLANE_16",500); + if (!up_avail || !left_up_avail || !left_avail) + error("invalid 16x16 intra pred Mode PLANE_16", 500); - mpr_line = &imgY[b.pos_y][b.pos_x+7]; - for (i = 1; i < 8; ++i) - { - ih += i*(mpr_line[i] - mpr_line[-i]); - iv += i*(imgY[left[8+i].pos_y][left[8+i].pos_x] - imgY[left[8-i].pos_y][left[8-i].pos_x]); + mpr_line = &imgY[b.pos_y][b.pos_x + 7]; + for (i = 1; i < 8; ++i) { + ih += i * (mpr_line[i] - mpr_line[-i]); + iv += i * (imgY[left[8 + i].pos_y][left[8 + i].pos_x] - + imgY[left[8 - i].pos_y][left[8 - i].pos_x]); } - ih += 8*(mpr_line[8] - imgY[left[0].pos_y][left[0].pos_x]); - iv += 8*(imgY[left[16].pos_y][left[16].pos_x] - imgY[left[0].pos_y][left[0].pos_x]); + ih += 8 * (mpr_line[8] - imgY[left[0].pos_y][left[0].pos_x]); + iv += 8 * (imgY[left[16].pos_y][left[16].pos_x] - + imgY[left[0].pos_y][left[0].pos_x]); - ib=(5 * ih + 32)>>6; - ic=(5 * iv + 32)>>6; + ib = (5 * ih + 32) >> 6; + ic = (5 * iv + 32) >> 6; - iaa=16 * (mpr_line[8] + imgY[left[16].pos_y][left[16].pos_x]); - for (j = 0;j < MB_BLOCK_SIZE; ++j) - { - for (i = 0;i < MB_BLOCK_SIZE; ++i) - { - mb_pred[j][i] = (imgpel) iClip1(max_imgpel_value, ((iaa + (i - 7) * ib + (j - 7) * ic + 16) >> 5)); + iaa = 16 * (mpr_line[8] + imgY[left[16].pos_y][left[16].pos_x]); + for (j = 0; j < MB_BLOCK_SIZE; ++j) { + for (i = 0; i < MB_BLOCK_SIZE; ++i) { + mb_pred[j][i] = (imgpel)iClip1( + max_imgpel_value, ((iaa + (i - 7) * ib + (j - 7) * ic + 16) >> 5)); } - }// store plane prediction + } // store plane prediction return DECODING_OK; } @@ -290,36 +274,33 @@ static int intra16x16_plane_pred_mbaff(Macroblock *currMB, ColorPlane pl) /*! *********************************************************************** * \brief - * makes and returns 16x16 intra prediction blocks + * makes and returns 16x16 intra prediction blocks * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * SEARCH_SYNC search next sync element as errors while decoding occured *********************************************************************** */ -int intrapred_16x16_mbaff(Macroblock *currMB, //!< Current Macroblock - ColorPlane pl, //!< Current colorplane (for 4:4:4) - int predmode) //!< prediction mode +int intrapred_16x16_mbaff(Macroblock *currMB, //!< Current Macroblock + ColorPlane pl, //!< Current colorplane (for 4:4:4) + int predmode) //!< prediction mode { - switch (predmode) - { - case VERT_PRED_16: // vertical prediction from block above + switch (predmode) { + case VERT_PRED_16: // vertical prediction from block above return (intra16x16_vert_pred_mbaff(currMB, pl)); break; - case HOR_PRED_16: // horizontal prediction from left block + case HOR_PRED_16: // horizontal prediction from left block return (intra16x16_hor_pred_mbaff(currMB, pl)); break; - case DC_PRED_16: // DC prediction + case DC_PRED_16: // DC prediction return (intra16x16_dc_pred_mbaff(currMB, pl)); break; - case PLANE_16:// 16 bit integer plan pred + case PLANE_16: // 16 bit integer plan pred return (intra16x16_plane_pred_mbaff(currMB, pl)); break; - default: - { // indication of fault in bitstream,exit - printf("illegal 16x16 intra prediction mode input: %d\n",predmode); - return SEARCH_SYNC; - } - } + default: { // indication of fault in bitstream,exit + printf("illegal 16x16 intra prediction mode input: %d\n", predmode); + return SEARCH_SYNC; + } + } } - diff --git a/src/common/ldecod_src/intra16x16_pred_normal.c b/src/common/ldecod_src/intra16x16_pred_normal.c index 1854b33..0bc0ff0 100644 --- a/src/common/ldecod_src/intra16x16_pred_normal.c +++ b/src/common/ldecod_src/intra16x16_pred_normal.c @@ -6,7 +6,7 @@ * Functions for intra 16x16 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Yuri Vatis * - Jan Muenster @@ -15,9 +15,9 @@ ************************************************************************************* */ #include "global.h" +#include "image.h" #include "intra16x16_pred.h" #include "mb_access.h" -#include "image.h" /*! *********************************************************************** @@ -25,133 +25,119 @@ * makes and returns 16x16 DC prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra16x16_dc_pred(Macroblock *currMB, ColorPlane pl) -{ +static int intra16x16_dc_pred(Macroblock *currMB, ColorPlane pl) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int s0 = 0, s1 = 0, s2 = 0; - int i,j; + int i, j; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); - PixelPos a, b; + PixelPos a, b; int up_avail, left_avail; - getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_LUMA], &a); - getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); + getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_LUMA], &a); + getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - up_avail = b.available; - left_avail = a.available; - } - else - { - up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; - left_avail = a.available ? currSlice->intra_block[a.mb_addr]: 0; + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + up_avail = b.available; + left_avail = a.available; + } else { + up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; + left_avail = a.available ? currSlice->intra_block[a.mb_addr] : 0; } // Sum top predictors - if (up_avail) - { + if (up_avail) { imgpel *pel = &imgY[b.pos_y][b.pos_x]; - for (i = 0; i < MB_BLOCK_SIZE; ++i) - { + for (i = 0; i < MB_BLOCK_SIZE; ++i) { s1 += *pel++; } } // Sum left predictors - if (left_avail) - { + if (left_avail) { int pos_y = a.pos_y; int pos_x = a.pos_x; - for (i = 0; i < MB_BLOCK_SIZE; ++i) - { - s2 += imgY[pos_y++][pos_x]; + for (i = 0; i < MB_BLOCK_SIZE; ++i) { + s2 += imgY[pos_y++][pos_x]; } } if (up_avail && left_avail) - s0 = (s1 + s2 + 16)>>5; // no edge + s0 = (s1 + s2 + 16) >> 5; // no edge else if (!up_avail && left_avail) - s0 = (s2 + 8)>>4; // upper edge + s0 = (s2 + 8) >> 4; // upper edge else if (up_avail && !left_avail) - s0 = (s1 + 8)>>4; // left edge + s0 = (s1 + 8) >> 4; // left edge else - s0 = p_Vid->dc_pred_value_comp[pl]; // top left corner, nothing to predict from + s0 = p_Vid->dc_pred_value_comp[pl]; // top left corner, nothing to predict + // from - for(j = 0; j < MB_BLOCK_SIZE; ++j) - { + for (j = 0; j < MB_BLOCK_SIZE; ++j) { #if (IMGTYPE == 0) memset(mb_pred[j], s0, MB_BLOCK_SIZE * sizeof(imgpel)); #else - for(i = 0; i < MB_BLOCK_SIZE; i += 4) - { - mb_pred[j][i ]=(imgpel) s0; - mb_pred[j][i + 1]=(imgpel) s0; - mb_pred[j][i + 2]=(imgpel) s0; - mb_pred[j][i + 3]=(imgpel) s0; + for (i = 0; i < MB_BLOCK_SIZE; i += 4) { + mb_pred[j][i] = (imgpel)s0; + mb_pred[j][i + 1] = (imgpel)s0; + mb_pred[j][i + 2] = (imgpel)s0; + mb_pred[j][i + 3] = (imgpel)s0; } #endif } return DECODING_OK; - } - /*! *********************************************************************** * \brief * makes and returns 16x16 vertical prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra16x16_vert_pred(Macroblock *currMB, ColorPlane pl) -{ +static int intra16x16_vert_pred(Macroblock *currMB, ColorPlane pl) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int j; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; - PixelPos b; //!< pixel position p(0,-1) + PixelPos b; //!< pixel position p(0,-1) int up_avail; - //getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); - p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); + // getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); + p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { + if (!p_Vid->active_pps->constrained_intra_pred_flag) { up_avail = b.available; - } - else - { + } else { up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; } if (!up_avail) - error ("invalid 16x16 intra pred Mode VERT_PRED_16",500); + error("invalid 16x16 intra pred Mode VERT_PRED_16", 500); { imgpel **prd = &currSlice->mb_pred[pl][0]; imgpel *src = &(imgY[b.pos_y][b.pos_x]); - for(j=0;jp_Slice; VideoParameters *p_Vid = currMB->p_Vid; #if (IMGTYPE == 0) @@ -183,8 +167,9 @@ static int intra16x16_hor_pred(Macroblock *currMB, ColorPlane pl) int i, j; #endif - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); imgpel prediction; int pos_y, pos_x; @@ -192,36 +177,31 @@ static int intra16x16_hor_pred(Macroblock *currMB, ColorPlane pl) int left_avail; - getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_LUMA], &a); + getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_LUMA], &a); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - left_avail = a.available; - } - else - { - left_avail = a.available ? currSlice->intra_block[a.mb_addr]: 0; + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + left_avail = a.available; + } else { + left_avail = a.available ? currSlice->intra_block[a.mb_addr] : 0; } if (!left_avail) - error ("invalid 16x16 intra pred Mode HOR_PRED_16",500); + error("invalid 16x16 intra pred Mode HOR_PRED_16", 500); pos_y = a.pos_y; pos_x = a.pos_x; - for(j = 0; j < MB_BLOCK_SIZE; ++j) - { + for (j = 0; j < MB_BLOCK_SIZE; ++j) { imgpel *prd = mb_pred[j]; prediction = imgY[pos_y++][pos_x]; #if (IMGTYPE == 0) memset(prd, prediction, MB_BLOCK_SIZE * sizeof(imgpel)); #else - for(i = 0; i < MB_BLOCK_SIZE; i += 4) - { - *prd++= prediction; // store predicted 16x16 block - *prd++= prediction; // store predicted 16x16 block - *prd++= prediction; // store predicted 16x16 block - *prd++= prediction; // store predicted 16x16 block + for (i = 0; i < MB_BLOCK_SIZE; i += 4) { + *prd++ = prediction; // store predicted 16x16 block + *prd++ = prediction; // store predicted 16x16 block + *prd++ = prediction; // store predicted 16x16 block + *prd++ = prediction; // store predicted 16x16 block } #endif } @@ -229,85 +209,78 @@ static int intra16x16_hor_pred(Macroblock *currMB, ColorPlane pl) return DECODING_OK; } - /*! *********************************************************************** * \brief * makes and returns 16x16 horizontal prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra16x16_plane_pred(Macroblock *currMB, ColorPlane pl) -{ +static int intra16x16_plane_pred(Macroblock *currMB, ColorPlane pl) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - - int i,j; + + int i, j; int ih = 0, iv = 0; - int ib,ic,iaa; + int ib, ic, iaa; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = &(currSlice->mb_pred[pl][0]); imgpel *mpr_line; int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; int pos_y, pos_x; - PixelPos a, b, d; + PixelPos a, b, d; int up_avail, left_avail, left_up_avail; - getNonAffNeighbour(currMB, -1, -1, p_Vid->mb_size[IS_LUMA], &d); - getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_LUMA], &a); - getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); + getNonAffNeighbour(currMB, -1, -1, p_Vid->mb_size[IS_LUMA], &d); + getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_LUMA], &a); + getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_LUMA], &b); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - up_avail = b.available; - left_avail = a.available; + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + up_avail = b.available; + left_avail = a.available; left_up_avail = d.available; - } - else - { - up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; - left_avail = a.available ? currSlice->intra_block[a.mb_addr] : 0; + } else { + up_avail = b.available ? currSlice->intra_block[b.mb_addr] : 0; + left_avail = a.available ? currSlice->intra_block[a.mb_addr] : 0; left_up_avail = d.available ? currSlice->intra_block[d.mb_addr] : 0; } - if (!up_avail || !left_up_avail || !left_avail) - error ("invalid 16x16 intra pred Mode PLANE_16",500); + if (!up_avail || !left_up_avail || !left_avail) + error("invalid 16x16 intra pred Mode PLANE_16", 500); - mpr_line = &imgY[b.pos_y][b.pos_x+7]; + mpr_line = &imgY[b.pos_y][b.pos_x + 7]; pos_y = a.pos_y + 7; pos_x = a.pos_x; - for (i = 1; i < 8; ++i) - { - ih += i*(mpr_line[i] - mpr_line[-i]); - iv += i*(imgY[pos_y + i][pos_x] - imgY[pos_y - i][pos_x]); + for (i = 1; i < 8; ++i) { + ih += i * (mpr_line[i] - mpr_line[-i]); + iv += i * (imgY[pos_y + i][pos_x] - imgY[pos_y - i][pos_x]); } - ih += 8*(mpr_line[8] - imgY[d.pos_y][d.pos_x]); - iv += 8*(imgY[pos_y + 8][pos_x] - imgY[d.pos_y][d.pos_x]); + ih += 8 * (mpr_line[8] - imgY[d.pos_y][d.pos_x]); + iv += 8 * (imgY[pos_y + 8][pos_x] - imgY[d.pos_y][d.pos_x]); - ib=(5 * ih + 32)>>6; - ic=(5 * iv + 32)>>6; + ib = (5 * ih + 32) >> 6; + ic = (5 * iv + 32) >> 6; - iaa=16 * (mpr_line[8] + imgY[pos_y + 8][pos_x]); - for (j = 0;j < MB_BLOCK_SIZE; ++j) - { + iaa = 16 * (mpr_line[8] + imgY[pos_y + 8][pos_x]); + for (j = 0; j < MB_BLOCK_SIZE; ++j) { int ibb = iaa + (j - 7) * ic + 16; imgpel *prd = mb_pred[j]; - for (i = 0;i < MB_BLOCK_SIZE; i += 4) - { - *prd++ = (imgpel) iClip1(max_imgpel_value, ((ibb + (i - 7) * ib) >> 5)); - *prd++ = (imgpel) iClip1(max_imgpel_value, ((ibb + (i - 6) * ib) >> 5)); - *prd++ = (imgpel) iClip1(max_imgpel_value, ((ibb + (i - 5) * ib) >> 5)); - *prd++ = (imgpel) iClip1(max_imgpel_value, ((ibb + (i - 4) * ib) >> 5)); + for (i = 0; i < MB_BLOCK_SIZE; i += 4) { + *prd++ = (imgpel)iClip1(max_imgpel_value, ((ibb + (i - 7) * ib) >> 5)); + *prd++ = (imgpel)iClip1(max_imgpel_value, ((ibb + (i - 6) * ib) >> 5)); + *prd++ = (imgpel)iClip1(max_imgpel_value, ((ibb + (i - 5) * ib) >> 5)); + *prd++ = (imgpel)iClip1(max_imgpel_value, ((ibb + (i - 4) * ib) >> 5)); } - }// store plane prediction + } // store plane prediction return DECODING_OK; } @@ -315,36 +288,33 @@ static int intra16x16_plane_pred(Macroblock *currMB, ColorPlane pl) /*! *********************************************************************** * \brief - * makes and returns 16x16 intra prediction blocks + * makes and returns 16x16 intra prediction blocks * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * SEARCH_SYNC search next sync element as errors while decoding occured *********************************************************************** */ -int intrapred_16x16_normal(Macroblock *currMB, //!< Current Macroblock - ColorPlane pl, //!< Current colorplane (for 4:4:4) - int predmode) //!< prediction mode +int intrapred_16x16_normal(Macroblock *currMB, //!< Current Macroblock + ColorPlane pl, //!< Current colorplane (for 4:4:4) + int predmode) //!< prediction mode { - switch (predmode) - { - case VERT_PRED_16: // vertical prediction from block above + switch (predmode) { + case VERT_PRED_16: // vertical prediction from block above return (intra16x16_vert_pred(currMB, pl)); break; - case HOR_PRED_16: // horizontal prediction from left block + case HOR_PRED_16: // horizontal prediction from left block return (intra16x16_hor_pred(currMB, pl)); break; - case DC_PRED_16: // DC prediction + case DC_PRED_16: // DC prediction return (intra16x16_dc_pred(currMB, pl)); break; - case PLANE_16:// 16 bit integer plan pred + case PLANE_16: // 16 bit integer plan pred return (intra16x16_plane_pred(currMB, pl)); break; - default: - { // indication of fault in bitstream,exit - printf("illegal 16x16 intra prediction mode input: %d\n",predmode); - return SEARCH_SYNC; - } + default: { // indication of fault in bitstream,exit + printf("illegal 16x16 intra prediction mode input: %d\n", predmode); + return SEARCH_SYNC; + } } } - diff --git a/src/common/ldecod_src/intra4x4_pred.c b/src/common/ldecod_src/intra4x4_pred.c index a99b433..f2ca8af 100644 --- a/src/common/ldecod_src/intra4x4_pred.c +++ b/src/common/ldecod_src/intra4x4_pred.c @@ -6,44 +6,44 @@ * Functions for intra 4x4 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * ************************************************************************************* */ -#include "global.h" #include "intra4x4_pred.h" -#include "mb_access.h" +#include "global.h" #include "image.h" +#include "mb_access.h" - -extern int intra4x4_pred_mbaff (Macroblock *currMB, ColorPlane pl, int ioff, int joff, int img_block_x, int img_block_y); -extern int intra4x4_pred_normal(Macroblock *currMB, ColorPlane pl, int ioff, int joff, int img_block_x, int img_block_y); +extern int intra4x4_pred_mbaff(Macroblock *currMB, ColorPlane pl, int ioff, + int joff, int img_block_x, int img_block_y); +extern int intra4x4_pred_normal(Macroblock *currMB, ColorPlane pl, int ioff, + int joff, int img_block_x, int img_block_y); /*! *********************************************************************** * \brief - * makes and returns 4x4 intra prediction blocks + * makes and returns 4x4 intra prediction blocks * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * SEARCH_SYNC search next sync element as errors while decoding occured *********************************************************************** */ -int intrapred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff, //!< pixel offset Y within MB - int img_block_x, //!< location of block X, multiples of 4 - int img_block_y) //!< location of block Y, multiples of 4 +int intrapred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff, //!< pixel offset Y within MB + int img_block_x, //!< location of block X, multiples of 4 + int img_block_y) //!< location of block Y, multiples of 4 { - if (currMB->p_Slice->mb_aff_frame_flag) - { - return intra4x4_pred_mbaff(currMB, pl, ioff, joff, img_block_x, img_block_y); - } - else - { - return intra4x4_pred_normal(currMB, pl, ioff, joff, img_block_x, img_block_y); + if (currMB->p_Slice->mb_aff_frame_flag) { + return intra4x4_pred_mbaff(currMB, pl, ioff, joff, img_block_x, + img_block_y); + } else { + return intra4x4_pred_normal(currMB, pl, ioff, joff, img_block_x, + img_block_y); } } diff --git a/src/common/ldecod_src/intra4x4_pred_mbaff.c b/src/common/ldecod_src/intra4x4_pred_mbaff.c index fe72740..91c6c72 100644 --- a/src/common/ldecod_src/intra4x4_pred_mbaff.c +++ b/src/common/ldecod_src/intra4x4_pred_mbaff.c @@ -6,16 +6,16 @@ * Functions for intra 4x4 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * ************************************************************************************* */ #include "global.h" +#include "image.h" #include "intra4x4_pred.h" #include "mb_access.h" -#include "image.h" // Notation for comments regarding prediction and predictors. // The pels of the 4x4 block are labelled a..p. The predictor pels above @@ -42,92 +42,80 @@ * \param joff * pixel offset Y within MB * \return - * DECODING_OK decoding of intra prediction mode was successful \n + * DECODING_OK decoding of intra prediction mode was successful \n * *********************************************************************** */ -static int intra4x4_dc_pred_mbaff(Macroblock *currMB, - ColorPlane pl, - int ioff, - int joff) -{ +static int intra4x4_dc_pred_mbaff(Macroblock *currMB, ColorPlane pl, int ioff, + int joff) { Slice *currSlice = currMB->p_Slice; - VideoParameters *p_Vid = currMB->p_Vid; + VideoParameters *p_Vid = currMB->p_Vid; - int i,j; - int s0 = 0; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + int i, j; + int s0 = 0; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; PixelPos pix_a[4], pix_b; int block_available_up; - int block_available_left; + int block_available_left; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **mb_pred = currSlice->mb_pred[pl]; - for (i=0;i<4;++i) - { - p_Vid->getNeighbour(currMB, ioff - 1, joff + i, p_Vid->mb_size[IS_LUMA], &pix_a[i]); + for (i = 0; i < 4; ++i) { + p_Vid->getNeighbour(currMB, ioff - 1, joff + i, p_Vid->mb_size[IS_LUMA], + &pix_a[i]); } - p_Vid->getNeighbour(currMB, ioff , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_b); + p_Vid->getNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<4;++i) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 4; ++i) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; } // form predictor pels - if (block_available_up) - { + if (block_available_up) { s0 += imgY[pix_b.pos_y][pix_b.pos_x + 0]; s0 += imgY[pix_b.pos_y][pix_b.pos_x + 1]; s0 += imgY[pix_b.pos_y][pix_b.pos_x + 2]; s0 += imgY[pix_b.pos_y][pix_b.pos_x + 3]; } - if (block_available_left) - { + if (block_available_left) { s0 += imgY[pix_a[0].pos_y][pix_a[0].pos_x]; s0 += imgY[pix_a[1].pos_y][pix_a[1].pos_x]; s0 += imgY[pix_a[2].pos_y][pix_a[2].pos_x]; s0 += imgY[pix_a[3].pos_y][pix_a[3].pos_x]; } - if (block_available_up && block_available_left) - { + if (block_available_up && block_available_left) { // no edge - s0 = (s0 + 4)>>3; - } - else if (!block_available_up && block_available_left) - { + s0 = (s0 + 4) >> 3; + } else if (!block_available_up && block_available_left) { // upper edge - s0 = (s0 + 2)>>2; - } - else if (block_available_up && !block_available_left) - { + s0 = (s0 + 2) >> 2; + } else if (block_available_up && !block_available_left) { // left edge - s0 = (s0 + 2)>>2; - } - else //if (!block_available_up && !block_available_left) + s0 = (s0 + 2) >> 2; + } else // if (!block_available_up && !block_available_left) { // top left corner, nothing to predict from s0 = p_Vid->dc_pred_value_comp[pl]; } - for (j=joff; j < joff + BLOCK_SIZE; ++j) - { + for (j = joff; j < joff + BLOCK_SIZE; ++j) { // store DC prediction - mb_pred[j][ioff ] = (imgpel) s0; - mb_pred[j][ioff + 1] = (imgpel) s0; - mb_pred[j][ioff + 2] = (imgpel) s0; - mb_pred[j][ioff + 3] = (imgpel) s0; + mb_pred[j][ioff] = (imgpel)s0; + mb_pred[j][ioff + 1] = (imgpel)s0; + mb_pred[j][ioff + 2] = (imgpel)s0; + mb_pred[j][ioff + 3] = (imgpel)s0; } return DECODING_OK; } @@ -138,44 +126,42 @@ static int intra4x4_dc_pred_mbaff(Macroblock *currMB, * makes and returns 4x4 vertical prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_vert_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int intra4x4_vert_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int block_available_up; PixelPos pix_b; - getAffNeighbour(currMB, ioff, joff - 1 , p_Vid->mb_size[IS_LUMA], &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - } - else - { + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + } else { block_available_up = pix_b.available; } - if (!block_available_up) - { - printf ("warning: Intra_4x4_Vertical prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); - } - else - { + if (!block_available_up) { + printf("warning: Intra_4x4_Vertical prediction mode not allowed at mb %d\n", + (int)currSlice->current_mb_nr); + } else { imgpel **mb_pred = currSlice->mb_pred[pl]; - imgpel *imgY = (pl) ? &currSlice->dec_picture->imgUV[pl - 1][pix_b.pos_y][pix_b.pos_x] : &currSlice->dec_picture->imgY[pix_b.pos_y][pix_b.pos_x]; + imgpel *imgY = + (pl) ? &currSlice->dec_picture->imgUV[pl - 1][pix_b.pos_y][pix_b.pos_x] + : &currSlice->dec_picture->imgY[pix_b.pos_y][pix_b.pos_x]; memcpy(&(mb_pred[joff++][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); memcpy(&(mb_pred[joff++][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); memcpy(&(mb_pred[joff++][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); - memcpy(&(mb_pred[joff ][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); + memcpy(&(mb_pred[joff][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); } return DECODING_OK; } @@ -199,47 +185,44 @@ static int intra4x4_vert_pred_mbaff(Macroblock *currMB, //!< current macroblo * *********************************************************************** */ -static int intra4x4_hor_pred_mbaff(Macroblock *currMB, - ColorPlane pl, - int ioff, - int joff) -{ +static int intra4x4_hor_pred_mbaff(Macroblock *currMB, ColorPlane pl, int ioff, + int joff) { VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; - int i,j; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + int i, j; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; PixelPos pix_a[4]; int block_available_left; - imgpel *predrow, prediction, **mb_pred = currSlice->mb_pred[pl]; + imgpel *predrow, prediction, **mb_pred = currSlice->mb_pred[pl]; - for (i=0;i<4;++i) - { - p_Vid->getNeighbour(currMB, ioff -1 , joff +i , p_Vid->mb_size[IS_LUMA], &pix_a[i]); + for (i = 0; i < 4; ++i) { + p_Vid->getNeighbour(currMB, ioff - 1, joff + i, p_Vid->mb_size[IS_LUMA], + &pix_a[i]); } - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<4;++i) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - } - else - { - block_available_left = pix_a[0].available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 4; ++i) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; } if (!block_available_left) - printf ("warning: Intra_4x4_Horizontal prediction mode not allowed at mb %d\n",(int) currSlice->current_mb_nr); + printf( + "warning: Intra_4x4_Horizontal prediction mode not allowed at mb %d\n", + (int)currSlice->current_mb_nr); - for(j=0;jp_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int i; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; PixelPos pix_a[4]; PixelPos pix_b, pix_d; @@ -273,41 +258,44 @@ static int intra4x4_diag_down_right_pred_mbaff(Macroblock *currMB, //!< curre int block_available_left; int block_available_up_left; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **mb_pred = currSlice->mb_pred[pl]; - for (i=0;i<4;++i) - { - p_Vid->getNeighbour(currMB, ioff -1 , joff +i , p_Vid->mb_size[IS_LUMA], &pix_a[i]); + for (i = 0; i < 4; ++i) { + p_Vid->getNeighbour(currMB, ioff - 1, joff + i, p_Vid->mb_size[IS_LUMA], + &pix_a[i]); } - p_Vid->getNeighbour(currMB, ioff , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_b); - p_Vid->getNeighbour(currMB, ioff -1 , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_d); + p_Vid->getNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + p_Vid->getNeighbour(currMB, ioff - 1, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_d); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<4;++i) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; - block_available_up_left = pix_d.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 4; ++i) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_4x4_Diagonal_Down_Right prediction mode not allowed at mb %d\n",(int) currSlice->current_mb_nr); - else - { + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_4x4_Diagonal_Down_Right prediction mode not allowed " + "at mb %d\n", + (int)currSlice->current_mb_nr); + else { imgpel PredPixel[7]; imgpel *pred_pel = &imgY[pix_b.pos_y][pix_b.pos_x]; // form predictor pels imgpel p_a = *pred_pel++; imgpel p_b = *pred_pel++; imgpel p_c = *pred_pel++; - imgpel p_d = *pred_pel ; + imgpel p_d = *pred_pel; imgpel p_i = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; imgpel p_j = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; @@ -315,19 +303,19 @@ static int intra4x4_diag_down_right_pred_mbaff(Macroblock *currMB, //!< curre imgpel p_l = imgY[pix_a[3].pos_y][pix_a[3].pos_x]; imgpel p_x = imgY[pix_d.pos_y][pix_d.pos_x]; - - PredPixel[0] = (imgpel) ((p_l + 2*p_k + p_j + 2) >> 2); - PredPixel[1] = (imgpel) ((p_k + 2*p_j + p_i + 2) >> 2); - PredPixel[2] = (imgpel) ((p_j + 2*p_i + p_x + 2) >> 2); - PredPixel[3] = (imgpel) ((p_i + 2*p_x + p_a + 2) >> 2); - PredPixel[4] = (imgpel) ((p_x + 2*p_a + p_b + 2) >> 2); - PredPixel[5] = (imgpel) ((p_a + 2*p_b + p_c + 2) >> 2); - PredPixel[6] = (imgpel) ((p_b + 2*p_c + p_d + 2) >> 2); + + PredPixel[0] = (imgpel)((p_l + 2 * p_k + p_j + 2) >> 2); + PredPixel[1] = (imgpel)((p_k + 2 * p_j + p_i + 2) >> 2); + PredPixel[2] = (imgpel)((p_j + 2 * p_i + p_x + 2) >> 2); + PredPixel[3] = (imgpel)((p_i + 2 * p_x + p_a + 2) >> 2); + PredPixel[4] = (imgpel)((p_x + 2 * p_a + p_b + 2) >> 2); + PredPixel[5] = (imgpel)((p_a + 2 * p_b + p_c + 2) >> 2); + PredPixel[6] = (imgpel)((p_b + 2 * p_c + p_d + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[3], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[2], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[1], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[0], 4 * sizeof(imgpel)); + memcpy(&mb_pred[joff][ioff], &PredPixel[0], 4 * sizeof(imgpel)); } return DECODING_OK; @@ -339,45 +327,49 @@ static int intra4x4_diag_down_right_pred_mbaff(Macroblock *currMB, //!< curre * makes and returns 4x4 diagonal down left prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_diag_down_left_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int +intra4x4_diag_down_left_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + PixelPos pix_b, pix_c; int block_available_up; int block_available_up_right; - p_Vid->getNeighbour(currMB, ioff , joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); - p_Vid->getNeighbour(currMB, ioff + 4, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_c); + p_Vid->getNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + p_Vid->getNeighbour(currMB, ioff + 4, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_c); - pix_c.available = pix_c.available && !((ioff==4) && ((joff==4)||(joff==12))); + pix_c.available = + pix_c.available && !((ioff == 4) && ((joff == 4) || (joff == 12))); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - } - else - { - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + } else { + block_available_up = pix_b.available; block_available_up_right = pix_c.available; } if (!block_available_up) - printf ("warning: Intra_4x4_Diagonal_Down_Left prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); - else - { - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = currSlice->mb_pred[pl]; + printf("warning: Intra_4x4_Diagonal_Down_Left prediction mode not allowed " + "at mb %d\n", + (int)currSlice->current_mb_nr); + else { + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = currSlice->mb_pred[pl]; imgpel p_e, p_f, p_g, p_h; imgpel PredPixel[8]; @@ -387,33 +379,30 @@ static int intra4x4_diag_down_left_pred_mbaff(Macroblock *currMB, //!< curren imgpel p_a = *pred_pel++; imgpel p_b = *pred_pel++; imgpel p_c = *pred_pel++; - imgpel p_d = *pred_pel ; + imgpel p_d = *pred_pel; - if (block_available_up_right) - { + if (block_available_up_right) { pred_pel = &imgY[pix_c.pos_y][pix_c.pos_x]; p_e = *pred_pel++; p_f = *pred_pel++; p_g = *pred_pel++; - p_h = *pred_pel ; - } - else - { + p_h = *pred_pel; + } else { p_e = p_f = p_g = p_h = p_d; } - PredPixel[0] = (imgpel) ((p_a + p_c + 2*(p_b) + 2) >> 2); - PredPixel[1] = (imgpel) ((p_b + p_d + 2*(p_c) + 2) >> 2); - PredPixel[2] = (imgpel) ((p_c + p_e + 2*(p_d) + 2) >> 2); - PredPixel[3] = (imgpel) ((p_d + p_f + 2*(p_e) + 2) >> 2); - PredPixel[4] = (imgpel) ((p_e + p_g + 2*(p_f) + 2) >> 2); - PredPixel[5] = (imgpel) ((p_f + p_h + 2*(p_g) + 2) >> 2); - PredPixel[6] = (imgpel) ((p_g + 3*(p_h) + 2) >> 2); + PredPixel[0] = (imgpel)((p_a + p_c + 2 * (p_b) + 2) >> 2); + PredPixel[1] = (imgpel)((p_b + p_d + 2 * (p_c) + 2) >> 2); + PredPixel[2] = (imgpel)((p_c + p_e + 2 * (p_d) + 2) >> 2); + PredPixel[3] = (imgpel)((p_d + p_f + 2 * (p_e) + 2) >> 2); + PredPixel[4] = (imgpel)((p_e + p_g + 2 * (p_f) + 2) >> 2); + PredPixel[5] = (imgpel)((p_f + p_h + 2 * (p_g) + 2) >> 2); + PredPixel[6] = (imgpel)((p_g + 3 * (p_h) + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[0], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[1], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[2], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[3], 4 * sizeof(imgpel)); + memcpy(&mb_pred[joff][ioff], &PredPixel[3], 4 * sizeof(imgpel)); } return DECODING_OK; @@ -425,20 +414,22 @@ static int intra4x4_diag_down_left_pred_mbaff(Macroblock *currMB, //!< curren * makes and returns 4x4 vertical right prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_vert_right_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int +intra4x4_vert_right_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int i; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; PixelPos pix_a[4]; PixelPos pix_b, pix_d; @@ -447,32 +438,36 @@ static int intra4x4_vert_right_pred_mbaff(Macroblock *currMB, //!< current ma int block_available_left; int block_available_up_left; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **mb_pred = currSlice->mb_pred[pl]; - for (i=0;i<4;++i) - { - p_Vid->getNeighbour(currMB, ioff -1 , joff +i , p_Vid->mb_size[IS_LUMA], &pix_a[i]); + for (i = 0; i < 4; ++i) { + p_Vid->getNeighbour(currMB, ioff - 1, joff + i, p_Vid->mb_size[IS_LUMA], + &pix_a[i]); } - p_Vid->getNeighbour(currMB, ioff , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_b); - p_Vid->getNeighbour(currMB, ioff -1 , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_d); + p_Vid->getNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + p_Vid->getNeighbour(currMB, ioff - 1, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_d); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<4;++i) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; - block_available_up_left = pix_d.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 4; ++i) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_4x4_Vertical_Right prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_4x4_Vertical_Right prediction mode not allowed at " + "mb %d\n", + (int)currSlice->current_mb_nr); { imgpel PredPixel[10]; imgpel *pred_pel = &imgY[pix_b.pos_y][pix_b.pos_x]; @@ -481,118 +476,117 @@ static int intra4x4_vert_right_pred_mbaff(Macroblock *currMB, //!< current ma imgpel p_a = *pred_pel++; imgpel p_b = *pred_pel++; imgpel p_c = *pred_pel++; - imgpel p_d = *pred_pel ; + imgpel p_d = *pred_pel; imgpel p_i = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; imgpel p_j = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; imgpel p_k = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; imgpel p_x = imgY[pix_d.pos_y][pix_d.pos_x]; - - PredPixel[0] = (imgpel) ((p_x + 2*p_i + p_j + 2) >> 2); - PredPixel[1] = (imgpel) ((p_x + p_a + 1) >> 1); - PredPixel[2] = (imgpel) ((p_a + p_b + 1) >> 1); - PredPixel[3] = (imgpel) ((p_b + p_c + 1) >> 1); - PredPixel[4] = (imgpel) ((p_c + p_d + 1) >> 1); - PredPixel[5] = (imgpel) ((p_i + 2*p_j + p_k + 2) >> 2); - PredPixel[6] = (imgpel) ((p_i + 2*p_x + p_a + 2) >> 2); - PredPixel[7] = (imgpel) ((p_x + 2*p_a + p_b + 2) >> 2); - PredPixel[8] = (imgpel) ((p_a + 2*p_b + p_c + 2) >> 2); - PredPixel[9] = (imgpel) ((p_b + 2*p_c + p_d + 2) >> 2); + + PredPixel[0] = (imgpel)((p_x + 2 * p_i + p_j + 2) >> 2); + PredPixel[1] = (imgpel)((p_x + p_a + 1) >> 1); + PredPixel[2] = (imgpel)((p_a + p_b + 1) >> 1); + PredPixel[3] = (imgpel)((p_b + p_c + 1) >> 1); + PredPixel[4] = (imgpel)((p_c + p_d + 1) >> 1); + PredPixel[5] = (imgpel)((p_i + 2 * p_j + p_k + 2) >> 2); + PredPixel[6] = (imgpel)((p_i + 2 * p_x + p_a + 2) >> 2); + PredPixel[7] = (imgpel)((p_x + 2 * p_a + p_b + 2) >> 2); + PredPixel[8] = (imgpel)((p_a + 2 * p_b + p_c + 2) >> 2); + PredPixel[9] = (imgpel)((p_b + 2 * p_c + p_d + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[1], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[6], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[0], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[5], 4 * sizeof(imgpel)); - + memcpy(&mb_pred[joff][ioff], &PredPixel[5], 4 * sizeof(imgpel)); } return DECODING_OK; } - /*! *********************************************************************** * \brief * makes and returns 4x4 vertical left prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_vert_left_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int +intra4x4_vert_left_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + PixelPos pix_b, pix_c; int block_available_up; int block_available_up_right; - p_Vid->getNeighbour(currMB, ioff , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_b); - p_Vid->getNeighbour(currMB, ioff +4 , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_c); + p_Vid->getNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + p_Vid->getNeighbour(currMB, ioff + 4, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_c); - pix_c.available = pix_c.available && !((ioff==4) && ((joff==4)||(joff==12))); - - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - } - else - { - block_available_up = pix_b.available; + pix_c.available = + pix_c.available && !((ioff == 4) && ((joff == 4) || (joff == 12))); + + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + } else { + block_available_up = pix_b.available; block_available_up_right = pix_c.available; } - if (!block_available_up) - printf ("warning: Intra_4x4_Vertical_Left prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_4x4_Vertical_Left prediction mode not allowed at mb " + "%d\n", + (int)currSlice->current_mb_nr); { imgpel PredPixel[10]; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = currSlice->mb_pred[pl]; imgpel *pred_pel = &imgY[pix_b.pos_y][pix_b.pos_x]; // form predictor pels imgpel p_a = *pred_pel++; imgpel p_b = *pred_pel++; imgpel p_c = *pred_pel++; - imgpel p_d = *pred_pel ; + imgpel p_d = *pred_pel; imgpel p_e, p_f, p_g; - if (block_available_up_right) - { + if (block_available_up_right) { imgpel *pred_pel = &imgY[pix_c.pos_y][pix_c.pos_x]; p_e = *pred_pel++; p_f = *pred_pel++; p_g = *pred_pel++; - } - else - { + } else { p_e = p_f = p_g = p_d; } - PredPixel[0] = (imgpel) ((p_a + p_b + 1) >> 1); - PredPixel[1] = (imgpel) ((p_b + p_c + 1) >> 1); - PredPixel[2] = (imgpel) ((p_c + p_d + 1) >> 1); - PredPixel[3] = (imgpel) ((p_d + p_e + 1) >> 1); - PredPixel[4] = (imgpel) ((p_e + p_f + 1) >> 1); - PredPixel[5] = (imgpel) ((p_a + 2*p_b + p_c + 2) >> 2); - PredPixel[6] = (imgpel) ((p_b + 2*p_c + p_d + 2) >> 2); - PredPixel[7] = (imgpel) ((p_c + 2*p_d + p_e + 2) >> 2); - PredPixel[8] = (imgpel) ((p_d + 2*p_e + p_f + 2) >> 2); - PredPixel[9] = (imgpel) ((p_e + 2*p_f + p_g + 2) >> 2); + PredPixel[0] = (imgpel)((p_a + p_b + 1) >> 1); + PredPixel[1] = (imgpel)((p_b + p_c + 1) >> 1); + PredPixel[2] = (imgpel)((p_c + p_d + 1) >> 1); + PredPixel[3] = (imgpel)((p_d + p_e + 1) >> 1); + PredPixel[4] = (imgpel)((p_e + p_f + 1) >> 1); + PredPixel[5] = (imgpel)((p_a + 2 * p_b + p_c + 2) >> 2); + PredPixel[6] = (imgpel)((p_b + 2 * p_c + p_d + 2) >> 2); + PredPixel[7] = (imgpel)((p_c + 2 * p_d + p_e + 2) >> 2); + PredPixel[8] = (imgpel)((p_d + 2 * p_e + p_f + 2) >> 2); + PredPixel[9] = (imgpel)((p_e + 2 * p_f + p_g + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[0], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[5], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[1], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[6], 4 * sizeof(imgpel)); + memcpy(&mb_pred[joff][ioff], &PredPixel[6], 4 * sizeof(imgpel)); } return DECODING_OK; } @@ -603,46 +597,47 @@ static int intra4x4_vert_left_pred_mbaff(Macroblock *currMB, //!< current mac * makes and returns 4x4 horizontal up prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_hor_up_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int +intra4x4_hor_up_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int i; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; PixelPos pix_a[4]; int block_available_left; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **mb_pred = currSlice->mb_pred[pl]; - for (i=0;i<4;++i) - { - p_Vid->getNeighbour(currMB, ioff -1 , joff +i , p_Vid->mb_size[IS_LUMA], &pix_a[i]); + for (i = 0; i < 4; ++i) { + p_Vid->getNeighbour(currMB, ioff - 1, joff + i, p_Vid->mb_size[IS_LUMA], + &pix_a[i]); } - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<4;++i) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - } - else - { - block_available_left = pix_a[0].available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 4; ++i) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; } if (!block_available_left) - printf ("warning: Intra_4x4_Horizontal_Up prediction mode not allowed at mb %d\n",(int) currSlice->current_mb_nr); - else - { + printf("warning: Intra_4x4_Horizontal_Up prediction mode not allowed at mb " + "%d\n", + (int)currSlice->current_mb_nr); + else { imgpel PredPixel[10]; // form predictor pels @@ -651,16 +646,16 @@ static int intra4x4_hor_up_pred_mbaff(Macroblock *currMB, //!< current macrob imgpel p_k = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; imgpel p_l = imgY[pix_a[3].pos_y][pix_a[3].pos_x]; - PredPixel[0] = (imgpel) ((p_i + p_j + 1) >> 1); - PredPixel[1] = (imgpel) ((p_i + 2*p_j + p_k + 2) >> 2); - PredPixel[2] = (imgpel) ((p_j + p_k + 1) >> 1); - PredPixel[3] = (imgpel) ((p_j + 2*p_k + p_l + 2) >> 2); - PredPixel[4] = (imgpel) ((p_k + p_l + 1) >> 1); - PredPixel[5] = (imgpel) ((p_k + 2*p_l + p_l + 2) >> 2); - PredPixel[6] = (imgpel) p_l; - PredPixel[7] = (imgpel) p_l; - PredPixel[8] = (imgpel) p_l; - PredPixel[9] = (imgpel) p_l; + PredPixel[0] = (imgpel)((p_i + p_j + 1) >> 1); + PredPixel[1] = (imgpel)((p_i + 2 * p_j + p_k + 2) >> 2); + PredPixel[2] = (imgpel)((p_j + p_k + 1) >> 1); + PredPixel[3] = (imgpel)((p_j + 2 * p_k + p_l + 2) >> 2); + PredPixel[4] = (imgpel)((p_k + p_l + 1) >> 1); + PredPixel[5] = (imgpel)((p_k + 2 * p_l + p_l + 2) >> 2); + PredPixel[6] = (imgpel)p_l; + PredPixel[7] = (imgpel)p_l; + PredPixel[8] = (imgpel)p_l; + PredPixel[9] = (imgpel)p_l; memcpy(&mb_pred[joff++][ioff], &PredPixel[0], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[2], 4 * sizeof(imgpel)); @@ -677,20 +672,22 @@ static int intra4x4_hor_up_pred_mbaff(Macroblock *currMB, //!< current macrob * makes and returns 4x4 horizontal down prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_hor_down_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int +intra4x4_hor_down_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - - int i; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + + int i; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; PixelPos pix_a[4]; PixelPos pix_b, pix_d; @@ -699,34 +696,37 @@ static int intra4x4_hor_down_pred_mbaff(Macroblock *currMB, //!< current macr int block_available_left; int block_available_up_left; - imgpel **mb_pred = currSlice->mb_pred[pl]; - - for (i=0;i<4;++i) - { - p_Vid->getNeighbour(currMB, ioff -1 , joff +i , p_Vid->mb_size[IS_LUMA], &pix_a[i]); + imgpel **mb_pred = currSlice->mb_pred[pl]; + + for (i = 0; i < 4; ++i) { + p_Vid->getNeighbour(currMB, ioff - 1, joff + i, p_Vid->mb_size[IS_LUMA], + &pix_a[i]); } - p_Vid->getNeighbour(currMB, ioff , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_b); - p_Vid->getNeighbour(currMB, ioff -1 , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_d); + p_Vid->getNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + p_Vid->getNeighbour(currMB, ioff - 1, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_d); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<4;++i) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; - block_available_up_left = pix_d.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 4; ++i) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_4x4_Horizontal_Down prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); - else - { + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_4x4_Horizontal_Down prediction mode not allowed at " + "mb %d\n", + (int)currSlice->current_mb_nr); + else { imgpel PredPixel[10]; imgpel *pred_pel = &imgY[pix_b.pos_y][pix_b.pos_x]; @@ -742,21 +742,21 @@ static int intra4x4_hor_down_pred_mbaff(Macroblock *currMB, //!< current macr imgpel p_x = imgY[pix_d.pos_y][pix_d.pos_x]; - PredPixel[0] = (imgpel) ((p_k + p_l + 1) >> 1); - PredPixel[1] = (imgpel) ((p_j + 2*p_k + p_l + 2) >> 2); - PredPixel[2] = (imgpel) ((p_j + p_k + 1) >> 1); - PredPixel[3] = (imgpel) ((p_i + 2*p_j + p_k + 2) >> 2); - PredPixel[4] = (imgpel) ((p_i + p_j + 1) >> 1); - PredPixel[5] = (imgpel) ((p_x + 2*p_i + p_j + 2) >> 2); - PredPixel[6] = (imgpel) ((p_x + p_i + 1) >> 1); - PredPixel[7] = (imgpel) ((p_i + 2*p_x + p_a + 2) >> 2); - PredPixel[8] = (imgpel) ((p_x + 2*p_a + p_b + 2) >> 2); - PredPixel[9] = (imgpel) ((p_a + 2*p_b + p_c + 2) >> 2); + PredPixel[0] = (imgpel)((p_k + p_l + 1) >> 1); + PredPixel[1] = (imgpel)((p_j + 2 * p_k + p_l + 2) >> 2); + PredPixel[2] = (imgpel)((p_j + p_k + 1) >> 1); + PredPixel[3] = (imgpel)((p_i + 2 * p_j + p_k + 2) >> 2); + PredPixel[4] = (imgpel)((p_i + p_j + 1) >> 1); + PredPixel[5] = (imgpel)((p_x + 2 * p_i + p_j + 2) >> 2); + PredPixel[6] = (imgpel)((p_x + p_i + 1) >> 1); + PredPixel[7] = (imgpel)((p_i + 2 * p_x + p_a + 2) >> 2); + PredPixel[8] = (imgpel)((p_x + 2 * p_a + p_b + 2) >> 2); + PredPixel[9] = (imgpel)((p_a + 2 * p_b + p_c + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[6], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[4], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[2], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[0], 4 * sizeof(imgpel)); + memcpy(&mb_pred[joff][ioff], &PredPixel[0], 4 * sizeof(imgpel)); } return DECODING_OK; @@ -765,26 +765,26 @@ static int intra4x4_hor_down_pred_mbaff(Macroblock *currMB, //!< current macr /*! *********************************************************************** * \brief - * makes and returns 4x4 intra prediction blocks + * makes and returns 4x4 intra prediction blocks * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * SEARCH_SYNC search next sync element as errors while decoding occured *********************************************************************** */ -int intra4x4_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff, //!< pixel offset Y within MB - int img_block_x, //!< location of block X, multiples of 4 - int img_block_y) //!< location of block Y, multiples of 4 +int intra4x4_pred_mbaff( + Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff, //!< pixel offset Y within MB + int img_block_x, //!< location of block X, multiples of 4 + int img_block_y) //!< location of block Y, multiples of 4 { VideoParameters *p_Vid = currMB->p_Vid; byte predmode = p_Vid->ipredmode[img_block_y][img_block_x]; - currMB->ipmode_DPCM = predmode; //For residual DPCM + currMB->ipmode_DPCM = predmode; // For residual DPCM - switch (predmode) - { + switch (predmode) { case DC_PRED: return (intra4x4_dc_pred_mbaff(currMB, pl, ioff, joff)); break; @@ -809,10 +809,10 @@ int intra4x4_pred_mbaff(Macroblock *currMB, //!< current macroblock case HOR_UP_PRED: return (intra4x4_hor_up_pred_mbaff(currMB, pl, ioff, joff)); break; - case HOR_DOWN_PRED: + case HOR_DOWN_PRED: return (intra4x4_hor_down_pred_mbaff(currMB, pl, ioff, joff)); default: - printf("Error: illegal intra_4x4 prediction mode: %d\n", (int) predmode); + printf("Error: illegal intra_4x4 prediction mode: %d\n", (int)predmode); return SEARCH_SYNC; break; } diff --git a/src/common/ldecod_src/intra4x4_pred_normal.c b/src/common/ldecod_src/intra4x4_pred_normal.c index 0c37933..40852c1 100644 --- a/src/common/ldecod_src/intra4x4_pred_normal.c +++ b/src/common/ldecod_src/intra4x4_pred_normal.c @@ -6,16 +6,16 @@ * Functions for intra 4x4 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * ************************************************************************************* */ #include "global.h" +#include "image.h" #include "intra4x4_pred.h" #include "mb_access.h" -#include "image.h" // Notation for comments regarding prediction and predictors. // The pels of the 4x4 block are labelled a..p. The predictor pels above @@ -42,47 +42,43 @@ * \param joff * pixel offset Y within MB * \return - * DECODING_OK decoding of intra prediction mode was successful \n + * DECODING_OK decoding of intra prediction mode was successful \n * *********************************************************************** */ -static int intra4x4_dc_pred(Macroblock *currMB, - ColorPlane pl, - int ioff, - int joff) -{ +static int intra4x4_dc_pred(Macroblock *currMB, ColorPlane pl, int ioff, + int joff) { Slice *currSlice = currMB->p_Slice; - VideoParameters *p_Vid = currMB->p_Vid; + VideoParameters *p_Vid = currMB->p_Vid; int j; - int s0 = 0; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + int s0 = 0; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; imgpel *curpel = NULL; - PixelPos pix_a, pix_b; + PixelPos pix_a, pix_b; int block_available_up; - int block_available_left; + int block_available_left; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **mb_pred = currSlice->mb_pred[pl]; - getNonAffNeighbour(currMB, ioff - 1, joff , p_Vid->mb_size[IS_LUMA], &pix_a); - getNonAffNeighbour(currMB, ioff , joff -1, p_Vid->mb_size[IS_LUMA], &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff, p_Vid->mb_size[IS_LUMA], &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr] : 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - } - else - { + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + } else { block_available_left = pix_a.available; - block_available_up = pix_b.available; + block_available_up = pix_b.available; } // form predictor pels - if (block_available_up) - { + if (block_available_up) { curpel = &imgY[pix_b.pos_y][pix_b.pos_x]; s0 += *curpel++; s0 += *curpel++; @@ -90,44 +86,36 @@ static int intra4x4_dc_pred(Macroblock *currMB, s0 += *curpel; } - if (block_available_left) - { + if (block_available_left) { imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - s0 += *(*(img_pred ++) + pos_x); - s0 += *(*(img_pred ++) + pos_x); - s0 += *(*(img_pred ++) + pos_x); - s0 += *(*(img_pred ) + pos_x); + s0 += *(*(img_pred++) + pos_x); + s0 += *(*(img_pred++) + pos_x); + s0 += *(*(img_pred++) + pos_x); + s0 += *(*(img_pred) + pos_x); } - if (block_available_up && block_available_left) - { + if (block_available_up && block_available_left) { // no edge - s0 = (s0 + 4)>>3; - } - else if (!block_available_up && block_available_left) - { + s0 = (s0 + 4) >> 3; + } else if (!block_available_up && block_available_left) { // upper edge - s0 = (s0 + 2)>>2; - } - else if (block_available_up && !block_available_left) - { + s0 = (s0 + 2) >> 2; + } else if (block_available_up && !block_available_left) { // left edge - s0 = (s0 + 2)>>2; - } - else //if (!block_available_up && !block_available_left) + s0 = (s0 + 2) >> 2; + } else // if (!block_available_up && !block_available_left) { // top left corner, nothing to predict from s0 = p_Vid->dc_pred_value_comp[pl]; } - for (j=joff; j < joff + BLOCK_SIZE; ++j) - { + for (j = joff; j < joff + BLOCK_SIZE; ++j) { // store DC prediction - mb_pred[j][ioff ] = (imgpel) s0; - mb_pred[j][ioff + 1] = (imgpel) s0; - mb_pred[j][ioff + 2] = (imgpel) s0; - mb_pred[j][ioff + 3] = (imgpel) s0; + mb_pred[j][ioff] = (imgpel)s0; + mb_pred[j][ioff + 1] = (imgpel)s0; + mb_pred[j][ioff + 2] = (imgpel)s0; + mb_pred[j][ioff + 3] = (imgpel)s0; } return DECODING_OK; } @@ -138,44 +126,42 @@ static int intra4x4_dc_pred(Macroblock *currMB, * makes and returns 4x4 vertical prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_vert_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int intra4x4_vert_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int block_available_up; PixelPos pix_b; - getNonAffNeighbour(currMB, ioff, joff - 1 , p_Vid->mb_size[IS_LUMA], &pix_b); + getNonAffNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - } - else - { + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + } else { block_available_up = pix_b.available; } - if (!block_available_up) - { - printf ("warning: Intra_4x4_Vertical prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); - } - else - { + if (!block_available_up) { + printf("warning: Intra_4x4_Vertical prediction mode not allowed at mb %d\n", + (int)currSlice->current_mb_nr); + } else { imgpel **mb_pred = currSlice->mb_pred[pl]; - imgpel *imgY = (pl) ? &currSlice->dec_picture->imgUV[pl - 1][pix_b.pos_y][pix_b.pos_x] : &currSlice->dec_picture->imgY[pix_b.pos_y][pix_b.pos_x]; + imgpel *imgY = + (pl) ? &currSlice->dec_picture->imgUV[pl - 1][pix_b.pos_y][pix_b.pos_x] + : &currSlice->dec_picture->imgY[pix_b.pos_y][pix_b.pos_x]; memcpy(&(mb_pred[joff++][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); memcpy(&(mb_pred[joff++][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); memcpy(&(mb_pred[joff++][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); - memcpy(&(mb_pred[joff ][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); + memcpy(&(mb_pred[joff][ioff]), imgY, BLOCK_SIZE * sizeof(imgpel)); } return DECODING_OK; } @@ -199,11 +185,8 @@ static int intra4x4_vert_pred(Macroblock *currMB, //!< current macroblock * *********************************************************************** */ -static int intra4x4_hor_pred(Macroblock *currMB, - ColorPlane pl, - int ioff, - int joff) -{ +static int intra4x4_hor_pred(Macroblock *currMB, ColorPlane pl, int ioff, + int joff) { VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; @@ -211,31 +194,36 @@ static int intra4x4_hor_pred(Macroblock *currMB, int block_available_left; - getNonAffNeighbour(currMB, ioff - 1 , joff, p_Vid->mb_size[IS_LUMA], &pix_a); + getNonAffNeighbour(currMB, ioff - 1, joff, p_Vid->mb_size[IS_LUMA], &pix_a); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block[pix_a.mb_addr]: 0; - } - else - { + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + } else { block_available_left = pix_a.available; } if (!block_available_left) - printf ("warning: Intra_4x4_Horizontal prediction mode not allowed at mb %d\n",(int) currSlice->current_mb_nr); + printf( + "warning: Intra_4x4_Horizontal prediction mode not allowed at mb %d\n", + (int)currSlice->current_mb_nr); else #if (IMGTYPE == 0) { - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = &currSlice->mb_pred[pl][joff]; - imgpel **img_pred = &imgY[pix_a.pos_y]; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = &currSlice->mb_pred[pl][joff]; + imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - memset((*(mb_pred++) + ioff), *(*(img_pred++) + pos_x), BLOCK_SIZE * sizeof (imgpel)); - memset((*(mb_pred++) + ioff), *(*(img_pred++) + pos_x), BLOCK_SIZE * sizeof (imgpel)); - memset((*(mb_pred++) + ioff), *(*(img_pred++) + pos_x), BLOCK_SIZE * sizeof (imgpel)); - memset((*(mb_pred ) + ioff), *(*(img_pred ) + pos_x), BLOCK_SIZE * sizeof (imgpel)); + memset((*(mb_pred++) + ioff), *(*(img_pred++) + pos_x), + BLOCK_SIZE * sizeof(imgpel)); + memset((*(mb_pred++) + ioff), *(*(img_pred++) + pos_x), + BLOCK_SIZE * sizeof(imgpel)); + memset((*(mb_pred++) + ioff), *(*(img_pred++) + pos_x), + BLOCK_SIZE * sizeof(imgpel)); + memset((*(mb_pred) + ioff), *(*(img_pred) + pos_x), + BLOCK_SIZE * sizeof(imgpel)); } #else { @@ -243,18 +231,18 @@ static int intra4x4_hor_pred(Macroblock *currMB, int pos_y = pix_a.pos_y; int pos_x = pix_a.pos_x; imgpel *predrow, prediction; - imgpel **mb_pred = &currSlice->mb_pred[pl][joff]; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + imgpel **mb_pred = &currSlice->mb_pred[pl][joff]; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; - for(j=0;jp_Slice; VideoParameters *p_Vid = currMB->p_Vid; - - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; + + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; PixelPos pix_a; PixelPos pix_b, pix_d; @@ -289,29 +279,32 @@ static int intra4x4_diag_down_right_pred(Macroblock *currMB, //!< current mac int block_available_left; int block_available_up_left; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **mb_pred = currSlice->mb_pred[pl]; - getNonAffNeighbour(currMB, ioff -1 , joff , p_Vid->mb_size[IS_LUMA], &pix_a); - getNonAffNeighbour(currMB, ioff , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_b); - getNonAffNeighbour(currMB, ioff -1 , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_d); + getNonAffNeighbour(currMB, ioff - 1, joff, p_Vid->mb_size[IS_LUMA], &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_d); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; - block_available_up_left = pix_d.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_4x4_Diagonal_Down_Right prediction mode not allowed at mb %d\n",(int) currSlice->current_mb_nr); - else - { + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_4x4_Diagonal_Down_Right prediction mode not allowed " + "at mb %d\n", + (int)currSlice->current_mb_nr); + else { imgpel PredPixel[7]; imgpel **img_pred = &imgY[pix_a.pos_y]; int pix_x = pix_a.pos_x; @@ -320,27 +313,27 @@ static int intra4x4_diag_down_right_pred(Macroblock *currMB, //!< current mac imgpel p_a = *pred_pel++; imgpel p_b = *pred_pel++; imgpel p_c = *pred_pel++; - imgpel p_d = *pred_pel ; + imgpel p_d = *pred_pel; imgpel p_i = *(*(img_pred++) + pix_x); imgpel p_j = *(*(img_pred++) + pix_x); imgpel p_k = *(*(img_pred++) + pix_x); - imgpel p_l = *(*(img_pred ) + pix_x); + imgpel p_l = *(*(img_pred) + pix_x); imgpel p_x = imgY[pix_d.pos_y][pix_d.pos_x]; - - PredPixel[0] = (imgpel) ((p_l + 2*p_k + p_j + 2) >> 2); - PredPixel[1] = (imgpel) ((p_k + 2*p_j + p_i + 2) >> 2); - PredPixel[2] = (imgpel) ((p_j + 2*p_i + p_x + 2) >> 2); - PredPixel[3] = (imgpel) ((p_i + 2*p_x + p_a + 2) >> 2); - PredPixel[4] = (imgpel) ((p_x + 2*p_a + p_b + 2) >> 2); - PredPixel[5] = (imgpel) ((p_a + 2*p_b + p_c + 2) >> 2); - PredPixel[6] = (imgpel) ((p_b + 2*p_c + p_d + 2) >> 2); + + PredPixel[0] = (imgpel)((p_l + 2 * p_k + p_j + 2) >> 2); + PredPixel[1] = (imgpel)((p_k + 2 * p_j + p_i + 2) >> 2); + PredPixel[2] = (imgpel)((p_j + 2 * p_i + p_x + 2) >> 2); + PredPixel[3] = (imgpel)((p_i + 2 * p_x + p_a + 2) >> 2); + PredPixel[4] = (imgpel)((p_x + 2 * p_a + p_b + 2) >> 2); + PredPixel[5] = (imgpel)((p_a + 2 * p_b + p_c + 2) >> 2); + PredPixel[6] = (imgpel)((p_b + 2 * p_c + p_d + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[3], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[2], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[1], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[0], 4 * sizeof(imgpel)); + memcpy(&mb_pred[joff][ioff], &PredPixel[0], 4 * sizeof(imgpel)); } return DECODING_OK; @@ -352,45 +345,49 @@ static int intra4x4_diag_down_right_pred(Macroblock *currMB, //!< current mac * makes and returns 4x4 diagonal down left prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_diag_down_left_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int +intra4x4_diag_down_left_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + PixelPos pix_b, pix_c; int block_available_up; int block_available_up_right; - p_Vid->getNeighbour(currMB, ioff , joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); - p_Vid->getNeighbour(currMB, ioff + 4, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_c); + p_Vid->getNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + p_Vid->getNeighbour(currMB, ioff + 4, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_c); - pix_c.available = pix_c.available && !((ioff==4) && ((joff==4)||(joff==12))); + pix_c.available = + pix_c.available && !((ioff == 4) && ((joff == 4) || (joff == 12))); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - } - else - { - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + } else { + block_available_up = pix_b.available; block_available_up_right = pix_c.available; } if (!block_available_up) - printf ("warning: Intra_4x4_Diagonal_Down_Left prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); - else - { - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = currSlice->mb_pred[pl]; + printf("warning: Intra_4x4_Diagonal_Down_Left prediction mode not allowed " + "at mb %d\n", + (int)currSlice->current_mb_nr); + else { + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = currSlice->mb_pred[pl]; imgpel p_e, p_f, p_g, p_h; imgpel PredPixel[8]; @@ -400,33 +397,30 @@ static int intra4x4_diag_down_left_pred(Macroblock *currMB, //!< current macr imgpel p_a = *pred_pel++; imgpel p_b = *pred_pel++; imgpel p_c = *pred_pel++; - imgpel p_d = *pred_pel ; + imgpel p_d = *pred_pel; - if (block_available_up_right) - { + if (block_available_up_right) { pred_pel = &imgY[pix_c.pos_y][pix_c.pos_x]; p_e = *pred_pel++; p_f = *pred_pel++; p_g = *pred_pel++; - p_h = *pred_pel ; - } - else - { + p_h = *pred_pel; + } else { p_e = p_f = p_g = p_h = p_d; } - PredPixel[0] = (imgpel) ((p_a + p_c + 2*(p_b) + 2) >> 2); - PredPixel[1] = (imgpel) ((p_b + p_d + 2*(p_c) + 2) >> 2); - PredPixel[2] = (imgpel) ((p_c + p_e + 2*(p_d) + 2) >> 2); - PredPixel[3] = (imgpel) ((p_d + p_f + 2*(p_e) + 2) >> 2); - PredPixel[4] = (imgpel) ((p_e + p_g + 2*(p_f) + 2) >> 2); - PredPixel[5] = (imgpel) ((p_f + p_h + 2*(p_g) + 2) >> 2); - PredPixel[6] = (imgpel) ((p_g + 3*(p_h) + 2) >> 2); + PredPixel[0] = (imgpel)((p_a + p_c + 2 * (p_b) + 2) >> 2); + PredPixel[1] = (imgpel)((p_b + p_d + 2 * (p_c) + 2) >> 2); + PredPixel[2] = (imgpel)((p_c + p_e + 2 * (p_d) + 2) >> 2); + PredPixel[3] = (imgpel)((p_d + p_f + 2 * (p_e) + 2) >> 2); + PredPixel[4] = (imgpel)((p_e + p_g + 2 * (p_f) + 2) >> 2); + PredPixel[5] = (imgpel)((p_f + p_h + 2 * (p_g) + 2) >> 2); + PredPixel[6] = (imgpel)((p_g + 3 * (p_h) + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[0], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[1], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[2], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[3], 4 * sizeof(imgpel)); + memcpy(&mb_pred[joff][ioff], &PredPixel[3], 4 * sizeof(imgpel)); } return DECODING_OK; @@ -438,46 +432,51 @@ static int intra4x4_diag_down_left_pred(Macroblock *currMB, //!< current macr * makes and returns 4x4 vertical right prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_vert_right_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int intra4x4_vert_right_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + PixelPos pix_a, pix_b, pix_d; int block_available_up; int block_available_left; int block_available_up_left; - getNonAffNeighbour(currMB, ioff -1 , joff , p_Vid->mb_size[IS_LUMA], &pix_a); - getNonAffNeighbour(currMB, ioff , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_b); - getNonAffNeighbour(currMB, ioff -1 , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_d); + getNonAffNeighbour(currMB, ioff - 1, joff, p_Vid->mb_size[IS_LUMA], &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_d); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block[pix_a.mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; - block_available_up_left = pix_d.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_4x4_Vertical_Right prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_4x4_Vertical_Right prediction mode not allowed at " + "mb %d\n", + (int)currSlice->current_mb_nr); { - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = currSlice->mb_pred[pl]; imgpel PredPixel[10]; imgpel **img_pred = &imgY[pix_a.pos_y]; @@ -487,118 +486,116 @@ static int intra4x4_vert_right_pred(Macroblock *currMB, //!< current macroblo imgpel p_a = *pred_pel++; imgpel p_b = *pred_pel++; imgpel p_c = *pred_pel++; - imgpel p_d = *pred_pel ; + imgpel p_d = *pred_pel; imgpel p_i = *(*(img_pred++) + pix_x); imgpel p_j = *(*(img_pred++) + pix_x); imgpel p_k = *(*(img_pred++) + pix_x); imgpel p_x = imgY[pix_d.pos_y][pix_d.pos_x]; - - PredPixel[0] = (imgpel) ((p_x + 2*p_i + p_j + 2) >> 2); - PredPixel[1] = (imgpel) ((p_x + p_a + 1) >> 1); - PredPixel[2] = (imgpel) ((p_a + p_b + 1) >> 1); - PredPixel[3] = (imgpel) ((p_b + p_c + 1) >> 1); - PredPixel[4] = (imgpel) ((p_c + p_d + 1) >> 1); - PredPixel[5] = (imgpel) ((p_i + 2*p_j + p_k + 2) >> 2); - PredPixel[6] = (imgpel) ((p_i + 2*p_x + p_a + 2) >> 2); - PredPixel[7] = (imgpel) ((p_x + 2*p_a + p_b + 2) >> 2); - PredPixel[8] = (imgpel) ((p_a + 2*p_b + p_c + 2) >> 2); - PredPixel[9] = (imgpel) ((p_b + 2*p_c + p_d + 2) >> 2); + + PredPixel[0] = (imgpel)((p_x + 2 * p_i + p_j + 2) >> 2); + PredPixel[1] = (imgpel)((p_x + p_a + 1) >> 1); + PredPixel[2] = (imgpel)((p_a + p_b + 1) >> 1); + PredPixel[3] = (imgpel)((p_b + p_c + 1) >> 1); + PredPixel[4] = (imgpel)((p_c + p_d + 1) >> 1); + PredPixel[5] = (imgpel)((p_i + 2 * p_j + p_k + 2) >> 2); + PredPixel[6] = (imgpel)((p_i + 2 * p_x + p_a + 2) >> 2); + PredPixel[7] = (imgpel)((p_x + 2 * p_a + p_b + 2) >> 2); + PredPixel[8] = (imgpel)((p_a + 2 * p_b + p_c + 2) >> 2); + PredPixel[9] = (imgpel)((p_b + 2 * p_c + p_d + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[1], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[6], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[0], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[5], 4 * sizeof(imgpel)); - + memcpy(&mb_pred[joff][ioff], &PredPixel[5], 4 * sizeof(imgpel)); } return DECODING_OK; } - /*! *********************************************************************** * \brief * makes and returns 4x4 vertical left prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_vert_left_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int intra4x4_vert_left_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + PixelPos pix_b, pix_c; int block_available_up; int block_available_up_right; - p_Vid->getNeighbour(currMB, ioff , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_b); - p_Vid->getNeighbour(currMB, ioff +4 , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_c); + p_Vid->getNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + p_Vid->getNeighbour(currMB, ioff + 4, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_c); - pix_c.available = pix_c.available && !((ioff==4) && ((joff==4)||(joff==12))); - - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - } - else - { - block_available_up = pix_b.available; + pix_c.available = + pix_c.available && !((ioff == 4) && ((joff == 4) || (joff == 12))); + + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + } else { + block_available_up = pix_b.available; block_available_up_right = pix_c.available; } - if (!block_available_up) - printf ("warning: Intra_4x4_Vertical_Left prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_4x4_Vertical_Left prediction mode not allowed at mb " + "%d\n", + (int)currSlice->current_mb_nr); { imgpel PredPixel[10]; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = currSlice->mb_pred[pl]; imgpel *pred_pel = &imgY[pix_b.pos_y][pix_b.pos_x]; // form predictor pels imgpel p_a = *pred_pel++; imgpel p_b = *pred_pel++; imgpel p_c = *pred_pel++; - imgpel p_d = *pred_pel ; + imgpel p_d = *pred_pel; imgpel p_e, p_f, p_g; - if (block_available_up_right) - { + if (block_available_up_right) { imgpel *pred_pel = &imgY[pix_c.pos_y][pix_c.pos_x]; p_e = *pred_pel++; p_f = *pred_pel++; p_g = *pred_pel++; - } - else - { + } else { p_e = p_f = p_g = p_d; } - PredPixel[0] = (imgpel) ((p_a + p_b + 1) >> 1); - PredPixel[1] = (imgpel) ((p_b + p_c + 1) >> 1); - PredPixel[2] = (imgpel) ((p_c + p_d + 1) >> 1); - PredPixel[3] = (imgpel) ((p_d + p_e + 1) >> 1); - PredPixel[4] = (imgpel) ((p_e + p_f + 1) >> 1); - PredPixel[5] = (imgpel) ((p_a + 2*p_b + p_c + 2) >> 2); - PredPixel[6] = (imgpel) ((p_b + 2*p_c + p_d + 2) >> 2); - PredPixel[7] = (imgpel) ((p_c + 2*p_d + p_e + 2) >> 2); - PredPixel[8] = (imgpel) ((p_d + 2*p_e + p_f + 2) >> 2); - PredPixel[9] = (imgpel) ((p_e + 2*p_f + p_g + 2) >> 2); + PredPixel[0] = (imgpel)((p_a + p_b + 1) >> 1); + PredPixel[1] = (imgpel)((p_b + p_c + 1) >> 1); + PredPixel[2] = (imgpel)((p_c + p_d + 1) >> 1); + PredPixel[3] = (imgpel)((p_d + p_e + 1) >> 1); + PredPixel[4] = (imgpel)((p_e + p_f + 1) >> 1); + PredPixel[5] = (imgpel)((p_a + 2 * p_b + p_c + 2) >> 2); + PredPixel[6] = (imgpel)((p_b + 2 * p_c + p_d + 2) >> 2); + PredPixel[7] = (imgpel)((p_c + 2 * p_d + p_e + 2) >> 2); + PredPixel[8] = (imgpel)((p_d + 2 * p_e + p_f + 2) >> 2); + PredPixel[9] = (imgpel)((p_e + 2 * p_f + p_g + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[0], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[5], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[1], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[6], 4 * sizeof(imgpel)); + memcpy(&mb_pred[joff][ioff], &PredPixel[6], 4 * sizeof(imgpel)); } return DECODING_OK; } @@ -609,40 +606,40 @@ static int intra4x4_vert_left_pred(Macroblock *currMB, //!< current macrobloc * makes and returns 4x4 horizontal up prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_hor_up_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int intra4x4_hor_up_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + PixelPos pix_a; int block_available_left; - getNonAffNeighbour(currMB, ioff -1 , joff, p_Vid->mb_size[IS_LUMA], &pix_a); + getNonAffNeighbour(currMB, ioff - 1, joff, p_Vid->mb_size[IS_LUMA], &pix_a); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block[pix_a.mb_addr]: 0; - } - else - { + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + } else { block_available_left = pix_a.available; } if (!block_available_left) - printf ("warning: Intra_4x4_Horizontal_Up prediction mode not allowed at mb %d\n",(int) currSlice->current_mb_nr); - else - { + printf("warning: Intra_4x4_Horizontal_Up prediction mode not allowed at mb " + "%d\n", + (int)currSlice->current_mb_nr); + else { imgpel PredPixel[10]; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = currSlice->mb_pred[pl]; imgpel **img_pred = &imgY[pix_a.pos_y]; int pix_x = pix_a.pos_x; @@ -651,18 +648,18 @@ static int intra4x4_hor_up_pred(Macroblock *currMB, //!< current macroblock imgpel p_i = *(*(img_pred++) + pix_x); imgpel p_j = *(*(img_pred++) + pix_x); imgpel p_k = *(*(img_pred++) + pix_x); - imgpel p_l = *(*(img_pred ) + pix_x); + imgpel p_l = *(*(img_pred) + pix_x); - PredPixel[0] = (imgpel) ((p_i + p_j + 1) >> 1); - PredPixel[1] = (imgpel) ((p_i + 2*p_j + p_k + 2) >> 2); - PredPixel[2] = (imgpel) ((p_j + p_k + 1) >> 1); - PredPixel[3] = (imgpel) ((p_j + 2*p_k + p_l + 2) >> 2); - PredPixel[4] = (imgpel) ((p_k + p_l + 1) >> 1); - PredPixel[5] = (imgpel) ((p_k + 2*p_l + p_l + 2) >> 2); - PredPixel[6] = (imgpel) p_l; - PredPixel[7] = (imgpel) p_l; - PredPixel[8] = (imgpel) p_l; - PredPixel[9] = (imgpel) p_l; + PredPixel[0] = (imgpel)((p_i + p_j + 1) >> 1); + PredPixel[1] = (imgpel)((p_i + 2 * p_j + p_k + 2) >> 2); + PredPixel[2] = (imgpel)((p_j + p_k + 1) >> 1); + PredPixel[3] = (imgpel)((p_j + 2 * p_k + p_l + 2) >> 2); + PredPixel[4] = (imgpel)((p_k + p_l + 1) >> 1); + PredPixel[5] = (imgpel)((p_k + 2 * p_l + p_l + 2) >> 2); + PredPixel[6] = (imgpel)p_l; + PredPixel[7] = (imgpel)p_l; + PredPixel[8] = (imgpel)p_l; + PredPixel[9] = (imgpel)p_l; memcpy(&mb_pred[joff++][ioff], &PredPixel[0], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[2], 4 * sizeof(imgpel)); @@ -679,48 +676,52 @@ static int intra4x4_hor_up_pred(Macroblock *currMB, //!< current macroblock * makes and returns 4x4 horizontal down prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static int intra4x4_hor_down_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static int intra4x4_hor_down_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + PixelPos pix_a, pix_b, pix_d; int block_available_up; int block_available_left; int block_available_up_left; - getNonAffNeighbour(currMB, ioff -1 , joff , p_Vid->mb_size[IS_LUMA], &pix_a); - getNonAffNeighbour(currMB, ioff , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_b); - getNonAffNeighbour(currMB, ioff -1 , joff -1 , p_Vid->mb_size[IS_LUMA], &pix_d); + getNonAffNeighbour(currMB, ioff - 1, joff, p_Vid->mb_size[IS_LUMA], &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, p_Vid->mb_size[IS_LUMA], &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff - 1, p_Vid->mb_size[IS_LUMA], + &pix_d); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; - block_available_up_left = pix_d.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_4x4_Horizontal_Down prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); - else - { + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_4x4_Horizontal_Down prediction mode not allowed at " + "mb %d\n", + (int)currSlice->current_mb_nr); + else { imgpel PredPixel[10]; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; - imgpel **mb_pred = currSlice->mb_pred[pl]; + imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; + imgpel **mb_pred = currSlice->mb_pred[pl]; imgpel **img_pred = &imgY[pix_a.pos_y]; int pix_x = pix_a.pos_x; @@ -734,54 +735,53 @@ static int intra4x4_hor_down_pred(Macroblock *currMB, //!< current macroblock imgpel p_i = *(*(img_pred++) + pix_x); imgpel p_j = *(*(img_pred++) + pix_x); imgpel p_k = *(*(img_pred++) + pix_x); - imgpel p_l = *(*(img_pred ) + pix_x); + imgpel p_l = *(*(img_pred) + pix_x); imgpel p_x = imgY[pix_d.pos_y][pix_d.pos_x]; - PredPixel[0] = (imgpel) ((p_k + p_l + 1) >> 1); - PredPixel[1] = (imgpel) ((p_j + 2*p_k + p_l + 2) >> 2); - PredPixel[2] = (imgpel) ((p_j + p_k + 1) >> 1); - PredPixel[3] = (imgpel) ((p_i + 2*p_j + p_k + 2) >> 2); - PredPixel[4] = (imgpel) ((p_i + p_j + 1) >> 1); - PredPixel[5] = (imgpel) ((p_x + 2*p_i + p_j + 2) >> 2); - PredPixel[6] = (imgpel) ((p_x + p_i + 1) >> 1); - PredPixel[7] = (imgpel) ((p_i + 2*p_x + p_a + 2) >> 2); - PredPixel[8] = (imgpel) ((p_x + 2*p_a + p_b + 2) >> 2); - PredPixel[9] = (imgpel) ((p_a + 2*p_b + p_c + 2) >> 2); + PredPixel[0] = (imgpel)((p_k + p_l + 1) >> 1); + PredPixel[1] = (imgpel)((p_j + 2 * p_k + p_l + 2) >> 2); + PredPixel[2] = (imgpel)((p_j + p_k + 1) >> 1); + PredPixel[3] = (imgpel)((p_i + 2 * p_j + p_k + 2) >> 2); + PredPixel[4] = (imgpel)((p_i + p_j + 1) >> 1); + PredPixel[5] = (imgpel)((p_x + 2 * p_i + p_j + 2) >> 2); + PredPixel[6] = (imgpel)((p_x + p_i + 1) >> 1); + PredPixel[7] = (imgpel)((p_i + 2 * p_x + p_a + 2) >> 2); + PredPixel[8] = (imgpel)((p_x + 2 * p_a + p_b + 2) >> 2); + PredPixel[9] = (imgpel)((p_a + 2 * p_b + p_c + 2) >> 2); memcpy(&mb_pred[joff++][ioff], &PredPixel[6], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[4], 4 * sizeof(imgpel)); memcpy(&mb_pred[joff++][ioff], &PredPixel[2], 4 * sizeof(imgpel)); - memcpy(&mb_pred[joff ][ioff], &PredPixel[0], 4 * sizeof(imgpel)); + memcpy(&mb_pred[joff][ioff], &PredPixel[0], 4 * sizeof(imgpel)); } return DECODING_OK; } - /*! *********************************************************************** * \brief - * makes and returns 4x4 intra prediction blocks + * makes and returns 4x4 intra prediction blocks * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * SEARCH_SYNC search next sync element as errors while decoding occured *********************************************************************** */ -int intra4x4_pred_normal(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff, //!< pixel offset Y within MB - int img_block_x, //!< location of block X, multiples of 4 - int img_block_y) //!< location of block Y, multiples of 4 +int intra4x4_pred_normal( + Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff, //!< pixel offset Y within MB + int img_block_x, //!< location of block X, multiples of 4 + int img_block_y) //!< location of block Y, multiples of 4 { VideoParameters *p_Vid = currMB->p_Vid; byte predmode = p_Vid->ipredmode[img_block_y][img_block_x]; - currMB->ipmode_DPCM = predmode; //For residual DPCM + currMB->ipmode_DPCM = predmode; // For residual DPCM - switch (predmode) - { + switch (predmode) { case DC_PRED: return (intra4x4_dc_pred(currMB, pl, ioff, joff)); break; @@ -806,10 +806,10 @@ int intra4x4_pred_normal(Macroblock *currMB, //!< current macroblock case HOR_UP_PRED: return (intra4x4_hor_up_pred(currMB, pl, ioff, joff)); break; - case HOR_DOWN_PRED: + case HOR_DOWN_PRED: return (intra4x4_hor_down_pred(currMB, pl, ioff, joff)); default: - printf("Error: illegal intra_4x4 prediction mode: %d\n", (int) predmode); + printf("Error: illegal intra_4x4 prediction mode: %d\n", (int)predmode); return SEARCH_SYNC; break; } diff --git a/src/common/ldecod_src/intra8x8_pred.c b/src/common/ldecod_src/intra8x8_pred.c index 99db85c..bbbfd64 100644 --- a/src/common/ldecod_src/intra8x8_pred.c +++ b/src/common/ldecod_src/intra8x8_pred.c @@ -6,7 +6,7 @@ * Functions for intra 8x8 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Yuri Vatis * - Jan Muenster @@ -14,14 +14,15 @@ * ************************************************************************************* */ -#include "global.h" #include "intra8x8_pred.h" -#include "mb_access.h" +#include "global.h" #include "image.h" +#include "mb_access.h" - -extern int intrapred8x8_normal(Macroblock *currMB, ColorPlane pl, int ioff, int joff); -extern int intrapred8x8_mbaff(Macroblock *currMB, ColorPlane pl, int ioff, int joff); +extern int intrapred8x8_normal(Macroblock *currMB, ColorPlane pl, int ioff, + int joff); +extern int intrapred8x8_mbaff(Macroblock *currMB, ColorPlane pl, int ioff, + int joff); /*! ************************************************************************ @@ -37,27 +38,22 @@ extern int intrapred8x8_mbaff(Macroblock *currMB, ColorPlane pl, int ioff, int j * ************************************************************************ */ -int intrapred8x8(Macroblock *currMB, //!< Current Macroblock - ColorPlane pl, //!< Current color plane - int ioff, //!< ioff - int joff) //!< joff +int intrapred8x8(Macroblock *currMB, //!< Current Macroblock + ColorPlane pl, //!< Current color plane + int ioff, //!< ioff + int joff) //!< joff -{ - //VideoParameters *p_Vid = currMB->p_Vid; +{ + // VideoParameters *p_Vid = currMB->p_Vid; int block_x = (currMB->block_x) + (ioff >> 2); int block_y = (currMB->block_y) + (joff >> 2); byte predmode = currMB->p_Slice->ipredmode[block_y][block_x]; - currMB->ipmode_DPCM = predmode; //For residual DPCM + currMB->ipmode_DPCM = predmode; // For residual DPCM - if (currMB->p_Slice->mb_aff_frame_flag) - { - return intrapred8x8_mbaff(currMB, pl, ioff, joff); - } - else - { + if (currMB->p_Slice->mb_aff_frame_flag) { + return intrapred8x8_mbaff(currMB, pl, ioff, joff); + } else { return intrapred8x8_normal(currMB, pl, ioff, joff); } } - - diff --git a/src/common/ldecod_src/intra8x8_pred_mbaff.c b/src/common/ldecod_src/intra8x8_pred_mbaff.c index b58d970..a749da7 100644 --- a/src/common/ldecod_src/intra8x8_pred_mbaff.c +++ b/src/common/ldecod_src/intra8x8_pred_mbaff.c @@ -6,7 +6,7 @@ * Functions for intra 8x8 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Yuri Vatis * - Jan Muenster @@ -15,9 +15,9 @@ ************************************************************************************* */ #include "global.h" +#include "image.h" #include "intra8x8_pred.h" #include "mb_access.h" -#include "image.h" // Notation for comments regarding prediction and predictors. // The pels of the 8x8 block are labeled a..p. The predictor pels above @@ -33,7 +33,6 @@ // W a7 b7 c7 d7 e7 f7 g7 h7 // X a8 b8 c8 d8 e8 f8 g8 h8 - // Predictor array index definitions #define P_Z (PredPel[0]) #define P_A (PredPel[1]) @@ -67,57 +66,52 @@ * Prefiltering for Intra8x8 prediction ************************************************************************************* */ -static inline void LowPassForIntra8x8Pred(imgpel *PredPel, int block_up_left, int block_up, int block_left) -{ +static inline void LowPassForIntra8x8Pred(imgpel *PredPel, int block_up_left, + int block_up, int block_left) { int i; imgpel LoopArray[25]; memcpy(&LoopArray[0], &PredPel[0], 25 * sizeof(imgpel)); - if(block_up_left) - { - if(block_up && block_left) - { - LoopArray[0] = (imgpel) ((P_Q + (P_Z<<1) + P_A + 2)>>2); - } - else - { - if(block_up) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_A + 2)>>2); + if (block_up_left) { + if (block_up && block_left) { + LoopArray[0] = (imgpel)((P_Q + (P_Z << 1) + P_A + 2) >> 2); + } else { + if (block_up) + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_A + 2) >> 2); else if (block_left) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_Q + 2)>>2); + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_Q + 2) >> 2); } } - - if(block_up) - { - if(block_up_left) - { - LoopArray[1] = (imgpel) ((PredPel[0] + (PredPel[1]<<1) + PredPel[2] + 2)>>2); - } - else - LoopArray[1] = (imgpel) ((PredPel[1] + (PredPel[1]<<1) + PredPel[2] + 2)>>2); + if (block_up) { + if (block_up_left) { + LoopArray[1] = + (imgpel)((PredPel[0] + (PredPel[1] << 1) + PredPel[2] + 2) >> 2); + } else + LoopArray[1] = + (imgpel)((PredPel[1] + (PredPel[1] << 1) + PredPel[2] + 2) >> 2); - for(i = 2; i <16; i++) - { - LoopArray[i] = (imgpel) ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2); + for (i = 2; i < 16; i++) { + LoopArray[i] = + (imgpel)((PredPel[i - 1] + (PredPel[i] << 1) + PredPel[i + 1] + 2) >> + 2); } - LoopArray[16] = (imgpel) ((P_P + (P_P<<1) + P_O + 2)>>2); + LoopArray[16] = (imgpel)((P_P + (P_P << 1) + P_O + 2) >> 2); } - if(block_left) - { - if(block_up_left) - LoopArray[17] = (imgpel) ((P_Z + (P_Q<<1) + P_R + 2)>>2); + if (block_left) { + if (block_up_left) + LoopArray[17] = (imgpel)((P_Z + (P_Q << 1) + P_R + 2) >> 2); else - LoopArray[17] = (imgpel) ((P_Q + (P_Q<<1) + P_R + 2)>>2); + LoopArray[17] = (imgpel)((P_Q + (P_Q << 1) + P_R + 2) >> 2); - for(i = 18; i <24; i++) - { - LoopArray[i] = (imgpel) ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2); + for (i = 18; i < 24; i++) { + LoopArray[i] = + (imgpel)((PredPel[i - 1] + (PredPel[i] << 1) + PredPel[i + 1] + 2) >> + 2); } - LoopArray[24] = (imgpel) ((P_W + (P_X<<1) + P_X + 2) >> 2); + LoopArray[24] = (imgpel)((P_W + (P_X << 1) + P_X + 2) >> 2); } memcpy(&PredPel[0], &LoopArray[0], 25 * sizeof(imgpel)); @@ -129,46 +123,40 @@ static inline void LowPassForIntra8x8Pred(imgpel *PredPel, int block_up_left, in * Prefiltering for Intra8x8 prediction (Horizontal) ************************************************************************************* */ -static inline void LowPassForIntra8x8PredHor(imgpel *PredPel, int block_up_left, int block_up, int block_left) -{ +static inline void LowPassForIntra8x8PredHor(imgpel *PredPel, int block_up_left, + int block_up, int block_left) { int i; imgpel LoopArray[25]; memcpy(&LoopArray[0], &PredPel[0], 25 * sizeof(imgpel)); - if(block_up_left) - { - if(block_up && block_left) - { - LoopArray[0] = (imgpel) ((P_Q + (P_Z<<1) + P_A + 2)>>2); - } - else - { - if(block_up) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_A + 2)>>2); + if (block_up_left) { + if (block_up && block_left) { + LoopArray[0] = (imgpel)((P_Q + (P_Z << 1) + P_A + 2) >> 2); + } else { + if (block_up) + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_A + 2) >> 2); else if (block_left) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_Q + 2)>>2); + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_Q + 2) >> 2); } } - - if(block_up) - { - if(block_up_left) - { - LoopArray[1] = (imgpel) ((PredPel[0] + (PredPel[1]<<1) + PredPel[2] + 2)>>2); - } - else - LoopArray[1] = (imgpel) ((PredPel[1] + (PredPel[1]<<1) + PredPel[2] + 2)>>2); + if (block_up) { + if (block_up_left) { + LoopArray[1] = + (imgpel)((PredPel[0] + (PredPel[1] << 1) + PredPel[2] + 2) >> 2); + } else + LoopArray[1] = + (imgpel)((PredPel[1] + (PredPel[1] << 1) + PredPel[2] + 2) >> 2); - for(i = 2; i <16; i++) - { - LoopArray[i] = (imgpel) ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2); + for (i = 2; i < 16; i++) { + LoopArray[i] = + (imgpel)((PredPel[i - 1] + (PredPel[i] << 1) + PredPel[i + 1] + 2) >> + 2); } - LoopArray[16] = (imgpel) ((P_P + (P_P<<1) + P_O + 2)>>2); + LoopArray[16] = (imgpel)((P_P + (P_P << 1) + P_O + 2) >> 2); } - memcpy(&PredPel[0], &LoopArray[0], 17 * sizeof(imgpel)); } @@ -178,71 +166,70 @@ static inline void LowPassForIntra8x8PredHor(imgpel *PredPel, int block_up_left, * Prefiltering for Intra8x8 prediction (Vertical) ************************************************************************************* */ -static inline void LowPassForIntra8x8PredVer(imgpel *PredPel, int block_up_left, int block_up, int block_left) -{ - // These functions need some cleanup and can be further optimized. - // For convenience, let us copy all data for now. It is obvious that the filtering makes things a bit more "complex" +static inline void LowPassForIntra8x8PredVer(imgpel *PredPel, int block_up_left, + int block_up, int block_left) { + // These functions need some cleanup and can be further optimized. + // For convenience, let us copy all data for now. It is obvious that the + // filtering makes things a bit more "complex" int i; imgpel LoopArray[25]; memcpy(&LoopArray[0], &PredPel[0], 25 * sizeof(imgpel)); - if(block_up_left) - { - if(block_up && block_left) - { - LoopArray[0] = (imgpel) ((P_Q + (P_Z<<1) + P_A + 2)>>2); - } - else - { - if(block_up) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_A + 2)>>2); + if (block_up_left) { + if (block_up && block_left) { + LoopArray[0] = (imgpel)((P_Q + (P_Z << 1) + P_A + 2) >> 2); + } else { + if (block_up) + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_A + 2) >> 2); else if (block_left) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_Q + 2)>>2); + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_Q + 2) >> 2); } } - - if(block_left) - { - if(block_up_left) - LoopArray[17] = (imgpel) ((P_Z + (P_Q<<1) + P_R + 2)>>2); - else - LoopArray[17] = (imgpel) ((P_Q + (P_Q<<1) + P_R + 2)>>2); - for(i = 18; i <24; i++) - { - LoopArray[i] = (imgpel) ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2); + if (block_left) { + if (block_up_left) + LoopArray[17] = (imgpel)((P_Z + (P_Q << 1) + P_R + 2) >> 2); + else + LoopArray[17] = (imgpel)((P_Q + (P_Q << 1) + P_R + 2) >> 2); + + for (i = 18; i < 24; i++) { + LoopArray[i] = + (imgpel)((PredPel[i - 1] + (PredPel[i] << 1) + PredPel[i + 1] + 2) >> + 2); } - LoopArray[24] = (imgpel) ((P_W + (P_X<<1) + P_X + 2) >> 2); + LoopArray[24] = (imgpel)((P_W + (P_X << 1) + P_X + 2) >> 2); } memcpy(&PredPel[0], &LoopArray[0], 25 * sizeof(imgpel)); } - /*! *********************************************************************** * \brief * makes and returns 8x8 DC prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_dc_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_dc_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { - int i,j; + int i, j; int s0 = 0; - imgpel PredPel[25]; // array of predictor pels + imgpel PredPel[25]; // array of predictor pels Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; - imgpel **imgY = (pl) ? dec_picture->imgUV[pl - 1] : dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel **imgY = (pl) ? dec_picture->imgUV[pl - 1] + : dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a[8]; PixelPos pix_b, pix_c, pix_d; @@ -251,41 +238,39 @@ static inline int intra8x8_dc_pred_mbaff(Macroblock *currMB, //!< current mac int block_available_left; int block_available_up_left; int block_available_up_right; - imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - for (i=0;i<8;i++) - { + for (i = 0; i < 8; i++) { getAffNeighbour(currMB, ioff - 1, joff + i, mb_size, &pix_a[i]); } - getAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<8;i++) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 8; i++) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -295,14 +280,12 @@ static inline int intra8x8_dc_pred_mbaff(Macroblock *currMB, //!< current mac P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -313,14 +296,11 @@ static inline int intra8x8_dc_pred_mbaff(Macroblock *currMB, //!< current mac P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { P_Q = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; P_R = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; P_S = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; @@ -329,47 +309,40 @@ static inline int intra8x8_dc_pred_mbaff(Macroblock *currMB, //!< current mac P_V = imgY[pix_a[5].pos_y][pix_a[5].pos_x]; P_W = imgY[pix_a[6].pos_y][pix_a[6].pos_x]; P_X = imgY[pix_a[7].pos_y][pix_a[7].pos_x]; - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); - - if (block_available_up && block_available_left) - { + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); + + if (block_available_up && block_available_left) { // no edge - s0 = (P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H + P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X + 8) >> 4; - } - else if (!block_available_up && block_available_left) - { + s0 = (P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H + P_Q + P_R + P_S + + P_T + P_U + P_V + P_W + P_X + 8) >> + 4; + } else if (!block_available_up && block_available_left) { // upper edge s0 = (P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X + 4) >> 3; - } - else if (block_available_up && !block_available_left) - { + } else if (block_available_up && !block_available_left) { // left edge s0 = (P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H + 4) >> 3; - } - else //if (!block_available_up && !block_available_left) + } else // if (!block_available_up && !block_available_left) { // top left corner, nothing to predict from s0 = p_Vid->dc_pred_value_comp[pl]; } - for(j = joff; j < joff + BLOCK_SIZE_8x8; j++) - for(i = ioff; i < ioff + BLOCK_SIZE_8x8; i++) - mpr[j][i] = (imgpel) s0; + for (j = joff; j < joff + BLOCK_SIZE_8x8; j++) + for (i = ioff; i < ioff + BLOCK_SIZE_8x8; i++) + mpr[j][i] = (imgpel)s0; return DECODING_OK; } @@ -380,21 +353,25 @@ static inline int intra8x8_dc_pred_mbaff(Macroblock *currMB, //!< current mac * makes and returns 8x8 vertical prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_vert_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_vert_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int i; - imgpel PredPel[25]; // array of predictor pels - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel PredPel[25]; // array of predictor pels + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a[8]; PixelPos pix_b, pix_c, pix_d; @@ -404,88 +381,80 @@ static inline int intra8x8_vert_pred_mbaff(Macroblock *currMB, //!< current m int block_available_up_left; int block_available_up_right; - imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - for (i=0;i<8;i++) - { + for (i = 0; i < 8; i++) { getAffNeighbour(currMB, ioff - 1, joff + i, mb_size, &pix_a[i]); } - getAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<8;i++) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 8; i++) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_up) - printf ("warning: Intra_8x8_Vertical prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_8x8_Vertical prediction mode not allowed at mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; - P_A = *(pred_pels ++); - P_B = *(pred_pels ++); - P_C = *(pred_pels ++); - P_D = *(pred_pels ++); - P_E = *(pred_pels ++); - P_F = *(pred_pels ++); - P_G = *(pred_pels ++); + P_A = *(pred_pels++); + P_B = *(pred_pels++); + P_C = *(pred_pels++); + P_D = *(pred_pels++); + P_E = *(pred_pels++); + P_F = *(pred_pels++); + P_G = *(pred_pels++); P_H = *pred_pels; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; - P_I = *(pred_pels ++); - P_J = *(pred_pels ++); - P_K = *(pred_pels ++); - P_L = *(pred_pels ++); - P_M = *(pred_pels ++); - P_N = *(pred_pels ++); - P_O = *(pred_pels ++); + P_I = *(pred_pels++); + P_J = *(pred_pels++); + P_K = *(pred_pels++); + P_L = *(pred_pels++); + P_M = *(pred_pels++); + P_N = *(pred_pels++); + P_O = *(pred_pels++); P_P = *pred_pels; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8PredHor(&(P_Z), block_available_up_left, block_available_up, block_available_left); - - for (i=joff; i < joff + BLOCK_SIZE_8x8; i++) - { + LowPassForIntra8x8PredHor(&(P_Z), block_available_up_left, block_available_up, + block_available_left); + + for (i = joff; i < joff + BLOCK_SIZE_8x8; i++) { memcpy(&mpr[i][ioff], (&P_A), BLOCK_SIZE_8x8 * sizeof(imgpel)); } @@ -498,22 +467,25 @@ static inline int intra8x8_vert_pred_mbaff(Macroblock *currMB, //!< current m * makes and returns 8x8 horizontal prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_hor_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_hor_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - - int i,j; - imgpel PredPel[25]; // array of predictor pels - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + int i, j; + imgpel PredPel[25]; // array of predictor pels + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a[8]; PixelPos pix_b, pix_c, pix_d; @@ -524,46 +496,47 @@ static inline int intra8x8_hor_pred_mbaff(Macroblock *currMB, //!< current ma int block_available_up_right; #if (IMGTYPE != 0) - int ipos0 = ioff , ipos1 = ioff + 1, ipos2 = ioff + 2, ipos3 = ioff + 3; + int ipos0 = ioff, ipos1 = ioff + 1, ipos2 = ioff + 2, ipos3 = ioff + 3; int ipos4 = ioff + 4, ipos5 = ioff + 5, ipos6 = ioff + 6, ipos7 = ioff + 7; #endif - int jpos; + int jpos; imgpel **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - for (i=0;i<8;i++) - { + for (i = 0; i < 8; i++) { getAffNeighbour(currMB, ioff - 1, joff + i, mb_size, &pix_a[i]); } - getAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<8;i++) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 8; i++) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_left) - printf ("warning: Intra_8x8_Horizontal prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf( + "warning: Intra_8x8_Horizontal prediction mode not allowed at mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_left) - { + if (block_available_left) { P_Q = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; P_R = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; P_S = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; @@ -572,66 +545,60 @@ static inline int intra8x8_hor_pred_mbaff(Macroblock *currMB, //!< current ma P_V = imgY[pix_a[5].pos_y][pix_a[5].pos_x]; P_W = imgY[pix_a[6].pos_y][pix_a[6].pos_x]; P_X = imgY[pix_a[7].pos_y][pix_a[7].pos_x]; - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8PredVer(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8PredVer(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - for (j=0; j < BLOCK_SIZE_8x8; j++) - { + for (j = 0; j < BLOCK_SIZE_8x8; j++) { jpos = j + joff; #if (IMGTYPE == 0) - memset(&mpr[jpos][ioff], (imgpel) (&P_Q)[j], 8 * sizeof(imgpel)); + memset(&mpr[jpos][ioff], (imgpel)(&P_Q)[j], 8 * sizeof(imgpel)); #else - mpr[jpos][ipos0] = - mpr[jpos][ipos1] = - mpr[jpos][ipos2] = - mpr[jpos][ipos3] = - mpr[jpos][ipos4] = - mpr[jpos][ipos5] = - mpr[jpos][ipos6] = - mpr[jpos][ipos7] = (imgpel) (&P_Q)[j]; + mpr[jpos][ipos0] = mpr[jpos][ipos1] = mpr[jpos][ipos2] = mpr[jpos][ipos3] = + mpr[jpos][ipos4] = mpr[jpos][ipos5] = mpr[jpos][ipos6] = + mpr[jpos][ipos7] = (imgpel)(&P_Q)[j]; #endif } - + return DECODING_OK; } - /*! +/*! *********************************************************************** * \brief * makes and returns 8x8 diagonal down right prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_diag_down_right_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_diag_down_right_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - int i; - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[16]; // array of final prediction values - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[16]; // array of final prediction values + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a[8]; PixelPos pix_b, pix_c, pix_d; @@ -644,39 +611,41 @@ static inline int intra8x8_diag_down_right_pred_mbaff(Macroblock *currMB, //! imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - for (i=0;i<8;i++) - { + for (i = 0; i < 8; i++) { getAffNeighbour(currMB, ioff - 1, joff + i, mb_size, &pix_a[i]); } - getAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<8;i++) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 8; i++) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_8x8_Diagonal_Down_Right prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_8x8_Diagonal_Down_Right prediction mode not allowed " + "at mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -686,14 +655,12 @@ static inline int intra8x8_diag_down_right_pred_mbaff(Macroblock *currMB, //! P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -704,14 +671,11 @@ static inline int intra8x8_diag_down_right_pred_mbaff(Macroblock *currMB, //! P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { P_Q = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; P_R = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; P_S = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; @@ -720,39 +684,36 @@ static inline int intra8x8_diag_down_right_pred_mbaff(Macroblock *currMB, //! P_V = imgY[pix_a[5].pos_y][pix_a[5].pos_x]; P_W = imgY[pix_a[6].pos_y][pix_a[6].pos_x]; P_X = imgY[pix_a[7].pos_y][pix_a[7].pos_x]; - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); // Mode DIAG_DOWN_RIGHT_PRED - PredArray[ 0] = (imgpel) ((P_X + P_V + 2*(P_W) + 2) >> 2); - PredArray[ 1] = (imgpel) ((P_W + P_U + 2*(P_V) + 2) >> 2); - PredArray[ 2] = (imgpel) ((P_V + P_T + 2*(P_U) + 2) >> 2); - PredArray[ 3] = (imgpel) ((P_U + P_S + 2*(P_T) + 2) >> 2); - PredArray[ 4] = (imgpel) ((P_T + P_R + 2*(P_S) + 2) >> 2); - PredArray[ 5] = (imgpel) ((P_S + P_Q + 2*(P_R) + 2) >> 2); - PredArray[ 6] = (imgpel) ((P_R + P_Z + 2*(P_Q) + 2) >> 2); - PredArray[ 7] = (imgpel) ((P_Q + P_A + 2*(P_Z) + 2) >> 2); - PredArray[ 8] = (imgpel) ((P_Z + P_B + 2*(P_A) + 2) >> 2); - PredArray[ 9] = (imgpel) ((P_A + P_C + 2*(P_B) + 2) >> 2); - PredArray[10] = (imgpel) ((P_B + P_D + 2*(P_C) + 2) >> 2); - PredArray[11] = (imgpel) ((P_C + P_E + 2*(P_D) + 2) >> 2); - PredArray[12] = (imgpel) ((P_D + P_F + 2*(P_E) + 2) >> 2); - PredArray[13] = (imgpel) ((P_E + P_G + 2*(P_F) + 2) >> 2); - PredArray[14] = (imgpel) ((P_F + P_H + 2*(P_G) + 2) >> 2); + PredArray[0] = (imgpel)((P_X + P_V + 2 * (P_W) + 2) >> 2); + PredArray[1] = (imgpel)((P_W + P_U + 2 * (P_V) + 2) >> 2); + PredArray[2] = (imgpel)((P_V + P_T + 2 * (P_U) + 2) >> 2); + PredArray[3] = (imgpel)((P_U + P_S + 2 * (P_T) + 2) >> 2); + PredArray[4] = (imgpel)((P_T + P_R + 2 * (P_S) + 2) >> 2); + PredArray[5] = (imgpel)((P_S + P_Q + 2 * (P_R) + 2) >> 2); + PredArray[6] = (imgpel)((P_R + P_Z + 2 * (P_Q) + 2) >> 2); + PredArray[7] = (imgpel)((P_Q + P_A + 2 * (P_Z) + 2) >> 2); + PredArray[8] = (imgpel)((P_Z + P_B + 2 * (P_A) + 2) >> 2); + PredArray[9] = (imgpel)((P_A + P_C + 2 * (P_B) + 2) >> 2); + PredArray[10] = (imgpel)((P_B + P_D + 2 * (P_C) + 2) >> 2); + PredArray[11] = (imgpel)((P_C + P_E + 2 * (P_D) + 2) >> 2); + PredArray[12] = (imgpel)((P_D + P_F + 2 * (P_E) + 2) >> 2); + PredArray[13] = (imgpel)((P_E + P_G + 2 * (P_F) + 2) >> 2); + PredArray[14] = (imgpel)((P_F + P_H + 2 * (P_G) + 2) >> 2); memcpy(&mpr[joff++][ioff], &PredArray[7], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[6], 8 * sizeof(imgpel)); @@ -761,8 +722,8 @@ static inline int intra8x8_diag_down_right_pred_mbaff(Macroblock *currMB, //! memcpy(&mpr[joff++][ioff], &PredArray[3], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[2], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[1], 8 * sizeof(imgpel)); - memcpy(&mpr[joff ][ioff], &PredArray[0], 8 * sizeof(imgpel)); - + memcpy(&mpr[joff][ioff], &PredArray[0], 8 * sizeof(imgpel)); + return DECODING_OK; } @@ -772,23 +733,27 @@ static inline int intra8x8_diag_down_right_pred_mbaff(Macroblock *currMB, //! * makes and returns 8x8 diagonal down left prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_diag_down_left_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_diag_down_left_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int i; - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[16]; // array of final prediction values + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[16]; // array of final prediction values imgpel *Pred = &PredArray[0]; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a[8]; PixelPos pix_b, pix_c, pix_d; @@ -801,39 +766,40 @@ static inline int intra8x8_diag_down_left_pred_mbaff(Macroblock *currMB, //!< imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - for (i=0;i<8;i++) - { + for (i = 0; i < 8; i++) { getAffNeighbour(currMB, ioff - 1, joff + i, mb_size, &pix_a[i]); } - getAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<8;i++) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 8; i++) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_up) - printf ("warning: Intra_8x8_Diagonal_Down_Left prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_8x8_Diagonal_Down_Left prediction mode not allowed " + "at mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -843,14 +809,12 @@ static inline int intra8x8_diag_down_left_pred_mbaff(Macroblock *currMB, //!< P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -861,14 +825,11 @@ static inline int intra8x8_diag_down_left_pred_mbaff(Macroblock *currMB, //!< P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { P_Q = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; P_R = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; P_S = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; @@ -877,41 +838,38 @@ static inline int intra8x8_diag_down_left_pred_mbaff(Macroblock *currMB, //!< P_V = imgY[pix_a[5].pos_y][pix_a[5].pos_x]; P_W = imgY[pix_a[6].pos_y][pix_a[6].pos_x]; P_X = imgY[pix_a[7].pos_y][pix_a[7].pos_x]; - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); // Mode DIAG_DOWN_LEFT_PRED - *Pred++ = (imgpel) ((P_A + P_C + 2*(P_B) + 2) >> 2); - *Pred++ = (imgpel) ((P_B + P_D + 2*(P_C) + 2) >> 2); - *Pred++ = (imgpel) ((P_C + P_E + 2*(P_D) + 2) >> 2); - *Pred++ = (imgpel) ((P_D + P_F + 2*(P_E) + 2) >> 2); - *Pred++ = (imgpel) ((P_E + P_G + 2*(P_F) + 2) >> 2); - *Pred++ = (imgpel) ((P_F + P_H + 2*(P_G) + 2) >> 2); - *Pred++ = (imgpel) ((P_G + P_I + 2*(P_H) + 2) >> 2); - *Pred++ = (imgpel) ((P_H + P_J + 2*(P_I) + 2) >> 2); - *Pred++ = (imgpel) ((P_I + P_K + 2*(P_J) + 2) >> 2); - *Pred++ = (imgpel) ((P_J + P_L + 2*(P_K) + 2) >> 2); - *Pred++ = (imgpel) ((P_K + P_M + 2*(P_L) + 2) >> 2); - *Pred++ = (imgpel) ((P_L + P_N + 2*(P_M) + 2) >> 2); - *Pred++ = (imgpel) ((P_M + P_O + 2*(P_N) + 2) >> 2); - *Pred++ = (imgpel) ((P_N + P_P + 2*(P_O) + 2) >> 2); - *Pred = (imgpel) ((P_O + 3*(P_P) + 2) >> 2); + *Pred++ = (imgpel)((P_A + P_C + 2 * (P_B) + 2) >> 2); + *Pred++ = (imgpel)((P_B + P_D + 2 * (P_C) + 2) >> 2); + *Pred++ = (imgpel)((P_C + P_E + 2 * (P_D) + 2) >> 2); + *Pred++ = (imgpel)((P_D + P_F + 2 * (P_E) + 2) >> 2); + *Pred++ = (imgpel)((P_E + P_G + 2 * (P_F) + 2) >> 2); + *Pred++ = (imgpel)((P_F + P_H + 2 * (P_G) + 2) >> 2); + *Pred++ = (imgpel)((P_G + P_I + 2 * (P_H) + 2) >> 2); + *Pred++ = (imgpel)((P_H + P_J + 2 * (P_I) + 2) >> 2); + *Pred++ = (imgpel)((P_I + P_K + 2 * (P_J) + 2) >> 2); + *Pred++ = (imgpel)((P_J + P_L + 2 * (P_K) + 2) >> 2); + *Pred++ = (imgpel)((P_K + P_M + 2 * (P_L) + 2) >> 2); + *Pred++ = (imgpel)((P_L + P_N + 2 * (P_M) + 2) >> 2); + *Pred++ = (imgpel)((P_M + P_O + 2 * (P_N) + 2) >> 2); + *Pred++ = (imgpel)((P_N + P_P + 2 * (P_O) + 2) >> 2); + *Pred = (imgpel)((P_O + 3 * (P_P) + 2) >> 2); - Pred = &PredArray[ 0]; + Pred = &PredArray[0]; memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); @@ -920,7 +878,7 @@ static inline int intra8x8_diag_down_left_pred_mbaff(Macroblock *currMB, //!< memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); - memcpy(&mpr[joff ][ioff], Pred , 8 * sizeof(imgpel)); + memcpy(&mpr[joff][ioff], Pred, 8 * sizeof(imgpel)); return DECODING_OK; } @@ -931,22 +889,26 @@ static inline int intra8x8_diag_down_left_pred_mbaff(Macroblock *currMB, //!< * makes and returns 8x8 vertical right prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_vert_right_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_vert_right_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int i; - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[22]; // array of final prediction values - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[22]; // array of final prediction values + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a[8]; PixelPos pix_b, pix_c, pix_d; @@ -959,39 +921,41 @@ static inline int intra8x8_vert_right_pred_mbaff(Macroblock *currMB, //!< cur imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - for (i=0;i<8;i++) - { + for (i = 0; i < 8; i++) { getAffNeighbour(currMB, ioff - 1, joff + i, mb_size, &pix_a[i]); } - getAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<8;i++) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 8; i++) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_8x8_Vertical_Right prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_8x8_Vertical_Right prediction mode not allowed at " + "mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -1001,14 +965,12 @@ static inline int intra8x8_vert_right_pred_mbaff(Macroblock *currMB, //!< cur P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -1019,14 +981,11 @@ static inline int intra8x8_vert_right_pred_mbaff(Macroblock *currMB, //!< cur P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { P_Q = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; P_R = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; P_S = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; @@ -1035,83 +994,83 @@ static inline int intra8x8_vert_right_pred_mbaff(Macroblock *currMB, //!< cur P_V = imgY[pix_a[5].pos_y][pix_a[5].pos_x]; P_W = imgY[pix_a[6].pos_y][pix_a[6].pos_x]; P_X = imgY[pix_a[7].pos_y][pix_a[7].pos_x]; - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - PredArray[ 0] = (imgpel) ((P_V + P_T + 2*P_U + 2) >> 2); - PredArray[ 1] = (imgpel) ((P_T + P_R + 2*P_S + 2) >> 2); - PredArray[ 2] = (imgpel) ((P_R + P_Z + 2*P_Q + 2) >> 2); - PredArray[ 3] = (imgpel) ((P_Z + P_A + 1) >> 1); - PredArray[ 4] = (imgpel) ((P_A + P_B + 1) >> 1); - PredArray[ 5] = (imgpel) ((P_B + P_C + 1) >> 1); - PredArray[ 6] = (imgpel) ((P_C + P_D + 1) >> 1); - PredArray[ 7] = (imgpel) ((P_D + P_E + 1) >> 1); - PredArray[ 8] = (imgpel) ((P_E + P_F + 1) >> 1); - PredArray[ 9] = (imgpel) ((P_F + P_G + 1) >> 1); - PredArray[10] = (imgpel) ((P_G + P_H + 1) >> 1); + PredArray[0] = (imgpel)((P_V + P_T + 2 * P_U + 2) >> 2); + PredArray[1] = (imgpel)((P_T + P_R + 2 * P_S + 2) >> 2); + PredArray[2] = (imgpel)((P_R + P_Z + 2 * P_Q + 2) >> 2); + PredArray[3] = (imgpel)((P_Z + P_A + 1) >> 1); + PredArray[4] = (imgpel)((P_A + P_B + 1) >> 1); + PredArray[5] = (imgpel)((P_B + P_C + 1) >> 1); + PredArray[6] = (imgpel)((P_C + P_D + 1) >> 1); + PredArray[7] = (imgpel)((P_D + P_E + 1) >> 1); + PredArray[8] = (imgpel)((P_E + P_F + 1) >> 1); + PredArray[9] = (imgpel)((P_F + P_G + 1) >> 1); + PredArray[10] = (imgpel)((P_G + P_H + 1) >> 1); - PredArray[11] = (imgpel) ((P_W + P_U + 2*P_V + 2) >> 2); - PredArray[12] = (imgpel) ((P_U + P_S + 2*P_T + 2) >> 2); - PredArray[13] = (imgpel) ((P_S + P_Q + 2*P_R + 2) >> 2); - PredArray[14] = (imgpel) ((P_Q + P_A + 2*P_Z + 2) >> 2); - PredArray[15] = (imgpel) ((P_Z + P_B + 2*P_A + 2) >> 2); - PredArray[16] = (imgpel) ((P_A + P_C + 2*P_B + 2) >> 2); - PredArray[17] = (imgpel) ((P_B + P_D + 2*P_C + 2) >> 2); - PredArray[18] = (imgpel) ((P_C + P_E + 2*P_D + 2) >> 2); - PredArray[19] = (imgpel) ((P_D + P_F + 2*P_E + 2) >> 2); - PredArray[20] = (imgpel) ((P_E + P_G + 2*P_F + 2) >> 2); - PredArray[21] = (imgpel) ((P_F + P_H + 2*P_G + 2) >> 2); + PredArray[11] = (imgpel)((P_W + P_U + 2 * P_V + 2) >> 2); + PredArray[12] = (imgpel)((P_U + P_S + 2 * P_T + 2) >> 2); + PredArray[13] = (imgpel)((P_S + P_Q + 2 * P_R + 2) >> 2); + PredArray[14] = (imgpel)((P_Q + P_A + 2 * P_Z + 2) >> 2); + PredArray[15] = (imgpel)((P_Z + P_B + 2 * P_A + 2) >> 2); + PredArray[16] = (imgpel)((P_A + P_C + 2 * P_B + 2) >> 2); + PredArray[17] = (imgpel)((P_B + P_D + 2 * P_C + 2) >> 2); + PredArray[18] = (imgpel)((P_C + P_E + 2 * P_D + 2) >> 2); + PredArray[19] = (imgpel)((P_D + P_F + 2 * P_E + 2) >> 2); + PredArray[20] = (imgpel)((P_E + P_G + 2 * P_F + 2) >> 2); + PredArray[21] = (imgpel)((P_F + P_H + 2 * P_G + 2) >> 2); - memcpy(&mpr[joff++][ioff], &PredArray[ 3], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[3], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[14], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 2], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[2], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[13], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 1], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[1], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[12], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 0], 8 * sizeof(imgpel)); - memcpy(&mpr[joff ][ioff], &PredArray[11], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[0], 8 * sizeof(imgpel)); + memcpy(&mpr[joff][ioff], &PredArray[11], 8 * sizeof(imgpel)); return DECODING_OK; } - /*! *********************************************************************** * \brief * makes and returns 8x8 vertical left prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_vert_left_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_vert_left_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int i; - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[22]; // array of final prediction values + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[22]; // array of final prediction values imgpel *pred_pel = &PredArray[0]; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a[8]; PixelPos pix_b, pix_c, pix_d; @@ -1124,39 +1083,40 @@ static inline int intra8x8_vert_left_pred_mbaff(Macroblock *currMB, //!< curr imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - for (i=0;i<8;i++) - { + for (i = 0; i < 8; i++) { getAffNeighbour(currMB, ioff - 1, joff + i, mb_size, &pix_a[i]); } - getAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<8;i++) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 8; i++) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_up) - printf ("warning: Intra_4x4_Vertical_Left prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_4x4_Vertical_Left prediction mode not allowed at mb " + "%d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -1166,14 +1126,12 @@ static inline int intra8x8_vert_left_pred_mbaff(Macroblock *currMB, //!< curr P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -1184,14 +1142,11 @@ static inline int intra8x8_vert_left_pred_mbaff(Macroblock *currMB, //!< curr P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { P_Q = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; P_R = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; P_S = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; @@ -1200,54 +1155,51 @@ static inline int intra8x8_vert_left_pred_mbaff(Macroblock *currMB, //!< curr P_V = imgY[pix_a[5].pos_y][pix_a[5].pos_x]; P_W = imgY[pix_a[6].pos_y][pix_a[6].pos_x]; P_X = imgY[pix_a[7].pos_y][pix_a[7].pos_x]; - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - *pred_pel++ = (imgpel) ((P_A + P_B + 1) >> 1); - *pred_pel++ = (imgpel) ((P_B + P_C + 1) >> 1); - *pred_pel++ = (imgpel) ((P_C + P_D + 1) >> 1); - *pred_pel++ = (imgpel) ((P_D + P_E + 1) >> 1); - *pred_pel++ = (imgpel) ((P_E + P_F + 1) >> 1); - *pred_pel++ = (imgpel) ((P_F + P_G + 1) >> 1); - *pred_pel++ = (imgpel) ((P_G + P_H + 1) >> 1); - *pred_pel++ = (imgpel) ((P_H + P_I + 1) >> 1); - *pred_pel++ = (imgpel) ((P_I + P_J + 1) >> 1); - *pred_pel++ = (imgpel) ((P_J + P_K + 1) >> 1); - *pred_pel++ = (imgpel) ((P_K + P_L + 1) >> 1); - *pred_pel++ = (imgpel) ((P_A + P_C + 2*P_B + 2) >> 2); - *pred_pel++ = (imgpel) ((P_B + P_D + 2*P_C + 2) >> 2); - *pred_pel++ = (imgpel) ((P_C + P_E + 2*P_D + 2) >> 2); - *pred_pel++ = (imgpel) ((P_D + P_F + 2*P_E + 2) >> 2); - *pred_pel++ = (imgpel) ((P_E + P_G + 2*P_F + 2) >> 2); - *pred_pel++ = (imgpel) ((P_F + P_H + 2*P_G + 2) >> 2); - *pred_pel++ = (imgpel) ((P_G + P_I + 2*P_H + 2) >> 2); - *pred_pel++ = (imgpel) ((P_H + P_J + 2*P_I + 2) >> 2); - *pred_pel++ = (imgpel) ((P_I + P_K + 2*P_J + 2) >> 2); - *pred_pel++ = (imgpel) ((P_J + P_L + 2*P_K + 2) >> 2); - *pred_pel = (imgpel) ((P_K + P_M + 2*P_L + 2) >> 2); + *pred_pel++ = (imgpel)((P_A + P_B + 1) >> 1); + *pred_pel++ = (imgpel)((P_B + P_C + 1) >> 1); + *pred_pel++ = (imgpel)((P_C + P_D + 1) >> 1); + *pred_pel++ = (imgpel)((P_D + P_E + 1) >> 1); + *pred_pel++ = (imgpel)((P_E + P_F + 1) >> 1); + *pred_pel++ = (imgpel)((P_F + P_G + 1) >> 1); + *pred_pel++ = (imgpel)((P_G + P_H + 1) >> 1); + *pred_pel++ = (imgpel)((P_H + P_I + 1) >> 1); + *pred_pel++ = (imgpel)((P_I + P_J + 1) >> 1); + *pred_pel++ = (imgpel)((P_J + P_K + 1) >> 1); + *pred_pel++ = (imgpel)((P_K + P_L + 1) >> 1); + *pred_pel++ = (imgpel)((P_A + P_C + 2 * P_B + 2) >> 2); + *pred_pel++ = (imgpel)((P_B + P_D + 2 * P_C + 2) >> 2); + *pred_pel++ = (imgpel)((P_C + P_E + 2 * P_D + 2) >> 2); + *pred_pel++ = (imgpel)((P_D + P_F + 2 * P_E + 2) >> 2); + *pred_pel++ = (imgpel)((P_E + P_G + 2 * P_F + 2) >> 2); + *pred_pel++ = (imgpel)((P_F + P_H + 2 * P_G + 2) >> 2); + *pred_pel++ = (imgpel)((P_G + P_I + 2 * P_H + 2) >> 2); + *pred_pel++ = (imgpel)((P_H + P_J + 2 * P_I + 2) >> 2); + *pred_pel++ = (imgpel)((P_I + P_K + 2 * P_J + 2) >> 2); + *pred_pel++ = (imgpel)((P_J + P_L + 2 * P_K + 2) >> 2); + *pred_pel = (imgpel)((P_K + P_M + 2 * P_L + 2) >> 2); - memcpy(&mpr[joff++][ioff], &PredArray[ 0], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[0], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[11], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 1], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[1], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[12], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 2], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[2], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[13], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 3], 8 * sizeof(imgpel)); - memcpy(&mpr[joff ][ioff], &PredArray[14], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[3], 8 * sizeof(imgpel)); + memcpy(&mpr[joff][ioff], &PredArray[14], 8 * sizeof(imgpel)); return DECODING_OK; } @@ -1258,22 +1210,26 @@ static inline int intra8x8_vert_left_pred_mbaff(Macroblock *currMB, //!< curr * makes and returns 8x8 horizontal up prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_hor_up_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_hor_up_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int i; - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[16]; // array of final prediction values - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[16]; // array of final prediction values + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a[8]; PixelPos pix_b, pix_c, pix_d; @@ -1282,51 +1238,52 @@ static inline int intra8x8_hor_up_pred_mbaff(Macroblock *currMB, //!< current int block_available_left; int block_available_up_left; int block_available_up_right; - int jpos0 = joff , jpos1 = joff + 1, jpos2 = joff + 2, jpos3 = joff + 3; + int jpos0 = joff, jpos1 = joff + 1, jpos2 = joff + 2, jpos3 = joff + 3; int jpos4 = joff + 4, jpos5 = joff + 5, jpos6 = joff + 6, jpos7 = joff + 7; #if (IMGTYPE == 0) int ipos3 = ioff + 3, ipos5 = ioff + 5, ipos7 = ioff + 7; #else - int ipos0 = ioff , ipos1 = ioff + 1, ipos2 = ioff + 2, ipos3 = ioff + 3; + int ipos0 = ioff, ipos1 = ioff + 1, ipos2 = ioff + 2, ipos3 = ioff + 3; int ipos4 = ioff + 4, ipos5 = ioff + 5, ipos6 = ioff + 6, ipos7 = ioff + 7; #endif imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - for (i=0;i<8;i++) - { + for (i = 0; i < 8; i++) { getAffNeighbour(currMB, ioff - 1, joff + i, mb_size, &pix_a[i]); } - getAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<8;i++) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 8; i++) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_left) - printf ("warning: Intra_8x8_Horizontal_Up prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_8x8_Horizontal_Up prediction mode not allowed at mb " + "%d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -1336,14 +1293,12 @@ static inline int intra8x8_hor_up_pred_mbaff(Macroblock *currMB, //!< current P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -1354,14 +1309,11 @@ static inline int intra8x8_hor_up_pred_mbaff(Macroblock *currMB, //!< current P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { P_Q = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; P_R = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; P_S = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; @@ -1370,38 +1322,35 @@ static inline int intra8x8_hor_up_pred_mbaff(Macroblock *currMB, //!< current P_V = imgY[pix_a[5].pos_y][pix_a[5].pos_x]; P_W = imgY[pix_a[6].pos_y][pix_a[6].pos_x]; P_X = imgY[pix_a[7].pos_y][pix_a[7].pos_x]; - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - PredArray[ 0] = (imgpel) ((P_Q + P_R + 1) >> 1); - PredArray[ 1] = (imgpel) ((P_S + P_Q + 2*P_R + 2) >> 2); - PredArray[ 2] = (imgpel) ((P_R + P_S + 1) >> 1); - PredArray[ 3] = (imgpel) ((P_T + P_R + 2*P_S + 2) >> 2); - PredArray[ 4] = (imgpel) ((P_S + P_T + 1) >> 1); - PredArray[ 5] = (imgpel) ((P_U + P_S + 2*P_T + 2) >> 2); - PredArray[ 6] = (imgpel) ((P_T + P_U + 1) >> 1); - PredArray[ 7] = (imgpel) ((P_V + P_T + 2*P_U + 2) >> 2); - PredArray[ 8] = (imgpel) ((P_U + P_V + 1) >> 1); - PredArray[ 9] = (imgpel) ((P_W + P_U + 2*P_V + 2) >> 2); - PredArray[10] = (imgpel) ((P_V + P_W + 1) >> 1); - PredArray[11] = (imgpel) ((P_X + P_V + 2*P_W + 2) >> 2); - PredArray[12] = (imgpel) ((P_W + P_X + 1) >> 1); - PredArray[13] = (imgpel) ((P_W + 3*P_X + 2) >> 2); - PredArray[14] = (imgpel) P_X; + PredArray[0] = (imgpel)((P_Q + P_R + 1) >> 1); + PredArray[1] = (imgpel)((P_S + P_Q + 2 * P_R + 2) >> 2); + PredArray[2] = (imgpel)((P_R + P_S + 1) >> 1); + PredArray[3] = (imgpel)((P_T + P_R + 2 * P_S + 2) >> 2); + PredArray[4] = (imgpel)((P_S + P_T + 1) >> 1); + PredArray[5] = (imgpel)((P_U + P_S + 2 * P_T + 2) >> 2); + PredArray[6] = (imgpel)((P_T + P_U + 1) >> 1); + PredArray[7] = (imgpel)((P_V + P_T + 2 * P_U + 2) >> 2); + PredArray[8] = (imgpel)((P_U + P_V + 1) >> 1); + PredArray[9] = (imgpel)((P_W + P_U + 2 * P_V + 2) >> 2); + PredArray[10] = (imgpel)((P_V + P_W + 1) >> 1); + PredArray[11] = (imgpel)((P_X + P_V + 2 * P_W + 2) >> 2); + PredArray[12] = (imgpel)((P_W + P_X + 1) >> 1); + PredArray[13] = (imgpel)((P_W + 3 * P_X + 2) >> 2); + PredArray[14] = (imgpel)P_X; memcpy(&mpr[jpos0][ioff], &PredArray[0], 8 * sizeof(imgpel)); memcpy(&mpr[jpos1][ioff], &PredArray[2], 8 * sizeof(imgpel)); @@ -1415,13 +1364,15 @@ static inline int intra8x8_hor_up_pred_mbaff(Macroblock *currMB, //!< current mpr[jpos4][ipos7] = PredArray[14]; memset(&mpr[jpos5][ipos5], PredArray[14], 3 * sizeof(imgpel)); memset(&mpr[jpos6][ipos3], PredArray[14], 5 * sizeof(imgpel)); - memset(&mpr[jpos7][ioff ], PredArray[14], 8 * sizeof(imgpel)); + memset(&mpr[jpos7][ioff], PredArray[14], 8 * sizeof(imgpel)); #else mpr[jpos4][ipos7] = PredArray[14]; - mpr[jpos5][ipos5] = mpr[jpos5][ipos6] = mpr[jpos5][ipos7] = PredArray[14]; - mpr[jpos6][ipos3] = mpr[jpos6][ipos4] = mpr[jpos6][ipos5] = mpr[jpos6][ipos6] = mpr[jpos6][ipos7] = PredArray[14]; - mpr[jpos7][ipos0] = mpr[jpos7][ipos1] = mpr[jpos7][ipos2] = mpr[jpos7][ipos3] = - mpr[jpos7][ipos4] = mpr[jpos7][ipos5] = mpr[jpos7][ipos6] = mpr[jpos7][ipos7] = PredArray[14]; + mpr[jpos5][ipos5] = mpr[jpos5][ipos6] = mpr[jpos5][ipos7] = PredArray[14]; + mpr[jpos6][ipos3] = mpr[jpos6][ipos4] = mpr[jpos6][ipos5] = + mpr[jpos6][ipos6] = mpr[jpos6][ipos7] = PredArray[14]; + mpr[jpos7][ipos0] = mpr[jpos7][ipos1] = mpr[jpos7][ipos2] = + mpr[jpos7][ipos3] = mpr[jpos7][ipos4] = mpr[jpos7][ipos5] = + mpr[jpos7][ipos6] = mpr[jpos7][ipos7] = PredArray[14]; #endif return DECODING_OK; } @@ -1432,22 +1383,26 @@ static inline int intra8x8_hor_up_pred_mbaff(Macroblock *currMB, //!< current * makes and returns 8x8 horizontal down prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_hor_down_pred_mbaff(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_hor_down_pred_mbaff(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int i; - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[22]; // array of final prediction values - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[22]; // array of final prediction values + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a[8]; PixelPos pix_b, pix_c, pix_d; @@ -1456,45 +1411,47 @@ static inline int intra8x8_hor_down_pred_mbaff(Macroblock *currMB, //!< curre int block_available_left; int block_available_up_left; int block_available_up_right; - int jpos0 = joff , jpos1 = joff + 1, jpos2 = joff + 2, jpos3 = joff + 3; + int jpos0 = joff, jpos1 = joff + 1, jpos2 = joff + 2, jpos3 = joff + 3; int jpos4 = joff + 4, jpos5 = joff + 5, jpos6 = joff + 6, jpos7 = joff + 7; - + imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - for (i=0;i<8;i++) - { + for (i = 0; i < 8; i++) { getAffNeighbour(currMB, ioff - 1, joff + i, mb_size, &pix_a[i]); } - getAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - for (i=0, block_available_left=1; i<8;i++) - block_available_left &= pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a[0].available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + for (i = 0, block_available_left = 1; i < 8; i++) + block_available_left &= + pix_a[i].available ? currSlice->intra_block[pix_a[i].mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a[0].available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_8x8_Horizontal_Down prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_8x8_Horizontal_Down prediction mode not allowed at " + "mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -1504,14 +1461,12 @@ static inline int intra8x8_hor_down_pred_mbaff(Macroblock *currMB, //!< curre P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -1522,14 +1477,11 @@ static inline int intra8x8_hor_down_pred_mbaff(Macroblock *currMB, //!< curre P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { P_Q = imgY[pix_a[0].pos_y][pix_a[0].pos_x]; P_R = imgY[pix_a[1].pos_y][pix_a[1].pos_x]; P_S = imgY[pix_a[2].pos_y][pix_a[2].pos_x]; @@ -1538,54 +1490,51 @@ static inline int intra8x8_hor_down_pred_mbaff(Macroblock *currMB, //!< curre P_V = imgY[pix_a[5].pos_y][pix_a[5].pos_x]; P_W = imgY[pix_a[6].pos_y][pix_a[6].pos_x]; P_X = imgY[pix_a[7].pos_y][pix_a[7].pos_x]; - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - PredArray[ 0] = (imgpel) ((P_X + P_W + 1) >> 1); - PredArray[ 1] = (imgpel) ((P_V + P_X + 2*P_W + 2) >> 2); - PredArray[ 2] = (imgpel) ((P_W + P_V + 1) >> 1); - PredArray[ 3] = (imgpel) ((P_U + P_W + 2*P_V + 2) >> 2); - PredArray[ 4] = (imgpel) ((P_V + P_U + 1) >> 1); - PredArray[ 5] = (imgpel) ((P_T + P_V + 2*P_U + 2) >> 2); - PredArray[ 6] = (imgpel) ((P_U + P_T + 1) >> 1); - PredArray[ 7] = (imgpel) ((P_S + P_U + 2*P_T + 2) >> 2); - PredArray[ 8] = (imgpel) ((P_T + P_S + 1) >> 1); - PredArray[ 9] = (imgpel) ((P_R + P_T + 2*P_S + 2) >> 2); - PredArray[10] = (imgpel) ((P_S + P_R + 1) >> 1); - PredArray[11] = (imgpel) ((P_Q + P_S + 2*P_R + 2) >> 2); - PredArray[12] = (imgpel) ((P_R + P_Q + 1) >> 1); - PredArray[13] = (imgpel) ((P_Z + P_R + 2*P_Q + 2) >> 2); - PredArray[14] = (imgpel) ((P_Q + P_Z + 1) >> 1); - PredArray[15] = (imgpel) ((P_Q + P_A + 2*P_Z + 2) >> 2); - PredArray[16] = (imgpel) ((P_Z + P_B + 2*P_A + 2) >> 2); - PredArray[17] = (imgpel) ((P_A + P_C + 2*P_B + 2) >> 2); - PredArray[18] = (imgpel) ((P_B + P_D + 2*P_C + 2) >> 2); - PredArray[19] = (imgpel) ((P_C + P_E + 2*P_D + 2) >> 2); - PredArray[20] = (imgpel) ((P_D + P_F + 2*P_E + 2) >> 2); - PredArray[21] = (imgpel) ((P_E + P_G + 2*P_F + 2) >> 2); + PredArray[0] = (imgpel)((P_X + P_W + 1) >> 1); + PredArray[1] = (imgpel)((P_V + P_X + 2 * P_W + 2) >> 2); + PredArray[2] = (imgpel)((P_W + P_V + 1) >> 1); + PredArray[3] = (imgpel)((P_U + P_W + 2 * P_V + 2) >> 2); + PredArray[4] = (imgpel)((P_V + P_U + 1) >> 1); + PredArray[5] = (imgpel)((P_T + P_V + 2 * P_U + 2) >> 2); + PredArray[6] = (imgpel)((P_U + P_T + 1) >> 1); + PredArray[7] = (imgpel)((P_S + P_U + 2 * P_T + 2) >> 2); + PredArray[8] = (imgpel)((P_T + P_S + 1) >> 1); + PredArray[9] = (imgpel)((P_R + P_T + 2 * P_S + 2) >> 2); + PredArray[10] = (imgpel)((P_S + P_R + 1) >> 1); + PredArray[11] = (imgpel)((P_Q + P_S + 2 * P_R + 2) >> 2); + PredArray[12] = (imgpel)((P_R + P_Q + 1) >> 1); + PredArray[13] = (imgpel)((P_Z + P_R + 2 * P_Q + 2) >> 2); + PredArray[14] = (imgpel)((P_Q + P_Z + 1) >> 1); + PredArray[15] = (imgpel)((P_Q + P_A + 2 * P_Z + 2) >> 2); + PredArray[16] = (imgpel)((P_Z + P_B + 2 * P_A + 2) >> 2); + PredArray[17] = (imgpel)((P_A + P_C + 2 * P_B + 2) >> 2); + PredArray[18] = (imgpel)((P_B + P_D + 2 * P_C + 2) >> 2); + PredArray[19] = (imgpel)((P_C + P_E + 2 * P_D + 2) >> 2); + PredArray[20] = (imgpel)((P_D + P_F + 2 * P_E + 2) >> 2); + PredArray[21] = (imgpel)((P_E + P_G + 2 * P_F + 2) >> 2); memcpy(&mpr[jpos0][ioff], &PredArray[14], 8 * sizeof(imgpel)); memcpy(&mpr[jpos1][ioff], &PredArray[12], 8 * sizeof(imgpel)); memcpy(&mpr[jpos2][ioff], &PredArray[10], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos3][ioff], &PredArray[ 8], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos4][ioff], &PredArray[ 6], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos5][ioff], &PredArray[ 4], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos6][ioff], &PredArray[ 2], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos7][ioff], &PredArray[ 0], 8 * sizeof(imgpel)); + memcpy(&mpr[jpos3][ioff], &PredArray[8], 8 * sizeof(imgpel)); + memcpy(&mpr[jpos4][ioff], &PredArray[6], 8 * sizeof(imgpel)); + memcpy(&mpr[jpos5][ioff], &PredArray[4], 8 * sizeof(imgpel)); + memcpy(&mpr[jpos6][ioff], &PredArray[2], 8 * sizeof(imgpel)); + memcpy(&mpr[jpos7][ioff], &PredArray[0], 8 * sizeof(imgpel)); return DECODING_OK; } @@ -1604,20 +1553,19 @@ static inline int intra8x8_hor_down_pred_mbaff(Macroblock *currMB, //!< curre * ************************************************************************ */ -int intrapred8x8_mbaff(Macroblock *currMB, //!< Current Macroblock - ColorPlane pl, //!< Current color plane - int ioff, //!< ioff - int joff) //!< joff +int intrapred8x8_mbaff(Macroblock *currMB, //!< Current Macroblock + ColorPlane pl, //!< Current color plane + int ioff, //!< ioff + int joff) //!< joff -{ +{ int block_x = (currMB->block_x) + (ioff >> 2); int block_y = (currMB->block_y) + (joff >> 2); byte predmode = currMB->p_Slice->ipredmode[block_y][block_x]; - currMB->ipmode_DPCM = predmode; //For residual DPCM + currMB->ipmode_DPCM = predmode; // For residual DPCM - switch (predmode) - { + switch (predmode) { case DC_PRED: return (intra8x8_dc_pred_mbaff(currMB, pl, ioff, joff)); break; @@ -1642,14 +1590,11 @@ int intrapred8x8_mbaff(Macroblock *currMB, //!< Current Macroblock case HOR_UP_PRED: return (intra8x8_hor_up_pred_mbaff(currMB, pl, ioff, joff)); break; - case HOR_DOWN_PRED: + case HOR_DOWN_PRED: return (intra8x8_hor_down_pred_mbaff(currMB, pl, ioff, joff)); default: - printf("Error: illegal intra_8x8 prediction mode: %d\n", (int) predmode); + printf("Error: illegal intra_8x8 prediction mode: %d\n", (int)predmode); return SEARCH_SYNC; break; - } + } } - - - diff --git a/src/common/ldecod_src/intra8x8_pred_normal.c b/src/common/ldecod_src/intra8x8_pred_normal.c index f117b03..cf6befb 100644 --- a/src/common/ldecod_src/intra8x8_pred_normal.c +++ b/src/common/ldecod_src/intra8x8_pred_normal.c @@ -6,7 +6,7 @@ * Functions for intra 8x8 prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Yuri Vatis * - Jan Muenster @@ -15,9 +15,9 @@ ************************************************************************************* */ #include "global.h" +#include "image.h" #include "intra8x8_pred.h" #include "mb_access.h" -#include "image.h" // Notation for comments regarding prediction and predictors. // The pels of the 8x8 block are labeled a..p. The predictor pels above @@ -33,7 +33,6 @@ // W a7 b7 c7 d7 e7 f7 g7 h7 // X a8 b8 c8 d8 e8 f8 g8 h8 - // Predictor array index definitions #define P_Z (PredPel[0]) #define P_A (PredPel[1]) @@ -67,57 +66,52 @@ * Prefiltering for Intra8x8 prediction ************************************************************************************* */ -static inline void LowPassForIntra8x8Pred(imgpel *PredPel, int block_up_left, int block_up, int block_left) -{ +static inline void LowPassForIntra8x8Pred(imgpel *PredPel, int block_up_left, + int block_up, int block_left) { int i; imgpel LoopArray[25]; memcpy(&LoopArray[0], &PredPel[0], 25 * sizeof(imgpel)); - if(block_up_left) - { - if(block_up && block_left) - { - LoopArray[0] = (imgpel) ((P_Q + (P_Z<<1) + P_A + 2)>>2); - } - else - { - if(block_up) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_A + 2)>>2); + if (block_up_left) { + if (block_up && block_left) { + LoopArray[0] = (imgpel)((P_Q + (P_Z << 1) + P_A + 2) >> 2); + } else { + if (block_up) + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_A + 2) >> 2); else if (block_left) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_Q + 2)>>2); + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_Q + 2) >> 2); } } - - if(block_up) - { - if(block_up_left) - { - LoopArray[1] = (imgpel) ((PredPel[0] + (PredPel[1]<<1) + PredPel[2] + 2)>>2); - } - else - LoopArray[1] = (imgpel) ((PredPel[1] + (PredPel[1]<<1) + PredPel[2] + 2)>>2); + if (block_up) { + if (block_up_left) { + LoopArray[1] = + (imgpel)((PredPel[0] + (PredPel[1] << 1) + PredPel[2] + 2) >> 2); + } else + LoopArray[1] = + (imgpel)((PredPel[1] + (PredPel[1] << 1) + PredPel[2] + 2) >> 2); - for(i = 2; i <16; i++) - { - LoopArray[i] = (imgpel) ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2); + for (i = 2; i < 16; i++) { + LoopArray[i] = + (imgpel)((PredPel[i - 1] + (PredPel[i] << 1) + PredPel[i + 1] + 2) >> + 2); } - LoopArray[16] = (imgpel) ((P_P + (P_P<<1) + P_O + 2)>>2); + LoopArray[16] = (imgpel)((P_P + (P_P << 1) + P_O + 2) >> 2); } - if(block_left) - { - if(block_up_left) - LoopArray[17] = (imgpel) ((P_Z + (P_Q<<1) + P_R + 2)>>2); + if (block_left) { + if (block_up_left) + LoopArray[17] = (imgpel)((P_Z + (P_Q << 1) + P_R + 2) >> 2); else - LoopArray[17] = (imgpel) ((P_Q + (P_Q<<1) + P_R + 2)>>2); + LoopArray[17] = (imgpel)((P_Q + (P_Q << 1) + P_R + 2) >> 2); - for(i = 18; i <24; i++) - { - LoopArray[i] = (imgpel) ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2); + for (i = 18; i < 24; i++) { + LoopArray[i] = + (imgpel)((PredPel[i - 1] + (PredPel[i] << 1) + PredPel[i + 1] + 2) >> + 2); } - LoopArray[24] = (imgpel) ((P_W + (P_X<<1) + P_X + 2) >> 2); + LoopArray[24] = (imgpel)((P_W + (P_X << 1) + P_X + 2) >> 2); } memcpy(&PredPel[0], &LoopArray[0], 25 * sizeof(imgpel)); @@ -129,46 +123,40 @@ static inline void LowPassForIntra8x8Pred(imgpel *PredPel, int block_up_left, in * Prefiltering for Intra8x8 prediction (Horizontal) ************************************************************************************* */ -static inline void LowPassForIntra8x8PredHor(imgpel *PredPel, int block_up_left, int block_up, int block_left) -{ +static inline void LowPassForIntra8x8PredHor(imgpel *PredPel, int block_up_left, + int block_up, int block_left) { int i; imgpel LoopArray[25]; memcpy(&LoopArray[0], &PredPel[0], 25 * sizeof(imgpel)); - if(block_up_left) - { - if(block_up && block_left) - { - LoopArray[0] = (imgpel) ((P_Q + (P_Z<<1) + P_A + 2)>>2); - } - else - { - if(block_up) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_A + 2)>>2); + if (block_up_left) { + if (block_up && block_left) { + LoopArray[0] = (imgpel)((P_Q + (P_Z << 1) + P_A + 2) >> 2); + } else { + if (block_up) + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_A + 2) >> 2); else if (block_left) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_Q + 2)>>2); + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_Q + 2) >> 2); } } - - if(block_up) - { - if(block_up_left) - { - LoopArray[1] = (imgpel) ((PredPel[0] + (PredPel[1]<<1) + PredPel[2] + 2)>>2); - } - else - LoopArray[1] = (imgpel) ((PredPel[1] + (PredPel[1]<<1) + PredPel[2] + 2)>>2); + if (block_up) { + if (block_up_left) { + LoopArray[1] = + (imgpel)((PredPel[0] + (PredPel[1] << 1) + PredPel[2] + 2) >> 2); + } else + LoopArray[1] = + (imgpel)((PredPel[1] + (PredPel[1] << 1) + PredPel[2] + 2) >> 2); - for(i = 2; i <16; i++) - { - LoopArray[i] = (imgpel) ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2); + for (i = 2; i < 16; i++) { + LoopArray[i] = + (imgpel)((PredPel[i - 1] + (PredPel[i] << 1) + PredPel[i + 1] + 2) >> + 2); } - LoopArray[16] = (imgpel) ((P_P + (P_P<<1) + P_O + 2)>>2); + LoopArray[16] = (imgpel)((P_P + (P_P << 1) + P_O + 2) >> 2); } - memcpy(&PredPel[0], &LoopArray[0], 17 * sizeof(imgpel)); } @@ -178,71 +166,69 @@ static inline void LowPassForIntra8x8PredHor(imgpel *PredPel, int block_up_left, * Prefiltering for Intra8x8 prediction (Vertical) ************************************************************************************* */ -static inline void LowPassForIntra8x8PredVer(imgpel *PredPel, int block_up_left, int block_up, int block_left) -{ - // These functions need some cleanup and can be further optimized. - // For convenience, let us copy all data for now. It is obvious that the filtering makes things a bit more "complex" +static inline void LowPassForIntra8x8PredVer(imgpel *PredPel, int block_up_left, + int block_up, int block_left) { + // These functions need some cleanup and can be further optimized. + // For convenience, let us copy all data for now. It is obvious that the + // filtering makes things a bit more "complex" int i; imgpel LoopArray[25]; memcpy(&LoopArray[0], &PredPel[0], 25 * sizeof(imgpel)); - if(block_up_left) - { - if(block_up && block_left) - { - LoopArray[0] = (imgpel) ((P_Q + (P_Z<<1) + P_A + 2)>>2); - } - else - { - if(block_up) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_A + 2)>>2); + if (block_up_left) { + if (block_up && block_left) { + LoopArray[0] = (imgpel)((P_Q + (P_Z << 1) + P_A + 2) >> 2); + } else { + if (block_up) + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_A + 2) >> 2); else if (block_left) - LoopArray[0] = (imgpel) ((P_Z + (P_Z<<1) + P_Q + 2)>>2); + LoopArray[0] = (imgpel)((P_Z + (P_Z << 1) + P_Q + 2) >> 2); } } - - if(block_left) - { - if(block_up_left) - LoopArray[17] = (imgpel) ((P_Z + (P_Q<<1) + P_R + 2)>>2); - else - LoopArray[17] = (imgpel) ((P_Q + (P_Q<<1) + P_R + 2)>>2); - for(i = 18; i <24; i++) - { - LoopArray[i] = (imgpel) ((PredPel[i-1] + (PredPel[i]<<1) + PredPel[i+1] + 2)>>2); + if (block_left) { + if (block_up_left) + LoopArray[17] = (imgpel)((P_Z + (P_Q << 1) + P_R + 2) >> 2); + else + LoopArray[17] = (imgpel)((P_Q + (P_Q << 1) + P_R + 2) >> 2); + + for (i = 18; i < 24; i++) { + LoopArray[i] = + (imgpel)((PredPel[i - 1] + (PredPel[i] << 1) + PredPel[i + 1] + 2) >> + 2); } - LoopArray[24] = (imgpel) ((P_W + (P_X<<1) + P_X + 2) >> 2); + LoopArray[24] = (imgpel)((P_W + (P_X << 1) + P_X + 2) >> 2); } memcpy(&PredPel[0], &LoopArray[0], 25 * sizeof(imgpel)); } - /*! *********************************************************************** * \brief * makes and returns 8x8 DC prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_dc_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int intra8x8_dc_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { - int i,j; + int i, j; int s0 = 0; - imgpel PredPel[25]; // array of predictor pels + imgpel PredPel[25]; // array of predictor pels Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; - imgpel **imgY = (pl) ? dec_picture->imgUV[pl - 1] : dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel **imgY = (pl) ? dec_picture->imgUV[pl - 1] + : dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a; PixelPos pix_b, pix_c, pix_d; @@ -251,36 +237,35 @@ static inline int intra8x8_dc_pred(Macroblock *currMB, //!< current macrobloc int block_available_left; int block_available_up_left; int block_available_up_right; - imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; getNonAffNeighbour(currMB, ioff - 1, joff, mb_size, &pix_a); - getNonAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getNonAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getNonAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getNonAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -290,14 +275,12 @@ static inline int intra8x8_dc_pred(Macroblock *currMB, //!< current macrobloc P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -308,65 +291,55 @@ static inline int intra8x8_dc_pred(Macroblock *currMB, //!< current macrobloc P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - P_Q = *(*(img_pred ++) + pos_x); - P_R = *(*(img_pred ++) + pos_x); - P_S = *(*(img_pred ++) + pos_x); - P_T = *(*(img_pred ++) + pos_x); - P_U = *(*(img_pred ++) + pos_x); - P_V = *(*(img_pred ++) + pos_x); - P_W = *(*(img_pred ++) + pos_x); - P_X = *(*(img_pred ) + pos_x); - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + P_Q = *(*(img_pred++) + pos_x); + P_R = *(*(img_pred++) + pos_x); + P_S = *(*(img_pred++) + pos_x); + P_T = *(*(img_pred++) + pos_x); + P_U = *(*(img_pred++) + pos_x); + P_V = *(*(img_pred++) + pos_x); + P_W = *(*(img_pred++) + pos_x); + P_X = *(*(img_pred) + pos_x); + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); - - if (block_available_up && block_available_left) - { + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); + + if (block_available_up && block_available_left) { // no edge - s0 = (P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H + P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X + 8) >> 4; - } - else if (!block_available_up && block_available_left) - { + s0 = (P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H + P_Q + P_R + P_S + + P_T + P_U + P_V + P_W + P_X + 8) >> + 4; + } else if (!block_available_up && block_available_left) { // upper edge s0 = (P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X + 4) >> 3; - } - else if (block_available_up && !block_available_left) - { + } else if (block_available_up && !block_available_left) { // left edge s0 = (P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H + 4) >> 3; - } - else //if (!block_available_up && !block_available_left) + } else // if (!block_available_up && !block_available_left) { // top left corner, nothing to predict from s0 = p_Vid->dc_pred_value_comp[pl]; } - for(j = joff; j < joff + BLOCK_SIZE_8x8; j++) - for(i = ioff; i < ioff + BLOCK_SIZE_8x8; i++) - mpr[j][i] = (imgpel) s0; + for (j = joff; j < joff + BLOCK_SIZE_8x8; j++) + for (i = ioff; i < ioff + BLOCK_SIZE_8x8; i++) + mpr[j][i] = (imgpel)s0; return DECODING_OK; } @@ -377,21 +350,24 @@ static inline int intra8x8_dc_pred(Macroblock *currMB, //!< current macrobloc * makes and returns 8x8 vertical prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_vert_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int intra8x8_vert_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int i; - imgpel PredPel[25]; // array of predictor pels - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel PredPel[25]; // array of predictor pels + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a; PixelPos pix_b, pix_c, pix_d; @@ -401,83 +377,76 @@ static inline int intra8x8_vert_pred(Macroblock *currMB, //!< current macrobl int block_available_up_left; int block_available_up_right; - imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - getNonAffNeighbour(currMB, ioff - 1, joff , mb_size, &pix_a); - getNonAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff, mb_size, &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getNonAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getNonAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr] : 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_up) - printf ("warning: Intra_8x8_Vertical prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_8x8_Vertical prediction mode not allowed at mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; - P_A = *(pred_pels ++); - P_B = *(pred_pels ++); - P_C = *(pred_pels ++); - P_D = *(pred_pels ++); - P_E = *(pred_pels ++); - P_F = *(pred_pels ++); - P_G = *(pred_pels ++); + P_A = *(pred_pels++); + P_B = *(pred_pels++); + P_C = *(pred_pels++); + P_D = *(pred_pels++); + P_E = *(pred_pels++); + P_F = *(pred_pels++); + P_G = *(pred_pels++); P_H = *pred_pels; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; - P_I = *(pred_pels ++); - P_J = *(pred_pels ++); - P_K = *(pred_pels ++); - P_L = *(pred_pels ++); - P_M = *(pred_pels ++); - P_N = *(pred_pels ++); - P_O = *(pred_pels ++); + P_I = *(pred_pels++); + P_J = *(pred_pels++); + P_K = *(pred_pels++); + P_L = *(pred_pels++); + P_M = *(pred_pels++); + P_N = *(pred_pels++); + P_O = *(pred_pels++); P_P = *pred_pels; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8PredHor(&(P_Z), block_available_up_left, block_available_up, block_available_left); - - for (i=joff; i < joff + BLOCK_SIZE_8x8; i++) - { + LowPassForIntra8x8PredHor(&(P_Z), block_available_up_left, block_available_up, + block_available_left); + + for (i = joff; i < joff + BLOCK_SIZE_8x8; i++) { memcpy(&mpr[i][ioff], (&P_A), BLOCK_SIZE_8x8 * sizeof(imgpel)); } @@ -490,22 +459,24 @@ static inline int intra8x8_vert_pred(Macroblock *currMB, //!< current macrobl * makes and returns 8x8 horizontal prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_hor_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int intra8x8_hor_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - int j; - imgpel PredPel[25]; // array of predictor pels - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel PredPel[25]; // array of predictor pels + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a; PixelPos pix_b, pix_c, pix_d; @@ -516,85 +487,78 @@ static inline int intra8x8_hor_pred(Macroblock *currMB, //!< current macroblo int block_available_up_right; #if (IMGTYPE != 0) - int ipos0 = ioff , ipos1 = ioff + 1, ipos2 = ioff + 2, ipos3 = ioff + 3; + int ipos0 = ioff, ipos1 = ioff + 1, ipos2 = ioff + 2, ipos3 = ioff + 3; int ipos4 = ioff + 4, ipos5 = ioff + 5, ipos6 = ioff + 6, ipos7 = ioff + 7; #endif - int jpos; + int jpos; imgpel **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - getNonAffNeighbour(currMB, ioff - 1, joff , mb_size, &pix_a); - getNonAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff, mb_size, &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getNonAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getNonAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_left) - printf ("warning: Intra_8x8_Horizontal prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf( + "warning: Intra_8x8_Horizontal prediction mode not allowed at mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_left) - { + if (block_available_left) { imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - P_Q = *(*(img_pred ++) + pos_x); - P_R = *(*(img_pred ++) + pos_x); - P_S = *(*(img_pred ++) + pos_x); - P_T = *(*(img_pred ++) + pos_x); - P_U = *(*(img_pred ++) + pos_x); - P_V = *(*(img_pred ++) + pos_x); - P_W = *(*(img_pred ++) + pos_x); - P_X = *(*(img_pred ) + pos_x); - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + P_Q = *(*(img_pred++) + pos_x); + P_R = *(*(img_pred++) + pos_x); + P_S = *(*(img_pred++) + pos_x); + P_T = *(*(img_pred++) + pos_x); + P_U = *(*(img_pred++) + pos_x); + P_V = *(*(img_pred++) + pos_x); + P_W = *(*(img_pred++) + pos_x); + P_X = *(*(img_pred) + pos_x); + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8PredVer(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8PredVer(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - for (j=0; j < BLOCK_SIZE_8x8; j++) - { + for (j = 0; j < BLOCK_SIZE_8x8; j++) { jpos = j + joff; #if (IMGTYPE == 0) - memset(&mpr[jpos][ioff], (imgpel) (&P_Q)[j], 8 * sizeof(imgpel)); + memset(&mpr[jpos][ioff], (imgpel)(&P_Q)[j], 8 * sizeof(imgpel)); #else - mpr[jpos][ipos0] = - mpr[jpos][ipos1] = - mpr[jpos][ipos2] = - mpr[jpos][ipos3] = - mpr[jpos][ipos4] = - mpr[jpos][ipos5] = - mpr[jpos][ipos6] = - mpr[jpos][ipos7] = (imgpel) (&P_Q)[j]; + mpr[jpos][ipos0] = mpr[jpos][ipos1] = mpr[jpos][ipos2] = mpr[jpos][ipos3] = + mpr[jpos][ipos4] = mpr[jpos][ipos5] = mpr[jpos][ipos6] = + mpr[jpos][ipos7] = (imgpel)(&P_Q)[j]; #endif } - + return DECODING_OK; } @@ -604,21 +568,25 @@ static inline int intra8x8_hor_pred(Macroblock *currMB, //!< current macroblo * makes and returns 8x8 diagonal down right prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_diag_down_right_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_diag_down_right_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[16]; // array of final prediction values - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[16]; // array of final prediction values + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a; PixelPos pix_b, pix_c, pix_d; @@ -631,34 +599,37 @@ static inline int intra8x8_diag_down_right_pred(Macroblock *currMB, //!< curr imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - getNonAffNeighbour(currMB, ioff - 1, joff , mb_size, &pix_a); - getNonAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff, mb_size, &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getNonAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getNonAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_8x8_Diagonal_Down_Right prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_8x8_Diagonal_Down_Right prediction mode not allowed " + "at mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -668,14 +639,12 @@ static inline int intra8x8_diag_down_right_pred(Macroblock *currMB, //!< curr P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -686,57 +655,51 @@ static inline int intra8x8_diag_down_right_pred(Macroblock *currMB, //!< curr P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - P_Q = *(*(img_pred ++) + pos_x); - P_R = *(*(img_pred ++) + pos_x); - P_S = *(*(img_pred ++) + pos_x); - P_T = *(*(img_pred ++) + pos_x); - P_U = *(*(img_pred ++) + pos_x); - P_V = *(*(img_pred ++) + pos_x); - P_W = *(*(img_pred ++) + pos_x); - P_X = *(*(img_pred ) + pos_x); - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + P_Q = *(*(img_pred++) + pos_x); + P_R = *(*(img_pred++) + pos_x); + P_S = *(*(img_pred++) + pos_x); + P_T = *(*(img_pred++) + pos_x); + P_U = *(*(img_pred++) + pos_x); + P_V = *(*(img_pred++) + pos_x); + P_W = *(*(img_pred++) + pos_x); + P_X = *(*(img_pred) + pos_x); + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); // Mode DIAG_DOWN_RIGHT_PRED - PredArray[ 0] = (imgpel) ((P_X + P_V + 2*(P_W) + 2) >> 2); - PredArray[ 1] = (imgpel) ((P_W + P_U + 2*(P_V) + 2) >> 2); - PredArray[ 2] = (imgpel) ((P_V + P_T + 2*(P_U) + 2) >> 2); - PredArray[ 3] = (imgpel) ((P_U + P_S + 2*(P_T) + 2) >> 2); - PredArray[ 4] = (imgpel) ((P_T + P_R + 2*(P_S) + 2) >> 2); - PredArray[ 5] = (imgpel) ((P_S + P_Q + 2*(P_R) + 2) >> 2); - PredArray[ 6] = (imgpel) ((P_R + P_Z + 2*(P_Q) + 2) >> 2); - PredArray[ 7] = (imgpel) ((P_Q + P_A + 2*(P_Z) + 2) >> 2); - PredArray[ 8] = (imgpel) ((P_Z + P_B + 2*(P_A) + 2) >> 2); - PredArray[ 9] = (imgpel) ((P_A + P_C + 2*(P_B) + 2) >> 2); - PredArray[10] = (imgpel) ((P_B + P_D + 2*(P_C) + 2) >> 2); - PredArray[11] = (imgpel) ((P_C + P_E + 2*(P_D) + 2) >> 2); - PredArray[12] = (imgpel) ((P_D + P_F + 2*(P_E) + 2) >> 2); - PredArray[13] = (imgpel) ((P_E + P_G + 2*(P_F) + 2) >> 2); - PredArray[14] = (imgpel) ((P_F + P_H + 2*(P_G) + 2) >> 2); + PredArray[0] = (imgpel)((P_X + P_V + 2 * (P_W) + 2) >> 2); + PredArray[1] = (imgpel)((P_W + P_U + 2 * (P_V) + 2) >> 2); + PredArray[2] = (imgpel)((P_V + P_T + 2 * (P_U) + 2) >> 2); + PredArray[3] = (imgpel)((P_U + P_S + 2 * (P_T) + 2) >> 2); + PredArray[4] = (imgpel)((P_T + P_R + 2 * (P_S) + 2) >> 2); + PredArray[5] = (imgpel)((P_S + P_Q + 2 * (P_R) + 2) >> 2); + PredArray[6] = (imgpel)((P_R + P_Z + 2 * (P_Q) + 2) >> 2); + PredArray[7] = (imgpel)((P_Q + P_A + 2 * (P_Z) + 2) >> 2); + PredArray[8] = (imgpel)((P_Z + P_B + 2 * (P_A) + 2) >> 2); + PredArray[9] = (imgpel)((P_A + P_C + 2 * (P_B) + 2) >> 2); + PredArray[10] = (imgpel)((P_B + P_D + 2 * (P_C) + 2) >> 2); + PredArray[11] = (imgpel)((P_C + P_E + 2 * (P_D) + 2) >> 2); + PredArray[12] = (imgpel)((P_D + P_F + 2 * (P_E) + 2) >> 2); + PredArray[13] = (imgpel)((P_E + P_G + 2 * (P_F) + 2) >> 2); + PredArray[14] = (imgpel)((P_F + P_H + 2 * (P_G) + 2) >> 2); memcpy(&mpr[joff++][ioff], &PredArray[7], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[6], 8 * sizeof(imgpel)); @@ -745,8 +708,8 @@ static inline int intra8x8_diag_down_right_pred(Macroblock *currMB, //!< curr memcpy(&mpr[joff++][ioff], &PredArray[3], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[2], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[1], 8 * sizeof(imgpel)); - memcpy(&mpr[joff ][ioff], &PredArray[0], 8 * sizeof(imgpel)); - + memcpy(&mpr[joff][ioff], &PredArray[0], 8 * sizeof(imgpel)); + return DECODING_OK; } @@ -756,22 +719,26 @@ static inline int intra8x8_diag_down_right_pred(Macroblock *currMB, //!< curr * makes and returns 8x8 diagonal down left prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_diag_down_left_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_diag_down_left_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[16]; // array of final prediction values + + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[16]; // array of final prediction values imgpel *Pred = &PredArray[0]; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a; PixelPos pix_b, pix_c, pix_d; @@ -780,38 +747,40 @@ static inline int intra8x8_diag_down_left_pred(Macroblock *currMB, //!< curre int block_available_left; int block_available_up_left; int block_available_up_right; - + imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - getNonAffNeighbour(currMB, ioff - 1, joff , mb_size, &pix_a); - getNonAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff, mb_size, &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getNonAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getNonAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_up) - printf ("warning: Intra_8x8_Diagonal_Down_Left prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_8x8_Diagonal_Down_Left prediction mode not allowed " + "at mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -821,14 +790,12 @@ static inline int intra8x8_diag_down_left_pred(Macroblock *currMB, //!< curre P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -839,59 +806,53 @@ static inline int intra8x8_diag_down_left_pred(Macroblock *currMB, //!< curre P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - P_Q = *(*(img_pred ++) + pos_x); - P_R = *(*(img_pred ++) + pos_x); - P_S = *(*(img_pred ++) + pos_x); - P_T = *(*(img_pred ++) + pos_x); - P_U = *(*(img_pred ++) + pos_x); - P_V = *(*(img_pred ++) + pos_x); - P_W = *(*(img_pred ++) + pos_x); - P_X = *(*(img_pred ) + pos_x); - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + P_Q = *(*(img_pred++) + pos_x); + P_R = *(*(img_pred++) + pos_x); + P_S = *(*(img_pred++) + pos_x); + P_T = *(*(img_pred++) + pos_x); + P_U = *(*(img_pred++) + pos_x); + P_V = *(*(img_pred++) + pos_x); + P_W = *(*(img_pred++) + pos_x); + P_X = *(*(img_pred) + pos_x); + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); // Mode DIAG_DOWN_LEFT_PRED - *Pred++ = (imgpel) ((P_A + P_C + 2*(P_B) + 2) >> 2); - *Pred++ = (imgpel) ((P_B + P_D + 2*(P_C) + 2) >> 2); - *Pred++ = (imgpel) ((P_C + P_E + 2*(P_D) + 2) >> 2); - *Pred++ = (imgpel) ((P_D + P_F + 2*(P_E) + 2) >> 2); - *Pred++ = (imgpel) ((P_E + P_G + 2*(P_F) + 2) >> 2); - *Pred++ = (imgpel) ((P_F + P_H + 2*(P_G) + 2) >> 2); - *Pred++ = (imgpel) ((P_G + P_I + 2*(P_H) + 2) >> 2); - *Pred++ = (imgpel) ((P_H + P_J + 2*(P_I) + 2) >> 2); - *Pred++ = (imgpel) ((P_I + P_K + 2*(P_J) + 2) >> 2); - *Pred++ = (imgpel) ((P_J + P_L + 2*(P_K) + 2) >> 2); - *Pred++ = (imgpel) ((P_K + P_M + 2*(P_L) + 2) >> 2); - *Pred++ = (imgpel) ((P_L + P_N + 2*(P_M) + 2) >> 2); - *Pred++ = (imgpel) ((P_M + P_O + 2*(P_N) + 2) >> 2); - *Pred++ = (imgpel) ((P_N + P_P + 2*(P_O) + 2) >> 2); - *Pred = (imgpel) ((P_O + 3*(P_P) + 2) >> 2); + *Pred++ = (imgpel)((P_A + P_C + 2 * (P_B) + 2) >> 2); + *Pred++ = (imgpel)((P_B + P_D + 2 * (P_C) + 2) >> 2); + *Pred++ = (imgpel)((P_C + P_E + 2 * (P_D) + 2) >> 2); + *Pred++ = (imgpel)((P_D + P_F + 2 * (P_E) + 2) >> 2); + *Pred++ = (imgpel)((P_E + P_G + 2 * (P_F) + 2) >> 2); + *Pred++ = (imgpel)((P_F + P_H + 2 * (P_G) + 2) >> 2); + *Pred++ = (imgpel)((P_G + P_I + 2 * (P_H) + 2) >> 2); + *Pred++ = (imgpel)((P_H + P_J + 2 * (P_I) + 2) >> 2); + *Pred++ = (imgpel)((P_I + P_K + 2 * (P_J) + 2) >> 2); + *Pred++ = (imgpel)((P_J + P_L + 2 * (P_K) + 2) >> 2); + *Pred++ = (imgpel)((P_K + P_M + 2 * (P_L) + 2) >> 2); + *Pred++ = (imgpel)((P_L + P_N + 2 * (P_M) + 2) >> 2); + *Pred++ = (imgpel)((P_M + P_O + 2 * (P_N) + 2) >> 2); + *Pred++ = (imgpel)((P_N + P_P + 2 * (P_O) + 2) >> 2); + *Pred = (imgpel)((P_O + 3 * (P_P) + 2) >> 2); - Pred = &PredArray[ 0]; + Pred = &PredArray[0]; memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); @@ -900,7 +861,7 @@ static inline int intra8x8_diag_down_left_pred(Macroblock *currMB, //!< curre memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], Pred++, 8 * sizeof(imgpel)); - memcpy(&mpr[joff ][ioff], Pred , 8 * sizeof(imgpel)); + memcpy(&mpr[joff][ioff], Pred, 8 * sizeof(imgpel)); return DECODING_OK; } @@ -911,21 +872,25 @@ static inline int intra8x8_diag_down_left_pred(Macroblock *currMB, //!< curre * makes and returns 8x8 vertical right prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_vert_right_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_vert_right_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[22]; // array of final prediction values - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[22]; // array of final prediction values + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a; PixelPos pix_b, pix_c, pix_d; @@ -938,34 +903,37 @@ static inline int intra8x8_vert_right_pred(Macroblock *currMB, //!< current m imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - getNonAffNeighbour(currMB, ioff - 1, joff , mb_size, &pix_a); - getNonAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff, mb_size, &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getNonAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getNonAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr]: 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_8x8_Vertical_Right prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_8x8_Vertical_Right prediction mode not allowed at " + "mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -975,14 +943,12 @@ static inline int intra8x8_vert_right_pred(Macroblock *currMB, //!< current m P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -993,100 +959,97 @@ static inline int intra8x8_vert_right_pred(Macroblock *currMB, //!< current m P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - P_Q = *(*(img_pred ++) + pos_x); - P_R = *(*(img_pred ++) + pos_x); - P_S = *(*(img_pred ++) + pos_x); - P_T = *(*(img_pred ++) + pos_x); - P_U = *(*(img_pred ++) + pos_x); - P_V = *(*(img_pred ++) + pos_x); - P_W = *(*(img_pred ++) + pos_x); - P_X = *(*(img_pred ) + pos_x); - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + P_Q = *(*(img_pred++) + pos_x); + P_R = *(*(img_pred++) + pos_x); + P_S = *(*(img_pred++) + pos_x); + P_T = *(*(img_pred++) + pos_x); + P_U = *(*(img_pred++) + pos_x); + P_V = *(*(img_pred++) + pos_x); + P_W = *(*(img_pred++) + pos_x); + P_X = *(*(img_pred) + pos_x); + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - PredArray[ 0] = (imgpel) ((P_V + P_T + 2*P_U + 2) >> 2); - PredArray[ 1] = (imgpel) ((P_T + P_R + 2*P_S + 2) >> 2); - PredArray[ 2] = (imgpel) ((P_R + P_Z + 2*P_Q + 2) >> 2); - PredArray[ 3] = (imgpel) ((P_Z + P_A + 1) >> 1); - PredArray[ 4] = (imgpel) ((P_A + P_B + 1) >> 1); - PredArray[ 5] = (imgpel) ((P_B + P_C + 1) >> 1); - PredArray[ 6] = (imgpel) ((P_C + P_D + 1) >> 1); - PredArray[ 7] = (imgpel) ((P_D + P_E + 1) >> 1); - PredArray[ 8] = (imgpel) ((P_E + P_F + 1) >> 1); - PredArray[ 9] = (imgpel) ((P_F + P_G + 1) >> 1); - PredArray[10] = (imgpel) ((P_G + P_H + 1) >> 1); + PredArray[0] = (imgpel)((P_V + P_T + 2 * P_U + 2) >> 2); + PredArray[1] = (imgpel)((P_T + P_R + 2 * P_S + 2) >> 2); + PredArray[2] = (imgpel)((P_R + P_Z + 2 * P_Q + 2) >> 2); + PredArray[3] = (imgpel)((P_Z + P_A + 1) >> 1); + PredArray[4] = (imgpel)((P_A + P_B + 1) >> 1); + PredArray[5] = (imgpel)((P_B + P_C + 1) >> 1); + PredArray[6] = (imgpel)((P_C + P_D + 1) >> 1); + PredArray[7] = (imgpel)((P_D + P_E + 1) >> 1); + PredArray[8] = (imgpel)((P_E + P_F + 1) >> 1); + PredArray[9] = (imgpel)((P_F + P_G + 1) >> 1); + PredArray[10] = (imgpel)((P_G + P_H + 1) >> 1); - PredArray[11] = (imgpel) ((P_W + P_U + 2*P_V + 2) >> 2); - PredArray[12] = (imgpel) ((P_U + P_S + 2*P_T + 2) >> 2); - PredArray[13] = (imgpel) ((P_S + P_Q + 2*P_R + 2) >> 2); - PredArray[14] = (imgpel) ((P_Q + P_A + 2*P_Z + 2) >> 2); - PredArray[15] = (imgpel) ((P_Z + P_B + 2*P_A + 2) >> 2); - PredArray[16] = (imgpel) ((P_A + P_C + 2*P_B + 2) >> 2); - PredArray[17] = (imgpel) ((P_B + P_D + 2*P_C + 2) >> 2); - PredArray[18] = (imgpel) ((P_C + P_E + 2*P_D + 2) >> 2); - PredArray[19] = (imgpel) ((P_D + P_F + 2*P_E + 2) >> 2); - PredArray[20] = (imgpel) ((P_E + P_G + 2*P_F + 2) >> 2); - PredArray[21] = (imgpel) ((P_F + P_H + 2*P_G + 2) >> 2); + PredArray[11] = (imgpel)((P_W + P_U + 2 * P_V + 2) >> 2); + PredArray[12] = (imgpel)((P_U + P_S + 2 * P_T + 2) >> 2); + PredArray[13] = (imgpel)((P_S + P_Q + 2 * P_R + 2) >> 2); + PredArray[14] = (imgpel)((P_Q + P_A + 2 * P_Z + 2) >> 2); + PredArray[15] = (imgpel)((P_Z + P_B + 2 * P_A + 2) >> 2); + PredArray[16] = (imgpel)((P_A + P_C + 2 * P_B + 2) >> 2); + PredArray[17] = (imgpel)((P_B + P_D + 2 * P_C + 2) >> 2); + PredArray[18] = (imgpel)((P_C + P_E + 2 * P_D + 2) >> 2); + PredArray[19] = (imgpel)((P_D + P_F + 2 * P_E + 2) >> 2); + PredArray[20] = (imgpel)((P_E + P_G + 2 * P_F + 2) >> 2); + PredArray[21] = (imgpel)((P_F + P_H + 2 * P_G + 2) >> 2); - memcpy(&mpr[joff++][ioff], &PredArray[ 3], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[3], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[14], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 2], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[2], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[13], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 1], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[1], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[12], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 0], 8 * sizeof(imgpel)); - memcpy(&mpr[joff ][ioff], &PredArray[11], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[0], 8 * sizeof(imgpel)); + memcpy(&mpr[joff][ioff], &PredArray[11], 8 * sizeof(imgpel)); return DECODING_OK; } - /*! *********************************************************************** * \brief * makes and returns 8x8 vertical left prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_vert_left_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_vert_left_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[22]; // array of final prediction values + + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[22]; // array of final prediction values imgpel *pred_pel = &PredArray[0]; - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a; PixelPos pix_b, pix_c, pix_d; @@ -1099,34 +1062,36 @@ static inline int intra8x8_vert_left_pred(Macroblock *currMB, //!< current ma imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - getNonAffNeighbour(currMB, ioff - 1, joff , mb_size, &pix_a); - getNonAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff, mb_size, &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getNonAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getNonAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr] : 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_up) - printf ("warning: Intra_4x4_Vertical_Left prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_4x4_Vertical_Left prediction mode not allowed at mb " + "%d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -1136,14 +1101,12 @@ static inline int intra8x8_vert_left_pred(Macroblock *currMB, //!< current ma P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -1154,72 +1117,66 @@ static inline int intra8x8_vert_left_pred(Macroblock *currMB, //!< current ma P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - P_Q = *(*(img_pred ++) + pos_x); - P_R = *(*(img_pred ++) + pos_x); - P_S = *(*(img_pred ++) + pos_x); - P_T = *(*(img_pred ++) + pos_x); - P_U = *(*(img_pred ++) + pos_x); - P_V = *(*(img_pred ++) + pos_x); - P_W = *(*(img_pred ++) + pos_x); - P_X = *(*(img_pred ) + pos_x); - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + P_Q = *(*(img_pred++) + pos_x); + P_R = *(*(img_pred++) + pos_x); + P_S = *(*(img_pred++) + pos_x); + P_T = *(*(img_pred++) + pos_x); + P_U = *(*(img_pred++) + pos_x); + P_V = *(*(img_pred++) + pos_x); + P_W = *(*(img_pred++) + pos_x); + P_X = *(*(img_pred) + pos_x); + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - *pred_pel++ = (imgpel) ((P_A + P_B + 1) >> 1); - *pred_pel++ = (imgpel) ((P_B + P_C + 1) >> 1); - *pred_pel++ = (imgpel) ((P_C + P_D + 1) >> 1); - *pred_pel++ = (imgpel) ((P_D + P_E + 1) >> 1); - *pred_pel++ = (imgpel) ((P_E + P_F + 1) >> 1); - *pred_pel++ = (imgpel) ((P_F + P_G + 1) >> 1); - *pred_pel++ = (imgpel) ((P_G + P_H + 1) >> 1); - *pred_pel++ = (imgpel) ((P_H + P_I + 1) >> 1); - *pred_pel++ = (imgpel) ((P_I + P_J + 1) >> 1); - *pred_pel++ = (imgpel) ((P_J + P_K + 1) >> 1); - *pred_pel++ = (imgpel) ((P_K + P_L + 1) >> 1); - *pred_pel++ = (imgpel) ((P_A + P_C + 2*P_B + 2) >> 2); - *pred_pel++ = (imgpel) ((P_B + P_D + 2*P_C + 2) >> 2); - *pred_pel++ = (imgpel) ((P_C + P_E + 2*P_D + 2) >> 2); - *pred_pel++ = (imgpel) ((P_D + P_F + 2*P_E + 2) >> 2); - *pred_pel++ = (imgpel) ((P_E + P_G + 2*P_F + 2) >> 2); - *pred_pel++ = (imgpel) ((P_F + P_H + 2*P_G + 2) >> 2); - *pred_pel++ = (imgpel) ((P_G + P_I + 2*P_H + 2) >> 2); - *pred_pel++ = (imgpel) ((P_H + P_J + 2*P_I + 2) >> 2); - *pred_pel++ = (imgpel) ((P_I + P_K + 2*P_J + 2) >> 2); - *pred_pel++ = (imgpel) ((P_J + P_L + 2*P_K + 2) >> 2); - *pred_pel = (imgpel) ((P_K + P_M + 2*P_L + 2) >> 2); + *pred_pel++ = (imgpel)((P_A + P_B + 1) >> 1); + *pred_pel++ = (imgpel)((P_B + P_C + 1) >> 1); + *pred_pel++ = (imgpel)((P_C + P_D + 1) >> 1); + *pred_pel++ = (imgpel)((P_D + P_E + 1) >> 1); + *pred_pel++ = (imgpel)((P_E + P_F + 1) >> 1); + *pred_pel++ = (imgpel)((P_F + P_G + 1) >> 1); + *pred_pel++ = (imgpel)((P_G + P_H + 1) >> 1); + *pred_pel++ = (imgpel)((P_H + P_I + 1) >> 1); + *pred_pel++ = (imgpel)((P_I + P_J + 1) >> 1); + *pred_pel++ = (imgpel)((P_J + P_K + 1) >> 1); + *pred_pel++ = (imgpel)((P_K + P_L + 1) >> 1); + *pred_pel++ = (imgpel)((P_A + P_C + 2 * P_B + 2) >> 2); + *pred_pel++ = (imgpel)((P_B + P_D + 2 * P_C + 2) >> 2); + *pred_pel++ = (imgpel)((P_C + P_E + 2 * P_D + 2) >> 2); + *pred_pel++ = (imgpel)((P_D + P_F + 2 * P_E + 2) >> 2); + *pred_pel++ = (imgpel)((P_E + P_G + 2 * P_F + 2) >> 2); + *pred_pel++ = (imgpel)((P_F + P_H + 2 * P_G + 2) >> 2); + *pred_pel++ = (imgpel)((P_G + P_I + 2 * P_H + 2) >> 2); + *pred_pel++ = (imgpel)((P_H + P_J + 2 * P_I + 2) >> 2); + *pred_pel++ = (imgpel)((P_I + P_K + 2 * P_J + 2) >> 2); + *pred_pel++ = (imgpel)((P_J + P_L + 2 * P_K + 2) >> 2); + *pred_pel = (imgpel)((P_K + P_M + 2 * P_L + 2) >> 2); - memcpy(&mpr[joff++][ioff], &PredArray[ 0], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[0], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[11], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 1], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[1], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[12], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 2], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[2], 8 * sizeof(imgpel)); memcpy(&mpr[joff++][ioff], &PredArray[13], 8 * sizeof(imgpel)); - memcpy(&mpr[joff++][ioff], &PredArray[ 3], 8 * sizeof(imgpel)); - memcpy(&mpr[joff ][ioff], &PredArray[14], 8 * sizeof(imgpel)); + memcpy(&mpr[joff++][ioff], &PredArray[3], 8 * sizeof(imgpel)); + memcpy(&mpr[joff][ioff], &PredArray[14], 8 * sizeof(imgpel)); return DECODING_OK; } @@ -1230,21 +1187,25 @@ static inline int intra8x8_vert_left_pred(Macroblock *currMB, //!< current ma * makes and returns 8x8 horizontal up prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_hor_up_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_hor_up_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[16]; // array of final prediction values - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[16]; // array of final prediction values + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a; PixelPos pix_b, pix_c, pix_d; @@ -1253,46 +1214,48 @@ static inline int intra8x8_hor_up_pred(Macroblock *currMB, //!< current macro int block_available_left; int block_available_up_left; int block_available_up_right; - int jpos0 = joff , jpos1 = joff + 1, jpos2 = joff + 2, jpos3 = joff + 3; + int jpos0 = joff, jpos1 = joff + 1, jpos2 = joff + 2, jpos3 = joff + 3; int jpos4 = joff + 4, jpos5 = joff + 5, jpos6 = joff + 6, jpos7 = joff + 7; #if (IMGTYPE == 0) int ipos3 = ioff + 3, ipos5 = ioff + 5, ipos7 = ioff + 7; #else - int ipos0 = ioff , ipos1 = ioff + 1, ipos2 = ioff + 2, ipos3 = ioff + 3; + int ipos0 = ioff, ipos1 = ioff + 1, ipos2 = ioff + 2, ipos3 = ioff + 3; int ipos4 = ioff + 4, ipos5 = ioff + 5, ipos6 = ioff + 6, ipos7 = ioff + 7; #endif imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - getNonAffNeighbour(currMB, ioff - 1, joff , mb_size, &pix_a); - getNonAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff, mb_size, &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getNonAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getNonAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr] : 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } if (!block_available_left) - printf ("warning: Intra_8x8_Horizontal_Up prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + printf("warning: Intra_8x8_Horizontal_Up prediction mode not allowed at mb " + "%d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -1302,14 +1265,12 @@ static inline int intra8x8_hor_up_pred(Macroblock *currMB, //!< current macro P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -1320,56 +1281,50 @@ static inline int intra8x8_hor_up_pred(Macroblock *currMB, //!< current macro P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - P_Q = *(*(img_pred ++) + pos_x); - P_R = *(*(img_pred ++) + pos_x); - P_S = *(*(img_pred ++) + pos_x); - P_T = *(*(img_pred ++) + pos_x); - P_U = *(*(img_pred ++) + pos_x); - P_V = *(*(img_pred ++) + pos_x); - P_W = *(*(img_pred ++) + pos_x); - P_X = *(*(img_pred ) + pos_x); - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + P_Q = *(*(img_pred++) + pos_x); + P_R = *(*(img_pred++) + pos_x); + P_S = *(*(img_pred++) + pos_x); + P_T = *(*(img_pred++) + pos_x); + P_U = *(*(img_pred++) + pos_x); + P_V = *(*(img_pred++) + pos_x); + P_W = *(*(img_pred++) + pos_x); + P_X = *(*(img_pred) + pos_x); + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - PredArray[ 0] = (imgpel) ((P_Q + P_R + 1) >> 1); - PredArray[ 1] = (imgpel) ((P_S + P_Q + 2*P_R + 2) >> 2); - PredArray[ 2] = (imgpel) ((P_R + P_S + 1) >> 1); - PredArray[ 3] = (imgpel) ((P_T + P_R + 2*P_S + 2) >> 2); - PredArray[ 4] = (imgpel) ((P_S + P_T + 1) >> 1); - PredArray[ 5] = (imgpel) ((P_U + P_S + 2*P_T + 2) >> 2); - PredArray[ 6] = (imgpel) ((P_T + P_U + 1) >> 1); - PredArray[ 7] = (imgpel) ((P_V + P_T + 2*P_U + 2) >> 2); - PredArray[ 8] = (imgpel) ((P_U + P_V + 1) >> 1); - PredArray[ 9] = (imgpel) ((P_W + P_U + 2*P_V + 2) >> 2); - PredArray[10] = (imgpel) ((P_V + P_W + 1) >> 1); - PredArray[11] = (imgpel) ((P_X + P_V + 2*P_W + 2) >> 2); - PredArray[12] = (imgpel) ((P_W + P_X + 1) >> 1); - PredArray[13] = (imgpel) ((P_W + 3*P_X + 2) >> 2); - PredArray[14] = (imgpel) P_X; + PredArray[0] = (imgpel)((P_Q + P_R + 1) >> 1); + PredArray[1] = (imgpel)((P_S + P_Q + 2 * P_R + 2) >> 2); + PredArray[2] = (imgpel)((P_R + P_S + 1) >> 1); + PredArray[3] = (imgpel)((P_T + P_R + 2 * P_S + 2) >> 2); + PredArray[4] = (imgpel)((P_S + P_T + 1) >> 1); + PredArray[5] = (imgpel)((P_U + P_S + 2 * P_T + 2) >> 2); + PredArray[6] = (imgpel)((P_T + P_U + 1) >> 1); + PredArray[7] = (imgpel)((P_V + P_T + 2 * P_U + 2) >> 2); + PredArray[8] = (imgpel)((P_U + P_V + 1) >> 1); + PredArray[9] = (imgpel)((P_W + P_U + 2 * P_V + 2) >> 2); + PredArray[10] = (imgpel)((P_V + P_W + 1) >> 1); + PredArray[11] = (imgpel)((P_X + P_V + 2 * P_W + 2) >> 2); + PredArray[12] = (imgpel)((P_W + P_X + 1) >> 1); + PredArray[13] = (imgpel)((P_W + 3 * P_X + 2) >> 2); + PredArray[14] = (imgpel)P_X; memcpy(&mpr[jpos0][ioff], &PredArray[0], 8 * sizeof(imgpel)); memcpy(&mpr[jpos1][ioff], &PredArray[2], 8 * sizeof(imgpel)); @@ -1383,13 +1338,15 @@ static inline int intra8x8_hor_up_pred(Macroblock *currMB, //!< current macro mpr[jpos4][ipos7] = PredArray[14]; memset(&mpr[jpos5][ipos5], PredArray[14], 3 * sizeof(imgpel)); memset(&mpr[jpos6][ipos3], PredArray[14], 5 * sizeof(imgpel)); - memset(&mpr[jpos7][ioff ], PredArray[14], 8 * sizeof(imgpel)); + memset(&mpr[jpos7][ioff], PredArray[14], 8 * sizeof(imgpel)); #else mpr[jpos4][ipos7] = PredArray[14]; - mpr[jpos5][ipos5] = mpr[jpos5][ipos6] = mpr[jpos5][ipos7] = PredArray[14]; - mpr[jpos6][ipos3] = mpr[jpos6][ipos4] = mpr[jpos6][ipos5] = mpr[jpos6][ipos6] = mpr[jpos6][ipos7] = PredArray[14]; - mpr[jpos7][ipos0] = mpr[jpos7][ipos1] = mpr[jpos7][ipos2] = mpr[jpos7][ipos3] = - mpr[jpos7][ipos4] = mpr[jpos7][ipos5] = mpr[jpos7][ipos6] = mpr[jpos7][ipos7] = PredArray[14]; + mpr[jpos5][ipos5] = mpr[jpos5][ipos6] = mpr[jpos5][ipos7] = PredArray[14]; + mpr[jpos6][ipos3] = mpr[jpos6][ipos4] = mpr[jpos6][ipos5] = + mpr[jpos6][ipos6] = mpr[jpos6][ipos7] = PredArray[14]; + mpr[jpos7][ipos0] = mpr[jpos7][ipos1] = mpr[jpos7][ipos2] = + mpr[jpos7][ipos3] = mpr[jpos7][ipos4] = mpr[jpos7][ipos5] = + mpr[jpos7][ipos6] = mpr[jpos7][ipos7] = PredArray[14]; #endif return DECODING_OK; } @@ -1400,21 +1357,25 @@ static inline int intra8x8_hor_up_pred(Macroblock *currMB, //!< current macro * makes and returns 8x8 horizontal down prediction mode * * \return - * DECODING_OK decoding of intraprediction mode was successful \n + * DECODING_OK decoding of intraprediction mode was successful \n * *********************************************************************** */ -static inline int intra8x8_hor_down_pred(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< current image plane - int ioff, //!< pixel offset X within MB - int joff) //!< pixel offset Y within MB +static inline int +intra8x8_hor_down_pred(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< current image plane + int ioff, //!< pixel offset X within MB + int joff) //!< pixel offset Y within MB { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - imgpel PredPel[25]; // array of predictor pels - imgpel PredArray[22]; // array of final prediction values - imgpel **imgY = (pl) ? currSlice->dec_picture->imgUV[pl - 1] : currSlice->dec_picture->imgY; // For MB level frame/field coding tools -- set default to imgY + imgpel PredPel[25]; // array of predictor pels + imgpel PredArray[22]; // array of final prediction values + imgpel **imgY = + (pl) ? currSlice->dec_picture->imgUV[pl - 1] + : currSlice->dec_picture->imgY; // For MB level frame/field coding + // tools -- set default to imgY PixelPos pix_a; PixelPos pix_b, pix_c, pix_d; @@ -1423,40 +1384,43 @@ static inline int intra8x8_hor_down_pred(Macroblock *currMB, //!< current mac int block_available_left; int block_available_up_left; int block_available_up_right; - int jpos0 = joff , jpos1 = joff + 1, jpos2 = joff + 2, jpos3 = joff + 3; + int jpos0 = joff, jpos1 = joff + 1, jpos2 = joff + 2, jpos3 = joff + 3; int jpos4 = joff + 4, jpos5 = joff + 5, jpos6 = joff + 6, jpos7 = joff + 7; - + imgpel *pred_pels, **mpr = currSlice->mb_pred[pl]; int *mb_size = p_Vid->mb_size[IS_LUMA]; - getNonAffNeighbour(currMB, ioff - 1, joff , mb_size, &pix_a); - getNonAffNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b); + getNonAffNeighbour(currMB, ioff - 1, joff, mb_size, &pix_a); + getNonAffNeighbour(currMB, ioff, joff - 1, mb_size, &pix_b); getNonAffNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c); getNonAffNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d); - pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8); + pix_c.available = pix_c.available && !(ioff == 8 && joff == 8); - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - block_available_left = pix_a.available ? currSlice->intra_block [pix_a.mb_addr] : 0; - block_available_up = pix_b.available ? currSlice->intra_block [pix_b.mb_addr] : 0; - block_available_up_right = pix_c.available ? currSlice->intra_block [pix_c.mb_addr] : 0; - block_available_up_left = pix_d.available ? currSlice->intra_block [pix_d.mb_addr] : 0; - } - else - { - block_available_left = pix_a.available; - block_available_up = pix_b.available; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + block_available_left = + pix_a.available ? currSlice->intra_block[pix_a.mb_addr] : 0; + block_available_up = + pix_b.available ? currSlice->intra_block[pix_b.mb_addr] : 0; + block_available_up_right = + pix_c.available ? currSlice->intra_block[pix_c.mb_addr] : 0; + block_available_up_left = + pix_d.available ? currSlice->intra_block[pix_d.mb_addr] : 0; + } else { + block_available_left = pix_a.available; + block_available_up = pix_b.available; block_available_up_right = pix_c.available; - block_available_up_left = pix_d.available; + block_available_up_left = pix_d.available; } - if ((!block_available_up)||(!block_available_left)||(!block_available_up_left)) - printf ("warning: Intra_8x8_Horizontal_Down prediction mode not allowed at mb %d\n", (int) currSlice->current_mb_nr); + if ((!block_available_up) || (!block_available_left) || + (!block_available_up_left)) + printf("warning: Intra_8x8_Horizontal_Down prediction mode not allowed at " + "mb %d\n", + (int)currSlice->current_mb_nr); // form predictor pels - if (block_available_up) - { + if (block_available_up) { pred_pels = &imgY[pix_b.pos_y][pix_b.pos_x]; P_A = pred_pels[0]; P_B = pred_pels[1]; @@ -1466,14 +1430,12 @@ static inline int intra8x8_hor_down_pred(Macroblock *currMB, //!< current mac P_F = pred_pels[5]; P_G = pred_pels[6]; P_H = pred_pels[7]; - } - else - { - P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_right) - { + if (block_available_up_right) { pred_pels = &imgY[pix_c.pos_y][pix_c.pos_x]; P_I = pred_pels[0]; P_J = pred_pels[1]; @@ -1484,73 +1446,67 @@ static inline int intra8x8_hor_down_pred(Macroblock *currMB, //!< current mac P_O = pred_pels[6]; P_P = pred_pels[7]; - } - else - { + } else { P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H; } - if (block_available_left) - { + if (block_available_left) { imgpel **img_pred = &imgY[pix_a.pos_y]; int pos_x = pix_a.pos_x; - P_Q = *(*(img_pred ++) + pos_x); - P_R = *(*(img_pred ++) + pos_x); - P_S = *(*(img_pred ++) + pos_x); - P_T = *(*(img_pred ++) + pos_x); - P_U = *(*(img_pred ++) + pos_x); - P_V = *(*(img_pred ++) + pos_x); - P_W = *(*(img_pred ++) + pos_x); - P_X = *(*(img_pred ) + pos_x); - } - else - { - P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = (imgpel) p_Vid->dc_pred_value_comp[pl]; + P_Q = *(*(img_pred++) + pos_x); + P_R = *(*(img_pred++) + pos_x); + P_S = *(*(img_pred++) + pos_x); + P_T = *(*(img_pred++) + pos_x); + P_U = *(*(img_pred++) + pos_x); + P_V = *(*(img_pred++) + pos_x); + P_W = *(*(img_pred++) + pos_x); + P_X = *(*(img_pred) + pos_x); + } else { + P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = + (imgpel)p_Vid->dc_pred_value_comp[pl]; } - if (block_available_up_left) - { + if (block_available_up_left) { P_Z = imgY[pix_d.pos_y][pix_d.pos_x]; - } - else - { - P_Z = (imgpel) p_Vid->dc_pred_value_comp[pl]; + } else { + P_Z = (imgpel)p_Vid->dc_pred_value_comp[pl]; } - LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left); + LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, + block_available_left); - PredArray[ 0] = (imgpel) ((P_X + P_W + 1) >> 1); - PredArray[ 1] = (imgpel) ((P_V + P_X + 2*P_W + 2) >> 2); - PredArray[ 2] = (imgpel) ((P_W + P_V + 1) >> 1); - PredArray[ 3] = (imgpel) ((P_U + P_W + 2*P_V + 2) >> 2); - PredArray[ 4] = (imgpel) ((P_V + P_U + 1) >> 1); - PredArray[ 5] = (imgpel) ((P_T + P_V + 2*P_U + 2) >> 2); - PredArray[ 6] = (imgpel) ((P_U + P_T + 1) >> 1); - PredArray[ 7] = (imgpel) ((P_S + P_U + 2*P_T + 2) >> 2); - PredArray[ 8] = (imgpel) ((P_T + P_S + 1) >> 1); - PredArray[ 9] = (imgpel) ((P_R + P_T + 2*P_S + 2) >> 2); - PredArray[10] = (imgpel) ((P_S + P_R + 1) >> 1); - PredArray[11] = (imgpel) ((P_Q + P_S + 2*P_R + 2) >> 2); - PredArray[12] = (imgpel) ((P_R + P_Q + 1) >> 1); - PredArray[13] = (imgpel) ((P_Z + P_R + 2*P_Q + 2) >> 2); - PredArray[14] = (imgpel) ((P_Q + P_Z + 1) >> 1); - PredArray[15] = (imgpel) ((P_Q + P_A + 2*P_Z + 2) >> 2); - PredArray[16] = (imgpel) ((P_Z + P_B + 2*P_A + 2) >> 2); - PredArray[17] = (imgpel) ((P_A + P_C + 2*P_B + 2) >> 2); - PredArray[18] = (imgpel) ((P_B + P_D + 2*P_C + 2) >> 2); - PredArray[19] = (imgpel) ((P_C + P_E + 2*P_D + 2) >> 2); - PredArray[20] = (imgpel) ((P_D + P_F + 2*P_E + 2) >> 2); - PredArray[21] = (imgpel) ((P_E + P_G + 2*P_F + 2) >> 2); + PredArray[0] = (imgpel)((P_X + P_W + 1) >> 1); + PredArray[1] = (imgpel)((P_V + P_X + 2 * P_W + 2) >> 2); + PredArray[2] = (imgpel)((P_W + P_V + 1) >> 1); + PredArray[3] = (imgpel)((P_U + P_W + 2 * P_V + 2) >> 2); + PredArray[4] = (imgpel)((P_V + P_U + 1) >> 1); + PredArray[5] = (imgpel)((P_T + P_V + 2 * P_U + 2) >> 2); + PredArray[6] = (imgpel)((P_U + P_T + 1) >> 1); + PredArray[7] = (imgpel)((P_S + P_U + 2 * P_T + 2) >> 2); + PredArray[8] = (imgpel)((P_T + P_S + 1) >> 1); + PredArray[9] = (imgpel)((P_R + P_T + 2 * P_S + 2) >> 2); + PredArray[10] = (imgpel)((P_S + P_R + 1) >> 1); + PredArray[11] = (imgpel)((P_Q + P_S + 2 * P_R + 2) >> 2); + PredArray[12] = (imgpel)((P_R + P_Q + 1) >> 1); + PredArray[13] = (imgpel)((P_Z + P_R + 2 * P_Q + 2) >> 2); + PredArray[14] = (imgpel)((P_Q + P_Z + 1) >> 1); + PredArray[15] = (imgpel)((P_Q + P_A + 2 * P_Z + 2) >> 2); + PredArray[16] = (imgpel)((P_Z + P_B + 2 * P_A + 2) >> 2); + PredArray[17] = (imgpel)((P_A + P_C + 2 * P_B + 2) >> 2); + PredArray[18] = (imgpel)((P_B + P_D + 2 * P_C + 2) >> 2); + PredArray[19] = (imgpel)((P_C + P_E + 2 * P_D + 2) >> 2); + PredArray[20] = (imgpel)((P_D + P_F + 2 * P_E + 2) >> 2); + PredArray[21] = (imgpel)((P_E + P_G + 2 * P_F + 2) >> 2); memcpy(&mpr[jpos0][ioff], &PredArray[14], 8 * sizeof(imgpel)); memcpy(&mpr[jpos1][ioff], &PredArray[12], 8 * sizeof(imgpel)); memcpy(&mpr[jpos2][ioff], &PredArray[10], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos3][ioff], &PredArray[ 8], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos4][ioff], &PredArray[ 6], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos5][ioff], &PredArray[ 4], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos6][ioff], &PredArray[ 2], 8 * sizeof(imgpel)); - memcpy(&mpr[jpos7][ioff], &PredArray[ 0], 8 * sizeof(imgpel)); - + memcpy(&mpr[jpos3][ioff], &PredArray[8], 8 * sizeof(imgpel)); + memcpy(&mpr[jpos4][ioff], &PredArray[6], 8 * sizeof(imgpel)); + memcpy(&mpr[jpos5][ioff], &PredArray[4], 8 * sizeof(imgpel)); + memcpy(&mpr[jpos6][ioff], &PredArray[2], 8 * sizeof(imgpel)); + memcpy(&mpr[jpos7][ioff], &PredArray[0], 8 * sizeof(imgpel)); + return DECODING_OK; } @@ -1568,20 +1524,19 @@ static inline int intra8x8_hor_down_pred(Macroblock *currMB, //!< current mac * ************************************************************************ */ -int intrapred8x8_normal(Macroblock *currMB, //!< Current Macroblock - ColorPlane pl, //!< Current color plane - int ioff, //!< ioff - int joff) //!< joff +int intrapred8x8_normal(Macroblock *currMB, //!< Current Macroblock + ColorPlane pl, //!< Current color plane + int ioff, //!< ioff + int joff) //!< joff -{ +{ int block_x = (currMB->block_x) + (ioff >> 2); int block_y = (currMB->block_y) + (joff >> 2); byte predmode = currMB->p_Slice->ipredmode[block_y][block_x]; - currMB->ipmode_DPCM = predmode; //For residual DPCM + currMB->ipmode_DPCM = predmode; // For residual DPCM - switch (predmode) - { + switch (predmode) { case DC_PRED: return (intra8x8_dc_pred(currMB, pl, ioff, joff)); break; @@ -1606,13 +1561,11 @@ int intrapred8x8_normal(Macroblock *currMB, //!< Current Macroblock case HOR_UP_PRED: return (intra8x8_hor_up_pred(currMB, pl, ioff, joff)); break; - case HOR_DOWN_PRED: + case HOR_DOWN_PRED: return (intra8x8_hor_down_pred(currMB, pl, ioff, joff)); default: - printf("Error: illegal intra_8x8 prediction mode: %d\n", (int) predmode); + printf("Error: illegal intra_8x8 prediction mode: %d\n", (int)predmode); return SEARCH_SYNC; break; } } - - diff --git a/src/common/ldecod_src/intra_chroma_pred.c b/src/common/ldecod_src/intra_chroma_pred.c index 0afca31..4bdc9b1 100644 --- a/src/common/ldecod_src/intra_chroma_pred.c +++ b/src/common/ldecod_src/intra_chroma_pred.c @@ -6,44 +6,42 @@ * Functions for intra chroma prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * ************************************************************************************* */ -#include "global.h" #include "block.h" -#include "mb_access.h" +#include "global.h" #include "image.h" +#include "mb_access.h" -static void intra_chroma_DC_single_mbaff(imgpel **curr_img, int up_avail, int left_avail, PixelPos up, PixelPos left[17], int blk_x, int blk_y, int *pred, int direction ) -{ +static void intra_chroma_DC_single_mbaff(imgpel **curr_img, int up_avail, + int left_avail, PixelPos up, + PixelPos left[17], int blk_x, + int blk_y, int *pred, int direction) { int i; int s0 = 0; - if ((direction && up_avail) || (!left_avail && up_avail)) - { - for (i = blk_x; i < (blk_x + 4);++i) + if ((direction && up_avail) || (!left_avail && up_avail)) { + for (i = blk_x; i < (blk_x + 4); ++i) s0 += curr_img[up.pos_y][up.pos_x + i]; *pred = (s0 + 2) >> 2; - } - else if (left_avail) - { - for (i = blk_y; i < (blk_y + 4);++i) + } else if (left_avail) { + for (i = blk_y; i < (blk_y + 4); ++i) s0 += curr_img[left[i].pos_y][left[i].pos_x]; *pred = (s0 + 2) >> 2; } } -void intrapred_chroma_ver_mbaff(Macroblock *currMB) -{ +void intrapred_chroma_ver_mbaff(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int j; StorablePicture *dec_picture = currSlice->dec_picture; - PixelPos up; //!< pixel position p(0,-1) + PixelPos up; //!< pixel position p(0,-1) int up_avail; int cr_MB_x = p_Vid->mb_cr_size_x; int cr_MB_y = p_Vid->mb_cr_size_y; @@ -51,39 +49,38 @@ void intrapred_chroma_ver_mbaff(Macroblock *currMB) getAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); if (!p_Vid->active_pps->constrained_intra_pred_flag) - up_avail = up.available; + up_avail = up.available; else up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; // Vertical Prediction if (!up_avail) - error("unexpected VERT_PRED_8 chroma intra prediction mode",-1); - else - { + error("unexpected VERT_PRED_8 chroma intra prediction mode", -1); + else { imgpel **mb_pred0 = currSlice->mb_pred[1]; imgpel **mb_pred1 = currSlice->mb_pred[2]; imgpel *i0 = &(dec_picture->imgUV[0][up.pos_y][up.pos_x]); imgpel *i1 = &(dec_picture->imgUV[1][up.pos_y][up.pos_x]); - for (j = 0; j < cr_MB_y; ++j) - { - memcpy(&(mb_pred0[j][0]),i0, cr_MB_x * sizeof(imgpel)); - memcpy(&(mb_pred1[j][0]),i1, cr_MB_x * sizeof(imgpel)); + for (j = 0; j < cr_MB_y; ++j) { + memcpy(&(mb_pred0[j][0]), i0, cr_MB_x * sizeof(imgpel)); + memcpy(&(mb_pred1[j][0]), i1, cr_MB_x * sizeof(imgpel)); } } } - -static void intra_chroma_DC_all_mbaff(imgpel **curr_img, int up_avail, int left_avail, PixelPos up, PixelPos left[17], int blk_x, int blk_y, int *pred ) -{ +static void intra_chroma_DC_all_mbaff(imgpel **curr_img, int up_avail, + int left_avail, PixelPos up, + PixelPos left[17], int blk_x, int blk_y, + int *pred) { int i; int s0 = 0, s1 = 0; - if (up_avail) - for (i = blk_x; i < (blk_x + 4);++i) + if (up_avail) + for (i = blk_x; i < (blk_x + 4); ++i) s0 += curr_img[up.pos_y][up.pos_x + i]; - if (left_avail) - for (i = blk_y; i < (blk_y + 4);++i) + if (left_avail) + for (i = blk_y; i < (blk_y + 4); ++i) s1 += curr_img[left[i].pos_y][left[i].pos_x]; if (up_avail && left_avail) @@ -94,46 +91,43 @@ static void intra_chroma_DC_all_mbaff(imgpel **curr_img, int up_avail, int left_ *pred = (s1 + 2) >> 2; } -static void intra_chroma_DC_single(imgpel **curr_img, int up_avail, int left_avail, PixelPos up, PixelPos left, int blk_x, int blk_y, int *pred, int direction ) -{ +static void intra_chroma_DC_single(imgpel **curr_img, int up_avail, + int left_avail, PixelPos up, PixelPos left, + int blk_x, int blk_y, int *pred, + int direction) { int i; int s0 = 0; - if ((direction && up_avail) || (!left_avail && up_avail)) - { + if ((direction && up_avail) || (!left_avail && up_avail)) { imgpel *cur_pel = &curr_img[up.pos_y][up.pos_x + blk_x]; - for (i = 0; i < 4;++i) + for (i = 0; i < 4; ++i) s0 += *(cur_pel++); *pred = (s0 + 2) >> 2; - } - else if (left_avail) - { + } else if (left_avail) { imgpel **cur_pel = &(curr_img[left.pos_y + blk_y - 1]); int pos_x = left.pos_x; - for (i = 0; i < 4;++i) + for (i = 0; i < 4; ++i) s0 += *((*cur_pel++) + pos_x); *pred = (s0 + 2) >> 2; } } - -static void intra_chroma_DC_all(imgpel **curr_img, int up_avail, int left_avail, PixelPos up, PixelPos left, int blk_x, int blk_y, int *pred ) -{ +static void intra_chroma_DC_all(imgpel **curr_img, int up_avail, int left_avail, + PixelPos up, PixelPos left, int blk_x, + int blk_y, int *pred) { int i; int s0 = 0, s1 = 0; - if (up_avail) - { + if (up_avail) { imgpel *cur_pel = &curr_img[up.pos_y][up.pos_x + blk_x]; - for (i = 0; i < 4;++i) + for (i = 0; i < 4; ++i) s0 += *(cur_pel++); } - if (left_avail) - { + if (left_avail) { imgpel **cur_pel = &(curr_img[left.pos_y + blk_y - 1]); int pos_x = left.pos_x; - for (i = 0; i < 4;++i) + for (i = 0; i < 4; ++i) s1 += *((*cur_pel++) + pos_x); } @@ -145,116 +139,111 @@ static void intra_chroma_DC_all(imgpel **curr_img, int up_avail, int left_avail, *pred = (s1 + 2) >> 2; } -static void intrapred_chroma_dc(Macroblock *currMB) -{ +static void intrapred_chroma_dc(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int ii, jj; StorablePicture *dec_picture = currSlice->dec_picture; - int b8, b4; - int yuv = dec_picture->chroma_format_idc - 1; - int blk_x, blk_y; - int pred, pred1; - static const int block_pos[3][4][4]= //[yuv][b8][b4] - { - { {0, 1, 2, 3},{0, 0, 0, 0},{0, 0, 0, 0},{0, 0, 0, 0}}, - { {0, 1, 2, 3},{2, 3, 2, 3},{0, 0, 0, 0},{0, 0, 0, 0}}, - { {0, 1, 2, 3},{1, 1, 3, 3},{2, 3, 2, 3},{3, 3, 3, 3}} - }; + int b8, b4; + int yuv = dec_picture->chroma_format_idc - 1; + int blk_x, blk_y; + int pred, pred1; + static const int block_pos[3][4][4] = //[yuv][b8][b4] + {{{0, 1, 2, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 1, 2, 3}, {2, 3, 2, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 1, 2, 3}, {1, 1, 3, 3}, {2, 3, 2, 3}, {3, 3, 3, 3}}}; - PixelPos up; //!< pixel position p(0,-1) + PixelPos up; //!< pixel position p(0,-1) PixelPos up_left; - PixelPos left; //!< pixel positions p(-1, -1..16) + PixelPos left; //!< pixel positions p(-1, -1..16) int up_avail, left_avail, left_up_avail; imgpel **imgUV0 = dec_picture->imgUV[0]; imgpel **imgUV1 = dec_picture->imgUV[1]; imgpel **mb_pred0 = currSlice->mb_pred[0 + 1]; imgpel **mb_pred1 = currSlice->mb_pred[1 + 1]; - getNonAffNeighbour(currMB, -1, -1, p_Vid->mb_size[IS_CHROMA], &up_left); - getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_CHROMA], &left); + getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_CHROMA], &left); getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - up_avail = up.available; - left_avail = left.available; + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + up_avail = up.available; + left_avail = left.available; left_up_avail = up_left.available; - } - else - { + } else { up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; - left_avail = left.available ? currSlice->intra_block[left.mb_addr]: 0; - left_up_avail = up_left.available ? currSlice->intra_block[up_left.mb_addr]: 0; + left_avail = left.available ? currSlice->intra_block[left.mb_addr] : 0; + left_up_avail = + up_left.available ? currSlice->intra_block[up_left.mb_addr] : 0; } // DC prediction - // Note that unlike what is stated in many presentations and papers, this mode does not operate - // the same way as I_16x16 DC prediction. - for(b8 = 0; b8 < (p_Vid->num_uv_blocks) ;++b8) - { - for (b4 = 0; b4 < 4; ++b4) - { + // Note that unlike what is stated in many presentations and papers, this mode + // does not operate the same way as I_16x16 DC prediction. + for (b8 = 0; b8 < (p_Vid->num_uv_blocks); ++b8) { + for (b4 = 0; b4 < 4; ++b4) { blk_y = subblk_offset_y[yuv][b8][b4]; blk_x = subblk_offset_x[yuv][b8][b4]; - pred = p_Vid->dc_pred_value_comp[1]; + pred = p_Vid->dc_pred_value_comp[1]; pred1 = p_Vid->dc_pred_value_comp[2]; //===== get prediction value ===== - switch (block_pos[yuv][b8][b4]) - { - case 0: //===== TOP LEFT ===== - intra_chroma_DC_all (imgUV0, up_avail, left_avail, up, left, blk_x, blk_y + 1, &pred); - intra_chroma_DC_all (imgUV1, up_avail, left_avail, up, left, blk_x, blk_y + 1, &pred1); + switch (block_pos[yuv][b8][b4]) { + case 0: //===== TOP LEFT ===== + intra_chroma_DC_all(imgUV0, up_avail, left_avail, up, left, blk_x, + blk_y + 1, &pred); + intra_chroma_DC_all(imgUV1, up_avail, left_avail, up, left, blk_x, + blk_y + 1, &pred1); break; case 1: //===== TOP RIGHT ===== - intra_chroma_DC_single(imgUV0, up_avail, left_avail, up, left, blk_x, blk_y + 1, &pred, 1); - intra_chroma_DC_single(imgUV1, up_avail, left_avail, up, left, blk_x, blk_y + 1, &pred1, 1); + intra_chroma_DC_single(imgUV0, up_avail, left_avail, up, left, blk_x, + blk_y + 1, &pred, 1); + intra_chroma_DC_single(imgUV1, up_avail, left_avail, up, left, blk_x, + blk_y + 1, &pred1, 1); break; case 2: //===== BOTTOM LEFT ===== - intra_chroma_DC_single(imgUV0, up_avail, left_avail, up, left, blk_x, blk_y + 1, &pred, 0); - intra_chroma_DC_single(imgUV1, up_avail, left_avail, up, left, blk_x, blk_y + 1, &pred1, 0); + intra_chroma_DC_single(imgUV0, up_avail, left_avail, up, left, blk_x, + blk_y + 1, &pred, 0); + intra_chroma_DC_single(imgUV1, up_avail, left_avail, up, left, blk_x, + blk_y + 1, &pred1, 0); break; case 3: //===== BOTTOM RIGHT ===== - intra_chroma_DC_all (imgUV0, up_avail, left_avail, up, left, blk_x, blk_y + 1, &pred); - intra_chroma_DC_all (imgUV1, up_avail, left_avail, up, left, blk_x, blk_y + 1, &pred1); + intra_chroma_DC_all(imgUV0, up_avail, left_avail, up, left, blk_x, + blk_y + 1, &pred); + intra_chroma_DC_all(imgUV1, up_avail, left_avail, up, left, blk_x, + blk_y + 1, &pred1); break; } - for (jj = blk_y; jj < blk_y + BLOCK_SIZE; ++jj) - { - for (ii = blk_x; ii < blk_x + BLOCK_SIZE; ++ii) - { - mb_pred0[jj][ii]=(imgpel) pred; - mb_pred1[jj][ii]=(imgpel) pred1; + for (jj = blk_y; jj < blk_y + BLOCK_SIZE; ++jj) { + for (ii = blk_x; ii < blk_x + BLOCK_SIZE; ++ii) { + mb_pred0[jj][ii] = (imgpel)pred; + mb_pred1[jj][ii] = (imgpel)pred1; } } } } } -static void intrapred_chroma_hor(Macroblock *currMB) -{ - VideoParameters *p_Vid = currMB->p_Vid; - PixelPos a; //!< pixel positions p(-1, -1..16) +static void intrapred_chroma_hor(Macroblock *currMB) { + VideoParameters *p_Vid = currMB->p_Vid; + PixelPos a; //!< pixel positions p(-1, -1..16) int left_avail; - + getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_CHROMA], &a); - + if (!p_Vid->active_pps->constrained_intra_pred_flag) left_avail = a.available; else - left_avail = a.available ? currMB->p_Slice->intra_block[a.mb_addr]: 0; + left_avail = a.available ? currMB->p_Slice->intra_block[a.mb_addr] : 0; // Horizontal Prediction - if (!left_avail ) - error("unexpected HOR_PRED_8 chroma intra prediction mode",-1); - else - { + if (!left_avail) + error("unexpected HOR_PRED_8 chroma intra prediction mode", -1); + else { Slice *currSlice = currMB->p_Slice; int cr_MB_x = p_Vid->mb_cr_size_x; int cr_MB_y = p_Vid->mb_cr_size_y; - int i,j; + int i, j; StorablePicture *dec_picture = currSlice->dec_picture; int pred, pred1; int pos_y = a.pos_y; @@ -263,128 +252,120 @@ static void intrapred_chroma_hor(Macroblock *currMB) imgpel **mb_pred1 = currSlice->mb_pred[1 + 1]; imgpel **i0 = dec_picture->imgUV[0]; imgpel **i1 = dec_picture->imgUV[1]; - for (j = 0; j < cr_MB_y; ++j) - { + for (j = 0; j < cr_MB_y; ++j) { pred = i0[pos_y][pos_x]; pred1 = i1[pos_y++][pos_x]; - for (i = 0; i < cr_MB_x; ++i) - { - mb_pred0[j][i]=(imgpel) pred; - mb_pred1[j][i]=(imgpel) pred1; + for (i = 0; i < cr_MB_x; ++i) { + mb_pred0[j][i] = (imgpel)pred; + mb_pred1[j][i] = (imgpel)pred1; } } } } -static void intrapred_chroma_ver(Macroblock *currMB) -{ +static void intrapred_chroma_ver(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int j; StorablePicture *dec_picture = currSlice->dec_picture; - PixelPos up; //!< pixel position p(0,-1) + PixelPos up; //!< pixel position p(0,-1) int up_avail; int cr_MB_x = p_Vid->mb_cr_size_x; int cr_MB_y = p_Vid->mb_cr_size_y; getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); if (!p_Vid->active_pps->constrained_intra_pred_flag) - up_avail = up.available; + up_avail = up.available; else up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; // Vertical Prediction if (!up_avail) - error("unexpected VERT_PRED_8 chroma intra prediction mode",-1); - else - { + error("unexpected VERT_PRED_8 chroma intra prediction mode", -1); + else { imgpel **mb_pred0 = currSlice->mb_pred[1]; imgpel **mb_pred1 = currSlice->mb_pred[2]; imgpel *i0 = &(dec_picture->imgUV[0][up.pos_y][up.pos_x]); imgpel *i1 = &(dec_picture->imgUV[1][up.pos_y][up.pos_x]); - for (j = 0; j < cr_MB_y; ++j) - { - memcpy(&(mb_pred0[j][0]),i0, cr_MB_x * sizeof(imgpel)); - memcpy(&(mb_pred1[j][0]),i1, cr_MB_x * sizeof(imgpel)); + for (j = 0; j < cr_MB_y; ++j) { + memcpy(&(mb_pred0[j][0]), i0, cr_MB_x * sizeof(imgpel)); + memcpy(&(mb_pred1[j][0]), i1, cr_MB_x * sizeof(imgpel)); } } } -static void intrapred_chroma_plane(Macroblock *currMB) -{ +static void intrapred_chroma_plane(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; - PixelPos up; //!< pixel position p(0,-1) + PixelPos up; //!< pixel position p(0,-1) PixelPos up_left; - PixelPos left; //!< pixel positions p(-1, -1..16) + PixelPos left; //!< pixel positions p(-1, -1..16) int up_avail, left_avail, left_up_avail; getNonAffNeighbour(currMB, -1, -1, p_Vid->mb_size[IS_CHROMA], &up_left); - getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_CHROMA], &left); + getNonAffNeighbour(currMB, -1, 0, p_Vid->mb_size[IS_CHROMA], &left); getNonAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - up_avail = up.available; - left_avail = left.available; + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + up_avail = up.available; + left_avail = left.available; left_up_avail = up_left.available; - } - else - { - up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; - left_avail = left.available ? currSlice->intra_block[left.mb_addr]: 0; - left_up_avail = up_left.available ? currSlice->intra_block[up_left.mb_addr]: 0; + } else { + up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; + left_avail = left.available ? currSlice->intra_block[left.mb_addr] : 0; + left_up_avail = + up_left.available ? currSlice->intra_block[up_left.mb_addr] : 0; } // plane prediction if (!left_up_avail || !left_avail || !up_avail) - error("unexpected PLANE_8 chroma intra prediction mode",-1); - else - { + error("unexpected PLANE_8 chroma intra prediction mode", -1); + else { int cr_MB_x = p_Vid->mb_cr_size_x; int cr_MB_y = p_Vid->mb_cr_size_y; int cr_MB_y2 = (cr_MB_y >> 1); int cr_MB_x2 = (cr_MB_x >> 1); - int i,j; + int i, j; int ih, iv, ib, ic, iaa; int uv; - for (uv = 0; uv < 2; uv++) - { + for (uv = 0; uv < 2; uv++) { imgpel **imgUV = dec_picture->imgUV[uv]; imgpel **mb_pred = currSlice->mb_pred[uv + 1]; int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; imgpel *upPred = &imgUV[up.pos_y][up.pos_x]; - int pos_x = up_left.pos_x; + int pos_x = up_left.pos_x; int pos_y1 = left.pos_y + cr_MB_y2; int pos_y2 = pos_y1 - 2; - //imgpel **predU1 = &imgUV[pos_y1]; + // imgpel **predU1 = &imgUV[pos_y1]; imgpel **predU2 = &imgUV[pos_y2]; ih = cr_MB_x2 * (upPred[cr_MB_x - 1] - imgUV[up_left.pos_y][pos_x]); for (i = 0; i < cr_MB_x2 - 1; ++i) ih += (i + 1) * (upPred[cr_MB_x2 + i] - upPred[cr_MB_x2 - 2 - i]); - iv = cr_MB_y2 * (imgUV[left.pos_y + cr_MB_y - 1][pos_x] - imgUV[up_left.pos_y][pos_x]); - - for (i = 0; i < cr_MB_y2 - 1; ++i) - { - iv += (i + 1)*(*(imgUV[pos_y1++] + pos_x) - *((*predU2--) + pos_x)); + iv = cr_MB_y2 * (imgUV[left.pos_y + cr_MB_y - 1][pos_x] - + imgUV[up_left.pos_y][pos_x]); + + for (i = 0; i < cr_MB_y2 - 1; ++i) { + iv += (i + 1) * (*(imgUV[pos_y1++] + pos_x) - *((*predU2--) + pos_x)); } - ib= ((cr_MB_x == 8 ? 17 : 5) * ih + 2 * cr_MB_x)>>(cr_MB_x == 8 ? 5 : 6); - ic= ((cr_MB_y == 8 ? 17 : 5) * iv + 2 * cr_MB_y)>>(cr_MB_y == 8 ? 5 : 6); + ib = ((cr_MB_x == 8 ? 17 : 5) * ih + 2 * cr_MB_x) >> + (cr_MB_x == 8 ? 5 : 6); + ic = ((cr_MB_y == 8 ? 17 : 5) * iv + 2 * cr_MB_y) >> + (cr_MB_y == 8 ? 5 : 6); - iaa = ((imgUV[pos_y1][pos_x] + upPred[cr_MB_x-1]) << 4); + iaa = ((imgUV[pos_y1][pos_x] + upPred[cr_MB_x - 1]) << 4); - for (j = 0; j < cr_MB_y; ++j) - { + for (j = 0; j < cr_MB_y; ++j) { int plane = iaa + (j - cr_MB_y2 + 1) * ic + 16 - (cr_MB_x2 - 1) * ib; for (i = 0; i < cr_MB_x; ++i) - mb_pred[j][i]=(imgpel) iClip1(max_imgpel_value, ((i * ib + plane) >> 5)); + mb_pred[j][i] = + (imgpel)iClip1(max_imgpel_value, ((i * ib + plane) >> 5)); } } } @@ -397,20 +378,18 @@ static void intrapred_chroma_plane(Macroblock *currMB) * outside since they are repeated for both components for no reason. ************************************************************************ */ -void intrapred_chroma(Macroblock *currMB) -{ - switch (currMB->c_ipred_mode) - { - case DC_PRED_8: +void intrapred_chroma(Macroblock *currMB) { + switch (currMB->c_ipred_mode) { + case DC_PRED_8: intrapred_chroma_dc(currMB); break; - case HOR_PRED_8: + case HOR_PRED_8: intrapred_chroma_hor(currMB); break; - case VERT_PRED_8: + case VERT_PRED_8: intrapred_chroma_ver(currMB); break; - case PLANE_8: + case PLANE_8: intrapred_chroma_plane(currMB); break; default: @@ -426,261 +405,262 @@ void intrapred_chroma(Macroblock *currMB) * outside since they are repeated for both components for no reason. ************************************************************************ */ -void intrapred_chroma_mbaff(Macroblock *currMB) -{ +void intrapred_chroma_mbaff(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - int i,j, ii, jj; + int i, j, ii, jj; StorablePicture *dec_picture = currSlice->dec_picture; int ih, iv, ib, ic, iaa; - int b8, b4; - int yuv = dec_picture->chroma_format_idc - 1; - int blk_x, blk_y; - int pred; - static const int block_pos[3][4][4]= //[yuv][b8][b4] - { - { {0, 1, 2, 3},{0, 0, 0, 0},{0, 0, 0, 0},{0, 0, 0, 0}}, - { {0, 1, 2, 3},{2, 3, 2, 3},{0, 0, 0, 0},{0, 0, 0, 0}}, - { {0, 1, 2, 3},{1, 1, 3, 3},{2, 3, 2, 3},{3, 3, 3, 3}} - }; + int b8, b4; + int yuv = dec_picture->chroma_format_idc - 1; + int blk_x, blk_y; + int pred; + static const int block_pos[3][4][4] = //[yuv][b8][b4] + {{{0, 1, 2, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 1, 2, 3}, {2, 3, 2, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 1, 2, 3}, {1, 1, 3, 3}, {2, 3, 2, 3}, {3, 3, 3, 3}}}; - switch (currMB->c_ipred_mode) - { - case DC_PRED_8: + switch (currMB->c_ipred_mode) { + case DC_PRED_8: { + PixelPos up; //!< pixel position p(0,-1) + PixelPos left[17]; //!< pixel positions p(-1, -1..16) + + int up_avail, left_avail[2], left_up_avail; + + int cr_MB_y = p_Vid->mb_cr_size_y; + int cr_MB_y2 = (cr_MB_y >> 1); + + for (i = 0; i < cr_MB_y + 1; ++i) + getAffNeighbour(currMB, -1, i - 1, p_Vid->mb_size[IS_CHROMA], &left[i]); + getAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); + + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + up_avail = up.available; + left_avail[0] = left_avail[1] = left[1].available; + left_up_avail = left[0].available; + } else { + up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; + for (i = 0, left_avail[0] = 1; i < cr_MB_y2; ++i) + left_avail[0] &= left[i + 1].available + ? currSlice->intra_block[left[i + 1].mb_addr] + : 0; + + for (i = cr_MB_y2, left_avail[1] = 1; i < cr_MB_y; ++i) + left_avail[1] &= left[i + 1].available + ? currSlice->intra_block[left[i + 1].mb_addr] + : 0; + + left_up_avail = + left[0].available ? currSlice->intra_block[left[0].mb_addr] : 0; + } + // DC prediction + // Note that unlike what is stated in many presentations and papers, this + // mode does not operate the same way as I_16x16 DC prediction. { - PixelPos up; //!< pixel position p(0,-1) - PixelPos left[17]; //!< pixel positions p(-1, -1..16) + int pred1; + imgpel **imgUV0 = dec_picture->imgUV[0]; + imgpel **imgUV1 = dec_picture->imgUV[1]; + imgpel **mb_pred0 = currSlice->mb_pred[0 + 1]; + imgpel **mb_pred1 = currSlice->mb_pred[1 + 1]; + for (b8 = 0; b8 < (p_Vid->num_uv_blocks); ++b8) { + for (b4 = 0; b4 < 4; ++b4) { + blk_y = subblk_offset_y[yuv][b8][b4]; + blk_x = subblk_offset_x[yuv][b8][b4]; - int up_avail, left_avail[2], left_up_avail; + pred = p_Vid->dc_pred_value_comp[1]; + pred1 = p_Vid->dc_pred_value_comp[2]; + //===== get prediction value ===== + switch (block_pos[yuv][b8][b4]) { + case 0: //===== TOP LEFT ===== + intra_chroma_DC_all_mbaff(imgUV0, up_avail, left_avail[0], up, left, + blk_x, blk_y + 1, &pred); + intra_chroma_DC_all_mbaff(imgUV1, up_avail, left_avail[0], up, left, + blk_x, blk_y + 1, &pred1); + break; + case 1: //===== TOP RIGHT ===== + intra_chroma_DC_single_mbaff(imgUV0, up_avail, left_avail[0], up, + left, blk_x, blk_y + 1, &pred, 1); + intra_chroma_DC_single_mbaff(imgUV1, up_avail, left_avail[0], up, + left, blk_x, blk_y + 1, &pred1, 1); + break; + case 2: //===== BOTTOM LEFT ===== + intra_chroma_DC_single_mbaff(imgUV0, up_avail, left_avail[1], up, + left, blk_x, blk_y + 1, &pred, 0); + intra_chroma_DC_single_mbaff(imgUV1, up_avail, left_avail[1], up, + left, blk_x, blk_y + 1, &pred1, 0); + break; + case 3: //===== BOTTOM RIGHT ===== + intra_chroma_DC_all_mbaff(imgUV0, up_avail, left_avail[1], up, left, + blk_x, blk_y + 1, &pred); + intra_chroma_DC_all_mbaff(imgUV1, up_avail, left_avail[1], up, left, + blk_x, blk_y + 1, &pred1); + break; + } - int cr_MB_y = p_Vid->mb_cr_size_y; - int cr_MB_y2 = (cr_MB_y >> 1); - - for (i=0; i < cr_MB_y + 1 ; ++i) - getAffNeighbour(currMB, -1, i-1, p_Vid->mb_size[IS_CHROMA], &left[i]); - getAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); - - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - up_avail = up.available; - left_avail[0] = left_avail[1] = left[1].available; - left_up_avail = left[0].available; - } - else - { - up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; - for (i=0, left_avail[0] = 1; i < cr_MB_y2;++i) - left_avail[0] &= left[i + 1].available ? currSlice->intra_block[left[i + 1].mb_addr]: 0; - - for (i = cr_MB_y2, left_avail[1] = 1; iintra_block[left[i + 1].mb_addr]: 0; - - left_up_avail = left[0].available ? currSlice->intra_block[left[0].mb_addr]: 0; - } - // DC prediction - // Note that unlike what is stated in many presentations and papers, this mode does not operate - // the same way as I_16x16 DC prediction. - { - int pred1; - imgpel **imgUV0 = dec_picture->imgUV[0]; - imgpel **imgUV1 = dec_picture->imgUV[1]; - imgpel **mb_pred0 = currSlice->mb_pred[0 + 1]; - imgpel **mb_pred1 = currSlice->mb_pred[1 + 1]; - for(b8 = 0; b8 < (p_Vid->num_uv_blocks) ;++b8) - { - for (b4 = 0; b4 < 4; ++b4) - { - blk_y = subblk_offset_y[yuv][b8][b4]; - blk_x = subblk_offset_x[yuv][b8][b4]; - - pred = p_Vid->dc_pred_value_comp[1]; - pred1 = p_Vid->dc_pred_value_comp[2]; - //===== get prediction value ===== - switch (block_pos[yuv][b8][b4]) - { - case 0: //===== TOP LEFT ===== - intra_chroma_DC_all_mbaff (imgUV0, up_avail, left_avail[0], up, left, blk_x, blk_y + 1, &pred); - intra_chroma_DC_all_mbaff (imgUV1, up_avail, left_avail[0], up, left, blk_x, blk_y + 1, &pred1); - break; - case 1: //===== TOP RIGHT ===== - intra_chroma_DC_single_mbaff (imgUV0, up_avail, left_avail[0], up, left, blk_x, blk_y + 1, &pred, 1); - intra_chroma_DC_single_mbaff (imgUV1, up_avail, left_avail[0], up, left, blk_x, blk_y + 1, &pred1, 1); - break; - case 2: //===== BOTTOM LEFT ===== - intra_chroma_DC_single_mbaff (imgUV0, up_avail, left_avail[1], up, left, blk_x, blk_y + 1, &pred, 0); - intra_chroma_DC_single_mbaff (imgUV1, up_avail, left_avail[1], up, left, blk_x, blk_y + 1, &pred1, 0); - break; - case 3: //===== BOTTOM RIGHT ===== - intra_chroma_DC_all_mbaff (imgUV0, up_avail, left_avail[1], up, left, blk_x, blk_y + 1, &pred); - intra_chroma_DC_all_mbaff (imgUV1, up_avail, left_avail[1], up, left, blk_x, blk_y + 1, &pred1); - break; - } - - for (jj = blk_y; jj < blk_y + BLOCK_SIZE; ++jj) - { - for (ii = blk_x; ii < blk_x + BLOCK_SIZE; ++ii) - { - mb_pred0[jj][ii]=(imgpel) pred; - mb_pred1[jj][ii]=(imgpel) pred1; - } + for (jj = blk_y; jj < blk_y + BLOCK_SIZE; ++jj) { + for (ii = blk_x; ii < blk_x + BLOCK_SIZE; ++ii) { + mb_pred0[jj][ii] = (imgpel)pred; + mb_pred1[jj][ii] = (imgpel)pred1; } } } } } - break; - case HOR_PRED_8: - { - PixelPos left[17]; //!< pixel positions p(-1, -1..16) + } break; + case HOR_PRED_8: { + PixelPos left[17]; //!< pixel positions p(-1, -1..16) - int left_avail[2], left_up_avail; + int left_avail[2], left_up_avail; - int cr_MB_x = p_Vid->mb_cr_size_x; - int cr_MB_y = p_Vid->mb_cr_size_y; - int cr_MB_y2 = (cr_MB_y >> 1); + int cr_MB_x = p_Vid->mb_cr_size_x; + int cr_MB_y = p_Vid->mb_cr_size_y; + int cr_MB_y2 = (cr_MB_y >> 1); - for (i=0; i < cr_MB_y + 1 ; ++i) - getAffNeighbour(currMB, -1, i-1, p_Vid->mb_size[IS_CHROMA], &left[i]); + for (i = 0; i < cr_MB_y + 1; ++i) + getAffNeighbour(currMB, -1, i - 1, p_Vid->mb_size[IS_CHROMA], &left[i]); - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - left_avail[0] = left_avail[1] = left[1].available; - left_up_avail = left[0].available; + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + left_avail[0] = left_avail[1] = left[1].available; + left_up_avail = left[0].available; + } else { + for (i = 0, left_avail[0] = 1; i < cr_MB_y2; ++i) + left_avail[0] &= left[i + 1].available + ? currSlice->intra_block[left[i + 1].mb_addr] + : 0; + + for (i = cr_MB_y2, left_avail[1] = 1; i < cr_MB_y; ++i) + left_avail[1] &= left[i + 1].available + ? currSlice->intra_block[left[i + 1].mb_addr] + : 0; + + left_up_avail = + left[0].available ? currSlice->intra_block[left[0].mb_addr] : 0; + } + // Horizontal Prediction + if (!left_avail[0] || !left_avail[1]) + error("unexpected HOR_PRED_8 chroma intra prediction mode", -1); + else { + int pred1; + imgpel **mb_pred0 = currSlice->mb_pred[0 + 1]; + imgpel **mb_pred1 = currSlice->mb_pred[1 + 1]; + imgpel **i0 = dec_picture->imgUV[0]; + imgpel **i1 = dec_picture->imgUV[1]; + for (j = 0; j < cr_MB_y; ++j) { + pred = i0[left[1 + j].pos_y][left[1 + j].pos_x]; + pred1 = i1[left[1 + j].pos_y][left[1 + j].pos_x]; + for (i = 0; i < cr_MB_x; ++i) { + mb_pred0[j][i] = (imgpel)pred; + mb_pred1[j][i] = (imgpel)pred1; + } } - else - { - for (i=0, left_avail[0] = 1; i < cr_MB_y2;++i) - left_avail[0] &= left[i + 1].available ? currSlice->intra_block[left[i + 1].mb_addr]: 0; + } + } break; + case VERT_PRED_8: { + PixelPos up; //!< pixel position p(0,-1) - for (i = cr_MB_y2, left_avail[1] = 1; iintra_block[left[i + 1].mb_addr]: 0; + int up_avail; - left_up_avail = left[0].available ? currSlice->intra_block[left[0].mb_addr]: 0; + int cr_MB_x = p_Vid->mb_cr_size_x; + int cr_MB_y = p_Vid->mb_cr_size_y; + + getAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); + + if (!p_Vid->active_pps->constrained_intra_pred_flag) + up_avail = up.available; + else + up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; + // Vertical Prediction + if (!up_avail) + error("unexpected VERT_PRED_8 chroma intra prediction mode", -1); + else { + imgpel **mb_pred0 = currSlice->mb_pred[0 + 1]; + imgpel **mb_pred1 = currSlice->mb_pred[1 + 1]; + imgpel *i0 = &(dec_picture->imgUV[0][up.pos_y][up.pos_x]); + imgpel *i1 = &(dec_picture->imgUV[1][up.pos_y][up.pos_x]); + for (j = 0; j < cr_MB_y; ++j) { + memcpy(&(mb_pred0[j][0]), i0, cr_MB_x * sizeof(imgpel)); + memcpy(&(mb_pred1[j][0]), i1, cr_MB_x * sizeof(imgpel)); } - // Horizontal Prediction - if (!left_avail[0] || !left_avail[1]) - error("unexpected HOR_PRED_8 chroma intra prediction mode",-1); - else - { - int pred1; - imgpel **mb_pred0 = currSlice->mb_pred[0 + 1]; - imgpel **mb_pred1 = currSlice->mb_pred[1 + 1]; - imgpel **i0 = dec_picture->imgUV[0]; - imgpel **i1 = dec_picture->imgUV[1]; + } + } break; + case PLANE_8: { + PixelPos up; //!< pixel position p(0,-1) + PixelPos left[17]; //!< pixel positions p(-1, -1..16) + + int up_avail, left_avail[2], left_up_avail; + + int cr_MB_x = p_Vid->mb_cr_size_x; + int cr_MB_y = p_Vid->mb_cr_size_y; + int cr_MB_y2 = (cr_MB_y >> 1); + int cr_MB_x2 = (cr_MB_x >> 1); + + for (i = 0; i < cr_MB_y + 1; ++i) + p_Vid->getNeighbour(currMB, -1, i - 1, p_Vid->mb_size[IS_CHROMA], + &left[i]); + p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); + + if (!p_Vid->active_pps->constrained_intra_pred_flag) { + up_avail = up.available; + left_avail[0] = left_avail[1] = left[1].available; + left_up_avail = left[0].available; + } else { + up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; + for (i = 0, left_avail[0] = 1; i < cr_MB_y2; ++i) + left_avail[0] &= left[i + 1].available + ? currSlice->intra_block[left[i + 1].mb_addr] + : 0; + + for (i = cr_MB_y2, left_avail[1] = 1; i < cr_MB_y; ++i) + left_avail[1] &= left[i + 1].available + ? currSlice->intra_block[left[i + 1].mb_addr] + : 0; + + left_up_avail = + left[0].available ? currSlice->intra_block[left[0].mb_addr] : 0; + } + // plane prediction + if (!left_up_avail || !left_avail[0] || !left_avail[1] || !up_avail) + error("unexpected PLANE_8 chroma intra prediction mode", -1); + else { + int uv; + for (uv = 0; uv < 2; uv++) { + imgpel **imgUV = dec_picture->imgUV[uv]; + imgpel **mb_pred = currSlice->mb_pred[uv + 1]; + int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; + imgpel *upPred = &imgUV[up.pos_y][up.pos_x]; + + ih = cr_MB_x2 * + (upPred[cr_MB_x - 1] - imgUV[left[0].pos_y][left[0].pos_x]); + for (i = 0; i < cr_MB_x2 - 1; ++i) + ih += (i + 1) * (upPred[cr_MB_x2 + i] - upPred[cr_MB_x2 - 2 - i]); + + iv = cr_MB_y2 * (imgUV[left[cr_MB_y].pos_y][left[cr_MB_y].pos_x] - + imgUV[left[0].pos_y][left[0].pos_x]); + for (i = 0; i < cr_MB_y2 - 1; ++i) + iv += (i + 1) * (imgUV[left[cr_MB_y2 + 1 + i].pos_y] + [left[cr_MB_y2 + 1 + i].pos_x] - + imgUV[left[cr_MB_y2 - 1 - i].pos_y] + [left[cr_MB_y2 - 1 - i].pos_x]); + + ib = ((cr_MB_x == 8 ? 17 : 5) * ih + 2 * cr_MB_x) >> + (cr_MB_x == 8 ? 5 : 6); + ic = ((cr_MB_y == 8 ? 17 : 5) * iv + 2 * cr_MB_y) >> + (cr_MB_y == 8 ? 5 : 6); + + iaa = 16 * (imgUV[left[cr_MB_y].pos_y][left[cr_MB_y].pos_x] + + upPred[cr_MB_x - 1]); + for (j = 0; j < cr_MB_y; ++j) - { - pred = i0[left[1 + j].pos_y][left[1 + j].pos_x]; - pred1 = i1[left[1 + j].pos_y][left[1 + j].pos_x]; for (i = 0; i < cr_MB_x; ++i) - { - mb_pred0[j][i]=(imgpel) pred; - mb_pred1[j][i]=(imgpel) pred1; - } - } + mb_pred[j][i] = (imgpel)iClip1(max_imgpel_value, + ((iaa + (i - cr_MB_x2 + 1) * ib + + (j - cr_MB_y2 + 1) * ic + 16) >> + 5)); } } - break; - case VERT_PRED_8: - { - PixelPos up; //!< pixel position p(0,-1) - - int up_avail; - - int cr_MB_x = p_Vid->mb_cr_size_x; - int cr_MB_y = p_Vid->mb_cr_size_y; - - getAffNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); - - if (!p_Vid->active_pps->constrained_intra_pred_flag) - up_avail = up.available; - else - up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; - // Vertical Prediction - if (!up_avail) - error("unexpected VERT_PRED_8 chroma intra prediction mode",-1); - else - { - imgpel **mb_pred0 = currSlice->mb_pred[0 + 1]; - imgpel **mb_pred1 = currSlice->mb_pred[1 + 1]; - imgpel *i0 = &(dec_picture->imgUV[0][up.pos_y][up.pos_x]); - imgpel *i1 = &(dec_picture->imgUV[1][up.pos_y][up.pos_x]); - for (j = 0; j < cr_MB_y; ++j) - { - memcpy(&(mb_pred0[j][0]),i0, cr_MB_x * sizeof(imgpel)); - memcpy(&(mb_pred1[j][0]),i1, cr_MB_x * sizeof(imgpel)); - } - } - } - break; - case PLANE_8: - { - PixelPos up; //!< pixel position p(0,-1) - PixelPos left[17]; //!< pixel positions p(-1, -1..16) - - int up_avail, left_avail[2], left_up_avail; - - int cr_MB_x = p_Vid->mb_cr_size_x; - int cr_MB_y = p_Vid->mb_cr_size_y; - int cr_MB_y2 = (cr_MB_y >> 1); - int cr_MB_x2 = (cr_MB_x >> 1); - - for (i=0; i < cr_MB_y + 1 ; ++i) - p_Vid->getNeighbour(currMB, -1, i-1, p_Vid->mb_size[IS_CHROMA], &left[i]); - p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[IS_CHROMA], &up); - - if (!p_Vid->active_pps->constrained_intra_pred_flag) - { - up_avail = up.available; - left_avail[0] = left_avail[1] = left[1].available; - left_up_avail = left[0].available; - } - else - { - up_avail = up.available ? currSlice->intra_block[up.mb_addr] : 0; - for (i=0, left_avail[0] = 1; i < cr_MB_y2;++i) - left_avail[0] &= left[i + 1].available ? currSlice->intra_block[left[i + 1].mb_addr]: 0; - - for (i = cr_MB_y2, left_avail[1] = 1; iintra_block[left[i + 1].mb_addr]: 0; - - left_up_avail = left[0].available ? currSlice->intra_block[left[0].mb_addr]: 0; - } - // plane prediction - if (!left_up_avail || !left_avail[0] || !left_avail[1] || !up_avail) - error("unexpected PLANE_8 chroma intra prediction mode",-1); - else - { - int uv; - for (uv = 0; uv < 2; uv++) - { - imgpel **imgUV = dec_picture->imgUV[uv]; - imgpel **mb_pred = currSlice->mb_pred[uv + 1]; - int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; - imgpel *upPred = &imgUV[up.pos_y][up.pos_x]; - - ih = cr_MB_x2 * (upPred[cr_MB_x - 1] - imgUV[left[0].pos_y][left[0].pos_x]); - for (i = 0; i < cr_MB_x2 - 1; ++i) - ih += (i + 1) * (upPred[cr_MB_x2 + i] - upPred[cr_MB_x2 - 2 - i]); - - iv = cr_MB_y2 * (imgUV[left[cr_MB_y].pos_y][left[cr_MB_y].pos_x] - imgUV[left[0].pos_y][left[0].pos_x]); - for (i = 0; i < cr_MB_y2 - 1; ++i) - iv += (i + 1)*(imgUV[left[cr_MB_y2 + 1 + i].pos_y][left[cr_MB_y2 + 1 + i].pos_x] - - imgUV[left[cr_MB_y2 - 1 - i].pos_y][left[cr_MB_y2 - 1 - i].pos_x]); - - ib= ((cr_MB_x == 8 ? 17 : 5) * ih + 2 * cr_MB_x)>>(cr_MB_x == 8 ? 5 : 6); - ic= ((cr_MB_y == 8 ? 17 : 5) * iv + 2 * cr_MB_y)>>(cr_MB_y == 8 ? 5 : 6); - - iaa=16*(imgUV[left[cr_MB_y].pos_y][left[cr_MB_y].pos_x] + upPred[cr_MB_x-1]); - - for (j = 0; j < cr_MB_y; ++j) - for (i = 0; i < cr_MB_x; ++i) - mb_pred[j][i]=(imgpel) iClip1(max_imgpel_value, ((iaa + (i - cr_MB_x2 + 1) * ib + (j - cr_MB_y2 + 1) * ic + 16) >> 5)); - } - } - } - break; + } break; default: error("illegal chroma intra prediction mode", 600); break; diff --git a/src/common/ldecod_src/io_raw.c b/src/common/ldecod_src/io_raw.c index 3495163..1594266 100644 --- a/src/common/ldecod_src/io_raw.c +++ b/src/common/ldecod_src/io_raw.c @@ -6,10 +6,11 @@ * I/O functions related to raw images * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Karsten Shring * - Alexis Michael Tourapis - * + * ************************************************************************************* */ #include "contributors.h" @@ -20,31 +21,28 @@ #define FAST_READ 1 #if FAST_READ -static inline int ReadData (int vfile, FrameFormat *source, unsigned char *buf) -{ +static inline int ReadData(int vfile, FrameFormat *source, unsigned char *buf) { unsigned char *cur_buf = buf; int read_size = source->pic_unit_size_shift3 * source->width[0]; int i, j; - for (i = 0; i < source->height[0]; i++) - { - if (read(vfile, cur_buf, read_size) != read_size) - { - printf ("read_one_frame: cannot read %d bytes from input file, unexpected EOF!\n", source->width[0]); + for (i = 0; i < source->height[0]; i++) { + if (read(vfile, cur_buf, read_size) != read_size) { + printf("read_one_frame: cannot read %d bytes from input file, unexpected " + "EOF!\n", + source->width[0]); return 0; } cur_buf += read_size; } - if (source->yuv_format != YUV400) - { + if (source->yuv_format != YUV400) { read_size = source->pic_unit_size_shift3 * source->width[1]; - for (j = 0; j < 2; j++) - { - for (i = 0; i < source->height[1]; i++) - { - if (read(vfile, cur_buf, read_size) != read_size) - { - printf ("read_one_frame: cannot read %d bytes from input file, unexpected EOF!\n", source->width[1]); + for (j = 0; j < 2; j++) { + for (i = 0; i < source->height[1]; i++) { + if (read(vfile, cur_buf, read_size) != read_size) { + printf("read_one_frame: cannot read %d bytes from input file, " + "unexpected EOF!\n", + source->width[1]); return 0; } cur_buf += read_size; @@ -54,21 +52,19 @@ static inline int ReadData (int vfile, FrameFormat *source, unsigned char *buf) return 1; } #else -static inline int ReadData (int vfile, int framesize_in_bytes, unsigned char *buf) -{ - if (read(vfile, buf, (int) framesize_in_bytes) != (int) framesize_in_bytes) - { - printf ("read_one_frame: cannot read %d bytes from input file, unexpected EOF!\n", (int) framesize_in_bytes); +static inline int ReadData(int vfile, int framesize_in_bytes, + unsigned char *buf) { + if (read(vfile, buf, (int)framesize_in_bytes) != (int)framesize_in_bytes) { + printf("read_one_frame: cannot read %d bytes from input file, unexpected " + "EOF!\n", + (int)framesize_in_bytes); return 0; - } - else - { + } else { return 1; } } #endif - /*! ************************************************************************ * \brief @@ -82,13 +78,14 @@ static inline int ReadData (int vfile, int framesize_in_bytes, unsigned char *bu * \param HeaderSize * Number of bytes in the source file to be skipped * \param source - * source file (on disk) information + * source file (on disk) information * \param buf * image buffer data ************************************************************************ */ -int ReadFrameConcatenated (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf) -{ +int ReadFrameConcatenated(InputParameters *p_Inp, VideoDataFile *input_file, + int FrameNoInFile, int HeaderSize, + FrameFormat *source, unsigned char *buf) { int file_read = 0; int vfile = input_file->f_num; unsigned int symbol_size_in_bytes = source->pic_unit_size_shift3; @@ -96,28 +93,31 @@ int ReadFrameConcatenated (InputParameters *p_Inp, VideoDataFile *input_file, in const int bytes_y = source->size_cmp[0] * symbol_size_in_bytes; const int bytes_uv = source->size_cmp[1] * symbol_size_in_bytes; - const int64 framesize_in_bytes = bytes_y + 2*bytes_uv; - + const int64 framesize_in_bytes = bytes_y + 2 * bytes_uv; + // Let us seek directly to the current frame - if (lseek (vfile, HeaderSize + framesize_in_bytes * (FrameNoInFile + p_Inp->start_frame), SEEK_SET) == -1) - { - snprintf(errortext, ET_SIZE, "read_one_frame: cannot advance file pointer in input file beyond frame %d\n", p_Inp->start_frame + FrameNoInFile); - error (errortext,-1); + if (lseek(vfile, + HeaderSize + + framesize_in_bytes * (FrameNoInFile + p_Inp->start_frame), + SEEK_SET) == -1) { + snprintf(errortext, ET_SIZE, + "read_one_frame: cannot advance file pointer in input file beyond " + "frame %d\n", + p_Inp->start_frame + FrameNoInFile); + error(errortext, -1); } - // Here we are at the correct position for the source frame in the file. + // Here we are at the correct position for the source frame in the file. // Now read it. - if ((source->pic_unit_size_on_disk & 0x07) == 0) - { + if ((source->pic_unit_size_on_disk & 0x07) == 0) { #if FAST_READ - file_read = ReadData (vfile, source, buf); + file_read = ReadData(vfile, source, buf); #else - file_read = ReadData (vfile, (int) framesize_in_bytes, buf); + file_read = ReadData(vfile, (int)framesize_in_bytes, buf); #endif - } - else - { - printf ("read_one_frame (NOT IMPLEMENTED): pic unit size on disk must be divided by 8"); - exit (-1); + } else { + printf("read_one_frame (NOT IMPLEMENTED): pic unit size on disk must be " + "divided by 8"); + exit(-1); } return file_read; } @@ -135,43 +135,41 @@ int ReadFrameConcatenated (InputParameters *p_Inp, VideoDataFile *input_file, in * \param HeaderSize * Number of bytes in the source file to be skipped * \param source - * source file (on disk) information + * source file (on disk) information * \param buf * taget buffer ************************************************************************ */ -int ReadFrameSeparate (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, int HeaderSize, FrameFormat *source, unsigned char *buf) -{ +int ReadFrameSeparate(InputParameters *p_Inp, VideoDataFile *input_file, + int FrameNoInFile, int HeaderSize, FrameFormat *source, + unsigned char *buf) { int file_read = 0; int vfile = input_file->f_num; - OpenFrameFile( input_file, FrameNoInFile + p_Inp->start_frame); + OpenFrameFile(input_file, FrameNoInFile + p_Inp->start_frame); // skip Header - if (lseek (vfile, HeaderSize, SEEK_SET) != HeaderSize) - { - error ("read_one_frame: cannot fseek to (Header size) in input file", -1); + if (lseek(vfile, HeaderSize, SEEK_SET) != HeaderSize) { + error("read_one_frame: cannot fseek to (Header size) in input file", -1); } // Read data - if ((source->pic_unit_size_on_disk & 0x07) == 0) - { + if ((source->pic_unit_size_on_disk & 0x07) == 0) { #if FAST_READ - file_read = ReadData (vfile, source, buf); + file_read = ReadData(vfile, source, buf); #else unsigned int symbol_size_in_bytes = source->pic_unit_size_shift3; const int bytes_y = source->size_cmp[0] * symbol_size_in_bytes; const int bytes_uv = source->size_cmp[1] * symbol_size_in_bytes; - const int64 framesize_in_bytes = bytes_y + 2*bytes_uv; + const int64 framesize_in_bytes = bytes_y + 2 * bytes_uv; - file_read = ReadData (vfile, (int) framesize_in_bytes, buf); + file_read = ReadData(vfile, (int)framesize_in_bytes, buf); #endif - } - else - { - printf ("read_one_frame (NOT IMPLEMENTED): pic unit size on disk must be divisible by 8"); - exit (-1); + } else { + printf("read_one_frame (NOT IMPLEMENTED): pic unit size on disk must be " + "divisible by 8"); + exit(-1); } if (vfile != -1) diff --git a/src/common/ldecod_src/io_tiff.c b/src/common/ldecod_src/io_tiff.c index 53da252..edee899 100644 --- a/src/common/ldecod_src/io_tiff.c +++ b/src/common/ldecod_src/io_tiff.c @@ -6,16 +6,16 @@ * I/O functions related to TIFF images * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Larry Luther * - Alexis Michael Tourapis - * + * ************************************************************************************* */ +#include "io_tiff.h" #include "contributors.h" #include "report.h" -#include "io_tiff.h" - // Maximum number of rows in image #define YRES 1080 @@ -24,151 +24,121 @@ //! TIFF Field Type Code typedef enum TiffType { - T_BYTE = 1, //!< 8-bit unsigned integer. - T_ASCII = 2, //!< 8-bit byte that contains a 7-bit ASCII code; the last byte must be NUL (binary zero). - T_SHORT = 3, //!< 16-bit (2-byte) unsigned integer. - T_LONG = 4, //!< 32-bit (4-byte) unsigned integer. - T_RATIONAL = 5, //!< Two LONGs: the first represents the numerator of a fraction; the second, the denominator. - T_SBYTE = 6, //!< An 8-bit signed (twos-complement) integer. - T_UNDEFINED = 7, //!< An 8-bit byte that may contain anything, depending on the definition of the field. - T_SSHORT = 8, //!< A 16-bit (2-byte) signed (twos-complement) integer. - T_SLONG = 9, //!< A 32-bit (4-byte) signed (twos-complement) integer. - T_SRATIONAL = 10, //!< Two SLONGs: the first represents the numerator of a fraction, the second the denominator. - T_FLOAT = 11, //!< Single precision (4-byte) IEEE format. - T_DOUBLE = 12 //!< Double precision (8-byte) IEEE format. + T_BYTE = 1, //!< 8-bit unsigned integer. + T_ASCII = 2, //!< 8-bit byte that contains a 7-bit ASCII code; the last byte + //!< must be NUL (binary zero). + T_SHORT = 3, //!< 16-bit (2-byte) unsigned integer. + T_LONG = 4, //!< 32-bit (4-byte) unsigned integer. + T_RATIONAL = 5, //!< Two LONGs: the first represents the numerator of a + //!< fraction; the second, the denominator. + T_SBYTE = 6, //!< An 8-bit signed (twos-complement) integer. + T_UNDEFINED = 7, //!< An 8-bit byte that may contain anything, depending on + //!< the definition of the field. + T_SSHORT = 8, //!< A 16-bit (2-byte) signed (twos-complement) integer. + T_SLONG = 9, //!< A 32-bit (4-byte) signed (twos-complement) integer. + T_SRATIONAL = 10, //!< Two SLONGs: the first represents the numerator of a + //!< fraction, the second the denominator. + T_FLOAT = 11, //!< Single precision (4-byte) IEEE format. + T_DOUBLE = 12 //!< Double precision (8-byte) IEEE format. } TiffType; - typedef struct TiffDirectoryEntry { - uint16 - tag, //!< The tag that identifies the field. - type; //!< The field type. - uint32 - count, //!< Number of values of the indicated type. - offset; //!< Value or offset. + uint16 tag, //!< The tag that identifies the field. + type; //!< The field type. + uint32 count, //!< Number of values of the indicated type. + offset; //!< Value or offset. } TiffDirectoryEntry; - //! TIFF Image File Directory typedef struct TiffIFD { - uint16 - nEntries; - TiffDirectoryEntry - directoryEntry[]; + uint16 nEntries; + TiffDirectoryEntry directoryEntry[]; } TiffIFD; - typedef struct TiffImageFileHeader { - uint16 - byteOrder, //!< "II" (4949H) or "MM" (4D4DH) - arbitraryNumber; //!< 42 - uint32 - offset; //!< Offset of the 0th IFD + uint16 byteOrder, //!< "II" (4949H) or "MM" (4D4DH) + arbitraryNumber; //!< 42 + uint32 offset; //!< Offset of the 0th IFD } TiffImageFileHeader; - //! TIFF file data typedef struct Tiff { - uint16 - *img; //!< Image data - uint8 - *fileInMemory; //!< The file will be read into memory in one gulp here. - uint8 - *mp; //!< Memory pointer. - int - le, //!< Little endian - 0 false, 1 - true - nStrips; - TiffImageFileHeader - ifh; - // Information from TAGs - uint16 - Orientation; - uint32 - BitsPerSample[3], - RowsPerStrip, - ImageLength, - ImageWidth, - StripByteCounts[YRES], - StripOffsets[YRES], - XResolution[2], - YResolution[2]; + uint16 *img; //!< Image data + uint8 *fileInMemory; //!< The file will be read into memory in one gulp here. + uint8 *mp; //!< Memory pointer. + int le, //!< Little endian - 0 false, 1 - true + nStrips; + TiffImageFileHeader ifh; + // Information from TAGs + uint16 Orientation; + uint32 BitsPerSample[3], RowsPerStrip, ImageLength, ImageWidth, + StripByteCounts[YRES], StripOffsets[YRES], XResolution[2], YResolution[2]; - uint32 (*getU16) (struct Tiff *); - uint32 (*getU32) (struct Tiff *); + uint32 (*getU16)(struct Tiff *); + uint32 (*getU32)(struct Tiff *); } Tiff; //! Video codes for RGB ==> YUV conversions typedef enum VideoCode { - VC_NULL = 0, - VC_ITU_REC709 = 1, - VC_CCIR_601 = 3, - VC_FCC = 4, - VC_ITU_REC624BG = 5, - VC_SMPTE_170M = 6, - VC_SMPTE_240M = 7, - VC_SMPTE_260M = 7, + VC_NULL = 0, + VC_ITU_REC709 = 1, + VC_CCIR_601 = 3, + VC_FCC = 4, + VC_ITU_REC624BG = 5, + VC_SMPTE_170M = 6, + VC_SMPTE_240M = 7, + VC_SMPTE_260M = 7, VC_ITU_REC709_EXACT = 8, - VC_MAX = 8 + VC_MAX = 8 } VideoCode; - -static const double Coef[VC_MAX+1][3] = { - {0.299 , 0.587 , 0.114}, // 0 unspecified - {0.2126 , 0.7152 , 0.0722}, // 1 SMPTE RP-177 & 274M, ITU-R Rec. 709 - {0.299 , 0.587 , 0.114}, // 2 unspecified - {0.299 , 0.587 , 0.114}, // 3 CCIR 601 ITU-R BT.601 / SMPTE 125M - {0.30 , 0.59 , 0.11}, // 4 FCC - {0.299 , 0.587 , 0.114}, // 5 ITU-R Rec. 624-4 System B, G - {0.299 , 0.587 , 0.114}, // 6 SMPTE 170M - {0.212 , 0.701 , 0.087}, // 7 SMPTE 240M (1987) 260M - {0.212639, 0.715169, 0.072192} // 8 SMPTE RP-177 & 274M, ITU-R Rec. 709 exact +static const double Coef[VC_MAX + 1][3] = { + {0.299, 0.587, 0.114}, // 0 unspecified + {0.2126, 0.7152, 0.0722}, // 1 SMPTE RP-177 & 274M, ITU-R Rec. 709 + {0.299, 0.587, 0.114}, // 2 unspecified + {0.299, 0.587, 0.114}, // 3 CCIR 601 ITU-R BT.601 / SMPTE 125M + {0.30, 0.59, 0.11}, // 4 FCC + {0.299, 0.587, 0.114}, // 5 ITU-R Rec. 624-4 System B, G + {0.299, 0.587, 0.114}, // 6 SMPTE 170M + {0.212, 0.701, 0.087}, // 7 SMPTE 240M (1987) 260M + {0.212639, 0.715169, + 0.072192} // 8 SMPTE RP-177 & 274M, ITU-R Rec. 709 exact }; #define CR Coef[videoCode][0] #define CG Coef[videoCode][1] #define CB Coef[videoCode][2] -#define CU (0.5/(CB-1.0)) -#define CV (0.5/(CR-1.0)) +#define CU (0.5 / (CB - 1.0)) +#define CV (0.5 / (CR - 1.0)) - -#define stdScaleY 219.0 // nominal range: 16..235 -#define stdScaleUV 224.0 // nominal range: 16..240 +#define stdScaleY 219.0 // nominal range: 16..235 +#define stdScaleUV 224.0 // nominal range: 16..240 #define INTEGER_SCALE 16384 -#define INTEGER_SHIFT 14 - +#define INTEGER_SHIFT 14 //! Parameters for RGB ==> YUV conversions. typedef struct RGB_YUV { - uint16 - pixMax; //!< Maximum pixel value. - int - stdRange, //!< 0 = full range, 1 = std range - y, u, v, - r, g, b, - yr, yg, yb, - ur, ug, ub, - vr, vg, vb, - offy, offuv; - double - sy, suv; + uint16 pixMax; //!< Maximum pixel value. + int stdRange, //!< 0 = full range, 1 = std range + y, u, v, r, g, b, yr, yg, yb, ur, ug, ub, vr, vg, vb, offy, offuv; + double sy, suv; } RGB_YUV; /*! ************************************************************************ * \brief - * Initialize pointer variables, since they are maintained across multiple calls to ReadTIFFImage + * Initialize pointer variables, since they are maintained across multiple + *calls to ReadTIFFImage * ************************************************************************ */ -void constructTiff (Tiff * t) -{ +void constructTiff(Tiff *t) { t->fileInMemory = 0; t->img = 0; t->mp = 0; } - /*! ************************************************************************ * \brief @@ -176,21 +146,17 @@ void constructTiff (Tiff * t) * ************************************************************************ */ -void destructTiff (Tiff * t) -{ - if (t->fileInMemory) - { - free( t->fileInMemory); +void destructTiff(Tiff *t) { + if (t->fileInMemory) { + free(t->fileInMemory); t->fileInMemory = 0; } - if (t->img) - { - free( t->img); + if (t->img) { + free(t->img); t->img = 0; } } - // No swap versions /*! @@ -200,8 +166,7 @@ void destructTiff (Tiff * t) * ************************************************************************ */ -static uint32 getU16 (Tiff * t) -{ +static uint32 getU16(Tiff *t) { union { uint8 in[2]; uint16 out; @@ -211,7 +176,6 @@ static uint32 getU16 (Tiff * t) return u.out; } - /*! ************************************************************************ * \brief @@ -219,8 +183,7 @@ static uint32 getU16 (Tiff * t) * ************************************************************************ */ -static uint32 getU32 (Tiff * t) -{ +static uint32 getU32(Tiff *t) { union { uint8 in[4]; uint32 out; @@ -232,7 +195,6 @@ static uint32 getU32 (Tiff * t) return u.out; } - // Swap versions /*! @@ -242,8 +204,7 @@ static uint32 getU32 (Tiff * t) * ************************************************************************ */ -static uint32 getSwappedU16 (Tiff * t) -{ +static uint32 getSwappedU16(Tiff *t) { union { uint8 in[2]; uint16 out; @@ -253,7 +214,6 @@ static uint32 getSwappedU16 (Tiff * t) return u.out; } - /*! ************************************************************************ * \brief @@ -261,8 +221,7 @@ static uint32 getSwappedU16 (Tiff * t) * ************************************************************************ */ -static uint32 getSwappedU32 (Tiff * t) -{ +static uint32 getSwappedU32(Tiff *t) { union { uint8 in[4]; uint32 out; @@ -274,7 +233,6 @@ static uint32 getSwappedU32 (Tiff * t) return u.out; } - /*! ************************************************************************ * \brief @@ -282,39 +240,34 @@ static uint32 getSwappedU32 (Tiff * t) * ************************************************************************ */ -static void getIntArray (Tiff * t, uint32 offset, TiffType type, uint32 a[], int n) -{ - int i; - uint8 *mp = t->mp; // save memory pointer +static void getIntArray(Tiff *t, uint32 offset, TiffType type, uint32 a[], + int n) { + int i; + uint8 *mp = t->mp; // save memory pointer t->mp = t->fileInMemory + offset; - switch (type) - { + switch (type) { case T_SHORT: - for (i=0; i < n; ++i) - { - a[i] = getU16( t); + for (i = 0; i < n; ++i) { + a[i] = getU16(t); } break; case T_LONG: - for (i=0; i < n; ++i) - { - a[i] = getU32( t); + for (i = 0; i < n; ++i) { + a[i] = getU32(t); } break; case T_RATIONAL: - for (i=0; i < 2*n; ++i) - { - a[i] = getU32( t); + for (i = 0; i < 2 * n; ++i) { + a[i] = getU32(t); } break; default: - assert( type == T_SHORT || type == T_LONG || type == T_RATIONAL); + assert(type == T_SHORT || type == T_LONG || type == T_RATIONAL); } - t->mp = mp; // restore memory pointer + t->mp = mp; // restore memory pointer } - /*! ************************************************************************ * \brief @@ -322,123 +275,121 @@ static void getIntArray (Tiff * t, uint32 offset, TiffType type, uint32 a[], int * ************************************************************************ */ -static int readDirectoryEntry (Tiff * t) -{ - uint32 tag = t->getU16( t); - TiffType type = (TiffType) t->getU16( t); - uint32 count = t->getU32( t); - uint32 offset = t->getU32( t); +static int readDirectoryEntry(Tiff *t) { + uint32 tag = t->getU16(t); + TiffType type = (TiffType)t->getU16(t); + uint32 count = t->getU32(t); + uint32 offset = t->getU32(t); - switch (tag) - { - case 256: // ImageWidth SHORT or LONG - assert( count == 1); - //printf( "256: ImageWidth = %u\n", offset); + switch (tag) { + case 256: // ImageWidth SHORT or LONG + assert(count == 1); + // printf( "256: ImageWidth = %u\n", offset); t->ImageWidth = offset; break; - case 257: // ImageLength SHORT or LONG - assert( count == 1); - //printf( "257: ImageLength = %u\n", offset); + case 257: // ImageLength SHORT or LONG + assert(count == 1); + // printf( "257: ImageLength = %u\n", offset); t->ImageLength = offset; - if (offset > YRES) - { - fprintf( stderr, "readDirectoryEntry: ImageLength (%d) exceeds builtin maximum of %d\n", offset, YRES); + if (offset > YRES) { + fprintf(stderr, + "readDirectoryEntry: ImageLength (%d) exceeds builtin maximum " + "of %d\n", + offset, YRES); return 1; } break; - case 258: // BitsPerSample SHORT 8,8,8 - if (count != 3) - { - fprintf( stderr, "BitsPerSample (only [3] supported)\n"); + case 258: // BitsPerSample SHORT 8,8,8 + if (count != 3) { + fprintf(stderr, "BitsPerSample (only [3] supported)\n"); return 1; } - getIntArray( t, offset, type, t->BitsPerSample, 3); - //printf( "258: BitsPerSample[%d] = %u,%u,%u\n", count, t->BitsPerSample[0], t->BitsPerSample[1], t->BitsPerSample[2]); - if (t->BitsPerSample[0] != t->BitsPerSample[1] || t->BitsPerSample[0] != t->BitsPerSample[2]) - { - fprintf( stderr, "BitsPerSample must be the same for all samples\n"); + getIntArray(t, offset, type, t->BitsPerSample, 3); + // printf( "258: BitsPerSample[%d] = %u,%u,%u\n", count, + // t->BitsPerSample[0], t->BitsPerSample[1], t->BitsPerSample[2]); + if (t->BitsPerSample[0] != t->BitsPerSample[1] || + t->BitsPerSample[0] != t->BitsPerSample[2]) { + fprintf(stderr, "BitsPerSample must be the same for all samples\n"); return 1; } - if (t->BitsPerSample[0] != 8 && t->BitsPerSample[0] != 16) - { - fprintf( stderr, "Only 8 or 16 BitsPerSample is supported\n"); + if (t->BitsPerSample[0] != 8 && t->BitsPerSample[0] != 16) { + fprintf(stderr, "Only 8 or 16 BitsPerSample is supported\n"); return 1; } break; - case 259: // Compression SHORT 1 or 32773 - assert( count == 1); - //printf( "259: Compression = %u\n", offset); - if (offset != 1) - { - fprintf( stderr, "Only uncompressed TIFF files supported\n"); + case 259: // Compression SHORT 1 or 32773 + assert(count == 1); + // printf( "259: Compression = %u\n", offset); + if (offset != 1) { + fprintf(stderr, "Only uncompressed TIFF files supported\n"); return 1; } break; - case 262: // PhotometricInterpretation SHORT 2 - assert( count == 1); - //printf( "262: PhotometricInterpretation = %u\n", offset); - assert( offset == 2); + case 262: // PhotometricInterpretation SHORT 2 + assert(count == 1); + // printf( "262: PhotometricInterpretation = %u\n", offset); + assert(offset == 2); break; - case 273: // StripOffsets SHORT or LONG - //printf( "273: StripOffsets[%d] = %u\n", count, offset); - getIntArray( t, offset, type, t->StripOffsets, count); + case 273: // StripOffsets SHORT or LONG + // printf( "273: StripOffsets[%d] = %u\n", count, offset); + getIntArray(t, offset, type, t->StripOffsets, count); t->nStrips = count; break; - case 274: // Orientation SHORT - assert( count == 1); - //printf( "274: Orientation = %u\n", offset); - t->Orientation = (uint16) offset; - if (t->Orientation != 1) - { - fprintf( stderr, "Only Orientation 1 is supported\n"); + case 274: // Orientation SHORT + assert(count == 1); + // printf( "274: Orientation = %u\n", offset); + t->Orientation = (uint16)offset; + if (t->Orientation != 1) { + fprintf(stderr, "Only Orientation 1 is supported\n"); return 1; } break; - case 277: // SamplesPerPixel SHORT 3 or more - assert( count == 1); - //printf( "277: SamplesPerPixel = %u\n", offset); - assert( offset == 3); + case 277: // SamplesPerPixel SHORT 3 or more + assert(count == 1); + // printf( "277: SamplesPerPixel = %u\n", offset); + assert(offset == 3); break; - case 278: // RowsPerStrip SHORT or LONG - assert( count == 1); - //printf( "278: RowsPerStrip = %u\n", offset); + case 278: // RowsPerStrip SHORT or LONG + assert(count == 1); + // printf( "278: RowsPerStrip = %u\n", offset); t->RowsPerStrip = offset; break; - case 279: // StripByteCounts LONG or SHORT - //printf( "279: StripByteCounts[%u] = %u\n", count, offset); - getIntArray( t, offset, type, t->StripByteCounts, count); + case 279: // StripByteCounts LONG or SHORT + // printf( "279: StripByteCounts[%u] = %u\n", count, offset); + getIntArray(t, offset, type, t->StripByteCounts, count); break; - case 282: // XResolution RATIONAL - assert( count == 1); - getIntArray( t, offset, type, t->XResolution, 1); - //printf( "282: XResolution = %u/%u\n", offset, t->XResolution[0], t->XResolution[1]); + case 282: // XResolution RATIONAL + assert(count == 1); + getIntArray(t, offset, type, t->XResolution, 1); + // printf( "282: XResolution = %u/%u\n", offset, t->XResolution[0], + // t->XResolution[1]); break; - case 283: // YResolution RATIONAL - assert( count == 1); - getIntArray( t, offset, type, t->YResolution, 1); - //printf( "283: YResolution = %u/%u\n", offset, t->YResolution[0], t->YResolution[1]); + case 283: // YResolution RATIONAL + assert(count == 1); + getIntArray(t, offset, type, t->YResolution, 1); + // printf( "283: YResolution = %u/%u\n", offset, t->YResolution[0], + // t->YResolution[1]); break; - case 284: // PlanarConfiguration SHORT - assert( count == 1); - //printf( "284: PlanarConfiguration = %u\n", offset); - assert( offset == 1); + case 284: // PlanarConfiguration SHORT + assert(count == 1); + // printf( "284: PlanarConfiguration = %u\n", offset); + assert(offset == 1); break; - case 296: // ResolutionUnit SHORT 1, 2 or 3 - //printf( "296: ResolutionUnit = %u\n", offset); - assert( count == 1); + case 296: // ResolutionUnit SHORT 1, 2 or 3 + // printf( "296: ResolutionUnit = %u\n", offset); + assert(count == 1); break; - case 305: // Software ASCII - //printf( "305: Software = %s\n", t->fileInMemory + offset); + case 305: // Software ASCII + // printf( "305: Software = %s\n", t->fileInMemory + offset); break; - case 339: // SampleFormat SHORT 1 + case 339: // SampleFormat SHORT 1 default: - //printf( "%3d: Unforseen = %u\n", tag, offset); - ; - } + // printf( "%3d: Unforseen = %u\n", tag, offset); + ; + } return 0; } - /*! ************************************************************************ * \brief @@ -448,73 +399,64 @@ static int readDirectoryEntry (Tiff * t) * 0 if successful ************************************************************************ */ -static int readFileIntoMemory (Tiff * t, const char * path) -{ - long - cnt, result; - uint16 - byteOrder; - int - endian = 1, - machineLittleEndian = (*( (signed char *)(&endian) ) == 1) ? 1 : 0, - fd; +static int readFileIntoMemory(Tiff *t, const char *path) { + long cnt, result; + uint16 byteOrder; + int endian = 1, + machineLittleEndian = (*((signed char *)(&endian)) == 1) ? 1 : 0, fd; - assert( t); - assert( path); + assert(t); + assert(path); - fd = open( path, OPENFLAGS_READ); - if (fd == -1) - { - fprintf( stderr, "Couldn't open to read: %s\n", path); + fd = open(path, OPENFLAGS_READ); + if (fd == -1) { + fprintf(stderr, "Couldn't open to read: %s\n", path); return 1; } - cnt = (long) lseek( fd, 0, SEEK_END); // TIFF files by definition cannot exceed 2^32 + cnt = (long)lseek(fd, 0, + SEEK_END); // TIFF files by definition cannot exceed 2^32 if (cnt == -1L) return 1; - if (lseek( fd, 0, SEEK_SET) == -1L) // reposition file at beginning + if (lseek(fd, 0, SEEK_SET) == -1L) // reposition file at beginning return 1; - t->fileInMemory = (uint8 *) realloc( t->fileInMemory, cnt); - if (t->fileInMemory == 0) - { - close( fd); + t->fileInMemory = (uint8 *)realloc(t->fileInMemory, cnt); + if (t->fileInMemory == 0) { + close(fd); return 1; } - result = (long) read( fd, t->fileInMemory, cnt); - if (result != cnt) - { - close( fd); + result = (long)read(fd, t->fileInMemory, cnt); + if (result != cnt) { + close(fd); return 1; } - close( fd); + close(fd); byteOrder = (t->fileInMemory[0] << 8) | t->fileInMemory[1]; - switch (byteOrder) - { - case 0x4949: // little endian file - t->le = 1; - //printf( "Little endian file\n"); - break; - case 0x4D4D: // big endian file - t->le = 0; - //printf( "Big endian file\n"); - break; - default: - fprintf( stderr, "First two bytes indicate: Not a TIFF file\n"); - free( t->fileInMemory); - t->fileInMemory = 0; - return 1; + switch (byteOrder) { + case 0x4949: // little endian file + t->le = 1; + // printf( "Little endian file\n"); + break; + case 0x4D4D: // big endian file + t->le = 0; + // printf( "Big endian file\n"); + break; + default: + fprintf(stderr, "First two bytes indicate: Not a TIFF file\n"); + free(t->fileInMemory); + t->fileInMemory = 0; + return 1; } - if (t->le == machineLittleEndian) // endianness of machine matches file + if (t->le == machineLittleEndian) // endianness of machine matches file { t->getU16 = getU16; t->getU32 = getU32; - } - else // endianness of machine does not match file + } else // endianness of machine does not match file { t->getU16 = getSwappedU16; t->getU32 = getSwappedU32; @@ -530,90 +472,78 @@ static int readFileIntoMemory (Tiff * t, const char * path) * ************************************************************************ */ -static int readImageData (Tiff * t) -{ - int i, j, n; - uint8 *mp, *s; +static int readImageData(Tiff *t) { + int i, j, n; + uint8 *mp, *s; uint16 *p; - uint32 size; + uint32 size; - assert( t); + assert(t); size = t->ImageWidth * t->ImageLength * 3 * sizeof(uint16); - t->img = (uint16 *) realloc( t->img, size); + t->img = (uint16 *)realloc(t->img, size); if (t->img == 0) return 1; - switch (t->BitsPerSample[0]) - { + switch (t->BitsPerSample[0]) { case 8: p = t->img; - for (i=0; i < t->nStrips; ++i) - { + for (i = 0; i < t->nStrips; ++i) { n = t->StripByteCounts[i]; s = t->fileInMemory + t->StripOffsets[i]; - for (j=0; j < n; ++j) - { + for (j = 0; j < n; ++j) { *p++ = *s++; } } break; case 16: - mp = t->mp; // save memory pointer + mp = t->mp; // save memory pointer p = t->img; - for (i=0; i < t->nStrips; ++i) - { + for (i = 0; i < t->nStrips; ++i) { n = t->StripByteCounts[i] / 2; t->mp = t->fileInMemory + t->StripOffsets[i]; - for (j=0; j < n; ++j) - { - *p++ = (uint16) getU16( t); + for (j = 0; j < n; ++j) { + *p++ = (uint16)getU16(t); } } - t->mp = mp; // restore memory pointer + t->mp = mp; // restore memory pointer break; } return 0; } - /*! ***************************************************************************** * \brief * Read the ImageFileDirectory. - * + * ***************************************************************************** -*/ -static int readImageFileDirectory (Tiff * t) -{ + */ +static int readImageFileDirectory(Tiff *t) { uint32 i; - uint32 nEntries = t->getU16( t); + uint32 nEntries = t->getU16(t); - for (i=0; i < nEntries; ++i) - { - readDirectoryEntry( t); + for (i = 0; i < nEntries; ++i) { + readDirectoryEntry(t); } return 0; } - /*! ***************************************************************************** * \brief * Read the ImageFileHeader. - * + * ***************************************************************************** -*/ -static int readImageFileHeader (Tiff * t) -{ - t->ifh.byteOrder = (uint16) getU16( t); - t->ifh.arbitraryNumber = (uint16) getU16( t); - t->ifh.offset = getU32( t); - if (t->ifh.arbitraryNumber != 42) - { - fprintf( stderr, "ImageFileHeader.arbitrary != 42\n"); + */ +static int readImageFileHeader(Tiff *t) { + t->ifh.byteOrder = (uint16)getU16(t); + t->ifh.arbitraryNumber = (uint16)getU16(t); + t->ifh.offset = getU32(t); + if (t->ifh.arbitraryNumber != 42) { + fprintf(stderr, "ImageFileHeader.arbitrary != 42\n"); return 1; - } + } t->mp = t->fileInMemory + t->ifh.offset; return 0; } @@ -622,26 +552,30 @@ static int readImageFileHeader (Tiff * t) ***************************************************************************** * \brief * Read the TIFF file named 'path' into 't'. - * + * ***************************************************************************** -*/ -static int readTiff (Tiff * t, char * path) { - assert( t); - assert( path); + */ +static int readTiff(Tiff *t, char *path) { + assert(t); + assert(path); - if (readFileIntoMemory( t, path)) + if (readFileIntoMemory(t, path)) goto Error; - if (readImageFileHeader( t)) + if (readImageFileHeader(t)) goto Error; - if (readImageFileDirectory( t)) + if (readImageFileDirectory(t)) goto Error; - if (readImageData( t)) + if (readImageData(t)) goto Error; return 0; Error: - if (t->fileInMemory) free( t->fileInMemory); t->fileInMemory = 0; - if (t->img) free( t->img); t->img = 0; + if (t->fileInMemory) + free(t->fileInMemory); + t->fileInMemory = 0; + if (t->img) + free(t->img); + t->img = 0; return 1; } @@ -649,25 +583,25 @@ Error: ***************************************************************************** * \brief * Initialize RGB ==> YUV conversion factors - * + * ***************************************************************************** -*/ -static int RGB_YUV_initialize (RGB_YUV * T, - VideoCode videoCode, //!< <-- Describes color space. - int stdRange, //!< <-- 1 = Standard range, 0 = Full range - uint16 pixMax //!< <-- Maximum component value. - ) -{ + */ +static int +RGB_YUV_initialize(RGB_YUV *T, + VideoCode videoCode, //!< <-- Describes color space. + int stdRange, //!< <-- 1 = Standard range, 0 = Full range + uint16 pixMax //!< <-- Maximum component value. +) { int i, pixScale; - switch (videoCode) - { - case VC_ITU_REC709: - case VC_CCIR_601: - break; - default: - fprintf( stderr, "RGB_YUV_initialize: Unsupported videoCode (%d)\n", videoCode); - return 1; + switch (videoCode) { + case VC_ITU_REC709: + case VC_CCIR_601: + break; + default: + fprintf(stderr, "RGB_YUV_initialize: Unsupported videoCode (%d)\n", + videoCode); + return 1; } T->stdRange = stdRange; @@ -675,39 +609,44 @@ static int RGB_YUV_initialize (RGB_YUV * T, pixScale = (int)pixMax + ((int)pixMax & 1); - if (stdRange) + if (stdRange) { + T->offy = (int)(INTEGER_SCALE * + (pixScale * 16 / 256.0 + 0.5)); // setup + rounding + T->sy = INTEGER_SCALE * stdScaleY / 255.0; + T->suv = INTEGER_SCALE * stdScaleUV / 255.0; + } else // full range { - T->offy = (int)(INTEGER_SCALE * (pixScale * 16 / 256.0 + 0.5)); // setup + rounding - T->sy = INTEGER_SCALE * stdScaleY / 255.0; - T->suv = INTEGER_SCALE * stdScaleUV / 255.0; - } - else // full range - { - T->offy = (int)(INTEGER_SCALE * 0.5); // rounding - T->sy = INTEGER_SCALE; - T->suv = INTEGER_SCALE; + T->offy = (int)(INTEGER_SCALE * 0.5); // rounding + T->sy = INTEGER_SCALE; + T->suv = INTEGER_SCALE; } - T->offuv = (int)(INTEGER_SCALE * (0.5 * pixScale + 0.5)); // offset + rounding + T->offuv = (int)(INTEGER_SCALE * (0.5 * pixScale + 0.5)); // offset + rounding // IMPORTANT NOTE: sign of 0.5 for rounding must agree with sign of CU & CV - T->yr = (int)(T-> sy*CR +0.5); T->yg = (int)(T-> sy*CG +0.5); T->yb = (int)(T-> sy*CB +0.5); - T->ur = (int)(T->suv*CR*CU-0.5); T->ug = (int)(T->suv*CG*CU-0.5); T->ub = (int)(T->suv*0.5 +0.5); - T->vr = (int)(T->suv*0.5 +0.5); T->vg = (int)(T->suv*CG*CV-0.5); T->vb = (int)(T->suv*CB*CV-0.5); + T->yr = (int)(T->sy * CR + 0.5); + T->yg = (int)(T->sy * CG + 0.5); + T->yb = (int)(T->sy * CB + 0.5); + T->ur = (int)(T->suv * CR * CU - 0.5); + T->ug = (int)(T->suv * CG * CU - 0.5); + T->ub = (int)(T->suv * 0.5 + 0.5); + T->vr = (int)(T->suv * 0.5 + 0.5); + T->vg = (int)(T->suv * CG * CV - 0.5); + T->vb = (int)(T->suv * CB * CV - 0.5); i = (unsigned int)(T->sy + 0.5); - if (T->yr+T->yg+T->yb != i) - { - fprintf( stderr, "ERROR: RGB_YUV_initialize: yr+yg+yb=%d sy=%u\n", T->yr+T->yg+T->yb, i); + if (T->yr + T->yg + T->yb != i) { + fprintf(stderr, "ERROR: RGB_YUV_initialize: yr+yg+yb=%d sy=%u\n", + T->yr + T->yg + T->yb, i); return 1; } - if (T->ur+T->ug+T->ub) - { - fprintf( stderr, "ERROR: RGB_YUV_initialize: ur+ug+ub=%d\n", T->ur+T->ug+T->ub); + if (T->ur + T->ug + T->ub) { + fprintf(stderr, "ERROR: RGB_YUV_initialize: ur+ug+ub=%d\n", + T->ur + T->ug + T->ub); return 1; } - if (T->vr+T->vg+T->vb) - { - fprintf( stderr, "ERROR: RGB_YUV_initialize: vr+vg+vb=%d\n", T->vr+T->vg+T->vb); + if (T->vr + T->vg + T->vb) { + fprintf(stderr, "ERROR: RGB_YUV_initialize: vr+vg+vb=%d\n", + T->vr + T->vg + T->vb); return 1; } @@ -717,74 +656,89 @@ static int RGB_YUV_initialize (RGB_YUV * T, /*! ***************************************************************************** * \brief - * Convert interleaved/planar RGB components to interleaved/planar YUV components - * + * Convert interleaved/planar RGB components to interleaved/planar YUV + *components + * ***************************************************************************** -*/ -static void RGB_YUV_rgb_to_yuv (RGB_YUV * T, - uint16 *rp, //!< <-- red components - uint16 *gp, //!< <-- green components - uint16 *bp, //!< <-- blue components - int xres, //!< <-- number of pixels in a row - int yres, //!< <-- number of rows - int rgb_stride, //!< <-- stride to next R,G,B component - uint16 *yp, //!< --> Y components - uint16 *up, //!< --> U components - uint16 *vp, //!< --> V components - int yuv_stride //!< <-- stride to next Y,U,V component - ) -{ + */ +static void +RGB_YUV_rgb_to_yuv(RGB_YUV *T, + uint16 *rp, //!< <-- red components + uint16 *gp, //!< <-- green components + uint16 *bp, //!< <-- blue components + int xres, //!< <-- number of pixels in a row + int yres, //!< <-- number of rows + int rgb_stride, //!< <-- stride to next R,G,B component + uint16 *yp, //!< --> Y components + uint16 *up, //!< --> U components + uint16 *vp, //!< --> V components + int yuv_stride //!< <-- stride to next Y,U,V component +) { int i; int count = xres * yres; - if (T->stdRange) // clipping not needed + if (T->stdRange) // clipping not needed { - for (i=0; i < count; ++i) - { - T->r = (int) *rp; rp += rgb_stride; - T->g = (int) *gp; gp += rgb_stride; - T->b = (int) *bp; bp += rgb_stride; + for (i = 0; i < count; ++i) { + T->r = (int)*rp; + rp += rgb_stride; + T->g = (int)*gp; + gp += rgb_stride; + T->b = (int)*bp; + bp += rgb_stride; // convert to YUV - *yp = (uint16)((T->yr*T->r + T->yg*T->g + T->yb*T->b + T-> offy) >> INTEGER_SHIFT); yp += yuv_stride; - *up = (uint16)((T->ur*T->r + T->ug*T->g + T->ub*T->b + T->offuv) >> INTEGER_SHIFT); up += yuv_stride; - *vp = (uint16)((T->vr*T->r + T->vg*T->g + T->vb*T->b + T->offuv) >> INTEGER_SHIFT); vp += yuv_stride; + *yp = (uint16)((T->yr * T->r + T->yg * T->g + T->yb * T->b + T->offy) >> + INTEGER_SHIFT); + yp += yuv_stride; + *up = (uint16)((T->ur * T->r + T->ug * T->g + T->ub * T->b + T->offuv) >> + INTEGER_SHIFT); + up += yuv_stride; + *vp = (uint16)((T->vr * T->r + T->vg * T->g + T->vb * T->b + T->offuv) >> + INTEGER_SHIFT); + vp += yuv_stride; } - } - else // full range -- need to clip + } else // full range -- need to clip { - for (i=0; i < count; ++i) - { - T->r = (int) *rp; rp += rgb_stride; - T->g = (int) *gp; gp += rgb_stride; - T->b = (int) *bp; bp += rgb_stride; + for (i = 0; i < count; ++i) { + T->r = (int)*rp; + rp += rgb_stride; + T->g = (int)*gp; + gp += rgb_stride; + T->b = (int)*bp; + bp += rgb_stride; // convert to YUV // right shift of neg value is wrong, but will get clipped so o.k. - T->y = (T->yr*T->r + T->yg*T->g + T->yb*T->b + T-> offy) >> INTEGER_SHIFT; - if (T->y < 0) + T->y = (T->yr * T->r + T->yg * T->g + T->yb * T->b + T->offy) >> + INTEGER_SHIFT; + if (T->y < 0) T->y = 0; - else if (T->y > T->pixMax) - T->y = (int) T->pixMax; - *yp = (uint16) T->y; yp += yuv_stride; + else if (T->y > T->pixMax) + T->y = (int)T->pixMax; + *yp = (uint16)T->y; + yp += yuv_stride; - T->u = (T->ur*T->r + T->ug*T->g + T->ub*T->b + T->offuv) >> INTEGER_SHIFT; - if (T->u < 0) + T->u = (T->ur * T->r + T->ug * T->g + T->ub * T->b + T->offuv) >> + INTEGER_SHIFT; + if (T->u < 0) T->u = 0; - else if (T->u > T->pixMax) - T->u = (int) T->pixMax; - *up = (uint16) T->u; up += yuv_stride; + else if (T->u > T->pixMax) + T->u = (int)T->pixMax; + *up = (uint16)T->u; + up += yuv_stride; - T->v = (T->vr*T->r + T->vg*T->g + T->vb*T->b + T->offuv) >> INTEGER_SHIFT; - if (T->v < 0) + T->v = (T->vr * T->r + T->vg * T->g + T->vb * T->b + T->offuv) >> + INTEGER_SHIFT; + if (T->v < 0) T->v = 0; - else if (T->v > T->pixMax) - T->v = (int) T->pixMax; - *vp = (uint16) T->v; vp += yuv_stride; + else if (T->v > T->pixMax) + T->v = (int)T->pixMax; + *vp = (uint16)T->v; + vp += yuv_stride; } - } // clipping + } // clipping } - /*! ***************************************************************************** * \brief FIR horizontal filter and 2:1 subsampling (with no phase shift) @@ -795,8 +749,8 @@ static void RGB_YUV_rgb_to_yuv (RGB_YUV * T, * STOPBAND RIPPLE IN -dB -.4000E+02\n * PASSBAND CUTOFF FREQUENCY 0.170000E+03 HERTZ\n * SAMPLING FREQUENCY 0.100000E+04 HERTZ\n - * number of taps in decimal 17 (normalized & rounded in kevin_filter.xls)\n - * Window Kaiser *4096 *8192\n + * number of taps in decimal 17 (normalized & rounded in + *kevin_filter.xls)\n Window Kaiser *4096 *8192\n * 0.000000000000000000E+00 coefficient of tap 0\n * 0.274349475697109923E-02 coefficient of tap 1 11 22\n * 0.000000000000000000E+00 coefficient of tap 2\n @@ -815,100 +769,87 @@ static void RGB_YUV_rgb_to_yuv (RGB_YUV * T, * 0.274349475697109923E-02 coefficient of tap 15\n * 0.000000000000000000E+00 coefficient of tap 16\n ***************************************************************************** -*/ -void horizontal_half_1chan_cosite (uint16 *srcPtr, - int srcXres, - int yres, - int srcZres, - uint16 *dstPtr, - int dstZres, - int pixMax //!< needed for clipping - ) -{ - int x, y, limit, n7, n5, n3, n1; - int result; + */ +void horizontal_half_1chan_cosite(uint16 *srcPtr, int srcXres, int yres, + int srcZres, uint16 *dstPtr, int dstZres, + int pixMax //!< needed for clipping +) { + int x, y, limit, n7, n5, n3, n1; + int result; uint16 *src = srcPtr; uint16 *dst = dstPtr; - for (y=0; y < yres; y++) - { - for (x=0; x < 8; x+=2) - { + for (y = 0; y < yres; y++) { + for (x = 0; x < 8; x += 2) { n1 = (x >= 1) ? 1 : x; n3 = (x >= 3) ? 3 : x; n5 = (x >= 5) ? 5 : x; n7 = (x >= 7) ? 7 : x; - result = ( 2048* *(src) - + 1228*( *(src-n1*srcZres) + *(src+ srcZres) ) - - 262*( *(src-n3*srcZres) + *(src+3*srcZres) ) - + 47*( *(src-n5*srcZres) + *(src+5*srcZres) ) - + 11*( *(src-n7*srcZres) + *(src+7*srcZres) )+2048) / 4096; - if (result < 0) + result = + (2048 * *(src) + 1228 * (*(src - n1 * srcZres) + *(src + srcZres)) - + 262 * (*(src - n3 * srcZres) + *(src + 3 * srcZres)) + + 47 * (*(src - n5 * srcZres) + *(src + 5 * srcZres)) + + 11 * (*(src - n7 * srcZres) + *(src + 7 * srcZres)) + 2048) / + 4096; + if (result < 0) result = 0; - else if (result > pixMax) + else if (result > pixMax) result = pixMax; - *dst = (uint16) result; + *dst = (uint16)result; dst += dstZres; - src += 2*srcZres; + src += 2 * srcZres; } limit = srcXres - 8; - for (x=8; x < limit; x+=2) - { - result = ( 2048* *(src) - + 1228*( *(src- srcZres) + *(src+ srcZres) ) - - 262*( *(src-3*srcZres) + *(src+3*srcZres) ) - + 47*( *(src-5*srcZres) + *(src+5*srcZres) ) - + 11*( *(src-7*srcZres) + *(src+7*srcZres) )+2048) / 4096; - if (result < 0) + for (x = 8; x < limit; x += 2) { + result = (2048 * *(src) + 1228 * (*(src - srcZres) + *(src + srcZres)) - + 262 * (*(src - 3 * srcZres) + *(src + 3 * srcZres)) + + 47 * (*(src - 5 * srcZres) + *(src + 5 * srcZres)) + + 11 * (*(src - 7 * srcZres) + *(src + 7 * srcZres)) + 2048) / + 4096; + if (result < 0) result = 0; - else if (result > pixMax) + else if (result > pixMax) result = pixMax; - *dst = (uint16) result; + *dst = (uint16)result; dst += dstZres; - src += 2*srcZres; + src += 2 * srcZres; } - limit = srcXres - (srcXres & 1); // must round down to not exceed dst - for (x=x; x < limit; x+=2) - { - n1 = (x < srcXres-1) ? 1 : 0; - n3 = (x < srcXres-3) ? 3 : (srcXres-1-x); - n5 = (x < srcXres-5) ? 5 : (srcXres-1-x); - n7 = (x < srcXres-7) ? 7 : (srcXres-1-x); - result = ( 2048* *(src) - + 1228*( *(src- srcZres) + *(src+n1*srcZres) ) - - 262*( *(src-3*srcZres) + *(src+n3*srcZres) ) - + 47*( *(src-5*srcZres) + *(src+n5*srcZres) ) - + 11*( *(src-7*srcZres) + *(src+n7*srcZres) )+2048) / 4096; - if (result < 0) + limit = srcXres - (srcXres & 1); // must round down to not exceed dst + for (x = x; x < limit; x += 2) { + n1 = (x < srcXres - 1) ? 1 : 0; + n3 = (x < srcXres - 3) ? 3 : (srcXres - 1 - x); + n5 = (x < srcXres - 5) ? 5 : (srcXres - 1 - x); + n7 = (x < srcXres - 7) ? 7 : (srcXres - 1 - x); + result = + (2048 * *(src) + 1228 * (*(src - srcZres) + *(src + n1 * srcZres)) - + 262 * (*(src - 3 * srcZres) + *(src + n3 * srcZres)) + + 47 * (*(src - 5 * srcZres) + *(src + n5 * srcZres)) + + 11 * (*(src - 7 * srcZres) + *(src + n7 * srcZres)) + 2048) / + 4096; + if (result < 0) result = 0; - else if (result > pixMax) + else if (result > pixMax) result = pixMax; - *dst = (uint16) result; + *dst = (uint16)result; dst += dstZres; - src += 2*srcZres; + src += 2 * srcZres; } } -} // horizontal_half_1chan_cosite - +} // horizontal_half_1chan_cosite /*! ***************************************************************************** * \brief - * FIR vertical filter and 2:1 subsampling with 0.5 sample interval phase shift - * see vertical_half_1chan.pdf for response + * FIR vertical filter and 2:1 subsampling with 0.5 sample interval phase + *shift see vertical_half_1chan.pdf for response ***************************************************************************** -*/ -void vertical_half_1chan (uint16 *srcPtr, - int xres, - int srcYres, - int srcZres, - uint16 *dstPtr, - int dstZres, - int pixMax //!< needed for clipping - ) -{ + */ +void vertical_half_1chan(uint16 *srcPtr, int xres, int srcYres, int srcZres, + uint16 *dstPtr, int dstZres, + int pixMax //!< needed for clipping +) { int x, y, limit, n6, n5, n4, n3, n2, n1; int result; @@ -916,26 +857,26 @@ void vertical_half_1chan (uint16 *srcPtr, uint16 *src = srcPtr; uint16 *dst = dstPtr; - for (y=0; y < 6; y+=2) - { + for (y = 0; y < 6; y += 2) { n1 = (y >= 1) ? 1 : y; n2 = (y >= 2) ? 2 : y; n3 = (y >= 3) ? 3 : y; n4 = (y >= 4) ? 4 : y; /*n5 = (y >= 5) ? 5 : y;*/ - for (x=0; x < xres; x++) - { - result = (225*( *(src ) + *(src+ srcRowCount) ) - +69*( *(src-n1*srcRowCount) + *(src+2*srcRowCount) ) - -30*( *(src-n2*srcRowCount) + *(src+3*srcRowCount) ) - -16*( *(src-n3*srcRowCount) + *(src+4*srcRowCount) ) - + 6*( *(src-n4*srcRowCount) + *(src+5*srcRowCount) ) - + 2*( *(src- y*srcRowCount) + *(src+6*srcRowCount) )+256) / 512; - if (result < 0) + for (x = 0; x < xres; x++) { + result = + (225 * (*(src) + *(src + srcRowCount)) + + 69 * (*(src - n1 * srcRowCount) + *(src + 2 * srcRowCount)) - + 30 * (*(src - n2 * srcRowCount) + *(src + 3 * srcRowCount)) - + 16 * (*(src - n3 * srcRowCount) + *(src + 4 * srcRowCount)) + + 6 * (*(src - n4 * srcRowCount) + *(src + 5 * srcRowCount)) + + 2 * (*(src - y * srcRowCount) + *(src + 6 * srcRowCount)) + 256) / + 512; + if (result < 0) result = 0; - else if (result > pixMax) + else if (result > pixMax) result = pixMax; - *dst = (uint16) result; + *dst = (uint16)result; dst += dstZres; src += srcZres; } @@ -943,56 +884,55 @@ void vertical_half_1chan (uint16 *srcPtr, } limit = srcYres - 6; - for (y=6; y < limit; y+=2) - { - for (x=0; x < xres; x++) - { - result = (225*( *(src ) + *(src+ srcRowCount) ) - +69*( *(src- srcRowCount) + *(src+2*srcRowCount) ) - -30*( *(src-2*srcRowCount) + *(src+3*srcRowCount) ) - -16*( *(src-3*srcRowCount) + *(src+4*srcRowCount) ) - + 6*( *(src-4*srcRowCount) + *(src+5*srcRowCount) ) - + 2*( *(src-5*srcRowCount) + *(src+6*srcRowCount) )+256) / 512; - if (result < 0) + for (y = 6; y < limit; y += 2) { + for (x = 0; x < xres; x++) { + result = + (225 * (*(src) + *(src + srcRowCount)) + + 69 * (*(src - srcRowCount) + *(src + 2 * srcRowCount)) - + 30 * (*(src - 2 * srcRowCount) + *(src + 3 * srcRowCount)) - + 16 * (*(src - 3 * srcRowCount) + *(src + 4 * srcRowCount)) + + 6 * (*(src - 4 * srcRowCount) + *(src + 5 * srcRowCount)) + + 2 * (*(src - 5 * srcRowCount) + *(src + 6 * srcRowCount)) + 256) / + 512; + if (result < 0) result = 0; - else if (result > pixMax) + else if (result > pixMax) result = pixMax; - *dst = (uint16) result; + *dst = (uint16)result; dst += dstZres; src += srcZres; } src += srcRowCount; } - limit = srcYres - (srcYres & 1); // must round down to not exceed dst - for (y=y; y < limit; y+=2) - { - n1 = (y < srcYres-1) ? 1 : 0; - n2 = (y < srcYres-2) ? 2 : (srcYres-1-y); - n3 = (y < srcYres-3) ? 3 : (srcYres-1-y); - n4 = (y < srcYres-4) ? 4 : (srcYres-1-y); - n5 = (y < srcYres-5) ? 5 : (srcYres-1-y); - n6 = (y < srcYres-6) ? 6 : (srcYres-1-y); - for (x=0; x < xres; x++) - { - result = (225*( *(src ) + *(src+n1*srcRowCount) ) - +69*( *(src- srcRowCount) + *(src+n2*srcRowCount) ) - -30*( *(src-2*srcRowCount) + *(src+n3*srcRowCount) ) - -16*( *(src-3*srcRowCount) + *(src+n4*srcRowCount) ) - + 6*( *(src-4*srcRowCount) + *(src+n5*srcRowCount) ) - + 2*( *(src-5*srcRowCount) + *(src+n6*srcRowCount) )+256) / 512; - if (result < 0) + limit = srcYres - (srcYres & 1); // must round down to not exceed dst + for (y = y; y < limit; y += 2) { + n1 = (y < srcYres - 1) ? 1 : 0; + n2 = (y < srcYres - 2) ? 2 : (srcYres - 1 - y); + n3 = (y < srcYres - 3) ? 3 : (srcYres - 1 - y); + n4 = (y < srcYres - 4) ? 4 : (srcYres - 1 - y); + n5 = (y < srcYres - 5) ? 5 : (srcYres - 1 - y); + n6 = (y < srcYres - 6) ? 6 : (srcYres - 1 - y); + for (x = 0; x < xres; x++) { + result = + (225 * (*(src) + *(src + n1 * srcRowCount)) + + 69 * (*(src - srcRowCount) + *(src + n2 * srcRowCount)) - + 30 * (*(src - 2 * srcRowCount) + *(src + n3 * srcRowCount)) - + 16 * (*(src - 3 * srcRowCount) + *(src + n4 * srcRowCount)) + + 6 * (*(src - 4 * srcRowCount) + *(src + n5 * srcRowCount)) + + 2 * (*(src - 5 * srcRowCount) + *(src + n6 * srcRowCount)) + 256) / + 512; + if (result < 0) result = 0; - else if (result > pixMax) + else if (result > pixMax) result = pixMax; - *dst = (uint16) result; + *dst = (uint16)result; dst += dstZres; src += srcZres; } src += srcRowCount; } -} // vertical_half_1chan - +} // vertical_half_1chan /*! ***************************************************************************** @@ -1004,7 +944,7 @@ void vertical_half_1chan (uint16 *srcPtr, * \param FrameNoInFile * [in] Frame number in the source file * \param source - * [in] source file (on disk) information + * [in] source file (on disk) information * \param buf * [out] memory buffer where image will be stored * \return @@ -1012,161 +952,172 @@ void vertical_half_1chan (uint16 *srcPtr, * 0, failure ***************************************************************************** */ -int ReadTIFFImage (InputParameters *p_Inp, VideoDataFile *input_file, int FrameNoInFile, FrameFormat *source, unsigned char *buf) -{ - static Tiff t; // Declaring it static allows it to "remember" memory allocations; ATOUR: Not a good idea since this affects reentrancy - char path[FILE_NAME_SIZE]; - int frameNumberInFile, n, nComponents, height, i, width, y; - RGB_YUV rgb_yuv; - uint16 - *img, *temp = NULL, *temp2 = NULL, - *p, *yp, *up, *vp; +int ReadTIFFImage(InputParameters *p_Inp, VideoDataFile *input_file, + int FrameNoInFile, FrameFormat *source, unsigned char *buf) { + static Tiff + t; // Declaring it static allows it to "remember" memory allocations; + // ATOUR: Not a good idea since this affects reentrancy + char path[FILE_NAME_SIZE]; + int frameNumberInFile, n, nComponents, height, i, width, y; + RGB_YUV rgb_yuv; + uint16 *img, *temp = NULL, *temp2 = NULL, *p, *yp, *up, *vp; - assert( p_Inp); - assert( input_file); - assert( source); - assert( buf); + assert(p_Inp); + assert(input_file); + assert(source); + assert(buf); - width = source->width[0]; + width = source->width[0]; height = source->height[0]; - assert( (width & 1) == 0 && (height & 1) == 0); // width & height must be even. + assert((width & 1) == 0 && (height & 1) == 0); // width & height must be even. - if (source->color_model == CM_RGB && !input_file->is_interleaved) - { - fprintf( stderr, "ReadTIFFImage: RGB input file has not been declared as interleaved but only interleaved is supported\n"); + if (source->color_model == CM_RGB && !input_file->is_interleaved) { + fprintf(stderr, "ReadTIFFImage: RGB input file has not been declared as " + "interleaved but only interleaved is supported\n"); goto Error; } frameNumberInFile = FrameNoInFile + p_Inp->start_frame; - if (input_file->num_digits > 0) - { - if (input_file->zero_pad) - { - n = snprintf( path, sizeof(path), "%s%0*d%s", input_file->fhead, input_file->num_digits, frameNumberInFile, input_file->ftail); - } - else - { - n = snprintf( path, sizeof(path), "%s%*d%s", input_file->fhead, input_file->num_digits, frameNumberInFile, input_file->ftail); + if (input_file->num_digits > 0) { + if (input_file->zero_pad) { + n = snprintf(path, sizeof(path), "%s%0*d%s", input_file->fhead, + input_file->num_digits, frameNumberInFile, + input_file->ftail); + } else { + n = snprintf(path, sizeof(path), "%s%*d%s", input_file->fhead, + input_file->num_digits, frameNumberInFile, + input_file->ftail); } - if (n == FILE_NAME_SIZE || n == -1) - { - fprintf( stderr, "ReadTIFFImage: file name is too large\n"); + if (n == FILE_NAME_SIZE || n == -1) { + fprintf(stderr, "ReadTIFFImage: file name is too large\n"); return 0; } - } - else - { - strcpy( path, input_file->fname); + } else { + strcpy(path, input_file->fname); } - if (readTiff( &t, path)) - { + if (readTiff(&t, path)) { goto Error; } - if ((int) t.ImageLength != height) - { - fprintf( stderr, "ReadTIFFImage: Tiff height (%u) different from encoder input height (%d) . Exiting...\n", t.ImageLength, height); + if ((int)t.ImageLength != height) { + fprintf(stderr, + "ReadTIFFImage: Tiff height (%u) different from encoder input " + "height (%d) . Exiting...\n", + t.ImageLength, height); goto Error; } - if ((int) t.ImageWidth != width) - { - fprintf( stderr, "ReadTIFFImage: Tiff width (%u) different from encoder input width (%d) . Exiting...\n", t.ImageWidth, width); + if ((int)t.ImageWidth != width) { + fprintf(stderr, + "ReadTIFFImage: Tiff width (%u) different from encoder input " + "width (%d) . Exiting...\n", + t.ImageWidth, width); goto Error; } - if (source->pic_unit_size_on_disk != 8 && source->pic_unit_size_on_disk != 16) { - fprintf( stderr, "ReadTIFFImage only supports pic_unit_size_on_disk of 8 or 16 not %d\n", source->pic_unit_size_on_disk); + if (source->pic_unit_size_on_disk != 8 && + source->pic_unit_size_on_disk != 16) { + fprintf( + stderr, + "ReadTIFFImage only supports pic_unit_size_on_disk of 8 or 16 not %d\n", + source->pic_unit_size_on_disk); goto Error; } // Transfer image to 'buf' - img = t.img; // default setting points at TIFF image data. - nComponents = width * height * 3; // for RGB, which will be overridden by YUV420 etc. + img = t.img; // default setting points at TIFF image data. + nComponents = + width * height * 3; // for RGB, which will be overridden by YUV420 etc. - if (source->color_model == CM_YUV) - { - if (RGB_YUV_initialize( &rgb_yuv, (VideoCode) p_Inp->videoCode, p_Inp->stdRange, 65535)) + if (source->color_model == CM_YUV) { + if (RGB_YUV_initialize(&rgb_yuv, (VideoCode)p_Inp->videoCode, + p_Inp->stdRange, 65535)) goto Error; - RGB_YUV_rgb_to_yuv( &rgb_yuv, img, img+1, img+2, width, height, 3, img, img+1, img+2, 3); - switch (source->yuv_format) - { + RGB_YUV_rgb_to_yuv(&rgb_yuv, img, img + 1, img + 2, width, height, 3, img, + img + 1, img + 2, 3); + switch (source->yuv_format) { case YUV420: // allocate planar buffer nComponents = width * height * 3 / 2; - yp = temp = (uint16 *) malloc( nComponents * sizeof(uint16)); + yp = temp = (uint16 *)malloc(nComponents * sizeof(uint16)); up = yp + width * height; vp = up + width * height / 4; // Y p = img; - for (i=0; i < width*height; ++i) - { - yp[i] = *p; p += 3; + for (i = 0; i < width * height; ++i) { + yp[i] = *p; + p += 3; } // subsample into planar buffer - temp2 = (uint16 *) malloc( height * width * sizeof(uint16) / 2); + temp2 = (uint16 *)malloc(height * width * sizeof(uint16) / 2); // U - horizontal_half_1chan_cosite( img+1, width, height, 3, temp2, 1, 65535); - vertical_half_1chan( temp2, width/2, height, 1, up, 1, 65535); + horizontal_half_1chan_cosite(img + 1, width, height, 3, temp2, 1, 65535); + vertical_half_1chan(temp2, width / 2, height, 1, up, 1, 65535); // V - horizontal_half_1chan_cosite( img+2, width, height, 3, temp2, 1, 65535); - vertical_half_1chan( temp2, width/2, height, 1, vp, 1, 65535); - free(temp2); temp2 = 0; - img = yp; // img points at result + horizontal_half_1chan_cosite(img + 2, width, height, 3, temp2, 1, 65535); + vertical_half_1chan(temp2, width / 2, height, 1, vp, 1, 65535); + free(temp2); + temp2 = 0; + img = yp; // img points at result break; case YUV422: // allocate planar buffer nComponents = width * height * 2; - yp = temp = (uint16 *) malloc( nComponents * sizeof(uint16)); - up = yp + width*height; - vp = yp + width*height/2; + yp = temp = (uint16 *)malloc(nComponents * sizeof(uint16)); + up = yp + width * height; + vp = yp + width * height / 2; // Y p = img; - for (i=0; i < width*height; ++i) - { - yp[i] = *p; p += 3; + for (i = 0; i < width * height; ++i) { + yp[i] = *p; + p += 3; } // U & V - for (y=0; y < height; ++y) { - horizontal_half_1chan_cosite( img + 1 + y*width*3, width, 1, 3, up + y * width/2, 1, 65535); - horizontal_half_1chan_cosite( img + 2 + y*width*3, width, 1, 3, vp + y * width/2, 1, 65535); + for (y = 0; y < height; ++y) { + horizontal_half_1chan_cosite(img + 1 + y * width * 3, width, 1, 3, + up + y * width / 2, 1, 65535); + horizontal_half_1chan_cosite(img + 2 + y * width * 3, width, 1, 3, + vp + y * width / 2, 1, 65535); } - img = yp; // img points at result + img = yp; // img points at result break; case YUV444: break; default: - fprintf( stderr, "ReadTIFFImage: Unsupported ColorFormat (%d)\n", source->yuv_format); + fprintf(stderr, "ReadTIFFImage: Unsupported ColorFormat (%d)\n", + source->yuv_format); goto Error; } } - switch (source->pic_unit_size_shift3) - { + switch (source->pic_unit_size_shift3) { case 1: - for (i=0; i < nComponents; ++i) - { + for (i = 0; i < nComponents; ++i) { buf[i] = (uint8)(img[i] >> 8); } break; case 2: - for (i=0; i < nComponents; ++i) - { - ((uint16 *) buf)[i] = img[i]; + for (i = 0; i < nComponents; ++i) { + ((uint16 *)buf)[i] = img[i]; } break; default: - fprintf( stderr, "ReadTIFFImage only supports pic_unit_size_shift3 of 1 or 2 not %d\n", source->pic_unit_size_shift3); + fprintf( + stderr, + "ReadTIFFImage only supports pic_unit_size_shift3 of 1 or 2 not %d\n", + source->pic_unit_size_shift3); goto Error; } - if (temp) free(temp); + if (temp) + free(temp); return 1; Error: - if (temp) free(temp); + if (temp) + free(temp); report_stats_on_error(); return 0; diff --git a/src/common/ldecod_src/ldecod.c b/src/common/ldecod_src/ldecod.c index 9b8e651..93127d3 100644 --- a/src/common/ldecod_src/ldecod.c +++ b/src/common/ldecod_src/ldecod.c @@ -2,8 +2,8 @@ /*! *********************************************************************** * \mainpage - * This is the H.264/AVC decoder reference software. For detailed documentation - * see the comments in each file. + * This is the H.264/AVC decoder reference software. For detailed + *documentation see the comments in each file. * * The JM software web site is located at: * http://iphome.hhi.de/suehring/tml @@ -27,7 +27,8 @@ * \brief * H.264/AVC reference decoder project main() * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Inge Lille-Langy * - Rickard Sjoberg * - Stephan Wenger @@ -44,43 +45,43 @@ #include "contributors.h" -//#include +// #include -#include "global.h" #include "annexb.h" -#include "image.h" -#include "memalloc.h" -#include "mc_prediction.h" -#include "mbuffer.h" -#include "leaky_bucket.h" -#include "fmo.h" -#include "output.h" -#include "cabac.h" -#include "parset.h" -#include "sei.h" -#include "erc_api.h" -#include "quant.h" #include "block.h" -#include "nalu.h" +#include "cabac.h" +#include "erc_api.h" +#include "fmo.h" +#include "global.h" +#include "image.h" #include "img_io.h" +#include "leaky_bucket.h" #include "loopfilter.h" +#include "mbuffer.h" +#include "mc_prediction.h" +#include "memalloc.h" +#include "nalu.h" +#include "output.h" +#include "parset.h" +#include "quant.h" +#include "sei.h" #include "h264decoder.h" -#define LOGFILE "log.dec" +#define LOGFILE "log.dec" #define DATADECFILE "dataDec.txt" -#define TRACEFILE "trace_dec.txt" +#define TRACEFILE "trace_dec.txt" // Decoder definition. This should be the only global variable in the entire // software. Global variables should be avoided. -DecoderParams *p_Dec; +DecoderParams *p_Dec; char errortext[ET_SIZE]; BlockPos *PicPos; // Prototypes of static functions -static void Report (VideoParameters *p_Vid); -static void init (VideoParameters *p_Vid); -static void free_slice (Slice *currSlice); +static void Report(VideoParameters *p_Vid); +static void init(VideoParameters *p_Vid); +static void free_slice(Slice *currSlice); void init_frext(VideoParameters *p_Vid); @@ -95,8 +96,7 @@ void init_frext(VideoParameters *p_Vid); * Exit code ************************************************************************ */ -void error(char *text, int code) -{ +void error(char *text, int code) { fprintf(stderr, "%s\n", text); #if !defined(SPEC) #if (MVC_EXTENSION_ENABLE) @@ -108,8 +108,7 @@ void error(char *text, int code) exit(code); } -static void reset_dpb( VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb ) -{ +static void reset_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb) { p_Dpb->p_Vid = p_Vid; p_Dpb->init_done = 0; } @@ -121,43 +120,46 @@ static void reset_dpb( VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb ) * Video Parameters VideoParameters *p_Vid *********************************************************************** */ -static void alloc_video_params( VideoParameters **p_Vid) -{ +static void alloc_video_params(VideoParameters **p_Vid) { int i; - if ((*p_Vid = (VideoParameters *) calloc(1, sizeof(VideoParameters)))==NULL) + if ((*p_Vid = (VideoParameters *)calloc(1, sizeof(VideoParameters))) == NULL) no_mem_exit("alloc_video_params: p_Vid"); - if (((*p_Vid)->old_slice = (OldSliceParams *) calloc(1, sizeof(OldSliceParams)))==NULL) + if (((*p_Vid)->old_slice = + (OldSliceParams *)calloc(1, sizeof(OldSliceParams))) == NULL) no_mem_exit("alloc_video_params: p_Vid->old_slice"); - if (((*p_Vid)->snr = (SNRParameters *)calloc(1, sizeof(SNRParameters)))==NULL) - no_mem_exit("alloc_video_params: p_Vid->snr"); + if (((*p_Vid)->snr = (SNRParameters *)calloc(1, sizeof(SNRParameters))) == + NULL) + no_mem_exit("alloc_video_params: p_Vid->snr"); // Allocate legacy dpb - if (((*p_Vid)->p_Dpb_legacy = (DecodedPictureBuffer*)calloc(1, sizeof(DecodedPictureBuffer)))==NULL) - no_mem_exit("alloc_video_params: p_Vid->p_Dpb_legacy"); + if (((*p_Vid)->p_Dpb_legacy = (DecodedPictureBuffer *)calloc( + 1, sizeof(DecodedPictureBuffer))) == NULL) + no_mem_exit("alloc_video_params: p_Vid->p_Dpb_legacy"); // Now set appropriate pointer (*p_Vid)->p_Dpb = (*p_Vid)->p_Dpb_legacy; reset_dpb(*p_Vid, (*p_Vid)->p_Dpb); // Allocate new dpb buffer - for (i = 0; i < 2; i++) - { - if (((*p_Vid)->p_Dpb_layer[i] = (DecodedPictureBuffer*)calloc(1, sizeof(DecodedPictureBuffer)))==NULL) - no_mem_exit("alloc_video_params: p_Vid->p_Dpb_layer[i]"); + for (i = 0; i < 2; i++) { + if (((*p_Vid)->p_Dpb_layer[i] = (DecodedPictureBuffer *)calloc( + 1, sizeof(DecodedPictureBuffer))) == NULL) + no_mem_exit("alloc_video_params: p_Vid->p_Dpb_layer[i]"); reset_dpb(*p_Vid, (*p_Vid)->p_Dpb_layer[i]); } - + (*p_Vid)->global_init_done = 0; -#if (ENABLE_OUTPUT_TONEMAPPING) - if (((*p_Vid)->seiToneMapping = (ToneMappingSEI*)calloc(1, sizeof(ToneMappingSEI)))==NULL) - no_mem_exit("alloc_video_params: (*p_Vid)->seiToneMapping"); +#if (ENABLE_OUTPUT_TONEMAPPING) + if (((*p_Vid)->seiToneMapping = + (ToneMappingSEI *)calloc(1, sizeof(ToneMappingSEI))) == NULL) + no_mem_exit("alloc_video_params: (*p_Vid)->seiToneMapping"); #endif - if(((*p_Vid)->ppSliceList = (Slice **) calloc(MAX_NUM_DECSLICES, sizeof(Slice *))) == NULL) - { + if (((*p_Vid)->ppSliceList = + (Slice **)calloc(MAX_NUM_DECSLICES, sizeof(Slice *))) == NULL) { no_mem_exit("alloc_video_params: p_Vid->ppSliceList"); } (*p_Vid)->iNumOfSlicesAllocated = MAX_NUM_DECSLICES; @@ -168,7 +170,6 @@ static void alloc_video_params( VideoParameters **p_Vid) (*p_Vid)->pNextPPS = AllocPPS(); } - /*! *********************************************************************** * \brief @@ -177,13 +178,12 @@ static void alloc_video_params( VideoParameters **p_Vid) * Input Parameters InputParameters *p_Vid *********************************************************************** */ -static void alloc_params( InputParameters **p_Inp ) -{ - if ((*p_Inp = (InputParameters *) calloc(1, sizeof(InputParameters)))==NULL) +static void alloc_params(InputParameters **p_Inp) { + if ((*p_Inp = (InputParameters *)calloc(1, sizeof(InputParameters))) == NULL) no_mem_exit("alloc_params: p_Inp"); } - /*! +/*! *********************************************************************** * \brief * Allocate the Decoder Structure @@ -191,10 +191,8 @@ static void alloc_params( InputParameters **p_Inp ) * Decoder Parameters *********************************************************************** */ -static int alloc_decoder( DecoderParams **p_Dec) -{ - if ((*p_Dec = (DecoderParams *) calloc(1, sizeof(DecoderParams)))==NULL) - { +static int alloc_decoder(DecoderParams **p_Dec) { + if ((*p_Dec = (DecoderParams *)calloc(1, sizeof(DecoderParams))) == NULL) { fprintf(stderr, "alloc_decoder: p_Dec\n"); return -1; } @@ -216,98 +214,82 @@ static int alloc_decoder( DecoderParams **p_Dec) * Image Parameters VideoParameters *p_Vid *********************************************************************** */ -static void free_img( VideoParameters *p_Vid) -{ +static void free_img(VideoParameters *p_Vid) { int i; - //free_mem3Dint(p_Vid->fcf ); - if (p_Vid != NULL) - { - free_annex_b (p_Vid); -#if (ENABLE_OUTPUT_TONEMAPPING) - if (p_Vid->seiToneMapping != NULL) - { - free (p_Vid->seiToneMapping); + // free_mem3Dint(p_Vid->fcf ); + if (p_Vid != NULL) { + free_annex_b(p_Vid); +#if (ENABLE_OUTPUT_TONEMAPPING) + if (p_Vid->seiToneMapping != NULL) { + free(p_Vid->seiToneMapping); p_Vid->seiToneMapping = NULL; } #endif - if (p_Vid->bitsfile != NULL) - { - free (p_Vid->bitsfile); + if (p_Vid->bitsfile != NULL) { + free(p_Vid->bitsfile); p_Vid->bitsfile = NULL; } - if (p_Vid->p_Dpb_legacy != NULL) - { - free (p_Vid->p_Dpb_legacy); + if (p_Vid->p_Dpb_legacy != NULL) { + free(p_Vid->p_Dpb_legacy); p_Vid->p_Dpb_legacy = NULL; } // Free new dpb layers - for (i = 0; i < 2; i++) - { - if (p_Vid->p_Dpb_layer[i] != NULL) - { - free (p_Vid->p_Dpb_layer[i]); + for (i = 0; i < 2; i++) { + if (p_Vid->p_Dpb_layer[i] != NULL) { + free(p_Vid->p_Dpb_layer[i]); p_Vid->p_Dpb_layer[i] = NULL; } } p_Vid->p_Dpb = NULL; - if (p_Vid->snr != NULL) - { - free (p_Vid->snr); + if (p_Vid->snr != NULL) { + free(p_Vid->snr); p_Vid->snr = NULL; } - if (p_Vid->old_slice != NULL) - { - free (p_Vid->old_slice); + if (p_Vid->old_slice != NULL) { + free(p_Vid->old_slice); p_Vid->old_slice = NULL; } - if(p_Vid->pNextSlice) - { + if (p_Vid->pNextSlice) { free_slice(p_Vid->pNextSlice); - p_Vid->pNextSlice=NULL; + p_Vid->pNextSlice = NULL; } - if(p_Vid->ppSliceList) - { + if (p_Vid->ppSliceList) { int i; - for(i=0; iiNumOfSlicesAllocated; i++) - if(p_Vid->ppSliceList[i]) + for (i = 0; i < p_Vid->iNumOfSlicesAllocated; i++) + if (p_Vid->ppSliceList[i]) free_slice(p_Vid->ppSliceList[i]); free(p_Vid->ppSliceList); } - if(p_Vid->nalu) - { + if (p_Vid->nalu) { FreeNALU(p_Vid->nalu); - p_Vid->nalu=NULL; + p_Vid->nalu = NULL; } - //free memory; + // free memory; FreeDecPicList(p_Vid->pDecOuputPic); - if(p_Vid->pNextPPS) - { - FreePPS(p_Vid->pNextPPS); - p_Vid->pNextPPS = NULL; - } + if (p_Vid->pNextPPS) { + FreePPS(p_Vid->pNextPPS); + p_Vid->pNextPPS = NULL; + } - free (p_Vid); + free(p_Vid); p_Vid = NULL; } } -void FreeDecPicList(DecodedPicList *pDecPicList) -{ - while(pDecPicList) - { +void FreeDecPicList(DecodedPicList *pDecPicList) { + while (pDecPicList) { DecodedPicList *pPicNext = pDecPicList->pNext; - if(pDecPicList->pY) - { + if (pDecPicList->pY) { free(pDecPicList->pY); - pDecPicList->pY=NULL; - pDecPicList->pU=NULL; - pDecPicList->pV=NULL; + pDecPicList->pY = NULL; + pDecPicList->pU = NULL; + pDecPicList->pV = NULL; } free(pDecPicList); pDecPicList = pPicNext; @@ -320,13 +302,13 @@ void FreeDecPicList(DecodedPicList *pDecPicList) * Initilize some arrays *********************************************************************** */ -static void init(VideoParameters *p_Vid) //!< video parameters +static void init(VideoParameters *p_Vid) //!< video parameters { - //int i; + // int i; InputParameters *p_Inp = p_Vid->p_Inp; - p_Vid->oldFrameSizeInMbs = (unsigned int) -1; + p_Vid->oldFrameSizeInMbs = (unsigned int)-1; - p_Vid->imgY_ref = NULL; + p_Vid->imgY_ref = NULL; p_Vid->imgUV_ref = NULL; p_Vid->recovery_point = 0; @@ -334,12 +316,12 @@ static void init(VideoParameters *p_Vid) //!< video parameters p_Vid->recovery_poc = 0x7fffffff; /* set to a max value */ p_Vid->idr_psnr_number = p_Inp->ref_offset; - p_Vid->psnr_number=0; + p_Vid->psnr_number = 0; p_Vid->number = 0; p_Vid->type = I_SLICE; - //p_Vid->dec_ref_pic_marking_buffer = NULL; + // p_Vid->dec_ref_pic_marking_buffer = NULL; p_Vid->g_nFrame = 0; // B pictures @@ -358,16 +340,14 @@ static void init(VideoParameters *p_Vid) //!< video parameters p_Vid->MbToSliceGroupMap = NULL; p_Vid->MapUnitToSliceGroupMap = NULL; - p_Vid->LastAccessUnitExists = 0; + p_Vid->LastAccessUnitExists = 0; p_Vid->NALUCount = 0; - p_Vid->out_buffer = NULL; p_Vid->pending_output = NULL; p_Vid->pending_output_state = FRAME; p_Vid->recovery_flag = 0; - #if (ENABLE_OUTPUT_TONEMAPPING) init_tone_mapping_sei(p_Vid->seiToneMapping); #endif @@ -396,63 +376,76 @@ static void init(VideoParameters *p_Vid) //!< video parameters * Initialize FREXT variables *********************************************************************** */ -void init_frext(VideoParameters *p_Vid) //!< video parameters +void init_frext(VideoParameters *p_Vid) //!< video parameters { - //pel bitdepth init - p_Vid->bitdepth_luma_qp_scale = 6 * (p_Vid->bitdepth_luma - 8); + // pel bitdepth init + p_Vid->bitdepth_luma_qp_scale = 6 * (p_Vid->bitdepth_luma - 8); - if(p_Vid->bitdepth_luma > p_Vid->bitdepth_chroma || p_Vid->active_sps->chroma_format_idc == YUV400) - p_Vid->pic_unit_bitsize_on_disk = (p_Vid->bitdepth_luma > 8)? 16:8; + if (p_Vid->bitdepth_luma > p_Vid->bitdepth_chroma || + p_Vid->active_sps->chroma_format_idc == YUV400) + p_Vid->pic_unit_bitsize_on_disk = (p_Vid->bitdepth_luma > 8) ? 16 : 8; else - p_Vid->pic_unit_bitsize_on_disk = (p_Vid->bitdepth_chroma > 8)? 16:8; - p_Vid->dc_pred_value_comp[0] = 1<<(p_Vid->bitdepth_luma - 1); - p_Vid->max_pel_value_comp[0] = (1<bitdepth_luma) - 1; + p_Vid->pic_unit_bitsize_on_disk = (p_Vid->bitdepth_chroma > 8) ? 16 : 8; + p_Vid->dc_pred_value_comp[0] = 1 << (p_Vid->bitdepth_luma - 1); + p_Vid->max_pel_value_comp[0] = (1 << p_Vid->bitdepth_luma) - 1; p_Vid->mb_size[0][0] = p_Vid->mb_size[0][1] = MB_BLOCK_SIZE; - if (p_Vid->active_sps->chroma_format_idc != YUV400) - { - //for chrominance part + if (p_Vid->active_sps->chroma_format_idc != YUV400) { + // for chrominance part p_Vid->bitdepth_chroma_qp_scale = 6 * (p_Vid->bitdepth_chroma - 8); - p_Vid->dc_pred_value_comp[1] = (1 << (p_Vid->bitdepth_chroma - 1)); - p_Vid->dc_pred_value_comp[2] = p_Vid->dc_pred_value_comp[1]; - p_Vid->max_pel_value_comp[1] = (1 << p_Vid->bitdepth_chroma) - 1; - p_Vid->max_pel_value_comp[2] = (1 << p_Vid->bitdepth_chroma) - 1; - p_Vid->num_blk8x8_uv = (1 << p_Vid->active_sps->chroma_format_idc) & (~(0x1)); + p_Vid->dc_pred_value_comp[1] = (1 << (p_Vid->bitdepth_chroma - 1)); + p_Vid->dc_pred_value_comp[2] = p_Vid->dc_pred_value_comp[1]; + p_Vid->max_pel_value_comp[1] = (1 << p_Vid->bitdepth_chroma) - 1; + p_Vid->max_pel_value_comp[2] = (1 << p_Vid->bitdepth_chroma) - 1; + p_Vid->num_blk8x8_uv = + (1 << p_Vid->active_sps->chroma_format_idc) & (~(0x1)); p_Vid->num_uv_blocks = (p_Vid->num_blk8x8_uv >> 1); p_Vid->num_cdc_coeff = (p_Vid->num_blk8x8_uv << 1); - p_Vid->mb_size[1][0] = p_Vid->mb_size[2][0] = p_Vid->mb_cr_size_x = (p_Vid->active_sps->chroma_format_idc==YUV420 || p_Vid->active_sps->chroma_format_idc==YUV422)? 8 : 16; - p_Vid->mb_size[1][1] = p_Vid->mb_size[2][1] = p_Vid->mb_cr_size_y = (p_Vid->active_sps->chroma_format_idc==YUV444 || p_Vid->active_sps->chroma_format_idc==YUV422)? 16 : 8; + p_Vid->mb_size[1][0] = p_Vid->mb_size[2][0] = p_Vid->mb_cr_size_x = + (p_Vid->active_sps->chroma_format_idc == YUV420 || + p_Vid->active_sps->chroma_format_idc == YUV422) + ? 8 + : 16; + p_Vid->mb_size[1][1] = p_Vid->mb_size[2][1] = p_Vid->mb_cr_size_y = + (p_Vid->active_sps->chroma_format_idc == YUV444 || + p_Vid->active_sps->chroma_format_idc == YUV422) + ? 16 + : 8; - p_Vid->subpel_x = p_Vid->mb_cr_size_x == 8 ? 7 : 3; - p_Vid->subpel_y = p_Vid->mb_cr_size_y == 8 ? 7 : 3; - p_Vid->shiftpel_x = p_Vid->mb_cr_size_x == 8 ? 3 : 2; - p_Vid->shiftpel_y = p_Vid->mb_cr_size_y == 8 ? 3 : 2; + p_Vid->subpel_x = p_Vid->mb_cr_size_x == 8 ? 7 : 3; + p_Vid->subpel_y = p_Vid->mb_cr_size_y == 8 ? 7 : 3; + p_Vid->shiftpel_x = p_Vid->mb_cr_size_x == 8 ? 3 : 2; + p_Vid->shiftpel_y = p_Vid->mb_cr_size_y == 8 ? 3 : 2; p_Vid->total_scale = p_Vid->shiftpel_x + p_Vid->shiftpel_y; - } - else - { + } else { p_Vid->bitdepth_chroma_qp_scale = 0; p_Vid->max_pel_value_comp[1] = 0; p_Vid->max_pel_value_comp[2] = 0; p_Vid->num_blk8x8_uv = 0; p_Vid->num_uv_blocks = 0; p_Vid->num_cdc_coeff = 0; - p_Vid->mb_size[1][0] = p_Vid->mb_size[2][0] = p_Vid->mb_cr_size_x = 0; - p_Vid->mb_size[1][1] = p_Vid->mb_size[2][1] = p_Vid->mb_cr_size_y = 0; - p_Vid->subpel_x = 0; - p_Vid->subpel_y = 0; - p_Vid->shiftpel_x = 0; - p_Vid->shiftpel_y = 0; - p_Vid->total_scale = 0; + p_Vid->mb_size[1][0] = p_Vid->mb_size[2][0] = p_Vid->mb_cr_size_x = 0; + p_Vid->mb_size[1][1] = p_Vid->mb_size[2][1] = p_Vid->mb_cr_size_y = 0; + p_Vid->subpel_x = 0; + p_Vid->subpel_y = 0; + p_Vid->shiftpel_x = 0; + p_Vid->shiftpel_y = 0; + p_Vid->total_scale = 0; } - p_Vid->mb_size_blk[0][0] = p_Vid->mb_size_blk[0][1] = p_Vid->mb_size[0][0] >> 2; - p_Vid->mb_size_blk[1][0] = p_Vid->mb_size_blk[2][0] = p_Vid->mb_size[1][0] >> 2; - p_Vid->mb_size_blk[1][1] = p_Vid->mb_size_blk[2][1] = p_Vid->mb_size[1][1] >> 2; + p_Vid->mb_size_blk[0][0] = p_Vid->mb_size_blk[0][1] = + p_Vid->mb_size[0][0] >> 2; + p_Vid->mb_size_blk[1][0] = p_Vid->mb_size_blk[2][0] = + p_Vid->mb_size[1][0] >> 2; + p_Vid->mb_size_blk[1][1] = p_Vid->mb_size_blk[2][1] = + p_Vid->mb_size[1][1] >> 2; - p_Vid->mb_size_shift[0][0] = p_Vid->mb_size_shift[0][1] = CeilLog2_sf (p_Vid->mb_size[0][0]); - p_Vid->mb_size_shift[1][0] = p_Vid->mb_size_shift[2][0] = CeilLog2_sf (p_Vid->mb_size[1][0]); - p_Vid->mb_size_shift[1][1] = p_Vid->mb_size_shift[2][1] = CeilLog2_sf (p_Vid->mb_size[1][1]); + p_Vid->mb_size_shift[0][0] = p_Vid->mb_size_shift[0][1] = + CeilLog2_sf(p_Vid->mb_size[0][0]); + p_Vid->mb_size_shift[1][0] = p_Vid->mb_size_shift[2][0] = + CeilLog2_sf(p_Vid->mb_size[1][0]); + p_Vid->mb_size_shift[1][1] = p_Vid->mb_size_shift[2][1] = + CeilLog2_sf(p_Vid->mb_size[1][1]); } /*! @@ -469,17 +462,16 @@ void init_frext(VideoParameters *p_Vid) //!< video parameters * None ************************************************************************ */ -static void Report(VideoParameters *p_Vid) -{ +static void Report(VideoParameters *p_Vid) { pic_parameter_set_rbsp_t *active_pps = p_Vid->active_pps; InputParameters *p_Inp = p_Vid->p_Inp; - SNRParameters *snr = p_Vid->snr; + SNRParameters *snr = p_Vid->snr; #define OUTSTRING_SIZE 255 char string[OUTSTRING_SIZE]; FILE *p_log; - static const char yuv_formats[4][4]= { {"400"}, {"420"}, {"422"}, {"444"} }; + static const char yuv_formats[4][4] = {{"400"}, {"420"}, {"422"}, {"444"}}; #if !defined(WIN32) && !defined(SPEC_WINDOWS) - time_t now; + time_t now; struct tm *l_time; #else char timebuf[128]; @@ -487,143 +479,143 @@ static void Report(VideoParameters *p_Vid) #ifndef SPEC // normalize time - p_Vid->tot_time = timenorm(p_Vid->tot_time); + p_Vid->tot_time = timenorm(p_Vid->tot_time); #endif - if (p_Inp->silent == FALSE) - { - fprintf(stdout,"-------------------- Average SNR all frames ------------------------------\n"); - fprintf(stdout," SNR Y(dB) : %5.2f\n",snr->snra[0]); - fprintf(stdout," SNR U(dB) : %5.2f\n",snr->snra[1]); - fprintf(stdout," SNR V(dB) : %5.2f\n",snr->snra[2]); + if (p_Inp->silent == FALSE) { + fprintf(stdout, "-------------------- Average SNR all frames " + "------------------------------\n"); + fprintf(stdout, " SNR Y(dB) : %5.2f\n", snr->snra[0]); + fprintf(stdout, " SNR U(dB) : %5.2f\n", snr->snra[1]); + fprintf(stdout, " SNR V(dB) : %5.2f\n", snr->snra[2]); #if !defined(SPEC) - fprintf(stdout," Total decoding time : %.3f sec (%.3f fps)[%d frm/%" FORMAT_OFF_T " ms]\n",p_Vid->tot_time*0.001,(snr->frame_ctr ) * 1000.0 / p_Vid->tot_time, snr->frame_ctr, p_Vid->tot_time); + fprintf(stdout, + " Total decoding time : %.3f sec (%.3f fps)[%d frm/%" FORMAT_OFF_T + " ms]\n", + p_Vid->tot_time * 0.001, + (snr->frame_ctr) * 1000.0 / p_Vid->tot_time, snr->frame_ctr, + p_Vid->tot_time); #endif - fprintf(stdout,"--------------------------------------------------------------------------\n"); - fprintf(stdout," Exit JM %s decoder, ver %s ",JM, VERSION); - fprintf(stdout,"\n"); - } - else - { - fprintf(stdout,"\n----------------------- Decoding Completed -------------------------------\n"); + fprintf(stdout, "----------------------------------------------------------" + "----------------\n"); + fprintf(stdout, " Exit JM %s decoder, ver %s ", JM, VERSION); + fprintf(stdout, "\n"); + } else { + fprintf(stdout, "\n----------------------- Decoding Completed " + "-------------------------------\n"); #if !defined(SPEC) - fprintf(stdout," Total decoding time : %.3f sec (%.3f fps)[%d frm/%" FORMAT_OFF_T " ms]\n",p_Vid->tot_time*0.001, (snr->frame_ctr) * 1000.0 / p_Vid->tot_time, snr->frame_ctr, p_Vid->tot_time); + fprintf(stdout, + " Total decoding time : %.3f sec (%.3f fps)[%d frm/%" FORMAT_OFF_T + " ms]\n", + p_Vid->tot_time * 0.001, + (snr->frame_ctr) * 1000.0 / p_Vid->tot_time, snr->frame_ctr, + p_Vid->tot_time); #endif - fprintf(stdout,"--------------------------------------------------------------------------\n"); - fprintf(stdout," Exit JM %s decoder, ver %s ",JM, VERSION); - fprintf(stdout,"\n"); + fprintf(stdout, "----------------------------------------------------------" + "----------------\n"); + fprintf(stdout, " Exit JM %s decoder, ver %s ", JM, VERSION); + fprintf(stdout, "\n"); } // write to log file - fprintf(stdout," Output status file : %s \n",LOGFILE); + fprintf(stdout, " Output status file : %s \n", LOGFILE); snprintf(string, OUTSTRING_SIZE, "%s", LOGFILE); - if ((p_log=fopen(string,"r"))==0) // check if file exist + if ((p_log = fopen(string, "r")) == 0) // check if file exist { - if ((p_log=fopen(string,"a"))==0) - { - snprintf(errortext, ET_SIZE, "Error open file %s for appending",string); + if ((p_log = fopen(string, "a")) == 0) { + snprintf(errortext, ET_SIZE, "Error open file %s for appending", string); error(errortext, 500); - } - else // Create header to new file + } else // Create header to new file { - fprintf(p_log," -------------------------------------------------------------------------------------------------------------------\n"); - fprintf(p_log,"| Decoder statistics. This file is made first time, later runs are appended |\n"); - fprintf(p_log," ------------------------------------------------------------------------------------------------------------------- \n"); - fprintf(p_log,"| ver | Date | Time | Sequence |#Img| Format | YUV |Coding|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|\n"); - fprintf(p_log," -------------------------------------------------------------------------------------------------------------------\n"); + fprintf(p_log, + " ---------------------------------------------------------------" + "----------------------------------------------------\n"); + fprintf(p_log, "| Decoder statistics. This file is made first time, " + "later runs are appended |\n"); + fprintf(p_log, + " ---------------------------------------------------------------" + "---------------------------------------------------- \n"); + fprintf(p_log, + "| ver | Date | Time | Sequence |#Img| Format | " + "YUV |Coding|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|\n"); + fprintf(p_log, + " ---------------------------------------------------------------" + "----------------------------------------------------\n"); } - } - else - { + } else { fclose(p_log); - p_log=fopen(string,"a"); // File exist,just open for appending + p_log = fopen(string, "a"); // File exist,just open for appending } - fprintf(p_log,"|%s/%-4s", VERSION, EXT_VERSION); + fprintf(p_log, "|%s/%-4s", VERSION, EXT_VERSION); #ifdef WIN32 - _strdate( timebuf ); - fprintf(p_log,"| %1.5s |",timebuf ); + _strdate(timebuf); + fprintf(p_log, "| %1.5s |", timebuf); - _strtime( timebuf); - fprintf(p_log," % 1.5s |",timebuf); + _strtime(timebuf); + fprintf(p_log, " % 1.5s |", timebuf); #else - now = time ((time_t *) NULL); // Get the system time and put it into 'now' as 'calender time' - time (&now); - l_time = localtime (&now); - strftime (string, sizeof string, "%d-%b-%Y", l_time); - fprintf(p_log,"| %1.5s |",string ); + now = time( + (time_t *) + NULL); // Get the system time and put it into 'now' as 'calender time' + time(&now); + l_time = localtime(&now); + strftime(string, sizeof string, "%d-%b-%Y", l_time); + fprintf(p_log, "| %1.5s |", string); - strftime (string, sizeof string, "%H:%M:%S", l_time); - fprintf(p_log,"| %1.5s |",string ); + strftime(string, sizeof string, "%H:%M:%S", l_time); + fprintf(p_log, "| %1.5s |", string); #endif - fprintf(p_log,"%20.20s|",p_Inp->infile); + fprintf(p_log, "%20.20s|", p_Inp->infile); - fprintf(p_log,"%3d |",p_Vid->number); - fprintf(p_log,"%4dx%-4d|", p_Vid->width, p_Vid->height); - fprintf(p_log," %s |", &(yuv_formats[p_Vid->yuv_format][0])); + fprintf(p_log, "%3d |", p_Vid->number); + fprintf(p_log, "%4dx%-4d|", p_Vid->width, p_Vid->height); + fprintf(p_log, " %s |", &(yuv_formats[p_Vid->yuv_format][0])); - if (active_pps) - { + if (active_pps) { if (active_pps->entropy_coding_mode_flag == CAVLC) - fprintf(p_log," CAVLC|"); + fprintf(p_log, " CAVLC|"); else - fprintf(p_log," CABAC|"); + fprintf(p_log, " CABAC|"); } - fprintf(p_log,"%6.3f|",snr->snr1[0]); - fprintf(p_log,"%6.3f|",snr->snr1[1]); - fprintf(p_log,"%6.3f|",snr->snr1[2]); - fprintf(p_log,"%6.3f|",snr->snra[0]); - fprintf(p_log,"%6.3f|",snr->snra[1]); - fprintf(p_log,"%6.3f|",snr->snra[2]); - fprintf(p_log,"\n"); + fprintf(p_log, "%6.3f|", snr->snr1[0]); + fprintf(p_log, "%6.3f|", snr->snr1[1]); + fprintf(p_log, "%6.3f|", snr->snr1[2]); + fprintf(p_log, "%6.3f|", snr->snra[0]); + fprintf(p_log, "%6.3f|", snr->snra[1]); + fprintf(p_log, "%6.3f|", snr->snra[2]); + fprintf(p_log, "\n"); fclose(p_log); - snprintf(string, OUTSTRING_SIZE,"%s", DATADECFILE); - p_log=fopen(string,"a"); + snprintf(string, OUTSTRING_SIZE, "%s", DATADECFILE); + p_log = fopen(string, "a"); - if(p_Vid->Bframe_ctr != 0) // B picture used + if (p_Vid->Bframe_ctr != 0) // B picture used { - fprintf(p_log, "%3d %2d %2d %2.2f %2.2f %2.2f %5d " - "%2.2f %2.2f %2.2f %5d " - "%2.2f %2.2f %2.2f %5d %.3f\n", - p_Vid->number, 0, p_Vid->ppSliceList[0]->qp, - snr->snr1[0], - snr->snr1[1], - snr->snr1[2], - 0, - 0.0, - 0.0, - 0.0, - 0, - snr->snra[0], - snr->snra[1], - snr->snra[2], - 0, - (double)0.001*p_Vid->tot_time/(p_Vid->number + p_Vid->Bframe_ctr - 1)); - } - else - { - fprintf(p_log, "%3d %2d %2d %2.2f %2.2f %2.2f %5d " - "%2.2f %2.2f %2.2f %5d " - "%2.2f %2.2f %2.2f %5d %.3f\n", - p_Vid->number, 0, p_Vid->ppSliceList[0]? p_Vid->ppSliceList[0]->qp: 0, - snr->snr1[0], - snr->snr1[1], - snr->snr1[2], - 0, - 0.0, - 0.0, - 0.0, - 0, - snr->snra[0], - snr->snra[1], - snr->snra[2], - 0, - p_Vid->number ? ((double)0.001*p_Vid->tot_time/p_Vid->number) : 0.0); + fprintf(p_log, + "%3d %2d %2d %2.2f %2.2f %2.2f %5d " + "%2.2f %2.2f %2.2f %5d " + "%2.2f %2.2f %2.2f %5d %.3f\n", + p_Vid->number, 0, p_Vid->ppSliceList[0]->qp, snr->snr1[0], + snr->snr1[1], snr->snr1[2], 0, 0.0, 0.0, 0.0, 0, snr->snra[0], + snr->snra[1], snr->snra[2], 0, + (double)0.001 * p_Vid->tot_time / + (p_Vid->number + p_Vid->Bframe_ctr - 1)); + } else { + fprintf(p_log, + "%3d %2d %2d %2.2f %2.2f %2.2f %5d " + "%2.2f %2.2f %2.2f %5d " + "%2.2f %2.2f %2.2f %5d %.3f\n", + p_Vid->number, 0, + p_Vid->ppSliceList[0] ? p_Vid->ppSliceList[0]->qp : 0, snr->snr1[0], + snr->snr1[1], snr->snr1[2], 0, 0.0, 0.0, 0.0, 0, snr->snra[0], + snr->snra[1], snr->snra[2], 0, + p_Vid->number ? ((double)0.001 * p_Vid->tot_time / p_Vid->number) + : 0.0); } fclose(p_log); } @@ -642,40 +634,37 @@ static void Report(VideoParameters *p_Vid) ************************************************************************ */ -DataPartition *AllocPartition(int n) -{ +DataPartition *AllocPartition(int n) { DataPartition *partArr, *dataPart; int i; - partArr = (DataPartition *) calloc(n, sizeof(DataPartition)); - if (partArr == NULL) - { - snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for Data Partition failed"); + partArr = (DataPartition *)calloc(n, sizeof(DataPartition)); + if (partArr == NULL) { + snprintf(errortext, ET_SIZE, + "AllocPartition: Memory allocation for Data Partition failed"); error(errortext, 100); } - for (i=0; ibitstream = (Bitstream *) calloc(1, sizeof(Bitstream)); - if (dataPart->bitstream == NULL) - { - snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for Bitstream failed"); + dataPart->bitstream = (Bitstream *)calloc(1, sizeof(Bitstream)); + if (dataPart->bitstream == NULL) { + snprintf(errortext, ET_SIZE, + "AllocPartition: Memory allocation for Bitstream failed"); error(errortext, 100); } - dataPart->bitstream->streamBuffer = (byte *) calloc(MAX_CODED_FRAME_SIZE, sizeof(byte)); - if (dataPart->bitstream->streamBuffer == NULL) - { - snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for streamBuffer failed"); + dataPart->bitstream->streamBuffer = + (byte *)calloc(MAX_CODED_FRAME_SIZE, sizeof(byte)); + if (dataPart->bitstream->streamBuffer == NULL) { + snprintf(errortext, ET_SIZE, + "AllocPartition: Memory allocation for streamBuffer failed"); error(errortext, 100); } } return partArr; } - - - /*! ************************************************************************ * \brief @@ -691,22 +680,19 @@ DataPartition *AllocPartition(int n) * n must be the same as for the corresponding call of AllocPartition ************************************************************************ */ -void FreePartition (DataPartition *dp, int n) -{ +void FreePartition(DataPartition *dp, int n) { int i; - assert (dp != NULL); - assert (dp->bitstream != NULL); - assert (dp->bitstream->streamBuffer != NULL); - for (i=0; istreamBuffer); - free (dp[i].bitstream); + assert(dp != NULL); + assert(dp->bitstream != NULL); + assert(dp->bitstream->streamBuffer != NULL); + for (i = 0; i < n; ++i) { + free(dp[i].bitstream->streamBuffer); + free(dp[i].bitstream); } - free (dp); + free(dp); } - /*! ************************************************************************ * \brief @@ -717,34 +703,44 @@ void FreePartition (DataPartition *dp, int n) * Input Parameters InputParameters *p_Inp, VideoParameters *p_Vid ************************************************************************ */ -Slice *malloc_slice(InputParameters *p_Inp, VideoParameters *p_Vid) -{ +Slice *malloc_slice(InputParameters *p_Inp, VideoParameters *p_Vid) { int i, j, memory_size = 0; Slice *currSlice; - currSlice = (Slice *) calloc(1, sizeof(Slice)); - if ( currSlice == NULL) - { - snprintf(errortext, ET_SIZE, "Memory allocation for Slice datastruct in NAL-mode %d failed", p_Inp->FileFormat); - error(errortext,100); + currSlice = (Slice *)calloc(1, sizeof(Slice)); + if (currSlice == NULL) { + snprintf(errortext, ET_SIZE, + "Memory allocation for Slice datastruct in NAL-mode %d failed", + p_Inp->FileFormat); + error(errortext, 100); } // create all context models currSlice->mot_ctx = create_contexts_MotionInfo(); currSlice->tex_ctx = create_contexts_TextureInfo(); - currSlice->max_part_nr = 3; //! assume data partitioning (worst case) for the following mallocs() + currSlice->max_part_nr = + 3; //! assume data partitioning (worst case) for the following mallocs() currSlice->partArr = AllocPartition(currSlice->max_part_nr); - memory_size += get_mem3Dint(&(currSlice->wp_weight), 2, MAX_REFERENCE_PICTURES, 3); - memory_size += get_mem3Dint(&(currSlice->wp_offset), 6, MAX_REFERENCE_PICTURES, 3); - memory_size += get_mem4Dint(&(currSlice->wbp_weight), 6, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 3); + memory_size += + get_mem3Dint(&(currSlice->wp_weight), 2, MAX_REFERENCE_PICTURES, 3); + memory_size += + get_mem3Dint(&(currSlice->wp_offset), 6, MAX_REFERENCE_PICTURES, 3); + memory_size += + get_mem4Dint(&(currSlice->wbp_weight), 6, MAX_REFERENCE_PICTURES, + MAX_REFERENCE_PICTURES, 3); - memory_size += get_mem3Dpel(&(currSlice->mb_pred), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE); - memory_size += get_mem3Dpel(&(currSlice->mb_rec ), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE); - memory_size += get_mem3Dint(&(currSlice->mb_rres), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE); - memory_size += get_mem3Dint(&(currSlice->cof ), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE); - // memory_size += get_mem3Dint(&(currSlice->fcf ), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + memory_size += get_mem3Dpel(&(currSlice->mb_pred), MAX_PLANE, MB_BLOCK_SIZE, + MB_BLOCK_SIZE); + memory_size += get_mem3Dpel(&(currSlice->mb_rec), MAX_PLANE, MB_BLOCK_SIZE, + MB_BLOCK_SIZE); + memory_size += get_mem3Dint(&(currSlice->mb_rres), MAX_PLANE, MB_BLOCK_SIZE, + MB_BLOCK_SIZE); + memory_size += + get_mem3Dint(&(currSlice->cof), MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + // memory_size += get_mem3Dint(&(currSlice->fcf ), MAX_PLANE, + // MB_BLOCK_SIZE, MB_BLOCK_SIZE); allocate_pred_mem(currSlice); @@ -754,29 +750,25 @@ Slice *malloc_slice(InputParameters *p_Inp, VideoParameters *p_Vid) currSlice->anchor_pic_flag = 0; #endif // reference flag initialization - for(i=0;i<17;++i) - { + for (i = 0; i < 17; ++i) { currSlice->ref_flag[i] = 1; } - for (i = 0; i < 6; i++) - { - currSlice->listX[i] = calloc(MAX_LIST_SIZE, sizeof (StorablePicture*)); // +1 for reordering - if (NULL==currSlice->listX[i]) + for (i = 0; i < 6; i++) { + currSlice->listX[i] = + calloc(MAX_LIST_SIZE, sizeof(StorablePicture *)); // +1 for reordering + if (NULL == currSlice->listX[i]) no_mem_exit("malloc_slice: currSlice->listX[i]"); } - for (j = 0; j < 6; j++) - { - for (i = 0; i < MAX_LIST_SIZE; i++) - { + for (j = 0; j < 6; j++) { + for (i = 0; i < MAX_LIST_SIZE; i++) { currSlice->listX[j][i] = NULL; } - currSlice->listXsize[j]=0; + currSlice->listXsize[j] = 0; } return currSlice; } - /*! ************************************************************************ * \brief @@ -787,43 +779,38 @@ Slice *malloc_slice(InputParameters *p_Inp, VideoParameters *p_Vid) * Input Parameters Slice *currSlice ************************************************************************ */ -static void free_slice(Slice *currSlice) -{ +static void free_slice(Slice *currSlice) { int i; free_pred_mem(currSlice); - free_mem3Dint(currSlice->cof ); + free_mem3Dint(currSlice->cof); free_mem3Dint(currSlice->mb_rres); - free_mem3Dpel(currSlice->mb_rec ); + free_mem3Dpel(currSlice->mb_rec); free_mem3Dpel(currSlice->mb_pred); - - free_mem3Dint(currSlice->wp_weight ); - free_mem3Dint(currSlice->wp_offset ); + free_mem3Dint(currSlice->wp_weight); + free_mem3Dint(currSlice->wp_offset); free_mem4Dint(currSlice->wbp_weight); - FreePartition (currSlice->partArr, 3); + FreePartition(currSlice->partArr, 3); - //if (1) + // if (1) { // delete all context models delete_contexts_MotionInfo(currSlice->mot_ctx); delete_contexts_TextureInfo(currSlice->tex_ctx); } - for (i=0; i<6; i++) - { - if (currSlice->listX[i]) - { - free (currSlice->listX[i]); + for (i = 0; i < 6; i++) { + if (currSlice->listX[i]) { + free(currSlice->listX[i]); currSlice->listX[i] = NULL; } } - while (currSlice->dec_ref_pic_marking_buffer) - { - DecRefPicMarking_t *tmp_drpm=currSlice->dec_ref_pic_marking_buffer; - currSlice->dec_ref_pic_marking_buffer=tmp_drpm->Next; - free (tmp_drpm); + while (currSlice->dec_ref_pic_marking_buffer) { + DecRefPicMarking_t *tmp_drpm = currSlice->dec_ref_pic_marking_buffer; + currSlice->dec_ref_pic_marking_buffer = tmp_drpm->Next; + free(tmp_drpm); } free(currSlice); @@ -844,13 +831,11 @@ static void free_slice(Slice *currSlice) * Number of allocated bytes *********************************************************************** */ -int init_global_buffers(VideoParameters *p_Vid) -{ - int memory_size=0; +int init_global_buffers(VideoParameters *p_Vid) { + int memory_size = 0; int i; - if (p_Vid->global_init_done) - { + if (p_Vid->global_init_done) { free_global_buffers(p_Vid); } @@ -858,78 +843,73 @@ int init_global_buffers(VideoParameters *p_Vid) memory_size += get_mem2Dpel(&p_Vid->imgY_ref, p_Vid->height, p_Vid->width); if (p_Vid->active_sps->chroma_format_idc != YUV400) - memory_size += get_mem3Dpel(&p_Vid->imgUV_ref, 2, p_Vid->height_cr, p_Vid->width_cr); + memory_size += + get_mem3Dpel(&p_Vid->imgUV_ref, 2, p_Vid->height_cr, p_Vid->width_cr); else - p_Vid->imgUV_ref=NULL; + p_Vid->imgUV_ref = NULL; // allocate memory in structure p_Vid - if( (p_Vid->separate_colour_plane_flag != 0) ) - { - for( i=0; imb_data_JV[i]) = (Macroblock *) calloc(p_Vid->FrameSizeInMbs, sizeof(Macroblock))) == NULL) + if ((p_Vid->separate_colour_plane_flag != 0)) { + for (i = 0; i < MAX_PLANE; ++i) { + if (((p_Vid->mb_data_JV[i]) = (Macroblock *)calloc( + p_Vid->FrameSizeInMbs, sizeof(Macroblock))) == NULL) no_mem_exit("init_global_buffers: p_Vid->mb_data"); } p_Vid->mb_data = NULL; - } - else - { - if(((p_Vid->mb_data) = (Macroblock *) calloc(p_Vid->FrameSizeInMbs, sizeof(Macroblock))) == NULL) + } else { + if (((p_Vid->mb_data) = (Macroblock *)calloc(p_Vid->FrameSizeInMbs, + sizeof(Macroblock))) == NULL) no_mem_exit("init_global_buffers: p_Vid->mb_data"); } - if( (p_Vid->separate_colour_plane_flag != 0) ) - { - for( i=0; iintra_block_JV[i]) = (signed char*) calloc(p_Vid->FrameSizeInMbs, sizeof(signed char))) == NULL) + if ((p_Vid->separate_colour_plane_flag != 0)) { + for (i = 0; i < MAX_PLANE; ++i) { + if (((p_Vid->intra_block_JV[i]) = (signed char *)calloc( + p_Vid->FrameSizeInMbs, sizeof(signed char))) == NULL) no_mem_exit("init_global_buffers: p_Vid->intra_block_JV"); } p_Vid->intra_block = NULL; - } - else - { - if(((p_Vid->intra_block) = (signed char*) calloc(p_Vid->FrameSizeInMbs, sizeof(signed char))) == NULL) + } else { + if (((p_Vid->intra_block) = (signed char *)calloc( + p_Vid->FrameSizeInMbs, sizeof(signed char))) == NULL) no_mem_exit("init_global_buffers: p_Vid->intra_block"); } - - //memory_size += get_mem2Dint(&PicPos,p_Vid->FrameSizeInMbs + 1,2); //! Helper array to access macroblock positions. We add 1 to also consider last MB. - if(((PicPos) = (BlockPos*) calloc(p_Vid->FrameSizeInMbs + 1, sizeof(BlockPos))) == NULL) + // memory_size += get_mem2Dint(&PicPos,p_Vid->FrameSizeInMbs + 1,2); //! + // Helper array to access macroblock positions. We add 1 to also consider last + // MB. + if (((PicPos) = (BlockPos *)calloc(p_Vid->FrameSizeInMbs + 1, + sizeof(BlockPos))) == NULL) no_mem_exit("init_global_buffers: PicPos"); - - for (i = 0; i < (int) p_Vid->FrameSizeInMbs + 1;++i) - { - PicPos[i].x = (short) (i % p_Vid->PicWidthInMbs); - PicPos[i].y = (short) (i / p_Vid->PicWidthInMbs); + for (i = 0; i < (int)p_Vid->FrameSizeInMbs + 1; ++i) { + PicPos[i].x = (short)(i % p_Vid->PicWidthInMbs); + PicPos[i].y = (short)(i / p_Vid->PicWidthInMbs); } - if( (p_Vid->separate_colour_plane_flag != 0) ) - { - for( i=0; iipredmode_JV[i]), 4*p_Vid->FrameHeightInMbs, 4*p_Vid->PicWidthInMbs); + if ((p_Vid->separate_colour_plane_flag != 0)) { + for (i = 0; i < MAX_PLANE; ++i) { + get_mem2D(&(p_Vid->ipredmode_JV[i]), 4 * p_Vid->FrameHeightInMbs, + 4 * p_Vid->PicWidthInMbs); } p_Vid->ipredmode = NULL; - } - else - memory_size += get_mem2D(&(p_Vid->ipredmode), 4*p_Vid->FrameHeightInMbs, 4*p_Vid->PicWidthInMbs); + } else + memory_size += get_mem2D(&(p_Vid->ipredmode), 4 * p_Vid->FrameHeightInMbs, + 4 * p_Vid->PicWidthInMbs); // CAVLC mem - memory_size += get_mem4D(&(p_Vid->nz_coeff), p_Vid->FrameSizeInMbs, 3, BLOCK_SIZE, BLOCK_SIZE); - if( (p_Vid->separate_colour_plane_flag != 0) ) - { - for( i=0; isiblock_JV[i]), p_Vid->FrameHeightInMbs, p_Vid->PicWidthInMbs); - if(p_Vid->siblock_JV[i]== NULL) + memory_size += get_mem4D(&(p_Vid->nz_coeff), p_Vid->FrameSizeInMbs, 3, + BLOCK_SIZE, BLOCK_SIZE); + if ((p_Vid->separate_colour_plane_flag != 0)) { + for (i = 0; i < MAX_PLANE; ++i) { + get_mem2Dint(&(p_Vid->siblock_JV[i]), p_Vid->FrameHeightInMbs, + p_Vid->PicWidthInMbs); + if (p_Vid->siblock_JV[i] == NULL) no_mem_exit("init_global_buffers: p_Vid->siblock_JV"); } p_Vid->siblock = NULL; - } - else - { - memory_size += get_mem2Dint(&(p_Vid->siblock), p_Vid->FrameHeightInMbs, p_Vid->PicWidthInMbs); + } else { + memory_size += get_mem2Dint(&(p_Vid->siblock), p_Vid->FrameHeightInMbs, + p_Vid->PicWidthInMbs); } init_qp_process(p_Vid); @@ -954,59 +934,49 @@ int init_global_buffers(VideoParameters *p_Vid) * ************************************************************************ */ -void free_global_buffers(VideoParameters *p_Vid) -{ - free_mem2Dpel (p_Vid->imgY_ref); +void free_global_buffers(VideoParameters *p_Vid) { + free_mem2Dpel(p_Vid->imgY_ref); if (p_Vid->imgUV_ref) - free_mem3Dpel (p_Vid->imgUV_ref); + free_mem3Dpel(p_Vid->imgUV_ref); // CAVLC free mem free_mem4D(p_Vid->nz_coeff); // free mem, allocated for structure p_Vid - if( (p_Vid->separate_colour_plane_flag != 0) ) - { + if ((p_Vid->separate_colour_plane_flag != 0)) { int i; - for(i=0; imb_data_JV[i]); p_Vid->mb_data_JV[i] = NULL; free_mem2Dint(p_Vid->siblock_JV[i]); p_Vid->siblock_JV[i] = NULL; free_mem2D(p_Vid->ipredmode_JV[i]); p_Vid->ipredmode_JV[i] = NULL; - free (p_Vid->intra_block_JV[i]); + free(p_Vid->intra_block_JV[i]); p_Vid->intra_block_JV[i] = NULL; - } - } - else - { - if (p_Vid->mb_data != NULL) - { + } + } else { + if (p_Vid->mb_data != NULL) { free(p_Vid->mb_data); p_Vid->mb_data = NULL; } - if(p_Vid->siblock) - { + if (p_Vid->siblock) { free_mem2Dint(p_Vid->siblock); p_Vid->siblock = NULL; } - if(p_Vid->ipredmode) - { + if (p_Vid->ipredmode) { free_mem2D(p_Vid->ipredmode); p_Vid->ipredmode = NULL; } - if(p_Vid->intra_block) - { - free (p_Vid->intra_block); + if (p_Vid->intra_block) { + free(p_Vid->intra_block); p_Vid->intra_block = NULL; } } - if(PicPos) - { + if (PicPos) { free(PicPos); - PicPos=NULL; + PicPos = NULL; } free_qp_matrices(p_Vid); @@ -1014,27 +984,23 @@ void free_global_buffers(VideoParameters *p_Vid) p_Vid->global_init_done = 0; } -void report_stats_on_error(void) -{ - //free_encoder_memory(p_Vid); - exit (-1); +void report_stats_on_error(void) { + // free_encoder_memory(p_Vid); + exit(-1); } -void ClearDecPicList(VideoParameters *p_Vid) -{ +void ClearDecPicList(VideoParameters *p_Vid) { DecodedPicList *pPic = p_Vid->pDecOuputPic, *pPrior = NULL; - //find the head first; - while(pPic && !pPic->bValid) - { + // find the head first; + while (pPic && !pPic->bValid) { pPrior = pPic; pPic = pPic->pNext; } - if(pPic && (pPic != p_Vid->pDecOuputPic)) - { - //move all nodes before pPic to the end; + if (pPic && (pPic != p_Vid->pDecOuputPic)) { + // move all nodes before pPic to the end; DecodedPicList *pPicTail = pPic; - while(pPicTail->pNext) + while (pPicTail->pNext) pPicTail = pPicTail->pNext; pPicTail->pNext = p_Vid->pDecOuputPic; @@ -1043,28 +1009,22 @@ void ClearDecPicList(VideoParameters *p_Vid) } } -DecodedPicList *GetOneAvailDecPicFromList(DecodedPicList *pDecPicList, int b3D) -{ +DecodedPicList *GetOneAvailDecPicFromList(DecodedPicList *pDecPicList, + int b3D) { DecodedPicList *pPic = pDecPicList, *pPrior = NULL; - if(b3D) - { - while(pPic && (pPic->bValid==3)) - { - pPrior = pPic; - pPic = pPic->pNext; - } - } - else - { - while(pPic && (pPic->bValid)) - { - pPrior = pPic; - pPic = pPic->pNext; - } + if (b3D) { + while (pPic && (pPic->bValid == 3)) { + pPrior = pPic; + pPic = pPic->pNext; + } + } else { + while (pPic && (pPic->bValid)) { + pPrior = pPic; + pPic = pPic->pNext; + } } - if(!pPic) - { + if (!pPic) { pPic = (DecodedPicList *)calloc(1, sizeof(*pPic)); pPrior->pNext = pPic; } @@ -1073,12 +1033,11 @@ DecodedPicList *GetOneAvailDecPicFromList(DecodedPicList *pDecPicList, int b3D) } /************************************ Interface: OpenDecoder -Return: +Return: 0: NOERROR; <0: ERROR; ************************************/ -int OpenDecoder(InputParameters *p_Inp) -{ +int OpenDecoder(InputParameters *p_Inp) { #if (MVC_EXTENSION_ENABLE) int i; #endif @@ -1086,62 +1045,64 @@ int OpenDecoder(InputParameters *p_Inp) DecoderParams *pDecoder; iRet = alloc_decoder(&p_Dec); - if(iRet) - { - return (iRet|DEC_ERRMASK); + if (iRet) { + return (iRet | DEC_ERRMASK); } pDecoder = p_Dec; - //Configure (pDecoder->p_Vid, pDecoder->p_Inp, argc, argv); + // Configure (pDecoder->p_Vid, pDecoder->p_Inp, argc, argv); memcpy(pDecoder->p_Inp, p_Inp, sizeof(InputParameters)); pDecoder->p_Vid->conceal_mode = pDecoder->p_Inp->conceal_mode; pDecoder->p_Vid->ref_poc_gap = pDecoder->p_Inp->ref_poc_gap; pDecoder->p_Vid->poc_gap = pDecoder->p_Inp->poc_gap; #if TRACE - if ((pDecoder->p_trace = fopen(TRACEFILE,"w"))==0) // append new statistic at the end + if ((pDecoder->p_trace = fopen(TRACEFILE, "w")) == + 0) // append new statistic at the end { - snprintf(errortext, ET_SIZE, "Error open file %s!",TRACEFILE); - //error(errortext,500); + snprintf(errortext, ET_SIZE, "Error open file %s!", TRACEFILE); + // error(errortext,500); return -1; } #endif #if (!MVC_EXTENSION_ENABLE) - if ((pDecoder->p_Vid->p_out = open(pDecoder->p_Inp->outfile, OPENFLAGS_WRITE, OPEN_PERMISSIONS))==-1) - { - snprintf(errortext, ET_SIZE, "Error open file %s ",p_Inp->outfile); - error(errortext,500); + if ((pDecoder->p_Vid->p_out = open(pDecoder->p_Inp->outfile, OPENFLAGS_WRITE, + OPEN_PERMISSIONS)) == -1) { + snprintf(errortext, ET_SIZE, "Error open file %s ", p_Inp->outfile); + error(errortext, 500); } #endif - if(strlen(pDecoder->p_Inp->reffile)>0 && strcmp(pDecoder->p_Inp->reffile, "\"\"")) - { - if ((pDecoder->p_Vid->p_ref = open(pDecoder->p_Inp->reffile, OPENFLAGS_READ))==-1) - { - fprintf(stdout," Input reference file : %s does not exist \n",pDecoder->p_Inp->reffile); - fprintf(stdout," SNR values are not available\n"); - } - } - else + if (strlen(pDecoder->p_Inp->reffile) > 0 && + strcmp(pDecoder->p_Inp->reffile, "\"\"")) { + if ((pDecoder->p_Vid->p_ref = + open(pDecoder->p_Inp->reffile, OPENFLAGS_READ)) == -1) { + fprintf(stdout, + " Input reference file : %s does not exist \n", + pDecoder->p_Inp->reffile); + fprintf(stdout, " SNR values " + "are not available\n"); + } + } else pDecoder->p_Vid->p_ref = -1; initBitsFile(pDecoder->p_Vid, pDecoder->p_Inp->FileFormat); - pDecoder->p_Vid->bitsfile->OpenBitsFile(pDecoder->p_Vid, pDecoder->p_Inp->infile); - + pDecoder->p_Vid->bitsfile->OpenBitsFile(pDecoder->p_Vid, + pDecoder->p_Inp->infile); + // Allocate Slice data struct - //pDecoder->p_Vid->currentSlice = NULL; //malloc_slice(pDecoder->p_Inp, pDecoder->p_Vid); - + // pDecoder->p_Vid->currentSlice = NULL; //malloc_slice(pDecoder->p_Inp, + // pDecoder->p_Vid); + init_old_slice(pDecoder->p_Vid->old_slice); init(pDecoder->p_Vid); - - init_out_buffer(pDecoder->p_Vid); + init_out_buffer(pDecoder->p_Vid); #if (MVC_EXTENSION_ENABLE) pDecoder->p_Vid->p_out = -1; - //multiview output file initialization - for(i=0;ip_Vid->p_out_mvc[i] = -1; } pDecoder->p_Vid->active_sps = NULL; @@ -1154,27 +1115,21 @@ int OpenDecoder(InputParameters *p_Inp) /************************************ Interface: DecodeOneFrame -Return: +Return: 0: NOERROR; 1: Finished decoding; others: Error Code; ************************************/ -int DecodeOneFrame(DecodedPicList **ppDecPicList) -{ +int DecodeOneFrame(DecodedPicList **ppDecPicList) { int iRet; DecoderParams *pDecoder = p_Dec; ClearDecPicList(pDecoder->p_Vid); iRet = decode_one_frame(pDecoder); - if(iRet == SOP) - { + if (iRet == SOP) { iRet = DEC_SUCCEED; - } - else if(iRet == EOS) - { + } else if (iRet == EOS) { iRet = DEC_EOS; - } - else - { + } else { iRet |= DEC_ERRMASK; } @@ -1182,10 +1137,9 @@ int DecodeOneFrame(DecodedPicList **ppDecPicList) return iRet; } -int FinitDecoder(DecodedPicList **ppDecPicList) -{ +int FinitDecoder(DecodedPicList **ppDecPicList) { DecoderParams *pDecoder = p_Dec; - if(!pDecoder) + if (!pDecoder) return DEC_GEN_NOERR; ClearDecPicList(pDecoder->p_Vid); #if (MVC_EXTENSION_ENABLE) @@ -1196,23 +1150,22 @@ int FinitDecoder(DecodedPicList **ppDecPicList) #if (PAIR_FIELDS_IN_OUTPUT) flush_pending_output(pDecoder->p_Vid, pDecoder->p_Vid->p_out); #endif - ResetAnnexB(pDecoder->p_Vid->annex_b); + ResetAnnexB(pDecoder->p_Vid->annex_b); pDecoder->p_Vid->newframe = 0; pDecoder->p_Vid->previous_frame_num = 0; *ppDecPicList = pDecoder->p_Vid->pDecOuputPic; return DEC_GEN_NOERR; } -int CloseDecoder() -{ +int CloseDecoder() { #if (MVC_EXTENSION_ENABLE) int i; #endif DecoderParams *pDecoder = p_Dec; - if(!pDecoder) + if (!pDecoder) return DEC_CLOSE_NOERR; - + Report(pDecoder->p_Vid); FmoFinit(pDecoder->p_Vid); free_global_buffers(pDecoder->p_Vid); @@ -1220,10 +1173,8 @@ int CloseDecoder() pDecoder->p_Vid->bitsfile->CloseBitsFile(pDecoder->p_Vid); #if (MVC_EXTENSION_ENABLE) - for(i=0;ip_Vid->p_out_mvc[i] != -1) - { + for (i = 0; i < MAX_VIEW_NUM; i++) { + if (pDecoder->p_Vid->p_out_mvc[i] != -1) { close(pDecoder->p_Vid->p_out_mvc[i]); } } @@ -1242,16 +1193,15 @@ int CloseDecoder() CleanUpPPS(pDecoder->p_Vid); #if (MVC_EXTENSION_ENABLE) - for(i=0; ip_Vid->SubsetSeqParSet+i); + for (i = 0; i < MAXSPS; i++) { + reset_subset_sps(pDecoder->p_Vid->SubsetSeqParSet + i); } #endif free_dpb(pDecoder->p_Vid->p_Dpb); uninit_out_buffer(pDecoder->p_Vid); - free (pDecoder->p_Inp); - free_img (pDecoder->p_Vid); + free(pDecoder->p_Inp); + free_img(pDecoder->p_Vid); free(pDecoder); return DEC_CLOSE_NOERR; diff --git a/src/common/ldecod_src/leaky_bucket.c b/src/common/ldecod_src/leaky_bucket.c index 46b2ef6..51338cb 100644 --- a/src/common/ldecod_src/leaky_bucket.c +++ b/src/common/ldecod_src/leaky_bucket.c @@ -4,10 +4,12 @@ * \file leaky_bucket.c * * \brief - * Calculate if decoder leaky bucket parameters meets HRD constraints specified by encoder. + * Calculate if decoder leaky bucket parameters meets HRD constraints + *specified by encoder. * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Shankar Regunathan ************************************************************************ */ @@ -35,51 +37,42 @@ *********************************************************************** */ /* gets unsigned double stored in Big Endian Order */ -unsigned long GetBigDoubleWord(FILE *fp) -{ +unsigned long GetBigDoubleWord(FILE *fp) { unsigned long dw; - dw = (unsigned long) (fgetc(fp) & 0xFF); - dw = ((unsigned long) (fgetc(fp) & 0xFF)) | (dw << 0x08); - dw = ((unsigned long) (fgetc(fp) & 0xFF)) | (dw << 0x08); - dw = ((unsigned long) (fgetc(fp) & 0xFF)) | (dw << 0x08); - return(dw); + dw = (unsigned long)(fgetc(fp) & 0xFF); + dw = ((unsigned long)(fgetc(fp) & 0xFF)) | (dw << 0x08); + dw = ((unsigned long)(fgetc(fp) & 0xFF)) | (dw << 0x08); + dw = ((unsigned long)(fgetc(fp) & 0xFF)) | (dw << 0x08); + return (dw); } /*! *********************************************************************** * \brief - * Calculates if decoder leaky bucket parameters meets HRD constraints specified by encoder. - * \param p_Inp - * Structure which contains decoder leaky bucket parameters. - * \return - * None - * \par SideEffects - * None. - * \par Notes - * Failure if LeakyBucketParam file is missing or if it does not have - * the correct number of entries. - * \author - * Shankar Regunathan shanre@microsoft.com + * Calculates if decoder leaky bucket parameters meets HRD constraints + *specified by encoder. \param p_Inp Structure which contains decoder leaky + *bucket parameters. \return None \par SideEffects None. \par Notes Failure if + *LeakyBucketParam file is missing or if it does not have the correct number of + *entries. \author Shankar Regunathan shanre@microsoft.com * \date * December 06, 2001. *********************************************************************** */ /* Main Routine to verify HRD compliance */ -void calc_buffer(InputParameters *p_Inp) -{ +void calc_buffer(InputParameters *p_Inp) { unsigned long NumberLeakyBuckets, *Rmin, *Bmin, *Fmin; - float B_interp, F_interp; + float B_interp, F_interp; unsigned long iBucket; float dnr, frac1, frac2; unsigned long R_decoder, B_decoder, F_decoder; FILE *outf; - if ((outf=fopen(p_Inp->LeakyBucketParamFile,"rb"))==NULL) - { - snprintf(errortext, ET_SIZE, "Error open file %s \n",p_Inp->LeakyBucketParamFile); - error(errortext,1); - } + if ((outf = fopen(p_Inp->LeakyBucketParamFile, "rb")) == NULL) { + snprintf(errortext, ET_SIZE, "Error open file %s \n", + p_Inp->LeakyBucketParamFile); + error(errortext, 1); + } NumberLeakyBuckets = GetBigDoubleWord(outf); printf(" Number Leaky Buckets: %8ld \n\n", NumberLeakyBuckets); @@ -87,8 +80,7 @@ void calc_buffer(InputParameters *p_Inp) Bmin = calloc(NumberLeakyBuckets, sizeof(unsigned long)); Fmin = calloc(NumberLeakyBuckets, sizeof(unsigned long)); - for(iBucket =0; iBucket < NumberLeakyBuckets; iBucket++) - { + for (iBucket = 0; iBucket < NumberLeakyBuckets; iBucket++) { Rmin[iBucket] = GetBigDoubleWord(outf); Bmin[iBucket] = GetBigDoubleWord(outf); Fmin[iBucket] = GetBigDoubleWord(outf); @@ -100,34 +92,33 @@ void calc_buffer(InputParameters *p_Inp) F_decoder = p_Inp->F_decoder; B_decoder = p_Inp->B_decoder; - for( iBucket =0; iBucket < NumberLeakyBuckets; iBucket++) - { - if(R_decoder < Rmin[iBucket]) + for (iBucket = 0; iBucket < NumberLeakyBuckets; iBucket++) { + if (R_decoder < Rmin[iBucket]) break; } printf("\n"); - if(iBucket > 0 ) - { - if(iBucket < NumberLeakyBuckets) - { - dnr = (float) (Rmin[iBucket] - Rmin[iBucket-1]); - frac1 = (float) (R_decoder - Rmin[iBucket-1]); - frac2 = (float) (Rmin[iBucket] - R_decoder); - B_interp = (float) (Bmin[iBucket] * frac1 + Bmin[iBucket-1] * frac2) /dnr; - F_interp = (float) (Fmin[iBucket] * frac1 + Fmin[iBucket-1] * frac2) /dnr; + if (iBucket > 0) { + if (iBucket < NumberLeakyBuckets) { + dnr = (float)(Rmin[iBucket] - Rmin[iBucket - 1]); + frac1 = (float)(R_decoder - Rmin[iBucket - 1]); + frac2 = (float)(Rmin[iBucket] - R_decoder); + B_interp = + (float)(Bmin[iBucket] * frac1 + Bmin[iBucket - 1] * frac2) / dnr; + F_interp = + (float)(Fmin[iBucket] * frac1 + Fmin[iBucket - 1] * frac2) / dnr; + } else { + B_interp = (float)Bmin[iBucket - 1]; + F_interp = (float)Fmin[iBucket - 1]; } - else { - B_interp = (float) Bmin[iBucket-1]; - F_interp = (float) Fmin[iBucket-1]; - } - printf(" Min.buffer %8.2f Decoder buffer size %ld \n Minimum Delay %8.2f DecoderDelay %ld \n", B_interp, B_decoder, F_interp, F_decoder); - if(B_decoder > B_interp && F_decoder > F_interp) + printf(" Min.buffer %8.2f Decoder buffer size %ld \n Minimum Delay %8.2f " + "DecoderDelay %ld \n", + B_interp, B_decoder, F_interp, F_decoder); + if (B_decoder > B_interp && F_decoder > F_interp) printf(" HRD Compliant \n"); else printf(" HRD Non Compliant \n"); - } - else { // (iBucket = 0) + } else { // (iBucket = 0) printf(" Decoder Rate is too small; HRD cannot be verified \n"); } diff --git a/src/common/ldecod_src/loopFilter.c b/src/common/ldecod_src/loopFilter.c index fb770bb..561c456 100644 --- a/src/common/ldecod_src/loopFilter.c +++ b/src/common/ldecod_src/loopFilter.c @@ -9,24 +9,27 @@ * * \author * Contributors: - * - Peter List Peter.List@t-systems.de: Original code (13-Aug-2001) - * - Jani Lainema Jani.Lainema@nokia.com: Some bug fixing, removal of recursiveness (16-Aug-2001) - * - Peter List Peter.List@t-systems.de: inplace filtering and various simplifications (10-Jan-2002) - * - Anthony Joch anthony@ubvideo.com: Simplified switching between filters and - * non-recursive default filter. (08-Jul-2002) - * - Cristina Gomila cristina.gomila@thomson.net: Simplification of the chroma deblocking - * from JVT-E089 (21-Nov-2002) - * - Alexis Michael Tourapis atour@dolby.com: Speed/Architecture improvements (08-Feb-2007) + * - Peter List Peter.List@t-systems.de: Original code (13-Aug-2001) + * - Jani Lainema Jani.Lainema@nokia.com: Some bug fixing, removal of + *recursiveness (16-Aug-2001) + * - Peter List Peter.List@t-systems.de: inplace filtering and various + *simplifications (10-Jan-2002) + * - Anthony Joch anthony@ubvideo.com: Simplified switching between + *filters and non-recursive default filter. (08-Jul-2002) + * - Cristina Gomila cristina.gomila@thomson.net: Simplification of the + *chroma deblocking from JVT-E089 (21-Nov-2002) + * - Alexis Michael Tourapis atour@dolby.com: Speed/Architecture + *improvements (08-Feb-2007) ************************************************************************************* */ +#include "loopfilter.h" #include "global.h" #include "image.h" -#include "mb_access.h" -#include "loopfilter.h" #include "loop_filter.h" +#include "mb_access.h" -static void DeblockMb (VideoParameters *p_Vid, StorablePicture *p, int MbQAddr); +static void DeblockMb(VideoParameters *p_Vid, StorablePicture *p, int MbQAddr); extern void set_loop_filter_functions_mbaff(VideoParameters *p_Vid); extern void set_loop_filter_functions_normal(VideoParameters *p_Vid); @@ -38,25 +41,23 @@ extern void set_loop_filter_functions_normal(VideoParameters *p_Vid); * Filter all macroblocks in order of increasing macroblock address. ***************************************************************************************** */ -void DeblockPicture(VideoParameters *p_Vid, StorablePicture *p) -{ +void DeblockPicture(VideoParameters *p_Vid, StorablePicture *p) { unsigned i; - for (i = 0; i < p->PicSizeInMbs; ++i) - { - DeblockMb( p_Vid, p, i ) ; + for (i = 0; i < p->PicSizeInMbs; ++i) { + DeblockMb(p_Vid, p, i); } } #else -static void DeblockParallel(VideoParameters *p_Vid, StorablePicture *p, unsigned int column, int block, int n_last) -{ +static void DeblockParallel(VideoParameters *p_Vid, StorablePicture *p, + unsigned int column, int block, int n_last) { int i, j; - - for (j = 0; j < GROUP_SIZE; j++) - { + + for (j = 0; j < GROUP_SIZE; j++) { i = block++ * (p_Vid->PicWidthInMbs - 2) + column; - DeblockMb( p_Vid, p, i ) ; - if (block == n_last) break; + DeblockMb(p_Vid, p, i); + if (block == n_last) + break; } } @@ -66,19 +67,19 @@ static void DeblockParallel(VideoParameters *p_Vid, StorablePicture *p, unsigned * Filter all macroblocks in a diagonal manner to enable parallelization. ***************************************************************************************** */ -void DeblockPicture(VideoParameters *p_Vid, StorablePicture *p) -{ - int iheightMBs =(p_Vid->PicSizeInMbs/p_Vid->PicWidthInMbs); +void DeblockPicture(VideoParameters *p_Vid, StorablePicture *p) { + int iheightMBs = (p_Vid->PicSizeInMbs / p_Vid->PicWidthInMbs); unsigned int i, k = p->PicWidthInMbs + 2 * (iheightMBs - 1); - - for (i = 0; i < k; i++) - { - int nn; - int n_last = imin(iheightMBs, (i >> 1) + 1); - int n_start = (i < p->PicWidthInMbs) ? 0 : ((i - p->PicWidthInMbs) >> 1) + 1; -#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) - #pragma omp parallel for + for (i = 0; i < k; i++) { + int nn; + int n_last = imin(iheightMBs, (i >> 1) + 1); + int n_start = + (i < p->PicWidthInMbs) ? 0 : ((i - p->PicWidthInMbs) >> 1) + 1; + +#if (defined(_OPENMP) || defined(SPEC_OPENMP)) && \ + !defined(SPEC_SUPPRESS_OPENMP) && !defined(SPEC_AUTO_SUPPRESS_OPENMP) +#pragma omp parallel for #endif for (nn = n_start; nn < n_last; nn += GROUP_SIZE) DeblockParallel(p_Vid, p, i, nn, n_last); @@ -86,22 +87,18 @@ void DeblockPicture(VideoParameters *p_Vid, StorablePicture *p) } #endif - -void DeblockPicturePartially(VideoParameters *p_Vid, StorablePicture *p, int iStart, int iEnd) -{ +void DeblockPicturePartially(VideoParameters *p_Vid, StorablePicture *p, + int iStart, int iEnd) { int i; - for (i = iStart; i < imin(iEnd, (int)p->PicSizeInMbs); ++i) - { - DeblockMb( p_Vid, p, i ) ; + for (i = iStart; i < imin(iEnd, (int)p->PicSizeInMbs); ++i) { + DeblockMb(p_Vid, p, i); } } - // likely already set - see testing via asserts -static void init_neighbors(VideoParameters *p_Vid) -{ - int i,j,addr; +static void init_neighbors(VideoParameters *p_Vid) { + int i, j, addr; int width = p_Vid->PicWidthInMbs; int height = p_Vid->PicHeightInMbs; int size = p_Vid->PicSizeInMbs; @@ -128,11 +125,8 @@ static void init_neighbors(VideoParameters *p_Vid) } } - -void init_Deblock(VideoParameters *p_Vid, int mb_aff_frame_flag) -{ - if(p_Vid->yuv_format == YUV444 && p_Vid->separate_colour_plane_flag) - { +void init_Deblock(VideoParameters *p_Vid, int mb_aff_frame_flag) { + if (p_Vid->yuv_format == YUV444 && p_Vid->separate_colour_plane_flag) { change_plane_JV(p_Vid, PLANE_Y, NULL); init_neighbors(p_Dec->p_Vid); change_plane_JV(p_Vid, PLANE_U, NULL); @@ -140,15 +134,11 @@ void init_Deblock(VideoParameters *p_Vid, int mb_aff_frame_flag) change_plane_JV(p_Vid, PLANE_V, NULL); init_neighbors(p_Dec->p_Vid); change_plane_JV(p_Vid, PLANE_Y, NULL); - } - else + } else init_neighbors(p_Dec->p_Vid); - if (mb_aff_frame_flag == 1) - { + if (mb_aff_frame_flag == 1) { set_loop_filter_functions_mbaff(p_Vid); - } - else - { + } else { set_loop_filter_functions_normal(p_Vid); } } @@ -160,191 +150,200 @@ void init_Deblock(VideoParameters *p_Vid, int mb_aff_frame_flag) ***************************************************************************************** */ -static void DeblockMb(VideoParameters *p_Vid, StorablePicture *p, int MbQAddr) -{ - Macroblock *MbQ = &(p_Vid->mb_data[MbQAddr]) ; // current Mb +static void DeblockMb(VideoParameters *p_Vid, StorablePicture *p, int MbQAddr) { + Macroblock *MbQ = &(p_Vid->mb_data[MbQAddr]); // current Mb // return, if filter is disabled - if (MbQ->DFDisableIdc == 1) - { + if (MbQ->DFDisableIdc == 1) { MbQ->DeblockCall = 0; - } - else - { - int edge; + } else { + int edge; #if !defined(SPEC) byte Strength[16]; #else - //avoid misalign core dumps at low opt: ask for 2x8 byte, not 16x1 byte - int64 Str8[2]; - byte *Strength = (byte *) Str8; + // avoid misalign core dumps at low opt: ask for 2x8 byte, not 16x1 byte + int64 Str8[2]; + byte *Strength = (byte *)Str8; #endif - int64 *p_Strength64 = (int64 *) Strength; - short mb_x, mb_y; + int64 *p_Strength64 = (int64 *)Strength; + short mb_x, mb_y; - int filterNon8x8LumaEdgesFlag[4] = {1,1,1,1}; - int filterLeftMbEdgeFlag; - int filterTopMbEdgeFlag; - int edge_cr; + int filterNon8x8LumaEdgesFlag[4] = {1, 1, 1, 1}; + int filterLeftMbEdgeFlag; + int filterTopMbEdgeFlag; + int edge_cr; - imgpel **imgY = p->imgY; - imgpel ***imgUV = p->imgUV; - Slice *currSlice = MbQ->p_Slice; - int mvlimit = ((p->structure!=FRAME) || (p->mb_aff_frame_flag && MbQ->mb_field)) ? 2 : 4; + imgpel **imgY = p->imgY; + imgpel ***imgUV = p->imgUV; + Slice *currSlice = MbQ->p_Slice; + int mvlimit = + ((p->structure != FRAME) || (p->mb_aff_frame_flag && MbQ->mb_field)) + ? 2 + : 4; seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; MbQ->DeblockCall = 1; - get_mb_pos (p_Vid, MbQAddr, p_Vid->mb_size[IS_LUMA], &mb_x, &mb_y); + get_mb_pos(p_Vid, MbQAddr, p_Vid->mb_size[IS_LUMA], &mb_x, &mb_y); if (MbQ->mb_type == I8MB) assert(MbQ->luma_transform_size_8x8_flag); - filterNon8x8LumaEdgesFlag[1] = - filterNon8x8LumaEdgesFlag[3] = !(MbQ->luma_transform_size_8x8_flag); + filterNon8x8LumaEdgesFlag[1] = filterNon8x8LumaEdgesFlag[3] = + !(MbQ->luma_transform_size_8x8_flag); filterLeftMbEdgeFlag = (mb_x != 0); - filterTopMbEdgeFlag = (mb_y != 0); + filterTopMbEdgeFlag = (mb_y != 0); if (p->mb_aff_frame_flag && mb_y == MB_BLOCK_SIZE && MbQ->mb_field) filterTopMbEdgeFlag = 0; - if (MbQ->DFDisableIdc==2) - { + if (MbQ->DFDisableIdc == 2) { // don't filter at slice boundaries filterLeftMbEdgeFlag = MbQ->mbAvailA; - // if this the bottom of a frame macroblock pair then always filter the top edge - filterTopMbEdgeFlag = (p->mb_aff_frame_flag && !MbQ->mb_field && (MbQAddr & 0x01)) ? 1 : MbQ->mbAvailB; + // if this the bottom of a frame macroblock pair then always filter the + // top edge + filterTopMbEdgeFlag = + (p->mb_aff_frame_flag && !MbQ->mb_field && (MbQAddr & 0x01)) + ? 1 + : MbQ->mbAvailB; } - if (p->mb_aff_frame_flag == 1) + if (p->mb_aff_frame_flag == 1) CheckAvailabilityOfNeighbors(MbQ); // Vertical deblocking - for (edge = 0; edge < 4 ; ++edge ) - { + for (edge = 0; edge < 4; ++edge) { // If cbp == 0 then deblocking for some macroblock types could be skipped - if (MbQ->cbp == 0) - { - if (filterNon8x8LumaEdgesFlag[edge] == 0 && active_sps->chroma_format_idc != YUV444) + if (MbQ->cbp == 0) { + if (filterNon8x8LumaEdgesFlag[edge] == 0 && + active_sps->chroma_format_idc != YUV444) continue; - else if (edge > 0) - { - if (((MbQ->mb_type == PSKIP && currSlice->slice_type == P_SLICE) || (MbQ->mb_type == P16x16) || (MbQ->mb_type == P16x8))) + else if (edge > 0) { + if (((MbQ->mb_type == PSKIP && currSlice->slice_type == P_SLICE) || + (MbQ->mb_type == P16x16) || (MbQ->mb_type == P16x8))) continue; - else if ((edge & 0x01) && ((MbQ->mb_type == P8x16) || (currSlice->slice_type == B_SLICE && MbQ->mb_type == BSKIP_DIRECT && active_sps->direct_8x8_inference_flag))) + else if ((edge & 0x01) && ((MbQ->mb_type == P8x16) || + (currSlice->slice_type == B_SLICE && + MbQ->mb_type == BSKIP_DIRECT && + active_sps->direct_8x8_inference_flag))) continue; } } - if( edge || filterLeftMbEdgeFlag ) - { + if (edge || filterLeftMbEdgeFlag) { // Strength for 4 blks in 1 stripe p_Vid->GetStrengthVer(Strength, MbQ, edge << 2, mvlimit, p); - if ((p_Strength64[0]) || (p_Strength64[1])) // only if one of the 16 Strength bytes is != 0 + if ((p_Strength64[0]) || + (p_Strength64[1])) // only if one of the 16 Strength bytes is != 0 { - if (filterNon8x8LumaEdgesFlag[edge]) - { - p_Vid->EdgeLoopLumaVer( PLANE_Y, imgY, Strength, MbQ, edge << 2, p) ; - if(currSlice->is_not_independent) - { - p_Vid->EdgeLoopLumaVer(PLANE_U, imgUV[0], Strength, MbQ, edge << 2, p); - p_Vid->EdgeLoopLumaVer(PLANE_V, imgUV[1], Strength, MbQ, edge << 2, p); + if (filterNon8x8LumaEdgesFlag[edge]) { + p_Vid->EdgeLoopLumaVer(PLANE_Y, imgY, Strength, MbQ, edge << 2, p); + if (currSlice->is_not_independent) { + p_Vid->EdgeLoopLumaVer(PLANE_U, imgUV[0], Strength, MbQ, + edge << 2, p); + p_Vid->EdgeLoopLumaVer(PLANE_V, imgUV[1], Strength, MbQ, + edge << 2, p); } } - if (active_sps->chroma_format_idc==YUV420 || active_sps->chroma_format_idc==YUV422) - { + if (active_sps->chroma_format_idc == YUV420 || + active_sps->chroma_format_idc == YUV422) { edge_cr = chroma_edge[0][edge][p->chroma_format_idc]; - if( (imgUV != NULL) && (edge_cr >= 0)) - { - p_Vid->EdgeLoopChromaVer( imgUV[0], Strength, MbQ, edge_cr, 0, p); - p_Vid->EdgeLoopChromaVer( imgUV[1], Strength, MbQ, edge_cr, 1, p); + if ((imgUV != NULL) && (edge_cr >= 0)) { + p_Vid->EdgeLoopChromaVer(imgUV[0], Strength, MbQ, edge_cr, 0, p); + p_Vid->EdgeLoopChromaVer(imgUV[1], Strength, MbQ, edge_cr, 1, p); } } - } + } } - }//end edge + } // end edge - // horizontal deblocking - for( edge = 0; edge < 4 ; ++edge ) - { + // horizontal deblocking + for (edge = 0; edge < 4; ++edge) { // If cbp == 0 then deblocking for some macroblock types could be skipped - if (MbQ->cbp == 0) - { - if (filterNon8x8LumaEdgesFlag[edge] == 0 && active_sps->chroma_format_idc==YUV420) + if (MbQ->cbp == 0) { + if (filterNon8x8LumaEdgesFlag[edge] == 0 && + active_sps->chroma_format_idc == YUV420) continue; - else if (edge > 0) - { - if (((MbQ->mb_type == PSKIP && currSlice->slice_type == P_SLICE) || (MbQ->mb_type == P16x16) || (MbQ->mb_type == P8x16))) + else if (edge > 0) { + if (((MbQ->mb_type == PSKIP && currSlice->slice_type == P_SLICE) || + (MbQ->mb_type == P16x16) || (MbQ->mb_type == P8x16))) continue; - else if ((edge & 0x01) && ((MbQ->mb_type == P16x8) || (currSlice->slice_type == B_SLICE && MbQ->mb_type == BSKIP_DIRECT && active_sps->direct_8x8_inference_flag))) + else if ((edge & 0x01) && ((MbQ->mb_type == P16x8) || + (currSlice->slice_type == B_SLICE && + MbQ->mb_type == BSKIP_DIRECT && + active_sps->direct_8x8_inference_flag))) continue; } } - if( edge || filterTopMbEdgeFlag ) - { + if (edge || filterTopMbEdgeFlag) { // Strength for 4 blks in 1 stripe p_Vid->GetStrengthHor(Strength, MbQ, edge << 2, mvlimit, p); - if ((p_Strength64[0]) || (p_Strength64[1])) // only if one of the 16 Strength bytes is != 0 + if ((p_Strength64[0]) || + (p_Strength64[1])) // only if one of the 16 Strength bytes is != 0 { - if (filterNon8x8LumaEdgesFlag[edge]) - { - p_Vid->EdgeLoopLumaHor( PLANE_Y, imgY, Strength, MbQ, edge << 2, p) ; - if(currSlice->is_not_independent) - { - p_Vid->EdgeLoopLumaHor(PLANE_U, imgUV[0], Strength, MbQ, edge << 2, p); - p_Vid->EdgeLoopLumaHor(PLANE_V, imgUV[1], Strength, MbQ, edge << 2, p); + if (filterNon8x8LumaEdgesFlag[edge]) { + p_Vid->EdgeLoopLumaHor(PLANE_Y, imgY, Strength, MbQ, edge << 2, p); + if (currSlice->is_not_independent) { + p_Vid->EdgeLoopLumaHor(PLANE_U, imgUV[0], Strength, MbQ, + edge << 2, p); + p_Vid->EdgeLoopLumaHor(PLANE_V, imgUV[1], Strength, MbQ, + edge << 2, p); } } - - if (active_sps->chroma_format_idc==YUV420 || active_sps->chroma_format_idc==YUV422) - { + + if (active_sps->chroma_format_idc == YUV420 || + active_sps->chroma_format_idc == YUV422) { edge_cr = chroma_edge[1][edge][p->chroma_format_idc]; - if( (imgUV != NULL) && (edge_cr >= 0)) - { - p_Vid->EdgeLoopChromaHor( imgUV[0], Strength, MbQ, edge_cr, 0, p); - p_Vid->EdgeLoopChromaHor( imgUV[1], Strength, MbQ, edge_cr, 1, p); + if ((imgUV != NULL) && (edge_cr >= 0)) { + p_Vid->EdgeLoopChromaHor(imgUV[0], Strength, MbQ, edge_cr, 0, p); + p_Vid->EdgeLoopChromaHor(imgUV[1], Strength, MbQ, edge_cr, 1, p); } } } - if (!edge && !MbQ->mb_field && MbQ->mixedModeEdgeFlag) //currSlice->mixedModeEdgeFlag) - { - // this is the extra horizontal edge between a frame macroblock pair and a field above it + if (!edge && !MbQ->mb_field && + MbQ->mixedModeEdgeFlag) // currSlice->mixedModeEdgeFlag) + { + // this is the extra horizontal edge between a frame macroblock pair + // and a field above it MbQ->DeblockCall = 2; - p_Vid->GetStrengthHor(Strength, MbQ, MB_BLOCK_SIZE, mvlimit, p); // Strength for 4 blks in 1 stripe + p_Vid->GetStrengthHor(Strength, MbQ, MB_BLOCK_SIZE, mvlimit, + p); // Strength for 4 blks in 1 stripe - //if( *((int*)Strength) ) // only if one of the 4 Strength bytes is != 0 + // if( *((int*)Strength) ) // only if one of the + // 4 Strength bytes is != 0 { - if (filterNon8x8LumaEdgesFlag[edge]) - { + if (filterNon8x8LumaEdgesFlag[edge]) { - p_Vid->EdgeLoopLumaHor(PLANE_Y, imgY, Strength, MbQ, MB_BLOCK_SIZE, p) ; - if(currSlice->is_not_independent) - { - p_Vid->EdgeLoopLumaHor(PLANE_U, imgUV[0], Strength, MbQ, MB_BLOCK_SIZE, p) ; - p_Vid->EdgeLoopLumaHor(PLANE_V, imgUV[1], Strength, MbQ, MB_BLOCK_SIZE, p) ; + p_Vid->EdgeLoopLumaHor(PLANE_Y, imgY, Strength, MbQ, + MB_BLOCK_SIZE, p); + if (currSlice->is_not_independent) { + p_Vid->EdgeLoopLumaHor(PLANE_U, imgUV[0], Strength, MbQ, + MB_BLOCK_SIZE, p); + p_Vid->EdgeLoopLumaHor(PLANE_V, imgUV[1], Strength, MbQ, + MB_BLOCK_SIZE, p); } } - if (active_sps->chroma_format_idc==YUV420 || active_sps->chroma_format_idc==YUV422) - { + if (active_sps->chroma_format_idc == YUV420 || + active_sps->chroma_format_idc == YUV422) { edge_cr = chroma_edge[1][edge][p->chroma_format_idc]; - if( (imgUV != NULL) && (edge_cr >= 0)) - { - p_Vid->EdgeLoopChromaHor( imgUV[0], Strength, MbQ, MB_BLOCK_SIZE, 0, p) ; - p_Vid->EdgeLoopChromaHor( imgUV[1], Strength, MbQ, MB_BLOCK_SIZE, 1, p) ; + if ((imgUV != NULL) && (edge_cr >= 0)) { + p_Vid->EdgeLoopChromaHor(imgUV[0], Strength, MbQ, MB_BLOCK_SIZE, + 0, p); + p_Vid->EdgeLoopChromaHor(imgUV[1], Strength, MbQ, MB_BLOCK_SIZE, + 1, p); } } } MbQ->DeblockCall = 1; } } - }//end edge + } // end edge MbQ->DeblockCall = 0; } } - diff --git a/src/common/ldecod_src/loop_filter_mbaff.c b/src/common/ldecod_src/loop_filter_mbaff.c index e3cf793..dee491d 100644 --- a/src/common/ldecod_src/loop_filter_mbaff.c +++ b/src/common/ldecod_src/loop_filter_mbaff.c @@ -9,269 +9,271 @@ * * \author * Contributors: - * - Peter List Peter.List@t-systems.de: Original code (13-Aug-2001) - * - Jani Lainema Jani.Lainema@nokia.com: Some bug fixing, removal of recursiveness (16-Aug-2001) - * - Peter List Peter.List@t-systems.de: inplace filtering and various simplifications (10-Jan-2002) - * - Anthony Joch anthony@ubvideo.com: Simplified switching between filters and - * non-recursive default filter. (08-Jul-2002) - * - Cristina Gomila cristina.gomila@thomson.net: Simplification of the chroma deblocking - * from JVT-E089 (21-Nov-2002) - * - Alexis Michael Tourapis atour@dolby.com: Speed/Architecture improvements (08-Feb-2007) + * - Peter List Peter.List@t-systems.de: Original code (13-Aug-2001) + * - Jani Lainema Jani.Lainema@nokia.com: Some bug fixing, removal of + *recursiveness (16-Aug-2001) + * - Peter List Peter.List@t-systems.de: inplace filtering and various + *simplifications (10-Jan-2002) + * - Anthony Joch anthony@ubvideo.com: Simplified switching between + *filters and non-recursive default filter. (08-Jul-2002) + * - Cristina Gomila cristina.gomila@thomson.net: Simplification of the + *chroma deblocking from JVT-E089 (21-Nov-2002) + * - Alexis Michael Tourapis atour@dolby.com: Speed/Architecture + *improvements (08-Feb-2007) ************************************************************************************* */ #include "global.h" #include "image.h" -#include "mb_access.h" -#include "loopfilter.h" #include "loop_filter.h" +#include "loopfilter.h" +#include "mb_access.h" -static void GetStrengthVerMBAff (byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p); -static void GetStrengthHorMBAff (byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p); -static void EdgeLoopLumaVerMBAff (ColorPlane pl, imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, StorablePicture *p); -static void EdgeLoopLumaHorMBAff (ColorPlane pl, imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, StorablePicture *p); -static void EdgeLoopChromaVerMBAff (imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int uv, StorablePicture *p); -static void EdgeLoopChromaHorMBAff (imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int uv, StorablePicture *p); +static void GetStrengthVerMBAff(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, int mvlimit, StorablePicture *p); +static void GetStrengthHorMBAff(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, int mvlimit, StorablePicture *p); +static void EdgeLoopLumaVerMBAff(ColorPlane pl, imgpel **Img, + byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, StorablePicture *p); +static void EdgeLoopLumaHorMBAff(ColorPlane pl, imgpel **Img, + byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, StorablePicture *p); +static void EdgeLoopChromaVerMBAff(imgpel **Img, byte Strength[MB_BLOCK_SIZE], + Macroblock *MbQ, int edge, int uv, + StorablePicture *p); +static void EdgeLoopChromaHorMBAff(imgpel **Img, byte Strength[MB_BLOCK_SIZE], + Macroblock *MbQ, int edge, int uv, + StorablePicture *p); -void set_loop_filter_functions_mbaff(VideoParameters *p_Vid) -{ - p_Vid->GetStrengthVer = GetStrengthVerMBAff; - p_Vid->GetStrengthHor = GetStrengthHorMBAff; - p_Vid->EdgeLoopLumaVer = EdgeLoopLumaVerMBAff; - p_Vid->EdgeLoopLumaHor = EdgeLoopLumaHorMBAff; +void set_loop_filter_functions_mbaff(VideoParameters *p_Vid) { + p_Vid->GetStrengthVer = GetStrengthVerMBAff; + p_Vid->GetStrengthHor = GetStrengthHorMBAff; + p_Vid->EdgeLoopLumaVer = EdgeLoopLumaVerMBAff; + p_Vid->EdgeLoopLumaHor = EdgeLoopLumaHorMBAff; p_Vid->EdgeLoopChromaVer = EdgeLoopChromaVerMBAff; p_Vid->EdgeLoopChromaHor = EdgeLoopChromaHorMBAff; } - -Macroblock* get_non_aff_neighbor_luma(Macroblock *mb, int xN, int yN) -{ +Macroblock *get_non_aff_neighbor_luma(Macroblock *mb, int xN, int yN) { if (xN < 0) - return(mb->mbleft); + return (mb->mbleft); else if (yN < 0) - return(mb->mbup); + return (mb->mbup); else - return(mb); + return (mb); } -Macroblock* get_non_aff_neighbor_chroma(Macroblock *mb, int xN, int yN, int block_width,int block_height) -{ - if (xN < 0) - { +Macroblock *get_non_aff_neighbor_chroma(Macroblock *mb, int xN, int yN, + int block_width, int block_height) { + if (xN < 0) { if (yN < block_height) - return(mb->mbleft); + return (mb->mbleft); else - return(NULL); - } - else if (xN < block_width) - { + return (NULL); + } else if (xN < block_width) { if (yN < 0) - return(mb->mbup); + return (mb->mbup); else if (yN < block_height) - return(mb); + return (mb); else - return(NULL); - } - else - return(NULL); + return (NULL); + } else + return (NULL); } - /*! ********************************************************************************************* * \brief * returns a buffer of 16 Strength values for one stripe in a mb (for MBAFF) ********************************************************************************************* */ -static void GetStrengthVerMBAff(byte Strength[16], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p) -{ - short blkP, blkQ, idx; - //short blk_x, blk_x2, blk_y, blk_y2 ; +static void GetStrengthVerMBAff(byte Strength[16], Macroblock *MbQ, int edge, + int mvlimit, StorablePicture *p) { + short blkP, blkQ, idx; + // short blk_x, blk_x2, blk_y, blk_y2 ; - int StrValue; - short mb_x, mb_y; + int StrValue; + short mb_x, mb_y; Macroblock *MbP; PixelPos pixP; VideoParameters *p_Vid = MbQ->p_Vid; - if ((p->slice_type==SP_SLICE)||(p->slice_type==SI_SLICE) ) - { - for( idx = 0; idx < MB_BLOCK_SIZE; ++idx ) - { + if ((p->slice_type == SP_SLICE) || (p->slice_type == SI_SLICE)) { + for (idx = 0; idx < MB_BLOCK_SIZE; ++idx) { getAffNeighbour(MbQ, edge - 1, idx, p_Vid->mb_size[IS_LUMA], &pixP); - blkQ = (short) ((idx & 0xFFFC) + (edge >> 2)); - blkP = (short) ((pixP.y & 0xFFFC) + (pixP.x >> 2)); + blkQ = (short)((idx & 0xFFFC) + (edge >> 2)); + blkP = (short)((pixP.y & 0xFFFC) + (pixP.x >> 2)); MbP = &(p_Vid->mb_data[pixP.mb_addr]); - MbQ->mixedModeEdgeFlag = (byte) (MbQ->mb_field != MbP->mb_field); //currSlice->mixedModeEdgeFlag = (byte) (MbQ->mb_field != MbP->mb_field); + MbQ->mixedModeEdgeFlag = + (byte)(MbQ->mb_field != + MbP->mb_field); // currSlice->mixedModeEdgeFlag = (byte) + // (MbQ->mb_field != MbP->mb_field); Strength[idx] = (edge == 0) ? 4 : 3; } - } - else - { + } else { getAffNeighbour(MbQ, edge - 1, 0, p_Vid->mb_size[IS_LUMA], &pixP); MbP = &(p_Vid->mb_data[pixP.mb_addr]); // Neighboring Frame MBs - if ((MbQ->mb_field == FALSE && MbP->mb_field == FALSE)) - { - MbQ->mixedModeEdgeFlag = (byte) (MbQ->mb_field != MbP->mb_field); - if (MbQ->is_intra_block == TRUE || MbP->is_intra_block == TRUE) - { - //printf("idx %d %d %d %d %d\n", idx, pixP.x, pixP.y, pixP.pos_x, pixP.pos_y); - // Start with Strength=3. or Strength=4 for Mb-edge + if ((MbQ->mb_field == FALSE && MbP->mb_field == FALSE)) { + MbQ->mixedModeEdgeFlag = (byte)(MbQ->mb_field != MbP->mb_field); + if (MbQ->is_intra_block == TRUE || MbP->is_intra_block == TRUE) { + // printf("idx %d %d %d %d %d\n", idx, pixP.x, pixP.y, pixP.pos_x, + // pixP.pos_y); + // Start with Strength=3. or Strength=4 for Mb-edge StrValue = (edge == 0) ? 4 : 3; - memset(Strength, (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte)); - } - else - { - get_mb_block_pos_mbaff (MbQ->mbAddrX, &mb_x, &mb_y); - for( idx = 0; idx < MB_BLOCK_SIZE; idx += BLOCK_SIZE) - { - blkQ = (short) ((idx & 0xFFFC) + (edge >> 2)); - blkP = (short) ((pixP.y & 0xFFFC) + (pixP.x >> 2)); + memset(Strength, (byte)StrValue, MB_BLOCK_SIZE * sizeof(byte)); + } else { + get_mb_block_pos_mbaff(MbQ->mbAddrX, &mb_x, &mb_y); + for (idx = 0; idx < MB_BLOCK_SIZE; idx += BLOCK_SIZE) { + blkQ = (short)((idx & 0xFFFC) + (edge >> 2)); + blkP = (short)((pixP.y & 0xFFFC) + (pixP.x >> 2)); - if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) + if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || + ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) StrValue = 2; - else if (edge && ((MbQ->mb_type == 1) || (MbQ->mb_type == 2))) - StrValue = 0; // if internal edge of certain types, we already know StrValue should be 0 - else // for everything else, if no coefs, but vector difference >= 1 set Strength=1 - { - int blk_y = ((mb_y<<2) + (blkQ >> 2)); - int blk_x = ((mb_x<<2) + (blkQ & 3)); + else if (edge && ((MbQ->mb_type == 1) || (MbQ->mb_type == 2))) + StrValue = 0; // if internal edge of certain types, we already know + // StrValue should be 0 + else // for everything else, if no coefs, but vector difference >= 1 + // set Strength=1 + { + int blk_y = ((mb_y << 2) + (blkQ >> 2)); + int blk_x = ((mb_x << 2) + (blkQ & 3)); int blk_y2 = (pixP.pos_y >> 2); int blk_x2 = (pixP.pos_x >> 2); - PicMotionParams *mv_info_p = &p->mv_info[blk_y ][blk_x ]; + PicMotionParams *mv_info_p = &p->mv_info[blk_y][blk_x]; PicMotionParams *mv_info_q = &p->mv_info[blk_y2][blk_x2]; StorablePicturePtr ref_p0 = mv_info_p->ref_pic[LIST_0]; StorablePicturePtr ref_q0 = mv_info_q->ref_pic[LIST_0]; StorablePicturePtr ref_p1 = mv_info_p->ref_pic[LIST_1]; StorablePicturePtr ref_q1 = mv_info_q->ref_pic[LIST_1]; - if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1))||((ref_p0==ref_q1) && (ref_p1==ref_q0))) - { + if (((ref_p0 == ref_q0) && (ref_p1 == ref_q1)) || + ((ref_p0 == ref_q1) && (ref_p1 == ref_q0))) { // L0 and L1 reference pictures of p0 are different; q0 as well - if (ref_p0 != ref_p1) - { + if (ref_p0 != ref_p1) { // compare MV for the same reference picture - if (ref_p0==ref_q0) - { - StrValue = (byte) ( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit)); + if (ref_p0 == ref_q0) { + StrValue = + (byte)(compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit)); + } else { + StrValue = + (byte)(compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit)); } - else - { - StrValue = (byte) ( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit)); - } - } - else - { // L0 and L1 reference pictures of p0 are the same; q0 as well + } else { // L0 and L1 reference pictures of p0 are the same; q0 as + // well - StrValue = (byte) (( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit)) - &&( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit))); + StrValue = + (byte)((compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit)) && + (compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit))); } - } - else - { + } else { StrValue = 1; - } + } } - *(int*)(Strength+idx) = StrValue * 0x01010101; + *(int *)(Strength + idx) = StrValue * 0x01010101; pixP.y += 4; pixP.pos_y += 4; } } - } - else - { - for( idx = 0; idx < MB_BLOCK_SIZE; ++idx ) - { + } else { + for (idx = 0; idx < MB_BLOCK_SIZE; ++idx) { getAffNeighbour(MbQ, edge - 1, idx, p_Vid->mb_size[IS_LUMA], &pixP); - blkQ = (short) ((idx & 0xFFFC) + (edge >> 2)); - blkP = (short) ((pixP.y & 0xFFFC) + (pixP.x >> 2)); + blkQ = (short)((idx & 0xFFFC) + (edge >> 2)); + blkP = (short)((pixP.y & 0xFFFC) + (pixP.x >> 2)); MbP = &(p_Vid->mb_data[pixP.mb_addr]); - MbQ->mixedModeEdgeFlag = (byte) (MbQ->mb_field != MbP->mb_field); + MbQ->mixedModeEdgeFlag = (byte)(MbQ->mb_field != MbP->mb_field); // Start with Strength=3. or Strength=4 for Mb-edge - Strength[idx] = (edge == 0 && (((!p->mb_aff_frame_flag && (p->structure==FRAME)) || - (p->mb_aff_frame_flag && !MbP->mb_field && !MbQ->mb_field)) || - ((p->mb_aff_frame_flag || (p->structure!=FRAME))))) ? 4 : 3; + Strength[idx] = + (edge == 0 && + (((!p->mb_aff_frame_flag && (p->structure == FRAME)) || + (p->mb_aff_frame_flag && !MbP->mb_field && !MbQ->mb_field)) || + ((p->mb_aff_frame_flag || (p->structure != FRAME))))) + ? 4 + : 3; - if (MbQ->is_intra_block == FALSE && MbP->is_intra_block == FALSE) - { - if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) - Strength[idx] = 2 ; - else - { + if (MbQ->is_intra_block == FALSE && MbP->is_intra_block == FALSE) { + if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || + ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) + Strength[idx] = 2; + else { // if no coefs, but vector difference >= 1 set Strength=1 - // if this is a mixed mode edge then one set of reference pictures will be frame and the - // other will be field - if(MbQ->mixedModeEdgeFlag) //if (currSlice->mixedModeEdgeFlag) + // if this is a mixed mode edge then one set of reference pictures + // will be frame and the other will be field + if (MbQ->mixedModeEdgeFlag) // if (currSlice->mixedModeEdgeFlag) { Strength[idx] = 1; - } - else - { - get_mb_block_pos_mbaff (MbQ->mbAddrX, &mb_x, &mb_y); + } else { + get_mb_block_pos_mbaff(MbQ->mbAddrX, &mb_x, &mb_y); { - int blk_y = ((mb_y<<2) + (blkQ >> 2)); - int blk_x = ((mb_x<<2) + (blkQ & 3)); + int blk_y = ((mb_y << 2) + (blkQ >> 2)); + int blk_x = ((mb_x << 2) + (blkQ & 3)); int blk_y2 = (pixP.pos_y >> 2); int blk_x2 = (pixP.pos_x >> 2); - PicMotionParams *mv_info_p = &p->mv_info[blk_y ][blk_x ]; + PicMotionParams *mv_info_p = &p->mv_info[blk_y][blk_x]; PicMotionParams *mv_info_q = &p->mv_info[blk_y2][blk_x2]; StorablePicturePtr ref_p0 = mv_info_p->ref_pic[LIST_0]; StorablePicturePtr ref_q0 = mv_info_q->ref_pic[LIST_0]; StorablePicturePtr ref_p1 = mv_info_p->ref_pic[LIST_1]; StorablePicturePtr ref_q1 = mv_info_q->ref_pic[LIST_1]; - if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1))||((ref_p0==ref_q1) && (ref_p1==ref_q0))) - { - Strength[idx]=0; - // L0 and L1 reference pictures of p0 are different; q0 as well - if (ref_p0 != ref_p1) - { + if (((ref_p0 == ref_q0) && (ref_p1 == ref_q1)) || + ((ref_p0 == ref_q1) && (ref_p1 == ref_q0))) { + Strength[idx] = 0; + // L0 and L1 reference pictures of p0 are different; q0 as + // well + if (ref_p0 != ref_p1) { // compare MV for the same reference picture - if (ref_p0==ref_q0) - { - Strength[idx] = (byte) ( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit)); + if (ref_p0 == ref_q0) { + Strength[idx] = + (byte)(compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit)); + } else { + Strength[idx] = + (byte)(compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit)); } - else - { - Strength[idx] = (byte) ( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit)); - } - } - else - { // L0 and L1 reference pictures of p0 are the same; q0 as well + } else { // L0 and L1 reference pictures of p0 are the same; + // q0 as well - Strength[idx] = (byte) (( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit)) - &&( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit))); + Strength[idx] = + (byte)((compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit)) && + (compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit))); } - } - else - { + } else { Strength[idx] = 1; } } @@ -289,176 +291,159 @@ static void GetStrengthVerMBAff(byte Strength[16], Macroblock *MbQ, int edge, in * returns a buffer of 16 Strength values for one stripe in a mb (for MBAFF) ********************************************************************************************* */ -static void GetStrengthHorMBAff(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p) -{ - short blkP, blkQ, idx; - short blk_x, blk_x2, blk_y, blk_y2 ; +static void GetStrengthHorMBAff(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, int mvlimit, StorablePicture *p) { + short blkP, blkQ, idx; + short blk_x, blk_x2, blk_y, blk_y2; - int StrValue; - int xQ, yQ = (edge < MB_BLOCK_SIZE ? edge : 1); - short mb_x, mb_y; + int StrValue; + int xQ, yQ = (edge < MB_BLOCK_SIZE ? edge : 1); + short mb_x, mb_y; Macroblock *MbP; PixelPos pixP; VideoParameters *p_Vid = MbQ->p_Vid; - if ((p->slice_type==SP_SLICE)||(p->slice_type==SI_SLICE) ) - { - for( idx = 0; idx < MB_BLOCK_SIZE; idx += BLOCK_SIZE) - { - xQ = idx; + if ((p->slice_type == SP_SLICE) || (p->slice_type == SI_SLICE)) { + for (idx = 0; idx < MB_BLOCK_SIZE; idx += BLOCK_SIZE) { + xQ = idx; getAffNeighbour(MbQ, xQ, yQ - 1, p_Vid->mb_size[IS_LUMA], &pixP); - blkQ = (short) ((yQ & 0xFFFC) + (xQ >> 2)); - blkP = (short) ((pixP.y & 0xFFFC) + (pixP.x >> 2)); + blkQ = (short)((yQ & 0xFFFC) + (xQ >> 2)); + blkP = (short)((pixP.y & 0xFFFC) + (pixP.x >> 2)); MbP = &(p_Vid->mb_data[pixP.mb_addr]); - MbQ->mixedModeEdgeFlag = (byte) (MbQ->mb_field != MbP->mb_field); + MbQ->mixedModeEdgeFlag = (byte)(MbQ->mb_field != MbP->mb_field); StrValue = (edge == 0 && (!MbP->mb_field && !MbQ->mb_field)) ? 4 : 3; - - *(int*)(Strength+idx) = StrValue * 0x01010101; + + *(int *)(Strength + idx) = StrValue * 0x01010101; } - } - else - { + } else { getAffNeighbour(MbQ, 0, yQ - 1, p_Vid->mb_size[IS_LUMA], &pixP); MbP = &(p_Vid->mb_data[pixP.mb_addr]); - MbQ->mixedModeEdgeFlag = (byte) (MbQ->mb_field != MbP->mb_field); + MbQ->mixedModeEdgeFlag = (byte)(MbQ->mb_field != MbP->mb_field); // Set intra mode deblocking - if (MbQ->is_intra_block == TRUE || MbP->is_intra_block == TRUE) - { + if (MbQ->is_intra_block == TRUE || MbP->is_intra_block == TRUE) { StrValue = (edge == 0 && (!MbP->mb_field && !MbQ->mb_field)) ? 4 : 3; - memset(Strength, (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte)); - } - else - { - for( idx = 0; idx < MB_BLOCK_SIZE; idx += BLOCK_SIZE ) - { - xQ = idx; + memset(Strength, (byte)StrValue, MB_BLOCK_SIZE * sizeof(byte)); + } else { + for (idx = 0; idx < MB_BLOCK_SIZE; idx += BLOCK_SIZE) { + xQ = idx; getAffNeighbour(MbQ, xQ, yQ - 1, p_Vid->mb_size[IS_LUMA], &pixP); - blkQ = (short) ((yQ & 0xFFFC) + (xQ >> 2)); - blkP = (short) ((pixP.y & 0xFFFC) + (pixP.x >> 2)); + blkQ = (short)((yQ & 0xFFFC) + (xQ >> 2)); + blkP = (short)((pixP.y & 0xFFFC) + (pixP.x >> 2)); - if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) - { + if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || + ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) { StrValue = 2; - } - else - { + } else { // if no coefs, but vector difference >= 1 set Strength=1 - // if this is a mixed mode edge then one set of reference pictures will be frame and the - // other will be field - if(MbQ->mixedModeEdgeFlag) //if (currSlice->mixedModeEdgeFlag) + // if this is a mixed mode edge then one set of reference pictures + // will be frame and the other will be field + if (MbQ->mixedModeEdgeFlag) // if (currSlice->mixedModeEdgeFlag) { StrValue = 1; - } - else - { - get_mb_block_pos_mbaff (MbQ->mbAddrX, &mb_x, &mb_y); - blk_y = (short) ((mb_y<<2) + (blkQ >> 2)); - blk_x = (short) ((mb_x<<2) + (blkQ & 3)); - blk_y2 = (short) (pixP.pos_y >> 2); - blk_x2 = (short) (pixP.pos_x >> 2); + } else { + get_mb_block_pos_mbaff(MbQ->mbAddrX, &mb_x, &mb_y); + blk_y = (short)((mb_y << 2) + (blkQ >> 2)); + blk_x = (short)((mb_x << 2) + (blkQ & 3)); + blk_y2 = (short)(pixP.pos_y >> 2); + blk_x2 = (short)(pixP.pos_x >> 2); { - PicMotionParams *mv_info_p = &p->mv_info[blk_y ][blk_x ]; + PicMotionParams *mv_info_p = &p->mv_info[blk_y][blk_x]; PicMotionParams *mv_info_q = &p->mv_info[blk_y2][blk_x2]; StorablePicturePtr ref_p0 = mv_info_p->ref_pic[LIST_0]; StorablePicturePtr ref_q0 = mv_info_q->ref_pic[LIST_0]; StorablePicturePtr ref_p1 = mv_info_p->ref_pic[LIST_1]; StorablePicturePtr ref_q1 = mv_info_q->ref_pic[LIST_1]; - if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1)) || - ((ref_p0==ref_q1) && (ref_p1==ref_q0))) - { + if (((ref_p0 == ref_q0) && (ref_p1 == ref_q1)) || + ((ref_p0 == ref_q1) && (ref_p1 == ref_q0))) { StrValue = 0; // L0 and L1 reference pictures of p0 are different; q0 as well - if (ref_p0 != ref_p1) - { + if (ref_p0 != ref_p1) { // compare MV for the same reference picture - if (ref_p0==ref_q0) - { - StrValue = (byte) ( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit)); - } - else - { - StrValue = (byte) ( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit)); + if (ref_p0 == ref_q0) { + StrValue = + (byte)(compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit)); + } else { + StrValue = + (byte)(compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit)); } + } else { // L0 and L1 reference pictures of p0 are the same; q0 + // as well + StrValue = + (byte)((compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit)) && + (compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) || + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit))); } - else - { // L0 and L1 reference pictures of p0 are the same; q0 as well - StrValue = (byte) (( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit)) - &&( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) || - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit))); - } - } - else - { + } else { StrValue = 1; } } } } - *(int*)(Strength+idx) = StrValue * 0x01010101; + *(int *)(Strength + idx) = StrValue * 0x01010101; } } } } - /*! ***************************************************************************************** * \brief * Filters 16 pel block edge of Super MB Frame coded MBs ***************************************************************************************** */ -static void EdgeLoopLumaVerMBAff(ColorPlane pl, imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, - int edge, StorablePicture *p) -{ +static void EdgeLoopLumaVerMBAff(ColorPlane pl, imgpel **Img, + byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, StorablePicture *p) { - int pel, Strng ; - imgpel L2 = 0, L1, L0, R0, R1, R2 = 0; - int Alpha = 0, Beta = 0 ; - const byte* ClipTab = NULL; - int indexA, indexB; - int PelNum = pl? pelnum_cr[0][p->chroma_format_idc] : MB_BLOCK_SIZE; + int pel, Strng; + imgpel L2 = 0, L1, L0, R0, R1, R2 = 0; + int Alpha = 0, Beta = 0; + const byte *ClipTab = NULL; + int indexA, indexB; + int PelNum = pl ? pelnum_cr[0][p->chroma_format_idc] : MB_BLOCK_SIZE; - int QP; + int QP; PixelPos pixP, pixQ; VideoParameters *p_Vid = MbQ->p_Vid; - int bitdepth_scale = pl? p_Vid->bitdepth_scale[IS_CHROMA] : p_Vid->bitdepth_scale[IS_LUMA]; - int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; + int bitdepth_scale = + pl ? p_Vid->bitdepth_scale[IS_CHROMA] : p_Vid->bitdepth_scale[IS_LUMA]; + int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; int AlphaC0Offset = MbQ->DFAlphaC0Offset; - int BetaOffset = MbQ->DFBetaOffset; + int BetaOffset = MbQ->DFBetaOffset; Macroblock *MbP; - imgpel *SrcPtrP, *SrcPtrQ; + imgpel *SrcPtrP, *SrcPtrQ; - if (MbQ->DFDisableIdc == 0) - { - for( pel = 0 ; pel < PelNum ; ++pel ) - { - getAffNeighbour(MbQ, edge - 1, pel, p_Vid->mb_size[IS_LUMA], &pixP); + if (MbQ->DFDisableIdc == 0) { + for (pel = 0; pel < PelNum; ++pel) { + getAffNeighbour(MbQ, edge - 1, pel, p_Vid->mb_size[IS_LUMA], &pixP); - if (pixP.available) - { - if( (Strng = Strength[pel]) != 0) - { + if (pixP.available) { + if ((Strng = Strength[pel]) != 0) { getAffNeighbour(MbQ, edge, pel, p_Vid->mb_size[IS_LUMA], &pixQ); MbP = &(p_Vid->mb_data[pixP.mb_addr]); @@ -467,80 +452,76 @@ static void EdgeLoopLumaVerMBAff(ColorPlane pl, imgpel** Img, byte Strength[MB_B SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]); // Average QP of the two blocks - QP = pl? ((MbP->qpc[pl-1] + MbQ->qpc[pl-1] + 1) >> 1) : (MbP->qp + MbQ->qp + 1) >> 1; + QP = pl ? ((MbP->qpc[pl - 1] + MbQ->qpc[pl - 1] + 1) >> 1) + : (MbP->qp + MbQ->qp + 1) >> 1; indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset); indexB = iClip3(0, MAX_QP, QP + BetaOffset); - Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; - Beta = BETA_TABLE [indexB] * bitdepth_scale; + Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; + Beta = BETA_TABLE[indexB] * bitdepth_scale; ClipTab = CLIP_TAB[indexA]; - L0 = SrcPtrP[ 0] ; - R0 = SrcPtrQ[ 0] ; + L0 = SrcPtrP[0]; + R0 = SrcPtrQ[0]; - if( iabs( R0 - L0 ) < Alpha ) - { - L1 = SrcPtrP[-1]; - R1 = SrcPtrQ[ 1]; + if (iabs(R0 - L0) < Alpha) { + L1 = SrcPtrP[-1]; + R1 = SrcPtrQ[1]; - if ((iabs( R0 - R1) < Beta ) && (iabs(L0 - L1) < Beta )) - { - L2 = SrcPtrP[-2]; - R2 = SrcPtrQ[ 2]; - if(Strng == 4 ) // INTRA strong filtering + if ((iabs(R0 - R1) < Beta) && (iabs(L0 - L1) < Beta)) { + L2 = SrcPtrP[-2]; + R2 = SrcPtrQ[2]; + if (Strng == 4) // INTRA strong filtering { int RL0 = L0 + R0; - int small_gap = (iabs( R0 - L0 ) < ((Alpha >> 2) + 2)); - int aq = ( iabs( R0 - R2) < Beta ) & small_gap; - int ap = ( iabs( L0 - L2) < Beta ) & small_gap; + int small_gap = (iabs(R0 - L0) < ((Alpha >> 2) + 2)); + int aq = (iabs(R0 - R2) < Beta) & small_gap; + int ap = (iabs(L0 - L2) < Beta) & small_gap; - if (ap) - { - int L3 = SrcPtrP[-3]; - SrcPtrP[-2 ] = (imgpel) ((((L3 + L2) << 1) + L2 + L1 + RL0 + 4) >> 3); - SrcPtrP[-1 ] = (imgpel) (( L2 + L1 + L0 + R0 + 2) >> 2); - SrcPtrP[ 0 ] = (imgpel) (( R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3); - } - else - { - SrcPtrP[ 0 ] = (imgpel) (((L1 << 1) + L0 + R1 + 2) >> 2) ; + if (ap) { + int L3 = SrcPtrP[-3]; + SrcPtrP[-2] = + (imgpel)((((L3 + L2) << 1) + L2 + L1 + RL0 + 4) >> 3); + SrcPtrP[-1] = (imgpel)((L2 + L1 + L0 + R0 + 2) >> 2); + SrcPtrP[0] = (imgpel)((R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3); + } else { + SrcPtrP[0] = (imgpel)(((L1 << 1) + L0 + R1 + 2) >> 2); } - if (aq) - { - imgpel R3 = SrcPtrQ[ 3]; - SrcPtrQ[ 0 ] = (imgpel) (( L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3); - SrcPtrQ[ 1 ] = (imgpel) (( R2 + R0 + R1 + L0 + 2) >> 2); - SrcPtrQ[ 2 ] = (imgpel) ((((R3 + R2) << 1) + R2 + R1 + RL0 + 4) >> 3); + if (aq) { + imgpel R3 = SrcPtrQ[3]; + SrcPtrQ[0] = (imgpel)((L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3); + SrcPtrQ[1] = (imgpel)((R2 + R0 + R1 + L0 + 2) >> 2); + SrcPtrQ[2] = + (imgpel)((((R3 + R2) << 1) + R2 + R1 + RL0 + 4) >> 3); + } else { + SrcPtrQ[0] = (imgpel)(((R1 << 1) + R0 + L1 + 2) >> 2); } - else - { - SrcPtrQ[ 0 ] = (imgpel) (((R1 << 1) + R0 + L1 + 2) >> 2); - } - } - else // normal filtering - { + } else // normal filtering + { int RL0 = (L0 + R0 + 1) >> 1; - int aq = (iabs( R0 - R2) < Beta); - int ap = (iabs( L0 - L2) < Beta); + int aq = (iabs(R0 - R2) < Beta); + int ap = (iabs(L0 - L2) < Beta); - int C0 = ClipTab[ Strng ] * bitdepth_scale; - int tc0 = (C0 + ap + aq) ; - int dif = iClip3( -tc0, tc0, (((R0 - L0) << 2) + (L1 - R1) + 4) >> 3) ; + int C0 = ClipTab[Strng] * bitdepth_scale; + int tc0 = (C0 + ap + aq); + int dif = + iClip3(-tc0, tc0, (((R0 - L0) << 2) + (L1 - R1) + 4) >> 3); - if( ap && (C0 != 0)) - *(SrcPtrP - 1) += iClip3( -C0, C0, ( L2 + RL0 - (L1 << 1)) >> 1 ) ; + if (ap && (C0 != 0)) + *(SrcPtrP - 1) += + iClip3(-C0, C0, (L2 + RL0 - (L1 << 1)) >> 1); - if (dif) - { - *SrcPtrP = (imgpel) iClip1 (max_imgpel_value, L0 + dif) ; - *SrcPtrQ = (imgpel) iClip1 (max_imgpel_value, R0 - dif) ; + if (dif) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, L0 + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, R0 - dif); } - if( aq && (C0 != 0)) - *(SrcPtrQ + 1) += iClip3( -C0, C0, ( R2 + RL0 - (R1 << 1)) >> 1 ) ; - } + if (aq && (C0 != 0)) + *(SrcPtrQ + 1) += + iClip3(-C0, C0, (R2 + RL0 - (R1 << 1)) >> 1); + } } } } @@ -555,122 +536,115 @@ static void EdgeLoopLumaVerMBAff(ColorPlane pl, imgpel** Img, byte Strength[MB_B * Filters 16 pel block edge of Super MB Frame coded MBs ***************************************************************************************** */ -static void EdgeLoopLumaHorMBAff(ColorPlane pl, imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, - int edge, StorablePicture *p) -{ - int width = p->iLumaStride; //p->size_x; - int pel, Strng ; - int PelNum = pl? pelnum_cr[1][p->chroma_format_idc] : MB_BLOCK_SIZE; +static void EdgeLoopLumaHorMBAff(ColorPlane pl, imgpel **Img, + byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, StorablePicture *p) { + int width = p->iLumaStride; // p->size_x; + int pel, Strng; + int PelNum = pl ? pelnum_cr[1][p->chroma_format_idc] : MB_BLOCK_SIZE; - int yQ = (edge < MB_BLOCK_SIZE ? edge : 1); + int yQ = (edge < MB_BLOCK_SIZE ? edge : 1); PixelPos pixP, pixQ; VideoParameters *p_Vid = MbQ->p_Vid; - int bitdepth_scale = pl? p_Vid->bitdepth_scale[IS_CHROMA] : p_Vid->bitdepth_scale[IS_LUMA]; - int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; + int bitdepth_scale = + pl ? p_Vid->bitdepth_scale[IS_CHROMA] : p_Vid->bitdepth_scale[IS_LUMA]; + int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; - getAffNeighbour(MbQ, 0, yQ - 1, p_Vid->mb_size[IS_LUMA], &pixP); + getAffNeighbour(MbQ, 0, yQ - 1, p_Vid->mb_size[IS_LUMA], &pixP); - if (pixP.available || (MbQ->DFDisableIdc == 0)) - { + if (pixP.available || (MbQ->DFDisableIdc == 0)) { int AlphaC0Offset = MbQ->DFAlphaC0Offset; int BetaOffset = MbQ->DFBetaOffset; Macroblock *MbP = &(p_Vid->mb_data[pixP.mb_addr]); - int incQ = ((MbP->mb_field && !MbQ->mb_field) ? 2 * width : width); - int incP = ((MbQ->mb_field && !MbP->mb_field) ? 2 * width : width); + int incQ = ((MbP->mb_field && !MbQ->mb_field) ? 2 * width : width); + int incP = ((MbQ->mb_field && !MbP->mb_field) ? 2 * width : width); // Average QP of the two blocks - int QP = pl? ((MbP->qpc[pl - 1] + MbQ->qpc[pl - 1] + 1) >> 1) : (MbP->qp + MbQ->qp + 1) >> 1; + int QP = pl ? ((MbP->qpc[pl - 1] + MbQ->qpc[pl - 1] + 1) >> 1) + : (MbP->qp + MbQ->qp + 1) >> 1; int indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset); int indexB = iClip3(0, MAX_QP, QP + BetaOffset); - int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; - int Beta = BETA_TABLE [indexB] * bitdepth_scale; + int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; + int Beta = BETA_TABLE[indexB] * bitdepth_scale; - if ((Alpha | Beta )!= 0) - { - const byte* ClipTab = CLIP_TAB[indexA]; + if ((Alpha | Beta) != 0) { + const byte *ClipTab = CLIP_TAB[indexA]; getAffNeighbour(MbQ, 0, yQ, p_Vid->mb_size[IS_LUMA], &pixQ); - for( pel = 0 ; pel < PelNum ; ++pel ) - { - if( (Strng = Strength[pel]) != 0) - { + for (pel = 0; pel < PelNum; ++pel) { + if ((Strng = Strength[pel]) != 0) { imgpel *SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]); imgpel *SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]); - imgpel L0 = *SrcPtrP; - imgpel R0 = *SrcPtrQ; + imgpel L0 = *SrcPtrP; + imgpel R0 = *SrcPtrQ; - if( iabs( R0 - L0 ) < Alpha ) - { - imgpel L1 = SrcPtrP[-incP]; - imgpel R1 = SrcPtrQ[ incQ]; + if (iabs(R0 - L0) < Alpha) { + imgpel L1 = SrcPtrP[-incP]; + imgpel R1 = SrcPtrQ[incQ]; - if ((iabs( R0 - R1) < Beta ) && (iabs(L0 - L1) < Beta )) - { - imgpel L2 = SrcPtrP[-incP*2]; - imgpel R2 = SrcPtrQ[ incQ*2]; - if(Strng == 4 ) // INTRA strong filtering + if ((iabs(R0 - R1) < Beta) && (iabs(L0 - L1) < Beta)) { + imgpel L2 = SrcPtrP[-incP * 2]; + imgpel R2 = SrcPtrQ[incQ * 2]; + if (Strng == 4) // INTRA strong filtering { int RL0 = L0 + R0; - int small_gap = (iabs( R0 - L0 ) < ((Alpha >> 2) + 2)); - int aq = ( iabs( R0 - R2) < Beta ) & small_gap; - int ap = ( iabs( L0 - L2) < Beta ) & small_gap; + int small_gap = (iabs(R0 - L0) < ((Alpha >> 2) + 2)); + int aq = (iabs(R0 - R2) < Beta) & small_gap; + int ap = (iabs(L0 - L2) < Beta) & small_gap; - if (ap) - { - imgpel L3 = SrcPtrP[-incP*3]; - SrcPtrP[-incP * 2] = (imgpel) ((((L3 + L2) << 1) + L2 + L1 + RL0 + 4) >> 3); - SrcPtrP[-incP ] = (imgpel) (( L2 + L1 + L0 + R0 + 2) >> 2); - SrcPtrP[ 0 ] = (imgpel) (( R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3); - } - else - { - SrcPtrP[ 0 ] = (imgpel) (((L1 << 1) + L0 + R1 + 2) >> 2) ; + if (ap) { + imgpel L3 = SrcPtrP[-incP * 3]; + SrcPtrP[-incP * 2] = + (imgpel)((((L3 + L2) << 1) + L2 + L1 + RL0 + 4) >> 3); + SrcPtrP[-incP] = (imgpel)((L2 + L1 + L0 + R0 + 2) >> 2); + SrcPtrP[0] = (imgpel)((R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3); + } else { + SrcPtrP[0] = (imgpel)(((L1 << 1) + L0 + R1 + 2) >> 2); } - if (aq) - { - imgpel R3 = SrcPtrQ[ incQ*3]; - SrcPtrQ[ 0 ] = (imgpel) (( L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3); - SrcPtrQ[ incQ ] = (imgpel) (( R2 + R0 + R1 + L0 + 2) >> 2); - SrcPtrQ[ incQ * 2 ] = (imgpel) ((((R3 + R2) << 1) + R2 + R1 + RL0 + 4) >> 3); + if (aq) { + imgpel R3 = SrcPtrQ[incQ * 3]; + SrcPtrQ[0] = (imgpel)((L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3); + SrcPtrQ[incQ] = (imgpel)((R2 + R0 + R1 + L0 + 2) >> 2); + SrcPtrQ[incQ * 2] = + (imgpel)((((R3 + R2) << 1) + R2 + R1 + RL0 + 4) >> 3); + } else { + SrcPtrQ[0] = (imgpel)(((R1 << 1) + R0 + L1 + 2) >> 2); } - else - { - SrcPtrQ[ 0 ] = (imgpel) (((R1 << 1) + R0 + L1 + 2) >> 2); - } - } - else // normal filtering - { + } else // normal filtering + { int RL0 = (L0 + R0 + 1) >> 1; - int aq = (iabs( R0 - R2) < Beta); - int ap = (iabs( L0 - L2) < Beta); + int aq = (iabs(R0 - R2) < Beta); + int ap = (iabs(L0 - L2) < Beta); - int C0 = ClipTab[ Strng ] * bitdepth_scale; - int tc0 = (C0 + ap + aq) ; - int dif = iClip3( -tc0, tc0, (((R0 - L0) << 2) + (L1 - R1) + 4) >> 3) ; + int C0 = ClipTab[Strng] * bitdepth_scale; + int tc0 = (C0 + ap + aq); + int dif = + iClip3(-tc0, tc0, (((R0 - L0) << 2) + (L1 - R1) + 4) >> 3); - if( ap && (C0 != 0)) - *(SrcPtrP - incP) += iClip3( -C0, C0, ( L2 + RL0 - (L1 << 1)) >> 1 ) ; + if (ap && (C0 != 0)) + *(SrcPtrP - incP) += + iClip3(-C0, C0, (L2 + RL0 - (L1 << 1)) >> 1); - if (dif) - { - *SrcPtrP = (imgpel) iClip1 (max_imgpel_value, L0 + dif) ; - *SrcPtrQ = (imgpel) iClip1 (max_imgpel_value, R0 - dif) ; + if (dif) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, L0 + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, R0 - dif); } - if( aq && (C0 != 0)) - *(SrcPtrQ + incQ) += iClip3( -C0, C0, ( R2 + RL0 - (R1 << 1)) >> 1 ) ; - } + if (aq && (C0 != 0)) + *(SrcPtrQ + incQ) += + iClip3(-C0, C0, (R2 + RL0 - (R1 << 1)) >> 1); + } } - } - } + } + } pixP.pos_x++; pixQ.pos_x++; } @@ -678,48 +652,47 @@ static void EdgeLoopLumaHorMBAff(ColorPlane pl, imgpel** Img, byte Strength[MB_B } } - - /*! ***************************************************************************************** * \brief * Filters chroma block edge for MBAFF types ***************************************************************************************** - */ -static void EdgeLoopChromaVerMBAff(imgpel** Img, byte Strength[16], Macroblock *MbQ, int edge, int uv, StorablePicture *p) -{ - int pel, Strng ; +*/ +static void EdgeLoopChromaVerMBAff(imgpel **Img, byte Strength[16], + Macroblock *MbQ, int edge, int uv, + StorablePicture *p) { + int pel, Strng; - imgpel L1, L0, R0, R1; - int Alpha = 0, Beta = 0; - const byte* ClipTab = NULL; - int indexA, indexB; + imgpel L1, L0, R0, R1; + int Alpha = 0, Beta = 0; + const byte *ClipTab = NULL; + int indexA, indexB; VideoParameters *p_Vid = MbQ->p_Vid; - int PelNum = pelnum_cr[0][p->chroma_format_idc]; - int StrengthIdx; - int QP; - int xQ = edge, yQ; + int PelNum = pelnum_cr[0][p->chroma_format_idc]; + int StrengthIdx; + int QP; + int xQ = edge, yQ; PixelPos pixP, pixQ; - int bitdepth_scale = p_Vid->bitdepth_scale[IS_CHROMA]; - int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; - - int AlphaC0Offset = MbQ->DFAlphaC0Offset; - int BetaOffset = MbQ->DFBetaOffset; - Macroblock *MbP; - imgpel *SrcPtrP, *SrcPtrQ; + int bitdepth_scale = p_Vid->bitdepth_scale[IS_CHROMA]; + int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; - for( pel = 0 ; pel < PelNum ; ++pel ) - { + int AlphaC0Offset = MbQ->DFAlphaC0Offset; + int BetaOffset = MbQ->DFBetaOffset; + Macroblock *MbP; + imgpel *SrcPtrP, *SrcPtrQ; + + for (pel = 0; pel < PelNum; ++pel) { yQ = pel; getAffNeighbour(MbQ, xQ, yQ, p_Vid->mb_size[IS_CHROMA], &pixQ); - getAffNeighbour(MbQ, xQ - 1, yQ, p_Vid->mb_size[IS_CHROMA], &pixP); - MbP = &(p_Vid->mb_data[pixP.mb_addr]); - StrengthIdx = (PelNum == 8) ? ((MbQ->mb_field && !MbP->mb_field) ? pel << 1 :((pel >> 1) << 2) + (pel & 0x01)) : pel; + getAffNeighbour(MbQ, xQ - 1, yQ, p_Vid->mb_size[IS_CHROMA], &pixP); + MbP = &(p_Vid->mb_data[pixP.mb_addr]); + StrengthIdx = (PelNum == 8) ? ((MbQ->mb_field && !MbP->mb_field) + ? pel << 1 + : ((pel >> 1) << 2) + (pel & 0x01)) + : pel; - if (pixP.available || (MbQ->DFDisableIdc == 0)) - { - if( (Strng = Strength[StrengthIdx]) != 0) - { + if (pixP.available || (MbQ->DFDisableIdc == 0)) { + if ((Strng = Strength[StrengthIdx]) != 0) { SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]); SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]); @@ -729,34 +702,30 @@ static void EdgeLoopChromaVerMBAff(imgpel** Img, byte Strength[16], Macroblock * indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset); indexB = iClip3(0, MAX_QP, QP + BetaOffset); - Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; - Beta = BETA_TABLE [indexB] * bitdepth_scale; + Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; + Beta = BETA_TABLE[indexB] * bitdepth_scale; ClipTab = CLIP_TAB[indexA]; - L0 = *SrcPtrP; - R0 = *SrcPtrQ; + L0 = *SrcPtrP; + R0 = *SrcPtrQ; - if( iabs( R0 - L0 ) < Alpha ) - { - L1 = SrcPtrP[-1]; - R1 = SrcPtrQ[ 1]; - if( ((iabs( R0 - R1) - Beta < 0) && (iabs(L0 - L1) - Beta < 0 )) ) - { - if( Strng == 4 ) // INTRA strong filtering + if (iabs(R0 - L0) < Alpha) { + L1 = SrcPtrP[-1]; + R1 = SrcPtrQ[1]; + if (((iabs(R0 - R1) - Beta < 0) && (iabs(L0 - L1) - Beta < 0))) { + if (Strng == 4) // INTRA strong filtering { - SrcPtrQ[0] = (imgpel) ( ((R1 << 1) + R0 + L1 + 2) >> 2 ); - SrcPtrP[0] = (imgpel) ( ((L1 << 1) + L0 + R1 + 2) >> 2 ); - } - else - { - int C0 = ClipTab[ Strng ] * bitdepth_scale; - int tc0 = (C0 + 1); - int dif = iClip3( -tc0, tc0, ( ((R0 - L0) << 2) + (L1 - R1) + 4) >> 3 ); + SrcPtrQ[0] = (imgpel)(((R1 << 1) + R0 + L1 + 2) >> 2); + SrcPtrP[0] = (imgpel)(((L1 << 1) + L0 + R1 + 2) >> 2); + } else { + int C0 = ClipTab[Strng] * bitdepth_scale; + int tc0 = (C0 + 1); + int dif = + iClip3(-tc0, tc0, (((R0 - L0) << 2) + (L1 - R1) + 4) >> 3); - if (dif) - { - *SrcPtrP = (imgpel) iClip1 ( max_imgpel_value, L0 + dif ); - *SrcPtrQ = (imgpel) iClip1 ( max_imgpel_value, R0 - dif ); + if (dif) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, L0 + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, R0 - dif); } } } @@ -771,29 +740,29 @@ static void EdgeLoopChromaVerMBAff(imgpel** Img, byte Strength[16], Macroblock * * \brief * Filters chroma block edge for MBAFF types ***************************************************************************************** - */ -static void EdgeLoopChromaHorMBAff(imgpel** Img, byte Strength[16], Macroblock *MbQ, int edge, int uv, StorablePicture *p) -{ +*/ +static void EdgeLoopChromaHorMBAff(imgpel **Img, byte Strength[16], + Macroblock *MbQ, int edge, int uv, + StorablePicture *p) { VideoParameters *p_Vid = MbQ->p_Vid; - int PelNum = pelnum_cr[1][p->chroma_format_idc]; - int yQ = (edge < MB_BLOCK_SIZE? edge : 1); + int PelNum = pelnum_cr[1][p->chroma_format_idc]; + int yQ = (edge < MB_BLOCK_SIZE ? edge : 1); PixelPos pixP, pixQ; - int bitdepth_scale = p_Vid->bitdepth_scale[IS_CHROMA]; - int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; - - int AlphaC0Offset = MbQ->DFAlphaC0Offset; - int BetaOffset = MbQ->DFBetaOffset; - int width = p->iChromaStride; //p->size_x_cr; + int bitdepth_scale = p_Vid->bitdepth_scale[IS_CHROMA]; + int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; - getAffNeighbour(MbQ, 0, yQ - 1, p_Vid->mb_size[IS_CHROMA], &pixP); + int AlphaC0Offset = MbQ->DFAlphaC0Offset; + int BetaOffset = MbQ->DFBetaOffset; + int width = p->iChromaStride; // p->size_x_cr; + + getAffNeighbour(MbQ, 0, yQ - 1, p_Vid->mb_size[IS_CHROMA], &pixP); getAffNeighbour(MbQ, 0, yQ, p_Vid->mb_size[IS_CHROMA], &pixQ); - if (pixP.available || (MbQ->DFDisableIdc == 0)) - { - Macroblock *MbP = &(p_Vid->mb_data[pixP.mb_addr]); + if (pixP.available || (MbQ->DFDisableIdc == 0)) { + Macroblock *MbP = &(p_Vid->mb_data[pixP.mb_addr]); int incQ = ((MbP->mb_field && !MbQ->mb_field) ? 2 * width : width); - int incP = ((MbQ->mb_field && !MbP->mb_field) ? 2 * width : width); + int incP = ((MbQ->mb_field && !MbP->mb_field) ? 2 * width : width); // Average QP of the two blocks int QP = (MbP->qpc[uv] + MbQ->qpc[uv] + 1) >> 1; @@ -801,52 +770,48 @@ static void EdgeLoopChromaHorMBAff(imgpel** Img, byte Strength[16], Macroblock * int indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset); int indexB = iClip3(0, MAX_QP, QP + BetaOffset); - int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; - int Beta = BETA_TABLE [indexB] * bitdepth_scale; + int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; + int Beta = BETA_TABLE[indexB] * bitdepth_scale; - if ((Alpha | Beta )!= 0) - { - const byte* ClipTab = CLIP_TAB[indexA]; - int pel, Strng ; - int StrengthIdx; - for( pel = 0 ; pel < PelNum ; ++pel ) - { - StrengthIdx = (PelNum == 8) ? ((MbQ->mb_field && !MbP->mb_field) ? pel << 1 :((pel >> 1) << 2) + (pel & 0x01)) : pel; + if ((Alpha | Beta) != 0) { + const byte *ClipTab = CLIP_TAB[indexA]; + int pel, Strng; + int StrengthIdx; + for (pel = 0; pel < PelNum; ++pel) { + StrengthIdx = (PelNum == 8) ? ((MbQ->mb_field && !MbP->mb_field) + ? pel << 1 + : ((pel >> 1) << 2) + (pel & 0x01)) + : pel; - if( (Strng = Strength[StrengthIdx]) != 0) - { + if ((Strng = Strength[StrengthIdx]) != 0) { imgpel *SrcPtrQ = &(Img[pixQ.pos_y][pixQ.pos_x]); imgpel *SrcPtrP = &(Img[pixP.pos_y][pixP.pos_x]); - imgpel L0 = *SrcPtrP; - imgpel R0 = *SrcPtrQ; + imgpel L0 = *SrcPtrP; + imgpel R0 = *SrcPtrQ; - if( iabs( R0 - L0 ) < Alpha ) - { - imgpel L1 = SrcPtrP[-incP]; - imgpel R1 = SrcPtrQ[ incQ]; - if( ((iabs( R0 - R1) - Beta < 0) && (iabs(L0 - L1) - Beta < 0 )) ) - { - if( Strng == 4 ) // INTRA strong filtering + if (iabs(R0 - L0) < Alpha) { + imgpel L1 = SrcPtrP[-incP]; + imgpel R1 = SrcPtrQ[incQ]; + if (((iabs(R0 - R1) - Beta < 0) && (iabs(L0 - L1) - Beta < 0))) { + if (Strng == 4) // INTRA strong filtering { - SrcPtrQ[0] = (imgpel) ( ((R1 << 1) + R0 + L1 + 2) >> 2 ); - SrcPtrP[0] = (imgpel) ( ((L1 << 1) + L0 + R1 + 2) >> 2 ); - } - else - { - int C0 = ClipTab[ Strng ] * bitdepth_scale; - int tc0 = (C0 + 1); - int dif = iClip3( -tc0, tc0, ( ((R0 - L0) << 2) + (L1 - R1) + 4) >> 3 ); + SrcPtrQ[0] = (imgpel)(((R1 << 1) + R0 + L1 + 2) >> 2); + SrcPtrP[0] = (imgpel)(((L1 << 1) + L0 + R1 + 2) >> 2); + } else { + int C0 = ClipTab[Strng] * bitdepth_scale; + int tc0 = (C0 + 1); + int dif = + iClip3(-tc0, tc0, (((R0 - L0) << 2) + (L1 - R1) + 4) >> 3); - if (dif) - { - *SrcPtrP = (imgpel) iClip1 ( max_imgpel_value, L0 + dif ); - *SrcPtrQ = (imgpel) iClip1 ( max_imgpel_value, R0 - dif ); + if (dif) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, L0 + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, R0 - dif); } } } } - } + } pixP.pos_x++; pixQ.pos_x++; } diff --git a/src/common/ldecod_src/loop_filter_normal.c b/src/common/ldecod_src/loop_filter_normal.c index 8e459f8..cfff304 100644 --- a/src/common/ldecod_src/loop_filter_normal.c +++ b/src/common/ldecod_src/loop_filter_normal.c @@ -9,692 +9,660 @@ * * \author * Contributors: - * - Peter List Peter.List@t-systems.de: Original code (13-Aug-2001) - * - Jani Lainema Jani.Lainema@nokia.com: Some bug fixing, removal of recursiveness (16-Aug-2001) - * - Peter List Peter.List@t-systems.de: inplace filtering and various simplifications (10-Jan-2002) - * - Anthony Joch anthony@ubvideo.com: Simplified switching between filters and - * non-recursive default filter. (08-Jul-2002) - * - Cristina Gomila cristina.gomila@thomson.net: Simplification of the chroma deblocking - * from JVT-E089 (21-Nov-2002) - * - Alexis Michael Tourapis atour@dolby.com: Speed/Architecture improvements (08-Feb-2007) + * - Peter List Peter.List@t-systems.de: Original code (13-Aug-2001) + * - Jani Lainema Jani.Lainema@nokia.com: Some bug fixing, removal of + *recursiveness (16-Aug-2001) + * - Peter List Peter.List@t-systems.de: inplace filtering and various + *simplifications (10-Jan-2002) + * - Anthony Joch anthony@ubvideo.com: Simplified switching between + *filters and non-recursive default filter. (08-Jul-2002) + * - Cristina Gomila cristina.gomila@thomson.net: Simplification of the + *chroma deblocking from JVT-E089 (21-Nov-2002) + * - Alexis Michael Tourapis atour@dolby.com: Speed/Architecture + *improvements (08-Feb-2007) ************************************************************************************* */ #include "global.h" #include "image.h" -#include "mb_access.h" -#include "loopfilter.h" #include "loop_filter.h" +#include "loopfilter.h" +#include "mb_access.h" -static void GetStrengthVer (byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p); -static void GetStrengthHor (byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p); -static void EdgeLoopLumaVer (ColorPlane pl, imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, StorablePicture *p); -static void EdgeLoopLumaHor (ColorPlane pl, imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, StorablePicture *p); -static void EdgeLoopChromaVer (imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int uv, StorablePicture *p); -static void EdgeLoopChromaHor (imgpel** Img, byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int uv, StorablePicture *p); +static void GetStrengthVer(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, int mvlimit, StorablePicture *p); +static void GetStrengthHor(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, int mvlimit, StorablePicture *p); +static void EdgeLoopLumaVer(ColorPlane pl, imgpel **Img, + byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, StorablePicture *p); +static void EdgeLoopLumaHor(ColorPlane pl, imgpel **Img, + byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, StorablePicture *p); +static void EdgeLoopChromaVer(imgpel **Img, byte Strength[MB_BLOCK_SIZE], + Macroblock *MbQ, int edge, int uv, + StorablePicture *p); +static void EdgeLoopChromaHor(imgpel **Img, byte Strength[MB_BLOCK_SIZE], + Macroblock *MbQ, int edge, int uv, + StorablePicture *p); - -void set_loop_filter_functions_normal(VideoParameters *p_Vid) -{ - p_Vid->GetStrengthVer = GetStrengthVer; - p_Vid->GetStrengthHor = GetStrengthHor; - p_Vid->EdgeLoopLumaVer = EdgeLoopLumaVer; - p_Vid->EdgeLoopLumaHor = EdgeLoopLumaHor; +void set_loop_filter_functions_normal(VideoParameters *p_Vid) { + p_Vid->GetStrengthVer = GetStrengthVer; + p_Vid->GetStrengthHor = GetStrengthHor; + p_Vid->EdgeLoopLumaVer = EdgeLoopLumaVer; + p_Vid->EdgeLoopLumaHor = EdgeLoopLumaHor; p_Vid->EdgeLoopChromaVer = EdgeLoopChromaVer; p_Vid->EdgeLoopChromaHor = EdgeLoopChromaHor; } - -static Macroblock* get_non_aff_neighbor_luma(Macroblock *mb, int xN, int yN) -{ +static Macroblock *get_non_aff_neighbor_luma(Macroblock *mb, int xN, int yN) { if (xN < 0) - return(mb->mbleft); + return (mb->mbleft); else if (yN < 0) - return(mb->mbup); + return (mb->mbup); else - return(mb); + return (mb); } -static Macroblock* get_non_aff_neighbor_chroma(Macroblock *mb, int xN, int yN, int block_width,int block_height) -{ - if (xN < 0) - { +static Macroblock *get_non_aff_neighbor_chroma(Macroblock *mb, int xN, int yN, + int block_width, + int block_height) { + if (xN < 0) { if (yN < block_height) - return(mb->mbleft); + return (mb->mbleft); else - return(NULL); - } - else if (xN < block_width) - { + return (NULL); + } else if (xN < block_width) { if (yN < 0) - return(mb->mbup); + return (mb->mbup); else if (yN < block_height) - return(mb); + return (mb); else - return(NULL); - } - else - return(NULL); + return (NULL); + } else + return (NULL); } #define get_x_luma(x) (x & 15) #define get_y_luma(y) (y & 15) -#define get_pos_x_luma(mb,x) (mb->pix_x + (x & 15)) -#define get_pos_y_luma(mb,y) (mb->pix_y + (y & 15)) -#define get_pos_x_chroma(mb,x,max) (mb->pix_c_x + (x & max)) -#define get_pos_y_chroma(mb,y,max) (mb->pix_c_y + (y & max)) +#define get_pos_x_luma(mb, x) (mb->pix_x + (x & 15)) +#define get_pos_y_luma(mb, y) (mb->pix_y + (y & 15)) +#define get_pos_x_chroma(mb, x, max) (mb->pix_c_x + (x & max)) +#define get_pos_y_chroma(mb, y, max) (mb->pix_c_y + (y & max)) - /*! +/*! ********************************************************************************************* * \brief - * returns a buffer of 16 Strength values for one stripe in a mb (for different Frame or Field types) + * returns a buffer of 16 Strength values for one stripe in a mb (for + *different Frame or Field types) ********************************************************************************************* */ -static void GetStrengthVer(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p) -{ +static void GetStrengthVer(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, int mvlimit, StorablePicture *p) { Slice *currSlice = MbQ->p_Slice; - int StrValue; + int StrValue; - if ((currSlice->slice_type==SP_SLICE)||(currSlice->slice_type==SI_SLICE) ) - { + if ((currSlice->slice_type == SP_SLICE) || + (currSlice->slice_type == SI_SLICE)) { // Set strength to either 3 or 4 regardless of pixel position - StrValue = (edge == 0 && (((p->structure==FRAME)) || ((p->structure != FRAME)))) ? 4 : 3; - memset(Strength, (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte)); - } - else - { - if (MbQ->is_intra_block == FALSE) - { + StrValue = + (edge == 0 && (((p->structure == FRAME)) || ((p->structure != FRAME)))) + ? 4 + : 3; + memset(Strength, (byte)StrValue, MB_BLOCK_SIZE * sizeof(byte)); + } else { + if (MbQ->is_intra_block == FALSE) { Macroblock *MbP; int xQ = edge - 1; Macroblock *neighbor = get_non_aff_neighbor_luma(MbQ, xQ, 0); MbP = (edge) ? MbQ : neighbor; - if (edge || MbP->is_intra_block == FALSE) - { - int blkP, blkQ, idx; - BlockPos mb = PicPos[ MbQ->mbAddrX ]; + if (edge || MbP->is_intra_block == FALSE) { + int blkP, blkQ, idx; + BlockPos mb = PicPos[MbQ->mbAddrX]; mb.x <<= 2; mb.y <<= 2; - for( idx = 0 ; idx < MB_BLOCK_SIZE ; idx += BLOCK_SIZE ) - { + for (idx = 0; idx < MB_BLOCK_SIZE; idx += BLOCK_SIZE) { blkQ = (idx & 0xFFFC) + (edge >> 2); blkP = (idx & 0xFFFC) + (get_x_luma(xQ) >> 2); - if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) + if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || + ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) StrValue = 2; - else if (edge && ((MbQ->mb_type == 1) || (MbQ->mb_type == 2))) - StrValue = 0; // if internal edge of certain types, we already know StrValue should be 0 - else // for everything else, if no coefs, but vector difference >= 1 set Strength=1 + else if (edge && ((MbQ->mb_type == 1) || (MbQ->mb_type == 2))) + StrValue = 0; // if internal edge of certain types, we already know + // StrValue should be 0 + else // for everything else, if no coefs, but vector difference >= 1 + // set Strength=1 { - int blk_y = mb.y + (blkQ >> 2); - int blk_x = mb.x + (blkQ & 3); - int blk_y2 = (short)(get_pos_y_luma(neighbor, 0) + idx) >> 2; - int blk_x2 = (short)(get_pos_x_luma(neighbor, xQ) ) >> 2; - PicMotionParams *mv_info_p = &p->mv_info[blk_y ][blk_x ]; + int blk_y = mb.y + (blkQ >> 2); + int blk_x = mb.x + (blkQ & 3); + int blk_y2 = (short)(get_pos_y_luma(neighbor, 0) + idx) >> 2; + int blk_x2 = (short)(get_pos_x_luma(neighbor, xQ)) >> 2; + PicMotionParams *mv_info_p = &p->mv_info[blk_y][blk_x]; StorablePicturePtr ref_p0 = mv_info_p->ref_pic[LIST_0]; StorablePicturePtr ref_p1 = mv_info_p->ref_pic[LIST_1]; PicMotionParams *mv_info_q = &p->mv_info[blk_y2][blk_x2]; StorablePicturePtr ref_q0 = mv_info_q->ref_pic[LIST_0]; StorablePicturePtr ref_q1 = mv_info_q->ref_pic[LIST_1]; - if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1)) || ((ref_p0==ref_q1) && (ref_p1==ref_q0))) - { + if (((ref_p0 == ref_q0) && (ref_p1 == ref_q1)) || + ((ref_p0 == ref_q1) && (ref_p1 == ref_q0))) { // L0 and L1 reference pictures of p0 are different; q0 as well - if (ref_p0 != ref_p1) - { + if (ref_p0 != ref_p1) { // compare MV for the same reference picture - if (ref_p0 == ref_q0) - { - StrValue = - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) | - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit); - } - else - { - StrValue = - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) | - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit); + if (ref_p0 == ref_q0) { + StrValue = compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) | + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit); + } else { + StrValue = compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) | + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit); } + } else { // L0 and L1 reference pictures of p0 are the same; q0 as + // well + StrValue = ((compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) | + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit)) && + (compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) | + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit))); } - else - { // L0 and L1 reference pictures of p0 are the same; q0 as well - StrValue = (( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) | - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit)) - && ( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) | - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit) - )); - } - } - else + } else StrValue = 1; } - //*(int*)(Strength+idx) = (StrValue<<24)|(StrValue<<16)|(StrValue<<8)|StrValue; - *(int*)(Strength+idx) = StrValue * 0x01010101; + //*(int*)(Strength+idx) = + //(StrValue<<24)|(StrValue<<16)|(StrValue<<8)|StrValue; + *(int *)(Strength + idx) = StrValue * 0x01010101; } - } - else - { + } else { // Start with Strength=3. or Strength=4 for Mb-edge - StrValue = (edge == 0 && ((((p->structure==FRAME))) || ((p->structure != FRAME)))) ? 4 : 3; - memset(Strength, (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte)); - } - } - else - { + StrValue = (edge == 0 && + ((((p->structure == FRAME))) || ((p->structure != FRAME)))) + ? 4 + : 3; + memset(Strength, (byte)StrValue, MB_BLOCK_SIZE * sizeof(byte)); + } + } else { // Start with Strength=3. or Strength=4 for Mb-edge - StrValue = (edge == 0 && ((((p->structure==FRAME))) || ((p->structure != FRAME)))) ? 4 : 3; - memset(Strength, (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte)); - } + StrValue = (edge == 0 && + ((((p->structure == FRAME))) || ((p->structure != FRAME)))) + ? 4 + : 3; + memset(Strength, (byte)StrValue, MB_BLOCK_SIZE * sizeof(byte)); + } } } - /*! +/*! ********************************************************************************************* * \brief - * returns a buffer of 16 Strength values for one stripe in a mb (for different Frame or Field types) + * returns a buffer of 16 Strength values for one stripe in a mb (for + *different Frame or Field types) ********************************************************************************************* */ -static void GetStrengthHor(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p) -{ - int StrValue; +static void GetStrengthHor(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, + int edge, int mvlimit, StorablePicture *p) { + int StrValue; Slice *currSlice = MbQ->p_Slice; - if ((currSlice->slice_type==SP_SLICE)||(currSlice->slice_type==SI_SLICE) ) - { + if ((currSlice->slice_type == SP_SLICE) || + (currSlice->slice_type == SI_SLICE)) { // Set strength to either 3 or 4 regardless of pixel position - StrValue = (edge == 0 && (((p->structure==FRAME)))) ? 4 : 3; - memset(Strength, (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte)); - } - else - { - if (MbQ->is_intra_block == FALSE) - { + StrValue = (edge == 0 && (((p->structure == FRAME)))) ? 4 : 3; + memset(Strength, (byte)StrValue, MB_BLOCK_SIZE * sizeof(byte)); + } else { + if (MbQ->is_intra_block == FALSE) { Macroblock *MbP; - int yQ = (edge < 16 ? edge - 1: 0); + int yQ = (edge < 16 ? edge - 1 : 0); Macroblock *neighbor = get_non_aff_neighbor_luma(MbQ, 0, yQ); MbP = (edge) ? MbQ : neighbor; - if (edge || MbP->is_intra_block == FALSE) - { - int blkP, blkQ, idx; - BlockPos mb = PicPos[ MbQ->mbAddrX ]; + if (edge || MbP->is_intra_block == FALSE) { + int blkP, blkQ, idx; + BlockPos mb = PicPos[MbQ->mbAddrX]; mb.x <<= 2; mb.y <<= 2; - for( idx = 0 ; idx < MB_BLOCK_SIZE ; idx += BLOCK_SIZE ) - { + for (idx = 0; idx < MB_BLOCK_SIZE; idx += BLOCK_SIZE) { blkQ = ((yQ + 1) & 0xFFFC) + (idx >> 2); blkP = (get_y_luma(yQ) & 0xFFFC) + (idx >> 2); - if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) + if (((MbQ->cbp_blk[0] & i64_power2(blkQ)) != 0) || + ((MbP->cbp_blk[0] & i64_power2(blkP)) != 0)) StrValue = 2; - else if (edge && ((MbQ->mb_type == 1) || (MbQ->mb_type == 3))) - StrValue = 0; // if internal edge of certain types, we already know StrValue should be 0 - else // for everything else, if no coefs, but vector difference >= 1 set Strength=1 - { - int blk_y = mb.y + (blkQ >> 2); - int blk_x = mb.x + (blkQ & 3); - int blk_y2 = get_pos_y_luma(neighbor,yQ) >> 2; - int blk_x2 = (short)(get_pos_x_luma(neighbor,0) + idx) >> 2; + else if (edge && ((MbQ->mb_type == 1) || (MbQ->mb_type == 3))) + StrValue = 0; // if internal edge of certain types, we already know + // StrValue should be 0 + else // for everything else, if no coefs, but vector difference >= 1 + // set Strength=1 + { + int blk_y = mb.y + (blkQ >> 2); + int blk_x = mb.x + (blkQ & 3); + int blk_y2 = get_pos_y_luma(neighbor, yQ) >> 2; + int blk_x2 = (short)(get_pos_x_luma(neighbor, 0) + idx) >> 2; - PicMotionParams *mv_info_p = &p->mv_info[blk_y ][blk_x ]; + PicMotionParams *mv_info_p = &p->mv_info[blk_y][blk_x]; PicMotionParams *mv_info_q = &p->mv_info[blk_y2][blk_x2]; StorablePicturePtr ref_p0 = mv_info_p->ref_pic[LIST_0]; StorablePicturePtr ref_q0 = mv_info_q->ref_pic[LIST_0]; StorablePicturePtr ref_p1 = mv_info_p->ref_pic[LIST_1]; - StorablePicturePtr ref_q1 = mv_info_q->ref_pic[LIST_1]; + StorablePicturePtr ref_q1 = mv_info_q->ref_pic[LIST_1]; - if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1)) || ((ref_p0==ref_q1) && (ref_p1==ref_q0))) - { + if (((ref_p0 == ref_q0) && (ref_p1 == ref_q1)) || + ((ref_p0 == ref_q1) && (ref_p1 == ref_q0))) { // L0 and L1 reference pictures of p0 are different; q0 as well - if (ref_p0 != ref_p1) - { + if (ref_p0 != ref_p1) { // compare MV for the same reference picture - if (ref_p0 == ref_q0) - { - StrValue = - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) | - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit); - } - else - { - StrValue = - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) | - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit); + if (ref_p0 == ref_q0) { + StrValue = compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) | + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit); + } else { + StrValue = compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) | + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit); } + } else { // L0 and L1 reference pictures of p0 are the same; q0 as + // well + StrValue = ((compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_0], mvlimit) | + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_1], mvlimit)) && + (compare_mvs(&mv_info_p->mv[LIST_0], + &mv_info_q->mv[LIST_1], mvlimit) | + compare_mvs(&mv_info_p->mv[LIST_1], + &mv_info_q->mv[LIST_0], mvlimit))); } - else - { // L0 and L1 reference pictures of p0 are the same; q0 as well - StrValue = (( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_0], mvlimit) | - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_1], mvlimit)) - && ( - compare_mvs(&mv_info_p->mv[LIST_0], &mv_info_q->mv[LIST_1], mvlimit) | - compare_mvs(&mv_info_p->mv[LIST_1], &mv_info_q->mv[LIST_0], mvlimit) - )); - } - } - else + } else StrValue = 1; } - //*(int*)(Strength+idx) = (StrValue<<24)|(StrValue<<16)|(StrValue<<8)|StrValue; - *(int*)(Strength+idx) = StrValue * 0x01010101; + //*(int*)(Strength+idx) = + //(StrValue<<24)|(StrValue<<16)|(StrValue<<8)|StrValue; + *(int *)(Strength + idx) = StrValue * 0x01010101; } - } - else - { + } else { // Start with Strength=3. or Strength=4 for Mb-edge StrValue = (edge == 0 && (p->structure == FRAME)) ? 4 : 3; - memset(Strength, (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte)); - } - } - else - { + memset(Strength, (byte)StrValue, MB_BLOCK_SIZE * sizeof(byte)); + } + } else { // Start with Strength=3. or Strength=4 for Mb-edge StrValue = (edge == 0 && (p->structure == FRAME)) ? 4 : 3; - memset(Strength, (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte)); - } + memset(Strength, (byte)StrValue, MB_BLOCK_SIZE * sizeof(byte)); + } } } - /*! ***************************************************************************************** * \brief - * Filters 16 pel block edge of Frame or Field coded MBs + * Filters 16 pel block edge of Frame or Field coded MBs ***************************************************************************************** */ -static void EdgeLoopLumaVer(ColorPlane pl, imgpel** Img, byte Strength[16], Macroblock *MbQ, int edge, StorablePicture *p) -{ +static void EdgeLoopLumaVer(ColorPlane pl, imgpel **Img, byte Strength[16], + Macroblock *MbQ, int edge, StorablePicture *p) { VideoParameters *p_Vid = MbQ->p_Vid; Macroblock *MbP = get_non_aff_neighbor_luma(MbQ, edge - 1, 0); - if (MbP || (MbQ->DFDisableIdc== 0)) - { - int bitdepth_scale = pl ? p_Vid->bitdepth_scale[IS_CHROMA] : p_Vid->bitdepth_scale[IS_LUMA]; + if (MbP || (MbQ->DFDisableIdc == 0)) { + int bitdepth_scale = + pl ? p_Vid->bitdepth_scale[IS_CHROMA] : p_Vid->bitdepth_scale[IS_LUMA]; // Average QP of the two blocks - int QP = pl? ((MbP->qpc[pl-1] + MbQ->qpc[pl-1] + 1) >> 1) : (MbP->qp + MbQ->qp + 1) >> 1; + int QP = pl ? ((MbP->qpc[pl - 1] + MbQ->qpc[pl - 1] + 1) >> 1) + : (MbP->qp + MbQ->qp + 1) >> 1; int indexA = iClip3(0, MAX_QP, QP + MbQ->DFAlphaC0Offset); int indexB = iClip3(0, MAX_QP, QP + MbQ->DFBetaOffset); - int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; - int Beta = BETA_TABLE [indexB] * bitdepth_scale; + int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; + int Beta = BETA_TABLE[indexB] * bitdepth_scale; - if ((Alpha | Beta )!= 0) - { + if ((Alpha | Beta) != 0) { const byte *ClipTab = CLIP_TAB[indexA]; - int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; + int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; int pos_x1 = get_pos_x_luma(MbP, (edge - 1)); imgpel **cur_img = &Img[get_pos_y_luma(MbP, 0)]; int pel; - for( pel = 0 ; pel < MB_BLOCK_SIZE ; pel += 4 ) - { - if(*Strength == 4 ) // INTRA strong filtering + for (pel = 0; pel < MB_BLOCK_SIZE; pel += 4) { + if (*Strength == 4) // INTRA strong filtering { int i; - for( i = 0 ; i < BLOCK_SIZE ; ++i ) - { + for (i = 0; i < BLOCK_SIZE; ++i) { imgpel *SrcPtrP = *(cur_img++) + pos_x1; imgpel *SrcPtrQ = SrcPtrP + 1; - imgpel L0 = *SrcPtrP; - imgpel R0 = *SrcPtrQ; + imgpel L0 = *SrcPtrP; + imgpel R0 = *SrcPtrQ; - if( iabs( R0 - L0 ) < Alpha ) - { - imgpel R1 = *(SrcPtrQ + 1); - imgpel L1 = *(SrcPtrP - 1); - if ((iabs( R0 - R1) < Beta) && (iabs(L0 - L1) < Beta)) - { - if ((iabs( R0 - L0 ) < ((Alpha >> 2) + 2))) - { - imgpel R2 = *(SrcPtrQ + 2); - imgpel L2 = *(SrcPtrP - 2); + if (iabs(R0 - L0) < Alpha) { + imgpel R1 = *(SrcPtrQ + 1); + imgpel L1 = *(SrcPtrP - 1); + if ((iabs(R0 - R1) < Beta) && (iabs(L0 - L1) < Beta)) { + if ((iabs(R0 - L0) < ((Alpha >> 2) + 2))) { + imgpel R2 = *(SrcPtrQ + 2); + imgpel L2 = *(SrcPtrP - 2); int RL0 = L0 + R0; - if (( iabs( L0 - L2) < Beta )) - { - imgpel L3 = *(SrcPtrP - 3); - *(SrcPtrP--) = (imgpel) (( R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3); - *(SrcPtrP--) = (imgpel) (( L2 + L1 + RL0 + 2) >> 2); - *(SrcPtrP ) = (imgpel) ((((L3 + L2) <<1) + L2 + L1 + RL0 + 4) >> 3); - } - else - { - *SrcPtrP = (imgpel) (((L1 << 1) + L0 + R1 + 2) >> 2); + if ((iabs(L0 - L2) < Beta)) { + imgpel L3 = *(SrcPtrP - 3); + *(SrcPtrP--) = + (imgpel)((R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3); + *(SrcPtrP--) = (imgpel)((L2 + L1 + RL0 + 2) >> 2); + *(SrcPtrP) = + (imgpel)((((L3 + L2) << 1) + L2 + L1 + RL0 + 4) >> 3); + } else { + *SrcPtrP = (imgpel)(((L1 << 1) + L0 + R1 + 2) >> 2); } - if (( iabs( R0 - R2) < Beta )) - { - imgpel R3 = *(SrcPtrQ + 3); - *(SrcPtrQ++) = (imgpel) (( L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3); - *(SrcPtrQ++) = (imgpel) (( R2 + R0 + L0 + R1 + 2) >> 2); - *(SrcPtrQ ) = (imgpel) ((((R3 + R2) <<1) + R2 + R1 + RL0 + 4) >> 3); + if ((iabs(R0 - R2) < Beta)) { + imgpel R3 = *(SrcPtrQ + 3); + *(SrcPtrQ++) = + (imgpel)((L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3); + *(SrcPtrQ++) = (imgpel)((R2 + R0 + L0 + R1 + 2) >> 2); + *(SrcPtrQ) = + (imgpel)((((R3 + R2) << 1) + R2 + R1 + RL0 + 4) >> 3); + } else { + *SrcPtrQ = (imgpel)(((R1 << 1) + R0 + L1 + 2) >> 2); } - else - { - *SrcPtrQ = (imgpel) (((R1 << 1) + R0 + L1 + 2) >> 2); - } - } - else - { - *SrcPtrP = (imgpel) (((L1 << 1) + L0 + R1 + 2) >> 2); - *SrcPtrQ = (imgpel) (((R1 << 1) + R0 + L1 + 2) >> 2); + } else { + *SrcPtrP = (imgpel)(((L1 << 1) + L0 + R1 + 2) >> 2); + *SrcPtrQ = (imgpel)(((R1 << 1) + R0 + L1 + 2) >> 2); } } - } + } } - } - else if( *Strength != 0) // normal filtering + } else if (*Strength != 0) // normal filtering { - int C0 = ClipTab[ *Strength ] * bitdepth_scale; + int C0 = ClipTab[*Strength] * bitdepth_scale; int i; imgpel *SrcPtrP, *SrcPtrQ; int edge_diff; - if (C0 == 0) - { - for( i= 0 ; i < BLOCK_SIZE ; ++i ) - { + if (C0 == 0) { + for (i = 0; i < BLOCK_SIZE; ++i) { SrcPtrP = *(cur_img++) + pos_x1; SrcPtrQ = SrcPtrP + 1; edge_diff = *SrcPtrQ - *SrcPtrP; - if( iabs( edge_diff ) < Alpha ) - { - imgpel *SrcPtrQ1 = SrcPtrQ + 1; - imgpel *SrcPtrP1 = SrcPtrP - 1; + if (iabs(edge_diff) < Alpha) { + imgpel *SrcPtrQ1 = SrcPtrQ + 1; + imgpel *SrcPtrP1 = SrcPtrP - 1; - if ((iabs( *SrcPtrQ - *SrcPtrQ1) < Beta) && (iabs(*SrcPtrP - *SrcPtrP1) < Beta)) - { - imgpel R2 = *(SrcPtrQ1 + 1); - imgpel L2 = *(SrcPtrP1 - 1); + if ((iabs(*SrcPtrQ - *SrcPtrQ1) < Beta) && + (iabs(*SrcPtrP - *SrcPtrP1) < Beta)) { + imgpel R2 = *(SrcPtrQ1 + 1); + imgpel L2 = *(SrcPtrP1 - 1); - int aq = (iabs(*SrcPtrQ - R2) < Beta); - int ap = (iabs(*SrcPtrP - L2) < Beta); + int aq = (iabs(*SrcPtrQ - R2) < Beta); + int ap = (iabs(*SrcPtrP - L2) < Beta); - int tc0 = (ap + aq) ; - int dif = iClip3( -tc0, tc0, (((edge_diff) << 2) + (*SrcPtrP1 - *SrcPtrQ1) + 4) >> 3 ); + int tc0 = (ap + aq); + int dif = iClip3( + -tc0, tc0, + (((edge_diff) << 2) + (*SrcPtrP1 - *SrcPtrQ1) + 4) >> 3); - if (dif != 0) - { - *SrcPtrP = (imgpel) iClip1(max_imgpel_value, *SrcPtrP + dif); - *SrcPtrQ = (imgpel) iClip1(max_imgpel_value, *SrcPtrQ - dif); + if (dif != 0) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, *SrcPtrP + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, *SrcPtrQ - dif); } } } } - } - else - { - for( i= 0 ; i < BLOCK_SIZE ; ++i ) - { + } else { + for (i = 0; i < BLOCK_SIZE; ++i) { SrcPtrP = *(cur_img++) + pos_x1; SrcPtrQ = SrcPtrP + 1; edge_diff = *SrcPtrQ - *SrcPtrP; - if( iabs( edge_diff ) < Alpha ) - { - imgpel *SrcPtrQ1 = SrcPtrQ + 1; - imgpel *SrcPtrP1 = SrcPtrP - 1; + if (iabs(edge_diff) < Alpha) { + imgpel *SrcPtrQ1 = SrcPtrQ + 1; + imgpel *SrcPtrP1 = SrcPtrP - 1; - if ((iabs( *SrcPtrQ - *SrcPtrQ1) < Beta) && (iabs(*SrcPtrP - *SrcPtrP1) < Beta)) - { + if ((iabs(*SrcPtrQ - *SrcPtrQ1) < Beta) && + (iabs(*SrcPtrP - *SrcPtrP1) < Beta)) { int RL0 = (*SrcPtrP + *SrcPtrQ + 1) >> 1; - imgpel R2 = *(SrcPtrQ1 + 1); - imgpel L2 = *(SrcPtrP1 - 1); + imgpel R2 = *(SrcPtrQ1 + 1); + imgpel L2 = *(SrcPtrP1 - 1); - int aq = (iabs(*SrcPtrQ - R2) < Beta); - int ap = (iabs(*SrcPtrP - L2) < Beta); + int aq = (iabs(*SrcPtrQ - R2) < Beta); + int ap = (iabs(*SrcPtrP - L2) < Beta); - int tc0 = (C0 + ap + aq) ; - int dif = iClip3( -tc0, tc0, (((edge_diff) << 2) + (*SrcPtrP1 - *SrcPtrQ1) + 4) >> 3 ); + int tc0 = (C0 + ap + aq); + int dif = iClip3( + -tc0, tc0, + (((edge_diff) << 2) + (*SrcPtrP1 - *SrcPtrQ1) + 4) >> 3); - if( ap ) - *SrcPtrP1 += iClip3( -C0, C0, (L2 + RL0 - (*SrcPtrP1<<1)) >> 1 ); + if (ap) + *SrcPtrP1 += + iClip3(-C0, C0, (L2 + RL0 - (*SrcPtrP1 << 1)) >> 1); - if (dif != 0) - { - *SrcPtrP = (imgpel) iClip1(max_imgpel_value, *SrcPtrP + dif); - *SrcPtrQ = (imgpel) iClip1(max_imgpel_value, *SrcPtrQ - dif); + if (dif != 0) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, *SrcPtrP + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, *SrcPtrQ - dif); } - if( aq ) - *SrcPtrQ1 += iClip3( -C0, C0, (R2 + RL0 - (*SrcPtrQ1<<1)) >> 1 ); + if (aq) + *SrcPtrQ1 += + iClip3(-C0, C0, (R2 + RL0 - (*SrcPtrQ1 << 1)) >> 1); } } } } - } - else - { + } else { cur_img += 4; } Strength += 4; - } + } } } } - /*! ***************************************************************************************** * \brief - * Filters 16 pel block edge of Frame or Field coded MBs + * Filters 16 pel block edge of Frame or Field coded MBs ***************************************************************************************** */ -static void EdgeLoopLumaHor(ColorPlane pl, imgpel** Img, byte Strength[16], Macroblock *MbQ, - int edge, StorablePicture *p) -{ +static void EdgeLoopLumaHor(ColorPlane pl, imgpel **Img, byte Strength[16], + Macroblock *MbQ, int edge, StorablePicture *p) { VideoParameters *p_Vid = MbQ->p_Vid; - int ypos = (edge < MB_BLOCK_SIZE ? edge - 1: 0); - Macroblock *MbP = get_non_aff_neighbor_luma(MbQ, 0, ypos); + int ypos = (edge < MB_BLOCK_SIZE ? edge - 1 : 0); + Macroblock *MbP = get_non_aff_neighbor_luma(MbQ, 0, ypos); - if (MbP || (MbQ->DFDisableIdc== 0)) - { - int bitdepth_scale = pl ? p_Vid->bitdepth_scale[IS_CHROMA] : p_Vid->bitdepth_scale[IS_LUMA]; + if (MbP || (MbQ->DFDisableIdc == 0)) { + int bitdepth_scale = + pl ? p_Vid->bitdepth_scale[IS_CHROMA] : p_Vid->bitdepth_scale[IS_LUMA]; // Average QP of the two blocks - int QP = pl? ((MbP->qpc[pl-1] + MbQ->qpc[pl-1] + 1) >> 1) : (MbP->qp + MbQ->qp + 1) >> 1; + int QP = pl ? ((MbP->qpc[pl - 1] + MbQ->qpc[pl - 1] + 1) >> 1) + : (MbP->qp + MbQ->qp + 1) >> 1; int indexA = iClip3(0, MAX_QP, QP + MbQ->DFAlphaC0Offset); int indexB = iClip3(0, MAX_QP, QP + MbQ->DFBetaOffset); - int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; - int Beta = BETA_TABLE [indexB] * bitdepth_scale; + int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; + int Beta = BETA_TABLE[indexB] * bitdepth_scale; - if ((Alpha | Beta )!= 0) - { + if ((Alpha | Beta) != 0) { const byte *ClipTab = CLIP_TAB[indexA]; int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; - int width = p->iLumaStride; //p->size_x; + int width = p->iLumaStride; // p->size_x; imgpel *imgP = &Img[get_pos_y_luma(MbP, ypos)][get_pos_x_luma(MbP, 0)]; imgpel *imgQ = imgP + width; int pel; - for( pel = 0 ; pel < MB_BLOCK_SIZE ; pel += 4 ) - { - if(*Strength == 4 ) // INTRA strong filtering + for (pel = 0; pel < MB_BLOCK_SIZE; pel += 4) { + if (*Strength == 4) // INTRA strong filtering { int pixel; int inc_dim2 = width * 2; int inc_dim3 = width * 3; - for( pixel = 0 ; pixel < BLOCK_SIZE ; ++pixel ) - { + for (pixel = 0; pixel < BLOCK_SIZE; ++pixel) { imgpel *SrcPtrP = imgP++; imgpel *SrcPtrQ = imgQ++; - imgpel L0 = *SrcPtrP; - imgpel R0 = *SrcPtrQ; + imgpel L0 = *SrcPtrP; + imgpel R0 = *SrcPtrQ; - if( iabs( R0 - L0 ) < Alpha ) - { - imgpel L1 = *(SrcPtrP - width); - imgpel R1 = *(SrcPtrQ + width); + if (iabs(R0 - L0) < Alpha) { + imgpel L1 = *(SrcPtrP - width); + imgpel R1 = *(SrcPtrQ + width); - if ((iabs( R0 - R1) < Beta) && (iabs(L0 - L1) < Beta)) - { - if ((iabs( R0 - L0 ) < ((Alpha >> 2) + 2))) - { - imgpel L2 = *(SrcPtrP - inc_dim2); - imgpel R2 = *(SrcPtrQ + inc_dim2); + if ((iabs(R0 - R1) < Beta) && (iabs(L0 - L1) < Beta)) { + if ((iabs(R0 - L0) < ((Alpha >> 2) + 2))) { + imgpel L2 = *(SrcPtrP - inc_dim2); + imgpel R2 = *(SrcPtrQ + inc_dim2); int RL0 = L0 + R0; - if (( iabs( L0 - L2) < Beta )) - { - imgpel L3 = *(SrcPtrP - inc_dim3); - *(SrcPtrP ) = (imgpel) (( R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3); - *(SrcPtrP -= width) = (imgpel) (( L2 + L1 + RL0 + 2) >> 2); - *(SrcPtrP - width) = (imgpel) ((((L3 + L2) <<1) + L2 + L1 + RL0 + 4) >> 3); - } - else - { - *SrcPtrP = (imgpel) (((L1 << 1) + L0 + R1 + 2) >> 2); + if ((iabs(L0 - L2) < Beta)) { + imgpel L3 = *(SrcPtrP - inc_dim3); + *(SrcPtrP) = + (imgpel)((R1 + ((L1 + RL0) << 1) + L2 + 4) >> 3); + *(SrcPtrP -= width) = (imgpel)((L2 + L1 + RL0 + 2) >> 2); + *(SrcPtrP - width) = + (imgpel)((((L3 + L2) << 1) + L2 + L1 + RL0 + 4) >> 3); + } else { + *SrcPtrP = (imgpel)(((L1 << 1) + L0 + R1 + 2) >> 2); } - if (( iabs( R0 - R2) < Beta )) - { - imgpel R3 = *(SrcPtrQ + inc_dim3); - *(SrcPtrQ ) = (imgpel) (( L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3); - *(SrcPtrQ += width ) = (imgpel) (( R2 + R0 + L0 + R1 + 2) >> 2); - *(SrcPtrQ + width ) = (imgpel) ((((R3 + R2) <<1) + R2 + R1 + RL0 + 4) >> 3); + if ((iabs(R0 - R2) < Beta)) { + imgpel R3 = *(SrcPtrQ + inc_dim3); + *(SrcPtrQ) = + (imgpel)((L1 + ((R1 + RL0) << 1) + R2 + 4) >> 3); + *(SrcPtrQ += width) = + (imgpel)((R2 + R0 + L0 + R1 + 2) >> 2); + *(SrcPtrQ + width) = + (imgpel)((((R3 + R2) << 1) + R2 + R1 + RL0 + 4) >> 3); + } else { + *SrcPtrQ = (imgpel)(((R1 << 1) + R0 + L1 + 2) >> 2); } - else - { - *SrcPtrQ = (imgpel) (((R1 << 1) + R0 + L1 + 2) >> 2); - } - } - else - { - *SrcPtrP = (imgpel) (((L1 << 1) + L0 + R1 + 2) >> 2); - *SrcPtrQ = (imgpel) (((R1 << 1) + R0 + L1 + 2) >> 2); + } else { + *SrcPtrP = (imgpel)(((L1 << 1) + L0 + R1 + 2) >> 2); + *SrcPtrQ = (imgpel)(((R1 << 1) + R0 + L1 + 2) >> 2); } } } } - } - else if( *Strength != 0) // normal filtering + } else if (*Strength != 0) // normal filtering { - int C0 = ClipTab[ *Strength ] * bitdepth_scale; + int C0 = ClipTab[*Strength] * bitdepth_scale; int i; imgpel *SrcPtrP, *SrcPtrQ; int edge_diff; - if (C0 == 0) - { - for( i= 0 ; i < BLOCK_SIZE ; ++i ) - { + if (C0 == 0) { + for (i = 0; i < BLOCK_SIZE; ++i) { SrcPtrP = imgP++; SrcPtrQ = imgQ++; edge_diff = *SrcPtrQ - *SrcPtrP; - if( iabs( edge_diff ) < Alpha ) - { - imgpel *SrcPtrQ1 = SrcPtrQ + width; - imgpel *SrcPtrP1 = SrcPtrP - width; + if (iabs(edge_diff) < Alpha) { + imgpel *SrcPtrQ1 = SrcPtrQ + width; + imgpel *SrcPtrP1 = SrcPtrP - width; - if ((iabs( *SrcPtrQ - *SrcPtrQ1) < Beta) && (iabs(*SrcPtrP - *SrcPtrP1) < Beta)) - { - imgpel R2 = *(SrcPtrQ1 + width); - imgpel L2 = *(SrcPtrP1 - width); + if ((iabs(*SrcPtrQ - *SrcPtrQ1) < Beta) && + (iabs(*SrcPtrP - *SrcPtrP1) < Beta)) { + imgpel R2 = *(SrcPtrQ1 + width); + imgpel L2 = *(SrcPtrP1 - width); - int aq = (iabs(*SrcPtrQ - R2) < Beta); - int ap = (iabs(*SrcPtrP - L2) < Beta); + int aq = (iabs(*SrcPtrQ - R2) < Beta); + int ap = (iabs(*SrcPtrP - L2) < Beta); - int tc0 = (ap + aq) ; - int dif = iClip3( -tc0, tc0, (((edge_diff) << 2) + (*SrcPtrP1 - *SrcPtrQ1) + 4) >> 3 ); + int tc0 = (ap + aq); + int dif = iClip3( + -tc0, tc0, + (((edge_diff) << 2) + (*SrcPtrP1 - *SrcPtrQ1) + 4) >> 3); - if (dif != 0) - { - *SrcPtrP = (imgpel) iClip1(max_imgpel_value, *SrcPtrP + dif); - *SrcPtrQ = (imgpel) iClip1(max_imgpel_value, *SrcPtrQ - dif); + if (dif != 0) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, *SrcPtrP + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, *SrcPtrQ - dif); } } } } - } - else - { - for( i= 0 ; i < BLOCK_SIZE ; ++i ) - { + } else { + for (i = 0; i < BLOCK_SIZE; ++i) { SrcPtrP = imgP++; SrcPtrQ = imgQ++; edge_diff = *SrcPtrQ - *SrcPtrP; - if( iabs( edge_diff ) < Alpha ) - { - imgpel *SrcPtrQ1 = SrcPtrQ + width; - imgpel *SrcPtrP1 = SrcPtrP - width; + if (iabs(edge_diff) < Alpha) { + imgpel *SrcPtrQ1 = SrcPtrQ + width; + imgpel *SrcPtrP1 = SrcPtrP - width; - if ((iabs( *SrcPtrQ - *SrcPtrQ1) < Beta) && (iabs(*SrcPtrP - *SrcPtrP1) < Beta)) - { + if ((iabs(*SrcPtrQ - *SrcPtrQ1) < Beta) && + (iabs(*SrcPtrP - *SrcPtrP1) < Beta)) { int RL0 = (*SrcPtrP + *SrcPtrQ + 1) >> 1; - imgpel R2 = *(SrcPtrQ1 + width); - imgpel L2 = *(SrcPtrP1 - width); + imgpel R2 = *(SrcPtrQ1 + width); + imgpel L2 = *(SrcPtrP1 - width); - int aq = (iabs(*SrcPtrQ - R2) < Beta); - int ap = (iabs(*SrcPtrP - L2) < Beta); + int aq = (iabs(*SrcPtrQ - R2) < Beta); + int ap = (iabs(*SrcPtrP - L2) < Beta); - int tc0 = (C0 + ap + aq) ; - int dif = iClip3( -tc0, tc0, (((edge_diff) << 2) + (*SrcPtrP1 - *SrcPtrQ1) + 4) >> 3 ); + int tc0 = (C0 + ap + aq); + int dif = iClip3( + -tc0, tc0, + (((edge_diff) << 2) + (*SrcPtrP1 - *SrcPtrQ1) + 4) >> 3); - if( ap ) - *SrcPtrP1 += iClip3( -C0, C0, (L2 + RL0 - (*SrcPtrP1<<1)) >> 1 ); + if (ap) + *SrcPtrP1 += + iClip3(-C0, C0, (L2 + RL0 - (*SrcPtrP1 << 1)) >> 1); - if (dif != 0) - { - *SrcPtrP = (imgpel) iClip1(max_imgpel_value, *SrcPtrP + dif); - *SrcPtrQ = (imgpel) iClip1(max_imgpel_value, *SrcPtrQ - dif); + if (dif != 0) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, *SrcPtrP + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, *SrcPtrQ - dif); } - if( aq ) - *SrcPtrQ1 += iClip3( -C0, C0, (R2 + RL0 - (*SrcPtrQ1<<1)) >> 1 ); + if (aq) + *SrcPtrQ1 += + iClip3(-C0, C0, (R2 + RL0 - (*SrcPtrQ1 << 1)) >> 1); } } } } - } - else - { + } else { imgP += 4; imgQ += 4; } Strength += 4; - } + } } } } - /*! ***************************************************************************************** * \brief * Filters chroma block edge for Frame or Field coded pictures ***************************************************************************************** */ -static void EdgeLoopChromaVer(imgpel** Img, byte Strength[16], Macroblock *MbQ, int edge, int uv, StorablePicture *p) -{ - VideoParameters *p_Vid = MbQ->p_Vid; +static void EdgeLoopChromaVer(imgpel **Img, byte Strength[16], Macroblock *MbQ, + int edge, int uv, StorablePicture *p) { + VideoParameters *p_Vid = MbQ->p_Vid; - int block_width = p_Vid->mb_cr_size_x; + int block_width = p_Vid->mb_cr_size_x; int block_height = p_Vid->mb_cr_size_y; int xQ = edge - 1; - int yQ = 0; + int yQ = 0; - Macroblock *MbP = get_non_aff_neighbor_chroma(MbQ,xQ,yQ,block_width,block_height); + Macroblock *MbP = + get_non_aff_neighbor_chroma(MbQ, xQ, yQ, block_width, block_height); - if (MbP || (MbQ->DFDisableIdc == 0)) - { - int bitdepth_scale = p_Vid->bitdepth_scale[IS_CHROMA]; - int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; + if (MbP || (MbQ->DFDisableIdc == 0)) { + int bitdepth_scale = p_Vid->bitdepth_scale[IS_CHROMA]; + int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; int AlphaC0Offset = MbQ->DFAlphaC0Offset; int BetaOffset = MbQ->DFBetaOffset; @@ -705,50 +673,43 @@ static void EdgeLoopChromaVer(imgpel** Img, byte Strength[16], Macroblock *MbQ, int indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset); int indexB = iClip3(0, MAX_QP, QP + BetaOffset); - int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; - int Beta = BETA_TABLE [indexB] * bitdepth_scale; + int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; + int Beta = BETA_TABLE[indexB] * bitdepth_scale; - if ((Alpha | Beta) != 0) - { + if ((Alpha | Beta) != 0) { const int PelNum = pelnum_cr[0][p->chroma_format_idc]; - const byte *ClipTab = CLIP_TAB[indexA]; + const byte *ClipTab = CLIP_TAB[indexA]; int pel; int pos_x1 = get_pos_x_chroma(MbP, xQ, (block_width - 1)); - imgpel **cur_img = &Img[get_pos_y_chroma(MbP,yQ, (block_height - 1))]; + imgpel **cur_img = &Img[get_pos_y_chroma(MbP, yQ, (block_height - 1))]; - for( pel = 0 ; pel < PelNum ; ++pel ) - { - int Strng = Strength[(PelNum == 8) ? (((pel >> 1) << 2) + (pel & 0x01)) : pel]; + for (pel = 0; pel < PelNum; ++pel) { + int Strng = + Strength[(PelNum == 8) ? (((pel >> 1) << 2) + (pel & 0x01)) : pel]; - if( Strng != 0) - { + if (Strng != 0) { imgpel *SrcPtrP = *cur_img + pos_x1; imgpel *SrcPtrQ = SrcPtrP + 1; int edge_diff = *SrcPtrQ - *SrcPtrP; - if ( iabs( edge_diff ) < Alpha ) - { - imgpel R1 = *(SrcPtrQ + 1); - if ( iabs(*SrcPtrQ - R1) < Beta ) - { - imgpel L1 = *(SrcPtrP - 1); - if ( iabs(*SrcPtrP - L1) < Beta ) - { - if( Strng == 4 ) // INTRA strong filtering + if (iabs(edge_diff) < Alpha) { + imgpel R1 = *(SrcPtrQ + 1); + if (iabs(*SrcPtrQ - R1) < Beta) { + imgpel L1 = *(SrcPtrP - 1); + if (iabs(*SrcPtrP - L1) < Beta) { + if (Strng == 4) // INTRA strong filtering { - *SrcPtrP = (imgpel) ( ((L1 << 1) + *SrcPtrP + R1 + 2) >> 2 ); - *SrcPtrQ = (imgpel) ( ((R1 << 1) + *SrcPtrQ + L1 + 2) >> 2 ); - } - else - { - int tc0 = ClipTab[ Strng ] * bitdepth_scale + 1; - int dif = iClip3( -tc0, tc0, ( ((edge_diff) << 2) + (L1 - R1) + 4) >> 3 ); + *SrcPtrP = (imgpel)(((L1 << 1) + *SrcPtrP + R1 + 2) >> 2); + *SrcPtrQ = (imgpel)(((R1 << 1) + *SrcPtrQ + L1 + 2) >> 2); + } else { + int tc0 = ClipTab[Strng] * bitdepth_scale + 1; + int dif = iClip3(-tc0, tc0, + (((edge_diff) << 2) + (L1 - R1) + 4) >> 3); - if (dif != 0) - { - *SrcPtrP = (imgpel) iClip1 ( max_imgpel_value, *SrcPtrP + dif); - *SrcPtrQ = (imgpel) iClip1 ( max_imgpel_value, *SrcPtrQ - dif); + if (dif != 0) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, *SrcPtrP + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, *SrcPtrQ - dif); } } } @@ -756,36 +717,35 @@ static void EdgeLoopChromaVer(imgpel** Img, byte Strength[16], Macroblock *MbQ, } } cur_img++; - } + } } } } - /*! ***************************************************************************************** * \brief * Filters chroma block edge for Frame or Field coded pictures ***************************************************************************************** */ -static void EdgeLoopChromaHor(imgpel** Img, byte Strength[16], Macroblock *MbQ, int edge, int uv, StorablePicture *p) -{ - VideoParameters *p_Vid = MbQ->p_Vid; +static void EdgeLoopChromaHor(imgpel **Img, byte Strength[16], Macroblock *MbQ, + int edge, int uv, StorablePicture *p) { + VideoParameters *p_Vid = MbQ->p_Vid; int block_width = p_Vid->mb_cr_size_x; int block_height = p_Vid->mb_cr_size_y; int xQ = 0; - int yQ = (edge < 16 ? edge - 1: 0); + int yQ = (edge < 16 ? edge - 1 : 0); - Macroblock *MbP = get_non_aff_neighbor_chroma(MbQ,xQ,yQ,block_width,block_height); + Macroblock *MbP = + get_non_aff_neighbor_chroma(MbQ, xQ, yQ, block_width, block_height); - if (MbP || (MbQ->DFDisableIdc == 0)) - { - int bitdepth_scale = p_Vid->bitdepth_scale[IS_CHROMA]; - int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; + if (MbP || (MbQ->DFDisableIdc == 0)) { + int bitdepth_scale = p_Vid->bitdepth_scale[IS_CHROMA]; + int max_imgpel_value = p_Vid->max_pel_value_comp[uv + 1]; int AlphaC0Offset = MbQ->DFAlphaC0Offset; int BetaOffset = MbQ->DFBetaOffset; - int width = p->iChromaStride; //p->size_x_cr; + int width = p->iChromaStride; // p->size_x_cr; // Average QP of the two blocks int QP = (MbP->qpc[uv] + MbQ->qpc[uv] + 1) >> 1; @@ -793,51 +753,45 @@ static void EdgeLoopChromaHor(imgpel** Img, byte Strength[16], Macroblock *MbQ, int indexA = iClip3(0, MAX_QP, QP + AlphaC0Offset); int indexB = iClip3(0, MAX_QP, QP + BetaOffset); - int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; - int Beta = BETA_TABLE [indexB] * bitdepth_scale; + int Alpha = ALPHA_TABLE[indexA] * bitdepth_scale; + int Beta = BETA_TABLE[indexB] * bitdepth_scale; - if ((Alpha | Beta) != 0) - { + if ((Alpha | Beta) != 0) { const int PelNum = pelnum_cr[1][p->chroma_format_idc]; - const byte *ClipTab = CLIP_TAB[indexA]; + const byte *ClipTab = CLIP_TAB[indexA]; int pel; - imgpel *imgP = &Img[get_pos_y_chroma(MbP,yQ, (block_height-1))][get_pos_x_chroma(MbP,xQ, (block_width - 1))]; - imgpel *imgQ = imgP + width ; + imgpel *imgP = &Img[get_pos_y_chroma(MbP, yQ, (block_height - 1))] + [get_pos_x_chroma(MbP, xQ, (block_width - 1))]; + imgpel *imgQ = imgP + width; - for( pel = 0 ; pel < PelNum ; ++pel ) - { - int Strng = Strength[(PelNum == 8) ? (((pel >> 1) << 2) + (pel & 0x01)) : pel]; + for (pel = 0; pel < PelNum; ++pel) { + int Strng = + Strength[(PelNum == 8) ? (((pel >> 1) << 2) + (pel & 0x01)) : pel]; - if( Strng != 0) - { + if (Strng != 0) { imgpel *SrcPtrP = imgP; imgpel *SrcPtrQ = imgQ; int edge_diff = *imgQ - *imgP; - if ( iabs( edge_diff ) < Alpha ) - { - imgpel R1 = *(SrcPtrQ + width); - if ( iabs(*SrcPtrQ - R1) < Beta ) - { - imgpel L1 = *(SrcPtrP - width); - if ( iabs(*SrcPtrP - L1) < Beta ) - { - if( Strng == 4 ) // INTRA strong filtering + if (iabs(edge_diff) < Alpha) { + imgpel R1 = *(SrcPtrQ + width); + if (iabs(*SrcPtrQ - R1) < Beta) { + imgpel L1 = *(SrcPtrP - width); + if (iabs(*SrcPtrP - L1) < Beta) { + if (Strng == 4) // INTRA strong filtering { - *SrcPtrP = (imgpel) ( ((L1 << 1) + *SrcPtrP + R1 + 2) >> 2 ); - *SrcPtrQ = (imgpel) ( ((R1 << 1) + *SrcPtrQ + L1 + 2) >> 2 ); - } - else - { - int tc0 = ClipTab[ Strng ] * bitdepth_scale + 1; - int dif = iClip3( -tc0, tc0, ( ((edge_diff) << 2) + (L1 - R1) + 4) >> 3 ); + *SrcPtrP = (imgpel)(((L1 << 1) + *SrcPtrP + R1 + 2) >> 2); + *SrcPtrQ = (imgpel)(((R1 << 1) + *SrcPtrQ + L1 + 2) >> 2); + } else { + int tc0 = ClipTab[Strng] * bitdepth_scale + 1; + int dif = iClip3(-tc0, tc0, + (((edge_diff) << 2) + (L1 - R1) + 4) >> 3); - if (dif != 0) - { - *SrcPtrP = (imgpel) iClip1 ( max_imgpel_value, *SrcPtrP + dif); - *SrcPtrQ = (imgpel) iClip1 ( max_imgpel_value, *SrcPtrQ - dif); + if (dif != 0) { + *SrcPtrP = (imgpel)iClip1(max_imgpel_value, *SrcPtrP + dif); + *SrcPtrQ = (imgpel)iClip1(max_imgpel_value, *SrcPtrQ - dif); } } } @@ -846,9 +800,7 @@ static void EdgeLoopChromaHor(imgpel** Img, byte Strength[16], Macroblock *MbQ, } imgP++; imgQ++; - } + } } } } - - diff --git a/src/common/ldecod_src/macroblock.c b/src/common/ldecod_src/macroblock.c index c523d6e..1bfcca7 100644 --- a/src/common/ldecod_src/macroblock.c +++ b/src/common/ldecod_src/macroblock.c @@ -6,7 +6,8 @@ * Decode a Macroblock * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Inge Lille-Langy * - Rickard Sjoberg * - Jani Lainema @@ -18,31 +19,31 @@ * - Lowell Winger * - Alexis Michael Tourapis *********************************************************************** -*/ + */ #include "contributors.h" #include #include "block.h" +#include "elements.h" #include "global.h" #include "mbuffer.h" #include "mbuffer_mvc.h" -#include "elements.h" -//#include "errorconcealment.h" -#include "macroblock.h" -#include "fmo.h" -#include "cabac.h" -#include "vlc.h" -#include "image.h" -#include "mb_access.h" +// #include "errorconcealment.h" #include "biaridecod.h" -#include "transform.h" -#include "mc_prediction.h" -#include "quant.h" -#include "mv_prediction.h" -#include "mb_prediction.h" +#include "cabac.h" #include "fast_memory.h" +#include "fmo.h" +#include "image.h" +#include "macroblock.h" +#include "mb_access.h" +#include "mb_prediction.h" +#include "mc_prediction.h" +#include "mv_prediction.h" +#include "quant.h" +#include "transform.h" +#include "vlc.h" #if TRACE #define TRACE_STRING(s) strncpy(currSE.tracestring, s, TRACESTRING_SIZE) @@ -52,36 +53,45 @@ #else #define TRACE_STRING(s) #define TRACE_DECBITS(i) -#define TRACE_PRINTF(s) +#define TRACE_PRINTF(s) #define TRACE_STRING_P(s) #endif //! look up tables for FRExt_chroma support void dectracebitcnt(int count); -static void read_CBP_and_coeffs_from_NAL_CABAC_420 (Macroblock *currMB); -static void read_CBP_and_coeffs_from_NAL_CABAC_400 (Macroblock *currMB); -static void read_CBP_and_coeffs_from_NAL_CABAC_422 (Macroblock *currMB); -static void read_CBP_and_coeffs_from_NAL_CABAC_444 (Macroblock *currMB); -static void read_CBP_and_coeffs_from_NAL_CAVLC_420 (Macroblock *currMB); -static void read_CBP_and_coeffs_from_NAL_CAVLC_400 (Macroblock *currMB); -static void read_CBP_and_coeffs_from_NAL_CAVLC_422 (Macroblock *currMB); -static void read_CBP_and_coeffs_from_NAL_CAVLC_444 (Macroblock *currMB); -static void read_motion_info_from_NAL_p_slice (Macroblock *currMB); -static void read_motion_info_from_NAL_b_slice (Macroblock *currMB); -static void read_ipred_modes (Macroblock *currMB); -static void read_IPCM_coeffs_from_NAL (Slice *currSlice, struct datapartition *dP); -static void read_one_macroblock_i_slice (Macroblock *currMB); -static void read_one_macroblock_p_slice (Macroblock *currMB); -static void read_one_macroblock_b_slice (Macroblock *currMB); -static int decode_one_component_i_slice (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -static int decode_one_component_p_slice (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -static int decode_one_component_b_slice (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -static int decode_one_component_sp_slice (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture); -extern void update_direct_types (Slice *currSlice); +static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB); +static void read_CBP_and_coeffs_from_NAL_CABAC_400(Macroblock *currMB); +static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB); +static void read_CBP_and_coeffs_from_NAL_CABAC_444(Macroblock *currMB); +static void read_CBP_and_coeffs_from_NAL_CAVLC_420(Macroblock *currMB); +static void read_CBP_and_coeffs_from_NAL_CAVLC_400(Macroblock *currMB); +static void read_CBP_and_coeffs_from_NAL_CAVLC_422(Macroblock *currMB); +static void read_CBP_and_coeffs_from_NAL_CAVLC_444(Macroblock *currMB); +static void read_motion_info_from_NAL_p_slice(Macroblock *currMB); +static void read_motion_info_from_NAL_b_slice(Macroblock *currMB); +static void read_ipred_modes(Macroblock *currMB); +static void read_IPCM_coeffs_from_NAL(Slice *currSlice, + struct datapartition *dP); +static void read_one_macroblock_i_slice(Macroblock *currMB); +static void read_one_macroblock_p_slice(Macroblock *currMB); +static void read_one_macroblock_b_slice(Macroblock *currMB); +static int decode_one_component_i_slice(Macroblock *currMB, + ColorPlane curr_plane, imgpel **currImg, + StorablePicture *dec_picture); +static int decode_one_component_p_slice(Macroblock *currMB, + ColorPlane curr_plane, imgpel **currImg, + StorablePicture *dec_picture); +static int decode_one_component_b_slice(Macroblock *currMB, + ColorPlane curr_plane, imgpel **currImg, + StorablePicture *dec_picture); +static int decode_one_component_sp_slice(Macroblock *currMB, + ColorPlane curr_plane, + imgpel **currImg, + StorablePicture *dec_picture); +extern void update_direct_types(Slice *currSlice); -static inline void reset_mv_info(PicMotionParams *mv_info) -{ +static inline void reset_mv_info(PicMotionParams *mv_info) { mv_info->ref_pic[LIST_0] = NULL; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = zero_mv; @@ -96,10 +106,7 @@ static inline void reset_mv_info(PicMotionParams *mv_info) * Set context for reference frames ************************************************************************ */ -static inline int BType2CtxRef (int btype) -{ - return (btype >= 4); -} +static inline int BType2CtxRef(int btype) { return (btype >= 4); } /*! ************************************************************************ @@ -107,17 +114,19 @@ static inline int BType2CtxRef (int btype) * Function for reading the reference picture indices using VLC ************************************************************************ */ -static signed char readRefPictureIdx_VLC(Macroblock *currMB, SyntaxElement *currSE, DataPartition *dP, signed char b8mode, int list) -{ +static signed char readRefPictureIdx_VLC(Macroblock *currMB, + SyntaxElement *currSE, + DataPartition *dP, signed char b8mode, + int list) { #if TRACE - signed char tstring[20]; - sprintf( tstring, "ref_idx_l%d", list); + signed char tstring[20]; + sprintf(tstring, "ref_idx_l%d", list); strncpy(currSE->tracestring, tstring, TRACESTRING_SIZE); #endif - currSE->context = BType2CtxRef (b8mode); + currSE->context = BType2CtxRef(b8mode); currSE->value2 = list; - dP->readSyntaxElement (currMB, currSE, dP); - return (signed char) currSE->value1; + dP->readSyntaxElement(currMB, currSE, dP); + return (signed char)currSE->value1; } /*! @@ -126,20 +135,22 @@ static signed char readRefPictureIdx_VLC(Macroblock *currMB, SyntaxElement *curr * Function for reading the reference picture indices using FLC ************************************************************************ */ -static signed char readRefPictureIdx_FLC(Macroblock *currMB, SyntaxElement *currSE, DataPartition *dP, signed char b8mode, int list) -{ +static signed char readRefPictureIdx_FLC(Macroblock *currMB, + SyntaxElement *currSE, + DataPartition *dP, signed char b8mode, + int list) { #if TRACE - signed char tstring[20]; - sprintf( tstring, "ref_idx_l%d", list); + signed char tstring[20]; + sprintf(tstring, "ref_idx_l%d", list); strncpy(currSE->tracestring, tstring, TRACESTRING_SIZE); #endif - currSE->context = BType2CtxRef (b8mode); + currSE->context = BType2CtxRef(b8mode); currSE->len = 1; readSyntaxElement_FLC(currSE, dP->bitstream); currSE->value1 = 1 - currSE->value1; - return (signed char) currSE->value1; + return (signed char)currSE->value1; } /*! @@ -148,8 +159,10 @@ static signed char readRefPictureIdx_FLC(Macroblock *currMB, SyntaxElement *curr * Dummy Function for reading the reference picture indices ************************************************************************ */ -static signed char readRefPictureIdx_Null(Macroblock *currMB, SyntaxElement *currSE, DataPartition *dP, signed char b8mode, int list) -{ +static signed char readRefPictureIdx_Null(Macroblock *currMB, + SyntaxElement *currSE, + DataPartition *dP, signed char b8mode, + int list) { return 0; } @@ -159,40 +172,38 @@ static signed char readRefPictureIdx_Null(Macroblock *currMB, SyntaxElement *cur * Function to prepare reference picture indice function pointer ************************************************************************ */ -static void prepareListforRefIdx ( Macroblock *currMB, SyntaxElement *currSE, DataPartition *dP, int num_ref_idx_active, int refidx_present) -{ - currMB->readRefPictureIdx = readRefPictureIdx_Null; // Initialize readRefPictureIdx - if(num_ref_idx_active > 1) - { - if (currMB->p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) - { +static void prepareListforRefIdx(Macroblock *currMB, SyntaxElement *currSE, + DataPartition *dP, int num_ref_idx_active, + int refidx_present) { + currMB->readRefPictureIdx = + readRefPictureIdx_Null; // Initialize readRefPictureIdx + if (num_ref_idx_active > 1) { + if (currMB->p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) { currSE->mapping = linfo_ue; - if (refidx_present) - { + if (refidx_present) { if (num_ref_idx_active == 2) - currMB->readRefPictureIdx = readRefPictureIdx_FLC; + currMB->readRefPictureIdx = readRefPictureIdx_FLC; else currMB->readRefPictureIdx = readRefPictureIdx_VLC; } - } - else - { + } else { currSE->reading = readRefFrame_CABAC; if (refidx_present) currMB->readRefPictureIdx = readRefPictureIdx_VLC; } - } + } } -void set_chroma_qp(Macroblock* currMB) -{ +void set_chroma_qp(Macroblock *currMB) { VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currMB->p_Slice->dec_picture; int i; - for (i=0; i<2; ++i) - { - currMB->qpc[i] = iClip3 ( -p_Vid->bitdepth_chroma_qp_scale, 51, currMB->qp + dec_picture->chroma_qp_offset[i] ); - currMB->qpc[i] = currMB->qpc[i] < 0 ? currMB->qpc[i] : QP_SCALE_CR[currMB->qpc[i]]; + for (i = 0; i < 2; ++i) { + currMB->qpc[i] = iClip3(-p_Vid->bitdepth_chroma_qp_scale, 51, + currMB->qp + dec_picture->chroma_qp_offset[i]); + currMB->qpc[i] = + currMB->qpc[i] < 0 ? currMB->qpc[i] : QP_SCALE_CR[currMB->qpc[i]]; currMB->qp_scaled[i + 1] = currMB->qpc[i] + p_Vid->bitdepth_chroma_qp_scale; } } @@ -203,39 +214,43 @@ void set_chroma_qp(Macroblock* currMB) * updates chroma QP according to luma QP and bit depth ************************************************************************ */ -void update_qp(Macroblock *currMB, int qp) -{ +void update_qp(Macroblock *currMB, int qp) { VideoParameters *p_Vid = currMB->p_Vid; currMB->qp = qp; currMB->qp_scaled[0] = qp + p_Vid->bitdepth_luma_qp_scale; set_chroma_qp(currMB); - currMB->is_lossless = (Boolean) ((currMB->qp_scaled[0] == 0) && (p_Vid->lossless_qpprime_flag == 1)); + currMB->is_lossless = (Boolean)((currMB->qp_scaled[0] == 0) && + (p_Vid->lossless_qpprime_flag == 1)); } -static void read_delta_quant(SyntaxElement *currSE, DataPartition *dP, Macroblock *currMB, const byte *partMap, int type) -{ +static void read_delta_quant(SyntaxElement *currSE, DataPartition *dP, + Macroblock *currMB, const byte *partMap, + int type) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + currSE->type = type; dP = &(currSlice->partArr[partMap[currSE->type]]); - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) - { + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) { currSE->mapping = linfo_se; - } - else - currSE->reading= read_dQuant_CABAC; + } else + currSE->reading = read_dQuant_CABAC; TRACE_STRING_P("mb_qp_delta"); dP->readSyntaxElement(currMB, currSE, dP); - currMB->delta_quant = (short) currSE->value1; - if ((currMB->delta_quant < -(26 + p_Vid->bitdepth_luma_qp_scale/2)) || (currMB->delta_quant > (25 + p_Vid->bitdepth_luma_qp_scale/2))) - error ("mb_qp_delta is out of range", 500); + currMB->delta_quant = (short)currSE->value1; + if ((currMB->delta_quant < -(26 + p_Vid->bitdepth_luma_qp_scale / 2)) || + (currMB->delta_quant > (25 + p_Vid->bitdepth_luma_qp_scale / 2))) + error("mb_qp_delta is out of range", 500); - currSlice->qp = ((currSlice->qp + currMB->delta_quant + 52 + 2*p_Vid->bitdepth_luma_qp_scale)%(52+p_Vid->bitdepth_luma_qp_scale)) - p_Vid->bitdepth_luma_qp_scale; + currSlice->qp = ((currSlice->qp + currMB->delta_quant + 52 + + 2 * p_Vid->bitdepth_luma_qp_scale) % + (52 + p_Vid->bitdepth_luma_qp_scale)) - + p_Vid->bitdepth_luma_qp_scale; update_qp(currMB, currSlice->qp); } @@ -245,24 +260,25 @@ static void read_delta_quant(SyntaxElement *currSE, DataPartition *dP, Macrobloc * Function to read reference picture indice values ************************************************************************ */ -static void readMBRefPictureIdx (SyntaxElement *currSE, DataPartition *dP, Macroblock *currMB, PicMotionParams **mv_info, int list, int step_v0, int step_h0) -{ +static void readMBRefPictureIdx(SyntaxElement *currSE, DataPartition *dP, + Macroblock *currMB, PicMotionParams **mv_info, + int list, int step_v0, int step_h0) { int k, j, i, j0, i0; signed char refframe; - for (j0 = 0; j0 < 4; j0 += step_v0) - { + for (j0 = 0; j0 < 4; j0 += step_v0) { currMB->subblock_y = j0 << 2; - for (i0 = 0; i0 < 4; i0 += step_h0) - { + for (i0 = 0; i0 < 4; i0 += step_h0) { k = 2 * (j0 >> 1) + (i0 >> 1); - if ((currMB->b8pdir[k] == list || currMB->b8pdir[k] == BI_PRED) && currMB->b8mode[k] != 0) - { + if ((currMB->b8pdir[k] == list || currMB->b8pdir[k] == BI_PRED) && + currMB->b8mode[k] != 0) { currMB->subblock_x = i0 << 2; - refframe = currMB->readRefPictureIdx(currMB, currSE, dP, currMB->b8mode[k], list); + refframe = currMB->readRefPictureIdx(currMB, currSE, dP, + currMB->b8mode[k], list); for (j = j0; j < j0 + step_v0; ++j) - for (i = currMB->block_x + i0; i < currMB->block_x + i0 + step_h0; ++i) + for (i = currMB->block_x + i0; i < currMB->block_x + i0 + step_h0; + ++i) mv_info[j][i].ref_idx[list] = refframe; } } @@ -275,85 +291,88 @@ static void readMBRefPictureIdx (SyntaxElement *currSE, DataPartition *dP, Macro * Function to read reference picture indice values ************************************************************************ */ -static void readMBMotionVectors (SyntaxElement *currSE, DataPartition *dP, Macroblock *currMB, int list, int step_h0, int step_v0) -{ +static void readMBMotionVectors(SyntaxElement *currSE, DataPartition *dP, + Macroblock *currMB, int list, int step_h0, + int step_v0) { int i, j, k, i4, j4, ii, jj, kk, i0, j0; short curr_mvd[2]; MotionVector pred_mv, curr_mv; - short (*mvd)[4][2]; - //VideoParameters *p_Vid = currMB->p_Vid; + short(*mvd)[4][2]; + // VideoParameters *p_Vid = currMB->p_Vid; PicMotionParams **mv_info = currMB->p_Slice->dec_picture->mv_info; PixelPos block[4]; // neighbor blocks - for (j0=0; j0<4; j0+=step_v0) - { - for (i0=0; i0<4; i0+=step_h0) - { + for (j0 = 0; j0 < 4; j0 += step_v0) { + for (i0 = 0; i0 < 4; i0 += step_h0) { kk = 2 * (j0 >> 1) + (i0 >> 1); - if ((currMB->b8pdir[kk] == list || currMB->b8pdir[kk]== BI_PRED) && (currMB->b8mode[kk] != 0))//has forward vector + if ((currMB->b8pdir[kk] == list || currMB->b8pdir[kk] == BI_PRED) && + (currMB->b8mode[kk] != 0)) // has forward vector { - signed char cur_ref_idx = mv_info[currMB->block_y+j0][currMB->block_x+i0].ref_idx[list]; - int mv_mode = currMB->b8mode[kk]; - int step_h = BLOCK_STEP [mv_mode][0]; - int step_v = BLOCK_STEP [mv_mode][1]; + signed char cur_ref_idx = + mv_info[currMB->block_y + j0][currMB->block_x + i0].ref_idx[list]; + int mv_mode = currMB->b8mode[kk]; + int step_h = BLOCK_STEP[mv_mode][0]; + int step_v = BLOCK_STEP[mv_mode][1]; int step_h4 = step_h << 2; int step_v4 = step_v << 2; - for (j = j0; j < j0 + step_v0; j += step_v) - { - currMB->subblock_y = j << 2; // position used for context determination - j4 = currMB->block_y + j; - mvd = &currMB->mvd [list][j]; + for (j = j0; j < j0 + step_v0; j += step_v) { + currMB->subblock_y = j + << 2; // position used for context determination + j4 = currMB->block_y + j; + mvd = &currMB->mvd[list][j]; - for (i = i0; i < i0 + step_h0; i += step_h) - { - currMB->subblock_x = i << 2; // position used for context determination + for (i = i0; i < i0 + step_h0; i += step_h) { + currMB->subblock_x = + i << 2; // position used for context determination i4 = currMB->block_x + i; - get_neighbors(currMB, block, BLOCK_SIZE * i, BLOCK_SIZE * j, step_h4); + get_neighbors(currMB, block, BLOCK_SIZE * i, BLOCK_SIZE * j, + step_h4); // first get MV predictor - currMB->GetMVPredictor (currMB, block, &pred_mv, cur_ref_idx, mv_info, list, BLOCK_SIZE * i, BLOCK_SIZE * j, step_h4, step_v4); + currMB->GetMVPredictor(currMB, block, &pred_mv, cur_ref_idx, + mv_info, list, BLOCK_SIZE * i, + BLOCK_SIZE * j, step_h4, step_v4); - for (k=0; k < 2; ++k) - { + for (k = 0; k < 2; ++k) { #if TRACE - signed char tstring[20]; - sprintf( tstring, "mvd_l%d", list); + signed char tstring[20]; + sprintf(tstring, "mvd_l%d", list); strncpy(currSE->tracestring, tstring, TRACESTRING_SIZE); #endif - currSE->value2 = (k << 1) + list; // identifies the component; only used for context determination + currSE->value2 = + (k << 1) + list; // identifies the component; only used for + // context determination dP->readSyntaxElement(currMB, currSE, dP); - curr_mvd[k] = (short) currSE->value1; + curr_mvd[k] = (short)currSE->value1; } - curr_mv.mv_x = (short)(curr_mvd[0] + pred_mv.mv_x); // compute motion vector - curr_mv.mv_y = (short)(curr_mvd[1] + pred_mv.mv_y); // compute motion vector + curr_mv.mv_x = + (short)(curr_mvd[0] + pred_mv.mv_x); // compute motion vector + curr_mv.mv_y = + (short)(curr_mvd[1] + pred_mv.mv_y); // compute motion vector - for(jj = j4; jj < j4 + step_v; ++jj) - { + for (jj = j4; jj < j4 + step_v; ++jj) { PicMotionParams *mvinfo = mv_info[jj] + i4; - for(ii = i4; ii < i4 + step_h; ++ii) - { + for (ii = i4; ii < i4 + step_h; ++ii) { (mvinfo++)->mv[list] = curr_mv; - } + } } // Init first line (mvd) - for(ii = i; ii < i + step_h; ++ii) - { + for (ii = i; ii < i + step_h; ++ii) { //*((int *) &mvd[0][ii][0]) = *((int *) curr_mvd); mvd[0][ii][0] = curr_mvd[0]; mvd[0][ii][1] = curr_mvd[1]; - //memcpy(&mvd[0][ii][0], curr_mvd, 2 * sizeof(short)); - } + // memcpy(&mvd[0][ii][0], curr_mvd, 2 * sizeof(short)); + } // now copy all other lines - for(jj = 1; jj < step_v; ++jj) - { - memcpy(&mvd[jj][i][0], &mvd[0][i][0], 2 * step_h * sizeof(short)); + for (jj = 1; jj < step_v; ++jj) { + memcpy(&mvd[jj][i][0], &mvd[0][i][0], 2 * step_h * sizeof(short)); } } } @@ -362,17 +381,19 @@ static void readMBMotionVectors (SyntaxElement *currSE, DataPartition *dP, Macro } } -void invScaleCoeff(Macroblock *currMB, int level, int run, int qp_per, int i, int j, int i0, int j0, int coef_ctr, const byte (*pos_scan4x4)[2], int (*InvLevelScale4x4)[4]) -{ - if (level != 0) /* leave if level == 0 */ +void invScaleCoeff(Macroblock *currMB, int level, int run, int qp_per, int i, + int j, int i0, int j0, int coef_ctr, + const byte (*pos_scan4x4)[2], int (*InvLevelScale4x4)[4]) { + if (level != 0) /* leave if level == 0 */ { coef_ctr += run + 1; i0 = pos_scan4x4[coef_ctr][0]; j0 = pos_scan4x4[coef_ctr][1]; - currMB->cbp_blk[0] |= i64_power2((j << 2) + i) ; - currMB->p_Slice->cof[0][(j<<2) + j0][(i<<2) + i0]= rshift_rnd_sf((level * InvLevelScale4x4[j0][i0]) << qp_per, 4); + currMB->cbp_blk[0] |= i64_power2((j << 2) + i); + currMB->p_Slice->cof[0][(j << 2) + j0][(i << 2) + i0] = + rshift_rnd_sf((level * InvLevelScale4x4[j0][i0]) << qp_per, 4); } } @@ -382,52 +403,61 @@ void invScaleCoeff(Macroblock *currMB, int level, int run, int qp_per, int i, in * initializes the current macroblock ************************************************************************ */ -void start_macroblock(Slice *currSlice, Macroblock **currMB) -{ +void start_macroblock(Slice *currSlice, Macroblock **currMB) { VideoParameters *p_Vid = currSlice->p_Vid; - StorablePicture *dec_picture = currSlice->dec_picture; //p_Vid->dec_picture; + StorablePicture *dec_picture = currSlice->dec_picture; // p_Vid->dec_picture; int mb_nr = currSlice->current_mb_nr; - - *currMB = &currSlice->mb_data[mb_nr]; //&p_Vid->mb_data[mb_nr]; // initialization code deleted, see below, StW + + *currMB = + &currSlice->mb_data[mb_nr]; //&p_Vid->mb_data[mb_nr]; // initialization + //code deleted, see below, StW (*currMB)->p_Slice = currSlice; - (*currMB)->p_Vid = p_Vid; + (*currMB)->p_Vid = p_Vid; (*currMB)->mbAddrX = mb_nr; - //assert (mb_nr < (int) p_Vid->PicSizeInMbs); + // assert (mb_nr < (int) p_Vid->PicSizeInMbs); /* Update coordinates of the current macroblock */ - if (currSlice->mb_aff_frame_flag) - { - (*currMB)->mb.x = (short) ( (mb_nr) % ((2*p_Vid->width) / MB_BLOCK_SIZE)); - (*currMB)->mb.y = (short) (2*((mb_nr) / ((2*p_Vid->width) / MB_BLOCK_SIZE))); + if (currSlice->mb_aff_frame_flag) { + (*currMB)->mb.x = (short)((mb_nr) % ((2 * p_Vid->width) / MB_BLOCK_SIZE)); + (*currMB)->mb.y = + (short)(2 * ((mb_nr) / ((2 * p_Vid->width) / MB_BLOCK_SIZE))); (*currMB)->mb.y += ((*currMB)->mb.x & 0x01); (*currMB)->mb.x >>= 1; - } - else - { + } else { (*currMB)->mb = PicPos[mb_nr]; } /* Define pixel/block positions */ - (*currMB)->block_x = (*currMB)->mb.x * BLOCK_SIZE; /* horizontal block position */ - (*currMB)->block_y = (*currMB)->mb.y * BLOCK_SIZE; /* vertical block position */ - (*currMB)->block_y_aff = (*currMB)->block_y; /* interlace relative vertical position */ - (*currMB)->pix_x = (*currMB)->mb.x * MB_BLOCK_SIZE; /* horizontal luma pixel position */ - (*currMB)->pix_y = (*currMB)->mb.y * MB_BLOCK_SIZE; /* vertical luma pixel position */ - (*currMB)->pix_c_x = (*currMB)->mb.x * p_Vid->mb_cr_size_x; /* horizontal chroma pixel position */ - (*currMB)->pix_c_y = (*currMB)->mb.y * p_Vid->mb_cr_size_y; /* vertical chroma pixel position */ + (*currMB)->block_x = + (*currMB)->mb.x * BLOCK_SIZE; /* horizontal block position */ + (*currMB)->block_y = + (*currMB)->mb.y * BLOCK_SIZE; /* vertical block position */ + (*currMB)->block_y_aff = + (*currMB)->block_y; /* interlace relative vertical position */ + (*currMB)->pix_x = + (*currMB)->mb.x * MB_BLOCK_SIZE; /* horizontal luma pixel position */ + (*currMB)->pix_y = + (*currMB)->mb.y * MB_BLOCK_SIZE; /* vertical luma pixel position */ + (*currMB)->pix_c_x = + (*currMB)->mb.x * + p_Vid->mb_cr_size_x; /* horizontal chroma pixel position */ + (*currMB)->pix_c_y = (*currMB)->mb.y * + p_Vid->mb_cr_size_y; /* vertical chroma pixel position */ // reset intra mode (*currMB)->is_intra_block = FALSE; // Save the slice number of this macroblock. When the macroblock below // is coded it will use this to decide if prediction for above is possible - (*currMB)->slice_nr = (short) currSlice->current_slice_nr; + (*currMB)->slice_nr = (short)currSlice->current_slice_nr; - dec_picture->slice_id[(*currMB)->mb.y][(*currMB)->mb.x] = (short) currSlice->current_slice_nr; - //dec_picture->max_slice_id = (short) imax(currSlice->current_slice_nr, dec_picture->max_slice_id); + dec_picture->slice_id[(*currMB)->mb.y][(*currMB)->mb.x] = + (short)currSlice->current_slice_nr; + // dec_picture->max_slice_id = (short) imax(currSlice->current_slice_nr, + // dec_picture->max_slice_id); CheckAvailabilityOfNeighbors(*currMB); @@ -437,24 +467,24 @@ void start_macroblock(Slice *currSlice, Macroblock **currMB) set_read_and_store_CBP(currMB, currSlice->active_sps->chroma_format_idc); // Reset syntax element entries in MB struct - //update_qp(*currMB, currSlice->qp); - (*currMB)->mb_type = 0; - (*currMB)->delta_quant = 0; - (*currMB)->cbp = 0; - (*currMB)->c_ipred_mode = DC_PRED_8; + // update_qp(*currMB, currSlice->qp); + (*currMB)->mb_type = 0; + (*currMB)->delta_quant = 0; + (*currMB)->cbp = 0; + (*currMB)->c_ipred_mode = DC_PRED_8; - if (currSlice->slice_type != I_SLICE) - { + if (currSlice->slice_type != I_SLICE) { if (currSlice->slice_type != B_SLICE) - fast_memset((*currMB)->mvd[0][0][0], 0, MB_BLOCK_PARTITIONS * 2 * sizeof(short)); + fast_memset((*currMB)->mvd[0][0][0], 0, + MB_BLOCK_PARTITIONS * 2 * sizeof(short)); else - fast_memset((*currMB)->mvd[0][0][0], 0, 2 * MB_BLOCK_PARTITIONS * 2 * sizeof(short)); + fast_memset((*currMB)->mvd[0][0][0], 0, + 2 * MB_BLOCK_PARTITIONS * 2 * sizeof(short)); } - + { int i; - for (i = 0; i < 3; i++) - { + for (i = 0; i < 3; i++) { (*currMB)->cbp_blk[i] = 0; (*currMB)->cbp_bits[i] = 0; (*currMB)->cbp_bits_8x8[i] = 0; @@ -462,27 +492,30 @@ void start_macroblock(Slice *currSlice, Macroblock **currMB) } // initialize currSlice->mb_rres - if (currSlice->is_reset_coeff == FALSE) - { + if (currSlice->is_reset_coeff == FALSE) { fast_memset(currSlice->mb_rres[0][0], 0, MB_PIXELS * sizeof(int)); - fast_memset(currSlice->mb_rres[1][0], 0, p_Vid->mb_cr_size_x * p_Vid->mb_cr_size_y * sizeof(int)); - fast_memset(currSlice->mb_rres[2][0], 0, p_Vid->mb_cr_size_x * p_Vid->mb_cr_size_y * sizeof(int)); - fast_memset(currSlice->cof[0][0], 0, MB_PIXELS * sizeof(int)); // reset luma coeffs + fast_memset(currSlice->mb_rres[1][0], 0, + p_Vid->mb_cr_size_x * p_Vid->mb_cr_size_y * sizeof(int)); + fast_memset(currSlice->mb_rres[2][0], 0, + p_Vid->mb_cr_size_x * p_Vid->mb_cr_size_y * sizeof(int)); + fast_memset(currSlice->cof[0][0], 0, + MB_PIXELS * sizeof(int)); // reset luma coeffs fast_memset(currSlice->cof[1][0], 0, MB_PIXELS * sizeof(int)); fast_memset(currSlice->cof[2][0], 0, MB_PIXELS * sizeof(int)); - //fast_memset(currSlice->fcf[0][0], 0, MB_PIXELS * sizeof(int)); // reset luma coeffs - //fast_memset(currSlice->fcf[1][0], 0, MB_PIXELS * sizeof(int)); - //fast_memset(currSlice->fcf[2][0], 0, MB_PIXELS * sizeof(int)); + // fast_memset(currSlice->fcf[0][0], 0, MB_PIXELS * sizeof(int)); // reset + // luma coeffs fast_memset(currSlice->fcf[1][0], 0, MB_PIXELS * + // sizeof(int)); fast_memset(currSlice->fcf[2][0], 0, MB_PIXELS * + // sizeof(int)); currSlice->is_reset_coeff = TRUE; } - + // store filtering parameters for this MB - (*currMB)->DFDisableIdc = currSlice->DFDisableIdc; + (*currMB)->DFDisableIdc = currSlice->DFDisableIdc; (*currMB)->DFAlphaC0Offset = currSlice->DFAlphaC0Offset; - (*currMB)->DFBetaOffset = currSlice->DFBetaOffset; + (*currMB)->DFBetaOffset = currSlice->DFBetaOffset; (*currMB)->list_offset = 0; - (*currMB)->mixedModeEdgeFlag=0; + (*currMB)->mixedModeEdgeFlag = 0; } /*! @@ -492,40 +525,42 @@ void start_macroblock(Slice *currSlice, Macroblock **currMB) * check end_of_slice condition ************************************************************************ */ -Boolean exit_macroblock(Slice *currSlice, int eos_bit) -{ +Boolean exit_macroblock(Slice *currSlice, int eos_bit) { VideoParameters *p_Vid = currSlice->p_Vid; - //! The if() statement below resembles the original code, which tested + //! The if() statement below resembles the original code, which tested //! p_Vid->current_mb_nr == p_Vid->PicSizeInMbs. Both is, of course, nonsense //! In an error prone environment, one can only be sure to have a new //! picture by checking the tr of the next slice header! -// printf ("exit_macroblock: FmoGetLastMBOfPicture %d, p_Vid->current_mb_nr %d\n", FmoGetLastMBOfPicture(), p_Vid->current_mb_nr); + // printf ("exit_macroblock: FmoGetLastMBOfPicture %d, p_Vid->current_mb_nr + // %d\n", FmoGetLastMBOfPicture(), p_Vid->current_mb_nr); ++(currSlice->num_dec_mb); - if(currSlice->current_mb_nr == p_Vid->PicSizeInMbs - 1) //if (p_Vid->num_dec_mb == p_Vid->PicSizeInMbs) + if (currSlice->current_mb_nr == + p_Vid->PicSizeInMbs - 1) // if (p_Vid->num_dec_mb == p_Vid->PicSizeInMbs) { return TRUE; } // ask for last mb in the slice CAVLC - else - { + else { - currSlice->current_mb_nr = FmoGetNextMBNr (p_Vid, currSlice->current_mb_nr); + currSlice->current_mb_nr = FmoGetNextMBNr(p_Vid, currSlice->current_mb_nr); - if (currSlice->current_mb_nr == (unsigned int) -1) // End of Slice group, MUST be end of slice + if (currSlice->current_mb_nr == + (unsigned int)-1) // End of Slice group, MUST be end of slice { - assert (currSlice->nal_startcode_follows (currSlice, eos_bit) == TRUE); + assert(currSlice->nal_startcode_follows(currSlice, eos_bit) == TRUE); return TRUE; } - if(currSlice->nal_startcode_follows(currSlice, eos_bit) == FALSE) + if (currSlice->nal_startcode_follows(currSlice, eos_bit) == FALSE) return FALSE; - if(currSlice->slice_type == I_SLICE || currSlice->slice_type == SI_SLICE || p_Vid->active_pps->entropy_coding_mode_flag == CABAC) + if (currSlice->slice_type == I_SLICE || currSlice->slice_type == SI_SLICE || + p_Vid->active_pps->entropy_coding_mode_flag == CABAC) return TRUE; - if(currSlice->cod_counter <= 0) + if (currSlice->cod_counter <= 0) return TRUE; return FALSE; } @@ -537,47 +572,37 @@ Boolean exit_macroblock(Slice *currSlice, int eos_bit) * Interpret the mb mode for P-Frames ************************************************************************ */ -static void interpret_mb_mode_P(Macroblock *currMB) -{ - static const short ICBPTAB[6] = {0,16,32,15,31,47}; - short mbmode = currMB->mb_type; +static void interpret_mb_mode_P(Macroblock *currMB) { + static const short ICBPTAB[6] = {0, 16, 32, 15, 31, 47}; + short mbmode = currMB->mb_type; - if(mbmode < 4) - { + if (mbmode < 4) { currMB->mb_type = mbmode; memset(currMB->b8mode, mbmode, 4 * sizeof(signed char)); memset(currMB->b8pdir, 0, 4 * sizeof(signed char)); - } - else if((mbmode == 4 || mbmode == 5)) - { + } else if ((mbmode == 4 || mbmode == 5)) { currMB->mb_type = P8x8; currMB->p_Slice->allrefzero = (mbmode == 5); - } - else if(mbmode == 6) - { + } else if (mbmode == 6) { currMB->is_intra_block = TRUE; currMB->mb_type = I4MB; - memset(currMB->b8mode,IBLOCK, 4 * sizeof(signed char)); - memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); - } - else if(mbmode == 31) - { + memset(currMB->b8mode, IBLOCK, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); + } else if (mbmode == 31) { currMB->is_intra_block = TRUE; currMB->mb_type = IPCM; currMB->cbp = -1; currMB->i16mode = 0; memset(currMB->b8mode, 0, 4 * sizeof(signed char)); - memset(currMB->b8pdir,-1, 4 * sizeof(signed char)); - } - else - { + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); + } else { currMB->is_intra_block = TRUE; currMB->mb_type = I16MB; - currMB->cbp = ICBPTAB[((mbmode-7))>>2]; - currMB->i16mode = ((mbmode-7)) & 0x03; + currMB->cbp = ICBPTAB[((mbmode - 7)) >> 2]; + currMB->i16mode = ((mbmode - 7)) & 0x03; memset(currMB->b8mode, 0, 4 * sizeof(signed char)); - memset(currMB->b8pdir,-1, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); } } @@ -587,36 +612,30 @@ static void interpret_mb_mode_P(Macroblock *currMB) * Interpret the mb mode for I-Frames ************************************************************************ */ -static void interpret_mb_mode_I(Macroblock *currMB) -{ - static const short ICBPTAB[6] = {0,16,32,15,31,47}; - short mbmode = currMB->mb_type; +static void interpret_mb_mode_I(Macroblock *currMB) { + static const short ICBPTAB[6] = {0, 16, 32, 15, 31, 47}; + short mbmode = currMB->mb_type; - if (mbmode == 0) - { + if (mbmode == 0) { currMB->is_intra_block = TRUE; currMB->mb_type = I4MB; - memset(currMB->b8mode,IBLOCK,4 * sizeof(signed char)); - memset(currMB->b8pdir,-1,4 * sizeof(signed char)); - } - else if(mbmode == 25) - { + memset(currMB->b8mode, IBLOCK, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); + } else if (mbmode == 25) { currMB->is_intra_block = TRUE; - currMB->mb_type=IPCM; - currMB->cbp= -1; + currMB->mb_type = IPCM; + currMB->cbp = -1; currMB->i16mode = 0; - memset(currMB->b8mode,0,4 * sizeof(signed char)); - memset(currMB->b8pdir,-1,4 * sizeof(signed char)); - } - else - { + memset(currMB->b8mode, 0, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); + } else { currMB->is_intra_block = TRUE; currMB->mb_type = I16MB; - currMB->cbp= ICBPTAB[(mbmode-1)>>2]; - currMB->i16mode = (mbmode-1) & 0x03; + currMB->cbp = ICBPTAB[(mbmode - 1) >> 2]; + currMB->i16mode = (mbmode - 1) & 0x03; memset(currMB->b8mode, 0, 4 * sizeof(signed char)); - memset(currMB->b8pdir,-1, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); } } @@ -626,80 +645,74 @@ static void interpret_mb_mode_I(Macroblock *currMB) * Interpret the mb mode for B-Frames ************************************************************************ */ -static void interpret_mb_mode_B(Macroblock *currMB) -{ - static const short offset2pdir16x16[12] = {0, 0, 1, 2, 0,0,0,0,0,0,0,0}; - static const short offset2pdir16x8[22][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{1,1},{0,0},{0,1},{0,0},{1,0}, - {0,0},{0,2},{0,0},{1,2},{0,0},{2,0},{0,0},{2,1},{0,0},{2,2},{0,0}}; - static const short offset2pdir8x16[22][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{1,1},{0,0},{0,1},{0,0}, - {1,0},{0,0},{0,2},{0,0},{1,2},{0,0},{2,0},{0,0},{2,1},{0,0},{2,2}}; +static void interpret_mb_mode_B(Macroblock *currMB) { + static const short offset2pdir16x16[12] = {0, 0, 1, 2, 0, 0, + 0, 0, 0, 0, 0, 0}; + static const short offset2pdir16x8[22][2] = { + {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {1, 1}, {0, 0}, + {0, 1}, {0, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 0}, {1, 2}, {0, 0}, + {2, 0}, {0, 0}, {2, 1}, {0, 0}, {2, 2}, {0, 0}}; + static const short offset2pdir8x16[22][2] = { + {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {1, 1}, + {0, 0}, {0, 1}, {0, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 0}, {1, 2}, + {0, 0}, {2, 0}, {0, 0}, {2, 1}, {0, 0}, {2, 2}}; - static const short ICBPTAB[6] = {0,16,32,15,31,47}; + static const short ICBPTAB[6] = {0, 16, 32, 15, 31, 47}; short i, mbmode; - short mbtype = currMB->mb_type; + short mbtype = currMB->mb_type; //--- set mbtype, b8type, and b8pdir --- - if (mbtype == 0) // direct + if (mbtype == 0) // direct { - mbmode=0; - memset(currMB->b8mode,0,4 * sizeof(signed char)); - memset(currMB->b8pdir,2,4 * sizeof(signed char)); - } - else if (mbtype == 23) // intra4x4 + mbmode = 0; + memset(currMB->b8mode, 0, 4 * sizeof(signed char)); + memset(currMB->b8pdir, 2, 4 * sizeof(signed char)); + } else if (mbtype == 23) // intra4x4 { currMB->is_intra_block = TRUE; - mbmode=I4MB; - memset(currMB->b8mode,IBLOCK,4 * sizeof(signed char)); - memset(currMB->b8pdir,-1,4 * sizeof(signed char)); - } - else if ((mbtype > 23) && (mbtype < 48) ) // intra16x16 + mbmode = I4MB; + memset(currMB->b8mode, IBLOCK, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); + } else if ((mbtype > 23) && (mbtype < 48)) // intra16x16 { currMB->is_intra_block = TRUE; - mbmode=I16MB; - memset(currMB->b8mode,0,4 * sizeof(signed char)); - memset(currMB->b8pdir,-1,4 * sizeof(signed char)); + mbmode = I16MB; + memset(currMB->b8mode, 0, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); - currMB->cbp = ICBPTAB[(mbtype-24)>>2]; - currMB->i16mode = (mbtype-24) & 0x03; - } - else if (mbtype == 22) // 8x8(+split) + currMB->cbp = ICBPTAB[(mbtype - 24) >> 2]; + currMB->i16mode = (mbtype - 24) & 0x03; + } else if (mbtype == 22) // 8x8(+split) { - mbmode=P8x8; // b8mode and pdir is transmitted in additional codewords - } - else if (mbtype < 4) // 16x16 + mbmode = P8x8; // b8mode and pdir is transmitted in additional codewords + } else if (mbtype < 4) // 16x16 { - mbmode=1; - memset(currMB->b8mode, 1,4 * sizeof(signed char)); + mbmode = 1; + memset(currMB->b8mode, 1, 4 * sizeof(signed char)); memset(currMB->b8pdir, offset2pdir16x16[mbtype], 4 * sizeof(signed char)); - } - else if(mbtype == 48) - { + } else if (mbtype == 48) { currMB->is_intra_block = TRUE; - mbmode=IPCM; - memset(currMB->b8mode, 0,4 * sizeof(signed char)); - memset(currMB->b8pdir,-1,4 * sizeof(signed char)); + mbmode = IPCM; + memset(currMB->b8mode, 0, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); - currMB->cbp= -1; + currMB->cbp = -1; currMB->i16mode = 0; } else if ((mbtype & 0x01) == 0) // 16x8 { - mbmode=2; - memset(currMB->b8mode, 2,4 * sizeof(signed char)); - for(i=0;i<4;++i) - { - currMB->b8pdir[i] = (signed char) offset2pdir16x8 [mbtype][i>>1]; + mbmode = 2; + memset(currMB->b8mode, 2, 4 * sizeof(signed char)); + for (i = 0; i < 4; ++i) { + currMB->b8pdir[i] = (signed char)offset2pdir16x8[mbtype][i >> 1]; } - } - else - { - mbmode=3; - memset(currMB->b8mode, 3,4 * sizeof(signed char)); - for(i=0;i<4; ++i) - { - currMB->b8pdir[i] = (signed char) offset2pdir8x16 [mbtype][i&0x01]; + } else { + mbmode = 3; + memset(currMB->b8mode, 3, 4 * sizeof(signed char)); + for (i = 0; i < 4; ++i) { + currMB->b8pdir[i] = (signed char)offset2pdir8x16[mbtype][i & 0x01]; } } currMB->mb_type = mbmode; @@ -711,119 +724,114 @@ static void interpret_mb_mode_B(Macroblock *currMB) * Interpret the mb mode for SI-Frames ************************************************************************ */ -static void interpret_mb_mode_SI(Macroblock *currMB) -{ - //VideoParameters *p_Vid = currMB->p_Vid; - const int ICBPTAB[6] = {0,16,32,15,31,47}; - short mbmode = currMB->mb_type; +static void interpret_mb_mode_SI(Macroblock *currMB) { + // VideoParameters *p_Vid = currMB->p_Vid; + const int ICBPTAB[6] = {0, 16, 32, 15, 31, 47}; + short mbmode = currMB->mb_type; - if (mbmode == 0) - { + if (mbmode == 0) { currMB->is_intra_block = TRUE; currMB->mb_type = SI4MB; - memset(currMB->b8mode,IBLOCK,4 * sizeof(signed char)); - memset(currMB->b8pdir,-1,4 * sizeof(signed char)); - currMB->p_Slice->siblock[currMB->mb.y][currMB->mb.x]=1; - } - else if (mbmode == 1) - { + memset(currMB->b8mode, IBLOCK, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); + currMB->p_Slice->siblock[currMB->mb.y][currMB->mb.x] = 1; + } else if (mbmode == 1) { currMB->is_intra_block = TRUE; currMB->mb_type = I4MB; - memset(currMB->b8mode,IBLOCK,4 * sizeof(signed char)); - memset(currMB->b8pdir,-1,4 * sizeof(signed char)); - } - else if(mbmode == 26) - { + memset(currMB->b8mode, IBLOCK, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); + } else if (mbmode == 26) { currMB->is_intra_block = TRUE; - currMB->mb_type=IPCM; - currMB->cbp= -1; + currMB->mb_type = IPCM; + currMB->cbp = -1; currMB->i16mode = 0; - memset(currMB->b8mode,0,4 * sizeof(signed char)); - memset(currMB->b8pdir,-1,4 * sizeof(signed char)); + memset(currMB->b8mode, 0, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); } - else - { + else { currMB->is_intra_block = TRUE; currMB->mb_type = I16MB; - currMB->cbp= ICBPTAB[(mbmode-2)>>2]; - currMB->i16mode = (mbmode-2) & 0x03; - memset(currMB->b8mode,0,4 * sizeof(signed char)); - memset(currMB->b8pdir,-1,4 * sizeof(signed char)); + currMB->cbp = ICBPTAB[(mbmode - 2) >> 2]; + currMB->i16mode = (mbmode - 2) & 0x03; + memset(currMB->b8mode, 0, 4 * sizeof(signed char)); + memset(currMB->b8pdir, -1, 4 * sizeof(signed char)); } } - /*! ************************************************************************ * \brief * Set mode interpretation based on slice type ************************************************************************ */ -void setup_slice_methods(Slice *currSlice) -{ - switch (currSlice->slice_type) - { - case P_SLICE: - currSlice->interpret_mb_mode = interpret_mb_mode_P; +void setup_slice_methods(Slice *currSlice) { + switch (currSlice->slice_type) { + case P_SLICE: + currSlice->interpret_mb_mode = interpret_mb_mode_P; currSlice->read_motion_info_from_NAL = read_motion_info_from_NAL_p_slice; - currSlice->read_one_macroblock = read_one_macroblock_p_slice; - currSlice->decode_one_component = decode_one_component_p_slice; - currSlice->update_direct_mv_info = NULL; + currSlice->read_one_macroblock = read_one_macroblock_p_slice; + currSlice->decode_one_component = decode_one_component_p_slice; + currSlice->update_direct_mv_info = NULL; #if (MVC_EXTENSION_ENABLE) - currSlice->init_lists = currSlice->view_id ? init_lists_p_slice_mvc : init_lists_p_slice; + currSlice->init_lists = + currSlice->view_id ? init_lists_p_slice_mvc : init_lists_p_slice; #else - currSlice->init_lists = init_lists_p_slice; + currSlice->init_lists = init_lists_p_slice; #endif break; case SP_SLICE: - currSlice->interpret_mb_mode = interpret_mb_mode_P; + currSlice->interpret_mb_mode = interpret_mb_mode_P; currSlice->read_motion_info_from_NAL = read_motion_info_from_NAL_p_slice; - currSlice->read_one_macroblock = read_one_macroblock_p_slice; - currSlice->decode_one_component = decode_one_component_sp_slice; - currSlice->update_direct_mv_info = NULL; + currSlice->read_one_macroblock = read_one_macroblock_p_slice; + currSlice->decode_one_component = decode_one_component_sp_slice; + currSlice->update_direct_mv_info = NULL; #if (MVC_EXTENSION_ENABLE) - currSlice->init_lists = currSlice->view_id ? init_lists_p_slice_mvc : init_lists_p_slice; + currSlice->init_lists = + currSlice->view_id ? init_lists_p_slice_mvc : init_lists_p_slice; #else - currSlice->init_lists = init_lists_p_slice; + currSlice->init_lists = init_lists_p_slice; #endif break; case B_SLICE: - currSlice->interpret_mb_mode = interpret_mb_mode_B; + currSlice->interpret_mb_mode = interpret_mb_mode_B; currSlice->read_motion_info_from_NAL = read_motion_info_from_NAL_b_slice; - currSlice->read_one_macroblock = read_one_macroblock_b_slice; - currSlice->decode_one_component = decode_one_component_b_slice; + currSlice->read_one_macroblock = read_one_macroblock_b_slice; + currSlice->decode_one_component = decode_one_component_b_slice; update_direct_types(currSlice); #if (MVC_EXTENSION_ENABLE) - currSlice->init_lists = currSlice->view_id ? init_lists_b_slice_mvc : init_lists_b_slice; + currSlice->init_lists = + currSlice->view_id ? init_lists_b_slice_mvc : init_lists_b_slice; #else - currSlice->init_lists = init_lists_b_slice; + currSlice->init_lists = init_lists_b_slice; #endif break; - case I_SLICE: - currSlice->interpret_mb_mode = interpret_mb_mode_I; + case I_SLICE: + currSlice->interpret_mb_mode = interpret_mb_mode_I; currSlice->read_motion_info_from_NAL = NULL; - currSlice->read_one_macroblock = read_one_macroblock_i_slice; - currSlice->decode_one_component = decode_one_component_i_slice; - currSlice->update_direct_mv_info = NULL; + currSlice->read_one_macroblock = read_one_macroblock_i_slice; + currSlice->decode_one_component = decode_one_component_i_slice; + currSlice->update_direct_mv_info = NULL; #if (MVC_EXTENSION_ENABLE) - currSlice->init_lists = currSlice->view_id ? init_lists_i_slice_mvc : init_lists_i_slice; + currSlice->init_lists = + currSlice->view_id ? init_lists_i_slice_mvc : init_lists_i_slice; #else - currSlice->init_lists = init_lists_i_slice; + currSlice->init_lists = init_lists_i_slice; #endif break; - case SI_SLICE: - currSlice->interpret_mb_mode = interpret_mb_mode_SI; + case SI_SLICE: + currSlice->interpret_mb_mode = interpret_mb_mode_SI; currSlice->read_motion_info_from_NAL = NULL; - currSlice->read_one_macroblock = read_one_macroblock_i_slice; - currSlice->decode_one_component = decode_one_component_i_slice; - currSlice->update_direct_mv_info = NULL; + currSlice->read_one_macroblock = read_one_macroblock_i_slice; + currSlice->decode_one_component = decode_one_component_i_slice; + currSlice->update_direct_mv_info = NULL; #if (MVC_EXTENSION_ENABLE) - currSlice->init_lists = currSlice->view_id ? init_lists_i_slice_mvc : init_lists_i_slice; + currSlice->init_lists = + currSlice->view_id ? init_lists_i_slice_mvc : init_lists_i_slice; #else - currSlice->init_lists = init_lists_i_slice; + currSlice->init_lists = init_lists_i_slice; #endif break; default: @@ -831,34 +839,41 @@ void setup_slice_methods(Slice *currSlice) break; } - if (currSlice->mb_aff_frame_flag) - { - currSlice->intrapred_chroma = intrapred_chroma_mbaff; - } - else - currSlice->intrapred_chroma = intrapred_chroma; + if (currSlice->mb_aff_frame_flag) { + currSlice->intrapred_chroma = intrapred_chroma_mbaff; + } else + currSlice->intrapred_chroma = intrapred_chroma; - switch(currSlice->p_Vid->active_pps->entropy_coding_mode_flag) - { + switch (currSlice->p_Vid->active_pps->entropy_coding_mode_flag) { case CABAC: - if ( currSlice->p_Vid->active_sps->chroma_format_idc==YUV444 && (currSlice->p_Vid->separate_colour_plane_flag == 0) ) - currSlice->read_CBP_and_coeffs_from_NAL = read_CBP_and_coeffs_from_NAL_CABAC_444; + if (currSlice->p_Vid->active_sps->chroma_format_idc == YUV444 && + (currSlice->p_Vid->separate_colour_plane_flag == 0)) + currSlice->read_CBP_and_coeffs_from_NAL = + read_CBP_and_coeffs_from_NAL_CABAC_444; else if (currSlice->p_Vid->active_sps->chroma_format_idc == YUV422) - currSlice->read_CBP_and_coeffs_from_NAL = read_CBP_and_coeffs_from_NAL_CABAC_422; + currSlice->read_CBP_and_coeffs_from_NAL = + read_CBP_and_coeffs_from_NAL_CABAC_422; else if (currSlice->p_Vid->active_sps->chroma_format_idc == YUV400) - currSlice->read_CBP_and_coeffs_from_NAL = read_CBP_and_coeffs_from_NAL_CABAC_400; + currSlice->read_CBP_and_coeffs_from_NAL = + read_CBP_and_coeffs_from_NAL_CABAC_400; else - currSlice->read_CBP_and_coeffs_from_NAL = read_CBP_and_coeffs_from_NAL_CABAC_420; + currSlice->read_CBP_and_coeffs_from_NAL = + read_CBP_and_coeffs_from_NAL_CABAC_420; break; case CAVLC: - if ( currSlice->p_Vid->active_sps->chroma_format_idc==YUV444 && (currSlice->p_Vid->separate_colour_plane_flag == 0) ) - currSlice->read_CBP_and_coeffs_from_NAL = read_CBP_and_coeffs_from_NAL_CAVLC_444; + if (currSlice->p_Vid->active_sps->chroma_format_idc == YUV444 && + (currSlice->p_Vid->separate_colour_plane_flag == 0)) + currSlice->read_CBP_and_coeffs_from_NAL = + read_CBP_and_coeffs_from_NAL_CAVLC_444; else if (currSlice->p_Vid->active_sps->chroma_format_idc == YUV422) - currSlice->read_CBP_and_coeffs_from_NAL = read_CBP_and_coeffs_from_NAL_CAVLC_422; + currSlice->read_CBP_and_coeffs_from_NAL = + read_CBP_and_coeffs_from_NAL_CAVLC_422; else if (currSlice->p_Vid->active_sps->chroma_format_idc == YUV400) - currSlice->read_CBP_and_coeffs_from_NAL = read_CBP_and_coeffs_from_NAL_CAVLC_400; + currSlice->read_CBP_and_coeffs_from_NAL = + read_CBP_and_coeffs_from_NAL_CAVLC_400; else - currSlice->read_CBP_and_coeffs_from_NAL = read_CBP_and_coeffs_from_NAL_CAVLC_420; + currSlice->read_CBP_and_coeffs_from_NAL = + read_CBP_and_coeffs_from_NAL_CAVLC_420; break; default: printf("Unsupported entropy coding mode\n"); @@ -872,15 +887,15 @@ void setup_slice_methods(Slice *currSlice) * init macroblock I and P frames ************************************************************************ */ -static void init_macroblock(Macroblock *currMB) -{ - //VideoParameters *p_Vid = currMB->p_Vid; +static void init_macroblock(Macroblock *currMB) { + // VideoParameters *p_Vid = currMB->p_Vid; int j, i; - PicMotionParams **mv_info = &currMB->p_Slice->dec_picture->mv_info[currMB->block_y]; //&p_Vid->dec_picture->mv_info[currMB->block_y]; + PicMotionParams **mv_info = + &currMB->p_Slice->dec_picture->mv_info + [currMB->block_y]; //&p_Vid->dec_picture->mv_info[currMB->block_y]; // reset vectors and pred. modes - for(j = 0; j < BLOCK_SIZE; ++j) - { + for (j = 0; j < BLOCK_SIZE; ++j) { i = currMB->block_x; reset_mv_info(*mv_info + (i++)); reset_mv_info(*mv_info + (i++)); @@ -889,182 +904,161 @@ static void init_macroblock(Macroblock *currMB) } } - /*! ************************************************************************ * \brief * Sets mode for 8x8 block ************************************************************************ */ -void SetB8Mode (Macroblock* currMB, int value, int i) -{ - Slice* currSlice = currMB->p_Slice; - static const signed char p_v2b8 [ 5] = {4, 5, 6, 7, IBLOCK}; - static const signed char p_v2pd [ 5] = {0, 0, 0, 0, -1}; - static const signed char b_v2b8 [14] = {0, 4, 4, 4, 5, 6, 5, 6, 5, 6, 7, 7, 7, IBLOCK}; - static const signed char b_v2pd [14] = {2, 0, 1, 2, 0, 0, 1, 1, 2, 2, 0, 1, 2, -1}; +void SetB8Mode(Macroblock *currMB, int value, int i) { + Slice *currSlice = currMB->p_Slice; + static const signed char p_v2b8[5] = {4, 5, 6, 7, IBLOCK}; + static const signed char p_v2pd[5] = {0, 0, 0, 0, -1}; + static const signed char b_v2b8[14] = {0, 4, 4, 4, 5, 6, 5, + 6, 5, 6, 7, 7, 7, IBLOCK}; + static const signed char b_v2pd[14] = {2, 0, 1, 2, 0, 0, 1, + 1, 2, 2, 0, 1, 2, -1}; - if (currSlice->slice_type==B_SLICE) - { + if (currSlice->slice_type == B_SLICE) { currMB->b8mode[i] = b_v2b8[value]; currMB->b8pdir[i] = b_v2pd[value]; - } - else - { + } else { currMB->b8mode[i] = p_v2b8[value]; currMB->b8pdir[i] = p_v2pd[value]; } } - -void reset_coeffs(Slice *currSlice) -{ +void reset_coeffs(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; // CAVLC if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC) - fast_memset(p_Vid->nz_coeff[currSlice->current_mb_nr][0][0], 0, 3 * BLOCK_PIXELS * sizeof(byte)); + fast_memset(p_Vid->nz_coeff[currSlice->current_mb_nr][0][0], 0, + 3 * BLOCK_PIXELS * sizeof(byte)); } -void field_flag_inference(Macroblock *currMB) -{ +void field_flag_inference(Macroblock *currMB) { VideoParameters *p_Vid = currMB->p_Vid; - if (currMB->mbAvailA) - { + if (currMB->mbAvailA) { currMB->mb_field = p_Vid->mb_data[currMB->mbAddrA].mb_field; - } - else - { + } else { // check top macroblock pair - currMB->mb_field = currMB->mbAvailB ? p_Vid->mb_data[currMB->mbAddrB].mb_field : FALSE; + currMB->mb_field = + currMB->mbAvailB ? p_Vid->mb_data[currMB->mbAddrB].mb_field : FALSE; } } - -void skip_macroblock(Macroblock *currMB) -{ +void skip_macroblock(Macroblock *currMB) { MotionVector pred_mv; int zeroMotionAbove; int zeroMotionLeft; - PixelPos mb[4]; // neighbor blocks - int i, j; - int a_mv_y = 0; - int a_ref_idx = 0; - int b_mv_y = 0; - int b_ref_idx = 0; - int img_block_y = currMB->block_y; + PixelPos mb[4]; // neighbor blocks + int i, j; + int a_mv_y = 0; + int a_ref_idx = 0; + int b_mv_y = 0; + int b_ref_idx = 0; + int img_block_y = currMB->block_y; VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; - int list_offset = currMB->list_offset; //((currSlice->mb_aff_frame_flag) && (currMB->mb_field)) ? (currMB->mbAddrX & 0x01) ? 4 : 2 : 0; + int list_offset = currMB->list_offset; //((currSlice->mb_aff_frame_flag) && + //(currMB->mb_field)) ? + //(currMB->mbAddrX & 0x01) ? 4 : 2 : 0; StorablePicture *dec_picture = currSlice->dec_picture; MotionVector *a_mv = NULL; MotionVector *b_mv = NULL; get_neighbors(currMB, mb, 0, 0, MB_BLOCK_SIZE); - if (mb[0].available) - { - a_mv = &dec_picture->mv_info[mb[0].pos_y][mb[0].pos_x].mv[LIST_0]; - a_mv_y = a_mv->mv_y; + if (mb[0].available) { + a_mv = &dec_picture->mv_info[mb[0].pos_y][mb[0].pos_x].mv[LIST_0]; + a_mv_y = a_mv->mv_y; a_ref_idx = dec_picture->mv_info[mb[0].pos_y][mb[0].pos_x].ref_idx[LIST_0]; - if (currMB->mb_field && !p_Vid->mb_data[mb[0].mb_addr].mb_field) - { - a_mv_y /=2; - a_ref_idx *=2; + if (currMB->mb_field && !p_Vid->mb_data[mb[0].mb_addr].mb_field) { + a_mv_y /= 2; + a_ref_idx *= 2; } - if (!currMB->mb_field && p_Vid->mb_data[mb[0].mb_addr].mb_field) - { - a_mv_y *=2; - a_ref_idx >>=1; + if (!currMB->mb_field && p_Vid->mb_data[mb[0].mb_addr].mb_field) { + a_mv_y *= 2; + a_ref_idx >>= 1; } } - if (mb[1].available) - { - b_mv = &dec_picture->mv_info[mb[1].pos_y][mb[1].pos_x].mv[LIST_0]; - b_mv_y = b_mv->mv_y; + if (mb[1].available) { + b_mv = &dec_picture->mv_info[mb[1].pos_y][mb[1].pos_x].mv[LIST_0]; + b_mv_y = b_mv->mv_y; b_ref_idx = dec_picture->mv_info[mb[1].pos_y][mb[1].pos_x].ref_idx[LIST_0]; - if (currMB->mb_field && !p_Vid->mb_data[mb[1].mb_addr].mb_field) - { - b_mv_y /=2; - b_ref_idx *=2; + if (currMB->mb_field && !p_Vid->mb_data[mb[1].mb_addr].mb_field) { + b_mv_y /= 2; + b_ref_idx *= 2; } - if (!currMB->mb_field && p_Vid->mb_data[mb[1].mb_addr].mb_field) - { - b_mv_y *=2; - b_ref_idx >>=1; + if (!currMB->mb_field && p_Vid->mb_data[mb[1].mb_addr].mb_field) { + b_mv_y *= 2; + b_ref_idx >>= 1; } } - zeroMotionLeft = !mb[0].available ? 1 : a_ref_idx==0 && a_mv->mv_x == 0 && a_mv_y==0 ? 1 : 0; - zeroMotionAbove = !mb[1].available ? 1 : b_ref_idx==0 && b_mv->mv_x == 0 && b_mv_y==0 ? 1 : 0; + zeroMotionLeft = !mb[0].available ? 1 + : a_ref_idx == 0 && a_mv->mv_x == 0 && a_mv_y == 0 ? 1 + : 0; + zeroMotionAbove = !mb[1].available ? 1 + : b_ref_idx == 0 && b_mv->mv_x == 0 && b_mv_y == 0 ? 1 + : 0; currMB->cbp = 0; reset_coeffs(currSlice); - if (zeroMotionAbove || zeroMotionLeft) - { + if (zeroMotionAbove || zeroMotionLeft) { StorablePicture *cur_pic = currSlice->listX[LIST_0 + list_offset][0]; PicMotionParams *mv_info = NULL; - for(j = img_block_y; j < img_block_y + BLOCK_SIZE; ++j) - { - for(i = currMB->block_x; i < currMB->block_x + BLOCK_SIZE; ++i) - { + for (j = img_block_y; j < img_block_y + BLOCK_SIZE; ++j) { + for (i = currMB->block_x; i < currMB->block_x + BLOCK_SIZE; ++i) { mv_info = &dec_picture->mv_info[j][i]; mv_info->ref_pic[LIST_0] = cur_pic; - mv_info->mv [LIST_0] = zero_mv; + mv_info->mv[LIST_0] = zero_mv; mv_info->ref_idx[LIST_0] = 0; } } - } - else - { + } else { PicMotionParams *mv_info = NULL; StorablePicture *cur_pic = currSlice->listX[LIST_0 + list_offset][0]; - currMB->GetMVPredictor (currMB, mb, &pred_mv, 0, dec_picture->mv_info, LIST_0, 0, 0, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + currMB->GetMVPredictor(currMB, mb, &pred_mv, 0, dec_picture->mv_info, + LIST_0, 0, 0, MB_BLOCK_SIZE, MB_BLOCK_SIZE); // Set first block line (position img_block_y) - for(j = img_block_y; j < img_block_y + BLOCK_SIZE; ++j) - { - for(i = currMB->block_x; i < currMB->block_x + BLOCK_SIZE; ++i) - { + for (j = img_block_y; j < img_block_y + BLOCK_SIZE; ++j) { + for (i = currMB->block_x; i < currMB->block_x + BLOCK_SIZE; ++i) { mv_info = &dec_picture->mv_info[j][i]; mv_info->ref_pic[LIST_0] = cur_pic; - mv_info->mv [LIST_0] = pred_mv; + mv_info->mv[LIST_0] = pred_mv; mv_info->ref_idx[LIST_0] = 0; } } } } -static void concealIPCMcoeffs(Macroblock *currMB) -{ +static void concealIPCMcoeffs(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; int i, j, k; - for(i=0;icof[0][i][j] = p_Vid->dc_pred_value_comp[0]; - //p_Vid->fcf[0][i][j] = p_Vid->dc_pred_value_comp[0]; + // p_Vid->fcf[0][i][j] = p_Vid->dc_pred_value_comp[0]; } } - if ((dec_picture->chroma_format_idc != YUV400) && (p_Vid->separate_colour_plane_flag == 0)) - { - for (k = 0; k < 2; ++k) - { - for(i=0;imb_cr_size_y;++i) - { - for(j=0;jmb_cr_size_x;++j) - { + if ((dec_picture->chroma_format_idc != YUV400) && + (p_Vid->separate_colour_plane_flag == 0)) { + for (k = 0; k < 2; ++k) { + for (i = 0; i < p_Vid->mb_cr_size_y; ++i) { + for (j = 0; j < p_Vid->mb_cr_size_x; ++j) { currSlice->cof[k][i][j] = p_Vid->dc_pred_value_comp[k]; - //p_Vid->fcf[k][i][j] = p_Vid->dc_pred_value_comp[k]; + // p_Vid->fcf[k][i][j] = p_Vid->dc_pred_value_comp[k]; } } } @@ -1077,48 +1071,47 @@ static void concealIPCMcoeffs(Macroblock *currMB) * Get the syntax elements from the NAL ************************************************************************ */ -static void read_one_macroblock_i_slice(Macroblock *currMB) -{ +static void read_one_macroblock_i_slice(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; SyntaxElement currSE; - int mb_nr = currMB->mbAddrX; + int mb_nr = currMB->mbAddrX; DataPartition *dP; const byte *partMap = assignSE2partition[currSlice->dp_mode]; - StorablePicture *dec_picture = currSlice->dec_picture; + StorablePicture *dec_picture = currSlice->dec_picture; PicMotionParamsOld *motion = &dec_picture->motion; - currMB->mb_field = ((mb_nr&0x01) == 0)? FALSE : currSlice->mb_data[mb_nr-1].mb_field; + currMB->mb_field = + ((mb_nr & 0x01) == 0) ? FALSE : currSlice->mb_data[mb_nr - 1].mb_field; update_qp(currMB, currSlice->qp); currSE.type = SE_MBTYPE; - // read MB mode ***************************************************************** + // read MB mode + // ***************************************************************** dP = &(currSlice->partArr[partMap[SE_MBTYPE]]); - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) currSE.mapping = linfo_ue; // read MB aff - if (currSlice->mb_aff_frame_flag && (mb_nr&0x01)==0) - { + if (currSlice->mb_aff_frame_flag && (mb_nr & 0x01) == 0) { TRACE_STRING("mb_field_decoding_flag"); - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) - { - currSE.len = (int64) 1; + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) { + currSE.len = (int64)1; readSyntaxElement_FLC(&currSE, dP->bitstream); - } - else - { + } else { currSE.reading = readFieldModeInfo_CABAC; dP->readSyntaxElement(currMB, &currSE, dP); } - currMB->mb_field = (Boolean) currSE.value1; + currMB->mb_field = (Boolean)currSE.value1; } - if(p_Vid->active_pps->entropy_coding_mode_flag == CABAC) + if (p_Vid->active_pps->entropy_coding_mode_flag == CABAC) CheckAvailabilityOfNeighborsCABAC(currMB); // read MB type @@ -1126,79 +1119,72 @@ static void read_one_macroblock_i_slice(Macroblock *currMB) currSE.reading = readMB_typeInfo_CABAC_i_slice; dP->readSyntaxElement(currMB, &currSE, dP); - currMB->mb_type = (short) currSE.value1; - if(!dP->bitstream->ei_flag) + currMB->mb_type = (short)currSE.value1; + if (!dP->bitstream->ei_flag) currMB->ei_flag = 0; - motion->mb_field[mb_nr] = (byte) currMB->mb_field; + motion->mb_field[mb_nr] = (byte)currMB->mb_field; - currMB->block_y_aff = ((currSlice->mb_aff_frame_flag) && (currMB->mb_field)) ? (mb_nr&0x01) ? (currMB->block_y - 4)>>1 : currMB->block_y >> 1 : currMB->block_y; + currMB->block_y_aff = + ((currSlice->mb_aff_frame_flag) && (currMB->mb_field)) + ? (mb_nr & 0x01) ? (currMB->block_y - 4) >> 1 : currMB->block_y >> 1 + : currMB->block_y; currSlice->siblock[currMB->mb.y][currMB->mb.x] = 0; currSlice->interpret_mb_mode(currMB); - //init NoMbPartLessThan8x8Flag + // init NoMbPartLessThan8x8Flag currMB->NoMbPartLessThan8x8Flag = TRUE; //============= Transform Size Flag for INTRA MBs ============= //------------------------------------------------------------- - //transform size flag for INTRA_4x4 and INTRA_8x8 modes - if (currMB->mb_type == I4MB && currSlice->Transform8x8Mode) - { - currSE.type = SE_HEADER; + // transform size flag for INTRA_4x4 and INTRA_8x8 modes + if (currMB->mb_type == I4MB && currSlice->Transform8x8Mode) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); // read CAVLC transform_size_8x8_flag - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) - { - currSE.len = (int64) 1; + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) { + currSE.len = (int64)1; readSyntaxElement_FLC(&currSE, dP->bitstream); - } - else - { + } else { dP->readSyntaxElement(currMB, &currSE, dP); } - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; - if (currMB->luma_transform_size_8x8_flag) - { + if (currMB->luma_transform_size_8x8_flag) { currMB->mb_type = I8MB; memset(&currMB->b8mode, I8MB, 4 * sizeof(signed char)); memset(&currMB->b8pdir, -1, 4 * sizeof(signed char)); } - } - else - { + } else { currMB->luma_transform_size_8x8_flag = FALSE; } //--- init macroblock data --- init_macroblock(currMB); - if(currMB->mb_type != IPCM) - { - // intra prediction modes for a macroblock 4x4 ********************************************** + if (currMB->mb_type != IPCM) { + // intra prediction modes for a macroblock 4x4 + // ********************************************** read_ipred_modes(currMB); - // read CBP and Coeffs *************************************************************** - currSlice->read_CBP_and_coeffs_from_NAL (currMB); - } - else - { - //read pcm_alignment_zero_bit and pcm_byte[i] + // read CBP and Coeffs + // *************************************************************** + currSlice->read_CBP_and_coeffs_from_NAL(currMB); + } else { + // read pcm_alignment_zero_bit and pcm_byte[i] - // here dP is assigned with the same dP as SE_MBTYPE, because IPCM syntax is in the - // same category as MBTYPE - if ( currSlice->dp_mode && currSlice->dpB_NotPresent ) - { + // here dP is assigned with the same dP as SE_MBTYPE, because IPCM syntax is + // in the same category as MBTYPE + if (currSlice->dp_mode && currSlice->dpB_NotPresent) { concealIPCMcoeffs(currMB); - } - else - { + } else { dP = &(currSlice->partArr[partMap[SE_LUM_DC_INTRA]]); read_IPCM_coeffs_from_NAL(currSlice, dP); } @@ -1213,50 +1199,48 @@ static void read_one_macroblock_i_slice(Macroblock *currMB) * Get the syntax elements from the NAL ************************************************************************ */ -static void read_one_macroblock_p_slice(Macroblock *currMB) -{ +static void read_one_macroblock_p_slice(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int i; SyntaxElement currSE; - int mb_nr = currMB->mbAddrX; + int mb_nr = currMB->mbAddrX; DataPartition *dP; const byte *partMap = assignSE2partition[currSlice->dp_mode]; Macroblock *topMB = NULL; - int prevMbSkipped = 0; - int check_bottom, read_bottom, read_top; + int prevMbSkipped = 0; + int check_bottom, read_bottom, read_top; StorablePicture *dec_picture = currSlice->dec_picture; PicMotionParamsOld *motion = &dec_picture->motion; - if (currSlice->mb_aff_frame_flag) - { - if (mb_nr&0x01) - { - topMB= &p_Vid->mb_data[mb_nr-1]; + if (currSlice->mb_aff_frame_flag) { + if (mb_nr & 0x01) { + topMB = &p_Vid->mb_data[mb_nr - 1]; prevMbSkipped = (topMB->mb_type == 0); - } - else + } else prevMbSkipped = 0; } - currMB->mb_field = ((mb_nr&0x01) == 0)? FALSE : p_Vid->mb_data[mb_nr-1].mb_field; + currMB->mb_field = + ((mb_nr & 0x01) == 0) ? FALSE : p_Vid->mb_data[mb_nr - 1].mb_field; update_qp(currMB, currSlice->qp); currSE.type = SE_MBTYPE; - // read MB mode ***************************************************************** + // read MB mode + // ***************************************************************** dP = &(currSlice->partArr[partMap[SE_MBTYPE]]); - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) currSE.mapping = linfo_ue; - if (p_Vid->active_pps->entropy_coding_mode_flag == CABAC) - { + if (p_Vid->active_pps->entropy_coding_mode_flag == CABAC) { // read MB skip_flag - if (currSlice->mb_aff_frame_flag && ((mb_nr&0x01) == 0||prevMbSkipped)) + if (currSlice->mb_aff_frame_flag && ((mb_nr & 0x01) == 0 || prevMbSkipped)) field_flag_inference(currMB); CheckAvailabilityOfNeighborsCABAC(currMB); @@ -1264,255 +1248,225 @@ static void read_one_macroblock_p_slice(Macroblock *currMB) currSE.reading = read_skip_flag_CABAC_p_slice; dP->readSyntaxElement(currMB, &currSE, dP); - currMB->mb_type = (short) currSE.value1; - currMB->skip_flag = (signed char) (!(currSE.value1)); + currMB->mb_type = (short)currSE.value1; + currMB->skip_flag = (signed char)(!(currSE.value1)); if (!dP->bitstream->ei_flag) currMB->ei_flag = 0; // read MB AFF - if (currSlice->mb_aff_frame_flag) - { - check_bottom=read_bottom=read_top=0; - if ((mb_nr&0x01)==0) - { - check_bottom = currMB->skip_flag; + if (currSlice->mb_aff_frame_flag) { + check_bottom = read_bottom = read_top = 0; + if ((mb_nr & 0x01) == 0) { + check_bottom = currMB->skip_flag; read_top = !check_bottom; - } - else - { + } else { read_bottom = (topMB->skip_flag && (!currMB->skip_flag)); } - if (read_bottom || read_top) - { + if (read_bottom || read_top) { TRACE_STRING("mb_field_decoding_flag"); currSE.reading = readFieldModeInfo_CABAC; dP->readSyntaxElement(currMB, &currSE, dP); - currMB->mb_field = (Boolean) currSE.value1; + currMB->mb_field = (Boolean)currSE.value1; } if (check_bottom) check_next_mb_and_get_field_mode_CABAC_p_slice(currSlice, &currSE, dP); - //update the list offset; - currMB->list_offset = (currMB->mb_field)? ((mb_nr&0x01)? 4: 2): 0; + // update the list offset; + currMB->list_offset = (currMB->mb_field) ? ((mb_nr & 0x01) ? 4 : 2) : 0; - //if (currMB->mb_type != 0 ) + // if (currMB->mb_type != 0 ) CheckAvailabilityOfNeighborsCABAC(currMB); } - + // read MB type - if (currMB->mb_type != 0 ) - { + if (currMB->mb_type != 0) { currSE.reading = readMB_typeInfo_CABAC_p_slice; TRACE_STRING("mb_type"); dP->readSyntaxElement(currMB, &currSE, dP); - currMB->mb_type = (short) currSE.value1; - if(!dP->bitstream->ei_flag) + currMB->mb_type = (short)currSE.value1; + if (!dP->bitstream->ei_flag) currMB->ei_flag = 0; } } // VLC Non-Intra - else - { - if(currSlice->cod_counter == -1) - { + else { + if (currSlice->cod_counter == -1) { TRACE_STRING("mb_skip_run"); dP->readSyntaxElement(currMB, &currSE, dP); currSlice->cod_counter = currSE.value1; } - if (currSlice->cod_counter==0) - { + if (currSlice->cod_counter == 0) { // read MB aff - if ((currSlice->mb_aff_frame_flag) && (((mb_nr&0x01)==0) || ((mb_nr&0x01) && prevMbSkipped))) - { + if ((currSlice->mb_aff_frame_flag) && + (((mb_nr & 0x01) == 0) || ((mb_nr & 0x01) && prevMbSkipped))) { TRACE_STRING("mb_field_decoding_flag"); - currSE.len = (int64) 1; + currSE.len = (int64)1; readSyntaxElement_FLC(&currSE, dP->bitstream); - currMB->mb_field = (Boolean) currSE.value1; + currMB->mb_field = (Boolean)currSE.value1; } // read MB type TRACE_STRING("mb_type"); dP->readSyntaxElement(currMB, &currSE, dP); - if(currSlice->slice_type == P_SLICE || currSlice->slice_type == SP_SLICE) + if (currSlice->slice_type == P_SLICE || currSlice->slice_type == SP_SLICE) ++(currSE.value1); - currMB->mb_type = (short) currSE.value1; - if(!dP->bitstream->ei_flag) + currMB->mb_type = (short)currSE.value1; + if (!dP->bitstream->ei_flag) currMB->ei_flag = 0; currSlice->cod_counter--; currMB->skip_flag = 0; - } - else - { + } else { currSlice->cod_counter--; currMB->mb_type = 0; currMB->ei_flag = 0; currMB->skip_flag = 1; // read field flag of bottom block - if(currSlice->mb_aff_frame_flag) - { - if(currSlice->cod_counter == 0 && ((mb_nr&0x01) == 0)) - { + if (currSlice->mb_aff_frame_flag) { + if (currSlice->cod_counter == 0 && ((mb_nr & 0x01) == 0)) { TRACE_STRING("mb_field_decoding_flag (of coded bottom mb)"); - currSE.len = (int64) 1; + currSE.len = (int64)1; readSyntaxElement_FLC(&currSE, dP->bitstream); dP->bitstream->frame_bitoffset--; TRACE_DECBITS(1); - currMB->mb_field = (Boolean) currSE.value1; - } - else if (currSlice->cod_counter > 0 && ((mb_nr & 0x01) == 0)) - { + currMB->mb_field = (Boolean)currSE.value1; + } else if (currSlice->cod_counter > 0 && ((mb_nr & 0x01) == 0)) { // check left macroblock pair first - if (mb_is_available(mb_nr - 2, currMB) && ((mb_nr % (p_Vid->PicWidthInMbs * 2))!=0)) - { - currMB->mb_field = p_Vid->mb_data[mb_nr-2].mb_field; - } - else - { + if (mb_is_available(mb_nr - 2, currMB) && + ((mb_nr % (p_Vid->PicWidthInMbs * 2)) != 0)) { + currMB->mb_field = p_Vid->mb_data[mb_nr - 2].mb_field; + } else { // check top macroblock pair - if (mb_is_available(mb_nr - 2*p_Vid->PicWidthInMbs, currMB)) - { - currMB->mb_field = p_Vid->mb_data[mb_nr-2*p_Vid->PicWidthInMbs].mb_field; - } - else + if (mb_is_available(mb_nr - 2 * p_Vid->PicWidthInMbs, currMB)) { + currMB->mb_field = + p_Vid->mb_data[mb_nr - 2 * p_Vid->PicWidthInMbs].mb_field; + } else currMB->mb_field = FALSE; } } } } - //update the list offset; - currMB->list_offset = (currMB->mb_field)? ((mb_nr&0x01)? 4: 2): 0; - + // update the list offset; + currMB->list_offset = (currMB->mb_field) ? ((mb_nr & 0x01) ? 4 : 2) : 0; } - motion->mb_field[mb_nr] = (byte) currMB->mb_field; + motion->mb_field[mb_nr] = (byte)currMB->mb_field; - currMB->block_y_aff = (currMB->mb_field) ? (mb_nr&0x01) ? (currMB->block_y - 4)>>1 : currMB->block_y >> 1 : currMB->block_y; + currMB->block_y_aff = + (currMB->mb_field) + ? (mb_nr & 0x01) ? (currMB->block_y - 4) >> 1 : currMB->block_y >> 1 + : currMB->block_y; currSlice->siblock[currMB->mb.y][currMB->mb.x] = 0; currSlice->interpret_mb_mode(currMB); - if(currSlice->mb_aff_frame_flag) - { - if(currMB->mb_field) - { - currSlice->num_ref_idx_active[LIST_0] <<=1; - currSlice->num_ref_idx_active[LIST_1] <<=1; + if (currSlice->mb_aff_frame_flag) { + if (currMB->mb_field) { + currSlice->num_ref_idx_active[LIST_0] <<= 1; + currSlice->num_ref_idx_active[LIST_1] <<= 1; } } - //init NoMbPartLessThan8x8Flag + // init NoMbPartLessThan8x8Flag currMB->NoMbPartLessThan8x8Flag = TRUE; - //====== READ 8x8 SUB-PARTITION MODES (modes of 8x8 blocks) and Intra VBST block modes ====== - if (currMB->mb_type == P8x8) - { + //====== READ 8x8 SUB-PARTITION MODES (modes of 8x8 blocks) and Intra VBST + //block modes ====== + if (currMB->mb_type == P8x8) { currSE.type = SE_MBTYPE; dP = &(currSlice->partArr[partMap[SE_MBTYPE]]); - if (p_Vid->active_pps->entropy_coding_mode_flag ==CAVLC || dP->bitstream->ei_flag) + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) currSE.mapping = linfo_ue; else currSE.reading = readB8_typeInfo_CABAC_p_slice; - for (i = 0; i < 4; ++i) - { + for (i = 0; i < 4; ++i) { TRACE_STRING("sub_mb_type"); - dP->readSyntaxElement (currMB, &currSE, dP); - SetB8Mode (currMB, currSE.value1, i); + dP->readSyntaxElement(currMB, &currSE, dP); + SetB8Mode(currMB, currSE.value1, i); - //set NoMbPartLessThan8x8Flag for P8x8 mode - currMB->NoMbPartLessThan8x8Flag &= (currMB->b8mode[i]==0 && p_Vid->active_sps->direct_8x8_inference_flag) || - (currMB->b8mode[i]==4); + // set NoMbPartLessThan8x8Flag for P8x8 mode + currMB->NoMbPartLessThan8x8Flag &= + (currMB->b8mode[i] == 0 && + p_Vid->active_sps->direct_8x8_inference_flag) || + (currMB->b8mode[i] == 4); } //--- init macroblock data --- - init_macroblock (currMB); - currSlice->read_motion_info_from_NAL (currMB); + init_macroblock(currMB); + currSlice->read_motion_info_from_NAL(currMB); } //============= Transform Size Flag for INTRA MBs ============= //------------------------------------------------------------- - //transform size flag for INTRA_4x4 and INTRA_8x8 modes - if (currMB->mb_type == I4MB && currSlice->Transform8x8Mode) - { - currSE.type = SE_HEADER; + // transform size flag for INTRA_4x4 and INTRA_8x8 modes + if (currMB->mb_type == I4MB && currSlice->Transform8x8Mode) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); // read CAVLC transform_size_8x8_flag - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) - { - currSE.len = (int64) 1; + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) { + currSE.len = (int64)1; readSyntaxElement_FLC(&currSE, dP->bitstream); - } - else - { + } else { dP->readSyntaxElement(currMB, &currSE, dP); } - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; - if (currMB->luma_transform_size_8x8_flag) - { + if (currMB->luma_transform_size_8x8_flag) { currMB->mb_type = I8MB; memset(&currMB->b8mode, I8MB, 4 * sizeof(signed char)); memset(&currMB->b8pdir, -1, 4 * sizeof(signed char)); } - } - else - { + } else { currMB->luma_transform_size_8x8_flag = FALSE; } - if(p_Vid->active_pps->constrained_intra_pred_flag) - { - if( currMB->is_intra_block == FALSE) - { + if (p_Vid->active_pps->constrained_intra_pred_flag) { + if (currMB->is_intra_block == FALSE) { currSlice->intra_block[mb_nr] = 0; } } - //--- init macroblock data --- if (currMB->mb_type != P8x8) init_macroblock(currMB); - if (currMB->mb_type == 0) - { + if (currMB->mb_type == 0) { skip_macroblock(currMB); - } - else if(currMB->mb_type != IPCM) - { - // intra prediction modes for a macroblock 4x4 ********************************************** + } else if (currMB->mb_type != IPCM) { + // intra prediction modes for a macroblock 4x4 + // ********************************************** if (currMB->is_intra_block == TRUE) read_ipred_modes(currMB); - // read inter frame vector data ********************************************************* - if (currMB->is_intra_block == FALSE && (currMB->mb_type!=0) && (currMB->mb_type != P8x8)) - { - currSlice->read_motion_info_from_NAL (currMB); + // read inter frame vector data + // ********************************************************* + if (currMB->is_intra_block == FALSE && (currMB->mb_type != 0) && + (currMB->mb_type != P8x8)) { + currSlice->read_motion_info_from_NAL(currMB); } - // read CBP and Coeffs *************************************************************** - currSlice->read_CBP_and_coeffs_from_NAL (currMB); - } - else - { - //read pcm_alignment_zero_bit and pcm_byte[i] + // read CBP and Coeffs + // *************************************************************** + currSlice->read_CBP_and_coeffs_from_NAL(currMB); + } else { + // read pcm_alignment_zero_bit and pcm_byte[i] - // here dP is assigned with the same dP as SE_MBTYPE, because IPCM syntax is in the - // same category as MBTYPE - if ( currSlice->dp_mode && currSlice->dpB_NotPresent ) - { + // here dP is assigned with the same dP as SE_MBTYPE, because IPCM syntax is + // in the same category as MBTYPE + if (currSlice->dp_mode && currSlice->dpB_NotPresent) { concealIPCMcoeffs(currMB); - } - else - { + } else { dP = &(currSlice->partArr[partMap[SE_LUM_DC_INTRA]]); read_IPCM_coeffs_from_NAL(currSlice, dP); } @@ -1527,49 +1481,47 @@ static void read_one_macroblock_p_slice(Macroblock *currMB) * Get the syntax elements from the NAL ************************************************************************ */ -static void read_one_macroblock_b_slice(Macroblock *currMB) -{ +static void read_one_macroblock_b_slice(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int i; SyntaxElement currSE; - int mb_nr = currMB->mbAddrX; + int mb_nr = currMB->mbAddrX; DataPartition *dP; const byte *partMap = assignSE2partition[currSlice->dp_mode]; Macroblock *topMB = NULL; - int prevMbSkipped = 0; - int check_bottom, read_bottom, read_top; + int prevMbSkipped = 0; + int check_bottom, read_bottom, read_top; StorablePicture *dec_picture = currSlice->dec_picture; PicMotionParamsOld *motion = &dec_picture->motion; - if (currSlice->mb_aff_frame_flag) - { - if (mb_nr&0x01) - { - topMB= &p_Vid->mb_data[mb_nr-1]; + if (currSlice->mb_aff_frame_flag) { + if (mb_nr & 0x01) { + topMB = &p_Vid->mb_data[mb_nr - 1]; prevMbSkipped = topMB->skip_flag; - } - else + } else prevMbSkipped = 0; } - currMB->mb_field = ((mb_nr&0x01) == 0)? FALSE : p_Vid->mb_data[mb_nr-1].mb_field; + currMB->mb_field = + ((mb_nr & 0x01) == 0) ? FALSE : p_Vid->mb_data[mb_nr - 1].mb_field; update_qp(currMB, currSlice->qp); currSE.type = SE_MBTYPE; - // read MB mode ***************************************************************** + // read MB mode + // ***************************************************************** dP = &(currSlice->partArr[partMap[SE_MBTYPE]]); - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) currSE.mapping = linfo_ue; - if (p_Vid->active_pps->entropy_coding_mode_flag == CABAC) - { + if (p_Vid->active_pps->entropy_coding_mode_flag == CABAC) { // read MB skip_flag - if (currSlice->mb_aff_frame_flag && ((mb_nr&0x01) == 0||prevMbSkipped)) + if (currSlice->mb_aff_frame_flag && ((mb_nr & 0x01) == 0 || prevMbSkipped)) field_flag_inference(currMB); CheckAvailabilityOfNeighborsCABAC(currMB); @@ -1577,8 +1529,8 @@ static void read_one_macroblock_b_slice(Macroblock *currMB) currSE.reading = read_skip_flag_CABAC_b_slice; dP->readSyntaxElement(currMB, &currSE, dP); - currMB->mb_type = (short) currSE.value1; - currMB->skip_flag = (signed char) (!(currSE.value1)); + currMB->mb_type = (short)currSE.value1; + currMB->skip_flag = (signed char)(!(currSE.value1)); currMB->cbp = currSE.value2; @@ -1586,209 +1538,189 @@ static void read_one_macroblock_b_slice(Macroblock *currMB) currMB->ei_flag = 0; if (currSE.value1 == 0 && currSE.value2 == 0) - currSlice->cod_counter=0; + currSlice->cod_counter = 0; // read MB AFF - if (currSlice->mb_aff_frame_flag) - { - check_bottom=read_bottom=read_top=0; - if ((mb_nr & 0x01) == 0) - { - check_bottom = currMB->skip_flag; + if (currSlice->mb_aff_frame_flag) { + check_bottom = read_bottom = read_top = 0; + if ((mb_nr & 0x01) == 0) { + check_bottom = currMB->skip_flag; read_top = !check_bottom; - } - else - { + } else { read_bottom = (topMB->skip_flag && (!currMB->skip_flag)); } - if (read_bottom || read_top) - { + if (read_bottom || read_top) { TRACE_STRING("mb_field_decoding_flag"); currSE.reading = readFieldModeInfo_CABAC; dP->readSyntaxElement(currMB, &currSE, dP); - currMB->mb_field = (Boolean) currSE.value1; + currMB->mb_field = (Boolean)currSE.value1; } if (check_bottom) check_next_mb_and_get_field_mode_CABAC_b_slice(currSlice, &currSE, dP); - //update the list offset; - currMB->list_offset = (currMB->mb_field)? ((mb_nr&0x01)? 4: 2): 0; - //if (currMB->mb_type != 0 ) + // update the list offset; + currMB->list_offset = (currMB->mb_field) ? ((mb_nr & 0x01) ? 4 : 2) : 0; + // if (currMB->mb_type != 0 ) CheckAvailabilityOfNeighborsCABAC(currMB); } // read MB type - if (currMB->mb_type != 0 ) - { + if (currMB->mb_type != 0) { currSE.reading = readMB_typeInfo_CABAC_b_slice; TRACE_STRING("mb_type"); dP->readSyntaxElement(currMB, &currSE, dP); - currMB->mb_type = (short) currSE.value1; - if(!dP->bitstream->ei_flag) + currMB->mb_type = (short)currSE.value1; + if (!dP->bitstream->ei_flag) currMB->ei_flag = 0; } - } - else // VLC Non-Intra + } else // VLC Non-Intra { - if(currSlice->cod_counter == -1) - { + if (currSlice->cod_counter == -1) { TRACE_STRING("mb_skip_run"); dP->readSyntaxElement(currMB, &currSE, dP); currSlice->cod_counter = currSE.value1; } - if (currSlice->cod_counter==0) - { + if (currSlice->cod_counter == 0) { // read MB aff - if ((currSlice->mb_aff_frame_flag) && (((mb_nr&0x01)==0) || ((mb_nr&0x01) && prevMbSkipped))) - { + if ((currSlice->mb_aff_frame_flag) && + (((mb_nr & 0x01) == 0) || ((mb_nr & 0x01) && prevMbSkipped))) { TRACE_STRING("mb_field_decoding_flag"); - currSE.len = (int64) 1; + currSE.len = (int64)1; readSyntaxElement_FLC(&currSE, dP->bitstream); - currMB->mb_field = (Boolean) currSE.value1; + currMB->mb_field = (Boolean)currSE.value1; } // read MB type TRACE_STRING("mb_type"); dP->readSyntaxElement(currMB, &currSE, dP); - if(currSlice->slice_type == P_SLICE || currSlice->slice_type == SP_SLICE) + if (currSlice->slice_type == P_SLICE || currSlice->slice_type == SP_SLICE) ++(currSE.value1); - currMB->mb_type = (short) currSE.value1; - if(!dP->bitstream->ei_flag) + currMB->mb_type = (short)currSE.value1; + if (!dP->bitstream->ei_flag) currMB->ei_flag = 0; currSlice->cod_counter--; currMB->skip_flag = 0; - } - else - { + } else { currSlice->cod_counter--; currMB->mb_type = 0; currMB->ei_flag = 0; currMB->skip_flag = 1; // read field flag of bottom block - if(currSlice->mb_aff_frame_flag) - { - if(currSlice->cod_counter == 0 && ((mb_nr&0x01) == 0)) - { + if (currSlice->mb_aff_frame_flag) { + if (currSlice->cod_counter == 0 && ((mb_nr & 0x01) == 0)) { TRACE_STRING("mb_field_decoding_flag (of coded bottom mb)"); - currSE.len = (int64) 1; + currSE.len = (int64)1; readSyntaxElement_FLC(&currSE, dP->bitstream); dP->bitstream->frame_bitoffset--; TRACE_DECBITS(1); - currMB->mb_field = (Boolean) currSE.value1; - } - else if (currSlice->cod_counter > 0 && ((mb_nr & 0x01) == 0)) - { + currMB->mb_field = (Boolean)currSE.value1; + } else if (currSlice->cod_counter > 0 && ((mb_nr & 0x01) == 0)) { // check left macroblock pair first - if (mb_is_available(mb_nr - 2, currMB) && ((mb_nr % (p_Vid->PicWidthInMbs * 2))!=0)) - { - currMB->mb_field = p_Vid->mb_data[mb_nr-2].mb_field; - } - else - { + if (mb_is_available(mb_nr - 2, currMB) && + ((mb_nr % (p_Vid->PicWidthInMbs * 2)) != 0)) { + currMB->mb_field = p_Vid->mb_data[mb_nr - 2].mb_field; + } else { // check top macroblock pair - if (mb_is_available(mb_nr - 2*p_Vid->PicWidthInMbs, currMB)) - { - currMB->mb_field = p_Vid->mb_data[mb_nr-2*p_Vid->PicWidthInMbs].mb_field; - } - else + if (mb_is_available(mb_nr - 2 * p_Vid->PicWidthInMbs, currMB)) { + currMB->mb_field = + p_Vid->mb_data[mb_nr - 2 * p_Vid->PicWidthInMbs].mb_field; + } else currMB->mb_field = FALSE; } } } } - //update the list offset; - currMB->list_offset = (currMB->mb_field)? ((mb_nr&0x01)? 4: 2): 0; - + // update the list offset; + currMB->list_offset = (currMB->mb_field) ? ((mb_nr & 0x01) ? 4 : 2) : 0; } - motion->mb_field[mb_nr] = (byte) currMB->mb_field; + motion->mb_field[mb_nr] = (byte)currMB->mb_field; - currMB->block_y_aff = (currMB->mb_field) ? (mb_nr&0x01) ? (currMB->block_y - 4)>>1 : currMB->block_y >> 1 : currMB->block_y; + currMB->block_y_aff = + (currMB->mb_field) + ? (mb_nr & 0x01) ? (currMB->block_y - 4) >> 1 : currMB->block_y >> 1 + : currMB->block_y; currSlice->siblock[currMB->mb.y][currMB->mb.x] = 0; currSlice->interpret_mb_mode(currMB); - if(currSlice->mb_aff_frame_flag) - { - if(currMB->mb_field) - { - currSlice->num_ref_idx_active[LIST_0] <<=1; - currSlice->num_ref_idx_active[LIST_1] <<=1; + if (currSlice->mb_aff_frame_flag) { + if (currMB->mb_field) { + currSlice->num_ref_idx_active[LIST_0] <<= 1; + currSlice->num_ref_idx_active[LIST_1] <<= 1; } } - //====== READ 8x8 SUB-PARTITION MODES (modes of 8x8 blocks) and Intra VBST block modes ====== - if (currMB->mb_type == P8x8) - { + //====== READ 8x8 SUB-PARTITION MODES (modes of 8x8 blocks) and Intra VBST + //block modes ====== + if (currMB->mb_type == P8x8) { currMB->NoMbPartLessThan8x8Flag = TRUE; currSE.type = SE_MBTYPE; dP = &(currSlice->partArr[partMap[SE_MBTYPE]]); - if (currSlice->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) + if (currSlice->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) currSE.mapping = linfo_ue; else currSE.reading = readB8_typeInfo_CABAC_b_slice; - for (i = 0; i < 4; ++i) - { + for (i = 0; i < 4; ++i) { TRACE_STRING("sub_mb_type"); - dP->readSyntaxElement (currMB, &currSE, dP); - SetB8Mode (currMB, currSE.value1, i); + dP->readSyntaxElement(currMB, &currSE, dP); + SetB8Mode(currMB, currSE.value1, i); - //set NoMbPartLessThan8x8Flag for P8x8 mode - currMB->NoMbPartLessThan8x8Flag &= (currMB->b8mode[i]==0 && currSlice->active_sps->direct_8x8_inference_flag) || - (currMB->b8mode[i]==4); + // set NoMbPartLessThan8x8Flag for P8x8 mode + currMB->NoMbPartLessThan8x8Flag &= + (currMB->b8mode[i] == 0 && + currSlice->active_sps->direct_8x8_inference_flag) || + (currMB->b8mode[i] == 4); } //--- init macroblock data --- - init_macroblock (currMB); - currSlice->read_motion_info_from_NAL (currMB); - } - else - { - //init NoMbPartLessThan8x8Flag - currMB->NoMbPartLessThan8x8Flag = ((currMB->mb_type == 0) && !(currSlice->active_sps->direct_8x8_inference_flag))? FALSE: TRUE; + init_macroblock(currMB); + currSlice->read_motion_info_from_NAL(currMB); + } else { + // init NoMbPartLessThan8x8Flag + currMB->NoMbPartLessThan8x8Flag = + ((currMB->mb_type == 0) && + !(currSlice->active_sps->direct_8x8_inference_flag)) + ? FALSE + : TRUE; } //============= Transform Size Flag for INTRA MBs ============= //------------------------------------------------------------- - //transform size flag for INTRA_4x4 and INTRA_8x8 modes - if (currMB->mb_type == I4MB && currSlice->Transform8x8Mode) - { - currSE.type = SE_HEADER; + // transform size flag for INTRA_4x4 and INTRA_8x8 modes + if (currMB->mb_type == I4MB && currSlice->Transform8x8Mode) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); // read CAVLC transform_size_8x8_flag - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) - { - currSE.len = (int64) 1; + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) { + currSE.len = (int64)1; readSyntaxElement_FLC(&currSE, dP->bitstream); - } - else - { + } else { dP->readSyntaxElement(currMB, &currSE, dP); } - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; - if (currMB->luma_transform_size_8x8_flag) - { + if (currMB->luma_transform_size_8x8_flag) { currMB->mb_type = I8MB; memset(&currMB->b8mode, I8MB, 4 * sizeof(signed char)); memset(&currMB->b8pdir, -1, 4 * sizeof(signed char)); } - } - else - { + } else { currMB->luma_transform_size_8x8_flag = FALSE; } - if(p_Vid->active_pps->constrained_intra_pred_flag && currMB->is_intra_block == FALSE) - { + if (p_Vid->active_pps->constrained_intra_pred_flag && + currMB->is_intra_block == FALSE) { currSlice->intra_block[mb_nr] = 0; } @@ -1796,40 +1728,35 @@ static void read_one_macroblock_b_slice(Macroblock *currMB) if (currMB->mb_type != P8x8) init_macroblock(currMB); - if ((currMB->mb_type == BSKIP_DIRECT) && currSlice->cod_counter >= 0) - { + if ((currMB->mb_type == BSKIP_DIRECT) && currSlice->cod_counter >= 0) { currMB->cbp = 0; reset_coeffs(currSlice); - if (p_Vid->active_pps->entropy_coding_mode_flag ==CABAC) - currSlice->cod_counter=-1; - } - else if(currMB->mb_type != IPCM) - { - // intra prediction modes for a macroblock 4x4 ********************************************** + if (p_Vid->active_pps->entropy_coding_mode_flag == CABAC) + currSlice->cod_counter = -1; + } else if (currMB->mb_type != IPCM) { + // intra prediction modes for a macroblock 4x4 + // ********************************************** if (currMB->is_intra_block == TRUE) read_ipred_modes(currMB); - // read inter frame vector data ********************************************************* - if (currMB->is_intra_block == FALSE && (currMB->mb_type!=0) && (currMB->mb_type != P8x8)) - { - currSlice->read_motion_info_from_NAL (currMB); + // read inter frame vector data + // ********************************************************* + if (currMB->is_intra_block == FALSE && (currMB->mb_type != 0) && + (currMB->mb_type != P8x8)) { + currSlice->read_motion_info_from_NAL(currMB); } - // read CBP and Coeffs *************************************************************** - currSlice->read_CBP_and_coeffs_from_NAL (currMB); - } - else - { - //read pcm_alignment_zero_bit and pcm_byte[i] + // read CBP and Coeffs + // *************************************************************** + currSlice->read_CBP_and_coeffs_from_NAL(currMB); + } else { + // read pcm_alignment_zero_bit and pcm_byte[i] - // here dP is assigned with the same dP as SE_MBTYPE, because IPCM syntax is in the - // same category as MBTYPE - if ( currSlice->dp_mode && currSlice->dpB_NotPresent ) - { + // here dP is assigned with the same dP as SE_MBTYPE, because IPCM syntax is + // in the same category as MBTYPE + if (currSlice->dp_mode && currSlice->dpB_NotPresent) { concealIPCMcoeffs(currMB); - } - else - { + } else { dP = &(currSlice->partArr[partMap[SE_LUM_DC_INTRA]]); read_IPCM_coeffs_from_NAL(currSlice, dP); } @@ -1838,7 +1765,6 @@ static void read_one_macroblock_b_slice(Macroblock *currMB) return; } - /*! ************************************************************************ * \brief @@ -1849,113 +1775,98 @@ static void read_one_macroblock_b_slice(Macroblock *currMB) * Dong Wang ************************************************************************ */ -static void init_decoding_engine_IPCM(Slice *currSlice) -{ +static void init_decoding_engine_IPCM(Slice *currSlice) { Bitstream *currStream; int ByteStartPosition; int PartitionNumber; int i; - if(currSlice->dp_mode==PAR_DP_1) - PartitionNumber=1; - else if(currSlice->dp_mode==PAR_DP_3) - PartitionNumber=3; - else - { + if (currSlice->dp_mode == PAR_DP_1) + PartitionNumber = 1; + else if (currSlice->dp_mode == PAR_DP_3) + PartitionNumber = 3; + else { printf("Partition Mode is not supported\n"); exit(1); } - for(i=0;ipartArr[i].bitstream; ByteStartPosition = currStream->read_len; - arideco_start_decoding (&currSlice->partArr[i].de_cabac, currStream->streamBuffer, ByteStartPosition, &currStream->read_len); + arideco_start_decoding(&currSlice->partArr[i].de_cabac, + currStream->streamBuffer, ByteStartPosition, + &currStream->read_len); } } - - - /*! ************************************************************************ * \brief - * Read IPCM pcm_alignment_zero_bit and pcm_byte[i] from stream to currSlice->cof - * (for IPCM CABAC and IPCM CAVLC) + * Read IPCM pcm_alignment_zero_bit and pcm_byte[i] from stream to + *currSlice->cof (for IPCM CABAC and IPCM CAVLC) * * \author * Dong Wang ************************************************************************ */ -static void read_IPCM_coeffs_from_NAL(Slice *currSlice, struct datapartition *dP) -{ +static void read_IPCM_coeffs_from_NAL(Slice *currSlice, + struct datapartition *dP) { VideoParameters *p_Vid = currSlice->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; SyntaxElement currSE; - int i,j; + int i, j; - //For CABAC, we don't need to read bits to let stream byte aligned - // because we have variable for integer bytes position - if(p_Vid->active_pps->entropy_coding_mode_flag == CABAC) - { + // For CABAC, we don't need to read bits to let stream byte aligned + // because we have variable for integer bytes position + if (p_Vid->active_pps->entropy_coding_mode_flag == CABAC) { readIPCM_CABAC(currSlice, dP); init_decoding_engine_IPCM(currSlice); - } - else - { - //read bits to let stream byte aligned + } else { + // read bits to let stream byte aligned - if(((dP->bitstream->frame_bitoffset) & 0x07) != 0) - { + if (((dP->bitstream->frame_bitoffset) & 0x07) != 0) { TRACE_STRING("pcm_alignment_zero_bit"); currSE.len = (8 - ((dP->bitstream->frame_bitoffset) & 0x07)); readSyntaxElement_FLC(&currSE, dP->bitstream); } - //read luma and chroma IPCM coefficients - currSE.len=p_Vid->bitdepth_luma; + // read luma and chroma IPCM coefficients + currSE.len = p_Vid->bitdepth_luma; TRACE_STRING("pcm_sample_luma"); - for(i=0;ibitstream); currSlice->cof[0][i][j] = currSE.value1; - //p_Vid->fcf[0][i][j] = currSE.value1; + // p_Vid->fcf[0][i][j] = currSE.value1; } } - currSE.len=p_Vid->bitdepth_chroma; - if ((dec_picture->chroma_format_idc != YUV400) && (p_Vid->separate_colour_plane_flag == 0)) - { + currSE.len = p_Vid->bitdepth_chroma; + if ((dec_picture->chroma_format_idc != YUV400) && + (p_Vid->separate_colour_plane_flag == 0)) { TRACE_STRING("pcm_sample_chroma (u)"); - for(i=0;imb_cr_size_y;++i) - { - for(j=0;jmb_cr_size_x;++j) - { + for (i = 0; i < p_Vid->mb_cr_size_y; ++i) { + for (j = 0; j < p_Vid->mb_cr_size_x; ++j) { readSyntaxElement_FLC(&currSE, dP->bitstream); currSlice->cof[1][i][j] = currSE.value1; - //p_Vid->fcf[1][i][j] = currSE.value1; + // p_Vid->fcf[1][i][j] = currSE.value1; } } TRACE_STRING("pcm_sample_chroma (v)"); - for(i=0;imb_cr_size_y;++i) - { - for(j=0;jmb_cr_size_x;++j) - { + for (i = 0; i < p_Vid->mb_cr_size_y; ++i) { + for (j = 0; j < p_Vid->mb_cr_size_x; ++j) { readSyntaxElement_FLC(&currSE, dP->bitstream); currSlice->cof[2][i][j] = currSE.value1; - //p_Vid->fcf[2][i][j] = currSE.value1; + // p_Vid->fcf[2][i][j] = currSE.value1; } } } } } - /*! ************************************************************************ * \brief @@ -1964,10 +1875,8 @@ static void read_IPCM_coeffs_from_NAL(Slice *currSlice, struct datapartition *dP ************************************************************************ */ - -static void read_ipred_modes(Macroblock *currMB) -{ - int b8,i,j,bi,bj,bx,by,dec; +static void read_ipred_modes(Macroblock *currMB) { + int b8, i, j, bi, bj, bx, by, dec; SyntaxElement currSE; DataPartition *dP; Slice *currSlice = currMB->p_Slice; @@ -1979,9 +1888,10 @@ static void read_ipred_modes(Macroblock *currMB) int mostProbableIntraPredMode; int upIntraPredMode; int leftIntraPredMode; - signed char IntraChromaPredModeFlag = (signed char) (currMB->is_intra_block == TRUE); + signed char IntraChromaPredModeFlag = + (signed char)(currMB->is_intra_block == TRUE); int bs_x, bs_y; - int ii,jj; + int ii, jj; PixelPos left_block, top_block; @@ -1990,155 +1900,164 @@ static void read_ipred_modes(Macroblock *currMB) TRACE_STRING("intra4x4_pred_mode"); dP = &(currSlice->partArr[partMap[SE_INTRAPREDMODE]]); - if (!(p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag)) + if (!(p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag)) currSE.reading = readIntraPredMode_CABAC; - for(b8 = 0; b8 < 4; ++b8) //loop 8x8 blocks + for (b8 = 0; b8 < 4; ++b8) // loop 8x8 blocks { - if((currMB->b8mode[b8]==IBLOCK )||(currMB->b8mode[b8]==I8MB)) - { - bs_x = bs_y = (currMB->b8mode[b8] == I8MB)?8:4; + if ((currMB->b8mode[b8] == IBLOCK) || (currMB->b8mode[b8] == I8MB)) { + bs_x = bs_y = (currMB->b8mode[b8] == I8MB) ? 8 : 4; IntraChromaPredModeFlag = 1; - ii = (bs_x>>2); - jj = (bs_y>>2); + ii = (bs_x >> 2); + jj = (bs_y >> 2); - for(j = 0; j < 2; j += jj) //loop subblocks + for (j = 0; j < 2; j += jj) // loop subblocks { by = (b8 & 2) + j; bj = currMB->block_y + by; - for(i = 0; i < 2; i += ii) - { + for (i = 0; i < 2; i += ii) { bx = ((b8 & 1) << 1) + i; bi = currMB->block_x + bx; - //get from stream - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) + // get from stream + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) readSyntaxElement_Intra4x4PredictionMode(&currSE, dP->bitstream); - else - { - currSE.context=(b8<<2)+(j<<1) +i; + else { + currSE.context = (b8 << 2) + (j << 1) + i; dP->readSyntaxElement(currMB, &currSE, dP); } - get4x4Neighbour(currMB, (bx<<2) - 1, (by<<2), p_Vid->mb_size[IS_LUMA], &left_block); - get4x4Neighbour(currMB, (bx<<2), (by<<2) - 1, p_Vid->mb_size[IS_LUMA], &top_block ); + get4x4Neighbour(currMB, (bx << 2) - 1, (by << 2), + p_Vid->mb_size[IS_LUMA], &left_block); + get4x4Neighbour(currMB, (bx << 2), (by << 2) - 1, + p_Vid->mb_size[IS_LUMA], &top_block); - //get from array and decode + // get from array and decode - if (p_Vid->active_pps->constrained_intra_pred_flag) - { - left_block.available = left_block.available ? currSlice->intra_block[left_block.mb_addr] : 0; - top_block.available = top_block.available ? currSlice->intra_block[top_block.mb_addr] : 0; + if (p_Vid->active_pps->constrained_intra_pred_flag) { + left_block.available = + left_block.available + ? currSlice->intra_block[left_block.mb_addr] + : 0; + top_block.available = + top_block.available ? currSlice->intra_block[top_block.mb_addr] + : 0; } // !! KS: not sure if the following is still correct... - ts = ls = 0; // Check to see if the neighboring block is SI - if (currMB->mb_type == I4MB && currSlice->slice_type == SI_SLICE) // need support for MBINTLC1 + ts = ls = 0; // Check to see if the neighboring block is SI + if (currMB->mb_type == I4MB && + currSlice->slice_type == SI_SLICE) // need support for MBINTLC1 { if (left_block.available) - if (currSlice->siblock [PicPos[left_block.mb_addr].y][PicPos[left_block.mb_addr].x]) - ls=1; + if (currSlice->siblock[PicPos[left_block.mb_addr].y] + [PicPos[left_block.mb_addr].x]) + ls = 1; if (top_block.available) - if (currSlice->siblock [PicPos[top_block.mb_addr].y][PicPos[top_block.mb_addr].x]) - ts=1; + if (currSlice->siblock[PicPos[top_block.mb_addr].y] + [PicPos[top_block.mb_addr].x]) + ts = 1; } - upIntraPredMode = (top_block.available &&(ts == 0)) ? currSlice->ipredmode[top_block.pos_y ][top_block.pos_x ] : -1; - leftIntraPredMode = (left_block.available &&(ls == 0)) ? currSlice->ipredmode[left_block.pos_y][left_block.pos_x] : -1; + upIntraPredMode = + (top_block.available && (ts == 0)) + ? currSlice->ipredmode[top_block.pos_y][top_block.pos_x] + : -1; + leftIntraPredMode = + (left_block.available && (ls == 0)) + ? currSlice->ipredmode[left_block.pos_y][left_block.pos_x] + : -1; - mostProbableIntraPredMode = (upIntraPredMode < 0 || leftIntraPredMode < 0) ? DC_PRED : upIntraPredMode < leftIntraPredMode ? upIntraPredMode : leftIntraPredMode; + mostProbableIntraPredMode = + (upIntraPredMode < 0 || leftIntraPredMode < 0) ? DC_PRED + : upIntraPredMode < leftIntraPredMode ? upIntraPredMode + : leftIntraPredMode; - dec = (currSE.value1 == -1) ? mostProbableIntraPredMode : currSE.value1 + (currSE.value1 >= mostProbableIntraPredMode); + dec = (currSE.value1 == -1) + ? mostProbableIntraPredMode + : currSE.value1 + + (currSE.value1 >= mostProbableIntraPredMode); - //set - //?? memset(&(p_Vid->ipredmode[bj + jj][bi]), dec, (bs_x>>2) * sizeof(signed char)); // sets 1 or 2 bytes - if (bs_x == 8) - { - for (jj = 0; jj < (bs_y >> 2); ++jj) - { //loop 4x4s in the subblock for 8x8 prediction setting - currSlice->ipredmode[bj + jj][bi ] = (byte) dec; - currSlice->ipredmode[bj + jj][bi+1] = (byte) dec; + // set + //?? memset(&(p_Vid->ipredmode[bj + jj][bi]), dec, (bs_x>>2) + //* sizeof(signed char)); // sets 1 or 2 bytes + if (bs_x == 8) { + for (jj = 0; jj < (bs_y >> 2); + ++jj) { // loop 4x4s in the subblock for 8x8 prediction setting + currSlice->ipredmode[bj + jj][bi] = (byte)dec; + currSlice->ipredmode[bj + jj][bi + 1] = (byte)dec; } - } - else // bs_x == 4 + } else // bs_x == 4 { - for (jj = 0; jj < (bs_y >> 2); ++jj) //loop 4x4s in the subblock for 8x8 prediction setting - currSlice->ipredmode[bj + jj][bi] = (byte) dec; + for (jj = 0; jj < (bs_y >> 2); + ++jj) // loop 4x4s in the subblock for 8x8 prediction setting + currSlice->ipredmode[bj + jj][bi] = (byte)dec; } } } } } - if (IntraChromaPredModeFlag && (dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { + if (IntraChromaPredModeFlag && (dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { currSE.type = SE_INTRAPREDMODE; TRACE_STRING("intra_chroma_pred_mode"); dP = &(currSlice->partArr[partMap[SE_INTRAPREDMODE]]); - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) - { + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) { currSE.mapping = linfo_ue; - } - else + } else currSE.reading = readCIPredMode_CABAC; dP->readSyntaxElement(currMB, &currSE, dP); - currMB->c_ipred_mode = (signed char) currSE.value1; + currMB->c_ipred_mode = (signed char)currSE.value1; - if (currMB->c_ipred_mode < DC_PRED_8 || currMB->c_ipred_mode > PLANE_8) - { + if (currMB->c_ipred_mode < DC_PRED_8 || currMB->c_ipred_mode > PLANE_8) { error("illegal chroma intra pred mode!\n", 600); } } } - /*! ************************************************************************ * \brief * Get current block spatial neighbors ************************************************************************ */ -void get_neighbors(Macroblock *currMB, // <-- current Macroblock - PixelPos *block, // <--> neighbor blocks - int mb_x, // <-- block x position - int mb_y, // <-- block y position - int blockshape_x // <-- block width - ) -{ +void get_neighbors(Macroblock *currMB, // <-- current Macroblock + PixelPos *block, // <--> neighbor blocks + int mb_x, // <-- block x position + int mb_y, // <-- block y position + int blockshape_x // <-- block width +) { VideoParameters *p_Vid = currMB->p_Vid; int *mb_size = p_Vid->mb_size[IS_LUMA]; - - get4x4Neighbour(currMB, mb_x - 1, mb_y , mb_size, block ); - get4x4Neighbour(currMB, mb_x, mb_y - 1, mb_size, block + 1); - get4x4Neighbour(currMB, mb_x + blockshape_x, mb_y - 1, mb_size, block + 2); - if (mb_y > 0) - { - if (mb_x < 8) // first column of 8x8 blocks + get4x4Neighbour(currMB, mb_x - 1, mb_y, mb_size, block); + get4x4Neighbour(currMB, mb_x, mb_y - 1, mb_size, block + 1); + get4x4Neighbour(currMB, mb_x + blockshape_x, mb_y - 1, mb_size, block + 2); + + if (mb_y > 0) { + if (mb_x < 8) // first column of 8x8 blocks { - if (mb_y == 8 ) - { - if (blockshape_x == MB_BLOCK_SIZE) - block[2].available = 0; - } - else if (mb_x + blockshape_x == 8) - { + if (mb_y == 8) { + if (blockshape_x == MB_BLOCK_SIZE) + block[2].available = 0; + } else if (mb_x + blockshape_x == 8) { block[2].available = 0; } - } - else if (mb_x + blockshape_x == MB_BLOCK_SIZE) - { + } else if (mb_x + blockshape_x == MB_BLOCK_SIZE) { block[2].available = 0; } } - if (!block[2].available) - { + if (!block[2].available) { get4x4Neighbour(currMB, mb_x - 1, mb_y - 1, mb_size, block + 3); block[2] = block[3]; } @@ -2150,121 +2069,132 @@ void get_neighbors(Macroblock *currMB, // <-- current Macroblock * Read motion info ************************************************************************ */ -static void read_motion_info_from_NAL_p_slice (Macroblock *currMB) -{ +static void read_motion_info_from_NAL_p_slice(Macroblock *currMB) { VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; SyntaxElement currSE; DataPartition *dP = NULL; - const byte *partMap = assignSE2partition[currSlice->dp_mode]; - short partmode = ((currMB->mb_type == P8x8) ? 4 : currMB->mb_type); - int step_h0 = BLOCK_STEP [partmode][0]; - int step_v0 = BLOCK_STEP [partmode][1]; + const byte *partMap = assignSE2partition[currSlice->dp_mode]; + short partmode = ((currMB->mb_type == P8x8) ? 4 : currMB->mb_type); + int step_h0 = BLOCK_STEP[partmode][0]; + int step_v0 = BLOCK_STEP[partmode][1]; int j4; StorablePicture *dec_picture = currSlice->dec_picture; PicMotionParams *mv_info = NULL; - int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? (mb_nr&0x01) ? 4 : 2 : 0; + int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? + // (mb_nr&0x01) ? 4 : 2 : 0; StorablePicture **list0 = currSlice->listX[LIST_0 + list_offset]; //===== READ REFERENCE PICTURE INDICES ===== currSE.type = SE_REFFRAME; dP = &(currSlice->partArr[partMap[SE_REFFRAME]]); - // For LIST_0, if multiple ref. pictures, read LIST_0 reference picture indices for the MB *********** - prepareListforRefIdx (currMB, &currSE, dP, currSlice->num_ref_idx_active[LIST_0], (currMB->mb_type != P8x8) || (!currSlice->allrefzero)); - readMBRefPictureIdx (&currSE, dP, currMB, &dec_picture->mv_info[currMB->block_y], LIST_0, step_v0, step_h0); + // For LIST_0, if multiple ref. pictures, read LIST_0 reference picture + // indices for the MB *********** + prepareListforRefIdx(currMB, &currSE, dP, + currSlice->num_ref_idx_active[LIST_0], + (currMB->mb_type != P8x8) || (!currSlice->allrefzero)); + readMBRefPictureIdx(&currSE, dP, currMB, + &dec_picture->mv_info[currMB->block_y], LIST_0, step_v0, + step_h0); //===== READ MOTION VECTORS ===== currSE.type = SE_MVD; dP = &(currSlice->partArr[partMap[SE_MVD]]); - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) currSE.mapping = linfo_se; - else + else currSE.reading = read_MVD_CABAC; // LIST_0 Motion vectors - readMBMotionVectors (&currSE, dP, currMB, LIST_0, step_h0, step_v0); + readMBMotionVectors(&currSE, dP, currMB, LIST_0, step_h0, step_v0); - // record reference picture Ids for deblocking decisions - for(j4 = currMB->block_y; j4 < (currMB->block_y + 4);++j4) - { + // record reference picture Ids for deblocking decisions + for (j4 = currMB->block_y; j4 < (currMB->block_y + 4); ++j4) { mv_info = &dec_picture->mv_info[j4][currMB->block_x]; - mv_info->ref_pic[LIST_0] = list0[(short) mv_info->ref_idx[LIST_0]]; + mv_info->ref_pic[LIST_0] = list0[(short)mv_info->ref_idx[LIST_0]]; mv_info++; - mv_info->ref_pic[LIST_0] = list0[(short) mv_info->ref_idx[LIST_0]]; + mv_info->ref_pic[LIST_0] = list0[(short)mv_info->ref_idx[LIST_0]]; mv_info++; - mv_info->ref_pic[LIST_0] = list0[(short) mv_info->ref_idx[LIST_0]]; + mv_info->ref_pic[LIST_0] = list0[(short)mv_info->ref_idx[LIST_0]]; mv_info++; - mv_info->ref_pic[LIST_0] = list0[(short) mv_info->ref_idx[LIST_0]]; + mv_info->ref_pic[LIST_0] = list0[(short)mv_info->ref_idx[LIST_0]]; } } - /*! ************************************************************************ * \brief * Read motion info ************************************************************************ */ -static void read_motion_info_from_NAL_b_slice (Macroblock *currMB) -{ +static void read_motion_info_from_NAL_b_slice(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; SyntaxElement currSE; DataPartition *dP = NULL; const byte *partMap = assignSE2partition[currSlice->dp_mode]; - int partmode = ((currMB->mb_type == P8x8) ? 4 : currMB->mb_type); - int step_h0 = BLOCK_STEP [partmode][0]; - int step_v0 = BLOCK_STEP [partmode][1]; + int partmode = ((currMB->mb_type == P8x8) ? 4 : currMB->mb_type); + int step_h0 = BLOCK_STEP[partmode][0]; + int step_v0 = BLOCK_STEP[partmode][1]; int j4, i4; - int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? (mb_nr&0x01) ? 4 : 2 : 0; + int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? + // (mb_nr&0x01) ? 4 : 2 : 0; StorablePicture **list0 = currSlice->listX[LIST_0 + list_offset]; StorablePicture **list1 = currSlice->listX[LIST_1 + list_offset]; if (currMB->mb_type == P8x8) - currSlice->update_direct_mv_info(currMB); + currSlice->update_direct_mv_info(currMB); //===== READ REFERENCE PICTURE INDICES ===== currSE.type = SE_REFFRAME; dP = &(currSlice->partArr[partMap[SE_REFFRAME]]); - // For LIST_0, if multiple ref. pictures, read LIST_0 reference picture indices for the MB *********** - prepareListforRefIdx (currMB, &currSE, dP, currSlice->num_ref_idx_active[LIST_0], TRUE); - readMBRefPictureIdx (&currSE, dP, currMB, &dec_picture->mv_info[currMB->block_y], LIST_0, step_v0, step_h0); + // For LIST_0, if multiple ref. pictures, read LIST_0 reference picture + // indices for the MB *********** + prepareListforRefIdx(currMB, &currSE, dP, + currSlice->num_ref_idx_active[LIST_0], TRUE); + readMBRefPictureIdx(&currSE, dP, currMB, + &dec_picture->mv_info[currMB->block_y], LIST_0, step_v0, + step_h0); - // For LIST_1, if multiple ref. pictures, read LIST_1 reference picture indices for the MB *********** - prepareListforRefIdx (currMB, &currSE, dP, currSlice->num_ref_idx_active[LIST_1], TRUE); - readMBRefPictureIdx (&currSE, dP, currMB, &dec_picture->mv_info[currMB->block_y], LIST_1, step_v0, step_h0); + // For LIST_1, if multiple ref. pictures, read LIST_1 reference picture + // indices for the MB *********** + prepareListforRefIdx(currMB, &currSE, dP, + currSlice->num_ref_idx_active[LIST_1], TRUE); + readMBRefPictureIdx(&currSE, dP, currMB, + &dec_picture->mv_info[currMB->block_y], LIST_1, step_v0, + step_h0); //===== READ MOTION VECTORS ===== currSE.type = SE_MVD; dP = &(currSlice->partArr[partMap[SE_MVD]]); - if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || dP->bitstream->ei_flag) + if (p_Vid->active_pps->entropy_coding_mode_flag == CAVLC || + dP->bitstream->ei_flag) currSE.mapping = linfo_se; - else + else currSE.reading = read_MVD_CABAC; // LIST_0 Motion vectors - readMBMotionVectors (&currSE, dP, currMB, LIST_0, step_h0, step_v0); + readMBMotionVectors(&currSE, dP, currMB, LIST_0, step_h0, step_v0); // LIST_1 Motion vectors - readMBMotionVectors (&currSE, dP, currMB, LIST_1, step_h0, step_v0); + readMBMotionVectors(&currSE, dP, currMB, LIST_1, step_h0, step_v0); // record reference picture Ids for deblocking decisions - for(j4 = currMB->block_y; j4 < (currMB->block_y + 4);++j4) - { - for(i4 = currMB->block_x; i4 < (currMB->block_x + 4);++i4) - { + for (j4 = currMB->block_y; j4 < (currMB->block_y + 4); ++j4) { + for (i4 = currMB->block_x; i4 < (currMB->block_x + 4); ++i4) { PicMotionParams *mv_info = &dec_picture->mv_info[j4][i4]; short ref_idx = mv_info->ref_idx[LIST_0]; - mv_info->ref_pic[LIST_0] = (ref_idx >= 0) ? list0[ref_idx] : NULL; + mv_info->ref_pic[LIST_0] = (ref_idx >= 0) ? list0[ref_idx] : NULL; ref_idx = mv_info->ref_idx[LIST_1]; mv_info->ref_pic[LIST_1] = (ref_idx >= 0) ? list1[ref_idx] : NULL; } @@ -2274,46 +2204,44 @@ static void read_motion_info_from_NAL_b_slice (Macroblock *currMB) /*! ************************************************************************ * \brief - * Get the Prediction from the Neighboring Blocks for Number of + * Get the Prediction from the Neighboring Blocks for Number of * Nonzero Coefficients * * Luma Blocks ************************************************************************ */ -int predict_nnz(Macroblock *currMB, int block_type, int i,int j) -{ +int predict_nnz(Macroblock *currMB, int block_type, int i, int j) { VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; PixelPos pix; int pred_nnz = 0; - int cnt = 0; + int cnt = 0; // left block get4x4Neighbour(currMB, i - 1, j, p_Vid->mb_size[IS_LUMA], &pix); - if ((currMB->is_intra_block == TRUE) && pix.available && p_Vid->active_pps->constrained_intra_pred_flag && (currSlice->dp_mode==PAR_DP_3)) - { + if ((currMB->is_intra_block == TRUE) && pix.available && + p_Vid->active_pps->constrained_intra_pred_flag && + (currSlice->dp_mode == PAR_DP_3)) { pix.available &= currSlice->intra_block[pix.mb_addr]; if (!pix.available) ++cnt; } - if (pix.available) - { - switch (block_type) - { + if (pix.available) { + switch (block_type) { case LUMA: - pred_nnz = p_Vid->nz_coeff [pix.mb_addr ][0][pix.y][pix.x]; + pred_nnz = p_Vid->nz_coeff[pix.mb_addr][0][pix.y][pix.x]; ++cnt; break; case CB: - pred_nnz = p_Vid->nz_coeff [pix.mb_addr ][1][pix.y][pix.x]; + pred_nnz = p_Vid->nz_coeff[pix.mb_addr][1][pix.y][pix.x]; ++cnt; break; case CR: - pred_nnz = p_Vid->nz_coeff [pix.mb_addr ][2][pix.y][pix.x]; + pred_nnz = p_Vid->nz_coeff[pix.mb_addr][2][pix.y][pix.x]; ++cnt; break; default: @@ -2325,27 +2253,26 @@ int predict_nnz(Macroblock *currMB, int block_type, int i,int j) // top block get4x4Neighbour(currMB, i, j - 1, p_Vid->mb_size[IS_LUMA], &pix); - if ((currMB->is_intra_block == TRUE) && pix.available && p_Vid->active_pps->constrained_intra_pred_flag && (currSlice->dp_mode==PAR_DP_3)) - { + if ((currMB->is_intra_block == TRUE) && pix.available && + p_Vid->active_pps->constrained_intra_pred_flag && + (currSlice->dp_mode == PAR_DP_3)) { pix.available &= currSlice->intra_block[pix.mb_addr]; if (!pix.available) ++cnt; } - if (pix.available) - { - switch (block_type) - { + if (pix.available) { + switch (block_type) { case LUMA: - pred_nnz += p_Vid->nz_coeff [pix.mb_addr ][0][pix.y][pix.x]; + pred_nnz += p_Vid->nz_coeff[pix.mb_addr][0][pix.y][pix.x]; ++cnt; break; case CB: - pred_nnz += p_Vid->nz_coeff [pix.mb_addr ][1][pix.y][pix.x]; + pred_nnz += p_Vid->nz_coeff[pix.mb_addr][1][pix.y][pix.x]; ++cnt; break; case CR: - pred_nnz += p_Vid->nz_coeff [pix.mb_addr ][2][pix.y][pix.x]; + pred_nnz += p_Vid->nz_coeff[pix.mb_addr][2][pix.y][pix.x]; ++cnt; break; default: @@ -2354,72 +2281,69 @@ int predict_nnz(Macroblock *currMB, int block_type, int i,int j) } } - if (cnt==2) - { + if (cnt == 2) { ++pred_nnz; - pred_nnz>>=1; + pred_nnz >>= 1; } return pred_nnz; } - /*! ************************************************************************ * \brief - * Get the Prediction from the Neighboring Blocks for Number of + * Get the Prediction from the Neighboring Blocks for Number of * Nonzero Coefficients * * Chroma Blocks ************************************************************************ */ -int predict_nnz_chroma(Macroblock *currMB, int i,int j) -{ +int predict_nnz_chroma(Macroblock *currMB, int i, int j) { VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currMB->p_Slice->dec_picture; Slice *currSlice = currMB->p_Slice; PixelPos pix; int pred_nnz = 0; - int cnt = 0; + int cnt = 0; - if (dec_picture->chroma_format_idc != YUV444) - { - //YUV420 and YUV422 - // left block - get4x4Neighbour(currMB, ((i&0x01)<<2) - 1, j, p_Vid->mb_size[IS_CHROMA], &pix); + if (dec_picture->chroma_format_idc != YUV444) { + // YUV420 and YUV422 + // left block + get4x4Neighbour(currMB, ((i & 0x01) << 2) - 1, j, p_Vid->mb_size[IS_CHROMA], + &pix); - if ((currMB->is_intra_block == TRUE) && pix.available && p_Vid->active_pps->constrained_intra_pred_flag && (currSlice->dp_mode==PAR_DP_3)) - { + if ((currMB->is_intra_block == TRUE) && pix.available && + p_Vid->active_pps->constrained_intra_pred_flag && + (currSlice->dp_mode == PAR_DP_3)) { pix.available &= currSlice->intra_block[pix.mb_addr]; if (!pix.available) ++cnt; } - if (pix.available) - { - pred_nnz = p_Vid->nz_coeff [pix.mb_addr ][1][pix.y][2 * (i>>1) + pix.x]; + if (pix.available) { + pred_nnz = p_Vid->nz_coeff[pix.mb_addr][1][pix.y][2 * (i >> 1) + pix.x]; ++cnt; } // top block - get4x4Neighbour(currMB, ((i&0x01)<<2), j - 1, p_Vid->mb_size[IS_CHROMA], &pix); + get4x4Neighbour(currMB, ((i & 0x01) << 2), j - 1, p_Vid->mb_size[IS_CHROMA], + &pix); - if ((currMB->is_intra_block == TRUE) && pix.available && p_Vid->active_pps->constrained_intra_pred_flag && (currSlice->dp_mode==PAR_DP_3)) - { + if ((currMB->is_intra_block == TRUE) && pix.available && + p_Vid->active_pps->constrained_intra_pred_flag && + (currSlice->dp_mode == PAR_DP_3)) { pix.available &= currSlice->intra_block[pix.mb_addr]; if (!pix.available) ++cnt; } - if (pix.available) - { - pred_nnz += p_Vid->nz_coeff [pix.mb_addr ][1][pix.y][2 * (i>>1) + pix.x]; + if (pix.available) { + pred_nnz += p_Vid->nz_coeff[pix.mb_addr][1][pix.y][2 * (i >> 1) + pix.x]; ++cnt; } - if (cnt==2) - { + if (cnt == 2) { ++pred_nnz; pred_nnz >>= 1; } @@ -2428,7 +2352,6 @@ int predict_nnz_chroma(Macroblock *currMB, int i,int j) return pred_nnz; } - /*! ************************************************************************ * \brief @@ -2439,11 +2362,9 @@ int predict_nnz_chroma(Macroblock *currMB, int i,int j) * contributions by James Au ************************************************************************ */ -static void readCoeff4x4_CAVLC (Macroblock *currMB, - int block_type, - int i, int j, int levarr[16], int runarr[16], - int *number_coefficients) -{ +static void readCoeff4x4_CAVLC(Macroblock *currMB, int block_type, int i, int j, + int levarr[16], int runarr[16], + int *number_coefficients) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; int mb_nr = currMB->mbAddrX; @@ -2455,121 +2376,116 @@ static void readCoeff4x4_CAVLC (Macroblock *currMB, int k, code, vlcnum; int numcoeff = 0, numtrailingones, numcoeff_vlc; int level_two_or_higher; - int numones, totzeros, abslevel, cdc=0, cac=0; + int numones, totzeros, abslevel, cdc = 0, cac = 0; int zerosleft, ntr, dptype = 0; int max_coeff_num = 0, nnz; signed char type[15]; - static const int incVlc[] = {0, 3, 6, 12, 24, 48, 32768}; // maximum vlc = 6 + static const int incVlc[] = {0, 3, 6, 12, 24, 48, 32768}; // maximum vlc = 6 - switch (block_type) - { + switch (block_type) { case LUMA: max_coeff_num = 16; TRACE_PRINTF("Luma"); - dptype = (currMB->is_intra_block == TRUE) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER; - p_Vid->nz_coeff[mb_nr][0][j][i] = 0; + dptype = + (currMB->is_intra_block == TRUE) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER; + p_Vid->nz_coeff[mb_nr][0][j][i] = 0; break; case LUMA_INTRA16x16DC: max_coeff_num = 16; TRACE_PRINTF("Lum16DC"); dptype = SE_LUM_DC_INTRA; - p_Vid->nz_coeff[mb_nr][0][j][i] = 0; + p_Vid->nz_coeff[mb_nr][0][j][i] = 0; break; case LUMA_INTRA16x16AC: max_coeff_num = 15; TRACE_PRINTF("Lum16AC"); dptype = SE_LUM_AC_INTRA; - p_Vid->nz_coeff[mb_nr][0][j][i] = 0; + p_Vid->nz_coeff[mb_nr][0][j][i] = 0; break; case CB: max_coeff_num = 16; TRACE_PRINTF("Luma_add1"); - dptype = ((currMB->is_intra_block == TRUE)) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER; - p_Vid->nz_coeff[mb_nr][1][j][i] = 0; + dptype = + ((currMB->is_intra_block == TRUE)) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER; + p_Vid->nz_coeff[mb_nr][1][j][i] = 0; break; case CB_INTRA16x16DC: max_coeff_num = 16; TRACE_PRINTF("Luma_add1_16DC"); dptype = SE_LUM_DC_INTRA; - p_Vid->nz_coeff[mb_nr][1][j][i] = 0; + p_Vid->nz_coeff[mb_nr][1][j][i] = 0; break; case CB_INTRA16x16AC: max_coeff_num = 15; TRACE_PRINTF("Luma_add1_16AC"); dptype = SE_LUM_AC_INTRA; - p_Vid->nz_coeff[mb_nr][1][j][i] = 0; + p_Vid->nz_coeff[mb_nr][1][j][i] = 0; break; case CR: max_coeff_num = 16; TRACE_PRINTF("Luma_add2"); - dptype = ((currMB->is_intra_block == TRUE)) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER; - p_Vid->nz_coeff[mb_nr][2][j][i] = 0; + dptype = + ((currMB->is_intra_block == TRUE)) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER; + p_Vid->nz_coeff[mb_nr][2][j][i] = 0; break; case CR_INTRA16x16DC: max_coeff_num = 16; TRACE_PRINTF("Luma_add2_16DC"); dptype = SE_LUM_DC_INTRA; - p_Vid->nz_coeff[mb_nr][2][j][i] = 0; + p_Vid->nz_coeff[mb_nr][2][j][i] = 0; break; case CR_INTRA16x16AC: max_coeff_num = 15; TRACE_PRINTF("Luma_add1_16AC"); dptype = SE_LUM_AC_INTRA; - p_Vid->nz_coeff[mb_nr][2][j][i] = 0; - break; + p_Vid->nz_coeff[mb_nr][2][j][i] = 0; + break; case CHROMA_DC: max_coeff_num = p_Vid->num_cdc_coeff; cdc = 1; TRACE_PRINTF("ChrDC"); - dptype = (currMB->is_intra_block == TRUE) ? SE_CHR_DC_INTRA : SE_CHR_DC_INTER; - p_Vid->nz_coeff[mb_nr][0][j][i] = 0; + dptype = + (currMB->is_intra_block == TRUE) ? SE_CHR_DC_INTRA : SE_CHR_DC_INTER; + p_Vid->nz_coeff[mb_nr][0][j][i] = 0; break; case CHROMA_AC: max_coeff_num = 15; cac = 1; TRACE_PRINTF("ChrDC"); - dptype = (currMB->is_intra_block == TRUE) ? SE_CHR_AC_INTRA : SE_CHR_AC_INTER; - p_Vid->nz_coeff[mb_nr][0][j][i] = 0; + dptype = + (currMB->is_intra_block == TRUE) ? SE_CHR_AC_INTRA : SE_CHR_AC_INTER; + p_Vid->nz_coeff[mb_nr][0][j][i] = 0; break; default: - error ("readCoeff4x4_CAVLC: invalid block type", 600); - p_Vid->nz_coeff[mb_nr][0][j][i] = 0; + error("readCoeff4x4_CAVLC: invalid block type", 600); + p_Vid->nz_coeff[mb_nr][0][j][i] = 0; break; } currSE.type = dptype; dP = &(currSlice->partArr[partMap[dptype]]); - currStream = dP->bitstream; + currStream = dP->bitstream; - if (!cdc) - { - // luma or chroma AC - if(block_type==LUMA || block_type==LUMA_INTRA16x16DC || block_type==LUMA_INTRA16x16AC ||block_type==CHROMA_AC) - { - nnz = (!cac) ? predict_nnz(currMB, LUMA, i<<2, j<<2) : predict_nnz_chroma(currMB, i, ((j-4)<<2)); - } - else if (block_type==CB || block_type==CB_INTRA16x16DC || block_type==CB_INTRA16x16AC) - { - nnz = predict_nnz(currMB, CB, i<<2, j<<2); - } - else - { - nnz = predict_nnz(currMB, CR, i<<2, j<<2); + if (!cdc) { + // luma or chroma AC + if (block_type == LUMA || block_type == LUMA_INTRA16x16DC || + block_type == LUMA_INTRA16x16AC || block_type == CHROMA_AC) { + nnz = (!cac) ? predict_nnz(currMB, LUMA, i << 2, j << 2) + : predict_nnz_chroma(currMB, i, ((j - 4) << 2)); + } else if (block_type == CB || block_type == CB_INTRA16x16DC || + block_type == CB_INTRA16x16AC) { + nnz = predict_nnz(currMB, CB, i << 2, j << 2); + } else { + nnz = predict_nnz(currMB, CR, i << 2, j << 2); } - if (nnz < 2) - { + if (nnz < 2) { numcoeff_vlc = 0; - } - else if (nnz < 4) - { + } else if (nnz < 4) { numcoeff_vlc = 1; - } - else if (nnz < 8) - { + } else if (nnz < 8) { numcoeff_vlc = 2; - } - else // + } else // { numcoeff_vlc = 3; } @@ -2578,23 +2494,23 @@ static void readCoeff4x4_CAVLC (Macroblock *currMB, readSyntaxElement_NumCoeffTrailingOnes(&currSE, currStream, type); - numcoeff = currSE.value1; - numtrailingones = currSE.value2; + numcoeff = currSE.value1; + numtrailingones = currSE.value2; - if(block_type==LUMA || block_type==LUMA_INTRA16x16DC || block_type==LUMA_INTRA16x16AC ||block_type==CHROMA_AC) - p_Vid->nz_coeff[mb_nr][0][j][i] = (byte) numcoeff; - else if (block_type==CB || block_type==CB_INTRA16x16DC || block_type==CB_INTRA16x16AC) - p_Vid->nz_coeff[mb_nr][1][j][i] = (byte) numcoeff; + if (block_type == LUMA || block_type == LUMA_INTRA16x16DC || + block_type == LUMA_INTRA16x16AC || block_type == CHROMA_AC) + p_Vid->nz_coeff[mb_nr][0][j][i] = (byte)numcoeff; + else if (block_type == CB || block_type == CB_INTRA16x16DC || + block_type == CB_INTRA16x16AC) + p_Vid->nz_coeff[mb_nr][1][j][i] = (byte)numcoeff; else - p_Vid->nz_coeff[mb_nr][2][j][i] = (byte) numcoeff; - } - else - { + p_Vid->nz_coeff[mb_nr][2][j][i] = (byte)numcoeff; + } else { // chroma DC readSyntaxElement_NumCoeffTrailingOnesChromaDC(p_Vid, &currSE, currStream); - numcoeff = currSE.value1; - numtrailingones = currSE.value2; + numcoeff = currSE.value1; + numtrailingones = currSE.value2; } memset(levarr, 0, max_coeff_num * sizeof(int)); @@ -2603,38 +2519,34 @@ static void readCoeff4x4_CAVLC (Macroblock *currMB, numones = numtrailingones; *number_coefficients = numcoeff; - if (numcoeff) - { - if (numtrailingones) - { + if (numcoeff) { + if (numtrailingones) { currSE.len = numtrailingones; #if TRACE - snprintf(currSE.tracestring, - TRACESTRING_SIZE, "%s trailing ones sign (%d,%d)", type, i, j); + snprintf(currSE.tracestring, TRACESTRING_SIZE, + "%s trailing ones sign (%d,%d)", type, i, j); #endif - readSyntaxElement_FLC (&currSE, currStream); + readSyntaxElement_FLC(&currSE, currStream); code = currSE.inf; ntr = numtrailingones; - for (k = numcoeff - 1; k > numcoeff - 1 - numtrailingones; k--) - { - ntr --; - levarr[k] = (code>>ntr)&1 ? -1 : 1; + for (k = numcoeff - 1; k > numcoeff - 1 - numtrailingones; k--) { + ntr--; + levarr[k] = (code >> ntr) & 1 ? -1 : 1; } } // decode levels - level_two_or_higher = (numcoeff > 3 && numtrailingones == 3)? 0 : 1; + level_two_or_higher = (numcoeff > 3 && numtrailingones == 3) ? 0 : 1; vlcnum = (numcoeff > 10 && numtrailingones < 3) ? 1 : 0; - for (k = numcoeff - 1 - numtrailingones; k >= 0; k--) - { + for (k = numcoeff - 1 - numtrailingones; k >= 0; k--) { #if TRACE - snprintf(currSE.tracestring, - TRACESTRING_SIZE, "%s lev (%d,%d) k=%d vlc=%d ", type, i, j, k, vlcnum); + snprintf(currSE.tracestring, TRACESTRING_SIZE, + "%s lev (%d,%d) k=%d vlc=%d ", type, i, j, k, vlcnum); #endif if (vlcnum == 0) @@ -2642,34 +2554,32 @@ static void readCoeff4x4_CAVLC (Macroblock *currMB, else readSyntaxElement_Level_VLCN(&currSE, vlcnum, currStream); - if (level_two_or_higher) - { + if (level_two_or_higher) { currSE.inf += (currSE.inf > 0) ? 1 : -1; level_two_or_higher = 0; } levarr[k] = currSE.inf; abslevel = iabs(levarr[k]); - if (abslevel == 1) + if (abslevel == 1) ++numones; // update VLC table - if (abslevel > incVlc[vlcnum]) + if (abslevel > incVlc[vlcnum]) ++vlcnum; - if (k == numcoeff - 1 - numtrailingones && abslevel >3) - vlcnum = 2; + if (k == numcoeff - 1 - numtrailingones && abslevel > 3) + vlcnum = 2; } - if (numcoeff < max_coeff_num) - { + if (numcoeff < max_coeff_num) { // decode total run vlcnum = numcoeff - 1; currSE.value1 = vlcnum; #if TRACE - snprintf(currSE.tracestring, - TRACESTRING_SIZE, "%s totalrun (%d,%d) vlc=%d ", type, i,j, vlcnum); + snprintf(currSE.tracestring, TRACESTRING_SIZE, + "%s totalrun (%d,%d) vlc=%d ", type, i, j, vlcnum); #endif if (cdc) readSyntaxElement_TotalZerosChromaDC(p_Vid, &currSE, currStream); @@ -2677,9 +2587,7 @@ static void readCoeff4x4_CAVLC (Macroblock *currMB, readSyntaxElement_TotalZeros(&currSE, currStream); totzeros = currSE.value1; - } - else - { + } else { totzeros = 0; } @@ -2687,28 +2595,25 @@ static void readCoeff4x4_CAVLC (Macroblock *currMB, zerosleft = totzeros; i = numcoeff - 1; - if (zerosleft > 0 && i > 0) - { - do - { + if (zerosleft > 0 && i > 0) { + do { // select VLC for runbefore vlcnum = imin(zerosleft - 1, RUNBEFORE_NUM_M1); currSE.value1 = vlcnum; #if TRACE - snprintf(currSE.tracestring, - TRACESTRING_SIZE, "%s run (%d,%d) k=%d vlc=%d ", - type, i, j, i, vlcnum); + snprintf(currSE.tracestring, TRACESTRING_SIZE, + "%s run (%d,%d) k=%d vlc=%d ", type, i, j, i, vlcnum); #endif readSyntaxElement_Run(&currSE, currStream); runarr[i] = currSE.value1; zerosleft -= runarr[i]; - i --; + i--; } while (zerosleft != 0 && i != 0); } - runarr[i] = zerosleft; + runarr[i] = zerosleft; } // if numcoeff } @@ -2719,9 +2624,10 @@ static void readCoeff4x4_CAVLC (Macroblock *currMB, * from the NAL (CABAC Mode) ************************************************************************ */ -static void readCompCoeff4x4SMB_CABAC (Macroblock *currMB, SyntaxElement *currSE, ColorPlane pl, int block_y, int block_x, int start_scan, int64 *cbp_blk) -{ - int i,j,k; +static void readCompCoeff4x4SMB_CABAC(Macroblock *currMB, SyntaxElement *currSE, + ColorPlane pl, int block_y, int block_x, + int start_scan, int64 *cbp_blk) { + int i, j, k; int i0, j0; int level = 1; DataPartition *dP; @@ -2729,31 +2635,31 @@ static void readCompCoeff4x4SMB_CABAC (Macroblock *currMB, SyntaxElement *currSE Slice *currSlice = currMB->p_Slice; const byte *partMap = assignSE2partition[currSlice->dp_mode]; - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; int **cof = currSlice->cof[pl]; - for (j = block_y; j < block_y + BLOCK_SIZE_8x8; j += 4) - { + for (j = block_y; j < block_y + BLOCK_SIZE_8x8; j += 4) { currMB->subblock_y = j; // position for coeff_count ctx - for (i = block_x; i < block_x + BLOCK_SIZE_8x8; i += 4) - { + for (i = block_x; i < block_x + BLOCK_SIZE_8x8; i += 4) { currMB->subblock_x = i; // position for coeff_count ctx pos_scan_4x4 = pos_scan4x4[start_scan]; level = 1; - if (start_scan == 0) - { + if (start_scan == 0) { /* - * make distinction between INTRA and INTER coded - * luminance coefficients - */ - currSE->type = (currMB->is_intra_block ? SE_LUM_DC_INTRA : SE_LUM_DC_INTER); + * make distinction between INTRA and INTER coded + * luminance coefficients + */ + currSE->type = + (currMB->is_intra_block ? SE_LUM_DC_INTRA : SE_LUM_DC_INTER); dP = &(currSlice->partArr[partMap[currSE->type]]); - if (dP->bitstream->ei_flag) + if (dP->bitstream->ei_flag) currSE->mapping = linfo_levrun_inter; - else + else currSE->reading = readRunLevel_CABAC; #if TRACE @@ -2762,52 +2668,52 @@ static void readCompCoeff4x4SMB_CABAC (Macroblock *currMB, SyntaxElement *currSE else if (pl == PLANE_U) sprintf(currSE->tracestring, "Cb sng "); else - sprintf(currSE->tracestring, "Cr sng "); + sprintf(currSE->tracestring, "Cr sng "); #endif dP->readSyntaxElement(currMB, currSE, dP); level = currSE->value1; - if (level != 0) /* leave if level == 0 */ + if (level != 0) /* leave if level == 0 */ { pos_scan_4x4 += 2 * currSE->value2; i0 = *pos_scan_4x4++; j0 = *pos_scan_4x4++; - *cbp_blk |= i64_power2(j + (i >> 2)) ; - //cof[j + j0][i + i0]= rshift_rnd_sf((level * InvLevelScale4x4[j0][i0]) << qp_per, 4); - cof[j + j0][i + i0]= level; - //p_Vid->fcf[pl][j + j0][i + i0]= level; + *cbp_blk |= i64_power2(j + (i >> 2)); + // cof[j + j0][i + i0]= rshift_rnd_sf((level * + // InvLevelScale4x4[j0][i0]) << qp_per, 4); + cof[j + j0][i + i0] = level; + // p_Vid->fcf[pl][j + j0][i + i0]= level; } } - if (level != 0) - { + if (level != 0) { // make distinction between INTRA and INTER coded luminance coefficients - currSE->type = (currMB->is_intra_block ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER); + currSE->type = + (currMB->is_intra_block ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER); dP = &(currSlice->partArr[partMap[currSE->type]]); - if (dP->bitstream->ei_flag) + if (dP->bitstream->ei_flag) currSE->mapping = linfo_levrun_inter; - else + else currSE->reading = readRunLevel_CABAC; - for(k = 1; (k < 17) && (level != 0); ++k) - { + for (k = 1; (k < 17) && (level != 0); ++k) { #if TRACE if (pl == PLANE_Y) sprintf(currSE->tracestring, "Luma sng "); else if (pl == PLANE_U) sprintf(currSE->tracestring, "Cb sng "); else - sprintf(currSE->tracestring, "Cr sng "); + sprintf(currSE->tracestring, "Cr sng "); #endif dP->readSyntaxElement(currMB, currSE, dP); level = currSE->value1; - if (level != 0) /* leave if level == 0 */ + if (level != 0) /* leave if level == 0 */ { pos_scan_4x4 += 2 * currSE->value2; @@ -2815,7 +2721,7 @@ static void readCompCoeff4x4SMB_CABAC (Macroblock *currMB, SyntaxElement *currSE j0 = *pos_scan_4x4++; cof[j + j0][i + i0] = level; - //p_Vid->fcf[pl][j + j0][i + i0]= level; + // p_Vid->fcf[pl][j + j0][i + i0]= level; } } } @@ -2830,92 +2736,97 @@ static void readCompCoeff4x4SMB_CABAC (Macroblock *currMB, SyntaxElement *currSE * from the NAL (CABAC Mode) ************************************************************************ */ -static void readCompCoeff4x4MB_CABAC (Macroblock *currMB, SyntaxElement *currSE, ColorPlane pl, int (*InvLevelScale4x4)[4], int qp_per, int cbp) -{ +static void readCompCoeff4x4MB_CABAC(Macroblock *currMB, SyntaxElement *currSE, + ColorPlane pl, int (*InvLevelScale4x4)[4], + int qp_per, int cbp) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - int start_scan = IS_I16MB (currMB)? 1 : 0; + int start_scan = IS_I16MB(currMB) ? 1 : 0; int block_y, block_x; int i, j; int64 *cbp_blk = &currMB->cbp_blk[pl]; - if( pl == PLANE_Y || (p_Vid->separate_colour_plane_flag != 0) ) - currSE->context = (IS_I16MB(currMB) ? LUMA_16AC: LUMA_4x4); + if (pl == PLANE_Y || (p_Vid->separate_colour_plane_flag != 0)) + currSE->context = (IS_I16MB(currMB) ? LUMA_16AC : LUMA_4x4); else if (pl == PLANE_U) - currSE->context = (IS_I16MB(currMB) ? CB_16AC: CB_4x4); + currSE->context = (IS_I16MB(currMB) ? CB_16AC : CB_4x4); else - currSE->context = (IS_I16MB(currMB) ? CR_16AC: CR_4x4); + currSE->context = (IS_I16MB(currMB) ? CR_16AC : CR_4x4); - if (currMB->is_lossless == FALSE) - { - for (block_y = 0; block_y < MB_BLOCK_SIZE; block_y += BLOCK_SIZE_8x8) /* all modes */ + if (currMB->is_lossless == FALSE) { + for (block_y = 0; block_y < MB_BLOCK_SIZE; + block_y += BLOCK_SIZE_8x8) /* all modes */ { int **cof = &currSlice->cof[pl][block_y]; - for (block_x = 0; block_x < MB_BLOCK_SIZE; block_x += BLOCK_SIZE_8x8) - { - if (cbp & (1 << ((block_y >> 2) + (block_x >> 3)))) // are there any coeff in current block at all + for (block_x = 0; block_x < MB_BLOCK_SIZE; block_x += BLOCK_SIZE_8x8) { + if (cbp & (1 << ((block_y >> 2) + + (block_x >> + 3)))) // are there any coeff in current block at all { - readCompCoeff4x4SMB_CABAC (currMB, currSE, pl, block_y, block_x, start_scan, cbp_blk); + readCompCoeff4x4SMB_CABAC(currMB, currSE, pl, block_y, block_x, + start_scan, cbp_blk); - if (start_scan == 0) - { - for (j = 0; j < BLOCK_SIZE_8x8; ++j) - { + if (start_scan == 0) { + for (j = 0; j < BLOCK_SIZE_8x8; ++j) { int *coef = &cof[j][block_x]; int jj = j & 0x03; - for (i = 0; i < BLOCK_SIZE_8x8; i+=4) - { + for (i = 0; i < BLOCK_SIZE_8x8; i += 4) { if (*coef) - *coef = rshift_rnd_sf((*coef * InvLevelScale4x4[jj][0]) << qp_per, 4); + *coef = rshift_rnd_sf( + (*coef * InvLevelScale4x4[jj][0]) << qp_per, 4); coef++; if (*coef) - *coef = rshift_rnd_sf((*coef * InvLevelScale4x4[jj][1]) << qp_per, 4); + *coef = rshift_rnd_sf( + (*coef * InvLevelScale4x4[jj][1]) << qp_per, 4); coef++; if (*coef) - *coef = rshift_rnd_sf((*coef * InvLevelScale4x4[jj][2]) << qp_per, 4); + *coef = rshift_rnd_sf( + (*coef * InvLevelScale4x4[jj][2]) << qp_per, 4); coef++; if (*coef) - *coef = rshift_rnd_sf((*coef * InvLevelScale4x4[jj][3]) << qp_per, 4); + *coef = rshift_rnd_sf( + (*coef * InvLevelScale4x4[jj][3]) << qp_per, 4); + coef++; + } + } + } else { + for (j = 0; j < BLOCK_SIZE_8x8; ++j) { + int *coef = &cof[j][block_x]; + int jj = j & 0x03; + for (i = 0; i < BLOCK_SIZE_8x8; i += 4) { + if ((jj != 0) && *coef) + *coef = rshift_rnd_sf( + (*coef * InvLevelScale4x4[jj][0]) << qp_per, 4); + coef++; + if (*coef) + *coef = rshift_rnd_sf( + (*coef * InvLevelScale4x4[jj][1]) << qp_per, 4); + coef++; + if (*coef) + *coef = rshift_rnd_sf( + (*coef * InvLevelScale4x4[jj][2]) << qp_per, 4); + coef++; + if (*coef) + *coef = rshift_rnd_sf( + (*coef * InvLevelScale4x4[jj][3]) << qp_per, 4); coef++; } } } - else - { - for (j = 0; j < BLOCK_SIZE_8x8; ++j) - { - int *coef = &cof[j][block_x]; - int jj = j & 0x03; - for (i = 0; i < BLOCK_SIZE_8x8; i += 4) - { - if ((jj != 0) && *coef) - *coef= rshift_rnd_sf((*coef * InvLevelScale4x4[jj][0]) << qp_per, 4); - coef++; - if (*coef) - *coef= rshift_rnd_sf((*coef * InvLevelScale4x4[jj][1]) << qp_per, 4); - coef++; - if (*coef) - *coef= rshift_rnd_sf((*coef * InvLevelScale4x4[jj][2]) << qp_per, 4); - coef++; - if (*coef) - *coef= rshift_rnd_sf((*coef * InvLevelScale4x4[jj][3]) << qp_per, 4); - coef++; - } - } - } } } } - } - else - { - for (block_y = 0; block_y < MB_BLOCK_SIZE; block_y += BLOCK_SIZE_8x8) /* all modes */ + } else { + for (block_y = 0; block_y < MB_BLOCK_SIZE; + block_y += BLOCK_SIZE_8x8) /* all modes */ { - for (block_x = 0; block_x < MB_BLOCK_SIZE; block_x += BLOCK_SIZE_8x8) - { - if (cbp & (1 << ((block_y >> 2) + (block_x >> 3)))) // are there any coeff in current block at all + for (block_x = 0; block_x < MB_BLOCK_SIZE; block_x += BLOCK_SIZE_8x8) { + if (cbp & (1 << ((block_y >> 2) + + (block_x >> + 3)))) // are there any coeff in current block at all { - readCompCoeff4x4SMB_CABAC (currMB, currSE, pl, block_y, block_x, start_scan, cbp_blk); + readCompCoeff4x4SMB_CABAC(currMB, currSE, pl, block_y, block_x, + start_scan, cbp_blk); } } } @@ -2929,15 +2840,18 @@ static void readCompCoeff4x4MB_CABAC (Macroblock *currMB, SyntaxElement *currSE, * from the NAL (CABAC Mode) ************************************************************************ */ -static void readCompCoeff8x8_CABAC (Macroblock *currMB, SyntaxElement *currSE, ColorPlane pl, int b8) -{ - if (currMB->cbp & (1<cbp & + (1 << b8)) // are there any coefficients in the current block { VideoParameters *p_Vid = currMB->p_Vid; - int transform_pl = (p_Vid->separate_colour_plane_flag != 0) ? currMB->p_Slice->colour_plane_id : (int) pl; + int transform_pl = (p_Vid->separate_colour_plane_flag != 0) + ? currMB->p_Slice->colour_plane_id + : (int)pl; int **tcoeffs; - int i,j,k; + int i, j, k; int level = 1; DataPartition *dP; @@ -2945,91 +2859,104 @@ static void readCompCoeff8x8_CABAC (Macroblock *currMB, SyntaxElement *currSE, C const byte *partMap = assignSE2partition[currSlice->dp_mode]; int boff_x, boff_y; - int64 cbp_mask = (int64) 51 << (4 * b8 - 2 * (b8 & 0x01)); // corresponds to 110011, as if all four 4x4 blocks contain coeff, shifted to block position + int64 cbp_mask = + (int64)51 + << (4 * b8 - + 2 * (b8 & 0x01)); // corresponds to 110011, as if all four 4x4 + // blocks contain coeff, shifted to block position int64 *cur_cbp = &currMB->cbp_blk[pl]; // select scan type - const byte (*pos_scan8x8) = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN8x8[0] : FIELD_SCAN8x8[0]; + const byte(*pos_scan8x8) = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN8x8[0] + : FIELD_SCAN8x8[0]; - int qp_per = p_Vid->qp_per_matrix[ currMB->qp_scaled[transform_pl/*pl*/] ]; - int qp_rem = p_Vid->qp_rem_matrix[ currMB->qp_scaled[transform_pl/*pl*/] ]; + int qp_per = p_Vid->qp_per_matrix[currMB->qp_scaled[transform_pl /*pl*/]]; + int qp_rem = p_Vid->qp_rem_matrix[currMB->qp_scaled[transform_pl /*pl*/]]; - int (*InvLevelScale8x8)[8] = (currMB->is_intra_block == TRUE) ? currSlice->InvLevelScale8x8_Intra[transform_pl][qp_rem] : currSlice->InvLevelScale8x8_Inter[transform_pl][qp_rem]; + int(*InvLevelScale8x8)[8] = + (currMB->is_intra_block == TRUE) + ? currSlice->InvLevelScale8x8_Intra[transform_pl][qp_rem] + : currSlice->InvLevelScale8x8_Inter[transform_pl][qp_rem]; // === set offset in current macroblock === - boff_x = (b8&0x01) << 3; + boff_x = (b8 & 0x01) << 3; boff_y = (b8 >> 1) << 3; tcoeffs = &currSlice->mb_rres[pl][boff_y]; currMB->subblock_x = boff_x; // position for coeff_count ctx currMB->subblock_y = boff_y; // position for coeff_count ctx - if (pl==PLANE_Y || (p_Vid->separate_colour_plane_flag != 0)) + if (pl == PLANE_Y || (p_Vid->separate_colour_plane_flag != 0)) currSE->context = LUMA_8x8; - else if (pl==PLANE_U) + else if (pl == PLANE_U) currSE->context = CB_8x8; else - currSE->context = CR_8x8; + currSE->context = CR_8x8; currSE->reading = readRunLevel_CABAC; // Read DC - currSE->type = ((currMB->is_intra_block == 1) ? SE_LUM_DC_INTRA : SE_LUM_DC_INTER ); // Intra or Inter? + currSE->type = + ((currMB->is_intra_block == 1) ? SE_LUM_DC_INTRA + : SE_LUM_DC_INTER); // Intra or Inter? dP = &(currSlice->partArr[partMap[currSE->type]]); #if TRACE - if (pl==PLANE_Y) + if (pl == PLANE_Y) sprintf(currSE->tracestring, "Luma8x8 DC sng "); - else if (pl==PLANE_U) - sprintf(currSE->tracestring, "Cb 8x8 DC sng "); - else - sprintf(currSE->tracestring, "Cr 8x8 DC sng "); -#endif + else if (pl == PLANE_U) + sprintf(currSE->tracestring, "Cb 8x8 DC sng "); + else + sprintf(currSE->tracestring, "Cr 8x8 DC sng "); +#endif dP->readSyntaxElement(currMB, currSE, dP); level = currSE->value1; //============ decode ============= - if (level != 0) /* leave if level == 0 */ + if (level != 0) /* leave if level == 0 */ { - *cur_cbp |= cbp_mask; + *cur_cbp |= cbp_mask; pos_scan8x8 += 2 * (currSE->value2); i = *pos_scan8x8++; j = *pos_scan8x8++; - tcoeffs[j][boff_x + i] = rshift_rnd_sf((level * InvLevelScale8x8[j][i]) << qp_per, 6); // dequantization - //tcoeffs[ j][boff_x + i] = level; + tcoeffs[j][boff_x + i] = rshift_rnd_sf( + (level * InvLevelScale8x8[j][i]) << qp_per, 6); // dequantization + // tcoeffs[ j][boff_x + i] = level; // AC coefficients - currSE->type = ((currMB->is_intra_block == 1) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER); + currSE->type = + ((currMB->is_intra_block == 1) ? SE_LUM_AC_INTRA : SE_LUM_AC_INTER); dP = &(currSlice->partArr[partMap[currSE->type]]); - for(k = 1;(k < 65) && (level != 0);++k) - { + for (k = 1; (k < 65) && (level != 0); ++k) { #if TRACE - if (pl==PLANE_Y) + if (pl == PLANE_Y) sprintf(currSE->tracestring, "Luma8x8 sng "); - else if (pl==PLANE_U) - sprintf(currSE->tracestring, "Cb 8x8 sng "); - else - sprintf(currSE->tracestring, "Cr 8x8 sng "); + else if (pl == PLANE_U) + sprintf(currSE->tracestring, "Cb 8x8 sng "); + else + sprintf(currSE->tracestring, "Cr 8x8 sng "); #endif dP->readSyntaxElement(currMB, currSE, dP); level = currSE->value1; //============ decode ============= - if (level != 0) /* leave if level == 0 */ + if (level != 0) /* leave if level == 0 */ { pos_scan8x8 += 2 * (currSE->value2); i = *pos_scan8x8++; j = *pos_scan8x8++; - tcoeffs[ j][boff_x + i] = rshift_rnd_sf((level * InvLevelScale8x8[j][i]) << qp_per, 6); // dequantization - //tcoeffs[ j][boff_x + i] = level; + tcoeffs[j][boff_x + i] = rshift_rnd_sf( + (level * InvLevelScale8x8[j][i]) << qp_per, 6); // dequantization + // tcoeffs[ j][boff_x + i] = level; } } /* @@ -3038,11 +2965,12 @@ static void readCompCoeff8x8_CABAC (Macroblock *currMB, SyntaxElement *currSE, C for (i = 0; i < 8; i++) { if (tcoeffs[ j][boff_x + i]) - tcoeffs[ j][boff_x + i] = rshift_rnd_sf((tcoeffs[ j][boff_x + i] * InvLevelScale8x8[j][i]) << qp_per, 6); // dequantization + tcoeffs[ j][boff_x + i] = rshift_rnd_sf((tcoeffs[ j][boff_x + i] * + InvLevelScale8x8[j][i]) << qp_per, 6); // dequantization } } */ - } + } } } @@ -3053,14 +2981,16 @@ static void readCompCoeff8x8_CABAC (Macroblock *currMB, SyntaxElement *currSE, C * from the NAL (CABAC Mode - lossless) ************************************************************************ */ -static void readCompCoeff8x8_CABAC_lossless (Macroblock *currMB, SyntaxElement *currSE, ColorPlane pl, int b8) -{ - if (currMB->cbp & (1<cbp & + (1 << b8)) // are there any coefficients in the current block { VideoParameters *p_Vid = currMB->p_Vid; int **tcoeffs; - int i,j,k; + int i, j, k; int level = 1; DataPartition *dP; @@ -3068,48 +2998,53 @@ static void readCompCoeff8x8_CABAC_lossless (Macroblock *currMB, SyntaxElement * const byte *partMap = assignSE2partition[currSlice->dp_mode]; int boff_x, boff_y; - int64 cbp_mask = (int64) 51 << (4 * b8 - 2 * (b8 & 0x01)); // corresponds to 110011, as if all four 4x4 blocks contain coeff, shifted to block position + int64 cbp_mask = + (int64)51 + << (4 * b8 - + 2 * (b8 & 0x01)); // corresponds to 110011, as if all four 4x4 + // blocks contain coeff, shifted to block position int64 *cur_cbp = &currMB->cbp_blk[pl]; // select scan type - const byte (*pos_scan8x8) = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN8x8[0] : FIELD_SCAN8x8[0]; + const byte(*pos_scan8x8) = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN8x8[0] + : FIELD_SCAN8x8[0]; // === set offset in current macroblock === - boff_x = (b8&0x01) << 3; + boff_x = (b8 & 0x01) << 3; boff_y = (b8 >> 1) << 3; tcoeffs = &currSlice->mb_rres[pl][boff_y]; currMB->subblock_x = boff_x; // position for coeff_count ctx currMB->subblock_y = boff_y; // position for coeff_count ctx - if (pl==PLANE_Y || (p_Vid->separate_colour_plane_flag != 0)) + if (pl == PLANE_Y || (p_Vid->separate_colour_plane_flag != 0)) currSE->context = LUMA_8x8; - else if (pl==PLANE_U) + else if (pl == PLANE_U) currSE->context = CB_8x8; else - currSE->context = CR_8x8; + currSE->context = CR_8x8; currSE->reading = readRunLevel_CABAC; - for(k=0; (k < 65) && (level != 0);++k) - { + for (k = 0; (k < 65) && (level != 0); ++k) { //============ read ============= /* - * make distinction between INTRA and INTER coded - * luminance coefficients - */ + * make distinction between INTRA and INTER coded + * luminance coefficients + */ - currSE->type = ((currMB->is_intra_block == 1) - ? (k==0 ? SE_LUM_DC_INTRA : SE_LUM_AC_INTRA) - : (k==0 ? SE_LUM_DC_INTER : SE_LUM_AC_INTER)); + currSE->type = ((currMB->is_intra_block == 1) + ? (k == 0 ? SE_LUM_DC_INTRA : SE_LUM_AC_INTRA) + : (k == 0 ? SE_LUM_DC_INTER : SE_LUM_AC_INTER)); #if TRACE - if (pl==PLANE_Y) + if (pl == PLANE_Y) sprintf(currSE->tracestring, "Luma8x8 sng "); - else if (pl==PLANE_U) - sprintf(currSE->tracestring, "Cb 8x8 sng "); - else - sprintf(currSE->tracestring, "Cr 8x8 sng "); + else if (pl == PLANE_U) + sprintf(currSE->tracestring, "Cb 8x8 sng "); + else + sprintf(currSE->tracestring, "Cr 8x8 sng "); #endif dP = &(currSlice->partArr[partMap[currSE->type]]); @@ -3119,7 +3054,7 @@ static void readCompCoeff8x8_CABAC_lossless (Macroblock *currMB, SyntaxElement * level = currSE->value1; //============ decode ============= - if (level != 0) /* leave if level == 0 */ + if (level != 0) /* leave if level == 0 */ { pos_scan8x8 += 2 * (currSE->value2); @@ -3141,22 +3076,19 @@ static void readCompCoeff8x8_CABAC_lossless (Macroblock *currMB, SyntaxElement * * from the NAL (CABAC Mode) ************************************************************************ */ -static void readCompCoeff8x8MB_CABAC (Macroblock *currMB, SyntaxElement *currSE, ColorPlane pl) -{ +static void readCompCoeff8x8MB_CABAC(Macroblock *currMB, SyntaxElement *currSE, + ColorPlane pl) { //======= 8x8 transform size & CABAC ======== - if(currMB->is_lossless == FALSE) - { - readCompCoeff8x8_CABAC (currMB, currSE, pl, 0); - readCompCoeff8x8_CABAC (currMB, currSE, pl, 1); - readCompCoeff8x8_CABAC (currMB, currSE, pl, 2); - readCompCoeff8x8_CABAC (currMB, currSE, pl, 3); - } - else - { - readCompCoeff8x8_CABAC_lossless (currMB, currSE, pl, 0); - readCompCoeff8x8_CABAC_lossless (currMB, currSE, pl, 1); - readCompCoeff8x8_CABAC_lossless (currMB, currSE, pl, 2); - readCompCoeff8x8_CABAC_lossless (currMB, currSE, pl, 3); + if (currMB->is_lossless == FALSE) { + readCompCoeff8x8_CABAC(currMB, currSE, pl, 0); + readCompCoeff8x8_CABAC(currMB, currSE, pl, 1); + readCompCoeff8x8_CABAC(currMB, currSE, pl, 2); + readCompCoeff8x8_CABAC(currMB, currSE, pl, 3); + } else { + readCompCoeff8x8_CABAC_lossless(currMB, currSE, pl, 0); + readCompCoeff8x8_CABAC_lossless(currMB, currSE, pl, 1); + readCompCoeff8x8_CABAC_lossless(currMB, currSE, pl, 2); + readCompCoeff8x8_CABAC_lossless(currMB, currSE, pl, 3); } } @@ -3167,31 +3099,31 @@ static void readCompCoeff8x8MB_CABAC (Macroblock *currMB, SyntaxElement *currSE, * from the NAL (CABAC Mode) ************************************************************************ */ -static void readCompCoeff4x4MB_CAVLC (Macroblock *currMB, ColorPlane pl, int (*InvLevelScale4x4)[4], int qp_per, int cbp, byte **nzcoeff) -{ +static void readCompCoeff4x4MB_CAVLC(Macroblock *currMB, ColorPlane pl, + int (*InvLevelScale4x4)[4], int qp_per, + int cbp, byte **nzcoeff) { int block_y, block_x, b8; int i, j, k; int i0, j0; int levarr[16] = {0}, runarr[16] = {0}, numcoeff; Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; int start_scan = IS_I16MB(currMB) ? 1 : 0; int64 *cur_cbp = &currMB->cbp_blk[pl]; - int coef_ctr, cur_context; + int coef_ctr, cur_context; - if (IS_I16MB(currMB)) - { + if (IS_I16MB(currMB)) { if (pl == PLANE_Y) cur_context = LUMA_INTRA16x16AC; else if (pl == PLANE_U) cur_context = CB_INTRA16x16AC; else cur_context = CR_INTRA16x16AC; - } - else - { + } else { if (pl == PLANE_Y) cur_context = LUMA; else if (pl == PLANE_U) @@ -3200,30 +3132,25 @@ static void readCompCoeff4x4MB_CAVLC (Macroblock *currMB, ColorPlane pl, int (*I cur_context = CR; } - if (currMB->is_lossless == FALSE) - { + if (currMB->is_lossless == FALSE) { int block_y4, block_x4; for (block_y = 0; block_y < 4; block_y += 2) /* all modes */ { block_y4 = block_y << 2; - for (block_x = 0; block_x < 4; block_x += 2) - { + for (block_x = 0; block_x < 4; block_x += 2) { block_x4 = block_x << 2; b8 = (block_y + (block_x >> 1)); - if (cbp & (1 << b8)) // test if the block contains any coefficients + if (cbp & (1 << b8)) // test if the block contains any coefficients { - for (j = block_y4; j < block_y4 + 8; j += BLOCK_SIZE) - { - for (i = block_x4; i < block_x4 + 8; i += BLOCK_SIZE) - { - readCoeff4x4_CAVLC(currMB, cur_context, i >> 2, j >> 2, levarr, runarr, &numcoeff); + for (j = block_y4; j < block_y4 + 8; j += BLOCK_SIZE) { + for (i = block_x4; i < block_x4 + 8; i += BLOCK_SIZE) { + readCoeff4x4_CAVLC(currMB, cur_context, i >> 2, j >> 2, levarr, + runarr, &numcoeff); pos_scan_4x4 = pos_scan4x4[start_scan]; - for (k = 0; k < numcoeff; ++k) - { - if (levarr[k] != 0) - { + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) { pos_scan_4x4 += (runarr[k] << 1); i0 = *pos_scan_4x4++; @@ -3232,67 +3159,57 @@ static void readCompCoeff4x4MB_CAVLC (Macroblock *currMB, ColorPlane pl, int (*I // inverse quant for 4x4 transform only *cur_cbp |= i64_power2(j + (i >> 2)); - currSlice->cof[pl][j + j0][i + i0]= rshift_rnd_sf((levarr[k] * InvLevelScale4x4[j0][i0])<fcf[0][(j<<2) + j0][(i<<2) + i0]= levarr[k]; + currSlice->cof[pl][j + j0][i + i0] = rshift_rnd_sf( + (levarr[k] * InvLevelScale4x4[j0][i0]) << qp_per, 4); + // p_Vid->fcf[0][(j<<2) + j0][(i<<2) + i0]= levarr[k]; } } } } + } else { + memset(&nzcoeff[block_y][block_x], 0, 2 * sizeof(byte)); + memset(&nzcoeff[block_y + 1][block_x], 0, 2 * sizeof(byte)); } - else + } + } + } else { + for (block_y = 0; block_y < 4; block_y += 2) /* all modes */ + { + for (block_x = 0; block_x < 4; block_x += 2) { + b8 = 2 * (block_y >> 1) + (block_x >> 1); + + if (cbp & (1 << b8)) /* are there any coeff in current block at all */ { - memset(&nzcoeff[block_y ][block_x], 0, 2 * sizeof(byte)); + for (j = block_y; j < block_y + 2; ++j) { + for (i = block_x; i < block_x + 2; ++i) { + readCoeff4x4_CAVLC(currMB, cur_context, i, j, levarr, runarr, + &numcoeff); + + coef_ctr = start_scan - 1; + + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) { + coef_ctr += runarr[k] + 1; + + i0 = pos_scan4x4[coef_ctr][0]; + j0 = pos_scan4x4[coef_ctr][1]; + + *cur_cbp |= i64_power2((j << 2) + i); + currSlice->cof[pl][(j << 2) + j0][(i << 2) + i0] = levarr[k]; + // p_Vid->fcf[0][(j<<2) + j0][(i<<2) + i0]= levarr[k]; + } + } + } + } + } else { + memset(&nzcoeff[block_y][block_x], 0, 2 * sizeof(byte)); memset(&nzcoeff[block_y + 1][block_x], 0, 2 * sizeof(byte)); } } } } - else - { - for (block_y=0; block_y < 4; block_y += 2) /* all modes */ - { - for (block_x=0; block_x < 4; block_x += 2) - { - b8 = 2*(block_y>>1) + (block_x>>1); - - if (cbp & (1<cof[pl][(j<<2) + j0][(i<<2) + i0]= levarr[k]; - //p_Vid->fcf[0][(j<<2) + j0][(i<<2) + i0]= levarr[k]; - } - } - } - } - } - else - { - memset(&nzcoeff[block_y ][block_x], 0, 2 * sizeof(byte)); - memset(&nzcoeff[block_y + 1][block_x], 0, 2 * sizeof(byte)); - } - } - } - } } - /*! ************************************************************************ * \brief @@ -3300,30 +3217,30 @@ static void readCompCoeff4x4MB_CAVLC (Macroblock *currMB, ColorPlane pl, int (*I * from the NAL (CABAC Mode) ************************************************************************ */ -static void readCompCoeff8x8MB_CAVLC (Macroblock *currMB, ColorPlane pl, int (*InvLevelScale8x8)[8], int qp_per, int cbp, byte **nzcoeff) -{ +static void readCompCoeff8x8MB_CAVLC(Macroblock *currMB, ColorPlane pl, + int (*InvLevelScale8x8)[8], int qp_per, + int cbp, byte **nzcoeff) { int block_y, block_x, b4, b8; int i, j, k; int i0, j0; int levarr[16] = {0}, runarr[16] = {0}, numcoeff; Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - const byte (*pos_scan8x8)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN8x8 : FIELD_SCAN8x8; + const byte(*pos_scan8x8)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN8x8 + : FIELD_SCAN8x8; int start_scan = IS_I16MB(currMB) ? 1 : 0; int64 *cur_cbp = &currMB->cbp_blk[pl]; - int coef_ctr, cur_context; + int coef_ctr, cur_context; - if (IS_I16MB(currMB)) - { + if (IS_I16MB(currMB)) { if (pl == PLANE_Y) cur_context = LUMA_INTRA16x16AC; else if (pl == PLANE_U) cur_context = CB_INTRA16x16AC; else cur_context = CR_INTRA16x16AC; - } - else - { + } else { if (pl == PLANE_Y) cur_context = LUMA; else if (pl == PLANE_U) @@ -3332,102 +3249,94 @@ static void readCompCoeff8x8MB_CAVLC (Macroblock *currMB, ColorPlane pl, int (*I cur_context = CR; } - if (currMB->is_lossless == FALSE) - { + if (currMB->is_lossless == FALSE) { int block_y4, block_x4; for (block_y = 0; block_y < 4; block_y += 2) /* all modes */ { block_y4 = block_y << 2; - for (block_x = 0; block_x < 4; block_x += 2) - { + for (block_x = 0; block_x < 4; block_x += 2) { block_x4 = block_x << 2; - b8 = block_y + (block_x>>1); + b8 = block_y + (block_x >> 1); - if (cbp & (1<mb_rres[pl][block_y4 +j0][block_x4 +i0] = rshift_rnd_sf((levarr[k] * InvLevelScale8x8[j0][i0])<mb_rres[pl][block_y4 + j0][block_x4 + i0] = + rshift_rnd_sf((levarr[k] * InvLevelScale8x8[j0][i0]) + << qp_per, + 6); // dequantization } - }//else (!currMB->luma_transform_size_8x8_flag) + } // else (!currMB->luma_transform_size_8x8_flag) } } - } - else - { - memset(&nzcoeff[block_y ][block_x], 0, 2 * sizeof(byte)); + } else { + memset(&nzcoeff[block_y][block_x], 0, 2 * sizeof(byte)); memset(&nzcoeff[block_y + 1][block_x], 0, 2 * sizeof(byte)); } } } - } - else // inverse quant for 8x8 transform + } else // inverse quant for 8x8 transform { - for (block_y=0; block_y < 4; block_y += 2) /* all modes */ + for (block_y = 0; block_y < 4; block_y += 2) /* all modes */ { - for (block_x=0; block_x < 4; block_x += 2) - { - b8 = 2*(block_y>>1) + (block_x>>1); + for (block_x = 0; block_x < 4; block_x += 2) { + b8 = 2 * (block_y >> 1) + (block_x >> 1); - if (cbp & (1<mb_rres[pl][block_y*4 +jz][block_x*4 +iz] = levarr[k]; + currSlice->mb_rres[pl][block_y * 4 + jz][block_x * 4 + iz] = + levarr[k]; } } } } - } - else - { - memset(&nzcoeff[block_y ][block_x], 0, 2 * sizeof(byte)); + } else { + memset(&nzcoeff[block_y][block_x], 0, 2 * sizeof(byte)); memset(&nzcoeff[block_y + 1][block_x], 0, 2 * sizeof(byte)); } } @@ -3438,33 +3347,29 @@ static void readCompCoeff8x8MB_CAVLC (Macroblock *currMB, ColorPlane pl, int (*I /*! ************************************************************************ * \brief - * Data partitioning: Check if neighboring macroblock is needed for + * Data partitioning: Check if neighboring macroblock is needed for * CAVLC context decoding, and disable current MB if data partition * is missing. ************************************************************************ */ -static void check_dp_neighbors (Macroblock *currMB) -{ +static void check_dp_neighbors(Macroblock *currMB) { VideoParameters *p_Vid = currMB->p_Vid; PixelPos up, left; - p_Vid->getNeighbour(currMB, -1, 0, p_Vid->mb_size[1], &left); - p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[1], &up); + p_Vid->getNeighbour(currMB, -1, 0, p_Vid->mb_size[1], &left); + p_Vid->getNeighbour(currMB, 0, -1, p_Vid->mb_size[1], &up); - if ((currMB->is_intra_block == FALSE) || (!(p_Vid->active_pps->constrained_intra_pred_flag)) ) - { - if (left.available) - { + if ((currMB->is_intra_block == FALSE) || + (!(p_Vid->active_pps->constrained_intra_pred_flag))) { + if (left.available) { currMB->dpl_flag |= p_Vid->mb_data[left.mb_addr].dpl_flag; } - if (up.available) - { + if (up.available) { currMB->dpl_flag |= p_Vid->mb_data[up.mb_addr].dpl_flag; } } } - /*! ************************************************************************ * \brief @@ -3472,9 +3377,8 @@ static void check_dp_neighbors (Macroblock *currMB) * from the NAL ************************************************************************ */ -static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) -{ - int i,j; +static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) { + int i, j; int level; int cbp; SyntaxElement currSE; @@ -3485,41 +3389,42 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) int qp_per, qp_rem; VideoParameters *p_Vid = currMB->p_Vid; - int smb = ((p_Vid->type==SP_SLICE) && (currMB->is_intra_block == FALSE)) || (p_Vid->type == SI_SLICE && currMB->mb_type == SI4MB); + int smb = ((p_Vid->type == SP_SLICE) && (currMB->is_intra_block == FALSE)) || + (p_Vid->type == SI_SLICE && currMB->mb_type == SI4MB); int qp_per_uv[2]; int qp_rem_uv[2]; - int intra = (currMB->is_intra_block == TRUE); + int intra = (currMB->is_intra_block == TRUE); StorablePicture *dec_picture = currSlice->dec_picture; int yuv = dec_picture->chroma_format_idc - 1; - int (*InvLevelScale4x4)[4] = NULL; + int(*InvLevelScale4x4)[4] = NULL; // select scan type - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; - if (!IS_I16MB (currMB)) - { + if (!IS_I16MB(currMB)) { int need_transform_size_flag; //===== C B P ===== //--------------------- - currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? SE_CBP_INTRA - : SE_CBP_INTER; + currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? SE_CBP_INTRA + : SE_CBP_INTER; dP = &(currSlice->partArr[partMap[currSE.type]]); - if (dP->bitstream->ei_flag) - { - currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? currSlice->linfo_cbp_intra - : currSlice->linfo_cbp_inter; - } - else - { + if (dP->bitstream->ei_flag) { + currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? currSlice->linfo_cbp_intra + : currSlice->linfo_cbp_inter; + } else { currSE.reading = read_CBP_CABAC; } @@ -3527,180 +3432,167 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) dP->readSyntaxElement(currMB, &currSE, dP); currMB->cbp = cbp = currSE.value1; - //============= Transform size flag for INTER MBs ============= //------------------------------------------------------------- - need_transform_size_flag = (((currMB->mb_type >= 1 && currMB->mb_type <= 3)|| - (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || - (currMB->NoMbPartLessThan8x8Flag)) - && currMB->mb_type != I8MB && currMB->mb_type != I4MB - && (currMB->cbp&15) - && currSlice->Transform8x8Mode); + need_transform_size_flag = + (((currMB->mb_type >= 1 && currMB->mb_type <= 3) || + (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || + (currMB->NoMbPartLessThan8x8Flag)) && + currMB->mb_type != I8MB && currMB->mb_type != I4MB && + (currMB->cbp & 15) && currSlice->Transform8x8Mode); - if (need_transform_size_flag) - { - currSE.type = SE_HEADER; + if (need_transform_size_flag) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); // read CAVLC transform_size_8x8_flag - if (dP->bitstream->ei_flag) - { + if (dP->bitstream->ei_flag) { currSE.len = 1; readSyntaxElement_FLC(&currSE, dP->bitstream); - } - else - { + } else { dP->readSyntaxElement(currMB, &currSE, dP); } - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; } //===== DQUANT ===== //---------------------- // Delta quant only if nonzero coeffs - if (cbp !=0) - { - read_delta_quant(&currSE, dP, currMB, partMap, ((currMB->is_intra_block == FALSE)) ? SE_DELTA_QUANT_INTER : SE_DELTA_QUANT_INTRA); + if (cbp != 0) { + read_delta_quant(&currSE, dP, currMB, partMap, + ((currMB->is_intra_block == FALSE)) + ? SE_DELTA_QUANT_INTER + : SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent ) + if (currSlice->dp_mode) { + if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent) currMB->dpl_flag = 1; - if( intra && currSlice->dpB_NotPresent ) - { + if (intra && currSlice->dpB_NotPresent) { currMB->ei_flag = 1; currMB->dpl_flag = 1; } // check for prediction from neighbours - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + cbp = 0; currMB->cbp = cbp; } } } - } - else // read DC coeffs for new intra modes + } else // read DC coeffs for new intra modes { cbp = currMB->cbp; - + read_delta_quant(&currSE, dP, currMB, partMap, SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if (currSlice->dpB_NotPresent) - { - currMB->ei_flag = 1; + if (currSlice->dp_mode) { + if (currSlice->dpB_NotPresent) { + currMB->ei_flag = 1; currMB->dpl_flag = 1; } - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - currMB->cbp = cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + currMB->cbp = cbp = 0; } } - if (!currMB->dpl_flag) - { + if (!currMB->dpl_flag) { int k; pos_scan_4x4 = pos_scan4x4[0]; currSE.type = SE_LUM_DC_INTRA; dP = &(currSlice->partArr[partMap[currSE.type]]); - currSE.context = LUMA_16DC; - currSE.type = SE_LUM_DC_INTRA; + currSE.context = LUMA_16DC; + currSE.type = SE_LUM_DC_INTRA; - if (dP->bitstream->ei_flag) - { + if (dP->bitstream->ei_flag) { currSE.mapping = linfo_levrun_inter; - } - else - { + } else { currSE.reading = readRunLevel_CABAC; } - level = 1; // just to get inside the loop + level = 1; // just to get inside the loop - for(k = 0; (k < 17) && (level != 0); ++k) - { + for (k = 0; (k < 17) && (level != 0); ++k) { #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC luma 16x16 "); #endif dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) /* leave if level == 0 */ + if (level != 0) /* leave if level == 0 */ { pos_scan_4x4 += (2 * currSE.value2); i0 = ((*pos_scan_4x4++) << 2); j0 = ((*pos_scan_4x4++) << 2); - currSlice->cof[0][j0][i0] = level;// add new intra DC coeff - //p_Vid->fcf[0][j0][i0] = level;// add new intra DC coeff + currSlice->cof[0][j0][i0] = level; // add new intra DC coeff + // p_Vid->fcf[0][j0][i0] = level;// add new intra DC coeff } } - - if(currMB->is_lossless == FALSE) - itrans_2(currMB, (ColorPlane) currSlice->colour_plane_id);// transform new intra DC + if (currMB->is_lossless == FALSE) + itrans_2( + currMB, + (ColorPlane)currSlice->colour_plane_id); // transform new intra DC } } update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; - qp_rem = p_Vid->qp_rem_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; + qp_per = p_Vid->qp_per_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; + qp_rem = p_Vid->qp_rem_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; // luma coefficients //======= Other Modes & CABAC ======== - //------------------------------------ - if (cbp) - { - if(currMB->luma_transform_size_8x8_flag) - { + //------------------------------------ + if (cbp) { + if (currMB->luma_transform_size_8x8_flag) { //======= 8x8 transform size & CABAC ======== - readCompCoeff8x8MB_CABAC (currMB, &currSE, PLANE_Y); - } - else - { - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; - readCompCoeff4x4MB_CABAC (currMB, &currSE, PLANE_Y, InvLevelScale4x4, qp_per, cbp); + readCompCoeff8x8MB_CABAC(currMB, &currSE, PLANE_Y); + } else { + InvLevelScale4x4 = + intra + ? currSlice + ->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id] + [qp_rem]; + readCompCoeff4x4MB_CABAC(currMB, &currSE, PLANE_Y, InvLevelScale4x4, + qp_per, cbp); } } - //init quant parameters for chroma - for(i=0; i < 2; ++i) - { - qp_per_uv[i] = p_Vid->qp_per_matrix[ currMB->qp_scaled[i + 1] ]; - qp_rem_uv[i] = p_Vid->qp_rem_matrix[ currMB->qp_scaled[i + 1] ]; + // init quant parameters for chroma + for (i = 0; i < 2; ++i) { + qp_per_uv[i] = p_Vid->qp_per_matrix[currMB->qp_scaled[i + 1]]; + qp_rem_uv[i] = p_Vid->qp_rem_matrix[currMB->qp_scaled[i + 1]]; } //========================== CHROMA DC ============================ //----------------------------------------------------------------- // chroma DC coeff - if(cbp>15) - { + if (cbp > 15) { int uv, ll, k, coef_ctr; - for (ll=0;ll<3;ll+=2) - { - uv = ll>>1; + for (ll = 0; ll < 3; ll += 2) { + uv = ll >> 1; - InvLevelScale4x4 = intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; + InvLevelScale4x4 = + intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] + : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; //===================== CHROMA DC YUV420 ====================== - memset(currSlice->cofu, 0, 4 *sizeof(int)); - coef_ctr=-1; + memset(currSlice->cofu, 0, 4 * sizeof(int)); + coef_ctr = -1; level = 1; - currMB->is_v_block = ll; - currSE.context = CHROMA_DC; - currSE.type = (intra ? SE_CHR_DC_INTRA : SE_CHR_DC_INTER); + currMB->is_v_block = ll; + currSE.context = CHROMA_DC; + currSE.type = (intra ? SE_CHR_DC_INTRA : SE_CHR_DC_INTER); dP = &(currSlice->partArr[partMap[currSE.type]]); @@ -3709,8 +3601,7 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) else currSE.reading = readRunLevel_CABAC; - for(k = 0; (k < (p_Vid->num_cdc_coeff + 1))&&(level!=0);++k) - { + for (k = 0; (k < (p_Vid->num_cdc_coeff + 1)) && (level != 0); ++k) { #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "2x2 DC Chroma "); #endif @@ -3718,61 +3609,62 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) - { - currMB->cbp_blk[0] |= 0xf0000 << (ll<<1) ; + if (level != 0) { + currMB->cbp_blk[0] |= 0xf0000 << (ll << 1); coef_ctr += currSE.value2 + 1; - // Bug: currSlice->cofu has only 4 entries, hence coef_ctr MUST be <4 (which is - // caught by the assert(). If it is bigger than 4, it starts patching the - // p_Vid->predmode pointer, which leads to bugs later on. + // Bug: currSlice->cofu has only 4 entries, hence coef_ctr MUST be <4 + // (which is caught by the assert(). If it is bigger than 4, it + // starts patching the p_Vid->predmode pointer, which leads to bugs + // later on. // - // This assert() should be left in the code, because it captures a very likely - // bug early when testing in error prone environments (or when testing NAL - // functionality). + // This assert() should be left in the code, because it captures a + // very likely bug early when testing in error prone environments (or + // when testing NAL functionality). - assert (coef_ctr < p_Vid->num_cdc_coeff); - currSlice->cofu[coef_ctr]=level; + assert(coef_ctr < p_Vid->num_cdc_coeff); + currSlice->cofu[coef_ctr] = level; } } - - if (smb || (currMB->is_lossless == TRUE)) // check to see if MB type is SPred or SIntra4x4 + if (smb || (currMB->is_lossless == + TRUE)) // check to see if MB type is SPred or SIntra4x4 { currSlice->cof[uv + 1][0][0] = currSlice->cofu[0]; currSlice->cof[uv + 1][0][4] = currSlice->cofu[1]; currSlice->cof[uv + 1][4][0] = currSlice->cofu[2]; currSlice->cof[uv + 1][4][4] = currSlice->cofu[3]; - //p_Vid->fcf[uv + 1][0][0] = currSlice->cofu[0]; - //p_Vid->fcf[uv + 1][4][0] = currSlice->cofu[1]; - //p_Vid->fcf[uv + 1][0][4] = currSlice->cofu[2]; - //p_Vid->fcf[uv + 1][4][4] = currSlice->cofu[3]; - } - else - { + // p_Vid->fcf[uv + 1][0][0] = currSlice->cofu[0]; + // p_Vid->fcf[uv + 1][4][0] = currSlice->cofu[1]; + // p_Vid->fcf[uv + 1][0][4] = currSlice->cofu[2]; + // p_Vid->fcf[uv + 1][4][4] = currSlice->cofu[3]; + } else { int temp[4]; int scale_dc = InvLevelScale4x4[0][0]; ihadamard2x2(currSlice->cofu, temp); - //p_Vid->fcf[uv + 1][0][0] = temp[0]; - //p_Vid->fcf[uv + 1][0][4] = temp[1]; - //p_Vid->fcf[uv + 1][4][0] = temp[2]; - //p_Vid->fcf[uv + 1][4][4] = temp[3]; + // p_Vid->fcf[uv + 1][0][0] = temp[0]; + // p_Vid->fcf[uv + 1][0][4] = temp[1]; + // p_Vid->fcf[uv + 1][4][0] = temp[2]; + // p_Vid->fcf[uv + 1][4][4] = temp[3]; - currSlice->cof[uv + 1][0][0] = (((temp[0] * scale_dc)<>5); - currSlice->cof[uv + 1][0][4] = (((temp[1] * scale_dc)<>5); - currSlice->cof[uv + 1][4][0] = (((temp[2] * scale_dc)<>5); - currSlice->cof[uv + 1][4][4] = (((temp[3] * scale_dc)<>5); - } - } + currSlice->cof[uv + 1][0][0] = + (((temp[0] * scale_dc) << qp_per_uv[uv]) >> 5); + currSlice->cof[uv + 1][0][4] = + (((temp[1] * scale_dc) << qp_per_uv[uv]) >> 5); + currSlice->cof[uv + 1][4][0] = + (((temp[2] * scale_dc) << qp_per_uv[uv]) >> 5); + currSlice->cof[uv + 1][4][4] = + (((temp[3] * scale_dc) << qp_per_uv[uv]) >> 5); + } + } } //========================== CHROMA AC ============================ //----------------------------------------------------------------- // chroma AC coeff, all zero fram start_scan - if (cbp >31) - { - currSE.context = CHROMA_AC; - currSE.type = (currMB->is_intra_block ? SE_CHR_AC_INTRA : SE_CHR_AC_INTER); + if (cbp > 31) { + currSE.context = CHROMA_AC; + currSE.type = (currMB->is_intra_block ? SE_CHR_AC_INTRA : SE_CHR_AC_INTER); dP = &(currSlice->partArr[partMap[currSE.type]]); @@ -3781,16 +3673,15 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) else currSE.reading = readRunLevel_CABAC; - if(currMB->is_lossless == FALSE) - { + if (currMB->is_lossless == FALSE) { int b4, b8, uv, k; - for (b8=0; b8 < p_Vid->num_blk8x8_uv; ++b8) - { - currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1 )); - InvLevelScale4x4 = intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; + for (b8 = 0; b8 < p_Vid->num_blk8x8_uv; ++b8) { + currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1)); + InvLevelScale4x4 = + intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] + : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; - for (b4 = 0; b4 < 4; ++b4) - { + for (b4 = 0; b4 < 4; ++b4) { i = cofuv_blk_x[yuv][b8][b4]; j = cofuv_blk_y[yuv][b8][b4]; @@ -3800,8 +3691,7 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) pos_scan_4x4 = pos_scan4x4[1]; level = 1; - for(k = 0; (k < 16) && (level != 0);++k) - { + for (k = 0; (k < 16) && (level != 0); ++k) { #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "AC Chroma "); #endif @@ -3809,67 +3699,61 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) - { + if (level != 0) { currMB->cbp_blk[0] |= i64_power2(cbp_blk_chroma[b8][b4]); pos_scan_4x4 += (currSE.value2 << 1); i0 = *pos_scan_4x4++; j0 = *pos_scan_4x4++; - currSlice->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = rshift_rnd_sf((level * InvLevelScale4x4[j0][i0])<fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; + currSlice->cof[uv + 1][(j << 2) + j0][(i << 2) + i0] = + rshift_rnd_sf( + (level * InvLevelScale4x4[j0][i0]) << qp_per_uv[uv], 4); + // p_Vid->fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; } - } //for(k=0;(k<16)&&(level!=0);++k) + } // for(k=0;(k<16)&&(level!=0);++k) } } - } - else - { + } else { int b4, b8, k; int uv; - for (b8=0; b8 < p_Vid->num_blk8x8_uv; ++b8) - { - currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1 )); + for (b8 = 0; b8 < p_Vid->num_blk8x8_uv; ++b8) { + currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1)); - for (b4=0; b4 < 4; ++b4) - { + for (b4 = 0; b4 < 4; ++b4) { i = cofuv_blk_x[yuv][b8][b4]; j = cofuv_blk_y[yuv][b8][b4]; pos_scan_4x4 = pos_scan4x4[1]; - level=1; + level = 1; currMB->subblock_y = subblk_offset_y[yuv][b8][b4]; currMB->subblock_x = subblk_offset_x[yuv][b8][b4]; - for(k=0;(k<16)&&(level!=0);++k) - { + for (k = 0; (k < 16) && (level != 0); ++k) { #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "AC Chroma "); #endif dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) - { + if (level != 0) { currMB->cbp_blk[0] |= i64_power2(cbp_blk_chroma[b8][b4]); pos_scan_4x4 += (currSE.value2 << 1); i0 = *pos_scan_4x4++; j0 = *pos_scan_4x4++; - currSlice->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; - //p_Vid->fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; + currSlice->cof[uv + 1][(j << 2) + j0][(i << 2) + i0] = level; + // p_Vid->fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; } - } + } } - } - } //for (b4=0; b4 < 4; b4++) - } + } + } // for (b4=0; b4 < 4; b4++) + } } - /*! ************************************************************************ * \brief @@ -3877,8 +3761,7 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_420(Macroblock *currMB) * from the NAL ************************************************************************ */ -static void read_CBP_and_coeffs_from_NAL_CABAC_400(Macroblock *currMB) -{ +static void read_CBP_and_coeffs_from_NAL_CABAC_400(Macroblock *currMB) { int k; int level; int cbp; @@ -3895,31 +3778,30 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_400(Macroblock *currMB) int need_transform_size_flag; - int (*InvLevelScale4x4)[4] = NULL; + int(*InvLevelScale4x4)[4] = NULL; // select scan type - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; - // read CBP if not new intra mode - if (!IS_I16MB (currMB)) - { + if (!IS_I16MB(currMB)) { //===== C B P ===== //--------------------- - currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? SE_CBP_INTRA - : SE_CBP_INTER; + currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? SE_CBP_INTRA + : SE_CBP_INTER; dP = &(currSlice->partArr[partMap[currSE.type]]); - if (dP->bitstream->ei_flag) - { - currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? currSlice->linfo_cbp_intra - : currSlice->linfo_cbp_inter; - } - else - { + if (dP->bitstream->ei_flag) { + currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? currSlice->linfo_cbp_intra + : currSlice->linfo_cbp_inter; + } else { currSE.reading = read_CBP_CABAC; } @@ -3927,151 +3809,140 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_400(Macroblock *currMB) dP->readSyntaxElement(currMB, &currSE, dP); currMB->cbp = cbp = currSE.value1; - //============= Transform size flag for INTER MBs ============= //------------------------------------------------------------- - need_transform_size_flag = (((currMB->mb_type >= 1 && currMB->mb_type <= 3)|| - (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || - (currMB->NoMbPartLessThan8x8Flag)) - && currMB->mb_type != I8MB && currMB->mb_type != I4MB - && (currMB->cbp&15) - && currSlice->Transform8x8Mode); + need_transform_size_flag = + (((currMB->mb_type >= 1 && currMB->mb_type <= 3) || + (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || + (currMB->NoMbPartLessThan8x8Flag)) && + currMB->mb_type != I8MB && currMB->mb_type != I4MB && + (currMB->cbp & 15) && currSlice->Transform8x8Mode); - if (need_transform_size_flag) - { - currSE.type = SE_HEADER; + if (need_transform_size_flag) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); // read CAVLC transform_size_8x8_flag - if (dP->bitstream->ei_flag) - { + if (dP->bitstream->ei_flag) { currSE.len = 1; readSyntaxElement_FLC(&currSE, dP->bitstream); - } - else - { + } else { dP->readSyntaxElement(currMB, &currSE, dP); } - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; } //===== DQUANT ===== //---------------------- // Delta quant only if nonzero coeffs - if (cbp !=0) - { - read_delta_quant(&currSE, dP, currMB, partMap, ((currMB->is_intra_block == FALSE)) ? SE_DELTA_QUANT_INTER : SE_DELTA_QUANT_INTRA); + if (cbp != 0) { + read_delta_quant(&currSE, dP, currMB, partMap, + ((currMB->is_intra_block == FALSE)) + ? SE_DELTA_QUANT_INTER + : SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent ) + if (currSlice->dp_mode) { + if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent) currMB->dpl_flag = 1; - if( intra && currSlice->dpB_NotPresent ) - { + if (intra && currSlice->dpB_NotPresent) { currMB->ei_flag = 1; currMB->dpl_flag = 1; } // check for prediction from neighbours - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + cbp = 0; currMB->cbp = cbp; } } } - } - else // read DC coeffs for new intra modes + } else // read DC coeffs for new intra modes { - cbp = currMB->cbp; + cbp = currMB->cbp; read_delta_quant(&currSE, dP, currMB, partMap, SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if (currSlice->dpB_NotPresent) - { - currMB->ei_flag = 1; + if (currSlice->dp_mode) { + if (currSlice->dpB_NotPresent) { + currMB->ei_flag = 1; currMB->dpl_flag = 1; } - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - currMB->cbp = cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + currMB->cbp = cbp = 0; } } - if (!currMB->dpl_flag) - { + if (!currMB->dpl_flag) { pos_scan_4x4 = pos_scan4x4[0]; { currSE.type = SE_LUM_DC_INTRA; dP = &(currSlice->partArr[partMap[currSE.type]]); - currSE.context = LUMA_16DC; - currSE.type = SE_LUM_DC_INTRA; + currSE.context = LUMA_16DC; + currSE.type = SE_LUM_DC_INTRA; - if (dP->bitstream->ei_flag) - { + if (dP->bitstream->ei_flag) { currSE.mapping = linfo_levrun_inter; - } - else - { + } else { currSE.reading = readRunLevel_CABAC; } - level = 1; // just to get inside the loop + level = 1; // just to get inside the loop - for(k = 0; (k < 17) && (level != 0); ++k) - { + for (k = 0; (k < 17) && (level != 0); ++k) { #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC luma 16x16 "); #endif dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) /* leave if level == 0 */ + if (level != 0) /* leave if level == 0 */ { pos_scan_4x4 += (2 * currSE.value2); i0 = ((*pos_scan_4x4++) << 2); j0 = ((*pos_scan_4x4++) << 2); - currSlice->cof[0][j0][i0] = level;// add new intra DC coeff - //p_Vid->fcf[0][j0][i0] = level;// add new intra DC coeff + currSlice->cof[0][j0][i0] = level; // add new intra DC coeff + // p_Vid->fcf[0][j0][i0] = level;// add new intra DC coeff } } } - if(currMB->is_lossless == FALSE) - itrans_2(currMB, (ColorPlane) currSlice->colour_plane_id);// transform new intra DC + if (currMB->is_lossless == FALSE) + itrans_2( + currMB, + (ColorPlane)currSlice->colour_plane_id); // transform new intra DC } } update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; - qp_rem = p_Vid->qp_rem_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; + qp_per = p_Vid->qp_per_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; + qp_rem = p_Vid->qp_rem_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; //======= Other Modes & CABAC ======== - //------------------------------------ - if (cbp) - { - if(currMB->luma_transform_size_8x8_flag) - { + //------------------------------------ + if (cbp) { + if (currMB->luma_transform_size_8x8_flag) { //======= 8x8 transform size & CABAC ======== - readCompCoeff8x8MB_CABAC (currMB, &currSE, PLANE_Y); + readCompCoeff8x8MB_CABAC(currMB, &currSE, PLANE_Y); + } else { + InvLevelScale4x4 = + intra + ? currSlice + ->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id] + [qp_rem]; + readCompCoeff4x4MB_CABAC(currMB, &currSE, PLANE_Y, InvLevelScale4x4, + qp_per, cbp); } - else - { - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; - readCompCoeff4x4MB_CABAC (currMB, &currSE, PLANE_Y, InvLevelScale4x4, qp_per, cbp); - } - } + } } /*! @@ -4081,8 +3952,7 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_400(Macroblock *currMB) * from the NAL ************************************************************************ */ -static void read_CBP_and_coeffs_from_NAL_CABAC_444(Macroblock *currMB) -{ +static void read_CBP_and_coeffs_from_NAL_CABAC_444(Macroblock *currMB) { int i, k; int level; int cbp; @@ -4095,48 +3965,45 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_444(Macroblock *currMB) int qp_per, qp_rem; VideoParameters *p_Vid = currMB->p_Vid; - int uv; + int uv; int qp_per_uv[2]; int qp_rem_uv[2]; int intra = (currMB->is_intra_block == TRUE); - int need_transform_size_flag; - int (*InvLevelScale4x4)[4] = NULL; + int(*InvLevelScale4x4)[4] = NULL; // select scan type - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; // QPI - //init constants for every chroma qp offset - for (i=0; i<2; ++i) - { - qp_per_uv[i] = p_Vid->qp_per_matrix[ currMB->qp_scaled[i + 1] ]; - qp_rem_uv[i] = p_Vid->qp_rem_matrix[ currMB->qp_scaled[i + 1] ]; + // init constants for every chroma qp offset + for (i = 0; i < 2; ++i) { + qp_per_uv[i] = p_Vid->qp_per_matrix[currMB->qp_scaled[i + 1]]; + qp_rem_uv[i] = p_Vid->qp_rem_matrix[currMB->qp_scaled[i + 1]]; } - // read CBP if not new intra mode - if (!IS_I16MB (currMB)) - { + if (!IS_I16MB(currMB)) { //===== C B P ===== //--------------------- - currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? SE_CBP_INTRA - : SE_CBP_INTER; + currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? SE_CBP_INTRA + : SE_CBP_INTER; dP = &(currSlice->partArr[partMap[currSE.type]]); - if (dP->bitstream->ei_flag) - { - currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? currSlice->linfo_cbp_intra - : currSlice->linfo_cbp_inter; - } - else - { + if (dP->bitstream->ei_flag) { + currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? currSlice->linfo_cbp_intra + : currSlice->linfo_cbp_inter; + } else { currSE.reading = read_CBP_CABAC; } @@ -4144,196 +4011,177 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_444(Macroblock *currMB) dP->readSyntaxElement(currMB, &currSE, dP); currMB->cbp = cbp = currSE.value1; - //============= Transform size flag for INTER MBs ============= //------------------------------------------------------------- - need_transform_size_flag = (((currMB->mb_type >= 1 && currMB->mb_type <= 3)|| - (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || - (currMB->NoMbPartLessThan8x8Flag)) - && currMB->mb_type != I8MB && currMB->mb_type != I4MB - && (currMB->cbp&15) - && currSlice->Transform8x8Mode); + need_transform_size_flag = + (((currMB->mb_type >= 1 && currMB->mb_type <= 3) || + (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || + (currMB->NoMbPartLessThan8x8Flag)) && + currMB->mb_type != I8MB && currMB->mb_type != I4MB && + (currMB->cbp & 15) && currSlice->Transform8x8Mode); - if (need_transform_size_flag) - { - currSE.type = SE_HEADER; + if (need_transform_size_flag) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); // read CAVLC transform_size_8x8_flag - if (dP->bitstream->ei_flag) - { + if (dP->bitstream->ei_flag) { currSE.len = 1; readSyntaxElement_FLC(&currSE, dP->bitstream); - } - else - { + } else { dP->readSyntaxElement(currMB, &currSE, dP); } - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; } //===== DQUANT ===== //---------------------- // Delta quant only if nonzero coeffs - if (cbp !=0) - { - read_delta_quant(&currSE, dP, currMB, partMap, ((currMB->is_intra_block == FALSE)) ? SE_DELTA_QUANT_INTER : SE_DELTA_QUANT_INTRA); + if (cbp != 0) { + read_delta_quant(&currSE, dP, currMB, partMap, + ((currMB->is_intra_block == FALSE)) + ? SE_DELTA_QUANT_INTER + : SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent ) + if (currSlice->dp_mode) { + if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent) currMB->dpl_flag = 1; - if( intra && currSlice->dpB_NotPresent ) - { + if (intra && currSlice->dpB_NotPresent) { currMB->ei_flag = 1; currMB->dpl_flag = 1; } // check for prediction from neighbours - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + cbp = 0; currMB->cbp = cbp; } } } - } - else // read DC coeffs for new intra modes + } else // read DC coeffs for new intra modes { cbp = currMB->cbp; - + read_delta_quant(&currSE, dP, currMB, partMap, SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if (currSlice->dpB_NotPresent) - { - currMB->ei_flag = 1; + if (currSlice->dp_mode) { + if (currSlice->dpB_NotPresent) { + currMB->ei_flag = 1; currMB->dpl_flag = 1; } - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - currMB->cbp = cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + currMB->cbp = cbp = 0; } } - if (!currMB->dpl_flag) - { + if (!currMB->dpl_flag) { pos_scan_4x4 = pos_scan4x4[0]; { currSE.type = SE_LUM_DC_INTRA; dP = &(currSlice->partArr[partMap[currSE.type]]); - currSE.context = LUMA_16DC; - currSE.type = SE_LUM_DC_INTRA; + currSE.context = LUMA_16DC; + currSE.type = SE_LUM_DC_INTRA; - if (dP->bitstream->ei_flag) - { + if (dP->bitstream->ei_flag) { currSE.mapping = linfo_levrun_inter; - } - else - { + } else { currSE.reading = readRunLevel_CABAC; } - level = 1; // just to get inside the loop + level = 1; // just to get inside the loop - for(k = 0; (k < 17) && (level != 0); ++k) - { + for (k = 0; (k < 17) && (level != 0); ++k) { #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC luma 16x16 "); #endif dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) /* leave if level == 0 */ + if (level != 0) /* leave if level == 0 */ { pos_scan_4x4 += (2 * currSE.value2); i0 = ((*pos_scan_4x4++) << 2); j0 = ((*pos_scan_4x4++) << 2); - currSlice->cof[0][j0][i0] = level;// add new intra DC coeff - //p_Vid->fcf[0][j0][i0] = level;// add new intra DC coeff + currSlice->cof[0][j0][i0] = level; // add new intra DC coeff + // p_Vid->fcf[0][j0][i0] = level;// add new intra DC coeff } } } - if(currMB->is_lossless == FALSE) - itrans_2(currMB, (ColorPlane) currSlice->colour_plane_id);// transform new intra DC + if (currMB->is_lossless == FALSE) + itrans_2( + currMB, + (ColorPlane)currSlice->colour_plane_id); // transform new intra DC } } update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; - qp_rem = p_Vid->qp_rem_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; + qp_per = p_Vid->qp_per_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; + qp_rem = p_Vid->qp_rem_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; - //init quant parameters for chroma - for(i=0; i < 2; ++i) - { - qp_per_uv[i] = p_Vid->qp_per_matrix[ currMB->qp_scaled[i + 1] ]; - qp_rem_uv[i] = p_Vid->qp_rem_matrix[ currMB->qp_scaled[i + 1] ]; + // init quant parameters for chroma + for (i = 0; i < 2; ++i) { + qp_per_uv[i] = p_Vid->qp_per_matrix[currMB->qp_scaled[i + 1]]; + qp_rem_uv[i] = p_Vid->qp_rem_matrix[currMB->qp_scaled[i + 1]]; } - - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale4x4 = + intra ? currSlice + ->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; // luma coefficients { //======= Other Modes & CABAC ======== - //------------------------------------ - if (cbp) - { - if(currMB->luma_transform_size_8x8_flag) - { + //------------------------------------ + if (cbp) { + if (currMB->luma_transform_size_8x8_flag) { //======= 8x8 transform size & CABAC ======== - readCompCoeff8x8MB_CABAC (currMB, &currSE, PLANE_Y); - } - else - { - readCompCoeff4x4MB_CABAC (currMB, &currSE, PLANE_Y, InvLevelScale4x4, qp_per, cbp); + readCompCoeff8x8MB_CABAC(currMB, &currSE, PLANE_Y); + } else { + readCompCoeff4x4MB_CABAC(currMB, &currSE, PLANE_Y, InvLevelScale4x4, + qp_per, cbp); } } } - for (uv = 0; uv < 2; ++uv ) - { + for (uv = 0; uv < 2; ++uv) { /*----------------------16x16DC Luma_Add----------------------*/ - if (IS_I16MB (currMB)) // read DC coeffs for new intra modes + if (IS_I16MB(currMB)) // read DC coeffs for new intra modes { - { + { currSE.type = SE_LUM_DC_INTRA; dP = &(currSlice->partArr[partMap[currSE.type]]); - if( (p_Vid->separate_colour_plane_flag != 0) ) - currSE.context = LUMA_16DC; + if ((p_Vid->separate_colour_plane_flag != 0)) + currSE.context = LUMA_16DC; else - currSE.context = (uv==0) ? CB_16DC : CR_16DC; + currSE.context = (uv == 0) ? CB_16DC : CR_16DC; - if (dP->bitstream->ei_flag) - { + if (dP->bitstream->ei_flag) { currSE.mapping = linfo_levrun_inter; - } - else - { + } else { currSE.reading = readRunLevel_CABAC; } coef_ctr = -1; - level = 1; // just to get inside the loop + level = 1; // just to get inside the loop - for(k=0;(k<17) && (level!=0);++k) - { + for (k = 0; (k < 17) && (level != 0); ++k) { #if TRACE if (uv == 0) - snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC Cb 16x16 "); + snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC Cb 16x16 "); else snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC Cr 16x16 "); #endif @@ -4341,50 +4189,53 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_444(Macroblock *currMB) dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) // leave if level == 0 + if (level != 0) // leave if level == 0 { coef_ctr += currSE.value2 + 1; i0 = pos_scan4x4[coef_ctr][0]; j0 = pos_scan4x4[coef_ctr][1]; - currSlice->cof[uv + 1][j0<<2][i0<<2] = level; - //p_Vid->fcf[uv + 1][j0<<2][i0<<2] = level; - } - } //k loop + currSlice->cof[uv + 1][j0 << 2][i0 << 2] = level; + // p_Vid->fcf[uv + 1][j0<<2][i0<<2] = level; + } + } // k loop } // else CAVLC - if(currMB->is_lossless == FALSE) - { - itrans_2(currMB, (ColorPlane) (uv + 1)); // transform new intra DC + if (currMB->is_lossless == FALSE) { + itrans_2(currMB, (ColorPlane)(uv + 1)); // transform new intra DC } - } //IS_I16MB + } // IS_I16MB update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ (currSlice->qp + p_Vid->bitdepth_luma_qp_scale) ]; - qp_rem = p_Vid->qp_rem_matrix[ (currSlice->qp + p_Vid->bitdepth_luma_qp_scale) ]; + qp_per = + p_Vid->qp_per_matrix[(currSlice->qp + p_Vid->bitdepth_luma_qp_scale)]; + qp_rem = + p_Vid->qp_rem_matrix[(currSlice->qp + p_Vid->bitdepth_luma_qp_scale)]; - //init constants for every chroma qp offset - qp_per_uv[uv] = p_Vid->qp_per_matrix[ (currMB->qpc[uv] + p_Vid->bitdepth_chroma_qp_scale) ]; - qp_rem_uv[uv] = p_Vid->qp_rem_matrix[ (currMB->qpc[uv] + p_Vid->bitdepth_chroma_qp_scale) ]; + // init constants for every chroma qp offset + qp_per_uv[uv] = p_Vid->qp_per_matrix[(currMB->qpc[uv] + + p_Vid->bitdepth_chroma_qp_scale)]; + qp_rem_uv[uv] = p_Vid->qp_rem_matrix[(currMB->qpc[uv] + + p_Vid->bitdepth_chroma_qp_scale)]; - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; + InvLevelScale4x4 = + intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] + : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; - { - if (cbp) - { - if(currMB->luma_transform_size_8x8_flag) - { + { + if (cbp) { + if (currMB->luma_transform_size_8x8_flag) { //======= 8x8 transform size & CABAC ======== - readCompCoeff8x8MB_CABAC (currMB, &currSE, (ColorPlane) (PLANE_U + uv)); - } - else //4x4 - { - readCompCoeff4x4MB_CABAC (currMB, &currSE, (ColorPlane) (PLANE_U + uv), InvLevelScale4x4, qp_per_uv[uv], cbp); + readCompCoeff8x8MB_CABAC(currMB, &currSE, (ColorPlane)(PLANE_U + uv)); + } else // 4x4 + { + readCompCoeff4x4MB_CABAC(currMB, &currSE, (ColorPlane)(PLANE_U + uv), + InvLevelScale4x4, qp_per_uv[uv], cbp); } } } - } + } } /*! @@ -4394,9 +4245,8 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_444(Macroblock *currMB) * from the NAL ************************************************************************ */ -static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) -{ - int i,j,k; +static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) { + int i, j, k; int level; int cbp; SyntaxElement currSE; @@ -4409,7 +4259,7 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) int qp_per, qp_rem; VideoParameters *p_Vid = currMB->p_Vid; - int uv; + int uv; int qp_per_uv[2]; int qp_rem_uv[2]; @@ -4422,38 +4272,37 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) int need_transform_size_flag; - int (*InvLevelScale4x4)[4] = NULL; + int(*InvLevelScale4x4)[4] = NULL; // select scan type - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; // QPI - //init constants for every chroma qp offset - for (i=0; i<2; ++i) - { - qp_per_uv[i] = p_Vid->qp_per_matrix[ currMB->qp_scaled[i + 1] ]; - qp_rem_uv[i] = p_Vid->qp_rem_matrix[ currMB->qp_scaled[i + 1] ]; + // init constants for every chroma qp offset + for (i = 0; i < 2; ++i) { + qp_per_uv[i] = p_Vid->qp_per_matrix[currMB->qp_scaled[i + 1]]; + qp_rem_uv[i] = p_Vid->qp_rem_matrix[currMB->qp_scaled[i + 1]]; } // read CBP if not new intra mode - if (!IS_I16MB (currMB)) - { + if (!IS_I16MB(currMB)) { //===== C B P ===== //--------------------- - currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? SE_CBP_INTRA - : SE_CBP_INTER; + currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? SE_CBP_INTRA + : SE_CBP_INTER; dP = &(currSlice->partArr[partMap[currSE.type]]); - if (dP->bitstream->ei_flag) - { - currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? currSlice->linfo_cbp_intra - : currSlice->linfo_cbp_inter; - } - else - { + if (dP->bitstream->ei_flag) { + currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? currSlice->linfo_cbp_intra + : currSlice->linfo_cbp_inter; + } else { currSE.reading = read_CBP_CABAC; } @@ -4461,160 +4310,147 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) dP->readSyntaxElement(currMB, &currSE, dP); currMB->cbp = cbp = currSE.value1; - //============= Transform size flag for INTER MBs ============= //------------------------------------------------------------- - need_transform_size_flag = (((currMB->mb_type >= 1 && currMB->mb_type <= 3)|| - (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || - (currMB->NoMbPartLessThan8x8Flag)) - && currMB->mb_type != I8MB && currMB->mb_type != I4MB - && (currMB->cbp&15) - && currSlice->Transform8x8Mode); + need_transform_size_flag = + (((currMB->mb_type >= 1 && currMB->mb_type <= 3) || + (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || + (currMB->NoMbPartLessThan8x8Flag)) && + currMB->mb_type != I8MB && currMB->mb_type != I4MB && + (currMB->cbp & 15) && currSlice->Transform8x8Mode); - if (need_transform_size_flag) - { - currSE.type = SE_HEADER; + if (need_transform_size_flag) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); // read CAVLC transform_size_8x8_flag - if (dP->bitstream->ei_flag) - { + if (dP->bitstream->ei_flag) { currSE.len = 1; readSyntaxElement_FLC(&currSE, dP->bitstream); - } - else - { + } else { dP->readSyntaxElement(currMB, &currSE, dP); } - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; } //===== DQUANT ===== //---------------------- // Delta quant only if nonzero coeffs - if (cbp !=0) - { - read_delta_quant(&currSE, dP, currMB, partMap, ((currMB->is_intra_block == FALSE)) ? SE_DELTA_QUANT_INTER : SE_DELTA_QUANT_INTRA); + if (cbp != 0) { + read_delta_quant(&currSE, dP, currMB, partMap, + ((currMB->is_intra_block == FALSE)) + ? SE_DELTA_QUANT_INTER + : SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent ) + if (currSlice->dp_mode) { + if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent) currMB->dpl_flag = 1; - if( intra && currSlice->dpB_NotPresent ) - { + if (intra && currSlice->dpB_NotPresent) { currMB->ei_flag = 1; currMB->dpl_flag = 1; } // check for prediction from neighbours - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + cbp = 0; currMB->cbp = cbp; } } } - } - else // read DC coeffs for new intra modes + } else // read DC coeffs for new intra modes { cbp = currMB->cbp; - + read_delta_quant(&currSE, dP, currMB, partMap, SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if (currSlice->dpB_NotPresent) - { - currMB->ei_flag = 1; + if (currSlice->dp_mode) { + if (currSlice->dpB_NotPresent) { + currMB->ei_flag = 1; currMB->dpl_flag = 1; } - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - currMB->cbp = cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + currMB->cbp = cbp = 0; } } - if (!currMB->dpl_flag) - { + if (!currMB->dpl_flag) { pos_scan_4x4 = pos_scan4x4[0]; { currSE.type = SE_LUM_DC_INTRA; dP = &(currSlice->partArr[partMap[currSE.type]]); - currSE.context = LUMA_16DC; - currSE.type = SE_LUM_DC_INTRA; + currSE.context = LUMA_16DC; + currSE.type = SE_LUM_DC_INTRA; - if (dP->bitstream->ei_flag) - { + if (dP->bitstream->ei_flag) { currSE.mapping = linfo_levrun_inter; - } - else - { + } else { currSE.reading = readRunLevel_CABAC; } - level = 1; // just to get inside the loop + level = 1; // just to get inside the loop - for(k = 0; (k < 17) && (level != 0); ++k) - { + for (k = 0; (k < 17) && (level != 0); ++k) { #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "DC luma 16x16 "); #endif dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) /* leave if level == 0 */ + if (level != 0) /* leave if level == 0 */ { pos_scan_4x4 += (2 * currSE.value2); i0 = ((*pos_scan_4x4++) << 2); j0 = ((*pos_scan_4x4++) << 2); - currSlice->cof[0][j0][i0] = level;// add new intra DC coeff - //p_Vid->fcf[0][j0][i0] = level;// add new intra DC coeff + currSlice->cof[0][j0][i0] = level; // add new intra DC coeff + // p_Vid->fcf[0][j0][i0] = level;// add new intra DC coeff } } } - if(currMB->is_lossless == FALSE) - itrans_2(currMB, (ColorPlane) currSlice->colour_plane_id);// transform new intra DC + if (currMB->is_lossless == FALSE) + itrans_2( + currMB, + (ColorPlane)currSlice->colour_plane_id); // transform new intra DC } } update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; - qp_rem = p_Vid->qp_rem_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; + qp_per = p_Vid->qp_per_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; + qp_rem = p_Vid->qp_rem_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; - //init quant parameters for chroma - for(i=0; i < 2; ++i) - { - qp_per_uv[i] = p_Vid->qp_per_matrix[ currMB->qp_scaled[i + 1] ]; - qp_rem_uv[i] = p_Vid->qp_rem_matrix[ currMB->qp_scaled[i + 1] ]; + // init quant parameters for chroma + for (i = 0; i < 2; ++i) { + qp_per_uv[i] = p_Vid->qp_per_matrix[currMB->qp_scaled[i + 1]]; + qp_rem_uv[i] = p_Vid->qp_rem_matrix[currMB->qp_scaled[i + 1]]; } - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale4x4 = + intra ? currSlice + ->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; // luma coefficients { //======= Other Modes & CABAC ======== - //------------------------------------ - if (cbp) - { - if(currMB->luma_transform_size_8x8_flag) - { + //------------------------------------ + if (cbp) { + if (currMB->luma_transform_size_8x8_flag) { //======= 8x8 transform size & CABAC ======== - readCompCoeff8x8MB_CABAC (currMB, &currSE, PLANE_Y); - } - else - { - readCompCoeff4x4MB_CABAC (currMB, &currSE, PLANE_Y, InvLevelScale4x4, qp_per, cbp); + readCompCoeff8x8MB_CABAC(currMB, &currSE, PLANE_Y); + } else { + readCompCoeff4x4MB_CABAC(currMB, &currSE, PLANE_Y, InvLevelScale4x4, + qp_per, cbp); } } } @@ -4622,33 +4458,36 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) //========================== CHROMA DC ============================ //----------------------------------------------------------------- // chroma DC coeff - if(cbp>15) - { - for (ll=0;ll<3;ll+=2) - { - int (*InvLevelScale4x4)[4] = NULL; - uv = ll>>1; + if (cbp > 15) { + for (ll = 0; ll < 3; ll += 2) { + int(*InvLevelScale4x4)[4] = NULL; + uv = ll >> 1; { int **imgcof = currSlice->cof[uv + 1]; - int m3[2][4] = {{0,0,0,0},{0,0,0,0}}; - int m4[2][4] = {{0,0,0,0},{0,0,0,0}}; - int qp_per_uv_dc = p_Vid->qp_per_matrix[ (currMB->qpc[uv] + 3 + p_Vid->bitdepth_chroma_qp_scale) ]; //for YUV422 only - int qp_rem_uv_dc = p_Vid->qp_rem_matrix[ (currMB->qpc[uv] + 3 + p_Vid->bitdepth_chroma_qp_scale) ]; //for YUV422 only + int m3[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; + int m4[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; + int qp_per_uv_dc = p_Vid->qp_per_matrix[( + currMB->qpc[uv] + 3 + + p_Vid->bitdepth_chroma_qp_scale)]; // for YUV422 only + int qp_rem_uv_dc = p_Vid->qp_rem_matrix[( + currMB->qpc[uv] + 3 + + p_Vid->bitdepth_chroma_qp_scale)]; // for YUV422 only if (intra) - InvLevelScale4x4 = currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv_dc]; - else - InvLevelScale4x4 = currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv_dc]; - + InvLevelScale4x4 = + currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv_dc]; + else + InvLevelScale4x4 = + currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv_dc]; //===================== CHROMA DC YUV422 ====================== { - coef_ctr=-1; - level=1; - for(k=0;(k<9)&&(level!=0);++k) - { - currSE.context = CHROMA_DC_2x4; - currSE.type = ((currMB->is_intra_block == TRUE) ? SE_CHR_DC_INTRA : SE_CHR_DC_INTER); - currMB->is_v_block = ll; + coef_ctr = -1; + level = 1; + for (k = 0; (k < 9) && (level != 0); ++k) { + currSE.context = CHROMA_DC_2x4; + currSE.type = ((currMB->is_intra_block == TRUE) ? SE_CHR_DC_INTRA + : SE_CHR_DC_INTER); + currMB->is_v_block = ll; #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "2x4 DC Chroma "); @@ -4664,22 +4503,20 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) level = currSE.value1; - if (level != 0) - { - currMB->cbp_blk[0] |= ((int64)0xff0000) << (ll<<2) ; + if (level != 0) { + currMB->cbp_blk[0] |= ((int64)0xff0000) << (ll << 2); coef_ctr += currSE.value2 + 1; - assert (coef_ctr < p_Vid->num_cdc_coeff); - i0=SCAN_YUV422[coef_ctr][0]; - j0=SCAN_YUV422[coef_ctr][1]; + assert(coef_ctr < p_Vid->num_cdc_coeff); + i0 = SCAN_YUV422[coef_ctr][0]; + j0 = SCAN_YUV422[coef_ctr][1]; - m3[i0][j0]=level; + m3[i0][j0] = level; } } } // inverse CHROMA DC YUV422 transform // horizontal - if(currMB->is_lossless == FALSE) - { + if (currMB->is_lossless == FALSE) { m4[0][0] = m3[0][0] + m3[1][0]; m4[0][1] = m3[0][1] + m3[1][1]; m4[0][2] = m3[0][2] + m3[1][2]; @@ -4690,54 +4527,45 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) m4[1][2] = m3[0][2] - m3[1][2]; m4[1][3] = m3[0][3] - m3[1][3]; - for (i = 0; i < 2; ++i) - { + for (i = 0; i < 2; ++i) { m6[0] = m4[i][0] + m4[i][2]; m6[1] = m4[i][0] - m4[i][2]; m6[2] = m4[i][1] - m4[i][3]; m6[3] = m4[i][1] + m4[i][3]; - imgcof[ 0][i<<2] = m6[0] + m6[3]; - imgcof[ 4][i<<2] = m6[1] + m6[2]; - imgcof[ 8][i<<2] = m6[1] - m6[2]; - imgcof[12][i<<2] = m6[0] - m6[3]; - }//for (i=0;i<2;++i) + imgcof[0][i << 2] = m6[0] + m6[3]; + imgcof[4][i << 2] = m6[1] + m6[2]; + imgcof[8][i << 2] = m6[1] - m6[2]; + imgcof[12][i << 2] = m6[0] - m6[3]; + } // for (i=0;i<2;++i) - for(j = 0;j < p_Vid->mb_cr_size_y; j += BLOCK_SIZE) - { - for(i=0;i < p_Vid->mb_cr_size_x;i+=BLOCK_SIZE) - { - imgcof[j][i] = rshift_rnd_sf((imgcof[j][i] * InvLevelScale4x4[0][0]) << qp_per_uv_dc, 6); + for (j = 0; j < p_Vid->mb_cr_size_y; j += BLOCK_SIZE) { + for (i = 0; i < p_Vid->mb_cr_size_x; i += BLOCK_SIZE) { + imgcof[j][i] = rshift_rnd_sf( + (imgcof[j][i] * InvLevelScale4x4[0][0]) << qp_per_uv_dc, 6); + } + } + } else { + for (j = 0; j < 4; ++j) { + for (i = 0; i < 2; ++i) { + currSlice->cof[uv + 1][j << 2][i << 2] = m3[i][j]; + // p_Vid->fcf[uv + 1][j<<2][i<<2] = m3[i][j]; } } } - else - { - for(j=0;j<4;++j) - { - for(i=0;i<2;++i) - { - currSlice->cof[uv + 1][j<<2][i<<2] = m3[i][j]; - //p_Vid->fcf[uv + 1][j<<2][i<<2] = m3[i][j]; - } - } - } - } - }//for (ll=0;ll<3;ll+=2) + } // for (ll=0;ll<3;ll+=2) } //========================== CHROMA AC ============================ //----------------------------------------------------------------- // chroma AC coeff, all zero fram start_scan - if (cbp<=31) - { - } - else - { + if (cbp <= 31) { + } else { { - currSE.context = CHROMA_AC; - currSE.type = (currMB->is_intra_block ? SE_CHR_AC_INTRA : SE_CHR_AC_INTER); + currSE.context = CHROMA_AC; + currSE.type = + (currMB->is_intra_block ? SE_CHR_AC_INTRA : SE_CHR_AC_INTER); dP = &(currSlice->partArr[partMap[currSE.type]]); @@ -4746,15 +4574,14 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) else currSE.reading = readRunLevel_CABAC; - if(currMB->is_lossless == FALSE) - { - for (b8=0; b8 < p_Vid->num_blk8x8_uv; ++b8) - { - currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1 )); - InvLevelScale4x4 = intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; + if (currMB->is_lossless == FALSE) { + for (b8 = 0; b8 < p_Vid->num_blk8x8_uv; ++b8) { + currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1)); + InvLevelScale4x4 = + intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] + : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; - for (b4 = 0; b4 < 4; ++b4) - { + for (b4 = 0; b4 < 4; ++b4) { i = cofuv_blk_x[yuv][b8][b4]; j = cofuv_blk_y[yuv][b8][b4]; @@ -4762,10 +4589,9 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) currMB->subblock_x = subblk_offset_x[yuv][b8][b4]; pos_scan_4x4 = pos_scan4x4[1]; - level=1; + level = 1; - for(k = 0; (k < 16) && (level != 0);++k) - { + for (k = 0; (k < 16) && (level != 0); ++k) { #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "AC Chroma "); #endif @@ -4773,63 +4599,58 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) - { + if (level != 0) { currMB->cbp_blk[0] |= i64_power2(cbp_blk_chroma[b8][b4]); pos_scan_4x4 += (currSE.value2 << 1); i0 = *pos_scan_4x4++; j0 = *pos_scan_4x4++; - currSlice->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = rshift_rnd_sf((level * InvLevelScale4x4[j0][i0])<fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; + currSlice->cof[uv + 1][(j << 2) + j0][(i << 2) + i0] = + rshift_rnd_sf( + (level * InvLevelScale4x4[j0][i0]) << qp_per_uv[uv], 4); + // p_Vid->fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; } - } //for(k=0;(k<16)&&(level!=0);++k) + } // for(k=0;(k<16)&&(level!=0);++k) } } - } - else - { - for (b8=0; b8 < p_Vid->num_blk8x8_uv; ++b8) - { - currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1 )); + } else { + for (b8 = 0; b8 < p_Vid->num_blk8x8_uv; ++b8) { + currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1)); - for (b4=0; b4 < 4; ++b4) - { + for (b4 = 0; b4 < 4; ++b4) { i = cofuv_blk_x[yuv][b8][b4]; j = cofuv_blk_y[yuv][b8][b4]; pos_scan_4x4 = pos_scan4x4[1]; - level=1; + level = 1; currMB->subblock_y = subblk_offset_y[yuv][b8][b4]; currMB->subblock_x = subblk_offset_x[yuv][b8][b4]; - for(k=0;(k<16)&&(level!=0);++k) - { + for (k = 0; (k < 16) && (level != 0); ++k) { #if TRACE snprintf(currSE.tracestring, TRACESTRING_SIZE, "AC Chroma "); #endif dP->readSyntaxElement(currMB, &currSE, dP); level = currSE.value1; - if (level != 0) - { + if (level != 0) { currMB->cbp_blk[0] |= i64_power2(cbp_blk_chroma[b8][b4]); pos_scan_4x4 += (currSE.value2 << 1); i0 = *pos_scan_4x4++; j0 = *pos_scan_4x4++; - currSlice->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; - //p_Vid->fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; + currSlice->cof[uv + 1][(j << 2) + j0][(i << 2) + i0] = level; + // p_Vid->fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = level; } - } + } } - } - } //for (b4=0; b4 < 4; b4++) - } //for (b8=0; b8 < p_Vid->num_blk8x8_uv; b8++) - } //if (dec_picture->chroma_format_idc != YUV400) + } + } // for (b4=0; b4 < 4; b4++) + } // for (b8=0; b8 < p_Vid->num_blk8x8_uv; b8++) + } // if (dec_picture->chroma_format_idc != YUV400) } /*! @@ -4839,8 +4660,7 @@ static void read_CBP_and_coeffs_from_NAL_CABAC_422(Macroblock *currMB) * from the NAL ************************************************************************ */ -static void read_CBP_and_coeffs_from_NAL_CAVLC_400(Macroblock *currMB) -{ +static void read_CBP_and_coeffs_from_NAL_CAVLC_400(Macroblock *currMB) { int k; int mb_nr = currMB->mbAddrX; int cbp; @@ -4859,45 +4679,45 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_400(Macroblock *currMB) int need_transform_size_flag; - int (*InvLevelScale4x4)[4] = NULL; - int (*InvLevelScale8x8)[8] = NULL; + int(*InvLevelScale4x4)[4] = NULL; + int(*InvLevelScale8x8)[8] = NULL; // select scan type - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; - // read CBP if not new intra mode - if (!IS_I16MB (currMB)) - { + if (!IS_I16MB(currMB)) { //===== C B P ===== //--------------------- - currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? SE_CBP_INTRA - : SE_CBP_INTER; + currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? SE_CBP_INTRA + : SE_CBP_INTER; dP = &(currSlice->partArr[partMap[currSE.type]]); - currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? currSlice->linfo_cbp_intra - : currSlice->linfo_cbp_inter; + currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? currSlice->linfo_cbp_intra + : currSlice->linfo_cbp_inter; TRACE_STRING("coded_block_pattern"); dP->readSyntaxElement(currMB, &currSE, dP); currMB->cbp = cbp = currSE.value1; - //============= Transform size flag for INTER MBs ============= //------------------------------------------------------------- - need_transform_size_flag = (((currMB->mb_type >= 1 && currMB->mb_type <= 3)|| - (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || - (currMB->NoMbPartLessThan8x8Flag)) - && currMB->mb_type != I8MB && currMB->mb_type != I4MB - && (currMB->cbp&15) - && currSlice->Transform8x8Mode); + need_transform_size_flag = + (((currMB->mb_type >= 1 && currMB->mb_type <= 3) || + (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || + (currMB->NoMbPartLessThan8x8Flag)) && + currMB->mb_type != I8MB && currMB->mb_type != I4MB && + (currMB->cbp & 15) && currSlice->Transform8x8Mode); - if (need_transform_size_flag) - { - currSE.type = SE_HEADER; + if (need_transform_size_flag) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); @@ -4906,105 +4726,106 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_400(Macroblock *currMB) currSE.len = 1; readSyntaxElement_FLC(&currSE, dP->bitstream); - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; } //===== DQUANT ===== //---------------------- // Delta quant only if nonzero coeffs - if (cbp !=0) - { - read_delta_quant(&currSE, dP, currMB, partMap, ((currMB->is_intra_block == FALSE)) ? SE_DELTA_QUANT_INTER : SE_DELTA_QUANT_INTRA); + if (cbp != 0) { + read_delta_quant(&currSE, dP, currMB, partMap, + ((currMB->is_intra_block == FALSE)) + ? SE_DELTA_QUANT_INTER + : SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent ) + if (currSlice->dp_mode) { + if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent) currMB->dpl_flag = 1; - if( intra && currSlice->dpB_NotPresent ) - { + if (intra && currSlice->dpB_NotPresent) { currMB->ei_flag = 1; currMB->dpl_flag = 1; } // check for prediction from neighbours - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + cbp = 0; currMB->cbp = cbp; } } } - } - else // read DC coeffs for new intra modes + } else // read DC coeffs for new intra modes { cbp = currMB->cbp; - + read_delta_quant(&currSE, dP, currMB, partMap, SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if (currSlice->dpB_NotPresent) - { - currMB->ei_flag = 1; + if (currSlice->dp_mode) { + if (currSlice->dpB_NotPresent) { + currMB->ei_flag = 1; currMB->dpl_flag = 1; } - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - currMB->cbp = cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + currMB->cbp = cbp = 0; } } - if (!currMB->dpl_flag) - { + if (!currMB->dpl_flag) { pos_scan_4x4 = pos_scan4x4[0]; - readCoeff4x4_CAVLC(currMB, LUMA_INTRA16x16DC, 0, 0, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, LUMA_INTRA16x16DC, 0, 0, levarr, runarr, + &numcoeff); - for(k = 0; k < numcoeff; ++k) - { - if (levarr[k] != 0) // leave if level == 0 + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) // leave if level == 0 { pos_scan_4x4 += 2 * runarr[k]; i0 = ((*pos_scan_4x4++) << 2); j0 = ((*pos_scan_4x4++) << 2); - currSlice->cof[0][j0][i0] = levarr[k];// add new intra DC coeff - //p_Vid->fcf[0][j0][i0] = levarr[k];// add new intra DC coeff + currSlice->cof[0][j0][i0] = levarr[k]; // add new intra DC coeff + // p_Vid->fcf[0][j0][i0] = levarr[k];// add new intra DC coeff } } - - if(currMB->is_lossless == FALSE) - itrans_2(currMB, (ColorPlane) currSlice->colour_plane_id);// transform new intra DC + if (currMB->is_lossless == FALSE) + itrans_2( + currMB, + (ColorPlane)currSlice->colour_plane_id); // transform new intra DC } } update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; - qp_rem = p_Vid->qp_rem_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; + qp_per = p_Vid->qp_per_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; + qp_rem = p_Vid->qp_rem_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; - InvLevelScale8x8 = intra? currSlice->InvLevelScale8x8_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale8x8_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale4x4 = + intra ? currSlice + ->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale8x8 = + intra ? currSlice + ->InvLevelScale8x8_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale8x8_Inter[currSlice->colour_plane_id][qp_rem]; // luma coefficients - if (cbp) - { + if (cbp) { if (!currMB->luma_transform_size_8x8_flag) // 4x4 transform { - readCompCoeff4x4MB_CAVLC (currMB, PLANE_Y, InvLevelScale4x4, qp_per, cbp, p_Vid->nz_coeff[mb_nr][PLANE_Y]); - } - else // 8x8 transform + readCompCoeff4x4MB_CAVLC(currMB, PLANE_Y, InvLevelScale4x4, qp_per, cbp, + p_Vid->nz_coeff[mb_nr][PLANE_Y]); + } else // 8x8 transform { - readCompCoeff8x8MB_CAVLC (currMB, PLANE_Y, InvLevelScale8x8, qp_per, cbp, p_Vid->nz_coeff[mb_nr][PLANE_Y]); + readCompCoeff8x8MB_CAVLC(currMB, PLANE_Y, InvLevelScale8x8, qp_per, cbp, + p_Vid->nz_coeff[mb_nr][PLANE_Y]); } - } - else - { + } else { fast_memset(p_Vid->nz_coeff[mb_nr][0][0], 0, BLOCK_PIXELS * sizeof(byte)); } } @@ -5016,9 +4837,8 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_400(Macroblock *currMB) * from the NAL ************************************************************************ */ -static void read_CBP_and_coeffs_from_NAL_CAVLC_422(Macroblock *currMB) -{ - int i,j,k; +static void read_CBP_and_coeffs_from_NAL_CAVLC_422(Macroblock *currMB) { + int i, j, k; int level; int mb_nr = currMB->mbAddrX; int cbp; @@ -5033,7 +4853,7 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_422(Macroblock *currMB) int qp_per, qp_rem; VideoParameters *p_Vid = currMB->p_Vid; - int uv; + int uv; int qp_per_uv[2]; int qp_rem_uv[2]; @@ -5046,45 +4866,45 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_422(Macroblock *currMB) int need_transform_size_flag; - int (*InvLevelScale4x4)[4] = NULL; - int (*InvLevelScale8x8)[8] = NULL; + int(*InvLevelScale4x4)[4] = NULL; + int(*InvLevelScale8x8)[8] = NULL; // select scan type - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; - // read CBP if not new intra mode - if (!IS_I16MB (currMB)) - { + if (!IS_I16MB(currMB)) { //===== C B P ===== //--------------------- - currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? SE_CBP_INTRA - : SE_CBP_INTER; + currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? SE_CBP_INTRA + : SE_CBP_INTER; dP = &(currSlice->partArr[partMap[currSE.type]]); - currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? currSlice->linfo_cbp_intra - : currSlice->linfo_cbp_inter; + currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? currSlice->linfo_cbp_intra + : currSlice->linfo_cbp_inter; TRACE_STRING("coded_block_pattern"); dP->readSyntaxElement(currMB, &currSE, dP); currMB->cbp = cbp = currSE.value1; - //============= Transform size flag for INTER MBs ============= //------------------------------------------------------------- - need_transform_size_flag = (((currMB->mb_type >= 1 && currMB->mb_type <= 3)|| - (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || - (currMB->NoMbPartLessThan8x8Flag)) - && currMB->mb_type != I8MB && currMB->mb_type != I4MB - && (currMB->cbp&15) - && currSlice->Transform8x8Mode); + need_transform_size_flag = + (((currMB->mb_type >= 1 && currMB->mb_type <= 3) || + (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || + (currMB->NoMbPartLessThan8x8Flag)) && + currMB->mb_type != I8MB && currMB->mb_type != I4MB && + (currMB->cbp & 15) && currSlice->Transform8x8Mode); - if (need_transform_size_flag) - { - currSE.type = SE_HEADER; + if (need_transform_size_flag) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); @@ -5093,157 +4913,157 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_422(Macroblock *currMB) currSE.len = 1; readSyntaxElement_FLC(&currSE, dP->bitstream); - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; } //===== DQUANT ===== //---------------------- // Delta quant only if nonzero coeffs - if (cbp !=0) - { - read_delta_quant(&currSE, dP, currMB, partMap, ((currMB->is_intra_block == FALSE)) ? SE_DELTA_QUANT_INTER : SE_DELTA_QUANT_INTRA); + if (cbp != 0) { + read_delta_quant(&currSE, dP, currMB, partMap, + ((currMB->is_intra_block == FALSE)) + ? SE_DELTA_QUANT_INTER + : SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent ) + if (currSlice->dp_mode) { + if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent) currMB->dpl_flag = 1; - if( intra && currSlice->dpB_NotPresent ) - { + if (intra && currSlice->dpB_NotPresent) { currMB->ei_flag = 1; currMB->dpl_flag = 1; } // check for prediction from neighbours - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + cbp = 0; currMB->cbp = cbp; } } } - } - else // read DC coeffs for new intra modes + } else // read DC coeffs for new intra modes { cbp = currMB->cbp; read_delta_quant(&currSE, dP, currMB, partMap, SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if (currSlice->dpB_NotPresent) - { - currMB->ei_flag = 1; + if (currSlice->dp_mode) { + if (currSlice->dpB_NotPresent) { + currMB->ei_flag = 1; currMB->dpl_flag = 1; } - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - currMB->cbp = cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + currMB->cbp = cbp = 0; } } - if (!currMB->dpl_flag) - { + if (!currMB->dpl_flag) { pos_scan_4x4 = pos_scan4x4[0]; - readCoeff4x4_CAVLC(currMB, LUMA_INTRA16x16DC, 0, 0, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, LUMA_INTRA16x16DC, 0, 0, levarr, runarr, + &numcoeff); - for(k = 0; k < numcoeff; ++k) - { - if (levarr[k] != 0) // leave if level == 0 + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) // leave if level == 0 { pos_scan_4x4 += 2 * runarr[k]; i0 = ((*pos_scan_4x4++) << 2); j0 = ((*pos_scan_4x4++) << 2); - currSlice->cof[0][j0][i0] = levarr[k];// add new intra DC coeff - //p_Vid->fcf[0][j0][i0] = levarr[k];// add new intra DC coeff + currSlice->cof[0][j0][i0] = levarr[k]; // add new intra DC coeff + // p_Vid->fcf[0][j0][i0] = levarr[k];// add new intra DC coeff } } - - if(currMB->is_lossless == FALSE) - itrans_2(currMB, (ColorPlane) currSlice->colour_plane_id);// transform new intra DC + if (currMB->is_lossless == FALSE) + itrans_2( + currMB, + (ColorPlane)currSlice->colour_plane_id); // transform new intra DC } } update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; - qp_rem = p_Vid->qp_rem_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; + qp_per = p_Vid->qp_per_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; + qp_rem = p_Vid->qp_rem_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; - //init quant parameters for chroma - for(i=0; i < 2; ++i) - { - qp_per_uv[i] = p_Vid->qp_per_matrix[ currMB->qp_scaled[i + 1] ]; - qp_rem_uv[i] = p_Vid->qp_rem_matrix[ currMB->qp_scaled[i + 1] ]; + // init quant parameters for chroma + for (i = 0; i < 2; ++i) { + qp_per_uv[i] = p_Vid->qp_per_matrix[currMB->qp_scaled[i + 1]]; + qp_rem_uv[i] = p_Vid->qp_rem_matrix[currMB->qp_scaled[i + 1]]; } - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; - InvLevelScale8x8 = intra? currSlice->InvLevelScale8x8_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale8x8_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale4x4 = + intra ? currSlice + ->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale8x8 = + intra ? currSlice + ->InvLevelScale8x8_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale8x8_Inter[currSlice->colour_plane_id][qp_rem]; // luma coefficients - if (cbp) - { + if (cbp) { if (!currMB->luma_transform_size_8x8_flag) // 4x4 transform { - readCompCoeff4x4MB_CAVLC (currMB, PLANE_Y, InvLevelScale4x4, qp_per, cbp, p_Vid->nz_coeff[mb_nr][PLANE_Y]); - } - else // 8x8 transform + readCompCoeff4x4MB_CAVLC(currMB, PLANE_Y, InvLevelScale4x4, qp_per, cbp, + p_Vid->nz_coeff[mb_nr][PLANE_Y]); + } else // 8x8 transform { - readCompCoeff8x8MB_CAVLC (currMB, PLANE_Y, InvLevelScale8x8, qp_per, cbp, p_Vid->nz_coeff[mb_nr][PLANE_Y]); + readCompCoeff8x8MB_CAVLC(currMB, PLANE_Y, InvLevelScale8x8, qp_per, cbp, + p_Vid->nz_coeff[mb_nr][PLANE_Y]); } - } - else - { + } else { fast_memset(p_Vid->nz_coeff[mb_nr][0][0], 0, BLOCK_PIXELS * sizeof(byte)); } //========================== CHROMA DC ============================ //----------------------------------------------------------------- // chroma DC coeff - if(cbp>15) - { - for (ll=0;ll<3;ll+=2) - { - int (*InvLevelScale4x4)[4] = NULL; - uv = ll>>1; + if (cbp > 15) { + for (ll = 0; ll < 3; ll += 2) { + int(*InvLevelScale4x4)[4] = NULL; + uv = ll >> 1; { int **imgcof = currSlice->cof[uv + 1]; - int m3[2][4] = {{0,0,0,0},{0,0,0,0}}; - int m4[2][4] = {{0,0,0,0},{0,0,0,0}}; - int qp_per_uv_dc = p_Vid->qp_per_matrix[ (currMB->qpc[uv] + 3 + p_Vid->bitdepth_chroma_qp_scale) ]; //for YUV422 only - int qp_rem_uv_dc = p_Vid->qp_rem_matrix[ (currMB->qpc[uv] + 3 + p_Vid->bitdepth_chroma_qp_scale) ]; //for YUV422 only + int m3[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; + int m4[2][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; + int qp_per_uv_dc = p_Vid->qp_per_matrix[( + currMB->qpc[uv] + 3 + + p_Vid->bitdepth_chroma_qp_scale)]; // for YUV422 only + int qp_rem_uv_dc = p_Vid->qp_rem_matrix[( + currMB->qpc[uv] + 3 + + p_Vid->bitdepth_chroma_qp_scale)]; // for YUV422 only if (intra) - InvLevelScale4x4 = currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv_dc]; - else - InvLevelScale4x4 = currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv_dc]; - + InvLevelScale4x4 = + currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv_dc]; + else + InvLevelScale4x4 = + currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv_dc]; //===================== CHROMA DC YUV422 ====================== readCoeff4x4_CAVLC(currMB, CHROMA_DC, 0, 0, levarr, runarr, &numcoeff); - coef_ctr=-1; - level=1; - for(k = 0; k < numcoeff; ++k) - { - if (levarr[k] != 0) - { - currMB->cbp_blk[0] |= ((int64)0xff0000) << (ll<<2); - coef_ctr += runarr[k]+1; + coef_ctr = -1; + level = 1; + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) { + currMB->cbp_blk[0] |= ((int64)0xff0000) << (ll << 2); + coef_ctr += runarr[k] + 1; i0 = SCAN_YUV422[coef_ctr][0]; j0 = SCAN_YUV422[coef_ctr][1]; - m3[i0][j0]=levarr[k]; + m3[i0][j0] = levarr[k]; } } // inverse CHROMA DC YUV422 transform // horizontal - if(currMB->is_lossless == FALSE) - { + if (currMB->is_lossless == FALSE) { m4[0][0] = m3[0][0] + m3[1][0]; m4[0][1] = m3[0][1] + m3[1][1]; m4[0][2] = m3[0][2] + m3[1][2]; @@ -5254,112 +5074,100 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_422(Macroblock *currMB) m4[1][2] = m3[0][2] - m3[1][2]; m4[1][3] = m3[0][3] - m3[1][3]; - for (i = 0; i < 2; ++i) - { + for (i = 0; i < 2; ++i) { m6[0] = m4[i][0] + m4[i][2]; m6[1] = m4[i][0] - m4[i][2]; m6[2] = m4[i][1] - m4[i][3]; m6[3] = m4[i][1] + m4[i][3]; - imgcof[ 0][i<<2] = m6[0] + m6[3]; - imgcof[ 4][i<<2] = m6[1] + m6[2]; - imgcof[ 8][i<<2] = m6[1] - m6[2]; - imgcof[12][i<<2] = m6[0] - m6[3]; - }//for (i=0;i<2;++i) + imgcof[0][i << 2] = m6[0] + m6[3]; + imgcof[4][i << 2] = m6[1] + m6[2]; + imgcof[8][i << 2] = m6[1] - m6[2]; + imgcof[12][i << 2] = m6[0] - m6[3]; + } // for (i=0;i<2;++i) - for(j = 0;j < p_Vid->mb_cr_size_y; j += BLOCK_SIZE) - { - for(i=0;i < p_Vid->mb_cr_size_x;i+=BLOCK_SIZE) - { - imgcof[j][i] = rshift_rnd_sf((imgcof[j][i] * InvLevelScale4x4[0][0]) << qp_per_uv_dc, 6); + for (j = 0; j < p_Vid->mb_cr_size_y; j += BLOCK_SIZE) { + for (i = 0; i < p_Vid->mb_cr_size_x; i += BLOCK_SIZE) { + imgcof[j][i] = rshift_rnd_sf( + (imgcof[j][i] * InvLevelScale4x4[0][0]) << qp_per_uv_dc, 6); } } - } - else - { - for(j=0;j<4;++j) - { - currSlice->cof[uv + 1][j<<2][0] = m3[0][j]; - currSlice->cof[uv + 1][j<<2][4] = m3[1][j]; + } else { + for (j = 0; j < 4; ++j) { + currSlice->cof[uv + 1][j << 2][0] = m3[0][j]; + currSlice->cof[uv + 1][j << 2][4] = m3[1][j]; } } - } - }//for (ll=0;ll<3;ll+=2) + } // for (ll=0;ll<3;ll+=2) } //========================== CHROMA AC ============================ //----------------------------------------------------------------- // chroma AC coeff, all zero fram start_scan - if (cbp<=31) - { - fast_memset(p_Vid->nz_coeff [mb_nr ][1][0], 0, 2 * BLOCK_PIXELS * sizeof(byte)); - } - else - { - if(currMB->is_lossless == FALSE) - { - for (b8=0; b8 < p_Vid->num_blk8x8_uv; ++b8) - { - currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1 )); - InvLevelScale4x4 = intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; + if (cbp <= 31) { + fast_memset(p_Vid->nz_coeff[mb_nr][1][0], 0, + 2 * BLOCK_PIXELS * sizeof(byte)); + } else { + if (currMB->is_lossless == FALSE) { + for (b8 = 0; b8 < p_Vid->num_blk8x8_uv; ++b8) { + currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1)); + InvLevelScale4x4 = + intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] + : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; - for (b4=0; b4 < 4; ++b4) - { + for (b4 = 0; b4 < 4; ++b4) { i = cofuv_blk_x[yuv][b8][b4]; j = cofuv_blk_y[yuv][b8][b4]; - readCoeff4x4_CAVLC(currMB, CHROMA_AC, i + 2*uv, j + 4, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, CHROMA_AC, i + 2 * uv, j + 4, levarr, + runarr, &numcoeff); coef_ctr = 0; - for(k = 0; k < numcoeff;++k) - { - if (levarr[k] != 0) - { + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) { currMB->cbp_blk[0] |= i64_power2(cbp_blk_chroma[b8][b4]); coef_ctr += runarr[k] + 1; - i0=pos_scan4x4[coef_ctr][0]; - j0=pos_scan4x4[coef_ctr][1]; + i0 = pos_scan4x4[coef_ctr][0]; + j0 = pos_scan4x4[coef_ctr][1]; - currSlice->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = rshift_rnd_sf((levarr[k] * InvLevelScale4x4[j0][i0])<fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = levarr[k]; + currSlice->cof[uv + 1][(j << 2) + j0][(i << 2) + i0] = + rshift_rnd_sf((levarr[k] * InvLevelScale4x4[j0][i0]) + << qp_per_uv[uv], + 4); + // p_Vid->fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = levarr[k]; } } } - } - } - else - { - for (b8=0; b8 < p_Vid->num_blk8x8_uv; ++b8) - { - currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1 )); + } + } else { + for (b8 = 0; b8 < p_Vid->num_blk8x8_uv; ++b8) { + currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1)); - for (b4=0; b4 < 4; ++b4) - { + for (b4 = 0; b4 < 4; ++b4) { i = cofuv_blk_x[yuv][b8][b4]; j = cofuv_blk_y[yuv][b8][b4]; - readCoeff4x4_CAVLC(currMB, CHROMA_AC, i + 2*uv, j + 4, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, CHROMA_AC, i + 2 * uv, j + 4, levarr, + runarr, &numcoeff); coef_ctr = 0; - for(k = 0; k < numcoeff;++k) - { - if (levarr[k] != 0) - { + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) { currMB->cbp_blk[0] |= i64_power2(cbp_blk_chroma[b8][b4]); coef_ctr += runarr[k] + 1; - i0=pos_scan4x4[coef_ctr][0]; - j0=pos_scan4x4[coef_ctr][1]; + i0 = pos_scan4x4[coef_ctr][0]; + j0 = pos_scan4x4[coef_ctr][1]; - currSlice->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = levarr[k]; + currSlice->cof[uv + 1][(j << 2) + j0][(i << 2) + i0] = levarr[k]; } } } - } + } } - } //if (dec_picture->chroma_format_idc != YUV400) + } // if (dec_picture->chroma_format_idc != YUV400) } /*! @@ -5369,9 +5177,8 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_422(Macroblock *currMB) * from the NAL ************************************************************************ */ -static void read_CBP_and_coeffs_from_NAL_CAVLC_444(Macroblock *currMB) -{ - int i,k; +static void read_CBP_and_coeffs_from_NAL_CAVLC_444(Macroblock *currMB) { + int i, k; int level; int mb_nr = currMB->mbAddrX; int cbp; @@ -5385,7 +5192,7 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_444(Macroblock *currMB) int qp_per, qp_rem; VideoParameters *p_Vid = currMB->p_Vid; - int uv; + int uv; int qp_per_uv[2]; int qp_rem_uv[2]; @@ -5393,44 +5200,45 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_444(Macroblock *currMB) int need_transform_size_flag; - int (*InvLevelScale4x4)[4] = NULL; - int (*InvLevelScale8x8)[8] = NULL; + int(*InvLevelScale4x4)[4] = NULL; + int(*InvLevelScale8x8)[8] = NULL; // select scan type - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; // read CBP if not new intra mode - if (!IS_I16MB (currMB)) - { + if (!IS_I16MB(currMB)) { //===== C B P ===== //--------------------- - currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? SE_CBP_INTRA - : SE_CBP_INTER; + currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? SE_CBP_INTRA + : SE_CBP_INTER; dP = &(currSlice->partArr[partMap[currSE.type]]); - currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? currSlice->linfo_cbp_intra - : currSlice->linfo_cbp_inter; + currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? currSlice->linfo_cbp_intra + : currSlice->linfo_cbp_inter; TRACE_STRING("coded_block_pattern"); dP->readSyntaxElement(currMB, &currSE, dP); currMB->cbp = cbp = currSE.value1; - //============= Transform size flag for INTER MBs ============= //------------------------------------------------------------- - need_transform_size_flag = (((currMB->mb_type >= 1 && currMB->mb_type <= 3)|| - (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || - (currMB->NoMbPartLessThan8x8Flag)) - && currMB->mb_type != I8MB && currMB->mb_type != I4MB - && (currMB->cbp&15) - && currSlice->Transform8x8Mode); + need_transform_size_flag = + (((currMB->mb_type >= 1 && currMB->mb_type <= 3) || + (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || + (currMB->NoMbPartLessThan8x8Flag)) && + currMB->mb_type != I8MB && currMB->mb_type != I4MB && + (currMB->cbp & 15) && currSlice->Transform8x8Mode); - if (need_transform_size_flag) - { - currSE.type = SE_HEADER; + if (need_transform_size_flag) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); @@ -5439,169 +5247,181 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_444(Macroblock *currMB) currSE.len = 1; readSyntaxElement_FLC(&currSE, dP->bitstream); - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; } //===== DQUANT ===== //---------------------- // Delta quant only if nonzero coeffs - if (cbp !=0) - { - read_delta_quant(&currSE, dP, currMB, partMap, ((currMB->is_intra_block == FALSE)) ? SE_DELTA_QUANT_INTER : SE_DELTA_QUANT_INTRA); + if (cbp != 0) { + read_delta_quant(&currSE, dP, currMB, partMap, + ((currMB->is_intra_block == FALSE)) + ? SE_DELTA_QUANT_INTER + : SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent ) + if (currSlice->dp_mode) { + if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent) currMB->dpl_flag = 1; - if( intra && currSlice->dpB_NotPresent ) - { + if (intra && currSlice->dpB_NotPresent) { currMB->ei_flag = 1; currMB->dpl_flag = 1; } // check for prediction from neighbours - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + cbp = 0; currMB->cbp = cbp; } } } - } - else // read DC coeffs for new intra modes + } else // read DC coeffs for new intra modes { cbp = currMB->cbp; read_delta_quant(&currSE, dP, currMB, partMap, SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if (currSlice->dpB_NotPresent) - { - currMB->ei_flag = 1; + if (currSlice->dp_mode) { + if (currSlice->dpB_NotPresent) { + currMB->ei_flag = 1; currMB->dpl_flag = 1; } - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - currMB->cbp = cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + currMB->cbp = cbp = 0; } } - if (!currMB->dpl_flag) - { + if (!currMB->dpl_flag) { pos_scan_4x4 = pos_scan4x4[0]; - readCoeff4x4_CAVLC(currMB, LUMA_INTRA16x16DC, 0, 0, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, LUMA_INTRA16x16DC, 0, 0, levarr, runarr, + &numcoeff); - for(k = 0; k < numcoeff; ++k) - { - if (levarr[k] != 0) // leave if level == 0 + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) // leave if level == 0 { pos_scan_4x4 += 2 * runarr[k]; i0 = ((*pos_scan_4x4++) << 2); j0 = ((*pos_scan_4x4++) << 2); - currSlice->cof[0][j0][i0] = levarr[k];// add new intra DC coeff - //p_Vid->fcf[0][j0][i0] = levarr[k];// add new intra DC coeff + currSlice->cof[0][j0][i0] = levarr[k]; // add new intra DC coeff + // p_Vid->fcf[0][j0][i0] = levarr[k];// add new intra DC coeff } } - - if(currMB->is_lossless == FALSE) - itrans_2(currMB, (ColorPlane) currSlice->colour_plane_id);// transform new intra DC + if (currMB->is_lossless == FALSE) + itrans_2( + currMB, + (ColorPlane)currSlice->colour_plane_id); // transform new intra DC } } update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; - qp_rem = p_Vid->qp_rem_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; + qp_per = p_Vid->qp_per_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; + qp_rem = p_Vid->qp_rem_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; - //init quant parameters for chroma - for(i=0; i < 2; ++i) - { - qp_per_uv[i] = p_Vid->qp_per_matrix[ currMB->qp_scaled[i + 1] ]; - qp_rem_uv[i] = p_Vid->qp_rem_matrix[ currMB->qp_scaled[i + 1] ]; + // init quant parameters for chroma + for (i = 0; i < 2; ++i) { + qp_per_uv[i] = p_Vid->qp_per_matrix[currMB->qp_scaled[i + 1]]; + qp_rem_uv[i] = p_Vid->qp_rem_matrix[currMB->qp_scaled[i + 1]]; } - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; - InvLevelScale8x8 = intra? currSlice->InvLevelScale8x8_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale8x8_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale4x4 = + intra ? currSlice + ->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale8x8 = + intra ? currSlice + ->InvLevelScale8x8_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale8x8_Inter[currSlice->colour_plane_id][qp_rem]; // luma coefficients - if (cbp) - { + if (cbp) { if (!currMB->luma_transform_size_8x8_flag) // 4x4 transform { - readCompCoeff4x4MB_CAVLC (currMB, PLANE_Y, InvLevelScale4x4, qp_per, cbp, p_Vid->nz_coeff[mb_nr][PLANE_Y]); - } - else // 8x8 transform + readCompCoeff4x4MB_CAVLC(currMB, PLANE_Y, InvLevelScale4x4, qp_per, cbp, + p_Vid->nz_coeff[mb_nr][PLANE_Y]); + } else // 8x8 transform { - readCompCoeff8x8MB_CAVLC (currMB, PLANE_Y, InvLevelScale8x8, qp_per, cbp, p_Vid->nz_coeff[mb_nr][PLANE_Y]); + readCompCoeff8x8MB_CAVLC(currMB, PLANE_Y, InvLevelScale8x8, qp_per, cbp, + p_Vid->nz_coeff[mb_nr][PLANE_Y]); } - } - else - { + } else { fast_memset(p_Vid->nz_coeff[mb_nr][0][0], 0, BLOCK_PIXELS * sizeof(byte)); } - for (uv = 0; uv < 2; ++uv ) - { + for (uv = 0; uv < 2; ++uv) { /*----------------------16x16DC Luma_Add----------------------*/ - if (IS_I16MB (currMB)) // read DC coeffs for new intra modes + if (IS_I16MB(currMB)) // read DC coeffs for new intra modes { if (uv == 0) - readCoeff4x4_CAVLC(currMB, CB_INTRA16x16DC, 0, 0, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, CB_INTRA16x16DC, 0, 0, levarr, runarr, + &numcoeff); else - readCoeff4x4_CAVLC(currMB, CR_INTRA16x16DC, 0, 0, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, CR_INTRA16x16DC, 0, 0, levarr, runarr, + &numcoeff); - coef_ctr=-1; - level = 1; // just to get inside the loop + coef_ctr = -1; + level = 1; // just to get inside the loop - for(k = 0; k < numcoeff; ++k) - { - if (levarr[k] != 0) // leave if level == 0 + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) // leave if level == 0 { coef_ctr += runarr[k] + 1; i0 = pos_scan4x4[coef_ctr][0]; j0 = pos_scan4x4[coef_ctr][1]; - currSlice->cof[uv + 1][j0<<2][i0<<2] = levarr[k];// add new intra DC coeff - //p_Vid->fcf[uv + 1][j0<<2][i0<<2] = levarr[k];// add new intra DC coeff - } //if leavarr[k] - } //k loop + currSlice->cof[uv + 1][j0 << 2][i0 << 2] = + levarr[k]; // add new intra DC coeff + // p_Vid->fcf[uv + 1][j0<<2][i0<<2] = levarr[k];// add new intra DC + // coeff + } // if leavarr[k] + } // k loop - if(currMB->is_lossless == FALSE) - { - itrans_2(currMB, (ColorPlane) (uv + 1)); // transform new intra DC + if (currMB->is_lossless == FALSE) { + itrans_2(currMB, (ColorPlane)(uv + 1)); // transform new intra DC } - } //IS_I16MB + } // IS_I16MB update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ (currSlice->qp + p_Vid->bitdepth_luma_qp_scale) ]; - qp_rem = p_Vid->qp_rem_matrix[ (currSlice->qp + p_Vid->bitdepth_luma_qp_scale) ]; + qp_per = + p_Vid->qp_per_matrix[(currSlice->qp + p_Vid->bitdepth_luma_qp_scale)]; + qp_rem = + p_Vid->qp_rem_matrix[(currSlice->qp + p_Vid->bitdepth_luma_qp_scale)]; - //init constants for every chroma qp offset - qp_per_uv[uv] = p_Vid->qp_per_matrix[ (currMB->qpc[uv] + p_Vid->bitdepth_chroma_qp_scale) ]; - qp_rem_uv[uv] = p_Vid->qp_rem_matrix[ (currMB->qpc[uv] + p_Vid->bitdepth_chroma_qp_scale) ]; + // init constants for every chroma qp offset + qp_per_uv[uv] = p_Vid->qp_per_matrix[(currMB->qpc[uv] + + p_Vid->bitdepth_chroma_qp_scale)]; + qp_rem_uv[uv] = p_Vid->qp_rem_matrix[(currMB->qpc[uv] + + p_Vid->bitdepth_chroma_qp_scale)]; - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; - InvLevelScale8x8 = intra? currSlice->InvLevelScale8x8_Intra[uv + 1][qp_rem_uv[uv]] : currSlice->InvLevelScale8x8_Inter[uv + 1][qp_rem_uv[uv]]; + InvLevelScale4x4 = + intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] + : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; + InvLevelScale8x8 = + intra ? currSlice->InvLevelScale8x8_Intra[uv + 1][qp_rem_uv[uv]] + : currSlice->InvLevelScale8x8_Inter[uv + 1][qp_rem_uv[uv]]; if (!currMB->luma_transform_size_8x8_flag) // 4x4 transform { - readCompCoeff4x4MB_CAVLC (currMB, (ColorPlane) (PLANE_U + uv), InvLevelScale4x4, qp_per_uv[uv], cbp, p_Vid->nz_coeff[mb_nr][PLANE_U + uv]); - } - else // 8x8 transform + readCompCoeff4x4MB_CAVLC(currMB, (ColorPlane)(PLANE_U + uv), + InvLevelScale4x4, qp_per_uv[uv], cbp, + p_Vid->nz_coeff[mb_nr][PLANE_U + uv]); + } else // 8x8 transform { - readCompCoeff8x8MB_CAVLC (currMB, (ColorPlane) (PLANE_U + uv), InvLevelScale8x8, qp_per_uv[uv], cbp, p_Vid->nz_coeff[mb_nr][PLANE_U + uv]); - } - } + readCompCoeff8x8MB_CAVLC(currMB, (ColorPlane)(PLANE_U + uv), + InvLevelScale8x8, qp_per_uv[uv], cbp, + p_Vid->nz_coeff[mb_nr][PLANE_U + uv]); + } + } } /*! @@ -5611,9 +5431,8 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_444(Macroblock *currMB) * from the NAL ************************************************************************ */ -static void read_CBP_and_coeffs_from_NAL_CAVLC_420(Macroblock *currMB) -{ - int i,j,k; +static void read_CBP_and_coeffs_from_NAL_CAVLC_420(Macroblock *currMB) { + int i, j, k; int mb_nr = currMB->mbAddrX; int cbp; SyntaxElement currSE; @@ -5626,9 +5445,10 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_420(Macroblock *currMB) int qp_per, qp_rem; VideoParameters *p_Vid = currMB->p_Vid; - int smb = ((p_Vid->type==SP_SLICE) && (currMB->is_intra_block == FALSE)) || (p_Vid->type == SI_SLICE && currMB->mb_type == SI4MB); + int smb = ((p_Vid->type == SP_SLICE) && (currMB->is_intra_block == FALSE)) || + (p_Vid->type == SI_SLICE && currMB->mb_type == SI4MB); - int uv; + int uv; int qp_per_uv[2]; int qp_rem_uv[2]; @@ -5641,26 +5461,29 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_420(Macroblock *currMB) int need_transform_size_flag; - int (*InvLevelScale4x4)[4] = NULL; - int (*InvLevelScale8x8)[8] = NULL; + int(*InvLevelScale4x4)[4] = NULL; + int(*InvLevelScale8x8)[8] = NULL; // select scan type - const byte (*pos_scan4x4)[2] = ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN : FIELD_SCAN; + const byte(*pos_scan4x4)[2] = + ((p_Vid->structure == FRAME) && (!currMB->mb_field)) ? SNGL_SCAN + : FIELD_SCAN; const byte *pos_scan_4x4 = pos_scan4x4[0]; // read CBP if not new intra mode - if (!IS_I16MB (currMB)) - { + if (!IS_I16MB(currMB)) { //===== C B P ===== //--------------------- - currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? SE_CBP_INTRA - : SE_CBP_INTER; + currSE.type = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? SE_CBP_INTRA + : SE_CBP_INTER; dP = &(currSlice->partArr[partMap[currSE.type]]); - currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || currMB->mb_type == I8MB) - ? currSlice->linfo_cbp_intra - : currSlice->linfo_cbp_inter; + currSE.mapping = (currMB->mb_type == I4MB || currMB->mb_type == SI4MB || + currMB->mb_type == I8MB) + ? currSlice->linfo_cbp_intra + : currSlice->linfo_cbp_inter; TRACE_STRING("coded_block_pattern"); dP->readSyntaxElement(currMB, &currSE, dP); @@ -5668,16 +5491,15 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_420(Macroblock *currMB) //============= Transform size flag for INTER MBs ============= //------------------------------------------------------------- - need_transform_size_flag = (((currMB->mb_type >= 1 && currMB->mb_type <= 3)|| - (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || - (currMB->NoMbPartLessThan8x8Flag)) - && currMB->mb_type != I8MB && currMB->mb_type != I4MB - && (currMB->cbp&15) - && currSlice->Transform8x8Mode); + need_transform_size_flag = + (((currMB->mb_type >= 1 && currMB->mb_type <= 3) || + (IS_DIRECT(currMB) && p_Vid->active_sps->direct_8x8_inference_flag) || + (currMB->NoMbPartLessThan8x8Flag)) && + currMB->mb_type != I8MB && currMB->mb_type != I4MB && + (currMB->cbp & 15) && currSlice->Transform8x8Mode); - if (need_transform_size_flag) - { - currSE.type = SE_HEADER; + if (need_transform_size_flag) { + currSE.type = SE_HEADER; dP = &(currSlice->partArr[partMap[SE_HEADER]]); currSE.reading = readMB_transform_size_flag_CABAC; TRACE_STRING("transform_size_8x8_flag"); @@ -5686,172 +5508,169 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_420(Macroblock *currMB) currSE.len = 1; readSyntaxElement_FLC(&currSE, dP->bitstream); - currMB->luma_transform_size_8x8_flag = (Boolean) currSE.value1; + currMB->luma_transform_size_8x8_flag = (Boolean)currSE.value1; } //===== DQUANT ===== //---------------------- // Delta quant only if nonzero coeffs - if (cbp !=0) - { - read_delta_quant(&currSE, dP, currMB, partMap, ((currMB->is_intra_block == FALSE)) ? SE_DELTA_QUANT_INTER : SE_DELTA_QUANT_INTRA); + if (cbp != 0) { + read_delta_quant(&currSE, dP, currMB, partMap, + ((currMB->is_intra_block == FALSE)) + ? SE_DELTA_QUANT_INTER + : SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent ) + if (currSlice->dp_mode) { + if ((currMB->is_intra_block == FALSE) && currSlice->dpC_NotPresent) currMB->dpl_flag = 1; - if( intra && currSlice->dpB_NotPresent ) - { + if (intra && currSlice->dpB_NotPresent) { currMB->ei_flag = 1; currMB->dpl_flag = 1; } // check for prediction from neighbours - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + cbp = 0; currMB->cbp = cbp; } } } - } - else - { - cbp = currMB->cbp; + } else { + cbp = currMB->cbp; read_delta_quant(&currSE, dP, currMB, partMap, SE_DELTA_QUANT_INTRA); - if (currSlice->dp_mode) - { - if (currSlice->dpB_NotPresent) - { - currMB->ei_flag = 1; + if (currSlice->dp_mode) { + if (currSlice->dpB_NotPresent) { + currMB->ei_flag = 1; currMB->dpl_flag = 1; } - check_dp_neighbors (currMB); - if (currMB->dpl_flag) - { - currMB->cbp = cbp = 0; + check_dp_neighbors(currMB); + if (currMB->dpl_flag) { + currMB->cbp = cbp = 0; } } - if (!currMB->dpl_flag) - { + if (!currMB->dpl_flag) { pos_scan_4x4 = pos_scan4x4[0]; - readCoeff4x4_CAVLC(currMB, LUMA_INTRA16x16DC, 0, 0, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, LUMA_INTRA16x16DC, 0, 0, levarr, runarr, + &numcoeff); - for(k = 0; k < numcoeff; ++k) - { - if (levarr[k] != 0) // leave if level == 0 + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) // leave if level == 0 { pos_scan_4x4 += 2 * runarr[k]; i0 = ((*pos_scan_4x4++) << 2); j0 = ((*pos_scan_4x4++) << 2); - currSlice->cof[0][j0][i0] = levarr[k];// add new intra DC coeff - //p_Vid->fcf[0][j0][i0] = levarr[k];// add new intra DC coeff + currSlice->cof[0][j0][i0] = levarr[k]; // add new intra DC coeff + // p_Vid->fcf[0][j0][i0] = levarr[k];// add new intra DC coeff } } - - if(currMB->is_lossless == FALSE) - itrans_2(currMB, (ColorPlane) currSlice->colour_plane_id);// transform new intra DC + if (currMB->is_lossless == FALSE) + itrans_2( + currMB, + (ColorPlane)currSlice->colour_plane_id); // transform new intra DC } } update_qp(currMB, currSlice->qp); - qp_per = p_Vid->qp_per_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; - qp_rem = p_Vid->qp_rem_matrix[ currMB->qp_scaled[currSlice->colour_plane_id] ]; + qp_per = p_Vid->qp_per_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; + qp_rem = p_Vid->qp_rem_matrix[currMB->qp_scaled[currSlice->colour_plane_id]]; - //init quant parameters for chroma - if (dec_picture->chroma_format_idc != YUV400) - { - for(i=0; i < 2; ++i) - { - qp_per_uv[i] = p_Vid->qp_per_matrix[ currMB->qp_scaled[i + 1] ]; - qp_rem_uv[i] = p_Vid->qp_rem_matrix[ currMB->qp_scaled[i + 1] ]; + // init quant parameters for chroma + if (dec_picture->chroma_format_idc != YUV400) { + for (i = 0; i < 2; ++i) { + qp_per_uv[i] = p_Vid->qp_per_matrix[currMB->qp_scaled[i + 1]]; + qp_rem_uv[i] = p_Vid->qp_rem_matrix[currMB->qp_scaled[i + 1]]; } } - InvLevelScale4x4 = intra? currSlice->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; - InvLevelScale8x8 = intra? currSlice->InvLevelScale8x8_Intra[currSlice->colour_plane_id][qp_rem] : currSlice->InvLevelScale8x8_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale4x4 = + intra ? currSlice + ->InvLevelScale4x4_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale4x4_Inter[currSlice->colour_plane_id][qp_rem]; + InvLevelScale8x8 = + intra ? currSlice + ->InvLevelScale8x8_Intra[currSlice->colour_plane_id][qp_rem] + : currSlice + ->InvLevelScale8x8_Inter[currSlice->colour_plane_id][qp_rem]; // luma coefficients - if (cbp) - { + if (cbp) { if (!currMB->luma_transform_size_8x8_flag) // 4x4 transform { - readCompCoeff4x4MB_CAVLC (currMB, PLANE_Y, InvLevelScale4x4, qp_per, cbp, p_Vid->nz_coeff[mb_nr][PLANE_Y]); - } - else // 8x8 transform + readCompCoeff4x4MB_CAVLC(currMB, PLANE_Y, InvLevelScale4x4, qp_per, cbp, + p_Vid->nz_coeff[mb_nr][PLANE_Y]); + } else // 8x8 transform { - readCompCoeff8x8MB_CAVLC (currMB, PLANE_Y, InvLevelScale8x8, qp_per, cbp, p_Vid->nz_coeff[mb_nr][PLANE_Y]); + readCompCoeff8x8MB_CAVLC(currMB, PLANE_Y, InvLevelScale8x8, qp_per, cbp, + p_Vid->nz_coeff[mb_nr][PLANE_Y]); } - } - else - { + } else { fast_memset(p_Vid->nz_coeff[mb_nr][0][0], 0, BLOCK_PIXELS * sizeof(byte)); } - if (dec_picture->chroma_format_idc != YUV444) - { + if (dec_picture->chroma_format_idc != YUV444) { //========================== CHROMA DC ============================ //----------------------------------------------------------------- // chroma DC coeff - if(cbp>15) - { - if (dec_picture->chroma_format_idc == YUV420) - { - for (ll=0;ll<3;ll+=2) - { - uv = ll>>1; + if (cbp > 15) { + if (dec_picture->chroma_format_idc == YUV420) { + for (ll = 0; ll < 3; ll += 2) { + uv = ll >> 1; - InvLevelScale4x4 = intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; + InvLevelScale4x4 = + intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] + : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; //===================== CHROMA DC YUV420 ====================== - memset(currSlice->cofu, 0, 4 *sizeof(int)); - coef_ctr=-1; + memset(currSlice->cofu, 0, 4 * sizeof(int)); + coef_ctr = -1; - readCoeff4x4_CAVLC(currMB, CHROMA_DC, 0, 0, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, CHROMA_DC, 0, 0, levarr, runarr, + &numcoeff); - for(k = 0; k < numcoeff; ++k) - { - if (levarr[k] != 0) - { - currMB->cbp_blk[0] |= 0xf0000 << (ll<<1) ; + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) { + currMB->cbp_blk[0] |= 0xf0000 << (ll << 1); coef_ctr += runarr[k] + 1; - currSlice->cofu[coef_ctr]=levarr[k]; + currSlice->cofu[coef_ctr] = levarr[k]; } } - - if (smb || (currMB->is_lossless == TRUE)) // check to see if MB type is SPred or SIntra4x4 + if (smb || (currMB->is_lossless == + TRUE)) // check to see if MB type is SPred or SIntra4x4 { currSlice->cof[uv + 1][0][0] = currSlice->cofu[0]; currSlice->cof[uv + 1][0][4] = currSlice->cofu[1]; currSlice->cof[uv + 1][4][0] = currSlice->cofu[2]; currSlice->cof[uv + 1][4][4] = currSlice->cofu[3]; - //p_Vid->fcf[uv + 1][0][0] = currSlice->cofu[0]; - //p_Vid->fcf[uv + 1][4][0] = currSlice->cofu[1]; - //p_Vid->fcf[uv + 1][0][4] = currSlice->cofu[2]; - //p_Vid->fcf[uv + 1][4][4] = currSlice->cofu[3]; - } - else - { + // p_Vid->fcf[uv + 1][0][0] = currSlice->cofu[0]; + // p_Vid->fcf[uv + 1][4][0] = currSlice->cofu[1]; + // p_Vid->fcf[uv + 1][0][4] = currSlice->cofu[2]; + // p_Vid->fcf[uv + 1][4][4] = currSlice->cofu[3]; + } else { ihadamard2x2(currSlice->cofu, temp); - //p_Vid->fcf[uv + 1][0][0] = temp[0]; - //p_Vid->fcf[uv + 1][0][4] = temp[1]; - //p_Vid->fcf[uv + 1][4][0] = temp[2]; - //p_Vid->fcf[uv + 1][4][4] = temp[3]; + // p_Vid->fcf[uv + 1][0][0] = temp[0]; + // p_Vid->fcf[uv + 1][0][4] = temp[1]; + // p_Vid->fcf[uv + 1][4][0] = temp[2]; + // p_Vid->fcf[uv + 1][4][4] = temp[3]; - currSlice->cof[uv + 1][0][0] = (((temp[0] * InvLevelScale4x4[0][0])<>5); - currSlice->cof[uv + 1][0][4] = (((temp[1] * InvLevelScale4x4[0][0])<>5); - currSlice->cof[uv + 1][4][0] = (((temp[2] * InvLevelScale4x4[0][0])<>5); - currSlice->cof[uv + 1][4][4] = (((temp[3] * InvLevelScale4x4[0][0])<>5); - } + currSlice->cof[uv + 1][0][0] = + (((temp[0] * InvLevelScale4x4[0][0]) << qp_per_uv[uv]) >> 5); + currSlice->cof[uv + 1][0][4] = + (((temp[1] * InvLevelScale4x4[0][0]) << qp_per_uv[uv]) >> 5); + currSlice->cof[uv + 1][4][0] = + (((temp[2] * InvLevelScale4x4[0][0]) << qp_per_uv[uv]) >> 5); + currSlice->cof[uv + 1][4][4] = + (((temp[3] * InvLevelScale4x4[0][0]) << qp_per_uv[uv]) >> 5); + } } } } @@ -5859,79 +5678,73 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_420(Macroblock *currMB) //========================== CHROMA AC ============================ //----------------------------------------------------------------- // chroma AC coeff, all zero fram start_scan - if (cbp<=31) - { - fast_memset(p_Vid->nz_coeff [mb_nr ][1][0], 0, 2 * BLOCK_PIXELS * sizeof(byte)); - } - else - { - if(currMB->is_lossless == FALSE) - { - for (b8=0; b8 < p_Vid->num_blk8x8_uv; ++b8) - { - currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1 )); - InvLevelScale4x4 = intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; + if (cbp <= 31) { + fast_memset(p_Vid->nz_coeff[mb_nr][1][0], 0, + 2 * BLOCK_PIXELS * sizeof(byte)); + } else { + if (currMB->is_lossless == FALSE) { + for (b8 = 0; b8 < p_Vid->num_blk8x8_uv; ++b8) { + currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1)); + InvLevelScale4x4 = + intra ? currSlice->InvLevelScale4x4_Intra[uv + 1][qp_rem_uv[uv]] + : currSlice->InvLevelScale4x4_Inter[uv + 1][qp_rem_uv[uv]]; - for (b4=0; b4 < 4; ++b4) - { + for (b4 = 0; b4 < 4; ++b4) { i = cofuv_blk_x[yuv][b8][b4]; j = cofuv_blk_y[yuv][b8][b4]; - readCoeff4x4_CAVLC(currMB, CHROMA_AC, i + 2*uv, j + 4, levarr, runarr, &numcoeff); + readCoeff4x4_CAVLC(currMB, CHROMA_AC, i + 2 * uv, j + 4, levarr, + runarr, &numcoeff); coef_ctr = 0; - for(k = 0; k < numcoeff;++k) - { - if (levarr[k] != 0) - { + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) { currMB->cbp_blk[0] |= i64_power2(cbp_blk_chroma[b8][b4]); coef_ctr += runarr[k] + 1; - i0=pos_scan4x4[coef_ctr][0]; - j0=pos_scan4x4[coef_ctr][1]; + i0 = pos_scan4x4[coef_ctr][0]; + j0 = pos_scan4x4[coef_ctr][1]; - currSlice->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = rshift_rnd_sf((levarr[k] * InvLevelScale4x4[j0][i0])<fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = levarr[k]; + currSlice->cof[uv + 1][(j << 2) + j0][(i << 2) + i0] = + rshift_rnd_sf((levarr[k] * InvLevelScale4x4[j0][i0]) + << qp_per_uv[uv], + 4); + // p_Vid->fcf[uv + 1][(j<<2) + j0][(i<<2) + i0] = levarr[k]; } } } - } + } + } else { + for (b8 = 0; b8 < p_Vid->num_blk8x8_uv; ++b8) { + currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1)); + + for (b4 = 0; b4 < 4; ++b4) { + i = cofuv_blk_x[yuv][b8][b4]; + j = cofuv_blk_y[yuv][b8][b4]; + + readCoeff4x4_CAVLC(currMB, CHROMA_AC, i + 2 * uv, j + 4, levarr, + runarr, &numcoeff); + coef_ctr = 0; + + for (k = 0; k < numcoeff; ++k) { + if (levarr[k] != 0) { + currMB->cbp_blk[0] |= i64_power2(cbp_blk_chroma[b8][b4]); + coef_ctr += runarr[k] + 1; + + i0 = pos_scan4x4[coef_ctr][0]; + j0 = pos_scan4x4[coef_ctr][1]; + + currSlice->cof[uv + 1][(j << 2) + j0][(i << 2) + i0] = + levarr[k]; + } + } + } + } } - else - { - for (b8=0; b8 < p_Vid->num_blk8x8_uv; ++b8) - { - currMB->is_v_block = uv = (b8 > ((p_Vid->num_uv_blocks) - 1 )); - - for (b4=0; b4 < 4; ++b4) - { - i = cofuv_blk_x[yuv][b8][b4]; - j = cofuv_blk_y[yuv][b8][b4]; - - readCoeff4x4_CAVLC(currMB, CHROMA_AC, i + 2*uv, j + 4, levarr, runarr, &numcoeff); - coef_ctr = 0; - - for(k = 0; k < numcoeff;++k) - { - if (levarr[k] != 0) - { - currMB->cbp_blk[0] |= i64_power2(cbp_blk_chroma[b8][b4]); - coef_ctr += runarr[k] + 1; - - i0=pos_scan4x4[coef_ctr][0]; - j0=pos_scan4x4[coef_ctr][1]; - - currSlice->cof[uv + 1][(j<<2) + j0][(i<<2) + i0] = levarr[k]; - } - } - } - } - } - } //if (dec_picture->chroma_format_idc != YUV400) + } // if (dec_picture->chroma_format_idc != YUV400) } } - /*! ************************************************************************ * \brief @@ -5939,17 +5752,18 @@ static void read_CBP_and_coeffs_from_NAL_CAVLC_420(Macroblock *currMB) ************************************************************************ */ -static int decode_one_component_i_slice(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ - //For residual DPCM - currMB->ipmode_DPCM = NO_INTRA_PMODE; - if(currMB->mb_type == IPCM) +static int decode_one_component_i_slice(Macroblock *currMB, + ColorPlane curr_plane, imgpel **currImg, + StorablePicture *dec_picture) { + // For residual DPCM + currMB->ipmode_DPCM = NO_INTRA_PMODE; + if (currMB->mb_type == IPCM) mb_pred_ipcm(currMB); - else if (currMB->mb_type==I16MB) + else if (currMB->mb_type == I16MB) mb_pred_intra16x16(currMB, curr_plane, dec_picture); else if (currMB->mb_type == I4MB) mb_pred_intra4x4(currMB, curr_plane, currImg, dec_picture); - else if (currMB->mb_type == I8MB) + else if (currMB->mb_type == I8MB) mb_pred_intra8x8(currMB, curr_plane, currImg, dec_picture); return 1; @@ -5961,22 +5775,23 @@ static int decode_one_component_i_slice(Macroblock *currMB, ColorPlane curr_plan * decode one color component for a p slice ************************************************************************ */ -static int decode_one_component_p_slice(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ - //For residual DPCM - currMB->ipmode_DPCM = NO_INTRA_PMODE; - if(currMB->mb_type == IPCM) +static int decode_one_component_p_slice(Macroblock *currMB, + ColorPlane curr_plane, imgpel **currImg, + StorablePicture *dec_picture) { + // For residual DPCM + currMB->ipmode_DPCM = NO_INTRA_PMODE; + if (currMB->mb_type == IPCM) mb_pred_ipcm(currMB); - else if (currMB->mb_type==I16MB) + else if (currMB->mb_type == I16MB) mb_pred_intra16x16(currMB, curr_plane, dec_picture); else if (currMB->mb_type == I4MB) mb_pred_intra4x4(currMB, curr_plane, currImg, dec_picture); - else if (currMB->mb_type == I8MB) + else if (currMB->mb_type == I8MB) mb_pred_intra8x8(currMB, curr_plane, currImg, dec_picture); else if (currMB->mb_type == PSKIP) mb_pred_skip(currMB, curr_plane, currImg, dec_picture); else if (currMB->mb_type == P16x16) - mb_pred_p_inter16x16(currMB, curr_plane, dec_picture); + mb_pred_p_inter16x16(currMB, curr_plane, dec_picture); else if (currMB->mb_type == P16x8) mb_pred_p_inter16x8(currMB, curr_plane, dec_picture); else if (currMB->mb_type == P8x16) @@ -5987,30 +5802,31 @@ static int decode_one_component_p_slice(Macroblock *currMB, ColorPlane curr_plan return 1; } - /*! ************************************************************************ * \brief * decode one color component for a sp slice ************************************************************************ */ -static int decode_one_component_sp_slice(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ - //For residual DPCM - currMB->ipmode_DPCM = NO_INTRA_PMODE; +static int decode_one_component_sp_slice(Macroblock *currMB, + ColorPlane curr_plane, + imgpel **currImg, + StorablePicture *dec_picture) { + // For residual DPCM + currMB->ipmode_DPCM = NO_INTRA_PMODE; if (currMB->mb_type == IPCM) mb_pred_ipcm(currMB); - else if (currMB->mb_type==I16MB) + else if (currMB->mb_type == I16MB) mb_pred_intra16x16(currMB, curr_plane, dec_picture); else if (currMB->mb_type == I4MB) mb_pred_intra4x4(currMB, curr_plane, currImg, dec_picture); - else if (currMB->mb_type == I8MB) + else if (currMB->mb_type == I8MB) mb_pred_intra8x8(currMB, curr_plane, currImg, dec_picture); else if (currMB->mb_type == PSKIP) mb_pred_sp_skip(currMB, curr_plane, dec_picture); else if (currMB->mb_type == P16x16) - mb_pred_p_inter16x16(currMB, curr_plane, dec_picture); + mb_pred_p_inter16x16(currMB, curr_plane, dec_picture); else if (currMB->mb_type == P16x8) mb_pred_p_inter16x8(currMB, curr_plane, dec_picture); else if (currMB->mb_type == P8x16) @@ -6021,8 +5837,6 @@ static int decode_one_component_sp_slice(Macroblock *currMB, ColorPlane curr_pla return 1; } - - /*! ************************************************************************ * \brief @@ -6030,78 +5844,73 @@ static int decode_one_component_sp_slice(Macroblock *currMB, ColorPlane curr_pla ************************************************************************ */ -static int decode_one_component_b_slice(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ - //For residual DPCM - currMB->ipmode_DPCM = NO_INTRA_PMODE; +static int decode_one_component_b_slice(Macroblock *currMB, + ColorPlane curr_plane, imgpel **currImg, + StorablePicture *dec_picture) { + // For residual DPCM + currMB->ipmode_DPCM = NO_INTRA_PMODE; - if(currMB->mb_type == IPCM) + if (currMB->mb_type == IPCM) mb_pred_ipcm(currMB); - else if (currMB->mb_type==I16MB) + else if (currMB->mb_type == I16MB) mb_pred_intra16x16(currMB, curr_plane, dec_picture); else if (currMB->mb_type == I4MB) mb_pred_intra4x4(currMB, curr_plane, currImg, dec_picture); - else if (currMB->mb_type == I8MB) - mb_pred_intra8x8(currMB, curr_plane, currImg, dec_picture); + else if (currMB->mb_type == I8MB) + mb_pred_intra8x8(currMB, curr_plane, currImg, dec_picture); else if (currMB->mb_type == P16x16) mb_pred_p_inter16x16(currMB, curr_plane, dec_picture); else if (currMB->mb_type == P16x8) mb_pred_p_inter16x8(currMB, curr_plane, dec_picture); else if (currMB->mb_type == P8x16) mb_pred_p_inter8x16(currMB, curr_plane, dec_picture); - else if (currMB->mb_type == BSKIP_DIRECT) - { + else if (currMB->mb_type == BSKIP_DIRECT) { Slice *currSlice = currMB->p_Slice; - if (currSlice->direct_spatial_mv_pred_flag == 0) - { + if (currSlice->direct_spatial_mv_pred_flag == 0) { if (currSlice->active_sps->direct_8x8_inference_flag) - mb_pred_b_d8x8temporal (currMB, curr_plane, currImg, dec_picture); + mb_pred_b_d8x8temporal(currMB, curr_plane, currImg, dec_picture); else - mb_pred_b_d4x4temporal (currMB, curr_plane, currImg, dec_picture); - } - else - { + mb_pred_b_d4x4temporal(currMB, curr_plane, currImg, dec_picture); + } else { if (currSlice->active_sps->direct_8x8_inference_flag) - mb_pred_b_d8x8spatial (currMB, curr_plane, currImg, dec_picture); + mb_pred_b_d8x8spatial(currMB, curr_plane, currImg, dec_picture); else - mb_pred_b_d4x4spatial (currMB, curr_plane, currImg, dec_picture); + mb_pred_b_d4x4spatial(currMB, curr_plane, currImg, dec_picture); } - } - else - mb_pred_b_inter8x8 (currMB, curr_plane, dec_picture); + } else + mb_pred_b_inter8x8(currMB, curr_plane, dec_picture); - return 1; + return 1; } -// probably a better way (or place) to do this, but I'm not sure what (where) it is [CJV] -// this is intended to make get_block_luma faster, but I'm still performing -// this at the MB level, and it really should be done at the slice level -static void init_cur_imgy(VideoParameters *p_Vid,Slice *currSlice,int pl) -{ - int i,j; +// probably a better way (or place) to do this, but I'm not sure what (where) it +// is [CJV] this is intended to make get_block_luma faster, but I'm still +// performing this at the MB level, and it really should be done at the slice +// level +static void init_cur_imgy(VideoParameters *p_Vid, Slice *currSlice, int pl) { + int i, j; if ((p_Vid->separate_colour_plane_flag == 0)) { StorablePicture *vidref = p_Vid->no_reference_picture; - int noref = (currSlice->framepoc < p_Vid->recovery_poc); - if (pl==PLANE_Y) { - for (j = 0; j < 6; j++) { // for (j = 0; j < (currSlice->slice_type==B_SLICE?2:1); j++) { - for (i = 0; i < currSlice->listXsize[j] ; i++) - { + int noref = (currSlice->framepoc < p_Vid->recovery_poc); + if (pl == PLANE_Y) { + for (j = 0; j < 6; j++) { // for (j = 0; j < + // (currSlice->slice_type==B_SLICE?2:1); j++) { + for (i = 0; i < currSlice->listXsize[j]; i++) { StorablePicture *curr_ref = currSlice->listX[j][i]; - if (curr_ref) - { + if (curr_ref) { curr_ref->no_ref = noref && (curr_ref == vidref); curr_ref->cur_imgY = curr_ref->imgY; } } } - } - else { - for (j = 0; j < 6; j++) { //for (j = 0; j < (currSlice->slice_type==B_SLICE?2:1); j++) { + } else { + for (j = 0; j < 6; j++) { // for (j = 0; j < + // (currSlice->slice_type==B_SLICE?2:1); j++) { for (i = 0; i < currSlice->listXsize[j]; i++) { StorablePicture *curr_ref = currSlice->listX[j][i]; if (curr_ref) { curr_ref->no_ref = noref && (curr_ref == vidref); - curr_ref->cur_imgY = curr_ref->imgUV[pl-1]; + curr_ref->cur_imgY = curr_ref->imgUV[pl - 1]; } } } @@ -6109,7 +5918,6 @@ static void init_cur_imgy(VideoParameters *p_Vid,Slice *currSlice,int pl) } } - /*! ************************************************************************ * \brief @@ -6117,41 +5925,39 @@ static void init_cur_imgy(VideoParameters *p_Vid,Slice *currSlice,int pl) ************************************************************************ */ -int decode_one_macroblock(Macroblock *currMB, StorablePicture *dec_picture) -{ +int decode_one_macroblock(Macroblock *currMB, StorablePicture *dec_picture) { Slice *currSlice = currMB->p_Slice; - VideoParameters *p_Vid = currMB->p_Vid; - + VideoParameters *p_Vid = currMB->p_Vid; // macroblock decoding ************************************************** - if (currSlice->is_not_independent) - { - if (!currMB->is_intra_block) - { - init_cur_imgy(p_Vid,currSlice,PLANE_Y); - currSlice->decode_one_component(currMB, PLANE_Y, dec_picture->imgY, dec_picture); - init_cur_imgy(p_Vid,currSlice,PLANE_U); - currSlice->decode_one_component(currMB, PLANE_U, dec_picture->imgUV[0], dec_picture); - init_cur_imgy(p_Vid,currSlice,PLANE_V); - currSlice->decode_one_component(currMB, PLANE_V, dec_picture->imgUV[1], dec_picture); - } - else - { - currSlice->decode_one_component(currMB, PLANE_Y, dec_picture->imgY, dec_picture); - currSlice->decode_one_component(currMB, PLANE_U, dec_picture->imgUV[0], dec_picture); - currSlice->decode_one_component(currMB, PLANE_V, dec_picture->imgUV[1], dec_picture); + if (currSlice->is_not_independent) { + if (!currMB->is_intra_block) { + init_cur_imgy(p_Vid, currSlice, PLANE_Y); + currSlice->decode_one_component(currMB, PLANE_Y, dec_picture->imgY, + dec_picture); + init_cur_imgy(p_Vid, currSlice, PLANE_U); + currSlice->decode_one_component(currMB, PLANE_U, dec_picture->imgUV[0], + dec_picture); + init_cur_imgy(p_Vid, currSlice, PLANE_V); + currSlice->decode_one_component(currMB, PLANE_V, dec_picture->imgUV[1], + dec_picture); + } else { + currSlice->decode_one_component(currMB, PLANE_Y, dec_picture->imgY, + dec_picture); + currSlice->decode_one_component(currMB, PLANE_U, dec_picture->imgUV[0], + dec_picture); + currSlice->decode_one_component(currMB, PLANE_V, dec_picture->imgUV[1], + dec_picture); } currSlice->is_reset_coeff = FALSE; - } - else - { - currSlice->decode_one_component(currMB, PLANE_Y, dec_picture->imgY, dec_picture); + } else { + currSlice->decode_one_component(currMB, PLANE_Y, dec_picture->imgY, + dec_picture); } return 0; } - /*! ************************************************************************ * \brief @@ -6159,19 +5965,17 @@ int decode_one_macroblock(Macroblock *currMB, StorablePicture *dec_picture) * for 4:4:4 Independent mode ************************************************************************ */ -void change_plane_JV( VideoParameters *p_Vid, int nplane, Slice *pSlice) -{ - //Slice *currSlice = p_Vid->currentSlice; - //p_Vid->colour_plane_id = nplane; +void change_plane_JV(VideoParameters *p_Vid, int nplane, Slice *pSlice) { + // Slice *currSlice = p_Vid->currentSlice; + // p_Vid->colour_plane_id = nplane; p_Vid->mb_data = p_Vid->mb_data_JV[nplane]; - p_Vid->dec_picture = p_Vid->dec_picture_JV[nplane]; + p_Vid->dec_picture = p_Vid->dec_picture_JV[nplane]; p_Vid->siblock = p_Vid->siblock_JV[nplane]; p_Vid->ipredmode = p_Vid->ipredmode_JV[nplane]; p_Vid->intra_block = p_Vid->intra_block_JV[nplane]; - if(pSlice) - { + if (pSlice) { pSlice->mb_data = p_Vid->mb_data_JV[nplane]; - pSlice->dec_picture = p_Vid->dec_picture_JV[nplane]; + pSlice->dec_picture = p_Vid->dec_picture_JV[nplane]; pSlice->siblock = p_Vid->siblock_JV[nplane]; pSlice->ipredmode = p_Vid->ipredmode_JV[nplane]; pSlice->intra_block = p_Vid->intra_block_JV[nplane]; @@ -6185,30 +5989,31 @@ void change_plane_JV( VideoParameters *p_Vid, int nplane, Slice *pSlice) * for 4:4:4 Independent mode ************************************************************************ */ -void make_frame_picture_JV(VideoParameters *p_Vid) -{ +void make_frame_picture_JV(VideoParameters *p_Vid) { int uv, line; int nsize; p_Vid->dec_picture = p_Vid->dec_picture_JV[0]; - //copy; - if(p_Vid->dec_picture->used_for_reference && p_Vid->dec_picture->slice_type != I_SLICE && p_Vid->dec_picture->slice_type!=SI_SLICE) - { - nsize = (p_Vid->dec_picture->size_y/BLOCK_SIZE)*(p_Vid->dec_picture->size_x/BLOCK_SIZE)*sizeof(PicMotionParams); - memcpy( &(p_Vid->dec_picture->JVmv_info[PLANE_Y][0][0]), &(p_Vid->dec_picture_JV[PLANE_Y]->mv_info[0][0]), nsize); - memcpy( &(p_Vid->dec_picture->JVmv_info[PLANE_U][0][0]), &(p_Vid->dec_picture_JV[PLANE_U]->mv_info[0][0]), nsize); - memcpy( &(p_Vid->dec_picture->JVmv_info[PLANE_V][0][0]), &(p_Vid->dec_picture_JV[PLANE_V]->mv_info[0][0]), nsize); + // copy; + if (p_Vid->dec_picture->used_for_reference && + p_Vid->dec_picture->slice_type != I_SLICE && + p_Vid->dec_picture->slice_type != SI_SLICE) { + nsize = (p_Vid->dec_picture->size_y / BLOCK_SIZE) * + (p_Vid->dec_picture->size_x / BLOCK_SIZE) * sizeof(PicMotionParams); + memcpy(&(p_Vid->dec_picture->JVmv_info[PLANE_Y][0][0]), + &(p_Vid->dec_picture_JV[PLANE_Y]->mv_info[0][0]), nsize); + memcpy(&(p_Vid->dec_picture->JVmv_info[PLANE_U][0][0]), + &(p_Vid->dec_picture_JV[PLANE_U]->mv_info[0][0]), nsize); + memcpy(&(p_Vid->dec_picture->JVmv_info[PLANE_V][0][0]), + &(p_Vid->dec_picture_JV[PLANE_V]->mv_info[0][0]), nsize); } // This could be done with pointers and seems not necessary - for( uv=0; uv<2; uv++ ) - { - for( line=0; lineheight; line++ ) - { + for (uv = 0; uv < 2; uv++) { + for (line = 0; line < p_Vid->height; line++) { nsize = sizeof(imgpel) * p_Vid->width; - memcpy( p_Vid->dec_picture->imgUV[uv][line], p_Vid->dec_picture_JV[uv+1]->imgY[line], nsize ); + memcpy(p_Vid->dec_picture->imgUV[uv][line], + p_Vid->dec_picture_JV[uv + 1]->imgY[line], nsize); } - free_storable_picture(p_Vid->dec_picture_JV[uv+1]); + free_storable_picture(p_Vid->dec_picture_JV[uv + 1]); } } - - diff --git a/src/common/ldecod_src/mb_access.c b/src/common/ldecod_src/mb_access.c index 3865e13..e89fb03 100644 --- a/src/common/ldecod_src/mb_access.c +++ b/src/common/ldecod_src/mb_access.c @@ -7,14 +7,15 @@ * Functions for macroblock neighborhoods * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Karsten Shring ************************************************************************************* */ +#include "mb_access.h" #include "global.h" #include "mbuffer.h" -#include "mb_access.h" /*! ************************************************************************ @@ -22,16 +23,17 @@ * returns 1 if the macroblock at the given address is available ************************************************************************ */ -Boolean mb_is_available(int mbAddr, Macroblock *currMB) -{ - //VideoParameters *p_Vid = currMB->p_Vid; - if ((mbAddr < 0) || (mbAddr > ((int)currMB->p_Slice->dec_picture->PicSizeInMbs - 1))) //if ((mbAddr < 0) || (mbAddr > ((int)p_Vid->dec_picture->PicSizeInMbs - 1))) +Boolean mb_is_available(int mbAddr, Macroblock *currMB) { + // VideoParameters *p_Vid = currMB->p_Vid; + if ((mbAddr < 0) || + (mbAddr > ((int)currMB->p_Slice->dec_picture->PicSizeInMbs - + 1))) // if ((mbAddr < 0) || (mbAddr > + // ((int)p_Vid->dec_picture->PicSizeInMbs - 1))) return FALSE; // the following line checks both: slice number and if the mb has been decoded - if (!currMB->DeblockCall) - { - //if (p_Vid->mb_data[mbAddr].slice_nr != currMB->slice_nr) + if (!currMB->DeblockCall) { + // if (p_Vid->mb_data[mbAddr].slice_nr != currMB->slice_nr) if (currMB->p_Slice->mb_data[mbAddr].slice_nr != currMB->slice_nr) return FALSE; } @@ -39,7 +41,6 @@ Boolean mb_is_available(int mbAddr, Macroblock *currMB) return TRUE; } - /*! ************************************************************************ * \brief @@ -47,55 +48,57 @@ Boolean mb_is_available(int mbAddr, Macroblock *currMB) * the current macroblock for prediction and context determination; ************************************************************************ */ -void CheckAvailabilityOfNeighbors(Macroblock *currMB) -{ - //VideoParameters *p_Vid = currMB->p_Vid; - StorablePicture *dec_picture = currMB->p_Slice->dec_picture; //p_Vid->dec_picture; +void CheckAvailabilityOfNeighbors(Macroblock *currMB) { + // VideoParameters *p_Vid = currMB->p_Vid; + StorablePicture *dec_picture = + currMB->p_Slice->dec_picture; // p_Vid->dec_picture; const int mb_nr = currMB->mbAddrX; - if (dec_picture->mb_aff_frame_flag) - { + if (dec_picture->mb_aff_frame_flag) { int cur_mb_pair = mb_nr >> 1; currMB->mbAddrA = 2 * (cur_mb_pair - 1); currMB->mbAddrB = 2 * (cur_mb_pair - dec_picture->PicWidthInMbs); currMB->mbAddrC = 2 * (cur_mb_pair - dec_picture->PicWidthInMbs + 1); currMB->mbAddrD = 2 * (cur_mb_pair - dec_picture->PicWidthInMbs - 1); - currMB->mbAvailA = (Boolean) (mb_is_available(currMB->mbAddrA, currMB) && ((PicPos[cur_mb_pair ].x)!=0)); - currMB->mbAvailB = (Boolean) (mb_is_available(currMB->mbAddrB, currMB)); - currMB->mbAvailC = (Boolean) (mb_is_available(currMB->mbAddrC, currMB) && ((PicPos[cur_mb_pair + 1].x)!=0)); - currMB->mbAvailD = (Boolean) (mb_is_available(currMB->mbAddrD, currMB) && ((PicPos[cur_mb_pair ].x)!=0)); - } - else - { + currMB->mbAvailA = (Boolean)(mb_is_available(currMB->mbAddrA, currMB) && + ((PicPos[cur_mb_pair].x) != 0)); + currMB->mbAvailB = (Boolean)(mb_is_available(currMB->mbAddrB, currMB)); + currMB->mbAvailC = (Boolean)(mb_is_available(currMB->mbAddrC, currMB) && + ((PicPos[cur_mb_pair + 1].x) != 0)); + currMB->mbAvailD = (Boolean)(mb_is_available(currMB->mbAddrD, currMB) && + ((PicPos[cur_mb_pair].x) != 0)); + } else { currMB->mbAddrA = mb_nr - 1; currMB->mbAddrD = mb_nr - dec_picture->PicWidthInMbs - 1; currMB->mbAddrB = currMB->mbAddrD + 1; currMB->mbAddrC = currMB->mbAddrB + 1; - - currMB->mbAvailA = (Boolean) (mb_is_available(currMB->mbAddrA, currMB) && ((PicPos[mb_nr ].x)!=0)); - currMB->mbAvailD = (Boolean) (mb_is_available(currMB->mbAddrD, currMB) && ((PicPos[mb_nr ].x)!=0)); - currMB->mbAvailC = (Boolean) (mb_is_available(currMB->mbAddrC, currMB) && ((PicPos[mb_nr + 1].x)!=0)); - currMB->mbAvailB = (Boolean) (mb_is_available(currMB->mbAddrB, currMB)); + currMB->mbAvailA = (Boolean)(mb_is_available(currMB->mbAddrA, currMB) && + ((PicPos[mb_nr].x) != 0)); + currMB->mbAvailD = (Boolean)(mb_is_available(currMB->mbAddrD, currMB) && + ((PicPos[mb_nr].x) != 0)); + currMB->mbAvailC = (Boolean)(mb_is_available(currMB->mbAddrC, currMB) && + ((PicPos[mb_nr + 1].x) != 0)); + currMB->mbAvailB = (Boolean)(mb_is_available(currMB->mbAddrB, currMB)); } - currMB->mb_left = (currMB->mbAvailA) ? &(currMB->p_Slice->mb_data[currMB->mbAddrA]) : NULL; - currMB->mb_up = (currMB->mbAvailB) ? &(currMB->p_Slice->mb_data[currMB->mbAddrB]) : NULL; + currMB->mb_left = + (currMB->mbAvailA) ? &(currMB->p_Slice->mb_data[currMB->mbAddrA]) : NULL; + currMB->mb_up = + (currMB->mbAvailB) ? &(currMB->p_Slice->mb_data[currMB->mbAddrB]) : NULL; } - /*! ************************************************************************ * \brief * returns the x and y macroblock coordinates for a given MbAddress ************************************************************************ */ -void get_mb_block_pos_normal (int mb_addr, short *x, short *y) -{ - BlockPos *pPos = &PicPos[ mb_addr ]; - *x = (short) pPos->x; - *y = (short) pPos->y; +void get_mb_block_pos_normal(int mb_addr, short *x, short *y) { + BlockPos *pPos = &PicPos[mb_addr]; + *x = (short)pPos->x; + *y = (short)pPos->y; } /*! @@ -105,11 +108,10 @@ void get_mb_block_pos_normal (int mb_addr, short *x, short *y) * for mbaff type slices ************************************************************************ */ -void get_mb_block_pos_mbaff (int mb_addr, short *x, short *y) -{ - BlockPos *pPos = &PicPos[ mb_addr >> 1 ]; - *x = (short) pPos->x; - *y = (short) ((pPos->y << 1) + (mb_addr & 0x01)); +void get_mb_block_pos_mbaff(int mb_addr, short *x, short *y) { + BlockPos *pPos = &PicPos[mb_addr >> 1]; + *x = (short)pPos->x; + *y = (short)((pPos->y << 1) + (mb_addr & 0x01)); } /*! @@ -118,15 +120,14 @@ void get_mb_block_pos_mbaff (int mb_addr, short *x, short *y) * returns the x and y sample coordinates for a given MbAddress ************************************************************************ */ -void get_mb_pos (VideoParameters *p_Vid, int mb_addr, int mb_size[2], short *x, short *y) -{ +void get_mb_pos(VideoParameters *p_Vid, int mb_addr, int mb_size[2], short *x, + short *y) { p_Vid->get_mb_block_pos(mb_addr, x, y); - (*x) = (short) ((*x) * mb_size[0]); - (*y) = (short) ((*y) * mb_size[1]); + (*x) = (short)((*x) * mb_size[0]); + (*y) = (short)((*y) * mb_size[1]); } - /*! ************************************************************************ * \brief @@ -143,61 +144,43 @@ void get_mb_pos (VideoParameters *p_Vid, int mb_addr, int mb_size[2], short *x, * returns position informations ************************************************************************ */ -void getNonAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix) -{ +void getNonAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], + PixelPos *pix) { int maxW = mb_size[0], maxH = mb_size[1]; - if (xN < 0) - { - if (yN < 0) - { - pix->mb_addr = currMB->mbAddrD; + if (xN < 0) { + if (yN < 0) { + pix->mb_addr = currMB->mbAddrD; pix->available = currMB->mbAvailD; - } - else if (yN < maxH) - { - pix->mb_addr = currMB->mbAddrA; + } else if (yN < maxH) { + pix->mb_addr = currMB->mbAddrA; pix->available = currMB->mbAvailA; - } - else - { + } else { pix->available = FALSE; } - } - else if (xN < maxW) - { - if (yN < 0) - { - pix->mb_addr = currMB->mbAddrB; + } else if (xN < maxW) { + if (yN < 0) { + pix->mb_addr = currMB->mbAddrB; pix->available = currMB->mbAvailB; - } - else if (yN < maxH) - { - pix->mb_addr = currMB->mbAddrX; + } else if (yN < maxH) { + pix->mb_addr = currMB->mbAddrX; pix->available = TRUE; - } - else - { + } else { pix->available = FALSE; } - } - else if ((xN >= maxW) && (yN < 0)) - { - pix->mb_addr = currMB->mbAddrC; + } else if ((xN >= maxW) && (yN < 0)) { + pix->mb_addr = currMB->mbAddrC; pix->available = currMB->mbAvailC; - } - else - { + } else { pix->available = FALSE; } - if (pix->available || currMB->DeblockCall) - { - BlockPos *CurPos = &PicPos[ pix->mb_addr ]; - pix->x = (short) (xN & (maxW - 1)); - pix->y = (short) (yN & (maxH - 1)); - pix->pos_x = (short) (pix->x + CurPos->x * maxW); - pix->pos_y = (short) (pix->y + CurPos->y * maxH); + if (pix->available || currMB->DeblockCall) { + BlockPos *CurPos = &PicPos[pix->mb_addr]; + pix->x = (short)(xN & (maxW - 1)); + pix->y = (short)(yN & (maxH - 1)); + pix->pos_x = (short)(pix->x + CurPos->x * maxW); + pix->pos_y = (short)(pix->y + CurPos->y * maxH); } } @@ -217,8 +200,8 @@ void getNonAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], Pixe * returns position informations ************************************************************************ */ -void getAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix) -{ +void getAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], + PixelPos *pix) { VideoParameters *p_Vid = currMB->p_Vid; int maxW, maxH; int yM = -1; @@ -229,307 +212,216 @@ void getAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPo // initialize to "not available" pix->available = FALSE; - if(yN > (maxH - 1)) - { + if (yN > (maxH - 1)) { return; } - if (xN > (maxW - 1) && yN >= 0 && yN < maxH) - { + if (xN > (maxW - 1) && yN >= 0 && yN < maxH) { return; } - if (xN < 0) - { - if (yN < 0) - { - if(!currMB->mb_field) - { + if (xN < 0) { + if (yN < 0) { + if (!currMB->mb_field) { // frame - if ((currMB->mbAddrX & 0x01) == 0) - { + if ((currMB->mbAddrX & 0x01) == 0) { // top - pix->mb_addr = currMB->mbAddrD + 1; + pix->mb_addr = currMB->mbAddrD + 1; pix->available = currMB->mbAvailD; yM = yN; - } - else - { + } else { // bottom - pix->mb_addr = currMB->mbAddrA; + pix->mb_addr = currMB->mbAddrA; pix->available = currMB->mbAvailA; - if (currMB->mbAvailA) - { - if(!p_Vid->mb_data[currMB->mbAddrA].mb_field) - { - yM = yN; - } - else - { + if (currMB->mbAvailA) { + if (!p_Vid->mb_data[currMB->mbAddrA].mb_field) { + yM = yN; + } else { (pix->mb_addr)++; - yM = (yN + maxH) >> 1; + yM = (yN + maxH) >> 1; } } } - } - else - { + } else { // field - if ((currMB->mbAddrX & 0x01) == 0) - { + if ((currMB->mbAddrX & 0x01) == 0) { // top - pix->mb_addr = currMB->mbAddrD; + pix->mb_addr = currMB->mbAddrD; pix->available = currMB->mbAvailD; - if (currMB->mbAvailD) - { - if(!p_Vid->mb_data[currMB->mbAddrD].mb_field) - { + if (currMB->mbAvailD) { + if (!p_Vid->mb_data[currMB->mbAddrD].mb_field) { (pix->mb_addr)++; - yM = 2 * yN; - } - else - { - yM = yN; + yM = 2 * yN; + } else { + yM = yN; } } - } - else - { + } else { // bottom - pix->mb_addr = currMB->mbAddrD+1; + pix->mb_addr = currMB->mbAddrD + 1; pix->available = currMB->mbAvailD; yM = yN; } } - } - else - { // xN < 0 && yN >= 0 - if (yN >= 0 && yN mb_field) - { + } else { // xN < 0 && yN >= 0 + if (yN >= 0 && yN < maxH) { + if (!currMB->mb_field) { // frame - if ((currMB->mbAddrX & 0x01) == 0) - { + if ((currMB->mbAddrX & 0x01) == 0) { // top - pix->mb_addr = currMB->mbAddrA; + pix->mb_addr = currMB->mbAddrA; pix->available = currMB->mbAvailA; - if (currMB->mbAvailA) - { - if(!p_Vid->mb_data[currMB->mbAddrA].mb_field) - { - yM = yN; - } - else - { - (pix->mb_addr)+= ((yN & 0x01) != 0); + if (currMB->mbAvailA) { + if (!p_Vid->mb_data[currMB->mbAddrA].mb_field) { + yM = yN; + } else { + (pix->mb_addr) += ((yN & 0x01) != 0); yM = yN >> 1; } } - } - else - { + } else { // bottom - pix->mb_addr = currMB->mbAddrA; + pix->mb_addr = currMB->mbAddrA; pix->available = currMB->mbAvailA; - if (currMB->mbAvailA) - { - if(!p_Vid->mb_data[currMB->mbAddrA].mb_field) - { + if (currMB->mbAvailA) { + if (!p_Vid->mb_data[currMB->mbAddrA].mb_field) { (pix->mb_addr)++; - yM = yN; - } - else - { - (pix->mb_addr)+= ((yN & 0x01) != 0); + yM = yN; + } else { + (pix->mb_addr) += ((yN & 0x01) != 0); yM = (yN + maxH) >> 1; } } } - } - else - { + } else { // field - if ((currMB->mbAddrX & 0x01) == 0) - { + if ((currMB->mbAddrX & 0x01) == 0) { // top - pix->mb_addr = currMB->mbAddrA; + pix->mb_addr = currMB->mbAddrA; pix->available = currMB->mbAvailA; - if (currMB->mbAvailA) - { - if(!p_Vid->mb_data[currMB->mbAddrA].mb_field) - { - if (yN < (maxH >> 1)) - { - yM = yN << 1; - } - else - { + if (currMB->mbAvailA) { + if (!p_Vid->mb_data[currMB->mbAddrA].mb_field) { + if (yN < (maxH >> 1)) { + yM = yN << 1; + } else { (pix->mb_addr)++; - yM = (yN << 1 ) - maxH; + yM = (yN << 1) - maxH; } - } - else - { - yM = yN; + } else { + yM = yN; } } - } - else - { + } else { // bottom - pix->mb_addr = currMB->mbAddrA; + pix->mb_addr = currMB->mbAddrA; pix->available = currMB->mbAvailA; - if (currMB->mbAvailA) - { - if(!p_Vid->mb_data[currMB->mbAddrA].mb_field) - { - if (yN < (maxH >> 1)) - { + if (currMB->mbAvailA) { + if (!p_Vid->mb_data[currMB->mbAddrA].mb_field) { + if (yN < (maxH >> 1)) { yM = (yN << 1) + 1; - } - else - { + } else { (pix->mb_addr)++; - yM = (yN << 1 ) + 1 - maxH; + yM = (yN << 1) + 1 - maxH; } - } - else - { + } else { (pix->mb_addr)++; - yM = yN; - } - } - } - } - } - } - } - else - { // xN >= 0 - if (xN >= 0 && xN < maxW) - { - if (yN<0) - { - if (!currMB->mb_field) - { - //frame - if ((currMB->mbAddrX & 0x01) == 0) - { - //top - pix->mb_addr = currMB->mbAddrB; - // for the deblocker if the current MB is a frame and the one above is a field - // then the neighbor is the top MB of the pair - if (currMB->mbAvailB) - { - if (!(currMB->DeblockCall == 1 && (p_Vid->mb_data[currMB->mbAddrB]).mb_field)) - pix->mb_addr += 1; - } - - pix->available = currMB->mbAvailB; - yM = yN; - } - else - { - // bottom - pix->mb_addr = currMB->mbAddrX - 1; - pix->available = TRUE; - yM = yN; - } - } - else - { - // field - if ((currMB->mbAddrX & 0x01) == 0) - { - // top - pix->mb_addr = currMB->mbAddrB; - pix->available = currMB->mbAvailB; - if (currMB->mbAvailB) - { - if(!p_Vid->mb_data[currMB->mbAddrB].mb_field) - { - (pix->mb_addr)++; - yM = 2* yN; - } - else - { - yM = yN; - } - } - } - else - { - // bottom - pix->mb_addr = currMB->mbAddrB + 1; - pix->available = currMB->mbAvailB; - yM = yN; - } - } - } - else - { - // yN >=0 - // for the deblocker if this is the extra edge then do this special stuff - if (yN == 0 && currMB->DeblockCall == 2) - { - pix->mb_addr = currMB->mbAddrB + 1; - pix->available = TRUE; - yM = yN - 1; - } - - else if ((yN >= 0) && (yN mb_addr = currMB->mbAddrX; - pix->available = TRUE; - yM = yN; - } - } - } - else - { // xN >= maxW - if(yN < 0) - { - if (!currMB->mb_field) - { - // frame - if ((currMB->mbAddrX & 0x01) == 0) - { - // top - pix->mb_addr = currMB->mbAddrC + 1; - pix->available = currMB->mbAvailC; - yM = yN; - } - else - { - // bottom - pix->available = FALSE; - } - } - else - { - // field - if ((currMB->mbAddrX & 0x01) == 0) - { - // top - pix->mb_addr = currMB->mbAddrC; - pix->available = currMB->mbAvailC; - if (currMB->mbAvailC) - { - if(!p_Vid->mb_data[currMB->mbAddrC].mb_field) - { - (pix->mb_addr)++; - yM = 2* yN; - } - else - { yM = yN; } } } - else - { + } + } + } + } else { // xN >= 0 + if (xN >= 0 && xN < maxW) { + if (yN < 0) { + if (!currMB->mb_field) { + // frame + if ((currMB->mbAddrX & 0x01) == 0) { + // top + pix->mb_addr = currMB->mbAddrB; + // for the deblocker if the current MB is a frame and the one above + // is a field then the neighbor is the top MB of the pair + if (currMB->mbAvailB) { + if (!(currMB->DeblockCall == 1 && + (p_Vid->mb_data[currMB->mbAddrB]).mb_field)) + pix->mb_addr += 1; + } + + pix->available = currMB->mbAvailB; + yM = yN; + } else { // bottom - pix->mb_addr = currMB->mbAddrC + 1; + pix->mb_addr = currMB->mbAddrX - 1; + pix->available = TRUE; + yM = yN; + } + } else { + // field + if ((currMB->mbAddrX & 0x01) == 0) { + // top + pix->mb_addr = currMB->mbAddrB; + pix->available = currMB->mbAvailB; + if (currMB->mbAvailB) { + if (!p_Vid->mb_data[currMB->mbAddrB].mb_field) { + (pix->mb_addr)++; + yM = 2 * yN; + } else { + yM = yN; + } + } + } else { + // bottom + pix->mb_addr = currMB->mbAddrB + 1; + pix->available = currMB->mbAvailB; + yM = yN; + } + } + } else { + // yN >=0 + // for the deblocker if this is the extra edge then do this special + // stuff + if (yN == 0 && currMB->DeblockCall == 2) { + pix->mb_addr = currMB->mbAddrB + 1; + pix->available = TRUE; + yM = yN - 1; + } + + else if ((yN >= 0) && (yN < maxH)) { + pix->mb_addr = currMB->mbAddrX; + pix->available = TRUE; + yM = yN; + } + } + } else { // xN >= maxW + if (yN < 0) { + if (!currMB->mb_field) { + // frame + if ((currMB->mbAddrX & 0x01) == 0) { + // top + pix->mb_addr = currMB->mbAddrC + 1; + pix->available = currMB->mbAvailC; + yM = yN; + } else { + // bottom + pix->available = FALSE; + } + } else { + // field + if ((currMB->mbAddrX & 0x01) == 0) { + // top + pix->mb_addr = currMB->mbAddrC; + pix->available = currMB->mbAvailC; + if (currMB->mbAvailC) { + if (!p_Vid->mb_data[currMB->mbAddrC].mb_field) { + (pix->mb_addr)++; + yM = 2 * yN; + } else { + yM = yN; + } + } + } else { + // bottom + pix->mb_addr = currMB->mbAddrC + 1; pix->available = currMB->mbAvailC; yM = yN; } @@ -537,17 +429,15 @@ void getAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPo } } } - if (pix->available || currMB->DeblockCall) - { - pix->x = (short) (xN & (maxW - 1)); - pix->y = (short) (yM & (maxH - 1)); + if (pix->available || currMB->DeblockCall) { + pix->x = (short)(xN & (maxW - 1)); + pix->y = (short)(yM & (maxH - 1)); get_mb_pos(p_Vid, pix->mb_addr, mb_size, &(pix->pos_x), &(pix->pos_y)); pix->pos_x = pix->pos_x + pix->x; pix->pos_y = pix->pos_y + pix->y; } } - /*! ************************************************************************ * \brief @@ -564,12 +454,11 @@ void getAffNeighbour(Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPo * returns position informations ************************************************************************ */ -void get4x4Neighbour (Macroblock *currMB, int block_x, int block_y, int mb_size[2], PixelPos *pix) -{ +void get4x4Neighbour(Macroblock *currMB, int block_x, int block_y, + int mb_size[2], PixelPos *pix) { currMB->p_Vid->getNeighbour(currMB, block_x, block_y, mb_size, pix); - if (pix->available) - { + if (pix->available) { pix->x >>= 2; pix->y >>= 2; pix->pos_x >>= 2; @@ -593,12 +482,11 @@ void get4x4Neighbour (Macroblock *currMB, int block_x, int block_y, int mb_size[ * returns position informations ************************************************************************ */ -void get4x4NeighbourBase (Macroblock *currMB, int block_x, int block_y, int mb_size[2], PixelPos *pix) -{ +void get4x4NeighbourBase(Macroblock *currMB, int block_x, int block_y, + int mb_size[2], PixelPos *pix) { currMB->p_Vid->getNeighbour(currMB, block_x, block_y, mb_size, pix); - if (pix->available) - { + if (pix->available) { pix->x >>= 2; pix->y >>= 2; } diff --git a/src/common/ldecod_src/mb_prediction.c b/src/common/ldecod_src/mb_prediction.c index cd52b33..06f5941 100644 --- a/src/common/ldecod_src/mb_prediction.c +++ b/src/common/ldecod_src/mb_prediction.c @@ -6,78 +6,82 @@ * Macroblock prediction functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Alexis Michael Tourapis ************************************************************************************* */ #include "contributors.h" +#include "biaridecod.h" #include "block.h" -#include "global.h" -#include "mbuffer.h" +#include "cabac.h" #include "elements.h" #include "errorconcealment.h" -#include "macroblock.h" #include "fmo.h" -#include "cabac.h" -#include "vlc.h" +#include "global.h" #include "image.h" -#include "mb_access.h" -#include "biaridecod.h" -#include "transform8x8.h" -#include "transform.h" -#include "mc_prediction.h" -#include "quant.h" +#include "intra16x16_pred.h" #include "intra4x4_pred.h" #include "intra8x8_pred.h" -#include "intra16x16_pred.h" -#include "mv_prediction.h" +#include "macroblock.h" +#include "mb_access.h" #include "mb_prediction.h" +#include "mbuffer.h" +#include "mc_prediction.h" +#include "mv_prediction.h" +#include "quant.h" +#include "transform.h" +#include "transform8x8.h" +#include "vlc.h" -extern int get_colocated_info_8x8 (Macroblock *currMB, StorablePicture *list1, int i, int j); -extern int get_colocated_info_4x4 (Macroblock *currMB, StorablePicture *list1, int i, int j); +extern int get_colocated_info_8x8(Macroblock *currMB, StorablePicture *list1, + int i, int j); +extern int get_colocated_info_4x4(Macroblock *currMB, StorablePicture *list1, + int i, int j); - -int mb_pred_intra4x4(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ +int mb_pred_intra4x4(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, StorablePicture *dec_picture) { Slice *currSlice = currMB->p_Slice; int yuv = dec_picture->chroma_format_idc - 1; - int i=0, j=0,k, j4=0,i4=0; + int i = 0, j = 0, k, j4 = 0, i4 = 0; int j_pos, i_pos; - int ioff,joff; - int block8x8; // needed for ABT - currMB->itrans_4x4 = (currMB->is_lossless == FALSE) ? itrans4x4 : Inv_Residual_trans_4x4; + int ioff, joff; + int block8x8; // needed for ABT + currMB->itrans_4x4 = + (currMB->is_lossless == FALSE) ? itrans4x4 : Inv_Residual_trans_4x4; - for (block8x8 = 0; block8x8 < 4; block8x8++) - { - for (k = block8x8 * 4; k < block8x8 * 4 + 4; k ++) - { - i = (decode_block_scan[k] & 3); + for (block8x8 = 0; block8x8 < 4; block8x8++) { + for (k = block8x8 * 4; k < block8x8 * 4 + 4; k++) { + i = (decode_block_scan[k] & 3); j = ((decode_block_scan[k] >> 2) & 3); ioff = (i << 2); joff = (j << 2); - i4 = currMB->block_x + i; - j4 = currMB->block_y + j; + i4 = currMB->block_x + i; + j4 = currMB->block_y + j; j_pos = j4 * BLOCK_SIZE; i_pos = i4 * BLOCK_SIZE; // PREDICTION //===== INTRA PREDICTION ===== - if (intrapred(currMB, curr_plane, ioff,joff,i4,j4) == SEARCH_SYNC) /* make 4x4 prediction block mpr from given prediction p_Vid->mb_mode */ - return SEARCH_SYNC; /* bit error */ + if (intrapred(currMB, curr_plane, ioff, joff, i4, j4) == + SEARCH_SYNC) /* make 4x4 prediction block mpr from given prediction + p_Vid->mb_mode */ + return SEARCH_SYNC; /* bit error */ // =============== 4x4 itrans ================ // ------------------------------------------- - currMB->itrans_4x4 (currMB, curr_plane, ioff, joff); + currMB->itrans_4x4(currMB, curr_plane, ioff, joff); - copy_image_data_4x4(&currImg[j_pos], &currSlice->mb_rec[curr_plane][joff], i_pos, ioff); + copy_image_data_4x4(&currImg[j_pos], &currSlice->mb_rec[curr_plane][joff], + i_pos, ioff); } } // chroma decoding ******************************************************* - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { intra_cr_decoding(currMB, yuv); } @@ -86,20 +90,19 @@ int mb_pred_intra4x4(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg return 1; } - -int mb_pred_intra16x16(Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture) -{ +int mb_pred_intra16x16(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture) { int yuv = dec_picture->chroma_format_idc - 1; intrapred16x16(currMB, curr_plane, currMB->i16mode); - currMB->ipmode_DPCM = (signed char) currMB->i16mode; //For residual DPCM + currMB->ipmode_DPCM = (signed char)currMB->i16mode; // For residual DPCM // =============== 4x4 itrans ================ // ------------------------------------------- iMBtrans4x4(currMB, curr_plane, 0); // chroma decoding ******************************************************* - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { intra_cr_decoding(currMB, yuv); } @@ -107,157 +110,148 @@ int mb_pred_intra16x16(Macroblock *currMB, ColorPlane curr_plane, StorablePictur return 1; } -int mb_pred_intra8x8(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ +int mb_pred_intra8x8(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, StorablePicture *dec_picture) { Slice *currSlice = currMB->p_Slice; int yuv = dec_picture->chroma_format_idc - 1; - int block8x8; // needed for ABT - currMB->itrans_8x8 = (currMB->is_lossless == FALSE) ? itrans8x8 : Inv_Residual_trans_8x8; + int block8x8; // needed for ABT + currMB->itrans_8x8 = + (currMB->is_lossless == FALSE) ? itrans8x8 : Inv_Residual_trans_8x8; - for (block8x8 = 0; block8x8 < 4; block8x8++) - { + for (block8x8 = 0; block8x8 < 4; block8x8++) { //=========== 8x8 BLOCK TYPE ============ int ioff = (block8x8 & 0x01) << 3; - int joff = (block8x8 >> 1 ) << 3; + int joff = (block8x8 >> 1) << 3; - //PREDICTION + // PREDICTION intrapred8x8(currMB, curr_plane, ioff, joff); - currMB->itrans_8x8 (currMB, curr_plane, ioff,joff); // use inverse integer transform and make 8x8 block m7 from prediction block mpr + currMB->itrans_8x8(currMB, curr_plane, ioff, + joff); // use inverse integer transform and make 8x8 + // block m7 from prediction block mpr - copy_image_data_8x8(&currImg[currMB->pix_y + joff], &currSlice->mb_rec[curr_plane][joff], currMB->pix_x + ioff, ioff); + copy_image_data_8x8(&currImg[currMB->pix_y + joff], + &currSlice->mb_rec[curr_plane][joff], + currMB->pix_x + ioff, ioff); } // chroma decoding ******************************************************* - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { intra_cr_decoding(currMB, yuv); } - + if (currMB->cbp != 0) - currSlice->is_reset_coeff = FALSE; + currSlice->is_reset_coeff = FALSE; return 1; } - -static void set_chroma_vector(Macroblock *currMB) -{ +static void set_chroma_vector(Macroblock *currMB) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - if (!currSlice->mb_aff_frame_flag) - { - if(currSlice->structure == TOP_FIELD) - { - int k,l; - for (l = LIST_0; l <= (LIST_1); l++) - { - for(k = 0; k < currSlice->listXsize[l]; k++) - { - if(p_Vid->structure != (int) currSlice->listX[l][k]->structure) - currSlice->chroma_vector_adjustment[l][k] = -2; + if (!currSlice->mb_aff_frame_flag) { + if (currSlice->structure == TOP_FIELD) { + int k, l; + for (l = LIST_0; l <= (LIST_1); l++) { + for (k = 0; k < currSlice->listXsize[l]; k++) { + if (p_Vid->structure != (int)currSlice->listX[l][k]->structure) + currSlice->chroma_vector_adjustment[l][k] = -2; else - currSlice->chroma_vector_adjustment[l][k] = 0; + currSlice->chroma_vector_adjustment[l][k] = 0; } } - } - else if(currSlice->structure == BOTTOM_FIELD) - { - int k,l; - for (l = LIST_0; l <= (LIST_1); l++) - { - for(k = 0; k < currSlice->listXsize[l]; k++) - { - if (p_Vid->structure != (int) currSlice->listX[l][k]->structure) - currSlice->chroma_vector_adjustment[l][k] = 2; + } else if (currSlice->structure == BOTTOM_FIELD) { + int k, l; + for (l = LIST_0; l <= (LIST_1); l++) { + for (k = 0; k < currSlice->listXsize[l]; k++) { + if (p_Vid->structure != (int)currSlice->listX[l][k]->structure) + currSlice->chroma_vector_adjustment[l][k] = 2; else - currSlice->chroma_vector_adjustment[l][k] = 0; + currSlice->chroma_vector_adjustment[l][k] = 0; + } + } + } else { + int k, l; + for (l = LIST_0; l <= (LIST_1); l++) { + for (k = 0; k < currSlice->listXsize[l]; k++) { + currSlice->chroma_vector_adjustment[l][k] = 0; } } } - else - { - int k,l; - for (l = LIST_0; l <= (LIST_1); l++) - { - for(k = 0; k < currSlice->listXsize[l]; k++) - { - currSlice->chroma_vector_adjustment[l][k] = 0; - } - } - } - } - else - { + } else { int mb_nr = (currMB->mbAddrX & 0x01); - int k,l; + int k, l; ////////////////////////// // find out the correct list offsets - if (currMB->mb_field) - { + if (currMB->mb_field) { int list_offset = currMB->list_offset; - for (l = LIST_0 + list_offset; l <= (LIST_1 + list_offset); l++) - { - for(k = 0; k < currSlice->listXsize[l]; k++) - { - if(mb_nr == 0 && currSlice->listX[l][k]->structure == BOTTOM_FIELD) - currSlice->chroma_vector_adjustment[l][k] = -2; - else if(mb_nr == 1 && currSlice->listX[l][k]->structure == TOP_FIELD) - currSlice->chroma_vector_adjustment[l][k] = 2; + for (l = LIST_0 + list_offset; l <= (LIST_1 + list_offset); l++) { + for (k = 0; k < currSlice->listXsize[l]; k++) { + if (mb_nr == 0 && currSlice->listX[l][k]->structure == BOTTOM_FIELD) + currSlice->chroma_vector_adjustment[l][k] = -2; + else if (mb_nr == 1 && currSlice->listX[l][k]->structure == TOP_FIELD) + currSlice->chroma_vector_adjustment[l][k] = 2; else - currSlice->chroma_vector_adjustment[l][k] = 0; + currSlice->chroma_vector_adjustment[l][k] = 0; } } - } - else - { - for (l = LIST_0; l <= (LIST_1); l++) - { - for(k = 0; k < currSlice->listXsize[l]; k++) - { - currSlice->chroma_vector_adjustment[l][k] = 0; + } else { + for (l = LIST_0; l <= (LIST_1); l++) { + for (k = 0; k < currSlice->listXsize[l]; k++) { + currSlice->chroma_vector_adjustment[l][k] = 0; } } } } - currSlice->max_mb_vmv_r = (currSlice->structure != FRAME || ( currMB->mb_field )) ? p_Vid->max_vmv_r >> 1 : p_Vid->max_vmv_r; + currSlice->max_mb_vmv_r = + (currSlice->structure != FRAME || (currMB->mb_field)) + ? p_Vid->max_vmv_r >> 1 + : p_Vid->max_vmv_r; } -int mb_pred_skip(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ +int mb_pred_skip(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, + StorablePicture *dec_picture) { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; set_chroma_vector(currMB); - perform_mc(currMB, curr_plane, dec_picture, LIST_0, 0, 0, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + perform_mc(currMB, curr_plane, dec_picture, LIST_0, 0, 0, MB_BLOCK_SIZE, + MB_BLOCK_SIZE); - copy_image_data_16x16(&currImg[currMB->pix_y], currSlice->mb_pred[curr_plane], currMB->pix_x, 0); + copy_image_data_16x16(&currImg[currMB->pix_y], currSlice->mb_pred[curr_plane], + currMB->pix_x, 0); - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { - copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], currSlice->mb_pred[1], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); - copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], currSlice->mb_pred[2], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], + currSlice->mb_pred[1], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], + currSlice->mb_pred[2], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); } return 1; } -int mb_pred_sp_skip(Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture) -{ +int mb_pred_sp_skip(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture) { set_chroma_vector(currMB); - perform_mc(currMB, curr_plane, dec_picture, LIST_0, 0, 0, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + perform_mc(currMB, curr_plane, dec_picture, LIST_0, 0, 0, MB_BLOCK_SIZE, + MB_BLOCK_SIZE); iTransform(currMB, curr_plane, 1); return 1; } -int mb_pred_p_inter8x8(Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture) -{ - int block8x8; // needed for ABT - int i=0, j=0,k; +int mb_pred_p_inter8x8(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture) { + int block8x8; // needed for ABT + int i = 0, j = 0, k; Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; @@ -265,40 +259,29 @@ int mb_pred_p_inter8x8(Macroblock *currMB, ColorPlane curr_plane, StorablePictur set_chroma_vector(currMB); - for (block8x8=0; block8x8<4; block8x8++) - { - int mv_mode = currMB->b8mode[block8x8]; + for (block8x8 = 0; block8x8 < 4; block8x8++) { + int mv_mode = currMB->b8mode[block8x8]; int pred_dir = currMB->b8pdir[block8x8]; int k_start = (block8x8 << 2); int k_inc = (mv_mode == SMB8x4) ? 2 : 1; - int k_end = (mv_mode == SMB8x8) ? k_start + 1 : ((mv_mode == SMB4x4) ? k_start + 4 : k_start + k_inc + 1); + int k_end = (mv_mode == SMB8x8) + ? k_start + 1 + : ((mv_mode == SMB4x4) ? k_start + 4 : k_start + k_inc + 1); - int block_size_x = ( mv_mode == SMB8x4 || mv_mode == SMB8x8 ) ? SMB_BLOCK_SIZE : BLOCK_SIZE; - int block_size_y = ( mv_mode == SMB4x8 || mv_mode == SMB8x8 ) ? SMB_BLOCK_SIZE : BLOCK_SIZE; + int block_size_x = + (mv_mode == SMB8x4 || mv_mode == SMB8x8) ? SMB_BLOCK_SIZE : BLOCK_SIZE; + int block_size_y = + (mv_mode == SMB4x8 || mv_mode == SMB8x8) ? SMB_BLOCK_SIZE : BLOCK_SIZE; - for (k = k_start; k < k_end; k += k_inc) - { - i = (decode_block_scan[k] & 3); + for (k = k_start; k < k_end; k += k_inc) { + i = (decode_block_scan[k] & 3); j = ((decode_block_scan[k] >> 2) & 3); - perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, block_size_x, block_size_y); - } + perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, block_size_x, + block_size_y); + } } - iTransform(currMB, curr_plane, smb); - - if (currMB->cbp != 0) - currSlice->is_reset_coeff = FALSE; - return 1; -} - -int mb_pred_p_inter16x16(Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture) -{ - int smb = (currMB->p_Vid->type == SP_SLICE); - Slice *currSlice = currMB->p_Slice; - - set_chroma_vector(currMB); - perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[0], 0, 0, MB_BLOCK_SIZE, MB_BLOCK_SIZE); iTransform(currMB, curr_plane, smb); if (currMB->cbp != 0) @@ -306,31 +289,14 @@ int mb_pred_p_inter16x16(Macroblock *currMB, ColorPlane curr_plane, StorablePict return 1; } -int mb_pred_p_inter16x8(Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture) -{ +int mb_pred_p_inter16x16(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture) { int smb = (currMB->p_Vid->type == SP_SLICE); Slice *currSlice = currMB->p_Slice; set_chroma_vector(currMB); - - perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[0], 0, 0, MB_BLOCK_SIZE, BLOCK_SIZE_8x8); - perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[2], 0, 2, MB_BLOCK_SIZE, BLOCK_SIZE_8x8); - iTransform(currMB, curr_plane, smb); - - if (currMB->cbp != 0) - currSlice->is_reset_coeff = FALSE; - return 1; -} - -int mb_pred_p_inter8x16(Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture) -{ - int smb = (currMB->p_Vid->type == SP_SLICE); - Slice *currSlice = currMB->p_Slice; - - set_chroma_vector(currMB); - - perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[0], 0, 0, BLOCK_SIZE_8x8, MB_BLOCK_SIZE); - perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[1], 2, 0, BLOCK_SIZE_8x8, MB_BLOCK_SIZE); + perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[0], 0, 0, + MB_BLOCK_SIZE, MB_BLOCK_SIZE); iTransform(currMB, curr_plane, smb); if (currMB->cbp != 0) @@ -338,303 +304,367 @@ int mb_pred_p_inter8x16(Macroblock *currMB, ColorPlane curr_plane, StorablePictu return 1; } -static inline void update_neighbor_mvs(PicMotionParams **motion, const PicMotionParams *mv_info, int i4) -{ +int mb_pred_p_inter16x8(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture) { + int smb = (currMB->p_Vid->type == SP_SLICE); + Slice *currSlice = currMB->p_Slice; + + set_chroma_vector(currMB); + + perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[0], 0, 0, + MB_BLOCK_SIZE, BLOCK_SIZE_8x8); + perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[2], 0, 2, + MB_BLOCK_SIZE, BLOCK_SIZE_8x8); + iTransform(currMB, curr_plane, smb); + + if (currMB->cbp != 0) + currSlice->is_reset_coeff = FALSE; + return 1; +} + +int mb_pred_p_inter8x16(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture) { + int smb = (currMB->p_Vid->type == SP_SLICE); + Slice *currSlice = currMB->p_Slice; + + set_chroma_vector(currMB); + + perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[0], 0, 0, + BLOCK_SIZE_8x8, MB_BLOCK_SIZE); + perform_mc(currMB, curr_plane, dec_picture, currMB->b8pdir[1], 2, 0, + BLOCK_SIZE_8x8, MB_BLOCK_SIZE); + iTransform(currMB, curr_plane, smb); + + if (currMB->cbp != 0) + currSlice->is_reset_coeff = FALSE; + return 1; +} + +static inline void update_neighbor_mvs(PicMotionParams **motion, + const PicMotionParams *mv_info, int i4) { (*motion++)[i4 + 1] = *mv_info; - (*motion )[i4 ] = *mv_info; - (*motion )[i4 + 1] = *mv_info; + (*motion)[i4] = *mv_info; + (*motion)[i4 + 1] = *mv_info; } -int mb_pred_b_d8x8temporal(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ +int mb_pred_b_d8x8temporal(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, StorablePicture *dec_picture) { short ref_idx; int refList; int k, i, j, i4, j4, j6; - int block8x8; // needed for ABT + int block8x8; // needed for ABT Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; PicMotionParams *mv_info = NULL, *colocated = NULL; - + int list_offset = currMB->list_offset; StorablePicture **list0 = currSlice->listX[LIST_0 + list_offset]; StorablePicture **list1 = currSlice->listX[LIST_1 + list_offset]; set_chroma_vector(currMB); - //printf("currMB %d\n", currMB->mbAddrX); - for (block8x8=0; block8x8<4; block8x8++) - { + // printf("currMB %d\n", currMB->mbAddrX); + for (block8x8 = 0; block8x8 < 4; block8x8++) { int pred_dir = currMB->b8pdir[block8x8]; int k_start = (block8x8 << 2); int k_end = k_start + 1; - for (k = k_start; k < k_start + BLOCK_MULTIPLE; k ++) - { + for (k = k_start; k < k_start + BLOCK_MULTIPLE; k++) { - i = (decode_block_scan[k] & 3); + i = (decode_block_scan[k] & 3); j = ((decode_block_scan[k] >> 2) & 3); - i4 = currMB->block_x + i; - j4 = currMB->block_y + j; - j6 = currMB->block_y_aff + j; + i4 = currMB->block_x + i; + j4 = currMB->block_y + j; + j6 = currMB->block_y_aff + j; mv_info = &dec_picture->mv_info[j4][i4]; colocated = &list1[0]->mv_info[RSD(j6)][RSD(i4)]; if(currSlice->mb_aff_frame_flag /*&& (!p_Vid->active_sps->frame_mbs_only_flag || p_Vid->active_sps->direct_8x8_inference_flag)*/) { assert(p_Vid->active_sps->direct_8x8_inference_flag); - if(!currMB->mb_field && ((currSlice->listX[LIST_1][0]->iCodingType==FRAME_MB_PAIR_CODING && currSlice->listX[LIST_1][0]->motion.mb_field[currMB->mbAddrX]) || - (currSlice->listX[LIST_1][0]->iCodingType==FIELD_CODING))) - { - if (iabs(dec_picture->poc - currSlice->listX[LIST_1+4][0]->poc)> iabs(dec_picture->poc -currSlice->listX[LIST_1+2][0]->poc) ) - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &currSlice->listX[LIST_1+2][0]->mv_info[RSD(j6)>>1][RSD(i4)] : &currSlice->listX[LIST_1+2][0]->mv_info[j6>>1][i4]; - } - else - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &currSlice->listX[LIST_1+4][0]->mv_info[RSD(j6)>>1][RSD(i4)] : &currSlice->listX[LIST_1+4][0]->mv_info[j6>>1][i4]; + if (!currMB->mb_field && + ((currSlice->listX[LIST_1][0]->iCodingType == + FRAME_MB_PAIR_CODING && + currSlice->listX[LIST_1][0]->motion.mb_field[currMB->mbAddrX]) || + (currSlice->listX[LIST_1][0]->iCodingType == FIELD_CODING))) { + if (iabs(dec_picture->poc - currSlice->listX[LIST_1 + 4][0]->poc) > + iabs(dec_picture->poc - currSlice->listX[LIST_1 + 2][0]->poc)) { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &currSlice->listX[LIST_1 + 2][0] + ->mv_info[RSD(j6) >> 1][RSD(i4)] + : &currSlice->listX[LIST_1 + 2][0]->mv_info[j6 >> 1][i4]; + } else { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &currSlice->listX[LIST_1 + 4][0] + ->mv_info[RSD(j6) >> 1][RSD(i4)] + : &currSlice->listX[LIST_1 + 4][0]->mv_info[j6 >> 1][i4]; } } + } else if (/*!currSlice->mb_aff_frame_flag &&*/ !p_Vid->active_sps + ->frame_mbs_only_flag && + (!currSlice->field_pic_flag && + currSlice->listX[LIST_1][0]->iCodingType != FRAME_CODING)) { + if (iabs(dec_picture->poc - list1[0]->bottom_field->poc) > + iabs(dec_picture->poc - list1[0]->top_field->poc)) { + colocated = p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->top_field->mv_info[RSD(j6) >> 1][RSD(i4)] + : &list1[0]->top_field->mv_info[j6 >> 1][i4]; + } else { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->bottom_field->mv_info[RSD(j6) >> 1][RSD(i4)] + : &list1[0]->bottom_field->mv_info[j6 >> 1][i4]; + } + } else if (!p_Vid->active_sps->frame_mbs_only_flag && + currSlice->field_pic_flag && + currSlice->structure != list1[0]->structure && + list1[0]->coded_frame) { + if (currSlice->structure == TOP_FIELD) { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->frame->top_field->mv_info[RSD(j6)][RSD(i4)] + : &list1[0]->frame->top_field->mv_info[j6][i4]; + } else { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->frame->bottom_field->mv_info[RSD(j6)][RSD(i4)] + : &list1[0]->frame->bottom_field->mv_info[j6][i4]; + } } - else if(/*!currSlice->mb_aff_frame_flag &&*/ !p_Vid->active_sps->frame_mbs_only_flag && - (!currSlice->field_pic_flag && currSlice->listX[LIST_1][0]->iCodingType!=FRAME_CODING)) - { - if (iabs(dec_picture->poc - list1[0]->bottom_field->poc)> iabs(dec_picture->poc -list1[0]->top_field->poc) ) - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->top_field->mv_info[RSD(j6)>>1][RSD(i4)] : &list1[0]->top_field->mv_info[j6>>1][i4]; - } - else - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->bottom_field->mv_info[RSD(j6)>>1][RSD(i4)] : &list1[0]->bottom_field->mv_info[j6>>1][i4]; - } - } - else if(!p_Vid->active_sps->frame_mbs_only_flag && currSlice->field_pic_flag && currSlice->structure!=list1[0]->structure && list1[0]->coded_frame) - { - if (currSlice->structure == TOP_FIELD) - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->frame->top_field->mv_info[RSD(j6)][RSD(i4)] : &list1[0]->frame->top_field->mv_info[j6][i4]; - } - else - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->frame->bottom_field->mv_info[RSD(j6)][RSD(i4)] : &list1[0]->frame->bottom_field->mv_info[j6][i4]; - } - } - - assert (pred_dir<=2); + assert(pred_dir <= 2); - refList = (colocated->ref_idx[LIST_0]== -1 ? LIST_1 : LIST_0); - ref_idx = colocated->ref_idx[refList]; + refList = (colocated->ref_idx[LIST_0] == -1 ? LIST_1 : LIST_0); + ref_idx = colocated->ref_idx[refList]; - if(ref_idx==-1) // co-located is intra mode + if (ref_idx == -1) // co-located is intra mode { mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; mv_info->ref_idx[LIST_1] = 0; - } - else // co-located skip or inter mode + } else // co-located skip or inter mode { - int mapped_idx=0; + int mapped_idx = 0; int iref; - if( (currSlice->mb_aff_frame_flag && ( (currMB->mb_field && colocated->ref_pic[refList]->structure==FRAME) || - (!currMB->mb_field && colocated->ref_pic[refList]->structure!=FRAME))) || - (!currSlice->mb_aff_frame_flag && ((currSlice->field_pic_flag==0 && colocated->ref_pic[refList]->structure!=FRAME) - ||(currSlice->field_pic_flag==1 && colocated->ref_pic[refList]->structure==FRAME))) ) - { - for (iref = 0; iref < imin(currSlice->num_ref_idx_active[LIST_0], currSlice->listXsize[LIST_0 + list_offset]);iref++) - { - if(currSlice->listX[LIST_0 + list_offset][iref]->top_field == colocated->ref_pic[refList] || - currSlice->listX[LIST_0 + list_offset][iref]->bottom_field == colocated->ref_pic[refList] || - currSlice->listX[LIST_0 + list_offset][iref]->frame == colocated->ref_pic[refList]) - { - mapped_idx = iref; + if ((currSlice->mb_aff_frame_flag && + ((currMB->mb_field && + colocated->ref_pic[refList]->structure == FRAME) || + (!currMB->mb_field && + colocated->ref_pic[refList]->structure != FRAME))) || + (!currSlice->mb_aff_frame_flag && + ((currSlice->field_pic_flag == 0 && + colocated->ref_pic[refList]->structure != FRAME) || + (currSlice->field_pic_flag == 1 && + colocated->ref_pic[refList]->structure == FRAME)))) { + for (iref = 0; + iref < imin(currSlice->num_ref_idx_active[LIST_0], + currSlice->listXsize[LIST_0 + list_offset]); + iref++) { + if (currSlice->listX[LIST_0 + list_offset][iref]->top_field == + colocated->ref_pic[refList] || + currSlice->listX[LIST_0 + list_offset][iref]->bottom_field == + colocated->ref_pic[refList] || + currSlice->listX[LIST_0 + list_offset][iref]->frame == + colocated->ref_pic[refList]) { + mapped_idx = iref; break; - } - else //! invalid index. Default to zero even though this case should not happen + } else //! invalid index. Default to zero even though this case + //! should not happen { - mapped_idx=INVALIDINDEX; + mapped_idx = INVALIDINDEX; } } - } - else - { - for (iref = 0; iref < imin(currSlice->num_ref_idx_active[LIST_0], currSlice->listXsize[LIST_0 + list_offset]);iref++) - { - if(currSlice->listX[LIST_0 + list_offset][iref] == colocated->ref_pic[refList]) - { - mapped_idx = iref; + } else { + for (iref = 0; + iref < imin(currSlice->num_ref_idx_active[LIST_0], + currSlice->listXsize[LIST_0 + list_offset]); + iref++) { + if (currSlice->listX[LIST_0 + list_offset][iref] == + colocated->ref_pic[refList]) { + mapped_idx = iref; break; - } - else //! invalid index. Default to zero even though this case should not happen + } else //! invalid index. Default to zero even though this case + //! should not happen { - mapped_idx=INVALIDINDEX; + mapped_idx = INVALIDINDEX; } } } - if(INVALIDINDEX != mapped_idx) - { + if (INVALIDINDEX != mapped_idx) { int mv_scale = currSlice->mvscale[LIST_0 + list_offset][mapped_idx]; - int mv_y = colocated->mv[refList].mv_y; - if((currSlice->mb_aff_frame_flag && !currMB->mb_field && colocated->ref_pic[refList]->structure!=FRAME) || - (!currSlice->mb_aff_frame_flag && currSlice->field_pic_flag==0 && colocated->ref_pic[refList]->structure!=FRAME) ) + int mv_y = colocated->mv[refList].mv_y; + if ((currSlice->mb_aff_frame_flag && !currMB->mb_field && + colocated->ref_pic[refList]->structure != FRAME) || + (!currSlice->mb_aff_frame_flag && + currSlice->field_pic_flag == 0 && + colocated->ref_pic[refList]->structure != FRAME)) mv_y *= 2; - else if((currSlice->mb_aff_frame_flag && currMB->mb_field && colocated->ref_pic[refList]->structure==FRAME) || - (!currSlice->mb_aff_frame_flag && currSlice->field_pic_flag==1 && colocated->ref_pic[refList]->structure==FRAME) ) + else if ((currSlice->mb_aff_frame_flag && currMB->mb_field && + colocated->ref_pic[refList]->structure == FRAME) || + (!currSlice->mb_aff_frame_flag && + currSlice->field_pic_flag == 1 && + colocated->ref_pic[refList]->structure == FRAME)) mv_y /= 2; //! In such case, an array is needed for each different reference. - if (mv_scale == 9999 || currSlice->listX[LIST_0 + list_offset][mapped_idx]->is_long_term) - { + if (mv_scale == 9999 || + currSlice->listX[LIST_0 + list_offset][mapped_idx] + ->is_long_term) { mv_info->mv[LIST_0].mv_x = colocated->mv[refList].mv_x; - mv_info->mv[LIST_0].mv_y = (short) mv_y; + mv_info->mv[LIST_0].mv_y = (short)mv_y; mv_info->mv[LIST_1] = zero_mv; - } - else - { - mv_info->mv[LIST_0].mv_x = (short) ((mv_scale * colocated->mv[refList].mv_x + 128 ) >> 8); - mv_info->mv[LIST_0].mv_y = (short) ((mv_scale * mv_y/*colocated->mv[refList].mv_y*/ + 128 ) >> 8); + } else { + mv_info->mv[LIST_0].mv_x = + (short)((mv_scale * colocated->mv[refList].mv_x + 128) >> 8); + mv_info->mv[LIST_0].mv_y = + (short)((mv_scale * mv_y /*colocated->mv[refList].mv_y*/ + + 128) >> + 8); - mv_info->mv[LIST_1].mv_x = (short) (mv_info->mv[LIST_0].mv_x - colocated->mv[refList].mv_x); - mv_info->mv[LIST_1].mv_y = (short) (mv_info->mv[LIST_0].mv_y - mv_y/*colocated->mv[refList].mv_y*/); + mv_info->mv[LIST_1].mv_x = + (short)(mv_info->mv[LIST_0].mv_x - colocated->mv[refList].mv_x); + mv_info->mv[LIST_1].mv_y = + (short)(mv_info->mv[LIST_0].mv_y - + mv_y /*colocated->mv[refList].mv_y*/); } - mv_info->ref_idx[LIST_0] = (signed char) mapped_idx; //colocated->ref_idx[refList]; + mv_info->ref_idx[LIST_0] = + (signed char)mapped_idx; // colocated->ref_idx[refList]; mv_info->ref_idx[LIST_1] = 0; + } else if (INVALIDINDEX == mapped_idx) { + error("temporal direct error: colocated block has ref that is " + "unavailable", + -1111); } - else if (INVALIDINDEX == mapped_idx) - { - error("temporal direct error: colocated block has ref that is unavailable",-1111); - } - } // store reference picture ID determined by direct mode mv_info->ref_pic[LIST_0] = list0[(short)mv_info->ref_idx[LIST_0]]; mv_info->ref_pic[LIST_1] = list1[(short)mv_info->ref_idx[LIST_1]]; } - for (k = k_start; k < k_end; k ++) - { - int i = (decode_block_scan[k] & 3); + for (k = k_start; k < k_end; k++) { + int i = (decode_block_scan[k] & 3); int j = ((decode_block_scan[k] >> 2) & 3); - perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, SMB_BLOCK_SIZE, SMB_BLOCK_SIZE); + perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, + SMB_BLOCK_SIZE, SMB_BLOCK_SIZE); } } - if (currMB->cbp == 0) - { - copy_image_data_16x16(&currImg[currMB->pix_y], currSlice->mb_pred[curr_plane], currMB->pix_x, 0); + if (currMB->cbp == 0) { + copy_image_data_16x16(&currImg[currMB->pix_y], + currSlice->mb_pred[curr_plane], currMB->pix_x, 0); - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { - copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], currSlice->mb_pred[1], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); - copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], currSlice->mb_pred[2], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { + copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], + currSlice->mb_pred[1], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], + currSlice->mb_pred[2], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); } - } - else - { - iTransform(currMB, curr_plane, 0); + } else { + iTransform(currMB, curr_plane, 0); currSlice->is_reset_coeff = FALSE; } return 1; } -int mb_pred_b_d4x4temporal(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ +int mb_pred_b_d4x4temporal(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, StorablePicture *dec_picture) { short ref_idx; int refList; int k; - int block8x8; // needed for ABT + int block8x8; // needed for ABT Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - + int list_offset = currMB->list_offset; StorablePicture **list0 = currSlice->listX[LIST_0 + list_offset]; StorablePicture **list1 = currSlice->listX[LIST_1 + list_offset]; set_chroma_vector(currMB); - for (block8x8=0; block8x8<4; block8x8++) - { + for (block8x8 = 0; block8x8 < 4; block8x8++) { int pred_dir = currMB->b8pdir[block8x8]; int k_start = (block8x8 << 2); int k_end = k_start + BLOCK_MULTIPLE; - for (k = k_start; k < k_end; k ++) - { + for (k = k_start; k < k_end; k++) { - int i = (decode_block_scan[k] & 3); + int i = (decode_block_scan[k] & 3); int j = ((decode_block_scan[k] >> 2) & 3); - int i4 = currMB->block_x + i; - int j4 = currMB->block_y + j; - int j6 = currMB->block_y_aff + j; + int i4 = currMB->block_x + i; + int j4 = currMB->block_y + j; + int j6 = currMB->block_y_aff + j; PicMotionParams *mv_info = &dec_picture->mv_info[j4][i4]; PicMotionParams *colocated = &list1[0]->mv_info[j6][i4]; - assert (pred_dir<=2); + assert(pred_dir <= 2); - refList = (colocated->ref_idx[LIST_0]== -1 ? LIST_1 : LIST_0); - ref_idx = colocated->ref_idx[refList]; + refList = (colocated->ref_idx[LIST_0] == -1 ? LIST_1 : LIST_0); + ref_idx = colocated->ref_idx[refList]; - if(ref_idx==-1) // co-located is intra mode + if (ref_idx == -1) // co-located is intra mode { mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; mv_info->ref_idx[LIST_1] = 0; - } - else // co-located skip or inter mode + } else // co-located skip or inter mode { - int mapped_idx=0; + int mapped_idx = 0; int iref; - for (iref=0;irefnum_ref_idx_active[LIST_0], currSlice->listXsize[LIST_0 + list_offset]);iref++) - { - if(currSlice->listX[LIST_0 + list_offset][iref] == colocated->ref_pic[refList]) - { - mapped_idx=iref; + for (iref = 0; iref < imin(currSlice->num_ref_idx_active[LIST_0], + currSlice->listXsize[LIST_0 + list_offset]); + iref++) { + if (currSlice->listX[LIST_0 + list_offset][iref] == + colocated->ref_pic[refList]) { + mapped_idx = iref; break; - } - else //! invalid index. Default to zero even though this case should not happen + } else //! invalid index. Default to zero even though this case should + //! not happen { - mapped_idx=INVALIDINDEX; + mapped_idx = INVALIDINDEX; } } - if (INVALIDINDEX == mapped_idx) - { - error("temporal direct error: colocated block has ref that is unavailable",-1111); - } - else - { + if (INVALIDINDEX == mapped_idx) { + error("temporal direct error: colocated block has ref that is " + "unavailable", + -1111); + } else { int mv_scale = currSlice->mvscale[LIST_0 + list_offset][mapped_idx]; //! In such case, an array is needed for each different reference. - if (mv_scale == 9999 || currSlice->listX[LIST_0+list_offset][mapped_idx]->is_long_term) - { + if (mv_scale == 9999 || + currSlice->listX[LIST_0 + list_offset][mapped_idx] + ->is_long_term) { mv_info->mv[LIST_0] = colocated->mv[refList]; mv_info->mv[LIST_1] = zero_mv; - } - else - { - mv_info->mv[LIST_0].mv_x = (short) ((mv_scale * colocated->mv[refList].mv_x + 128 ) >> 8); - mv_info->mv[LIST_0].mv_y = (short) ((mv_scale * colocated->mv[refList].mv_y + 128 ) >> 8); + } else { + mv_info->mv[LIST_0].mv_x = + (short)((mv_scale * colocated->mv[refList].mv_x + 128) >> 8); + mv_info->mv[LIST_0].mv_y = + (short)((mv_scale * colocated->mv[refList].mv_y + 128) >> 8); - mv_info->mv[LIST_1].mv_x = (short) (mv_info->mv[LIST_0].mv_x - colocated->mv[refList].mv_x); - mv_info->mv[LIST_1].mv_y = (short) (mv_info->mv[LIST_0].mv_y - colocated->mv[refList].mv_y); + mv_info->mv[LIST_1].mv_x = + (short)(mv_info->mv[LIST_0].mv_x - colocated->mv[refList].mv_x); + mv_info->mv[LIST_1].mv_y = + (short)(mv_info->mv[LIST_0].mv_y - colocated->mv[refList].mv_y); } - mv_info->ref_idx[LIST_0] = (signed char) mapped_idx; //colocated->ref_idx[refList]; + mv_info->ref_idx[LIST_0] = + (signed char)mapped_idx; // colocated->ref_idx[refList]; mv_info->ref_idx[LIST_1] = 0; } } @@ -643,37 +673,37 @@ int mb_pred_b_d4x4temporal(Macroblock *currMB, ColorPlane curr_plane, imgpel **c mv_info->ref_pic[LIST_1] = list1[(short)mv_info->ref_idx[LIST_1]]; } - for (k = k_start; k < k_end; k ++) - { - int i = (decode_block_scan[k] & 3); + for (k = k_start; k < k_end; k++) { + int i = (decode_block_scan[k] & 3); int j = ((decode_block_scan[k] >> 2) & 3); - perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, BLOCK_SIZE, BLOCK_SIZE); - + perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, BLOCK_SIZE, + BLOCK_SIZE); } } - if (currMB->cbp == 0) - { - copy_image_data_16x16(&currImg[currMB->pix_y], currSlice->mb_pred[curr_plane], currMB->pix_x, 0); + if (currMB->cbp == 0) { + copy_image_data_16x16(&currImg[currMB->pix_y], + currSlice->mb_pred[curr_plane], currMB->pix_x, 0); - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { - copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], currSlice->mb_pred[1], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); - copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], currSlice->mb_pred[2], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { + copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], + currSlice->mb_pred[1], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], + currSlice->mb_pred[2], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); } - } - else - { - iTransform(currMB, curr_plane, 0); + } else { + iTransform(currMB, curr_plane, 0); currSlice->is_reset_coeff = FALSE; } return 1; } - -int mb_pred_b_d8x8spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ +int mb_pred_b_d8x8spatial(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, StorablePicture *dec_picture) { signed char l0_rFrame = -1, l1_rFrame = -1; MotionVector pmvl0 = zero_mv, pmvl1 = zero_mv; int i4, j4; @@ -690,40 +720,36 @@ int mb_pred_b_d8x8spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **cu set_chroma_vector(currMB); - prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, &l1_rFrame); + prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, + &l1_rFrame); - if (l0_rFrame == 0 || l1_rFrame == 0) - { + if (l0_rFrame == 0 || l1_rFrame == 0) { int is_not_moving; - - for (block8x8 = 0; block8x8 < 4; block8x8++) - { + + for (block8x8 = 0; block8x8 < 4; block8x8++) { int k_start = (block8x8 << 2); - int i = (decode_block_scan[k_start] & 3); - int j = ((decode_block_scan[k_start] >> 2) & 3); - i4 = currMB->block_x + i; - j4 = currMB->block_y + j; + int i = (decode_block_scan[k_start] & 3); + int j = ((decode_block_scan[k_start] >> 2) & 3); + i4 = currMB->block_x + i; + j4 = currMB->block_y + j; - is_not_moving = (get_colocated_info_8x8(currMB, list1[0], i4, currMB->block_y_aff + j) == 0); + is_not_moving = (get_colocated_info_8x8(currMB, list1[0], i4, + currMB->block_y_aff + j) == 0); mv_info = &dec_picture->mv_info[j4][i4]; //===== DIRECT PREDICTION ===== - if (l1_rFrame == -1) - { - if (is_not_moving) - { + if (l1_rFrame == -1) { + if (is_not_moving) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; mv_info->ref_idx[LIST_1] = -1; - } - else - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + } else { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = zero_mv; @@ -731,71 +757,56 @@ int mb_pred_b_d8x8spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **cu mv_info->ref_idx[LIST_1] = -1; } pred_dir = 0; - } - else if (l0_rFrame == -1) - { - if (is_not_moving) - { + } else if (l0_rFrame == -1) { + if (is_not_moving) { mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = 0; - } - else - { - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; - mv_info->mv[LIST_0] = zero_mv; + } else { + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; + mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = l1_rFrame; } pred_dir = 1; - } - else - { - if (l0_rFrame == 0 && ((is_not_moving))) - { + } else { + if (l0_rFrame == 0 && ((is_not_moving))) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->ref_idx[LIST_0] = 0; - } - else - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + } else { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->mv[LIST_0] = pmvl0; mv_info->ref_idx[LIST_0] = l0_rFrame; } - if (l1_rFrame == 0 && ((is_not_moving))) - { + if (l1_rFrame == 0 && ((is_not_moving))) { mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_1] = zero_mv; - mv_info->ref_idx[LIST_1] = 0; - } - else - { - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_idx[LIST_1] = 0; + } else { + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_1] = pmvl1; - mv_info->ref_idx[LIST_1] = l1_rFrame; - } + mv_info->ref_idx[LIST_1] = l1_rFrame; + } pred_dir = 2; } update_neighbor_mvs(&dec_picture->mv_info[j4], mv_info, i4); - perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, SMB_BLOCK_SIZE, SMB_BLOCK_SIZE); + perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, + SMB_BLOCK_SIZE, SMB_BLOCK_SIZE); } - } - else - { + } else { //===== DIRECT PREDICTION ===== - if (l0_rFrame < 0 && l1_rFrame < 0) - { + if (l0_rFrame < 0 && l1_rFrame < 0) { pred_dir = 2; - for (j4 = currMB->block_y; j4 < currMB->block_y + BLOCK_MULTIPLE; j4 += 2) - { - for (i4 = currMB->block_x; i4 < currMB->block_x + BLOCK_MULTIPLE; i4 += 2) - { + for (j4 = currMB->block_y; j4 < currMB->block_y + BLOCK_MULTIPLE; + j4 += 2) { + for (i4 = currMB->block_x; i4 < currMB->block_x + BLOCK_MULTIPLE; + i4 += 2) { mv_info = &dec_picture->mv_info[j4][i4]; mv_info->ref_pic[LIST_0] = list0[0]; @@ -803,23 +814,21 @@ int mb_pred_b_d8x8spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **cu mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; - mv_info->ref_idx[LIST_1] = 0; + mv_info->ref_idx[LIST_1] = 0; update_neighbor_mvs(&dec_picture->mv_info[j4], mv_info, i4); } } - } - else if (l1_rFrame == -1) - { + } else if (l1_rFrame == -1) { pred_dir = 0; - for (j4 = currMB->block_y; j4 < currMB->block_y + BLOCK_MULTIPLE; j4 += 2) - { - for (i4 = currMB->block_x; i4 < currMB->block_x + BLOCK_MULTIPLE; i4 += 2) - { + for (j4 = currMB->block_y; j4 < currMB->block_y + BLOCK_MULTIPLE; + j4 += 2) { + for (i4 = currMB->block_x; i4 < currMB->block_x + BLOCK_MULTIPLE; + i4 += 2) { mv_info = &dec_picture->mv_info[j4][i4]; - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = zero_mv; @@ -829,18 +838,16 @@ int mb_pred_b_d8x8spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **cu update_neighbor_mvs(&dec_picture->mv_info[j4], mv_info, i4); } } - } - else if (l0_rFrame == -1) - { + } else if (l0_rFrame == -1) { pred_dir = 1; - for (j4 = currMB->block_y; j4 < currMB->block_y + BLOCK_MULTIPLE; j4 += 2) - { - for (i4 = currMB->block_x; i4 < currMB->block_x + BLOCK_MULTIPLE; i4 += 2) - { + for (j4 = currMB->block_y; j4 < currMB->block_y + BLOCK_MULTIPLE; + j4 += 2) { + for (i4 = currMB->block_x; i4 < currMB->block_x + BLOCK_MULTIPLE; + i4 += 2) { mv_info = &dec_picture->mv_info[j4][i4]; mv_info->ref_pic[LIST_0] = NULL; - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = -1; @@ -849,54 +856,54 @@ int mb_pred_b_d8x8spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **cu update_neighbor_mvs(&dec_picture->mv_info[j4], mv_info, i4); } } - } - else - { + } else { pred_dir = 2; - for (j4 = currMB->block_y; j4 < currMB->block_y + BLOCK_MULTIPLE; j4 += 2) - { - for (i4 = currMB->block_x; i4 < currMB->block_x + BLOCK_MULTIPLE; i4 += 2) - { + for (j4 = currMB->block_y; j4 < currMB->block_y + BLOCK_MULTIPLE; + j4 += 2) { + for (i4 = currMB->block_x; i4 < currMB->block_x + BLOCK_MULTIPLE; + i4 += 2) { mv_info = &dec_picture->mv_info[j4][i4]; - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = l0_rFrame; - mv_info->ref_idx[LIST_1] = l1_rFrame; + mv_info->ref_idx[LIST_1] = l1_rFrame; update_neighbor_mvs(&dec_picture->mv_info[j4], mv_info, i4); } } } // Now perform Motion Compensation - perform_mc(currMB, curr_plane, dec_picture, pred_dir, 0, 0, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + perform_mc(currMB, curr_plane, dec_picture, pred_dir, 0, 0, MB_BLOCK_SIZE, + MB_BLOCK_SIZE); } - if (currMB->cbp == 0) - { - copy_image_data_16x16(&currImg[currMB->pix_y], currSlice->mb_pred[curr_plane], currMB->pix_x, 0); + if (currMB->cbp == 0) { + copy_image_data_16x16(&currImg[currMB->pix_y], + currSlice->mb_pred[curr_plane], currMB->pix_x, 0); - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { - copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], currSlice->mb_pred[1], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); - copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], currSlice->mb_pred[2], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { + copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], + currSlice->mb_pred[1], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], + currSlice->mb_pred[2], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); } - } - else - { - iTransform(currMB, curr_plane, 0); + } else { + iTransform(currMB, curr_plane, 0); currSlice->is_reset_coeff = FALSE; } return 1; } - -int mb_pred_b_d4x4spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, StorablePicture *dec_picture) -{ +int mb_pred_b_d4x4spatial(Macroblock *currMB, ColorPlane curr_plane, + imgpel **currImg, StorablePicture *dec_picture) { signed char l0_rFrame = -1, l1_rFrame = -1; MotionVector pmvl0 = zero_mv, pmvl1 = zero_mv; int k; @@ -913,40 +920,36 @@ int mb_pred_b_d4x4spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **cu set_chroma_vector(currMB); - prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, &l1_rFrame); + prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, + &l1_rFrame); - for (block8x8 = 0; block8x8 < 4; block8x8++) - { + for (block8x8 = 0; block8x8 < 4; block8x8++) { int k_start = (block8x8 << 2); int k_end = k_start + BLOCK_MULTIPLE; - for (k = k_start; k < k_end; k ++) - { - int i = (decode_block_scan[k] & 3); - int j = ((decode_block_scan[k] >> 2) & 3); - int i4 = currMB->block_x + i; - int j4 = currMB->block_y + j; - - mv_info = &dec_picture->mv_info[j4][i4]; - //===== DIRECT PREDICTION ===== - if (l0_rFrame == 0 || l1_rFrame == 0) - { - int is_not_moving = (get_colocated_info_4x4(currMB, list1[0], i4, currMB->block_y_aff + j) == 0); + for (k = k_start; k < k_end; k++) { + int i = (decode_block_scan[k] & 3); + int j = ((decode_block_scan[k] >> 2) & 3); + int i4 = currMB->block_x + i; + int j4 = currMB->block_y + j; - if (l1_rFrame == -1) - { - if (is_not_moving) - { + mv_info = &dec_picture->mv_info[j4][i4]; + //===== DIRECT PREDICTION ===== + if (l0_rFrame == 0 || l1_rFrame == 0) { + int is_not_moving = + (get_colocated_info_4x4(currMB, list1[0], i4, + currMB->block_y_aff + j) == 0); + + if (l1_rFrame == -1) { + if (is_not_moving) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; mv_info->ref_idx[LIST_1] = -1; - } - else - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + } else { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = zero_mv; @@ -954,63 +957,47 @@ int mb_pred_b_d4x4spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **cu mv_info->ref_idx[LIST_1] = -1; } pred_dir = 0; - } - else if (l0_rFrame == -1) - { - if (is_not_moving) - { + } else if (l0_rFrame == -1) { + if (is_not_moving) { mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = 0; - } - else - { - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; - mv_info->mv[LIST_0] = zero_mv; + } else { + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; + mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = l1_rFrame; } pred_dir = 1; - } - else - { - if (l0_rFrame == 0 && ((is_not_moving))) - { + } else { + if (l0_rFrame == 0 && ((is_not_moving))) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->ref_idx[LIST_0] = 0; - } - else - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + } else { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->mv[LIST_0] = pmvl0; mv_info->ref_idx[LIST_0] = l0_rFrame; } - if (l1_rFrame == 0 && ((is_not_moving))) - { + if (l1_rFrame == 0 && ((is_not_moving))) { mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_1] = zero_mv; - mv_info->ref_idx[LIST_1] = 0; - } - else - { - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_idx[LIST_1] = 0; + } else { + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_1] = pmvl1; - mv_info->ref_idx[LIST_1] = l1_rFrame; - } + mv_info->ref_idx[LIST_1] = l1_rFrame; + } pred_dir = 2; } - } - else - { + } else { mv_info = &dec_picture->mv_info[j4][i4]; - if (l0_rFrame < 0 && l1_rFrame < 0) - { + if (l0_rFrame < 0 && l1_rFrame < 0) { pred_dir = 2; mv_info->ref_pic[LIST_0] = list0[0]; mv_info->ref_pic[LIST_1] = list1[0]; @@ -1018,75 +1005,71 @@ int mb_pred_b_d4x4spatial(Macroblock *currMB, ColorPlane curr_plane, imgpel **cu mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; mv_info->ref_idx[LIST_1] = 0; - } - else if (l1_rFrame == -1) - { + } else if (l1_rFrame == -1) { pred_dir = 0; - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = l0_rFrame; mv_info->ref_idx[LIST_1] = -1; - } - else if (l0_rFrame == -1) - { + } else if (l0_rFrame == -1) { pred_dir = 1; mv_info->ref_pic[LIST_0] = NULL; - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = l1_rFrame; - } - else - { + } else { pred_dir = 2; - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = l0_rFrame; - mv_info->ref_idx[LIST_1] = l1_rFrame; + mv_info->ref_idx[LIST_1] = l1_rFrame; } } } - for (k = k_start; k < k_end; k ++) - { - int i = (decode_block_scan[k] & 3); + for (k = k_start; k < k_end; k++) { + int i = (decode_block_scan[k] & 3); int j = ((decode_block_scan[k] >> 2) & 3); - perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, BLOCK_SIZE, BLOCK_SIZE); + perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, BLOCK_SIZE, + BLOCK_SIZE); } } - if (currMB->cbp == 0) - { - copy_image_data_16x16(&currImg[currMB->pix_y], currSlice->mb_pred[curr_plane], currMB->pix_x, 0); + if (currMB->cbp == 0) { + copy_image_data_16x16(&currImg[currMB->pix_y], + currSlice->mb_pred[curr_plane], currMB->pix_x, 0); - if ((dec_picture->chroma_format_idc != YUV400) && (dec_picture->chroma_format_idc != YUV444)) - { - copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], currSlice->mb_pred[1], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); - copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], currSlice->mb_pred[2], currMB->pix_c_x, 0, p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + if ((dec_picture->chroma_format_idc != YUV400) && + (dec_picture->chroma_format_idc != YUV444)) { + copy_image_data(&dec_picture->imgUV[0][currMB->pix_c_y], + currSlice->mb_pred[1], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); + copy_image_data(&dec_picture->imgUV[1][currMB->pix_c_y], + currSlice->mb_pred[2], currMB->pix_c_x, 0, + p_Vid->mb_size[1][0], p_Vid->mb_size[1][1]); } - } - else - { - iTransform(currMB, curr_plane, 0); + } else { + iTransform(currMB, curr_plane, 0); currSlice->is_reset_coeff = FALSE; } return 1; } -int mb_pred_b_inter8x8(Macroblock *currMB, ColorPlane curr_plane, StorablePicture *dec_picture) -{ +int mb_pred_b_inter8x8(Macroblock *currMB, ColorPlane curr_plane, + StorablePicture *dec_picture) { signed char l0_rFrame = -1, l1_rFrame = -1; MotionVector pmvl0 = zero_mv, pmvl1 = zero_mv; int block_size_x, block_size_y; int k; - int block8x8; // needed for ABT + int block8x8; // needed for ABT Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; @@ -1095,97 +1078,89 @@ int mb_pred_b_inter8x8(Macroblock *currMB, ColorPlane curr_plane, StorablePictur StorablePicture **list1 = currSlice->listX[LIST_1 + list_offset]; set_chroma_vector(currMB); - - // prepare direct modes - if (currSlice->direct_spatial_mv_pred_flag && (!(currMB->b8mode[0] && currMB->b8mode[1] && currMB->b8mode[2] && currMB->b8mode[3]))) - prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, &l1_rFrame); - for (block8x8=0; block8x8<4; block8x8++) - { - int mv_mode = currMB->b8mode[block8x8]; + // prepare direct modes + if (currSlice->direct_spatial_mv_pred_flag && + (!(currMB->b8mode[0] && currMB->b8mode[1] && currMB->b8mode[2] && + currMB->b8mode[3]))) + prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, + &l1_rFrame); + + for (block8x8 = 0; block8x8 < 4; block8x8++) { + int mv_mode = currMB->b8mode[block8x8]; int pred_dir = currMB->b8pdir[block8x8]; - if ( mv_mode != 0 ) - { + if (mv_mode != 0) { int k_start = (block8x8 << 2); int k_inc = (mv_mode == SMB8x4) ? 2 : 1; - int k_end = (mv_mode == SMB8x8) ? k_start + 1 : ((mv_mode == SMB4x4) ? k_start + 4 : k_start + k_inc + 1); + int k_end = + (mv_mode == SMB8x8) + ? k_start + 1 + : ((mv_mode == SMB4x4) ? k_start + 4 : k_start + k_inc + 1); - block_size_x = ( mv_mode == SMB8x4 || mv_mode == SMB8x8 ) ? SMB_BLOCK_SIZE : BLOCK_SIZE; - block_size_y = ( mv_mode == SMB4x8 || mv_mode == SMB8x8 ) ? SMB_BLOCK_SIZE : BLOCK_SIZE; + block_size_x = (mv_mode == SMB8x4 || mv_mode == SMB8x8) ? SMB_BLOCK_SIZE + : BLOCK_SIZE; + block_size_y = (mv_mode == SMB4x8 || mv_mode == SMB8x8) ? SMB_BLOCK_SIZE + : BLOCK_SIZE; - for (k = k_start; k < k_end; k += k_inc) - { - int i = (decode_block_scan[k] & 3); + for (k = k_start; k < k_end; k += k_inc) { + int i = (decode_block_scan[k] & 3); int j = ((decode_block_scan[k] >> 2) & 3); - perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, block_size_x, block_size_y); - } - } - else - { + perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, + block_size_x, block_size_y); + } + } else { int k_start = (block8x8 << 2); int k_end = k_start; - if (p_Vid->active_sps->direct_8x8_inference_flag) - { + if (p_Vid->active_sps->direct_8x8_inference_flag) { block_size_x = SMB_BLOCK_SIZE; block_size_y = SMB_BLOCK_SIZE; - k_end ++; - } - else - { + k_end++; + } else { block_size_x = BLOCK_SIZE; block_size_y = BLOCK_SIZE; k_end += BLOCK_MULTIPLE; } // Prepare mvs (needed for deblocking and mv prediction - if (currSlice->direct_spatial_mv_pred_flag) - { - for (k = k_start; k < k_start + BLOCK_MULTIPLE; k ++) - { - int i = (decode_block_scan[k] & 3); - int j = ((decode_block_scan[k] >> 2) & 3); - int i4 = currMB->block_x + i; - int j4 = currMB->block_y + j; + if (currSlice->direct_spatial_mv_pred_flag) { + for (k = k_start; k < k_start + BLOCK_MULTIPLE; k++) { + int i = (decode_block_scan[k] & 3); + int j = ((decode_block_scan[k] >> 2) & 3); + int i4 = currMB->block_x + i; + int j4 = currMB->block_y + j; PicMotionParams *mv_info = &dec_picture->mv_info[j4][i4]; - assert (pred_dir<=2); - + assert(pred_dir <= 2); + //===== DIRECT PREDICTION ===== - // motion information should be already set - if (mv_info->ref_idx[LIST_1] == -1) - { + // motion information should be already set + if (mv_info->ref_idx[LIST_1] == -1) { pred_dir = 0; - } - else if (mv_info->ref_idx[LIST_0] == -1) - { + } else if (mv_info->ref_idx[LIST_0] == -1) { pred_dir = 1; - } - else - { + } else { pred_dir = 2; } -/* - if ((pred_dir & 0x01) == 0) - mv_info->ref_pic[LIST_0] = list0[(short)mv_info->ref_idx[LIST_0]]; - if (pred_dir > 0) - mv_info->ref_pic[LIST_1] = list1[(short)mv_info->ref_idx[LIST_1]]; - */ + /* + if ((pred_dir & 0x01) == 0) + mv_info->ref_pic[LIST_0] = + list0[(short)mv_info->ref_idx[LIST_0]]; if (pred_dir > 0) + mv_info->ref_pic[LIST_1] = + list1[(short)mv_info->ref_idx[LIST_1]]; + */ } - } - else - { - for (k = k_start; k < k_start + BLOCK_MULTIPLE; k ++) - { + } else { + for (k = k_start; k < k_start + BLOCK_MULTIPLE; k++) { - int i = (decode_block_scan[k] & 3); + int i = (decode_block_scan[k] & 3); int j = ((decode_block_scan[k] >> 2) & 3); - int i4 = currMB->block_x + i; - int j4 = currMB->block_y + j; + int i4 = currMB->block_x + i; + int j4 = currMB->block_y + j; PicMotionParams *mv_info = &dec_picture->mv_info[j4][i4]; - assert (pred_dir<=2); + assert(pred_dir <= 2); // store reference picture ID determined by direct mode mv_info->ref_pic[LIST_0] = list0[(short)mv_info->ref_idx[LIST_0]]; @@ -1193,12 +1168,12 @@ int mb_pred_b_inter8x8(Macroblock *currMB, ColorPlane curr_plane, StorablePictur } } - for (k = k_start; k < k_end; k ++) - { - int i = (decode_block_scan[k] & 3); + for (k = k_start; k < k_end; k++) { + int i = (decode_block_scan[k] & 3); int j = ((decode_block_scan[k] >> 2) & 3); - perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, block_size_x, block_size_y); - } + perform_mc(currMB, curr_plane, dec_picture, pred_dir, i, j, + block_size_x, block_size_y); + } } } @@ -1211,41 +1186,38 @@ int mb_pred_b_inter8x8(Macroblock *currMB, ColorPlane curr_plane, StorablePictur /*! ************************************************************************ * \brief - * Copy IPCM coefficients to decoded picture buffer and set parameters for this MB - * (for IPCM CABAC and IPCM CAVLC 28/11/2003) + * Copy IPCM coefficients to decoded picture buffer and set parameters for + *this MB (for IPCM CABAC and IPCM CAVLC 28/11/2003) * * \author * Dong Wang ************************************************************************ */ -int mb_pred_ipcm(Macroblock *currMB) -{ +int mb_pred_ipcm(Macroblock *currMB) { int i, j, k; Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; StorablePicture *dec_picture = currSlice->dec_picture; - //Copy coefficients to decoded picture buffer - //IPCM coefficients are stored in currSlice->cof which is set in function read_IPCM_coeffs_from_NAL() + // Copy coefficients to decoded picture buffer + // IPCM coefficients are stored in currSlice->cof which is set in function + // read_IPCM_coeffs_from_NAL() - for(i = 0; i < MB_BLOCK_SIZE; ++i) - { - for(j = 0;j < MB_BLOCK_SIZE ; ++j) - { - dec_picture->imgY[currMB->pix_y + i][currMB->pix_x + j] = (imgpel) currSlice->cof[0][i][j]; + for (i = 0; i < MB_BLOCK_SIZE; ++i) { + for (j = 0; j < MB_BLOCK_SIZE; ++j) { + dec_picture->imgY[currMB->pix_y + i][currMB->pix_x + j] = + (imgpel)currSlice->cof[0][i][j]; } } - if ((dec_picture->chroma_format_idc != YUV400) && (p_Vid->separate_colour_plane_flag == 0)) - { - for (k = 0; k < 2; ++k) - { - for(i = 0; i < p_Vid->mb_cr_size_y; ++i) - { - for(j = 0;j < p_Vid->mb_cr_size_x; ++j) - { - dec_picture->imgUV[k][currMB->pix_c_y+i][currMB->pix_c_x + j] = (imgpel) currSlice->cof[k + 1][i][j]; + if ((dec_picture->chroma_format_idc != YUV400) && + (p_Vid->separate_colour_plane_flag == 0)) { + for (k = 0; k < 2; ++k) { + for (i = 0; i < p_Vid->mb_cr_size_y; ++i) { + for (j = 0; j < p_Vid->mb_cr_size_x; ++j) { + dec_picture->imgUV[k][currMB->pix_c_y + i][currMB->pix_c_x + j] = + (imgpel)currSlice->cof[k + 1][i][j]; } } } @@ -1255,18 +1227,18 @@ int mb_pred_ipcm(Macroblock *currMB) update_qp(currMB, 0); // for CAVLC: Set the nz_coeff to 16. - // These parameters are to be used in CAVLC decoding of neighbour blocks - memset(p_Vid->nz_coeff[currMB->mbAddrX][0][0], 16, 3 * BLOCK_PIXELS * sizeof(byte)); + // These parameters are to be used in CAVLC decoding of neighbour blocks + memset(p_Vid->nz_coeff[currMB->mbAddrX][0][0], 16, + 3 * BLOCK_PIXELS * sizeof(byte)); // for CABAC decoding of MB skip flag currMB->skip_flag = 0; - //for deblocking filter CABAC + // for deblocking filter CABAC currMB->cbp_blk[0] = 0xFFFF; - //For CABAC decoding of Dquant + // For CABAC decoding of Dquant currSlice->last_dquant = 0; currSlice->is_reset_coeff = FALSE; return 1; } - diff --git a/src/common/ldecod_src/mbuffer.c b/src/common/ldecod_src/mbuffer.c index b6ae474..588f40e 100644 --- a/src/common/ldecod_src/mbuffer.c +++ b/src/common/ldecod_src/mbuffer.c @@ -8,7 +8,8 @@ * Frame buffer functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Karsten Shring * - Alexis Tourapis * - Jill Boyce @@ -21,32 +22,34 @@ #include -#include "global.h" #include "erc_api.h" +#include "fast_memory.h" +#include "global.h" #include "header.h" #include "image.h" #include "mbuffer.h" +#include "mbuffer_mvc.h" #include "memalloc.h" #include "output.h" -#include "mbuffer_mvc.h" -#include "fast_memory.h" - - -static void insert_picture_in_dpb (VideoParameters *p_Vid, FrameStore* fs, StorablePicture* p); +static void insert_picture_in_dpb(VideoParameters *p_Vid, FrameStore *fs, + StorablePicture *p); #if (MVC_EXTENSION_ENABLE) -static int output_one_frame_from_dpb(DecodedPictureBuffer *p_Dpb, int curr_view_id); -static void get_smallest_poc (DecodedPictureBuffer *p_Dpb, int *poc,int * pos, int curr_view_id); -static int remove_unused_frame_from_dpb (DecodedPictureBuffer *p_Dpb, int curr_view_id); +static int output_one_frame_from_dpb(DecodedPictureBuffer *p_Dpb, + int curr_view_id); +static void get_smallest_poc(DecodedPictureBuffer *p_Dpb, int *poc, int *pos, + int curr_view_id); +static int remove_unused_frame_from_dpb(DecodedPictureBuffer *p_Dpb, + int curr_view_id); #else static void output_one_frame_from_dpb(DecodedPictureBuffer *p_Dpb); -static void get_smallest_poc (DecodedPictureBuffer *p_Dpb, int *poc,int * pos); -static int remove_unused_frame_from_dpb (DecodedPictureBuffer *p_Dpb); +static void get_smallest_poc(DecodedPictureBuffer *p_Dpb, int *poc, int *pos); +static int remove_unused_frame_from_dpb(DecodedPictureBuffer *p_Dpb); #endif -static void gen_field_ref_ids (VideoParameters *p_Vid, StorablePicture *p); -static int is_used_for_reference (FrameStore* fs); -static int is_short_term_reference (FrameStore* fs); -static int is_long_term_reference (FrameStore* fs); +static void gen_field_ref_ids(VideoParameters *p_Vid, StorablePicture *p); +static int is_used_for_reference(FrameStore *fs); +static int is_short_term_reference(FrameStore *fs); +static int is_long_term_reference(FrameStore *fs); #define MAX_LIST_SIZE 33 @@ -56,24 +59,20 @@ static int is_long_term_reference (FrameStore* fs); * Print out list of pictures in DPB. Used for debug purposes. ************************************************************************ */ -void dump_dpb(DecodedPictureBuffer *p_Dpb) -{ +void dump_dpb(DecodedPictureBuffer *p_Dpb) { #if DUMP_DPB unsigned i; - for (i=0; iused_size;i++) - { + for (i = 0; i < p_Dpb->used_size; i++) { printf("("); printf("fn=%d ", p_Dpb->fs[i]->frame_num); - if (p_Dpb->fs[i]->is_used & 1) - { + if (p_Dpb->fs[i]->is_used & 1) { if (p_Dpb->fs[i]->top_field) printf("T: poc=%d ", p_Dpb->fs[i]->top_field->poc); else printf("T: poc=%d ", p_Dpb->fs[i]->frame->top_poc); } - if (p_Dpb->fs[i]->is_used & 2) - { + if (p_Dpb->fs[i]->is_used & 2) { if (p_Dpb->fs[i]->bottom_field) printf("B: poc=%d ", p_Dpb->fs[i]->bottom_field->poc); else @@ -82,18 +81,21 @@ void dump_dpb(DecodedPictureBuffer *p_Dpb) if (p_Dpb->fs[i]->is_used == 3) printf("F: poc=%d ", p_Dpb->fs[i]->frame->poc); printf("G: poc=%d) ", p_Dpb->fs[i]->poc); - if (p_Dpb->fs[i]->is_reference) printf ("ref (%d) ", p_Dpb->fs[i]->is_reference); - if (p_Dpb->fs[i]->is_long_term) printf ("lt_ref (%d) ", p_Dpb->fs[i]->is_reference); - if (p_Dpb->fs[i]->is_output) printf ("out "); - if (p_Dpb->fs[i]->is_used == 3) - { - if (p_Dpb->fs[i]->frame->non_existing) printf ("ne "); + if (p_Dpb->fs[i]->is_reference) + printf("ref (%d) ", p_Dpb->fs[i]->is_reference); + if (p_Dpb->fs[i]->is_long_term) + printf("lt_ref (%d) ", p_Dpb->fs[i]->is_reference); + if (p_Dpb->fs[i]->is_output) + printf("out "); + if (p_Dpb->fs[i]->is_used == 3) { + if (p_Dpb->fs[i]->frame->non_existing) + printf("ne "); } #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs[i]->is_reference) - printf ("view_id (%d) ", p_Dpb->fs[i]->view_id); + if (p_Dpb->fs[i]->is_reference) + printf("view_id (%d) ", p_Dpb->fs[i]->view_id); #endif - printf ("\n"); + printf("\n"); } #endif } @@ -106,14 +108,14 @@ void dump_dpb(DecodedPictureBuffer *p_Dpb) * ************************************************************************ */ -int getDpbSize(seq_parameter_set_rbsp_t *active_sps) -{ - int pic_size = (active_sps->pic_width_in_mbs_minus1 + 1) * (active_sps->pic_height_in_map_units_minus1 + 1) * (active_sps->frame_mbs_only_flag?1:2) * 384; +int getDpbSize(seq_parameter_set_rbsp_t *active_sps) { + int pic_size = (active_sps->pic_width_in_mbs_minus1 + 1) * + (active_sps->pic_height_in_map_units_minus1 + 1) * + (active_sps->frame_mbs_only_flag ? 1 : 2) * 384; int size = 0; - switch (active_sps->level_idc) - { + switch (active_sps->level_idc) { case 9: size = 152064; break; @@ -121,7 +123,8 @@ int getDpbSize(seq_parameter_set_rbsp_t *active_sps) size = 152064; break; case 11: - if (!IS_FREXT_PROFILE(active_sps->profile_idc) && (active_sps->constrained_set3_flag == 1)) + if (!IS_FREXT_PROFILE(active_sps->profile_idc) && + (active_sps->constrained_set3_flag == 1)) size = 152064; else size = 345600; @@ -166,28 +169,28 @@ int getDpbSize(seq_parameter_set_rbsp_t *active_sps) size = 70778880; break; default: - error ("undefined level", 500); + error("undefined level", 500); break; } size /= pic_size; - size = imin( size, 16); + size = imin(size, 16); - if (active_sps->vui_parameters_present_flag && active_sps->vui_seq_parameters.bitstream_restriction_flag) - { + if (active_sps->vui_parameters_present_flag && + active_sps->vui_seq_parameters.bitstream_restriction_flag) { int size_vui; - if ((int)active_sps->vui_seq_parameters.max_dec_frame_buffering > size) - { - error ("max_dec_frame_buffering larger than MaxDpbSize", 500); + if ((int)active_sps->vui_seq_parameters.max_dec_frame_buffering > size) { + error("max_dec_frame_buffering larger than MaxDpbSize", 500); } - size_vui = imax (1, active_sps->vui_seq_parameters.max_dec_frame_buffering); + size_vui = imax(1, active_sps->vui_seq_parameters.max_dec_frame_buffering); #ifdef _DEBUG - if(size_vui < size) - { - printf("Warning: max_dec_frame_buffering(%d) is less than DPB size(%d) calculated from Profile/Level.\n", size_vui, size); + if (size_vui < size) { + printf("Warning: max_dec_frame_buffering(%d) is less than DPB size(%d) " + "calculated from Profile/Level.\n", + size_vui, size); } #endif - size = size_vui; + size = size_vui; } return size; @@ -201,55 +204,55 @@ int getDpbSize(seq_parameter_set_rbsp_t *active_sps) * ************************************************************************ */ -void check_num_ref(DecodedPictureBuffer *p_Dpb) -{ - if ((int)(p_Dpb->ltref_frames_in_buffer + p_Dpb->ref_frames_in_buffer ) > (imax(1, p_Dpb->num_ref_frames))) - { - error ("Max. number of reference frames exceeded. Invalid stream.", 500); +void check_num_ref(DecodedPictureBuffer *p_Dpb) { + if ((int)(p_Dpb->ltref_frames_in_buffer + p_Dpb->ref_frames_in_buffer) > + (imax(1, p_Dpb->num_ref_frames))) { + error("Max. number of reference frames exceeded. Invalid stream.", 500); } } - /*! ************************************************************************ * \brief - * Allocate memory for decoded picture buffer and initialize with sane values. + * Allocate memory for decoded picture buffer and initialize with sane + *values. * ************************************************************************ */ -void init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb) -{ - unsigned i; +void init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb) { + unsigned i; seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; p_Dpb->p_Vid = p_Vid; - if (p_Dpb->init_done) - { + if (p_Dpb->init_done) { free_dpb(p_Dpb); } #if (MVC_EXTENSION_ENABLE) - if(p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) + if (p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) p_Dpb->size = GetMaxDecFrameBuffering(p_Vid) + 2; else p_Dpb->size = getDpbSize(active_sps); - if(active_sps->profile_idc == MVC_HIGH || active_sps->profile_idc == STEREO_HIGH) - p_Dpb->size = (p_Dpb->size<<1) + 2; + if (active_sps->profile_idc == MVC_HIGH || + active_sps->profile_idc == STEREO_HIGH) + p_Dpb->size = (p_Dpb->size << 1) + 2; #else p_Dpb->size = getDpbSize(active_sps); #endif - - p_Dpb->num_ref_frames = active_sps->num_ref_frames; + p_Dpb->num_ref_frames = active_sps->num_ref_frames; #if (MVC_EXTENSION_ENABLE) - if ((unsigned int)active_sps->max_dec_frame_buffering < active_sps->num_ref_frames) + if ((unsigned int)active_sps->max_dec_frame_buffering < + active_sps->num_ref_frames) #else if (p_Dpb->size < active_sps->num_ref_frames) #endif { - error ("DPB size at specified level is smaller than the specified number of reference frames. This is not allowed.\n", 1000); + error("DPB size at specified level is smaller than the specified number of " + "reference frames. This is not allowed.\n", + 1000); } p_Dpb->used_size = 0; @@ -258,22 +261,21 @@ void init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb) p_Dpb->ref_frames_in_buffer = 0; p_Dpb->ltref_frames_in_buffer = 0; - p_Dpb->fs = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==p_Dpb->fs) + p_Dpb->fs = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == p_Dpb->fs) no_mem_exit("init_dpb: p_Dpb->fs"); - p_Dpb->fs_ref = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==p_Dpb->fs_ref) + p_Dpb->fs_ref = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == p_Dpb->fs_ref) no_mem_exit("init_dpb: p_Dpb->fs_ref"); - p_Dpb->fs_ltref = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==p_Dpb->fs_ltref) + p_Dpb->fs_ltref = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == p_Dpb->fs_ltref) no_mem_exit("init_dpb: p_Dpb->fs_ltref"); - for (i = 0; i < p_Dpb->size; i++) - { - p_Dpb->fs[i] = alloc_frame_store(); - p_Dpb->fs_ref[i] = NULL; + for (i = 0; i < p_Dpb->size; i++) { + p_Dpb->fs[i] = alloc_frame_store(); + p_Dpb->fs_ref[i] = NULL; p_Dpb->fs_ltref[i] = NULL; #if (MVC_EXTENSION_ENABLE) p_Dpb->fs[i]->view_id = MVC_INIT_VIEW_ID; @@ -284,16 +286,18 @@ void init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb) /* for (i = 0; i < 6; i++) { - currSlice->listX[i] = calloc(MAX_LIST_SIZE, sizeof (StorablePicture*)); // +1 for reordering - if (NULL==currSlice->listX[i]) - no_mem_exit("init_dpb: currSlice->listX[i]"); + currSlice->listX[i] = calloc(MAX_LIST_SIZE, sizeof (StorablePicture*)); // +1 + for reordering if (NULL==currSlice->listX[i]) no_mem_exit("init_dpb: + currSlice->listX[i]"); } */ /* allocate a dummy storable picture */ - p_Vid->no_reference_picture = alloc_storable_picture (p_Vid, FRAME, p_Vid->width, p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); - p_Vid->no_reference_picture->top_field = p_Vid->no_reference_picture; + p_Vid->no_reference_picture = + alloc_storable_picture(p_Vid, FRAME, p_Vid->width, p_Vid->height, + p_Vid->width_cr, p_Vid->height_cr); + p_Vid->no_reference_picture->top_field = p_Vid->no_reference_picture; p_Vid->no_reference_picture->bottom_field = p_Vid->no_reference_picture; - p_Vid->no_reference_picture->frame = p_Vid->no_reference_picture; + p_Vid->no_reference_picture->frame = p_Vid->no_reference_picture; p_Dpb->last_output_poc = INT_MIN; @@ -306,56 +310,57 @@ void init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb) p_Dpb->init_done = 1; // picture error concealment - if(p_Vid->conceal_mode !=0) + if (p_Vid->conceal_mode != 0) p_Vid->last_out_fs = alloc_frame_store(); } -void re_init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb) -{ - int i; +void re_init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb) { + int i; seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; int iDpbSize; #if (MVC_EXTENSION_ENABLE) - if(p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) + if (p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) iDpbSize = GetMaxDecFrameBuffering(p_Vid) + 2; else iDpbSize = getDpbSize(active_sps); - if(active_sps->profile_idc == MVC_HIGH || active_sps->profile_idc == STEREO_HIGH) - iDpbSize = (iDpbSize<<1) + 2; + if (active_sps->profile_idc == MVC_HIGH || + active_sps->profile_idc == STEREO_HIGH) + iDpbSize = (iDpbSize << 1) + 2; #else iDpbSize = getDpbSize(active_sps); #endif p_Dpb->num_ref_frames = active_sps->num_ref_frames; - if( iDpbSize > (int)p_Dpb->size) - { + if (iDpbSize > (int)p_Dpb->size) { #if (MVC_EXTENSION_ENABLE) - if ((unsigned int)active_sps->max_dec_frame_buffering < active_sps->num_ref_frames) + if ((unsigned int)active_sps->max_dec_frame_buffering < + active_sps->num_ref_frames) #else if (p_Dpb->size < active_sps->num_ref_frames) #endif { - error ("DPB size at specified level is smaller than the specified number of reference frames. This is not allowed.\n", 1000); + error("DPB size at specified level is smaller than the specified number " + "of reference frames. This is not allowed.\n", + 1000); } - p_Dpb->fs = realloc(p_Dpb->fs, iDpbSize*sizeof (FrameStore*)); - if (NULL==p_Dpb->fs) + p_Dpb->fs = realloc(p_Dpb->fs, iDpbSize * sizeof(FrameStore *)); + if (NULL == p_Dpb->fs) no_mem_exit("re_init_dpb: p_Dpb->fs"); - p_Dpb->fs_ref = realloc(p_Dpb->fs_ref, iDpbSize*sizeof (FrameStore*)); - if (NULL==p_Dpb->fs_ref) + p_Dpb->fs_ref = realloc(p_Dpb->fs_ref, iDpbSize * sizeof(FrameStore *)); + if (NULL == p_Dpb->fs_ref) no_mem_exit("re_init_dpb: p_Dpb->fs_ref"); - p_Dpb->fs_ltref = realloc(p_Dpb->fs_ltref, iDpbSize*sizeof (FrameStore*)); - if (NULL==p_Dpb->fs_ltref) + p_Dpb->fs_ltref = realloc(p_Dpb->fs_ltref, iDpbSize * sizeof(FrameStore *)); + if (NULL == p_Dpb->fs_ltref) no_mem_exit("re_init_dpb: p_Dpb->fs_ltref"); - for (i = p_Dpb->size; i < iDpbSize; i++) - { - p_Dpb->fs[i] = alloc_frame_store(); - p_Dpb->fs_ref[i] = NULL; + for (i = p_Dpb->size; i < iDpbSize; i++) { + p_Dpb->fs[i] = alloc_frame_store(); + p_Dpb->fs_ref[i] = NULL; p_Dpb->fs_ltref[i] = NULL; #if (MVC_EXTENSION_ENABLE) p_Dpb->fs[i]->view_id = MVC_INIT_VIEW_ID; @@ -373,26 +378,21 @@ void re_init_dpb(VideoParameters *p_Vid, DecodedPictureBuffer *p_Dpb) * Free memory for decoded picture buffer. ************************************************************************ */ -void free_dpb(DecodedPictureBuffer *p_Dpb) -{ +void free_dpb(DecodedPictureBuffer *p_Dpb) { VideoParameters *p_Vid = p_Dpb->p_Vid; unsigned i; - if (p_Dpb->fs) - { - for (i=0; isize; i++) - { + if (p_Dpb->fs) { + for (i = 0; i < p_Dpb->size; i++) { free_frame_store(p_Dpb->fs[i]); } - free (p_Dpb->fs); - p_Dpb->fs=NULL; + free(p_Dpb->fs); + p_Dpb->fs = NULL; } - if (p_Dpb->fs_ref) - { - free (p_Dpb->fs_ref); + if (p_Dpb->fs_ref) { + free(p_Dpb->fs_ref); } - if (p_Dpb->fs_ltref) - { - free (p_Dpb->fs_ltref); + if (p_Dpb->fs_ltref) { + free(p_Dpb->fs_ltref); } p_Dpb->last_output_poc = INT_MIN; #if (MVC_EXTENSION_ENABLE) @@ -402,47 +402,46 @@ void free_dpb(DecodedPictureBuffer *p_Dpb) p_Dpb->init_done = 0; // picture error concealment - if(p_Vid->conceal_mode != 0) - free_frame_store(p_Vid->last_out_fs); + if (p_Vid->conceal_mode != 0) + free_frame_store(p_Vid->last_out_fs); free_storable_picture(p_Vid->no_reference_picture); } - /*! ************************************************************************ * \brief - * Allocate memory for decoded picture buffer frame stores and initialize with sane values. + * Allocate memory for decoded picture buffer frame stores and initialize + *with sane values. * * \return * the allocated FrameStore structure ************************************************************************ */ -FrameStore* alloc_frame_store(void) -{ +FrameStore *alloc_frame_store(void) { FrameStore *f; - f = calloc (1, sizeof(FrameStore)); - if (NULL==f) + f = calloc(1, sizeof(FrameStore)); + if (NULL == f) no_mem_exit("alloc_frame_store: f"); - f->is_used = 0; + f->is_used = 0; f->is_reference = 0; f->is_long_term = 0; f->is_orig_reference = 0; f->is_output = 0; - f->frame = NULL;; - f->top_field = NULL; + f->frame = NULL; + ; + f->top_field = NULL; f->bottom_field = NULL; return f; } -void alloc_pic_motion(PicMotionParamsOld *motion, int size_y, int size_x) -{ - motion->mb_field = calloc (size_y * size_x, sizeof(byte)); +void alloc_pic_motion(PicMotionParamsOld *motion, int size_y, int size_x) { + motion->mb_field = calloc(size_y * size_x, sizeof(byte)); if (motion->mb_field == NULL) no_mem_exit("alloc_storable_picture: motion->mb_field"); } @@ -469,37 +468,44 @@ void alloc_pic_motion(PicMotionParamsOld *motion, int size_y, int size_x) * the allocated StorablePicture structure ************************************************************************ */ -StorablePicture* alloc_storable_picture(VideoParameters *p_Vid, PictureStructure structure, int size_x, int size_y, int size_x_cr, int size_y_cr) -{ - seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; +StorablePicture *alloc_storable_picture(VideoParameters *p_Vid, + PictureStructure structure, int size_x, + int size_y, int size_x_cr, + int size_y_cr) { + seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; StorablePicture *s; - int nplane; + int nplane; - //printf ("Allocating (%s) picture (x=%d, y=%d, x_cr=%d, y_cr=%d)\n", (type == FRAME)?"FRAME":(type == TOP_FIELD)?"TOP_FIELD":"BOTTOM_FIELD", size_x, size_y, size_x_cr, size_y_cr); + // printf ("Allocating (%s) picture (x=%d, y=%d, x_cr=%d, y_cr=%d)\n", (type + // == FRAME)?"FRAME":(type == TOP_FIELD)?"TOP_FIELD":"BOTTOM_FIELD", size_x, + // size_y, size_x_cr, size_y_cr); - s = calloc (1, sizeof(StorablePicture)); - if (NULL==s) + s = calloc(1, sizeof(StorablePicture)); + if (NULL == s) no_mem_exit("alloc_storable_picture: s"); - if (structure!=FRAME) - { - size_y /= 2; + if (structure != FRAME) { + size_y /= 2; size_y_cr /= 2; } - s->PicSizeInMbs = (size_x*size_y)/256; + s->PicSizeInMbs = (size_x * size_y) / 256; s->imgUV = NULL; - //get_mem2Dpel (&(s->imgY), size_y, size_x); - get_mem2DpelWithPad (&(s->imgY), size_y, size_x, p_Vid->iLumaPadY, p_Vid->iLumaPadX); - s->iLumaStride = size_x+2*p_Vid->iLumaPadX; - s->iLumaExpandedHeight = size_y+2*p_Vid->iLumaPadY; + // get_mem2Dpel (&(s->imgY), size_y, size_x); + get_mem2DpelWithPad(&(s->imgY), size_y, size_x, p_Vid->iLumaPadY, + p_Vid->iLumaPadX); + s->iLumaStride = size_x + 2 * p_Vid->iLumaPadX; + s->iLumaExpandedHeight = size_y + 2 * p_Vid->iLumaPadY; if (active_sps->chroma_format_idc != YUV400) - get_mem3DpelWithPad(&(s->imgUV), 2, size_y_cr, size_x_cr, p_Vid->iChromaPadY, p_Vid->iChromaPadX); //get_mem3Dpel (&(s->imgUV), 2, size_y_cr, size_x_cr); - s->iChromaStride =size_x_cr + 2*p_Vid->iChromaPadX; - s->iChromaExpandedHeight = size_y_cr + 2*p_Vid->iChromaPadY; + get_mem3DpelWithPad(&(s->imgUV), 2, size_y_cr, size_x_cr, + p_Vid->iChromaPadY, + p_Vid->iChromaPadX); // get_mem3Dpel (&(s->imgUV), 2, + // size_y_cr, size_x_cr); + s->iChromaStride = size_x_cr + 2 * p_Vid->iChromaPadX; + s->iChromaExpandedHeight = size_y_cr + 2 * p_Vid->iChromaPadY; s->iLumaPadY = p_Vid->iLumaPadY; s->iLumaPadX = p_Vid->iLumaPadX; s->iChromaPadY = p_Vid->iChromaPadY; @@ -507,35 +513,35 @@ StorablePicture* alloc_storable_picture(VideoParameters *p_Vid, PictureStructure s->separate_colour_plane_flag = p_Vid->separate_colour_plane_flag; + get_mem2Dshort(&(s->slice_id), size_y / MB_BLOCK_SIZE, + size_x / MB_BLOCK_SIZE); - get_mem2Dshort (&(s->slice_id), size_y / MB_BLOCK_SIZE, size_x / MB_BLOCK_SIZE); + get_mem2Dmp(&s->mv_info, size_y / BLOCK_SIZE, size_x / BLOCK_SIZE); + alloc_pic_motion(&s->motion, size_y / BLOCK_SIZE, size_x / BLOCK_SIZE); - get_mem2Dmp ( &s->mv_info, size_y / BLOCK_SIZE, size_x / BLOCK_SIZE); - alloc_pic_motion( &s->motion , size_y / BLOCK_SIZE, size_x / BLOCK_SIZE); - - if( (p_Vid->separate_colour_plane_flag != 0) ) - { - for( nplane=0; nplaneJVmv_info[nplane], size_y / BLOCK_SIZE, size_x / BLOCK_SIZE); - alloc_pic_motion(&s->JVmotion[nplane] , size_y / BLOCK_SIZE, size_x / BLOCK_SIZE); + if ((p_Vid->separate_colour_plane_flag != 0)) { + for (nplane = 0; nplane < MAX_PLANE; nplane++) { + get_mem2Dmp(&s->JVmv_info[nplane], size_y / BLOCK_SIZE, + size_x / BLOCK_SIZE); + alloc_pic_motion(&s->JVmotion[nplane], size_y / BLOCK_SIZE, + size_x / BLOCK_SIZE); } } - s->pic_num=0; - s->frame_num=0; - s->long_term_frame_idx=0; - s->long_term_pic_num=0; - s->used_for_reference=0; - s->is_long_term=0; - s->non_existing=0; + s->pic_num = 0; + s->frame_num = 0; + s->long_term_frame_idx = 0; + s->long_term_pic_num = 0; + s->used_for_reference = 0; + s->is_long_term = 0; + s->non_existing = 0; s->is_output = 0; s->max_slice_id = 0; #if (MVC_EXTENSION_ENABLE) s->view_id = -1; #endif - s->structure=structure; + s->structure = structure; s->size_x = size_x; s->size_y = size_y; @@ -546,27 +552,26 @@ StorablePicture* alloc_storable_picture(VideoParameters *p_Vid, PictureStructure s->size_x_cr_m1 = size_x_cr - 1; s->size_y_cr_m1 = size_y_cr - 1; - s->top_field = p_Vid->no_reference_picture; + s->top_field = p_Vid->no_reference_picture; s->bottom_field = p_Vid->no_reference_picture; - s->frame = p_Vid->no_reference_picture; + s->frame = p_Vid->no_reference_picture; s->dec_ref_pic_marking_buffer = NULL; - s->coded_frame = 0; - s->mb_aff_frame_flag = 0; + s->coded_frame = 0; + s->mb_aff_frame_flag = 0; s->top_poc = s->bottom_poc = s->poc = 0; s->seiHasTone_mapping = 0; - if(!p_Vid->active_sps->frame_mbs_only_flag && structure!=FRAME) - { - int i; - for (i = 0; i < 2; i++) - { - s->listX[i] = calloc(MAX_LIST_SIZE, sizeof (StorablePicture*)); // +1 for reordering - if (NULL==s->listX[i]) - no_mem_exit("alloc_storable_picture: s->listX[i]"); - } + if (!p_Vid->active_sps->frame_mbs_only_flag && structure != FRAME) { + int i; + for (i = 0; i < 2; i++) { + s->listX[i] = + calloc(MAX_LIST_SIZE, sizeof(StorablePicture *)); // +1 for reordering + if (NULL == s->listX[i]) + no_mem_exit("alloc_storable_picture: s->listX[i]"); + } } return s; @@ -584,39 +589,31 @@ StorablePicture* alloc_storable_picture(VideoParameters *p_Vid, PictureStructure * ************************************************************************ */ -void free_frame_store(FrameStore* f) -{ - if (f) - { - if (f->frame) - { +void free_frame_store(FrameStore *f) { + if (f) { + if (f->frame) { free_storable_picture(f->frame); - f->frame=NULL; + f->frame = NULL; } - if (f->top_field) - { + if (f->top_field) { free_storable_picture(f->top_field); - f->top_field=NULL; + f->top_field = NULL; } - if (f->bottom_field) - { + if (f->bottom_field) { free_storable_picture(f->bottom_field); - f->bottom_field=NULL; + f->bottom_field = NULL; } free(f); } } -void free_pic_motion(PicMotionParamsOld *motion) -{ - if (motion->mb_field) - { +void free_pic_motion(PicMotionParamsOld *motion) { + if (motion->mb_field) { free(motion->mb_field); motion->mb_field = NULL; } } - /*! ************************************************************************ * \brief @@ -627,24 +624,18 @@ void free_pic_motion(PicMotionParamsOld *motion) * ************************************************************************ */ -void free_storable_picture(StorablePicture* p) -{ +void free_storable_picture(StorablePicture *p) { int nplane; - if (p) - { - if (p->mv_info) - { + if (p) { + if (p->mv_info) { free_mem2Dmp(p->mv_info); p->mv_info = NULL; } free_pic_motion(&p->motion); - if( (p->separate_colour_plane_flag != 0) ) - { - for( nplane=0; nplaneJVmv_info[nplane]) - { + if ((p->separate_colour_plane_flag != 0)) { + for (nplane = 0; nplane < MAX_PLANE; nplane++) { + if (p->JVmv_info[nplane]) { free_mem2Dmp(p->JVmv_info[nplane]); p->JVmv_info[nplane] = NULL; } @@ -652,22 +643,19 @@ void free_storable_picture(StorablePicture* p) } } - if (p->imgY) - { + if (p->imgY) { free_mem2DpelWithPad(p->imgY, p->iLumaPadY, p->iLumaPadX); - p->imgY=NULL; + p->imgY = NULL; } - if (p->imgUV) - { + if (p->imgUV) { free_mem3DpelWithPad(p->imgUV, p->iChromaPadY, p->iChromaPadX); - p->imgUV=NULL; + p->imgUV = NULL; } - if (p->slice_id) - { + if (p->slice_id) { free_mem2Dshort(p->slice_id); - p->slice_id=NULL; + p->slice_id = NULL; } if (p->seiHasTone_mapping) @@ -675,10 +663,8 @@ void free_storable_picture(StorablePicture* p) { int i; - for(i=0; i<2; i++) - { - if(p->listX[i]) - { + for (i = 0; i < 2; i++) { + if (p->listX[i]) { free(p->listX[i]); p->listX[i] = NULL; } @@ -696,27 +682,20 @@ void free_storable_picture(StorablePicture* p) * ************************************************************************ */ -static void unmark_for_reference(FrameStore* fs) -{ +static void unmark_for_reference(FrameStore *fs) { - if (fs->is_used & 1) - { - if (fs->top_field) - { + if (fs->is_used & 1) { + if (fs->top_field) { fs->top_field->used_for_reference = 0; } } - if (fs->is_used & 2) - { - if (fs->bottom_field) - { + if (fs->is_used & 2) { + if (fs->bottom_field) { fs->bottom_field->used_for_reference = 0; } } - if (fs->is_used == 3) - { - if (fs->top_field && fs->bottom_field) - { + if (fs->is_used == 3) { + if (fs->top_field && fs->bottom_field) { fs->top_field->used_for_reference = 0; fs->bottom_field->used_for_reference = 0; } @@ -725,23 +704,19 @@ static void unmark_for_reference(FrameStore* fs) fs->is_reference = 0; - if(fs->frame) - { + if (fs->frame) { free_pic_motion(&fs->frame->motion); } - if (fs->top_field) - { + if (fs->top_field) { free_pic_motion(&fs->top_field->motion); } - if (fs->bottom_field) - { + if (fs->bottom_field) { free_pic_motion(&fs->bottom_field->motion); } } - /*! ************************************************************************ * \brief @@ -749,29 +724,22 @@ static void unmark_for_reference(FrameStore* fs) * ************************************************************************ */ -static void unmark_for_long_term_reference(FrameStore* fs) -{ +static void unmark_for_long_term_reference(FrameStore *fs) { - if (fs->is_used & 1) - { - if (fs->top_field) - { + if (fs->is_used & 1) { + if (fs->top_field) { fs->top_field->used_for_reference = 0; fs->top_field->is_long_term = 0; } } - if (fs->is_used & 2) - { - if (fs->bottom_field) - { + if (fs->is_used & 2) { + if (fs->bottom_field) { fs->bottom_field->used_for_reference = 0; fs->bottom_field->is_long_term = 0; } } - if (fs->is_used == 3) - { - if (fs->top_field && fs->bottom_field) - { + if (fs->is_used == 3) { + if (fs->top_field && fs->bottom_field) { fs->top_field->used_for_reference = 0; fs->top_field->is_long_term = 0; fs->bottom_field->used_for_reference = 0; @@ -785,18 +753,18 @@ static void unmark_for_long_term_reference(FrameStore* fs) fs->is_long_term = 0; } - /*! ************************************************************************ * \brief - * compares two stored pictures by picture number for qsort in descending order + * compares two stored pictures by picture number for qsort in descending + *order * ************************************************************************ */ -static inline int compare_pic_by_pic_num_desc( const void *arg1, const void *arg2 ) -{ - int pic_num1 = (*(StorablePicture**)arg1)->pic_num; - int pic_num2 = (*(StorablePicture**)arg2)->pic_num; +static inline int compare_pic_by_pic_num_desc(const void *arg1, + const void *arg2) { + int pic_num1 = (*(StorablePicture **)arg1)->pic_num; + int pic_num2 = (*(StorablePicture **)arg2)->pic_num; if (pic_num1 < pic_num2) return 1; @@ -809,18 +777,19 @@ static inline int compare_pic_by_pic_num_desc( const void *arg1, const void *arg /*! ************************************************************************ * \brief - * compares two stored pictures by picture number for qsort in descending order + * compares two stored pictures by picture number for qsort in descending + *order * ************************************************************************ */ -static inline int compare_pic_by_lt_pic_num_asc( const void *arg1, const void *arg2 ) -{ - int long_term_pic_num1 = (*(StorablePicture**)arg1)->long_term_pic_num; - int long_term_pic_num2 = (*(StorablePicture**)arg2)->long_term_pic_num; +static inline int compare_pic_by_lt_pic_num_asc(const void *arg1, + const void *arg2) { + int long_term_pic_num1 = (*(StorablePicture **)arg1)->long_term_pic_num; + int long_term_pic_num2 = (*(StorablePicture **)arg2)->long_term_pic_num; - if ( long_term_pic_num1 < long_term_pic_num2) + if (long_term_pic_num1 < long_term_pic_num2) return -1; - if ( long_term_pic_num1 > long_term_pic_num2) + if (long_term_pic_num1 > long_term_pic_num2) return 1; else return 0; @@ -833,19 +802,18 @@ static inline int compare_pic_by_lt_pic_num_asc( const void *arg1, const void *a * ************************************************************************ */ -static inline int compare_fs_by_frame_num_desc( const void *arg1, const void *arg2 ) -{ - int frame_num_wrap1 = (*(FrameStore**)arg1)->frame_num_wrap; - int frame_num_wrap2 = (*(FrameStore**)arg2)->frame_num_wrap; - if ( frame_num_wrap1 < frame_num_wrap2) +static inline int compare_fs_by_frame_num_desc(const void *arg1, + const void *arg2) { + int frame_num_wrap1 = (*(FrameStore **)arg1)->frame_num_wrap; + int frame_num_wrap2 = (*(FrameStore **)arg2)->frame_num_wrap; + if (frame_num_wrap1 < frame_num_wrap2) return 1; - if ( frame_num_wrap1 > frame_num_wrap2) + if (frame_num_wrap1 > frame_num_wrap2) return -1; else return 0; } - /*! ************************************************************************ * \brief @@ -853,20 +821,19 @@ static inline int compare_fs_by_frame_num_desc( const void *arg1, const void *ar * ************************************************************************ */ -static inline int compare_fs_by_lt_pic_idx_asc( const void *arg1, const void *arg2 ) -{ - int long_term_frame_idx1 = (*(FrameStore**)arg1)->long_term_frame_idx; - int long_term_frame_idx2 = (*(FrameStore**)arg2)->long_term_frame_idx; +static inline int compare_fs_by_lt_pic_idx_asc(const void *arg1, + const void *arg2) { + int long_term_frame_idx1 = (*(FrameStore **)arg1)->long_term_frame_idx; + int long_term_frame_idx2 = (*(FrameStore **)arg2)->long_term_frame_idx; - if ( long_term_frame_idx1 < long_term_frame_idx2) + if (long_term_frame_idx1 < long_term_frame_idx2) return -1; - if ( long_term_frame_idx1 > long_term_frame_idx2) + if (long_term_frame_idx1 > long_term_frame_idx2) return 1; else return 0; } - /*! ************************************************************************ * \brief @@ -874,20 +841,18 @@ static inline int compare_fs_by_lt_pic_idx_asc( const void *arg1, const void *ar * ************************************************************************ */ -static inline int compare_pic_by_poc_asc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(StorablePicture**)arg1)->poc; - int poc2 = (*(StorablePicture**)arg2)->poc; +static inline int compare_pic_by_poc_asc(const void *arg1, const void *arg2) { + int poc1 = (*(StorablePicture **)arg1)->poc; + int poc2 = (*(StorablePicture **)arg2)->poc; - if ( poc1 < poc2) - return -1; - if ( poc1 > poc2) + if (poc1 < poc2) + return -1; + if (poc1 > poc2) return 1; else return 0; } - /*! ************************************************************************ * \brief @@ -895,10 +860,9 @@ static inline int compare_pic_by_poc_asc( const void *arg1, const void *arg2 ) * ************************************************************************ */ -static inline int compare_pic_by_poc_desc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(StorablePicture**)arg1)->poc; - int poc2 = (*(StorablePicture**)arg2)->poc; +static inline int compare_pic_by_poc_desc(const void *arg1, const void *arg2) { + int poc1 = (*(StorablePicture **)arg1)->poc; + int poc2 = (*(StorablePicture **)arg2)->poc; if (poc1 < poc2) return 1; @@ -908,7 +872,6 @@ static inline int compare_pic_by_poc_desc( const void *arg1, const void *arg2 ) return 0; } - /*! ************************************************************************ * \brief @@ -916,10 +879,9 @@ static inline int compare_pic_by_poc_desc( const void *arg1, const void *arg2 ) * ************************************************************************ */ -static inline int compare_fs_by_poc_asc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(FrameStore**)arg1)->poc; - int poc2 = (*(FrameStore**)arg2)->poc; +static inline int compare_fs_by_poc_asc(const void *arg1, const void *arg2) { + int poc1 = (*(FrameStore **)arg1)->poc; + int poc2 = (*(FrameStore **)arg2)->poc; if (poc1 < poc2) return -1; @@ -929,7 +891,6 @@ static inline int compare_fs_by_poc_asc( const void *arg1, const void *arg2 ) return 0; } - /*! ************************************************************************ * \brief @@ -937,10 +898,9 @@ static inline int compare_fs_by_poc_asc( const void *arg1, const void *arg2 ) * ************************************************************************ */ -static inline int compare_fs_by_poc_desc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(FrameStore**)arg1)->poc; - int poc2 = (*(FrameStore**)arg2)->poc; +static inline int compare_fs_by_poc_desc(const void *arg1, const void *arg2) { + int poc1 = (*(FrameStore **)arg1)->poc; + int poc2 = (*(FrameStore **)arg2)->poc; if (poc1 < poc2) return 1; @@ -950,7 +910,6 @@ static inline int compare_fs_by_poc_desc( const void *arg1, const void *arg2 ) return 0; } - /*! ************************************************************************ * \brief @@ -958,12 +917,10 @@ static inline int compare_fs_by_poc_desc( const void *arg1, const void *arg2 ) * ************************************************************************ */ -int is_short_ref(StorablePicture *s) -{ +int is_short_ref(StorablePicture *s) { return ((s->used_for_reference) && (!(s->is_long_term))); } - /*! ************************************************************************ * \brief @@ -971,12 +928,10 @@ int is_short_ref(StorablePicture *s) * ************************************************************************ */ -int is_long_ref(StorablePicture *s) -{ +int is_long_ref(StorablePicture *s) { return ((s->used_for_reference) && (s->is_long_term)); } - /*! ************************************************************************ * \brief @@ -984,44 +939,38 @@ int is_long_ref(StorablePicture *s) * ************************************************************************ */ -void gen_pic_list_from_frame_list(PictureStructure currStructure, FrameStore **fs_list, int list_idx, StorablePicture **list, signed char *list_size, int long_term) -{ +void gen_pic_list_from_frame_list(PictureStructure currStructure, + FrameStore **fs_list, int list_idx, + StorablePicture **list, + signed char *list_size, int long_term) { int top_idx = 0; int bot_idx = 0; int (*is_ref)(StorablePicture *s); if (long_term) - is_ref=is_long_ref; + is_ref = is_long_ref; else - is_ref=is_short_ref; + is_ref = is_short_ref; - if (currStructure == TOP_FIELD) - { - while ((top_idxis_used & 1) - { - if(is_ref(fs_list[top_idx]->top_field)) - { + if (currStructure == TOP_FIELD) { + while ((top_idx < list_idx) || (bot_idx < list_idx)) { + for (; top_idx < list_idx; top_idx++) { + if (fs_list[top_idx]->is_used & 1) { + if (is_ref(fs_list[top_idx]->top_field)) { // short term ref pic - list[(short) *list_size] = fs_list[top_idx]->top_field; + list[(short)*list_size] = fs_list[top_idx]->top_field; (*list_size)++; top_idx++; break; } } } - for ( ; bot_idxis_used & 2) - { - if(is_ref(fs_list[bot_idx]->bottom_field)) - { + for (; bot_idx < list_idx; bot_idx++) { + if (fs_list[bot_idx]->is_used & 2) { + if (is_ref(fs_list[bot_idx]->bottom_field)) { // short term ref pic - list[(short) *list_size] = fs_list[bot_idx]->bottom_field; + list[(short)*list_size] = fs_list[bot_idx]->bottom_field; (*list_size)++; bot_idx++; break; @@ -1030,32 +979,24 @@ void gen_pic_list_from_frame_list(PictureStructure currStructure, FrameStore **f } } } - if (currStructure == BOTTOM_FIELD) - { - while ((top_idxis_used & 2) - { - if(is_ref(fs_list[bot_idx]->bottom_field)) - { + if (currStructure == BOTTOM_FIELD) { + while ((top_idx < list_idx) || (bot_idx < list_idx)) { + for (; bot_idx < list_idx; bot_idx++) { + if (fs_list[bot_idx]->is_used & 2) { + if (is_ref(fs_list[bot_idx]->bottom_field)) { // short term ref pic - list[(short) *list_size] = fs_list[bot_idx]->bottom_field; + list[(short)*list_size] = fs_list[bot_idx]->bottom_field; (*list_size)++; bot_idx++; break; } } } - for ( ; top_idxis_used & 1) - { - if(is_ref(fs_list[top_idx]->top_field)) - { + for (; top_idx < list_idx; top_idx++) { + if (fs_list[top_idx]->is_used & 1) { + if (is_ref(fs_list[top_idx]->top_field)) { // short term ref pic - list[(short) *list_size] = fs_list[top_idx]->top_field; + list[(short)*list_size] = fs_list[top_idx]->top_field; (*list_size)++; top_idx++; break; @@ -1074,22 +1015,19 @@ void gen_pic_list_from_frame_list(PictureStructure currStructure, FrameStore **f * ************************************************************************ */ -static void gen_pic_list_from_frame_interview_list(PictureStructure currStrcture, FrameStore **fs_list, int list_idx, StorablePicture **list, signed char *list_size) -{ +static void gen_pic_list_from_frame_interview_list( + PictureStructure currStrcture, FrameStore **fs_list, int list_idx, + StorablePicture **list, signed char *list_size) { int i; - if (currStrcture == TOP_FIELD) - { - for (i=0; itop_field; (*list_size)++; } } - if (currStrcture == BOTTOM_FIELD) - { - for (i=0; ibottom_field; (*list_size)++; } @@ -1097,9 +1035,7 @@ static void gen_pic_list_from_frame_interview_list(PictureStructure currStrcture } #endif - -void update_pic_num(Slice *currSlice) -{ +void update_pic_num(Slice *currSlice) { unsigned int i; VideoParameters *p_Vid = currSlice->p_Vid; DecodedPictureBuffer *p_Dpb = currSlice->p_Dpb; @@ -1108,20 +1044,15 @@ void update_pic_num(Slice *currSlice) int add_top = 0, add_bottom = 0; int MaxFrameNum = 1 << (active_sps->log2_max_frame_num_minus4 + 4); - if (currSlice->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term)) - { - if( p_Dpb->fs_ref[i]->frame_num > currSlice->frame_num ) - { - p_Dpb->fs_ref[i]->frame_num_wrap = p_Dpb->fs_ref[i]->frame_num - MaxFrameNum; - } - else - { + if (currSlice->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term)) { + if (p_Dpb->fs_ref[i]->frame_num > currSlice->frame_num) { + p_Dpb->fs_ref[i]->frame_num_wrap = + p_Dpb->fs_ref[i]->frame_num - MaxFrameNum; + } else { p_Dpb->fs_ref[i]->frame_num_wrap = p_Dpb->fs_ref[i]->frame_num; } p_Dpb->fs_ref[i]->frame->pic_num = p_Dpb->fs_ref[i]->frame_num_wrap; @@ -1129,62 +1060,51 @@ void update_pic_num(Slice *currSlice) } } // update long_term_pic_num - for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_used==3) - { - if (p_Dpb->fs_ltref[i]->frame->is_long_term) - { - p_Dpb->fs_ltref[i]->frame->long_term_pic_num = p_Dpb->fs_ltref[i]->frame->long_term_frame_idx; + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_used == 3) { + if (p_Dpb->fs_ltref[i]->frame->is_long_term) { + p_Dpb->fs_ltref[i]->frame->long_term_pic_num = + p_Dpb->fs_ltref[i]->frame->long_term_frame_idx; } } } - } - else - { - if (currSlice->structure == TOP_FIELD) - { - add_top = 1; + } else { + if (currSlice->structure == TOP_FIELD) { + add_top = 1; add_bottom = 0; - } - else - { - add_top = 0; + } else { + add_top = 0; add_bottom = 1; } - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_reference) - { - if( p_Dpb->fs_ref[i]->frame_num > currSlice->frame_num ) - { - p_Dpb->fs_ref[i]->frame_num_wrap = p_Dpb->fs_ref[i]->frame_num - MaxFrameNum; - } - else - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_reference) { + if (p_Dpb->fs_ref[i]->frame_num > currSlice->frame_num) { + p_Dpb->fs_ref[i]->frame_num_wrap = + p_Dpb->fs_ref[i]->frame_num - MaxFrameNum; + } else { p_Dpb->fs_ref[i]->frame_num_wrap = p_Dpb->fs_ref[i]->frame_num; } - if (p_Dpb->fs_ref[i]->is_reference & 1) - { - p_Dpb->fs_ref[i]->top_field->pic_num = (2 * p_Dpb->fs_ref[i]->frame_num_wrap) + add_top; + if (p_Dpb->fs_ref[i]->is_reference & 1) { + p_Dpb->fs_ref[i]->top_field->pic_num = + (2 * p_Dpb->fs_ref[i]->frame_num_wrap) + add_top; } - if (p_Dpb->fs_ref[i]->is_reference & 2) - { - p_Dpb->fs_ref[i]->bottom_field->pic_num = (2 * p_Dpb->fs_ref[i]->frame_num_wrap) + add_bottom; + if (p_Dpb->fs_ref[i]->is_reference & 2) { + p_Dpb->fs_ref[i]->bottom_field->pic_num = + (2 * p_Dpb->fs_ref[i]->frame_num_wrap) + add_bottom; } } } // update long_term_pic_num - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_long_term & 1) - { - p_Dpb->fs_ltref[i]->top_field->long_term_pic_num = 2 * p_Dpb->fs_ltref[i]->top_field->long_term_frame_idx + add_top; + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_long_term & 1) { + p_Dpb->fs_ltref[i]->top_field->long_term_pic_num = + 2 * p_Dpb->fs_ltref[i]->top_field->long_term_frame_idx + add_top; } - if (p_Dpb->fs_ltref[i]->is_long_term & 2) - { - p_Dpb->fs_ltref[i]->bottom_field->long_term_pic_num = 2 * p_Dpb->fs_ltref[i]->bottom_field->long_term_frame_idx + add_bottom; + if (p_Dpb->fs_ltref[i]->is_long_term & 2) { + p_Dpb->fs_ltref[i]->bottom_field->long_term_pic_num = + 2 * p_Dpb->fs_ltref[i]->bottom_field->long_term_frame_idx + + add_bottom; } } } @@ -1197,9 +1117,8 @@ void update_pic_num(Slice *currSlice) * ************************************************************************ */ -void init_lists_i_slice(Slice *currSlice) -{ - //VideoParameters *p_Vid = currSlice->p_Vid; +void init_lists_i_slice(Slice *currSlice) { + // VideoParameters *p_Vid = currSlice->p_Vid; #if (MVC_EXTENSION_ENABLE) currSlice->listinterviewidx0 = 0; @@ -1217,8 +1136,7 @@ void init_lists_i_slice(Slice *currSlice) * ************************************************************************ */ -void init_lists_p_slice(Slice *currSlice) -{ +void init_lists_p_slice(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; DecodedPictureBuffer *p_Dpb = currSlice->p_Dpb; @@ -1239,16 +1157,16 @@ void init_lists_p_slice(Slice *currSlice) currSlice->listinterviewidx1 = 0; #endif - if (currSlice->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { + if (currSlice->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) #else - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term)) #endif { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; @@ -1256,41 +1174,42 @@ void init_lists_p_slice(Slice *currSlice) } } // order list 0 by PicNum - qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_pic_num_desc); - currSlice->listXsize[0] = (signed char) list0idx; - //printf("listX[0] (PicNum): "); for (i=0; ilistX[0][i]->pic_num);} printf("\n"); + qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture *), + compare_pic_by_pic_num_desc); + currSlice->listXsize[0] = (signed char)list0idx; + // printf("listX[0] (PicNum): "); for (i=0; ilistX[0][i]->pic_num);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_used==3) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ltref[i]->frame->is_long_term && (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) + if (p_Dpb->fs_ltref[i]->frame->is_long_term && + (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) #else if (p_Dpb->fs_ltref[i]->frame->is_long_term) #endif { - currSlice->listX[0][list0idx++]=p_Dpb->fs_ltref[i]->frame; + currSlice->listX[0][list0idx++] = p_Dpb->fs_ltref[i]->frame; } } } - qsort((void *)&currSlice->listX[0][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - currSlice->listXsize[0] = (signed char) list0idx; - } - else - { - fs_list0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list0) + qsort((void *)&currSlice->listX[0][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + currSlice->listXsize[0] = (signed char)list0idx; + } else { + fs_list0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list0) no_mem_exit("init_lists: fs_list0"); - fs_listlt = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_listlt) + fs_listlt = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_listlt) no_mem_exit("init_lists: fs_listlt"); - for (i=0; iref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ref[i]->is_reference && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) + if (p_Dpb->fs_ref[i]->is_reference && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) #else if (p_Dpb->fs_ref[i]->is_reference) #endif @@ -1299,88 +1218,103 @@ void init_lists_p_slice(Slice *currSlice) } } - qsort((void *)fs_list0, list0idx, sizeof(FrameStore*), compare_fs_by_frame_num_desc); + qsort((void *)fs_list0, list0idx, sizeof(FrameStore *), + compare_fs_by_frame_num_desc); - //printf("fs_list0 (FrameNum): "); for (i=0; iframe_num_wrap);} printf("\n"); + // printf("fs_list0 (FrameNum): "); for (i=0; iframe_num_wrap);} printf("\n"); currSlice->listXsize[0] = 0; - gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, currSlice->listX[0], &currSlice->listXsize[0], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, + currSlice->listX[0], &currSlice->listXsize[0], + 0); - //printf("listX[0] (PicNum): "); for (i=0; i < currSlice->listXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->pic_num);} printf("\n"); + // printf("listX[0] (PicNum): "); for (i=0; i < currSlice->listXsize[0]; + // i++){printf ("%d ", currSlice->listX[0][i]->pic_num);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) #endif - fs_listlt[listltidx++]=p_Dpb->fs_ltref[i]; + fs_listlt[listltidx++] = p_Dpb->fs_ltref[i]; } - qsort((void *)fs_listlt, listltidx, sizeof(FrameStore*), compare_fs_by_lt_pic_idx_asc); + qsort((void *)fs_listlt, listltidx, sizeof(FrameStore *), + compare_fs_by_lt_pic_idx_asc); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[0], &currSlice->listXsize[0], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[0], &currSlice->listXsize[0], + 1); free(fs_list0); free(fs_listlt); } - currSlice->listXsize[1] = 0; - + currSlice->listXsize[1] = 0; #if (MVC_EXTENSION_ENABLE) - if (currSlice->svc_extension_flag==0) - { - currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview0) + if (currSlice->svc_extension_flag == 0) { + currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview0) no_mem_exit("init_lists: fs_listinterview0"); list0idx = currSlice->listXsize[0]; - if (currSlice->structure == FRAME) - { - append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); + if (currSlice->structure == FRAME) { + append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); - for (i=0; i<(unsigned int)currSlice->listinterviewidx0; i++) - { - currSlice->listX[0][list0idx++] = currSlice->fs_listinterview0[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx0; i++) { + currSlice->listX[0][list0idx++] = + currSlice->fs_listinterview0[i]->frame; } - currSlice->listXsize[0] = (signed char) list0idx; - } - else - { - append_interview_list(p_Dpb, currSlice->structure, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview0, currSlice->listinterviewidx0, currSlice->listX[0], &currSlice->listXsize[0]); + currSlice->listXsize[0] = (signed char)list0idx; + } else { + append_interview_list(p_Dpb, currSlice->structure, 0, + currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview0, + currSlice->listinterviewidx0, currSlice->listX[0], + &currSlice->listXsize[0]); } } #endif // set max size - currSlice->listXsize[0] = (signed char) imin (currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); - currSlice->listXsize[1] = (signed char) imin (currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); + currSlice->listXsize[0] = (signed char)imin( + currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); + currSlice->listXsize[1] = (signed char)imin( + currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); // set the unused list entries to NULL - for (i=currSlice->listXsize[0]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[0]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[0][i] = p_Vid->no_reference_picture; } - for (i=currSlice->listXsize[1]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[1]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[1][i] = p_Vid->no_reference_picture; } -/*#if PRINTREFLIST -#if (MVC_EXTENSION_ENABLE) - // print out for debug purpose - if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && currSlice->current_slice_nr==0) - { - if(currSlice->listXsize[0]>0) + /*#if PRINTREFLIST + #if (MVC_EXTENSION_ENABLE) + // print out for debug purpose + if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && + currSlice->current_slice_nr==0) { - printf("\n"); - printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[0]); i++) //ref list 0 + if(currSlice->listXsize[0]>0) { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, currSlice->listX[0][i]->view_id); + printf("\n"); + printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", + currSlice->view_id, currSlice->structure==FRAME ? + "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); for(i=0; i<(unsigned + int)(currSlice->listXsize[0]); i++) //ref list 0 + { + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, + currSlice->listX[0][i]->view_id); + } } } - } -#endif -#endif*/ + #endif + #endif*/ } /*! @@ -1390,8 +1324,7 @@ void init_lists_p_slice(Slice *currSlice) * ************************************************************************ */ -void init_lists_b_slice(Slice *currSlice) -{ +void init_lists_b_slice(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; DecodedPictureBuffer *p_Dpb = currSlice->p_Dpb; @@ -1417,102 +1350,109 @@ void init_lists_b_slice(Slice *currSlice) { // B-Slice - if (currSlice->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { + if (currSlice->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) #else - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term)) #endif { - if (currSlice->framepoc >= p_Dpb->fs_ref[i]->frame->poc) //!KS use >= for error concealment - // if (p_Vid->framepoc > p_Dpb->fs_ref[i]->frame->poc) + if (currSlice->framepoc >= + p_Dpb->fs_ref[i] + ->frame->poc) //! KS use >= for error concealment + // if (p_Vid->framepoc > + // p_Dpb->fs_ref[i]->frame->poc) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } } - qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_poc_desc); + qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture *), + compare_pic_by_poc_desc); list0idx_1 = list0idx; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) #else - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term)) #endif { - if (currSlice->framepoc < p_Dpb->fs_ref[i]->frame->poc) - { + if (currSlice->framepoc < p_Dpb->fs_ref[i]->frame->poc) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } } - qsort((void *)&currSlice->listX[0][list0idx_1], list0idx-list0idx_1, sizeof(StorablePicture*), compare_pic_by_poc_asc); + qsort((void *)&currSlice->listX[0][list0idx_1], list0idx - list0idx_1, + sizeof(StorablePicture *), compare_pic_by_poc_asc); - for (j=0; jlistX[1][list0idx-list0idx_1+j]=currSlice->listX[0][j]; + for (j = 0; j < list0idx_1; j++) { + currSlice->listX[1][list0idx - list0idx_1 + j] = currSlice->listX[0][j]; } - for (j=list0idx_1; jlistX[1][j-list0idx_1]=currSlice->listX[0][j]; + for (j = list0idx_1; j < list0idx; j++) { + currSlice->listX[1][j - list0idx_1] = currSlice->listX[0][j]; } - currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char) list0idx; + currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char)list0idx; - // printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); - // printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[1]; i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); + // printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[0]; i++){printf ("%d ", + // currSlice->listX[0][i]->poc);} printf("\n"); + // printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[1]; i++){printf ("%d ", + // currSlice->listX[1][i]->poc);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_used==3) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ltref[i]->frame->is_long_term && (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) + if (p_Dpb->fs_ltref[i]->frame->is_long_term && + (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) #else if (p_Dpb->fs_ltref[i]->frame->is_long_term) #endif { - currSlice->listX[0][list0idx] = p_Dpb->fs_ltref[i]->frame; + currSlice->listX[0][list0idx] = p_Dpb->fs_ltref[i]->frame; currSlice->listX[1][list0idx++] = p_Dpb->fs_ltref[i]->frame; } } } - qsort((void *)&currSlice->listX[0][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - qsort((void *)&currSlice->listX[1][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char) list0idx; - } - else - { - fs_list0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list0) + qsort((void *)&currSlice->listX[0][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + qsort((void *)&currSlice->listX[1][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char)list0idx; + } else { + fs_list0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list0) no_mem_exit("init_lists: fs_list0"); - fs_list1 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list1) + fs_list1 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list1) no_mem_exit("init_lists: fs_list1"); - fs_listlt = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_listlt) + fs_listlt = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_listlt) no_mem_exit("init_lists: fs_listlt"); currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 1; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used) { #if (MVC_EXTENSION_ENABLE) - if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) + if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) #else if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc) #endif @@ -1521,14 +1461,14 @@ void init_lists_b_slice(Slice *currSlice) } } } - qsort((void *)fs_list0, list0idx, sizeof(FrameStore*), compare_fs_by_poc_desc); + qsort((void *)fs_list0, list0idx, sizeof(FrameStore *), + compare_fs_by_poc_desc); list0idx_1 = list0idx; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used) { #if (MVC_EXTENSION_ENABLE) - if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) + if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) #else if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc) #endif @@ -1537,41 +1477,55 @@ void init_lists_b_slice(Slice *currSlice) } } } - qsort((void *)&fs_list0[list0idx_1], list0idx-list0idx_1, sizeof(FrameStore*), compare_fs_by_poc_asc); + qsort((void *)&fs_list0[list0idx_1], list0idx - list0idx_1, + sizeof(FrameStore *), compare_fs_by_poc_asc); - for (j=0; jThisPOC); for (i=0; ipoc);} printf("\n"); - // printf("fs_list1 currPoc=%d (Poc): ", currSlice->ThisPOC); for (i=0; ipoc);} printf("\n"); + // printf("fs_list0 currPoc=%d (Poc): ", currSlice->ThisPOC); for + // (i=0; ipoc);} + // printf("\n"); printf("fs_list1 currPoc=%d (Poc): ", + // currSlice->ThisPOC); for (i=0; ipoc);} printf("\n"); currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 0; - gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, currSlice->listX[0], &currSlice->listXsize[0], 0); - gen_pic_list_from_frame_list(currSlice->structure, fs_list1, list0idx, currSlice->listX[1], &currSlice->listXsize[1], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, + currSlice->listX[0], + &currSlice->listXsize[0], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list1, list0idx, + currSlice->listX[1], + &currSlice->listXsize[1], 0); - // printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); - // printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[1]; i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); + // printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[0]; i++){printf ("%d ", + // currSlice->listX[0][i]->poc);} printf("\n"); + // printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[1]; i++){printf ("%d ", + // currSlice->listX[1][i]->poc);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) #endif - fs_listlt[listltidx++]=p_Dpb->fs_ltref[i]; + fs_listlt[listltidx++] = p_Dpb->fs_ltref[i]; } - qsort((void *)fs_listlt, listltidx, sizeof(FrameStore*), compare_fs_by_lt_pic_idx_asc); + qsort((void *)fs_listlt, listltidx, sizeof(FrameStore *), + compare_fs_by_lt_pic_idx_asc); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[0], &currSlice->listXsize[0], 1); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[1], &currSlice->listXsize[1], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[0], + &currSlice->listXsize[0], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[1], + &currSlice->listXsize[1], 1); free(fs_list0); free(fs_list1); @@ -1579,103 +1533,122 @@ void init_lists_b_slice(Slice *currSlice) } } - if ((currSlice->listXsize[0] == currSlice->listXsize[1]) && (currSlice->listXsize[0] > 1)) - { - // check if lists are identical, if yes swap first two elements of currSlice->listX[1] - int diff=0; - for (j = 0; j< currSlice->listXsize[0]; j++) - { - if (currSlice->listX[0][j] != currSlice->listX[1][j]) - { + if ((currSlice->listXsize[0] == currSlice->listXsize[1]) && + (currSlice->listXsize[0] > 1)) { + // check if lists are identical, if yes swap first two elements of + // currSlice->listX[1] + int diff = 0; + for (j = 0; j < currSlice->listXsize[0]; j++) { + if (currSlice->listX[0][j] != currSlice->listX[1][j]) { diff = 1; break; } } - if (!diff) - { + if (!diff) { StorablePicture *tmp_s = currSlice->listX[1][0]; - currSlice->listX[1][0]=currSlice->listX[1][1]; - currSlice->listX[1][1]=tmp_s; + currSlice->listX[1][0] = currSlice->listX[1][1]; + currSlice->listX[1][1] = tmp_s; } } #if (MVC_EXTENSION_ENABLE) - if (currSlice->svc_extension_flag == 0) - { + if (currSlice->svc_extension_flag == 0) { // B-Slice - currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview0) + currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview0) no_mem_exit("init_lists: fs_listinterview0"); - currSlice->fs_listinterview1 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview1) + currSlice->fs_listinterview1 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview1) no_mem_exit("init_lists: fs_listinterview1"); list0idx = currSlice->listXsize[0]; - if (currSlice->structure == FRAME) - { - append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - append_interview_list(p_Dpb, 0, 1, currSlice->fs_listinterview1, &currSlice->listinterviewidx1, currPOC, curr_view_id, anchor_pic_flag); + if (currSlice->structure == FRAME) { + append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + append_interview_list(p_Dpb, 0, 1, currSlice->fs_listinterview1, + &currSlice->listinterviewidx1, currPOC, + curr_view_id, anchor_pic_flag); - for (i=0; i<(unsigned int)currSlice->listinterviewidx0; i++) - { - currSlice->listX[0][list0idx++]=currSlice->fs_listinterview0[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx0; i++) { + currSlice->listX[0][list0idx++] = + currSlice->fs_listinterview0[i]->frame; } - currSlice->listXsize[0] = (signed char) list0idx; + currSlice->listXsize[0] = (signed char)list0idx; list0idx = currSlice->listXsize[1]; - for (i=0; i<(unsigned int)currSlice->listinterviewidx1; i++) - { - currSlice->listX[1][list0idx++]=currSlice->fs_listinterview1[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx1; i++) { + currSlice->listX[1][list0idx++] = + currSlice->fs_listinterview1[i]->frame; } - currSlice->listXsize[1] = (signed char) list0idx; + currSlice->listXsize[1] = (signed char)list0idx; + } else { + append_interview_list(p_Dpb, currSlice->structure, 0, + currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview0, + currSlice->listinterviewidx0, currSlice->listX[0], + &currSlice->listXsize[0]); + append_interview_list(p_Dpb, currSlice->structure, 1, + currSlice->fs_listinterview1, + &currSlice->listinterviewidx1, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview1, + currSlice->listinterviewidx1, currSlice->listX[1], + &currSlice->listXsize[1]); } - else - { - append_interview_list(p_Dpb, currSlice->structure, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview0, currSlice->listinterviewidx0, currSlice->listX[0], &currSlice->listXsize[0]); - append_interview_list(p_Dpb, currSlice->structure, 1, currSlice->fs_listinterview1, &currSlice->listinterviewidx1, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview1, currSlice->listinterviewidx1, currSlice->listX[1], &currSlice->listXsize[1]); - } } #endif // set max size - currSlice->listXsize[0] = (signed char) imin (currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); - currSlice->listXsize[1] = (signed char) imin (currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); + currSlice->listXsize[0] = (signed char)imin( + currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); + currSlice->listXsize[1] = (signed char)imin( + currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); // set the unused list entries to NULL - for (i=currSlice->listXsize[0]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[0]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[0][i] = p_Vid->no_reference_picture; } - for (i=currSlice->listXsize[1]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[1]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[1][i] = p_Vid->no_reference_picture; } -/*#if PRINTREFLIST -#if (MVC_EXTENSION_ENABLE) - // print out for debug purpose - if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && currSlice->current_slice_nr==0) - { - if((currSlice->listXsize[0]>0) || (currSlice->listXsize[1]>0)) - printf("\n"); - if(currSlice->listXsize[0]>0) + /*#if PRINTREFLIST + #if (MVC_EXTENSION_ENABLE) + // print out for debug purpose + if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && + currSlice->current_slice_nr==0) { - printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[0]); i++) //ref list 0 + if((currSlice->listXsize[0]>0) || (currSlice->listXsize[1]>0)) + printf("\n"); + if(currSlice->listXsize[0]>0) { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, currSlice->listX[0][i]->view_id); + printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", + currSlice->view_id, currSlice->structure==FRAME ? + "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); for(i=0; i<(unsigned + int)(currSlice->listXsize[0]); i++) //ref list 0 + { + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, + currSlice->listX[0][i]->view_id); + } + } + if(currSlice->listXsize[1]>0) + { + printf(" ** (CurViewID:%d) %s Ref Pic List 1 ****\n", + currSlice->view_id, currSlice->structure==FRAME ? + "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); for(i=0; i<(unsigned + int)(currSlice->listXsize[1]); i++) //ref list 1 + { + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[1][i]->poc, currSlice->listX[1][i]->pic_num, + currSlice->listX[1][i]->view_id); + } } } - if(currSlice->listXsize[1]>0) - { - printf(" ** (CurViewID:%d) %s Ref Pic List 1 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[1]); i++) //ref list 1 - { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[1][i]->poc, currSlice->listX[1][i]->pic_num, currSlice->listX[1][i]->view_id); - } - } - } -#endif -#endif*/ + #endif + #endif*/ } /*! @@ -1685,8 +1658,7 @@ void init_lists_b_slice(Slice *currSlice) * ************************************************************************ */ -void init_lists(Slice *currSlice) -{ +void init_lists(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; DecodedPictureBuffer *p_Dpb = currSlice->p_Dpb; @@ -1707,29 +1679,28 @@ void init_lists(Slice *currSlice) int anchor_pic_flag = currSlice->anchor_pic_flag; currSlice->listinterviewidx0 = 0; - currSlice->listinterviewidx1 = 0; + currSlice->listinterviewidx1 = 0; #endif - - if ((currSlice->slice_type == I_SLICE)||(currSlice->slice_type == SI_SLICE)) - { + if ((currSlice->slice_type == I_SLICE) || + (currSlice->slice_type == SI_SLICE)) { currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 0; return; } - if ((currSlice->slice_type == P_SLICE)||(currSlice->slice_type == SP_SLICE)) - { - if (currSlice->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { + if ((currSlice->slice_type == P_SLICE) || + (currSlice->slice_type == SP_SLICE)) { + if (currSlice->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) #else - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term)) #endif { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; @@ -1737,41 +1708,42 @@ void init_lists(Slice *currSlice) } } // order list 0 by PicNum - qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_pic_num_desc); - currSlice->listXsize[0] = (signed char) list0idx; - //printf("listX[0] (PicNum): "); for (i=0; ilistX[0][i]->pic_num);} printf("\n"); + qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture *), + compare_pic_by_pic_num_desc); + currSlice->listXsize[0] = (signed char)list0idx; + // printf("listX[0] (PicNum): "); for (i=0; ilistX[0][i]->pic_num);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_used==3) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ltref[i]->frame->is_long_term && (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) + if (p_Dpb->fs_ltref[i]->frame->is_long_term && + (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) #else if (p_Dpb->fs_ltref[i]->frame->is_long_term) #endif { - currSlice->listX[0][list0idx++]=p_Dpb->fs_ltref[i]->frame; + currSlice->listX[0][list0idx++] = p_Dpb->fs_ltref[i]->frame; } } } - qsort((void *)&currSlice->listX[0][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - currSlice->listXsize[0] = (signed char) list0idx; - } - else - { - fs_list0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list0) - no_mem_exit("init_lists: fs_list0"); - fs_listlt = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_listlt) - no_mem_exit("init_lists: fs_listlt"); + qsort((void *)&currSlice->listX[0][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + currSlice->listXsize[0] = (signed char)list0idx; + } else { + fs_list0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list0) + no_mem_exit("init_lists: fs_list0"); + fs_listlt = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_listlt) + no_mem_exit("init_lists: fs_listlt"); - for (i=0; iref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ref[i]->is_reference && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) + if (p_Dpb->fs_ref[i]->is_reference && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) #else if (p_Dpb->fs_ref[i]->is_reference) #endif @@ -1780,132 +1752,143 @@ void init_lists(Slice *currSlice) } } - qsort((void *)fs_list0, list0idx, sizeof(FrameStore*), compare_fs_by_frame_num_desc); + qsort((void *)fs_list0, list0idx, sizeof(FrameStore *), + compare_fs_by_frame_num_desc); - //printf("fs_list0 (FrameNum): "); for (i=0; iframe_num_wrap);} printf("\n"); + // printf("fs_list0 (FrameNum): "); for (i=0; iframe_num_wrap);} printf("\n"); currSlice->listXsize[0] = 0; - gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, currSlice->listX[0], &currSlice->listXsize[0], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, + currSlice->listX[0], + &currSlice->listXsize[0], 0); - //printf("listX[0] (PicNum): "); for (i=0; i < currSlice->listXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->pic_num);} printf("\n"); + // printf("listX[0] (PicNum): "); for (i=0; i < currSlice->listXsize[0]; + // i++){printf ("%d ", currSlice->listX[0][i]->pic_num);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) #endif - fs_listlt[listltidx++]=p_Dpb->fs_ltref[i]; + fs_listlt[listltidx++] = p_Dpb->fs_ltref[i]; } - qsort((void *)fs_listlt, listltidx, sizeof(FrameStore*), compare_fs_by_lt_pic_idx_asc); + qsort((void *)fs_listlt, listltidx, sizeof(FrameStore *), + compare_fs_by_lt_pic_idx_asc); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[0], &currSlice->listXsize[0], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[0], + &currSlice->listXsize[0], 1); free(fs_list0); free(fs_listlt); } currSlice->listXsize[1] = 0; - } - else - { + } else { // B-Slice - if (currSlice->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { + if (currSlice->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) #else - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term)) #endif { - if (currSlice->framepoc >= p_Dpb->fs_ref[i]->frame->poc) //!KS use >= for error concealment -// if (p_Vid->framepoc > p_Dpb->fs_ref[i]->frame->poc) + if (currSlice->framepoc >= + p_Dpb->fs_ref[i] + ->frame->poc) //! KS use >= for error concealment + // if (p_Vid->framepoc > p_Dpb->fs_ref[i]->frame->poc) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } } - qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_poc_desc); + qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture *), + compare_pic_by_poc_desc); list0idx_1 = list0idx; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) #else - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term)) + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term)) #endif { - if (currSlice->framepoc < p_Dpb->fs_ref[i]->frame->poc) - { + if (currSlice->framepoc < p_Dpb->fs_ref[i]->frame->poc) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } } - qsort((void *)&currSlice->listX[0][list0idx_1], list0idx-list0idx_1, sizeof(StorablePicture*), compare_pic_by_poc_asc); + qsort((void *)&currSlice->listX[0][list0idx_1], list0idx - list0idx_1, + sizeof(StorablePicture *), compare_pic_by_poc_asc); - for (j=0; jlistX[1][list0idx-list0idx_1+j]=currSlice->listX[0][j]; + for (j = 0; j < list0idx_1; j++) { + currSlice->listX[1][list0idx - list0idx_1 + j] = currSlice->listX[0][j]; } - for (j=list0idx_1; jlistX[1][j-list0idx_1]=currSlice->listX[0][j]; + for (j = list0idx_1; j < list0idx; j++) { + currSlice->listX[1][j - list0idx_1] = currSlice->listX[0][j]; } - currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char) list0idx; + currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char)list0idx; -// printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); -// printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[1]; i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); + // printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[0]; i++){printf ("%d ", + // currSlice->listX[0][i]->poc);} printf("\n"); + // printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[1]; i++){printf ("%d ", + // currSlice->listX[1][i]->poc);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_used==3) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_used == 3) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ltref[i]->frame->is_long_term && (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) + if (p_Dpb->fs_ltref[i]->frame->is_long_term && + (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) #else if (p_Dpb->fs_ltref[i]->frame->is_long_term) #endif { - currSlice->listX[0][list0idx] = p_Dpb->fs_ltref[i]->frame; + currSlice->listX[0][list0idx] = p_Dpb->fs_ltref[i]->frame; currSlice->listX[1][list0idx++] = p_Dpb->fs_ltref[i]->frame; } } } - qsort((void *)&currSlice->listX[0][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - qsort((void *)&currSlice->listX[1][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char) list0idx; - } - else - { - fs_list0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list0) - no_mem_exit("init_lists: fs_list0"); - fs_list1 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list1) - no_mem_exit("init_lists: fs_list1"); - fs_listlt = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_listlt) - no_mem_exit("init_lists: fs_listlt"); + qsort((void *)&currSlice->listX[0][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + qsort((void *)&currSlice->listX[1][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char)list0idx; + } else { + fs_list0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list0) + no_mem_exit("init_lists: fs_list0"); + fs_list1 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list1) + no_mem_exit("init_lists: fs_list1"); + fs_listlt = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_listlt) + no_mem_exit("init_lists: fs_listlt"); currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 1; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used) { #if (MVC_EXTENSION_ENABLE) - if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) + if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) #else if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc) #endif @@ -1914,14 +1897,14 @@ void init_lists(Slice *currSlice) } } } - qsort((void *)fs_list0, list0idx, sizeof(FrameStore*), compare_fs_by_poc_desc); + qsort((void *)fs_list0, list0idx, sizeof(FrameStore *), + compare_fs_by_poc_desc); list0idx_1 = list0idx; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used) { #if (MVC_EXTENSION_ENABLE) - if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) + if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) #else if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc) #endif @@ -1930,41 +1913,55 @@ void init_lists(Slice *currSlice) } } } - qsort((void *)&fs_list0[list0idx_1], list0idx-list0idx_1, sizeof(FrameStore*), compare_fs_by_poc_asc); + qsort((void *)&fs_list0[list0idx_1], list0idx - list0idx_1, + sizeof(FrameStore *), compare_fs_by_poc_asc); - for (j=0; jThisPOC); for (i=0; ipoc);} printf("\n"); -// printf("fs_list1 currPoc=%d (Poc): ", currSlice->ThisPOC); for (i=0; ipoc);} printf("\n"); + // printf("fs_list0 currPoc=%d (Poc): ", currSlice->ThisPOC); for + // (i=0; ipoc);} + // printf("\n"); printf("fs_list1 currPoc=%d (Poc): ", + // currSlice->ThisPOC); for (i=0; ipoc);} printf("\n"); currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 0; - gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, currSlice->listX[0], &currSlice->listXsize[0], 0); - gen_pic_list_from_frame_list(currSlice->structure, fs_list1, list0idx, currSlice->listX[1], &currSlice->listXsize[1], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, + currSlice->listX[0], + &currSlice->listXsize[0], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list1, list0idx, + currSlice->listX[1], + &currSlice->listXsize[1], 0); -// printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); -// printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[1]; i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); + // printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[0]; i++){printf ("%d ", + // currSlice->listX[0][i]->poc);} printf("\n"); + // printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[1]; i++){printf ("%d ", + // currSlice->listX[1][i]->poc);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) #endif - fs_listlt[listltidx++]=p_Dpb->fs_ltref[i]; + fs_listlt[listltidx++] = p_Dpb->fs_ltref[i]; } - qsort((void *)fs_listlt, listltidx, sizeof(FrameStore*), compare_fs_by_lt_pic_idx_asc); + qsort((void *)fs_listlt, listltidx, sizeof(FrameStore *), + compare_fs_by_lt_pic_idx_asc); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[0], &currSlice->listXsize[0], 1); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[1], &currSlice->listXsize[1], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[0], + &currSlice->listXsize[0], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[1], + &currSlice->listXsize[1], 1); free(fs_list0); free(fs_list1); @@ -1972,95 +1969,109 @@ void init_lists(Slice *currSlice) } } - if ((currSlice->listXsize[0] == currSlice->listXsize[1]) && (currSlice->listXsize[0] > 1)) - { - // check if lists are identical, if yes swap first two elements of currSlice->listX[1] - int diff=0; - for (j = 0; j< currSlice->listXsize[0]; j++) - { - if (currSlice->listX[0][j]!=currSlice->listX[1][j]) - diff=1; + if ((currSlice->listXsize[0] == currSlice->listXsize[1]) && + (currSlice->listXsize[0] > 1)) { + // check if lists are identical, if yes swap first two elements of + // currSlice->listX[1] + int diff = 0; + for (j = 0; j < currSlice->listXsize[0]; j++) { + if (currSlice->listX[0][j] != currSlice->listX[1][j]) + diff = 1; } - if (!diff) - { + if (!diff) { StorablePicture *tmp_s = currSlice->listX[1][0]; - currSlice->listX[1][0]=currSlice->listX[1][1]; - currSlice->listX[1][1]=tmp_s; + currSlice->listX[1][0] = currSlice->listX[1][1]; + currSlice->listX[1][1] = tmp_s; } } #if (MVC_EXTENSION_ENABLE) - if (currSlice->svc_extension_flag==0) - { - if ((currSlice->slice_type == P_SLICE)||(currSlice->slice_type == SP_SLICE)) - { - currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview0) + if (currSlice->svc_extension_flag == 0) { + if ((currSlice->slice_type == P_SLICE) || + (currSlice->slice_type == SP_SLICE)) { + currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview0) no_mem_exit("init_lists: fs_listinterview0"); list0idx = currSlice->listXsize[0]; - if (currSlice->structure == FRAME) - { - append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); + if (currSlice->structure == FRAME) { + append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); - for (i=0; i<(unsigned int)currSlice->listinterviewidx0; i++) - { - currSlice->listX[0][list0idx++]=currSlice->fs_listinterview0[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx0; i++) { + currSlice->listX[0][list0idx++] = + currSlice->fs_listinterview0[i]->frame; } - currSlice->listXsize[0] = (signed char) list0idx; + currSlice->listXsize[0] = (signed char)list0idx; + } else { + append_interview_list(p_Dpb, currSlice->structure, 0, + currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview0, + currSlice->listinterviewidx0, currSlice->listX[0], + &currSlice->listXsize[0]); } - else - { - append_interview_list(p_Dpb, currSlice->structure, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview0, currSlice->listinterviewidx0, currSlice->listX[0], &currSlice->listXsize[0]); - } - } - else - { + } else { // B-Slice - currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview0) + currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview0) no_mem_exit("init_lists: fs_listinterview0"); - currSlice->fs_listinterview1 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview1) + currSlice->fs_listinterview1 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview1) no_mem_exit("init_lists: fs_listinterview1"); list0idx = currSlice->listXsize[0]; - if (currSlice->structure == FRAME) - { - append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - append_interview_list(p_Dpb, 0, 1, currSlice->fs_listinterview1, &currSlice->listinterviewidx1, currPOC, curr_view_id, anchor_pic_flag); + if (currSlice->structure == FRAME) { + append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + append_interview_list(p_Dpb, 0, 1, currSlice->fs_listinterview1, + &currSlice->listinterviewidx1, currPOC, + curr_view_id, anchor_pic_flag); - for (i=0; i<(unsigned int)currSlice->listinterviewidx0; i++) - { - currSlice->listX[0][list0idx++]=currSlice->fs_listinterview0[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx0; i++) { + currSlice->listX[0][list0idx++] = + currSlice->fs_listinterview0[i]->frame; } - currSlice->listXsize[0] = (signed char) list0idx; + currSlice->listXsize[0] = (signed char)list0idx; list0idx = currSlice->listXsize[1]; - for (i=0; i<(unsigned int)currSlice->listinterviewidx1; i++) - { - currSlice->listX[1][list0idx++]=currSlice->fs_listinterview1[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx1; i++) { + currSlice->listX[1][list0idx++] = + currSlice->fs_listinterview1[i]->frame; } - currSlice->listXsize[1] = (signed char) list0idx; - } - else - { - append_interview_list(p_Dpb, currSlice->structure, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview0, currSlice->listinterviewidx0, currSlice->listX[0], &currSlice->listXsize[0]); - append_interview_list(p_Dpb, currSlice->structure, 1, currSlice->fs_listinterview1, &currSlice->listinterviewidx1, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview1, currSlice->listinterviewidx1, currSlice->listX[1], &currSlice->listXsize[1]); + currSlice->listXsize[1] = (signed char)list0idx; + } else { + append_interview_list(p_Dpb, currSlice->structure, 0, + currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview0, + currSlice->listinterviewidx0, currSlice->listX[0], + &currSlice->listXsize[0]); + append_interview_list(p_Dpb, currSlice->structure, 1, + currSlice->fs_listinterview1, + &currSlice->listinterviewidx1, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview1, + currSlice->listinterviewidx1, currSlice->listX[1], + &currSlice->listXsize[1]); } } } #endif // set max size - currSlice->listXsize[0] = (signed char) imin (currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); - currSlice->listXsize[1] = (signed char) imin (currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); + currSlice->listXsize[0] = (signed char)imin( + currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); + currSlice->listXsize[1] = (signed char)imin( + currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); // set the unused list entries to NULL - for (i=currSlice->listXsize[0]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[0]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[0][i] = p_Vid->no_reference_picture; } - for (i=currSlice->listXsize[1]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[1]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[1][i] = p_Vid->no_reference_picture; } } @@ -2076,66 +2087,61 @@ void init_lists(Slice *currSlice) * ************************************************************************ */ -void init_mbaff_lists(VideoParameters *p_Vid, Slice *currSlice) -{ +void init_mbaff_lists(VideoParameters *p_Vid, Slice *currSlice) { unsigned j; int i; - for (i=2;i<6;i++) - { - for (j=0; jlistX[i][j] = p_Vid->no_reference_picture; } - currSlice->listXsize[i]=0; + currSlice->listXsize[i] = 0; } - for (i=0; ilistXsize[0]; i++) - { - currSlice->listX[2][2*i ] = currSlice->listX[0][i]->top_field; - currSlice->listX[2][2*i+1] = currSlice->listX[0][i]->bottom_field; - currSlice->listX[4][2*i ] = currSlice->listX[0][i]->bottom_field; - currSlice->listX[4][2*i+1] = currSlice->listX[0][i]->top_field; + for (i = 0; i < currSlice->listXsize[0]; i++) { + currSlice->listX[2][2 * i] = currSlice->listX[0][i]->top_field; + currSlice->listX[2][2 * i + 1] = currSlice->listX[0][i]->bottom_field; + currSlice->listX[4][2 * i] = currSlice->listX[0][i]->bottom_field; + currSlice->listX[4][2 * i + 1] = currSlice->listX[0][i]->top_field; } - currSlice->listXsize[2]=currSlice->listXsize[4]=currSlice->listXsize[0] * 2; + currSlice->listXsize[2] = currSlice->listXsize[4] = + currSlice->listXsize[0] * 2; - for (i=0; ilistXsize[1]; i++) - { - currSlice->listX[3][2*i ] = currSlice->listX[1][i]->top_field; - currSlice->listX[3][2*i+1] = currSlice->listX[1][i]->bottom_field; - currSlice->listX[5][2*i ] = currSlice->listX[1][i]->bottom_field; - currSlice->listX[5][2*i+1] = currSlice->listX[1][i]->top_field; + for (i = 0; i < currSlice->listXsize[1]; i++) { + currSlice->listX[3][2 * i] = currSlice->listX[1][i]->top_field; + currSlice->listX[3][2 * i + 1] = currSlice->listX[1][i]->bottom_field; + currSlice->listX[5][2 * i] = currSlice->listX[1][i]->bottom_field; + currSlice->listX[5][2 * i + 1] = currSlice->listX[1][i]->top_field; } - currSlice->listXsize[3]=currSlice->listXsize[5]=currSlice->listXsize[1] * 2; + currSlice->listXsize[3] = currSlice->listXsize[5] = + currSlice->listXsize[1] * 2; } - /*! - ************************************************************************ - * \brief - * Returns short term pic with given picNum - * - ************************************************************************ - */ -StorablePicture* get_short_term_pic(DecodedPictureBuffer *p_Dpb, int picNum) -{ - VideoParameters *p_Vid = p_Dpb->p_Vid; +/*! +************************************************************************ +* \brief +* Returns short term pic with given picNum +* +************************************************************************ +*/ +StorablePicture *get_short_term_pic(DecodedPictureBuffer *p_Dpb, int picNum) { + VideoParameters *p_Vid = p_Dpb->p_Vid; unsigned i; - for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) - { - if (p_Vid->structure == FRAME) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Vid->structure == FRAME) { if (p_Dpb->fs_ref[i]->is_reference == 3) - if ((!p_Dpb->fs_ref[i]->frame->is_long_term)&&(p_Dpb->fs_ref[i]->frame->pic_num == picNum)) + if ((!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->pic_num == picNum)) return p_Dpb->fs_ref[i]->frame; - } - else - { + } else { if (p_Dpb->fs_ref[i]->is_reference & 1) - if ((!p_Dpb->fs_ref[i]->top_field->is_long_term)&&(p_Dpb->fs_ref[i]->top_field->pic_num == picNum)) + if ((!p_Dpb->fs_ref[i]->top_field->is_long_term) && + (p_Dpb->fs_ref[i]->top_field->pic_num == picNum)) return p_Dpb->fs_ref[i]->top_field; if (p_Dpb->fs_ref[i]->is_reference & 2) - if ((!p_Dpb->fs_ref[i]->bottom_field->is_long_term)&&(p_Dpb->fs_ref[i]->bottom_field->pic_num == picNum)) + if ((!p_Dpb->fs_ref[i]->bottom_field->is_long_term) && + (p_Dpb->fs_ref[i]->bottom_field->pic_num == picNum)) return p_Dpb->fs_ref[i]->bottom_field; } } @@ -2150,33 +2156,33 @@ StorablePicture* get_short_term_pic(DecodedPictureBuffer *p_Dpb, int picNum) * ************************************************************************ */ -StorablePicture* get_long_term_pic(DecodedPictureBuffer *p_Dpb, int LongtermPicNum) -{ +StorablePicture *get_long_term_pic(DecodedPictureBuffer *p_Dpb, + int LongtermPicNum) { VideoParameters *p_Vid = p_Dpb->p_Vid; unsigned i; - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Vid->structure==FRAME) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Vid->structure == FRAME) { if (p_Dpb->fs_ltref[i]->is_reference == 3) - if ((p_Dpb->fs_ltref[i]->frame->is_long_term)&&(p_Dpb->fs_ltref[i]->frame->long_term_pic_num == LongtermPicNum)) + if ((p_Dpb->fs_ltref[i]->frame->is_long_term) && + (p_Dpb->fs_ltref[i]->frame->long_term_pic_num == LongtermPicNum)) return p_Dpb->fs_ltref[i]->frame; - } - else - { + } else { if (p_Dpb->fs_ltref[i]->is_reference & 1) - if ((p_Dpb->fs_ltref[i]->top_field->is_long_term)&&(p_Dpb->fs_ltref[i]->top_field->long_term_pic_num == LongtermPicNum)) + if ((p_Dpb->fs_ltref[i]->top_field->is_long_term) && + (p_Dpb->fs_ltref[i]->top_field->long_term_pic_num == + LongtermPicNum)) return p_Dpb->fs_ltref[i]->top_field; if (p_Dpb->fs_ltref[i]->is_reference & 2) - if ((p_Dpb->fs_ltref[i]->bottom_field->is_long_term)&&(p_Dpb->fs_ltref[i]->bottom_field->long_term_pic_num == LongtermPicNum)) + if ((p_Dpb->fs_ltref[i]->bottom_field->is_long_term) && + (p_Dpb->fs_ltref[i]->bottom_field->long_term_pic_num == + LongtermPicNum)) return p_Dpb->fs_ltref[i]->bottom_field; } } return NULL; } - #if (!MVC_EXTENSION_ENABLE) /*! ************************************************************************ @@ -2185,27 +2191,28 @@ StorablePicture* get_long_term_pic(DecodedPictureBuffer *p_Dpb, int LongtermPic * ************************************************************************ */ -static void reorder_short_term(Slice *currSlice, int cur_list, int num_ref_idx_lX_active_minus1, int picNumLX, int *refIdxLX) -{ - StorablePicture **RefPicListX = currSlice->listX[cur_list]; +static void reorder_short_term(Slice *currSlice, int cur_list, + int num_ref_idx_lX_active_minus1, int picNumLX, + int *refIdxLX) { + StorablePicture **RefPicListX = currSlice->listX[cur_list]; int cIdx, nIdx; StorablePicture *picLX; picLX = get_short_term_pic(currSlice->p_Dpb, picNumLX); - for( cIdx = num_ref_idx_lX_active_minus1+1; cIdx > *refIdxLX; cIdx-- ) - RefPicListX[ cIdx ] = RefPicListX[ cIdx - 1]; + for (cIdx = num_ref_idx_lX_active_minus1 + 1; cIdx > *refIdxLX; cIdx--) + RefPicListX[cIdx] = RefPicListX[cIdx - 1]; - RefPicListX[ (*refIdxLX)++ ] = picLX; + RefPicListX[(*refIdxLX)++] = picLX; nIdx = *refIdxLX; - for( cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1+1; cIdx++ ) - if (RefPicListX[ cIdx ]) - { - if( (RefPicListX[ cIdx ]->is_long_term ) || (RefPicListX[ cIdx ]->pic_num != picNumLX )) - RefPicListX[ nIdx++ ] = RefPicListX[ cIdx ]; + for (cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1 + 1; cIdx++) + if (RefPicListX[cIdx]) { + if ((RefPicListX[cIdx]->is_long_term) || + (RefPicListX[cIdx]->pic_num != picNumLX)) + RefPicListX[nIdx++] = RefPicListX[cIdx]; } } @@ -2216,27 +2223,27 @@ static void reorder_short_term(Slice *currSlice, int cur_list, int num_ref_idx_l * ************************************************************************ */ -static void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX, int num_ref_idx_lX_active_minus1, int LongTermPicNum, int *refIdxLX) -{ +static void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX, + int num_ref_idx_lX_active_minus1, + int LongTermPicNum, int *refIdxLX) { int cIdx, nIdx; StorablePicture *picLX; picLX = get_long_term_pic(currSlice->p_Dpb, LongTermPicNum); - for( cIdx = num_ref_idx_lX_active_minus1+1; cIdx > *refIdxLX; cIdx-- ) - RefPicListX[ cIdx ] = RefPicListX[ cIdx - 1]; + for (cIdx = num_ref_idx_lX_active_minus1 + 1; cIdx > *refIdxLX; cIdx--) + RefPicListX[cIdx] = RefPicListX[cIdx - 1]; - RefPicListX[ (*refIdxLX)++ ] = picLX; + RefPicListX[(*refIdxLX)++] = picLX; nIdx = *refIdxLX; - for( cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1+1; cIdx++ ) - { - if (RefPicListX[ cIdx ]) - { - if( (!RefPicListX[ cIdx ]->is_long_term ) || (RefPicListX[ cIdx ]->long_term_pic_num != LongTermPicNum )) - RefPicListX[ nIdx++ ] = RefPicListX[ cIdx ]; + for (cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1 + 1; cIdx++) { + if (RefPicListX[cIdx]) { + if ((!RefPicListX[cIdx]->is_long_term) || + (RefPicListX[cIdx]->long_term_pic_num != LongTermPicNum)) + RefPicListX[nIdx++] = RefPicListX[cIdx]; } } } @@ -2249,12 +2256,13 @@ static void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX, i * ************************************************************************ */ -void reorder_ref_pic_list(Slice *currSlice, int cur_list) -{ - int *reordering_of_pic_nums_idc = currSlice->reordering_of_pic_nums_idc[cur_list]; +void reorder_ref_pic_list(Slice *currSlice, int cur_list) { + int *reordering_of_pic_nums_idc = + currSlice->reordering_of_pic_nums_idc[cur_list]; int *abs_diff_pic_num_minus1 = currSlice->abs_diff_pic_num_minus1[cur_list]; int *long_term_pic_idx = currSlice->long_term_pic_idx[cur_list]; - int num_ref_idx_lX_active_minus1 = currSlice->num_ref_idx_active[cur_list] - 1; + int num_ref_idx_lX_active_minus1 = + currSlice->num_ref_idx_active[cur_list] - 1; VideoParameters *p_Vid = currSlice->p_Vid; int i; @@ -2262,68 +2270,67 @@ void reorder_ref_pic_list(Slice *currSlice, int cur_list) int maxPicNum, currPicNum, picNumLXNoWrap, picNumLXPred, picNumLX; int refIdxLX = 0; - if (p_Vid->structure==FRAME) - { - maxPicNum = p_Vid->MaxFrameNum; + if (p_Vid->structure == FRAME) { + maxPicNum = p_Vid->MaxFrameNum; currPicNum = currSlice->frame_num; - } - else - { - maxPicNum = 2 * p_Vid->MaxFrameNum; + } else { + maxPicNum = 2 * p_Vid->MaxFrameNum; currPicNum = 2 * currSlice->frame_num + 1; } picNumLXPred = currPicNum; - for (i=0; reordering_of_pic_nums_idc[i]!=3; i++) - { - if (reordering_of_pic_nums_idc[i]>3) - error ("Invalid remapping_of_pic_nums_idc command", 500); + for (i = 0; reordering_of_pic_nums_idc[i] != 3; i++) { + if (reordering_of_pic_nums_idc[i] > 3) + error("Invalid remapping_of_pic_nums_idc command", 500); - if (reordering_of_pic_nums_idc[i] < 2) - { - if (reordering_of_pic_nums_idc[i] == 0) - { - if( picNumLXPred - ( abs_diff_pic_num_minus1[i] + 1 ) < 0 ) - picNumLXNoWrap = picNumLXPred - ( abs_diff_pic_num_minus1[i] + 1 ) + maxPicNum; + if (reordering_of_pic_nums_idc[i] < 2) { + if (reordering_of_pic_nums_idc[i] == 0) { + if (picNumLXPred - (abs_diff_pic_num_minus1[i] + 1) < 0) + picNumLXNoWrap = + picNumLXPred - (abs_diff_pic_num_minus1[i] + 1) + maxPicNum; else - picNumLXNoWrap = picNumLXPred - ( abs_diff_pic_num_minus1[i] + 1 ); - } - else // (remapping_of_pic_nums_idc[i] == 1) + picNumLXNoWrap = picNumLXPred - (abs_diff_pic_num_minus1[i] + 1); + } else // (remapping_of_pic_nums_idc[i] == 1) { - if( picNumLXPred + ( abs_diff_pic_num_minus1[i] + 1 ) >= maxPicNum ) - picNumLXNoWrap = picNumLXPred + ( abs_diff_pic_num_minus1[i] + 1 ) - maxPicNum; + if (picNumLXPred + (abs_diff_pic_num_minus1[i] + 1) >= maxPicNum) + picNumLXNoWrap = + picNumLXPred + (abs_diff_pic_num_minus1[i] + 1) - maxPicNum; else - picNumLXNoWrap = picNumLXPred + ( abs_diff_pic_num_minus1[i] + 1 ); + picNumLXNoWrap = picNumLXPred + (abs_diff_pic_num_minus1[i] + 1); } picNumLXPred = picNumLXNoWrap; - if( picNumLXNoWrap > currPicNum ) + if (picNumLXNoWrap > currPicNum) picNumLX = picNumLXNoWrap - maxPicNum; else picNumLX = picNumLXNoWrap; #if (MVC_EXTENSION_ENABLE) - reorder_short_term(currSlice, cur_list, num_ref_idx_lX_active_minus1, picNumLX, &refIdxLX, -1); + reorder_short_term(currSlice, cur_list, num_ref_idx_lX_active_minus1, + picNumLX, &refIdxLX, -1); #else - reorder_short_term(currSlice, cur_list, num_ref_idx_lX_active_minus1, picNumLX, &refIdxLX); + reorder_short_term(currSlice, cur_list, num_ref_idx_lX_active_minus1, + picNumLX, &refIdxLX); #endif - } - else //(remapping_of_pic_nums_idc[i] == 2) + } else //(remapping_of_pic_nums_idc[i] == 2) { #if (MVC_EXTENSION_ENABLE) - reorder_long_term(currSlice, currSlice->listX[cur_list], num_ref_idx_lX_active_minus1, long_term_pic_idx[i], &refIdxLX, -1); + reorder_long_term(currSlice, currSlice->listX[cur_list], + num_ref_idx_lX_active_minus1, long_term_pic_idx[i], + &refIdxLX, -1); #else - reorder_long_term(currSlice, currSlice->listX[cur_list], num_ref_idx_lX_active_minus1, long_term_pic_idx[i], &refIdxLX); + reorder_long_term(currSlice, currSlice->listX[cur_list], + num_ref_idx_lX_active_minus1, long_term_pic_idx[i], + &refIdxLX); #endif } - } // that's a definition - currSlice->listXsize[cur_list] = (signed char) (num_ref_idx_lX_active_minus1 + 1); + currSlice->listXsize[cur_list] = + (signed char)(num_ref_idx_lX_active_minus1 + 1); } - /*! ************************************************************************ * \brief @@ -2332,41 +2339,34 @@ void reorder_ref_pic_list(Slice *currSlice, int cur_list) ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -void update_ref_list(DecodedPictureBuffer *p_Dpb, int curr_view_id) -{ +void update_ref_list(DecodedPictureBuffer *p_Dpb, int curr_view_id) { unsigned i, j; - for (i=0, j=0; iused_size; i++) - { - if (is_short_term_reference(p_Dpb->fs[i]) && p_Dpb->fs[i]->view_id == curr_view_id) - { - p_Dpb->fs_ref[j++]=p_Dpb->fs[i]; + for (i = 0, j = 0; i < p_Dpb->used_size; i++) { + if (is_short_term_reference(p_Dpb->fs[i]) && + p_Dpb->fs[i]->view_id == curr_view_id) { + p_Dpb->fs_ref[j++] = p_Dpb->fs[i]; } } p_Dpb->ref_frames_in_buffer = j; - while (jsize) - { - p_Dpb->fs_ref[j++]=NULL; + while (j < p_Dpb->size) { + p_Dpb->fs_ref[j++] = NULL; } } #else -void update_ref_list(DecodedPictureBuffer *p_Dpb) -{ +void update_ref_list(DecodedPictureBuffer *p_Dpb) { unsigned i, j; - for (i=0, j=0; iused_size; i++) - { - if (is_short_term_reference(p_Dpb->fs[i])) - { - p_Dpb->fs_ref[j++]=p_Dpb->fs[i]; + for (i = 0, j = 0; i < p_Dpb->used_size; i++) { + if (is_short_term_reference(p_Dpb->fs[i])) { + p_Dpb->fs_ref[j++] = p_Dpb->fs[i]; } } p_Dpb->ref_frames_in_buffer = j; - while (jsize) - { - p_Dpb->fs_ref[j++]=NULL; + while (j < p_Dpb->size) { + p_Dpb->fs_ref[j++] = NULL; } } #endif @@ -2380,41 +2380,34 @@ void update_ref_list(DecodedPictureBuffer *p_Dpb) ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -void update_ltref_list(DecodedPictureBuffer *p_Dpb, int curr_view_id) -{ +void update_ltref_list(DecodedPictureBuffer *p_Dpb, int curr_view_id) { unsigned i, j; - for (i=0, j=0; iused_size; i++) - { - if (is_long_term_reference(p_Dpb->fs[i]) && p_Dpb->fs[i]->view_id == curr_view_id) - { + for (i = 0, j = 0; i < p_Dpb->used_size; i++) { + if (is_long_term_reference(p_Dpb->fs[i]) && + p_Dpb->fs[i]->view_id == curr_view_id) { p_Dpb->fs_ltref[j++] = p_Dpb->fs[i]; } } p_Dpb->ltref_frames_in_buffer = j; - while (jsize) - { - p_Dpb->fs_ltref[j++]=NULL; + while (j < p_Dpb->size) { + p_Dpb->fs_ltref[j++] = NULL; } } #else -void update_ltref_list(DecodedPictureBuffer *p_Dpb) -{ +void update_ltref_list(DecodedPictureBuffer *p_Dpb) { unsigned i, j; - for (i=0, j=0; iused_size; i++) - { - if (is_long_term_reference(p_Dpb->fs[i])) - { + for (i = 0, j = 0; i < p_Dpb->used_size; i++) { + if (is_long_term_reference(p_Dpb->fs[i])) { p_Dpb->fs_ltref[j++] = p_Dpb->fs[i]; } } p_Dpb->ltref_frames_in_buffer = j; - while (jsize) - { - p_Dpb->fs_ltref[j++]=NULL; + while (j < p_Dpb->size) { + p_Dpb->fs_ltref[j++] = NULL; } } #endif @@ -2426,26 +2419,23 @@ void update_ltref_list(DecodedPictureBuffer *p_Dpb) * ************************************************************************ */ -static void idr_memory_management(DecodedPictureBuffer *p_Dpb, StorablePicture* p) -{ +static void idr_memory_management(DecodedPictureBuffer *p_Dpb, + StorablePicture *p) { unsigned i; #if (MVC_EXTENSION_ENABLE) VideoParameters *p_Vid = p_Dpb->p_Vid; int size = 0; - int iVOIdx = GetVOIdx(p_Vid, p->view_id); + int iVOIdx = GetVOIdx(p_Vid, p->view_id); int svc_extension_flag = p_Vid->ppSliceList[0]->svc_extension_flag; #endif - assert (p->idr_flag); + assert(p->idr_flag); - if (p->no_output_of_prior_pics_flag) - { + if (p->no_output_of_prior_pics_flag) { // free all stored pictures - for (i=0; iused_size; i++) - { + for (i = 0; i < p_Dpb->used_size; i++) { #if (MVC_EXTENSION_ENABLE) - if (svc_extension_flag == 0 || p_Dpb->fs[i]->view_id == p->view_id) - { + if (svc_extension_flag == 0 || p_Dpb->fs[i]->view_id == p->view_id) { free_frame_store(p_Dpb->fs[i]); p_Dpb->fs[i] = alloc_frame_store(); size++; @@ -2456,31 +2446,28 @@ static void idr_memory_management(DecodedPictureBuffer *p_Dpb, StorablePicture* p_Dpb->fs[i] = alloc_frame_store(); #endif } - for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) if (svc_extension_flag == 0 || p_Dpb->fs_ref[i]->view_id == p->view_id) #endif - p_Dpb->fs_ref[i]=NULL; + p_Dpb->fs_ref[i] = NULL; } - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) if (svc_extension_flag == 0 || p_Dpb->fs_ltref[i]->view_id == p->view_id) #endif - p_Dpb->fs_ltref[i]=NULL; + p_Dpb->fs_ltref[i] = NULL; } #if (MVC_EXTENSION_ENABLE) p_Dpb->used_size -= size; #else - p_Dpb->used_size=0; + p_Dpb->used_size = 0; #endif - } - else - { + } else { #if (MVC_EXTENSION_ENABLE) - - if(p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) //if (svc_extension_flag == 0) + + if (p_Vid->profile_idc == MVC_HIGH || + p_Vid->profile_idc == STEREO_HIGH) // if (svc_extension_flag == 0) flush_dpb(p_Dpb, -1); else flush_dpb(p_Dpb, p->view_id); @@ -2492,36 +2479,30 @@ static void idr_memory_management(DecodedPictureBuffer *p_Dpb, StorablePicture* #if (MVC_EXTENSION_ENABLE) update_ref_list(p_Dpb, p->view_id); - update_ltref_list(p_Dpb, p->view_id); - p_Dpb->last_output_poc = INT_MIN; - p_Dpb->last_output_view_id = -1; + update_ltref_list(p_Dpb, p->view_id); + p_Dpb->last_output_poc = INT_MIN; + p_Dpb->last_output_view_id = -1; - if (p->long_term_reference_flag) - { - p_Dpb->max_long_term_pic_idx[iVOIdx] = 0; - p->is_long_term = 1; - p->long_term_frame_idx = 0; - } - else - { - p_Dpb->max_long_term_pic_idx[iVOIdx] = -1; - p->is_long_term = 0; - } + if (p->long_term_reference_flag) { + p_Dpb->max_long_term_pic_idx[iVOIdx] = 0; + p->is_long_term = 1; + p->long_term_frame_idx = 0; + } else { + p_Dpb->max_long_term_pic_idx[iVOIdx] = -1; + p->is_long_term = 0; + } #else update_ref_list(p_Dpb); update_ltref_list(p_Dpb); p_Dpb->last_output_poc = INT_MIN; - if (p->long_term_reference_flag) - { + if (p->long_term_reference_flag) { p_Dpb->max_long_term_pic_idx = 0; - p->is_long_term = 1; - p->long_term_frame_idx = 0; - } - else - { + p->is_long_term = 1; + p->long_term_frame_idx = 0; + } else { p_Dpb->max_long_term_pic_idx = -1; - p->is_long_term = 0; + p->is_long_term = 0; } #endif } @@ -2533,33 +2514,29 @@ static void idr_memory_management(DecodedPictureBuffer *p_Dpb, StorablePicture* * ************************************************************************ */ -static void sliding_window_memory_management(DecodedPictureBuffer *p_Dpb, StorablePicture* p) -{ +static void sliding_window_memory_management(DecodedPictureBuffer *p_Dpb, + StorablePicture *p) { unsigned i; - assert (!p->idr_flag); - // if this is a reference pic with sliding sliding window, unmark first ref frame - if (p_Dpb->ref_frames_in_buffer==p_Dpb->num_ref_frames - p_Dpb->ltref_frames_in_buffer) - { + assert(!p->idr_flag); + // if this is a reference pic with sliding sliding window, unmark first ref + // frame + if (p_Dpb->ref_frames_in_buffer == + p_Dpb->num_ref_frames - p_Dpb->ltref_frames_in_buffer) { #if (MVC_EXTENSION_ENABLE) - if ( p_Dpb->p_Vid->profile_idc == MVC_HIGH || p_Dpb->p_Vid->profile_idc == STEREO_HIGH ) - { - for (i=0; iused_size;i++) - { - if (p_Dpb->fs[i]->is_reference && (!(p_Dpb->fs[i]->is_long_term)) && p_Dpb->fs[i]->view_id == p->view_id) - { + if (p_Dpb->p_Vid->profile_idc == MVC_HIGH || + p_Dpb->p_Vid->profile_idc == STEREO_HIGH) { + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->is_reference && (!(p_Dpb->fs[i]->is_long_term)) && + p_Dpb->fs[i]->view_id == p->view_id) { unmark_for_reference(p_Dpb->fs[i]); update_ref_list(p_Dpb, p->view_id); break; } } - } - else - { - for (i=0; iused_size;i++) - { - if (p_Dpb->fs[i]->is_reference && (!(p_Dpb->fs[i]->is_long_term))) - { + } else { + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->is_reference && (!(p_Dpb->fs[i]->is_long_term))) { unmark_for_reference(p_Dpb->fs[i]); update_ref_list(p_Dpb, p->view_id); break; @@ -2567,10 +2544,8 @@ static void sliding_window_memory_management(DecodedPictureBuffer *p_Dpb, Storab } } #else - for (i=0; iused_size;i++) - { - if (p_Dpb->fs[i]->is_reference && (!(p_Dpb->fs[i]->is_long_term))) - { + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->is_reference && (!(p_Dpb->fs[i]->is_long_term))) { unmark_for_reference(p_Dpb->fs[i]); update_ref_list(p_Dpb); break; @@ -2588,8 +2563,8 @@ static void sliding_window_memory_management(DecodedPictureBuffer *p_Dpb, Storab * Calculate picNumX ************************************************************************ */ -static int get_pic_num_x (StorablePicture *p, int difference_of_pic_nums_minus1) -{ +static int get_pic_num_x(StorablePicture *p, + int difference_of_pic_nums_minus1) { int currPicNum; if (p->structure == FRAME) @@ -2600,158 +2575,145 @@ static int get_pic_num_x (StorablePicture *p, int difference_of_pic_nums_minus1) return currPicNum - (difference_of_pic_nums_minus1 + 1); } - /*! ************************************************************************ * \brief * Adaptive Memory Management: Mark short term picture unused ************************************************************************ */ -static void mm_unmark_short_term_for_reference(DecodedPictureBuffer *p_Dpb, StorablePicture *p, int difference_of_pic_nums_minus1) -{ +static void +mm_unmark_short_term_for_reference(DecodedPictureBuffer *p_Dpb, + StorablePicture *p, + int difference_of_pic_nums_minus1) { int picNumX; unsigned i; picNumX = get_pic_num_x(p, difference_of_pic_nums_minus1); - for (i=0; iref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ref[i]->view_id == p->view_id) - { + if (p_Dpb->fs_ref[i]->view_id == p->view_id) { #endif - if (p->structure == FRAME) - { - if ((p_Dpb->fs_ref[i]->is_reference==3) && (p_Dpb->fs_ref[i]->is_long_term==0)) - { - if (p_Dpb->fs_ref[i]->frame->pic_num == picNumX) - { - unmark_for_reference(p_Dpb->fs_ref[i]); - return; - } - } - } - else - { - if ((p_Dpb->fs_ref[i]->is_reference & 1) && (!(p_Dpb->fs_ref[i]->is_long_term & 1))) - { - if (p_Dpb->fs_ref[i]->top_field->pic_num == picNumX) - { - p_Dpb->fs_ref[i]->top_field->used_for_reference = 0; - p_Dpb->fs_ref[i]->is_reference &= 2; - if (p_Dpb->fs_ref[i]->is_used == 3) - { - p_Dpb->fs_ref[i]->frame->used_for_reference = 0; + if (p->structure == FRAME) { + if ((p_Dpb->fs_ref[i]->is_reference == 3) && + (p_Dpb->fs_ref[i]->is_long_term == 0)) { + if (p_Dpb->fs_ref[i]->frame->pic_num == picNumX) { + unmark_for_reference(p_Dpb->fs_ref[i]); + return; } - return; } - } - if ((p_Dpb->fs_ref[i]->is_reference & 2) && (!(p_Dpb->fs_ref[i]->is_long_term & 2))) - { - if (p_Dpb->fs_ref[i]->bottom_field->pic_num == picNumX) - { - p_Dpb->fs_ref[i]->bottom_field->used_for_reference = 0; - p_Dpb->fs_ref[i]->is_reference &= 1; - if (p_Dpb->fs_ref[i]->is_used == 3) - { - p_Dpb->fs_ref[i]->frame->used_for_reference = 0; + } else { + if ((p_Dpb->fs_ref[i]->is_reference & 1) && + (!(p_Dpb->fs_ref[i]->is_long_term & 1))) { + if (p_Dpb->fs_ref[i]->top_field->pic_num == picNumX) { + p_Dpb->fs_ref[i]->top_field->used_for_reference = 0; + p_Dpb->fs_ref[i]->is_reference &= 2; + if (p_Dpb->fs_ref[i]->is_used == 3) { + p_Dpb->fs_ref[i]->frame->used_for_reference = 0; + } + return; + } + } + if ((p_Dpb->fs_ref[i]->is_reference & 2) && + (!(p_Dpb->fs_ref[i]->is_long_term & 2))) { + if (p_Dpb->fs_ref[i]->bottom_field->pic_num == picNumX) { + p_Dpb->fs_ref[i]->bottom_field->used_for_reference = 0; + p_Dpb->fs_ref[i]->is_reference &= 1; + if (p_Dpb->fs_ref[i]->is_used == 3) { + p_Dpb->fs_ref[i]->frame->used_for_reference = 0; + } + return; } - return; } } - } #if (MVC_EXTENSION_ENABLE) } #endif } } - /*! ************************************************************************ * \brief * Adaptive Memory Management: Mark long term picture unused ************************************************************************ */ -static void mm_unmark_long_term_for_reference(DecodedPictureBuffer *p_Dpb, StorablePicture *p, int long_term_pic_num) -{ +static void mm_unmark_long_term_for_reference(DecodedPictureBuffer *p_Dpb, + StorablePicture *p, + int long_term_pic_num) { unsigned i; - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ltref[i]->view_id == p->view_id) - { + if (p_Dpb->fs_ltref[i]->view_id == p->view_id) { #endif - if (p->structure == FRAME) - { - if ((p_Dpb->fs_ltref[i]->is_reference==3) && (p_Dpb->fs_ltref[i]->is_long_term==3)) - { - if (p_Dpb->fs_ltref[i]->frame->long_term_pic_num == long_term_pic_num) - { - unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); - } - } - } - else - { - if ((p_Dpb->fs_ltref[i]->is_reference & 1) && ((p_Dpb->fs_ltref[i]->is_long_term & 1))) - { - if (p_Dpb->fs_ltref[i]->top_field->long_term_pic_num == long_term_pic_num) - { - p_Dpb->fs_ltref[i]->top_field->used_for_reference = 0; - p_Dpb->fs_ltref[i]->top_field->is_long_term = 0; - p_Dpb->fs_ltref[i]->is_reference &= 2; - p_Dpb->fs_ltref[i]->is_long_term &= 2; - if (p_Dpb->fs_ltref[i]->is_used == 3) - { - p_Dpb->fs_ltref[i]->frame->used_for_reference = 0; - p_Dpb->fs_ltref[i]->frame->is_long_term = 0; + if (p->structure == FRAME) { + if ((p_Dpb->fs_ltref[i]->is_reference == 3) && + (p_Dpb->fs_ltref[i]->is_long_term == 3)) { + if (p_Dpb->fs_ltref[i]->frame->long_term_pic_num == + long_term_pic_num) { + unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); } - return; } - } - if ((p_Dpb->fs_ltref[i]->is_reference & 2) && ((p_Dpb->fs_ltref[i]->is_long_term & 2))) - { - if (p_Dpb->fs_ltref[i]->bottom_field->long_term_pic_num == long_term_pic_num) - { - p_Dpb->fs_ltref[i]->bottom_field->used_for_reference = 0; - p_Dpb->fs_ltref[i]->bottom_field->is_long_term = 0; - p_Dpb->fs_ltref[i]->is_reference &= 1; - p_Dpb->fs_ltref[i]->is_long_term &= 1; - if (p_Dpb->fs_ltref[i]->is_used == 3) - { - p_Dpb->fs_ltref[i]->frame->used_for_reference = 0; - p_Dpb->fs_ltref[i]->frame->is_long_term = 0; + } else { + if ((p_Dpb->fs_ltref[i]->is_reference & 1) && + ((p_Dpb->fs_ltref[i]->is_long_term & 1))) { + if (p_Dpb->fs_ltref[i]->top_field->long_term_pic_num == + long_term_pic_num) { + p_Dpb->fs_ltref[i]->top_field->used_for_reference = 0; + p_Dpb->fs_ltref[i]->top_field->is_long_term = 0; + p_Dpb->fs_ltref[i]->is_reference &= 2; + p_Dpb->fs_ltref[i]->is_long_term &= 2; + if (p_Dpb->fs_ltref[i]->is_used == 3) { + p_Dpb->fs_ltref[i]->frame->used_for_reference = 0; + p_Dpb->fs_ltref[i]->frame->is_long_term = 0; + } + return; + } + } + if ((p_Dpb->fs_ltref[i]->is_reference & 2) && + ((p_Dpb->fs_ltref[i]->is_long_term & 2))) { + if (p_Dpb->fs_ltref[i]->bottom_field->long_term_pic_num == + long_term_pic_num) { + p_Dpb->fs_ltref[i]->bottom_field->used_for_reference = 0; + p_Dpb->fs_ltref[i]->bottom_field->is_long_term = 0; + p_Dpb->fs_ltref[i]->is_reference &= 1; + p_Dpb->fs_ltref[i]->is_long_term &= 1; + if (p_Dpb->fs_ltref[i]->is_used == 3) { + p_Dpb->fs_ltref[i]->frame->used_for_reference = 0; + p_Dpb->fs_ltref[i]->frame->is_long_term = 0; + } + return; } - return; } } - } #if (MVC_EXTENSION_ENABLE) } #endif } } - /*! ************************************************************************ * \brief - * Mark a long-term reference frame or complementary field pair unused for referemce + * Mark a long-term reference frame or complementary field pair unused for + *referemce ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -static void unmark_long_term_frame_for_reference_by_frame_idx(DecodedPictureBuffer *p_Dpb, int long_term_frame_idx, int view_id) +static void unmark_long_term_frame_for_reference_by_frame_idx( + DecodedPictureBuffer *p_Dpb, int long_term_frame_idx, int view_id) #else -static void unmark_long_term_frame_for_reference_by_frame_idx(DecodedPictureBuffer *p_Dpb, int long_term_frame_idx) +static void +unmark_long_term_frame_for_reference_by_frame_idx(DecodedPictureBuffer *p_Dpb, + int long_term_frame_idx) #endif { unsigned i; - for(i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ltref[i]->long_term_frame_idx == long_term_frame_idx && p_Dpb->fs_ltref[i]->view_id == view_id) + if (p_Dpb->fs_ltref[i]->long_term_frame_idx == long_term_frame_idx && + p_Dpb->fs_ltref[i]->view_id == view_id) #else if (p_Dpb->fs_ltref[i]->long_term_frame_idx == long_term_frame_idx) #endif @@ -2767,285 +2729,257 @@ static void unmark_long_term_frame_for_reference_by_frame_idx(DecodedPictureBuff ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -static void unmark_long_term_field_for_reference_by_frame_idx(DecodedPictureBuffer *p_Dpb, PictureStructure structure, int long_term_frame_idx, int mark_current, unsigned curr_frame_num, int curr_pic_num, int curr_view_id) +static void unmark_long_term_field_for_reference_by_frame_idx( + DecodedPictureBuffer *p_Dpb, PictureStructure structure, + int long_term_frame_idx, int mark_current, unsigned curr_frame_num, + int curr_pic_num, int curr_view_id) #else -static void unmark_long_term_field_for_reference_by_frame_idx(DecodedPictureBuffer *p_Dpb, PictureStructure structure, int long_term_frame_idx, int mark_current, unsigned curr_frame_num, int curr_pic_num) +static void unmark_long_term_field_for_reference_by_frame_idx( + DecodedPictureBuffer *p_Dpb, PictureStructure structure, + int long_term_frame_idx, int mark_current, unsigned curr_frame_num, + int curr_pic_num) #endif { VideoParameters *p_Vid = p_Dpb->p_Vid; unsigned i; - assert(structure!=FRAME); - if (curr_pic_num<0) + assert(structure != FRAME); + if (curr_pic_num < 0) curr_pic_num += (2 * p_Vid->MaxFrameNum); - for(i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) - { + if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) { #endif - if (p_Dpb->fs_ltref[i]->long_term_frame_idx == long_term_frame_idx) - { - if (structure == TOP_FIELD) - { - if ((p_Dpb->fs_ltref[i]->is_long_term == 3)) - { - unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); - } - else - { - if ((p_Dpb->fs_ltref[i]->is_long_term == 1)) - { + if (p_Dpb->fs_ltref[i]->long_term_frame_idx == long_term_frame_idx) { + if (structure == TOP_FIELD) { + if ((p_Dpb->fs_ltref[i]->is_long_term == 3)) { unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); - } - else - { - if (mark_current) - { - if (p_Dpb->last_picture) - { - if ( ( p_Dpb->last_picture != p_Dpb->fs_ltref[i] )|| p_Dpb->last_picture->frame_num != curr_frame_num) + } else { + if ((p_Dpb->fs_ltref[i]->is_long_term == 1)) { + unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } else { + if (mark_current) { + if (p_Dpb->last_picture) { + if ((p_Dpb->last_picture != p_Dpb->fs_ltref[i]) || + p_Dpb->last_picture->frame_num != curr_frame_num) + unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } else { unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); - } - else - { - unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } + } else { + if ((p_Dpb->fs_ltref[i]->frame_num) != + (unsigned)(curr_pic_num >> 1)) { + unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } } } - else - { - if ((p_Dpb->fs_ltref[i]->frame_num) != (unsigned)(curr_pic_num >> 1)) - { - unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } + } + if (structure == BOTTOM_FIELD) { + if ((p_Dpb->fs_ltref[i]->is_long_term == 3)) { + unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } else { + if ((p_Dpb->fs_ltref[i]->is_long_term == 2)) { + unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } else { + if (mark_current) { + if (p_Dpb->last_picture) { + if ((p_Dpb->last_picture != p_Dpb->fs_ltref[i]) || + p_Dpb->last_picture->frame_num != curr_frame_num) + unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } else { + unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } + } else { + if ((p_Dpb->fs_ltref[i]->frame_num) != + (unsigned)(curr_pic_num >> 1)) { + unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); + } } } } } } - if (structure == BOTTOM_FIELD) - { - if ((p_Dpb->fs_ltref[i]->is_long_term == 3)) - { - unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); - } - else - { - if ((p_Dpb->fs_ltref[i]->is_long_term == 2)) - { - unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); - } - else - { - if (mark_current) - { - if (p_Dpb->last_picture) - { - if ( ( p_Dpb->last_picture != p_Dpb->fs_ltref[i] )|| p_Dpb->last_picture->frame_num != curr_frame_num) - unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); - } - else - { - unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); - } - } - else - { - if ((p_Dpb->fs_ltref[i]->frame_num) != (unsigned)(curr_pic_num >> 1)) - { - unmark_for_long_term_reference(p_Dpb->fs_ltref[i]); - } - } - } - } - } - } #if (MVC_EXTENSION_ENABLE) } #endif } } - /*! ************************************************************************ * \brief * mark a picture as long-term reference ************************************************************************ */ -static void mark_pic_long_term(DecodedPictureBuffer *p_Dpb, StorablePicture* p, int long_term_frame_idx, int picNumX) -{ +static void mark_pic_long_term(DecodedPictureBuffer *p_Dpb, StorablePicture *p, + int long_term_frame_idx, int picNumX) { unsigned i; int add_top, add_bottom; - if (p->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { + if (p->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ref[i]->view_id == p->view_id) - { + if (p_Dpb->fs_ref[i]->view_id == p->view_id) { #endif - if (p_Dpb->fs_ref[i]->is_reference == 3) - { - if ((!p_Dpb->fs_ref[i]->frame->is_long_term)&&(p_Dpb->fs_ref[i]->frame->pic_num == picNumX)) - { - p_Dpb->fs_ref[i]->long_term_frame_idx = p_Dpb->fs_ref[i]->frame->long_term_frame_idx - = long_term_frame_idx; - p_Dpb->fs_ref[i]->frame->long_term_pic_num = long_term_frame_idx; - p_Dpb->fs_ref[i]->frame->is_long_term = 1; + if (p_Dpb->fs_ref[i]->is_reference == 3) { + if ((!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->pic_num == picNumX)) { + p_Dpb->fs_ref[i]->long_term_frame_idx = + p_Dpb->fs_ref[i]->frame->long_term_frame_idx = + long_term_frame_idx; + p_Dpb->fs_ref[i]->frame->long_term_pic_num = long_term_frame_idx; + p_Dpb->fs_ref[i]->frame->is_long_term = 1; - if (p_Dpb->fs_ref[i]->top_field && p_Dpb->fs_ref[i]->bottom_field) - { - p_Dpb->fs_ref[i]->top_field->long_term_frame_idx = p_Dpb->fs_ref[i]->bottom_field->long_term_frame_idx - = long_term_frame_idx; - p_Dpb->fs_ref[i]->top_field->long_term_pic_num = long_term_frame_idx; - p_Dpb->fs_ref[i]->bottom_field->long_term_pic_num = long_term_frame_idx; - - p_Dpb->fs_ref[i]->top_field->is_long_term = p_Dpb->fs_ref[i]->bottom_field->is_long_term - = 1; + if (p_Dpb->fs_ref[i]->top_field && p_Dpb->fs_ref[i]->bottom_field) { + p_Dpb->fs_ref[i]->top_field->long_term_frame_idx = + p_Dpb->fs_ref[i]->bottom_field->long_term_frame_idx = + long_term_frame_idx; + p_Dpb->fs_ref[i]->top_field->long_term_pic_num = + long_term_frame_idx; + p_Dpb->fs_ref[i]->bottom_field->long_term_pic_num = + long_term_frame_idx; + p_Dpb->fs_ref[i]->top_field->is_long_term = + p_Dpb->fs_ref[i]->bottom_field->is_long_term = 1; + } + p_Dpb->fs_ref[i]->is_long_term = 3; + return; } - p_Dpb->fs_ref[i]->is_long_term = 3; - return; } - } #if (MVC_EXTENSION_ENABLE) } #endif } - printf ("Warning: reference frame for long term marking not found\n"); - } - else - { - if (p->structure == TOP_FIELD) - { - add_top = 1; + printf("Warning: reference frame for long term marking not found\n"); + } else { + if (p->structure == TOP_FIELD) { + add_top = 1; add_bottom = 0; - } - else - { - add_top = 0; + } else { + add_top = 0; add_bottom = 1; } - for (i=0; iref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ref[i]->view_id == p->view_id) - { + if (p_Dpb->fs_ref[i]->view_id == p->view_id) { #endif - if (p_Dpb->fs_ref[i]->is_reference & 1) - { - if ((!p_Dpb->fs_ref[i]->top_field->is_long_term)&&(p_Dpb->fs_ref[i]->top_field->pic_num == picNumX)) - { - if ((p_Dpb->fs_ref[i]->is_long_term) && (p_Dpb->fs_ref[i]->long_term_frame_idx != long_term_frame_idx)) - { - printf ("Warning: assigning long_term_frame_idx different from other field\n"); - } + if (p_Dpb->fs_ref[i]->is_reference & 1) { + if ((!p_Dpb->fs_ref[i]->top_field->is_long_term) && + (p_Dpb->fs_ref[i]->top_field->pic_num == picNumX)) { + if ((p_Dpb->fs_ref[i]->is_long_term) && + (p_Dpb->fs_ref[i]->long_term_frame_idx != + long_term_frame_idx)) { + printf("Warning: assigning long_term_frame_idx different from " + "other field\n"); + } - p_Dpb->fs_ref[i]->long_term_frame_idx = p_Dpb->fs_ref[i]->top_field->long_term_frame_idx - = long_term_frame_idx; - p_Dpb->fs_ref[i]->top_field->long_term_pic_num = 2 * long_term_frame_idx + add_top; - p_Dpb->fs_ref[i]->top_field->is_long_term = 1; - p_Dpb->fs_ref[i]->is_long_term |= 1; - if (p_Dpb->fs_ref[i]->is_long_term == 3) - { - p_Dpb->fs_ref[i]->frame->is_long_term = 1; - p_Dpb->fs_ref[i]->frame->long_term_frame_idx = p_Dpb->fs_ref[i]->frame->long_term_pic_num = long_term_frame_idx; + p_Dpb->fs_ref[i]->long_term_frame_idx = + p_Dpb->fs_ref[i]->top_field->long_term_frame_idx = + long_term_frame_idx; + p_Dpb->fs_ref[i]->top_field->long_term_pic_num = + 2 * long_term_frame_idx + add_top; + p_Dpb->fs_ref[i]->top_field->is_long_term = 1; + p_Dpb->fs_ref[i]->is_long_term |= 1; + if (p_Dpb->fs_ref[i]->is_long_term == 3) { + p_Dpb->fs_ref[i]->frame->is_long_term = 1; + p_Dpb->fs_ref[i]->frame->long_term_frame_idx = + p_Dpb->fs_ref[i]->frame->long_term_pic_num = + long_term_frame_idx; + } + return; } - return; } - } - if (p_Dpb->fs_ref[i]->is_reference & 2) - { - if ((!p_Dpb->fs_ref[i]->bottom_field->is_long_term)&&(p_Dpb->fs_ref[i]->bottom_field->pic_num == picNumX)) - { - if ((p_Dpb->fs_ref[i]->is_long_term) && (p_Dpb->fs_ref[i]->long_term_frame_idx != long_term_frame_idx)) - { - printf ("Warning: assigning long_term_frame_idx different from other field\n"); - } + if (p_Dpb->fs_ref[i]->is_reference & 2) { + if ((!p_Dpb->fs_ref[i]->bottom_field->is_long_term) && + (p_Dpb->fs_ref[i]->bottom_field->pic_num == picNumX)) { + if ((p_Dpb->fs_ref[i]->is_long_term) && + (p_Dpb->fs_ref[i]->long_term_frame_idx != + long_term_frame_idx)) { + printf("Warning: assigning long_term_frame_idx different from " + "other field\n"); + } - p_Dpb->fs_ref[i]->long_term_frame_idx = p_Dpb->fs_ref[i]->bottom_field->long_term_frame_idx - = long_term_frame_idx; - p_Dpb->fs_ref[i]->bottom_field->long_term_pic_num = 2 * long_term_frame_idx + add_bottom; - p_Dpb->fs_ref[i]->bottom_field->is_long_term = 1; - p_Dpb->fs_ref[i]->is_long_term |= 2; - if (p_Dpb->fs_ref[i]->is_long_term == 3) - { - p_Dpb->fs_ref[i]->frame->is_long_term = 1; - p_Dpb->fs_ref[i]->frame->long_term_frame_idx = p_Dpb->fs_ref[i]->frame->long_term_pic_num = long_term_frame_idx; + p_Dpb->fs_ref[i]->long_term_frame_idx = + p_Dpb->fs_ref[i]->bottom_field->long_term_frame_idx = + long_term_frame_idx; + p_Dpb->fs_ref[i]->bottom_field->long_term_pic_num = + 2 * long_term_frame_idx + add_bottom; + p_Dpb->fs_ref[i]->bottom_field->is_long_term = 1; + p_Dpb->fs_ref[i]->is_long_term |= 2; + if (p_Dpb->fs_ref[i]->is_long_term == 3) { + p_Dpb->fs_ref[i]->frame->is_long_term = 1; + p_Dpb->fs_ref[i]->frame->long_term_frame_idx = + p_Dpb->fs_ref[i]->frame->long_term_pic_num = + long_term_frame_idx; + } + return; } - return; } - } #if (MVC_EXTENSION_ENABLE) } #endif } - printf ("Warning: reference field for long term marking not found\n"); + printf("Warning: reference field for long term marking not found\n"); } } - /*! ************************************************************************ * \brief * Assign a long term frame index to a short term picture ************************************************************************ */ -static void mm_assign_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, StorablePicture* p, int difference_of_pic_nums_minus1, int long_term_frame_idx) -{ +static void mm_assign_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, + StorablePicture *p, + int difference_of_pic_nums_minus1, + int long_term_frame_idx) { int picNumX = get_pic_num_x(p, difference_of_pic_nums_minus1); // remove frames/fields with same long_term_frame_idx - if (p->structure == FRAME) - { + if (p->structure == FRAME) { #if (MVC_EXTENSION_ENABLE) - unmark_long_term_frame_for_reference_by_frame_idx(p_Dpb, long_term_frame_idx, p->view_id); + unmark_long_term_frame_for_reference_by_frame_idx( + p_Dpb, long_term_frame_idx, p->view_id); #else - unmark_long_term_frame_for_reference_by_frame_idx(p_Dpb, long_term_frame_idx); + unmark_long_term_frame_for_reference_by_frame_idx(p_Dpb, + long_term_frame_idx); #endif - } - else - { + } else { unsigned i; PictureStructure structure = FRAME; - for (i=0; iref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ref[i]->view_id == p->view_id) - { + if (p_Dpb->fs_ref[i]->view_id == p->view_id) { #endif - if (p_Dpb->fs_ref[i]->is_reference & 1) - { - if (p_Dpb->fs_ref[i]->top_field->pic_num == picNumX) - { - structure = TOP_FIELD; - break; + if (p_Dpb->fs_ref[i]->is_reference & 1) { + if (p_Dpb->fs_ref[i]->top_field->pic_num == picNumX) { + structure = TOP_FIELD; + break; + } } - } - if (p_Dpb->fs_ref[i]->is_reference & 2) - { - if (p_Dpb->fs_ref[i]->bottom_field->pic_num == picNumX) - { - structure = BOTTOM_FIELD; - break; + if (p_Dpb->fs_ref[i]->is_reference & 2) { + if (p_Dpb->fs_ref[i]->bottom_field->pic_num == picNumX) { + structure = BOTTOM_FIELD; + break; + } } - } #if (MVC_EXTENSION_ENABLE) } #endif } - if (structure==FRAME) - { - error ("field for long term marking not found",200); + if (structure == FRAME) { + error("field for long term marking not found", 200); } #if (MVC_EXTENSION_ENABLE) - unmark_long_term_field_for_reference_by_frame_idx(p_Dpb, structure, long_term_frame_idx, 0, 0, picNumX, p->view_id); + unmark_long_term_field_for_reference_by_frame_idx( + p_Dpb, structure, long_term_frame_idx, 0, 0, picNumX, p->view_id); #else - unmark_long_term_field_for_reference_by_frame_idx(p_Dpb, structure, long_term_frame_idx, 0, 0, picNumX); + unmark_long_term_field_for_reference_by_frame_idx( + p_Dpb, structure, long_term_frame_idx, 0, 0, picNumX); #endif } @@ -3059,9 +2993,12 @@ static void mm_assign_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, StorableP ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -void mm_update_max_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, int max_long_term_frame_idx_plus1, int curr_view_id) +void mm_update_max_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, + int max_long_term_frame_idx_plus1, + int curr_view_id) #else -void mm_update_max_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, int max_long_term_frame_idx_plus1) +void mm_update_max_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, + int max_long_term_frame_idx_plus1) #endif { unsigned i; @@ -3075,10 +3012,11 @@ void mm_update_max_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, int max_long #endif // check for invalid frames - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ltref[i]->long_term_frame_idx > p_Dpb->max_long_term_pic_idx[iVOIdx] && p_Dpb->fs_ltref[i]->view_id == curr_view_id) + if (p_Dpb->fs_ltref[i]->long_term_frame_idx > + p_Dpb->max_long_term_pic_idx[iVOIdx] && + p_Dpb->fs_ltref[i]->view_id == curr_view_id) #else if (p_Dpb->fs_ltref[i]->long_term_frame_idx > p_Dpb->max_long_term_pic_idx) #endif @@ -3088,7 +3026,6 @@ void mm_update_max_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, int max_long } } - /*! ************************************************************************ * \brief @@ -3096,13 +3033,12 @@ void mm_update_max_long_term_frame_idx(DecodedPictureBuffer *p_Dpb, int max_long ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -static void mm_unmark_all_long_term_for_reference (DecodedPictureBuffer *p_Dpb, int curr_view_id) -{ +static void mm_unmark_all_long_term_for_reference(DecodedPictureBuffer *p_Dpb, + int curr_view_id) { mm_update_max_long_term_frame_idx(p_Dpb, 0, curr_view_id); } #else -static void mm_unmark_all_long_term_for_reference (DecodedPictureBuffer *p_Dpb) -{ +static void mm_unmark_all_long_term_for_reference(DecodedPictureBuffer *p_Dpb) { mm_update_max_long_term_frame_idx(p_Dpb, 0); } #endif @@ -3114,57 +3050,52 @@ static void mm_unmark_all_long_term_for_reference (DecodedPictureBuffer *p_Dpb) ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -static void mm_unmark_all_short_term_for_reference (DecodedPictureBuffer *p_Dpb, int curr_view_id) -{ +static void mm_unmark_all_short_term_for_reference(DecodedPictureBuffer *p_Dpb, + int curr_view_id) { unsigned int i; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->view_id == curr_view_id) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->view_id == curr_view_id) { unmark_for_reference(p_Dpb->fs_ref[i]); } } update_ref_list(p_Dpb, curr_view_id); } #else -static void mm_unmark_all_short_term_for_reference (DecodedPictureBuffer *p_Dpb) -{ +static void +mm_unmark_all_short_term_for_reference(DecodedPictureBuffer *p_Dpb) { unsigned int i; - for (i=0; iref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { unmark_for_reference(p_Dpb->fs_ref[i]); } update_ref_list(p_Dpb); } #endif - /*! ************************************************************************ * \brief * Mark the current picture used for long term reference ************************************************************************ */ -static void mm_mark_current_picture_long_term(DecodedPictureBuffer *p_Dpb, StorablePicture *p, int long_term_frame_idx) -{ +static void mm_mark_current_picture_long_term(DecodedPictureBuffer *p_Dpb, + StorablePicture *p, + int long_term_frame_idx) { // remove long term pictures with same long_term_frame_idx #if (MVC_EXTENSION_ENABLE) - if (p->structure == FRAME) - { - unmark_long_term_frame_for_reference_by_frame_idx(p_Dpb, long_term_frame_idx, p->view_id); - } - else - { - unmark_long_term_field_for_reference_by_frame_idx(p_Dpb, p->structure, long_term_frame_idx, 1, p->pic_num, 0, p->view_id); + if (p->structure == FRAME) { + unmark_long_term_frame_for_reference_by_frame_idx( + p_Dpb, long_term_frame_idx, p->view_id); + } else { + unmark_long_term_field_for_reference_by_frame_idx( + p_Dpb, p->structure, long_term_frame_idx, 1, p->pic_num, 0, p->view_id); } #else - if (p->structure == FRAME) - { - unmark_long_term_frame_for_reference_by_frame_idx(p_Dpb, long_term_frame_idx); - } - else - { - unmark_long_term_field_for_reference_by_frame_idx(p_Dpb, p->structure, long_term_frame_idx, 1, p->pic_num, 0); + if (p->structure == FRAME) { + unmark_long_term_frame_for_reference_by_frame_idx(p_Dpb, + long_term_frame_idx); + } else { + unmark_long_term_field_for_reference_by_frame_idx( + p_Dpb, p->structure, long_term_frame_idx, 1, p->pic_num, 0); } #endif @@ -3172,121 +3103,120 @@ static void mm_mark_current_picture_long_term(DecodedPictureBuffer *p_Dpb, Stora p->long_term_frame_idx = long_term_frame_idx; } - /*! ************************************************************************ * \brief * Perform Adaptive memory control decoded reference picture marking process ************************************************************************ */ -static void adaptive_memory_management(DecodedPictureBuffer *p_Dpb, StorablePicture* p) -{ +static void adaptive_memory_management(DecodedPictureBuffer *p_Dpb, + StorablePicture *p) { DecRefPicMarking_t *tmp_drpm; VideoParameters *p_Vid = p_Dpb->p_Vid; p_Vid->last_has_mmco_5 = 0; - assert (!p->idr_flag); - assert (p->adaptive_ref_pic_buffering_flag); + assert(!p->idr_flag); + assert(p->adaptive_ref_pic_buffering_flag); - while (p->dec_ref_pic_marking_buffer) - { + while (p->dec_ref_pic_marking_buffer) { tmp_drpm = p->dec_ref_pic_marking_buffer; - switch (tmp_drpm->memory_management_control_operation) - { - case 0: - if (tmp_drpm->Next != NULL) - { - error ("memory_management_control_operation = 0 not last operation in buffer", 500); - } - break; - case 1: - mm_unmark_short_term_for_reference(p_Dpb, p, tmp_drpm->difference_of_pic_nums_minus1); + switch (tmp_drpm->memory_management_control_operation) { + case 0: + if (tmp_drpm->Next != NULL) { + error("memory_management_control_operation = 0 not last operation in " + "buffer", + 500); + } + break; + case 1: + mm_unmark_short_term_for_reference( + p_Dpb, p, tmp_drpm->difference_of_pic_nums_minus1); #if (MVC_EXTENSION_ENABLE) - update_ref_list(p_Dpb, p->view_id); + update_ref_list(p_Dpb, p->view_id); #else - update_ref_list(p_Dpb); + update_ref_list(p_Dpb); #endif - break; - case 2: - mm_unmark_long_term_for_reference(p_Dpb, p, tmp_drpm->long_term_pic_num); + break; + case 2: + mm_unmark_long_term_for_reference(p_Dpb, p, tmp_drpm->long_term_pic_num); #if (MVC_EXTENSION_ENABLE) - update_ltref_list(p_Dpb, p->view_id); + update_ltref_list(p_Dpb, p->view_id); #else - update_ltref_list(p_Dpb); + update_ltref_list(p_Dpb); #endif - break; - case 3: - mm_assign_long_term_frame_idx(p_Dpb, p, tmp_drpm->difference_of_pic_nums_minus1, tmp_drpm->long_term_frame_idx); + break; + case 3: + mm_assign_long_term_frame_idx(p_Dpb, p, + tmp_drpm->difference_of_pic_nums_minus1, + tmp_drpm->long_term_frame_idx); #if (MVC_EXTENSION_ENABLE) - update_ref_list(p_Dpb, p->view_id); - update_ltref_list(p_Dpb, p->view_id); + update_ref_list(p_Dpb, p->view_id); + update_ltref_list(p_Dpb, p->view_id); #else - update_ref_list(p_Dpb); - update_ltref_list(p_Dpb); + update_ref_list(p_Dpb); + update_ltref_list(p_Dpb); #endif - break; - case 4: + break; + case 4: #if (MVC_EXTENSION_ENABLE) - mm_update_max_long_term_frame_idx (p_Dpb, tmp_drpm->max_long_term_frame_idx_plus1, p->view_id); - update_ltref_list(p_Dpb, p->view_id); + mm_update_max_long_term_frame_idx( + p_Dpb, tmp_drpm->max_long_term_frame_idx_plus1, p->view_id); + update_ltref_list(p_Dpb, p->view_id); #else - mm_update_max_long_term_frame_idx (p_Dpb, tmp_drpm->max_long_term_frame_idx_plus1); - update_ltref_list(p_Dpb); + mm_update_max_long_term_frame_idx( + p_Dpb, tmp_drpm->max_long_term_frame_idx_plus1); + update_ltref_list(p_Dpb); #endif - break; - case 5: + break; + case 5: #if (MVC_EXTENSION_ENABLE) - mm_unmark_all_short_term_for_reference(p_Dpb, p->view_id); - mm_unmark_all_long_term_for_reference(p_Dpb, p->view_id); + mm_unmark_all_short_term_for_reference(p_Dpb, p->view_id); + mm_unmark_all_long_term_for_reference(p_Dpb, p->view_id); #else - mm_unmark_all_short_term_for_reference(p_Dpb); - mm_unmark_all_long_term_for_reference(p_Dpb); + mm_unmark_all_short_term_for_reference(p_Dpb); + mm_unmark_all_long_term_for_reference(p_Dpb); #endif - p_Vid->last_has_mmco_5 = 1; - break; - case 6: - mm_mark_current_picture_long_term(p_Dpb, p, tmp_drpm->long_term_frame_idx); - check_num_ref(p_Dpb); - break; - default: - error ("invalid memory_management_control_operation in buffer", 500); + p_Vid->last_has_mmco_5 = 1; + break; + case 6: + mm_mark_current_picture_long_term(p_Dpb, p, + tmp_drpm->long_term_frame_idx); + check_num_ref(p_Dpb); + break; + default: + error("invalid memory_management_control_operation in buffer", 500); } p->dec_ref_pic_marking_buffer = tmp_drpm->Next; - free (tmp_drpm); + free(tmp_drpm); } - if ( p_Vid->last_has_mmco_5 ) - { + if (p_Vid->last_has_mmco_5) { p->pic_num = p->frame_num = 0; - switch (p->structure) - { - case TOP_FIELD: - { - //p->poc = p->top_poc = p_Vid->toppoc =0; - p->poc = p->top_poc = 0; - break; - } - case BOTTOM_FIELD: - { - //p->poc = p->bottom_poc = p_Vid->bottompoc = 0; - p->poc = p->bottom_poc = 0; - break; - } - case FRAME: - { - p->top_poc -= p->poc; - p->bottom_poc -= p->poc; - - //p_Vid->toppoc = p->top_poc; - //p_Vid->bottompoc = p->bottom_poc; - - p->poc = imin (p->top_poc, p->bottom_poc); - //p_Vid->framepoc = p->poc; - break; - } + switch (p->structure) { + case TOP_FIELD: { + // p->poc = p->top_poc = p_Vid->toppoc =0; + p->poc = p->top_poc = 0; + break; } - //currSlice->ThisPOC = p->poc; + case BOTTOM_FIELD: { + // p->poc = p->bottom_poc = p_Vid->bottompoc = 0; + p->poc = p->bottom_poc = 0; + break; + } + case FRAME: { + p->top_poc -= p->poc; + p->bottom_poc -= p->poc; + + // p_Vid->toppoc = p->top_poc; + // p_Vid->bottompoc = p->bottom_poc; + + p->poc = imin(p->top_poc, p->bottom_poc); + // p_Vid->framepoc = p->poc; + break; + } + } + // currSlice->ThisPOC = p->poc; #if (MVC_EXTENSION_ENABLE) flush_dpb(p_Dpb, p->view_id); #else @@ -3295,7 +3225,6 @@ static void adaptive_memory_management(DecodedPictureBuffer *p_Dpb, StorablePict } } - /*! ************************************************************************ * \brief @@ -3312,63 +3241,61 @@ static void adaptive_memory_management(DecodedPictureBuffer *p_Dpb, StorablePict * ************************************************************************ */ -void store_picture_in_dpb(DecodedPictureBuffer *p_Dpb, StorablePicture* p) -{ +void store_picture_in_dpb(DecodedPictureBuffer *p_Dpb, StorablePicture *p) { VideoParameters *p_Vid = p_Dpb->p_Vid; unsigned i; int poc, pos; // picture error concealment - - // diagnostics - //printf ("Storing (%s) non-ref pic with frame_num #%d\n", (p->type == FRAME)?"FRAME":(p->type == TOP_FIELD)?"TOP_FIELD":"BOTTOM_FIELD", p->pic_num); - // if frame, check for new store, - assert (p!=NULL); - p_Vid->last_has_mmco_5=0; + // diagnostics + // printf ("Storing (%s) non-ref pic with frame_num #%d\n", (p->type == + // FRAME)?"FRAME":(p->type == TOP_FIELD)?"TOP_FIELD":"BOTTOM_FIELD", + // p->pic_num); + // if frame, check for new store, + assert(p != NULL); + + p_Vid->last_has_mmco_5 = 0; p_Vid->last_pic_bottom_field = (p->structure == BOTTOM_FIELD); - if (p->idr_flag) - { + if (p->idr_flag) { idr_memory_management(p_Dpb, p); - // picture error concealment - memset(p_Vid->pocs_in_dpb, 0, sizeof(int)*100); - } - else - { + // picture error concealment + memset(p_Vid->pocs_in_dpb, 0, sizeof(int) * 100); + } else { // adaptive memory management if (p->used_for_reference && (p->adaptive_ref_pic_buffering_flag)) adaptive_memory_management(p_Dpb, p); } - if ((p->structure==TOP_FIELD)||(p->structure==BOTTOM_FIELD)) - { + if ((p->structure == TOP_FIELD) || (p->structure == BOTTOM_FIELD)) { // check for frame store with same pic_number #if (MVC_EXTENSION_ENABLE) - if (!(p_Dpb->last_picture && p_Dpb->last_picture->view_id == p->view_id)) - { - for(i=0; iused_size; i++) - { - if (p_Dpb->fs[i]->view_id == p->view_id && ((p->structure==TOP_FIELD && p_Dpb->fs[i]->is_used == 2) || (p->structure==BOTTOM_FIELD && p_Dpb->fs[i]->is_used == 1))) - break; - } - if (i < p_Dpb->used_size) - { - p_Dpb->last_picture = p_Dpb->fs[i]; + if (!(p_Dpb->last_picture && p_Dpb->last_picture->view_id == p->view_id)) { + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->view_id == p->view_id && + ((p->structure == TOP_FIELD && p_Dpb->fs[i]->is_used == 2) || + (p->structure == BOTTOM_FIELD && p_Dpb->fs[i]->is_used == 1))) + break; } - } + if (i < p_Dpb->used_size) { + p_Dpb->last_picture = p_Dpb->fs[i]; + } + } if (p_Dpb->last_picture && p_Dpb->last_picture->view_id == p->view_id) #else if (p_Dpb->last_picture) #endif { - if ((int)p_Dpb->last_picture->frame_num == p->pic_num) - { - if (((p->structure==TOP_FIELD)&&(p_Dpb->last_picture->is_used==2))||((p->structure==BOTTOM_FIELD)&&(p_Dpb->last_picture->is_used==1))) - { - if ((p->used_for_reference && (p_Dpb->last_picture->is_orig_reference!=0))|| - (!p->used_for_reference && (p_Dpb->last_picture->is_orig_reference==0))) - { + if ((int)p_Dpb->last_picture->frame_num == p->pic_num) { + if (((p->structure == TOP_FIELD) && + (p_Dpb->last_picture->is_used == 2)) || + ((p->structure == BOTTOM_FIELD) && + (p_Dpb->last_picture->is_used == 1))) { + if ((p->used_for_reference && + (p_Dpb->last_picture->is_orig_reference != 0)) || + (!p->used_for_reference && + (p_Dpb->last_picture->is_orig_reference == 0))) { insert_picture_in_dpb(p_Vid, p_Dpb->last_picture, p); #if (MVC_EXTENSION_ENABLE) update_ref_list(p_Dpb, p->view_id); @@ -3389,20 +3316,19 @@ void store_picture_in_dpb(DecodedPictureBuffer *p_Dpb, StorablePicture* p) // this is a frame or a field which has no stored complementary field // sliding window, if necessary - if ((!p->idr_flag)&&(p->used_for_reference && (!p->adaptive_ref_pic_buffering_flag))) - { + if ((!p->idr_flag) && + (p->used_for_reference && (!p->adaptive_ref_pic_buffering_flag))) { sliding_window_memory_management(p_Dpb, p); } // picture error concealment - if(p_Vid->conceal_mode != 0) - for(i=0;isize;i++) - if(p_Dpb->fs[i]->is_reference) + if (p_Vid->conceal_mode != 0) + for (i = 0; i < p_Dpb->size; i++) + if (p_Dpb->fs[i]->is_reference) p_Dpb->fs[i]->concealment_reference = 1; // first try to remove unused frames - if (p_Dpb->used_size==p_Dpb->size) - { + if (p_Dpb->used_size == p_Dpb->size) { // picture error concealment if (p_Vid->conceal_mode != 0) conceal_non_ref_pics(p_Dpb, 2); @@ -3413,23 +3339,20 @@ void store_picture_in_dpb(DecodedPictureBuffer *p_Dpb, StorablePicture* p) remove_unused_frame_from_dpb(p_Dpb); #endif - if(p_Vid->conceal_mode != 0) + if (p_Vid->conceal_mode != 0) sliding_window_poc_management(p_Dpb, p); } - + // then output frames until one can be removed - while (p_Dpb->used_size == p_Dpb->size) - { + while (p_Dpb->used_size == p_Dpb->size) { // non-reference frames may be output directly - if (!p->used_for_reference) - { + if (!p->used_for_reference) { #if (MVC_EXTENSION_ENABLE) get_smallest_poc(p_Dpb, &poc, &pos, p->view_id); #else get_smallest_poc(p_Dpb, &poc, &pos); #endif - if ((-1==pos) || (p->poc < poc)) - { + if ((-1 == pos) || (p->poc < poc)) { direct_output(p_Vid, p, p_Vid->p_out); return; } @@ -3443,43 +3366,38 @@ void store_picture_in_dpb(DecodedPictureBuffer *p_Dpb, StorablePicture* p) } // check for duplicate frame number in short term reference buffer - if ((p->used_for_reference)&&(!p->is_long_term)) - { - for (i=0; iref_frames_in_buffer; i++) - { + if ((p->used_for_reference) && (!p->is_long_term)) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { #if (MVC_EXTENSION_ENABLE) - if (p_Dpb->fs_ref[i]->frame_num == p->frame_num && p_Dpb->fs_ref[i]->view_id == p->view_id) + if (p_Dpb->fs_ref[i]->frame_num == p->frame_num && + p_Dpb->fs_ref[i]->view_id == p->view_id) #else if (p_Dpb->fs_ref[i]->frame_num == p->frame_num) #endif { - error("duplicate frame_num in short-term reference picture buffer", 500); + error("duplicate frame_num in short-term reference picture buffer", + 500); } } - } // store at end of buffer - insert_picture_in_dpb(p_Vid, p_Dpb->fs[p_Dpb->used_size],p); + insert_picture_in_dpb(p_Vid, p_Dpb->fs[p_Dpb->used_size], p); // picture error concealment - if (p->idr_flag) - { + if (p->idr_flag) { p_Vid->earlier_missing_poc = 0; } - if (p->structure != FRAME) - { + if (p->structure != FRAME) { p_Dpb->last_picture = p_Dpb->fs[p_Dpb->used_size]; - } - else - { + } else { p_Dpb->last_picture = NULL; } p_Dpb->used_size++; - if(p_Vid->conceal_mode != 0) - p_Vid->pocs_in_dpb[p_Dpb->used_size-1] = p->poc; + if (p_Vid->conceal_mode != 0) + p_Vid->pocs_in_dpb[p_Dpb->used_size - 1] = p->poc; #if (MVC_EXTENSION_ENABLE) update_ref_list(p_Dpb, p->view_id); @@ -3494,7 +3412,6 @@ void store_picture_in_dpb(DecodedPictureBuffer *p_Dpb, StorablePicture* p) dump_dpb(p_Dpb); } - /*! ************************************************************************ * \brief @@ -3510,31 +3427,30 @@ void store_picture_in_dpb(DecodedPictureBuffer *p_Dpb, StorablePicture* p) * ************************************************************************ */ -static void insert_picture_in_dpb(VideoParameters *p_Vid, FrameStore* fs, StorablePicture* p) -{ +static void insert_picture_in_dpb(VideoParameters *p_Vid, FrameStore *fs, + StorablePicture *p) { InputParameters *p_Inp = p_Vid->p_Inp; -// printf ("insert (%s) pic with frame_num #%d, poc %d\n", (p->structure == FRAME)?"FRAME":(p->structure == TOP_FIELD)?"TOP_FIELD":"BOTTOM_FIELD", p->pic_num, p->poc); - assert (p!=NULL); - assert (fs!=NULL); - switch (p->structure) - { + // printf ("insert (%s) pic with frame_num #%d, poc %d\n", (p->structure == + // FRAME)?"FRAME":(p->structure == TOP_FIELD)?"TOP_FIELD":"BOTTOM_FIELD", + // p->pic_num, p->poc); + assert(p != NULL); + assert(fs != NULL); + switch (p->structure) { case FRAME: fs->frame = p; fs->is_used = 3; - if (p->used_for_reference) - { + if (p->used_for_reference) { fs->is_reference = 3; fs->is_orig_reference = 3; - if (p->is_long_term) - { + if (p->is_long_term) { fs->is_long_term = 3; fs->long_term_frame_idx = p->long_term_frame_idx; } } #if (MVC_EXTENSION_ENABLE) fs->view_id = p->view_id; - fs->inter_view_flag[0] = fs->inter_view_flag[1] = p->inter_view_flag; - fs->anchor_pic_flag[0] = fs->anchor_pic_flag[1] = p->anchor_pic_flag; + fs->inter_view_flag[0] = fs->inter_view_flag[1] = p->inter_view_flag; + fs->anchor_pic_flag[0] = fs->anchor_pic_flag[1] = p->anchor_pic_flag; #endif // generate field views dpb_split_field(p_Vid, fs); @@ -3544,26 +3460,21 @@ static void insert_picture_in_dpb(VideoParameters *p_Vid, FrameStore* fs, Storab fs->is_used |= 1; #if (MVC_EXTENSION_ENABLE) fs->view_id = p->view_id; - fs->inter_view_flag[0] = p->inter_view_flag; - fs->anchor_pic_flag[0] = p->anchor_pic_flag; + fs->inter_view_flag[0] = p->inter_view_flag; + fs->anchor_pic_flag[0] = p->anchor_pic_flag; #endif - if (p->used_for_reference) - { + if (p->used_for_reference) { fs->is_reference |= 1; fs->is_orig_reference |= 1; - if (p->is_long_term) - { + if (p->is_long_term) { fs->is_long_term |= 1; fs->long_term_frame_idx = p->long_term_frame_idx; } } - if (fs->is_used == 3) - { + if (fs->is_used == 3) { // generate frame view dpb_combine_field(p_Vid, fs); - } - else - { + } else { fs->poc = p->poc; gen_field_ref_ids(p_Vid, p); } @@ -3573,26 +3484,21 @@ static void insert_picture_in_dpb(VideoParameters *p_Vid, FrameStore* fs, Storab fs->is_used |= 2; #if (MVC_EXTENSION_ENABLE) fs->view_id = p->view_id; - fs->inter_view_flag[1] = p->inter_view_flag; - fs->anchor_pic_flag[1] = p->anchor_pic_flag; + fs->inter_view_flag[1] = p->inter_view_flag; + fs->anchor_pic_flag[1] = p->anchor_pic_flag; #endif - if (p->used_for_reference) - { + if (p->used_for_reference) { fs->is_reference |= 2; fs->is_orig_reference |= 2; - if (p->is_long_term) - { + if (p->is_long_term) { fs->is_long_term |= 2; fs->long_term_frame_idx = p->long_term_frame_idx; } } - if (fs->is_used == 3) - { + if (fs->is_used == 3) { // generate frame view dpb_combine_field(p_Vid, fs); - } - else - { + } else { fs->poc = p->poc; gen_field_ref_ids(p_Vid, p); } @@ -3603,8 +3509,7 @@ static void insert_picture_in_dpb(VideoParameters *p_Vid, FrameStore* fs, Storab fs->is_output = p->is_output; - if (fs->is_used==3) - { + if (fs->is_used == 3) { calculate_frame_no(p_Vid, p); if (-1 != p_Vid->p_ref && !p_Inp->silent) find_snr(p_Vid, fs->frame, &p_Vid->p_ref); @@ -3617,27 +3522,22 @@ static void insert_picture_in_dpb(VideoParameters *p_Vid, FrameStore* fs, Storab * Check if one of the frames/fields in frame store is used for reference ************************************************************************ */ -static int is_used_for_reference(FrameStore* fs) -{ - if (fs->is_reference) - { +static int is_used_for_reference(FrameStore *fs) { + if (fs->is_reference) { return 1; } if (fs->is_used == 3) // frame { - if (fs->frame->used_for_reference) - { + if (fs->frame->used_for_reference) { return 1; } } if (fs->is_used & 1) // top field { - if (fs->top_field) - { - if (fs->top_field->used_for_reference) - { + if (fs->top_field) { + if (fs->top_field->used_for_reference) { return 1; } } @@ -3645,10 +3545,8 @@ static int is_used_for_reference(FrameStore* fs) if (fs->is_used & 2) // bottom field { - if (fs->bottom_field) - { - if (fs->bottom_field->used_for_reference) - { + if (fs->bottom_field) { + if (fs->bottom_field->used_for_reference) { return 1; } } @@ -3656,30 +3554,27 @@ static int is_used_for_reference(FrameStore* fs) return 0; } - /*! ************************************************************************ * \brief - * Check if one of the frames/fields in frame store is used for short-term reference + * Check if one of the frames/fields in frame store is used for short-term + *reference ************************************************************************ */ -static int is_short_term_reference(FrameStore* fs) -{ +static int is_short_term_reference(FrameStore *fs) { - if (fs->is_used==3) // frame + if (fs->is_used == 3) // frame { - if ((fs->frame->used_for_reference)&&(!fs->frame->is_long_term)) - { + if ((fs->frame->used_for_reference) && (!fs->frame->is_long_term)) { return 1; } } if (fs->is_used & 1) // top field { - if (fs->top_field) - { - if ((fs->top_field->used_for_reference)&&(!fs->top_field->is_long_term)) - { + if (fs->top_field) { + if ((fs->top_field->used_for_reference) && + (!fs->top_field->is_long_term)) { return 1; } } @@ -3687,10 +3582,9 @@ static int is_short_term_reference(FrameStore* fs) if (fs->is_used & 2) // bottom field { - if (fs->bottom_field) - { - if ((fs->bottom_field->used_for_reference)&&(!fs->bottom_field->is_long_term)) - { + if (fs->bottom_field) { + if ((fs->bottom_field->used_for_reference) && + (!fs->bottom_field->is_long_term)) { return 1; } } @@ -3698,30 +3592,27 @@ static int is_short_term_reference(FrameStore* fs) return 0; } - /*! ************************************************************************ * \brief - * Check if one of the frames/fields in frame store is used for short-term reference + * Check if one of the frames/fields in frame store is used for short-term + *reference ************************************************************************ */ -static int is_long_term_reference(FrameStore* fs) -{ +static int is_long_term_reference(FrameStore *fs) { - if (fs->is_used==3) // frame + if (fs->is_used == 3) // frame { - if ((fs->frame->used_for_reference)&&(fs->frame->is_long_term)) - { + if ((fs->frame->used_for_reference) && (fs->frame->is_long_term)) { return 1; } } if (fs->is_used & 1) // top field { - if (fs->top_field) - { - if ((fs->top_field->used_for_reference)&&(fs->top_field->is_long_term)) - { + if (fs->top_field) { + if ((fs->top_field->used_for_reference) && + (fs->top_field->is_long_term)) { return 1; } } @@ -3729,10 +3620,9 @@ static int is_long_term_reference(FrameStore* fs) if (fs->is_used & 2) // bottom field { - if (fs->bottom_field) - { - if ((fs->bottom_field->used_for_reference)&&(fs->bottom_field->is_long_term)) - { + if (fs->bottom_field) { + if ((fs->bottom_field->used_for_reference) && + (fs->bottom_field->is_long_term)) { return 1; } } @@ -3740,42 +3630,39 @@ static int is_long_term_reference(FrameStore* fs) return 0; } - /*! ************************************************************************ * \brief * remove one frame from DPB ************************************************************************ */ -static void remove_frame_from_dpb(DecodedPictureBuffer *p_Dpb, int pos) -{ - FrameStore* fs = p_Dpb->fs[pos]; - FrameStore* tmp; +static void remove_frame_from_dpb(DecodedPictureBuffer *p_Dpb, int pos) { + FrameStore *fs = p_Dpb->fs[pos]; + FrameStore *tmp; unsigned i; -// printf ("remove frame with frame_num #%d\n", fs->frame_num); - switch (fs->is_used) - { + // printf ("remove frame with frame_num #%d\n", fs->frame_num); + switch (fs->is_used) { case 3: free_storable_picture(fs->frame); free_storable_picture(fs->top_field); free_storable_picture(fs->bottom_field); - fs->frame=NULL; - fs->top_field=NULL; - fs->bottom_field=NULL; + fs->frame = NULL; + fs->top_field = NULL; + fs->bottom_field = NULL; break; case 2: free_storable_picture(fs->bottom_field); - fs->bottom_field=NULL; + fs->bottom_field = NULL; break; case 1: free_storable_picture(fs->top_field); - fs->top_field=NULL; + fs->top_field = NULL; break; case 0: break; default: - error("invalid frame store type",500); + error("invalid frame store type", 500); } fs->is_used = 0; fs->is_long_term = 0; @@ -3785,11 +3672,10 @@ static void remove_frame_from_dpb(DecodedPictureBuffer *p_Dpb, int pos) // move empty framestore to end of buffer tmp = p_Dpb->fs[pos]; - for (i=pos; iused_size-1;i++) - { - p_Dpb->fs[i] = p_Dpb->fs[i+1]; + for (i = pos; i < p_Dpb->used_size - 1; i++) { + p_Dpb->fs[i] = p_Dpb->fs[i + 1]; } - p_Dpb->fs[p_Dpb->used_size-1] = tmp; + p_Dpb->fs[p_Dpb->used_size - 1] = tmp; p_Dpb->used_size--; } @@ -3800,30 +3686,30 @@ static void remove_frame_from_dpb(DecodedPictureBuffer *p_Dpb, int pos) ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -static void get_smallest_poc(DecodedPictureBuffer *p_Dpb, int *poc,int * pos, int curr_view_id) +static void get_smallest_poc(DecodedPictureBuffer *p_Dpb, int *poc, int *pos, + int curr_view_id) #else -static void get_smallest_poc(DecodedPictureBuffer *p_Dpb, int *poc,int * pos) +static void get_smallest_poc(DecodedPictureBuffer *p_Dpb, int *poc, int *pos) #endif { unsigned i; - if (p_Dpb->used_size<1) - { - error("Cannot determine smallest POC, DPB empty.",150); + if (p_Dpb->used_size < 1) { + error("Cannot determine smallest POC, DPB empty.", 150); } - *pos=-1; + *pos = -1; *poc = INT_MAX; - for (i = 0; i < p_Dpb->used_size; i++) - { + for (i = 0; i < p_Dpb->used_size; i++) { #if (MVC_EXTENSION_ENABLE) - if ((*poc > p_Dpb->fs[i]->poc)&&(!p_Dpb->fs[i]->is_output) && (p_Dpb->fs[i]->view_id == curr_view_id || curr_view_id == -1)) + if ((*poc > p_Dpb->fs[i]->poc) && (!p_Dpb->fs[i]->is_output) && + (p_Dpb->fs[i]->view_id == curr_view_id || curr_view_id == -1)) #else - if ((*poc > p_Dpb->fs[i]->poc)&&(!p_Dpb->fs[i]->is_output)) + if ((*poc > p_Dpb->fs[i]->poc) && (!p_Dpb->fs[i]->is_output)) #endif { *poc = p_Dpb->fs[i]->poc; - *pos=i; + *pos = i; } } } @@ -3835,15 +3721,14 @@ static void get_smallest_poc(DecodedPictureBuffer *p_Dpb, int *poc,int * pos) ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -static int remove_unused_frame_from_dpb(DecodedPictureBuffer *p_Dpb, int curr_view_id) -{ +static int remove_unused_frame_from_dpb(DecodedPictureBuffer *p_Dpb, + int curr_view_id) { unsigned i; // check for frames that were already output and no longer used for reference - for (i = 0; i < p_Dpb->used_size; i++) - { - if (p_Dpb->fs[i]->is_output && (!is_used_for_reference(p_Dpb->fs[i])) && (p_Dpb->fs[i]->view_id == curr_view_id || curr_view_id == -1)) - { + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->is_output && (!is_used_for_reference(p_Dpb->fs[i])) && + (p_Dpb->fs[i]->view_id == curr_view_id || curr_view_id == -1)) { remove_frame_from_dpb(p_Dpb, i); return 1; } @@ -3851,15 +3736,12 @@ static int remove_unused_frame_from_dpb(DecodedPictureBuffer *p_Dpb, int curr_vi return 0; } #else -static int remove_unused_frame_from_dpb(DecodedPictureBuffer *p_Dpb) -{ +static int remove_unused_frame_from_dpb(DecodedPictureBuffer *p_Dpb) { unsigned i; // check for frames that were already output and no longer used for reference - for (i = 0; i < p_Dpb->used_size; i++) - { - if (p_Dpb->fs[i]->is_output && (!is_used_for_reference(p_Dpb->fs[i]))) - { + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->is_output && (!is_used_for_reference(p_Dpb->fs[i]))) { remove_frame_from_dpb(p_Dpb, i); return 1; } @@ -3868,7 +3750,6 @@ static int remove_unused_frame_from_dpb(DecodedPictureBuffer *p_Dpb) } #endif - /*! ************************************************************************ * \brief @@ -3876,89 +3757,82 @@ static int remove_unused_frame_from_dpb(DecodedPictureBuffer *p_Dpb) ************************************************************************ */ #if (MVC_EXTENSION_ENABLE) -static int output_one_frame_from_dpb(DecodedPictureBuffer *p_Dpb, int curr_view_id) +static int output_one_frame_from_dpb(DecodedPictureBuffer *p_Dpb, + int curr_view_id) #else static void output_one_frame_from_dpb(DecodedPictureBuffer *p_Dpb) #endif { VideoParameters *p_Vid = p_Dpb->p_Vid; int poc, pos; - //diagnostics - if (p_Dpb->used_size<1) - { - error("Cannot output frame, DPB empty.",150); + // diagnostics + if (p_Dpb->used_size < 1) { + error("Cannot output frame, DPB empty.", 150); } // find smallest POC #if (MVC_EXTENSION_ENABLE) get_smallest_poc(p_Dpb, &poc, &pos, curr_view_id); - if(pos==-1) - { - if (curr_view_id == -1) - error("no frames for output available", 150); - else - return 0; + if (pos == -1) { + if (curr_view_id == -1) + error("no frames for output available", 150); + else + return 0; } #else get_smallest_poc(p_Dpb, &poc, &pos); - if(pos==-1) - { + if (pos == -1) { error("no frames for output available", 150); } -#endif +#endif // call the output function -// printf ("output frame with frame_num #%d, poc %d (dpb. p_Dpb->size=%d, p_Dpb->used_size=%d)\n", p_Dpb->fs[pos]->frame_num, p_Dpb->fs[pos]->frame->poc, p_Dpb->size, p_Dpb->used_size); + // printf ("output frame with frame_num #%d, poc %d (dpb. p_Dpb->size=%d, + // p_Dpb->used_size=%d)\n", p_Dpb->fs[pos]->frame_num, + // p_Dpb->fs[pos]->frame->poc, p_Dpb->size, p_Dpb->used_size); // picture error concealment - if(p_Vid->conceal_mode != 0) - { - if(p_Dpb->last_output_poc == 0) - { + if (p_Vid->conceal_mode != 0) { + if (p_Dpb->last_output_poc == 0) { write_lost_ref_after_idr(p_Dpb, pos); } write_lost_non_ref_pic(p_Dpb, poc, p_Vid->p_out); } -// JVT-P072 ends + // JVT-P072 ends write_stored_frame(p_Vid, p_Dpb->fs[pos], p_Vid->p_out); // picture error concealment #if (MVC_EXTENSION_ENABLE) - if(p_Vid->conceal_mode == 0) - if (p_Dpb->last_output_poc >= poc && p_Dpb->fs[pos]->view_id == p_Dpb->last_output_view_id) - { - error ("output POC must be in ascending order", 150); + if (p_Vid->conceal_mode == 0) + if (p_Dpb->last_output_poc >= poc && + p_Dpb->fs[pos]->view_id == p_Dpb->last_output_view_id) { + error("output POC must be in ascending order", 150); } p_Dpb->last_output_poc = poc; p_Dpb->last_output_view_id = p_Dpb->fs[pos]->view_id; // free frame store and move empty store to end of buffer - if (!is_used_for_reference(p_Dpb->fs[pos])) - { + if (!is_used_for_reference(p_Dpb->fs[pos])) { remove_frame_from_dpb(p_Dpb, pos); } return 1; #else - if(p_Vid->conceal_mode == 0) - if (p_Dpb->last_output_poc >= poc) - { - error ("output POC must be in ascending order", 150); + if (p_Vid->conceal_mode == 0) + if (p_Dpb->last_output_poc >= poc) { + error("output POC must be in ascending order", 150); } p_Dpb->last_output_poc = poc; // free frame store and move empty store to end of buffer - if (!is_used_for_reference(p_Dpb->fs[pos])) - { + if (!is_used_for_reference(p_Dpb->fs[pos])) { remove_frame_from_dpb(p_Dpb, pos); } #endif } - - /*! ************************************************************************ * \brief @@ -3975,38 +3849,38 @@ void flush_dpb(DecodedPictureBuffer *p_Dpb) unsigned i; // diagnostics - // printf("Flush remaining frames from the dpb. p_Dpb->size=%d, p_Dpb->used_size=%d\n",p_Dpb->size,p_Dpb->used_size); + // printf("Flush remaining frames from the dpb. p_Dpb->size=%d, + // p_Dpb->used_size=%d\n",p_Dpb->size,p_Dpb->used_size); -// if(p_Vid->conceal_mode == 0) + // if(p_Vid->conceal_mode == 0) if (p_Vid->conceal_mode != 0) conceal_non_ref_pics(p_Dpb, 0); #if (MVC_EXTENSION_ENABLE) // mark all frames unused - for (i=0; iused_size; i++) - { - if (p_Dpb->fs[i]->view_id == curr_view_id || curr_view_id == -1) - { - unmark_for_reference (p_Dpb->fs[i]); + for (i = 0; i < p_Dpb->used_size; i++) { + if (p_Dpb->fs[i]->view_id == curr_view_id || curr_view_id == -1) { + unmark_for_reference(p_Dpb->fs[i]); } } - while (remove_unused_frame_from_dpb(p_Dpb, curr_view_id)) ; + while (remove_unused_frame_from_dpb(p_Dpb, curr_view_id)) + ; // output frames in POC order - while (p_Dpb->used_size && output_one_frame_from_dpb(p_Dpb, curr_view_id)) ; + while (p_Dpb->used_size && output_one_frame_from_dpb(p_Dpb, curr_view_id)) + ; #else // mark all frames unused - for (i=0; iused_size; i++) - { - unmark_for_reference (p_Dpb->fs[i]); + for (i = 0; i < p_Dpb->used_size; i++) { + unmark_for_reference(p_Dpb->fs[i]); } - while (remove_unused_frame_from_dpb(p_Dpb)) ; + while (remove_unused_frame_from_dpb(p_Dpb)) + ; // output frames in POC order - while (p_Dpb->used_size) - { + while (p_Dpb->used_size) { output_one_frame_from_dpb(p_Dpb); } #endif @@ -4014,33 +3888,26 @@ void flush_dpb(DecodedPictureBuffer *p_Dpb) p_Dpb->last_output_poc = INT_MIN; } - -static void gen_field_ref_ids(VideoParameters *p_Vid, StorablePicture *p) -{ - int i,j; - //! Generate Frame parameters from field information. - for (i = 0; i < (p->size_x >> 2); i++) - { - for (j = 0; j < (p->size_y >> 2); j++) - { - //p->mv_info[j][i].field_frame = 1; +static void gen_field_ref_ids(VideoParameters *p_Vid, StorablePicture *p) { + int i, j; + //! Generate Frame parameters from field information. + for (i = 0; i < (p->size_x >> 2); i++) { + for (j = 0; j < (p->size_y >> 2); j++) { + // p->mv_info[j][i].field_frame = 1; } } - //copy the list; - if(p->listX[LIST_0]) - { - p->listXsize[LIST_0] = p_Vid->ppSliceList[0]->listXsize[LIST_0]; - for(i=0; ilistXsize[LIST_0]; i++) + // copy the list; + if (p->listX[LIST_0]) { + p->listXsize[LIST_0] = p_Vid->ppSliceList[0]->listXsize[LIST_0]; + for (i = 0; i < p->listXsize[LIST_0]; i++) p->listX[LIST_0][i] = p_Vid->ppSliceList[0]->listX[LIST_0][i]; } - if(p->listX[LIST_1]) - { - p->listXsize[LIST_1] = p_Vid->ppSliceList[0]->listXsize[LIST_1]; - for(i=0; ilistXsize[LIST_1]; i++) + if (p->listX[LIST_1]) { + p->listXsize[LIST_1] = p_Vid->ppSliceList[0]->listXsize[LIST_1]; + for (i = 0; i < p->listXsize[LIST_1]; i++) p->listX[LIST_1][i] = p_Vid->ppSliceList[0]->listX[LIST_1][i]; } - } /*! @@ -4049,42 +3916,46 @@ static void gen_field_ref_ids(VideoParameters *p_Vid, StorablePicture *p) * Extract top field from a frame ************************************************************************ */ -void dpb_split_field(VideoParameters *p_Vid, FrameStore *fs) -{ +void dpb_split_field(VideoParameters *p_Vid, FrameStore *fs) { int i, j, ii, jj, jj4; - int idiv,jdiv; + int idiv, jdiv; int currentmb; int twosz16 = 2 * (fs->frame->size_x >> 4); - StorablePicture *fs_top, *fs_btm; + StorablePicture *fs_top, *fs_btm; StorablePicture *frame = fs->frame; fs->poc = frame->poc; - if (!frame->frame_mbs_only_flag) - { - fs_top = fs->top_field = alloc_storable_picture(p_Vid, TOP_FIELD, frame->size_x, frame->size_y, frame->size_x_cr, frame->size_y_cr); - fs_btm = fs->bottom_field = alloc_storable_picture(p_Vid, BOTTOM_FIELD, frame->size_x, frame->size_y, frame->size_x_cr, frame->size_y_cr); + if (!frame->frame_mbs_only_flag) { + fs_top = fs->top_field = + alloc_storable_picture(p_Vid, TOP_FIELD, frame->size_x, frame->size_y, + frame->size_x_cr, frame->size_y_cr); + fs_btm = fs->bottom_field = alloc_storable_picture( + p_Vid, BOTTOM_FIELD, frame->size_x, frame->size_y, frame->size_x_cr, + frame->size_y_cr); - for (i = 0; i < (frame->size_y >> 1); i++) - { - memcpy(fs_top->imgY[i], frame->imgY[i*2], frame->size_x*sizeof(imgpel)); + for (i = 0; i < (frame->size_y >> 1); i++) { + memcpy(fs_top->imgY[i], frame->imgY[i * 2], + frame->size_x * sizeof(imgpel)); } - for (i = 0; i< (frame->size_y_cr>>1); i++) - { - memcpy(fs_top->imgUV[0][i], frame->imgUV[0][i*2], frame->size_x_cr*sizeof(imgpel)); - memcpy(fs_top->imgUV[1][i], frame->imgUV[1][i*2], frame->size_x_cr*sizeof(imgpel)); + for (i = 0; i < (frame->size_y_cr >> 1); i++) { + memcpy(fs_top->imgUV[0][i], frame->imgUV[0][i * 2], + frame->size_x_cr * sizeof(imgpel)); + memcpy(fs_top->imgUV[1][i], frame->imgUV[1][i * 2], + frame->size_x_cr * sizeof(imgpel)); } - for (i = 0; i < (frame->size_y>>1); i++) - { - memcpy(fs_btm->imgY[i], frame->imgY[i*2 + 1], frame->size_x*sizeof(imgpel)); + for (i = 0; i < (frame->size_y >> 1); i++) { + memcpy(fs_btm->imgY[i], frame->imgY[i * 2 + 1], + frame->size_x * sizeof(imgpel)); } - for (i = 0; i < (frame->size_y_cr>>1); i++) - { - memcpy(fs_btm->imgUV[0][i], frame->imgUV[0][i*2 + 1], frame->size_x_cr*sizeof(imgpel)); - memcpy(fs_btm->imgUV[1][i], frame->imgUV[1][i*2 + 1], frame->size_x_cr*sizeof(imgpel)); + for (i = 0; i < (frame->size_y_cr >> 1); i++) { + memcpy(fs_btm->imgUV[0][i], frame->imgUV[0][i * 2 + 1], + frame->size_x_cr * sizeof(imgpel)); + memcpy(fs_btm->imgUV[1][i], frame->imgUV[1][i * 2 + 1], + frame->size_x_cr * sizeof(imgpel)); } fs_top->poc = frame->top_poc; @@ -4095,156 +3966,175 @@ void dpb_split_field(VideoParameters *p_Vid, FrameStore *fs) fs_btm->view_id = frame->view_id; #endif - fs_top->frame_poc = frame->frame_poc; + fs_top->frame_poc = frame->frame_poc; - fs_top->bottom_poc = fs_btm->bottom_poc = frame->bottom_poc; - fs_top->top_poc = fs_btm->top_poc = frame->top_poc; - fs_btm->frame_poc = frame->frame_poc; + fs_top->bottom_poc = fs_btm->bottom_poc = frame->bottom_poc; + fs_top->top_poc = fs_btm->top_poc = frame->top_poc; + fs_btm->frame_poc = frame->frame_poc; - fs_top->used_for_reference = fs_btm->used_for_reference - = frame->used_for_reference; - fs_top->is_long_term = fs_btm->is_long_term - = frame->is_long_term; - fs->long_term_frame_idx = fs_top->long_term_frame_idx - = fs_btm->long_term_frame_idx - = frame->long_term_frame_idx; + fs_top->used_for_reference = fs_btm->used_for_reference = + frame->used_for_reference; + fs_top->is_long_term = fs_btm->is_long_term = frame->is_long_term; + fs->long_term_frame_idx = fs_top->long_term_frame_idx = + fs_btm->long_term_frame_idx = frame->long_term_frame_idx; fs_top->coded_frame = fs_btm->coded_frame = 1; - fs_top->mb_aff_frame_flag = fs_btm->mb_aff_frame_flag - = frame->mb_aff_frame_flag; + fs_top->mb_aff_frame_flag = fs_btm->mb_aff_frame_flag = + frame->mb_aff_frame_flag; - frame->top_field = fs_top; + frame->top_field = fs_top; frame->bottom_field = fs_btm; - frame->frame = frame; + frame->frame = frame; fs_top->bottom_field = fs_btm; - fs_top->frame = frame; + fs_top->frame = frame; fs_top->top_field = fs_top; fs_btm->top_field = fs_top; - fs_btm->frame = frame; + fs_btm->frame = frame; fs_btm->bottom_field = fs_btm; #if (MVC_EXTENSION_ENABLE) fs_top->view_id = fs_btm->view_id = fs->view_id; - fs_top->inter_view_flag = fs->inter_view_flag[0]; - fs_btm->inter_view_flag = fs->inter_view_flag[1]; + fs_top->inter_view_flag = fs->inter_view_flag[0]; + fs_btm->inter_view_flag = fs->inter_view_flag[1]; #endif - fs_top->chroma_format_idc = fs_btm->chroma_format_idc = frame->chroma_format_idc; + fs_top->chroma_format_idc = fs_btm->chroma_format_idc = + frame->chroma_format_idc; fs_top->iCodingType = fs_btm->iCodingType = frame->iCodingType; - if(frame->used_for_reference) - { + if (frame->used_for_reference) { pad_dec_picture(p_Vid, fs_top); pad_dec_picture(p_Vid, fs_btm); } - } - else - { - fs_top=NULL; - fs_btm=NULL; - frame->top_field=NULL; - frame->bottom_field=NULL; + } else { + fs_top = NULL; + fs_btm = NULL; + frame->top_field = NULL; + frame->bottom_field = NULL; frame->frame = frame; } - if (!frame->frame_mbs_only_flag) - { - if (frame->mb_aff_frame_flag) - { + if (!frame->frame_mbs_only_flag) { + if (frame->mb_aff_frame_flag) { PicMotionParamsOld *frm_motion = &frame->motion; - for (j=0 ; j< (frame->size_y >> 3); j++) - { - jj = (j >> 2)*8 + (j & 0x03); + for (j = 0; j < (frame->size_y >> 3); j++) { + jj = (j >> 2) * 8 + (j & 0x03); jj4 = jj + 4; jdiv = (j >> 1); - for (i=0 ; i < (frame->size_x>>2); i++) - { + for (i = 0; i < (frame->size_x >> 2); i++) { idiv = (i >> 2); - currentmb = twosz16*(jdiv >> 1)+ (idiv)*2 + (jdiv & 0x01); + currentmb = twosz16 * (jdiv >> 1) + (idiv) * 2 + (jdiv & 0x01); // Assign field mvs attached to MB-Frame buffer to the proper buffer - if (frm_motion->mb_field[currentmb]) - { - //fs_btm->mv_info[j][i].field_frame = fs_top->mv_info[j][i].field_frame = 1; - //frame->mv_info[2*j][i].field_frame = frame->mv_info[2*j+1][i].field_frame = 1; + if (frm_motion->mb_field[currentmb]) { + // fs_btm->mv_info[j][i].field_frame = + // fs_top->mv_info[j][i].field_frame = 1; + // frame->mv_info[2*j][i].field_frame = + // frame->mv_info[2*j+1][i].field_frame = 1; - fs_btm->mv_info[j][i].mv[LIST_0] = frame->mv_info[jj4][i].mv[LIST_0]; - fs_btm->mv_info[j][i].mv[LIST_1] = frame->mv_info[jj4][i].mv[LIST_1]; - fs_btm->mv_info[j][i].ref_idx[LIST_0] = frame->mv_info[jj4][i].ref_idx[LIST_0]; - if(fs_btm->mv_info[j][i].ref_idx[LIST_0] >=0) - fs_btm->mv_info[j][i].ref_pic[LIST_0] = p_Vid->ppSliceList[0]->listX[4][(short) fs_btm->mv_info[j][i].ref_idx[LIST_0]]; + fs_btm->mv_info[j][i].mv[LIST_0] = + frame->mv_info[jj4][i].mv[LIST_0]; + fs_btm->mv_info[j][i].mv[LIST_1] = + frame->mv_info[jj4][i].mv[LIST_1]; + fs_btm->mv_info[j][i].ref_idx[LIST_0] = + frame->mv_info[jj4][i].ref_idx[LIST_0]; + if (fs_btm->mv_info[j][i].ref_idx[LIST_0] >= 0) + fs_btm->mv_info[j][i].ref_pic[LIST_0] = + p_Vid->ppSliceList[0] + ->listX[4][(short)fs_btm->mv_info[j][i].ref_idx[LIST_0]]; else fs_btm->mv_info[j][i].ref_pic[LIST_0] = NULL; - fs_btm->mv_info[j][i].ref_idx[LIST_1] = frame->mv_info[jj4][i].ref_idx[LIST_1]; - if(fs_btm->mv_info[j][i].ref_idx[LIST_1] >=0) - fs_btm->mv_info[j][i].ref_pic[LIST_1] = p_Vid->ppSliceList[0]->listX[5][(short) fs_btm->mv_info[j][i].ref_idx[LIST_1]]; + fs_btm->mv_info[j][i].ref_idx[LIST_1] = + frame->mv_info[jj4][i].ref_idx[LIST_1]; + if (fs_btm->mv_info[j][i].ref_idx[LIST_1] >= 0) + fs_btm->mv_info[j][i].ref_pic[LIST_1] = + p_Vid->ppSliceList[0] + ->listX[5][(short)fs_btm->mv_info[j][i].ref_idx[LIST_1]]; else fs_btm->mv_info[j][i].ref_pic[LIST_1] = NULL; - + fs_top->mv_info[j][i].mv[LIST_0] = frame->mv_info[jj][i].mv[LIST_0]; fs_top->mv_info[j][i].mv[LIST_1] = frame->mv_info[jj][i].mv[LIST_1]; - fs_top->mv_info[j][i].ref_idx[LIST_0] = frame->mv_info[jj][i].ref_idx[LIST_0]; - if(fs_top->mv_info[j][i].ref_idx[LIST_0] >=0) - fs_top->mv_info[j][i].ref_pic[LIST_0] = p_Vid->ppSliceList[0]->listX[2][(short) fs_top->mv_info[j][i].ref_idx[LIST_0]]; + fs_top->mv_info[j][i].ref_idx[LIST_0] = + frame->mv_info[jj][i].ref_idx[LIST_0]; + if (fs_top->mv_info[j][i].ref_idx[LIST_0] >= 0) + fs_top->mv_info[j][i].ref_pic[LIST_0] = + p_Vid->ppSliceList[0] + ->listX[2][(short)fs_top->mv_info[j][i].ref_idx[LIST_0]]; else fs_top->mv_info[j][i].ref_pic[LIST_0] = NULL; - fs_top->mv_info[j][i].ref_idx[LIST_1] = frame->mv_info[jj][i].ref_idx[LIST_1]; - if(fs_top->mv_info[j][i].ref_idx[LIST_1] >=0) - fs_top->mv_info[j][i].ref_pic[LIST_1] = p_Vid->ppSliceList[0]->listX[3][(short) fs_top->mv_info[j][i].ref_idx[LIST_1]]; + fs_top->mv_info[j][i].ref_idx[LIST_1] = + frame->mv_info[jj][i].ref_idx[LIST_1]; + if (fs_top->mv_info[j][i].ref_idx[LIST_1] >= 0) + fs_top->mv_info[j][i].ref_pic[LIST_1] = + p_Vid->ppSliceList[0] + ->listX[3][(short)fs_top->mv_info[j][i].ref_idx[LIST_1]]; else fs_top->mv_info[j][i].ref_pic[LIST_1] = NULL; } } } } - - //! Generate field MVs from Frame MVs - for (j=0 ; j < (frame->size_y >> 3) ; j++) - { - jj = 2* RSD(j); + + //! Generate field MVs from Frame MVs + for (j = 0; j < (frame->size_y >> 3); j++) { + jj = 2 * RSD(j); jdiv = (j >> 1); - for (i=0 ; i < (frame->size_x >> 2) ; i++) - { + for (i = 0; i < (frame->size_x >> 2); i++) { ii = RSD(i); idiv = (i >> 2); - currentmb = twosz16 * (jdiv >> 1)+ (idiv)*2 + (jdiv & 0x01); + currentmb = twosz16 * (jdiv >> 1) + (idiv) * 2 + (jdiv & 0x01); - if (!frame->mb_aff_frame_flag || !frame->motion.mb_field[currentmb]) - { - //frame->mv_info[2*j+1][i].field_frame = frame->mv_info[2*j][i].field_frame = 0; + if (!frame->mb_aff_frame_flag || !frame->motion.mb_field[currentmb]) { + // frame->mv_info[2*j+1][i].field_frame = + // frame->mv_info[2*j][i].field_frame = 0; - //fs_top->mv_info[j][i].field_frame = fs_btm->mv_info[j][i].field_frame = 0; + // fs_top->mv_info[j][i].field_frame = + // fs_btm->mv_info[j][i].field_frame = 0; - fs_top->mv_info[j][i].mv[LIST_0] = fs_btm->mv_info[j][i].mv[LIST_0] = frame->mv_info[jj][ii].mv[LIST_0]; - fs_top->mv_info[j][i].mv[LIST_1] = fs_btm->mv_info[j][i].mv[LIST_1] = frame->mv_info[jj][ii].mv[LIST_1]; + fs_top->mv_info[j][i].mv[LIST_0] = fs_btm->mv_info[j][i].mv[LIST_0] = + frame->mv_info[jj][ii].mv[LIST_0]; + fs_top->mv_info[j][i].mv[LIST_1] = fs_btm->mv_info[j][i].mv[LIST_1] = + frame->mv_info[jj][ii].mv[LIST_1]; - // Scaling of references is done here since it will not affect spatial direct (2*0 =0) + // Scaling of references is done here since it will not affect spatial + // direct (2*0 =0) if (frame->mv_info[jj][ii].ref_idx[LIST_0] == -1) - fs_top->mv_info[j][i].ref_idx[LIST_0] = fs_btm->mv_info[j][i].ref_idx[LIST_0] = - 1; - else - { - fs_top->mv_info[j][i].ref_idx[LIST_0] = fs_btm->mv_info[j][i].ref_idx[LIST_0] = frame->mv_info[jj][ii].ref_idx[LIST_0]; - fs_top->mv_info[j][i].ref_pic[LIST_0] = fs_btm->mv_info[j][i].ref_pic[LIST_0] = p_Vid->ppSliceList[0]->listX[LIST_0][(short) frame->mv_info[jj][ii].ref_idx[LIST_0]]; + fs_top->mv_info[j][i].ref_idx[LIST_0] = + fs_btm->mv_info[j][i].ref_idx[LIST_0] = -1; + else { + fs_top->mv_info[j][i].ref_idx[LIST_0] = + fs_btm->mv_info[j][i].ref_idx[LIST_0] = + frame->mv_info[jj][ii].ref_idx[LIST_0]; + fs_top->mv_info[j][i].ref_pic[LIST_0] = + fs_btm->mv_info[j][i].ref_pic[LIST_0] = + p_Vid->ppSliceList[0] + ->listX[LIST_0] + [(short)frame->mv_info[jj][ii].ref_idx[LIST_0]]; } if (frame->mv_info[jj][ii].ref_idx[LIST_1] == -1) - fs_top->mv_info[j][i].ref_idx[LIST_1] = fs_btm->mv_info[j][i].ref_idx[LIST_1] = - 1; - else - { - fs_top->mv_info[j][i].ref_idx[LIST_1] = fs_btm->mv_info[j][i].ref_idx[LIST_1] = frame->mv_info[jj][ii].ref_idx[LIST_1]; - fs_top->mv_info[j][i].ref_pic[LIST_1] = fs_btm->mv_info[j][i].ref_pic[LIST_1] = p_Vid->ppSliceList[0]->listX[LIST_1][(short) frame->mv_info[jj][ii].ref_idx[LIST_1]]; + fs_top->mv_info[j][i].ref_idx[LIST_1] = + fs_btm->mv_info[j][i].ref_idx[LIST_1] = -1; + else { + fs_top->mv_info[j][i].ref_idx[LIST_1] = + fs_btm->mv_info[j][i].ref_idx[LIST_1] = + frame->mv_info[jj][ii].ref_idx[LIST_1]; + fs_top->mv_info[j][i].ref_pic[LIST_1] = + fs_btm->mv_info[j][i].ref_pic[LIST_1] = + p_Vid->ppSliceList[0] + ->listX[LIST_1] + [(short)frame->mv_info[jj][ii].ref_idx[LIST_1]]; } - } - else - { - //frame->mv_info[2*j+1][i].field_frame = frame->mv_info[2*j][i].field_frame = frame->motion.mb_field[currentmb]; + } else { + // frame->mv_info[2*j+1][i].field_frame = + // frame->mv_info[2*j][i].field_frame = + // frame->motion.mb_field[currentmb]; } } } - } - else - { + } else { /* for (j = 0; j < frame->size_y >> 2; j++) for (i = 0; i < frame->size_x >> 2; i++) @@ -4253,7 +4143,6 @@ void dpb_split_field(VideoParameters *p_Vid, FrameStore *fs) } } - /*! ************************************************************************ * \brief @@ -4261,44 +4150,48 @@ void dpb_split_field(VideoParameters *p_Vid, FrameStore *fs) * YUV components and display information only ************************************************************************ */ -void dpb_combine_field_yuv(VideoParameters *p_Vid, FrameStore *fs) -{ +void dpb_combine_field_yuv(VideoParameters *p_Vid, FrameStore *fs) { int i, j; - if (!fs->frame) - { - fs->frame = alloc_storable_picture(p_Vid, FRAME, fs->top_field->size_x, fs->top_field->size_y*2, fs->top_field->size_x_cr, fs->top_field->size_y_cr*2); + if (!fs->frame) { + fs->frame = alloc_storable_picture( + p_Vid, FRAME, fs->top_field->size_x, fs->top_field->size_y * 2, + fs->top_field->size_x_cr, fs->top_field->size_y_cr * 2); } - for (i=0; itop_field->size_y; i++) - { - memcpy(fs->frame->imgY[i*2], fs->top_field->imgY[i] , fs->top_field->size_x * sizeof(imgpel)); // top field - memcpy(fs->frame->imgY[i*2 + 1], fs->bottom_field->imgY[i], fs->bottom_field->size_x * sizeof(imgpel)); // bottom field + for (i = 0; i < fs->top_field->size_y; i++) { + memcpy(fs->frame->imgY[i * 2], fs->top_field->imgY[i], + fs->top_field->size_x * sizeof(imgpel)); // top field + memcpy(fs->frame->imgY[i * 2 + 1], fs->bottom_field->imgY[i], + fs->bottom_field->size_x * sizeof(imgpel)); // bottom field } - for (j = 0; j < 2; j++) - { - for (i=0; itop_field->size_y_cr; i++) - { - memcpy(fs->frame->imgUV[j][i*2], fs->top_field->imgUV[j][i], fs->top_field->size_x_cr*sizeof(imgpel)); - memcpy(fs->frame->imgUV[j][i*2 + 1], fs->bottom_field->imgUV[j][i], fs->bottom_field->size_x_cr*sizeof(imgpel)); + for (j = 0; j < 2; j++) { + for (i = 0; i < fs->top_field->size_y_cr; i++) { + memcpy(fs->frame->imgUV[j][i * 2], fs->top_field->imgUV[j][i], + fs->top_field->size_x_cr * sizeof(imgpel)); + memcpy(fs->frame->imgUV[j][i * 2 + 1], fs->bottom_field->imgUV[j][i], + fs->bottom_field->size_x_cr * sizeof(imgpel)); } } - fs->poc=fs->frame->poc =fs->frame->frame_poc = imin (fs->top_field->poc, fs->bottom_field->poc); + fs->poc = fs->frame->poc = fs->frame->frame_poc = + imin(fs->top_field->poc, fs->bottom_field->poc); - fs->bottom_field->frame_poc=fs->top_field->frame_poc=fs->frame->poc; + fs->bottom_field->frame_poc = fs->top_field->frame_poc = fs->frame->poc; - fs->bottom_field->top_poc=fs->frame->top_poc=fs->top_field->poc; - fs->top_field->bottom_poc=fs->frame->bottom_poc=fs->bottom_field->poc; + fs->bottom_field->top_poc = fs->frame->top_poc = fs->top_field->poc; + fs->top_field->bottom_poc = fs->frame->bottom_poc = fs->bottom_field->poc; - fs->frame->used_for_reference = (fs->top_field->used_for_reference && fs->bottom_field->used_for_reference ); - fs->frame->is_long_term = (fs->top_field->is_long_term && fs->bottom_field->is_long_term ); + fs->frame->used_for_reference = (fs->top_field->used_for_reference && + fs->bottom_field->used_for_reference); + fs->frame->is_long_term = + (fs->top_field->is_long_term && fs->bottom_field->is_long_term); if (fs->frame->is_long_term) fs->frame->long_term_frame_idx = fs->long_term_frame_idx; - fs->frame->top_field = fs->top_field; + fs->frame->top_field = fs->top_field; fs->frame->bottom_field = fs->bottom_field; fs->frame->frame = fs->frame; @@ -4306,12 +4199,15 @@ void dpb_combine_field_yuv(VideoParameters *p_Vid, FrameStore *fs) fs->frame->chroma_format_idc = fs->top_field->chroma_format_idc; fs->frame->frame_cropping_flag = fs->top_field->frame_cropping_flag; - if (fs->frame->frame_cropping_flag) - { - fs->frame->frame_cropping_rect_top_offset = fs->top_field->frame_cropping_rect_top_offset; - fs->frame->frame_cropping_rect_bottom_offset = fs->top_field->frame_cropping_rect_bottom_offset; - fs->frame->frame_cropping_rect_left_offset = fs->top_field->frame_cropping_rect_left_offset; - fs->frame->frame_cropping_rect_right_offset = fs->top_field->frame_cropping_rect_right_offset; + if (fs->frame->frame_cropping_flag) { + fs->frame->frame_cropping_rect_top_offset = + fs->top_field->frame_cropping_rect_top_offset; + fs->frame->frame_cropping_rect_bottom_offset = + fs->top_field->frame_cropping_rect_bottom_offset; + fs->frame->frame_cropping_rect_left_offset = + fs->top_field->frame_cropping_rect_left_offset; + fs->frame->frame_cropping_rect_right_offset = + fs->top_field->frame_cropping_rect_right_offset; } fs->top_field->frame = fs->bottom_field->frame = fs->frame; @@ -4319,189 +4215,219 @@ void dpb_combine_field_yuv(VideoParameters *p_Vid, FrameStore *fs) fs->top_field->top_field = fs->top_field; fs->bottom_field->top_field = fs->top_field; fs->bottom_field->bottom_field = fs->bottom_field; - if(fs->top_field->used_for_reference || fs->bottom_field->used_for_reference) - { + if (fs->top_field->used_for_reference || + fs->bottom_field->used_for_reference) { pad_dec_picture(p_Vid, fs->frame); } - } - /*! ************************************************************************ * \brief * Generate a frame from top and bottom fields ************************************************************************ */ -void dpb_combine_field(VideoParameters *p_Vid, FrameStore *fs) -{ - int i,j, jj, jj4, k; +void dpb_combine_field(VideoParameters *p_Vid, FrameStore *fs) { + int i, j, jj, jj4, k; dpb_combine_field_yuv(p_Vid, fs); #if (MVC_EXTENSION_ENABLE) fs->frame->view_id = fs->view_id; #endif - fs->frame->iCodingType = fs->top_field->iCodingType; //FIELD_CODING; - //! Use inference flag to remap mvs/references + fs->frame->iCodingType = + fs->top_field->iCodingType; // FIELD_CODING; + //! Use inference flag to remap mvs/references //! Generate Frame parameters from field information. #if 1 - for (j=0 ; j < (fs->top_field->size_y >> 2) ; j++) - { - jj = (j<<1); + for (j = 0; j < (fs->top_field->size_y >> 2); j++) { + jj = (j << 1); jj4 = jj + 1; - for (i=0 ; i< (fs->top_field->size_x >> 2) ; i++) - { - //fs->frame->mv_info[jj][i].field_frame= fs->frame->mv_info[jj4][i].field_frame = 1; + for (i = 0; i < (fs->top_field->size_x >> 2); i++) { + // fs->frame->mv_info[jj][i].field_frame= + // fs->frame->mv_info[jj4][i].field_frame = 1; - fs->frame->mv_info[jj][i].mv[LIST_0] = fs->top_field->mv_info[j][i].mv[LIST_0]; - fs->frame->mv_info[jj][i].mv[LIST_1] = fs->top_field->mv_info[j][i].mv[LIST_1]; + fs->frame->mv_info[jj][i].mv[LIST_0] = + fs->top_field->mv_info[j][i].mv[LIST_0]; + fs->frame->mv_info[jj][i].mv[LIST_1] = + fs->top_field->mv_info[j][i].mv[LIST_1]; - fs->frame->mv_info[jj][i].ref_idx[LIST_0] = fs->top_field->mv_info[j][i].ref_idx[LIST_0]; - fs->frame->mv_info[jj][i].ref_idx[LIST_1] = fs->top_field->mv_info[j][i].ref_idx[LIST_1]; + fs->frame->mv_info[jj][i].ref_idx[LIST_0] = + fs->top_field->mv_info[j][i].ref_idx[LIST_0]; + fs->frame->mv_info[jj][i].ref_idx[LIST_1] = + fs->top_field->mv_info[j][i].ref_idx[LIST_1]; /* bug: top field list doesnot exist.*/ - if(fs->top_field->listXsize[LIST_0] >0) - { + if (fs->top_field->listXsize[LIST_0] > 0) { k = fs->top_field->mv_info[j][i].ref_idx[LIST_0]; - assert( k < fs->top_field->listXsize[LIST_0]); - fs->frame->mv_info[jj][i].ref_pic[LIST_0] = k>=0? fs->top_field->listX[LIST_0][k]: NULL; + assert(k < fs->top_field->listXsize[LIST_0]); + fs->frame->mv_info[jj][i].ref_pic[LIST_0] = + k >= 0 ? fs->top_field->listX[LIST_0][k] : NULL; k = fs->top_field->mv_info[j][i].ref_idx[LIST_1]; - assert( k < fs->top_field->listXsize[LIST_1]); - fs->frame->mv_info[jj][i].ref_pic[LIST_1] = k>=0? fs->top_field->listX[LIST_1][k]: NULL; - } - else - { + assert(k < fs->top_field->listXsize[LIST_1]); + fs->frame->mv_info[jj][i].ref_pic[LIST_1] = + k >= 0 ? fs->top_field->listX[LIST_1][k] : NULL; + } else { k = fs->top_field->mv_info[j][i].ref_idx[LIST_0]; - assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_0], p_Vid->ppSliceList[0]->listXsize[LIST_0])); - fs->frame->mv_info[jj][i].ref_pic[LIST_0] = k>=0?p_Vid->ppSliceList[0]->listX[LIST_0][k]: NULL; + assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_0], + p_Vid->ppSliceList[0]->listXsize[LIST_0])); + fs->frame->mv_info[jj][i].ref_pic[LIST_0] = + k >= 0 ? p_Vid->ppSliceList[0]->listX[LIST_0][k] : NULL; k = fs->top_field->mv_info[j][i].ref_idx[LIST_1]; - assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_1], p_Vid->ppSliceList[0]->listXsize[LIST_1])); - fs->frame->mv_info[jj][i].ref_pic[LIST_1] = k>=0?p_Vid->ppSliceList[0]->listX[LIST_1][k]: NULL; + assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_1], + p_Vid->ppSliceList[0]->listXsize[LIST_1])); + fs->frame->mv_info[jj][i].ref_pic[LIST_1] = + k >= 0 ? p_Vid->ppSliceList[0]->listX[LIST_1][k] : NULL; } //! association with id already known for fields. - fs->frame->mv_info[jj4][i].mv[LIST_0] = fs->bottom_field->mv_info[j][i].mv[LIST_0]; - fs->frame->mv_info[jj4][i].mv[LIST_1] = fs->bottom_field->mv_info[j][i].mv[LIST_1]; + fs->frame->mv_info[jj4][i].mv[LIST_0] = + fs->bottom_field->mv_info[j][i].mv[LIST_0]; + fs->frame->mv_info[jj4][i].mv[LIST_1] = + fs->bottom_field->mv_info[j][i].mv[LIST_1]; - fs->frame->mv_info[jj4][i].ref_idx[LIST_0] = fs->bottom_field->mv_info[j][i].ref_idx[LIST_0]; - fs->frame->mv_info[jj4][i].ref_idx[LIST_1] = fs->bottom_field->mv_info[j][i].ref_idx[LIST_1]; + fs->frame->mv_info[jj4][i].ref_idx[LIST_0] = + fs->bottom_field->mv_info[j][i].ref_idx[LIST_0]; + fs->frame->mv_info[jj4][i].ref_idx[LIST_1] = + fs->bottom_field->mv_info[j][i].ref_idx[LIST_1]; - if(fs->bottom_field->listXsize[LIST_0]>0) - { + if (fs->bottom_field->listXsize[LIST_0] > 0) { k = fs->bottom_field->mv_info[j][i].ref_idx[LIST_0]; assert(k < fs->bottom_field->listXsize[LIST_0]); - fs->frame->mv_info[jj4][i].ref_pic[LIST_0] = k>=0? fs->bottom_field->listX[LIST_0][k]: NULL; + fs->frame->mv_info[jj4][i].ref_pic[LIST_0] = + k >= 0 ? fs->bottom_field->listX[LIST_0][k] : NULL; k = fs->bottom_field->mv_info[j][i].ref_idx[LIST_1]; assert(k < fs->bottom_field->listXsize[LIST_1]); - fs->frame->mv_info[jj4][i].ref_pic[LIST_1] = k>=0? fs->bottom_field->listX[LIST_1][k]: NULL; - } - else - { + fs->frame->mv_info[jj4][i].ref_pic[LIST_1] = + k >= 0 ? fs->bottom_field->listX[LIST_1][k] : NULL; + } else { k = fs->bottom_field->mv_info[j][i].ref_idx[LIST_0]; - assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_0], p_Vid->ppSliceList[0]->listXsize[LIST_0])); - fs->frame->mv_info[jj4][i].ref_pic[LIST_0] = k>=0? p_Vid->ppSliceList[0]->listX[LIST_0][k]: NULL; + assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_0], + p_Vid->ppSliceList[0]->listXsize[LIST_0])); + fs->frame->mv_info[jj4][i].ref_pic[LIST_0] = + k >= 0 ? p_Vid->ppSliceList[0]->listX[LIST_0][k] : NULL; k = fs->bottom_field->mv_info[j][i].ref_idx[LIST_1]; - assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_1], p_Vid->ppSliceList[0]->listXsize[LIST_1])); - fs->frame->mv_info[jj4][i].ref_pic[LIST_1] = k>=0? p_Vid->ppSliceList[0]->listX[LIST_1][k]: NULL; + assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_1], + p_Vid->ppSliceList[0]->listXsize[LIST_1])); + fs->frame->mv_info[jj4][i].ref_pic[LIST_1] = + k >= 0 ? p_Vid->ppSliceList[0]->listX[LIST_1][k] : NULL; } - //fs->top_field->mv_info[j][i].field_frame = 1; - //fs->bottom_field->mv_info[j][i].field_frame = 1; + // fs->top_field->mv_info[j][i].field_frame = 1; + // fs->bottom_field->mv_info[j][i].field_frame = 1; } } #else - for (j=0 ; j < (fs->top_field->size_y >> 2) ; j++) - { - jj = 8*(j >> 2) + (j & 0x03); + for (j = 0; j < (fs->top_field->size_y >> 2); j++) { + jj = 8 * (j >> 2) + (j & 0x03); jj4 = jj + 4; - for (i=0 ; i< (fs->top_field->size_x >> 2) ; i++) - { - //fs->frame->mv_info[jj][i].field_frame= fs->frame->mv_info[jj4][i].field_frame = 1; + for (i = 0; i < (fs->top_field->size_x >> 2); i++) { + // fs->frame->mv_info[jj][i].field_frame= + // fs->frame->mv_info[jj4][i].field_frame = 1; - fs->frame->mv_info[jj][i].mv[LIST_0] = fs->top_field->mv_info[j][i].mv[LIST_0]; - fs->frame->mv_info[jj][i].mv[LIST_1] = fs->top_field->mv_info[j][i].mv[LIST_1]; + fs->frame->mv_info[jj][i].mv[LIST_0] = + fs->top_field->mv_info[j][i].mv[LIST_0]; + fs->frame->mv_info[jj][i].mv[LIST_1] = + fs->top_field->mv_info[j][i].mv[LIST_1]; - fs->frame->mv_info[jj][i].ref_idx[LIST_0] = fs->top_field->mv_info[j][i].ref_idx[LIST_0]; - fs->frame->mv_info[jj][i].ref_idx[LIST_1] = fs->top_field->mv_info[j][i].ref_idx[LIST_1]; + fs->frame->mv_info[jj][i].ref_idx[LIST_0] = + fs->top_field->mv_info[j][i].ref_idx[LIST_0]; + fs->frame->mv_info[jj][i].ref_idx[LIST_1] = + fs->top_field->mv_info[j][i].ref_idx[LIST_1]; /* bug: top field list doesnot exist.*/ - if(fs->top_field->listXsize[LIST_0] >0) - { + if (fs->top_field->listXsize[LIST_0] > 0) { k = fs->top_field->mv_info[j][i].ref_idx[LIST_0]; - assert( k < fs->top_field->listXsize[LIST_0]); - fs->frame->mv_info[jj][i].ref_pic[LIST_0] = k>=0? fs->top_field->listX[LIST_0][k]: NULL; + assert(k < fs->top_field->listXsize[LIST_0]); + fs->frame->mv_info[jj][i].ref_pic[LIST_0] = + k >= 0 ? fs->top_field->listX[LIST_0][k] : NULL; k = fs->top_field->mv_info[j][i].ref_idx[LIST_1]; - assert( k < fs->top_field->listXsize[LIST_1]); - fs->frame->mv_info[jj][i].ref_pic[LIST_1] = k>=0? fs->top_field->listX[LIST_1][k]: NULL; - } - else - { + assert(k < fs->top_field->listXsize[LIST_1]); + fs->frame->mv_info[jj][i].ref_pic[LIST_1] = + k >= 0 ? fs->top_field->listX[LIST_1][k] : NULL; + } else { k = fs->top_field->mv_info[j][i].ref_idx[LIST_0]; - assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_0], p_Vid->ppSliceList[0]->listXsize[LIST_0])); - fs->frame->mv_info[jj][i].ref_pic[LIST_0] = k>=0?p_Vid->ppSliceList[0]->listX[LIST_0][k]: NULL; + assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_0], + p_Vid->ppSliceList[0]->listXsize[LIST_0])); + fs->frame->mv_info[jj][i].ref_pic[LIST_0] = + k >= 0 ? p_Vid->ppSliceList[0]->listX[LIST_0][k] : NULL; k = fs->top_field->mv_info[j][i].ref_idx[LIST_1]; - assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_1], p_Vid->ppSliceList[0]->listXsize[LIST_1])); - fs->frame->mv_info[jj][i].ref_pic[LIST_1] = k>=0?p_Vid->ppSliceList[0]->listX[LIST_1][k]: NULL; + assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_1], + p_Vid->ppSliceList[0]->listXsize[LIST_1])); + fs->frame->mv_info[jj][i].ref_pic[LIST_1] = + k >= 0 ? p_Vid->ppSliceList[0]->listX[LIST_1][k] : NULL; } //! association with id already known for fields. - fs->frame->mv_info[jj4][i].mv[LIST_0] = fs->bottom_field->mv_info[j][i].mv[LIST_0]; - fs->frame->mv_info[jj4][i].mv[LIST_1] = fs->bottom_field->mv_info[j][i].mv[LIST_1]; + fs->frame->mv_info[jj4][i].mv[LIST_0] = + fs->bottom_field->mv_info[j][i].mv[LIST_0]; + fs->frame->mv_info[jj4][i].mv[LIST_1] = + fs->bottom_field->mv_info[j][i].mv[LIST_1]; - fs->frame->mv_info[jj4][i].ref_idx[LIST_0] = fs->bottom_field->mv_info[j][i].ref_idx[LIST_0]; - fs->frame->mv_info[jj4][i].ref_idx[LIST_1] = fs->bottom_field->mv_info[j][i].ref_idx[LIST_1]; + fs->frame->mv_info[jj4][i].ref_idx[LIST_0] = + fs->bottom_field->mv_info[j][i].ref_idx[LIST_0]; + fs->frame->mv_info[jj4][i].ref_idx[LIST_1] = + fs->bottom_field->mv_info[j][i].ref_idx[LIST_1]; - if(fs->bottom_field->listXsize[LIST_0]>0) - { + if (fs->bottom_field->listXsize[LIST_0] > 0) { k = fs->bottom_field->mv_info[j][i].ref_idx[LIST_0]; assert(k < fs->bottom_field->listXsize[LIST_0]); - fs->frame->mv_info[jj4][i].ref_pic[LIST_0] = k>=0? fs->bottom_field->listX[LIST_0][k]: NULL; + fs->frame->mv_info[jj4][i].ref_pic[LIST_0] = + k >= 0 ? fs->bottom_field->listX[LIST_0][k] : NULL; k = fs->bottom_field->mv_info[j][i].ref_idx[LIST_1]; assert(k < fs->bottom_field->listXsize[LIST_1]); - fs->frame->mv_info[jj4][i].ref_pic[LIST_1] = k>=0? fs->bottom_field->listX[LIST_1][k]: NULL; - } - else - { + fs->frame->mv_info[jj4][i].ref_pic[LIST_1] = + k >= 0 ? fs->bottom_field->listX[LIST_1][k] : NULL; + } else { k = fs->bottom_field->mv_info[j][i].ref_idx[LIST_0]; - assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_0], p_Vid->ppSliceList[0]->listXsize[LIST_0])); - fs->frame->mv_info[jj4][i].ref_pic[LIST_0] = k>=0? p_Vid->ppSliceList[0]->listX[LIST_0][k]: NULL; + assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_0], + p_Vid->ppSliceList[0]->listXsize[LIST_0])); + fs->frame->mv_info[jj4][i].ref_pic[LIST_0] = + k >= 0 ? p_Vid->ppSliceList[0]->listX[LIST_0][k] : NULL; k = fs->bottom_field->mv_info[j][i].ref_idx[LIST_1]; - assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_1], p_Vid->ppSliceList[0]->listXsize[LIST_1])); - fs->frame->mv_info[jj4][i].ref_pic[LIST_1] = k>=0? p_Vid->ppSliceList[0]->listX[LIST_1][k]: NULL; + assert(k < imin(p_Vid->ppSliceList[0]->num_ref_idx_active[LIST_1], + p_Vid->ppSliceList[0]->listXsize[LIST_1])); + fs->frame->mv_info[jj4][i].ref_pic[LIST_1] = + k >= 0 ? p_Vid->ppSliceList[0]->listX[LIST_1][k] : NULL; } - //fs->top_field->mv_info[j][i].field_frame = 1; - //fs->bottom_field->mv_info[j][i].field_frame = 1; + // fs->top_field->mv_info[j][i].field_frame = 1; + // fs->bottom_field->mv_info[j][i].field_frame = 1; } } #endif } - /*! ************************************************************************ * \brief * Allocate memory for buffering of reference picture reordering commands ************************************************************************ */ -void alloc_ref_pic_list_reordering_buffer(Slice *currSlice) -{ +void alloc_ref_pic_list_reordering_buffer(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; int size = currSlice->num_ref_idx_active[LIST_0] + 1; - if (p_Vid->type!=I_SLICE && p_Vid->type!=SI_SLICE) - { - if ((currSlice->reordering_of_pic_nums_idc[LIST_0] = calloc(size ,sizeof(int)))==NULL) no_mem_exit("alloc_ref_pic_list_reordering_buffer: reordering_of_pic_nums_idc_l0"); - if ((currSlice->abs_diff_pic_num_minus1[LIST_0] = calloc(size,sizeof(int)))==NULL) no_mem_exit("alloc_ref_pic_list_reordering_buffer: abs_diff_pic_num_minus1_l0"); - if ((currSlice->long_term_pic_idx[LIST_0] = calloc(size,sizeof(int)))==NULL) no_mem_exit("alloc_ref_pic_list_reordering_buffer: long_term_pic_idx_l0"); + if (p_Vid->type != I_SLICE && p_Vid->type != SI_SLICE) { + if ((currSlice->reordering_of_pic_nums_idc[LIST_0] = + calloc(size, sizeof(int))) == NULL) + no_mem_exit("alloc_ref_pic_list_reordering_buffer: " + "reordering_of_pic_nums_idc_l0"); + if ((currSlice->abs_diff_pic_num_minus1[LIST_0] = + calloc(size, sizeof(int))) == NULL) + no_mem_exit( + "alloc_ref_pic_list_reordering_buffer: abs_diff_pic_num_minus1_l0"); + if ((currSlice->long_term_pic_idx[LIST_0] = calloc(size, sizeof(int))) == + NULL) + no_mem_exit("alloc_ref_pic_list_reordering_buffer: long_term_pic_idx_l0"); #if (MVC_EXTENSION_ENABLE) - if ((currSlice->abs_diff_view_idx_minus1[LIST_0] = calloc(size,sizeof(int)))==NULL) no_mem_exit("alloc_ref_pic_list_reordering_buffer: abs_diff_view_idx_minus1_l0"); + if ((currSlice->abs_diff_view_idx_minus1[LIST_0] = + calloc(size, sizeof(int))) == NULL) + no_mem_exit( + "alloc_ref_pic_list_reordering_buffer: abs_diff_view_idx_minus1_l0"); #endif - } - else - { + } else { currSlice->reordering_of_pic_nums_idc[LIST_0] = NULL; currSlice->abs_diff_pic_num_minus1[LIST_0] = NULL; currSlice->long_term_pic_idx[LIST_0] = NULL; @@ -4510,22 +4436,27 @@ void alloc_ref_pic_list_reordering_buffer(Slice *currSlice) #endif } - size = currSlice->num_ref_idx_active[LIST_1]+1; + size = currSlice->num_ref_idx_active[LIST_1] + 1; - if (p_Vid->type==B_SLICE) - { - if ((currSlice->reordering_of_pic_nums_idc[LIST_1] = calloc(size,sizeof(int)))==NULL) - no_mem_exit("alloc_ref_pic_list_reordering_buffer: reordering_of_pic_nums_idc_l1"); - if ((currSlice->abs_diff_pic_num_minus1[LIST_1] = calloc(size,sizeof(int)))==NULL) - no_mem_exit("alloc_ref_pic_list_reordering_buffer: abs_diff_pic_num_minus1_l1"); - if ((currSlice->long_term_pic_idx[LIST_1] = calloc(size,sizeof(int)))==NULL) + if (p_Vid->type == B_SLICE) { + if ((currSlice->reordering_of_pic_nums_idc[LIST_1] = + calloc(size, sizeof(int))) == NULL) + no_mem_exit("alloc_ref_pic_list_reordering_buffer: " + "reordering_of_pic_nums_idc_l1"); + if ((currSlice->abs_diff_pic_num_minus1[LIST_1] = + calloc(size, sizeof(int))) == NULL) + no_mem_exit( + "alloc_ref_pic_list_reordering_buffer: abs_diff_pic_num_minus1_l1"); + if ((currSlice->long_term_pic_idx[LIST_1] = calloc(size, sizeof(int))) == + NULL) no_mem_exit("alloc_ref_pic_list_reordering_buffer: long_term_pic_idx_l1"); #if (MVC_EXTENSION_ENABLE) - if ((currSlice->abs_diff_view_idx_minus1[LIST_1] = calloc(size,sizeof(int)))==NULL) no_mem_exit("alloc_ref_pic_list_reordering_buffer: abs_diff_view_idx_minus1_l1"); + if ((currSlice->abs_diff_view_idx_minus1[LIST_1] = + calloc(size, sizeof(int))) == NULL) + no_mem_exit( + "alloc_ref_pic_list_reordering_buffer: abs_diff_view_idx_minus1_l1"); #endif - } - else - { + } else { currSlice->reordering_of_pic_nums_idc[LIST_1] = NULL; currSlice->abs_diff_pic_num_minus1[LIST_1] = NULL; currSlice->long_term_pic_idx[LIST_1] = NULL; @@ -4535,15 +4466,13 @@ void alloc_ref_pic_list_reordering_buffer(Slice *currSlice) } } - /*! ************************************************************************ * \brief * Free memory for buffering of reference picture reordering commands ************************************************************************ */ -void free_ref_pic_list_reordering_buffer(Slice *currSlice) -{ +void free_ref_pic_list_reordering_buffer(Slice *currSlice) { if (currSlice->reordering_of_pic_nums_idc[LIST_0]) free(currSlice->reordering_of_pic_nums_idc[LIST_0]); if (currSlice->abs_diff_pic_num_minus1[LIST_0]) @@ -4588,10 +4517,9 @@ void free_ref_pic_list_reordering_buffer(Slice *currSlice) * ************************************************************************ */ -void fill_frame_num_gap(VideoParameters *p_Vid, Slice *currSlice) -{ +void fill_frame_num_gap(VideoParameters *p_Vid, Slice *currSlice) { seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; - + int CurrFrameNum; int UnusedShortTermFrameNum; StorablePicture *picture = NULL; @@ -4602,11 +4530,11 @@ void fill_frame_num_gap(VideoParameters *p_Vid, Slice *currSlice) printf("A gap in frame number is found, try to fill it.\n"); UnusedShortTermFrameNum = (p_Vid->pre_frame_num + 1) % p_Vid->MaxFrameNum; - CurrFrameNum = currSlice->frame_num; //p_Vid->frame_num; + CurrFrameNum = currSlice->frame_num; // p_Vid->frame_num; - while (CurrFrameNum != UnusedShortTermFrameNum) - { - picture = alloc_storable_picture (p_Vid, FRAME, p_Vid->width, p_Vid->height, p_Vid->width_cr, p_Vid->height_cr); + while (CurrFrameNum != UnusedShortTermFrameNum) { + picture = alloc_storable_picture(p_Vid, FRAME, p_Vid->width, p_Vid->height, + p_Vid->width_cr, p_Vid->height_cr); picture->coded_frame = 1; picture->pic_num = UnusedShortTermFrameNum; picture->frame_num = UnusedShortTermFrameNum; @@ -4619,28 +4547,26 @@ void fill_frame_num_gap(VideoParameters *p_Vid, Slice *currSlice) #endif currSlice->frame_num = UnusedShortTermFrameNum; - if (active_sps->pic_order_cnt_type!=0) - { + if (active_sps->pic_order_cnt_type != 0) { decode_poc(p_Vid, p_Vid->ppSliceList[0]); } - picture->top_poc = currSlice->toppoc; + picture->top_poc = currSlice->toppoc; picture->bottom_poc = currSlice->bottompoc; - picture->frame_poc = currSlice->framepoc; - picture->poc = currSlice->framepoc; + picture->frame_poc = currSlice->framepoc; + picture->poc = currSlice->framepoc; store_picture_in_dpb(currSlice->p_Dpb, picture); - picture=NULL; + picture = NULL; p_Vid->pre_frame_num = UnusedShortTermFrameNum; - UnusedShortTermFrameNum = (UnusedShortTermFrameNum + 1) % p_Vid->MaxFrameNum; + UnusedShortTermFrameNum = + (UnusedShortTermFrameNum + 1) % p_Vid->MaxFrameNum; } currSlice->delta_pic_order_cnt[0] = tmp1; currSlice->delta_pic_order_cnt[1] = tmp2; currSlice->frame_num = CurrFrameNum; - } - /*! ************************************************************************ * \brief @@ -4648,42 +4574,37 @@ void fill_frame_num_gap(VideoParameters *p_Vid, Slice *currSlice) * ************************************************************************ */ -void compute_colocated (Slice *currSlice, StorablePicture **listX[6]) -{ - int i,j; +void compute_colocated(Slice *currSlice, StorablePicture **listX[6]) { + int i, j; VideoParameters *p_Vid = currSlice->p_Vid; - if (currSlice->direct_spatial_mv_pred_flag == 0) - { - for (j = 0; j < 2 + (currSlice->mb_aff_frame_flag * 4); j += 2) - { - for (i=0; ilistXsize[j];i++) - { + if (currSlice->direct_spatial_mv_pred_flag == 0) { + for (j = 0; j < 2 + (currSlice->mb_aff_frame_flag * 4); j += 2) { + for (i = 0; i < currSlice->listXsize[j]; i++) { int prescale, iTRb, iTRp; - if (j==0) - { - iTRb = iClip3( -128, 127, p_Vid->dec_picture->poc - listX[LIST_0 + j][i]->poc ); - } - else if (j == 2) - { - iTRb = iClip3( -128, 127, p_Vid->dec_picture->top_poc - listX[LIST_0 + j][i]->poc ); - } - else - { - iTRb = iClip3( -128, 127, p_Vid->dec_picture->bottom_poc - listX[LIST_0 + j][i]->poc ); + if (j == 0) { + iTRb = iClip3(-128, 127, + p_Vid->dec_picture->poc - listX[LIST_0 + j][i]->poc); + } else if (j == 2) { + iTRb = + iClip3(-128, 127, + p_Vid->dec_picture->top_poc - listX[LIST_0 + j][i]->poc); + } else { + iTRb = iClip3(-128, 127, + p_Vid->dec_picture->bottom_poc - + listX[LIST_0 + j][i]->poc); } - iTRp = iClip3( -128, 127, listX[LIST_1 + j][0]->poc - listX[LIST_0 + j][i]->poc); + iTRp = iClip3(-128, 127, + listX[LIST_1 + j][0]->poc - listX[LIST_0 + j][i]->poc); - if (iTRp!=0) - { - prescale = ( 16384 + iabs( iTRp / 2 ) ) / iTRp; - currSlice->mvscale[j][i] = iClip3( -1024, 1023, ( iTRb * prescale + 32 ) >> 6 ) ; - } - else - { + if (iTRp != 0) { + prescale = (16384 + iabs(iTRp / 2)) / iTRp; + currSlice->mvscale[j][i] = + iClip3(-1024, 1023, (iTRb * prescale + 32) >> 6); + } else { currSlice->mvscale[j][i] = 9999; } } @@ -4691,83 +4612,75 @@ void compute_colocated (Slice *currSlice, StorablePicture **listX[6]) } } - #if (MVC_EXTENSION_ENABLE) -int GetMaxDecFrameBuffering(VideoParameters *p_Vid) -{ +int GetMaxDecFrameBuffering(VideoParameters *p_Vid) { int i, j, iMax, iMax_1 = 0, iMax_2 = 0; subset_seq_parameter_set_rbsp_t *curr_subset_sps; seq_parameter_set_rbsp_t *curr_sps; curr_subset_sps = p_Vid->SubsetSeqParSet; curr_sps = p_Vid->SeqParSet; - for(i=0; iValid && curr_subset_sps->sps.seq_parameter_set_id < MAXSPS) - { + for (i = 0; i < MAXSPS; i++) { + if (curr_subset_sps->Valid && + curr_subset_sps->sps.seq_parameter_set_id < MAXSPS) { j = curr_subset_sps->sps.max_dec_frame_buffering; - if (curr_subset_sps->sps.vui_parameters_present_flag && curr_subset_sps->sps.vui_seq_parameters.bitstream_restriction_flag) - { - if ((int)curr_subset_sps->sps.vui_seq_parameters.max_dec_frame_buffering > j) - { - error ("max_dec_frame_buffering larger than MaxDpbSize", 500); + if (curr_subset_sps->sps.vui_parameters_present_flag && + curr_subset_sps->sps.vui_seq_parameters.bitstream_restriction_flag) { + if ((int)curr_subset_sps->sps.vui_seq_parameters + .max_dec_frame_buffering > j) { + error("max_dec_frame_buffering larger than MaxDpbSize", 500); } - j = imax (1, curr_subset_sps->sps.vui_seq_parameters.max_dec_frame_buffering); + j = imax( + 1, curr_subset_sps->sps.vui_seq_parameters.max_dec_frame_buffering); } - if(j > iMax_2) + if (j > iMax_2) iMax_2 = j; } - - if(curr_sps->Valid) - { + + if (curr_sps->Valid) { j = curr_sps->max_dec_frame_buffering; - if (curr_sps->vui_parameters_present_flag && curr_sps->vui_seq_parameters.bitstream_restriction_flag) - { - if ((int)curr_sps->vui_seq_parameters.max_dec_frame_buffering > j) - { - error ("max_dec_frame_buffering larger than MaxDpbSize", 500); + if (curr_sps->vui_parameters_present_flag && + curr_sps->vui_seq_parameters.bitstream_restriction_flag) { + if ((int)curr_sps->vui_seq_parameters.max_dec_frame_buffering > j) { + error("max_dec_frame_buffering larger than MaxDpbSize", 500); } - j = imax (1, curr_sps->vui_seq_parameters.max_dec_frame_buffering); + j = imax(1, curr_sps->vui_seq_parameters.max_dec_frame_buffering); } - if(j > iMax_1) + if (j > iMax_1) iMax_1 = j; } curr_subset_sps++; curr_sps++; - } - + } + if (iMax_1 > 0 && iMax_2 > 0) iMax = iMax_1 + iMax_2; else - iMax = (iMax_1 >0? iMax_1*2 : iMax_2*2); + iMax = (iMax_1 > 0 ? iMax_1 * 2 : iMax_2 * 2); return iMax; } -static int is_view_id_in_ref_view_list(int view_id, int *ref_view_id, int num_ref_views) -{ - int i; - for(i=0; ip_Vid; int iVOIdx = GetVOIdx(p_Vid, curr_view_id); @@ -4776,61 +4689,56 @@ void append_interview_list(DecodedPictureBuffer *p_Dpb, int fld_idx; int num_ref_views, *ref_view_id; - - if(iVOIdx <0) + if (iVOIdx < 0) printf("Error: iVOIdx: %d is not less than 0\n", iVOIdx); - if(anchor_pic_flag) - { - num_ref_views = list_idx? p_Vid->active_subset_sps->num_anchor_refs_l1[iVOIdx] : p_Vid->active_subset_sps->num_anchor_refs_l0[iVOIdx]; - ref_view_id = list_idx? p_Vid->active_subset_sps->anchor_ref_l1[iVOIdx]:p_Vid->active_subset_sps->anchor_ref_l0[iVOIdx]; - } - else - { - num_ref_views = list_idx? p_Vid->active_subset_sps->num_non_anchor_refs_l1[iVOIdx] : p_Vid->active_subset_sps->num_non_anchor_refs_l0[iVOIdx]; - ref_view_id = list_idx? p_Vid->active_subset_sps->non_anchor_ref_l1[iVOIdx]:p_Vid->active_subset_sps->non_anchor_ref_l0[iVOIdx]; + if (anchor_pic_flag) { + num_ref_views = list_idx + ? p_Vid->active_subset_sps->num_anchor_refs_l1[iVOIdx] + : p_Vid->active_subset_sps->num_anchor_refs_l0[iVOIdx]; + ref_view_id = list_idx ? p_Vid->active_subset_sps->anchor_ref_l1[iVOIdx] + : p_Vid->active_subset_sps->anchor_ref_l0[iVOIdx]; + } else { + num_ref_views = + list_idx ? p_Vid->active_subset_sps->num_non_anchor_refs_l1[iVOIdx] + : p_Vid->active_subset_sps->num_non_anchor_refs_l0[iVOIdx]; + ref_view_id = list_idx + ? p_Vid->active_subset_sps->non_anchor_ref_l1[iVOIdx] + : p_Vid->active_subset_sps->non_anchor_ref_l0[iVOIdx]; } // if(num_ref_views <= 0) - // printf("Error: iNumOfRefViews: %d is not larger than 0\n", num_ref_views); + // printf("Error: iNumOfRefViews: %d is not larger than 0\n", + //num_ref_views); - if(currPicStructure == BOTTOM_FIELD) + if (currPicStructure == BOTTOM_FIELD) fld_idx = 1; else fld_idx = 0; - for(i=0; iused_size; i++) - { - if(currPicStructure==FRAME) - { + for (i = 0; i < p_Dpb->used_size; i++) { + if (currPicStructure == FRAME) { pic_avail = (p_Dpb->fs[i]->is_used == 3); if (pic_avail) poc = p_Dpb->fs[i]->frame->poc; - } - else if(currPicStructure==TOP_FIELD) - { + } else if (currPicStructure == TOP_FIELD) { pic_avail = p_Dpb->fs[i]->is_used & 1; if (pic_avail) poc = p_Dpb->fs[i]->top_field->poc; - } - else if(currPicStructure==BOTTOM_FIELD) - { + } else if (currPicStructure == BOTTOM_FIELD) { pic_avail = p_Dpb->fs[i]->is_used & 2; if (pic_avail) poc = p_Dpb->fs[i]->bottom_field->poc; - } - else - pic_avail =0; + } else + pic_avail = 0; - if(pic_avail && p_Dpb->fs[i]->inter_view_flag[fld_idx]) - { - if(poc == currPOC) - { - if(is_view_id_in_ref_view_list(p_Dpb->fs[i]->view_id, ref_view_id, num_ref_views)) - { - //add one inter-view reference; + if (pic_avail && p_Dpb->fs[i]->inter_view_flag[fld_idx]) { + if (poc == currPOC) { + if (is_view_id_in_ref_view_list(p_Dpb->fs[i]->view_id, ref_view_id, + num_ref_views)) { + // add one inter-view reference; list[*listXsize] = p_Dpb->fs[i]; - //next; + // next; (*listXsize)++; } } @@ -4838,4 +4746,3 @@ void append_interview_list(DecodedPictureBuffer *p_Dpb, } } #endif - diff --git a/src/common/ldecod_src/mbuffer_mvc.c b/src/common/ldecod_src/mbuffer_mvc.c index c2f1a92..704d8d7 100644 --- a/src/common/ldecod_src/mbuffer_mvc.c +++ b/src/common/ldecod_src/mbuffer_mvc.c @@ -8,7 +8,8 @@ * Frame buffer functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Athanasios Leontaris * - Karsten Shring * - Alexis Tourapis @@ -35,31 +36,32 @@ * ************************************************************************ */ -void reorder_short_term(Slice *currSlice, int cur_list, int num_ref_idx_lX_active_minus1, int picNumLX, int *refIdxLX, int currViewID) -{ - StorablePicture **RefPicListX = currSlice->listX[cur_list]; +void reorder_short_term(Slice *currSlice, int cur_list, + int num_ref_idx_lX_active_minus1, int picNumLX, + int *refIdxLX, int currViewID) { + StorablePicture **RefPicListX = currSlice->listX[cur_list]; int cIdx, nIdx; StorablePicture *picLX; picLX = get_short_term_pic(currSlice->p_Dpb, picNumLX); - for( cIdx = num_ref_idx_lX_active_minus1+1; cIdx > *refIdxLX; cIdx-- ) - RefPicListX[ cIdx ] = RefPicListX[ cIdx - 1]; + for (cIdx = num_ref_idx_lX_active_minus1 + 1; cIdx > *refIdxLX; cIdx--) + RefPicListX[cIdx] = RefPicListX[cIdx - 1]; - RefPicListX[ (*refIdxLX)++ ] = picLX; + RefPicListX[(*refIdxLX)++] = picLX; nIdx = *refIdxLX; - for( cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1+1; cIdx++ ) - if (RefPicListX[ cIdx ]) - { - if( (RefPicListX[ cIdx ]->is_long_term ) || (RefPicListX[ cIdx ]->pic_num != picNumLX ) || ( currViewID != -1 && RefPicListX[ cIdx ]->view_id != currViewID )) - RefPicListX[ nIdx++ ] = RefPicListX[ cIdx ]; + for (cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1 + 1; cIdx++) + if (RefPicListX[cIdx]) { + if ((RefPicListX[cIdx]->is_long_term) || + (RefPicListX[cIdx]->pic_num != picNumLX) || + (currViewID != -1 && RefPicListX[cIdx]->view_id != currViewID)) + RefPicListX[nIdx++] = RefPicListX[cIdx]; } } - /*! ************************************************************************ * \brief @@ -67,27 +69,28 @@ void reorder_short_term(Slice *currSlice, int cur_list, int num_ref_idx_lX_activ * ************************************************************************ */ -void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX, int num_ref_idx_lX_active_minus1, int LongTermPicNum, int *refIdxLX, int currViewID) -{ +void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX, + int num_ref_idx_lX_active_minus1, int LongTermPicNum, + int *refIdxLX, int currViewID) { int cIdx, nIdx; StorablePicture *picLX; picLX = get_long_term_pic(currSlice->p_Dpb, LongTermPicNum); - for( cIdx = num_ref_idx_lX_active_minus1+1; cIdx > *refIdxLX; cIdx-- ) - RefPicListX[ cIdx ] = RefPicListX[ cIdx - 1]; + for (cIdx = num_ref_idx_lX_active_minus1 + 1; cIdx > *refIdxLX; cIdx--) + RefPicListX[cIdx] = RefPicListX[cIdx - 1]; - RefPicListX[ (*refIdxLX)++ ] = picLX; + RefPicListX[(*refIdxLX)++] = picLX; nIdx = *refIdxLX; - for( cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1+1; cIdx++ ) - { - if (RefPicListX[ cIdx ]) - { - if( (!RefPicListX[ cIdx ]->is_long_term ) || (RefPicListX[ cIdx ]->long_term_pic_num != LongTermPicNum ) || ( currViewID != -1 && RefPicListX[ cIdx ]->view_id != currViewID )) - RefPicListX[ nIdx++ ] = RefPicListX[ cIdx ]; + for (cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1 + 1; cIdx++) { + if (RefPicListX[cIdx]) { + if ((!RefPicListX[cIdx]->is_long_term) || + (RefPicListX[cIdx]->long_term_pic_num != LongTermPicNum) || + (currViewID != -1 && RefPicListX[cIdx]->view_id != currViewID)) + RefPicListX[nIdx++] = RefPicListX[cIdx]; } } } @@ -99,37 +102,31 @@ void reorder_long_term(Slice *currSlice, StorablePicture **RefPicListX, int num_ * ************************************************************************ */ -static StorablePicture* get_inter_view_pic(VideoParameters *p_Vid, Slice *currSlice, int targetViewID, int currPOC, int listidx) -{ +static StorablePicture *get_inter_view_pic(VideoParameters *p_Vid, + Slice *currSlice, int targetViewID, + int currPOC, int listidx) { unsigned i; unsigned int listinterview_size; FrameStore **fs_listinterview; - if (listidx == 0) - { + if (listidx == 0) { fs_listinterview = currSlice->fs_listinterview0; - listinterview_size = currSlice->listinterviewidx0; - } - else - { + listinterview_size = currSlice->listinterviewidx0; + } else { fs_listinterview = currSlice->fs_listinterview1; - listinterview_size = currSlice->listinterviewidx1; + listinterview_size = currSlice->listinterviewidx1; } - for(i=0; iview_id == targetViewID) - { - if(p_Vid->structure==FRAME && fs_listinterview[i]->frame->poc == currPOC) - { + for (i = 0; i < listinterview_size; i++) { + if (fs_listinterview[i]->view_id == targetViewID) { + if (p_Vid->structure == FRAME && + fs_listinterview[i]->frame->poc == currPOC) { return fs_listinterview[i]->frame; - } - else if(p_Vid->structure==TOP_FIELD && fs_listinterview[i]->top_field->poc == currPOC) - { + } else if (p_Vid->structure == TOP_FIELD && + fs_listinterview[i]->top_field->poc == currPOC) { return fs_listinterview[i]->top_field; - } - else if(p_Vid->structure==BOTTOM_FIELD && fs_listinterview[i]->bottom_field->poc == currPOC) - { + } else if (p_Vid->structure == BOTTOM_FIELD && + fs_listinterview[i]->bottom_field->poc == currPOC) { return fs_listinterview[i]->bottom_field; } } @@ -145,22 +142,19 @@ static StorablePicture* get_inter_view_pic(VideoParameters *p_Vid, Slice *currS * ************************************************************************ */ -static void gen_pic_list_from_frame_interview_list(PictureStructure currStructure, FrameStore **fs_list, int list_idx, StorablePicture **list, signed char *list_size) -{ +static void gen_pic_list_from_frame_interview_list( + PictureStructure currStructure, FrameStore **fs_list, int list_idx, + StorablePicture **list, signed char *list_size) { int i; - if (currStructure == TOP_FIELD) - { - for (i=0; itop_field; (*list_size)++; } } - if (currStructure == BOTTOM_FIELD) - { - for (i=0; ibottom_field; (*list_size)++; } @@ -170,14 +164,15 @@ static void gen_pic_list_from_frame_interview_list(PictureStructure currStructur /*! ************************************************************************ * \brief - * compares two stored pictures by picture number for qsort in descending order + * compares two stored pictures by picture number for qsort in descending + *order * ************************************************************************ */ -static inline int compare_pic_by_pic_num_desc( const void *arg1, const void *arg2 ) -{ - int pic_num1 = (*(StorablePicture**)arg1)->pic_num; - int pic_num2 = (*(StorablePicture**)arg2)->pic_num; +static inline int compare_pic_by_pic_num_desc(const void *arg1, + const void *arg2) { + int pic_num1 = (*(StorablePicture **)arg1)->pic_num; + int pic_num2 = (*(StorablePicture **)arg2)->pic_num; if (pic_num1 < pic_num2) return 1; @@ -190,18 +185,19 @@ static inline int compare_pic_by_pic_num_desc( const void *arg1, const void *arg /*! ************************************************************************ * \brief - * compares two stored pictures by picture number for qsort in descending order + * compares two stored pictures by picture number for qsort in descending + *order * ************************************************************************ */ -static inline int compare_pic_by_lt_pic_num_asc( const void *arg1, const void *arg2 ) -{ - int long_term_pic_num1 = (*(StorablePicture**)arg1)->long_term_pic_num; - int long_term_pic_num2 = (*(StorablePicture**)arg2)->long_term_pic_num; +static inline int compare_pic_by_lt_pic_num_asc(const void *arg1, + const void *arg2) { + int long_term_pic_num1 = (*(StorablePicture **)arg1)->long_term_pic_num; + int long_term_pic_num2 = (*(StorablePicture **)arg2)->long_term_pic_num; - if ( long_term_pic_num1 < long_term_pic_num2) + if (long_term_pic_num1 < long_term_pic_num2) return -1; - else if ( long_term_pic_num1 > long_term_pic_num2) + else if (long_term_pic_num1 > long_term_pic_num2) return 1; else return 0; @@ -214,20 +210,19 @@ static inline int compare_pic_by_lt_pic_num_asc( const void *arg1, const void *a * ************************************************************************ */ -static inline int compare_fs_by_frame_num_desc( const void *arg1, const void *arg2 ) -{ - int frame_num_wrap1 = (*(FrameStore**)arg1)->frame_num_wrap; - int frame_num_wrap2 = (*(FrameStore**)arg2)->frame_num_wrap; +static inline int compare_fs_by_frame_num_desc(const void *arg1, + const void *arg2) { + int frame_num_wrap1 = (*(FrameStore **)arg1)->frame_num_wrap; + int frame_num_wrap2 = (*(FrameStore **)arg2)->frame_num_wrap; - if ( frame_num_wrap1 < frame_num_wrap2) + if (frame_num_wrap1 < frame_num_wrap2) return 1; - else if ( frame_num_wrap1 > frame_num_wrap2) + else if (frame_num_wrap1 > frame_num_wrap2) return -1; else return 0; } - /*! ************************************************************************ * \brief @@ -235,20 +230,19 @@ static inline int compare_fs_by_frame_num_desc( const void *arg1, const void *ar * ************************************************************************ */ -static inline int compare_fs_by_lt_pic_idx_asc( const void *arg1, const void *arg2 ) -{ - int long_term_frame_idx1 = (*(FrameStore**)arg1)->long_term_frame_idx; - int long_term_frame_idx2 = (*(FrameStore**)arg2)->long_term_frame_idx; +static inline int compare_fs_by_lt_pic_idx_asc(const void *arg1, + const void *arg2) { + int long_term_frame_idx1 = (*(FrameStore **)arg1)->long_term_frame_idx; + int long_term_frame_idx2 = (*(FrameStore **)arg2)->long_term_frame_idx; - if ( long_term_frame_idx1 < long_term_frame_idx2) + if (long_term_frame_idx1 < long_term_frame_idx2) return -1; - else if ( long_term_frame_idx1 > long_term_frame_idx2) + else if (long_term_frame_idx1 > long_term_frame_idx2) return 1; else return 0; } - /*! ************************************************************************ * \brief @@ -256,20 +250,18 @@ static inline int compare_fs_by_lt_pic_idx_asc( const void *arg1, const void *ar * ************************************************************************ */ -static inline int compare_pic_by_poc_asc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(StorablePicture**)arg1)->poc; - int poc2 = (*(StorablePicture**)arg2)->poc; +static inline int compare_pic_by_poc_asc(const void *arg1, const void *arg2) { + int poc1 = (*(StorablePicture **)arg1)->poc; + int poc2 = (*(StorablePicture **)arg2)->poc; - if ( poc1 < poc2) - return -1; - else if ( poc1 > poc2) + if (poc1 < poc2) + return -1; + else if (poc1 > poc2) return 1; else return 0; } - /*! ************************************************************************ * \brief @@ -277,10 +269,9 @@ static inline int compare_pic_by_poc_asc( const void *arg1, const void *arg2 ) * ************************************************************************ */ -static inline int compare_pic_by_poc_desc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(StorablePicture**)arg1)->poc; - int poc2 = (*(StorablePicture**)arg2)->poc; +static inline int compare_pic_by_poc_desc(const void *arg1, const void *arg2) { + int poc1 = (*(StorablePicture **)arg1)->poc; + int poc2 = (*(StorablePicture **)arg2)->poc; if (poc1 < poc2) return 1; @@ -290,7 +281,6 @@ static inline int compare_pic_by_poc_desc( const void *arg1, const void *arg2 ) return 0; } - /*! ************************************************************************ * \brief @@ -298,10 +288,9 @@ static inline int compare_pic_by_poc_desc( const void *arg1, const void *arg2 ) * ************************************************************************ */ -static inline int compare_fs_by_poc_asc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(FrameStore**)arg1)->poc; - int poc2 = (*(FrameStore**)arg2)->poc; +static inline int compare_fs_by_poc_asc(const void *arg1, const void *arg2) { + int poc1 = (*(FrameStore **)arg1)->poc; + int poc2 = (*(FrameStore **)arg2)->poc; if (poc1 < poc2) return -1; @@ -311,7 +300,6 @@ static inline int compare_fs_by_poc_asc( const void *arg1, const void *arg2 ) return 0; } - /*! ************************************************************************ * \brief @@ -319,10 +307,9 @@ static inline int compare_fs_by_poc_asc( const void *arg1, const void *arg2 ) * ************************************************************************ */ -static inline int compare_fs_by_poc_desc( const void *arg1, const void *arg2 ) -{ - int poc1 = (*(FrameStore**)arg1)->poc; - int poc2 = (*(FrameStore**)arg2)->poc; +static inline int compare_fs_by_poc_desc(const void *arg1, const void *arg2) { + int poc1 = (*(FrameStore **)arg1)->poc; + int poc2 = (*(FrameStore **)arg2)->poc; if (poc1 < poc2) return 1; @@ -332,7 +319,6 @@ static inline int compare_fs_by_poc_desc( const void *arg1, const void *arg2 ) return 0; } - /*! ************************************************************************ * \brief @@ -340,9 +326,8 @@ static inline int compare_fs_by_poc_desc( const void *arg1, const void *arg2 ) * ************************************************************************ */ -void init_lists_i_slice_mvc(Slice *currSlice) -{ - //VideoParameters *p_Vid = currSlice->p_Vid; +void init_lists_i_slice_mvc(Slice *currSlice) { + // VideoParameters *p_Vid = currSlice->p_Vid; currSlice->listinterviewidx0 = 0; currSlice->listinterviewidx1 = 0; @@ -358,8 +343,7 @@ void init_lists_i_slice_mvc(Slice *currSlice) * ************************************************************************ */ -void init_lists_p_slice_mvc(Slice *currSlice) -{ +void init_lists_p_slice_mvc(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; DecodedPictureBuffer *p_Dpb = currSlice->p_Dpb; @@ -378,130 +362,143 @@ void init_lists_p_slice_mvc(Slice *currSlice) currSlice->listinterviewidx0 = 0; currSlice->listinterviewidx1 = 0; - if (currSlice->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) - { + if (currSlice->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } // order list 0 by PicNum - qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_pic_num_desc); - currSlice->listXsize[0] = (signed char) list0idx; - //printf("listX[0] (PicNum): "); for (i=0; ilistX[0][i]->pic_num);} printf("\n"); + qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture *), + compare_pic_by_pic_num_desc); + currSlice->listXsize[0] = (signed char)list0idx; + // printf("listX[0] (PicNum): "); for (i=0; ilistX[0][i]->pic_num);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_used==3) - { - if (p_Dpb->fs_ltref[i]->frame->is_long_term && (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) - { - currSlice->listX[0][list0idx++]=p_Dpb->fs_ltref[i]->frame; + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_used == 3) { + if (p_Dpb->fs_ltref[i]->frame->is_long_term && + (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) { + currSlice->listX[0][list0idx++] = p_Dpb->fs_ltref[i]->frame; } } } - qsort((void *)&currSlice->listX[0][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - currSlice->listXsize[0] = (signed char) list0idx; - } - else - { - fs_list0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list0) + qsort((void *)&currSlice->listX[0][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + currSlice->listXsize[0] = (signed char)list0idx; + } else { + fs_list0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list0) no_mem_exit("init_lists: fs_list0"); - fs_listlt = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_listlt) + fs_listlt = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_listlt) no_mem_exit("init_lists: fs_listlt"); - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_reference && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_reference && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) { fs_list0[list0idx++] = p_Dpb->fs_ref[i]; } } - qsort((void *)fs_list0, list0idx, sizeof(FrameStore*), compare_fs_by_frame_num_desc); + qsort((void *)fs_list0, list0idx, sizeof(FrameStore *), + compare_fs_by_frame_num_desc); - //printf("fs_list0 (FrameNum): "); for (i=0; iframe_num_wrap);} printf("\n"); + // printf("fs_list0 (FrameNum): "); for (i=0; iframe_num_wrap);} printf("\n"); currSlice->listXsize[0] = 0; - gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, currSlice->listX[0], &currSlice->listXsize[0], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, + currSlice->listX[0], &currSlice->listXsize[0], + 0); - //printf("listX[0] (PicNum): "); for (i=0; i < currSlice->listXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->pic_num);} printf("\n"); + // printf("listX[0] (PicNum): "); for (i=0; i < currSlice->listXsize[0]; + // i++){printf ("%d ", currSlice->listX[0][i]->pic_num);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) - fs_listlt[listltidx++]=p_Dpb->fs_ltref[i]; + fs_listlt[listltidx++] = p_Dpb->fs_ltref[i]; } - qsort((void *)fs_listlt, listltidx, sizeof(FrameStore*), compare_fs_by_lt_pic_idx_asc); + qsort((void *)fs_listlt, listltidx, sizeof(FrameStore *), + compare_fs_by_lt_pic_idx_asc); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[0], &currSlice->listXsize[0], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[0], &currSlice->listXsize[0], + 1); free(fs_list0); free(fs_listlt); } - currSlice->listXsize[1] = 0; + currSlice->listXsize[1] = 0; - if (currSlice->svc_extension_flag == 0) - { - currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview0) + if (currSlice->svc_extension_flag == 0) { + currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview0) no_mem_exit("init_lists: fs_listinterview0"); list0idx = currSlice->listXsize[0]; - if (currSlice->structure == FRAME) - { - append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); + if (currSlice->structure == FRAME) { + append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); - for (i=0; i<(unsigned int)currSlice->listinterviewidx0; i++) - { - currSlice->listX[0][list0idx++]=currSlice->fs_listinterview0[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx0; i++) { + currSlice->listX[0][list0idx++] = + currSlice->fs_listinterview0[i]->frame; } - currSlice->listXsize[0] = (signed char) list0idx; - } - else - { - append_interview_list(p_Dpb, currSlice->structure, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview0, currSlice->listinterviewidx0, currSlice->listX[0], &currSlice->listXsize[0]); + currSlice->listXsize[0] = (signed char)list0idx; + } else { + append_interview_list(p_Dpb, currSlice->structure, 0, + currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview0, + currSlice->listinterviewidx0, currSlice->listX[0], + &currSlice->listXsize[0]); } } // set max size - currSlice->listXsize[0] = (signed char) imin (currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); - currSlice->listXsize[1] = (signed char) imin (currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); + currSlice->listXsize[0] = (signed char)imin( + currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); + currSlice->listXsize[1] = (signed char)imin( + currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); // set the unused list entries to NULL - for (i=currSlice->listXsize[0]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[0]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[0][i] = p_Vid->no_reference_picture; } - for (i=currSlice->listXsize[1]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[1]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[1][i] = p_Vid->no_reference_picture; } -/*#if PRINTREFLIST - // print out for debug purpose - if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && currSlice->current_slice_nr==0) - { - if(currSlice->listXsize[0]>0) + /*#if PRINTREFLIST + // print out for debug purpose + if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && + currSlice->current_slice_nr==0) { - printf("\n"); - printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[0]); i++) //ref list 0 + if(currSlice->listXsize[0]>0) { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, currSlice->listX[0][i]->view_id); + printf("\n"); + printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", + currSlice->view_id, currSlice->structure==FRAME ? + "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); for(i=0; i<(unsigned + int)(currSlice->listXsize[0]); i++) //ref list 0 + { + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, + currSlice->listX[0][i]->view_id); + } } } - } -#endif*/ + #endif*/ } /*! @@ -511,8 +508,7 @@ void init_lists_p_slice_mvc(Slice *currSlice) * ************************************************************************ */ -void init_lists_b_slice_mvc(Slice *currSlice) -{ +void init_lists_b_slice_mvc(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; DecodedPictureBuffer *p_Dpb = currSlice->p_Dpb; @@ -536,139 +532,153 @@ void init_lists_b_slice_mvc(Slice *currSlice) { // B-Slice - if (currSlice->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) - { - if (currSlice->framepoc >= p_Dpb->fs_ref[i]->frame->poc) //!KS use >= for error concealment - // if (p_Vid->framepoc > p_Dpb->fs_ref[i]->frame->poc) + if (currSlice->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) { + if (currSlice->framepoc >= + p_Dpb->fs_ref[i] + ->frame->poc) //! KS use >= for error concealment + // if (p_Vid->framepoc > + // p_Dpb->fs_ref[i]->frame->poc) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } } - qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_poc_desc); + qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture *), + compare_pic_by_poc_desc); list0idx_1 = list0idx; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) - { - if (currSlice->framepoc < p_Dpb->fs_ref[i]->frame->poc) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) { + if (currSlice->framepoc < p_Dpb->fs_ref[i]->frame->poc) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } } - qsort((void *)&currSlice->listX[0][list0idx_1], list0idx-list0idx_1, sizeof(StorablePicture*), compare_pic_by_poc_asc); + qsort((void *)&currSlice->listX[0][list0idx_1], list0idx - list0idx_1, + sizeof(StorablePicture *), compare_pic_by_poc_asc); - for (j=0; jlistX[1][list0idx-list0idx_1+j]=currSlice->listX[0][j]; + for (j = 0; j < list0idx_1; j++) { + currSlice->listX[1][list0idx - list0idx_1 + j] = currSlice->listX[0][j]; } - for (j=list0idx_1; jlistX[1][j-list0idx_1]=currSlice->listX[0][j]; + for (j = list0idx_1; j < list0idx; j++) { + currSlice->listX[1][j - list0idx_1] = currSlice->listX[0][j]; } - currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char) list0idx; + currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char)list0idx; - // printf("currSlice->listX[0] currPoc=%d (Poc): ", currSlice->framepoc); for (i=0; ilistXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); - // printf("currSlice->listX[1] currPoc=%d (Poc): ", currSlice->framepoc); for (i=0; ilistXsize[1]; i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); + // printf("currSlice->listX[0] currPoc=%d (Poc): ", + // currSlice->framepoc); for (i=0; ilistXsize[0]; + // i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); + // printf("currSlice->listX[1] currPoc=%d (Poc): ", + // currSlice->framepoc); for (i=0; ilistXsize[1]; + // i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_used==3) - { - if (p_Dpb->fs_ltref[i]->frame->is_long_term && (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) - { - currSlice->listX[0][list0idx] = p_Dpb->fs_ltref[i]->frame; + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_used == 3) { + if (p_Dpb->fs_ltref[i]->frame->is_long_term && + (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) { + currSlice->listX[0][list0idx] = p_Dpb->fs_ltref[i]->frame; currSlice->listX[1][list0idx++] = p_Dpb->fs_ltref[i]->frame; } } } - qsort((void *)&currSlice->listX[0][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - qsort((void *)&currSlice->listX[1][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char) list0idx; - } - else - { - fs_list0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list0) + qsort((void *)&currSlice->listX[0][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + qsort((void *)&currSlice->listX[1][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char)list0idx; + } else { + fs_list0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list0) no_mem_exit("init_lists: fs_list0"); - fs_list1 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list1) + fs_list1 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list1) no_mem_exit("init_lists: fs_list1"); - fs_listlt = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_listlt) + fs_listlt = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_listlt) no_mem_exit("init_lists: fs_listlt"); currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 1; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used) - { - if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used) { + if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) { fs_list0[list0idx++] = p_Dpb->fs_ref[i]; } } } - qsort((void *)fs_list0, list0idx, sizeof(FrameStore*), compare_fs_by_poc_desc); + qsort((void *)fs_list0, list0idx, sizeof(FrameStore *), + compare_fs_by_poc_desc); list0idx_1 = list0idx; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used) - { - if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used) { + if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) { fs_list0[list0idx++] = p_Dpb->fs_ref[i]; } } } - qsort((void *)&fs_list0[list0idx_1], list0idx-list0idx_1, sizeof(FrameStore*), compare_fs_by_poc_asc); + qsort((void *)&fs_list0[list0idx_1], list0idx - list0idx_1, + sizeof(FrameStore *), compare_fs_by_poc_asc); - for (j=0; jThisPOC); for (i=0; ipoc);} printf("\n"); - // printf("fs_list1 currPoc=%d (Poc): ", currSlice->ThisPOC); for (i=0; ipoc);} printf("\n"); + // printf("fs_list0 currPoc=%d (Poc): ", currSlice->ThisPOC); for + // (i=0; ipoc);} + // printf("\n"); printf("fs_list1 currPoc=%d (Poc): ", + // currSlice->ThisPOC); for (i=0; ipoc);} printf("\n"); currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 0; - gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, currSlice->listX[0], &currSlice->listXsize[0], 0); - gen_pic_list_from_frame_list(currSlice->structure, fs_list1, list0idx, currSlice->listX[1], &currSlice->listXsize[1], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, + currSlice->listX[0], + &currSlice->listXsize[0], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list1, list0idx, + currSlice->listX[1], + &currSlice->listXsize[1], 0); - // printf("currSlice->listX[0] currPoc=%d (Poc): ", currSlice->framepoc); for (i=0; ilistXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); - // printf("currSlice->listX[1] currPoc=%d (Poc): ", currSlice->framepoc); for (i=0; ilistXsize[1]; i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); + // printf("currSlice->listX[0] currPoc=%d (Poc): ", + // currSlice->framepoc); for (i=0; ilistXsize[0]; + // i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); + // printf("currSlice->listX[1] currPoc=%d (Poc): ", + // currSlice->framepoc); for (i=0; ilistXsize[1]; + // i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) - fs_listlt[listltidx++]=p_Dpb->fs_ltref[i]; + fs_listlt[listltidx++] = p_Dpb->fs_ltref[i]; } - qsort((void *)fs_listlt, listltidx, sizeof(FrameStore*), compare_fs_by_lt_pic_idx_asc); + qsort((void *)fs_listlt, listltidx, sizeof(FrameStore *), + compare_fs_by_lt_pic_idx_asc); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[0], &currSlice->listXsize[0], 1); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[1], &currSlice->listXsize[1], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[0], + &currSlice->listXsize[0], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[1], + &currSlice->listXsize[1], 1); free(fs_list0); free(fs_list1); @@ -676,100 +686,119 @@ void init_lists_b_slice_mvc(Slice *currSlice) } } - if ((currSlice->listXsize[0] == currSlice->listXsize[1]) && (currSlice->listXsize[0] > 1)) - { - // check if lists are identical, if yes swap first two elements of currSlice->listX[1] - int diff=0; - for (j = 0; j< currSlice->listXsize[0]; j++) - { - if (currSlice->listX[0][j] != currSlice->listX[1][j]) - { + if ((currSlice->listXsize[0] == currSlice->listXsize[1]) && + (currSlice->listXsize[0] > 1)) { + // check if lists are identical, if yes swap first two elements of + // currSlice->listX[1] + int diff = 0; + for (j = 0; j < currSlice->listXsize[0]; j++) { + if (currSlice->listX[0][j] != currSlice->listX[1][j]) { diff = 1; break; } } - if (!diff) - { + if (!diff) { StorablePicture *tmp_s = currSlice->listX[1][0]; - currSlice->listX[1][0]=currSlice->listX[1][1]; - currSlice->listX[1][1]=tmp_s; + currSlice->listX[1][0] = currSlice->listX[1][1]; + currSlice->listX[1][1] = tmp_s; } } - if (currSlice->svc_extension_flag == 0) - { + if (currSlice->svc_extension_flag == 0) { // B-Slice - currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview0) + currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview0) no_mem_exit("init_lists: fs_listinterview0"); - currSlice->fs_listinterview1 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview1) + currSlice->fs_listinterview1 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview1) no_mem_exit("init_lists: fs_listinterview1"); list0idx = currSlice->listXsize[0]; - if (currSlice->structure == FRAME) - { - append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - append_interview_list(p_Dpb, 0, 1, currSlice->fs_listinterview1, &currSlice->listinterviewidx1, currPOC, curr_view_id, anchor_pic_flag); + if (currSlice->structure == FRAME) { + append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + append_interview_list(p_Dpb, 0, 1, currSlice->fs_listinterview1, + &currSlice->listinterviewidx1, currPOC, + curr_view_id, anchor_pic_flag); - for (i=0; i<(unsigned int)currSlice->listinterviewidx0; i++) - { - currSlice->listX[0][list0idx++]=currSlice->fs_listinterview0[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx0; i++) { + currSlice->listX[0][list0idx++] = + currSlice->fs_listinterview0[i]->frame; } - currSlice->listXsize[0] = (signed char) list0idx; + currSlice->listXsize[0] = (signed char)list0idx; list0idx = currSlice->listXsize[1]; - for (i=0; i<(unsigned int)currSlice->listinterviewidx1; i++) - { - currSlice->listX[1][list0idx++] = currSlice->fs_listinterview1[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx1; i++) { + currSlice->listX[1][list0idx++] = + currSlice->fs_listinterview1[i]->frame; } - currSlice->listXsize[1] = (signed char) list0idx; + currSlice->listXsize[1] = (signed char)list0idx; + } else { + append_interview_list(p_Dpb, currSlice->structure, 0, + currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview0, + currSlice->listinterviewidx0, currSlice->listX[0], + &currSlice->listXsize[0]); + append_interview_list(p_Dpb, currSlice->structure, 1, + currSlice->fs_listinterview1, + &currSlice->listinterviewidx1, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview1, + currSlice->listinterviewidx1, currSlice->listX[1], + &currSlice->listXsize[1]); } - else - { - append_interview_list(p_Dpb, currSlice->structure, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview0, currSlice->listinterviewidx0, currSlice->listX[0], &currSlice->listXsize[0]); - append_interview_list(p_Dpb, currSlice->structure, 1, currSlice->fs_listinterview1, &currSlice->listinterviewidx1, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview1, currSlice->listinterviewidx1, currSlice->listX[1], &currSlice->listXsize[1]); - } } // set max size - currSlice->listXsize[0] = (signed char) imin (currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); - currSlice->listXsize[1] = (signed char) imin (currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); + currSlice->listXsize[0] = (signed char)imin( + currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); + currSlice->listXsize[1] = (signed char)imin( + currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); // set the unused list entries to NULL - for (i=currSlice->listXsize[0]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[0]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[0][i] = p_Vid->no_reference_picture; } - for (i=currSlice->listXsize[1]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[1]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[1][i] = p_Vid->no_reference_picture; } -/*#if PRINTREFLIST - // print out for debug purpose - if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && currSlice->current_slice_nr==0) - { - if((currSlice->listXsize[0]>0) || (currSlice->listXsize[1]>0)) - printf("\n"); - if(currSlice->listXsize[0]>0) + /*#if PRINTREFLIST + // print out for debug purpose + if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && + currSlice->current_slice_nr==0) { - printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[0]); i++) //ref list 0 + if((currSlice->listXsize[0]>0) || (currSlice->listXsize[1]>0)) + printf("\n"); + if(currSlice->listXsize[0]>0) { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, currSlice->listX[0][i]->view_id); + printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", + currSlice->view_id, currSlice->structure==FRAME ? + "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); for(i=0; i<(unsigned + int)(currSlice->listXsize[0]); i++) //ref list 0 + { + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, + currSlice->listX[0][i]->view_id); + } + } + if(currSlice->listXsize[1]>0) + { + printf(" ** (CurViewID:%d) %s Ref Pic List 1 ****\n", + currSlice->view_id, currSlice->structure==FRAME ? + "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); for(i=0; i<(unsigned + int)(currSlice->listXsize[1]); i++) //ref list 1 + { + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[1][i]->poc, currSlice->listX[1][i]->pic_num, + currSlice->listX[1][i]->view_id); + } } } - if(currSlice->listXsize[1]>0) - { - printf(" ** (CurViewID:%d) %s Ref Pic List 1 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[1]); i++) //ref list 1 - { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[1][i]->poc, currSlice->listX[1][i]->pic_num, currSlice->listX[1][i]->view_id); - } - } - } -#endif*/ + #endif*/ } /*! @@ -779,8 +808,7 @@ void init_lists_b_slice_mvc(Slice *currSlice) * ************************************************************************ */ -void init_lists_mvc(Slice *currSlice) -{ +void init_lists_mvc(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; DecodedPictureBuffer *p_Dpb = currSlice->p_Dpb; @@ -800,226 +828,241 @@ void init_lists_mvc(Slice *currSlice) int anchor_pic_flag = currSlice->anchor_pic_flag; currSlice->listinterviewidx0 = 0; - currSlice->listinterviewidx1 = 0; + currSlice->listinterviewidx1 = 0; - if ((currSlice->slice_type == I_SLICE)||(currSlice->slice_type == SI_SLICE)) - { + if ((currSlice->slice_type == I_SLICE) || + (currSlice->slice_type == SI_SLICE)) { currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 0; return; } - if ((currSlice->slice_type == P_SLICE)||(currSlice->slice_type == SP_SLICE)) - { - if (currSlice->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) - { + if ((currSlice->slice_type == P_SLICE) || + (currSlice->slice_type == SP_SLICE)) { + if (currSlice->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } // order list 0 by PicNum - qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_pic_num_desc); - currSlice->listXsize[0] = (signed char) list0idx; - //printf("listX[0] (PicNum): "); for (i=0; ilistX[0][i]->pic_num);} printf("\n"); + qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture *), + compare_pic_by_pic_num_desc); + currSlice->listXsize[0] = (signed char)list0idx; + // printf("listX[0] (PicNum): "); for (i=0; ilistX[0][i]->pic_num);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_used==3) - { - if (p_Dpb->fs_ltref[i]->frame->is_long_term && (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) - { - currSlice->listX[0][list0idx++]=p_Dpb->fs_ltref[i]->frame; + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_used == 3) { + if (p_Dpb->fs_ltref[i]->frame->is_long_term && + (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) { + currSlice->listX[0][list0idx++] = p_Dpb->fs_ltref[i]->frame; } } } - qsort((void *)&currSlice->listX[0][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - currSlice->listXsize[0] = (signed char) list0idx; - } - else - { - fs_list0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list0) - no_mem_exit("init_lists: fs_list0"); - fs_listlt = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_listlt) - no_mem_exit("init_lists: fs_listlt"); + qsort((void *)&currSlice->listX[0][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + currSlice->listXsize[0] = (signed char)list0idx; + } else { + fs_list0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list0) + no_mem_exit("init_lists: fs_list0"); + fs_listlt = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_listlt) + no_mem_exit("init_lists: fs_listlt"); - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_reference && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_reference && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) { fs_list0[list0idx++] = p_Dpb->fs_ref[i]; } } - qsort((void *)fs_list0, list0idx, sizeof(FrameStore*), compare_fs_by_frame_num_desc); + qsort((void *)fs_list0, list0idx, sizeof(FrameStore *), + compare_fs_by_frame_num_desc); - //printf("fs_list0 (FrameNum): "); for (i=0; iframe_num_wrap);} printf("\n"); + // printf("fs_list0 (FrameNum): "); for (i=0; iframe_num_wrap);} printf("\n"); currSlice->listXsize[0] = 0; - gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, currSlice->listX[0], &currSlice->listXsize[0], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, + currSlice->listX[0], + &currSlice->listXsize[0], 0); - //printf("listX[0] (PicNum): "); for (i=0; i < currSlice->listXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->pic_num);} printf("\n"); + // printf("listX[0] (PicNum): "); for (i=0; i < currSlice->listXsize[0]; + // i++){printf ("%d ", currSlice->listX[0][i]->pic_num);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) - fs_listlt[listltidx++]=p_Dpb->fs_ltref[i]; + fs_listlt[listltidx++] = p_Dpb->fs_ltref[i]; } - qsort((void *)fs_listlt, listltidx, sizeof(FrameStore*), compare_fs_by_lt_pic_idx_asc); + qsort((void *)fs_listlt, listltidx, sizeof(FrameStore *), + compare_fs_by_lt_pic_idx_asc); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[0], &currSlice->listXsize[0], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[0], + &currSlice->listXsize[0], 1); free(fs_list0); free(fs_listlt); } currSlice->listXsize[1] = 0; - } - else - { + } else { // B-Slice - if (currSlice->structure == FRAME) - { - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) - { - if (currSlice->framepoc >= p_Dpb->fs_ref[i]->frame->poc) //!KS use >= for error concealment -// if (p_Vid->framepoc > p_Dpb->fs_ref[i]->frame->poc) + if (currSlice->structure == FRAME) { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) { + if (currSlice->framepoc >= + p_Dpb->fs_ref[i] + ->frame->poc) //! KS use >= for error concealment + // if (p_Vid->framepoc > p_Dpb->fs_ref[i]->frame->poc) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } } - qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture*), compare_pic_by_poc_desc); + qsort((void *)currSlice->listX[0], list0idx, sizeof(StorablePicture *), + compare_pic_by_poc_desc); list0idx_1 = list0idx; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used==3) - { - if ((p_Dpb->fs_ref[i]->frame->used_for_reference)&&(!p_Dpb->fs_ref[i]->frame->is_long_term) && (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) - { - if (currSlice->framepoc < p_Dpb->fs_ref[i]->frame->poc) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used == 3) { + if ((p_Dpb->fs_ref[i]->frame->used_for_reference) && + (!p_Dpb->fs_ref[i]->frame->is_long_term) && + (p_Dpb->fs_ref[i]->frame->view_id == curr_view_id)) { + if (currSlice->framepoc < p_Dpb->fs_ref[i]->frame->poc) { currSlice->listX[0][list0idx++] = p_Dpb->fs_ref[i]->frame; } } } } - qsort((void *)&currSlice->listX[0][list0idx_1], list0idx-list0idx_1, sizeof(StorablePicture*), compare_pic_by_poc_asc); + qsort((void *)&currSlice->listX[0][list0idx_1], list0idx - list0idx_1, + sizeof(StorablePicture *), compare_pic_by_poc_asc); - for (j=0; jlistX[1][list0idx-list0idx_1+j]=currSlice->listX[0][j]; + for (j = 0; j < list0idx_1; j++) { + currSlice->listX[1][list0idx - list0idx_1 + j] = currSlice->listX[0][j]; } - for (j=list0idx_1; jlistX[1][j-list0idx_1]=currSlice->listX[0][j]; + for (j = list0idx_1; j < list0idx; j++) { + currSlice->listX[1][j - list0idx_1] = currSlice->listX[0][j]; } - currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char) list0idx; + currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char)list0idx; -// printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); -// printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[1]; i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); + // printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[0]; i++){printf ("%d ", + // currSlice->listX[0][i]->poc);} printf("\n"); + // printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[1]; i++){printf ("%d ", + // currSlice->listX[1][i]->poc);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ltref[i]->is_used==3) - { - if (p_Dpb->fs_ltref[i]->frame->is_long_term && (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) - { - currSlice->listX[0][list0idx] = p_Dpb->fs_ltref[i]->frame; + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { + if (p_Dpb->fs_ltref[i]->is_used == 3) { + if (p_Dpb->fs_ltref[i]->frame->is_long_term && + (p_Dpb->fs_ltref[i]->frame->view_id == curr_view_id)) { + currSlice->listX[0][list0idx] = p_Dpb->fs_ltref[i]->frame; currSlice->listX[1][list0idx++] = p_Dpb->fs_ltref[i]->frame; } } } - qsort((void *)&currSlice->listX[0][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - qsort((void *)&currSlice->listX[1][(short) currSlice->listXsize[0]], list0idx - currSlice->listXsize[0], sizeof(StorablePicture*), compare_pic_by_lt_pic_num_asc); - currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char) list0idx; - } - else - { - fs_list0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list0) - no_mem_exit("init_lists: fs_list0"); - fs_list1 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_list1) - no_mem_exit("init_lists: fs_list1"); - fs_listlt = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==fs_listlt) - no_mem_exit("init_lists: fs_listlt"); + qsort((void *)&currSlice->listX[0][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + qsort((void *)&currSlice->listX[1][(short)currSlice->listXsize[0]], + list0idx - currSlice->listXsize[0], sizeof(StorablePicture *), + compare_pic_by_lt_pic_num_asc); + currSlice->listXsize[0] = currSlice->listXsize[1] = (signed char)list0idx; + } else { + fs_list0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list0) + no_mem_exit("init_lists: fs_list0"); + fs_list1 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_list1) + no_mem_exit("init_lists: fs_list1"); + fs_listlt = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == fs_listlt) + no_mem_exit("init_lists: fs_listlt"); currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 1; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used) - { - if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used) { + if (currSlice->ThisPOC >= p_Dpb->fs_ref[i]->poc && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) { fs_list0[list0idx++] = p_Dpb->fs_ref[i]; } } } - qsort((void *)fs_list0, list0idx, sizeof(FrameStore*), compare_fs_by_poc_desc); + qsort((void *)fs_list0, list0idx, sizeof(FrameStore *), + compare_fs_by_poc_desc); list0idx_1 = list0idx; - for (i=0; iref_frames_in_buffer; i++) - { - if (p_Dpb->fs_ref[i]->is_used) - { - if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc && (p_Dpb->fs_ref[i]->view_id == curr_view_id)) - { + for (i = 0; i < p_Dpb->ref_frames_in_buffer; i++) { + if (p_Dpb->fs_ref[i]->is_used) { + if (currSlice->ThisPOC < p_Dpb->fs_ref[i]->poc && + (p_Dpb->fs_ref[i]->view_id == curr_view_id)) { fs_list0[list0idx++] = p_Dpb->fs_ref[i]; } } } - qsort((void *)&fs_list0[list0idx_1], list0idx-list0idx_1, sizeof(FrameStore*), compare_fs_by_poc_asc); + qsort((void *)&fs_list0[list0idx_1], list0idx - list0idx_1, + sizeof(FrameStore *), compare_fs_by_poc_asc); - for (j=0; jThisPOC); for (i=0; ipoc);} printf("\n"); -// printf("fs_list1 currPoc=%d (Poc): ", currSlice->ThisPOC); for (i=0; ipoc);} printf("\n"); + // printf("fs_list0 currPoc=%d (Poc): ", currSlice->ThisPOC); for + // (i=0; ipoc);} + // printf("\n"); printf("fs_list1 currPoc=%d (Poc): ", + // currSlice->ThisPOC); for (i=0; ipoc);} printf("\n"); currSlice->listXsize[0] = 0; currSlice->listXsize[1] = 0; - gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, currSlice->listX[0], &currSlice->listXsize[0], 0); - gen_pic_list_from_frame_list(currSlice->structure, fs_list1, list0idx, currSlice->listX[1], &currSlice->listXsize[1], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list0, list0idx, + currSlice->listX[0], + &currSlice->listXsize[0], 0); + gen_pic_list_from_frame_list(currSlice->structure, fs_list1, list0idx, + currSlice->listX[1], + &currSlice->listXsize[1], 0); -// printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[0]; i++){printf ("%d ", currSlice->listX[0][i]->poc);} printf("\n"); -// printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); for (i=0; ilistXsize[1]; i++){printf ("%d ", currSlice->listX[1][i]->poc);} printf("\n"); + // printf("currSlice->listX[0] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[0]; i++){printf ("%d ", + // currSlice->listX[0][i]->poc);} printf("\n"); + // printf("currSlice->listX[1] currPoc=%d (Poc): ", p_Vid->framepoc); + // for (i=0; ilistXsize[1]; i++){printf ("%d ", + // currSlice->listX[1][i]->poc);} printf("\n"); // long term handling - for (i=0; iltref_frames_in_buffer; i++) - { + for (i = 0; i < p_Dpb->ltref_frames_in_buffer; i++) { if (p_Dpb->fs_ltref[i]->view_id == curr_view_id) - fs_listlt[listltidx++]=p_Dpb->fs_ltref[i]; + fs_listlt[listltidx++] = p_Dpb->fs_ltref[i]; } - qsort((void *)fs_listlt, listltidx, sizeof(FrameStore*), compare_fs_by_lt_pic_idx_asc); + qsort((void *)fs_listlt, listltidx, sizeof(FrameStore *), + compare_fs_by_lt_pic_idx_asc); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[0], &currSlice->listXsize[0], 1); - gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, currSlice->listX[1], &currSlice->listXsize[1], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[0], + &currSlice->listXsize[0], 1); + gen_pic_list_from_frame_list(currSlice->structure, fs_listlt, listltidx, + currSlice->listX[1], + &currSlice->listXsize[1], 1); free(fs_list0); free(fs_list1); @@ -1027,95 +1070,109 @@ void init_lists_mvc(Slice *currSlice) } } - if ((currSlice->listXsize[0] == currSlice->listXsize[1]) && (currSlice->listXsize[0] > 1)) - { - // check if lists are identical, if yes swap first two elements of currSlice->listX[1] - int diff=0; - for (j = 0; j< currSlice->listXsize[0]; j++) - { - if (currSlice->listX[0][j]!=currSlice->listX[1][j]) - diff=1; + if ((currSlice->listXsize[0] == currSlice->listXsize[1]) && + (currSlice->listXsize[0] > 1)) { + // check if lists are identical, if yes swap first two elements of + // currSlice->listX[1] + int diff = 0; + for (j = 0; j < currSlice->listXsize[0]; j++) { + if (currSlice->listX[0][j] != currSlice->listX[1][j]) + diff = 1; } - if (!diff) - { + if (!diff) { StorablePicture *tmp_s = currSlice->listX[1][0]; - currSlice->listX[1][0]=currSlice->listX[1][1]; - currSlice->listX[1][1]=tmp_s; + currSlice->listX[1][0] = currSlice->listX[1][1]; + currSlice->listX[1][1] = tmp_s; } } - if (currSlice->svc_extension_flag==0) - { - if ((currSlice->slice_type == P_SLICE)||(currSlice->slice_type == SP_SLICE)) - { - currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview0) + if (currSlice->svc_extension_flag == 0) { + if ((currSlice->slice_type == P_SLICE) || + (currSlice->slice_type == SP_SLICE)) { + currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview0) no_mem_exit("init_lists: fs_listinterview0"); list0idx = currSlice->listXsize[0]; - if (currSlice->structure == FRAME) - { - append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); + if (currSlice->structure == FRAME) { + append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); - for (i=0; i<(unsigned int)currSlice->listinterviewidx0; i++) - { - currSlice->listX[0][list0idx++]=currSlice->fs_listinterview0[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx0; i++) { + currSlice->listX[0][list0idx++] = + currSlice->fs_listinterview0[i]->frame; } - currSlice->listXsize[0] = (signed char) list0idx; + currSlice->listXsize[0] = (signed char)list0idx; + } else { + append_interview_list(p_Dpb, currSlice->structure, 0, + currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview0, + currSlice->listinterviewidx0, currSlice->listX[0], + &currSlice->listXsize[0]); } - else - { - append_interview_list(p_Dpb, currSlice->structure, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview0, currSlice->listinterviewidx0, currSlice->listX[0], &currSlice->listXsize[0]); - } - } - else - { + } else { // B-Slice - currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview0) + currSlice->fs_listinterview0 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview0) no_mem_exit("init_lists: fs_listinterview0"); - currSlice->fs_listinterview1 = calloc(p_Dpb->size, sizeof (FrameStore*)); - if (NULL==currSlice->fs_listinterview1) + currSlice->fs_listinterview1 = calloc(p_Dpb->size, sizeof(FrameStore *)); + if (NULL == currSlice->fs_listinterview1) no_mem_exit("init_lists: fs_listinterview1"); list0idx = currSlice->listXsize[0]; - if (currSlice->structure == FRAME) - { - append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - append_interview_list(p_Dpb, 0, 1, currSlice->fs_listinterview1, &currSlice->listinterviewidx1, currPOC, curr_view_id, anchor_pic_flag); + if (currSlice->structure == FRAME) { + append_interview_list(p_Dpb, 0, 0, currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + append_interview_list(p_Dpb, 0, 1, currSlice->fs_listinterview1, + &currSlice->listinterviewidx1, currPOC, + curr_view_id, anchor_pic_flag); - for (i=0; i<(unsigned int)currSlice->listinterviewidx0; i++) - { - currSlice->listX[0][list0idx++]=currSlice->fs_listinterview0[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx0; i++) { + currSlice->listX[0][list0idx++] = + currSlice->fs_listinterview0[i]->frame; } - currSlice->listXsize[0] = (signed char) list0idx; + currSlice->listXsize[0] = (signed char)list0idx; list0idx = currSlice->listXsize[1]; - for (i=0; i<(unsigned int)currSlice->listinterviewidx1; i++) - { - currSlice->listX[1][list0idx++]=currSlice->fs_listinterview1[i]->frame; + for (i = 0; i < (unsigned int)currSlice->listinterviewidx1; i++) { + currSlice->listX[1][list0idx++] = + currSlice->fs_listinterview1[i]->frame; } - currSlice->listXsize[1] = (signed char) list0idx; - } - else - { - append_interview_list(p_Dpb, currSlice->structure, 0, currSlice->fs_listinterview0, &currSlice->listinterviewidx0, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview0, currSlice->listinterviewidx0, currSlice->listX[0], &currSlice->listXsize[0]); - append_interview_list(p_Dpb, currSlice->structure, 1, currSlice->fs_listinterview1, &currSlice->listinterviewidx1, currPOC, curr_view_id, anchor_pic_flag); - gen_pic_list_from_frame_interview_list(currSlice->structure, currSlice->fs_listinterview1, currSlice->listinterviewidx1, currSlice->listX[1], &currSlice->listXsize[1]); + currSlice->listXsize[1] = (signed char)list0idx; + } else { + append_interview_list(p_Dpb, currSlice->structure, 0, + currSlice->fs_listinterview0, + &currSlice->listinterviewidx0, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview0, + currSlice->listinterviewidx0, currSlice->listX[0], + &currSlice->listXsize[0]); + append_interview_list(p_Dpb, currSlice->structure, 1, + currSlice->fs_listinterview1, + &currSlice->listinterviewidx1, currPOC, + curr_view_id, anchor_pic_flag); + gen_pic_list_from_frame_interview_list( + currSlice->structure, currSlice->fs_listinterview1, + currSlice->listinterviewidx1, currSlice->listX[1], + &currSlice->listXsize[1]); } } } // set max size - currSlice->listXsize[0] = (signed char) imin (currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); - currSlice->listXsize[1] = (signed char) imin (currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); + currSlice->listXsize[0] = (signed char)imin( + currSlice->listXsize[0], currSlice->num_ref_idx_active[LIST_0]); + currSlice->listXsize[1] = (signed char)imin( + currSlice->listXsize[1], currSlice->num_ref_idx_active[LIST_1]); // set the unused list entries to NULL - for (i=currSlice->listXsize[0]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[0]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[0][i] = p_Vid->no_reference_picture; } - for (i=currSlice->listXsize[1]; i< (MAX_LIST_SIZE) ; i++) - { + for (i = currSlice->listXsize[1]; i < (MAX_LIST_SIZE); i++) { currSlice->listX[1][i] = p_Vid->no_reference_picture; } } @@ -1127,30 +1184,30 @@ void init_lists_mvc(Slice *currSlice) * ************************************************************************ */ -static void reorder_interview(VideoParameters *p_Vid, Slice *currSlice, StorablePicture **RefPicListX, int num_ref_idx_lX_active_minus1, int *refIdxLX, int targetViewID, int currPOC, int listidx) -{ +static void reorder_interview(VideoParameters *p_Vid, Slice *currSlice, + StorablePicture **RefPicListX, + int num_ref_idx_lX_active_minus1, int *refIdxLX, + int targetViewID, int currPOC, int listidx) { int cIdx, nIdx; StorablePicture *picLX; - picLX = get_inter_view_pic(p_Vid, currSlice, targetViewID, currPOC, listidx); + picLX = get_inter_view_pic(p_Vid, currSlice, targetViewID, currPOC, listidx); - if (picLX) - { - for( cIdx = num_ref_idx_lX_active_minus1+1; cIdx > *refIdxLX; cIdx-- ) - RefPicListX[ cIdx ] = RefPicListX[ cIdx - 1]; + if (picLX) { + for (cIdx = num_ref_idx_lX_active_minus1 + 1; cIdx > *refIdxLX; cIdx--) + RefPicListX[cIdx] = RefPicListX[cIdx - 1]; - RefPicListX[ (*refIdxLX)++ ] = picLX; + RefPicListX[(*refIdxLX)++] = picLX; - nIdx = *refIdxLX; + nIdx = *refIdxLX; - for( cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1+1; cIdx++ ) - if((RefPicListX[cIdx]->view_id != targetViewID) || (RefPicListX[cIdx]->poc != currPOC)) - RefPicListX[ nIdx++ ] = RefPicListX[ cIdx ]; - } + for (cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1 + 1; cIdx++) + if ((RefPicListX[cIdx]->view_id != targetViewID) || + (RefPicListX[cIdx]->poc != currPOC)) + RefPicListX[nIdx++] = RefPicListX[cIdx]; + } } - - /*! ************************************************************************ * \brief @@ -1158,193 +1215,213 @@ static void reorder_interview(VideoParameters *p_Vid, Slice *currSlice, Storable * ************************************************************************ */ -void reorder_ref_pic_list_mvc(Slice *currSlice, int cur_list, int **anchor_ref, int **non_anchor_ref, int view_id, int anchor_pic_flag, int currPOC, int listidx) -{ +void reorder_ref_pic_list_mvc(Slice *currSlice, int cur_list, int **anchor_ref, + int **non_anchor_ref, int view_id, + int anchor_pic_flag, int currPOC, int listidx) { VideoParameters *p_Vid = currSlice->p_Vid; - int *reordering_of_pic_nums_idc = currSlice->reordering_of_pic_nums_idc[cur_list]; + int *reordering_of_pic_nums_idc = + currSlice->reordering_of_pic_nums_idc[cur_list]; int *abs_diff_pic_num_minus1 = currSlice->abs_diff_pic_num_minus1[cur_list]; int *long_term_pic_idx = currSlice->long_term_pic_idx[cur_list]; - int num_ref_idx_lX_active_minus1 = currSlice->num_ref_idx_active[cur_list] - 1; + int num_ref_idx_lX_active_minus1 = + currSlice->num_ref_idx_active[cur_list] - 1; int *abs_diff_view_idx_minus1 = currSlice->abs_diff_view_idx_minus1[cur_list]; int i; int maxPicNum, currPicNum, picNumLXNoWrap, picNumLXPred, picNumLX; - int picViewIdxLX, targetViewID; + int picViewIdxLX, targetViewID; int refIdxLX = 0; - int maxViewIdx =0; - int curr_VOIdx = -1; - int picViewIdxLXPred=-1; + int maxViewIdx = 0; + int curr_VOIdx = -1; + int picViewIdxLXPred = -1; - if (p_Vid->structure==FRAME) - { - maxPicNum = p_Vid->MaxFrameNum; + if (p_Vid->structure == FRAME) { + maxPicNum = p_Vid->MaxFrameNum; currPicNum = currSlice->frame_num; - } - else - { - maxPicNum = 2 * p_Vid->MaxFrameNum; + } else { + maxPicNum = 2 * p_Vid->MaxFrameNum; currPicNum = 2 * currSlice->frame_num + 1; } - if(currSlice->svc_extension_flag==0) - { - curr_VOIdx = GetVOIdx(p_Vid, view_id); - maxViewIdx = get_maxViewIdx(p_Vid, view_id, anchor_pic_flag, 0); - picViewIdxLXPred=-1; - } + if (currSlice->svc_extension_flag == 0) { + curr_VOIdx = GetVOIdx(p_Vid, view_id); + maxViewIdx = get_maxViewIdx(p_Vid, view_id, anchor_pic_flag, 0); + picViewIdxLXPred = -1; + } picNumLXPred = currPicNum; - for (i=0; reordering_of_pic_nums_idc[i]!=3; i++) - { + for (i = 0; reordering_of_pic_nums_idc[i] != 3; i++) { if (reordering_of_pic_nums_idc[i] > 5) - error ("Invalid remapping_of_pic_nums_idc command", 500); + error("Invalid remapping_of_pic_nums_idc command", 500); - if (reordering_of_pic_nums_idc[i] < 2) - { - if (reordering_of_pic_nums_idc[i] == 0) - { - if( picNumLXPred - ( abs_diff_pic_num_minus1[i] + 1 ) < 0 ) - picNumLXNoWrap = picNumLXPred - ( abs_diff_pic_num_minus1[i] + 1 ) + maxPicNum; + if (reordering_of_pic_nums_idc[i] < 2) { + if (reordering_of_pic_nums_idc[i] == 0) { + if (picNumLXPred - (abs_diff_pic_num_minus1[i] + 1) < 0) + picNumLXNoWrap = + picNumLXPred - (abs_diff_pic_num_minus1[i] + 1) + maxPicNum; else - picNumLXNoWrap = picNumLXPred - ( abs_diff_pic_num_minus1[i] + 1 ); - } - else // (remapping_of_pic_nums_idc[i] == 1) + picNumLXNoWrap = picNumLXPred - (abs_diff_pic_num_minus1[i] + 1); + } else // (remapping_of_pic_nums_idc[i] == 1) { - if( picNumLXPred + ( abs_diff_pic_num_minus1[i] + 1 ) >= maxPicNum ) - picNumLXNoWrap = picNumLXPred + ( abs_diff_pic_num_minus1[i] + 1 ) - maxPicNum; + if (picNumLXPred + (abs_diff_pic_num_minus1[i] + 1) >= maxPicNum) + picNumLXNoWrap = + picNumLXPred + (abs_diff_pic_num_minus1[i] + 1) - maxPicNum; else - picNumLXNoWrap = picNumLXPred + ( abs_diff_pic_num_minus1[i] + 1 ); + picNumLXNoWrap = picNumLXPred + (abs_diff_pic_num_minus1[i] + 1); } picNumLXPred = picNumLXNoWrap; - if( picNumLXNoWrap > currPicNum ) + if (picNumLXNoWrap > currPicNum) picNumLX = picNumLXNoWrap - maxPicNum; else picNumLX = picNumLXNoWrap; - reorder_short_term(currSlice, cur_list, num_ref_idx_lX_active_minus1, picNumLX, &refIdxLX, view_id); - } - else if (reordering_of_pic_nums_idc[i] == 2) //(remapping_of_pic_nums_idc[i] == 2) + reorder_short_term(currSlice, cur_list, num_ref_idx_lX_active_minus1, + picNumLX, &refIdxLX, view_id); + } else if (reordering_of_pic_nums_idc[i] == + 2) //(remapping_of_pic_nums_idc[i] == 2) { - reorder_long_term(currSlice, currSlice->listX[cur_list], num_ref_idx_lX_active_minus1, long_term_pic_idx[i], &refIdxLX, view_id); - } - else - { - if(reordering_of_pic_nums_idc[i] == 4) //(remapping_of_pic_nums_idc[i] == 4) - { - picViewIdxLX = picViewIdxLXPred - (abs_diff_view_idx_minus1[i] + 1); - if( picViewIdxLX <0) - picViewIdxLX += maxViewIdx; - } - else //(remapping_of_pic_nums_idc[i] == 5) - { - picViewIdxLX = picViewIdxLXPred + (abs_diff_view_idx_minus1[i] + 1); - if( picViewIdxLX >= maxViewIdx) - picViewIdxLX -= maxViewIdx; - } - picViewIdxLXPred = picViewIdxLX; - - if (anchor_pic_flag) - targetViewID = anchor_ref[curr_VOIdx][picViewIdxLX]; - else - targetViewID = non_anchor_ref[curr_VOIdx][picViewIdxLX]; + reorder_long_term(currSlice, currSlice->listX[cur_list], + num_ref_idx_lX_active_minus1, long_term_pic_idx[i], + &refIdxLX, view_id); + } else { + if (reordering_of_pic_nums_idc[i] == + 4) //(remapping_of_pic_nums_idc[i] == 4) + { + picViewIdxLX = picViewIdxLXPred - (abs_diff_view_idx_minus1[i] + 1); + if (picViewIdxLX < 0) + picViewIdxLX += maxViewIdx; + } else //(remapping_of_pic_nums_idc[i] == 5) + { + picViewIdxLX = picViewIdxLXPred + (abs_diff_view_idx_minus1[i] + 1); + if (picViewIdxLX >= maxViewIdx) + picViewIdxLX -= maxViewIdx; + } + picViewIdxLXPred = picViewIdxLX; - reorder_interview(p_Vid, currSlice, currSlice->listX[cur_list], num_ref_idx_lX_active_minus1, &refIdxLX, targetViewID, currPOC, listidx); - } + if (anchor_pic_flag) + targetViewID = anchor_ref[curr_VOIdx][picViewIdxLX]; + else + targetViewID = non_anchor_ref[curr_VOIdx][picViewIdxLX]; + + reorder_interview(p_Vid, currSlice, currSlice->listX[cur_list], + num_ref_idx_lX_active_minus1, &refIdxLX, targetViewID, + currPOC, listidx); + } } // that's a definition - currSlice->listXsize[cur_list] = (signed char) (num_ref_idx_lX_active_minus1 + 1); + currSlice->listXsize[cur_list] = + (signed char)(num_ref_idx_lX_active_minus1 + 1); } -void reorder_lists_mvc(Slice * currSlice, int currPOC) -{ +void reorder_lists_mvc(Slice *currSlice, int currPOC) { VideoParameters *p_Vid = currSlice->p_Vid; - if ((currSlice->slice_type != I_SLICE)&&(currSlice->slice_type != SI_SLICE)) - { - if (currSlice->ref_pic_list_reordering_flag[LIST_0]) - { - reorder_ref_pic_list_mvc(currSlice, LIST_0, - p_Vid->active_subset_sps->anchor_ref_l0, - p_Vid->active_subset_sps->non_anchor_ref_l0, - currSlice->view_id, currSlice->anchor_pic_flag, currPOC, 0); - } - if (p_Vid->no_reference_picture == currSlice->listX[0][currSlice->num_ref_idx_active[LIST_0]-1]) - { - if (p_Vid->non_conforming_stream) - printf("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no reference picture'\n"); - else - error("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no reference picture', invalid bitstream",500); - } - // that's a definition - currSlice->listXsize[0] = (signed char)currSlice->num_ref_idx_active[LIST_0]; - } - if (currSlice->slice_type == B_SLICE) - { - if (currSlice->ref_pic_list_reordering_flag[LIST_1]) - { - reorder_ref_pic_list_mvc(currSlice, LIST_1, - p_Vid->active_subset_sps->anchor_ref_l1, - p_Vid->active_subset_sps->non_anchor_ref_l1, - currSlice->view_id, currSlice->anchor_pic_flag, currPOC, 1); - } - if (p_Vid->no_reference_picture == currSlice->listX[1][currSlice->num_ref_idx_active[LIST_1]-1]) - { - if (p_Vid->non_conforming_stream) - printf("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no reference picture'\n"); - else - error("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no reference picture', invalid bitstream",500); - } - // that's a definition - currSlice->listXsize[1] = (signed char)currSlice->num_ref_idx_active[LIST_1]; - } - - free_ref_pic_list_reordering_buffer(currSlice); - - if ( currSlice->slice_type == P_SLICE ) - { -#if PRINTREFLIST - unsigned int i; - // print out for debug purpose - if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && currSlice->current_slice_nr==0) - { - if(currSlice->listXsize[0]>0) - { - printf("\n"); - printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[0]); i++) //ref list 0 - { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, currSlice->listX[0][i]->view_id); - } - } + if ((currSlice->slice_type != I_SLICE) && + (currSlice->slice_type != SI_SLICE)) { + if (currSlice->ref_pic_list_reordering_flag[LIST_0]) { + reorder_ref_pic_list_mvc( + currSlice, LIST_0, p_Vid->active_subset_sps->anchor_ref_l0, + p_Vid->active_subset_sps->non_anchor_ref_l0, currSlice->view_id, + currSlice->anchor_pic_flag, currPOC, 0); } -#endif + if (p_Vid->no_reference_picture == + currSlice->listX[0][currSlice->num_ref_idx_active[LIST_0] - 1]) { + if (p_Vid->non_conforming_stream) + printf("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no " + "reference picture'\n"); + else + error("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no " + "reference picture', invalid bitstream", + 500); + } + // that's a definition + currSlice->listXsize[0] = + (signed char)currSlice->num_ref_idx_active[LIST_0]; } - else if ( currSlice->slice_type == B_SLICE ) - { + if (currSlice->slice_type == B_SLICE) { + if (currSlice->ref_pic_list_reordering_flag[LIST_1]) { + reorder_ref_pic_list_mvc( + currSlice, LIST_1, p_Vid->active_subset_sps->anchor_ref_l1, + p_Vid->active_subset_sps->non_anchor_ref_l1, currSlice->view_id, + currSlice->anchor_pic_flag, currPOC, 1); + } + if (p_Vid->no_reference_picture == + currSlice->listX[1][currSlice->num_ref_idx_active[LIST_1] - 1]) { + if (p_Vid->non_conforming_stream) + printf("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no " + "reference picture'\n"); + else + error("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no " + "reference picture', invalid bitstream", + 500); + } + // that's a definition + currSlice->listXsize[1] = + (signed char)currSlice->num_ref_idx_active[LIST_1]; + } + + free_ref_pic_list_reordering_buffer(currSlice); + + if (currSlice->slice_type == P_SLICE) { #if PRINTREFLIST unsigned int i; // print out for debug purpose - if((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && currSlice->current_slice_nr==0) - { - if((currSlice->listXsize[0]>0) || (currSlice->listXsize[1]>0)) + if ((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && + currSlice->current_slice_nr == 0) { + if (currSlice->listXsize[0] > 0) { printf("\n"); - if(currSlice->listXsize[0]>0) - { - printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[0]); i++) //ref list 0 + printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", + currSlice->view_id, + currSlice->structure == FRAME + ? "FRM" + : (currSlice->structure == TOP_FIELD ? "TOP" : "BOT")); + for (i = 0; i < (unsigned int)(currSlice->listXsize[0]); + i++) // ref list 0 { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, currSlice->listX[0][i]->view_id); + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, + currSlice->listX[0][i]->view_id); } } - if(currSlice->listXsize[1]>0) - { - printf(" ** (CurViewID:%d) %s Ref Pic List 1 ****\n", currSlice->view_id, currSlice->structure==FRAME ? "FRM":(currSlice->structure==TOP_FIELD ? "TOP":"BOT")); - for(i=0; i<(unsigned int)(currSlice->listXsize[1]); i++) //ref list 1 + } +#endif + } else if (currSlice->slice_type == B_SLICE) { +#if PRINTREFLIST + unsigned int i; + // print out for debug purpose + if ((p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH) && + currSlice->current_slice_nr == 0) { + if ((currSlice->listXsize[0] > 0) || (currSlice->listXsize[1] > 0)) + printf("\n"); + if (currSlice->listXsize[0] > 0) { + printf(" ** (CurViewID:%d) %s Ref Pic List 0 ****\n", + currSlice->view_id, + currSlice->structure == FRAME + ? "FRM" + : (currSlice->structure == TOP_FIELD ? "TOP" : "BOT")); + for (i = 0; i < (unsigned int)(currSlice->listXsize[0]); + i++) // ref list 0 { - printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, currSlice->listX[1][i]->poc, currSlice->listX[1][i]->pic_num, currSlice->listX[1][i]->view_id); + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[0][i]->poc, currSlice->listX[0][i]->pic_num, + currSlice->listX[0][i]->view_id); + } + } + if (currSlice->listXsize[1] > 0) { + printf(" ** (CurViewID:%d) %s Ref Pic List 1 ****\n", + currSlice->view_id, + currSlice->structure == FRAME + ? "FRM" + : (currSlice->structure == TOP_FIELD ? "TOP" : "BOT")); + for (i = 0; i < (unsigned int)(currSlice->listXsize[1]); + i++) // ref list 1 + { + printf(" %2d -> POC: %4d PicNum: %4d ViewID: %d\n", i, + currSlice->listX[1][i]->poc, currSlice->listX[1][i]->pic_num, + currSlice->listX[1][i]->view_id); } } } @@ -1353,4 +1430,3 @@ void reorder_lists_mvc(Slice * currSlice, int currPOC) } #endif - diff --git a/src/common/ldecod_src/mc_direct.c b/src/common/ldecod_src/mc_direct.c index 05dbc5d..a4a0b09 100644 --- a/src/common/ldecod_src/mc_direct.c +++ b/src/common/ldecod_src/mc_direct.c @@ -7,693 +7,704 @@ * Direct Prediction functions * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * - Yuwen He * ************************************************************************************* */ -#include "global.h" #include "block.h" -#include "mc_prediction.h" -#include "mbuffer.h" -#include "mb_access.h" +#include "global.h" #include "macroblock.h" +#include "mb_access.h" +#include "mbuffer.h" +#include "mc_prediction.h" #include "memalloc.h" -static void update_direct_mv_info_temporal(Macroblock *currMB) -{ +static void update_direct_mv_info_temporal(Macroblock *currMB) { VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; - int j,k; - int partmode = ((currMB->mb_type == P8x8) ? 4 : currMB->mb_type); - int step_h0 = BLOCK_STEP [partmode][0]; - int step_v0 = BLOCK_STEP [partmode][1]; + int j, k; + int partmode = ((currMB->mb_type == P8x8) ? 4 : currMB->mb_type); + int step_h0 = BLOCK_STEP[partmode][0]; + int step_v0 = BLOCK_STEP[partmode][1]; int i0, j0, j6; int j4, i4; StorablePicture *dec_picture = currSlice->dec_picture; - int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? (mb_nr&0x01) ? 4 : 2 : 0; + int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? + // (mb_nr&0x01) ? 4 : 2 : 0; StorablePicture **list0 = currSlice->listX[LIST_0 + list_offset]; StorablePicture **list1 = currSlice->listX[LIST_1 + list_offset]; - Boolean has_direct = (currMB->b8mode[0] == 0) | (currMB->b8mode[1] == 0) | (currMB->b8mode[2] == 0) | (currMB->b8mode[3] == 0); + Boolean has_direct = (currMB->b8mode[0] == 0) | (currMB->b8mode[1] == 0) | + (currMB->b8mode[2] == 0) | (currMB->b8mode[3] == 0); - if (has_direct) - { + if (has_direct) { int mv_scale = 0; for (k = 0; k < 4; ++k) // Scan all blocks { - if (currMB->b8mode[k] == 0) - { + if (currMB->b8mode[k] == 0) { currMB->b8pdir[k] = 2; - for(j0 = 2 * (k >> 1); j0 < 2 * (k >> 1) + 2; j0 += step_v0) - { - for(i0 = currMB->block_x + 2*(k & 0x01); i0 < currMB->block_x + 2 * (k & 0x01)+2; i0 += step_h0) - { + for (j0 = 2 * (k >> 1); j0 < 2 * (k >> 1) + 2; j0 += step_v0) { + for (i0 = currMB->block_x + 2 * (k & 0x01); + i0 < currMB->block_x + 2 * (k & 0x01) + 2; i0 += step_h0) { PicMotionParams *colocated; int refList; int ref_idx; int mapped_idx = -1, iref; - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->mv_info[RSD(currMB->block_y_aff + j0)][RSD(i0)] : &list1[0]->mv_info[currMB->block_y_aff + j0][i0]; - if(currSlice->mb_aff_frame_flag) - { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->mv_info[RSD(currMB->block_y_aff + j0)][RSD(i0)] + : &list1[0]->mv_info[currMB->block_y_aff + j0][i0]; + if (currSlice->mb_aff_frame_flag) { assert(p_Vid->active_sps->direct_8x8_inference_flag); - if(!currMB->mb_field && ((currSlice->listX[LIST_1][0]->iCodingType==FRAME_MB_PAIR_CODING && currSlice->listX[LIST_1][0]->motion.mb_field[currMB->mbAddrX]) || - (currSlice->listX[LIST_1][0]->iCodingType==FIELD_CODING))) - { - if (iabs(dec_picture->poc - currSlice->listX[LIST_1+4][0]->poc)> iabs(dec_picture->poc -currSlice->listX[LIST_1+2][0]->poc) ) - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &currSlice->listX[LIST_1+2][0]->mv_info[RSD(currMB->block_y_aff + j0)>>1][RSD(i0)] : &currSlice->listX[LIST_1+2][0]->mv_info[(currMB->block_y_aff + j0)>>1][i0]; - } - else - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &currSlice->listX[LIST_1+4][0]->mv_info[RSD(currMB->block_y_aff + j0)>>1][RSD(i0)] : &currSlice->listX[LIST_1+4][0]->mv_info[(currMB->block_y_aff + j0)>>1][i0]; + if (!currMB->mb_field && + ((currSlice->listX[LIST_1][0]->iCodingType == + FRAME_MB_PAIR_CODING && + currSlice->listX[LIST_1][0] + ->motion.mb_field[currMB->mbAddrX]) || + (currSlice->listX[LIST_1][0]->iCodingType == + FIELD_CODING))) { + if (iabs(dec_picture->poc - + currSlice->listX[LIST_1 + 4][0]->poc) > + iabs(dec_picture->poc - + currSlice->listX[LIST_1 + 2][0]->poc)) { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &currSlice->listX[LIST_1 + 2][0] + ->mv_info[RSD(currMB->block_y_aff + j0) >> 1] + [RSD(i0)] + : &currSlice->listX[LIST_1 + 2][0] + ->mv_info[(currMB->block_y_aff + j0) >> 1][i0]; + } else { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &currSlice->listX[LIST_1 + 4][0] + ->mv_info[RSD(currMB->block_y_aff + j0) >> 1] + [RSD(i0)] + : &currSlice->listX[LIST_1 + 4][0] + ->mv_info[(currMB->block_y_aff + j0) >> 1][i0]; } } - } - else if(!p_Vid->active_sps->frame_mbs_only_flag && !currSlice->field_pic_flag && currSlice->listX[LIST_1][0]->iCodingType != FRAME_CODING) - { - if (iabs(dec_picture->poc - list1[0]->bottom_field->poc)> iabs(dec_picture->poc -list1[0]->top_field->poc) ) - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->top_field->mv_info[RSD(currMB->block_y_aff + j0)>>1][RSD(i0)] : &list1[0]->top_field->mv_info[(currMB->block_y_aff + j0)>>1][i0]; + } else if (!p_Vid->active_sps->frame_mbs_only_flag && + !currSlice->field_pic_flag && + currSlice->listX[LIST_1][0]->iCodingType != + FRAME_CODING) { + if (iabs(dec_picture->poc - list1[0]->bottom_field->poc) > + iabs(dec_picture->poc - list1[0]->top_field->poc)) { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->top_field->mv_info + [RSD(currMB->block_y_aff + j0) >> 1][RSD(i0)] + : &list1[0] + ->top_field + ->mv_info[(currMB->block_y_aff + j0) >> 1][i0]; + } else { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->bottom_field->mv_info + [RSD(currMB->block_y_aff + j0) >> 1][RSD(i0)] + : &list1[0] + ->bottom_field + ->mv_info[(currMB->block_y_aff + j0) >> 1][i0]; } - else - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->bottom_field->mv_info[RSD(currMB->block_y_aff + j0)>>1][RSD(i0)] : &list1[0]->bottom_field->mv_info[(currMB->block_y_aff + j0)>>1][i0]; - } - } - else if(!p_Vid->active_sps->frame_mbs_only_flag && currSlice->field_pic_flag && currSlice->structure!=list1[0]->structure && list1[0]->coded_frame) - { - if (currSlice->structure == TOP_FIELD) - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->frame->top_field->mv_info[RSD(currMB->block_y_aff + j0)][RSD(i0)] : &list1[0]->frame->top_field->mv_info[currMB->block_y_aff + j0][i0]; - } - else - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->frame->bottom_field->mv_info[RSD(currMB->block_y_aff + j0)][RSD(i0)] : &list1[0]->frame->bottom_field->mv_info[currMB->block_y_aff + j0][i0]; + } else if (!p_Vid->active_sps->frame_mbs_only_flag && + currSlice->field_pic_flag && + currSlice->structure != list1[0]->structure && + list1[0]->coded_frame) { + if (currSlice->structure == TOP_FIELD) { + colocated = p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->frame->top_field->mv_info[RSD( + currMB->block_y_aff + j0)][RSD(i0)] + : &list1[0] + ->frame->top_field + ->mv_info[currMB->block_y_aff + j0][i0]; + } else { + colocated = p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->frame->bottom_field->mv_info[RSD( + currMB->block_y_aff + j0)][RSD(i0)] + : &list1[0] + ->frame->bottom_field + ->mv_info[currMB->block_y_aff + j0][i0]; } } - refList = colocated->ref_idx[LIST_0 ]== -1 ? LIST_1 : LIST_0; + refList = colocated->ref_idx[LIST_0] == -1 ? LIST_1 : LIST_0; ref_idx = colocated->ref_idx[refList]; - if (ref_idx == -1) - { - for (j4 = currMB->block_y + j0; j4 < currMB->block_y + j0 + step_v0; ++j4) - { - for (i4 = i0; i4 < i0 + step_h0; ++i4) - { + if (ref_idx == -1) { + for (j4 = currMB->block_y + j0; + j4 < currMB->block_y + j0 + step_v0; ++j4) { + for (i4 = i0; i4 < i0 + step_h0; ++i4) { PicMotionParams *mv_info = &dec_picture->mv_info[j4][i4]; mv_info->ref_pic[LIST_0] = list0[0]; mv_info->ref_pic[LIST_1] = list1[0]; - mv_info->mv [LIST_0] = zero_mv; - mv_info->mv [LIST_1] = zero_mv; - mv_info->ref_idx [LIST_0] = 0; - mv_info->ref_idx [LIST_1] = 0; + mv_info->mv[LIST_0] = zero_mv; + mv_info->mv[LIST_1] = zero_mv; + mv_info->ref_idx[LIST_0] = 0; + mv_info->ref_idx[LIST_1] = 0; } } - } - else - { - if( (currSlice->mb_aff_frame_flag && ( (currMB->mb_field && colocated->ref_pic[refList]->structure==FRAME) || - (!currMB->mb_field && colocated->ref_pic[refList]->structure!=FRAME))) || - (!currSlice->mb_aff_frame_flag && ((currSlice->field_pic_flag==0 && colocated->ref_pic[refList]->structure!=FRAME)|| - (currSlice->field_pic_flag==1 && colocated->ref_pic[refList]->structure==FRAME))) ) - { + } else { + if ((currSlice->mb_aff_frame_flag && + ((currMB->mb_field && + colocated->ref_pic[refList]->structure == FRAME) || + (!currMB->mb_field && + colocated->ref_pic[refList]->structure != FRAME))) || + (!currSlice->mb_aff_frame_flag && + ((currSlice->field_pic_flag == 0 && + colocated->ref_pic[refList]->structure != FRAME) || + (currSlice->field_pic_flag == 1 && + colocated->ref_pic[refList]->structure == FRAME)))) { //! Frame with field co-located - for (iref = 0; iref < imin(currSlice->num_ref_idx_active[LIST_0], currSlice->listXsize[LIST_0 + list_offset]); ++iref) - { - if (currSlice->listX[LIST_0 + list_offset][iref]->top_field == colocated->ref_pic[refList] || - currSlice->listX[LIST_0 + list_offset][iref]->bottom_field == colocated->ref_pic[refList] || - currSlice->listX[LIST_0 + list_offset][iref]->frame == colocated->ref_pic[refList] ) - { - mapped_idx=iref; + for (iref = 0; + iref < imin(currSlice->num_ref_idx_active[LIST_0], + currSlice->listXsize[LIST_0 + list_offset]); + ++iref) { + if (currSlice->listX[LIST_0 + list_offset][iref]->top_field == + colocated->ref_pic[refList] || + currSlice->listX[LIST_0 + list_offset][iref] + ->bottom_field == colocated->ref_pic[refList] || + currSlice->listX[LIST_0 + list_offset][iref]->frame == + colocated->ref_pic[refList]) { + mapped_idx = iref; break; - } - else //! invalid index. Default to zero even though this case should not happen - mapped_idx=INVALIDINDEX; + } else //! invalid index. Default to zero even though this + //! case should not happen + mapped_idx = INVALIDINDEX; } - } - else - { - for (iref = 0; iref < imin(currSlice->num_ref_idx_active[LIST_0], currSlice->listXsize[LIST_0 + list_offset]); ++iref) - { - if (currSlice->listX[LIST_0 + list_offset][iref] == colocated->ref_pic[refList]) - { - mapped_idx=iref; + } else { + for (iref = 0; + iref < imin(currSlice->num_ref_idx_active[LIST_0], + currSlice->listXsize[LIST_0 + list_offset]); + ++iref) { + if (currSlice->listX[LIST_0 + list_offset][iref] == + colocated->ref_pic[refList]) { + mapped_idx = iref; break; - } - else //! invalid index. Default to zero even though this case should not happen - mapped_idx=INVALIDINDEX; + } else //! invalid index. Default to zero even though this + //! case should not happen + mapped_idx = INVALIDINDEX; } } - if (mapped_idx != INVALIDINDEX) - { - for (j = j0; j < j0 + step_v0; ++j) - { + if (mapped_idx != INVALIDINDEX) { + for (j = j0; j < j0 + step_v0; ++j) { j4 = currMB->block_y + j; j6 = currMB->block_y_aff + j; - for (i4 = i0; i4 < i0 + step_h0; ++i4) - { - PicMotionParams *colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->mv_info[RSD(j6)][RSD(i4)] : &list1[0]->mv_info[j6][i4]; + for (i4 = i0; i4 < i0 + step_h0; ++i4) { + PicMotionParams *colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->mv_info[RSD(j6)][RSD(i4)] + : &list1[0]->mv_info[j6][i4]; PicMotionParams *mv_info = &dec_picture->mv_info[j4][i4]; int mv_y; if(currSlice->mb_aff_frame_flag /*&& (!p_Vid->active_sps->frame_mbs_only_flag || p_Vid->active_sps->direct_8x8_inference_flag)*/) { - if(!currMB->mb_field && ((currSlice->listX[LIST_1][0]->iCodingType==FRAME_MB_PAIR_CODING && currSlice->listX[LIST_1][0]->motion.mb_field[currMB->mbAddrX]) || - (currSlice->listX[LIST_1][0]->iCodingType==FIELD_CODING))) - { - if (iabs(dec_picture->poc - currSlice->listX[LIST_1+4][0]->poc)> iabs(dec_picture->poc -currSlice->listX[LIST_1+2][0]->poc) ) - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &currSlice->listX[LIST_1+2][0]->mv_info[RSD(j6)>>1][RSD(i4)] : &currSlice->listX[LIST_1+2][0]->mv_info[j6>>1][i4]; - } - else - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &currSlice->listX[LIST_1+4][0]->mv_info[RSD(j6)>>1][RSD(i4)] : &currSlice->listX[LIST_1+4][0]->mv_info[j6>>1][i4]; + if (!currMB->mb_field && + ((currSlice->listX[LIST_1][0]->iCodingType == + FRAME_MB_PAIR_CODING && + currSlice->listX[LIST_1][0] + ->motion.mb_field[currMB->mbAddrX]) || + (currSlice->listX[LIST_1][0]->iCodingType == + FIELD_CODING))) { + if (iabs(dec_picture->poc - + currSlice->listX[LIST_1 + 4][0]->poc) > + iabs(dec_picture->poc - + currSlice->listX[LIST_1 + 2][0]->poc)) { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &currSlice->listX[LIST_1 + 2][0] + ->mv_info[RSD(j6) >> 1][RSD(i4)] + : &currSlice->listX[LIST_1 + 2][0] + ->mv_info[j6 >> 1][i4]; + } else { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &currSlice->listX[LIST_1 + 4][0] + ->mv_info[RSD(j6) >> 1][RSD(i4)] + : &currSlice->listX[LIST_1 + 4][0] + ->mv_info[j6 >> 1][i4]; } } - } - else if(/*!currSlice->mb_aff_frame_flag &&*/ !p_Vid->active_sps->frame_mbs_only_flag && !currSlice->field_pic_flag && currSlice->listX[LIST_1][0]->iCodingType!=FRAME_CODING) - { - if (iabs(dec_picture->poc - list1[0]->bottom_field->poc)> iabs(dec_picture->poc -list1[0]->top_field->poc) ) - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->top_field->mv_info[RSD(j6)>>1][RSD(i4)] : &list1[0]->top_field->mv_info[(j6)>>1][i4]; + } else if (/*!currSlice->mb_aff_frame_flag &&*/ !p_Vid + ->active_sps->frame_mbs_only_flag && + !currSlice->field_pic_flag && + currSlice->listX[LIST_1][0]->iCodingType != + FRAME_CODING) { + if (iabs(dec_picture->poc - list1[0]->bottom_field->poc) > + iabs(dec_picture->poc - list1[0]->top_field->poc)) { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->top_field->mv_info[RSD(j6) >> 1] + [RSD(i4)] + : &list1[0]->top_field->mv_info[(j6) >> 1][i4]; + } else { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->bottom_field->mv_info[RSD(j6) >> 1] + [RSD(i4)] + : &list1[0] + ->bottom_field->mv_info[(j6) >> 1][i4]; } - else - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->bottom_field->mv_info[RSD(j6)>>1][RSD(i4)] : &list1[0]->bottom_field->mv_info[(j6)>>1][i4]; - } - } - else if(!p_Vid->active_sps->frame_mbs_only_flag && currSlice->field_pic_flag && currSlice->structure!=list1[0]->structure && list1[0]->coded_frame) - { - if (currSlice->structure == TOP_FIELD) - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->frame->top_field->mv_info[RSD(j6)][RSD(i4)] : &list1[0]->frame->top_field->mv_info[j6][i4]; - } - else - { - colocated = p_Vid->active_sps->direct_8x8_inference_flag ? - &list1[0]->frame->bottom_field->mv_info[RSD(j6)][RSD(i4)] : &list1[0]->frame->bottom_field->mv_info[j6][i4]; + } else if (!p_Vid->active_sps->frame_mbs_only_flag && + currSlice->field_pic_flag && + currSlice->structure != list1[0]->structure && + list1[0]->coded_frame) { + if (currSlice->structure == TOP_FIELD) { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->frame->top_field->mv_info[RSD(j6)] + [RSD(i4)] + : &list1[0]->frame->top_field->mv_info[j6][i4]; + } else { + colocated = + p_Vid->active_sps->direct_8x8_inference_flag + ? &list1[0]->frame->bottom_field->mv_info[RSD( + j6)][RSD(i4)] + : &list1[0] + ->frame->bottom_field->mv_info[j6][i4]; } } - mv_y = colocated->mv[refList].mv_y; - if((currSlice->mb_aff_frame_flag && !currMB->mb_field && colocated->ref_pic[refList]->structure!=FRAME) || - (!currSlice->mb_aff_frame_flag && currSlice->field_pic_flag==0 && colocated->ref_pic[refList]->structure!=FRAME)) + mv_y = colocated->mv[refList].mv_y; + if ((currSlice->mb_aff_frame_flag && !currMB->mb_field && + colocated->ref_pic[refList]->structure != FRAME) || + (!currSlice->mb_aff_frame_flag && + currSlice->field_pic_flag == 0 && + colocated->ref_pic[refList]->structure != FRAME)) mv_y *= 2; - else if((currSlice->mb_aff_frame_flag && currMB->mb_field && colocated->ref_pic[refList]->structure==FRAME) || - (!currSlice->mb_aff_frame_flag && currSlice->field_pic_flag==1 && colocated->ref_pic[refList]->structure==FRAME)) + else if ((currSlice->mb_aff_frame_flag && + currMB->mb_field && + colocated->ref_pic[refList]->structure == + FRAME) || + (!currSlice->mb_aff_frame_flag && + currSlice->field_pic_flag == 1 && + colocated->ref_pic[refList]->structure == FRAME)) mv_y /= 2; - mv_scale = currSlice->mvscale[LIST_0 + list_offset][mapped_idx]; + mv_scale = + currSlice->mvscale[LIST_0 + list_offset][mapped_idx]; - mv_info->ref_idx [LIST_0] = (signed char) mapped_idx; - mv_info->ref_idx [LIST_1] = 0; + mv_info->ref_idx[LIST_0] = (signed char)mapped_idx; + mv_info->ref_idx[LIST_1] = 0; mv_info->ref_pic[LIST_0] = list0[mapped_idx]; mv_info->ref_pic[LIST_1] = list1[0]; - if (mv_scale == 9999 || currSlice->listX[LIST_0+list_offset][mapped_idx]->is_long_term) - { + if (mv_scale == 9999 || + currSlice->listX[LIST_0 + list_offset][mapped_idx] + ->is_long_term) { mv_info->mv[LIST_0].mv_x = colocated->mv[refList].mv_x; - mv_info->mv[LIST_0].mv_y = (short) mv_y; + mv_info->mv[LIST_0].mv_y = (short)mv_y; mv_info->mv[LIST_1] = zero_mv; - } - else - { - mv_info->mv[LIST_0].mv_x = (short) ((mv_scale * colocated->mv[refList].mv_x + 128 ) >> 8); - mv_info->mv[LIST_0].mv_y = (short) ((mv_scale * mv_y/*colocated->mv[refList].mv_y*/ + 128 ) >> 8); - mv_info->mv[LIST_1].mv_x = (short) (mv_info->mv[LIST_0].mv_x - colocated->mv[refList].mv_x); - mv_info->mv[LIST_1].mv_y = (short) (mv_info->mv[LIST_0].mv_y - mv_y/*colocated->mv[refList].mv_y*/); + } else { + mv_info->mv[LIST_0].mv_x = + (short)((mv_scale * colocated->mv[refList].mv_x + + 128) >> + 8); + mv_info->mv[LIST_0].mv_y = + (short)((mv_scale * + mv_y /*colocated->mv[refList].mv_y*/ + + 128) >> + 8); + mv_info->mv[LIST_1].mv_x = + (short)(mv_info->mv[LIST_0].mv_x - + colocated->mv[refList].mv_x); + mv_info->mv[LIST_1].mv_y = + (short)(mv_info->mv[LIST_0].mv_y - + mv_y /*colocated->mv[refList].mv_y*/); } } } - } - else if (INVALIDINDEX == mapped_idx) - { - error("temporal direct error: colocated block has ref that is unavailable",-1111); + } else if (INVALIDINDEX == mapped_idx) { + error("temporal direct error: colocated block has ref that is " + "unavailable", + -1111); } } } } } - } + } } } - -static inline void update_neighbor_mvs(PicMotionParams **motion, const PicMotionParams *mv_info, int i4) -{ +static inline void update_neighbor_mvs(PicMotionParams **motion, + const PicMotionParams *mv_info, int i4) { (*motion++)[i4 + 1] = *mv_info; - (*motion )[i4 ] = *mv_info; - (*motion )[i4 + 1] = *mv_info; + (*motion)[i4] = *mv_info; + (*motion)[i4 + 1] = *mv_info; } /*! ************************************************************************************* * \brief -* Colocated info <= direct_inference is disabled. +* Colocated info <= direct_inference is disabled. ************************************************************************************* */ -int get_colocated_info_4x4(Macroblock *currMB, StorablePicture *list1, int i, int j) -{ +int get_colocated_info_4x4(Macroblock *currMB, StorablePicture *list1, int i, + int j) { if (list1->is_long_term) return 1; - else - { + else { PicMotionParams *fs = &list1->mv_info[j][i]; - int moving = !((( - (fs->ref_idx[LIST_0] == 0) - && (iabs(fs->mv[LIST_0].mv_x)>>1 == 0) - && (iabs(fs->mv[LIST_0].mv_y)>>1 == 0))) - || ((fs->ref_idx[LIST_0] == -1) - && (fs->ref_idx[LIST_1] == 0) - && (iabs(fs->mv[LIST_1].mv_x)>>1 == 0) - && (iabs(fs->mv[LIST_1].mv_y)>>1 == 0))); + int moving = !( + (((fs->ref_idx[LIST_0] == 0) && (iabs(fs->mv[LIST_0].mv_x) >> 1 == 0) && + (iabs(fs->mv[LIST_0].mv_y) >> 1 == 0))) || + ((fs->ref_idx[LIST_0] == -1) && (fs->ref_idx[LIST_1] == 0) && + (iabs(fs->mv[LIST_1].mv_x) >> 1 == 0) && + (iabs(fs->mv[LIST_1].mv_y) >> 1 == 0))); - return moving; + return moving; } } /*! ************************************************************************************* * \brief -* Temporary function for colocated info when direct_inference is enabled. Will be replaced with -* function that will access directly motion information +* Temporary function for colocated info when direct_inference is enabled. +*Will be replaced with function that will access directly motion information ************************************************************************************* */ -int get_colocated_info_8x8(Macroblock *currMB, StorablePicture *list1, int i, int j) -{ +int get_colocated_info_8x8(Macroblock *currMB, StorablePicture *list1, int i, + int j) { if (list1->is_long_term) return 1; - else - { + else { Slice *currSlice = currMB->p_Slice; VideoParameters *p_Vid = currMB->p_Vid; - if( (currSlice->mb_aff_frame_flag) || - (!p_Vid->active_sps->frame_mbs_only_flag && ((!currSlice->structure && list1->iCodingType == FIELD_CODING)||(currSlice->structure!=list1->structure && list1->coded_frame)))) - { + if ((currSlice->mb_aff_frame_flag) || + (!p_Vid->active_sps->frame_mbs_only_flag && + ((!currSlice->structure && list1->iCodingType == FIELD_CODING) || + (currSlice->structure != list1->structure && list1->coded_frame)))) { int jj = RSD(j); int ii = RSD(i); - int jdiv = (jj>>1); + int jdiv = (jj >> 1); int moving; PicMotionParams *fs = &list1->mv_info[jj][ii]; - if(currSlice->field_pic_flag && currSlice->structure!=list1->structure && list1->coded_frame) - { - if(currSlice->structure == TOP_FIELD) - fs = list1->top_field->mv_info[jj] + ii; - else - fs = list1->bottom_field->mv_info[jj] + ii; - } - else - { - if( (currSlice->mb_aff_frame_flag && ((!currMB->mb_field && list1->motion.mb_field[currMB->mbAddrX]) || - (!currMB->mb_field && list1->iCodingType == FIELD_CODING))) - || (!currSlice->mb_aff_frame_flag)) - { - if (iabs(currSlice->dec_picture->poc - list1->bottom_field->poc)> iabs(currSlice->dec_picture->poc -list1->top_field->poc) ) - { + if (currSlice->field_pic_flag && + currSlice->structure != list1->structure && list1->coded_frame) { + if (currSlice->structure == TOP_FIELD) + fs = list1->top_field->mv_info[jj] + ii; + else + fs = list1->bottom_field->mv_info[jj] + ii; + } else { + if ((currSlice->mb_aff_frame_flag && + ((!currMB->mb_field && list1->motion.mb_field[currMB->mbAddrX]) || + (!currMB->mb_field && list1->iCodingType == FIELD_CODING))) || + (!currSlice->mb_aff_frame_flag)) { + if (iabs(currSlice->dec_picture->poc - list1->bottom_field->poc) > + iabs(currSlice->dec_picture->poc - list1->top_field->poc)) { fs = list1->top_field->mv_info[jdiv] + ii; - } - else - { + } else { fs = list1->bottom_field->mv_info[jdiv] + ii; } } } - moving = !((((fs->ref_idx[LIST_0] == 0) - && (iabs(fs->mv[LIST_0].mv_x)>>1 == 0) - && (iabs(fs->mv[LIST_0].mv_y)>>1 == 0))) - || ((fs->ref_idx[LIST_0] == -1) - && (fs->ref_idx[LIST_1] == 0) - && (iabs(fs->mv[LIST_1].mv_x)>>1 == 0) - && (iabs(fs->mv[LIST_1].mv_y)>>1 == 0))); + moving = !((((fs->ref_idx[LIST_0] == 0) && + (iabs(fs->mv[LIST_0].mv_x) >> 1 == 0) && + (iabs(fs->mv[LIST_0].mv_y) >> 1 == 0))) || + ((fs->ref_idx[LIST_0] == -1) && (fs->ref_idx[LIST_1] == 0) && + (iabs(fs->mv[LIST_1].mv_x) >> 1 == 0) && + (iabs(fs->mv[LIST_1].mv_y) >> 1 == 0))); return moving; - } - else - { + } else { PicMotionParams *fs = &list1->mv_info[RSD(j)][RSD(i)]; int moving; - if(currMB->p_Vid->separate_colour_plane_flag && currMB->p_Vid->yuv_format==YUV444) - fs = &list1->JVmv_info[currMB->p_Slice->colour_plane_id][RSD(j)][RSD(i)]; - moving= !((((fs->ref_idx[LIST_0] == 0) - && (iabs(fs->mv[LIST_0].mv_x)>>1 == 0) - && (iabs(fs->mv[LIST_0].mv_y)>>1 == 0))) - || ((fs->ref_idx[LIST_0] == -1) - && (fs->ref_idx[LIST_1] == 0) - && (iabs(fs->mv[LIST_1].mv_x)>>1 == 0) - && (iabs(fs->mv[LIST_1].mv_y)>>1 == 0))); - return moving; + if (currMB->p_Vid->separate_colour_plane_flag && + currMB->p_Vid->yuv_format == YUV444) + fs = + &list1->JVmv_info[currMB->p_Slice->colour_plane_id][RSD(j)][RSD(i)]; + moving = !((((fs->ref_idx[LIST_0] == 0) && + (iabs(fs->mv[LIST_0].mv_x) >> 1 == 0) && + (iabs(fs->mv[LIST_0].mv_y) >> 1 == 0))) || + ((fs->ref_idx[LIST_0] == -1) && (fs->ref_idx[LIST_1] == 0) && + (iabs(fs->mv[LIST_1].mv_x) >> 1 == 0) && + (iabs(fs->mv[LIST_1].mv_y) >> 1 == 0))); + return moving; } } } +static void update_direct_mv_info_spatial_8x8(Macroblock *currMB) { + Boolean has_direct = (currMB->b8mode[0] == 0) | (currMB->b8mode[1] == 0) | + (currMB->b8mode[2] == 0) | (currMB->b8mode[3] == 0); -static void update_direct_mv_info_spatial_8x8(Macroblock *currMB) -{ - Boolean has_direct = (currMB->b8mode[0] == 0) | (currMB->b8mode[1] == 0) | (currMB->b8mode[2] == 0) | (currMB->b8mode[3] == 0); - - if (has_direct) - { - //VideoParameters *p_Vid = currMB->p_Vid; + if (has_direct) { + // VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; - int i,j,k; + int i, j, k; int j4, i4; StorablePicture *dec_picture = currSlice->dec_picture; - int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? (mb_nr&0x01) ? 4 : 2 : 0; + int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? + // (mb_nr&0x01) ? 4 : 2 : 0; StorablePicture **list0 = currSlice->listX[LIST_0 + list_offset]; StorablePicture **list1 = currSlice->listX[LIST_1 + list_offset]; - signed char l0_rFrame, l1_rFrame; + signed char l0_rFrame, l1_rFrame; MotionVector pmvl0, pmvl1; int is_not_moving; PicMotionParams *mv_info = NULL; - prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, &l1_rFrame); + prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, + &l1_rFrame); - for (k = 0; k < 4; ++k) - { - if (currMB->b8mode[k] == 0) - { + for (k = 0; k < 4; ++k) { + if (currMB->b8mode[k] == 0) { i = 2 * (k & 0x01); j = 2 * (k >> 1); - //j6 = currMB->block_y_aff + j; - j4 = currMB->block_y + j; - i4 = currMB->block_x + i; + // j6 = currMB->block_y_aff + j; + j4 = currMB->block_y + j; + i4 = currMB->block_x + i; mv_info = &dec_picture->mv_info[j4][i4]; - is_not_moving = (get_colocated_info_8x8(currMB, list1[0], i4, currMB->block_y_aff + j) == 0); + is_not_moving = (get_colocated_info_8x8(currMB, list1[0], i4, + currMB->block_y_aff + j) == 0); - if (is_not_moving && (l0_rFrame == 0 || l1_rFrame == 0)) - { - if (l1_rFrame == -1) - { - if (l0_rFrame == 0) - { + if (is_not_moving && (l0_rFrame == 0 || l1_rFrame == 0)) { + if (l1_rFrame == -1) { + if (l0_rFrame == 0) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; mv_info->ref_idx[LIST_1] = -1; - } - else - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + } else { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = pmvl0; - mv_info->mv[LIST_1] = zero_mv; + mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = l0_rFrame; mv_info->ref_idx[LIST_1] = -1; } - } - else if (l0_rFrame == -1) - { - if (l1_rFrame == 0) - { + } else if (l0_rFrame == -1) { + if (l1_rFrame == 0) { mv_info->ref_pic[LIST_0] = NULL; mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_0] = zero_mv; - mv_info->mv[LIST_1] = zero_mv; + mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = 0; - } - else - { + } else { mv_info->ref_pic[LIST_0] = NULL; - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_0] = zero_mv; - mv_info->mv[LIST_1] = pmvl1; + mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = l1_rFrame; } - } - else - { - if (l0_rFrame == 0) - { + } else { + if (l0_rFrame == 0) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->ref_idx[LIST_0] = 0; - } - else - { - mv_info->ref_pic[LIST_1] = list1[(short) l0_rFrame]; + } else { + mv_info->ref_pic[LIST_1] = list1[(short)l0_rFrame]; mv_info->mv[LIST_0] = pmvl0; mv_info->ref_idx[LIST_0] = l0_rFrame; } - if (l1_rFrame == 0) - { + if (l1_rFrame == 0) { mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_1] = 0; - } - else - { - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + } else { + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_1] = l1_rFrame; } } - } - else - { - if (l0_rFrame < 0 && l1_rFrame < 0) - { + } else { + if (l0_rFrame < 0 && l1_rFrame < 0) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; mv_info->ref_idx[LIST_1] = 0; - } - else if (l0_rFrame < 0) - { + } else if (l0_rFrame < 0) { mv_info->ref_pic[LIST_0] = NULL; - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = l1_rFrame; - } - else if (l1_rFrame < 0) - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + } else if (l1_rFrame < 0) { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = l0_rFrame; mv_info->ref_idx[LIST_1] = -1; - } - else - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + } else { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = l0_rFrame; mv_info->ref_idx[LIST_1] = l1_rFrame; } } - update_neighbor_mvs(&dec_picture->mv_info[j4], mv_info, i4); + update_neighbor_mvs(&dec_picture->mv_info[j4], mv_info, i4); } } } } -static void update_direct_mv_info_spatial_4x4(Macroblock *currMB) -{ - Boolean has_direct = (currMB->b8mode[0] == 0) | (currMB->b8mode[1] == 0) | (currMB->b8mode[2] == 0) | (currMB->b8mode[3] == 0); +static void update_direct_mv_info_spatial_4x4(Macroblock *currMB) { + Boolean has_direct = (currMB->b8mode[0] == 0) | (currMB->b8mode[1] == 0) | + (currMB->b8mode[2] == 0) | (currMB->b8mode[3] == 0); - if (has_direct) - { + if (has_direct) { VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; - int i,j,k; + int i, j, k; int j6; int j4, i4; StorablePicture *dec_picture = p_Vid->dec_picture; - int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? (mb_nr&0x01) ? 4 : 2 : 0; + int list_offset = currMB->list_offset; // ((currSlice->mb_aff_frame_flag)&&(currMB->mb_field))? + // (mb_nr&0x01) ? 4 : 2 : 0; StorablePicture **list0 = currSlice->listX[LIST_0 + list_offset]; StorablePicture **list1 = currSlice->listX[LIST_1 + list_offset]; - signed char l0_rFrame, l1_rFrame; + signed char l0_rFrame, l1_rFrame; MotionVector pmvl0, pmvl1; - prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, &l1_rFrame); - for (k = 0; k < 4; ++k) - { - if (currMB->b8mode[k] == 0) - { + prepare_direct_params(currMB, dec_picture, &pmvl0, &pmvl1, &l0_rFrame, + &l1_rFrame); + for (k = 0; k < 4; ++k) { + if (currMB->b8mode[k] == 0) { i = 2 * (k & 0x01); - for(j = 2 * (k >> 1); j < 2 * (k >> 1)+2;++j) - { + for (j = 2 * (k >> 1); j < 2 * (k >> 1) + 2; ++j) { j6 = currMB->block_y_aff + j; - j4 = currMB->block_y + j; + j4 = currMB->block_y + j; - for(i4 = currMB->block_x + i; i4 < currMB->block_x + i + 2; ++i4) - { + for (i4 = currMB->block_x + i; i4 < currMB->block_x + i + 2; ++i4) { PicMotionParams *mv_info = &dec_picture->mv_info[j4][i4]; - //===== DIRECT PREDICTION ===== - if (l0_rFrame == 0 || l1_rFrame == 0) - { - int is_not_moving = (get_colocated_info_4x4(currMB, list1[0], i4, currMB->block_y_aff + j) == 0); + //===== DIRECT PREDICTION ===== + if (l0_rFrame == 0 || l1_rFrame == 0) { + int is_not_moving = + (get_colocated_info_4x4(currMB, list1[0], i4, + currMB->block_y_aff + j) == 0); - if (l1_rFrame == -1) - { - if (is_not_moving) - { + if (l1_rFrame == -1) { + if (is_not_moving) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; mv_info->ref_idx[LIST_1] = -1; - } - else - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + } else { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = l0_rFrame; mv_info->ref_idx[LIST_1] = -1; } - } - else if (l0_rFrame == -1) - { - if (is_not_moving) - { + } else if (l0_rFrame == -1) { + if (is_not_moving) { mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = 0; - } - else - { - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; - mv_info->mv[LIST_0] = zero_mv; + } else { + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; + mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = l1_rFrame; } - } - else - { - if (l0_rFrame == 0 && ((is_not_moving))) - { + } else { + if (l0_rFrame == 0 && ((is_not_moving))) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->ref_idx[LIST_0] = 0; - } - else - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + } else { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->mv[LIST_0] = pmvl0; mv_info->ref_idx[LIST_0] = l0_rFrame; } - if (l1_rFrame == 0 && ((is_not_moving))) - { + if (l1_rFrame == 0 && ((is_not_moving))) { mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_1] = zero_mv; - mv_info->ref_idx[LIST_1] = 0; - } - else - { - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_idx[LIST_1] = 0; + } else { + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_1] = pmvl1; - mv_info->ref_idx[LIST_1] = l1_rFrame; - } + mv_info->ref_idx[LIST_1] = l1_rFrame; + } } - } - else - { + } else { mv_info = &dec_picture->mv_info[j4][i4]; - if (l0_rFrame < 0 && l1_rFrame < 0) - { + if (l0_rFrame < 0 && l1_rFrame < 0) { mv_info->ref_pic[LIST_0] = list0[0]; mv_info->ref_pic[LIST_1] = list1[0]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = 0; mv_info->ref_idx[LIST_1] = 0; - } - else if (l1_rFrame == -1) - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; + } else if (l1_rFrame == -1) { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; mv_info->ref_pic[LIST_1] = NULL; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = zero_mv; mv_info->ref_idx[LIST_0] = l0_rFrame; mv_info->ref_idx[LIST_1] = -1; - } - else if (l0_rFrame == -1) - { + } else if (l0_rFrame == -1) { mv_info->ref_pic[LIST_0] = NULL; - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_0] = zero_mv; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = -1; mv_info->ref_idx[LIST_1] = l1_rFrame; - } - else - { - mv_info->ref_pic[LIST_0] = list0[(short) l0_rFrame]; - mv_info->ref_pic[LIST_1] = list1[(short) l1_rFrame]; + } else { + mv_info->ref_pic[LIST_0] = list0[(short)l0_rFrame]; + mv_info->ref_pic[LIST_1] = list1[(short)l1_rFrame]; mv_info->mv[LIST_0] = pmvl0; mv_info->mv[LIST_1] = pmvl1; mv_info->ref_idx[LIST_0] = l0_rFrame; - mv_info->ref_idx[LIST_1] = l1_rFrame; + mv_info->ref_idx[LIST_1] = l1_rFrame; } } } } } - } + } } } - -void update_direct_types(Slice *currSlice) -{ +void update_direct_types(Slice *currSlice) { if (currSlice->active_sps->direct_8x8_inference_flag) - currSlice->update_direct_mv_info = currSlice->direct_spatial_mv_pred_flag ? update_direct_mv_info_spatial_8x8 : update_direct_mv_info_temporal; + currSlice->update_direct_mv_info = currSlice->direct_spatial_mv_pred_flag + ? update_direct_mv_info_spatial_8x8 + : update_direct_mv_info_temporal; else - currSlice->update_direct_mv_info = currSlice->direct_spatial_mv_pred_flag ? update_direct_mv_info_spatial_4x4 : update_direct_mv_info_temporal; + currSlice->update_direct_mv_info = currSlice->direct_spatial_mv_pred_flag + ? update_direct_mv_info_spatial_4x4 + : update_direct_mv_info_temporal; } diff --git a/src/common/ldecod_src/mc_prediction.c b/src/common/ldecod_src/mc_prediction.c index fbaea5e..795afac 100644 --- a/src/common/ldecod_src/mc_prediction.c +++ b/src/common/ldecod_src/mc_prediction.c @@ -7,35 +7,37 @@ * Functions for motion compensated prediction * * \author - * Main contributors (see contributors.h for copyright, + * Main contributors (see contributors.h for copyright, * address and affiliation details) * - Alexis Michael Tourapis * - Chris Vogt * ************************************************************************************* */ -#include "global.h" -#include "block.h" #include "mc_prediction.h" -#include "mbuffer.h" -#include "mb_access.h" +#include "block.h" +#include "global.h" #include "macroblock.h" +#include "mb_access.h" +#include "mbuffer.h" #include "memalloc.h" - -int allocate_pred_mem(Slice *currSlice) -{ +int allocate_pred_mem(Slice *currSlice) { int alloc_size = 0; - alloc_size += get_mem2Dpel(&currSlice->tmp_block_l0, MB_BLOCK_SIZE, MB_BLOCK_SIZE); - alloc_size += get_mem2Dpel(&currSlice->tmp_block_l1, MB_BLOCK_SIZE, MB_BLOCK_SIZE); - alloc_size += get_mem2Dpel(&currSlice->tmp_block_l2, MB_BLOCK_SIZE, MB_BLOCK_SIZE); - alloc_size += get_mem2Dpel(&currSlice->tmp_block_l3, MB_BLOCK_SIZE, MB_BLOCK_SIZE); - alloc_size += get_mem2Dint(&currSlice->tmp_res, MB_BLOCK_SIZE + 5, MB_BLOCK_SIZE + 5); + alloc_size += + get_mem2Dpel(&currSlice->tmp_block_l0, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + alloc_size += + get_mem2Dpel(&currSlice->tmp_block_l1, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + alloc_size += + get_mem2Dpel(&currSlice->tmp_block_l2, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + alloc_size += + get_mem2Dpel(&currSlice->tmp_block_l3, MB_BLOCK_SIZE, MB_BLOCK_SIZE); + alloc_size += + get_mem2Dint(&currSlice->tmp_res, MB_BLOCK_SIZE + 5, MB_BLOCK_SIZE + 5); return (alloc_size); } -void free_pred_mem(Slice *currSlice) -{ +void free_pred_mem(Slice *currSlice) { free_mem2Dint(currSlice->tmp_res); free_mem2Dpel(currSlice->tmp_block_l0); free_mem2Dpel(currSlice->tmp_block_l1); @@ -43,23 +45,22 @@ void free_pred_mem(Slice *currSlice) free_mem2Dpel(currSlice->tmp_block_l3); } -static const int COEF[6] = { 1, -5, 20, 20, -5, 1 }; +static const int COEF[6] = {1, -5, 20, 20, -5, 1}; /*! ************************************************************************ * \brief * block single list prediction ************************************************************************ */ -static void mc_prediction(imgpel **mb_pred, int ver_block_size, int hor_block_size, int ioff, imgpel **block) -{ +static void mc_prediction(imgpel **mb_pred, int ver_block_size, + int hor_block_size, int ioff, imgpel **block) { - int jj; - //int *r0 = (int *) &(mb_pred[0][ioff]); - //int *r1 = (int *) block[0]; + int jj; + // int *r0 = (int *) &(mb_pred[0][ioff]); + // int *r1 = (int *) block[0]; - for (jj = 0; jj < ver_block_size; jj++) - { - memcpy(&mb_pred[jj][ioff], block[jj], hor_block_size * sizeof(imgpel)); + for (jj = 0; jj < ver_block_size; jj++) { + memcpy(&mb_pred[jj][ioff], block[jj], hor_block_size * sizeof(imgpel)); } } @@ -69,83 +70,67 @@ static void mc_prediction(imgpel **mb_pred, int ver_block_size, int hor_block_si * block single list weighted prediction ************************************************************************ */ -static void weighted_mc_prediction(imgpel **mb_pred, - int ver_block_size, - int hor_block_size, - int ioff, - imgpel **block, - int wp_scale, - int wp_offset, - int weight_denom, - int color_clip) -{ +static void weighted_mc_prediction(imgpel **mb_pred, int ver_block_size, + int hor_block_size, int ioff, imgpel **block, + int wp_scale, int wp_offset, + int weight_denom, int color_clip) { int ii, jj; int result; - for(jj = 0; jj < ver_block_size; jj++) - { - for(ii = 0; ii < hor_block_size; ii++) - { - result = rshift_rnd((wp_scale * block[jj][ii]), weight_denom) + wp_offset; + for (jj = 0; jj < ver_block_size; jj++) { + for (ii = 0; ii < hor_block_size; ii++) { + result = rshift_rnd((wp_scale * block[jj][ii]), weight_denom) + wp_offset; mb_pred[jj][ii + ioff] = (imgpel)iClip3(0, color_clip, result); } } } - - /*! ************************************************************************ * \brief * block biprediction ************************************************************************ */ -static void bi_prediction(imgpel **mb_pred, - imgpel **block_l0, - imgpel **block_l1, - int ver_block_size, - int hor_block_size, - int ioff) -{ +static void bi_prediction(imgpel **mb_pred, imgpel **block_l0, + imgpel **block_l1, int ver_block_size, + int hor_block_size, int ioff) { imgpel *mpr = &mb_pred[0][ioff]; imgpel *b0 = block_l0[0]; imgpel *b1 = block_l1[0]; int ii, jj; int row_inc = MB_BLOCK_SIZE - hor_block_size; - for(jj = 0;jj < ver_block_size;jj++) - { - // unroll the loop - for(ii = 0; ii < hor_block_size; ii += 2) - { + for (jj = 0; jj < ver_block_size; jj++) { + // unroll the loop + for (ii = 0; ii < hor_block_size; ii += 2) { *(mpr++) = (imgpel)(((*(b0++) + *(b1++)) + 1) >> 1); *(mpr++) = (imgpel)(((*(b0++) + *(b1++)) + 1) >> 1); } mpr += row_inc; - b0 += row_inc; - b1 += row_inc; + b0 += row_inc; + b1 += row_inc; } } - - /*! ************************************************************************ * \brief * block weighted biprediction ************************************************************************ */ -static void weighted_bi_prediction(imgpel *mb_pred, imgpel *block_l0, imgpel *block_l1, int ver_block_size, int hor_block_size, - int wp_scale_l0, int wp_scale_l1, int wp_offset, int weight_denom, int color_clip) -{ +static void weighted_bi_prediction(imgpel *mb_pred, imgpel *block_l0, + imgpel *block_l1, int ver_block_size, + int hor_block_size, int wp_scale_l0, + int wp_scale_l1, int wp_offset, + int weight_denom, int color_clip) { int ii, jj, result; int row_inc = MB_BLOCK_SIZE - hor_block_size; - for(jj = 0; jj < ver_block_size; jj++) - { - for(ii=0;ii>5)); - *orig_line = (imgpel) ((*orig_line + *(cur_line++) + 1 ) >> 1); + *orig_line = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); + *orig_line = (imgpel)((*orig_line + *(cur_line++) + 1) >> 1); orig_line++; } } @@ -217,15 +200,14 @@ static void get_luma_10(imgpel **block, imgpel **cur_imgY, int ver_block_size, i * \brief * Half horizontal ************************************************************************ - */ -static void get_luma_20(imgpel **block, imgpel **cur_imgY, int ver_block_size, int hor_block_size, int x_pos , int max_imgpel_value) -{ + */ +static void get_luma_20(imgpel **block, imgpel **cur_imgY, int ver_block_size, + int hor_block_size, int x_pos, int max_imgpel_value) { imgpel *p0, *p1, *p2, *p3, *p4, *p5; imgpel *orig_line; int i, j; int result; - for (j = 0; j < ver_block_size; j++) - { + for (j = 0; j < ver_block_size; j++) { p0 = &cur_imgY[j][x_pos - 2]; p1 = p0 + 1; p2 = p1 + 1; @@ -234,11 +216,11 @@ static void get_luma_20(imgpel **block, imgpel **cur_imgY, int ver_block_size, i p5 = p4 + 1; orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *orig_line++ = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5)); + *orig_line++ = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); } } } @@ -248,16 +230,15 @@ static void get_luma_20(imgpel **block, imgpel **cur_imgY, int ver_block_size, i * \brief * Qpel (3,0) horizontal ************************************************************************ - */ -static void get_luma_30(imgpel **block, imgpel **cur_imgY, int ver_block_size, int hor_block_size, int x_pos , int max_imgpel_value) -{ + */ +static void get_luma_30(imgpel **block, imgpel **cur_imgY, int ver_block_size, + int hor_block_size, int x_pos, int max_imgpel_value) { imgpel *p0, *p1, *p2, *p3, *p4, *p5; imgpel *orig_line, *cur_line; int i, j; int result; - - for (j = 0; j < ver_block_size; j++) - { + + for (j = 0; j < ver_block_size; j++) { cur_line = &(cur_imgY[j][x_pos + 1]); p0 = &cur_imgY[j][x_pos - 2]; p1 = p0 + 1; @@ -265,14 +246,14 @@ static void get_luma_30(imgpel **block, imgpel **cur_imgY, int ver_block_size, i p3 = p2 + 1; p4 = p3 + 1; p5 = p4 + 1; - orig_line = block[j]; + orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *orig_line = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5)); - *orig_line = (imgpel) ((*orig_line + *(cur_line++) + 1 ) >> 1); + *orig_line = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); + *orig_line = (imgpel)((*orig_line + *(cur_line++) + 1) >> 1); orig_line++; } } @@ -283,18 +264,18 @@ static void get_luma_30(imgpel **block, imgpel **cur_imgY, int ver_block_size, i * \brief * Qpel vertical (0, 1) ************************************************************************ - */ -static void get_luma_01(imgpel **block, imgpel **cur_imgY, int ver_block_size, int hor_block_size, int x_pos, int shift_x, int max_imgpel_value) -{ + */ +static void get_luma_01(imgpel **block, imgpel **cur_imgY, int ver_block_size, + int hor_block_size, int x_pos, int shift_x, + int max_imgpel_value) { imgpel *p0, *p1, *p2, *p3, *p4, *p5; imgpel *orig_line, *cur_line; int i, j; int result; int jj = 0; - p0 = &(cur_imgY[ - 2][x_pos]); - for (j = 0; j < ver_block_size; j++) - { - p1 = p0 + shift_x; + p0 = &(cur_imgY[-2][x_pos]); + for (j = 0; j < ver_block_size; j++) { + p1 = p0 + shift_x; p2 = p1 + shift_x; p3 = p2 + shift_x; p4 = p3 + shift_x; @@ -302,70 +283,68 @@ static void get_luma_01(imgpel **block, imgpel **cur_imgY, int ver_block_size, i orig_line = block[j]; cur_line = &(cur_imgY[jj++][x_pos]); - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *orig_line = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5)); - *orig_line = (imgpel) ((*orig_line + *(cur_line++) + 1 ) >> 1); + *orig_line = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); + *orig_line = (imgpel)((*orig_line + *(cur_line++) + 1) >> 1); orig_line++; } p0 = p1 - hor_block_size; } } - /*! ************************************************************************ * \brief * Half vertical ************************************************************************ - */ -static void get_luma_02(imgpel **block, imgpel **cur_imgY, int ver_block_size, int hor_block_size, int x_pos, int shift_x, int max_imgpel_value) -{ + */ +static void get_luma_02(imgpel **block, imgpel **cur_imgY, int ver_block_size, + int hor_block_size, int x_pos, int shift_x, + int max_imgpel_value) { imgpel *p0, *p1, *p2, *p3, *p4, *p5; imgpel *orig_line; int i, j; int result; - p0 = &(cur_imgY[ - 2][x_pos]); - for (j = 0; j < ver_block_size; j++) - { - p1 = p0 + shift_x; + p0 = &(cur_imgY[-2][x_pos]); + for (j = 0; j < ver_block_size; j++) { + p1 = p0 + shift_x; p2 = p1 + shift_x; p3 = p2 + shift_x; p4 = p3 + shift_x; p5 = p4 + shift_x; orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *orig_line++ = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5)); + *orig_line++ = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); } p0 = p1 - hor_block_size; } } - /*! ************************************************************************ * \brief * Qpel vertical (0, 3) ************************************************************************ - */ -static void get_luma_03(imgpel **block, imgpel **cur_imgY, int ver_block_size, int hor_block_size, int x_pos, int shift_x, int max_imgpel_value) -{ + */ +static void get_luma_03(imgpel **block, imgpel **cur_imgY, int ver_block_size, + int hor_block_size, int x_pos, int shift_x, + int max_imgpel_value) { imgpel *p0, *p1, *p2, *p3, *p4, *p5; imgpel *orig_line, *cur_line; int i, j; int result; int jj = 1; - p0 = &(cur_imgY[ -2][x_pos]); - for (j = 0; j < ver_block_size; j++) - { - p1 = p0 + shift_x; + p0 = &(cur_imgY[-2][x_pos]); + for (j = 0; j < ver_block_size; j++) { + p1 = p0 + shift_x; p2 = p1 + shift_x; p3 = p2 + shift_x; p4 = p3 + shift_x; @@ -373,12 +352,12 @@ static void get_luma_03(imgpel **block, imgpel **cur_imgY, int ver_block_size, i orig_line = block[j]; cur_line = &(cur_imgY[jj++][x_pos]); - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *orig_line = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5)); - *orig_line = (imgpel) ((*orig_line + *(cur_line++) + 1 ) >> 1); + *orig_line = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); + *orig_line = (imgpel)((*orig_line + *(cur_line++) + 1) >> 1); orig_line++; } p0 = p1 - hor_block_size; @@ -390,40 +369,39 @@ static void get_luma_03(imgpel **block, imgpel **cur_imgY, int ver_block_size, i * \brief * Hpel horizontal, Qpel vertical (2, 1) ************************************************************************ - */ -static void get_luma_21(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ver_block_size, int hor_block_size, int x_pos, int max_imgpel_value) -{ + */ +static void get_luma_21(imgpel **block, imgpel **cur_imgY, int **tmp_res, + int ver_block_size, int hor_block_size, int x_pos, + int max_imgpel_value) { int i, j; /* Vertical & horizontal interpolation */ int *tmp_line; imgpel *p0, *p1, *p2, *p3, *p4, *p5; - int *x0, *x1, *x2, *x3, *x4, *x5; - imgpel *orig_line; - int result; + int *x0, *x1, *x2, *x3, *x4, *x5; + imgpel *orig_line; + int result; int jj = -2; - for (j = 0; j < ver_block_size + 5; j++) - { + for (j = 0; j < ver_block_size + 5; j++) { p0 = &cur_imgY[jj++][x_pos - 2]; p1 = p0 + 1; p2 = p1 + 1; p3 = p2 + 1; p4 = p3 + 1; - p5 = p4 + 1; - tmp_line = tmp_res[j]; + p5 = p4 + 1; + tmp_line = tmp_res[j]; - for (i = 0; i < hor_block_size; i++) - { - *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); } - } + } jj = 2; - for (j = 0; j < ver_block_size; j++) - { - tmp_line = tmp_res[jj++]; - x0 = tmp_res[j ]; + for (j = 0; j < ver_block_size; j++) { + tmp_line = tmp_res[jj++]; + x0 = tmp_res[j]; x1 = tmp_res[j + 1]; x2 = tmp_res[j + 2]; x3 = tmp_res[j + 3]; @@ -431,12 +409,15 @@ static void get_luma_21(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ve x5 = tmp_res[j + 5]; orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*x0++ + *x5++) - 5 * (*x1++ + *x4++) + 20 * (*x2++ + *x3++); + for (i = 0; i < hor_block_size; i++) { + result = (*x0++ + *x5++) - 5 * (*x1++ + *x4++) + 20 * (*x2++ + *x3++); - *orig_line = (imgpel) iClip1(max_imgpel_value, ((result + 512)>>10)); - *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((*(tmp_line++) + 16) >> 5)) + 1 )>> 1); + *orig_line = (imgpel)iClip1(max_imgpel_value, ((result + 512) >> 10)); + *orig_line = + (imgpel)((*orig_line + + iClip1(max_imgpel_value, ((*(tmp_line++) + 16) >> 5)) + + 1) >> + 1); orig_line++; } } @@ -447,38 +428,37 @@ static void get_luma_21(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ve * \brief * Hpel horizontal, Hpel vertical (2, 2) ************************************************************************ - */ -static void get_luma_22(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ver_block_size, int hor_block_size, int x_pos, int max_imgpel_value) -{ + */ +static void get_luma_22(imgpel **block, imgpel **cur_imgY, int **tmp_res, + int ver_block_size, int hor_block_size, int x_pos, + int max_imgpel_value) { int i, j; /* Vertical & horizontal interpolation */ int *tmp_line; imgpel *p0, *p1, *p2, *p3, *p4, *p5; - int *x0, *x1, *x2, *x3, *x4, *x5; - imgpel *orig_line; - int result; + int *x0, *x1, *x2, *x3, *x4, *x5; + imgpel *orig_line; + int result; - int jj = - 2; + int jj = -2; - for (j = 0; j < ver_block_size + 5; j++) - { + for (j = 0; j < ver_block_size + 5; j++) { p0 = &cur_imgY[jj++][x_pos - 2]; p1 = p0 + 1; p2 = p1 + 1; p3 = p2 + 1; p4 = p3 + 1; - p5 = p4 + 1; - tmp_line = tmp_res[j]; + p5 = p4 + 1; + tmp_line = tmp_res[j]; - for (i = 0; i < hor_block_size; i++) - { - *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); } } - for (j = 0; j < ver_block_size; j++) - { - x0 = tmp_res[j ]; + for (j = 0; j < ver_block_size; j++) { + x0 = tmp_res[j]; x1 = tmp_res[j + 1]; x2 = tmp_res[j + 2]; x3 = tmp_res[j + 3]; @@ -486,11 +466,10 @@ static void get_luma_22(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ve x5 = tmp_res[j + 5]; orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*x0++ + *x5++) - 5 * (*x1++ + *x4++) + 20 * (*x2++ + *x3++); + for (i = 0; i < hor_block_size; i++) { + result = (*x0++ + *x5++) - 5 * (*x1++ + *x4++) + 20 * (*x2++ + *x3++); - *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result + 512)>>10)); + *(orig_line++) = (imgpel)iClip1(max_imgpel_value, ((result + 512) >> 10)); } } } @@ -500,40 +479,39 @@ static void get_luma_22(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ve * \brief * Hpel horizontal, Qpel vertical (2, 3) ************************************************************************ - */ -static void get_luma_23(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ver_block_size, int hor_block_size, int x_pos, int max_imgpel_value) -{ + */ +static void get_luma_23(imgpel **block, imgpel **cur_imgY, int **tmp_res, + int ver_block_size, int hor_block_size, int x_pos, + int max_imgpel_value) { int i, j; /* Vertical & horizontal interpolation */ int *tmp_line; imgpel *p0, *p1, *p2, *p3, *p4, *p5; - int *x0, *x1, *x2, *x3, *x4, *x5; - imgpel *orig_line; - int result; + int *x0, *x1, *x2, *x3, *x4, *x5; + imgpel *orig_line; + int result; int jj = -2; - for (j = 0; j < ver_block_size + 5; j++) - { + for (j = 0; j < ver_block_size + 5; j++) { p0 = &cur_imgY[jj++][x_pos - 2]; p1 = p0 + 1; p2 = p1 + 1; p3 = p2 + 1; p4 = p3 + 1; - p5 = p4 + 1; - tmp_line = tmp_res[j]; + p5 = p4 + 1; + tmp_line = tmp_res[j]; - for (i = 0; i < hor_block_size; i++) - { - *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); } } jj = 3; - for (j = 0; j < ver_block_size; j++) - { - tmp_line = tmp_res[jj++]; - x0 = tmp_res[j ]; + for (j = 0; j < ver_block_size; j++) { + tmp_line = tmp_res[jj++]; + x0 = tmp_res[j]; x1 = tmp_res[j + 1]; x2 = tmp_res[j + 2]; x3 = tmp_res[j + 3]; @@ -541,12 +519,15 @@ static void get_luma_23(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ve x5 = tmp_res[j + 5]; orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*x0++ + *x5++) - 5 * (*x1++ + *x4++) + 20 * (*x2++ + *x3++); + for (i = 0; i < hor_block_size; i++) { + result = (*x0++ + *x5++) - 5 * (*x1++ + *x4++) + 20 * (*x2++ + *x3++); - *orig_line = (imgpel) iClip1(max_imgpel_value, ((result + 512)>>10)); - *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((*(tmp_line++) + 16) >> 5)) + 1 )>> 1); + *orig_line = (imgpel)iClip1(max_imgpel_value, ((result + 512) >> 10)); + *orig_line = + (imgpel)((*orig_line + + iClip1(max_imgpel_value, ((*(tmp_line++) + 16) >> 5)) + + 1) >> + 1); orig_line++; } } @@ -557,36 +538,35 @@ static void get_luma_23(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ve * \brief * Qpel horizontal, Hpel vertical (1, 2) ************************************************************************ - */ -static void get_luma_12(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ver_block_size, int hor_block_size, int x_pos, int shift_x, int max_imgpel_value) -{ + */ +static void get_luma_12(imgpel **block, imgpel **cur_imgY, int **tmp_res, + int ver_block_size, int hor_block_size, int x_pos, + int shift_x, int max_imgpel_value) { int i, j; int *tmp_line; - imgpel *p0, *p1, *p2, *p3, *p4, *p5; - int *x0, *x1, *x2, *x3, *x4, *x5; - imgpel *orig_line; - int result; + imgpel *p0, *p1, *p2, *p3, *p4, *p5; + int *x0, *x1, *x2, *x3, *x4, *x5; + imgpel *orig_line; + int result; - p0 = &(cur_imgY[ -2][x_pos - 2]); - for (j = 0; j < ver_block_size; j++) - { + p0 = &(cur_imgY[-2][x_pos - 2]); + for (j = 0; j < ver_block_size; j++) { p1 = p0 + shift_x; p2 = p1 + shift_x; p3 = p2 + shift_x; p4 = p3 + shift_x; p5 = p4 + shift_x; - tmp_line = tmp_res[j]; + tmp_line = tmp_res[j]; - for (i = 0; i < hor_block_size + 5; i++) - { - *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size + 5; i++) { + *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); } p0 = p1 - (hor_block_size + 5); } - for (j = 0; j < ver_block_size; j++) - { - tmp_line = &tmp_res[j][2]; + for (j = 0; j < ver_block_size; j++) { + tmp_line = &tmp_res[j][2]; orig_line = block[j]; x0 = tmp_res[j]; x1 = x0 + 1; @@ -595,53 +575,55 @@ static void get_luma_12(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ve x4 = x3 + 1; x5 = x4 + 1; - for (i = 0; i < hor_block_size; i++) - { - result = (*(x0++) + *(x5++)) - 5 * (*(x1++) + *(x4++)) + 20 * (*(x2++) + *(x3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(x0++) + *(x5++)) - 5 * (*(x1++) + *(x4++)) + + 20 * (*(x2++) + *(x3++)); - *orig_line = (imgpel) iClip1(max_imgpel_value, ((result + 512)>>10)); - *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((*(tmp_line++) + 16)>>5))+1)>>1); - orig_line ++; + *orig_line = (imgpel)iClip1(max_imgpel_value, ((result + 512) >> 10)); + *orig_line = + (imgpel)((*orig_line + + iClip1(max_imgpel_value, ((*(tmp_line++) + 16) >> 5)) + + 1) >> + 1); + orig_line++; } - } + } } - /*! ************************************************************************ * \brief * Qpel horizontal, Hpel vertical (3, 2) ************************************************************************ - */ -static void get_luma_32(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ver_block_size, int hor_block_size, int x_pos, int shift_x, int max_imgpel_value) -{ + */ +static void get_luma_32(imgpel **block, imgpel **cur_imgY, int **tmp_res, + int ver_block_size, int hor_block_size, int x_pos, + int shift_x, int max_imgpel_value) { int i, j; int *tmp_line; - imgpel *p0, *p1, *p2, *p3, *p4, *p5; - int *x0, *x1, *x2, *x3, *x4, *x5; - imgpel *orig_line; - int result; + imgpel *p0, *p1, *p2, *p3, *p4, *p5; + int *x0, *x1, *x2, *x3, *x4, *x5; + imgpel *orig_line; + int result; - p0 = &(cur_imgY[ -2][x_pos - 2]); - for (j = 0; j < ver_block_size; j++) - { + p0 = &(cur_imgY[-2][x_pos - 2]); + for (j = 0; j < ver_block_size; j++) { p1 = p0 + shift_x; p2 = p1 + shift_x; p3 = p2 + shift_x; p4 = p3 + shift_x; p5 = p4 + shift_x; - tmp_line = tmp_res[j]; + tmp_line = tmp_res[j]; - for (i = 0; i < hor_block_size + 5; i++) - { - *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size + 5; i++) { + *(tmp_line++) = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); } p0 = p1 - (hor_block_size + 5); } - for (j = 0; j < ver_block_size; j++) - { - tmp_line = &tmp_res[j][3]; + for (j = 0; j < ver_block_size; j++) { + tmp_line = &tmp_res[j][3]; orig_line = block[j]; x0 = tmp_res[j]; x1 = x0 + 1; @@ -650,13 +632,17 @@ static void get_luma_32(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ve x4 = x3 + 1; x5 = x4 + 1; - for (i = 0; i < hor_block_size; i++) - { - result = (*(x0++) + *(x5++)) - 5 * (*(x1++) + *(x4++)) + 20 * (*(x2++) + *(x3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(x0++) + *(x5++)) - 5 * (*(x1++) + *(x4++)) + + 20 * (*(x2++) + *(x3++)); - *orig_line = (imgpel) iClip1(max_imgpel_value, ((result + 512)>>10)); - *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((*(tmp_line++) + 16)>>5))+1)>>1); - orig_line ++; + *orig_line = (imgpel)iClip1(max_imgpel_value, ((result + 512) >> 10)); + *orig_line = + (imgpel)((*orig_line + + iClip1(max_imgpel_value, ((*(tmp_line++) + 16) >> 5)) + + 1) >> + 1); + orig_line++; } } } @@ -666,18 +652,18 @@ static void get_luma_32(imgpel **block, imgpel **cur_imgY, int **tmp_res, int ve * \brief * Qpel horizontal, Qpel vertical (3, 3) ************************************************************************ - */ -static void get_luma_33(imgpel **block, imgpel **cur_imgY, int ver_block_size, int hor_block_size, int x_pos, int shift_x, int max_imgpel_value) -{ + */ +static void get_luma_33(imgpel **block, imgpel **cur_imgY, int ver_block_size, + int hor_block_size, int x_pos, int shift_x, + int max_imgpel_value) { int i, j; imgpel *p0, *p1, *p2, *p3, *p4, *p5; - imgpel *orig_line; - int result; + imgpel *orig_line; + int result; int jj = 1; - for (j = 0; j < ver_block_size; j++) - { + for (j = 0; j < ver_block_size; j++) { p0 = &cur_imgY[jj++][x_pos - 2]; p1 = p0 + 1; p2 = p1 + 1; @@ -687,17 +673,16 @@ static void get_luma_33(imgpel **block, imgpel **cur_imgY, int ver_block_size, i orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5)); + *(orig_line++) = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); } } p0 = &(cur_imgY[-2][x_pos + 1]); - for (j = 0; j < ver_block_size; j++) - { + for (j = 0; j < ver_block_size; j++) { p1 = p0 + shift_x; p2 = p1 + shift_x; p3 = p2 + shift_x; @@ -705,36 +690,37 @@ static void get_luma_33(imgpel **block, imgpel **cur_imgY, int ver_block_size, i p5 = p4 + shift_x; orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((result + 16) >> 5)) + 1) >> 1); + *orig_line = + (imgpel)((*orig_line + + iClip1(max_imgpel_value, ((result + 16) >> 5)) + 1) >> + 1); orig_line++; } - p0 = p1 - hor_block_size ; - } + p0 = p1 - hor_block_size; + } } - - /*! ************************************************************************ * \brief * Qpel horizontal, Qpel vertical (1, 1) ************************************************************************ - */ -static void get_luma_11(imgpel **block, imgpel **cur_imgY, int ver_block_size, int hor_block_size, int x_pos, int shift_x, int max_imgpel_value) -{ + */ +static void get_luma_11(imgpel **block, imgpel **cur_imgY, int ver_block_size, + int hor_block_size, int x_pos, int shift_x, + int max_imgpel_value) { int i, j; imgpel *p0, *p1, *p2, *p3, *p4, *p5; - imgpel *orig_line; - int result; + imgpel *orig_line; + int result; int jj = 0; - for (j = 0; j < ver_block_size; j++) - { + for (j = 0; j < ver_block_size; j++) { p0 = &cur_imgY[jj++][x_pos - 2]; p1 = p0 + 1; p2 = p1 + 1; @@ -744,17 +730,16 @@ static void get_luma_11(imgpel **block, imgpel **cur_imgY, int ver_block_size, i orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5)); + *(orig_line++) = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); } } p0 = &(cur_imgY[-2][x_pos]); - for (j = 0; j < ver_block_size; j++) - { + for (j = 0; j < ver_block_size; j++) { p1 = p0 + shift_x; p2 = p1 + shift_x; p3 = p2 + shift_x; @@ -762,15 +747,18 @@ static void get_luma_11(imgpel **block, imgpel **cur_imgY, int ver_block_size, i p5 = p4 + shift_x; orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((result + 16) >> 5)) + 1) >> 1); + *orig_line = + (imgpel)((*orig_line + + iClip1(max_imgpel_value, ((result + 16) >> 5)) + 1) >> + 1); orig_line++; } - p0 = p1 - hor_block_size ; - } + p0 = p1 - hor_block_size; + } } /*! @@ -778,19 +766,19 @@ static void get_luma_11(imgpel **block, imgpel **cur_imgY, int ver_block_size, i * \brief * Qpel horizontal, Qpel vertical (1, 3) ************************************************************************ - */ -static void get_luma_13(imgpel **block, imgpel **cur_imgY, int ver_block_size, int hor_block_size, int x_pos, int shift_x, int max_imgpel_value) -{ + */ +static void get_luma_13(imgpel **block, imgpel **cur_imgY, int ver_block_size, + int hor_block_size, int x_pos, int shift_x, + int max_imgpel_value) { /* Diagonal interpolation */ int i, j; imgpel *p0, *p1, *p2, *p3, *p4, *p5; - imgpel *orig_line; - int result; + imgpel *orig_line; + int result; int jj = 1; - for (j = 0; j < ver_block_size; j++) - { + for (j = 0; j < ver_block_size; j++) { p0 = &cur_imgY[jj++][x_pos - 2]; p1 = p0 + 1; p2 = p1 + 1; @@ -800,17 +788,16 @@ static void get_luma_13(imgpel **block, imgpel **cur_imgY, int ver_block_size, i orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5)); + *(orig_line++) = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); } } p0 = &(cur_imgY[-2][x_pos]); - for (j = 0; j < ver_block_size; j++) - { + for (j = 0; j < ver_block_size; j++) { p1 = p0 + shift_x; p2 = p1 + shift_x; p3 = p2 + shift_x; @@ -818,15 +805,18 @@ static void get_luma_13(imgpel **block, imgpel **cur_imgY, int ver_block_size, i p5 = p4 + shift_x; orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((result + 16) >> 5)) + 1) >> 1); + *orig_line = + (imgpel)((*orig_line + + iClip1(max_imgpel_value, ((result + 16) >> 5)) + 1) >> + 1); orig_line++; } - p0 = p1 - hor_block_size ; - } + p0 = p1 - hor_block_size; + } } /*! @@ -834,19 +824,19 @@ static void get_luma_13(imgpel **block, imgpel **cur_imgY, int ver_block_size, i * \brief * Qpel horizontal, Qpel vertical (3, 1) ************************************************************************ - */ -static void get_luma_31(imgpel **block, imgpel **cur_imgY, int ver_block_size, int hor_block_size, int x_pos, int shift_x, int max_imgpel_value) -{ + */ +static void get_luma_31(imgpel **block, imgpel **cur_imgY, int ver_block_size, + int hor_block_size, int x_pos, int shift_x, + int max_imgpel_value) { /* Diagonal interpolation */ int i, j; imgpel *p0, *p1, *p2, *p3, *p4, *p5; - imgpel *orig_line; - int result; + imgpel *orig_line; + int result; int jj = 0; - for (j = 0; j < ver_block_size; j++) - { + for (j = 0; j < ver_block_size; j++) { p0 = &cur_imgY[jj++][x_pos - 2]; p1 = p0 + 1; p2 = p1 + 1; @@ -856,17 +846,16 @@ static void get_luma_31(imgpel **block, imgpel **cur_imgY, int ver_block_size, i orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *(orig_line++) = (imgpel) iClip1(max_imgpel_value, ((result + 16)>>5)); + *(orig_line++) = (imgpel)iClip1(max_imgpel_value, ((result + 16) >> 5)); } } p0 = &(cur_imgY[-2][x_pos + 1]); - for (j = 0; j < ver_block_size; j++) - { + for (j = 0; j < ver_block_size; j++) { p1 = p0 + shift_x; p2 = p1 + shift_x; p3 = p2 + shift_x; @@ -874,15 +863,18 @@ static void get_luma_31(imgpel **block, imgpel **cur_imgY, int ver_block_size, i p5 = p4 + shift_x; orig_line = block[j]; - for (i = 0; i < hor_block_size; i++) - { - result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + 20 * (*(p2++) + *(p3++)); + for (i = 0; i < hor_block_size; i++) { + result = (*(p0++) + *(p5++)) - 5 * (*(p1++) + *(p4++)) + + 20 * (*(p2++) + *(p3++)); - *orig_line = (imgpel) ((*orig_line + iClip1(max_imgpel_value, ((result + 16) >> 5)) + 1) >> 1); + *orig_line = + (imgpel)((*orig_line + + iClip1(max_imgpel_value, ((result + 16) >> 5)) + 1) >> + 1); orig_line++; } - p0 = p1 - hor_block_size ; - } + p0 = p1 - hor_block_size; + } } /*! @@ -890,147 +882,153 @@ static void get_luma_31(imgpel **block, imgpel **cur_imgY, int ver_block_size, i * \brief * Interpolation of 1/4 subpixel ************************************************************************ - */ + */ -void get_block_luma(StorablePicture *curr_ref, int x_pos, int y_pos, int hor_block_size, int ver_block_size, imgpel **block, - int shift_x, int maxold_x, int maxold_y, int **tmp_res, int max_imgpel_value, imgpel no_ref_value, Macroblock *currMB) -{ +void get_block_luma(StorablePicture *curr_ref, int x_pos, int y_pos, + int hor_block_size, int ver_block_size, imgpel **block, + int shift_x, int maxold_x, int maxold_y, int **tmp_res, + int max_imgpel_value, imgpel no_ref_value, + Macroblock *currMB) { if (curr_ref->no_ref) { printf("list[ref_frame] is equal to 'no reference picture' before RAP\n"); - memset(block[0],no_ref_value,ver_block_size * hor_block_size * sizeof(imgpel)); - } - else - { - imgpel **cur_imgY = (currMB->p_Vid->separate_colour_plane_flag && currMB->p_Slice->colour_plane_id>PLANE_Y)? curr_ref->imgUV[currMB->p_Slice->colour_plane_id-1] : curr_ref->cur_imgY; + memset(block[0], no_ref_value, + ver_block_size * hor_block_size * sizeof(imgpel)); + } else { + imgpel **cur_imgY = + (currMB->p_Vid->separate_colour_plane_flag && + currMB->p_Slice->colour_plane_id > PLANE_Y) + ? curr_ref->imgUV[currMB->p_Slice->colour_plane_id - 1] + : curr_ref->cur_imgY; int dx = (x_pos & 3); int dy = (y_pos & 3); x_pos >>= 2; y_pos >>= 2; - x_pos = iClip3(-18, maxold_x+2, x_pos); - y_pos = iClip3(-10, maxold_y+2, y_pos); + x_pos = iClip3(-18, maxold_x + 2, x_pos); + y_pos = iClip3(-10, maxold_y + 2, y_pos); if (dx == 0 && dy == 0) - get_block_00(&block[0][0], &cur_imgY[y_pos][x_pos], curr_ref->iLumaStride, ver_block_size); - else - { /* other positions */ + get_block_00(&block[0][0], &cur_imgY[y_pos][x_pos], curr_ref->iLumaStride, + ver_block_size); + else { /* other positions */ if (dy == 0) /* No vertical interpolation */ - { + { if (dx == 1) - get_luma_10(block, &cur_imgY[ y_pos], ver_block_size, hor_block_size, x_pos, max_imgpel_value); + get_luma_10(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, max_imgpel_value); else if (dx == 2) - get_luma_20(block, &cur_imgY[ y_pos], ver_block_size, hor_block_size, x_pos, max_imgpel_value); + get_luma_20(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, max_imgpel_value); else - get_luma_30(block, &cur_imgY[ y_pos], ver_block_size, hor_block_size, x_pos, max_imgpel_value); - } - else if (dx == 0) /* No horizontal interpolation */ - { - if (dy == 1) - get_luma_01(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, x_pos, shift_x, max_imgpel_value); - else if (dy == 2) - get_luma_02(block, &cur_imgY[ y_pos], ver_block_size, hor_block_size, x_pos, shift_x, max_imgpel_value); - else - get_luma_03(block, &cur_imgY[ y_pos], ver_block_size, hor_block_size, x_pos, shift_x, max_imgpel_value); - } - else if (dx == 2) /* Vertical & horizontal interpolation */ - { - if (dy == 1) - get_luma_21(block, &cur_imgY[ y_pos], tmp_res, ver_block_size, hor_block_size, x_pos, max_imgpel_value); - else if (dy == 2) - get_luma_22(block, &cur_imgY[ y_pos], tmp_res, ver_block_size, hor_block_size, x_pos, max_imgpel_value); - else - get_luma_23(block, &cur_imgY[ y_pos], tmp_res, ver_block_size, hor_block_size, x_pos, max_imgpel_value); - } - else if (dy == 2) + get_luma_30(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, max_imgpel_value); + } else if (dx == 0) /* No horizontal interpolation */ { - if (dx == 1) - get_luma_12(block, &cur_imgY[ y_pos], tmp_res, ver_block_size, hor_block_size, x_pos, shift_x, max_imgpel_value); + if (dy == 1) + get_luma_01(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, shift_x, max_imgpel_value); + else if (dy == 2) + get_luma_02(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, shift_x, max_imgpel_value); else - get_luma_32(block, &cur_imgY[ y_pos], tmp_res, ver_block_size, hor_block_size, x_pos, shift_x, max_imgpel_value); - } - else + get_luma_03(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, shift_x, max_imgpel_value); + } else if (dx == 2) /* Vertical & horizontal interpolation */ { - if (dx == 1) - { - if (dy == 1) - get_luma_11(block, &cur_imgY[ y_pos], ver_block_size, hor_block_size, x_pos, shift_x, max_imgpel_value); - else - get_luma_13(block, &cur_imgY[ y_pos], ver_block_size, hor_block_size, x_pos, shift_x, max_imgpel_value); - } + if (dy == 1) + get_luma_21(block, &cur_imgY[y_pos], tmp_res, ver_block_size, + hor_block_size, x_pos, max_imgpel_value); + else if (dy == 2) + get_luma_22(block, &cur_imgY[y_pos], tmp_res, ver_block_size, + hor_block_size, x_pos, max_imgpel_value); else - { + get_luma_23(block, &cur_imgY[y_pos], tmp_res, ver_block_size, + hor_block_size, x_pos, max_imgpel_value); + } else if (dy == 2) { + if (dx == 1) + get_luma_12(block, &cur_imgY[y_pos], tmp_res, ver_block_size, + hor_block_size, x_pos, shift_x, max_imgpel_value); + else + get_luma_32(block, &cur_imgY[y_pos], tmp_res, ver_block_size, + hor_block_size, x_pos, shift_x, max_imgpel_value); + } else { + if (dx == 1) { if (dy == 1) - get_luma_31(block, &cur_imgY[ y_pos], ver_block_size, hor_block_size, x_pos, shift_x, max_imgpel_value); + get_luma_11(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, shift_x, max_imgpel_value); else - get_luma_33(block, &cur_imgY[ y_pos], ver_block_size, hor_block_size, x_pos, shift_x, max_imgpel_value); + get_luma_13(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, shift_x, max_imgpel_value); + } else { + if (dy == 1) + get_luma_31(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, shift_x, max_imgpel_value); + else + get_luma_33(block, &cur_imgY[y_pos], ver_block_size, hor_block_size, + x_pos, shift_x, max_imgpel_value); } } } } } - /*! ************************************************************************ * \brief * Chroma (0,X) ************************************************************************ - */ -static void get_chroma_0X(imgpel *block, imgpel *cur_img, int span, int ver_block_size, int hor_block_size, int w00, int w01, int total_scale) -{ + */ +static void get_chroma_0X(imgpel *block, imgpel *cur_img, int span, + int ver_block_size, int hor_block_size, int w00, + int w01, int total_scale) { imgpel *cur_row = cur_img; imgpel *nxt_row = cur_img + span; - imgpel *cur_line, *cur_line_p1; imgpel *blk_line; int result; int i, j; - for (j = 0; j < ver_block_size; j++) - { - cur_line = cur_row; - cur_line_p1 = nxt_row; - blk_line = block; - block += 16; - cur_row = nxt_row; - nxt_row += span; - for (i = 0; i < hor_block_size; i++) - { + for (j = 0; j < ver_block_size; j++) { + cur_line = cur_row; + cur_line_p1 = nxt_row; + blk_line = block; + block += 16; + cur_row = nxt_row; + nxt_row += span; + for (i = 0; i < hor_block_size; i++) { result = (w00 * *cur_line++ + w01 * *cur_line_p1++); - *(blk_line++) = (imgpel) rshift_rnd_sf(result, total_scale); + *(blk_line++) = (imgpel)rshift_rnd_sf(result, total_scale); } } } - /*! ************************************************************************ * \brief * Chroma (X,0) ************************************************************************ - */ -static void get_chroma_X0(imgpel *block, imgpel *cur_img, int span, int ver_block_size, int hor_block_size, int w00, int w10, int total_scale) -{ + */ +static void get_chroma_X0(imgpel *block, imgpel *cur_img, int span, + int ver_block_size, int hor_block_size, int w00, + int w10, int total_scale) { imgpel *cur_row = cur_img; - - imgpel *cur_line, *cur_line_p1; - imgpel *blk_line; - int result; - int i, j; - for (j = 0; j < ver_block_size; j++) - { - cur_line = cur_row; - cur_line_p1 = cur_line + 1; - blk_line = block; - block += 16; - cur_row += span; - for (i = 0; i < hor_block_size; i++) - { - result = (w00 * *cur_line++ + w10 * *cur_line_p1++); - //*(blk_line++) = (imgpel) iClip1(max_imgpel_value, rshift_rnd_sf(result, total_scale)); - *(blk_line++) = (imgpel) rshift_rnd_sf(result, total_scale); - } + imgpel *cur_line, *cur_line_p1; + imgpel *blk_line; + int result; + int i, j; + for (j = 0; j < ver_block_size; j++) { + cur_line = cur_row; + cur_line_p1 = cur_line + 1; + blk_line = block; + block += 16; + cur_row += span; + for (i = 0; i < hor_block_size; i++) { + result = (w00 * *cur_line++ + w10 * *cur_line_p1++); + //*(blk_line++) = (imgpel) iClip1(max_imgpel_value, rshift_rnd_sf(result, + //total_scale)); + *(blk_line++) = (imgpel)rshift_rnd_sf(result, total_scale); } + } } /*! @@ -1038,477 +1036,515 @@ static void get_chroma_X0(imgpel *block, imgpel *cur_img, int span, int ver_bloc * \brief * Chroma (X,X) ************************************************************************ - */ -static void get_chroma_XX(imgpel *block, imgpel *cur_img, int span, int ver_block_size, int hor_block_size, int w00, int w01, int w10, int w11, int total_scale) -{ + */ +static void get_chroma_XX(imgpel *block, imgpel *cur_img, int span, + int ver_block_size, int hor_block_size, int w00, + int w01, int w10, int w11, int total_scale) { imgpel *cur_row = cur_img; imgpel *nxt_row = cur_img + span; - { imgpel *cur_line, *cur_line_p1; imgpel *blk_line; int result; int i, j; - for (j = 0; j < ver_block_size; j++) - { - cur_line = cur_row; + for (j = 0; j < ver_block_size; j++) { + cur_line = cur_row; cur_line_p1 = nxt_row; blk_line = block; block += 16; cur_row = nxt_row; nxt_row += span; - for (i = 0; i < hor_block_size; i++) - { - result = (w00 * *(cur_line++) + w01 * *(cur_line_p1++)); - result += (w10 * *(cur_line ) + w11 * *(cur_line_p1 )); - *(blk_line++) = (imgpel) rshift_rnd_sf(result, total_scale); + for (i = 0; i < hor_block_size; i++) { + result = (w00 * *(cur_line++) + w01 * *(cur_line_p1++)); + result += (w10 * *(cur_line) + w11 * *(cur_line_p1)); + *(blk_line++) = (imgpel)rshift_rnd_sf(result, total_scale); } } } } -static void get_block_chroma(StorablePicture *curr_ref, int x_pos, int y_pos, int subpel_x, int subpel_y, int maxold_x, int maxold_y, - int hor_block_size, int vert_block_size, int shiftpel_x, int shiftpel_y, - imgpel *block1, imgpel *block2, int total_scale, imgpel no_ref_value, VideoParameters *p_Vid) -{ - imgpel *img1,*img2; - short dx,dy; +static void get_block_chroma(StorablePicture *curr_ref, int x_pos, int y_pos, + int subpel_x, int subpel_y, int maxold_x, + int maxold_y, int hor_block_size, + int vert_block_size, int shiftpel_x, + int shiftpel_y, imgpel *block1, imgpel *block2, + int total_scale, imgpel no_ref_value, + VideoParameters *p_Vid) { + imgpel *img1, *img2; + short dx, dy; int span = curr_ref->iChromaStride; if (curr_ref->no_ref) { printf("list[ref_frame] is equal to 'no reference picture' before RAP\n"); - memset(block1,no_ref_value,vert_block_size * hor_block_size * sizeof(imgpel)); - memset(block2,no_ref_value,vert_block_size * hor_block_size * sizeof(imgpel)); - } - else - { - dx = (short) (x_pos & subpel_x); - dy = (short) (y_pos & subpel_y); + memset(block1, no_ref_value, + vert_block_size * hor_block_size * sizeof(imgpel)); + memset(block2, no_ref_value, + vert_block_size * hor_block_size * sizeof(imgpel)); + } else { + dx = (short)(x_pos & subpel_x); + dy = (short)(y_pos & subpel_y); x_pos = x_pos >> shiftpel_x; y_pos = y_pos >> shiftpel_y; - //clip MV; - assert(vert_block_size <=p_Vid->iChromaPadY && hor_block_size<=p_Vid->iChromaPadX); - x_pos = iClip3(-p_Vid->iChromaPadX, maxold_x, x_pos); //16 - y_pos = iClip3(-p_Vid->iChromaPadY, maxold_y, y_pos); //8 + // clip MV; + assert(vert_block_size <= p_Vid->iChromaPadY && + hor_block_size <= p_Vid->iChromaPadX); + x_pos = iClip3(-p_Vid->iChromaPadX, maxold_x, x_pos); // 16 + y_pos = iClip3(-p_Vid->iChromaPadY, maxold_y, y_pos); // 8 img1 = &curr_ref->imgUV[0][y_pos][x_pos]; img2 = &curr_ref->imgUV[1][y_pos][x_pos]; - if (dx == 0 && dy == 0) - { + if (dx == 0 && dy == 0) { get_block_00(block1, img1, span, vert_block_size); get_block_00(block2, img2, span, vert_block_size); - } - else - { - short dxcur = (short) (subpel_x + 1 - dx); - short dycur = (short) (subpel_y + 1 - dy); + } else { + short dxcur = (short)(subpel_x + 1 - dx); + short dycur = (short)(subpel_y + 1 - dy); short w00 = dxcur * dycur; - if (dx == 0) - { + if (dx == 0) { short w01 = dxcur * dy; - get_chroma_0X(block1, img1, span, vert_block_size, hor_block_size, w00, w01, total_scale); - get_chroma_0X(block2, img2, span, vert_block_size, hor_block_size, w00, w01, total_scale); - } - else if (dy == 0) - { + get_chroma_0X(block1, img1, span, vert_block_size, hor_block_size, w00, + w01, total_scale); + get_chroma_0X(block2, img2, span, vert_block_size, hor_block_size, w00, + w01, total_scale); + } else if (dy == 0) { short w10 = dx * dycur; - get_chroma_X0(block1, img1, span, vert_block_size, hor_block_size, w00, w10, total_scale); - get_chroma_X0(block2, img2, span, vert_block_size, hor_block_size, w00, w10, total_scale); - } - else - { + get_chroma_X0(block1, img1, span, vert_block_size, hor_block_size, w00, + w10, total_scale); + get_chroma_X0(block2, img2, span, vert_block_size, hor_block_size, w00, + w10, total_scale); + } else { short w01 = dxcur * dy; short w10 = dx * dycur; short w11 = dx * dy; - get_chroma_XX(block1, img1, span, vert_block_size, hor_block_size, w00, w01, w10, w11, total_scale); - get_chroma_XX(block2, img2, span, vert_block_size, hor_block_size, w00, w01, w10, w11, total_scale); + get_chroma_XX(block1, img1, span, vert_block_size, hor_block_size, w00, + w01, w10, w11, total_scale); + get_chroma_XX(block2, img2, span, vert_block_size, hor_block_size, w00, + w01, w10, w11, total_scale); } } } } -void intra_cr_decoding(Macroblock *currMB, int yuv) -{ +void intra_cr_decoding(Macroblock *currMB, int yuv) { VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; StorablePicture *dec_picture = currSlice->dec_picture; imgpel **curUV; int uv; - int b8,b4; + int b8, b4; int ioff, joff; - int i,j; + int i, j; - currSlice->intrapred_chroma(currMB);// last argument is ignored, computes needed data for both uv channels + currSlice->intrapred_chroma(currMB); // last argument is ignored, computes + // needed data for both uv channels - for(uv = 0; uv < 2; uv++) - { - currMB->itrans_4x4 = (currMB->is_lossless == FALSE) ? itrans4x4 : itrans4x4_ls; + for (uv = 0; uv < 2; uv++) { + currMB->itrans_4x4 = + (currMB->is_lossless == FALSE) ? itrans4x4 : itrans4x4_ls; curUV = dec_picture->imgUV[uv]; - - if(currMB->is_lossless) - { - if ((currMB->c_ipred_mode == VERT_PRED_8)||(currMB->c_ipred_mode == HOR_PRED_8)) - Inv_Residual_trans_Chroma(currMB, uv) ; - else - { - for(j=0;jmb_cr_size_y;j++) - for(i=0;imb_cr_size_x;i++) - currSlice->mb_rres [uv+1][j][i]=currSlice->cof[uv+1][j][i]; + + if (currMB->is_lossless) { + if ((currMB->c_ipred_mode == VERT_PRED_8) || + (currMB->c_ipred_mode == HOR_PRED_8)) + Inv_Residual_trans_Chroma(currMB, uv); + else { + for (j = 0; j < p_Vid->mb_cr_size_y; j++) + for (i = 0; i < p_Vid->mb_cr_size_x; i++) + currSlice->mb_rres[uv + 1][j][i] = currSlice->cof[uv + 1][j][i]; } } - if ((!(currMB->mb_type == SI4MB) && (currMB->cbp >> 4)) ) - { - for (b8 = 0; b8 < (p_Vid->num_uv_blocks); b8++) - { - for(b4 = 0; b4 < 4; b4++) - { - joff = subblk_offset_y[yuv][b8][b4]; - ioff = subblk_offset_x[yuv][b8][b4]; + if ((!(currMB->mb_type == SI4MB) && (currMB->cbp >> 4))) { + for (b8 = 0; b8 < (p_Vid->num_uv_blocks); b8++) { + for (b4 = 0; b4 < 4; b4++) { + joff = subblk_offset_y[yuv][b8][b4]; + ioff = subblk_offset_x[yuv][b8][b4]; - currMB->itrans_4x4(currMB, (ColorPlane) (uv + 1), ioff, joff); + currMB->itrans_4x4(currMB, (ColorPlane)(uv + 1), ioff, joff); - copy_image_data_4x4(&curUV[currMB->pix_c_y + joff], &(currSlice->mb_rec[uv + 1][joff]), currMB->pix_c_x + ioff, ioff); + copy_image_data_4x4(&curUV[currMB->pix_c_y + joff], + &(currSlice->mb_rec[uv + 1][joff]), + currMB->pix_c_x + ioff, ioff); } } - } - else if (currMB->mb_type == SI4MB) - { + } else if (currMB->mb_type == SI4MB) { itrans_sp_cr(currMB, uv); - for (joff = 0; joff < 8; joff += 4) - { - for(ioff = 0; ioff < 8;ioff+=4) - { - currMB->itrans_4x4(currMB, (ColorPlane) (uv + 1), ioff, joff); - - copy_image_data_4x4(&curUV[currMB->pix_c_y + joff], &(currSlice->mb_rec[uv + 1][joff]), currMB->pix_c_x + ioff, ioff); - } - } - } - else - { - for (b8 = 0; b8 < (p_Vid->num_uv_blocks); b8++) - { - for(b4 = 0; b4 < 4; b4++) - { - joff = subblk_offset_y[yuv][b8][b4]; - ioff = subblk_offset_x[yuv][b8][b4]; + for (joff = 0; joff < 8; joff += 4) { + for (ioff = 0; ioff < 8; ioff += 4) { + currMB->itrans_4x4(currMB, (ColorPlane)(uv + 1), ioff, joff); - copy_image_data_4x4(&curUV[currMB->pix_c_y + joff], &(currSlice->mb_pred[uv + 1][joff]), currMB->pix_c_x + ioff, ioff); + copy_image_data_4x4(&curUV[currMB->pix_c_y + joff], + &(currSlice->mb_rec[uv + 1][joff]), + currMB->pix_c_x + ioff, ioff); + } + } + } else { + for (b8 = 0; b8 < (p_Vid->num_uv_blocks); b8++) { + for (b4 = 0; b4 < 4; b4++) { + joff = subblk_offset_y[yuv][b8][b4]; + ioff = subblk_offset_x[yuv][b8][b4]; + + copy_image_data_4x4(&curUV[currMB->pix_c_y + joff], + &(currSlice->mb_pred[uv + 1][joff]), + currMB->pix_c_x + ioff, ioff); } } } } } -static inline void set_direct_references(const PixelPos *mb, signed char *l0_rFrame, signed char *l1_rFrame, PicMotionParams **mv_info) -{ - if (mb->available) - { +static inline void set_direct_references(const PixelPos *mb, + signed char *l0_rFrame, + signed char *l1_rFrame, + PicMotionParams **mv_info) { + if (mb->available) { signed char *ref_idx = mv_info[mb->pos_y][mb->pos_x].ref_idx; - *l0_rFrame = ref_idx[LIST_0]; - *l1_rFrame = ref_idx[LIST_1]; - } - else - { - *l0_rFrame = -1; - *l1_rFrame = -1; + *l0_rFrame = ref_idx[LIST_0]; + *l1_rFrame = ref_idx[LIST_1]; + } else { + *l0_rFrame = -1; + *l1_rFrame = -1; } } - -static void set_direct_references_mb_field(const PixelPos *mb, signed char *l0_rFrame, signed char *l1_rFrame, PicMotionParams **mv_info, Macroblock *mb_data) -{ - if (mb->available) - { +static void set_direct_references_mb_field(const PixelPos *mb, + signed char *l0_rFrame, + signed char *l1_rFrame, + PicMotionParams **mv_info, + Macroblock *mb_data) { + if (mb->available) { signed char *ref_idx = mv_info[mb->pos_y][mb->pos_x].ref_idx; - if (mb_data[mb->mb_addr].mb_field) - { - *l0_rFrame = ref_idx[LIST_0]; - *l1_rFrame = ref_idx[LIST_1]; + if (mb_data[mb->mb_addr].mb_field) { + *l0_rFrame = ref_idx[LIST_0]; + *l1_rFrame = ref_idx[LIST_1]; + } else { + *l0_rFrame = + (ref_idx[LIST_0] < 0) ? ref_idx[LIST_0] : ref_idx[LIST_0] * 2; + *l1_rFrame = + (ref_idx[LIST_1] < 0) ? ref_idx[LIST_1] : ref_idx[LIST_1] * 2; } - else - { - *l0_rFrame = (ref_idx[LIST_0] < 0) ? ref_idx[LIST_0] : ref_idx[LIST_0] * 2; - *l1_rFrame = (ref_idx[LIST_1] < 0) ? ref_idx[LIST_1] : ref_idx[LIST_1] * 2; - } - } - else - { - *l0_rFrame = -1; - *l1_rFrame = -1; + } else { + *l0_rFrame = -1; + *l1_rFrame = -1; } } -static void set_direct_references_mb_frame(const PixelPos *mb, signed char *l0_rFrame, signed char *l1_rFrame, PicMotionParams **mv_info, Macroblock *mb_data) -{ - if (mb->available) - { +static void set_direct_references_mb_frame(const PixelPos *mb, + signed char *l0_rFrame, + signed char *l1_rFrame, + PicMotionParams **mv_info, + Macroblock *mb_data) { + if (mb->available) { signed char *ref_idx = mv_info[mb->pos_y][mb->pos_x].ref_idx; - if (mb_data[mb->mb_addr].mb_field) - { - *l0_rFrame = (ref_idx[LIST_0] >> 1); - *l1_rFrame = (ref_idx[LIST_1] >> 1); + if (mb_data[mb->mb_addr].mb_field) { + *l0_rFrame = (ref_idx[LIST_0] >> 1); + *l1_rFrame = (ref_idx[LIST_1] >> 1); + } else { + *l0_rFrame = ref_idx[LIST_0]; + *l1_rFrame = ref_idx[LIST_1]; } - else - { - *l0_rFrame = ref_idx[LIST_0]; - *l1_rFrame = ref_idx[LIST_1]; - } - } - else - { - *l0_rFrame = -1; - *l1_rFrame = -1; + } else { + *l0_rFrame = -1; + *l1_rFrame = -1; } } -void prepare_direct_params(Macroblock *currMB, StorablePicture *dec_picture, MotionVector *pmvl0, MotionVector *pmvl1, signed char *l0_rFrame, signed char *l1_rFrame) -{ +void prepare_direct_params(Macroblock *currMB, StorablePicture *dec_picture, + MotionVector *pmvl0, MotionVector *pmvl1, + signed char *l0_rFrame, signed char *l1_rFrame) { Slice *currSlice = currMB->p_Slice; signed char l0_refA, l0_refB, l0_refC; signed char l1_refA, l1_refB, l1_refC; PicMotionParams **mv_info = dec_picture->mv_info; - + PixelPos mb[4]; get_neighbors(currMB, mb, 0, 0, 16); - if (!currSlice->mb_aff_frame_flag) - { + if (!currSlice->mb_aff_frame_flag) { set_direct_references(&mb[0], &l0_refA, &l1_refA, mv_info); set_direct_references(&mb[1], &l0_refB, &l1_refB, mv_info); set_direct_references(&mb[2], &l0_refC, &l1_refC, mv_info); - } - else - { + } else { VideoParameters *p_Vid = currMB->p_Vid; - if (currMB->mb_field) - { - set_direct_references_mb_field(&mb[0], &l0_refA, &l1_refA, mv_info, p_Vid->mb_data); - set_direct_references_mb_field(&mb[1], &l0_refB, &l1_refB, mv_info, p_Vid->mb_data); - set_direct_references_mb_field(&mb[2], &l0_refC, &l1_refC, mv_info, p_Vid->mb_data); - } - else - { - set_direct_references_mb_frame(&mb[0], &l0_refA, &l1_refA, mv_info, p_Vid->mb_data); - set_direct_references_mb_frame(&mb[1], &l0_refB, &l1_refB, mv_info, p_Vid->mb_data); - set_direct_references_mb_frame(&mb[2], &l0_refC, &l1_refC, mv_info, p_Vid->mb_data); + if (currMB->mb_field) { + set_direct_references_mb_field(&mb[0], &l0_refA, &l1_refA, mv_info, + p_Vid->mb_data); + set_direct_references_mb_field(&mb[1], &l0_refB, &l1_refB, mv_info, + p_Vid->mb_data); + set_direct_references_mb_field(&mb[2], &l0_refC, &l1_refC, mv_info, + p_Vid->mb_data); + } else { + set_direct_references_mb_frame(&mb[0], &l0_refA, &l1_refA, mv_info, + p_Vid->mb_data); + set_direct_references_mb_frame(&mb[1], &l0_refB, &l1_refB, mv_info, + p_Vid->mb_data); + set_direct_references_mb_frame(&mb[2], &l0_refC, &l1_refC, mv_info, + p_Vid->mb_data); } } - *l0_rFrame = (signed char) imin(imin((unsigned char) l0_refA, (unsigned char) l0_refB), (unsigned char) l0_refC); - *l1_rFrame = (signed char) imin(imin((unsigned char) l1_refA, (unsigned char) l1_refB), (unsigned char) l1_refC); + *l0_rFrame = + (signed char)imin(imin((unsigned char)l0_refA, (unsigned char)l0_refB), + (unsigned char)l0_refC); + *l1_rFrame = + (signed char)imin(imin((unsigned char)l1_refA, (unsigned char)l1_refB), + (unsigned char)l1_refC); - if (*l0_rFrame >=0) - currMB->GetMVPredictor (currMB, mb, pmvl0, *l0_rFrame, mv_info, LIST_0, 0, 0, 16, 16); + if (*l0_rFrame >= 0) + currMB->GetMVPredictor(currMB, mb, pmvl0, *l0_rFrame, mv_info, LIST_0, 0, 0, + 16, 16); - if (*l1_rFrame >=0) - currMB->GetMVPredictor (currMB, mb, pmvl1, *l1_rFrame, mv_info, LIST_1, 0, 0, 16, 16); + if (*l1_rFrame >= 0) + currMB->GetMVPredictor(currMB, mb, pmvl1, *l1_rFrame, mv_info, LIST_1, 0, 0, + 16, 16); } -static void check_motion_vector_range(const MotionVector *mv, Slice *pSlice) -{ - if (mv->mv_x > 8191 || mv->mv_x < -8192) - { - fprintf(stderr,"WARNING! Horizontal motion vector %d is out of allowed range {-8192, 8191} in picture %d, macroblock %d\n", mv->mv_x, pSlice->p_Vid->number, pSlice->current_mb_nr); - //error("invalid stream: too big horizontal motion vector", 500); +static void check_motion_vector_range(const MotionVector *mv, Slice *pSlice) { + if (mv->mv_x > 8191 || mv->mv_x < -8192) { + fprintf(stderr, + "WARNING! Horizontal motion vector %d is out of allowed range " + "{-8192, 8191} in picture %d, macroblock %d\n", + mv->mv_x, pSlice->p_Vid->number, pSlice->current_mb_nr); + // error("invalid stream: too big horizontal motion vector", 500); } - if (mv->mv_y > (pSlice->max_mb_vmv_r - 1) || mv->mv_y < (-pSlice->max_mb_vmv_r)) - { - fprintf(stderr,"WARNING! Vertical motion vector %d is out of allowed range {%d, %d} in picture %d, macroblock %d\n", mv->mv_y, (-pSlice->max_mb_vmv_r), (pSlice->max_mb_vmv_r - 1), pSlice->p_Vid->number, pSlice->current_mb_nr); - //error("invalid stream: too big vertical motion vector", 500); + if (mv->mv_y > (pSlice->max_mb_vmv_r - 1) || + mv->mv_y < (-pSlice->max_mb_vmv_r)) { + fprintf(stderr, + "WARNING! Vertical motion vector %d is out of allowed range {%d, " + "%d} in picture %d, macroblock %d\n", + mv->mv_y, (-pSlice->max_mb_vmv_r), (pSlice->max_mb_vmv_r - 1), + pSlice->p_Vid->number, pSlice->current_mb_nr); + // error("invalid stream: too big vertical motion vector", 500); } } -static inline int check_vert_mv(int llimit, int vec1_y,int rlimit) -{ +static inline int check_vert_mv(int llimit, int vec1_y, int rlimit) { int y_pos = vec1_y >> 2; - if(y_pos < llimit || y_pos > rlimit) + if (y_pos < llimit || y_pos > rlimit) return 1; else return 0; } -static void perform_mc_single_wp(Macroblock *currMB, ColorPlane pl, StorablePicture *dec_picture, int pred_dir, int i, int j, int block_size_x, int block_size_y) -{ - VideoParameters *p_Vid = currMB->p_Vid; +static void perform_mc_single_wp(Macroblock *currMB, ColorPlane pl, + StorablePicture *dec_picture, int pred_dir, + int i, int j, int block_size_x, + int block_size_y) { + VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; seq_parameter_set_rbsp_t *active_sps = currSlice->active_sps; imgpel **tmp_block_l0 = currSlice->tmp_block_l0; imgpel **tmp_block_l1 = currSlice->tmp_block_l1; static const int mv_mul = 16; // 4 * 4 - int i4 = currMB->block_x + i; - int j4 = currMB->block_y + j; + int i4 = currMB->block_x + i; + int j4 = currMB->block_y + j; int type = currSlice->slice_type; int chroma_format_idc = dec_picture->chroma_format_idc; //===== Single List Prediction ===== int ioff = (i << 2); - int joff = (j << 2); + int joff = (j << 2); PicMotionParams *mv_info = &dec_picture->mv_info[j4][i4]; - short ref_idx = mv_info->ref_idx[pred_dir]; - short ref_idx_wp = ref_idx; + short ref_idx = mv_info->ref_idx[pred_dir]; + short ref_idx_wp = ref_idx; MotionVector *mv_array = &mv_info->mv[pred_dir]; int list_offset = currMB->list_offset; StorablePicture *list = currSlice->listX[list_offset + pred_dir][ref_idx]; int vec1_x, vec1_y; // vars for get_block_luma int maxold_x = dec_picture->size_x_m1; - int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 : dec_picture->size_y_m1; - int shift_x = dec_picture->iLumaStride; + int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 + : dec_picture->size_y_m1; + int shift_x = dec_picture->iLumaStride; int **tmp_res = currSlice->tmp_res; int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; - imgpel no_ref_value = (imgpel) p_Vid->dc_pred_value_comp[pl]; + imgpel no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[pl]; // check_motion_vector_range(mv_array, currSlice); vec1_x = i4 * mv_mul + mv_array->mv_x; vec1_y = (currMB->block_y_aff + j) * mv_mul + mv_array->mv_y; - if(block_size_y > (p_Vid->iLumaPadY-4) && CheckVertMV(currMB, vec1_y, block_size_y)) - { - get_block_luma(list, vec1_x, vec1_y, block_size_x, BLOCK_SIZE_8x8, tmp_block_l0, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - get_block_luma(list, vec1_x, vec1_y+(BLOCK_SIZE_8x8<<2), block_size_x, block_size_y-BLOCK_SIZE_8x8, tmp_block_l0+BLOCK_SIZE_8x8, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - } - else - get_block_luma(list, vec1_x, vec1_y, block_size_x, block_size_y, tmp_block_l0,shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - + if (block_size_y > (p_Vid->iLumaPadY - 4) && + CheckVertMV(currMB, vec1_y, block_size_y)) { + get_block_luma(list, vec1_x, vec1_y, block_size_x, BLOCK_SIZE_8x8, + tmp_block_l0, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + get_block_luma(list, vec1_x, vec1_y + (BLOCK_SIZE_8x8 << 2), block_size_x, + block_size_y - BLOCK_SIZE_8x8, tmp_block_l0 + BLOCK_SIZE_8x8, + shift_x, maxold_x, maxold_y, tmp_res, max_imgpel_value, + no_ref_value, currMB); + } else + get_block_luma(list, vec1_x, vec1_y, block_size_x, block_size_y, + tmp_block_l0, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); { int alpha_l0, wp_offset; - if (currMB->mb_field && ((p_Vid->active_pps->weighted_pred_flag&&(type==P_SLICE|| type == SP_SLICE))||(p_Vid->active_pps->weighted_bipred_idc==1 && (type==B_SLICE)))) - ref_idx_wp >>=1; - alpha_l0 = currSlice->wp_weight[pred_dir][ref_idx_wp][0]; + if (currMB->mb_field && + ((p_Vid->active_pps->weighted_pred_flag && + (type == P_SLICE || type == SP_SLICE)) || + (p_Vid->active_pps->weighted_bipred_idc == 1 && (type == B_SLICE)))) + ref_idx_wp >>= 1; + alpha_l0 = currSlice->wp_weight[pred_dir][ref_idx_wp][0]; wp_offset = currSlice->wp_offset[pred_dir][ref_idx_wp][0]; - weighted_mc_prediction(&currSlice->mb_pred[pl][joff], block_size_y, block_size_x, ioff, tmp_block_l0, alpha_l0, wp_offset, currSlice->luma_log2_weight_denom, max_imgpel_value); + weighted_mc_prediction(&currSlice->mb_pred[pl][joff], block_size_y, + block_size_x, ioff, tmp_block_l0, alpha_l0, + wp_offset, currSlice->luma_log2_weight_denom, + max_imgpel_value); } - if ((chroma_format_idc != YUV400) && (chroma_format_idc != YUV444) ) - { - int ioff_cr,joff_cr,block_size_x_cr,block_size_y_cr; - int vec1_y_cr = vec1_y + ((active_sps->chroma_format_idc == 1)? currSlice->chroma_vector_adjustment[list_offset + pred_dir][ref_idx] : 0); + if ((chroma_format_idc != YUV400) && (chroma_format_idc != YUV444)) { + int ioff_cr, joff_cr, block_size_x_cr, block_size_y_cr; + int vec1_y_cr = + vec1_y + + ((active_sps->chroma_format_idc == 1) + ? currSlice + ->chroma_vector_adjustment[list_offset + pred_dir][ref_idx] + : 0); int total_scale = p_Vid->total_scale; int subpel_x = p_Vid->subpel_x; - int subpel_y = p_Vid->subpel_y; + int subpel_y = p_Vid->subpel_y; int shiftpel_x = p_Vid->shiftpel_x; int shiftpel_y = p_Vid->shiftpel_y; int maxold_x = dec_picture->size_x_cr_m1; - int maxold_y = (currMB->mb_field) ? (dec_picture->size_y_cr >> 1) - 1 : dec_picture->size_y_cr_m1; + int maxold_y = (currMB->mb_field) ? (dec_picture->size_y_cr >> 1) - 1 + : dec_picture->size_y_cr_m1; int chroma_log2_weight = currSlice->chroma_log2_weight_denom; if (p_Vid->mb_cr_size_x == MB_BLOCK_SIZE) { ioff_cr = ioff; block_size_x_cr = block_size_x; - } - else { + } else { ioff_cr = ioff >> 1; block_size_x_cr = block_size_x >> 1; } if (p_Vid->mb_cr_size_y == MB_BLOCK_SIZE) { joff_cr = joff; block_size_y_cr = block_size_y; - } - else { + } else { joff_cr = joff >> 1; block_size_y_cr = block_size_y >> 1; } - no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[1]; -{ + no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[1]; + { int *weight = currSlice->wp_weight[pred_dir][ref_idx_wp]; int *offset = currSlice->wp_offset[pred_dir][ref_idx_wp]; - get_block_chroma(list,vec1_x,vec1_y_cr,subpel_x,subpel_y,maxold_x,maxold_y,block_size_x_cr,block_size_y_cr,shiftpel_x,shiftpel_y,&tmp_block_l0[0][0],&tmp_block_l1[0][0] ,total_scale,no_ref_value,p_Vid); - weighted_mc_prediction(&currSlice->mb_pred[1][joff_cr], block_size_y_cr, block_size_x_cr, ioff_cr, tmp_block_l0, weight[1], offset[1], chroma_log2_weight, p_Vid->max_pel_value_comp[1]); - weighted_mc_prediction(&currSlice->mb_pred[2][joff_cr], block_size_y_cr, block_size_x_cr, ioff_cr, tmp_block_l1, weight[2], offset[2], chroma_log2_weight, p_Vid->max_pel_value_comp[2]); + get_block_chroma(list, vec1_x, vec1_y_cr, subpel_x, subpel_y, maxold_x, + maxold_y, block_size_x_cr, block_size_y_cr, shiftpel_x, + shiftpel_y, &tmp_block_l0[0][0], &tmp_block_l1[0][0], + total_scale, no_ref_value, p_Vid); + weighted_mc_prediction(&currSlice->mb_pred[1][joff_cr], block_size_y_cr, + block_size_x_cr, ioff_cr, tmp_block_l0, weight[1], + offset[1], chroma_log2_weight, + p_Vid->max_pel_value_comp[1]); + weighted_mc_prediction(&currSlice->mb_pred[2][joff_cr], block_size_y_cr, + block_size_x_cr, ioff_cr, tmp_block_l1, weight[2], + offset[2], chroma_log2_weight, + p_Vid->max_pel_value_comp[2]); } } } - -static void perform_mc_single(Macroblock *currMB, ColorPlane pl, StorablePicture *dec_picture, int pred_dir, int i, int j, int block_size_x, int block_size_y) -{ - VideoParameters *p_Vid = currMB->p_Vid; +static void perform_mc_single(Macroblock *currMB, ColorPlane pl, + StorablePicture *dec_picture, int pred_dir, int i, + int j, int block_size_x, int block_size_y) { + VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; seq_parameter_set_rbsp_t *active_sps = currSlice->active_sps; imgpel **tmp_block_l0 = currSlice->tmp_block_l0; imgpel **tmp_block_l1 = currSlice->tmp_block_l1; static const int mv_mul = 16; // 4 * 4 - int i4 = currMB->block_x + i; - int j4 = currMB->block_y + j; + int i4 = currMB->block_x + i; + int j4 = currMB->block_y + j; int chroma_format_idc = dec_picture->chroma_format_idc; //===== Single List Prediction ===== int ioff = (i << 2); - int joff = (j << 2); + int joff = (j << 2); PicMotionParams *mv_info = &dec_picture->mv_info[j4][i4]; MotionVector *mv_array = &mv_info->mv[pred_dir]; - short ref_idx = mv_info->ref_idx[pred_dir]; + short ref_idx = mv_info->ref_idx[pred_dir]; int list_offset = currMB->list_offset; StorablePicture *list = currSlice->listX[list_offset + pred_dir][ref_idx]; int vec1_x, vec1_y; // vars for get_block_luma int maxold_x = dec_picture->size_x_m1; - int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 : dec_picture->size_y_m1; - int shift_x = dec_picture->iLumaStride; + int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 + : dec_picture->size_y_m1; + int shift_x = dec_picture->iLumaStride; int **tmp_res = currSlice->tmp_res; int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; - imgpel no_ref_value = (imgpel) p_Vid->dc_pred_value_comp[pl]; + imgpel no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[pl]; // check_motion_vector_range(mv_array, currSlice); vec1_x = i4 * mv_mul + mv_array->mv_x; vec1_y = (currMB->block_y_aff + j) * mv_mul + mv_array->mv_y; - - if (block_size_y > (p_Vid->iLumaPadY-4) && CheckVertMV(currMB, vec1_y, block_size_y)) - { - get_block_luma(list, vec1_x, vec1_y, block_size_x, BLOCK_SIZE_8x8, tmp_block_l0, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - get_block_luma(list, vec1_x, vec1_y+(BLOCK_SIZE_8x8<<2), block_size_x, block_size_y-BLOCK_SIZE_8x8, tmp_block_l0+BLOCK_SIZE_8x8, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - } - else - get_block_luma(list, vec1_x, vec1_y, block_size_x, block_size_y, tmp_block_l0,shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - mc_prediction(&currSlice->mb_pred[pl][joff], block_size_y, block_size_x, ioff, tmp_block_l0); + if (block_size_y > (p_Vid->iLumaPadY - 4) && + CheckVertMV(currMB, vec1_y, block_size_y)) { + get_block_luma(list, vec1_x, vec1_y, block_size_x, BLOCK_SIZE_8x8, + tmp_block_l0, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + get_block_luma(list, vec1_x, vec1_y + (BLOCK_SIZE_8x8 << 2), block_size_x, + block_size_y - BLOCK_SIZE_8x8, tmp_block_l0 + BLOCK_SIZE_8x8, + shift_x, maxold_x, maxold_y, tmp_res, max_imgpel_value, + no_ref_value, currMB); + } else + get_block_luma(list, vec1_x, vec1_y, block_size_x, block_size_y, + tmp_block_l0, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); - if ((chroma_format_idc != YUV400) && (chroma_format_idc != YUV444) ) - { - int ioff_cr,joff_cr,block_size_x_cr,block_size_y_cr; - int vec1_y_cr = vec1_y + ((active_sps->chroma_format_idc == 1)? currSlice->chroma_vector_adjustment[list_offset + pred_dir][ref_idx] : 0); + mc_prediction(&currSlice->mb_pred[pl][joff], block_size_y, block_size_x, ioff, + tmp_block_l0); + + if ((chroma_format_idc != YUV400) && (chroma_format_idc != YUV444)) { + int ioff_cr, joff_cr, block_size_x_cr, block_size_y_cr; + int vec1_y_cr = + vec1_y + + ((active_sps->chroma_format_idc == 1) + ? currSlice + ->chroma_vector_adjustment[list_offset + pred_dir][ref_idx] + : 0); int total_scale = p_Vid->total_scale; int subpel_x = p_Vid->subpel_x; - int subpel_y = p_Vid->subpel_y; + int subpel_y = p_Vid->subpel_y; int shiftpel_x = p_Vid->shiftpel_x; int shiftpel_y = p_Vid->shiftpel_y; int maxold_x = dec_picture->size_x_cr_m1; - int maxold_y = (currMB->mb_field) ? (dec_picture->size_y_cr >> 1) - 1 : dec_picture->size_y_cr_m1; - if (p_Vid->mb_cr_size_x == MB_BLOCK_SIZE) - { + int maxold_y = (currMB->mb_field) ? (dec_picture->size_y_cr >> 1) - 1 + : dec_picture->size_y_cr_m1; + if (p_Vid->mb_cr_size_x == MB_BLOCK_SIZE) { ioff_cr = ioff; block_size_x_cr = block_size_x; - } - else - { + } else { ioff_cr = ioff >> 1; block_size_x_cr = block_size_x >> 1; } - if (p_Vid->mb_cr_size_y == MB_BLOCK_SIZE) - { + if (p_Vid->mb_cr_size_y == MB_BLOCK_SIZE) { joff_cr = joff; block_size_y_cr = block_size_y; - } - else - { + } else { joff_cr = joff >> 1; block_size_y_cr = block_size_y >> 1; } - no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[1]; - get_block_chroma(list,vec1_x,vec1_y_cr,subpel_x,subpel_y,maxold_x,maxold_y,block_size_x_cr,block_size_y_cr,shiftpel_x,shiftpel_y,&tmp_block_l0[0][0],&tmp_block_l1[0][0] ,total_scale,no_ref_value,p_Vid); - mc_prediction(&currSlice->mb_pred[1][joff_cr], block_size_y_cr, block_size_x_cr, ioff_cr, tmp_block_l0); - mc_prediction(&currSlice->mb_pred[2][joff_cr], block_size_y_cr, block_size_x_cr, ioff_cr, tmp_block_l1); + no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[1]; + get_block_chroma(list, vec1_x, vec1_y_cr, subpel_x, subpel_y, maxold_x, + maxold_y, block_size_x_cr, block_size_y_cr, shiftpel_x, + shiftpel_y, &tmp_block_l0[0][0], &tmp_block_l1[0][0], + total_scale, no_ref_value, p_Vid); + mc_prediction(&currSlice->mb_pred[1][joff_cr], block_size_y_cr, + block_size_x_cr, ioff_cr, tmp_block_l0); + mc_prediction(&currSlice->mb_pred[2][joff_cr], block_size_y_cr, + block_size_x_cr, ioff_cr, tmp_block_l1); } } -static void perform_mc_bi_wp(Macroblock *currMB, ColorPlane pl, StorablePicture *dec_picture, int i, int j, int block_size_x, int block_size_y) -{ +static void perform_mc_bi_wp(Macroblock *currMB, ColorPlane pl, + StorablePicture *dec_picture, int i, int j, + int block_size_x, int block_size_y) { static const int mv_mul = 16; - int vec1_x, vec1_y, vec2_x, vec2_y; - VideoParameters *p_Vid = currMB->p_Vid; + int vec1_x, vec1_y, vec2_x, vec2_y; + VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; int weighted_bipred_idc = p_Vid->active_pps->weighted_bipred_idc; @@ -1524,17 +1560,23 @@ static void perform_mc_bi_wp(Macroblock *currMB, ColorPlane pl, StorablePicture MotionVector *l1_mv_array = &mv_info->mv[LIST_1]; short l0_refframe = mv_info->ref_idx[LIST_0]; short l1_refframe = mv_info->ref_idx[LIST_1]; - int l0_ref_idx = (currMB->mb_field && weighted_bipred_idc == 1) ? l0_refframe >> 1: l0_refframe; - int l1_ref_idx = (currMB->mb_field && weighted_bipred_idc == 1) ? l1_refframe >> 1: l1_refframe; + int l0_ref_idx = (currMB->mb_field && weighted_bipred_idc == 1) + ? l0_refframe >> 1 + : l0_refframe; + int l1_ref_idx = (currMB->mb_field && weighted_bipred_idc == 1) + ? l1_refframe >> 1 + : l1_refframe; - /// WP Parameters - int wt_list_offset = (weighted_bipred_idc==2)? list_offset : 0; - int *weight0 = currSlice->wbp_weight[LIST_0 + wt_list_offset][l0_ref_idx][l1_ref_idx]; - int *weight1 = currSlice->wbp_weight[LIST_1 + wt_list_offset][l0_ref_idx][l1_ref_idx]; + int wt_list_offset = (weighted_bipred_idc == 2) ? list_offset : 0; + int *weight0 = + currSlice->wbp_weight[LIST_0 + wt_list_offset][l0_ref_idx][l1_ref_idx]; + int *weight1 = + currSlice->wbp_weight[LIST_1 + wt_list_offset][l0_ref_idx][l1_ref_idx]; int *offset0 = currSlice->wp_offset[LIST_0 + wt_list_offset][l0_ref_idx]; int *offset1 = currSlice->wp_offset[LIST_1 + wt_list_offset][l1_ref_idx]; - int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 : dec_picture->size_y_m1; + int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 + : dec_picture->size_y_m1; int pady = p_Vid->iLumaPadY; int rlimit = maxold_y + pady - block_size_y - 2; int llimit = 2 - pady; @@ -1553,10 +1595,10 @@ static void perform_mc_bi_wp(Macroblock *currMB, ColorPlane pl, StorablePicture // vars for get_block_luma int maxold_x = dec_picture->size_x_m1; - int shift_x = dec_picture->iLumaStride; + int shift_x = dec_picture->iLumaStride; int **tmp_res = currSlice->tmp_res; int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; - imgpel no_ref_value = (imgpel) p_Vid->dc_pred_value_comp[pl]; + imgpel no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[pl]; check_motion_vector_range(l0_mv_array, currSlice); check_motion_vector_range(l1_mv_array, currSlice); @@ -1565,86 +1607,109 @@ static void perform_mc_bi_wp(Macroblock *currMB, ColorPlane pl, StorablePicture vec1_y = (block_y_aff + j) * mv_mul + l0_mv_array->mv_y; vec2_y = (block_y_aff + j) * mv_mul + l1_mv_array->mv_y; - if (big_blocky && check_vert_mv(llimit, vec1_y, rlimit)) - { - get_block_luma(list0, vec1_x, vec1_y, block_size_x, BLOCK_SIZE_8x8, tmp_block_l0, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - get_block_luma(list0, vec1_x, vec1_y+(BLOCK_SIZE_8x8<<2), block_size_x, block_size_y-BLOCK_SIZE_8x8, tmp_block_l0+BLOCK_SIZE_8x8, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - } - else - get_block_luma(list0, vec1_x, vec1_y, block_size_x, block_size_y, tmp_block_l0,shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - if (big_blocky && check_vert_mv(llimit, vec2_y,rlimit)) - { - get_block_luma(list1, vec2_x, vec2_y, block_size_x, BLOCK_SIZE_8x8, tmp_block_l1, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - get_block_luma(list1, vec2_x, vec2_y+(BLOCK_SIZE_8x8<<2), block_size_x, block_size_y-BLOCK_SIZE_8x8, tmp_block_l1 + BLOCK_SIZE_8x8, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - } - else - get_block_luma(list1, vec2_x, vec2_y, block_size_x, block_size_y, tmp_block_l1,shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); + if (big_blocky && check_vert_mv(llimit, vec1_y, rlimit)) { + get_block_luma(list0, vec1_x, vec1_y, block_size_x, BLOCK_SIZE_8x8, + tmp_block_l0, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + get_block_luma(list0, vec1_x, vec1_y + (BLOCK_SIZE_8x8 << 2), block_size_x, + block_size_y - BLOCK_SIZE_8x8, tmp_block_l0 + BLOCK_SIZE_8x8, + shift_x, maxold_x, maxold_y, tmp_res, max_imgpel_value, + no_ref_value, currMB); + } else + get_block_luma(list0, vec1_x, vec1_y, block_size_x, block_size_y, + tmp_block_l0, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + if (big_blocky && check_vert_mv(llimit, vec2_y, rlimit)) { + get_block_luma(list1, vec2_x, vec2_y, block_size_x, BLOCK_SIZE_8x8, + tmp_block_l1, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + get_block_luma(list1, vec2_x, vec2_y + (BLOCK_SIZE_8x8 << 2), block_size_x, + block_size_y - BLOCK_SIZE_8x8, tmp_block_l1 + BLOCK_SIZE_8x8, + shift_x, maxold_x, maxold_y, tmp_res, max_imgpel_value, + no_ref_value, currMB); + } else + get_block_luma(list1, vec2_x, vec2_y, block_size_x, block_size_y, + tmp_block_l1, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + wp_offset = ((offset0[0] + offset1[0] + 1) >> 1); + weighted_bi_prediction(&currSlice->mb_pred[pl][joff][ioff], block0, block1, + block_size_y, block_size_x, weight0[0], weight1[0], + wp_offset, currSlice->luma_log2_weight_denom + 1, + max_imgpel_value); - wp_offset = ((offset0[0] + offset1[0] + 1) >>1); - weighted_bi_prediction(&currSlice->mb_pred[pl][joff][ioff], block0, block1, block_size_y, block_size_x, weight0[0], weight1[0], wp_offset, currSlice->luma_log2_weight_denom + 1, max_imgpel_value); - - if ((chroma_format_idc != YUV400) && (chroma_format_idc != YUV444) ) - { - int ioff_cr, joff_cr,block_size_y_cr,block_size_x_cr,vec2_y_cr,vec1_y_cr; + if ((chroma_format_idc != YUV400) && (chroma_format_idc != YUV444)) { + int ioff_cr, joff_cr, block_size_y_cr, block_size_x_cr, vec2_y_cr, + vec1_y_cr; int maxold_x = dec_picture->size_x_cr_m1; - int maxold_y = (currMB->mb_field) ? (dec_picture->size_y_cr >> 1) - 1 : dec_picture->size_y_cr_m1; + int maxold_y = (currMB->mb_field) ? (dec_picture->size_y_cr >> 1) - 1 + : dec_picture->size_y_cr_m1; int shiftpel_x = p_Vid->shiftpel_x; int shiftpel_y = p_Vid->shiftpel_y; int subpel_x = p_Vid->subpel_x; - int subpel_y = p_Vid->subpel_y; + int subpel_y = p_Vid->subpel_y; int total_scale = p_Vid->total_scale; int chroma_log2 = currSlice->chroma_log2_weight_denom + 1; - if (p_Vid->mb_cr_size_x == MB_BLOCK_SIZE) - { - ioff_cr = ioff; - block_size_x_cr = block_size_x; - } - else - { + if (p_Vid->mb_cr_size_x == MB_BLOCK_SIZE) { + ioff_cr = ioff; + block_size_x_cr = block_size_x; + } else { ioff_cr = ioff >> 1; - block_size_x_cr = block_size_x >> 1; + block_size_x_cr = block_size_x >> 1; } - if (p_Vid->mb_cr_size_y == MB_BLOCK_SIZE) - { + if (p_Vid->mb_cr_size_y == MB_BLOCK_SIZE) { joff_cr = joff; block_size_y_cr = block_size_y; - } - else - { + } else { joff_cr = joff >> 1; block_size_y_cr = block_size_y >> 1; } - if (chroma_format_idc == 1) - { - vec1_y_cr = vec1_y + currSlice->chroma_vector_adjustment[LIST_0 + list_offset][l0_refframe]; - vec2_y_cr = vec2_y + currSlice->chroma_vector_adjustment[LIST_1 + list_offset][l1_refframe]; - } - else - { + if (chroma_format_idc == 1) { + vec1_y_cr = + vec1_y + + currSlice + ->chroma_vector_adjustment[LIST_0 + list_offset][l0_refframe]; + vec2_y_cr = + vec2_y + + currSlice + ->chroma_vector_adjustment[LIST_1 + list_offset][l1_refframe]; + } else { vec1_y_cr = vec1_y; vec2_y_cr = vec2_y; } no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[1]; - wp_offset = ((offset0[1] + offset1[1] + 1) >>1); - get_block_chroma(list0,vec1_x,vec1_y_cr,subpel_x,subpel_y,maxold_x,maxold_y,block_size_x_cr,block_size_y_cr,shiftpel_x,shiftpel_y,block0,block2 ,total_scale,no_ref_value,p_Vid); - get_block_chroma(list1,vec2_x,vec2_y_cr,subpel_x,subpel_y,maxold_x,maxold_y,block_size_x_cr,block_size_y_cr,shiftpel_x,shiftpel_y,block1,block3 ,total_scale,no_ref_value,p_Vid); - weighted_bi_prediction(&currSlice->mb_pred[1][joff_cr][ioff_cr],block0,block1,block_size_y_cr,block_size_x_cr,weight0[1],weight1[1],wp_offset,chroma_log2,p_Vid->max_pel_value_comp[1]); - wp_offset = ((offset0[2] + offset1[2] + 1) >>1); - weighted_bi_prediction(&currSlice->mb_pred[2][joff_cr][ioff_cr],block2,block3,block_size_y_cr,block_size_x_cr,weight0[2],weight1[2],wp_offset,chroma_log2,p_Vid->max_pel_value_comp[2]); - } + wp_offset = ((offset0[1] + offset1[1] + 1) >> 1); + get_block_chroma(list0, vec1_x, vec1_y_cr, subpel_x, subpel_y, maxold_x, + maxold_y, block_size_x_cr, block_size_y_cr, shiftpel_x, + shiftpel_y, block0, block2, total_scale, no_ref_value, + p_Vid); + get_block_chroma(list1, vec2_x, vec2_y_cr, subpel_x, subpel_y, maxold_x, + maxold_y, block_size_x_cr, block_size_y_cr, shiftpel_x, + shiftpel_y, block1, block3, total_scale, no_ref_value, + p_Vid); + weighted_bi_prediction(&currSlice->mb_pred[1][joff_cr][ioff_cr], block0, + block1, block_size_y_cr, block_size_x_cr, weight0[1], + weight1[1], wp_offset, chroma_log2, + p_Vid->max_pel_value_comp[1]); + wp_offset = ((offset0[2] + offset1[2] + 1) >> 1); + weighted_bi_prediction(&currSlice->mb_pred[2][joff_cr][ioff_cr], block2, + block3, block_size_y_cr, block_size_x_cr, weight0[2], + weight1[2], wp_offset, chroma_log2, + p_Vid->max_pel_value_comp[2]); + } } -static void perform_mc_bi(Macroblock *currMB, ColorPlane pl, StorablePicture *dec_picture, int i, int j, int block_size_x, int block_size_y) -{ +static void perform_mc_bi(Macroblock *currMB, ColorPlane pl, + StorablePicture *dec_picture, int i, int j, + int block_size_x, int block_size_y) { static const int mv_mul = 16; - int vec1_x=0, vec1_y=0, vec2_x=0, vec2_y=0; - VideoParameters *p_Vid = currMB->p_Vid; + int vec1_x = 0, vec1_y = 0, vec2_x = 0, vec2_y = 0; + VideoParameters *p_Vid = currMB->p_Vid; Slice *currSlice = currMB->p_Slice; - + int block_y_aff = currMB->block_y_aff; int i4 = currMB->block_x + i; int j4 = currMB->block_y + j; @@ -1658,7 +1723,8 @@ static void perform_mc_bi(Macroblock *currMB, ColorPlane pl, StorablePicture *de short l1_refframe = mv_info->ref_idx[LIST_1]; int list_offset = currMB->list_offset; - int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 : dec_picture->size_y_m1; + int maxold_y = (currMB->mb_field) ? (dec_picture->size_y >> 1) - 1 + : dec_picture->size_y_m1; int pady = p_Vid->iLumaPadY; int rlimit = maxold_y + pady - block_size_y - 2; int llimit = 2 - pady; @@ -1675,94 +1741,115 @@ static void perform_mc_bi(Macroblock *currMB, ColorPlane pl, StorablePicture *de imgpel *block3 = &tmp_block_l3[0][0]; // vars for get_block_luma int maxold_x = dec_picture->size_x_m1; - int shift_x = dec_picture->iLumaStride; + int shift_x = dec_picture->iLumaStride; int **tmp_res = currSlice->tmp_res; int max_imgpel_value = p_Vid->max_pel_value_comp[pl]; - imgpel no_ref_value = (imgpel) p_Vid->dc_pred_value_comp[pl]; + imgpel no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[pl]; check_motion_vector_range(l0_mv_array, currSlice); check_motion_vector_range(l1_mv_array, currSlice); vec1_x = i4 * mv_mul + l0_mv_array->mv_x; vec2_x = i4 * mv_mul + l1_mv_array->mv_x; vec1_y = (block_y_aff + j) * mv_mul + l0_mv_array->mv_y; vec2_y = (block_y_aff + j) * mv_mul + l1_mv_array->mv_y; - if (big_blocky && check_vert_mv(llimit, vec1_y, rlimit)) - { - get_block_luma(list0, vec1_x, vec1_y, block_size_x, BLOCK_SIZE_8x8, tmp_block_l0, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - get_block_luma(list0, vec1_x, vec1_y+(BLOCK_SIZE_8x8<<2), block_size_x, block_size_y-BLOCK_SIZE_8x8, tmp_block_l0+BLOCK_SIZE_8x8, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - } - else - get_block_luma(list0, vec1_x, vec1_y, block_size_x, block_size_y, tmp_block_l0,shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - if (big_blocky && check_vert_mv(llimit, vec2_y,rlimit)) - { - get_block_luma(list1, vec2_x, vec2_y, block_size_x, BLOCK_SIZE_8x8, tmp_block_l1, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - get_block_luma(list1, vec2_x, vec2_y+(BLOCK_SIZE_8x8<<2), block_size_x, block_size_y-BLOCK_SIZE_8x8, tmp_block_l1 + BLOCK_SIZE_8x8, shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - } - else - get_block_luma(list1, vec2_x, vec2_y, block_size_x, block_size_y, tmp_block_l1,shift_x,maxold_x,maxold_y,tmp_res,max_imgpel_value,no_ref_value, currMB); - bi_prediction(&currSlice->mb_pred[pl][joff],tmp_block_l0,tmp_block_l1, block_size_y, block_size_x, ioff); + if (big_blocky && check_vert_mv(llimit, vec1_y, rlimit)) { + get_block_luma(list0, vec1_x, vec1_y, block_size_x, BLOCK_SIZE_8x8, + tmp_block_l0, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + get_block_luma(list0, vec1_x, vec1_y + (BLOCK_SIZE_8x8 << 2), block_size_x, + block_size_y - BLOCK_SIZE_8x8, tmp_block_l0 + BLOCK_SIZE_8x8, + shift_x, maxold_x, maxold_y, tmp_res, max_imgpel_value, + no_ref_value, currMB); + } else + get_block_luma(list0, vec1_x, vec1_y, block_size_x, block_size_y, + tmp_block_l0, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + if (big_blocky && check_vert_mv(llimit, vec2_y, rlimit)) { + get_block_luma(list1, vec2_x, vec2_y, block_size_x, BLOCK_SIZE_8x8, + tmp_block_l1, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + get_block_luma(list1, vec2_x, vec2_y + (BLOCK_SIZE_8x8 << 2), block_size_x, + block_size_y - BLOCK_SIZE_8x8, tmp_block_l1 + BLOCK_SIZE_8x8, + shift_x, maxold_x, maxold_y, tmp_res, max_imgpel_value, + no_ref_value, currMB); + } else + get_block_luma(list1, vec2_x, vec2_y, block_size_x, block_size_y, + tmp_block_l1, shift_x, maxold_x, maxold_y, tmp_res, + max_imgpel_value, no_ref_value, currMB); + bi_prediction(&currSlice->mb_pred[pl][joff], tmp_block_l0, tmp_block_l1, + block_size_y, block_size_x, ioff); - if ((chroma_format_idc != YUV400) && (chroma_format_idc != YUV444) ) - { - int ioff_cr, joff_cr,block_size_y_cr,block_size_x_cr,vec2_y_cr,vec1_y_cr; + if ((chroma_format_idc != YUV400) && (chroma_format_idc != YUV444)) { + int ioff_cr, joff_cr, block_size_y_cr, block_size_x_cr, vec2_y_cr, + vec1_y_cr; int chroma_format_idc = p_Vid->active_sps->chroma_format_idc; int maxold_x = dec_picture->size_x_cr_m1; - int maxold_y = (currMB->mb_field) ? (dec_picture->size_y_cr >> 1) - 1 : dec_picture->size_y_cr_m1; + int maxold_y = (currMB->mb_field) ? (dec_picture->size_y_cr >> 1) - 1 + : dec_picture->size_y_cr_m1; int shiftpel_x = p_Vid->shiftpel_x; int shiftpel_y = p_Vid->shiftpel_y; int subpel_x = p_Vid->subpel_x; - int subpel_y = p_Vid->subpel_y; + int subpel_y = p_Vid->subpel_y; int total_scale = p_Vid->total_scale; if (p_Vid->mb_cr_size_x == MB_BLOCK_SIZE) { - ioff_cr = ioff; - block_size_x_cr = block_size_x; - } - else { + ioff_cr = ioff; + block_size_x_cr = block_size_x; + } else { ioff_cr = ioff >> 1; - block_size_x_cr = block_size_x >> 1; + block_size_x_cr = block_size_x >> 1; } if (p_Vid->mb_cr_size_y == MB_BLOCK_SIZE) { joff_cr = joff; block_size_y_cr = block_size_y; - } - else { + } else { joff_cr = joff >> 1; block_size_y_cr = block_size_y >> 1; } if (chroma_format_idc == 1) { - vec1_y_cr = vec1_y + currSlice->chroma_vector_adjustment[LIST_0 + list_offset][l0_refframe]; - vec2_y_cr = vec2_y + currSlice->chroma_vector_adjustment[LIST_1 + list_offset][l1_refframe]; - } - else { + vec1_y_cr = + vec1_y + + currSlice + ->chroma_vector_adjustment[LIST_0 + list_offset][l0_refframe]; + vec2_y_cr = + vec2_y + + currSlice + ->chroma_vector_adjustment[LIST_1 + list_offset][l1_refframe]; + } else { vec1_y_cr = vec1_y; vec2_y_cr = vec2_y; } no_ref_value = (imgpel)p_Vid->dc_pred_value_comp[1]; - get_block_chroma(list0,vec1_x,vec1_y_cr,subpel_x,subpel_y,maxold_x,maxold_y,block_size_x_cr,block_size_y_cr,shiftpel_x,shiftpel_y,block0,block2 ,total_scale,no_ref_value,p_Vid); - get_block_chroma(list1,vec2_x,vec2_y_cr,subpel_x,subpel_y,maxold_x,maxold_y,block_size_x_cr,block_size_y_cr,shiftpel_x,shiftpel_y,block1,block3 ,total_scale,no_ref_value,p_Vid); - bi_prediction(&currSlice->mb_pred[1][joff_cr],tmp_block_l0,tmp_block_l1, block_size_y_cr, block_size_x_cr, ioff_cr); - bi_prediction(&currSlice->mb_pred[2][joff_cr],tmp_block_l2,tmp_block_l3, block_size_y_cr, block_size_x_cr, ioff_cr); + get_block_chroma(list0, vec1_x, vec1_y_cr, subpel_x, subpel_y, maxold_x, + maxold_y, block_size_x_cr, block_size_y_cr, shiftpel_x, + shiftpel_y, block0, block2, total_scale, no_ref_value, + p_Vid); + get_block_chroma(list1, vec2_x, vec2_y_cr, subpel_x, subpel_y, maxold_x, + maxold_y, block_size_x_cr, block_size_y_cr, shiftpel_x, + shiftpel_y, block1, block3, total_scale, no_ref_value, + p_Vid); + bi_prediction(&currSlice->mb_pred[1][joff_cr], tmp_block_l0, tmp_block_l1, + block_size_y_cr, block_size_x_cr, ioff_cr); + bi_prediction(&currSlice->mb_pred[2][joff_cr], tmp_block_l2, tmp_block_l3, + block_size_y_cr, block_size_x_cr, ioff_cr); } } - -void perform_mc(Macroblock *currMB, ColorPlane pl, StorablePicture *dec_picture, int pred_dir, int i, int j, int block_size_x, int block_size_y) -{ +void perform_mc(Macroblock *currMB, ColorPlane pl, StorablePicture *dec_picture, + int pred_dir, int i, int j, int block_size_x, + int block_size_y) { Slice *currSlice = currMB->p_Slice; - assert (pred_dir<=2); - if (pred_dir != 2) - { + assert(pred_dir <= 2); + if (pred_dir != 2) { if (currSlice->weighted_pred_flag) - perform_mc_single_wp(currMB, pl, dec_picture, pred_dir, i, j, block_size_x, block_size_y); + perform_mc_single_wp(currMB, pl, dec_picture, pred_dir, i, j, + block_size_x, block_size_y); else - perform_mc_single(currMB, pl, dec_picture, pred_dir, i, j, block_size_x, block_size_y); - } - else - { + perform_mc_single(currMB, pl, dec_picture, pred_dir, i, j, block_size_x, + block_size_y); + } else { if (currSlice->weighted_bipred_idc) - perform_mc_bi_wp(currMB, pl, dec_picture, i, j, block_size_x, block_size_y); + perform_mc_bi_wp(currMB, pl, dec_picture, i, j, block_size_x, + block_size_y); else perform_mc_bi(currMB, pl, dec_picture, i, j, block_size_x, block_size_y); } } - - diff --git a/src/common/ldecod_src/memalloc.c b/src/common/ldecod_src/memalloc.c index e8eb420..8351343 100644 --- a/src/common/ldecod_src/memalloc.c +++ b/src/common/ldecod_src/memalloc.c @@ -7,56 +7,57 @@ * Memory allocation and free helper functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) - * - Alexis Michael Tourapis - * - Karsten Shring + * Main contributors (see contributors.h for copyright, address and + *affiliation details) + * - Alexis Michael Tourapis + * - Karsten Shring * ************************************************************************ */ -#include "global.h" #include "memalloc.h" +#include "global.h" - /*! - ************************************************************************ - * \brief - * Initialize 2-dimensional top and bottom field to point to the proper - * lines in frame - * - * \par Output: - * memory size in bytes - ************************************************************************/ -int init_top_bot_planes(imgpel **imgFrame, int dim0, imgpel ***imgTopField, imgpel ***imgBotField) -{ +/*! +************************************************************************ +* \brief +* Initialize 2-dimensional top and bottom field to point to the proper +* lines in frame +* +* \par Output: +* memory size in bytes +************************************************************************/ +int init_top_bot_planes(imgpel **imgFrame, int dim0, imgpel ***imgTopField, + imgpel ***imgBotField) { int i; - if((*imgTopField = (imgpel**) malloc((dim0>>1) * sizeof(imgpel*))) == NULL) + if ((*imgTopField = (imgpel **)malloc((dim0 >> 1) * sizeof(imgpel *))) == + NULL) no_mem_exit("init_top_bot_planes: imgTopField"); - if((*imgBotField = (imgpel**) malloc((dim0>>1) * sizeof(imgpel*))) == NULL) + if ((*imgBotField = (imgpel **)malloc((dim0 >> 1) * sizeof(imgpel *))) == + NULL) no_mem_exit("init_top_bot_planes: imgBotField"); - for(i = 0; i < (dim0>>1); i++) - { - (*imgTopField)[i] = imgFrame[2 * i ]; - (*imgBotField)[i] = imgFrame[2 * i + 1]; + for (i = 0; i < (dim0 >> 1); i++) { + (*imgTopField)[i] = imgFrame[2 * i]; + (*imgBotField)[i] = imgFrame[2 * i + 1]; } - return dim0 * sizeof(imgpel*); + return dim0 * sizeof(imgpel *); } - /*! - ************************************************************************ - * \brief - * free 2-dimensional top and bottom fields without freeing target memory - * - * \par Output: - * memory size in bytes - ************************************************************************/ -void free_top_bot_planes(imgpel **imgTopField, imgpel **imgBotField) -{ - free (imgTopField); - free (imgBotField); +/*! +************************************************************************ +* \brief +* free 2-dimensional top and bottom fields without freeing target memory +* +* \par Output: +* memory size in bytes +************************************************************************/ +void free_top_bot_planes(imgpel **imgTopField, imgpel **imgBotField) { + free(imgTopField); + free(imgBotField); } /*! @@ -67,19 +68,20 @@ void free_top_bot_planes(imgpel **imgTopField, imgpel **imgBotField) * \par Output: * memory size in bytes ************************************************************************/ -int get_mem2Ddist(DistortionData ***array2D, int dim0, int dim1) -{ +int get_mem2Ddist(DistortionData ***array2D, int dim0, int dim1) { int i; - if((*array2D = (DistortionData**)malloc(dim0 * sizeof(DistortionData*))) == NULL) + if ((*array2D = (DistortionData **)malloc(dim0 * sizeof(DistortionData *))) == + NULL) no_mem_exit("get_mem2Ddist: array2D"); - if((*(*array2D) = (DistortionData* )calloc(dim0 * dim1, sizeof(DistortionData ))) == NULL) + if ((*(*array2D) = (DistortionData *)calloc(dim0 * dim1, + sizeof(DistortionData))) == NULL) no_mem_exit("get_mem2Ddist: array2D"); - for(i = 1 ; i < dim0; i++) - (*array2D)[i] = (*array2D)[i-1] + dim1; + for (i = 1; i < dim0; i++) + (*array2D)[i] = (*array2D)[i - 1] + dim1; - return dim0 * (sizeof(DistortionData*) + dim1 * sizeof(DistortionData)); + return dim0 * (sizeof(DistortionData *) + dim1 * sizeof(DistortionData)); } /*! @@ -90,19 +92,20 @@ int get_mem2Ddist(DistortionData ***array2D, int dim0, int dim1) * \par Output: * memory size in bytes ************************************************************************/ -int get_mem2Dlm(LambdaParams ***array2D, int dim0, int dim1) -{ +int get_mem2Dlm(LambdaParams ***array2D, int dim0, int dim1) { int i; - if((*array2D = (LambdaParams**)malloc(dim0 * sizeof(LambdaParams*))) == NULL) + if ((*array2D = (LambdaParams **)malloc(dim0 * sizeof(LambdaParams *))) == + NULL) no_mem_exit("get_mem2Dlm: array2D"); - if((*(*array2D) = (LambdaParams* )calloc(dim0 * dim1,sizeof(LambdaParams ))) == NULL) + if ((*(*array2D) = + (LambdaParams *)calloc(dim0 * dim1, sizeof(LambdaParams))) == NULL) no_mem_exit("get_mem2Dlm: array2D"); - for(i = 1 ; i < dim0; i++) - (*array2D)[i] = (*array2D)[i-1] + dim1; + for (i = 1; i < dim0; i++) + (*array2D)[i] = (*array2D)[i - 1] + dim1; - return dim0 * (sizeof(LambdaParams*) + dim1 * sizeof(LambdaParams)); + return dim0 * (sizeof(LambdaParams *) + dim1 * sizeof(LambdaParams)); } /*! @@ -112,20 +115,16 @@ int get_mem2Dlm(LambdaParams ***array2D, int dim0, int dim1) * which was allocated with get_mem2Ddist() ************************************************************************ */ -void free_mem2Ddist(DistortionData **array2D) -{ - if (array2D) - { +void free_mem2Ddist(DistortionData **array2D) { + if (array2D) { if (*array2D) - free (*array2D); - else - error ("free_mem2Ddist: trying to free unused memory",100); + free(*array2D); + else + error("free_mem2Ddist: trying to free unused memory", 100); - free (array2D); - } - else - { - error ("free_mem2Ddist: trying to free unused memory",100); + free(array2D); + } else { + error("free_mem2Ddist: trying to free unused memory", 100); } } @@ -136,20 +135,16 @@ void free_mem2Ddist(DistortionData **array2D) * which was allocated with get_mem2Dlm() ************************************************************************ */ -void free_mem2Dlm(LambdaParams **array2D) -{ - if (array2D) - { +void free_mem2Dlm(LambdaParams **array2D) { + if (array2D) { if (*array2D) - free (*array2D); - else - error ("free_mem2Dlm: trying to free unused memory",100); + free(*array2D); + else + error("free_mem2Dlm: trying to free unused memory", 100); - free (array2D); - } - else - { - error ("free_mem2Dlm: trying to free unused memory",100); + free(array2D); + } else { + error("free_mem2Dlm: trying to free unused memory", 100); } } @@ -161,19 +156,20 @@ void free_mem2Dlm(LambdaParams **array2D) * \par Output: * memory size in bytes ************************************************************************/ -int get_mem2Dmp(PicMotionParams ***array2D, int dim0, int dim1) -{ +int get_mem2Dmp(PicMotionParams ***array2D, int dim0, int dim1) { int i; - if((*array2D = (PicMotionParams**)malloc(dim0 * sizeof(PicMotionParams*))) == NULL) + if ((*array2D = (PicMotionParams **)malloc( + dim0 * sizeof(PicMotionParams *))) == NULL) no_mem_exit("get_mem2Dmv: array2D"); - if((*(*array2D) = (PicMotionParams* )calloc(dim0 * dim1,sizeof(PicMotionParams ))) == NULL) + if ((*(*array2D) = (PicMotionParams *)calloc( + dim0 * dim1, sizeof(PicMotionParams))) == NULL) no_mem_exit("get_mem2Dmp: array2D"); - for(i = 1 ; i < dim0; i++) - (*array2D)[i] = (*array2D)[i-1] + dim1; + for (i = 1; i < dim0; i++) + (*array2D)[i] = (*array2D)[i - 1] + dim1; - return dim0 * (sizeof(PicMotionParams*) + dim1 * sizeof(PicMotionParams)); + return dim0 * (sizeof(PicMotionParams *) + dim1 * sizeof(PicMotionParams)); } /*! @@ -185,18 +181,18 @@ int get_mem2Dmp(PicMotionParams ***array2D, int dim0, int dim1) * memory size in bytes ************************************************************************ */ -int get_mem3Dmp(PicMotionParams ****array3D, int dim0, int dim1, int dim2) -{ - int i, mem_size = dim0 * sizeof(PicMotionParams**); +int get_mem3Dmp(PicMotionParams ****array3D, int dim0, int dim1, int dim2) { + int i, mem_size = dim0 * sizeof(PicMotionParams **); - if(((*array3D) = (PicMotionParams***)malloc(dim0 * sizeof(PicMotionParams**))) == NULL) + if (((*array3D) = (PicMotionParams ***)malloc( + dim0 * sizeof(PicMotionParams **))) == NULL) no_mem_exit("get_mem3Dmp: array3D"); mem_size += get_mem2Dmp(*array3D, dim0 * dim1, dim2); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array3D)[i] = (*array3D)[i - 1] + dim1; - + return mem_size; } @@ -207,24 +203,19 @@ int get_mem3Dmp(PicMotionParams ****array3D, int dim0, int dim1, int dim2) * which was allocated with get_mem2Dmp() ************************************************************************ */ -void free_mem2Dmp(PicMotionParams **array2D) -{ - if (array2D) - { +void free_mem2Dmp(PicMotionParams **array2D) { + if (array2D) { if (*array2D) - free (*array2D); - else - error ("free_mem2Dmp: trying to free unused memory",100); + free(*array2D); + else + error("free_mem2Dmp: trying to free unused memory", 100); - free (array2D); - } - else - { - error ("free_mem2Dmp: trying to free unused memory",100); + free(array2D); + } else { + error("free_mem2Dmp: trying to free unused memory", 100); } } - /*! ************************************************************************ * \brief @@ -232,21 +223,15 @@ void free_mem2Dmp(PicMotionParams **array2D) * which was allocated with get_mem3Dmp() ************************************************************************ */ -void free_mem3Dmp(PicMotionParams ***array3D) -{ - if (array3D) - { +void free_mem3Dmp(PicMotionParams ***array3D) { + if (array3D) { free_mem2Dmp(*array3D); - free (array3D); - } - else - { - error ("free_mem3Dmp: trying to free unused memory",100); + free(array3D); + } else { + error("free_mem3Dmp: trying to free unused memory", 100); } } - - /*! ************************************************************************ * \brief @@ -255,19 +240,20 @@ void free_mem3Dmp(PicMotionParams ***array3D) * \par Output: * memory size in bytes ************************************************************************/ -int get_mem2Dquant(LevelQuantParams ***array2D, int dim0, int dim1) -{ +int get_mem2Dquant(LevelQuantParams ***array2D, int dim0, int dim1) { int i; - if((*array2D = (LevelQuantParams**) malloc(dim0 * sizeof(LevelQuantParams*))) == NULL) + if ((*array2D = (LevelQuantParams **)malloc( + dim0 * sizeof(LevelQuantParams *))) == NULL) no_mem_exit("get_mem2Dquant: array2D"); - if((*(*array2D) = (LevelQuantParams* ) calloc(dim0 * dim1,sizeof(LevelQuantParams ))) == NULL) + if ((*(*array2D) = (LevelQuantParams *)calloc( + dim0 * dim1, sizeof(LevelQuantParams))) == NULL) no_mem_exit("get_mem2Dquant: array2D"); - for(i = 1 ; i < dim0; i++) - (*array2D)[i] = (*array2D)[i-1] + dim1; + for (i = 1; i < dim0; i++) + (*array2D)[i] = (*array2D)[i - 1] + dim1; - return dim0 * (sizeof(LevelQuantParams*) + dim1 * sizeof(LevelQuantParams)); + return dim0 * (sizeof(LevelQuantParams *) + dim1 * sizeof(LevelQuantParams)); } /*! @@ -279,66 +265,70 @@ int get_mem2Dquant(LevelQuantParams ***array2D, int dim0, int dim1) * memory size in bytes ************************************************************************ */ -int get_mem3Dquant(LevelQuantParams ****array3D, int dim0, int dim1, int dim2) -{ - int i, mem_size = dim0 * sizeof(LevelQuantParams**); +int get_mem3Dquant(LevelQuantParams ****array3D, int dim0, int dim1, int dim2) { + int i, mem_size = dim0 * sizeof(LevelQuantParams **); - if(((*array3D) = (LevelQuantParams***)malloc(dim0 * sizeof(LevelQuantParams**))) == NULL) + if (((*array3D) = (LevelQuantParams ***)malloc( + dim0 * sizeof(LevelQuantParams **))) == NULL) no_mem_exit("get_mem3Dquant: array3D"); mem_size += get_mem2Dquant(*array3D, dim0 * dim1, dim2); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array3D)[i] = (*array3D)[i - 1] + dim1; - + return mem_size; } /*! ************************************************************************ * \brief - * Allocate 4D memory array -> LevelQuantParams array3D[dim0][dim1][dim2][dim3] + * Allocate 4D memory array -> LevelQuantParams + *array3D[dim0][dim1][dim2][dim3] * * \par Output: * memory size in bytes ************************************************************************ */ -int get_mem4Dquant(LevelQuantParams *****array4D, int dim0, int dim1, int dim2, int dim3) -{ - int i, mem_size = dim0 * sizeof(LevelQuantParams***); +int get_mem4Dquant(LevelQuantParams *****array4D, int dim0, int dim1, int dim2, + int dim3) { + int i, mem_size = dim0 * sizeof(LevelQuantParams ***); - if(((*array4D) = (LevelQuantParams****)malloc(dim0 * sizeof(LevelQuantParams***))) == NULL) + if (((*array4D) = (LevelQuantParams ****)malloc( + dim0 * sizeof(LevelQuantParams ***))) == NULL) no_mem_exit("get_mem4Dquant: array4D"); mem_size += get_mem3Dquant(*array4D, dim0 * dim1, dim2, dim3); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array4D)[i] = (*array4D)[i - 1] + dim1; - + return mem_size; } /*! ************************************************************************ * \brief - * Allocate 5D memory array -> LevelQuantParams array3D[dim0][dim1][dim2][dim3][dim4] + * Allocate 5D memory array -> LevelQuantParams + *array3D[dim0][dim1][dim2][dim3][dim4] * * \par Output: * memory size in bytes ************************************************************************ */ -int get_mem5Dquant(LevelQuantParams ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4) -{ - int i, mem_size = dim0 * sizeof(LevelQuantParams***); +int get_mem5Dquant(LevelQuantParams ******array5D, int dim0, int dim1, int dim2, + int dim3, int dim4) { + int i, mem_size = dim0 * sizeof(LevelQuantParams ***); - if(((*array5D) = (LevelQuantParams*****)malloc(dim0 * sizeof(LevelQuantParams****))) == NULL) + if (((*array5D) = (LevelQuantParams *****)malloc( + dim0 * sizeof(LevelQuantParams ****))) == NULL) no_mem_exit("get_mem5Dquant: array5D"); mem_size += get_mem4Dquant(*array5D, dim0 * dim1, dim2, dim3, dim4); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array5D)[i] = (*array5D)[i - 1] + dim1; - + return mem_size; } @@ -349,24 +339,19 @@ int get_mem5Dquant(LevelQuantParams ******array5D, int dim0, int dim1, int dim2, * which was allocated with get_mem2Dquant() ************************************************************************ */ -void free_mem2Dquant(LevelQuantParams **array2D) -{ - if (array2D) - { +void free_mem2Dquant(LevelQuantParams **array2D) { + if (array2D) { if (*array2D) - free (*array2D); - else - error ("free_mem2Dquant: trying to free unused memory",100); + free(*array2D); + else + error("free_mem2Dquant: trying to free unused memory", 100); - free (array2D); - } - else - { - error ("free_mem2Dquant: trying to free unused memory",100); + free(array2D); + } else { + error("free_mem2Dquant: trying to free unused memory", 100); } } - /*! ************************************************************************ * \brief @@ -374,16 +359,12 @@ void free_mem2Dquant(LevelQuantParams **array2D) * which was allocated with get_mem3Dquant() ************************************************************************ */ -void free_mem3Dquant(LevelQuantParams ***array3D) -{ - if (array3D) - { +void free_mem3Dquant(LevelQuantParams ***array3D) { + if (array3D) { free_mem2Dquant(*array3D); - free (array3D); - } - else - { - error ("free_mem3Dquant: trying to free unused memory",100); + free(array3D); + } else { + error("free_mem3Dquant: trying to free unused memory", 100); } } @@ -394,16 +375,12 @@ void free_mem3Dquant(LevelQuantParams ***array3D) * which was allocated with get_mem4Dquant() ************************************************************************ */ -void free_mem4Dquant(LevelQuantParams ****array4D) -{ - if (array4D) - { +void free_mem4Dquant(LevelQuantParams ****array4D) { + if (array4D) { free_mem3Dquant(*array4D); - free (array4D); - } - else - { - error ("free_mem4Dquant: trying to free unused memory",100); + free(array4D); + } else { + error("free_mem4Dquant: trying to free unused memory", 100); } } @@ -414,20 +391,15 @@ void free_mem4Dquant(LevelQuantParams ****array4D) * which was allocated with get_mem5Dquant() ************************************************************************ */ -void free_mem5Dquant(LevelQuantParams *****array5D) -{ - if (array5D) - { +void free_mem5Dquant(LevelQuantParams *****array5D) { + if (array5D) { free_mem4Dquant(*array5D); - free (array5D); - } - else - { - error ("free_mem5Dquant: trying to free unused memory",100); + free(array5D); + } else { + error("free_mem5Dquant: trying to free unused memory", 100); } } - /*! ************************************************************************ * \brief @@ -436,19 +408,21 @@ void free_mem5Dquant(LevelQuantParams *****array5D) * \par Output: * memory size in bytes ************************************************************************/ -int get_mem2D_spp(StorablePicturePtr ***array2D, int dim0, int dim1) -{ +int get_mem2D_spp(StorablePicturePtr ***array2D, int dim0, int dim1) { int i; - if((*array2D = (StorablePicturePtr**)malloc(dim0 * sizeof(StorablePicturePtr*))) == NULL) + if ((*array2D = (StorablePicturePtr **)malloc( + dim0 * sizeof(StorablePicturePtr *))) == NULL) no_mem_exit("get_mem2D_spp: array2D"); - if((*(*array2D) = (StorablePicturePtr* )calloc(dim0 * dim1,sizeof(StorablePicturePtr ))) == NULL) + if ((*(*array2D) = (StorablePicturePtr *)calloc( + dim0 * dim1, sizeof(StorablePicturePtr))) == NULL) no_mem_exit("get_mem2D_spp: array2D"); - for(i = 1 ; i < dim0; i++) - (*array2D)[i] = (*array2D)[i-1] + dim1; + for (i = 1; i < dim0; i++) + (*array2D)[i] = (*array2D)[i - 1] + dim1; - return dim0 * (sizeof(StorablePicturePtr*) + dim1 * sizeof(StorablePicturePtr)); + return dim0 * + (sizeof(StorablePicturePtr *) + dim1 * sizeof(StorablePicturePtr)); } /*! @@ -460,18 +434,19 @@ int get_mem2D_spp(StorablePicturePtr ***array2D, int dim0, int dim1) * memory size in bytes ************************************************************************ */ -int get_mem3D_spp(StorablePicturePtr ****array3D, int dim0, int dim1, int dim2) -{ - int i, mem_size = dim0 * sizeof(StorablePicturePtr**); +int get_mem3D_spp(StorablePicturePtr ****array3D, int dim0, int dim1, + int dim2) { + int i, mem_size = dim0 * sizeof(StorablePicturePtr **); - if(((*array3D) = (StorablePicturePtr***)malloc(dim0 * sizeof(StorablePicturePtr**))) == NULL) + if (((*array3D) = (StorablePicturePtr ***)malloc( + dim0 * sizeof(StorablePicturePtr **))) == NULL) no_mem_exit("get_mem3D_spp: array3D"); mem_size += get_mem2D_spp(*array3D, dim0 * dim1, dim2); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array3D)[i] = (*array3D)[i - 1] + dim1; - + return mem_size; } @@ -483,19 +458,20 @@ int get_mem3D_spp(StorablePicturePtr ****array3D, int dim0, int dim1, int dim2) * \par Output: * memory size in bytes ************************************************************************/ -int get_mem2Dmv(MotionVector ***array2D, int dim0, int dim1) -{ +int get_mem2Dmv(MotionVector ***array2D, int dim0, int dim1) { int i; - if((*array2D = (MotionVector**)malloc(dim0 * sizeof(MotionVector*))) == NULL) + if ((*array2D = (MotionVector **)malloc(dim0 * sizeof(MotionVector *))) == + NULL) no_mem_exit("get_mem2Dmv: array2D"); - if((*(*array2D) = (MotionVector* )calloc(dim0 * dim1,sizeof(MotionVector ))) == NULL) + if ((*(*array2D) = + (MotionVector *)calloc(dim0 * dim1, sizeof(MotionVector))) == NULL) no_mem_exit("get_mem2Dmv: array2D"); - for(i = 1 ; i < dim0; i++) - (*array2D)[i] = (*array2D)[i-1] + dim1; + for (i = 1; i < dim0; i++) + (*array2D)[i] = (*array2D)[i - 1] + dim1; - return dim0 * (sizeof(MotionVector*) + dim1 * sizeof(MotionVector)); + return dim0 * (sizeof(MotionVector *) + dim1 * sizeof(MotionVector)); } /*! @@ -507,18 +483,18 @@ int get_mem2Dmv(MotionVector ***array2D, int dim0, int dim1) * memory size in bytes ************************************************************************ */ -int get_mem3Dmv(MotionVector ****array3D, int dim0, int dim1, int dim2) -{ - int i, mem_size = dim0 * sizeof(MotionVector**); +int get_mem3Dmv(MotionVector ****array3D, int dim0, int dim1, int dim2) { + int i, mem_size = dim0 * sizeof(MotionVector **); - if(((*array3D) = (MotionVector***)malloc(dim0 * sizeof(MotionVector**))) == NULL) + if (((*array3D) = (MotionVector ***)malloc(dim0 * sizeof(MotionVector **))) == + NULL) no_mem_exit("get_mem3Dmv: array3D"); mem_size += get_mem2Dmv(*array3D, dim0 * dim1, dim2); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array3D)[i] = (*array3D)[i - 1] + dim1; - + return mem_size; } @@ -531,90 +507,97 @@ int get_mem3Dmv(MotionVector ****array3D, int dim0, int dim1, int dim2) * memory size in bytes ************************************************************************ */ -int get_mem4Dmv(MotionVector *****array4D, int dim0, int dim1, int dim2, int dim3) -{ - int i, mem_size = dim0 * sizeof(MotionVector***); +int get_mem4Dmv(MotionVector *****array4D, int dim0, int dim1, int dim2, + int dim3) { + int i, mem_size = dim0 * sizeof(MotionVector ***); - if(((*array4D) = (MotionVector****)malloc(dim0 * sizeof(MotionVector***))) == NULL) + if (((*array4D) = + (MotionVector ****)malloc(dim0 * sizeof(MotionVector ***))) == NULL) no_mem_exit("get_mem4Dpel: array4D"); mem_size += get_mem3Dmv(*array4D, dim0 * dim1, dim2, dim3); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array4D)[i] = (*array4D)[i - 1] + dim1; - + return mem_size; } /*! ************************************************************************ * \brief - * Allocate 5D memory array -> MotionVector array3D[dim0][dim1][dim2][dim3][dim4] + * Allocate 5D memory array -> MotionVector + *array3D[dim0][dim1][dim2][dim3][dim4] * * \par Output: * memory size in bytes ************************************************************************ */ -int get_mem5Dmv(MotionVector ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4) -{ - int i, mem_size = dim0 * sizeof(MotionVector***); +int get_mem5Dmv(MotionVector ******array5D, int dim0, int dim1, int dim2, + int dim3, int dim4) { + int i, mem_size = dim0 * sizeof(MotionVector ***); - if(((*array5D) = (MotionVector*****)malloc(dim0 * sizeof(MotionVector****))) == NULL) + if (((*array5D) = (MotionVector *****)malloc( + dim0 * sizeof(MotionVector ****))) == NULL) no_mem_exit("get_mem5Dpel: array5D"); mem_size += get_mem4Dmv(*array5D, dim0 * dim1, dim2, dim3, dim4); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array5D)[i] = (*array5D)[i - 1] + dim1; - + return mem_size; } /*! ************************************************************************ * \brief - * Allocate 6D memory array -> MotionVector array6D[dim0][dim1][dim2][dim3][dim4][dim5] + * Allocate 6D memory array -> MotionVector + *array6D[dim0][dim1][dim2][dim3][dim4][dim5] * * \par Output: * memory size in bytes ************************************************************************ */ -int get_mem6Dmv(MotionVector *******array6D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5) -{ - int i, mem_size = dim0 * sizeof(MotionVector*****); +int get_mem6Dmv(MotionVector *******array6D, int dim0, int dim1, int dim2, + int dim3, int dim4, int dim5) { + int i, mem_size = dim0 * sizeof(MotionVector *****); - if(((*array6D) = (MotionVector******)malloc(dim0 * sizeof(MotionVector*****))) == NULL) + if (((*array6D) = (MotionVector ******)malloc( + dim0 * sizeof(MotionVector *****))) == NULL) no_mem_exit("get_mem5Dpel: array6D"); mem_size += get_mem5Dmv(*array6D, dim0 * dim1, dim2, dim3, dim4, dim5); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array6D)[i] = (*array6D)[i - 1] + dim1; - + return mem_size; } /*! ************************************************************************ * \brief - * Allocate 7D memory array -> MotionVector array7D[dim0][dim1][dim2][dim3][dim4][dim5][dim6] + * Allocate 7D memory array -> MotionVector + *array7D[dim0][dim1][dim2][dim3][dim4][dim5][dim6] * * \par Output: * memory size in bytes ************************************************************************ */ -int get_mem7Dmv(MotionVector ********array7D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5, int dim6) -{ - int i, mem_size = dim0 * sizeof(MotionVector******); +int get_mem7Dmv(MotionVector ********array7D, int dim0, int dim1, int dim2, + int dim3, int dim4, int dim5, int dim6) { + int i, mem_size = dim0 * sizeof(MotionVector ******); - if(((*array7D) = (MotionVector*******)malloc(dim0 * sizeof(MotionVector******))) == NULL) + if (((*array7D) = (MotionVector *******)malloc( + dim0 * sizeof(MotionVector ******))) == NULL) no_mem_exit("get_mem7Dmv: array7D"); mem_size += get_mem6Dmv(*array7D, dim0 * dim1, dim2, dim3, dim4, dim5, dim6); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array7D)[i] = (*array7D)[i - 1] + dim1; - + return mem_size; } @@ -625,24 +608,19 @@ int get_mem7Dmv(MotionVector ********array7D, int dim0, int dim1, int dim2, int * which was allocated with get_mem2D_spp() ************************************************************************ */ -void free_mem2D_spp(StorablePicturePtr **array2D) -{ - if (array2D) - { +void free_mem2D_spp(StorablePicturePtr **array2D) { + if (array2D) { if (*array2D) - free (*array2D); - else - error ("free_mem2D_spp: trying to free unused memory",100); + free(*array2D); + else + error("free_mem2D_spp: trying to free unused memory", 100); - free (array2D); - } - else - { - error ("free_mem2D_spp: trying to free unused memory",100); + free(array2D); + } else { + error("free_mem2D_spp: trying to free unused memory", 100); } } - /*! ************************************************************************ * \brief @@ -650,20 +628,15 @@ void free_mem2D_spp(StorablePicturePtr **array2D) * which was allocated with get_mem3D_spp() ************************************************************************ */ -void free_mem3D_spp(StorablePicturePtr ***array3D) -{ - if (array3D) - { +void free_mem3D_spp(StorablePicturePtr ***array3D) { + if (array3D) { free_mem2D_spp(*array3D); - free (array3D); - } - else - { - error ("free_mem3D_spp: trying to free unused memory",100); + free(array3D); + } else { + error("free_mem3D_spp: trying to free unused memory", 100); } } - /*! ************************************************************************ * \brief @@ -671,24 +644,19 @@ void free_mem3D_spp(StorablePicturePtr ***array3D) * which was allocated with get_mem2Dmv() ************************************************************************ */ -void free_mem2Dmv(MotionVector **array2D) -{ - if (array2D) - { +void free_mem2Dmv(MotionVector **array2D) { + if (array2D) { if (*array2D) - free (*array2D); - else - error ("free_mem2Dmv: trying to free unused memory",100); + free(*array2D); + else + error("free_mem2Dmv: trying to free unused memory", 100); - free (array2D); - } - else - { - error ("free_mem2Dmv: trying to free unused memory",100); + free(array2D); + } else { + error("free_mem2Dmv: trying to free unused memory", 100); } } - /*! ************************************************************************ * \brief @@ -696,16 +664,12 @@ void free_mem2Dmv(MotionVector **array2D) * which was allocated with get_mem3Dmv() ************************************************************************ */ -void free_mem3Dmv(MotionVector ***array3D) -{ - if (array3D) - { +void free_mem3Dmv(MotionVector ***array3D) { + if (array3D) { free_mem2Dmv(*array3D); - free (array3D); - } - else - { - error ("free_mem3Dmv: trying to free unused memory",100); + free(array3D); + } else { + error("free_mem3Dmv: trying to free unused memory", 100); } } @@ -716,16 +680,12 @@ void free_mem3Dmv(MotionVector ***array3D) * which was allocated with get_mem4Dmv() ************************************************************************ */ -void free_mem4Dmv(MotionVector ****array4D) -{ - if (array4D) - { +void free_mem4Dmv(MotionVector ****array4D) { + if (array4D) { free_mem3Dmv(*array4D); - free (array4D); - } - else - { - error ("free_mem4Dmv: trying to free unused memory",100); + free(array4D); + } else { + error("free_mem4Dmv: trying to free unused memory", 100); } } @@ -736,16 +696,12 @@ void free_mem4Dmv(MotionVector ****array4D) * which was allocated with get_mem5Dmv() ************************************************************************ */ -void free_mem5Dmv(MotionVector *****array5D) -{ - if (array5D) - { +void free_mem5Dmv(MotionVector *****array5D) { + if (array5D) { free_mem4Dmv(*array5D); - free (array5D); - } - else - { - error ("free_mem5Dmv: trying to free unused memory",100); + free(array5D); + } else { + error("free_mem5Dmv: trying to free unused memory", 100); } } /*! @@ -755,16 +711,12 @@ void free_mem5Dmv(MotionVector *****array5D) * which was allocated with get_mem6Dmv() ************************************************************************ */ -void free_mem6Dmv(MotionVector ******array6D) -{ - if (array6D) - { +void free_mem6Dmv(MotionVector ******array6D) { + if (array6D) { free_mem5Dmv(*array6D); - free (array6D); - } - else - { - error ("free_mem6Dmv: trying to free unused memory",100); + free(array6D); + } else { + error("free_mem6Dmv: trying to free unused memory", 100); } } @@ -775,21 +727,15 @@ void free_mem6Dmv(MotionVector ******array6D) * which was allocated with get_mem7Dmv() ************************************************************************ */ -void free_mem7Dmv(MotionVector *******array7D) -{ - if (array7D) - { +void free_mem7Dmv(MotionVector *******array7D) { + if (array7D) { free_mem6Dmv(*array7D); - free (array7D); - } - else - { - error ("free_mem7Dmv: trying to free unused memory",100); + free(array7D); + } else { + error("free_mem7Dmv: trying to free unused memory", 100); } } - - /*! ************************************************************************ * \brief @@ -798,12 +744,11 @@ void free_mem7Dmv(MotionVector *******array7D) * \par Output: * memory size in bytes ************************************************************************/ -int get_mem1Dpel(imgpel **array1D, int dim0) -{ - if((*array1D = (imgpel*)calloc(dim0, sizeof(imgpel))) == NULL) +int get_mem1Dpel(imgpel **array1D, int dim0) { + if ((*array1D = (imgpel *)calloc(dim0, sizeof(imgpel))) == NULL) no_mem_exit("get_mem1Dpel: arra12D"); - return (sizeof(imgpel*) + dim0 * sizeof(imgpel)); + return (sizeof(imgpel *) + dim0 * sizeof(imgpel)); } /*! @@ -814,47 +759,45 @@ int get_mem1Dpel(imgpel **array1D, int dim0) * \par Output: * memory size in bytes ************************************************************************/ -int get_mem2Dpel(imgpel ***array2D, int dim0, int dim1) -{ +int get_mem2Dpel(imgpel ***array2D, int dim0, int dim1) { int i; - if((*array2D = (imgpel**)malloc(dim0 * sizeof(imgpel*))) == NULL) + if ((*array2D = (imgpel **)malloc(dim0 * sizeof(imgpel *))) == NULL) no_mem_exit("get_mem2Dpel: array2D"); - if((*(*array2D) = (imgpel* )calloc(dim0 * dim1,sizeof(imgpel ))) == NULL) + if ((*(*array2D) = (imgpel *)calloc(dim0 * dim1, sizeof(imgpel))) == NULL) no_mem_exit("get_mem2Dpel: array2D"); - for(i = 1 ; i < dim0; i++) - (*array2D)[i] = (*array2D)[i-1] + dim1; + for (i = 1; i < dim0; i++) + (*array2D)[i] = (*array2D)[i - 1] + dim1; - return dim0 * (sizeof(imgpel*) + dim1 * sizeof(imgpel)); + return dim0 * (sizeof(imgpel *) + dim1 * sizeof(imgpel)); } -int get_mem2DpelWithPad(imgpel ***array2D, int dim0, int dim1, int iPadY, int iPadX) -{ +int get_mem2DpelWithPad(imgpel ***array2D, int dim0, int dim1, int iPadY, + int iPadX) { int i; imgpel *curr = NULL; int iHeight, iWidth; - - iHeight = dim0+2*iPadY; - iWidth = dim1+2*iPadX; - if((*array2D = (imgpel**)malloc(iHeight*sizeof(imgpel*))) == NULL) + + iHeight = dim0 + 2 * iPadY; + iWidth = dim1 + 2 * iPadX; + if ((*array2D = (imgpel **)malloc(iHeight * sizeof(imgpel *))) == NULL) no_mem_exit("get_mem2DpelWithPad: array2D"); - if((*(*array2D) = (imgpel* )calloc(iHeight * iWidth, sizeof(imgpel ))) == NULL) + if ((*(*array2D) = (imgpel *)calloc(iHeight * iWidth, sizeof(imgpel))) == + NULL) no_mem_exit("get_mem2DpelWithPad: array2D"); (*array2D)[0] += iPadX; curr = (*array2D)[0]; - for(i = 1 ; i < iHeight; i++) - { + for (i = 1; i < iHeight; i++) { curr += iWidth; (*array2D)[i] = curr; } (*array2D) = &((*array2D)[iPadY]); - return iHeight * (sizeof(imgpel*) + iWidth * sizeof(imgpel)); + return iHeight * (sizeof(imgpel *) + iWidth * sizeof(imgpel)); } - /*! ************************************************************************ * \brief @@ -864,50 +807,49 @@ int get_mem2DpelWithPad(imgpel ***array2D, int dim0, int dim1, int iPadY, int iP * memory size in bytes ************************************************************************ */ -int get_mem3Dpel(imgpel ****array3D, int dim0, int dim1, int dim2) -{ - int i, mem_size = dim0 * sizeof(imgpel**); +int get_mem3Dpel(imgpel ****array3D, int dim0, int dim1, int dim2) { + int i, mem_size = dim0 * sizeof(imgpel **); - if(((*array3D) = (imgpel***)malloc(dim0 * sizeof(imgpel**))) == NULL) + if (((*array3D) = (imgpel ***)malloc(dim0 * sizeof(imgpel **))) == NULL) no_mem_exit("get_mem3Dpel: array3D"); mem_size += get_mem2Dpel(*array3D, dim0 * dim1, dim2); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array3D)[i] = (*array3D)[i - 1] + dim1; - + return mem_size; } -int get_mem3DpelWithPad(imgpel ****array3D, int dim0, int dim1, int dim2, int iPadY, int iPadX) -{ - int i, mem_size = dim0 * sizeof(imgpel**); +int get_mem3DpelWithPad(imgpel ****array3D, int dim0, int dim1, int dim2, + int iPadY, int iPadX) { + int i, mem_size = dim0 * sizeof(imgpel **); - if(((*array3D) = (imgpel***)malloc(dim0*sizeof(imgpel**))) == NULL) + if (((*array3D) = (imgpel ***)malloc(dim0 * sizeof(imgpel **))) == NULL) no_mem_exit("get_mem3DpelWithPad: array3D"); - mem_size += get_mem2DpelWithPad(*array3D, dim0*dim1+2*(dim0-1)*iPadY, dim2, iPadY, iPadX); + mem_size += get_mem2DpelWithPad( + *array3D, dim0 * dim1 + 2 * (dim0 - 1) * iPadY, dim2, iPadY, iPadX); + + for (i = 1; i < dim0; i++) + (*array3D)[i] = (*array3D)[i - 1] + (dim1 + 2 * iPadY); - for(i = 1; i < dim0; i++) - (*array3D)[i] = (*array3D)[i - 1] + (dim1+2*iPadY); - return mem_size; } -int get_mem3DpelWithPadSeparately(imgpel ****array3D, int dim0, int dim1, int dim2, int iPadY, int iPadX) -{ - int i, mem_size = dim0 * sizeof(imgpel**); +int get_mem3DpelWithPadSeparately(imgpel ****array3D, int dim0, int dim1, + int dim2, int iPadY, int iPadX) { + int i, mem_size = dim0 * sizeof(imgpel **); - if(((*array3D) = (imgpel***)malloc(dim0*sizeof(imgpel**))) == NULL) + if (((*array3D) = (imgpel ***)malloc(dim0 * sizeof(imgpel **))) == NULL) no_mem_exit("get_mem3DpelWithPadSeparately: array3D"); - for(i = 0; i < dim0; i++) - mem_size += get_mem2DpelWithPad((*array3D)+i, dim1, dim2, iPadY, iPadX); - + for (i = 0; i < dim0; i++) + mem_size += get_mem2DpelWithPad((*array3D) + i, dim1, dim2, iPadY, iPadX); + return mem_size; } - /*! ************************************************************************ * \brief @@ -917,46 +859,47 @@ int get_mem3DpelWithPadSeparately(imgpel ****array3D, int dim0, int dim1, int di * memory size in bytes ************************************************************************ */ -int get_mem4Dpel(imgpel *****array4D, int dim0, int dim1, int dim2, int dim3) -{ - int i, mem_size = dim0 * sizeof(imgpel***); +int get_mem4Dpel(imgpel *****array4D, int dim0, int dim1, int dim2, int dim3) { + int i, mem_size = dim0 * sizeof(imgpel ***); - if(((*array4D) = (imgpel****)malloc(dim0 * sizeof(imgpel***))) == NULL) + if (((*array4D) = (imgpel ****)malloc(dim0 * sizeof(imgpel ***))) == NULL) no_mem_exit("get_mem4Dpel: array4D"); mem_size += get_mem3Dpel(*array4D, dim0 * dim1, dim2, dim3); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array4D)[i] = (*array4D)[i - 1] + dim1; return mem_size; } -int get_mem4DpelWithPad(imgpel *****array4D, int dim0, int dim1, int dim2, int dim3, int iPadY, int iPadX) -{ - int i, mem_size = dim0 * sizeof(imgpel***); +int get_mem4DpelWithPad(imgpel *****array4D, int dim0, int dim1, int dim2, + int dim3, int iPadY, int iPadX) { + int i, mem_size = dim0 * sizeof(imgpel ***); - if(((*array4D) = (imgpel****)malloc(dim0 * sizeof(imgpel***))) == NULL) + if (((*array4D) = (imgpel ****)malloc(dim0 * sizeof(imgpel ***))) == NULL) no_mem_exit("get_mem4DpelWithPad: array4D"); - mem_size += get_mem3DpelWithPad(*array4D, dim0 * dim1, dim2, dim3, iPadY, iPadX); + mem_size += + get_mem3DpelWithPad(*array4D, dim0 * dim1, dim2, dim3, iPadY, iPadX); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array4D)[i] = (*array4D)[i - 1] + dim1; return mem_size; } -int get_mem4DpelWithPadSeparately(imgpel *****array4D, int dim0, int dim1, int dim2, int dim3, int iPadY, int iPadX) -{ - int i, mem_size = dim0 * sizeof(imgpel***); +int get_mem4DpelWithPadSeparately(imgpel *****array4D, int dim0, int dim1, + int dim2, int dim3, int iPadY, int iPadX) { + int i, mem_size = dim0 * sizeof(imgpel ***); - if(((*array4D) = (imgpel****)malloc(dim0 * sizeof(imgpel***))) == NULL) + if (((*array4D) = (imgpel ****)malloc(dim0 * sizeof(imgpel ***))) == NULL) no_mem_exit("get_mem4DpelWithPadSeparately: array4D"); - mem_size += get_mem3DpelWithPadSeparately(*array4D, dim0 * dim1, dim2, dim3, iPadY, iPadX); + mem_size += get_mem3DpelWithPadSeparately(*array4D, dim0 * dim1, dim2, dim3, + iPadY, iPadX); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array4D)[i] = (*array4D)[i - 1] + dim1; return mem_size; @@ -971,46 +914,49 @@ int get_mem4DpelWithPadSeparately(imgpel *****array4D, int dim0, int dim1, int d * memory size in bytes ************************************************************************ */ -int get_mem5Dpel(imgpel ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4) -{ - int i, mem_size = dim0 * sizeof(imgpel****); +int get_mem5Dpel(imgpel ******array5D, int dim0, int dim1, int dim2, int dim3, + int dim4) { + int i, mem_size = dim0 * sizeof(imgpel ****); - if(((*array5D) = (imgpel*****)malloc(dim0 * sizeof(imgpel****))) == NULL) + if (((*array5D) = (imgpel *****)malloc(dim0 * sizeof(imgpel ****))) == NULL) no_mem_exit("get_mem5Dpel: array5D"); mem_size += get_mem4Dpel(*array5D, dim0 * dim1, dim2, dim3, dim4); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array5D)[i] = (*array5D)[i - 1] + dim1; return mem_size; } -int get_mem5DpelWithPad(imgpel ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4, int iPadY, int iPadX) -{ - int i, mem_size = dim0 * sizeof(imgpel****); +int get_mem5DpelWithPad(imgpel ******array5D, int dim0, int dim1, int dim2, + int dim3, int dim4, int iPadY, int iPadX) { + int i, mem_size = dim0 * sizeof(imgpel ****); - if(((*array5D) = (imgpel*****)malloc(dim0 * sizeof(imgpel****))) == NULL) + if (((*array5D) = (imgpel *****)malloc(dim0 * sizeof(imgpel ****))) == NULL) no_mem_exit("get_mem5DpelWithPad: array5D"); - mem_size += get_mem4DpelWithPad(*array5D, dim0 * dim1, dim2, dim3, dim4, iPadY, iPadX); + mem_size += get_mem4DpelWithPad(*array5D, dim0 * dim1, dim2, dim3, dim4, + iPadY, iPadX); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array5D)[i] = (*array5D)[i - 1] + dim1; return mem_size; } -int get_mem5DpelWithPadSeparately(imgpel ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4, int iPadY, int iPadX) -{ - int i, mem_size = dim0 * sizeof(imgpel****); +int get_mem5DpelWithPadSeparately(imgpel ******array5D, int dim0, int dim1, + int dim2, int dim3, int dim4, int iPadY, + int iPadX) { + int i, mem_size = dim0 * sizeof(imgpel ****); - if(((*array5D) = (imgpel*****)malloc(dim0 * sizeof(imgpel****))) == NULL) + if (((*array5D) = (imgpel *****)malloc(dim0 * sizeof(imgpel ****))) == NULL) no_mem_exit("get_mem5DpelWithPadSeparately: array5D"); - mem_size += get_mem4DpelWithPadSeparately(*array5D, dim0 * dim1, dim2, dim3, dim4, iPadY, iPadX); + mem_size += get_mem4DpelWithPadSeparately(*array5D, dim0 * dim1, dim2, dim3, + dim4, iPadY, iPadX); - for(i = 1; i < dim0; i++) + for (i = 1; i < dim0; i++) (*array5D)[i] = (*array5D)[i - 1] + dim1; return mem_size; @@ -1023,15 +969,11 @@ int get_mem5DpelWithPadSeparately(imgpel ******array5D, int dim0, int dim1, int * which was allocated with get_mem1Dpel() ************************************************************************ */ -void free_mem1Dpel(imgpel *array1D) -{ - if (array1D) - { - free (array1D); - } - else - { - error ("free_mem1Dpel: trying to free unused memory",100); +void free_mem1Dpel(imgpel *array1D) { + if (array1D) { + free(array1D); + } else { + error("free_mem1Dpel: trying to free unused memory", 100); } } @@ -1042,41 +984,32 @@ void free_mem1Dpel(imgpel *array1D) * which was allocated with get_mem2Dpel() ************************************************************************ */ -void free_mem2Dpel(imgpel **array2D) -{ - if (array2D) - { +void free_mem2Dpel(imgpel **array2D) { + if (array2D) { if (*array2D) - free (*array2D); - else - error ("free_mem2Dpel: trying to free unused memory",100); + free(*array2D); + else + error("free_mem2Dpel: trying to free unused memory", 100); - free (array2D); - } - else - { - error ("free_mem2Dpel: trying to free unused memory",100); + free(array2D); + } else { + error("free_mem2Dpel: trying to free unused memory", 100); } } -void free_mem2DpelWithPad(imgpel **array2D, int iPadY, int iPadX) -{ - if (array2D) - { +void free_mem2DpelWithPad(imgpel **array2D, int iPadY, int iPadX) { + if (array2D) { if (*array2D) - free (array2D[-iPadY]-iPadX); - else - error ("free_mem2DpelWithPad: trying to free unused memory",100); + free(array2D[-iPadY] - iPadX); + else + error("free_mem2DpelWithPad: trying to free unused memory", 100); - free (&array2D[-iPadY]); - } - else - { - error ("free_mem2DpelWithPad: trying to free unused memory",100); + free(&array2D[-iPadY]); + } else { + error("free_mem2DpelWithPad: trying to free unused memory", 100); } } - /*! ************************************************************************ * \brief @@ -1084,51 +1017,37 @@ void free_mem2DpelWithPad(imgpel **array2D, int iPadY, int iPadX) * which was allocated with get_mem3Dpel() ************************************************************************ */ -void free_mem3Dpel(imgpel ***array3D) -{ - if (array3D) - { +void free_mem3Dpel(imgpel ***array3D) { + if (array3D) { free_mem2Dpel(*array3D); - free (array3D); - } - else - { - error ("free_mem3Dpel: trying to free unused memory",100); + free(array3D); + } else { + error("free_mem3Dpel: trying to free unused memory", 100); } } -void free_mem3DpelWithPad(imgpel ***array3D, int iPadY, int iPadX) -{ - if (array3D) - { +void free_mem3DpelWithPad(imgpel ***array3D, int iPadY, int iPadX) { + if (array3D) { free_mem2DpelWithPad(*array3D, iPadY, iPadX); - free (array3D); + free(array3D); + } else { + error("free_mem3Dpel: trying to free unused memory", 100); } - else - { - error ("free_mem3Dpel: trying to free unused memory",100); - } - } -void free_mem3DpelWithPadSeparately(imgpel ***array3D, int iDim12, int iPadY, int iPadX) -{ - if (array3D) - { +void free_mem3DpelWithPadSeparately(imgpel ***array3D, int iDim12, int iPadY, + int iPadX) { + if (array3D) { int i; - for(i=0; i short array6D[dim0][dim1][dim2][dim3][dim4][dim5] + * Allocate 6D memory array -> short + *array6D[dim0][dim1][dim2][dim3][dim4][dim5] * * \par Output: * memory size in bytes ************************************************************************ */ -int get_mem6Dshort(short *******array6D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5) -{ - int i, mem_size = dim0 * sizeof(short*****); +int get_mem6Dshort(short *******array6D, int dim0, int dim1, int dim2, int dim3, + int dim4, int dim5) { + int i, mem_size = dim0 * sizeof(short *****); - if(((*array6D) = (short******)malloc(dim0 * sizeof(short*****))) == NULL) + if (((*array6D) = (short ******)malloc(dim0 * sizeof(short *****))) == NULL) no_mem_exit("get_mem6Dshort: array6D"); mem_size += get_mem5Dshort(*array6D, dim0 * dim1, dim2, dim3, dim4, dim5); - for(i = 1; i < dim0; i++) - (*array6D)[i] = (*array6D)[i-1] + dim1; + for (i = 1; i < dim0; i++) + (*array6D)[i] = (*array6D)[i - 1] + dim1; return mem_size; } @@ -2058,23 +1880,25 @@ int get_mem6Dshort(short *******array6D, int dim0, int dim1, int dim2, int dim3, /*! ************************************************************************ * \brief - * Allocate 7D memory array -> short array7D[dim0][dim1][dim2][dim3][dim4][dim5][dim6] + * Allocate 7D memory array -> short + *array7D[dim0][dim1][dim2][dim3][dim4][dim5][dim6] * * \par Output: * memory size in bytes ************************************************************************ */ -int get_mem7Dshort(short ********array7D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5, int dim6) -{ - int i, mem_size = dim0 * sizeof(short******); +int get_mem7Dshort(short ********array7D, int dim0, int dim1, int dim2, + int dim3, int dim4, int dim5, int dim6) { + int i, mem_size = dim0 * sizeof(short ******); - if(((*array7D) = (short*******)malloc(dim0 * sizeof(short******))) == NULL) + if (((*array7D) = (short *******)malloc(dim0 * sizeof(short ******))) == NULL) no_mem_exit("get_mem7Dshort: array7D"); - mem_size += get_mem6Dshort(*array7D, dim0 * dim1, dim2, dim3, dim4, dim5, dim6); + mem_size += + get_mem6Dshort(*array7D, dim0 * dim1, dim2, dim3, dim4, dim5, dim6); - for(i = 1; i < dim0; i++) - (*array7D)[i] = (*array7D)[i-1] + dim1; + for (i = 1; i < dim0; i++) + (*array7D)[i] = (*array7D)[i - 1] + dim1; return mem_size; } @@ -2086,19 +1910,16 @@ int get_mem7Dshort(short ********array7D, int dim0, int dim1, int dim2, int dim3 * which was allocated with get_mem2Duint16() ************************************************************************ */ -void free_mem2Duint16(uint16 **array2D) -{ - if (array2D) - { +void free_mem2Duint16(uint16 **array2D) { + if (array2D) { if (*array2D) - free (*array2D); - else error ("free_mem2Duint16: trying to free unused memory",100); + free(*array2D); + else + error("free_mem2Duint16: trying to free unused memory", 100); - free (array2D); - } - else - { - error ("free_mem2Duint16: trying to free unused memory",100); + free(array2D); + } else { + error("free_mem2Duint16: trying to free unused memory", 100); } } @@ -2109,16 +1930,12 @@ void free_mem2Duint16(uint16 **array2D) * which was allocated with get_mem3Duint16() ************************************************************************ */ -void free_mem3Duint16(uint16 ***array3D) -{ - if (array3D) - { - free_mem2Duint16(*array3D); - free (array3D); - } - else - { - error ("free_mem3Duint16: trying to free unused memory",100); +void free_mem3Duint16(uint16 ***array3D) { + if (array3D) { + free_mem2Duint16(*array3D); + free(array3D); + } else { + error("free_mem3Duint16: trying to free unused memory", 100); } } @@ -2129,16 +1946,12 @@ void free_mem3Duint16(uint16 ***array3D) * which was allocated with get_mem4Duint16() ************************************************************************ */ -void free_mem4Duint16(uint16 ****array4D) -{ - if (array4D) - { - free_mem3Duint16( *array4D); - free (array4D); - } - else - { - error ("free_mem4Duint16: trying to free unused memory",100); +void free_mem4Duint16(uint16 ****array4D) { + if (array4D) { + free_mem3Duint16(*array4D); + free(array4D); + } else { + error("free_mem4Duint16: trying to free unused memory", 100); } } @@ -2149,19 +1962,16 @@ void free_mem4Duint16(uint16 ****array4D) * which was allocated with get_mem2Dshort() ************************************************************************ */ -void free_mem2Dshort(short **array2D) -{ - if (array2D) - { +void free_mem2Dshort(short **array2D) { + if (array2D) { if (*array2D) - free (*array2D); - else error ("free_mem2Dshort: trying to free unused memory",100); + free(*array2D); + else + error("free_mem2Dshort: trying to free unused memory", 100); - free (array2D); - } - else - { - error ("free_mem2Dshort: trying to free unused memory",100); + free(array2D); + } else { + error("free_mem2Dshort: trying to free unused memory", 100); } } @@ -2172,16 +1982,12 @@ void free_mem2Dshort(short **array2D) * which was allocated with get_mem3Dshort() ************************************************************************ */ -void free_mem3Dshort(short ***array3D) -{ - if (array3D) - { - free_mem2Dshort(*array3D); - free (array3D); - } - else - { - error ("free_mem3Dshort: trying to free unused memory",100); +void free_mem3Dshort(short ***array3D) { + if (array3D) { + free_mem2Dshort(*array3D); + free(array3D); + } else { + error("free_mem3Dshort: trying to free unused memory", 100); } } @@ -2192,16 +1998,12 @@ void free_mem3Dshort(short ***array3D) * which was allocated with get_mem4Dshort() ************************************************************************ */ -void free_mem4Dshort(short ****array4D) -{ - if (array4D) - { - free_mem3Dshort( *array4D); - free (array4D); - } - else - { - error ("free_mem4Dshort: trying to free unused memory",100); +void free_mem4Dshort(short ****array4D) { + if (array4D) { + free_mem3Dshort(*array4D); + free(array4D); + } else { + error("free_mem4Dshort: trying to free unused memory", 100); } } @@ -2212,16 +2014,12 @@ void free_mem4Dshort(short ****array4D) * which was allocated with get_mem5Dshort() ************************************************************************ */ -void free_mem5Dshort(short *****array5D) -{ - if (array5D) - { - free_mem4Dshort( *array5D) ; - free (array5D); - } - else - { - error ("free_mem5Dshort: trying to free unused memory",100); +void free_mem5Dshort(short *****array5D) { + if (array5D) { + free_mem4Dshort(*array5D); + free(array5D); + } else { + error("free_mem5Dshort: trying to free unused memory", 100); } } @@ -2232,16 +2030,12 @@ void free_mem5Dshort(short *****array5D) * which was allocated with get_mem6Dshort() ************************************************************************ */ -void free_mem6Dshort(short ******array6D) -{ - if (array6D) - { - free_mem5Dshort( *array6D); - free (array6D); - } - else - { - error ("free_mem6Dshort: trying to free unused memory",100); +void free_mem6Dshort(short ******array6D) { + if (array6D) { + free_mem5Dshort(*array6D); + free(array6D); + } else { + error("free_mem6Dshort: trying to free unused memory", 100); } } @@ -2252,16 +2046,12 @@ void free_mem6Dshort(short ******array6D) * which was allocated with get_mem7Dshort() ************************************************************************ */ -void free_mem7Dshort(short *******array7D) -{ - if (array7D) - { - free_mem6Dshort( *array7D); - free (array7D); - } - else - { - error ("free_mem7Dshort: trying to free unused memory",100); +void free_mem7Dshort(short *******array7D) { + if (array7D) { + free_mem6Dshort(*array7D); + free(array7D); + } else { + error("free_mem7Dshort: trying to free unused memory", 100); } } @@ -2274,20 +2064,19 @@ void free_mem7Dshort(short *******array7D) * memory size in bytes ************************************************************************ */ -int get_mem2Ddouble(double ***array2D, int dim0, int dim1) -{ +int get_mem2Ddouble(double ***array2D, int dim0, int dim1) { int i; - if((*array2D = (double**)malloc(dim0 * sizeof(double*))) == NULL) - no_mem_exit("get_mem2Ddouble: array2D"); - - if(((*array2D)[0] = (double* )calloc(dim0 * dim1,sizeof(double ))) == NULL) + if ((*array2D = (double **)malloc(dim0 * sizeof(double *))) == NULL) no_mem_exit("get_mem2Ddouble: array2D"); - for(i=1 ; i -offset_y - 1; i--) - { - (*array2D)[i] = (*array2D)[i+1] - dim1; + for (i = -1; i > -offset_y - 1; i--) { + (*array2D)[i] = (*array2D)[i + 1] - dim1; } - for(i=1 ; i < dim1 - offset_y; i++) - (*array2D)[i] = (*array2D)[i-1] + dim1; + for (i = 1; i < dim1 - offset_y; i++) + (*array2D)[i] = (*array2D)[i - 1] + dim1; - return dim0 * (sizeof(short*) + dim1 * sizeof(short)); + return dim0 * (sizeof(short *) + dim1 * sizeof(short)); } /*! @@ -2411,27 +2198,26 @@ int get_offset_mem2Dshort(short ***array2D, int dim0, int dim1, int offset_y, in * memory size in bytes ************************************************************************ */ -int get_mem3Doint(int ****array3D, int dim0, int dim1, int dim2, int offset) -{ - int i,j; +int get_mem3Doint(int ****array3D, int dim0, int dim1, int dim2, int offset) { + int i, j; - if(((*array3D) = (int***)malloc(dim0 * sizeof(int**))) == NULL) + if (((*array3D) = (int ***)malloc(dim0 * sizeof(int **))) == NULL) no_mem_exit("get_mem3Doint: array3D"); - if(((*array3D)[0] = (int** )calloc(dim0 * dim1, sizeof(int*))) == NULL) + if (((*array3D)[0] = (int **)calloc(dim0 * dim1, sizeof(int *))) == NULL) no_mem_exit("get_mem3Doint: array3D"); - (*array3D) [0] += offset; + (*array3D)[0] += offset; - for(i=1 ; i * - Karsten Shring ************************************************************************************* @@ -21,145 +22,153 @@ * Get motion vector predictor ************************************************************************ */ -static void GetMotionVectorPredictorMBAFF (Macroblock *currMB, - PixelPos *block, // <--> block neighbors - MotionVector *pmv, - short ref_frame, - PicMotionParams **mv_info, - int list, - int mb_x, - int mb_y, - int blockshape_x, - int blockshape_y) -{ - int mv_a, mv_b, mv_c, pred_vec=0; +static void +GetMotionVectorPredictorMBAFF(Macroblock *currMB, + PixelPos *block, // <--> block neighbors + MotionVector *pmv, short ref_frame, + PicMotionParams **mv_info, int list, int mb_x, + int mb_y, int blockshape_x, int blockshape_y) { + int mv_a, mv_b, mv_c, pred_vec = 0; int mvPredType, rFrameL, rFrameU, rFrameUR; int hv; VideoParameters *p_Vid = currMB->p_Vid; mvPredType = MVPRED_MEDIAN; - - if (currMB->mb_field) - { - rFrameL = block[0].available - ? (p_Vid->mb_data[block[0].mb_addr].mb_field - ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] - : mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] * 2) : -1; - rFrameU = block[1].available - ? (p_Vid->mb_data[block[1].mb_addr].mb_field - ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] - : mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] * 2) : -1; - rFrameUR = block[2].available - ? (p_Vid->mb_data[block[2].mb_addr].mb_field - ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] - : mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] * 2) : -1; + if (currMB->mb_field) { + rFrameL = + block[0].available + ? (p_Vid->mb_data[block[0].mb_addr].mb_field + ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] + : mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] * 2) + : -1; + rFrameU = + block[1].available + ? (p_Vid->mb_data[block[1].mb_addr].mb_field + ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] + : mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] * 2) + : -1; + rFrameUR = + block[2].available + ? (p_Vid->mb_data[block[2].mb_addr].mb_field + ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] + : mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] * 2) + : -1; + } else { + rFrameL = + block[0].available + ? (p_Vid->mb_data[block[0].mb_addr].mb_field + ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] >> 1 + : mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list]) + : -1; + rFrameU = + block[1].available + ? (p_Vid->mb_data[block[1].mb_addr].mb_field + ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] >> 1 + : mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list]) + : -1; + rFrameUR = + block[2].available + ? (p_Vid->mb_data[block[2].mb_addr].mb_field + ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] >> 1 + : mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list]) + : -1; } - else - { - rFrameL = block[0].available - ? (p_Vid->mb_data[block[0].mb_addr].mb_field - ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] >>1 - : mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list]) : -1; - rFrameU = block[1].available - ? (p_Vid->mb_data[block[1].mb_addr].mb_field - ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] >>1 - : mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list]) : -1; - rFrameUR = block[2].available - ? (p_Vid->mb_data[block[2].mb_addr].mb_field - ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] >>1 - : mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list]) : -1; - } - /* Prediction if only one of the neighbors uses the reference frame - * we are checking - */ - if(rFrameL == ref_frame && rFrameU != ref_frame && rFrameUR != ref_frame) + * we are checking + */ + if (rFrameL == ref_frame && rFrameU != ref_frame && rFrameUR != ref_frame) mvPredType = MVPRED_L; - else if(rFrameL != ref_frame && rFrameU == ref_frame && rFrameUR != ref_frame) + else if (rFrameL != ref_frame && rFrameU == ref_frame && + rFrameUR != ref_frame) mvPredType = MVPRED_U; - else if(rFrameL != ref_frame && rFrameU != ref_frame && rFrameUR == ref_frame) + else if (rFrameL != ref_frame && rFrameU != ref_frame && + rFrameUR == ref_frame) mvPredType = MVPRED_UR; // Directional predictions - if(blockshape_x == 8 && blockshape_y == 16) - { - if(mb_x == 0) - { - if(rFrameL == ref_frame) + if (blockshape_x == 8 && blockshape_y == 16) { + if (mb_x == 0) { + if (rFrameL == ref_frame) mvPredType = MVPRED_L; - } - else - { - if( rFrameUR == ref_frame) + } else { + if (rFrameUR == ref_frame) mvPredType = MVPRED_UR; } - } - else if(blockshape_x == 16 && blockshape_y == 8) - { - if(mb_y == 0) - { - if(rFrameU == ref_frame) + } else if (blockshape_x == 16 && blockshape_y == 8) { + if (mb_y == 0) { + if (rFrameU == ref_frame) mvPredType = MVPRED_U; - } - else - { - if(rFrameL == ref_frame) + } else { + if (rFrameL == ref_frame) mvPredType = MVPRED_L; } } - for (hv=0; hv < 2; hv++) - { - if (hv == 0) - { - mv_a = block[0].available ? mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_x : 0; - mv_b = block[1].available ? mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_x : 0; - mv_c = block[2].available ? mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_x : 0; - } - else - { - if (currMB->mb_field) - { - mv_a = block[0].available ? p_Vid->mb_data[block[0].mb_addr].mb_field - ? mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y - : mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y / 2 - : 0; - mv_b = block[1].available ? p_Vid->mb_data[block[1].mb_addr].mb_field - ? mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y - : mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y / 2 - : 0; - mv_c = block[2].available ? p_Vid->mb_data[block[2].mb_addr].mb_field - ? mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y - : mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y / 2 - : 0; - } - else - { - mv_a = block[0].available ? p_Vid->mb_data[block[0].mb_addr].mb_field - ? mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y * 2 - : mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y - : 0; - mv_b = block[1].available ? p_Vid->mb_data[block[1].mb_addr].mb_field - ? mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y * 2 - : mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y - : 0; - mv_c = block[2].available ? p_Vid->mb_data[block[2].mb_addr].mb_field - ? mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y * 2 - : mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y - : 0; + for (hv = 0; hv < 2; hv++) { + if (hv == 0) { + mv_a = block[0].available + ? mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_x + : 0; + mv_b = block[1].available + ? mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_x + : 0; + mv_c = block[2].available + ? mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_x + : 0; + } else { + if (currMB->mb_field) { + mv_a = + block[0].available + ? p_Vid->mb_data[block[0].mb_addr].mb_field + ? mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y + : mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y / + 2 + : 0; + mv_b = + block[1].available + ? p_Vid->mb_data[block[1].mb_addr].mb_field + ? mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y + : mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y / + 2 + : 0; + mv_c = + block[2].available + ? p_Vid->mb_data[block[2].mb_addr].mb_field + ? mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y + : mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y / + 2 + : 0; + } else { + mv_a = + block[0].available + ? p_Vid->mb_data[block[0].mb_addr].mb_field + ? mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y * + 2 + : mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y + : 0; + mv_b = + block[1].available + ? p_Vid->mb_data[block[1].mb_addr].mb_field + ? mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y * + 2 + : mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y + : 0; + mv_c = + block[2].available + ? p_Vid->mb_data[block[2].mb_addr].mb_field + ? mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y * + 2 + : mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y + : 0; } } - switch (mvPredType) - { + switch (mvPredType) { case MVPRED_MEDIAN: - if(!(block[1].available || block[2].available)) - { + if (!(block[1].available || block[2].available)) { pred_vec = mv_a; - } - else - { + } else { pred_vec = imedian(mv_a, mv_b, mv_c); } break; @@ -177,9 +186,9 @@ static void GetMotionVectorPredictorMBAFF (Macroblock *currMB, } if (hv == 0) - pmv->mv_x = (short) pred_vec; + pmv->mv_x = (short)pred_vec; else - pmv->mv_y = (short) pred_vec; + pmv->mv_y = (short)pred_vec; } } @@ -189,112 +198,96 @@ static void GetMotionVectorPredictorMBAFF (Macroblock *currMB, * Get motion vector predictor ************************************************************************ */ -static void GetMotionVectorPredictorNormal (Macroblock *currMB, - PixelPos *block, // <--> block neighbors - MotionVector *pmv, - short ref_frame, - PicMotionParams **mv_info, - int list, - int mb_x, - int mb_y, - int blockshape_x, - int blockshape_y) -{ +static void +GetMotionVectorPredictorNormal(Macroblock *currMB, + PixelPos *block, // <--> block neighbors + MotionVector *pmv, short ref_frame, + PicMotionParams **mv_info, int list, int mb_x, + int mb_y, int blockshape_x, int blockshape_y) { int mvPredType = MVPRED_MEDIAN; - int rFrameL = block[0].available ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] : -1; - int rFrameU = block[1].available ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] : -1; - int rFrameUR = block[2].available ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] : -1; + int rFrameL = block[0].available + ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] + : -1; + int rFrameU = block[1].available + ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] + : -1; + int rFrameUR = block[2].available + ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] + : -1; /* Prediction if only one of the neighbors uses the reference frame - * we are checking - */ - if(rFrameL == ref_frame && rFrameU != ref_frame && rFrameUR != ref_frame) + * we are checking + */ + if (rFrameL == ref_frame && rFrameU != ref_frame && rFrameUR != ref_frame) mvPredType = MVPRED_L; - else if(rFrameL != ref_frame && rFrameU == ref_frame && rFrameUR != ref_frame) + else if (rFrameL != ref_frame && rFrameU == ref_frame && + rFrameUR != ref_frame) mvPredType = MVPRED_U; - else if(rFrameL != ref_frame && rFrameU != ref_frame && rFrameUR == ref_frame) + else if (rFrameL != ref_frame && rFrameU != ref_frame && + rFrameUR == ref_frame) mvPredType = MVPRED_UR; // Directional predictions - if(blockshape_x == 8 && blockshape_y == 16) - { - if(mb_x == 0) - { - if(rFrameL == ref_frame) + if (blockshape_x == 8 && blockshape_y == 16) { + if (mb_x == 0) { + if (rFrameL == ref_frame) mvPredType = MVPRED_L; - } - else - { - if(rFrameUR == ref_frame) + } else { + if (rFrameUR == ref_frame) mvPredType = MVPRED_UR; } - } - else if(blockshape_x == 16 && blockshape_y == 8) - { - if(mb_y == 0) - { - if(rFrameU == ref_frame) + } else if (blockshape_x == 16 && blockshape_y == 8) { + if (mb_y == 0) { + if (rFrameU == ref_frame) mvPredType = MVPRED_U; - } - else - { - if(rFrameL == ref_frame) + } else { + if (rFrameL == ref_frame) mvPredType = MVPRED_L; } } - switch (mvPredType) - { + switch (mvPredType) { case MVPRED_MEDIAN: - if(!(block[1].available || block[2].available)) - { - if (block[0].available) - { + if (!(block[1].available || block[2].available)) { + if (block[0].available) { *pmv = mv_info[block[0].pos_y][block[0].pos_x].mv[list]; - } - else - { + } else { *pmv = zero_mv; - } - } - else - { - MotionVector *mv_a = block[0].available ? &mv_info[block[0].pos_y][block[0].pos_x].mv[list] : (MotionVector *) &zero_mv; - MotionVector *mv_b = block[1].available ? &mv_info[block[1].pos_y][block[1].pos_x].mv[list] : (MotionVector *) &zero_mv; - MotionVector *mv_c = block[2].available ? &mv_info[block[2].pos_y][block[2].pos_x].mv[list] : (MotionVector *) &zero_mv; + } + } else { + MotionVector *mv_a = + block[0].available ? &mv_info[block[0].pos_y][block[0].pos_x].mv[list] + : (MotionVector *)&zero_mv; + MotionVector *mv_b = + block[1].available ? &mv_info[block[1].pos_y][block[1].pos_x].mv[list] + : (MotionVector *)&zero_mv; + MotionVector *mv_c = + block[2].available ? &mv_info[block[2].pos_y][block[2].pos_x].mv[list] + : (MotionVector *)&zero_mv; - pmv->mv_x = (short) imedian(mv_a->mv_x, mv_b->mv_x, mv_c->mv_x); - pmv->mv_y = (short) imedian(mv_a->mv_y, mv_b->mv_y, mv_c->mv_y); - } + pmv->mv_x = (short)imedian(mv_a->mv_x, mv_b->mv_x, mv_c->mv_x); + pmv->mv_y = (short)imedian(mv_a->mv_y, mv_b->mv_y, mv_c->mv_y); + } break; case MVPRED_L: - if (block[0].available) - { + if (block[0].available) { *pmv = mv_info[block[0].pos_y][block[0].pos_x].mv[list]; - } - else - { + } else { *pmv = zero_mv; } break; case MVPRED_U: - if (block[1].available) - { + if (block[1].available) { *pmv = mv_info[block[1].pos_y][block[1].pos_x].mv[list]; - } - else - { + } else { *pmv = zero_mv; } break; case MVPRED_UR: - if (block[2].available) - { + if (block[2].available) { *pmv = mv_info[block[2].pos_y][block[2].pos_x].mv[list]; - } - else - { + } else { *pmv = zero_mv; } break; @@ -303,8 +296,7 @@ static void GetMotionVectorPredictorNormal (Macroblock *currMB, } } -void init_motion_vector_prediction(Macroblock *currMB, int mb_aff_frame_flag) -{ +void init_motion_vector_prediction(Macroblock *currMB, int mb_aff_frame_flag) { if (mb_aff_frame_flag) currMB->GetMVPredictor = GetMotionVectorPredictorMBAFF; else diff --git a/src/common/ldecod_src/nal.c b/src/common/ldecod_src/nal.c index ac9d00a..5ee1a44 100644 --- a/src/common/ldecod_src/nal.c +++ b/src/common/ldecod_src/nal.c @@ -8,66 +8,63 @@ * Sequence Packets (RBSP), and then onto String Of Data Bits (SODB) * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Shankar L. Regunathan * - Tobias Oelbaum -************************************************************************ + ************************************************************************ */ #include "contributors.h" #include "global.h" - /*! - ************************************************************************ - * \brief - * Converts RBSP to string of data bits - * \param streamBuffer - * pointer to buffer containing data - * \param last_byte_pos - * position of the last byte containing data. - * \return last_byte_pos - * position of the last byte pos. If the last-byte was entirely a stuffing byte, - * it is removed, and the last_byte_pos is updated. - * +/*! +************************************************************************ +* \brief +* Converts RBSP to string of data bits +* \param streamBuffer +* pointer to buffer containing data +* \param last_byte_pos +* position of the last byte containing data. +* \return last_byte_pos +* position of the last byte pos. If the last-byte was entirely a +*stuffing byte, it is removed, and the last_byte_pos is updated. +* ************************************************************************/ -int RBSPtoSODB(byte *streamBuffer, int last_byte_pos) -{ +int RBSPtoSODB(byte *streamBuffer, int last_byte_pos) { int ctr_bit, bitoffset; bitoffset = 0; - //find trailing 1 - ctr_bit = (streamBuffer[last_byte_pos-1] & (0x01< 0x03)) + if (count == ZEROBYTES_SHORTSTARTCODE && streamBuffer[i] == 0x03) { + // check the 4th byte after 0x000003, except when cabac_zero_word is used, + // in which case the last three bytes of this NAL unit must be 0x000003 + if ((i < end_bytepos - 1) && (streamBuffer[i + 1] > 0x03)) return -1; - //if cabac_zero_word is used, the final byte of this NAL unit(0x03) is discarded, and the last two bytes of RBSP must be 0x0000 - if(i == end_bytepos-1) + // if cabac_zero_word is used, the final byte of this NAL unit(0x03) is + // discarded, and the last two bytes of RBSP must be 0x0000 + if (i == end_bytepos - 1) return j; ++i; count = 0; } streamBuffer[j] = streamBuffer[i]; - if(streamBuffer[i] == 0x00) + if (streamBuffer[i] == 0x00) ++count; else count = 0; diff --git a/src/common/ldecod_src/nalu.c b/src/common/ldecod_src/nalu.c index 51b98c7..c079f0d 100644 --- a/src/common/ldecod_src/nalu.c +++ b/src/common/ldecod_src/nalu.c @@ -7,21 +7,21 @@ * Decoder NALU support functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger ************************************************************************ */ -#include "global.h" -#include "annexb.h" #include "nalu.h" +#include "annexb.h" +#include "global.h" #include "memalloc.h" #include "rtp.h" #if (MVC_EXTENSION_ENABLE) #include "vlc.h" #endif - /*! ************************************************************************************* * \brief @@ -30,37 +30,35 @@ * \param * p_Vid: Imageparameter information * \param -* filemode: +* filemode: * ************************************************************************************* */ -void initBitsFile (VideoParameters *p_Vid, int filemode) -{ +void initBitsFile(VideoParameters *p_Vid, int filemode) { - switch (filemode) - { + switch (filemode) { case PAR_OF_ANNEXB: - if ((p_Vid->bitsfile = (BitsFile *) calloc(1, sizeof(BitsFile)))==NULL) + if ((p_Vid->bitsfile = (BitsFile *)calloc(1, sizeof(BitsFile))) == NULL) no_mem_exit("initBitsFile : p_Vid->bitsfile"); - p_Vid->bitsfile->OpenBitsFile = OpenAnnexBFile; - p_Vid->bitsfile->CloseBitsFile = CloseAnnexBFile; - p_Vid->bitsfile->GetNALU = GetAnnexbNALU; + p_Vid->bitsfile->OpenBitsFile = OpenAnnexBFile; + p_Vid->bitsfile->CloseBitsFile = CloseAnnexBFile; + p_Vid->bitsfile->GetNALU = GetAnnexbNALU; malloc_annex_b(p_Vid); break; case PAR_OF_RTP: - if ((p_Vid->bitsfile = (BitsFile *) calloc(1, sizeof(BitsFile)))==NULL) + if ((p_Vid->bitsfile = (BitsFile *)calloc(1, sizeof(BitsFile))) == NULL) no_mem_exit("initBitsFile : p_Vid->bitsfile"); - p_Vid->bitsfile->OpenBitsFile = OpenRTPFile; - p_Vid->bitsfile->CloseBitsFile = CloseRTPFile; - p_Vid->bitsfile->GetNALU = GetRTPNALU; + p_Vid->bitsfile->OpenBitsFile = OpenRTPFile; + p_Vid->bitsfile->CloseBitsFile = CloseRTPFile; + p_Vid->bitsfile->GetNALU = GetRTPNALU; break; default: - error ("initBitsFile: Unknown bitstream file mode", 255); + error("initBitsFile: Unknown bitstream file mode", 255); break; - } + } } /*! @@ -76,13 +74,12 @@ void initBitsFile (VideoParameters *p_Vid, int filemode) ************************************************************************************* */ -static int NALUtoRBSP (NALU_t *nalu) -{ - assert (nalu != NULL); +static int NALUtoRBSP(NALU_t *nalu) { + assert(nalu != NULL); - nalu->len = EBSPtoRBSP (nalu->buf, nalu->len, 1) ; + nalu->len = EBSPtoRBSP(nalu->buf, nalu->len, 1); - return nalu->len ; + return nalu->len; } /*! @@ -91,126 +88,121 @@ static int NALUtoRBSP (NALU_t *nalu) * Read the next NAL unit (with error handling) ************************************************************************ */ -int read_next_nalu(VideoParameters *p_Vid, NALU_t *nalu) -{ +int read_next_nalu(VideoParameters *p_Vid, NALU_t *nalu) { InputParameters *p_Inp = p_Vid->p_Inp; int ret; ret = p_Vid->bitsfile->GetNALU(p_Vid, nalu); - if (ret < 0) - { - snprintf (errortext, ET_SIZE, "Error while getting the NALU in file format %s, exit\n", p_Inp->FileFormat==PAR_OF_ANNEXB?"Annex B":"RTP"); - error (errortext, 601); + if (ret < 0) { + snprintf(errortext, ET_SIZE, + "Error while getting the NALU in file format %s, exit\n", + p_Inp->FileFormat == PAR_OF_ANNEXB ? "Annex B" : "RTP"); + error(errortext, 601); } - if (ret == 0) - { - //FreeNALU(nalu); + if (ret == 0) { + // FreeNALU(nalu); return 0; } - //In some cases, zero_byte shall be present. If current NALU is a VCL NALU, we can't tell - //whether it is the first VCL NALU at this point, so only non-VCL NAL unit is checked here. + // In some cases, zero_byte shall be present. If current NALU is a VCL NALU, + // we can't tell whether it is the first VCL NALU at this point, so only + // non-VCL NAL unit is checked here. CheckZeroByteNonVCL(p_Vid, nalu); ret = NALUtoRBSP(nalu); if (ret < 0) - error ("Invalid startcode emulation prevention found.", 602); - + error("Invalid startcode emulation prevention found.", 602); // Got a NALU - if (nalu->forbidden_bit) - { - error ("Found NALU with forbidden_bit set, bit error?", 603); + if (nalu->forbidden_bit) { + error("Found NALU with forbidden_bit set, bit error?", 603); } return nalu->len; } -void CheckZeroByteNonVCL(VideoParameters *p_Vid, NALU_t *nalu) -{ - int CheckZeroByte=0; +void CheckZeroByteNonVCL(VideoParameters *p_Vid, NALU_t *nalu) { + int CheckZeroByte = 0; - //This function deals only with non-VCL NAL units - if(nalu->nal_unit_type>=1&&nalu->nal_unit_type<=5) + // This function deals only with non-VCL NAL units + if (nalu->nal_unit_type >= 1 && nalu->nal_unit_type <= 5) return; - //for SPS and PPS, zero_byte shall exist - if(nalu->nal_unit_type==NALU_TYPE_SPS || nalu->nal_unit_type==NALU_TYPE_PPS) - CheckZeroByte=1; - //check the possibility of the current NALU to be the start of a new access unit, according to 7.4.1.2.3 - if(nalu->nal_unit_type==NALU_TYPE_AUD || nalu->nal_unit_type==NALU_TYPE_SPS || - nalu->nal_unit_type==NALU_TYPE_PPS || nalu->nal_unit_type==NALU_TYPE_SEI || - (nalu->nal_unit_type>=13 && nalu->nal_unit_type<=18)) - { - if(p_Vid->LastAccessUnitExists) - { - p_Vid->LastAccessUnitExists=0; //deliver the last access unit to decoder - p_Vid->NALUCount=0; + // for SPS and PPS, zero_byte shall exist + if (nalu->nal_unit_type == NALU_TYPE_SPS || + nalu->nal_unit_type == NALU_TYPE_PPS) + CheckZeroByte = 1; + // check the possibility of the current NALU to be the start of a new access + // unit, according to 7.4.1.2.3 + if (nalu->nal_unit_type == NALU_TYPE_AUD || + nalu->nal_unit_type == NALU_TYPE_SPS || + nalu->nal_unit_type == NALU_TYPE_PPS || + nalu->nal_unit_type == NALU_TYPE_SEI || + (nalu->nal_unit_type >= 13 && nalu->nal_unit_type <= 18)) { + if (p_Vid->LastAccessUnitExists) { + p_Vid->LastAccessUnitExists = 0; // deliver the last access unit to + // decoder + p_Vid->NALUCount = 0; } } p_Vid->NALUCount++; - //for the first NAL unit in an access unit, zero_byte shall exists - if(p_Vid->NALUCount==1) - CheckZeroByte=1; - if(CheckZeroByte && nalu->startcodeprefix_len==3) - { + // for the first NAL unit in an access unit, zero_byte shall exists + if (p_Vid->NALUCount == 1) + CheckZeroByte = 1; + if (CheckZeroByte && nalu->startcodeprefix_len == 3) { printf("Warning: zero_byte shall exist\n"); - //because it is not a very serious problem, we do not exit here + // because it is not a very serious problem, we do not exit here } } -void CheckZeroByteVCL(VideoParameters *p_Vid, NALU_t *nalu) -{ - int CheckZeroByte=0; +void CheckZeroByteVCL(VideoParameters *p_Vid, NALU_t *nalu) { + int CheckZeroByte = 0; - //This function deals only with VCL NAL units - if(!(nalu->nal_unit_type>=NALU_TYPE_SLICE && nalu->nal_unit_type <= NALU_TYPE_IDR)) + // This function deals only with VCL NAL units + if (!(nalu->nal_unit_type >= NALU_TYPE_SLICE && + nalu->nal_unit_type <= NALU_TYPE_IDR)) return; - if(p_Vid->LastAccessUnitExists) - { - p_Vid->NALUCount=0; + if (p_Vid->LastAccessUnitExists) { + p_Vid->NALUCount = 0; } p_Vid->NALUCount++; - //the first VCL NAL unit that is the first NAL unit after last VCL NAL unit indicates - //the start of a new access unit and hence the first NAL unit of the new access unit. (sounds like a tongue twister :-) - if(p_Vid->NALUCount == 1) + // the first VCL NAL unit that is the first NAL unit after last VCL NAL unit + // indicates the start of a new access unit and hence the first NAL unit of + // the new access unit. (sounds like a tongue twister :-) + if (p_Vid->NALUCount == 1) CheckZeroByte = 1; p_Vid->LastAccessUnitExists = 1; - if(CheckZeroByte && nalu->startcodeprefix_len==3) - { + if (CheckZeroByte && nalu->startcodeprefix_len == 3) { printf("warning: zero_byte shall exist\n"); - //because it is not a very serious problem, we do not exit here + // because it is not a very serious problem, we do not exit here } } #if (MVC_EXTENSION_ENABLE) -void nal_unit_header_mvc_extension(NALUnitHeaderMVCExt_t *NaluHeaderMVCExt, Bitstream *s) -{ - //to be implemented; - NaluHeaderMVCExt->non_idr_flag = u_v (1, "non_idr_flag" , s); - NaluHeaderMVCExt->priority_id = u_v (6, "priority_id" , s); - NaluHeaderMVCExt->view_id = u_v (10, "view_id" , s); - NaluHeaderMVCExt->temporal_id = u_v (3, "temporal_id" , s); - NaluHeaderMVCExt->anchor_pic_flag = u_v (1, "anchor_pic_flag" , s); - NaluHeaderMVCExt->inter_view_flag = u_v (1, "inter_view_flag" , s); - NaluHeaderMVCExt->reserved_one_bit = u_v (1, "reserved_one_bit" , s); - if(NaluHeaderMVCExt->reserved_one_bit != 1) - { - printf("Nalu Header MVC Extension: reserved_one_bit is not 1!\n"); - } +void nal_unit_header_mvc_extension(NALUnitHeaderMVCExt_t *NaluHeaderMVCExt, + Bitstream *s) { + // to be implemented; + NaluHeaderMVCExt->non_idr_flag = u_v(1, "non_idr_flag", s); + NaluHeaderMVCExt->priority_id = u_v(6, "priority_id", s); + NaluHeaderMVCExt->view_id = u_v(10, "view_id", s); + NaluHeaderMVCExt->temporal_id = u_v(3, "temporal_id", s); + NaluHeaderMVCExt->anchor_pic_flag = u_v(1, "anchor_pic_flag", s); + NaluHeaderMVCExt->inter_view_flag = u_v(1, "inter_view_flag", s); + NaluHeaderMVCExt->reserved_one_bit = u_v(1, "reserved_one_bit", s); + if (NaluHeaderMVCExt->reserved_one_bit != 1) { + printf("Nalu Header MVC Extension: reserved_one_bit is not 1!\n"); + } } -void nal_unit_header_svc_extension( void ) -{ - //to be implemented for Annex G; +void nal_unit_header_svc_extension(void) { + // to be implemented for Annex G; } -void prefix_nal_unit_svc( void ) -{ - //to be implemented for Annex G; +void prefix_nal_unit_svc(void) { + // to be implemented for Annex G; } #endif diff --git a/src/common/ldecod_src/nalucommon.c b/src/common/ldecod_src/nalucommon.c index a12e3ee..bba57e5 100644 --- a/src/common/ldecod_src/nalucommon.c +++ b/src/common/ldecod_src/nalucommon.c @@ -7,15 +7,15 @@ * Common NALU support functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger ************************************************************************ */ #include "global.h" -#include "nalu.h" #include "memalloc.h" - +#include "nalu.h" /*! ************************************************************************************* @@ -29,25 +29,22 @@ * pointer to a NALU ************************************************************************************* */ -NALU_t *AllocNALU(int buffersize) -{ +NALU_t *AllocNALU(int buffersize) { NALU_t *n; - if ((n = (NALU_t*)calloc (1, sizeof (NALU_t))) == NULL) - no_mem_exit ("AllocNALU: n"); + if ((n = (NALU_t *)calloc(1, sizeof(NALU_t))) == NULL) + no_mem_exit("AllocNALU: n"); - n->max_size=buffersize; + n->max_size = buffersize; - if ((n->buf = (byte*)calloc (buffersize, sizeof (byte))) == NULL) - { - free (n); - no_mem_exit ("AllocNALU: n->buf"); + if ((n->buf = (byte *)calloc(buffersize, sizeof(byte))) == NULL) { + free(n); + no_mem_exit("AllocNALU: n->buf"); } return n; } - /*! ************************************************************************************* * \brief @@ -58,15 +55,12 @@ NALU_t *AllocNALU(int buffersize) * ************************************************************************************* */ -void FreeNALU(NALU_t *n) -{ - if (n != NULL) - { - if (n->buf != NULL) - { +void FreeNALU(NALU_t *n) { + if (n != NULL) { + if (n->buf != NULL) { free(n->buf); - n->buf=NULL; + n->buf = NULL; } - free (n); + free(n); } } diff --git a/src/common/ldecod_src/output.c b/src/common/ldecod_src/output.c index 2cd2708..e4cb97d 100644 --- a/src/common/ldecod_src/output.c +++ b/src/common/ldecod_src/output.c @@ -7,7 +7,8 @@ * Output an image and Trance support * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Karsten Suehring ************************************************************************ */ @@ -18,13 +19,13 @@ #include "contributors.h" +#include "fast_memory.h" #include "global.h" -#include "mbuffer.h" #include "image.h" +#include "input.h" +#include "mbuffer.h" #include "memalloc.h" #include "sei.h" -#include "input.h" -#include "fast_memory.h" #ifdef SPEC #define STRCMP strcmp @@ -32,11 +33,20 @@ #define STRCMP strcasecmp #endif -static void write_out_picture(VideoParameters *p_Vid, StorablePicture *p, int p_out); -static void img2buf_byte (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int symbol_size_in_bytes, int crop_left, int crop_right, int crop_top, int crop_bottom, int iOutStride); -static void img2buf_normal (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int symbol_size_in_bytes, int crop_left, int crop_right, int crop_top, int crop_bottom, int iOutStride); -static void img2buf_endian (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int symbol_size_in_bytes, int crop_left, int crop_right, int crop_top, int crop_bottom, int iOutStride); - +static void write_out_picture(VideoParameters *p_Vid, StorablePicture *p, + int p_out); +static void img2buf_byte(imgpel **imgX, unsigned char *buf, int size_x, + int size_y, int symbol_size_in_bytes, int crop_left, + int crop_right, int crop_top, int crop_bottom, + int iOutStride); +static void img2buf_normal(imgpel **imgX, unsigned char *buf, int size_x, + int size_y, int symbol_size_in_bytes, int crop_left, + int crop_right, int crop_top, int crop_bottom, + int iOutStride); +static void img2buf_endian(imgpel **imgX, unsigned char *buf, int size_x, + int size_y, int symbol_size_in_bytes, int crop_left, + int crop_right, int crop_top, int crop_bottom, + int iOutStride); /*! ************************************************************************ @@ -46,22 +56,18 @@ static void img2buf_endian (imgpel** imgX, unsigned char* buf, int size_x, int s * ************************************************************************ */ -static void initOutput(VideoParameters *p_Vid, int symbol_size_in_bytes) -{ - if (( sizeof(char) == sizeof (imgpel))) - { - if ( sizeof(char) == symbol_size_in_bytes) +static void initOutput(VideoParameters *p_Vid, int symbol_size_in_bytes) { + if ((sizeof(char) == sizeof(imgpel))) { + if (sizeof(char) == symbol_size_in_bytes) p_Vid->img2buf = img2buf_byte; else p_Vid->img2buf = img2buf_normal; - } - else - { + } else { if (testEndian()) p_Vid->img2buf = img2buf_endian; else p_Vid->img2buf = img2buf_normal; - } + } } /*! @@ -88,61 +94,56 @@ static void initOutput(VideoParameters *p_Vid, int symbol_size_in_bytes) * pixels to crop from bottom ************************************************************************ */ -static void img2buf_normal (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int symbol_size_in_bytes, int crop_left, int crop_right, int crop_top, int crop_bottom, int iOutStride) -{ - int i,j; +static void img2buf_normal(imgpel **imgX, unsigned char *buf, int size_x, + int size_y, int symbol_size_in_bytes, int crop_left, + int crop_right, int crop_top, int crop_bottom, + int iOutStride) { + int i, j; - int twidth = size_x - crop_left - crop_right; + int twidth = size_x - crop_left - crop_right; int theight = size_y - crop_top - crop_bottom; int size = 0; // sizeof (imgpel) > sizeof(char) // little endian - if ((int) sizeof (imgpel) < symbol_size_in_bytes) - { - // this should not happen. we should not have smaller imgpel than our source material. - size = sizeof (imgpel); + if ((int)sizeof(imgpel) < symbol_size_in_bytes) { + // this should not happen. we should not have smaller imgpel than our source + // material. + size = sizeof(imgpel); // clear buffer - for(j=0; j> 8) | ((tmp16&0xFF)<<8)); - memcpy(buf+((j-crop_left+((i-crop_top)*iOutStride))*2),&(ui16), 2); - } - break; - } - case 4: - { - for(i=crop_top;i>8) | ((tmp32&0xFF000000)>>24)); - memcpy(buf+((j-crop_left+((i-crop_top)*iOutStride))*4),&(ui32), 4); - } - break; - } - default: - { - error ("writing only to formats of 8, 16 or 32 bit allowed on big endian architecture", 500); - break; - } - } + switch (symbol_size_in_bytes) { + case 1: { + for (i = crop_top; i < size_y - crop_bottom; i++) + for (j = crop_left; j < size_x - crop_right; j++) { + ui8 = (unsigned char)(imgX[i][j]); + buf[(j - crop_left + ((i - crop_top) * iOutStride))] = ui8; + } + break; + } + case 2: { + for (i = crop_top; i < size_y - crop_bottom; i++) + for (j = crop_left; j < size_x - crop_right; j++) { + tmp16 = (uint16)(imgX[i][j]); + ui16 = (uint16)((tmp16 >> 8) | ((tmp16 & 0xFF) << 8)); + memcpy(buf + ((j - crop_left + ((i - crop_top) * iOutStride)) * 2), + &(ui16), 2); + } + break; + } + case 4: { + for (i = crop_top; i < size_y - crop_bottom; i++) + for (j = crop_left; j < size_x - crop_right; j++) { + tmp32 = (unsigned long)(imgX[i][j]); + ui32 = + (unsigned long)(((tmp32 & 0xFF00) << 8) | ((tmp32 & 0xFF) << 24) | + ((tmp32 & 0xFF0000) >> 8) | + ((tmp32 & 0xFF000000) >> 24)); + memcpy(buf + ((j - crop_left + ((i - crop_top) * iOutStride)) * 4), + &(ui32), 4); + } + break; + } + default: { + error("writing only to formats of 8, 16 or 32 bit allowed on big endian " + "architecture", + 500); + break; + } + } } - #if (PAIR_FIELDS_IN_OUTPUT) void clear_picture(VideoParameters *p_Vid, StorablePicture *p); @@ -275,28 +277,23 @@ void clear_picture(VideoParameters *p_Vid, StorablePicture *p); * Output file ************************************************************************ */ -void flush_pending_output(VideoParameters *p_Vid, int p_out) -{ - if (p_Vid->pending_output_state != FRAME) - { +void flush_pending_output(VideoParameters *p_Vid, int p_out) { + if (p_Vid->pending_output_state != FRAME) { write_out_picture(p_Vid, p_Vid->pending_output, p_out); } - if (p_Vid->pending_output->imgY) - { - free_mem2Dpel (p_Vid->pending_output->imgY); - p_Vid->pending_output->imgY=NULL; + if (p_Vid->pending_output->imgY) { + free_mem2Dpel(p_Vid->pending_output->imgY); + p_Vid->pending_output->imgY = NULL; } - if (p_Vid->pending_output->imgUV) - { - free_mem3Dpel (p_Vid->pending_output->imgUV); - p_Vid->pending_output->imgUV=NULL; + if (p_Vid->pending_output->imgUV) { + free_mem3Dpel(p_Vid->pending_output->imgUV); + p_Vid->pending_output->imgUV = NULL; } p_Vid->pending_output_state = FRAME; } - /*! ************************************************************************ * \brief @@ -309,26 +306,23 @@ void flush_pending_output(VideoParameters *p_Vid, int p_out) * Output file ************************************************************************ */ -void write_picture(VideoParameters *p_Vid, StorablePicture *p, int p_out, int real_structure) -{ - int i, add; +void write_picture(VideoParameters *p_Vid, StorablePicture *p, int p_out, + int real_structure) { + int i, add; + + if (real_structure == FRAME) { - if (real_structure==FRAME) - { - flush_pending_output(p_Vid, p_out); write_out_picture(p_Vid, p, p_out); return; } - if (real_structure == p_Vid->pending_output_state) - { + if (real_structure == p_Vid->pending_output_state) { flush_pending_output(p_Vid, p_out); write_picture(p_Vid, p, p_out, real_structure); return; } - if (p_Vid->pending_output_state == FRAME) - { + if (p_Vid->pending_output_state == FRAME) { p_Vid->pending_output->size_x = p->size_x; p_Vid->pending_output->size_y = p->size_y; p_Vid->pending_output->size_x_cr = p->size_x_cr; @@ -337,76 +331,79 @@ void write_picture(VideoParameters *p_Vid, StorablePicture *p, int p_out, int re p_Vid->pending_output->frame_mbs_only_flag = p->frame_mbs_only_flag; p_Vid->pending_output->frame_cropping_flag = p->frame_cropping_flag; - if (p_Vid->pending_output->frame_cropping_flag) - { - p_Vid->pending_output->frame_cropping_rect_left_offset = p->frame_cropping_rect_left_offset; - p_Vid->pending_output->frame_cropping_rect_right_offset = p->frame_cropping_rect_right_offset; - p_Vid->pending_output->frame_cropping_rect_top_offset = p->frame_cropping_rect_top_offset; - p_Vid->pending_output->frame_cropping_rect_bottom_offset = p->frame_cropping_rect_bottom_offset; + if (p_Vid->pending_output->frame_cropping_flag) { + p_Vid->pending_output->frame_cropping_rect_left_offset = + p->frame_cropping_rect_left_offset; + p_Vid->pending_output->frame_cropping_rect_right_offset = + p->frame_cropping_rect_right_offset; + p_Vid->pending_output->frame_cropping_rect_top_offset = + p->frame_cropping_rect_top_offset; + p_Vid->pending_output->frame_cropping_rect_bottom_offset = + p->frame_cropping_rect_bottom_offset; } - get_mem2Dpel (&(p_Vid->pending_output->imgY), p_Vid->pending_output->size_y, p_Vid->pending_output->size_x); - get_mem3Dpel (&(p_Vid->pending_output->imgUV), 2, p_Vid->pending_output->size_y_cr, p_Vid->pending_output->size_x_cr); + get_mem2Dpel(&(p_Vid->pending_output->imgY), p_Vid->pending_output->size_y, + p_Vid->pending_output->size_x); + get_mem3Dpel(&(p_Vid->pending_output->imgUV), 2, + p_Vid->pending_output->size_y_cr, + p_Vid->pending_output->size_x_cr); clear_picture(p_Vid, p_Vid->pending_output); // copy first field - if (real_structure == TOP_FIELD) - { + if (real_structure == TOP_FIELD) { add = 0; - } - else - { + } else { add = 1; } - for (i=0; ipending_output->size_y; i+=2) - { - memcpy(p_Vid->pending_output->imgY[(i+add)], p->imgY[(i+add)], p->size_x * sizeof(imgpel)); + for (i = 0; i < p_Vid->pending_output->size_y; i += 2) { + memcpy(p_Vid->pending_output->imgY[(i + add)], p->imgY[(i + add)], + p->size_x * sizeof(imgpel)); } - for (i=0; ipending_output->size_y_cr; i+=2) - { - memcpy(p_Vid->pending_output->imgUV[0][(i+add)], p->imgUV[0][(i+add)], p->size_x_cr * sizeof(imgpel)); - memcpy(p_Vid->pending_output->imgUV[1][(i+add)], p->imgUV[1][(i+add)], p->size_x_cr * sizeof(imgpel)); + for (i = 0; i < p_Vid->pending_output->size_y_cr; i += 2) { + memcpy(p_Vid->pending_output->imgUV[0][(i + add)], p->imgUV[0][(i + add)], + p->size_x_cr * sizeof(imgpel)); + memcpy(p_Vid->pending_output->imgUV[1][(i + add)], p->imgUV[1][(i + add)], + p->size_x_cr * sizeof(imgpel)); } p_Vid->pending_output_state = real_structure; - } - else - { - if ( (p_Vid->pending_output->size_x!=p->size_x) || (p_Vid->pending_output->size_y!= p->size_y) - || (p_Vid->pending_output->frame_mbs_only_flag != p->frame_mbs_only_flag) - || (p_Vid->pending_output->frame_cropping_flag != p->frame_cropping_flag) - || ( p_Vid->pending_output->frame_cropping_flag && - ( (p_Vid->pending_output->frame_cropping_rect_left_offset != p->frame_cropping_rect_left_offset) - ||(p_Vid->pending_output->frame_cropping_rect_right_offset != p->frame_cropping_rect_right_offset) - ||(p_Vid->pending_output->frame_cropping_rect_top_offset != p->frame_cropping_rect_top_offset) - ||(p_Vid->pending_output->frame_cropping_rect_bottom_offset != p->frame_cropping_rect_bottom_offset) - ) - ) - ) - { + } else { + if ((p_Vid->pending_output->size_x != p->size_x) || + (p_Vid->pending_output->size_y != p->size_y) || + (p_Vid->pending_output->frame_mbs_only_flag != + p->frame_mbs_only_flag) || + (p_Vid->pending_output->frame_cropping_flag != + p->frame_cropping_flag) || + (p_Vid->pending_output->frame_cropping_flag && + ((p_Vid->pending_output->frame_cropping_rect_left_offset != + p->frame_cropping_rect_left_offset) || + (p_Vid->pending_output->frame_cropping_rect_right_offset != + p->frame_cropping_rect_right_offset) || + (p_Vid->pending_output->frame_cropping_rect_top_offset != + p->frame_cropping_rect_top_offset) || + (p_Vid->pending_output->frame_cropping_rect_bottom_offset != + p->frame_cropping_rect_bottom_offset)))) { flush_pending_output(p_Vid, p_out); - write_picture (p_Vid, p, p_out, real_structure); + write_picture(p_Vid, p, p_out, real_structure); return; } // copy second field - if (real_structure == TOP_FIELD) - { + if (real_structure == TOP_FIELD) { add = 0; - } - else - { + } else { add = 1; } - for (i=0; ipending_output->size_y; i+=2) - { - memcpy(p_Vid->pending_output->imgY[(i+add)], p->imgY[(i+add)], p->size_x * sizeof(imgpel)); + for (i = 0; i < p_Vid->pending_output->size_y; i += 2) { + memcpy(p_Vid->pending_output->imgY[(i + add)], p->imgY[(i + add)], + p->size_x * sizeof(imgpel)); } - for (i=0; ipending_output->size_y_cr; i+=2) - { - memcpy(p_Vid->pending_output->imgUV[0][(i+add)], p->imgUV[0][(i+add)], p->size_x_cr * sizeof(imgpel)); - memcpy(p_Vid->pending_output->imgUV[1][(i+add)], p->imgUV[1][(i+add)], p->size_x_cr * sizeof(imgpel)); + for (i = 0; i < p_Vid->pending_output->size_y_cr; i += 2) { + memcpy(p_Vid->pending_output->imgUV[0][(i + add)], p->imgUV[0][(i + add)], + p->size_x_cr * sizeof(imgpel)); + memcpy(p_Vid->pending_output->imgUV[1][(i + add)], p->imgUV[1][(i + add)], + p->size_x_cr * sizeof(imgpel)); } flush_pending_output(p_Vid, p_out); @@ -430,15 +427,13 @@ void write_picture(VideoParameters *p_Vid, StorablePicture *p, int p_out, int re * real picture structure ************************************************************************ */ -void write_picture(VideoParameters *p_Vid, StorablePicture *p, int p_out, int real_structure) -{ +void write_picture(VideoParameters *p_Vid, StorablePicture *p, int p_out, + int real_structure) { write_out_picture(p_Vid, p, p_out); } - #endif - /*! ************************************************************************ * \brief @@ -452,24 +447,25 @@ void write_picture(VideoParameters *p_Vid, StorablePicture *p, int p_out, int re * Output file ************************************************************************ */ -static void write_out_picture(VideoParameters *p_Vid, StorablePicture *p, int p_out) -{ +static void write_out_picture(VideoParameters *p_Vid, StorablePicture *p, + int p_out) { InputParameters *p_Inp = p_Vid->p_Inp; DecodedPicList *pDecPic; - static const int SubWidthC [4]= { 1, 2, 2, 1}; - static const int SubHeightC [4]= { 1, 2, 1, 1}; + static const int SubWidthC[4] = {1, 2, 2, 1}; + static const int SubHeightC[4] = {1, 2, 1, 1}; #if (MVC_EXTENSION_ENABLE) - char out_ViewFileName[FILE_NAME_SIZE], chBuf[FILE_NAME_SIZE], *pch; + char out_ViewFileName[FILE_NAME_SIZE], chBuf[FILE_NAME_SIZE], *pch; int iViewIdx = GetVOIdx(p_Vid, p->view_id); #endif int crop_left, crop_right, crop_top, crop_bottom; - int symbol_size_in_bytes = ((p_Vid->pic_unit_bitsize_on_disk+7) >> 3); - Boolean rgb_output = (Boolean) (p_Vid->active_sps->vui_seq_parameters.matrix_coefficients==0); + int symbol_size_in_bytes = ((p_Vid->pic_unit_bitsize_on_disk + 7) >> 3); + Boolean rgb_output = + (Boolean)(p_Vid->active_sps->vui_seq_parameters.matrix_coefficients == 0); unsigned char *buf; - //int iPicSizeTab[4] = {2, 3, 4, 6}; + // int iPicSizeTab[4] = {2, 3, 4, 6}; int iLumaSize, iFrameSize; int iLumaSizeX, iLumaSizeY; int iChromaSizeX, iChromaSizeY; @@ -479,109 +475,114 @@ static void write_out_picture(VideoParameters *p_Vid, StorablePicture *p, int p_ if (p->non_existing) return; - #if (ENABLE_OUTPUT_TONEMAPPING) // note: this tone-mapping is working for RGB format only. Sharp - if (p->seiHasTone_mapping && rgb_output) - { - //printf("output frame %d with tone model id %d\n", p->frame_num, p->tone_mapping_model_id); - symbol_size_in_bytes = (p->tonemapped_bit_depth>8)? 2 : 1; + if (p->seiHasTone_mapping && rgb_output) { + // printf("output frame %d with tone model id %d\n", p->frame_num, + // p->tone_mapping_model_id); + symbol_size_in_bytes = (p->tonemapped_bit_depth > 8) ? 2 : 1; tone_map(p->imgY, p->tone_mapping_lut, p->size_x, p->size_y); tone_map(p->imgUV[0], p->tone_mapping_lut, p->size_x_cr, p->size_y_cr); tone_map(p->imgUV[1], p->tone_mapping_lut, p->size_x_cr, p->size_y_cr); } #endif - if (p->frame_cropping_flag) - { - crop_left = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_left_offset; - crop_right = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_right_offset; - crop_top = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_top_offset; - crop_bottom = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_bottom_offset; - } - else - { + if (p->frame_cropping_flag) { + crop_left = + SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_left_offset; + crop_right = + SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_right_offset; + crop_top = SubHeightC[p->chroma_format_idc] * (2 - p->frame_mbs_only_flag) * + p->frame_cropping_rect_top_offset; + crop_bottom = SubHeightC[p->chroma_format_idc] * + (2 - p->frame_mbs_only_flag) * + p->frame_cropping_rect_bottom_offset; + } else { crop_left = crop_right = crop_top = crop_bottom = 0; } - iChromaSizeX = p->size_x_cr- p->frame_cropping_rect_left_offset -p->frame_cropping_rect_right_offset; - iChromaSizeY = p->size_y_cr - ( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_top_offset -( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_bottom_offset; - iLumaSizeX = p->size_x-crop_left-crop_right; - iLumaSizeY = p->size_y-crop_top-crop_bottom; - iLumaSize = iLumaSizeX*iLumaSizeY*symbol_size_in_bytes; - iFrameSize = (iLumaSizeX*iLumaSizeY + 2*(iChromaSizeX*iChromaSizeY))*symbol_size_in_bytes; //iLumaSize*iPicSizeTab[p->chroma_format_idc]/2; + iChromaSizeX = p->size_x_cr - p->frame_cropping_rect_left_offset - + p->frame_cropping_rect_right_offset; + iChromaSizeY = + p->size_y_cr - + (2 - p->frame_mbs_only_flag) * p->frame_cropping_rect_top_offset - + (2 - p->frame_mbs_only_flag) * p->frame_cropping_rect_bottom_offset; + iLumaSizeX = p->size_x - crop_left - crop_right; + iLumaSizeY = p->size_y - crop_top - crop_bottom; + iLumaSize = iLumaSizeX * iLumaSizeY * symbol_size_in_bytes; + iFrameSize = + (iLumaSizeX * iLumaSizeY + 2 * (iChromaSizeX * iChromaSizeY)) * + symbol_size_in_bytes; // iLumaSize*iPicSizeTab[p->chroma_format_idc]/2; - //printf ("write frame size: %dx%d\n", p->size_x-crop_left-crop_right,p->size_y-crop_top-crop_bottom ); + // printf ("write frame size: %dx%d\n", + // p->size_x-crop_left-crop_right,p->size_y-crop_top-crop_bottom ); initOutput(p_Vid, symbol_size_in_bytes); - // KS: this buffer should actually be allocated only once, but this is still much faster than the previous version + // KS: this buffer should actually be allocated only once, but this is still + // much faster than the previous version pDecPic = GetOneAvailDecPicFromList(p_Vid->pDecOuputPic, 0); - - if(pDecPic->pY == NULL) - { + + if (pDecPic->pY == NULL) { pDecPic->pY = malloc(iFrameSize); - pDecPic->pU = pDecPic->pY+iLumaSize; - pDecPic->pV = pDecPic->pU + ((iFrameSize-iLumaSize)>>1); - //init; + pDecPic->pU = pDecPic->pY + iLumaSize; + pDecPic->pV = pDecPic->pU + ((iFrameSize - iLumaSize) >> 1); + // init; pDecPic->iYUVFormat = p->chroma_format_idc; pDecPic->iYUVStorageFormat = 0; pDecPic->iBitDepth = p_Vid->pic_unit_bitsize_on_disk; - pDecPic->iWidth = iLumaSizeX; //p->size_x; - pDecPic->iHeight = iLumaSizeY; //p->size_y; - pDecPic->iYBufStride = iLumaSizeX*symbol_size_in_bytes; //p->size_x *symbol_size_in_bytes; - pDecPic->iUVBufStride = iChromaSizeX*symbol_size_in_bytes; //p->size_x_cr*symbol_size_in_bytes; + pDecPic->iWidth = iLumaSizeX; // p->size_x; + pDecPic->iHeight = iLumaSizeY; // p->size_y; + pDecPic->iYBufStride = + iLumaSizeX * symbol_size_in_bytes; // p->size_x *symbol_size_in_bytes; + pDecPic->iUVBufStride = + iChromaSizeX * + symbol_size_in_bytes; // p->size_x_cr*symbol_size_in_bytes; } #if (MVC_EXTENSION_ENABLE) { pDecPic->bValid = 1; - pDecPic->iViewId = p->view_id >=0 ? p->view_id : -1; + pDecPic->iViewId = p->view_id >= 0 ? p->view_id : -1; } #else pDecPic->bValid = 1; #endif - + pDecPic->iPOC = p->frame_poc; - //buf = pDecPic->pY; //malloc (p->size_x*p->size_y*symbol_size_in_bytes); - if (NULL==pDecPic->pY) - { + // buf = pDecPic->pY; //malloc (p->size_x*p->size_y*symbol_size_in_bytes); + if (NULL == pDecPic->pY) { no_mem_exit("write_out_picture: buf"); } #if (MVC_EXTENSION_ENABLE) - if (p->view_id >= 0 && p_Inp->DecodeAllLayers == 1) - { - if((p_Vid->p_out_mvc[iViewIdx] == -1) && (STRCMP(p_Inp->outfile, "\"\"")!=0) && (strlen(p_Inp->outfile)>0)) - { + if (p->view_id >= 0 && p_Inp->DecodeAllLayers == 1) { + if ((p_Vid->p_out_mvc[iViewIdx] == -1) && + (STRCMP(p_Inp->outfile, "\"\"") != 0) && (strlen(p_Inp->outfile) > 0)) { strcpy(chBuf, p_Inp->outfile); pch = strrchr(chBuf, '.'); - if(pch) + if (pch) *pch = '\0'; - if (strcmp("nul", chBuf)) - { + if (strcmp("nul", chBuf)) { sprintf(out_ViewFileName, "%s_ViewId%04d.yuv", chBuf, p->view_id); - if ((p_Vid->p_out_mvc[iViewIdx]=open(out_ViewFileName, OPENFLAGS_WRITE, OPEN_PERMISSIONS))==-1) - { + if ((p_Vid->p_out_mvc[iViewIdx] = open( + out_ViewFileName, OPENFLAGS_WRITE, OPEN_PERMISSIONS)) == -1) { snprintf(errortext, ET_SIZE, "Error open file %s ", out_ViewFileName); fprintf(stderr, "%s\n", errortext); exit(500); } - } - else - { + } else { p_Vid->p_out_mvc[iViewIdx] = -1; } } p_out = p_Vid->p_out_mvc[iViewIdx]; - } - else - { //Normal AVC - if((p_Vid->p_out_mvc[0] == -1) && (STRCMP(p_Inp->outfile, "\"\"")!=0) && (strlen(p_Inp->outfile)>0)) - { - if( (STRCMP(p_Inp->outfile, "\"\"")!=0) && ((p_Vid->p_out_mvc[0]=open(p_Inp->outfile, OPENFLAGS_WRITE, OPEN_PERMISSIONS))==-1) ) - { - snprintf(errortext, ET_SIZE, "Error open file %s ",p_Inp->outfile); - //error(errortext,500); + } else { // Normal AVC + if ((p_Vid->p_out_mvc[0] == -1) && (STRCMP(p_Inp->outfile, "\"\"") != 0) && + (strlen(p_Inp->outfile) > 0)) { + if ((STRCMP(p_Inp->outfile, "\"\"") != 0) && + ((p_Vid->p_out_mvc[0] = open(p_Inp->outfile, OPENFLAGS_WRITE, + OPEN_PERMISSIONS)) == -1)) { + snprintf(errortext, ET_SIZE, "Error open file %s ", p_Inp->outfile); + // error(errortext,500); fprintf(stderr, "%s\n", errortext); exit(500); } @@ -590,123 +591,151 @@ static void write_out_picture(VideoParameters *p_Vid, StorablePicture *p, int p_ } #endif - if(rgb_output) - { - buf = malloc (p->size_x*p->size_y*symbol_size_in_bytes); - crop_left = p->frame_cropping_rect_left_offset; - crop_right = p->frame_cropping_rect_right_offset; - crop_top = ( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_top_offset; - crop_bottom = ( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_bottom_offset; + if (rgb_output) { + buf = malloc(p->size_x * p->size_y * symbol_size_in_bytes); + crop_left = p->frame_cropping_rect_left_offset; + crop_right = p->frame_cropping_rect_right_offset; + crop_top = (2 - p->frame_mbs_only_flag) * p->frame_cropping_rect_top_offset; + crop_bottom = + (2 - p->frame_mbs_only_flag) * p->frame_cropping_rect_bottom_offset; - p_Vid->img2buf (p->imgUV[1], buf, p->size_x_cr, p->size_y_cr, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom, pDecPic->iYBufStride); - if (p_out >= 0) - { - ret = write(p_out, buf, (p->size_y_cr-crop_bottom-crop_top)*(p->size_x_cr-crop_right-crop_left)*symbol_size_in_bytes); - if (ret != ((p->size_y_cr-crop_bottom-crop_top)*(p->size_x_cr-crop_right-crop_left)*symbol_size_in_bytes)) - { - error ("write_out_picture: error writing to RGB file", 500); + p_Vid->img2buf(p->imgUV[1], buf, p->size_x_cr, p->size_y_cr, + symbol_size_in_bytes, crop_left, crop_right, crop_top, + crop_bottom, pDecPic->iYBufStride); + if (p_out >= 0) { + ret = write(p_out, buf, + (p->size_y_cr - crop_bottom - crop_top) * + (p->size_x_cr - crop_right - crop_left) * + symbol_size_in_bytes); + if (ret != + ((p->size_y_cr - crop_bottom - crop_top) * + (p->size_x_cr - crop_right - crop_left) * symbol_size_in_bytes)) { + error("write_out_picture: error writing to RGB file", 500); } } - if (p->frame_cropping_flag) - { - crop_left = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_left_offset; - crop_right = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_right_offset; - crop_top = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_top_offset; - crop_bottom = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_bottom_offset; - } - else - { + if (p->frame_cropping_flag) { + crop_left = + SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_left_offset; + crop_right = + SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_right_offset; + crop_top = SubHeightC[p->chroma_format_idc] * + (2 - p->frame_mbs_only_flag) * + p->frame_cropping_rect_top_offset; + crop_bottom = SubHeightC[p->chroma_format_idc] * + (2 - p->frame_mbs_only_flag) * + p->frame_cropping_rect_bottom_offset; + } else { crop_left = crop_right = crop_top = crop_bottom = 0; } - if(buf) + if (buf) free(buf); } - buf = (pDecPic->bValid==1)? pDecPic->pY: pDecPic->pY+iLumaSizeX*symbol_size_in_bytes; + buf = (pDecPic->bValid == 1) + ? pDecPic->pY + : pDecPic->pY + iLumaSizeX * symbol_size_in_bytes; - p_Vid->img2buf (p->imgY, buf, p->size_x, p->size_y, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom, pDecPic->iYBufStride); + p_Vid->img2buf(p->imgY, buf, p->size_x, p->size_y, symbol_size_in_bytes, + crop_left, crop_right, crop_top, crop_bottom, + pDecPic->iYBufStride); - if(p_out >=0) - { - ret = write(p_out, buf, (p->size_y-crop_bottom-crop_top)*(p->size_x-crop_right-crop_left)*symbol_size_in_bytes); - if (ret != ((p->size_y-crop_bottom-crop_top)*(p->size_x-crop_right-crop_left)*symbol_size_in_bytes)) - { - error ("write_out_picture: error writing to YUV file", 500); + if (p_out >= 0) { + ret = + write(p_out, buf, + (p->size_y - crop_bottom - crop_top) * + (p->size_x - crop_right - crop_left) * symbol_size_in_bytes); + if (ret != ((p->size_y - crop_bottom - crop_top) * + (p->size_x - crop_right - crop_left) * symbol_size_in_bytes)) { + error("write_out_picture: error writing to YUV file", 500); } } - if (p->chroma_format_idc!=YUV400) - { - crop_left = p->frame_cropping_rect_left_offset; - crop_right = p->frame_cropping_rect_right_offset; - crop_top = ( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_top_offset; - crop_bottom = ( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_bottom_offset; - buf = (pDecPic->bValid==1)? pDecPic->pU : pDecPic->pU + iChromaSizeX*symbol_size_in_bytes; + if (p->chroma_format_idc != YUV400) { + crop_left = p->frame_cropping_rect_left_offset; + crop_right = p->frame_cropping_rect_right_offset; + crop_top = (2 - p->frame_mbs_only_flag) * p->frame_cropping_rect_top_offset; + crop_bottom = + (2 - p->frame_mbs_only_flag) * p->frame_cropping_rect_bottom_offset; + buf = (pDecPic->bValid == 1) + ? pDecPic->pU + : pDecPic->pU + iChromaSizeX * symbol_size_in_bytes; - p_Vid->img2buf (p->imgUV[0], buf, p->size_x_cr, p->size_y_cr, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom, pDecPic->iUVBufStride); - if(p_out >= 0) - { - ret = write(p_out, buf, (p->size_y_cr-crop_bottom-crop_top)*(p->size_x_cr-crop_right-crop_left)* symbol_size_in_bytes); - if (ret != ((p->size_y_cr-crop_bottom-crop_top)*(p->size_x_cr-crop_right-crop_left)* symbol_size_in_bytes)) - { - error ("write_out_picture: error writing to YUV file", 500); + p_Vid->img2buf(p->imgUV[0], buf, p->size_x_cr, p->size_y_cr, + symbol_size_in_bytes, crop_left, crop_right, crop_top, + crop_bottom, pDecPic->iUVBufStride); + if (p_out >= 0) { + ret = write(p_out, buf, + (p->size_y_cr - crop_bottom - crop_top) * + (p->size_x_cr - crop_right - crop_left) * + symbol_size_in_bytes); + if (ret != + ((p->size_y_cr - crop_bottom - crop_top) * + (p->size_x_cr - crop_right - crop_left) * symbol_size_in_bytes)) { + error("write_out_picture: error writing to YUV file", 500); } } - if (!rgb_output) - { - buf = (pDecPic->bValid==1)? pDecPic->pV : pDecPic->pV + iChromaSizeX*symbol_size_in_bytes; - p_Vid->img2buf (p->imgUV[1], buf, p->size_x_cr, p->size_y_cr, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom, pDecPic->iUVBufStride); + if (!rgb_output) { + buf = (pDecPic->bValid == 1) + ? pDecPic->pV + : pDecPic->pV + iChromaSizeX * symbol_size_in_bytes; + p_Vid->img2buf(p->imgUV[1], buf, p->size_x_cr, p->size_y_cr, + symbol_size_in_bytes, crop_left, crop_right, crop_top, + crop_bottom, pDecPic->iUVBufStride); - if(p_out >= 0) - { - ret = write(p_out, buf, (p->size_y_cr-crop_bottom-crop_top)*(p->size_x_cr-crop_right-crop_left)*symbol_size_in_bytes); - if (ret != ((p->size_y_cr-crop_bottom-crop_top)*(p->size_x_cr-crop_right-crop_left)*symbol_size_in_bytes)) - { - error ("write_out_picture: error writing to YUV file", 500); + if (p_out >= 0) { + ret = write(p_out, buf, + (p->size_y_cr - crop_bottom - crop_top) * + (p->size_x_cr - crop_right - crop_left) * + symbol_size_in_bytes); + if (ret != + ((p->size_y_cr - crop_bottom - crop_top) * + (p->size_x_cr - crop_right - crop_left) * symbol_size_in_bytes)) { + error("write_out_picture: error writing to YUV file", 500); } } } - } - else - { - if (p_Inp->write_uv) - { - int i,j; - imgpel cr_val = (imgpel) (1<<(p_Vid->bitdepth_luma - 1)); + } else { + if (p_Inp->write_uv) { + int i, j; + imgpel cr_val = (imgpel)(1 << (p_Vid->bitdepth_luma - 1)); - get_mem3Dpel (&(p->imgUV), 1, p->size_y/2, p->size_x/2); - - for (j=0; jsize_y/2; j++) - { - for (i=0; isize_x/2; i++) - { - p->imgUV[0][j][i]=cr_val; + get_mem3Dpel(&(p->imgUV), 1, p->size_y / 2, p->size_x / 2); + + for (j = 0; j < p->size_y / 2; j++) { + for (i = 0; i < p->size_x / 2; i++) { + p->imgUV[0][j][i] = cr_val; } } // fake out U=V=128 to make a YUV 4:2:0 stream - buf = malloc (p->size_x*p->size_y*symbol_size_in_bytes); - p_Vid->img2buf (p->imgUV[0], buf, p->size_x/2, p->size_y/2, symbol_size_in_bytes, crop_left/2, crop_right/2, crop_top/2, crop_bottom/2, pDecPic->iYBufStride/2); + buf = malloc(p->size_x * p->size_y * symbol_size_in_bytes); + p_Vid->img2buf(p->imgUV[0], buf, p->size_x / 2, p->size_y / 2, + symbol_size_in_bytes, crop_left / 2, crop_right / 2, + crop_top / 2, crop_bottom / 2, pDecPic->iYBufStride / 2); - ret = write(p_out, buf, symbol_size_in_bytes * (p->size_y-crop_bottom-crop_top)/2 * (p->size_x-crop_right-crop_left)/2 ); - if (ret != (symbol_size_in_bytes * (p->size_y-crop_bottom-crop_top)/2 * (p->size_x-crop_right-crop_left)/2)) - { - error ("write_out_picture: error writing to YUV file", 500); + ret = write(p_out, buf, + symbol_size_in_bytes * (p->size_y - crop_bottom - crop_top) / + 2 * (p->size_x - crop_right - crop_left) / 2); + if (ret != (symbol_size_in_bytes * (p->size_y - crop_bottom - crop_top) / + 2 * (p->size_x - crop_right - crop_left) / 2)) { + error("write_out_picture: error writing to YUV file", 500); } - ret = write(p_out, buf, symbol_size_in_bytes * (p->size_y-crop_bottom-crop_top)/2 * (p->size_x-crop_right-crop_left)/2 ); - if (ret != (symbol_size_in_bytes * (p->size_y-crop_bottom-crop_top)/2 * (p->size_x-crop_right-crop_left)/2)) - { - error ("write_out_picture: error writing to YUV file", 500); + ret = write(p_out, buf, + symbol_size_in_bytes * (p->size_y - crop_bottom - crop_top) / + 2 * (p->size_x - crop_right - crop_left) / 2); + if (ret != (symbol_size_in_bytes * (p->size_y - crop_bottom - crop_top) / + 2 * (p->size_x - crop_right - crop_left) / 2)) { + error("write_out_picture: error writing to YUV file", 500); } free(buf); free_mem3Dpel(p->imgUV); - p->imgUV=NULL; + p->imgUV = NULL; } } - //free(buf); + // free(buf); // fsync(p_out); } @@ -717,15 +746,15 @@ static void write_out_picture(VideoParameters *p_Vid, StorablePicture *p, int p_ * Initialize output buffer for direct output ************************************************************************ */ -void init_out_buffer(VideoParameters *p_Vid) -{ - p_Vid->out_buffer = alloc_frame_store(); +void init_out_buffer(VideoParameters *p_Vid) { + p_Vid->out_buffer = alloc_frame_store(); #if (PAIR_FIELDS_IN_OUTPUT) - p_Vid->pending_output = calloc (sizeof(StorablePicture), 1); - if (NULL==p_Vid->pending_output) no_mem_exit("init_out_buffer"); + p_Vid->pending_output = calloc(sizeof(StorablePicture), 1); + if (NULL == p_Vid->pending_output) + no_mem_exit("init_out_buffer"); p_Vid->pending_output->imgUV = NULL; - p_Vid->pending_output->imgY = NULL; + p_Vid->pending_output->imgY = NULL; #endif } @@ -735,13 +764,12 @@ void init_out_buffer(VideoParameters *p_Vid) * Uninitialize output buffer for direct output ************************************************************************ */ -void uninit_out_buffer(VideoParameters *p_Vid) -{ +void uninit_out_buffer(VideoParameters *p_Vid) { free_frame_store(p_Vid->out_buffer); - p_Vid->out_buffer=NULL; + p_Vid->out_buffer = NULL; #if (PAIR_FIELDS_IN_OUTPUT) flush_pending_output(p_Vid, p_Vid->p_out); - free (p_Vid->pending_output); + free(p_Vid->pending_output); #endif } @@ -751,32 +779,28 @@ void uninit_out_buffer(VideoParameters *p_Vid) * Initialize picture memory with (Y:0,U:128,V:128) ************************************************************************ */ -void clear_picture(VideoParameters *p_Vid, StorablePicture *p) -{ - int i,j; +void clear_picture(VideoParameters *p_Vid, StorablePicture *p) { + int i, j; - for(i=0;isize_y;i++) - { - for (j=0; jsize_x; j++) - p->imgY[i][j] = (imgpel) p_Vid->dc_pred_value_comp[0]; + for (i = 0; i < p->size_y; i++) { + for (j = 0; j < p->size_x; j++) + p->imgY[i][j] = (imgpel)p_Vid->dc_pred_value_comp[0]; } - for(i=0;isize_y_cr;i++) - { - for (j=0; jsize_x_cr; j++) - p->imgUV[0][i][j] = (imgpel) p_Vid->dc_pred_value_comp[1]; + for (i = 0; i < p->size_y_cr; i++) { + for (j = 0; j < p->size_x_cr; j++) + p->imgUV[0][i][j] = (imgpel)p_Vid->dc_pred_value_comp[1]; } - for(i=0;isize_y_cr;i++) - { - for (j=0; jsize_x_cr; j++) - p->imgUV[1][i][j] = (imgpel) p_Vid->dc_pred_value_comp[2]; + for (i = 0; i < p->size_y_cr; i++) { + for (j = 0; j < p->size_x_cr; j++) + p->imgUV[1][i][j] = (imgpel)p_Vid->dc_pred_value_comp[2]; } } /*! ************************************************************************ * \brief - * Write out not paired direct output fields. A second empty field is generated - * and combined into the frame buffer. + * Write out not paired direct output fields. A second empty field is + *generated and combined into the frame buffer. * * \param p_Vid * image decoding parameters for current picture @@ -786,47 +810,51 @@ void clear_picture(VideoParameters *p_Vid, StorablePicture *p) * Output file ************************************************************************ */ -void write_unpaired_field(VideoParameters *p_Vid, FrameStore* fs, int p_out) -{ +void write_unpaired_field(VideoParameters *p_Vid, FrameStore *fs, int p_out) { StorablePicture *p; - assert (fs->is_used<3); + assert(fs->is_used < 3); - if(fs->is_used & 0x01) - { + if (fs->is_used & 0x01) { // we have a top field // construct an empty bottom field p = fs->top_field; - fs->bottom_field = alloc_storable_picture(p_Vid, BOTTOM_FIELD, p->size_x, 2*p->size_y, p->size_x_cr, 2*p->size_y_cr); + fs->bottom_field = + alloc_storable_picture(p_Vid, BOTTOM_FIELD, p->size_x, 2 * p->size_y, + p->size_x_cr, 2 * p->size_y_cr); fs->bottom_field->chroma_format_idc = p->chroma_format_idc; clear_picture(p_Vid, fs->bottom_field); dpb_combine_field_yuv(p_Vid, fs); #if (MVC_EXTENSION_ENABLE) fs->frame->view_id = fs->view_id; #endif - write_picture (p_Vid, fs->frame, p_out, TOP_FIELD); + write_picture(p_Vid, fs->frame, p_out, TOP_FIELD); } - if(fs->is_used & 0x02) - { + if (fs->is_used & 0x02) { // we have a bottom field // construct an empty top field p = fs->bottom_field; - fs->top_field = alloc_storable_picture(p_Vid, TOP_FIELD, p->size_x, 2*p->size_y, p->size_x_cr, 2*p->size_y_cr); + fs->top_field = + alloc_storable_picture(p_Vid, TOP_FIELD, p->size_x, 2 * p->size_y, + p->size_x_cr, 2 * p->size_y_cr); fs->top_field->chroma_format_idc = p->chroma_format_idc; clear_picture(p_Vid, fs->top_field); - fs ->top_field->frame_cropping_flag = fs->bottom_field->frame_cropping_flag; - if(fs ->top_field->frame_cropping_flag) - { - fs ->top_field->frame_cropping_rect_top_offset = fs->bottom_field->frame_cropping_rect_top_offset; - fs ->top_field->frame_cropping_rect_bottom_offset = fs->bottom_field->frame_cropping_rect_bottom_offset; - fs ->top_field->frame_cropping_rect_left_offset = fs->bottom_field->frame_cropping_rect_left_offset; - fs ->top_field->frame_cropping_rect_right_offset = fs->bottom_field->frame_cropping_rect_right_offset; + fs->top_field->frame_cropping_flag = fs->bottom_field->frame_cropping_flag; + if (fs->top_field->frame_cropping_flag) { + fs->top_field->frame_cropping_rect_top_offset = + fs->bottom_field->frame_cropping_rect_top_offset; + fs->top_field->frame_cropping_rect_bottom_offset = + fs->bottom_field->frame_cropping_rect_bottom_offset; + fs->top_field->frame_cropping_rect_left_offset = + fs->bottom_field->frame_cropping_rect_left_offset; + fs->top_field->frame_cropping_rect_right_offset = + fs->bottom_field->frame_cropping_rect_right_offset; } dpb_combine_field_yuv(p_Vid, fs); #if (MVC_EXTENSION_ENABLE) fs->frame->view_id = fs->view_id; #endif - write_picture (p_Vid, fs->frame, p_out, BOTTOM_FIELD); + write_picture(p_Vid, fs->frame, p_out, BOTTOM_FIELD); } fs->is_used = 3; @@ -843,8 +871,7 @@ void write_unpaired_field(VideoParameters *p_Vid, FrameStore* fs, int p_out) * Output file ************************************************************************ */ -void flush_direct_output(VideoParameters *p_Vid, int p_out) -{ +void flush_direct_output(VideoParameters *p_Vid, int p_out) { write_unpaired_field(p_Vid, p_Vid->out_buffer, p_out); free_storable_picture(p_Vid->out_buffer->frame); @@ -856,7 +883,6 @@ void flush_direct_output(VideoParameters *p_Vid, int p_out) p_Vid->out_buffer->is_used = 0; } - /*! ************************************************************************ * \brief @@ -870,17 +896,13 @@ void flush_direct_output(VideoParameters *p_Vid, int p_out) * Output file ************************************************************************ */ -void write_stored_frame( VideoParameters *p_Vid, FrameStore *fs,int p_out) -{ +void write_stored_frame(VideoParameters *p_Vid, FrameStore *fs, int p_out) { // make sure no direct output field is pending flush_direct_output(p_Vid, p_out); - if (fs->is_used<3) - { + if (fs->is_used < 3) { write_unpaired_field(p_Vid, fs, p_out); - } - else - { + } else { if (fs->recovery_frame) p_Vid->recovery_flag = 1; if ((!p_Vid->non_conforming_stream) || p_Vid->recovery_flag) @@ -904,15 +926,13 @@ void write_stored_frame( VideoParameters *p_Vid, FrameStore *fs,int p_out) * Output file ************************************************************************ */ -void direct_output(VideoParameters *p_Vid, StorablePicture *p, int p_out) -{ +void direct_output(VideoParameters *p_Vid, StorablePicture *p, int p_out) { InputParameters *p_Inp = p_Vid->p_Inp; - if (p->structure==FRAME) - { + if (p->structure == FRAME) { // we have a frame (or complementary field pair) // so output it directly flush_direct_output(p_Vid, p_out); - write_picture (p_Vid, p, p_out, FRAME); + write_picture(p_Vid, p, p_out, FRAME); calculate_frame_no(p_Vid, p); if (-1 != p_Vid->p_ref && !p_Inp->silent) find_snr(p_Vid, p, &p_Vid->p_ref); @@ -920,30 +940,27 @@ void direct_output(VideoParameters *p_Vid, StorablePicture *p, int p_out) return; } - if (p->structure == TOP_FIELD) - { - if (p_Vid->out_buffer->is_used &1) + if (p->structure == TOP_FIELD) { + if (p_Vid->out_buffer->is_used & 1) flush_direct_output(p_Vid, p_Vid->p_out); p_Vid->out_buffer->top_field = p; p_Vid->out_buffer->is_used |= 1; } - if (p->structure == BOTTOM_FIELD) - { - if (p_Vid->out_buffer->is_used &2) + if (p->structure == BOTTOM_FIELD) { + if (p_Vid->out_buffer->is_used & 2) flush_direct_output(p_Vid, p_Vid->p_out); p_Vid->out_buffer->bottom_field = p; p_Vid->out_buffer->is_used |= 2; } - if (p_Vid->out_buffer->is_used == 3) - { + if (p_Vid->out_buffer->is_used == 3) { // we have both fields, so output them dpb_combine_field_yuv(p_Vid, p_Vid->out_buffer); #if (MVC_EXTENSION_ENABLE) p_Vid->out_buffer->frame->view_id = p_Vid->out_buffer->view_id; #endif - write_picture (p_Vid, p_Vid->out_buffer->frame, p_Vid->p_out, FRAME); + write_picture(p_Vid, p_Vid->out_buffer->frame, p_Vid->p_out, FRAME); calculate_frame_no(p_Vid, p); if (-1 != p_Vid->p_ref && !p_Inp->silent) @@ -957,4 +974,3 @@ void direct_output(VideoParameters *p_Vid, StorablePicture *p, int p_out) p_Vid->out_buffer->is_used = 0; } } - diff --git a/src/common/ldecod_src/parset.c b/src/common/ldecod_src/parset.c index 617e8e1..4a24786 100644 --- a/src/common/ldecod_src/parset.c +++ b/src/common/ldecod_src/parset.c @@ -6,195 +6,196 @@ * \brief * Parameter Sets * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger * *********************************************************************** */ +#include "parset.h" +#include "cabac.h" +#include "erc_api.h" +#include "fmo.h" #include "global.h" #include "image.h" -#include "parsetcommon.h" -#include "parset.h" -#include "nalu.h" -#include "memalloc.h" -#include "fmo.h" -#include "cabac.h" -#include "vlc.h" #include "mbuffer.h" -#include "erc_api.h" +#include "memalloc.h" +#include "nalu.h" +#include "parsetcommon.h" +#include "vlc.h" #if TRACE -#define SYMTRACESTRING(s) strncpy(sym->tracestring,s,TRACESTRING_SIZE) +#define SYMTRACESTRING(s) strncpy(sym->tracestring, s, TRACESTRING_SIZE) #else #define SYMTRACESTRING(s) // do nothing #endif - extern void init_frext(VideoParameters *p_Vid); // syntax for scaling list matrix values -void Scaling_List(int *scalingList, int sizeOfScalingList, Boolean *UseDefaultScalingMatrix, Bitstream *s) -{ +void Scaling_List(int *scalingList, int sizeOfScalingList, + Boolean *UseDefaultScalingMatrix, Bitstream *s) { int j, scanj; int delta_scale, lastScale, nextScale; - lastScale = 8; - nextScale = 8; + lastScale = 8; + nextScale = 8; - for(j=0; jbitstream; - assert (p != NULL); - assert (p->bitstream != NULL); - assert (p->bitstream->streamBuffer != 0); - assert (sps != NULL); + assert(p != NULL); + assert(p->bitstream != NULL); + assert(p->bitstream->streamBuffer != 0); + assert(sps != NULL); p_Dec->UsedBits = 0; - sps->profile_idc = u_v (8, "SPS: profile_idc" , s); + sps->profile_idc = u_v(8, "SPS: profile_idc", s); - if ((sps->profile_idc!=BASELINE ) && - (sps->profile_idc!=MAIN ) && - (sps->profile_idc!=EXTENDED ) && - (sps->profile_idc!=FREXT_HP ) && - (sps->profile_idc!=FREXT_Hi10P ) && - (sps->profile_idc!=FREXT_Hi422 ) && - (sps->profile_idc!=FREXT_Hi444 ) && - (sps->profile_idc!=FREXT_CAVLC444 ) + if ((sps->profile_idc != BASELINE) && (sps->profile_idc != MAIN) && + (sps->profile_idc != EXTENDED) && (sps->profile_idc != FREXT_HP) && + (sps->profile_idc != FREXT_Hi10P) && (sps->profile_idc != FREXT_Hi422) && + (sps->profile_idc != FREXT_Hi444) && (sps->profile_idc != FREXT_CAVLC444) #if (MVC_EXTENSION_ENABLE) - && (sps->profile_idc!=MVC_HIGH) - && (sps->profile_idc!=STEREO_HIGH) + && (sps->profile_idc != MVC_HIGH) && (sps->profile_idc != STEREO_HIGH) #endif - ) - { + ) { printf("Invalid Profile IDC (%d) encountered. \n", sps->profile_idc); return p_Dec->UsedBits; } - sps->constrained_set0_flag = u_1 ( "SPS: constrained_set0_flag" , s); - sps->constrained_set1_flag = u_1 ( "SPS: constrained_set1_flag" , s); - sps->constrained_set2_flag = u_1 ( "SPS: constrained_set2_flag" , s); - sps->constrained_set3_flag = u_1 ( "SPS: constrained_set3_flag" , s); + sps->constrained_set0_flag = u_1("SPS: constrained_set0_flag", s); + sps->constrained_set1_flag = u_1("SPS: constrained_set1_flag", s); + sps->constrained_set2_flag = u_1("SPS: constrained_set2_flag", s); + sps->constrained_set3_flag = u_1("SPS: constrained_set3_flag", s); #if (MVC_EXTENSION_ENABLE) - sps->constrained_set4_flag = u_1 ( "SPS: constrained_set4_flag" , s); - reserved_zero = u_v (3, "SPS: reserved_zero_3bits" , s); + sps->constrained_set4_flag = u_1("SPS: constrained_set4_flag", s); + reserved_zero = u_v(3, "SPS: reserved_zero_3bits", s); #else - reserved_zero = u_v (4, "SPS: reserved_zero_4bits" , s); + reserved_zero = u_v(4, "SPS: reserved_zero_4bits", s); #endif - assert (reserved_zero==0); + assert(reserved_zero == 0); - sps->level_idc = u_v (8, "SPS: level_idc" , s); + sps->level_idc = u_v(8, "SPS: level_idc", s); - sps->seq_parameter_set_id = ue_v ("SPS: seq_parameter_set_id" , s); + sps->seq_parameter_set_id = ue_v("SPS: seq_parameter_set_id", s); // Fidelity Range Extensions stuff sps->chroma_format_idc = 1; - sps->bit_depth_luma_minus8 = 0; + sps->bit_depth_luma_minus8 = 0; sps->bit_depth_chroma_minus8 = 0; - p_Vid->lossless_qpprime_flag = 0; + p_Vid->lossless_qpprime_flag = 0; sps->separate_colour_plane_flag = 0; - if((sps->profile_idc==FREXT_HP ) || - (sps->profile_idc==FREXT_Hi10P) || - (sps->profile_idc==FREXT_Hi422) || - (sps->profile_idc==FREXT_Hi444) || - (sps->profile_idc==FREXT_CAVLC444) + if ((sps->profile_idc == FREXT_HP) || (sps->profile_idc == FREXT_Hi10P) || + (sps->profile_idc == FREXT_Hi422) || (sps->profile_idc == FREXT_Hi444) || + (sps->profile_idc == FREXT_CAVLC444) #if (MVC_EXTENSION_ENABLE) - || (sps->profile_idc==MVC_HIGH) - || (sps->profile_idc==STEREO_HIGH) + || (sps->profile_idc == MVC_HIGH) || (sps->profile_idc == STEREO_HIGH) #endif - ) - { - sps->chroma_format_idc = ue_v ("SPS: chroma_format_idc" , s); + ) { + sps->chroma_format_idc = ue_v("SPS: chroma_format_idc", s); - if(sps->chroma_format_idc == YUV444) - { - sps->separate_colour_plane_flag = u_1 ("SPS: separate_colour_plane_flag" , s); + if (sps->chroma_format_idc == YUV444) { + sps->separate_colour_plane_flag = + u_1("SPS: separate_colour_plane_flag", s); } - sps->bit_depth_luma_minus8 = ue_v ("SPS: bit_depth_luma_minus8" , s); - sps->bit_depth_chroma_minus8 = ue_v ("SPS: bit_depth_chroma_minus8" , s); - //checking; - if((sps->bit_depth_luma_minus8+8 > sizeof(imgpel)*8) || (sps->bit_depth_chroma_minus8+8> sizeof(imgpel)*8)) - error ("Source picture has higher bit depth than imgpel data type. \nPlease recompile with larger data type for imgpel.", 500); + sps->bit_depth_luma_minus8 = ue_v("SPS: bit_depth_luma_minus8", s); + sps->bit_depth_chroma_minus8 = ue_v("SPS: bit_depth_chroma_minus8", s); + // checking; + if ((sps->bit_depth_luma_minus8 + 8 > sizeof(imgpel) * 8) || + (sps->bit_depth_chroma_minus8 + 8 > sizeof(imgpel) * 8)) + error("Source picture has higher bit depth than imgpel data type. " + "\nPlease recompile with larger data type for imgpel.", + 500); - p_Vid->lossless_qpprime_flag = u_1 ("SPS: lossless_qpprime_y_zero_flag" , s); + p_Vid->lossless_qpprime_flag = u_1("SPS: lossless_qpprime_y_zero_flag", s); - sps->seq_scaling_matrix_present_flag = u_1 ( "SPS: seq_scaling_matrix_present_flag" , s); - - if(sps->seq_scaling_matrix_present_flag) - { + sps->seq_scaling_matrix_present_flag = + u_1("SPS: seq_scaling_matrix_present_flag", s); + + if (sps->seq_scaling_matrix_present_flag) { n_ScalingList = (sps->chroma_format_idc != YUV444) ? 8 : 12; - for(i=0; iseq_scaling_list_present_flag[i] = u_1 ( "SPS: seq_scaling_list_present_flag" , s); - if(sps->seq_scaling_list_present_flag[i]) - { - if(i<6) - Scaling_List(sps->ScalingList4x4[i], 16, &sps->UseDefaultScalingMatrix4x4Flag[i], s); + for (i = 0; i < n_ScalingList; i++) { + sps->seq_scaling_list_present_flag[i] = + u_1("SPS: seq_scaling_list_present_flag", s); + if (sps->seq_scaling_list_present_flag[i]) { + if (i < 6) + Scaling_List(sps->ScalingList4x4[i], 16, + &sps->UseDefaultScalingMatrix4x4Flag[i], s); else - Scaling_List(sps->ScalingList8x8[i-6], 64, &sps->UseDefaultScalingMatrix8x8Flag[i-6], s); + Scaling_List(sps->ScalingList8x8[i - 6], 64, + &sps->UseDefaultScalingMatrix8x8Flag[i - 6], s); } } } } - sps->log2_max_frame_num_minus4 = ue_v ("SPS: log2_max_frame_num_minus4" , s); - sps->pic_order_cnt_type = ue_v ("SPS: pic_order_cnt_type" , s); + sps->log2_max_frame_num_minus4 = ue_v("SPS: log2_max_frame_num_minus4", s); + sps->pic_order_cnt_type = ue_v("SPS: pic_order_cnt_type", s); if (sps->pic_order_cnt_type == 0) - sps->log2_max_pic_order_cnt_lsb_minus4 = ue_v ("SPS: log2_max_pic_order_cnt_lsb_minus4" , s); - else if (sps->pic_order_cnt_type == 1) - { - sps->delta_pic_order_always_zero_flag = u_1 ("SPS: delta_pic_order_always_zero_flag" , s); - sps->offset_for_non_ref_pic = se_v ("SPS: offset_for_non_ref_pic" , s); - sps->offset_for_top_to_bottom_field = se_v ("SPS: offset_for_top_to_bottom_field" , s); - sps->num_ref_frames_in_pic_order_cnt_cycle = ue_v ("SPS: num_ref_frames_in_pic_order_cnt_cycle" , s); - for(i=0; inum_ref_frames_in_pic_order_cnt_cycle; i++) - sps->offset_for_ref_frame[i] = se_v ("SPS: offset_for_ref_frame[i]" , s); + sps->log2_max_pic_order_cnt_lsb_minus4 = + ue_v("SPS: log2_max_pic_order_cnt_lsb_minus4", s); + else if (sps->pic_order_cnt_type == 1) { + sps->delta_pic_order_always_zero_flag = + u_1("SPS: delta_pic_order_always_zero_flag", s); + sps->offset_for_non_ref_pic = se_v("SPS: offset_for_non_ref_pic", s); + sps->offset_for_top_to_bottom_field = + se_v("SPS: offset_for_top_to_bottom_field", s); + sps->num_ref_frames_in_pic_order_cnt_cycle = + ue_v("SPS: num_ref_frames_in_pic_order_cnt_cycle", s); + for (i = 0; i < sps->num_ref_frames_in_pic_order_cnt_cycle; i++) + sps->offset_for_ref_frame[i] = se_v("SPS: offset_for_ref_frame[i]", s); } - sps->num_ref_frames = ue_v ("SPS: num_ref_frames" , s); - sps->gaps_in_frame_num_value_allowed_flag = u_1 ("SPS: gaps_in_frame_num_value_allowed_flag" , s); - sps->pic_width_in_mbs_minus1 = ue_v ("SPS: pic_width_in_mbs_minus1" , s); - sps->pic_height_in_map_units_minus1 = ue_v ("SPS: pic_height_in_map_units_minus1" , s); - sps->frame_mbs_only_flag = u_1 ("SPS: frame_mbs_only_flag" , s); - if (!sps->frame_mbs_only_flag) - { - sps->mb_adaptive_frame_field_flag = u_1 ("SPS: mb_adaptive_frame_field_flag" , s); + sps->num_ref_frames = ue_v("SPS: num_ref_frames", s); + sps->gaps_in_frame_num_value_allowed_flag = + u_1("SPS: gaps_in_frame_num_value_allowed_flag", s); + sps->pic_width_in_mbs_minus1 = ue_v("SPS: pic_width_in_mbs_minus1", s); + sps->pic_height_in_map_units_minus1 = + ue_v("SPS: pic_height_in_map_units_minus1", s); + sps->frame_mbs_only_flag = u_1("SPS: frame_mbs_only_flag", s); + if (!sps->frame_mbs_only_flag) { + sps->mb_adaptive_frame_field_flag = + u_1("SPS: mb_adaptive_frame_field_flag", s); } - sps->direct_8x8_inference_flag = u_1 ("SPS: direct_8x8_inference_flag" , s); - sps->frame_cropping_flag = u_1 ("SPS: frame_cropping_flag" , s); + sps->direct_8x8_inference_flag = u_1("SPS: direct_8x8_inference_flag", s); + sps->frame_cropping_flag = u_1("SPS: frame_cropping_flag", s); - if (sps->frame_cropping_flag) - { - sps->frame_cropping_rect_left_offset = ue_v ("SPS: frame_cropping_rect_left_offset" , s); - sps->frame_cropping_rect_right_offset = ue_v ("SPS: frame_cropping_rect_right_offset" , s); - sps->frame_cropping_rect_top_offset = ue_v ("SPS: frame_cropping_rect_top_offset" , s); - sps->frame_cropping_rect_bottom_offset = ue_v ("SPS: frame_cropping_rect_bottom_offset" , s); + if (sps->frame_cropping_flag) { + sps->frame_cropping_rect_left_offset = + ue_v("SPS: frame_cropping_rect_left_offset", s); + sps->frame_cropping_rect_right_offset = + ue_v("SPS: frame_cropping_rect_right_offset", s); + sps->frame_cropping_rect_top_offset = + ue_v("SPS: frame_cropping_rect_top_offset", s); + sps->frame_cropping_rect_bottom_offset = + ue_v("SPS: frame_cropping_rect_bottom_offset", s); } - sps->vui_parameters_present_flag = (Boolean) u_1 ("SPS: vui_parameters_present_flag" , s); + sps->vui_parameters_present_flag = + (Boolean)u_1("SPS: vui_parameters_present_flag", s); InitVUI(sps); ReadVUI(p, sps); @@ -205,458 +206,464 @@ int InterpretSPS (VideoParameters *p_Vid, DataPartition *p, seq_parameter_set_rb // fill subset_sps with content of p #if (MVC_EXTENSION_ENABLE) -static int InterpretSubsetSPS (VideoParameters *p_Vid, DataPartition *p, int *curr_seq_set_id) -{ +static int InterpretSubsetSPS(VideoParameters *p_Vid, DataPartition *p, + int *curr_seq_set_id) { subset_seq_parameter_set_rbsp_t *subset_sps; unsigned int additional_extension2_flag; Bitstream *s = p->bitstream; seq_parameter_set_rbsp_t *sps = AllocSPS(); - assert (p != NULL); - assert (p->bitstream != NULL); - assert (p->bitstream->streamBuffer != 0); + assert(p != NULL); + assert(p->bitstream != NULL); + assert(p->bitstream->streamBuffer != 0); - InterpretSPS (p_Vid, p, sps); + InterpretSPS(p_Vid, p, sps); *curr_seq_set_id = sps->seq_parameter_set_id; subset_sps = p_Vid->SubsetSeqParSet + sps->seq_parameter_set_id; - if(subset_sps->Valid || subset_sps->num_views_minus1>=0) - { + if (subset_sps->Valid || subset_sps->num_views_minus1 >= 0) { reset_subset_sps(subset_sps); } - memcpy (&subset_sps->sps, sps, sizeof (seq_parameter_set_rbsp_t)); + memcpy(&subset_sps->sps, sps, sizeof(seq_parameter_set_rbsp_t)); - assert (subset_sps != NULL); + assert(subset_sps != NULL); subset_sps->Valid = FALSE; - /*if(subset_sps->sps.profile_idc == SCALABLE_BASELINE_PROFILE || subset_sps->sps.profile_idc == SCALABLE_HIGH_PROFILE) + /*if(subset_sps->sps.profile_idc == SCALABLE_BASELINE_PROFILE || + subset_sps->sps.profile_idc == SCALABLE_HIGH_PROFILE) { - printf("\nScalable profile is not supported yet!\n"); + printf("\nScalable profile is not supported yet!\n"); } else*/ - if(subset_sps->sps.profile_idc == MVC_HIGH || subset_sps->sps.profile_idc == STEREO_HIGH) - { - subset_sps->bit_equal_to_one = u_1("bit_equal_to_one" , s); + if (subset_sps->sps.profile_idc == MVC_HIGH || + subset_sps->sps.profile_idc == STEREO_HIGH) { + subset_sps->bit_equal_to_one = u_1("bit_equal_to_one", s); - if(subset_sps->bit_equal_to_one !=1 ) - { - printf("\nbit_equal_to_one is not equal to 1!\n"); - return p_Dec->UsedBits; - } + if (subset_sps->bit_equal_to_one != 1) { + printf("\nbit_equal_to_one is not equal to 1!\n"); + return p_Dec->UsedBits; + } - seq_parameter_set_mvc_extension(subset_sps, s); - - subset_sps->mvc_vui_parameters_present_flag = u_1("mvc_vui_parameters_present_flag" , s); - if(subset_sps->mvc_vui_parameters_present_flag) - mvc_vui_parameters_extension(&(subset_sps->MVCVUIParams) , s); + seq_parameter_set_mvc_extension(subset_sps, s); + + subset_sps->mvc_vui_parameters_present_flag = + u_1("mvc_vui_parameters_present_flag", s); + if (subset_sps->mvc_vui_parameters_present_flag) + mvc_vui_parameters_extension(&(subset_sps->MVCVUIParams), s); } - additional_extension2_flag = u_1("additional_extension2_flag" , s); - if(additional_extension2_flag) - { - while (more_rbsp_data(s->streamBuffer, s->frame_bitoffset,s->bitstream_length)) - additional_extension2_flag = u_1("additional_extension2_flag" , s); + additional_extension2_flag = u_1("additional_extension2_flag", s); + if (additional_extension2_flag) { + while (more_rbsp_data(s->streamBuffer, s->frame_bitoffset, + s->bitstream_length)) + additional_extension2_flag = u_1("additional_extension2_flag", s); } if (subset_sps->sps.Valid) - subset_sps->Valid = TRUE; + subset_sps->Valid = TRUE; - FreeSPS (sps); + FreeSPS(sps); return p_Dec->UsedBits; - } #endif -void InitVUI(seq_parameter_set_rbsp_t *sps) -{ +void InitVUI(seq_parameter_set_rbsp_t *sps) { sps->vui_seq_parameters.matrix_coefficients = 2; } - -int ReadVUI(DataPartition *p, seq_parameter_set_rbsp_t *sps) -{ +int ReadVUI(DataPartition *p, seq_parameter_set_rbsp_t *sps) { Bitstream *s = p->bitstream; - if (sps->vui_parameters_present_flag) - { - sps->vui_seq_parameters.aspect_ratio_info_present_flag = u_1 ("VUI: aspect_ratio_info_present_flag" , s); - if (sps->vui_seq_parameters.aspect_ratio_info_present_flag) - { - sps->vui_seq_parameters.aspect_ratio_idc = u_v ( 8, "VUI: aspect_ratio_idc" , s); - if (255==sps->vui_seq_parameters.aspect_ratio_idc) - { - sps->vui_seq_parameters.sar_width = (unsigned short) u_v (16, "VUI: sar_width" , s); - sps->vui_seq_parameters.sar_height = (unsigned short) u_v (16, "VUI: sar_height" , s); + if (sps->vui_parameters_present_flag) { + sps->vui_seq_parameters.aspect_ratio_info_present_flag = + u_1("VUI: aspect_ratio_info_present_flag", s); + if (sps->vui_seq_parameters.aspect_ratio_info_present_flag) { + sps->vui_seq_parameters.aspect_ratio_idc = + u_v(8, "VUI: aspect_ratio_idc", s); + if (255 == sps->vui_seq_parameters.aspect_ratio_idc) { + sps->vui_seq_parameters.sar_width = + (unsigned short)u_v(16, "VUI: sar_width", s); + sps->vui_seq_parameters.sar_height = + (unsigned short)u_v(16, "VUI: sar_height", s); } } - sps->vui_seq_parameters.overscan_info_present_flag = u_1 ("VUI: overscan_info_present_flag" , s); - if (sps->vui_seq_parameters.overscan_info_present_flag) - { - sps->vui_seq_parameters.overscan_appropriate_flag = u_1 ("VUI: overscan_appropriate_flag" , s); + sps->vui_seq_parameters.overscan_info_present_flag = + u_1("VUI: overscan_info_present_flag", s); + if (sps->vui_seq_parameters.overscan_info_present_flag) { + sps->vui_seq_parameters.overscan_appropriate_flag = + u_1("VUI: overscan_appropriate_flag", s); } - sps->vui_seq_parameters.video_signal_type_present_flag = u_1 ("VUI: video_signal_type_present_flag" , s); - if (sps->vui_seq_parameters.video_signal_type_present_flag) - { - sps->vui_seq_parameters.video_format = u_v ( 3,"VUI: video_format" , s); - sps->vui_seq_parameters.video_full_range_flag = u_1 ( "VUI: video_full_range_flag" , s); - sps->vui_seq_parameters.colour_description_present_flag = u_1 ( "VUI: color_description_present_flag" , s); - if(sps->vui_seq_parameters.colour_description_present_flag) - { - sps->vui_seq_parameters.colour_primaries = u_v ( 8,"VUI: colour_primaries" , s); - sps->vui_seq_parameters.transfer_characteristics = u_v ( 8,"VUI: transfer_characteristics" , s); - sps->vui_seq_parameters.matrix_coefficients = u_v ( 8,"VUI: matrix_coefficients" , s); + sps->vui_seq_parameters.video_signal_type_present_flag = + u_1("VUI: video_signal_type_present_flag", s); + if (sps->vui_seq_parameters.video_signal_type_present_flag) { + sps->vui_seq_parameters.video_format = u_v(3, "VUI: video_format", s); + sps->vui_seq_parameters.video_full_range_flag = + u_1("VUI: video_full_range_flag", s); + sps->vui_seq_parameters.colour_description_present_flag = + u_1("VUI: color_description_present_flag", s); + if (sps->vui_seq_parameters.colour_description_present_flag) { + sps->vui_seq_parameters.colour_primaries = + u_v(8, "VUI: colour_primaries", s); + sps->vui_seq_parameters.transfer_characteristics = + u_v(8, "VUI: transfer_characteristics", s); + sps->vui_seq_parameters.matrix_coefficients = + u_v(8, "VUI: matrix_coefficients", s); } } - sps->vui_seq_parameters.chroma_location_info_present_flag = u_1 ( "VUI: chroma_loc_info_present_flag" , s); - if(sps->vui_seq_parameters.chroma_location_info_present_flag) - { - sps->vui_seq_parameters.chroma_sample_loc_type_top_field = ue_v ( "VUI: chroma_sample_loc_type_top_field" , s); - sps->vui_seq_parameters.chroma_sample_loc_type_bottom_field = ue_v ( "VUI: chroma_sample_loc_type_bottom_field" , s); + sps->vui_seq_parameters.chroma_location_info_present_flag = + u_1("VUI: chroma_loc_info_present_flag", s); + if (sps->vui_seq_parameters.chroma_location_info_present_flag) { + sps->vui_seq_parameters.chroma_sample_loc_type_top_field = + ue_v("VUI: chroma_sample_loc_type_top_field", s); + sps->vui_seq_parameters.chroma_sample_loc_type_bottom_field = + ue_v("VUI: chroma_sample_loc_type_bottom_field", s); } - sps->vui_seq_parameters.timing_info_present_flag = u_1 ("VUI: timing_info_present_flag" , s); - if (sps->vui_seq_parameters.timing_info_present_flag) - { - sps->vui_seq_parameters.num_units_in_tick = u_v (32,"VUI: num_units_in_tick" , s); - sps->vui_seq_parameters.time_scale = u_v (32,"VUI: time_scale" , s); - sps->vui_seq_parameters.fixed_frame_rate_flag = u_1 ( "VUI: fixed_frame_rate_flag" , s); + sps->vui_seq_parameters.timing_info_present_flag = + u_1("VUI: timing_info_present_flag", s); + if (sps->vui_seq_parameters.timing_info_present_flag) { + sps->vui_seq_parameters.num_units_in_tick = + u_v(32, "VUI: num_units_in_tick", s); + sps->vui_seq_parameters.time_scale = u_v(32, "VUI: time_scale", s); + sps->vui_seq_parameters.fixed_frame_rate_flag = + u_1("VUI: fixed_frame_rate_flag", s); } - sps->vui_seq_parameters.nal_hrd_parameters_present_flag = u_1 ("VUI: nal_hrd_parameters_present_flag" , s); - if (sps->vui_seq_parameters.nal_hrd_parameters_present_flag) - { + sps->vui_seq_parameters.nal_hrd_parameters_present_flag = + u_1("VUI: nal_hrd_parameters_present_flag", s); + if (sps->vui_seq_parameters.nal_hrd_parameters_present_flag) { ReadHRDParameters(p, &(sps->vui_seq_parameters.nal_hrd_parameters)); } - sps->vui_seq_parameters.vcl_hrd_parameters_present_flag = u_1 ("VUI: vcl_hrd_parameters_present_flag" , s); - if (sps->vui_seq_parameters.vcl_hrd_parameters_present_flag) - { + sps->vui_seq_parameters.vcl_hrd_parameters_present_flag = + u_1("VUI: vcl_hrd_parameters_present_flag", s); + if (sps->vui_seq_parameters.vcl_hrd_parameters_present_flag) { ReadHRDParameters(p, &(sps->vui_seq_parameters.vcl_hrd_parameters)); } - if (sps->vui_seq_parameters.nal_hrd_parameters_present_flag || sps->vui_seq_parameters.vcl_hrd_parameters_present_flag) - { - sps->vui_seq_parameters.low_delay_hrd_flag = u_1 ("VUI: low_delay_hrd_flag" , s); + if (sps->vui_seq_parameters.nal_hrd_parameters_present_flag || + sps->vui_seq_parameters.vcl_hrd_parameters_present_flag) { + sps->vui_seq_parameters.low_delay_hrd_flag = + u_1("VUI: low_delay_hrd_flag", s); } - sps->vui_seq_parameters.pic_struct_present_flag = u_1 ("VUI: pic_struct_present_flag " , s); - sps->vui_seq_parameters.bitstream_restriction_flag = u_1 ("VUI: bitstream_restriction_flag" , s); - if (sps->vui_seq_parameters.bitstream_restriction_flag) - { - sps->vui_seq_parameters.motion_vectors_over_pic_boundaries_flag = u_1 ("VUI: motion_vectors_over_pic_boundaries_flag", s); - sps->vui_seq_parameters.max_bytes_per_pic_denom = ue_v ("VUI: max_bytes_per_pic_denom" , s); - sps->vui_seq_parameters.max_bits_per_mb_denom = ue_v ("VUI: max_bits_per_mb_denom" , s); - sps->vui_seq_parameters.log2_max_mv_length_horizontal = ue_v ("VUI: log2_max_mv_length_horizontal" , s); - sps->vui_seq_parameters.log2_max_mv_length_vertical = ue_v ("VUI: log2_max_mv_length_vertical" , s); - sps->vui_seq_parameters.num_reorder_frames = ue_v ("VUI: num_reorder_frames" , s); - sps->vui_seq_parameters.max_dec_frame_buffering = ue_v ("VUI: max_dec_frame_buffering" , s); + sps->vui_seq_parameters.pic_struct_present_flag = + u_1("VUI: pic_struct_present_flag ", s); + sps->vui_seq_parameters.bitstream_restriction_flag = + u_1("VUI: bitstream_restriction_flag", s); + if (sps->vui_seq_parameters.bitstream_restriction_flag) { + sps->vui_seq_parameters.motion_vectors_over_pic_boundaries_flag = + u_1("VUI: motion_vectors_over_pic_boundaries_flag", s); + sps->vui_seq_parameters.max_bytes_per_pic_denom = + ue_v("VUI: max_bytes_per_pic_denom", s); + sps->vui_seq_parameters.max_bits_per_mb_denom = + ue_v("VUI: max_bits_per_mb_denom", s); + sps->vui_seq_parameters.log2_max_mv_length_horizontal = + ue_v("VUI: log2_max_mv_length_horizontal", s); + sps->vui_seq_parameters.log2_max_mv_length_vertical = + ue_v("VUI: log2_max_mv_length_vertical", s); + sps->vui_seq_parameters.num_reorder_frames = + ue_v("VUI: num_reorder_frames", s); + sps->vui_seq_parameters.max_dec_frame_buffering = + ue_v("VUI: max_dec_frame_buffering", s); } } return 0; } - -int ReadHRDParameters(DataPartition *p, hrd_parameters_t *hrd) -{ +int ReadHRDParameters(DataPartition *p, hrd_parameters_t *hrd) { Bitstream *s = p->bitstream; unsigned int SchedSelIdx; - hrd->cpb_cnt_minus1 = ue_v ( "VUI: cpb_cnt_minus1" , s); - hrd->bit_rate_scale = u_v ( 4,"VUI: bit_rate_scale" , s); - hrd->cpb_size_scale = u_v ( 4,"VUI: cpb_size_scale" , s); + hrd->cpb_cnt_minus1 = ue_v("VUI: cpb_cnt_minus1", s); + hrd->bit_rate_scale = u_v(4, "VUI: bit_rate_scale", s); + hrd->cpb_size_scale = u_v(4, "VUI: cpb_size_scale", s); - for( SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1; SchedSelIdx++ ) - { - hrd->bit_rate_value_minus1[ SchedSelIdx ] = ue_v ( "VUI: bit_rate_value_minus1" , s); - hrd->cpb_size_value_minus1[ SchedSelIdx ] = ue_v ( "VUI: cpb_size_value_minus1" , s); - hrd->cbr_flag[ SchedSelIdx ] = u_1 ( "VUI: cbr_flag" , s); + for (SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1; SchedSelIdx++) { + hrd->bit_rate_value_minus1[SchedSelIdx] = + ue_v("VUI: bit_rate_value_minus1", s); + hrd->cpb_size_value_minus1[SchedSelIdx] = + ue_v("VUI: cpb_size_value_minus1", s); + hrd->cbr_flag[SchedSelIdx] = u_1("VUI: cbr_flag", s); } - hrd->initial_cpb_removal_delay_length_minus1 = u_v ( 5,"VUI: initial_cpb_removal_delay_length_minus1" , s); - hrd->cpb_removal_delay_length_minus1 = u_v ( 5,"VUI: cpb_removal_delay_length_minus1" , s); - hrd->dpb_output_delay_length_minus1 = u_v ( 5,"VUI: dpb_output_delay_length_minus1" , s); - hrd->time_offset_length = u_v ( 5,"VUI: time_offset_length" , s); + hrd->initial_cpb_removal_delay_length_minus1 = + u_v(5, "VUI: initial_cpb_removal_delay_length_minus1", s); + hrd->cpb_removal_delay_length_minus1 = + u_v(5, "VUI: cpb_removal_delay_length_minus1", s); + hrd->dpb_output_delay_length_minus1 = + u_v(5, "VUI: dpb_output_delay_length_minus1", s); + hrd->time_offset_length = u_v(5, "VUI: time_offset_length", s); return 0; } - -int InterpretPPS (VideoParameters *p_Vid, DataPartition *p, pic_parameter_set_rbsp_t *pps) -{ +int InterpretPPS(VideoParameters *p_Vid, DataPartition *p, + pic_parameter_set_rbsp_t *pps) { unsigned i; unsigned n_ScalingList; int chroma_format_idc; int NumberBitsPerSliceGroupId; Bitstream *s = p->bitstream; - assert (p != NULL); - assert (p->bitstream != NULL); - assert (p->bitstream->streamBuffer != 0); - assert (pps != NULL); + assert(p != NULL); + assert(p->bitstream != NULL); + assert(p->bitstream->streamBuffer != 0); + assert(pps != NULL); p_Dec->UsedBits = 0; - pps->pic_parameter_set_id = ue_v ("PPS: pic_parameter_set_id" , s); - pps->seq_parameter_set_id = ue_v ("PPS: seq_parameter_set_id" , s); - pps->entropy_coding_mode_flag = u_1 ("PPS: entropy_coding_mode_flag" , s); + pps->pic_parameter_set_id = ue_v("PPS: pic_parameter_set_id", s); + pps->seq_parameter_set_id = ue_v("PPS: seq_parameter_set_id", s); + pps->entropy_coding_mode_flag = u_1("PPS: entropy_coding_mode_flag", s); - //! Note: as per JVT-F078 the following bit is unconditional. If F078 is not accepted, then - //! one has to fetch the correct SPS to check whether the bit is present (hopefully there is - //! no consistency problem :-( - //! The current encoder code handles this in the same way. When you change this, don't forget - //! the encoder! StW, 12/8/02 - pps->bottom_field_pic_order_in_frame_present_flag = u_1 ("PPS: bottom_field_pic_order_in_frame_present_flag" , s); + //! Note: as per JVT-F078 the following bit is unconditional. If F078 is not + //! accepted, then one has to fetch the correct SPS to check whether the bit + //! is present (hopefully there is no consistency problem :-( The current + //! encoder code handles this in the same way. When you change this, don't + //! forget the encoder! StW, 12/8/02 + pps->bottom_field_pic_order_in_frame_present_flag = + u_1("PPS: bottom_field_pic_order_in_frame_present_flag", s); - pps->num_slice_groups_minus1 = ue_v ("PPS: num_slice_groups_minus1" , s); + pps->num_slice_groups_minus1 = ue_v("PPS: num_slice_groups_minus1", s); // FMO stuff begins here - if (pps->num_slice_groups_minus1 > 0) - { - pps->slice_group_map_type = ue_v ("PPS: slice_group_map_type" , s); - if (pps->slice_group_map_type == 0) - { - for (i=0; i<=pps->num_slice_groups_minus1; i++) - pps->run_length_minus1 [i] = ue_v ("PPS: run_length_minus1 [i]" , s); - } - else if (pps->slice_group_map_type == 2) - { - for (i=0; inum_slice_groups_minus1; i++) - { + if (pps->num_slice_groups_minus1 > 0) { + pps->slice_group_map_type = ue_v("PPS: slice_group_map_type", s); + if (pps->slice_group_map_type == 0) { + for (i = 0; i <= pps->num_slice_groups_minus1; i++) + pps->run_length_minus1[i] = ue_v("PPS: run_length_minus1 [i]", s); + } else if (pps->slice_group_map_type == 2) { + for (i = 0; i < pps->num_slice_groups_minus1; i++) { //! JVT-F078: avoid reference of SPS by using ue(v) instead of u(v) - pps->top_left [i] = ue_v ("PPS: top_left [i]" , s); - pps->bottom_right [i] = ue_v ("PPS: bottom_right [i]" , s); + pps->top_left[i] = ue_v("PPS: top_left [i]", s); + pps->bottom_right[i] = ue_v("PPS: bottom_right [i]", s); } - } - else if (pps->slice_group_map_type == 3 || - pps->slice_group_map_type == 4 || - pps->slice_group_map_type == 5) - { - pps->slice_group_change_direction_flag = u_1 ("PPS: slice_group_change_direction_flag" , s); - pps->slice_group_change_rate_minus1 = ue_v ("PPS: slice_group_change_rate_minus1" , s); - } - else if (pps->slice_group_map_type == 6) - { - if (pps->num_slice_groups_minus1+1 >4) + } else if (pps->slice_group_map_type == 3 || + pps->slice_group_map_type == 4 || + pps->slice_group_map_type == 5) { + pps->slice_group_change_direction_flag = + u_1("PPS: slice_group_change_direction_flag", s); + pps->slice_group_change_rate_minus1 = + ue_v("PPS: slice_group_change_rate_minus1", s); + } else if (pps->slice_group_map_type == 6) { + if (pps->num_slice_groups_minus1 + 1 > 4) NumberBitsPerSliceGroupId = 3; - else if (pps->num_slice_groups_minus1+1 > 2) + else if (pps->num_slice_groups_minus1 + 1 > 2) NumberBitsPerSliceGroupId = 2; else NumberBitsPerSliceGroupId = 1; - pps->pic_size_in_map_units_minus1 = ue_v ("PPS: pic_size_in_map_units_minus1" , s); - if ((pps->slice_group_id = calloc (pps->pic_size_in_map_units_minus1+1, 1)) == NULL) - no_mem_exit ("InterpretPPS: slice_group_id"); - for (i=0; i<=pps->pic_size_in_map_units_minus1; i++) - pps->slice_group_id[i] = (byte) u_v (NumberBitsPerSliceGroupId, "slice_group_id[i]", s); + pps->pic_size_in_map_units_minus1 = + ue_v("PPS: pic_size_in_map_units_minus1", s); + if ((pps->slice_group_id = + calloc(pps->pic_size_in_map_units_minus1 + 1, 1)) == NULL) + no_mem_exit("InterpretPPS: slice_group_id"); + for (i = 0; i <= pps->pic_size_in_map_units_minus1; i++) + pps->slice_group_id[i] = + (byte)u_v(NumberBitsPerSliceGroupId, "slice_group_id[i]", s); } } // End of FMO stuff - pps->num_ref_idx_l0_active_minus1 = ue_v ("PPS: num_ref_idx_l0_active_minus1" , s); - pps->num_ref_idx_l1_active_minus1 = ue_v ("PPS: num_ref_idx_l1_active_minus1" , s); - pps->weighted_pred_flag = u_1 ("PPS: weighted_pred_flag" , s); - pps->weighted_bipred_idc = u_v ( 2, "PPS: weighted_bipred_idc" , s); - pps->pic_init_qp_minus26 = se_v ("PPS: pic_init_qp_minus26" , s); - pps->pic_init_qs_minus26 = se_v ("PPS: pic_init_qs_minus26" , s); + pps->num_ref_idx_l0_active_minus1 = + ue_v("PPS: num_ref_idx_l0_active_minus1", s); + pps->num_ref_idx_l1_active_minus1 = + ue_v("PPS: num_ref_idx_l1_active_minus1", s); + pps->weighted_pred_flag = u_1("PPS: weighted_pred_flag", s); + pps->weighted_bipred_idc = u_v(2, "PPS: weighted_bipred_idc", s); + pps->pic_init_qp_minus26 = se_v("PPS: pic_init_qp_minus26", s); + pps->pic_init_qs_minus26 = se_v("PPS: pic_init_qs_minus26", s); - pps->chroma_qp_index_offset = se_v ("PPS: chroma_qp_index_offset" , s); + pps->chroma_qp_index_offset = se_v("PPS: chroma_qp_index_offset", s); - pps->deblocking_filter_control_present_flag = u_1 ("PPS: deblocking_filter_control_present_flag" , s); - pps->constrained_intra_pred_flag = u_1 ("PPS: constrained_intra_pred_flag" , s); - pps->redundant_pic_cnt_present_flag = u_1 ("PPS: redundant_pic_cnt_present_flag" , s); + pps->deblocking_filter_control_present_flag = + u_1("PPS: deblocking_filter_control_present_flag", s); + pps->constrained_intra_pred_flag = u_1("PPS: constrained_intra_pred_flag", s); + pps->redundant_pic_cnt_present_flag = + u_1("PPS: redundant_pic_cnt_present_flag", s); - if(more_rbsp_data(s->streamBuffer, s->frame_bitoffset,s->bitstream_length)) // more_data_in_rbsp() + if (more_rbsp_data(s->streamBuffer, s->frame_bitoffset, + s->bitstream_length)) // more_data_in_rbsp() { - //Fidelity Range Extensions Stuff - pps->transform_8x8_mode_flag = u_1 ("PPS: transform_8x8_mode_flag" , s); - pps->pic_scaling_matrix_present_flag = u_1 ("PPS: pic_scaling_matrix_present_flag" , s); + // Fidelity Range Extensions Stuff + pps->transform_8x8_mode_flag = u_1("PPS: transform_8x8_mode_flag", s); + pps->pic_scaling_matrix_present_flag = + u_1("PPS: pic_scaling_matrix_present_flag", s); - if(pps->pic_scaling_matrix_present_flag) - { - chroma_format_idc = p_Vid->SeqParSet[pps->seq_parameter_set_id].chroma_format_idc; - n_ScalingList = 6 + ((chroma_format_idc != YUV444) ? 2 : 6) * pps->transform_8x8_mode_flag; - for(i=0; ipic_scaling_list_present_flag[i]= u_1 ("PPS: pic_scaling_list_present_flag" , s); + if (pps->pic_scaling_matrix_present_flag) { + chroma_format_idc = + p_Vid->SeqParSet[pps->seq_parameter_set_id].chroma_format_idc; + n_ScalingList = 6 + ((chroma_format_idc != YUV444) ? 2 : 6) * + pps->transform_8x8_mode_flag; + for (i = 0; i < n_ScalingList; i++) { + pps->pic_scaling_list_present_flag[i] = + u_1("PPS: pic_scaling_list_present_flag", s); - if(pps->pic_scaling_list_present_flag[i]) - { - if(i<6) - Scaling_List(pps->ScalingList4x4[i], 16, &pps->UseDefaultScalingMatrix4x4Flag[i], s); + if (pps->pic_scaling_list_present_flag[i]) { + if (i < 6) + Scaling_List(pps->ScalingList4x4[i], 16, + &pps->UseDefaultScalingMatrix4x4Flag[i], s); else - Scaling_List(pps->ScalingList8x8[i-6], 64, &pps->UseDefaultScalingMatrix8x8Flag[i-6], s); + Scaling_List(pps->ScalingList8x8[i - 6], 64, + &pps->UseDefaultScalingMatrix8x8Flag[i - 6], s); } } } - pps->second_chroma_qp_index_offset = se_v ("PPS: second_chroma_qp_index_offset" , s); - } - else - { - pps->second_chroma_qp_index_offset = pps->chroma_qp_index_offset; + pps->second_chroma_qp_index_offset = + se_v("PPS: second_chroma_qp_index_offset", s); + } else { + pps->second_chroma_qp_index_offset = pps->chroma_qp_index_offset; } pps->Valid = TRUE; return p_Dec->UsedBits; } - -void PPSConsistencyCheck (pic_parameter_set_rbsp_t *pps) -{ - printf ("Consistency checking a picture parset, to be implemented\n"); -// if (pps->seq_parameter_set_id invalid then do something) +void PPSConsistencyCheck(pic_parameter_set_rbsp_t *pps) { + printf("Consistency checking a picture parset, to be implemented\n"); + // if (pps->seq_parameter_set_id invalid then do something) } -void SPSConsistencyCheck (seq_parameter_set_rbsp_t *sps) -{ - printf ("Consistency checking a sequence parset, to be implemented\n"); +void SPSConsistencyCheck(seq_parameter_set_rbsp_t *sps) { + printf("Consistency checking a sequence parset, to be implemented\n"); } #if (MVC_EXTENSION_ENABLE) -void SubsetSPSConsistencyCheck (subset_seq_parameter_set_rbsp_t *subset_sps) -{ - printf ("Consistency checking a subset sequence parset, to be implemented\n"); +void SubsetSPSConsistencyCheck(subset_seq_parameter_set_rbsp_t *subset_sps) { + printf("Consistency checking a subset sequence parset, to be implemented\n"); } #endif -void MakePPSavailable (VideoParameters *p_Vid, int id, pic_parameter_set_rbsp_t *pps) -{ - assert (pps->Valid == TRUE); +void MakePPSavailable(VideoParameters *p_Vid, int id, + pic_parameter_set_rbsp_t *pps) { + assert(pps->Valid == TRUE); - if (p_Vid->PicParSet[id].Valid == TRUE && p_Vid->PicParSet[id].slice_group_id != NULL) - free (p_Vid->PicParSet[id].slice_group_id); + if (p_Vid->PicParSet[id].Valid == TRUE && + p_Vid->PicParSet[id].slice_group_id != NULL) + free(p_Vid->PicParSet[id].slice_group_id); - memcpy (&p_Vid->PicParSet[id], pps, sizeof (pic_parameter_set_rbsp_t)); + memcpy(&p_Vid->PicParSet[id], pps, sizeof(pic_parameter_set_rbsp_t)); - // we can simply use the memory provided with the pps. the PPS is destroyed after this function - // call and will not try to free if pps->slice_group_id == NULL + // we can simply use the memory provided with the pps. the PPS is destroyed + // after this function call and will not try to free if pps->slice_group_id == + // NULL p_Vid->PicParSet[id].slice_group_id = pps->slice_group_id; - pps->slice_group_id = NULL; + pps->slice_group_id = NULL; } -void CleanUpPPS(VideoParameters *p_Vid) -{ +void CleanUpPPS(VideoParameters *p_Vid) { int i; - for (i=0; iPicParSet[i].Valid == TRUE && p_Vid->PicParSet[i].slice_group_id != NULL) - free (p_Vid->PicParSet[i].slice_group_id); + for (i = 0; i < MAXPPS; i++) { + if (p_Vid->PicParSet[i].Valid == TRUE && + p_Vid->PicParSet[i].slice_group_id != NULL) + free(p_Vid->PicParSet[i].slice_group_id); p_Vid->PicParSet[i].Valid = FALSE; } } - -void MakeSPSavailable (VideoParameters *p_Vid, int id, seq_parameter_set_rbsp_t *sps) -{ - assert (sps->Valid == TRUE); - memcpy (&p_Vid->SeqParSet[id], sps, sizeof (seq_parameter_set_rbsp_t)); +void MakeSPSavailable(VideoParameters *p_Vid, int id, + seq_parameter_set_rbsp_t *sps) { + assert(sps->Valid == TRUE); + memcpy(&p_Vid->SeqParSet[id], sps, sizeof(seq_parameter_set_rbsp_t)); } - -void ProcessSPS (VideoParameters *p_Vid, NALU_t *nalu) -{ +void ProcessSPS(VideoParameters *p_Vid, NALU_t *nalu) { DataPartition *dp = AllocPartition(1); seq_parameter_set_rbsp_t *sps = AllocSPS(); - memcpy (dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len-1); - dp->bitstream->code_len = dp->bitstream->bitstream_length = RBSPtoSODB (dp->bitstream->streamBuffer, nalu->len-1); + memcpy(dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len - 1); + dp->bitstream->code_len = dp->bitstream->bitstream_length = + RBSPtoSODB(dp->bitstream->streamBuffer, nalu->len - 1); dp->bitstream->ei_flag = 0; dp->bitstream->read_len = dp->bitstream->frame_bitoffset = 0; - InterpretSPS (p_Vid, dp, sps); + InterpretSPS(p_Vid, dp, sps); #if (MVC_EXTENSION_ENABLE) get_max_dec_frame_buf_size(sps); #endif - if (sps->Valid) - { - if (p_Vid->active_sps) - { - if (sps->seq_parameter_set_id == p_Vid->active_sps->seq_parameter_set_id) - { - if (!sps_is_equal(sps, p_Vid->active_sps)) - { - if (p_Vid->dec_picture) // && p_Vid->num_dec_mb == p_Vid->PicSizeInMbs) //? + if (sps->Valid) { + if (p_Vid->active_sps) { + if (sps->seq_parameter_set_id == + p_Vid->active_sps->seq_parameter_set_id) { + if (!sps_is_equal(sps, p_Vid->active_sps)) { + if (p_Vid->dec_picture) // && p_Vid->num_dec_mb == + // p_Vid->PicSizeInMbs) //? { // this may only happen on slice loss exit_picture(p_Vid, &p_Vid->dec_picture); } - p_Vid->active_sps=NULL; + p_Vid->active_sps = NULL; } } } // SPSConsistencyCheck (pps); - MakeSPSavailable (p_Vid, sps->seq_parameter_set_id, sps); + MakeSPSavailable(p_Vid, sps->seq_parameter_set_id, sps); p_Vid->profile_idc = sps->profile_idc; p_Vid->separate_colour_plane_flag = sps->separate_colour_plane_flag; - if( p_Vid->separate_colour_plane_flag ) - { + if (p_Vid->separate_colour_plane_flag) { p_Vid->ChromaArrayType = 0; - } - else - { + } else { p_Vid->ChromaArrayType = sps->chroma_format_idc; } } - FreePartition (dp, 1); - FreeSPS (sps); + FreePartition(dp, 1); + FreeSPS(sps); } #if (MVC_EXTENSION_ENABLE) -void ProcessSubsetSPS (VideoParameters *p_Vid, NALU_t *nalu) -{ +void ProcessSubsetSPS(VideoParameters *p_Vid, NALU_t *nalu) { DataPartition *dp = AllocPartition(1); subset_seq_parameter_set_rbsp_t *subset_sps; int curr_seq_set_id; - memcpy (dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len-1); - dp->bitstream->code_len = dp->bitstream->bitstream_length = RBSPtoSODB (dp->bitstream->streamBuffer, nalu->len-1); + memcpy(dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len - 1); + dp->bitstream->code_len = dp->bitstream->bitstream_length = + RBSPtoSODB(dp->bitstream->streamBuffer, nalu->len - 1); dp->bitstream->ei_flag = 0; dp->bitstream->read_len = dp->bitstream->frame_bitoffset = 0; - InterpretSubsetSPS (p_Vid, dp, &curr_seq_set_id); + InterpretSubsetSPS(p_Vid, dp, &curr_seq_set_id); subset_sps = p_Vid->SubsetSeqParSet + curr_seq_set_id; get_max_dec_frame_buf_size(&(subset_sps->sps)); - if (subset_sps->Valid) - { + if (subset_sps->Valid) { // SubsetSPSConsistencyCheck (subset_sps); p_Vid->profile_idc = subset_sps->sps.profile_idc; - p_Vid->separate_colour_plane_flag = subset_sps->sps.separate_colour_plane_flag; - if( p_Vid->separate_colour_plane_flag ) - { + p_Vid->separate_colour_plane_flag = + subset_sps->sps.separate_colour_plane_flag; + if (p_Vid->separate_colour_plane_flag) { p_Vid->ChromaArrayType = 0; - } - else - { + } else { p_Vid->ChromaArrayType = subset_sps->sps.chroma_format_idc; } } -// FreeSubsetSPS (subset_sps); - FreePartition (dp, 1); + // FreeSubsetSPS (subset_sps); + FreePartition(dp, 1); } #endif -void ProcessPPS (VideoParameters *p_Vid, NALU_t *nalu) -{ +void ProcessPPS(VideoParameters *p_Vid, NALU_t *nalu) { DataPartition *dp = AllocPartition(1); pic_parameter_set_rbsp_t *pps = AllocPPS(); - memcpy (dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len-1); - dp->bitstream->code_len = dp->bitstream->bitstream_length = RBSPtoSODB (dp->bitstream->streamBuffer, nalu->len-1); + memcpy(dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len - 1); + dp->bitstream->code_len = dp->bitstream->bitstream_length = + RBSPtoSODB(dp->bitstream->streamBuffer, nalu->len - 1); dp->bitstream->ei_flag = 0; dp->bitstream->read_len = dp->bitstream->frame_bitoffset = 0; - InterpretPPS (p_Vid, dp, pps); + InterpretPPS(p_Vid, dp, pps); // PPSConsistencyCheck (pps); - if (p_Vid->active_pps) - { - if (pps->pic_parameter_set_id == p_Vid->active_pps->pic_parameter_set_id) - { - if(!pps_is_equal(pps, p_Vid->active_pps)) - { - //copy to next PPS; - memcpy(p_Vid->pNextPPS, p_Vid->active_pps, sizeof (pic_parameter_set_rbsp_t)); + if (p_Vid->active_pps) { + if (pps->pic_parameter_set_id == p_Vid->active_pps->pic_parameter_set_id) { + if (!pps_is_equal(pps, p_Vid->active_pps)) { + // copy to next PPS; + memcpy(p_Vid->pNextPPS, p_Vid->active_pps, + sizeof(pic_parameter_set_rbsp_t)); { - if (p_Vid->dec_picture) // && p_Vid->num_dec_mb == p_Vid->PicSizeInMbs) + if (p_Vid + ->dec_picture) // && p_Vid->num_dec_mb == p_Vid->PicSizeInMbs) { // this may only happen on slice loss exit_picture(p_Vid, &p_Vid->dec_picture); @@ -666,9 +673,9 @@ void ProcessPPS (VideoParameters *p_Vid, NALU_t *nalu) } } } - MakePPSavailable (p_Vid, pps->pic_parameter_set_id, pps); - FreePartition (dp, 1); - FreePPS (pps); + MakePPSavailable(p_Vid, pps->pic_parameter_set_id, pps); + FreePartition(dp, 1); + FreePPS(pps); } /*! @@ -678,8 +685,7 @@ void ProcessPPS (VideoParameters *p_Vid, NALU_t *nalu) * ************************************************************************ */ -static void updateMaxValue(FrameFormat *format) -{ +static void updateMaxValue(FrameFormat *format) { format->max_value[0] = (1 << format->bit_depth[0]) - 1; format->max_value_sq[0] = format->max_value[0] * format->max_value[0]; format->max_value[1] = (1 << format->bit_depth[1]) - 1; @@ -695,25 +701,28 @@ static void updateMaxValue(FrameFormat *format) * ************************************************************************ */ -void reset_format_info(seq_parameter_set_rbsp_t *sps, VideoParameters *p_Vid, FrameFormat *source, FrameFormat *output) -{ +void reset_format_info(seq_parameter_set_rbsp_t *sps, VideoParameters *p_Vid, + FrameFormat *source, FrameFormat *output) { InputParameters *p_Inp = p_Vid->p_Inp; - static const int SubWidthC [4]= { 1, 2, 2, 1}; - static const int SubHeightC [4]= { 1, 2, 1, 1}; + static const int SubWidthC[4] = {1, 2, 2, 1}; + static const int SubHeightC[4] = {1, 2, 1, 1}; int crop_left, crop_right; int crop_top, crop_bottom; // cropping for luma - if (sps->frame_cropping_flag) - { - crop_left = SubWidthC [sps->chroma_format_idc] * sps->frame_cropping_rect_left_offset; - crop_right = SubWidthC [sps->chroma_format_idc] * sps->frame_cropping_rect_right_offset; - crop_top = SubHeightC[sps->chroma_format_idc] * ( 2 - sps->frame_mbs_only_flag ) * sps->frame_cropping_rect_top_offset; - crop_bottom = SubHeightC[sps->chroma_format_idc] * ( 2 - sps->frame_mbs_only_flag ) * sps->frame_cropping_rect_bottom_offset; - } - else - { + if (sps->frame_cropping_flag) { + crop_left = SubWidthC[sps->chroma_format_idc] * + sps->frame_cropping_rect_left_offset; + crop_right = SubWidthC[sps->chroma_format_idc] * + sps->frame_cropping_rect_right_offset; + crop_top = SubHeightC[sps->chroma_format_idc] * + (2 - sps->frame_mbs_only_flag) * + sps->frame_cropping_rect_top_offset; + crop_bottom = SubHeightC[sps->chroma_format_idc] * + (2 - sps->frame_mbs_only_flag) * + sps->frame_cropping_rect_bottom_offset; + } else { crop_left = crop_right = crop_top = crop_bottom = 0; } @@ -721,36 +730,32 @@ void reset_format_info(seq_parameter_set_rbsp_t *sps, VideoParameters *p_Vid, Fr source->height[0] = p_Vid->height - crop_top - crop_bottom; // cropping for chroma - if (sps->frame_cropping_flag) - { - crop_left = sps->frame_cropping_rect_left_offset; - crop_right = sps->frame_cropping_rect_right_offset; - crop_top = ( 2 - sps->frame_mbs_only_flag ) * sps->frame_cropping_rect_top_offset; - crop_bottom = ( 2 - sps->frame_mbs_only_flag ) * sps->frame_cropping_rect_bottom_offset; - } - else - { + if (sps->frame_cropping_flag) { + crop_left = sps->frame_cropping_rect_left_offset; + crop_right = sps->frame_cropping_rect_right_offset; + crop_top = + (2 - sps->frame_mbs_only_flag) * sps->frame_cropping_rect_top_offset; + crop_bottom = + (2 - sps->frame_mbs_only_flag) * sps->frame_cropping_rect_bottom_offset; + } else { crop_left = crop_right = crop_top = crop_bottom = 0; } - if ((sps->chroma_format_idc==YUV400) && p_Inp->write_uv) - { - source->width[1] = (source->width[0] >> 1); - source->width[2] = source->width[1]; + if ((sps->chroma_format_idc == YUV400) && p_Inp->write_uv) { + source->width[1] = (source->width[0] >> 1); + source->width[2] = source->width[1]; source->height[1] = (source->height[0] >> 1); source->height[2] = source->height[1]; - } - else - { - source->width[1] = p_Vid->width_cr - crop_left - crop_right; - source->width[2] = source->width[1]; + } else { + source->width[1] = p_Vid->width_cr - crop_left - crop_right; + source->width[2] = source->width[1]; source->height[1] = p_Vid->height_cr - crop_top - crop_bottom; source->height[2] = source->height[1]; } - output->width[0] = p_Vid->width; - source->width[1] = p_Vid->width_cr; - source->width[2] = p_Vid->width_cr; + output->width[0] = p_Vid->width; + source->width[1] = p_Vid->width_cr; + source->width[2] = p_Vid->width_cr; output->height[0] = p_Vid->height; output->height[1] = p_Vid->height_cr; output->height[2] = p_Vid->height_cr; @@ -758,38 +763,42 @@ void reset_format_info(seq_parameter_set_rbsp_t *sps, VideoParameters *p_Vid, Fr source->size_cmp[0] = source->width[0] * source->height[0]; source->size_cmp[1] = source->width[1] * source->height[1]; source->size_cmp[2] = source->size_cmp[1]; - source->size = source->size_cmp[0] + source->size_cmp[1] + source->size_cmp[2]; - source->mb_width = source->width[0] / MB_BLOCK_SIZE; - source->mb_height = source->height[0] / MB_BLOCK_SIZE; + source->size = + source->size_cmp[0] + source->size_cmp[1] + source->size_cmp[2]; + source->mb_width = source->width[0] / MB_BLOCK_SIZE; + source->mb_height = source->height[0] / MB_BLOCK_SIZE; // output size (excluding padding) output->size_cmp[0] = output->width[0] * output->height[0]; output->size_cmp[1] = output->width[1] * output->height[1]; output->size_cmp[2] = output->size_cmp[1]; - output->size = output->size_cmp[0] + output->size_cmp[1] + output->size_cmp[2]; - output->mb_width = output->width[0] / MB_BLOCK_SIZE; - output->mb_height = output->height[0] / MB_BLOCK_SIZE; - + output->size = + output->size_cmp[0] + output->size_cmp[1] + output->size_cmp[2]; + output->mb_width = output->width[0] / MB_BLOCK_SIZE; + output->mb_height = output->height[0] / MB_BLOCK_SIZE; output->bit_depth[0] = source->bit_depth[0] = p_Vid->bitdepth_luma; output->bit_depth[1] = source->bit_depth[1] = p_Vid->bitdepth_chroma; - output->bit_depth[2] = source->bit_depth[2] = p_Vid->bitdepth_chroma; - output->pic_unit_size_on_disk = (imax(output->bit_depth[0], output->bit_depth[1]) > 8) ? 16 : 8; + output->bit_depth[2] = source->bit_depth[2] = p_Vid->bitdepth_chroma; + output->pic_unit_size_on_disk = + (imax(output->bit_depth[0], output->bit_depth[1]) > 8) ? 16 : 8; output->pic_unit_size_shift3 = output->pic_unit_size_on_disk >> 3; - output->frame_rate = source->frame_rate; + output->frame_rate = source->frame_rate; output->color_model = source->color_model; - output->yuv_format = source->yuv_format = (ColorFormat) sps->chroma_format_idc; + output->yuv_format = source->yuv_format = (ColorFormat)sps->chroma_format_idc; - output->auto_crop_bottom = crop_bottom; - output->auto_crop_right = crop_right; - output->auto_crop_bottom_cr = (crop_bottom * p_Vid->mb_cr_size_y) / MB_BLOCK_SIZE; - output->auto_crop_right_cr = (crop_right * p_Vid->mb_cr_size_x) / MB_BLOCK_SIZE; + output->auto_crop_bottom = crop_bottom; + output->auto_crop_right = crop_right; + output->auto_crop_bottom_cr = + (crop_bottom * p_Vid->mb_cr_size_y) / MB_BLOCK_SIZE; + output->auto_crop_right_cr = + (crop_right * p_Vid->mb_cr_size_x) / MB_BLOCK_SIZE; - source->auto_crop_bottom = output->auto_crop_bottom; - source->auto_crop_right = output->auto_crop_right; + source->auto_crop_bottom = output->auto_crop_bottom; + source->auto_crop_right = output->auto_crop_right; source->auto_crop_bottom_cr = output->auto_crop_bottom_cr; - source->auto_crop_right_cr = output->auto_crop_right_cr; + source->auto_crop_right_cr = output->auto_crop_right_cr; updateMaxValue(source); updateMaxValue(output); @@ -802,75 +811,60 @@ void reset_format_info(seq_parameter_set_rbsp_t *sps, VideoParameters *p_Vid, Fr * ************************************************************************ */ -void activate_sps (VideoParameters *p_Vid, seq_parameter_set_rbsp_t *sps) -{ - InputParameters *p_Inp = p_Vid->p_Inp; +void activate_sps(VideoParameters *p_Vid, seq_parameter_set_rbsp_t *sps) { + InputParameters *p_Inp = p_Vid->p_Inp; - if (p_Vid->active_sps != sps) - { - if (p_Vid->dec_picture) - { + if (p_Vid->active_sps != sps) { + if (p_Vid->dec_picture) { // this may only happen on slice loss exit_picture(p_Vid, &p_Vid->dec_picture); } p_Vid->active_sps = sps; p_Vid->bitdepth_chroma = 0; - p_Vid->width_cr = 0; - p_Vid->height_cr = 0; + p_Vid->width_cr = 0; + p_Vid->height_cr = 0; // maximum vertical motion vector range in luma quarter pixel units - if (p_Vid->active_sps->level_idc <= 10) - { + if (p_Vid->active_sps->level_idc <= 10) { p_Vid->max_vmv_r = 64 * 4; - } - else if (p_Vid->active_sps->level_idc <= 20) - { + } else if (p_Vid->active_sps->level_idc <= 20) { p_Vid->max_vmv_r = 128 * 4; - } - else if (p_Vid->active_sps->level_idc <= 30) - { + } else if (p_Vid->active_sps->level_idc <= 30) { p_Vid->max_vmv_r = 256 * 4; - } - else - { + } else { p_Vid->max_vmv_r = 512 * 4; // 512 pixels in quarter pixels } // Fidelity Range Extensions stuff (part 1) - p_Vid->bitdepth_luma = (short) (sps->bit_depth_luma_minus8 + 8); - p_Vid->bitdepth_scale[0] = 1 << sps->bit_depth_luma_minus8; - if (sps->chroma_format_idc != YUV400) - { - p_Vid->bitdepth_chroma = (short) (sps->bit_depth_chroma_minus8 + 8); + p_Vid->bitdepth_luma = (short)(sps->bit_depth_luma_minus8 + 8); + p_Vid->bitdepth_scale[0] = 1 << sps->bit_depth_luma_minus8; + if (sps->chroma_format_idc != YUV400) { + p_Vid->bitdepth_chroma = (short)(sps->bit_depth_chroma_minus8 + 8); p_Vid->bitdepth_scale[1] = 1 << sps->bit_depth_chroma_minus8; } - p_Vid->MaxFrameNum = 1<<(sps->log2_max_frame_num_minus4+4); - p_Vid->PicWidthInMbs = (sps->pic_width_in_mbs_minus1 +1); - p_Vid->PicHeightInMapUnits = (sps->pic_height_in_map_units_minus1 +1); - p_Vid->FrameHeightInMbs = ( 2 - sps->frame_mbs_only_flag ) * p_Vid->PicHeightInMapUnits; + p_Vid->MaxFrameNum = 1 << (sps->log2_max_frame_num_minus4 + 4); + p_Vid->PicWidthInMbs = (sps->pic_width_in_mbs_minus1 + 1); + p_Vid->PicHeightInMapUnits = (sps->pic_height_in_map_units_minus1 + 1); + p_Vid->FrameHeightInMbs = + (2 - sps->frame_mbs_only_flag) * p_Vid->PicHeightInMapUnits; p_Vid->FrameSizeInMbs = p_Vid->PicWidthInMbs * p_Vid->FrameHeightInMbs; - p_Vid->yuv_format=sps->chroma_format_idc; + p_Vid->yuv_format = sps->chroma_format_idc; p_Vid->width = p_Vid->PicWidthInMbs * MB_BLOCK_SIZE; p_Vid->height = p_Vid->FrameHeightInMbs * MB_BLOCK_SIZE; - - if (sps->chroma_format_idc == YUV420) - { - p_Vid->width_cr = (p_Vid->width >> 1); + + if (sps->chroma_format_idc == YUV420) { + p_Vid->width_cr = (p_Vid->width >> 1); p_Vid->height_cr = (p_Vid->height >> 1); - } - else if (sps->chroma_format_idc == YUV422) - { - p_Vid->width_cr = (p_Vid->width >> 1); + } else if (sps->chroma_format_idc == YUV422) { + p_Vid->width_cr = (p_Vid->width >> 1); p_Vid->height_cr = p_Vid->height; - p_Vid->iChromaPadY = MCBUF_CHROMA_PAD_Y*2; - } - else if (sps->chroma_format_idc == YUV444) - { - //YUV444 + p_Vid->iChromaPadY = MCBUF_CHROMA_PAD_Y * 2; + } else if (sps->chroma_format_idc == YUV444) { + // YUV444 p_Vid->width_cr = p_Vid->width; p_Vid->height_cr = p_Vid->height; p_Vid->iChromaPadX = p_Vid->iLumaPadX; @@ -878,64 +872,61 @@ void activate_sps (VideoParameters *p_Vid, seq_parameter_set_rbsp_t *sps) } #if (MVC_EXTENSION_ENABLE) - if (p_Vid->last_pic_width_in_mbs_minus1 != (int) p_Vid->active_sps->pic_width_in_mbs_minus1 - || p_Vid->last_pic_height_in_map_units_minus1 != (int) p_Vid->active_sps->pic_height_in_map_units_minus1 - || p_Vid->last_max_dec_frame_buffering != GetMaxDecFrameBuffering(p_Vid) - || (p_Vid->last_profile_idc != (int) p_Vid->active_sps->profile_idc - && p_Vid->active_sps->profile_idc < MVC_HIGH - && p_Vid->last_profile_idc< MVC_HIGH)) - { - init_frext(p_Vid); - init_global_buffers(p_Vid); + if (p_Vid->last_pic_width_in_mbs_minus1 != + (int)p_Vid->active_sps->pic_width_in_mbs_minus1 || + p_Vid->last_pic_height_in_map_units_minus1 != + (int)p_Vid->active_sps->pic_height_in_map_units_minus1 || + p_Vid->last_max_dec_frame_buffering != GetMaxDecFrameBuffering(p_Vid) || + (p_Vid->last_profile_idc != (int)p_Vid->active_sps->profile_idc && + p_Vid->active_sps->profile_idc < MVC_HIGH && + p_Vid->last_profile_idc < MVC_HIGH)) { + init_frext(p_Vid); + init_global_buffers(p_Vid); + + if (!p_Vid->no_output_of_prior_pics_flag) { + flush_dpb(p_Vid->p_Dpb, -1); + } - if (!p_Vid->no_output_of_prior_pics_flag) - { - flush_dpb(p_Vid->p_Dpb, -1); - } - init_dpb(p_Vid, p_Vid->p_Dpb); - p_Vid->last_pic_width_in_mbs_minus1 = p_Vid->active_sps->pic_width_in_mbs_minus1; - p_Vid->last_pic_height_in_map_units_minus1 = p_Vid->active_sps->pic_height_in_map_units_minus1; - p_Vid->last_max_dec_frame_buffering = GetMaxDecFrameBuffering(p_Vid); + p_Vid->last_pic_width_in_mbs_minus1 = + p_Vid->active_sps->pic_width_in_mbs_minus1; + p_Vid->last_pic_height_in_map_units_minus1 = + p_Vid->active_sps->pic_height_in_map_units_minus1; + p_Vid->last_max_dec_frame_buffering = GetMaxDecFrameBuffering(p_Vid); p_Vid->last_profile_idc = p_Vid->active_sps->profile_idc; - } - else if(p_Vid->last_profile_idc != (int) p_Vid->active_sps->profile_idc - && (p_Vid->last_profile_idc>=MVC_HIGH || p_Vid->active_sps->profile_idc >= MVC_HIGH) - && p_Vid->p_Dpb->init_done /*&& !(p_Vid->init_bl_done)*/) - { + } else if (p_Vid->last_profile_idc != (int)p_Vid->active_sps->profile_idc && + (p_Vid->last_profile_idc >= MVC_HIGH || + p_Vid->active_sps->profile_idc >= MVC_HIGH) && + p_Vid->p_Dpb->init_done /*&& !(p_Vid->init_bl_done)*/) { re_init_dpb(p_Vid, p_Vid->p_Dpb); p_Vid->last_profile_idc = p_Vid->active_sps->profile_idc; } - p_Vid->p_Dpb->num_ref_frames = p_Vid->active_sps->num_ref_frames; + p_Vid->p_Dpb->num_ref_frames = p_Vid->active_sps->num_ref_frames; #else init_frext(p_Vid); init_global_buffers(p_Vid); - if (!p_Vid->no_output_of_prior_pics_flag) - { + if (!p_Vid->no_output_of_prior_pics_flag) { flush_dpb(p_Vid->p_Dpb); } init_dpb(p_Vid, p_Vid->p_Dpb); #endif ercInit(p_Vid, p_Vid->width, p_Vid->height, 1); - if(p_Vid->dec_picture) - { - ercReset(p_Vid->erc_errorVar, p_Vid->PicSizeInMbs, p_Vid->PicSizeInMbs, p_Vid->dec_picture->size_x); + if (p_Vid->dec_picture) { + ercReset(p_Vid->erc_errorVar, p_Vid->PicSizeInMbs, p_Vid->PicSizeInMbs, + p_Vid->dec_picture->size_x); p_Vid->erc_mvperMB = 0; } } - - reset_format_info(sps, p_Vid, &p_Inp->source, &p_Inp->output); + reset_format_info(sps, p_Vid, &p_Inp->source, &p_Inp->output); } -void activate_pps(VideoParameters *p_Vid, pic_parameter_set_rbsp_t *pps) -{ - if (p_Vid->active_pps != pps) - { +void activate_pps(VideoParameters *p_Vid, pic_parameter_set_rbsp_t *pps) { + if (p_Vid->active_pps != pps) { if (p_Vid->dec_picture) // && p_Vid->num_dec_mb == p_Vid->pi) { // this may only happen on slice loss @@ -946,36 +937,38 @@ void activate_pps(VideoParameters *p_Vid, pic_parameter_set_rbsp_t *pps) } } -void UseParameterSet (Slice *currSlice) -{ +void UseParameterSet(Slice *currSlice) { VideoParameters *p_Vid = currSlice->p_Vid; - int PicParsetId = currSlice->pic_parameter_set_id; + int PicParsetId = currSlice->pic_parameter_set_id; pic_parameter_set_rbsp_t *pps = &p_Vid->PicParSet[PicParsetId]; seq_parameter_set_rbsp_t *sps = &p_Vid->SeqParSet[pps->seq_parameter_set_id]; int i; if (pps->Valid != TRUE) - printf ("Trying to use an invalid (uninitialized) Picture Parameter Set with ID %d, expect the unexpected...\n", PicParsetId); + printf("Trying to use an invalid (uninitialized) Picture Parameter Set " + "with ID %d, expect the unexpected...\n", + PicParsetId); #if (MVC_EXTENSION_ENABLE) - if((currSlice->svc_extension_flag == -1)) - { + if ((currSlice->svc_extension_flag == -1)) { if (sps->Valid != TRUE) - printf ("PicParset %d references an invalid (uninitialized) Sequence Parameter Set with ID %d, expect the unexpected...\n", - PicParsetId, (int) pps->seq_parameter_set_id); - } - else - { + printf("PicParset %d references an invalid (uninitialized) Sequence " + "Parameter Set with ID %d, expect the unexpected...\n", + PicParsetId, (int)pps->seq_parameter_set_id); + } else { // Set SPS to the subset SPS parameters - p_Vid->active_subset_sps = p_Vid->SubsetSeqParSet + pps->seq_parameter_set_id; + p_Vid->active_subset_sps = + p_Vid->SubsetSeqParSet + pps->seq_parameter_set_id; sps = &(p_Vid->active_subset_sps->sps); if (p_Vid->SubsetSeqParSet[pps->seq_parameter_set_id].Valid != TRUE) - printf ("PicParset %d references an invalid (uninitialized) Subset Sequence Parameter Set with ID %d, expect the unexpected...\n", - PicParsetId, (int) pps->seq_parameter_set_id); + printf("PicParset %d references an invalid (uninitialized) Subset " + "Sequence Parameter Set with ID %d, expect the unexpected...\n", + PicParsetId, (int)pps->seq_parameter_set_id); } #else if (sps->Valid != TRUE) - printf ("PicParset %d references an invalid (uninitialized) Sequence Parameter Set with ID %d, expect the unexpected...\n", - PicParsetId, (int) pps->seq_parameter_set_id); + printf("PicParset %d references an invalid (uninitialized) Sequence " + "Parameter Set with ID %d, expect the unexpected...\n", + PicParsetId, (int)pps->seq_parameter_set_id); #endif // In theory, and with a well-designed software, the lines above @@ -983,267 +976,317 @@ void UseParameterSet (Slice *currSlice) // in p_Vid-> (but no more in p_Inp-> -- these have been taken care of) // Set Sequence Parameter Stuff first - // printf ("Using Picture Parameter set %d and associated Sequence Parameter Set %d\n", PicParsetId, pps->seq_parameter_set_id); - if ((int) sps->pic_order_cnt_type < 0 || sps->pic_order_cnt_type > 2) // != 1 + // printf ("Using Picture Parameter set %d and associated Sequence Parameter + // Set %d\n", PicParsetId, pps->seq_parameter_set_id); + if ((int)sps->pic_order_cnt_type < 0 || sps->pic_order_cnt_type > 2) // != 1 { - printf ("invalid sps->pic_order_cnt_type = %d\n", (int) sps->pic_order_cnt_type); - error ("pic_order_cnt_type != 1", -1000); + printf("invalid sps->pic_order_cnt_type = %d\n", + (int)sps->pic_order_cnt_type); + error("pic_order_cnt_type != 1", -1000); } - if (sps->pic_order_cnt_type == 1) - { - if(sps->num_ref_frames_in_pic_order_cnt_cycle >= MAXnum_ref_frames_in_pic_order_cnt_cycle) - { - error("num_ref_frames_in_pic_order_cnt_cycle too large",-1011); + if (sps->pic_order_cnt_type == 1) { + if (sps->num_ref_frames_in_pic_order_cnt_cycle >= + MAXnum_ref_frames_in_pic_order_cnt_cycle) { + error("num_ref_frames_in_pic_order_cnt_cycle too large", -1011); } } activate_sps(p_Vid, sps); activate_pps(p_Vid, pps); - // currSlice->dp_mode is set by read_new_slice (NALU first byte available there) - if (pps->entropy_coding_mode_flag == CAVLC) - { + // currSlice->dp_mode is set by read_new_slice (NALU first byte available + // there) + if (pps->entropy_coding_mode_flag == CAVLC) { currSlice->nal_startcode_follows = uvlc_startcode_follows; - for (i=0; i<3; i++) - { - currSlice->partArr[i].readSyntaxElement = readSyntaxElement_UVLC; + for (i = 0; i < 3; i++) { + currSlice->partArr[i].readSyntaxElement = readSyntaxElement_UVLC; } - } - else - { + } else { currSlice->nal_startcode_follows = cabac_startcode_follows; - for (i=0; i<3; i++) - { + for (i = 0; i < 3; i++) { currSlice->partArr[i].readSyntaxElement = readSyntaxElement_CABAC; } } } #if (MVC_EXTENSION_ENABLE) -void seq_parameter_set_mvc_extension(subset_seq_parameter_set_rbsp_t *subset_sps, Bitstream *s) -{ +void seq_parameter_set_mvc_extension( + subset_seq_parameter_set_rbsp_t *subset_sps, Bitstream *s) { int i, j, num_views; - subset_sps->num_views_minus1 = ue_v("num_views_minus1" , s); - num_views = 1+subset_sps->num_views_minus1; - if( num_views >0) - { - if ((subset_sps->view_id = (int*) calloc(num_views, sizeof(int))) == NULL) + subset_sps->num_views_minus1 = ue_v("num_views_minus1", s); + num_views = 1 + subset_sps->num_views_minus1; + if (num_views > 0) { + if ((subset_sps->view_id = (int *)calloc(num_views, sizeof(int))) == NULL) no_mem_exit("init_subset_seq_parameter_set: subset_sps->view_id"); - if ((subset_sps->num_anchor_refs_l0 = (int*) calloc(num_views, sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->num_anchor_refs_l0"); - if ((subset_sps->num_anchor_refs_l1 = (int*) calloc(num_views, sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->num_anchor_refs_l1"); - if ((subset_sps->anchor_ref_l0 = (int**) calloc(num_views, sizeof(int*))) == NULL) + if ((subset_sps->num_anchor_refs_l0 = + (int *)calloc(num_views, sizeof(int))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->num_anchor_refs_l0"); + if ((subset_sps->num_anchor_refs_l1 = + (int *)calloc(num_views, sizeof(int))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->num_anchor_refs_l1"); + if ((subset_sps->anchor_ref_l0 = + (int **)calloc(num_views, sizeof(int *))) == NULL) no_mem_exit("init_subset_seq_parameter_set: subset_sps->anchor_ref_l0"); - if ((subset_sps->anchor_ref_l1 = (int**) calloc(num_views, sizeof(int*))) == NULL) + if ((subset_sps->anchor_ref_l1 = + (int **)calloc(num_views, sizeof(int *))) == NULL) no_mem_exit("init_subset_seq_parameter_set: subset_sps->anchor_ref_l1"); - if ((subset_sps->num_non_anchor_refs_l0 = (int*) calloc(num_views, sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->num_non_anchor_refs_l0"); - if ((subset_sps->num_non_anchor_refs_l1 = (int*) calloc(num_views, sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->num_non_anchor_refs_l1"); - if ((subset_sps->non_anchor_ref_l0 = (int**) calloc(num_views, sizeof(int*))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->non_anchor_ref_l0"); - if ((subset_sps->non_anchor_ref_l1 = (int**) calloc(num_views, sizeof(int*))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->non_anchor_ref_l1"); + if ((subset_sps->num_non_anchor_refs_l0 = + (int *)calloc(num_views, sizeof(int))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->num_non_anchor_refs_l0"); + if ((subset_sps->num_non_anchor_refs_l1 = + (int *)calloc(num_views, sizeof(int))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->num_non_anchor_refs_l1"); + if ((subset_sps->non_anchor_ref_l0 = + (int **)calloc(num_views, sizeof(int *))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->non_anchor_ref_l0"); + if ((subset_sps->non_anchor_ref_l1 = + (int **)calloc(num_views, sizeof(int *))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->non_anchor_ref_l1"); } - for(i=0; iview_id[i] = ue_v("view_id" , s); + for (i = 0; i < num_views; i++) { + subset_sps->view_id[i] = ue_v("view_id", s); } - for(i=1; inum_anchor_refs_l0[i] = ue_v("num_anchor_refs_l0" , s); - if(subset_sps->num_anchor_refs_l0[i]>0) - { - if ((subset_sps->anchor_ref_l0[i] = (int*) calloc(subset_sps->num_anchor_refs_l0[i], sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->anchor_ref_l0[i]"); - for(j=0; jnum_anchor_refs_l0[i]; j++) - subset_sps->anchor_ref_l0[i][j] = ue_v("anchor_ref_l0" , s); + for (i = 1; i < num_views; i++) { + subset_sps->num_anchor_refs_l0[i] = ue_v("num_anchor_refs_l0", s); + if (subset_sps->num_anchor_refs_l0[i] > 0) { + if ((subset_sps->anchor_ref_l0[i] = (int *)calloc( + subset_sps->num_anchor_refs_l0[i], sizeof(int))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->anchor_ref_l0[i]"); + for (j = 0; j < subset_sps->num_anchor_refs_l0[i]; j++) + subset_sps->anchor_ref_l0[i][j] = ue_v("anchor_ref_l0", s); } - subset_sps->num_anchor_refs_l1[i] = ue_v("num_anchor_refs_l1" , s); - if(subset_sps->num_anchor_refs_l1[i]>0) - { - if ((subset_sps->anchor_ref_l1[i] = (int*) calloc(subset_sps->num_anchor_refs_l1[i], sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->anchor_ref_l1[i]"); - for(j=0; jnum_anchor_refs_l1[i]; j++) - subset_sps->anchor_ref_l1[i][j] = ue_v("anchor_ref_l1" , s); + subset_sps->num_anchor_refs_l1[i] = ue_v("num_anchor_refs_l1", s); + if (subset_sps->num_anchor_refs_l1[i] > 0) { + if ((subset_sps->anchor_ref_l1[i] = (int *)calloc( + subset_sps->num_anchor_refs_l1[i], sizeof(int))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->anchor_ref_l1[i]"); + for (j = 0; j < subset_sps->num_anchor_refs_l1[i]; j++) + subset_sps->anchor_ref_l1[i][j] = ue_v("anchor_ref_l1", s); } } - for(i=1; inum_non_anchor_refs_l0[i] = ue_v("num_non_anchor_refs_l0" , s); - if(subset_sps->num_non_anchor_refs_l0[i]>0) - { - if ((subset_sps->non_anchor_ref_l0[i] = (int*) calloc(subset_sps->num_non_anchor_refs_l0[i], sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->non_anchor_ref_l0[i]"); - for(j=0; jnum_non_anchor_refs_l0[i]; j++) - subset_sps->non_anchor_ref_l0[i][j] = ue_v("non_anchor_ref_l0" , s); + for (i = 1; i < num_views; i++) { + subset_sps->num_non_anchor_refs_l0[i] = ue_v("num_non_anchor_refs_l0", s); + if (subset_sps->num_non_anchor_refs_l0[i] > 0) { + if ((subset_sps->non_anchor_ref_l0[i] = (int *)calloc( + subset_sps->num_non_anchor_refs_l0[i], sizeof(int))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->non_anchor_ref_l0[i]"); + for (j = 0; j < subset_sps->num_non_anchor_refs_l0[i]; j++) + subset_sps->non_anchor_ref_l0[i][j] = ue_v("non_anchor_ref_l0", s); } - subset_sps->num_non_anchor_refs_l1[i] = ue_v("num_non_anchor_refs_l1" , s); - if(subset_sps->num_non_anchor_refs_l1[i]>0) - { - if ((subset_sps->non_anchor_ref_l1[i] = (int*) calloc(subset_sps->num_non_anchor_refs_l1[i], sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->non_anchor_ref_l1[i]"); - for(j=0; jnum_non_anchor_refs_l1[i]; j++) - subset_sps->non_anchor_ref_l1[i][j] = ue_v("non_anchor_ref_l1" , s); + subset_sps->num_non_anchor_refs_l1[i] = ue_v("num_non_anchor_refs_l1", s); + if (subset_sps->num_non_anchor_refs_l1[i] > 0) { + if ((subset_sps->non_anchor_ref_l1[i] = (int *)calloc( + subset_sps->num_non_anchor_refs_l1[i], sizeof(int))) == NULL) + no_mem_exit( + "init_subset_seq_parameter_set: subset_sps->non_anchor_ref_l1[i]"); + for (j = 0; j < subset_sps->num_non_anchor_refs_l1[i]; j++) + subset_sps->non_anchor_ref_l1[i][j] = ue_v("non_anchor_ref_l1", s); } } - subset_sps->num_level_values_signalled_minus1 = ue_v("num_level_values_signalled_minus1" , s); - if(subset_sps->num_level_values_signalled_minus1 >=0) - { - i = 1+ subset_sps->num_level_values_signalled_minus1; - if ((subset_sps->level_idc = (int*) calloc(i, sizeof(int))) == NULL) + subset_sps->num_level_values_signalled_minus1 = + ue_v("num_level_values_signalled_minus1", s); + if (subset_sps->num_level_values_signalled_minus1 >= 0) { + i = 1 + subset_sps->num_level_values_signalled_minus1; + if ((subset_sps->level_idc = (int *)calloc(i, sizeof(int))) == NULL) no_mem_exit("init_subset_seq_parameter_set: subset_sps->level_idc"); - if ((subset_sps->num_applicable_ops_minus1 = (int*) calloc(i, sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->num_applicable_ops_minus1"); - if ((subset_sps->applicable_op_temporal_id = (int**) calloc(i, sizeof(int*))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->applicable_op_temporal_id"); - if ((subset_sps->applicable_op_num_target_views_minus1 = (int**) calloc(i, sizeof(int*))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->applicable_op_num_target_views_minus1"); - if ((subset_sps->applicable_op_target_view_id = (int***) calloc(i, sizeof(int**))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->applicable_op_target_view_id"); - if ((subset_sps->applicable_op_num_views_minus1 = (int**) calloc(i, sizeof(int*))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->applicable_op_num_views_minus1"); + if ((subset_sps->num_applicable_ops_minus1 = + (int *)calloc(i, sizeof(int))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->num_applicable_ops_minus1"); + if ((subset_sps->applicable_op_temporal_id = + (int **)calloc(i, sizeof(int *))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->applicable_op_temporal_id"); + if ((subset_sps->applicable_op_num_target_views_minus1 = + (int **)calloc(i, sizeof(int *))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->applicable_op_num_target_views_minus1"); + if ((subset_sps->applicable_op_target_view_id = + (int ***)calloc(i, sizeof(int **))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->applicable_op_target_view_id"); + if ((subset_sps->applicable_op_num_views_minus1 = + (int **)calloc(i, sizeof(int *))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->applicable_op_num_views_minus1"); } - for(i=0; i<=subset_sps->num_level_values_signalled_minus1; i++) - { - subset_sps->level_idc[i] = u_v(8, "level_idc" , s); - subset_sps->num_applicable_ops_minus1[i] = ue_v("num_applicable_ops_minus1" , s); - if(subset_sps->num_applicable_ops_minus1[i]>=0) - { - if ((subset_sps->applicable_op_temporal_id[i] = (int*) calloc(1+subset_sps->num_applicable_ops_minus1[i], sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->applicable_op_temporal_id[i]"); - if ((subset_sps->applicable_op_num_target_views_minus1[i] = (int*) calloc(1+subset_sps->num_applicable_ops_minus1[i], sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->applicable_op_num_target_views_minus1[i]"); - if ((subset_sps->applicable_op_target_view_id[i] = (int**) calloc(1+subset_sps->num_applicable_ops_minus1[i], sizeof(int *))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->applicable_op_target_view_id[i]"); - if ((subset_sps->applicable_op_num_views_minus1[i] = (int*) calloc(1+subset_sps->num_applicable_ops_minus1[i], sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->applicable_op_num_views_minus1[i]"); + for (i = 0; i <= subset_sps->num_level_values_signalled_minus1; i++) { + subset_sps->level_idc[i] = u_v(8, "level_idc", s); + subset_sps->num_applicable_ops_minus1[i] = + ue_v("num_applicable_ops_minus1", s); + if (subset_sps->num_applicable_ops_minus1[i] >= 0) { + if ((subset_sps->applicable_op_temporal_id[i] = + (int *)calloc(1 + subset_sps->num_applicable_ops_minus1[i], + sizeof(int))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->applicable_op_temporal_id[i]"); + if ((subset_sps->applicable_op_num_target_views_minus1[i] = + (int *)calloc(1 + subset_sps->num_applicable_ops_minus1[i], + sizeof(int))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->applicable_op_num_target_views_minus1[i]"); + if ((subset_sps->applicable_op_target_view_id[i] = + (int **)calloc(1 + subset_sps->num_applicable_ops_minus1[i], + sizeof(int *))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->applicable_op_target_view_id[i]"); + if ((subset_sps->applicable_op_num_views_minus1[i] = + (int *)calloc(1 + subset_sps->num_applicable_ops_minus1[i], + sizeof(int))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->applicable_op_num_views_minus1[i]"); - for(j=0; j<=subset_sps->num_applicable_ops_minus1[i]; j++) - { + for (j = 0; j <= subset_sps->num_applicable_ops_minus1[i]; j++) { int k; - subset_sps->applicable_op_temporal_id[i][j] = u_v(3, "applicable_op_temporal_id" , s); - subset_sps->applicable_op_num_target_views_minus1[i][j] = ue_v("applicable_op_num_target_views_minus1" , s); - if(subset_sps->applicable_op_num_target_views_minus1[i][j]>=0) - { - if ((subset_sps->applicable_op_target_view_id[i][j] = (int*) calloc(1+subset_sps->applicable_op_num_target_views_minus1[i][j], sizeof(int))) == NULL) - no_mem_exit("init_subset_seq_parameter_set: subset_sps->applicable_op_target_view_id[i][j]"); - for(k = 0; k <= subset_sps->applicable_op_num_target_views_minus1[i][j]; k++) - subset_sps->applicable_op_target_view_id[i][j][k] = ue_v("applicable_op_target_view_id" , s); + subset_sps->applicable_op_temporal_id[i][j] = + u_v(3, "applicable_op_temporal_id", s); + subset_sps->applicable_op_num_target_views_minus1[i][j] = + ue_v("applicable_op_num_target_views_minus1", s); + if (subset_sps->applicable_op_num_target_views_minus1[i][j] >= 0) { + if ((subset_sps->applicable_op_target_view_id[i][j] = (int *)calloc( + 1 + subset_sps->applicable_op_num_target_views_minus1[i][j], + sizeof(int))) == NULL) + no_mem_exit("init_subset_seq_parameter_set: " + "subset_sps->applicable_op_target_view_id[i][j]"); + for (k = 0; + k <= subset_sps->applicable_op_num_target_views_minus1[i][j]; + k++) + subset_sps->applicable_op_target_view_id[i][j][k] = + ue_v("applicable_op_target_view_id", s); } - subset_sps->applicable_op_num_views_minus1[i][j] = ue_v("applicable_op_num_views_minus1" , s); + subset_sps->applicable_op_num_views_minus1[i][j] = + ue_v("applicable_op_num_views_minus1", s); } } } } -int MemAlloc1D(void** ppBuf, int iEleSize, int iNum) -{ - if(iEleSize*iNum <=0) +int MemAlloc1D(void **ppBuf, int iEleSize, int iNum) { + if (iEleSize * iNum <= 0) return 1; *ppBuf = calloc(iNum, iEleSize); return (*ppBuf == NULL); } -void hrd_parameters(MVCVUI_t *pMVCVUI, Bitstream *s) -{ +void hrd_parameters(MVCVUI_t *pMVCVUI, Bitstream *s) { int i; - pMVCVUI->cpb_cnt_minus1 = (signed char) ue_v("cpb_cnt_minus1" , s); - assert(pMVCVUI->cpb_cnt_minus1<=31); - pMVCVUI->bit_rate_scale = (signed char) u_v(4, "bit_rate_scale" , s); - pMVCVUI->cpb_size_scale = (signed char) u_v(4, "cpb_size_scale" , s); - for(i=0; i<=pMVCVUI->cpb_cnt_minus1; i++) - { - pMVCVUI->bit_rate_value_minus1[i] = ue_v("bit_rate_value_minus1" , s); - pMVCVUI->cpb_size_value_minus1[i] = ue_v("cpb_size_value_minus1" , s); - pMVCVUI->cbr_flag[i] = (signed char) u_1 ("cbr_flag" , s); + pMVCVUI->cpb_cnt_minus1 = (signed char)ue_v("cpb_cnt_minus1", s); + assert(pMVCVUI->cpb_cnt_minus1 <= 31); + pMVCVUI->bit_rate_scale = (signed char)u_v(4, "bit_rate_scale", s); + pMVCVUI->cpb_size_scale = (signed char)u_v(4, "cpb_size_scale", s); + for (i = 0; i <= pMVCVUI->cpb_cnt_minus1; i++) { + pMVCVUI->bit_rate_value_minus1[i] = ue_v("bit_rate_value_minus1", s); + pMVCVUI->cpb_size_value_minus1[i] = ue_v("cpb_size_value_minus1", s); + pMVCVUI->cbr_flag[i] = (signed char)u_1("cbr_flag", s); } - pMVCVUI->initial_cpb_removal_delay_length_minus1 = (signed char) u_v(5, "initial_cpb_removal_delay_length_minus1" , s); - pMVCVUI->cpb_removal_delay_length_minus1 = (signed char) u_v(5, "cpb_removal_delay_length_minus1" , s); - pMVCVUI->dpb_output_delay_length_minus1 = (signed char) u_v(5, "dpb_output_delay_length_minus1" , s); - pMVCVUI->time_offset_length = (signed char) u_v(5, "time_offset_length" , s); - + pMVCVUI->initial_cpb_removal_delay_length_minus1 = + (signed char)u_v(5, "initial_cpb_removal_delay_length_minus1", s); + pMVCVUI->cpb_removal_delay_length_minus1 = + (signed char)u_v(5, "cpb_removal_delay_length_minus1", s); + pMVCVUI->dpb_output_delay_length_minus1 = + (signed char)u_v(5, "dpb_output_delay_length_minus1", s); + pMVCVUI->time_offset_length = (signed char)u_v(5, "time_offset_length", s); } -void mvc_vui_parameters_extension(MVCVUI_t *pMVCVUI, Bitstream *s) -{ +void mvc_vui_parameters_extension(MVCVUI_t *pMVCVUI, Bitstream *s) { int i, j, iNumOps; - pMVCVUI->num_ops_minus1 = ue_v("vui_mvc_num_ops_minus1" , s); - iNumOps = 1+ pMVCVUI->num_ops_minus1; - if(iNumOps > 0) - { - MemAlloc1D((void **)&(pMVCVUI->temporal_id), sizeof(pMVCVUI->temporal_id[0]), iNumOps); - MemAlloc1D((void **)&(pMVCVUI->num_target_output_views_minus1), sizeof(pMVCVUI->num_target_output_views_minus1[0]), iNumOps); - if ((pMVCVUI->view_id = (int**) calloc(iNumOps, sizeof(int*))) == NULL) + pMVCVUI->num_ops_minus1 = ue_v("vui_mvc_num_ops_minus1", s); + iNumOps = 1 + pMVCVUI->num_ops_minus1; + if (iNumOps > 0) { + MemAlloc1D((void **)&(pMVCVUI->temporal_id), + sizeof(pMVCVUI->temporal_id[0]), iNumOps); + MemAlloc1D((void **)&(pMVCVUI->num_target_output_views_minus1), + sizeof(pMVCVUI->num_target_output_views_minus1[0]), iNumOps); + if ((pMVCVUI->view_id = (int **)calloc(iNumOps, sizeof(int *))) == NULL) no_mem_exit("mvc_vui_parameters_extension: pMVCVUI->view_id"); - MemAlloc1D((void **)&(pMVCVUI->timing_info_present_flag), sizeof(pMVCVUI->timing_info_present_flag[0]), iNumOps); - MemAlloc1D((void **)&(pMVCVUI->num_units_in_tick), sizeof(pMVCVUI->num_units_in_tick[0]), iNumOps); - MemAlloc1D((void **)&(pMVCVUI->time_scale), sizeof(pMVCVUI->time_scale[0]), iNumOps); - MemAlloc1D((void **)&(pMVCVUI->fixed_frame_rate_flag), sizeof(pMVCVUI->fixed_frame_rate_flag[0]), iNumOps); - MemAlloc1D((void **)&(pMVCVUI->nal_hrd_parameters_present_flag), sizeof(pMVCVUI->nal_hrd_parameters_present_flag[0]), iNumOps); - MemAlloc1D((void **)&(pMVCVUI->vcl_hrd_parameters_present_flag), sizeof(pMVCVUI->vcl_hrd_parameters_present_flag[0]), iNumOps); - MemAlloc1D((void **)&(pMVCVUI->low_delay_hrd_flag), sizeof(pMVCVUI->low_delay_hrd_flag[0]), iNumOps); - MemAlloc1D((void **)&(pMVCVUI->pic_struct_present_flag), sizeof(pMVCVUI->pic_struct_present_flag[0]), iNumOps); + MemAlloc1D((void **)&(pMVCVUI->timing_info_present_flag), + sizeof(pMVCVUI->timing_info_present_flag[0]), iNumOps); + MemAlloc1D((void **)&(pMVCVUI->num_units_in_tick), + sizeof(pMVCVUI->num_units_in_tick[0]), iNumOps); + MemAlloc1D((void **)&(pMVCVUI->time_scale), sizeof(pMVCVUI->time_scale[0]), + iNumOps); + MemAlloc1D((void **)&(pMVCVUI->fixed_frame_rate_flag), + sizeof(pMVCVUI->fixed_frame_rate_flag[0]), iNumOps); + MemAlloc1D((void **)&(pMVCVUI->nal_hrd_parameters_present_flag), + sizeof(pMVCVUI->nal_hrd_parameters_present_flag[0]), iNumOps); + MemAlloc1D((void **)&(pMVCVUI->vcl_hrd_parameters_present_flag), + sizeof(pMVCVUI->vcl_hrd_parameters_present_flag[0]), iNumOps); + MemAlloc1D((void **)&(pMVCVUI->low_delay_hrd_flag), + sizeof(pMVCVUI->low_delay_hrd_flag[0]), iNumOps); + MemAlloc1D((void **)&(pMVCVUI->pic_struct_present_flag), + sizeof(pMVCVUI->pic_struct_present_flag[0]), iNumOps); - for(i=0; itemporal_id[i] = (signed char) u_v(3, "vui_mvc_temporal_id" , s); - pMVCVUI->num_target_output_views_minus1[i] = ue_v("vui_mvc_num_target_output_views_minus1" , s); - if(pMVCVUI->num_target_output_views_minus1[i] >= 0) - MemAlloc1D((void **)&(pMVCVUI->view_id[i]), sizeof(pMVCVUI->view_id[0][0]), pMVCVUI->num_target_output_views_minus1[i]+1); - for(j=0; j<=pMVCVUI->num_target_output_views_minus1[i]; j++) - pMVCVUI->view_id[i][j] = ue_v("vui_mvc_view_id" , s); - pMVCVUI->timing_info_present_flag[i] = (signed char) u_1("vui_mvc_timing_info_present_flag", s); - if(pMVCVUI->timing_info_present_flag[i]) - { - pMVCVUI->num_units_in_tick[i] = u_v(32, "vui_mvc_num_units_in_tick" , s); - pMVCVUI->time_scale[i] = u_v(32, "vui_mvc_time_scale" , s); - pMVCVUI->fixed_frame_rate_flag[i] = (signed char) u_1("vui_mvc_fixed_frame_rate_flag" , s); + for (i = 0; i < iNumOps; i++) { + pMVCVUI->temporal_id[i] = (signed char)u_v(3, "vui_mvc_temporal_id", s); + pMVCVUI->num_target_output_views_minus1[i] = + ue_v("vui_mvc_num_target_output_views_minus1", s); + if (pMVCVUI->num_target_output_views_minus1[i] >= 0) + MemAlloc1D((void **)&(pMVCVUI->view_id[i]), + sizeof(pMVCVUI->view_id[0][0]), + pMVCVUI->num_target_output_views_minus1[i] + 1); + for (j = 0; j <= pMVCVUI->num_target_output_views_minus1[i]; j++) + pMVCVUI->view_id[i][j] = ue_v("vui_mvc_view_id", s); + pMVCVUI->timing_info_present_flag[i] = + (signed char)u_1("vui_mvc_timing_info_present_flag", s); + if (pMVCVUI->timing_info_present_flag[i]) { + pMVCVUI->num_units_in_tick[i] = u_v(32, "vui_mvc_num_units_in_tick", s); + pMVCVUI->time_scale[i] = u_v(32, "vui_mvc_time_scale", s); + pMVCVUI->fixed_frame_rate_flag[i] = + (signed char)u_1("vui_mvc_fixed_frame_rate_flag", s); } - pMVCVUI->nal_hrd_parameters_present_flag[i] = (signed char) u_1("vui_mvc_nal_hrd_parameters_present_flag" , s); - if(pMVCVUI->nal_hrd_parameters_present_flag[i]) + pMVCVUI->nal_hrd_parameters_present_flag[i] = + (signed char)u_1("vui_mvc_nal_hrd_parameters_present_flag", s); + if (pMVCVUI->nal_hrd_parameters_present_flag[i]) hrd_parameters(pMVCVUI, s); - pMVCVUI->vcl_hrd_parameters_present_flag[i] = (signed char) u_1("vcl_hrd_parameters_present_flag" , s); - if(pMVCVUI->vcl_hrd_parameters_present_flag[i]) + pMVCVUI->vcl_hrd_parameters_present_flag[i] = + (signed char)u_1("vcl_hrd_parameters_present_flag", s); + if (pMVCVUI->vcl_hrd_parameters_present_flag[i]) hrd_parameters(pMVCVUI, s); - if(pMVCVUI->nal_hrd_parameters_present_flag[i]||pMVCVUI->vcl_hrd_parameters_present_flag[i]) - pMVCVUI->low_delay_hrd_flag[i] = (signed char) u_1("vui_mvc_low_delay_hrd_flag" , s); - pMVCVUI->pic_struct_present_flag[i] = (signed char) u_1("vui_mvc_pic_struct_present_flag" , s); + if (pMVCVUI->nal_hrd_parameters_present_flag[i] || + pMVCVUI->vcl_hrd_parameters_present_flag[i]) + pMVCVUI->low_delay_hrd_flag[i] = + (signed char)u_1("vui_mvc_low_delay_hrd_flag", s); + pMVCVUI->pic_struct_present_flag[i] = + (signed char)u_1("vui_mvc_pic_struct_present_flag", s); } } } -void init_subset_sps_list(subset_seq_parameter_set_rbsp_t *subset_sps_list, int iSize) -{ +void init_subset_sps_list(subset_seq_parameter_set_rbsp_t *subset_sps_list, + int iSize) { int i; - memset(subset_sps_list, 0, iSize*sizeof(subset_sps_list[0])); - for(i=0; inum_views_minus1>=0) - { - subset_sps->sps.seq_parameter_set_id = (unsigned int) -1; + if (subset_sps && subset_sps->num_views_minus1 >= 0) { + subset_sps->sps.seq_parameter_set_id = (unsigned int)-1; FREEPTR(subset_sps->view_id); - for(i=0; i<=subset_sps->num_views_minus1; i++) - { + for (i = 0; i <= subset_sps->num_views_minus1; i++) { FREEPTR(subset_sps->anchor_ref_l0[i]); FREEPTR(subset_sps->anchor_ref_l1[i]); } @@ -1252,8 +1295,7 @@ void reset_subset_sps(subset_seq_parameter_set_rbsp_t *subset_sps) FREEPTR(subset_sps->num_anchor_refs_l0); FREEPTR(subset_sps->num_anchor_refs_l1); - for(i=0; i<=subset_sps->num_views_minus1; i++) - { + for (i = 0; i <= subset_sps->num_views_minus1; i++) { FREEPTR(subset_sps->non_anchor_ref_l0[i]); FREEPTR(subset_sps->non_anchor_ref_l1[i]); } @@ -1262,13 +1304,10 @@ void reset_subset_sps(subset_seq_parameter_set_rbsp_t *subset_sps) FREEPTR(subset_sps->num_non_anchor_refs_l0); FREEPTR(subset_sps->num_non_anchor_refs_l1); - if(subset_sps->num_level_values_signalled_minus1 >= 0) - { + if (subset_sps->num_level_values_signalled_minus1 >= 0) { FREEPTR(subset_sps->level_idc); - for(i=0; i<=subset_sps->num_level_values_signalled_minus1; i++) - { - for(j=0; j<=subset_sps->num_applicable_ops_minus1[i]; j++) - { + for (i = 0; i <= subset_sps->num_level_values_signalled_minus1; i++) { + for (j = 0; j <= subset_sps->num_applicable_ops_minus1[i]; j++) { FREEPTR(subset_sps->applicable_op_target_view_id[i][j]); } FREEPTR(subset_sps->applicable_op_target_view_id[i]); @@ -1279,24 +1318,22 @@ void reset_subset_sps(subset_seq_parameter_set_rbsp_t *subset_sps) FREEPTR(subset_sps->applicable_op_target_view_id); FREEPTR(subset_sps->applicable_op_temporal_id); FREEPTR(subset_sps->applicable_op_num_target_views_minus1); - FREEPTR(subset_sps->applicable_op_num_views_minus1); + FREEPTR(subset_sps->applicable_op_num_views_minus1); FREEPTR(subset_sps->num_applicable_ops_minus1); subset_sps->num_level_values_signalled_minus1 = -1; - } + } - //end; + // end; subset_sps->num_views_minus1 = -1; } - if(subset_sps && subset_sps->mvc_vui_parameters_present_flag) - { + if (subset_sps && subset_sps->mvc_vui_parameters_present_flag) { MVCVUI_t *pMVCVUI = &(subset_sps->MVCVUIParams); - if(pMVCVUI->num_ops_minus1 >=0) - { + if (pMVCVUI->num_ops_minus1 >= 0) { FREEPTR(pMVCVUI->temporal_id); FREEPTR(pMVCVUI->num_target_output_views_minus1); - for(i=0; i<=pMVCVUI->num_ops_minus1; i++) + for (i = 0; i <= pMVCVUI->num_ops_minus1; i++) FREEPTR(pMVCVUI->view_id[i]); FREEPTR(pMVCVUI->view_id); FREEPTR(pMVCVUI->timing_info_present_flag); @@ -1309,21 +1346,22 @@ void reset_subset_sps(subset_seq_parameter_set_rbsp_t *subset_sps) FREEPTR(pMVCVUI->pic_struct_present_flag); pMVCVUI->num_ops_minus1 = -1; - } + } subset_sps->mvc_vui_parameters_present_flag = 0; } } -int GetBaseViewId(VideoParameters *p_Vid, subset_seq_parameter_set_rbsp_t **subset_sps) -{ +int GetBaseViewId(VideoParameters *p_Vid, + subset_seq_parameter_set_rbsp_t **subset_sps) { subset_seq_parameter_set_rbsp_t *curr_subset_sps; - int i, iBaseViewId=0; //-1; + int i, iBaseViewId = 0; //-1; *subset_sps = NULL; curr_subset_sps = p_Vid->SubsetSeqParSet; - for(i=0; inum_views_minus1>=0 && curr_subset_sps->sps.Valid) // && curr_subset_sps->sps.seq_parameter_set_id < MAXSPS) + for (i = 0; i < MAXSPS; i++) { + if (curr_subset_sps->num_views_minus1 >= 0 && + curr_subset_sps->sps + .Valid) // && curr_subset_sps->sps.seq_parameter_set_id < MAXSPS) { iBaseViewId = curr_subset_sps->view_id[BASE_VIEW_IDX]; break; @@ -1331,19 +1369,19 @@ int GetBaseViewId(VideoParameters *p_Vid, subset_seq_parameter_set_rbsp_t **subs curr_subset_sps++; } - if(ipic_width_in_mbs_minus1 + 1) * (sps->pic_height_in_map_units_minus1 + 1) * (sps->frame_mbs_only_flag?1:2) * 384; +void get_max_dec_frame_buf_size(seq_parameter_set_rbsp_t *sps) { + int pic_size = (sps->pic_width_in_mbs_minus1 + 1) * + (sps->pic_height_in_map_units_minus1 + 1) * + (sps->frame_mbs_only_flag ? 1 : 2) * 384; int size = 0; - switch (sps->level_idc) - { + switch (sps->level_idc) { case 9: size = 152064; break; @@ -1351,7 +1389,8 @@ void get_max_dec_frame_buf_size(seq_parameter_set_rbsp_t *sps) size = 152064; break; case 11: - if (!IS_FREXT_PROFILE(sps->profile_idc) && (sps->constrained_set3_flag == 1)) + if (!IS_FREXT_PROFILE(sps->profile_idc) && + (sps->constrained_set3_flag == 1)) size = 152064; else size = 345600; @@ -1396,12 +1435,12 @@ void get_max_dec_frame_buf_size(seq_parameter_set_rbsp_t *sps) size = 70778880; break; default: - error ("undefined level", 500); + error("undefined level", 500); break; } size /= pic_size; - size = imin( size, 16); + size = imin(size, 16); sps->max_dec_frame_buffering = size; } #endif diff --git a/src/common/ldecod_src/parsetcommon.c b/src/common/ldecod_src/parsetcommon.c index 5cb92ad..e11b151 100644 --- a/src/common/ldecod_src/parsetcommon.c +++ b/src/common/ldecod_src/parsetcommon.c @@ -7,14 +7,15 @@ * Picture and Sequence Parameter set generation and handling * \date 25 November 2002 * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger * ************************************************************************************** */ -#include "global.h" #include "parsetcommon.h" +#include "global.h" #include "memalloc.h" /*! ************************************************************************************* @@ -26,16 +27,14 @@ ************************************************************************************* */ -pic_parameter_set_rbsp_t *AllocPPS () - { - pic_parameter_set_rbsp_t *p; - - if ((p=calloc (1, sizeof (pic_parameter_set_rbsp_t))) == NULL) - no_mem_exit ("AllocPPS: PPS"); - p->slice_group_id = NULL; - return p; - } +pic_parameter_set_rbsp_t *AllocPPS() { + pic_parameter_set_rbsp_t *p; + if ((p = calloc(1, sizeof(pic_parameter_set_rbsp_t))) == NULL) + no_mem_exit("AllocPPS: PPS"); + p->slice_group_id = NULL; + return p; +} /*! ************************************************************************************* @@ -47,15 +46,13 @@ pic_parameter_set_rbsp_t *AllocPPS () ************************************************************************************* */ -seq_parameter_set_rbsp_t *AllocSPS () - { - seq_parameter_set_rbsp_t *p; - - if ((p=calloc (1, sizeof (seq_parameter_set_rbsp_t))) == NULL) - no_mem_exit ("AllocSPS: SPS"); - return p; - } +seq_parameter_set_rbsp_t *AllocSPS() { + seq_parameter_set_rbsp_t *p; + if ((p = calloc(1, sizeof(seq_parameter_set_rbsp_t))) == NULL) + no_mem_exit("AllocSPS: SPS"); + return p; +} /*! ************************************************************************************* @@ -67,34 +64,30 @@ seq_parameter_set_rbsp_t *AllocSPS () ************************************************************************************* */ - void FreePPS (pic_parameter_set_rbsp_t *pps) - { - assert (pps != NULL); - if (pps->slice_group_id != NULL) - free (pps->slice_group_id); - free (pps); - } +void FreePPS(pic_parameter_set_rbsp_t *pps) { + assert(pps != NULL); + if (pps->slice_group_id != NULL) + free(pps->slice_group_id); + free(pps); +} +/*! +************************************************************************************* +* \brief +* Frees a sps +* +* \param sps +* Sequence parameter set to be freed +************************************************************************************* +*/ - /*! - ************************************************************************************* - * \brief - * Frees a sps - * - * \param sps - * Sequence parameter set to be freed - ************************************************************************************* - */ +void FreeSPS(seq_parameter_set_rbsp_t *sps) { + assert(sps != NULL); + free(sps); +} - void FreeSPS (seq_parameter_set_rbsp_t *sps) - { - assert (sps != NULL); - free (sps); - } - - -int sps_is_equal(seq_parameter_set_rbsp_t *sps1, seq_parameter_set_rbsp_t *sps2) -{ +int sps_is_equal(seq_parameter_set_rbsp_t *sps1, + seq_parameter_set_rbsp_t *sps2) { unsigned i; int equal = 1; @@ -110,52 +103,65 @@ int sps_is_equal(seq_parameter_set_rbsp_t *sps1, seq_parameter_set_rbsp_t *sps2) equal &= (sps1->log2_max_frame_num_minus4 == sps2->log2_max_frame_num_minus4); equal &= (sps1->pic_order_cnt_type == sps2->pic_order_cnt_type); - if (!equal) return equal; + if (!equal) + return equal; - if( sps1->pic_order_cnt_type == 0 ) - { - equal &= (sps1->log2_max_pic_order_cnt_lsb_minus4 == sps2->log2_max_pic_order_cnt_lsb_minus4); + if (sps1->pic_order_cnt_type == 0) { + equal &= (sps1->log2_max_pic_order_cnt_lsb_minus4 == + sps2->log2_max_pic_order_cnt_lsb_minus4); } - else if( sps1->pic_order_cnt_type == 1 ) - { - equal &= (sps1->delta_pic_order_always_zero_flag == sps2->delta_pic_order_always_zero_flag); + else if (sps1->pic_order_cnt_type == 1) { + equal &= (sps1->delta_pic_order_always_zero_flag == + sps2->delta_pic_order_always_zero_flag); equal &= (sps1->offset_for_non_ref_pic == sps2->offset_for_non_ref_pic); - equal &= (sps1->offset_for_top_to_bottom_field == sps2->offset_for_top_to_bottom_field); - equal &= (sps1->num_ref_frames_in_pic_order_cnt_cycle == sps2->num_ref_frames_in_pic_order_cnt_cycle); - if (!equal) return equal; + equal &= (sps1->offset_for_top_to_bottom_field == + sps2->offset_for_top_to_bottom_field); + equal &= (sps1->num_ref_frames_in_pic_order_cnt_cycle == + sps2->num_ref_frames_in_pic_order_cnt_cycle); + if (!equal) + return equal; - for ( i = 0 ; i< sps1->num_ref_frames_in_pic_order_cnt_cycle ;i ++) + for (i = 0; i < sps1->num_ref_frames_in_pic_order_cnt_cycle; i++) equal &= (sps1->offset_for_ref_frame[i] == sps2->offset_for_ref_frame[i]); } equal &= (sps1->num_ref_frames == sps2->num_ref_frames); - equal &= (sps1->gaps_in_frame_num_value_allowed_flag == sps2->gaps_in_frame_num_value_allowed_flag); + equal &= (sps1->gaps_in_frame_num_value_allowed_flag == + sps2->gaps_in_frame_num_value_allowed_flag); equal &= (sps1->pic_width_in_mbs_minus1 == sps2->pic_width_in_mbs_minus1); - equal &= (sps1->pic_height_in_map_units_minus1 == sps2->pic_height_in_map_units_minus1); + equal &= (sps1->pic_height_in_map_units_minus1 == + sps2->pic_height_in_map_units_minus1); equal &= (sps1->frame_mbs_only_flag == sps2->frame_mbs_only_flag); - if (!equal) return equal; - if( !sps1->frame_mbs_only_flag ) - equal &= (sps1->mb_adaptive_frame_field_flag == sps2->mb_adaptive_frame_field_flag); + if (!equal) + return equal; + if (!sps1->frame_mbs_only_flag) + equal &= (sps1->mb_adaptive_frame_field_flag == + sps2->mb_adaptive_frame_field_flag); equal &= (sps1->direct_8x8_inference_flag == sps2->direct_8x8_inference_flag); equal &= (sps1->frame_cropping_flag == sps2->frame_cropping_flag); - if (!equal) return equal; - if (sps1->frame_cropping_flag) - { - equal &= (sps1->frame_cropping_rect_left_offset == sps2->frame_cropping_rect_left_offset); - equal &= (sps1->frame_cropping_rect_right_offset == sps2->frame_cropping_rect_right_offset); - equal &= (sps1->frame_cropping_rect_top_offset == sps2->frame_cropping_rect_top_offset); - equal &= (sps1->frame_cropping_rect_bottom_offset == sps2->frame_cropping_rect_bottom_offset); + if (!equal) + return equal; + if (sps1->frame_cropping_flag) { + equal &= (sps1->frame_cropping_rect_left_offset == + sps2->frame_cropping_rect_left_offset); + equal &= (sps1->frame_cropping_rect_right_offset == + sps2->frame_cropping_rect_right_offset); + equal &= (sps1->frame_cropping_rect_top_offset == + sps2->frame_cropping_rect_top_offset); + equal &= (sps1->frame_cropping_rect_bottom_offset == + sps2->frame_cropping_rect_bottom_offset); } - equal &= (sps1->vui_parameters_present_flag == sps2->vui_parameters_present_flag); + equal &= + (sps1->vui_parameters_present_flag == sps2->vui_parameters_present_flag); return equal; } -int pps_is_equal(pic_parameter_set_rbsp_t *pps1, pic_parameter_set_rbsp_t *pps2) -{ +int pps_is_equal(pic_parameter_set_rbsp_t *pps1, + pic_parameter_set_rbsp_t *pps2) { unsigned i, j; int equal = 1; @@ -165,80 +171,84 @@ int pps_is_equal(pic_parameter_set_rbsp_t *pps1, pic_parameter_set_rbsp_t *pps2) equal &= (pps1->pic_parameter_set_id == pps2->pic_parameter_set_id); equal &= (pps1->seq_parameter_set_id == pps2->seq_parameter_set_id); equal &= (pps1->entropy_coding_mode_flag == pps2->entropy_coding_mode_flag); - equal &= (pps1->bottom_field_pic_order_in_frame_present_flag == pps2->bottom_field_pic_order_in_frame_present_flag); + equal &= (pps1->bottom_field_pic_order_in_frame_present_flag == + pps2->bottom_field_pic_order_in_frame_present_flag); equal &= (pps1->num_slice_groups_minus1 == pps2->num_slice_groups_minus1); - if (!equal) return equal; + if (!equal) + return equal; - if (pps1->num_slice_groups_minus1>0) - { - equal &= (pps1->slice_group_map_type == pps2->slice_group_map_type); - if (!equal) return equal; - if (pps1->slice_group_map_type == 0) - { - for (i=0; i<=pps1->num_slice_groups_minus1; i++) - equal &= (pps1->run_length_minus1[i] == pps2->run_length_minus1[i]); - } - else if( pps1->slice_group_map_type == 2 ) - { - for (i=0; inum_slice_groups_minus1; i++) - { - equal &= (pps1->top_left[i] == pps2->top_left[i]); - equal &= (pps1->bottom_right[i] == pps2->bottom_right[i]); - } - } - else if( pps1->slice_group_map_type == 3 || pps1->slice_group_map_type==4 || pps1->slice_group_map_type==5 ) - { - equal &= (pps1->slice_group_change_direction_flag == pps2->slice_group_change_direction_flag); - equal &= (pps1->slice_group_change_rate_minus1 == pps2->slice_group_change_rate_minus1); - } - else if( pps1->slice_group_map_type == 6 ) - { - equal &= (pps1->pic_size_in_map_units_minus1 == pps2->pic_size_in_map_units_minus1); - if (!equal) return equal; - for (i=0; i<=pps1->pic_size_in_map_units_minus1; i++) - equal &= (pps1->slice_group_id[i] == pps2->slice_group_id[i]); + if (pps1->num_slice_groups_minus1 > 0) { + equal &= (pps1->slice_group_map_type == pps2->slice_group_map_type); + if (!equal) + return equal; + if (pps1->slice_group_map_type == 0) { + for (i = 0; i <= pps1->num_slice_groups_minus1; i++) + equal &= (pps1->run_length_minus1[i] == pps2->run_length_minus1[i]); + } else if (pps1->slice_group_map_type == 2) { + for (i = 0; i < pps1->num_slice_groups_minus1; i++) { + equal &= (pps1->top_left[i] == pps2->top_left[i]); + equal &= (pps1->bottom_right[i] == pps2->bottom_right[i]); } + } else if (pps1->slice_group_map_type == 3 || + pps1->slice_group_map_type == 4 || + pps1->slice_group_map_type == 5) { + equal &= (pps1->slice_group_change_direction_flag == + pps2->slice_group_change_direction_flag); + equal &= (pps1->slice_group_change_rate_minus1 == + pps2->slice_group_change_rate_minus1); + } else if (pps1->slice_group_map_type == 6) { + equal &= (pps1->pic_size_in_map_units_minus1 == + pps2->pic_size_in_map_units_minus1); + if (!equal) + return equal; + for (i = 0; i <= pps1->pic_size_in_map_units_minus1; i++) + equal &= (pps1->slice_group_id[i] == pps2->slice_group_id[i]); + } } - equal &= (pps1->num_ref_idx_l0_active_minus1 == pps2->num_ref_idx_l0_active_minus1); - equal &= (pps1->num_ref_idx_l1_active_minus1 == pps2->num_ref_idx_l1_active_minus1); + equal &= (pps1->num_ref_idx_l0_active_minus1 == + pps2->num_ref_idx_l0_active_minus1); + equal &= (pps1->num_ref_idx_l1_active_minus1 == + pps2->num_ref_idx_l1_active_minus1); equal &= (pps1->weighted_pred_flag == pps2->weighted_pred_flag); equal &= (pps1->weighted_bipred_idc == pps2->weighted_bipred_idc); equal &= (pps1->pic_init_qp_minus26 == pps2->pic_init_qp_minus26); equal &= (pps1->pic_init_qs_minus26 == pps2->pic_init_qs_minus26); equal &= (pps1->chroma_qp_index_offset == pps2->chroma_qp_index_offset); - equal &= (pps1->deblocking_filter_control_present_flag == pps2->deblocking_filter_control_present_flag); - equal &= (pps1->constrained_intra_pred_flag == pps2->constrained_intra_pred_flag); - equal &= (pps1->redundant_pic_cnt_present_flag == pps2->redundant_pic_cnt_present_flag); + equal &= (pps1->deblocking_filter_control_present_flag == + pps2->deblocking_filter_control_present_flag); + equal &= + (pps1->constrained_intra_pred_flag == pps2->constrained_intra_pred_flag); + equal &= (pps1->redundant_pic_cnt_present_flag == + pps2->redundant_pic_cnt_present_flag); - if (!equal) return equal; + if (!equal) + return equal; - //Fidelity Range Extensions Stuff - //It is initialized to zero, so should be ok to check all the time. + // Fidelity Range Extensions Stuff + // It is initialized to zero, so should be ok to check all the time. equal &= (pps1->transform_8x8_mode_flag == pps2->transform_8x8_mode_flag); - equal &= (pps1->pic_scaling_matrix_present_flag == pps2->pic_scaling_matrix_present_flag); - if(pps1->pic_scaling_matrix_present_flag) - { - for(i = 0; i < (6 + ((unsigned)pps1->transform_8x8_mode_flag << 1)); i++) - { - equal &= (pps1->pic_scaling_list_present_flag[i] == pps2->pic_scaling_list_present_flag[i]); - if(pps1->pic_scaling_list_present_flag[i]) - { - if(i < 6) - { + equal &= (pps1->pic_scaling_matrix_present_flag == + pps2->pic_scaling_matrix_present_flag); + if (pps1->pic_scaling_matrix_present_flag) { + for (i = 0; i < (6 + ((unsigned)pps1->transform_8x8_mode_flag << 1)); i++) { + equal &= (pps1->pic_scaling_list_present_flag[i] == + pps2->pic_scaling_list_present_flag[i]); + if (pps1->pic_scaling_list_present_flag[i]) { + if (i < 6) { for (j = 0; j < 16; j++) equal &= (pps1->ScalingList4x4[i][j] == pps2->ScalingList4x4[i][j]); - } - else - { + } else { for (j = 0; j < 64; j++) - equal &= (pps1->ScalingList8x8[i-6][j] == pps2->ScalingList8x8[i-6][j]); + equal &= (pps1->ScalingList8x8[i - 6][j] == + pps2->ScalingList8x8[i - 6][j]); } } } } - equal &= (pps1->second_chroma_qp_index_offset == pps2->second_chroma_qp_index_offset); + equal &= (pps1->second_chroma_qp_index_offset == + pps2->second_chroma_qp_index_offset); return equal; } diff --git a/src/common/ldecod_src/quant.c b/src/common/ldecod_src/quant.c index 2bef3e1..c909fdb 100644 --- a/src/common/ldecod_src/quant.c +++ b/src/common/ldecod_src/quant.c @@ -8,74 +8,48 @@ * Quantization functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * *********************************************************************** */ #include "contributors.h" -#include "global.h" -#include "memalloc.h" #include "block.h" +#include "global.h" #include "image.h" #include "mb_access.h" -#include "transform.h" +#include "memalloc.h" #include "quant.h" +#include "transform.h" -int quant_intra_default[16] = { - 6,13,20,28, - 13,20,28,32, - 20,28,32,37, - 28,32,37,42 -}; +int quant_intra_default[16] = {6, 13, 20, 28, 13, 20, 28, 32, + 20, 28, 32, 37, 28, 32, 37, 42}; -int quant_inter_default[16] = { - 10,14,20,24, - 14,20,24,27, - 20,24,27,30, - 24,27,30,34 -}; +int quant_inter_default[16] = {10, 14, 20, 24, 14, 20, 24, 27, + 20, 24, 27, 30, 24, 27, 30, 34}; int quant8_intra_default[64] = { - 6,10,13,16,18,23,25,27, -10,11,16,18,23,25,27,29, -13,16,18,23,25,27,29,31, -16,18,23,25,27,29,31,33, -18,23,25,27,29,31,33,36, -23,25,27,29,31,33,36,38, -25,27,29,31,33,36,38,40, -27,29,31,33,36,38,40,42 -}; + 6, 10, 13, 16, 18, 23, 25, 27, 10, 11, 16, 18, 23, 25, 27, 29, + 13, 16, 18, 23, 25, 27, 29, 31, 16, 18, 23, 25, 27, 29, 31, 33, + 18, 23, 25, 27, 29, 31, 33, 36, 23, 25, 27, 29, 31, 33, 36, 38, + 25, 27, 29, 31, 33, 36, 38, 40, 27, 29, 31, 33, 36, 38, 40, 42}; int quant8_inter_default[64] = { - 9,13,15,17,19,21,22,24, -13,13,17,19,21,22,24,25, -15,17,19,21,22,24,25,27, -17,19,21,22,24,25,27,28, -19,21,22,24,25,27,28,30, -21,22,24,25,27,28,30,32, -22,24,25,27,28,30,32,33, -24,25,27,28,30,32,33,35 -}; + 9, 13, 15, 17, 19, 21, 22, 24, 13, 13, 17, 19, 21, 22, 24, 25, + 15, 17, 19, 21, 22, 24, 25, 27, 17, 19, 21, 22, 24, 25, 27, 28, + 19, 21, 22, 24, 25, 27, 28, 30, 21, 22, 24, 25, 27, 28, 30, 32, + 22, 24, 25, 27, 28, 30, 32, 33, 24, 25, 27, 28, 30, 32, 33, 35}; -int quant_org[16] = { //to be use if no q matrix is chosen -16,16,16,16, -16,16,16,16, -16,16,16,16, -16,16,16,16 -}; +int quant_org[16] = { // to be use if no q matrix is chosen + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; -int quant8_org[64] = { //to be use if no q matrix is chosen -16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16 -}; +int quant8_org[64] = { // to be use if no q matrix is chosen + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; /*! *********************************************************************** @@ -83,39 +57,38 @@ int quant8_org[64] = { //to be use if no q matrix is chosen * Initiate quantization process arrays *********************************************************************** */ -void init_qp_process(VideoParameters *p_Vid) -{ - int bitdepth_qp_scale = imax(p_Vid->bitdepth_luma_qp_scale,p_Vid->bitdepth_chroma_qp_scale); +void init_qp_process(VideoParameters *p_Vid) { + int bitdepth_qp_scale = + imax(p_Vid->bitdepth_luma_qp_scale, p_Vid->bitdepth_chroma_qp_scale); int i; - // We should allocate memory outside of this process since maybe we will have a change of SPS - // and we may need to recreate these. Currently should only support same bitdepth + // We should allocate memory outside of this process since maybe we will have + // a change of SPS and we may need to recreate these. Currently should only + // support same bitdepth if (p_Vid->qp_per_matrix == NULL) - if ((p_Vid->qp_per_matrix = (int*)malloc((MAX_QP + 1 + bitdepth_qp_scale)*sizeof(int))) == NULL) + if ((p_Vid->qp_per_matrix = (int *)malloc((MAX_QP + 1 + bitdepth_qp_scale) * + sizeof(int))) == NULL) no_mem_exit("init_qp_process: p_Vid->qp_per_matrix"); if (p_Vid->qp_rem_matrix == NULL) - if ((p_Vid->qp_rem_matrix = (int*)malloc((MAX_QP + 1 + bitdepth_qp_scale)*sizeof(int))) == NULL) + if ((p_Vid->qp_rem_matrix = (int *)malloc((MAX_QP + 1 + bitdepth_qp_scale) * + sizeof(int))) == NULL) no_mem_exit("init_qp_process: p_Vid->qp_rem_matrix"); - for (i = 0; i < MAX_QP + bitdepth_qp_scale + 1; i++) - { + for (i = 0; i < MAX_QP + bitdepth_qp_scale + 1; i++) { p_Vid->qp_per_matrix[i] = i / 6; p_Vid->qp_rem_matrix[i] = i % 6; } } -void free_qp_matrices(VideoParameters *p_Vid) -{ - if (p_Vid->qp_per_matrix != NULL) - { - free (p_Vid->qp_per_matrix); +void free_qp_matrices(VideoParameters *p_Vid) { + if (p_Vid->qp_per_matrix != NULL) { + free(p_Vid->qp_per_matrix); p_Vid->qp_per_matrix = NULL; } - if (p_Vid->qp_rem_matrix != NULL) - { - free (p_Vid->qp_rem_matrix); + if (p_Vid->qp_rem_matrix != NULL) { + free(p_Vid->qp_rem_matrix); p_Vid->qp_rem_matrix = NULL; } } @@ -123,7 +96,8 @@ void free_qp_matrices(VideoParameters *p_Vid) /*! ************************************************************************ * \brief - * For mapping the q-matrix to the active id and calculate quantisation values + * For mapping the q-matrix to the active id and calculate quantisation + *values * * \param currSlice * Slice pointer @@ -134,118 +108,97 @@ void free_qp_matrices(VideoParameters *p_Vid) * ************************************************************************ */ -void assign_quant_params(Slice *currSlice) -{ - seq_parameter_set_rbsp_t* sps = currSlice->active_sps; - pic_parameter_set_rbsp_t* pps = currSlice->active_pps; +void assign_quant_params(Slice *currSlice) { + seq_parameter_set_rbsp_t *sps = currSlice->active_sps; + pic_parameter_set_rbsp_t *pps = currSlice->active_pps; int i; int n_ScalingList; - if(!pps->pic_scaling_matrix_present_flag && !sps->seq_scaling_matrix_present_flag) - { - for(i=0; i<12; i++) + if (!pps->pic_scaling_matrix_present_flag && + !sps->seq_scaling_matrix_present_flag) { + for (i = 0; i < 12; i++) currSlice->qmatrix[i] = (i < 6) ? quant_org : quant8_org; - } - else - { + } else { n_ScalingList = (sps->chroma_format_idc != YUV444) ? 8 : 12; - if(sps->seq_scaling_matrix_present_flag) // check sps first + if (sps->seq_scaling_matrix_present_flag) // check sps first { - for(i=0; iseq_scaling_list_present_flag[i]) // fall-back rule A + for (i = 0; i < n_ScalingList; i++) { + if (i < 6) { + if (!sps->seq_scaling_list_present_flag[i]) // fall-back rule A { - if(i==0) + if (i == 0) currSlice->qmatrix[i] = quant_intra_default; - else if(i==3) + else if (i == 3) currSlice->qmatrix[i] = quant_inter_default; else - currSlice->qmatrix[i] = currSlice->qmatrix[i-1]; - } - else - { - if(sps->UseDefaultScalingMatrix4x4Flag[i]) - currSlice->qmatrix[i] = (i<3) ? quant_intra_default : quant_inter_default; + currSlice->qmatrix[i] = currSlice->qmatrix[i - 1]; + } else { + if (sps->UseDefaultScalingMatrix4x4Flag[i]) + currSlice->qmatrix[i] = + (i < 3) ? quant_intra_default : quant_inter_default; else currSlice->qmatrix[i] = sps->ScalingList4x4[i]; } - } - else - { - if(!sps->seq_scaling_list_present_flag[i]) // fall-back rule A + } else { + if (!sps->seq_scaling_list_present_flag[i]) // fall-back rule A { - if(i==6) + if (i == 6) currSlice->qmatrix[i] = quant8_intra_default; - else if(i==7) + else if (i == 7) currSlice->qmatrix[i] = quant8_inter_default; else - currSlice->qmatrix[i] = currSlice->qmatrix[i-2]; - } - else - { - if(sps->UseDefaultScalingMatrix8x8Flag[i-6]) - currSlice->qmatrix[i] = (i==6 || i==8 || i==10) ? quant8_intra_default:quant8_inter_default; + currSlice->qmatrix[i] = currSlice->qmatrix[i - 2]; + } else { + if (sps->UseDefaultScalingMatrix8x8Flag[i - 6]) + currSlice->qmatrix[i] = (i == 6 || i == 8 || i == 10) + ? quant8_intra_default + : quant8_inter_default; else - currSlice->qmatrix[i] = sps->ScalingList8x8[i-6]; + currSlice->qmatrix[i] = sps->ScalingList8x8[i - 6]; } } } } - if(pps->pic_scaling_matrix_present_flag) // then check pps + if (pps->pic_scaling_matrix_present_flag) // then check pps { - for(i=0; ipic_scaling_list_present_flag[i]) // fall-back rule B + for (i = 0; i < n_ScalingList; i++) { + if (i < 6) { + if (!pps->pic_scaling_list_present_flag[i]) // fall-back rule B { - if (i==0) - { - if(!sps->seq_scaling_matrix_present_flag) + if (i == 0) { + if (!sps->seq_scaling_matrix_present_flag) currSlice->qmatrix[i] = quant_intra_default; - } - else if (i==3) - { - if(!sps->seq_scaling_matrix_present_flag) + } else if (i == 3) { + if (!sps->seq_scaling_matrix_present_flag) currSlice->qmatrix[i] = quant_inter_default; - } - else - currSlice->qmatrix[i] = currSlice->qmatrix[i-1]; - } - else - { - if(pps->UseDefaultScalingMatrix4x4Flag[i]) - currSlice->qmatrix[i] = (i<3) ? quant_intra_default:quant_inter_default; + } else + currSlice->qmatrix[i] = currSlice->qmatrix[i - 1]; + } else { + if (pps->UseDefaultScalingMatrix4x4Flag[i]) + currSlice->qmatrix[i] = + (i < 3) ? quant_intra_default : quant_inter_default; else currSlice->qmatrix[i] = pps->ScalingList4x4[i]; } - } - else - { - if(!pps->pic_scaling_list_present_flag[i]) // fall-back rule B + } else { + if (!pps->pic_scaling_list_present_flag[i]) // fall-back rule B { - if (i==6) - { - if(!sps->seq_scaling_matrix_present_flag) + if (i == 6) { + if (!sps->seq_scaling_matrix_present_flag) currSlice->qmatrix[i] = quant8_intra_default; - } - else if(i==7) - { - if(!sps->seq_scaling_matrix_present_flag) + } else if (i == 7) { + if (!sps->seq_scaling_matrix_present_flag) currSlice->qmatrix[i] = quant8_inter_default; - } - else - currSlice->qmatrix[i] = currSlice->qmatrix[i-2]; - } - else - { - if(pps->UseDefaultScalingMatrix8x8Flag[i-6]) - currSlice->qmatrix[i] = (i==6 || i==8 || i==10) ? quant8_intra_default:quant8_inter_default; + } else + currSlice->qmatrix[i] = currSlice->qmatrix[i - 2]; + } else { + if (pps->UseDefaultScalingMatrix8x8Flag[i - 6]) + currSlice->qmatrix[i] = (i == 6 || i == 8 || i == 10) + ? quant8_intra_default + : quant8_inter_default; else - currSlice->qmatrix[i] = pps->ScalingList8x8[i-6]; + currSlice->qmatrix[i] = pps->ScalingList8x8[i - 6]; } } } @@ -253,34 +206,32 @@ void assign_quant_params(Slice *currSlice) } CalculateQuant4x4Param(currSlice); - if(pps->transform_8x8_mode_flag) + if (pps->transform_8x8_mode_flag) CalculateQuant8x8Param(currSlice); } -static void set_dequant4x4(int (*InvLevelScale4x4)[4], const int (*dequant)[4], int *qmatrix) -{ +static void set_dequant4x4(int (*InvLevelScale4x4)[4], const int (*dequant)[4], + int *qmatrix) { int j; - for(j=0; j<4; j++) - { - *(*InvLevelScale4x4 ) = *(*dequant ) * *qmatrix++; - *(*InvLevelScale4x4 + 1) = *(*dequant + 1) * *qmatrix++; - *(*InvLevelScale4x4 + 2) = *(*dequant + 2) * *qmatrix++; + for (j = 0; j < 4; j++) { + *(*InvLevelScale4x4) = *(*dequant) * *qmatrix++; + *(*InvLevelScale4x4 + 1) = *(*dequant + 1) * *qmatrix++; + *(*InvLevelScale4x4 + 2) = *(*dequant + 2) * *qmatrix++; *(*InvLevelScale4x4++ + 3) = *(*dequant++ + 3) * *qmatrix++; } } -static void set_dequant8x8(int (*InvLevelScale8x8)[8], const int (*dequant)[8], int *qmatrix) -{ +static void set_dequant8x8(int (*InvLevelScale8x8)[8], const int (*dequant)[8], + int *qmatrix) { int j; - for(j = 0; j < 8; j++) - { - *(*InvLevelScale8x8 ) = *(*dequant ) * *qmatrix++; - *(*InvLevelScale8x8 + 1) = *(*dequant + 1) * *qmatrix++; - *(*InvLevelScale8x8 + 2) = *(*dequant + 2) * *qmatrix++; - *(*InvLevelScale8x8 + 3) = *(*dequant + 3) * *qmatrix++; - *(*InvLevelScale8x8 + 4) = *(*dequant + 4) * *qmatrix++; - *(*InvLevelScale8x8 + 5) = *(*dequant + 5) * *qmatrix++; - *(*InvLevelScale8x8 + 6) = *(*dequant + 6) * *qmatrix++; + for (j = 0; j < 8; j++) { + *(*InvLevelScale8x8) = *(*dequant) * *qmatrix++; + *(*InvLevelScale8x8 + 1) = *(*dequant + 1) * *qmatrix++; + *(*InvLevelScale8x8 + 2) = *(*dequant + 2) * *qmatrix++; + *(*InvLevelScale8x8 + 3) = *(*dequant + 3) * *qmatrix++; + *(*InvLevelScale8x8 + 4) = *(*dequant + 4) * *qmatrix++; + *(*InvLevelScale8x8 + 5) = *(*dequant + 5) * *qmatrix++; + *(*InvLevelScale8x8 + 6) = *(*dequant + 6) * *qmatrix++; *(*InvLevelScale8x8++ + 7) = *(*dequant++ + 7) * *qmatrix++; } } @@ -292,26 +243,29 @@ static void set_dequant8x8(int (*InvLevelScale8x8)[8], const int (*dequant)[8], * ************************************************************************ */ -void CalculateQuant4x4Param(Slice *currSlice) -{ +void CalculateQuant4x4Param(Slice *currSlice) { int k; - const int (*p_dequant_coef)[4][4] = dequant_coef; - int (*InvLevelScale4x4_Intra_0)[4][4] = currSlice->InvLevelScale4x4_Intra[0]; - int (*InvLevelScale4x4_Intra_1)[4][4] = currSlice->InvLevelScale4x4_Intra[1]; - int (*InvLevelScale4x4_Intra_2)[4][4] = currSlice->InvLevelScale4x4_Intra[2]; - int (*InvLevelScale4x4_Inter_0)[4][4] = currSlice->InvLevelScale4x4_Inter[0]; - int (*InvLevelScale4x4_Inter_1)[4][4] = currSlice->InvLevelScale4x4_Inter[1]; - int (*InvLevelScale4x4_Inter_2)[4][4] = currSlice->InvLevelScale4x4_Inter[2]; + const int(*p_dequant_coef)[4][4] = dequant_coef; + int(*InvLevelScale4x4_Intra_0)[4][4] = currSlice->InvLevelScale4x4_Intra[0]; + int(*InvLevelScale4x4_Intra_1)[4][4] = currSlice->InvLevelScale4x4_Intra[1]; + int(*InvLevelScale4x4_Intra_2)[4][4] = currSlice->InvLevelScale4x4_Intra[2]; + int(*InvLevelScale4x4_Inter_0)[4][4] = currSlice->InvLevelScale4x4_Inter[0]; + int(*InvLevelScale4x4_Inter_1)[4][4] = currSlice->InvLevelScale4x4_Inter[1]; + int(*InvLevelScale4x4_Inter_2)[4][4] = currSlice->InvLevelScale4x4_Inter[2]; - - for(k=0; k<6; k++) - { - set_dequant4x4(*InvLevelScale4x4_Intra_0++, *p_dequant_coef , currSlice->qmatrix[0]); - set_dequant4x4(*InvLevelScale4x4_Intra_1++, *p_dequant_coef , currSlice->qmatrix[1]); - set_dequant4x4(*InvLevelScale4x4_Intra_2++, *p_dequant_coef , currSlice->qmatrix[2]); - set_dequant4x4(*InvLevelScale4x4_Inter_0++, *p_dequant_coef , currSlice->qmatrix[3]); - set_dequant4x4(*InvLevelScale4x4_Inter_1++, *p_dequant_coef , currSlice->qmatrix[4]); - set_dequant4x4(*InvLevelScale4x4_Inter_2++, *p_dequant_coef++, currSlice->qmatrix[5]); + for (k = 0; k < 6; k++) { + set_dequant4x4(*InvLevelScale4x4_Intra_0++, *p_dequant_coef, + currSlice->qmatrix[0]); + set_dequant4x4(*InvLevelScale4x4_Intra_1++, *p_dequant_coef, + currSlice->qmatrix[1]); + set_dequant4x4(*InvLevelScale4x4_Intra_2++, *p_dequant_coef, + currSlice->qmatrix[2]); + set_dequant4x4(*InvLevelScale4x4_Inter_0++, *p_dequant_coef, + currSlice->qmatrix[3]); + set_dequant4x4(*InvLevelScale4x4_Inter_1++, *p_dequant_coef, + currSlice->qmatrix[4]); + set_dequant4x4(*InvLevelScale4x4_Inter_2++, *p_dequant_coef++, + currSlice->qmatrix[5]); } } @@ -322,32 +276,35 @@ void CalculateQuant4x4Param(Slice *currSlice) * ************************************************************************ */ -void CalculateQuant8x8Param(Slice *currSlice) -{ +void CalculateQuant8x8Param(Slice *currSlice) { int k; - const int (*p_dequant_coef)[8][8] = dequant_coef8; - int (*InvLevelScale8x8_Intra_0)[8][8] = currSlice->InvLevelScale8x8_Intra[0]; - int (*InvLevelScale8x8_Intra_1)[8][8] = currSlice->InvLevelScale8x8_Intra[1]; - int (*InvLevelScale8x8_Intra_2)[8][8] = currSlice->InvLevelScale8x8_Intra[2]; - int (*InvLevelScale8x8_Inter_0)[8][8] = currSlice->InvLevelScale8x8_Inter[0]; - int (*InvLevelScale8x8_Inter_1)[8][8] = currSlice->InvLevelScale8x8_Inter[1]; - int (*InvLevelScale8x8_Inter_2)[8][8] = currSlice->InvLevelScale8x8_Inter[2]; + const int(*p_dequant_coef)[8][8] = dequant_coef8; + int(*InvLevelScale8x8_Intra_0)[8][8] = currSlice->InvLevelScale8x8_Intra[0]; + int(*InvLevelScale8x8_Intra_1)[8][8] = currSlice->InvLevelScale8x8_Intra[1]; + int(*InvLevelScale8x8_Intra_2)[8][8] = currSlice->InvLevelScale8x8_Intra[2]; + int(*InvLevelScale8x8_Inter_0)[8][8] = currSlice->InvLevelScale8x8_Inter[0]; + int(*InvLevelScale8x8_Inter_1)[8][8] = currSlice->InvLevelScale8x8_Inter[1]; + int(*InvLevelScale8x8_Inter_2)[8][8] = currSlice->InvLevelScale8x8_Inter[2]; - for(k=0; k<6; k++) - { - set_dequant8x8(*InvLevelScale8x8_Intra_0++, *p_dequant_coef , currSlice->qmatrix[6]); - set_dequant8x8(*InvLevelScale8x8_Inter_0++, *p_dequant_coef++, currSlice->qmatrix[7]); + for (k = 0; k < 6; k++) { + set_dequant8x8(*InvLevelScale8x8_Intra_0++, *p_dequant_coef, + currSlice->qmatrix[6]); + set_dequant8x8(*InvLevelScale8x8_Inter_0++, *p_dequant_coef++, + currSlice->qmatrix[7]); } p_dequant_coef = dequant_coef8; - if( currSlice->active_sps->chroma_format_idc == 3 ) // 4:4:4 + if (currSlice->active_sps->chroma_format_idc == 3) // 4:4:4 { - for(k=0; k<6; k++) - { - set_dequant8x8(*InvLevelScale8x8_Intra_1++, *p_dequant_coef , currSlice->qmatrix[8]); - set_dequant8x8(*InvLevelScale8x8_Inter_1++, *p_dequant_coef , currSlice->qmatrix[9]); - set_dequant8x8(*InvLevelScale8x8_Intra_2++, *p_dequant_coef , currSlice->qmatrix[10]); - set_dequant8x8(*InvLevelScale8x8_Inter_2++, *p_dequant_coef++, currSlice->qmatrix[11]); + for (k = 0; k < 6; k++) { + set_dequant8x8(*InvLevelScale8x8_Intra_1++, *p_dequant_coef, + currSlice->qmatrix[8]); + set_dequant8x8(*InvLevelScale8x8_Inter_1++, *p_dequant_coef, + currSlice->qmatrix[9]); + set_dequant8x8(*InvLevelScale8x8_Intra_2++, *p_dequant_coef, + currSlice->qmatrix[10]); + set_dequant8x8(*InvLevelScale8x8_Inter_2++, *p_dequant_coef++, + currSlice->qmatrix[11]); } } } diff --git a/src/common/ldecod_src/rtp.c b/src/common/ldecod_src/rtp.c index 3545616..ee14dea 100644 --- a/src/common/ldecod_src/rtp.c +++ b/src/common/ldecod_src/rtp.c @@ -7,12 +7,12 @@ * Network Adaptation layer for RTP packets * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Stephan Wenger ************************************************************************ */ - /*! A quick guide to the basics of the RTP decoder implementation @@ -75,12 +75,13 @@ Each Slice header contaions the information on which parameter set to be used. The function RTPSetImgInp() copies the information of the relevant parameter set in the VCL's global variables p_Vid-> and p_Inp-> IMPORTANT: any changes - in the semantics of the p_Vid-> and p_Inp-> structure members must be represented - in this function as well! + in the semantics of the p_Vid-> and p_Inp-> structure members must be + represented in this function as well! A note to the stream-buffer data structure: The stream buffer always contains only the contents of the partition in question, and not the slice/partition - header. Decoding has to start at bitoffset 0 (CAVLC) or bytreoffset 0 (CABAC). + header. Decoding has to start at bitoffset 0 (CAVLC) or bytreoffset 0 + (CABAC). The remaining functions should be self-explanatory. @@ -93,14 +94,14 @@ #endif #include "contributors.h" -#include "global.h" #include "errorconcealment.h" -#include "rtp.h" #include "fmo.h" -#include "sei.h" +#include "global.h" #include "memalloc.h" +#include "rtp.h" +#include "sei.h" -int RTPReadPacket (RTPpacket_t *p, int bitstream); +int RTPReadPacket(RTPpacket_t *p, int bitstream); /*! ************************************************************************ @@ -110,32 +111,26 @@ int RTPReadPacket (RTPpacket_t *p, int bitstream); * none ************************************************************************ */ -void OpenRTPFile (VideoParameters *p_Vid, char *fn) -{ - if ((p_Vid->BitStreamFile = open(fn, OPENFLAGS_READ)) == -1) - { - snprintf (errortext, ET_SIZE, "Cannot open RTP file '%s'", fn); - error(errortext,500); +void OpenRTPFile(VideoParameters *p_Vid, char *fn) { + if ((p_Vid->BitStreamFile = open(fn, OPENFLAGS_READ)) == -1) { + snprintf(errortext, ET_SIZE, "Cannot open RTP file '%s'", fn); + error(errortext, 500); } } - /*! ************************************************************************ * \brief * Closes the bit stream file ************************************************************************ */ -void CloseRTPFile(VideoParameters *p_Vid) -{ - if (p_Vid->BitStreamFile != -1) - { +void CloseRTPFile(VideoParameters *p_Vid) { + if (p_Vid->BitStreamFile != -1) { close(p_Vid->BitStreamFile); - p_Vid->BitStreamFile = - 1; + p_Vid->BitStreamFile = -1; } } - /*! ************************************************************************ * \brief @@ -151,66 +146,64 @@ void CloseRTPFile(VideoParameters *p_Vid) ************************************************************************ */ -int GetRTPNALU (VideoParameters *p_Vid, NALU_t *nalu) -{ - static uint16 first_call = 1; //!< triggers sequence number initialization on first call - static uint16 old_seq = 0; //!< store the last RTP sequence number for loss detection +int GetRTPNALU(VideoParameters *p_Vid, NALU_t *nalu) { + static uint16 first_call = + 1; //!< triggers sequence number initialization on first call + static uint16 old_seq = + 0; //!< store the last RTP sequence number for loss detection RTPpacket_t *p; int ret; - if ((p=malloc (sizeof (RTPpacket_t)))== NULL) - no_mem_exit ("GetRTPNALU-1"); - if ((p->packet=malloc (MAXRTPPACKETSIZE))== NULL) - no_mem_exit ("GetRTPNALU-2"); - if ((p->payload=malloc (MAXRTPPACKETSIZE))== NULL) - no_mem_exit ("GetRTPNALU-3"); + if ((p = malloc(sizeof(RTPpacket_t))) == NULL) + no_mem_exit("GetRTPNALU-1"); + if ((p->packet = malloc(MAXRTPPACKETSIZE)) == NULL) + no_mem_exit("GetRTPNALU-2"); + if ((p->payload = malloc(MAXRTPPACKETSIZE)) == NULL) + no_mem_exit("GetRTPNALU-3"); - ret = RTPReadPacket (p, p_Vid->BitStreamFile); + ret = RTPReadPacket(p, p_Vid->BitStreamFile); nalu->forbidden_bit = 1; nalu->len = 0; if (ret > 0) // we got a packet ( -1=error, 0=end of file ) { - if (first_call) - { + if (first_call) { first_call = 0; - old_seq = (uint16) (p->seq - 1); + old_seq = (uint16)(p->seq - 1); } - nalu->lost_packets = (uint16) ( p->seq - (old_seq + 1) ); + nalu->lost_packets = (uint16)(p->seq - (old_seq + 1)); old_seq = p->seq; - assert (p->paylen < nalu->max_size); + assert(p->paylen < nalu->max_size); nalu->len = p->paylen; - memcpy (nalu->buf, p->payload, p->paylen); - nalu->forbidden_bit = (nalu->buf[0]>>7) & 1; - nalu->nal_reference_idc = (NalRefIdc) ((nalu->buf[0]>>5) & 3); - nalu->nal_unit_type = (NaluType) ((nalu->buf[0]) & 0x1f); - if (nalu->lost_packets) - { - printf ("Warning: RTP sequence number discontinuity detected\n"); + memcpy(nalu->buf, p->payload, p->paylen); + nalu->forbidden_bit = (nalu->buf[0] >> 7) & 1; + nalu->nal_reference_idc = (NalRefIdc)((nalu->buf[0] >> 5) & 3); + nalu->nal_unit_type = (NaluType)((nalu->buf[0]) & 0x1f); + if (nalu->lost_packets) { + printf("Warning: RTP sequence number discontinuity detected\n"); } } // free memory - free (p->payload); - free (p->packet); - free (p); + free(p->payload); + free(p->packet); + free(p); -// printf ("Got an RTP NALU, len %d, first byte %x\n", nalu->len, nalu->buf[0]); - - if (ret>0) + // printf ("Got an RTP NALU, len %d, first byte %x\n", nalu->len, + // nalu->buf[0]); + + if (ret > 0) // length of packet return nalu->len; - else + else // error code return ret; } - - /*! ***************************************************************************** * @@ -236,50 +229,49 @@ int GetRTPNALU (VideoParameters *p_Vid, NALU_t *nalu) * Stephan Wenger stewe@cs.tu-berlin.de *****************************************************************************/ -int DecomposeRTPpacket (RTPpacket_t *p) +int DecomposeRTPpacket(RTPpacket_t *p) { #ifdef SPEC_PTHREADS // consistency check - assert (p->packlen < 65536 - 28); // IP, UDP headers - assert (p->packlen >= 12); // at least a complete RTP header - assert (p->payload != NULL); - assert (p->packet != NULL); + assert(p->packlen < 65536 - 28); // IP, UDP headers + assert(p->packlen >= 12); // at least a complete RTP header + assert(p->payload != NULL); + assert(p->packet != NULL); // Extract header information - p->v = (p->packet[0] >> 6) & 0x03; - p->p = (p->packet[0] >> 5) & 0x01; - p->x = (p->packet[0] >> 4) & 0x01; + p->v = (p->packet[0] >> 6) & 0x03; + p->p = (p->packet[0] >> 5) & 0x01; + p->x = (p->packet[0] >> 4) & 0x01; p->cc = (p->packet[0] >> 0) & 0x0F; - p->m = (p->packet[1] >> 7) & 0x01; + p->m = (p->packet[1] >> 7) & 0x01; p->pt = (p->packet[1] >> 0) & 0x7F; - memcpy (&p->seq, &p->packet[2], 2); + memcpy(&p->seq, &p->packet[2], 2); p->seq = ntohs((uint16)p->seq); - memcpy (&p->timestamp, &p->packet[4], 4);// change to shifts for unified byte sex + memcpy(&p->timestamp, &p->packet[4], + 4); // change to shifts for unified byte sex p->timestamp = ntohl(p->timestamp); - memcpy (&p->ssrc, &p->packet[8], 4);// change to shifts for unified byte sex + memcpy(&p->ssrc, &p->packet[8], 4); // change to shifts for unified byte sex p->ssrc = ntohl(p->ssrc); // header consistency checks - if ( (p->v != 2) - || (p->p != 0) - || (p->x != 0) - || (p->cc != 0) ) - { - printf ("DecomposeRTPpacket, RTP header consistency problem, header follows\n"); - DumpRTPHeader (p); + if ((p->v != 2) || (p->p != 0) || (p->x != 0) || (p->cc != 0)) { + printf( + "DecomposeRTPpacket, RTP header consistency problem, header follows\n"); + DumpRTPHeader(p); return -1; } - p->paylen = p->packlen-12; - memcpy (p->payload, &p->packet[12], p->paylen); + p->paylen = p->packlen - 12; + memcpy(p->payload, &p->packet[12], p->paylen); return 0; #else - printf("ERROR: we're in DecompseRTPpacket which shouldn't be called in SPEC CPU\n"); + printf("ERROR: we're in DecompseRTPpacket which shouldn't be called in SPEC " + "CPU\n"); return 1; #endif } @@ -306,24 +298,23 @@ int DecomposeRTPpacket (RTPpacket_t *p) * Stephan Wenger stewe@cs.tu-berlin.de *****************************************************************************/ -void DumpRTPHeader (RTPpacket_t *p) +void DumpRTPHeader(RTPpacket_t *p) { int i; - for (i=0; i< 30; i++) - printf ("%02x ", p->packet[i]); - printf ("Version (V): %d\n", (int) p->v); - printf ("Padding (P): %d\n", (int) p->p); - printf ("Extension (X): %d\n", (int) p->x); - printf ("CSRC count (CC): %d\n", (int) p->cc); - printf ("Marker bit (M): %d\n", (int) p->m); - printf ("Payload Type (PT): %d\n", (int) p->pt); - printf ("Sequence Number: %d\n", (int) p->seq); - printf ("Timestamp: %d\n", (int) p->timestamp); - printf ("SSRC: %d\n", (int) p->ssrc); + for (i = 0; i < 30; i++) + printf("%02x ", p->packet[i]); + printf("Version (V): %d\n", (int)p->v); + printf("Padding (P): %d\n", (int)p->p); + printf("Extension (X): %d\n", (int)p->x); + printf("CSRC count (CC): %d\n", (int)p->cc); + printf("Marker bit (M): %d\n", (int)p->m); + printf("Payload Type (PT): %d\n", (int)p->pt); + printf("Sequence Number: %d\n", (int)p->seq); + printf("Timestamp: %d\n", (int)p->timestamp); + printf("SSRC: %d\n", (int)p->ssrc); } - /*! ***************************************************************************** * @@ -351,44 +342,39 @@ void DumpRTPHeader (RTPpacket_t *p) * \author * Stephan Wenger, stewe@cs.tu-berlin.de *****************************************************************************/ -int RTPReadPacket (RTPpacket_t *p, int bitstream) -{ +int RTPReadPacket(RTPpacket_t *p, int bitstream) { int64 Filepos; int intime; - assert (p != NULL); - assert (p->packet != NULL); - assert (p->payload != NULL); + assert(p != NULL); + assert(p->packet != NULL); + assert(p->payload != NULL); - Filepos = tell (bitstream); - if (4 != read (bitstream, &p->packlen, 4)) - { + Filepos = tell(bitstream); + if (4 != read(bitstream, &p->packlen, 4)) { return 0; } - if (4 != read (bitstream, &intime, 4)) - { - lseek (bitstream, Filepos, SEEK_SET); - printf ("RTPReadPacket: File corruption, could not read Timestamp, exit\n"); - exit (-1); + if (4 != read(bitstream, &intime, 4)) { + lseek(bitstream, Filepos, SEEK_SET); + printf("RTPReadPacket: File corruption, could not read Timestamp, exit\n"); + exit(-1); } - assert (p->packlen < MAXRTPPACKETSIZE); + assert(p->packlen < MAXRTPPACKETSIZE); - if (p->packlen != (unsigned int) read (bitstream, p->packet, p->packlen)) - { - printf ("RTPReadPacket: File corruption, could not read %d bytes\n", (int) p->packlen); - exit (-1); // EOF inidication + if (p->packlen != (unsigned int)read(bitstream, p->packet, p->packlen)) { + printf("RTPReadPacket: File corruption, could not read %d bytes\n", + (int)p->packlen); + exit(-1); // EOF inidication } - if (DecomposeRTPpacket (p) < 0) - { - // this should never happen, hence exit() is ok. We probably do not want to attempt - // to decode a packet that obviously wasn't generated by RTP - printf ("Errors reported by DecomposePacket(), exit\n"); - exit (-700); + if (DecomposeRTPpacket(p) < 0) { + // this should never happen, hence exit() is ok. We probably do not want to + // attempt to decode a packet that obviously wasn't generated by RTP + printf("Errors reported by DecomposePacket(), exit\n"); + exit(-700); } - assert (p->pt == H264PAYLOADTYPE); - assert (p->ssrc == H264SSRC); + assert(p->pt == H264PAYLOADTYPE); + assert(p->ssrc == H264SSRC); return p->packlen; } - diff --git a/src/common/ldecod_src/sei.c b/src/common/ldecod_src/sei.c index 52b8826..db155c7 100644 --- a/src/common/ldecod_src/sei.c +++ b/src/common/ldecod_src/sei.c @@ -6,7 +6,8 @@ * Functions to implement SEI messages * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Dong Tian * - Karsten Suehring ************************************************************************ @@ -14,42 +15,53 @@ #include "contributors.h" -#include #include "global.h" -#include "memalloc.h" -#include "sei.h" -#include "vlc.h" #include "header.h" #include "mbuffer.h" +#include "memalloc.h" #include "parset.h" +#include "sei.h" +#include "vlc.h" +#include - -// #define PRINT_BUFFERING_PERIOD_INFO // uncomment to print buffering period SEI info -// #define PRINT_PCITURE_TIMING_INFO // uncomment to print picture timing SEI info -// #define WRITE_MAP_IMAGE // uncomment to write spare picture map -// #define PRINT_SUBSEQUENCE_INFO // uncomment to print sub-sequence SEI info -// #define PRINT_SUBSEQUENCE_LAYER_CHAR // uncomment to print sub-sequence layer characteristics SEI info -// #define PRINT_SUBSEQUENCE_CHAR // uncomment to print sub-sequence characteristics SEI info -// #define PRINT_SCENE_INFORMATION // uncomment to print scene information SEI info -// #define PRINT_PAN_SCAN_RECT // uncomment to print pan-scan rectangle SEI info -// #define PRINT_RECOVERY_POINT // uncomment to print random access point SEI info -// #define PRINT_FILLER_PAYLOAD_INFO // uncomment to print filler payload SEI info -// #define PRINT_DEC_REF_PIC_MARKING // uncomment to print decoded picture buffer management repetition SEI info -// #define PRINT_RESERVED_INFO // uncomment to print reserved SEI info -// #define PRINT_USER_DATA_UNREGISTERED_INFO // uncomment to print unregistered user data SEI info -// #define PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO // uncomment to print ITU-T T.35 user data SEI info -// #define PRINT_FULL_FRAME_FREEZE_INFO // uncomment to print full-frame freeze SEI info -// #define PRINT_FULL_FRAME_FREEZE_RELEASE_INFO // uncomment to print full-frame freeze release SEI info -// #define PRINT_FULL_FRAME_SNAPSHOT_INFO // uncomment to print full-frame snapshot SEI info -// #define PRINT_PROGRESSIVE_REFINEMENT_END_INFO // uncomment to print Progressive refinement segment start SEI info -// #define PRINT_PROGRESSIVE_REFINEMENT_END_INFO // uncomment to print Progressive refinement segment end SEI info -// #define PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO // uncomment to print Motion-constrained slice group set SEI info -// #define PRINT_FILM_GRAIN_CHARACTERISTICS_INFO // uncomment to print Film grain characteristics SEI info -// #define PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO // uncomment to print deblocking filter display preference SEI info -// #define PRINT_STEREO_VIDEO_INFO_INFO // uncomment to print stereo video SEI info -// #define PRINT_TONE_MAPPING // uncomment to print tone-mapping SEI info -// #define PRINT_POST_FILTER_HINT_INFO // uncomment to print post-filter hint SEI info -// #define PRINT_FRAME_PACKING_ARRANGEMENT_INFO // uncomment to print frame packing arrangement SEI info +// #define PRINT_BUFFERING_PERIOD_INFO // uncomment to print buffering period +// SEI info #define PRINT_PCITURE_TIMING_INFO // uncomment to print picture +// timing SEI info #define WRITE_MAP_IMAGE // uncomment to write +// spare picture map #define PRINT_SUBSEQUENCE_INFO // uncomment to +// print sub-sequence SEI info #define PRINT_SUBSEQUENCE_LAYER_CHAR // +// uncomment to print sub-sequence layer characteristics SEI info #define +// PRINT_SUBSEQUENCE_CHAR // uncomment to print sub-sequence +// characteristics SEI info #define PRINT_SCENE_INFORMATION // uncomment +// to print scene information SEI info #define PRINT_PAN_SCAN_RECT // +// uncomment to print pan-scan rectangle SEI info #define PRINT_RECOVERY_POINT +// // uncomment to print random access point SEI info #define +// PRINT_FILLER_PAYLOAD_INFO // uncomment to print filler payload SEI info +// #define PRINT_DEC_REF_PIC_MARKING // uncomment to print decoded picture +// buffer management repetition SEI info #define PRINT_RESERVED_INFO // +// uncomment to print reserved SEI info #define +// PRINT_USER_DATA_UNREGISTERED_INFO // uncomment to print unregistered +// user data SEI info #define PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO // +// uncomment to print ITU-T T.35 user data SEI info #define +// PRINT_FULL_FRAME_FREEZE_INFO // uncomment to print full-frame +// freeze SEI info #define PRINT_FULL_FRAME_FREEZE_RELEASE_INFO // +// uncomment to print full-frame freeze release SEI info #define +// PRINT_FULL_FRAME_SNAPSHOT_INFO // uncomment to print full-frame +// snapshot SEI info #define PRINT_PROGRESSIVE_REFINEMENT_END_INFO // +// uncomment to print Progressive refinement segment start SEI info #define +// PRINT_PROGRESSIVE_REFINEMENT_END_INFO // uncomment to print Progressive +// refinement segment end SEI info #define +// PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO // uncomment to print +// Motion-constrained slice group set SEI info #define +// PRINT_FILM_GRAIN_CHARACTERISTICS_INFO // uncomment to print Film grain +// characteristics SEI info #define +// PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO // uncomment to print +// deblocking filter display preference SEI info #define +// PRINT_STEREO_VIDEO_INFO_INFO // uncomment to print stereo video +// SEI info #define PRINT_TONE_MAPPING // uncomment to +// print tone-mapping SEI info #define PRINT_POST_FILTER_HINT_INFO // uncomment +// to print post-filter hint SEI info #define +// PRINT_FRAME_PACKING_ARRANGEMENT_INFO // uncomment to print frame +// packing arrangement SEI info /*! ************************************************************************ * \brief @@ -63,123 +75,130 @@ * ************************************************************************ */ -void InterpretSEIMessage(byte* msg, int size, VideoParameters *p_Vid, Slice *pSlice) -{ +void InterpretSEIMessage(byte *msg, int size, VideoParameters *p_Vid, + Slice *pSlice) { int payload_type = 0; int payload_size = 0; int offset = 1; byte tmp_byte; - - do - { + + do { // sei_message(); payload_type = 0; tmp_byte = msg[offset++]; - while (tmp_byte == 0xFF) - { + while (tmp_byte == 0xFF) { payload_type += 255; tmp_byte = msg[offset++]; } - payload_type += tmp_byte; // this is the last byte + payload_type += tmp_byte; // this is the last byte payload_size = 0; tmp_byte = msg[offset++]; - while (tmp_byte == 0xFF) - { + while (tmp_byte == 0xFF) { payload_size += 255; tmp_byte = msg[offset++]; } - payload_size += tmp_byte; // this is the last byte + payload_size += tmp_byte; // this is the last byte - switch ( payload_type ) // sei_payload( type, size ); + switch (payload_type) // sei_payload( type, size ); { - case SEI_BUFFERING_PERIOD: - interpret_buffering_period_info( msg+offset, payload_size, p_Vid ); + case SEI_BUFFERING_PERIOD: + interpret_buffering_period_info(msg + offset, payload_size, p_Vid); break; - case SEI_PIC_TIMING: - interpret_picture_timing_info( msg+offset, payload_size, p_Vid ); + case SEI_PIC_TIMING: + interpret_picture_timing_info(msg + offset, payload_size, p_Vid); break; - case SEI_PAN_SCAN_RECT: - interpret_pan_scan_rect_info( msg+offset, payload_size, p_Vid ); + case SEI_PAN_SCAN_RECT: + interpret_pan_scan_rect_info(msg + offset, payload_size, p_Vid); break; - case SEI_FILLER_PAYLOAD: - interpret_filler_payload_info( msg+offset, payload_size, p_Vid ); + case SEI_FILLER_PAYLOAD: + interpret_filler_payload_info(msg + offset, payload_size, p_Vid); break; - case SEI_USER_DATA_REGISTERED_ITU_T_T35: - interpret_user_data_registered_itu_t_t35_info( msg+offset, payload_size, p_Vid ); + case SEI_USER_DATA_REGISTERED_ITU_T_T35: + interpret_user_data_registered_itu_t_t35_info(msg + offset, payload_size, + p_Vid); break; - case SEI_USER_DATA_UNREGISTERED: - interpret_user_data_unregistered_info( msg+offset, payload_size, p_Vid ); + case SEI_USER_DATA_UNREGISTERED: + interpret_user_data_unregistered_info(msg + offset, payload_size, p_Vid); break; - case SEI_RECOVERY_POINT: - interpret_recovery_point_info( msg+offset, payload_size, p_Vid ); + case SEI_RECOVERY_POINT: + interpret_recovery_point_info(msg + offset, payload_size, p_Vid); break; - case SEI_DEC_REF_PIC_MARKING_REPETITION: - interpret_dec_ref_pic_marking_repetition_info( msg+offset, payload_size, p_Vid, pSlice ); + case SEI_DEC_REF_PIC_MARKING_REPETITION: + interpret_dec_ref_pic_marking_repetition_info(msg + offset, payload_size, + p_Vid, pSlice); break; - case SEI_SPARE_PIC: - interpret_spare_pic( msg+offset, payload_size, p_Vid ); + case SEI_SPARE_PIC: + interpret_spare_pic(msg + offset, payload_size, p_Vid); break; - case SEI_SCENE_INFO: - interpret_scene_information( msg+offset, payload_size, p_Vid ); + case SEI_SCENE_INFO: + interpret_scene_information(msg + offset, payload_size, p_Vid); break; - case SEI_SUB_SEQ_INFO: - interpret_subsequence_info( msg+offset, payload_size, p_Vid ); + case SEI_SUB_SEQ_INFO: + interpret_subsequence_info(msg + offset, payload_size, p_Vid); break; - case SEI_SUB_SEQ_LAYER_CHARACTERISTICS: - interpret_subsequence_layer_characteristics_info( msg+offset, payload_size, p_Vid ); + case SEI_SUB_SEQ_LAYER_CHARACTERISTICS: + interpret_subsequence_layer_characteristics_info(msg + offset, + payload_size, p_Vid); break; - case SEI_SUB_SEQ_CHARACTERISTICS: - interpret_subsequence_characteristics_info( msg+offset, payload_size, p_Vid ); + case SEI_SUB_SEQ_CHARACTERISTICS: + interpret_subsequence_characteristics_info(msg + offset, payload_size, + p_Vid); break; - case SEI_FULL_FRAME_FREEZE: - interpret_full_frame_freeze_info( msg+offset, payload_size, p_Vid ); + case SEI_FULL_FRAME_FREEZE: + interpret_full_frame_freeze_info(msg + offset, payload_size, p_Vid); break; - case SEI_FULL_FRAME_FREEZE_RELEASE: - interpret_full_frame_freeze_release_info( msg+offset, payload_size, p_Vid ); + case SEI_FULL_FRAME_FREEZE_RELEASE: + interpret_full_frame_freeze_release_info(msg + offset, payload_size, + p_Vid); break; - case SEI_FULL_FRAME_SNAPSHOT: - interpret_full_frame_snapshot_info( msg+offset, payload_size, p_Vid ); + case SEI_FULL_FRAME_SNAPSHOT: + interpret_full_frame_snapshot_info(msg + offset, payload_size, p_Vid); break; - case SEI_PROGRESSIVE_REFINEMENT_SEGMENT_START: - interpret_progressive_refinement_start_info( msg+offset, payload_size, p_Vid ); + case SEI_PROGRESSIVE_REFINEMENT_SEGMENT_START: + interpret_progressive_refinement_start_info(msg + offset, payload_size, + p_Vid); break; - case SEI_PROGRESSIVE_REFINEMENT_SEGMENT_END: - interpret_progressive_refinement_end_info( msg+offset, payload_size, p_Vid ); + case SEI_PROGRESSIVE_REFINEMENT_SEGMENT_END: + interpret_progressive_refinement_end_info(msg + offset, payload_size, + p_Vid); break; - case SEI_MOTION_CONSTRAINED_SLICE_GROUP_SET: - interpret_motion_constrained_slice_group_set_info( msg+offset, payload_size, p_Vid ); - case SEI_FILM_GRAIN_CHARACTERISTICS: - interpret_film_grain_characteristics_info ( msg+offset, payload_size, p_Vid ); + case SEI_MOTION_CONSTRAINED_SLICE_GROUP_SET: + interpret_motion_constrained_slice_group_set_info(msg + offset, + payload_size, p_Vid); + case SEI_FILM_GRAIN_CHARACTERISTICS: + interpret_film_grain_characteristics_info(msg + offset, payload_size, + p_Vid); break; - case SEI_DEBLOCKING_FILTER_DISPLAY_PREFERENCE: - interpret_deblocking_filter_display_preference_info ( msg+offset, payload_size, p_Vid ); + case SEI_DEBLOCKING_FILTER_DISPLAY_PREFERENCE: + interpret_deblocking_filter_display_preference_info(msg + offset, + payload_size, p_Vid); break; - case SEI_STEREO_VIDEO_INFO: - interpret_stereo_video_info_info ( msg+offset, payload_size, p_Vid ); + case SEI_STEREO_VIDEO_INFO: + interpret_stereo_video_info_info(msg + offset, payload_size, p_Vid); break; - case SEI_TONE_MAPPING: - interpret_tone_mapping( msg+offset, payload_size, p_Vid ); + case SEI_TONE_MAPPING: + interpret_tone_mapping(msg + offset, payload_size, p_Vid); break; - case SEI_POST_FILTER_HINTS: - interpret_post_filter_hints_info ( msg+offset, payload_size, p_Vid ); + case SEI_POST_FILTER_HINTS: + interpret_post_filter_hints_info(msg + offset, payload_size, p_Vid); break; - case SEI_FRAME_PACKING_ARRANGEMENT: - interpret_frame_packing_arrangement_info( msg+offset, payload_size, p_Vid ); + case SEI_FRAME_PACKING_ARRANGEMENT: + interpret_frame_packing_arrangement_info(msg + offset, payload_size, + p_Vid); break; default: - interpret_reserved_info( msg+offset, payload_size, p_Vid ); - break; + interpret_reserved_info(msg + offset, payload_size, p_Vid); + break; } offset += payload_size; - } while( msg[offset] != 0x80 ); // more_rbsp_data() msg[offset] != 0x80 + } while (msg[offset] != 0x80); // more_rbsp_data() msg[offset] != 0x80 // ignore the trailing bits rbsp_trailing_bits(); - assert(msg[offset] == 0x80); // this is the trailing bits - assert( offset+1 == size ); + assert(msg[offset] == 0x80); // this is the trailing bits + assert(offset + 1 == size); } - /*! ************************************************************************ * \brief @@ -193,26 +212,25 @@ void InterpretSEIMessage(byte* msg, int size, VideoParameters *p_Vid, Slice *pSl * ************************************************************************ */ -void interpret_spare_pic( byte* payload, int size, VideoParameters *p_Vid ) -{ - int i,x,y; - Bitstream* buf; +void interpret_spare_pic(byte *payload, int size, VideoParameters *p_Vid) { + int i, x, y; + Bitstream *buf; int bit0, bit1, bitc, no_bit0; int target_frame_num = 0; int num_spare_pics; int delta_spare_frame_num, CandidateSpareFrameNum, SpareFrameNum = 0; int ref_area_indicator; - int m, n, left, right, top, bottom,directx, directy; + int m, n, left, right, top, bottom, directx, directy; byte ***map; #ifdef WRITE_MAP_IMAGE - int symbol_size_in_bytes = p_Vid->pic_unit_bitsize_on_disk/8; - int j, k, i0, j0, tmp, kk; + int symbol_size_in_bytes = p_Vid->pic_unit_bitsize_on_disk / 8; + int j, k, i0, j0, tmp, kk; signed char filename[20] = "map_dec.yuv"; FILE *fp; - imgpel** Y; - static int old_pn=-1; + imgpel **Y; + static int old_pn = -1; static int first = 1; printf("Spare picture SEI message\n"); @@ -220,8 +238,8 @@ void interpret_spare_pic( byte* payload, int size, VideoParameters *p_Vid ) p_Dec->UsedBits = 0; - assert( payload!=NULL); - assert( p_Vid!=NULL); + assert(payload != NULL); + assert(p_Vid != NULL); buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -231,156 +249,134 @@ void interpret_spare_pic( byte* payload, int size, VideoParameters *p_Vid ) target_frame_num = ue_v("SEI: target_frame_num", buf); #ifdef WRITE_MAP_IMAGE - printf( "target_frame_num is %d\n", target_frame_num ); + printf("target_frame_num is %d\n", target_frame_num); #endif num_spare_pics = 1 + ue_v("SEI: num_spare_pics_minus1", buf); #ifdef WRITE_MAP_IMAGE - printf( "num_spare_pics is %d\n", num_spare_pics ); + printf("num_spare_pics is %d\n", num_spare_pics); #endif get_mem3D(&map, num_spare_pics, p_Vid->height >> 4, p_Vid->width >> 4); - for (i=0; iheight >> 4; y++) - for (x=0; xwidth >> 4; x++) + switch (ref_area_indicator) { + case 0: // The whole frame can serve as spare picture + for (y = 0; y < p_Vid->height >> 4; y++) + for (x = 0; x < p_Vid->width >> 4; x++) map[i][y][x] = 0; break; - case 1: // The map is not compressed - for (y=0; yheight >> 4; y++) - for (x=0; xwidth >> 4; x++) - { - map[i][y][x] = (byte) u_1("SEI: ref_mb_indicator", buf); + case 1: // The map is not compressed + for (y = 0; y < p_Vid->height >> 4; y++) + for (x = 0; x < p_Vid->width >> 4; x++) { + map[i][y][x] = (byte)u_1("SEI: ref_mb_indicator", buf); } break; - case 2: // The map is compressed - //!KS: could not check this function, description is unclear (as stated in Ed. Note) + case 2: // The map is compressed + //! KS: could not check this function, description is unclear (as + //! stated in Ed. Note) bit0 = 0; bit1 = 1; bitc = bit0; no_bit0 = -1; - x = ( (p_Vid->width >> 4) - 1 ) / 2; - y = ( (p_Vid->height >> 4) - 1 ) / 2; + x = ((p_Vid->width >> 4) - 1) / 2; + y = ((p_Vid->height >> 4) - 1) / 2; left = right = x; top = bottom = y; directx = 0; directy = 1; - for (m=0; mheight >> 4; m++) - for (n=0; nwidth >> 4; n++) - { + for (m = 0; m < p_Vid->height >> 4; m++) + for (n = 0; n < p_Vid->width >> 4; n++) { - if (no_bit0<0) - { + if (no_bit0 < 0) { no_bit0 = ue_v("SEI: zero_run_length", buf); } - if (no_bit0>0) - map[i][y][x] = (byte) bit0; - else - map[i][y][x] = (byte) bit1; + if (no_bit0 > 0) + map[i][y][x] = (byte)bit0; + else + map[i][y][x] = (byte)bit1; no_bit0--; // go to the next mb: - if ( directx == -1 && directy == 0 ) - { - if (x > left) x--; - else if (x == 0) - { + if (directx == -1 && directy == 0) { + if (x > left) + x--; + else if (x == 0) { y = bottom + 1; bottom++; directx = 1; directy = 0; - } - else if (x == left) - { + } else if (x == left) { x--; left--; directx = 0; directy = 1; } - } - else if ( directx == 1 && directy == 0 ) - { - if (x < right) x++; - else if (x == (p_Vid->width >> 4) - 1) - { + } else if (directx == 1 && directy == 0) { + if (x < right) + x++; + else if (x == (p_Vid->width >> 4) - 1) { y = top - 1; top--; directx = -1; directy = 0; - } - else if (x == right) - { + } else if (x == right) { x++; right++; directx = 0; directy = -1; } - } - else if ( directx == 0 && directy == -1 ) - { - if ( y > top) y--; - else if (y == 0) - { + } else if (directx == 0 && directy == -1) { + if (y > top) + y--; + else if (y == 0) { x = left - 1; left--; directx = 0; directy = 1; - } - else if (y == top) - { + } else if (y == top) { y--; top--; directx = -1; directy = 0; } - } - else if ( directx == 0 && directy == 1 ) - { - if (y < bottom) y++; - else if (y == (p_Vid->height >> 4) - 1) - { - x = right+1; + } else if (directx == 0 && directy == 1) { + if (y < bottom) + y++; + else if (y == (p_Vid->height >> 4) - 1) { + x = right + 1; right++; directx = 0; directy = -1; - } - else if (y == bottom) - { + } else if (y == bottom) { y++; bottom++; directx = 1; directy = 0; } } - - } break; default: - printf( "Wrong ref_area_indicator %d!\n", ref_area_indicator ); + printf("Wrong ref_area_indicator %d!\n", ref_area_indicator); exit(0); break; } @@ -389,52 +385,47 @@ void interpret_spare_pic( byte* payload, int size, VideoParameters *p_Vid ) #ifdef WRITE_MAP_IMAGE // begin to write map seq - if ( old_pn != p_Vid->number ) - { + if (old_pn != p_Vid->number) { old_pn = p_Vid->number; get_mem2Dpel(&Y, p_Vid->height, p_Vid->width); - if (first) - { - fp = fopen( filename, "wb" ); + if (first) { + fp = fopen(filename, "wb"); first = 0; - } - else - fp = fopen( filename, "ab" ); - assert( fp != NULL ); - for (kk=0; kkheight >> 4; i++) - for (j=0; j < p_Vid->width >> 4; j++) - { - tmp=map[kk][i][j]==0? p_Vid->max_pel_value_comp[0] : 0; - for (i0=0; i0<16; i0++) - for (j0=0; j0<16; j0++) - Y[i*16+i0][j*16+j0]=tmp; + } else + fp = fopen(filename, "ab"); + assert(fp != NULL); + for (kk = 0; kk < num_spare_pics; kk++) { + for (i = 0; i < p_Vid->height >> 4; i++) + for (j = 0; j < p_Vid->width >> 4; j++) { + tmp = map[kk][i][j] == 0 ? p_Vid->max_pel_value_comp[0] : 0; + for (i0 = 0; i0 < 16; i0++) + for (j0 = 0; j0 < 16; j0++) + Y[i * 16 + i0][j * 16 + j0] = tmp; } // write the map image - for (i=0; i < p_Vid->height; i++) - for (j=0; j < p_Vid->width; j++) + for (i = 0; i < p_Vid->height; i++) + for (j = 0; j < p_Vid->width; j++) fwrite(&(Y[i][j]), symbol_size_in_bytes, 1, p_out); - for (k=0; k < 2; k++) - for (i=0; i < p_Vid->height>>1; i++) - for (j=0; j < p_Vid->width>>1; j++) - fwrite(&(p_Vid->dc_pred_value_comp[1]), symbol_size_in_bytes, 1, p_out); + for (k = 0; k < 2; k++) + for (i = 0; i < p_Vid->height >> 1; i++) + for (j = 0; j < p_Vid->width >> 1; j++) + fwrite(&(p_Vid->dc_pred_value_comp[1]), symbol_size_in_bytes, 1, + p_out); } - fclose( fp ); - free_mem2Dpel( Y ); + fclose(fp); + free_mem2Dpel(Y); } // end of writing map image #undef WRITE_MAP_IMAGE #endif - free_mem3D( map ); + free_mem3D(map); free(buf); } - /*! ************************************************************************ * \brief @@ -448,11 +439,12 @@ void interpret_spare_pic( byte* payload, int size, VideoParameters *p_Vid ) * ************************************************************************ */ -void interpret_subsequence_info( byte* payload, int size, VideoParameters *p_Vid ) -{ - Bitstream* buf; - int sub_seq_layer_num, sub_seq_id, first_ref_pic_flag, leading_non_ref_pic_flag, last_pic_flag, - sub_seq_frame_num_flag, sub_seq_frame_num; +void interpret_subsequence_info(byte *payload, int size, + VideoParameters *p_Vid) { + Bitstream *buf; + int sub_seq_layer_num, sub_seq_id, first_ref_pic_flag, + leading_non_ref_pic_flag, last_pic_flag, sub_seq_frame_num_flag, + sub_seq_frame_num; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -461,27 +453,25 @@ void interpret_subsequence_info( byte* payload, int size, VideoParameters *p_Vid p_Dec->UsedBits = 0; - sub_seq_layer_num = ue_v("SEI: sub_seq_layer_num" , buf); - sub_seq_id = ue_v("SEI: sub_seq_id" , buf); - first_ref_pic_flag = u_1 ("SEI: first_ref_pic_flag" , buf); - leading_non_ref_pic_flag = u_1 ("SEI: leading_non_ref_pic_flag", buf); - last_pic_flag = u_1 ("SEI: last_pic_flag" , buf); - sub_seq_frame_num_flag = u_1 ("SEI: sub_seq_frame_num_flag" , buf); - if (sub_seq_frame_num_flag) - { - sub_seq_frame_num = ue_v("SEI: sub_seq_frame_num" , buf); + sub_seq_layer_num = ue_v("SEI: sub_seq_layer_num", buf); + sub_seq_id = ue_v("SEI: sub_seq_id", buf); + first_ref_pic_flag = u_1("SEI: first_ref_pic_flag", buf); + leading_non_ref_pic_flag = u_1("SEI: leading_non_ref_pic_flag", buf); + last_pic_flag = u_1("SEI: last_pic_flag", buf); + sub_seq_frame_num_flag = u_1("SEI: sub_seq_frame_num_flag", buf); + if (sub_seq_frame_num_flag) { + sub_seq_frame_num = ue_v("SEI: sub_seq_frame_num", buf); } #ifdef PRINT_SUBSEQUENCE_INFO printf("Sub-sequence information SEI message\n"); - printf("sub_seq_layer_num = %d\n", sub_seq_layer_num ); + printf("sub_seq_layer_num = %d\n", sub_seq_layer_num); printf("sub_seq_id = %d\n", sub_seq_id); printf("first_ref_pic_flag = %d\n", first_ref_pic_flag); printf("leading_non_ref_pic_flag = %d\n", leading_non_ref_pic_flag); printf("last_pic_flag = %d\n", last_pic_flag); printf("sub_seq_frame_num_flag = %d\n", sub_seq_frame_num_flag); - if (sub_seq_frame_num_flag) - { + if (sub_seq_frame_num_flag) { printf("sub_seq_frame_num = %d\n", sub_seq_frame_num); } #endif @@ -505,10 +495,11 @@ void interpret_subsequence_info( byte* payload, int size, VideoParameters *p_Vid * ************************************************************************ */ -void interpret_subsequence_layer_characteristics_info( byte* payload, int size, VideoParameters *p_Vid ) -{ - Bitstream* buf; - long num_sub_layers, accurate_statistics_flag, average_bit_rate, average_frame_rate; +void interpret_subsequence_layer_characteristics_info(byte *payload, int size, + VideoParameters *p_Vid) { + Bitstream *buf; + long num_sub_layers, accurate_statistics_flag, average_bit_rate, + average_frame_rate; int i; buf = malloc(sizeof(Bitstream)); @@ -525,22 +516,22 @@ void interpret_subsequence_layer_characteristics_info( byte* payload, int size, printf("num_sub_layers_minus1 = %d\n", num_sub_layers - 1); #endif - for (i=0; ibitstream_length = size; @@ -570,35 +563,33 @@ void interpret_subsequence_characteristics_info( byte* payload, int size, VideoP p_Dec->UsedBits = 0; sub_seq_layer_num = ue_v("SEI: sub_seq_layer_num", buf); - sub_seq_id = ue_v("SEI: sub_seq_id", buf); - duration_flag = u_1 ("SEI: duration_flag", buf); + sub_seq_id = ue_v("SEI: sub_seq_id", buf); + duration_flag = u_1("SEI: duration_flag", buf); #ifdef PRINT_SUBSEQUENCE_CHAR printf("Sub-sequence characteristics SEI message\n"); - printf("sub_seq_layer_num = %d\n", sub_seq_layer_num ); + printf("sub_seq_layer_num = %d\n", sub_seq_layer_num); printf("sub_seq_id = %d\n", sub_seq_id); printf("duration_flag = %d\n", duration_flag); #endif - if ( duration_flag ) - { - sub_seq_duration = u_v (32, "SEI: duration_flag", buf); + if (duration_flag) { + sub_seq_duration = u_v(32, "SEI: duration_flag", buf); #ifdef PRINT_SUBSEQUENCE_CHAR printf("sub_seq_duration = %ld\n", sub_seq_duration); #endif } - average_rate_flag = u_1 ("SEI: average_rate_flag", buf); + average_rate_flag = u_1("SEI: average_rate_flag", buf); #ifdef PRINT_SUBSEQUENCE_CHAR printf("average_rate_flag = %d\n", average_rate_flag); #endif - if ( average_rate_flag ) - { - accurate_statistics_flag = u_1 ( "SEI: accurate_statistics_flag", buf); - average_bit_rate = u_v (16, "SEI: average_bit_rate", buf); - average_frame_rate = u_v (16, "SEI: average_frame_rate", buf); + if (average_rate_flag) { + accurate_statistics_flag = u_1("SEI: accurate_statistics_flag", buf); + average_bit_rate = u_v(16, "SEI: average_bit_rate", buf); + average_frame_rate = u_v(16, "SEI: average_frame_rate", buf); #ifdef PRINT_SUBSEQUENCE_CHAR printf("accurate_statistics_flag = %d\n", accurate_statistics_flag); @@ -607,17 +598,16 @@ void interpret_subsequence_characteristics_info( byte* payload, int size, VideoP #endif } - num_referenced_subseqs = ue_v("SEI: num_referenced_subseqs", buf); + num_referenced_subseqs = ue_v("SEI: num_referenced_subseqs", buf); #ifdef PRINT_SUBSEQUENCE_CHAR printf("num_referenced_subseqs = %d\n", num_referenced_subseqs); #endif - for (i=0; iUsedBits = 0; - scene_id = ue_v("SEI: scene_id" , buf); + scene_id = ue_v("SEI: scene_id", buf); scene_transition_type = ue_v("SEI: scene_transition_type", buf); - if ( scene_transition_type > 3 ) - { - second_scene_id = ue_v("SEI: scene_transition_type", buf);; + if (scene_transition_type > 3) { + second_scene_id = ue_v("SEI: scene_transition_type", buf); + ; } #ifdef PRINT_SCENE_INFORMATION printf("Scene information SEI message\n"); printf("scene_transition_type = %d\n", scene_transition_type); printf("scene_id = %d\n", scene_id); - if ( scene_transition_type > 3 ) - { + if (scene_transition_type > 3) { printf("second_scene_id = %d\n", second_scene_id); } #endif - free( buf ); + free(buf); #ifdef PRINT_SCENE_INFORMATION #undef PRINT_SCENE_INFORMATION #endif } - /*! ************************************************************************ * \brief @@ -694,28 +681,23 @@ void interpret_scene_information( byte* payload, int size, VideoParameters *p_Vi * ************************************************************************ */ -void interpret_filler_payload_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_filler_payload_info(byte *payload, int size, + VideoParameters *p_Vid) { int payload_cnt = 0; - while (payload_cnt=16); + assert(size >= 16); - for (offset = 0; offset < 16; offset++) - { + for (offset = 0; offset < 16; offset++) { #ifdef PRINT_USER_DATA_UNREGISTERED_INFO - printf("%02x",payload[offset]); + printf("%02x", payload[offset]); #endif } #ifdef PRINT_USER_DATA_UNREGISTERED_INFO - printf("\n"); + printf("\n"); #endif - while (offset < size) - { + while (offset < size) { payload_byte = payload[offset]; - offset ++; + offset++; #ifdef PRINT_USER_DATA_UNREGISTERED_INFO printf("Unreg data payload_byte = %d\n", payload_byte); #endif @@ -773,7 +752,6 @@ void interpret_user_data_unregistered_info( byte* payload, int size, VideoParame #endif } - /*! ************************************************************************ * \brief @@ -787,10 +765,11 @@ void interpret_user_data_unregistered_info( byte* payload, int size, VideoParame * ************************************************************************ */ -void interpret_user_data_registered_itu_t_t35_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_user_data_registered_itu_t_t35_info(byte *payload, int size, + VideoParameters *p_Vid) { int offset = 0; - byte itu_t_t35_country_code, itu_t_t35_country_code_extension_byte, payload_byte; + byte itu_t_t35_country_code, itu_t_t35_country_code_extension_byte, + payload_byte; itu_t_t35_country_code = payload[offset]; offset++; @@ -798,18 +777,17 @@ void interpret_user_data_registered_itu_t_t35_info( byte* payload, int size, Vid printf("User data registered by ITU-T T.35 SEI message\n"); printf(" itu_t_t35_country_code = %d \n", itu_t_t35_country_code); #endif - if(itu_t_t35_country_code == 0xFF) - { + if (itu_t_t35_country_code == 0xFF) { itu_t_t35_country_code_extension_byte = payload[offset]; offset++; #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO - printf(" ITU_T_T35_COUNTRY_CODE_EXTENSION_BYTE %d \n", itu_t_t35_country_code_extension_byte); + printf(" ITU_T_T35_COUNTRY_CODE_EXTENSION_BYTE %d \n", + itu_t_t35_country_code_extension_byte); #endif } - while (offset < size) - { + while (offset < size) { payload_byte = payload[offset]; - offset ++; + offset++; #ifdef PRINT_USER_DATA_REGISTERED_ITU_T_T35_INFO printf("itu_t_t35 payload_byte = %d\n", payload_byte); #endif @@ -819,7 +797,6 @@ void interpret_user_data_registered_itu_t_t35_info( byte* payload, int size, Vid #endif } - /*! ************************************************************************ * \brief @@ -833,15 +810,15 @@ void interpret_user_data_registered_itu_t_t35_info( byte* payload, int size, Vid * ************************************************************************ */ -void interpret_pan_scan_rect_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_pan_scan_rect_info(byte *payload, int size, + VideoParameters *p_Vid) { int pan_scan_rect_cancel_flag; int pan_scan_cnt_minus1, i; int pan_scan_rect_repetition_period; int pan_scan_rect_id, pan_scan_rect_left_offset, pan_scan_rect_right_offset; int pan_scan_rect_top_offset, pan_scan_rect_bottom_offset; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -853,15 +830,14 @@ void interpret_pan_scan_rect_info( byte* payload, int size, VideoParameters *p_V pan_scan_rect_id = ue_v("SEI: pan_scan_rect_id", buf); pan_scan_rect_cancel_flag = u_1("SEI: pan_scan_rect_cancel_flag", buf); - if (!pan_scan_rect_cancel_flag) - { + if (!pan_scan_rect_cancel_flag) { pan_scan_cnt_minus1 = ue_v("SEI: pan_scan_cnt_minus1", buf); - for (i = 0; i <= pan_scan_cnt_minus1; i++) - { - pan_scan_rect_left_offset = se_v("SEI: pan_scan_rect_left_offset" , buf); - pan_scan_rect_right_offset = se_v("SEI: pan_scan_rect_right_offset" , buf); - pan_scan_rect_top_offset = se_v("SEI: pan_scan_rect_top_offset" , buf); - pan_scan_rect_bottom_offset = se_v("SEI: pan_scan_rect_bottom_offset", buf); + for (i = 0; i <= pan_scan_cnt_minus1; i++) { + pan_scan_rect_left_offset = se_v("SEI: pan_scan_rect_left_offset", buf); + pan_scan_rect_right_offset = se_v("SEI: pan_scan_rect_right_offset", buf); + pan_scan_rect_top_offset = se_v("SEI: pan_scan_rect_top_offset", buf); + pan_scan_rect_bottom_offset = + se_v("SEI: pan_scan_rect_bottom_offset", buf); #ifdef PRINT_PAN_SCAN_RECT printf("Pan scan rectangle SEI message %d/%d\n", i, pan_scan_cnt_minus1); printf("pan_scan_rect_id = %d\n", pan_scan_rect_id); @@ -871,16 +847,16 @@ void interpret_pan_scan_rect_info( byte* payload, int size, VideoParameters *p_V printf("pan_scan_rect_bottom_offset = %d\n", pan_scan_rect_bottom_offset); #endif } - pan_scan_rect_repetition_period = ue_v("SEI: pan_scan_rect_repetition_period", buf); + pan_scan_rect_repetition_period = + ue_v("SEI: pan_scan_rect_repetition_period", buf); } - free (buf); + free(buf); #ifdef PRINT_PAN_SCAN_RECT #undef PRINT_PAN_SCAN_RECT #endif } - /*! ************************************************************************ * \brief @@ -894,13 +870,12 @@ void interpret_pan_scan_rect_info( byte* payload, int size, VideoParameters *p_V * ************************************************************************ */ -void interpret_recovery_point_info( byte* payload, int size, VideoParameters *p_Vid ) -{ - int recovery_frame_cnt, exact_match_flag, broken_link_flag, changing_slice_group_idc; - - - Bitstream* buf; +void interpret_recovery_point_info(byte *payload, int size, + VideoParameters *p_Vid) { + int recovery_frame_cnt, exact_match_flag, broken_link_flag, + changing_slice_group_idc; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -909,10 +884,10 @@ void interpret_recovery_point_info( byte* payload, int size, VideoParameters *p_ p_Dec->UsedBits = 0; - recovery_frame_cnt = ue_v( "SEI: recovery_frame_cnt" , buf); - exact_match_flag = u_1 ( "SEI: exact_match_flag" , buf); - broken_link_flag = u_1 ( "SEI: broken_link_flag" , buf); - changing_slice_group_idc = u_v ( 2, "SEI: changing_slice_group_idc", buf); + recovery_frame_cnt = ue_v("SEI: recovery_frame_cnt", buf); + exact_match_flag = u_1("SEI: exact_match_flag", buf); + broken_link_flag = u_1("SEI: broken_link_flag", buf); + changing_slice_group_idc = u_v(2, "SEI: changing_slice_group_idc", buf); p_Vid->recovery_point = 1; p_Vid->recovery_frame_cnt = recovery_frame_cnt; @@ -924,13 +899,12 @@ void interpret_recovery_point_info( byte* payload, int size, VideoParameters *p_ printf("broken_link_flag = %d\n", broken_link_flag); printf("changing_slice_group_idc = %d\n", changing_slice_group_idc); #endif - free (buf); + free(buf); #ifdef PRINT_RECOVERY_POINT #undef PRINT_RECOVERY_POINT #endif } - /*! ************************************************************************ * \brief @@ -944,18 +918,19 @@ void interpret_recovery_point_info( byte* payload, int size, VideoParameters *p_ * ************************************************************************ */ -void interpret_dec_ref_pic_marking_repetition_info( byte* payload, int size, VideoParameters *p_Vid, Slice *pSlice ) -{ +void interpret_dec_ref_pic_marking_repetition_info(byte *payload, int size, + VideoParameters *p_Vid, + Slice *pSlice) { int original_idr_flag, original_frame_num; int original_field_pic_flag, original_bottom_field_flag; DecRefPicMarking_t *tmp_drpm; DecRefPicMarking_t *old_drpm; - int old_idr_flag , old_no_output_of_prior_pics_flag, old_long_term_reference_flag , old_adaptive_ref_pic_buffering_flag; + int old_idr_flag, old_no_output_of_prior_pics_flag, + old_long_term_reference_flag, old_adaptive_ref_pic_buffering_flag; - - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -964,15 +939,13 @@ void interpret_dec_ref_pic_marking_repetition_info( byte* payload, int size, Vid p_Dec->UsedBits = 0; - original_idr_flag = u_1 ( "SEI: original_idr_flag" , buf); - original_frame_num = ue_v( "SEI: original_frame_num" , buf); + original_idr_flag = u_1("SEI: original_idr_flag", buf); + original_frame_num = ue_v("SEI: original_frame_num", buf); - if ( !p_Vid->active_sps->frame_mbs_only_flag ) - { - original_field_pic_flag = u_1 ( "SEI: original_field_pic_flag", buf); - if ( original_field_pic_flag ) - { - original_bottom_field_flag = u_1 ( "SEI: original_bottom_field_flag", buf); + if (!p_Vid->active_sps->frame_mbs_only_flag) { + original_field_pic_flag = u_1("SEI: original_field_pic_flag", buf); + if (original_field_pic_flag) { + original_bottom_field_flag = u_1("SEI: original_bottom_field_flag", buf); } } @@ -980,26 +953,27 @@ void interpret_dec_ref_pic_marking_repetition_info( byte* payload, int size, Vid printf("Decoded Picture Buffer Management Repetition SEI message\n"); printf("original_idr_flag = %d\n", original_idr_flag); printf("original_frame_num = %d\n", original_frame_num); - if ( active_sps->frame_mbs_only_flag ) - { + if (active_sps->frame_mbs_only_flag) { printf("original_field_pic_flag = %d\n", original_field_pic_flag); - if ( original_field_pic_flag ) - { + if (original_field_pic_flag) { printf("original_bottom_field_flag = %d\n", original_bottom_field_flag); } } #endif - // we need to save everything that is probably overwritten in dec_ref_pic_marking() + // we need to save everything that is probably overwritten in + // dec_ref_pic_marking() old_drpm = pSlice->dec_ref_pic_marking_buffer; - old_idr_flag = pSlice->idr_flag; //p_Vid->idr_flag; + old_idr_flag = pSlice->idr_flag; // p_Vid->idr_flag; - old_no_output_of_prior_pics_flag = pSlice->no_output_of_prior_pics_flag; //p_Vid->no_output_of_prior_pics_flag; + old_no_output_of_prior_pics_flag = + pSlice + ->no_output_of_prior_pics_flag; // p_Vid->no_output_of_prior_pics_flag; old_long_term_reference_flag = pSlice->long_term_reference_flag; old_adaptive_ref_pic_buffering_flag = pSlice->adaptive_ref_pic_buffering_flag; // set new initial values - //p_Vid->idr_flag = original_idr_flag; + // p_Vid->idr_flag = original_idr_flag; pSlice->idr_flag = original_idr_flag; pSlice->dec_ref_pic_marking_buffer = NULL; @@ -1007,36 +981,37 @@ void interpret_dec_ref_pic_marking_repetition_info( byte* payload, int size, Vid // print out decoded values #ifdef PRINT_DEC_REF_PIC_MARKING - if (p_Vid->idr_flag) - { - printf("no_output_of_prior_pics_flag = %d\n", p_Vid->no_output_of_prior_pics_flag); - printf("long_term_reference_flag = %d\n", p_Vid->long_term_reference_flag); - } - else - { - printf("adaptive_ref_pic_buffering_flag = %d\n", p_Vid->adaptive_ref_pic_buffering_flag); - if (p_Vid->adaptive_ref_pic_buffering_flag) - { - tmp_drpm=p_Vid->dec_ref_pic_marking_buffer; - while (tmp_drpm != NULL) - { - printf("memory_management_control_operation = %d\n", tmp_drpm->memory_management_control_operation); + if (p_Vid->idr_flag) { + printf("no_output_of_prior_pics_flag = %d\n", + p_Vid->no_output_of_prior_pics_flag); + printf("long_term_reference_flag = %d\n", + p_Vid->long_term_reference_flag); + } else { + printf("adaptive_ref_pic_buffering_flag = %d\n", + p_Vid->adaptive_ref_pic_buffering_flag); + if (p_Vid->adaptive_ref_pic_buffering_flag) { + tmp_drpm = p_Vid->dec_ref_pic_marking_buffer; + while (tmp_drpm != NULL) { + printf("memory_management_control_operation = %d\n", + tmp_drpm->memory_management_control_operation); - if ((tmp_drpm->memory_management_control_operation==1)||(tmp_drpm->memory_management_control_operation==3)) - { - printf("difference_of_pic_nums_minus1 = %d\n", tmp_drpm->difference_of_pic_nums_minus1); + if ((tmp_drpm->memory_management_control_operation == 1) || + (tmp_drpm->memory_management_control_operation == 3)) { + printf("difference_of_pic_nums_minus1 = %d\n", + tmp_drpm->difference_of_pic_nums_minus1); } - if (tmp_drpm->memory_management_control_operation==2) - { - printf("long_term_pic_num = %d\n", tmp_drpm->long_term_pic_num); + if (tmp_drpm->memory_management_control_operation == 2) { + printf("long_term_pic_num = %d\n", + tmp_drpm->long_term_pic_num); } - if ((tmp_drpm->memory_management_control_operation==3)||(tmp_drpm->memory_management_control_operation==6)) - { - printf("long_term_frame_idx = %d\n", tmp_drpm->long_term_frame_idx); + if ((tmp_drpm->memory_management_control_operation == 3) || + (tmp_drpm->memory_management_control_operation == 6)) { + printf("long_term_frame_idx = %d\n", + tmp_drpm->long_term_frame_idx); } - if (tmp_drpm->memory_management_control_operation==4) - { - printf("max_long_term_pic_idx_plus1 = %d\n", tmp_drpm->max_long_term_frame_idx_plus1); + if (tmp_drpm->memory_management_control_operation == 4) { + printf("max_long_term_pic_idx_plus1 = %d\n", + tmp_drpm->max_long_term_frame_idx_plus1); } tmp_drpm = tmp_drpm->Next; } @@ -1044,12 +1019,11 @@ void interpret_dec_ref_pic_marking_repetition_info( byte* payload, int size, Vid } #endif - while (pSlice->dec_ref_pic_marking_buffer) - { - tmp_drpm=pSlice->dec_ref_pic_marking_buffer; + while (pSlice->dec_ref_pic_marking_buffer) { + tmp_drpm = pSlice->dec_ref_pic_marking_buffer; - pSlice->dec_ref_pic_marking_buffer=tmp_drpm->Next; - free (tmp_drpm); + pSlice->dec_ref_pic_marking_buffer = tmp_drpm->Next; + free(tmp_drpm); } // restore old values in p_Vid @@ -1060,7 +1034,7 @@ void interpret_dec_ref_pic_marking_repetition_info( byte* payload, int size, Vid pSlice->long_term_reference_flag = old_long_term_reference_flag; pSlice->adaptive_ref_pic_buffering_flag = old_adaptive_ref_pic_buffering_flag; - free (buf); + free(buf); #ifdef PRINT_DEC_REF_PIC_MARKING #undef PRINT_DEC_REF_PIC_MARKING #endif @@ -1079,29 +1053,30 @@ void interpret_dec_ref_pic_marking_repetition_info( byte* payload, int size, Vid * ************************************************************************ */ -void interpret_full_frame_freeze_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_full_frame_freeze_info(byte *payload, int size, + VideoParameters *p_Vid) { int full_frame_freeze_repetition_period; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; buf->streamBuffer = payload; buf->frame_bitoffset = 0; - full_frame_freeze_repetition_period = ue_v( "SEI: full_frame_freeze_repetition_period" , buf); + full_frame_freeze_repetition_period = + ue_v("SEI: full_frame_freeze_repetition_period", buf); #ifdef PRINT_FULL_FRAME_FREEZE_INFO - printf("full_frame_freeze_repetition_period = %d\n", full_frame_freeze_repetition_period); + printf("full_frame_freeze_repetition_period = %d\n", + full_frame_freeze_repetition_period); #endif - free (buf); + free(buf); #ifdef PRINT_FULL_FRAME_FREEZE_INFO #undef PRINT_FULL_FRAME_FREEZE_INFO #endif } - /*! ************************************************************************ * \brief @@ -1115,13 +1090,13 @@ void interpret_full_frame_freeze_info( byte* payload, int size, VideoParameters * ************************************************************************ */ -void interpret_full_frame_freeze_release_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_full_frame_freeze_release_info(byte *payload, int size, + VideoParameters *p_Vid) { #ifdef PRINT_FULL_FRAME_FREEZE_RELEASE_INFO printf("Full-frame freeze release SEI message\n"); - if (size) - { - printf("payload size of this message should be zero, but is %d bytes.\n", size); + if (size) { + printf("payload size of this message should be zero, but is %d bytes.\n", + size); } #endif @@ -1143,11 +1118,11 @@ void interpret_full_frame_freeze_release_info( byte* payload, int size, VideoPar * ************************************************************************ */ -void interpret_full_frame_snapshot_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_full_frame_snapshot_info(byte *payload, int size, + VideoParameters *p_Vid) { int snapshot_id; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -1162,7 +1137,7 @@ void interpret_full_frame_snapshot_info( byte* payload, int size, VideoParameter printf("Full-frame snapshot SEI message\n"); printf("snapshot_id = %d\n", snapshot_id); #endif - free (buf); + free(buf); #ifdef PRINT_FULL_FRAME_SNAPSHOT_INFO #undef PRINT_FULL_FRAME_SNAPSHOT_INFO #endif @@ -1181,11 +1156,11 @@ void interpret_full_frame_snapshot_info( byte* payload, int size, VideoParameter * ************************************************************************ */ -void interpret_progressive_refinement_start_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_progressive_refinement_start_info(byte *payload, int size, + VideoParameters *p_Vid) { int progressive_refinement_id, num_refinement_steps_minus1; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -1194,7 +1169,7 @@ void interpret_progressive_refinement_start_info( byte* payload, int size, Video p_Dec->UsedBits = 0; - progressive_refinement_id = ue_v("SEI: progressive_refinement_id" , buf); + progressive_refinement_id = ue_v("SEI: progressive_refinement_id", buf); num_refinement_steps_minus1 = ue_v("SEI: num_refinement_steps_minus1", buf); #ifdef PRINT_PROGRESSIVE_REFINEMENT_START_INFO @@ -1202,13 +1177,12 @@ void interpret_progressive_refinement_start_info( byte* payload, int size, Video printf("progressive_refinement_id = %d\n", progressive_refinement_id); printf("num_refinement_steps_minus1 = %d\n", num_refinement_steps_minus1); #endif - free (buf); + free(buf); #ifdef PRINT_PROGRESSIVE_REFINEMENT_START_INFO #undef PRINT_PROGRESSIVE_REFINEMENT_START_INFO #endif } - /*! ************************************************************************ * \brief @@ -1222,11 +1196,11 @@ void interpret_progressive_refinement_start_info( byte* payload, int size, Video * ************************************************************************ */ -void interpret_progressive_refinement_end_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_progressive_refinement_end_info(byte *payload, int size, + VideoParameters *p_Vid) { int progressive_refinement_id; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -1235,19 +1209,18 @@ void interpret_progressive_refinement_end_info( byte* payload, int size, VideoPa p_Dec->UsedBits = 0; - progressive_refinement_id = ue_v("SEI: progressive_refinement_id" , buf); + progressive_refinement_id = ue_v("SEI: progressive_refinement_id", buf); #ifdef PRINT_PROGRESSIVE_REFINEMENT_END_INFO printf("Progressive refinement segment end SEI message\n"); printf("progressive_refinement_id = %d\n", progressive_refinement_id); #endif - free (buf); + free(buf); #ifdef PRINT_PROGRESSIVE_REFINEMENT_END_INFO #undef PRINT_PROGRESSIVE_REFINEMENT_END_INFO #endif } - /*! ************************************************************************ * \brief @@ -1261,13 +1234,14 @@ void interpret_progressive_refinement_end_info( byte* payload, int size, VideoPa * ************************************************************************ */ -void interpret_motion_constrained_slice_group_set_info( byte* payload, int size, VideoParameters *p_Vid ) -{ - int num_slice_groups_minus1, slice_group_id, exact_match_flag, pan_scan_rect_flag, pan_scan_rect_id; +void interpret_motion_constrained_slice_group_set_info(byte *payload, int size, + VideoParameters *p_Vid) { + int num_slice_groups_minus1, slice_group_id, exact_match_flag, + pan_scan_rect_flag, pan_scan_rect_id; int i; int sliceGroupSize; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -1276,39 +1250,37 @@ void interpret_motion_constrained_slice_group_set_info( byte* payload, int size, p_Dec->UsedBits = 0; - num_slice_groups_minus1 = ue_v("SEI: num_slice_groups_minus1" , buf); - sliceGroupSize = CeilLog2( num_slice_groups_minus1 + 1 ); + num_slice_groups_minus1 = ue_v("SEI: num_slice_groups_minus1", buf); + sliceGroupSize = CeilLog2(num_slice_groups_minus1 + 1); #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO printf("Motion-constrained slice group set SEI message\n"); printf("num_slice_groups_minus1 = %d\n", num_slice_groups_minus1); #endif - for (i=0; i<=num_slice_groups_minus1;i++) - { + for (i = 0; i <= num_slice_groups_minus1; i++) { - slice_group_id = u_v (sliceGroupSize, "SEI: slice_group_id" , buf) ; + slice_group_id = u_v(sliceGroupSize, "SEI: slice_group_id", buf); #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO printf("slice_group_id = %d\n", slice_group_id); #endif } - exact_match_flag = u_1("SEI: exact_match_flag" , buf); - pan_scan_rect_flag = u_1("SEI: pan_scan_rect_flag" , buf); + exact_match_flag = u_1("SEI: exact_match_flag", buf); + pan_scan_rect_flag = u_1("SEI: pan_scan_rect_flag", buf); #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO printf("exact_match_flag = %d\n", exact_match_flag); printf("pan_scan_rect_flag = %d\n", pan_scan_rect_flag); #endif - if (pan_scan_rect_flag) - { - pan_scan_rect_id = ue_v("SEI: pan_scan_rect_id" , buf); + if (pan_scan_rect_flag) { + pan_scan_rect_id = ue_v("SEI: pan_scan_rect_id", buf); #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO printf("pan_scan_rect_id = %d\n", pan_scan_rect_id); #endif } - free (buf); + free(buf); #ifdef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO #undef PRINT_MOTION_CONST_SLICE_GROUP_SET_INFO #endif @@ -1327,11 +1299,13 @@ void interpret_motion_constrained_slice_group_set_info( byte* payload, int size, * ************************************************************************ */ -void interpret_film_grain_characteristics_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_film_grain_characteristics_info(byte *payload, int size, + VideoParameters *p_Vid) { int film_grain_characteristics_cancel_flag; int model_id, separate_colour_description_present_flag; - int film_grain_bit_depth_luma_minus8, film_grain_bit_depth_chroma_minus8, film_grain_full_range_flag, film_grain_colour_primaries, film_grain_transfer_characteristics, film_grain_matrix_coefficients; + int film_grain_bit_depth_luma_minus8, film_grain_bit_depth_chroma_minus8, + film_grain_full_range_flag, film_grain_colour_primaries, + film_grain_transfer_characteristics, film_grain_matrix_coefficients; int blending_mode_id, log2_scale_factor, comp_model_present_flag[3]; int num_intensity_intervals_minus1, num_model_values_minus1; int intensity_interval_lower_bound, intensity_interval_upper_bound; @@ -1340,89 +1314,105 @@ void interpret_film_grain_characteristics_info( byte* payload, int size, VideoPa int c, i, j; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; buf->streamBuffer = payload; buf->frame_bitoffset = 0; - film_grain_characteristics_cancel_flag = u_1("SEI: film_grain_characteristics_cancel_flag", buf); + film_grain_characteristics_cancel_flag = + u_1("SEI: film_grain_characteristics_cancel_flag", buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO - printf("film_grain_characteristics_cancel_flag = %d\n", film_grain_characteristics_cancel_flag); + printf("film_grain_characteristics_cancel_flag = %d\n", + film_grain_characteristics_cancel_flag); #endif - if(!film_grain_characteristics_cancel_flag) - { + if (!film_grain_characteristics_cancel_flag) { - model_id = u_v(2, "SEI: model_id", buf); - separate_colour_description_present_flag = u_1("SEI: separate_colour_description_present_flag", buf); + model_id = u_v(2, "SEI: model_id", buf); + separate_colour_description_present_flag = + u_1("SEI: separate_colour_description_present_flag", buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO printf("model_id = %d\n", model_id); - printf("separate_colour_description_present_flag = %d\n", separate_colour_description_present_flag); + printf("separate_colour_description_present_flag = %d\n", + separate_colour_description_present_flag); #endif - if (separate_colour_description_present_flag) - { - film_grain_bit_depth_luma_minus8 = u_v(3, "SEI: film_grain_bit_depth_luma_minus8", buf); - film_grain_bit_depth_chroma_minus8 = u_v(3, "SEI: film_grain_bit_depth_chroma_minus8", buf); - film_grain_full_range_flag = u_v(1, "SEI: film_grain_full_range_flag", buf); - film_grain_colour_primaries = u_v(8, "SEI: film_grain_colour_primaries", buf); - film_grain_transfer_characteristics = u_v(8, "SEI: film_grain_transfer_characteristics", buf); - film_grain_matrix_coefficients = u_v(8, "SEI: film_grain_matrix_coefficients", buf); + if (separate_colour_description_present_flag) { + film_grain_bit_depth_luma_minus8 = + u_v(3, "SEI: film_grain_bit_depth_luma_minus8", buf); + film_grain_bit_depth_chroma_minus8 = + u_v(3, "SEI: film_grain_bit_depth_chroma_minus8", buf); + film_grain_full_range_flag = + u_v(1, "SEI: film_grain_full_range_flag", buf); + film_grain_colour_primaries = + u_v(8, "SEI: film_grain_colour_primaries", buf); + film_grain_transfer_characteristics = + u_v(8, "SEI: film_grain_transfer_characteristics", buf); + film_grain_matrix_coefficients = + u_v(8, "SEI: film_grain_matrix_coefficients", buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO - printf("film_grain_bit_depth_luma_minus8 = %d\n", film_grain_bit_depth_luma_minus8); - printf("film_grain_bit_depth_chroma_minus8 = %d\n", film_grain_bit_depth_chroma_minus8); + printf("film_grain_bit_depth_luma_minus8 = %d\n", + film_grain_bit_depth_luma_minus8); + printf("film_grain_bit_depth_chroma_minus8 = %d\n", + film_grain_bit_depth_chroma_minus8); printf("film_grain_full_range_flag = %d\n", film_grain_full_range_flag); printf("film_grain_colour_primaries = %d\n", film_grain_colour_primaries); - printf("film_grain_transfer_characteristics = %d\n", film_grain_transfer_characteristics); - printf("film_grain_matrix_coefficients = %d\n", film_grain_matrix_coefficients); + printf("film_grain_transfer_characteristics = %d\n", + film_grain_transfer_characteristics); + printf("film_grain_matrix_coefficients = %d\n", + film_grain_matrix_coefficients); #endif } - blending_mode_id = u_v(2, "SEI: blending_mode_id", buf); - log2_scale_factor = u_v(4, "SEI: log2_scale_factor", buf); + blending_mode_id = u_v(2, "SEI: blending_mode_id", buf); + log2_scale_factor = u_v(4, "SEI: log2_scale_factor", buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO printf("blending_mode_id = %d\n", blending_mode_id); printf("log2_scale_factor = %d\n", log2_scale_factor); #endif - for (c = 0; c < 3; c ++) - { - comp_model_present_flag[c] = u_1("SEI: comp_model_present_flag", buf); + for (c = 0; c < 3; c++) { + comp_model_present_flag[c] = u_1("SEI: comp_model_present_flag", buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO printf("comp_model_present_flag = %d\n", comp_model_present_flag[c]); #endif } - for (c = 0; c < 3; c ++) - if (comp_model_present_flag[c]) - { - num_intensity_intervals_minus1 = u_v(8, "SEI: num_intensity_intervals_minus1", buf); - num_model_values_minus1 = u_v(3, "SEI: num_model_values_minus1", buf); + for (c = 0; c < 3; c++) + if (comp_model_present_flag[c]) { + num_intensity_intervals_minus1 = + u_v(8, "SEI: num_intensity_intervals_minus1", buf); + num_model_values_minus1 = u_v(3, "SEI: num_model_values_minus1", buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO - printf("num_intensity_intervals_minus1 = %d\n", num_intensity_intervals_minus1); + printf("num_intensity_intervals_minus1 = %d\n", + num_intensity_intervals_minus1); printf("num_model_values_minus1 = %d\n", num_model_values_minus1); #endif - for (i = 0; i <= num_intensity_intervals_minus1; i ++) - { - intensity_interval_lower_bound = u_v(8, "SEI: intensity_interval_lower_bound", buf); - intensity_interval_upper_bound = u_v(8, "SEI: intensity_interval_upper_bound", buf); + for (i = 0; i <= num_intensity_intervals_minus1; i++) { + intensity_interval_lower_bound = + u_v(8, "SEI: intensity_interval_lower_bound", buf); + intensity_interval_upper_bound = + u_v(8, "SEI: intensity_interval_upper_bound", buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO - printf("intensity_interval_lower_bound = %d\n", intensity_interval_lower_bound); - printf("intensity_interval_upper_bound = %d\n", intensity_interval_upper_bound); + printf("intensity_interval_lower_bound = %d\n", + intensity_interval_lower_bound); + printf("intensity_interval_upper_bound = %d\n", + intensity_interval_upper_bound); #endif - for (j = 0; j <= num_model_values_minus1; j++) - { - comp_model_value = se_v("SEI: comp_model_value", buf); + for (j = 0; j <= num_model_values_minus1; j++) { + comp_model_value = se_v("SEI: comp_model_value", buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO printf("comp_model_value = %d\n", comp_model_value); #endif } } } - film_grain_characteristics_repetition_period = ue_v("SEI: film_grain_characteristics_repetition_period", buf); + film_grain_characteristics_repetition_period = + ue_v("SEI: film_grain_characteristics_repetition_period", buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO - printf("film_grain_characteristics_repetition_period = %d\n", film_grain_characteristics_repetition_period); + printf("film_grain_characteristics_repetition_period = %d\n", + film_grain_characteristics_repetition_period); #endif } - free (buf); + free(buf); #ifdef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO #undef PRINT_FILM_GRAIN_CHARACTERISTICS_INFO #endif @@ -1441,35 +1431,44 @@ void interpret_film_grain_characteristics_info( byte* payload, int size, VideoPa * ************************************************************************ */ -void interpret_deblocking_filter_display_preference_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_deblocking_filter_display_preference_info( + byte *payload, int size, VideoParameters *p_Vid) { int deblocking_display_preference_cancel_flag; - int display_prior_to_deblocking_preferred_flag, dec_frame_buffering_constraint_flag, deblocking_display_preference_repetition_period; + int display_prior_to_deblocking_preferred_flag, + dec_frame_buffering_constraint_flag, + deblocking_display_preference_repetition_period; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; buf->streamBuffer = payload; buf->frame_bitoffset = 0; - deblocking_display_preference_cancel_flag = u_1("SEI: deblocking_display_preference_cancel_flag", buf); + deblocking_display_preference_cancel_flag = + u_1("SEI: deblocking_display_preference_cancel_flag", buf); #ifdef PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO - printf("deblocking_display_preference_cancel_flag = %d\n", deblocking_display_preference_cancel_flag); + printf("deblocking_display_preference_cancel_flag = %d\n", + deblocking_display_preference_cancel_flag); #endif - if(!deblocking_display_preference_cancel_flag) - { - display_prior_to_deblocking_preferred_flag = u_1("SEI: display_prior_to_deblocking_preferred_flag", buf); - dec_frame_buffering_constraint_flag = u_1("SEI: dec_frame_buffering_constraint_flag", buf); - deblocking_display_preference_repetition_period = ue_v("SEI: deblocking_display_preference_repetition_period", buf); + if (!deblocking_display_preference_cancel_flag) { + display_prior_to_deblocking_preferred_flag = + u_1("SEI: display_prior_to_deblocking_preferred_flag", buf); + dec_frame_buffering_constraint_flag = + u_1("SEI: dec_frame_buffering_constraint_flag", buf); + deblocking_display_preference_repetition_period = + ue_v("SEI: deblocking_display_preference_repetition_period", buf); #ifdef PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO - printf("display_prior_to_deblocking_preferred_flag = %d\n", display_prior_to_deblocking_preferred_flag); - printf("dec_frame_buffering_constraint_flag = %d\n", dec_frame_buffering_constraint_flag); - printf("deblocking_display_preference_repetition_period = %d\n", deblocking_display_preference_repetition_period); + printf("display_prior_to_deblocking_preferred_flag = %d\n", + display_prior_to_deblocking_preferred_flag); + printf("dec_frame_buffering_constraint_flag = %d\n", + dec_frame_buffering_constraint_flag); + printf("deblocking_display_preference_repetition_period = %d\n", + deblocking_display_preference_repetition_period); #endif } - free (buf); + free(buf); #ifdef PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO #undef PRINT_DEBLOCKING_FILTER_DISPLAY_PREFERENCE_INFO #endif @@ -1488,14 +1487,15 @@ void interpret_deblocking_filter_display_preference_info( byte* payload, int siz * ************************************************************************ */ -void interpret_stereo_video_info_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_stereo_video_info_info(byte *payload, int size, + VideoParameters *p_Vid) { int field_views_flags; - int top_field_is_left_view_flag, current_frame_is_left_view_flag, next_frame_is_second_view_flag; + int top_field_is_left_view_flag, current_frame_is_left_view_flag, + next_frame_is_second_view_flag; int left_view_self_contained_flag; int right_view_self_contained_flag; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -1506,31 +1506,35 @@ void interpret_stereo_video_info_info( byte* payload, int size, VideoParameters #ifdef PRINT_STEREO_VIDEO_INFO_INFO printf("field_views_flags = %d\n", field_views_flags); #endif - if (field_views_flags) - { - top_field_is_left_view_flag = u_1("SEI: top_field_is_left_view_flag", buf); + if (field_views_flags) { + top_field_is_left_view_flag = u_1("SEI: top_field_is_left_view_flag", buf); #ifdef PRINT_STEREO_VIDEO_INFO_INFO printf("top_field_is_left_view_flag = %d\n", top_field_is_left_view_flag); #endif - } - else - { - current_frame_is_left_view_flag = u_1("SEI: current_frame_is_left_view_flag", buf); - next_frame_is_second_view_flag = u_1("SEI: next_frame_is_second_view_flag", buf); + } else { + current_frame_is_left_view_flag = + u_1("SEI: current_frame_is_left_view_flag", buf); + next_frame_is_second_view_flag = + u_1("SEI: next_frame_is_second_view_flag", buf); #ifdef PRINT_STEREO_VIDEO_INFO_INFO - printf("current_frame_is_left_view_flag = %d\n", current_frame_is_left_view_flag); - printf("next_frame_is_second_view_flag = %d\n", next_frame_is_second_view_flag); + printf("current_frame_is_left_view_flag = %d\n", + current_frame_is_left_view_flag); + printf("next_frame_is_second_view_flag = %d\n", + next_frame_is_second_view_flag); #endif } - left_view_self_contained_flag = u_1("SEI: left_view_self_contained_flag", buf); - right_view_self_contained_flag = u_1("SEI: right_view_self_contained_flag", buf); + left_view_self_contained_flag = + u_1("SEI: left_view_self_contained_flag", buf); + right_view_self_contained_flag = + u_1("SEI: right_view_self_contained_flag", buf); #ifdef PRINT_STEREO_VIDEO_INFO_INFO printf("left_view_self_contained_flag = %d\n", left_view_self_contained_flag); - printf("right_view_self_contained_flag = %d\n", right_view_self_contained_flag); + printf("right_view_self_contained_flag = %d\n", + right_view_self_contained_flag); #endif - free (buf); + free(buf); #ifdef PRINT_STEREO_VIDEO_INFO_INFO #undef PRINT_STEREO_VIDEO_INFO_INFO #endif @@ -1549,8 +1553,7 @@ void interpret_stereo_video_info_info( byte* payload, int size, VideoParameters * ************************************************************************ */ -void interpret_reserved_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_reserved_info(byte *payload, int size, VideoParameters *p_Vid) { int offset = 0; byte payload_byte; @@ -1558,10 +1561,9 @@ void interpret_reserved_info( byte* payload, int size, VideoParameters *p_Vid ) printf("Reserved SEI message\n"); #endif - while (offset < size) - { + while (offset < size) { payload_byte = payload[offset]; - offset ++; + offset++; #ifdef PRINT_RESERVED_INFO printf("reserved_sei_message_payload_byte = %d\n", payload_byte); #endif @@ -1571,7 +1573,6 @@ void interpret_reserved_info( byte* payload, int size, VideoParameters *p_Vid ) #endif } - /*! ************************************************************************ * \brief @@ -1585,12 +1586,13 @@ void interpret_reserved_info( byte* payload, int size, VideoParameters *p_Vid ) * ************************************************************************ */ -void interpret_buffering_period_info( byte* payload, int size, VideoParameters *p_Vid ) -{ - int seq_parameter_set_id, initial_cpb_removal_delay, initial_cpb_removal_delay_offset; +void interpret_buffering_period_info(byte *payload, int size, + VideoParameters *p_Vid) { + int seq_parameter_set_id, initial_cpb_removal_delay, + initial_cpb_removal_delay_offset; unsigned int k; - Bitstream* buf; + Bitstream *buf; seq_parameter_set_rbsp_t *sps; buf = malloc(sizeof(Bitstream)); @@ -1600,7 +1602,7 @@ void interpret_buffering_period_info( byte* payload, int size, VideoParameters * p_Dec->UsedBits = 0; - seq_parameter_set_id = ue_v("SEI: seq_parameter_set_id" , buf); + seq_parameter_set_id = ue_v("SEI: seq_parameter_set_id", buf); sps = &p_Vid->SeqParSet[seq_parameter_set_id]; @@ -1611,46 +1613,65 @@ void interpret_buffering_period_info( byte* payload, int size, VideoParameters * printf("seq_parameter_set_id = %d\n", seq_parameter_set_id); #endif - // Note: NalHrdBpPresentFlag and CpbDpbDelaysPresentFlag can also be set "by some means not specified in this Recommendation | International Standard" - if (sps->vui_parameters_present_flag) - { + // Note: NalHrdBpPresentFlag and CpbDpbDelaysPresentFlag can also be set "by + // some means not specified in this Recommendation | International Standard" + if (sps->vui_parameters_present_flag) { - if (sps->vui_seq_parameters.nal_hrd_parameters_present_flag) - { - for (k=0; kvui_seq_parameters.nal_hrd_parameters.cpb_cnt_minus1+1; k++) - { - initial_cpb_removal_delay = u_v(sps->vui_seq_parameters.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay" , buf); - initial_cpb_removal_delay_offset = u_v(sps->vui_seq_parameters.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay_offset" , buf); + if (sps->vui_seq_parameters.nal_hrd_parameters_present_flag) { + for (k = 0; + k < sps->vui_seq_parameters.nal_hrd_parameters.cpb_cnt_minus1 + 1; + k++) { + initial_cpb_removal_delay = + u_v(sps->vui_seq_parameters.nal_hrd_parameters + .initial_cpb_removal_delay_length_minus1 + + 1, + "SEI: initial_cpb_removal_delay", buf); + initial_cpb_removal_delay_offset = + u_v(sps->vui_seq_parameters.nal_hrd_parameters + .initial_cpb_removal_delay_length_minus1 + + 1, + "SEI: initial_cpb_removal_delay_offset", buf); #ifdef PRINT_BUFFERING_PERIOD_INFO - printf("nal initial_cpb_removal_delay[%d] = %d\n", k, initial_cpb_removal_delay); - printf("nal initial_cpb_removal_delay_offset[%d] = %d\n", k, initial_cpb_removal_delay_offset); + printf("nal initial_cpb_removal_delay[%d] = %d\n", k, + initial_cpb_removal_delay); + printf("nal initial_cpb_removal_delay_offset[%d] = %d\n", k, + initial_cpb_removal_delay_offset); #endif } } - if (sps->vui_seq_parameters.vcl_hrd_parameters_present_flag) - { - for (k=0; kvui_seq_parameters.vcl_hrd_parameters.cpb_cnt_minus1+1; k++) - { - initial_cpb_removal_delay = u_v(sps->vui_seq_parameters.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay" , buf); - initial_cpb_removal_delay_offset = u_v(sps->vui_seq_parameters.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay_offset" , buf); + if (sps->vui_seq_parameters.vcl_hrd_parameters_present_flag) { + for (k = 0; + k < sps->vui_seq_parameters.vcl_hrd_parameters.cpb_cnt_minus1 + 1; + k++) { + initial_cpb_removal_delay = + u_v(sps->vui_seq_parameters.vcl_hrd_parameters + .initial_cpb_removal_delay_length_minus1 + + 1, + "SEI: initial_cpb_removal_delay", buf); + initial_cpb_removal_delay_offset = + u_v(sps->vui_seq_parameters.vcl_hrd_parameters + .initial_cpb_removal_delay_length_minus1 + + 1, + "SEI: initial_cpb_removal_delay_offset", buf); #ifdef PRINT_BUFFERING_PERIOD_INFO - printf("vcl initial_cpb_removal_delay[%d] = %d\n", k, initial_cpb_removal_delay); - printf("vcl initial_cpb_removal_delay_offset[%d] = %d\n", k, initial_cpb_removal_delay_offset); + printf("vcl initial_cpb_removal_delay[%d] = %d\n", k, + initial_cpb_removal_delay); + printf("vcl initial_cpb_removal_delay_offset[%d] = %d\n", k, + initial_cpb_removal_delay_offset); #endif } } } - free (buf); + free(buf); #ifdef PRINT_BUFFERING_PERIOD_INFO #undef PRINT_BUFFERING_PERIOD_INFO #endif } - /*! ************************************************************************ * \brief @@ -1664,27 +1685,29 @@ void interpret_buffering_period_info( byte* payload, int size, VideoParameters * * ************************************************************************ */ -void interpret_picture_timing_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_picture_timing_info(byte *payload, int size, + VideoParameters *p_Vid) { seq_parameter_set_rbsp_t *active_sps = p_Vid->active_sps; - int cpb_removal_delay, dpb_output_delay, picture_structure_present_flag, picture_structure; + int cpb_removal_delay, dpb_output_delay, picture_structure_present_flag, + picture_structure; int clock_time_stamp_flag; - int ct_type, nuit_field_based_flag, counting_type, full_timestamp_flag, discontinuity_flag, cnt_dropped_flag, nframes; - int seconds_value, minutes_value, hours_value, seconds_flag, minutes_flag, hours_flag, time_offset; + int ct_type, nuit_field_based_flag, counting_type, full_timestamp_flag, + discontinuity_flag, cnt_dropped_flag, nframes; + int seconds_value, minutes_value, hours_value, seconds_flag, minutes_flag, + hours_flag, time_offset; int NumClockTs = 0; int i; int cpb_removal_len = 24; - int dpb_output_len = 24; + int dpb_output_len = 24; Boolean CpbDpbDelaysPresentFlag; - Bitstream* buf; + Bitstream *buf; - if (NULL==active_sps) - { - fprintf (stderr, "Warning: no active SPS, timing SEI cannot be parsed\n"); + if (NULL == active_sps) { + fprintf(stderr, "Warning: no active SPS, timing SEI cannot be parsed\n"); return; } @@ -1695,61 +1718,63 @@ void interpret_picture_timing_info( byte* payload, int size, VideoParameters *p_ p_Dec->UsedBits = 0; - #ifdef PRINT_PCITURE_TIMING_INFO printf("Picture timing SEI message\n"); #endif - // CpbDpbDelaysPresentFlag can also be set "by some means not specified in this Recommendation | International Standard" - CpbDpbDelaysPresentFlag = (Boolean) (active_sps->vui_parameters_present_flag - && ( (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag != 0) - ||(active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag != 0))); + // CpbDpbDelaysPresentFlag can also be set "by some means not specified in + // this Recommendation | International Standard" + CpbDpbDelaysPresentFlag = + (Boolean)(active_sps->vui_parameters_present_flag && + ((active_sps->vui_seq_parameters + .nal_hrd_parameters_present_flag != 0) || + (active_sps->vui_seq_parameters + .vcl_hrd_parameters_present_flag != 0))); - if (CpbDpbDelaysPresentFlag ) - { - if (active_sps->vui_parameters_present_flag) - { - if (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag) - { - cpb_removal_len = active_sps->vui_seq_parameters.nal_hrd_parameters.cpb_removal_delay_length_minus1 + 1; - dpb_output_len = active_sps->vui_seq_parameters.nal_hrd_parameters.dpb_output_delay_length_minus1 + 1; - } - else if (active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag) - { - cpb_removal_len = active_sps->vui_seq_parameters.vcl_hrd_parameters.cpb_removal_delay_length_minus1 + 1; - dpb_output_len = active_sps->vui_seq_parameters.vcl_hrd_parameters.dpb_output_delay_length_minus1 + 1; + if (CpbDpbDelaysPresentFlag) { + if (active_sps->vui_parameters_present_flag) { + if (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag) { + cpb_removal_len = active_sps->vui_seq_parameters.nal_hrd_parameters + .cpb_removal_delay_length_minus1 + + 1; + dpb_output_len = active_sps->vui_seq_parameters.nal_hrd_parameters + .dpb_output_delay_length_minus1 + + 1; + } else if (active_sps->vui_seq_parameters + .vcl_hrd_parameters_present_flag) { + cpb_removal_len = active_sps->vui_seq_parameters.vcl_hrd_parameters + .cpb_removal_delay_length_minus1 + + 1; + dpb_output_len = active_sps->vui_seq_parameters.vcl_hrd_parameters + .dpb_output_delay_length_minus1 + + 1; } } - if ((active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag)|| - (active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag)) - { - cpb_removal_delay = u_v(cpb_removal_len, "SEI: cpb_removal_delay" , buf); - dpb_output_delay = u_v(dpb_output_len, "SEI: dpb_output_delay" , buf); + if ((active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag) || + (active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag)) { + cpb_removal_delay = u_v(cpb_removal_len, "SEI: cpb_removal_delay", buf); + dpb_output_delay = u_v(dpb_output_len, "SEI: dpb_output_delay", buf); #ifdef PRINT_PCITURE_TIMING_INFO - printf("cpb_removal_delay = %d\n",cpb_removal_delay); - printf("dpb_output_delay = %d\n",dpb_output_delay); + printf("cpb_removal_delay = %d\n", cpb_removal_delay); + printf("dpb_output_delay = %d\n", dpb_output_delay); #endif } } - if (!active_sps->vui_parameters_present_flag) - { + if (!active_sps->vui_parameters_present_flag) { picture_structure_present_flag = 0; - } - else - { - picture_structure_present_flag = active_sps->vui_seq_parameters.pic_struct_present_flag; + } else { + picture_structure_present_flag = + active_sps->vui_seq_parameters.pic_struct_present_flag; } - if (picture_structure_present_flag) - { - picture_structure = u_v(4, "SEI: pic_struct" , buf); + if (picture_structure_present_flag) { + picture_structure = u_v(4, "SEI: pic_struct", buf); #ifdef PRINT_PCITURE_TIMING_INFO - printf("picture_structure = %d\n",picture_structure); + printf("picture_structure = %d\n", picture_structure); #endif - switch (picture_structure) - { + switch (picture_structure) { case 0: case 1: case 2: @@ -1766,70 +1791,63 @@ void interpret_picture_timing_info( byte* payload, int size, VideoParameters *p_ NumClockTs = 3; break; default: - error("reserved picture_structure used (can't determine NumClockTs)", 500); + error("reserved picture_structure used (can't determine NumClockTs)", + 500); } - for (i=0; ivui_seq_parameters.vcl_hrd_parameters_present_flag) - time_offset_length = active_sps->vui_seq_parameters.vcl_hrd_parameters.time_offset_length; - else if (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag) - time_offset_length = active_sps->vui_seq_parameters.nal_hrd_parameters.time_offset_length; + time_offset_length = active_sps->vui_seq_parameters + .vcl_hrd_parameters.time_offset_length; + else if (active_sps->vui_seq_parameters + .nal_hrd_parameters_present_flag) + time_offset_length = active_sps->vui_seq_parameters + .nal_hrd_parameters.time_offset_length; else time_offset_length = 24; if (time_offset_length) - time_offset = i_v(time_offset_length, "SEI: time_offset" , buf); + time_offset = i_v(time_offset_length, "SEI: time_offset", buf); else time_offset = 0; #ifdef PRINT_PCITURE_TIMING_INFO - printf("time_offset = %d\n",time_offset); + printf("time_offset = %d\n", time_offset); #endif } } } } - free (buf); + free(buf); #ifdef PRINT_PCITURE_TIMING_INFO #undef PRINT_PCITURE_TIMING_INFO #endif @@ -1873,10 +1894,10 @@ void interpret_picture_timing_info( byte* payload, int size, VideoParameters *p_ * the image pointer ************************************************************************ */ -void interpret_frame_packing_arrangement_info( byte* payload, int size, VideoParameters *p_Vid ) -{ +void interpret_frame_packing_arrangement_info(byte *payload, int size, + VideoParameters *p_Vid) { frame_packing_arrangement_information_struct seiFramePackingArrangement; - Bitstream* buf; + Bitstream *buf; buf = malloc(sizeof(Bitstream)); buf->bitstream_length = size; @@ -1889,60 +1910,99 @@ void interpret_frame_packing_arrangement_info( byte* payload, int size, VideoPar printf("Frame packing arrangement SEI message\n"); #endif - seiFramePackingArrangement.frame_packing_arrangement_id = (unsigned int)ue_v( "SEI: frame_packing_arrangement_id", buf ); - seiFramePackingArrangement.frame_packing_arrangement_cancel_flag = u_1( "SEI: frame_packing_arrangement_cancel_flag", buf ); + seiFramePackingArrangement.frame_packing_arrangement_id = + (unsigned int)ue_v("SEI: frame_packing_arrangement_id", buf); + seiFramePackingArrangement.frame_packing_arrangement_cancel_flag = + u_1("SEI: frame_packing_arrangement_cancel_flag", buf); #ifdef PRINT_FRAME_PACKING_ARRANGEMENT_INFO - printf("frame_packing_arrangement_id = %d\n", seiFramePackingArrangement.frame_packing_arrangement_id); - printf("frame_packing_arrangement_cancel_flag = %d\n", seiFramePackingArrangement.frame_packing_arrangement_cancel_flag); + printf("frame_packing_arrangement_id = %d\n", + seiFramePackingArrangement.frame_packing_arrangement_id); + printf("frame_packing_arrangement_cancel_flag = %d\n", + seiFramePackingArrangement.frame_packing_arrangement_cancel_flag); #endif - if ( seiFramePackingArrangement.frame_packing_arrangement_cancel_flag == FALSE ) - { - seiFramePackingArrangement.frame_packing_arrangement_type = (unsigned char)u_v( 7, "SEI: frame_packing_arrangement_type", buf ); - seiFramePackingArrangement.quincunx_sampling_flag = u_1( "SEI: quincunx_sampling_flag", buf ); - seiFramePackingArrangement.content_interpretation_type = (unsigned char)u_v( 6, "SEI: content_interpretation_type", buf ); - seiFramePackingArrangement.spatial_flipping_flag = u_1( "SEI: spatial_flipping_flag", buf ); - seiFramePackingArrangement.frame0_flipped_flag = u_1( "SEI: frame0_flipped_flag", buf ); - seiFramePackingArrangement.field_views_flag = u_1( "SEI: field_views_flag", buf ); - seiFramePackingArrangement.current_frame_is_frame0_flag = u_1( "SEI: current_frame_is_frame0_flag", buf ); - seiFramePackingArrangement.frame0_self_contained_flag = u_1( "SEI: frame0_self_contained_flag", buf ); - seiFramePackingArrangement.frame1_self_contained_flag = u_1( "SEI: frame1_self_contained_flag", buf ); + if (seiFramePackingArrangement.frame_packing_arrangement_cancel_flag == + FALSE) { + seiFramePackingArrangement.frame_packing_arrangement_type = + (unsigned char)u_v(7, "SEI: frame_packing_arrangement_type", buf); + seiFramePackingArrangement.quincunx_sampling_flag = + u_1("SEI: quincunx_sampling_flag", buf); + seiFramePackingArrangement.content_interpretation_type = + (unsigned char)u_v(6, "SEI: content_interpretation_type", buf); + seiFramePackingArrangement.spatial_flipping_flag = + u_1("SEI: spatial_flipping_flag", buf); + seiFramePackingArrangement.frame0_flipped_flag = + u_1("SEI: frame0_flipped_flag", buf); + seiFramePackingArrangement.field_views_flag = + u_1("SEI: field_views_flag", buf); + seiFramePackingArrangement.current_frame_is_frame0_flag = + u_1("SEI: current_frame_is_frame0_flag", buf); + seiFramePackingArrangement.frame0_self_contained_flag = + u_1("SEI: frame0_self_contained_flag", buf); + seiFramePackingArrangement.frame1_self_contained_flag = + u_1("SEI: frame1_self_contained_flag", buf); #ifdef PRINT_FRAME_PACKING_ARRANGEMENT_INFO - printf("frame_packing_arrangement_type = %d\n", seiFramePackingArrangement.frame_packing_arrangement_type); - printf("quincunx_sampling_flag = %d\n", seiFramePackingArrangement.quincunx_sampling_flag); - printf("content_interpretation_type = %d\n", seiFramePackingArrangement.content_interpretation_type); - printf("spatial_flipping_flag = %d\n", seiFramePackingArrangement.spatial_flipping_flag); - printf("frame0_flipped_flag = %d\n", seiFramePackingArrangement.frame0_flipped_flag); - printf("field_views_flag = %d\n", seiFramePackingArrangement.field_views_flag); - printf("current_frame_is_frame0_flag = %d\n", seiFramePackingArrangement.current_frame_is_frame0_flag); - printf("frame0_self_contained_flag = %d\n", seiFramePackingArrangement.frame0_self_contained_flag); - printf("frame1_self_contained_flag = %d\n", seiFramePackingArrangement.frame1_self_contained_flag); + printf("frame_packing_arrangement_type = %d\n", + seiFramePackingArrangement.frame_packing_arrangement_type); + printf("quincunx_sampling_flag = %d\n", + seiFramePackingArrangement.quincunx_sampling_flag); + printf("content_interpretation_type = %d\n", + seiFramePackingArrangement.content_interpretation_type); + printf("spatial_flipping_flag = %d\n", + seiFramePackingArrangement.spatial_flipping_flag); + printf("frame0_flipped_flag = %d\n", + seiFramePackingArrangement.frame0_flipped_flag); + printf("field_views_flag = %d\n", + seiFramePackingArrangement.field_views_flag); + printf("current_frame_is_frame0_flag = %d\n", + seiFramePackingArrangement.current_frame_is_frame0_flag); + printf("frame0_self_contained_flag = %d\n", + seiFramePackingArrangement.frame0_self_contained_flag); + printf("frame1_self_contained_flag = %d\n", + seiFramePackingArrangement.frame1_self_contained_flag); #endif - if ( seiFramePackingArrangement.quincunx_sampling_flag == FALSE && seiFramePackingArrangement.frame_packing_arrangement_type != 5 ) - { - seiFramePackingArrangement.frame0_grid_position_x = (unsigned char)u_v( 4, "SEI: frame0_grid_position_x", buf ); - seiFramePackingArrangement.frame0_grid_position_y = (unsigned char)u_v( 4, "SEI: frame0_grid_position_y", buf ); - seiFramePackingArrangement.frame1_grid_position_x = (unsigned char)u_v( 4, "SEI: frame1_grid_position_x", buf ); - seiFramePackingArrangement.frame1_grid_position_y = (unsigned char)u_v( 4, "SEI: frame1_grid_position_y", buf ); + if (seiFramePackingArrangement.quincunx_sampling_flag == FALSE && + seiFramePackingArrangement.frame_packing_arrangement_type != 5) { + seiFramePackingArrangement.frame0_grid_position_x = + (unsigned char)u_v(4, "SEI: frame0_grid_position_x", buf); + seiFramePackingArrangement.frame0_grid_position_y = + (unsigned char)u_v(4, "SEI: frame0_grid_position_y", buf); + seiFramePackingArrangement.frame1_grid_position_x = + (unsigned char)u_v(4, "SEI: frame1_grid_position_x", buf); + seiFramePackingArrangement.frame1_grid_position_y = + (unsigned char)u_v(4, "SEI: frame1_grid_position_y", buf); #ifdef PRINT_FRAME_PACKING_ARRANGEMENT_INFO - printf("frame0_grid_position_x = %d\n", seiFramePackingArrangement.frame0_grid_position_x); - printf("frame0_grid_position_y = %d\n", seiFramePackingArrangement.frame0_grid_position_y); - printf("frame1_grid_position_x = %d\n", seiFramePackingArrangement.frame1_grid_position_x); - printf("frame1_grid_position_y = %d\n", seiFramePackingArrangement.frame1_grid_position_y); + printf("frame0_grid_position_x = %d\n", + seiFramePackingArrangement.frame0_grid_position_x); + printf("frame0_grid_position_y = %d\n", + seiFramePackingArrangement.frame0_grid_position_y); + printf("frame1_grid_position_x = %d\n", + seiFramePackingArrangement.frame1_grid_position_x); + printf("frame1_grid_position_y = %d\n", + seiFramePackingArrangement.frame1_grid_position_y); #endif } - seiFramePackingArrangement.frame_packing_arrangement_reserved_byte = (unsigned char)u_v( 8, "SEI: frame_packing_arrangement_reserved_byte", buf ); - seiFramePackingArrangement.frame_packing_arrangement_repetition_period = (unsigned int)ue_v( "SEI: frame_packing_arrangement_repetition_period", buf ); + seiFramePackingArrangement.frame_packing_arrangement_reserved_byte = + (unsigned char)u_v(8, "SEI: frame_packing_arrangement_reserved_byte", + buf); + seiFramePackingArrangement.frame_packing_arrangement_repetition_period = + (unsigned int)ue_v("SEI: frame_packing_arrangement_repetition_period", + buf); #ifdef PRINT_FRAME_PACKING_ARRANGEMENT_INFO - printf("frame_packing_arrangement_reserved_byte = %d\n", seiFramePackingArrangement.frame_packing_arrangement_reserved_byte); - printf("frame_packing_arrangement_repetition_period = %d\n", seiFramePackingArrangement.frame_packing_arrangement_repetition_period); + printf("frame_packing_arrangement_reserved_byte = %d\n", + seiFramePackingArrangement.frame_packing_arrangement_reserved_byte); + printf( + "frame_packing_arrangement_repetition_period = %d\n", + seiFramePackingArrangement.frame_packing_arrangement_repetition_period); #endif } - seiFramePackingArrangement.frame_packing_arrangement_extension_flag = u_1( "SEI: frame_packing_arrangement_extension_flag", buf ); + seiFramePackingArrangement.frame_packing_arrangement_extension_flag = + u_1("SEI: frame_packing_arrangement_extension_flag", buf); #ifdef PRINT_FRAME_PACKING_ARRANGEMENT_INFO - printf("frame_packing_arrangement_extension_flag = %d\n", seiFramePackingArrangement.frame_packing_arrangement_extension_flag); + printf("frame_packing_arrangement_extension_flag = %d\n", + seiFramePackingArrangement.frame_packing_arrangement_extension_flag); #endif - free (buf); + free(buf); #ifdef PRINT_FRAME_PACKING_ARRANGEMENT_INFO #undef PRINT_FRAME_PACKING_ARRANGEMENT_INFO #endif @@ -1961,35 +2021,33 @@ void interpret_frame_packing_arrangement_info( byte* payload, int size, VideoPar * ************************************************************************ */ -typedef struct -{ - unsigned int tone_map_id; +typedef struct { + unsigned int tone_map_id; unsigned char tone_map_cancel_flag; - unsigned int tone_map_repetition_period; + unsigned int tone_map_repetition_period; unsigned char coded_data_bit_depth; unsigned char sei_bit_depth; - unsigned int model_id; + unsigned int model_id; // variables for model 0 - int min_value; - int max_value; + int min_value; + int max_value; // variables for model 1 - int sigmoid_midpoint; - int sigmoid_width; + int sigmoid_midpoint; + int sigmoid_width; // variables for model 2 - int start_of_coded_interval[1<bitstream_length = size; @@ -1997,134 +2055,157 @@ void interpret_tone_mapping( byte* payload, int size, VideoParameters *p_Vid ) buf->frame_bitoffset = 0; seiToneMappingTmp.tone_map_id = ue_v("SEI: tone_map_id", buf); - seiToneMappingTmp.tone_map_cancel_flag = (unsigned char) u_1("SEI: tone_map_cancel_flag", buf); + seiToneMappingTmp.tone_map_cancel_flag = + (unsigned char)u_1("SEI: tone_map_cancel_flag", buf); #ifdef PRINT_TONE_MAPPING printf("Tone-mapping SEI message\n"); printf("tone_map_id = %d\n", seiToneMappingTmp.tone_map_id); if (seiToneMappingTmp.tone_map_id != 0) - printf("WARNING! Tone_map_id != 0, print the SEI message info only. The tone mapping is actually applied only when Tone_map_id==0\n\n"); + printf("WARNING! Tone_map_id != 0, print the SEI message info only. The " + "tone mapping is actually applied only when Tone_map_id==0\n\n"); printf("tone_map_cancel_flag = %d\n", seiToneMappingTmp.tone_map_cancel_flag); #endif - if (!seiToneMappingTmp.tone_map_cancel_flag) - { - seiToneMappingTmp.tone_map_repetition_period = ue_v( "SEI: tone_map_repetition_period", buf); - seiToneMappingTmp.coded_data_bit_depth = (unsigned char)u_v (8,"SEI: coded_data_bit_depth" , buf); - seiToneMappingTmp.sei_bit_depth = (unsigned char)u_v (8,"SEI: sei_bit_depth" , buf); - seiToneMappingTmp.model_id = ue_v( "SEI: model_id" , buf); + if (!seiToneMappingTmp.tone_map_cancel_flag) { + seiToneMappingTmp.tone_map_repetition_period = + ue_v("SEI: tone_map_repetition_period", buf); + seiToneMappingTmp.coded_data_bit_depth = + (unsigned char)u_v(8, "SEI: coded_data_bit_depth", buf); + seiToneMappingTmp.sei_bit_depth = + (unsigned char)u_v(8, "SEI: sei_bit_depth", buf); + seiToneMappingTmp.model_id = ue_v("SEI: model_id", buf); #ifdef PRINT_TONE_MAPPING - printf("tone_map_repetition_period = %d\n", seiToneMappingTmp.tone_map_repetition_period); - printf("coded_data_bit_depth = %d\n", seiToneMappingTmp.coded_data_bit_depth); + printf("tone_map_repetition_period = %d\n", + seiToneMappingTmp.tone_map_repetition_period); + printf("coded_data_bit_depth = %d\n", + seiToneMappingTmp.coded_data_bit_depth); printf("sei_bit_depth = %d\n", seiToneMappingTmp.sei_bit_depth); printf("model_id = %d\n", seiToneMappingTmp.model_id); #endif - max_coded_num = 1<>3)<<3), "SEI: start_of_coded_interval" , buf); + } else if (seiToneMappingTmp.model_id == 2) { // user defined table mapping + for (i = 0; i < max_output_num; i++) { + seiToneMappingTmp.start_of_coded_interval[i] = + u_v((((seiToneMappingTmp.coded_data_bit_depth + 7) >> 3) << 3), + "SEI: start_of_coded_interval", buf); #ifdef PRINT_TONE_MAPPING // too long to print - //printf("start_of_coded_interval[%d] = %d\n", i, seiToneMappingTmp.start_of_coded_interval[i]); + // printf("start_of_coded_interval[%d] = %d\n", i, + // seiToneMappingTmp.start_of_coded_interval[i]); #endif } - } - else if (seiToneMappingTmp.model_id == 3) - { // piece-wise linear mapping - seiToneMappingTmp.num_pivots = u_v (16,"SEI: num_pivots", buf); + } else if (seiToneMappingTmp.model_id == 3) { // piece-wise linear mapping + seiToneMappingTmp.num_pivots = u_v(16, "SEI: num_pivots", buf); #ifdef PRINT_TONE_MAPPING printf("num_pivots = %d\n", seiToneMappingTmp.num_pivots); #endif seiToneMappingTmp.coded_pivot_value[0] = 0; seiToneMappingTmp.sei_pivot_value[0] = 0; - seiToneMappingTmp.coded_pivot_value[seiToneMappingTmp.num_pivots+1] = max_coded_num-1; - seiToneMappingTmp.sei_pivot_value[seiToneMappingTmp.num_pivots+1] = max_output_num-1; + seiToneMappingTmp.coded_pivot_value[seiToneMappingTmp.num_pivots + 1] = + max_coded_num - 1; + seiToneMappingTmp.sei_pivot_value[seiToneMappingTmp.num_pivots + 1] = + max_output_num - 1; - for (i=1; i < seiToneMappingTmp.num_pivots+1; i++) - { - seiToneMappingTmp.coded_pivot_value[i] = u_v( (((seiToneMappingTmp.coded_data_bit_depth+7)>>3)<<3), "SEI: coded_pivot_value", buf); - seiToneMappingTmp.sei_pivot_value[i] = u_v( (((seiToneMappingTmp.sei_bit_depth+7)>>3)<<3), "SEI: sei_pivot_value", buf); + for (i = 1; i < seiToneMappingTmp.num_pivots + 1; i++) { + seiToneMappingTmp.coded_pivot_value[i] = + u_v((((seiToneMappingTmp.coded_data_bit_depth + 7) >> 3) << 3), + "SEI: coded_pivot_value", buf); + seiToneMappingTmp.sei_pivot_value[i] = + u_v((((seiToneMappingTmp.sei_bit_depth + 7) >> 3) << 3), + "SEI: sei_pivot_value", buf); #ifdef PRINT_TONE_MAPPING - printf("coded_pivot_value[%d] = %d, sei_pivot_value[%d] = %d\n", i, seiToneMappingTmp.coded_pivot_value[i], i, seiToneMappingTmp.sei_pivot_value[i]); + printf("coded_pivot_value[%d] = %d, sei_pivot_value[%d] = %d\n", i, + seiToneMappingTmp.coded_pivot_value[i], i, + seiToneMappingTmp.sei_pivot_value[i]); #endif } } #if (ENABLE_OUTPUT_TONEMAPPING) - // Currently, only when the map_id == 0, the tone-mapping is actually applied. - if (seiToneMappingTmp.tone_map_id== 0) - { + // Currently, only when the map_id == 0, the tone-mapping is actually + // applied. + if (seiToneMappingTmp.tone_map_id == 0) { int j; p_Vid->seiToneMapping->seiHasTone_mapping = TRUE; - p_Vid->seiToneMapping->tone_map_repetition_period = seiToneMappingTmp.tone_map_repetition_period; - p_Vid->seiToneMapping->coded_data_bit_depth = seiToneMappingTmp.coded_data_bit_depth; + p_Vid->seiToneMapping->tone_map_repetition_period = + seiToneMappingTmp.tone_map_repetition_period; + p_Vid->seiToneMapping->coded_data_bit_depth = + seiToneMappingTmp.coded_data_bit_depth; p_Vid->seiToneMapping->sei_bit_depth = seiToneMappingTmp.sei_bit_depth; p_Vid->seiToneMapping->model_id = seiToneMappingTmp.model_id; p_Vid->seiToneMapping->count = 0; // generate the look up table of tone mapping - switch(seiToneMappingTmp.model_id) - { - case 0: // linear mapping with clipping - for (i=0; i<=seiToneMappingTmp.min_value; i++) + switch (seiToneMappingTmp.model_id) { + case 0: // linear mapping with clipping + for (i = 0; i <= seiToneMappingTmp.min_value; i++) p_Vid->seiToneMapping->lut[i] = 0; - for (i=seiToneMappingTmp.min_value+1; i < seiToneMappingTmp.max_value; i++) - p_Vid->seiToneMapping->lut[i] = (imgpel) ((i-seiToneMappingTmp.min_value) * (max_output_num-1)/(seiToneMappingTmp.max_value- seiToneMappingTmp.min_value)); + for (i = seiToneMappingTmp.min_value + 1; + i < seiToneMappingTmp.max_value; i++) + p_Vid->seiToneMapping->lut[i] = + (imgpel)((i - seiToneMappingTmp.min_value) * + (max_output_num - 1) / + (seiToneMappingTmp.max_value - + seiToneMappingTmp.min_value)); - for (i=seiToneMappingTmp.max_value; iseiToneMapping->lut[i] = (imgpel) (max_output_num - 1); + for (i = seiToneMappingTmp.max_value; i < max_coded_num; i++) + p_Vid->seiToneMapping->lut[i] = (imgpel)(max_output_num - 1); break; case 1: // sigmoid mapping - for (i=0; i < max_coded_num; i++) - { - double tmp = 1.0 + exp( -6*(double)(i-seiToneMappingTmp.sigmoid_midpoint)/seiToneMappingTmp.sigmoid_width); - p_Vid->seiToneMapping->lut[i] = (imgpel)( (double)(max_output_num-1)/ tmp + 0.5); + for (i = 0; i < max_coded_num; i++) { + double tmp = + 1.0 + exp(-6 * (double)(i - seiToneMappingTmp.sigmoid_midpoint) / + seiToneMappingTmp.sigmoid_width); + p_Vid->seiToneMapping->lut[i] = + (imgpel)((double)(max_output_num - 1) / tmp + 0.5); } break; case 2: // user defined table - if (0 < max_output_num-1) - { - for (j=0; jseiToneMapping->lut[i] = (imgpel) j; + if (0 < max_output_num - 1) { + for (j = 0; j < max_output_num - 1; j++) { + for (i = seiToneMappingTmp.start_of_coded_interval[j]; + i < seiToneMappingTmp.start_of_coded_interval[j + 1]; i++) { + p_Vid->seiToneMapping->lut[i] = (imgpel)j; } } - p_Vid->seiToneMapping->lut[i] = (imgpel) (max_output_num - 1); + p_Vid->seiToneMapping->lut[i] = (imgpel)(max_output_num - 1); } break; case 3: // piecewise linear mapping - for (j=0; jseiToneMapping->lut[i] = (imgpel) (seiToneMappingTmp.sei_pivot_value[j] + (int)(( (i - seiToneMappingTmp.coded_pivot_value[j]) * slope))); + for (j = 0; j < seiToneMappingTmp.num_pivots + 1; j++) { + double slope = (double)(seiToneMappingTmp.sei_pivot_value[j + 1] - + seiToneMappingTmp.sei_pivot_value[j]) / + (seiToneMappingTmp.coded_pivot_value[j + 1] - + seiToneMappingTmp.coded_pivot_value[j]); + for (i = seiToneMappingTmp.coded_pivot_value[j]; + i <= seiToneMappingTmp.coded_pivot_value[j + 1]; i++) { + p_Vid->seiToneMapping->lut[i] = + (imgpel)(seiToneMappingTmp.sei_pivot_value[j] + + (int)(((i - seiToneMappingTmp.coded_pivot_value[j]) * + slope))); } } break; @@ -2135,43 +2216,35 @@ void interpret_tone_mapping( byte* payload, int size, VideoParameters *p_Vid ) } #endif } // end !tone_map_cancel_flag - free (buf); + free(buf); } #if (ENABLE_OUTPUT_TONEMAPPING) -// tone map using the look-up-table generated according to SEI tone mapping message -void tone_map (imgpel** imgX, imgpel* lut, int size_x, int size_y) -{ +// tone map using the look-up-table generated according to SEI tone mapping +// message +void tone_map(imgpel **imgX, imgpel *lut, int size_x, int size_y) { int i, j; - for(i=0;iseiHasTone_mapping = FALSE; seiToneMapping->count = 0; } -void update_tone_mapping_sei(ToneMappingSEI *seiToneMapping) -{ +void update_tone_mapping_sei(ToneMappingSEI *seiToneMapping) { - if(seiToneMapping->tone_map_repetition_period == 0) - { + if (seiToneMapping->tone_map_repetition_period == 0) { seiToneMapping->seiHasTone_mapping = FALSE; seiToneMapping->count = 0; - } - else if (seiToneMapping->tone_map_repetition_period>1) - { + } else if (seiToneMapping->tone_map_repetition_period > 1) { seiToneMapping->count++; - if (seiToneMapping->count>=seiToneMapping->tone_map_repetition_period) - { + if (seiToneMapping->count >= seiToneMapping->tone_map_repetition_period) { seiToneMapping->seiHasTone_mapping = FALSE; seiToneMapping->count = 0; } @@ -2189,13 +2262,14 @@ void update_tone_mapping_sei(ToneMappingSEI *seiToneMapping) * the size of the sei message * \param p_Vid * the image pointer - * + * ************************************************************************ */ -void interpret_post_filter_hints_info( byte* payload, int size, VideoParameters *p_Vid ) -{ - Bitstream* buf; - unsigned int filter_hint_size_y, filter_hint_size_x, filter_hint_type, color_component, cx, cy, additional_extension_flag; +void interpret_post_filter_hints_info(byte *payload, int size, + VideoParameters *p_Vid) { + Bitstream *buf; + unsigned int filter_hint_size_y, filter_hint_size_x, filter_hint_type, + color_component, cx, cy, additional_extension_flag; int ***filter_hint; buf = malloc(sizeof(Bitstream)); @@ -2205,34 +2279,40 @@ void interpret_post_filter_hints_info( byte* payload, int size, VideoParameters p_Dec->UsedBits = 0; - filter_hint_size_y = ue_v("SEI: filter_hint_size_y", buf); // interpret post-filter hint SEI here - filter_hint_size_x = ue_v("SEI: filter_hint_size_x", buf); // interpret post-filter hint SEI here - filter_hint_type = u_v(2, "SEI: filter_hint_type", buf); // interpret post-filter hint SEI here + filter_hint_size_y = ue_v("SEI: filter_hint_size_y", + buf); // interpret post-filter hint SEI here + filter_hint_size_x = ue_v("SEI: filter_hint_size_x", + buf); // interpret post-filter hint SEI here + filter_hint_type = u_v(2, "SEI: filter_hint_type", + buf); // interpret post-filter hint SEI here - get_mem3Dint (&filter_hint, 3, filter_hint_size_y, filter_hint_size_x); + get_mem3Dint(&filter_hint, 3, filter_hint_size_y, filter_hint_size_x); - for (color_component = 0; color_component < 3; color_component ++) - for (cy = 0; cy < filter_hint_size_y; cy ++) - for (cx = 0; cx < filter_hint_size_x; cx ++) - filter_hint[color_component][cy][cx] = se_v("SEI: filter_hint", buf); // interpret post-filter hint SEI here + for (color_component = 0; color_component < 3; color_component++) + for (cy = 0; cy < filter_hint_size_y; cy++) + for (cx = 0; cx < filter_hint_size_x; cx++) + filter_hint[color_component][cy][cx] = se_v( + "SEI: filter_hint", buf); // interpret post-filter hint SEI here - additional_extension_flag = u_1("SEI: additional_extension_flag", buf); // interpret post-filter hint SEI here + additional_extension_flag = u_1("SEI: additional_extension_flag", + buf); // interpret post-filter hint SEI here #ifdef PRINT_POST_FILTER_HINT_INFO printf(" Post-filter hint SEI message\n"); printf(" post_filter_hint_size_y %d \n", filter_hint_size_y); printf(" post_filter_hint_size_x %d \n", filter_hint_size_x); - printf(" post_filter_hint_type %d \n", filter_hint_type); - for (color_component = 0; color_component < 3; color_component ++) - for (cy = 0; cy < filter_hint_size_y; cy ++) - for (cx = 0; cx < filter_hint_size_x; cx ++) - printf(" post_filter_hint[%d][%d][%d] %d \n", color_component, cy, cx, filter_hint[color_component][cy][cx]); + printf(" post_filter_hint_type %d \n", filter_hint_type); + for (color_component = 0; color_component < 3; color_component++) + for (cy = 0; cy < filter_hint_size_y; cy++) + for (cx = 0; cx < filter_hint_size_x; cx++) + printf(" post_filter_hint[%d][%d][%d] %d \n", color_component, cy, cx, + filter_hint[color_component][cy][cx]); printf(" additional_extension_flag %d \n", additional_extension_flag); #undef PRINT_POST_FILTER_HINT_INFO #endif - free_mem3Dint (filter_hint); - free( buf ); + free_mem3Dint(filter_hint); + free(buf); } diff --git a/src/common/ldecod_src/transform.c b/src/common/ldecod_src/transform.c index 85647ec..a51938a 100644 --- a/src/common/ldecod_src/transform.c +++ b/src/common/ldecod_src/transform.c @@ -6,48 +6,45 @@ * Transform functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Alexis Michael Tourapis * \date * 01. July 2007 ************************************************************************** */ -#include "global.h" #include "transform.h" +#include "global.h" - -void forward4x4(int **block, int **tblock, int pos_y, int pos_x) -{ - int i, ii; +void forward4x4(int **block, int **tblock, int pos_y, int pos_x) { + int i, ii; int tmp[16]; int *pTmp = tmp, *pblock; - int p0,p1,p2,p3; - int t0,t1,t2,t3; + int p0, p1, p2, p3; + int t0, t1, t2, t3; // Horizontal - for (i=pos_y; i < pos_y + BLOCK_SIZE; i++) - { + for (i = pos_y; i < pos_y + BLOCK_SIZE; i++) { pblock = &block[i][pos_x]; p0 = *(pblock++); p1 = *(pblock++); p2 = *(pblock++); - p3 = *(pblock ); + p3 = *(pblock); t0 = p0 + p3; t1 = p1 + p2; t2 = p1 - p2; t3 = p0 - p3; - *(pTmp++) = t0 + t1; + *(pTmp++) = t0 + t1; *(pTmp++) = (t3 << 1) + t2; - *(pTmp++) = t0 - t1; - *(pTmp++) = t3 - (t2 << 1); + *(pTmp++) = t0 - t1; + *(pTmp++) = t3 - (t2 << 1); } - // Vertical - for (i=0; i < BLOCK_SIZE; i++) - { + // Vertical + for (i = 0; i < BLOCK_SIZE; i++) { pTmp = tmp + i; p0 = *pTmp; p1 = *(pTmp += BLOCK_SIZE); @@ -60,34 +57,32 @@ void forward4x4(int **block, int **tblock, int pos_y, int pos_x) t3 = p0 - p3; ii = pos_x + i; - tblock[pos_y ][ii] = t0 + t1; + tblock[pos_y][ii] = t0 + t1; tblock[pos_y + 1][ii] = t2 + (t3 << 1); - tblock[pos_y + 2][ii] = t0 - t1; + tblock[pos_y + 2][ii] = t0 - t1; tblock[pos_y + 3][ii] = t3 - (t2 << 1); } } -void inverse4x4(int **tblock, int **block, int pos_y, int pos_x) -{ - int i, ii; +void inverse4x4(int **tblock, int **block, int pos_y, int pos_x) { + int i, ii; int tmp[16]; int *pTmp = tmp, *pblock; - int p0,p1,p2,p3; - int t0,t1,t2,t3; + int p0, p1, p2, p3; + int t0, t1, t2, t3; // Horizontal - for (i = pos_y; i < pos_y + BLOCK_SIZE; i++) - { + for (i = pos_y; i < pos_y + BLOCK_SIZE; i++) { pblock = &tblock[i][pos_x]; t0 = *(pblock++); t1 = *(pblock++); t2 = *(pblock++); - t3 = *(pblock ); + t3 = *(pblock); - p0 = t0 + t2; - p1 = t0 - t2; + p0 = t0 + t2; + p1 = t0 - t2; p2 = (t1 >> 1) - t3; - p3 = t1 + (t3 >> 1); + p3 = t1 + (t3 >> 1); *(pTmp++) = p0 + p3; *(pTmp++) = p1 + p2; @@ -95,9 +90,8 @@ void inverse4x4(int **tblock, int **block, int pos_y, int pos_x) *(pTmp++) = p0 - p3; } - // Vertical - for (i = 0; i < BLOCK_SIZE; i++) - { + // Vertical + for (i = 0; i < BLOCK_SIZE; i++) { pTmp = tmp + i; t0 = *pTmp; t1 = *(pTmp += BLOCK_SIZE); @@ -106,34 +100,31 @@ void inverse4x4(int **tblock, int **block, int pos_y, int pos_x) p0 = t0 + t2; p1 = t0 - t2; - p2 =(t1 >> 1) - t3; + p2 = (t1 >> 1) - t3; p3 = t1 + (t3 >> 1); ii = i + pos_x; - block[pos_y ][ii] = p0 + p3; + block[pos_y][ii] = p0 + p3; block[pos_y + 1][ii] = p1 + p2; block[pos_y + 2][ii] = p1 - p2; block[pos_y + 3][ii] = p0 - p3; } } - -void hadamard4x4(int **block, int **tblock) -{ +void hadamard4x4(int **block, int **tblock) { int i; int tmp[16]; int *pTmp = tmp, *pblock; - int p0,p1,p2,p3; - int t0,t1,t2,t3; + int p0, p1, p2, p3; + int t0, t1, t2, t3; // Horizontal - for (i = 0; i < BLOCK_SIZE; i++) - { + for (i = 0; i < BLOCK_SIZE; i++) { pblock = block[i]; p0 = *(pblock++); p1 = *(pblock++); p2 = *(pblock++); - p3 = *(pblock ); + p3 = *(pblock); t0 = p0 + p3; t1 = p1 + p2; @@ -142,13 +133,12 @@ void hadamard4x4(int **block, int **tblock) *(pTmp++) = t0 + t1; *(pTmp++) = t3 + t2; - *(pTmp++) = t0 - t1; + *(pTmp++) = t0 - t1; *(pTmp++) = t3 - t2; } - // Vertical - for (i = 0; i < BLOCK_SIZE; i++) - { + // Vertical + for (i = 0; i < BLOCK_SIZE; i++) { pTmp = tmp + i; p0 = *pTmp; p1 = *(pTmp += BLOCK_SIZE); @@ -167,23 +157,20 @@ void hadamard4x4(int **block, int **tblock) } } - -void ihadamard4x4(int **tblock, int **block) -{ - int i; +void ihadamard4x4(int **tblock, int **block) { + int i; int tmp[16]; int *pTmp = tmp, *pblock; - int p0,p1,p2,p3; - int t0,t1,t2,t3; + int p0, p1, p2, p3; + int t0, t1, t2, t3; // Horizontal - for (i = 0; i < BLOCK_SIZE; i++) - { + for (i = 0; i < BLOCK_SIZE; i++) { pblock = tblock[i]; t0 = *(pblock++); t1 = *(pblock++); t2 = *(pblock++); - t3 = *(pblock ); + t3 = *(pblock); p0 = t0 + t2; p1 = t0 - t2; @@ -196,9 +183,8 @@ void ihadamard4x4(int **tblock, int **block) *(pTmp++) = p0 - p3; } - // Vertical - for (i = 0; i < BLOCK_SIZE; i++) - { + // Vertical + for (i = 0; i < BLOCK_SIZE; i++) { pTmp = tmp + i; t0 = *pTmp; t1 = *(pTmp += BLOCK_SIZE); @@ -209,7 +195,7 @@ void ihadamard4x4(int **tblock, int **block) p1 = t0 - t2; p2 = t1 - t3; p3 = t1 + t3; - + block[0][i] = p0 + p3; block[1][i] = p1 + p2; block[2][i] = p1 - p2; @@ -217,13 +203,12 @@ void ihadamard4x4(int **tblock, int **block) } } -void hadamard4x2(int **block, int **tblock) -{ +void hadamard4x2(int **block, int **tblock) { int i; int tmp[8]; int *pTmp = tmp; - int p0,p1,p2,p3; - int t0,t1,t2,t3; + int p0, p1, p2, p3; + int t0, t1, t2, t3; // Horizontal *(pTmp++) = block[0][0] + block[1][0]; @@ -234,12 +219,11 @@ void hadamard4x2(int **block, int **tblock) *(pTmp++) = block[0][0] - block[1][0]; *(pTmp++) = block[0][1] - block[1][1]; *(pTmp++) = block[0][2] - block[1][2]; - *(pTmp ) = block[0][3] - block[1][3]; + *(pTmp) = block[0][3] - block[1][3]; // Vertical pTmp = tmp; - for (i=0;i<2;i++) - { + for (i = 0; i < 2; i++) { p0 = *(pTmp++); p1 = *(pTmp++); p2 = *(pTmp++); @@ -252,18 +236,17 @@ void hadamard4x2(int **block, int **tblock) tblock[i][0] = (t0 + t1); tblock[i][1] = (t3 + t2); - tblock[i][2] = (t0 - t1); + tblock[i][2] = (t0 - t1); tblock[i][3] = (t3 - t2); } } -void ihadamard4x2(int **tblock, int **block) -{ - int i; +void ihadamard4x2(int **tblock, int **block) { + int i; int tmp[8]; int *pTmp = tmp; - int p0,p1,p2,p3; - int t0,t1,t2,t3; + int p0, p1, p2, p3; + int t0, t1, t2, t3; // Horizontal *(pTmp++) = tblock[0][0] + tblock[1][0]; @@ -274,12 +257,11 @@ void ihadamard4x2(int **tblock, int **block) *(pTmp++) = tblock[0][0] - tblock[1][0]; *(pTmp++) = tblock[0][1] - tblock[1][1]; *(pTmp++) = tblock[0][2] - tblock[1][2]; - *(pTmp ) = tblock[0][3] - tblock[1][3]; + *(pTmp) = tblock[0][3] - tblock[1][3]; // Vertical pTmp = tmp; - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { p0 = *(pTmp++); p1 = *(pTmp++); p2 = *(pTmp++); @@ -298,25 +280,24 @@ void ihadamard4x2(int **tblock, int **block) } } -//following functions perform 8 additions, 8 assignments. Should be a bit faster -void hadamard2x2(int **block, int tblock[4]) -{ - int p0,p1,p2,p3; +// following functions perform 8 additions, 8 assignments. Should be a bit +// faster +void hadamard2x2(int **block, int tblock[4]) { + int p0, p1, p2, p3; p0 = block[0][0] + block[0][4]; p1 = block[0][0] - block[0][4]; p2 = block[4][0] + block[4][4]; p3 = block[4][0] - block[4][4]; - + tblock[0] = (p0 + p2); tblock[1] = (p1 + p3); tblock[2] = (p0 - p2); tblock[3] = (p1 - p3); } -void ihadamard2x2(int tblock[4], int block[4]) -{ - int t0,t1,t2,t3; +void ihadamard2x2(int tblock[4], int block[4]) { + int t0, t1, t2, t3; t0 = tblock[0] + tblock[1]; t1 = tblock[0] - tblock[1]; @@ -349,19 +330,16 @@ void ihadamard2x2(int tblock[4], int block[4]) */ - -void forward8x8(int **block, int **tblock, int pos_y, int pos_x) -{ - int i, ii; +void forward8x8(int **block, int **tblock, int pos_y, int pos_x) { + int i, ii; int tmp[64]; int *pTmp = tmp, *pblock; int a0, a1, a2, a3; - int p0, p1, p2, p3, p4, p5 ,p6, p7; + int p0, p1, p2, p3, p4, p5, p6, p7; int b0, b1, b2, b3, b4, b5, b6, b7; // Horizontal - for (i=pos_y; i < pos_y + BLOCK_SIZE_8x8; i++) - { + for (i = pos_y; i < pos_y + BLOCK_SIZE_8x8; i++) { pblock = &block[i][pos_x]; p0 = *(pblock++); p1 = *(pblock++); @@ -370,7 +348,7 @@ void forward8x8(int **block, int **tblock, int pos_y, int pos_x) p4 = *(pblock++); p5 = *(pblock++); p6 = *(pblock++); - p7 = *(pblock ); + p7 = *(pblock); a0 = p0 + p7; a1 = p1 + p6; @@ -392,19 +370,18 @@ void forward8x8(int **block, int **tblock, int pos_y, int pos_x) b6 = a0 + a3 - ((a1 >> 1) + a1); b7 = a1 - a2 + ((a3 >> 1) + a3); - *(pTmp++) = b0 + b1; - *(pTmp++) = b4 + (b7 >> 2); - *(pTmp++) = b2 + (b3 >> 1); - *(pTmp++) = b5 + (b6 >> 2); - *(pTmp++) = b0 - b1; - *(pTmp++) = b6 - (b5 >> 2); - *(pTmp++) = (b2 >> 1) - b3; + *(pTmp++) = b0 + b1; + *(pTmp++) = b4 + (b7 >> 2); + *(pTmp++) = b2 + (b3 >> 1); + *(pTmp++) = b5 + (b6 >> 2); + *(pTmp++) = b0 - b1; + *(pTmp++) = b6 - (b5 >> 2); + *(pTmp++) = (b2 >> 1) - b3; *(pTmp++) = (b4 >> 2) - b7; } - // Vertical - for (i=0; i < BLOCK_SIZE_8x8; i++) - { + // Vertical + for (i = 0; i < BLOCK_SIZE_8x8; i++) { pTmp = tmp + i; p0 = *pTmp; p1 = *(pTmp += BLOCK_SIZE_8x8); @@ -436,29 +413,27 @@ void forward8x8(int **block, int **tblock, int pos_y, int pos_x) b7 = a1 - a2 + ((a3 >> 1) + a3); ii = pos_x + i; - tblock[pos_y ][ii] = b0 + b1; - tblock[pos_y + 1][ii] = b4 + (b7 >> 2); - tblock[pos_y + 2][ii] = b2 + (b3 >> 1); - tblock[pos_y + 3][ii] = b5 + (b6 >> 2); - tblock[pos_y + 4][ii] = b0 - b1; - tblock[pos_y + 5][ii] = b6 - (b5 >> 2); + tblock[pos_y][ii] = b0 + b1; + tblock[pos_y + 1][ii] = b4 + (b7 >> 2); + tblock[pos_y + 2][ii] = b2 + (b3 >> 1); + tblock[pos_y + 3][ii] = b5 + (b6 >> 2); + tblock[pos_y + 4][ii] = b0 - b1; + tblock[pos_y + 5][ii] = b6 - (b5 >> 2); tblock[pos_y + 6][ii] = (b2 >> 1) - b3; tblock[pos_y + 7][ii] = (b4 >> 2) - b7; } } -void inverse8x8(int **tblock, int **block, int pos_y, int pos_x) -{ +void inverse8x8(int **tblock, int **block, int pos_y, int pos_x) { int i, ii; int tmp[64]; int *pTmp = tmp, *pblock; int a0, a1, a2, a3; - int p0, p1, p2, p3, p4, p5 ,p6, p7; + int p0, p1, p2, p3, p4, p5, p6, p7; int b0, b1, b2, b3, b4, b5, b6, b7; - // Horizontal - for (i=pos_y; i < pos_y + BLOCK_SIZE_8x8; i++) - { + // Horizontal + for (i = pos_y; i < pos_y + BLOCK_SIZE_8x8; i++) { pblock = &tblock[i][pos_x]; p0 = *(pblock++); p1 = *(pblock++); @@ -467,28 +442,27 @@ void inverse8x8(int **tblock, int **block, int pos_y, int pos_x) p4 = *(pblock++); p5 = *(pblock++); p6 = *(pblock++); - p7 = *(pblock ); + p7 = *(pblock); a0 = p0 + p4; a1 = p0 - p4; a2 = p6 - (p2 >> 1); a3 = p2 + (p6 >> 1); - b0 = a0 + a3; - b2 = a1 - a2; - b4 = a1 + a2; - b6 = a0 - a3; + b0 = a0 + a3; + b2 = a1 - a2; + b4 = a1 + a2; + b6 = a0 - a3; - a0 = -p3 + p5 - p7 - (p7 >> 1); - a1 = p1 + p7 - p3 - (p3 >> 1); - a2 = -p1 + p7 + p5 + (p5 >> 1); - a3 = p3 + p5 + p1 + (p1 >> 1); + a0 = -p3 + p5 - p7 - (p7 >> 1); + a1 = p1 + p7 - p3 - (p3 >> 1); + a2 = -p1 + p7 + p5 + (p5 >> 1); + a3 = p3 + p5 + p1 + (p1 >> 1); - - b1 = a0 + (a3>>2); - b3 = a1 + (a2>>2); - b5 = a2 - (a1>>2); - b7 = a3 - (a0>>2); + b1 = a0 + (a3 >> 2); + b3 = a1 + (a2 >> 2); + b5 = a2 - (a1 >> 2); + b7 = a3 - (a0 >> 2); *(pTmp++) = b0 + b7; *(pTmp++) = b2 - b5; @@ -500,9 +474,8 @@ void inverse8x8(int **tblock, int **block, int pos_y, int pos_x) *(pTmp++) = b0 - b7; } - // Vertical - for (i=0; i < BLOCK_SIZE_8x8; i++) - { + // Vertical + for (i = 0; i < BLOCK_SIZE_8x8; i++) { pTmp = tmp + i; p0 = *pTmp; p1 = *(pTmp += BLOCK_SIZE_8x8); @@ -513,10 +486,10 @@ void inverse8x8(int **tblock, int **block, int pos_y, int pos_x) p6 = *(pTmp += BLOCK_SIZE_8x8); p7 = *(pTmp += BLOCK_SIZE_8x8); - a0 = p0 + p4; - a1 = p0 - p4; - a2 = p6 - (p2>>1); - a3 = p2 + (p6>>1); + a0 = p0 + p4; + a1 = p0 - p4; + a2 = p6 - (p2 >> 1); + a3 = p2 + (p6 >> 1); b0 = a0 + a3; b2 = a1 - a2; @@ -524,18 +497,17 @@ void inverse8x8(int **tblock, int **block, int pos_y, int pos_x) b6 = a0 - a3; a0 = -p3 + p5 - p7 - (p7 >> 1); - a1 = p1 + p7 - p3 - (p3 >> 1); + a1 = p1 + p7 - p3 - (p3 >> 1); a2 = -p1 + p7 + p5 + (p5 >> 1); - a3 = p3 + p5 + p1 + (p1 >> 1); + a3 = p3 + p5 + p1 + (p1 >> 1); - - b1 = a0 + (a3 >> 2); - b7 = a3 - (a0 >> 2); - b3 = a1 + (a2 >> 2); - b5 = a2 - (a1 >> 2); + b1 = a0 + (a3 >> 2); + b7 = a3 - (a0 >> 2); + b3 = a1 + (a2 >> 2); + b5 = a2 - (a1 >> 2); ii = i + pos_x; - block[pos_y ][ii] = b0 + b7; + block[pos_y][ii] = b0 + b7; block[pos_y + 1][ii] = b2 - b5; block[pos_y + 2][ii] = b4 + b3; block[pos_y + 3][ii] = b6 + b1; @@ -545,4 +517,3 @@ void inverse8x8(int **tblock, int **block, int pos_y, int pos_x) block[pos_y + 7][ii] = b0 - b7; } } - diff --git a/src/common/ldecod_src/transform8x8.c b/src/common/ldecod_src/transform8x8.c index af58ca1..de19580 100644 --- a/src/common/ldecod_src/transform8x8.c +++ b/src/common/ldecod_src/transform8x8.c @@ -7,7 +7,8 @@ * 8x8 transform functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Yuri Vatis * - Jan Muenster * @@ -18,44 +19,51 @@ #include "global.h" +#include "elements.h" #include "image.h" #include "mb_access.h" -#include "elements.h" -#include "transform8x8.h" -#include "transform.h" #include "quant.h" +#include "transform.h" +#include "transform8x8.h" -static void recon8x8(int **m7, imgpel **mb_rec, imgpel **mpr, int max_imgpel_value, int ioff) -{ +static void recon8x8(int **m7, imgpel **mb_rec, imgpel **mpr, + int max_imgpel_value, int ioff) { int j; - int *m_tr = NULL; + int *m_tr = NULL; imgpel *m_rec = NULL; imgpel *m_prd = NULL; - for( j = 0; j < 8; j++) - { + for (j = 0; j < 8; j++) { m_tr = (*m7++) + ioff; m_rec = (*mb_rec++) + ioff; m_prd = (*mpr++) + ioff; - *m_rec++ = (imgpel) iClip1(max_imgpel_value, (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); - *m_rec++ = (imgpel) iClip1(max_imgpel_value, (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); - *m_rec++ = (imgpel) iClip1(max_imgpel_value, (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); - *m_rec++ = (imgpel) iClip1(max_imgpel_value, (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); - *m_rec++ = (imgpel) iClip1(max_imgpel_value, (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); - *m_rec++ = (imgpel) iClip1(max_imgpel_value, (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); - *m_rec++ = (imgpel) iClip1(max_imgpel_value, (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); - *m_rec = (imgpel) iClip1(max_imgpel_value, (*m_prd ) + rshift_rnd_sf(*m_tr , DQ_BITS_8)); + *m_rec++ = (imgpel)iClip1(max_imgpel_value, + (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); + *m_rec++ = (imgpel)iClip1(max_imgpel_value, + (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); + *m_rec++ = (imgpel)iClip1(max_imgpel_value, + (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); + *m_rec++ = (imgpel)iClip1(max_imgpel_value, + (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); + *m_rec++ = (imgpel)iClip1(max_imgpel_value, + (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); + *m_rec++ = (imgpel)iClip1(max_imgpel_value, + (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); + *m_rec++ = (imgpel)iClip1(max_imgpel_value, + (*m_prd++) + rshift_rnd_sf(*m_tr++, DQ_BITS_8)); + *m_rec = (imgpel)iClip1(max_imgpel_value, + (*m_prd) + rshift_rnd_sf(*m_tr, DQ_BITS_8)); } } -static void recon8x8_lossless(int **m7, imgpel **mb_rec, imgpel **mpr, int max_imgpel_value, int ioff) -{ +static void recon8x8_lossless(int **m7, imgpel **mb_rec, imgpel **mpr, + int max_imgpel_value, int ioff) { int i, j; - for( j = 0; j < 8; j++) - { - for( i = ioff; i < ioff + 8; i++) - (*mb_rec)[i] = (imgpel) iClip1(max_imgpel_value, ((*m7)[i] + (long)(*mpr)[i])); + for (j = 0; j < 8; j++) { + for (i = ioff; i < ioff + 8; i++) + (*mb_rec)[i] = + (imgpel)iClip1(max_imgpel_value, ((*m7)[i] + (long)(*mpr)[i])); mb_rec++; m7++; mpr++; @@ -67,23 +75,24 @@ static void recon8x8_lossless(int **m7, imgpel **mb_rec, imgpel **mpr, int max_i * \brief * Inverse 8x8 transformation *********************************************************************** - */ -void itrans8x8(Macroblock *currMB, //!< current macroblock - ColorPlane pl, //!< used color plane - int ioff, //!< index to 4x4 block - int joff) //!< index to 4x4 block + */ +void itrans8x8(Macroblock *currMB, //!< current macroblock + ColorPlane pl, //!< used color plane + int ioff, //!< index to 4x4 block + int joff) //!< index to 4x4 block { Slice *currSlice = currMB->p_Slice; - int **m7 = currSlice->mb_rres[pl]; + int **m7 = currSlice->mb_rres[pl]; - if (currMB->is_lossless == TRUE) - { - recon8x8_lossless(&m7[joff], &currSlice->mb_rec[pl][joff], &currSlice->mb_pred[pl][joff], currMB->p_Vid->max_pel_value_comp[pl], ioff); - } - else - { + if (currMB->is_lossless == TRUE) { + recon8x8_lossless(&m7[joff], &currSlice->mb_rec[pl][joff], + &currSlice->mb_pred[pl][joff], + currMB->p_Vid->max_pel_value_comp[pl], ioff); + } else { inverse8x8(m7, m7, joff, ioff); - recon8x8 (&m7[joff], &currSlice->mb_rec[pl][joff], &currSlice->mb_pred[pl][joff], currMB->p_Vid->max_pel_value_comp[pl], ioff); + recon8x8(&m7[joff], &currSlice->mb_rec[pl][joff], + &currSlice->mb_pred[pl][joff], + currMB->p_Vid->max_pel_value_comp[pl], ioff); } } diff --git a/src/common/ldecod_src/vlc.c b/src/common/ldecod_src/vlc.c index f9741bd..068e6ce 100644 --- a/src/common/ldecod_src/vlc.c +++ b/src/common/ldecod_src/vlc.c @@ -6,7 +6,8 @@ * VLC support functions * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Inge Lille-Langy * - Detlev Marpe * - Gabi Blaettermann @@ -14,14 +15,13 @@ */ #include "contributors.h" +#include "elements.h" #include "global.h" #include "vlc.h" -#include "elements.h" - // A little trick to avoid those horrible #if TRACE all over the source code #if TRACE -#define SYMTRACESTRING(s) strncpy(symbol.tracestring,s,TRACESTRING_SIZE) +#define SYMTRACESTRING(s) strncpy(symbol.tracestring, s, TRACESTRING_SIZE) #else #define SYMTRACESTRING(s) // do nothing #endif @@ -45,20 +45,18 @@ * ************************************************************************************* */ -int ue_v (char *tracestring, Bitstream *bitstream) -{ +int ue_v(char *tracestring, Bitstream *bitstream) { SyntaxElement symbol; - //assert (bitstream->streamBuffer != NULL); + // assert (bitstream->streamBuffer != NULL); symbol.type = SE_HEADER; - symbol.mapping = linfo_ue; // Mapping rule + symbol.mapping = linfo_ue; // Mapping rule SYMTRACESTRING(tracestring); - readSyntaxElement_VLC (&symbol, bitstream); - p_Dec->UsedBits+=symbol.len; + readSyntaxElement_VLC(&symbol, bitstream); + p_Dec->UsedBits += symbol.len; return symbol.value1; } - /*! ************************************************************************************* * \brief @@ -76,20 +74,18 @@ int ue_v (char *tracestring, Bitstream *bitstream) * ************************************************************************************* */ -int se_v (char *tracestring, Bitstream *bitstream) -{ +int se_v(char *tracestring, Bitstream *bitstream) { SyntaxElement symbol; - //assert (bitstream->streamBuffer != NULL); + // assert (bitstream->streamBuffer != NULL); symbol.type = SE_HEADER; - symbol.mapping = linfo_se; // Mapping rule: signed integer + symbol.mapping = linfo_se; // Mapping rule: signed integer SYMTRACESTRING(tracestring); - readSyntaxElement_VLC (&symbol, bitstream); - p_Dec->UsedBits+=symbol.len; + readSyntaxElement_VLC(&symbol, bitstream); + p_Dec->UsedBits += symbol.len; return symbol.value1; } - /*! ************************************************************************************* * \brief @@ -110,18 +106,17 @@ int se_v (char *tracestring, Bitstream *bitstream) * ************************************************************************************* */ -int u_v (int LenInBits, char*tracestring, Bitstream *bitstream) -{ +int u_v(int LenInBits, char *tracestring, Bitstream *bitstream) { SyntaxElement symbol; symbol.inf = 0; - //assert (bitstream->streamBuffer != NULL); + // assert (bitstream->streamBuffer != NULL); symbol.type = SE_HEADER; - symbol.mapping = linfo_ue; // Mapping rule + symbol.mapping = linfo_ue; // Mapping rule symbol.len = LenInBits; SYMTRACESTRING(tracestring); - readSyntaxElement_FLC (&symbol, bitstream); - p_Dec->UsedBits+=symbol.len; + readSyntaxElement_FLC(&symbol, bitstream); + p_Dec->UsedBits += symbol.len; return symbol.inf; } @@ -146,26 +141,24 @@ int u_v (int LenInBits, char*tracestring, Bitstream *bitstream) * ************************************************************************************* */ -int i_v (int LenInBits, char*tracestring, Bitstream *bitstream) -{ +int i_v(int LenInBits, char *tracestring, Bitstream *bitstream) { SyntaxElement symbol; symbol.inf = 0; - //assert (bitstream->streamBuffer != NULL); + // assert (bitstream->streamBuffer != NULL); symbol.type = SE_HEADER; - symbol.mapping = linfo_ue; // Mapping rule + symbol.mapping = linfo_ue; // Mapping rule symbol.len = LenInBits; SYMTRACESTRING(tracestring); - readSyntaxElement_FLC (&symbol, bitstream); - p_Dec->UsedBits+=symbol.len; + readSyntaxElement_FLC(&symbol, bitstream); + p_Dec->UsedBits += symbol.len; // can be negative - symbol.inf = -( symbol.inf & (1 << (LenInBits - 1)) ) | symbol.inf; + symbol.inf = -(symbol.inf & (1 << (LenInBits - 1))) | symbol.inf; return symbol.inf; } - /*! ************************************************************************************* * \brief @@ -183,13 +176,10 @@ int i_v (int LenInBits, char*tracestring, Bitstream *bitstream) * ************************************************************************************* */ -Boolean u_1 (char *tracestring, Bitstream *bitstream) -{ - return (Boolean) u_v (1, tracestring, bitstream); +Boolean u_1(char *tracestring, Bitstream *bitstream) { + return (Boolean)u_v(1, tracestring, bitstream); } - - /*! ************************************************************************ * \brief @@ -200,10 +190,9 @@ Boolean u_1 (char *tracestring, Bitstream *bitstream) * number in the code table ************************************************************************ */ -void linfo_ue(int len, int info, int *value1, int *dummy) -{ - //assert ((len >> 1) < 32); - *value1 = (int) (((unsigned int) 1 << (len >> 1)) + (unsigned int) (info) - 1); +void linfo_ue(int len, int info, int *value1, int *dummy) { + // assert ((len >> 1) < 32); + *value1 = (int)(((unsigned int)1 << (len >> 1)) + (unsigned int)(info)-1); } /*! @@ -216,16 +205,14 @@ void linfo_ue(int len, int info, int *value1, int *dummy) * signed mvd ************************************************************************ */ -void linfo_se(int len, int info, int *value1, int *dummy) -{ - //assert ((len >> 1) < 32); - unsigned int n = ((unsigned int) 1 << (len >> 1)) + (unsigned int) info - 1; +void linfo_se(int len, int info, int *value1, int *dummy) { + // assert ((len >> 1) < 32); + unsigned int n = ((unsigned int)1 << (len >> 1)) + (unsigned int)info - 1; *value1 = (n + 1) >> 1; - if((n & 0x01) == 0) // lsb is signed bit + if ((n & 0x01) == 0) // lsb is signed bit *value1 = -*value1; } - /*! ************************************************************************ * \par Input: @@ -234,15 +221,13 @@ void linfo_se(int len, int info, int *value1, int *dummy) * cbp (intra) ************************************************************************ */ -void linfo_cbp_intra_normal(int len,int info,int *cbp, int *dummy) -{ +void linfo_cbp_intra_normal(int len, int info, int *cbp, int *dummy) { int cbp_idx; linfo_ue(len, info, &cbp_idx, dummy); - *cbp=NCBP[1][cbp_idx][0]; + *cbp = NCBP[1][cbp_idx][0]; } - /*! ************************************************************************ * \par Input: @@ -251,12 +236,11 @@ void linfo_cbp_intra_normal(int len,int info,int *cbp, int *dummy) * cbp (intra) ************************************************************************ */ -void linfo_cbp_intra_other(int len,int info,int *cbp, int *dummy) -{ +void linfo_cbp_intra_other(int len, int info, int *cbp, int *dummy) { int cbp_idx; linfo_ue(len, info, &cbp_idx, dummy); - *cbp=NCBP[0][cbp_idx][0]; + *cbp = NCBP[0][cbp_idx][0]; } /*! @@ -267,12 +251,11 @@ void linfo_cbp_intra_other(int len,int info,int *cbp, int *dummy) * cbp (inter) ************************************************************************ */ -void linfo_cbp_inter_normal(int len,int info,int *cbp, int *dummy) -{ +void linfo_cbp_inter_normal(int len, int info, int *cbp, int *dummy) { int cbp_idx; linfo_ue(len, info, &cbp_idx, dummy); - *cbp=NCBP[1][cbp_idx][1]; + *cbp = NCBP[1][cbp_idx][1]; } /*! @@ -283,12 +266,11 @@ void linfo_cbp_inter_normal(int len,int info,int *cbp, int *dummy) * cbp (inter) ************************************************************************ */ -void linfo_cbp_inter_other(int len,int info,int *cbp, int *dummy) -{ +void linfo_cbp_inter_other(int len, int info, int *cbp, int *dummy) { int cbp_idx; linfo_ue(len, info, &cbp_idx, dummy); - *cbp=NCBP[0][cbp_idx][1]; + *cbp = NCBP[0][cbp_idx][1]; } /*! @@ -299,33 +281,29 @@ void linfo_cbp_inter_other(int len,int info,int *cbp, int *dummy) * level, run ************************************************************************ */ -void linfo_levrun_inter(int len, int info, int *level, int *irun) -{ - //assert (((len >> 1) - 5) < 32); +void linfo_levrun_inter(int len, int info, int *level, int *irun) { + // assert (((len >> 1) - 5) < 32); - if (len <= 9) - { - int l2 = imax(0,(len >> 1)-1); - int inf = info >> 1; + if (len <= 9) { + int l2 = imax(0, (len >> 1) - 1); + int inf = info >> 1; *level = NTAB1[l2][inf][0]; - *irun = NTAB1[l2][inf][1]; + *irun = NTAB1[l2][inf][1]; if ((info & 0x01) == 1) - *level = -*level; // make sign - } - else // if len > 9, skip using the array + *level = -*level; // make sign + } else // if len > 9, skip using the array { - *irun = (info & 0x1e) >> 1; - *level = LEVRUN1[*irun] + (info >> 5) + ( 1 << ((len >> 1) - 5)); + *irun = (info & 0x1e) >> 1; + *level = LEVRUN1[*irun] + (info >> 5) + (1 << ((len >> 1) - 5)); if ((info & 0x01) == 1) *level = -*level; } - + if (len == 1) // EOB *level = 0; } - /*! ************************************************************************ * \par Input: @@ -334,25 +312,22 @@ void linfo_levrun_inter(int len, int info, int *level, int *irun) * level, run ************************************************************************ */ -void linfo_levrun_c2x2(int len, int info, int *level, int *irun) -{ - if (len<=5) - { - int l2 = imax(0, (len >> 1) - 1); - int inf = info >> 1; +void linfo_levrun_c2x2(int len, int info, int *level, int *irun) { + if (len <= 5) { + int l2 = imax(0, (len >> 1) - 1); + int inf = info >> 1; *level = NTAB3[l2][inf][0]; - *irun = NTAB3[l2][inf][1]; + *irun = NTAB3[l2][inf][1]; if ((info & 0x01) == 1) - *level = -*level; // make sign - } - else // if len > 5, skip using the array + *level = -*level; // make sign + } else // if len > 5, skip using the array { - *irun = (info & 0x06) >> 1; + *irun = (info & 0x06) >> 1; *level = LEVRUN3[*irun] + (info >> 3) + (1 << ((len >> 1) - 3)); if ((info & 0x01) == 1) *level = -*level; } - + if (len == 1) // EOB *level = 0; } @@ -364,10 +339,10 @@ void linfo_levrun_c2x2(int len, int info, int *level, int *irun) * map it to the corresponding syntax element ************************************************************************ */ -int readSyntaxElement_VLC(SyntaxElement *sym, Bitstream *currStream) -{ +int readSyntaxElement_VLC(SyntaxElement *sym, Bitstream *currStream) { - sym->len = GetVLCSymbol (currStream->streamBuffer, currStream->frame_bitoffset, &(sym->inf), currStream->bitstream_length); + sym->len = GetVLCSymbol(currStream->streamBuffer, currStream->frame_bitoffset, + &(sym->inf), currStream->bitstream_length); if (sym->len == -1) return -1; @@ -381,7 +356,6 @@ int readSyntaxElement_VLC(SyntaxElement *sym, Bitstream *currStream) return 1; } - /*! ************************************************************************ * \brief @@ -389,8 +363,8 @@ int readSyntaxElement_VLC(SyntaxElement *sym, Bitstream *currStream) * map it to the corresponding syntax element ************************************************************************ */ -int readSyntaxElement_UVLC(Macroblock *currMB, SyntaxElement *sym, struct datapartition *dP) -{ +int readSyntaxElement_UVLC(Macroblock *currMB, SyntaxElement *sym, + struct datapartition *dP) { return (readSyntaxElement_VLC(sym, dP->bitstream)); } @@ -401,15 +375,17 @@ int readSyntaxElement_UVLC(Macroblock *currMB, SyntaxElement *sym, struct datapa * map it to the corresponding Intra Prediction Direction ************************************************************************ */ -int readSyntaxElement_Intra4x4PredictionMode(SyntaxElement *sym, Bitstream *currStream) -{ - sym->len = GetVLCSymbol_IntraMode (currStream->streamBuffer, currStream->frame_bitoffset, &(sym->inf), currStream->bitstream_length); +int readSyntaxElement_Intra4x4PredictionMode(SyntaxElement *sym, + Bitstream *currStream) { + sym->len = GetVLCSymbol_IntraMode(currStream->streamBuffer, + currStream->frame_bitoffset, &(sym->inf), + currStream->bitstream_length); if (sym->len == -1) return -1; currStream->frame_bitoffset += sym->len; - sym->value1 = (sym->len == 1) ? -1 : sym->inf; + sym->value1 = (sym->len == 1) ? -1 : sym->inf; #if TRACE tracebits2(sym->tracestring, sym->len, sym->value1); @@ -418,37 +394,33 @@ int readSyntaxElement_Intra4x4PredictionMode(SyntaxElement *sym, Bitstream *cu return 1; } -int GetVLCSymbol_IntraMode (byte buffer[],int totbitoffset,int *info, int bytecount) -{ +int GetVLCSymbol_IntraMode(byte buffer[], int totbitoffset, int *info, + int bytecount) { int byteoffset = (totbitoffset >> 3); // byte from start of buffer - int bitoffset = (7 - (totbitoffset & 0x07)); // bit from start of byte - byte *cur_byte = &(buffer[byteoffset]); - int ctr_bit = (*cur_byte & (0x01 << bitoffset)); // control bit for current bit posision + int bitoffset = (7 - (totbitoffset & 0x07)); // bit from start of byte + byte *cur_byte = &(buffer[byteoffset]); + int ctr_bit = + (*cur_byte & (0x01 << bitoffset)); // control bit for current bit posision - //First bit - if (ctr_bit) - { + // First bit + if (ctr_bit) { *info = 0; return 1; } - if (byteoffset >= bytecount) - { + if (byteoffset >= bytecount) { return -1; - } - else - { + } else { int inf = (*(cur_byte) << 8) + *(cur_byte + 1); inf <<= (sizeof(byte) * 8) - bitoffset; inf = inf & 0xFFFF; inf >>= (sizeof(byte) * 8) * 2 - 3; *info = inf; - return 4; // return absolute offset in bit from start of frame - } + return 4; // return absolute offset in bit from start of frame + } } - /*! ************************************************************************ * \brief @@ -464,31 +436,28 @@ int GetVLCSymbol_IntraMode (byte buffer[],int totbitoffset,int *info, int byteco * true if more bits available ************************************************************************ */ -int more_rbsp_data (byte buffer[],int totbitoffset,int bytecount) -{ - long byteoffset = (totbitoffset >> 3); // byte from start of buffer +int more_rbsp_data(byte buffer[], int totbitoffset, int bytecount) { + long byteoffset = (totbitoffset >> 3); // byte from start of buffer // there is more until we're in the last byte - if (byteoffset < (bytecount - 1)) + if (byteoffset < (bytecount - 1)) return TRUE; - else - { - int bitoffset = (7 - (totbitoffset & 0x07)); // bit from start of byte - byte *cur_byte = &(buffer[byteoffset]); + else { + int bitoffset = (7 - (totbitoffset & 0x07)); // bit from start of byte + byte *cur_byte = &(buffer[byteoffset]); // read one bit - int ctr_bit = ctr_bit = ((*cur_byte)>> (bitoffset--)) & 0x01; // control bit for current bit posision + int ctr_bit = ctr_bit = ((*cur_byte) >> (bitoffset--)) & + 0x01; // control bit for current bit posision - //assert (byteoffset=0 && !cnt) - { - cnt |= ((*cur_byte)>> (bitoffset--)) & 0x01; // set up control bit + while (bitoffset >= 0 && !cnt) { + cnt |= ((*cur_byte) >> (bitoffset--)) & 0x01; // set up control bit } return (cnt); @@ -496,25 +465,22 @@ int more_rbsp_data (byte buffer[],int totbitoffset,int bytecount) } } - /*! ************************************************************************ * \brief * Check if there are symbols for the next MB ************************************************************************ */ -int uvlc_startcode_follows(Slice *currSlice, int dummy) -{ - byte dp_Nr = assignSE2partition[currSlice->dp_mode][SE_MBTYPE]; - DataPartition *dP = &(currSlice->partArr[dp_Nr]); +int uvlc_startcode_follows(Slice *currSlice, int dummy) { + byte dp_Nr = assignSE2partition[currSlice->dp_mode][SE_MBTYPE]; + DataPartition *dP = &(currSlice->partArr[dp_Nr]); Bitstream *currStream = dP->bitstream; - byte *buf = currStream->streamBuffer; + byte *buf = currStream->streamBuffer; - return (!(more_rbsp_data(buf, currStream->frame_bitoffset,currStream->bitstream_length))); + return (!(more_rbsp_data(buf, currStream->frame_bitoffset, + currStream->bitstream_length))); } - - /*! ************************************************************************ * \brief @@ -532,49 +498,45 @@ int uvlc_startcode_follows(Slice *currSlice, int dummy) * bits read ************************************************************************ */ -int GetVLCSymbol (byte buffer[],int totbitoffset,int *info, int bytecount) -{ - long byteoffset = (totbitoffset >> 3); // byte from start of buffer - int bitoffset = (7 - (totbitoffset & 0x07)); // bit from start of byte - int bitcounter = 1; - int len = 0; - byte *cur_byte = &(buffer[byteoffset]); - int ctr_bit = ((*cur_byte) >> (bitoffset)) & 0x01; // control bit for current bit posision +int GetVLCSymbol(byte buffer[], int totbitoffset, int *info, int bytecount) { + long byteoffset = (totbitoffset >> 3); // byte from start of buffer + int bitoffset = (7 - (totbitoffset & 0x07)); // bit from start of byte + int bitcounter = 1; + int len = 0; + byte *cur_byte = &(buffer[byteoffset]); + int ctr_bit = ((*cur_byte) >> (bitoffset)) & + 0x01; // control bit for current bit posision - while (ctr_bit == 0) - { // find leading 1 bit + while (ctr_bit == 0) { // find leading 1 bit len++; bitcounter++; bitoffset--; bitoffset &= 0x07; - cur_byte += (bitoffset == 7); - byteoffset+= (bitoffset == 7); - ctr_bit = ((*cur_byte) >> (bitoffset)) & 0x01; + cur_byte += (bitoffset == 7); + byteoffset += (bitoffset == 7); + ctr_bit = ((*cur_byte) >> (bitoffset)) & 0x01; } if (byteoffset + ((len + 7) >> 3) > bytecount) return -1; - else - { + else { // make infoword - int inf = 0; // shortest possible code is 1, then info is always 0 + int inf = 0; // shortest possible code is 1, then info is always 0 - while (len--) - { - bitoffset --; + while (len--) { + bitoffset--; bitoffset &= 0x07; - cur_byte += (bitoffset == 7); + cur_byte += (bitoffset == 7); bitcounter++; - inf <<= 1; + inf <<= 1; inf |= ((*cur_byte) >> (bitoffset)) & 0x01; } *info = inf; - return bitcounter; // return absolute offset in bit from start of frame + return bitcounter; // return absolute offset in bit from start of frame } } - /*! ************************************************************************ * \brief @@ -588,26 +550,25 @@ int GetVLCSymbol (byte buffer[],int totbitoffset,int *info, int bytecount) ************************************************************************ */ -//static inline int ShowBitsThres (int inf, int bitcount, int numbits) -static inline int ShowBitsThres (int inf, int numbits) -{ +// static inline int ShowBitsThres (int inf, int bitcount, int numbits) +static inline int ShowBitsThres(int inf, int numbits) { return ((inf) >> ((sizeof(byte) * 24) - (numbits))); /* - if ((numbits + 7) > bitcount) + if ((numbits + 7) > bitcount) { return -1; } - else + else { //Worst case scenario is that we will need to traverse 3 bytes inf >>= (sizeof(byte)*8)*3 - numbits; } - - return inf; //Will be a small unsigned integer so will not need any conversion when returning as int + + return inf; //Will be a small unsigned integer so will not need any conversion + when returning as int */ } - /*! ************************************************************************ * \brief @@ -615,61 +576,56 @@ static inline int ShowBitsThres (int inf, int numbits) ************************************************************************ */ -static int code_from_bitstream_2d(SyntaxElement *sym, - Bitstream *currStream, - const byte *lentab, - const byte *codtab, - int tabwidth, - int tabheight, - int *code) -{ +static int code_from_bitstream_2d(SyntaxElement *sym, Bitstream *currStream, + const byte *lentab, const byte *codtab, + int tabwidth, int tabheight, int *code) { int i, j; const byte *len = &lentab[0], *cod = &codtab[0]; int *frame_bitoffset = &currStream->frame_bitoffset; - byte *buf = &currStream->streamBuffer[*frame_bitoffset >> 3]; + byte *buf = &currStream->streamBuffer[*frame_bitoffset >> 3]; + + // Apply bitoffset to three bytes (maximum that may be traversed by + // ShowBitsThres) + unsigned int inf = + ((*buf) << 16) + (*(buf + 1) << 8) + + *(buf + 2); // Even at the end of a stream we will still be pulling out of + // allocated memory as alloc is done by MAX_CODED_FRAME_SIZE + inf <<= (*frame_bitoffset & 0x07); // Offset is constant so apply before + // extracting different numbers of bits + inf &= 0xFFFFFF; // Arithmetic shift so wipe any sign which may be extended + // inside ShowBitsThres - //Apply bitoffset to three bytes (maximum that may be traversed by ShowBitsThres) - unsigned int inf = ((*buf) << 16) + (*(buf + 1) << 8) + *(buf + 2); //Even at the end of a stream we will still be pulling out of allocated memory as alloc is done by MAX_CODED_FRAME_SIZE - inf <<= (*frame_bitoffset & 0x07); //Offset is constant so apply before extracting different numbers of bits - inf &= 0xFFFFFF; //Arithmetic shift so wipe any sign which may be extended inside ShowBitsThres - // this VLC decoding method is not optimized for speed - for (j = 0; j < tabheight; j++) - { - for (i = 0; i < tabwidth; i++) - { - if ((*len == 0) || (ShowBitsThres(inf, (int) *len) != *cod)) - { + for (j = 0; j < tabheight; j++) { + for (i = 0; i < tabwidth; i++) { + if ((*len == 0) || (ShowBitsThres(inf, (int)*len) != *cod)) { ++len; ++cod; - } - else - { + } else { sym->len = *len; *frame_bitoffset += *len; // move bitstream pointer - *code = *cod; + *code = *cod; sym->value1 = i; - sym->value2 = j; - return 0; // found code and return + sym->value2 = j; + return 0; // found code and return } } } - return -1; // failed to find code + return -1; // failed to find code } - /*! ************************************************************************ * \brief * read FLC codeword from UVLC-partition ************************************************************************ */ -int readSyntaxElement_FLC(SyntaxElement *sym, Bitstream *currStream) -{ - int BitstreamLengthInBits = (currStream->bitstream_length << 3) + 7; - - if ((GetBits(currStream->streamBuffer, currStream->frame_bitoffset, &(sym->inf), BitstreamLengthInBits, sym->len)) < 0) +int readSyntaxElement_FLC(SyntaxElement *sym, Bitstream *currStream) { + int BitstreamLengthInBits = (currStream->bitstream_length << 3) + 7; + + if ((GetBits(currStream->streamBuffer, currStream->frame_bitoffset, + &(sym->inf), BitstreamLengthInBits, sym->len)) < 0) return -1; sym->value1 = sym->inf; @@ -682,8 +638,6 @@ int readSyntaxElement_FLC(SyntaxElement *sym, Bitstream *currStream) return 1; } - - /*! ************************************************************************ * \brief @@ -691,57 +645,55 @@ int readSyntaxElement_FLC(SyntaxElement *sym, Bitstream *currStream) ************************************************************************ */ -int readSyntaxElement_NumCoeffTrailingOnes(SyntaxElement *sym, +int readSyntaxElement_NumCoeffTrailingOnes(SyntaxElement *sym, Bitstream *currStream, - signed char *type) -{ - int frame_bitoffset = currStream->frame_bitoffset; + signed char *type) { + int frame_bitoffset = currStream->frame_bitoffset; int BitstreamLengthInBytes = currStream->bitstream_length; - int BitstreamLengthInBits = (BitstreamLengthInBytes << 3) + 7; - byte *buf = currStream->streamBuffer; + int BitstreamLengthInBits = (BitstreamLengthInBytes << 3) + 7; + byte *buf = currStream->streamBuffer; - static const byte lentab[3][4][17] = - { - { // 0702 - { 1, 6, 8, 9,10,11,13,13,13,14,14,15,15,16,16,16,16}, - { 0, 2, 6, 8, 9,10,11,13,13,14,14,15,15,15,16,16,16}, - { 0, 0, 3, 7, 8, 9,10,11,13,13,14,14,15,15,16,16,16}, - { 0, 0, 0, 5, 6, 7, 8, 9,10,11,13,14,14,15,15,16,16}, - }, - { - { 2, 6, 6, 7, 8, 8, 9,11,11,12,12,12,13,13,13,14,14}, - { 0, 2, 5, 6, 6, 7, 8, 9,11,11,12,12,13,13,14,14,14}, - { 0, 0, 3, 6, 6, 7, 8, 9,11,11,12,12,13,13,13,14,14}, - { 0, 0, 0, 4, 4, 5, 6, 6, 7, 9,11,11,12,13,13,13,14}, - }, - { - { 4, 6, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9,10,10,10,10}, - { 0, 4, 5, 5, 5, 5, 6, 6, 7, 8, 8, 9, 9, 9,10,10,10}, - { 0, 0, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10}, - { 0, 0, 0, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 9,10,10,10}, - }, + static const byte lentab[3][4][17] = { + { + // 0702 + {1, 6, 8, 9, 10, 11, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 16}, + {0, 2, 6, 8, 9, 10, 11, 13, 13, 14, 14, 15, 15, 15, 16, 16, 16}, + {0, 0, 3, 7, 8, 9, 10, 11, 13, 13, 14, 14, 15, 15, 16, 16, 16}, + {0, 0, 0, 5, 6, 7, 8, 9, 10, 11, 13, 14, 14, 15, 15, 16, 16}, + }, + { + {2, 6, 6, 7, 8, 8, 9, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14}, + {0, 2, 5, 6, 6, 7, 8, 9, 11, 11, 12, 12, 13, 13, 14, 14, 14}, + {0, 0, 3, 6, 6, 7, 8, 9, 11, 11, 12, 12, 13, 13, 13, 14, 14}, + {0, 0, 0, 4, 4, 5, 6, 6, 7, 9, 11, 11, 12, 13, 13, 13, 14}, + }, + { + {4, 6, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10}, + {0, 4, 5, 5, 5, 5, 6, 6, 7, 8, 8, 9, 9, 9, 10, 10, 10}, + {0, 0, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10}, + {0, 0, 0, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 9, 10, 10, 10}, + }, }; - static const byte codtab[3][4][17] = - { - { - { 1, 5, 7, 7, 7, 7,15,11, 8,15,11,15,11,15,11, 7,4}, - { 0, 1, 4, 6, 6, 6, 6,14,10,14,10,14,10, 1,14,10,6}, - { 0, 0, 1, 5, 5, 5, 5, 5,13, 9,13, 9,13, 9,13, 9,5}, - { 0, 0, 0, 3, 3, 4, 4, 4, 4, 4,12,12, 8,12, 8,12,8}, - }, - { - { 3,11, 7, 7, 7, 4, 7,15,11,15,11, 8,15,11, 7, 9,7}, - { 0, 2, 7,10, 6, 6, 6, 6,14,10,14,10,14,10,11, 8,6}, - { 0, 0, 3, 9, 5, 5, 5, 5,13, 9,13, 9,13, 9, 6,10,5}, - { 0, 0, 0, 5, 4, 6, 8, 4, 4, 4,12, 8,12,12, 8, 1,4}, - }, - { - {15,15,11, 8,15,11, 9, 8,15,11,15,11, 8,13, 9, 5,1}, - { 0,14,15,12,10, 8,14,10,14,14,10,14,10, 7,12, 8,4}, - { 0, 0,13,14,11, 9,13, 9,13,10,13, 9,13, 9,11, 7,3}, - { 0, 0, 0,12,11,10, 9, 8,13,12,12,12, 8,12,10, 6,2}, - }, + static const byte codtab[3][4][17] = { + { + {1, 5, 7, 7, 7, 7, 15, 11, 8, 15, 11, 15, 11, 15, 11, 7, 4}, + {0, 1, 4, 6, 6, 6, 6, 14, 10, 14, 10, 14, 10, 1, 14, 10, 6}, + {0, 0, 1, 5, 5, 5, 5, 5, 13, 9, 13, 9, 13, 9, 13, 9, 5}, + {0, 0, 0, 3, 3, 4, 4, 4, 4, 4, 12, 12, 8, 12, 8, 12, 8}, + }, + { + {3, 11, 7, 7, 7, 4, 7, 15, 11, 15, 11, 8, 15, 11, 7, 9, 7}, + {0, 2, 7, 10, 6, 6, 6, 6, 14, 10, 14, 10, 14, 10, 11, 8, 6}, + {0, 0, 3, 9, 5, 5, 5, 5, 13, 9, 13, 9, 13, 9, 6, 10, 5}, + {0, 0, 0, 5, 4, 6, 8, 4, 4, 4, 12, 8, 12, 12, 8, 1, 4}, + }, + { + {15, 15, 11, 8, 15, 11, 9, 8, 15, 11, 15, 11, 8, 13, 9, 5, 1}, + {0, 14, 15, 12, 10, 8, 14, 10, 14, 14, 10, 14, 10, 7, 12, 8, 4}, + {0, 0, 13, 14, 11, 9, 13, 9, 13, 10, 13, 9, 13, 9, 11, 7, 3}, + {0, 0, 0, 12, 11, 10, 9, 8, 13, 12, 12, 12, 8, 12, 10, 6, 2}, + }, }; int retval = 0, code; @@ -749,106 +701,100 @@ int readSyntaxElement_NumCoeffTrailingOnes(SyntaxElement *sym, // vlcnum is the index of Table used to code coeff_token // vlcnum==3 means (8<=nC) which uses 6bit FLC - if (vlcnum == 3) - { + if (vlcnum == 3) { // read 6 bit FLC - //code = ShowBits(buf, frame_bitoffset, BitstreamLengthInBytes, 6); + // code = ShowBits(buf, frame_bitoffset, BitstreamLengthInBytes, 6); code = ShowBits(buf, frame_bitoffset, BitstreamLengthInBits, 6); currStream->frame_bitoffset += 6; sym->value2 = (code & 3); sym->value1 = (code >> 2); - if (!sym->value1 && sym->value2 == 3) - { + if (!sym->value1 && sym->value2 == 3) { // #c = 0, #t1 = 3 => #c = 0 sym->value2 = 0; - } - else + } else sym->value1++; sym->len = 6; - } - else - { - //retval = code_from_bitstream_2d(sym, currStream, &lentab[vlcnum][0][0], &codtab[vlcnum][0][0], 17, 4, &code); - retval = code_from_bitstream_2d(sym, currStream, lentab[vlcnum][0], codtab[vlcnum][0], 17, 4, &code); - if (retval) - { + } else { + // retval = code_from_bitstream_2d(sym, currStream, &lentab[vlcnum][0][0], + // &codtab[vlcnum][0][0], 17, 4, &code); + retval = code_from_bitstream_2d(sym, currStream, lentab[vlcnum][0], + codtab[vlcnum][0], 17, 4, &code); + if (retval) { printf("ERROR: failed to find NumCoeff/TrailingOnes\n"); exit(-1); } } #if TRACE - snprintf(sym->tracestring, TRACESTRING_SIZE, "%s # c & tr.1s vlc=%d #c=%d #t1=%d", - type, vlcnum, sym->value1, sym->value2); + snprintf(sym->tracestring, TRACESTRING_SIZE, + "%s # c & tr.1s vlc=%d #c=%d #t1=%d", type, vlcnum, sym->value1, + sym->value2); tracebits2(sym->tracestring, sym->len, code); #endif return retval; } - /*! ************************************************************************ * \brief * read NumCoeff/TrailingOnes codeword from UVLC-partition ChromaDC ************************************************************************ */ -int readSyntaxElement_NumCoeffTrailingOnesChromaDC(VideoParameters *p_Vid, SyntaxElement *sym, Bitstream *currStream) -{ - static const byte lentab[3][4][17] = - { - //YUV420 - {{ 2, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 1, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 0, 3, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, - //YUV422 - {{ 1, 7, 7, 9, 9,10,11,12,13, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 2, 7, 7, 9,10,11,12,12, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 0, 3, 7, 7, 9,10,11,12, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 0, 0, 5, 6, 7, 7,10,11, 0, 0, 0, 0, 0, 0, 0, 0}}, - //YUV444 - {{ 1, 6, 8, 9,10,11,13,13,13,14,14,15,15,16,16,16,16}, - { 0, 2, 6, 8, 9,10,11,13,13,14,14,15,15,15,16,16,16}, - { 0, 0, 3, 7, 8, 9,10,11,13,13,14,14,15,15,16,16,16}, - { 0, 0, 0, 5, 6, 7, 8, 9,10,11,13,14,14,15,15,16,16}} - }; +int readSyntaxElement_NumCoeffTrailingOnesChromaDC(VideoParameters *p_Vid, + SyntaxElement *sym, + Bitstream *currStream) { + static const byte lentab[3][4][17] = { + // YUV420 + {{2, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 3, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, + // YUV422 + {{1, 7, 7, 9, 9, 10, 11, 12, 13, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 2, 7, 7, 9, 10, 11, 12, 12, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 3, 7, 7, 9, 10, 11, 12, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 5, 6, 7, 7, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0}}, + // YUV444 + {{1, 6, 8, 9, 10, 11, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 16}, + {0, 2, 6, 8, 9, 10, 11, 13, 13, 14, 14, 15, 15, 15, 16, 16, 16}, + {0, 0, 3, 7, 8, 9, 10, 11, 13, 13, 14, 14, 15, 15, 16, 16, 16}, + {0, 0, 0, 5, 6, 7, 8, 9, 10, 11, 13, 14, 14, 15, 15, 16, 16}}}; - static const byte codtab[3][4][17] = - { - //YUV420 - {{ 1, 7, 4, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 1, 6, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 0, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, - //YUV422 - {{ 1,15,14, 7, 6, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 1,13,12, 5, 6, 6, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 0, 1,11,10, 4, 5, 5, 4, 0, 0, 0, 0, 0, 0, 0, 0}, - { 0, 0, 0, 1, 1, 9, 8, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0}}, - //YUV444 - {{ 1, 5, 7, 7, 7, 7,15,11, 8,15,11,15,11,15,11, 7, 4}, - { 0, 1, 4, 6, 6, 6, 6,14,10,14,10,14,10, 1,14,10, 6}, - { 0, 0, 1, 5, 5, 5, 5, 5,13, 9,13, 9,13, 9,13, 9, 5}, - { 0, 0, 0, 3, 3, 4, 4, 4, 4, 4,12,12, 8,12, 8,12, 8}} + static const byte codtab[3][4][17] = { + // YUV420 + {{1, 7, 4, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 6, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, + // YUV422 + {{1, 15, 14, 7, 6, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 13, 12, 5, 6, 6, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 1, 11, 10, 4, 5, 5, 4, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 1, 1, 9, 8, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0}}, + // YUV444 + {{1, 5, 7, 7, 7, 7, 15, 11, 8, 15, 11, 15, 11, 15, 11, 7, 4}, + {0, 1, 4, 6, 6, 6, 6, 14, 10, 14, 10, 14, 10, 1, 14, 10, 6}, + {0, 0, 1, 5, 5, 5, 5, 5, 13, 9, 13, 9, 13, 9, 13, 9, 5}, + {0, 0, 0, 3, 3, 4, 4, 4, 4, 4, 12, 12, 8, 12, 8, 12, 8}} }; int code; int yuv = p_Vid->active_sps->chroma_format_idc - 1; - int retval = code_from_bitstream_2d(sym, currStream, &lentab[yuv][0][0], &codtab[yuv][0][0], 17, 4, &code); + int retval = code_from_bitstream_2d(sym, currStream, &lentab[yuv][0][0], + &codtab[yuv][0][0], 17, 4, &code); - if (retval) - { + if (retval) { printf("ERROR: failed to find NumCoeff/TrailingOnes ChromaDC\n"); exit(-1); } #if TRACE - snprintf(sym->tracestring, TRACESTRING_SIZE, "ChrDC # c & tr.1s #c=%d #t1=%d", - sym->value1, sym->value2); + snprintf(sym->tracestring, TRACESTRING_SIZE, + "ChrDC # c & tr.1s #c=%d #t1=%d", sym->value1, sym->value2); tracebits2(sym->tracestring, sym->len, code); #endif @@ -862,48 +808,42 @@ int readSyntaxElement_NumCoeffTrailingOnesChromaDC(VideoParameters *p_Vid, Synta * read Level VLC0 codeword from UVLC-partition ************************************************************************ */ -int readSyntaxElement_Level_VLC0(SyntaxElement *sym, Bitstream *currStream) -{ - int frame_bitoffset = currStream->frame_bitoffset; +int readSyntaxElement_Level_VLC0(SyntaxElement *sym, Bitstream *currStream) { + int frame_bitoffset = currStream->frame_bitoffset; int BitstreamLengthInBytes = currStream->bitstream_length; - int BitstreamLengthInBits = (BitstreamLengthInBytes << 3) + 7; - byte *buf = currStream->streamBuffer; + int BitstreamLengthInBits = (BitstreamLengthInBytes << 3) + 7; + byte *buf = currStream->streamBuffer; int len = 1, sign = 0, level = 0, code = 1; while (!ShowBits(buf, frame_bitoffset++, BitstreamLengthInBits, 1)) len++; - if (len < 15) - { - sign = (len - 1) & 1; + if (len < 15) { + sign = (len - 1) & 1; level = ((len - 1) >> 1) + 1; - } - else if (len == 15) - { + } else if (len == 15) { // escape code code <<= 4; code |= ShowBits(buf, frame_bitoffset, BitstreamLengthInBits, 4); - len += 4; + len += 4; frame_bitoffset += 4; sign = (code & 0x01); level = ((code >> 1) & 0x07) + 8; - } - else if (len >= 16) - { + } else if (len >= 16) { // escape code int addbit = (len - 16); int offset = (2048 << addbit) - 2032; - len -= 4; - code = ShowBits(buf, frame_bitoffset, BitstreamLengthInBits, len); - sign = (code & 0x01); - frame_bitoffset += len; + len -= 4; + code = ShowBits(buf, frame_bitoffset, BitstreamLengthInBits, len); + sign = (code & 0x01); + frame_bitoffset += len; level = (code >> 1) + offset; code |= (1 << (len)); // for display purpose only len += addbit + 16; - } + } - sym->inf = (sign) ? -level : level ; + sym->inf = (sign) ? -level : level; sym->len = len; #if TRACE @@ -920,12 +860,12 @@ int readSyntaxElement_Level_VLC0(SyntaxElement *sym, Bitstream *currStream) * read Level VLC codeword from UVLC-partition ************************************************************************ */ -int readSyntaxElement_Level_VLCN(SyntaxElement *sym, int vlc, Bitstream *currStream) -{ - int frame_bitoffset = currStream->frame_bitoffset; +int readSyntaxElement_Level_VLCN(SyntaxElement *sym, int vlc, + Bitstream *currStream) { + int frame_bitoffset = currStream->frame_bitoffset; int BitstreamLengthInBytes = currStream->bitstream_length; - int BitstreamLengthInBits = (BitstreamLengthInBytes << 3) + 7; - byte *buf = currStream->streamBuffer; + int BitstreamLengthInBits = (BitstreamLengthInBytes << 3) + 7; + byte *buf = currStream->streamBuffer; int levabs, sign; int len = 1; @@ -934,49 +874,46 @@ int readSyntaxElement_Level_VLCN(SyntaxElement *sym, int vlc, Bitstream *currStr int shift = vlc - 1; // read pre zeros - while (!ShowBits(buf, frame_bitoffset ++, BitstreamLengthInBits, 1)) + while (!ShowBits(buf, frame_bitoffset++, BitstreamLengthInBits, 1)) len++; frame_bitoffset -= len; - if (len < 16) - { + if (len < 16) { levabs = ((len - 1) << shift) + 1; // read (vlc-1) bits -> suffix - if (shift) - { - sb = ShowBits(buf, frame_bitoffset + len, BitstreamLengthInBits, shift); - code = (code << (shift) )| sb; + if (shift) { + sb = ShowBits(buf, frame_bitoffset + len, BitstreamLengthInBits, shift); + code = (code << (shift)) | sb; levabs += sb; len += (shift); } // read 1 bit -> sign sign = ShowBits(buf, frame_bitoffset + len, BitstreamLengthInBits, 1); - code = (code << 1)| sign; - len ++; - } - else // escape + code = (code << 1) | sign; + len++; + } else // escape { int addbit = len - 5; int offset = (1 << addbit) + (15 << shift) - 2047; sb = ShowBits(buf, frame_bitoffset + len, BitstreamLengthInBits, addbit); - code = (code << addbit ) | sb; - len += addbit; + code = (code << addbit) | sb; + len += addbit; levabs = sb + offset; - + // read 1 bit -> sign sign = ShowBits(buf, frame_bitoffset + len, BitstreamLengthInBits, 1); - code = (code << 1)| sign; + code = (code << 1) | sign; len++; } - sym->inf = (sign)? -levabs : levabs; + sym->inf = (sign) ? -levabs : levabs; sym->len = len; currStream->frame_bitoffset = frame_bitoffset + len; @@ -994,53 +931,67 @@ int readSyntaxElement_Level_VLCN(SyntaxElement *sym, int vlc, Bitstream *currStr * read Total Zeros codeword from UVLC-partition ************************************************************************ */ -int readSyntaxElement_TotalZeros(SyntaxElement *sym, Bitstream *currStream) -{ - static const byte lentab[TOTRUN_NUM][16] = - { +int readSyntaxElement_TotalZeros(SyntaxElement *sym, Bitstream *currStream) { + static const byte lentab[TOTRUN_NUM][16] = { - { 1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9}, - { 3,3,3,3,3,4,4,4,4,5,5,6,6,6,6}, - { 4,3,3,3,4,4,3,3,4,5,5,6,5,6}, - { 5,3,4,4,3,3,3,4,3,4,5,5,5}, - { 4,4,4,3,3,3,3,3,4,5,4,5}, - { 6,5,3,3,3,3,3,3,4,3,6}, - { 6,5,3,3,3,2,3,4,3,6}, - { 6,4,5,3,2,2,3,3,6}, - { 6,6,4,2,2,3,2,5}, - { 5,5,3,2,2,2,4}, - { 4,4,3,3,1,3}, - { 4,4,2,1,3}, - { 3,3,1,2}, - { 2,2,1}, - { 1,1}, + {1, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9}, + {3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, + {4, 3, 3, 3, 4, 4, 3, 3, 4, 5, 5, 6, 5, 6}, + {5, 3, 4, 4, 3, 3, 3, 4, 3, 4, 5, 5, 5}, + {4, 4, 4, 3, 3, 3, 3, 3, 4, 5, 4, 5}, + {6, 5, 3, 3, 3, 3, 3, 3, 4, 3, 6}, + {6, 5, 3, 3, 3, 2, 3, 4, 3, 6}, + {6, 4, 5, 3, 2, 2, 3, 3, 6}, + {6, 6, 4, 2, 2, 3, 2, 5}, + {5, 5, 3, 2, 2, 2, 4}, + {4, 4, 3, 3, 1, 3}, + {4, 4, 2, 1, 3}, + {3, 3, 1, 2}, + {2, 2, 1}, + {1, 1}, }; - static const byte codtab[TOTRUN_NUM][16] = - { - {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1}, - {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0}, - {5,7,6,5,4,3,4,3,2,3,2,1,1,0}, - {3,7,5,4,6,5,4,3,3,2,2,1,0}, - {5,4,3,7,6,5,4,3,2,1,1,0}, - {1,1,7,6,5,4,3,2,1,1,0}, - {1,1,5,4,3,3,2,1,1,0}, - {1,1,1,3,3,2,2,1,0}, - {1,0,1,3,2,1,1,1,}, - {1,0,1,3,2,1,1,}, - {0,1,1,2,1,3}, - {0,1,1,1,1}, - {0,1,1,1}, - {0,1,1}, - {0,1}, + static const byte codtab[TOTRUN_NUM][16] = { + {1, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 1}, + {7, 6, 5, 4, 3, 5, 4, 3, 2, 3, 2, 3, 2, 1, 0}, + {5, 7, 6, 5, 4, 3, 4, 3, 2, 3, 2, 1, 1, 0}, + {3, 7, 5, 4, 6, 5, 4, 3, 3, 2, 2, 1, 0}, + {5, 4, 3, 7, 6, 5, 4, 3, 2, 1, 1, 0}, + {1, 1, 7, 6, 5, 4, 3, 2, 1, 1, 0}, + {1, 1, 5, 4, 3, 3, 2, 1, 1, 0}, + {1, 1, 1, 3, 3, 2, 2, 1, 0}, + { + 1, + 0, + 1, + 3, + 2, + 1, + 1, + 1, + }, + { + 1, + 0, + 1, + 3, + 2, + 1, + 1, + }, + {0, 1, 1, 2, 1, 3}, + {0, 1, 1, 1, 1}, + {0, 1, 1, 1}, + {0, 1, 1}, + {0, 1}, }; int code; int vlcnum = sym->value1; - int retval = code_from_bitstream_2d(sym, currStream, &lentab[vlcnum][0], &codtab[vlcnum][0], 16, 1, &code); + int retval = code_from_bitstream_2d(sym, currStream, &lentab[vlcnum][0], + &codtab[vlcnum][0], 16, 1, &code); - if (retval) - { + if (retval) { printf("ERROR: failed to find Total Zeros !cdc\n"); exit(-1); } @@ -1058,79 +1009,89 @@ int readSyntaxElement_TotalZeros(SyntaxElement *sym, Bitstream *currStream) * read Total Zeros Chroma DC codeword from UVLC-partition ************************************************************************ */ -int readSyntaxElement_TotalZerosChromaDC(VideoParameters *p_Vid, SyntaxElement *sym, Bitstream *currStream) -{ - static const byte lentab[3][TOTRUN_NUM][16] = - { - //YUV420 - {{ 1,2,3,3}, - { 1,2,2}, - { 1,1}}, - //YUV422 - {{ 1,3,3,4,4,4,5,5}, - { 3,2,3,3,3,3,3}, - { 3,3,2,2,3,3}, - { 3,2,2,2,3}, - { 2,2,2,2}, - { 2,2,1}, - { 1,1}}, - //YUV444 - {{ 1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9}, - { 3,3,3,3,3,4,4,4,4,5,5,6,6,6,6}, - { 4,3,3,3,4,4,3,3,4,5,5,6,5,6}, - { 5,3,4,4,3,3,3,4,3,4,5,5,5}, - { 4,4,4,3,3,3,3,3,4,5,4,5}, - { 6,5,3,3,3,3,3,3,4,3,6}, - { 6,5,3,3,3,2,3,4,3,6}, - { 6,4,5,3,2,2,3,3,6}, - { 6,6,4,2,2,3,2,5}, - { 5,5,3,2,2,2,4}, - { 4,4,3,3,1,3}, - { 4,4,2,1,3}, - { 3,3,1,2}, - { 2,2,1}, - { 1,1}} - }; +int readSyntaxElement_TotalZerosChromaDC(VideoParameters *p_Vid, + SyntaxElement *sym, + Bitstream *currStream) { + static const byte lentab[3][TOTRUN_NUM][16] = { + // YUV420 + {{1, 2, 3, 3}, {1, 2, 2}, {1, 1}}, + // YUV422 + {{1, 3, 3, 4, 4, 4, 5, 5}, + {3, 2, 3, 3, 3, 3, 3}, + {3, 3, 2, 2, 3, 3}, + {3, 2, 2, 2, 3}, + {2, 2, 2, 2}, + {2, 2, 1}, + {1, 1}}, + // YUV444 + {{1, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9}, + {3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6}, + {4, 3, 3, 3, 4, 4, 3, 3, 4, 5, 5, 6, 5, 6}, + {5, 3, 4, 4, 3, 3, 3, 4, 3, 4, 5, 5, 5}, + {4, 4, 4, 3, 3, 3, 3, 3, 4, 5, 4, 5}, + {6, 5, 3, 3, 3, 3, 3, 3, 4, 3, 6}, + {6, 5, 3, 3, 3, 2, 3, 4, 3, 6}, + {6, 4, 5, 3, 2, 2, 3, 3, 6}, + {6, 6, 4, 2, 2, 3, 2, 5}, + {5, 5, 3, 2, 2, 2, 4}, + {4, 4, 3, 3, 1, 3}, + {4, 4, 2, 1, 3}, + {3, 3, 1, 2}, + {2, 2, 1}, + {1, 1}}}; - static const byte codtab[3][TOTRUN_NUM][16] = - { - //YUV420 - {{ 1,1,1,0}, - { 1,1,0}, - { 1,0}}, - //YUV422 - {{ 1,2,3,2,3,1,1,0}, - { 0,1,1,4,5,6,7}, - { 0,1,1,2,6,7}, - { 6,0,1,2,7}, - { 0,1,2,3}, - { 0,1,1}, - { 0,1}}, - //YUV444 - {{1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1}, - {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0}, - {5,7,6,5,4,3,4,3,2,3,2,1,1,0}, - {3,7,5,4,6,5,4,3,3,2,2,1,0}, - {5,4,3,7,6,5,4,3,2,1,1,0}, - {1,1,7,6,5,4,3,2,1,1,0}, - {1,1,5,4,3,3,2,1,1,0}, - {1,1,1,3,3,2,2,1,0}, - {1,0,1,3,2,1,1,1,}, - {1,0,1,3,2,1,1,}, - {0,1,1,2,1,3}, - {0,1,1,1,1}, - {0,1,1,1}, - {0,1,1}, - {0,1}} - }; + static const byte codtab[3][TOTRUN_NUM][16] = { + // YUV420 + {{1, 1, 1, 0}, {1, 1, 0}, {1, 0}}, + // YUV422 + {{1, 2, 3, 2, 3, 1, 1, 0}, + {0, 1, 1, 4, 5, 6, 7}, + {0, 1, 1, 2, 6, 7}, + {6, 0, 1, 2, 7}, + {0, 1, 2, 3}, + {0, 1, 1}, + {0, 1}}, + // YUV444 + {{1, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 1}, + {7, 6, 5, 4, 3, 5, 4, 3, 2, 3, 2, 3, 2, 1, 0}, + {5, 7, 6, 5, 4, 3, 4, 3, 2, 3, 2, 1, 1, 0}, + {3, 7, 5, 4, 6, 5, 4, 3, 3, 2, 2, 1, 0}, + {5, 4, 3, 7, 6, 5, 4, 3, 2, 1, 1, 0}, + {1, 1, 7, 6, 5, 4, 3, 2, 1, 1, 0}, + {1, 1, 5, 4, 3, 3, 2, 1, 1, 0}, + {1, 1, 1, 3, 3, 2, 2, 1, 0}, + { + 1, + 0, + 1, + 3, + 2, + 1, + 1, + 1, + }, + { + 1, + 0, + 1, + 3, + 2, + 1, + 1, + }, + {0, 1, 1, 2, 1, 3}, + {0, 1, 1, 1, 1}, + {0, 1, 1, 1}, + {0, 1, 1}, + {0, 1}}}; int code; int yuv = p_Vid->active_sps->chroma_format_idc - 1; int vlcnum = sym->value1; - int retval = code_from_bitstream_2d(sym, currStream, &lentab[yuv][vlcnum][0], &codtab[yuv][vlcnum][0], 16, 1, &code); + int retval = code_from_bitstream_2d(sym, currStream, &lentab[yuv][vlcnum][0], + &codtab[yuv][vlcnum][0], 16, 1, &code); - if (retval) - { + if (retval) { printf("ERROR: failed to find Total Zeros\n"); exit(-1); } @@ -1142,42 +1103,38 @@ int readSyntaxElement_TotalZerosChromaDC(VideoParameters *p_Vid, SyntaxElement * return retval; } - /*! ************************************************************************ * \brief * read Run codeword from UVLC-partition ************************************************************************ */ -int readSyntaxElement_Run(SyntaxElement *sym, Bitstream *currStream) -{ - static const byte lentab[TOTRUN_NUM][16] = - { - {1,1}, - {1,2,2}, - {2,2,2,2}, - {2,2,2,3,3}, - {2,2,3,3,3,3}, - {2,3,3,3,3,3,3}, - {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11}, +int readSyntaxElement_Run(SyntaxElement *sym, Bitstream *currStream) { + static const byte lentab[TOTRUN_NUM][16] = { + {1, 1}, + {1, 2, 2}, + {2, 2, 2, 2}, + {2, 2, 2, 3, 3}, + {2, 2, 3, 3, 3, 3}, + {2, 3, 3, 3, 3, 3, 3}, + {3, 3, 3, 3, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11}, }; - static const byte codtab[TOTRUN_NUM][16] = - { - {1,0}, - {1,1,0}, - {3,2,1,0}, - {3,2,1,1,0}, - {3,2,3,2,1,0}, - {3,0,1,3,2,5,4}, - {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1}, + static const byte codtab[TOTRUN_NUM][16] = { + {1, 0}, + {1, 1, 0}, + {3, 2, 1, 0}, + {3, 2, 1, 1, 0}, + {3, 2, 3, 2, 1, 0}, + {3, 0, 1, 3, 2, 5, 4}, + {7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1}, }; int code; int vlcnum = sym->value1; - int retval = code_from_bitstream_2d(sym, currStream, &lentab[vlcnum][0], &codtab[vlcnum][0], 16, 1, &code); + int retval = code_from_bitstream_2d(sym, currStream, &lentab[vlcnum][0], + &codtab[vlcnum][0], 16, 1, &code); - if (retval) - { + if (retval) { printf("ERROR: failed to find Run\n"); exit(-1); } @@ -1189,7 +1146,6 @@ int readSyntaxElement_Run(SyntaxElement *sym, Bitstream *currStream) return retval; } - /*! ************************************************************************ * \brief @@ -1208,27 +1164,21 @@ int readSyntaxElement_Run(SyntaxElement *sym, Bitstream *currStream) * ************************************************************************ */ -int GetBits (byte buffer[],int totbitoffset,int *info, int bitcount, - int numbits) -{ - if ((totbitoffset + numbits ) > bitcount) - { +int GetBits(byte buffer[], int totbitoffset, int *info, int bitcount, + int numbits) { + if ((totbitoffset + numbits) > bitcount) { return -1; - } - else - { - int bitoffset = 7 - (totbitoffset & 0x07); // bit from start of byte - int byteoffset = (totbitoffset >> 3); // byte from start of buffer + } else { + int bitoffset = 7 - (totbitoffset & 0x07); // bit from start of byte + int byteoffset = (totbitoffset >> 3); // byte from start of buffer int bitcounter = numbits; - byte *curbyte = &(buffer[byteoffset]); + byte *curbyte = &(buffer[byteoffset]); int inf = 0; - while (numbits--) - { - inf <<=1; - inf |= ((*curbyte)>> (bitoffset--)) & 0x01; - if (bitoffset == -1 ) - { //Move onto next byte to get all of numbits + while (numbits--) { + inf <<= 1; + inf |= ((*curbyte) >> (bitoffset--)) & 0x01; + if (bitoffset == -1) { // Move onto next byte to get all of numbits curbyte++; bitoffset = 7; } @@ -1238,7 +1188,7 @@ int GetBits (byte buffer[],int totbitoffset,int *info, int bitcount, } *info = inf; - return bitcounter; // return absolute offset in bit from start of frame + return bitcounter; // return absolute offset in bit from start of frame } } @@ -1259,31 +1209,24 @@ int GetBits (byte buffer[],int totbitoffset,int *info, int bitcount, ************************************************************************ */ -int ShowBits (byte buffer[],int totbitoffset,int bitcount, int numbits) -{ - if ((totbitoffset + numbits ) > bitcount) - { +int ShowBits(byte buffer[], int totbitoffset, int bitcount, int numbits) { + if ((totbitoffset + numbits) > bitcount) { return -1; - } - else - { - int bitoffset = 7 - (totbitoffset & 0x07); // bit from start of byte - int byteoffset = (totbitoffset >> 3); // byte from start of buffer - byte *curbyte = &(buffer[byteoffset]); - int inf = 0; + } else { + int bitoffset = 7 - (totbitoffset & 0x07); // bit from start of byte + int byteoffset = (totbitoffset >> 3); // byte from start of buffer + byte *curbyte = &(buffer[byteoffset]); + int inf = 0; - while (numbits--) - { - inf <<=1; - inf |= ((*curbyte)>> (bitoffset--)) & 0x01; + while (numbits--) { + inf <<= 1; + inf |= ((*curbyte) >> (bitoffset--)) & 0x01; - if (bitoffset == -1 ) - { //Move onto next byte to get all of numbits + if (bitoffset == -1) { // Move onto next byte to get all of numbits curbyte++; bitoffset = 7; } } - return inf; // return absolute offset in bit from start of frame + return inf; // return absolute offset in bit from start of frame } } - diff --git a/src/common/ldecod_src/win32.c b/src/common/ldecod_src/win32.c index efc4475..3b45101 100644 --- a/src/common/ldecod_src/win32.c +++ b/src/common/ldecod_src/win32.c @@ -7,7 +7,8 @@ * Platform dependent code * * \author - * Main contributors (see contributors.h for copyright, address and affiliation details) + * Main contributors (see contributors.h for copyright, address and + *affiliation details) * - Karsten Suehring ************************************************************************************* */ @@ -19,20 +20,17 @@ #include "global.h" - #if defined(_WIN32) || defined(SPEC_WINDOWS) static LARGE_INTEGER freq; -void gettime(TIME_T* time) -{ +void gettime(TIME_T *time) { #if !defined(SPEC_WINDOWS) QueryPerformanceCounter(time); #endif /* SPEC_WINDOWS */ } -int64 timediff(TIME_T* start, TIME_T* end) -{ +int64 timediff(TIME_T *start, TIME_T *end) { #if !defined(SPEC_WINDOWS) return (int64)((end->QuadPart - start->QuadPart)); #else @@ -40,20 +38,18 @@ int64 timediff(TIME_T* start, TIME_T* end) #endif } -int64 timenorm(int64 cur_time) -{ +int64 timenorm(int64 cur_time) { #if !defined(SPEC_WINDOWS) static int first = 1; - if(first) - { + if (first) { QueryPerformanceFrequency(&freq); first = 0; } - return (int64)(cur_time * 1000 /(freq.QuadPart)); + return (int64)(cur_time * 1000 / (freq.QuadPart)); #else - return 0; + return 0; #endif /* SPEC_WINDOWS */ } @@ -63,25 +59,18 @@ int64 timenorm(int64 cur_time) /* SPEC NOTE: timezone tz is obsolete */ static struct timezone tz; -void gettime(TIME_T* time) -{ - gettimeofday(time, &tz); -} +void gettime(TIME_T *time) { gettimeofday(time, &tz); } #else -void gettime(TIME_T* time) { } +void gettime(TIME_T *time) {} #endif /* !SPEC */ -int64 timediff(TIME_T* start, TIME_T* end) -{ +int64 timediff(TIME_T *start, TIME_T *end) { int t1, t2; - t1 = end->tv_sec - start->tv_sec; - t2 = end->tv_usec - start->tv_usec; - return (int64) t2 + (int64) t1 * (int64) 1000000; + t1 = end->tv_sec - start->tv_sec; + t2 = end->tv_usec - start->tv_usec; + return (int64)t2 + (int64)t1 * (int64)1000000; } -int64 timenorm(int64 cur_time) -{ - return (int64)(cur_time / (int64) 1000); -} +int64 timenorm(int64 cur_time) { return (int64)(cur_time / (int64)1000); } #endif diff --git a/src/gemm/configs/ref-config.c b/src/gemm/configs/ref-config.c index 51e42da..14987ff 100644 --- a/src/gemm/configs/ref-config.c +++ b/src/gemm/configs/ref-config.c @@ -1,4 +1,3 @@ #include - bench_gemm_config config = {110, 110, 110}; diff --git a/src/gemm/configs/test-config.c b/src/gemm/configs/test-config.c index 95c9997..e1d725c 100644 --- a/src/gemm/configs/test-config.c +++ b/src/gemm/configs/test-config.c @@ -1,4 +1,3 @@ #include - bench_gemm_config config = {50, 50, 50}; diff --git a/src/gemm/configs/train-config.c b/src/gemm/configs/train-config.c index e332dc5..b20fa67 100644 --- a/src/gemm/configs/train-config.c +++ b/src/gemm/configs/train-config.c @@ -1,4 +1,3 @@ #include - bench_gemm_config config = {40, 40, 40}; diff --git a/src/gemm/gemm.c b/src/gemm/gemm.c index d35d341..d7c6a4d 100644 --- a/src/gemm/gemm.c +++ b/src/gemm/gemm.c @@ -1,57 +1,59 @@ +#include "bench.h" +#include #include -#define A(i,j) a[(j)*lda + (i)] +#define A(i, j) a[(j) * lda + (i)] -void serial_init(int m, int n, double * a, int lda){ - int count = 1; - for(int j=0;j #include #include -#include #include +#include #include - +#define TEST typedef struct { uint32_t m; uint32_t n; uint32_t k; } bench_gemm_config; -void AddDot4x4( int, double *, int, double *, int, double *, int ); -void PackMatrixA( int, double *, int, double * ); -void PackMatrixB( int, double *, int, double * ); -void InnerKernel( int, int, int, double *, int, double *, int, double *, int, int ); -void matmul( int m, int n, int k, double *a, int lda, double *b, int ldb,double *c, int ldc ); +void AddDot4x4(int, double *, int, double *, int, double *, int); +void PackMatrixA(int, double *, int, double *); +void PackMatrixB(int, double *, int, double *); +void InnerKernel(int, int, int, double *, int, double *, int, double *, int, + int); +void matmul(int m, int n, int k, double *a, int lda, double *b, int ldb, + double *c, int ldc); diff --git a/src/gemm/matmul.c b/src/gemm/matmul.c index f04b347..4ecb05e 100644 --- a/src/gemm/matmul.c +++ b/src/gemm/matmul.c @@ -1,124 +1,127 @@ -#include "gemm.h" +#include +#define A(i, j) a[(j) * lda + (i)] +#define B(i, j) b[(j) * ldb + (i)] +#define C(i, j) c[(j) * ldc + (i)] -#define A(i,j) a[(j)*lda+(i)] -#define B(i,j) b[(j)*ldb+(i)] -#define C(i,j) c[(j)*ldc+(i)] +void AddDot4x4(int k, double *a, int lda, double *b, int ldb, double *c, + int ldc) { -void AddDot4x4(int k, double *a, int lda, double *b, int ldb, double *c, int ldc){ + register double c_00, c_01, c_02, c_03, c_10, c_11, c_12, c_13, c_20, c_21, + c_22, c_23, c_30, c_31, c_32, c_33, a_0p, a_1p, a_2p, a_3p, b_0p_reg, + b_1p_reg, b_2p_reg, b_3p_reg; + double *b_0p_ptr, *b_1p_ptr, *b_2p_ptr, *b_3p_ptr; - register double c_00, c_01, c_02, c_03, c_10, c_11, c_12, c_13, c_20, c_21, c_22, c_23, c_30, c_31, c_32, c_33, a_0p, a_1p, a_2p, a_3p, b_0p_reg, b_1p_reg, b_2p_reg, b_3p_reg; - double * b_0p_ptr, *b_1p_ptr, *b_2p_ptr, *b_3p_ptr; + c_00 = 0.0; + c_01 = 0.0; + c_02 = 0.0; + c_03 = 0.0; + c_10 = 0.0; + c_11 = 0.0; + c_12 = 0.0; + c_13 = 0.0; + c_20 = 0.0; + c_21 = 0.0; + c_22 = 0.0; + c_23 = 0.0; + c_30 = 0.0; + c_31 = 0.0; + c_32 = 0.0; + c_33 = 0.0; - c_00 = 0.0; - c_01 = 0.0; - c_02 = 0.0; - c_03 = 0.0; - c_10 = 0.0; - c_11 = 0.0; - c_12 = 0.0; - c_13 = 0.0; - c_20 = 0.0; - c_21 = 0.0; - c_22 = 0.0; - c_23 = 0.0; - c_30 = 0.0; - c_31 = 0.0; - c_32 = 0.0; - c_33 = 0.0; + b_0p_ptr = &B(0, 0); + b_1p_ptr = &B(0, 1); + b_2p_ptr = &B(0, 2); + b_3p_ptr = &B(0, 3); - b_0p_ptr = &B(0,0); - b_1p_ptr = &B(0,1); - b_2p_ptr = &B(0,2); - b_3p_ptr = &B(0,3); + // #pragma omp parallel for num_threads(4) + for (int p = 0; p < k; p++) { + a_0p = A(0, p); + a_1p = A(1, p); + a_2p = A(2, p); + a_3p = A(3, p); - // #pragma omp parallel for num_threads(4) - for(int p=0;p + +bench_linpack_config config = {270}; diff --git a/src/linpack/configs/test-config.c b/src/linpack/configs/test-config.c index e69de29..d0872d9 100644 --- a/src/linpack/configs/test-config.c +++ b/src/linpack/configs/test-config.c @@ -0,0 +1,3 @@ +#include + +bench_linpack_config config = {100}; diff --git a/src/linpack/configs/train-config.c b/src/linpack/configs/train-config.c index e69de29..e26665f 100644 --- a/src/linpack/configs/train-config.c +++ b/src/linpack/configs/train-config.c @@ -0,0 +1,3 @@ +#include + +bench_linpack_config config = {80}; diff --git a/src/linpack/include/linpack.h b/src/linpack/include/linpack.h new file mode 100644 index 0000000..2719c70 --- /dev/null +++ b/src/linpack/include/linpack.h @@ -0,0 +1,42 @@ +#ifndef __LINPACK_H__ +#define __LINPACK_H__ + +#define FLT_DIG 6 +#define DBL_DIG 15 + +#define SP + +#ifndef SP +#ifndef DP +#define DP +#endif +#endif + +#ifdef SP +#define ZERO 0.0 +#define ONE 1.0 +#define PREC "Single" +#define BASE10DIG FLT_DIG + +typedef float REAL; +#endif + +#ifdef DP +#define ZERO 0.0e0 +#define ONE 1.0e0 +#define PREC "Double" +#define BASE10DIG DBL_DIG + +typedef double REAL; +#endif + +/* 2022-07-26: Macro defined for memreq variable to resolve warnings + * during malloc check + */ +#define MEM_T long + +typedef struct { + int arsize; +} bench_linpack_config; + +#endif diff --git a/src/linpack/linpack.c b/src/linpack/linpack.c index 16c5f73..023a340 100644 --- a/src/linpack/linpack.c +++ b/src/linpack/linpack.c @@ -30,105 +30,61 @@ #include #include +#include #include #include #include +#include -#define FLT_DIG 6 -#define DBL_DIG 15 +extern bench_linpack_config config; -#define SP - -#ifndef SP -#ifndef DP -#define DP -#endif -#endif - -#ifdef SP -#define ZERO 0.0 -#define ONE 1.0 -#define PREC "Single" -#define BASE10DIG FLT_DIG - -typedef float REAL; -#endif - -#ifdef DP -#define ZERO 0.0e0 -#define ONE 1.0e0 -#define PREC "Double" -#define BASE10DIG DBL_DIG - -typedef double REAL; -#endif - -/* 2022-07-26: Macro defined for memreq variable to resolve warnings - * during malloc check - */ -#define MEM_T long - -static REAL linpack (long nreps, int arsize); -static void matgen (REAL *a, int lda, int n, REAL *b, REAL *norma); -static void dgefa (REAL *a, int lda, int n, int *ipvt, int *info, int roll); -static void dgesl (REAL *a, int lda, int n, int *ipvt, REAL *b, int job, - int roll); -static void daxpy_r (int n, REAL da, REAL *dx, int incx, REAL *dy, int incy); -static REAL ddot_r (int n, REAL *dx, int incx, REAL *dy, int incy); -static void dscal_r (int n, REAL da, REAL *dx, int incx); -static void daxpy_ur (int n, REAL da, REAL *dx, int incx, REAL *dy, int incy); -static REAL ddot_ur (int n, REAL *dx, int incx, REAL *dy, int incy); -static void dscal_ur (int n, REAL da, REAL *dx, int incx); -static int idamax (int n, REAL *dx, int incx); -static REAL second (void); -static double -fabs (double x) -{ - return x < 0 ? -x : x; -} +static REAL linpack(long nreps, int arsize); +static void matgen(REAL *a, int lda, int n, REAL *b, REAL *norma); +static void dgefa(REAL *a, int lda, int n, int *ipvt, int *info, int roll); +static void dgesl(REAL *a, int lda, int n, int *ipvt, REAL *b, int job, + int roll); +static void daxpy_r(int n, REAL da, REAL *dx, int incx, REAL *dy, int incy); +static REAL ddot_r(int n, REAL *dx, int incx, REAL *dy, int incy); +static void dscal_r(int n, REAL da, REAL *dx, int incx); +static void daxpy_ur(int n, REAL da, REAL *dx, int incx, REAL *dy, int incy); +static REAL ddot_ur(int n, REAL *dx, int incx, REAL *dy, int incy); +static void dscal_ur(int n, REAL da, REAL *dx, int incx); +static int idamax(int n, REAL *dx, int incx); +static REAL second(void); +static inline double fabs(double x) { return x < 0 ? -x : x; } static void *mempool = NULL; -int -main (int argc, char **argv) +int main(int argc, char **argv) { - ioe_init (); - bench_malloc_init (); + ioe_init(); + bench_malloc_init(); int arsize; long arsize2d, nreps; volatile size_t malloc_arg; volatile MEM_T memreq; - arsize = 270; + arsize = config.arsize; arsize2d = (long)arsize * (long)arsize; memreq = arsize2d * sizeof (REAL) + (long)arsize * sizeof (REAL) + (long)arsize * sizeof (int); malloc_arg = (size_t)memreq; uint64_t start_time, end_time; - if ((MEM_T)malloc_arg != memreq - || (mempool = bench_malloc (malloc_arg)) == NULL) - { - // printf("Not enough memory available for given array size.\n"); - return 1; - } + if ((MEM_T)malloc_arg != memreq || + (mempool = bench_malloc(malloc_arg)) == NULL) { + BENCH_LOG(ERROR, "Not enough memory available for given array size.\n"); + return 1; + } - // printf("LINPACK benchmark, %s precision.\n", PREC); - // printf("Machine precision: %d digits.\n", BASE10DIG); - // printf("Array size %d X %d.\n", arsize, arsize); - // printf("Memory required: %ldK.\n", (memreq + 512L) >> 10); - // printf("Average rolled and unrolled performance:\n\n"); - // printf(" Reps Time(s) DGEFA DGESL OVERHEAD KFLOPS\n"); - // printf("----------------------------------------------------\n"); nreps = 1; - start_time = uptime (); - while (linpack (nreps, arsize) < 10.) - { - nreps *= 2; - } - end_time = uptime (); - bench_free (mempool); - printf ("time: %s ms\n", format_time (end_time - start_time)); + start_time = uptime(); + while (linpack(nreps, arsize) < 10.) { + nreps *= 2; + } + end_time = uptime(); + bench_free(mempool); + BENCH_LOG(INFO, "OpenPerf time: %s", format_time(end_time - start_time)); return 0; } @@ -137,54 +93,28 @@ linpack (long nreps, int arsize) { REAL *a, *b; - REAL norma, t1, kflops, tdgesl, tdgefa, totalt, toverhead, ops; + REAL norma, totalt; int *ipvt, n, info, lda; long i, arsize2d; lda = arsize; n = arsize / 2; arsize2d = (long)arsize * (long)arsize; - ops = ((2.0 * n * n * n) / 3.0 + 2.0 * n * n); a = (REAL *)mempool; b = a + arsize2d; ipvt = (int *)&b[arsize]; - tdgesl = 0; - tdgefa = 0; - totalt = second (); - for (i = 0; i < nreps; i++) - { - matgen (a, lda, n, b, &norma); - t1 = second (); - dgefa (a, lda, n, ipvt, &info, 1); - tdgefa += second () - t1; - t1 = second (); - dgesl (a, lda, n, ipvt, b, 0, 1); - tdgesl += second () - t1; - } - for (i = 0; i < nreps; i++) - { - matgen (a, lda, n, b, &norma); - t1 = second (); - dgefa (a, lda, n, ipvt, &info, 0); - tdgefa += second () - t1; - t1 = second (); - dgesl (a, lda, n, ipvt, b, 0, 0); - tdgesl += second () - t1; - } - totalt = second () - totalt; - if (totalt < 0.5 || tdgefa + tdgesl < 0.2) - return (0.); - kflops = 2. * nreps * ops / (1000. * (tdgefa + tdgesl)); - toverhead = totalt - tdgefa - tdgesl; - if (tdgefa < 0.) - tdgefa = 0.; - if (tdgesl < 0.) - tdgesl = 0.; - if (toverhead < 0.) - toverhead = 0.; - // printf("%8ld %6.2f %6.2f%% %6.2f%% %6.2f%% %9.3f\n", nreps, totalt, - // 100. * tdgefa / totalt, 100. * tdgesl / totalt, - // 100. * toverhead / totalt, kflops); + totalt = second(); + for (i = 0; i < nreps; i++) { + matgen(a, lda, n, b, &norma); + dgefa(a, lda, n, ipvt, &info, 1); + dgesl(a, lda, n, ipvt, b, 0, 1); + } + for (i = 0; i < nreps; i++) { + matgen(a, lda, n, b, &norma); + dgefa(a, lda, n, ipvt, &info, 0); + dgesl(a, lda, n, ipvt, b, 0, 0); + } + totalt = second() - totalt; return (totalt); } @@ -909,5 +839,5 @@ static REAL second (void) { - return ((REAL)(uptime () / 1000)); + return ((REAL)(uptime() / 1000)); } diff --git a/src/mcf/Makefile b/src/mcf/Makefile index 5359a1c..7fafe6f 100644 --- a/src/mcf/Makefile +++ b/src/mcf/Makefile @@ -1,9 +1,10 @@ NAME = mcf +mainargs ?= ref BENCH_LIBS = bench openlibm soft-fp -SRCS = main.c mcf.c pqueue.c $(shell realpath ./test-gen/test.c) +SRCS = main.c mcf.c pqueue.c ./configs/$(mainargs)-config.c INC_PATH += ../common/openlibm/include \ ../common/openlibm/src \ @@ -12,7 +13,6 @@ INC_PATH += ../common/openlibm/include \ include $(AM_HOME)/Makefile - BENCH_LINKAGE = $(addsuffix -$(ARCH).a, $(join \ $(addsuffix /build/, $(addprefix $(WORK_DIR)/../common/, $(BENCH_LIBS))), \ $(BENCH_LIBS) )) diff --git a/src/mcf/configs/ref-config.c b/src/mcf/configs/ref-config.c new file mode 100644 index 0000000..b4fac91 --- /dev/null +++ b/src/mcf/configs/ref-config.c @@ -0,0 +1,36 @@ +#include "input.h" + +const int nodes_num = 14; +const int edges_num = 25; +const int demands_num = 1; + +node_t node_buf[] = { + {0, 0, 0, 6}, {1, 0, 0, 1}, {2, 0, 0, 1}, {3, 0, 0, 1}, {4, 0, 0, 6}, + {5, 0, 0, 1}, {6, 0, 0, 1}, {7, 0, 0, 1}, {8, 0, 0, 2}, {9, 0, 0, 1}, + {10, 0, 0, 1}, {11, 0, 0, 2}, {12, 0, 0, 1}, {13, 0, 0, 1}, +}; + +edge_t edge_buf[] = { + {0, 0, 1, 101, 122}, {1, 1, 2, 179, 377}, {2, 2, 3, 124, 202}, + {3, 3, 4, 125, 261}, {4, 4, 5, 182, 423}, {5, 5, 6, 184, 405}, + {6, 6, 7, 140, 259}, {7, 7, 8, 118, 398}, {8, 8, 9, 128, 228}, + {9, 9, 10, 186, 238}, {10, 10, 11, 172, 236}, {11, 11, 12, 187, 350}, + {12, 12, 13, 163, 217}, {13, 0, 4, 180, 181}, {14, 0, 6, 5, 249}, + {15, 0, 7, 108, 427}, {16, 0, 12, 155, 139}, {17, 0, 8, 3, 322}, + {18, 4, 7, 106, 182}, {19, 4, 9, 81, 345}, {20, 4, 5, 212, 289}, + {21, 4, 6, 166, 419}, {22, 4, 10, 198, 30}, {23, 8, 12, 221, 308}, + {24, 11, 12, 179, 235}, +}; + +demands_t demands_buf[] = { + {0, 0, 13, 10}, {1, 0, 1, 96}, {2, 1, 6, 78}, {3, 1, 9, 95}, + {4, 3, 5, 35}, {5, 3, 10, 77}, {6, 3, 13, 38}, {7, 3, 9, 98}, + {8, 3, 11, 92}, {9, 3, 6, 29}, {10, 3, 4, 38}, {11, 4, 10, 73}, + {12, 4, 5, 6}, {13, 4, 12, 28}, {14, 4, 13, 4}, {15, 4, 8, 56}, + {16, 4, 9, 22}, {17, 4, 7, 48}, {18, 4, 6, 29}, {19, 5, 9, 35}, + {20, 5, 13, 39}, {21, 5, 12, 77}, {22, 5, 8, 42}, {23, 5, 10, 63}, + {24, 6, 12, 7}, {25, 6, 10, 25}, {26, 6, 11, 18}, {27, 6, 8, 29}, + {28, 6, 13, 36}, {29, 6, 9, 45}, {30, 7, 11, 36}, {31, 7, 13, 95}, + {32, 7, 12, 68}, {33, 7, 8, 33}, {34, 7, 10, 11}, {35, 8, 13, 82}, + {36, 8, 10, 7}, {37, 9, 10, 25}, {38, 9, 11, 84}, {39, 10, 13, 78}, +}; diff --git a/src/mcf/configs/test-config.c b/src/mcf/configs/test-config.c new file mode 100644 index 0000000..435a578 --- /dev/null +++ b/src/mcf/configs/test-config.c @@ -0,0 +1,25 @@ +#include "input.h" + +const int nodes_num = 4; +const int edges_num = 3; +const int demands_num = 4; + +node_t node_buf[] = { + {0, 0, 0, 1}, + {1, 0, 0, 1}, + {2, 0, 0, 1}, + {3, 0, 0, 1}, +}; + +edge_t edge_buf[] = { + {0, 0, 1, 121, 468}, + {1, 1, 2, 185, 328}, + {2, 2, 3, 141, 271}, +}; + +demands_t demands_buf[] = { + {0, 0, 3, 10}, + {1, 0, 3, 60}, + {2, 0, 1, 92}, + {3, 1, 2, 18}, +}; diff --git a/src/mcf/configs/train-config.c b/src/mcf/configs/train-config.c new file mode 100644 index 0000000..87d1d76 --- /dev/null +++ b/src/mcf/configs/train-config.c @@ -0,0 +1,20 @@ +#include "input.h" + +const int nodes_num = 6; +const int edges_num = 5; +const int demands_num = 6; + +node_t node_buf[] = { + {0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}, + {3, 0, 0, 1}, {4, 0, 0, 1}, {5, 0, 0, 1}, +}; + +edge_t edge_buf[] = { + {0, 0, 1, 164, 484}, {1, 1, 2, 193, 186}, {2, 2, 3, 167, 274}, + {3, 3, 4, 180, 133}, {4, 4, 5, 129, 348}, +}; + +demands_t demands_buf[] = { + {0, 0, 5, 10}, {1, 0, 2, 52}, {2, 0, 4, 13}, + {3, 1, 5, 20}, {4, 1, 2, 72}, {5, 1, 3, 44}, +}; diff --git a/src/mcf/include/input.h b/src/mcf/include/input.h index e045c28..da88a35 100644 --- a/src/mcf/include/input.h +++ b/src/mcf/include/input.h @@ -1,33 +1,34 @@ -#ifndef __test_h__ -#define __test_h__ +#ifndef __TEST_H__ +#define __TEST_H__ extern const int nodes_num; extern const int edges_num; extern const int demands_num; -typedef struct{ - int id; // node id - int x,y; // (x,y) location in um, location is not used currently for anything; - int edge_num; -}node_t; +typedef struct { + int id; // node id + int x, + y; // (x,y) location in um, location is not used currently for anything; + int edge_num; +} node_t; -typedef struct{ - int id; - int src; - int des; - double capacity; - double delay; -}edge_t; +typedef struct { + int id; + int src; + int des; + double capacity; + double delay; +} edge_t; -typedef struct{ - int id; - int src; - int des; - double amount; -}demands_t; +typedef struct { + int id; + int src; + int des; + double amount; +} demands_t; extern node_t node_buf[]; extern edge_t edge_buf[]; extern demands_t demands_buf[]; -#endif \ No newline at end of file +#endif diff --git a/src/mcf/include/mcf.h b/src/mcf/include/mcf.h index 5795e1a..819653b 100644 --- a/src/mcf/include/mcf.h +++ b/src/mcf/include/mcf.h @@ -1,18 +1,16 @@ #ifndef _MCF_H_ #define _MCF_H_ -#include #include #include +#include #include - - // #define MAX_DEGREE 40 #define DBL_MAX 1.7976931348623157e+308 // MCF: "max commodity flow"; MCMCF: "min-cost max concurrent flow" -typedef enum { MCF_TYPE = 0, MCMCF_TYPE = 1 }PROBLEM_TYPE; +typedef enum { MCF_TYPE = 0, MCMCF_TYPE = 1 } PROBLEM_TYPE; //////////////////////////////////////////////////////////////////////////////// // @@ -20,58 +18,65 @@ typedef enum { MCF_TYPE = 0, MCMCF_TYPE = 1 }PROBLEM_TYPE; // //////////////////////////////////////////////////////////////////////////////// -static inline int max(int a, int b){return b > a ? b : a;} +static inline int max(int a, int b) { return b > a ? b : a; } -typedef struct -{ - int id; // start from 0 - int x, y; // location coordinates directly in um; // 位置坐标直接在um中; - int pre; // parent node in shortest path tree // 最短路径树的父节点 - int pre_edge; // parent edge in shortest path tree // 最短路径树中的父边 - double dist; // distance for shortest path algorithm // 最短路径算法的距离 - int no_comm; // number of destinations for commodities starting from this node // 从该节点出发的商品目的地数量 - int *comms; // list of commodities starting from the node // 从该节点开始的商品列表 - int no_edge; // number of edges incident to the node // 与节点关联的边数 - int *edges; // list of edges incident to the node // 与节点关联的边列表 - int dij_visited; // flag for Dijkstra algo // Dijkstra 算法的标志 - int dij_updated; // second flag for Dijkstra algo // Dijkstra 算法的第二个标志 - int min_visited; // flag for searching min c(e) // 搜索 min c(e) 的标志 - // _preferred_path has a number of elements equal to the number of - // commodities; each entry stores the next, downstream, node index - // of the preferred unique path of the flow of this commodity from - // src toward des; this is constructed during the randomized rounding; - // _preferred_path 的元素数量等于商品数量; 每个条目存储该商品从 src 到 des 的 - // 首选唯一路径的下一个下游节点索引; 这是在随机舍入期间构建的; - int *_preferred_path; -}NODE; +typedef struct { + int id; // start from 0 + int x, y; // location coordinates directly in um; // 位置坐标直接在um中; + int pre; // parent node in shortest path tree // 最短路径树的父节点 + int pre_edge; // parent edge in shortest path tree // 最短路径树中的父边 + double dist; // distance for shortest path algorithm // 最短路径算法的距离 + int no_comm; // number of destinations for commodities starting from this node + // // 从该节点出发的商品目的地数量 + int *comms; // list of commodities starting from the node // + // 从该节点开始的商品列表 + int no_edge; // number of edges incident to the node // 与节点关联的边数 + int *edges; // list of edges incident to the node // 与节点关联的边列表 + int dij_visited; // flag for Dijkstra algo // Dijkstra 算法的标志 + int dij_updated; // second flag for Dijkstra algo // Dijkstra 算法的第二个标志 + int min_visited; // flag for searching min c(e) // 搜索 min c(e) 的标志 + // _preferred_path has a number of elements equal to the number of + // commodities; each entry stores the next, downstream, node index + // of the preferred unique path of the flow of this commodity from + // src toward des; this is constructed during the randomized rounding; + // _preferred_path 的元素数量等于商品数量; 每个条目存储该商品从 src 到 des 的 + // 首选唯一路径的下一个下游节点索引; 这是在随机舍入期间构建的; + int *_preferred_path; +} NODE; //////////////////////////////////////////////////////////////////////////////// // // EDGE // //////////////////////////////////////////////////////////////////////////////// -typedef struct -{ - int id; // start from 0 - int src, dest; // source and destination node id - double latency; // delay of this edge; will play role of cost; // 该边沿的延迟; 将发挥成本的作用; - double length; - // _flows has a number of elements equal to the number of demands/ - // commodities with the index being the id of demand; - // _flows有与需求商品数量相等的元素,索引为需求的id; - double *_flows; - double flow; // accumulated total flow; // 累计总流量; - double capacity; // c_e - double left_capacity; - // dual of capacity; - // 容量的对偶; - double _Y_e; - double _old_Y_e; -}EDGE; +typedef struct { + int id; // start from 0 + int src, dest; // source and destination node id + double latency; // delay of this edge; will play role of cost; // + // 该边沿的延迟; 将发挥成本的作用; + double length; + // _flows has a number of elements equal to the number of demands/ + // commodities with the index being the id of demand; + // _flows有与需求商品数量相等的元素,索引为需求的id; + double *_flows; + double flow; // accumulated total flow; // 累计总流量; + double capacity; // c_e + double left_capacity; + // dual of capacity; + // 容量的对偶; + double _Y_e; + double _old_Y_e; +} EDGE; -static inline void set_flow_of_commodity(EDGE *edge, int id, double flow) { edge->_flows[ id] = flow; } -static inline void add_to_flow_of_commodity(EDGE *edge, int id, double val) { edge->_flows[ id] += val; } -static inline double flow_of_commodity(EDGE *edge, int id) { return edge->_flows[ id]; } +static inline void set_flow_of_commodity(EDGE *edge, int id, double flow) { + edge->_flows[id] = flow; +} +static inline void add_to_flow_of_commodity(EDGE *edge, int id, double val) { + edge->_flows[id] += val; +} +static inline double flow_of_commodity(EDGE *edge, int id) { + return edge->_flows[id]; +} //////////////////////////////////////////////////////////////////////////////// // @@ -79,14 +84,13 @@ static inline double flow_of_commodity(EDGE *edge, int id) { return edge->_flow // //////////////////////////////////////////////////////////////////////////////// -typedef struct -{ - int id; // start from 0 - int src, dest; // source and destination - double demand; - double left_demand; +typedef struct { + int id; // start from 0 + int src, dest; // source and destination + double demand; + double left_demand; -}COMMODITY; +} COMMODITY; //////////////////////////////////////////////////////////////////////////////// // @@ -94,66 +98,56 @@ typedef struct // //////////////////////////////////////////////////////////////////////////////// -typedef struct -{ - // Note: "inherited" like this from the original code; I should - // make them vectors; - // 注意:从原始代码中这样“继承”; 我应该把它们做成矢量; - int no_node; - NODE *nodes; - int no_edge; - EDGE *edges; - int no_cut; - int no_commodity; - COMMODITY *_commodities; +typedef struct { + // Note: "inherited" like this from the original code; I should + // make them vectors; + int no_node; + NODE *nodes; + int no_edge; + EDGE *edges; + int no_cut; + int no_commodity; + COMMODITY *_commodities; - // primal variables are the actual final flows through edges of graph; - // their values are stored in _flows of EDGE class; - // dual variable PHI_d; the other dual variables are Y_e - // and the "length function" (see Ababei paper); - // 原始变量是通过图边的实际最终流量; 它们的值存储在 EDGE 类的 _flows 中; - // 双变量PHI_d; 其他对偶变量是 Y_e 和“长度函数”(参见 Ababei 论文); - double _phi_latency; - // L is used to record the minimum latency achievable; utilized as - // budget in the MCF problem formulation; found out via binary search; - // L用于记录可实现的最小延迟; 用作 MCF 问题制定中的预算; 通过二分查找找到; - double L, LL, UL; // L is latency budget; LL/UP is lower/upper latency; // L 是延迟预算; LL/UP 是较低/较高延迟; + // primal variables are the actual final flows through edges of graph; + // their values are stored in _flows of EDGE class; + // dual variable PHI_d; the other dual variables are Y_e + // and the "length function" (see Ababei paper); + double _phi_latency; + // L is used to record the minimum latency achievable; utilized as + // budget in the MCF problem formulation; found out via binary search; + double L, LL, UL; // L is latency budget; LL/UP is lower/upper latency; - // lambda_max is the first lambda that mcf() returns, with initial - // latency_limit relaxed to 1000000 (inf); - // lambda_max 是 mcf() 返回的第一个 lambda,初始 Latency_limit 放宽至 1000000 (inf); - double _lambda_max; - double _latency_max; // associated with lambda_max; // 与 lambda_max 关联; - double _total_latency; + // lambda_max is the first lambda that mcf() returns, with initial + // latency_limit relaxed to 1000000 (inf); + double _lambda_max; + double _latency_max; // associated with lambda_max; + double _total_latency; - // control variables; - // 控制变量; - double _delta; - double _epsilon1; - double _scale; - // s = [P(lambda_max) - L]/[lambda_max - dual]; see eq. 9 of Hu - // paper; used to implement "interval estimation"; - // s = [P(lambda_max) - L]/[lambda_max - 对偶]; 参考Hu的论文的例9; 用于实现“区间估计”; - double _s; - // temp_edge_flow stores how much flow is routed during an iteration; - // it is a sketch array; - // temp_edge_flow 存储迭代期间路由的流量; 它是一个草图数组; - double *_temp_edge_flow; - int _rd; - int _min_rd; - // arguments; - PROBLEM_TYPE _problem_type; - char _network_filename[512]; -}MCF; + // control variables; + double _delta; + double _epsilon1; + double _scale; + // s = [P(lambda_max) - L]/[lambda_max - dual]; see eq. 9 of Hu + // paper; used to implement "interval estimation"; + double _s; + // temp_edge_flow stores how much flow is routed during an iteration; + // it is a sketch array; + double *_temp_edge_flow; + int _rd; + int _min_rd; + // arguments; + PROBLEM_TYPE _problem_type; + char _network_filename[512]; +} MCF; -void MCF_init(MCF *mcf) ; +void MCF_init(MCF *mcf); // utils; -static inline double flow_of_commodity_thru_edge(MCF *mcf, int c_id, int e_id) -{ - //assert(c_id >= 0 && c_id < no_commodity); - //assert(e_id >= 0 && e_id < no_edge); - return flow_of_commodity(&mcf->edges[ e_id], c_id); +static inline double flow_of_commodity_thru_edge(MCF *mcf, int c_id, int e_id) { + // assert(c_id >= 0 && c_id < no_commodity); + // assert(e_id >= 0 && e_id < no_edge); + return flow_of_commodity(&mcf->edges[e_id], c_id); } static inline double get_L(MCF *mcf) { return mcf->L; } static inline int problem_type(MCF *mcf) { return mcf->_problem_type; } @@ -191,7 +185,6 @@ void read_network_topology_and_demands(MCF *mcf, double rate); void free_topology(MCF *mcf); void print_network_demands(MCF *mcf, bool print_only_edges); void print_backward_shortest_path(MCF *mcf, int t); -void print_routing_paths(MCF *mcf); - +void print_routing_paths(MCF *mcf); #endif diff --git a/src/mcf/include/pqueue.h b/src/mcf/include/pqueue.h index 379682d..99336dc 100644 --- a/src/mcf/include/pqueue.h +++ b/src/mcf/include/pqueue.h @@ -11,40 +11,48 @@ // //////////////////////////////////////////////////////////////////////////////// -typedef struct -{ - int _node; - double _dist; -}PQDATUM; +typedef struct { + int _node; + double _dist; +} PQDATUM; -static inline void PQDATUM_init(PQDATUM *pqdatum){pqdatum->_node = -1; pqdatum->_dist = -1;} +static inline void PQDATUM_init(PQDATUM *pqdatum) { + pqdatum->_node = -1; + pqdatum->_dist = -1; +} static inline int node(PQDATUM *pqdatum) { return pqdatum->_node; } static inline double dist(PQDATUM *pqdatum) { return pqdatum->_dist; } -static inline void set_node(PQDATUM *pqdatum, int node) { pqdatum->_node = node; } -static inline void set_dist(PQDATUM *pqdatum, double dist) { pqdatum->_dist = dist; } +static inline void set_node(PQDATUM *pqdatum, int node) { + pqdatum->_node = node; +} +static inline void set_dist(PQDATUM *pqdatum, double dist) { + pqdatum->_dist = dist; +} -typedef struct -{ - int _size, _avail, _step; - PQDATUM *_d; -}PQUEUE; +typedef struct { + int _size, _avail, _step; + PQDATUM *_d; +} PQUEUE; -static inline void PQUEUE_init(PQUEUE *pqueue){pqueue->_size = -1; pqueue->_avail = -1; pqueue->_step = -1;} +static inline void PQUEUE_init(PQUEUE *pqueue) { + pqueue->_size = -1; + pqueue->_avail = -1; + pqueue->_step = -1; +} static inline int size(PQUEUE *pqueue) { return pqueue->_size; } static inline int avail(PQUEUE *pqueue) { return pqueue->_avail; } static inline int step(PQUEUE *pqueue) { return pqueue->_step; } static inline PQDATUM *d(PQUEUE *pqueue) { return pqueue->_d; } PQUEUE *pqinit(PQUEUE *pqueue, int n); -int pqinsert( PQUEUE *pqueue, PQDATUM a_d, int *pos); +int pqinsert(PQUEUE *pqueue, PQDATUM a_d, int *pos); PQDATUM *pqremove(PQUEUE *pqueue, PQDATUM *a_d, int *pos); int pqdeckey(PQUEUE *pqueue, PQDATUM a_d, int *pos); PQDATUM *pqpeek(PQUEUE *pqueue, PQDATUM *a_d); static inline double get_distance(PQDATUM d) { return dist(&d); } -static inline int pqempty(PQUEUE *pqueue) { return ( pqueue->_size == 1); } +static inline int pqempty(PQUEUE *pqueue) { return (pqueue->_size == 1); } static inline void pqfree(PQUEUE *pqueue, int *pos) { - bench_free( pqueue->_d); - bench_free( pos); + bench_free(pqueue->_d); + bench_free(pos); } - #endif diff --git a/src/mcf/main.c b/src/mcf/main.c index 229e1fb..54220ec 100644 --- a/src/mcf/main.c +++ b/src/mcf/main.c @@ -1,8 +1,8 @@ #include -#include -#include -#include +#include #include +#include +#include extern int demands_select; @@ -12,47 +12,45 @@ extern int demands_select; // //////////////////////////////////////////////////////////////////////////////// -int main(char *args) -{ - bench_malloc_init(); - uint64_t start_time, end_time; - start_time = uptime(); +int main(char *args) { + bench_malloc_init(); + uint64_t start_time, end_time; + start_time = uptime(); - bench_printf("\nRandomized rounded paths: size: %d\n", sizeof(size_t)); - for(demands_select = 0; demands_select < demands_num; demands_select++) - { - // (1) run MCF solver; - MCF mcf; - MCF_init(&mcf); - // here you should build your network either by reading it from a - // file (network examples are in /tests) or by populating the - // mcf object directly from the host application (the one inside - // which you plan to call MCF solver possibly multiple times); - // parse_options(&mcf, argc, argv); - parse_options(&mcf, "MCF", 0.1); - build_network_from_file(&mcf, 1000000, 1); - run_mcf_solver(&mcf); + BENCH_LOG(DEBUG, "\nRandomized rounded paths: size: %d", sizeof(size_t)); + for (demands_select = 0; demands_select < demands_num; demands_select++) { + // (1) run MCF solver; + MCF mcf; + MCF_init(&mcf); + // here you should build your network either by reading it from a + // file (network examples are in /tests) or by populating the + // mcf object directly from the host application (the one inside + // which you plan to call MCF solver possibly multiple times); + // parse_options(&mcf, argc, argv); + parse_options(&mcf, "MCF", 0.1); + build_network_from_file(&mcf, 1000000, 1); + run_mcf_solver(&mcf); - // (2) entertain user; - // printf("\n\nFINAL RESULT:"); - // if ( problem_type(&mcf) == MCMCF_TYPE) { - // printf("\nFinal latency L=%lf", get_L(&mcf)); - // } - // print_network_demands(&mcf, true); // print_only_edges; - // Note: rounding is not required; you may want or not to use this - // in your application; in my case I do it so that one commodity - // is shipped only via one path (in the context of NoCs I want to - // avoid packet (re)ordering at destinations); be aware: randomization - // "damages" optimality and may violate capacities; - do_randomized_rounding(&mcf); - print_routing_paths(&mcf); + // (2) entertain user; + // printf("\n\nFINAL RESULT:"); + // if ( problem_type(&mcf) == MCMCF_TYPE) { + // printf("\nFinal latency L=%lf", get_L(&mcf)); + // } + // print_network_demands(&mcf, true); // print_only_edges; + // + // Note: rounding is not required; you may want or not to use this + // in your application; in my case I do it so that one commodity + // is shipped only via one path (in the context of NoCs I want to + // avoid packet (re)ordering at destinations); be aware: randomization + // "damages" optimality and may violate capacities; + do_randomized_rounding(&mcf); + print_routing_paths(&mcf); + // (3) clean up + free_topology(&mcf); + } + end_time = uptime(); + BENCH_LOG(INFO, "OpenPerf time: %s", format_time(end_time - start_time)); - // (3) clean up - free_topology(&mcf); - } - end_time = uptime(); - bench_printf("time: %s ms \n", format_time(end_time - start_time)); - - return 0; + return 0; } diff --git a/src/mcf/mcf.c b/src/mcf/mcf.c index a5c4906..bb31d55 100644 --- a/src/mcf/mcf.c +++ b/src/mcf/mcf.c @@ -1,33 +1,31 @@ -#include -#include -#include -#include -#include +#include #include +#include +#include +#include +#include +void MCF_init(MCF *mcf) { + mcf->no_node = 0; + mcf->no_edge = 0; + mcf->no_commodity = 0; -void MCF_init(MCF *mcf) -{ - mcf->no_node = 0; - mcf->no_edge = 0; - mcf->no_commodity = 0; + mcf->L = 0; + mcf->LL = 0; + mcf->UL = 0; + mcf->_phi_latency = 0; + mcf->_lambda_max = 0; + mcf->_latency_max = 0; + mcf->_total_latency = 0; - mcf->L=0; - mcf->LL=0; - mcf->UL=0; - mcf->_phi_latency = 0; - mcf->_lambda_max = 0; - mcf->_latency_max = 0; - mcf->_total_latency = 0; - - mcf->_delta = 1.0; - mcf->_epsilon1 = 0.1; - mcf->_scale = 1; - mcf->_s = -1; - mcf->_min_rd = 0; - mcf->_rd = 0; - mcf->_temp_edge_flow = 0; - mcf->_problem_type = MCMCF_TYPE; + mcf->_delta = 1.0; + mcf->_epsilon1 = 0.1; + mcf->_scale = 1; + mcf->_s = -1; + mcf->_min_rd = 0; + mcf->_rd = 0; + mcf->_temp_edge_flow = 0; + mcf->_problem_type = MCMCF_TYPE; } //////////////////////////////////////////////////////////////////////////////// @@ -36,384 +34,383 @@ void MCF_init(MCF *mcf) // //////////////////////////////////////////////////////////////////////////////// -void initialize(MCF *mcf, double delta, int flag) -{ - // called each time mcf() is called; - int i=0; +void initialize(MCF *mcf, double delta, int flag) { + // called each time mcf() is called; + int i = 0; - // init dual variables - if (flag == 0) { // 0: "max concurrent flow" - mcf->_phi_latency = 0.0; - } else { // 1 "min-cost max concurrent flow" - mcf->_phi_latency = delta / mcf->L; // dual variable PHI_d = 1/1000000 - } - for ( i = 0; i < mcf->no_edge; i++) { - mcf->edges[i]._Y_e = delta / mcf->edges[i].capacity; - mcf->edges[i]._old_Y_e = mcf->edges[i]._Y_e; - } - // init edges - for (i = 0; i < mcf->no_edge; i++) { - mcf->edges[i].flow = 0.0; - for (int j = 0; j < mcf->no_commodity; j++) { - mcf->edges[i]._flows[ j] = 0.0; - } - } - // reset edge flows - for ( i = 0; i < mcf->no_edge; i++) { - mcf->_temp_edge_flow[i] = 0.0; - } - // init edge "length function" l(e) - for ( i = 0; i < mcf->no_edge; i++) { - mcf->edges[i].length = 0.0; - mcf->edges[i].length += mcf->edges[i]._Y_e; - mcf->edges[i].length += mcf->edges[i].latency * mcf->_phi_latency; // 0 for flag=0; - } - // init commodities - for ( i = 0; i < mcf->no_commodity; i++) { - mcf->_commodities[i].left_demand = mcf->_commodities[i].demand; + // init dual variables + if (flag == 0) { // 0: "max concurrent flow" + mcf->_phi_latency = 0.0; + } else { // 1 "min-cost max concurrent flow" + mcf->_phi_latency = delta / mcf->L; // dual variable PHI_d = 1/1000000 + } + for (i = 0; i < mcf->no_edge; i++) { + mcf->edges[i]._Y_e = delta / mcf->edges[i].capacity; + mcf->edges[i]._old_Y_e = mcf->edges[i]._Y_e; + } + // init edges + for (i = 0; i < mcf->no_edge; i++) { + mcf->edges[i].flow = 0.0; + for (int j = 0; j < mcf->no_commodity; j++) { + mcf->edges[i]._flows[j] = 0.0; } + } + // reset edge flows + for (i = 0; i < mcf->no_edge; i++) { + mcf->_temp_edge_flow[i] = 0.0; + } + // init edge "length function" l(e) + for (i = 0; i < mcf->no_edge; i++) { + mcf->edges[i].length = 0.0; + mcf->edges[i].length += mcf->edges[i]._Y_e; + mcf->edges[i].length += + mcf->edges[i].latency * mcf->_phi_latency; // 0 for flag=0; + } + // init commodities + for (i = 0; i < mcf->no_commodity; i++) { + mcf->_commodities[i].left_demand = mcf->_commodities[i].demand; + } - // reset _total_latency, which will be computed as the summation - // of individual latencies from shortest-path trees for each source - // of commodities; - mcf->_total_latency = 0.0; + // reset _total_latency, which will be computed as the summation + // of individual latencies from shortest-path trees for each source + // of commodities; + mcf->_total_latency = 0.0; } -bool parse_options(MCF *mcf, char *arg, float epsilon) -{ - // mcf->_problem_type = MCMCF_TYPE; // default; - // mcf->_epsilon1 = 0.1; // default; +bool parse_options(MCF *mcf, char *arg, float epsilon) { + // mcf->_problem_type = MCMCF_TYPE; // default; + // mcf->_epsilon1 = 0.1; // default; - if (strcmp(arg, "MCF") == 0) { - mcf->_problem_type = MCF_TYPE; - } - else if (strcmp(arg, "MCMCF") == 0) { - mcf->_problem_type = MCMCF_TYPE; - } else { - bench_printf("Error: -problem_type must be MCF or MCMCF.\n"); + if (strcmp(arg, "MCF") == 0) { + mcf->_problem_type = MCF_TYPE; + } else if (strcmp(arg, "MCMCF") == 0) { + mcf->_problem_type = MCMCF_TYPE; + } else { + BENCH_LOG(ERROR, "Error: -problem_type must be MCF or MCMCF.\n"); + assert(0); + } + + mcf->_epsilon1 = epsilon; + if (mcf->_epsilon1 <= 0 || mcf->_epsilon1 >= 1) { + BENCH_LOG(ERROR, "Error: -epsilon option requires a float in (0,1).\n"); + assert(0); + } + + return true; +} + +void init_param(MCF *mcf) { + // called one time only from inside build_network_from_file() because + // we need the number of edges of the graph for delta calculation; + // () set latency budget to infinity (inf); + mcf->L = 1000000.0; + // () epsilon is now set to default _epsilon1 = 0.1 inside parse_options(); + // or it could be set by user via command line argument; + // () delta is set according to equation 3 from Karakostas paper; + double epsilon = mcf->_epsilon1; + mcf->_delta = (1 / pow(1 + epsilon, (1 - epsilon) / epsilon)) * + (pow((1 - epsilon) / mcf->no_edge, 1 / epsilon)); + // () expected number of iterations (or phases) of the outer loop; + // currently it is not used for any purpose; + mcf->_scale = log((1 + epsilon) / mcf->_delta) / log(1 + epsilon); + // printf("\nepsilon=%e delta=%e _scale=%e\n",_epsilon1,_delta,_scale); // + // assert(0); +} + +bool feasibility_check(MCF *mcf) { + // check and see if the routed flows violate capacities; if so, + // then return false: no feasible solution; this is a "stretch"; + // feasibility should be checked differently; + double threshold, violation; + bool printed_warning = false; + for (int i = 0; i < mcf->no_edge; i++) { + if (mcf->edges[i].flow > mcf->edges[i].capacity) { + // consider only violations that are greater than 3 * epsilon; + threshold = 3 * mcf->_epsilon1 * mcf->edges[i].capacity; + violation = (mcf->edges[i].flow - mcf->edges[i].capacity); + if (violation > threshold) { + return false; + } else { + // print once only a warning; + if (!printed_warning) { + bench_printf("\nWarning: Some edges have capacity violation within " + "3*epsilon"); + printed_warning = true; + } + } + } + } + return true; // solution is ok; +} + +double compute_D(MCF *mcf) { + // "D" is the numerator of dual=D/alpha; see section 6 of Garg paper; + double D = 0.0; + for (int i = 0; i < mcf->no_edge; i++) { + D += mcf->edges[i]._Y_e * mcf->edges[i].capacity; + } + D += mcf->L * mcf->_phi_latency; + + return D; +} + +double compute_alpha(MCF *mcf) { + // "alpha" is the denuminator of dual=D/alpha; see section 6 of Garg paper; + int i, j; + double alpha = 0.0; // to return; + for (i = 0; i < mcf->no_node; i++) { + if (mcf->nodes[i].no_comm) { + int *dest_flag = (int *)bench_malloc((mcf->no_node) * sizeof(int)); + assert(dest_flag); + if (dest_flag == NULL) { + printf("\nError: Unable to bench_malloc .\n"); assert(0); - } + } + memset((void *)dest_flag, 0, (mcf->no_node) * sizeof(int)); - mcf->_epsilon1 = epsilon; - if (mcf->_epsilon1 <= 0 || mcf->_epsilon1 >= 1) { - bench_printf("Error: -epsilon option requires a float in (0,1).\n"); - assert(0); - } + for (j = 0; j < mcf->nodes[i].no_comm; j++) { + dest_flag[mcf->_commodities[mcf->nodes[i].comms[j]].dest] = 1; + } - return true; + shortest_paths(mcf, mcf->nodes[i].id, mcf->nodes[i].no_comm, dest_flag); + mcf->_rd++; + bench_free(dest_flag); + + for (j = 0; j < mcf->nodes[i].no_comm; j++) { + alpha += + mcf->_commodities[mcf->nodes[i].comms[j]].demand * + mcf->nodes[mcf->_commodities[mcf->nodes[i].comms[j]].dest].dist; + } + } + } + + return alpha; } -void init_param(MCF *mcf) -{ - // called one time only from inside build_network_from_file() because - // we need the number of edges of the graph for delta calculation; - // () set latency budget to infinity (inf); - mcf->L = 1000000.0; - // () epsilon is now set to default _epsilon1 = 0.1 inside parse_options(); - // or it could be set by user via command line argument; - // () delta is set according to equation 3 from Karakostas paper; - double epsilon = mcf->_epsilon1; - mcf->_delta = (1/pow(1+epsilon, (1-epsilon)/epsilon))*(pow((1-epsilon)/mcf->no_edge, 1/epsilon)); - // () expected number of iterations (or phases) of the outer loop; - // currently it is not used for any purpose; - mcf->_scale = log((1+epsilon)/mcf->_delta) / log(1+epsilon); - //printf("\nepsilon=%e delta=%e _scale=%e\n",_epsilon1,_delta,_scale); // assert(0); -} +double compute_lambda(MCF *mcf) { + // compute lambda=MIN(actual flow/demand) among all commodities; + double lambda = DBL_MAX; -bool feasibility_check(MCF *mcf) -{ - // check and see if the routed flows violate capacities; if so, - // then return false: no feasible solution; this is a "stretch"; - // feasibility should be checked differently; - double threshold, violation; - bool printed_warning = false; - for ( int i = 0; i < mcf->no_edge; i++) { - if (mcf->edges[i].flow > mcf->edges[i].capacity) { - // consider only violations that are greater than 3 * epsilon; - threshold = 3 * mcf->_epsilon1 * mcf->edges[i].capacity; - violation = (mcf->edges[i].flow - mcf->edges[i].capacity); - if ( violation > threshold) { - return false; - } else { - // print once only a warning; - if ( !printed_warning) { - bench_printf("\nWarning: Some edges have capacity violation within 3*epsilon"); - printed_warning = true; - } - } - } + for (int comm_i = 0; comm_i < mcf->no_commodity; comm_i++) { + // for each commodity we take its source node and look + // at its outgoing edges to sum all flow pushed/routed + // for this commodity; + int src_id = mcf->_commodities[comm_i].src; // source node; + double routed_flow_this_commodity = 0.0; + for (int j = 0; j < mcf->nodes[src_id].no_edge; j++) { + int edge_id = mcf->nodes[src_id].edges[j]; + routed_flow_this_commodity += mcf->edges[edge_id]._flows[comm_i]; } - return true; // solution is ok; -} - -double compute_D(MCF *mcf) -{ - // "D" is the numerator of dual=D/alpha; see section 6 of Garg paper; - double D = 0.0; - for ( int i = 0; i < mcf->no_edge; i++) { - D += mcf->edges[i]._Y_e * mcf->edges[i].capacity; + double this_lambda = + routed_flow_this_commodity / mcf->_commodities[comm_i].demand; + if (this_lambda < lambda) { + lambda = this_lambda; } - D += mcf->L *mcf->_phi_latency; + } - return D; + return lambda; } -double compute_alpha(MCF *mcf) -{ - // "alpha" is the denuminator of dual=D/alpha; see section 6 of Garg paper; - int i, j; - double alpha = 0.0; // to return; - for ( i = 0; i < mcf->no_node; i++) { - if ( mcf->nodes[i].no_comm) { - int *dest_flag = (int*)bench_malloc((mcf->no_node)*sizeof(int)); - assert(dest_flag); - if ( dest_flag == NULL) { - printf("\nError: Unable to bench_malloc .\n"); assert(0); - } - memset((void*)dest_flag,0,(mcf->no_node)*sizeof(int)); - - for ( j = 0; j < mcf->nodes[i].no_comm; j++) { - dest_flag[mcf->_commodities[mcf->nodes[i].comms[j]].dest] = 1; - } - - shortest_paths(mcf, mcf->nodes[i].id, mcf->nodes[i].no_comm, dest_flag); - mcf->_rd++; - bench_free( dest_flag); +double check_latency_constraint(MCF *mcf, int dest) { + // this is L/c(P) in Fleischer paper (pp. 10), where + // c(P) is is the cost of sending one unit of flow along + // the shortest path: Sum_{e in P}{D(e)}, where D(e) is + // latency of each edge along path; + int t = dest; + double cost_to_send_unit_flow = 0.0; // along the shortest path to this dest; + while (mcf->nodes[t].pre != -1) { + cost_to_send_unit_flow += mcf->edges[mcf->nodes[t].pre_edge].latency; + t = mcf->nodes[t].pre; + } - for ( j = 0; j < mcf->nodes[i].no_comm; j++) { - alpha += mcf->_commodities[mcf->nodes[i].comms[j]].demand * - mcf->nodes[mcf->_commodities[mcf->nodes[i].comms[j]].dest].dist; - } - } - } - - return alpha; + return mcf->L / cost_to_send_unit_flow; } -double compute_lambda(MCF *mcf) -{ - // compute lambda=MIN(actual flow/demand) among all commodities; - double lambda = DBL_MAX; +double min_capacity(MCF *mcf, int s) { + // Note: currently not used; + // find "c" as the minimum capacity of the edges on ALL + // the paths in the shortest paths tree for this source node "s"; + int t = 0; + double min_capacity = 1000000.0; - for ( int comm_i = 0; comm_i < mcf->no_commodity; comm_i++) { - // for each commodity we take its source node and look - // at its outgoing edges to sum all flow pushed/routed - // for this commodity; - int src_id = mcf->_commodities[comm_i].src; // source node; - double routed_flow_this_commodity = 0.0; - for ( int j = 0; j < mcf->nodes[src_id].no_edge; j++) { - int edge_id = mcf->nodes[src_id].edges[j]; - routed_flow_this_commodity += mcf->edges[edge_id]._flows[ comm_i]; - } - double this_lambda = routed_flow_this_commodity / mcf->_commodities[comm_i].demand; - if ( this_lambda < lambda) { - lambda = this_lambda; - } - } - - return lambda; -} - -double check_latency_constraint(MCF *mcf, int dest) -{ - // this is L/c(P) in Fleischer paper (pp. 10), where - // c(P) is is the cost of sending one unit of flow along - // the shortest path: Sum_{e in P}{D(e)}, where D(e) is - // latency of each edge along path; - int t = dest; - double cost_to_send_unit_flow = 0.0; // along the shortest path to this dest; - while ( mcf->nodes[t].pre != -1) { - cost_to_send_unit_flow += mcf->edges[mcf->nodes[t].pre_edge].latency; - t = mcf->nodes[t].pre; - } - - return mcf->L/cost_to_send_unit_flow; -} - -double min_capacity(MCF *mcf, int s) -{ - // Note: currently not used; - // find "c" as the minimum capacity of the edges on ALL - // the paths in the shortest paths tree for this source node "s"; - int t = 0; - double min_capacity = 1000000.0; - - mcf->_min_rd++; - // start from all dest nodes, traverse shortest path tree; - for ( int i = 0; i < mcf->nodes[s].no_comm; i++) { - if ( mcf->_commodities[mcf->nodes[s].comms[i]].left_demand > 1e-3) { - // pick up this destination and walk backward to sourse "s"; - t = mcf->_commodities[mcf->nodes[s].comms[i]].dest; - while ( (mcf->nodes[t].pre != -1) && (mcf->nodes[t].min_visited != mcf->_min_rd)) { - int edge_id = mcf->nodes[t].pre_edge; - mcf->nodes[t].min_visited = mcf->_min_rd; - - if (mcf->edges[edge_id].capacity < min_capacity) { - min_capacity = mcf->edges[edge_id].capacity; - } - } - } - } - return min_capacity; -} - -double min_capacity_this_commodity(MCF *mcf, int dest) -{ - // find "c" as the minimum available capacity of the edges on - // the shortest path for this sink node "t"; - double min_avail_capacity = 1000000.0; - - int t = dest; - while ( mcf->nodes[t].pre != -1) { + mcf->_min_rd++; + // start from all dest nodes, traverse shortest path tree; + for (int i = 0; i < mcf->nodes[s].no_comm; i++) { + if (mcf->_commodities[mcf->nodes[s].comms[i]].left_demand > 1e-3) { + // pick up this destination and walk backward to sourse "s"; + t = mcf->_commodities[mcf->nodes[s].comms[i]].dest; + while ((mcf->nodes[t].pre != -1) && + (mcf->nodes[t].min_visited != mcf->_min_rd)) { int edge_id = mcf->nodes[t].pre_edge; - if ( mcf->edges[edge_id].left_capacity < min_avail_capacity) { - min_avail_capacity = mcf->edges[edge_id].left_capacity; + mcf->nodes[t].min_visited = mcf->_min_rd; + + if (mcf->edges[edge_id].capacity < min_capacity) { + min_capacity = mcf->edges[edge_id].capacity; } - t = mcf->nodes[t].pre; + } } - return min_avail_capacity; + } + return min_capacity; } -void reset_left_capacities_in_tree(MCF *mcf, int s) -{ - // reset left_capacities of edges in the shortest paths tree to the - // initial capacities; u'(e)=u(e), for any e in tree; - int t = 0; - // start from all dest nodes, traverse shortest path tree; - for ( int i = 0; i < mcf->nodes[s].no_comm; i++) { - if ( mcf->_commodities[mcf->nodes[s].comms[i]].left_demand > 1e-3) { - // pick up this destination and walk backward to sourse "s"; - t = mcf->_commodities[mcf->nodes[s].comms[i]].dest; - while ( mcf->nodes[t].pre != -1) { - int edge_id = mcf->nodes[t].pre_edge; - mcf->edges[edge_id].left_capacity = mcf->edges[edge_id].capacity; - t = mcf->nodes[t].pre; - } - } +double min_capacity_this_commodity(MCF *mcf, int dest) { + // find "c" as the minimum available capacity of the edges on + // the shortest path for this sink node "t"; + double min_avail_capacity = 1000000.0; + + int t = dest; + while (mcf->nodes[t].pre != -1) { + int edge_id = mcf->nodes[t].pre_edge; + if (mcf->edges[edge_id].left_capacity < min_avail_capacity) { + min_avail_capacity = mcf->edges[edge_id].left_capacity; } + t = mcf->nodes[t].pre; + } + return min_avail_capacity; } -void route_flow(MCF *mcf, int t, double routed_amount, int commodity_id) -{ - // t is destination to which we route "amount" of commodity; - while ( mcf->nodes[t].pre != -1) { +void reset_left_capacities_in_tree(MCF *mcf, int s) { + // reset left_capacities of edges in the shortest paths tree to the + // initial capacities; u'(e)=u(e), for any e in tree; + int t = 0; + // start from all dest nodes, traverse shortest path tree; + for (int i = 0; i < mcf->nodes[s].no_comm; i++) { + if (mcf->_commodities[mcf->nodes[s].comms[i]].left_demand > 1e-3) { + // pick up this destination and walk backward to sourse "s"; + t = mcf->_commodities[mcf->nodes[s].comms[i]].dest; + while (mcf->nodes[t].pre != -1) { int edge_id = mcf->nodes[t].pre_edge; - mcf->_temp_edge_flow[edge_id] += routed_amount; - mcf->edges[edge_id].left_capacity -= routed_amount; - - // record this routed_amount for this commodity id on the - // corresponding edge also; - assert(commodity_id >= 0 && commodity_id < mcf->no_commodity); - mcf->edges[ edge_id]._flows[ commodity_id] += routed_amount; - + mcf->edges[edge_id].left_capacity = mcf->edges[edge_id].capacity; t = mcf->nodes[t].pre; + } } - return; + } } -void update_dual_variables(MCF *mcf, int s, double epsilon, int flag) -{ - // update dual variables; compute l_i_j_s(e), where - // "j" is jth iteration of phase "i", and "s" is the current step; - int i, t; - double old_phi_latency; - double temp_latency = 0.0; +void route_flow(MCF *mcf, int t, double routed_amount, int commodity_id) { + // t is destination to which we route "amount" of commodity; + while (mcf->nodes[t].pre != -1) { + int edge_id = mcf->nodes[t].pre_edge; + mcf->_temp_edge_flow[edge_id] += routed_amount; + mcf->edges[edge_id].left_capacity -= routed_amount; - // (1) accumulate temp_latency along the shortest paths for the - // shortest paths tree for the commodities of this source node; - mcf->_min_rd++; - for ( i = 0; i < mcf->nodes[s].no_comm; i++) { - t = mcf->_commodities[mcf->nodes[s].comms[i]].dest; - while ( (mcf->nodes[t].pre != -1) && (mcf->nodes[t].min_visited != mcf->_min_rd)) { - int edge_id = mcf->nodes[t].pre_edge; - mcf->nodes[t].min_visited = mcf->_min_rd; - - temp_latency += mcf->_temp_edge_flow[edge_id] * mcf->edges[edge_id].latency; + // record this routed_amount for this commodity id on the + // corresponding edge also; + assert(commodity_id >= 0 && commodity_id < mcf->no_commodity); + mcf->edges[edge_id]._flows[commodity_id] += routed_amount; - // update the dual variable Y_e; - mcf->edges[edge_id]._old_Y_e = mcf->edges[edge_id]._Y_e; - // Note: _temp_edge_flow[edge_id] represents the amount of total - // flow of all commodities that have the same source "s", which is - // pushed thru this edge during this step "s"; - mcf->edges[edge_id]._Y_e *= - (1 + epsilon * mcf->_temp_edge_flow[edge_id] / mcf->edges[edge_id].capacity); - - // walk upstream on shortest path; - t = mcf->nodes[t].pre; - } - } - mcf->_min_rd++; - // record latency contributed due to total flow pushed thru during - // this step "s"; - mcf->_total_latency += temp_latency; - - // (2) update additional dual variable PHI_d; - old_phi_latency = mcf->_phi_latency; - mcf->_phi_latency *= (1 + epsilon * temp_latency / mcf->L); // adjust value from prev. iter; - - // (3) update the "length function"; - for ( i = 0; i < mcf->no_edge; i++) { - mcf->edges[i].length += (mcf->edges[i]._Y_e - mcf->edges[i]._old_Y_e); - // the above length function is enough for "max concurrent flow" problem; - // howver, if we solve "min-cost max concurrent flow", then, we must add - // more to the length function; - if ( flag != 0) { // 1 - mcf->edges[i].length += mcf->edges[i].latency * (mcf->_phi_latency - old_phi_latency); - } - } - - // (4) add to the flow recorded for each edge the accumulated - // amounts (as sum of f_{i,j,s}^{c_q}) for each commodity routed during - // this iteration, amounts which are reflected by _temp_edge_flow (which - // has values != zero) for edges of shortest path of this iter; - for ( i = 0; i < mcf->no_edge; i++) { - mcf->edges[i].flow += mcf->_temp_edge_flow[i]; - } - - // (5) reset temp storage of pushed flow during this iter; prepare it - // for the next push/iteration; - for ( i = 0; i < mcf->no_edge; i++) { - mcf->_temp_edge_flow[i] = 0.0; - } - - return; + t = mcf->nodes[t].pre; + } + return; } -void scale_down_linear(MCF *mcf, float times) -{ - // Note: currently not used; - for ( int i = 0; i < mcf->no_edge; i++) { - mcf->edges[i].length /= times; - mcf->edges[i]._Y_e /= times; +void update_dual_variables(MCF *mcf, int s, double epsilon, int flag) { + // update dual variables; compute l_i_j_s(e), where + // "j" is jth iteration of phase "i", and "s" is the current step; + int i, t; + double old_phi_latency; + double temp_latency = 0.0; + + // (1) accumulate temp_latency along the shortest paths for the + // shortest paths tree for the commodities of this source node; + mcf->_min_rd++; + for (i = 0; i < mcf->nodes[s].no_comm; i++) { + t = mcf->_commodities[mcf->nodes[s].comms[i]].dest; + while ((mcf->nodes[t].pre != -1) && + (mcf->nodes[t].min_visited != mcf->_min_rd)) { + int edge_id = mcf->nodes[t].pre_edge; + mcf->nodes[t].min_visited = mcf->_min_rd; + + temp_latency += + mcf->_temp_edge_flow[edge_id] * mcf->edges[edge_id].latency; + + // update the dual variable Y_e; + mcf->edges[edge_id]._old_Y_e = mcf->edges[edge_id]._Y_e; + // Note: _temp_edge_flow[edge_id] represents the amount of total + // flow of all commodities that have the same source "s", which is + // pushed thru this edge during this step "s"; + mcf->edges[edge_id]._Y_e *= (1 + epsilon * mcf->_temp_edge_flow[edge_id] / + mcf->edges[edge_id].capacity); + + // walk upstream on shortest path; + t = mcf->nodes[t].pre; } - mcf->_phi_latency /= times; - return; + } + mcf->_min_rd++; + // record latency contributed due to total flow pushed thru during + // this step "s"; + mcf->_total_latency += temp_latency; + + // (2) update additional dual variable PHI_d; + old_phi_latency = mcf->_phi_latency; + mcf->_phi_latency *= + (1 + epsilon * temp_latency / mcf->L); // adjust value from prev. iter; + + // (3) update the "length function"; + for (i = 0; i < mcf->no_edge; i++) { + mcf->edges[i].length += (mcf->edges[i]._Y_e - mcf->edges[i]._old_Y_e); + // the above length function is enough for "max concurrent flow" problem; + // howver, if we solve "min-cost max concurrent flow", then, we must add + // more to the length function; + if (flag != 0) { // 1 + mcf->edges[i].length += + mcf->edges[i].latency * (mcf->_phi_latency - old_phi_latency); + } + } + + // (4) add to the flow recorded for each edge the accumulated + // amounts (as sum of f_{i,j,s}^{c_q}) for each commodity routed during + // this iteration, amounts which are reflected by _temp_edge_flow (which + // has values != zero) for edges of shortest path of this iter; + for (i = 0; i < mcf->no_edge; i++) { + mcf->edges[i].flow += mcf->_temp_edge_flow[i]; + } + + // (5) reset temp storage of pushed flow during this iter; prepare it + // for the next push/iteration; + for (i = 0; i < mcf->no_edge; i++) { + mcf->_temp_edge_flow[i] = 0.0; + } + + return; } -void scale_down_flows(MCF *mcf, int phase_count) -{ - // scale down final solution; basically averaging over the number - // of phases (iterations of the main big loop of mcf); - int scale = max( 1, phase_count); // this is "t"; - for ( int i = 0; i < mcf->no_edge; i ++) { - mcf->edges[i].flow /= scale; - for ( int j = 0; j < mcf->no_commodity; j ++) { - mcf->edges[i]._flows[ j] /= scale; - } - } +void scale_down_linear(MCF *mcf, float times) { + // Note: currently not used; + for (int i = 0; i < mcf->no_edge; i++) { + mcf->edges[i].length /= times; + mcf->edges[i]._Y_e /= times; + } + mcf->_phi_latency /= times; + return; } -double minimum(double x, double y, double z) -{ - double min; - if ( x < y) { - if ( x < z) min = x; - else min = z; - } else { - if ( y < z) min = y; - else min = z; +void scale_down_flows(MCF *mcf, int phase_count) { + // scale down final solution; basically averaging over the number + // of phases (iterations of the main big loop of mcf); + int scale = max(1, phase_count); // this is "t"; + for (int i = 0; i < mcf->no_edge; i++) { + mcf->edges[i].flow /= scale; + for (int j = 0; j < mcf->no_commodity; j++) { + mcf->edges[i]._flows[j] /= scale; } - return min; + } +} + +double minimum(double x, double y, double z) { + double min; + if (x < y) { + if (x < z) + min = x; + else + min = z; + } else { + if (y < z) + min = y; + else + min = z; + } + return min; } //////////////////////////////////////////////////////////////////////////////// @@ -422,302 +419,313 @@ double minimum(double x, double y, double z) // //////////////////////////////////////////////////////////////////////////////// -int run_mcf_solver(MCF *mcf_v) -{ - // it is assumed that the network was already created from file - // or host application; +int run_mcf_solver(MCF *mcf_v) { + // it is assumed that the network was already created from file + // or host application; - // (1) first, run of MCF solver with the latency constraint - // relaxed to infinity L=1000000 (inf); this is basically - // the "max commodity flow" problem; - // Reminder on MCF flavors: - // -- "max multicommodity flow": total flow summed over all commodities - // is to be maximized; - // -- "max concurrent flow": each commodity si,ti has a demand di; - // objective is to maximize the fraction of the demand that can be shipped - // simultaneously for all commodities; - // -- "min-cost max concurrent flow"; + // (1) first, run of MCF solver with the latency constraint + // relaxed to infinity L=1000000 (inf); this is basically + // the "max commodity flow" problem; + // Reminder on MCF flavors: + // -- "max multicommodity flow": total flow summed over all commodities + // is to be maximized; + // -- "max concurrent flow": each commodity si,ti has a demand di; + // objective is to maximize the fraction of the demand that can be shipped + // simultaneously for all commodities; + // -- "min-cost max concurrent flow"; - // printf("\nPART 1 - MAX CONCURRENT FLOW (MCF):"); + // printf("\nPART 1 - MAX CONCURRENT FLOW (MCF):"); - // flag=0 means that this is a "max commodity flow" run; there is - // no latency constraint/budget; - mcf_v->_lambda_max = mcf(mcf_v, mcf_v->_delta, mcf_v->_epsilon1, 0); // flag=0; - //print_network_demands(true); // assert(0); // debug; + // flag=0 means that this is a "max commodity flow" run; there is + // no latency constraint/budget; + mcf_v->_lambda_max = + mcf(mcf_v, mcf_v->_delta, mcf_v->_epsilon1, 0); // flag=0; + // print_network_demands(true); // assert(0); // debug; - // early exit if there is no "feasible" solution; - if ( feasibility_check(mcf_v) == false) { - bench_printf("\nWarning: No feasible solution; some edges have capacity "); - bench_printf("\n violation greater than 3*epsilon.\n"); - free_topology(mcf_v); - assert(0); - } + // early exit if there is no "feasible" solution; + if (feasibility_check(mcf_v) == false) { + bench_printf("\nWarning: No feasible solution; some edges have capacity "); + bench_printf("\n violation greater than 3*epsilon.\n"); + free_topology(mcf_v); + assert(0); + } - // Note: at this time we could simply stop is we were not interested - // in solving this problem such that the minimum latency is also achieved; - // the minimum latency (stored in L) is found via binary search by - // solving repeatedly the so called "min-cost max concurrent flow" problem; - // also note that the solution we have now is most likely different - // from the solution we'll have after the binary search; - // so, if user wants a solution for the problem "max commodity flow" only, - // then stop here; - if (mcf_v->_problem_type == MCF_TYPE) { - return 1; - } - - - // (2) second, "improved" binary search to refine L; basically we look - // for the minimum latency achievable; during this search mcf is run with - // flag=1, that is as a "min-cost max concurrent flow"; - // printf("\n\nPART 2 - BINARY SEARCH FOR L - MIN-COST MAX CONCURRENT FLOW (MCMCF):"); - // maximum latency is as resulted after finding the solution of the - // "max multicommodity flow" problem from PART 1; - mcf_v->_latency_max = mcf_v->_total_latency; // Hu: 1000000; - mcf_v->LL = 0; - mcf_v->UL = mcf_v->_total_latency; // Hu: _latency_max/_lambda_max; - mcf_v->_s = -1; - - int counter = 0; - while ( (mcf_v->UL - mcf_v->LL)/mcf_v->LL > 0.1) { - // (a) set Latency as the middle point between LL and UL; - mcf_v->L = (mcf_v->LL + mcf_v->UL) / 2; - // (b) this call of MCF modifies LL and UL using the - // "interval estimation" technique proposed in Hu paper; - mcf(mcf_v, mcf_v->_delta, mcf_v->_epsilon1, 1); // flag=1; - - // (c) now, if anything goes wrong for some pathological testcase, - // have a brutal exit; this will require debugging; - counter++; - if ( counter >= 512) { - bench_printf("\nError: Binary search of MCMCF took more than 512 iterations."); - bench_printf("\n This is an unusual testcase or the code has a bug.\n"); - free_topology(mcf_v); - assert(0); - } - } - - //printf("\nLL=%lf, UL=%lf", LL, UL); - //printf("\nFinal latency L=%lf\n", UL); + // Note: at this time we could simply stop is we were not interested + // in solving this problem such that the minimum latency is also achieved; + // the minimum latency (stored in L) is found via binary search by + // solving repeatedly the so called "min-cost max concurrent flow" problem; + // also note that the solution we have now is most likely different + // from the solution we'll have after the binary search; + // so, if user wants a solution for the problem "max commodity flow" only, + // then stop here; + if (mcf_v->_problem_type == MCF_TYPE) { return 1; + } + + // (2) second, "improved" binary search to refine L; basically we look + // for the minimum latency achievable; during this search mcf is run with + // flag=1, that is as a "min-cost max concurrent flow"; + // printf("\n\nPART 2 - BINARY SEARCH FOR L - MIN-COST MAX CONCURRENT FLOW + // (MCMCF):"); maximum latency is as resulted after finding the solution of + // the "max multicommodity flow" problem from PART 1; + mcf_v->_latency_max = mcf_v->_total_latency; // Hu: 1000000; + mcf_v->LL = 0; + mcf_v->UL = mcf_v->_total_latency; // Hu: _latency_max/_lambda_max; + mcf_v->_s = -1; + + int counter = 0; + while ((mcf_v->UL - mcf_v->LL) / mcf_v->LL > 0.1) { + // (a) set Latency as the middle point between LL and UL; + mcf_v->L = (mcf_v->LL + mcf_v->UL) / 2; + // (b) this call of MCF modifies LL and UL using the + // "interval estimation" technique proposed in Hu paper; + mcf(mcf_v, mcf_v->_delta, mcf_v->_epsilon1, 1); // flag=1; + + // (c) now, if anything goes wrong for some pathological testcase, + // have a brutal exit; this will require debugging; + counter++; + if (counter >= 512) { + bench_printf( + "\nError: Binary search of MCMCF took more than 512 iterations."); + bench_printf( + "\n This is an unusual testcase or the code has a bug.\n"); + free_topology(mcf_v); + assert(0); + } + } + + // printf("\nLL=%lf, UL=%lf", LL, UL); + // printf("\nFinal latency L=%lf\n", UL); + return 1; } -double mcf(MCF *mcf_v, double delta, double epsilon, int flag) -{ - // flag: - // 0 -- max concurrent flow; - // 1 -- min-cost max concurrent flow; +double mcf(MCF *mcf_v, double delta, double epsilon, int flag) { + // flag: + // 0 -- max concurrent flow; + // 1 -- min-cost max concurrent flow; - int i,j; - int iter=0; // phase counter: number of iterations of the big main loop - double lambda=1; // result to be returned; - double D=1, alpha=1, dual=1; - // used to find the amount of flow pushed in each step; - double usable_amount_cap, usable_amount_latency, routed_amount; - // for tracking gap between lambda and dual; - // double gap=0.0; - // double old_gap=0.0; - // double old_old_gap=0.0; + int i, j; + int iter = 0; // phase counter: number of iterations of the big main loop + double lambda = 1; // result to be returned; + double D = 1, alpha = 1, dual = 1; + // used to find the amount of flow pushed in each step; + double usable_amount_cap, usable_amount_latency, routed_amount; + // for tracking gap between lambda and dual; + // double gap=0.0; + // double old_gap=0.0; + // double old_old_gap=0.0; + // () initialization of primal variables (i.e., flows thru all edges) + // and dual valiables PHI_d, Y_e and "length function" l(e) + // of all edges; also resets left_demand to demand for all commodities + // as well as _total_latency; + initialize(mcf_v, delta, flag); + mcf_v->_rd = 1; + for (i = 0; i < mcf_v->no_node; i++) { + mcf_v->nodes[i].dij_visited = 0; + mcf_v->nodes[i].dij_updated = 0; + mcf_v->nodes[i].min_visited = 0; + } - // () initialization of primal variables (i.e., flows thru all edges) - // and dual valiables PHI_d, Y_e and "length function" l(e) - // of all edges; also resets left_demand to demand for all commodities - // as well as _total_latency; - initialize(mcf_v, delta, flag); - mcf_v->_rd = 1; - for ( i = 0; i < mcf_v->no_node; i++) { - mcf_v->nodes[i].dij_visited = 0; - mcf_v->nodes[i].dij_updated = 0; - mcf_v->nodes[i].min_visited = 0; + // () the big loop, each run of this loop is a phase; each phase + // has |S| iterations; + while (1) { + + // () in every phase we start with the demand d_j for every commodity; + for (j = 0; j < mcf_v->no_commodity; j++) { + mcf_v->_commodities[j].left_demand = mcf_v->_commodities[j].demand; } - - // () the big loop, each run of this loop is a phase; each phase - // has |S| iterations; - while (1) { + // () next there are |S| iterations, one for each node that is a + // source for at least a commodity; + for (i = 0; i < mcf_v->no_node; i++) { + if (mcf_v->nodes[i] + .no_comm) { // if this node is source of "r" _commodities; - // () in every phase we start with the demand d_j for every commodity; - for ( j = 0; j < mcf_v->no_commodity; j++) { - mcf_v->_commodities[j].left_demand = mcf_v->_commodities[j].demand; + int commodities_left = mcf_v->nodes[i].no_comm; + int *dest_flag = (int *)bench_malloc((mcf_v->no_node) * sizeof(int)); + if (dest_flag == NULL) { + bench_printf("\nError: Unable to bench_malloc .\n"); + assert(0); } - - - // () next there are |S| iterations, one for each node that is a - // source for at least a commodity; - for ( i = 0; i < mcf_v->no_node; i++) { - if ( mcf_v->nodes[i].no_comm) { // if this node is source of "r" _commodities; - - int commodities_left = mcf_v->nodes[i].no_comm; - int *dest_flag = (int*)bench_malloc((mcf_v->no_node)*sizeof(int)); - if ( dest_flag == NULL) { - bench_printf("\nError: Unable to bench_malloc .\n"); assert(0); - } - memset((void*)dest_flag,0,(mcf_v->no_node)*sizeof(int)); - // dest_flag is set "1" for nodes that are destinations of _commodities; - for ( j = 0; j < mcf_v->nodes[i].no_comm; j++) { - dest_flag[mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest] = 1; - } - - - // while there are left commodities to be routed for this node; - // there are a number of steps for current iteration; - int step_count = 0; - while ( commodities_left) { - step_count ++; - - // () compute shortest PATHS tree, where edges have "length(e)"; - // of all paths from this sink to all its destinations; - //print_network_demands( true); // debug; - shortest_paths(mcf_v, mcf_v->nodes[i].id, commodities_left, dest_flag); - - // () reset left_capacities of edges in the tree to the - // initial capacities; u'(e) = u(e), any e in tree; - reset_left_capacities_in_tree(mcf_v, mcf_v->nodes[i].id); - - // () route "f = d(c_q)" units of flow of a given commodity - // and update the flow of each edge: f_e = f_e + f, along its - // shortest path; - bool flow_has_been_routed = false; - for ( j = 0; j < mcf_v->nodes[i].no_comm; j++) { - - // the amount of commodity c_q that has not been routed yet - // at step "s"; - double left_demand = mcf_v->_commodities[mcf_v->nodes[i].comms[j]].left_demand; - - if ( left_demand > 1e-3) { - flow_has_been_routed = true; - //print_backward_shortest_path(_commodities[nodes[i].comms[j]].dest); - - - // available flow amount from bottleneck-edge of shortest path; - // this "c" represents the available minimum capacity of the - // edges on shortest path of this commodity; - usable_amount_cap = min_capacity_this_commodity(mcf_v, mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest); - - - // available flow amount from latency constraint - if ( flag == 0) { // 0: "max concurrent flow" // 0: “最大并发流量” - usable_amount_latency = 1000000.0; // inf; - } else { // 1: "min-cost max concurrent flow" // 1: “最小成本最大并发流” - // this is L/c(P), where c(P) is is the cost of sending - // one unit of flow along the shortest path: - // Sum_{e in P}{D(e)}, where D(e) is latency of each edge; - usable_amount_latency = check_latency_constraint(mcf_v, mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest); - - } - - // flow amount to be routed at step "s": f_{i,j,s}^{c_q}; - routed_amount = minimum(usable_amount_cap, left_demand, usable_amount_latency); - - - - // update every "_temp_edge_flow" - from dest backward to src - // will be added routed_amount; also update left_capacities - // of edges along the shortest path of this commodity; - route_flow(mcf_v, mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest, - routed_amount, mcf_v->nodes[i].comms[j]); - - // update commodity amounts to be routed still (i.e., are left); - mcf_v->_commodities[mcf_v->nodes[i].comms[j]].left_demand -= routed_amount; - - if (mcf_v->_commodities[mcf_v->nodes[i].comms[j]].left_demand <= 1e-3) { - // this commodity is done, set its destination flag to 0; - commodities_left --; - dest_flag[mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest] = 0; - } - } - }//for ( j = 0; j < nodes[i].no_comm; j++) - - // () update dual variables: Y_e, phi_latency (or PHI_d), - // length(e); - update_dual_variables(mcf_v, mcf_v->nodes[i].id, epsilon, flag); - - mcf_v->_rd++; - if ( !flow_has_been_routed) break; - }//while ( commodities_left) - - - bench_free( dest_flag); - - }//if ( nodes[i].no_comm) - }//for ( i = 0; i < no_node; i++) - - - // () increment phase counter; a phase is an iteration of the big main loop; - iter++; - // additional stopping criterion; - if ( iter >= mcf_v->_scale) break; - //if ( iter >= 80) break; - - // () compute dual and lambda and keep track of the gap between them; - // -- compute dual=D/alpha; - D = compute_D(mcf_v); - alpha = compute_alpha(mcf_v); - dual = D / alpha; - - // -- compute lambda; - // Note1: the original code of Hu computed lambda differently; - // this is not in fact lambda in the sense of Karakostas paper, - // but rather an "artificial" variable to make easier its tracking - // towards a value of 1; - //lambda = L / (_total_latency/iter); - // Note2: I now compute it as: lambda=MIN(actual flow/demand) among all commodities; - // lambda = L / (_total_latency/iter); - lambda = compute_lambda(mcf_v); - lambda /= iter; // consider effect of scaling; - //printf("\n Lambda=%.8f, Dual=D/alpha=%.8f, D=%.8f",lambda,dual,D); - - // -- keep track of gap; - // old_old_gap = old_gap; - // old_gap = gap; - // gap = dual/lambda - 1; - - - // () this implements the "interval estimation"; see Theorem 3 of Hu paper; - if ( flag == 1) { - double UL1 = mcf_v->UL, LL1 = mcf_v->LL; - double d = dual; - //if (d < 1) d = 1; - double s1 = (mcf_v->_latency_max - mcf_v->L)/(mcf_v->_lambda_max - d); - if ( s1 > 0 && (mcf_v->_s < 0 || mcf_v->_s > s1)) { - mcf_v->_s = s1; - } - if ( mcf_v->_s > 0) { - if ( lambda < 1) { - UL1 = mcf_v->L + (1 - lambda) * mcf_v->_s; - if ( UL1 < mcf_v->UL) mcf_v->UL = UL1; - } - if ( dual > 1) { - LL1 = mcf_v->L - (dual - 1) * mcf_v->_s; - if ( LL1 > mcf_v->LL) mcf_v->LL = LL1; - } - } - if ( lambda > 1) { mcf_v->UL = mcf_v->L; } - if ( dual < 1) { mcf_v->LL = mcf_v->L; } - if ( (mcf_v->UL-mcf_v->LL < 0) || (mcf_v->UL/mcf_v->LL - 1) < 0.01) { break; } - if ( D >= 1) { break; } - } else { // 0 - // for "max commodity flow" case, the stopping criterion is - // "D>=1"; see Karakostas paper; - // Note1: original code of Hu used "dual/lambda-1= 1) { break; } + memset((void *)dest_flag, 0, (mcf_v->no_node) * sizeof(int)); + // dest_flag is set "1" for nodes that are destinations of _commodities; + for (j = 0; j < mcf_v->nodes[i].no_comm; j++) { + dest_flag[mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest] = 1; } - - }//while (1) + // while there are left commodities to be routed for this node; + // there are a number of steps for current iteration; + int step_count = 0; + while (commodities_left) { + step_count++; - // () scale down the final flows so that the solution is feasible - // (that is, capacities are met); - scale_down_flows(mcf_v, iter); - // also, record final latency, which must consider scaling too; - mcf_v->_total_latency = mcf_v->_total_latency / iter; + // () compute shortest PATHS tree, where edges have "length(e)"; + // of all paths from this sink to all its destinations; + // print_network_demands( true); // debug; + shortest_paths(mcf_v, mcf_v->nodes[i].id, commodities_left, + dest_flag); - - // () entertain user; - // printf("\nlambda = %lf, dual = %lf, [%lf, %lf], L=%lf, iter=%d", - // lambda, D/alpha, mcf_v->LL, mcf_v->UL, mcf_v->L, iter); + // () reset left_capacities of edges in the tree to the + // initial capacities; u'(e) = u(e), any e in tree; + reset_left_capacities_in_tree(mcf_v, mcf_v->nodes[i].id); - return lambda; + // () route "f = d(c_q)" units of flow of a given commodity + // and update the flow of each edge: f_e = f_e + f, along its + // shortest path; + bool flow_has_been_routed = false; + for (j = 0; j < mcf_v->nodes[i].no_comm; j++) { + + // the amount of commodity c_q that has not been routed yet + // at step "s"; + double left_demand = + mcf_v->_commodities[mcf_v->nodes[i].comms[j]].left_demand; + + if (left_demand > 1e-3) { + flow_has_been_routed = true; + // print_backward_shortest_path(_commodities[nodes[i].comms[j]].dest); + + // available flow amount from bottleneck-edge of shortest path; + // this "c" represents the available minimum capacity of the + // edges on shortest path of this commodity; + usable_amount_cap = min_capacity_this_commodity( + mcf_v, mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest); + + // available flow amount from latency constraint + if (flag == 0) { // 0: "max concurrent flow" + usable_amount_latency = 1000000.0; // inf; + } else { // 1: "min-cost max concurrent flow" + // this is L/c(P), where c(P) is is the cost of sending + // one unit of flow along the shortest path: + // Sum_{e in P}{D(e)}, where D(e) is latency of each edge; + usable_amount_latency = check_latency_constraint( + mcf_v, mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest); + } + + // flow amount to be routed at step "s": f_{i,j,s}^{c_q}; + routed_amount = minimum(usable_amount_cap, left_demand, + usable_amount_latency); + + // update every "_temp_edge_flow" - from dest backward to src + // will be added routed_amount; also update left_capacities + // of edges along the shortest path of this commodity; + route_flow(mcf_v, + mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest, + routed_amount, mcf_v->nodes[i].comms[j]); + + // update commodity amounts to be routed still (i.e., are left); + mcf_v->_commodities[mcf_v->nodes[i].comms[j]].left_demand -= + routed_amount; + + if (mcf_v->_commodities[mcf_v->nodes[i].comms[j]].left_demand <= + 1e-3) { + // this commodity is done, set its destination flag to 0; + commodities_left--; + dest_flag[mcf_v->_commodities[mcf_v->nodes[i].comms[j]].dest] = + 0; + } + } + } // for ( j = 0; j < nodes[i].no_comm; j++) + + // () update dual variables: Y_e, phi_latency (or PHI_d), + // length(e); + update_dual_variables(mcf_v, mcf_v->nodes[i].id, epsilon, flag); + + mcf_v->_rd++; + if (!flow_has_been_routed) + break; + } // while ( commodities_left) + + bench_free(dest_flag); + + } // if ( nodes[i].no_comm) + } // for ( i = 0; i < no_node; i++) + + // () increment phase counter; a phase is an iteration of the big main loop; + iter++; + // additional stopping criterion; + if (iter >= mcf_v->_scale) + break; + // if ( iter >= 80) break; + + // () compute dual and lambda and keep track of the gap between them; + // -- compute dual=D/alpha; + D = compute_D(mcf_v); + alpha = compute_alpha(mcf_v); + dual = D / alpha; + + // -- compute lambda; + // Note1: the original code of Hu computed lambda differently; + // this is not in fact lambda in the sense of Karakostas paper, + // but rather an "artificial" variable to make easier its tracking + // towards a value of 1; + // lambda = L / (_total_latency/iter); + // Note2: I now compute it as: lambda=MIN(actual flow/demand) among all + // commodities; lambda = L / (_total_latency/iter); + lambda = compute_lambda(mcf_v); + lambda /= iter; // consider effect of scaling; + // printf("\n Lambda=%.8f, Dual=D/alpha=%.8f, D=%.8f",lambda,dual,D); + + // -- keep track of gap; + // old_old_gap = old_gap; + // old_gap = gap; + // gap = dual/lambda - 1; + + // () this implements the "interval estimation"; see Theorem 3 of Hu paper; + if (flag == 1) { + double UL1 = mcf_v->UL, LL1 = mcf_v->LL; + double d = dual; + // if (d < 1) d = 1; + double s1 = (mcf_v->_latency_max - mcf_v->L) / (mcf_v->_lambda_max - d); + if (s1 > 0 && (mcf_v->_s < 0 || mcf_v->_s > s1)) { + mcf_v->_s = s1; + } + if (mcf_v->_s > 0) { + if (lambda < 1) { + UL1 = mcf_v->L + (1 - lambda) * mcf_v->_s; + if (UL1 < mcf_v->UL) + mcf_v->UL = UL1; + } + if (dual > 1) { + LL1 = mcf_v->L - (dual - 1) * mcf_v->_s; + if (LL1 > mcf_v->LL) + mcf_v->LL = LL1; + } + } + if (lambda > 1) { + mcf_v->UL = mcf_v->L; + } + if (dual < 1) { + mcf_v->LL = mcf_v->L; + } + if ((mcf_v->UL - mcf_v->LL < 0) || (mcf_v->UL / mcf_v->LL - 1) < 0.01) { + break; + } + if (D >= 1) { + break; + } + } else { // 0 + // for "max commodity flow" case, the stopping criterion is + // "D>=1"; see Karakostas paper; + // Note1: original code of Hu used "dual/lambda-1= 1) { + break; + } + } + + } // while (1) + + // () scale down the final flows so that the solution is feasible + // (that is, capacities are met); + scale_down_flows(mcf_v, iter); + // also, record final latency, which must consider scaling too; + mcf_v->_total_latency = mcf_v->_total_latency / iter; + + // () entertain user; + // printf("\nlambda = %lf, dual = %lf, [%lf, %lf], L=%lf, iter=%d", + // lambda, D/alpha, mcf_v->LL, mcf_v->UL, mcf_v->L, iter); + + return lambda; } //////////////////////////////////////////////////////////////////////////////// @@ -726,71 +734,75 @@ double mcf(MCF *mcf_v, double delta, double epsilon, int flag) // //////////////////////////////////////////////////////////////////////////////// -void shortest_paths(MCF *mcf_v, int s, int num_commodities, int *dest_flag) -{ - // implements Dijkstra's all paths shortest path algorithm; - // num_commodities is the number of commodities that still need - // routing for this source; +void shortest_paths(MCF *mcf_v, int s, int num_commodities, int *dest_flag) { + // implements Dijkstra's all paths shortest path algorithm; + // num_commodities is the number of commodities that still need + // routing for this source; - int num_commodities_to_process = num_commodities; - PQDATUM wf, wf1; // WAVEFRONTS; - PQDATUM_init(&wf); - PQDATUM_init(&wf1); + int num_commodities_to_process = num_commodities; + PQDATUM wf, wf1; // WAVEFRONTS; + PQDATUM_init(&wf); + PQDATUM_init(&wf1); - PQUEUE pq; - PQUEUE_init(&pq); - int *pos = (int *)bench_malloc(sizeof(int) * (mcf_v->no_node)); - if ( pos == NULL) { - bench_printf("\nError: Unable to bench_malloc .\n"); assert(0); - } - - pqinit(&pq, 400); // 400 is just a constant; - // reset dist of all nodes; - for ( int i = 0; i < mcf_v->no_node; i++) { - mcf_v->nodes[i].dist = DBL_MAX; - } - // source "s" resets; - mcf_v->nodes[s].pre = -1; - mcf_v->nodes[s].pre_edge = -1; - mcf_v->nodes[s].dist = 0.0; + PQUEUE pq; + PQUEUE_init(&pq); + int *pos = (int *)bench_malloc(sizeof(int) * (mcf_v->no_node)); + if (pos == NULL) { + bench_printf("\nError: Unable to bench_malloc .\n"); + assert(0); + } - set_node(&wf, s); // sourse "s"; - set_dist(&wf, 0.0); + pqinit(&pq, 400); // 400 is just a constant; + // reset dist of all nodes; + for (int i = 0; i < mcf_v->no_node; i++) { + mcf_v->nodes[i].dist = DBL_MAX; + } + // source "s" resets; + mcf_v->nodes[s].pre = -1; + mcf_v->nodes[s].pre_edge = -1; + mcf_v->nodes[s].dist = 0.0; - pqinsert(&pq, wf, pos); + set_node(&wf, s); // sourse "s"; + set_dist(&wf, 0.0); - while ( !pqempty(&pq)) { - int v, w; - - // retreive the shortest non-visited node; - pqremove(&pq, &wf1, pos); - v = node(&wf1); - if ( dest_flag[v]) num_commodities_to_process--; - // break when all shortest paths to all destinations from source "s" - // have been found; - if ( num_commodities_to_process <= 0) break; - - mcf_v->nodes[v].dij_visited = mcf_v->_rd; - for ( int i = 0; i < mcf_v->nodes[v].no_edge; i++) { - w = mcf_v->edges[mcf_v->nodes[v].edges[i]].dest; - if (mcf_v->nodes[w].dij_visited != mcf_v->_rd) - if (mcf_v->nodes[w].dij_updated != mcf_v->_rd || - mcf_v->nodes[w].dist > dist(&wf1) + mcf_v->edges[mcf_v->nodes[v].edges[i]].length) { - mcf_v->nodes[w].pre = v; - mcf_v->nodes[w].pre_edge = mcf_v->nodes[v].edges[i]; - mcf_v->nodes[w].dist = dist(&wf1) + mcf_v->edges[mcf_v->nodes[v].edges[i]].length; - set_node(&wf, w); - set_dist(&wf, mcf_v->nodes[w].dist); - if (mcf_v->nodes[w].dij_updated != mcf_v->_rd) { - pqinsert(&pq, wf, pos); - } else { - pqdeckey(&pq, wf, pos); - } - mcf_v->nodes[w].dij_updated = mcf_v->_rd; - } + pqinsert(&pq, wf, pos); + + while (!pqempty(&pq)) { + int v, w; + + // retreive the shortest non-visited node; + pqremove(&pq, &wf1, pos); + v = node(&wf1); + if (dest_flag[v]) + num_commodities_to_process--; + // break when all shortest paths to all destinations from source "s" + // have been found; + if (num_commodities_to_process <= 0) + break; + + mcf_v->nodes[v].dij_visited = mcf_v->_rd; + for (int i = 0; i < mcf_v->nodes[v].no_edge; i++) { + w = mcf_v->edges[mcf_v->nodes[v].edges[i]].dest; + if (mcf_v->nodes[w].dij_visited != mcf_v->_rd) + if (mcf_v->nodes[w].dij_updated != mcf_v->_rd || + mcf_v->nodes[w].dist > + dist(&wf1) + mcf_v->edges[mcf_v->nodes[v].edges[i]].length) { + mcf_v->nodes[w].pre = v; + mcf_v->nodes[w].pre_edge = mcf_v->nodes[v].edges[i]; + mcf_v->nodes[w].dist = + dist(&wf1) + mcf_v->edges[mcf_v->nodes[v].edges[i]].length; + set_node(&wf, w); + set_dist(&wf, mcf_v->nodes[w].dist); + if (mcf_v->nodes[w].dij_updated != mcf_v->_rd) { + pqinsert(&pq, wf, pos); + } else { + pqdeckey(&pq, wf, pos); + } + mcf_v->nodes[w].dij_updated = mcf_v->_rd; } } - pqfree(&pq, pos); // clean up; + } + pqfree(&pq, pos); // clean up; } //////////////////////////////////////////////////////////////////////////////// @@ -799,185 +811,195 @@ void shortest_paths(MCF *mcf_v, int s, int num_commodities, int *dest_flag) // //////////////////////////////////////////////////////////////////////////////// -bool build_network_from_host_application(MCF *mcf_v) -{ - // used from inside the host application that hosts also the floorplanner - // and the VNOC1 NoC simulator; - // you should implement this based on how your host application looks like; - // the idea is to populate the MCF object similarly to how I do it inside - // read_network_topology_and_demands(); +bool build_network_from_host_application(MCF *mcf_v) { + // used from inside the host application that hosts also the floorplanner + // and the VNOC1 NoC simulator; + // you should implement this based on how your host application looks like; + // the idea is to populate the MCF object similarly to how I do it inside + // read_network_topology_and_demands(); - return true; + return true; } -bool build_network_from_file(MCF *mcf_v, double latency_limit, double rate) -{ - // rate is the demand coefficient (injection rate): 0.05, 0.1, 0.15, 0.2, 0.25; - // latency_limit and rate are not used; +bool build_network_from_file(MCF *mcf_v, double latency_limit, double rate) { + // rate is the demand coefficient (injection rate): 0.05, 0.1, 0.15, 0.2, + // 0.25; latency_limit and rate are not used; - // (1) import the network topology and the demands; - read_network_topology_and_demands(mcf_v, 1); + // (1) import the network topology and the demands; + read_network_topology_and_demands(mcf_v, 1); - // (3) one time initialization of parameters (of those not set by - // user via command line arguments); - init_param(mcf_v); + // (3) one time initialization of parameters (of those not set by + // user via command line arguments); + init_param(mcf_v); - return true; + return true; } int demands_select = 0; -void read_network_topology_and_demands(MCF *mcf_v, double rate) -{ - int id, x, y, src, dest; - double delay, capacity; +void read_network_topology_and_demands(MCF *mcf_v, double rate) { + int id, x, y, src, dest; + double delay, capacity; - // (1) nodes - mcf_v->no_node = nodes_num; - mcf_v->nodes = (NODE*)bench_malloc(sizeof(NODE) * (mcf_v->no_node)); - if ( mcf_v->nodes == NULL) { - bench_printf("\nError: Unable to bench_malloc .\n"); assert(0); + // (1) nodes + mcf_v->no_node = nodes_num; + mcf_v->nodes = (NODE *)bench_malloc(sizeof(NODE) * (mcf_v->no_node)); + if (mcf_v->nodes == NULL) { + bench_printf("\nError: Unable to bench_malloc .\n"); + assert(0); + } + for (int i = 0; i < mcf_v->no_node; i++) { + id = node_buf[i].id; + x = node_buf[i].x; + y = node_buf[i].y; + + mcf_v->nodes[i].id = id; + mcf_v->nodes[i].x = x; + mcf_v->nodes[i].y = y; + mcf_v->nodes[i].pre = -1; + mcf_v->nodes[i].dist = DBL_MAX; + mcf_v->nodes[i].no_comm = 0; + mcf_v->nodes[i].comms = NULL; + mcf_v->nodes[i].no_edge = 0; + mcf_v->nodes[i].dij_visited = 0; + mcf_v->nodes[i].dij_updated = 0; + mcf_v->nodes[i].min_visited = 0; + + // here we work with a fixed pre-allocation; not optimal; we should + // allocate only as much as needed; also in this way we have to make + // sure there will be no nodes with a bigger degree than MAX_DEGREE=40; + // TO DO: this must be fixed as it's ugly programming; + // mcf_v->nodes[i].edges = (int *)bench_malloc(sizeof(int) * MAX_DEGREE); + mcf_v->nodes[i].edges = + (int *)bench_malloc(sizeof(int) * node_buf[i].edge_num); + assert(mcf_v->nodes[i].edges); + if (mcf_v->nodes[i].edges == NULL) { + bench_printf("\nError: Unable to bench_malloc .\n"); + assert(0); } - for ( int i = 0; i < mcf_v->no_node; i++) { - id = node_buf[i].id; - x = node_buf[i].x; - y = node_buf[i].y; + } - mcf_v->nodes[i].id = id; - mcf_v->nodes[i].x = x; - mcf_v->nodes[i].y = y; - mcf_v->nodes[i].pre = -1; - mcf_v->nodes[i].dist = DBL_MAX; - mcf_v->nodes[i].no_comm = 0; - mcf_v->nodes[i].comms = NULL; - mcf_v->nodes[i].no_edge = 0; - mcf_v->nodes[i].dij_visited = 0; - mcf_v->nodes[i].dij_updated = 0; - mcf_v->nodes[i].min_visited = 0; + // (2) edges + mcf_v->no_edge = edges_num; + mcf_v->edges = (EDGE *)bench_malloc(sizeof(EDGE) * (mcf_v->no_edge)); + if (mcf_v->edges == NULL) { + bench_printf("\nError: Unable to bench_malloc .\n"); + assert(0); + } + mcf_v->_temp_edge_flow = + (double *)bench_malloc(sizeof(double) * (mcf_v->no_edge)); + if (mcf_v->_temp_edge_flow == NULL) { + bench_printf("\nError: Unable to bench_malloc <_temp_edge_flow>.\n"); + assert(0); + } + for (int i = 0; i < mcf_v->no_edge; i++) { + id = edge_buf[i].id; + src = edge_buf[i].src; + dest = edge_buf[i].des; + capacity = edge_buf[i].capacity; + delay = edge_buf[i].delay; - // here we work with a fixed pre-allocation; not optimal; we should - // allocate only as much as needed; also in this way we have to make - // sure there will be no nodes with a bigger degree than MAX_DEGREE=40; - // TO DO: this must be fixed as it's ugly programming; - // mcf_v->nodes[i].edges = (int *)bench_malloc(sizeof(int) * MAX_DEGREE); - mcf_v->nodes[i].edges = (int *)bench_malloc(sizeof(int) * node_buf[i].edge_num); - assert(mcf_v->nodes[i].edges); - if ( mcf_v->nodes[i].edges == NULL) { - bench_printf("\nError: Unable to bench_malloc .\n"); assert(0); - } + mcf_v->edges[i].id = id; + mcf_v->edges[i].src = src; + mcf_v->edges[i].dest = dest; + mcf_v->edges[i].capacity = capacity; + mcf_v->edges[i].left_capacity = capacity; + mcf_v->edges[i].latency = delay; + mcf_v->edges[i].length = 0.0; + + mcf_v->edges[i].flow = 0.0; + mcf_v->edges[i]._flows = NULL; + } + + // (3) record adjacent edges for each node; + for (int i = 0; i < mcf_v->no_edge; i++) { + int index = mcf_v->edges[i].src; + mcf_v->nodes[index].edges[mcf_v->nodes[index].no_edge] = mcf_v->edges[i].id; + mcf_v->nodes[index].no_edge++; + } + + // (4) read demands/commodities; + double amount; + mcf_v->no_commodity = 1; // demands_num; + mcf_v->_commodities = + (COMMODITY *)bench_malloc(sizeof(COMMODITY) * (mcf_v->no_commodity)); + if (mcf_v->_commodities == NULL) { + bench_printf("\nError: Unable to bench_malloc <_commodities>.\n"); + assert(0); + } + for (int i = 0; i < mcf_v->no_commodity; i++) { + id = demands_buf[demands_select].id; + src = demands_buf[demands_select].src; + dest = demands_buf[demands_select].des; + amount = demands_buf[demands_select].amount; + + mcf_v->_commodities[i].id = id; + mcf_v->_commodities[i].src = src; + mcf_v->_commodities[i].dest = dest; + mcf_v->_commodities[i].demand = amount * rate; // rate = 1 by default; + mcf_v->_commodities[i].left_demand = amount; + + if (mcf_v->nodes[src].comms == NULL) { + mcf_v->nodes[src].comms = + (int *)bench_malloc(sizeof(int) * mcf_v->no_node); + if (mcf_v->nodes[src].comms == NULL) { + bench_printf("\nError: Unable to bench_malloc .\n"); + assert(0); + } } + mcf_v->nodes[src].comms[mcf_v->nodes[src].no_comm] = i; + mcf_v->nodes[src].no_comm++; + } - // (2) edges - mcf_v->no_edge = edges_num; - mcf_v->edges = (EDGE *)bench_malloc(sizeof(EDGE) * (mcf_v->no_edge)); - if ( mcf_v->edges == NULL) { - bench_printf("\nError: Unable to bench_malloc .\n"); assert(0); + // (5) reset; + for (int i = 0; i < mcf_v->no_edge; i++) { + // Note1: I had to delay this allocation because no_commodity had + // not been set yet; + mcf_v->edges[i]._flows = + (double *)bench_malloc(sizeof(double) * (mcf_v->no_commodity)); + if (mcf_v->edges[i]._flows == NULL) { + bench_printf("\nError: Unable to bench_malloc .\n"); + assert(0); } - mcf_v->_temp_edge_flow = (double*)bench_malloc(sizeof(double) * (mcf_v->no_edge)); - if ( mcf_v->_temp_edge_flow == NULL) { - bench_printf("\nError: Unable to bench_malloc <_temp_edge_flow>.\n"); assert(0); + for (int j = 0; j < mcf_v->no_commodity; j++) { + mcf_v->edges[i]._flows[j] = 0.0; } - for ( int i = 0; i < mcf_v->no_edge; i++) { - id = edge_buf[i].id; - src = edge_buf[i].src; - dest = edge_buf[i].des; - capacity = edge_buf[i].capacity; - delay = edge_buf[i].delay; + } + for (int i = 0; i < mcf_v->no_node; i++) { + // Note2: same as above; + // 注2:同上; + mcf_v->nodes[i]._preferred_path = + (int *)bench_malloc(sizeof(int) * mcf_v->no_commodity); + if (mcf_v->nodes[i]._preferred_path == NULL) { + bench_printf("\nError: Unable to bench_malloc <_preferred_path>.\n"); + assert(0); + } + for (int j = 0; j < mcf_v->no_commodity; j++) { + mcf_v->nodes[i]._preferred_path[j] = -1; + } + } - mcf_v->edges[i].id = id; - mcf_v->edges[i].src = src; - mcf_v->edges[i].dest = dest; - mcf_v->edges[i].capacity = capacity; - mcf_v->edges[i].left_capacity = capacity; - mcf_v->edges[i].latency = delay; - mcf_v->edges[i].length = 0.0; - - mcf_v->edges[i].flow = 0.0; - mcf_v->edges[i]._flows = NULL; - } - - // (3) record adjacent edges for each node; - for ( int i = 0; i < mcf_v->no_edge; i++) { - int index = mcf_v->edges[i].src; - mcf_v->nodes[index].edges[mcf_v->nodes[index].no_edge] = mcf_v->edges[i].id; - mcf_v->nodes[index].no_edge++; - } - - // (4) read demands/commodities; - double amount; - mcf_v->no_commodity = 1; // demands_num; - mcf_v->_commodities = (COMMODITY *)bench_malloc(sizeof(COMMODITY) * (mcf_v->no_commodity)); - if ( mcf_v->_commodities == NULL) { - bench_printf("\nError: Unable to bench_malloc <_commodities>.\n"); assert(0); - } - for ( int i = 0; i < mcf_v->no_commodity; i++) { - id = demands_buf[demands_select].id; - src = demands_buf[demands_select].src; - dest = demands_buf[demands_select].des; - amount = demands_buf[demands_select].amount; - - mcf_v->_commodities[i].id = id; - mcf_v->_commodities[i].src = src; - mcf_v->_commodities[i].dest = dest; - mcf_v->_commodities[i].demand = amount * rate; // rate = 1 by default; - mcf_v->_commodities[i].left_demand = amount; - - if (mcf_v->nodes[src].comms == NULL) { - mcf_v->nodes[src].comms = (int *)bench_malloc(sizeof(int) * mcf_v->no_node); - if ( mcf_v->nodes[src].comms == NULL) { - bench_printf("\nError: Unable to bench_malloc .\n"); assert(0); - } - } - mcf_v->nodes[src].comms[mcf_v->nodes[src].no_comm] = i; - mcf_v->nodes[src].no_comm++; - } - - // (5) reset; - for ( int i = 0; i < mcf_v->no_edge; i++) { - // Note1: I had to delay this allocation because no_commodity had - // not been set yet; - mcf_v->edges[i]._flows = (double *)bench_malloc(sizeof(double) * (mcf_v->no_commodity)); - if ( mcf_v->edges[i]._flows == NULL) { - bench_printf("\nError: Unable to bench_malloc .\n"); assert(0); - } - for ( int j = 0; j < mcf_v->no_commodity; j++) { - mcf_v->edges[i]._flows[j] = 0.0; - } - } - for ( int i = 0; i < mcf_v->no_node; i++) { - // Note2: same as above; - // 注2:同上; - mcf_v->nodes[i]._preferred_path = (int *)bench_malloc(sizeof(int) * mcf_v->no_commodity); - if ( mcf_v->nodes[i]._preferred_path == NULL) { - bench_printf("\nError: Unable to bench_malloc <_preferred_path>.\n"); assert(0); - } - for ( int j = 0; j < mcf_v->no_commodity; j++) { - mcf_v->nodes[i]._preferred_path[j] = -1; - } - } - - return; + return; } -void free_topology(MCF *mcf_v) -{ - int i=0; +void free_topology(MCF *mcf_v) { + int i = 0; - bench_free( mcf_v->_commodities); + bench_free(mcf_v->_commodities); - for ( i = 0; i < mcf_v->no_edge; i++) { - bench_free( mcf_v->edges[i]._flows); - } - bench_free( mcf_v->edges); - bench_free( mcf_v->_temp_edge_flow); + for (i = 0; i < mcf_v->no_edge; i++) { + bench_free(mcf_v->edges[i]._flows); + } + bench_free(mcf_v->edges); + bench_free(mcf_v->_temp_edge_flow); - for ( i = 0; i < mcf_v->no_node; i++) { - bench_free( mcf_v->nodes[i].comms); - bench_free( mcf_v->nodes[i].edges); - } - bench_free( mcf_v->nodes); + for (i = 0; i < mcf_v->no_node; i++) { + bench_free(mcf_v->nodes[i].comms); + bench_free(mcf_v->nodes[i].edges); + } + bench_free(mcf_v->nodes); - return; + return; } //////////////////////////////////////////////////////////////////////////////// @@ -986,78 +1008,80 @@ void free_topology(MCF *mcf_v) // //////////////////////////////////////////////////////////////////////////////// -void print_network_demands(MCF *mcf_v, bool print_only_edges) -{ - bench_printf("\n\nNetwork and demands:"); - bench_printf("\nNodes %d",mcf_v->no_node); - if ( print_only_edges == false) { - for ( int i = 0; i < mcf_v->no_node; i++) { - bench_printf("\n %d (%d %d)", mcf_v->nodes[i].id, mcf_v->nodes[i].x, mcf_v->nodes[i].y); - bench_printf(" num_commodities=%d dist=%lf",mcf_v->nodes[i].no_comm,mcf_v->nodes[i].dist); - bench_printf("\n "); - for ( int k = 0; k < mcf_v->nodes[i].no_edge; k++) { - bench_printf(" %d", mcf_v->nodes[i].edges[k]); - } - } +void print_network_demands(MCF *mcf_v, bool print_only_edges) { + bench_printf("\n\nNetwork and demands:"); + bench_printf("\nNodes %d", mcf_v->no_node); + if (print_only_edges == false) { + for (int i = 0; i < mcf_v->no_node; i++) { + bench_printf("\n %d (%d %d)", mcf_v->nodes[i].id, mcf_v->nodes[i].x, + mcf_v->nodes[i].y); + bench_printf(" num_commodities=%d dist=%lf", mcf_v->nodes[i].no_comm, + mcf_v->nodes[i].dist); + bench_printf("\n "); + for (int k = 0; k < mcf_v->nodes[i].no_edge; k++) { + bench_printf(" %d", mcf_v->nodes[i].edges[k]); + } } - bench_printf("\nEdges %d",mcf_v->no_edge); - if(mcf_v->no_node < 20){ - for ( int i = 0; i < mcf_v->no_edge; i++) { - //printf("\n %d %d -> %d cap: %.2lf Y_e: %.2lf len: %.2lf flow: %.2lf breakdown:", - // edges[i].id, edges[i].src, edges[i].dest, - // edges[i].capacity, edges[i]._Y_e, - // edges[i].length, edges[i].flow); - bench_printf("\n %2d %2d -> %-2d cap: %.2lf flow: %.2lf breakdown:", - mcf_v->edges[i].id, mcf_v->edges[i].src, mcf_v->edges[i].dest, - mcf_v->edges[i].capacity, mcf_v->edges[i].flow); - for ( int j = 0; j < mcf_v->no_commodity; j++) { - bench_printf(" %.2lf", mcf_v->edges[i]._flows[ j]); - } - } + } + bench_printf("\nEdges %d", mcf_v->no_edge); + if (mcf_v->no_node < 20) { + for (int i = 0; i < mcf_v->no_edge; i++) { + // printf("\n %d %d -> %d cap: %.2lf Y_e: %.2lf len: %.2lf flow: %.2lf + // breakdown:", + // edges[i].id, edges[i].src, edges[i].dest, + // edges[i].capacity, edges[i]._Y_e, + // edges[i].length, edges[i].flow); + bench_printf("\n %2d %2d -> %-2d cap: %.2lf flow: %.2lf breakdown:", + mcf_v->edges[i].id, mcf_v->edges[i].src, + mcf_v->edges[i].dest, mcf_v->edges[i].capacity, + mcf_v->edges[i].flow); + for (int j = 0; j < mcf_v->no_commodity; j++) { + bench_printf(" %.2lf", mcf_v->edges[i]._flows[j]); + } } - if ( print_only_edges == false) { - bench_printf("\nDemands/commodities %d",mcf_v->no_commodity); - for ( int i = 0; i < mcf_v->no_commodity; i++) { - bench_printf("\n %d %d -> %d demand=%lf portion_unsatisfied=%lf", mcf_v->_commodities[i].id, - mcf_v->_commodities[i].src, mcf_v->_commodities[i].dest, - mcf_v->_commodities[i].demand, // amount * rate + } + if (print_only_edges == false) { + bench_printf("\nDemands/commodities %d", mcf_v->no_commodity); + for (int i = 0; i < mcf_v->no_commodity; i++) { + bench_printf("\n %d %d -> %d demand=%lf portion_unsatisfied=%lf", + mcf_v->_commodities[i].id, mcf_v->_commodities[i].src, + mcf_v->_commodities[i].dest, + mcf_v->_commodities[i].demand, // amount * rate mcf_v->_commodities[i].left_demand); // amount - } } - bench_printf("\n"); + } + bench_printf("\n"); } -void print_routing_paths(MCF *mcf_v) -{ - // call only after a call of do_randomized_rounding(); - // printf("\nRandomized rounded paths:"); +void print_routing_paths(MCF *mcf_v) { + // call only after a call of do_randomized_rounding(); + // printf("\nRandomized rounded paths:"); - for ( int i = 0; i < mcf_v->no_commodity; i++) { - // printf("Commodity %d: %d -> %d: ", i, - // mcf_v->_commodities[i].src, mcf_v->_commodities[i].dest); - bench_printf("Commodity %d: %d -> %d: ", demands_select, - mcf_v->_commodities[i].src, mcf_v->_commodities[i].dest); - + for (int i = 0; i < mcf_v->no_commodity; i++) { + // printf("Commodity %d: %d -> %d: ", i, + // mcf_v->_commodities[i].src, mcf_v->_commodities[i].dest); + BENCH_LOG(DEBUG, "Commodity %d: %d -> %d: ", demands_select, + mcf_v->_commodities[i].src, mcf_v->_commodities[i].dest); - int src_id = mcf_v->_commodities[i].src; - while ( src_id != mcf_v->_commodities[i].dest) { - bench_printf(" %d", src_id); - src_id = mcf_v->nodes[src_id]._preferred_path[i]; - } - bench_printf(" %d", src_id); // dest; + int src_id = mcf_v->_commodities[i].src; + while (src_id != mcf_v->_commodities[i].dest) { + bench_printf(" %d", src_id); + src_id = mcf_v->nodes[src_id]._preferred_path[i]; } - bench_printf("\n"); + bench_printf(" %d", src_id); // dest; + } + bench_printf("\n"); } -void print_backward_shortest_path(MCF *mcf_v, int dest) -{ - // debug only; - int t = dest; - bench_printf("\n"); - while ( mcf_v->nodes[t].pre != -1) { - bench_printf(" %d ->", t); - t = mcf_v->nodes[t].pre; - } bench_printf(" %d ", t); +void print_backward_shortest_path(MCF *mcf_v, int dest) { + // debug only; + int t = dest; + bench_printf("\n"); + while (mcf_v->nodes[t].pre != -1) { + bench_printf(" %d ->", t); + t = mcf_v->nodes[t].pre; + } + bench_printf(" %d ", t); } //////////////////////////////////////////////////////////////////////////////// @@ -1066,49 +1090,50 @@ void print_backward_shortest_path(MCF *mcf_v, int dest) // //////////////////////////////////////////////////////////////////////////////// -bool do_randomized_rounding(MCF *mcf_v) -{ - // after mcf_solver finds a fractional flow solution, we do a - // randomized rounding to set only one path for each commodity; - // otherwise the commodities would traverse multiple paths that - // would translate in path splitting for packets which would require - // router architecture modification too much and re-ordering of packets - // at destination; +bool do_randomized_rounding(MCF *mcf_v) { + // after mcf_solver finds a fractional flow solution, we do a + // randomized rounding to set only one path for each commodity; + // otherwise the commodities would traverse multiple paths that + // would translate in path splitting for packets which would require + // router architecture modification too much and re-ordering of packets + // at destination; - for ( int i = 0; i < mcf_v->no_commodity; i++) { - // () for each commodity we start from its source and traverse - // downstream nodes; at each step we pick up the node that has - // the largest fraction of this commodity as the preferred path; - // record this preferred path in the preferred_path array; + for (int i = 0; i < mcf_v->no_commodity; i++) { + // () for each commodity we start from its source and traverse + // downstream nodes; at each step we pick up the node that has + // the largest fraction of this commodity as the preferred path; + // record this preferred path in the preferred_path array; - int src_id = mcf_v->_commodities[i].src; - while ( src_id != mcf_v->_commodities[i].dest) { - // recursively travel from src to dest searching for maximum - // fractional flow; - - int id_max_flow_fraction = -1; - double max_flow_fraction = 0.0; - for ( int k = 0; k < mcf_v->nodes[ src_id].no_edge; k++) { - // for each adjacent edge look at the commodity index "i", - // and seek the edge id with maximum flow fraction; + int src_id = mcf_v->_commodities[i].src; + while (src_id != mcf_v->_commodities[i].dest) { + // recursively travel from src to dest searching for maximum + // fractional flow; - int edge_id = mcf_v->nodes[ src_id].edges[k]; - if ( max_flow_fraction < mcf_v->edges[edge_id]._flows[ i]) { - max_flow_fraction = mcf_v->edges[edge_id]._flows[ i]; - id_max_flow_fraction = edge_id; - } - } - assert((id_max_flow_fraction >= 0) & (id_max_flow_fraction < mcf_v->no_edge)); + int id_max_flow_fraction = -1; + double max_flow_fraction = 0.0; + for (int k = 0; k < mcf_v->nodes[src_id].no_edge; k++) { + // for each adjacent edge look at the commodity index "i", + // and seek the edge id with maximum flow fraction; - // () record the neighbor node id as the downstream node of the - // preferred path for this commodity; that is, along the edge with - // max fraction of flow from current node for this commodity; - mcf_v->nodes[src_id]._preferred_path[i] = mcf_v->edges[id_max_flow_fraction].dest; - - // prepare for next iter; - src_id = mcf_v->nodes[src_id]._preferred_path[i]; + int edge_id = mcf_v->nodes[src_id].edges[k]; + if (max_flow_fraction < mcf_v->edges[edge_id]._flows[i]) { + max_flow_fraction = mcf_v->edges[edge_id]._flows[i]; + id_max_flow_fraction = edge_id; } - } + } + assert((id_max_flow_fraction >= 0) & + (id_max_flow_fraction < mcf_v->no_edge)); - return true; + // () record the neighbor node id as the downstream node of the + // preferred path for this commodity; that is, along the edge with + // max fraction of flow from current node for this commodity; + mcf_v->nodes[src_id]._preferred_path[i] = + mcf_v->edges[id_max_flow_fraction].dest; + + // prepare for next iter; + src_id = mcf_v->nodes[src_id]._preferred_path[i]; + } + } + + return true; } diff --git a/src/mcf/pqueue.c b/src/mcf/pqueue.c index b0b69e5..9d9a275 100644 --- a/src/mcf/pqueue.c +++ b/src/mcf/pqueue.c @@ -1,9 +1,9 @@ // #include // #include // #include +#include #include #include -#include //////////////////////////////////////////////////////////////////////////////// // @@ -11,125 +11,125 @@ // //////////////////////////////////////////////////////////////////////////////// -PQUEUE *pqinit(PQUEUE *pqueue, int n) -{ - // initialize the queue; - pqueue->_d = (PQDATUM *)bench_malloc(sizeof(PQDATUM) * n); - if ( pqueue->_d == NULL) { - bench_printf("\nError: Unable to malloc .\n"); - assert(0); - } - - pqueue->_avail = pqueue->_step = n; - pqueue->_size = 1; - return (pqueue); // return a pointer to itself; +PQUEUE *pqinit(PQUEUE *pqueue, int n) { + // initialize the queue; + pqueue->_d = (PQDATUM *)bench_malloc(sizeof(PQDATUM) * n); + if (pqueue->_d == NULL) { + bench_printf("\nError: Unable to malloc .\n"); + assert(0); + } + + pqueue->_avail = pqueue->_step = n; + pqueue->_size = 1; + return (pqueue); // return a pointer to itself; } -int pqinsert(PQUEUE *pqueue, PQDATUM a_d, int *pos) -{ - // insert an item into the queue; - // return 1 if item was inserted; 0 otherwise; +int pqinsert(PQUEUE *pqueue, PQDATUM a_d, int *pos) { + // insert an item into the queue; + // return 1 if item was inserted; 0 otherwise; - PQDATUM *tmp; - int i, newsize; + PQDATUM *tmp; + int i, newsize; - if ( pqueue->_size == -1) return 0; // pqueue was not initialized first; - - // (1) allocate more memory if necessary; - if ( pqueue->_size >= pqueue->_avail) { - newsize = pqueue->_size + pqueue->_step; - tmp = (PQDATUM *)bench_realloc( pqueue->_d, sizeof(PQDATUM) * newsize); - if ( tmp == NULL) { - bench_printf("\nError: Unable to my_realloc .\n"); - assert(0); - //return 0; - } - pqueue->_d = tmp; // redundant; - pqueue->_avail = newsize; + if (pqueue->_size == -1) + return 0; // pqueue was not initialized first; + + // (1) allocate more memory if necessary; + if (pqueue->_size >= pqueue->_avail) { + newsize = pqueue->_size + pqueue->_step; + tmp = (PQDATUM *)bench_realloc(pqueue->_d, sizeof(PQDATUM) * newsize); + if (tmp == NULL) { + bench_printf("\nError: Unable to my_realloc .\n"); + assert(0); + // return 0; } + pqueue->_d = tmp; // redundant; + pqueue->_avail = newsize; + } - // (2) insert item; - i = pqueue->_size++; - while ( i > 1 && get_distance( pqueue->_d[i / 2]) > get_distance( a_d)) { - pqueue->_d[i] = pqueue->_d[i / 2]; - pos[node(&pqueue->_d[i])] = i; - i /= 2; - } - pqueue->_d[i] = a_d; + // (2) insert item; + i = pqueue->_size++; + while (i > 1 && get_distance(pqueue->_d[i / 2]) > get_distance(a_d)) { + pqueue->_d[i] = pqueue->_d[i / 2]; pos[node(&pqueue->_d[i])] = i; - return 1; -} - -PQDATUM *pqremove(PQUEUE *pqueue, PQDATUM *a_d, int *pos) -{ - // remove the highest-ranking item from the queue; - // a_d: pointer to the PQDATUM variable that will hold the - // datum corresponding to the queue item removed; - // return value: - // >= 0 an item has been removed. The variable that d points - // to now contains the datum associated with the item in question; - // -1 no item could be removed. Either the queue pointer - // provided was NULL, or the queue was empty. The chunk - // of memory that d points to has not been modified. - - PQDATUM tmp; - PQDATUM_init(&tmp); - int i = 1, j; - - if ( pqueue->_size == -1 || pqueue->_size == 1) return NULL; - - *a_d = pqueue->_d[1]; - tmp = pqueue->_d[ --pqueue->_size]; - while (i <= pqueue->_size / 2) { - j = 2 * i; - if ( j < pqueue->_size && get_distance(pqueue->_d[j]) > get_distance(pqueue->_d[j + 1])) { - j++; - } - if ( get_distance(pqueue->_d[j]) >= get_distance(tmp)) { - break; - } - pqueue->_d[i] = pqueue->_d[j]; - pos[ node(&pqueue->_d[i])] = i; - i = j; - } - pqueue->_d[i] = tmp; - pos[ node(&pqueue->_d[i])] = i; - return a_d; -} - -int pqdeckey(PQUEUE *pqueue, PQDATUM a_d, int *pos) -{ - int i = 0; - - if ( pqueue->_size == -1) return 0; // pqueue was not initialized first; - - i = pos[ node(&a_d)]; - if ( node(&pqueue->_d[i]) != node(&a_d)) - bench_printf("wrong\n"); - while ( i > 1 && get_distance(pqueue->_d[i / 2]) > get_distance(a_d)) { - pqueue->_d[i] = pqueue->_d[i / 2]; - pos[ node(&pqueue->_d[i])] = i; - i /= 2; - } - pqueue->_d[i] = a_d; - pos[ node(&pqueue->_d[i])] = i; - return 1; + i /= 2; + } + pqueue->_d[i] = a_d; + pos[node(&pqueue->_d[i])] = i; + return 1; } -PQDATUM *pqpeek(PQUEUE *pqueue, PQDATUM *a_d) -{ - // access highest-ranking item without removing it; - // a_d: pointer to the PQDATUM variable that will hold the - // datum corresponding to the highest-ranking item; - // return value: - // >= 0 Success. The variable that d points to now contains - // the datum associated with the highest-ranking item. - // -1 Failure. Either the queue pointer provided was NULL, - // or the queue was empty. The chunk of memory that d - // points to has not been modified. +PQDATUM *pqremove(PQUEUE *pqueue, PQDATUM *a_d, int *pos) { + // remove the highest-ranking item from the queue; + // a_d: pointer to the PQDATUM variable that will hold the + // datum corresponding to the queue item removed; + // return value: + // >= 0 an item has been removed. The variable that d points + // to now contains the datum associated with the item in question; + // -1 no item could be removed. Either the queue pointer + // provided was NULL, or the queue was empty. The chunk + // of memory that d points to has not been modified. - if ( pqueue->_size == -1 || pqueue->_size == 1) return NULL; + PQDATUM tmp; + PQDATUM_init(&tmp); + int i = 1, j; - *a_d = pqueue->_d[1]; - return a_d; + if (pqueue->_size == -1 || pqueue->_size == 1) + return NULL; + + *a_d = pqueue->_d[1]; + tmp = pqueue->_d[--pqueue->_size]; + while (i <= pqueue->_size / 2) { + j = 2 * i; + if (j < pqueue->_size && + get_distance(pqueue->_d[j]) > get_distance(pqueue->_d[j + 1])) { + j++; + } + if (get_distance(pqueue->_d[j]) >= get_distance(tmp)) { + break; + } + pqueue->_d[i] = pqueue->_d[j]; + pos[node(&pqueue->_d[i])] = i; + i = j; + } + pqueue->_d[i] = tmp; + pos[node(&pqueue->_d[i])] = i; + return a_d; +} + +int pqdeckey(PQUEUE *pqueue, PQDATUM a_d, int *pos) { + int i = 0; + + if (pqueue->_size == -1) + return 0; // pqueue was not initialized first; + + i = pos[node(&a_d)]; + if (node(&pqueue->_d[i]) != node(&a_d)) + bench_printf("wrong\n"); + while (i > 1 && get_distance(pqueue->_d[i / 2]) > get_distance(a_d)) { + pqueue->_d[i] = pqueue->_d[i / 2]; + pos[node(&pqueue->_d[i])] = i; + i /= 2; + } + pqueue->_d[i] = a_d; + pos[node(&pqueue->_d[i])] = i; + return 1; +} + +PQDATUM *pqpeek(PQUEUE *pqueue, PQDATUM *a_d) { + // access highest-ranking item without removing it; + // a_d: pointer to the PQDATUM variable that will hold the + // datum corresponding to the highest-ranking item; + // return value: + // >= 0 Success. The variable that d points to now contains + // the datum associated with the highest-ranking item. + // -1 Failure. Either the queue pointer provided was NULL, + // or the queue was empty. The chunk of memory that d + // points to has not been modified. + + if (pqueue->_size == -1 || pqueue->_size == 1) + return NULL; + + *a_d = pqueue->_d[1]; + return a_d; } diff --git a/src/mcf/test-gen/input-ref.c b/src/mcf/test-gen/input-ref.c index b7d9d23..4d2e5c2 100644 --- a/src/mcf/test-gen/input-ref.c +++ b/src/mcf/test-gen/input-ref.c @@ -1,93 +1,36 @@ #include "input.h" -const int nodes_num = 14; -const int edges_num = 25; -const int demands_num = 40; +const int nodes_num = 14; +const int edges_num = 25; +const int demands_num = 40; -node_t node_buf[]={ - { 0, 0, 0, 6}, - { 1, 0, 0, 1}, - { 2, 0, 0, 1}, - { 3, 0, 0, 1}, - { 4, 0, 0, 6}, - { 5, 0, 0, 1}, - { 6, 0, 0, 1}, - { 7, 0, 0, 1}, - { 8, 0, 0, 2}, - { 9, 0, 0, 1}, - { 10, 0, 0, 1}, - { 11, 0, 0, 2}, - { 12, 0, 0, 1}, - { 13, 0, 0, 1}, +node_t node_buf[] = { + {0, 0, 0, 6}, {1, 0, 0, 1}, {2, 0, 0, 1}, {3, 0, 0, 1}, {4, 0, 0, 6}, + {5, 0, 0, 1}, {6, 0, 0, 1}, {7, 0, 0, 1}, {8, 0, 0, 2}, {9, 0, 0, 1}, + {10, 0, 0, 1}, {11, 0, 0, 2}, {12, 0, 0, 1}, {13, 0, 0, 1}, }; -edge_t edge_buf[]={ - { 0, 0, 1, 101, 122}, - { 1, 1, 2, 179, 377}, - { 2, 2, 3, 124, 202}, - { 3, 3, 4, 125, 261}, - { 4, 4, 5, 182, 423}, - { 5, 5, 6, 184, 405}, - { 6, 6, 7, 140, 259}, - { 7, 7, 8, 118, 398}, - { 8, 8, 9, 128, 228}, - { 9, 9, 10, 186, 238}, - { 10, 10, 11, 172, 236}, - { 11, 11, 12, 187, 350}, - { 12, 12, 13, 163, 217}, - { 13, 0, 4, 180, 181}, - { 14, 0, 6, 5, 249}, - { 15, 0, 7, 108, 427}, - { 16, 0, 12, 155, 139}, - { 17, 0, 8, 3, 322}, - { 18, 4, 7, 106, 182}, - { 19, 4, 9, 81, 345}, - { 20, 4, 5, 212, 289}, - { 21, 4, 6, 166, 419}, - { 22, 4, 10, 198, 30}, - { 23, 8, 12, 221, 308}, - { 24, 11, 12, 179, 235}, +edge_t edge_buf[] = { + {0, 0, 1, 101, 122}, {1, 1, 2, 179, 377}, {2, 2, 3, 124, 202}, + {3, 3, 4, 125, 261}, {4, 4, 5, 182, 423}, {5, 5, 6, 184, 405}, + {6, 6, 7, 140, 259}, {7, 7, 8, 118, 398}, {8, 8, 9, 128, 228}, + {9, 9, 10, 186, 238}, {10, 10, 11, 172, 236}, {11, 11, 12, 187, 350}, + {12, 12, 13, 163, 217}, {13, 0, 4, 180, 181}, {14, 0, 6, 5, 249}, + {15, 0, 7, 108, 427}, {16, 0, 12, 155, 139}, {17, 0, 8, 3, 322}, + {18, 4, 7, 106, 182}, {19, 4, 9, 81, 345}, {20, 4, 5, 212, 289}, + {21, 4, 6, 166, 419}, {22, 4, 10, 198, 30}, {23, 8, 12, 221, 308}, + {24, 11, 12, 179, 235}, }; -demands_t demands_buf[]={ - { 0, 0, 13, 10}, - { 1, 0, 1, 96}, - { 2, 1, 6, 78}, - { 3, 1, 9, 95}, - { 4, 3, 5, 35}, - { 5, 3, 10, 77}, - { 6, 3, 13, 38}, - { 7, 3, 9, 98}, - { 8, 3, 11, 92}, - { 9, 3, 6, 29}, - { 10, 3, 4, 38}, - { 11, 4, 10, 73}, - { 12, 4, 5, 6}, - { 13, 4, 12, 28}, - { 14, 4, 13, 4}, - { 15, 4, 8, 56}, - { 16, 4, 9, 22}, - { 17, 4, 7, 48}, - { 18, 4, 6, 29}, - { 19, 5, 9, 35}, - { 20, 5, 13, 39}, - { 21, 5, 12, 77}, - { 22, 5, 8, 42}, - { 23, 5, 10, 63}, - { 24, 6, 12, 7}, - { 25, 6, 10, 25}, - { 26, 6, 11, 18}, - { 27, 6, 8, 29}, - { 28, 6, 13, 36}, - { 29, 6, 9, 45}, - { 30, 7, 11, 36}, - { 31, 7, 13, 95}, - { 32, 7, 12, 68}, - { 33, 7, 8, 33}, - { 34, 7, 10, 11}, - { 35, 8, 13, 82}, - { 36, 8, 10, 7}, - { 37, 9, 10, 25}, - { 38, 9, 11, 84}, - { 39, 10, 13, 78}, +demands_t demands_buf[] = { + {0, 0, 13, 10}, {1, 0, 1, 96}, {2, 1, 6, 78}, {3, 1, 9, 95}, + {4, 3, 5, 35}, {5, 3, 10, 77}, {6, 3, 13, 38}, {7, 3, 9, 98}, + {8, 3, 11, 92}, {9, 3, 6, 29}, {10, 3, 4, 38}, {11, 4, 10, 73}, + {12, 4, 5, 6}, {13, 4, 12, 28}, {14, 4, 13, 4}, {15, 4, 8, 56}, + {16, 4, 9, 22}, {17, 4, 7, 48}, {18, 4, 6, 29}, {19, 5, 9, 35}, + {20, 5, 13, 39}, {21, 5, 12, 77}, {22, 5, 8, 42}, {23, 5, 10, 63}, + {24, 6, 12, 7}, {25, 6, 10, 25}, {26, 6, 11, 18}, {27, 6, 8, 29}, + {28, 6, 13, 36}, {29, 6, 9, 45}, {30, 7, 11, 36}, {31, 7, 13, 95}, + {32, 7, 12, 68}, {33, 7, 8, 33}, {34, 7, 10, 11}, {35, 8, 13, 82}, + {36, 8, 10, 7}, {37, 9, 10, 25}, {38, 9, 11, 84}, {39, 10, 13, 78}, }; diff --git a/src/mcf/test-gen/input-test.c b/src/mcf/test-gen/input-test.c index c0bbbe7..435a578 100644 --- a/src/mcf/test-gen/input-test.c +++ b/src/mcf/test-gen/input-test.c @@ -1,25 +1,25 @@ #include "input.h" -const int nodes_num = 4; -const int edges_num = 3; -const int demands_num = 4; +const int nodes_num = 4; +const int edges_num = 3; +const int demands_num = 4; -node_t node_buf[]={ - { 0, 0, 0, 1}, - { 1, 0, 0, 1}, - { 2, 0, 0, 1}, - { 3, 0, 0, 1}, +node_t node_buf[] = { + {0, 0, 0, 1}, + {1, 0, 0, 1}, + {2, 0, 0, 1}, + {3, 0, 0, 1}, }; -edge_t edge_buf[]={ - { 0, 0, 1, 121, 468}, - { 1, 1, 2, 185, 328}, - { 2, 2, 3, 141, 271}, +edge_t edge_buf[] = { + {0, 0, 1, 121, 468}, + {1, 1, 2, 185, 328}, + {2, 2, 3, 141, 271}, }; -demands_t demands_buf[]={ - { 0, 0, 3, 10}, - { 1, 0, 3, 60}, - { 2, 0, 1, 92}, - { 3, 1, 2, 18}, +demands_t demands_buf[] = { + {0, 0, 3, 10}, + {1, 0, 3, 60}, + {2, 0, 1, 92}, + {3, 1, 2, 18}, }; diff --git a/src/mcf/test-gen/input-train.c b/src/mcf/test-gen/input-train.c index 03c9d49..87d1d76 100644 --- a/src/mcf/test-gen/input-train.c +++ b/src/mcf/test-gen/input-train.c @@ -1,31 +1,20 @@ #include "input.h" -const int nodes_num = 6; -const int edges_num = 5; -const int demands_num = 6; +const int nodes_num = 6; +const int edges_num = 5; +const int demands_num = 6; -node_t node_buf[]={ - { 0, 0, 0, 1}, - { 1, 0, 0, 1}, - { 2, 0, 0, 1}, - { 3, 0, 0, 1}, - { 4, 0, 0, 1}, - { 5, 0, 0, 1}, +node_t node_buf[] = { + {0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}, + {3, 0, 0, 1}, {4, 0, 0, 1}, {5, 0, 0, 1}, }; -edge_t edge_buf[]={ - { 0, 0, 1, 164, 484}, - { 1, 1, 2, 193, 186}, - { 2, 2, 3, 167, 274}, - { 3, 3, 4, 180, 133}, - { 4, 4, 5, 129, 348}, +edge_t edge_buf[] = { + {0, 0, 1, 164, 484}, {1, 1, 2, 193, 186}, {2, 2, 3, 167, 274}, + {3, 3, 4, 180, 133}, {4, 4, 5, 129, 348}, }; -demands_t demands_buf[]={ - { 0, 0, 5, 10}, - { 1, 0, 2, 52}, - { 2, 0, 4, 13}, - { 3, 1, 5, 20}, - { 4, 1, 2, 72}, - { 5, 1, 3, 44}, +demands_t demands_buf[] = { + {0, 0, 5, 10}, {1, 0, 2, 52}, {2, 0, 4, 13}, + {3, 1, 5, 20}, {4, 1, 2, 72}, {5, 1, 3, 44}, }; diff --git a/src/mcf/test-gen/main.c b/src/mcf/test-gen/main.c index 721f031..714a9bd 100644 --- a/src/mcf/test-gen/main.c +++ b/src/mcf/test-gen/main.c @@ -1,112 +1,122 @@ #include #include #include - -int main(int argc, char *argv[]) -{ - struct timeval tv_start; - int node_num = 10; - int edge_num = 0; - int demands_num = 1; +int main(int argc, char *argv[]) { + struct timeval tv_start; + int node_num = 10; + int edge_num = 0; + int demands_num = 1; - gettimeofday( &tv_start, NULL); - srand(tv_start.tv_usec); + gettimeofday(&tv_start, NULL); + srand(tv_start.tv_usec); - FILE *fp = fopen("test.c", "w"); - fprintf(fp, "#include \"input.h\"\n\n"); // 记录此时的偏移,最后需要打印三个变量 - int num_write = ftell(fp); - int edge_num_write = 0; + FILE *fp = fopen("test.c", "w"); + fprintf(fp, + "#include \"input.h\"\n\n"); // 记录此时的偏移,最后需要打印三个变量 + int num_write = ftell(fp); + int edge_num_write = 0; - if(argv[1]) + if (argv[1]) { + node_num = atoi(argv[1]); + } + + int edge_num_offset_buf[node_num]; // 记录每个节点的edge打印位置 + // ******************************************* 先来占位,最后再写入 + // ******************************************* // + fprintf(fp, "const int nodes_num = %5d;\n", 0); + fprintf(fp, "const int edges_num = %5d;\n", 0); + fprintf(fp, "const int demands_num = %5d;\n\n", 0); + // ******************************************* 生成结点 + // ******************************************* // + fprintf(fp, "node_t node_buf[]={\n"); + for (int i = 0; i < node_num; i++) { + fprintf(fp, "\t{%5d, %5d, %5d,", i, 0, 0); + edge_num_offset_buf[i] = ftell(fp); + fprintf(fp, " %5d},\n", 1); + } + fprintf(fp, "};\n\n"); + // ******************************************* 生成边 + // ******************************************* // + edge_num = 0; + fprintf(fp, "edge_t edge_buf[]={\n"); + for (int i = 0; i < node_num - 1; + i++) // 初始化初始通路 ,初始通路必定能满足条件 + { + int capacity = rand() % 99 + 100; // 容量 + int delay = rand() % 451 + 50; // 花费 + fprintf(fp, "\t{%5d, %5d, %5d, %5d, %5d},\n", edge_num, i, i + 1, capacity, + delay); + edge_num++; + } + + for (int start_node = 0; start_node < node_num - 1; start_node++) // 生成分支 + { + int len2end = (node_num - 1) - start_node; // 到终点的距离 + int base = len2end > 7 ? 7 : len2end; + int branch_num = + (rand() % 4 == 1) ? rand() % base : 0; // 产生多少条分支,75%概率不生成 + int node_write[len2end]; // 计分表,保证通路不重复 + + fseek(fp, edge_num_offset_buf[start_node], SEEK_SET); + fprintf(fp, " %5d", branch_num + 1); // 一条原路与branch_num条支路 + fseek(fp, 0, SEEK_END); + + for (int i = 0; i < len2end; i++) + node_write[i] = 0; + + for (int i = 0; i < branch_num; i++) // 分支,不保证能用 { - node_num = atoi(argv[1]); + int capacity = rand() % 255 + 1; // 容量 + int delay = rand() % 500 + 1; // 花费 + int end_node; + do { + end_node = rand() % (len2end - 1) + start_node + 1; + } while (node_write[end_node - start_node - 1] == 1); // 只能向后生成 + node_write[end_node - start_node - 1] = 1; // 不能重复 + fprintf(fp, "\t{%5d, %5d, %5d, %5d, %5d},\n", edge_num, start_node, + end_node, capacity, delay); + edge_num++; // 输出完成后再加 } + } + fprintf(fp, "};\n\n"); + // ******************************************* 生成目标 + // ******************************************* // - int edge_num_offset_buf[node_num]; // 记录每个节点的edge打印位置 -// ******************************************* 先来占位,最后再写入 ******************************************* // - fprintf(fp, "const int nodes_num = %5d;\n", 0); - fprintf(fp, "const int edges_num = %5d;\n", 0); - fprintf(fp, "const int demands_num = %5d;\n\n", 0); -// ******************************************* 生成结点 ******************************************* // - fprintf(fp, "node_t node_buf[]={\n"); - for(int i = 0; i < node_num; i++) + fprintf(fp, "demands_t demands_buf[]={\n"); + fprintf(fp, "\t{%5d, %5d, %5d, %5d},\n", 0, 0, node_num - 1, + 10); // 打印第一个目标,该目标为固定值 + + for (int start_node = 0; start_node < node_num - 1; start_node++) // 生成分支 + { + int len2end = (node_num - 1) - start_node; // 到终点的距离 + int base = len2end > 15 ? 15 : len2end; + int branch_num = rand() % base; // 该起点产生多少条需求 + int node_write[len2end]; // 计分表,保证通路不重复 + for (int i = 0; i < len2end; i++) + node_write[i] = 0; + + for (int i = 0; i < branch_num; i++) // 开始生成 { - fprintf(fp, "\t{%5d, %5d, %5d,", i, 0, 0); - edge_num_offset_buf[i] = ftell(fp); - fprintf(fp, " %5d},\n", 1); - } - fprintf(fp, "};\n\n"); -// ******************************************* 生成边 ******************************************* // - edge_num = 0; - fprintf(fp, "edge_t edge_buf[]={\n"); - for(int i = 0; i < node_num - 1; i++) // 初始化初始通路 ,初始通路必定能满足条件 - { - int capacity = rand()%99 + 100; // 容量 - int delay = rand()%451 + 50; // 花费 - fprintf(fp, "\t{%5d, %5d, %5d, %5d, %5d},\n", edge_num, i, i + 1, capacity, delay); - edge_num++; - } - - for(int start_node = 0; start_node < node_num - 1; start_node++) // 生成分支 - { - int len2end = (node_num - 1) - start_node; // 到终点的距离 - int base = len2end > 7 ? 7 : len2end; - int branch_num = (rand()%4 == 1) ? rand()%base : 0; // 产生多少条分支,75%概率不生成 - int node_write[len2end]; // 计分表,保证通路不重复 + int demands = rand() % 100 + 1; // 需求容量 + int end_node; + do { + end_node = rand() % len2end + start_node + 1; + } while (node_write[end_node - start_node - 1] == 1); // 只能向后生成 + node_write[end_node - start_node - 1] = 1; // 不能重复 + fprintf(fp, "\t{%5d, %5d, %5d, %5d},\n", demands_num, start_node, + end_node, demands); + demands_num++; // 输出完成后再加 + } + } + fprintf(fp, "};\n"); - fseek(fp, edge_num_offset_buf[start_node], SEEK_SET); - fprintf(fp, " %5d", branch_num + 1); // 一条原路与branch_num条支路 - fseek(fp, 0, SEEK_END); + // ******************************************* + // ******************************************* // + fseek(fp, num_write, SEEK_SET); + fprintf(fp, "const int nodes_num = %5d;\n", node_num); + fprintf(fp, "const int edges_num = %5d;\n", edge_num); + fprintf(fp, "const int demands_num = %5d;\n\n", demands_num); - for(int i = 0; i < len2end; i++) node_write[i] = 0; - - for(int i = 0; i < branch_num; i++) // 分支,不保证能用 - { - int capacity = rand()%255 + 1; // 容量 - int delay = rand()%500 + 1; // 花费 - int end_node; - do{ - end_node = rand()%(len2end - 1) + start_node + 1; - }while(node_write[end_node - start_node - 1] == 1);// 只能向后生成 - node_write[end_node - start_node - 1] = 1; // 不能重复 - fprintf(fp, "\t{%5d, %5d, %5d, %5d, %5d},\n", edge_num, start_node, end_node, capacity, delay); - edge_num++; // 输出完成后再加 - } - } - fprintf(fp, "};\n\n"); -// ******************************************* 生成目标 ******************************************* // - - fprintf(fp, "demands_t demands_buf[]={\n"); - fprintf(fp, "\t{%5d, %5d, %5d, %5d},\n", 0, 0, node_num - 1, 10); // 打印第一个目标,该目标为固定值 - - for(int start_node = 0; start_node < node_num - 1; start_node++) // 生成分支 - { - int len2end = (node_num - 1) - start_node; // 到终点的距离 - int base = len2end > 15 ? 15 : len2end; - int branch_num = rand()%base; // 该起点产生多少条需求 - int node_write[len2end]; // 计分表,保证通路不重复 - for(int i = 0; i < len2end; i++) node_write[i] = 0; - - for(int i = 0; i < branch_num; i++) // 开始生成 - { - int demands = rand()%100 + 1; // 需求容量 - int end_node; - do{ - end_node = rand()%len2end + start_node + 1; - }while(node_write[end_node - start_node - 1] == 1);// 只能向后生成 - node_write[end_node - start_node - 1] = 1; // 不能重复 - fprintf(fp, "\t{%5d, %5d, %5d, %5d},\n", demands_num, start_node, end_node, demands); - demands_num++; // 输出完成后再加 - } - } - fprintf(fp, "};\n"); - -// ******************************************* ******************************************* // - fseek(fp, num_write, SEEK_SET); - fprintf(fp, "const int nodes_num = %5d;\n", node_num); - fprintf(fp, "const int edges_num = %5d;\n", edge_num); - fprintf(fp, "const int demands_num = %5d;\n\n", demands_num); - - fclose(fp); + fclose(fp); } diff --git a/src/mcf/test.c b/src/mcf/test.c index c0bbbe7..435a578 100644 --- a/src/mcf/test.c +++ b/src/mcf/test.c @@ -1,25 +1,25 @@ #include "input.h" -const int nodes_num = 4; -const int edges_num = 3; -const int demands_num = 4; +const int nodes_num = 4; +const int edges_num = 3; +const int demands_num = 4; -node_t node_buf[]={ - { 0, 0, 0, 1}, - { 1, 0, 0, 1}, - { 2, 0, 0, 1}, - { 3, 0, 0, 1}, +node_t node_buf[] = { + {0, 0, 0, 1}, + {1, 0, 0, 1}, + {2, 0, 0, 1}, + {3, 0, 0, 1}, }; -edge_t edge_buf[]={ - { 0, 0, 1, 121, 468}, - { 1, 1, 2, 185, 328}, - { 2, 2, 3, 141, 271}, +edge_t edge_buf[] = { + {0, 0, 1, 121, 468}, + {1, 1, 2, 185, 328}, + {2, 2, 3, 141, 271}, }; -demands_t demands_buf[]={ - { 0, 0, 3, 10}, - { 1, 0, 3, 60}, - { 2, 0, 1, 92}, - { 3, 1, 2, 18}, +demands_t demands_buf[] = { + {0, 0, 3, 10}, + {1, 0, 3, 60}, + {2, 0, 1, 92}, + {3, 1, 2, 18}, }; diff --git a/src/stream/Makefile b/src/stream/Makefile index df223a0..c990fbf 100644 --- a/src/stream/Makefile +++ b/src/stream/Makefile @@ -1,7 +1,9 @@ NAME = stream +mainargs ?= ref + BENCH_LIBS = bench openlibm soft-fp -SRCS = stream.c +SRCS = stream.c ./configs/$(mainargs)-config.c INC_PATH += ../common/openlibm/include \ ../common/openlibm/src \ diff --git a/src/stream/configs/ref-config.c b/src/stream/configs/ref-config.c new file mode 100644 index 0000000..b2679d0 --- /dev/null +++ b/src/stream/configs/ref-config.c @@ -0,0 +1,3 @@ +#include + +bench_stream_config config = {200000}; diff --git a/src/stream/configs/test-config.c b/src/stream/configs/test-config.c new file mode 100644 index 0000000..e3f82ec --- /dev/null +++ b/src/stream/configs/test-config.c @@ -0,0 +1,3 @@ +#include + +bench_stream_config config = {100000}; diff --git a/src/stream/configs/train-config.c b/src/stream/configs/train-config.c new file mode 100644 index 0000000..fdfa7a5 --- /dev/null +++ b/src/stream/configs/train-config.c @@ -0,0 +1,3 @@ +#include + +bench_stream_config config = {10000}; diff --git a/src/stream/include/stream.h b/src/stream/include/stream.h new file mode 100644 index 0000000..e5e9326 --- /dev/null +++ b/src/stream/include/stream.h @@ -0,0 +1,4 @@ + +typedef struct { + unsigned int stream_array_size; +} bench_stream_config; diff --git a/src/stream/stream.c b/src/stream/stream.c index f9db9ea..eb8d3c4 100644 --- a/src/stream/stream.c +++ b/src/stream/stream.c @@ -42,9 +42,12 @@ /*----------------------------------------------------------------------------*/ #include #include -#include -#include +#include +#include #include +#include +#include +#include /*----------------------------------------------------------------------- * INSTRUCTIONS: * @@ -60,22 +63,23 @@ * Example 1: One Xeon E3 with 8 MB L3 cache * STREAM_ARRAY_SIZE should be >= 4 million, giving * an array size of 30.5 MB and a total memory requirement - * of 91.5 MB. + * of 91.5 MB. * Example 2: Two Xeon E5's with 20 MB L3 cache each (using OpenMP) * STREAM_ARRAY_SIZE should be >= 20 million, giving * an array size of 153 MB and a total memory requirement - * of 458 MB. + * of 458 MB. * (b) The size should be large enough so that the 'timing calibration' - * output by the program is at least 20 clock-ticks. + * output by the program is at least 20 clock-ticks. * Example: most versions of Windows have a 10 millisecond timer * granularity. 20 "ticks" at 10 ms/tic is 200 milliseconds. * If the chip is capable of 10 GB/s, it moves 2 GB in 200 msec. - * This means the each array must be at least 1 GB, or 128M elements. + * This means the each array must be at least 1 GB, or 128M + *elements. * * Version 5.10 increases the default array size from 2 million * elements to 10 million elements in response to the increasing * size of L3 caches. The new default size is large enough for caches - * up to 20 MB. + * up to 20 MB. * Version 5.10 changes the loop index variables from "register int" * to "size_t", which allows array indices >2^32 (4 billion) * on properly configured 64-bit systems. Additional compiler options @@ -85,12 +89,12 @@ * code for the (many) compilers that support preprocessor definitions * on the compile line. E.g., * gcc -O -DSTREAM_ARRAY_SIZE=100000000 stream.c -o stream.100M - * will override the default size of 10M with a new size of 100M elements - * per array. + * will override the default size of 10M with a new size of 100M + *elements per array. */ -#if (STREAM_ARRAY_SIZE+0) > 0 -#else -# define STREAM_ARRAY_SIZE 200000 +#if (STREAM_ARRAY_SIZE + 0) > 0 +#else +#define STREAM_ARRAY_SIZE 200000 #endif /* 2) STREAM runs each kernel "NTIMES" times and reports the *best* result * for any iteration after the first, therefore the minimum value @@ -102,29 +106,29 @@ * code using, for example, "-DNTIMES=7". */ #ifdef NTIMES -#if NTIMES<=1 -# define NTIMES 10 +#if NTIMES <= 1 +#define NTIMES 10 #endif #endif #ifndef NTIMES -# define NTIMES 2 +#define NTIMES 2 #endif /* Users are allowed to modify the "OFFSET" variable, which *may* change the - * relative alignment of the arrays (though compilers may change the - * effective offset by making the arrays non-contiguous on some systems). - * Use of non-zero values for OFFSET can be especially helpful if the + * relative alignment of the arrays (though compilers may change the + * effective offset by making the arrays non-contiguous on some + * systems). Use of non-zero values for OFFSET can be especially helpful if the * STREAM_ARRAY_SIZE is set to a value close to a large power of 2. * OFFSET can also be set on the compile line without changing the source * code using, for example, "-DOFFSET=56". */ #ifndef OFFSET -# define OFFSET 0 +#define OFFSET 0 #endif /* * 3) Compile the code with optimization. Many compilers generate - * unreasonably bad code before the optimizer tightens things up. + * unreasonably bad code before the optimizer tightens things up. * If the results are unreasonably good, on the other hand, the * optimizer might be too smart for me! * @@ -133,309 +137,292 @@ * This is known to work on many, many systems.... * * To use multiple cores, you need to tell the compiler to obey the OpenMP - * directives in the code. This varies by compiler, but a common example is - * gcc -O -fopenmp stream.c -o stream_omp - * The environment variable OMP_NUM_THREADS allows runtime control of the - * number of threads/cores used when the resulting "stream_omp" program - * is executed. + * directives in the code. This varies by compiler, but a common example + *is gcc -O -fopenmp stream.c -o stream_omp The environment variable + *OMP_NUM_THREADS allows runtime control of the number of threads/cores used + *when the resulting "stream_omp" program is executed. * * To run with single-precision variables and arithmetic, simply add * -DSTREAM_TYPE=float * to the compile line. - * Note that this changes the minimum array sizes required --- see (1) above. + * Note that this changes the minimum array sizes required --- see (1) + *above. * - * The preprocessor directive "TUNED" does not do much -- it simply causes the - * code to call separate functions to execute each kernel. Trivial versions - * of these functions are provided, but they are *not* tuned -- they just + * The preprocessor directive "TUNED" does not do much -- it simply causes + *the code to call separate functions to execute each kernel. Trivial versions + * of these functions are provided, but they are *not* tuned -- they just * provide predefined interfaces to be replaced with tuned code. * * * 4) Optional: Mail the results to mccalpin@cs.virginia.edu * Be sure to include info that will help me understand: - * a) the computer hardware configuration (e.g., processor model, memory type) - * b) the compiler name/version and compilation flags - * c) any run-time information (such as OMP_NUM_THREADS) - * d) all of the output from the test case. + * a) the computer hardware configuration (e.g., processor model, + *memory type) b) the compiler name/version and compilation flags c) any + *run-time information (such as OMP_NUM_THREADS) d) all of the output from the + *test case. * * Thanks! * *-----------------------------------------------------------------------*/ -# define HLINE "-------------------------------------------------------------\n" +#define HLINE "-------------------------------------------------------------\n" #define DIS_OPENMP -# ifndef MIN -# define MIN(x,y) ((x)<(y)?(x):(y)) -# endif -# ifndef MAX -# define MAX(x,y) ((x)>(y)?(x):(y)) -# endif +#ifndef MIN +#define MIN(x, y) ((x) < (y) ? (x) : (y)) +#endif +#ifndef MAX +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#endif #ifndef STREAM_TYPE #define STREAM_TYPE double #endif -static STREAM_TYPE a[STREAM_ARRAY_SIZE+OFFSET], - b[STREAM_ARRAY_SIZE+OFFSET], - c[STREAM_ARRAY_SIZE+OFFSET]; +// static STREAM_TYPE a[STREAM_ARRAY_SIZE + OFFSET], b[STREAM_ARRAY_SIZE + +// OFFSET], +// c[STREAM_ARRAY_SIZE + OFFSET]; -static double avgtime[4] = {0}, maxtime[4] = {0}, - mintime[4] = {FLT_MAX,FLT_MAX,FLT_MAX,FLT_MAX}; +static double avgtime[4] = {0}, maxtime[4] = {0}, + mintime[4] = {FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX}; -static char *label[4] = {"Copy: ", "Scale: ", - "Add: ", "Triad: "}; +static char *label[4] = { + "Copy: ", "Scale: ", "Add: ", "Triad: "}; -static double bytes[4] = { - 2 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE, - 2 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE, - 3 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE, - 3 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE - }; +// static double bytes[4] = {2 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE, +// 2 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE, +// 3 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE, +// 3 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE}; extern double mysecond(); extern void checkSTREAMresults(); -#ifdef TUNED -extern void tuned_STREAM_Copy(); -extern void tuned_STREAM_Scale(STREAM_TYPE scalar); -extern void tuned_STREAM_Add(); -extern void tuned_STREAM_Triad(STREAM_TYPE scalar); -#endif #ifndef DIS_OPENMP #ifdef _OPENMP extern int omp_get_num_threads(); #endif #endif -int -main() - { - int quantum, checktick(); - int BytesPerWord; - int k; - size_t j; - STREAM_TYPE scalar; - double t, times[4][NTIMES]; - /* --- SETUP --- determine precision and check timing --- */ +extern const bench_stream_config config; - printf(HLINE); - printf("STREAM version $Revision: 5.10 $\n"); - printf(HLINE); - BytesPerWord = sizeof(STREAM_TYPE); - printf("This system uses %d bytes per array element.\n", - BytesPerWord); +int main() { + int asize = config.stream_array_size; + bench_malloc_init(); + STREAM_TYPE *a = bench_malloc(sizeof(STREAM_TYPE) * (asize + OFFSET)); + STREAM_TYPE *b = bench_malloc(sizeof(STREAM_TYPE) * (asize + OFFSET)); + STREAM_TYPE *c = bench_malloc(sizeof(STREAM_TYPE) * (asize + OFFSET)); - printf(HLINE); + double bytes[4] = { + 2 * sizeof(STREAM_TYPE) * asize, 2 * sizeof(STREAM_TYPE) * asize, + 3 * sizeof(STREAM_TYPE) * asize, 3 * sizeof(STREAM_TYPE) * asize}; + + STREAM_TYPE *vptr[] = {a, b, c}; + int quantum, checktick(); + // int BytesPerWord; + int k; + size_t j; + STREAM_TYPE scalar; + double t, times[4][NTIMES]; + + /* --- SETUP --- determine precision and check timing --- */ + + // printf(HLINE); + // printf("STREAM version $Revision: 5.10 $\n"); + // printf(HLINE); + // BytesPerWord = sizeof(STREAM_TYPE); + // printf("This system uses %d bytes per array element.\n", BytesPerWord); + + // printf(HLINE); #ifdef N - printf("***** WARNING: ******\n"); - printf(" It appears that you set the preprocessor variable N when compiling this code.\n"); - printf(" This version of the code uses the preprocesor variable STREAM_ARRAY_SIZE to control the array size\n"); - printf(" Reverting to default value of STREAM_ARRAY_SIZE=%.0f\n",(double) STREAM_ARRAY_SIZE); - printf("***** WARNING: ******\n"); + /* printf("***** WARNING: ******\n"); + printf(" It appears that you set the preprocessor variable N when " + "compiling this code.\n"); + printf(" This version of the code uses the preprocesor variable " + "STREAM_ARRAY_SIZE to control the array size\n"); + printf(" Reverting to default value of STREAM_ARRAY_SIZE=%.0f\n", + (double)STREAM_ARRAY_SIZE); + printf("***** WARNING: ******\n"); */ #endif - - printf("Array size = %.0f (elements), Offset = %d (elements)\n" , (double) STREAM_ARRAY_SIZE, OFFSET); - printf("Memory per array = %.1f MiB (= %.1f GiB).\n", - BytesPerWord * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024.0), - BytesPerWord * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024.0/1024.0)); - printf("Total memory required = %.1f MiB (= %.1f GiB).\n", - (3.0 * BytesPerWord) * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024.), - (3.0 * BytesPerWord) * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024./1024.)); - printf("Each kernel will be executed %d times.\n", NTIMES); - printf(" The *best* time for each kernel (excluding the first iteration)\n"); - printf(" will be used to compute the reported bandwidth.\n"); + /* + printf("Array size = %.0f (elements), Offset = %d (elements)\n", + (double)STREAM_ARRAY_SIZE, OFFSET); + printf("Memory per array = %.1f MiB (= %.1f GiB).\n", + BytesPerWord * ((double)STREAM_ARRAY_SIZE / 1024.0 / 1024.0), + BytesPerWord * ((double)STREAM_ARRAY_SIZE / 1024.0 / 1024.0 / 1024.0)); + printf("Total memory required = %.1f MiB (= %.1f GiB).\n", + (3.0 * BytesPerWord) * ((double)STREAM_ARRAY_SIZE / 1024.0 / 1024.), + (3.0 * BytesPerWord) * + ((double)STREAM_ARRAY_SIZE / 1024.0 / 1024. / 1024.)); + printf("Each kernel will be executed %d times.\n", NTIMES); + printf(" The *best* time for each kernel (excluding the first iteration)\n"); + printf(" will be used to compute the reported bandwidth.\n"); */ #ifndef DIS_OPENMP #ifdef _OPENMP - printf(HLINE); -#pragma omp parallel - { -#pragma omp master - { - k = omp_get_num_threads(); - printf ("Number of Threads requested = %i\n",k); - } - } -#endif -#endif - -#ifndef DIS_OPENMP -#ifdef _OPENMP - k = 0; + printf(HLINE); #pragma omp parallel -#pragma omp atomic - k++; - printf ("Number of Threads counted = %i\n",k); -#endif -#endif - - /* Get initial value for system clock. */ -#ifndef DIS_OPENMP -#pragma omp parallel for -#endif - for (j=0; j= 1) - printf("Your clock granularity/precision appears to be " - "%d microseconds.\n", quantum); - else { - printf("Your clock granularity appears to be " - "less than one microsecond.\n"); - quantum = 1; + { +#pragma omp master + { + k = omp_get_num_threads(); + printf("Number of Threads requested = %i\n", k); } + } +#endif +#endif - t = mysecond(); +#ifndef DIS_OPENMP +#ifdef _OPENMP + k = 0; +#pragma omp parallel +#pragma omp atomic + k++; + printf("Number of Threads counted = %i\n", k); +#endif +#endif + + /* Get initial value for system clock. */ #ifndef DIS_OPENMP #pragma omp parallel for #endif - for (j = 0; j < STREAM_ARRAY_SIZE; j++) - a[j] = 2.0E0 * a[j]; - t = 1.0E6 * (mysecond() - t); + for (j = 0; j < asize; j++) { + a[j] = 1.0; + b[j] = 2.0; + c[j] = 0.0; + } - printf("Each test below will take on the order" - " of %d microseconds.\n", (int) t ); - printf(" (= %d clock ticks)\n", (int) (t/quantum) ); - printf("Increase the size of the arrays if this shows that\n"); - printf("you are not getting at least 20 clock ticks per test.\n"); + printf(HLINE); - printf(HLINE); + if ((quantum = checktick()) >= 1) + printf("Your clock granularity/precision appears to be " + "%d microseconds.\n", + quantum); + else { + printf("Your clock granularity appears to be " + "less than one microsecond.\n"); + quantum = 1; + } - printf("WARNING -- The above is only a rough guideline.\n"); - printf("For best results, please be sure you know the\n"); - printf("precision of your system timer.\n"); - printf(HLINE); - - /* --- MAIN LOOP --- repeat test cases NTIMES times --- */ - - scalar = 3.0; - for (k=0; k= 0 ? (a) : -(a)) #endif -void checkSTREAMresults () -{ - STREAM_TYPE aj,bj,cj,scalar; - STREAM_TYPE aSumErr,bSumErr,cSumErr; - STREAM_TYPE aAvgErr,bAvgErr,cAvgErr; - double epsilon; - size_t j; - int k,ierr,err; +void checkSTREAMresults(int asize, STREAM_TYPE **vptr) { + assert(vptr); + STREAM_TYPE aj, bj, cj, scalar; + STREAM_TYPE aSumErr, bSumErr, cSumErr; + STREAM_TYPE aAvgErr, bAvgErr, cAvgErr; + double epsilon; + size_t j; + int k, ierr, err; - /* reproduce initialization */ - aj = 1.0; - bj = 2.0; - cj = 0.0; - /* a[] is modified during timing check */ - aj = 2.0E0 * aj; - /* now execute timing loop */ - scalar = 3.0; - for (k=0; k epsilon) { + err++; + printf("Failed Validation on array a[], AvgRelAbsErr > epsilon (%e)\n", + epsilon); + printf(" Expected Value: %e, AvgAbsErr: %e, AvgRelAbsErr: %e\n", aj, + aAvgErr, abs(aAvgErr) / aj); + ierr = 0; + for (j = 0; j < asize; j++) { + if (abs(vptr[0][j] / aj - 1.0) > epsilon) { + ierr++; +#ifdef VERBOSE + if (ierr < 10) { + printf(" array a: index: %ld, expected: %e, observed: %e, " + "relative error: %e\n", + j, aj, vptr[0][j], abs((aj - vptr[0][j]) / aAvgErr)); } - - /* accumulate deltas between observed and expected results */ - aSumErr = 0.0; - bSumErr = 0.0; - cSumErr = 0.0; - for (j=0; j epsilon) { - err++; - printf ("Failed Validation on array a[], AvgRelAbsErr > epsilon (%e)\n",epsilon); - printf (" Expected Value: %e, AvgAbsErr: %e, AvgRelAbsErr: %e\n",aj,aAvgErr,abs(aAvgErr)/aj); - ierr = 0; - for (j=0; j epsilon) { - ierr++; +#endif + } + } + printf(" For array a[], %d errors were found.\n", ierr); + } + if (abs(bAvgErr / bj) > epsilon) { + err++; + printf("Failed Validation on array b[], AvgRelAbsErr > epsilon (%e)\n", + epsilon); + printf(" Expected Value: %e, AvgAbsErr: %e, AvgRelAbsErr: %e\n", bj, + bAvgErr, abs(bAvgErr) / bj); + printf(" AvgRelAbsErr > Epsilon (%e)\n", epsilon); + ierr = 0; + for (j = 0; j < asize; j++) { + if (abs(vptr[1][j] / bj - 1.0) > epsilon) { + ierr++; #ifdef VERBOSE - if (ierr < 10) { - printf(" array a: index: %ld, expected: %e, observed: %e, relative error: %e\n", - j,aj,a[j],abs((aj-a[j])/aAvgErr)); - } + if (ierr < 10) { + printf(" array b: index: %ld, expected: %e, observed: %e, " + "relative error: %e\n", + j, bj, vptr[1][j], abs((bj - vptr[1][j]) / bAvgErr)); + } #endif - } - } - printf(" For array a[], %d errors were found.\n",ierr); - } - if (abs(bAvgErr/bj) > epsilon) { - err++; - printf ("Failed Validation on array b[], AvgRelAbsErr > epsilon (%e)\n",epsilon); - printf (" Expected Value: %e, AvgAbsErr: %e, AvgRelAbsErr: %e\n",bj,bAvgErr,abs(bAvgErr)/bj); - printf (" AvgRelAbsErr > Epsilon (%e)\n",epsilon); - ierr = 0; - for (j=0; j epsilon) { - ierr++; + } + } + printf(" For array b[], %d errors were found.\n", ierr); + } + if (abs(cAvgErr / cj) > epsilon) { + err++; + printf("Failed Validation on array c[], AvgRelAbsErr > epsilon (%e)\n", + epsilon); + printf(" Expected Value: %e, AvgAbsErr: %e, AvgRelAbsErr: %e\n", cj, + cAvgErr, abs(cAvgErr) / cj); + printf(" AvgRelAbsErr > Epsilon (%e)\n", epsilon); + ierr = 0; + for (j = 0; j < asize; j++) { + if (abs(vptr[2][j] / cj - 1.0) > epsilon) { + ierr++; #ifdef VERBOSE - if (ierr < 10) { - printf(" array b: index: %ld, expected: %e, observed: %e, relative error: %e\n", - j,bj,b[j],abs((bj-b[j])/bAvgErr)); - } + if (ierr < 10) { + printf(" array c: index: %ld, expected: %e, observed: %e, " + "relative error: %e\n", + j, cj, c[j], abs((cj - c[j]) / cAvgErr)); + } #endif - } - } - printf(" For array b[], %d errors were found.\n",ierr); - } - if (abs(cAvgErr/cj) > epsilon) { - err++; - printf ("Failed Validation on array c[], AvgRelAbsErr > epsilon (%e)\n",epsilon); - printf (" Expected Value: %e, AvgAbsErr: %e, AvgRelAbsErr: %e\n",cj,cAvgErr,abs(cAvgErr)/cj); - printf (" AvgRelAbsErr > Epsilon (%e)\n",epsilon); - ierr = 0; - for (j=0; j epsilon) { - ierr++; + } + } + printf(" For array c[], %d errors were found.\n", ierr); + } + if (err == 0) { + printf("Solution Validates: avg error less than %e on all three arrays\n", + epsilon); + } #ifdef VERBOSE - if (ierr < 10) { - printf(" array c: index: %ld, expected: %e, observed: %e, relative error: %e\n", - j,cj,c[j],abs((cj-c[j])/cAvgErr)); - } -#endif - } - } - printf(" For array c[], %d errors were found.\n",ierr); - } - if (err == 0) { - printf ("Solution Validates: avg error less than %e on all three arrays\n",epsilon); - } -#ifdef VERBOSE - printf ("Results Validation Verbose Results: \n"); - printf (" Expected a(1), b(1), c(1): %f %f %f \n",aj,bj,cj); - printf (" Observed a(1), b(1), c(1): %f %f %f \n",a[1],b[1],c[1]); - printf (" Rel Errors on a, b, c: %e %e %e \n",abs(aAvgErr/aj),abs(bAvgErr/bj),abs(cAvgErr/cj)); + printf("Results Validation Verbose Results: \n"); + printf(" Expected a(1), b(1), c(1): %f %f %f \n", aj, bj, cj); + printf(" Observed a(1), b(1), c(1): %f %f %f \n", vptr[0][1], vptr[1][1], + vptr[2][1]); + printf(" Rel Errors on a, b, c: %e %e %e \n", abs(aAvgErr / aj), + abs(bAvgErr / bj), abs(cAvgErr / cj)); #endif } - -#ifdef TUNED -/* stubs for "tuned" versions of the kernels */ -void tuned_STREAM_Copy() -{ - size_t j; -#ifndef DIS_OPENMP -#pragma omp parallel for -#endif - for (j=0; j + +Finfo file_table[] = { + {"/share/test.c", 355, 0, NULL, NULL}, + {"/share/test", 752, 355, NULL, NULL}, + {"/share/trm.c", 269, 1107, NULL, NULL}, +}; +int tcc_argc1 = 10; +char *tcc_argv1[] = { + "./tcc", "/share/trm.c", "/share/test.c", "-ffreestanding", + "-nostdlib", "-o", "/share/test", "-Wl,-Ttext=0x80000000", + "-O2", "-static"}; + +bench_tcc_config config = {3}; diff --git a/src/tcc/configs/train-config.c b/src/tcc/configs/train-config.c new file mode 100644 index 0000000..df2a3b4 --- /dev/null +++ b/src/tcc/configs/train-config.c @@ -0,0 +1,16 @@ +#include "../config.h" +#include + +Finfo file_table[] = { + {"/share/trm.c", 273, 0, NULL, NULL}, + {"/share/trap.h", 106, 273, NULL, NULL}, + {"/share/train.c", 1521, 379, NULL, NULL}, + {"/share/train", 106, 1900, NULL, NULL}, +}; +int tcc_argc1 = 10; +char *tcc_argv1[] = { + "./tcc", "/share/trm.c", "/share/train.c", "-ffreestanding", + "-nostdlib", "-o", "/share/train", "-Wl,-Ttext=0x80000000", + "-O2", "-static"}; + +bench_tcc_config config = {4}; diff --git a/src/tcc/dwarf.h b/src/tcc/dwarf.h index c961bc3..9033117 100644 --- a/src/tcc/dwarf.h +++ b/src/tcc/dwarf.h @@ -27,1006 +27,935 @@ not, see . */ #ifndef _DWARF_H -#define _DWARF_H 1 +#define _DWARF_H 1 /* DWARF Unit Header Types. */ -enum - { - DW_UT_compile = 0x01, - DW_UT_type = 0x02, - DW_UT_partial = 0x03, - DW_UT_skeleton = 0x04, - DW_UT_split_compile = 0x05, - DW_UT_split_type = 0x06, +enum { + DW_UT_compile = 0x01, + DW_UT_type = 0x02, + DW_UT_partial = 0x03, + DW_UT_skeleton = 0x04, + DW_UT_split_compile = 0x05, + DW_UT_split_type = 0x06, - DW_UT_lo_user = 0x80, - DW_UT_hi_user = 0xff - }; + DW_UT_lo_user = 0x80, + DW_UT_hi_user = 0xff +}; /* DWARF tags. */ -enum - { - DW_TAG_array_type = 0x01, - DW_TAG_class_type = 0x02, - DW_TAG_entry_point = 0x03, - DW_TAG_enumeration_type = 0x04, - DW_TAG_formal_parameter = 0x05, - /* 0x06 reserved. */ - /* 0x07 reserved. */ - DW_TAG_imported_declaration = 0x08, - /* 0x09 reserved. */ - DW_TAG_label = 0x0a, - DW_TAG_lexical_block = 0x0b, - /* 0x0c reserved. */ - DW_TAG_member = 0x0d, - /* 0x0e reserved. */ - DW_TAG_pointer_type = 0x0f, - DW_TAG_reference_type = 0x10, - DW_TAG_compile_unit = 0x11, - DW_TAG_string_type = 0x12, - DW_TAG_structure_type = 0x13, - /* 0x14 reserved. */ - DW_TAG_subroutine_type = 0x15, - DW_TAG_typedef = 0x16, - DW_TAG_union_type = 0x17, - DW_TAG_unspecified_parameters = 0x18, - DW_TAG_variant = 0x19, - DW_TAG_common_block = 0x1a, - DW_TAG_common_inclusion = 0x1b, - DW_TAG_inheritance = 0x1c, - DW_TAG_inlined_subroutine = 0x1d, - DW_TAG_module = 0x1e, - DW_TAG_ptr_to_member_type = 0x1f, - DW_TAG_set_type = 0x20, - DW_TAG_subrange_type = 0x21, - DW_TAG_with_stmt = 0x22, - DW_TAG_access_declaration = 0x23, - DW_TAG_base_type = 0x24, - DW_TAG_catch_block = 0x25, - DW_TAG_const_type = 0x26, - DW_TAG_constant = 0x27, - DW_TAG_enumerator = 0x28, - DW_TAG_file_type = 0x29, - DW_TAG_friend = 0x2a, - DW_TAG_namelist = 0x2b, - DW_TAG_namelist_item = 0x2c, - DW_TAG_packed_type = 0x2d, - DW_TAG_subprogram = 0x2e, - DW_TAG_template_type_parameter = 0x2f, - DW_TAG_template_value_parameter = 0x30, - DW_TAG_thrown_type = 0x31, - DW_TAG_try_block = 0x32, - DW_TAG_variant_part = 0x33, - DW_TAG_variable = 0x34, - DW_TAG_volatile_type = 0x35, - DW_TAG_dwarf_procedure = 0x36, - DW_TAG_restrict_type = 0x37, - DW_TAG_interface_type = 0x38, - DW_TAG_namespace = 0x39, - DW_TAG_imported_module = 0x3a, - DW_TAG_unspecified_type = 0x3b, - DW_TAG_partial_unit = 0x3c, - DW_TAG_imported_unit = 0x3d, - /* 0x3e reserved. Was DW_TAG_mutable_type. */ - DW_TAG_condition = 0x3f, - DW_TAG_shared_type = 0x40, - DW_TAG_type_unit = 0x41, - DW_TAG_rvalue_reference_type = 0x42, - DW_TAG_template_alias = 0x43, - DW_TAG_coarray_type = 0x44, - DW_TAG_generic_subrange = 0x45, - DW_TAG_dynamic_type = 0x46, - DW_TAG_atomic_type = 0x47, - DW_TAG_call_site = 0x48, - DW_TAG_call_site_parameter = 0x49, - DW_TAG_skeleton_unit = 0x4a, - DW_TAG_immutable_type = 0x4b, +enum { + DW_TAG_array_type = 0x01, + DW_TAG_class_type = 0x02, + DW_TAG_entry_point = 0x03, + DW_TAG_enumeration_type = 0x04, + DW_TAG_formal_parameter = 0x05, + /* 0x06 reserved. */ + /* 0x07 reserved. */ + DW_TAG_imported_declaration = 0x08, + /* 0x09 reserved. */ + DW_TAG_label = 0x0a, + DW_TAG_lexical_block = 0x0b, + /* 0x0c reserved. */ + DW_TAG_member = 0x0d, + /* 0x0e reserved. */ + DW_TAG_pointer_type = 0x0f, + DW_TAG_reference_type = 0x10, + DW_TAG_compile_unit = 0x11, + DW_TAG_string_type = 0x12, + DW_TAG_structure_type = 0x13, + /* 0x14 reserved. */ + DW_TAG_subroutine_type = 0x15, + DW_TAG_typedef = 0x16, + DW_TAG_union_type = 0x17, + DW_TAG_unspecified_parameters = 0x18, + DW_TAG_variant = 0x19, + DW_TAG_common_block = 0x1a, + DW_TAG_common_inclusion = 0x1b, + DW_TAG_inheritance = 0x1c, + DW_TAG_inlined_subroutine = 0x1d, + DW_TAG_module = 0x1e, + DW_TAG_ptr_to_member_type = 0x1f, + DW_TAG_set_type = 0x20, + DW_TAG_subrange_type = 0x21, + DW_TAG_with_stmt = 0x22, + DW_TAG_access_declaration = 0x23, + DW_TAG_base_type = 0x24, + DW_TAG_catch_block = 0x25, + DW_TAG_const_type = 0x26, + DW_TAG_constant = 0x27, + DW_TAG_enumerator = 0x28, + DW_TAG_file_type = 0x29, + DW_TAG_friend = 0x2a, + DW_TAG_namelist = 0x2b, + DW_TAG_namelist_item = 0x2c, + DW_TAG_packed_type = 0x2d, + DW_TAG_subprogram = 0x2e, + DW_TAG_template_type_parameter = 0x2f, + DW_TAG_template_value_parameter = 0x30, + DW_TAG_thrown_type = 0x31, + DW_TAG_try_block = 0x32, + DW_TAG_variant_part = 0x33, + DW_TAG_variable = 0x34, + DW_TAG_volatile_type = 0x35, + DW_TAG_dwarf_procedure = 0x36, + DW_TAG_restrict_type = 0x37, + DW_TAG_interface_type = 0x38, + DW_TAG_namespace = 0x39, + DW_TAG_imported_module = 0x3a, + DW_TAG_unspecified_type = 0x3b, + DW_TAG_partial_unit = 0x3c, + DW_TAG_imported_unit = 0x3d, + /* 0x3e reserved. Was DW_TAG_mutable_type. */ + DW_TAG_condition = 0x3f, + DW_TAG_shared_type = 0x40, + DW_TAG_type_unit = 0x41, + DW_TAG_rvalue_reference_type = 0x42, + DW_TAG_template_alias = 0x43, + DW_TAG_coarray_type = 0x44, + DW_TAG_generic_subrange = 0x45, + DW_TAG_dynamic_type = 0x46, + DW_TAG_atomic_type = 0x47, + DW_TAG_call_site = 0x48, + DW_TAG_call_site_parameter = 0x49, + DW_TAG_skeleton_unit = 0x4a, + DW_TAG_immutable_type = 0x4b, - DW_TAG_lo_user = 0x4080, + DW_TAG_lo_user = 0x4080, - DW_TAG_MIPS_loop = 0x4081, - DW_TAG_format_label = 0x4101, - DW_TAG_function_template = 0x4102, - DW_TAG_class_template = 0x4103, + DW_TAG_MIPS_loop = 0x4081, + DW_TAG_format_label = 0x4101, + DW_TAG_function_template = 0x4102, + DW_TAG_class_template = 0x4103, - DW_TAG_GNU_BINCL = 0x4104, - DW_TAG_GNU_EINCL = 0x4105, + DW_TAG_GNU_BINCL = 0x4104, + DW_TAG_GNU_EINCL = 0x4105, - DW_TAG_GNU_template_template_param = 0x4106, - DW_TAG_GNU_template_parameter_pack = 0x4107, - DW_TAG_GNU_formal_parameter_pack = 0x4108, - DW_TAG_GNU_call_site = 0x4109, - DW_TAG_GNU_call_site_parameter = 0x410a, - - DW_TAG_hi_user = 0xffff - }; + DW_TAG_GNU_template_template_param = 0x4106, + DW_TAG_GNU_template_parameter_pack = 0x4107, + DW_TAG_GNU_formal_parameter_pack = 0x4108, + DW_TAG_GNU_call_site = 0x4109, + DW_TAG_GNU_call_site_parameter = 0x410a, + DW_TAG_hi_user = 0xffff +}; /* Children determination encodings. */ -enum - { - DW_CHILDREN_no = 0, - DW_CHILDREN_yes = 1 - }; - +enum { DW_CHILDREN_no = 0, DW_CHILDREN_yes = 1 }; /* DWARF attributes encodings. */ -enum - { - DW_AT_sibling = 0x01, - DW_AT_location = 0x02, - DW_AT_name = 0x03, - /* 0x04 reserved. */ - /* 0x05 reserved. */ - /* 0x06 reserved. */ - /* 0x07 reserved. */ - /* 0x08 reserved. */ - DW_AT_ordering = 0x09, - /* 0x0a reserved. */ - DW_AT_byte_size = 0x0b, - DW_AT_bit_offset = 0x0c, /* Deprecated in DWARF4. */ - DW_AT_bit_size = 0x0d, - /* 0x0e reserved. */ - /* 0x0f reserved. */ - DW_AT_stmt_list = 0x10, - DW_AT_low_pc = 0x11, - DW_AT_high_pc = 0x12, - DW_AT_language = 0x13, - /* 0x14 reserved. */ - DW_AT_discr = 0x15, - DW_AT_discr_value = 0x16, - DW_AT_visibility = 0x17, - DW_AT_import = 0x18, - DW_AT_string_length = 0x19, - DW_AT_common_reference = 0x1a, - DW_AT_comp_dir = 0x1b, - DW_AT_const_value = 0x1c, - DW_AT_containing_type = 0x1d, - DW_AT_default_value = 0x1e, - /* 0x1f reserved. */ - DW_AT_inline = 0x20, - DW_AT_is_optional = 0x21, - DW_AT_lower_bound = 0x22, - /* 0x23 reserved. */ - /* 0x24 reserved. */ - DW_AT_producer = 0x25, - /* 0x26 reserved. */ - DW_AT_prototyped = 0x27, - /* 0x28 reserved. */ - /* 0x29 reserved. */ - DW_AT_return_addr = 0x2a, - /* 0x2b reserved. */ - DW_AT_start_scope = 0x2c, - /* 0x2d reserved. */ - DW_AT_bit_stride = 0x2e, - DW_AT_upper_bound = 0x2f, - /* 0x30 reserved. */ - DW_AT_abstract_origin = 0x31, - DW_AT_accessibility = 0x32, - DW_AT_address_class = 0x33, - DW_AT_artificial = 0x34, - DW_AT_base_types = 0x35, - DW_AT_calling_convention = 0x36, - DW_AT_count = 0x37, - DW_AT_data_member_location = 0x38, - DW_AT_decl_column = 0x39, - DW_AT_decl_file = 0x3a, - DW_AT_decl_line = 0x3b, - DW_AT_declaration = 0x3c, - DW_AT_discr_list = 0x3d, - DW_AT_encoding = 0x3e, - DW_AT_external = 0x3f, - DW_AT_frame_base = 0x40, - DW_AT_friend = 0x41, - DW_AT_identifier_case = 0x42, - DW_AT_macro_info = 0x43, /* Deprecated in DWARF5. */ - DW_AT_namelist_item = 0x44, - DW_AT_priority = 0x45, - DW_AT_segment = 0x46, - DW_AT_specification = 0x47, - DW_AT_static_link = 0x48, - DW_AT_type = 0x49, - DW_AT_use_location = 0x4a, - DW_AT_variable_parameter = 0x4b, - DW_AT_virtuality = 0x4c, - DW_AT_vtable_elem_location = 0x4d, - DW_AT_allocated = 0x4e, - DW_AT_associated = 0x4f, - DW_AT_data_location = 0x50, - DW_AT_byte_stride = 0x51, - DW_AT_entry_pc = 0x52, - DW_AT_use_UTF8 = 0x53, - DW_AT_extension = 0x54, - DW_AT_ranges = 0x55, - DW_AT_trampoline = 0x56, - DW_AT_call_column = 0x57, - DW_AT_call_file = 0x58, - DW_AT_call_line = 0x59, - DW_AT_description = 0x5a, - DW_AT_binary_scale = 0x5b, - DW_AT_decimal_scale = 0x5c, - DW_AT_small = 0x5d, - DW_AT_decimal_sign = 0x5e, - DW_AT_digit_count = 0x5f, - DW_AT_picture_string = 0x60, - DW_AT_mutable = 0x61, - DW_AT_threads_scaled = 0x62, - DW_AT_explicit = 0x63, - DW_AT_object_pointer = 0x64, - DW_AT_endianity = 0x65, - DW_AT_elemental = 0x66, - DW_AT_pure = 0x67, - DW_AT_recursive = 0x68, - DW_AT_signature = 0x69, - DW_AT_main_subprogram = 0x6a, - DW_AT_data_bit_offset = 0x6b, - DW_AT_const_expr = 0x6c, - DW_AT_enum_class = 0x6d, - DW_AT_linkage_name = 0x6e, - DW_AT_string_length_bit_size = 0x6f, - DW_AT_string_length_byte_size = 0x70, - DW_AT_rank = 0x71, - DW_AT_str_offsets_base = 0x72, - DW_AT_addr_base = 0x73, - DW_AT_rnglists_base = 0x74, - /* 0x75 reserved. */ - DW_AT_dwo_name = 0x76, - DW_AT_reference = 0x77, - DW_AT_rvalue_reference = 0x78, - DW_AT_macros = 0x79, - DW_AT_call_all_calls = 0x7a, - DW_AT_call_all_source_calls = 0x7b, - DW_AT_call_all_tail_calls = 0x7c, - DW_AT_call_return_pc = 0x7d, - DW_AT_call_value = 0x7e, - DW_AT_call_origin = 0x7f, - DW_AT_call_parameter = 0x80, - DW_AT_call_pc = 0x81, - DW_AT_call_tail_call = 0x82, - DW_AT_call_target = 0x83, - DW_AT_call_target_clobbered = 0x84, - DW_AT_call_data_location = 0x85, - DW_AT_call_data_value = 0x86, - DW_AT_noreturn = 0x87, - DW_AT_alignment = 0x88, - DW_AT_export_symbols = 0x89, - DW_AT_deleted = 0x8a, - DW_AT_defaulted = 0x8b, - DW_AT_loclists_base = 0x8c, +enum { + DW_AT_sibling = 0x01, + DW_AT_location = 0x02, + DW_AT_name = 0x03, + /* 0x04 reserved. */ + /* 0x05 reserved. */ + /* 0x06 reserved. */ + /* 0x07 reserved. */ + /* 0x08 reserved. */ + DW_AT_ordering = 0x09, + /* 0x0a reserved. */ + DW_AT_byte_size = 0x0b, + DW_AT_bit_offset = 0x0c, /* Deprecated in DWARF4. */ + DW_AT_bit_size = 0x0d, + /* 0x0e reserved. */ + /* 0x0f reserved. */ + DW_AT_stmt_list = 0x10, + DW_AT_low_pc = 0x11, + DW_AT_high_pc = 0x12, + DW_AT_language = 0x13, + /* 0x14 reserved. */ + DW_AT_discr = 0x15, + DW_AT_discr_value = 0x16, + DW_AT_visibility = 0x17, + DW_AT_import = 0x18, + DW_AT_string_length = 0x19, + DW_AT_common_reference = 0x1a, + DW_AT_comp_dir = 0x1b, + DW_AT_const_value = 0x1c, + DW_AT_containing_type = 0x1d, + DW_AT_default_value = 0x1e, + /* 0x1f reserved. */ + DW_AT_inline = 0x20, + DW_AT_is_optional = 0x21, + DW_AT_lower_bound = 0x22, + /* 0x23 reserved. */ + /* 0x24 reserved. */ + DW_AT_producer = 0x25, + /* 0x26 reserved. */ + DW_AT_prototyped = 0x27, + /* 0x28 reserved. */ + /* 0x29 reserved. */ + DW_AT_return_addr = 0x2a, + /* 0x2b reserved. */ + DW_AT_start_scope = 0x2c, + /* 0x2d reserved. */ + DW_AT_bit_stride = 0x2e, + DW_AT_upper_bound = 0x2f, + /* 0x30 reserved. */ + DW_AT_abstract_origin = 0x31, + DW_AT_accessibility = 0x32, + DW_AT_address_class = 0x33, + DW_AT_artificial = 0x34, + DW_AT_base_types = 0x35, + DW_AT_calling_convention = 0x36, + DW_AT_count = 0x37, + DW_AT_data_member_location = 0x38, + DW_AT_decl_column = 0x39, + DW_AT_decl_file = 0x3a, + DW_AT_decl_line = 0x3b, + DW_AT_declaration = 0x3c, + DW_AT_discr_list = 0x3d, + DW_AT_encoding = 0x3e, + DW_AT_external = 0x3f, + DW_AT_frame_base = 0x40, + DW_AT_friend = 0x41, + DW_AT_identifier_case = 0x42, + DW_AT_macro_info = 0x43, /* Deprecated in DWARF5. */ + DW_AT_namelist_item = 0x44, + DW_AT_priority = 0x45, + DW_AT_segment = 0x46, + DW_AT_specification = 0x47, + DW_AT_static_link = 0x48, + DW_AT_type = 0x49, + DW_AT_use_location = 0x4a, + DW_AT_variable_parameter = 0x4b, + DW_AT_virtuality = 0x4c, + DW_AT_vtable_elem_location = 0x4d, + DW_AT_allocated = 0x4e, + DW_AT_associated = 0x4f, + DW_AT_data_location = 0x50, + DW_AT_byte_stride = 0x51, + DW_AT_entry_pc = 0x52, + DW_AT_use_UTF8 = 0x53, + DW_AT_extension = 0x54, + DW_AT_ranges = 0x55, + DW_AT_trampoline = 0x56, + DW_AT_call_column = 0x57, + DW_AT_call_file = 0x58, + DW_AT_call_line = 0x59, + DW_AT_description = 0x5a, + DW_AT_binary_scale = 0x5b, + DW_AT_decimal_scale = 0x5c, + DW_AT_small = 0x5d, + DW_AT_decimal_sign = 0x5e, + DW_AT_digit_count = 0x5f, + DW_AT_picture_string = 0x60, + DW_AT_mutable = 0x61, + DW_AT_threads_scaled = 0x62, + DW_AT_explicit = 0x63, + DW_AT_object_pointer = 0x64, + DW_AT_endianity = 0x65, + DW_AT_elemental = 0x66, + DW_AT_pure = 0x67, + DW_AT_recursive = 0x68, + DW_AT_signature = 0x69, + DW_AT_main_subprogram = 0x6a, + DW_AT_data_bit_offset = 0x6b, + DW_AT_const_expr = 0x6c, + DW_AT_enum_class = 0x6d, + DW_AT_linkage_name = 0x6e, + DW_AT_string_length_bit_size = 0x6f, + DW_AT_string_length_byte_size = 0x70, + DW_AT_rank = 0x71, + DW_AT_str_offsets_base = 0x72, + DW_AT_addr_base = 0x73, + DW_AT_rnglists_base = 0x74, + /* 0x75 reserved. */ + DW_AT_dwo_name = 0x76, + DW_AT_reference = 0x77, + DW_AT_rvalue_reference = 0x78, + DW_AT_macros = 0x79, + DW_AT_call_all_calls = 0x7a, + DW_AT_call_all_source_calls = 0x7b, + DW_AT_call_all_tail_calls = 0x7c, + DW_AT_call_return_pc = 0x7d, + DW_AT_call_value = 0x7e, + DW_AT_call_origin = 0x7f, + DW_AT_call_parameter = 0x80, + DW_AT_call_pc = 0x81, + DW_AT_call_tail_call = 0x82, + DW_AT_call_target = 0x83, + DW_AT_call_target_clobbered = 0x84, + DW_AT_call_data_location = 0x85, + DW_AT_call_data_value = 0x86, + DW_AT_noreturn = 0x87, + DW_AT_alignment = 0x88, + DW_AT_export_symbols = 0x89, + DW_AT_deleted = 0x8a, + DW_AT_defaulted = 0x8b, + DW_AT_loclists_base = 0x8c, - DW_AT_lo_user = 0x2000, + DW_AT_lo_user = 0x2000, - DW_AT_MIPS_fde = 0x2001, - DW_AT_MIPS_loop_begin = 0x2002, - DW_AT_MIPS_tail_loop_begin = 0x2003, - DW_AT_MIPS_epilog_begin = 0x2004, - DW_AT_MIPS_loop_unroll_factor = 0x2005, - DW_AT_MIPS_software_pipeline_depth = 0x2006, - DW_AT_MIPS_linkage_name = 0x2007, - DW_AT_MIPS_stride = 0x2008, - DW_AT_MIPS_abstract_name = 0x2009, - DW_AT_MIPS_clone_origin = 0x200a, - DW_AT_MIPS_has_inlines = 0x200b, - DW_AT_MIPS_stride_byte = 0x200c, - DW_AT_MIPS_stride_elem = 0x200d, - DW_AT_MIPS_ptr_dopetype = 0x200e, - DW_AT_MIPS_allocatable_dopetype = 0x200f, - DW_AT_MIPS_assumed_shape_dopetype = 0x2010, - DW_AT_MIPS_assumed_size = 0x2011, + DW_AT_MIPS_fde = 0x2001, + DW_AT_MIPS_loop_begin = 0x2002, + DW_AT_MIPS_tail_loop_begin = 0x2003, + DW_AT_MIPS_epilog_begin = 0x2004, + DW_AT_MIPS_loop_unroll_factor = 0x2005, + DW_AT_MIPS_software_pipeline_depth = 0x2006, + DW_AT_MIPS_linkage_name = 0x2007, + DW_AT_MIPS_stride = 0x2008, + DW_AT_MIPS_abstract_name = 0x2009, + DW_AT_MIPS_clone_origin = 0x200a, + DW_AT_MIPS_has_inlines = 0x200b, + DW_AT_MIPS_stride_byte = 0x200c, + DW_AT_MIPS_stride_elem = 0x200d, + DW_AT_MIPS_ptr_dopetype = 0x200e, + DW_AT_MIPS_allocatable_dopetype = 0x200f, + DW_AT_MIPS_assumed_shape_dopetype = 0x2010, + DW_AT_MIPS_assumed_size = 0x2011, - /* GNU extensions. */ - DW_AT_sf_names = 0x2101, - DW_AT_src_info = 0x2102, - DW_AT_mac_info = 0x2103, - DW_AT_src_coords = 0x2104, - DW_AT_body_begin = 0x2105, - DW_AT_body_end = 0x2106, - DW_AT_GNU_vector = 0x2107, - DW_AT_GNU_guarded_by = 0x2108, - DW_AT_GNU_pt_guarded_by = 0x2109, - DW_AT_GNU_guarded = 0x210a, - DW_AT_GNU_pt_guarded = 0x210b, - DW_AT_GNU_locks_excluded = 0x210c, - DW_AT_GNU_exclusive_locks_required = 0x210d, - DW_AT_GNU_shared_locks_required = 0x210e, - DW_AT_GNU_odr_signature = 0x210f, - DW_AT_GNU_template_name = 0x2110, - DW_AT_GNU_call_site_value = 0x2111, - DW_AT_GNU_call_site_data_value = 0x2112, - DW_AT_GNU_call_site_target = 0x2113, - DW_AT_GNU_call_site_target_clobbered = 0x2114, - DW_AT_GNU_tail_call = 0x2115, - DW_AT_GNU_all_tail_call_sites = 0x2116, - DW_AT_GNU_all_call_sites = 0x2117, - DW_AT_GNU_all_source_call_sites = 0x2118, - DW_AT_GNU_locviews = 0x2137, - DW_AT_GNU_entry_view = 0x2138, - DW_AT_GNU_macros = 0x2119, - DW_AT_GNU_deleted = 0x211a, - /* GNU Debug Fission extensions. */ - DW_AT_GNU_dwo_name = 0x2130, - DW_AT_GNU_dwo_id = 0x2131, - DW_AT_GNU_ranges_base = 0x2132, - DW_AT_GNU_addr_base = 0x2133, - DW_AT_GNU_pubnames = 0x2134, - DW_AT_GNU_pubtypes = 0x2135, + /* GNU extensions. */ + DW_AT_sf_names = 0x2101, + DW_AT_src_info = 0x2102, + DW_AT_mac_info = 0x2103, + DW_AT_src_coords = 0x2104, + DW_AT_body_begin = 0x2105, + DW_AT_body_end = 0x2106, + DW_AT_GNU_vector = 0x2107, + DW_AT_GNU_guarded_by = 0x2108, + DW_AT_GNU_pt_guarded_by = 0x2109, + DW_AT_GNU_guarded = 0x210a, + DW_AT_GNU_pt_guarded = 0x210b, + DW_AT_GNU_locks_excluded = 0x210c, + DW_AT_GNU_exclusive_locks_required = 0x210d, + DW_AT_GNU_shared_locks_required = 0x210e, + DW_AT_GNU_odr_signature = 0x210f, + DW_AT_GNU_template_name = 0x2110, + DW_AT_GNU_call_site_value = 0x2111, + DW_AT_GNU_call_site_data_value = 0x2112, + DW_AT_GNU_call_site_target = 0x2113, + DW_AT_GNU_call_site_target_clobbered = 0x2114, + DW_AT_GNU_tail_call = 0x2115, + DW_AT_GNU_all_tail_call_sites = 0x2116, + DW_AT_GNU_all_call_sites = 0x2117, + DW_AT_GNU_all_source_call_sites = 0x2118, + DW_AT_GNU_locviews = 0x2137, + DW_AT_GNU_entry_view = 0x2138, + DW_AT_GNU_macros = 0x2119, + DW_AT_GNU_deleted = 0x211a, + /* GNU Debug Fission extensions. */ + DW_AT_GNU_dwo_name = 0x2130, + DW_AT_GNU_dwo_id = 0x2131, + DW_AT_GNU_ranges_base = 0x2132, + DW_AT_GNU_addr_base = 0x2133, + DW_AT_GNU_pubnames = 0x2134, + DW_AT_GNU_pubtypes = 0x2135, - /* https://gcc.gnu.org/wiki/DW_AT_GNU_numerator_denominator */ - DW_AT_GNU_numerator = 0x2303, - DW_AT_GNU_denominator = 0x2304, - /* https://gcc.gnu.org/wiki/DW_AT_GNU_bias */ - DW_AT_GNU_bias = 0x2305, + /* https://gcc.gnu.org/wiki/DW_AT_GNU_numerator_denominator */ + DW_AT_GNU_numerator = 0x2303, + DW_AT_GNU_denominator = 0x2304, + /* https://gcc.gnu.org/wiki/DW_AT_GNU_bias */ + DW_AT_GNU_bias = 0x2305, - DW_AT_hi_user = 0x3fff - }; + DW_AT_hi_user = 0x3fff +}; /* Old unofficially attribute names. Should not be used. Will not appear in known-dwarf.h */ /* DWARF1 array subscripts and element data types. */ -#define DW_AT_subscr_data 0x0a +#define DW_AT_subscr_data 0x0a /* DWARF1 enumeration literals. */ -#define DW_AT_element_list 0x0f +#define DW_AT_element_list 0x0f /* DWARF1 reference for variable to member structure, class or union. */ -#define DW_AT_member 0x14 +#define DW_AT_member 0x14 /* DWARF form encodings. */ -enum - { - DW_FORM_addr = 0x01, - DW_FORM_block2 = 0x03, - DW_FORM_block4 = 0x04, - DW_FORM_data2 = 0x05, - DW_FORM_data4 = 0x06, - DW_FORM_data8 = 0x07, - DW_FORM_string = 0x08, - DW_FORM_block = 0x09, - DW_FORM_block1 = 0x0a, - DW_FORM_data1 = 0x0b, - DW_FORM_flag = 0x0c, - DW_FORM_sdata = 0x0d, - DW_FORM_strp = 0x0e, - DW_FORM_udata = 0x0f, - DW_FORM_ref_addr = 0x10, - DW_FORM_ref1 = 0x11, - DW_FORM_ref2 = 0x12, - DW_FORM_ref4 = 0x13, - DW_FORM_ref8 = 0x14, - DW_FORM_ref_udata = 0x15, - DW_FORM_indirect = 0x16, - DW_FORM_sec_offset = 0x17, - DW_FORM_exprloc = 0x18, - DW_FORM_flag_present = 0x19, - DW_FORM_strx = 0x1a, - DW_FORM_addrx = 0x1b, - DW_FORM_ref_sup4 = 0x1c, - DW_FORM_strp_sup = 0x1d, - DW_FORM_data16 = 0x1e, - DW_FORM_line_strp = 0x1f, - DW_FORM_ref_sig8 = 0x20, - DW_FORM_implicit_const = 0x21, - DW_FORM_loclistx = 0x22, - DW_FORM_rnglistx = 0x23, - DW_FORM_ref_sup8 = 0x24, - DW_FORM_strx1 = 0x25, - DW_FORM_strx2 = 0x26, - DW_FORM_strx3 = 0x27, - DW_FORM_strx4 = 0x28, - DW_FORM_addrx1 = 0x29, - DW_FORM_addrx2 = 0x2a, - DW_FORM_addrx3 = 0x2b, - DW_FORM_addrx4 = 0x2c, +enum { + DW_FORM_addr = 0x01, + DW_FORM_block2 = 0x03, + DW_FORM_block4 = 0x04, + DW_FORM_data2 = 0x05, + DW_FORM_data4 = 0x06, + DW_FORM_data8 = 0x07, + DW_FORM_string = 0x08, + DW_FORM_block = 0x09, + DW_FORM_block1 = 0x0a, + DW_FORM_data1 = 0x0b, + DW_FORM_flag = 0x0c, + DW_FORM_sdata = 0x0d, + DW_FORM_strp = 0x0e, + DW_FORM_udata = 0x0f, + DW_FORM_ref_addr = 0x10, + DW_FORM_ref1 = 0x11, + DW_FORM_ref2 = 0x12, + DW_FORM_ref4 = 0x13, + DW_FORM_ref8 = 0x14, + DW_FORM_ref_udata = 0x15, + DW_FORM_indirect = 0x16, + DW_FORM_sec_offset = 0x17, + DW_FORM_exprloc = 0x18, + DW_FORM_flag_present = 0x19, + DW_FORM_strx = 0x1a, + DW_FORM_addrx = 0x1b, + DW_FORM_ref_sup4 = 0x1c, + DW_FORM_strp_sup = 0x1d, + DW_FORM_data16 = 0x1e, + DW_FORM_line_strp = 0x1f, + DW_FORM_ref_sig8 = 0x20, + DW_FORM_implicit_const = 0x21, + DW_FORM_loclistx = 0x22, + DW_FORM_rnglistx = 0x23, + DW_FORM_ref_sup8 = 0x24, + DW_FORM_strx1 = 0x25, + DW_FORM_strx2 = 0x26, + DW_FORM_strx3 = 0x27, + DW_FORM_strx4 = 0x28, + DW_FORM_addrx1 = 0x29, + DW_FORM_addrx2 = 0x2a, + DW_FORM_addrx3 = 0x2b, + DW_FORM_addrx4 = 0x2c, - /* GNU Debug Fission extensions. */ - DW_FORM_GNU_addr_index = 0x1f01, - DW_FORM_GNU_str_index = 0x1f02, - - DW_FORM_GNU_ref_alt = 0x1f20, /* offset in alternate .debuginfo. */ - DW_FORM_GNU_strp_alt = 0x1f21 /* offset in alternate .debug_str. */ - }; + /* GNU Debug Fission extensions. */ + DW_FORM_GNU_addr_index = 0x1f01, + DW_FORM_GNU_str_index = 0x1f02, + DW_FORM_GNU_ref_alt = 0x1f20, /* offset in alternate .debuginfo. */ + DW_FORM_GNU_strp_alt = 0x1f21 /* offset in alternate .debug_str. */ +}; /* DWARF location operation encodings. */ -enum - { - DW_OP_addr = 0x03, /* Constant address. */ - DW_OP_deref = 0x06, - DW_OP_const1u = 0x08, /* Unsigned 1-byte constant. */ - DW_OP_const1s = 0x09, /* Signed 1-byte constant. */ - DW_OP_const2u = 0x0a, /* Unsigned 2-byte constant. */ - DW_OP_const2s = 0x0b, /* Signed 2-byte constant. */ - DW_OP_const4u = 0x0c, /* Unsigned 4-byte constant. */ - DW_OP_const4s = 0x0d, /* Signed 4-byte constant. */ - DW_OP_const8u = 0x0e, /* Unsigned 8-byte constant. */ - DW_OP_const8s = 0x0f, /* Signed 8-byte constant. */ - DW_OP_constu = 0x10, /* Unsigned LEB128 constant. */ - DW_OP_consts = 0x11, /* Signed LEB128 constant. */ - DW_OP_dup = 0x12, - DW_OP_drop = 0x13, - DW_OP_over = 0x14, - DW_OP_pick = 0x15, /* 1-byte stack index. */ - DW_OP_swap = 0x16, - DW_OP_rot = 0x17, - DW_OP_xderef = 0x18, - DW_OP_abs = 0x19, - DW_OP_and = 0x1a, - DW_OP_div = 0x1b, - DW_OP_minus = 0x1c, - DW_OP_mod = 0x1d, - DW_OP_mul = 0x1e, - DW_OP_neg = 0x1f, - DW_OP_not = 0x20, - DW_OP_or = 0x21, - DW_OP_plus = 0x22, - DW_OP_plus_uconst = 0x23, /* Unsigned LEB128 addend. */ - DW_OP_shl = 0x24, - DW_OP_shr = 0x25, - DW_OP_shra = 0x26, - DW_OP_xor = 0x27, - DW_OP_bra = 0x28, /* Signed 2-byte constant. */ - DW_OP_eq = 0x29, - DW_OP_ge = 0x2a, - DW_OP_gt = 0x2b, - DW_OP_le = 0x2c, - DW_OP_lt = 0x2d, - DW_OP_ne = 0x2e, - DW_OP_skip = 0x2f, /* Signed 2-byte constant. */ - DW_OP_lit0 = 0x30, /* Literal 0. */ - DW_OP_lit1 = 0x31, /* Literal 1. */ - DW_OP_lit2 = 0x32, /* Literal 2. */ - DW_OP_lit3 = 0x33, /* Literal 3. */ - DW_OP_lit4 = 0x34, /* Literal 4. */ - DW_OP_lit5 = 0x35, /* Literal 5. */ - DW_OP_lit6 = 0x36, /* Literal 6. */ - DW_OP_lit7 = 0x37, /* Literal 7. */ - DW_OP_lit8 = 0x38, /* Literal 8. */ - DW_OP_lit9 = 0x39, /* Literal 9. */ - DW_OP_lit10 = 0x3a, /* Literal 10. */ - DW_OP_lit11 = 0x3b, /* Literal 11. */ - DW_OP_lit12 = 0x3c, /* Literal 12. */ - DW_OP_lit13 = 0x3d, /* Literal 13. */ - DW_OP_lit14 = 0x3e, /* Literal 14. */ - DW_OP_lit15 = 0x3f, /* Literal 15. */ - DW_OP_lit16 = 0x40, /* Literal 16. */ - DW_OP_lit17 = 0x41, /* Literal 17. */ - DW_OP_lit18 = 0x42, /* Literal 18. */ - DW_OP_lit19 = 0x43, /* Literal 19. */ - DW_OP_lit20 = 0x44, /* Literal 20. */ - DW_OP_lit21 = 0x45, /* Literal 21. */ - DW_OP_lit22 = 0x46, /* Literal 22. */ - DW_OP_lit23 = 0x47, /* Literal 23. */ - DW_OP_lit24 = 0x48, /* Literal 24. */ - DW_OP_lit25 = 0x49, /* Literal 25. */ - DW_OP_lit26 = 0x4a, /* Literal 26. */ - DW_OP_lit27 = 0x4b, /* Literal 27. */ - DW_OP_lit28 = 0x4c, /* Literal 28. */ - DW_OP_lit29 = 0x4d, /* Literal 29. */ - DW_OP_lit30 = 0x4e, /* Literal 30. */ - DW_OP_lit31 = 0x4f, /* Literal 31. */ - DW_OP_reg0 = 0x50, /* Register 0. */ - DW_OP_reg1 = 0x51, /* Register 1. */ - DW_OP_reg2 = 0x52, /* Register 2. */ - DW_OP_reg3 = 0x53, /* Register 3. */ - DW_OP_reg4 = 0x54, /* Register 4. */ - DW_OP_reg5 = 0x55, /* Register 5. */ - DW_OP_reg6 = 0x56, /* Register 6. */ - DW_OP_reg7 = 0x57, /* Register 7. */ - DW_OP_reg8 = 0x58, /* Register 8. */ - DW_OP_reg9 = 0x59, /* Register 9. */ - DW_OP_reg10 = 0x5a, /* Register 10. */ - DW_OP_reg11 = 0x5b, /* Register 11. */ - DW_OP_reg12 = 0x5c, /* Register 12. */ - DW_OP_reg13 = 0x5d, /* Register 13. */ - DW_OP_reg14 = 0x5e, /* Register 14. */ - DW_OP_reg15 = 0x5f, /* Register 15. */ - DW_OP_reg16 = 0x60, /* Register 16. */ - DW_OP_reg17 = 0x61, /* Register 17. */ - DW_OP_reg18 = 0x62, /* Register 18. */ - DW_OP_reg19 = 0x63, /* Register 19. */ - DW_OP_reg20 = 0x64, /* Register 20. */ - DW_OP_reg21 = 0x65, /* Register 21. */ - DW_OP_reg22 = 0x66, /* Register 22. */ - DW_OP_reg23 = 0x67, /* Register 24. */ - DW_OP_reg24 = 0x68, /* Register 24. */ - DW_OP_reg25 = 0x69, /* Register 25. */ - DW_OP_reg26 = 0x6a, /* Register 26. */ - DW_OP_reg27 = 0x6b, /* Register 27. */ - DW_OP_reg28 = 0x6c, /* Register 28. */ - DW_OP_reg29 = 0x6d, /* Register 29. */ - DW_OP_reg30 = 0x6e, /* Register 30. */ - DW_OP_reg31 = 0x6f, /* Register 31. */ - DW_OP_breg0 = 0x70, /* Base register 0. */ - DW_OP_breg1 = 0x71, /* Base register 1. */ - DW_OP_breg2 = 0x72, /* Base register 2. */ - DW_OP_breg3 = 0x73, /* Base register 3. */ - DW_OP_breg4 = 0x74, /* Base register 4. */ - DW_OP_breg5 = 0x75, /* Base register 5. */ - DW_OP_breg6 = 0x76, /* Base register 6. */ - DW_OP_breg7 = 0x77, /* Base register 7. */ - DW_OP_breg8 = 0x78, /* Base register 8. */ - DW_OP_breg9 = 0x79, /* Base register 9. */ - DW_OP_breg10 = 0x7a, /* Base register 10. */ - DW_OP_breg11 = 0x7b, /* Base register 11. */ - DW_OP_breg12 = 0x7c, /* Base register 12. */ - DW_OP_breg13 = 0x7d, /* Base register 13. */ - DW_OP_breg14 = 0x7e, /* Base register 14. */ - DW_OP_breg15 = 0x7f, /* Base register 15. */ - DW_OP_breg16 = 0x80, /* Base register 16. */ - DW_OP_breg17 = 0x81, /* Base register 17. */ - DW_OP_breg18 = 0x82, /* Base register 18. */ - DW_OP_breg19 = 0x83, /* Base register 19. */ - DW_OP_breg20 = 0x84, /* Base register 20. */ - DW_OP_breg21 = 0x85, /* Base register 21. */ - DW_OP_breg22 = 0x86, /* Base register 22. */ - DW_OP_breg23 = 0x87, /* Base register 23. */ - DW_OP_breg24 = 0x88, /* Base register 24. */ - DW_OP_breg25 = 0x89, /* Base register 25. */ - DW_OP_breg26 = 0x8a, /* Base register 26. */ - DW_OP_breg27 = 0x8b, /* Base register 27. */ - DW_OP_breg28 = 0x8c, /* Base register 28. */ - DW_OP_breg29 = 0x8d, /* Base register 29. */ - DW_OP_breg30 = 0x8e, /* Base register 30. */ - DW_OP_breg31 = 0x8f, /* Base register 31. */ - DW_OP_regx = 0x90, /* Unsigned LEB128 register. */ - DW_OP_fbreg = 0x91, /* Signed LEB128 offset. */ - DW_OP_bregx = 0x92, /* ULEB128 register followed by SLEB128 off. */ - DW_OP_piece = 0x93, /* ULEB128 size of piece addressed. */ - DW_OP_deref_size = 0x94, /* 1-byte size of data retrieved. */ - DW_OP_xderef_size = 0x95, /* 1-byte size of data retrieved. */ - DW_OP_nop = 0x96, - DW_OP_push_object_address = 0x97, - DW_OP_call2 = 0x98, - DW_OP_call4 = 0x99, - DW_OP_call_ref = 0x9a, - DW_OP_form_tls_address = 0x9b,/* TLS offset to address in current thread */ - DW_OP_call_frame_cfa = 0x9c,/* CFA as determined by CFI. */ - DW_OP_bit_piece = 0x9d, /* ULEB128 size and ULEB128 offset in bits. */ - DW_OP_implicit_value = 0x9e, /* DW_FORM_block follows opcode. */ - DW_OP_stack_value = 0x9f, /* No operands, special like DW_OP_piece. */ +enum { + DW_OP_addr = 0x03, /* Constant address. */ + DW_OP_deref = 0x06, + DW_OP_const1u = 0x08, /* Unsigned 1-byte constant. */ + DW_OP_const1s = 0x09, /* Signed 1-byte constant. */ + DW_OP_const2u = 0x0a, /* Unsigned 2-byte constant. */ + DW_OP_const2s = 0x0b, /* Signed 2-byte constant. */ + DW_OP_const4u = 0x0c, /* Unsigned 4-byte constant. */ + DW_OP_const4s = 0x0d, /* Signed 4-byte constant. */ + DW_OP_const8u = 0x0e, /* Unsigned 8-byte constant. */ + DW_OP_const8s = 0x0f, /* Signed 8-byte constant. */ + DW_OP_constu = 0x10, /* Unsigned LEB128 constant. */ + DW_OP_consts = 0x11, /* Signed LEB128 constant. */ + DW_OP_dup = 0x12, + DW_OP_drop = 0x13, + DW_OP_over = 0x14, + DW_OP_pick = 0x15, /* 1-byte stack index. */ + DW_OP_swap = 0x16, + DW_OP_rot = 0x17, + DW_OP_xderef = 0x18, + DW_OP_abs = 0x19, + DW_OP_and = 0x1a, + DW_OP_div = 0x1b, + DW_OP_minus = 0x1c, + DW_OP_mod = 0x1d, + DW_OP_mul = 0x1e, + DW_OP_neg = 0x1f, + DW_OP_not = 0x20, + DW_OP_or = 0x21, + DW_OP_plus = 0x22, + DW_OP_plus_uconst = 0x23, /* Unsigned LEB128 addend. */ + DW_OP_shl = 0x24, + DW_OP_shr = 0x25, + DW_OP_shra = 0x26, + DW_OP_xor = 0x27, + DW_OP_bra = 0x28, /* Signed 2-byte constant. */ + DW_OP_eq = 0x29, + DW_OP_ge = 0x2a, + DW_OP_gt = 0x2b, + DW_OP_le = 0x2c, + DW_OP_lt = 0x2d, + DW_OP_ne = 0x2e, + DW_OP_skip = 0x2f, /* Signed 2-byte constant. */ + DW_OP_lit0 = 0x30, /* Literal 0. */ + DW_OP_lit1 = 0x31, /* Literal 1. */ + DW_OP_lit2 = 0x32, /* Literal 2. */ + DW_OP_lit3 = 0x33, /* Literal 3. */ + DW_OP_lit4 = 0x34, /* Literal 4. */ + DW_OP_lit5 = 0x35, /* Literal 5. */ + DW_OP_lit6 = 0x36, /* Literal 6. */ + DW_OP_lit7 = 0x37, /* Literal 7. */ + DW_OP_lit8 = 0x38, /* Literal 8. */ + DW_OP_lit9 = 0x39, /* Literal 9. */ + DW_OP_lit10 = 0x3a, /* Literal 10. */ + DW_OP_lit11 = 0x3b, /* Literal 11. */ + DW_OP_lit12 = 0x3c, /* Literal 12. */ + DW_OP_lit13 = 0x3d, /* Literal 13. */ + DW_OP_lit14 = 0x3e, /* Literal 14. */ + DW_OP_lit15 = 0x3f, /* Literal 15. */ + DW_OP_lit16 = 0x40, /* Literal 16. */ + DW_OP_lit17 = 0x41, /* Literal 17. */ + DW_OP_lit18 = 0x42, /* Literal 18. */ + DW_OP_lit19 = 0x43, /* Literal 19. */ + DW_OP_lit20 = 0x44, /* Literal 20. */ + DW_OP_lit21 = 0x45, /* Literal 21. */ + DW_OP_lit22 = 0x46, /* Literal 22. */ + DW_OP_lit23 = 0x47, /* Literal 23. */ + DW_OP_lit24 = 0x48, /* Literal 24. */ + DW_OP_lit25 = 0x49, /* Literal 25. */ + DW_OP_lit26 = 0x4a, /* Literal 26. */ + DW_OP_lit27 = 0x4b, /* Literal 27. */ + DW_OP_lit28 = 0x4c, /* Literal 28. */ + DW_OP_lit29 = 0x4d, /* Literal 29. */ + DW_OP_lit30 = 0x4e, /* Literal 30. */ + DW_OP_lit31 = 0x4f, /* Literal 31. */ + DW_OP_reg0 = 0x50, /* Register 0. */ + DW_OP_reg1 = 0x51, /* Register 1. */ + DW_OP_reg2 = 0x52, /* Register 2. */ + DW_OP_reg3 = 0x53, /* Register 3. */ + DW_OP_reg4 = 0x54, /* Register 4. */ + DW_OP_reg5 = 0x55, /* Register 5. */ + DW_OP_reg6 = 0x56, /* Register 6. */ + DW_OP_reg7 = 0x57, /* Register 7. */ + DW_OP_reg8 = 0x58, /* Register 8. */ + DW_OP_reg9 = 0x59, /* Register 9. */ + DW_OP_reg10 = 0x5a, /* Register 10. */ + DW_OP_reg11 = 0x5b, /* Register 11. */ + DW_OP_reg12 = 0x5c, /* Register 12. */ + DW_OP_reg13 = 0x5d, /* Register 13. */ + DW_OP_reg14 = 0x5e, /* Register 14. */ + DW_OP_reg15 = 0x5f, /* Register 15. */ + DW_OP_reg16 = 0x60, /* Register 16. */ + DW_OP_reg17 = 0x61, /* Register 17. */ + DW_OP_reg18 = 0x62, /* Register 18. */ + DW_OP_reg19 = 0x63, /* Register 19. */ + DW_OP_reg20 = 0x64, /* Register 20. */ + DW_OP_reg21 = 0x65, /* Register 21. */ + DW_OP_reg22 = 0x66, /* Register 22. */ + DW_OP_reg23 = 0x67, /* Register 24. */ + DW_OP_reg24 = 0x68, /* Register 24. */ + DW_OP_reg25 = 0x69, /* Register 25. */ + DW_OP_reg26 = 0x6a, /* Register 26. */ + DW_OP_reg27 = 0x6b, /* Register 27. */ + DW_OP_reg28 = 0x6c, /* Register 28. */ + DW_OP_reg29 = 0x6d, /* Register 29. */ + DW_OP_reg30 = 0x6e, /* Register 30. */ + DW_OP_reg31 = 0x6f, /* Register 31. */ + DW_OP_breg0 = 0x70, /* Base register 0. */ + DW_OP_breg1 = 0x71, /* Base register 1. */ + DW_OP_breg2 = 0x72, /* Base register 2. */ + DW_OP_breg3 = 0x73, /* Base register 3. */ + DW_OP_breg4 = 0x74, /* Base register 4. */ + DW_OP_breg5 = 0x75, /* Base register 5. */ + DW_OP_breg6 = 0x76, /* Base register 6. */ + DW_OP_breg7 = 0x77, /* Base register 7. */ + DW_OP_breg8 = 0x78, /* Base register 8. */ + DW_OP_breg9 = 0x79, /* Base register 9. */ + DW_OP_breg10 = 0x7a, /* Base register 10. */ + DW_OP_breg11 = 0x7b, /* Base register 11. */ + DW_OP_breg12 = 0x7c, /* Base register 12. */ + DW_OP_breg13 = 0x7d, /* Base register 13. */ + DW_OP_breg14 = 0x7e, /* Base register 14. */ + DW_OP_breg15 = 0x7f, /* Base register 15. */ + DW_OP_breg16 = 0x80, /* Base register 16. */ + DW_OP_breg17 = 0x81, /* Base register 17. */ + DW_OP_breg18 = 0x82, /* Base register 18. */ + DW_OP_breg19 = 0x83, /* Base register 19. */ + DW_OP_breg20 = 0x84, /* Base register 20. */ + DW_OP_breg21 = 0x85, /* Base register 21. */ + DW_OP_breg22 = 0x86, /* Base register 22. */ + DW_OP_breg23 = 0x87, /* Base register 23. */ + DW_OP_breg24 = 0x88, /* Base register 24. */ + DW_OP_breg25 = 0x89, /* Base register 25. */ + DW_OP_breg26 = 0x8a, /* Base register 26. */ + DW_OP_breg27 = 0x8b, /* Base register 27. */ + DW_OP_breg28 = 0x8c, /* Base register 28. */ + DW_OP_breg29 = 0x8d, /* Base register 29. */ + DW_OP_breg30 = 0x8e, /* Base register 30. */ + DW_OP_breg31 = 0x8f, /* Base register 31. */ + DW_OP_regx = 0x90, /* Unsigned LEB128 register. */ + DW_OP_fbreg = 0x91, /* Signed LEB128 offset. */ + DW_OP_bregx = 0x92, /* ULEB128 register followed by SLEB128 off. */ + DW_OP_piece = 0x93, /* ULEB128 size of piece addressed. */ + DW_OP_deref_size = 0x94, /* 1-byte size of data retrieved. */ + DW_OP_xderef_size = 0x95, /* 1-byte size of data retrieved. */ + DW_OP_nop = 0x96, + DW_OP_push_object_address = 0x97, + DW_OP_call2 = 0x98, + DW_OP_call4 = 0x99, + DW_OP_call_ref = 0x9a, + DW_OP_form_tls_address = 0x9b, /* TLS offset to address in current thread */ + DW_OP_call_frame_cfa = 0x9c, /* CFA as determined by CFI. */ + DW_OP_bit_piece = 0x9d, /* ULEB128 size and ULEB128 offset in bits. */ + DW_OP_implicit_value = 0x9e, /* DW_FORM_block follows opcode. */ + DW_OP_stack_value = 0x9f, /* No operands, special like DW_OP_piece. */ - DW_OP_implicit_pointer = 0xa0, - DW_OP_addrx = 0xa1, - DW_OP_constx = 0xa2, - DW_OP_entry_value = 0xa3, - DW_OP_const_type = 0xa4, - DW_OP_regval_type = 0xa5, - DW_OP_deref_type = 0xa6, - DW_OP_xderef_type = 0xa7, - DW_OP_convert = 0xa8, - DW_OP_reinterpret = 0xa9, + DW_OP_implicit_pointer = 0xa0, + DW_OP_addrx = 0xa1, + DW_OP_constx = 0xa2, + DW_OP_entry_value = 0xa3, + DW_OP_const_type = 0xa4, + DW_OP_regval_type = 0xa5, + DW_OP_deref_type = 0xa6, + DW_OP_xderef_type = 0xa7, + DW_OP_convert = 0xa8, + DW_OP_reinterpret = 0xa9, - /* GNU extensions. */ - DW_OP_GNU_push_tls_address = 0xe0, - DW_OP_GNU_uninit = 0xf0, - DW_OP_GNU_encoded_addr = 0xf1, - DW_OP_GNU_implicit_pointer = 0xf2, - DW_OP_GNU_entry_value = 0xf3, - DW_OP_GNU_const_type = 0xf4, - DW_OP_GNU_regval_type = 0xf5, - DW_OP_GNU_deref_type = 0xf6, - DW_OP_GNU_convert = 0xf7, - DW_OP_GNU_reinterpret = 0xf9, - DW_OP_GNU_parameter_ref = 0xfa, + /* GNU extensions. */ + DW_OP_GNU_push_tls_address = 0xe0, + DW_OP_GNU_uninit = 0xf0, + DW_OP_GNU_encoded_addr = 0xf1, + DW_OP_GNU_implicit_pointer = 0xf2, + DW_OP_GNU_entry_value = 0xf3, + DW_OP_GNU_const_type = 0xf4, + DW_OP_GNU_regval_type = 0xf5, + DW_OP_GNU_deref_type = 0xf6, + DW_OP_GNU_convert = 0xf7, + DW_OP_GNU_reinterpret = 0xf9, + DW_OP_GNU_parameter_ref = 0xfa, - /* GNU Debug Fission extensions. */ - DW_OP_GNU_addr_index = 0xfb, - DW_OP_GNU_const_index = 0xfc, + /* GNU Debug Fission extensions. */ + DW_OP_GNU_addr_index = 0xfb, + DW_OP_GNU_const_index = 0xfc, - DW_OP_GNU_variable_value = 0xfd, - - DW_OP_lo_user = 0xe0, /* Implementation-defined range start. */ - DW_OP_hi_user = 0xff /* Implementation-defined range end. */ - }; + DW_OP_GNU_variable_value = 0xfd, + DW_OP_lo_user = 0xe0, /* Implementation-defined range start. */ + DW_OP_hi_user = 0xff /* Implementation-defined range end. */ +}; /* DWARF base type encodings. */ -enum - { - DW_ATE_void = 0x0, - DW_ATE_address = 0x1, - DW_ATE_boolean = 0x2, - DW_ATE_complex_float = 0x3, - DW_ATE_float = 0x4, - DW_ATE_signed = 0x5, - DW_ATE_signed_char = 0x6, - DW_ATE_unsigned = 0x7, - DW_ATE_unsigned_char = 0x8, - DW_ATE_imaginary_float = 0x9, - DW_ATE_packed_decimal = 0xa, - DW_ATE_numeric_string = 0xb, - DW_ATE_edited = 0xc, - DW_ATE_signed_fixed = 0xd, - DW_ATE_unsigned_fixed = 0xe, - DW_ATE_decimal_float = 0xf, - DW_ATE_UTF = 0x10, - DW_ATE_UCS = 0x11, - DW_ATE_ASCII = 0x12, - - DW_ATE_lo_user = 0x80, - DW_ATE_hi_user = 0xff - }; +enum { + DW_ATE_void = 0x0, + DW_ATE_address = 0x1, + DW_ATE_boolean = 0x2, + DW_ATE_complex_float = 0x3, + DW_ATE_float = 0x4, + DW_ATE_signed = 0x5, + DW_ATE_signed_char = 0x6, + DW_ATE_unsigned = 0x7, + DW_ATE_unsigned_char = 0x8, + DW_ATE_imaginary_float = 0x9, + DW_ATE_packed_decimal = 0xa, + DW_ATE_numeric_string = 0xb, + DW_ATE_edited = 0xc, + DW_ATE_signed_fixed = 0xd, + DW_ATE_unsigned_fixed = 0xe, + DW_ATE_decimal_float = 0xf, + DW_ATE_UTF = 0x10, + DW_ATE_UCS = 0x11, + DW_ATE_ASCII = 0x12, + DW_ATE_lo_user = 0x80, + DW_ATE_hi_user = 0xff +}; /* DWARF decimal sign encodings. */ -enum - { - DW_DS_unsigned = 1, - DW_DS_leading_overpunch = 2, - DW_DS_trailing_overpunch = 3, - DW_DS_leading_separate = 4, - DW_DS_trailing_separate = 5, - }; - +enum { + DW_DS_unsigned = 1, + DW_DS_leading_overpunch = 2, + DW_DS_trailing_overpunch = 3, + DW_DS_leading_separate = 4, + DW_DS_trailing_separate = 5, +}; /* DWARF endianity encodings. */ -enum - { - DW_END_default = 0, - DW_END_big = 1, - DW_END_little = 2, - - DW_END_lo_user = 0x40, - DW_END_hi_user = 0xff - }; +enum { + DW_END_default = 0, + DW_END_big = 1, + DW_END_little = 2, + DW_END_lo_user = 0x40, + DW_END_hi_user = 0xff +}; /* DWARF accessibility encodings. */ -enum - { - DW_ACCESS_public = 1, - DW_ACCESS_protected = 2, - DW_ACCESS_private = 3 - }; - +enum { DW_ACCESS_public = 1, DW_ACCESS_protected = 2, DW_ACCESS_private = 3 }; /* DWARF visibility encodings. */ -enum - { - DW_VIS_local = 1, - DW_VIS_exported = 2, - DW_VIS_qualified = 3 - }; - +enum { DW_VIS_local = 1, DW_VIS_exported = 2, DW_VIS_qualified = 3 }; /* DWARF virtuality encodings. */ -enum - { - DW_VIRTUALITY_none = 0, - DW_VIRTUALITY_virtual = 1, - DW_VIRTUALITY_pure_virtual = 2 - }; - +enum { + DW_VIRTUALITY_none = 0, + DW_VIRTUALITY_virtual = 1, + DW_VIRTUALITY_pure_virtual = 2 +}; /* DWARF language encodings. */ -enum - { - DW_LANG_C89 = 0x0001, /* ISO C:1989 */ - DW_LANG_C = 0x0002, /* C */ - DW_LANG_Ada83 = 0x0003, /* ISO Ada:1983 */ - DW_LANG_C_plus_plus = 0x0004, /* ISO C++:1998 */ - DW_LANG_Cobol74 = 0x0005, /* ISO Cobol:1974 */ - DW_LANG_Cobol85 = 0x0006, /* ISO Cobol:1985 */ - DW_LANG_Fortran77 = 0x0007, /* ISO FORTRAN 77 */ - DW_LANG_Fortran90 = 0x0008, /* ISO Fortran 90 */ - DW_LANG_Pascal83 = 0x0009, /* ISO Pascal:1983 */ - DW_LANG_Modula2 = 0x000a, /* ISO Modula-2:1996 */ - DW_LANG_Java = 0x000b, /* Java */ - DW_LANG_C99 = 0x000c, /* ISO C:1999 */ - DW_LANG_Ada95 = 0x000d, /* ISO Ada:1995 */ - DW_LANG_Fortran95 = 0x000e, /* ISO Fortran 95 */ - DW_LANG_PLI = 0x000f, /* ISO PL/1:1976 */ - DW_LANG_ObjC = 0x0010, /* Objective-C */ - DW_LANG_ObjC_plus_plus = 0x0011, /* Objective-C++ */ - DW_LANG_UPC = 0x0012, /* Unified Parallel C */ - DW_LANG_D = 0x0013, /* D */ - DW_LANG_Python = 0x0014, /* Python */ - DW_LANG_OpenCL = 0x0015, /* OpenCL */ - DW_LANG_Go = 0x0016, /* Go */ - DW_LANG_Modula3 = 0x0017, /* Modula-3 */ - DW_LANG_Haskell = 0x0018, /* Haskell */ - DW_LANG_C_plus_plus_03 = 0x0019, /* ISO C++:2003 */ - DW_LANG_C_plus_plus_11 = 0x001a, /* ISO C++:2011 */ - DW_LANG_OCaml = 0x001b, /* OCaml */ - DW_LANG_Rust = 0x001c, /* Rust */ - DW_LANG_C11 = 0x001d, /* ISO C:2011 */ - DW_LANG_Swift = 0x001e, /* Swift */ - DW_LANG_Julia = 0x001f, /* Julia */ - DW_LANG_Dylan = 0x0020, /* Dylan */ - DW_LANG_C_plus_plus_14 = 0x0021, /* ISO C++:2014 */ - DW_LANG_Fortran03 = 0x0022, /* ISO/IEC 1539-1:2004 */ - DW_LANG_Fortran08 = 0x0023, /* ISO/IEC 1539-1:2010 */ - DW_LANG_RenderScript = 0x0024, /* RenderScript Kernal Language */ - DW_LANG_BLISS = 0x0025, /* BLISS */ +enum { + DW_LANG_C89 = 0x0001, /* ISO C:1989 */ + DW_LANG_C = 0x0002, /* C */ + DW_LANG_Ada83 = 0x0003, /* ISO Ada:1983 */ + DW_LANG_C_plus_plus = 0x0004, /* ISO C++:1998 */ + DW_LANG_Cobol74 = 0x0005, /* ISO Cobol:1974 */ + DW_LANG_Cobol85 = 0x0006, /* ISO Cobol:1985 */ + DW_LANG_Fortran77 = 0x0007, /* ISO FORTRAN 77 */ + DW_LANG_Fortran90 = 0x0008, /* ISO Fortran 90 */ + DW_LANG_Pascal83 = 0x0009, /* ISO Pascal:1983 */ + DW_LANG_Modula2 = 0x000a, /* ISO Modula-2:1996 */ + DW_LANG_Java = 0x000b, /* Java */ + DW_LANG_C99 = 0x000c, /* ISO C:1999 */ + DW_LANG_Ada95 = 0x000d, /* ISO Ada:1995 */ + DW_LANG_Fortran95 = 0x000e, /* ISO Fortran 95 */ + DW_LANG_PLI = 0x000f, /* ISO PL/1:1976 */ + DW_LANG_ObjC = 0x0010, /* Objective-C */ + DW_LANG_ObjC_plus_plus = 0x0011, /* Objective-C++ */ + DW_LANG_UPC = 0x0012, /* Unified Parallel C */ + DW_LANG_D = 0x0013, /* D */ + DW_LANG_Python = 0x0014, /* Python */ + DW_LANG_OpenCL = 0x0015, /* OpenCL */ + DW_LANG_Go = 0x0016, /* Go */ + DW_LANG_Modula3 = 0x0017, /* Modula-3 */ + DW_LANG_Haskell = 0x0018, /* Haskell */ + DW_LANG_C_plus_plus_03 = 0x0019, /* ISO C++:2003 */ + DW_LANG_C_plus_plus_11 = 0x001a, /* ISO C++:2011 */ + DW_LANG_OCaml = 0x001b, /* OCaml */ + DW_LANG_Rust = 0x001c, /* Rust */ + DW_LANG_C11 = 0x001d, /* ISO C:2011 */ + DW_LANG_Swift = 0x001e, /* Swift */ + DW_LANG_Julia = 0x001f, /* Julia */ + DW_LANG_Dylan = 0x0020, /* Dylan */ + DW_LANG_C_plus_plus_14 = 0x0021, /* ISO C++:2014 */ + DW_LANG_Fortran03 = 0x0022, /* ISO/IEC 1539-1:2004 */ + DW_LANG_Fortran08 = 0x0023, /* ISO/IEC 1539-1:2010 */ + DW_LANG_RenderScript = 0x0024, /* RenderScript Kernal Language */ + DW_LANG_BLISS = 0x0025, /* BLISS */ - DW_LANG_lo_user = 0x8000, - DW_LANG_Mips_Assembler = 0x8001, /* Assembler */ - DW_LANG_hi_user = 0xffff - }; + DW_LANG_lo_user = 0x8000, + DW_LANG_Mips_Assembler = 0x8001, /* Assembler */ + DW_LANG_hi_user = 0xffff +}; /* Old (typo) '1' != 'I'. */ #define DW_LANG_PL1 DW_LANG_PLI /* DWARF identifier case encodings. */ -enum - { - DW_ID_case_sensitive = 0, - DW_ID_up_case = 1, - DW_ID_down_case = 2, - DW_ID_case_insensitive = 3 - }; - +enum { + DW_ID_case_sensitive = 0, + DW_ID_up_case = 1, + DW_ID_down_case = 2, + DW_ID_case_insensitive = 3 +}; /* DWARF calling conventions encodings. Used as values of DW_AT_calling_convention for subroutines (normal, program or nocall) or structures, unions and class types (normal, reference or value). */ -enum - { - DW_CC_normal = 0x1, - DW_CC_program = 0x2, - DW_CC_nocall = 0x3, - DW_CC_pass_by_reference = 0x4, - DW_CC_pass_by_value = 0x5, - DW_CC_lo_user = 0x40, - DW_CC_hi_user = 0xff - }; - +enum { + DW_CC_normal = 0x1, + DW_CC_program = 0x2, + DW_CC_nocall = 0x3, + DW_CC_pass_by_reference = 0x4, + DW_CC_pass_by_value = 0x5, + DW_CC_lo_user = 0x40, + DW_CC_hi_user = 0xff +}; /* DWARF inline encodings. */ -enum - { - DW_INL_not_inlined = 0, - DW_INL_inlined = 1, - DW_INL_declared_not_inlined = 2, - DW_INL_declared_inlined = 3 - }; - +enum { + DW_INL_not_inlined = 0, + DW_INL_inlined = 1, + DW_INL_declared_not_inlined = 2, + DW_INL_declared_inlined = 3 +}; /* DWARF ordering encodings. */ -enum - { - DW_ORD_row_major = 0, - DW_ORD_col_major = 1 - }; - +enum { DW_ORD_row_major = 0, DW_ORD_col_major = 1 }; /* DWARF discriminant descriptor encodings. */ -enum - { - DW_DSC_label = 0, - DW_DSC_range = 1 - }; +enum { DW_DSC_label = 0, DW_DSC_range = 1 }; /* DWARF defaulted member function encodings. */ -enum - { - DW_DEFAULTED_no = 0, - DW_DEFAULTED_in_class = 1, - DW_DEFAULTED_out_of_class = 2 - }; +enum { + DW_DEFAULTED_no = 0, + DW_DEFAULTED_in_class = 1, + DW_DEFAULTED_out_of_class = 2 +}; /* DWARF line content descriptions. */ -enum - { - DW_LNCT_path = 0x1, - DW_LNCT_directory_index = 0x2, - DW_LNCT_timestamp = 0x3, - DW_LNCT_size = 0x4, - DW_LNCT_MD5 = 0x5, - DW_LNCT_lo_user = 0x2000, - DW_LNCT_hi_user = 0x3fff - }; +enum { + DW_LNCT_path = 0x1, + DW_LNCT_directory_index = 0x2, + DW_LNCT_timestamp = 0x3, + DW_LNCT_size = 0x4, + DW_LNCT_MD5 = 0x5, + DW_LNCT_lo_user = 0x2000, + DW_LNCT_hi_user = 0x3fff +}; /* DWARF standard opcode encodings. */ -enum - { - DW_LNS_copy = 1, - DW_LNS_advance_pc = 2, - DW_LNS_advance_line = 3, - DW_LNS_set_file = 4, - DW_LNS_set_column = 5, - DW_LNS_negate_stmt = 6, - DW_LNS_set_basic_block = 7, - DW_LNS_const_add_pc = 8, - DW_LNS_fixed_advance_pc = 9, - DW_LNS_set_prologue_end = 10, - DW_LNS_set_epilogue_begin = 11, - DW_LNS_set_isa = 12 - }; - +enum { + DW_LNS_copy = 1, + DW_LNS_advance_pc = 2, + DW_LNS_advance_line = 3, + DW_LNS_set_file = 4, + DW_LNS_set_column = 5, + DW_LNS_negate_stmt = 6, + DW_LNS_set_basic_block = 7, + DW_LNS_const_add_pc = 8, + DW_LNS_fixed_advance_pc = 9, + DW_LNS_set_prologue_end = 10, + DW_LNS_set_epilogue_begin = 11, + DW_LNS_set_isa = 12 +}; /* DWARF extended opcode encodings. */ -enum - { - DW_LNE_end_sequence = 1, - DW_LNE_set_address = 2, - DW_LNE_define_file = 3, - DW_LNE_set_discriminator = 4, +enum { + DW_LNE_end_sequence = 1, + DW_LNE_set_address = 2, + DW_LNE_define_file = 3, + DW_LNE_set_discriminator = 4, - DW_LNE_lo_user = 128, + DW_LNE_lo_user = 128, - DW_LNE_NVIDIA_inlined_call = 144, - DW_LNE_NVIDIA_set_function_name = 145, - - DW_LNE_hi_user = 255 - }; + DW_LNE_NVIDIA_inlined_call = 144, + DW_LNE_NVIDIA_set_function_name = 145, + DW_LNE_hi_user = 255 +}; /* DWARF macinfo type encodings. */ -enum - { - DW_MACINFO_define = 1, - DW_MACINFO_undef = 2, - DW_MACINFO_start_file = 3, - DW_MACINFO_end_file = 4, - DW_MACINFO_vendor_ext = 255 - }; - +enum { + DW_MACINFO_define = 1, + DW_MACINFO_undef = 2, + DW_MACINFO_start_file = 3, + DW_MACINFO_end_file = 4, + DW_MACINFO_vendor_ext = 255 +}; /* DWARF debug_macro type encodings. */ -enum - { - DW_MACRO_define = 0x01, - DW_MACRO_undef = 0x02, - DW_MACRO_start_file = 0x03, - DW_MACRO_end_file = 0x04, - DW_MACRO_define_strp = 0x05, - DW_MACRO_undef_strp = 0x06, - DW_MACRO_import = 0x07, - DW_MACRO_define_sup = 0x08, - DW_MACRO_undef_sup = 0x09, - DW_MACRO_import_sup = 0x0a, - DW_MACRO_define_strx = 0x0b, - DW_MACRO_undef_strx = 0x0c, - DW_MACRO_lo_user = 0xe0, - DW_MACRO_hi_user = 0xff - }; +enum { + DW_MACRO_define = 0x01, + DW_MACRO_undef = 0x02, + DW_MACRO_start_file = 0x03, + DW_MACRO_end_file = 0x04, + DW_MACRO_define_strp = 0x05, + DW_MACRO_undef_strp = 0x06, + DW_MACRO_import = 0x07, + DW_MACRO_define_sup = 0x08, + DW_MACRO_undef_sup = 0x09, + DW_MACRO_import_sup = 0x0a, + DW_MACRO_define_strx = 0x0b, + DW_MACRO_undef_strx = 0x0c, + DW_MACRO_lo_user = 0xe0, + DW_MACRO_hi_user = 0xff +}; /* Old GNU extension names for DWARF5 debug_macro type encodings. There are no equivalents for the supplementary object file (sup) and indirect string references (strx). */ -#define DW_MACRO_GNU_define DW_MACRO_define -#define DW_MACRO_GNU_undef DW_MACRO_undef -#define DW_MACRO_GNU_start_file DW_MACRO_start_file -#define DW_MACRO_GNU_end_file DW_MACRO_end_file -#define DW_MACRO_GNU_define_indirect DW_MACRO_define_strp -#define DW_MACRO_GNU_undef_indirect DW_MACRO_undef_strp +#define DW_MACRO_GNU_define DW_MACRO_define +#define DW_MACRO_GNU_undef DW_MACRO_undef +#define DW_MACRO_GNU_start_file DW_MACRO_start_file +#define DW_MACRO_GNU_end_file DW_MACRO_end_file +#define DW_MACRO_GNU_define_indirect DW_MACRO_define_strp +#define DW_MACRO_GNU_undef_indirect DW_MACRO_undef_strp #define DW_MACRO_GNU_transparent_include DW_MACRO_import -#define DW_MACRO_GNU_lo_user DW_MACRO_lo_user -#define DW_MACRO_GNU_hi_user DW_MACRO_hi_user - +#define DW_MACRO_GNU_lo_user DW_MACRO_lo_user +#define DW_MACRO_GNU_hi_user DW_MACRO_hi_user /* Range list entry encoding. */ -enum - { - DW_RLE_end_of_list = 0x0, - DW_RLE_base_addressx = 0x1, - DW_RLE_startx_endx = 0x2, - DW_RLE_startx_length = 0x3, - DW_RLE_offset_pair = 0x4, - DW_RLE_base_address = 0x5, - DW_RLE_start_end = 0x6, - DW_RLE_start_length = 0x7 - }; - +enum { + DW_RLE_end_of_list = 0x0, + DW_RLE_base_addressx = 0x1, + DW_RLE_startx_endx = 0x2, + DW_RLE_startx_length = 0x3, + DW_RLE_offset_pair = 0x4, + DW_RLE_base_address = 0x5, + DW_RLE_start_end = 0x6, + DW_RLE_start_length = 0x7 +}; /* Location list entry encoding. */ -enum - { - DW_LLE_end_of_list = 0x0, - DW_LLE_base_addressx = 0x1, - DW_LLE_startx_endx = 0x2, - DW_LLE_startx_length = 0x3, - DW_LLE_offset_pair = 0x4, - DW_LLE_default_location = 0x5, - DW_LLE_base_address = 0x6, - DW_LLE_start_end = 0x7, - DW_LLE_start_length = 0x8 - }; - +enum { + DW_LLE_end_of_list = 0x0, + DW_LLE_base_addressx = 0x1, + DW_LLE_startx_endx = 0x2, + DW_LLE_startx_length = 0x3, + DW_LLE_offset_pair = 0x4, + DW_LLE_default_location = 0x5, + DW_LLE_base_address = 0x6, + DW_LLE_start_end = 0x7, + DW_LLE_start_length = 0x8 +}; /* GNU DebugFission list entry encodings (.debug_loc.dwo). */ -enum - { - DW_LLE_GNU_end_of_list_entry = 0x0, - DW_LLE_GNU_base_address_selection_entry = 0x1, - DW_LLE_GNU_start_end_entry = 0x2, - DW_LLE_GNU_start_length_entry = 0x3 - }; +enum { + DW_LLE_GNU_end_of_list_entry = 0x0, + DW_LLE_GNU_base_address_selection_entry = 0x1, + DW_LLE_GNU_start_end_entry = 0x2, + DW_LLE_GNU_start_length_entry = 0x3 +}; /* DWARF5 package file section identifiers. */ -enum - { - DW_SECT_INFO = 1, - /* Reserved = 2, */ - DW_SECT_ABBREV = 3, - DW_SECT_LINE = 4, - DW_SECT_LOCLISTS = 5, - DW_SECT_STR_OFFSETS = 6, - DW_SECT_MACRO = 7, - DW_SECT_RNGLISTS = 8, - }; - +enum { + DW_SECT_INFO = 1, + /* Reserved = 2, */ + DW_SECT_ABBREV = 3, + DW_SECT_LINE = 4, + DW_SECT_LOCLISTS = 5, + DW_SECT_STR_OFFSETS = 6, + DW_SECT_MACRO = 7, + DW_SECT_RNGLISTS = 8, +}; /* DWARF call frame instruction encodings. */ -enum - { - DW_CFA_advance_loc = 0x40, - DW_CFA_offset = 0x80, - DW_CFA_restore = 0xc0, - DW_CFA_extended = 0, +enum { + DW_CFA_advance_loc = 0x40, + DW_CFA_offset = 0x80, + DW_CFA_restore = 0xc0, + DW_CFA_extended = 0, - DW_CFA_nop = 0x00, - DW_CFA_set_loc = 0x01, - DW_CFA_advance_loc1 = 0x02, - DW_CFA_advance_loc2 = 0x03, - DW_CFA_advance_loc4 = 0x04, - DW_CFA_offset_extended = 0x05, - DW_CFA_restore_extended = 0x06, - DW_CFA_undefined = 0x07, - DW_CFA_same_value = 0x08, - DW_CFA_register = 0x09, - DW_CFA_remember_state = 0x0a, - DW_CFA_restore_state = 0x0b, - DW_CFA_def_cfa = 0x0c, - DW_CFA_def_cfa_register = 0x0d, - DW_CFA_def_cfa_offset = 0x0e, - DW_CFA_def_cfa_expression = 0x0f, - DW_CFA_expression = 0x10, - DW_CFA_offset_extended_sf = 0x11, - DW_CFA_def_cfa_sf = 0x12, - DW_CFA_def_cfa_offset_sf = 0x13, - DW_CFA_val_offset = 0x14, - DW_CFA_val_offset_sf = 0x15, - DW_CFA_val_expression = 0x16, + DW_CFA_nop = 0x00, + DW_CFA_set_loc = 0x01, + DW_CFA_advance_loc1 = 0x02, + DW_CFA_advance_loc2 = 0x03, + DW_CFA_advance_loc4 = 0x04, + DW_CFA_offset_extended = 0x05, + DW_CFA_restore_extended = 0x06, + DW_CFA_undefined = 0x07, + DW_CFA_same_value = 0x08, + DW_CFA_register = 0x09, + DW_CFA_remember_state = 0x0a, + DW_CFA_restore_state = 0x0b, + DW_CFA_def_cfa = 0x0c, + DW_CFA_def_cfa_register = 0x0d, + DW_CFA_def_cfa_offset = 0x0e, + DW_CFA_def_cfa_expression = 0x0f, + DW_CFA_expression = 0x10, + DW_CFA_offset_extended_sf = 0x11, + DW_CFA_def_cfa_sf = 0x12, + DW_CFA_def_cfa_offset_sf = 0x13, + DW_CFA_val_offset = 0x14, + DW_CFA_val_offset_sf = 0x15, + DW_CFA_val_expression = 0x16, - DW_CFA_low_user = 0x1c, - DW_CFA_MIPS_advance_loc8 = 0x1d, - DW_CFA_GNU_window_save = 0x2d, - DW_CFA_AARCH64_negate_ra_state = 0x2d, - DW_CFA_GNU_args_size = 0x2e, - DW_CFA_GNU_negative_offset_extended = 0x2f, - DW_CFA_high_user = 0x3f - }; + DW_CFA_low_user = 0x1c, + DW_CFA_MIPS_advance_loc8 = 0x1d, + DW_CFA_GNU_window_save = 0x2d, + DW_CFA_AARCH64_negate_ra_state = 0x2d, + DW_CFA_GNU_args_size = 0x2e, + DW_CFA_GNU_negative_offset_extended = 0x2f, + DW_CFA_high_user = 0x3f +}; /* ID indicating CIE as opposed to FDE in .debug_frame. */ -enum - { - DW_CIE_ID_32 = 0xffffffffU, /* In 32-bit format CIE header. */ - DW_CIE_ID_64 = 0xffffffffffffffffULL /* In 64-bit format CIE header. */ - }; - +enum { + DW_CIE_ID_32 = 0xffffffffU, /* In 32-bit format CIE header. */ + DW_CIE_ID_64 = 0xffffffffffffffffULL /* In 64-bit format CIE header. */ +}; /* Information for GNU unwind information. */ -enum - { - DW_EH_PE_absptr = 0x00, - DW_EH_PE_omit = 0xff, +enum { + DW_EH_PE_absptr = 0x00, + DW_EH_PE_omit = 0xff, - /* FDE data encoding. */ - DW_EH_PE_uleb128 = 0x01, - DW_EH_PE_udata2 = 0x02, - DW_EH_PE_udata4 = 0x03, - DW_EH_PE_udata8 = 0x04, - DW_EH_PE_sleb128 = 0x09, - DW_EH_PE_sdata2 = 0x0a, - DW_EH_PE_sdata4 = 0x0b, - DW_EH_PE_sdata8 = 0x0c, - DW_EH_PE_signed = 0x08, + /* FDE data encoding. */ + DW_EH_PE_uleb128 = 0x01, + DW_EH_PE_udata2 = 0x02, + DW_EH_PE_udata4 = 0x03, + DW_EH_PE_udata8 = 0x04, + DW_EH_PE_sleb128 = 0x09, + DW_EH_PE_sdata2 = 0x0a, + DW_EH_PE_sdata4 = 0x0b, + DW_EH_PE_sdata8 = 0x0c, + DW_EH_PE_signed = 0x08, - /* FDE flags. */ - DW_EH_PE_pcrel = 0x10, - DW_EH_PE_textrel = 0x20, - DW_EH_PE_datarel = 0x30, - DW_EH_PE_funcrel = 0x40, - DW_EH_PE_aligned = 0x50, - - DW_EH_PE_indirect = 0x80 - }; + /* FDE flags. */ + DW_EH_PE_pcrel = 0x10, + DW_EH_PE_textrel = 0x20, + DW_EH_PE_datarel = 0x30, + DW_EH_PE_funcrel = 0x40, + DW_EH_PE_aligned = 0x50, + DW_EH_PE_indirect = 0x80 +}; /* DWARF XXX. */ -#define DW_ADDR_none 0 +#define DW_ADDR_none 0 /* Section 7.2.2 of the DWARF3 specification defines a range of escape codes that can appear in the length field of certain DWARF structures. @@ -1041,6 +970,6 @@ enum as 0xffffff00 whereas in fact it should be 0xfffffff0. */ #define DWARF3_LENGTH_MIN_ESCAPE_CODE 0xfffffff0u #define DWARF3_LENGTH_MAX_ESCAPE_CODE 0xffffffffu -#define DWARF3_LENGTH_64_BIT DWARF3_LENGTH_MAX_ESCAPE_CODE +#define DWARF3_LENGTH_64_BIT DWARF3_LENGTH_MAX_ESCAPE_CODE -#endif /* dwarf.h */ +#endif /* dwarf.h */ diff --git a/src/tcc/elf.h b/src/tcc/elf.h index 14cfdcf..984dccf 100644 --- a/src/tcc/elf.h +++ b/src/tcc/elf.h @@ -17,7 +17,7 @@ . */ #ifndef _ELF_H -#define _ELF_H 1 +#define _ELF_H 1 #ifndef _WIN32 #include @@ -28,10 +28,10 @@ typedef signed char int8_t; typedef short int int16_t; typedef int int32_t; typedef long long int int64_t; -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long int uint64_t; +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; #endif #endif @@ -43,15 +43,15 @@ typedef uint16_t Elf64_Half; /* Types for signed and unsigned 32-bit quantities. */ typedef uint32_t Elf32_Word; -typedef int32_t Elf32_Sword; +typedef int32_t Elf32_Sword; typedef uint32_t Elf64_Word; -typedef int32_t Elf64_Sword; +typedef int32_t Elf64_Sword; /* Types for signed and unsigned 64-bit quantities. */ typedef uint64_t Elf32_Xword; -typedef int64_t Elf32_Sxword; +typedef int64_t Elf32_Sxword; typedef uint64_t Elf64_Xword; -typedef int64_t Elf64_Sxword; +typedef int64_t Elf64_Sxword; /* Type of addresses. */ typedef uint32_t Elf32_Addr; @@ -69,451 +69,443 @@ typedef uint16_t Elf64_Section; typedef Elf32_Half Elf32_Versym; typedef Elf64_Half Elf64_Versym; - /* The ELF file header. This appears at the start of every ELF file. */ #define EI_NIDENT (16) -typedef struct -{ - unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ - Elf32_Half e_type; /* Object file type */ - Elf32_Half e_machine; /* Architecture */ - Elf32_Word e_version; /* Object file version */ - Elf32_Addr e_entry; /* Entry point virtual address */ - Elf32_Off e_phoff; /* Program header table file offset */ - Elf32_Off e_shoff; /* Section header table file offset */ - Elf32_Word e_flags; /* Processor-specific flags */ - Elf32_Half e_ehsize; /* ELF header size in bytes */ - Elf32_Half e_phentsize; /* Program header table entry size */ - Elf32_Half e_phnum; /* Program header table entry count */ - Elf32_Half e_shentsize; /* Section header table entry size */ - Elf32_Half e_shnum; /* Section header table entry count */ - Elf32_Half e_shstrndx; /* Section header string table index */ +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ + Elf32_Half e_type; /* Object file type */ + Elf32_Half e_machine; /* Architecture */ + Elf32_Word e_version; /* Object file version */ + Elf32_Addr e_entry; /* Entry point virtual address */ + Elf32_Off e_phoff; /* Program header table file offset */ + Elf32_Off e_shoff; /* Section header table file offset */ + Elf32_Word e_flags; /* Processor-specific flags */ + Elf32_Half e_ehsize; /* ELF header size in bytes */ + Elf32_Half e_phentsize; /* Program header table entry size */ + Elf32_Half e_phnum; /* Program header table entry count */ + Elf32_Half e_shentsize; /* Section header table entry size */ + Elf32_Half e_shnum; /* Section header table entry count */ + Elf32_Half e_shstrndx; /* Section header string table index */ } Elf32_Ehdr; -typedef struct -{ - unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ - Elf64_Half e_type; /* Object file type */ - Elf64_Half e_machine; /* Architecture */ - Elf64_Word e_version; /* Object file version */ - Elf64_Addr e_entry; /* Entry point virtual address */ - Elf64_Off e_phoff; /* Program header table file offset */ - Elf64_Off e_shoff; /* Section header table file offset */ - Elf64_Word e_flags; /* Processor-specific flags */ - Elf64_Half e_ehsize; /* ELF header size in bytes */ - Elf64_Half e_phentsize; /* Program header table entry size */ - Elf64_Half e_phnum; /* Program header table entry count */ - Elf64_Half e_shentsize; /* Section header table entry size */ - Elf64_Half e_shnum; /* Section header table entry count */ - Elf64_Half e_shstrndx; /* Section header string table index */ +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ + Elf64_Half e_type; /* Object file type */ + Elf64_Half e_machine; /* Architecture */ + Elf64_Word e_version; /* Object file version */ + Elf64_Addr e_entry; /* Entry point virtual address */ + Elf64_Off e_phoff; /* Program header table file offset */ + Elf64_Off e_shoff; /* Section header table file offset */ + Elf64_Word e_flags; /* Processor-specific flags */ + Elf64_Half e_ehsize; /* ELF header size in bytes */ + Elf64_Half e_phentsize; /* Program header table entry size */ + Elf64_Half e_phnum; /* Program header table entry count */ + Elf64_Half e_shentsize; /* Section header table entry size */ + Elf64_Half e_shnum; /* Section header table entry count */ + Elf64_Half e_shstrndx; /* Section header string table index */ } Elf64_Ehdr; /* Fields in the e_ident array. The EI_* macros are indices into the array. The macros under each EI_* macro are the values the byte may have. */ -#define EI_MAG0 0 /* File identification byte 0 index */ -#define ELFMAG0 0x7f /* Magic number byte 0 */ +#define EI_MAG0 0 /* File identification byte 0 index */ +#define ELFMAG0 0x7f /* Magic number byte 0 */ -#define EI_MAG1 1 /* File identification byte 1 index */ -#define ELFMAG1 'E' /* Magic number byte 1 */ +#define EI_MAG1 1 /* File identification byte 1 index */ +#define ELFMAG1 'E' /* Magic number byte 1 */ -#define EI_MAG2 2 /* File identification byte 2 index */ -#define ELFMAG2 'L' /* Magic number byte 2 */ +#define EI_MAG2 2 /* File identification byte 2 index */ +#define ELFMAG2 'L' /* Magic number byte 2 */ -#define EI_MAG3 3 /* File identification byte 3 index */ -#define ELFMAG3 'F' /* Magic number byte 3 */ +#define EI_MAG3 3 /* File identification byte 3 index */ +#define ELFMAG3 'F' /* Magic number byte 3 */ /* Conglomeration of the identification bytes, for easy testing as a word. */ -#define ELFMAG "\177ELF" -#define SELFMAG 4 +#define ELFMAG "\177ELF" +#define SELFMAG 4 -#define EI_CLASS 4 /* File class byte index */ -#define ELFCLASSNONE 0 /* Invalid class */ -#define ELFCLASS32 1 /* 32-bit objects */ -#define ELFCLASS64 2 /* 64-bit objects */ -#define ELFCLASSNUM 3 +#define EI_CLASS 4 /* File class byte index */ +#define ELFCLASSNONE 0 /* Invalid class */ +#define ELFCLASS32 1 /* 32-bit objects */ +#define ELFCLASS64 2 /* 64-bit objects */ +#define ELFCLASSNUM 3 -#define EI_DATA 5 /* Data encoding byte index */ -#define ELFDATANONE 0 /* Invalid data encoding */ -#define ELFDATA2LSB 1 /* 2's complement, little endian */ -#define ELFDATA2MSB 2 /* 2's complement, big endian */ -#define ELFDATANUM 3 +#define EI_DATA 5 /* Data encoding byte index */ +#define ELFDATANONE 0 /* Invalid data encoding */ +#define ELFDATA2LSB 1 /* 2's complement, little endian */ +#define ELFDATA2MSB 2 /* 2's complement, big endian */ +#define ELFDATANUM 3 -#define EI_VERSION 6 /* File version byte index */ - /* Value must be EV_CURRENT */ +#define EI_VERSION 6 /* File version byte index */ + /* Value must be EV_CURRENT */ -#define EI_OSABI 7 /* OS ABI identification */ -#define ELFOSABI_NONE 0 /* UNIX System V ABI */ -#define ELFOSABI_SYSV 0 /* Alias. */ -#define ELFOSABI_HPUX 1 /* HP-UX */ -#define ELFOSABI_NETBSD 2 /* NetBSD. */ -#define ELFOSABI_GNU 3 /* Object uses GNU ELF extensions. */ -#define ELFOSABI_LINUX ELFOSABI_GNU /* Compatibility alias. */ -#define ELFOSABI_SOLARIS 6 /* Sun Solaris. */ -#define ELFOSABI_AIX 7 /* IBM AIX. */ -#define ELFOSABI_IRIX 8 /* SGI Irix. */ -#define ELFOSABI_FREEBSD 9 /* FreeBSD. */ -#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */ -#define ELFOSABI_MODESTO 11 /* Novell Modesto. */ -#define ELFOSABI_OPENBSD 12 /* OpenBSD. */ -#define ELFOSABI_OPENVMS 13 -#define ELFOSABI_NSK 14 /* Hewlett-Packard Non-Stop Kernel. */ -#define ELFOSABI_AROS 15 /* Amiga Research OS. */ -#define ELFOSABI_FENIXOS 16 /* FenixOS. */ -#define ELFOSABI_ARM_AEABI 64 /* ARM EABI. */ -#define ELFOSABI_C6000_LINUX 65 /* Linux TMS320C6000. */ -#define ELFOSABI_ARM 97 /* ARM */ -#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ +#define EI_OSABI 7 /* OS ABI identification */ +#define ELFOSABI_NONE 0 /* UNIX System V ABI */ +#define ELFOSABI_SYSV 0 /* Alias. */ +#define ELFOSABI_HPUX 1 /* HP-UX */ +#define ELFOSABI_NETBSD 2 /* NetBSD. */ +#define ELFOSABI_GNU 3 /* Object uses GNU ELF extensions. */ +#define ELFOSABI_LINUX ELFOSABI_GNU /* Compatibility alias. */ +#define ELFOSABI_SOLARIS 6 /* Sun Solaris. */ +#define ELFOSABI_AIX 7 /* IBM AIX. */ +#define ELFOSABI_IRIX 8 /* SGI Irix. */ +#define ELFOSABI_FREEBSD 9 /* FreeBSD. */ +#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */ +#define ELFOSABI_MODESTO 11 /* Novell Modesto. */ +#define ELFOSABI_OPENBSD 12 /* OpenBSD. */ +#define ELFOSABI_OPENVMS 13 +#define ELFOSABI_NSK 14 /* Hewlett-Packard Non-Stop Kernel. */ +#define ELFOSABI_AROS 15 /* Amiga Research OS. */ +#define ELFOSABI_FENIXOS 16 /* FenixOS. */ +#define ELFOSABI_ARM_AEABI 64 /* ARM EABI. */ +#define ELFOSABI_C6000_LINUX 65 /* Linux TMS320C6000. */ +#define ELFOSABI_ARM 97 /* ARM */ +#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ -#define EI_ABIVERSION 8 /* ABI version */ +#define EI_ABIVERSION 8 /* ABI version */ -#define EI_PAD 9 /* Byte index of padding bytes */ +#define EI_PAD 9 /* Byte index of padding bytes */ /* Legal values for e_type (object file type). */ -#define ET_NONE 0 /* No file type */ -#define ET_REL 1 /* Relocatable file */ -#define ET_EXEC 2 /* Executable file */ -#define ET_DYN 3 /* Shared object file */ -#define ET_CORE 4 /* Core file */ -#define ET_NUM 5 /* Number of defined types */ -#define ET_LOOS 0xfe00 /* OS-specific range start */ -#define ET_HIOS 0xfeff /* OS-specific range end */ -#define ET_LOPROC 0xff00 /* Processor-specific range start */ -#define ET_HIPROC 0xffff /* Processor-specific range end */ +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* Relocatable file */ +#define ET_EXEC 2 /* Executable file */ +#define ET_DYN 3 /* Shared object file */ +#define ET_CORE 4 /* Core file */ +#define ET_NUM 5 /* Number of defined types */ +#define ET_LOOS 0xfe00 /* OS-specific range start */ +#define ET_HIOS 0xfeff /* OS-specific range end */ +#define ET_LOPROC 0xff00 /* Processor-specific range start */ +#define ET_HIPROC 0xffff /* Processor-specific range end */ /* Legal values for e_machine (architecture). */ -#define EM_NONE 0 /* No machine */ -#define EM_M32 1 /* AT&T WE 32100 */ -#define EM_SPARC 2 /* SUN SPARC */ -#define EM_386 3 /* Intel 80386 */ -#define EM_68K 4 /* Motorola m68k family */ -#define EM_88K 5 /* Motorola m88k family */ -#define EM_860 7 /* Intel 80860 */ -#define EM_MIPS 8 /* MIPS R3000 big-endian */ -#define EM_S370 9 /* IBM System/370 */ -#define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */ +#define EM_NONE 0 /* No machine */ +#define EM_M32 1 /* AT&T WE 32100 */ +#define EM_SPARC 2 /* SUN SPARC */ +#define EM_386 3 /* Intel 80386 */ +#define EM_68K 4 /* Motorola m68k family */ +#define EM_88K 5 /* Motorola m88k family */ +#define EM_860 7 /* Intel 80860 */ +#define EM_MIPS 8 /* MIPS R3000 big-endian */ +#define EM_S370 9 /* IBM System/370 */ +#define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */ -#define EM_PARISC 15 /* HPPA */ -#define EM_VPP500 17 /* Fujitsu VPP500 */ -#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ -#define EM_960 19 /* Intel 80960 */ -#define EM_PPC 20 /* PowerPC */ -#define EM_PPC64 21 /* PowerPC 64-bit */ -#define EM_S390 22 /* IBM S390 */ +#define EM_PARISC 15 /* HPPA */ +#define EM_VPP500 17 /* Fujitsu VPP500 */ +#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ +#define EM_960 19 /* Intel 80960 */ +#define EM_PPC 20 /* PowerPC */ +#define EM_PPC64 21 /* PowerPC 64-bit */ +#define EM_S390 22 /* IBM S390 */ -#define EM_V800 36 /* NEC V800 series */ -#define EM_FR20 37 /* Fujitsu FR20 */ -#define EM_RH32 38 /* TRW RH-32 */ -#define EM_RCE 39 /* Motorola RCE */ -#define EM_ARM 40 /* ARM */ -#define EM_FAKE_ALPHA 41 /* Digital Alpha */ -#define EM_SH 42 /* Hitachi SH */ -#define EM_SPARCV9 43 /* SPARC v9 64-bit */ -#define EM_TRICORE 44 /* Siemens Tricore */ -#define EM_ARC 45 /* Argonaut RISC Core */ -#define EM_H8_300 46 /* Hitachi H8/300 */ -#define EM_H8_300H 47 /* Hitachi H8/300H */ -#define EM_H8S 48 /* Hitachi H8S */ -#define EM_H8_500 49 /* Hitachi H8/500 */ -#define EM_IA_64 50 /* Intel Merced */ -#define EM_MIPS_X 51 /* Stanford MIPS-X */ -#define EM_COLDFIRE 52 /* Motorola Coldfire */ -#define EM_68HC12 53 /* Motorola M68HC12 */ -#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/ -#define EM_PCP 55 /* Siemens PCP */ -#define EM_NCPU 56 /* Sony nCPU embedded RISC */ -#define EM_NDR1 57 /* Denso NDR1 microprocessor */ -#define EM_STARCORE 58 /* Motorola Start*Core processor */ -#define EM_ME16 59 /* Toyota ME16 processor */ -#define EM_ST100 60 /* STMicroelectronic ST100 processor */ -#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/ -#define EM_X86_64 62 /* AMD x86-64 architecture */ -#define EM_PDSP 63 /* Sony DSP Processor */ +#define EM_V800 36 /* NEC V800 series */ +#define EM_FR20 37 /* Fujitsu FR20 */ +#define EM_RH32 38 /* TRW RH-32 */ +#define EM_RCE 39 /* Motorola RCE */ +#define EM_ARM 40 /* ARM */ +#define EM_FAKE_ALPHA 41 /* Digital Alpha */ +#define EM_SH 42 /* Hitachi SH */ +#define EM_SPARCV9 43 /* SPARC v9 64-bit */ +#define EM_TRICORE 44 /* Siemens Tricore */ +#define EM_ARC 45 /* Argonaut RISC Core */ +#define EM_H8_300 46 /* Hitachi H8/300 */ +#define EM_H8_300H 47 /* Hitachi H8/300H */ +#define EM_H8S 48 /* Hitachi H8S */ +#define EM_H8_500 49 /* Hitachi H8/500 */ +#define EM_IA_64 50 /* Intel Merced */ +#define EM_MIPS_X 51 /* Stanford MIPS-X */ +#define EM_COLDFIRE 52 /* Motorola Coldfire */ +#define EM_68HC12 53 /* Motorola M68HC12 */ +#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/ +#define EM_PCP 55 /* Siemens PCP */ +#define EM_NCPU 56 /* Sony nCPU embedded RISC */ +#define EM_NDR1 57 /* Denso NDR1 microprocessor */ +#define EM_STARCORE 58 /* Motorola Start*Core processor */ +#define EM_ME16 59 /* Toyota ME16 processor */ +#define EM_ST100 60 /* STMicroelectronic ST100 processor */ +#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/ +#define EM_X86_64 62 /* AMD x86-64 architecture */ +#define EM_PDSP 63 /* Sony DSP Processor */ -#define EM_FX66 66 /* Siemens FX66 microcontroller */ -#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ -#define EM_ST7 68 /* STMicroelectronics ST7 8 bit mc */ -#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ -#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ -#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ -#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ -#define EM_SVX 73 /* Silicon Graphics SVx */ -#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ -#define EM_VAX 75 /* Digital VAX */ -#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ -#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ -#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ -#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ -#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ -#define EM_HUANY 81 /* Harvard University machine-independent object files */ -#define EM_PRISM 82 /* SiTera Prism */ -#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ -#define EM_FR30 84 /* Fujitsu FR30 */ -#define EM_D10V 85 /* Mitsubishi D10V */ -#define EM_D30V 86 /* Mitsubishi D30V */ -#define EM_V850 87 /* NEC v850 */ -#define EM_M32R 88 /* Mitsubishi M32R */ -#define EM_MN10300 89 /* Matsushita MN10300 */ -#define EM_MN10200 90 /* Matsushita MN10200 */ -#define EM_PJ 91 /* picoJava */ -#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ -#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ -#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ -#define EM_AARCH64 183 /* ARM AARCH64 */ -#define EM_TILEPRO 188 /* Tilera TILEPro */ -#define EM_TILEGX 191 /* Tilera TILE-Gx */ -#define EM_RISCV 243 /* RISC-V */ -#define EM_NUM 253 +#define EM_FX66 66 /* Siemens FX66 microcontroller */ +#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ +#define EM_ST7 68 /* STMicroelectronics ST7 8 bit mc */ +#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ +#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ +#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ +#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ +#define EM_SVX 73 /* Silicon Graphics SVx */ +#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ +#define EM_VAX 75 /* Digital VAX */ +#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ +#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ +#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ +#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ +#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ +#define EM_HUANY 81 /* Harvard University machine-independent object files */ +#define EM_PRISM 82 /* SiTera Prism */ +#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ +#define EM_FR30 84 /* Fujitsu FR30 */ +#define EM_D10V 85 /* Mitsubishi D10V */ +#define EM_D30V 86 /* Mitsubishi D30V */ +#define EM_V850 87 /* NEC v850 */ +#define EM_M32R 88 /* Mitsubishi M32R */ +#define EM_MN10300 89 /* Matsushita MN10300 */ +#define EM_MN10200 90 /* Matsushita MN10200 */ +#define EM_PJ 91 /* picoJava */ +#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ +#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ +#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ +#define EM_AARCH64 183 /* ARM AARCH64 */ +#define EM_TILEPRO 188 /* Tilera TILEPro */ +#define EM_TILEGX 191 /* Tilera TILE-Gx */ +#define EM_RISCV 243 /* RISC-V */ +#define EM_NUM 253 /* If it is necessary to assign new unofficial EM_* values, please pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the chances of collision with official or non-GNU unofficial values. */ -#define EM_ALPHA 0x9026 -#define EM_C60 0x9c60 +#define EM_ALPHA 0x9026 +#define EM_C60 0x9c60 /* Legal values for e_version (version). */ -#define EV_NONE 0 /* Invalid ELF version */ -#define EV_CURRENT 1 /* Current version */ -#define EV_NUM 2 +#define EV_NONE 0 /* Invalid ELF version */ +#define EV_CURRENT 1 /* Current version */ +#define EV_NUM 2 /* Section header. */ -typedef struct -{ - Elf32_Word sh_name; /* Section name (string tbl index) */ - Elf32_Word sh_type; /* Section type */ - Elf32_Word sh_flags; /* Section flags */ - Elf32_Addr sh_addr; /* Section virtual addr at execution */ - Elf32_Off sh_offset; /* Section file offset */ - Elf32_Word sh_size; /* Section size in bytes */ - Elf32_Word sh_link; /* Link to another section */ - Elf32_Word sh_info; /* Additional section information */ - Elf32_Word sh_addralign; /* Section alignment */ - Elf32_Word sh_entsize; /* Entry size if section holds table */ +typedef struct { + Elf32_Word sh_name; /* Section name (string tbl index) */ + Elf32_Word sh_type; /* Section type */ + Elf32_Word sh_flags; /* Section flags */ + Elf32_Addr sh_addr; /* Section virtual addr at execution */ + Elf32_Off sh_offset; /* Section file offset */ + Elf32_Word sh_size; /* Section size in bytes */ + Elf32_Word sh_link; /* Link to another section */ + Elf32_Word sh_info; /* Additional section information */ + Elf32_Word sh_addralign; /* Section alignment */ + Elf32_Word sh_entsize; /* Entry size if section holds table */ } Elf32_Shdr; -typedef struct -{ - Elf64_Word sh_name; /* Section name (string tbl index) */ - Elf64_Word sh_type; /* Section type */ - Elf64_Xword sh_flags; /* Section flags */ - Elf64_Addr sh_addr; /* Section virtual addr at execution */ - Elf64_Off sh_offset; /* Section file offset */ - Elf64_Xword sh_size; /* Section size in bytes */ - Elf64_Word sh_link; /* Link to another section */ - Elf64_Word sh_info; /* Additional section information */ - Elf64_Xword sh_addralign; /* Section alignment */ - Elf64_Xword sh_entsize; /* Entry size if section holds table */ +typedef struct { + Elf64_Word sh_name; /* Section name (string tbl index) */ + Elf64_Word sh_type; /* Section type */ + Elf64_Xword sh_flags; /* Section flags */ + Elf64_Addr sh_addr; /* Section virtual addr at execution */ + Elf64_Off sh_offset; /* Section file offset */ + Elf64_Xword sh_size; /* Section size in bytes */ + Elf64_Word sh_link; /* Link to another section */ + Elf64_Word sh_info; /* Additional section information */ + Elf64_Xword sh_addralign; /* Section alignment */ + Elf64_Xword sh_entsize; /* Entry size if section holds table */ } Elf64_Shdr; /* Special section indices. */ -#define SHN_UNDEF 0 /* Undefined section */ -#define SHN_LORESERVE 0xff00 /* Start of reserved indices */ -#define SHN_LOPROC 0xff00 /* Start of processor-specific */ -#define SHN_BEFORE 0xff00 /* Order section before all others - (Solaris). */ -#define SHN_AFTER 0xff01 /* Order section after all others - (Solaris). */ -#define SHN_HIPROC 0xff1f /* End of processor-specific */ -#define SHN_LOOS 0xff20 /* Start of OS-specific */ -#define SHN_HIOS 0xff3f /* End of OS-specific */ -#define SHN_ABS 0xfff1 /* Associated symbol is absolute */ -#define SHN_COMMON 0xfff2 /* Associated symbol is common */ -#define SHN_XINDEX 0xffff /* Index is in extra table. */ -#define SHN_HIRESERVE 0xffff /* End of reserved indices */ +#define SHN_UNDEF 0 /* Undefined section */ +#define SHN_LORESERVE 0xff00 /* Start of reserved indices */ +#define SHN_LOPROC 0xff00 /* Start of processor-specific */ +#define SHN_BEFORE \ + 0xff00 /* Order section before all others \ + (Solaris). */ +#define SHN_AFTER \ + 0xff01 /* Order section after all others \ + (Solaris). */ +#define SHN_HIPROC 0xff1f /* End of processor-specific */ +#define SHN_LOOS 0xff20 /* Start of OS-specific */ +#define SHN_HIOS 0xff3f /* End of OS-specific */ +#define SHN_ABS 0xfff1 /* Associated symbol is absolute */ +#define SHN_COMMON 0xfff2 /* Associated symbol is common */ +#define SHN_XINDEX 0xffff /* Index is in extra table. */ +#define SHN_HIRESERVE 0xffff /* End of reserved indices */ /* Legal values for sh_type (section type). */ -#define SHT_NULL 0 /* Section header table entry unused */ -#define SHT_PROGBITS 1 /* Program data */ -#define SHT_SYMTAB 2 /* Symbol table */ -#define SHT_STRTAB 3 /* String table */ -#define SHT_RELA 4 /* Relocation entries with addends */ -#define SHT_HASH 5 /* Symbol hash table */ -#define SHT_DYNAMIC 6 /* Dynamic linking information */ -#define SHT_NOTE 7 /* Notes */ -#define SHT_NOBITS 8 /* Program space with no data (bss) */ -#define SHT_REL 9 /* Relocation entries, no addends */ -#define SHT_SHLIB 10 /* Reserved */ -#define SHT_DYNSYM 11 /* Dynamic linker symbol table */ -#define SHT_INIT_ARRAY 14 /* Array of constructors */ -#define SHT_FINI_ARRAY 15 /* Array of destructors */ -#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */ -#define SHT_GROUP 17 /* Section group */ -#define SHT_SYMTAB_SHNDX 18 /* Extended section indices */ -#define SHT_NUM 19 /* Number of defined types. */ -#define SHT_LOOS 0x60000000 /* Start OS-specific. */ -#define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* Object attributes. */ -#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */ -#define SHT_GNU_LIBLIST 0x6ffffff7 /* Prelink library list */ -#define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */ -#define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */ -#define SHT_SUNW_move 0x6ffffffa -#define SHT_SUNW_COMDAT 0x6ffffffb -#define SHT_SUNW_syminfo 0x6ffffffc -#define SHT_GNU_verdef 0x6ffffffd /* Version definition section. */ -#define SHT_GNU_verneed 0x6ffffffe /* Version needs section. */ -#define SHT_GNU_versym 0x6fffffff /* Version symbol table. */ -#define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */ -#define SHT_HIOS 0x6fffffff /* End OS-specific type */ -#define SHT_LOPROC 0x70000000 /* Start of processor-specific */ -#define SHT_HIPROC 0x7fffffff /* End of processor-specific */ -#define SHT_LOUSER 0x80000000 /* Start of application-specific */ -#define SHT_HIUSER 0x8fffffff /* End of application-specific */ +#define SHT_NULL 0 /* Section header table entry unused */ +#define SHT_PROGBITS 1 /* Program data */ +#define SHT_SYMTAB 2 /* Symbol table */ +#define SHT_STRTAB 3 /* String table */ +#define SHT_RELA 4 /* Relocation entries with addends */ +#define SHT_HASH 5 /* Symbol hash table */ +#define SHT_DYNAMIC 6 /* Dynamic linking information */ +#define SHT_NOTE 7 /* Notes */ +#define SHT_NOBITS 8 /* Program space with no data (bss) */ +#define SHT_REL 9 /* Relocation entries, no addends */ +#define SHT_SHLIB 10 /* Reserved */ +#define SHT_DYNSYM 11 /* Dynamic linker symbol table */ +#define SHT_INIT_ARRAY 14 /* Array of constructors */ +#define SHT_FINI_ARRAY 15 /* Array of destructors */ +#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */ +#define SHT_GROUP 17 /* Section group */ +#define SHT_SYMTAB_SHNDX 18 /* Extended section indices */ +#define SHT_NUM 19 /* Number of defined types. */ +#define SHT_LOOS 0x60000000 /* Start OS-specific. */ +#define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* Object attributes. */ +#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */ +#define SHT_GNU_LIBLIST 0x6ffffff7 /* Prelink library list */ +#define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */ +#define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */ +#define SHT_SUNW_move 0x6ffffffa +#define SHT_SUNW_COMDAT 0x6ffffffb +#define SHT_SUNW_syminfo 0x6ffffffc +#define SHT_GNU_verdef 0x6ffffffd /* Version definition section. */ +#define SHT_GNU_verneed 0x6ffffffe /* Version needs section. */ +#define SHT_GNU_versym 0x6fffffff /* Version symbol table. */ +#define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */ +#define SHT_HIOS 0x6fffffff /* End OS-specific type */ +#define SHT_LOPROC 0x70000000 /* Start of processor-specific */ +#define SHT_HIPROC 0x7fffffff /* End of processor-specific */ +#define SHT_LOUSER 0x80000000 /* Start of application-specific */ +#define SHT_HIUSER 0x8fffffff /* End of application-specific */ /* Legal values for sh_flags (section flags). */ -#define SHF_WRITE (1 << 0) /* Writable */ -#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */ -#define SHF_EXECINSTR (1 << 2) /* Executable */ -#define SHF_MERGE (1 << 4) /* Might be merged */ -#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */ -#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */ -#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */ -#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling - required */ -#define SHF_GROUP (1 << 9) /* Section is member of a group. */ -#define SHF_TLS (1 << 10) /* Section hold thread-local data. */ -#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */ -#define SHF_MASKOS 0x0ff00000 /* OS-specific. */ -#define SHF_MASKPROC 0xf0000000 /* Processor-specific */ -#define SHF_ORDERED (1 << 30) /* Special ordering requirement - (Solaris). */ -#define SHF_EXCLUDE (1U << 31) /* Section is excluded unless - referenced or allocated (Solaris).*/ +#define SHF_WRITE (1 << 0) /* Writable */ +#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */ +#define SHF_EXECINSTR (1 << 2) /* Executable */ +#define SHF_MERGE (1 << 4) /* Might be merged */ +#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */ +#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */ +#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */ +#define SHF_OS_NONCONFORMING \ + (1 << 8) /* Non-standard OS specific handling \ + required */ +#define SHF_GROUP (1 << 9) /* Section is member of a group. */ +#define SHF_TLS (1 << 10) /* Section hold thread-local data. */ +#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */ +#define SHF_MASKOS 0x0ff00000 /* OS-specific. */ +#define SHF_MASKPROC 0xf0000000 /* Processor-specific */ +#define SHF_ORDERED \ + (1 << 30) /* Special ordering requirement \ + (Solaris). */ +#define SHF_EXCLUDE \ + (1U << 31) /* Section is excluded unless \ + referenced or allocated (Solaris).*/ /* Section group handling. */ -#define GRP_COMDAT 0x1 /* Mark group as COMDAT. */ +#define GRP_COMDAT 0x1 /* Mark group as COMDAT. */ /* Symbol table entry. */ -typedef struct -{ - Elf32_Word st_name; /* Symbol name (string tbl index) */ - Elf32_Addr st_value; /* Symbol value */ - Elf32_Word st_size; /* Symbol size */ - unsigned char st_info; /* Symbol type and binding */ - unsigned char st_other; /* Symbol visibility */ - Elf32_Section st_shndx; /* Section index */ +typedef struct { + Elf32_Word st_name; /* Symbol name (string tbl index) */ + Elf32_Addr st_value; /* Symbol value */ + Elf32_Word st_size; /* Symbol size */ + unsigned char st_info; /* Symbol type and binding */ + unsigned char st_other; /* Symbol visibility */ + Elf32_Section st_shndx; /* Section index */ } Elf32_Sym; -typedef struct -{ - Elf64_Word st_name; /* Symbol name (string tbl index) */ - unsigned char st_info; /* Symbol type and binding */ - unsigned char st_other; /* Symbol visibility */ - Elf64_Section st_shndx; /* Section index */ - Elf64_Addr st_value; /* Symbol value */ - Elf64_Xword st_size; /* Symbol size */ +typedef struct { + Elf64_Word st_name; /* Symbol name (string tbl index) */ + unsigned char st_info; /* Symbol type and binding */ + unsigned char st_other; /* Symbol visibility */ + Elf64_Section st_shndx; /* Section index */ + Elf64_Addr st_value; /* Symbol value */ + Elf64_Xword st_size; /* Symbol size */ } Elf64_Sym; /* The syminfo section if available contains additional information about every dynamic symbol. */ -typedef struct -{ - Elf32_Half si_boundto; /* Direct bindings, symbol bound to */ - Elf32_Half si_flags; /* Per symbol flags */ +typedef struct { + Elf32_Half si_boundto; /* Direct bindings, symbol bound to */ + Elf32_Half si_flags; /* Per symbol flags */ } Elf32_Syminfo; -typedef struct -{ - Elf64_Half si_boundto; /* Direct bindings, symbol bound to */ - Elf64_Half si_flags; /* Per symbol flags */ +typedef struct { + Elf64_Half si_boundto; /* Direct bindings, symbol bound to */ + Elf64_Half si_flags; /* Per symbol flags */ } Elf64_Syminfo; /* Possible values for si_boundto. */ -#define SYMINFO_BT_SELF 0xffff /* Symbol bound to self */ -#define SYMINFO_BT_PARENT 0xfffe /* Symbol bound to parent */ -#define SYMINFO_BT_LOWRESERVE 0xff00 /* Beginning of reserved entries */ +#define SYMINFO_BT_SELF 0xffff /* Symbol bound to self */ +#define SYMINFO_BT_PARENT 0xfffe /* Symbol bound to parent */ +#define SYMINFO_BT_LOWRESERVE 0xff00 /* Beginning of reserved entries */ /* Possible bitmasks for si_flags. */ -#define SYMINFO_FLG_DIRECT 0x0001 /* Direct bound symbol */ -#define SYMINFO_FLG_PASSTHRU 0x0002 /* Pass-thru symbol for translator */ -#define SYMINFO_FLG_COPY 0x0004 /* Symbol is a copy-reloc */ -#define SYMINFO_FLG_LAZYLOAD 0x0008 /* Symbol bound to object to be lazy - loaded */ +#define SYMINFO_FLG_DIRECT 0x0001 /* Direct bound symbol */ +#define SYMINFO_FLG_PASSTHRU 0x0002 /* Pass-thru symbol for translator */ +#define SYMINFO_FLG_COPY 0x0004 /* Symbol is a copy-reloc */ +#define SYMINFO_FLG_LAZYLOAD \ + 0x0008 /* Symbol bound to object to be lazy \ + loaded */ /* Syminfo version values. */ -#define SYMINFO_NONE 0 -#define SYMINFO_CURRENT 1 -#define SYMINFO_NUM 2 - +#define SYMINFO_NONE 0 +#define SYMINFO_CURRENT 1 +#define SYMINFO_NUM 2 /* How to extract and insert information held in the st_info field. */ -#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4) -#define ELF32_ST_TYPE(val) ((val) & 0xf) -#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) +#define ELF32_ST_BIND(val) (((unsigned char)(val)) >> 4) +#define ELF32_ST_TYPE(val) ((val) & 0xf) +#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) /* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ -#define ELF64_ST_BIND(val) ELF32_ST_BIND (val) -#define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val) -#define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type)) +#define ELF64_ST_BIND(val) ELF32_ST_BIND(val) +#define ELF64_ST_TYPE(val) ELF32_ST_TYPE(val) +#define ELF64_ST_INFO(bind, type) ELF32_ST_INFO((bind), (type)) /* Legal values for ST_BIND subfield of st_info (symbol binding). */ -#define STB_LOCAL 0 /* Local symbol */ -#define STB_GLOBAL 1 /* Global symbol */ -#define STB_WEAK 2 /* Weak symbol */ -#define STB_NUM 3 /* Number of defined types. */ -#define STB_LOOS 10 /* Start of OS-specific */ -#define STB_GNU_UNIQUE 10 /* Unique symbol. */ -#define STB_HIOS 12 /* End of OS-specific */ -#define STB_LOPROC 13 /* Start of processor-specific */ -#define STB_HIPROC 15 /* End of processor-specific */ +#define STB_LOCAL 0 /* Local symbol */ +#define STB_GLOBAL 1 /* Global symbol */ +#define STB_WEAK 2 /* Weak symbol */ +#define STB_NUM 3 /* Number of defined types. */ +#define STB_LOOS 10 /* Start of OS-specific */ +#define STB_GNU_UNIQUE 10 /* Unique symbol. */ +#define STB_HIOS 12 /* End of OS-specific */ +#define STB_LOPROC 13 /* Start of processor-specific */ +#define STB_HIPROC 15 /* End of processor-specific */ /* Legal values for ST_TYPE subfield of st_info (symbol type). */ -#define STT_NOTYPE 0 /* Symbol type is unspecified */ -#define STT_OBJECT 1 /* Symbol is a data object */ -#define STT_FUNC 2 /* Symbol is a code object */ -#define STT_SECTION 3 /* Symbol associated with a section */ -#define STT_FILE 4 /* Symbol's name is file name */ -#define STT_COMMON 5 /* Symbol is a common data object */ -#define STT_TLS 6 /* Symbol is thread-local data object*/ -#define STT_NUM 7 /* Number of defined types. */ -#define STT_LOOS 10 /* Start of OS-specific */ -#define STT_GNU_IFUNC 10 /* Symbol is indirect code object */ -#define STT_HIOS 12 /* End of OS-specific */ -#define STT_LOPROC 13 /* Start of processor-specific */ -#define STT_HIPROC 15 /* End of processor-specific */ - +#define STT_NOTYPE 0 /* Symbol type is unspecified */ +#define STT_OBJECT 1 /* Symbol is a data object */ +#define STT_FUNC 2 /* Symbol is a code object */ +#define STT_SECTION 3 /* Symbol associated with a section */ +#define STT_FILE 4 /* Symbol's name is file name */ +#define STT_COMMON 5 /* Symbol is a common data object */ +#define STT_TLS 6 /* Symbol is thread-local data object*/ +#define STT_NUM 7 /* Number of defined types. */ +#define STT_LOOS 10 /* Start of OS-specific */ +#define STT_GNU_IFUNC 10 /* Symbol is indirect code object */ +#define STT_HIOS 12 /* End of OS-specific */ +#define STT_LOPROC 13 /* Start of processor-specific */ +#define STT_HIPROC 15 /* End of processor-specific */ /* Symbol table indices are found in the hash buckets and chain table of a symbol hash table section. This special index value indicates the end of a chain, meaning no further symbols are found in that bucket. */ -#define STN_UNDEF 0 /* End of a chain. */ - +#define STN_UNDEF 0 /* End of a chain. */ /* How to extract and insert information held in the st_other field. */ -#define ELF32_ST_VISIBILITY(o) ((o) & 0x03) +#define ELF32_ST_VISIBILITY(o) ((o) & 0x03) /* For ELF64 the definitions are the same. */ -#define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o) +#define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY(o) /* Symbol visibility specification encoded in the st_other field. */ -#define STV_DEFAULT 0 /* Default symbol visibility rules */ -#define STV_INTERNAL 1 /* Processor specific hidden class */ -#define STV_HIDDEN 2 /* Sym unavailable in other modules */ -#define STV_PROTECTED 3 /* Not preemptible, not exported */ - +#define STV_DEFAULT 0 /* Default symbol visibility rules */ +#define STV_INTERNAL 1 /* Processor specific hidden class */ +#define STV_HIDDEN 2 /* Sym unavailable in other modules */ +#define STV_PROTECTED 3 /* Not preemptible, not exported */ /* Relocation table entry without addend (in section of type SHT_REL). */ -typedef struct -{ - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ +typedef struct { + Elf32_Addr r_offset; /* Address */ + Elf32_Word r_info; /* Relocation type and symbol index */ } Elf32_Rel; /* I have seen two different definitions of the Elf64_Rel and @@ -521,227 +513,218 @@ typedef struct whoever) gets their act together. */ /* The following, at least, is used on Sparc v9, MIPS, and Alpha. */ -typedef struct -{ - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ +typedef struct { + Elf64_Addr r_offset; /* Address */ + Elf64_Xword r_info; /* Relocation type and symbol index */ } Elf64_Rel; /* Relocation table entry with addend (in section of type SHT_RELA). */ -typedef struct -{ - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ - Elf32_Sword r_addend; /* Addend */ +typedef struct { + Elf32_Addr r_offset; /* Address */ + Elf32_Word r_info; /* Relocation type and symbol index */ + Elf32_Sword r_addend; /* Addend */ } Elf32_Rela; -typedef struct -{ - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ - Elf64_Sxword r_addend; /* Addend */ +typedef struct { + Elf64_Addr r_offset; /* Address */ + Elf64_Xword r_info; /* Relocation type and symbol index */ + Elf64_Sxword r_addend; /* Addend */ } Elf64_Rela; /* How to extract and insert information held in the r_info field. */ -#define ELF32_R_SYM(val) ((val) >> 8) -#define ELF32_R_TYPE(val) ((val) & 0xff) -#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) +#define ELF32_R_SYM(val) ((val) >> 8) +#define ELF32_R_TYPE(val) ((val) & 0xff) +#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) -#define ELF64_R_SYM(i) ((i) >> 32) -#define ELF64_R_TYPE(i) ((i) & 0xffffffff) -#define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type)) +#define ELF64_R_SYM(i) ((i) >> 32) +#define ELF64_R_TYPE(i) ((i) & 0xffffffff) +#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)(sym)) << 32) + (type)) /* Program segment header. */ -typedef struct -{ - Elf32_Word p_type; /* Segment type */ - Elf32_Off p_offset; /* Segment file offset */ - Elf32_Addr p_vaddr; /* Segment virtual address */ - Elf32_Addr p_paddr; /* Segment physical address */ - Elf32_Word p_filesz; /* Segment size in file */ - Elf32_Word p_memsz; /* Segment size in memory */ - Elf32_Word p_flags; /* Segment flags */ - Elf32_Word p_align; /* Segment alignment */ +typedef struct { + Elf32_Word p_type; /* Segment type */ + Elf32_Off p_offset; /* Segment file offset */ + Elf32_Addr p_vaddr; /* Segment virtual address */ + Elf32_Addr p_paddr; /* Segment physical address */ + Elf32_Word p_filesz; /* Segment size in file */ + Elf32_Word p_memsz; /* Segment size in memory */ + Elf32_Word p_flags; /* Segment flags */ + Elf32_Word p_align; /* Segment alignment */ } Elf32_Phdr; -typedef struct -{ - Elf64_Word p_type; /* Segment type */ - Elf64_Word p_flags; /* Segment flags */ - Elf64_Off p_offset; /* Segment file offset */ - Elf64_Addr p_vaddr; /* Segment virtual address */ - Elf64_Addr p_paddr; /* Segment physical address */ - Elf64_Xword p_filesz; /* Segment size in file */ - Elf64_Xword p_memsz; /* Segment size in memory */ - Elf64_Xword p_align; /* Segment alignment */ +typedef struct { + Elf64_Word p_type; /* Segment type */ + Elf64_Word p_flags; /* Segment flags */ + Elf64_Off p_offset; /* Segment file offset */ + Elf64_Addr p_vaddr; /* Segment virtual address */ + Elf64_Addr p_paddr; /* Segment physical address */ + Elf64_Xword p_filesz; /* Segment size in file */ + Elf64_Xword p_memsz; /* Segment size in memory */ + Elf64_Xword p_align; /* Segment alignment */ } Elf64_Phdr; /* Special value for e_phnum. This indicates that the real number of program headers is too large to fit into e_phnum. Instead the real value is in the field sh_info of section 0. */ -#define PN_XNUM 0xffff +#define PN_XNUM 0xffff /* Legal values for p_type (segment type). */ -#define PT_NULL 0 /* Program header table entry unused */ -#define PT_LOAD 1 /* Loadable program segment */ -#define PT_DYNAMIC 2 /* Dynamic linking information */ -#define PT_INTERP 3 /* Program interpreter */ -#define PT_NOTE 4 /* Auxiliary information */ -#define PT_SHLIB 5 /* Reserved */ -#define PT_PHDR 6 /* Entry for header table itself */ -#define PT_TLS 7 /* Thread-local storage segment */ -#define PT_NUM 8 /* Number of defined types */ -#define PT_LOOS 0x60000000 /* Start of OS-specific */ -#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */ -#define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */ -#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ -#define PT_LOSUNW 0x6ffffffa -#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ -#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */ -#define PT_HISUNW 0x6fffffff -#define PT_HIOS 0x6fffffff /* End of OS-specific */ -#define PT_LOPROC 0x70000000 /* Start of processor-specific */ -#define PT_HIPROC 0x7fffffff /* End of processor-specific */ +#define PT_NULL 0 /* Program header table entry unused */ +#define PT_LOAD 1 /* Loadable program segment */ +#define PT_DYNAMIC 2 /* Dynamic linking information */ +#define PT_INTERP 3 /* Program interpreter */ +#define PT_NOTE 4 /* Auxiliary information */ +#define PT_SHLIB 5 /* Reserved */ +#define PT_PHDR 6 /* Entry for header table itself */ +#define PT_TLS 7 /* Thread-local storage segment */ +#define PT_NUM 8 /* Number of defined types */ +#define PT_LOOS 0x60000000 /* Start of OS-specific */ +#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */ +#define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */ +#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ +#define PT_LOSUNW 0x6ffffffa +#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ +#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */ +#define PT_HISUNW 0x6fffffff +#define PT_HIOS 0x6fffffff /* End of OS-specific */ +#define PT_LOPROC 0x70000000 /* Start of processor-specific */ +#define PT_HIPROC 0x7fffffff /* End of processor-specific */ /* Legal values for p_flags (segment flags). */ -#define PF_X (1 << 0) /* Segment is executable */ -#define PF_W (1 << 1) /* Segment is writable */ -#define PF_R (1 << 2) /* Segment is readable */ -#define PF_MASKOS 0x0ff00000 /* OS-specific */ -#define PF_MASKPROC 0xf0000000 /* Processor-specific */ +#define PF_X (1 << 0) /* Segment is executable */ +#define PF_W (1 << 1) /* Segment is writable */ +#define PF_R (1 << 2) /* Segment is readable */ +#define PF_MASKOS 0x0ff00000 /* OS-specific */ +#define PF_MASKPROC 0xf0000000 /* Processor-specific */ /* Legal values for note segment descriptor types for core files. */ -#define NT_PRSTATUS 1 /* Contains copy of prstatus struct */ -#define NT_FPREGSET 2 /* Contains copy of fpregset struct */ -#define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */ -#define NT_PRXREG 4 /* Contains copy of prxregset struct */ -#define NT_TASKSTRUCT 4 /* Contains copy of task structure */ -#define NT_PLATFORM 5 /* String from sysinfo(SI_PLATFORM) */ -#define NT_AUXV 6 /* Contains copy of auxv array */ -#define NT_GWINDOWS 7 /* Contains copy of gwindows struct */ -#define NT_ASRS 8 /* Contains copy of asrset struct */ -#define NT_PSTATUS 10 /* Contains copy of pstatus struct */ -#define NT_PSINFO 13 /* Contains copy of psinfo struct */ -#define NT_PRCRED 14 /* Contains copy of prcred struct */ -#define NT_UTSNAME 15 /* Contains copy of utsname struct */ -#define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */ -#define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */ -#define NT_PRFPXREG 20 /* Contains copy of fprxregset struct */ -#define NT_PRXFPREG 0x46e62b7f /* Contains copy of user_fxsr_struct */ -#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */ -#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */ -#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */ -#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */ -#define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */ -#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ -#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */ -#define NT_S390_TIMER 0x301 /* s390 timer register */ -#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */ -#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */ -#define NT_S390_CTRS 0x304 /* s390 control registers */ -#define NT_S390_PREFIX 0x305 /* s390 prefix register */ -#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */ -#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */ -#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ -#define NT_ARM_TLS 0x401 /* ARM TLS register */ -#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ -#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ +#define NT_PRSTATUS 1 /* Contains copy of prstatus struct */ +#define NT_FPREGSET 2 /* Contains copy of fpregset struct */ +#define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */ +#define NT_PRXREG 4 /* Contains copy of prxregset struct */ +#define NT_TASKSTRUCT 4 /* Contains copy of task structure */ +#define NT_PLATFORM 5 /* String from sysinfo(SI_PLATFORM) */ +#define NT_AUXV 6 /* Contains copy of auxv array */ +#define NT_GWINDOWS 7 /* Contains copy of gwindows struct */ +#define NT_ASRS 8 /* Contains copy of asrset struct */ +#define NT_PSTATUS 10 /* Contains copy of pstatus struct */ +#define NT_PSINFO 13 /* Contains copy of psinfo struct */ +#define NT_PRCRED 14 /* Contains copy of prcred struct */ +#define NT_UTSNAME 15 /* Contains copy of utsname struct */ +#define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */ +#define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */ +#define NT_PRFPXREG 20 /* Contains copy of fprxregset struct */ +#define NT_PRXFPREG 0x46e62b7f /* Contains copy of user_fxsr_struct */ +#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */ +#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */ +#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */ +#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */ +#define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */ +#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ +#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */ +#define NT_S390_TIMER 0x301 /* s390 timer register */ +#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */ +#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */ +#define NT_S390_CTRS 0x304 /* s390 control registers */ +#define NT_S390_PREFIX 0x305 /* s390 prefix register */ +#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */ +#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */ +#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ +#define NT_ARM_TLS 0x401 /* ARM TLS register */ +#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ +#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ /* Legal values for the note segment descriptor types for object files. */ -#define NT_VERSION 1 /* Contains a version string. */ - +#define NT_VERSION 1 /* Contains a version string. */ /* Dynamic section entry. */ -typedef struct -{ - Elf32_Sword d_tag; /* Dynamic entry type */ - union - { - Elf32_Word d_val; /* Integer value */ - Elf32_Addr d_ptr; /* Address value */ - } d_un; +typedef struct { + Elf32_Sword d_tag; /* Dynamic entry type */ + union { + Elf32_Word d_val; /* Integer value */ + Elf32_Addr d_ptr; /* Address value */ + } d_un; } Elf32_Dyn; -typedef struct -{ - Elf64_Sxword d_tag; /* Dynamic entry type */ - union - { - Elf64_Xword d_val; /* Integer value */ - Elf64_Addr d_ptr; /* Address value */ - } d_un; +typedef struct { + Elf64_Sxword d_tag; /* Dynamic entry type */ + union { + Elf64_Xword d_val; /* Integer value */ + Elf64_Addr d_ptr; /* Address value */ + } d_un; } Elf64_Dyn; /* Legal values for d_tag (dynamic entry type). */ -#define DT_NULL 0 /* Marks end of dynamic section */ -#define DT_NEEDED 1 /* Name of needed library */ -#define DT_PLTRELSZ 2 /* Size in bytes of PLT relocs */ -#define DT_PLTGOT 3 /* Processor defined value */ -#define DT_HASH 4 /* Address of symbol hash table */ -#define DT_STRTAB 5 /* Address of string table */ -#define DT_SYMTAB 6 /* Address of symbol table */ -#define DT_RELA 7 /* Address of Rela relocs */ -#define DT_RELASZ 8 /* Total size of Rela relocs */ -#define DT_RELAENT 9 /* Size of one Rela reloc */ -#define DT_STRSZ 10 /* Size of string table */ -#define DT_SYMENT 11 /* Size of one symbol table entry */ -#define DT_INIT 12 /* Address of init function */ -#define DT_FINI 13 /* Address of termination function */ -#define DT_SONAME 14 /* Name of shared object */ -#define DT_RPATH 15 /* Library search path (deprecated) */ -#define DT_SYMBOLIC 16 /* Start symbol search here */ -#define DT_REL 17 /* Address of Rel relocs */ -#define DT_RELSZ 18 /* Total size of Rel relocs */ -#define DT_RELENT 19 /* Size of one Rel reloc */ -#define DT_PLTREL 20 /* Type of reloc in PLT */ -#define DT_DEBUG 21 /* For debugging; unspecified */ -#define DT_TEXTREL 22 /* Reloc might modify .text */ -#define DT_JMPREL 23 /* Address of PLT relocs */ -#define DT_BIND_NOW 24 /* Process relocations of object */ -#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */ -#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */ -#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */ -#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */ -#define DT_RUNPATH 29 /* Library search path */ -#define DT_FLAGS 30 /* Flags for the object being loaded */ -#define DT_ENCODING 32 /* Start of encoded range */ -#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/ -#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */ -#define DT_NUM 34 /* Number used */ -#define DT_LOOS 0x6000000d /* Start of OS-specific */ -#define DT_HIOS 0x6ffff000 /* End of OS-specific */ -#define DT_LOPROC 0x70000000 /* Start of processor-specific */ -#define DT_HIPROC 0x7fffffff /* End of processor-specific */ -#define DT_PROCNUM DT_MIPS_NUM /* Most used by any processor */ +#define DT_NULL 0 /* Marks end of dynamic section */ +#define DT_NEEDED 1 /* Name of needed library */ +#define DT_PLTRELSZ 2 /* Size in bytes of PLT relocs */ +#define DT_PLTGOT 3 /* Processor defined value */ +#define DT_HASH 4 /* Address of symbol hash table */ +#define DT_STRTAB 5 /* Address of string table */ +#define DT_SYMTAB 6 /* Address of symbol table */ +#define DT_RELA 7 /* Address of Rela relocs */ +#define DT_RELASZ 8 /* Total size of Rela relocs */ +#define DT_RELAENT 9 /* Size of one Rela reloc */ +#define DT_STRSZ 10 /* Size of string table */ +#define DT_SYMENT 11 /* Size of one symbol table entry */ +#define DT_INIT 12 /* Address of init function */ +#define DT_FINI 13 /* Address of termination function */ +#define DT_SONAME 14 /* Name of shared object */ +#define DT_RPATH 15 /* Library search path (deprecated) */ +#define DT_SYMBOLIC 16 /* Start symbol search here */ +#define DT_REL 17 /* Address of Rel relocs */ +#define DT_RELSZ 18 /* Total size of Rel relocs */ +#define DT_RELENT 19 /* Size of one Rel reloc */ +#define DT_PLTREL 20 /* Type of reloc in PLT */ +#define DT_DEBUG 21 /* For debugging; unspecified */ +#define DT_TEXTREL 22 /* Reloc might modify .text */ +#define DT_JMPREL 23 /* Address of PLT relocs */ +#define DT_BIND_NOW 24 /* Process relocations of object */ +#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */ +#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */ +#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */ +#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */ +#define DT_RUNPATH 29 /* Library search path */ +#define DT_FLAGS 30 /* Flags for the object being loaded */ +#define DT_ENCODING 32 /* Start of encoded range */ +#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/ +#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */ +#define DT_NUM 34 /* Number used */ +#define DT_LOOS 0x6000000d /* Start of OS-specific */ +#define DT_HIOS 0x6ffff000 /* End of OS-specific */ +#define DT_LOPROC 0x70000000 /* Start of processor-specific */ +#define DT_HIPROC 0x7fffffff /* End of processor-specific */ +#define DT_PROCNUM DT_MIPS_NUM /* Most used by any processor */ /* DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the Dyn.d_un.d_val field of the Elf*_Dyn structure. This follows Sun's approach. */ -#define DT_VALRNGLO 0x6ffffd00 -#define DT_GNU_PRELINKED 0x6ffffdf5 /* Prelinking timestamp */ -#define DT_GNU_CONFLICTSZ 0x6ffffdf6 /* Size of conflict section */ -#define DT_GNU_LIBLISTSZ 0x6ffffdf7 /* Size of library list */ -#define DT_CHECKSUM 0x6ffffdf8 -#define DT_PLTPADSZ 0x6ffffdf9 -#define DT_MOVEENT 0x6ffffdfa -#define DT_MOVESZ 0x6ffffdfb -#define DT_FEATURE_1 0x6ffffdfc /* Feature selection (DTF_*). */ -#define DT_POSFLAG_1 0x6ffffdfd /* Flags for DT_* entries, effecting - the following DT_* entry. */ -#define DT_SYMINSZ 0x6ffffdfe /* Size of syminfo table (in bytes) */ -#define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */ -#define DT_VALRNGHI 0x6ffffdff -#define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) /* Reverse order! */ +#define DT_VALRNGLO 0x6ffffd00 +#define DT_GNU_PRELINKED 0x6ffffdf5 /* Prelinking timestamp */ +#define DT_GNU_CONFLICTSZ 0x6ffffdf6 /* Size of conflict section */ +#define DT_GNU_LIBLISTSZ 0x6ffffdf7 /* Size of library list */ +#define DT_CHECKSUM 0x6ffffdf8 +#define DT_PLTPADSZ 0x6ffffdf9 +#define DT_MOVEENT 0x6ffffdfa +#define DT_MOVESZ 0x6ffffdfb +#define DT_FEATURE_1 0x6ffffdfc /* Feature selection (DTF_*). */ +#define DT_POSFLAG_1 \ + 0x6ffffdfd /* Flags for DT_* entries, effecting \ + the following DT_* entry. */ +#define DT_SYMINSZ 0x6ffffdfe /* Size of syminfo table (in bytes) */ +#define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */ +#define DT_VALRNGHI 0x6ffffdff +#define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) /* Reverse order! */ #define DT_VALNUM 12 /* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the @@ -749,208 +732,198 @@ typedef struct If any adjustment is made to the ELF object after it has been built these entries will need to be adjusted. */ -#define DT_ADDRRNGLO 0x6ffffe00 -#define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table. */ -#define DT_TLSDESC_PLT 0x6ffffef6 -#define DT_TLSDESC_GOT 0x6ffffef7 -#define DT_GNU_CONFLICT 0x6ffffef8 /* Start of conflict section */ -#define DT_GNU_LIBLIST 0x6ffffef9 /* Library list */ -#define DT_CONFIG 0x6ffffefa /* Configuration information. */ -#define DT_DEPAUDIT 0x6ffffefb /* Dependency auditing. */ -#define DT_AUDIT 0x6ffffefc /* Object auditing. */ -#define DT_PLTPAD 0x6ffffefd /* PLT padding. */ -#define DT_MOVETAB 0x6ffffefe /* Move table. */ -#define DT_SYMINFO 0x6ffffeff /* Syminfo table. */ -#define DT_ADDRRNGHI 0x6ffffeff -#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */ +#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table. */ +#define DT_TLSDESC_PLT 0x6ffffef6 +#define DT_TLSDESC_GOT 0x6ffffef7 +#define DT_GNU_CONFLICT 0x6ffffef8 /* Start of conflict section */ +#define DT_GNU_LIBLIST 0x6ffffef9 /* Library list */ +#define DT_CONFIG 0x6ffffefa /* Configuration information. */ +#define DT_DEPAUDIT 0x6ffffefb /* Dependency auditing. */ +#define DT_AUDIT 0x6ffffefc /* Object auditing. */ +#define DT_PLTPAD 0x6ffffefd /* PLT padding. */ +#define DT_MOVETAB 0x6ffffefe /* Move table. */ +#define DT_SYMINFO 0x6ffffeff /* Syminfo table. */ +#define DT_ADDRRNGHI 0x6ffffeff +#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */ #define DT_ADDRNUM 11 /* The versioning entry types. The next are defined as part of the GNU extension. */ -#define DT_VERSYM 0x6ffffff0 +#define DT_VERSYM 0x6ffffff0 -#define DT_RELACOUNT 0x6ffffff9 -#define DT_RELCOUNT 0x6ffffffa +#define DT_RELACOUNT 0x6ffffff9 +#define DT_RELCOUNT 0x6ffffffa /* These were chosen by Sun. */ -#define DT_FLAGS_1 0x6ffffffb /* State flags, see DF_1_* below. */ -#define DT_VERDEF 0x6ffffffc /* Address of version definition - table */ -#define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */ -#define DT_VERNEED 0x6ffffffe /* Address of table with needed - versions */ -#define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */ -#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ +#define DT_FLAGS_1 0x6ffffffb /* State flags, see DF_1_* below. */ +#define DT_VERDEF \ + 0x6ffffffc /* Address of version definition \ + table */ +#define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */ +#define DT_VERNEED \ + 0x6ffffffe /* Address of table with needed \ + versions */ +#define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */ +#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ #define DT_VERSIONTAGNUM 16 /* Sun added these machine-independent extensions in the "processor-specific" range. Be compatible. */ -#define DT_AUXILIARY 0x7ffffffd /* Shared object to load before self */ -#define DT_FILTER 0x7fffffff /* Shared object to get values from */ -#define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1) -#define DT_EXTRANUM 3 +#define DT_AUXILIARY 0x7ffffffd /* Shared object to load before self */ +#define DT_FILTER 0x7fffffff /* Shared object to get values from */ +#define DT_EXTRATAGIDX(tag) ((Elf32_Word) - ((Elf32_Sword)(tag) << 1 >> 1) - 1) +#define DT_EXTRANUM 3 /* Values of `d_un.d_val' in the DT_FLAGS entry. */ -#define DF_ORIGIN 0x00000001 /* Object may use DF_ORIGIN */ -#define DF_SYMBOLIC 0x00000002 /* Symbol resolutions starts here */ -#define DF_TEXTREL 0x00000004 /* Object contains text relocations */ -#define DF_BIND_NOW 0x00000008 /* No lazy binding for this object */ -#define DF_STATIC_TLS 0x00000010 /* Module uses the static TLS model */ +#define DF_ORIGIN 0x00000001 /* Object may use DF_ORIGIN */ +#define DF_SYMBOLIC 0x00000002 /* Symbol resolutions starts here */ +#define DF_TEXTREL 0x00000004 /* Object contains text relocations */ +#define DF_BIND_NOW 0x00000008 /* No lazy binding for this object */ +#define DF_STATIC_TLS 0x00000010 /* Module uses the static TLS model */ /* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1 entry in the dynamic section. */ -#define DF_1_NOW 0x00000001 /* Set RTLD_NOW for this object. */ -#define DF_1_GLOBAL 0x00000002 /* Set RTLD_GLOBAL for this object. */ -#define DF_1_GROUP 0x00000004 /* Set RTLD_GROUP for this object. */ -#define DF_1_NODELETE 0x00000008 /* Set RTLD_NODELETE for this object.*/ -#define DF_1_LOADFLTR 0x00000010 /* Trigger filtee loading at runtime.*/ -#define DF_1_INITFIRST 0x00000020 /* Set RTLD_INITFIRST for this object*/ -#define DF_1_NOOPEN 0x00000040 /* Set RTLD_NOOPEN for this object. */ -#define DF_1_ORIGIN 0x00000080 /* $ORIGIN must be handled. */ -#define DF_1_DIRECT 0x00000100 /* Direct binding enabled. */ -#define DF_1_TRANS 0x00000200 -#define DF_1_INTERPOSE 0x00000400 /* Object is used to interpose. */ -#define DF_1_NODEFLIB 0x00000800 /* Ignore default lib search path. */ -#define DF_1_NODUMP 0x00001000 /* Object can't be dldump'ed. */ -#define DF_1_CONFALT 0x00002000 /* Configuration alternative created.*/ -#define DF_1_ENDFILTEE 0x00004000 /* Filtee terminates filters search. */ -#define DF_1_DISPRELDNE 0x00008000 /* Disp reloc applied at build time. */ -#define DF_1_DISPRELPND 0x00010000 /* Disp reloc applied at run-time. */ -#define DF_1_NODIRECT 0x00020000 /* Object has no-direct binding. */ -#define DF_1_IGNMULDEF 0x00040000 -#define DF_1_NOKSYMS 0x00080000 -#define DF_1_NOHDR 0x00100000 -#define DF_1_EDITED 0x00200000 /* Object is modified after built. */ -#define DF_1_NORELOC 0x00400000 -#define DF_1_SYMINTPOSE 0x00800000 /* Object has individual interposers. */ -#define DF_1_GLOBAUDIT 0x01000000 /* Global auditing required. */ -#define DF_1_SINGLETON 0x02000000 /* Singleton symbols are used. */ -#define DF_1_PIE 0x08000000 +#define DF_1_NOW 0x00000001 /* Set RTLD_NOW for this object. */ +#define DF_1_GLOBAL 0x00000002 /* Set RTLD_GLOBAL for this object. */ +#define DF_1_GROUP 0x00000004 /* Set RTLD_GROUP for this object. */ +#define DF_1_NODELETE 0x00000008 /* Set RTLD_NODELETE for this object.*/ +#define DF_1_LOADFLTR 0x00000010 /* Trigger filtee loading at runtime.*/ +#define DF_1_INITFIRST 0x00000020 /* Set RTLD_INITFIRST for this object*/ +#define DF_1_NOOPEN 0x00000040 /* Set RTLD_NOOPEN for this object. */ +#define DF_1_ORIGIN 0x00000080 /* $ORIGIN must be handled. */ +#define DF_1_DIRECT 0x00000100 /* Direct binding enabled. */ +#define DF_1_TRANS 0x00000200 +#define DF_1_INTERPOSE 0x00000400 /* Object is used to interpose. */ +#define DF_1_NODEFLIB 0x00000800 /* Ignore default lib search path. */ +#define DF_1_NODUMP 0x00001000 /* Object can't be dldump'ed. */ +#define DF_1_CONFALT 0x00002000 /* Configuration alternative created.*/ +#define DF_1_ENDFILTEE 0x00004000 /* Filtee terminates filters search. */ +#define DF_1_DISPRELDNE 0x00008000 /* Disp reloc applied at build time. */ +#define DF_1_DISPRELPND 0x00010000 /* Disp reloc applied at run-time. */ +#define DF_1_NODIRECT 0x00020000 /* Object has no-direct binding. */ +#define DF_1_IGNMULDEF 0x00040000 +#define DF_1_NOKSYMS 0x00080000 +#define DF_1_NOHDR 0x00100000 +#define DF_1_EDITED 0x00200000 /* Object is modified after built. */ +#define DF_1_NORELOC 0x00400000 +#define DF_1_SYMINTPOSE 0x00800000 /* Object has individual interposers. */ +#define DF_1_GLOBAUDIT 0x01000000 /* Global auditing required. */ +#define DF_1_SINGLETON 0x02000000 /* Singleton symbols are used. */ +#define DF_1_PIE 0x08000000 /* Flags for the feature selection in DT_FEATURE_1. */ -#define DTF_1_PARINIT 0x00000001 -#define DTF_1_CONFEXP 0x00000002 +#define DTF_1_PARINIT 0x00000001 +#define DTF_1_CONFEXP 0x00000002 /* Flags in the DT_POSFLAG_1 entry effecting only the next DT_* entry. */ -#define DF_P1_LAZYLOAD 0x00000001 /* Lazyload following object. */ -#define DF_P1_GROUPPERM 0x00000002 /* Symbols from next object are not - generally available. */ +#define DF_P1_LAZYLOAD 0x00000001 /* Lazyload following object. */ +#define DF_P1_GROUPPERM \ + 0x00000002 /* Symbols from next object are not \ + generally available. */ /* Version definition sections. */ -typedef struct -{ - Elf32_Half vd_version; /* Version revision */ - Elf32_Half vd_flags; /* Version information */ - Elf32_Half vd_ndx; /* Version Index */ - Elf32_Half vd_cnt; /* Number of associated aux entries */ - Elf32_Word vd_hash; /* Version name hash value */ - Elf32_Word vd_aux; /* Offset in bytes to verdaux array */ - Elf32_Word vd_next; /* Offset in bytes to next verdef - entry */ +typedef struct { + Elf32_Half vd_version; /* Version revision */ + Elf32_Half vd_flags; /* Version information */ + Elf32_Half vd_ndx; /* Version Index */ + Elf32_Half vd_cnt; /* Number of associated aux entries */ + Elf32_Word vd_hash; /* Version name hash value */ + Elf32_Word vd_aux; /* Offset in bytes to verdaux array */ + Elf32_Word vd_next; /* Offset in bytes to next verdef + entry */ } Elf32_Verdef; -typedef struct -{ - Elf64_Half vd_version; /* Version revision */ - Elf64_Half vd_flags; /* Version information */ - Elf64_Half vd_ndx; /* Version Index */ - Elf64_Half vd_cnt; /* Number of associated aux entries */ - Elf64_Word vd_hash; /* Version name hash value */ - Elf64_Word vd_aux; /* Offset in bytes to verdaux array */ - Elf64_Word vd_next; /* Offset in bytes to next verdef - entry */ +typedef struct { + Elf64_Half vd_version; /* Version revision */ + Elf64_Half vd_flags; /* Version information */ + Elf64_Half vd_ndx; /* Version Index */ + Elf64_Half vd_cnt; /* Number of associated aux entries */ + Elf64_Word vd_hash; /* Version name hash value */ + Elf64_Word vd_aux; /* Offset in bytes to verdaux array */ + Elf64_Word vd_next; /* Offset in bytes to next verdef + entry */ } Elf64_Verdef; - /* Legal values for vd_version (version revision). */ -#define VER_DEF_NONE 0 /* No version */ -#define VER_DEF_CURRENT 1 /* Current version */ -#define VER_DEF_NUM 2 /* Given version number */ +#define VER_DEF_NONE 0 /* No version */ +#define VER_DEF_CURRENT 1 /* Current version */ +#define VER_DEF_NUM 2 /* Given version number */ /* Legal values for vd_flags (version information flags). */ -#define VER_FLG_BASE 0x1 /* Version definition of file itself */ -#define VER_FLG_WEAK 0x2 /* Weak version identifier */ +#define VER_FLG_BASE 0x1 /* Version definition of file itself */ +#define VER_FLG_WEAK 0x2 /* Weak version identifier */ /* Versym symbol index values. */ -#define VER_NDX_LOCAL 0 /* Symbol is local. */ -#define VER_NDX_GLOBAL 1 /* Symbol is global. */ -#define VER_NDX_LORESERVE 0xff00 /* Beginning of reserved entries. */ -#define VER_NDX_ELIMINATE 0xff01 /* Symbol is to be eliminated. */ +#define VER_NDX_LOCAL 0 /* Symbol is local. */ +#define VER_NDX_GLOBAL 1 /* Symbol is global. */ +#define VER_NDX_LORESERVE 0xff00 /* Beginning of reserved entries. */ +#define VER_NDX_ELIMINATE 0xff01 /* Symbol is to be eliminated. */ /* Auxiliary version information. */ -typedef struct -{ - Elf32_Word vda_name; /* Version or dependency names */ - Elf32_Word vda_next; /* Offset in bytes to next verdaux - entry */ +typedef struct { + Elf32_Word vda_name; /* Version or dependency names */ + Elf32_Word vda_next; /* Offset in bytes to next verdaux + entry */ } Elf32_Verdaux; -typedef struct -{ - Elf64_Word vda_name; /* Version or dependency names */ - Elf64_Word vda_next; /* Offset in bytes to next verdaux - entry */ +typedef struct { + Elf64_Word vda_name; /* Version or dependency names */ + Elf64_Word vda_next; /* Offset in bytes to next verdaux + entry */ } Elf64_Verdaux; - /* Version dependency section. */ -typedef struct -{ - Elf32_Half vn_version; /* Version of structure */ - Elf32_Half vn_cnt; /* Number of associated aux entries */ - Elf32_Word vn_file; /* Offset of filename for this - dependency */ - Elf32_Word vn_aux; /* Offset in bytes to vernaux array */ - Elf32_Word vn_next; /* Offset in bytes to next verneed - entry */ +typedef struct { + Elf32_Half vn_version; /* Version of structure */ + Elf32_Half vn_cnt; /* Number of associated aux entries */ + Elf32_Word vn_file; /* Offset of filename for this + dependency */ + Elf32_Word vn_aux; /* Offset in bytes to vernaux array */ + Elf32_Word vn_next; /* Offset in bytes to next verneed + entry */ } Elf32_Verneed; -typedef struct -{ - Elf64_Half vn_version; /* Version of structure */ - Elf64_Half vn_cnt; /* Number of associated aux entries */ - Elf64_Word vn_file; /* Offset of filename for this - dependency */ - Elf64_Word vn_aux; /* Offset in bytes to vernaux array */ - Elf64_Word vn_next; /* Offset in bytes to next verneed - entry */ +typedef struct { + Elf64_Half vn_version; /* Version of structure */ + Elf64_Half vn_cnt; /* Number of associated aux entries */ + Elf64_Word vn_file; /* Offset of filename for this + dependency */ + Elf64_Word vn_aux; /* Offset in bytes to vernaux array */ + Elf64_Word vn_next; /* Offset in bytes to next verneed + entry */ } Elf64_Verneed; - /* Legal values for vn_version (version revision). */ -#define VER_NEED_NONE 0 /* No version */ -#define VER_NEED_CURRENT 1 /* Current version */ -#define VER_NEED_NUM 2 /* Given version number */ +#define VER_NEED_NONE 0 /* No version */ +#define VER_NEED_CURRENT 1 /* Current version */ +#define VER_NEED_NUM 2 /* Given version number */ /* Auxiliary needed version information. */ -typedef struct -{ - Elf32_Word vna_hash; /* Hash value of dependency name */ - Elf32_Half vna_flags; /* Dependency specific information */ - Elf32_Half vna_other; /* Unused */ - Elf32_Word vna_name; /* Dependency name string offset */ - Elf32_Word vna_next; /* Offset in bytes to next vernaux - entry */ +typedef struct { + Elf32_Word vna_hash; /* Hash value of dependency name */ + Elf32_Half vna_flags; /* Dependency specific information */ + Elf32_Half vna_other; /* Unused */ + Elf32_Word vna_name; /* Dependency name string offset */ + Elf32_Word vna_next; /* Offset in bytes to next vernaux + entry */ } Elf32_Vernaux; -typedef struct -{ - Elf64_Word vna_hash; /* Hash value of dependency name */ - Elf64_Half vna_flags; /* Dependency specific information */ - Elf64_Half vna_other; /* Unused */ - Elf64_Word vna_name; /* Dependency name string offset */ - Elf64_Word vna_next; /* Offset in bytes to next vernaux - entry */ +typedef struct { + Elf64_Word vna_hash; /* Hash value of dependency name */ + Elf64_Half vna_flags; /* Dependency specific information */ + Elf64_Half vna_other; /* Unused */ + Elf64_Word vna_name; /* Dependency name string offset */ + Elf64_Word vna_next; /* Offset in bytes to next vernaux + entry */ } Elf64_Vernaux; - /* Legal values for vna_flags. */ -#define VER_FLG_WEAK 0x2 /* Weak version identifier */ - +#define VER_FLG_WEAK 0x2 /* Weak version identifier */ /* Auxiliary vector. */ @@ -961,118 +934,111 @@ typedef struct types are an arrangement between the exec server and the program interpreter, so we don't fully specify them here. */ -typedef struct -{ - uint32_t a_type; /* Entry type */ - union - { - uint32_t a_val; /* Integer value */ - /* We use to have pointer elements added here. We cannot do that, - though, since it does not work when using 32-bit definitions - on 64-bit platforms and vice versa. */ - } a_un; +typedef struct { + uint32_t a_type; /* Entry type */ + union { + uint32_t a_val; /* Integer value */ + /* We use to have pointer elements added here. We cannot do that, + though, since it does not work when using 32-bit definitions + on 64-bit platforms and vice versa. */ + } a_un; } Elf32_auxv_t; -typedef struct -{ - uint64_t a_type; /* Entry type */ - union - { - uint64_t a_val; /* Integer value */ - /* We use to have pointer elements added here. We cannot do that, - though, since it does not work when using 32-bit definitions - on 64-bit platforms and vice versa. */ - } a_un; +typedef struct { + uint64_t a_type; /* Entry type */ + union { + uint64_t a_val; /* Integer value */ + /* We use to have pointer elements added here. We cannot do that, + though, since it does not work when using 32-bit definitions + on 64-bit platforms and vice versa. */ + } a_un; } Elf64_auxv_t; /* Legal values for a_type (entry type). */ -#define AT_NULL 0 /* End of vector */ -#define AT_IGNORE 1 /* Entry should be ignored */ -#define AT_EXECFD 2 /* File descriptor of program */ -#define AT_PHDR 3 /* Program headers for program */ -#define AT_PHENT 4 /* Size of program header entry */ -#define AT_PHNUM 5 /* Number of program headers */ -#define AT_PAGESZ 6 /* System page size */ -#define AT_BASE 7 /* Base address of interpreter */ -#define AT_FLAGS 8 /* Flags */ -#define AT_ENTRY 9 /* Entry point of program */ -#define AT_NOTELF 10 /* Program is not ELF */ -#define AT_UID 11 /* Real uid */ -#define AT_EUID 12 /* Effective uid */ -#define AT_GID 13 /* Real gid */ -#define AT_EGID 14 /* Effective gid */ -#define AT_CLKTCK 17 /* Frequency of times() */ +#define AT_NULL 0 /* End of vector */ +#define AT_IGNORE 1 /* Entry should be ignored */ +#define AT_EXECFD 2 /* File descriptor of program */ +#define AT_PHDR 3 /* Program headers for program */ +#define AT_PHENT 4 /* Size of program header entry */ +#define AT_PHNUM 5 /* Number of program headers */ +#define AT_PAGESZ 6 /* System page size */ +#define AT_BASE 7 /* Base address of interpreter */ +#define AT_FLAGS 8 /* Flags */ +#define AT_ENTRY 9 /* Entry point of program */ +#define AT_NOTELF 10 /* Program is not ELF */ +#define AT_UID 11 /* Real uid */ +#define AT_EUID 12 /* Effective uid */ +#define AT_GID 13 /* Real gid */ +#define AT_EGID 14 /* Effective gid */ +#define AT_CLKTCK 17 /* Frequency of times() */ /* Some more special a_type values describing the hardware. */ -#define AT_PLATFORM 15 /* String identifying platform. */ -#define AT_HWCAP 16 /* Machine dependent hints about - processor capabilities. */ +#define AT_PLATFORM 15 /* String identifying platform. */ +#define AT_HWCAP \ + 16 /* Machine dependent hints about \ + processor capabilities. */ /* This entry gives some information about the FPU initialization performed by the kernel. */ -#define AT_FPUCW 18 /* Used FPU control word. */ +#define AT_FPUCW 18 /* Used FPU control word. */ /* Cache block sizes. */ -#define AT_DCACHEBSIZE 19 /* Data cache block size. */ -#define AT_ICACHEBSIZE 20 /* Instruction cache block size. */ -#define AT_UCACHEBSIZE 21 /* Unified cache block size. */ +#define AT_DCACHEBSIZE 19 /* Data cache block size. */ +#define AT_ICACHEBSIZE 20 /* Instruction cache block size. */ +#define AT_UCACHEBSIZE 21 /* Unified cache block size. */ /* A special ignored value for PPC, used by the kernel to control the interpretation of the AUXV. Must be > 16. */ -#define AT_IGNOREPPC 22 /* Entry should be ignored. */ +#define AT_IGNOREPPC 22 /* Entry should be ignored. */ -#define AT_SECURE 23 /* Boolean, was exec setuid-like? */ +#define AT_SECURE 23 /* Boolean, was exec setuid-like? */ -#define AT_BASE_PLATFORM 24 /* String identifying real platforms.*/ +#define AT_BASE_PLATFORM 24 /* String identifying real platforms.*/ -#define AT_RANDOM 25 /* Address of 16 random bytes. */ +#define AT_RANDOM 25 /* Address of 16 random bytes. */ -#define AT_EXECFN 31 /* Filename of executable. */ +#define AT_EXECFN 31 /* Filename of executable. */ /* Pointer to the global system page used for system calls and other nice things. */ -#define AT_SYSINFO 32 -#define AT_SYSINFO_EHDR 33 +#define AT_SYSINFO 32 +#define AT_SYSINFO_EHDR 33 /* Shapes of the caches. Bits 0-3 contains associativity; bits 4-7 contains log2 of line size; mask those to get cache size. */ -#define AT_L1I_CACHESHAPE 34 -#define AT_L1D_CACHESHAPE 35 -#define AT_L2_CACHESHAPE 36 -#define AT_L3_CACHESHAPE 37 +#define AT_L1I_CACHESHAPE 34 +#define AT_L1D_CACHESHAPE 35 +#define AT_L2_CACHESHAPE 36 +#define AT_L3_CACHESHAPE 37 /* Note section contents. Each entry in the note section begins with a header of a fixed form. */ -typedef struct -{ - Elf32_Word n_namesz; /* Length of the note's name. */ - Elf32_Word n_descsz; /* Length of the note's descriptor. */ - Elf32_Word n_type; /* Type of the note. */ +typedef struct { + Elf32_Word n_namesz; /* Length of the note's name. */ + Elf32_Word n_descsz; /* Length of the note's descriptor. */ + Elf32_Word n_type; /* Type of the note. */ } Elf32_Nhdr; -typedef struct -{ - Elf64_Word n_namesz; /* Length of the note's name. */ - Elf64_Word n_descsz; /* Length of the note's descriptor. */ - Elf64_Word n_type; /* Type of the note. */ +typedef struct { + Elf64_Word n_namesz; /* Length of the note's name. */ + Elf64_Word n_descsz; /* Length of the note's descriptor. */ + Elf64_Word n_type; /* Type of the note. */ } Elf64_Nhdr; /* Known names of notes. */ /* Solaris entries in the note section have this name. */ -#define ELF_NOTE_SOLARIS "SUNW Solaris" +#define ELF_NOTE_SOLARIS "SUNW Solaris" /* Note entries for GNU systems have this name. */ -#define ELF_NOTE_GNU "GNU" - +#define ELF_NOTE_GNU "GNU" /* Defined types of notes for Solaris. */ /* Value of descriptor (one word) is desired pagesize for the binary. */ -#define ELF_NOTE_PAGESIZE_HINT 1 - +#define ELF_NOTE_PAGESIZE_HINT 1 /* Defined note types for GNU systems. */ @@ -1082,15 +1048,15 @@ typedef struct word 2: minor version of the ABI word 3: subminor version of the ABI */ -#define NT_GNU_ABI_TAG 1 -#define ELF_NOTE_ABI NT_GNU_ABI_TAG /* Old name. */ +#define NT_GNU_ABI_TAG 1 +#define ELF_NOTE_ABI NT_GNU_ABI_TAG /* Old name. */ /* Known OSes. These values can appear in word 0 of an NT_GNU_ABI_TAG note section entry. */ -#define ELF_NOTE_OS_LINUX 0 -#define ELF_NOTE_OS_GNU 1 -#define ELF_NOTE_OS_SOLARIS2 2 -#define ELF_NOTE_OS_FREEBSD 3 +#define ELF_NOTE_OS_LINUX 0 +#define ELF_NOTE_OS_GNU 1 +#define ELF_NOTE_OS_SOLARIS2 2 +#define ELF_NOTE_OS_FREEBSD 3 /* Synthetic hwcap information. The descriptor begins with two words: word 0: number of entries @@ -1098,2114 +1064,2187 @@ typedef struct Then follow variable-length entries, one byte followed by a '\0'-terminated hwcap name string. The byte gives the bit number to test if enabled, (1U << bit) & bitmask. */ -#define NT_GNU_HWCAP 2 +#define NT_GNU_HWCAP 2 /* Build ID bits as generated by ld --build-id. The descriptor consists of any nonzero number of bytes. */ -#define NT_GNU_BUILD_ID 3 +#define NT_GNU_BUILD_ID 3 /* Version note generated by GNU gold containing a version string. */ -#define NT_GNU_GOLD_VERSION 4 - +#define NT_GNU_GOLD_VERSION 4 /* Move records. */ -typedef struct -{ - Elf32_Xword m_value; /* Symbol value. */ - Elf32_Word m_info; /* Size and index. */ - Elf32_Word m_poffset; /* Symbol offset. */ - Elf32_Half m_repeat; /* Repeat count. */ - Elf32_Half m_stride; /* Stride info. */ +typedef struct { + Elf32_Xword m_value; /* Symbol value. */ + Elf32_Word m_info; /* Size and index. */ + Elf32_Word m_poffset; /* Symbol offset. */ + Elf32_Half m_repeat; /* Repeat count. */ + Elf32_Half m_stride; /* Stride info. */ } Elf32_Move; -typedef struct -{ - Elf64_Xword m_value; /* Symbol value. */ - Elf64_Xword m_info; /* Size and index. */ - Elf64_Xword m_poffset; /* Symbol offset. */ - Elf64_Half m_repeat; /* Repeat count. */ - Elf64_Half m_stride; /* Stride info. */ +typedef struct { + Elf64_Xword m_value; /* Symbol value. */ + Elf64_Xword m_info; /* Size and index. */ + Elf64_Xword m_poffset; /* Symbol offset. */ + Elf64_Half m_repeat; /* Repeat count. */ + Elf64_Half m_stride; /* Stride info. */ } Elf64_Move; /* Macro to construct move records. */ -#define ELF32_M_SYM(info) ((info) >> 8) -#define ELF32_M_SIZE(info) ((unsigned char) (info)) -#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char) (size)) - -#define ELF64_M_SYM(info) ELF32_M_SYM (info) -#define ELF64_M_SIZE(info) ELF32_M_SIZE (info) -#define ELF64_M_INFO(sym, size) ELF32_M_INFO (sym, size) +#define ELF32_M_SYM(info) ((info) >> 8) +#define ELF32_M_SIZE(info) ((unsigned char)(info)) +#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size)) +#define ELF64_M_SYM(info) ELF32_M_SYM(info) +#define ELF64_M_SIZE(info) ELF32_M_SIZE(info) +#define ELF64_M_INFO(sym, size) ELF32_M_INFO(sym, size) /* Motorola 68k specific definitions. */ /* Values for Elf32_Ehdr.e_flags. */ -#define EF_CPU32 0x00810000 +#define EF_CPU32 0x00810000 /* m68k relocs. */ -#define R_68K_NONE 0 /* No reloc */ -#define R_68K_32 1 /* Direct 32 bit */ -#define R_68K_16 2 /* Direct 16 bit */ -#define R_68K_8 3 /* Direct 8 bit */ -#define R_68K_PC32 4 /* PC relative 32 bit */ -#define R_68K_PC16 5 /* PC relative 16 bit */ -#define R_68K_PC8 6 /* PC relative 8 bit */ -#define R_68K_GOT32 7 /* 32 bit PC relative GOT entry */ -#define R_68K_GOT16 8 /* 16 bit PC relative GOT entry */ -#define R_68K_GOT8 9 /* 8 bit PC relative GOT entry */ -#define R_68K_GOT32O 10 /* 32 bit GOT offset */ -#define R_68K_GOT16O 11 /* 16 bit GOT offset */ -#define R_68K_GOT8O 12 /* 8 bit GOT offset */ -#define R_68K_PLT32 13 /* 32 bit PC relative PLT address */ -#define R_68K_PLT16 14 /* 16 bit PC relative PLT address */ -#define R_68K_PLT8 15 /* 8 bit PC relative PLT address */ -#define R_68K_PLT32O 16 /* 32 bit PLT offset */ -#define R_68K_PLT16O 17 /* 16 bit PLT offset */ -#define R_68K_PLT8O 18 /* 8 bit PLT offset */ -#define R_68K_COPY 19 /* Copy symbol at runtime */ -#define R_68K_GLOB_DAT 20 /* Create GOT entry */ -#define R_68K_JMP_SLOT 21 /* Create PLT entry */ -#define R_68K_RELATIVE 22 /* Adjust by program base */ -#define R_68K_TLS_GD32 25 /* 32 bit GOT offset for GD */ -#define R_68K_TLS_GD16 26 /* 16 bit GOT offset for GD */ -#define R_68K_TLS_GD8 27 /* 8 bit GOT offset for GD */ -#define R_68K_TLS_LDM32 28 /* 32 bit GOT offset for LDM */ -#define R_68K_TLS_LDM16 29 /* 16 bit GOT offset for LDM */ -#define R_68K_TLS_LDM8 30 /* 8 bit GOT offset for LDM */ -#define R_68K_TLS_LDO32 31 /* 32 bit module-relative offset */ -#define R_68K_TLS_LDO16 32 /* 16 bit module-relative offset */ -#define R_68K_TLS_LDO8 33 /* 8 bit module-relative offset */ -#define R_68K_TLS_IE32 34 /* 32 bit GOT offset for IE */ -#define R_68K_TLS_IE16 35 /* 16 bit GOT offset for IE */ -#define R_68K_TLS_IE8 36 /* 8 bit GOT offset for IE */ -#define R_68K_TLS_LE32 37 /* 32 bit offset relative to - static TLS block */ -#define R_68K_TLS_LE16 38 /* 16 bit offset relative to - static TLS block */ -#define R_68K_TLS_LE8 39 /* 8 bit offset relative to - static TLS block */ -#define R_68K_TLS_DTPMOD32 40 /* 32 bit module number */ -#define R_68K_TLS_DTPREL32 41 /* 32 bit module-relative offset */ -#define R_68K_TLS_TPREL32 42 /* 32 bit TP-relative offset */ +#define R_68K_NONE 0 /* No reloc */ +#define R_68K_32 1 /* Direct 32 bit */ +#define R_68K_16 2 /* Direct 16 bit */ +#define R_68K_8 3 /* Direct 8 bit */ +#define R_68K_PC32 4 /* PC relative 32 bit */ +#define R_68K_PC16 5 /* PC relative 16 bit */ +#define R_68K_PC8 6 /* PC relative 8 bit */ +#define R_68K_GOT32 7 /* 32 bit PC relative GOT entry */ +#define R_68K_GOT16 8 /* 16 bit PC relative GOT entry */ +#define R_68K_GOT8 9 /* 8 bit PC relative GOT entry */ +#define R_68K_GOT32O 10 /* 32 bit GOT offset */ +#define R_68K_GOT16O 11 /* 16 bit GOT offset */ +#define R_68K_GOT8O 12 /* 8 bit GOT offset */ +#define R_68K_PLT32 13 /* 32 bit PC relative PLT address */ +#define R_68K_PLT16 14 /* 16 bit PC relative PLT address */ +#define R_68K_PLT8 15 /* 8 bit PC relative PLT address */ +#define R_68K_PLT32O 16 /* 32 bit PLT offset */ +#define R_68K_PLT16O 17 /* 16 bit PLT offset */ +#define R_68K_PLT8O 18 /* 8 bit PLT offset */ +#define R_68K_COPY 19 /* Copy symbol at runtime */ +#define R_68K_GLOB_DAT 20 /* Create GOT entry */ +#define R_68K_JMP_SLOT 21 /* Create PLT entry */ +#define R_68K_RELATIVE 22 /* Adjust by program base */ +#define R_68K_TLS_GD32 25 /* 32 bit GOT offset for GD */ +#define R_68K_TLS_GD16 26 /* 16 bit GOT offset for GD */ +#define R_68K_TLS_GD8 27 /* 8 bit GOT offset for GD */ +#define R_68K_TLS_LDM32 28 /* 32 bit GOT offset for LDM */ +#define R_68K_TLS_LDM16 29 /* 16 bit GOT offset for LDM */ +#define R_68K_TLS_LDM8 30 /* 8 bit GOT offset for LDM */ +#define R_68K_TLS_LDO32 31 /* 32 bit module-relative offset */ +#define R_68K_TLS_LDO16 32 /* 16 bit module-relative offset */ +#define R_68K_TLS_LDO8 33 /* 8 bit module-relative offset */ +#define R_68K_TLS_IE32 34 /* 32 bit GOT offset for IE */ +#define R_68K_TLS_IE16 35 /* 16 bit GOT offset for IE */ +#define R_68K_TLS_IE8 36 /* 8 bit GOT offset for IE */ +#define R_68K_TLS_LE32 \ + 37 /* 32 bit offset relative to \ + static TLS block */ +#define R_68K_TLS_LE16 \ + 38 /* 16 bit offset relative to \ + static TLS block */ +#define R_68K_TLS_LE8 \ + 39 /* 8 bit offset relative to \ + static TLS block */ +#define R_68K_TLS_DTPMOD32 40 /* 32 bit module number */ +#define R_68K_TLS_DTPREL32 41 /* 32 bit module-relative offset */ +#define R_68K_TLS_TPREL32 42 /* 32 bit TP-relative offset */ /* Keep this the last entry. */ -#define R_68K_NUM 43 +#define R_68K_NUM 43 /* Intel 80386 specific definitions. */ /* i386 relocs. */ -#define R_386_NONE 0 /* No reloc */ -#define R_386_32 1 /* Direct 32 bit */ -#define R_386_PC32 2 /* PC relative 32 bit */ -#define R_386_GOT32 3 /* 32 bit GOT entry */ -#define R_386_PLT32 4 /* 32 bit PLT address */ -#define R_386_COPY 5 /* Copy symbol at runtime */ -#define R_386_GLOB_DAT 6 /* Create GOT entry */ -#define R_386_JMP_SLOT 7 /* Create PLT entry */ -#define R_386_RELATIVE 8 /* Adjust by program base */ -#define R_386_GOTOFF 9 /* 32 bit offset to GOT */ -#define R_386_GOTPC 10 /* 32 bit PC relative offset to GOT */ -#define R_386_32PLT 11 -#define R_386_TLS_TPOFF 14 /* Offset in static TLS block */ -#define R_386_TLS_IE 15 /* Address of GOT entry for static TLS - block offset */ -#define R_386_TLS_GOTIE 16 /* GOT entry for static TLS block - offset */ -#define R_386_TLS_LE 17 /* Offset relative to static TLS - block */ -#define R_386_TLS_GD 18 /* Direct 32 bit for GNU version of - general dynamic thread local data */ -#define R_386_TLS_LDM 19 /* Direct 32 bit for GNU version of - local dynamic thread local data - in LE code */ -#define R_386_16 20 -#define R_386_PC16 21 -#define R_386_8 22 -#define R_386_PC8 23 -#define R_386_TLS_GD_32 24 /* Direct 32 bit for general dynamic - thread local data */ -#define R_386_TLS_GD_PUSH 25 /* Tag for pushl in GD TLS code */ -#define R_386_TLS_GD_CALL 26 /* Relocation for call to - __tls_get_addr() */ -#define R_386_TLS_GD_POP 27 /* Tag for popl in GD TLS code */ -#define R_386_TLS_LDM_32 28 /* Direct 32 bit for local dynamic - thread local data in LE code */ -#define R_386_TLS_LDM_PUSH 29 /* Tag for pushl in LDM TLS code */ -#define R_386_TLS_LDM_CALL 30 /* Relocation for call to - __tls_get_addr() in LDM code */ -#define R_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */ -#define R_386_TLS_LDO_32 32 /* Offset relative to TLS block */ -#define R_386_TLS_IE_32 33 /* GOT entry for negated static TLS - block offset */ -#define R_386_TLS_LE_32 34 /* Negated offset relative to static - TLS block */ -#define R_386_TLS_DTPMOD32 35 /* ID of module containing symbol */ -#define R_386_TLS_DTPOFF32 36 /* Offset in TLS block */ -#define R_386_TLS_TPOFF32 37 /* Negated offset in static TLS block */ +#define R_386_NONE 0 /* No reloc */ +#define R_386_32 1 /* Direct 32 bit */ +#define R_386_PC32 2 /* PC relative 32 bit */ +#define R_386_GOT32 3 /* 32 bit GOT entry */ +#define R_386_PLT32 4 /* 32 bit PLT address */ +#define R_386_COPY 5 /* Copy symbol at runtime */ +#define R_386_GLOB_DAT 6 /* Create GOT entry */ +#define R_386_JMP_SLOT 7 /* Create PLT entry */ +#define R_386_RELATIVE 8 /* Adjust by program base */ +#define R_386_GOTOFF 9 /* 32 bit offset to GOT */ +#define R_386_GOTPC 10 /* 32 bit PC relative offset to GOT */ +#define R_386_32PLT 11 +#define R_386_TLS_TPOFF 14 /* Offset in static TLS block */ +#define R_386_TLS_IE \ + 15 /* Address of GOT entry for static TLS \ + block offset */ +#define R_386_TLS_GOTIE \ + 16 /* GOT entry for static TLS block \ + offset */ +#define R_386_TLS_LE \ + 17 /* Offset relative to static TLS \ + block */ +#define R_386_TLS_GD \ + 18 /* Direct 32 bit for GNU version of \ + general dynamic thread local data */ +#define R_386_TLS_LDM \ + 19 /* Direct 32 bit for GNU version of \ + local dynamic thread local data \ + in LE code */ +#define R_386_16 20 +#define R_386_PC16 21 +#define R_386_8 22 +#define R_386_PC8 23 +#define R_386_TLS_GD_32 \ + 24 /* Direct 32 bit for general dynamic \ + thread local data */ +#define R_386_TLS_GD_PUSH 25 /* Tag for pushl in GD TLS code */ +#define R_386_TLS_GD_CALL \ + 26 /* Relocation for call to \ + __tls_get_addr() */ +#define R_386_TLS_GD_POP 27 /* Tag for popl in GD TLS code */ +#define R_386_TLS_LDM_32 \ + 28 /* Direct 32 bit for local dynamic \ + thread local data in LE code */ +#define R_386_TLS_LDM_PUSH 29 /* Tag for pushl in LDM TLS code */ +#define R_386_TLS_LDM_CALL \ + 30 /* Relocation for call to \ + __tls_get_addr() in LDM code */ +#define R_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */ +#define R_386_TLS_LDO_32 32 /* Offset relative to TLS block */ +#define R_386_TLS_IE_32 \ + 33 /* GOT entry for negated static TLS \ + block offset */ +#define R_386_TLS_LE_32 \ + 34 /* Negated offset relative to static \ + TLS block */ +#define R_386_TLS_DTPMOD32 35 /* ID of module containing symbol */ +#define R_386_TLS_DTPOFF32 36 /* Offset in TLS block */ +#define R_386_TLS_TPOFF32 37 /* Negated offset in static TLS block */ /* 38? */ -#define R_386_TLS_GOTDESC 39 /* GOT offset for TLS descriptor. */ -#define R_386_TLS_DESC_CALL 40 /* Marker of call through TLS - descriptor for - relaxation. */ -#define R_386_TLS_DESC 41 /* TLS descriptor containing - pointer to code and to - argument, returning the TLS - offset for the symbol. */ -#define R_386_IRELATIVE 42 /* Adjust indirectly by program base */ -#define R_386_GOT32X 43 /* 32 bit GOT entry, relaxable */ +#define R_386_TLS_GOTDESC 39 /* GOT offset for TLS descriptor. */ +#define R_386_TLS_DESC_CALL \ + 40 /* Marker of call through TLS \ + descriptor for \ + relaxation. */ +#define R_386_TLS_DESC \ + 41 /* TLS descriptor containing \ + pointer to code and to \ + argument, returning the TLS \ + offset for the symbol. */ +#define R_386_IRELATIVE 42 /* Adjust indirectly by program base */ +#define R_386_GOT32X 43 /* 32 bit GOT entry, relaxable */ /* Keep this the last entry. */ -#define R_386_NUM 44 +#define R_386_NUM 44 /* SUN SPARC specific definitions. */ /* Legal values for ST_TYPE subfield of st_info (symbol type). */ -#define STT_SPARC_REGISTER 13 /* Global register reserved to app. */ +#define STT_SPARC_REGISTER 13 /* Global register reserved to app. */ /* Values for Elf64_Ehdr.e_flags. */ -#define EF_SPARCV9_MM 3 -#define EF_SPARCV9_TSO 0 -#define EF_SPARCV9_PSO 1 -#define EF_SPARCV9_RMO 2 -#define EF_SPARC_LEDATA 0x800000 /* little endian data */ -#define EF_SPARC_EXT_MASK 0xFFFF00 -#define EF_SPARC_32PLUS 0x000100 /* generic V8+ features */ -#define EF_SPARC_SUN_US1 0x000200 /* Sun UltraSPARC1 extensions */ -#define EF_SPARC_HAL_R1 0x000400 /* HAL R1 extensions */ -#define EF_SPARC_SUN_US3 0x000800 /* Sun UltraSPARCIII extensions */ +#define EF_SPARCV9_MM 3 +#define EF_SPARCV9_TSO 0 +#define EF_SPARCV9_PSO 1 +#define EF_SPARCV9_RMO 2 +#define EF_SPARC_LEDATA 0x800000 /* little endian data */ +#define EF_SPARC_EXT_MASK 0xFFFF00 +#define EF_SPARC_32PLUS 0x000100 /* generic V8+ features */ +#define EF_SPARC_SUN_US1 0x000200 /* Sun UltraSPARC1 extensions */ +#define EF_SPARC_HAL_R1 0x000400 /* HAL R1 extensions */ +#define EF_SPARC_SUN_US3 0x000800 /* Sun UltraSPARCIII extensions */ /* SPARC relocs. */ -#define R_SPARC_NONE 0 /* No reloc */ -#define R_SPARC_8 1 /* Direct 8 bit */ -#define R_SPARC_16 2 /* Direct 16 bit */ -#define R_SPARC_32 3 /* Direct 32 bit */ -#define R_SPARC_DISP8 4 /* PC relative 8 bit */ -#define R_SPARC_DISP16 5 /* PC relative 16 bit */ -#define R_SPARC_DISP32 6 /* PC relative 32 bit */ -#define R_SPARC_WDISP30 7 /* PC relative 30 bit shifted */ -#define R_SPARC_WDISP22 8 /* PC relative 22 bit shifted */ -#define R_SPARC_HI22 9 /* High 22 bit */ -#define R_SPARC_22 10 /* Direct 22 bit */ -#define R_SPARC_13 11 /* Direct 13 bit */ -#define R_SPARC_LO10 12 /* Truncated 10 bit */ -#define R_SPARC_GOT10 13 /* Truncated 10 bit GOT entry */ -#define R_SPARC_GOT13 14 /* 13 bit GOT entry */ -#define R_SPARC_GOT22 15 /* 22 bit GOT entry shifted */ -#define R_SPARC_PC10 16 /* PC relative 10 bit truncated */ -#define R_SPARC_PC22 17 /* PC relative 22 bit shifted */ -#define R_SPARC_WPLT30 18 /* 30 bit PC relative PLT address */ -#define R_SPARC_COPY 19 /* Copy symbol at runtime */ -#define R_SPARC_GLOB_DAT 20 /* Create GOT entry */ -#define R_SPARC_JMP_SLOT 21 /* Create PLT entry */ -#define R_SPARC_RELATIVE 22 /* Adjust by program base */ -#define R_SPARC_UA32 23 /* Direct 32 bit unaligned */ +#define R_SPARC_NONE 0 /* No reloc */ +#define R_SPARC_8 1 /* Direct 8 bit */ +#define R_SPARC_16 2 /* Direct 16 bit */ +#define R_SPARC_32 3 /* Direct 32 bit */ +#define R_SPARC_DISP8 4 /* PC relative 8 bit */ +#define R_SPARC_DISP16 5 /* PC relative 16 bit */ +#define R_SPARC_DISP32 6 /* PC relative 32 bit */ +#define R_SPARC_WDISP30 7 /* PC relative 30 bit shifted */ +#define R_SPARC_WDISP22 8 /* PC relative 22 bit shifted */ +#define R_SPARC_HI22 9 /* High 22 bit */ +#define R_SPARC_22 10 /* Direct 22 bit */ +#define R_SPARC_13 11 /* Direct 13 bit */ +#define R_SPARC_LO10 12 /* Truncated 10 bit */ +#define R_SPARC_GOT10 13 /* Truncated 10 bit GOT entry */ +#define R_SPARC_GOT13 14 /* 13 bit GOT entry */ +#define R_SPARC_GOT22 15 /* 22 bit GOT entry shifted */ +#define R_SPARC_PC10 16 /* PC relative 10 bit truncated */ +#define R_SPARC_PC22 17 /* PC relative 22 bit shifted */ +#define R_SPARC_WPLT30 18 /* 30 bit PC relative PLT address */ +#define R_SPARC_COPY 19 /* Copy symbol at runtime */ +#define R_SPARC_GLOB_DAT 20 /* Create GOT entry */ +#define R_SPARC_JMP_SLOT 21 /* Create PLT entry */ +#define R_SPARC_RELATIVE 22 /* Adjust by program base */ +#define R_SPARC_UA32 23 /* Direct 32 bit unaligned */ /* Additional Sparc64 relocs. */ -#define R_SPARC_PLT32 24 /* Direct 32 bit ref to PLT entry */ -#define R_SPARC_HIPLT22 25 /* High 22 bit PLT entry */ -#define R_SPARC_LOPLT10 26 /* Truncated 10 bit PLT entry */ -#define R_SPARC_PCPLT32 27 /* PC rel 32 bit ref to PLT entry */ -#define R_SPARC_PCPLT22 28 /* PC rel high 22 bit PLT entry */ -#define R_SPARC_PCPLT10 29 /* PC rel trunc 10 bit PLT entry */ -#define R_SPARC_10 30 /* Direct 10 bit */ -#define R_SPARC_11 31 /* Direct 11 bit */ -#define R_SPARC_64 32 /* Direct 64 bit */ -#define R_SPARC_OLO10 33 /* 10bit with secondary 13bit addend */ -#define R_SPARC_HH22 34 /* Top 22 bits of direct 64 bit */ -#define R_SPARC_HM10 35 /* High middle 10 bits of ... */ -#define R_SPARC_LM22 36 /* Low middle 22 bits of ... */ -#define R_SPARC_PC_HH22 37 /* Top 22 bits of pc rel 64 bit */ -#define R_SPARC_PC_HM10 38 /* High middle 10 bit of ... */ -#define R_SPARC_PC_LM22 39 /* Low middle 22 bits of ... */ -#define R_SPARC_WDISP16 40 /* PC relative 16 bit shifted */ -#define R_SPARC_WDISP19 41 /* PC relative 19 bit shifted */ -#define R_SPARC_GLOB_JMP 42 /* was part of v9 ABI but was removed */ -#define R_SPARC_7 43 /* Direct 7 bit */ -#define R_SPARC_5 44 /* Direct 5 bit */ -#define R_SPARC_6 45 /* Direct 6 bit */ -#define R_SPARC_DISP64 46 /* PC relative 64 bit */ -#define R_SPARC_PLT64 47 /* Direct 64 bit ref to PLT entry */ -#define R_SPARC_HIX22 48 /* High 22 bit complemented */ -#define R_SPARC_LOX10 49 /* Truncated 11 bit complemented */ -#define R_SPARC_H44 50 /* Direct high 12 of 44 bit */ -#define R_SPARC_M44 51 /* Direct mid 22 of 44 bit */ -#define R_SPARC_L44 52 /* Direct low 10 of 44 bit */ -#define R_SPARC_REGISTER 53 /* Global register usage */ -#define R_SPARC_UA64 54 /* Direct 64 bit unaligned */ -#define R_SPARC_UA16 55 /* Direct 16 bit unaligned */ -#define R_SPARC_TLS_GD_HI22 56 -#define R_SPARC_TLS_GD_LO10 57 -#define R_SPARC_TLS_GD_ADD 58 -#define R_SPARC_TLS_GD_CALL 59 -#define R_SPARC_TLS_LDM_HI22 60 -#define R_SPARC_TLS_LDM_LO10 61 -#define R_SPARC_TLS_LDM_ADD 62 -#define R_SPARC_TLS_LDM_CALL 63 -#define R_SPARC_TLS_LDO_HIX22 64 -#define R_SPARC_TLS_LDO_LOX10 65 -#define R_SPARC_TLS_LDO_ADD 66 -#define R_SPARC_TLS_IE_HI22 67 -#define R_SPARC_TLS_IE_LO10 68 -#define R_SPARC_TLS_IE_LD 69 -#define R_SPARC_TLS_IE_LDX 70 -#define R_SPARC_TLS_IE_ADD 71 -#define R_SPARC_TLS_LE_HIX22 72 -#define R_SPARC_TLS_LE_LOX10 73 -#define R_SPARC_TLS_DTPMOD32 74 -#define R_SPARC_TLS_DTPMOD64 75 -#define R_SPARC_TLS_DTPOFF32 76 -#define R_SPARC_TLS_DTPOFF64 77 -#define R_SPARC_TLS_TPOFF32 78 -#define R_SPARC_TLS_TPOFF64 79 -#define R_SPARC_GOTDATA_HIX22 80 -#define R_SPARC_GOTDATA_LOX10 81 -#define R_SPARC_GOTDATA_OP_HIX22 82 -#define R_SPARC_GOTDATA_OP_LOX10 83 -#define R_SPARC_GOTDATA_OP 84 -#define R_SPARC_H34 85 -#define R_SPARC_SIZE32 86 -#define R_SPARC_SIZE64 87 -#define R_SPARC_WDISP10 88 -#define R_SPARC_JMP_IREL 248 -#define R_SPARC_IRELATIVE 249 -#define R_SPARC_GNU_VTINHERIT 250 -#define R_SPARC_GNU_VTENTRY 251 -#define R_SPARC_REV32 252 +#define R_SPARC_PLT32 24 /* Direct 32 bit ref to PLT entry */ +#define R_SPARC_HIPLT22 25 /* High 22 bit PLT entry */ +#define R_SPARC_LOPLT10 26 /* Truncated 10 bit PLT entry */ +#define R_SPARC_PCPLT32 27 /* PC rel 32 bit ref to PLT entry */ +#define R_SPARC_PCPLT22 28 /* PC rel high 22 bit PLT entry */ +#define R_SPARC_PCPLT10 29 /* PC rel trunc 10 bit PLT entry */ +#define R_SPARC_10 30 /* Direct 10 bit */ +#define R_SPARC_11 31 /* Direct 11 bit */ +#define R_SPARC_64 32 /* Direct 64 bit */ +#define R_SPARC_OLO10 33 /* 10bit with secondary 13bit addend */ +#define R_SPARC_HH22 34 /* Top 22 bits of direct 64 bit */ +#define R_SPARC_HM10 35 /* High middle 10 bits of ... */ +#define R_SPARC_LM22 36 /* Low middle 22 bits of ... */ +#define R_SPARC_PC_HH22 37 /* Top 22 bits of pc rel 64 bit */ +#define R_SPARC_PC_HM10 38 /* High middle 10 bit of ... */ +#define R_SPARC_PC_LM22 39 /* Low middle 22 bits of ... */ +#define R_SPARC_WDISP16 40 /* PC relative 16 bit shifted */ +#define R_SPARC_WDISP19 41 /* PC relative 19 bit shifted */ +#define R_SPARC_GLOB_JMP 42 /* was part of v9 ABI but was removed */ +#define R_SPARC_7 43 /* Direct 7 bit */ +#define R_SPARC_5 44 /* Direct 5 bit */ +#define R_SPARC_6 45 /* Direct 6 bit */ +#define R_SPARC_DISP64 46 /* PC relative 64 bit */ +#define R_SPARC_PLT64 47 /* Direct 64 bit ref to PLT entry */ +#define R_SPARC_HIX22 48 /* High 22 bit complemented */ +#define R_SPARC_LOX10 49 /* Truncated 11 bit complemented */ +#define R_SPARC_H44 50 /* Direct high 12 of 44 bit */ +#define R_SPARC_M44 51 /* Direct mid 22 of 44 bit */ +#define R_SPARC_L44 52 /* Direct low 10 of 44 bit */ +#define R_SPARC_REGISTER 53 /* Global register usage */ +#define R_SPARC_UA64 54 /* Direct 64 bit unaligned */ +#define R_SPARC_UA16 55 /* Direct 16 bit unaligned */ +#define R_SPARC_TLS_GD_HI22 56 +#define R_SPARC_TLS_GD_LO10 57 +#define R_SPARC_TLS_GD_ADD 58 +#define R_SPARC_TLS_GD_CALL 59 +#define R_SPARC_TLS_LDM_HI22 60 +#define R_SPARC_TLS_LDM_LO10 61 +#define R_SPARC_TLS_LDM_ADD 62 +#define R_SPARC_TLS_LDM_CALL 63 +#define R_SPARC_TLS_LDO_HIX22 64 +#define R_SPARC_TLS_LDO_LOX10 65 +#define R_SPARC_TLS_LDO_ADD 66 +#define R_SPARC_TLS_IE_HI22 67 +#define R_SPARC_TLS_IE_LO10 68 +#define R_SPARC_TLS_IE_LD 69 +#define R_SPARC_TLS_IE_LDX 70 +#define R_SPARC_TLS_IE_ADD 71 +#define R_SPARC_TLS_LE_HIX22 72 +#define R_SPARC_TLS_LE_LOX10 73 +#define R_SPARC_TLS_DTPMOD32 74 +#define R_SPARC_TLS_DTPMOD64 75 +#define R_SPARC_TLS_DTPOFF32 76 +#define R_SPARC_TLS_DTPOFF64 77 +#define R_SPARC_TLS_TPOFF32 78 +#define R_SPARC_TLS_TPOFF64 79 +#define R_SPARC_GOTDATA_HIX22 80 +#define R_SPARC_GOTDATA_LOX10 81 +#define R_SPARC_GOTDATA_OP_HIX22 82 +#define R_SPARC_GOTDATA_OP_LOX10 83 +#define R_SPARC_GOTDATA_OP 84 +#define R_SPARC_H34 85 +#define R_SPARC_SIZE32 86 +#define R_SPARC_SIZE64 87 +#define R_SPARC_WDISP10 88 +#define R_SPARC_JMP_IREL 248 +#define R_SPARC_IRELATIVE 249 +#define R_SPARC_GNU_VTINHERIT 250 +#define R_SPARC_GNU_VTENTRY 251 +#define R_SPARC_REV32 252 /* Keep this the last entry. */ -#define R_SPARC_NUM 253 +#define R_SPARC_NUM 253 /* For Sparc64, legal values for d_tag of Elf64_Dyn. */ #define DT_SPARC_REGISTER 0x70000001 -#define DT_SPARC_NUM 2 +#define DT_SPARC_NUM 2 /* MIPS R3000 specific definitions. */ /* Legal values for e_flags field of Elf32_Ehdr. */ -#define EF_MIPS_NOREORDER 1 /* A .noreorder directive was used */ -#define EF_MIPS_PIC 2 /* Contains PIC code */ -#define EF_MIPS_CPIC 4 /* Uses PIC calling sequence */ -#define EF_MIPS_XGOT 8 +#define EF_MIPS_NOREORDER 1 /* A .noreorder directive was used */ +#define EF_MIPS_PIC 2 /* Contains PIC code */ +#define EF_MIPS_CPIC 4 /* Uses PIC calling sequence */ +#define EF_MIPS_XGOT 8 #define EF_MIPS_64BIT_WHIRL 16 -#define EF_MIPS_ABI2 32 -#define EF_MIPS_ABI_ON32 64 -#define EF_MIPS_ARCH 0xf0000000 /* MIPS architecture level */ +#define EF_MIPS_ABI2 32 +#define EF_MIPS_ABI_ON32 64 +#define EF_MIPS_ARCH 0xf0000000 /* MIPS architecture level */ /* Legal values for MIPS architecture level. */ -#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ -#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ -#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ -#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ -#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ -#define EF_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ -#define EF_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ +#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ +#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ +#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ +#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ +#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ +#define EF_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ +#define EF_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ /* The following are non-official names and should not be used. */ -#define E_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ -#define E_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ -#define E_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ -#define E_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ -#define E_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ -#define E_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ -#define E_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ +#define E_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ +#define E_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ +#define E_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ +#define E_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ +#define E_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ +#define E_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ +#define E_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ /* Special section indices. */ -#define SHN_MIPS_ACOMMON 0xff00 /* Allocated common symbols */ -#define SHN_MIPS_TEXT 0xff01 /* Allocated test symbols. */ -#define SHN_MIPS_DATA 0xff02 /* Allocated data symbols. */ -#define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols */ -#define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols */ +#define SHN_MIPS_ACOMMON 0xff00 /* Allocated common symbols */ +#define SHN_MIPS_TEXT 0xff01 /* Allocated test symbols. */ +#define SHN_MIPS_DATA 0xff02 /* Allocated data symbols. */ +#define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols */ +#define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols */ /* Legal values for sh_type field of Elf32_Shdr. */ -#define SHT_MIPS_LIBLIST 0x70000000 /* Shared objects used in link */ -#define SHT_MIPS_MSYM 0x70000001 -#define SHT_MIPS_CONFLICT 0x70000002 /* Conflicting symbols */ -#define SHT_MIPS_GPTAB 0x70000003 /* Global data area sizes */ -#define SHT_MIPS_UCODE 0x70000004 /* Reserved for SGI/MIPS compilers */ -#define SHT_MIPS_DEBUG 0x70000005 /* MIPS ECOFF debugging information*/ -#define SHT_MIPS_REGINFO 0x70000006 /* Register usage information */ -#define SHT_MIPS_PACKAGE 0x70000007 -#define SHT_MIPS_PACKSYM 0x70000008 -#define SHT_MIPS_RELD 0x70000009 -#define SHT_MIPS_IFACE 0x7000000b -#define SHT_MIPS_CONTENT 0x7000000c -#define SHT_MIPS_OPTIONS 0x7000000d /* Miscellaneous options. */ -#define SHT_MIPS_SHDR 0x70000010 -#define SHT_MIPS_FDESC 0x70000011 -#define SHT_MIPS_EXTSYM 0x70000012 -#define SHT_MIPS_DENSE 0x70000013 -#define SHT_MIPS_PDESC 0x70000014 -#define SHT_MIPS_LOCSYM 0x70000015 -#define SHT_MIPS_AUXSYM 0x70000016 -#define SHT_MIPS_OPTSYM 0x70000017 -#define SHT_MIPS_LOCSTR 0x70000018 -#define SHT_MIPS_LINE 0x70000019 -#define SHT_MIPS_RFDESC 0x7000001a -#define SHT_MIPS_DELTASYM 0x7000001b -#define SHT_MIPS_DELTAINST 0x7000001c -#define SHT_MIPS_DELTACLASS 0x7000001d -#define SHT_MIPS_DWARF 0x7000001e /* DWARF debugging information. */ -#define SHT_MIPS_DELTADECL 0x7000001f -#define SHT_MIPS_SYMBOL_LIB 0x70000020 -#define SHT_MIPS_EVENTS 0x70000021 /* Event section. */ -#define SHT_MIPS_TRANSLATE 0x70000022 -#define SHT_MIPS_PIXIE 0x70000023 -#define SHT_MIPS_XLATE 0x70000024 -#define SHT_MIPS_XLATE_DEBUG 0x70000025 -#define SHT_MIPS_WHIRL 0x70000026 -#define SHT_MIPS_EH_REGION 0x70000027 -#define SHT_MIPS_XLATE_OLD 0x70000028 +#define SHT_MIPS_LIBLIST 0x70000000 /* Shared objects used in link */ +#define SHT_MIPS_MSYM 0x70000001 +#define SHT_MIPS_CONFLICT 0x70000002 /* Conflicting symbols */ +#define SHT_MIPS_GPTAB 0x70000003 /* Global data area sizes */ +#define SHT_MIPS_UCODE 0x70000004 /* Reserved for SGI/MIPS compilers */ +#define SHT_MIPS_DEBUG 0x70000005 /* MIPS ECOFF debugging information*/ +#define SHT_MIPS_REGINFO 0x70000006 /* Register usage information */ +#define SHT_MIPS_PACKAGE 0x70000007 +#define SHT_MIPS_PACKSYM 0x70000008 +#define SHT_MIPS_RELD 0x70000009 +#define SHT_MIPS_IFACE 0x7000000b +#define SHT_MIPS_CONTENT 0x7000000c +#define SHT_MIPS_OPTIONS 0x7000000d /* Miscellaneous options. */ +#define SHT_MIPS_SHDR 0x70000010 +#define SHT_MIPS_FDESC 0x70000011 +#define SHT_MIPS_EXTSYM 0x70000012 +#define SHT_MIPS_DENSE 0x70000013 +#define SHT_MIPS_PDESC 0x70000014 +#define SHT_MIPS_LOCSYM 0x70000015 +#define SHT_MIPS_AUXSYM 0x70000016 +#define SHT_MIPS_OPTSYM 0x70000017 +#define SHT_MIPS_LOCSTR 0x70000018 +#define SHT_MIPS_LINE 0x70000019 +#define SHT_MIPS_RFDESC 0x7000001a +#define SHT_MIPS_DELTASYM 0x7000001b +#define SHT_MIPS_DELTAINST 0x7000001c +#define SHT_MIPS_DELTACLASS 0x7000001d +#define SHT_MIPS_DWARF 0x7000001e /* DWARF debugging information. */ +#define SHT_MIPS_DELTADECL 0x7000001f +#define SHT_MIPS_SYMBOL_LIB 0x70000020 +#define SHT_MIPS_EVENTS 0x70000021 /* Event section. */ +#define SHT_MIPS_TRANSLATE 0x70000022 +#define SHT_MIPS_PIXIE 0x70000023 +#define SHT_MIPS_XLATE 0x70000024 +#define SHT_MIPS_XLATE_DEBUG 0x70000025 +#define SHT_MIPS_WHIRL 0x70000026 +#define SHT_MIPS_EH_REGION 0x70000027 +#define SHT_MIPS_XLATE_OLD 0x70000028 #define SHT_MIPS_PDR_EXCEPTION 0x70000029 /* Legal values for sh_flags field of Elf32_Shdr. */ -#define SHF_MIPS_GPREL 0x10000000 /* Must be part of global data area */ -#define SHF_MIPS_MERGE 0x20000000 -#define SHF_MIPS_ADDR 0x40000000 +#define SHF_MIPS_GPREL 0x10000000 /* Must be part of global data area */ +#define SHF_MIPS_MERGE 0x20000000 +#define SHF_MIPS_ADDR 0x40000000 #define SHF_MIPS_STRINGS 0x80000000 #define SHF_MIPS_NOSTRIP 0x08000000 -#define SHF_MIPS_LOCAL 0x04000000 -#define SHF_MIPS_NAMES 0x02000000 -#define SHF_MIPS_NODUPE 0x01000000 - +#define SHF_MIPS_LOCAL 0x04000000 +#define SHF_MIPS_NAMES 0x02000000 +#define SHF_MIPS_NODUPE 0x01000000 /* Symbol tables. */ /* MIPS specific values for `st_other'. */ -#define STO_MIPS_DEFAULT 0x0 -#define STO_MIPS_INTERNAL 0x1 -#define STO_MIPS_HIDDEN 0x2 -#define STO_MIPS_PROTECTED 0x3 -#define STO_MIPS_PLT 0x8 -#define STO_MIPS_SC_ALIGN_UNUSED 0xff +#define STO_MIPS_DEFAULT 0x0 +#define STO_MIPS_INTERNAL 0x1 +#define STO_MIPS_HIDDEN 0x2 +#define STO_MIPS_PROTECTED 0x3 +#define STO_MIPS_PLT 0x8 +#define STO_MIPS_SC_ALIGN_UNUSED 0xff /* MIPS specific values for `st_info'. */ -#define STB_MIPS_SPLIT_COMMON 13 +#define STB_MIPS_SPLIT_COMMON 13 /* Entries found in sections of type SHT_MIPS_GPTAB. */ -typedef union -{ - struct - { - Elf32_Word gt_current_g_value; /* -G value used for compilation */ - Elf32_Word gt_unused; /* Not used */ - } gt_header; /* First entry in section */ - struct - { - Elf32_Word gt_g_value; /* If this value were used for -G */ - Elf32_Word gt_bytes; /* This many bytes would be used */ - } gt_entry; /* Subsequent entries in section */ +typedef union { + struct { + Elf32_Word gt_current_g_value; /* -G value used for compilation */ + Elf32_Word gt_unused; /* Not used */ + } gt_header; /* First entry in section */ + struct { + Elf32_Word gt_g_value; /* If this value were used for -G */ + Elf32_Word gt_bytes; /* This many bytes would be used */ + } gt_entry; /* Subsequent entries in section */ } Elf32_gptab; /* Entry found in sections of type SHT_MIPS_REGINFO. */ -typedef struct -{ - Elf32_Word ri_gprmask; /* General registers used */ - Elf32_Word ri_cprmask[4]; /* Coprocessor registers used */ - Elf32_Sword ri_gp_value; /* $gp register value */ +typedef struct { + Elf32_Word ri_gprmask; /* General registers used */ + Elf32_Word ri_cprmask[4]; /* Coprocessor registers used */ + Elf32_Sword ri_gp_value; /* $gp register value */ } Elf32_RegInfo; /* Entries found in sections of type SHT_MIPS_OPTIONS. */ -typedef struct -{ - unsigned char kind; /* Determines interpretation of the - variable part of descriptor. */ - unsigned char size; /* Size of descriptor, including header. */ - Elf32_Section section; /* Section header index of section affected, - 0 for global options. */ - Elf32_Word info; /* Kind-specific information. */ +typedef struct { + unsigned char kind; /* Determines interpretation of the + variable part of descriptor. */ + unsigned char size; /* Size of descriptor, including header. */ + Elf32_Section section; /* Section header index of section affected, + 0 for global options. */ + Elf32_Word info; /* Kind-specific information. */ } Elf_Options; /* Values for `kind' field in Elf_Options. */ -#define ODK_NULL 0 /* Undefined. */ -#define ODK_REGINFO 1 /* Register usage information. */ -#define ODK_EXCEPTIONS 2 /* Exception processing options. */ -#define ODK_PAD 3 /* Section padding options. */ -#define ODK_HWPATCH 4 /* Hardware workarounds performed */ -#define ODK_FILL 5 /* record the fill value used by the linker. */ -#define ODK_TAGS 6 /* reserve space for desktop tools to write. */ -#define ODK_HWAND 7 /* HW workarounds. 'AND' bits when merging. */ -#define ODK_HWOR 8 /* HW workarounds. 'OR' bits when merging. */ +#define ODK_NULL 0 /* Undefined. */ +#define ODK_REGINFO 1 /* Register usage information. */ +#define ODK_EXCEPTIONS 2 /* Exception processing options. */ +#define ODK_PAD 3 /* Section padding options. */ +#define ODK_HWPATCH 4 /* Hardware workarounds performed */ +#define ODK_FILL 5 /* record the fill value used by the linker. */ +#define ODK_TAGS 6 /* reserve space for desktop tools to write. */ +#define ODK_HWAND 7 /* HW workarounds. 'AND' bits when merging. */ +#define ODK_HWOR 8 /* HW workarounds. 'OR' bits when merging. */ /* Values for `info' in Elf_Options for ODK_EXCEPTIONS entries. */ -#define OEX_FPU_MIN 0x1f /* FPE's which MUST be enabled. */ -#define OEX_FPU_MAX 0x1f00 /* FPE's which MAY be enabled. */ -#define OEX_PAGE0 0x10000 /* page zero must be mapped. */ -#define OEX_SMM 0x20000 /* Force sequential memory mode? */ -#define OEX_FPDBUG 0x40000 /* Force floating point debug mode? */ -#define OEX_PRECISEFP OEX_FPDBUG -#define OEX_DISMISS 0x80000 /* Dismiss invalid address faults? */ +#define OEX_FPU_MIN 0x1f /* FPE's which MUST be enabled. */ +#define OEX_FPU_MAX 0x1f00 /* FPE's which MAY be enabled. */ +#define OEX_PAGE0 0x10000 /* page zero must be mapped. */ +#define OEX_SMM 0x20000 /* Force sequential memory mode? */ +#define OEX_FPDBUG 0x40000 /* Force floating point debug mode? */ +#define OEX_PRECISEFP OEX_FPDBUG +#define OEX_DISMISS 0x80000 /* Dismiss invalid address faults? */ -#define OEX_FPU_INVAL 0x10 -#define OEX_FPU_DIV0 0x08 -#define OEX_FPU_OFLO 0x04 -#define OEX_FPU_UFLO 0x02 -#define OEX_FPU_INEX 0x01 +#define OEX_FPU_INVAL 0x10 +#define OEX_FPU_DIV0 0x08 +#define OEX_FPU_OFLO 0x04 +#define OEX_FPU_UFLO 0x02 +#define OEX_FPU_INEX 0x01 /* Masks for `info' in Elf_Options for an ODK_HWPATCH entry. */ -#define OHW_R4KEOP 0x1 /* R4000 end-of-page patch. */ -#define OHW_R8KPFETCH 0x2 /* may need R8000 prefetch patch. */ -#define OHW_R5KEOP 0x4 /* R5000 end-of-page patch. */ -#define OHW_R5KCVTL 0x8 /* R5000 cvt.[ds].l bug. clean=1. */ +#define OHW_R4KEOP 0x1 /* R4000 end-of-page patch. */ +#define OHW_R8KPFETCH 0x2 /* may need R8000 prefetch patch. */ +#define OHW_R5KEOP 0x4 /* R5000 end-of-page patch. */ +#define OHW_R5KCVTL 0x8 /* R5000 cvt.[ds].l bug. clean=1. */ -#define OPAD_PREFIX 0x1 -#define OPAD_POSTFIX 0x2 -#define OPAD_SYMBOL 0x4 +#define OPAD_PREFIX 0x1 +#define OPAD_POSTFIX 0x2 +#define OPAD_SYMBOL 0x4 /* Entry found in `.options' section. */ -typedef struct -{ - Elf32_Word hwp_flags1; /* Extra flags. */ - Elf32_Word hwp_flags2; /* Extra flags. */ +typedef struct { + Elf32_Word hwp_flags1; /* Extra flags. */ + Elf32_Word hwp_flags2; /* Extra flags. */ } Elf_Options_Hw; /* Masks for `info' in ElfOptions for ODK_HWAND and ODK_HWOR entries. */ -#define OHWA0_R4KEOP_CHECKED 0x00000001 -#define OHWA1_R4KEOP_CLEAN 0x00000002 +#define OHWA0_R4KEOP_CHECKED 0x00000001 +#define OHWA1_R4KEOP_CLEAN 0x00000002 /* MIPS relocs. */ -#define R_MIPS_NONE 0 /* No reloc */ -#define R_MIPS_16 1 /* Direct 16 bit */ -#define R_MIPS_32 2 /* Direct 32 bit */ -#define R_MIPS_REL32 3 /* PC relative 32 bit */ -#define R_MIPS_26 4 /* Direct 26 bit shifted */ -#define R_MIPS_HI16 5 /* High 16 bit */ -#define R_MIPS_LO16 6 /* Low 16 bit */ -#define R_MIPS_GPREL16 7 /* GP relative 16 bit */ -#define R_MIPS_LITERAL 8 /* 16 bit literal entry */ -#define R_MIPS_GOT16 9 /* 16 bit GOT entry */ -#define R_MIPS_PC16 10 /* PC relative 16 bit */ -#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ -#define R_MIPS_GPREL32 12 /* GP relative 32 bit */ +#define R_MIPS_NONE 0 /* No reloc */ +#define R_MIPS_16 1 /* Direct 16 bit */ +#define R_MIPS_32 2 /* Direct 32 bit */ +#define R_MIPS_REL32 3 /* PC relative 32 bit */ +#define R_MIPS_26 4 /* Direct 26 bit shifted */ +#define R_MIPS_HI16 5 /* High 16 bit */ +#define R_MIPS_LO16 6 /* Low 16 bit */ +#define R_MIPS_GPREL16 7 /* GP relative 16 bit */ +#define R_MIPS_LITERAL 8 /* 16 bit literal entry */ +#define R_MIPS_GOT16 9 /* 16 bit GOT entry */ +#define R_MIPS_PC16 10 /* PC relative 16 bit */ +#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ +#define R_MIPS_GPREL32 12 /* GP relative 32 bit */ -#define R_MIPS_SHIFT5 16 -#define R_MIPS_SHIFT6 17 -#define R_MIPS_64 18 -#define R_MIPS_GOT_DISP 19 -#define R_MIPS_GOT_PAGE 20 -#define R_MIPS_GOT_OFST 21 -#define R_MIPS_GOT_HI16 22 -#define R_MIPS_GOT_LO16 23 -#define R_MIPS_SUB 24 -#define R_MIPS_INSERT_A 25 -#define R_MIPS_INSERT_B 26 -#define R_MIPS_DELETE 27 -#define R_MIPS_HIGHER 28 -#define R_MIPS_HIGHEST 29 -#define R_MIPS_CALL_HI16 30 -#define R_MIPS_CALL_LO16 31 -#define R_MIPS_SCN_DISP 32 -#define R_MIPS_REL16 33 -#define R_MIPS_ADD_IMMEDIATE 34 -#define R_MIPS_PJUMP 35 -#define R_MIPS_RELGOT 36 -#define R_MIPS_JALR 37 -#define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */ -#define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */ -#define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */ -#define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */ -#define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */ -#define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */ -#define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */ -#define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */ -#define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */ -#define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */ -#define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */ -#define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */ -#define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */ -#define R_MIPS_GLOB_DAT 51 -#define R_MIPS_COPY 126 -#define R_MIPS_JUMP_SLOT 127 +#define R_MIPS_SHIFT5 16 +#define R_MIPS_SHIFT6 17 +#define R_MIPS_64 18 +#define R_MIPS_GOT_DISP 19 +#define R_MIPS_GOT_PAGE 20 +#define R_MIPS_GOT_OFST 21 +#define R_MIPS_GOT_HI16 22 +#define R_MIPS_GOT_LO16 23 +#define R_MIPS_SUB 24 +#define R_MIPS_INSERT_A 25 +#define R_MIPS_INSERT_B 26 +#define R_MIPS_DELETE 27 +#define R_MIPS_HIGHER 28 +#define R_MIPS_HIGHEST 29 +#define R_MIPS_CALL_HI16 30 +#define R_MIPS_CALL_LO16 31 +#define R_MIPS_SCN_DISP 32 +#define R_MIPS_REL16 33 +#define R_MIPS_ADD_IMMEDIATE 34 +#define R_MIPS_PJUMP 35 +#define R_MIPS_RELGOT 36 +#define R_MIPS_JALR 37 +#define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */ +#define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */ +#define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */ +#define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */ +#define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */ +#define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */ +#define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */ +#define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */ +#define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */ +#define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */ +#define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */ +#define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */ +#define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */ +#define R_MIPS_GLOB_DAT 51 +#define R_MIPS_COPY 126 +#define R_MIPS_JUMP_SLOT 127 /* Keep this the last entry. */ -#define R_MIPS_NUM 128 +#define R_MIPS_NUM 128 /* Legal values for p_type field of Elf32_Phdr. */ -#define PT_MIPS_REGINFO 0x70000000 /* Register usage information */ -#define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */ +#define PT_MIPS_REGINFO 0x70000000 /* Register usage information */ +#define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */ #define PT_MIPS_OPTIONS 0x70000002 /* Special program header types. */ -#define PF_MIPS_LOCAL 0x10000000 +#define PF_MIPS_LOCAL 0x10000000 /* Legal values for d_tag field of Elf32_Dyn. */ -#define DT_MIPS_RLD_VERSION 0x70000001 /* Runtime linker interface version */ -#define DT_MIPS_TIME_STAMP 0x70000002 /* Timestamp */ -#define DT_MIPS_ICHECKSUM 0x70000003 /* Checksum */ -#define DT_MIPS_IVERSION 0x70000004 /* Version string (string tbl index) */ -#define DT_MIPS_FLAGS 0x70000005 /* Flags */ -#define DT_MIPS_BASE_ADDRESS 0x70000006 /* Base address */ -#define DT_MIPS_MSYM 0x70000007 -#define DT_MIPS_CONFLICT 0x70000008 /* Address of CONFLICT section */ -#define DT_MIPS_LIBLIST 0x70000009 /* Address of LIBLIST section */ -#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local GOT entries */ -#define DT_MIPS_CONFLICTNO 0x7000000b /* Number of CONFLICT entries */ -#define DT_MIPS_LIBLISTNO 0x70000010 /* Number of LIBLIST entries */ -#define DT_MIPS_SYMTABNO 0x70000011 /* Number of DYNSYM entries */ -#define DT_MIPS_UNREFEXTNO 0x70000012 /* First external DYNSYM */ -#define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry in DYNSYM */ -#define DT_MIPS_HIPAGENO 0x70000014 /* Number of GOT page table entries */ -#define DT_MIPS_RLD_MAP 0x70000016 /* Address of run time loader map. */ -#define DT_MIPS_DELTA_CLASS 0x70000017 /* Delta C++ class definition. */ -#define DT_MIPS_DELTA_CLASS_NO 0x70000018 /* Number of entries in - DT_MIPS_DELTA_CLASS. */ -#define DT_MIPS_DELTA_INSTANCE 0x70000019 /* Delta C++ class instances. */ -#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a /* Number of entries in - DT_MIPS_DELTA_INSTANCE. */ -#define DT_MIPS_DELTA_RELOC 0x7000001b /* Delta relocations. */ -#define DT_MIPS_DELTA_RELOC_NO 0x7000001c /* Number of entries in - DT_MIPS_DELTA_RELOC. */ -#define DT_MIPS_DELTA_SYM 0x7000001d /* Delta symbols that Delta - relocations refer to. */ -#define DT_MIPS_DELTA_SYM_NO 0x7000001e /* Number of entries in - DT_MIPS_DELTA_SYM. */ -#define DT_MIPS_DELTA_CLASSSYM 0x70000020 /* Delta symbols that hold the - class declaration. */ -#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 /* Number of entries in - DT_MIPS_DELTA_CLASSSYM. */ -#define DT_MIPS_CXX_FLAGS 0x70000022 /* Flags indicating for C++ flavor. */ -#define DT_MIPS_PIXIE_INIT 0x70000023 -#define DT_MIPS_SYMBOL_LIB 0x70000024 +#define DT_MIPS_RLD_VERSION 0x70000001 /* Runtime linker interface version */ +#define DT_MIPS_TIME_STAMP 0x70000002 /* Timestamp */ +#define DT_MIPS_ICHECKSUM 0x70000003 /* Checksum */ +#define DT_MIPS_IVERSION 0x70000004 /* Version string (string tbl index) */ +#define DT_MIPS_FLAGS 0x70000005 /* Flags */ +#define DT_MIPS_BASE_ADDRESS 0x70000006 /* Base address */ +#define DT_MIPS_MSYM 0x70000007 +#define DT_MIPS_CONFLICT 0x70000008 /* Address of CONFLICT section */ +#define DT_MIPS_LIBLIST 0x70000009 /* Address of LIBLIST section */ +#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local GOT entries */ +#define DT_MIPS_CONFLICTNO 0x7000000b /* Number of CONFLICT entries */ +#define DT_MIPS_LIBLISTNO 0x70000010 /* Number of LIBLIST entries */ +#define DT_MIPS_SYMTABNO 0x70000011 /* Number of DYNSYM entries */ +#define DT_MIPS_UNREFEXTNO 0x70000012 /* First external DYNSYM */ +#define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry in DYNSYM */ +#define DT_MIPS_HIPAGENO 0x70000014 /* Number of GOT page table entries */ +#define DT_MIPS_RLD_MAP 0x70000016 /* Address of run time loader map. */ +#define DT_MIPS_DELTA_CLASS 0x70000017 /* Delta C++ class definition. */ +#define DT_MIPS_DELTA_CLASS_NO \ + 0x70000018 /* Number of entries in \ + DT_MIPS_DELTA_CLASS. */ +#define DT_MIPS_DELTA_INSTANCE 0x70000019 /* Delta C++ class instances. */ +#define DT_MIPS_DELTA_INSTANCE_NO \ + 0x7000001a /* Number of entries in \ + DT_MIPS_DELTA_INSTANCE. */ +#define DT_MIPS_DELTA_RELOC 0x7000001b /* Delta relocations. */ +#define DT_MIPS_DELTA_RELOC_NO \ + 0x7000001c /* Number of entries in \ + DT_MIPS_DELTA_RELOC. */ +#define DT_MIPS_DELTA_SYM \ + 0x7000001d /* Delta symbols that Delta \ + relocations refer to. */ +#define DT_MIPS_DELTA_SYM_NO \ + 0x7000001e /* Number of entries in \ + DT_MIPS_DELTA_SYM. */ +#define DT_MIPS_DELTA_CLASSSYM \ + 0x70000020 /* Delta symbols that hold the \ + class declaration. */ +#define DT_MIPS_DELTA_CLASSSYM_NO \ + 0x70000021 /* Number of entries in \ + DT_MIPS_DELTA_CLASSSYM. */ +#define DT_MIPS_CXX_FLAGS 0x70000022 /* Flags indicating for C++ flavor. */ +#define DT_MIPS_PIXIE_INIT 0x70000023 +#define DT_MIPS_SYMBOL_LIB 0x70000024 #define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025 #define DT_MIPS_LOCAL_GOTIDX 0x70000026 #define DT_MIPS_HIDDEN_GOTIDX 0x70000027 #define DT_MIPS_PROTECTED_GOTIDX 0x70000028 -#define DT_MIPS_OPTIONS 0x70000029 /* Address of .options. */ -#define DT_MIPS_INTERFACE 0x7000002a /* Address of .interface. */ +#define DT_MIPS_OPTIONS 0x70000029 /* Address of .options. */ +#define DT_MIPS_INTERFACE 0x7000002a /* Address of .interface. */ #define DT_MIPS_DYNSTR_ALIGN 0x7000002b -#define DT_MIPS_INTERFACE_SIZE 0x7000002c /* Size of the .interface section. */ -#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d /* Address of rld_text_rsolve - function stored in GOT. */ -#define DT_MIPS_PERF_SUFFIX 0x7000002e /* Default suffix of dso to be added - by rld on dlopen() calls. */ -#define DT_MIPS_COMPACT_SIZE 0x7000002f /* (O32)Size of compact rel section. */ -#define DT_MIPS_GP_VALUE 0x70000030 /* GP value for aux GOTs. */ -#define DT_MIPS_AUX_DYNAMIC 0x70000031 /* Address of aux .dynamic. */ +#define DT_MIPS_INTERFACE_SIZE 0x7000002c /* Size of the .interface section. \ + */ +#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR \ + 0x7000002d /* Address of rld_text_rsolve \ + function stored in GOT. */ +#define DT_MIPS_PERF_SUFFIX \ + 0x7000002e /* Default suffix of dso to be added \ + by rld on dlopen() calls. */ +#define DT_MIPS_COMPACT_SIZE 0x7000002f /* (O32)Size of compact rel section. \ + */ +#define DT_MIPS_GP_VALUE 0x70000030 /* GP value for aux GOTs. */ +#define DT_MIPS_AUX_DYNAMIC 0x70000031 /* Address of aux .dynamic. */ /* The address of .got.plt in an executable using the new non-PIC ABI. */ -#define DT_MIPS_PLTGOT 0x70000032 +#define DT_MIPS_PLTGOT 0x70000032 /* The base of the PLT in an executable using the new non-PIC ABI if that PLT is writable. For a non-writable PLT, this is omitted or has a zero value. */ -#define DT_MIPS_RWPLT 0x70000034 -#define DT_MIPS_NUM 0x35 +#define DT_MIPS_RWPLT 0x70000034 +#define DT_MIPS_NUM 0x35 /* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */ -#define RHF_NONE 0 /* No flags */ -#define RHF_QUICKSTART (1 << 0) /* Use quickstart */ -#define RHF_NOTPOT (1 << 1) /* Hash size not power of 2 */ -#define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) /* Ignore LD_LIBRARY_PATH */ -#define RHF_NO_MOVE (1 << 3) -#define RHF_SGI_ONLY (1 << 4) -#define RHF_GUARANTEE_INIT (1 << 5) -#define RHF_DELTA_C_PLUS_PLUS (1 << 6) -#define RHF_GUARANTEE_START_INIT (1 << 7) -#define RHF_PIXIE (1 << 8) -#define RHF_DEFAULT_DELAY_LOAD (1 << 9) -#define RHF_REQUICKSTART (1 << 10) -#define RHF_REQUICKSTARTED (1 << 11) -#define RHF_CORD (1 << 12) -#define RHF_NO_UNRES_UNDEF (1 << 13) -#define RHF_RLD_ORDER_SAFE (1 << 14) +#define RHF_NONE 0 /* No flags */ +#define RHF_QUICKSTART (1 << 0) /* Use quickstart */ +#define RHF_NOTPOT (1 << 1) /* Hash size not power of 2 */ +#define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) /* Ignore LD_LIBRARY_PATH */ +#define RHF_NO_MOVE (1 << 3) +#define RHF_SGI_ONLY (1 << 4) +#define RHF_GUARANTEE_INIT (1 << 5) +#define RHF_DELTA_C_PLUS_PLUS (1 << 6) +#define RHF_GUARANTEE_START_INIT (1 << 7) +#define RHF_PIXIE (1 << 8) +#define RHF_DEFAULT_DELAY_LOAD (1 << 9) +#define RHF_REQUICKSTART (1 << 10) +#define RHF_REQUICKSTARTED (1 << 11) +#define RHF_CORD (1 << 12) +#define RHF_NO_UNRES_UNDEF (1 << 13) +#define RHF_RLD_ORDER_SAFE (1 << 14) /* Entries found in sections of type SHT_MIPS_LIBLIST. */ -typedef struct -{ - Elf32_Word l_name; /* Name (string table index) */ - Elf32_Word l_time_stamp; /* Timestamp */ - Elf32_Word l_checksum; /* Checksum */ - Elf32_Word l_version; /* Interface version */ - Elf32_Word l_flags; /* Flags */ +typedef struct { + Elf32_Word l_name; /* Name (string table index) */ + Elf32_Word l_time_stamp; /* Timestamp */ + Elf32_Word l_checksum; /* Checksum */ + Elf32_Word l_version; /* Interface version */ + Elf32_Word l_flags; /* Flags */ } Elf32_Lib; -typedef struct -{ - Elf64_Word l_name; /* Name (string table index) */ - Elf64_Word l_time_stamp; /* Timestamp */ - Elf64_Word l_checksum; /* Checksum */ - Elf64_Word l_version; /* Interface version */ - Elf64_Word l_flags; /* Flags */ +typedef struct { + Elf64_Word l_name; /* Name (string table index) */ + Elf64_Word l_time_stamp; /* Timestamp */ + Elf64_Word l_checksum; /* Checksum */ + Elf64_Word l_version; /* Interface version */ + Elf64_Word l_flags; /* Flags */ } Elf64_Lib; - /* Legal values for l_flags. */ -#define LL_NONE 0 -#define LL_EXACT_MATCH (1 << 0) /* Require exact match */ -#define LL_IGNORE_INT_VER (1 << 1) /* Ignore interface version */ -#define LL_REQUIRE_MINOR (1 << 2) -#define LL_EXPORTS (1 << 3) -#define LL_DELAY_LOAD (1 << 4) -#define LL_DELTA (1 << 5) +#define LL_NONE 0 +#define LL_EXACT_MATCH (1 << 0) /* Require exact match */ +#define LL_IGNORE_INT_VER (1 << 1) /* Ignore interface version */ +#define LL_REQUIRE_MINOR (1 << 2) +#define LL_EXPORTS (1 << 3) +#define LL_DELAY_LOAD (1 << 4) +#define LL_DELTA (1 << 5) /* Entries found in sections of type SHT_MIPS_CONFLICT. */ typedef Elf32_Addr Elf32_Conflict; - /* HPPA specific definitions. */ /* Legal values for e_flags field of Elf32_Ehdr. */ -#define EF_PARISC_TRAPNIL 0x00010000 /* Trap nil pointer dereference. */ -#define EF_PARISC_EXT 0x00020000 /* Program uses arch. extensions. */ -#define EF_PARISC_LSB 0x00040000 /* Program expects little endian. */ -#define EF_PARISC_WIDE 0x00080000 /* Program expects wide mode. */ -#define EF_PARISC_NO_KABP 0x00100000 /* No kernel assisted branch - prediction. */ -#define EF_PARISC_LAZYSWAP 0x00400000 /* Allow lazy swapping. */ -#define EF_PARISC_ARCH 0x0000ffff /* Architecture version. */ +#define EF_PARISC_TRAPNIL 0x00010000 /* Trap nil pointer dereference. */ +#define EF_PARISC_EXT 0x00020000 /* Program uses arch. extensions. */ +#define EF_PARISC_LSB 0x00040000 /* Program expects little endian. */ +#define EF_PARISC_WIDE 0x00080000 /* Program expects wide mode. */ +#define EF_PARISC_NO_KABP \ + 0x00100000 /* No kernel assisted branch \ + prediction. */ +#define EF_PARISC_LAZYSWAP 0x00400000 /* Allow lazy swapping. */ +#define EF_PARISC_ARCH 0x0000ffff /* Architecture version. */ /* Defined values for `e_flags & EF_PARISC_ARCH' are: */ -#define EFA_PARISC_1_0 0x020b /* PA-RISC 1.0 big-endian. */ -#define EFA_PARISC_1_1 0x0210 /* PA-RISC 1.1 big-endian. */ -#define EFA_PARISC_2_0 0x0214 /* PA-RISC 2.0 big-endian. */ +#define EFA_PARISC_1_0 0x020b /* PA-RISC 1.0 big-endian. */ +#define EFA_PARISC_1_1 0x0210 /* PA-RISC 1.1 big-endian. */ +#define EFA_PARISC_2_0 0x0214 /* PA-RISC 2.0 big-endian. */ /* Additional section indices. */ -#define SHN_PARISC_ANSI_COMMON 0xff00 /* Section for tentatively declared - symbols in ANSI C. */ -#define SHN_PARISC_HUGE_COMMON 0xff01 /* Common blocks in huge model. */ +#define SHN_PARISC_ANSI_COMMON \ + 0xff00 /* Section for tentatively declared \ + symbols in ANSI C. */ +#define SHN_PARISC_HUGE_COMMON 0xff01 /* Common blocks in huge model. */ /* Legal values for sh_type field of Elf32_Shdr. */ -#define SHT_PARISC_EXT 0x70000000 /* Contains product specific ext. */ -#define SHT_PARISC_UNWIND 0x70000001 /* Unwind information. */ -#define SHT_PARISC_DOC 0x70000002 /* Debug info for optimized code. */ +#define SHT_PARISC_EXT 0x70000000 /* Contains product specific ext. */ +#define SHT_PARISC_UNWIND 0x70000001 /* Unwind information. */ +#define SHT_PARISC_DOC 0x70000002 /* Debug info for optimized code. */ /* Legal values for sh_flags field of Elf32_Shdr. */ -#define SHF_PARISC_SHORT 0x20000000 /* Section with short addressing. */ -#define SHF_PARISC_HUGE 0x40000000 /* Section far from gp. */ -#define SHF_PARISC_SBP 0x80000000 /* Static branch prediction code. */ +#define SHF_PARISC_SHORT 0x20000000 /* Section with short addressing. */ +#define SHF_PARISC_HUGE 0x40000000 /* Section far from gp. */ +#define SHF_PARISC_SBP 0x80000000 /* Static branch prediction code. */ /* Legal values for ST_TYPE subfield of st_info (symbol type). */ -#define STT_PARISC_MILLICODE 13 /* Millicode function entry point. */ +#define STT_PARISC_MILLICODE 13 /* Millicode function entry point. */ -#define STT_HP_OPAQUE (STT_LOOS + 0x1) -#define STT_HP_STUB (STT_LOOS + 0x2) +#define STT_HP_OPAQUE (STT_LOOS + 0x1) +#define STT_HP_STUB (STT_LOOS + 0x2) /* HPPA relocs. */ -#define R_PARISC_NONE 0 /* No reloc. */ -#define R_PARISC_DIR32 1 /* Direct 32-bit reference. */ -#define R_PARISC_DIR21L 2 /* Left 21 bits of eff. address. */ -#define R_PARISC_DIR17R 3 /* Right 17 bits of eff. address. */ -#define R_PARISC_DIR17F 4 /* 17 bits of eff. address. */ -#define R_PARISC_DIR14R 6 /* Right 14 bits of eff. address. */ -#define R_PARISC_PCREL32 9 /* 32-bit rel. address. */ -#define R_PARISC_PCREL21L 10 /* Left 21 bits of rel. address. */ -#define R_PARISC_PCREL17R 11 /* Right 17 bits of rel. address. */ -#define R_PARISC_PCREL17F 12 /* 17 bits of rel. address. */ -#define R_PARISC_PCREL14R 14 /* Right 14 bits of rel. address. */ -#define R_PARISC_DPREL21L 18 /* Left 21 bits of rel. address. */ -#define R_PARISC_DPREL14R 22 /* Right 14 bits of rel. address. */ -#define R_PARISC_GPREL21L 26 /* GP-relative, left 21 bits. */ -#define R_PARISC_GPREL14R 30 /* GP-relative, right 14 bits. */ -#define R_PARISC_LTOFF21L 34 /* LT-relative, left 21 bits. */ -#define R_PARISC_LTOFF14R 38 /* LT-relative, right 14 bits. */ -#define R_PARISC_SECREL32 41 /* 32 bits section rel. address. */ -#define R_PARISC_SEGBASE 48 /* No relocation, set segment base. */ -#define R_PARISC_SEGREL32 49 /* 32 bits segment rel. address. */ -#define R_PARISC_PLTOFF21L 50 /* PLT rel. address, left 21 bits. */ -#define R_PARISC_PLTOFF14R 54 /* PLT rel. address, right 14 bits. */ -#define R_PARISC_LTOFF_FPTR32 57 /* 32 bits LT-rel. function pointer. */ -#define R_PARISC_LTOFF_FPTR21L 58 /* LT-rel. fct ptr, left 21 bits. */ -#define R_PARISC_LTOFF_FPTR14R 62 /* LT-rel. fct ptr, right 14 bits. */ -#define R_PARISC_FPTR64 64 /* 64 bits function address. */ -#define R_PARISC_PLABEL32 65 /* 32 bits function address. */ -#define R_PARISC_PLABEL21L 66 /* Left 21 bits of fdesc address. */ -#define R_PARISC_PLABEL14R 70 /* Right 14 bits of fdesc address. */ -#define R_PARISC_PCREL64 72 /* 64 bits PC-rel. address. */ -#define R_PARISC_PCREL22F 74 /* 22 bits PC-rel. address. */ -#define R_PARISC_PCREL14WR 75 /* PC-rel. address, right 14 bits. */ -#define R_PARISC_PCREL14DR 76 /* PC rel. address, right 14 bits. */ -#define R_PARISC_PCREL16F 77 /* 16 bits PC-rel. address. */ -#define R_PARISC_PCREL16WF 78 /* 16 bits PC-rel. address. */ -#define R_PARISC_PCREL16DF 79 /* 16 bits PC-rel. address. */ -#define R_PARISC_DIR64 80 /* 64 bits of eff. address. */ -#define R_PARISC_DIR14WR 83 /* 14 bits of eff. address. */ -#define R_PARISC_DIR14DR 84 /* 14 bits of eff. address. */ -#define R_PARISC_DIR16F 85 /* 16 bits of eff. address. */ -#define R_PARISC_DIR16WF 86 /* 16 bits of eff. address. */ -#define R_PARISC_DIR16DF 87 /* 16 bits of eff. address. */ -#define R_PARISC_GPREL64 88 /* 64 bits of GP-rel. address. */ -#define R_PARISC_GPREL14WR 91 /* GP-rel. address, right 14 bits. */ -#define R_PARISC_GPREL14DR 92 /* GP-rel. address, right 14 bits. */ -#define R_PARISC_GPREL16F 93 /* 16 bits GP-rel. address. */ -#define R_PARISC_GPREL16WF 94 /* 16 bits GP-rel. address. */ -#define R_PARISC_GPREL16DF 95 /* 16 bits GP-rel. address. */ -#define R_PARISC_LTOFF64 96 /* 64 bits LT-rel. address. */ -#define R_PARISC_LTOFF14WR 99 /* LT-rel. address, right 14 bits. */ -#define R_PARISC_LTOFF14DR 100 /* LT-rel. address, right 14 bits. */ -#define R_PARISC_LTOFF16F 101 /* 16 bits LT-rel. address. */ -#define R_PARISC_LTOFF16WF 102 /* 16 bits LT-rel. address. */ -#define R_PARISC_LTOFF16DF 103 /* 16 bits LT-rel. address. */ -#define R_PARISC_SECREL64 104 /* 64 bits section rel. address. */ -#define R_PARISC_SEGREL64 112 /* 64 bits segment rel. address. */ -#define R_PARISC_PLTOFF14WR 115 /* PLT-rel. address, right 14 bits. */ -#define R_PARISC_PLTOFF14DR 116 /* PLT-rel. address, right 14 bits. */ -#define R_PARISC_PLTOFF16F 117 /* 16 bits LT-rel. address. */ -#define R_PARISC_PLTOFF16WF 118 /* 16 bits PLT-rel. address. */ -#define R_PARISC_PLTOFF16DF 119 /* 16 bits PLT-rel. address. */ -#define R_PARISC_LTOFF_FPTR64 120 /* 64 bits LT-rel. function ptr. */ -#define R_PARISC_LTOFF_FPTR14WR 123 /* LT-rel. fct. ptr., right 14 bits. */ -#define R_PARISC_LTOFF_FPTR14DR 124 /* LT-rel. fct. ptr., right 14 bits. */ -#define R_PARISC_LTOFF_FPTR16F 125 /* 16 bits LT-rel. function ptr. */ -#define R_PARISC_LTOFF_FPTR16WF 126 /* 16 bits LT-rel. function ptr. */ -#define R_PARISC_LTOFF_FPTR16DF 127 /* 16 bits LT-rel. function ptr. */ -#define R_PARISC_LORESERVE 128 -#define R_PARISC_COPY 128 /* Copy relocation. */ -#define R_PARISC_IPLT 129 /* Dynamic reloc, imported PLT */ -#define R_PARISC_EPLT 130 /* Dynamic reloc, exported PLT */ -#define R_PARISC_TPREL32 153 /* 32 bits TP-rel. address. */ -#define R_PARISC_TPREL21L 154 /* TP-rel. address, left 21 bits. */ -#define R_PARISC_TPREL14R 158 /* TP-rel. address, right 14 bits. */ -#define R_PARISC_LTOFF_TP21L 162 /* LT-TP-rel. address, left 21 bits. */ -#define R_PARISC_LTOFF_TP14R 166 /* LT-TP-rel. address, right 14 bits.*/ -#define R_PARISC_LTOFF_TP14F 167 /* 14 bits LT-TP-rel. address. */ -#define R_PARISC_TPREL64 216 /* 64 bits TP-rel. address. */ -#define R_PARISC_TPREL14WR 219 /* TP-rel. address, right 14 bits. */ -#define R_PARISC_TPREL14DR 220 /* TP-rel. address, right 14 bits. */ -#define R_PARISC_TPREL16F 221 /* 16 bits TP-rel. address. */ -#define R_PARISC_TPREL16WF 222 /* 16 bits TP-rel. address. */ -#define R_PARISC_TPREL16DF 223 /* 16 bits TP-rel. address. */ -#define R_PARISC_LTOFF_TP64 224 /* 64 bits LT-TP-rel. address. */ -#define R_PARISC_LTOFF_TP14WR 227 /* LT-TP-rel. address, right 14 bits.*/ -#define R_PARISC_LTOFF_TP14DR 228 /* LT-TP-rel. address, right 14 bits.*/ -#define R_PARISC_LTOFF_TP16F 229 /* 16 bits LT-TP-rel. address. */ -#define R_PARISC_LTOFF_TP16WF 230 /* 16 bits LT-TP-rel. address. */ -#define R_PARISC_LTOFF_TP16DF 231 /* 16 bits LT-TP-rel. address. */ -#define R_PARISC_GNU_VTENTRY 232 -#define R_PARISC_GNU_VTINHERIT 233 -#define R_PARISC_TLS_GD21L 234 /* GD 21-bit left. */ -#define R_PARISC_TLS_GD14R 235 /* GD 14-bit right. */ -#define R_PARISC_TLS_GDCALL 236 /* GD call to __t_g_a. */ -#define R_PARISC_TLS_LDM21L 237 /* LD module 21-bit left. */ -#define R_PARISC_TLS_LDM14R 238 /* LD module 14-bit right. */ -#define R_PARISC_TLS_LDMCALL 239 /* LD module call to __t_g_a. */ -#define R_PARISC_TLS_LDO21L 240 /* LD offset 21-bit left. */ -#define R_PARISC_TLS_LDO14R 241 /* LD offset 14-bit right. */ -#define R_PARISC_TLS_DTPMOD32 242 /* DTP module 32-bit. */ -#define R_PARISC_TLS_DTPMOD64 243 /* DTP module 64-bit. */ -#define R_PARISC_TLS_DTPOFF32 244 /* DTP offset 32-bit. */ -#define R_PARISC_TLS_DTPOFF64 245 /* DTP offset 32-bit. */ -#define R_PARISC_TLS_LE21L R_PARISC_TPREL21L -#define R_PARISC_TLS_LE14R R_PARISC_TPREL14R -#define R_PARISC_TLS_IE21L R_PARISC_LTOFF_TP21L -#define R_PARISC_TLS_IE14R R_PARISC_LTOFF_TP14R -#define R_PARISC_TLS_TPREL32 R_PARISC_TPREL32 -#define R_PARISC_TLS_TPREL64 R_PARISC_TPREL64 -#define R_PARISC_HIRESERVE 255 +#define R_PARISC_NONE 0 /* No reloc. */ +#define R_PARISC_DIR32 1 /* Direct 32-bit reference. */ +#define R_PARISC_DIR21L 2 /* Left 21 bits of eff. address. */ +#define R_PARISC_DIR17R 3 /* Right 17 bits of eff. address. */ +#define R_PARISC_DIR17F 4 /* 17 bits of eff. address. */ +#define R_PARISC_DIR14R 6 /* Right 14 bits of eff. address. */ +#define R_PARISC_PCREL32 9 /* 32-bit rel. address. */ +#define R_PARISC_PCREL21L 10 /* Left 21 bits of rel. address. */ +#define R_PARISC_PCREL17R 11 /* Right 17 bits of rel. address. */ +#define R_PARISC_PCREL17F 12 /* 17 bits of rel. address. */ +#define R_PARISC_PCREL14R 14 /* Right 14 bits of rel. address. */ +#define R_PARISC_DPREL21L 18 /* Left 21 bits of rel. address. */ +#define R_PARISC_DPREL14R 22 /* Right 14 bits of rel. address. */ +#define R_PARISC_GPREL21L 26 /* GP-relative, left 21 bits. */ +#define R_PARISC_GPREL14R 30 /* GP-relative, right 14 bits. */ +#define R_PARISC_LTOFF21L 34 /* LT-relative, left 21 bits. */ +#define R_PARISC_LTOFF14R 38 /* LT-relative, right 14 bits. */ +#define R_PARISC_SECREL32 41 /* 32 bits section rel. address. */ +#define R_PARISC_SEGBASE 48 /* No relocation, set segment base. */ +#define R_PARISC_SEGREL32 49 /* 32 bits segment rel. address. */ +#define R_PARISC_PLTOFF21L 50 /* PLT rel. address, left 21 bits. */ +#define R_PARISC_PLTOFF14R 54 /* PLT rel. address, right 14 bits. */ +#define R_PARISC_LTOFF_FPTR32 57 /* 32 bits LT-rel. function pointer. */ +#define R_PARISC_LTOFF_FPTR21L 58 /* LT-rel. fct ptr, left 21 bits. */ +#define R_PARISC_LTOFF_FPTR14R 62 /* LT-rel. fct ptr, right 14 bits. */ +#define R_PARISC_FPTR64 64 /* 64 bits function address. */ +#define R_PARISC_PLABEL32 65 /* 32 bits function address. */ +#define R_PARISC_PLABEL21L 66 /* Left 21 bits of fdesc address. */ +#define R_PARISC_PLABEL14R 70 /* Right 14 bits of fdesc address. */ +#define R_PARISC_PCREL64 72 /* 64 bits PC-rel. address. */ +#define R_PARISC_PCREL22F 74 /* 22 bits PC-rel. address. */ +#define R_PARISC_PCREL14WR 75 /* PC-rel. address, right 14 bits. */ +#define R_PARISC_PCREL14DR 76 /* PC rel. address, right 14 bits. */ +#define R_PARISC_PCREL16F 77 /* 16 bits PC-rel. address. */ +#define R_PARISC_PCREL16WF 78 /* 16 bits PC-rel. address. */ +#define R_PARISC_PCREL16DF 79 /* 16 bits PC-rel. address. */ +#define R_PARISC_DIR64 80 /* 64 bits of eff. address. */ +#define R_PARISC_DIR14WR 83 /* 14 bits of eff. address. */ +#define R_PARISC_DIR14DR 84 /* 14 bits of eff. address. */ +#define R_PARISC_DIR16F 85 /* 16 bits of eff. address. */ +#define R_PARISC_DIR16WF 86 /* 16 bits of eff. address. */ +#define R_PARISC_DIR16DF 87 /* 16 bits of eff. address. */ +#define R_PARISC_GPREL64 88 /* 64 bits of GP-rel. address. */ +#define R_PARISC_GPREL14WR 91 /* GP-rel. address, right 14 bits. */ +#define R_PARISC_GPREL14DR 92 /* GP-rel. address, right 14 bits. */ +#define R_PARISC_GPREL16F 93 /* 16 bits GP-rel. address. */ +#define R_PARISC_GPREL16WF 94 /* 16 bits GP-rel. address. */ +#define R_PARISC_GPREL16DF 95 /* 16 bits GP-rel. address. */ +#define R_PARISC_LTOFF64 96 /* 64 bits LT-rel. address. */ +#define R_PARISC_LTOFF14WR 99 /* LT-rel. address, right 14 bits. */ +#define R_PARISC_LTOFF14DR 100 /* LT-rel. address, right 14 bits. */ +#define R_PARISC_LTOFF16F 101 /* 16 bits LT-rel. address. */ +#define R_PARISC_LTOFF16WF 102 /* 16 bits LT-rel. address. */ +#define R_PARISC_LTOFF16DF 103 /* 16 bits LT-rel. address. */ +#define R_PARISC_SECREL64 104 /* 64 bits section rel. address. */ +#define R_PARISC_SEGREL64 112 /* 64 bits segment rel. address. */ +#define R_PARISC_PLTOFF14WR 115 /* PLT-rel. address, right 14 bits. */ +#define R_PARISC_PLTOFF14DR 116 /* PLT-rel. address, right 14 bits. */ +#define R_PARISC_PLTOFF16F 117 /* 16 bits LT-rel. address. */ +#define R_PARISC_PLTOFF16WF 118 /* 16 bits PLT-rel. address. */ +#define R_PARISC_PLTOFF16DF 119 /* 16 bits PLT-rel. address. */ +#define R_PARISC_LTOFF_FPTR64 120 /* 64 bits LT-rel. function ptr. */ +#define R_PARISC_LTOFF_FPTR14WR 123 /* LT-rel. fct. ptr., right 14 bits. */ +#define R_PARISC_LTOFF_FPTR14DR 124 /* LT-rel. fct. ptr., right 14 bits. */ +#define R_PARISC_LTOFF_FPTR16F 125 /* 16 bits LT-rel. function ptr. */ +#define R_PARISC_LTOFF_FPTR16WF 126 /* 16 bits LT-rel. function ptr. */ +#define R_PARISC_LTOFF_FPTR16DF 127 /* 16 bits LT-rel. function ptr. */ +#define R_PARISC_LORESERVE 128 +#define R_PARISC_COPY 128 /* Copy relocation. */ +#define R_PARISC_IPLT 129 /* Dynamic reloc, imported PLT */ +#define R_PARISC_EPLT 130 /* Dynamic reloc, exported PLT */ +#define R_PARISC_TPREL32 153 /* 32 bits TP-rel. address. */ +#define R_PARISC_TPREL21L 154 /* TP-rel. address, left 21 bits. */ +#define R_PARISC_TPREL14R 158 /* TP-rel. address, right 14 bits. */ +#define R_PARISC_LTOFF_TP21L 162 /* LT-TP-rel. address, left 21 bits. */ +#define R_PARISC_LTOFF_TP14R 166 /* LT-TP-rel. address, right 14 bits.*/ +#define R_PARISC_LTOFF_TP14F 167 /* 14 bits LT-TP-rel. address. */ +#define R_PARISC_TPREL64 216 /* 64 bits TP-rel. address. */ +#define R_PARISC_TPREL14WR 219 /* TP-rel. address, right 14 bits. */ +#define R_PARISC_TPREL14DR 220 /* TP-rel. address, right 14 bits. */ +#define R_PARISC_TPREL16F 221 /* 16 bits TP-rel. address. */ +#define R_PARISC_TPREL16WF 222 /* 16 bits TP-rel. address. */ +#define R_PARISC_TPREL16DF 223 /* 16 bits TP-rel. address. */ +#define R_PARISC_LTOFF_TP64 224 /* 64 bits LT-TP-rel. address. */ +#define R_PARISC_LTOFF_TP14WR 227 /* LT-TP-rel. address, right 14 bits.*/ +#define R_PARISC_LTOFF_TP14DR 228 /* LT-TP-rel. address, right 14 bits.*/ +#define R_PARISC_LTOFF_TP16F 229 /* 16 bits LT-TP-rel. address. */ +#define R_PARISC_LTOFF_TP16WF 230 /* 16 bits LT-TP-rel. address. */ +#define R_PARISC_LTOFF_TP16DF 231 /* 16 bits LT-TP-rel. address. */ +#define R_PARISC_GNU_VTENTRY 232 +#define R_PARISC_GNU_VTINHERIT 233 +#define R_PARISC_TLS_GD21L 234 /* GD 21-bit left. */ +#define R_PARISC_TLS_GD14R 235 /* GD 14-bit right. */ +#define R_PARISC_TLS_GDCALL 236 /* GD call to __t_g_a. */ +#define R_PARISC_TLS_LDM21L 237 /* LD module 21-bit left. */ +#define R_PARISC_TLS_LDM14R 238 /* LD module 14-bit right. */ +#define R_PARISC_TLS_LDMCALL 239 /* LD module call to __t_g_a. */ +#define R_PARISC_TLS_LDO21L 240 /* LD offset 21-bit left. */ +#define R_PARISC_TLS_LDO14R 241 /* LD offset 14-bit right. */ +#define R_PARISC_TLS_DTPMOD32 242 /* DTP module 32-bit. */ +#define R_PARISC_TLS_DTPMOD64 243 /* DTP module 64-bit. */ +#define R_PARISC_TLS_DTPOFF32 244 /* DTP offset 32-bit. */ +#define R_PARISC_TLS_DTPOFF64 245 /* DTP offset 32-bit. */ +#define R_PARISC_TLS_LE21L R_PARISC_TPREL21L +#define R_PARISC_TLS_LE14R R_PARISC_TPREL14R +#define R_PARISC_TLS_IE21L R_PARISC_LTOFF_TP21L +#define R_PARISC_TLS_IE14R R_PARISC_LTOFF_TP14R +#define R_PARISC_TLS_TPREL32 R_PARISC_TPREL32 +#define R_PARISC_TLS_TPREL64 R_PARISC_TPREL64 +#define R_PARISC_HIRESERVE 255 /* Legal values for p_type field of Elf32_Phdr/Elf64_Phdr. */ -#define PT_HP_TLS (PT_LOOS + 0x0) -#define PT_HP_CORE_NONE (PT_LOOS + 0x1) -#define PT_HP_CORE_VERSION (PT_LOOS + 0x2) -#define PT_HP_CORE_KERNEL (PT_LOOS + 0x3) -#define PT_HP_CORE_COMM (PT_LOOS + 0x4) -#define PT_HP_CORE_PROC (PT_LOOS + 0x5) -#define PT_HP_CORE_LOADABLE (PT_LOOS + 0x6) -#define PT_HP_CORE_STACK (PT_LOOS + 0x7) -#define PT_HP_CORE_SHM (PT_LOOS + 0x8) -#define PT_HP_CORE_MMF (PT_LOOS + 0x9) -#define PT_HP_PARALLEL (PT_LOOS + 0x10) -#define PT_HP_FASTBIND (PT_LOOS + 0x11) -#define PT_HP_OPT_ANNOT (PT_LOOS + 0x12) -#define PT_HP_HSL_ANNOT (PT_LOOS + 0x13) -#define PT_HP_STACK (PT_LOOS + 0x14) +#define PT_HP_TLS (PT_LOOS + 0x0) +#define PT_HP_CORE_NONE (PT_LOOS + 0x1) +#define PT_HP_CORE_VERSION (PT_LOOS + 0x2) +#define PT_HP_CORE_KERNEL (PT_LOOS + 0x3) +#define PT_HP_CORE_COMM (PT_LOOS + 0x4) +#define PT_HP_CORE_PROC (PT_LOOS + 0x5) +#define PT_HP_CORE_LOADABLE (PT_LOOS + 0x6) +#define PT_HP_CORE_STACK (PT_LOOS + 0x7) +#define PT_HP_CORE_SHM (PT_LOOS + 0x8) +#define PT_HP_CORE_MMF (PT_LOOS + 0x9) +#define PT_HP_PARALLEL (PT_LOOS + 0x10) +#define PT_HP_FASTBIND (PT_LOOS + 0x11) +#define PT_HP_OPT_ANNOT (PT_LOOS + 0x12) +#define PT_HP_HSL_ANNOT (PT_LOOS + 0x13) +#define PT_HP_STACK (PT_LOOS + 0x14) -#define PT_PARISC_ARCHEXT 0x70000000 -#define PT_PARISC_UNWIND 0x70000001 +#define PT_PARISC_ARCHEXT 0x70000000 +#define PT_PARISC_UNWIND 0x70000001 /* Legal values for p_flags field of Elf32_Phdr/Elf64_Phdr. */ -#define PF_PARISC_SBP 0x08000000 - -#define PF_HP_PAGE_SIZE 0x00100000 -#define PF_HP_FAR_SHARED 0x00200000 -#define PF_HP_NEAR_SHARED 0x00400000 -#define PF_HP_CODE 0x01000000 -#define PF_HP_MODIFY 0x02000000 -#define PF_HP_LAZYSWAP 0x04000000 -#define PF_HP_SBP 0x08000000 +#define PF_PARISC_SBP 0x08000000 +#define PF_HP_PAGE_SIZE 0x00100000 +#define PF_HP_FAR_SHARED 0x00200000 +#define PF_HP_NEAR_SHARED 0x00400000 +#define PF_HP_CODE 0x01000000 +#define PF_HP_MODIFY 0x02000000 +#define PF_HP_LAZYSWAP 0x04000000 +#define PF_HP_SBP 0x08000000 /* Alpha specific definitions. */ /* Legal values for e_flags field of Elf64_Ehdr. */ -#define EF_ALPHA_32BIT 1 /* All addresses must be < 2GB. */ -#define EF_ALPHA_CANRELAX 2 /* Relocations for relaxing exist. */ +#define EF_ALPHA_32BIT 1 /* All addresses must be < 2GB. */ +#define EF_ALPHA_CANRELAX 2 /* Relocations for relaxing exist. */ /* Legal values for sh_type field of Elf64_Shdr. */ /* These two are primarily concerned with ECOFF debugging info. */ -#define SHT_ALPHA_DEBUG 0x70000001 -#define SHT_ALPHA_REGINFO 0x70000002 +#define SHT_ALPHA_DEBUG 0x70000001 +#define SHT_ALPHA_REGINFO 0x70000002 /* Legal values for sh_flags field of Elf64_Shdr. */ -#define SHF_ALPHA_GPREL 0x10000000 +#define SHF_ALPHA_GPREL 0x10000000 /* Legal values for st_other field of Elf64_Sym. */ -#define STO_ALPHA_NOPV 0x80 /* No PV required. */ -#define STO_ALPHA_STD_GPLOAD 0x88 /* PV only used for initial ldgp. */ +#define STO_ALPHA_NOPV 0x80 /* No PV required. */ +#define STO_ALPHA_STD_GPLOAD 0x88 /* PV only used for initial ldgp. */ /* Alpha relocs. */ -#define R_ALPHA_NONE 0 /* No reloc */ -#define R_ALPHA_REFLONG 1 /* Direct 32 bit */ -#define R_ALPHA_REFQUAD 2 /* Direct 64 bit */ -#define R_ALPHA_GPREL32 3 /* GP relative 32 bit */ -#define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */ -#define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */ -#define R_ALPHA_GPDISP 6 /* Add displacement to GP */ -#define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */ -#define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */ -#define R_ALPHA_SREL16 9 /* PC relative 16 bit */ -#define R_ALPHA_SREL32 10 /* PC relative 32 bit */ -#define R_ALPHA_SREL64 11 /* PC relative 64 bit */ -#define R_ALPHA_GPRELHIGH 17 /* GP relative 32 bit, high 16 bits */ -#define R_ALPHA_GPRELLOW 18 /* GP relative 32 bit, low 16 bits */ -#define R_ALPHA_GPREL16 19 /* GP relative 16 bit */ -#define R_ALPHA_COPY 24 /* Copy symbol at runtime */ -#define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */ -#define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */ -#define R_ALPHA_RELATIVE 27 /* Adjust by program base */ -#define R_ALPHA_TLS_GD_HI 28 -#define R_ALPHA_TLSGD 29 -#define R_ALPHA_TLS_LDM 30 -#define R_ALPHA_DTPMOD64 31 -#define R_ALPHA_GOTDTPREL 32 -#define R_ALPHA_DTPREL64 33 -#define R_ALPHA_DTPRELHI 34 -#define R_ALPHA_DTPRELLO 35 -#define R_ALPHA_DTPREL16 36 -#define R_ALPHA_GOTTPREL 37 -#define R_ALPHA_TPREL64 38 -#define R_ALPHA_TPRELHI 39 -#define R_ALPHA_TPRELLO 40 -#define R_ALPHA_TPREL16 41 +#define R_ALPHA_NONE 0 /* No reloc */ +#define R_ALPHA_REFLONG 1 /* Direct 32 bit */ +#define R_ALPHA_REFQUAD 2 /* Direct 64 bit */ +#define R_ALPHA_GPREL32 3 /* GP relative 32 bit */ +#define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */ +#define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */ +#define R_ALPHA_GPDISP 6 /* Add displacement to GP */ +#define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */ +#define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */ +#define R_ALPHA_SREL16 9 /* PC relative 16 bit */ +#define R_ALPHA_SREL32 10 /* PC relative 32 bit */ +#define R_ALPHA_SREL64 11 /* PC relative 64 bit */ +#define R_ALPHA_GPRELHIGH 17 /* GP relative 32 bit, high 16 bits */ +#define R_ALPHA_GPRELLOW 18 /* GP relative 32 bit, low 16 bits */ +#define R_ALPHA_GPREL16 19 /* GP relative 16 bit */ +#define R_ALPHA_COPY 24 /* Copy symbol at runtime */ +#define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */ +#define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */ +#define R_ALPHA_RELATIVE 27 /* Adjust by program base */ +#define R_ALPHA_TLS_GD_HI 28 +#define R_ALPHA_TLSGD 29 +#define R_ALPHA_TLS_LDM 30 +#define R_ALPHA_DTPMOD64 31 +#define R_ALPHA_GOTDTPREL 32 +#define R_ALPHA_DTPREL64 33 +#define R_ALPHA_DTPRELHI 34 +#define R_ALPHA_DTPRELLO 35 +#define R_ALPHA_DTPREL16 36 +#define R_ALPHA_GOTTPREL 37 +#define R_ALPHA_TPREL64 38 +#define R_ALPHA_TPRELHI 39 +#define R_ALPHA_TPRELLO 40 +#define R_ALPHA_TPREL16 41 /* Keep this the last entry. */ -#define R_ALPHA_NUM 46 +#define R_ALPHA_NUM 46 /* Magic values of the LITUSE relocation addend. */ -#define LITUSE_ALPHA_ADDR 0 -#define LITUSE_ALPHA_BASE 1 -#define LITUSE_ALPHA_BYTOFF 2 -#define LITUSE_ALPHA_JSR 3 -#define LITUSE_ALPHA_TLS_GD 4 -#define LITUSE_ALPHA_TLS_LDM 5 +#define LITUSE_ALPHA_ADDR 0 +#define LITUSE_ALPHA_BASE 1 +#define LITUSE_ALPHA_BYTOFF 2 +#define LITUSE_ALPHA_JSR 3 +#define LITUSE_ALPHA_TLS_GD 4 +#define LITUSE_ALPHA_TLS_LDM 5 /* Legal values for d_tag of Elf64_Dyn. */ -#define DT_ALPHA_PLTRO (DT_LOPROC + 0) -#define DT_ALPHA_NUM 1 +#define DT_ALPHA_PLTRO (DT_LOPROC + 0) +#define DT_ALPHA_NUM 1 /* PowerPC specific declarations */ /* Values for Elf32/64_Ehdr.e_flags. */ -#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */ +#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */ /* Cygnus local bits below */ -#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/ -#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib - flag */ +#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/ +#define EF_PPC_RELOCATABLE_LIB \ + 0x00008000 /* PowerPC -mrelocatable-lib \ + flag */ /* PowerPC relocations defined by the ABIs */ -#define R_PPC_NONE 0 -#define R_PPC_ADDR32 1 /* 32bit absolute address */ -#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */ -#define R_PPC_ADDR16 3 /* 16bit absolute address */ -#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */ -#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */ -#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */ -#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */ -#define R_PPC_ADDR14_BRTAKEN 8 -#define R_PPC_ADDR14_BRNTAKEN 9 -#define R_PPC_REL24 10 /* PC relative 26 bit */ -#define R_PPC_REL14 11 /* PC relative 16 bit */ -#define R_PPC_REL14_BRTAKEN 12 -#define R_PPC_REL14_BRNTAKEN 13 -#define R_PPC_GOT16 14 -#define R_PPC_GOT16_LO 15 -#define R_PPC_GOT16_HI 16 -#define R_PPC_GOT16_HA 17 -#define R_PPC_PLTREL24 18 -#define R_PPC_COPY 19 -#define R_PPC_GLOB_DAT 20 -#define R_PPC_JMP_SLOT 21 -#define R_PPC_RELATIVE 22 -#define R_PPC_LOCAL24PC 23 -#define R_PPC_UADDR32 24 -#define R_PPC_UADDR16 25 -#define R_PPC_REL32 26 -#define R_PPC_PLT32 27 -#define R_PPC_PLTREL32 28 -#define R_PPC_PLT16_LO 29 -#define R_PPC_PLT16_HI 30 -#define R_PPC_PLT16_HA 31 -#define R_PPC_SDAREL16 32 -#define R_PPC_SECTOFF 33 -#define R_PPC_SECTOFF_LO 34 -#define R_PPC_SECTOFF_HI 35 -#define R_PPC_SECTOFF_HA 36 +#define R_PPC_NONE 0 +#define R_PPC_ADDR32 1 /* 32bit absolute address */ +#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */ +#define R_PPC_ADDR16 3 /* 16bit absolute address */ +#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */ +#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */ +#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */ +#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */ +#define R_PPC_ADDR14_BRTAKEN 8 +#define R_PPC_ADDR14_BRNTAKEN 9 +#define R_PPC_REL24 10 /* PC relative 26 bit */ +#define R_PPC_REL14 11 /* PC relative 16 bit */ +#define R_PPC_REL14_BRTAKEN 12 +#define R_PPC_REL14_BRNTAKEN 13 +#define R_PPC_GOT16 14 +#define R_PPC_GOT16_LO 15 +#define R_PPC_GOT16_HI 16 +#define R_PPC_GOT16_HA 17 +#define R_PPC_PLTREL24 18 +#define R_PPC_COPY 19 +#define R_PPC_GLOB_DAT 20 +#define R_PPC_JMP_SLOT 21 +#define R_PPC_RELATIVE 22 +#define R_PPC_LOCAL24PC 23 +#define R_PPC_UADDR32 24 +#define R_PPC_UADDR16 25 +#define R_PPC_REL32 26 +#define R_PPC_PLT32 27 +#define R_PPC_PLTREL32 28 +#define R_PPC_PLT16_LO 29 +#define R_PPC_PLT16_HI 30 +#define R_PPC_PLT16_HA 31 +#define R_PPC_SDAREL16 32 +#define R_PPC_SECTOFF 33 +#define R_PPC_SECTOFF_LO 34 +#define R_PPC_SECTOFF_HI 35 +#define R_PPC_SECTOFF_HA 36 /* PowerPC relocations defined for the TLS access ABI. */ -#define R_PPC_TLS 67 /* none (sym+add)@tls */ -#define R_PPC_DTPMOD32 68 /* word32 (sym+add)@dtpmod */ -#define R_PPC_TPREL16 69 /* half16* (sym+add)@tprel */ -#define R_PPC_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ -#define R_PPC_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ -#define R_PPC_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ -#define R_PPC_TPREL32 73 /* word32 (sym+add)@tprel */ -#define R_PPC_DTPREL16 74 /* half16* (sym+add)@dtprel */ -#define R_PPC_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ -#define R_PPC_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ -#define R_PPC_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ -#define R_PPC_DTPREL32 78 /* word32 (sym+add)@dtprel */ -#define R_PPC_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ -#define R_PPC_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ -#define R_PPC_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ -#define R_PPC_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ -#define R_PPC_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ -#define R_PPC_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ -#define R_PPC_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ -#define R_PPC_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ -#define R_PPC_GOT_TPREL16 87 /* half16* (sym+add)@got@tprel */ -#define R_PPC_GOT_TPREL16_LO 88 /* half16 (sym+add)@got@tprel@l */ -#define R_PPC_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ -#define R_PPC_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ -#define R_PPC_GOT_DTPREL16 91 /* half16* (sym+add)@got@dtprel */ -#define R_PPC_GOT_DTPREL16_LO 92 /* half16* (sym+add)@got@dtprel@l */ -#define R_PPC_GOT_DTPREL16_HI 93 /* half16* (sym+add)@got@dtprel@h */ -#define R_PPC_GOT_DTPREL16_HA 94 /* half16* (sym+add)@got@dtprel@ha */ +#define R_PPC_TLS 67 /* none (sym+add)@tls */ +#define R_PPC_DTPMOD32 68 /* word32 (sym+add)@dtpmod */ +#define R_PPC_TPREL16 69 /* half16* (sym+add)@tprel */ +#define R_PPC_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ +#define R_PPC_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ +#define R_PPC_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ +#define R_PPC_TPREL32 73 /* word32 (sym+add)@tprel */ +#define R_PPC_DTPREL16 74 /* half16* (sym+add)@dtprel */ +#define R_PPC_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ +#define R_PPC_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ +#define R_PPC_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ +#define R_PPC_DTPREL32 78 /* word32 (sym+add)@dtprel */ +#define R_PPC_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ +#define R_PPC_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ +#define R_PPC_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ +#define R_PPC_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ +#define R_PPC_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ +#define R_PPC_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ +#define R_PPC_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ +#define R_PPC_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ +#define R_PPC_GOT_TPREL16 87 /* half16* (sym+add)@got@tprel */ +#define R_PPC_GOT_TPREL16_LO 88 /* half16 (sym+add)@got@tprel@l */ +#define R_PPC_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ +#define R_PPC_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ +#define R_PPC_GOT_DTPREL16 91 /* half16* (sym+add)@got@dtprel */ +#define R_PPC_GOT_DTPREL16_LO 92 /* half16* (sym+add)@got@dtprel@l */ +#define R_PPC_GOT_DTPREL16_HI 93 /* half16* (sym+add)@got@dtprel@h */ +#define R_PPC_GOT_DTPREL16_HA 94 /* half16* (sym+add)@got@dtprel@ha */ /* The remaining relocs are from the Embedded ELF ABI, and are not in the SVR4 ELF ABI. */ -#define R_PPC_EMB_NADDR32 101 -#define R_PPC_EMB_NADDR16 102 -#define R_PPC_EMB_NADDR16_LO 103 -#define R_PPC_EMB_NADDR16_HI 104 -#define R_PPC_EMB_NADDR16_HA 105 -#define R_PPC_EMB_SDAI16 106 -#define R_PPC_EMB_SDA2I16 107 -#define R_PPC_EMB_SDA2REL 108 -#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */ -#define R_PPC_EMB_MRKREF 110 -#define R_PPC_EMB_RELSEC16 111 -#define R_PPC_EMB_RELST_LO 112 -#define R_PPC_EMB_RELST_HI 113 -#define R_PPC_EMB_RELST_HA 114 -#define R_PPC_EMB_BIT_FLD 115 -#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */ +#define R_PPC_EMB_NADDR32 101 +#define R_PPC_EMB_NADDR16 102 +#define R_PPC_EMB_NADDR16_LO 103 +#define R_PPC_EMB_NADDR16_HI 104 +#define R_PPC_EMB_NADDR16_HA 105 +#define R_PPC_EMB_SDAI16 106 +#define R_PPC_EMB_SDA2I16 107 +#define R_PPC_EMB_SDA2REL 108 +#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */ +#define R_PPC_EMB_MRKREF 110 +#define R_PPC_EMB_RELSEC16 111 +#define R_PPC_EMB_RELST_LO 112 +#define R_PPC_EMB_RELST_HI 113 +#define R_PPC_EMB_RELST_HA 114 +#define R_PPC_EMB_BIT_FLD 115 +#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */ /* Diab tool relocations. */ -#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */ -#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */ -#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */ -#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */ -#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */ -#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */ +#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */ +#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */ +#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */ +#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */ +#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */ +#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */ /* GNU extension to support local ifunc. */ -#define R_PPC_IRELATIVE 248 +#define R_PPC_IRELATIVE 248 /* GNU relocs used in PIC code sequences. */ -#define R_PPC_REL16 249 /* half16 (sym+add-.) */ -#define R_PPC_REL16_LO 250 /* half16 (sym+add-.)@l */ -#define R_PPC_REL16_HI 251 /* half16 (sym+add-.)@h */ -#define R_PPC_REL16_HA 252 /* half16 (sym+add-.)@ha */ +#define R_PPC_REL16 249 /* half16 (sym+add-.) */ +#define R_PPC_REL16_LO 250 /* half16 (sym+add-.)@l */ +#define R_PPC_REL16_HI 251 /* half16 (sym+add-.)@h */ +#define R_PPC_REL16_HA 252 /* half16 (sym+add-.)@ha */ /* This is a phony reloc to handle any old fashioned TOC16 references that may still be in object files. */ -#define R_PPC_TOC16 255 +#define R_PPC_TOC16 255 /* PowerPC specific values for the Dyn d_tag field. */ -#define DT_PPC_GOT (DT_LOPROC + 0) -#define DT_PPC_NUM 1 +#define DT_PPC_GOT (DT_LOPROC + 0) +#define DT_PPC_NUM 1 /* PowerPC64 relocations defined by the ABIs */ -#define R_PPC64_NONE R_PPC_NONE -#define R_PPC64_ADDR32 R_PPC_ADDR32 /* 32bit absolute address */ -#define R_PPC64_ADDR24 R_PPC_ADDR24 /* 26bit address, word aligned */ -#define R_PPC64_ADDR16 R_PPC_ADDR16 /* 16bit absolute address */ -#define R_PPC64_ADDR16_LO R_PPC_ADDR16_LO /* lower 16bits of address */ -#define R_PPC64_ADDR16_HI R_PPC_ADDR16_HI /* high 16bits of address. */ -#define R_PPC64_ADDR16_HA R_PPC_ADDR16_HA /* adjusted high 16bits. */ -#define R_PPC64_ADDR14 R_PPC_ADDR14 /* 16bit address, word aligned */ -#define R_PPC64_ADDR14_BRTAKEN R_PPC_ADDR14_BRTAKEN -#define R_PPC64_ADDR14_BRNTAKEN R_PPC_ADDR14_BRNTAKEN -#define R_PPC64_REL24 R_PPC_REL24 /* PC-rel. 26 bit, word aligned */ -#define R_PPC64_REL14 R_PPC_REL14 /* PC relative 16 bit */ -#define R_PPC64_REL14_BRTAKEN R_PPC_REL14_BRTAKEN -#define R_PPC64_REL14_BRNTAKEN R_PPC_REL14_BRNTAKEN -#define R_PPC64_GOT16 R_PPC_GOT16 -#define R_PPC64_GOT16_LO R_PPC_GOT16_LO -#define R_PPC64_GOT16_HI R_PPC_GOT16_HI -#define R_PPC64_GOT16_HA R_PPC_GOT16_HA +#define R_PPC64_NONE R_PPC_NONE +#define R_PPC64_ADDR32 R_PPC_ADDR32 /* 32bit absolute address */ +#define R_PPC64_ADDR24 R_PPC_ADDR24 /* 26bit address, word aligned */ +#define R_PPC64_ADDR16 R_PPC_ADDR16 /* 16bit absolute address */ +#define R_PPC64_ADDR16_LO R_PPC_ADDR16_LO /* lower 16bits of address */ +#define R_PPC64_ADDR16_HI R_PPC_ADDR16_HI /* high 16bits of address. */ +#define R_PPC64_ADDR16_HA R_PPC_ADDR16_HA /* adjusted high 16bits. */ +#define R_PPC64_ADDR14 R_PPC_ADDR14 /* 16bit address, word aligned */ +#define R_PPC64_ADDR14_BRTAKEN R_PPC_ADDR14_BRTAKEN +#define R_PPC64_ADDR14_BRNTAKEN R_PPC_ADDR14_BRNTAKEN +#define R_PPC64_REL24 R_PPC_REL24 /* PC-rel. 26 bit, word aligned */ +#define R_PPC64_REL14 R_PPC_REL14 /* PC relative 16 bit */ +#define R_PPC64_REL14_BRTAKEN R_PPC_REL14_BRTAKEN +#define R_PPC64_REL14_BRNTAKEN R_PPC_REL14_BRNTAKEN +#define R_PPC64_GOT16 R_PPC_GOT16 +#define R_PPC64_GOT16_LO R_PPC_GOT16_LO +#define R_PPC64_GOT16_HI R_PPC_GOT16_HI +#define R_PPC64_GOT16_HA R_PPC_GOT16_HA -#define R_PPC64_COPY R_PPC_COPY -#define R_PPC64_GLOB_DAT R_PPC_GLOB_DAT -#define R_PPC64_JMP_SLOT R_PPC_JMP_SLOT -#define R_PPC64_RELATIVE R_PPC_RELATIVE +#define R_PPC64_COPY R_PPC_COPY +#define R_PPC64_GLOB_DAT R_PPC_GLOB_DAT +#define R_PPC64_JMP_SLOT R_PPC_JMP_SLOT +#define R_PPC64_RELATIVE R_PPC_RELATIVE -#define R_PPC64_UADDR32 R_PPC_UADDR32 -#define R_PPC64_UADDR16 R_PPC_UADDR16 -#define R_PPC64_REL32 R_PPC_REL32 -#define R_PPC64_PLT32 R_PPC_PLT32 -#define R_PPC64_PLTREL32 R_PPC_PLTREL32 -#define R_PPC64_PLT16_LO R_PPC_PLT16_LO -#define R_PPC64_PLT16_HI R_PPC_PLT16_HI -#define R_PPC64_PLT16_HA R_PPC_PLT16_HA +#define R_PPC64_UADDR32 R_PPC_UADDR32 +#define R_PPC64_UADDR16 R_PPC_UADDR16 +#define R_PPC64_REL32 R_PPC_REL32 +#define R_PPC64_PLT32 R_PPC_PLT32 +#define R_PPC64_PLTREL32 R_PPC_PLTREL32 +#define R_PPC64_PLT16_LO R_PPC_PLT16_LO +#define R_PPC64_PLT16_HI R_PPC_PLT16_HI +#define R_PPC64_PLT16_HA R_PPC_PLT16_HA -#define R_PPC64_SECTOFF R_PPC_SECTOFF -#define R_PPC64_SECTOFF_LO R_PPC_SECTOFF_LO -#define R_PPC64_SECTOFF_HI R_PPC_SECTOFF_HI -#define R_PPC64_SECTOFF_HA R_PPC_SECTOFF_HA -#define R_PPC64_ADDR30 37 /* word30 (S + A - P) >> 2 */ -#define R_PPC64_ADDR64 38 /* doubleword64 S + A */ -#define R_PPC64_ADDR16_HIGHER 39 /* half16 #higher(S + A) */ -#define R_PPC64_ADDR16_HIGHERA 40 /* half16 #highera(S + A) */ -#define R_PPC64_ADDR16_HIGHEST 41 /* half16 #highest(S + A) */ -#define R_PPC64_ADDR16_HIGHESTA 42 /* half16 #highesta(S + A) */ -#define R_PPC64_UADDR64 43 /* doubleword64 S + A */ -#define R_PPC64_REL64 44 /* doubleword64 S + A - P */ -#define R_PPC64_PLT64 45 /* doubleword64 L + A */ -#define R_PPC64_PLTREL64 46 /* doubleword64 L + A - P */ -#define R_PPC64_TOC16 47 /* half16* S + A - .TOC */ -#define R_PPC64_TOC16_LO 48 /* half16 #lo(S + A - .TOC.) */ -#define R_PPC64_TOC16_HI 49 /* half16 #hi(S + A - .TOC.) */ -#define R_PPC64_TOC16_HA 50 /* half16 #ha(S + A - .TOC.) */ -#define R_PPC64_TOC 51 /* doubleword64 .TOC */ -#define R_PPC64_PLTGOT16 52 /* half16* M + A */ -#define R_PPC64_PLTGOT16_LO 53 /* half16 #lo(M + A) */ -#define R_PPC64_PLTGOT16_HI 54 /* half16 #hi(M + A) */ -#define R_PPC64_PLTGOT16_HA 55 /* half16 #ha(M + A) */ +#define R_PPC64_SECTOFF R_PPC_SECTOFF +#define R_PPC64_SECTOFF_LO R_PPC_SECTOFF_LO +#define R_PPC64_SECTOFF_HI R_PPC_SECTOFF_HI +#define R_PPC64_SECTOFF_HA R_PPC_SECTOFF_HA +#define R_PPC64_ADDR30 37 /* word30 (S + A - P) >> 2 */ +#define R_PPC64_ADDR64 38 /* doubleword64 S + A */ +#define R_PPC64_ADDR16_HIGHER 39 /* half16 #higher(S + A) */ +#define R_PPC64_ADDR16_HIGHERA 40 /* half16 #highera(S + A) */ +#define R_PPC64_ADDR16_HIGHEST 41 /* half16 #highest(S + A) */ +#define R_PPC64_ADDR16_HIGHESTA 42 /* half16 #highesta(S + A) */ +#define R_PPC64_UADDR64 43 /* doubleword64 S + A */ +#define R_PPC64_REL64 44 /* doubleword64 S + A - P */ +#define R_PPC64_PLT64 45 /* doubleword64 L + A */ +#define R_PPC64_PLTREL64 46 /* doubleword64 L + A - P */ +#define R_PPC64_TOC16 47 /* half16* S + A - .TOC */ +#define R_PPC64_TOC16_LO 48 /* half16 #lo(S + A - .TOC.) */ +#define R_PPC64_TOC16_HI 49 /* half16 #hi(S + A - .TOC.) */ +#define R_PPC64_TOC16_HA 50 /* half16 #ha(S + A - .TOC.) */ +#define R_PPC64_TOC 51 /* doubleword64 .TOC */ +#define R_PPC64_PLTGOT16 52 /* half16* M + A */ +#define R_PPC64_PLTGOT16_LO 53 /* half16 #lo(M + A) */ +#define R_PPC64_PLTGOT16_HI 54 /* half16 #hi(M + A) */ +#define R_PPC64_PLTGOT16_HA 55 /* half16 #ha(M + A) */ -#define R_PPC64_ADDR16_DS 56 /* half16ds* (S + A) >> 2 */ -#define R_PPC64_ADDR16_LO_DS 57 /* half16ds #lo(S + A) >> 2 */ -#define R_PPC64_GOT16_DS 58 /* half16ds* (G + A) >> 2 */ -#define R_PPC64_GOT16_LO_DS 59 /* half16ds #lo(G + A) >> 2 */ -#define R_PPC64_PLT16_LO_DS 60 /* half16ds #lo(L + A) >> 2 */ -#define R_PPC64_SECTOFF_DS 61 /* half16ds* (R + A) >> 2 */ -#define R_PPC64_SECTOFF_LO_DS 62 /* half16ds #lo(R + A) >> 2 */ -#define R_PPC64_TOC16_DS 63 /* half16ds* (S + A - .TOC.) >> 2 */ -#define R_PPC64_TOC16_LO_DS 64 /* half16ds #lo(S + A - .TOC.) >> 2 */ -#define R_PPC64_PLTGOT16_DS 65 /* half16ds* (M + A) >> 2 */ -#define R_PPC64_PLTGOT16_LO_DS 66 /* half16ds #lo(M + A) >> 2 */ +#define R_PPC64_ADDR16_DS 56 /* half16ds* (S + A) >> 2 */ +#define R_PPC64_ADDR16_LO_DS 57 /* half16ds #lo(S + A) >> 2 */ +#define R_PPC64_GOT16_DS 58 /* half16ds* (G + A) >> 2 */ +#define R_PPC64_GOT16_LO_DS 59 /* half16ds #lo(G + A) >> 2 */ +#define R_PPC64_PLT16_LO_DS 60 /* half16ds #lo(L + A) >> 2 */ +#define R_PPC64_SECTOFF_DS 61 /* half16ds* (R + A) >> 2 */ +#define R_PPC64_SECTOFF_LO_DS 62 /* half16ds #lo(R + A) >> 2 */ +#define R_PPC64_TOC16_DS 63 /* half16ds* (S + A - .TOC.) >> 2 */ +#define R_PPC64_TOC16_LO_DS 64 /* half16ds #lo(S + A - .TOC.) >> 2 */ +#define R_PPC64_PLTGOT16_DS 65 /* half16ds* (M + A) >> 2 */ +#define R_PPC64_PLTGOT16_LO_DS 66 /* half16ds #lo(M + A) >> 2 */ /* PowerPC64 relocations defined for the TLS access ABI. */ -#define R_PPC64_TLS 67 /* none (sym+add)@tls */ -#define R_PPC64_DTPMOD64 68 /* doubleword64 (sym+add)@dtpmod */ -#define R_PPC64_TPREL16 69 /* half16* (sym+add)@tprel */ -#define R_PPC64_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ -#define R_PPC64_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ -#define R_PPC64_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ -#define R_PPC64_TPREL64 73 /* doubleword64 (sym+add)@tprel */ -#define R_PPC64_DTPREL16 74 /* half16* (sym+add)@dtprel */ -#define R_PPC64_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ -#define R_PPC64_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ -#define R_PPC64_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ -#define R_PPC64_DTPREL64 78 /* doubleword64 (sym+add)@dtprel */ -#define R_PPC64_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ -#define R_PPC64_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ -#define R_PPC64_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ -#define R_PPC64_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ -#define R_PPC64_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ -#define R_PPC64_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ -#define R_PPC64_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ -#define R_PPC64_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ -#define R_PPC64_GOT_TPREL16_DS 87 /* half16ds* (sym+add)@got@tprel */ -#define R_PPC64_GOT_TPREL16_LO_DS 88 /* half16ds (sym+add)@got@tprel@l */ -#define R_PPC64_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ -#define R_PPC64_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ -#define R_PPC64_GOT_DTPREL16_DS 91 /* half16ds* (sym+add)@got@dtprel */ +#define R_PPC64_TLS 67 /* none (sym+add)@tls */ +#define R_PPC64_DTPMOD64 68 /* doubleword64 (sym+add)@dtpmod */ +#define R_PPC64_TPREL16 69 /* half16* (sym+add)@tprel */ +#define R_PPC64_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ +#define R_PPC64_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ +#define R_PPC64_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ +#define R_PPC64_TPREL64 73 /* doubleword64 (sym+add)@tprel */ +#define R_PPC64_DTPREL16 74 /* half16* (sym+add)@dtprel */ +#define R_PPC64_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ +#define R_PPC64_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ +#define R_PPC64_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ +#define R_PPC64_DTPREL64 78 /* doubleword64 (sym+add)@dtprel */ +#define R_PPC64_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ +#define R_PPC64_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ +#define R_PPC64_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ +#define R_PPC64_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ +#define R_PPC64_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ +#define R_PPC64_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ +#define R_PPC64_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ +#define R_PPC64_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ +#define R_PPC64_GOT_TPREL16_DS 87 /* half16ds* (sym+add)@got@tprel */ +#define R_PPC64_GOT_TPREL16_LO_DS 88 /* half16ds (sym+add)@got@tprel@l */ +#define R_PPC64_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ +#define R_PPC64_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ +#define R_PPC64_GOT_DTPREL16_DS 91 /* half16ds* (sym+add)@got@dtprel */ #define R_PPC64_GOT_DTPREL16_LO_DS 92 /* half16ds (sym+add)@got@dtprel@l */ -#define R_PPC64_GOT_DTPREL16_HI 93 /* half16 (sym+add)@got@dtprel@h */ -#define R_PPC64_GOT_DTPREL16_HA 94 /* half16 (sym+add)@got@dtprel@ha */ -#define R_PPC64_TPREL16_DS 95 /* half16ds* (sym+add)@tprel */ -#define R_PPC64_TPREL16_LO_DS 96 /* half16ds (sym+add)@tprel@l */ -#define R_PPC64_TPREL16_HIGHER 97 /* half16 (sym+add)@tprel@higher */ -#define R_PPC64_TPREL16_HIGHERA 98 /* half16 (sym+add)@tprel@highera */ -#define R_PPC64_TPREL16_HIGHEST 99 /* half16 (sym+add)@tprel@highest */ -#define R_PPC64_TPREL16_HIGHESTA 100 /* half16 (sym+add)@tprel@highesta */ -#define R_PPC64_DTPREL16_DS 101 /* half16ds* (sym+add)@dtprel */ -#define R_PPC64_DTPREL16_LO_DS 102 /* half16ds (sym+add)@dtprel@l */ -#define R_PPC64_DTPREL16_HIGHER 103 /* half16 (sym+add)@dtprel@higher */ -#define R_PPC64_DTPREL16_HIGHERA 104 /* half16 (sym+add)@dtprel@highera */ -#define R_PPC64_DTPREL16_HIGHEST 105 /* half16 (sym+add)@dtprel@highest */ +#define R_PPC64_GOT_DTPREL16_HI 93 /* half16 (sym+add)@got@dtprel@h */ +#define R_PPC64_GOT_DTPREL16_HA 94 /* half16 (sym+add)@got@dtprel@ha */ +#define R_PPC64_TPREL16_DS 95 /* half16ds* (sym+add)@tprel */ +#define R_PPC64_TPREL16_LO_DS 96 /* half16ds (sym+add)@tprel@l */ +#define R_PPC64_TPREL16_HIGHER 97 /* half16 (sym+add)@tprel@higher */ +#define R_PPC64_TPREL16_HIGHERA 98 /* half16 (sym+add)@tprel@highera */ +#define R_PPC64_TPREL16_HIGHEST 99 /* half16 (sym+add)@tprel@highest */ +#define R_PPC64_TPREL16_HIGHESTA 100 /* half16 (sym+add)@tprel@highesta */ +#define R_PPC64_DTPREL16_DS 101 /* half16ds* (sym+add)@dtprel */ +#define R_PPC64_DTPREL16_LO_DS 102 /* half16ds (sym+add)@dtprel@l */ +#define R_PPC64_DTPREL16_HIGHER 103 /* half16 (sym+add)@dtprel@higher */ +#define R_PPC64_DTPREL16_HIGHERA 104 /* half16 (sym+add)@dtprel@highera */ +#define R_PPC64_DTPREL16_HIGHEST 105 /* half16 (sym+add)@dtprel@highest */ #define R_PPC64_DTPREL16_HIGHESTA 106 /* half16 (sym+add)@dtprel@highesta */ /* GNU extension to support local ifunc. */ -#define R_PPC64_JMP_IREL 247 -#define R_PPC64_IRELATIVE 248 -#define R_PPC64_REL16 249 /* half16 (sym+add-.) */ -#define R_PPC64_REL16_LO 250 /* half16 (sym+add-.)@l */ -#define R_PPC64_REL16_HI 251 /* half16 (sym+add-.)@h */ -#define R_PPC64_REL16_HA 252 /* half16 (sym+add-.)@ha */ +#define R_PPC64_JMP_IREL 247 +#define R_PPC64_IRELATIVE 248 +#define R_PPC64_REL16 249 /* half16 (sym+add-.) */ +#define R_PPC64_REL16_LO 250 /* half16 (sym+add-.)@l */ +#define R_PPC64_REL16_HI 251 /* half16 (sym+add-.)@h */ +#define R_PPC64_REL16_HA 252 /* half16 (sym+add-.)@ha */ /* PowerPC64 specific values for the Dyn d_tag field. */ -#define DT_PPC64_GLINK (DT_LOPROC + 0) -#define DT_PPC64_OPD (DT_LOPROC + 1) -#define DT_PPC64_OPDSZ (DT_LOPROC + 2) -#define DT_PPC64_NUM 3 - +#define DT_PPC64_GLINK (DT_LOPROC + 0) +#define DT_PPC64_OPD (DT_LOPROC + 1) +#define DT_PPC64_OPDSZ (DT_LOPROC + 2) +#define DT_PPC64_NUM 3 /* ARM specific declarations */ /* Processor specific flags for the ELF header e_flags field. */ -#define EF_ARM_RELEXEC 0x01 -#define EF_ARM_HASENTRY 0x02 -#define EF_ARM_INTERWORK 0x04 -#define EF_ARM_APCS_26 0x08 -#define EF_ARM_APCS_FLOAT 0x10 -#define EF_ARM_PIC 0x20 -#define EF_ARM_ALIGN8 0x40 /* 8-bit structure alignment is in use */ -#define EF_ARM_NEW_ABI 0x80 -#define EF_ARM_OLD_ABI 0x100 -#define EF_ARM_SOFT_FLOAT 0x200 -#define EF_ARM_VFP_FLOAT 0x400 -#define EF_ARM_MAVERICK_FLOAT 0x800 - -#define EF_ARM_ABI_FLOAT_SOFT 0x200 /* NB conflicts with EF_ARM_SOFT_FLOAT */ -#define EF_ARM_ABI_FLOAT_HARD 0x400 /* NB conflicts with EF_ARM_VFP_FLOAT */ +#define EF_ARM_RELEXEC 0x01 +#define EF_ARM_HASENTRY 0x02 +#define EF_ARM_INTERWORK 0x04 +#define EF_ARM_APCS_26 0x08 +#define EF_ARM_APCS_FLOAT 0x10 +#define EF_ARM_PIC 0x20 +#define EF_ARM_ALIGN8 0x40 /* 8-bit structure alignment is in use */ +#define EF_ARM_NEW_ABI 0x80 +#define EF_ARM_OLD_ABI 0x100 +#define EF_ARM_SOFT_FLOAT 0x200 +#define EF_ARM_VFP_FLOAT 0x400 +#define EF_ARM_MAVERICK_FLOAT 0x800 +#define EF_ARM_ABI_FLOAT_SOFT 0x200 /* NB conflicts with EF_ARM_SOFT_FLOAT */ +#define EF_ARM_ABI_FLOAT_HARD 0x400 /* NB conflicts with EF_ARM_VFP_FLOAT */ /* Other constants defined in the ARM ELF spec. version B-01. */ /* NB. These conflict with values defined above. */ -#define EF_ARM_SYMSARESORTED 0x04 -#define EF_ARM_DYNSYMSUSESEGIDX 0x08 -#define EF_ARM_MAPSYMSFIRST 0x10 -#define EF_ARM_EABIMASK 0XFF000000 +#define EF_ARM_SYMSARESORTED 0x04 +#define EF_ARM_DYNSYMSUSESEGIDX 0x08 +#define EF_ARM_MAPSYMSFIRST 0x10 +#define EF_ARM_EABIMASK 0XFF000000 /* Constants defined in AAELF. */ -#define EF_ARM_BE8 0x00800000 -#define EF_ARM_LE8 0x00400000 +#define EF_ARM_BE8 0x00800000 +#define EF_ARM_LE8 0x00400000 -#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) -#define EF_ARM_EABI_UNKNOWN 0x00000000 -#define EF_ARM_EABI_VER1 0x01000000 -#define EF_ARM_EABI_VER2 0x02000000 -#define EF_ARM_EABI_VER3 0x03000000 -#define EF_ARM_EABI_VER4 0x04000000 -#define EF_ARM_EABI_VER5 0x05000000 +#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) +#define EF_ARM_EABI_UNKNOWN 0x00000000 +#define EF_ARM_EABI_VER1 0x01000000 +#define EF_ARM_EABI_VER2 0x02000000 +#define EF_ARM_EABI_VER3 0x03000000 +#define EF_ARM_EABI_VER4 0x04000000 +#define EF_ARM_EABI_VER5 0x05000000 /* Additional symbol types for Thumb. */ -#define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */ -#define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */ +#define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */ +#define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */ /* ARM-specific values for sh_flags */ -#define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */ -#define SHF_ARM_COMDEF 0x80000000 /* Section may be multiply defined - in the input to a link step. */ +#define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */ +#define SHF_ARM_COMDEF \ + 0x80000000 /* Section may be multiply defined \ + in the input to a link step. */ /* ARM-specific program header flags */ -#define PF_ARM_SB 0x10000000 /* Segment contains the location - addressed by the static base. */ -#define PF_ARM_PI 0x20000000 /* Position-independent segment. */ -#define PF_ARM_ABS 0x40000000 /* Absolute segment. */ +#define PF_ARM_SB \ + 0x10000000 /* Segment contains the location \ + addressed by the static base. */ +#define PF_ARM_PI 0x20000000 /* Position-independent segment. */ +#define PF_ARM_ABS 0x40000000 /* Absolute segment. */ /* Processor specific values for the Phdr p_type field. */ -#define PT_ARM_EXIDX (PT_LOPROC + 1) /* ARM unwind segment. */ +#define PT_ARM_EXIDX (PT_LOPROC + 1) /* ARM unwind segment. */ /* Processor specific values for the Shdr sh_type field. */ -#define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */ -#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) /* Preemption details. */ -#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */ - +#define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */ +#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) /* Preemption details. */ +#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */ /* AArch64 relocs. */ -#define R_AARCH64_NONE 0 /* No relocation. */ -#define R_AARCH64_ABS64 257 /* Direct 64 bit. */ -#define R_AARCH64_ABS32 258 /* Direct 32 bit. */ -#define R_AARCH64_ABS16 259 /* Direct 16-bit. */ -#define R_AARCH64_PREL64 260 /* PC-relative 64-bit. */ -#define R_AARCH64_PREL32 261 /* PC-relative 32-bit. */ -#define R_AARCH64_PREL16 262 /* PC-relative 16-bit. */ -#define R_AARCH64_MOVW_UABS_G0 263 /* Dir. MOVZ imm. from bits 15:0. */ -#define R_AARCH64_MOVW_UABS_G0_NC 264 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_UABS_G1 265 /* Dir. MOVZ imm. from bits 31:16. */ -#define R_AARCH64_MOVW_UABS_G1_NC 266 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_UABS_G2 267 /* Dir. MOVZ imm. from bits 47:32. */ -#define R_AARCH64_MOVW_UABS_G2_NC 268 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_UABS_G3 269 /* Dir. MOV{K,Z} imm. from 63:48. */ -#define R_AARCH64_MOVW_SABS_G0 270 /* Dir. MOV{N,Z} imm. from 15:0. */ -#define R_AARCH64_MOVW_SABS_G1 271 /* Dir. MOV{N,Z} imm. from 31:16. */ -#define R_AARCH64_MOVW_SABS_G2 272 /* Dir. MOV{N,Z} imm. from 47:32. */ -#define R_AARCH64_LD_PREL_LO19 273 /* PC-rel. LD imm. from bits 20:2. */ -#define R_AARCH64_ADR_PREL_LO21 274 /* PC-rel. ADR imm. from bits 20:0. */ -#define R_AARCH64_ADR_PREL_PG_HI21 275 /* Page-rel. ADRP imm. from 32:12. */ -#define R_AARCH64_ADR_PREL_PG_HI21_NC 276 /* Likewise; no overflow check. */ -#define R_AARCH64_ADD_ABS_LO12_NC 277 /* Dir. ADD imm. from bits 11:0. */ -#define R_AARCH64_LDST8_ABS_LO12_NC 278 /* Likewise for LD/ST; no check. */ -#define R_AARCH64_TSTBR14 279 /* PC-rel. TBZ/TBNZ imm. from 15:2. */ -#define R_AARCH64_CONDBR19 280 /* PC-rel. cond. br. imm. from 20:2. */ -#define R_AARCH64_JUMP26 282 /* PC-rel. B imm. from bits 27:2. */ -#define R_AARCH64_CALL26 283 /* Likewise for CALL. */ -#define R_AARCH64_LDST16_ABS_LO12_NC 284 /* Dir. ADD imm. from bits 11:1. */ -#define R_AARCH64_LDST32_ABS_LO12_NC 285 /* Likewise for bits 11:2. */ -#define R_AARCH64_LDST64_ABS_LO12_NC 286 /* Likewise for bits 11:3. */ -#define R_AARCH64_MOVW_PREL_G0 287 /* PC-rel. MOV{N,Z} imm. from 15:0. */ -#define R_AARCH64_MOVW_PREL_G0_NC 288 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_PREL_G1 289 /* PC-rel. MOV{N,Z} imm. from 31:16. */ -#define R_AARCH64_MOVW_PREL_G1_NC 290 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_PREL_G2 291 /* PC-rel. MOV{N,Z} imm. from 47:32. */ -#define R_AARCH64_MOVW_PREL_G2_NC 292 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_PREL_G3 293 /* PC-rel. MOV{N,Z} imm. from 63:48. */ -#define R_AARCH64_LDST128_ABS_LO12_NC 299 /* Dir. ADD imm. from bits 11:4. */ -#define R_AARCH64_MOVW_GOTOFF_G0 300 /* GOT-rel. off. MOV{N,Z} imm. 15:0. */ -#define R_AARCH64_MOVW_GOTOFF_G0_NC 301 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_GOTOFF_G1 302 /* GOT-rel. o. MOV{N,Z} imm. 31:16. */ -#define R_AARCH64_MOVW_GOTOFF_G1_NC 303 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_GOTOFF_G2 304 /* GOT-rel. o. MOV{N,Z} imm. 47:32. */ -#define R_AARCH64_MOVW_GOTOFF_G2_NC 305 /* Likewise for MOVK; no check. */ -#define R_AARCH64_MOVW_GOTOFF_G3 306 /* GOT-rel. o. MOV{N,Z} imm. 63:48. */ -#define R_AARCH64_GOTREL64 307 /* GOT-relative 64-bit. */ -#define R_AARCH64_GOTREL32 308 /* GOT-relative 32-bit. */ -#define R_AARCH64_GOT_LD_PREL19 309 /* PC-rel. GOT off. load imm. 20:2. */ -#define R_AARCH64_LD64_GOTOFF_LO15 310 /* GOT-rel. off. LD/ST imm. 14:3. */ -#define R_AARCH64_ADR_GOT_PAGE 311 /* P-page-rel. GOT off. ADRP 32:12. */ -#define R_AARCH64_LD64_GOT_LO12_NC 312 /* Dir. GOT off. LD/ST imm. 11:3. */ -#define R_AARCH64_LD64_GOTPAGE_LO15 313 /* GOT-page-rel. GOT off. LD/ST 14:3 */ -#define R_AARCH64_TLSGD_ADR_PREL21 512 /* PC-relative ADR imm. 20:0. */ -#define R_AARCH64_TLSGD_ADR_PAGE21 513 /* page-rel. ADRP imm. 32:12. */ -#define R_AARCH64_TLSGD_ADD_LO12_NC 514 /* direct ADD imm. from 11:0. */ -#define R_AARCH64_TLSGD_MOVW_G1 515 /* GOT-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSGD_MOVW_G0_NC 516 /* GOT-rel. MOVK imm. 15:0. */ -#define R_AARCH64_TLSLD_ADR_PREL21 517 /* Like 512; local dynamic model. */ -#define R_AARCH64_TLSLD_ADR_PAGE21 518 /* Like 513; local dynamic model. */ -#define R_AARCH64_TLSLD_ADD_LO12_NC 519 /* Like 514; local dynamic model. */ -#define R_AARCH64_TLSLD_MOVW_G1 520 /* Like 515; local dynamic model. */ -#define R_AARCH64_TLSLD_MOVW_G0_NC 521 /* Like 516; local dynamic model. */ -#define R_AARCH64_TLSLD_LD_PREL19 522 /* TLS PC-rel. load imm. 20:2. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G2 523 /* TLS DTP-rel. MOV{N,Z} 47:32. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G1 524 /* TLS DTP-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G0 526 /* TLS DTP-rel. MOV{N,Z} 15:0. */ -#define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLD_ADD_DTPREL_HI12 528 /* DTP-rel. ADD imm. from 23:12. */ -#define R_AARCH64_TLSLD_ADD_DTPREL_LO12 529 /* DTP-rel. ADD imm. from 11:0. */ -#define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC 530 /* Likewise; no ovfl. check. */ -#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531 /* DTP-rel. LD/ST imm. 11:0. */ -#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC 532 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12 533 /* DTP-rel. LD/ST imm. 11:1. */ -#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12 535 /* DTP-rel. LD/ST imm. 11:2. */ -#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12 537 /* DTP-rel. LD/ST imm. 11:3. */ -#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC 538 /* Likewise; no check. */ -#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 539 /* GOT-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC 540 /* GOT-rel. MOVK 15:0. */ -#define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 541 /* Page-rel. ADRP 32:12. */ -#define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC 542 /* Direct LD off. 11:3. */ -#define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 543 /* PC-rel. load imm. 20:2. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G2 544 /* TLS TP-rel. MOV{N,Z} 47:32. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G1 545 /* TLS TP-rel. MOV{N,Z} 31:16. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G1_NC 546 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G0 547 /* TLS TP-rel. MOV{N,Z} 15:0. */ -#define R_AARCH64_TLSLE_MOVW_TPREL_G0_NC 548 /* Likewise; MOVK; no check. */ -#define R_AARCH64_TLSLE_ADD_TPREL_HI12 549 /* TP-rel. ADD imm. 23:12. */ -#define R_AARCH64_TLSLE_ADD_TPREL_LO12 550 /* TP-rel. ADD imm. 11:0. */ -#define R_AARCH64_TLSLE_ADD_TPREL_LO12_NC 551 /* Likewise; no ovfl. check. */ -#define R_AARCH64_TLSLE_LDST8_TPREL_LO12 552 /* TP-rel. LD/ST off. 11:0. */ -#define R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC 553 /* Likewise; no ovfl. check. */ -#define R_AARCH64_TLSLE_LDST16_TPREL_LO12 554 /* TP-rel. LD/ST off. 11:1. */ -#define R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC 555 /* Likewise; no check. */ -#define R_AARCH64_TLSLE_LDST32_TPREL_LO12 556 /* TP-rel. LD/ST off. 11:2. */ -#define R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC 557 /* Likewise; no check. */ -#define R_AARCH64_TLSLE_LDST64_TPREL_LO12 558 /* TP-rel. LD/ST off. 11:3. */ -#define R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC 559 /* Likewise; no check. */ -#define R_AARCH64_TLSDESC_LD_PREL19 560 /* PC-rel. load immediate 20:2. */ -#define R_AARCH64_TLSDESC_ADR_PREL21 561 /* PC-rel. ADR immediate 20:0. */ -#define R_AARCH64_TLSDESC_ADR_PAGE21 562 /* Page-rel. ADRP imm. 32:12. */ -#define R_AARCH64_TLSDESC_LD64_LO12 563 /* Direct LD off. from 11:3. */ -#define R_AARCH64_TLSDESC_ADD_LO12 564 /* Direct ADD imm. from 11:0. */ -#define R_AARCH64_TLSDESC_OFF_G1 565 /* GOT-rel. MOV{N,Z} imm. 31:16. */ -#define R_AARCH64_TLSDESC_OFF_G0_NC 566 /* GOT-rel. MOVK imm. 15:0; no ck. */ -#define R_AARCH64_TLSDESC_LDR 567 /* Relax LDR. */ -#define R_AARCH64_TLSDESC_ADD 568 /* Relax ADD. */ -#define R_AARCH64_TLSDESC_CALL 569 /* Relax BLR. */ -#define R_AARCH64_TLSLE_LDST128_TPREL_LO12 570 /* TP-rel. LD/ST off. 11:4. */ -#define R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC 571 /* Likewise; no check. */ -#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12 572 /* DTP-rel. LD/ST imm. 11:4. */ -#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC 573 /* Likewise; no check. */ -#define R_AARCH64_COPY 1024 /* Copy symbol at runtime. */ -#define R_AARCH64_GLOB_DAT 1025 /* Create GOT entry. */ -#define R_AARCH64_JUMP_SLOT 1026 /* Create PLT entry. */ -#define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */ -#define R_AARCH64_TLS_DTPMOD64 1028 /* Module number, 64 bit. */ -#define R_AARCH64_TLS_DTPREL64 1029 /* Module-relative offset, 64 bit. */ -#define R_AARCH64_TLS_TPREL64 1030 /* TP-relative offset, 64 bit. */ -#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */ -#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */ +#define R_AARCH64_NONE 0 /* No relocation. */ +#define R_AARCH64_ABS64 257 /* Direct 64 bit. */ +#define R_AARCH64_ABS32 258 /* Direct 32 bit. */ +#define R_AARCH64_ABS16 259 /* Direct 16-bit. */ +#define R_AARCH64_PREL64 260 /* PC-relative 64-bit. */ +#define R_AARCH64_PREL32 261 /* PC-relative 32-bit. */ +#define R_AARCH64_PREL16 262 /* PC-relative 16-bit. */ +#define R_AARCH64_MOVW_UABS_G0 263 /* Dir. MOVZ imm. from bits 15:0. */ +#define R_AARCH64_MOVW_UABS_G0_NC 264 /* Likewise for MOVK; no check. */ +#define R_AARCH64_MOVW_UABS_G1 265 /* Dir. MOVZ imm. from bits 31:16. */ +#define R_AARCH64_MOVW_UABS_G1_NC 266 /* Likewise for MOVK; no check. */ +#define R_AARCH64_MOVW_UABS_G2 267 /* Dir. MOVZ imm. from bits 47:32. */ +#define R_AARCH64_MOVW_UABS_G2_NC 268 /* Likewise for MOVK; no check. */ +#define R_AARCH64_MOVW_UABS_G3 269 /* Dir. MOV{K,Z} imm. from 63:48. */ +#define R_AARCH64_MOVW_SABS_G0 270 /* Dir. MOV{N,Z} imm. from 15:0. */ +#define R_AARCH64_MOVW_SABS_G1 271 /* Dir. MOV{N,Z} imm. from 31:16. */ +#define R_AARCH64_MOVW_SABS_G2 272 /* Dir. MOV{N,Z} imm. from 47:32. */ +#define R_AARCH64_LD_PREL_LO19 273 /* PC-rel. LD imm. from bits 20:2. */ +#define R_AARCH64_ADR_PREL_LO21 274 /* PC-rel. ADR imm. from bits 20:0. */ +#define R_AARCH64_ADR_PREL_PG_HI21 275 /* Page-rel. ADRP imm. from 32:12. */ +#define R_AARCH64_ADR_PREL_PG_HI21_NC 276 /* Likewise; no overflow check. */ +#define R_AARCH64_ADD_ABS_LO12_NC 277 /* Dir. ADD imm. from bits 11:0. */ +#define R_AARCH64_LDST8_ABS_LO12_NC 278 /* Likewise for LD/ST; no check. */ +#define R_AARCH64_TSTBR14 279 /* PC-rel. TBZ/TBNZ imm. from 15:2. */ +#define R_AARCH64_CONDBR19 280 /* PC-rel. cond. br. imm. from 20:2. */ +#define R_AARCH64_JUMP26 282 /* PC-rel. B imm. from bits 27:2. */ +#define R_AARCH64_CALL26 283 /* Likewise for CALL. */ +#define R_AARCH64_LDST16_ABS_LO12_NC 284 /* Dir. ADD imm. from bits 11:1. */ +#define R_AARCH64_LDST32_ABS_LO12_NC 285 /* Likewise for bits 11:2. */ +#define R_AARCH64_LDST64_ABS_LO12_NC 286 /* Likewise for bits 11:3. */ +#define R_AARCH64_MOVW_PREL_G0 287 /* PC-rel. MOV{N,Z} imm. from 15:0. */ +#define R_AARCH64_MOVW_PREL_G0_NC 288 /* Likewise for MOVK; no check. */ +#define R_AARCH64_MOVW_PREL_G1 289 /* PC-rel. MOV{N,Z} imm. from 31:16. */ +#define R_AARCH64_MOVW_PREL_G1_NC 290 /* Likewise for MOVK; no check. */ +#define R_AARCH64_MOVW_PREL_G2 291 /* PC-rel. MOV{N,Z} imm. from 47:32. */ +#define R_AARCH64_MOVW_PREL_G2_NC 292 /* Likewise for MOVK; no check. */ +#define R_AARCH64_MOVW_PREL_G3 293 /* PC-rel. MOV{N,Z} imm. from 63:48. */ +#define R_AARCH64_LDST128_ABS_LO12_NC 299 /* Dir. ADD imm. from bits 11:4. */ +#define R_AARCH64_MOVW_GOTOFF_G0 300 /* GOT-rel. off. MOV{N,Z} imm. 15:0. */ +#define R_AARCH64_MOVW_GOTOFF_G0_NC 301 /* Likewise for MOVK; no check. */ +#define R_AARCH64_MOVW_GOTOFF_G1 302 /* GOT-rel. o. MOV{N,Z} imm. 31:16. */ +#define R_AARCH64_MOVW_GOTOFF_G1_NC 303 /* Likewise for MOVK; no check. */ +#define R_AARCH64_MOVW_GOTOFF_G2 304 /* GOT-rel. o. MOV{N,Z} imm. 47:32. */ +#define R_AARCH64_MOVW_GOTOFF_G2_NC 305 /* Likewise for MOVK; no check. */ +#define R_AARCH64_MOVW_GOTOFF_G3 306 /* GOT-rel. o. MOV{N,Z} imm. 63:48. */ +#define R_AARCH64_GOTREL64 307 /* GOT-relative 64-bit. */ +#define R_AARCH64_GOTREL32 308 /* GOT-relative 32-bit. */ +#define R_AARCH64_GOT_LD_PREL19 309 /* PC-rel. GOT off. load imm. 20:2. */ +#define R_AARCH64_LD64_GOTOFF_LO15 310 /* GOT-rel. off. LD/ST imm. 14:3. */ +#define R_AARCH64_ADR_GOT_PAGE 311 /* P-page-rel. GOT off. ADRP 32:12. */ +#define R_AARCH64_LD64_GOT_LO12_NC 312 /* Dir. GOT off. LD/ST imm. 11:3. */ +#define R_AARCH64_LD64_GOTPAGE_LO15 313 /* GOT-page-rel. GOT off. LD/ST 14:3 \ + */ +#define R_AARCH64_TLSGD_ADR_PREL21 512 /* PC-relative ADR imm. 20:0. */ +#define R_AARCH64_TLSGD_ADR_PAGE21 513 /* page-rel. ADRP imm. 32:12. */ +#define R_AARCH64_TLSGD_ADD_LO12_NC 514 /* direct ADD imm. from 11:0. */ +#define R_AARCH64_TLSGD_MOVW_G1 515 /* GOT-rel. MOV{N,Z} 31:16. */ +#define R_AARCH64_TLSGD_MOVW_G0_NC 516 /* GOT-rel. MOVK imm. 15:0. */ +#define R_AARCH64_TLSLD_ADR_PREL21 517 /* Like 512; local dynamic model. */ +#define R_AARCH64_TLSLD_ADR_PAGE21 518 /* Like 513; local dynamic model. */ +#define R_AARCH64_TLSLD_ADD_LO12_NC 519 /* Like 514; local dynamic model. */ +#define R_AARCH64_TLSLD_MOVW_G1 520 /* Like 515; local dynamic model. */ +#define R_AARCH64_TLSLD_MOVW_G0_NC 521 /* Like 516; local dynamic model. */ +#define R_AARCH64_TLSLD_LD_PREL19 522 /* TLS PC-rel. load imm. 20:2. */ +#define R_AARCH64_TLSLD_MOVW_DTPREL_G2 523 /* TLS DTP-rel. MOV{N,Z} 47:32. */ +#define R_AARCH64_TLSLD_MOVW_DTPREL_G1 524 /* TLS DTP-rel. MOV{N,Z} 31:16. */ +#define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525 /* Likewise; MOVK; no check. */ +#define R_AARCH64_TLSLD_MOVW_DTPREL_G0 526 /* TLS DTP-rel. MOV{N,Z} 15:0. */ +#define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527 /* Likewise; MOVK; no check. */ +#define R_AARCH64_TLSLD_ADD_DTPREL_HI12 528 /* DTP-rel. ADD imm. from 23:12. \ + */ +#define R_AARCH64_TLSLD_ADD_DTPREL_LO12 529 /* DTP-rel. ADD imm. from 11:0. */ +#define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC 530 /* Likewise; no ovfl. check. */ +#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531 /* DTP-rel. LD/ST imm. 11:0. */ +#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC 532 /* Likewise; no check. */ +#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12 533 /* DTP-rel. LD/ST imm. 11:1. */ +#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534 /* Likewise; no check. */ +#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12 535 /* DTP-rel. LD/ST imm. 11:2. */ +#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536 /* Likewise; no check. */ +#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12 537 /* DTP-rel. LD/ST imm. 11:3. */ +#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC 538 /* Likewise; no check. */ +#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 539 /* GOT-rel. MOV{N,Z} 31:16. */ +#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC 540 /* GOT-rel. MOVK 15:0. */ +#define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 541 /* Page-rel. ADRP 32:12. */ +#define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC 542 /* Direct LD off. 11:3. */ +#define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 543 /* PC-rel. load imm. 20:2. */ +#define R_AARCH64_TLSLE_MOVW_TPREL_G2 544 /* TLS TP-rel. MOV{N,Z} 47:32. */ +#define R_AARCH64_TLSLE_MOVW_TPREL_G1 545 /* TLS TP-rel. MOV{N,Z} 31:16. */ +#define R_AARCH64_TLSLE_MOVW_TPREL_G1_NC 546 /* Likewise; MOVK; no check. */ +#define R_AARCH64_TLSLE_MOVW_TPREL_G0 547 /* TLS TP-rel. MOV{N,Z} 15:0. */ +#define R_AARCH64_TLSLE_MOVW_TPREL_G0_NC 548 /* Likewise; MOVK; no check. */ +#define R_AARCH64_TLSLE_ADD_TPREL_HI12 549 /* TP-rel. ADD imm. 23:12. */ +#define R_AARCH64_TLSLE_ADD_TPREL_LO12 550 /* TP-rel. ADD imm. 11:0. */ +#define R_AARCH64_TLSLE_ADD_TPREL_LO12_NC 551 /* Likewise; no ovfl. check. */ +#define R_AARCH64_TLSLE_LDST8_TPREL_LO12 552 /* TP-rel. LD/ST off. 11:0. */ +#define R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC 553 /* Likewise; no ovfl. check. \ + */ +#define R_AARCH64_TLSLE_LDST16_TPREL_LO12 554 /* TP-rel. LD/ST off. 11:1. */ +#define R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC 555 /* Likewise; no check. */ +#define R_AARCH64_TLSLE_LDST32_TPREL_LO12 556 /* TP-rel. LD/ST off. 11:2. */ +#define R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC 557 /* Likewise; no check. */ +#define R_AARCH64_TLSLE_LDST64_TPREL_LO12 558 /* TP-rel. LD/ST off. 11:3. */ +#define R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC 559 /* Likewise; no check. */ +#define R_AARCH64_TLSDESC_LD_PREL19 560 /* PC-rel. load immediate 20:2. */ +#define R_AARCH64_TLSDESC_ADR_PREL21 561 /* PC-rel. ADR immediate 20:0. */ +#define R_AARCH64_TLSDESC_ADR_PAGE21 562 /* Page-rel. ADRP imm. 32:12. */ +#define R_AARCH64_TLSDESC_LD64_LO12 563 /* Direct LD off. from 11:3. */ +#define R_AARCH64_TLSDESC_ADD_LO12 564 /* Direct ADD imm. from 11:0. */ +#define R_AARCH64_TLSDESC_OFF_G1 565 /* GOT-rel. MOV{N,Z} imm. 31:16. */ +#define R_AARCH64_TLSDESC_OFF_G0_NC 566 /* GOT-rel. MOVK imm. 15:0; no ck. */ +#define R_AARCH64_TLSDESC_LDR 567 /* Relax LDR. */ +#define R_AARCH64_TLSDESC_ADD 568 /* Relax ADD. */ +#define R_AARCH64_TLSDESC_CALL 569 /* Relax BLR. */ +#define R_AARCH64_TLSLE_LDST128_TPREL_LO12 570 /* TP-rel. LD/ST off. 11:4. */ +#define R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC 571 /* Likewise; no check. */ +#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12 572 /* DTP-rel. LD/ST imm. 11:4. \ + */ +#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC 573 /* Likewise; no check. */ +#define R_AARCH64_COPY 1024 /* Copy symbol at runtime. */ +#define R_AARCH64_GLOB_DAT 1025 /* Create GOT entry. */ +#define R_AARCH64_JUMP_SLOT 1026 /* Create PLT entry. */ +#define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */ +#define R_AARCH64_TLS_DTPMOD64 1028 /* Module number, 64 bit. */ +#define R_AARCH64_TLS_DTPREL64 1029 /* Module-relative offset, 64 bit. */ +#define R_AARCH64_TLS_TPREL64 1030 /* TP-relative offset, 64 bit. */ +#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */ +#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */ /* Keep this the last entry. */ -#define R_AARCH64_NUM 1033 +#define R_AARCH64_NUM 1033 /* ARM relocs. */ -#define R_ARM_NONE 0 /* No reloc */ -#define R_ARM_PC24 1 /* PC relative 26 bit branch */ -#define R_ARM_ABS32 2 /* Direct 32 bit */ -#define R_ARM_REL32 3 /* PC relative 32 bit */ -#define R_ARM_PC13 4 -#define R_ARM_ABS16 5 /* Direct 16 bit */ -#define R_ARM_ABS12 6 /* Direct 12 bit */ -#define R_ARM_THM_ABS5 7 -#define R_ARM_ABS8 8 /* Direct 8 bit */ -#define R_ARM_SBREL32 9 -#define R_ARM_THM_PC22 10 -#define R_ARM_THM_PC8 11 -#define R_ARM_AMP_VCALL9 12 -#define R_ARM_SWI24 13 /* Obsolete static relocation. */ -#define R_ARM_TLS_DESC 13 /* Dynamic relocation. */ -#define R_ARM_THM_SWI8 14 -#define R_ARM_XPC25 15 -#define R_ARM_THM_XPC22 16 -#define R_ARM_TLS_DTPMOD32 17 /* ID of module containing symbol */ -#define R_ARM_TLS_DTPOFF32 18 /* Offset in TLS block */ -#define R_ARM_TLS_TPOFF32 19 /* Offset in static TLS block */ -#define R_ARM_COPY 20 /* Copy symbol at runtime */ -#define R_ARM_GLOB_DAT 21 /* Create GOT entry */ -#define R_ARM_JUMP_SLOT 22 /* Create PLT entry */ -#define R_ARM_RELATIVE 23 /* Adjust by program base */ -#define R_ARM_GOTOFF 24 /* 32 bit offset to GOT */ -#define R_ARM_GOTPC 25 /* 32 bit PC relative offset to GOT */ -#define R_ARM_GOT32 26 /* 32 bit GOT entry */ -#define R_ARM_PLT32 27 /* 32 bit PLT address */ -#define R_ARM_CALL 28 -#define R_ARM_JUMP24 29 -#define R_ARM_THM_JUMP24 30 -#define R_ARM_BASE_ABS 31 /* Adjust by program base. */ -#define R_ARM_ALU_PCREL_7_0 32 -#define R_ARM_ALU_PCREL_15_8 33 -#define R_ARM_ALU_PCREL_23_15 34 -#define R_ARM_LDR_SBREL_11_0 35 -#define R_ARM_ALU_SBREL_19_12 36 -#define R_ARM_ALU_SBREL_27_20 37 +#define R_ARM_NONE 0 /* No reloc */ +#define R_ARM_PC24 1 /* PC relative 26 bit branch */ +#define R_ARM_ABS32 2 /* Direct 32 bit */ +#define R_ARM_REL32 3 /* PC relative 32 bit */ +#define R_ARM_PC13 4 +#define R_ARM_ABS16 5 /* Direct 16 bit */ +#define R_ARM_ABS12 6 /* Direct 12 bit */ +#define R_ARM_THM_ABS5 7 +#define R_ARM_ABS8 8 /* Direct 8 bit */ +#define R_ARM_SBREL32 9 +#define R_ARM_THM_PC22 10 +#define R_ARM_THM_PC8 11 +#define R_ARM_AMP_VCALL9 12 +#define R_ARM_SWI24 13 /* Obsolete static relocation. */ +#define R_ARM_TLS_DESC 13 /* Dynamic relocation. */ +#define R_ARM_THM_SWI8 14 +#define R_ARM_XPC25 15 +#define R_ARM_THM_XPC22 16 +#define R_ARM_TLS_DTPMOD32 17 /* ID of module containing symbol */ +#define R_ARM_TLS_DTPOFF32 18 /* Offset in TLS block */ +#define R_ARM_TLS_TPOFF32 19 /* Offset in static TLS block */ +#define R_ARM_COPY 20 /* Copy symbol at runtime */ +#define R_ARM_GLOB_DAT 21 /* Create GOT entry */ +#define R_ARM_JUMP_SLOT 22 /* Create PLT entry */ +#define R_ARM_RELATIVE 23 /* Adjust by program base */ +#define R_ARM_GOTOFF 24 /* 32 bit offset to GOT */ +#define R_ARM_GOTPC 25 /* 32 bit PC relative offset to GOT */ +#define R_ARM_GOT32 26 /* 32 bit GOT entry */ +#define R_ARM_PLT32 27 /* 32 bit PLT address */ +#define R_ARM_CALL 28 +#define R_ARM_JUMP24 29 +#define R_ARM_THM_JUMP24 30 +#define R_ARM_BASE_ABS 31 /* Adjust by program base. */ +#define R_ARM_ALU_PCREL_7_0 32 +#define R_ARM_ALU_PCREL_15_8 33 +#define R_ARM_ALU_PCREL_23_15 34 +#define R_ARM_LDR_SBREL_11_0 35 +#define R_ARM_ALU_SBREL_19_12 36 +#define R_ARM_ALU_SBREL_27_20 37 #define R_ARM_TARGET1 38 -#define R_ARM_SBREL31 39 /* Program base relative. */ -#define R_ARM_V4BX 40 -#define R_ARM_TARGET2 41 -#define R_ARM_PREL31 42 -#define R_ARM_MOVW_ABS_NC 43 -#define R_ARM_MOVT_ABS 44 -#define R_ARM_MOVW_PREL_NC 45 /* PC relative 16-bit (MOVW). */ -#define R_ARM_MOVT_PREL 46 /* PC relative (MOVT). */ -#define R_ARM_THM_MOVW_ABS_NC 47 -#define R_ARM_THM_MOVT_ABS 48 +#define R_ARM_SBREL31 39 /* Program base relative. */ +#define R_ARM_V4BX 40 +#define R_ARM_TARGET2 41 +#define R_ARM_PREL31 42 +#define R_ARM_MOVW_ABS_NC 43 +#define R_ARM_MOVT_ABS 44 +#define R_ARM_MOVW_PREL_NC 45 /* PC relative 16-bit (MOVW). */ +#define R_ARM_MOVT_PREL 46 /* PC relative (MOVT). */ +#define R_ARM_THM_MOVW_ABS_NC 47 +#define R_ARM_THM_MOVT_ABS 48 /* Values from 49 to 89 are not yet used/handled by tcc. */ -#define R_ARM_TLS_GOTDESC 90 -#define R_ARM_TLS_CALL 91 -#define R_ARM_TLS_DESCSEQ 92 -#define R_ARM_THM_TLS_CALL 93 -#define R_ARM_GOT_PREL 96 -#define R_ARM_GNU_VTENTRY 100 -#define R_ARM_GNU_VTINHERIT 101 -#define R_ARM_THM_PC11 102 /* thumb unconditional branch */ -#define R_ARM_THM_PC9 103 /* thumb conditional branch */ -#define R_ARM_TLS_GD32 104 /* PC-rel 32 bit for global dynamic - thread local data */ -#define R_ARM_TLS_LDM32 105 /* PC-rel 32 bit for local dynamic - thread local data */ -#define R_ARM_TLS_LDO32 106 /* 32 bit offset relative to TLS - block */ -#define R_ARM_TLS_IE32 107 /* PC-rel 32 bit for GOT entry of - static TLS block offset */ -#define R_ARM_TLS_LE32 108 /* 32 bit offset relative to static - TLS block */ -#define R_ARM_THM_TLS_DESCSEQ 129 -#define R_ARM_IRELATIVE 160 -#define R_ARM_RXPC25 249 -#define R_ARM_RSBREL32 250 -#define R_ARM_THM_RPC22 251 -#define R_ARM_RREL32 252 -#define R_ARM_RABS22 253 -#define R_ARM_RPC24 254 -#define R_ARM_RBASE 255 +#define R_ARM_TLS_GOTDESC 90 +#define R_ARM_TLS_CALL 91 +#define R_ARM_TLS_DESCSEQ 92 +#define R_ARM_THM_TLS_CALL 93 +#define R_ARM_GOT_PREL 96 +#define R_ARM_GNU_VTENTRY 100 +#define R_ARM_GNU_VTINHERIT 101 +#define R_ARM_THM_PC11 102 /* thumb unconditional branch */ +#define R_ARM_THM_PC9 103 /* thumb conditional branch */ +#define R_ARM_TLS_GD32 \ + 104 /* PC-rel 32 bit for global dynamic \ + thread local data */ +#define R_ARM_TLS_LDM32 \ + 105 /* PC-rel 32 bit for local dynamic \ + thread local data */ +#define R_ARM_TLS_LDO32 \ + 106 /* 32 bit offset relative to TLS \ + block */ +#define R_ARM_TLS_IE32 \ + 107 /* PC-rel 32 bit for GOT entry of \ + static TLS block offset */ +#define R_ARM_TLS_LE32 \ + 108 /* 32 bit offset relative to static \ + TLS block */ +#define R_ARM_THM_TLS_DESCSEQ 129 +#define R_ARM_IRELATIVE 160 +#define R_ARM_RXPC25 249 +#define R_ARM_RSBREL32 250 +#define R_ARM_THM_RPC22 251 +#define R_ARM_RREL32 252 +#define R_ARM_RABS22 253 +#define R_ARM_RPC24 254 +#define R_ARM_RBASE 255 /* Keep this the last entry. */ -#define R_ARM_NUM 256 +#define R_ARM_NUM 256 /* TMS320C67xx specific declarations */ /* XXX: no ELF standard yet*/ /* TMS320C67xx relocs. */ -#define R_C60_32 1 -#define R_C60_GOT32 3 /* 32 bit GOT entry */ -#define R_C60_PLT32 4 /* 32 bit PLT address */ -#define R_C60_COPY 5 /* Copy symbol at runtime */ -#define R_C60_GLOB_DAT 6 /* Create GOT entry */ -#define R_C60_JMP_SLOT 7 /* Create PLT entry */ -#define R_C60_RELATIVE 8 /* Adjust by program base */ -#define R_C60_GOTOFF 9 /* 32 bit offset to GOT */ -#define R_C60_GOTPC 10 /* 32 bit PC relative offset to GOT */ +#define R_C60_32 1 +#define R_C60_GOT32 3 /* 32 bit GOT entry */ +#define R_C60_PLT32 4 /* 32 bit PLT address */ +#define R_C60_COPY 5 /* Copy symbol at runtime */ +#define R_C60_GLOB_DAT 6 /* Create GOT entry */ +#define R_C60_JMP_SLOT 7 /* Create PLT entry */ +#define R_C60_RELATIVE 8 /* Adjust by program base */ +#define R_C60_GOTOFF 9 /* 32 bit offset to GOT */ +#define R_C60_GOTPC 10 /* 32 bit PC relative offset to GOT */ -#define R_C60LO16 0x54 /* low 16 bit MVKL embedded */ -#define R_C60HI16 0x55 /* high 16 bit MVKH embedded */ +#define R_C60LO16 0x54 /* low 16 bit MVKL embedded */ +#define R_C60HI16 0x55 /* high 16 bit MVKH embedded */ /* Keep this the last entry. */ -#define R_C60_NUM 0x56 +#define R_C60_NUM 0x56 /* IA-64 specific declarations. */ /* Processor specific flags for the Ehdr e_flags field. */ -#define EF_IA_64_MASKOS 0x0000000f /* os-specific flags */ -#define EF_IA_64_ABI64 0x00000010 /* 64-bit ABI */ -#define EF_IA_64_ARCH 0xff000000 /* arch. version mask */ +#define EF_IA_64_MASKOS 0x0000000f /* os-specific flags */ +#define EF_IA_64_ABI64 0x00000010 /* 64-bit ABI */ +#define EF_IA_64_ARCH 0xff000000 /* arch. version mask */ /* Processor specific values for the Phdr p_type field. */ -#define PT_IA_64_ARCHEXT (PT_LOPROC + 0) /* arch extension bits */ -#define PT_IA_64_UNWIND (PT_LOPROC + 1) /* ia64 unwind bits */ -#define PT_IA_64_HP_OPT_ANOT (PT_LOOS + 0x12) -#define PT_IA_64_HP_HSL_ANOT (PT_LOOS + 0x13) -#define PT_IA_64_HP_STACK (PT_LOOS + 0x14) +#define PT_IA_64_ARCHEXT (PT_LOPROC + 0) /* arch extension bits */ +#define PT_IA_64_UNWIND (PT_LOPROC + 1) /* ia64 unwind bits */ +#define PT_IA_64_HP_OPT_ANOT (PT_LOOS + 0x12) +#define PT_IA_64_HP_HSL_ANOT (PT_LOOS + 0x13) +#define PT_IA_64_HP_STACK (PT_LOOS + 0x14) /* Processor specific flags for the Phdr p_flags field. */ -#define PF_IA_64_NORECOV 0x80000000 /* spec insns w/o recovery */ +#define PF_IA_64_NORECOV 0x80000000 /* spec insns w/o recovery */ /* Processor specific values for the Shdr sh_type field. */ -#define SHT_IA_64_EXT (SHT_LOPROC + 0) /* extension bits */ -#define SHT_IA_64_UNWIND (SHT_LOPROC + 1) /* unwind bits */ +#define SHT_IA_64_EXT (SHT_LOPROC + 0) /* extension bits */ +#define SHT_IA_64_UNWIND (SHT_LOPROC + 1) /* unwind bits */ /* Processor specific flags for the Shdr sh_flags field. */ -#define SHF_IA_64_SHORT 0x10000000 /* section near gp */ -#define SHF_IA_64_NORECOV 0x20000000 /* spec insns w/o recovery */ +#define SHF_IA_64_SHORT 0x10000000 /* section near gp */ +#define SHF_IA_64_NORECOV 0x20000000 /* spec insns w/o recovery */ /* Processor specific values for the Dyn d_tag field. */ -#define DT_IA_64_PLT_RESERVE (DT_LOPROC + 0) -#define DT_IA_64_NUM 1 +#define DT_IA_64_PLT_RESERVE (DT_LOPROC + 0) +#define DT_IA_64_NUM 1 /* IA-64 relocations. */ -#define R_IA64_NONE 0x00 /* none */ -#define R_IA64_IMM14 0x21 /* symbol + addend, add imm14 */ -#define R_IA64_IMM22 0x22 /* symbol + addend, add imm22 */ -#define R_IA64_IMM64 0x23 /* symbol + addend, mov imm64 */ -#define R_IA64_DIR32MSB 0x24 /* symbol + addend, data4 MSB */ -#define R_IA64_DIR32LSB 0x25 /* symbol + addend, data4 LSB */ -#define R_IA64_DIR64MSB 0x26 /* symbol + addend, data8 MSB */ -#define R_IA64_DIR64LSB 0x27 /* symbol + addend, data8 LSB */ -#define R_IA64_GPREL22 0x2a /* @gprel(sym + add), add imm22 */ -#define R_IA64_GPREL64I 0x2b /* @gprel(sym + add), mov imm64 */ -#define R_IA64_GPREL32MSB 0x2c /* @gprel(sym + add), data4 MSB */ -#define R_IA64_GPREL32LSB 0x2d /* @gprel(sym + add), data4 LSB */ -#define R_IA64_GPREL64MSB 0x2e /* @gprel(sym + add), data8 MSB */ -#define R_IA64_GPREL64LSB 0x2f /* @gprel(sym + add), data8 LSB */ -#define R_IA64_LTOFF22 0x32 /* @ltoff(sym + add), add imm22 */ -#define R_IA64_LTOFF64I 0x33 /* @ltoff(sym + add), mov imm64 */ -#define R_IA64_PLTOFF22 0x3a /* @pltoff(sym + add), add imm22 */ -#define R_IA64_PLTOFF64I 0x3b /* @pltoff(sym + add), mov imm64 */ -#define R_IA64_PLTOFF64MSB 0x3e /* @pltoff(sym + add), data8 MSB */ -#define R_IA64_PLTOFF64LSB 0x3f /* @pltoff(sym + add), data8 LSB */ -#define R_IA64_FPTR64I 0x43 /* @fptr(sym + add), mov imm64 */ -#define R_IA64_FPTR32MSB 0x44 /* @fptr(sym + add), data4 MSB */ -#define R_IA64_FPTR32LSB 0x45 /* @fptr(sym + add), data4 LSB */ -#define R_IA64_FPTR64MSB 0x46 /* @fptr(sym + add), data8 MSB */ -#define R_IA64_FPTR64LSB 0x47 /* @fptr(sym + add), data8 LSB */ -#define R_IA64_PCREL60B 0x48 /* @pcrel(sym + add), brl */ -#define R_IA64_PCREL21B 0x49 /* @pcrel(sym + add), ptb, call */ -#define R_IA64_PCREL21M 0x4a /* @pcrel(sym + add), chk.s */ -#define R_IA64_PCREL21F 0x4b /* @pcrel(sym + add), fchkf */ -#define R_IA64_PCREL32MSB 0x4c /* @pcrel(sym + add), data4 MSB */ -#define R_IA64_PCREL32LSB 0x4d /* @pcrel(sym + add), data4 LSB */ -#define R_IA64_PCREL64MSB 0x4e /* @pcrel(sym + add), data8 MSB */ -#define R_IA64_PCREL64LSB 0x4f /* @pcrel(sym + add), data8 LSB */ -#define R_IA64_LTOFF_FPTR22 0x52 /* @ltoff(@fptr(s+a)), imm22 */ -#define R_IA64_LTOFF_FPTR64I 0x53 /* @ltoff(@fptr(s+a)), imm64 */ -#define R_IA64_LTOFF_FPTR32MSB 0x54 /* @ltoff(@fptr(s+a)), data4 MSB */ -#define R_IA64_LTOFF_FPTR32LSB 0x55 /* @ltoff(@fptr(s+a)), data4 LSB */ -#define R_IA64_LTOFF_FPTR64MSB 0x56 /* @ltoff(@fptr(s+a)), data8 MSB */ -#define R_IA64_LTOFF_FPTR64LSB 0x57 /* @ltoff(@fptr(s+a)), data8 LSB */ -#define R_IA64_SEGREL32MSB 0x5c /* @segrel(sym + add), data4 MSB */ -#define R_IA64_SEGREL32LSB 0x5d /* @segrel(sym + add), data4 LSB */ -#define R_IA64_SEGREL64MSB 0x5e /* @segrel(sym + add), data8 MSB */ -#define R_IA64_SEGREL64LSB 0x5f /* @segrel(sym + add), data8 LSB */ -#define R_IA64_SECREL32MSB 0x64 /* @secrel(sym + add), data4 MSB */ -#define R_IA64_SECREL32LSB 0x65 /* @secrel(sym + add), data4 LSB */ -#define R_IA64_SECREL64MSB 0x66 /* @secrel(sym + add), data8 MSB */ -#define R_IA64_SECREL64LSB 0x67 /* @secrel(sym + add), data8 LSB */ -#define R_IA64_REL32MSB 0x6c /* data 4 + REL */ -#define R_IA64_REL32LSB 0x6d /* data 4 + REL */ -#define R_IA64_REL64MSB 0x6e /* data 8 + REL */ -#define R_IA64_REL64LSB 0x6f /* data 8 + REL */ -#define R_IA64_LTV32MSB 0x74 /* symbol + addend, data4 MSB */ -#define R_IA64_LTV32LSB 0x75 /* symbol + addend, data4 LSB */ -#define R_IA64_LTV64MSB 0x76 /* symbol + addend, data8 MSB */ -#define R_IA64_LTV64LSB 0x77 /* symbol + addend, data8 LSB */ -#define R_IA64_PCREL21BI 0x79 /* @pcrel(sym + add), 21bit inst */ -#define R_IA64_PCREL22 0x7a /* @pcrel(sym + add), 22bit inst */ -#define R_IA64_PCREL64I 0x7b /* @pcrel(sym + add), 64bit inst */ -#define R_IA64_IPLTMSB 0x80 /* dynamic reloc, imported PLT, MSB */ -#define R_IA64_IPLTLSB 0x81 /* dynamic reloc, imported PLT, LSB */ -#define R_IA64_COPY 0x84 /* copy relocation */ -#define R_IA64_SUB 0x85 /* Addend and symbol difference */ -#define R_IA64_LTOFF22X 0x86 /* LTOFF22, relaxable. */ -#define R_IA64_LDXMOV 0x87 /* Use of LTOFF22X. */ -#define R_IA64_TPREL14 0x91 /* @tprel(sym + add), imm14 */ -#define R_IA64_TPREL22 0x92 /* @tprel(sym + add), imm22 */ -#define R_IA64_TPREL64I 0x93 /* @tprel(sym + add), imm64 */ -#define R_IA64_TPREL64MSB 0x96 /* @tprel(sym + add), data8 MSB */ -#define R_IA64_TPREL64LSB 0x97 /* @tprel(sym + add), data8 LSB */ -#define R_IA64_LTOFF_TPREL22 0x9a /* @ltoff(@tprel(s+a)), imm2 */ -#define R_IA64_DTPMOD64MSB 0xa6 /* @dtpmod(sym + add), data8 MSB */ -#define R_IA64_DTPMOD64LSB 0xa7 /* @dtpmod(sym + add), data8 LSB */ -#define R_IA64_LTOFF_DTPMOD22 0xaa /* @ltoff(@dtpmod(sym + add)), imm22 */ -#define R_IA64_DTPREL14 0xb1 /* @dtprel(sym + add), imm14 */ -#define R_IA64_DTPREL22 0xb2 /* @dtprel(sym + add), imm22 */ -#define R_IA64_DTPREL64I 0xb3 /* @dtprel(sym + add), imm64 */ -#define R_IA64_DTPREL32MSB 0xb4 /* @dtprel(sym + add), data4 MSB */ -#define R_IA64_DTPREL32LSB 0xb5 /* @dtprel(sym + add), data4 LSB */ -#define R_IA64_DTPREL64MSB 0xb6 /* @dtprel(sym + add), data8 MSB */ -#define R_IA64_DTPREL64LSB 0xb7 /* @dtprel(sym + add), data8 LSB */ -#define R_IA64_LTOFF_DTPREL22 0xba /* @ltoff(@dtprel(s+a)), imm22 */ +#define R_IA64_NONE 0x00 /* none */ +#define R_IA64_IMM14 0x21 /* symbol + addend, add imm14 */ +#define R_IA64_IMM22 0x22 /* symbol + addend, add imm22 */ +#define R_IA64_IMM64 0x23 /* symbol + addend, mov imm64 */ +#define R_IA64_DIR32MSB 0x24 /* symbol + addend, data4 MSB */ +#define R_IA64_DIR32LSB 0x25 /* symbol + addend, data4 LSB */ +#define R_IA64_DIR64MSB 0x26 /* symbol + addend, data8 MSB */ +#define R_IA64_DIR64LSB 0x27 /* symbol + addend, data8 LSB */ +#define R_IA64_GPREL22 0x2a /* @gprel(sym + add), add imm22 */ +#define R_IA64_GPREL64I 0x2b /* @gprel(sym + add), mov imm64 */ +#define R_IA64_GPREL32MSB 0x2c /* @gprel(sym + add), data4 MSB */ +#define R_IA64_GPREL32LSB 0x2d /* @gprel(sym + add), data4 LSB */ +#define R_IA64_GPREL64MSB 0x2e /* @gprel(sym + add), data8 MSB */ +#define R_IA64_GPREL64LSB 0x2f /* @gprel(sym + add), data8 LSB */ +#define R_IA64_LTOFF22 0x32 /* @ltoff(sym + add), add imm22 */ +#define R_IA64_LTOFF64I 0x33 /* @ltoff(sym + add), mov imm64 */ +#define R_IA64_PLTOFF22 0x3a /* @pltoff(sym + add), add imm22 */ +#define R_IA64_PLTOFF64I 0x3b /* @pltoff(sym + add), mov imm64 */ +#define R_IA64_PLTOFF64MSB 0x3e /* @pltoff(sym + add), data8 MSB */ +#define R_IA64_PLTOFF64LSB 0x3f /* @pltoff(sym + add), data8 LSB */ +#define R_IA64_FPTR64I 0x43 /* @fptr(sym + add), mov imm64 */ +#define R_IA64_FPTR32MSB 0x44 /* @fptr(sym + add), data4 MSB */ +#define R_IA64_FPTR32LSB 0x45 /* @fptr(sym + add), data4 LSB */ +#define R_IA64_FPTR64MSB 0x46 /* @fptr(sym + add), data8 MSB */ +#define R_IA64_FPTR64LSB 0x47 /* @fptr(sym + add), data8 LSB */ +#define R_IA64_PCREL60B 0x48 /* @pcrel(sym + add), brl */ +#define R_IA64_PCREL21B 0x49 /* @pcrel(sym + add), ptb, call */ +#define R_IA64_PCREL21M 0x4a /* @pcrel(sym + add), chk.s */ +#define R_IA64_PCREL21F 0x4b /* @pcrel(sym + add), fchkf */ +#define R_IA64_PCREL32MSB 0x4c /* @pcrel(sym + add), data4 MSB */ +#define R_IA64_PCREL32LSB 0x4d /* @pcrel(sym + add), data4 LSB */ +#define R_IA64_PCREL64MSB 0x4e /* @pcrel(sym + add), data8 MSB */ +#define R_IA64_PCREL64LSB 0x4f /* @pcrel(sym + add), data8 LSB */ +#define R_IA64_LTOFF_FPTR22 0x52 /* @ltoff(@fptr(s+a)), imm22 */ +#define R_IA64_LTOFF_FPTR64I 0x53 /* @ltoff(@fptr(s+a)), imm64 */ +#define R_IA64_LTOFF_FPTR32MSB 0x54 /* @ltoff(@fptr(s+a)), data4 MSB */ +#define R_IA64_LTOFF_FPTR32LSB 0x55 /* @ltoff(@fptr(s+a)), data4 LSB */ +#define R_IA64_LTOFF_FPTR64MSB 0x56 /* @ltoff(@fptr(s+a)), data8 MSB */ +#define R_IA64_LTOFF_FPTR64LSB 0x57 /* @ltoff(@fptr(s+a)), data8 LSB */ +#define R_IA64_SEGREL32MSB 0x5c /* @segrel(sym + add), data4 MSB */ +#define R_IA64_SEGREL32LSB 0x5d /* @segrel(sym + add), data4 LSB */ +#define R_IA64_SEGREL64MSB 0x5e /* @segrel(sym + add), data8 MSB */ +#define R_IA64_SEGREL64LSB 0x5f /* @segrel(sym + add), data8 LSB */ +#define R_IA64_SECREL32MSB 0x64 /* @secrel(sym + add), data4 MSB */ +#define R_IA64_SECREL32LSB 0x65 /* @secrel(sym + add), data4 LSB */ +#define R_IA64_SECREL64MSB 0x66 /* @secrel(sym + add), data8 MSB */ +#define R_IA64_SECREL64LSB 0x67 /* @secrel(sym + add), data8 LSB */ +#define R_IA64_REL32MSB 0x6c /* data 4 + REL */ +#define R_IA64_REL32LSB 0x6d /* data 4 + REL */ +#define R_IA64_REL64MSB 0x6e /* data 8 + REL */ +#define R_IA64_REL64LSB 0x6f /* data 8 + REL */ +#define R_IA64_LTV32MSB 0x74 /* symbol + addend, data4 MSB */ +#define R_IA64_LTV32LSB 0x75 /* symbol + addend, data4 LSB */ +#define R_IA64_LTV64MSB 0x76 /* symbol + addend, data8 MSB */ +#define R_IA64_LTV64LSB 0x77 /* symbol + addend, data8 LSB */ +#define R_IA64_PCREL21BI 0x79 /* @pcrel(sym + add), 21bit inst */ +#define R_IA64_PCREL22 0x7a /* @pcrel(sym + add), 22bit inst */ +#define R_IA64_PCREL64I 0x7b /* @pcrel(sym + add), 64bit inst */ +#define R_IA64_IPLTMSB 0x80 /* dynamic reloc, imported PLT, MSB */ +#define R_IA64_IPLTLSB 0x81 /* dynamic reloc, imported PLT, LSB */ +#define R_IA64_COPY 0x84 /* copy relocation */ +#define R_IA64_SUB 0x85 /* Addend and symbol difference */ +#define R_IA64_LTOFF22X 0x86 /* LTOFF22, relaxable. */ +#define R_IA64_LDXMOV 0x87 /* Use of LTOFF22X. */ +#define R_IA64_TPREL14 0x91 /* @tprel(sym + add), imm14 */ +#define R_IA64_TPREL22 0x92 /* @tprel(sym + add), imm22 */ +#define R_IA64_TPREL64I 0x93 /* @tprel(sym + add), imm64 */ +#define R_IA64_TPREL64MSB 0x96 /* @tprel(sym + add), data8 MSB */ +#define R_IA64_TPREL64LSB 0x97 /* @tprel(sym + add), data8 LSB */ +#define R_IA64_LTOFF_TPREL22 0x9a /* @ltoff(@tprel(s+a)), imm2 */ +#define R_IA64_DTPMOD64MSB 0xa6 /* @dtpmod(sym + add), data8 MSB */ +#define R_IA64_DTPMOD64LSB 0xa7 /* @dtpmod(sym + add), data8 LSB */ +#define R_IA64_LTOFF_DTPMOD22 0xaa /* @ltoff(@dtpmod(sym + add)), imm22 */ +#define R_IA64_DTPREL14 0xb1 /* @dtprel(sym + add), imm14 */ +#define R_IA64_DTPREL22 0xb2 /* @dtprel(sym + add), imm22 */ +#define R_IA64_DTPREL64I 0xb3 /* @dtprel(sym + add), imm64 */ +#define R_IA64_DTPREL32MSB 0xb4 /* @dtprel(sym + add), data4 MSB */ +#define R_IA64_DTPREL32LSB 0xb5 /* @dtprel(sym + add), data4 LSB */ +#define R_IA64_DTPREL64MSB 0xb6 /* @dtprel(sym + add), data8 MSB */ +#define R_IA64_DTPREL64LSB 0xb7 /* @dtprel(sym + add), data8 LSB */ +#define R_IA64_LTOFF_DTPREL22 0xba /* @ltoff(@dtprel(s+a)), imm22 */ /* SH specific declarations */ /* Processor specific flags for the ELF header e_flags field. */ -#define EF_SH_MACH_MASK 0x1f -#define EF_SH_UNKNOWN 0x0 -#define EF_SH1 0x1 -#define EF_SH2 0x2 -#define EF_SH3 0x3 -#define EF_SH_DSP 0x4 -#define EF_SH3_DSP 0x5 -#define EF_SH4AL_DSP 0x6 -#define EF_SH3E 0x8 -#define EF_SH4 0x9 -#define EF_SH2E 0xb -#define EF_SH4A 0xc -#define EF_SH2A 0xd -#define EF_SH4_NOFPU 0x10 -#define EF_SH4A_NOFPU 0x11 -#define EF_SH4_NOMMU_NOFPU 0x12 -#define EF_SH2A_NOFPU 0x13 -#define EF_SH3_NOMMU 0x14 -#define EF_SH2A_SH4_NOFPU 0x15 -#define EF_SH2A_SH3_NOFPU 0x16 -#define EF_SH2A_SH4 0x17 -#define EF_SH2A_SH3E 0x18 +#define EF_SH_MACH_MASK 0x1f +#define EF_SH_UNKNOWN 0x0 +#define EF_SH1 0x1 +#define EF_SH2 0x2 +#define EF_SH3 0x3 +#define EF_SH_DSP 0x4 +#define EF_SH3_DSP 0x5 +#define EF_SH4AL_DSP 0x6 +#define EF_SH3E 0x8 +#define EF_SH4 0x9 +#define EF_SH2E 0xb +#define EF_SH4A 0xc +#define EF_SH2A 0xd +#define EF_SH4_NOFPU 0x10 +#define EF_SH4A_NOFPU 0x11 +#define EF_SH4_NOMMU_NOFPU 0x12 +#define EF_SH2A_NOFPU 0x13 +#define EF_SH3_NOMMU 0x14 +#define EF_SH2A_SH4_NOFPU 0x15 +#define EF_SH2A_SH3_NOFPU 0x16 +#define EF_SH2A_SH4 0x17 +#define EF_SH2A_SH3E 0x18 /* SH relocs. */ -#define R_SH_NONE 0 -#define R_SH_DIR32 1 -#define R_SH_REL32 2 -#define R_SH_DIR8WPN 3 -#define R_SH_IND12W 4 -#define R_SH_DIR8WPL 5 -#define R_SH_DIR8WPZ 6 -#define R_SH_DIR8BP 7 -#define R_SH_DIR8W 8 -#define R_SH_DIR8L 9 -#define R_SH_SWITCH16 25 -#define R_SH_SWITCH32 26 -#define R_SH_USES 27 -#define R_SH_COUNT 28 -#define R_SH_ALIGN 29 -#define R_SH_CODE 30 -#define R_SH_DATA 31 -#define R_SH_LABEL 32 -#define R_SH_SWITCH8 33 -#define R_SH_GNU_VTINHERIT 34 -#define R_SH_GNU_VTENTRY 35 -#define R_SH_TLS_GD_32 144 -#define R_SH_TLS_LD_32 145 -#define R_SH_TLS_LDO_32 146 -#define R_SH_TLS_IE_32 147 -#define R_SH_TLS_LE_32 148 -#define R_SH_TLS_DTPMOD32 149 -#define R_SH_TLS_DTPOFF32 150 -#define R_SH_TLS_TPOFF32 151 -#define R_SH_GOT32 160 -#define R_SH_PLT32 161 -#define R_SH_COPY 162 -#define R_SH_GLOB_DAT 163 -#define R_SH_JMP_SLOT 164 -#define R_SH_RELATIVE 165 -#define R_SH_GOTOFF 166 -#define R_SH_GOTPC 167 +#define R_SH_NONE 0 +#define R_SH_DIR32 1 +#define R_SH_REL32 2 +#define R_SH_DIR8WPN 3 +#define R_SH_IND12W 4 +#define R_SH_DIR8WPL 5 +#define R_SH_DIR8WPZ 6 +#define R_SH_DIR8BP 7 +#define R_SH_DIR8W 8 +#define R_SH_DIR8L 9 +#define R_SH_SWITCH16 25 +#define R_SH_SWITCH32 26 +#define R_SH_USES 27 +#define R_SH_COUNT 28 +#define R_SH_ALIGN 29 +#define R_SH_CODE 30 +#define R_SH_DATA 31 +#define R_SH_LABEL 32 +#define R_SH_SWITCH8 33 +#define R_SH_GNU_VTINHERIT 34 +#define R_SH_GNU_VTENTRY 35 +#define R_SH_TLS_GD_32 144 +#define R_SH_TLS_LD_32 145 +#define R_SH_TLS_LDO_32 146 +#define R_SH_TLS_IE_32 147 +#define R_SH_TLS_LE_32 148 +#define R_SH_TLS_DTPMOD32 149 +#define R_SH_TLS_DTPOFF32 150 +#define R_SH_TLS_TPOFF32 151 +#define R_SH_GOT32 160 +#define R_SH_PLT32 161 +#define R_SH_COPY 162 +#define R_SH_GLOB_DAT 163 +#define R_SH_JMP_SLOT 164 +#define R_SH_RELATIVE 165 +#define R_SH_GOTOFF 166 +#define R_SH_GOTPC 167 /* Keep this the last entry. */ -#define R_SH_NUM 256 +#define R_SH_NUM 256 /* S/390 specific definitions. */ /* Valid values for the e_flags field. */ -#define EF_S390_HIGH_GPRS 0x00000001 /* High GPRs kernel facility needed. */ +#define EF_S390_HIGH_GPRS 0x00000001 /* High GPRs kernel facility needed. */ /* Additional s390 relocs */ -#define R_390_NONE 0 /* No reloc. */ -#define R_390_8 1 /* Direct 8 bit. */ -#define R_390_12 2 /* Direct 12 bit. */ -#define R_390_16 3 /* Direct 16 bit. */ -#define R_390_32 4 /* Direct 32 bit. */ -#define R_390_PC32 5 /* PC relative 32 bit. */ -#define R_390_GOT12 6 /* 12 bit GOT offset. */ -#define R_390_GOT32 7 /* 32 bit GOT offset. */ -#define R_390_PLT32 8 /* 32 bit PC relative PLT address. */ -#define R_390_COPY 9 /* Copy symbol at runtime. */ -#define R_390_GLOB_DAT 10 /* Create GOT entry. */ -#define R_390_JMP_SLOT 11 /* Create PLT entry. */ -#define R_390_RELATIVE 12 /* Adjust by program base. */ -#define R_390_GOTOFF32 13 /* 32 bit offset to GOT. */ -#define R_390_GOTPC 14 /* 32 bit PC relative offset to GOT. */ -#define R_390_GOT16 15 /* 16 bit GOT offset. */ -#define R_390_PC16 16 /* PC relative 16 bit. */ -#define R_390_PC16DBL 17 /* PC relative 16 bit shifted by 1. */ -#define R_390_PLT16DBL 18 /* 16 bit PC rel. PLT shifted by 1. */ -#define R_390_PC32DBL 19 /* PC relative 32 bit shifted by 1. */ -#define R_390_PLT32DBL 20 /* 32 bit PC rel. PLT shifted by 1. */ -#define R_390_GOTPCDBL 21 /* 32 bit PC rel. GOT shifted by 1. */ -#define R_390_64 22 /* Direct 64 bit. */ -#define R_390_PC64 23 /* PC relative 64 bit. */ -#define R_390_GOT64 24 /* 64 bit GOT offset. */ -#define R_390_PLT64 25 /* 64 bit PC relative PLT address. */ -#define R_390_GOTENT 26 /* 32 bit PC rel. to GOT entry >> 1. */ -#define R_390_GOTOFF16 27 /* 16 bit offset to GOT. */ -#define R_390_GOTOFF64 28 /* 64 bit offset to GOT. */ -#define R_390_GOTPLT12 29 /* 12 bit offset to jump slot. */ -#define R_390_GOTPLT16 30 /* 16 bit offset to jump slot. */ -#define R_390_GOTPLT32 31 /* 32 bit offset to jump slot. */ -#define R_390_GOTPLT64 32 /* 64 bit offset to jump slot. */ -#define R_390_GOTPLTENT 33 /* 32 bit rel. offset to jump slot. */ -#define R_390_PLTOFF16 34 /* 16 bit offset from GOT to PLT. */ -#define R_390_PLTOFF32 35 /* 32 bit offset from GOT to PLT. */ -#define R_390_PLTOFF64 36 /* 16 bit offset from GOT to PLT. */ -#define R_390_TLS_LOAD 37 /* Tag for load insn in TLS code. */ -#define R_390_TLS_GDCALL 38 /* Tag for function call in general - dynamic TLS code. */ -#define R_390_TLS_LDCALL 39 /* Tag for function call in local - dynamic TLS code. */ -#define R_390_TLS_GD32 40 /* Direct 32 bit for general dynamic - thread local data. */ -#define R_390_TLS_GD64 41 /* Direct 64 bit for general dynamic - thread local data. */ -#define R_390_TLS_GOTIE12 42 /* 12 bit GOT offset for static TLS - block offset. */ -#define R_390_TLS_GOTIE32 43 /* 32 bit GOT offset for static TLS - block offset. */ -#define R_390_TLS_GOTIE64 44 /* 64 bit GOT offset for static TLS - block offset. */ -#define R_390_TLS_LDM32 45 /* Direct 32 bit for local dynamic - thread local data in LE code. */ -#define R_390_TLS_LDM64 46 /* Direct 64 bit for local dynamic - thread local data in LE code. */ -#define R_390_TLS_IE32 47 /* 32 bit address of GOT entry for - negated static TLS block offset. */ -#define R_390_TLS_IE64 48 /* 64 bit address of GOT entry for - negated static TLS block offset. */ -#define R_390_TLS_IEENT 49 /* 32 bit rel. offset to GOT entry for - negated static TLS block offset. */ -#define R_390_TLS_LE32 50 /* 32 bit negated offset relative to - static TLS block. */ -#define R_390_TLS_LE64 51 /* 64 bit negated offset relative to - static TLS block. */ -#define R_390_TLS_LDO32 52 /* 32 bit offset relative to TLS - block. */ -#define R_390_TLS_LDO64 53 /* 64 bit offset relative to TLS - block. */ -#define R_390_TLS_DTPMOD 54 /* ID of module containing symbol. */ -#define R_390_TLS_DTPOFF 55 /* Offset in TLS block. */ -#define R_390_TLS_TPOFF 56 /* Negated offset in static TLS - block. */ -#define R_390_20 57 /* Direct 20 bit. */ -#define R_390_GOT20 58 /* 20 bit GOT offset. */ -#define R_390_GOTPLT20 59 /* 20 bit offset to jump slot. */ -#define R_390_TLS_GOTIE20 60 /* 20 bit GOT offset for static TLS - block offset. */ -#define R_390_IRELATIVE 61 /* STT_GNU_IFUNC relocation. */ +#define R_390_NONE 0 /* No reloc. */ +#define R_390_8 1 /* Direct 8 bit. */ +#define R_390_12 2 /* Direct 12 bit. */ +#define R_390_16 3 /* Direct 16 bit. */ +#define R_390_32 4 /* Direct 32 bit. */ +#define R_390_PC32 5 /* PC relative 32 bit. */ +#define R_390_GOT12 6 /* 12 bit GOT offset. */ +#define R_390_GOT32 7 /* 32 bit GOT offset. */ +#define R_390_PLT32 8 /* 32 bit PC relative PLT address. */ +#define R_390_COPY 9 /* Copy symbol at runtime. */ +#define R_390_GLOB_DAT 10 /* Create GOT entry. */ +#define R_390_JMP_SLOT 11 /* Create PLT entry. */ +#define R_390_RELATIVE 12 /* Adjust by program base. */ +#define R_390_GOTOFF32 13 /* 32 bit offset to GOT. */ +#define R_390_GOTPC 14 /* 32 bit PC relative offset to GOT. */ +#define R_390_GOT16 15 /* 16 bit GOT offset. */ +#define R_390_PC16 16 /* PC relative 16 bit. */ +#define R_390_PC16DBL 17 /* PC relative 16 bit shifted by 1. */ +#define R_390_PLT16DBL 18 /* 16 bit PC rel. PLT shifted by 1. */ +#define R_390_PC32DBL 19 /* PC relative 32 bit shifted by 1. */ +#define R_390_PLT32DBL 20 /* 32 bit PC rel. PLT shifted by 1. */ +#define R_390_GOTPCDBL 21 /* 32 bit PC rel. GOT shifted by 1. */ +#define R_390_64 22 /* Direct 64 bit. */ +#define R_390_PC64 23 /* PC relative 64 bit. */ +#define R_390_GOT64 24 /* 64 bit GOT offset. */ +#define R_390_PLT64 25 /* 64 bit PC relative PLT address. */ +#define R_390_GOTENT 26 /* 32 bit PC rel. to GOT entry >> 1. */ +#define R_390_GOTOFF16 27 /* 16 bit offset to GOT. */ +#define R_390_GOTOFF64 28 /* 64 bit offset to GOT. */ +#define R_390_GOTPLT12 29 /* 12 bit offset to jump slot. */ +#define R_390_GOTPLT16 30 /* 16 bit offset to jump slot. */ +#define R_390_GOTPLT32 31 /* 32 bit offset to jump slot. */ +#define R_390_GOTPLT64 32 /* 64 bit offset to jump slot. */ +#define R_390_GOTPLTENT 33 /* 32 bit rel. offset to jump slot. */ +#define R_390_PLTOFF16 34 /* 16 bit offset from GOT to PLT. */ +#define R_390_PLTOFF32 35 /* 32 bit offset from GOT to PLT. */ +#define R_390_PLTOFF64 36 /* 16 bit offset from GOT to PLT. */ +#define R_390_TLS_LOAD 37 /* Tag for load insn in TLS code. */ +#define R_390_TLS_GDCALL \ + 38 /* Tag for function call in general \ + dynamic TLS code. */ +#define R_390_TLS_LDCALL \ + 39 /* Tag for function call in local \ + dynamic TLS code. */ +#define R_390_TLS_GD32 \ + 40 /* Direct 32 bit for general dynamic \ + thread local data. */ +#define R_390_TLS_GD64 \ + 41 /* Direct 64 bit for general dynamic \ + thread local data. */ +#define R_390_TLS_GOTIE12 \ + 42 /* 12 bit GOT offset for static TLS \ + block offset. */ +#define R_390_TLS_GOTIE32 \ + 43 /* 32 bit GOT offset for static TLS \ + block offset. */ +#define R_390_TLS_GOTIE64 \ + 44 /* 64 bit GOT offset for static TLS \ + block offset. */ +#define R_390_TLS_LDM32 \ + 45 /* Direct 32 bit for local dynamic \ + thread local data in LE code. */ +#define R_390_TLS_LDM64 \ + 46 /* Direct 64 bit for local dynamic \ + thread local data in LE code. */ +#define R_390_TLS_IE32 \ + 47 /* 32 bit address of GOT entry for \ + negated static TLS block offset. */ +#define R_390_TLS_IE64 \ + 48 /* 64 bit address of GOT entry for \ + negated static TLS block offset. */ +#define R_390_TLS_IEENT \ + 49 /* 32 bit rel. offset to GOT entry for \ + negated static TLS block offset. */ +#define R_390_TLS_LE32 \ + 50 /* 32 bit negated offset relative to \ + static TLS block. */ +#define R_390_TLS_LE64 \ + 51 /* 64 bit negated offset relative to \ + static TLS block. */ +#define R_390_TLS_LDO32 \ + 52 /* 32 bit offset relative to TLS \ + block. */ +#define R_390_TLS_LDO64 \ + 53 /* 64 bit offset relative to TLS \ + block. */ +#define R_390_TLS_DTPMOD 54 /* ID of module containing symbol. */ +#define R_390_TLS_DTPOFF 55 /* Offset in TLS block. */ +#define R_390_TLS_TPOFF \ + 56 /* Negated offset in static TLS \ + block. */ +#define R_390_20 57 /* Direct 20 bit. */ +#define R_390_GOT20 58 /* 20 bit GOT offset. */ +#define R_390_GOTPLT20 59 /* 20 bit offset to jump slot. */ +#define R_390_TLS_GOTIE20 \ + 60 /* 20 bit GOT offset for static TLS \ + block offset. */ +#define R_390_IRELATIVE 61 /* STT_GNU_IFUNC relocation. */ /* Keep this the last entry. */ -#define R_390_NUM 62 - +#define R_390_NUM 62 /* CRIS relocations. */ -#define R_CRIS_NONE 0 -#define R_CRIS_8 1 -#define R_CRIS_16 2 -#define R_CRIS_32 3 -#define R_CRIS_8_PCREL 4 -#define R_CRIS_16_PCREL 5 -#define R_CRIS_32_PCREL 6 -#define R_CRIS_GNU_VTINHERIT 7 -#define R_CRIS_GNU_VTENTRY 8 -#define R_CRIS_COPY 9 -#define R_CRIS_GLOB_DAT 10 -#define R_CRIS_JUMP_SLOT 11 -#define R_CRIS_RELATIVE 12 -#define R_CRIS_16_GOT 13 -#define R_CRIS_32_GOT 14 -#define R_CRIS_16_GOTPLT 15 -#define R_CRIS_32_GOTPLT 16 -#define R_CRIS_32_GOTREL 17 -#define R_CRIS_32_PLT_GOTREL 18 -#define R_CRIS_32_PLT_PCREL 19 - -#define R_CRIS_NUM 20 +#define R_CRIS_NONE 0 +#define R_CRIS_8 1 +#define R_CRIS_16 2 +#define R_CRIS_32 3 +#define R_CRIS_8_PCREL 4 +#define R_CRIS_16_PCREL 5 +#define R_CRIS_32_PCREL 6 +#define R_CRIS_GNU_VTINHERIT 7 +#define R_CRIS_GNU_VTENTRY 8 +#define R_CRIS_COPY 9 +#define R_CRIS_GLOB_DAT 10 +#define R_CRIS_JUMP_SLOT 11 +#define R_CRIS_RELATIVE 12 +#define R_CRIS_16_GOT 13 +#define R_CRIS_32_GOT 14 +#define R_CRIS_16_GOTPLT 15 +#define R_CRIS_32_GOTPLT 16 +#define R_CRIS_32_GOTREL 17 +#define R_CRIS_32_PLT_GOTREL 18 +#define R_CRIS_32_PLT_PCREL 19 +#define R_CRIS_NUM 20 /* AMD x86-64 relocations. */ -#define R_X86_64_NONE 0 /* No reloc */ -#define R_X86_64_64 1 /* Direct 64 bit */ -#define R_X86_64_PC32 2 /* PC relative 32 bit signed */ -#define R_X86_64_GOT32 3 /* 32 bit GOT entry */ -#define R_X86_64_PLT32 4 /* 32 bit PLT address */ -#define R_X86_64_COPY 5 /* Copy symbol at runtime */ -#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */ -#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */ -#define R_X86_64_RELATIVE 8 /* Adjust by program base */ -#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative - offset to GOT */ -#define R_X86_64_32 10 /* Direct 32 bit zero extended */ -#define R_X86_64_32S 11 /* Direct 32 bit sign extended */ -#define R_X86_64_16 12 /* Direct 16 bit zero extended */ -#define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */ -#define R_X86_64_8 14 /* Direct 8 bit sign extended */ -#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */ -#define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */ -#define R_X86_64_DTPOFF64 17 /* Offset in module's TLS block */ -#define R_X86_64_TPOFF64 18 /* Offset in initial TLS block */ -#define R_X86_64_TLSGD 19 /* 32 bit signed PC relative offset - to two GOT entries for GD symbol */ -#define R_X86_64_TLSLD 20 /* 32 bit signed PC relative offset - to two GOT entries for LD symbol */ -#define R_X86_64_DTPOFF32 21 /* Offset in TLS block */ -#define R_X86_64_GOTTPOFF 22 /* 32 bit signed PC relative offset - to GOT entry for IE symbol */ -#define R_X86_64_TPOFF32 23 /* Offset in initial TLS block */ -#define R_X86_64_PC64 24 /* PC relative 64 bit */ -#define R_X86_64_GOTOFF64 25 /* 64 bit offset to GOT */ -#define R_X86_64_GOTPC32 26 /* 32 bit signed pc relative - offset to GOT */ -#define R_X86_64_GOT64 27 /* 64-bit GOT entry offset */ -#define R_X86_64_GOTPCREL64 28 /* 64-bit PC relative offset - to GOT entry */ -#define R_X86_64_GOTPC64 29 /* 64-bit PC relative offset to GOT */ -#define R_X86_64_GOTPLT64 30 /* like GOT64, says PLT entry needed */ -#define R_X86_64_PLTOFF64 31 /* 64-bit GOT relative offset - to PLT entry */ -#define R_X86_64_SIZE32 32 /* Size of symbol plus 32-bit addend */ -#define R_X86_64_SIZE64 33 /* Size of symbol plus 64-bit addend */ -#define R_X86_64_GOTPC32_TLSDESC 34 /* GOT offset for TLS descriptor. */ -#define R_X86_64_TLSDESC_CALL 35 /* Marker for call through TLS - descriptor. */ -#define R_X86_64_TLSDESC 36 /* TLS descriptor. */ -#define R_X86_64_IRELATIVE 37 /* Adjust indirectly by program base */ -#define R_X86_64_RELATIVE64 38 /* 64-bit adjust by program base */ -#define R_X86_64_GOTPCRELX 41 /* like GOTPCREL, but optionally with - linker optimizations */ -#define R_X86_64_REX_GOTPCRELX 42 /* like GOTPCRELX, but a REX prefix - is present */ +#define R_X86_64_NONE 0 /* No reloc */ +#define R_X86_64_64 1 /* Direct 64 bit */ +#define R_X86_64_PC32 2 /* PC relative 32 bit signed */ +#define R_X86_64_GOT32 3 /* 32 bit GOT entry */ +#define R_X86_64_PLT32 4 /* 32 bit PLT address */ +#define R_X86_64_COPY 5 /* Copy symbol at runtime */ +#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */ +#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */ +#define R_X86_64_RELATIVE 8 /* Adjust by program base */ +#define R_X86_64_GOTPCREL \ + 9 /* 32 bit signed PC relative \ + offset to GOT */ +#define R_X86_64_32 10 /* Direct 32 bit zero extended */ +#define R_X86_64_32S 11 /* Direct 32 bit sign extended */ +#define R_X86_64_16 12 /* Direct 16 bit zero extended */ +#define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */ +#define R_X86_64_8 14 /* Direct 8 bit sign extended */ +#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */ +#define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */ +#define R_X86_64_DTPOFF64 17 /* Offset in module's TLS block */ +#define R_X86_64_TPOFF64 18 /* Offset in initial TLS block */ +#define R_X86_64_TLSGD \ + 19 /* 32 bit signed PC relative offset \ + to two GOT entries for GD symbol */ +#define R_X86_64_TLSLD \ + 20 /* 32 bit signed PC relative offset \ + to two GOT entries for LD symbol */ +#define R_X86_64_DTPOFF32 21 /* Offset in TLS block */ +#define R_X86_64_GOTTPOFF \ + 22 /* 32 bit signed PC relative offset \ + to GOT entry for IE symbol */ +#define R_X86_64_TPOFF32 23 /* Offset in initial TLS block */ +#define R_X86_64_PC64 24 /* PC relative 64 bit */ +#define R_X86_64_GOTOFF64 25 /* 64 bit offset to GOT */ +#define R_X86_64_GOTPC32 \ + 26 /* 32 bit signed pc relative \ + offset to GOT */ +#define R_X86_64_GOT64 27 /* 64-bit GOT entry offset */ +#define R_X86_64_GOTPCREL64 \ + 28 /* 64-bit PC relative offset \ + to GOT entry */ +#define R_X86_64_GOTPC64 29 /* 64-bit PC relative offset to GOT */ +#define R_X86_64_GOTPLT64 30 /* like GOT64, says PLT entry needed */ +#define R_X86_64_PLTOFF64 \ + 31 /* 64-bit GOT relative offset \ + to PLT entry */ +#define R_X86_64_SIZE32 32 /* Size of symbol plus 32-bit addend */ +#define R_X86_64_SIZE64 33 /* Size of symbol plus 64-bit addend */ +#define R_X86_64_GOTPC32_TLSDESC 34 /* GOT offset for TLS descriptor. */ +#define R_X86_64_TLSDESC_CALL \ + 35 /* Marker for call through TLS \ + descriptor. */ +#define R_X86_64_TLSDESC 36 /* TLS descriptor. */ +#define R_X86_64_IRELATIVE 37 /* Adjust indirectly by program base */ +#define R_X86_64_RELATIVE64 38 /* 64-bit adjust by program base */ +#define R_X86_64_GOTPCRELX \ + 41 /* like GOTPCREL, but optionally with \ + linker optimizations */ +#define R_X86_64_REX_GOTPCRELX \ + 42 /* like GOTPCRELX, but a REX prefix \ + is present */ -#define R_X86_64_NUM 43 +#define R_X86_64_NUM 43 /* x86-64 sh_type values. */ -#define SHT_X86_64_UNWIND 0x70000001 /* Unwind information. */ +#define SHT_X86_64_UNWIND 0x70000001 /* Unwind information. */ /* AM33 relocations. */ -#define R_MN10300_NONE 0 /* No reloc. */ -#define R_MN10300_32 1 /* Direct 32 bit. */ -#define R_MN10300_16 2 /* Direct 16 bit. */ -#define R_MN10300_8 3 /* Direct 8 bit. */ -#define R_MN10300_PCREL32 4 /* PC-relative 32-bit. */ -#define R_MN10300_PCREL16 5 /* PC-relative 16-bit signed. */ -#define R_MN10300_PCREL8 6 /* PC-relative 8-bit signed. */ -#define R_MN10300_GNU_VTINHERIT 7 /* Ancient C++ vtable garbage... */ -#define R_MN10300_GNU_VTENTRY 8 /* ... collection annotation. */ -#define R_MN10300_24 9 /* Direct 24 bit. */ -#define R_MN10300_GOTPC32 10 /* 32-bit PCrel offset to GOT. */ -#define R_MN10300_GOTPC16 11 /* 16-bit PCrel offset to GOT. */ -#define R_MN10300_GOTOFF32 12 /* 32-bit offset from GOT. */ -#define R_MN10300_GOTOFF24 13 /* 24-bit offset from GOT. */ -#define R_MN10300_GOTOFF16 14 /* 16-bit offset from GOT. */ -#define R_MN10300_PLT32 15 /* 32-bit PCrel to PLT entry. */ -#define R_MN10300_PLT16 16 /* 16-bit PCrel to PLT entry. */ -#define R_MN10300_GOT32 17 /* 32-bit offset to GOT entry. */ -#define R_MN10300_GOT24 18 /* 24-bit offset to GOT entry. */ -#define R_MN10300_GOT16 19 /* 16-bit offset to GOT entry. */ -#define R_MN10300_COPY 20 /* Copy symbol at runtime. */ -#define R_MN10300_GLOB_DAT 21 /* Create GOT entry. */ -#define R_MN10300_JMP_SLOT 22 /* Create PLT entry. */ -#define R_MN10300_RELATIVE 23 /* Adjust by program base. */ -#define R_MN10300_TLS_GD 24 /* 32-bit offset for global dynamic. */ -#define R_MN10300_TLS_LD 25 /* 32-bit offset for local dynamic. */ -#define R_MN10300_TLS_LDO 26 /* Module-relative offset. */ -#define R_MN10300_TLS_GOTIE 27 /* GOT offset for static TLS block - offset. */ -#define R_MN10300_TLS_IE 28 /* GOT address for static TLS block - offset. */ -#define R_MN10300_TLS_LE 29 /* Offset relative to static TLS - block. */ -#define R_MN10300_TLS_DTPMOD 30 /* ID of module containing symbol. */ -#define R_MN10300_TLS_DTPOFF 31 /* Offset in module TLS block. */ -#define R_MN10300_TLS_TPOFF 32 /* Offset in static TLS block. */ -#define R_MN10300_SYM_DIFF 33 /* Adjustment for next reloc as needed - by linker relaxation. */ -#define R_MN10300_ALIGN 34 /* Alignment requirement for linker - relaxation. */ -#define R_MN10300_NUM 35 - +#define R_MN10300_NONE 0 /* No reloc. */ +#define R_MN10300_32 1 /* Direct 32 bit. */ +#define R_MN10300_16 2 /* Direct 16 bit. */ +#define R_MN10300_8 3 /* Direct 8 bit. */ +#define R_MN10300_PCREL32 4 /* PC-relative 32-bit. */ +#define R_MN10300_PCREL16 5 /* PC-relative 16-bit signed. */ +#define R_MN10300_PCREL8 6 /* PC-relative 8-bit signed. */ +#define R_MN10300_GNU_VTINHERIT 7 /* Ancient C++ vtable garbage... */ +#define R_MN10300_GNU_VTENTRY 8 /* ... collection annotation. */ +#define R_MN10300_24 9 /* Direct 24 bit. */ +#define R_MN10300_GOTPC32 10 /* 32-bit PCrel offset to GOT. */ +#define R_MN10300_GOTPC16 11 /* 16-bit PCrel offset to GOT. */ +#define R_MN10300_GOTOFF32 12 /* 32-bit offset from GOT. */ +#define R_MN10300_GOTOFF24 13 /* 24-bit offset from GOT. */ +#define R_MN10300_GOTOFF16 14 /* 16-bit offset from GOT. */ +#define R_MN10300_PLT32 15 /* 32-bit PCrel to PLT entry. */ +#define R_MN10300_PLT16 16 /* 16-bit PCrel to PLT entry. */ +#define R_MN10300_GOT32 17 /* 32-bit offset to GOT entry. */ +#define R_MN10300_GOT24 18 /* 24-bit offset to GOT entry. */ +#define R_MN10300_GOT16 19 /* 16-bit offset to GOT entry. */ +#define R_MN10300_COPY 20 /* Copy symbol at runtime. */ +#define R_MN10300_GLOB_DAT 21 /* Create GOT entry. */ +#define R_MN10300_JMP_SLOT 22 /* Create PLT entry. */ +#define R_MN10300_RELATIVE 23 /* Adjust by program base. */ +#define R_MN10300_TLS_GD 24 /* 32-bit offset for global dynamic. */ +#define R_MN10300_TLS_LD 25 /* 32-bit offset for local dynamic. */ +#define R_MN10300_TLS_LDO 26 /* Module-relative offset. */ +#define R_MN10300_TLS_GOTIE \ + 27 /* GOT offset for static TLS block \ + offset. */ +#define R_MN10300_TLS_IE \ + 28 /* GOT address for static TLS block \ + offset. */ +#define R_MN10300_TLS_LE \ + 29 /* Offset relative to static TLS \ + block. */ +#define R_MN10300_TLS_DTPMOD 30 /* ID of module containing symbol. */ +#define R_MN10300_TLS_DTPOFF 31 /* Offset in module TLS block. */ +#define R_MN10300_TLS_TPOFF 32 /* Offset in static TLS block. */ +#define R_MN10300_SYM_DIFF \ + 33 /* Adjustment for next reloc as needed \ + by linker relaxation. */ +#define R_MN10300_ALIGN \ + 34 /* Alignment requirement for linker \ + relaxation. */ +#define R_MN10300_NUM 35 /* M32R relocs. */ -#define R_M32R_NONE 0 /* No reloc. */ -#define R_M32R_16 1 /* Direct 16 bit. */ -#define R_M32R_32 2 /* Direct 32 bit. */ -#define R_M32R_24 3 /* Direct 24 bit. */ -#define R_M32R_10_PCREL 4 /* PC relative 10 bit shifted. */ -#define R_M32R_18_PCREL 5 /* PC relative 18 bit shifted. */ -#define R_M32R_26_PCREL 6 /* PC relative 26 bit shifted. */ -#define R_M32R_HI16_ULO 7 /* High 16 bit with unsigned low. */ -#define R_M32R_HI16_SLO 8 /* High 16 bit with signed low. */ -#define R_M32R_LO16 9 /* Low 16 bit. */ -#define R_M32R_SDA16 10 /* 16 bit offset in SDA. */ -#define R_M32R_GNU_VTINHERIT 11 -#define R_M32R_GNU_VTENTRY 12 +#define R_M32R_NONE 0 /* No reloc. */ +#define R_M32R_16 1 /* Direct 16 bit. */ +#define R_M32R_32 2 /* Direct 32 bit. */ +#define R_M32R_24 3 /* Direct 24 bit. */ +#define R_M32R_10_PCREL 4 /* PC relative 10 bit shifted. */ +#define R_M32R_18_PCREL 5 /* PC relative 18 bit shifted. */ +#define R_M32R_26_PCREL 6 /* PC relative 26 bit shifted. */ +#define R_M32R_HI16_ULO 7 /* High 16 bit with unsigned low. */ +#define R_M32R_HI16_SLO 8 /* High 16 bit with signed low. */ +#define R_M32R_LO16 9 /* Low 16 bit. */ +#define R_M32R_SDA16 10 /* 16 bit offset in SDA. */ +#define R_M32R_GNU_VTINHERIT 11 +#define R_M32R_GNU_VTENTRY 12 /* M32R relocs use SHT_RELA. */ -#define R_M32R_16_RELA 33 /* Direct 16 bit. */ -#define R_M32R_32_RELA 34 /* Direct 32 bit. */ -#define R_M32R_24_RELA 35 /* Direct 24 bit. */ -#define R_M32R_10_PCREL_RELA 36 /* PC relative 10 bit shifted. */ -#define R_M32R_18_PCREL_RELA 37 /* PC relative 18 bit shifted. */ -#define R_M32R_26_PCREL_RELA 38 /* PC relative 26 bit shifted. */ -#define R_M32R_HI16_ULO_RELA 39 /* High 16 bit with unsigned low */ -#define R_M32R_HI16_SLO_RELA 40 /* High 16 bit with signed low */ -#define R_M32R_LO16_RELA 41 /* Low 16 bit */ -#define R_M32R_SDA16_RELA 42 /* 16 bit offset in SDA */ -#define R_M32R_RELA_GNU_VTINHERIT 43 -#define R_M32R_RELA_GNU_VTENTRY 44 -#define R_M32R_REL32 45 /* PC relative 32 bit. */ - -#define R_M32R_GOT24 48 /* 24 bit GOT entry */ -#define R_M32R_26_PLTREL 49 /* 26 bit PC relative to PLT shifted */ -#define R_M32R_COPY 50 /* Copy symbol at runtime */ -#define R_M32R_GLOB_DAT 51 /* Create GOT entry */ -#define R_M32R_JMP_SLOT 52 /* Create PLT entry */ -#define R_M32R_RELATIVE 53 /* Adjust by program base */ -#define R_M32R_GOTOFF 54 /* 24 bit offset to GOT */ -#define R_M32R_GOTPC24 55 /* 24 bit PC relative offset to GOT */ -#define R_M32R_GOT16_HI_ULO 56 /* High 16 bit GOT entry with unsigned - low */ -#define R_M32R_GOT16_HI_SLO 57 /* High 16 bit GOT entry with signed - low */ -#define R_M32R_GOT16_LO 58 /* Low 16 bit GOT entry */ -#define R_M32R_GOTPC_HI_ULO 59 /* High 16 bit PC relative offset to - GOT with unsigned low */ -#define R_M32R_GOTPC_HI_SLO 60 /* High 16 bit PC relative offset to - GOT with signed low */ -#define R_M32R_GOTPC_LO 61 /* Low 16 bit PC relative offset to - GOT */ -#define R_M32R_GOTOFF_HI_ULO 62 /* High 16 bit offset to GOT - with unsigned low */ -#define R_M32R_GOTOFF_HI_SLO 63 /* High 16 bit offset to GOT - with signed low */ -#define R_M32R_GOTOFF_LO 64 /* Low 16 bit offset to GOT */ -#define R_M32R_NUM 256 /* Keep this the last entry. */ +#define R_M32R_16_RELA 33 /* Direct 16 bit. */ +#define R_M32R_32_RELA 34 /* Direct 32 bit. */ +#define R_M32R_24_RELA 35 /* Direct 24 bit. */ +#define R_M32R_10_PCREL_RELA 36 /* PC relative 10 bit shifted. */ +#define R_M32R_18_PCREL_RELA 37 /* PC relative 18 bit shifted. */ +#define R_M32R_26_PCREL_RELA 38 /* PC relative 26 bit shifted. */ +#define R_M32R_HI16_ULO_RELA 39 /* High 16 bit with unsigned low */ +#define R_M32R_HI16_SLO_RELA 40 /* High 16 bit with signed low */ +#define R_M32R_LO16_RELA 41 /* Low 16 bit */ +#define R_M32R_SDA16_RELA 42 /* 16 bit offset in SDA */ +#define R_M32R_RELA_GNU_VTINHERIT 43 +#define R_M32R_RELA_GNU_VTENTRY 44 +#define R_M32R_REL32 45 /* PC relative 32 bit. */ +#define R_M32R_GOT24 48 /* 24 bit GOT entry */ +#define R_M32R_26_PLTREL 49 /* 26 bit PC relative to PLT shifted */ +#define R_M32R_COPY 50 /* Copy symbol at runtime */ +#define R_M32R_GLOB_DAT 51 /* Create GOT entry */ +#define R_M32R_JMP_SLOT 52 /* Create PLT entry */ +#define R_M32R_RELATIVE 53 /* Adjust by program base */ +#define R_M32R_GOTOFF 54 /* 24 bit offset to GOT */ +#define R_M32R_GOTPC24 55 /* 24 bit PC relative offset to GOT */ +#define R_M32R_GOT16_HI_ULO \ + 56 /* High 16 bit GOT entry with unsigned \ + low */ +#define R_M32R_GOT16_HI_SLO \ + 57 /* High 16 bit GOT entry with signed \ + low */ +#define R_M32R_GOT16_LO 58 /* Low 16 bit GOT entry */ +#define R_M32R_GOTPC_HI_ULO \ + 59 /* High 16 bit PC relative offset to \ + GOT with unsigned low */ +#define R_M32R_GOTPC_HI_SLO \ + 60 /* High 16 bit PC relative offset to \ + GOT with signed low */ +#define R_M32R_GOTPC_LO \ + 61 /* Low 16 bit PC relative offset to \ + GOT */ +#define R_M32R_GOTOFF_HI_ULO \ + 62 /* High 16 bit offset to GOT \ + with unsigned low */ +#define R_M32R_GOTOFF_HI_SLO \ + 63 /* High 16 bit offset to GOT \ + with signed low */ +#define R_M32R_GOTOFF_LO 64 /* Low 16 bit offset to GOT */ +#define R_M32R_NUM 256 /* Keep this the last entry. */ /* TILEPro relocations. */ -#define R_TILEPRO_NONE 0 /* No reloc */ -#define R_TILEPRO_32 1 /* Direct 32 bit */ -#define R_TILEPRO_16 2 /* Direct 16 bit */ -#define R_TILEPRO_8 3 /* Direct 8 bit */ -#define R_TILEPRO_32_PCREL 4 /* PC relative 32 bit */ -#define R_TILEPRO_16_PCREL 5 /* PC relative 16 bit */ -#define R_TILEPRO_8_PCREL 6 /* PC relative 8 bit */ -#define R_TILEPRO_LO16 7 /* Low 16 bit */ -#define R_TILEPRO_HI16 8 /* High 16 bit */ -#define R_TILEPRO_HA16 9 /* High 16 bit, adjusted */ -#define R_TILEPRO_COPY 10 /* Copy relocation */ -#define R_TILEPRO_GLOB_DAT 11 /* Create GOT entry */ -#define R_TILEPRO_JMP_SLOT 12 /* Create PLT entry */ -#define R_TILEPRO_RELATIVE 13 /* Adjust by program base */ -#define R_TILEPRO_BROFF_X1 14 /* X1 pipe branch offset */ -#define R_TILEPRO_JOFFLONG_X1 15 /* X1 pipe jump offset */ -#define R_TILEPRO_JOFFLONG_X1_PLT 16 /* X1 pipe jump offset to PLT */ -#define R_TILEPRO_IMM8_X0 17 /* X0 pipe 8-bit */ -#define R_TILEPRO_IMM8_Y0 18 /* Y0 pipe 8-bit */ -#define R_TILEPRO_IMM8_X1 19 /* X1 pipe 8-bit */ -#define R_TILEPRO_IMM8_Y1 20 /* Y1 pipe 8-bit */ -#define R_TILEPRO_MT_IMM15_X1 21 /* X1 pipe mtspr */ -#define R_TILEPRO_MF_IMM15_X1 22 /* X1 pipe mfspr */ -#define R_TILEPRO_IMM16_X0 23 /* X0 pipe 16-bit */ -#define R_TILEPRO_IMM16_X1 24 /* X1 pipe 16-bit */ -#define R_TILEPRO_IMM16_X0_LO 25 /* X0 pipe low 16-bit */ -#define R_TILEPRO_IMM16_X1_LO 26 /* X1 pipe low 16-bit */ -#define R_TILEPRO_IMM16_X0_HI 27 /* X0 pipe high 16-bit */ -#define R_TILEPRO_IMM16_X1_HI 28 /* X1 pipe high 16-bit */ -#define R_TILEPRO_IMM16_X0_HA 29 /* X0 pipe high 16-bit, adjusted */ -#define R_TILEPRO_IMM16_X1_HA 30 /* X1 pipe high 16-bit, adjusted */ -#define R_TILEPRO_IMM16_X0_PCREL 31 /* X0 pipe PC relative 16 bit */ -#define R_TILEPRO_IMM16_X1_PCREL 32 /* X1 pipe PC relative 16 bit */ -#define R_TILEPRO_IMM16_X0_LO_PCREL 33 /* X0 pipe PC relative low 16 bit */ -#define R_TILEPRO_IMM16_X1_LO_PCREL 34 /* X1 pipe PC relative low 16 bit */ -#define R_TILEPRO_IMM16_X0_HI_PCREL 35 /* X0 pipe PC relative high 16 bit */ -#define R_TILEPRO_IMM16_X1_HI_PCREL 36 /* X1 pipe PC relative high 16 bit */ -#define R_TILEPRO_IMM16_X0_HA_PCREL 37 /* X0 pipe PC relative ha() 16 bit */ -#define R_TILEPRO_IMM16_X1_HA_PCREL 38 /* X1 pipe PC relative ha() 16 bit */ -#define R_TILEPRO_IMM16_X0_GOT 39 /* X0 pipe 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT 40 /* X1 pipe 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X0_GOT_LO 41 /* X0 pipe low 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT_LO 42 /* X1 pipe low 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X0_GOT_HI 43 /* X0 pipe high 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT_HI 44 /* X1 pipe high 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X0_GOT_HA 45 /* X0 pipe ha() 16-bit GOT offset */ -#define R_TILEPRO_IMM16_X1_GOT_HA 46 /* X1 pipe ha() 16-bit GOT offset */ -#define R_TILEPRO_MMSTART_X0 47 /* X0 pipe mm "start" */ -#define R_TILEPRO_MMEND_X0 48 /* X0 pipe mm "end" */ -#define R_TILEPRO_MMSTART_X1 49 /* X1 pipe mm "start" */ -#define R_TILEPRO_MMEND_X1 50 /* X1 pipe mm "end" */ -#define R_TILEPRO_SHAMT_X0 51 /* X0 pipe shift amount */ -#define R_TILEPRO_SHAMT_X1 52 /* X1 pipe shift amount */ -#define R_TILEPRO_SHAMT_Y0 53 /* Y0 pipe shift amount */ -#define R_TILEPRO_SHAMT_Y1 54 /* Y1 pipe shift amount */ -#define R_TILEPRO_DEST_IMM8_X1 55 /* X1 pipe destination 8-bit */ +#define R_TILEPRO_NONE 0 /* No reloc */ +#define R_TILEPRO_32 1 /* Direct 32 bit */ +#define R_TILEPRO_16 2 /* Direct 16 bit */ +#define R_TILEPRO_8 3 /* Direct 8 bit */ +#define R_TILEPRO_32_PCREL 4 /* PC relative 32 bit */ +#define R_TILEPRO_16_PCREL 5 /* PC relative 16 bit */ +#define R_TILEPRO_8_PCREL 6 /* PC relative 8 bit */ +#define R_TILEPRO_LO16 7 /* Low 16 bit */ +#define R_TILEPRO_HI16 8 /* High 16 bit */ +#define R_TILEPRO_HA16 9 /* High 16 bit, adjusted */ +#define R_TILEPRO_COPY 10 /* Copy relocation */ +#define R_TILEPRO_GLOB_DAT 11 /* Create GOT entry */ +#define R_TILEPRO_JMP_SLOT 12 /* Create PLT entry */ +#define R_TILEPRO_RELATIVE 13 /* Adjust by program base */ +#define R_TILEPRO_BROFF_X1 14 /* X1 pipe branch offset */ +#define R_TILEPRO_JOFFLONG_X1 15 /* X1 pipe jump offset */ +#define R_TILEPRO_JOFFLONG_X1_PLT 16 /* X1 pipe jump offset to PLT */ +#define R_TILEPRO_IMM8_X0 17 /* X0 pipe 8-bit */ +#define R_TILEPRO_IMM8_Y0 18 /* Y0 pipe 8-bit */ +#define R_TILEPRO_IMM8_X1 19 /* X1 pipe 8-bit */ +#define R_TILEPRO_IMM8_Y1 20 /* Y1 pipe 8-bit */ +#define R_TILEPRO_MT_IMM15_X1 21 /* X1 pipe mtspr */ +#define R_TILEPRO_MF_IMM15_X1 22 /* X1 pipe mfspr */ +#define R_TILEPRO_IMM16_X0 23 /* X0 pipe 16-bit */ +#define R_TILEPRO_IMM16_X1 24 /* X1 pipe 16-bit */ +#define R_TILEPRO_IMM16_X0_LO 25 /* X0 pipe low 16-bit */ +#define R_TILEPRO_IMM16_X1_LO 26 /* X1 pipe low 16-bit */ +#define R_TILEPRO_IMM16_X0_HI 27 /* X0 pipe high 16-bit */ +#define R_TILEPRO_IMM16_X1_HI 28 /* X1 pipe high 16-bit */ +#define R_TILEPRO_IMM16_X0_HA 29 /* X0 pipe high 16-bit, adjusted */ +#define R_TILEPRO_IMM16_X1_HA 30 /* X1 pipe high 16-bit, adjusted */ +#define R_TILEPRO_IMM16_X0_PCREL 31 /* X0 pipe PC relative 16 bit */ +#define R_TILEPRO_IMM16_X1_PCREL 32 /* X1 pipe PC relative 16 bit */ +#define R_TILEPRO_IMM16_X0_LO_PCREL 33 /* X0 pipe PC relative low 16 bit */ +#define R_TILEPRO_IMM16_X1_LO_PCREL 34 /* X1 pipe PC relative low 16 bit */ +#define R_TILEPRO_IMM16_X0_HI_PCREL 35 /* X0 pipe PC relative high 16 bit */ +#define R_TILEPRO_IMM16_X1_HI_PCREL 36 /* X1 pipe PC relative high 16 bit */ +#define R_TILEPRO_IMM16_X0_HA_PCREL 37 /* X0 pipe PC relative ha() 16 bit */ +#define R_TILEPRO_IMM16_X1_HA_PCREL 38 /* X1 pipe PC relative ha() 16 bit */ +#define R_TILEPRO_IMM16_X0_GOT 39 /* X0 pipe 16-bit GOT offset */ +#define R_TILEPRO_IMM16_X1_GOT 40 /* X1 pipe 16-bit GOT offset */ +#define R_TILEPRO_IMM16_X0_GOT_LO 41 /* X0 pipe low 16-bit GOT offset */ +#define R_TILEPRO_IMM16_X1_GOT_LO 42 /* X1 pipe low 16-bit GOT offset */ +#define R_TILEPRO_IMM16_X0_GOT_HI 43 /* X0 pipe high 16-bit GOT offset */ +#define R_TILEPRO_IMM16_X1_GOT_HI 44 /* X1 pipe high 16-bit GOT offset */ +#define R_TILEPRO_IMM16_X0_GOT_HA 45 /* X0 pipe ha() 16-bit GOT offset */ +#define R_TILEPRO_IMM16_X1_GOT_HA 46 /* X1 pipe ha() 16-bit GOT offset */ +#define R_TILEPRO_MMSTART_X0 47 /* X0 pipe mm "start" */ +#define R_TILEPRO_MMEND_X0 48 /* X0 pipe mm "end" */ +#define R_TILEPRO_MMSTART_X1 49 /* X1 pipe mm "start" */ +#define R_TILEPRO_MMEND_X1 50 /* X1 pipe mm "end" */ +#define R_TILEPRO_SHAMT_X0 51 /* X0 pipe shift amount */ +#define R_TILEPRO_SHAMT_X1 52 /* X1 pipe shift amount */ +#define R_TILEPRO_SHAMT_Y0 53 /* Y0 pipe shift amount */ +#define R_TILEPRO_SHAMT_Y1 54 /* Y1 pipe shift amount */ +#define R_TILEPRO_DEST_IMM8_X1 55 /* X1 pipe destination 8-bit */ /* Relocs 56-59 are currently not defined. */ -#define R_TILEPRO_TLS_GD_CALL 60 /* "jal" for TLS GD */ -#define R_TILEPRO_IMM8_X0_TLS_GD_ADD 61 /* X0 pipe "addi" for TLS GD */ -#define R_TILEPRO_IMM8_X1_TLS_GD_ADD 62 /* X1 pipe "addi" for TLS GD */ -#define R_TILEPRO_IMM8_Y0_TLS_GD_ADD 63 /* Y0 pipe "addi" for TLS GD */ -#define R_TILEPRO_IMM8_Y1_TLS_GD_ADD 64 /* Y1 pipe "addi" for TLS GD */ -#define R_TILEPRO_TLS_IE_LOAD 65 /* "lw_tls" for TLS IE */ -#define R_TILEPRO_IMM16_X0_TLS_GD 66 /* X0 pipe 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD 67 /* X1 pipe 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_GD_LO 68 /* X0 pipe low 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD_LO 69 /* X1 pipe low 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_GD_HI 70 /* X0 pipe high 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD_HI 71 /* X1 pipe high 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_GD_HA 72 /* X0 pipe ha() 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X1_TLS_GD_HA 73 /* X1 pipe ha() 16-bit TLS GD offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE 74 /* X0 pipe 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE 75 /* X1 pipe 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE_LO 76 /* X0 pipe low 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE_LO 77 /* X1 pipe low 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE_HI 78 /* X0 pipe high 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE_HI 79 /* X1 pipe high 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X0_TLS_IE_HA 80 /* X0 pipe ha() 16-bit TLS IE offset */ -#define R_TILEPRO_IMM16_X1_TLS_IE_HA 81 /* X1 pipe ha() 16-bit TLS IE offset */ -#define R_TILEPRO_TLS_DTPMOD32 82 /* ID of module containing symbol */ -#define R_TILEPRO_TLS_DTPOFF32 83 /* Offset in TLS block */ -#define R_TILEPRO_TLS_TPOFF32 84 /* Offset in static TLS block */ -#define R_TILEPRO_IMM16_X0_TLS_LE 85 /* X0 pipe 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE 86 /* X1 pipe 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X0_TLS_LE_LO 87 /* X0 pipe low 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE_LO 88 /* X1 pipe low 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X0_TLS_LE_HI 89 /* X0 pipe high 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE_HI 90 /* X1 pipe high 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X0_TLS_LE_HA 91 /* X0 pipe ha() 16-bit TLS LE offset */ -#define R_TILEPRO_IMM16_X1_TLS_LE_HA 92 /* X1 pipe ha() 16-bit TLS LE offset */ +#define R_TILEPRO_TLS_GD_CALL 60 /* "jal" for TLS GD */ +#define R_TILEPRO_IMM8_X0_TLS_GD_ADD 61 /* X0 pipe "addi" for TLS GD */ +#define R_TILEPRO_IMM8_X1_TLS_GD_ADD 62 /* X1 pipe "addi" for TLS GD */ +#define R_TILEPRO_IMM8_Y0_TLS_GD_ADD 63 /* Y0 pipe "addi" for TLS GD */ +#define R_TILEPRO_IMM8_Y1_TLS_GD_ADD 64 /* Y1 pipe "addi" for TLS GD */ +#define R_TILEPRO_TLS_IE_LOAD 65 /* "lw_tls" for TLS IE */ +#define R_TILEPRO_IMM16_X0_TLS_GD 66 /* X0 pipe 16-bit TLS GD offset */ +#define R_TILEPRO_IMM16_X1_TLS_GD 67 /* X1 pipe 16-bit TLS GD offset */ +#define R_TILEPRO_IMM16_X0_TLS_GD_LO 68 /* X0 pipe low 16-bit TLS GD offset */ +#define R_TILEPRO_IMM16_X1_TLS_GD_LO 69 /* X1 pipe low 16-bit TLS GD offset */ +#define R_TILEPRO_IMM16_X0_TLS_GD_HI 70 /* X0 pipe high 16-bit TLS GD offset \ + */ +#define R_TILEPRO_IMM16_X1_TLS_GD_HI 71 /* X1 pipe high 16-bit TLS GD offset \ + */ +#define R_TILEPRO_IMM16_X0_TLS_GD_HA 72 /* X0 pipe ha() 16-bit TLS GD offset \ + */ +#define R_TILEPRO_IMM16_X1_TLS_GD_HA 73 /* X1 pipe ha() 16-bit TLS GD offset \ + */ +#define R_TILEPRO_IMM16_X0_TLS_IE 74 /* X0 pipe 16-bit TLS IE offset */ +#define R_TILEPRO_IMM16_X1_TLS_IE 75 /* X1 pipe 16-bit TLS IE offset */ +#define R_TILEPRO_IMM16_X0_TLS_IE_LO 76 /* X0 pipe low 16-bit TLS IE offset */ +#define R_TILEPRO_IMM16_X1_TLS_IE_LO 77 /* X1 pipe low 16-bit TLS IE offset */ +#define R_TILEPRO_IMM16_X0_TLS_IE_HI 78 /* X0 pipe high 16-bit TLS IE offset \ + */ +#define R_TILEPRO_IMM16_X1_TLS_IE_HI 79 /* X1 pipe high 16-bit TLS IE offset \ + */ +#define R_TILEPRO_IMM16_X0_TLS_IE_HA 80 /* X0 pipe ha() 16-bit TLS IE offset \ + */ +#define R_TILEPRO_IMM16_X1_TLS_IE_HA 81 /* X1 pipe ha() 16-bit TLS IE offset \ + */ +#define R_TILEPRO_TLS_DTPMOD32 82 /* ID of module containing symbol */ +#define R_TILEPRO_TLS_DTPOFF32 83 /* Offset in TLS block */ +#define R_TILEPRO_TLS_TPOFF32 84 /* Offset in static TLS block */ +#define R_TILEPRO_IMM16_X0_TLS_LE 85 /* X0 pipe 16-bit TLS LE offset */ +#define R_TILEPRO_IMM16_X1_TLS_LE 86 /* X1 pipe 16-bit TLS LE offset */ +#define R_TILEPRO_IMM16_X0_TLS_LE_LO 87 /* X0 pipe low 16-bit TLS LE offset */ +#define R_TILEPRO_IMM16_X1_TLS_LE_LO 88 /* X1 pipe low 16-bit TLS LE offset */ +#define R_TILEPRO_IMM16_X0_TLS_LE_HI 89 /* X0 pipe high 16-bit TLS LE offset \ + */ +#define R_TILEPRO_IMM16_X1_TLS_LE_HI 90 /* X1 pipe high 16-bit TLS LE offset \ + */ +#define R_TILEPRO_IMM16_X0_TLS_LE_HA 91 /* X0 pipe ha() 16-bit TLS LE offset \ + */ +#define R_TILEPRO_IMM16_X1_TLS_LE_HA 92 /* X1 pipe ha() 16-bit TLS LE offset \ + */ -#define R_TILEPRO_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */ -#define R_TILEPRO_GNU_VTENTRY 129 /* GNU C++ vtable member usage */ - -#define R_TILEPRO_NUM 130 +#define R_TILEPRO_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */ +#define R_TILEPRO_GNU_VTENTRY 129 /* GNU C++ vtable member usage */ +#define R_TILEPRO_NUM 130 /* TILE-Gx relocations. */ -#define R_TILEGX_NONE 0 /* No reloc */ -#define R_TILEGX_64 1 /* Direct 64 bit */ -#define R_TILEGX_32 2 /* Direct 32 bit */ -#define R_TILEGX_16 3 /* Direct 16 bit */ -#define R_TILEGX_8 4 /* Direct 8 bit */ -#define R_TILEGX_64_PCREL 5 /* PC relative 64 bit */ -#define R_TILEGX_32_PCREL 6 /* PC relative 32 bit */ -#define R_TILEGX_16_PCREL 7 /* PC relative 16 bit */ -#define R_TILEGX_8_PCREL 8 /* PC relative 8 bit */ -#define R_TILEGX_HW0 9 /* hword 0 16-bit */ -#define R_TILEGX_HW1 10 /* hword 1 16-bit */ -#define R_TILEGX_HW2 11 /* hword 2 16-bit */ -#define R_TILEGX_HW3 12 /* hword 3 16-bit */ -#define R_TILEGX_HW0_LAST 13 /* last hword 0 16-bit */ -#define R_TILEGX_HW1_LAST 14 /* last hword 1 16-bit */ -#define R_TILEGX_HW2_LAST 15 /* last hword 2 16-bit */ -#define R_TILEGX_COPY 16 /* Copy relocation */ -#define R_TILEGX_GLOB_DAT 17 /* Create GOT entry */ -#define R_TILEGX_JMP_SLOT 18 /* Create PLT entry */ -#define R_TILEGX_RELATIVE 19 /* Adjust by program base */ -#define R_TILEGX_BROFF_X1 20 /* X1 pipe branch offset */ -#define R_TILEGX_JUMPOFF_X1 21 /* X1 pipe jump offset */ -#define R_TILEGX_JUMPOFF_X1_PLT 22 /* X1 pipe jump offset to PLT */ -#define R_TILEGX_IMM8_X0 23 /* X0 pipe 8-bit */ -#define R_TILEGX_IMM8_Y0 24 /* Y0 pipe 8-bit */ -#define R_TILEGX_IMM8_X1 25 /* X1 pipe 8-bit */ -#define R_TILEGX_IMM8_Y1 26 /* Y1 pipe 8-bit */ -#define R_TILEGX_DEST_IMM8_X1 27 /* X1 pipe destination 8-bit */ -#define R_TILEGX_MT_IMM14_X1 28 /* X1 pipe mtspr */ -#define R_TILEGX_MF_IMM14_X1 29 /* X1 pipe mfspr */ -#define R_TILEGX_MMSTART_X0 30 /* X0 pipe mm "start" */ -#define R_TILEGX_MMEND_X0 31 /* X0 pipe mm "end" */ -#define R_TILEGX_SHAMT_X0 32 /* X0 pipe shift amount */ -#define R_TILEGX_SHAMT_X1 33 /* X1 pipe shift amount */ -#define R_TILEGX_SHAMT_Y0 34 /* Y0 pipe shift amount */ -#define R_TILEGX_SHAMT_Y1 35 /* Y1 pipe shift amount */ -#define R_TILEGX_IMM16_X0_HW0 36 /* X0 pipe hword 0 */ -#define R_TILEGX_IMM16_X1_HW0 37 /* X1 pipe hword 0 */ -#define R_TILEGX_IMM16_X0_HW1 38 /* X0 pipe hword 1 */ -#define R_TILEGX_IMM16_X1_HW1 39 /* X1 pipe hword 1 */ -#define R_TILEGX_IMM16_X0_HW2 40 /* X0 pipe hword 2 */ -#define R_TILEGX_IMM16_X1_HW2 41 /* X1 pipe hword 2 */ -#define R_TILEGX_IMM16_X0_HW3 42 /* X0 pipe hword 3 */ -#define R_TILEGX_IMM16_X1_HW3 43 /* X1 pipe hword 3 */ -#define R_TILEGX_IMM16_X0_HW0_LAST 44 /* X0 pipe last hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_LAST 45 /* X1 pipe last hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_LAST 46 /* X0 pipe last hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_LAST 47 /* X1 pipe last hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_LAST 48 /* X0 pipe last hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_LAST 49 /* X1 pipe last hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_PCREL 50 /* X0 pipe PC relative hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_PCREL 51 /* X1 pipe PC relative hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_PCREL 52 /* X0 pipe PC relative hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_PCREL 53 /* X1 pipe PC relative hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_PCREL 54 /* X0 pipe PC relative hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_PCREL 55 /* X1 pipe PC relative hword 2 */ -#define R_TILEGX_IMM16_X0_HW3_PCREL 56 /* X0 pipe PC relative hword 3 */ -#define R_TILEGX_IMM16_X1_HW3_PCREL 57 /* X1 pipe PC relative hword 3 */ +#define R_TILEGX_NONE 0 /* No reloc */ +#define R_TILEGX_64 1 /* Direct 64 bit */ +#define R_TILEGX_32 2 /* Direct 32 bit */ +#define R_TILEGX_16 3 /* Direct 16 bit */ +#define R_TILEGX_8 4 /* Direct 8 bit */ +#define R_TILEGX_64_PCREL 5 /* PC relative 64 bit */ +#define R_TILEGX_32_PCREL 6 /* PC relative 32 bit */ +#define R_TILEGX_16_PCREL 7 /* PC relative 16 bit */ +#define R_TILEGX_8_PCREL 8 /* PC relative 8 bit */ +#define R_TILEGX_HW0 9 /* hword 0 16-bit */ +#define R_TILEGX_HW1 10 /* hword 1 16-bit */ +#define R_TILEGX_HW2 11 /* hword 2 16-bit */ +#define R_TILEGX_HW3 12 /* hword 3 16-bit */ +#define R_TILEGX_HW0_LAST 13 /* last hword 0 16-bit */ +#define R_TILEGX_HW1_LAST 14 /* last hword 1 16-bit */ +#define R_TILEGX_HW2_LAST 15 /* last hword 2 16-bit */ +#define R_TILEGX_COPY 16 /* Copy relocation */ +#define R_TILEGX_GLOB_DAT 17 /* Create GOT entry */ +#define R_TILEGX_JMP_SLOT 18 /* Create PLT entry */ +#define R_TILEGX_RELATIVE 19 /* Adjust by program base */ +#define R_TILEGX_BROFF_X1 20 /* X1 pipe branch offset */ +#define R_TILEGX_JUMPOFF_X1 21 /* X1 pipe jump offset */ +#define R_TILEGX_JUMPOFF_X1_PLT 22 /* X1 pipe jump offset to PLT */ +#define R_TILEGX_IMM8_X0 23 /* X0 pipe 8-bit */ +#define R_TILEGX_IMM8_Y0 24 /* Y0 pipe 8-bit */ +#define R_TILEGX_IMM8_X1 25 /* X1 pipe 8-bit */ +#define R_TILEGX_IMM8_Y1 26 /* Y1 pipe 8-bit */ +#define R_TILEGX_DEST_IMM8_X1 27 /* X1 pipe destination 8-bit */ +#define R_TILEGX_MT_IMM14_X1 28 /* X1 pipe mtspr */ +#define R_TILEGX_MF_IMM14_X1 29 /* X1 pipe mfspr */ +#define R_TILEGX_MMSTART_X0 30 /* X0 pipe mm "start" */ +#define R_TILEGX_MMEND_X0 31 /* X0 pipe mm "end" */ +#define R_TILEGX_SHAMT_X0 32 /* X0 pipe shift amount */ +#define R_TILEGX_SHAMT_X1 33 /* X1 pipe shift amount */ +#define R_TILEGX_SHAMT_Y0 34 /* Y0 pipe shift amount */ +#define R_TILEGX_SHAMT_Y1 35 /* Y1 pipe shift amount */ +#define R_TILEGX_IMM16_X0_HW0 36 /* X0 pipe hword 0 */ +#define R_TILEGX_IMM16_X1_HW0 37 /* X1 pipe hword 0 */ +#define R_TILEGX_IMM16_X0_HW1 38 /* X0 pipe hword 1 */ +#define R_TILEGX_IMM16_X1_HW1 39 /* X1 pipe hword 1 */ +#define R_TILEGX_IMM16_X0_HW2 40 /* X0 pipe hword 2 */ +#define R_TILEGX_IMM16_X1_HW2 41 /* X1 pipe hword 2 */ +#define R_TILEGX_IMM16_X0_HW3 42 /* X0 pipe hword 3 */ +#define R_TILEGX_IMM16_X1_HW3 43 /* X1 pipe hword 3 */ +#define R_TILEGX_IMM16_X0_HW0_LAST 44 /* X0 pipe last hword 0 */ +#define R_TILEGX_IMM16_X1_HW0_LAST 45 /* X1 pipe last hword 0 */ +#define R_TILEGX_IMM16_X0_HW1_LAST 46 /* X0 pipe last hword 1 */ +#define R_TILEGX_IMM16_X1_HW1_LAST 47 /* X1 pipe last hword 1 */ +#define R_TILEGX_IMM16_X0_HW2_LAST 48 /* X0 pipe last hword 2 */ +#define R_TILEGX_IMM16_X1_HW2_LAST 49 /* X1 pipe last hword 2 */ +#define R_TILEGX_IMM16_X0_HW0_PCREL 50 /* X0 pipe PC relative hword 0 */ +#define R_TILEGX_IMM16_X1_HW0_PCREL 51 /* X1 pipe PC relative hword 0 */ +#define R_TILEGX_IMM16_X0_HW1_PCREL 52 /* X0 pipe PC relative hword 1 */ +#define R_TILEGX_IMM16_X1_HW1_PCREL 53 /* X1 pipe PC relative hword 1 */ +#define R_TILEGX_IMM16_X0_HW2_PCREL 54 /* X0 pipe PC relative hword 2 */ +#define R_TILEGX_IMM16_X1_HW2_PCREL 55 /* X1 pipe PC relative hword 2 */ +#define R_TILEGX_IMM16_X0_HW3_PCREL 56 /* X0 pipe PC relative hword 3 */ +#define R_TILEGX_IMM16_X1_HW3_PCREL 57 /* X1 pipe PC relative hword 3 */ #define R_TILEGX_IMM16_X0_HW0_LAST_PCREL 58 /* X0 pipe PC-rel last hword 0 */ #define R_TILEGX_IMM16_X1_HW0_LAST_PCREL 59 /* X1 pipe PC-rel last hword 0 */ #define R_TILEGX_IMM16_X0_HW1_LAST_PCREL 60 /* X0 pipe PC-rel last hword 1 */ #define R_TILEGX_IMM16_X1_HW1_LAST_PCREL 61 /* X1 pipe PC-rel last hword 1 */ #define R_TILEGX_IMM16_X0_HW2_LAST_PCREL 62 /* X0 pipe PC-rel last hword 2 */ #define R_TILEGX_IMM16_X1_HW2_LAST_PCREL 63 /* X1 pipe PC-rel last hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_GOT 64 /* X0 pipe hword 0 GOT offset */ -#define R_TILEGX_IMM16_X1_HW0_GOT 65 /* X1 pipe hword 0 GOT offset */ -#define R_TILEGX_IMM16_X0_HW0_PLT_PCREL 66 /* X0 pipe PC-rel PLT hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_PLT_PCREL 67 /* X1 pipe PC-rel PLT hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_PLT_PCREL 68 /* X0 pipe PC-rel PLT hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_PLT_PCREL 69 /* X1 pipe PC-rel PLT hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_PLT_PCREL 70 /* X0 pipe PC-rel PLT hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_PLT_PCREL 71 /* X1 pipe PC-rel PLT hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_LAST_GOT 72 /* X0 pipe last hword 0 GOT offset */ -#define R_TILEGX_IMM16_X1_HW0_LAST_GOT 73 /* X1 pipe last hword 0 GOT offset */ -#define R_TILEGX_IMM16_X0_HW1_LAST_GOT 74 /* X0 pipe last hword 1 GOT offset */ -#define R_TILEGX_IMM16_X1_HW1_LAST_GOT 75 /* X1 pipe last hword 1 GOT offset */ -#define R_TILEGX_IMM16_X0_HW3_PLT_PCREL 76 /* X0 pipe PC-rel PLT hword 3 */ -#define R_TILEGX_IMM16_X1_HW3_PLT_PCREL 77 /* X1 pipe PC-rel PLT hword 3 */ -#define R_TILEGX_IMM16_X0_HW0_TLS_GD 78 /* X0 pipe hword 0 TLS GD offset */ -#define R_TILEGX_IMM16_X1_HW0_TLS_GD 79 /* X1 pipe hword 0 TLS GD offset */ -#define R_TILEGX_IMM16_X0_HW0_TLS_LE 80 /* X0 pipe hword 0 TLS LE offset */ -#define R_TILEGX_IMM16_X1_HW0_TLS_LE 81 /* X1 pipe hword 0 TLS LE offset */ +#define R_TILEGX_IMM16_X0_HW0_GOT 64 /* X0 pipe hword 0 GOT offset */ +#define R_TILEGX_IMM16_X1_HW0_GOT 65 /* X1 pipe hword 0 GOT offset */ +#define R_TILEGX_IMM16_X0_HW0_PLT_PCREL 66 /* X0 pipe PC-rel PLT hword 0 */ +#define R_TILEGX_IMM16_X1_HW0_PLT_PCREL 67 /* X1 pipe PC-rel PLT hword 0 */ +#define R_TILEGX_IMM16_X0_HW1_PLT_PCREL 68 /* X0 pipe PC-rel PLT hword 1 */ +#define R_TILEGX_IMM16_X1_HW1_PLT_PCREL 69 /* X1 pipe PC-rel PLT hword 1 */ +#define R_TILEGX_IMM16_X0_HW2_PLT_PCREL 70 /* X0 pipe PC-rel PLT hword 2 */ +#define R_TILEGX_IMM16_X1_HW2_PLT_PCREL 71 /* X1 pipe PC-rel PLT hword 2 */ +#define R_TILEGX_IMM16_X0_HW0_LAST_GOT 72 /* X0 pipe last hword 0 GOT offset \ + */ +#define R_TILEGX_IMM16_X1_HW0_LAST_GOT 73 /* X1 pipe last hword 0 GOT offset \ + */ +#define R_TILEGX_IMM16_X0_HW1_LAST_GOT 74 /* X0 pipe last hword 1 GOT offset \ + */ +#define R_TILEGX_IMM16_X1_HW1_LAST_GOT 75 /* X1 pipe last hword 1 GOT offset \ + */ +#define R_TILEGX_IMM16_X0_HW3_PLT_PCREL 76 /* X0 pipe PC-rel PLT hword 3 */ +#define R_TILEGX_IMM16_X1_HW3_PLT_PCREL 77 /* X1 pipe PC-rel PLT hword 3 */ +#define R_TILEGX_IMM16_X0_HW0_TLS_GD 78 /* X0 pipe hword 0 TLS GD offset */ +#define R_TILEGX_IMM16_X1_HW0_TLS_GD 79 /* X1 pipe hword 0 TLS GD offset */ +#define R_TILEGX_IMM16_X0_HW0_TLS_LE 80 /* X0 pipe hword 0 TLS LE offset */ +#define R_TILEGX_IMM16_X1_HW0_TLS_LE 81 /* X1 pipe hword 0 TLS LE offset */ #define R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE 82 /* X0 pipe last hword 0 LE off */ #define R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE 83 /* X1 pipe last hword 0 LE off */ #define R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE 84 /* X0 pipe last hword 1 LE off */ @@ -3215,106 +3254,115 @@ typedef Elf32_Addr Elf32_Conflict; #define R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD 88 /* X0 pipe last hword 1 GD off */ #define R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD 89 /* X1 pipe last hword 1 GD off */ /* Relocs 90-91 are currently not defined. */ -#define R_TILEGX_IMM16_X0_HW0_TLS_IE 92 /* X0 pipe hword 0 TLS IE offset */ -#define R_TILEGX_IMM16_X1_HW0_TLS_IE 93 /* X1 pipe hword 0 TLS IE offset */ -#define R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL 94 /* X0 pipe PC-rel PLT last hword 0 */ -#define R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL 95 /* X1 pipe PC-rel PLT last hword 0 */ -#define R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL 96 /* X0 pipe PC-rel PLT last hword 1 */ -#define R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL 97 /* X1 pipe PC-rel PLT last hword 1 */ -#define R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL 98 /* X0 pipe PC-rel PLT last hword 2 */ -#define R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL 99 /* X1 pipe PC-rel PLT last hword 2 */ -#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE 100 /* X0 pipe last hword 0 IE off */ -#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE 101 /* X1 pipe last hword 0 IE off */ -#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE 102 /* X0 pipe last hword 1 IE off */ -#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE 103 /* X1 pipe last hword 1 IE off */ +#define R_TILEGX_IMM16_X0_HW0_TLS_IE 92 /* X0 pipe hword 0 TLS IE offset */ +#define R_TILEGX_IMM16_X1_HW0_TLS_IE 93 /* X1 pipe hword 0 TLS IE offset */ +#define R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL \ + 94 /* X0 pipe PC-rel PLT last hword 0 */ +#define R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL \ + 95 /* X1 pipe PC-rel PLT last hword 0 */ +#define R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL \ + 96 /* X0 pipe PC-rel PLT last hword 1 */ +#define R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL \ + 97 /* X1 pipe PC-rel PLT last hword 1 */ +#define R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL \ + 98 /* X0 pipe PC-rel PLT last hword 2 */ +#define R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL \ + 99 /* X1 pipe PC-rel PLT last hword 2 */ +#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE 100 /* X0 pipe last hword 0 IE off \ + */ +#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE 101 /* X1 pipe last hword 0 IE off \ + */ +#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE 102 /* X0 pipe last hword 1 IE off \ + */ +#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE 103 /* X1 pipe last hword 1 IE off \ + */ /* Relocs 104-105 are currently not defined. */ -#define R_TILEGX_TLS_DTPMOD64 106 /* 64-bit ID of symbol's module */ -#define R_TILEGX_TLS_DTPOFF64 107 /* 64-bit offset in TLS block */ -#define R_TILEGX_TLS_TPOFF64 108 /* 64-bit offset in static TLS block */ -#define R_TILEGX_TLS_DTPMOD32 109 /* 32-bit ID of symbol's module */ -#define R_TILEGX_TLS_DTPOFF32 110 /* 32-bit offset in TLS block */ -#define R_TILEGX_TLS_TPOFF32 111 /* 32-bit offset in static TLS block */ -#define R_TILEGX_TLS_GD_CALL 112 /* "jal" for TLS GD */ -#define R_TILEGX_IMM8_X0_TLS_GD_ADD 113 /* X0 pipe "addi" for TLS GD */ -#define R_TILEGX_IMM8_X1_TLS_GD_ADD 114 /* X1 pipe "addi" for TLS GD */ -#define R_TILEGX_IMM8_Y0_TLS_GD_ADD 115 /* Y0 pipe "addi" for TLS GD */ -#define R_TILEGX_IMM8_Y1_TLS_GD_ADD 116 /* Y1 pipe "addi" for TLS GD */ -#define R_TILEGX_TLS_IE_LOAD 117 /* "ld_tls" for TLS IE */ -#define R_TILEGX_IMM8_X0_TLS_ADD 118 /* X0 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_IMM8_X1_TLS_ADD 119 /* X1 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_IMM8_Y0_TLS_ADD 120 /* Y0 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_IMM8_Y1_TLS_ADD 121 /* Y1 pipe "addi" for TLS GD/IE */ +#define R_TILEGX_TLS_DTPMOD64 106 /* 64-bit ID of symbol's module */ +#define R_TILEGX_TLS_DTPOFF64 107 /* 64-bit offset in TLS block */ +#define R_TILEGX_TLS_TPOFF64 108 /* 64-bit offset in static TLS block */ +#define R_TILEGX_TLS_DTPMOD32 109 /* 32-bit ID of symbol's module */ +#define R_TILEGX_TLS_DTPOFF32 110 /* 32-bit offset in TLS block */ +#define R_TILEGX_TLS_TPOFF32 111 /* 32-bit offset in static TLS block */ +#define R_TILEGX_TLS_GD_CALL 112 /* "jal" for TLS GD */ +#define R_TILEGX_IMM8_X0_TLS_GD_ADD 113 /* X0 pipe "addi" for TLS GD */ +#define R_TILEGX_IMM8_X1_TLS_GD_ADD 114 /* X1 pipe "addi" for TLS GD */ +#define R_TILEGX_IMM8_Y0_TLS_GD_ADD 115 /* Y0 pipe "addi" for TLS GD */ +#define R_TILEGX_IMM8_Y1_TLS_GD_ADD 116 /* Y1 pipe "addi" for TLS GD */ +#define R_TILEGX_TLS_IE_LOAD 117 /* "ld_tls" for TLS IE */ +#define R_TILEGX_IMM8_X0_TLS_ADD 118 /* X0 pipe "addi" for TLS GD/IE */ +#define R_TILEGX_IMM8_X1_TLS_ADD 119 /* X1 pipe "addi" for TLS GD/IE */ +#define R_TILEGX_IMM8_Y0_TLS_ADD 120 /* Y0 pipe "addi" for TLS GD/IE */ +#define R_TILEGX_IMM8_Y1_TLS_ADD 121 /* Y1 pipe "addi" for TLS GD/IE */ -#define R_TILEGX_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */ -#define R_TILEGX_GNU_VTENTRY 129 /* GNU C++ vtable member usage */ +#define R_TILEGX_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */ +#define R_TILEGX_GNU_VTENTRY 129 /* GNU C++ vtable member usage */ -#define R_TILEGX_NUM 130 +#define R_TILEGX_NUM 130 /* RISC-V ELF Flags */ -#define EF_RISCV_RVC 0x0001 -#define EF_RISCV_FLOAT_ABI 0x0006 -#define EF_RISCV_FLOAT_ABI_SOFT 0x0000 -#define EF_RISCV_FLOAT_ABI_SINGLE 0x0002 -#define EF_RISCV_FLOAT_ABI_DOUBLE 0x0004 -#define EF_RISCV_FLOAT_ABI_QUAD 0x0006 +#define EF_RISCV_RVC 0x0001 +#define EF_RISCV_FLOAT_ABI 0x0006 +#define EF_RISCV_FLOAT_ABI_SOFT 0x0000 +#define EF_RISCV_FLOAT_ABI_SINGLE 0x0002 +#define EF_RISCV_FLOAT_ABI_DOUBLE 0x0004 +#define EF_RISCV_FLOAT_ABI_QUAD 0x0006 /* RISC-V relocations. */ -#define R_RISCV_NONE 0 -#define R_RISCV_32 1 -#define R_RISCV_64 2 -#define R_RISCV_RELATIVE 3 -#define R_RISCV_COPY 4 -#define R_RISCV_JUMP_SLOT 5 -#define R_RISCV_TLS_DTPMOD32 6 -#define R_RISCV_TLS_DTPMOD64 7 -#define R_RISCV_TLS_DTPREL32 8 -#define R_RISCV_TLS_DTPREL64 9 -#define R_RISCV_TLS_TPREL32 10 -#define R_RISCV_TLS_TPREL64 11 -#define R_RISCV_BRANCH 16 -#define R_RISCV_JAL 17 -#define R_RISCV_CALL 18 -#define R_RISCV_CALL_PLT 19 -#define R_RISCV_GOT_HI20 20 -#define R_RISCV_TLS_GOT_HI20 21 -#define R_RISCV_TLS_GD_HI20 22 -#define R_RISCV_PCREL_HI20 23 -#define R_RISCV_PCREL_LO12_I 24 -#define R_RISCV_PCREL_LO12_S 25 -#define R_RISCV_HI20 26 -#define R_RISCV_LO12_I 27 -#define R_RISCV_LO12_S 28 -#define R_RISCV_TPREL_HI20 29 -#define R_RISCV_TPREL_LO12_I 30 -#define R_RISCV_TPREL_LO12_S 31 -#define R_RISCV_TPREL_ADD 32 -#define R_RISCV_ADD8 33 -#define R_RISCV_ADD16 34 -#define R_RISCV_ADD32 35 -#define R_RISCV_ADD64 36 -#define R_RISCV_SUB8 37 -#define R_RISCV_SUB16 38 -#define R_RISCV_SUB32 39 -#define R_RISCV_SUB64 40 -#define R_RISCV_GNU_VTINHERIT 41 -#define R_RISCV_GNU_VTENTRY 42 -#define R_RISCV_ALIGN 43 -#define R_RISCV_RVC_BRANCH 44 -#define R_RISCV_RVC_JUMP 45 -#define R_RISCV_RVC_LUI 46 -#define R_RISCV_GPREL_I 47 -#define R_RISCV_GPREL_S 48 -#define R_RISCV_TPREL_I 49 -#define R_RISCV_TPREL_S 50 -#define R_RISCV_RELAX 51 -#define R_RISCV_SUB6 52 -#define R_RISCV_SET6 53 -#define R_RISCV_SET8 54 -#define R_RISCV_SET16 55 -#define R_RISCV_SET32 56 -#define R_RISCV_32_PCREL 57 +#define R_RISCV_NONE 0 +#define R_RISCV_32 1 +#define R_RISCV_64 2 +#define R_RISCV_RELATIVE 3 +#define R_RISCV_COPY 4 +#define R_RISCV_JUMP_SLOT 5 +#define R_RISCV_TLS_DTPMOD32 6 +#define R_RISCV_TLS_DTPMOD64 7 +#define R_RISCV_TLS_DTPREL32 8 +#define R_RISCV_TLS_DTPREL64 9 +#define R_RISCV_TLS_TPREL32 10 +#define R_RISCV_TLS_TPREL64 11 +#define R_RISCV_BRANCH 16 +#define R_RISCV_JAL 17 +#define R_RISCV_CALL 18 +#define R_RISCV_CALL_PLT 19 +#define R_RISCV_GOT_HI20 20 +#define R_RISCV_TLS_GOT_HI20 21 +#define R_RISCV_TLS_GD_HI20 22 +#define R_RISCV_PCREL_HI20 23 +#define R_RISCV_PCREL_LO12_I 24 +#define R_RISCV_PCREL_LO12_S 25 +#define R_RISCV_HI20 26 +#define R_RISCV_LO12_I 27 +#define R_RISCV_LO12_S 28 +#define R_RISCV_TPREL_HI20 29 +#define R_RISCV_TPREL_LO12_I 30 +#define R_RISCV_TPREL_LO12_S 31 +#define R_RISCV_TPREL_ADD 32 +#define R_RISCV_ADD8 33 +#define R_RISCV_ADD16 34 +#define R_RISCV_ADD32 35 +#define R_RISCV_ADD64 36 +#define R_RISCV_SUB8 37 +#define R_RISCV_SUB16 38 +#define R_RISCV_SUB32 39 +#define R_RISCV_SUB64 40 +#define R_RISCV_GNU_VTINHERIT 41 +#define R_RISCV_GNU_VTENTRY 42 +#define R_RISCV_ALIGN 43 +#define R_RISCV_RVC_BRANCH 44 +#define R_RISCV_RVC_JUMP 45 +#define R_RISCV_RVC_LUI 46 +#define R_RISCV_GPREL_I 47 +#define R_RISCV_GPREL_S 48 +#define R_RISCV_TPREL_I 49 +#define R_RISCV_TPREL_S 50 +#define R_RISCV_RELAX 51 +#define R_RISCV_SUB6 52 +#define R_RISCV_SET6 53 +#define R_RISCV_SET8 54 +#define R_RISCV_SET16 55 +#define R_RISCV_SET32 56 +#define R_RISCV_32_PCREL 57 -#define R_RISCV_NUM 58 +#define R_RISCV_NUM 58 - -#endif /* elf.h */ +#endif /* elf.h */ diff --git a/src/tcc/fs.c b/src/tcc/fs.c index 2bcdd5c..26cd76b 100644 --- a/src/tcc/fs.c +++ b/src/tcc/fs.c @@ -1,11 +1,10 @@ +#include #include #include -#include extern uint8_t ramdisk_start; extern uint8_t ramdisk_end; - #define RAMDISK_SIZE ((&ramdisk_end) - (&ramdisk_start)) static Finfo *file_table = NULL; @@ -18,30 +17,21 @@ int fs_init(Finfo *list, size_t count) { return 0; } - - -size_t ramdisk_read(void *buf, size_t offset, size_t len) -{ +size_t ramdisk_read(void *buf, size_t offset, size_t len) { assert(offset + len <= RAMDISK_SIZE); memcpy(buf, &ramdisk_start + offset, len); return len; } -size_t ramdisk_write(const void *buf, size_t offset, size_t len) -{ +size_t ramdisk_write(const void *buf, size_t offset, size_t len) { assert(offset + len <= RAMDISK_SIZE); memcpy(&ramdisk_start + offset, buf, len); return len; } - - -int fs_open(const char *pathname, int flags, int mode) -{ - //printf("ex1 addr is %x\n", (uint32_t)ramdisk_start + 336); - for(int fs_num = 0; fs_num < file_count; fs_num ++) - { - if(strcmp(pathname, file_table[fs_num].name) == 0) // 匹配成功 - { +int fs_open(const char *pathname, int flags, int mode) { + // printf("ex1 addr is %x\n", (uint32_t)ramdisk_start + 336); + for (int fs_num = 0; fs_num < file_count; fs_num++) { + if (strcmp(pathname, file_table[fs_num].name) == 0) { file_table[fs_num].open_offset = 0; return fs_num; } @@ -50,56 +40,48 @@ int fs_open(const char *pathname, int flags, int mode) assert(0); } -size_t fs_read(int fd, void *buf, size_t len) -{ +size_t fs_read(int fd, void *buf, size_t len) { assert(file_table); assert(buf); Finfo *file = &file_table[fd]; size_t real_len = len; size_t size = file->size; - size_t disk_offset = file->disk_offset; + size_t disk_offset = file->disk_offset; size_t open_offset = file->open_offset; - - if(file->read != NULL) - { + + if (file->read != NULL) { return file->read(buf, file->open_offset, len); } - if(open_offset > size) - { + if (open_offset > size) { return 0; } - if(open_offset + len > size) - { + if (open_offset + len > size) { real_len = size - open_offset; } - + ramdisk_read(buf, disk_offset + open_offset, real_len); file->open_offset += real_len; return real_len; } -size_t fs_write(int fd, const void *buf, size_t len) -{ +size_t fs_write(int fd, const void *buf, size_t len) { assert(file_table); assert(buf); Finfo *file = &file_table[fd]; size_t real_len = len; size_t size = file->size; - size_t disk_offset = file->disk_offset; + size_t disk_offset = file->disk_offset; size_t open_offset = file->open_offset; - if(file->write != NULL) - { + if (file->write != NULL) { return file->write(buf, file->open_offset, len); } - if(open_offset > size) - { + if (open_offset > size) { return 0; } - if(open_offset + len > size) - { + if (open_offset + len > size) { real_len = size - open_offset; } @@ -108,21 +90,25 @@ size_t fs_write(int fd, const void *buf, size_t len) return real_len; } -size_t fs_lseek(int fd, size_t offset, int whence) -{ +size_t fs_lseek(int fd, size_t offset, int whence) { assert(file_table); size_t new_offset = 0; Finfo *file = &file_table[fd]; - switch(whence) - { - case SEEK_SET: new_offset = offset; break; - case SEEK_CUR: new_offset = file->open_offset + offset; break; - case SEEK_END: new_offset = file->size + offset; break; - default : return -1; + switch (whence) { + case SEEK_SET: + new_offset = offset; + break; + case SEEK_CUR: + new_offset = file->open_offset + offset; + break; + case SEEK_END: + new_offset = file->size + offset; + break; + default: + return -1; } - if((new_offset < 0 || new_offset > file->size)) - { + if ((new_offset < 0 || new_offset > file->size)) { bench_printf("file offset out of bound\n"); return -1; } @@ -131,19 +117,10 @@ size_t fs_lseek(int fd, size_t offset, int whence) return new_offset; } -int fs_close(int fd) -{ - return 0; -} +int fs_close(int fd) { return 0; } -int fs_tell(int fd) -{ +int fs_tell(int fd) { assert(file_table); Finfo *file = &file_table[fd]; return file->open_offset; } - - - - - diff --git a/src/tcc/include/fs.h b/src/tcc/include/fs.h index 2fa1abc..4b902ac 100644 --- a/src/tcc/include/fs.h +++ b/src/tcc/include/fs.h @@ -5,12 +5,12 @@ #include #ifndef SEEK_SET -enum {SEEK_SET, SEEK_CUR, SEEK_END}; +enum { SEEK_SET, SEEK_CUR, SEEK_END }; #endif -enum {FD_STDIN, FD_STDOUT, FD_STDERR}; +enum { FD_STDIN, FD_STDOUT, FD_STDERR }; -typedef size_t (*ReadFn) (void *buf, size_t offset, size_t len); -typedef size_t (*WriteFn) (const void *buf, size_t offset, size_t len); +typedef size_t (*ReadFn)(void *buf, size_t offset, size_t len); +typedef size_t (*WriteFn)(const void *buf, size_t offset, size_t len); typedef struct { char *name; diff --git a/src/tcc/input/test.c b/src/tcc/input/test.c index 98d087d..cd99c74 100644 --- a/src/tcc/input/test.c +++ b/src/tcc/input/test.c @@ -2,25 +2,23 @@ int ans[] = {153, 370, 371, 407}; -int cube(int n) { - return n * n * n; -} +int cube(int n) { return n * n * n; } int main() { - int n, n2, n1, n0; - int k = 0; - for(n = 100; n < 500; n ++) { - n2 = n / 100; - n1 = (n / 10) % 10; - n0 = n % 10; + int n, n2, n1, n0; + int k = 0; + for (n = 100; n < 500; n++) { + n2 = n / 100; + n1 = (n / 10) % 10; + n0 = n % 10; - // if(n == cube(n2) + cube(n1) + cube(n0)) { - // check(n == ans[k]); - // k ++; - // } - } + // if(n == cube(n2) + cube(n1) + cube(n0)) { + // check(n == ans[k]); + // k ++; + // } + } - // check(k == 4); + // check(k == 4); - return 0; + return 0; } diff --git a/src/tcc/input/train.c b/src/tcc/input/train.c index c13c065..c38e132 100644 --- a/src/tcc/input/train.c +++ b/src/tcc/input/train.c @@ -4,49 +4,59 @@ typedef unsigned int uint32_t; typedef unsigned char uint8_t; typedef uint32_t size_t; #define NULL 0 -#define LENGTH(x) sizeof(x)/sizeof(x[0]) +#define LENGTH(x) sizeof(x) / sizeof(x[0]) void *memset(void *s, int c, size_t n) { - char* p = NULL; - if(s == NULL) + char *p = NULL; + if (s == NULL) return s; - + p = (char *)s; - while(n > 0) - { + while (n > 0) { *(p++) = c; n--; } return s; } -// *************************************** *************************************** // +// *************************************** +// *************************************** // int add(int a, int b) { - int c = a + b; - return c; + int c = a + b; + return c; } -int add_test_data[] = {0, 1, 2, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff}; -int add_ans[] = {0, 0x1, 0x2, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0x1, 0x2, 0x3, 0x80000000, 0x80000001, 0x80000002, 0xffffffff, 0, 0x2, 0x3, 0x4, 0x80000001, 0x80000002, 0x80000003, 0, 0x1, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0, 0x7ffffffd, 0x7ffffffe, 0x80000000, 0x80000001, 0x80000002, 0xffffffff, 0, 0x1, 0x7ffffffe, 0x7fffffff, 0x80000001, 0x80000002, 0x80000003, 0, 0x1, 0x2, 0x7fffffff, 0x80000000, 0xfffffffe, 0xffffffff, 0, 0x7ffffffd, 0x7ffffffe, 0x7fffffff, 0xfffffffc, 0xfffffffd, 0xffffffff, 0, 0x1, 0x7ffffffe, 0x7fffffff, 0x80000000, 0xfffffffd, 0xfffffffe}; +int add_test_data[] = {0, 1, 2, 0x7fffffff, + 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff}; +int add_ans[] = { + 0, 0x1, 0x2, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, + 0xffffffff, 0x1, 0x2, 0x3, 0x80000000, 0x80000001, 0x80000002, + 0xffffffff, 0, 0x2, 0x3, 0x4, 0x80000001, 0x80000002, + 0x80000003, 0, 0x1, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, + 0xffffffff, 0, 0x7ffffffd, 0x7ffffffe, 0x80000000, 0x80000001, 0x80000002, + 0xffffffff, 0, 0x1, 0x7ffffffe, 0x7fffffff, 0x80000001, 0x80000002, + 0x80000003, 0, 0x1, 0x2, 0x7fffffff, 0x80000000, 0xfffffffe, + 0xffffffff, 0, 0x7ffffffd, 0x7ffffffe, 0x7fffffff, 0xfffffffc, 0xfffffffd, + 0xffffffff, 0, 0x1, 0x7ffffffe, 0x7fffffff, 0x80000000, 0xfffffffd, + 0xfffffffe}; #define add_NR_DATA 8 int add_main() { - int i, j, ans_idx = 0; - for(i = 0; i < add_NR_DATA; i ++) { - for(j = 0; j < add_NR_DATA; j ++) { - check(add(add_test_data[i], add_test_data[j]) == add_ans[ans_idx ++]); - } - check(j == add_NR_DATA); - } + int i, j, ans_idx = 0; + for (i = 0; i < add_NR_DATA; i++) { + for (j = 0; j < add_NR_DATA; j++) { + check(add(add_test_data[i], add_test_data[j]) == add_ans[ans_idx++]); + } + check(j == add_NR_DATA); + } - check(i == add_NR_DATA); + check(i == add_NR_DATA); - return 0; + return 0; } -int main(){ - add_main(); - return 0; +int main() { + add_main(); + return 0; } - diff --git a/src/tcc/input/trap.h b/src/tcc/input/trap.h index 174109b..0b1efd9 100644 --- a/src/tcc/input/trap.h +++ b/src/tcc/input/trap.h @@ -2,7 +2,8 @@ #define __TRAP_H__ int check(int cond) { - if (!cond) return 1; + if (!cond) + return 1; return 0; } diff --git a/src/tcc/input/trm.c b/src/tcc/input/trm.c index 196517c..3299fb1 100644 --- a/src/tcc/input/trm.c +++ b/src/tcc/input/trm.c @@ -11,7 +11,5 @@ static const char mainargs[] = ""; void _start() { int ret = main(mainargs); - // halt(ret); + // halt(ret); } - - diff --git a/src/tcc/libtcc.c b/src/tcc/libtcc.c index c1bd74c..fca06ea 100644 --- a/src/tcc/libtcc.c +++ b/src/tcc/libtcc.c @@ -18,15 +18,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "tccpp.c" -#include "tccgen.c" -#include "tccdbg.c" #include "tccasm.c" +#include "tccdbg.c" #include "tccelf.c" +#include "tccgen.c" +#include "tccpp.c" +#include "riscv32-asm.c" #include "riscv32-gen.c" #include "riscv32-link.c" -#include "riscv32-asm.c" #include "tcc.h" @@ -39,99 +39,88 @@ TCC_SEM(static tcc_compile_sem); /********************************************************/ #if CONFIG_TCC_SEMLOCK -ST_FUNC void wait_sem(TCCSem *p) -{ - if (!p->init) - sem_init(&p->sem, 0, 1), p->init = 1; - while (sem_wait(&p->sem) < 0 && errno == EINTR); -} -ST_FUNC void post_sem(TCCSem *p) -{ - sem_post(&p->sem); +ST_FUNC void wait_sem(TCCSem *p) { + if (!p->init) + sem_init(&p->sem, 0, 1), p->init = 1; + while (sem_wait(&p->sem) < 0 && errno == EINTR) + ; } +ST_FUNC void post_sem(TCCSem *p) { sem_post(&p->sem); } #endif -PUB_FUNC void tcc_enter_state(TCCState *s1) -{ - if (s1->error_set_jmp_enabled) - return; - WAIT_SEM(&tcc_compile_sem); - tcc_state = s1; +PUB_FUNC void tcc_enter_state(TCCState *s1) { + if (s1->error_set_jmp_enabled) + return; + WAIT_SEM(&tcc_compile_sem); + tcc_state = s1; } -PUB_FUNC void tcc_exit_state(TCCState *s1) -{ - if (s1->error_set_jmp_enabled) - return; - tcc_state = NULL; - POST_SEM(&tcc_compile_sem); +PUB_FUNC void tcc_exit_state(TCCState *s1) { + if (s1->error_set_jmp_enabled) + return; + tcc_state = NULL; + POST_SEM(&tcc_compile_sem); } /********************************************************/ /* copy a string and truncate it. */ -ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s) -{ - char *q, *q_end; - int c; +ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s) { + char *q, *q_end; + int c; - if (buf_size > 0) { - q = buf; - q_end = buf + buf_size - 1; - while (q < q_end) { - c = *s++; - if (c == '\0') - break; - *q++ = c; - } - *q = '\0'; + if (buf_size > 0) { + q = buf; + q_end = buf + buf_size - 1; + while (q < q_end) { + c = *s++; + if (c == '\0') + break; + *q++ = c; } - return buf; + *q = '\0'; + } + return buf; } /* strcat and truncate. */ -ST_FUNC char *pstrcat(char *buf, size_t buf_size, const char *s) -{ - size_t len; - len = strlen(buf); - if (len < buf_size) - pstrcpy(buf + len, buf_size - len, s); - return buf; +ST_FUNC char *pstrcat(char *buf, size_t buf_size, const char *s) { + size_t len; + len = strlen(buf); + if (len < buf_size) + pstrcpy(buf + len, buf_size - len, s); + return buf; } -ST_FUNC char *pstrncpy(char *out, const char *in, size_t num) -{ - memcpy(out, in, num); - out[num] = '\0'; - return out; +ST_FUNC char *pstrncpy(char *out, const char *in, size_t num) { + memcpy(out, in, num); + out[num] = '\0'; + return out; } /* extract the basename of a file */ -PUB_FUNC char *tcc_basename(const char *name) -{ - char *p = strchr(name, 0); - - while (p > name && !IS_DIRSEP(p[-1])) - --p; - return p; +PUB_FUNC char *tcc_basename(const char *name) { + char *p = strchr(name, 0); + + while (p > name && !IS_DIRSEP(p[-1])) + --p; + return p; } /* extract extension part of a file * * (if no extension, return pointer to end-of-string) */ -PUB_FUNC char *tcc_fileextension (const char *name) -{ - char *b = tcc_basename(name); - char *e = strrchr(b, '.'); - return e ? e : strchr(b, 0); +PUB_FUNC char *tcc_fileextension(const char *name) { + char *b = tcc_basename(name); + char *e = strrchr(b, '.'); + return e ? e : strchr(b, 0); } -ST_FUNC char *tcc_load_text(int fd) -{ - int len = fs_lseek(fd, 0, SEEK_END); - char *buf = load_data(fd, 0, len + 1); - buf[len] = 0; - return buf; +ST_FUNC char *tcc_load_text(int fd) { + int len = fs_lseek(fd, 0, SEEK_END); + char *buf = load_data(fd, 0, len + 1); + buf[len] = 0; + return buf; } /********************************************************/ @@ -141,47 +130,39 @@ ST_FUNC char *tcc_load_text(int fd) // #undef malloc // #undef realloc -PUB_FUNC void tcc_free(void *ptr) -{ - bench_free(ptr); +PUB_FUNC void tcc_free(void *ptr) { bench_free(ptr); } + +PUB_FUNC void *tcc_malloc(unsigned long size) { + void *ptr; + ptr = bench_malloc(size); + if (!ptr && size) + _tcc_error("memory full (malloc)"); + return ptr; } -PUB_FUNC void *tcc_malloc(unsigned long size) -{ - void *ptr; - ptr = bench_malloc(size); - if (!ptr && size) - _tcc_error("memory full (malloc)"); - return ptr; +PUB_FUNC void *tcc_mallocz(unsigned long size) { + void *ptr; + ptr = tcc_malloc(size); + if (size) + memset(ptr, 0, size); + return ptr; } -PUB_FUNC void *tcc_mallocz(unsigned long size) -{ - void *ptr; - ptr = tcc_malloc(size); - if (size) - memset(ptr, 0, size); - return ptr; +PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size) { + void *ptr1; + ptr1 = bench_realloc(ptr, size); + if (!ptr1 && size) + _tcc_error("memory full (realloc)"); + return ptr1; } -PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size) -{ - void *ptr1; - ptr1 = bench_realloc(ptr, size); - if (!ptr1 && size) - _tcc_error("memory full (realloc)"); - return ptr1; +PUB_FUNC char *tcc_strdup(const char *str) { + char *ptr; + ptr = tcc_malloc(strlen(str) + 1); + strcpy(ptr, str); + return ptr; } -PUB_FUNC char *tcc_strdup(const char *str) -{ - char *ptr; - ptr = tcc_malloc(strlen(str) + 1); - strcpy(ptr, str); - return ptr; -} - - // #define free(p) use_tcc_free(p) // #define malloc(s) use_tcc_malloc(s) // #define realloc(p, s) use_tcc_realloc(p, s) @@ -189,861 +170,828 @@ PUB_FUNC char *tcc_strdup(const char *str) /********************************************************/ /* dynarrays */ -ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data) -{ - int nb, nb_alloc; - void **pp; +ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data) { + int nb, nb_alloc; + void **pp; - nb = *nb_ptr; - pp = *(void ***)ptab; - /* every power of two we double array size */ - if ((nb & (nb - 1)) == 0) { - if (!nb) - nb_alloc = 1; - else - nb_alloc = nb * 2; - pp = tcc_realloc(pp, nb_alloc * sizeof(void *)); - *(void***)ptab = pp; + nb = *nb_ptr; + pp = *(void ***)ptab; + /* every power of two we double array size */ + if ((nb & (nb - 1)) == 0) { + if (!nb) + nb_alloc = 1; + else + nb_alloc = nb * 2; + pp = tcc_realloc(pp, nb_alloc * sizeof(void *)); + *(void ***)ptab = pp; + } + pp[nb++] = data; + *nb_ptr = nb; +} + +ST_FUNC void dynarray_reset(void *pp, int *n) { + void **p; + for (p = *(void ***)pp; *n; ++p, --*n) + if (*p) + tcc_free(*p); + tcc_free(*(void **)pp); + *(void **)pp = NULL; +} + +static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, + const char *in) { + const char *p; + do { + int c; + CString str; + + cstr_new(&str); + for (p = in; c = *p, c != '\0' && c != PATHSEP[0]; ++p) { + if (c == '{' && p[1] && p[2] == '}') { + c = p[1], p += 2; + if (c == 'B') + cstr_cat(&str, s->tcc_lib_path, -1); + if (c == 'R') + cstr_cat(&str, CONFIG_SYSROOT, -1); + if (c == 'f' && file) { + /* substitute current file's dir */ + const char *f = file->true_filename; + const char *b = tcc_basename(f); + if (b > f) + cstr_cat(&str, f, b - f - 1); + else + cstr_cat(&str, ".", 1); + } + } else { + cstr_ccat(&str, c); + } } - pp[nb++] = data; - *nb_ptr = nb; -} - -ST_FUNC void dynarray_reset(void *pp, int *n) -{ - void **p; - for (p = *(void***)pp; *n; ++p, --*n) - if (*p) - tcc_free(*p); - tcc_free(*(void**)pp); - *(void**)pp = NULL; -} - -static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char *in) -{ - const char *p; - do { - int c; - CString str; - - cstr_new(&str); - for (p = in; c = *p, c != '\0' && c != PATHSEP[0]; ++p) { - if (c == '{' && p[1] && p[2] == '}') { - c = p[1], p += 2; - if (c == 'B') - cstr_cat(&str, s->tcc_lib_path, -1); - if (c == 'R') - cstr_cat(&str, CONFIG_SYSROOT, -1); - if (c == 'f' && file) { - /* substitute current file's dir */ - const char *f = file->true_filename; - const char *b = tcc_basename(f); - if (b > f) - cstr_cat(&str, f, b - f - 1); - else - cstr_cat(&str, ".", 1); - } - } else { - cstr_ccat(&str, c); - } - } - if (str.size) { - cstr_ccat(&str, '\0'); - dynarray_add(p_ary, p_nb_ary, tcc_strdup(str.data)); - } - cstr_free(&str); - in = p+1; - } while (*p); + if (str.size) { + cstr_ccat(&str, '\0'); + dynarray_add(p_ary, p_nb_ary, tcc_strdup(str.data)); + } + cstr_free(&str); + in = p + 1; + } while (*p); } /********************************************************/ /* warning / error */ /* warn_... option bits */ -#define WARN_ON 1 /* warning is on (-Woption) */ +#define WARN_ON 1 /* warning is on (-Woption) */ #define WARN_ERR 2 /* warning is an error (-Werror=option) */ #define WARN_NOE 4 /* warning is not an error (-Wno-error=option) */ /* error1() modes */ enum { ERROR_WARN, ERROR_NOABORT, ERROR_ERROR }; -static void error1(int mode, const char *fmt, va_list ap) -{ - BufferedFile **pf, *f; - TCCState *s1 = tcc_state; - CString cs; +static void error1(int mode, const char *fmt, va_list ap) { + BufferedFile **pf, *f; + TCCState *s1 = tcc_state; + CString cs; - cstr_new(&cs); + cstr_new(&cs); - if (s1 == NULL) - /* can happen only if called from tcc_malloc(): 'out of memory' */ - goto no_file; + if (s1 == NULL) + /* can happen only if called from tcc_malloc(): 'out of memory' */ + goto no_file; - tcc_exit_state(s1); + tcc_exit_state(s1); - if (mode == ERROR_WARN) { - if (s1->warn_error) - mode = ERROR_ERROR; - if (s1->warn_num) { - /* handle tcc_warning_c(warn_option)(fmt, ...) */ - int wopt = *(&s1->warn_none + s1->warn_num); - s1->warn_num = 0; - if (0 == (wopt & WARN_ON)) - return; - if (wopt & WARN_ERR) - mode = ERROR_ERROR; - if (wopt & WARN_NOE) - mode = ERROR_WARN; - } - if (s1->warn_none) - return; + if (mode == ERROR_WARN) { + if (s1->warn_error) + mode = ERROR_ERROR; + if (s1->warn_num) { + /* handle tcc_warning_c(warn_option)(fmt, ...) */ + int wopt = *(&s1->warn_none + s1->warn_num); + s1->warn_num = 0; + if (0 == (wopt & WARN_ON)) + return; + if (wopt & WARN_ERR) + mode = ERROR_ERROR; + if (wopt & WARN_NOE) + mode = ERROR_WARN; } + if (s1->warn_none) + return; + } - f = NULL; - if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */ - /* use upper file if inline ":asm:" or token ":paste:" */ - for (f = file; f && f->filename[0] == ':'; f = f->prev) - ; - } - if (f) { - for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++) - cstr_printf(&cs, "In file included from %s:%d:\n", - (*pf)->filename, (*pf)->line_num - 1); - cstr_printf(&cs, "%s:%d: ", - f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL)); - } else if (s1->current_filename) { - cstr_printf(&cs, "%s: ", s1->current_filename); - } + f = NULL; + if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */ + /* use upper file if inline ":asm:" or token ":paste:" */ + for (f = file; f && f->filename[0] == ':'; f = f->prev) + ; + } + if (f) { + for (pf = s1->include_stack; pf < s1->include_stack_ptr; pf++) + cstr_printf(&cs, "In file included from %s:%d:\n", (*pf)->filename, + (*pf)->line_num - 1); + cstr_printf(&cs, "%s:%d: ", f->filename, + f->line_num - !!(tok_flags & TOK_FLAG_BOL)); + } else if (s1->current_filename) { + cstr_printf(&cs, "%s: ", s1->current_filename); + } no_file: - if (0 == cs.size) - cstr_printf(&cs, "tcc: "); - cstr_printf(&cs, mode == ERROR_WARN ? "warning: " : "error: "); - cstr_vprintf(&cs, fmt, ap); - if (!s1 || !s1->error_func) { - /* default case: stderr */ - if (s1 && s1->output_type == TCC_OUTPUT_PREPROCESS && s1->ppfp == FD_STDOUT) - printf("\n"); /* print a newline during tcc -E */ - // fflush(stdout); /* flush -v output */ - // fprintf(stderr, "%s\n", (char*)cs.data); - // fflush(stderr); /* print error/warning now (win32) */ - printf("%s\n", (char*)cs.data); + if (0 == cs.size) + cstr_printf(&cs, "tcc: "); + cstr_printf(&cs, mode == ERROR_WARN ? "warning: " : "error: "); + cstr_vprintf(&cs, fmt, ap); + if (!s1 || !s1->error_func) { + /* default case: stderr */ + if (s1 && s1->output_type == TCC_OUTPUT_PREPROCESS && s1->ppfp == FD_STDOUT) + printf("\n"); /* print a newline during tcc -E */ + // fflush(stdout); /* flush -v output */ + // fprintf(stderr, "%s\n", (char*)cs.data); + // fflush(stderr); /* print error/warning now (win32) */ + printf("%s\n", (char *)cs.data); - } else { - s1->error_func(s1->error_opaque, (char*)cs.data); + } else { + s1->error_func(s1->error_opaque, (char *)cs.data); + } + cstr_free(&cs); + if (s1) { + if (mode != ERROR_WARN) + s1->nb_errors++; + if (mode != ERROR_ERROR) + return; + if (s1->error_set_jmp_enabled) { } - cstr_free(&cs); - if (s1) { - if (mode != ERROR_WARN) - s1->nb_errors++; - if (mode != ERROR_ERROR) - return; - if (s1->error_set_jmp_enabled){} - // longjmp(s1->error_jmp_buf, 1); - } - // exit(1); - assert(0); + // longjmp(s1->error_jmp_buf, 1); + } + // exit(1); + assert(0); } -LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func) -{ - s->error_opaque = error_opaque; - s->error_func = error_func; +LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, + TCCErrorFunc error_func) { + s->error_opaque = error_opaque; + s->error_func = error_func; } -LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s) -{ - return s->error_func; -} +LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s) { return s->error_func; } -LIBTCCAPI void *tcc_get_error_opaque(TCCState *s) -{ - return s->error_opaque; -} +LIBTCCAPI void *tcc_get_error_opaque(TCCState *s) { return s->error_opaque; } /* error without aborting current compilation */ -PUB_FUNC void _tcc_error_noabort(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - error1(ERROR_NOABORT, fmt, ap); - va_end(ap); +PUB_FUNC void _tcc_error_noabort(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + error1(ERROR_NOABORT, fmt, ap); + va_end(ap); } -PUB_FUNC void _tcc_error(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - for (;;) error1(ERROR_ERROR, fmt, ap); +PUB_FUNC void _tcc_error(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + for (;;) + error1(ERROR_ERROR, fmt, ap); } -PUB_FUNC void _tcc_warning(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - error1(ERROR_WARN, fmt, ap); - va_end(ap); +PUB_FUNC void _tcc_warning(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + error1(ERROR_WARN, fmt, ap); + va_end(ap); } /********************************************************/ /* I/O layer */ -ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen) -{ - BufferedFile *bf; - int buflen = initlen ? initlen : IO_BUF_SIZE; +ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen) { + BufferedFile *bf; + int buflen = initlen ? initlen : IO_BUF_SIZE; - bf = tcc_mallocz(sizeof(BufferedFile) + buflen); - bf->buf_ptr = bf->buffer; - bf->buf_end = bf->buffer + initlen; - bf->buf_end[0] = CH_EOB; /* put eob symbol */ - pstrcpy(bf->filename, sizeof(bf->filename), filename); + bf = tcc_mallocz(sizeof(BufferedFile) + buflen); + bf->buf_ptr = bf->buffer; + bf->buf_end = bf->buffer + initlen; + bf->buf_end[0] = CH_EOB; /* put eob symbol */ + pstrcpy(bf->filename, sizeof(bf->filename), filename); #ifdef _WIN32 - normalize_slashes(bf->filename); + normalize_slashes(bf->filename); #endif - bf->true_filename = bf->filename; - bf->line_num = 1; - bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; - bf->fd = -1; - bf->prev = file; - file = bf; - tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; + bf->true_filename = bf->filename; + bf->line_num = 1; + bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; + bf->fd = -1; + bf->prev = file; + file = bf; + tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; } -ST_FUNC void tcc_close(void) -{ - TCCState *s1 = tcc_state; - BufferedFile *bf = file; - if (bf->fd > 0) { - fs_close(bf->fd); - total_lines += bf->line_num; - } - if (bf->true_filename != bf->filename) - tcc_free(bf->true_filename); - file = bf->prev; - tcc_free(bf); +ST_FUNC void tcc_close(void) { + TCCState *s1 = tcc_state; + BufferedFile *bf = file; + if (bf->fd > 0) { + fs_close(bf->fd); + total_lines += bf->line_num; + } + if (bf->true_filename != bf->filename) + tcc_free(bf->true_filename); + file = bf->prev; + tcc_free(bf); } -static int _tcc_open(TCCState *s1, const char *filename) -{ - int fd; - if (strcmp(filename, "-") == 0) - fd = 0, filename = ""; - else - fd = fs_open(filename, 0, 0); - if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3) - printf("%s %*s%s\n", fd < 0 ? "nf":"->", - (int)(s1->include_stack_ptr - s1->include_stack), "", filename); - return fd; +static int _tcc_open(TCCState *s1, const char *filename) { + int fd; + if (strcmp(filename, "-") == 0) + fd = 0, filename = ""; + else + fd = fs_open(filename, 0, 0); + if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3) + printf("%s %*s%s\n", fd < 0 ? "nf" : "->", + (int)(s1->include_stack_ptr - s1->include_stack), "", filename); + return fd; } -ST_FUNC int tcc_open(TCCState *s1, const char *filename) -{ - int fd = _tcc_open(s1, filename); - if (fd < 0) - return -1; - tcc_open_bf(s1, filename, 0); - file->fd = fd; - return 0; +ST_FUNC int tcc_open(TCCState *s1, const char *filename) { + int fd = _tcc_open(s1, filename); + if (fd < 0) + return -1; + tcc_open_bf(s1, filename, 0); + file->fd = fd; + return 0; } /* compile the file opened in 'file'. Return non zero if errors. */ -static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) -{ - /* Here we enter the code section where we use the global variables for - parsing and code generation (tccpp.c, tccgen.c, -gen.c). - Other threads need to wait until we're done. +static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) { + /* Here we enter the code section where we use the global variables for + parsing and code generation (tccpp.c, tccgen.c, -gen.c). + Other threads need to wait until we're done. - Alternatively we could use thread local storage for those global - variables, which may or may not have advantages */ + Alternatively we could use thread local storage for those global + variables, which may or may not have advantages */ - tcc_enter_state(s1); - s1->error_set_jmp_enabled = 1; + tcc_enter_state(s1); + s1->error_set_jmp_enabled = 1; - if (1/*setjmp(s1->error_jmp_buf) == 0*/) { - s1->nb_errors = 0; + if (1 /*setjmp(s1->error_jmp_buf) == 0*/) { + s1->nb_errors = 0; - if (fd == -1) { - int len = strlen(str); - tcc_open_bf(s1, "", len); - memcpy(file->buffer, str, len); - } else { - tcc_open_bf(s1, str, 0); - file->fd = fd; - } - - preprocess_start(s1, filetype); - tccgen_init(s1); - - if (s1->output_type == TCC_OUTPUT_PREPROCESS) { - tcc_preprocess(s1); - } else { - tccelf_begin_file(s1); - if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) { - tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP)); - } else { - tccgen_compile(s1); - } - tccelf_end_file(s1); - } + if (fd == -1) { + int len = strlen(str); + tcc_open_bf(s1, "", len); + memcpy(file->buffer, str, len); + } else { + tcc_open_bf(s1, str, 0); + file->fd = fd; } - tccgen_finish(s1); - preprocess_end(s1); - s1->error_set_jmp_enabled = 0; - tcc_exit_state(s1); - return s1->nb_errors != 0 ? -1 : 0; + + preprocess_start(s1, filetype); + tccgen_init(s1); + + if (s1->output_type == TCC_OUTPUT_PREPROCESS) { + tcc_preprocess(s1); + } else { + tccelf_begin_file(s1); + if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) { + tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP)); + } else { + tccgen_compile(s1); + } + tccelf_end_file(s1); + } + } + tccgen_finish(s1); + preprocess_end(s1); + s1->error_set_jmp_enabled = 0; + tcc_exit_state(s1); + return s1->nb_errors != 0 ? -1 : 0; } -LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str) -{ - return tcc_compile(s, s->filetype, str, -1); +LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str) { + return tcc_compile(s, s->filetype, str, -1); } /* define a preprocessor symbol. value can be NULL, sym can be "sym=val" */ -LIBTCCAPI void tcc_define_symbol(TCCState *s1, const char *sym, const char *value) -{ - const char *eq; - if (NULL == (eq = strchr(sym, '='))) - eq = strchr(sym, 0); - if (NULL == value) - value = *eq ? eq + 1 : "1"; - cstr_printf(&s1->cmdline_defs, "#define %.*s %s\n", (int)(eq-sym), sym, value); +LIBTCCAPI void tcc_define_symbol(TCCState *s1, const char *sym, + const char *value) { + const char *eq; + if (NULL == (eq = strchr(sym, '='))) + eq = strchr(sym, 0); + if (NULL == value) + value = *eq ? eq + 1 : "1"; + cstr_printf(&s1->cmdline_defs, "#define %.*s %s\n", (int)(eq - sym), sym, + value); } /* undefine a preprocessor symbol */ -LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym) -{ - cstr_printf(&s1->cmdline_defs, "#undef %s\n", sym); +LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym) { + cstr_printf(&s1->cmdline_defs, "#undef %s\n", sym); } +LIBTCCAPI TCCState *tcc_new(void) { + TCCState *s; -LIBTCCAPI TCCState *tcc_new(void) -{ - TCCState *s; - - s = tcc_mallocz(sizeof(TCCState)); - if (!s) - return NULL; + s = tcc_mallocz(sizeof(TCCState)); + if (!s) + return NULL; #ifdef MEM_DEBUG - ++nb_states; + ++nb_states; #endif #undef gnu_ext - s->gnu_ext = 1; - s->tcc_ext = 1; - s->nocommon = 1; - s->dollars_in_identifiers = 1; /*on by default like in gcc/clang*/ - s->cversion = 199901; /* default unless -std=c11 is supplied */ - s->warn_implicit_function_declaration = 1; - s->warn_discarded_qualifiers = 1; - s->ms_extensions = 1; + s->gnu_ext = 1; + s->tcc_ext = 1; + s->nocommon = 1; + s->dollars_in_identifiers = 1; /*on by default like in gcc/clang*/ + s->cversion = 199901; /* default unless -std=c11 is supplied */ + s->warn_implicit_function_declaration = 1; + s->warn_discarded_qualifiers = 1; + s->ms_extensions = 1; #ifdef CHAR_IS_UNSIGNED - s->char_is_unsigned = 1; + s->char_is_unsigned = 1; #endif #ifdef TCC_TARGET_I386 - s->seg_size = 32; + s->seg_size = 32; #endif - /* enable this if you want symbols with leading underscore on windows: */ -// #if defined TCC_TARGET_MACHO /* || defined TCC_TARGET_PE */ -// s->leading_underscore = 1; -// #endif -// #ifdef TCC_TARGET_ARM -// s->float_abi = ARM_FLOAT_ABI; -// #endif -// #ifdef CONFIG_NEW_DTAGS -// s->enable_new_dtags = 1; -// #endif - s->ppfp = FD_STDOUT; - /* might be used in error() before preprocess_start() */ - s->include_stack_ptr = s->include_stack; + /* enable this if you want symbols with leading underscore on windows: */ + // #if defined TCC_TARGET_MACHO /* || defined TCC_TARGET_PE */ + // s->leading_underscore = 1; + // #endif + // #ifdef TCC_TARGET_ARM + // s->float_abi = ARM_FLOAT_ABI; + // #endif + // #ifdef CONFIG_NEW_DTAGS + // s->enable_new_dtags = 1; + // #endif + s->ppfp = FD_STDOUT; + /* might be used in error() before preprocess_start() */ + s->include_stack_ptr = s->include_stack; - tcc_set_lib_path(s, CONFIG_TCCDIR); - return s; + tcc_set_lib_path(s, CONFIG_TCCDIR); + return s; } -LIBTCCAPI void tcc_delete(TCCState *s1) -{ - /* free sections */ - tccelf_delete(s1); +LIBTCCAPI void tcc_delete(TCCState *s1) { + /* free sections */ + tccelf_delete(s1); - /* free library paths */ - dynarray_reset(&s1->library_paths, &s1->nb_library_paths); - dynarray_reset(&s1->crt_paths, &s1->nb_crt_paths); + /* free library paths */ + dynarray_reset(&s1->library_paths, &s1->nb_library_paths); + dynarray_reset(&s1->crt_paths, &s1->nb_crt_paths); - /* free defsyms */ - dynarray_reset(&s1->defsyms, &s1->nb_defsyms); + /* free defsyms */ + dynarray_reset(&s1->defsyms, &s1->nb_defsyms); - /* free include paths */ - dynarray_reset(&s1->include_paths, &s1->nb_include_paths); - dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths); + /* free include paths */ + dynarray_reset(&s1->include_paths, &s1->nb_include_paths); + dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths); - tcc_free(s1->tcc_lib_path); - tcc_free(s1->soname); - tcc_free(s1->rpath); - tcc_free(s1->elf_entryname); - tcc_free(s1->init_symbol); - tcc_free(s1->fini_symbol); - tcc_free(s1->mapfile); - tcc_free(s1->outfile); - tcc_free(s1->deps_outfile); - dynarray_reset(&s1->files, &s1->nb_files); - dynarray_reset(&s1->target_deps, &s1->nb_target_deps); - dynarray_reset(&s1->pragma_libs, &s1->nb_pragma_libs); - dynarray_reset(&s1->argv, &s1->argc); - cstr_free(&s1->cmdline_defs); - cstr_free(&s1->cmdline_incl); + tcc_free(s1->tcc_lib_path); + tcc_free(s1->soname); + tcc_free(s1->rpath); + tcc_free(s1->elf_entryname); + tcc_free(s1->init_symbol); + tcc_free(s1->fini_symbol); + tcc_free(s1->mapfile); + tcc_free(s1->outfile); + tcc_free(s1->deps_outfile); + dynarray_reset(&s1->files, &s1->nb_files); + dynarray_reset(&s1->target_deps, &s1->nb_target_deps); + dynarray_reset(&s1->pragma_libs, &s1->nb_pragma_libs); + dynarray_reset(&s1->argv, &s1->argc); + cstr_free(&s1->cmdline_defs); + cstr_free(&s1->cmdline_incl); #ifdef TCC_IS_NATIVE - /* free runtime memory */ - tcc_run_free(s1); + /* free runtime memory */ + tcc_run_free(s1); #endif - tcc_free(s1->dState); - tcc_free(s1); + tcc_free(s1->dState); + tcc_free(s1); #ifdef MEM_DEBUG - if (0 == --nb_states) - tcc_memcheck(); + if (0 == --nb_states) + tcc_memcheck(); #endif } -LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) -{ +LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) { #ifdef CONFIG_TCC_PIE - if (output_type == TCC_OUTPUT_EXE) - output_type |= TCC_OUTPUT_DYN; + if (output_type == TCC_OUTPUT_EXE) + output_type |= TCC_OUTPUT_DYN; #endif - s->output_type = output_type; + s->output_type = output_type; - if (!s->nostdinc) { - /* default include paths */ - /* -isystem paths have already been handled */ - tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS); - } + if (!s->nostdinc) { + /* default include paths */ + /* -isystem paths have already been handled */ + tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS); + } - if (output_type == TCC_OUTPUT_PREPROCESS) { - s->do_debug = 0; - return 0; - } + if (output_type == TCC_OUTPUT_PREPROCESS) { + s->do_debug = 0; + return 0; + } - tccelf_new(s); - if (s->do_debug) { - /* add debug sections */ - tcc_debug_new(s); - } + tccelf_new(s); + if (s->do_debug) { + /* add debug sections */ + tcc_debug_new(s); + } #ifdef CONFIG_TCC_BCHECK - if (s->do_bounds_check) { - /* if bound checking, then add corresponding sections */ - tccelf_bounds_new(s); - } + if (s->do_bounds_check) { + /* if bound checking, then add corresponding sections */ + tccelf_bounds_new(s); + } #endif - if (output_type == TCC_OUTPUT_OBJ) { - /* always elf for objects */ - s->output_format = TCC_OUTPUT_FORMAT_ELF; - return 0; - } + if (output_type == TCC_OUTPUT_OBJ) { + /* always elf for objects */ + s->output_format = TCC_OUTPUT_FORMAT_ELF; + return 0; + } - tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); + tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); #ifdef TCC_TARGET_PE -# ifdef _WIN32 - /* allow linking with system dll's directly */ - tcc_add_systemdir(s); -# endif - /* target PE has its own startup code in libtcc1.a */ - return 0; +#ifdef _WIN32 + /* allow linking with system dll's directly */ + tcc_add_systemdir(s); +#endif + /* target PE has its own startup code in libtcc1.a */ + return 0; #elif defined TCC_TARGET_MACHO -# ifdef TCC_IS_NATIVE - tcc_add_macos_sdkpath(s); -# endif - /* Mach-O with LC_MAIN doesn't need any crt startup code. */ - return 0; +#ifdef TCC_IS_NATIVE + tcc_add_macos_sdkpath(s); +#endif + /* Mach-O with LC_MAIN doesn't need any crt startup code. */ + return 0; #else - /* paths for crt objects */ - tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX); + /* paths for crt objects */ + tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX); - /* add libc crt1/crti objects */ - if (output_type != TCC_OUTPUT_MEMORY && !s->nostdlib) { + /* add libc crt1/crti objects */ + if (output_type != TCC_OUTPUT_MEMORY && !s->nostdlib) { #if TARGETOS_OpenBSD - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crt0.o"); - if (output_type == TCC_OUTPUT_DLL) - tcc_add_crt(s, "crtbeginS.o"); - else - tcc_add_crt(s, "crtbegin.o"); + if (output_type != TCC_OUTPUT_DLL) + tcc_add_crt(s, "crt0.o"); + if (output_type == TCC_OUTPUT_DLL) + tcc_add_crt(s, "crtbeginS.o"); + else + tcc_add_crt(s, "crtbegin.o"); #elif TARGETOS_FreeBSD - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crt1.o"); - tcc_add_crt(s, "crti.o"); - if (s->static_link) - tcc_add_crt(s, "crtbeginT.o"); - else if (output_type & TCC_OUTPUT_DYN) - tcc_add_crt(s, "crtbeginS.o"); - else - tcc_add_crt(s, "crtbegin.o"); + if (output_type != TCC_OUTPUT_DLL) + tcc_add_crt(s, "crt1.o"); + tcc_add_crt(s, "crti.o"); + if (s->static_link) + tcc_add_crt(s, "crtbeginT.o"); + else if (output_type & TCC_OUTPUT_DYN) + tcc_add_crt(s, "crtbeginS.o"); + else + tcc_add_crt(s, "crtbegin.o"); #elif TARGETOS_NetBSD - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crt0.o"); - tcc_add_crt(s, "crti.o"); - if (s->static_link) - tcc_add_crt(s, "crtbeginT.o"); - else if (output_type & TCC_OUTPUT_DYN) - tcc_add_crt(s, "crtbeginS.o"); - else - tcc_add_crt(s, "crtbegin.o"); + if (output_type != TCC_OUTPUT_DLL) + tcc_add_crt(s, "crt0.o"); + tcc_add_crt(s, "crti.o"); + if (s->static_link) + tcc_add_crt(s, "crtbeginT.o"); + else if (output_type & TCC_OUTPUT_DYN) + tcc_add_crt(s, "crtbeginS.o"); + else + tcc_add_crt(s, "crtbegin.o"); #elif defined TARGETOS_ANDROID - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crtbegin_dynamic.o"); - else - tcc_add_crt(s, "crtbegin_so.o"); + if (output_type != TCC_OUTPUT_DLL) + tcc_add_crt(s, "crtbegin_dynamic.o"); + else + tcc_add_crt(s, "crtbegin_so.o"); #else - if (output_type != TCC_OUTPUT_DLL) - tcc_add_crt(s, "crt1.o"); - tcc_add_crt(s, "crti.o"); + if (output_type != TCC_OUTPUT_DLL) + tcc_add_crt(s, "crt1.o"); + tcc_add_crt(s, "crti.o"); #endif - } - return 0; + } + return 0; #endif } -LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname) -{ - tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname); - return 0; +LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname) { + tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname); + return 0; } -LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname) -{ - tcc_split_path(s, &s->sysinclude_paths, &s->nb_sysinclude_paths, pathname); - return 0; +LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname) { + tcc_split_path(s, &s->sysinclude_paths, &s->nb_sysinclude_paths, pathname); + return 0; } /* add/update a 'DLLReference', Just find if level == -1 */ -ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname, int level) -{ - DLLReference *ref = NULL; - int i; - for (i = 0; i < s1->nb_loaded_dlls; i++) - if (0 == strcmp(s1->loaded_dlls[i]->name, dllname)) { - ref = s1->loaded_dlls[i]; - break; - } - if (level == -1) - return ref; - if (ref) { - if (level < ref->level) - ref->level = level; - ref->found = 1; - return ref; +ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname, + int level) { + DLLReference *ref = NULL; + int i; + for (i = 0; i < s1->nb_loaded_dlls; i++) + if (0 == strcmp(s1->loaded_dlls[i]->name, dllname)) { + ref = s1->loaded_dlls[i]; + break; } - ref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname)); - strcpy(ref->name, dllname); - dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, ref); - ref->level = level; - ref->index = s1->nb_loaded_dlls; + if (level == -1) return ref; + if (ref) { + if (level < ref->level) + ref->level = level; + ref->found = 1; + return ref; + } + ref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname)); + strcpy(ref->name, dllname); + dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, ref); + ref->level = level; + ref->index = s1->nb_loaded_dlls; + return ref; } /* OpenBSD: choose latest from libxxx.so.x.y versions */ #if defined TARGETOS_OpenBSD && !defined _WIN32 #include -static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size) -{ - const char *star; - glob_t g; - char *p; - int i, v, v1, v2, v3; +static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size) { + const char *star; + glob_t g; + char *p; + int i, v, v1, v2, v3; - star = strchr(pattern, '*'); - if (!star || glob(pattern, 0, NULL, &g)) - return -1; - for (v = -1, i = 0; i < g.gl_pathc; ++i) { - p = g.gl_pathv[i]; - if (2 != sscanf(p + (star - pattern), "%d.%d.%d", &v1, &v2, &v3)) - continue; - if ((v1 = v1 * 1000 + v2) > v) - v = v1, pstrcpy(buf, size, p); - } - globfree(&g); - return v; + star = strchr(pattern, '*'); + if (!star || glob(pattern, 0, NULL, &g)) + return -1; + for (v = -1, i = 0; i < g.gl_pathc; ++i) { + p = g.gl_pathv[i]; + if (2 != sscanf(p + (star - pattern), "%d.%d.%d", &v1, &v2, &v3)) + continue; + if ((v1 = v1 * 1000 + v2) > v) + v = v1, pstrcpy(buf, size, p); + } + globfree(&g); + return v; } #endif -ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) -{ - int fd, ret = -1; +ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, + int flags) { + int fd, ret = -1; #if defined TARGETOS_OpenBSD && !defined _WIN32 - char buf[1024]; - if (tcc_glob_so(s1, filename, buf, sizeof buf) >= 0) - filename = buf; + char buf[1024]; + if (tcc_glob_so(s1, filename, buf, sizeof buf) >= 0) + filename = buf; #endif - /* ignore binary files with -E */ - if (s1->output_type == TCC_OUTPUT_PREPROCESS - && (flags & AFF_TYPE_BIN)) - return 0; + /* ignore binary files with -E */ + if (s1->output_type == TCC_OUTPUT_PREPROCESS && (flags & AFF_TYPE_BIN)) + return 0; - /* open the file */ - fd = _tcc_open(s1, filename); - if (fd < 0) { - if (flags & AFF_PRINT_ERROR) - tcc_error_noabort("file '%s' not found", filename); - return ret; - } + /* open the file */ + fd = _tcc_open(s1, filename); + if (fd < 0) { + if (flags & AFF_PRINT_ERROR) + tcc_error_noabort("file '%s' not found", filename); + return ret; + } - s1->current_filename = filename; - if (flags & AFF_TYPE_BIN) { - ElfW(Ehdr) ehdr; - int obj_type; + s1->current_filename = filename; + if (flags & AFF_TYPE_BIN) { + ElfW(Ehdr) ehdr; + int obj_type; - obj_type = tcc_object_type(fd, &ehdr); - fs_lseek(fd, 0, SEEK_SET); + obj_type = tcc_object_type(fd, &ehdr); + fs_lseek(fd, 0, SEEK_SET); - switch (obj_type) { + switch (obj_type) { - case AFF_BINTYPE_REL: - ret = tcc_load_object_file(s1, fd, 0); - break; + case AFF_BINTYPE_REL: + ret = tcc_load_object_file(s1, fd, 0); + break; - case AFF_BINTYPE_AR: - ret = tcc_load_archive(s1, fd, !(flags & AFF_WHOLE_ARCHIVE)); - break; + case AFF_BINTYPE_AR: + ret = tcc_load_archive(s1, fd, !(flags & AFF_WHOLE_ARCHIVE)); + break; #ifdef TCC_TARGET_PE - default: - ret = pe_load_file(s1, fd, filename); - goto check_success; + default: + ret = pe_load_file(s1, fd, filename); + goto check_success; #elif defined TCC_TARGET_MACHO - case AFF_BINTYPE_DYN: - case_dyn_or_tbd: - if (s1->output_type == TCC_OUTPUT_MEMORY) { + case AFF_BINTYPE_DYN: + case_dyn_or_tbd: + if (s1->output_type == TCC_OUTPUT_MEMORY) { #ifdef TCC_IS_NATIVE - void* dl; - const char* soname = filename; - if (obj_type != AFF_BINTYPE_DYN) - soname = macho_tbd_soname(filename); - dl = dlopen(soname, RTLD_GLOBAL | RTLD_LAZY); - if (dl) - tcc_add_dllref(s1, soname, 0)->handle = dl, ret = 0; - if (filename != soname) - tcc_free((void *)soname); + void *dl; + const char *soname = filename; + if (obj_type != AFF_BINTYPE_DYN) + soname = macho_tbd_soname(filename); + dl = dlopen(soname, RTLD_GLOBAL | RTLD_LAZY); + if (dl) + tcc_add_dllref(s1, soname, 0)->handle = dl, ret = 0; + if (filename != soname) + tcc_free((void *)soname); #endif - } else if (obj_type == AFF_BINTYPE_DYN) { - ret = macho_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0); - } else { - ret = macho_load_tbd(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0); - } - break; - default: - { - const char *ext = tcc_fileextension(filename); - if (!strcmp(ext, ".tbd")) - goto case_dyn_or_tbd; - if (!strcmp(ext, ".dylib")) { - obj_type = AFF_BINTYPE_DYN; - goto case_dyn_or_tbd; - } - goto check_success; - } + } else if (obj_type == AFF_BINTYPE_DYN) { + ret = + macho_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0); + } else { + ret = + macho_load_tbd(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0); + } + break; + default: { + const char *ext = tcc_fileextension(filename); + if (!strcmp(ext, ".tbd")) + goto case_dyn_or_tbd; + if (!strcmp(ext, ".dylib")) { + obj_type = AFF_BINTYPE_DYN; + goto case_dyn_or_tbd; + } + goto check_success; + } #else /* unix */ - case AFF_BINTYPE_DYN: - if (s1->output_type == TCC_OUTPUT_MEMORY) { + case AFF_BINTYPE_DYN: + if (s1->output_type == TCC_OUTPUT_MEMORY) { #ifdef TCC_IS_NATIVE - void* dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY); - if (dl) - tcc_add_dllref(s1, filename, 0)->handle = dl, ret = 0; + void *dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY); + if (dl) + tcc_add_dllref(s1, filename, 0)->handle = dl, ret = 0; #endif - } else - ret = tcc_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0); - break; + } else + ret = tcc_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0); + break; - default: - /* as GNU ld, consider it is an ld script if not recognized */ - ret = tcc_load_ldscript(s1, fd); - goto check_success; + default: + /* as GNU ld, consider it is an ld script if not recognized */ + ret = tcc_load_ldscript(s1, fd); + goto check_success; #endif /* pe / macos / unix */ -check_success: - if (ret < 0) - tcc_error_noabort("%s: unrecognized file type", filename); - break; + check_success: + if (ret < 0) + tcc_error_noabort("%s: unrecognized file type", filename); + break; #ifdef TCC_TARGET_COFF - case AFF_BINTYPE_C67: - ret = tcc_load_coff(s1, fd); - break; + case AFF_BINTYPE_C67: + ret = tcc_load_coff(s1, fd); + break; #endif - } - fs_close(fd); + } + fs_close(fd); + } else { + /* update target deps */ + dynarray_add(&s1->target_deps, &s1->nb_target_deps, tcc_strdup(filename)); + ret = tcc_compile(s1, flags, filename, fd); + } + s1->current_filename = NULL; + return ret; +} + +LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename) { + int filetype = s->filetype; + if (0 == (filetype & AFF_TYPE_MASK)) { + /* use a file extension to detect a filetype */ + const char *ext = tcc_fileextension(filename); + if (ext[0]) { + ext++; + if (!strcmp(ext, "S")) + filetype = AFF_TYPE_ASMPP; + else if (!strcmp(ext, "s")) + filetype = AFF_TYPE_ASM; + else if (!PATHCMP(ext, "c") || !PATHCMP(ext, "h") || !PATHCMP(ext, "i")) + filetype = AFF_TYPE_C; + else + filetype |= AFF_TYPE_BIN; } else { - /* update target deps */ - dynarray_add(&s1->target_deps, &s1->nb_target_deps, tcc_strdup(filename)); - ret = tcc_compile(s1, flags, filename, fd); + filetype = AFF_TYPE_C; } - s1->current_filename = NULL; - return ret; + } + return tcc_add_file_internal(s, filename, filetype | AFF_PRINT_ERROR); } -LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename) -{ - int filetype = s->filetype; - if (0 == (filetype & AFF_TYPE_MASK)) { - /* use a file extension to detect a filetype */ - const char *ext = tcc_fileextension(filename); - if (ext[0]) { - ext++; - if (!strcmp(ext, "S")) - filetype = AFF_TYPE_ASMPP; - else if (!strcmp(ext, "s")) - filetype = AFF_TYPE_ASM; - else if (!PATHCMP(ext, "c") - || !PATHCMP(ext, "h") - || !PATHCMP(ext, "i")) - filetype = AFF_TYPE_C; - else - filetype |= AFF_TYPE_BIN; - } else { - filetype = AFF_TYPE_C; - } - } - return tcc_add_file_internal(s, filename, filetype | AFF_PRINT_ERROR); -} - -LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname) -{ - tcc_split_path(s, &s->library_paths, &s->nb_library_paths, pathname); - return 0; +LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname) { + tcc_split_path(s, &s->library_paths, &s->nb_library_paths, pathname); + return 0; } static int tcc_add_library_internal(TCCState *s, const char *fmt, - const char *filename, int flags, char **paths, int nb_paths) -{ - char buf[1024]; - int i; + const char *filename, int flags, + char **paths, int nb_paths) { + char buf[1024]; + int i; - for(i = 0; i < nb_paths; i++) { - snprintf(buf, sizeof(buf), fmt, paths[i], filename); - if (tcc_add_file_internal(s, buf, flags | AFF_TYPE_BIN) == 0) - return 0; - } - return -1; + for (i = 0; i < nb_paths; i++) { + snprintf(buf, sizeof(buf), fmt, paths[i], filename); + if (tcc_add_file_internal(s, buf, flags | AFF_TYPE_BIN) == 0) + return 0; + } + return -1; } /* find and load a dll. Return non zero if not found */ -ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags) -{ - return tcc_add_library_internal(s, "%s/%s", filename, flags, - s->library_paths, s->nb_library_paths); +ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags) { + return tcc_add_library_internal(s, "%s/%s", filename, flags, s->library_paths, + s->nb_library_paths); } /* find [cross-]libtcc1.a and tcc helper objects in library path */ -ST_FUNC void tcc_add_support(TCCState *s1, const char *filename) -{ - char buf[100]; - if (CONFIG_TCC_CROSSPREFIX[0]) - filename = strcat(strcpy(buf, CONFIG_TCC_CROSSPREFIX), filename); - if (tcc_add_dll(s1, filename, 0) < 0) - tcc_error_noabort("%s not found", filename); +ST_FUNC void tcc_add_support(TCCState *s1, const char *filename) { + char buf[100]; + if (CONFIG_TCC_CROSSPREFIX[0]) + filename = strcat(strcpy(buf, CONFIG_TCC_CROSSPREFIX), filename); + if (tcc_add_dll(s1, filename, 0) < 0) + tcc_error_noabort("%s not found", filename); } #if !defined TCC_TARGET_PE && !defined TCC_TARGET_MACHO -ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename) -{ - if (-1 == tcc_add_library_internal(s1, "%s/%s", - filename, 0, s1->crt_paths, s1->nb_crt_paths)) - tcc_error_noabort("file '%s' not found", filename); - return 0; +ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename) { + if (-1 == tcc_add_library_internal(s1, "%s/%s", filename, 0, s1->crt_paths, + s1->nb_crt_paths)) + tcc_error_noabort("file '%s' not found", filename); + return 0; } #endif /* the library name is the same as the argument of the '-l' option */ -LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) -{ +LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) { #if defined TCC_TARGET_PE - static const char * const libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL }; - const char * const *pp = s->static_link ? libs + 4 : libs; + static const char *const libs[] = {"%s/%s.def", "%s/lib%s.def", + "%s/%s.dll", "%s/lib%s.dll", + "%s/lib%s.a", NULL}; + const char *const *pp = s->static_link ? libs + 4 : libs; #elif defined TCC_TARGET_MACHO - static const char * const libs[] = { "%s/lib%s.dylib", "%s/lib%s.tbd", "%s/lib%s.a", NULL }; - const char * const *pp = s->static_link ? libs + 2 : libs; + static const char *const libs[] = {"%s/lib%s.dylib", "%s/lib%s.tbd", + "%s/lib%s.a", NULL}; + const char *const *pp = s->static_link ? libs + 2 : libs; #elif defined TARGETOS_OpenBSD - static const char * const libs[] = { "%s/lib%s.so.*", "%s/lib%s.a", NULL }; - const char * const *pp = s->static_link ? libs + 1 : libs; + static const char *const libs[] = {"%s/lib%s.so.*", "%s/lib%s.a", NULL}; + const char *const *pp = s->static_link ? libs + 1 : libs; #else - static const char * const libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL }; - const char * const *pp = s->static_link ? libs + 1 : libs; + static const char *const libs[] = {"%s/lib%s.so", "%s/lib%s.a", NULL}; + const char *const *pp = s->static_link ? libs + 1 : libs; #endif - int flags = s->filetype & AFF_WHOLE_ARCHIVE; - while (*pp) { - if (0 == tcc_add_library_internal(s, *pp, - libraryname, flags, s->library_paths, s->nb_library_paths)) - return 0; - ++pp; - } - return -1; + int flags = s->filetype & AFF_WHOLE_ARCHIVE; + while (*pp) { + if (0 == tcc_add_library_internal(s, *pp, libraryname, flags, + s->library_paths, s->nb_library_paths)) + return 0; + ++pp; + } + return -1; } -PUB_FUNC int tcc_add_library_err(TCCState *s1, const char *libname) -{ - int ret = tcc_add_library(s1, libname); - if (ret < 0) - tcc_error_noabort("library '%s' not found", libname); - return ret; +PUB_FUNC int tcc_add_library_err(TCCState *s1, const char *libname) { + int ret = tcc_add_library(s1, libname); + if (ret < 0) + tcc_error_noabort("library '%s' not found", libname); + return ret; } /* handle #pragma comment(lib,) */ -ST_FUNC void tcc_add_pragma_libs(TCCState *s1) -{ - int i; - for (i = 0; i < s1->nb_pragma_libs; i++) - tcc_add_library_err(s1, s1->pragma_libs[i]); +ST_FUNC void tcc_add_pragma_libs(TCCState *s1) { + int i; + for (i = 0; i < s1->nb_pragma_libs; i++) + tcc_add_library_err(s1, s1->pragma_libs[i]); } -LIBTCCAPI int tcc_add_symbol(TCCState *s1, const char *name, const void *val) -{ +LIBTCCAPI int tcc_add_symbol(TCCState *s1, const char *name, const void *val) { #ifdef TCC_TARGET_PE - /* On x86_64 'val' might not be reachable with a 32bit offset. - So it is handled here as if it were in a DLL. */ - pe_putimport(s1, 0, name, (uintptr_t)val); + /* On x86_64 'val' might not be reachable with a 32bit offset. + So it is handled here as if it were in a DLL. */ + pe_putimport(s1, 0, name, (uintptr_t)val); #else - char buf[256]; - if (s1->leading_underscore) { - buf[0] = '_'; - pstrcpy(buf + 1, sizeof(buf) - 1, name); - name = buf; - } - set_global_sym(s1, name, NULL, (addr_t)(uintptr_t)val); /* NULL: SHN_ABS */ + char buf[256]; + if (s1->leading_underscore) { + buf[0] = '_'; + pstrcpy(buf + 1, sizeof(buf) - 1, name); + name = buf; + } + set_global_sym(s1, name, NULL, (addr_t)(uintptr_t)val); /* NULL: SHN_ABS */ #endif - return 0; + return 0; } -LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path) -{ - tcc_free(s->tcc_lib_path); - s->tcc_lib_path = tcc_strdup(path); +LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path) { + tcc_free(s->tcc_lib_path); + s->tcc_lib_path = tcc_strdup(path); } /********************************************************/ /* options parser */ -static int strstart(const char *val, const char **str) -{ - const char *p, *q; - p = *str; - q = val; - while (*q) { - if (*p != *q) - return 0; - p++; - q++; - } - *str = p; - return 1; +static int strstart(const char *val, const char **str) { + const char *p, *q; + p = *str; + q = val; + while (*q) { + if (*p != *q) + return 0; + p++; + q++; + } + *str = p; + return 1; } /* Like strstart, but automatically takes into account that ld options can @@ -1054,816 +1002,807 @@ static int strstart(const char *val, const char **str) * * you provide `val` always in 'option[=]' form (no leading -) */ -static int link_option(const char *str, const char *val, const char **ptr) -{ - const char *p, *q; - int ret; +static int link_option(const char *str, const char *val, const char **ptr) { + const char *p, *q; + int ret; - /* there should be 1 or 2 dashes */ - if (*str++ != '-') - return 0; - if (*str == '-') - str++; + /* there should be 1 or 2 dashes */ + if (*str++ != '-') + return 0; + if (*str == '-') + str++; - /* then str & val should match (potentially up to '=') */ - p = str; - q = val; + /* then str & val should match (potentially up to '=') */ + p = str; + q = val; - ret = 1; - if (q[0] == '?') { - ++q; - if (strstart("no-", &p)) - ret = -1; - } + ret = 1; + if (q[0] == '?') { + ++q; + if (strstart("no-", &p)) + ret = -1; + } - while (*q != '\0' && *q != '=') { - if (*p != *q) - return 0; - p++; - q++; - } + while (*q != '\0' && *q != '=') { + if (*p != *q) + return 0; + p++; + q++; + } - /* '=' near eos means ',' or '=' is ok */ - if (*q == '=') { - if (*p == 0) - *ptr = p; - if (*p != ',' && *p != '=') - return 0; - p++; - } else if (*p) { - return 0; - } - *ptr = p; - return ret; + /* '=' near eos means ',' or '=' is ok */ + if (*q == '=') { + if (*p == 0) + *ptr = p; + if (*p != ',' && *p != '=') + return 0; + p++; + } else if (*p) { + return 0; + } + *ptr = p; + return ret; } -static const char *skip_linker_arg(const char **str) -{ - const char *s1 = *str; - const char *s2 = strchr(s1, ','); - *str = s2 ? s2++ : (s2 = s1 + strlen(s1)); - return s2; +static const char *skip_linker_arg(const char **str) { + const char *s1 = *str; + const char *s2 = strchr(s1, ','); + *str = s2 ? s2++ : (s2 = s1 + strlen(s1)); + return s2; } -static void copy_linker_arg(char **pp, const char *s, int sep) -{ - const char *q = s; - char *p = *pp; - int l = 0; - if (p && sep) - p[l = strlen(p)] = sep, ++l; - skip_linker_arg(&q); - pstrncpy(l + (*pp = tcc_realloc(p, q - s + l + 1)), s, q - s); +static void copy_linker_arg(char **pp, const char *s, int sep) { + const char *q = s; + char *p = *pp; + int l = 0; + if (p && sep) + p[l = strlen(p)] = sep, ++l; + skip_linker_arg(&q); + pstrncpy(l + (*pp = tcc_realloc(p, q - s + l + 1)), s, q - s); } /* set linker options */ -static int tcc_set_linker(TCCState *s, const char *option) -{ - TCCState *s1 = s; - while (*option) { +static int tcc_set_linker(TCCState *s, const char *option) { + TCCState *s1 = s; + while (*option) { - const char *p = NULL; - char *end = NULL; - int ignoring = 0; - int ret; + const char *p = NULL; + char *end = NULL; + int ignoring = 0; + int ret; - if (link_option(option, "Bsymbolic", &p)) { - s->symbolic = 1; - } else if (link_option(option, "nostdlib", &p)) { - s->nostdlib = 1; - } else if (link_option(option, "e=", &p) - || link_option(option, "entry=", &p)) { - copy_linker_arg(&s->elf_entryname, p, 0); - } else if (link_option(option, "fini=", &p)) { - copy_linker_arg(&s->fini_symbol, p, 0); - ignoring = 1; - } else if (link_option(option, "image-base=", &p) - || link_option(option, "Ttext=", &p)) { - s->text_addr = strtoull(p, &end, 16); - s->has_text_addr = 1; - } else if (link_option(option, "data-base=", &p)) { - // Since we don't have linker script, add an ability to move data segment to a given location - s->data_addr = strtoull(p, &end, 16); - } else if (link_option(option, "defsym=", &p)) { - char *sym = tcc_mallocz(strlen(p)); - strcpy(sym, p); - // printf("Adding defsym %s\n", sym); - dynarray_add(&s->defsyms, &s->nb_defsyms, sym); - } else if (link_option(option, "init=", &p)) { - copy_linker_arg(&s->init_symbol, p, 0); - ignoring = 1; - } else if (link_option(option, "Map=", &p)) { - copy_linker_arg(&s->mapfile, p, 0); - ignoring = 1; - } else if (link_option(option, "oformat=", &p)) { + if (link_option(option, "Bsymbolic", &p)) { + s->symbolic = 1; + } else if (link_option(option, "nostdlib", &p)) { + s->nostdlib = 1; + } else if (link_option(option, "e=", &p) || + link_option(option, "entry=", &p)) { + copy_linker_arg(&s->elf_entryname, p, 0); + } else if (link_option(option, "fini=", &p)) { + copy_linker_arg(&s->fini_symbol, p, 0); + ignoring = 1; + } else if (link_option(option, "image-base=", &p) || + link_option(option, "Ttext=", &p)) { + s->text_addr = strtoull(p, &end, 16); + s->has_text_addr = 1; + } else if (link_option(option, "data-base=", &p)) { + // Since we don't have linker script, add an ability to move data segment + // to a given location + s->data_addr = strtoull(p, &end, 16); + } else if (link_option(option, "defsym=", &p)) { + char *sym = tcc_mallocz(strlen(p)); + strcpy(sym, p); + // printf("Adding defsym %s\n", sym); + dynarray_add(&s->defsyms, &s->nb_defsyms, sym); + } else if (link_option(option, "init=", &p)) { + copy_linker_arg(&s->init_symbol, p, 0); + ignoring = 1; + } else if (link_option(option, "Map=", &p)) { + copy_linker_arg(&s->mapfile, p, 0); + ignoring = 1; + } else if (link_option(option, "oformat=", &p)) { #if defined(TCC_TARGET_PE) - if (strstart("pe-", &p)) { + if (strstart("pe-", &p)) { #elif PTR_SIZE == 8 - if (strstart("elf64-", &p)) { + if (strstart("elf64-", &p)) { #else - if (strstart("elf32-", &p)) { + if (strstart("elf32-", &p)) { #endif - s->output_format = TCC_OUTPUT_FORMAT_ELF; - } else if (!strcmp(p, "binary")) { - s->output_format = TCC_OUTPUT_FORMAT_BINARY; + s->output_format = TCC_OUTPUT_FORMAT_ELF; + } else if (!strcmp(p, "binary")) { + s->output_format = TCC_OUTPUT_FORMAT_BINARY; #ifdef TCC_TARGET_COFF - } else if (!strcmp(p, "coff")) { - s->output_format = TCC_OUTPUT_FORMAT_COFF; + } else if (!strcmp(p, "coff")) { + s->output_format = TCC_OUTPUT_FORMAT_COFF; #endif - } else - goto err; + } else + goto err; - } else if (link_option(option, "as-needed", &p)) { - ignoring = 1; - } else if (link_option(option, "O", &p)) { - ignoring = 1; - } else if (link_option(option, "export-all-symbols", &p)) { - s->rdynamic = 1; - } else if (link_option(option, "export-dynamic", &p)) { - s->rdynamic = 1; - } else if (link_option(option, "rpath=", &p)) { - copy_linker_arg(&s->rpath, p, ':'); - } else if (link_option(option, "enable-new-dtags", &p)) { - s->enable_new_dtags = 1; - } else if (link_option(option, "section-alignment=", &p)) { - s->section_align = strtoul(p, &end, 16); - } else if (link_option(option, "soname=", &p)) { - copy_linker_arg(&s->soname, p, 0); + } else if (link_option(option, "as-needed", &p)) { + ignoring = 1; + } else if (link_option(option, "O", &p)) { + ignoring = 1; + } else if (link_option(option, "export-all-symbols", &p)) { + s->rdynamic = 1; + } else if (link_option(option, "export-dynamic", &p)) { + s->rdynamic = 1; + } else if (link_option(option, "rpath=", &p)) { + copy_linker_arg(&s->rpath, p, ':'); + } else if (link_option(option, "enable-new-dtags", &p)) { + s->enable_new_dtags = 1; + } else if (link_option(option, "section-alignment=", &p)) { + s->section_align = strtoul(p, &end, 16); + } else if (link_option(option, "soname=", &p)) { + copy_linker_arg(&s->soname, p, 0); #ifdef TCC_TARGET_PE - } else if (link_option(option, "large-address-aware", &p)) { - s->pe_characteristics |= 0x20; - } else if (link_option(option, "file-alignment=", &p)) { - s->pe_file_align = strtoul(p, &end, 16); - } else if (link_option(option, "stack=", &p)) { - s->pe_stack_size = strtoul(p, &end, 10); - } else if (link_option(option, "subsystem=", &p)) { + } else if (link_option(option, "large-address-aware", &p)) { + s->pe_characteristics |= 0x20; + } else if (link_option(option, "file-alignment=", &p)) { + s->pe_file_align = strtoul(p, &end, 16); + } else if (link_option(option, "stack=", &p)) { + s->pe_stack_size = strtoul(p, &end, 10); + } else if (link_option(option, "subsystem=", &p)) { #if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) - if (!strcmp(p, "native")) { - s->pe_subsystem = 1; - } else if (!strcmp(p, "console")) { - s->pe_subsystem = 3; - } else if (!strcmp(p, "gui") || !strcmp(p, "windows")) { - s->pe_subsystem = 2; - } else if (!strcmp(p, "posix")) { - s->pe_subsystem = 7; - } else if (!strcmp(p, "efiapp")) { - s->pe_subsystem = 10; - } else if (!strcmp(p, "efiboot")) { - s->pe_subsystem = 11; - } else if (!strcmp(p, "efiruntime")) { - s->pe_subsystem = 12; - } else if (!strcmp(p, "efirom")) { - s->pe_subsystem = 13; + if (!strcmp(p, "native")) { + s->pe_subsystem = 1; + } else if (!strcmp(p, "console")) { + s->pe_subsystem = 3; + } else if (!strcmp(p, "gui") || !strcmp(p, "windows")) { + s->pe_subsystem = 2; + } else if (!strcmp(p, "posix")) { + s->pe_subsystem = 7; + } else if (!strcmp(p, "efiapp")) { + s->pe_subsystem = 10; + } else if (!strcmp(p, "efiboot")) { + s->pe_subsystem = 11; + } else if (!strcmp(p, "efiruntime")) { + s->pe_subsystem = 12; + } else if (!strcmp(p, "efirom")) { + s->pe_subsystem = 13; #elif defined(TCC_TARGET_ARM) - if (!strcmp(p, "wince")) { - s->pe_subsystem = 9; + if (!strcmp(p, "wince")) { + s->pe_subsystem = 9; #endif - } else - goto err; + } else + goto err; #endif - } else if (ret = link_option(option, "?whole-archive", &p), ret) { - if (ret > 0) - s->filetype |= AFF_WHOLE_ARCHIVE; - else - s->filetype &= ~AFF_WHOLE_ARCHIVE; - } else if (link_option(option, "z=", &p)) { - ignoring = 1; - } else if (p) { - return 0; - } else { + } else if (ret = link_option(option, "?whole-archive", &p), ret) { + if (ret > 0) + s->filetype |= AFF_WHOLE_ARCHIVE; + else + s->filetype &= ~AFF_WHOLE_ARCHIVE; + } else if (link_option(option, "z=", &p)) { + ignoring = 1; + } else if (p) { + return 0; + } else { err: - tcc_error("unsupported linker option '%s'", option); - } - if (ignoring) - tcc_warning_c(warn_unsupported)("unsupported linker option '%s'", option); - option = skip_linker_arg(&p); + tcc_error("unsupported linker option '%s'", option); } - return 1; + if (ignoring) + tcc_warning_c(warn_unsupported)("unsupported linker option '%s'", option); + option = skip_linker_arg(&p); + } + return 1; } typedef struct TCCOption { - const char *name; - uint16_t index; - uint16_t flags; + const char *name; + uint16_t index; + uint16_t flags; } TCCOption; enum { - TCC_OPTION_ignored = 0, - TCC_OPTION_HELP, - TCC_OPTION_HELP2, - TCC_OPTION_v, - TCC_OPTION_I, - TCC_OPTION_D, - TCC_OPTION_U, - TCC_OPTION_P, - TCC_OPTION_L, - TCC_OPTION_B, - TCC_OPTION_l, - TCC_OPTION_bench, - TCC_OPTION_bt, - TCC_OPTION_b, - TCC_OPTION_ba, - TCC_OPTION_g, - TCC_OPTION_c, - TCC_OPTION_dumpversion, - TCC_OPTION_d, - TCC_OPTION_static, - TCC_OPTION_std, - TCC_OPTION_shared, - TCC_OPTION_soname, - TCC_OPTION_o, - TCC_OPTION_r, - TCC_OPTION_Wl, - TCC_OPTION_Wp, - TCC_OPTION_W, - TCC_OPTION_O, - TCC_OPTION_mfloat_abi, - TCC_OPTION_m, - TCC_OPTION_f, - TCC_OPTION_isystem, - TCC_OPTION_iwithprefix, - TCC_OPTION_include, - TCC_OPTION_nostdinc, - TCC_OPTION_nostdlib, - TCC_OPTION_print_search_dirs, - TCC_OPTION_rdynamic, - TCC_OPTION_pthread, - TCC_OPTION_run, - TCC_OPTION_w, - TCC_OPTION_E, - TCC_OPTION_M, - TCC_OPTION_MD, - TCC_OPTION_MF, - TCC_OPTION_MM, - TCC_OPTION_MMD, - TCC_OPTION_x, - TCC_OPTION_ar, - TCC_OPTION_impdef, + TCC_OPTION_ignored = 0, + TCC_OPTION_HELP, + TCC_OPTION_HELP2, + TCC_OPTION_v, + TCC_OPTION_I, + TCC_OPTION_D, + TCC_OPTION_U, + TCC_OPTION_P, + TCC_OPTION_L, + TCC_OPTION_B, + TCC_OPTION_l, + TCC_OPTION_bench, + TCC_OPTION_bt, + TCC_OPTION_b, + TCC_OPTION_ba, + TCC_OPTION_g, + TCC_OPTION_c, + TCC_OPTION_dumpversion, + TCC_OPTION_d, + TCC_OPTION_static, + TCC_OPTION_std, + TCC_OPTION_shared, + TCC_OPTION_soname, + TCC_OPTION_o, + TCC_OPTION_r, + TCC_OPTION_Wl, + TCC_OPTION_Wp, + TCC_OPTION_W, + TCC_OPTION_O, + TCC_OPTION_mfloat_abi, + TCC_OPTION_m, + TCC_OPTION_f, + TCC_OPTION_isystem, + TCC_OPTION_iwithprefix, + TCC_OPTION_include, + TCC_OPTION_nostdinc, + TCC_OPTION_nostdlib, + TCC_OPTION_print_search_dirs, + TCC_OPTION_rdynamic, + TCC_OPTION_pthread, + TCC_OPTION_run, + TCC_OPTION_w, + TCC_OPTION_E, + TCC_OPTION_M, + TCC_OPTION_MD, + TCC_OPTION_MF, + TCC_OPTION_MM, + TCC_OPTION_MMD, + TCC_OPTION_x, + TCC_OPTION_ar, + TCC_OPTION_impdef, }; #define TCC_OPTION_HAS_ARG 0x0001 -#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */ +#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */ static const TCCOption tcc_options[] = { - { "h", TCC_OPTION_HELP, 0 }, - { "-help", TCC_OPTION_HELP, 0 }, - { "?", TCC_OPTION_HELP, 0 }, - { "hh", TCC_OPTION_HELP2, 0 }, - { "v", TCC_OPTION_v, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "-version", TCC_OPTION_v, 0 }, /* handle as verbose, also prints version*/ - { "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG }, - { "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG }, - { "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG }, - { "P", TCC_OPTION_P, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "L", TCC_OPTION_L, TCC_OPTION_HAS_ARG }, - { "B", TCC_OPTION_B, TCC_OPTION_HAS_ARG }, - { "l", TCC_OPTION_l, TCC_OPTION_HAS_ARG }, - { "bench", TCC_OPTION_bench, 0 }, + {"h", TCC_OPTION_HELP, 0}, + {"-help", TCC_OPTION_HELP, 0}, + {"?", TCC_OPTION_HELP, 0}, + {"hh", TCC_OPTION_HELP2, 0}, + {"v", TCC_OPTION_v, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"-version", TCC_OPTION_v, 0}, /* handle as verbose, also prints version*/ + {"I", TCC_OPTION_I, TCC_OPTION_HAS_ARG}, + {"D", TCC_OPTION_D, TCC_OPTION_HAS_ARG}, + {"U", TCC_OPTION_U, TCC_OPTION_HAS_ARG}, + {"P", TCC_OPTION_P, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"L", TCC_OPTION_L, TCC_OPTION_HAS_ARG}, + {"B", TCC_OPTION_B, TCC_OPTION_HAS_ARG}, + {"l", TCC_OPTION_l, TCC_OPTION_HAS_ARG}, + {"bench", TCC_OPTION_bench, 0}, #ifdef CONFIG_TCC_BACKTRACE - { "bt", TCC_OPTION_bt, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, + {"bt", TCC_OPTION_bt, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, #endif #ifdef CONFIG_TCC_BCHECK - { "b", TCC_OPTION_b, 0 }, + {"b", TCC_OPTION_b, 0}, #endif - { "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "c", TCC_OPTION_c, 0 }, - { "dumpversion", TCC_OPTION_dumpversion, 0}, - { "d", TCC_OPTION_d, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "static", TCC_OPTION_static, 0 }, - { "std", TCC_OPTION_std, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "shared", TCC_OPTION_shared, 0 }, - { "soname", TCC_OPTION_soname, TCC_OPTION_HAS_ARG }, - { "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG }, - { "pthread", TCC_OPTION_pthread, 0}, - { "run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "rdynamic", TCC_OPTION_rdynamic, 0 }, - { "r", TCC_OPTION_r, 0 }, - { "Wl,", TCC_OPTION_Wl, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "Wp,", TCC_OPTION_Wp, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "O", TCC_OPTION_O, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, + {"g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"c", TCC_OPTION_c, 0}, + {"dumpversion", TCC_OPTION_dumpversion, 0}, + {"d", TCC_OPTION_d, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"static", TCC_OPTION_static, 0}, + {"std", TCC_OPTION_std, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"shared", TCC_OPTION_shared, 0}, + {"soname", TCC_OPTION_soname, TCC_OPTION_HAS_ARG}, + {"o", TCC_OPTION_o, TCC_OPTION_HAS_ARG}, + {"pthread", TCC_OPTION_pthread, 0}, + {"run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"rdynamic", TCC_OPTION_rdynamic, 0}, + {"r", TCC_OPTION_r, 0}, + {"Wl,", TCC_OPTION_Wl, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"Wp,", TCC_OPTION_Wp, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"O", TCC_OPTION_O, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, #ifdef TCC_TARGET_ARM - { "mfloat-abi", TCC_OPTION_mfloat_abi, TCC_OPTION_HAS_ARG }, + {"mfloat-abi", TCC_OPTION_mfloat_abi, TCC_OPTION_HAS_ARG}, #endif - { "m", TCC_OPTION_m, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG }, - { "include", TCC_OPTION_include, TCC_OPTION_HAS_ARG }, - { "nostdinc", TCC_OPTION_nostdinc, 0 }, - { "nostdlib", TCC_OPTION_nostdlib, 0 }, - { "print-search-dirs", TCC_OPTION_print_search_dirs, 0 }, - { "w", TCC_OPTION_w, 0 }, - { "E", TCC_OPTION_E, 0}, - { "M", TCC_OPTION_M, 0}, - { "MD", TCC_OPTION_MD, 0}, - { "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG }, - { "MM", TCC_OPTION_MM, 0}, - { "MMD", TCC_OPTION_MMD, 0}, - { "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG }, - { "ar", TCC_OPTION_ar, 0}, + {"m", TCC_OPTION_m, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP}, + {"isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG}, + {"include", TCC_OPTION_include, TCC_OPTION_HAS_ARG}, + {"nostdinc", TCC_OPTION_nostdinc, 0}, + {"nostdlib", TCC_OPTION_nostdlib, 0}, + {"print-search-dirs", TCC_OPTION_print_search_dirs, 0}, + {"w", TCC_OPTION_w, 0}, + {"E", TCC_OPTION_E, 0}, + {"M", TCC_OPTION_M, 0}, + {"MD", TCC_OPTION_MD, 0}, + {"MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG}, + {"MM", TCC_OPTION_MM, 0}, + {"MMD", TCC_OPTION_MMD, 0}, + {"x", TCC_OPTION_x, TCC_OPTION_HAS_ARG}, + {"ar", TCC_OPTION_ar, 0}, #ifdef TCC_TARGET_PE - { "impdef", TCC_OPTION_impdef, 0}, + {"impdef", TCC_OPTION_impdef, 0}, #endif /* ignored (silently, except after -Wunsupported) */ - { "arch", 0, TCC_OPTION_HAS_ARG}, - { "C", 0, 0 }, - { "-param", 0, TCC_OPTION_HAS_ARG }, - { "pedantic", 0, 0 }, - { "pipe", 0, 0 }, - { "s", 0, 0 }, - { "traditional", 0, 0 }, - { NULL, 0, 0 }, + {"arch", 0, TCC_OPTION_HAS_ARG}, + {"C", 0, 0}, + {"-param", 0, TCC_OPTION_HAS_ARG}, + {"pedantic", 0, 0}, + {"pipe", 0, 0}, + {"s", 0, 0}, + {"traditional", 0, 0}, + {NULL, 0, 0}, }; typedef struct FlagDef { - uint16_t offset; - uint16_t flags; - const char *name; + uint16_t offset; + uint16_t flags; + const char *name; } FlagDef; -#define WD_ALL 0x0001 /* warning is activated when using -Wall */ +#define WD_ALL 0x0001 /* warning is activated when using -Wall */ #define FD_INVERT 0x0002 /* invert value before storing */ static const FlagDef options_W[] = { - { offsetof(TCCState, warn_all), WD_ALL, "all" }, - { offsetof(TCCState, warn_error), 0, "error" }, - { offsetof(TCCState, warn_write_strings), 0, "write-strings" }, - { offsetof(TCCState, warn_unsupported), 0, "unsupported" }, - { offsetof(TCCState, warn_implicit_function_declaration), WD_ALL, "implicit-function-declaration" }, - { offsetof(TCCState, warn_discarded_qualifiers), WD_ALL, "discarded-qualifiers" }, - { 0, 0, NULL } -}; + {offsetof(TCCState, warn_all), WD_ALL, "all"}, + {offsetof(TCCState, warn_error), 0, "error"}, + {offsetof(TCCState, warn_write_strings), 0, "write-strings"}, + {offsetof(TCCState, warn_unsupported), 0, "unsupported"}, + {offsetof(TCCState, warn_implicit_function_declaration), WD_ALL, + "implicit-function-declaration"}, + {offsetof(TCCState, warn_discarded_qualifiers), WD_ALL, + "discarded-qualifiers"}, + {0, 0, NULL}}; static const FlagDef options_f[] = { - { offsetof(TCCState, char_is_unsigned), 0, "unsigned-char" }, - { offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char" }, - { offsetof(TCCState, nocommon), FD_INVERT, "common" }, - { offsetof(TCCState, leading_underscore), 0, "leading-underscore" }, - { offsetof(TCCState, ms_extensions), 0, "ms-extensions" }, - { offsetof(TCCState, dollars_in_identifiers), 0, "dollars-in-identifiers" }, - { offsetof(TCCState, test_coverage), 0, "test-coverage" }, - { 0, 0, NULL } -}; + {offsetof(TCCState, char_is_unsigned), 0, "unsigned-char"}, + {offsetof(TCCState, char_is_unsigned), FD_INVERT, "signed-char"}, + {offsetof(TCCState, nocommon), FD_INVERT, "common"}, + {offsetof(TCCState, leading_underscore), 0, "leading-underscore"}, + {offsetof(TCCState, ms_extensions), 0, "ms-extensions"}, + {offsetof(TCCState, dollars_in_identifiers), 0, "dollars-in-identifiers"}, + {offsetof(TCCState, test_coverage), 0, "test-coverage"}, + {0, 0, NULL}}; static const FlagDef options_m[] = { - { offsetof(TCCState, ms_bitfields), 0, "ms-bitfields" }, + {offsetof(TCCState, ms_bitfields), 0, "ms-bitfields"}, #ifdef TCC_TARGET_X86_64 - { offsetof(TCCState, nosse), FD_INVERT, "sse" }, + {offsetof(TCCState, nosse), FD_INVERT, "sse"}, #endif - { 0, 0, NULL } -}; + {0, 0, NULL}}; -static int set_flag(TCCState *s, const FlagDef *flags, const char *name) -{ - int value, mask, ret; - const FlagDef *p; - const char *r; - unsigned char *f; +static int set_flag(TCCState *s, const FlagDef *flags, const char *name) { + int value, mask, ret; + const FlagDef *p; + const char *r; + unsigned char *f; - r = name, value = !strstart("no-", &r), mask = 0; + r = name, value = !strstart("no-", &r), mask = 0; - /* when called with options_W, look for -W[no-]error=