MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / f_predict

Function f_predict

internal/cbm/pdf/pdf_obj.c:2245–2385  ·  view source on GitHub ↗

PNG (>= 10) and TIFF (2) predictors. false: parameters it cannot apply. */

Source from the content-addressed store, hash-verified

2243
2244/* PNG (>= 10) and TIFF (2) predictors. false: parameters it cannot apply. */
2245static bool f_predict(pdf_doc_t *d, pdf_val_t *parms, pdf_buf_t *io) {
2246 if (!parms || parms->kind != PV_DICT) {
2247 return true;
2248 }
2249 pdf_val_t *pv = pdf_dget(d, parms, "Predictor");
2250 double pred = 1;
2251 if (pv) {
2252 if (pv->kind != PV_NUM) {
2253 return false;
2254 }
2255 pred = pv->num == 0.0 ? 1 : pv->num;
2256 }
2257 if (pred == 1) {
2258 return true;
2259 }
2260 static const char *const keys[] = {"Colors", "BitsPerComponent", "Columns"};
2261 static const int64_t dflt[] = {1, 8, 1};
2262 int64_t prm[3];
2263 bool ints = true;
2264 for (int i = 0; i < 3; i++) {
2265 pdf_val_t *v = pdf_dget(d, parms, keys[i]);
2266 if (!v || (v->kind == PV_NUM && v->num == 0.0)) {
2267 prm[i] = dflt[i];
2268 } else if (v->kind != PV_NUM) {
2269 return false;
2270 } else {
2271 ints = ints && v->is_int;
2272 prm[i] = v->is_int ? v->inum : pdf_d2i(v->num);
2273 }
2274 }
2275 int64_t colors = prm[0];
2276 int64_t bpc = prm[1];
2277 int64_t cols = prm[2];
2278 if (pred < PDF_PNG_PRED && !(pred == PDF_TIFF_PRED && bpc == PDF_BITS_PER_BYTE)) {
2279 return true;
2280 }
2281 if (!ints) {
2282 return false;
2283 }
2284 /* products of hostile parameters: computed in double and bounded */
2285 double bits = (double)colors * (double)bpc;
2286 double rowd = floor((bits * (double)cols + 7) / PDF_BITS_PER_BYTE);
2287 double bppd = floor(bits / PDF_BITS_PER_BYTE);
2288 if (rowd > (double)PDF_MAX_STREAM_OUT) {
2289 return false;
2290 }
2291 int64_t rowlen = rowd < -2 ? -2 : (int64_t)rowd;
2292 int64_t bpp =
2293 bppd<1 ? 1 : bppd>(double) PDF_MAX_STREAM_OUT ? (int64_t)PDF_MAX_STREAM_OUT : (int64_t)bppd;
2294 if (pred >= PDF_PNG_PRED) {
2295 if (rowlen == -1) {
2296 return false;
2297 }
2298 pdf_buf_t out = {0};
2299 if (rowlen < 0) {
2300 buf_free(io);
2301 *io = out;
2302 return true;

Callers 1

decode_filtersFunction · 0.85

Calls 6

pdf_dgetFunction · 0.85
pdf_d2iFunction · 0.85
buf_freeFunction · 0.85
cbm_callocFunction · 0.85
buf_reserveFunction · 0.85
cbm_freeFunction · 0.85

Tested by

no test coverage detected