|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <windows.h></windows.h>
|
|
Toshihiro Shimizu |
890ddd |
#include "assert.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "ttwainP.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttwain_utilPD.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttwain_global_def.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef __cplusplus
|
|
Toshihiro Shimizu |
890ddd |
extern "C" {
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static int getColorCount(LPBITMAPINFOHEADER pbi)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (pbi->biSize == sizeof(BITMAPCOREHEADER)) {
|
|
Toshihiro Shimizu |
890ddd |
LPBITMAPCOREHEADER lpbc = ((LPBITMAPCOREHEADER)pbi);
|
|
Toshihiro Shimizu |
890ddd |
return 1 << lpbc->bcBitCount;
|
|
Toshihiro Shimizu |
890ddd |
} else if (pbi->biClrUsed == 0)
|
|
Toshihiro Shimizu |
890ddd |
return 0xFFF & (1 << pbi->biBitCount);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return (int)pbi->biClrUsed;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
static size_t BmiColorTableBytes(LPBITMAPINFOHEADER pbi)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return getColorCount(pbi) * sizeof(RGBQUAD);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
static LPBYTE get_buffer(LPBITMAPINFOHEADER lpbi, int *iud)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
LPBYTE buf = (LPBYTE)lpbi + lpbi->biSize + BmiColorTableBytes(lpbi);
|
|
Toshihiro Shimizu |
890ddd |
*iud = (lpbi->biHeight > 0);
|
|
Toshihiro Shimizu |
890ddd |
return buf;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
#define PelsPerMeter2DPI(ppm) (((float)ppm * 2.54) / 100.0)
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
int TTWAIN_Native2RasterPD(void *handle, void *the_ras, int *lx, int *ly)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(!"DAFARE");
|
|
Toshihiro Shimizu |
890ddd |
#if 0
|
|
Toshihiro Shimizu |
890ddd |
LPBITMAPINFOHEADER lpBIH;
|
|
Toshihiro Shimizu |
890ddd |
LPBYTE buffer;
|
|
Toshihiro Shimizu |
890ddd |
int is_upside_down;
|
|
Toshihiro Shimizu |
890ddd |
int ras_type = 0;
|
|
Toshihiro Shimizu |
890ddd |
int linesize;
|
|
Toshihiro Shimizu |
890ddd |
float ras_bpp = 0;
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 rebound;
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *ras_out;
|
|
Toshihiro Shimizu |
890ddd |
int y,x;
|
|
Toshihiro Shimizu |
890ddd |
float xDpi, yDpi;
|
|
Toshihiro Shimizu |
890ddd |
DWORD bitmap_size;
|
|
Toshihiro Shimizu |
890ddd |
int extraX, extraY, extraByteX;
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 tot_rebound = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RASTER *ras = (RASTER *) the_ras;
|
|
Toshihiro Shimizu |
890ddd |
if (!handle)
|
|
Toshihiro Shimizu |
890ddd |
return FALSE;
|
|
Toshihiro Shimizu |
890ddd |
/*DAFARE
|
|
Toshihiro Shimizu |
890ddd |
if (!ras)
|
|
Toshihiro Shimizu |
890ddd |
return FALSE;
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
lpBIH = (LPBITMAPINFOHEADER) GLOBAL_LOCK(handle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
extraX = (int)lpBIH->biWidth - ras->lx;
|
|
Toshihiro Shimizu |
890ddd |
extraY = (int)lpBIH->biHeight- ras->ly;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*lx = lpBIH->biWidth ;
|
|
Toshihiro Shimizu |
890ddd |
*ly = lpBIH->biHeight;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(extraX>=0);
|
|
Toshihiro Shimizu |
890ddd |
assert(extraY>=0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
xDpi = PelsPerMeter2DPI(lpBIH->biXPelsPerMeter);
|
|
Toshihiro Shimizu |
890ddd |
yDpi = PelsPerMeter2DPI(lpBIH->biYPelsPerMeter);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (lpBIH->biBitCount)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
CASE 1:
|
|
Toshihiro Shimizu |
890ddd |
ras_type = RAS_BW;
|
|
Toshihiro Shimizu |
890ddd |
ras_bpp = 1.0/8.0;
|
|
Toshihiro Shimizu |
890ddd |
CASE 8:
|
|
Toshihiro Shimizu |
890ddd |
ras_type = RAS_GR8;
|
|
Toshihiro Shimizu |
890ddd |
ras_bpp = 1;
|
|
Toshihiro Shimizu |
890ddd |
CASE 24:
|
|
Toshihiro Shimizu |
890ddd |
ras_type = RAS_RGB;
|
|
Toshihiro Shimizu |
890ddd |
ras_bpp = 3;
|
|
Toshihiro Shimizu |
890ddd |
DEFAULT:
|
|
Toshihiro Shimizu |
890ddd |
assert(0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
extraByteX = CEIL(extraX * ras_bpp);
|
|
Toshihiro Shimizu |
890ddd |
bitmap_size = ((((lpBIH->biWidth * lpBIH->biBitCount) + 31) & ~31) >> 3) * lpBIH->biHeight;
|
|
Toshihiro Shimizu |
890ddd |
/* cfr. DIBs and Their Use
|
|
Toshihiro Shimizu |
890ddd |
Ron Gery
|
|
Toshihiro Shimizu |
890ddd |
Microsoft Developer Network Technology Group
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
ras_out = ras->buffer;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
buffer = 0;
|
|
Toshihiro Shimizu |
890ddd |
buffer = get_buffer(lpBIH, &is_upside_down);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (is_upside_down)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ras_out = ras->buffer;
|
|
Toshihiro Shimizu |
890ddd |
if (!TTwainData.transferInfo.nextImageNeedsToBeInverted)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
switch (ras_type)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
CASE RAS_GR8:
|
|
Toshihiro Shimizu |
890ddd |
__OR RAS_RGB:
|
|
Toshihiro Shimizu |
890ddd |
__OR RAS_BW:
|
|
Toshihiro Shimizu |
890ddd |
linesize = CEIL(ras->lx * ras_bpp);
|
|
Toshihiro Shimizu |
890ddd |
for (y =0; y<ras->ly; y++, ras_out += linesize)</ras->
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
memcpy(ras_out, buffer, linesize);
|
|
Toshihiro Shimizu |
890ddd |
buffer += linesize;
|
|
Toshihiro Shimizu |
890ddd |
buffer += extraByteX;
|
|
Toshihiro Shimizu |
890ddd |
rebound = (TUINT32) buffer;
|
|
Toshihiro Shimizu |
890ddd |
rebound = 4 - (rebound %4);
|
|
Toshihiro Shimizu |
890ddd |
tot_rebound +=rebound;
|
|
Toshihiro Shimizu |
890ddd |
buffer += rebound;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
switch (ras_type)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
CASE RAS_BW:
|
|
Toshihiro Shimizu |
890ddd |
linesize = CEIL(ras->lx * ras_bpp);
|
|
Toshihiro Shimizu |
890ddd |
for (y =0; y<ras->ly; y++, ras_out)</ras->
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (x = 0; x
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
UCHAR eight_bit;
|
|
Toshihiro Shimizu |
890ddd |
eight_bit = *buffer;
|
|
Toshihiro Shimizu |
890ddd |
*ras_out = (UCHAR) ~eight_bit;
|
|
Toshihiro Shimizu |
890ddd |
buffer++;
|
|
Toshihiro Shimizu |
890ddd |
ras_out++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
buffer += extraByteX;
|
|
Toshihiro Shimizu |
890ddd |
rebound = (TUINT32) buffer;
|
|
Toshihiro Shimizu |
890ddd |
rebound = 4 - (rebound %4);
|
|
Toshihiro Shimizu |
890ddd |
buffer += rebound;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
DEFAULT:
|
|
Toshihiro Shimizu |
890ddd |
assert(0); /*only BW images may need to be inverted*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(!"Not IMPL!");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
GLOBAL_UNLOCK(handle);
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
char msg[1024];
|
|
Toshihiro Shimizu |
890ddd |
sprintf(msg,"tot rebounded byte=%d\n", tot_rebound);
|
|
Toshihiro Shimizu |
890ddd |
OutputDebugString(msg);
|
|
Toshihiro Shimizu |
890ddd |
if (lpBIH->biSize)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert((lpBIH->biSizeImage-CEIL(ras->lx*ras->ly*ras_bpp))==tot_rebound);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
return TRUE;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
return 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef __cplusplus
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|