Began incorporating hqXx filter. Removed old, unused Win32 code.

This commit is contained in:
William Kendrick 2003-12-20 18:03:29 +00:00
parent dba2ecf3b3
commit a6427c94ee
12 changed files with 9247 additions and 335 deletions

View file

@ -6,7 +6,7 @@
# bill@newbreedsoftware.com
# http://www.newbreedsoftware.com/tuxpaint/
# June 14, 2002 - December 19, 2003
# June 14, 2002 - December 20, 2003
# Where to install things:
@ -541,11 +541,12 @@ install-man:
# Build the program!
tuxpaint: obj/tuxpaint.o $(ARCH_LIBS)
tuxpaint: obj/tuxpaint.o obj/hqxx.o obj/hq3x.o obj/hq4x.o $(ARCH_LIBS)
@echo
@echo "...Linking Tux Paint..."
@$(CC) $(CFLAGS) $(SDL_CFLAGS) $(DEFS) \
-o tuxpaint obj/tuxpaint.o $(ARCH_LIBS) $(SDL_LIBS) \
-o tuxpaint obj/tuxpaint.o obj/hqxx.o obj/hq3x.o obj/hq4x.o \
$(ARCH_LIBS) $(SDL_LIBS) \
-lm $(ARCH_LINKS)
@$(RSRC_CMD)
@$(MIMESET_CMD)
@ -553,9 +554,10 @@ tuxpaint: obj/tuxpaint.o $(ARCH_LIBS)
# Build the object for the program!
obj/tuxpaint.o: src/tuxpaint.c obj \
obj/tuxpaint.o: src/tuxpaint.c \
src/tools.h src/titles.h src/colors.h src/shapes.h \
src/magic.h src/sounds.h src/tip_tux.h src/great.h \
src/hqxx.h src/hq3x.h src/hq4x.h \
src/mouse/arrow.xbm src/mouse/arrow-mask.xbm \
src/mouse/hand.xbm src/mouse/hand-mask.xbm \
src/mouse/insertion.xbm src/mouse/insertion-mask.xbm \
@ -581,6 +583,26 @@ obj/BeOS_Print.o: src/BeOS_Print.cpp obj src/BeOS_print.h
-c src/BeOS_print.cpp -o obj/BeOS_print.o
obj/hq3x.o: src/hq3x.c src/hq3x.h src/hqxx.h
@echo
@echo "...Compiling high quality 3x scale filter..."
@$(CC) $(CFLAGS) \
-c src/hq3x.c -o obj/hq3x.o
obj/hq4x.o: src/hq4x.c src/hq4x.h src/hqxx.h
@echo
@echo "...Compiling high quality 4x scale filter..."
@$(CC) $(CFLAGS) \
-c src/hq4x.c -o obj/hq4x.o
obj/hqxx.o: src/hqxx.c src/hqxx.h
@echo
@echo "...Compiling high quality scale filter helpers..."
@$(CC) $(CFLAGS) \
-c src/hqxx.c -o obj/hqxx.o
# Build the translation files for gettext
translations: trans \
@ -654,11 +676,11 @@ trans/es.mo: src/messages/es.po
trans/eu.mo: src/messages/eu.po
@echo " eu_ES ...Basque..."
@msgfmt src/messages/eu.po -o trans/eu.mo
trans/fi.mo: src/messages/fi.po
@echo " fi_FI ...Finnish..."
@msgfmt src/messages/fi.po -o trans/fi.mo
trans/fr.mo: src/messages/fr.po
@echo " fr_FR ...French..."
@msgfmt src/messages/fr.po -o trans/fr.mo
@ -681,8 +703,8 @@ trans/is.mo: src/messages/is.po
trans/it.mo: src/messages/it.po
@echo " it_IT ...Italian..."
@msgfmt src/messages/it.po -o trans/it.mo
@msgfmt src/messages/it.po -o trans/it.m
trans/ja.mo: src/messages/ja.po
@echo " ja_JP ...Japanese..."
@msgfmt src/messages/ja.po -o trans/ja.mo
@ -706,7 +728,7 @@ trans/nl.mo: src/messages/nl.po
trans/nb.mo: src/messages/nb.po
@echo " nb_NO ...Norwegian Bokmal..."
@msgfmt src/messages/nb.po -o trans/nb.mo
trans/nn.mo: src/messages/nn.po
@echo " nn_NO ...Norwegian Nynorsk..."
@msgfmt src/messages/nn.po -o trans/nn.mo

