From 10947b94f115ccb0016408ba4a28bd2a534d56f2 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 27 Jul 2019 10:12:27 +0300 Subject: [PATCH] genesys: Return errors as exceptions from pixel format conv functions --- backend/genesys.cc | 127 +++++++++--------------------------- backend/genesys_conv.cc | 21 ++---- backend/genesys_conv_hlp.cc | 63 +++++------------- 3 files changed, 51 insertions(+), 160 deletions(-) diff --git a/backend/genesys.cc b/backend/genesys.cc index 871785141..871f15c7e 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -3841,7 +3841,6 @@ genesys_read_ordered_data (Genesys_Device * dev, SANE_Byte * destination, size_t * len) { DBG_HELPER(dbg); - SANE_Status status = SANE_STATUS_GOOD; size_t bytes, extra; unsigned int channels, depth, src_pixels; unsigned int ccd_shift[12], shift_count; @@ -4029,53 +4028,35 @@ Problems with the first approach: { case 1: /* RGB, chunky, 16 bit */ #ifdef WORDS_BIGENDIAN - status = - genesys_reorder_components_endian_16 (work_buffer_src, - work_buffer_dst, - dst_lines, - src_pixels, 3); + genesys_reorder_components_endian_16(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels, 3); break; #endif /*WORDS_BIGENDIAN */ case 0: /* RGB, chunky, 8 bit */ - status = SANE_STATUS_GOOD; break; case 2: /* RGB, cis, 8 bit */ - status = - genesys_reorder_components_cis_8 (work_buffer_src, - work_buffer_dst, - dst_lines, src_pixels); + genesys_reorder_components_cis_8(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels); break; case 3: /* RGB, cis, 16 bit */ - status = - genesys_reorder_components_cis_16 (work_buffer_src, - work_buffer_dst, - dst_lines, src_pixels); + genesys_reorder_components_cis_16(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels); break; case 4: /* BGR, chunky, 8 bit */ - status = - genesys_reorder_components_bgr_8 (work_buffer_src, - work_buffer_dst, - dst_lines, src_pixels); + genesys_reorder_components_bgr_8(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels); break; case 5: /* BGR, chunky, 16 bit */ - status = - genesys_reorder_components_bgr_16 (work_buffer_src, - work_buffer_dst, - dst_lines, src_pixels); + genesys_reorder_components_bgr_16(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels); break; case 6: /* BGR, cis, 8 bit */ - status = - genesys_reorder_components_cis_bgr_8 (work_buffer_src, - work_buffer_dst, - dst_lines, - src_pixels); + genesys_reorder_components_cis_bgr_8(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels); break; case 7: /* BGR, cis, 16 bit */ - status = - genesys_reorder_components_cis_bgr_16 (work_buffer_src, - work_buffer_dst, - dst_lines, - src_pixels); + genesys_reorder_components_cis_bgr_16(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels); break; } } @@ -4084,28 +4065,12 @@ Problems with the first approach: #ifdef WORDS_BIGENDIAN if (depth == 16) { - status = - genesys_reorder_components_endian_16 (work_buffer_src, - work_buffer_dst, - dst_lines, - src_pixels, 1); + genesys_reorder_components_endian_16(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels, 1); } - else - { - status = SANE_STATUS_GOOD; - } -#else /*!WORDS_BIGENDIAN */ - status = SANE_STATUS_GOOD; #endif /*WORDS_BIGENDIAN */ } - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to convert byte ordering(%s)\n", __func__, - sane_strstatus(status)); - return SANE_STATUS_IO_ERROR; - } - dst_buffer->produce(bytes); src_buffer->consume(bytes); } @@ -4151,24 +4116,13 @@ Problems with the first approach: if (dst_lines != 0) { - if (depth == 8) - status = genesys_reverse_ccd_8 (work_buffer_src, work_buffer_dst, - dst_lines, - src_pixels * channels, - ccd_shift, shift_count); - else - status = genesys_reverse_ccd_16 (work_buffer_src, work_buffer_dst, - dst_lines, - src_pixels * channels, - ccd_shift, shift_count); - - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to reverse ccd effects(%s)\n", __func__, - sane_strstatus(status)); - return SANE_STATUS_IO_ERROR; - } - + if (depth == 8) { + genesys_reverse_ccd_8(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels * channels, ccd_shift, shift_count); + } else { + genesys_reverse_ccd_16(work_buffer_src, work_buffer_dst, dst_lines, + src_pixels * channels, ccd_shift, shift_count); + } dst_buffer->produce(bytes); src_buffer->consume(bytes); } @@ -4203,30 +4157,14 @@ Problems with the first approach: if (dst_lines != 0) { if (depth == 1) - status = genesys_shrink_lines_1 (work_buffer_src, - work_buffer_dst, - dst_lines, - src_pixels, - dev->settings.pixels, - channels); + genesys_shrink_lines_1(work_buffer_src, work_buffer_dst, dst_lines, src_pixels, + dev->settings.pixels, channels); else if (depth == 8) - status = genesys_shrink_lines_8 (work_buffer_src, - work_buffer_dst, - dst_lines, - src_pixels, - dev->settings.pixels, channels); + genesys_shrink_lines_8(work_buffer_src, work_buffer_dst, dst_lines, src_pixels, + dev->settings.pixels, channels); else - status = genesys_shrink_lines_16 (work_buffer_src, - work_buffer_dst, - dst_lines, - src_pixels, - dev->settings.pixels, channels); - - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to shrink lines(%s)\n", __func__, sane_strstatus(status)); - return SANE_STATUS_IO_ERROR; - } + genesys_shrink_lines_16(work_buffer_src, work_buffer_dst, dst_lines, src_pixels, + dev->settings.pixels, channels); /* we just consumed this many bytes*/ bytes = (dst_lines * src_pixels * channels * depth) / 8; @@ -4247,12 +4185,7 @@ Problems with the first approach: if (needs_reverse) { - status = genesys_reverse_bits (work_buffer_src, destination, bytes); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to reverse bits(%s)\n", __func__, sane_strstatus(status)); - return SANE_STATUS_IO_ERROR; - } + genesys_reverse_bits(work_buffer_src, destination, bytes); *len = bytes; } else diff --git a/backend/genesys_conv.cc b/backend/genesys_conv.cc index 7c49a8ea4..50e33eb37 100644 --- a/backend/genesys_conv.cc +++ b/backend/genesys_conv.cc @@ -77,18 +77,13 @@ #undef BYTES_PER_COMPONENT #undef DOUBLE_BYTE -static SANE_Status -genesys_reverse_bits( - uint8_t *src_data, - uint8_t *dst_data, - size_t bytes) +static void genesys_reverse_bits(uint8_t* src_data, uint8_t* dst_data, size_t bytes) { DBG_HELPER(dbg); size_t i; for(i = 0; i < bytes; i++) { *dst_data++ = ~ *src_data++; } - return SANE_STATUS_GOOD; } /** @@ -214,14 +209,10 @@ genesys_gray_lineart( * or grows it in case it is the opposite like when motor resolution is higher than * sensor's one. */ -static SANE_Status -genesys_shrink_lines_1 ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int src_pixels, - unsigned int dst_pixels, - unsigned int channels) +static void genesys_shrink_lines_1(uint8_t* src_data, uint8_t* dst_data, + unsigned int lines, + unsigned int src_pixels, unsigned int dst_pixels, + unsigned int channels) { DBG_HELPER(dbg); unsigned int dst_x, src_x, y, c, cnt; @@ -318,8 +309,6 @@ genesys_shrink_lines_1 ( } } } - - return SANE_STATUS_GOOD; } diff --git a/backend/genesys_conv_hlp.cc b/backend/genesys_conv_hlp.cc index a25a40198..7982625a7 100644 --- a/backend/genesys_conv_hlp.cc +++ b/backend/genesys_conv_hlp.cc @@ -45,12 +45,8 @@ * Conversion filters for genesys backend */ -static SANE_Status -FUNC_NAME(genesys_reorder_components_cis) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int pixels) +static void FUNC_NAME(genesys_reorder_components_cis) (uint8_t* src_data, uint8_t* dst_data, + unsigned int lines, unsigned int pixels) { DBG_HELPER(dbg); unsigned int x, y; @@ -95,15 +91,10 @@ FUNC_NAME(genesys_reorder_components_cis) ( src[1] += rest; src[2] += rest; } - return SANE_STATUS_GOOD; } -static SANE_Status -FUNC_NAME(genesys_reorder_components_cis_bgr) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int pixels) +static void FUNC_NAME(genesys_reorder_components_cis_bgr) (uint8_t* src_data, uint8_t* dst_data, + unsigned int lines, unsigned int pixels) { DBG_HELPER(dbg); unsigned int x, y; @@ -147,15 +138,10 @@ FUNC_NAME(genesys_reorder_components_cis_bgr) ( src[1] += rest; src[2] += rest; } - return SANE_STATUS_GOOD; } -static SANE_Status -FUNC_NAME(genesys_reorder_components_bgr) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int pixels) +static void FUNC_NAME(genesys_reorder_components_bgr) (uint8_t* src_data, uint8_t* dst_data, + unsigned int lines, unsigned int pixels) { DBG_HELPER(dbg); unsigned int c; @@ -189,17 +175,12 @@ FUNC_NAME(genesys_reorder_components_bgr) ( #endif } - return SANE_STATUS_GOOD; } #if defined(DOUBLE_BYTE) && defined(WORDS_BIGENDIAN) -static SANE_Status -FUNC_NAME(genesys_reorder_components_endian) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int pixels, - unsigned int channels) +static void FUNC_NAME(genesys_reorder_components_endian) (uint8_t* src_data, uint8_t* dst_data, + unsigned int lines, unsigned int pixels, + unsigned int channels) { DBG_HELPER(dbg); unsigned int c; @@ -211,19 +192,13 @@ FUNC_NAME(genesys_reorder_components_endian) ( *dst++ = src[0]; src += 2; } -return SANE_STATUS_GOOD; } #endif /*defined(DOUBLE_BYTE) && defined(WORDS_BIGENDIAN)*/ -static SANE_Status -FUNC_NAME(genesys_reverse_ccd) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int components_per_line, - unsigned int *ccd_shift, - unsigned int component_count) +static void FUNC_NAME(genesys_reverse_ccd) (uint8_t* src_data, uint8_t* dst_data, + unsigned int lines, unsigned int components_per_line, + unsigned int *ccd_shift, unsigned int component_count) { DBG_HELPER(dbg); unsigned int x, y, c; @@ -283,17 +258,12 @@ FUNC_NAME(genesys_reverse_ccd) ( } } } - return SANE_STATUS_GOOD; } -static SANE_Status -FUNC_NAME(genesys_shrink_lines) ( - uint8_t *src_data, - uint8_t *dst_data, - unsigned int lines, - unsigned int src_pixels, - unsigned int dst_pixels, - unsigned int channels) +static void FUNC_NAME(genesys_shrink_lines) (uint8_t* src_data, uint8_t* dst_data, + unsigned int lines, + unsigned int src_pixels, unsigned int dst_pixels, + unsigned int channels) { DBG_HELPER(dbg); unsigned int dst_x, src_x, y, c, cnt; @@ -347,5 +317,4 @@ FUNC_NAME(genesys_shrink_lines) ( } } } - return SANE_STATUS_GOOD; }