pattern_gen.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. * Author: g0tsu
  12. * Email: g0tsu at dnmx.0rg
  13. */
  14. #include <stdio.h>
  15. #include <assert.h>
  16. #include <libcaptcha.h>
  17. #include <errno.h>
  18. #include <global.h>
  19. #define STB_IMAGE_WRITE_IMPLEMENTATION
  20. #include "stb_image_write.h"
  21. static int create_shapes_pattern() {
  22. lc_bmp * text = lc_preset_text("../ttf/dejavu.ttf", "HELLOWORLD", 38, 50, 0, 10, 10);
  23. lc_bmp * fg = lc_generate_square_shapes(text->w, text->h, 2, 10);
  24. lc_bmp * bg = lc_generate_square_shapes(text->w, text->h, 2, 10);
  25. lc_colorize_sepia(bg);
  26. lc_bmp * cc = lc_pattern_apply(fg, text);
  27. lc_bmp * out = lc_pattern_merge(bg, cc, 0 , 0);
  28. /* lc_save_png("/tmp/out.png", out);*/
  29. lc_free(out);
  30. lc_free(cc);
  31. lc_free(bg);
  32. lc_free(fg);
  33. lc_free(text);
  34. return 0;
  35. }
  36. static int create_shapes_pattern_square() {
  37. lc_bmp * text = lc_preset_text("../ttf/dejavu.ttf", "HELLOWORLD", 38, 50, 0, 10, 10);
  38. lc_bmp * bmp = lc_preset_square(text, 2, 10);
  39. /* lc_save_png("/tmp/out.png", bmp);*/
  40. lc_free(bmp);
  41. lc_free(text);
  42. return 0;
  43. }
  44. static int create_shapes_pattern_circle() {
  45. lc_bmp * text = lc_preset_text("../ttf/dejavu.ttf", "HELLOWORLD", 38, 50, 0, 10, 10);
  46. lc_bmp * bmp = lc_preset_circle(text, 0, 14);
  47. /* lc_save_png("/tmp/out.png", bmp);*/
  48. lc_free(bmp);
  49. lc_free(text);
  50. return 0;
  51. }
  52. static int generate_screenshot() {
  53. lc_bmp * text = lc_preset_text("../ttf/dejavu.ttf", "HELLOWORLD", 38, 50, 0, 10, 10);
  54. lc_bmp * bmp = lc_create_3ch_bmp(text->w * 3 + 3, text->h * 2 + 2); //6 images
  55. int ow = text->w;
  56. int oh = text->h;
  57. lc_bmp * square = lc_preset_square(text, 1, 2);
  58. lc_place_bmp_shape(bmp, square, 0, 0);
  59. lc_free(square);
  60. square = lc_preset_square(text, 2, 15);
  61. lc_place_bmp_shape(bmp, square, text->w + 1, 0);
  62. lc_free(square);
  63. square = lc_preset_square(text, 2, 20);
  64. lc_place_bmp_shape(bmp, square, text->w * 2 + 1, 0);
  65. lc_free(square);
  66. lc_bmp * noise = lc_preset_noise(text);
  67. lc_place_bmp_shape(bmp, noise, 0, text->h + 1);
  68. lc_free(noise);
  69. square = lc_preset_circle(text, 0, 14);
  70. lc_place_bmp_shape(bmp, square, ow + 1, oh + 1);
  71. lc_free(square);
  72. square = lc_preset_circle(text, 0, 30);
  73. lc_place_bmp_shape(bmp, square, ow * 2 + 1, oh+ 1);
  74. lc_free(square);
  75. /* text = lc_preset_text("../ttf/dejavu.ttf", "MAYBEMORESOMEDAY😃️", 38, 50, 0, 10, 10);*/
  76. /* lc_bmp * fg = lc_generate_square_shapes(text->w, text->h, 2, 10);*/
  77. /* lc_bmp * cc = lc_pattern_apply(fg, text);*/
  78. /* lc_place_bmp_shape(bmp, cc, ow + 1, oh + 1);*/
  79. /* lc_save_png("/tmp/out.png", bmp);*/
  80. /* lc_free(fg);*/
  81. /* lc_free(cc);*/
  82. lc_free(bmp);
  83. lc_free(text);
  84. return 0;
  85. }
  86. int main() {
  87. assert(!create_shapes_pattern());
  88. assert(!create_shapes_pattern_square());
  89. assert(!create_shapes_pattern_circle());
  90. assert(!generate_screenshot());
  91. return 0;
  92. }