draw_bitmap.c 550 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "psdriver.h"
  2. void PS_Bitmap(int ncols, int nrows, int threshold,
  3. const unsigned char *buf)
  4. {
  5. int i, j;
  6. output("%d %d %d %d BITMAP\n", cur_x, cur_y, ncols, nrows);
  7. for (j = 0; j < nrows; j++) {
  8. unsigned int bit = 0x80;
  9. unsigned int acc = 0;
  10. for (i = 0; i < ncols; i++) {
  11. unsigned int k = buf[j * ncols + i];
  12. if (k > threshold)
  13. acc |= bit;
  14. bit >>= 1;
  15. if (!bit) {
  16. output("%02X", acc);
  17. bit = 0x80;
  18. acc = 0;
  19. }
  20. }
  21. if (bit != 0x80)
  22. output("%02X", acc);
  23. output("\n");
  24. }
  25. }