kvs40xx: fix [-Wstrict-aliasing] compiler warnings

merge-requests/1/head
Olaf Meeuwissen 2015-12-31 17:51:00 +09:00
rodzic b1f886a2e3
commit 3f0c3df2fc
3 zmienionych plików z 42 dodań i 26 usunięć

Wyświetl plik

@ -228,6 +228,18 @@ swap_bytes32 (u32 x)
(x & (u32) 0x0000ff00UL) << 8 | (x & (u32) 0x00ff0000UL) >> 8; (x & (u32) 0x0000ff00UL) << 8 | (x & (u32) 0x00ff0000UL) >> 8;
} }
static inline void
copy16 (u8 * p, u16 x)
{
memcpy (p, (u8 *) &x, sizeof (x));
}
static inline void
copy32 (u8 * p, u32 x)
{
memcpy (p, (u8 *) &x, sizeof (x));
}
#if WORDS_BIGENDIAN #if WORDS_BIGENDIAN
static inline void static inline void
set24 (u8 * p, u32 x) set24 (u8 * p, u32 x)

Wyświetl plik

@ -360,7 +360,7 @@ kvs40xx_set_timeout (struct scanner * s, int timeout)
c.data_size = sizeof (t); c.data_size = sizeof (t);
c.cmd[0] = SET_TIMEOUT; c.cmd[0] = SET_TIMEOUT;
c.cmd[2] = 0x8d; c.cmd[2] = 0x8d;
*((u16 *) (c.cmd + 7)) = cpu2be16 (sizeof (t)); copy16 (c.cmd + 7, cpu2be16 (sizeof (t)));
if (s->bus == USB) if (s->bus == USB)
sanei_usb_set_timeout (timeout * 1000); sanei_usb_set_timeout (timeout * 1000);
@ -379,7 +379,7 @@ kvs40xx_set_window (struct scanner * s, int wnd_id)
c.data = &wnd; c.data = &wnd;
c.data_size = sizeof (wnd); c.data_size = sizeof (wnd);
c.cmd[0] = SET_WINDOW; c.cmd[0] = SET_WINDOW;
*((u16 *) (c.cmd + 7)) = cpu2be16 (sizeof (wnd)); copy16 (c.cmd + 7, cpu2be16 (sizeof (wnd)));
kvs40xx_init_window (s, &wnd, wnd_id); kvs40xx_init_window (s, &wnd, wnd_id);
return send_command (s, &c); return send_command (s, &c);

Wyświetl plik

