Lines Matching refs:ss
82 #define DECL_CTX pixma_sane_t *ss = check_handle(h)
83 #define OPT_IN_CTX ss->opt
155 static void mark_all_button_options_cached ( struct pixma_sane_t * ss )
159 ss -> button_option_is_cached[i] = 1;
299 update_button_state (pixma_sane_t * ss, SANE_Int * info)
303 uint32_t ev = pixma_wait_event (ss->s, 300);
326 mark_all_button_options_cached(ss);
330 enable_option (pixma_sane_t * ss, SANE_Int o, SANE_Bool enable)
341 clamp_value (pixma_sane_t * ss, SANE_Int n, void *v, SANE_Int * info)
374 * ss: scanner device
380 create_mode_list (pixma_sane_t * ss)
386 cfg = pixma_get_config (ss->s);
387 tpu = (ss->source_map[OVAL (opt_source).w] == PIXMA_SOURCE_TPU);
391 ss->mode_list[i] = SANE_VALUE_SCAN_MODE_COLOR;
392 ss->mode_map[i] = PIXMA_SCAN_MODE_COLOR;
396 ss->mode_list[i] = SANE_VALUE_SCAN_MODE_GRAY;
397 ss->mode_map[i] = PIXMA_SCAN_MODE_GRAY;
402 ss->mode_list[i] = SANE_I18N ("Negative color");
403 ss->mode_map[i] = PIXMA_SCAN_MODE_NEGATIVE_COLOR;
407 ss->mode_list[i] = SANE_I18N ("Negative gray");
408 ss->mode_map[i] = PIXMA_SCAN_MODE_NEGATIVE_GRAY;
414 ss->mode_list[i] = SANE_I18N ("Infrared");
415 ss->mode_map[i] = PIXMA_SCAN_MODE_TPUIR;
420 ss->mode_list[i] = SANE_I18N ("48 bits color");
421 ss->mode_map[i] = PIXMA_SCAN_MODE_COLOR_48;
425 ss->mode_list[i] = SANE_I18N ("16 bits gray");
426 ss->mode_map[i] = PIXMA_SCAN_MODE_GRAY_16;
432 ss->mode_list[i] = SANE_VALUE_SCAN_MODE_LINEART;
433 ss->mode_map[i] = PIXMA_SCAN_MODE_LINEART;
437 ss->mode_list[i] = 0;
438 ss->mode_map[i] = 0;
442 * ss: scanner device */
444 create_dpi_list (pixma_sane_t * ss)
452 cfg = pixma_get_config (ss->s);
457 if (ss->source_map[OVAL (opt_source).w] == PIXMA_SOURCE_TPU
458 && ss->mode_map[OVAL (opt_mode).w] == PIXMA_SCAN_MODE_TPUIR)
464 else if (ss->source_map[OVAL (opt_source).w] == PIXMA_SOURCE_TPU
465 || ss->source_map[OVAL (opt_source).w] == PIXMA_SOURCE_ADF
466 || ss->source_map[OVAL (opt_source).w] == PIXMA_SOURCE_ADFDUP)
472 else if (ss->source_map[OVAL (opt_source).w] == PIXMA_SOURCE_FLATBED
473 && (ss->mode_map[OVAL (opt_mode).w] == PIXMA_SCAN_MODE_COLOR_48
474 || ss->mode_map[OVAL (opt_mode).w] == PIXMA_SCAN_MODE_GRAY_16))
501 ss->dpi_list[i] = 75 * (1 << (j - 1)); /* 75 x 2^(j-1) */
503 while ((unsigned) ss->dpi_list[i] < max_dpi);
504 ss->dpi_list[0] = i;
510 create_calibrate_list (pixma_sane_t * ss)
513 ss->calibrate_list[i] = SANE_I18N ("Once");
514 ss->calibrate_map[i] = PIXMA_CALIBRATE_ONCE;
516 ss->calibrate_list[i] = SANE_I18N ("Always");
517 ss->calibrate_map[i] = PIXMA_CALIBRATE_ALWAYS;
519 ss->calibrate_list[i] = SANE_I18N ("Never");
520 ss->calibrate_map[i] = PIXMA_CALIBRATE_NEVER;
525 select_value_from_list (pixma_sane_t * ss, SANE_Int n, void *v,
559 control_scalar_option (pixma_sane_t * ss, SANE_Int n, SANE_Action a, void *v,
594 clamp_value (ss, n, v, info);
596 select_value_from_list (ss, n, v, info);
623 control_string_option (pixma_sane_t * ss, SANE_Int n, SANE_Action a, void *v,
681 control_option (pixma_sane_t * ss, SANE_Int n,
693 cfg = pixma_get_config (ss->s);
710 clamp_value (ss, n, v, info);
714 ss->gamma_table[i] = *((SANE_Int *) v + i);
720 ss->gamma_table[i * 2] = *((SANE_Int *) v + i);
721 ss->gamma_table[i * 2 + 1] = *((uint8_t *)((SANE_Int *) v + i) + 1);
725 /* PDBG (pixma_hexdump (4, ss->gamma_table, table_size * byte_cnt)); */
732 *((SANE_Int *) v + i) = ss->gamma_table[i];
738 *((SANE_Int *) v + i) = ss->gamma_table[i * 2];
739 *((uint8_t *)((SANE_Int *) v + i) + 1) = ss->gamma_table[i * 2 + 1];
747 ss->gamma_table, table_size);
748 /* PDBG (pixma_hexdump (4, ss->gamma_table, table_size * byte_cnt)); */
759 update_button_state (ss, info);
776 if (! ss->button_option_is_cached[ BUTTON_GROUP_INDEX(n) ] )
777 update_button_state (ss, info);
779 ss->button_option_is_cached[ BUTTON_GROUP_INDEX(n) ] = 0;
788 result = control_scalar_option (ss, n, a, v, info);
791 result = control_string_option (ss, n, a, v, info);
808 if (enable_option (ss, opt_gamma_table, OVAL (opt_custom_gamma).b))
811 sane_control_option (ss, opt_gamma_table, SANE_ACTION_SET_AUTO,
825 ss->gamma_table, table_size);
826 /* PDBG (pixma_hexdump (4, ss->gamma_table,
835 ss->mode_map[OVAL (opt_mode).w])); */
837 create_dpi_list (ss);
838 if (ss->mode_map[OVAL (opt_mode).w] == PIXMA_SCAN_MODE_LINEART)
840 enable_option (ss, opt_threshold, SANE_TRUE);
841 enable_option (ss, opt_threshold_curve, SANE_TRUE);
845 enable_option (ss, opt_threshold, SANE_FALSE);
846 enable_option (ss, opt_threshold_curve, SANE_FALSE);
858 OVAL (opt_mode).w = ss->mode_map[0];
860 create_mode_list (ss);
861 create_dpi_list (ss);
865 OVAL (opt_resolution).w = ss->dpi_list[1];
866 if (ss->mode_map[OVAL (opt_mode).w] == PIXMA_SCAN_MODE_LINEART)
868 enable_option (ss, opt_threshold, SANE_TRUE);
869 enable_option (ss, opt_threshold_curve, SANE_TRUE);
873 enable_option (ss, opt_threshold, SANE_FALSE);
874 enable_option (ss, opt_threshold_curve, SANE_FALSE);
878 enable_option (ss, opt_adf_wait, SANE_TRUE);
882 enable_option (ss, opt_adf_wait, SANE_FALSE);
908 calc_scan_param (pixma_sane_t * ss, pixma_scan_param_t * sp)
948 sp->gamma_table = ss->gamma_table;
949 sp->source = ss->source_map[OVAL (opt_source).w];
950 sp->mode = ss->mode_map[OVAL (opt_mode).w];
951 sp->adf_pageid = ss->page_count;
955 sp->calibrate = ss->calibrate_map[OVAL (opt_calibrate).w];
957 error = pixma_check_scan_param (ss->s, sp);
967 init_option_descriptors (pixma_sane_t * ss)
972 cfg = pixma_get_config (ss->s);
977 ss->xrange.min = SANE_FIX (0);
978 ss->xrange.max = SANE_FIX (cfg->width / 75.0 * 25.4);
979 ss->xrange.quant = SANE_FIX (0);
981 ss->yrange.min = SANE_FIX (0);
982 ss->yrange.max = SANE_FIX (cfg->height / 75.0 * 25.4);
983 ss->yrange.quant = SANE_FIX (0);
989 create_mode_list (ss);
992 create_dpi_list (ss);
996 ss->source_list[i] = SANE_I18N ("Flatbed");
997 ss->source_map[i] = PIXMA_SOURCE_FLATBED;
1001 ss->source_list[i] = SANE_I18N ("Automatic Document Feeder");
1002 ss->source_map[i] = PIXMA_SOURCE_ADF;
1007 ss->source_list[i] = SANE_I18N ("ADF Duplex");
1008 ss->source_map[i] = PIXMA_SOURCE_ADFDUP;
1013 ss->source_list[i] = SANE_I18N ("Transparency Unit");
1014 ss->source_map[i] = PIXMA_SOURCE_TPU;
1018 create_calibrate_list (ss);
1020 build_option_descriptors (ss);
1044 enable_option (ss, opt_gamma, SANE_TRUE);
1045 sane_control_option (ss, opt_gamma, SANE_ACTION_SET_AUTO,
1048 enable_option (ss, opt_custom_gamma, SANE_TRUE);
1049 sane_control_option (ss, opt_custom_gamma, SANE_ACTION_SET_AUTO,
1052 enable_option (ss, opt_button_controlled,
1072 write_all (pixma_sane_t * ss, void *buf_, size_t size)
1077 while (size != 0 && !ss->reader_stop)
1079 count = write (ss->wpipe, buf, size);
1092 reader_loop (pixma_sane_t * ss)
1099 /*bufsize = ss->sp.line_size + 1;*/ /* XXX: "odd" bufsize for testing pixma_read_image() */
1100 bufsize = ss->sp.line_size; /* bufsize EVEN needed by Xsane for 48 bits depth */
1108 count = pixma_activate_connection (ss->s);
1112 pixma_enable_background (ss->s, 1);
1113 if (OVAL (opt_button_controlled).b && ss->page_count == 0)
1121 while (pixma_wait_event (ss->s, 10) != 0)
1127 if (ss->reader_stop)
1132 events = pixma_wait_event (ss->s, 1000);
1144 count = pixma_scan (ss->s, &ss->sp);
1147 while ((count = pixma_read_image (ss->s, buf, bufsize)) > 0)
1149 if (write_all (ss, buf, count) != count)
1150 pixma_cancel (ss->s);
1155 pixma_enable_background (ss->s, 0);
1156 pixma_deactivate_connection (ss->s);
1158 close (ss->wpipe);
1159 ss->wpipe = -1;
1175 pixma_sane_t *ss = (pixma_sane_t *) arg;
1178 reader_ss = ss;
1187 close (ss->rpipe);
1188 ss->rpipe = -1;
1189 return reader_loop (ss);
1195 pixma_sane_t *ss = (pixma_sane_t *) arg;
1198 ss->reader_stop and the return value from write(). */
1204 return reader_loop (ss);
1208 terminate_reader_task (pixma_sane_t * ss, int *exit_code)
1213 pid = ss->reader_taskid;
1222 ss->reader_stop = SANE_TRUE;
1223 /* pixma_cancel (ss->s); What is this for ? Makes end-of-scan buggy => removing */
1226 sanei_thread_invalidate (ss->reader_taskid);
1228 if (ss->sp.source != PIXMA_SOURCE_ADF && ss->sp.source != PIXMA_SOURCE_ADFDUP)
1229 ss->idle = SANE_TRUE;
1246 start_reader_task (pixma_sane_t * ss)
1252 if (ss->rpipe != -1 || ss->wpipe != -1)
1255 (1, "BUG:rpipe = %d, wpipe = %d\n", ss->rpipe, ss->wpipe));
1256 close (ss->rpipe);
1257 close (ss->wpipe);
1258 ss->rpipe = -1;
1259 ss->wpipe = -1;
1261 if (sanei_thread_is_valid (ss->reader_taskid))
1264 (1, "BUG:reader_taskid(%ld) != -1\n", (long) ss->reader_taskid));
1265 terminate_reader_task (ss, NULL);
1273 ss->rpipe = fds[0];
1274 ss->wpipe = fds[1];
1275 ss->reader_stop = SANE_FALSE;
1280 pid = sanei_thread_begin (reader_process, ss);
1283 close (ss->wpipe);
1284 ss->wpipe = -1;
1289 pid = sanei_thread_begin (reader_thread, ss);
1293 close (ss->wpipe);
1294 close (ss->rpipe);
1295 ss->wpipe = -1;
1296 ss->rpipe = -1;
1302 ss->reader_taskid = pid;
1447 pixma_jpeg_finish(pixma_sane_t *ss)
1449 jpeg_destroy_decompress(&ss->jpeg_cinfo);
1453 pixma_jpeg_read(pixma_sane_t *ss, SANE_Byte *data,
1456 struct jpeg_decompress_struct *cinfo = &ss->jpeg_cinfo;
1483 /* scanlines of decompressed data will be in ss->jdst->buffer
1487 l = jpeg_read_scanlines(cinfo, ss->jdst->buffer, 1);
1491 /* from ss->jdst->buffer to linebuffer
1495 (*ss->jdst->put_pixel_rows)(cinfo, ss->jdst, 1, (char *)src->linebuffer);
1497 *length = ss->sp.w * ss->sp.channels;
1499 if (ss->sp.channels == 1)
1504 for (i = 0; i < ss->sp.w; i++)
1515 if (ss->sp.depth == 1)
1522 for (i = 1; i < ss->sp.w + 1; i++)
1546 read_image (pixma_sane_t * ss, void *buf, unsigned size, int *readlen)
1552 if (ss->image_bytes_read >= ss->sp.image_size)
1557 if (ss->cancel)
1558 /* ss->rpipe has already been closed by sane_cancel(). */
1560 if (ss->sp.mode_jpeg && !ss->jpeg_header_seen)
1562 status = pixma_jpeg_read_header(ss);
1565 close (ss->rpipe);
1566 pixma_jpeg_finish(ss);
1567 ss->rpipe = -1;
1568 if (sanei_thread_is_valid (terminate_reader_task (ss, &status))
1582 if (ss->sp.mode_jpeg)
1585 pixma_jpeg_read(ss, buf, size, &count);
1588 count = read (ss->rpipe, buf, size);
1596 if (!ss->cancel)
1601 close (ss->rpipe);
1602 ss->rpipe = -1;
1603 terminate_reader_task (ss, NULL);
1604 if (ss->sp.mode_jpeg)
1605 pixma_jpeg_finish(ss);
1610 ss->image_bytes_read += count;
1611 if (ss->image_bytes_read > ss->sp.image_size)
1613 PDBG (pixma_dbg (1, "BUG:ss->image_bytes_read > ss->sp.image_size\n"));
1615 if (ss->image_bytes_read >= ss->sp.image_size)
1617 close (ss->rpipe);
1618 ss->rpipe = -1;
1619 terminate_reader_task (ss, NULL);
1620 if (ss->sp.mode_jpeg)
1621 pixma_jpeg_finish(ss);
1627 ss->image_bytes_read, ss->sp.image_size));
1628 close (ss->rpipe);
1629 if (ss->sp.mode_jpeg)
1630 pixma_jpeg_finish(ss);
1631 ss->rpipe = -1;
1632 if (sanei_thread_is_valid (terminate_reader_task (ss, &status))
1717 pixma_sane_t *ss = NULL;
1735 for (ss = first_scanner; ss; ss = ss->next)
1737 if (strcmp (pixma_get_string (ss->s, PIXMA_STRING_ID), name) == 0)
1769 ss = (pixma_sane_t *) calloc (1, sizeof (*ss));
1770 if (!ss)
1772 ss->next = first_scanner;
1773 first_scanner = ss;
1774 sanei_thread_initialize (ss->reader_taskid);
1775 ss->wpipe = -1;
1776 ss->rpipe = -1;
1777 ss->idle = SANE_TRUE;
1778 ss->scanning = SANE_FALSE;
1779 ss->sp.frontend_cancel = SANE_FALSE;
1781 ss->button_option_is_cached[j] = 0;
1782 error = pixma_open (i, &ss->s);
1785 sane_close (ss);
1788 pixma_enable_background (ss->s, 0);
1789 init_option_descriptors (ss);
1790 *h = ss;
1797 pixma_sane_t **p, *ss;
1804 ss = *p;
1805 sane_cancel (ss);
1806 pixma_close (ss->s);
1807 *p = ss->next;
1808 free (ss);
1816 if (ss && 0 <= n && n < opt_last)
1832 if (!ss)
1836 if (!ss->idle && a != SANE_ACTION_GET_VALUE)
1839 if (ss->sp.source != PIXMA_SOURCE_ADF && ss->sp.source != PIXMA_SOURCE_ADFDUP)
1866 error = control_option (ss, n, a, v, &info);
1878 if (!ss || !p)
1881 if (!ss->idle)
1883 sp = &ss->sp; /* sp is calculated in sane_start() */
1887 calc_scan_param (ss, &temp);
1906 if (!ss)
1908 if (!ss->idle && ss->scanning)
1910 PDBG (pixma_dbg (3, "Warning in Sane_start: !idle && scanning. idle=%d, ss->scanning=%d\n",
1911 ss->idle, ss->scanning));
1912 if (ss->sp.source != PIXMA_SOURCE_ADF && ss->sp.source != PIXMA_SOURCE_ADFDUP)
1916 ss->cancel = SANE_FALSE;
1917 if (ss->idle ||
1918 ss->source_map[OVAL (opt_source).w] == PIXMA_SOURCE_FLATBED ||
1919 ss->source_map[OVAL (opt_source).w] == PIXMA_SOURCE_TPU)
1920 ss->page_count = 0; /* start from idle state or scan from flatbed or TPU */
1922 ss->page_count++;
1923 if (calc_scan_param (ss, &ss->sp) < 0)
1927 if (ss->sp.mode_jpeg)
1930 status = pixma_jpeg_start(ss);
1938 ss->image_bytes_read = 0;
1941 error = start_reader_task (ss);
1944 ss->output_line_size = (ss->sp.w * ss->sp.channels * ss->sp.depth) / 8;
1945 ss->byte_pos_in_line = 0;
1946 ss->last_read_status = SANE_STATUS_GOOD;
1947 ss->scanning = SANE_TRUE;
1948 ss->idle = SANE_FALSE;
1949 if (ss->sp.mode_jpeg && !ss->jpeg_header_seen)
1952 status = pixma_jpeg_read_header(ss);
1955 close (ss->rpipe);
1956 pixma_jpeg_finish(ss);
1957 ss->rpipe = -1;
1958 if (sanei_thread_is_valid (terminate_reader_task (ss, &error))
1982 if (!ss || !buf || !len)
1984 if (ss->cancel)
1986 if ((ss->idle)
1987 && (ss->sp.source == PIXMA_SOURCE_ADF || ss->sp.source == PIXMA_SOURCE_ADFDUP))
1989 if (!ss->scanning)
1990 return ss->last_read_status;
1995 if ((ss->sp.line_size - ((ss->sp.software_lineart == 1) ? (ss->output_line_size * 8) : ss->output_line_size)) == 0)
1997 status = read_image (ss, buf, maxlen, &sum);
2007 if (ss->byte_pos_in_line < ss->output_line_size)
2009 n = ss->output_line_size - ss->byte_pos_in_line;
2012 status = read_image (ss, buf, n, &n);
2017 ss->byte_pos_in_line += n;
2022 n = ss->sp.line_size - ss->byte_pos_in_line;
2028 status = read_image (ss, temp, n, &n);
2031 ss->byte_pos_in_line += n;
2032 if (ss->byte_pos_in_line == ss->sp.line_size)
2033 ss->byte_pos_in_line = 0;
2037 if (ss->cancel)
2045 ss->scanning = (status == SANE_STATUS_GOOD);
2046 ss->last_read_status = status;
2055 if (!ss)
2057 ss->cancel = SANE_TRUE;
2058 ss->sp.frontend_cancel = SANE_TRUE;
2059 if (ss->idle)
2061 close (ss->rpipe);
2062 if (ss->sp.mode_jpeg)
2063 pixma_jpeg_finish(ss);
2064 ss->rpipe = -1;
2065 terminate_reader_task (ss, NULL);
2066 ss->idle = SANE_TRUE;
2074 if (!ss || ss->idle || ss->rpipe == -1)
2078 if (fcntl (ss->rpipe, F_SETFL, (m) ? O_NONBLOCK : 0) == -1)
2096 if (!ss || !fd || ss->idle || ss->rpipe == -1)
2098 *fd = ss->rpipe;
2117 constraint @word_list = ss->dpi_list
2125 constraint @string_list = ss->mode_list
2133 constraint @string_list = ss->source_list
2175 constraint @range = &ss->xrange
2184 constraint @range = &ss->yrange
2193 constraint @range = &ss->xrange
2202 constraint @range = &ss->yrange
2282 constraint @string_list = ss->calibrate_list