ROOT logo
// $Id: ZImage.h 2417 2010-07-24 11:31:48Z matevz $

// Copyright (C) 1999-2008, Matevz Tadel. All rights reserved.
// This file is part of GLED, released under GNU General Public License version 2.
// For the licensing terms see $GLEDSYS/LICENSE or http://www.gnu.org/.

#ifndef Geom1_ZImage_H
#define Geom1_ZImage_H

#include <Glasses/ZGlass.h>
#include <Stones/ZColor.h>

#ifndef __CINT__
#include <IL/il.h>
#include <IL/ilu.h>
#else
typedef unsigned int ILuint;
#endif

class ZImage : public ZGlass
{
  // 7777 AddViewInclude(GL/glew.h)
  // 7777 RnrCtrl(RnrBits(0,4,0,0))
  MAC_RNR_FRIENDS(ZImage);

private:
  void _init();

  void _setup() { m_data = (UChar_t*)data(); m_bpp = bpp(); }
  void _reset() { m_data = 0;      m_bpp = 0; }
  UChar_t      *m_data;		//!
  Int_t         m_bpp;          //!

  ILuint	mIL_Name;	//! X{gp}

protected:

  TString	mFile;		//  X{GS}  7 Filor()
  Int_t		mW;		//  X{G}   7 ValOut(-join=>1)
  Int_t		mH;		//  X{G}   7 ValOut()

  Int_t		mImgFmt;	//  X{GS}  7 PhonyEnum(-const=>1, -join=>1, -vals=>[0,"undef", GL_COLOR_INDEX,col_index, GL_RGB,rgb, GL_RGBA,rgba, GL_BGR,bgr, GL_BGRA,bgra, GL_RED,red, GL_GREEN,green, GL_BLUE,blue, GL_ALPHA,alpha, GL_LUMINANCE,lum, GL_LUMINANCE_ALPHA,lum_alpha, GL_DEPTH_COMPONENT,depth_comp])
  Int_t		mImgTyp;	//  X{GS}  7 PhonyEnum(-const=>1, -join=>1, -vals=>[0,"undef", GL_BYTE,"byte", GL_UNSIGNED_BYTE,"ubyte", GL_SHORT,"short", GL_UNSIGNED_SHORT,"ushort", GL_INT,"int", GL_UNSIGNED_INT,"uint", GL_FLOAT,"float", GL_DOUBLE,"double"])
  Int_t		mIntFmt;	//  X{GS}  7 PhonyEnum(-vals=>[GL_ALPHA4,alpha4, GL_ALPHA8,alpha8, GL_ALPHA12,alpha12, GL_ALPHA16,alpha16, GL_LUMINANCE4,lum4, GL_LUMINANCE8,lum8, GL_LUMINANCE12,lum12, GL_LUMINANCE16,lum16, GL_LUMINANCE4_ALPHA4,lum4_alpha4, GL_LUMINANCE6_ALPHA2,lum6_alpha2, GL_LUMINANCE8_ALPHA8,lum8_alpha8, GL_LUMINANCE12_ALPHA4,lum12_alpha4, GL_LUMINANCE12_ALPHA12,lum12_alpha12, GL_LUMINANCE16_ALPHA16,lum16_alpha16, GL_INTENSITY,"int", GL_INTENSITY4,int4, GL_INTENSITY8,int8, GL_INTENSITY12,int12, GL_INTENSITY16,int16, GL_R3_G3_B2,r3_g3_b2, GL_RGB4,rgb4, GL_RGB5,rgb5, GL_RGB8,rgb8, GL_RGB10,rgb10, GL_RGB12,rgb12, GL_RGB16,rgb16, GL_RGBA2,rgba2, GL_RGBA4,rgba4, GL_RGB5_A1,rgb5_a1, GL_RGBA8,rgba8, GL_RGB10_A2,rgb10_a2, GL_RGBA12,rgba12, GL_RGBA16,rgba16])

  Int_t         mSWrap;         //  X{GST} 7 PhonyEnum(-vals=>[GL_CLAMP,Clamp, GL_CLAMP_TO_EDGE,ClampEdge, GL_REPEAT,Repeat], -width=>8, -join=>1)
  Int_t         mTWrap;         //  X{GST} 7 PhonyEnum(-vals=>[GL_CLAMP,Clamp, GL_CLAMP_TO_EDGE,ClampEdge, GL_REPEAT,Repeat], -width=>8)

