1998-10-24 10:44:05 +00:00
|
|
|
/*
|
|
|
|
* PostScript driver bitmap functions
|
|
|
|
*
|
|
|
|
* Copyright 1998 Huw D M Davies
|
|
|
|
*
|
2002-03-09 23:29:33 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1998-10-24 10:44:05 +00:00
|
|
|
*/
|
|
|
|
|
2003-05-19 19:06:47 +00:00
|
|
|
#include <assert.h>
|
2003-11-03 22:14:46 +00:00
|
|
|
#include <stdlib.h>
|
2003-05-19 19:06:47 +00:00
|
|
|
|
1998-10-24 10:44:05 +00:00
|
|
|
#include "psdrv.h"
|
1999-03-23 13:46:04 +00:00
|
|
|
#include "winbase.h"
|
2002-03-28 22:22:05 +00:00
|
|
|
#include "wine/debug.h"
|
1999-03-23 13:46:04 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
|
1999-04-19 14:56:29 +00:00
|
|
|
|
1999-03-23 13:46:04 +00:00
|
|
|
|
2002-03-28 22:22:05 +00:00
|
|
|
/* Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned. */
|
2007-03-17 10:43:46 +00:00
|
|
|
static inline int get_dib_width_bytes( int width, int depth )
|
2002-03-28 22:22:05 +00:00
|
|
|
{
|
2011-08-29 10:03:17 +00:00
|
|
|
return ((width * depth + 31) / 8) & ~3;
|
2002-03-28 22:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-23 13:46:04 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* PSDRV_WriteImageHeader
|
|
|
|
*
|
|
|
|
* Helper for PSDRV_StretchDIBits
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Uses level 2 PostScript
|
|
|
|
*/
|
|
|
|
|
2011-07-07 11:29:17 +00:00
|
|
|
static BOOL PSDRV_WriteImageHeader(PHYSDEV dev, const BITMAPINFO *info, INT xDst,
|
1999-03-23 13:46:04 +00:00
|
|
|
INT yDst, INT widthDst, INT heightDst,
|
|
|
|
INT widthSrc, INT heightSrc)
|
|
|
|
{
|
2011-07-20 12:36:10 +00:00
|
|
|
switch(info->bmiHeader.biBitCount)
|
|
|
|
{
|
1999-03-23 13:46:04 +00:00
|
|
|
case 1:
|
2011-07-20 12:36:10 +00:00
|
|
|
case 4:
|
|
|
|
case 8:
|
|
|
|
PSDRV_WriteIndexColorSpaceBegin(dev, (1 << info->bmiHeader.biBitCount) - 1);
|
|
|
|
PSDRV_WriteRGBQUAD(dev, info->bmiColors, 1 << info->bmiHeader.biBitCount);
|
2011-07-07 11:29:17 +00:00
|
|
|
PSDRV_WriteIndexColorSpaceEnd(dev);
|
1999-03-23 13:46:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
case 24:
|
|
|
|
case 32:
|
|
|
|
{
|
|
|
|
PSCOLOR pscol;
|
|
|
|
pscol.type = PSCOLOR_RGB;
|
|
|
|
pscol.value.rgb.r = pscol.value.rgb.g = pscol.value.rgb.b = 0.0;
|
2011-07-07 11:29:17 +00:00
|
|
|
PSDRV_WriteSetColor(dev, &pscol);
|
1999-03-23 13:46:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-07 11:29:17 +00:00
|
|
|
PSDRV_WriteImage(dev, info->bmiHeader.biBitCount, xDst, yDst,
|
2011-07-20 12:36:10 +00:00
|
|
|
widthDst, heightDst, widthSrc, heightSrc, FALSE, info->bmiHeader.biHeight < 0);
|
2003-05-19 19:06:47 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* PSDRV_WriteImageMaskHeader
|
|
|
|
*
|
|
|
|
* Helper for PSDRV_StretchDIBits
|
|
|
|
*
|
|
|
|
* We use the imagemask operator for 1bpp bitmaps since the output
|
|
|
|
* takes much less time for the printer to render.
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Uses level 2 PostScript
|
|
|
|
*/
|
|
|
|
|
2011-07-07 11:29:17 +00:00
|
|
|
static BOOL PSDRV_WriteImageMaskHeader(PHYSDEV dev, const BITMAPINFO *info, INT xDst,
|
2003-05-19 19:06:47 +00:00
|
|
|
INT yDst, INT widthDst, INT heightDst,
|
|
|
|
INT widthSrc, INT heightSrc)
|
|
|
|
{
|
|
|
|
PSCOLOR bkgnd, foregnd;
|
|
|
|
|
|
|
|
assert(info->bmiHeader.biBitCount == 1);
|
|
|
|
|
|
|
|
/* We'll write the mask with -ve polarity so that
|
|
|
|
the foregnd color corresponds to a bit equal to
|
|
|
|
0 in the bitmap.
|
|
|
|
*/
|
2011-07-20 12:36:10 +00:00
|
|
|
PSDRV_CreateColor(dev, &foregnd, RGB(info->bmiColors[0].rgbRed,
|
|
|
|
info->bmiColors[0].rgbGreen,
|
|
|
|
info->bmiColors[0].rgbBlue) );
|
|
|
|
PSDRV_CreateColor(dev, &bkgnd, RGB(info->bmiColors[1].rgbRed,
|
|
|
|
info->bmiColors[1].rgbGreen,
|
|
|
|
info->bmiColors[1].rgbBlue) );
|
2011-07-07 11:29:17 +00:00
|
|
|
|
|
|
|
PSDRV_WriteGSave(dev);
|
|
|
|
PSDRV_WriteNewPath(dev);
|
|
|
|
PSDRV_WriteRectangle(dev, xDst, yDst, widthDst, heightDst);
|
|
|
|
PSDRV_WriteSetColor(dev, &bkgnd);
|
|
|
|
PSDRV_WriteFill(dev);
|
|
|
|
PSDRV_WriteGRestore(dev);
|
|
|
|
|
|
|
|
PSDRV_WriteSetColor(dev, &foregnd);
|
|
|
|
PSDRV_WriteImage(dev, 1, xDst, yDst, widthDst, heightDst,
|
2011-07-20 12:36:10 +00:00
|
|
|
widthSrc, heightSrc, TRUE, info->bmiHeader.biHeight < 0);
|
2003-05-19 19:06:47 +00:00
|
|
|
|
1999-03-23 13:46:04 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
1998-10-24 10:44:05 +00:00
|
|
|
|
2003-12-08 21:40:27 +00:00
|
|
|
static inline DWORD max_rle_size(DWORD size)
|
|
|
|
{
|
|
|
|
return size + (size + 127) / 128 + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD max_ascii85_size(DWORD size)
|
|
|
|
{
|
|
|
|
return (size + 3) / 4 * 5;
|
|
|
|
}
|
1998-10-24 10:44:05 +00:00
|
|
|
|
2011-07-20 14:04:28 +00:00
|
|
|
static void free_heap_bits( struct gdi_image_bits *bits )
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, bits->ptr );
|
|
|
|
}
|
|
|
|
|
2011-07-20 12:36:10 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* PSDRV_WriteImageBits
|
|
|
|
*/
|
|
|
|
static void PSDRV_WriteImageBits( PHYSDEV dev, const BITMAPINFO *info, INT xDst, INT yDst,
|
|
|
|
INT widthDst, INT heightDst, INT widthSrc, INT heightSrc,
|
|
|
|
void *bits, DWORD size )
|
|
|
|
{
|
|
|
|
BYTE *rle, *ascii85;
|
|
|
|
DWORD rle_len, ascii85_len;
|
|
|
|
|
|
|
|
if (info->bmiHeader.biBitCount == 1)
|
|
|
|
/* Use imagemask rather than image */
|
|
|
|
PSDRV_WriteImageMaskHeader(dev, info, xDst, yDst, widthDst, heightDst,
|
|
|
|
widthSrc, heightSrc);
|
|
|
|
else
|
|
|
|
PSDRV_WriteImageHeader(dev, info, xDst, yDst, widthDst, heightDst,
|
|
|
|
widthSrc, heightSrc);
|
|
|
|
|
|
|
|
rle = HeapAlloc(GetProcessHeap(), 0, max_rle_size(size));
|
|
|
|
rle_len = RLE_encode(bits, size, rle);
|
|
|
|
ascii85 = HeapAlloc(GetProcessHeap(), 0, max_ascii85_size(rle_len));
|
|
|
|
ascii85_len = ASCII85_encode(rle, rle_len, ascii85);
|
|
|
|
HeapFree(GetProcessHeap(), 0, rle);
|
|
|
|
PSDRV_WriteData(dev, ascii85, ascii85_len);
|
|
|
|
PSDRV_WriteSpool(dev, "~>\n", 3);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ascii85);
|
|
|
|
}
|
|
|
|
|
2011-07-20 14:04:28 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* PSDRV_PutImage
|
|
|
|
*/
|
2011-07-21 16:49:47 +00:00
|
|
|
DWORD PSDRV_PutImage( PHYSDEV dev, HBITMAP hbitmap, HRGN clip, BITMAPINFO *info,
|
|
|
|
const struct gdi_image_bits *bits, struct bitblt_coords *src,
|
|
|
|
struct bitblt_coords *dst, DWORD rop )
|
2011-07-20 14:04:28 +00:00
|
|
|
{
|
|
|
|
int src_stride, dst_stride, size, x, y, width, height, bit_offset;
|
|
|
|
int dst_x, dst_y, dst_width, dst_height;
|
|
|
|
unsigned char *src_ptr, *dst_ptr;
|
|
|
|
struct gdi_image_bits dst_bits;
|
|
|
|
|
|
|
|
if (hbitmap) return ERROR_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
if (info->bmiHeader.biPlanes != 1) goto update_format;
|
|
|
|
if (info->bmiHeader.biCompression != BI_RGB) goto update_format;
|
|
|
|
if (info->bmiHeader.biBitCount == 16 || info->bmiHeader.biBitCount == 32) goto update_format;
|
|
|
|
if (!bits) return ERROR_SUCCESS; /* just querying the format */
|
|
|
|
|
|
|
|
TRACE( "bpp %u %s -> %s\n", info->bmiHeader.biBitCount, wine_dbgstr_rect(&src->visrect),
|
|
|
|
wine_dbgstr_rect(&dst->visrect) );
|
|
|
|
|
|
|
|
width = src->visrect.right - src->visrect.left;
|
|
|
|
height = src->visrect.bottom - src->visrect.top;
|
|
|
|
src_stride = get_dib_width_bytes( info->bmiHeader.biWidth, info->bmiHeader.biBitCount );
|
|
|
|
dst_stride = (width * info->bmiHeader.biBitCount + 7) / 8;
|
|
|
|
|
|
|
|
src_ptr = bits->ptr;
|
|
|
|
if (info->bmiHeader.biHeight > 0)
|
|
|
|
src_ptr += (info->bmiHeader.biHeight - src->visrect.bottom) * src_stride;
|
|
|
|
else
|
|
|
|
src_ptr += src->visrect.top * src_stride;
|
|
|
|
bit_offset = src->visrect.left * info->bmiHeader.biBitCount;
|
|
|
|
src_ptr += bit_offset / 8;
|
|
|
|
bit_offset &= 7;
|
|
|
|
if (bit_offset) FIXME( "pos %s not supported\n", wine_dbgstr_rect(&src->visrect) );
|
|
|
|
size = height * dst_stride;
|
|
|
|
|
|
|
|
if (src_stride != dst_stride || (info->bmiHeader.biBitCount == 24 && !bits->is_copy))
|
|
|
|
{
|
|
|
|
if (!(dst_bits.ptr = HeapAlloc( GetProcessHeap(), 0, size ))) return ERROR_OUTOFMEMORY;
|
|
|
|
dst_bits.is_copy = TRUE;
|
|
|
|
dst_bits.free = free_heap_bits;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dst_bits.ptr = src_ptr;
|
|
|
|
dst_bits.is_copy = bits->is_copy;
|
|
|
|
dst_bits.free = NULL;
|
|
|
|
}
|
|
|
|
dst_ptr = dst_bits.ptr;
|
|
|
|
|
|
|
|
switch (info->bmiHeader.biBitCount)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 4:
|
|
|
|
case 8:
|
|
|
|
if (src_stride != dst_stride)
|
|
|
|
for (y = 0; y < height; y++, src_ptr += src_stride, dst_ptr += dst_stride)
|
|
|
|
memcpy( dst_ptr, src_ptr, dst_stride );
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
if (dst_ptr != src_ptr)
|
|
|
|
for (y = 0; y < height; y++, src_ptr += src_stride, dst_ptr += dst_stride)
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
dst_ptr[x * 3] = src_ptr[x * 3 + 2];
|
|
|
|
dst_ptr[x * 3 + 1] = src_ptr[x * 3 + 1];
|
|
|
|
dst_ptr[x * 3 + 2] = src_ptr[x * 3];
|
|
|
|
}
|
|
|
|
else /* swap R and B in place */
|
|
|
|
for (y = 0; y < height; y++, src_ptr += src_stride, dst_ptr += dst_stride)
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
unsigned char tmp = dst_ptr[x * 3];
|
|
|
|
dst_ptr[x * 3] = dst_ptr[x * 3 + 2];
|
|
|
|
dst_ptr[x * 3 + 2] = tmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_x = dst->visrect.left;
|
|
|
|
dst_y = dst->visrect.top,
|
|
|
|
dst_width = dst->visrect.right - dst->visrect.left;
|
|
|
|
dst_height = dst->visrect.bottom - dst->visrect.top;
|
|
|
|
if (src->width * dst->width < 0)
|
|
|
|
{
|
|
|
|
dst_x += dst_width;
|
|
|
|
dst_width = -dst_width;
|
|
|
|
}
|
|
|
|
if (src->height * dst->height < 0)
|
|
|
|
{
|
|
|
|
dst_y += dst_height;
|
|
|
|
dst_height = -dst_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
PSDRV_SetClip(dev);
|
|
|
|
PSDRV_WriteGSave(dev);
|
2011-07-21 17:46:28 +00:00
|
|
|
if (clip) PSDRV_AddClip( dev, clip );
|
2011-07-20 14:04:28 +00:00
|
|
|
PSDRV_WriteImageBits( dev, info, dst_x, dst_y, dst_width, dst_height,
|
|
|
|
width, height, dst_bits.ptr, size );
|
|
|
|
PSDRV_WriteGRestore(dev);
|
|
|
|
PSDRV_ResetClip(dev);
|
|
|
|
if (dst_bits.free) dst_bits.free( &dst_bits );
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
update_format:
|
|
|
|
info->bmiHeader.biPlanes = 1;
|
|
|
|
if (info->bmiHeader.biBitCount > 8) info->bmiHeader.biBitCount = 24;
|
|
|
|
info->bmiHeader.biCompression = BI_RGB;
|
|
|
|
return ERROR_BAD_FORMAT;
|
|
|
|
}
|
|
|
|
|
1998-10-24 10:44:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* PSDRV_StretchDIBits
|
1999-03-23 13:46:04 +00:00
|
|
|
*
|
|
|
|
* BUGS
|
1999-12-25 22:56:13 +00:00
|
|
|
* Doesn't work correctly if xSrc isn't byte aligned - this affects 1 and 4
|
|
|
|
* bit depths.
|
1999-03-23 13:46:04 +00:00
|
|
|
* Compression not implemented.
|
1998-10-24 10:44:05 +00:00
|
|
|
*/
|
2011-07-13 12:56:12 +00:00
|
|
|
INT PSDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
|
|
|
|
INT heightDst, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, const void *bits,
|
2011-09-02 13:53:10 +00:00
|
|
|
BITMAPINFO *info, UINT wUsage, DWORD dwRop )
|
1998-10-24 10:44:05 +00:00
|
|
|
{
|
2009-11-18 12:20:17 +00:00
|
|
|
INT stride;
|
1999-03-23 13:46:04 +00:00
|
|
|
INT line;
|
2002-05-02 01:39:48 +00:00
|
|
|
POINT pt[2];
|
2003-12-08 21:40:27 +00:00
|
|
|
const BYTE *src_ptr;
|
2011-07-20 12:36:10 +00:00
|
|
|
BYTE *dst_ptr, *bitmap;
|
|
|
|
DWORD bitmap_size;
|
1999-03-23 13:46:04 +00:00
|
|
|
|
2011-07-07 11:29:17 +00:00
|
|
|
TRACE("%p (%d,%d %dx%d) -> (%d,%d %dx%d)\n", dev->hdc,
|
1999-03-23 13:46:04 +00:00
|
|
|
xSrc, ySrc, widthSrc, heightSrc, xDst, yDst, widthDst, heightDst);
|
|
|
|
|
2011-08-04 11:09:34 +00:00
|
|
|
stride = get_dib_width_bytes( info->bmiHeader.biWidth, info->bmiHeader.biBitCount );
|
1999-03-23 13:46:04 +00:00
|
|
|
|
2011-08-04 11:09:34 +00:00
|
|
|
TRACE("full size=%dx%d bpp=%d compression=%d rop=%08x\n", info->bmiHeader.biWidth,
|
|
|
|
info->bmiHeader.biHeight, info->bmiHeader.biBitCount, info->bmiHeader.biCompression, dwRop);
|
1998-10-24 10:44:05 +00:00
|
|
|
|
|
|
|
|
2011-08-04 11:09:34 +00:00
|
|
|
if(info->bmiHeader.biCompression != BI_RGB) {
|
1999-06-26 19:09:08 +00:00
|
|
|
FIXME("Compression not supported\n");
|
1999-03-23 13:46:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-05-02 01:39:48 +00:00
|
|
|
pt[0].x = xDst;
|
|
|
|
pt[0].y = yDst;
|
|
|
|
pt[1].x = xDst + widthDst;
|
|
|
|
pt[1].y = yDst + heightDst;
|
2011-07-07 11:29:17 +00:00
|
|
|
LPtoDP( dev->hdc, pt, 2 );
|
2002-05-02 01:39:48 +00:00
|
|
|
xDst = pt[0].x;
|
|
|
|
yDst = pt[0].y;
|
|
|
|
widthDst = pt[1].x - pt[0].x;
|
|
|
|
heightDst = pt[1].y - pt[0].y;
|
1999-03-23 13:46:04 +00:00
|
|
|
|
2011-08-04 11:09:34 +00:00
|
|
|
switch (info->bmiHeader.biBitCount) {
|
1999-03-23 13:46:04 +00:00
|
|
|
|
|
|
|
case 1:
|
2003-12-08 21:40:27 +00:00
|
|
|
src_ptr = bits;
|
2009-11-18 12:20:17 +00:00
|
|
|
src_ptr += (ySrc * stride);
|
1999-12-25 22:56:13 +00:00
|
|
|
if(xSrc & 7)
|
1999-06-26 19:09:08 +00:00
|
|
|
FIXME("This won't work...\n");
|
2003-12-08 21:40:27 +00:00
|
|
|
bitmap_size = heightSrc * ((widthSrc + 7) / 8);
|
|
|
|
dst_ptr = bitmap = HeapAlloc(GetProcessHeap(), 0, bitmap_size);
|
2009-11-18 12:20:17 +00:00
|
|
|
for(line = 0; line < heightSrc; line++, src_ptr += stride, dst_ptr += ((widthSrc + 7) / 8))
|
2003-12-08 21:40:27 +00:00
|
|
|
memcpy(dst_ptr, src_ptr + xSrc / 8, (widthSrc + 7) / 8);
|
1999-03-23 13:46:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2003-12-08 21:40:27 +00:00
|
|
|
src_ptr = bits;
|
2009-11-18 12:20:17 +00:00
|
|
|
src_ptr += (ySrc * stride);
|
1999-12-25 22:56:13 +00:00
|
|
|
if(xSrc & 1)
|
1999-06-26 19:09:08 +00:00
|
|
|
FIXME("This won't work...\n");
|
2003-12-08 21:40:27 +00:00
|
|
|
bitmap_size = heightSrc * ((widthSrc + 1) / 2);
|
|
|
|
dst_ptr = bitmap = HeapAlloc(GetProcessHeap(), 0, bitmap_size);
|
2009-11-18 12:20:17 +00:00
|
|
|
for(line = 0; line < heightSrc; line++, src_ptr += stride, dst_ptr += ((widthSrc + 1) / 2))
|
2003-12-08 21:40:27 +00:00
|
|
|
memcpy(dst_ptr, src_ptr + xSrc/2, (widthSrc+1)/2);
|
1999-03-23 13:46:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
2003-12-08 21:40:27 +00:00
|
|
|
src_ptr = bits;
|
2009-11-18 12:20:17 +00:00
|
|
|
src_ptr += (ySrc * stride);
|
2003-12-08 21:40:27 +00:00
|
|
|
bitmap_size = heightSrc * widthSrc;
|
|
|
|
dst_ptr = bitmap = HeapAlloc(GetProcessHeap(), 0, bitmap_size);
|
2009-11-18 12:20:17 +00:00
|
|
|
for(line = 0; line < heightSrc; line++, src_ptr += stride, dst_ptr += widthSrc)
|
2003-12-08 21:40:27 +00:00
|
|
|
memcpy(dst_ptr, src_ptr + xSrc, widthSrc);
|
1999-03-23 13:46:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
2003-12-08 21:40:27 +00:00
|
|
|
src_ptr = bits;
|
2009-11-18 12:20:17 +00:00
|
|
|
src_ptr += (ySrc * stride);
|
2004-11-30 21:02:46 +00:00
|
|
|
bitmap_size = heightSrc * widthSrc * 3;
|
2003-12-08 21:40:27 +00:00
|
|
|
dst_ptr = bitmap = HeapAlloc(GetProcessHeap(), 0, bitmap_size);
|
|
|
|
|
2009-11-18 12:20:17 +00:00
|
|
|
for(line = 0; line < heightSrc; line++, src_ptr += stride) {
|
2003-12-08 21:40:27 +00:00
|
|
|
const WORD *words = (const WORD *)src_ptr + xSrc;
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < widthSrc; i++) {
|
|
|
|
BYTE r, g, b;
|
|
|
|
|
|
|
|
/* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
|
|
|
|
r = words[i] >> 10 & 0x1f;
|
|
|
|
r = r << 3 | r >> 2;
|
|
|
|
g = words[i] >> 5 & 0x1f;
|
|
|
|
g = g << 3 | g >> 2;
|
|
|
|
b = words[i] & 0x1f;
|
|
|
|
b = b << 3 | b >> 2;
|
|
|
|
dst_ptr[0] = r;
|
|
|
|
dst_ptr[1] = g;
|
|
|
|
dst_ptr[2] = b;
|
|
|
|
dst_ptr += 3;
|
|
|
|
}
|
|
|
|
}
|
1999-03-23 13:46:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 24:
|
2003-12-08 21:40:27 +00:00
|
|
|
src_ptr = bits;
|
2009-11-18 12:20:17 +00:00
|
|
|
src_ptr += (ySrc * stride);
|
2003-12-08 21:40:27 +00:00
|
|
|
bitmap_size = heightSrc * widthSrc * 3;
|
|
|
|
dst_ptr = bitmap = HeapAlloc(GetProcessHeap(), 0, bitmap_size);
|
2009-11-18 12:20:17 +00:00
|
|
|
for(line = 0; line < heightSrc; line++, src_ptr += stride) {
|
2003-12-08 21:40:27 +00:00
|
|
|
const BYTE *byte = src_ptr + xSrc * 3;
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < widthSrc; i++) {
|
|
|
|
dst_ptr[0] = byte[i * 3 + 2];
|
|
|
|
dst_ptr[1] = byte[i * 3 + 1];
|
|
|
|
dst_ptr[2] = byte[i * 3];
|
|
|
|
dst_ptr += 3;
|
|
|
|
}
|
|
|
|
}
|
1999-03-23 13:46:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 32:
|
2003-12-08 21:40:27 +00:00
|
|
|
src_ptr = bits;
|
2009-11-18 12:20:17 +00:00
|
|
|
src_ptr += (ySrc * stride);
|
2003-12-08 21:40:27 +00:00
|
|
|
bitmap_size = heightSrc * widthSrc * 3;
|
|
|
|
dst_ptr = bitmap = HeapAlloc(GetProcessHeap(), 0, bitmap_size);
|
2009-11-18 12:20:17 +00:00
|
|
|
for(line = 0; line < heightSrc; line++, src_ptr += stride) {
|
2003-12-08 21:40:27 +00:00
|
|
|
const BYTE *byte = src_ptr + xSrc * 4;
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < widthSrc; i++) {
|
|
|
|
dst_ptr[0] = byte[i * 4 + 2];
|
|
|
|
dst_ptr[1] = byte[i * 4 + 1];
|
|
|
|
dst_ptr[2] = byte[i * 4];
|
|
|
|
dst_ptr += 3;
|
|
|
|
}
|
|
|
|
}
|
1999-03-23 13:46:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-06-26 19:09:08 +00:00
|
|
|
FIXME("Unsupported depth\n");
|
1999-03-23 13:46:04 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
}
|
2003-12-08 21:40:27 +00:00
|
|
|
|
2011-07-20 12:36:10 +00:00
|
|
|
PSDRV_SetClip(dev);
|
|
|
|
PSDRV_WriteGSave(dev);
|
|
|
|
PSDRV_WriteImageBits( dev, info, xDst, yDst, widthDst, heightDst,
|
|
|
|
widthSrc, heightSrc, bitmap, bitmap_size );
|
2003-12-08 21:40:27 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, bitmap);
|
2011-07-07 11:29:17 +00:00
|
|
|
PSDRV_WriteGRestore(dev);
|
|
|
|
PSDRV_ResetClip(dev);
|
2003-11-03 22:14:46 +00:00
|
|
|
return abs(heightSrc);
|
1998-10-24 10:44:05 +00:00
|
|
|
}
|