Panda3D
Loading...
Searching...
No Matches
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 */
27class EXPCL_PANDA_GOBJ TexturePeeker : public ReferenceCount {
28private:
29 TexturePeeker(Texture *tex, Texture::CData *cdata);
30
31public:
32 INLINE bool is_valid() const;
33
34PUBLISHED:
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 INLINE bool has_pixel(int x, int y, int z) const;
41 void lookup(LColor &color, PN_stdfloat u, PN_stdfloat v) const;
42 void lookup(LColor &color, PN_stdfloat u, PN_stdfloat v, PN_stdfloat w) const;
43 void fetch_pixel(LColor &color, int x, int y) const;
44 void fetch_pixel(LColor &color, int x, int y, int z) const;
45 bool lookup_bilinear(LColor &color, PN_stdfloat u, PN_stdfloat v) const;
46 void filter_rect(LColor &color,
47 PN_stdfloat min_u, PN_stdfloat min_v,
48 PN_stdfloat max_u, PN_stdfloat max_v) const;
49 void filter_rect(LColor &color,
50 PN_stdfloat min_u, PN_stdfloat min_v, PN_stdfloat min_w,
51 PN_stdfloat max_u, PN_stdfloat max_v, PN_stdfloat max_w) const;
52
53private:
54 static void init_rect_minmax(int &min_x, int &max_x,
55 PN_stdfloat &min_u, PN_stdfloat &max_u,
56 int x_size);
57
58 void accum_filter_z(LColor &color, PN_stdfloat &net,
59 int min_x, int max_x, PN_stdfloat min_u, PN_stdfloat max_u,
60 int min_y, int max_y, PN_stdfloat min_v, PN_stdfloat max_v,
61 int min_z, int max_z, PN_stdfloat min_w, PN_stdfloat max_w) const;
62 void accum_filter_y(LColor &color, PN_stdfloat &net, int zi,
63 int min_x, int max_x, PN_stdfloat min_u, PN_stdfloat max_u,
64 int min_y, int max_y, PN_stdfloat min_v, PN_stdfloat max_v,
65 PN_stdfloat weight) const;
66 void accum_filter_x(LColor &color, PN_stdfloat &net, int yi, int zi,
67 int min_x, int max_x, PN_stdfloat min_u, PN_stdfloat max_u,
68 PN_stdfloat weight) const;
69 void accum_texel(LColor &color, PN_stdfloat &net, const unsigned char *&p,
70 PN_stdfloat weight) const;
71
72 typedef double GetComponentFunc(const unsigned char *&p);
73 typedef void GetTexelFunc(LColor &color, const unsigned char *&p,
74 GetComponentFunc *get_component);
75
76 static void get_texel_r(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
77 static void get_texel_g(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
78 static void get_texel_b(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
79 static void get_texel_a(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
80 static void get_texel_l(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
81 static void get_texel_la(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
82 static void get_texel_rg(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
83 static void get_texel_rgb(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
84 static void get_texel_rgba(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
85 static void get_texel_srgb(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
86 static void get_texel_srgba(LColor &color, const unsigned char *&p, GetComponentFunc *get_component);
87
88 int _x_size;
89 int _y_size;
90 int _z_size;
91 int _is_cube;
92 int _unused1;
93 int _pixel_width;
94 Texture::Format _format;
95 Texture::ComponentType _component_type;
96 CPTA_uchar _image;
97
98 GetComponentFunc *_get_component;
99 GetTexelFunc *_get_texel;
100
101 friend class Texture;
102};
103
104#include "texturePeeker.I"
105
106#endif
int get_y_size() const
Returns the height of the texture image that is contributing to the TexturePeeker's information.
void lookup(LColor &color, PN_stdfloat u, PN_stdfloat v) const
Fills "color" with the RGBA color of the texel at point (u, v).
int get_z_size() const
Returns the depth of the texture image that is contributing to the TexturePeeker's information.
bool is_valid() const
Returns true if the TexturePeeker was able to initialize itself and is ready to return texel colors.
void fetch_pixel(LColor &color, int x, int y) const
Works like TexturePeeker::lookup(), but instead of uv-coordinates, integer coordinates are used.
bool has_pixel(int x, int y) const
Returns whether a given coordinate is inside of the texture dimensions.
int get_x_size() const
Returns the width of the texture image that is contributing to the TexturePeeker's information.
bool lookup_bilinear(LColor &color, PN_stdfloat u, PN_stdfloat v) const
Performs a bilinear lookup to retrieve the color value stored at the uv coordinate (u,...
void filter_rect(LColor &color, PN_stdfloat min_u, PN_stdfloat min_v, PN_stdfloat max_u, PN_stdfloat max_v) const
Fills "color" with the average RGBA color of the texels within the rectangle defined by the specified...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.