Fast IFS using RPN notation
python
c
x86-64
nasm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rpn_if_default.h 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2020 Weber Yann
  3. *
  4. * This file is part of pyrpn.
  5. *
  6. * pyrpn is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * pyrpn is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __rpn_if_default__h__
  20. #define __rpn_if_default__h__
  21. /**@file rpn_if_default.h Defines default IF
  22. * @brief Default IF definitions
  23. */
  24. /**@defgroup ifs_if_default Default functions
  25. * @brief Simple iterated functions functions
  26. */
  27. #include "config.h"
  28. #include "rpn_if.h"
  29. #define RPN_IF_POSITION_LINEAR 0 // One expr for position
  30. #define RPN_IF_POSITION_XY 1 // two expr for poisition
  31. #define RPN_IF_POSITION_XDIM 2 // X expr for position
  32. #define RPN_IF_POSITION_OF_LOOP 0 // Loop on position overflow
  33. #define RPN_IF_POSITION_OF_ERR 16 // Trigger error on position overflow
  34. #define RPN_IF_RES_BOOL 0 // Set to one when position occurs
  35. #define RPN_IF_RES_CONST 1 // Set to a constant value
  36. #define RPN_IF_RES_CONST_RGBA 2 // Set to a constant RGB using alpha channel
  37. #define RPN_IF_RES_COUNT 3 // Count number of time position occurs
  38. #define RPN_IF_RES_XFUN 4 // Set to result of rpn_expr
  39. #define RPN_IF_RES_RGB 5 // Set result to RGB color from rpn_expr
  40. #define RPN_IF_RES_RGBA 6 // Set result to RGB using alpha channel from rpn_expr
  41. typedef struct rpn_if_default_data_s rpn_if_default_data_t;
  42. /**@brief Stores default IF data
  43. *
  44. * Stores flags and size limit
  45. */
  46. struct rpn_if_default_data_s
  47. {
  48. short pos_flag;
  49. short res_flag;
  50. /**@brief Stores size limits given pos_flag
  51. *
  52. * @note If NULL no limit
  53. * - For @ref RPN_IF_POSITION_LINEAR size_lim is a single size_t
  54. * - For @ref RPN_IF_POSITION_XY size_lim is two size_t (height and width)
  55. * - For @ref RPN_IF_POSITION_XDIM *size_lim is the size of size_lim
  56. */
  57. size_t *size_lim;
  58. /**@brief Store constant values to set mem giver res_flag
  59. * - For @ref RPN_IF_CONST_RGBA const_val points on a single value
  60. * - For @ref RPN_IF_RES_CONST_RGBA const_val points on 4 values
  61. */
  62. rpn_value_t *const_val;
  63. };
  64. int rpn_if_argf_default(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  65. int rpn_if_resf_default(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
  66. /**@brief Set the first expression argument from position
  67. * @params rif Expressions
  68. * @params pos Memory map offset
  69. * @params args pointer on expressions arguments
  70. * @note Other arguments are set using the generic @ref rpn_if_argf_default
  71. * function
  72. */
  73. int rpn_if_argf_linear(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  74. /**@brief Transform 1st expression result to position
  75. * @params rif Expressions
  76. * @params pos Pointer on resulting position in memory map
  77. * @params data Pointer on resulting data
  78. * @note Data from position fecth is done by generic @ref rpn_if_resf_default
  79. * function
  80. */
  81. int rpn_if_resf_linear(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
  82. /**@brief Set the 1st & 2nd argument from position
  83. * @params rif Expressions
  84. * @params pos Memory map offset
  85. * @params args pointer on expression arguments
  86. * @note Other arguments are set using the generic @ref rpn_if_argf_default
  87. * function
  88. */
  89. int rpn_if_argf_xy(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  90. /**@brief Transform 1st and 2nd result into a memory map's offset
  91. * @params rif Expressions
  92. * @param pos Memory map offset pointer
  93. * @params data Pointer on resulting data
  94. * @note Data from position fetch is done by generic @ref rpn_if_resf_default
  95. * function
  96. */
  97. int rpn_if_resf_xy(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
  98. /**@brief Set X first arguments from position
  99. * @params rif Expressions
  100. * @params pos Memory map offset
  101. * @params args Pointer on expression arguments
  102. * @note Other arguments are set using the generic @ref rpn_if_argf_default
  103. * function
  104. */
  105. int rpn_if_argf_xdim(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  106. /**@brief Transform X arguments into a memory map's offset
  107. * @params rif Expressions
  108. * @param pos Memory map offset pointer
  109. * @param data Pointer on resulting data
  110. * @note Data from position fetch is done by generic @ref rpn_if_resf_default
  111. * function
  112. */
  113. int rpn_if_resf_xdim(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
  114. #endif