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 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. #include "config.h"
  22. #include "rpn_if.h"
  23. /**@file rpn_if_default.h Defines default IF
  24. * @ingroup ifs_if_default
  25. * @ingroup ifs_if
  26. * @brief Default IF definitions
  27. */
  28. /**@defgroup ifs_if_default Default iterated functions
  29. * @ingroup ifs_if
  30. * @brief Iterated function default implementation
  31. *
  32. * Defines default @ref rpn_if_param_s.setres_f and @ref rpn_if_param_s.getarg_f
  33. * functions and flags to select them (see @ref ifs_if_default_posflag and
  34. * @ref ifs_if_default_resflag ).
  35. *
  36. * The @ref rpn_if_default_params function constructs suitable
  37. * @ref rpn_if_param_t to instanciate an @ref rpn_if_t with
  38. * @ref rpn_if_new function.
  39. */
  40. /**@weakgroup ifs_if_default_posflag Default IF position flags
  41. * @ingroup ifs_if_default
  42. * @{ */
  43. #define RPN_IF_POSITION_LINEAR 0 ///< One expr for position
  44. #define RPN_IF_POSITION_XY 1 ///< two expr for position
  45. #define RPN_IF_POSITION_XDIM 2 ///< X expr for position
  46. #define RPN_IF_POSITION_OF_LOOP 0 ///< Loop on position overflow
  47. #define RPN_IF_POSITION_OF_ERR 16 ///< Trigger error on position overflow
  48. /**@}*/
  49. /**@weakgroup ifs_if_default_resflag Default IF position flags
  50. * @ingroup ifs_if_default
  51. * @{ */
  52. #define RPN_IF_RES_BOOL 0 ///< Set to one when position occurs
  53. #define RPN_IF_RES_CONST 1 ///< Set to a constant value
  54. #define RPN_IF_RES_CONST_RGBA 2 ///< Set to a constant RGB using alpha channel
  55. #define RPN_IF_RES_COUNT 3 ///< Count number of time position occurs
  56. #define RPN_IF_RES_XFUN 4 ///< Set to result of rpn_expr
  57. #define RPN_IF_RES_RGB 5 ///< Set result to RGB color from rpn_expr
  58. #define RPN_IF_RES_RGBA 6 ///< Set result to RGB using alpha channel from rpn_expr
  59. /**@}*/
  60. /**@brief Alias for struct @ref rpn_if_default_data_s */
  61. typedef struct rpn_if_default_data_s rpn_if_default_data_t;
  62. /**@brief Stores default IF data
  63. *
  64. * Stores flags and size limit
  65. * @ingroup ifs_if_default
  66. */
  67. struct rpn_if_default_data_s
  68. {
  69. /**@brief Flag defining position coordinate handling */
  70. short pos_flag;
  71. /**@brief Flag defining result handling */
  72. short res_flag;
  73. /**@brief Stores size limits given pos_flag
  74. *
  75. * @note If NULL no limit
  76. * - For @ref RPN_IF_POSITION_LINEAR size_lim is a single size_t
  77. * - For @ref RPN_IF_POSITION_XY size_lim is two size_t (height and width)
  78. * - For @ref RPN_IF_POSITION_XDIM the first element (*size_lim) is the
  79. * size of the size_lim array
  80. */
  81. size_t *size_lim;
  82. /** Number of dimensions (if XDIM ndim = len(size_lim)-1) */
  83. size_t ndim;
  84. /**@brief Store constant values to set mem given res_flag
  85. * - For @ref RPN_IF_RES_CONST const_val points on a single value
  86. * - For @ref RPN_IF_RES_CONST_RGBA const_val points on 4 values
  87. * - Else const_val is set to NULL
  88. */
  89. rpn_value_t *const_val;
  90. };
  91. /**@brief Create a new @ref rpn_if_param_s corresponding to given flags
  92. * @ingroup ifs_if_default
  93. *
  94. * @param pos_flag Binary OR combination of RPN_IF_POSITION_*
  95. * (@ref ifs_if_default_posflag )
  96. * @param res_flag Binary OR combination of RPN_IF_RES_*
  97. * (@ref ifs_if_default_resflag )
  98. * @param lim Depends on pos_flag parameter (
  99. * see @ref rpn_if_default_data_s::size_lim )
  100. * @param res_const Depends on res_flag parameter (
  101. * see @ref rpn_if_default_data_s::const_val )
  102. * @param rpn_stack_sz The size of the stack for expressions
  103. * @returns A new @ref rpn_if_param_t or NULL on error
  104. * @ingroup ifs_if_default
  105. */
  106. rpn_if_param_t* rpn_if_default_params(short pos_flag, short res_flag,
  107. const size_t *lim, const rpn_value_t *res_const,
  108. unsigned char rpn_stack_sz);
  109. /** Fetch size limit and const values array sizes given flag values
  110. * @param pos_flag (@ref ifs_if_default_posflag)
  111. * @param res_flag (@ref ifs_if_default_resflag)
  112. * @param sizes size limit array size and constant values array size
  113. * @return 0 or -1 if a flag is not valid
  114. * @warning returns 1 for size limit when XDIM position, but actually the
  115. * limit is given by the 1st number in the limit (example : [2,640,480],
  116. * [3,16,640,480], ...)
  117. * @todo replace short by int for sizes
  118. */
  119. int rpn_if_sizes_from_flag(short pos_flag, short res_flag, short sizes[2]);
  120. /**@brief Default argf function ( see @ref rpn_if_param_s.getarg_f )
  121. *
  122. * This function handle internal rif modification to set next arguments.
  123. * It will call specialized function depending on
  124. * @ref rpn_if_default_data_s.pos_flag and @ref rpn_if_default_data_s.res_flag
  125. * @note The position is the first set of arguments and can be use to
  126. * look for the other one
  127. *
  128. * @param rif Pointer on expressions
  129. * @param pos The position
  130. * @return 0 or -1 on error
  131. */
  132. int rpn_if_getarg_default(rpn_if_t *rif, size_t pos);
  133. /**@brief Default result function ( see @ref rpn_if_param_s.setres_f )
  134. *
  135. * This function will store the result at given position and
  136. * It will call specialized function depending on
  137. * @ref rpn_if_default_data_s.pos_flag and @ref rpn_if_default_data_s.res_flag
  138. * @param rif Pointer on expressions
  139. * @param pos Will be set to the resulting position
  140. * @return 0 or -1 on error
  141. */
  142. int rpn_if_setres_default(rpn_if_t *rif, size_t *pos);
  143. /**@brief Set the first expression argument from linear position
  144. * @param rif Expressions
  145. * @param pos Memory map offset
  146. * @param args pointer on expressions arguments
  147. * @return 0 or -1 on error
  148. * @note Other arguments are set using the generic @ref rpn_if_getarg_default
  149. * function
  150. */
  151. int rpn_if_argf_linear(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  152. /**@brief Transform 1st expression result to position
  153. * @param rif Expressions
  154. * @param pos Pointer on resulting position in memory map
  155. * @return 0 or -1 on error
  156. * @note Data from position fecth is done by generic @ref rpn_if_setres_default
  157. * function
  158. */
  159. int rpn_if_resf_linear(rpn_if_t *rif, size_t *pos);
  160. /**@brief Set the 1st & 2nd argument from position
  161. * @param rif Expressions
  162. * @param pos Memory map offset
  163. * @param args pointer on expression arguments
  164. * @return 0 or -1 on error
  165. * @note Other arguments are set using the generic @ref rpn_if_getarg_default
  166. * function
  167. */
  168. int rpn_if_argf_xy(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  169. /**@brief Transform 1st and 2nd result into a memory map's offset
  170. * @param rif Expressions
  171. * @param pos Memory map offset pointer
  172. * @return 0 or -1 on error
  173. * @note Data from position fetch is done by generic @ref rpn_if_setres_default
  174. * function
  175. */
  176. int rpn_if_resf_xy(rpn_if_t *rif, size_t *pos);
  177. /**@brief Set X first arguments from position
  178. * @param rif Expressions
  179. * @param pos Memory map offset
  180. * @param args Pointer on expression arguments
  181. * @return 0 or -1 on error
  182. * @note Other arguments are set using the generic @ref rpn_if_getarg_default
  183. * function
  184. */
  185. int rpn_if_argf_xdim(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  186. /**@brief Transform X arguments into a memory map's offset
  187. * @param rif Expressions
  188. * @param pos Memory map offset pointer
  189. * @return 0 or -1 on error
  190. * @note Data from position fetch is done by generic @ref rpn_if_setres_default
  191. * function
  192. */
  193. int rpn_if_resf_xdim(rpn_if_t *rif, size_t *pos);
  194. #endif