ddutil.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef DDUTIL_H
  2. #define DDUTIL_H
  3. #include <ddraw.h>
  4. class gxGraphics;
  5. typedef IDirectDrawSurface7 ddSurf;
  6. struct ddUtil{
  7. static void buildMipMaps( ddSurf *surf );
  8. static void copy( ddSurf *dest,int dx,int dy,int dw,int dh,ddSurf *src,int sx,int sy,int sw,int sh );
  9. static ddSurf *loadSurface( const std::string &f,int flags,gxGraphics *gfx );
  10. static ddSurf *createSurface( int width,int height,int flags,gxGraphics *gfx );
  11. };
  12. class PixelFormat{
  13. int depth,pitch;
  14. unsigned amask,rmask,gmask,bmask,argbfill;
  15. unsigned char ashr,ashl,rshr,rshl,gshr,gshl,bshr,bshl;
  16. typedef void (_fastcall *Plot)(void *pix,unsigned argb);
  17. typedef unsigned (_fastcall *Point)(void *pix);
  18. Plot plot;
  19. Point point;
  20. char *plot_code,*point_code;
  21. public:
  22. PixelFormat():plot_code(0){
  23. }
  24. PixelFormat( const DDPIXELFORMAT &pf ):plot_code(0){
  25. setFormat( pf );
  26. }
  27. ~PixelFormat();
  28. void setFormat( const DDPIXELFORMAT &pf );
  29. int getDepth()const{
  30. return depth;
  31. }
  32. int getPitch()const{
  33. return pitch;
  34. }
  35. unsigned fromARGB( unsigned n )const{
  36. return ( (n>>ashr<<ashl)&amask ) | ( (n>>rshr<<rshl)&rmask ) | ( (n>>gshr<<gshl)&gmask ) | ( (n>>bshr<<bshl)&bmask );
  37. }
  38. unsigned toARGB( unsigned n )const{
  39. return ( (n&amask)>>ashl<<ashr ) | ( (n&rmask)>>rshl<<rshr ) | ( (n&gmask)>>gshl<<gshr ) | ( (n&bmask)>>bshl<<bshr ) | argbfill;
  40. }
  41. void setPixel( void *p,unsigned n )const{ plot(p,n); }
  42. unsigned getPixel( void *p )const{ return point(p); }
  43. };
  44. #endif