2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <utils/Compat.h>
26 #define IMAGE_MIN_THREADS 1
27 #define IMAGE_MAX_THREADS 128
31 #define FATAL(x...) { \
36 #define unlikely(x) __builtin_expect(!!(x), 0)
39 /* if true, decode file in place instead of creating a new output file */
41 /* if true, use memory mapping instead of copying all input into memory */
43 /* if true, assume input is a sparse file */
45 /* if true, print more verbose information to stderr */
47 const char *fec_filename;
50 /* the number of Reed-Solomon generator polynomial roots, also the number
51 of parity bytes generated for each N bytes in RS(M, N) */
53 /* for RS(M, N), N = M - roots */
63 uint8_t *fec_mmap_addr;
68 struct image_proc_ctx;
69 typedef void (*image_proc_func)(image_proc_ctx *);
71 struct image_proc_ctx {
82 extern bool image_load(const std::vector<std::string>& filename, image *ctx,
84 extern bool image_save(const std::string& filename, image *ctx);
86 extern bool image_ecc_new(const std::string& filename, image *ctx);
87 extern bool image_ecc_load(const std::string& filename, image *ctx);
88 extern bool image_ecc_save(image *ctx);
90 extern bool image_process(image_proc_func f, image *ctx);
92 extern void image_init(image *ctx);
93 extern void image_free(image *ctx);
95 inline uint8_t image_get_interleaved_byte(uint64_t i, image *ctx)
97 uint64_t offset = fec_ecc_interleave(i, ctx->rs_n, ctx->rounds);
99 if (unlikely(offset >= ctx->inp_size)) {
103 return ctx->input[offset];
106 inline void image_set_interleaved_byte(uint64_t i, image *ctx,
109 uint64_t offset = fec_ecc_interleave(i, ctx->rs_n, ctx->rounds);
111 if (unlikely(offset >= ctx->inp_size)) {
113 } else if (ctx->output && ctx->output[offset] != value) {
114 ctx->output[offset] = value;