GRASS 8 Programmer's Manual 8.6.0dev(2026)-d2adb3a889
Loading...
Searching...
No Matches
quant.c
Go to the documentation of this file.
1/*!
2 * \file lib/raster/quant.c
3 *
4 * \brief Raster Library - Quantization rules.
5 *
6 * The quantization table is stored as a linear array. Rules are added
7 * starting from index 0. Redundant rules are not eliminated. Rules
8 * are tested from the highest index downto 0. There are two
9 * "infinite" rules. Support is provided to reverse the order of the
10 * rules.
11 *
12 * SPDX-FileCopyrightText: 1999-2009 GRASS Development Team
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 *
15 * \author USACERL and many others
16 */
17
18#include <stdlib.h>
19#include <grass/gis.h>
20#include <grass/raster.h>
21
22static int double_comp(const void *, const void *);
23
24#define USE_LOOKUP 1
25#define MAX_LOOKUP_TABLE_SIZE 2048
26#define NO_DATA (Rast_set_c_null_value(&tmp, 1), (CELL)tmp)
27
28#define NO_LEFT_INFINITE_RULE (!q->infiniteLeftSet)
29#define NO_RIGHT_INFINITE_RULE (!q->infiniteRightSet)
30#define NO_FINITE_RULE (q->nofRules <= 0)
31#define NO_EXPLICIT_RULE \
32 (NO_FINITE_RULE && NO_LEFT_INFINITE_RULE && NO_RIGHT_INFINITE_RULE)
33
34/*!
35 \brief Resets the number of defined rules and number of infinite rules to 0
36
37 \param q pointer to Quant structure to be reset
38 */
39void Rast_quant_clear(struct Quant *q)
40{
41 q->nofRules = 0;
43}
44
45/*!
46 \brief Resets and frees allocated memory
47
48 Resets the number of defined rules to 0 and free's space allocated
49 for rules. Calls Rast_quant_clear().
50
51 \param q pointer to Quant structure to be reset
52 */
53void Rast_quant_free(struct Quant *q)
54{
56
57 if (q->maxNofRules > 0)
58 G_free(q->table);
59 if (q->fp_lookup.active) {
60 G_free(q->fp_lookup.vals);
61 G_free(q->fp_lookup.rules);
62 q->fp_lookup.nalloc = 0;
63 q->fp_lookup.active = 0;
64 }
65 q->maxNofRules = 0;
66}
67
68/*!
69 * \brief Organized fp_lookup table.
70 *
71 * Organizes fp_lookup table for faster (logarithmic) lookup time
72 * G_quant_organize_fp_lookup() creates a list of min and max for
73 * each quant rule, sorts this list, and stores the pointer to quant
74 * rule that should be used in between any 2 numbers in this list.
75 * Also it stores extreme points for 2 infinite rules, if exist.
76 * After the call to G_quant_organize_fp_lookup()
77 * instead of linearly searching through list of rules to find
78 * a rule to apply, quant lookup will perform a binary search
79 * to find an interval containing floating point value, and then use
80 * the rule associated with this interval.
81 * when the value doesn't fall within any interval, check for the
82 * infinite rules.
83 *
84 * \param q pointer to Quant structure which holds quant rules info
85 *
86 * \return 1 on success
87 */
89{
90 int i;
91 DCELL val;
92 CELL tmp;
93 struct Quant_table *p;
94
96 return -1;
97 if (q->nofRules == 0)
98 return -1;
99 q->fp_lookup.vals = (DCELL *)G_calloc(q->nofRules * 2, sizeof(DCELL));
100 /* 2 endpoints for each rule */
101 q->fp_lookup.rules = (struct Quant_table **)G_calloc(
102 q->nofRules * 2, sizeof(struct Quant_table *));
103
104 /* first we organize finite rules into a table */
105 if (!NO_FINITE_RULE) {
106 i = 0;
107 /* get the list of DCELL values from set of all dLows and dHighs
108 of all rules */
109 /* NOTE: if dLow==DHigh in a rule, the value appears twice in a list
110 but if dLow==DHigh of the previous, rule the value appears only once
111 */
112
113 for (p = &(q->table[q->nofRules - 1]); p >= q->table; p--) {
114 /* check if the min is the same as previous maximum */
115 if (i == 0 || p->dLow != q->fp_lookup.vals[i - 1])
116 q->fp_lookup.vals[i++] = p->dLow;
117 q->fp_lookup.vals[i++] = p->dHigh;
118 }
119 q->fp_lookup.nalloc = i;
120
121 /* now sort the values */
122 qsort((char *)q->fp_lookup.vals, q->fp_lookup.nalloc, sizeof(DCELL),
123 double_comp);
124
125 /* now find the rule to apply in between each 2 values in a list */
126 for (i = 0; i < q->fp_lookup.nalloc - 1; i++) {
127 /*debug
128 fprintf (stderr, "%lf %lf ", q->fp_lookup.vals[i],
129 q->fp_lookup.vals[i+1]);
130 */
131 val = (q->fp_lookup.vals[i] + q->fp_lookup.vals[i + 1]) / 2.;
132 q->fp_lookup.rules[i] =
134 /* debug
135 if(q->fp_lookup.rules[i])
136 fprintf (stderr, "%lf %lf %d %d\n", q->fp_lookup.rules[i]->dLow,
137 q->fp_lookup.rules[i]->dHigh, q->fp_lookup.rules[i]->cLow,
138 q->fp_lookup.rules[i]->cHigh); else fprintf (stderr, "null\n");
139 */
140 }
141 } /* organizing finite rules */
142
144 q->fp_lookup.inf_dmin = q->infiniteDLeft;
145 q->fp_lookup.inf_min = q->infiniteCLeft;
146 }
147 else {
148 if (q->fp_lookup.nalloc)
149 q->fp_lookup.inf_dmin = q->fp_lookup.vals[0];
150 q->fp_lookup.inf_min = NO_DATA;
151 }
152
154 if (q->fp_lookup.nalloc)
155 q->fp_lookup.inf_dmax = q->infiniteDRight;
156 q->fp_lookup.inf_max = q->infiniteCRight;
157 }
158 else {
159 q->fp_lookup.inf_dmax = q->fp_lookup.vals[q->fp_lookup.nalloc - 1];
160 q->fp_lookup.inf_max = NO_DATA;
161 }
162 q->fp_lookup.active = 1;
163 return 1;
164}
165
166/*!
167 * \brief Initialize the structure
168 *
169 * Initializes the <i>q</i> struct.
170 *
171 * \param quant pointer to Quant structure to be initialized
172 */
173void Rast_quant_init(struct Quant *quant)
174{
175 quant->fp_lookup.active = 0;
176 quant->maxNofRules = 0;
177 quant->truncate_only = 0;
178 quant->round_only = 0;
179 Rast_quant_clear(quant);
180}
181
182/*!
183 \brief Returns whether or not quant rules are set to truncate map
184
185 \param quant pointer to Quant structure which holds quant rules info
186
187 \return 1 if truncate is enable
188 \return 0 if not truncated
189 */
190int Rast_quant_is_truncate(const struct Quant *quant)
191{
192 return quant->truncate_only;
193}
194
195/*!
196 \brief Returns whether or not quant rules are set to round map
197 \param quant pointer to Quant structure which holds quant rules info
198
199 \return 1 is round
200 \return 0 not round
201 */
202int Rast_quant_is_round(const struct Quant *quant)
203{
204 return quant->round_only;
205}
206
207/*!
208 * \brief Sets the quant rules to perform simple truncation on floats.
209 *
210 * Sets the quant for <i>q</i> rules to perform simple truncation on
211 * floats.
212 *
213 * \param quant pointer to Quant structure which holds quant rules info
214 */
215void Rast_quant_truncate(struct Quant *quant)
216{
217 quant->truncate_only = 1;
218}
219
220/*!
221 * \brief Sets the quant rules to perform simple rounding on floats.
222 *
223 * Sets the quant for <i>q</i> rules to perform simple rounding on
224 * floats.
225 *
226 * \param quant pointer to Quant structure which holds quant rules info
227 */
228void Rast_quant_round(struct Quant *quant)
229{
230 quant->round_only = 1;
231}
232
233static void quant_set_limits(struct Quant *q, DCELL dLow, DCELL dHigh,
235{
236 q->dMin = dLow;
237 q->dMax = dHigh;
238 q->cMin = cLow;
239 q->cMax = cHigh;
240}
241
242static void quant_update_limits(struct Quant *q, DCELL dLow, DCELL dHigh,
244{
245 if (NO_EXPLICIT_RULE) {
246 quant_set_limits(q, dLow, dHigh, cLow, cHigh);
247 return;
248 }
249
250 q->dMin = MIN(q->dMin, MIN(dLow, dHigh));
251 q->dMax = MAX(q->dMax, MAX(dLow, dHigh));
252 q->cMin = MIN(q->cMin, MIN(cLow, cHigh));
253 q->cMax = MAX(q->cMax, MAX(cLow, cHigh));
254}
255
256/*!
257 * \brief Returns the minimum and maximum cell and dcell values of all
258 * the ranges defined.
259 *
260 * Extracts the minimum and maximum floating-point and integer values
261 * from all the rules (except the "infinite" rules) in <i>q</i> into
262 * <i>dmin</i>, <i>dmax</i>, <i>cmin</i>, and <i>cmax</i>.
263 *
264 * \param q pointer to Quant structure which holds quant rules info
265 * \param[out] dMin minimum fp value
266 * \param[out] dMax maximum fp value
267 * \param[out] cMin minimum value
268 * \param[out] cMax maximum value
269 *
270 * \return -1 if q->truncate or q->round are true or after
271 * Rast_quant_init (), or any call to Rast_quant_clear () or Rast_quant_free()
272 * no explicit rules have been added. In this case the returned
273 * minimum and maximum CELL and DCELL values are null.
274 * \return 1 if there are any explicit rules
275 * \return 0 if there are no explicit rules (this includes cases when
276 * q is set to truncate or round map), and sets <i>dmin</i>,
277 * <i>dmax</i>, <i>cmin</i>, and <i>cmax</i> to NULL.
278 */
279int Rast_quant_get_limits(const struct Quant *q, DCELL *dMin, DCELL *dMax,
280 CELL *cMin, CELL *cMax)
281{
282 if (NO_EXPLICIT_RULE) {
283 Rast_set_c_null_value(cMin, 1);
284 Rast_set_c_null_value(cMax, 1);
285 Rast_set_d_null_value(dMin, 1);
286 Rast_set_d_null_value(dMax, 1);
287 return -1;
288 }
289
290 *dMin = q->dMin;
291 *dMax = q->dMax;
292 *cMin = q->cMin;
293 *cMax = q->cMax;
294
295 return 1;
296}
297
298/*!
299 \brief Returns the number of quantization rules defined.
300
301 This number does not include the 2 infinite intervals.
302
303 \param q pointer to Quant structure which holds quant rules info
304
305 \return number of quantization rules
306 */
307int Rast_quant_nof_rules(const struct Quant *q)
308{
309 return q->nofRules;
310}
311
312/*!
313 \brief Returns the i'th quantization rule.
314
315 For 0 <= i < Rast_quant_nof_rules(). A larger value for i means that
316 the rule has been added later.
317
318 \param q pointer to Quant structure which holds quant rules info
319 \param i index
320 \param[out] dLow minimum fp value
321 \param[out] dHigh maximum fp value
322 \param[out] cLow minimum value
323 \param[out] cHigh maximum value
324 */
325void Rast_quant_get_ith_rule(const struct Quant *q, int i, DCELL *dLow,
327{
328 *dLow = q->table[i].dLow;
329 *dHigh = q->table[i].dHigh;
330 *cLow = q->table[i].cLow;
331 *cHigh = q->table[i].cHigh;
332}
333
334static void quant_table_increase(struct Quant *q)
335{
336 if (q->nofRules < q->maxNofRules)
337 return;
338
339 if (q->maxNofRules == 0) {
340 q->maxNofRules = 50;
341 q->table = (struct Quant_table *)G_malloc(q->maxNofRules *
342 sizeof(struct Quant_table));
343 }
344 else {
345 q->maxNofRules += 50;
346 q->table = (struct Quant_table *)G_realloc(
347 (char *)q->table, q->maxNofRules * sizeof(struct Quant_table));
348 }
349}
350
351/*!
352 \brief Defines a rule for values "dLeft" and smaller.
353
354 Values in this range are mapped to "c" if none of the "finite"
355 quantization rules applies.
356
357 \param q pointer to Quant structure which holds quant rules info
358
359 \param dLeft fp value
360 \param c value
361 */
363{
364 q->infiniteDLeft = dLeft;
365 q->infiniteCLeft = c;
366 quant_update_limits(q, dLeft, dLeft, c, c);
367
368 /* update lookup table */
369 if (q->fp_lookup.active) {
370 q->fp_lookup.inf_dmin = q->infiniteDLeft;
371 q->fp_lookup.inf_min = q->infiniteCLeft;
372 }
373 q->infiniteLeftSet = 1;
374}
375
376/*!
377 \brief Returns in "dLeft" and "c" the rule values.
378
379 For the negative infinite interval (see Rast_quant_set_neg_infinite_rule()).
380
381 \param q pointer to Quant structure which holds quant rules info
382 \param[out] dLeft fp value
383 \param[out] c value
384
385 \return 0 if this rule is not defined
386 \return 1 otherwise
387 */
389 CELL *c)
390{
391 if (q->infiniteLeftSet == 0)
392 return 0;
393
394 *dLeft = q->infiniteDLeft;
395 *c = q->infiniteCLeft;
396
397 return 1;
398}
399
400/*!
401 \brief Defines a rule for values "dRight" and larger.
402
403 Values in this range are mapped to "c" if none of the "finite"
404 quantization rules or the negative infinite rule applies.
405
406 \param q pointer to Quant structure which holds quant rules info
407 \param dRight fp value
408 \param c value
409 */
411{
413 q->infiniteCRight = c;
414 quant_update_limits(q, dRight, dRight, c, c);
415
416 /* update lookup table */
417 if (q->fp_lookup.active) {
418 q->fp_lookup.inf_dmax = q->infiniteDRight;
419 q->fp_lookup.inf_max = q->infiniteCRight;
420 }
421 q->infiniteRightSet = 1;
422}
423
424/*!
425 \brief Returns in "dRight" and "c" the rule values.
426
427 For the positive infinite interval (see Rast_quant_set_pos_infinite_rule()).
428
429 \param q pointer to Quant structure which holds quant rules info
430 \param[out] dRight fp value
431 \param[out] c value
432
433 \return 0 if this rule is not defined
434 \return 1 otherwise
435 */
437 CELL *c)
438{
439 if (q->infiniteRightSet == 0)
440 return 0;
441
443 *c = q->infiniteCRight;
444
445 return 1;
446}
447
448/*!
449 \brief Adds a new rule to the set of quantization rules.
450
451 If dLow < dHigh the rule will be stored with the low and high values
452 interchanged.
453
454 Note: currently no cleanup of rules is performed, i.e. redundant
455 rules are not removed. This can't be changed because Categories
456 structure HEAVILY depends of quant rules stored in exactly the same
457 order they are entered. So if the cleanup or rearrangement is done in
458 the future make a flag for add_rule whether or not to do it, then
459 quant will not set this flag.
460
461 \param q pointer to Quant structure which holds quant rules info
462 \param dLow minimum fp value
463 \param dHigh maximum fp value
464 \param cLow minimum value
465 \param cHigh maximum value
466 */
468 CELL cHigh)
469{
470 int i;
471 struct Quant_table *p;
472
473 quant_table_increase(q);
474
475 i = q->nofRules;
476
477 p = &(q->table[i]);
478 if (dHigh >= dLow) {
479 p->dLow = dLow;
480 p->dHigh = dHigh;
481 p->cLow = cLow;
482 p->cHigh = cHigh;
483 }
484 else {
485 p->dLow = dHigh;
486 p->dHigh = dLow;
487 p->cLow = cHigh;
488 p->cHigh = cLow;
489 }
490
491 /* destroy lookup table, it has to be rebuilt */
492 if (q->fp_lookup.active) {
493 G_free(q->fp_lookup.vals);
494 G_free(q->fp_lookup.rules);
495 q->fp_lookup.active = 0;
496 q->fp_lookup.nalloc = 0;
497 }
498
499 quant_update_limits(q, dLow, dHigh, cLow, cHigh);
500
501 q->nofRules++;
502}
503
504/*!
505 \brief Rreverses the order in which the qunatization rules are stored.
506
507 See also Rast_quant_get_ith_rule() and Rast_quant_perform_d()).
508
509 \param q pointer to Quant rules which holds quant rules info
510 */
512{
513 struct Quant_table tmp;
514 struct Quant_table *pLeft, *pRight;
515
516 pLeft = q->table;
517 pRight = &(q->table[q->nofRules - 1]);
518
519 while (pLeft < pRight) {
520 tmp.dLow = pLeft->dLow;
521 tmp.dHigh = pLeft->dHigh;
522 tmp.cLow = pLeft->cLow;
523 tmp.cHigh = pLeft->cHigh;
524
525 pLeft->dLow = pRight->dLow;
526 pLeft->dHigh = pRight->dHigh;
527 pLeft->cLow = pRight->cLow;
528 pLeft->cHigh = pRight->cHigh;
529
530 pRight->dLow = tmp.dLow;
531 pRight->dHigh = tmp.dHigh;
532 pRight->cLow = tmp.cLow;
533 pRight->cHigh = tmp.cHigh;
534
535 pLeft++;
536 pRight--;
537 }
538}
539
540static CELL quant_interpolate(DCELL dLow, DCELL dHigh, CELL cLow, CELL cHigh,
542{
543 if (cLow == cHigh)
544 return cLow;
545 if (dLow == dHigh)
546 return cLow;
547
548 return (CELL)((dValue - dLow) / (dHigh - dLow) * (DCELL)(cHigh - cLow) +
549 (DCELL)cLow);
550}
551
552static int less_or_equal(double x, double y)
553{
554 if (x <= y)
555 return 1;
556 else
557 return 0;
558}
559
560static int less(double x, double y)
561{
562 if (x < y)
563 return 1;
564 else
565 return 0;
566}
567
568/*!
569 * \brief
570 *
571 *
572 * Returns a CELL category for the floating-point <i>value</i> based
573 * on the quantization rules in <i>q</i>. The first rule found that
574 * applies is used. The rules are searched in the reverse order they
575 * are added to <i>q</i>. If no rule is found, the <i>value</i>
576 * is first tested against the negative infinite rule, and finally
577 * against the positive infinite rule. If none of these rules apply,
578 * the NULL-value is returned.
579 *
580 * <b>Note:</b> See G_quant_organize_fp_lookup() for details on how
581 * the values are looked up from fp_lookup table when it is
582 * active. Right now fp_lookup is automatically organized during the
583 * first call to Rast_quant_get_cell_value().
584 *
585 * \param q pointer to Quant structure which holds quant rules info
586 * \param dcellValue fp cell value
587 *
588 * \return cell value (integer)
589 */
591{
592 CELL tmp;
593 DCELL dtmp;
594 int try, min_ind, max_ind;
595 struct Quant_table *p;
596 int (*lower)(double, double);
597
598 dtmp = dcellVal;
599 /* I know the functions which call me already check for null values,
600 but I am a public function, and can be called from outside */
602 return NO_DATA;
603
604 if (q->truncate_only)
605 return (CELL)dtmp;
606
607 if (q->round_only) {
608 if (dcellVal > 0)
609 return (CELL)(dcellVal + .5);
610 return (CELL)(dcellVal - .5);
611 }
612
614 return NO_DATA;
616 return NO_DATA;
617
618 if (USE_LOOKUP &&
619 (q->fp_lookup.active || Rast__quant_organize_fp_lookup(q) > 0)) {
620 /* first check if values fall within range */
621 /* if value is below the range */
622 if (dcellVal < q->fp_lookup.vals[0]) {
623 if (dcellVal <= q->fp_lookup.inf_dmin)
624 return q->fp_lookup.inf_min;
625 else
626 return NO_DATA;
627 }
628 /* if value is below above range */
629 if (dcellVal > q->fp_lookup.vals[q->fp_lookup.nalloc - 1]) {
630 if (dcellVal >= q->fp_lookup.inf_dmax)
631 return q->fp_lookup.inf_max;
632 else
633 return NO_DATA;
634 }
635 /* make binary search to find which interval our value belongs to
636 and apply the rule for this interval */
637 try = (q->fp_lookup.nalloc - 1) / 2;
638 min_ind = 0;
639 max_ind = q->fp_lookup.nalloc - 2;
640 while (1) {
641 /* DEBUG
642 fprintf (stderr, "%d %d %d\n", min_ind, max_ind, try);
643 */
644 /* when the ruke for the interval is NULL, we exclude the end
645 points. when it exists, we include the end-points */
646 if (q->fp_lookup.rules[try])
647 lower = less;
648 else
649 lower = less_or_equal;
650
651 if (lower(q->fp_lookup.vals[try + 1],
652 dcellVal)) { /* recurse to the second half */
653 min_ind = try + 1;
654 /* must be still < nalloc-1, since number is within the range */
655 try = (max_ind + min_ind) / 2;
656 continue;
657 }
658 if (lower(
659 dcellVal,
660 q->fp_lookup.vals[try])) { /* recurse to the second half */
661 max_ind = try - 1;
662 /* must be still >= 0, since number is within the range */
663 try = (max_ind + min_ind) / 2;
664 continue;
665 }
666 /* the value fits into the interval! */
667 p = q->fp_lookup.rules[try];
668 if (p)
669 return quant_interpolate(p->dLow, p->dHigh, p->cLow, p->cHigh,
670 dcellVal);
671 /* otherwise when finite rule for this interval doesn't exist */
672 else { /* first check if maybe infinite rule applies */
673 if (dcellVal <= q->fp_lookup.inf_dmin)
674 return q->fp_lookup.inf_min;
675 if (dcellVal >= q->fp_lookup.inf_dmax)
676 return q->fp_lookup.inf_max;
677 else
678 return NO_DATA;
679 }
680 } /* while */
681 } /* looking up in fp_lookup */
682
683 if (!NO_FINITE_RULE) {
685 if (!p)
686 return NO_DATA;
687 return quant_interpolate(p->dLow, p->dHigh, p->cLow, p->cHigh,
688 dcellVal);
689 }
690
691 if ((!NO_LEFT_INFINITE_RULE) && (dcellVal <= q->infiniteDLeft))
692 return q->infiniteCLeft;
693
694 if ((NO_RIGHT_INFINITE_RULE) || (dcellVal < q->infiniteDRight))
695 return NO_DATA;
696
697 return q->infiniteCRight;
698}
699
700/*!
701 \brief Returns in "cell" the quantized CELL values.
702
703 Returns in "cell" the quantized CELL values corresponding to the
704 DCELL values stored in "dcell". the number of elements quantized
705 is n. quantization is performed by repeated application of
706 Rast_quant_get_cell_value().
707
708 \param q pointer to Quant structure which holds quant rules info
709 \param dcell pointer to fp cell values array
710 \param[out] cell pointer cell values array
711 \param n number of cells
712 */
713void Rast_quant_perform_d(struct Quant *q, const DCELL *dcell, CELL *cell,
714 int n)
715{
716 int i;
717
718 for (i = 0; i < n; i++, dcell++)
720 *cell++ = Rast_quant_get_cell_value(q, *dcell);
721 else
722 Rast_set_c_null_value(cell++, 1);
723}
724
725/*!
726 \brief Same as Rast_quant_perform_d(), except the type.
727
728 \param q pointer to Quant structure which holds quant rules info
729 \param fcell pointer to fp cell values array
730 \param[out] cell pointer cell values array
731 \param n number of cells
732 */
733void Rast_quant_perform_f(struct Quant *q, const FCELL *fcell, CELL *cell,
734 int n)
735{
736 int i;
737
738 for (i = 0; i < n; i++, fcell++)
740 *cell++ = Rast_quant_get_cell_value(q, (DCELL)*fcell);
741 else
742 Rast_set_c_null_value(cell++, 1);
743}
744
745static int double_comp(const void *xx, const void *yy)
746{
747 const DCELL *x = xx;
748 const DCELL *y = yy;
749
751 return 0;
752 if (*x < *y)
753 return -1;
754 else if (*x == *y)
755 return 0;
756 else
757 return 1;
758}
759
760/*!
761 \brief Returns quant rule which will be applied.
762
763 Returns quant rule which will be applied when looking up the integer
764 quant value for val (used when organizing fp_lookup).
765
766 \param q pointer to Quant structure which holds quant rules info
767 \param val fp cell value
768
769 \return pointer to the Quant_table (color rule)
770 \return NULL otherwise
771 */
773 DCELL val)
774{
775 const struct Quant_table *p;
776
777 for (p = &(q->table[q->nofRules - 1]); p >= q->table; p--)
778 if ((val >= p->dLow) && (val <= p->dHigh))
779 break;
780 if (p >= q->table)
781 return (struct Quant_table *)p;
782 else
783 return (struct Quant_table *)NULL;
784}
#define NULL
Definition ccmath.h:32
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
#define G_realloc(p, n)
Definition defs/gis.h:138
#define G_calloc(m, n)
Definition defs/gis.h:137
#define G_malloc(n)
Definition defs/gis.h:136
#define Rast_is_f_null_value(fcellVal)
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
Definition null_val.c:151
void Rast_set_c_null_value(CELL *, int)
To set a number of CELL raster values to NULL.
Definition null_val.c:122
#define Rast_is_d_null_value(dcellVal)
#define MIN(a, b)
Definition gis.h:150
float FCELL
Definition gis.h:633
double DCELL
Definition gis.h:632
int CELL
Definition gis.h:631
#define MAX(a, b)
Definition gis.h:145
#define NO_LEFT_INFINITE_RULE
Definition quant.c:28
void Rast_quant_free(struct Quant *q)
Resets and frees allocated memory.
Definition quant.c:53
#define MAX_LOOKUP_TABLE_SIZE
Definition quant.c:25
#define NO_RIGHT_INFINITE_RULE
Definition quant.c:29
void Rast_quant_get_ith_rule(const struct Quant *q, int i, DCELL *dLow, DCELL *dHigh, CELL *cLow, CELL *cHigh)
Returns the i'th quantization rule.
Definition quant.c:325
int Rast_quant_is_truncate(const struct Quant *quant)
Returns whether or not quant rules are set to truncate map.
Definition quant.c:190
int Rast__quant_organize_fp_lookup(struct Quant *q)
Organized fp_lookup table.
Definition quant.c:88
#define USE_LOOKUP
Definition quant.c:24
void Rast_quant_init(struct Quant *quant)
Initialize the structure.
Definition quant.c:173
void Rast_quant_round(struct Quant *quant)
Sets the quant rules to perform simple rounding on floats.
Definition quant.c:228
void Rast_quant_perform_d(struct Quant *q, const DCELL *dcell, CELL *cell, int n)
Returns in "cell" the quantized CELL values.
Definition quant.c:713
#define NO_EXPLICIT_RULE
Definition quant.c:31
void Rast_quant_add_rule(struct Quant *q, DCELL dLow, DCELL dHigh, CELL cLow, CELL cHigh)
Adds a new rule to the set of quantization rules.
Definition quant.c:467
int Rast_quant_get_neg_infinite_rule(const struct Quant *q, DCELL *dLeft, CELL *c)
Returns in "dLeft" and "c" the rule values.
Definition quant.c:388
void Rast_quant_perform_f(struct Quant *q, const FCELL *fcell, CELL *cell, int n)
Same as Rast_quant_perform_d(), except the type.
Definition quant.c:733
void Rast_quant_set_neg_infinite_rule(struct Quant *q, DCELL dLeft, CELL c)
Defines a rule for values "dLeft" and smaller.
Definition quant.c:362
void Rast_quant_truncate(struct Quant *quant)
Sets the quant rules to perform simple truncation on floats.
Definition quant.c:215
#define NO_FINITE_RULE
Definition quant.c:30
#define NO_DATA
Definition quant.c:26
int Rast_quant_get_pos_infinite_rule(const struct Quant *q, DCELL *dRight, CELL *c)
Returns in "dRight" and "c" the rule values.
Definition quant.c:436
int Rast_quant_get_limits(const struct Quant *q, DCELL *dMin, DCELL *dMax, CELL *cMin, CELL *cMax)
Returns the minimum and maximum cell and dcell values of all the ranges defined.
Definition quant.c:279
void Rast_quant_clear(struct Quant *q)
Resets the number of defined rules and number of infinite rules to 0.
Definition quant.c:39
int Rast_quant_nof_rules(const struct Quant *q)
Returns the number of quantization rules defined.
Definition quant.c:307
void Rast_quant_reverse_rule_order(struct Quant *q)
Rreverses the order in which the qunatization rules are stored.
Definition quant.c:511
CELL Rast_quant_get_cell_value(struct Quant *q, DCELL dcellVal)
Returns a CELL category for the floating-point value based on the quantization rules in q....
Definition quant.c:590
struct Quant_table * Rast__quant_get_rule_for_d_raster_val(const struct Quant *q, DCELL val)
Returns quant rule which will be applied.
Definition quant.c:772
void Rast_quant_set_pos_infinite_rule(struct Quant *q, DCELL dRight, CELL c)
Defines a rule for values "dRight" and larger.
Definition quant.c:410
int Rast_quant_is_round(const struct Quant *quant)
Returns whether or not quant rules are set to round map.
Definition quant.c:202
DCELL dLow
Definition raster.h:74
CELL cHigh
Definition raster.h:77
CELL cLow
Definition raster.h:76
DCELL dHigh
Definition raster.h:75
Definition raster.h:80
DCELL dMin
Definition raster.h:98
int truncate_only
Definition raster.h:81
int nofRules
Definition raster.h:89
struct Quant_table * table
Definition raster.h:102
int maxNofRules
Definition raster.h:88
CELL cMin
Definition raster.h:100
CELL cMax
Definition raster.h:101
DCELL infiniteDLeft
Definition raster.h:94
DCELL infiniteDRight
Definition raster.h:95
int round_only
Definition raster.h:82
int infiniteRightSet
Definition raster.h:86
CELL infiniteCLeft
Definition raster.h:96
CELL infiniteCRight
Definition raster.h:97
int infiniteLeftSet
Definition raster.h:85
struct Quant::@5 fp_lookup
DCELL dMax
Definition raster.h:99
#define x