View file

@ -7,7 +7,7 @@ bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
June 17, 2002 - December 18, 2003
June 17, 2002 - December 20, 2003
* Design and Coding:
@ -26,7 +26,11 @@ June 17, 2002 - December 18, 2003
by Damian Yerrick - http://www.wikipedia.org/wiki/Damian_Yerrick
800x600 resolution support patch by:
TOYAMA Shin-ichi <kyone@tky2.3web.ne.jp>
TOYAMA Shin-ichi <shin1@wmail.plala.or.jp>
High quality stamp scaler from "hq2x", "hq3x" and "hq4x" demos
http://www.hiend3d.com/hq3x.html
by Maxim Stepin <maxim@hiend3d.com>
* Graphics

View file

@ -7,7 +7,7 @@ bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
2003.Dec.19 (0.9.13)
2003.Dec.20 (0.9.13)
* Translated into Basque (eu_ES)
Juan Irigoien <juanirigoien@irakasle.net>
@ -25,7 +25,11 @@ http://www.newbreedsoftware.com/tuxpaint/
(Place "noflip" and/or "nomirror" in the stamps' ".dat"
option files.) Stamps can have alternative mirror-images (e.g., to
show a shape the opposite direction, but not have backwards text on it).
Create "filename_mirror.png" image files. [PENDING]
Create "filename_mirror.png" image files.
* Incorproated high quality filtering code from HiEnd3D,
http://www.hiend3d.com/hq3x.html
by Maxim Stepin <maxim@hiend3d.com>
* Added "--nostampcontrols", "--mirrorstamps" and their opposite options,
to disable stamp controls, and default to mirrored stamp shapes,

3797
src/hq3x.c Normal file

File diff suppressed because it is too large Load diff

1
src/hq3x.h Normal file
View file

@ -0,0 +1 @@
void hq3x_32( unsigned char * pIn, unsigned char * pOut, int Xres, int Yres, int BpL, int LUT16to32[65536], int RGBtoYUV[65536] );

5230
src/hq4x.c Normal file

File diff suppressed because it is too large Load diff

1
src/hq4x.h Normal file
View file

@ -0,0 +1 @@
void hq4x_32( unsigned char * pIn, unsigned char * pOut, int Xres, int Yres, int BpL, int LUT16to32[65536], int RGBtoYUV[65536] );

122
src/hqxx.c Normal file
View file

@ -0,0 +1,122 @@
/*
hqNx filter look-up table init
Copyright (C) 2003 MaxSt ( maxst@hiend3d.com )
Library-ified by Bill Kendrick <bill@newbreedsoftware.com>
Based on "hq3x_src_c.zip" dated August 5, 2003
from: http://www.hiend3d.com/hq3x.html
December 20, 2003 - December 20, 2003
This program 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 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser 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 "hqxx.h"
const int Ymask = 0x00FF0000;
const int Umask = 0x0000FF00;
const int Vmask = 0x000000FF;
const int trY = 0x00300000;
const int trU = 0x00000700;
const int trV = 0x00000006;
void InitLUTs(int * LUT16to32, int * RGBtoYUV)
{
int i, j, k, r, g, b, Y, u, v;
for (i=0; i<65536; i++)
LUT16to32[i] = ((i & 0xF800) << 8) + ((i & 0x07E0) << 5) + ((i & 0x001F) << 3);
for (i=0; i<32; i++)
for (j=0; j<64; j++)
for (k=0; k<32; k++)
{
r = i << 3;
g = j << 2;
b = k << 3;
Y = (r + g + b) >> 2;
u = 128 + ((r - b) >> 2);
v = 128 + ((-r + 2*g -b)>>3);
RGBtoYUV[ (i << 11) + (j << 5) + k ] = (Y<<16) + (u<<8) + v;
}
}
inline void Interp1(unsigned char * pc, int c1, int c2)
{
*((int*)pc) = (c1*3+c2) >> 2;
}
inline void Interp2(unsigned char * pc, int c1, int c2, int c3)
{
*((int*)pc) = (c1*2+c2+c3) >> 2;
}
inline void Interp3(unsigned char * pc, int c1, int c2)
{
//*((int*)pc) = (c1*7+c2)/8;
*((int*)pc) = ((((c1 & 0x00FF00)*7 + (c2 & 0x00FF00) ) & 0x0007F800) +
(((c1 & 0xFF00FF)*7 + (c2 & 0xFF00FF) ) & 0x07F807F8)) >> 3;
}
inline void Interp4(unsigned char * pc, int c1, int c2, int c3)
{
//*((int*)pc) = (c1*2+(c2+c3)*7)/16;
*((int*)pc) = ((((c1 & 0x00FF00)*2 + ((c2 & 0x00FF00) + (c3 & 0x00FF00))*7 ) & 0x000FF000) +
(((c1 & 0xFF00FF)*2 + ((c2 & 0xFF00FF) + (c3 & 0xFF00FF))*7 ) & 0x0FF00FF0)) >> 4;
}
inline void Interp5(unsigned char * pc, int c1, int c2)
{
*((int*)pc) = (c1+c2) >> 1;
}
inline void Interp6(unsigned char * pc, int c1, int c2, int c3)
{
//*((int*)pc) = (c1*5+c2*2+c3)/8;
*((int*)pc) = ((((c1 & 0x00FF00)*5 + (c2 & 0x00FF00)*2 + (c3 & 0x00FF00) ) & 0x0007F800) +
(((c1 & 0xFF00FF)*5 + (c2 & 0xFF00FF)*2 + (c3 & 0xFF00FF) ) & 0x07F807F8)) >> 3;
}
inline void Interp7(unsigned char * pc, int c1, int c2, int c3)
{
//*((int*)pc) = (c1*6+c2+c3)/8;
*((int*)pc) = ((((c1 & 0x00FF00)*6 + (c2 & 0x00FF00) + (c3 & 0x00FF00) ) & 0x0007F800) +
(((c1 & 0xFF00FF)*6 + (c2 & 0xFF00FF) + (c3 & 0xFF00FF) ) & 0x07F807F8)) >> 3;
}
inline void Interp8(unsigned char * pc, int c1, int c2)
{
//*((int*)pc) = (c1*5+c2*3)/8;
*((int*)pc) = ((((c1 & 0x00FF00)*5 + (c2 & 0x00FF00)*3 ) & 0x0007F800) +
(((c1 & 0xFF00FF)*5 + (c2 & 0xFF00FF)*3 ) & 0x07F807F8)) >> 3;
}
inline int Diff(unsigned int w1, unsigned int w2)
{
YUV1 = w1; /* RGBtoYUV[w1]; */
YUV2 = w2; /* RGBtoYUV[w2]; */
return ( ( abs((YUV1 & Ymask) - (YUV2 & Ymask)) > trY ) ||
( abs((YUV1 & Umask) - (YUV2 & Umask)) > trU ) ||
( abs((YUV1 & Vmask) - (YUV2 & Vmask)) > trV ) );
}

48
src/hqxx.h Normal file
View file

@ -0,0 +1,48 @@
/*
hqNx filter look-up table init
Copyright (C) 2003 MaxSt ( maxst@hiend3d.com )
Library-ified by Bill Kendrick <bill@newbreedsoftware.com>
Based on "hq3x_src_c.zip" dated August 5, 2003
from: http://www.hiend3d.com/hq3x.html
This program 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 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser 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
*/
#ifndef HQINIT_H
#define HQINIT_H
static int YUV1, YUV2;
extern const int Ymask;
extern const int Umask;
extern const int Vmask;
extern const int trY;
extern const int trU;
extern const int trV;
void InitLUTs(int * LUT16to32, int * RGBtoYUV);
inline void Interp1(unsigned char * pc, int c1, int c2);
inline void Interp2(unsigned char * pc, int c1, int c2, int c3);
inline void Interp3(unsigned char * pc, int c1, int c2);
inline void Interp4(unsigned char * pc, int c1, int c2, int c3);
inline void Interp5(unsigned char * pc, int c1, int c2);
inline void Interp6(unsigned char * pc, int c1, int c2, int c3);
inline void Interp7(unsigned char * pc, int c1, int c2, int c3);
inline void Interp8(unsigned char * pc, int c1, int c2);
inline int Diff(unsigned int w1, unsigned int w2);
#endif

View file

@ -7,12 +7,12 @@
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
June 14, 2002 - December 19, 2003
June 14, 2002 - December 20, 2003
*/
#define VER_VERSION "0.9.13"
#define VER_DATE "2003.12.19"
#define VER_DATE "2003.12.20"
/* #define DEBUG */
@ -49,6 +49,9 @@
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "hqxx.h"
#include "hq3x.h"
#include "hq4x.h"
#include <locale.h>
#include <iconv.h>

View file

