pnmFileTypeAndroid.cxx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file pnmFileTypeAndroid.cxx
  10. * @author rdb
  11. * @date 2013-01-11
  12. */
  13. #include "pnmFileTypeAndroid.h"
  14. #ifdef ANDROID
  15. #include "config_pnmimagetypes.h"
  16. /**
  17. *
  18. */
  19. PNMFileTypeAndroid::
  20. PNMFileTypeAndroid(CompressFormat format) : _format(format) {
  21. }
  22. /**
  23. * Returns a few words describing the file type.
  24. */
  25. std::string PNMFileTypeAndroid::
  26. get_name() const {
  27. return "Android Bitmap";
  28. }
  29. /**
  30. * Returns the number of different possible filename extensions associated
  31. * with this particular file type.
  32. */
  33. int PNMFileTypeAndroid::
  34. get_num_extensions() const {
  35. switch (_format) {
  36. case CF_jpeg:
  37. return 3;
  38. case CF_png:
  39. return 1;
  40. case CF_webp:
  41. return 1;
  42. default:
  43. return 0;
  44. }
  45. }
  46. /**
  47. * Returns the nth possible filename extension associated with this particular
  48. * file type, without a leading dot.
  49. */
  50. std::string PNMFileTypeAndroid::
  51. get_extension(int n) const {
  52. static const char *const jpeg_extensions[] = {"jpg", "jpeg", "jpe"};
  53. switch (_format) {
  54. case CF_jpeg:
  55. return jpeg_extensions[n];
  56. case CF_png:
  57. return "png";
  58. case CF_webp:
  59. return "webp";
  60. default:
  61. return 0;
  62. }
  63. }
  64. /**
  65. * Returns true if this particular file type uses a magic number to identify
  66. * it, false otherwise.
  67. */
  68. bool PNMFileTypeAndroid::
  69. has_magic_number() const {
  70. return false;
  71. }
  72. /**
  73. * Allocates and returns a new PNMReader suitable for reading from this file
  74. * type, if possible. If reading from this file type is not supported,
  75. * returns NULL.
  76. */
  77. PNMReader *PNMFileTypeAndroid::
  78. make_reader(std::istream *file, bool owns_file, const std::string &magic_number) {
  79. return new Reader(this, file, owns_file, magic_number);
  80. }
  81. /**
  82. * Allocates and returns a new PNMWriter suitable for reading from this file
  83. * type, if possible. If writing files of this type is not supported, returns
  84. * NULL.
  85. */
  86. PNMWriter *PNMFileTypeAndroid::
  87. make_writer(std::ostream *file, bool owns_file) {
  88. return new Writer(this, file, owns_file, _format);
  89. }
  90. #endif // ANDROID