SANE_Status kvs20xx_read_image_data (struct scanner * s, unsigned page, unsigned side, void *buf, unsigned max_size, unsigned *size) { SANE_Status status; struct cmd c = { {0}, 10, 0, 0, CMD_IN }; c.cmd[0] = READ_10; c.cmd[4] = page; c.cmd[5] = side; c.data_size = max_size < MAX_READ_DATA_SIZE ? max_size : MAX_READ_DATA_SIZE; set24 (c.cmd + 6, c.data_size); status = send_command (s, &c); if (status && status != SANE_STATUS_EOF) return status; *size = c.data_size; DBG (DBG_INFO, "kvs20xx_read_image_data: read %d, status %d\n", *size, status); memcpy (buf, c.data, *size); return status; }
SANE_Status kvs40xx_read_image_data (struct scanner * s, unsigned page, unsigned side, void *buf, unsigned max_size, unsigned *size) { SANE_Status status; struct cmd c = { {0}, 10, NULL, 0, CMD_IN }; c.data_size = max_size < MAX_READ_DATA_SIZE ? max_size : MAX_READ_DATA_SIZE; c.cmd[0] = READ_10; c.cmd[4] = page; c.cmd[5] = side; set24 (c.cmd + 6, c.data_size); *size = 0; status = send_command (s, &c); if (status && status != SANE_STATUS_EOF && status != INCORRECT_LENGTH) return status; *size = c.data_size; memcpy (buf, c.data, *size); return status; }
SANE_Status kvs20xx_read_picture_element (struct scanner * s, unsigned side, SANE_Parameters * p) { SANE_Status status; struct cmd c = { {0}, 10, 0, 16, CMD_IN }; u32 *data; c.cmd[0] = READ_10; c.cmd[2] = 0x80; c.cmd[5] = side; set24 (c.cmd + 6, c.data_size); status = send_command (s, &c); if (status) return status; data = (u32 *) c.data; p->pixels_per_line = be2cpu32 (data[0]); p->lines = be2cpu32 (data[1]); return SANE_STATUS_GOOD; }
static SANE_Status st400_set_window( ST400_Device *dev ) { unsigned short xoff, yoff; SANE_Byte th; struct { /* 10byte command */ SANE_Byte cmd, lun, reserved1[4], tr_len[3], ctrl; /* 40byte window struct */ SANE_Byte reserved2[6], wd_len[2], winnr, reserved3; SANE_Byte x_res[2], y_res[2]; /* resolution: 200, 300, 400 */ SANE_Byte x_ul[2], y_ul[2]; /* upper left corner */ SANE_Byte width[2], height[2]; SANE_Byte reserved4, threshold; SANE_Byte reserved5, halftone; /* ht: 0 or 2 */ SANE_Byte bitsperpixel, reserved6[13]; /* bpp: 1 or 8 */ } scsi_cmd; /* The PC/Amiga source uses reserved5 to indicate A4/A5 paper size * (values 4 and 5), but a comment implies that this is only for the * scanning program and the value is ignored by the scanner. */ SANE_Status status; memset(&scsi_cmd, 0, sizeof(scsi_cmd)); scsi_cmd.cmd = CMD_SET_WINDOW; set24(scsi_cmd.tr_len, 40); set16(scsi_cmd.wd_len, 32); /* These offsets seem to be required to avoid damaging the scanner: * If a scan with 0/0 as the top left corner is started, the scanner * seems to try to move the carriage over the bottom end (not a * pretty sound). */ xoff = (11L * dev->val[OPT_RESOLUTION]) / 100; yoff = 6; th = (double)maxval(dev->model->bits) * SANE_UNFIX(dev->val[OPT_THRESHOLD]) / 100.0; scsi_cmd.winnr = 1; set16(scsi_cmd.x_res, (unsigned short)dev->val[OPT_RESOLUTION]); set16(scsi_cmd.y_res, (unsigned short)dev->val[OPT_RESOLUTION]); set16(scsi_cmd.x_ul, dev->x + xoff); set16(scsi_cmd.y_ul, dev->wy + yoff); set16(scsi_cmd.width, dev->w); set16(scsi_cmd.height, dev->wh); scsi_cmd.threshold = th; scsi_cmd.halftone = (dev->val[OPT_DEPTH] == 1) ? 0 : 2; scsi_cmd.bitsperpixel = dev->val[OPT_DEPTH]; DBG(DSCSI, "SCSI: sending SET_WINDOW (x=%hu y=%hu w=%hu h=%hu wy=%hu wh=%hu th=%d\n", dev->x, dev->y, dev->w, dev->h, dev->wy, dev->wh, (int)th); status = sanei_scsi_cmd(dev->fd, &scsi_cmd, sizeof(scsi_cmd), 0, 0); DBG(DSCSI, "SCSI: result=%s\n", sane_strstatus(status)); return status; }
void Http2Base::PushData(uint32_t id, const void* data, size_t size){ size_t left = size; while(left > remoteframebodylimit){ Http2_header* const header=(Http2_header *)p_move(p_malloc(remoteframebodylimit), -(char)sizeof(Http2_header)); memset(header, 0, sizeof(Http2_header)); set32(header->id, id); set24(header->length, remoteframebodylimit); memcpy(header+1, data, remoteframebodylimit); PushFrame(header); data = (char*)data + remoteframebodylimit; left -= remoteframebodylimit; } Http2_header* const header=(Http2_header *)p_move(p_malloc(left), -(char)sizeof(Http2_header)); memset(header, 0, sizeof(Http2_header)); set32(header->id, id); set24(header->length, left); if(size == 0) { LOGD(DHTTP2, "<guest2> [%d]: set stream end\n", id); header->flags = END_STREAM_F; }else{ memcpy(header+1, data, left); } PushFrame(header); }
static SANE_Status st400_read10( int fd, SANE_Byte *buf, size_t *lenP ) { struct { SANE_Byte cmd, lun, res[4], tr_len[3], ctrl; } scsi_cmd; SANE_Status status; memset(&scsi_cmd, 0, sizeof(scsi_cmd)); scsi_cmd.cmd = CMD_READ10; set24(scsi_cmd.tr_len, *lenP); DBG(DSCSI, "SCSI: sending READ10 (%lu bytes)\n", (u_long)(*lenP)); status = sanei_scsi_cmd(fd, &scsi_cmd, sizeof(scsi_cmd), buf, lenP); DBG(DSCSI, "SCSI: result=%s (%lu bytes)\n", sane_strstatus(status), (u_long)(*lenP)); return status; }
void Http2Base::SettingsProc(const Http2_header* header) { const Setting_Frame *sf = (const Setting_Frame *)(header + 1); if((header->flags & ACK_F) == 0) { while((char *)sf-(char *)(header+1) < get24(header->length)){ uint32_t value = get32(sf->value); switch(get16(sf->identifier)){ case SETTINGS_HEADER_TABLE_SIZE: LOGD(DHTTP2, "set head table size:%d\n", value); request_table.set_dynamic_table_size_limit_max(value); break; case SETTINGS_INITIAL_WINDOW_SIZE: if(value >= (uint32_t)1<<31u){ LOGE("ERROR window overflow\n"); ErrProc(ERR_FLOW_CONTROL_ERROR); return; } AdjustInitalFrameWindowSize((ssize_t)value - (ssize_t)remoteframewindowsize); remoteframewindowsize = value; LOGD(DHTTP2, "set inital frame window size:%d\n", remoteframewindowsize); break; case SETTINGS_MAX_FRAME_SIZE: if(value > 0xffffff || value < FRAMEBODYLIMIT){ LOGE("ERROR frame size overflow\n"); ErrProc(ERR_FRAME_SIZE_ERROR); return; } remoteframebodylimit = value; LOGD(DHTTP2, "set frame body size limit: %d\n", remoteframebodylimit); break; default: LOG("Get a unkown setting(%d): %d\n", get16(sf->identifier), value); break; } sf++; } Http2_header *header_back = (Http2_header *)p_memdup(header, sizeof(Http2_header)); set24(header_back->length, 0); header_back->flags |= ACK_F; PushFrame(header_back); }else if(get24(header->length) != 0){ LOGE("ERROR setting ack with content\n"); ErrProc(ERR_FRAME_SIZE_ERROR); } }
SANE_Status read_support_info (struct scanner * s, struct support_info * inf) { SANE_Status st; struct cmd c = { {0}, 10, NULL, sizeof (*inf), CMD_IN }; c.cmd[0] = READ_10; c.cmd[2] = SUPPORT_INFO; set24 (c.cmd + 6, c.data_size); st = send_command (s, &c); if (st) return st; memcpy (inf, c.data, sizeof (*inf)); return SANE_STATUS_GOOD; }
SANE_Status kvs40xx_document_exist (struct scanner * s) { SANE_Status status; struct cmd c = { {0}, 10, NULL, 6, CMD_IN }; u8 *d; c.cmd[0] = READ_10; c.cmd[2] = 0x81; set24 (c.cmd + 6, c.data_size); status = send_command (s, &c); if (status) return status; d = c.data; if (d[0] & 0x20) return SANE_STATUS_GOOD; return SANE_STATUS_NO_DOCS; }
LOCAL void Palette_Paint( HDC hDC, HWND hWindow ) /***********************************************************************/ { RECT ClientRect; LPPALETTE lpPalette; int iRowIncr, iColIncr, iWidth, iHeight, iRows, iCols; int iStart, iEntry, r, c, xCount, yCount; LPRGB lpRGB, lpLine; LFIXED xrate, yrate; BLTSESSION BltSession; FRMTYPEINFO TypeInfo; // get pointer to palette information lpPalette = (LPPALETTE)GetWindowLong(hWindow, GWL_PALETTE); if (!lpPalette) return; GetClientRect(hWindow, &ClientRect); FrameRect(hDC, &ClientRect, (HBRUSH)GetStockObject(BLACK_BRUSH) ); if (!lpPalette->iColors) return; // get ClientRect and allocate buffer for SuperBlt GetChipLayout(hWindow, &ClientRect, &iRows, &iCols, &iRowIncr, &iColIncr, &iStart); iWidth = RectWidth(&ClientRect); iHeight = RectHeight(&ClientRect); lpRGB = (LPRGB)Alloc((long)iWidth*3L); if (!lpRGB) return; yrate = FGET(iHeight, iRows); xrate = FGET(iWidth, iCols); FrameSetTypeInfo(&TypeInfo, FDT_RGBCOLOR, NULL); StartSuperBlt( &BltSession, hDC, NULL, lpBltScreen, &ClientRect, TypeInfo, 10, 0, 0, YES, NULL, NULL ); for (r = 0; r < iRows; ++r) { yCount = FMUL(r+1, yrate) - FMUL(r, yrate); set24(lpRGB, iWidth, RGB(255,255,255)); SuperBlt(&BltSession, (LPTR)lpRGB); yCount -= 2; while (--yCount >= 0) { iEntry = iStart + (r * iRowIncr); lpLine = lpRGB; set24(lpLine, iWidth, RGB(255,255,255)); for (c = 0; c < iCols; ++c) { xCount = FMUL(c+1, xrate) - FMUL(c, xrate); if (iEntry < lpPalette->iColors) set24(lpLine+1, xCount-2, RGB2long(lpPalette->lpColorInfo[iEntry].rgb)); lpLine += xCount; iEntry += iColIncr; } SuperBlt(&BltSession, (LPTR)lpRGB); } set24(lpRGB, iWidth, RGB(255,255,255)); SuperBlt(&BltSession, (LPTR)lpRGB); } SuperBlt(&BltSession, NULL); FreeUp((LPTR)lpRGB); }