Panda3D
texturePeeker.h
Go to the documentation of this file.
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 texturePeeker.h
10  * @author drose
11  * @date 2008-08-26
12  */
13 
14 #ifndef TEXTUREPEEKER_H
15 #define TEXTUREPEEKER_H
16 
17 #include "pandabase.h"
18 
19 #include "referenceCount.h"
20 #include "texture.h"
21 
22 /**
23  * An instance of this object is returned by Texture::peek(). This object
24  * allows quick and easy inspection of a texture's texels by (u, v)
25  * coordinates.
26  */
27 class EXPCL_PANDA_GOBJ TexturePeeker : public ReferenceCount {
28 private:
29  TexturePeeker(Texture *tex, Texture::CData *cdata);
30 
31 public:
32  INLINE bool is_valid() const;
33 
34 PUBLISHED:
35  INLINE int get_x_size() const;
36  INLINE int get_y_size() const;
37  INLINE int get_z_size() const;
38 
39  INLINE bool has_pixel(int x, int y) const;
40  void lookup(LColor &color, PN_stdfloat u, PN_stdfloat v) const;
41  void lookup(LColor &color, PN_stdfloat u, PN_stdfloat v, PN_stdfloat w) const;
42  void fetch_pixel(LColor &color, int x, int y) const;
43  bool lookup_bilinear(LColor &color, PN_stdfloat u, PN_stdfloat v) const;
44  void filter_rect(LColor &color,
45  PN_stdfloat min_u, PN_stdfloat min_v,
46  PN_stdfloat max_u, PN_stdfloat max_v) const;
47  void filter_rect(LColor &color,
48  PN_stdfloat min_u, PN_stdfloat min_v, PN_stdfloat min_w,
49  PN_stdfloat max_u, PN_stdfloat max_v, PN_stdfloat max_w) const;
50 
51 private:
52  static void init_rect_minmax(int &min_x, int &max_x,
53  PN_stdfloat &min_u, PN_stdfloat &max_u,
54  int x_size);
55 
56  void accum_filter_z(LColor &color, PN_stdfloat &net,
57  int min_x, int max_x, PN_stdfloat min_u, PN_stdfloat max_u,
58  int min_y, int max_y, PN_stdfloat min_v, PN_stdfloat max_v,
59  int min_z, int max_z, PN_stdfloat min_w, PN_stdfloat max_w) const;
60  void accum_filter_y(LColor &color, PN_stdfloat &net, int zi,
61  int min_x, int max_x, PN_stdfloat min_u, PN_stdfloat max_u,
62  int min_y, int max_y, PN_stdfloat min_v, PN_stdfloat max_v,
63  PN_stdfloat weight) const;
64  void accum_filter_x(LColor &color, PN_stdfloat &net, int yi, int zi,
65  int min_x, int max_x, PN_stdfloat min_u, PN_stdfloat max_u,
66  PN_stdfloat weight) const;
67  void accum_texel(LColor &color, PN_stdfloat &net, const unsigned char *&p,
68  PN_stdfloat weight) const;
69 
70  typedef double GetComponentFunc(const unsigned char *&p);
71  typedef void GetTexelFunc(LColor &color, const unsigned char *&p,
72  GetComponentFunc *get_component);
73 
74  static void get_texel_r(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
75  static void get_texel_g(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
76  static void get_texel_b(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
77  static void get_texel_a(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
78  static void get_texel_l(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
79  static void get_texel_la(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
80  static void get_texel_rg(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
81  static void get_texel_rgb(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
82  static void get_texel_rgba(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
83  static void get_texel_srgb(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
84  static void get_texel_srgba(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
85 
86  int _x_size;
87  int _y_size;
88  int _z_size;
89  int _component_width;
90  int _num_components;
91  int _pixel_width;
92  Texture::Format _format;
93  Texture::ComponentType _component_type;
94  CPTA_uchar _image;
95 
96  GetComponentFunc *_get_component;
97  GetTexelFunc *_get_texel;
98 
99  friend class Texture;
100 };
101 
102 #include "texturePeeker.I"
103 
104 #endif
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ReferenceCount
A base class for all things that want to be reference-counted.
Definition: referenceCount.h:38
ConstPointerToArray< unsigned char >
Texture
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
referenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
texture.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TexturePeeker
An instance of this object is returned by Texture::peek().
Definition: texturePeeker.h:27
texturePeeker.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.