ida_2d.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * ida_2d.c
  3. *
  4. * This code uses Zint to encode data into a QR Code and then outputs
  5. * the symbol as text suitable for use with the IDAutomation2D font
  6. *
  7. * This code can be adapted to use any matrix symbology by changing the
  8. * line indicated.
  9. *
  10. * This code can be compiled with:
  11. *
  12. * gcc -o ida_2d ida_2d.c -lzint
  13. *
  14. * Fonts can be downloaded from https://www.idautomation.com/
  15. *
  16. */
  17. #include <stdio.h>
  18. #include <zint.h>
  19. #include <string.h>
  20. int main(int argc, char **argv)
  21. {
  22. struct zint_symbol *my_symbol;
  23. int error = 0;
  24. int x, y, sub, glyph;
  25. my_symbol = ZBarcode_Create();
  26. my_symbol->symbology = BARCODE_QRCODE; // Change symbology here
  27. my_symbol->output_options = OUT_BUFFER_INTERMEDIATE;
  28. error = ZBarcode_Encode(my_symbol, argv[1], strlen(argv[1]));
  29. if (error != 0)
  30. {
  31. printf("%s\n", my_symbol->errtxt);
  32. }
  33. if (error >= ZINT_ERROR_TOO_LONG)
  34. {
  35. ZBarcode_Delete(my_symbol);
  36. return 1;
  37. }
  38. for (y = 0; y < my_symbol->rows; y += 4) {
  39. for (x = 0; x < my_symbol->width; x++) {
  40. glyph = 0;
  41. for (sub = 0; sub < 4; sub++) {
  42. glyph *= 2;
  43. if ((y + sub) < my_symbol->rows) {
  44. if (((my_symbol->encoded_data[y + sub][x / 8] >> (x % 8)) & 1) == 0) {
  45. glyph += 1;
  46. }
  47. } else {
  48. glyph += 1;
  49. }
  50. }
  51. glyph += 'A';
  52. printf("%c", glyph);
  53. }
  54. printf("\n");
  55. }
  56. ZBarcode_Delete(my_symbol);
  57. return 0;
  58. }