1
0
mirror of https://git.familie-radermacher.ch/linux/ptouch-print.git synced 2025-05-13 23:32:59 +00:00

part 1 of preparing support for high-dpi devices

This commit is contained in:
Dominic Radermacher 2019-12-17 21:11:17 +01:00
parent 815aaf1992
commit 9509424d56
3 changed files with 18 additions and 11 deletions

View File

@ -22,7 +22,7 @@
struct _pt_tape_info { struct _pt_tape_info {
uint8_t mm; /* Tape width in mm */ uint8_t mm; /* Tape width in mm */
uint8_t px; /* Printing area in px */ uint16_t px; /* Printing area in px */
double margins; /* default tape margins in mm */ double margins; /* default tape margins in mm */
}; };
@ -86,7 +86,7 @@ int ptouch_init(ptouch_dev ptdev);
int ptouch_lf(ptouch_dev ptdev); int ptouch_lf(ptouch_dev ptdev);
int ptouch_ff(ptouch_dev ptdev); int ptouch_ff(ptouch_dev ptdev);
size_t ptouch_get_max_pixel_width(ptouch_dev ptdev); size_t ptouch_get_max_pixel_width(ptouch_dev ptdev);
int ptouch_get_tape_pixel_width(ptouch_dev ptdev); size_t ptouch_get_tape_width(ptouch_dev ptdev);
int ptouch_page_flags(ptouch_dev ptdev, uint8_t page_flags); int ptouch_page_flags(ptouch_dev ptdev, uint8_t page_flags);
int ptouch_eject(ptouch_dev ptdev); int ptouch_eject(ptouch_dev ptdev);
int ptouch_getstatus(ptouch_dev ptdev); int ptouch_getstatus(ptouch_dev ptdev);

View File

@ -288,11 +288,16 @@ int ptouch_getstatus(ptouch_dev ptdev)
return -1; return -1;
} }
int ptouch_getmaxwidth(ptouch_dev ptdev) size_t ptouch_get_tape_width(ptouch_dev ptdev)
{ {
return ptdev->tape_width_px; return ptdev->tape_width_px;
} }
size_t ptouch_get_max_width(ptouch_dev ptdev)
{
return ptdev->devinfo->max_px;
}
int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len) int ptouch_sendraster(ptouch_dev ptdev, uint8_t *data, size_t len)
{ {
uint8_t buf[64]; uint8_t buf[64];

View File

@ -34,7 +34,7 @@
#define MAX_LINES 4 /* maybe this should depend on tape size */ #define MAX_LINES 4 /* maybe this should depend on tape size */
gdImage *image_load(const char *file); gdImage *image_load(const char *file);
void rasterline_setpixel(uint8_t rasterline[16], int pixel); void rasterline_setpixel(uint8_t* rasterline, size_t size, int pixel);
int get_baselineoffset(char *text, char *font, int fsz); int get_baselineoffset(char *text, char *font, int fsz);
int find_fontsize(int want_px, char *font, char *text); int find_fontsize(int want_px, char *font, char *text);
int needed_width(char *text, char *font, int fsz); int needed_width(char *text, char *font, int fsz);
@ -58,25 +58,27 @@ bool debug=false;
/* -------------------------------------------------------------------- /* --------------------------------------------------------------------
-------------------------------------------------------------------- */ -------------------------------------------------------------------- */
void rasterline_setpixel(uint8_t rasterline[16], int pixel) void rasterline_setpixel(uint8_t* rasterline, size_t size, int pixel)
{ {
if (pixel > 128) { // TODO: pixel should be unsigned, since we can't have negative
// if (pixel > ptdev->devinfo->device_max_px) {
if (pixel > (int)(size*8)) {
return; return;
} }
rasterline[15-(pixel/8)] |= (uint8_t)(1<<(pixel%8)); rasterline[(size-1)-(pixel/8)] |= (uint8_t)(1<<(pixel%8));
return; return;
} }
int print_img(ptouch_dev ptdev, gdImage *im) int print_img(ptouch_dev ptdev, gdImage *im)
{ {
int d,i,k,offset,tape_width; int d,i,k,offset,tape_width;
uint8_t rasterline[16]; uint8_t rasterline[(ptdev->devinfo->max_px)/8];
if (!im) { if (!im) {
printf(_("nothing to print\n")); printf(_("nothing to print\n"));
return -1; return -1;
} }
tape_width=ptouch_getmaxwidth(ptdev); tape_width=ptouch_get_tape_width(ptdev);
/* find out whether color 0 or color 1 is darker */ /* find out whether color 0 or color 1 is darker */
d=(gdImageRed(im,1)+gdImageGreen(im,1)+gdImageBlue(im,1) < gdImageRed(im,0)+gdImageGreen(im,0)+gdImageBlue(im,0))?1:0; d=(gdImageRed(im,1)+gdImageGreen(im,1)+gdImageBlue(im,1) < gdImageRed(im,0)+gdImageGreen(im,0)+gdImageBlue(im,0))?1:0;
if (gdImageSY(im) > tape_width) { if (gdImageSY(im) > tape_width) {
@ -99,7 +101,7 @@ int print_img(ptouch_dev ptdev, gdImage *im)
memset(rasterline, 0, sizeof(rasterline)); memset(rasterline, 0, sizeof(rasterline));
for (i=0; i<gdImageSY(im); i+=1) { for (i=0; i<gdImageSY(im); i+=1) {
if (gdImageGetPixel(im, k, gdImageSY(im)-1-i) == d) { if (gdImageGetPixel(im, k, gdImageSY(im)-1-i) == d) {
rasterline_setpixel(rasterline, offset+i); rasterline_setpixel(rasterline, sizeof(rasterline), offset+i);
} }
} }
if (ptouch_sendraster(ptdev, rasterline, 16) != 0) { if (ptouch_sendraster(ptdev, rasterline, 16) != 0) {
@ -459,7 +461,7 @@ int main(int argc, char *argv[])
printf(_("ptouch_getstatus() failed\n")); printf(_("ptouch_getstatus() failed\n"));
return 1; return 1;
} }
tape_width=ptouch_getmaxwidth(ptdev); tape_width=ptouch_get_tape_width(ptdev);
for (i=1; i<argc; i++) { for (i=1; i<argc; i++) {
if (*argv[i] != '-') { if (*argv[i] != '-') {
break; break;