pattern_gen.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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, 1, 2);
  39. /* lc_save_png("/tmp/out.png", bmp);*/
  40. lc_free(bmp);
  41. lc_free(text);
  42. return 0;
  43. }
  44. static int generate_screenshot() {
  45. lc_bmp * text = lc_preset_text("../ttf/dejavu.ttf", "HELLOWORLD", 38, 50, 0, 10, 10);
  46. lc_bmp * bmp = lc_create_3ch_bmp(text->w * 3 + 3, text->h * 2 + 2); //6 images
  47. int ow = text->w;
  48. int oh = text->h;
  49. lc_bmp * square = lc_preset_square(text, 1, 2);
  50. lc_place_bmp_shape(bmp, square, 0, 0);
  51. lc_free(square);
  52. square = lc_preset_square(text, 2, 15);
  53. lc_place_bmp_shape(bmp, square, text->w + 1, 0);
  54. lc_free(square);
  55. square = lc_preset_square(text, 2, 20);
  56. lc_place_bmp_shape(bmp, square, text->w * 2 + 1, 0);
  57. lc_free(square);
  58. lc_bmp * noise = lc_preset_noise(text);
  59. lc_place_bmp_shape(bmp, noise, 0, text->h + 1);
  60. lc_free(noise);
  61. lc_free(text);
  62. text = lc_preset_text("../ttf/dejavu.ttf", "MAYBEMORESOMEDAY😃️", 38, 50, 0, 10, 10);
  63. lc_bmp * fg = lc_generate_square_shapes(text->w, text->h, 2, 10);
  64. lc_bmp * cc = lc_pattern_apply(fg, text);
  65. lc_place_bmp_shape(bmp, cc, ow + 1, oh + 1);
  66. lc_save_png("/tmp/out.png", bmp);
  67. lc_free(fg);
  68. lc_free(cc);
  69. lc_free(bmp);
  70. lc_free(text);
  71. return 0;
  72. }
  73. int main() {
  74. assert(!create_shapes_pattern());
  75. assert(!create_shapes_pattern_square());
  76. assert(!generate_screenshot());
  77. return 0;
  78. }