rotate_glyph.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #define STB_IMAGE_WRITE_IMPLEMENTATION
  19. #include "stb_image_write.h"
  20. static int create_bmp_glyph() {
  21. char *fontfile = "../ttf/cmunrm/cmunrm.ttf";
  22. lc_fontBuffer *font = lc_create_font(fontfile);
  23. lc_bmpGlyph *glyph;
  24. if (!font) {
  25. perror("lc_create_font()");
  26. return 1;
  27. }
  28. glyph = lc_create_glyph(font, 'P', 320);
  29. if (!glyph) {
  30. puts("lc_create_glyph()");
  31. return 1;
  32. }
  33. lc_rotate_glyph_180(glyph);
  34. /* lc_save_png("/tmp/out.png", bmp);*/
  35. lc_free(glyph);
  36. lc_free(font);
  37. return 0;
  38. }
  39. static int rotate_bmp_180() {
  40. char *fontfile = "../ttf/cmunrm/cmunrm.ttf";
  41. lc_fontBuffer *font = lc_create_font(fontfile);
  42. lc_bmpGlyph *glyph;
  43. lc_bmp *bmp;
  44. if (!font) {
  45. perror("lc_create_font()");
  46. return 1;
  47. }
  48. glyph = lc_create_glyph(font, 'P', 320);
  49. if (!glyph) {
  50. puts("lc_create_glyph()");
  51. return 1;
  52. }
  53. bmp = lc_rotate_bmp_180(glyph->buffer, glyph->w, glyph->h);
  54. if (!bmp) {
  55. perror("lc_rotate_bmp_180()");
  56. lc_free(glyph);
  57. lc_free(font);
  58. return 1;
  59. }
  60. /* lc_save_png("/tmp/out.png", bmp);*/
  61. lc_free(bmp);
  62. lc_free(glyph);
  63. lc_free(font);
  64. return 0;
  65. }
  66. int main() {
  67. assert(!create_bmp_glyph());
  68. assert(!rotate_bmp_180());
  69. return 0;
  70. }