1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
|
/* $OpenBSD: ss_scanjet.c,v 1.3 1996/04/21 22:31:17 deraadt Exp $ */
/* $NetBSD: ss_scanjet.c,v 1.3 1996/03/30 21:47:07 christos Exp $ */
/*
* Copyright (c) 1995 Kenneth Stailey. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Kenneth Stailey.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* special functions for the HP ScanJet IIc and IIcx
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/fcntl.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/malloc.h>
#include <sys/buf.h>
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/device.h>
#include <sys/conf.h> /* for cdevsw */
#include <sys/scanio.h>
#include <scsi/scsi_all.h>
#include <scsi/scsi_scanner.h>
#include <scsi/scsiconf.h>
#include <scsi/ssvar.h>
#define SCANJET_RETRIES 4
int scanjet_get_params __P((struct ss_softc *));
int scanjet_set_params __P((struct ss_softc *, struct scan_io *));
int scanjet_trigger_scanner __P((struct ss_softc *));
int scanjet_read __P((struct ss_softc *, struct buf *));
/* only used internally */
int scanjet_write __P((struct ss_softc *ss, char *buf, u_int size, int flags));
int scanjet_set_window __P((struct ss_softc *ss));
void scanjet_compute_sizes __P((struct ss_softc *));
/*
* structure for the special handlers
*/
struct ss_special scanjet_special = {
scanjet_set_params,
scanjet_trigger_scanner,
scanjet_get_params,
NULL, /* no special minphys */
scanjet_read, /* scsi 6-byte read */
NULL, /* no "rewind" code (yet?) */
NULL, /* no adf support right now */
NULL /* no adf support right now */
};
/*
* scanjet_attach: attach special functions to ss
*/
void
scanjet_attach(ss, sa)
struct ss_softc *ss;
struct scsibus_attach_args *sa;
{
#ifdef SCSIDEBUG
struct scsi_link *sc_link = sa->sa_sc_link;
#endif
SC_DEBUG(sc_link, SDEV_DB1, ("scanjet_attach: start\n"));
ss->sio.scan_scanner_type = 0;
printf("\n%s: ", ss->sc_dev.dv_xname);
/* first, check the model (which determines nothing yet) */
if (!bcmp(sa->sa_inqbuf->product, "C1750A", 6)) {
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
printf("HP ScanJet IIc\n");
}
if (!bcmp(sa->sa_inqbuf->product, "C2500A", 6)) {
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
printf("HP ScanJet IIcx\n");
}
SC_DEBUG(sc_link, SDEV_DB1, ("scanjet_attach: scanner_type = %d\n",
ss->sio.scan_scanner_type));
/* now install special handlers */
ss->special = &scanjet_special;
/*
* populate the scanio struct with legal values
*/
ss->sio.scan_width = 1200;
ss->sio.scan_height = 1200;
ss->sio.scan_x_resolution = 100;
ss->sio.scan_y_resolution = 100;
ss->sio.scan_x_origin = 0;
ss->sio.scan_y_origin = 0;
ss->sio.scan_brightness = 128;
ss->sio.scan_contrast = 128;
ss->sio.scan_quality = 100;
ss->sio.scan_image_mode = SIM_GRAYSCALE;
scanjet_compute_sizes(ss);
}
int
scanjet_get_params(ss)
struct ss_softc *ss;
{
return (0);
}
/*
* check the parameters if the scanjet is capable of fulfilling it
* but don't send the command to the scanner in case the user wants
* to change parameters by more than one call
*/
int
scanjet_set_params(ss, sio)
struct ss_softc *ss;
struct scan_io *sio;
{
#if 0
int error;
/*
* if the scanner is triggered, then rewind it
*/
if (ss->flags & SSF_TRIGGERED) {
error = scanjet_rewind_scanner(ss);
if (error)
return (error);
}
#endif
/* size constraints... */
if (sio->scan_width == 0 ||
sio->scan_x_origin + sio->scan_width > 10200 || /* 8.5" */
sio->scan_height == 0 ||
sio->scan_y_origin + sio->scan_height > 16800) /* 14" */
return (EINVAL);
/* resolution (dpi)... */
if (sio->scan_x_resolution < 100 ||
sio->scan_x_resolution > 400 ||
sio->scan_y_resolution < 100 ||
sio->scan_y_resolution > 400)
return (EINVAL);
switch (sio->scan_image_mode) {
case SIM_BINARY_MONOCHROME:
case SIM_DITHERED_MONOCHROME:
case SIM_GRAYSCALE:
case SIM_COLOR:
break;
default:
return (EINVAL);
}
/* change ss_softc to the new values, but save ro-variables */
sio->scan_scanner_type = ss->sio.scan_scanner_type;
bcopy(sio, &ss->sio, sizeof(struct scan_io));
scanjet_compute_sizes(ss);
return (0);
}
/*
* trigger the scanner to start a scan operation
* this includes sending the mode- and window-data,
* and starting the scanner
*/
int
scanjet_trigger_scanner(ss)
struct ss_softc *ss;
{
char escape_codes[20];
#ifdef SCSIDEBUG
struct scsi_link *sc_link = ss->sc_link;
#endif
int error;
scanjet_compute_sizes(ss);
/* send parameters */
error = scanjet_set_window(ss);
if (error) {
uprintf("set window failed\n");
return (error);
}
/* send "trigger" operation */
strcpy(escape_codes, "\033*f0S");
error = scanjet_write(ss, escape_codes, strlen(escape_codes), 0);
if (error) {
uprintf("trigger failed\n");
return (error);
}
return (0);
}
int
scanjet_read(ss, bp)
struct ss_softc *ss;
struct buf *bp;
{
struct scsi_rw_scanner cmd;
struct scsi_link *sc_link = ss->sc_link;
/*
* Fill out the scsi command
*/
bzero(&cmd, sizeof(cmd));
cmd.opcode = READ;
/*
* Handle "fixed-block-mode" tape drives by using the
* block count instead of the length.
*/
_lto3b(bp->b_bcount, cmd.len);
/*
* go ask the adapter to do all this for us
*/
if (scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd, sizeof(cmd),
(u_char *) bp->b_data, bp->b_bcount, SCANJET_RETRIES, 100000, bp,
SCSI_NOSLEEP | SCSI_DATA_IN) != SUCCESSFULLY_QUEUED)
printf("%s: not queued\n", ss->sc_dev.dv_xname);
else {
ss->sio.scan_window_size -= bp->b_bcount;
if (ss->sio.scan_window_size < 0)
ss->sio.scan_window_size = 0;
}
return (0);
}
/*
* Do a synchronous write. Used to send control messages.
*/
int
scanjet_write(ss, buf, size, flags)
struct ss_softc *ss;
char *buf;
u_int size;
int flags;
{
struct scsi_rw_scanner cmd;
/*
* If it's a null transfer, return immediatly
*/
if (size == 0)
return (0);
bzero(&cmd, sizeof(cmd));
cmd.opcode = WRITE;
_lto3b(size, cmd.len);
return (scsi_scsi_cmd(ss->sc_link, (struct scsi_generic *) &cmd,
sizeof(cmd), (u_char *) buf, size, 0, 100000, NULL,
flags | SCSI_DATA_OUT));
}
#ifdef SCANJETDEBUG
static void show_es(char *es)
{
char *p = es;
while (*p) {
if (*p == '\033')
printf("[Esc]");
else
printf("%c", *p);
++p;
}
printf("\n");
}
#endif
/*
* simulate SCSI_SET_WINDOW for ScanJets
*/
int
scanjet_set_window(ss)
struct ss_softc *ss;
{
char escape_codes[128], *p;
p = escape_codes;
sprintf(p, "\033*f%ldP", ss->sio.scan_width / 4);
p += strlen(p);
sprintf(p, "\033*f%ldQ", ss->sio.scan_height / 4);
p += strlen(p);
sprintf(p, "\033*f%ldX", ss->sio.scan_x_origin / 4);
p += strlen(p);
sprintf(p, "\033*f%ldY", ss->sio.scan_y_origin / 4);
p += strlen(p);
sprintf(p, "\033*a%dR", ss->sio.scan_x_resolution);
p += strlen(p);
sprintf(p, "\033*a%dS", ss->sio.scan_y_resolution);
p += strlen(p);
switch (ss->sio.scan_image_mode) {
case SIM_BINARY_MONOCHROME:
/* use "line art" mode */
strcpy(p, "\033*a0T");
p += strlen(p);
/* make image data be "min-is-white ala PBM */
strcpy(p, "\033*a0I");
p += strlen(p);
break;
case SIM_DITHERED_MONOCHROME:
/* use dithered mode */
strcpy(p, "\033*a3T");
p += strlen(p);
/* make image data be "min-is-white ala PBM */
strcpy(p, "\033*a0I");
p += strlen(p);
break;
case SIM_GRAYSCALE:
/* use grayscale mode */
strcpy(p, "\033*a4T");
p += strlen(p);
/* make image data be "min-is-black ala PGM */
strcpy(p, "\033*a1I");
p += strlen(p);
break;
case SIM_COLOR:
/* use RGB color mode */
strcpy(p, "\033*a5T");
p += strlen(p);
/* make image data be "min-is-black ala PPM */
strcpy(p, "\033*a1I");
p += strlen(p);
/* use pass-through matrix (disable NTSC) */
strcpy(p, "\033*u2T");
p += strlen(p);
}
sprintf(p, "\033*a%dG", ss->sio.scan_bits_per_pixel);
p += strlen(p);
sprintf(p, "\033*a%dL", (int)(ss->sio.scan_brightness) - 128);
p += strlen(p);
sprintf(p, "\033*a%dK", (int)(ss->sio.scan_contrast) - 128);
p += strlen(p);
return (scanjet_write(ss, escape_codes, p - escape_codes, 0));
}
void
scanjet_compute_sizes(ss)
struct ss_softc *ss;
{
int r = 0; /* round up by r 1/1200" */
/*
* Deal with the fact that the HP ScanJet IIc uses 1/300" not 1/1200"
* as its base unit of measurement. PINT uses 1/1200" (yes I know
* ScanJet II's use decipoints as well but 1200 % 720 != 0)
*/
ss->sio.scan_width = (ss->sio.scan_width + 3) & 0xfffffffc;
ss->sio.scan_height = (ss->sio.scan_height + 3) & 0xfffffffc;
switch (ss->sio.scan_image_mode) {
case SIM_BINARY_MONOCHROME:
case SIM_DITHERED_MONOCHROME:
ss->sio.scan_bits_per_pixel = 1;
break;
case SIM_GRAYSCALE:
r = 600;
ss->sio.scan_bits_per_pixel = 8;
break;
case SIM_COLOR:
r = 600;
ss->sio.scan_bits_per_pixel = 24;
break;
}
ss->sio.scan_pixels_per_line =
(ss->sio.scan_width * ss->sio.scan_x_resolution + r) / 1200;
if (ss->sio.scan_bits_per_pixel == 1)
/* pad to byte boundary: */
ss->sio.scan_pixels_per_line =
(ss->sio.scan_pixels_per_line + 7) & 0xfffffff8;
ss->sio.scan_lines =
(ss->sio.scan_height * ss->sio.scan_y_resolution + r) / 1200;
ss->sio.scan_window_size = ss->sio.scan_lines *
((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
}
/* $NetBSD: ss_scanjet.c,v 1.1 1996/02/18 20:32:49 mycroft Exp $ */
/*
* Copyright (c) 1995 Kenneth Stailey. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Kenneth Stailey.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* special functions for the HP ScanJet IIc and IIcx
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/fcntl.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/malloc.h>
#include <sys/buf.h>
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/device.h>
#include <sys/conf.h> /* for cdevsw */
#include <sys/scanio.h>
#include <scsi/scsi_all.h>
#include <scsi/scsi_scanner.h>
#include <scsi/scsiconf.h>
#include <scsi/ssvar.h>
#define SCANJET_RETRIES 4
int scanjet_get_params __P((struct ss_softc *));
int scanjet_set_params __P((struct ss_softc *, struct scan_io *));
int scanjet_trigger_scanner __P((struct ss_softc *));
int scanjet_read __P((struct ss_softc *, struct buf *));
/* only used internally */
int scanjet_write __P((struct ss_softc *ss, char *buf, u_int size, int flags));
int scanjet_set_window __P((struct ss_softc *ss));
void scanjet_compute_sizes __P((struct ss_softc *));
/*
* structure for the special handlers
*/
struct ss_special scanjet_special = {
scanjet_set_params,
scanjet_trigger_scanner,
scanjet_get_params,
NULL, /* no special minphys */
scanjet_read, /* scsi 6-byte read */
NULL, /* no "rewind" code (yet?) */
NULL, /* no adf support right now */
NULL /* no adf support right now */
};
/*
* scanjet_attach: attach special functions to ss
*/
void
scanjet_attach(ss, sa)
struct ss_softc *ss;
struct scsibus_attach_args *sa;
{
struct scsi_link *sc_link = sa->sa_sc_link;
SC_DEBUG(sc_link, SDEV_DB1, ("scanjet_attach: start\n"));
ss->sio.scan_scanner_type = 0;
/* first, check the model (which determines nothing yet) */
if (!bcmp(sa->sa_inqbuf->product, "C1750A", 6)) {
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
printf(": HP ScanJet IIc\n");
}
if (!bcmp(sa->sa_inqbuf->product, "C2500A", 6)) {
ss->sio.scan_scanner_type = HP_SCANJET_IIC;
printf(": HP ScanJet IIcx\n");
}
SC_DEBUG(sc_link, SDEV_DB1, ("mustek_attach: scanner_type = %d\n",
ss->sio.scan_scanner_type));
/* now install special handlers */
ss->special = &scanjet_special;
/*
* populate the scanio struct with legal values
*/
ss->sio.scan_width = 1200;
ss->sio.scan_height = 1200;
ss->sio.scan_x_resolution = 100;
ss->sio.scan_y_resolution = 100;
ss->sio.scan_x_origin = 0;
ss->sio.scan_y_origin = 0;
ss->sio.scan_brightness = 100;
ss->sio.scan_contrast = 100;
ss->sio.scan_quality = 100;
ss->sio.scan_image_mode = SIM_GRAYSCALE;
scanjet_compute_sizes(ss);
}
int
scanjet_get_params(ss)
struct ss_softc *ss;
{
return (0);
}
/*
* check the parameters if the scanjet is capable of fulfilling it
* but don't send the command to the scanner in case the user wants
* to change parameters by more than one call
*/
int
scanjet_set_params(ss, sio)
struct ss_softc *ss;
struct scan_io *sio;
{
int error;
#if 0
/*
* if the scanner is triggered, then rewind it
*/
if (ss->flags & SSF_TRIGGERED) {
error = scanjet_rewind_scanner(ss);
if (error)
return (error);
}
#endif
/* size constraints... */
if (sio->scan_width == 0 ||
sio->scan_x_origin + sio->scan_width > 10200 || /* 8.5" */
sio->scan_height == 0 ||
sio->scan_y_origin + sio->scan_height > 16800) /* 14" */
return (EINVAL);
/* resolution (dpi)... */
if (sio->scan_x_resolution < 100 ||
sio->scan_x_resolution > 400 ||
sio->scan_y_resolution < 100 ||
sio->scan_y_resolution > 400)
return (EINVAL);
switch (sio->scan_image_mode) {
case SIM_BINARY_MONOCHROME:
case SIM_DITHERED_MONOCHROME:
case SIM_GRAYSCALE:
case SIM_COLOR:
break;
default:
return (EINVAL);
}
/* change ss_softc to the new values, but save ro-variables */
sio->scan_scanner_type = ss->sio.scan_scanner_type;
bcopy(sio, &ss->sio, sizeof(struct scan_io));
scanjet_compute_sizes(ss);
return (0);
}
/*
* trigger the scanner to start a scan operation
* this includes sending the mode- and window-data,
* and starting the scanner
*/
int
scanjet_trigger_scanner(ss)
struct ss_softc *ss;
{
char escape_codes[20];
struct scsi_link *sc_link = ss->sc_link;
int error;
scanjet_compute_sizes(ss);
/* send parameters */
error = scanjet_set_window(ss);
if (error) {
uprintf("set window failed\n");
return (error);
}
/* send "trigger" operation */
strcpy(escape_codes, "\033*f0S");
error = scanjet_write(ss, escape_codes, strlen(escape_codes), 0);
if (error) {
uprintf("trigger failed\n");
return (error);
}
return (0);
}
int
scanjet_read(ss, bp)
struct ss_softc *ss;
struct buf *bp;
{
struct scsi_rw_scanner cmd;
struct scsi_link *sc_link = ss->sc_link;
/*
* Fill out the scsi command
*/
bzero(&cmd, sizeof(cmd));
cmd.opcode = READ;
/*
* Handle "fixed-block-mode" tape drives by using the
* block count instead of the length.
*/
lto3b(bp->b_bcount, cmd.len);
/*
* go ask the adapter to do all this for us
*/
if (scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd, sizeof(cmd),
(u_char *) bp->b_data, bp->b_bcount, SCANJET_RETRIES, 100000, bp,
SCSI_NOSLEEP | SCSI_DATA_IN) != SUCCESSFULLY_QUEUED)
printf("%s: not queued\n", ss->sc_dev.dv_xname);
else {
ss->sio.scan_window_size -= bp->b_bcount;
if (ss->sio.scan_window_size < 0)
ss->sio.scan_window_size = 0;
}
return (0);
}
/*
* Do a synchronous write. Used to send control messages.
*/
int
scanjet_write(ss, buf, size, flags)
struct ss_softc *ss;
char *buf;
u_int size;
int flags;
{
struct scsi_rw_scanner cmd;
/*
* If it's a null transfer, return immediatly
*/
if (size == 0)
return (0);
bzero(&cmd, sizeof(cmd));
cmd.opcode = WRITE;
lto3b(size, cmd.len);
return (scsi_scsi_cmd(ss->sc_link, (struct scsi_generic *) &cmd,
sizeof(cmd), (u_char *) buf, size, 0, 100000, NULL,
flags | SCSI_DATA_OUT));
}
#ifdef SCANJETDEBUG
static void show_es(char *es)
{
char *p = es;
while (*p) {
if (*p == '\033')
printf("[Esc]");
else
printf("%c", *p);
++p;
}
printf("\n");
}
#endif
/*
* simulate SCSI_SET_WINDOW for ScanJets
*/
int
scanjet_set_window(ss)
struct ss_softc *ss;
{
char escape_codes[128], *p;
p = escape_codes;
sprintf(p, "\033*f%dP", ss->sio.scan_width / 4);
p += strlen(p);
sprintf(p, "\033*f%dQ", ss->sio.scan_height / 4);
p += strlen(p);
sprintf(p, "\033*f%dX", ss->sio.scan_x_origin / 4);
p += strlen(p);
sprintf(p, "\033*f%dY", ss->sio.scan_y_origin / 4);
p += strlen(p);
sprintf(p, "\033*a%dR", ss->sio.scan_x_resolution);
p += strlen(p);
sprintf(p, "\033*a%dS", ss->sio.scan_y_resolution);
p += strlen(p);
switch (ss->sio.scan_image_mode) {
case SIM_BINARY_MONOCHROME:
/* use "line art" mode */
strcpy(p, "\033*a0T");
p += strlen(p);
/* make image data be "min-is-white ala PBM */
strcpy(p, "\033*a0I");
p += strlen(p);
break;
case SIM_DITHERED_MONOCHROME:
/* use dithered mode */
strcpy(p, "\033*a3T");
p += strlen(p);
/* make image data be "min-is-white ala PBM */
strcpy(p, "\033*a0I");
p += strlen(p);
break;
case SIM_GRAYSCALE:
/* use grayscale mode */
strcpy(p, "\033*a4T");
p += strlen(p);
/* make image data be "min-is-black ala PGM */
strcpy(p, "\033*a1I");
p += strlen(p);
break;
case SIM_COLOR:
/* use RGB color mode */
strcpy(p, "\033*a5T");
p += strlen(p);
/* make image data be "min-is-black ala PPM */
strcpy(p, "\033*a1I");
p += strlen(p);
/* use pass-through matrix (disable NTSC) */
strcpy(p, "\033*u2T");
p += strlen(p);
}
sprintf(p, "\033*a%dG", ss->sio.scan_bits_per_pixel);
p += strlen(p);
sprintf(p, "\033*a%dL", (int)(ss->sio.scan_brightness) - 128);
p += strlen(p);
sprintf(p, "\033*a%dK", (int)(ss->sio.scan_contrast) - 128);
p += strlen(p);
return (scanjet_write(ss, escape_codes, p - escape_codes, 0));
}
void
scanjet_compute_sizes(ss)
struct ss_softc *ss;
{
/*
* Deal with the fact that the HP ScanJet IIc uses 1/300" not 1/1200"
* as its base unit of measurement. PINT uses 1/1200" (yes I know
* ScanJet II's use decipoints as well but 1200 % 720 != 0)
*/
ss->sio.scan_width = (ss->sio.scan_width + 3) & 0xfffffffc;
ss->sio.scan_height = (ss->sio.scan_height + 3) & 0xfffffffc;
switch (ss->sio.scan_image_mode) {
case SIM_BINARY_MONOCHROME:
case SIM_DITHERED_MONOCHROME:
ss->sio.scan_bits_per_pixel = 1;
break;
case SIM_GRAYSCALE:
ss->sio.scan_bits_per_pixel = 8;
break;
case SIM_COLOR:
ss->sio.scan_bits_per_pixel = 24;
break;
}
ss->sio.scan_pixels_per_line =
(ss->sio.scan_width * ss->sio.scan_x_resolution) / 1200;
if (ss->sio.scan_bits_per_pixel == 1)
/* pad to byte boundary: */
ss->sio.scan_pixels_per_line =
(ss->sio.scan_pixels_per_line + 7) & 0xfffffff8;
ss->sio.scan_lines =
(ss->sio.scan_height * ss->sio.scan_y_resolution) / 1200;
ss->sio.scan_window_size = ss->sio.scan_lines *
((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
}
|