Ticket #2456: Tex_Part2_V2.patch
File Tex_Part2_V2.patch, 29.4 KB (added by , 10 years ago) |
---|
-
source/graphics/tests/test_TextureConverter.h
38 38 m_VFS = CreateVfs(20*MiB); 39 39 TS_ASSERT_OK(m_VFS->Mount(L"", DataDir()/"mods"/"_test.tex", VFS_MOUNT_MUST_EXIST)); 40 40 TS_ASSERT_OK(m_VFS->Mount(L"cache/", DataDir()/"_testcache")); 41 42 tex_codec_register_all();43 41 } 44 42 45 43 void tearDown() 46 44 { 47 tex_codec_unregister_all();48 49 45 m_VFS.reset(); 50 46 DeleteDirectory(DataDir()/"_testcache"); 51 47 } -
source/graphics/tests/test_TextureManager.h
41 41 TS_ASSERT_OK(m_VFS->Mount(L"cache/", DataDir()/"_testcache")); 42 42 43 43 h_mgr_init(); 44 tex_codec_register_all();45 44 46 45 CXeromyces::Startup(); 47 46 } … … 50 49 { 51 50 CXeromyces::Terminate(); 52 51 53 tex_codec_unregister_all();54 52 h_mgr_shutdown(); 55 53 56 54 m_VFS.reset(); -
source/lib/res/graphics/tests/test_tex.h
64 64 } 65 65 66 66 public: 67 68 // this also covers BGR and orientation transforms.69 void DISABLED_test_encode_decode() // disabled because it's completely broken70 {71 tex_codec_register_all();72 73 // for each codec74 const TexCodecVTbl* c = 0;75 for(;;)76 {77 c = tex_codec_next(c);78 if(!c)79 break;80 81 // get an extension that this codec will support82 // (so that tex_encode uses this codec)83 wchar_t extension[30] = {'.'};84 wcscpy_s(extension+1, 29, c->name);85 // .. make sure the c->name hack worked86 const TexCodecVTbl* correct_c = 0;87 TS_ASSERT_OK(tex_codec_for_filename(extension, &correct_c));88 TS_ASSERT_EQUALS(c, correct_c);89 90 // for each test width/height combination91 const size_t widths [] = { 4, 5, 4, 256, 384 };92 const size_t heights[] = { 4, 4, 5, 256, 256 };93 for(size_t i = 0; i < ARRAY_SIZE(widths); i++)94 {95 // for each bit depth96 for(size_t bpp = 8; bpp <= 32; bpp += 8)97 {98 size_t flags = 0;99 if(!wcscmp(extension, L".dds"))100 flags |= (TEX_DXT&3); // DXT3101 if(bpp == 8)102 flags |= TEX_GREY;103 else if(bpp == 16)104 continue; // not supported105 else if(bpp == 32)106 flags |= TEX_ALPHA;107 108 // normal109 generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);110 // top-down111 flags &= ~TEX_ORIENTATION; flags |= TEX_TOP_DOWN;112 generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);113 // bottom up114 flags &= ~TEX_ORIENTATION; flags |= TEX_BOTTOM_UP;115 generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);116 117 flags &= ~TEX_ORIENTATION;118 flags |= TEX_BGR;119 120 // bgr, normal121 generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);122 // bgr, top-down123 flags &= ~TEX_ORIENTATION; flags |= TEX_TOP_DOWN;124 generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);125 // bgr, bottom up126 flags &= ~TEX_ORIENTATION; flags |= TEX_BOTTOM_UP;127 generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);128 } // for bpp129 } // for width/height130 } // foreach codec131 132 tex_codec_unregister_all();133 }134 135 67 // have mipmaps be created for a test image; check resulting size and pixels 136 68 void test_mipmap_create() 137 69 { … … 164 96 165 97 void test_s3tc_decode() 166 98 { 167 tex_codec_register_all();168 169 99 const size_t w = 4, h = 4, bpp = 4; 170 100 const size_t size = w*h/2; 171 101 shared_ptr<u8> img(new u8[size], ArrayDeleter()); … … 187 117 188 118 // compare img 189 119 TS_ASSERT_SAME_DATA(t.get_data(), expected, 48); 190 191 // cleanup192 tex_codec_unregister_all();193 120 } 194 121 }; -
source/lib/tex/tex.cpp
569 569 // but this is open to misuse. 570 570 bool tex_is_known_extension(const VfsPath& pathname) 571 571 { 572 const TexCodecVTbl* dummy;572 const ITexCodec* dummy; 573 573 // found codec for it => known extension 574 574 const OsPath extension = pathname.Extension(); 575 575 if(tex_codec_for_filename(extension, &dummy) == INFO::OK) … … 704 704 // directly into the output buffer and makes for zero-copy IO. 705 705 size_t tex_hdr_size(const VfsPath& filename) 706 706 { 707 const TexCodecVTbl* c;707 const ITexCodec* c; 708 708 709 709 const OsPath extension = filename.Extension(); 710 710 WARN_RETURN_STATUS_IF_ERR(tex_codec_for_filename(extension, &c)); … … 718 718 719 719 Status Tex::decode(const shared_ptr<u8>& Data, size_t DataSize) 720 720 { 721 const TexCodecVTbl* c;721 const ITexCodec* c; 722 722 RETURN_STATUS_IF_ERR(tex_codec_for_header(Data.get(), DataSize, &c)); 723 723 724 724 // make sure the entire header is available … … 762 762 const size_t max_out_size = img_size()*4 + 256*KiB; 763 763 RETURN_STATUS_IF_ERR(da_alloc(da, max_out_size)); 764 764 765 const TexCodecVTbl* c;765 const ITexCodec* c; 766 766 WARN_RETURN_STATUS_IF_ERR(tex_codec_for_filename(extension, &c)); 767 767 768 768 // encode into <da> -
source/lib/tex/tex.h
368 368 369 369 370 370 /** 371 * Manually register codecs. must be called before first use of a372 * codec (e.g. loading a texture).373 *374 * This would normally be taken care of by TEX_CODEC_REGISTER, but375 * no longer works when building as a static library.376 * Workaround: hard-code a list of codecs in tex_codec.cpp and377 * call their registration functions.378 **/379 extern void tex_codec_register_all();380 381 /**382 * remove all codecs that have been registered.383 **/384 extern void tex_codec_unregister_all();385 386 /**387 371 * special value for levels_to_skip: the callback will only be called 388 372 * for the base mipmap level (i.e. 100%) 389 373 **/ -
source/lib/tex/tex_bmp.cpp
60 60 #define BI_RGB 0 // biCompression 61 61 62 62 63 static Status bmp_transform(Tex* UNUSED(t), size_t UNUSED(transforms)) 63 Status TexCodecBmp::transform(Tex* UNUSED(t), size_t UNUSED(transforms)) const 64 64 { 65 65 return INFO::TEX_CODEC_CANNOT_HANDLE; 66 66 } 67 67 68 68 69 static bool bmp_is_hdr(const u8* file) 69 bool TexCodecBmp::is_hdr(const u8* file) const 70 70 { 71 71 // check header signature (bfType == "BM"?). 72 72 // we compare single bytes to be endian-safe. … … 74 74 } 75 75 76 76 77 static bool bmp_is_ext(const OsPath& extension) 77 bool TexCodecBmp::is_ext(const OsPath& extension) const 78 78 { 79 79 return extension == L".bmp"; 80 80 } 81 81 82 82 83 s tatic size_t bmp_hdr_size(const u8* file)83 size_t TexCodecBmp::hdr_size(const u8* file) const 84 84 { 85 85 const size_t hdr_size = sizeof(BmpHeader); 86 86 if(file) … … 95 95 96 96 97 97 // requirements: uncompressed, direct colour, bottom up 98 static Status bmp_decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t) 98 Status TexCodecBmp::decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t) const 99 99 { 100 100 const BmpHeader* hdr = (const BmpHeader*)data; 101 101 const long w = (long)read_le32(&hdr->biWidth); … … 124 124 } 125 125 126 126 127 static Status bmp_encode(Tex* RESTRICT t, DynArray* RESTRICT da) 127 Status TexCodecBmp::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const 128 128 { 129 129 const size_t hdr_size = sizeof(BmpHeader); // needed for BITMAPFILEHEADER 130 130 const size_t img_size = t->img_size(); … … 155 155 }; 156 156 return tex_codec_write(t, transforms, &hdr, hdr_size, da); 157 157 } 158 159 TEX_CODEC_REGISTER(bmp); -
source/lib/tex/tex_codec.cpp
33 33 #include "lib/allocators/shared_ptr.h" // ArrayDeleter 34 34 #include "tex.h" 35 35 36 static const TexCodecVTbl* codecs; 36 // Statically allocate all of the codecs... 37 TexCodecDds DdsCodec; 38 TexCodecPng PngCodec; 39 TexCodecJpg JpgCodec; 40 TexCodecTga TgaCodec; 41 TexCodecPng BmpCodec; 42 // Codecs will be searched in this order 43 static const ITexCodec *codecs[] = {(ITexCodec *)&DdsCodec, (ITexCodec *)&PngCodec, 44 (ITexCodec *)&JpgCodec, (ITexCodec *)&TgaCodec, (ITexCodec *)&BmpCodec}; 45 static const int codecs_len = sizeof(codecs) / sizeof(ITexCodec*); 37 46 38 // add this vtbl to the codec list. called at NLSO init time by the39 // TEX_CODEC_REGISTER in each codec file. note that call order and therefore40 // order in the list is undefined, but since each codec only steps up if it41 // can handle the given format, this is not a problem.42 //43 // returns int to alloc calling from a macro at file scope.44 int tex_codec_register(TexCodecVTbl* c)45 {46 ENSURE(c);47 48 // insert at front of list.49 c->next = codecs;50 codecs = c;51 52 return 0; // (assigned to dummy variable)53 }54 55 // remove all codecs that have been registered.56 void tex_codec_unregister_all()57 {58 codecs = NULL;59 }60 61 47 // find codec that recognizes the desired output file extension, 62 48 // or return ERR::TEX_UNKNOWN_FORMAT if unknown. 63 49 // note: does not raise a warning because it is used by 64 50 // tex_is_known_extension. 65 Status tex_codec_for_filename(const OsPath& extension, const TexCodecVTbl** c)51 Status tex_codec_for_filename(const OsPath& extension, const ITexCodec** c) 66 52 { 67 for( *c = codecs; *c; *c = (*c)->next)53 for(int i = 0; i < codecs_len; ++i) 68 54 { 69 55 // we found it 70 if((*c)->is_ext(extension)) 56 if(codecs[i]->is_ext(extension)) { 57 *c = codecs[i]; 71 58 return INFO::OK; 59 } 72 60 } 73 61 74 62 return ERR::TEX_UNKNOWN_FORMAT; // NOWARN … … 76 64 77 65 78 66 // find codec that recognizes the header's magic field 79 Status tex_codec_for_header(const u8* file, size_t file_size, const TexCodecVTbl** c)67 Status tex_codec_for_header(const u8* file, size_t file_size, const ITexCodec** c) 80 68 { 81 69 // we guarantee at least 4 bytes for is_hdr to look at 82 70 if(file_size < 4) 83 71 WARN_RETURN(ERR::TEX_INCOMPLETE_HEADER); 84 85 for( *c = codecs; *c; *c = (*c)->next)72 73 for(int i = 0; i < codecs_len; ++i) 86 74 { 87 75 // we found it 88 if((*c)->is_hdr(file)) 76 if(codecs[i]->is_hdr(file)) { 77 *c = codecs[i]; 89 78 return INFO::OK; 79 } 90 80 } 91 81 92 82 WARN_RETURN(ERR::TEX_UNKNOWN_FORMAT); 93 83 } 94 84 95 96 const TexCodecVTbl* tex_codec_next(const TexCodecVTbl* prev_codec)97 {98 // first time99 if(!prev_codec)100 return codecs;101 // middle of list: return next (can be 0 to indicate end of list)102 else103 return prev_codec->next;104 }105 106 107 85 Status tex_codec_transform(Tex* t, size_t transforms) 108 86 { 109 87 Status ret = INFO::TEX_CODEC_CANNOT_HANDLE; 110 88 111 89 // find codec that understands the data, and transform 112 for( const TexCodecVTbl* c = codecs; c; c = c->next)90 for(int i = 0; i < codecs_len; ++i) 113 91 { 114 Status err = c ->transform(t, transforms);92 Status err = codecs[i]->transform(t, transforms); 115 93 // success 116 94 if(err == INFO::OK) 117 95 return INFO::OK; … … 131 109 // helper functions used by codecs 132 110 //----------------------------------------------------------------------------- 133 111 134 void tex_codec_register_all()135 {136 #define REGISTER_CODEC(name) extern void name##_register(); name##_register()137 REGISTER_CODEC(bmp);138 REGISTER_CODEC(dds);139 REGISTER_CODEC(jpg);140 REGISTER_CODEC(png);141 REGISTER_CODEC(tga);142 #undef REGISTER_CODEC143 }144 145 112 // allocate an array of row pointers that point into the given texture data. 146 113 // <file_orientation> indicates whether the file format is top-down or 147 114 // bottom-up; the row array is inverted if necessary to match global -
source/lib/tex/tex_codec.h
36 36 * 'template method'-style interface to increase code reuse and 37 37 * simplify writing new codecs. 38 38 **/ 39 struct TexCodecVTbl 39 class ITexCodec 40 40 { 41 public: 41 42 /** 42 43 * decode the file into a Tex structure. 43 44 * … … 49 50 * @param t output texture object 50 51 * @return Status 51 52 **/ 52 Status (*decode)(u8* data, size_t size, Tex* RESTRICT t);53 virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const = 0; 53 54 54 55 /** 55 56 * encode the texture data into the codec's file format (in memory). … … 62 63 * by the caller. 63 64 * @return Status 64 65 **/ 65 Status (*encode)(Tex* RESTRICT t, DynArray* RESTRICT da);66 virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const = 0; 66 67 67 68 /** 68 69 * transform the texture's pixel format. … … 73 74 * to its format; generic pixel format transforms are handled by 74 75 * the caller. 75 76 **/ 76 Status (*transform)(Tex* t, size_t transforms);77 virtual Status transform(Tex* t, size_t transforms) const = 0; 77 78 78 79 /** 79 80 * indicate if the data appears to be an instance of this codec's header, … … 83 84 * (this should be enough to examine the header's 'magic' field) 84 85 * @return bool 85 86 **/ 86 bool (*is_hdr)(const u8* file);87 virtual bool is_hdr(const u8* file) const = 0; 87 88 88 89 /** 89 90 * is the extension that of a file format supported by this codec? … … 95 96 * @param extension (including '.') 96 97 * @return bool 97 98 **/ 98 bool (*is_ext)(const OsPath& extension);99 virtual bool is_ext(const OsPath& extension) const = 0; 99 100 100 101 /** 101 102 * return size of the file header supported by this codec. … … 106 107 * variable-length fields. 107 108 * @return size [bytes] 108 109 **/ 109 size_t (*hdr_size)(const u8* file);110 virtual size_t hdr_size(const u8* file) const = 0; 110 111 111 112 /** 112 113 * name of codec for debug purposes. typically set via TEX_CODEC_REGISTER. 113 114 **/ 114 const wchar_t* name; 115 virtual const wchar_t* get_name() const = 0; 116 }; 115 117 116 /** 117 * intrusive linked-list of codecs: more convenient than fixed-size 118 * static storage. 119 * set by caller; should be initialized to NULL. 120 **/ 121 const TexCodecVTbl* next; 118 class TexCodecPng:ITexCodec { 119 public: 120 virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; 121 virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; 122 virtual Status transform(Tex* t, size_t transforms) const; 123 virtual bool is_hdr(const u8* file) const; 124 virtual bool is_ext(const OsPath& extension) const; 125 virtual size_t hdr_size(const u8* file) const; 126 virtual const wchar_t* get_name() const { 127 static const wchar_t *name = L"png"; 128 return name; 129 }; 122 130 }; 123 131 132 class TexCodecJpg:ITexCodec { 133 public: 134 virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; 135 virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; 136 virtual Status transform(Tex* t, size_t transforms) const; 137 virtual bool is_hdr(const u8* file) const; 138 virtual bool is_ext(const OsPath& extension) const; 139 virtual size_t hdr_size(const u8* file) const; 140 virtual const wchar_t* get_name() const { 141 static const wchar_t *name = L"jpg"; 142 return name; 143 }; 144 }; 124 145 125 /** 126 * build codec vtbl and register it. the codec will be queried for future 127 * texture load requests. call order is undefined, but since each codec 128 * only steps up if it can handle the given format, this is not a problem. 129 * 130 * @param name identifier of codec (not string!). used to bind 'member' 131 * functions prefixed with it to the vtbl, and as the TexCodecVTbl name. 132 * it should also mirror the default file extension (e.g. dds) - 133 * this is relied upon (but verified) in the self-test. 134 * 135 * usage: at file scope within the source file containing the codec's methods. 136 **/ 137 #define TEX_CODEC_REGISTER(name)\ 138 static TexCodecVTbl UID__ = \ 139 {\ 140 name##_decode, name##_encode, name##_transform,\ 141 name##_is_hdr, name##_is_ext, name##_hdr_size,\ 142 WIDEN(#name)\ 143 };\ 144 /*static int dummy = tex_codec_register(&vtbl);*/\ 145 /* note: when building as a static library, pre-main initializers */\ 146 /* will not run! as a workaround, we build an externally visible */\ 147 /* registration function that must be called via */\ 148 /* tex_codec_register_all - see comments there. */\ 149 void name##_register() { tex_codec_register(&UID__); } 146 class TexCodecDds:ITexCodec { 147 public: 148 virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; 149 virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; 150 virtual Status transform(Tex* t, size_t transforms) const; 151 virtual bool is_hdr(const u8* file) const; 152 virtual bool is_ext(const OsPath& extension) const; 153 virtual size_t hdr_size(const u8* file) const; 154 virtual const wchar_t* get_name() const { 155 static const wchar_t *name = L"dds"; 156 return name; 157 }; 158 }; 150 159 160 class TexCodecTga:ITexCodec { 161 public: 162 virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; 163 virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; 164 virtual Status transform(Tex* t, size_t transforms) const; 165 virtual bool is_hdr(const u8* file) const; 166 virtual bool is_ext(const OsPath& extension) const; 167 virtual size_t hdr_size(const u8* file) const; 168 virtual const wchar_t* get_name() const { 169 static const wchar_t *name = L"tga"; 170 return name; 171 }; 172 }; 151 173 152 /** 153 * add this vtbl to the codec list. called at NLSO init time by the 154 * TEX_CODEC_REGISTER in each codec file. 155 * order in list is unspecified; see TEX_CODEC_REGISTER. 156 * 157 * @param c pointer to vtbl. 158 * @return int (allows calling from a macro at file scope; value is not used) 159 **/ 160 extern int tex_codec_register(TexCodecVTbl* c); 174 class TexCodecBmp:ITexCodec { 175 public: 176 virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; 177 virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; 178 virtual Status transform(Tex* t, size_t transforms) const; 179 virtual bool is_hdr(const u8* file) const; 180 virtual bool is_ext(const OsPath& extension) const; 181 virtual size_t hdr_size(const u8* file) const; 182 virtual const wchar_t* get_name() const { 183 static const wchar_t *name = L"bmp"; 184 return name; 185 }; 186 }; 161 187 162 163 188 /** 164 189 * Find codec that recognizes the desired output file extension. 165 190 * … … 169 194 * called by tex_is_known_extension) if no codec indicates they can 170 195 * handle the given extension. 171 196 **/ 172 extern Status tex_codec_for_filename(const OsPath& extension, const TexCodecVTbl** c);197 extern Status tex_codec_for_filename(const OsPath& extension, const ITexCodec** c); 173 198 174 199 /** 175 200 * find codec that recognizes the header's magic field. … … 181 206 * @return Status; ERR::RES_UNKNOWN_FORMAT if no codec indicates they can 182 207 * handle the given format (header). 183 208 **/ 184 extern Status tex_codec_for_header(const u8* data, size_t data_size, const TexCodecVTbl** c);209 extern Status tex_codec_for_header(const u8* data, size_t data_size, const ITexCodec** c); 185 210 186 211 /** 187 * enumerate all registered codecs.188 *189 * used by self-test to test each one of them in turn.190 *191 * @param prev_codec the last codec returned by this function.192 * pass 0 the first time.193 * note: this routine is stateless and therefore reentrant.194 * @return the next codec, or 0 if all have been returned.195 **/196 extern const TexCodecVTbl* tex_codec_next(const TexCodecVTbl* prev_codec);197 198 /**199 212 * transform the texture's pixel format. 200 213 * tries each codec's transform method once, or until one indicates success. 201 214 * -
source/lib/tex/tex_dds.cpp
586 586 587 587 //----------------------------------------------------------------------------- 588 588 589 static bool dds_is_hdr(const u8* file) 589 bool TexCodecDds::is_hdr(const u8* file) const 590 590 { 591 591 return *(u32*)file == FOURCC('D','D','S',' '); 592 592 } 593 593 594 594 595 static bool dds_is_ext(const OsPath& extension) 595 bool TexCodecDds::is_ext(const OsPath& extension) const 596 596 { 597 597 return extension == L".dds"; 598 598 } 599 599 600 600 601 s tatic size_t dds_hdr_size(const u8* UNUSED(file))601 size_t TexCodecDds::hdr_size(const u8* UNUSED(file)) const 602 602 { 603 603 return 4+sizeof(DDS_HEADER); 604 604 } 605 605 606 606 607 static Status dds_decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t) 607 Status TexCodecDds::decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t) const 608 608 { 609 609 const DDS_HEADER* sd = (const DDS_HEADER*)(data+4); 610 610 RETURN_STATUS_IF_ERR(decode_sd(sd, t->m_Width, t->m_Height, t->m_Bpp, t->m_Flags)); … … 612 612 } 613 613 614 614 615 static Status dds_encode(Tex* RESTRICT UNUSED(t), DynArray* RESTRICT UNUSED(da)) 615 Status TexCodecDds::encode(Tex* RESTRICT UNUSED(t), DynArray* RESTRICT UNUSED(da)) const 616 616 { 617 617 // note: do not return ERR::NOT_SUPPORTED et al. because that would 618 618 // break tex_write (which assumes either this, 0 or errors are returned). … … 622 622 623 623 TIMER_ADD_CLIENT(tc_dds_transform); 624 624 625 static Status dds_transform(Tex* t, size_t transforms) 625 Status TexCodecDds::transform(Tex* t, size_t transforms) const 626 626 { 627 627 TIMER_ACCRUE(tc_dds_transform); 628 628 … … 651 651 // both not DXT (nothing we can do) - bail. 652 652 return INFO::TEX_CODEC_CANNOT_HANDLE; 653 653 } 654 655 656 TEX_CODEC_REGISTER(dds); -
source/lib/tex/tex_jpg.cpp
423 423 //----------------------------------------------------------------------------- 424 424 425 425 426 static Status jpg_transform(Tex* UNUSED(t), size_t UNUSED(transforms)) 426 Status TexCodecJpg::transform(Tex* UNUSED(t), size_t UNUSED(transforms)) const 427 427 { 428 428 return INFO::TEX_CODEC_CANNOT_HANDLE; 429 429 } … … 557 557 558 558 559 559 560 static bool jpg_is_hdr(const u8* file) 560 bool TexCodecJpg::is_hdr(const u8* file) const 561 561 { 562 562 // JFIF requires SOI marker at start of stream. 563 563 // we compare single bytes to be endian-safe. … … 565 565 } 566 566 567 567 568 static bool jpg_is_ext(const OsPath& extension) 568 bool TexCodecJpg::is_ext(const OsPath& extension) const 569 569 { 570 570 return extension == L".jpg" || extension == L".jpeg"; 571 571 } 572 572 573 573 574 s tatic size_t jpg_hdr_size(const u8* UNUSED(file))574 size_t TexCodecJpg::hdr_size(const u8* UNUSED(file)) const 575 575 { 576 576 return 0; // libjpg returns decoded image data; no header 577 577 } 578 578 579 579 580 static Status jpg_decode(rpU8 data, size_t size, Tex* RESTRICT t) 580 Status TexCodecJpg::decode(rpU8 data, size_t size, Tex* RESTRICT t) const 581 581 { 582 582 // contains the JPEG decompression parameters and pointers to 583 583 // working space (allocated as needed by the JPEG library). … … 598 598 599 599 600 600 // limitation: palette images aren't supported 601 static Status jpg_encode(Tex* RESTRICT t, DynArray* RESTRICT da) 601 Status TexCodecJpg::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const 602 602 { 603 603 // contains the JPEG compression parameters and pointers to 604 604 // working space (allocated as needed by the JPEG library). … … 616 616 617 617 return ret; 618 618 } 619 620 TEX_CODEC_REGISTER(jpg); -
source/lib/tex/tex_png.cpp
107 107 108 108 //----------------------------------------------------------------------------- 109 109 110 static Status png_transform(Tex* UNUSED(t), size_t UNUSED(transforms)) 110 Status TexCodecPng::transform(Tex* UNUSED(t), size_t UNUSED(transforms)) const 111 111 { 112 112 return INFO::TEX_CODEC_CANNOT_HANDLE; 113 113 } … … 200 200 201 201 202 202 203 static bool png_is_hdr(const u8* file) 203 bool TexCodecPng::is_hdr(const u8* file) const 204 204 { 205 205 // don't use png_sig_cmp, so we don't pull in libpng for 206 206 // this check alone (it might not actually be used). … … 208 208 } 209 209 210 210 211 static bool png_is_ext(const OsPath& extension) 211 bool TexCodecPng::is_ext(const OsPath& extension) const 212 212 { 213 213 return extension == L".png"; 214 214 } 215 215 216 216 217 s tatic size_t png_hdr_size(const u8* UNUSED(file))217 size_t TexCodecPng::hdr_size(const u8* UNUSED(file)) const 218 218 { 219 219 return 0; // libpng returns decoded image data; no header 220 220 } … … 223 223 TIMER_ADD_CLIENT(tc_png_decode); 224 224 225 225 // limitation: palette images aren't supported 226 static Status png_decode(rpU8 data, size_t size, Tex* RESTRICT t) 226 Status TexCodecPng::decode(rpU8 data, size_t size, Tex* RESTRICT t) const 227 227 { 228 228 TIMER_ACCRUE(tc_png_decode); 229 229 … … 257 257 258 258 259 259 // limitation: palette images aren't supported 260 static Status png_encode(Tex* RESTRICT t, DynArray* RESTRICT da) 260 Status TexCodecPng::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const 261 261 { 262 262 Status ret = ERR::FAIL; 263 263 png_infop info_ptr = 0; … … 284 284 png_destroy_write_struct(&png_ptr, &info_ptr); 285 285 return ret; 286 286 } 287 288 TEX_CODEC_REGISTER(png); -
source/lib/tex/tex_tga.cpp
67 67 #pragma pack(pop) 68 68 69 69 70 static Status tga_transform(Tex* UNUSED(t), size_t UNUSED(transforms)) 70 Status TexCodecTga::transform(Tex* UNUSED(t), size_t UNUSED(transforms)) const 71 71 { 72 72 return INFO::TEX_CODEC_CANNOT_HANDLE; 73 73 } 74 74 75 75 76 static bool tga_is_hdr(const u8* file) 76 bool TexCodecTga::is_hdr(const u8* file) const 77 77 { 78 78 TgaHeader* hdr = (TgaHeader*)file; 79 79 … … 93 93 } 94 94 95 95 96 static bool tga_is_ext(const OsPath& extension) 96 bool TexCodecTga::is_ext(const OsPath& extension) const 97 97 { 98 98 return extension == L".tga"; 99 99 } 100 100 101 101 102 s tatic size_t tga_hdr_size(const u8* file)102 size_t TexCodecTga::hdr_size(const u8* file) const 103 103 { 104 104 size_t hdr_size = sizeof(TgaHeader); 105 105 if(file) … … 112 112 113 113 114 114 // requirements: uncompressed, direct color, bottom up 115 static Status tga_decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t) 115 Status TexCodecTga::decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t) const 116 116 { 117 117 const TgaHeader* hdr = (const TgaHeader*)data; 118 118 const u8 type = hdr->img_type; … … 144 144 } 145 145 146 146 147 static Status tga_encode(Tex* RESTRICT t, DynArray* RESTRICT da) 147 Status TexCodecTga::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const 148 148 { 149 149 u8 img_desc = 0; 150 150 if(t->m_Flags & TEX_TOP_DOWN) … … 173 173 return tex_codec_write(t, transforms, &hdr, hdr_size, da); 174 174 } 175 175 176 TEX_CODEC_REGISTER(tga); -
source/network/tests/test_Net.h
44 44 45 45 // Need some stuff for terrain movement costs: 46 46 // (TODO: this ought to be independent of any graphics code) 47 tex_codec_register_all();48 47 new CTerrainTextureManager; 49 48 g_TexMan.LoadTerrainTextures(); 50 49 … … 56 55 enet_deinitialize(); 57 56 58 57 delete &g_TexMan; 59 tex_codec_unregister_all();60 58 61 59 CXeromyces::Terminate(); 62 60 g_VFS.reset(); -
source/ps/ArchiveBuilder.cpp
36 36 CArchiveBuilder::CArchiveBuilder(const OsPath& mod, const OsPath& tempdir) : 37 37 m_TempDir(tempdir) 38 38 { 39 tex_codec_register_all();40 41 39 m_VFS = CreateVfs(20*MiB); 42 40 43 41 DeleteDirectory(m_TempDir/"_archivecache"); // clean up in case the last run failed … … 55 53 m_VFS.reset(); 56 54 57 55 DeleteDirectory(m_TempDir/"_archivecache"); 58 59 tex_codec_unregister_all();60 56 } 61 57 62 58 void CArchiveBuilder::AddBaseMod(const OsPath& mod) -
source/ps/GameSetup/GameSetup.cpp
682 682 g_VBMan.Shutdown(); 683 683 TIMER_END(L"shutdown Renderer"); 684 684 685 tex_codec_unregister_all();686 687 685 g_Profiler2.ShutdownGPU(); 688 686 689 687 // Free cursors before shutting down SDL, as they may depend on SDL. … … 936 934 937 935 RunHardwareDetection(); 938 936 939 tex_codec_register_all();940 941 937 const int quality = SANE_TEX_QUALITY_DEFAULT; // TODO: set value from config file 942 938 SetTextureQuality(quality); 943 939 -
source/ps/Replay.cpp
134 134 135 135 // Need some stuff for terrain movement costs: 136 136 // (TODO: this ought to be independent of any graphics code) 137 tex_codec_register_all();138 137 new CTerrainTextureManager; 139 138 g_TexMan.LoadTerrainTextures(); 140 139 … … 246 245 247 246 // Clean up 248 247 delete &g_TexMan; 249 tex_codec_unregister_all();250 248 251 249 delete &g_Profiler; 252 250 delete &g_ProfileViewer; -
source/simulation2/components/tests/test_Pathfinder.h
41 41 42 42 // Need some stuff for terrain movement costs: 43 43 // (TODO: this ought to be independent of any graphics code) 44 tex_codec_register_all();45 44 new CTerrainTextureManager; 46 45 g_TexMan.LoadTerrainTextures(); 47 46 } … … 49 48 void tearDown() 50 49 { 51 50 delete &g_TexMan; 52 tex_codec_unregister_all();53 51 54 52 g_VFS.reset(); 55 53 -
source/simulation2/tests/test_Serializer.h
638 638 639 639 // Need some stuff for terrain movement costs: 640 640 // (TODO: this ought to be independent of any graphics code) 641 tex_codec_register_all();642 641 new CTerrainTextureManager; 643 642 g_TexMan.LoadTerrainTextures(); 644 643 … … 685 684 686 685 // Shut down the world 687 686 delete &g_TexMan; 688 tex_codec_unregister_all();689 687 g_VFS.reset(); 690 688 CXeromyces::Terminate(); 691 689 }