Tacked GPL into comments. More hq4x tweaks.
This commit is contained in:
parent
7487c3b31b
commit
8dee572c9d
8 changed files with 404 additions and 340 deletions
|
|
@ -3,6 +3,22 @@
|
||||||
/* printing support for Tux Paint */
|
/* printing support for Tux Paint */
|
||||||
/* Marcin 'Shard' Konicki <shard at beosjournal.org> */
|
/* Marcin 'Shard' Konicki <shard at beosjournal.org> */
|
||||||
|
|
||||||
|
/*
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
/* Jan. 17, 2003 */
|
/* Jan. 17, 2003 */
|
||||||
|
|
||||||
#include "BeOS_print.h"
|
#include "BeOS_print.h"
|
||||||
|
|
|
||||||
|
|
@ -172,12 +172,13 @@
|
||||||
|
|
||||||
|
|
||||||
void hq4x_32(SDL_Surface * src, SDL_Surface * dest,
|
void hq4x_32(SDL_Surface * src, SDL_Surface * dest,
|
||||||
int RGBtoYUV[65536])
|
Uint32 RGBtoYUV[65536])
|
||||||
{
|
{
|
||||||
int x, y, k;
|
int x, y, k;
|
||||||
int prevline, nextline;
|
int prevline, nextline;
|
||||||
Uint16 w[10];
|
Uint16 w[10];
|
||||||
Uint8 a;
|
Uint8 a;
|
||||||
|
Uint32 YUV1, YUV2;
|
||||||
int pattern;
|
int pattern;
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
void hq4x_32(SDL_Surface * src, SDL_Surface * dest,
|
void hq4x_32(SDL_Surface * src, SDL_Surface * dest,
|
||||||
int RGBtoYUV[65536]);
|
Uint32 RGBtoYUV[65536]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
12
src/hqxx.c
12
src/hqxx.c
|
|
@ -165,7 +165,7 @@ void hqxx_putpixel(SDL_Surface * surface, int x, int y, Uint16 pixel, Uint8 alph
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InitLUTs(int * RGBtoYUV)
|
void InitLUTs(Uint32 * RGBtoYUV)
|
||||||
{
|
{
|
||||||
int i, j, k, r, g, b, Y, u, v;
|
int i, j, k, r, g, b, Y, u, v;
|
||||||
|
|
||||||
|
|
@ -181,9 +181,7 @@ void InitLUTs(int * RGBtoYUV)
|
||||||
Y = (r + g + b) >> 2;
|
Y = (r + g + b) >> 2;
|
||||||
u = 128 + ((r - b) >> 2);
|
u = 128 + ((r - b) >> 2);
|
||||||
v = 128 + ((-r + 2 * g - b) >> 3);
|
v = 128 + ((-r + 2 * g - b) >> 3);
|
||||||
RGBtoYUV[(i << 11) + (j << 5) + k] = (((Y & 0xF8) << 8) |
|
RGBtoYUV[(i << 11) + (j << 5) + k] = (Y << 16) + (u << 8) + v;
|
||||||
((u & 0xFE) << 3) |
|
|
||||||
(v >> 3));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -210,15 +208,11 @@ inline void Interp2(SDL_Surface * dest, int x, int y, Uint16 c1, Uint16 c2, Uint
|
||||||
{
|
{
|
||||||
Uint32 c;
|
Uint32 c;
|
||||||
|
|
||||||
/* FIXME? */
|
|
||||||
|
|
||||||
// c = (c1 * 2 + c2 + c3) >> 2;
|
// c = (c1 * 2 + c2 + c3) >> 2;
|
||||||
|
|
||||||
c = ((((c1 & 0x07E0) * 2 + (c2 & 0x07E0) + (c3 & 0x07E0)) & (0x07E0 << 2)) +
|
c = ((((c1 & 0x07E0) * 2 + (c2 & 0x07E0) + (c3 & 0x07E0)) & (0x07E0 << 2)) +
|
||||||
(((c1 & 0xF81F) * 2 + (c2 & 0xF81F) + (c3 & 0xF81F)) & (0xF81F << 2)))
|
(((c1 & 0xF81F) * 2 + (c2 & 0xF81F) + (c3 & 0xF81F)) & (0xF81F << 2)))
|
||||||
>> 2;
|
>> 2;
|
||||||
|
|
||||||
|
|
||||||
hqxx_putpixel(dest, x, y, c, alpha);
|
hqxx_putpixel(dest, x, y, c, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,7 +246,7 @@ inline void Interp4(SDL_Surface * dest, int x, int y, Uint16 c1, Uint16 c2, Uint
|
||||||
|
|
||||||
c = ((((c1 & 0x07E0) * 2 +
|
c = ((((c1 & 0x07E0) * 2 +
|
||||||
((c2 & 0x07E0) +
|
((c2 & 0x07E0) +
|
||||||
(c3 & 0x07E0)) * 7) & 0x7E00) +
|
(c3 & 0x07E0)) * 7) & 0x07E00) +
|
||||||
(((c1 & 0xF81F) * 2 +
|
(((c1 & 0xF81F) * 2 +
|
||||||
((c2 & 0xF81F) +
|
((c2 & 0xF81F) +
|
||||||
(c3 & 0xF81F)) * 7) & 0xF81F0)) >> 4;
|
(c3 & 0xF81F)) * 7) & 0xF81F0)) >> 4;
|
||||||
|
|
|
||||||
24
src/hqxx.h
24
src/hqxx.h
|
|
@ -27,23 +27,25 @@
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
static int YUV1, YUV2;
|
#define Ymask 0x00FF0000
|
||||||
|
#define Umask 0x0000FF00
|
||||||
|
#define Vmask 0x000000FF
|
||||||
|
|
||||||
#define Ymask 0xF800
|
//#define Ymask 0xF800
|
||||||
#define Umask 0x07E0
|
//#define Umask 0x07E0
|
||||||
#define Vmask 0x001F
|
//#define Vmask 0x001F
|
||||||
|
|
||||||
//trY in 32 = 0x00300000
|
#define trY 0x00300000
|
||||||
//trU in 32 = 0x00000700
|
#define trU 0x00000700
|
||||||
//trV in 32 = 0x00000006
|
#define trV 0x00000006
|
||||||
|
|
||||||
#define trY 0x3000
|
//#define trY 0x3000
|
||||||
#define trU 0x00C0
|
//#define trU 0x00C0
|
||||||
#define trV 0x0006
|
//#define trV 0x0006
|
||||||
|
|
||||||
|
|
||||||
Uint16 hqxx_getpixel(SDL_Surface * surface, int x, int y, Uint8 * alpha);
|
Uint16 hqxx_getpixel(SDL_Surface * surface, int x, int y, Uint8 * alpha);
|
||||||
void InitLUTs(int * RGBtoYUV);
|
void InitLUTs(Uint32 * RGBtoYUV);
|
||||||
inline void Interp0(SDL_Surface * dest, int x, int y, Uint16 c, Uint8 alpha);
|
inline void Interp0(SDL_Surface * dest, int x, int y, Uint16 c, Uint8 alpha);
|
||||||
inline void Interp1(SDL_Surface * dest, int x, int y, Uint16 c1, Uint16 c2, Uint8 alpha);
|
inline void Interp1(SDL_Surface * dest, int x, int y, Uint16 c1, Uint16 c2, Uint8 alpha);
|
||||||
inline void Interp2(SDL_Surface * dest, int x, int y, Uint16 c1, Uint16 c2, Uint16 c3, Uint8 alpha);
|
inline void Interp2(SDL_Surface * dest, int x, int y, Uint16 c1, Uint16 c2, Uint16 c3, Uint8 alpha);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,20 @@
|
||||||
Copyright (c) 2003 by Bill Kendrick
|
Copyright (c) 2003 by Bill Kendrick
|
||||||
bill@newbreedsoftware.com
|
bill@newbreedsoftware.com
|
||||||
http://www.newbreedsoftware.com/tuxpaint/
|
http://www.newbreedsoftware.com/tuxpaint/
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
June 14, 2002 - December 20, 2003
|
June 14, 2002 - December 20, 2003
|
||||||
*/
|
*/
|
||||||
|
|
@ -24,6 +38,9 @@
|
||||||
/* #define USE_HWSURFACE */
|
/* #define USE_HWSURFACE */
|
||||||
|
|
||||||
|
|
||||||
|
/* #define USE_HQ4X */
|
||||||
|
|
||||||
|
|
||||||
/* Disable fancy cursors in fullscreen mode, to avoid SDL bug: */
|
/* Disable fancy cursors in fullscreen mode, to avoid SDL bug: */
|
||||||
#define LARGE_CURSOR_FULLSCREEN_BUG
|
#define LARGE_CURSOR_FULLSCREEN_BUG
|
||||||
|
|
||||||
|
|
@ -2990,6 +3007,7 @@ void stamp_draw(int x, int y)
|
||||||
|
|
||||||
/* Shrink or grow it! */
|
/* Shrink or grow it! */
|
||||||
|
|
||||||
|
#ifdef HQ4X
|
||||||
if (state_stamps[cur_stamp]->size == 400)
|
if (state_stamps[cur_stamp]->size == 400)
|
||||||
{
|
{
|
||||||
/* Use high quality 4x filter! */
|
/* Use high quality 4x filter! */
|
||||||
|
|
@ -3024,6 +3042,7 @@ void stamp_draw(int x, int y)
|
||||||
hq4x_32(tmp_surf, final_surf, RGBtoYUV);
|
hq4x_32(tmp_surf, final_surf, RGBtoYUV);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
final_surf = thumbnail(tmp_surf,
|
final_surf = thumbnail(tmp_surf,
|
||||||
(tmp_surf->w *
|
(tmp_surf->w *
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,22 @@
|
||||||
/* */
|
/* */
|
||||||
/****************************************************/
|
/****************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,26 @@
|
||||||
/* win32_print.c */
|
/* win32_print.c */
|
||||||
/* printing support for Tux Paint */
|
/* printing support for Tux Paint */
|
||||||
|
|
||||||
/* John Popplewell <john@johnnypops.demon.co.uk> */
|
/* John Popplewell <john@johnnypops.demon.co.uk> */
|
||||||
|
|
||||||
/* Sept. 30, 2002 - Oct. 17, 2002 */
|
/*
|
||||||
/* Oct. 07, 2003 - added banding support */
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Sept. 30, 2002 - Oct. 17, 2002 */
|
||||||
|
/* Oct. 07, 2003 - added banding support */
|
||||||
/* - prints using 24-bit (not 32-bit) bitmap */
|
/* - prints using 24-bit (not 32-bit) bitmap */
|
||||||
|
|
||||||
#include "SDL_syswm.h"
|
#include "SDL_syswm.h"
|
||||||
|
|
@ -17,243 +33,243 @@
|
||||||
#define MIR( id ) (MAKEINTRESOURCE( id ))
|
#define MIR( id ) (MAKEINTRESOURCE( id ))
|
||||||
|
|
||||||
|
|
||||||
static PRINTDLG global_pd = {
|
static PRINTDLG global_pd = {
|
||||||
sizeof(PRINTDLG),
|
sizeof(PRINTDLG),
|
||||||
NULL, NULL, NULL, NULL,
|
NULL, NULL, NULL, NULL,
|
||||||
PD_RETURNDC,
|
PD_RETURNDC,
|
||||||
0xFFFF,
|
0xFFFF,
|
||||||
0xFFFF,
|
0xFFFF,
|
||||||
0xFFFF,
|
0xFFFF,
|
||||||
0xFFFF,
|
0xFFFF,
|
||||||
1,
|
1,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static SDL_Surface *make24bitDIB( SDL_Surface *surf )
|
static SDL_Surface *make24bitDIB( SDL_Surface *surf )
|
||||||
{
|
{
|
||||||
SDL_PixelFormat pixfmt;
|
SDL_PixelFormat pixfmt;
|
||||||
SDL_Surface *surf24;
|
SDL_Surface *surf24;
|
||||||
SDL_Surface *surfDIB;
|
SDL_Surface *surfDIB;
|
||||||
Uint8 *src,*dst;
|
Uint8 *src,*dst;
|
||||||
Uint32 linesize;
|
Uint32 linesize;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset( &pixfmt, 0, sizeof(pixfmt) );
|
memset( &pixfmt, 0, sizeof(pixfmt) );
|
||||||
pixfmt.palette = NULL;
|
pixfmt.palette = NULL;
|
||||||
pixfmt.BitsPerPixel = 24;
|
pixfmt.BitsPerPixel = 24;
|
||||||
pixfmt.BytesPerPixel= 3;
|
pixfmt.BytesPerPixel= 3;
|
||||||
pixfmt.Rmask = 0x00FF0000;
|
pixfmt.Rmask = 0x00FF0000;
|
||||||
pixfmt.Gmask = 0x0000FF00;
|
pixfmt.Gmask = 0x0000FF00;
|
||||||
pixfmt.Bmask = 0x000000FF;
|
pixfmt.Bmask = 0x000000FF;
|
||||||
pixfmt.Amask = 0;
|
pixfmt.Amask = 0;
|
||||||
pixfmt.Rshift = 16;
|
pixfmt.Rshift = 16;
|
||||||
pixfmt.Gshift = 8;
|
pixfmt.Gshift = 8;
|
||||||
pixfmt.Bshift = 0;
|
pixfmt.Bshift = 0;
|
||||||
pixfmt.Ashift = 0;
|
pixfmt.Ashift = 0;
|
||||||
pixfmt.Rloss = 0;
|
pixfmt.Rloss = 0;
|
||||||
pixfmt.Gloss = 0;
|
pixfmt.Gloss = 0;
|
||||||
pixfmt.Bloss = 0;
|
pixfmt.Bloss = 0;
|
||||||
pixfmt.Aloss = 0;
|
pixfmt.Aloss = 0;
|
||||||
pixfmt.colorkey = 0;
|
pixfmt.colorkey = 0;
|
||||||
pixfmt.alpha = 0;
|
pixfmt.alpha = 0;
|
||||||
|
|
||||||
surf24 = SDL_ConvertSurface( surf, &pixfmt, SDL_SWSURFACE );
|
surf24 = SDL_ConvertSurface( surf, &pixfmt, SDL_SWSURFACE );
|
||||||
surfDIB = SDL_CreateRGBSurface( SDL_SWSURFACE, surf24->w, surf24->h, 24,
|
surfDIB = SDL_CreateRGBSurface( SDL_SWSURFACE, surf24->w, surf24->h, 24,
|
||||||
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask, pixfmt.Amask );
|
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask, pixfmt.Amask );
|
||||||
|
|
||||||
linesize = surf24->w * 3; // Flip top2bottom
|
linesize = surf24->w * 3; // Flip top2bottom
|
||||||
dst = surfDIB->pixels;
|
dst = surfDIB->pixels;
|
||||||
src = ((Uint8*)surf24->pixels)+((surf24->h-1)*surf24->pitch);
|
src = ((Uint8*)surf24->pixels)+((surf24->h-1)*surf24->pitch);
|
||||||
for ( i = 0; i < surf24->h; ++i )
|
for ( i = 0; i < surf24->h; ++i )
|
||||||
{
|
{
|
||||||
memcpy( dst, src, linesize );
|
memcpy( dst, src, linesize );
|
||||||
src -= surf24->pitch;
|
src -= surf24->pitch;
|
||||||
dst += surfDIB->pitch;
|
dst += surfDIB->pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_FreeSurface( surf24 ); // Free temp surface
|
SDL_FreeSurface( surf24 ); // Free temp surface
|
||||||
|
|
||||||
return surfDIB;
|
return surfDIB;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns 0 if failed */
|
/* returns 0 if failed */
|
||||||
static int GetDefaultPrinterStrings( char *device, char *driver, char *output )
|
static int GetDefaultPrinterStrings( char *device, char *driver, char *output )
|
||||||
{
|
{
|
||||||
char buff[MAX_PATH];
|
char buff[MAX_PATH];
|
||||||
char *section = "windows";
|
char *section = "windows";
|
||||||
char *key = "device";
|
char *key = "device";
|
||||||
char *def = "NODEFAULTPRINTER";
|
char *def = "NODEFAULTPRINTER";
|
||||||
char *dev,*drv,*out;
|
char *dev,*drv,*out;
|
||||||
|
|
||||||
if ( !GetProfileString( section, key, def, buff, sizeof(buff) ) )
|
if ( !GetProfileString( section, key, def, buff, sizeof(buff) ) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ( strcmp( buff, def ) == 0 )
|
if ( strcmp( buff, def ) == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ( ((dev = strtok( buff, "," )) != NULL) &&
|
if ( ((dev = strtok( buff, "," )) != NULL) &&
|
||||||
((drv = strtok( NULL, ", ")) != NULL) &&
|
((drv = strtok( NULL, ", ")) != NULL) &&
|
||||||
((out = strtok( NULL, ", ")) != NULL) )
|
((out = strtok( NULL, ", ")) != NULL) )
|
||||||
{
|
{
|
||||||
if ( device ) strcpy( device, dev );
|
if ( device ) strcpy( device, dev );
|
||||||
if ( driver ) strcpy( driver, drv );
|
if ( driver ) strcpy( driver, drv );
|
||||||
if ( output ) strcpy( output, out );
|
if ( output ) strcpy( output, out );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define dmDeviceNameSize 32
|
#define dmDeviceNameSize 32
|
||||||
|
|
||||||
static HANDLE LoadCustomPrinterHDEVMODE( HWND hWnd, const char *filepath )
|
static HANDLE LoadCustomPrinterHDEVMODE( HWND hWnd, const char *filepath )
|
||||||
{
|
{
|
||||||
char device[MAX_PATH];
|
char device[MAX_PATH];
|
||||||
HANDLE hPrinter = NULL;
|
HANDLE hPrinter = NULL;
|
||||||
int sizeof_devmode;
|
int sizeof_devmode;
|
||||||
HGLOBAL hDevMode = NULL;
|
HGLOBAL hDevMode = NULL;
|
||||||
DEVMODE *devmode = NULL;
|
DEVMODE *devmode = NULL;
|
||||||
int res;
|
int res;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
int block_size;
|
int block_size;
|
||||||
int block_read;
|
int block_read;
|
||||||
|
|
||||||
if ( (fp = fopen( filepath, "rb" )) == NULL )
|
if ( (fp = fopen( filepath, "rb" )) == NULL )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ( fread( device, 1, dmDeviceNameSize, fp ) != dmDeviceNameSize )
|
if ( fread( device, 1, dmDeviceNameSize, fp ) != dmDeviceNameSize )
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
|
|
||||||
if (!OpenPrinter( device, &hPrinter, NULL ))
|
if (!OpenPrinter( device, &hPrinter, NULL ))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
sizeof_devmode = (int)DocumentProperties( hWnd, hPrinter, device,
|
sizeof_devmode = (int)DocumentProperties( hWnd, hPrinter, device,
|
||||||
NULL, NULL, 0 );
|
NULL, NULL, 0 );
|
||||||
|
|
||||||
if ( !sizeof_devmode )
|
if ( !sizeof_devmode )
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
|
|
||||||
hDevMode = GlobalAlloc( GHND, sizeof_devmode );
|
hDevMode = GlobalAlloc( GHND, sizeof_devmode );
|
||||||
if ( !hDevMode )
|
if ( !hDevMode )
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
|
|
||||||
devmode = (DEVMODE*)GlobalLock( hDevMode );
|
devmode = (DEVMODE*)GlobalLock( hDevMode );
|
||||||
if ( !devmode )
|
if ( !devmode )
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
|
|
||||||
res = DocumentProperties( hWnd, hPrinter, device, devmode, NULL,
|
res = DocumentProperties( hWnd, hPrinter, device, devmode, NULL,
|
||||||
DM_OUT_BUFFER);
|
DM_OUT_BUFFER);
|
||||||
if ( res != IDOK )
|
if ( res != IDOK )
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
|
|
||||||
block_size = devmode->dmSize + devmode->dmDriverExtra;
|
block_size = devmode->dmSize + devmode->dmDriverExtra;
|
||||||
block_read = fread( devmode, 1, block_size, fp );
|
block_read = fread( devmode, 1, block_size, fp );
|
||||||
if ( block_size != block_read )
|
if ( block_size != block_read )
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
res = DocumentProperties( hWnd, hPrinter, device, devmode, devmode,
|
res = DocumentProperties( hWnd, hPrinter, device, devmode, devmode,
|
||||||
DM_IN_BUFFER|DM_OUT_BUFFER);
|
DM_IN_BUFFER|DM_OUT_BUFFER);
|
||||||
if ( res != IDOK )
|
if ( res != IDOK )
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
|
|
||||||
GlobalUnlock( hDevMode );
|
GlobalUnlock( hDevMode );
|
||||||
ClosePrinter( hPrinter );
|
ClosePrinter( hPrinter );
|
||||||
return hDevMode;
|
return hDevMode;
|
||||||
|
|
||||||
err_exit:
|
err_exit:
|
||||||
if ( fp ) fclose( fp );
|
if ( fp ) fclose( fp );
|
||||||
if ( devmode ) GlobalUnlock( hDevMode );
|
if ( devmode ) GlobalUnlock( hDevMode );
|
||||||
if ( hDevMode ) GlobalFree( hDevMode );
|
if ( hDevMode ) GlobalFree( hDevMode );
|
||||||
if ( hPrinter ) ClosePrinter( hPrinter );
|
if ( hPrinter ) ClosePrinter( hPrinter );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int SaveCustomPrinterHDEVMODE( HWND hWnd, const char *filepath, HANDLE hDevMode )
|
static int SaveCustomPrinterHDEVMODE( HWND hWnd, const char *filepath, HANDLE hDevMode )
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
|
||||||
NOREF(hWnd);
|
NOREF(hWnd);
|
||||||
if ( (fp = fopen( filepath, "wb" )) != NULL )
|
if ( (fp = fopen( filepath, "wb" )) != NULL )
|
||||||
{
|
{
|
||||||
DEVMODE *devmode = (DEVMODE*)GlobalLock( hDevMode );
|
DEVMODE *devmode = (DEVMODE*)GlobalLock( hDevMode );
|
||||||
int block_size = devmode->dmSize + devmode->dmDriverExtra;
|
int block_size = devmode->dmSize + devmode->dmDriverExtra;
|
||||||
int block_written;
|
int block_written;
|
||||||
char devname[dmDeviceNameSize];
|
char devname[dmDeviceNameSize];
|
||||||
|
|
||||||
strcpy( devname, (const char*)devmode->dmDeviceName );
|
strcpy( devname, (const char*)devmode->dmDeviceName );
|
||||||
fwrite( devname, 1, sizeof(devname), fp );
|
fwrite( devname, 1, sizeof(devname), fp );
|
||||||
block_written = fwrite( devmode, 1, block_size, fp );
|
block_written = fwrite( devmode, 1, block_size, fp );
|
||||||
GlobalUnlock( hDevMode );
|
GlobalUnlock( hDevMode );
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
return block_size == block_written;
|
return block_size == block_written;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static HDC GetCustomPrinterDC( HWND hWnd, const char *printcfg, int show )
|
static HDC GetCustomPrinterDC( HWND hWnd, const char *printcfg, int show )
|
||||||
{
|
{
|
||||||
global_pd.hwndOwner = hWnd;
|
global_pd.hwndOwner = hWnd;
|
||||||
global_pd.hDC = NULL;
|
global_pd.hDC = NULL;
|
||||||
global_pd.hDevNames = NULL;
|
global_pd.hDevNames = NULL;
|
||||||
|
|
||||||
if ( global_pd.hDevMode == NULL )
|
if ( global_pd.hDevMode == NULL )
|
||||||
{
|
{
|
||||||
global_pd.hDevMode = LoadCustomPrinterHDEVMODE( hWnd, printcfg );
|
global_pd.hDevMode = LoadCustomPrinterHDEVMODE( hWnd, printcfg );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( show )
|
if ( show )
|
||||||
{
|
{
|
||||||
if ( PrintDlg( &global_pd ) )
|
if ( PrintDlg( &global_pd ) )
|
||||||
{
|
{
|
||||||
SaveCustomPrinterHDEVMODE( hWnd, printcfg, global_pd.hDevMode );
|
SaveCustomPrinterHDEVMODE( hWnd, printcfg, global_pd.hDevMode );
|
||||||
return global_pd.hDC;
|
return global_pd.hDC;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DEVMODE *devmode = (DEVMODE*)GlobalLock( global_pd.hDevMode );
|
DEVMODE *devmode = (DEVMODE*)GlobalLock( global_pd.hDevMode );
|
||||||
|
|
||||||
global_pd.hDC = CreateDC( NULL, (const char*)devmode->dmDeviceName, NULL, devmode );
|
global_pd.hDC = CreateDC( NULL, (const char*)devmode->dmDeviceName, NULL, devmode );
|
||||||
GlobalUnlock( global_pd.hDevMode );
|
GlobalUnlock( global_pd.hDevMode );
|
||||||
}
|
}
|
||||||
return global_pd.hDC;
|
return global_pd.hDC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static HDC GetDefaultPrinterDC( void )
|
static HDC GetDefaultPrinterDC( void )
|
||||||
{
|
{
|
||||||
char device[MAX_PATH],driver[MAX_PATH],output[MAX_PATH];
|
char device[MAX_PATH],driver[MAX_PATH],output[MAX_PATH];
|
||||||
|
|
||||||
if ( GetDefaultPrinterStrings( device, driver, output ) )
|
if ( GetDefaultPrinterStrings( device, driver, output ) )
|
||||||
return CreateDC( driver, device, output, NULL );
|
return CreateDC( driver, device, output, NULL );
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static HDC GetPrinterDC( HWND hWnd, const char *printcfg, int show )
|
static HDC GetPrinterDC( HWND hWnd, const char *printcfg, int show )
|
||||||
{
|
{
|
||||||
if ( !printcfg ) return GetDefaultPrinterDC();
|
if ( !printcfg ) return GetDefaultPrinterDC();
|
||||||
return GetCustomPrinterDC( hWnd, printcfg, show );
|
return GetCustomPrinterDC( hWnd, printcfg, show );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int IsBandingRequired( HDC hPrinter )
|
static int IsBandingRequired( HDC hPrinter )
|
||||||
{
|
{
|
||||||
OSVERSIONINFO osvi;
|
OSVERSIONINFO osvi;
|
||||||
int indata = NEXTBAND;
|
int indata = NEXTBAND;
|
||||||
|
|
||||||
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||||
if ( GetVersionEx( &osvi ) && (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) )
|
if ( GetVersionEx( &osvi ) && (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) )
|
||||||
return Escape( hPrinter, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&indata, NULL );
|
return Escape( hPrinter, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&indata, NULL );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int IsPrinterAvailable( void )
|
int IsPrinterAvailable( void )
|
||||||
{
|
{
|
||||||
return (GetDefaultPrinterStrings( NULL, NULL, NULL ) != 0);
|
return (GetDefaultPrinterStrings( NULL, NULL, NULL ) != 0);
|
||||||
|
|
@ -267,8 +283,8 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
|
||||||
DOCINFO di;
|
DOCINFO di;
|
||||||
int nError;
|
int nError;
|
||||||
SDL_SysWMinfo wminfo;
|
SDL_SysWMinfo wminfo;
|
||||||
HDC hDCwindow;
|
HDC hDCwindow;
|
||||||
HDC hDCprinter;
|
HDC hDCprinter;
|
||||||
BITMAPINFOHEADER bmih;
|
BITMAPINFOHEADER bmih;
|
||||||
SDL_Surface *surf24 = NULL;
|
SDL_Surface *surf24 = NULL;
|
||||||
RECT rc;
|
RECT rc;
|
||||||
|
|
@ -278,17 +294,17 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
|
||||||
float subscaler,subscalerx,subscalery;
|
float subscaler,subscalerx,subscalery;
|
||||||
int hDCCaps;
|
int hDCCaps;
|
||||||
HBITMAP hbm = NULL;
|
HBITMAP hbm = NULL;
|
||||||
HDC hdcMem = NULL;
|
HDC hdcMem = NULL;
|
||||||
|
|
||||||
SDL_VERSION(&wminfo.version);
|
SDL_VERSION(&wminfo.version);
|
||||||
if ( !SDL_GetWMInfo( &wminfo ) )
|
if ( !SDL_GetWMInfo( &wminfo ) )
|
||||||
return "win32_print: SDL_GetWMInfo() failed.";
|
return "win32_print: SDL_GetWMInfo() failed.";
|
||||||
|
|
||||||
hWnd = wminfo.window;
|
hWnd = wminfo.window;
|
||||||
hDCprinter = GetPrinterDC( hWnd, printcfg, showdialog );
|
hDCprinter = GetPrinterDC( hWnd, printcfg, showdialog );
|
||||||
if ( !hDCprinter )
|
if ( !hDCprinter )
|
||||||
return "win32_print: GetPrinterDC() failed.";
|
return "win32_print: GetPrinterDC() failed.";
|
||||||
|
|
||||||
EnableWindow( hWnd, FALSE );
|
EnableWindow( hWnd, FALSE );
|
||||||
|
|
||||||
di.cbSize = sizeof(DOCINFO);
|
di.cbSize = sizeof(DOCINFO);
|
||||||
|
|
@ -313,21 +329,21 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
surf24 = make24bitDIB( surf );
|
surf24 = make24bitDIB( surf );
|
||||||
if ( !surf24 )
|
if ( !surf24 )
|
||||||
{
|
{
|
||||||
res = "win32_print: make24bitDIB() failed.";
|
res = "win32_print: make24bitDIB() failed.";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset( &bmih,0, sizeof(bmih) );
|
memset( &bmih,0, sizeof(bmih) );
|
||||||
bmih.biSize = sizeof(bmih);
|
bmih.biSize = sizeof(bmih);
|
||||||
bmih.biPlanes = 1;
|
bmih.biPlanes = 1;
|
||||||
bmih.biCompression = BI_RGB;
|
bmih.biCompression = BI_RGB;
|
||||||
bmih.biBitCount = 24;
|
bmih.biBitCount = 24;
|
||||||
bmih.biWidth = surf24->w;
|
bmih.biWidth = surf24->w;
|
||||||
bmih.biHeight = surf24->h;
|
bmih.biHeight = surf24->h;
|
||||||
|
|
||||||
GetClientRect( hWnd, &rc );
|
GetClientRect( hWnd, &rc );
|
||||||
subscalerx = (float)rc.right/surf24->w;
|
subscalerx = (float)rc.right/surf24->w;
|
||||||
subscalery = (float)rc.bottom/surf24->h;
|
subscalery = (float)rc.bottom/surf24->h;
|
||||||
|
|
@ -335,15 +351,15 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
|
||||||
if ( subscalerx < subscalery )
|
if ( subscalerx < subscalery )
|
||||||
subscaler = subscalerx;
|
subscaler = subscalerx;
|
||||||
|
|
||||||
hDCwindow = GetDC( hWnd );
|
hDCwindow = GetDC( hWnd );
|
||||||
if ( !hDCwindow )
|
if ( !hDCwindow )
|
||||||
{
|
{
|
||||||
res = "win32_print: failed to get window DC.";
|
res = "win32_print: failed to get window DC.";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
fLogPelsX1 = (float)GetDeviceCaps(hDCwindow, LOGPIXELSX);
|
fLogPelsX1 = (float)GetDeviceCaps(hDCwindow, LOGPIXELSX);
|
||||||
fLogPelsY1 = (float)GetDeviceCaps(hDCwindow, LOGPIXELSY);
|
fLogPelsY1 = (float)GetDeviceCaps(hDCwindow, LOGPIXELSY);
|
||||||
ReleaseDC( hWnd, hDCwindow );
|
ReleaseDC( hWnd, hDCwindow );
|
||||||
|
|
||||||
fLogPelsX2 = (float)GetDeviceCaps(hDCprinter, LOGPIXELSX);
|
fLogPelsX2 = (float)GetDeviceCaps(hDCprinter, LOGPIXELSX);
|
||||||
fLogPelsY2 = (float)GetDeviceCaps(hDCprinter, LOGPIXELSY);
|
fLogPelsY2 = (float)GetDeviceCaps(hDCprinter, LOGPIXELSY);
|
||||||
|
|
@ -368,69 +384,69 @@ const char *SurfacePrint( SDL_Surface *surf, const char *printcfg, int showdialo
|
||||||
|
|
||||||
hDCCaps = GetDeviceCaps(hDCprinter, RASTERCAPS);
|
hDCCaps = GetDeviceCaps(hDCprinter, RASTERCAPS);
|
||||||
|
|
||||||
if (hDCCaps & RC_PALETTE)
|
if (hDCCaps & RC_PALETTE)
|
||||||
{
|
{
|
||||||
res = "win32_print: printer context requires palette.";
|
res = "win32_print: printer context requires palette.";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( IsBandingRequired( hDCprinter ) )
|
if ( IsBandingRequired( hDCprinter ) )
|
||||||
{
|
{
|
||||||
RECT rcBand = { 0 };
|
RECT rcBand = { 0 };
|
||||||
RECT rcPrinter;
|
RECT rcPrinter;
|
||||||
RECT rcImage;
|
RECT rcImage;
|
||||||
|
|
||||||
SetRect( &rcPrinter, xLeft, yTop, (int)(fScaleX*bmih.biWidth), (int)(fScaleY*bmih.biHeight) );
|
SetRect( &rcPrinter, xLeft, yTop, (int)(fScaleX*bmih.biWidth), (int)(fScaleY*bmih.biHeight) );
|
||||||
SetRect( &rcImage, 0, 0, bmih.biWidth, bmih.biHeight );
|
SetRect( &rcImage, 0, 0, bmih.biWidth, bmih.biHeight );
|
||||||
|
|
||||||
while ( Escape(hDCprinter, NEXTBAND, 0, NULL, &rcBand) )
|
while ( Escape(hDCprinter, NEXTBAND, 0, NULL, &rcBand) )
|
||||||
{
|
{
|
||||||
if ( IsRectEmpty( &rcBand) ) break;
|
if ( IsRectEmpty( &rcBand) ) break;
|
||||||
if ( IntersectRect( &rcBand, &rcBand, &rcPrinter ) )
|
if ( IntersectRect( &rcBand, &rcBand, &rcPrinter ) )
|
||||||
{
|
{
|
||||||
rcImage.top = (int)(0.5f+(float)rcBand.top/fScaleX);
|
rcImage.top = (int)(0.5f+(float)rcBand.top/fScaleX);
|
||||||
rcImage.bottom = (int)(0.5f+(float)rcBand.bottom/fScaleX);
|
rcImage.bottom = (int)(0.5f+(float)rcBand.bottom/fScaleX);
|
||||||
|
|
||||||
SetStretchBltMode( hDCprinter, COLORONCOLOR );
|
SetStretchBltMode( hDCprinter, COLORONCOLOR );
|
||||||
nError = StretchDIBits(hDCprinter, rcBand.left, rcBand.top,
|
nError = StretchDIBits(hDCprinter, rcBand.left, rcBand.top,
|
||||||
rcBand.right - rcBand.left,
|
rcBand.right - rcBand.left,
|
||||||
rcBand.bottom - rcBand.top,
|
rcBand.bottom - rcBand.top,
|
||||||
rcImage.left, rcImage.top,
|
rcImage.left, rcImage.top,
|
||||||
rcImage.right - rcImage.left,
|
rcImage.right - rcImage.left,
|
||||||
rcImage.bottom - rcImage.top,
|
rcImage.bottom - rcImage.top,
|
||||||
surf24->pixels, (BITMAPINFO*)&bmih,
|
surf24->pixels, (BITMAPINFO*)&bmih,
|
||||||
DIB_RGB_COLORS, SRCCOPY);
|
DIB_RGB_COLORS, SRCCOPY);
|
||||||
if ( nError == GDI_ERROR )
|
if ( nError == GDI_ERROR )
|
||||||
{
|
{
|
||||||
res = "win32_print: StretchDIBits() failed.";
|
res = "win32_print: StretchDIBits() failed.";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( hDCCaps & RC_STRETCHDIB )
|
if ( hDCCaps & RC_STRETCHDIB )
|
||||||
{
|
{
|
||||||
SetStretchBltMode(hDCprinter, COLORONCOLOR);
|
SetStretchBltMode(hDCprinter, COLORONCOLOR);
|
||||||
|
|
||||||
nError = StretchDIBits(hDCprinter, xLeft, yTop,
|
nError = StretchDIBits(hDCprinter, xLeft, yTop,
|
||||||
(int)(fScaleX*bmih.biWidth),
|
(int)(fScaleX*bmih.biWidth),
|
||||||
(int)(fScaleY*bmih.biHeight),
|
(int)(fScaleY*bmih.biHeight),
|
||||||
0, 0, bmih.biWidth, bmih.biHeight,
|
0, 0, bmih.biWidth, bmih.biHeight,
|
||||||
surf24->pixels, (BITMAPINFO*)&bmih,
|
surf24->pixels, (BITMAPINFO*)&bmih,
|
||||||
DIB_RGB_COLORS, SRCCOPY);
|
DIB_RGB_COLORS, SRCCOPY);
|
||||||
if ( nError == GDI_ERROR )
|
if ( nError == GDI_ERROR )
|
||||||
{
|
{
|
||||||
res = "win32_print: StretchDIBits() failed.";
|
res = "win32_print: StretchDIBits() failed.";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = "win32_print: StretchDIBits() not available.";
|
res = "win32_print: StretchDIBits() not available.";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -450,7 +466,7 @@ error:
|
||||||
if ( surf24 ) SDL_FreeSurface( surf24 );
|
if ( surf24 ) SDL_FreeSurface( surf24 );
|
||||||
|
|
||||||
EnableWindow( hWnd, TRUE );
|
EnableWindow( hWnd, TRUE );
|
||||||
DeleteDC( hDCprinter );
|
DeleteDC( hDCprinter );
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue