reedsol.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. This is a simple Reed-Solomon encoder
  3. (C) Cliff Hones 2004
  4. */
  5. /*
  6. libzint - the open source barcode library
  7. Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions
  10. are met:
  11. 1. Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. 3. Neither the name of the project nor the names of its contributors
  17. may be used to endorse or promote products derived from this software
  18. without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  23. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. SUCH DAMAGE.
  30. */
  31. /* SPDX-License-Identifier: BSD-3-Clause */
  32. #ifndef Z_REEDSOL_H
  33. #define Z_REEDSOL_H
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif /* __cplusplus */
  37. typedef struct {
  38. const unsigned char *logt; /* These are static */
  39. const unsigned char *alog;
  40. unsigned char rspoly[256]; /* Generated poly */
  41. unsigned char log_rspoly[256]; /* Logs of poly */
  42. int nsym; /* Degree of poly */
  43. int zero; /* Set if poly has a zero coeff */
  44. } rs_t;
  45. typedef struct {
  46. unsigned int *logt; /* These are malloced */
  47. unsigned int *alog;
  48. unsigned short rspoly[4096]; /* Generated poly, 12-bit max - needs to be enlarged if > 12-bit used */
  49. unsigned int log_rspoly[4096]; /* Logs of poly */
  50. int nsym; /* Degree of poly */
  51. int zero; /* Set if poly has a zero coeff */
  52. } rs_uint_t;
  53. INTERNAL void rs_init_gf(rs_t *rs, const unsigned int prime_poly);
  54. INTERNAL void rs_init_code(rs_t *rs, const int nsym, int index);
  55. INTERNAL void rs_encode(const rs_t *rs, const int datalen, const unsigned char *data, unsigned char *res);
  56. INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned int *data, unsigned int *res);
  57. /* No free needed as log tables static */
  58. INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod);
  59. INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index);
  60. INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data,
  61. unsigned int *res);
  62. INTERNAL void rs_uint_free(rs_uint_t *rs_uint);
  63. #ifdef __cplusplus
  64. }
  65. #endif /* __cplusplus */
  66. /* vim: set ts=4 sw=4 et : */
  67. #endif /* Z_REEDSOL_H */