Panda3D
 All Classes Functions Variables Enumerations
pnmFileTypeAndroid.h
1 // Filename: pnmFileTypeAndroid.h
2 // Created by: rdb (11Jan13)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PNMFILETYPEANDROID_H
16 #define PNMFILETYPEANDROID_H
17 
18 #ifdef ANDROID
19 
20 #include "pandabase.h"
21 
22 #include "pnmFileType.h"
23 #include "pnmReader.h"
24 #include "pnmWriter.h"
25 
26 #include <jni.h>
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : PNMFileTypeAndroid
30 // Description : Wrapper class around the Android Bitmap mechanism
31 // to allow loading images on Android without needing
32 // libpng or libjpeg.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeAndroid : public PNMFileType {
35 public:
36  PNMFileTypeAndroid();
37 
38  virtual string get_name() const;
39 
40  virtual int get_num_extensions() const;
41  virtual string get_extension(int n) const;
42 
43  virtual bool has_magic_number() const;
44 
45  virtual PNMReader *make_reader(istream *file, bool owns_file = true,
46  const string &magic_number = string());
47 
48 public:
49  class Reader : public PNMReader {
50  public:
51  Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
52  virtual ~Reader();
53 
54  virtual void prepare_read();
55  virtual int read_data(xel *array, xelval *alpha);
56 
57  private:
58  // It is assumed that the Reader is only used within a single thread.
59  JNIEnv *_env;
60  jobject _bitmap;
61  int _sample_size;
62  uint32_t _stride;
63  int32_t _format;
64  };
65 
66  // The TypedWritable interface follows.
67 public:
68  static void register_with_read_factory();
69 
70 protected:
71  static TypedWritable *make_PNMFileTypeAndroid(const FactoryParams &params);
72 
73 public:
74  static TypeHandle get_class_type() {
75  return _type_handle;
76  }
77  static void init_type() {
78  PNMFileType::init_type();
79  register_type(_type_handle, "PNMFileTypeAndroid",
80  PNMFileType::get_class_type());
81  }
82  virtual TypeHandle get_type() const {
83  return get_class_type();
84  }
85  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
86 
87 private:
88  static TypeHandle _type_handle;
89 };
90 
91 #endif // ANDROID
92 
93 #endif
virtual string get_extension(int n) const
Returns the nth possible filename extension associated with this particular file type, without a leading dot.
Definition: pnmFileType.cxx:62
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:35
virtual int get_num_extensions() const
Returns the number of different possible filename extensions associated with this particular file typ...
Definition: pnmFileType.cxx:50
virtual PNMReader * make_reader(istream *file, bool owns_file=true, const string &magic_number=string())
Allocates and returns a new PNMReader suitable for reading from this file type, if possible...
virtual bool has_magic_number() const
Returns true if this particular file type uses a magic number to identify it, false otherwise...
Definition: pnmFileType.cxx:89
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This is an abstract base class that defines the interface for reading image files of various types...
Definition: pnmReader.h:31
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85