X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/rigol/blobdiff_plain/3df147113765d5a8ba192795d2be9b7e3e295749..2d17f2ab31a270ebbac95879fef6c7d3176d1960:/rigol.c diff --git a/rigol.c b/rigol.c index 389253f..0e9ff9e 100644 --- a/rigol.c +++ b/rigol.c @@ -302,15 +302,13 @@ void do_get_buf (struct usb_dev_handle *sc) void do_get_screen(struct usb_dev_handle *sc) { unsigned char screen[320*234]; - unsigned char screen_conv[320*234*3]; - unsigned char lut[256][3]; time_t lt; char filename[256]; unsigned char *png; - int i; + int imglen; + int ret; int l; int fd; - FILE *fp; pid_t display; /* Hide "RMT" from screen */ @@ -323,25 +321,26 @@ void do_get_screen(struct usb_dev_handle *sc) printf ("hmm. didnt' get %d bytes, but %d\n\n", sizeof(screen), l); } - for(i = 0; i < 256; i++) { - lut[i][0] = ((i >> 6) * 0x55); - lut[i][1] = ((((i >> 3) & 7) * 0x49) >> 1); - lut[i][2] = (((i & 7) * 0x49) >> 1); - } - - for(i = 0; i < sizeof(screen_conv); i += 3) { - screen_conv[i] = lut[screen[i/3]][0]; - screen_conv[i+1] = lut[screen[i/3]][1]; - screen_conv[i+2] = lut[screen[i/3]][2]; - } + png = lcd2png(screen, &imglen); lt = time(NULL); - strftime(filename, sizeof(filename), "screen_%Y%m%d-%H%M%S.ppm", localtime(<)); + strftime(filename, sizeof(filename), "screen_%Y%m%d-%H%M%S.png", localtime(<)); + fd=open(filename, O_CREAT|O_WRONLY, 0644); + if (fd == -1) { + perror("open"); + exit(EXIT_FAILURE); + } - fp = fopen (filename, "w"); - fprintf(fp, "P6\n320 234\n255\n"); - fwrite(screen_conv, sizeof(screen_conv), 1, fp); - fclose (fp); + while(imglen > 0) { + ret = write(fd, png, imglen); + if (ret == -1) { + perror("write"); + exit(EXIT_FAILURE); + } + imglen -= ret; + } + close(fd); + free(png); printf("Waveform saved as %s\n", filename); @@ -357,12 +356,6 @@ void do_get_screen(struct usb_dev_handle *sc) default: break; } - - strftime(filename, sizeof(filename), "screen_%Y%m%d-%H%M%S.png", localtime(<)); - fd=open(filename, O_CREAT|O_WRONLY, 0644); - png = lcd2png(screen, &i); - write(fd, png, i); - close(fd); } void child_reaper(int sig)