@ -1272,41 +1272,45 @@ kvs40xx_init_window (struct scanner *s, struct window *wnd, int wnd_id)
{ {
int paper = str_index (paper_list, s->val[PAPER_SIZE].s), i; int paper = str_index (paper_list, s->val[PAPER_SIZE].s), i;
memset (wnd, 0, sizeof (struct window)); memset (wnd, 0, sizeof (struct window));
*(u16 *) wnd->window_descriptor_block_length = cpu2be16 (66); copy16 (wnd->window_descriptor_block_length, cpu2be16 (66));
wnd->window_identifier = wnd_id; wnd->window_identifier = wnd_id;
*(u16 *) wnd->x_resolution = cpu2be16 (s->val[RESOLUTION].w); copy16 (wnd->x_resolution, cpu2be16 (s->val[RESOLUTION].w));
*(u16 *) wnd->y_resolution = cpu2be16 (s->val[RESOLUTION].w); copy16 (wnd->y_resolution, cpu2be16 (s->val[RESOLUTION].w));
if (!paper) if (!paper)
{ {
*(u32 *) wnd->upper_left_x = copy32 (wnd->upper_left_x,
cpu2be32 (mm2scanner_units (s->val[TL_X].w)); cpu2be32 (mm2scanner_units (s->val[TL_X].w)));
*(u32 *) wnd->upper_left_y = copy32 (wnd->upper_left_y,
cpu2be32 (mm2scanner_units (s->val[TL_Y].w)); cpu2be32 (mm2scanner_units (s->val[TL_Y].w)));
*(u32 *) wnd->document_width = copy32 (wnd->document_width,
cpu2be32 (mm2scanner_units (s->val[BR_X].w)); cpu2be32 (mm2scanner_units (s->val[BR_X].w)));
*(u32 *) wnd->width = copy32 (wnd->width,
cpu2be32 (mm2scanner_units (s->val[BR_X].w - s->val[TL_X].w)); cpu2be32 (mm2scanner_units (s->val[BR_X].w - s->val[TL_X].w)));
*(u32 *) wnd->document_length = cpu2be32 (mm2scanner_units copy32 (wnd->document_length, cpu2be32 (mm2scanner_units
(s->val[BR_Y].w)); (s->val[BR_Y].w)));
*(u32 *) wnd->length = copy32 (wnd->length,
cpu2be32 (mm2scanner_units (s->val[BR_Y].w - s->val[TL_Y].w)); cpu2be32 (mm2scanner_units (s->val[BR_Y].w - s->val[TL_Y].w)));
} }
else else
{ {
u32 w = cpu2be32 (mm2scanner_units (paper_sizes[paper].width)); u32 w = cpu2be32 (mm2scanner_units (paper_sizes[paper].width));
u32 h = cpu2be32 (mm2scanner_units (paper_sizes[paper].height)); u32 h = cpu2be32 (mm2scanner_units (paper_sizes[paper].height));
*(u32 *) wnd->upper_left_x = cpu2be32 (mm2scanner_units (0)); copy32 (wnd->upper_left_x, cpu2be32 (mm2scanner_units (0)));
*(u32 *) wnd->upper_left_y = cpu2be32 (mm2scanner_units (0)); copy32 (wnd->upper_left_y, cpu2be32 (mm2scanner_units (0)));
if (!s->val[LANDSCAPE].b) if (!s->val[LANDSCAPE].b)
{ {
*(u32 *) wnd->document_width = *(u32 *) wnd->width = w; copy32 (wnd->width, w);
*(u32 *) wnd->document_length = *(u32 *) wnd->length = h; copy32 (wnd->length, h);
copy32 (wnd->document_width, w);
copy32 (wnd->document_length, h);
} }
else else
{ {
*(u32 *) wnd->document_width = *(u32 *) wnd->width = h; copy32 (wnd->width, h);
*(u32 *) wnd->document_length = *(u32 *) wnd->length = w; copy32 (wnd->length, w);
copy32 (wnd->document_width, h);
copy32 (wnd->document_length, w);
} }
} }
wnd->brightness = s->val[BRIGHTNESS].w; wnd->brightness = s->val[BRIGHTNESS].w;
@ -1315,11 +1319,11 @@ kvs40xx_init_window (struct scanner *s, struct window *wnd, int wnd_id)
wnd->image_composition = mode_val[str_index (mode_list, s->val[MODE].s)]; wnd->image_composition = mode_val[str_index (mode_list, s->val[MODE].s)];
wnd->bit_per_pixel = bps_val[str_index (mode_list, s->val[MODE].s)]; wnd->bit_per_pixel = bps_val[str_index (mode_list, s->val[MODE].s)];
*(u16 *) wnd->halftone_pattern = copy16 (wnd->halftone_pattern,
cpu2be16 (str_index (halftone_pattern, s->val[HALFTONE_PATTERN].s)); cpu2be16 (str_index (halftone_pattern, s->val[HALFTONE_PATTERN].s)));
wnd->rif_padding = s->val[INVERSE].b << 7; wnd->rif_padding = s->val[INVERSE].b << 7;
*(u16 *) wnd->bit_ordering = cpu2be16 (BIT_ORDERING); copy16 (wnd->bit_ordering, cpu2be16 (BIT_ORDERING));
wnd->compression_type = s->val[COMPRESSION].b ? 0x81 : 0; wnd->compression_type = s->val[COMPRESSION].b ? 0x81 : 0;
wnd->compression_argument = s->val[COMPRESSION_PAR].w; wnd->compression_argument = s->val[COMPRESSION_PAR].w;