@ -1,301 +0,0 @@
/* win32_print.c */
/* printing support for Tux Paint */
/* John Popplewell <john@johnnypops.demon.co.uk> */
/* Sept. 30, 2002 - Oct. 17, 2002 */
#include "SDL_syswm.h"
#include "win32_print.h"
#include "resource.h"
#define NOREF(x) ((x)=(x))
#define GETHINST(hWnd) ((HINSTANCE)GetWindowLong( hWnd, GWL_HINSTANCE ))
#define MIR( id ) (MAKEINTRESOURCE( id ))
static int bPrint;
static HWND hDlgCancel;
static int GetPrinterContext( HWND hWnd, PRINTDLG *pd )
{
pd->hwndOwner = hWnd;
pd->Flags = PD_RETURNDC;
pd->nFromPage = 0xFFFF;
pd->nToPage = 0xFFFF;
pd->nMinPage = 0xFFFF;
pd->nMaxPage = 0xFFFF;
pd->nCopies = 1;
return PrintDlg( pd );
}
BOOL CALLBACK AbortProc( HDC hDC, int nCode )
{
MSG msg;
NOREF(nCode);
NOREF(hDC);
while ( PeekMessage( (LPMSG)&msg, (HWND)NULL, 0, 0, PM_REMOVE) )
{
if ( !IsDialogMessage( hDlgCancel, (LPMSG)&msg ) )
{
TranslateMessage( (LPMSG)&msg );
DispatchMessage( (LPMSG)&msg );
}
}
return bPrint;
}
LRESULT CALLBACK AbortPrintJob( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
NOREF(hDlg);
NOREF(lParam);
NOREF(wParam);
NOREF(message);
switch ( message )
{
case WM_INITDIALOG :
return TRUE;
case WM_COMMAND :
bPrint = FALSE;
return TRUE;
default :
return FALSE;
}
}
static SDL_Surface *make32bitDIB( SDL_Surface *surf )
{
SDL_PixelFormat pixfmt;
SDL_Surface *surf32;
SDL_Surface *surfDIB;
Uint8 *src,*dst;
Uint32 linesize;
int i;
memset( &pixfmt, 0, sizeof(pixfmt) );
pixfmt.palette = NULL;
pixfmt.BitsPerPixel = 32;
pixfmt.BytesPerPixel= 4;
pixfmt.Rmask = 0x00FF0000;
pixfmt.Gmask = 0x0000FF00;
pixfmt.Bmask = 0x000000FF;
pixfmt.Amask = 0xFF000000;
pixfmt.Rshift = 16;
pixfmt.Gshift = 8;
pixfmt.Bshift = 0;
pixfmt.Ashift = 24;
pixfmt.Rloss = 0;
pixfmt.Gloss = 0;
pixfmt.Bloss = 0;
pixfmt.Aloss = 0;
pixfmt.colorkey = 0;
pixfmt.alpha = 0;
surf32 = SDL_ConvertSurface( surf, &pixfmt, SDL_SWSURFACE );
surfDIB = SDL_CreateRGBSurface( SDL_SWSURFACE, surf32->w, surf32->h, 32,
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask, pixfmt.Amask );
linesize = surf32->w*sizeof(Uint32); /* Flip top2bottom */
dst = surfDIB->pixels;
src = ((Uint8*)surf32->pixels)+((surf32->h-1)*surf32->pitch);
for ( i = 0; i < surf32->h; ++i )
{
memcpy( dst, src, linesize );
src -= surf32->pitch;
dst += surfDIB->pitch;
}
SDL_FreeSurface( surf32 ); /* Free temp surface */
return surfDIB;
}
int IsPrinterAvailable( void )
{
char *section = "windows";
char *key = "device";
char *def = "NODEFAULTPRINTER";
char buff[256];
if ( !GetProfileString( section, key, def, buff, sizeof(buff) ) )
return 0;
return (strcmp( buff, def ) != 0);
}
int SurfacePrint( SDL_Surface *surf )
{
int res = 0;
HWND hWnd;
PRINTDLG pd;
DOCINFO di;
int nError;
SDL_SysWMinfo wminfo;
HDC hDC;
BITMAPINFOHEADER bmih;
SDL_Surface *surf32 = NULL;
RECT rc;
float fLogPelsX1, fLogPelsY1, fLogPelsX2, fLogPelsY2;
float fScaleX, fScaleY;
int cWidthPels, xLeft, yTop;
float subscaler,subscalerx,subscalery;
int hDCCaps;
HANDLE hOldObject = NULL;
HBITMAP hbm = NULL;
HDC hdcMem = NULL;
SDL_VERSION(&wminfo.version);
if ( !SDL_GetWMInfo( &wminfo ) )
return -1;
hWnd = wminfo.window;
memset( &pd, 0, sizeof(PRINTDLG) );
pd.lStructSize = sizeof(PRINTDLG);
if ( !GetPrinterContext( hWnd, &pd ) || (pd.hDC == NULL) )
return -1;
bPrint = TRUE;
SetAbortProc( pd.hDC, AbortProc );
hDlgCancel = CreateDialog( GETHINST(hWnd), MIR(IDD_ABORTDLG), hWnd, (DLGPROC)AbortPrintJob );
EnableWindow( hWnd, FALSE );
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Tux Paint";
di.lpszOutput = (LPTSTR)NULL;
di.lpszDatatype = (LPTSTR)NULL;
di.fwType = 0;
nError = StartDoc( pd.hDC, &di );
if ( nError == SP_ERROR )
{
res = -2;
goto error;
}
nError = StartPage(pd.hDC);
if (nError <= 0)
{
res = -3;
goto error;
}
//////////////////////////////////////////////////////////////////////////////////////
surf32 = make32bitDIB( surf );
if ( !surf32 )
{
res = -4;
goto error;
}
memset( &bmih,0, sizeof(bmih) );
bmih.biSize = sizeof(bmih);
bmih.biPlanes = 1;
bmih.biCompression = BI_RGB;
bmih.biBitCount = 32;
bmih.biWidth = surf32->w;
bmih.biHeight = surf32->h;
GetClientRect( hWnd, &rc );
subscalerx = (float)rc.right/surf32->w;
subscalery = (float)rc.bottom/surf32->h;
subscaler = subscalery;
if ( subscalerx < subscalery )
subscaler = subscalerx;
hDC = GetDC( hWnd );
fLogPelsX1 = (float)GetDeviceCaps(hDC, LOGPIXELSX);
fLogPelsY1 = (float)GetDeviceCaps(hDC, LOGPIXELSY);
ReleaseDC( hWnd, hDC );
fLogPelsX2 = (float)GetDeviceCaps(pd.hDC, LOGPIXELSX);
fLogPelsY2 = (float)GetDeviceCaps(pd.hDC, LOGPIXELSY);
if (fLogPelsX1 > fLogPelsX2)
fScaleX = (fLogPelsX1/fLogPelsX2);
else
fScaleX = (fLogPelsX2/fLogPelsX1);
if (fLogPelsY1 > fLogPelsY2)
fScaleY = (fLogPelsY1/fLogPelsY2);
else
fScaleY = (fLogPelsY2/fLogPelsY1);
fScaleX *= subscaler;
fScaleY *= subscaler;
yTop = 0;
cWidthPels = GetDeviceCaps(pd.hDC, PHYSICALWIDTH);
xLeft = ((cWidthPels - ((int)(fScaleX*bmih.biWidth)))/2)-
GetDeviceCaps(pd.hDC, PHYSICALOFFSETX);
hDCCaps = GetDeviceCaps(pd.hDC, RASTERCAPS);
if ( hDCCaps & RC_STRETCHDIB )
{
StretchDIBits(pd.hDC, xLeft, yTop,
(int)(fScaleX*bmih.biWidth),
(int)(fScaleY*bmih.biHeight),
0, 0, bmih.biWidth, bmih.biHeight,
surf32->pixels, (BITMAPINFO*)&bmih,
DIB_RGB_COLORS, SRCCOPY);
}
else
if ( hDCCaps & RC_STRETCHBLT )
{
hbm = CreateDIBitmap(pd.hDC, &bmih, CBM_INIT,
surf32->pixels, (const BITMAPINFO*)&bmih, 0);
if ( hbm )
{
hdcMem = CreateCompatibleDC( pd.hDC );
if ( hdcMem )
{
hOldObject = SelectObject(hdcMem, hbm);
if ( hOldObject )
{
StretchBlt(pd.hDC, xLeft, yTop,
(int)(fScaleX*bmih.biWidth),
(int)(fScaleY*bmih.biHeight),
hdcMem, 0, 0, bmih.biWidth, bmih.biHeight, SRCCOPY);
SelectObject(hdcMem, hOldObject);
}
}
}
}
else
{
res = -10;
goto error;
}
//////////////////////////////////////////////////////////////////////////////////////
nError = EndPage( pd.hDC );
if ( nError <= 0 )
{
res = -9;
goto error;
}
EndDoc( pd.hDC );
error:
if ( hdcMem ) DeleteDC( hdcMem );
if ( hbm ) DeleteObject( hbm );
if ( surf32 ) SDL_FreeSurface( surf32 );
EnableWindow( hWnd, TRUE );
DestroyWindow( hDlgCancel );
DeleteDC( pd.hDC );
return res;
}

View file

@ -1,19 +0,0 @@
/* win32_print.h */
/* printing support for Tux Paint */
/* John Popplewell <john@johnnypops.demon.co.uk> */
/* Sept. 30, 2002 - Oct. 1, 2002 */
#ifndef __WIN32_PRINT_H__
#define __WIN32_PRINT_H__
#ifndef _SDL_H
#include "SDL.h"
#endif
extern int SurfacePrint( SDL_Surface *surf );
extern int IsPrinterAvailable( void );
#endif