  Int_t		mMagFilter;	//  X{GST} 7 PhonyEnum(-vals=>[GL_NEAREST,Nearest, GL_LINEAR,Linear], -width=>8, -join=>1)
  Int_t		mMinFilter;	//  X{GST} 7 PhonyEnum(-vals=>[GL_NEAREST,Nearest, GL_LINEAR,Linear, GL_NEAREST_MIPMAP_NEAREST,NearestMipmapNearest, GL_LINEAR_MIPMAP_NEAREST,LinearMipmapNearest, GL_NEAREST_MIPMAP_LINEAR,NearestMipmapLinear, GL_LINEAR_MIPMAP_LINEAR,LinearMipmapLinear], -width=>14)

  Int_t		mEnvMode;	//  X{GS}  7 PhonyEnum(-vals=>[GL_DECAL,Decal, GL_REPLACE,Replace, GL_MODULATE,Modulate, GL_BLEND,Blend], -width=>8, -join=>1)
  ZColor	mEnvColor;	//  X{PGS} 7 ColorButt(-width=>8)

  Bool_t	bLoadAdEnlight; //  X{GS}  7 Bool(-join=>1)
  Bool_t        bLoadAdBind;    //  X{GS}  7 Bool()
  Bool_t	bUseShadowing;  //  X{GE}  7 Bool(-join=>1)
  Bool_t        bSmartShadow;   //  X{GS}  7 Bool()
  Bool_t	bLoaded;	//! X{G}   7 BoolOut(-join=>1)
  Bool_t	bShadowed;	//! X{G}   7 BoolOut()

  ZColor        mClearColor;    //  X{PGS} 7 ColorButt()

  void shadow_check(const Exc_t& eh);

public:
  ZImage(const Text_t* n="ZImage", const Text_t* t=0) : ZGlass(n,t) { _init(); }
  virtual ~ZImage();

  virtual void AdEnlightenment();

  void SetUseShadowing(Bool_t useshadowing);

  void Load();    // X{E} 7 MButt(-join=>1)
  void Unload();  // X{E} 7 MButt(-join=>1)
  void Save(const Text_t* file=0); // X{E} 7 MCWButt()

  Bool_t IsBindable();

  void BlurAverage(UInt_t count=1);       // X{E} 7 MCWButt(-join=>1)
  void BlurGaussian(UInt_t count=1);      // X{E} 7 MCWButt()
  void Contrastify(Float_t contrast=1.1); // X{E} 7 MCWButt(-join=>1)
  void Equalize();                        // X{E} 7 MButt()
  void Rotate(Float_t angle=90);          // X{E} 7 MCWButt(-join=>1)
  void Mirror();                          // X{E} 7 MButt()

  void SetupAsCanvas(Int_t w=256, Int_t h=256,
		     Int_t bpp=1, Bool_t clear_p=true); // X{E} 7 MCWButt()
  void Diagonal(Float_t r=1, Float_t g=1, Float_t b=1); // X{E} 7 MCWButt()

  // Image operations ... locking is user's responsibility
  void  bind();
  void  unbind();
  void	shadow();
  void  delete_image();
  bool  load_image();
  void  create_image(Int_t w, Int_t h, Int_t bpp);

  int	w();
  int	h();
  void* data();
  int   bpp();
  int   gl_format();
  int   gl_type();

  static GMutex sILMutex;
  static Bool_t sVerboseLoad; //! X{GS} 7 Bool()


  //--------------------------------
  // Low-level pixel control.
  //--------------------------------

  void set_byte(Int_t x, Int_t y, UChar_t w)  { m_data[y*mH + x] = w; }
  void get_byte(Int_t x, Int_t y, UChar_t& w) { w = m_data[y*mH + x]; }

  void set_short(Int_t x, Int_t y, UShort_t w)  { ((UShort_t*)m_data)[y*mH + x] = w; }
  void get_short(Int_t x, Int_t y, UShort_t& w) { w = ((UShort_t*)m_data)[y*mH + x]; }

  void set_rgb(Int_t x, Int_t y, UChar_t r, UChar_t g, UChar_t b)    { UChar_t*p = &m_data[m_bpp*(y*mH + x)]; *p++=r; *p++=g; *p++=b; }
  void get_rgb(Int_t x, Int_t y, UChar_t& r, UChar_t& g, UChar_t& b) { UChar_t*p = &m_data[m_bpp*(y*mH + x)]; r=*p++; g=*p++; b=*p++; }

  void set_rgba(Int_t x, Int_t y, UChar_t r, UChar_t g, UChar_t b, UChar_t a)     { UChar_t*p = &m_data[m_bpp*(y*mH + x)]; *p++=r; *p++=g; *p++=b; *p++=a; }
  void get_rgba(Int_t x, Int_t y, UChar_t& r, UChar_t& g, UChar_t& b, UChar_t& a) { UChar_t*p = &m_data[m_bpp*(y*mH + x)]; r=*p++; g=*p++; b=*p++; a=*p++; }

