inline void wildCopy32(UInt8 * dst, const UInt8 * src, UInt8 * dst_end) { /// Unrolling with clang is doing >10% performance degrade. #if defined(__clang__) #pragma nounroll #endif do { copy32(dst, src); dst += 32; src += 32; } while (dst < dst_end); }
template <> void inline copy<32>(UInt8 * dst, const UInt8 * src) { copy32(dst, src); }
void kvs40xx_init_window (struct scanner *s, struct window *wnd, int wnd_id) { int paper = str_index (paper_list, s->val[PAPER_SIZE].s), i; memset (wnd, 0, sizeof (struct window)); copy16 (wnd->window_descriptor_block_length, cpu2be16 (66)); wnd->window_identifier = wnd_id; copy16 (wnd->x_resolution, cpu2be16 (s->val[RESOLUTION].w)); copy16 (wnd->y_resolution, cpu2be16 (s->val[RESOLUTION].w)); if (!paper) { copy32 (wnd->upper_left_x, cpu2be32 (mm2scanner_units (s->val[TL_X].w))); copy32 (wnd->upper_left_y, cpu2be32 (mm2scanner_units (s->val[TL_Y].w))); copy32 (wnd->document_width, cpu2be32 (mm2scanner_units (s->val[BR_X].w))); copy32 (wnd->width, cpu2be32 (mm2scanner_units (s->val[BR_X].w - s->val[TL_X].w))); copy32 (wnd->document_length, cpu2be32 (mm2scanner_units (s->val[BR_Y].w))); copy32 (wnd->length, cpu2be32 (mm2scanner_units (s->val[BR_Y].w - s->val[TL_Y].w))); } else { u32 w = cpu2be32 (mm2scanner_units (paper_sizes[paper].width)); u32 h = cpu2be32 (mm2scanner_units (paper_sizes[paper].height)); copy32 (wnd->upper_left_x, cpu2be32 (mm2scanner_units (0))); copy32 (wnd->upper_left_y, cpu2be32 (mm2scanner_units (0))); if (!s->val[LANDSCAPE].b) { copy32 (wnd->width, w); copy32 (wnd->length, h); copy32 (wnd->document_width, w); copy32 (wnd->document_length, h); } else { copy32 (wnd->width, h); copy32 (wnd->length, w); copy32 (wnd->document_width, h); copy32 (wnd->document_length, w); } } wnd->brightness = s->val[BRIGHTNESS].w; wnd->threshold = s->val[THRESHOLD].w; wnd->contrast = s->val[CONTRAST].w; 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)]; copy16 (wnd->halftone_pattern, cpu2be16 (str_index (halftone_pattern, s->val[HALFTONE_PATTERN].s))); wnd->rif_padding = s->val[INVERSE].b << 7; copy16 (wnd->bit_ordering, cpu2be16 (BIT_ORDERING)); wnd->compression_type = s->val[COMPRESSION].b ? 0x81 : 0; wnd->compression_argument = s->val[COMPRESSION_PAR].w; wnd->vendor_unique_identifier = 0; wnd->nobuf_fstspeed_dfstop = str_index (source_list, s->val[SOURCE].s) << 7 | str_index (stapeled_list, s->val[STAPELED_DOC].s) << 5 | s->val[STOP_SKEW].b << 4 | s->val[CROP].b << 3 | s->val[DFSTOP].b << 0; wnd->mirror_image = s->val[MIRROR].b << 7 | s->val[DFEED_L].b << 2 | s->val[DFEED_C].b << 1 | s->val[DFEED_R].b << 0; wnd->image_emphasis = str_index (image_emphasis_list, s->val[IMAGE_EMPHASIS].s); wnd->gamma_correction = gamma_val[str_index (gamma_list, s->val[GAMMA_CORRECTION].s)]; wnd->mcd_lamp_dfeed_sens = str_index (lamp_list, s->val[LAMP].s) << 4 | str_index (dfeed_sence_list, s->val[DFEED_SENCE].s); wnd->document_size = (paper != 0) << 7 | s->val[LENGTHCTL].b << 6 | s->val[LONG_PAPER].b << 5 | s->val[LANDSCAPE].b << 4 | paper_val[paper]; wnd->ahead_deskew_dfeed_scan_area_fspeed_rshad = (s->val[DESKEW].b || s->val[CROP].b ? 2 : 0) << 5 | /*XXX*/ s->val[DBLFEED].b << 4 | s->val[FIT_TO_PAGE].b << 2; wnd->continuous_scanning_pages = str_index (feeder_mode_list, s->val[FEEDER_MODE].s) ? 0xff : 0; wnd->automatic_threshold_mode = automatic_threshold_val [str_index (automatic_threshold_list, s->val[AUTOMATIC_THRESHOLD].s)]; wnd->automatic_separation_mode = 0; /*Does not supported */ wnd->standard_white_level_mode = white_level_val[str_index (white_level_list, s->val[WHITE_LEVEL].s)]; wnd->b_wnr_noise_reduction = str_index (noise_reduction_list, s->val[NOISE_REDUCTION].s); i = str_index (manual_feed_list, s->val[MANUALFEED].s); wnd->mfeed_toppos_btmpos_dsepa_hsepa_dcont_rstkr = i << 6 | s->val[TOPPOS].b << 5 | s->val[BTMPOS].b << 4; wnd->stop_mode = 1; wnd->red_chroma = s->val[RED_CHROMA].w; wnd->blue_chroma = s->val[BLUE_CHROMA].w; }
void copyTo(uint8_t *to, bool swap) { if ( swap ) { assert(0 && "non-native endianness not supported yet"); } else { if( is64() ) { // in-memory matches on-disk, so copy segment fields followed by sections ::memcpy(to, (uint8_t*)&cmd, 72); if ( nsects != 0 ) ::memcpy(&to[72], sections, sizeof(section_64)*nsects); } else { // on-disk is 32-bit struct, so copy each field ::memcpy(to, (uint8_t*)&cmd, 24); copy32(to, 24, vmaddr); copy32(to, 28, vmsize); copy32(to, 32, fileoff); copy32(to, 36, filesize); copy32(to, 40, maxprot); copy32(to, 44, initprot); copy32(to, 48, nsects); copy32(to, 52, flags); for(uint32_t i=0; i < nsects; ++i) { unsigned off = 56+i*68; ::memcpy(&to[off], sections[i].sectname, 32); copy32(to, off+32, sections[i].addr); copy32(to, off+36, sections[i].size); copy32(to, off+40, sections[i].offset); copy32(to, off+44, sections[i].align); copy32(to, off+48, sections[i].reloff); copy32(to, off+52, sections[i].nreloc); copy32(to, off+56, sections[i].flags); copy32(to, off+60, sections[i].reserved1); copy32(to, off+64, sections[i].reserved2); } } } }