TImage.cxx

Go to the documentation of this file.
00001 // @(#)root/graf:$Id: TImage.cxx 30544 2009-10-02 15:33:12Z couet $
00002 // Author: Fons Rademakers   15/10/2001
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TImage.h"
00013 #include "TROOT.h"
00014 #include "TPluginManager.h"
00015 #include "TApplication.h"
00016 #include "TSystem.h"
00017 
00018 ClassImp(TImage)
00019 
00020 
00021 //______________________________________________________________________________
00022 /* Begin_Html
00023 <center><h2>Image class</h2></center>
00024 TImage is an abstract interface to image processing library.
00025 It allows for the reading and writing of images in different formats, several
00026 image manipulations (scaling, tiling, merging, etc.) and displaying in pads.
00027 <p>
00028 The concrete implementation of this class is done by the
00029 <a href="http://root.cern.ch/root/html/TASImage.html">TASImage</a> class. The 
00030 methods are documented in that class.
00031 End_Html */
00032 
00033 
00034 //______________________________________________________________________________
00035 TImage *TImage::Create()
00036 {
00037    // Create an image.
00038    // Use ReadImage() or SetImage() to initialize the image.
00039 
00040    static TPluginHandler *h = 0;
00041 
00042    if (!h) {
00043       h = gROOT->GetPluginManager()->FindHandler("TImage");
00044       if (!h) return 0;
00045       if (h->LoadPlugin() == -1) {
00046          h = 0;   // try to reload plugin next time
00047          return 0;
00048       }
00049    }
00050    TImage *img = (TImage *) h->ExecPlugin(0);
00051    if (img) img->SetName("dummy_image");
00052 
00053    return img;
00054 }
00055 
00056 
00057 //______________________________________________________________________________
00058 TImage::EImageFileTypes TImage::GetImageFileTypeFromFilename(const char* filename)
00059 {
00060    // Return the image type for the extension specified in filename.
00061    // Case of the extension is ignored. E.g. for a filename "myimg.GIF",
00062    // kGif is returned.
00063    // kAnimGif is returned if the file extension is ".anim.gif".
00064 
00065    if (!filename) return kUnknown;
00066 
00067    TString sFilename(filename);
00068    if (sFilename.EndsWith(".xpm.gz", TString::kIgnoreCase))
00069       return kGZCompressedXpm;
00070    else if (sFilename.EndsWith(".xpm.z", TString::kIgnoreCase))
00071       return kZCompressedXpm;
00072    else if (sFilename.EndsWith(".png", TString::kIgnoreCase))
00073       return kPng;
00074    else if (sFilename.EndsWith(".jpeg", TString::kIgnoreCase))
00075       return kJpeg;
00076    else if (sFilename.EndsWith(".jpg", TString::kIgnoreCase))
00077       return kJpeg;
00078    else if (sFilename.EndsWith(".xcf", TString::kIgnoreCase))
00079       return kXcf;
00080    else if (sFilename.EndsWith(".ppm", TString::kIgnoreCase))
00081       return kPpm;
00082    else if (sFilename.EndsWith(".pnm", TString::kIgnoreCase))
00083       return kPnm;
00084    else if (sFilename.EndsWith(".bmp", TString::kIgnoreCase))
00085       return kBmp;
00086    else if (sFilename.EndsWith(".ico", TString::kIgnoreCase))
00087       return kIco;
00088    else if (sFilename.EndsWith(".cur", TString::kIgnoreCase))
00089       return kCur;
00090    else if (sFilename.EndsWith(".gif", TString::kIgnoreCase))
00091       return kGif;
00092    else if (sFilename.EndsWith(".tiff", TString::kIgnoreCase))
00093       return kTiff;
00094    else if (sFilename.EndsWith(".tif", TString::kIgnoreCase))
00095       return kTiff;
00096    else if (sFilename.EndsWith(".xbm", TString::kIgnoreCase))
00097       return kXbm;
00098    else if (sFilename.EndsWith(".fits", TString::kIgnoreCase))
00099       return kFits;
00100    else if (sFilename.EndsWith(".tga", TString::kIgnoreCase))
00101       return kTga;
00102    else if (sFilename.EndsWith(".xml", TString::kIgnoreCase))
00103       return kXml;
00104    else if (sFilename.EndsWith(".anim.gif", TString::kIgnoreCase))
00105       return kAnimGif;
00106 
00107    return kUnknown;
00108 }
00109 
00110 
00111 //______________________________________________________________________________
00112 TImage *TImage::Open(const char *file, EImageFileTypes type)
00113 {
00114    // Open a specified image file.
00115 
00116    TImage *img = Create();
00117    char *fullname = gSystem->ExpandPathName(file);
00118 
00119    if (img)
00120       img->ReadImage(fullname, type);
00121 
00122    delete [] fullname;
00123 
00124    return img;
00125 }
00126 
00127 
00128 //______________________________________________________________________________
00129 TImage *TImage::Open(const char *name, const Double_t *imageData, UInt_t width,
00130                      UInt_t height, TImagePalette *palette)
00131 {
00132    // Open an image with the specified data in a Double_t array.
00133 
00134    TImage *img = Create();
00135 
00136    if (img) {
00137       img->SetImage(imageData, width, height, palette);
00138       img->SetName(name);
00139    }
00140    return img;
00141 }
00142 
00143 
00144 //______________________________________________________________________________
00145 TImage *TImage::Open(const char *name, const TArrayD &imageData, UInt_t width,
00146                      TImagePalette *palette)
00147 {
00148    // Open an image with the specified data in a TArrayD.
00149 
00150    TImage *img = Create();
00151 
00152    if (img) {
00153       img->SetImage(imageData, width, palette);
00154       img->SetName(name);
00155    }
00156    return img;
00157 }
00158 
00159 
00160 //______________________________________________________________________________
00161 TImage *TImage::Open(const char *name, const TVectorD &imageData, UInt_t width,
00162                      TImagePalette *palette)
00163 {
00164    // Open an image with the specified data in a TVectorD.
00165 
00166    TImage *img = Create();
00167 
00168    if (img) {
00169       img->SetImage(imageData, width, palette);
00170       img->SetName(name);
00171    }
00172    return img;
00173 }
00174 
00175 
00176 //______________________________________________________________________________
00177 TImage *TImage::Open(char **data)
00178 {
00179    // Create image from XPM data array.
00180 
00181    TImage *img = Create();
00182 
00183    if (img) {
00184       img->SetImageBuffer(data, TImage::kXpm);
00185       img->SetName("XPM_image");
00186    }
00187    return img;
00188 }
00189 
00190 
00191 TImage operator+(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "+"); return ret; }
00192 TImage operator/(const TImage &i1, const TImage &i2) { TImage ret(i1); ret.Append(&i2, "/"); return ret; }

Generated on Tue Jul 5 14:14:27 2011 for ROOT_528-00b_version by  doxygen 1.5.1