File: crn_texture_file_types.cpp

package info (click to toggle)
crunch-dxtc 0.55.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,600 kB
  • sloc: cpp: 64,979; ansic: 633; python: 321; makefile: 112
file content (103 lines) | stat: -rw-r--r-- 2,216 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// File: crn_texture_file_types.cpp
// See Copyright Notice and license at the end of inc/crnlib.h
#include "crn_core.h"
#include "crn_texture_file_types.h"
#include "crn_file_utils.h"

namespace crnlib {
const char* texture_file_types::get_extension(format fmt) {
  CRNLIB_ASSERT(fmt < cNumFileFormats);
  if (fmt >= cNumFileFormats)
    return NULL;

  static const char* extensions[cNumFileFormats] =
      {
          "dds",
          "crn",
          "ktx",

          "tga",
          "png",
          "jpg",
          "jpeg",
          "bmp",
          "gif",
          "tif",
          "tiff",
          "ppm",
          "pgm",
          "psd",
          "jp2",

          "<clipboard>",
          "<dragdrop>"};
  return extensions[fmt];
}

texture_file_types::format texture_file_types::determine_file_format(const char* pFilename) {
  dynamic_string ext;
  if (!file_utils::split_path(pFilename, NULL, NULL, NULL, &ext))
    return cFormatInvalid;

  if (ext.is_empty())
    return cFormatInvalid;

  if (ext[0] == '.')
    ext.right(1);

  for (uint i = 0; i < cNumFileFormats; i++)
    if (ext == get_extension(static_cast<format>(i)))
      return static_cast<format>(i);

  return cFormatInvalid;
}

bool texture_file_types::supports_mipmaps(format fmt) {
  switch (fmt) {
    case cFormatCRN:
    case cFormatDDS:
    case cFormatKTX:
      return true;
    default:
      break;
  }

  return false;
}

bool texture_file_types::supports_alpha(format fmt) {
  switch (fmt) {
    case cFormatJPG:
    case cFormatJPEG:
    case cFormatGIF:
    case cFormatJP2:
      return false;
    default:
      break;
  }

  return true;
}

const char* get_texture_type_desc(texture_type t) {
  switch (t) {
    case cTextureTypeUnknown:
      return "Unknown";
    case cTextureTypeRegularMap:
      return "2D map";
    case cTextureTypeNormalMap:
      return "Normal map";
    case cTextureTypeVerticalCrossCubemap:
      return "Vertical Cross Cubemap";
    case cTextureTypeCubemap:
      return "Cubemap";
    default:
      break;
  }

  CRNLIB_ASSERT(false);

  return "?";
}

}  // namespace crnlib