Commit graph

14 commits

Author SHA1 Message Date
Ivan Grokhotkov
cc67312433
Add an option to use single-precision floating point in calculations
On some platforms, such as microcontrollers with a single-precision
FPU, operations on double type can be significantly slower compared
to the float type. For example, on ESP32-S3 microcontroller, decoding
a QR code of a certain size may take 1700ms when 'double' is used and
just 250ms when 'float' is used.

This commit adds two options to allow for such optimizations:

- QUIRC_FLOAT_TYPE: if defined, it is the type name to use in floating
  point calculations. Can be set, for example, using:
    CFLAGS += -DQUIRC_FLOAT_TYPE=float

- QUIRC_USE_TGMATH: if defined, Quirc will internally use <tgmath.h>
  header, instead of <math.h>. This C99-or-later header allows the
  program to call type-generic functions, such as 'sqrt', and the
  calls will be dispatched to the correct implementation (sqrtf, sqrt,
  sqrtl) depending on the actual argument type. Without setting this
  option, the benefit of -DQUIRC_FLOAT_TYPE=float would be limited as
  the double-precision versions of math functions would still be used.

The change is backwards compatible with existing applications. If
these macros are not defined, the behavior is the same as before.
2023-03-21 02:04:39 +01:00
Jaap Haitsma
2ff513b0b4 merge upstream 2021-06-16 23:52:51 -04:00
YAMAMOTO Takashi
38f882b3d6 flood_fill_seed: Simplify the flow by having a single "return point". 2021-05-11 13:46:31 +09:00
YAMAMOTO Takashi
dd6c64cafe Add QUIRC_ASSERT 2021-05-11 13:26:47 +09:00
YAMAMOTO Takashi
40def012e7 flood_fill_seed: Unify "left" and "x" vars
This reduces the memory usage a bit.
2021-05-11 13:04:02 +09:00
YAMAMOTO Takashi
772cd3e73f Improve stack usage for flood filling
* Make flood filling logic iterative (vs recursive)
  I basically tried one-to-one conversions here to avoid mistakes.
  probably it has a room for later optimizations.

* Use explicit malloc (vs variables on stack) to allocate the work area.

* Estimate the amount of memory for the work area dynamically
  from the image size, instead of using a constant FLOOD_FILL_MAX_DEPTH,
  which is too big in the most cases.
2021-05-11 11:05:58 +09:00
Claudio Felber
963d6ed126 Fix stack corruption and bus errors while scanning oversized QR codes 2020-09-15 00:51:41 +02:00
Jaap Haitsma
bff065d88b Try all possible groups and new algo for grid_size 2020-05-27 21:33:51 -04:00
Alexandre Perrin
f700e456b4 define a QUIRC_PIXEL_ALIAS_IMAGE constant to explicit conditional path
Before this patch, the "sizeof dance" was confusing, fix #54.
2019-07-02 09:22:25 +02:00
Claudio Felber
96a5a380fb Remove quirc.row_average and associated code
quirc.row_average was used by the former threshold function and has
become obsolete with the introduction of the Otsu threshold function.
2019-04-30 18:43:57 +02:00
Alexandre Perrin
21f6863577 Added a row_average member to struct quirc.
Prep to remove the VLA from threshold()
2017-06-11 10:08:58 +02:00
Daniel Beer
59182ef1cd Deinterleave blocks correct.
Use explicit small-block count. Derived value using greedy calculation
wasn't correct in many cases.
2016-12-28 15:37:18 +13:00
Alexandre Perrin
3a6efb3d84 Large images decoding support
Fix #2, this patch makes large images support a compile time option by
allowing QUIRC_MAX_REGIONS to be tuned via CFLAGS up to 65534 (current
default is 254).
2016-07-15 14:40:40 +02:00
Daniel Beer
a3142bc6b4 Initial commit: version 1.0. 2012-05-04 12:58:42 +12:00