brother_mfp: fix for makefile and other small enhancements.

brother_mfp_backend
Ralph Little 2022-09-13 22:09:25 -07:00
rodzic a7d6a553ee
commit 4f060d6cea
6 zmienionych plików z 55 dodań i 128 usunięć

Wyświetl plik

@ -382,8 +382,7 @@ libsane_bh_la_LIBADD = $(COMMON_LIBS) libbh.la \
EXTRA_DIST += bh.conf.in
libbrother_mfp_la_SOURCES = brother_mfp.h \
brother_mfp-driver.cpp \
libbrother_mfp_la_SOURCES = brother_mfp-driver.cpp \
brother_mfp-driver.h \
brother_mfp-common.h \
brother_mfp-encoder.cpp \

Wyświetl plik

@ -58,90 +58,6 @@ extern "C" void sanei_debug_brother_mfp_call(int level, const char *msg, ...);
/*-----------------------------------------------------------------*/
typedef struct
{
size_t dummy;
} Brother_jpeg_decode_state;
typedef struct
{
size_t dummy;
} Brother_raw_decode_state;
//static void Brother_decode_gray_rlength_init (Brother_rlen_decode_state *state);
//static void Brother_decode_jpeg_init (Brother_jpeg_decode_state *state);
//static void Brother_decode_gray_raw_init (Brother_raw_decode_state *state);
//
//static SANE_Status Brother_decode_jpeg (Brother_jpeg_decode_state *state,
// const SANE_Byte *in_buffer, size_t in_buffer_len,
// SANE_Byte *out_buffer, size_t out_buffer_len,
// size_t *bytes_consumed, size_t *bytes_written);
//
//static SANE_Status Brother_decode_gray_raw (Brother_raw_decode_state *state,
// const SANE_Byte *in_buffer, size_t in_buffer_len,
// SANE_Byte *out_buffer, size_t out_buffer_len,
// size_t *bytes_consumed, size_t *bytes_written);
//
//static SANE_Status Brother_decode_gray_rlength (Brother_rlen_decode_state *state,
// const SANE_Byte *in_buffer, size_t in_buffer_len,
// SANE_Byte *out_buffer, size_t out_buffer_len,
// size_t *bytes_consumed, size_t *bytes_written);
//static void
//Brother_decode_jpeg_init (Brother_jpeg_decode_state *state)
//{
// (void)state;
//// state->decode_bytes_left = 0;
//}
//
//static void
//Brother_decode_gray_raw_init (Brother_raw_decode_state *state)
//{
// (void)state;
//// state->decode_bytes_left = block_size;
//}
//
//
//static SANE_Status
//Brother_decode_jpeg (Brother_jpeg_decode_state *state,
// const SANE_Byte *in_buffer, size_t in_buffer_len,
// SANE_Byte *out_buffer, size_t out_buffer_len,
// size_t *bytes_consumed, size_t *bytes_written)
//{
// (void)state;
//
// /*
// * TODO: replace with JPEG decoding.
// *
// */
// size_t bytes_to_copy = MIN(in_buffer_len, (size_t)out_buffer_len);
// (void) memcpy (out_buffer, in_buffer, bytes_to_copy);
//
// *bytes_written = bytes_to_copy;
// *bytes_consumed = bytes_to_copy;
//
// return SANE_STATUS_GOOD;
//}
//
//static SANE_Status
//Brother_decode_gray_raw (Brother_raw_decode_state *state,
// const SANE_Byte *in_buffer, size_t in_buffer_len,
// SANE_Byte *out_buffer, size_t out_buffer_len,
// size_t *bytes_consumed, size_t *bytes_written)
//{
// (void)state;
//
// size_t bytes_to_copy = MIN(in_buffer_len, (size_t )out_buffer_len);
// (void) memcpy (out_buffer, in_buffer, bytes_to_copy);
//
// *bytes_written = bytes_to_copy;
// *bytes_consumed = bytes_to_copy;
//
// return SANE_STATUS_GOOD;
//}
const char* BrotherDriver::ScanModeToText (BrotherScanMode scan_mode)
{
static const char *scan_mode_text[] =
@ -1030,9 +946,9 @@ BrotherUSBDriver::BrotherUSBDriver (const char *devicename, BrotherFamily family
was_cancelled(false),
devicename (nullptr),
fd (0),
small_buffer {0},
data_buffer (nullptr),
data_buffer_bytes (0)
{
this->devicename = strdup(devicename);
}

Wyświetl plik

@ -69,7 +69,10 @@
class BrotherDriver
{
public:
BrotherDriver (BrotherFamily family);
explicit BrotherDriver (BrotherFamily family);
BrotherDriver(const BrotherDriver &) = delete;
BrotherDriver &operator=(const BrotherDriver &) = delete;
virtual ~BrotherDriver();
@ -147,16 +150,16 @@ public:
~BrotherUSBDriver ();
SANE_Status Connect ();
SANE_Status Connect () override;
SANE_Status Disconnect ();
SANE_Status Disconnect () override;
SANE_Status StartScan ();
SANE_Status StartScan () override;
SANE_Status CancelScan ();
SANE_Status CancelScan () override;
SANE_Status ReadScanData (SANE_Byte *data, size_t data_len,
size_t *bytes_read);
size_t *bytes_read) override;
private:
SANE_Status StartSession ();

Wyświetl plik

@ -297,10 +297,12 @@ SANE_Status BrotherEncoderFamily4::EncodeParameterBlock (SANE_Byte *data, size_t
"C=JPEG\nJ=MID\n" : "C=RLENGTH\n",
(unsigned int) (scan_params.param_brightness + 50),
(unsigned int) (scan_params.param_contrast + 50),
scan_params.param_pixel_x_offset,
scan_params.param_pixel_y_offset,
scan_params.param_pixel_x_offset + scan_params.param_pixel_x_width,
scan_params.param_pixel_y_offset + scan_params.param_pixel_y_height);
(unsigned int) (scan_params.param_pixel_x_offset),
(unsigned int) (scan_params.param_pixel_y_offset),
(unsigned int) (scan_params.param_pixel_x_offset
+ scan_params.param_pixel_x_width),
(unsigned int) (scan_params.param_pixel_y_offset
+ scan_params.param_pixel_y_height));
if (*length > data_len)
{
@ -656,10 +658,11 @@ DecodeStatus BrotherGrayRLengthDecoder::DecodeScanData (const SANE_Byte *in_buff
*
*/
size_t bytes_to_copy = MIN(out_buffer_len, block_bytes_left);
size_t consumed = 0;
if (bytes_to_copy)
{
size_t consumed = 0;
if (decode_state == BROTHER_DECODE_RLEN_IN_BYTES)
{
bytes_to_copy = MIN(bytes_to_copy, in_buffer_len);

Wyświetl plik

@ -267,29 +267,29 @@ public:
{
}
void Reset()
void Reset() override
{
current_header.block_type = 0;
}
SANE_Status DecodeSessionResp (const SANE_Byte *data, size_t data_len,
BrotherSessionResponse &response);
BrotherSessionResponse &response) override;
SANE_Status EncodeBasicParameterBlock (SANE_Byte *data, size_t data_len, size_t *length);
SANE_Status EncodeBasicParameterBlock (SANE_Byte *data, size_t data_len, size_t *length) override;
SANE_Status DecodeBasicParameterBlockResp (const SANE_Byte *data, size_t data_len,
BrotherBasicParamResponse &response);
BrotherBasicParamResponse &response) override;
SANE_Status EncodeADFBlock (SANE_Byte *data, size_t data_len, size_t *length);
SANE_Status EncodeADFBlock (SANE_Byte *data, size_t data_len, size_t *length) override;
SANE_Status DecodeADFBlockResp (const SANE_Byte *data, size_t data_len,
BrotherADFResponse &response);
BrotherADFResponse &response) override;
SANE_Status EncodeParameterBlock (SANE_Byte *data, size_t data_len, size_t *length);
SANE_Status EncodeParameterBlock (SANE_Byte *data, size_t data_len, size_t *length) override;
SANE_Status DecodeScanData (const SANE_Byte *src_data, size_t src_data_len,
size_t *src_data_consumed, SANE_Byte *dst_data,
size_t dest_data_len, size_t *dest_data_written);
size_t dest_data_len, size_t *dest_data_written) override;
private:
DecodeStatus DecodeScanDataHeader (const SANE_Byte *src_data, size_t src_data_len,

Wyświetl plik

@ -145,12 +145,15 @@ struct BrotherDevice
model (nullptr),
sane_device {nullptr, nullptr, nullptr, nullptr},
name (nullptr),
modes {0},
params {SANE_FRAME_GRAY, SANE_FALSE, 0, 0, 0, 0},
internal_scan_mode(nullptr),
x_res (0),
y_res (0),
scan_file (nullptr),
driver (nullptr)
{
(void)memset(opt, 0, sizeof(opt));
}
struct BrotherDevice *next;
@ -325,12 +328,12 @@ attach_with_no_ret (const char *devicename)
static size_t
max_string_size (const SANE_String_Const strings[])
{
size_t size, max_size = 0;
size_t max_size = 0;
SANE_Int i;
for (i = 0; strings[i]; ++i)
{
size = strlen (strings[i]) + 1;
size_t size = strlen (strings[i]) + 1;
if (size > max_size)
max_size = size;
}
@ -685,7 +688,7 @@ sane_close (SANE_Handle handle)
DBG (DBG_EVENT, "sane_close\n");
device = (BrotherDevice *)handle;
device = static_cast<BrotherDevice *>(handle);
/*
* Check is a valid device handle by running through our list of devices.
@ -725,7 +728,7 @@ sane_close (SANE_Handle handle)
const SANE_Option_Descriptor *
sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
{
BrotherDevice *device = (BrotherDevice *)handle;
BrotherDevice *device = static_cast<BrotherDevice *>(handle);
DBG (DBG_EVENT, "sane_get_option_descriptor: device=%s, option = %d\n", device->name, option);
if (option < 0 || option >= NUM_OPTIONS)
@ -741,7 +744,7 @@ SANE_Status
sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
void *value, SANE_Int * info)
{
BrotherDevice *device = (BrotherDevice *)handle;
BrotherDevice *device = static_cast<BrotherDevice *>(handle);
DBG (DBG_EVENT, "sane_control_option\n");
@ -832,19 +835,6 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
option, device->opt[option].name, *(SANE_Int *) value);
status = SANE_STATUS_GOOD;
if (option == OPT_CONTRAST)
{
status = device->driver->SetContrast((SANE_Int)device->val[option].w);
}
else if (option == OPT_BRIGHTNESS)
{
status = device->driver->SetBrightness((SANE_Int)device->val[option].w);
}
if (status != SANE_STATUS_GOOD)
{
return status;
}
break;
case OPT_MODE:
@ -943,7 +933,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
SANE_Status
sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
{
BrotherDevice *device = (BrotherDevice *)handle;
BrotherDevice *device = static_cast<BrotherDevice *>(handle);
SANE_Status rc = SANE_STATUS_GOOD;
DBG (DBG_EVENT, "sane_get_parameters\n");
@ -993,6 +983,22 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
return rc;
}
/*
* Brightness and contrast.
*
*/
rc = device->driver->SetContrast((SANE_Int)device->val[OPT_CONTRAST].w);
if (rc != SANE_STATUS_GOOD)
{
return rc;
}
rc = device->driver->SetBrightness((SANE_Int)device->val[OPT_BRIGHTNESS].w);
if (rc != SANE_STATUS_GOOD)
{
return rc;
}
/*
* A bit sucky but we have to determine which mode from the text of the selected option.
*
@ -1080,7 +1086,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
SANE_Status
sane_start (SANE_Handle handle)
{
BrotherDevice *device = (BrotherDevice *)handle;
BrotherDevice *device = static_cast<BrotherDevice *>(handle);
SANE_Status res;
DBG (DBG_EVENT, "sane_start\n");
@ -1120,7 +1126,7 @@ SANE_Status
sane_read (SANE_Handle handle, SANE_Byte * data,
SANE_Int max_length, SANE_Int * length)
{
BrotherDevice *device = (BrotherDevice *)handle;
BrotherDevice *device = static_cast<BrotherDevice *>(handle);
DBG (DBG_EVENT, "sane_read\n");
@ -1156,7 +1162,7 @@ void
sane_cancel (SANE_Handle handle)
{
SANE_Status res;
BrotherDevice *device = (BrotherDevice *)handle;
BrotherDevice *device = static_cast<BrotherDevice *>(handle);
DBG (DBG_EVENT, "sane_cancel\n");