1 /* sane - Scanner Access Now Easy. 2 3 pieusb_buffer.h 4 5 Copyright (C) 2012-2015 Jan Vleeshouwers, Michael Rickmann, Klaus Kaempf 6 7 This file is part of the SANE package. 8 9 This program is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License as 11 published by the Free Software Foundation; either version 2 of the 12 License, or (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, but 15 WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <https://www.gnu.org/licenses/>. 21 22 As a special exception, the authors of SANE give permission for 23 additional uses of the libraries contained in this release of SANE. 24 25 The exception is that, if you link a SANE library with other files 26 to produce an executable, this does not by itself cause the 27 resulting executable to be covered by the GNU General Public 28 License. Your use of that executable is in no way restricted on 29 account of linking the SANE library code into it. 30 31 This exception does not, however, invalidate any other reasons why 32 the executable file might be covered by the GNU General Public 33 License. 34 35 If you submit changes to SANE to the maintainers to be included in 36 a subsequent release, you agree by submitting the changes that 37 those changes may be distributed with this exception intact. 38 39 If you write modifications of your own for SANE, it is your choice 40 whether to permit this exception to apply to your modifications. 41 If you do not wish that, delete this exception notice. */ 42 43 #ifndef PIEUSB_BUFFER_H 44 #define PIEUSB_BUFFER_H 45 46 #include "pieusb.h" 47 #include "../include/sane/sanei_ir.h" 48 49 #ifndef L_tmpnam 50 #define L_tmpnam 20 51 #endif 52 53 struct Pieusb_Read_Buffer 54 { 55 SANE_Uint* data; /* image data - always store as 16 bit values; mmap'ed */ 56 unsigned int data_size; /* size of mmap region */ 57 SANE_Int data_file; /* associated file if memory mapped */ 58 char buffer_name[L_tmpnam]; 59 60 /* Buffer parameters */ 61 SANE_Int width; /* number of pixels on a line */ 62 SANE_Int height; /* number of lines in buffer */ 63 SANE_Int colors; /* number of colors in a pixel */ 64 SANE_Int depth; /* number of bits of a color */ 65 SANE_Int packing_density; /* number of single color samples packed together */ 66 67 /* Derived quantities 68 * All derived quantities pertain to the image, not to the buffer */ 69 SANE_Int packet_size_bytes; /* number of bytes of a packet of samples = round_up(depth*packing_density/8) */ 70 SANE_Int line_size_packets; /* number of packets on a single color line = round-down((width+packing_density-1)/packing_density) */ 71 SANE_Int line_size_bytes; /* number of bytes on a single color line = line_size_packets*packet_size_bytes */ 72 SANE_Int image_size_bytes; /* total number of bytes in the buffer (= colors * height * line_size_packets* packet_size_bytes) */ 73 SANE_Int color_index_red; /* color index of the red color plane (-1 if not used) */ 74 SANE_Int color_index_green; /* color index of the green color plane (-1 if not used) */ 75 SANE_Int color_index_blue; /* color index of the blue color plane (-1 if not used) */ 76 SANE_Int color_index_infrared; /* color index of the infrared color plane (-1 if not used) */ 77 78 /* Reading - byte oriented */ 79 SANE_Uint** p_read; /* array of pointers to next sample to read for each color plane */ 80 SANE_Int read_index[4]; /* location where to read next (color-index, height-index, width-index, byte-index) */ 81 SANE_Int bytes_read; /* number of bytes read from the buffer */ 82 SANE_Int bytes_unread; /* number of bytes not yet read from the buffer */ 83 SANE_Int bytes_written; /* number of bytes written to the buffer */ 84 85 /* Writing */ 86 SANE_Uint** p_write; /* array of pointers to next byte to write for each color plane */ 87 }; 88 89 void sanei_pieusb_buffer_get(struct Pieusb_Read_Buffer* buffer, SANE_Byte* data, SANE_Int max_len, SANE_Int* len); 90 SANE_Status sanei_pieusb_buffer_create(struct Pieusb_Read_Buffer* buffer, SANE_Int width, SANE_Int height, SANE_Byte colors, SANE_Byte depth); 91 void sanei_pieusb_buffer_delete(struct Pieusb_Read_Buffer* buffer); 92 SANE_Int sanei_pieusb_buffer_put_full_color_line(struct Pieusb_Read_Buffer* buffer, void* line, int size); 93 SANE_Int sanei_pieusb_buffer_put_single_color_line(struct Pieusb_Read_Buffer* buffer, SANE_Byte color, void* line, SANE_Int size); 94 95 #endif /* PIEUSB_BUFFER_H */ 96