112 const float scale=1/255.0f;
127 tmp=*(
unsigned short*)&pixel[0];
128 rgb.
X=((tmp&0x0f00)>>4);
129 rgb.
Y=((tmp&0x00f0));
130 rgb.
Z=((tmp&0x000f)<<4);
136 tmp=*(
unsigned short*)&pixel[0];
145 tmp=*(
unsigned short*)&pixel[0];
163 r=(
unsigned char) (rgb.
X*255.0f);
164 g=(
unsigned char) (rgb.
Y*255.0f);
165 b=(
unsigned char) (rgb.
Z*255.0f);
178 tmp=*(
unsigned short*)&pixel[0];
183 *(
unsigned short*)&pixel[0]=tmp;
189 tmp=*(
unsigned short*)&pixel[0];
194 *(
unsigned short*)&pixel[0]=tmp;
203 *(
unsigned short*)&pixel[0]=tmp;
217 SurfaceFormat(format)
230 SurfaceFormat=desc.
Format;
239 SurfaceFormat=desc.
Format;
245 D3DSurface->Release();
252 D3DSURFACE_DESC d3d_desc;
253 ::ZeroMemory(&d3d_desc,
sizeof(D3DSURFACE_DESC));
256 surface_desc.
Height = d3d_desc.Height;
257 surface_desc.
Width = d3d_desc.Width;
262 D3DLOCKED_RECT lock_rect;
263 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
265 *pitch = lock_rect.Pitch;
266 return (
void *)lock_rect.pBits;
297 D3DLOCKED_RECT lock_rect;
298 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
301 unsigned char *mem=(
unsigned char *) lock_rect.pBits;
303 for (i=0; i<sd.
Height; i++)
305 memset(mem,0,size*sd.
Width);
306 mem+=lock_rect.Pitch;
336 D3DLOCKED_RECT lock_rect;
337 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
340 unsigned char *mem=(
unsigned char *) lock_rect.pBits;
342 for (i=0; i<sd.
Height; i++)
344 memcpy(mem,&other[i*sd.
Width*size],size*sd.
Width);
345 mem+=lock_rect.Pitch;
375 D3DLOCKED_RECT lock_rect;
376 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
384 unsigned char *mem=(
unsigned char *) lock_rect.pBits;
387 for (i=
min.J; i<
max.J; i++)
389 memcpy(mem,&other[(i*sd.
Width+
min.I)*size],size*dx);
390 mem+=lock_rect.Pitch;
426 D3DLOCKED_RECT lock_rect;
427 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
428 DX8_ErrorCode(D3DSurface->LockRect(&lock_rect,0,D3DLOCK_READONLY));
430 unsigned char *mem=(
unsigned char *) lock_rect.pBits;
432 for (i=0; i<sd.
Height; i++)
439 memcpy(&other[i*sd.
Width*mysize],mem,mysize*sd.
Width);
441 mem+=lock_rect.Pitch;
466 unsigned int dstx,
unsigned int dsty,
467 unsigned int srcx,
unsigned int srcy,
468 unsigned int width,
unsigned int height,
481 src.right=srcx+width;
483 src.bottom=srcy+height;
485 if (src.right>
int(osd.
Width)) src.right=int(osd.
Width);
486 if (src.bottom>
int(osd.
Height)) src.bottom=int(osd.
Height);
499 dest.right=dstx+width;
501 dest.bottom=dsty+height;
503 if (dest.right>
int(sd.
Width)) dest.right=int(sd.
Width);
504 if (dest.bottom>
int(sd.
Height)) dest.bottom=int(sd.
Height);
506 DX8_ErrorCode(D3DXLoadSurfaceFromSurface(D3DSurface,
NULL,&dest,other->D3DSurface,
NULL,&src,D3DX_FILTER_NONE,0));
526 unsigned int dstx,
unsigned int dsty,
unsigned int dstwidth,
unsigned int dstheight,
527 unsigned int srcx,
unsigned int srcy,
unsigned int srcwidth,
unsigned int srcheight,
538 src.right=srcx+srcwidth;
540 src.bottom=srcy+srcheight;
544 dest.right=dstx+dstwidth;
546 dest.bottom=dsty+dstheight;
548 DX8_ErrorCode(D3DXLoadSurfaceFromSurface(D3DSurface,
NULL,&dest,other->D3DSurface,
NULL,&src,D3DX_FILTER_TRIANGLE ,0));
585 D3DLOCKED_RECT lock_rect;
586 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
588 ::ZeroMemory(&rect,
sizeof(RECT));
595 DX8_ErrorCode(D3DSurface->LockRect(&lock_rect,&rect,D3DLOCK_READONLY));
603 for (y =
min->J; y < max->J; y++) {
604 for (x =
min->I; x < max->
I; x++) {
607 unsigned char *alpha=(
unsigned char*) ((
unsigned int)lock_rect.pBits+(y-
min->J)*lock_rect.Pitch+(x-
min->I)*size);
608 unsigned char myalpha=alpha[size-1];
609 myalpha=(myalpha>>(8-alphabits)) & mask;
611 realmin.
I =
MIN(realmin.
I, x);
612 realmax.
I =
MAX(realmax.
I, x);
613 realmin.
J =
MIN(realmin.
J, y);
614 realmax.
J =
MAX(realmax.
J, y);
663 D3DLOCKED_RECT lock_rect;
664 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
666 ::ZeroMemory(&rect,
sizeof(RECT));
673 DX8_ErrorCode(D3DSurface->LockRect(&lock_rect,&rect,D3DLOCK_READONLY));
678 for (y = 0; y < (int) sd.
Height; y++)
681 unsigned char *alpha=(
unsigned char*) ((
unsigned int)lock_rect.pBits+y*lock_rect.Pitch);
682 unsigned char myalpha=alpha[size-1];
683 myalpha=(myalpha>>(8-alphabits)) & mask;
717 D3DLOCKED_RECT lock_rect;
718 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
720 ::ZeroMemory(&rect,
sizeof(RECT));
727 DX8_ErrorCode(D3DSurface->LockRect(&lock_rect,&rect,D3DLOCK_READONLY));
750 D3DSurface = surface;
755 if (D3DSurface !=
NULL) {
756 D3DSurface->AddRef ();
783 if (D3DSurface !=
NULL) {
784 D3DSurface->Release ();
813 D3DLOCKED_RECT lock_rect;
814 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
816 ::ZeroMemory(&rect,
sizeof(RECT));
824 unsigned char *cptr=(
unsigned char*)lock_rect.pBits;
825 unsigned short *sptr=(
unsigned short*)lock_rect.pBits;
826 unsigned int *lptr=(
unsigned int*)lock_rect.pBits;
831 *cptr=(
unsigned char) (color & 0xFF);
834 *sptr=(
unsigned short) (color & 0xFFFF);
867 D3DLOCKED_RECT lock_rect;
868 ::ZeroMemory(&lock_rect,
sizeof(D3DLOCKED_RECT));
870 ::ZeroMemory(&rect,
sizeof(RECT));
878 unsigned char *cptr=(
unsigned char*)lock_rect.pBits;
879 unsigned short *sptr=(
unsigned short*)lock_rect.pBits;
880 unsigned int *lptr=(
unsigned int*)lock_rect.pBits;
884 for (x=x1; x<=x2; x++)
889 *cptr++=(
unsigned char) (color & 0xFF);
892 *sptr++=(
unsigned short) (color & 0xFFFF);
924 bool is_compressed =
false;
950 is_compressed =
true;
967 unsigned char *bits=(
unsigned char*)
Lock(&pitch);
972 for (y=0; y<sd.
Height; y++)
974 for (x=0; x<sd.
Width; x++)
977 mono&=(rgb.
X==rgb.
Y);
978 mono&=(rgb.
X==rgb.
Z);
979 mono&=(rgb.
Z==rgb.
Y);
1017 unsigned char *bits=(
unsigned char*)
Lock(&pitch);
1021 for (y=0; y<sd.
Height; y++)
1023 for (x=0; x<sd.
Width; x++)
Color scale(const Color &a, const Color &b)
unsigned int PixelSize(const SurfaceClass::SurfaceDescription &sd)
void Convert_Pixel(Vector3 &rgb, const SurfaceClass::SurfaceDescription &sd, const unsigned char *pixel)
T Bound(T original, T minval, T maxval)
static IDirect3DSurface8 * _Create_DX8_Surface(unsigned int width, unsigned int height, WW3DFormat format)
static void _Copy_DX8_Rects(IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRectsArray, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPointsArray)
void DrawHLine(const unsigned int y, const unsigned int x1, const unsigned int x2, unsigned int color)
void Get_Description(SurfaceDescription &surface_desc)
void Copy(unsigned int dstx, unsigned int dsty, unsigned int srcx, unsigned int srcy, unsigned int width, unsigned int height, const SurfaceClass *other)
void Attach(IDirect3DSurface8 *surface)
unsigned char * CreateCopy(int *width, int *height, int *size, bool flip=false)
bool Is_Transparent_Column(unsigned int column)
void Get_Pixel(Vector3 &rgb, int x, int y)
void Hue_Shift(const Vector3 &hsv_shift)
void Stretch_Copy(unsigned int dstx, unsigned int dsty, unsigned int dstwidth, unsigned int dstheight, unsigned int srcx, unsigned int srcy, unsigned int srcwidth, unsigned int srcheight, const SurfaceClass *source)
void FindBB(Vector2i *min, Vector2i *max)
SurfaceClass(unsigned width, unsigned height, WW3DFormat format)
void DrawPixel(const unsigned int x, const unsigned int y, unsigned int color)
void Recolor(Vector3 &rgb, const Vector3 &hsv_shift)
WWINLINE void DX8_ErrorCode(unsigned res)
#define REF_PTR_RELEASE(x)
unsigned int PixelSize(const SurfaceClass::SurfaceDescription &sd)
void Convert_Pixel(Vector3 &rgb, const SurfaceClass::SurfaceDescription &sd, const unsigned char *pixel)