1 /*
2    SANE EPSON backend
3    Copyright (C) 2001 SEIKO EPSON Corporation
4 
5    Date         Author      Reason
6    07/10/2001   Peter       New
7 
8    This file is part of the `iscan' program.
9 
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 
24    As a special exception, the copyright holders give permission
25    to link the code of this program with the esmod library and
26    distribute linked combinations including the two.  You must obey
27    the GNU General Public License in all respects for all of the
28    code used other then esmod.
29 */
30 
31 /*--------------------------------------------------------------*/
32 #include "pisa_img_converter.h"
33 #include "pisa_error.h"
34 
35 /*--------------------------------------------------------------*/
36 
37 
38 /*Convert 8bpp grayscale pixels to 24bpp rgb pixels*/
convert_grayscale_to_rgb(BYTE * in_buf,long width,long height,BYTE * out_rgb_buf)39 int convert_grayscale_to_rgb(BYTE* in_buf, long width, long height, BYTE* out_rgb_buf)
40 {
41   long i,j,ofs;
42   ofs = 0;
43   for( i = 0; i<height; i++)
44     for( j = 0; j<width; j++, ofs+=3)
45       {
46 	/*just copy the gray value 3 times to make rgb*/
47 	out_rgb_buf[ofs] = in_buf[i*width+j];
48 	out_rgb_buf[ofs+1] = out_rgb_buf[ofs];
49 	out_rgb_buf[ofs+2] = out_rgb_buf[ofs];
50       }
51   return PISA_ERR_SUCCESS;
52 }
53 
54 /*Convert 1bpp b&w pixels to 24bpp rgb pixels*/
convert_binary_to_rgb(BYTE * in_buf,long width,long height,BYTE * out_rgb_buf)55 int convert_binary_to_rgb(BYTE* in_buf, long width, long height, BYTE* out_rgb_buf)
56 {
57   long i,j,in_ofs, out_ofs;
58   int rgb_val;
59   int bitshift;
60   unsigned int temp_byte = 0;
61 
62   //offset into input image
63   in_ofs = 0;
64   //offset into output image
65   out_ofs = 0;
66 
67   for( i = 0; i<height; i++)
68     {
69       j = 0;
70       bitshift = -1;
71       in_ofs  = i*(int)((width+7)/8);
72       while( j<width)
73 	{
74 	  //get a new byte every 8 columns
75 	  if(j%8 == 0)
76 	    {
77 	      temp_byte = in_buf[in_ofs+(int)(j/8)];
78 	      bitshift = 7;
79 	    }
80 
81 	  //black or white pixel
82 	  if((temp_byte >> bitshift) & 1)
83 	    rgb_val = IMG_CONVERTER_RGB_WHITE;
84 	  else
85 	    rgb_val = IMG_CONVERTER_RGB_BLACK;
86 
87 	  //write the rgb values
88 	  out_rgb_buf[out_ofs] = (unsigned int) rgb_val;
89 	  out_rgb_buf[out_ofs+1] = (unsigned int)rgb_val;
90 	  out_rgb_buf[out_ofs+2] = (unsigned int)rgb_val;
91 	  j++;
92 	  out_ofs+=3;
93 	  bitshift--;
94 	}
95     }
96   return PISA_ERR_SUCCESS;
97 }
98 
99 
100