1 /* $NetBSD: ss_mustek.c,v 1.6 1996/10/12 23:23:21 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1995 Joachim Koenig-Baltes. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Joachim Koenig-Baltes. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * special driver for MUSTEK flatbed scanners MFS 06000CX and MFS 12000CX 34 * these scanners come with their own scsi card, containing an NCR53C400 35 * SCSI controller chip. I'm in the progress of writing a driver for this 36 * card to work under NetBSD-current. I've hooked it up to a Seagate ST01 37 * hostadapter in the meantime, giving 350KB/sec for higher resolutions! 38 * 39 * I tried to connect it to my Adaptec 1542B, but with no success. It seems, 40 * it does not like synchronous negotiation between Hostadapter and other 41 * targets, but I could not turn this off for the 1542B. 42 * 43 * There is also an other reason why you would not like to connect it to your 44 * favourite SCSI host adapter: The Mustek DOES NOT DISCONNECT. It will block 45 * other traffic from the bus while a transfer is active. 46 */ 47 48 #include <sys/types.h> 49 #include <sys/param.h> 50 #include <sys/kernel.h> 51 #include <sys/systm.h> 52 #include <sys/fcntl.h> 53 #include <sys/errno.h> 54 #include <sys/ioctl.h> 55 #include <sys/malloc.h> 56 #include <sys/buf.h> 57 #include <sys/proc.h> 58 #include <sys/user.h> 59 #include <sys/device.h> 60 #include <sys/conf.h> /* for cdevsw */ 61 #include <sys/scanio.h> 62 63 #include <scsi/scsi_all.h> 64 #include <scsi/scsi_scanner.h> 65 #include <scsi/scsiconf.h> 66 #include <scsi/ssvar.h> 67 #include <scsi/ss_mustek.h> 68 69 #define MUSTEK_RETRIES 4 70 71 int mustek_get_params __P((struct ss_softc *)); 72 int mustek_set_params __P((struct ss_softc *, struct scan_io *)); 73 int mustek_trigger_scanner __P((struct ss_softc *)); 74 void mustek_minphys __P((struct ss_softc *, struct buf *)); 75 int mustek_read __P((struct ss_softc *, struct buf *)); 76 int mustek_rewind_scanner __P((struct ss_softc *)); 77 78 /* only used internally */ 79 int mustek_get_status __P((struct ss_softc *, int, int)); 80 void mustek_compute_sizes __P((struct ss_softc *)); 81 82 /* 83 * structure for the special handlers 84 */ 85 struct ss_special mustek_special = { 86 mustek_set_params, 87 mustek_trigger_scanner, 88 mustek_get_params, 89 mustek_minphys, 90 mustek_read, 91 mustek_rewind_scanner, 92 NULL, /* no adf support right now */ 93 NULL /* no adf support right now */ 94 }; 95 96 /* 97 * mustek_attach: attach special functions to ss 98 */ 99 void 100 mustek_attach(ss, sa) 101 struct ss_softc *ss; 102 struct scsibus_attach_args *sa; 103 { 104 #ifdef SCSIDEBUG 105 struct scsi_link *sc_link = sa->sa_sc_link; 106 #endif 107 108 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_attach: start\n")); 109 ss->sio.scan_scanner_type = 0; 110 111 printf("\n%s: ", ss->sc_dev.dv_xname); 112 113 /* first, check the model which determines resolutions */ 114 if (!bcmp(sa->sa_inqbuf->product, "MFS-06000CX", 11)) { 115 ss->sio.scan_scanner_type = MUSTEK_06000CX; 116 printf("Mustek 6000CX Flatbed 3-pass color scanner, 3 - 600 dpi\n"); 117 } 118 if (!bcmp(sa->sa_inqbuf->product, "MFS-12000CX", 11)) { 119 ss->sio.scan_scanner_type = MUSTEK_12000CX; 120 printf("Mustek 12000CX Flatbed 3-pass color scanner, 6 - 1200 dpi\n"); 121 } 122 123 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_attach: scanner_type = %d\n", 124 ss->sio.scan_scanner_type)); 125 126 /* install special handlers */ 127 ss->special = &mustek_special; 128 129 /* 130 * populate the scanio struct with legal values 131 * the default should come from user space 132 */ 133 ss->sio.scan_width = 1200; 134 ss->sio.scan_height = 1200; 135 ss->sio.scan_x_resolution = 99; 136 ss->sio.scan_y_resolution = 99; 137 ss->sio.scan_x_origin = 0; 138 ss->sio.scan_y_origin = 0; 139 ss->sio.scan_brightness = 100; 140 ss->sio.scan_contrast = 100; 141 ss->sio.scan_quality = 100; 142 ss->sio.scan_image_mode = SIM_GRAYSCALE; 143 144 mustek_compute_sizes(ss); 145 } 146 147 int 148 mustek_get_params (ss) 149 struct ss_softc *ss; 150 { 151 152 return (0); 153 } 154 155 /* 156 * check the parameters if the mustek is capable of fulfilling it 157 * but don't send the command to the scanner in case the user wants 158 * to change parameters by more than one call 159 */ 160 int 161 mustek_set_params(ss, sio) 162 struct ss_softc *ss; 163 struct scan_io *sio; 164 { 165 int error; 166 167 /* 168 * if the scanner is triggered, then rewind it 169 */ 170 if (ss->flags & SSF_TRIGGERED) { 171 error = mustek_rewind_scanner(ss); 172 if (error) 173 return (error); 174 } 175 176 /* size constraints: 8.5" horizontally and 14" vertically */ 177 #ifdef MUSTEK_INCH_SPEC 178 /* sizes must be a multiple of 1/8" */ 179 sio->scan_x_origin -= sio->scan_x_origin % 150; 180 sio->scan_y_origin -= sio->scan_y_origin % 150; 181 sio->scan_width -= sio->scan_width % 150; 182 sio->scan_height -= sio->scan_height % 150; 183 #endif 184 if (sio->scan_width == 0 || 185 sio->scan_x_origin + sio->scan_width > 10200 || 186 sio->scan_height == 0 || 187 sio->scan_y_origin + sio->scan_height > 16800) 188 return (EINVAL); 189 190 /* 191 * for now, only realize the values for the MUSTEK_06000CX 192 * in the future, values for the MUSTEK_12000CX will be implemented 193 */ 194 195 /* 196 * resolution (dpi) must be <= 300 and a multiple of 3 or 197 * between 300 and 600 and a multiple of 30 198 */ 199 sio->scan_x_resolution -= sio->scan_x_resolution <= 300 ? 200 sio->scan_x_resolution % 3 : sio->scan_x_resolution % 30; 201 sio->scan_y_resolution -= sio->scan_y_resolution <= 300 ? 202 sio->scan_y_resolution % 3 : sio->scan_y_resolution % 30; 203 if (sio->scan_x_resolution < 3 || sio->scan_x_resolution > 600 || 204 sio->scan_x_resolution != sio->scan_y_resolution) 205 return (EINVAL); 206 207 /* assume brightness values are between 64 and 136 in steps of 3 */ 208 sio->scan_brightness -= (sio->scan_brightness - 64) % 3; 209 if (sio->scan_brightness < 64 || sio->scan_brightness > 136) 210 return (EINVAL); 211 212 /* contrast values must be between 16 and 184 in steps of 7 */ 213 sio->scan_contrast -= (sio->scan_contrast - 16) % 7; 214 if (sio->scan_contrast < 16 || sio->scan_contrast > 184) 215 return (EINVAL); 216 217 /* 218 * velocity: between 0 (fast) and 4 (slow) which will be mapped 219 * to 100% = 4, 80% = 3, 60% = 2, 40% = 1, 20% = 0 220 * must be a multiple of 20 221 */ 222 sio->scan_quality -= sio->scan_quality % 20; 223 if (sio->scan_quality < 20 || sio->scan_quality > 100) 224 return (EINVAL); 225 226 switch (sio->scan_image_mode) { 227 case SIM_BINARY_MONOCHROME: 228 case SIM_DITHERED_MONOCHROME: 229 case SIM_GRAYSCALE: 230 case SIM_RED: 231 case SIM_GREEN: 232 case SIM_BLUE: 233 break; 234 default: 235 return (EINVAL); 236 } 237 238 /* change ss_softc to the new values, but save ro-variables */ 239 sio->scan_scanner_type = ss->sio.scan_scanner_type; 240 bcopy(sio, &ss->sio, sizeof(struct scan_io)); 241 242 mustek_compute_sizes(ss); 243 244 return (0); 245 } 246 247 /* 248 * trim the requested transfer to a multiple of the line size 249 * this is called only from ssread() which guarantees, scanner is triggered 250 * In the future, it will trim the transfer to not read to much at a time 251 * because the mustek cannot disconnect. It will be calculated by the 252 * resolution, the velocity and the number of bytes per line. 253 */ 254 void 255 mustek_minphys(ss, bp) 256 struct ss_softc *ss; 257 struct buf *bp; 258 { 259 #ifdef SCSIDEBUG 260 struct scsi_link *sc_link = ss->sc_link; 261 #endif 262 263 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_minphys: before: %ld\n", 264 bp->b_bcount)); 265 bp->b_bcount -= bp->b_bcount % 266 ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8); 267 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_minphys: after: %ld\n", 268 bp->b_bcount)); 269 } 270 271 /* 272 * trigger the scanner to start a scan operation 273 * this includes sending the mode- and window-data, starting the scanner 274 * and getting the image size info 275 */ 276 int 277 mustek_trigger_scanner(ss) 278 struct ss_softc *ss; 279 { 280 struct mustek_mode_select_cmd mode_cmd; 281 struct mustek_mode_select_data mode_data; 282 struct mustek_set_window_cmd window_cmd; 283 struct mustek_set_window_data window_data; 284 struct mustek_start_scan_cmd start_scan_cmd; 285 struct scsi_link *sc_link = ss->sc_link; 286 int pixel_tlx, pixel_tly, pixel_brx, pixel_bry, paperlength; 287 int error; 288 289 mustek_compute_sizes(ss); 290 291 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_trigger_scanner\n")); 292 293 /* 294 * set the window params and send the scsi command 295 */ 296 bzero(&window_cmd, sizeof(window_cmd)); 297 window_cmd.opcode = MUSTEK_SET_WINDOW; 298 window_cmd.length = sizeof(window_data); 299 300 bzero(&window_data, sizeof(window_data)); 301 window_data.frame.header = MUSTEK_LINEART_BACKGROUND | MUSTEK_UNIT_SPEC; 302 #ifdef MUSTEK_INCH_SPEC 303 /* the positional values are all 1 byte because 256 / 8 = 32" */ 304 pixel_tlx = ss->sio.scan_x_origin / 150; 305 pixel_tly = ss->sio.scan_y_origin / 150; 306 pixel_brx = pixel_tlx + ss->sio.scan_width / 150; 307 pixel_bry = pixel_tly + ss->sio.scan_height / 150; 308 #else 309 pixel_tlx = (ss->sio.scan_x_origin * ss->sio.scan_x_resolution) / 1200; 310 pixel_tly = (ss->sio.scan_y_origin * ss->sio.scan_y_resolution) / 1200; 311 pixel_brx = pixel_tlx + 312 (ss->sio.scan_width * ss->sio.scan_x_resolution) / 1200; 313 pixel_bry = pixel_tly + 314 (ss->sio.scan_height * ss->sio.scan_y_resolution) / 1200; 315 #endif 316 _lto2l(pixel_tlx, window_data.frame.tl_x); 317 _lto2l(pixel_tly, window_data.frame.tl_y); 318 _lto2l(pixel_brx, window_data.frame.br_x); 319 _lto2l(pixel_bry, window_data.frame.br_y); 320 321 #if MUSTEK_WINDOWS >= 1 322 window_data.window1 = window_data.frame; 323 window_data.window1.header = MUSTEK_WINDOW_MASK | MUSTEK_UNIT_SPEC; 324 #endif 325 326 /* send the set window command to the scanner */ 327 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_set_parms: set_window\n")); 328 error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &window_cmd, 329 sizeof(window_cmd), (u_char *) &window_data, sizeof(window_data), 330 MUSTEK_RETRIES, 5000, NULL, SCSI_DATA_OUT); 331 if (error) 332 return (error); 333 334 /* 335 * do what it takes to actualize the mode 336 */ 337 bzero(&mode_cmd, sizeof(mode_cmd)); 338 mode_cmd.opcode = MUSTEK_MODE_SELECT; 339 _lto2b(sizeof(mode_data), mode_cmd.length); 340 341 bzero(&mode_data, sizeof(mode_data)); 342 mode_data.mode = 343 MUSTEK_MODE_MASK | MUSTEK_HT_PATTERN_BUILTIN | MUSTEK_UNIT_SPEC; 344 if (ss->sio.scan_x_resolution <= 300) { 345 mode_data.resolution = ss->sio.scan_x_resolution / 3; 346 } else { 347 /* 348 * the resolution values is computed by modulo 100, but not 349 * for 600dpi, where the value is 100 (a bit tricky, but ...) 350 */ 351 mode_data.resolution = 352 ((ss->sio.scan_x_resolution - 1) % 100) + 1; 353 } 354 mode_data.brightness = (ss->sio.scan_brightness - 64) / 3; 355 mode_data.contrast = (ss->sio.scan_contrast - 16) / 7; 356 mode_data.grain = 0; 357 mode_data.velocity = ss->sio.scan_quality / 20 - 1; 358 #ifdef MUSTEK_INCH_SPEC 359 paperlength = 14 * 8; /* 14" */ 360 #else 361 paperlength = 14 * ss->sio.scan_y_resolution; /* 14" */ 362 #endif 363 _lto2l(paperlength, mode_data.paperlength); 364 365 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_trigger_scanner: mode_select\n")); 366 /* send the command to the scanner */ 367 error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &mode_cmd, 368 sizeof(mode_cmd), (u_char *) &mode_data, sizeof(mode_data), 369 MUSTEK_RETRIES, 5000, NULL, SCSI_DATA_OUT); 370 if (error) 371 return (error); 372 373 /* 374 * now construct and send the start command 375 */ 376 bzero(&start_scan_cmd,sizeof(start_scan_cmd)); 377 start_scan_cmd.opcode = MUSTEK_START_STOP; 378 start_scan_cmd.mode = MUSTEK_SCAN_START; 379 if (ss->sio.scan_x_resolution <= 300) 380 start_scan_cmd.mode |= MUSTEK_RES_STEP_1; 381 else 382 start_scan_cmd.mode |= MUSTEK_RES_STEP_10; 383 switch (ss->sio.scan_image_mode) { 384 case SIM_BINARY_MONOCHROME: 385 case SIM_DITHERED_MONOCHROME: 386 start_scan_cmd.mode |= MUSTEK_BIT_MODE | MUSTEK_GRAY_FILTER; 387 break; 388 case SIM_GRAYSCALE: 389 start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_GRAY_FILTER; 390 break; 391 case SIM_RED: 392 start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_RED_FILTER; 393 break; 394 case SIM_GREEN: 395 start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_GREEN_FILTER; 396 break; 397 case SIM_BLUE: 398 start_scan_cmd.mode |= MUSTEK_GRAY_MODE | MUSTEK_BLUE_FILTER; 399 break; 400 } 401 402 /* send the command to the scanner */ 403 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_trigger_scanner: start_scan\n")); 404 error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &start_scan_cmd, 405 sizeof(start_scan_cmd), NULL, 0, 406 MUSTEK_RETRIES, 5000, NULL, 0); 407 if (error) 408 return (error); 409 410 /* 411 * now check if scanner ready this time with update of size info 412 * we wait here so that if the user issues a read directly afterwards, 413 * the scanner will respond directly (otherwise we had to sleep with 414 * a buffer locked in memory) 415 */ 416 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_trigger_scanner: get_status\n")); 417 error = mustek_get_status(ss, 60, 1); 418 if (error) 419 return (error); 420 421 return (0); 422 } 423 424 /* 425 * stop a scan operation in progress 426 */ 427 int 428 mustek_rewind_scanner(ss) 429 struct ss_softc *ss; 430 { 431 struct mustek_start_scan_cmd cmd; 432 struct scsi_link *sc_link = ss->sc_link; 433 int error; 434 435 if (ss->sio.scan_window_size != 0) { 436 /* 437 * only if not all data has been read, the scanner has to be 438 * stopped 439 */ 440 bzero(&cmd, sizeof(cmd)); 441 cmd.opcode = MUSTEK_START_STOP; 442 cmd.mode = MUSTEK_SCAN_STOP; 443 444 /* send the command to the scanner */ 445 SC_DEBUG(sc_link, SDEV_DB1, 446 ("mustek_rewind_scanner: stop_scan\n")); 447 error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd, 448 sizeof(cmd), NULL, 0, MUSTEK_RETRIES, 5000, NULL, 0); 449 if (error) 450 return (error); 451 } 452 453 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_rewind_scanner: end\n")); 454 455 return (0); 456 } 457 458 /* 459 * read the requested number of bytes/lines from the scanner 460 */ 461 int 462 mustek_read(ss, bp) 463 struct ss_softc *ss; 464 struct buf *bp; 465 { 466 struct mustek_read_cmd cmd; 467 struct scsi_link *sc_link = ss->sc_link; 468 u_long lines_to_read; 469 470 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_read: start\n")); 471 472 bzero(&cmd, sizeof(cmd)); 473 cmd.opcode = MUSTEK_READ; 474 475 /* instead of the bytes, the mustek wants the number of lines */ 476 lines_to_read = bp->b_bcount / 477 ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8); 478 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_read: read %ld lines\n", 479 lines_to_read)); 480 _lto3b(lines_to_read, cmd.length); 481 482 /* 483 * go ask the adapter to do all this for us 484 */ 485 if (scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd, sizeof(cmd), 486 (u_char *) bp->b_data, bp->b_bcount, MUSTEK_RETRIES, 10000, bp, 487 SCSI_NOSLEEP | SCSI_DATA_IN) != SUCCESSFULLY_QUEUED) 488 printf("%s: not queued\n", ss->sc_dev.dv_xname); 489 else { 490 ss->sio.scan_lines -= lines_to_read; 491 ss->sio.scan_window_size -= bp->b_bcount; 492 } 493 494 return (0); 495 } 496 497 /* 498 * check if the scanner is ready to take commands 499 * wait timeout seconds and try only every second 500 * if update, then update picture size info 501 * 502 * returns EBUSY if scanner not ready 503 */ 504 int 505 mustek_get_status(ss, timeout, update) 506 struct ss_softc *ss; 507 int timeout, update; 508 { 509 struct mustek_get_status_cmd cmd; 510 struct mustek_get_status_data data; 511 struct scsi_link *sc_link = ss->sc_link; 512 int error, lines, bytes_per_line; 513 514 bzero(&cmd, sizeof(cmd)); 515 cmd.opcode = MUSTEK_GET_STATUS; 516 cmd.length = sizeof(data); 517 518 while (1) { 519 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_get_status: stat_cmd\n")); 520 error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd, 521 sizeof(cmd), (u_char *) &data, sizeof(data), MUSTEK_RETRIES, 522 5000, NULL, SCSI_DATA_IN); 523 if (error) 524 return (error); 525 if ((data.ready_busy == MUSTEK_READY) || 526 (timeout-- <= 0)) 527 break; 528 /* please wait a second */ 529 tsleep((caddr_t)mustek_get_status, PRIBIO + 1, "mtkrdy", hz); 530 } 531 532 if (update) { 533 bytes_per_line = _2ltol(data.bytes_per_line); 534 lines = _3ltol(data.lines); 535 if (lines != ss->sio.scan_lines) { 536 printf("mustek: lines actual(%d) != computed(%ld)\n", 537 lines, ss->sio.scan_lines); 538 return (EIO); 539 } 540 if (bytes_per_line * lines != ss->sio.scan_window_size) { 541 printf("mustek: win-size actual(%d) != computed(%ld)\n", 542 bytes_per_line * lines, ss->sio.scan_window_size); 543 return (EIO); 544 } 545 546 SC_DEBUG(sc_link, SDEV_DB1, 547 ("mustek_get_size: bpl=%ld, lines=%ld\n", 548 (ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8, 549 ss->sio.scan_lines)); 550 SC_DEBUG(sc_link, SDEV_DB1, ("window size = %ld\n", 551 ss->sio.scan_window_size)); 552 } 553 554 SC_DEBUG(sc_link, SDEV_DB1, ("mustek_get_status: end\n")); 555 if (data.ready_busy == MUSTEK_READY) 556 return (0); 557 else 558 return (EBUSY); 559 } 560 561 /* 562 * mustek_compute_sizes: compute window_size and lines for the picture 563 * this function is called from different places in the code 564 */ 565 void 566 mustek_compute_sizes(ss) 567 struct ss_softc *ss; 568 { 569 570 switch (ss->sio.scan_image_mode) { 571 case SIM_BINARY_MONOCHROME: 572 case SIM_DITHERED_MONOCHROME: 573 ss->sio.scan_bits_per_pixel = 1; 574 break; 575 case SIM_GRAYSCALE: 576 case SIM_RED: 577 case SIM_GREEN: 578 case SIM_BLUE: 579 ss->sio.scan_bits_per_pixel = 8; 580 break; 581 } 582 583 /* 584 * horizontal number of bytes is always a multiple of 2, 585 * in 8-bit mode at least 586 */ 587 ss->sio.scan_pixels_per_line = 588 (ss->sio.scan_width * ss->sio.scan_x_resolution) / 1200; 589 if (ss->sio.scan_bits_per_pixel == 1) 590 /* make it a multiple of 16, and thus of 2 bytes */ 591 ss->sio.scan_pixels_per_line = 592 (ss->sio.scan_pixels_per_line + 15) & 0xfffffff0; 593 else 594 ss->sio.scan_pixels_per_line = 595 (ss->sio.scan_pixels_per_line + 1) & 0xfffffffe; 596 597 ss->sio.scan_lines = 598 (ss->sio.scan_height * ss->sio.scan_y_resolution) / 1200; 599 ss->sio.scan_window_size = ss->sio.scan_lines * 600 ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8); 601 } 602