pattern_basic.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 load_png_bmp() {
  21. char * filename = "../patterns/96c.png";
  22. lc_bmp *img = lc_load_png(filename);
  23. if (!img) {
  24. perror("lc_load_png()");
  25. return 1;
  26. }
  27. /* stbi_write_png("/tmp/glyph.png", img->w, img->h,*/
  28. /* img->ch, img->buffer, img->w * img->ch);*/
  29. lc_free(img);
  30. return 0;
  31. }
  32. static int crop_png_bmp() {
  33. char * filename = "../patterns/96c.png";
  34. lc_bmp *img = lc_load_png(filename);
  35. lc_bmp *cropped;
  36. if (!img) {
  37. perror("lc_load_png()");
  38. return 1;
  39. }
  40. cropped = lc_crop_bmp(img, 100, 90, 400, 280);
  41. if (!cropped) {
  42. perror("lc_crop_bmp()");
  43. return 1;
  44. }
  45. /* stbi_write_png("/tmp/glyph.png", cropped->w, cropped->h,*/
  46. /* cropped->ch, cropped->buffer, cropped->w * cropped->ch);*/
  47. lc_free(cropped);
  48. lc_free(img);
  49. return 0;
  50. }
  51. int main() {
  52. assert(!load_png_bmp());
  53. assert(!crop_png_bmp());
  54. return 0;
  55. }