  void set_pixel(Int_t x, Int_t y, Float_t w);
  void get_pixel(Int_t x, Int_t y, Float_t& w);
  void set_pixel(Int_t x, Int_t y, Float_t r, Float_t g, Float_t b);
  void get_pixel(Int_t x, Int_t y, Float_t& r, Float_t& g, Float_t& b);
  void set_pixel(Int_t x, Int_t y, Float_t r, Float_t g, Float_t b, Float_t a);
  void get_pixel(Int_t x, Int_t y, Float_t& r, Float_t& g, Float_t& b, Float_t& a);

  void add_pixel(Int_t x, Int_t y, Float_t w, Bool_t clip=true);
  void add_pixel(Int_t x, Int_t y, Float_t r, Float_t g, Float_t b, Bool_t clip=true);
  void add_pixel(Int_t x, Int_t y, Float_t r, Float_t g, Float_t b, Float_t a, Bool_t clip=true);

  void inc_pixel(Int_t x, Int_t y, Bool_t clip=true);
  void inc_pixel_idx(Int_t idx, Int_t x, Int_t y, Bool_t clip=true);

#include "ZImage.h7"
  ClassDef(ZImage, 1);
}; // endclass ZImage


#endif
 ZImage.h:1
 ZImage.h:2
 ZImage.h:3
 ZImage.h:4
 ZImage.h:5
 ZImage.h:6
 ZImage.h:7
 ZImage.h:8
 ZImage.h:9
 ZImage.h:10
 ZImage.h:11
 ZImage.h:12
 ZImage.h:13
 ZImage.h:14
 ZImage.h:15
 ZImage.h:16
 ZImage.h:17
 ZImage.h:18
 ZImage.h:19
 ZImage.h:20
 ZImage.h:21
 ZImage.h:22
 ZImage.h:23
 ZImage.h:24
 ZImage.h:25
 ZImage.h:26
 ZImage.h:27
 ZImage.h:28
 ZImage.h:29
 ZImage.h:30
 ZImage.h:31
 ZImage.h:32
 ZImage.h:33
 ZImage.h:34
 ZImage.h:35
 ZImage.h:36
 ZImage.h:37
 ZImage.h:38
 ZImage.h:39
 ZImage.h:40
 ZImage.h:41
 ZImage.h:42
 ZImage.h:43
 ZImage.h:44
 ZImage.h:45
 ZImage.h:46
 ZImage.h:47
 ZImage.h:48
 ZImage.h:49
 ZImage.h:50
 ZImage.h:51
 ZImage.h:52
 ZImage.h:53
 ZImage.h:54
 ZImage.h:55
 ZImage.h:56
 ZImage.h:57
 ZImage.h:58
 ZImage.h:59
 ZImage.h:60
 ZImage.h:61
 ZImage.h:62
 ZImage.h:63
 ZImage.h:64
 ZImage.h:65
 ZImage.h:66
 ZImage.h:67
 ZImage.h:68
 ZImage.h:69
 ZImage.h:70
 ZImage.h:71
 ZImage.h:72
 ZImage.h:73
 ZImage.h:74
 ZImage.h:75
 ZImage.h:76
 ZImage.h:77
 ZImage.h:78
 ZImage.h:79
 ZImage.h:80
 ZImage.h:81
 ZImage.h:82
 ZImage.h:83
 ZImage.h:84
 ZImage.h:85
 ZImage.h:86
 ZImage.h:87
 ZImage.h:88
 ZImage.h:89
 ZImage.h:90
 ZImage.h:91
 ZImage.h:92
 ZImage.h:93
 ZImage.h:94
 ZImage.h:95
 ZImage.h:96
 ZImage.h:97
 ZImage.h:98
 ZImage.h:99
 ZImage.h:100
 ZImage.h:101
 ZImage.h:102
 ZImage.h:103
 ZImage.h:104
 ZImage.h:105
 ZImage.h:106
 ZImage.h:107
 ZImage.h:108
 ZImage.h:109
 ZImage.h:110
 ZImage.h:111
 ZImage.h:112
 ZImage.h:113
 ZImage.h:114
 ZImage.h:115
 ZImage.h:116
 ZImage.h:117
 ZImage.h:118
 ZImage.h:119
 ZImage.h:120
 ZImage.h:121
 ZImage.h:122
 ZImage.h:123
 ZImage.h:124
 ZImage.h:125
 ZImage.h:126
 ZImage.h:127
 ZImage.h:128
 ZImage.h:129
 ZImage.h:130
 ZImage.h:131
 ZImage.h:132
 ZImage.h:133
 ZImage.h:134
 ZImage.h:135
 ZImage.h:136
 ZImage.h:137
 ZImage.h:138
 ZImage.h:139
 ZImage.h:140
 ZImage.h:141
 ZImage.h:142
 ZImage.h:143
 ZImage.h:144
 ZImage.h:145