Logo ROOT   6.08/02
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TASImage.cxx
Go to the documentation of this file.
1 // @(#)root/asimage:$Id: TASImage.cxx,v 1.54 2006/03/13 15:18:56 rdm E
2 // Author: Fons Rademakers, Reiner Rohlfs, Valeriy Onuchin 28/11/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /**************************************************************************
13  * Some parts of this source are based on libAfterImage 2.00.00
14  * (http://www.afterstep.org/)
15  *
16  * Copyright (c) 2002 Sasha Vasko <sasha@aftercode.net>
17  * Copyright (c) 1998, 1999 Ethan Fischer <allanon@crystaltokyo.com>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU Library General Public License as
21  * published by the Free Software Foundation; either version 2 of the
22  * License, or (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU Library General Public
30  * License along with this program; if not, write to the Free Software
31  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32  *
33  **************************************************************************/
34 
35 /** \class TASImage
36 \ingroup asimage
37 
38 Image class.
39 
40 TASImage is the concrete interface to the image processing library
41 libAfterImage.
42 
43 It allows reading and writing of images in different formats, several image
44 manipulations (scaling, tiling, merging, etc.) and displaying in pads. The size
45 of the image on the screen does not depend on the original size of the image but
46 on the size of the pad. Therefore it is very easy to resize the image on the
47 screen by resizing the pad.
48 
49 Besides reading an image from a file an image can be defined by a two
50 dimensional array of values. A palette defines the color of each value.
51 
52 The image can be zoomed by defining a rectangle with the mouse. The color
53 palette can be modified with a GUI, just select StartPaletteEditor() from the
54 context menu.
55 
56 Several examples showing how to use this class are available in the
57 ROOT tutorials: `$ROOTSYS/tutorials/image/`
58 */
59 
60 # include <ft2build.h>
61 # include FT_FREETYPE_H
62 # include FT_GLYPH_H
63 #include "TASImage.h"
64 #include "TASImagePlugin.h"
65 #include "TROOT.h"
66 #include "TMath.h"
67 #include "TSystem.h"
68 #include "TVirtualX.h"
69 #include "TVirtualPad.h"
70 #include "TArrayD.h"
71 #include "TVectorD.h"
72 #include "TVirtualPS.h"
73 #include "TGaxis.h"
74 #include "TColor.h"
75 #include "TObjArray.h"
76 #include "TArrayL.h"
77 #include "TPoint.h"
78 #include "TFrame.h"
79 #include "TTF.h"
80 #include "TRandom.h"
81 #include "Riostream.h"
82 #include "THashTable.h"
83 #include "TPluginManager.h"
84 #include "TEnv.h"
85 #include "TStyle.h"
86 #include "TText.h"
87 #include "RConfigure.h"
88 #include "TVirtualPadPainter.h"
89 
90 #ifndef WIN32
91 #ifndef R__HAS_COCOA
92 # include <X11/Xlib.h>
93 #endif
94 #else
95 # include "Windows4root.h"
96 #endif
97 extern "C" {
98 #ifndef WIN32
99 #ifdef R__HAS_COCOA
100 # define X_DISPLAY_MISSING 1
101 #endif
102 # include <afterbase.h>
103 #else
104 # include <win32/config.h>
105 # include <win32/afterbase.h>
106 # define X_DISPLAY_MISSING 1
107 #endif
108 # include <afterimage.h>
109 # include <bmp.h>
110 # include <draw.h>
111 }
112 
113 #include <fontconfig/fontconfig.h>
114 
115 // auxiliary functions for general polygon filling
116 #include "TASPolyUtils.c"
117 
118 
119 ASVisual *TASImage::fgVisual = 0;
121 
122 static ASFontManager *gFontManager = 0;
123 static unsigned long kAllPlanes = ~0;
125 
126 // default icon paths
127 static char *gIconPaths[7] = {0, 0, 0, 0, 0, 0, 0};
128 
129 ///////////////////////////// alpha-blending macros ///////////////////////////////
130 
131 #if defined(__GNUC__) && __GNUC__ >= 4 && ((__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ >= 1) || (__GNUC_MINOR__ >= 3)) && !__INTEL_COMPILER
132 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
133 #endif
134 
135 #ifdef R__BYTESWAP
136 typedef struct {
137  unsigned char b;
138  unsigned char g;
139  unsigned char r;
140  unsigned char a;
141 } __argb32__;
142 #else
143 typedef struct {
144  unsigned char a;
145  unsigned char r;
146  unsigned char g;
147  unsigned char b;
148 } __argb32__;
149 #endif
150 
151 
152 //______________________________________________________________________________
153 #define _alphaBlend(bot, top) {\
154  __argb32__ *T = (__argb32__*)(top);\
155  __argb32__ *B = (__argb32__*)(bot);\
156  int aa = 255-T->a;\
157  if (!aa) {\
158  *bot = *top;\
159  } else { \
160  B->a = ((B->a*aa)>>8) + T->a;\
161  B->r = (B->r*aa + T->r*T->a)>>8;\
162  B->g = (B->g*aa + T->g*T->a)>>8;\
163  B->b = (B->b*aa + T->b*T->a)>>8;\
164  }\
165 }\
166 
167 
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// Destroy image.
173 
174 void TASImage::DestroyImage()
175 {
176  if (fImage) {
177  destroy_asimage(&fImage);
178  }
179 
180  if (fIsGray && fGrayImage) {
181  destroy_asimage(&fGrayImage);
182  }
183 
184  fIsGray = kFALSE;
185  fGrayImage = 0;
186  fImage = 0;
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Set default parameters.
191 
193 {
194  fImage = 0;
195  fScaledImage = 0;
196  fMaxValue = 1;
197  fMinValue = 0;
198  fEditable = kFALSE;
199  fPaintMode = 1;
200  fZoomOffX = 0;
201  fZoomOffY = 0;
202  fZoomWidth = 0;
203  fZoomHeight = 0;
205 
206  fGrayImage = 0;
207  fIsGray = kFALSE;
209 
210  if (!fgInit) {
211  set_application_name((char*)(gProgName ? gProgName : "ROOT"));
212  fgInit = kTRUE;
213  }
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Default image constructor.
218 
220 {
221  SetDefaults();
222 }
223 
224 ////////////////////////////////////////////////////////////////////////////////
225 /// Create an empty image.
226 
228 {
229  SetDefaults();
230  fImage = create_asimage(w ? w : 20, h ? h : 20, 0);
231  UnZoom();
232 }
233 
234 ////////////////////////////////////////////////////////////////////////////////
235 /// Create an image object and read from specified file.
236 /// For more information see description of function ReadImage()
237 /// which is called by this constructor.
238 
239 TASImage::TASImage(const char *file, EImageFileTypes) : TImage(file)
240 {
241  SetDefaults();
242  TString fname = file;
243  gSystem->ExpandPathName(fname);
244  ReadImage(fname.Data());
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 /// Create an image depending on the values of imageData.
249 /// For more information see function SetImage() which is called
250 /// by this constructor.
251 
252 TASImage::TASImage(const char *name, const Double_t *imageData, UInt_t width,
253  UInt_t height, TImagePalette *palette) : TImage(name)
254 {
255  SetDefaults();
256  SetImage(imageData, width, height, palette);
257 }
258 
259 ////////////////////////////////////////////////////////////////////////////////
260 /// Create an image depending on the values of imageData.
261 /// The size of the image is width X (imageData.fN / width).
262 /// For more information see function SetImage() which is called by
263 /// this constructor.
264 
265 TASImage::TASImage(const char *name, const TArrayD &imageData, UInt_t width,
266  TImagePalette *palette) : TImage(name)
267 {
268  SetDefaults();
269  SetImage(imageData, width, palette);
270 }
271 
272 ////////////////////////////////////////////////////////////////////////////////
273 /// Create an image depending on the values of imageData.
274 /// The size of the image is width X (imageData.fN / width).
275 /// For more information see function SetImage() which is called by
276 /// this constructor.
277 
278 TASImage::TASImage(const char *name, const TVectorD &imageData, UInt_t width,
279  TImagePalette *palette) : TImage(name)
280 {
281  SetDefaults();
282  SetImage(imageData, width, palette);
283 }
284 
285 ////////////////////////////////////////////////////////////////////////////////
286 /// Image copy constructor.
287 
289 {
290  SetDefaults();
291 
292  if (img.IsValid()) {
293  fImage = clone_asimage(img.fImage, SCL_DO_ALL);
295  fGrayImage = fGrayImage ? clone_asimage(img.fGrayImage, SCL_DO_ALL) : 0;
296 
297  if (img.fImage->alt.vector) {
298  Int_t size = img.fImage->width * img.fImage->height * sizeof(double);
299  fImage->alt.vector = (double*)malloc(size);
300  memcpy(fImage->alt.vector, img.fImage->alt.vector, size);
301  }
302 
304  fZoomOffX = img.fZoomOffX;
305  fZoomOffY = img.fZoomOffY;
306  fZoomWidth = img.fZoomWidth;
307  fZoomHeight = img.fZoomHeight;
308  fEditable = img.fEditable;
309  fIsGray = img.fIsGray;
310  }
311 }
312 
313 ////////////////////////////////////////////////////////////////////////////////
314 /// Image assignment operator.
315 
317 {
318  if (this != &img && img.IsValid()) {
319  TImage::operator=(img);
320 
321  DestroyImage();
322  delete fScaledImage;
323  fImage = clone_asimage(img.fImage, SCL_DO_ALL);
325  fGrayImage = fGrayImage ? clone_asimage(img.fGrayImage, SCL_DO_ALL) : 0;
326 
327  if (img.fImage->alt.vector) {
328  Int_t size = img.fImage->width * img.fImage->height * sizeof(double);
329  fImage->alt.vector = (double*)malloc(size);
330  memcpy(fImage->alt.vector, img.fImage->alt.vector, size);
331  }
332 
333  fScaledImage = img.fScaledImage ? (TASImage*)img.fScaledImage->Clone("") : 0;
335  fZoomOffX = img.fZoomOffX;
336  fZoomOffY = img.fZoomOffY;
337  fZoomWidth = img.fZoomWidth;
338  fZoomHeight = img.fZoomHeight;
339  fEditable = img.fEditable;
340  fIsGray = img.fIsGray;
341  fPaintMode = 1;
342  }
343 
344  return *this;
345 }
346 
347 ////////////////////////////////////////////////////////////////////////////////
348 /// Image destructor, clean up image and visual.
349 
351 {
352  DestroyImage();
353  delete fScaledImage;
354  fScaledImage = 0;
355 }
356 
357 ////////////////////////////////////////////////////////////////////////////////
358 /// Set icons paths.
359 
360 static void init_icon_paths()
361 {
362  TString icon_path = gEnv->GetValue("Gui.IconPath", "");
363  if (icon_path.IsNull()) {
364  icon_path = "icons";
366 #ifndef R__WIN32
367  icon_path = ".:" + icon_path + ":" + TROOT::GetIconPath() + ":" + EXTRAICONPATH;
368 #else
369  icon_path = ".;" + icon_path + ";" + TROOT::GetIconPath() + ";" + EXTRAICONPATH;
370 #endif
371  }
372 
373  Int_t cnt = 0;
374  Ssiz_t from = 0;
375  TString token;
376 #ifndef R__WIN32
377  const char *delim = "/";
378 #else
379  const char *delim = "\\";
380 #endif
381  while (icon_path.Tokenize(token, from, delim) && cnt < 6) {
382  char *path = gSystem->ExpandPathName(token.Data());
383  if (path) {
384  gIconPaths[cnt] = path;
385  cnt++;
386  }
387  }
388  gIconPaths[cnt] = 0;
389 }
390 
391 ////////////////////////////////////////////////////////////////////////////////
392 /// Guess the file type from the first byte of file.
393 
394 const char *TASImage::TypeFromMagicNumber(const char *file)
395 {
396  UChar_t magic;
397  FILE *fp = fopen(file, "rb");
398  const char *ret = "";
399 
400  if (!fp) return 0;
401 
402  if (!fread(&magic, 1, 1, fp)) {
403  fclose(fp);
404  return 0;
405  }
406 
407  switch (magic) {
408  case 0x00:
409  {
410  if (!fread(&magic, 1, 1, fp)) {
411  fclose(fp);
412  return 0;
413  }
414  if (!fread(&magic, 1, 1, fp)) {
415  fclose(fp);
416  return 0;
417  }
418 
419  ret = (magic == 1) ? "ico" : "cur";
420  break;
421  }
422  case 0x25:
423  {
424  if (!fread(&magic, 1, 1, fp)) {
425  fclose(fp);
426  return 0;
427  }
428 
429  if (magic == 0x21) ret = "ps";
430  else if (magic == 0x50) ret = "pdf";
431  break;
432  }
433  case 0x42:
434  ret = "bmp";
435  break;
436  case 0x47:
437  ret = "gif";
438  break;
439  case 0x54:
440  ret = "tga";
441  break;
442  case 0x49:
443  ret = "tiff";
444  break;
445  case 0x89:
446  ret = "png";
447  break;
448  case 0xff:
449  ret = "jpg";
450  break;
451  default:
452  ret = "";
453  }
454 
455  fclose(fp);
456  return ret;
457 }
458 
459 ////////////////////////////////////////////////////////////////////////////////
460 /// Read specified image file.
461 /// The file type is determined by the file extension (the type argument is
462 /// ignored). It will attempt to append .gz and then .Z to the filename and
463 /// find such a file. If the filename ends with extension consisting of digits
464 /// only, it will attempt to find the file with this extension stripped
465 /// off. On success this extension will be used to load subimage from
466 /// the file with that number. Subimage is supported for GIF files
467 /// (ICO, BMP, CUR, TIFF, XCF to be supported in future).
468 /// For example,
469 /// ~~~ {.cpp}
470 /// i1 = TImage::Open("anim.gif.0"); // read the first subimage
471 /// i4 = TImage::Open("anim.gif.3"); // read the forth subimage
472 /// ~~~
473 /// It is also possible to put XPM raw string (see also SetImageBuffer) as
474 /// the first input parameter ("filename"), such string is returned by
475 /// GetImageBuffer method.
476 
477 void TASImage::ReadImage(const char *filename, EImageFileTypes /*type*/)
478 {
479  if (!InitVisual()) {
480  Warning("Scale", "Visual not initiated");
481  return;
482  }
483 
484  Bool_t xpm = filename && (filename[0] == '/' &&
485  filename[1] == '*') && filename[2] == ' ';
486 
487  if (xpm) { // XPM strings in-memory array
488  SetImageBuffer((char**)&filename, TImage::kXpm);
489  fName = "XPM_image";
490  return;
491  }
492 
493  if (!gIconPaths[0]) {
494  init_icon_paths();
495  }
496  // suppress the "root : looking for image ..." messages
497  set_output_threshold(0);
498 
499  static ASImageImportParams iparams;
500  iparams.flags = 0;
501  iparams.width = 0;
502  iparams.height = 0;
503  iparams.filter = SCL_DO_ALL;
504  iparams.gamma = SCREEN_GAMMA;
505  iparams.gamma_table = NULL;
506  iparams.compression = GetImageCompression();
507  iparams.format = ASA_ASImage;
508  iparams.search_path = gIconPaths;
509  iparams.subimage = 0;
510  iparams.return_animation_delay = -1;
511 
512  TString ext;
513  const char *dot;
514  if (filename) dot = strrchr(filename, '.');
515  else dot = 0;
516  ASImage *image = 0;
517  TString fname = filename;
518 
519  if (!dot) {
520  if (filename) ext = TypeFromMagicNumber(filename);
521  else ext = dot + 1;
522  } else {
523  ext = dot + 1;
524  }
525 
526  if (!ext.IsNull() && ext.IsDigit()) { // read subimage
527  iparams.subimage = ext.Atoi();
528  fname = fname(0, fname.Length() - ext.Length() - 1);
529  ext = strrchr(fname.Data(), '.') + 1;
530  }
531 
532  image = file2ASImage_extra(fname.Data(), &iparams);
533 
534  if (image) { // it's OK
535  goto end;
536  } else { // try to read it via plugin
537  if (ext.IsNull()) {
538  return;
539  }
540  ext.ToLower();
541  ext.Strip();
542  UInt_t w = 0;
543  UInt_t h = 0;
544  unsigned char *bitmap = 0;
545 
547 
548  if (!plug) {
549  TPluginHandler *handler = gROOT->GetPluginManager()->FindHandler("TImagePlugin", ext);
550  if (!handler || ((handler->LoadPlugin() == -1))) {
551  return;
552  }
553  plug = (TImagePlugin*)handler->ExecPlugin(1, ext.Data());
554 
555  if (!plug) {
556  return;
557  }
558 
559  fgPlugList->Add(plug);
560  }
561 
562  if (plug) {
563  if (plug->InheritsFrom(TASImagePlugin::Class())) {
564  image = ((TASImagePlugin*)plug)->File2ASImage(fname.Data());
565  if (image) goto end;
566  }
567  bitmap = plug->ReadFile(fname.Data(), w, h);
568  if (bitmap) {
569  image = bitmap2asimage(bitmap, w, h, 0, 0);
570  }
571  if (!image) {
572  return;
573  }
574  }
575  }
576 
577 end:
578  fName.Form("%s.", gSystem->BaseName(fname.Data()));
579 
580  DestroyImage();
581  delete fScaledImage;
582  fScaledImage = 0;
583 
584  fImage = image;
586  fEditable = kFALSE;
587  fZoomOffX = 0;
588  fZoomOffY = 0;
589  fZoomWidth = fImage->width;
590  fZoomHeight = fImage->height;
591  fPaintMode = 1;
592 }
593 
594 ////////////////////////////////////////////////////////////////////////////////
595 /// Write image to specified file.
596 ///
597 /// If there is no file extension or if the file extension is unknown, the
598 /// type argument will be used to determine the file type. The quality and
599 /// compression is derived from the TAttImage values.
600 ///
601 /// It's possible to write image into an animated GIF file by specifying file
602 /// name as "myfile.gif+" or "myfile.gif+NN", where NN is the delay of displaying
603 /// subimages during animation in 10ms seconds units. NN is not restricted
604 /// to two digits. If NN is omitted the delay between subimages is zero.
605 /// For an animation that stops after last subimage is reached, one has to
606 /// write the last image as .gif+ (zero delay of last image) or .gif+NN
607 /// (NN*10ms delay of last image).
608 ///
609 /// For repeated animation (looping), the last subimage must be specified as:
610 /// - "myfile.gif++NN++" if you want an infinite looping gif with NN*10ms
611 /// delay of the last image.
612 /// - "myfile.gif++" for an infinite loop with zero delay of last image.
613 /// - "myfile.gif+NN++RR" if you want a finite looping gif with NN*10ms
614 /// delay of the last image and the animation to be stopped after RR
615 /// repeats. RR is not restricted to two digits.
616 ///
617 /// A deprecated version for saving the last subimage of a looping gif animation is:
618 /// - "myfile.gif++NN" for a finite loop where NN is number of repetitions
619 /// and NN*10ms the delay of last image. (No separate control of repeats and delay).
620 /// Note: If the file "myfile.gif" already exists, the new frames are appended at
621 /// the end of the file. To avoid this, delete it first with gSystem->Unlink(myfile.gif);
622 ///
623 /// The following macro creates animated gif from jpeg images with names
624 /// - imageNN.jpg, where 1<= NN <= 10
625 /// - The delays are set to 10*10ms.
626 /// ~~~ {.cpp}
627 /// {
628 /// TImage *img = 0;
629 /// gSystem->Unlink("anim.gif"); // delete existing file
630 ///
631 /// for (int i = 1; i <= 10; i++) {
632 /// delete img; // delete previous image
633 ///
634 /// // Read image data. Image can be in any format, e.g. png, gif, etc.
635 /// img = TImage::Open(Form("image%d.jpg", i));
636 ///
637 /// if (i < 10) {
638 /// img->WriteImage("anim.gif+10"); // 10 centiseconds delay
639 /// } else { // the last image written. "++" stands for infinit animation.
640 /// img->WriteImage("anim.gif++10++"); // 10 centiseconds delay of last image
641 /// }
642 /// }
643 /// }
644 /// ~~~
645 
647 {
648  if (!IsValid()) {
649  Error("WriteImage", "no image loaded");
650  return;
651  }
652 
653  if (!file || !*file) {
654  Error("WriteImage", "no file name specified");
655  return;
656  }
657 
658  const char *s;
659  if ((s = strrchr(file, '.'))) {
660  s++;
662  if (t == kUnknown) {
663  Error("WriteImage", "cannot determine a valid file type");
664  return;
665  }
666  if (t != kUnknown)
667  type = t;
668  }
669 
670  if (type == kUnknown) {
671  Error("WriteImage", "not a valid file type was specified");
672  return;
673  }
674 
675  UInt_t mytype;
676  MapFileTypes(type, mytype);
677  ASImageFileTypes atype = (ASImageFileTypes)mytype;
678 
679  UInt_t aquality;
680  EImageQuality quality = GetImageQuality();
681  MapQuality(quality, aquality);
682 
683  static TString fname;
684  fname = file;
685  static ASImageExportParams parms;
686  ASImage *im = fScaledImage ? fScaledImage->fImage : fImage;
687 
688  switch (type) {
689  case kXpm:
690  parms.xpm.type = atype;
691  parms.xpm.flags = EXPORT_ALPHA;
692  parms.xpm.dither = 4;
693  parms.xpm.opaque_threshold = 127;
694  parms.xpm.max_colors = 512;
695  break;
696  case kBmp:
697  ASImage2bmp(im, fname.Data(), 0);
698  return;
699  case kXcf:
700  ASImage2xcf(im, fname.Data(), 0);
701  return;
702  case kPng:
703  parms.png.type = atype;
704  parms.png.flags = EXPORT_ALPHA;
705  parms.png.compression = !GetImageCompression() ? -1 : int(GetImageCompression());
706  break;
707  case kJpeg:
708  parms.jpeg.type = atype;
709  parms.jpeg.flags = 0;
710  parms.jpeg.quality = aquality;
711  break;
712  case kGif:
713  parms.gif.type = atype;
714  parms.gif.flags = EXPORT_ALPHA;
715  parms.gif.dither = 0;
716  parms.gif.opaque_threshold = 0;
717  break;
718  case kAnimGif:
719  {
720  parms.gif.type = atype;
721  parms.gif.flags = EXPORT_ALPHA | EXPORT_APPEND;
722  parms.gif.dither = 0;
723  parms.gif.opaque_threshold = 0;
724  parms.gif.animate_repeats = 0;
725 
726  s += 4; // skip "gif+"
727  int delay = 0;
728 
729  const TString sufix = s; // we denote as suffix as everything that is after .gif+
730  const UInt_t sLength = sufix.Length();
731 
732  if (sufix=="+") {
733  // .gif++ implies that this is the last image of the animation
734  // and that the gif will loop forever (infinite animation)
735  // and that the delay of last image is 0ms (backward compatibility reasons)
736  delay = 0;
737  parms.gif.flags |= EXPORT_ANIMATION_REPEATS;// activate repetition
738  parms.gif.animate_repeats = 0;// 0 is code for looping forever (if EXPORT_ANIMATION_REPEATS is also set)
739  } else if(sufix=="") {
740  // .gif+ implies that this is a subimage of the animation with zero delay
741  // or the last image of an animation that will not repeat.
742  // Last image delay is zero because atoi("")=0.
743  delay = atoi(s);
744  //Nothing else needed here
745  } else if(!sufix.Contains("+")) {
746  // .gif+NN implies that this is a subimage of the animation
747  // with NN*10ms delay (latency) until the next one.
748  // You can also use this option on the last image if you do not want the gif to replay
749  delay = atoi(s);
750  //Nothing else needed here
751  } else if(sLength>1 && sufix.BeginsWith("+") && sufix.CountChar('+')==1) {
752  // .gif++NN implies that this is the last image of the animation
753  // and that it will loop NN number of times (finite animation)
754  // and that the delay of last image is NN*10ms (backward compatibility reasons).
755  delay = atoi(s);// atoi is smart enough to ignore the "+" sign before.
756  parms.gif.flags |= EXPORT_ANIMATION_REPEATS;// activate repetition
757  parms.gif.animate_repeats = atoi(s);// loops only NN times, then it stops. atoi discards + sign.
758  } else if(sLength>3 && sufix.BeginsWith("+") && sufix.EndsWith("++") && !TString(sufix(1,sLength-3)).Contains("+")) {
759  // .gif++NN++ implies that this is the last image of the animation
760  // and that the gif will loop forever (infinite animation)
761  // and that the delay of last image is NN*10ms.
762  // In contrast, .gif++ is an infinite loop but with 0 delay, whereas the option
763  // .gif++NN is a loop repeated NN times (not infinite) with NN*10ms delay
764  // between last and first loop images.
765  delay = atoi(s);// atoi discards the three plus signs
766  parms.gif.flags |= EXPORT_ANIMATION_REPEATS;// activate repetition
767  parms.gif.animate_repeats = 0;// 0 is code for looping forever (if EXPORT_ANIMATION_REPEATS is also set)
768  } else if(sLength>3 && sufix.CountChar('+')==2 && TString(sufix(1,sLength-2)).Contains("++")) {
769  // .gif+NN++RR implies that this is the last image animation
770  // and that the gif will loop RR number of times (finite animation)
771  // and that the delay of last image is NN*10ms.
772  const TString sDelay = sufix(0,sufix.First('+'));
773  const TString sRepeats = sufix(sufix.First('+')+2,sLength-(sufix.First('+')+2));
774  delay = atoi(sDelay);
775  parms.gif.flags |= EXPORT_ANIMATION_REPEATS;// activate repetition
776  parms.gif.animate_repeats = atoi(sRepeats);// loops NN times.
777  } else {
778  Error("WriteImage", "gif suffix %s not yet supported", s);
779  return;
780  }
781 
782  parms.gif.animate_delay = delay;
783 
784  int i1 = fname.Index("gif+");
785  if (i1 != kNPOS) {
786  fname = fname(0, i1 + 3);
787  }
788  else {
789  Error("WriteImage", "unexpected gif extension structure %s", fname.Data());
790  return;
791  }
792  break;
793  }
794  case kTiff:
795  parms.tiff.type = atype;
796  parms.tiff.flags = EXPORT_ALPHA;
797  parms.tiff.rows_per_strip = 0;
798  parms.tiff.compression_type = aquality <= 50 ? TIFF_COMPRESSION_JPEG :
799  TIFF_COMPRESSION_NONE;
800  parms.tiff.jpeg_quality = 100;
801  parms.tiff.opaque_threshold = 0;
802  break;
803  default:
804  Error("WriteImage", "file type %s not yet supported", s);
805  return;
806  }
807 
808  if (!ASImage2file(im, 0, fname.Data(), atype, &parms)) {
809  Error("WriteImage", "error writing file %s", file);
810  }
811 }
812 
813 ////////////////////////////////////////////////////////////////////////////////
814 /// Return file type depending on specified extension.
815 /// Protected method.
816 
818 {
819  TString s(ext);
820  s.Strip();
821  s.ToLower();
822 
823  if (s == "xpm")
824  return kXpm;
825  if (s == "png")
826  return kPng;
827  if (s == "jpg" || s == "jpeg")
828  return kJpeg;
829  if (s == "xcf")
830  return kXcf;
831  if (s == "ppm")
832  return kPpm;
833  if (s == "pnm")
834  return kPnm;
835  if (s == "bmp")
836  return kBmp;
837  if (s == "ico")
838  return kIco;
839  if (s == "cur")
840  return kCur;
841  if (s == "gif")
842  return kGif;
843  if (s.Contains("gif+"))
844  return kAnimGif;
845  if (s == "tiff")
846  return kTiff;
847  if (s == "xbm")
848  return kXbm;
849  if (s == "tga")
850  return kTga;
851  if (s == "xml")
852  return kXml;
853 
854  return kUnknown;
855 }
856 
857 ////////////////////////////////////////////////////////////////////////////////
858 /// Map file type to/from AfterImage types.
859 /// Protected method.
860 
862 {
863  if (toas) {
864  switch (type) {
865  case kXpm:
866  astype = ASIT_Xpm; break;
867  case kZCompressedXpm:
868  astype = ASIT_ZCompressedXpm; break;
869  case kGZCompressedXpm:
870  astype = ASIT_GZCompressedXpm; break;
871  case kPng:
872  astype = ASIT_Png; break;
873  case kJpeg:
874  astype = ASIT_Jpeg; break;
875  case kXcf:
876  astype = ASIT_Xcf; break;
877  case kPpm:
878  astype = ASIT_Ppm; break;
879  case kPnm:
880  astype = ASIT_Pnm; break;
881  case kBmp:
882  astype = ASIT_Bmp; break;
883  case kIco:
884  astype = ASIT_Ico; break;
885  case kCur:
886  astype = ASIT_Cur; break;
887  case kGif:
888  astype = ASIT_Gif; break;
889  case kAnimGif:
890  astype = ASIT_Gif; break;
891  case kTiff:
892  astype = ASIT_Tiff; break;
893  case kXbm:
894  astype = ASIT_Xbm; break;
895  case kTga:
896  astype = ASIT_Targa; break;
897  case kXml:
898  astype = ASIT_XMLScript; break;
899  default:
900  astype = ASIT_Unknown;
901  }
902  } else {
903  switch (astype) {
904  case ASIT_Xpm:
905  type = kXpm; break;
906  case ASIT_ZCompressedXpm:
907  type = kZCompressedXpm; break;
908  case ASIT_GZCompressedXpm:
909  type = kGZCompressedXpm; break;
910  case ASIT_Png:
911  type = kPng; break;
912  case ASIT_Jpeg:
913  type = kJpeg; break;
914  case ASIT_Xcf:
915  type = kXcf; break;
916  case ASIT_Ppm:
917  type = kPpm; break;
918  case ASIT_Pnm:
919  type = kPnm; break;
920  case ASIT_Bmp:
921  type = kBmp; break;
922  case ASIT_Ico:
923  type = kIco; break;
924  case ASIT_Cur:
925  type = kCur; break;
926  case ASIT_Gif:
927  type = kGif; break;
928  case ASIT_Tiff:
929  type = kTiff; break;
930  case ASIT_Xbm:
931  type = kXbm; break;
932  case ASIT_XMLScript:
933  type = kXml; break;
934  case ASIT_Targa:
935  type = kTga; break;
936  default:
937  type = kUnknown;
938  }
939  }
940 }
941 
942 ////////////////////////////////////////////////////////////////////////////////
943 /// Map quality to/from AfterImage quality.
944 /// Protected method.
945 
946 void TASImage::MapQuality(EImageQuality &quality, UInt_t &asquality, Bool_t toas)
947 {
948  if (toas) {
949  switch (quality) {
950  case kImgPoor:
951  asquality = 25; break;
952  case kImgFast:
953  asquality = 75; break;
954  case kImgGood:
955  asquality = 50; break;
956  case kImgBest:
957  asquality = 100; break;
958  default:
959  asquality = 0;
960  }
961  } else {
962  quality = kImgDefault;
963  if (asquality > 0 && asquality <= 25)
964  quality = kImgPoor;
965  if (asquality > 26 && asquality <= 50)
966  quality = kImgFast;
967  if (asquality > 51 && asquality <= 75)
968  quality = kImgGood;
969  if (asquality > 76 && asquality <= 100)
970  quality = kImgBest;
971  }
972 }
973 
974 ////////////////////////////////////////////////////////////////////////////////
975 /// Deletes the old image and creates a new image depending on the values
976 /// of imageData. The size of the image is width X height.
977 ///
978 /// The color of each pixel depends on the imageData of the corresponding
979 /// pixel. The palette is used to convert an image value into its color.
980 /// If palette is not defined (palette = 0) a default palette is used.
981 /// Any previously defined zooming is reset.
982 
983 void TASImage::SetImage(const Double_t *imageData, UInt_t width, UInt_t height,
984  TImagePalette *palette)
985 {
986  TAttImage::SetPalette(palette);
987 
988  if (!InitVisual()) {
989  Warning("SetImage", "Visual not initiated");
990  return;
991  }
992 
993  DestroyImage();
994  delete fScaledImage;
995  fScaledImage = 0;
996 
997  // get min and max value of image
998  fMinValue = fMaxValue = *imageData;
999  for (Int_t pixel = 1; pixel < Int_t(width * height); pixel++) {
1000  if (fMinValue > *(imageData + pixel)) fMinValue = *(imageData + pixel);
1001  if (fMaxValue < *(imageData + pixel)) fMaxValue = *(imageData + pixel);
1002  }
1003 
1004  // copy ROOT palette to asImage palette
1005  const TImagePalette &pal = GetPalette();
1006 
1007  ASVectorPalette asPalette;
1008 
1009  asPalette.npoints = pal.fNumPoints;
1010  Int_t col;
1011  for (col = 0; col < 4; col++)
1012  asPalette.channels[col] = new UShort_t[asPalette.npoints];
1013 
1014  memcpy(asPalette.channels[0], pal.fColorBlue, pal.fNumPoints * sizeof(UShort_t));
1015  memcpy(asPalette.channels[1], pal.fColorGreen, pal.fNumPoints * sizeof(UShort_t));
1016  memcpy(asPalette.channels[2], pal.fColorRed, pal.fNumPoints * sizeof(UShort_t));
1017  memcpy(asPalette.channels[3], pal.fColorAlpha, pal.fNumPoints * sizeof(UShort_t));
1018 
1019  asPalette.points = new Double_t[asPalette.npoints];
1020  for (Int_t point = 0; point < Int_t(asPalette.npoints); point++)
1021  asPalette.points[point] = fMinValue + (fMaxValue - fMinValue) * pal.fPoints[point];
1022 
1023  fImage = create_asimage_from_vector(fgVisual, (Double_t*)imageData, width,
1024  height, &asPalette, ASA_ASImage,
1026 
1027  delete [] asPalette.points;
1028  for (col = 0; col < 4; col++)
1029  delete [] asPalette.channels[col];
1030 
1031  fZoomUpdate = 0;
1032  fZoomOffX = 0;
1033  fZoomOffY = 0;
1034  fZoomWidth = width;
1035  fZoomHeight = height;
1037 }
1038 
1039 ////////////////////////////////////////////////////////////////////////////////
1040 /// Delete the old image and creates a new image depending on the values
1041 /// of imageData. The size of the image is width X (imageData.fN / width).
1042 /// The color of each pixel depends on the imageData of the corresponding
1043 /// pixel. The palette is used to convert an image value into its color.
1044 /// If palette is not defined (palette = 0) a default palette is used.
1045 /// Any previously defined zooming is reset.
1046 
1047 void TASImage::SetImage(const TArrayD &imageData, UInt_t width, TImagePalette *palette)
1048 {
1049  SetImage(imageData.GetArray(), width, imageData.GetSize() / width, palette);
1050 }
1051 
1052 ////////////////////////////////////////////////////////////////////////////////
1053 /// Delete the old image and creates a new image depending on the values
1054 /// of imageData. The size of the image is width X (imageData.fN / width).
1055 /// The color of each pixel depends on the imageData of the corresponding
1056 /// pixel. The palette is used to convert an image value into its color.
1057 /// If palette is not defined (palette = 0) a default palette is used.
1058 /// Any previously defined zooming is reset.
1059 
1060 void TASImage::SetImage(const TVectorD &imageData, UInt_t width, TImagePalette *palette)
1061 {
1062  SetImage(imageData.GetMatrixArray(), width,
1063  imageData.GetNoElements() / width, palette);
1064 }
1065 
1066 ////////////////////////////////////////////////////////////////////////////////
1067 /// Create an image from the given pad, afterwards this image can be
1068 /// saved in any of the supported image formats.
1069 
1071 {
1072  if (!pad) {
1073  Error("FromPad", "pad cannot be 0");
1074  return;
1075  }
1076 
1077  if (!InitVisual()) {
1078  Warning("FromPad", "Visual not initiated");
1079  return;
1080  }
1081 
1082  SetName(pad->GetName());
1083 
1084  DestroyImage();
1085  delete fScaledImage;
1086  fScaledImage = 0;
1087 
1088  if (gROOT->IsBatch()) { // in batch mode
1089  TVirtualPS *psave = gVirtualPS;
1090  gVirtualPS = (TVirtualPS*)gROOT->ProcessLineFast("new TImageDump()");
1091  gVirtualPS->Open(pad->GetName(), 114); // in memory
1092  gVirtualPS->SetBit(BIT(11)); //kPrintingPS
1093 
1094  TASImage *itmp = (TASImage*)gVirtualPS->GetStream();
1095 
1096  if (itmp && itmp->fImage) {
1097  itmp->BeginPaint();
1098  }
1099 
1100  TVirtualPad *sav = gPad;
1101  gPad = pad;
1102  pad->Paint();
1103  gPad = sav;
1104 
1105  if (itmp && itmp->fImage && (itmp != this)) {
1106  fImage = clone_asimage(itmp->fImage, SCL_DO_ALL);
1107  if (itmp->fImage->alt.argb32) {
1108  UInt_t sz = itmp->fImage->width*itmp->fImage->height;
1109  fImage->alt.argb32 = (ARGB32*)safemalloc(sz*sizeof(ARGB32));
1110  memcpy(fImage->alt.argb32, itmp->fImage->alt.argb32, sz*4);
1111  }
1112  }
1113  delete gVirtualPS;
1114  gVirtualPS = psave;
1115  return;
1116  }
1117 
1118  if (w == 0) {
1119  w = TMath::Abs(pad->UtoPixel(1.));
1120  }
1121 
1122  if (h == 0) {
1123  h = pad->VtoPixel(0.);
1124  }
1125  // synchronization
1126  gVirtualX->Update(1);
1127  if (!gThreadXAR) {
1129  gSystem->Sleep(10);
1131  }
1132 
1133  TVirtualPad *canvas = (TVirtualPad*)pad->GetCanvas();
1134  Int_t wid = (pad == canvas) ? pad->GetCanvasID() : pad->GetPixmapID();
1135  gVirtualX->SelectWindow(wid);
1136 
1137  Window_t wd = (Window_t)gVirtualX->GetCurrentWindow();
1138  if (!wd) return;
1139 
1140  static int x11 = -1;
1141  if (x11 < 0) x11 = gVirtualX->InheritsFrom("TGX11");
1142 
1143  if (x11) { //use built-in optimized version
1144  fImage = pixmap2asimage(fgVisual, wd, x, y, w, h, kAllPlanes, 0, 0);
1145  } else {
1146  unsigned char *bits = gVirtualX->GetColorBits(wd, 0, 0, w, h);
1147 
1148  if (!bits) { // error
1149  return;
1150  }
1151  fImage = bitmap2asimage(bits, w, h, 0, 0);
1152  delete [] bits;
1153  }
1154 }
1155 
1156 ////////////////////////////////////////////////////////////////////////////////
1157 /// Draw image.
1158 /// Support the following drawing options:
1159 /// - "T[x,y[,tint]]" : tile image (use specified offset and tint),
1160 /// e.g. "T100,100,#556655"
1161 /// with this option the zooming is not possible
1162 /// and disabled
1163 /// - "N" : display in new canvas (of original image size)
1164 /// - "X" : image is drawn expanded to pad size
1165 /// - "Z" : image is vectorized and image palette is drawn
1166 ///
1167 /// The default is to display the image in the current gPad.
1168 
1170 {
1171  if (!fImage) {
1172  Error("Draw", "no image set");
1173  return;
1174  }
1175 
1176  TString opt = option;
1177  opt.ToLower();
1178  if (opt.Contains("n") || !gPad || !gPad->IsEditable()) {
1179  Int_t w = -64;
1180  Int_t h = 64;
1181  w = (fImage->width > 64) ? (Int_t)fImage->width : w;
1182  h = (fImage->height > 64) ? (Int_t)fImage->height : h;
1183 
1184  Float_t cx = 1./gStyle->GetScreenFactor();
1185  w = Int_t(w*cx) + 4;
1186  h = Int_t(h*cx) + 28;
1187  TString rname = GetName();
1188  rname.ReplaceAll(".", "");
1189  rname += Form("\", \"%s (%d x %d)", rname.Data(), fImage->width, fImage->height);
1190  rname = "new TCanvas(\"" + rname + Form("\", %d, %d);", w, h);
1191  gROOT->ProcessLineFast(rname.Data());
1192  }
1193 
1194  if (!opt.Contains("x")) {
1195  Double_t left = gPad->GetLeftMargin();
1196  Double_t right = gPad->GetRightMargin();
1197  Double_t top = gPad->GetTopMargin();
1198  Double_t bottom = gPad->GetBottomMargin();
1199 
1200  gPad->Range(-left / (1.0 - left - right),
1201  -bottom / (1.0 - top - bottom),
1202  1 + right / (1.0 - left - right),
1203  1 + top / ( 1.0 - top - bottom));
1204  gPad->RangeAxis(0, 0, 1, 1);
1205  }
1206 
1207  TFrame *frame = gPad->GetFrame();
1208  if (frame) {
1209  frame->SetBorderMode(0);
1210  frame->SetFillColor(gPad->GetFillColor());
1211  frame->SetLineColor(gPad->GetFillColor());
1212  frame->Draw();
1213  }
1214 
1215  TObject::Draw(option);
1216 }
1217 
1218 ////////////////////////////////////////////////////////////////////////////////
1219 /// Draw asimage on drawable.
1220 
1222  Int_t xsrc, Int_t ysrc, UInt_t wsrc, UInt_t hsrc,
1223  Option_t *opt)
1224 {
1225  if (!im) return;
1226 
1227  wsrc = wsrc ? wsrc : im->width;
1228  hsrc = hsrc ? hsrc : im->height;
1229 
1230  static int x11 = -1;
1231  if (x11 < 0) x11 = gVirtualX->InheritsFrom("TGX11");
1232 
1233  Pixmap_t mask = kNone;
1234 
1235  if (x11) {
1236  UInt_t hh = hsrc;
1237  UInt_t ow = wsrc%8;
1238  UInt_t ww = wsrc - ow + (ow ? 8 : 0);
1239 
1240  UInt_t bit = 0;
1241  int i = 0;
1242  UInt_t yy = 0;
1243  UInt_t xx = 0;
1244 
1245  char *bits = new char[ww*hh]; //an array of bits
1246 
1247  ASImageDecoder *imdec = start_image_decoding(fgVisual, im, SCL_DO_ALPHA,
1248  xsrc, ysrc, ww, 0, 0);
1249  if (imdec) {
1250  for (yy = 0; yy < hh; yy++) {
1251  imdec->decode_image_scanline(imdec);
1252  CARD32 *a = imdec->buffer.alpha;
1253 
1254  for (xx = 0; xx < ww; xx++) {
1255  if (a[xx]) {
1256  SETBIT(bits[i], bit);
1257  } else {
1258  CLRBIT(bits[i], bit);
1259  }
1260  bit++;
1261  if (bit == 8) {
1262  bit = 0;
1263  i++;
1264  }
1265  }
1266  }
1267  }
1268 
1269  stop_image_decoding(&imdec);
1270 
1271  mask = gVirtualX->CreateBitmap(gVirtualX->GetDefaultRootWindow(),
1272  (const char *)bits, ww, hh);
1273  delete [] bits;
1274  }
1275 
1276  GCValues_t gv;
1277  static GContext_t gc = 0;
1278 
1280  gv.fClipMask = mask;
1281  gv.fClipXOrigin = x;
1282  gv.fClipYOrigin = y;
1283 
1284  if (!gc) {
1285  gc = gVirtualX->CreateGC(gVirtualX->GetDefaultRootWindow(), &gv);
1286  } else {
1287  gVirtualX->ChangeGC(gc, &gv);
1288  }
1289 
1290  if (x11 && (!gPad || gPad->GetGLDevice() == -1)) { //use built-in optimized version
1291  asimage2drawable(fgVisual, wid, im, (GC)gc, xsrc, ysrc, x, y, wsrc, hsrc, 1);
1292  } else {
1293  ASImage *img = 0;
1294  unsigned char *bits = (unsigned char *)im->alt.argb32;
1295  if (!bits) {
1296  img = tile_asimage(fgVisual, im, xsrc, ysrc, wsrc, hsrc,
1297  0, ASA_ARGB32, 0, ASIMAGE_QUALITY_DEFAULT);
1298  if (img)
1299  bits = (unsigned char *)img->alt.argb32;
1300  }
1301 
1302  if (bits) {
1303  TString option(opt);
1304  option.ToLower();
1305 
1306  if (gPad && gPad->GetGLDevice() != -1) {
1307  if (TVirtualPadPainter *painter = gPad->GetPainter())
1308  painter->DrawPixels(bits, wsrc, hsrc, x, y, !option.Contains("opaque"));
1309  } else {
1310  Pixmap_t pic = gVirtualX->CreatePixmapFromData(bits, wsrc, hsrc);
1311  if (pic) {
1312  if (!option.Contains("opaque")) {
1313  SETBIT(wsrc,31);
1314  SETBIT(hsrc,31);
1315  }
1316  gVirtualX->CopyArea(pic, wid, gc, 0, 0, wsrc, hsrc, x, y);
1317  gVirtualX->DeletePixmap(pic);
1318  }
1319  }
1320  }
1321 
1322  if (img) {
1323  destroy_asimage(&img);
1324  }
1325  }
1326 
1327  // free mask pixmap
1328  if (gv.fClipMask != kNone) gVirtualX->DeletePixmap(gv.fClipMask);
1329 
1330  gv.fMask = kGCClipMask;
1331  gv.fClipMask = kNone;
1332  if (gc) gVirtualX->ChangeGC(gc, &gv);
1333 }
1334 
1335 ////////////////////////////////////////////////////////////////////////////////
1336 /// Draw image on the drawable wid (pixmap, window) at x,y position.
1337 ///
1338 /// \param[in] wid : Drawable (pixmap or window) on which image is drawn.
1339 /// \param[in] x,y : Window coordinates where image is drawn.
1340 /// \param[in] xsrc, ysrc : X and Y coordinates of an image area to be drawn.
1341 /// \param[in] wsrc, hsrc : Width and height image area to be drawn.
1342 
1344  UInt_t wsrc, UInt_t hsrc, Option_t *opt)
1345 {
1347  xsrc, ysrc, wsrc, hsrc, opt);
1348 }
1349 
1350 ////////////////////////////////////////////////////////////////////////////////
1351 /// Paint image.
1352 /// Support the following drawing options:
1353 /// - "T[x,y[,tint]]" : tile image (use specified offset and tint),
1354 /// e.g. "T100,100,#556655"
1355 /// with this option the zooming is not possible
1356 /// and disabled
1357 /// - "N" : display in new canvas (of original image size)
1358 /// - "X" : image is drawn expanded to pad size
1359 /// - "Z" : image is vectorized and image palette is drawn
1360 ///
1361 /// The default is to display the image in the current gPad.
1362 
1364 {
1365  if (!fImage) {
1366  Error("Paint", "no image set");
1367  return;
1368  }
1369 
1370  if (!InitVisual()) {
1371  Warning("Paint", "Visual not initiated");
1372  return;
1373  }
1374 
1375  Int_t tile_x = 0, tile_y = 0;
1376  CARD32 tile_tint = 0;
1377  Bool_t tile = kFALSE;
1378  Bool_t expand = kFALSE;
1379 
1380  TString opt = option;
1381  opt.ToLower();
1382 
1383  if (opt.Contains("t")) {
1384  char stint[64];
1385  if (sscanf(opt.Data() + opt.Index("t"), "t%d,%d,%s", &tile_x, &tile_y,
1386  stint) <= 3) {
1387  tile = kTRUE;
1388  if (parse_argb_color(stint, (CARD32*)&tile_tint) == stint)
1389  tile_tint = 0;
1390  } else {
1391  Error("Paint", "tile option error");
1392  }
1393  } else if (opt.Contains("x")) {
1394  expand = kTRUE;
1395  fConstRatio = kFALSE;
1396  } else if (opt.Contains("z")) {
1398 
1399  if (!fImage->alt.vector) {
1400  Vectorize(256);
1401  }
1402  }
1403 
1404  ASImage *image = fImage;
1405 
1406  // Get geometry of pad
1407  Int_t to_w = gPad->UtoPixel(1.);
1408  Int_t to_h = gPad->VtoPixel(0.);
1409 
1410  // remove the size by the margin of the pad
1411  if (!expand) {
1412  to_h = (Int_t)(to_h * (1.0 - gPad->GetBottomMargin() - gPad->GetTopMargin() ) + 0.5);
1413  to_w = (Int_t)(to_w * (1.0 - gPad->GetLeftMargin() - gPad->GetRightMargin() ) + 0.5);
1414  }
1415 
1416  if ((to_w < 25 || to_h < 25) && !expand) {
1417  Error("Paint", "pad too small to display an image");
1418  return;
1419  }
1420 
1421  if (GetConstRatio()) {
1422  if ((Double_t)to_w / (Double_t)fZoomWidth <
1423  (Double_t)to_h / (Double_t)fZoomHeight)
1424  to_h = Int_t(Double_t(fZoomHeight) * to_w / fZoomWidth);
1425  else
1426  to_w = Int_t(Double_t(fZoomWidth) * to_h / fZoomHeight);
1427  }
1428  // upper left corner and size of the palette in pixels
1429  Int_t pal_Ax = to_w + gPad->UtoAbsPixel(gPad->GetLeftMargin()) +
1430  (gPad->UtoAbsPixel(gPad->GetRightMargin()) / 10);
1431  Int_t pal_Ay = gPad->YtoAbsPixel(1.0);
1432  Int_t pal_x = to_w + gPad->UtoPixel(gPad->GetLeftMargin()) +
1433  (gPad->UtoPixel(gPad->GetRightMargin()) / 10);
1434  Int_t pal_y = gPad->YtoPixel(1.0);
1435  Int_t pal_w = gPad->UtoPixel(gPad->GetRightMargin()) / 3;
1436  Int_t pal_h = to_h;
1437 
1438  ASImage *grad_im = 0;
1439 
1440  if (fImage->alt.vector && fPaletteEnabled) {
1441  // draw the palette
1442  ASGradient grad;
1443  const TImagePalette &pal = GetPalette();
1444 
1445  grad.npoints = pal.fNumPoints;
1446  grad.type = GRADIENT_Top2Bottom;
1447  grad.color = new ARGB32[grad.npoints];
1448  grad.offset = new double[grad.npoints];
1449 
1450  for (Int_t pt = 0; pt < grad.npoints; pt++) {
1451  Int_t oldPt = grad.npoints - pt -1;
1452  grad.offset[pt] = 1 - pal.fPoints[oldPt];
1453  grad.color[pt] = (((ARGB32)(pal.fColorBlue[oldPt] & 0xff00)) >> 8) |
1454  (((ARGB32)(pal.fColorGreen[oldPt] & 0xff00)) ) |
1455  (((ARGB32)(pal.fColorRed[oldPt] & 0xff00)) << 8) |
1456  (((ARGB32)(pal.fColorAlpha[oldPt] & 0xff00)) << 16);
1457  }
1458 
1459  grad_im = make_gradient(fgVisual, &grad , UInt_t(pal_w),
1460  pal_h, SCL_DO_COLOR,
1461  ASA_ARGB32, GetImageCompression(), GetImageQuality());
1462 
1463  delete [] grad.color;
1464  delete [] grad.offset;
1465  }
1466 
1467  if (tile) {
1468  delete fScaledImage;
1470  if (!fScaledImage) return;
1471  fScaledImage->fImage = tile_asimage(fgVisual, fImage, tile_x, tile_y,
1472  to_w, to_h, tile_tint, ASA_ASImage,
1474  image = fScaledImage->fImage;
1475 
1476  } else if (fZoomUpdate == kZoomOps) {
1477  image = fImage;
1478 
1479  } else {
1480  // Scale and zoom image if needed
1481  if (Int_t(fImage->width) != to_w || Int_t(fImage->height) != to_h ||
1482  fImage->width != fZoomWidth || fImage->height != fZoomHeight) {
1483 
1484  if (fScaledImage && (Int_t(fScaledImage->GetWidth()) != to_w ||
1485  Int_t(fScaledImage->GetHeight()) != to_h ||
1486  fZoomUpdate)) {
1487 
1488  delete fScaledImage;
1489  fScaledImage = 0;
1490  }
1491 
1492  if (!fScaledImage) {
1494  if (!fScaledImage) return;
1495 
1496  if (fZoomWidth && fZoomHeight &&
1497  ((fImage->width != fZoomWidth) || (fImage->height != fZoomHeight))) {
1498  // zoom and scale image
1499  ASImage *tmpImage = 0;
1500 
1501  tmpImage = tile_asimage(fgVisual, fImage, fZoomOffX,
1502  fImage->height - fZoomHeight - fZoomOffY,
1503  fZoomWidth, fZoomHeight, 0, ASA_ASImage,
1505 
1506  if (tmpImage) {
1507  fScaledImage->fImage = scale_asimage(fgVisual, tmpImage, to_w, to_h,
1508  ASA_ASImage, GetImageCompression(),
1509  GetImageQuality());
1510  destroy_asimage(&tmpImage);
1511  }
1512  } else {
1513  // scale image, no zooming
1514  fScaledImage->fImage = scale_asimage(fgVisual, fImage, to_w, to_h,
1515  ASA_ASImage, GetImageCompression(),
1516  GetImageQuality());
1517  }
1518  }
1519  image = fScaledImage->fImage;
1520  }
1521  }
1522  fZoomUpdate = 0;
1523 
1524  if (!image) {
1525  Error("Paint", "image could not be rendered to display");
1526  return;
1527  }
1528 
1529  int tox = expand ? 0 : int(gPad->UtoPixel(1.) * gPad->GetLeftMargin());
1530  int toy = expand ? 0 : int(gPad->VtoPixel(0.) * gPad->GetTopMargin());
1531 
1532  if (!gROOT->IsBatch()) {
1533  Window_t wid = (Window_t)gVirtualX->GetWindowID(gPad->GetPixmapID());
1534  Image2Drawable(fScaledImage ? fScaledImage->fImage : fImage, wid, tox, toy);
1535 
1536  if (grad_im && fPaletteEnabled) {
1537  // draw color bar
1538  Image2Drawable(grad_im, wid, pal_x, pal_y);
1539 
1540  // values of palette
1541  TGaxis axis;
1542  Int_t ndiv = 510;
1543  double min = fMinValue;
1544  double max = fMaxValue;
1545  axis.SetLineColor(0); // draw white ticks
1546  Double_t pal_Xpos = gPad->AbsPixeltoX(pal_Ax + pal_w);
1547  axis.PaintAxis(pal_Xpos, gPad->PixeltoY(pal_Ay + pal_h - 1),
1548  pal_Xpos, gPad->PixeltoY(pal_Ay),
1549  min, max, ndiv, "+LU");
1550  min = fMinValue;
1551  max = fMaxValue;
1552  axis.SetLineColor(1); // draw black ticks
1553  axis.PaintAxis(pal_Xpos, gPad->AbsPixeltoY(pal_Ay + pal_h),
1554  pal_Xpos, gPad->AbsPixeltoY(pal_Ay + 1),
1555  min, max, ndiv, "+L");
1556  }
1557  }
1558 
1559  // loop over pixmap and draw image to PostScript
1560  if (gVirtualPS) {
1561  if (gVirtualPS->InheritsFrom("TImageDump")) { // PostScript is asimage
1562  TImage *dump = (TImage *)gVirtualPS->GetStream();
1563  if (!dump) return;
1564  dump->Merge(fScaledImage ? fScaledImage : this, "alphablend",
1565  gPad->XtoAbsPixel(0), gPad->YtoAbsPixel(1));
1566 
1567  if (grad_im) {
1568  TASImage tgrad;
1569  tgrad.fImage = grad_im;
1570  dump->Merge(&tgrad, "alphablend", pal_Ax, pal_Ay);
1571 
1572  // values of palette
1573  TGaxis axis;
1574  Int_t ndiv = 510;
1575  double min = fMinValue;
1576  double max = fMaxValue;
1577  axis.SetLineColor(1); // draw black ticks
1578  Double_t pal_Xpos = gPad->AbsPixeltoX(pal_Ax + pal_w);
1579  axis.PaintAxis(pal_Xpos, gPad->AbsPixeltoY(pal_Ay + pal_h),
1580  pal_Xpos, gPad->AbsPixeltoY(pal_Ay + 1),
1581  min, max, ndiv, "+L");
1582  }
1583  return;
1584  } else if (gVirtualPS->InheritsFrom("TPDF")) {
1585  Warning("Paint", "PDF not implemented yet");
1586  return;
1587  } else if (gVirtualPS->InheritsFrom("TSVG")) {
1588  Warning("Paint", "SVG not implemented yet");
1589  return;
1590  }
1591 
1592  // get special color cell to be reused during image printing
1593  TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
1594  TColor *color = 0;
1595  // Look for color by name
1596  if ((color = (TColor*)colors->FindObject("Image_PS")) == 0)
1597  color = new TColor(colors->GetEntries(), 1., 1., 1., "Image_PS");
1598 
1599  gVirtualPS->SetFillColor(color->GetNumber());
1600  gVirtualPS->SetFillStyle(1001);
1601 
1602  Double_t dx = gPad->GetX2()-gPad->GetX1();
1603  Double_t dy = gPad->GetY2()-gPad->GetY1();
1604  Double_t x1,x2,y1,y2;
1605 
1606  if (expand) {
1607  x1 = gPad->GetX1();
1608  x2 = x1+dx/image->width;
1609  y1 = gPad->GetY2();
1610  y2 = y1+dy/image->height;
1611  } else {
1612  x1 = gPad->GetX1()+dx*gPad->GetLeftMargin();
1613  x2 = x1+(dx*(1-gPad->GetRightMargin()-gPad->GetLeftMargin()))/image->width;
1614  y1 = gPad->GetY2()-dy*gPad->GetTopMargin();
1615  y2 = y1+(dy*(1-gPad->GetTopMargin()-gPad->GetBottomMargin()))/image->height;
1616  }
1617 
1618  gVirtualPS->CellArrayBegin(image->width, image->height, x1, x2, y1, y2);
1619 
1620  ASImageDecoder *imdec = start_image_decoding(fgVisual, image, SCL_DO_ALL,
1621  0, 0, image->width, image->height, 0);
1622  if (!imdec) return;
1623  for (Int_t yt = 0; yt < (Int_t)image->height; yt++) {
1624  imdec->decode_image_scanline(imdec);
1625  for (Int_t xt = 0; xt < (Int_t)image->width; xt++)
1626  gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
1627  imdec->buffer.green[xt],
1628  imdec->buffer.blue[xt]);
1629  }
1630  stop_image_decoding(&imdec);
1632 
1633  // print the color bar
1634  if (grad_im) {
1635  Double_t xconv = (gPad->AbsPixeltoX(pal_Ax + pal_w) - gPad->AbsPixeltoX(pal_Ax)) / grad_im->width;
1636  Double_t yconv = (gPad->AbsPixeltoY(pal_Ay - pal_h) - gPad->AbsPixeltoY(pal_Ay)) / grad_im->height;
1637  x1 = gPad->AbsPixeltoX(pal_Ax);
1638  x2 = x1 + xconv;
1639  y2 = gPad->AbsPixeltoY(pal_Ay);
1640  y1 = y2 - yconv;
1641  gVirtualPS->CellArrayBegin(grad_im->width, grad_im->height,
1642  x1, x2, y1, y2);
1643 
1644  imdec = start_image_decoding(fgVisual, grad_im, SCL_DO_ALL,
1645  0, 0, grad_im->width, grad_im->height, 0);
1646  if (imdec) {
1647  for (Int_t yt = 0; yt < (Int_t)grad_im->height; yt++) {
1648  imdec->decode_image_scanline(imdec);
1649  for (Int_t xt = 0; xt < (Int_t)grad_im->width; xt++)
1650  gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
1651  imdec->buffer.green[xt],
1652  imdec->buffer.blue[xt]);
1653  }
1654  }
1655  stop_image_decoding(&imdec);
1657 
1658  // values of palette
1659  TGaxis axis;
1660  Int_t ndiv = 510;
1661  double min = fMinValue;
1662  double max = fMaxValue;
1663  axis.SetLineColor(1); // draw black ticks
1664  Double_t pal_Xpos = gPad->AbsPixeltoX(pal_Ax + pal_w);
1665  axis.PaintAxis(pal_Xpos, gPad->AbsPixeltoY(pal_Ay + pal_h),
1666  pal_Xpos, gPad->AbsPixeltoY(pal_Ay + 1),
1667  min, max, ndiv, "+L");
1668 
1669  }
1670  }
1671 
1672  if (grad_im) {
1673  destroy_asimage(&grad_im);
1674  }
1675 }
1676 
1677 ////////////////////////////////////////////////////////////////////////////////
1678 /// Is the mouse in the image ?
1679 
1681 {
1682  Int_t pxl, pyl, pxt, pyt;
1683 
1684  Int_t px1 = gPad->XtoAbsPixel(0);
1685  Int_t py1 = gPad->YtoAbsPixel(0);
1686  Int_t px2 = gPad->XtoAbsPixel(1);
1687  Int_t py2 = gPad->YtoAbsPixel(1);
1688 
1689  if (px1 < px2) {pxl = px1; pxt = px2;}
1690  else {pxl = px2; pxt = px1;}
1691  if (py1 < py2) {pyl = py1; pyt = py2;}
1692  else {pyl = py2; pyt = py1;}
1693 
1694  if ((px > pxl && px < pxt) && (py > pyl && py < pyt))
1695  return 0;
1696 
1697  return 999999;
1698 }
1699 
1700 ////////////////////////////////////////////////////////////////////////////////
1701 /// Execute mouse events.
1702 
1704 {
1705  static TBox *ZoomBox;
1706 
1707  if (!gPad) return;
1708 
1709  if (IsEditable()) {
1710  gPad->ExecuteEvent(event, px, py);
1711  return;
1712  }
1713 
1714  gPad->SetCursor(kCross);
1715 
1716  static Int_t px1old, py1old, px2old, py2old;
1717  static Int_t px1, py1, px2, py2, pxl, pyl, pxt, pyt;
1718 
1719  if (!IsValid()) return;
1720 
1721  if (event == kButton1Motion || event == kButton1Down ||
1722  event == kButton1Up) {
1723 
1724  // convert to image pixel on screen
1725  Int_t imgX = px - gPad->XtoAbsPixel(0);
1726  Int_t imgY = py - gPad->YtoAbsPixel(1);
1727 
1728  if (imgX < 0) px = px - imgX;
1729  if (imgY < 0) py = py - imgY;
1730 
1731  ASImage *image = fImage;
1732  if (fScaledImage) image = fScaledImage->fImage;
1733 
1734  if (imgX >= (int)image->width) px = px - imgX + image->width - 1;
1735  if (imgY >= (int)image->height) py = py - imgY + image->height - 1;
1736 
1737  switch (event) {
1738 
1739  case kButton1Down:
1740  px1 = gPad->XtoAbsPixel(gPad->GetX1());
1741  py1 = gPad->YtoAbsPixel(gPad->GetY1());
1742  px2 = gPad->XtoAbsPixel(gPad->GetX2());
1743  py2 = gPad->YtoAbsPixel(gPad->GetY2());
1744  px1old = px; py1old = py;
1745  break;
1746 
1747  case kButton1Motion:
1748  px2old = px;
1749  px2old = TMath::Max(px2old, px1);
1750  px2old = TMath::Min(px2old, px2);
1751  py2old = py;
1752  py2old = TMath::Max(py2old, py2);
1753  py2old = TMath::Min(py2old, py1);
1754  pxl = TMath::Min(px1old, px2old);
1755  pxt = TMath::Max(px1old, px2old);
1756  pyl = TMath::Max(py1old, py2old);
1757  pyt = TMath::Min(py1old, py2old);
1758 
1759  if (ZoomBox) {
1760  ZoomBox->SetX1(gPad->AbsPixeltoX(pxl));
1761  ZoomBox->SetY1(gPad->AbsPixeltoY(pyl));
1762  ZoomBox->SetX2(gPad->AbsPixeltoX(pxt));
1763  ZoomBox->SetY2(gPad->AbsPixeltoY(pyt));
1764  }
1765  else {
1766  ZoomBox = new TBox(pxl, pyl, pxt, pyt);
1767  ZoomBox->SetFillStyle(0);
1768  ZoomBox->Draw("l*");
1769  }
1770  gPad->Modified(kTRUE);
1771  gPad->Update();
1772  break;
1773 
1774  case kButton1Up:
1775  // do nothing if zoom area is too small
1776  if ( TMath::Abs(pxl - pxt) < 5 || TMath::Abs(pyl - pyt) < 5)
1777  return;
1778 
1779  pxl = 0;
1780  pxt = 0;
1781  pyl = 0;
1782  pyt = 0;
1783 
1784  Double_t xfact = (fScaledImage) ? (Double_t)fScaledImage->fImage->width / fZoomWidth : 1;
1785  Double_t yfact = (fScaledImage) ? (Double_t)fScaledImage->fImage->height / fZoomHeight : 1;
1786 
1787  Int_t imgX1 = px1old - gPad->XtoAbsPixel(0);
1788  Int_t imgY1 = py1old - gPad->YtoAbsPixel(1);
1789  Int_t imgX2 = px - gPad->XtoAbsPixel(0);
1790  Int_t imgY2 = py - gPad->YtoAbsPixel(1);
1791 
1792  imgY1 = image->height - 1 - imgY1;
1793  imgY2 = image->height - 1 - imgY2;
1794  imgX1 = (Int_t)(imgX1 / xfact) + fZoomOffX;
1795  imgY1 = (Int_t)(imgY1 / yfact) + fZoomOffY;
1796  imgX2 = (Int_t)(imgX2 / xfact) + fZoomOffX;
1797  imgY2 = (Int_t)(imgY2 / yfact) + fZoomOffY;
1798 
1799  Zoom((imgX1 < imgX2) ? imgX1 : imgX2, (imgY1 < imgY2) ? imgY1 : imgY2,
1800  TMath::Abs(imgX1 - imgX2) + 1, TMath::Abs(imgY1 - imgY2) + 1);
1801 
1802  if (ZoomBox) {
1803  ZoomBox->Delete();
1804  ZoomBox = 0;
1805  }
1806  gPad->Modified(kTRUE);
1807  gPad->Update();
1808  break;
1809  }
1810  }
1811 }
1812 
1813 ////////////////////////////////////////////////////////////////////////////////
1814 /// Get image pixel coordinates and the pixel value at the mouse pointer.
1815 
1817 {
1818  static char info[64];
1819  info[0] = 0;
1820 
1821  if (!IsValid()) return info;
1822 
1823  // convert to image pixel on screen
1824  px -= gPad->XtoAbsPixel(0);
1825  py -= gPad->YtoAbsPixel(1);
1826 
1827  // no info if mouse is outside of image
1828  if (px < 0 || py < 0) return info;
1829 
1830  ASImage *image = fImage;
1831  if (fScaledImage) image = fScaledImage->fImage;
1832  if (px >= (int)image->width || py >= (int)image->height)
1833  return info;
1834 
1835  py = image->height - 1 - py;
1836  // convert to original image size and take zooming into account
1837  if (fScaledImage) {
1838  px = (Int_t)(px / (Double_t)fScaledImage->fImage->width * fZoomWidth ) + fZoomOffX;
1839  py = (Int_t)(py / (Double_t)fScaledImage->fImage->height * fZoomHeight) + fZoomOffY;
1840  }
1841 
1842  if (fImage->alt.vector) {
1843  snprintf(info,64,"x: %d y: %d %.5g",
1844  px, py, fImage->alt.vector[px + py * fImage->width]);
1845  } else {
1846  snprintf(info,64,"x: %d y: %d", px, py);
1847  }
1848 
1849  return info;
1850 }
1851 
1852 ////////////////////////////////////////////////////////////////////////////////
1853 /// Set a new palette to an image.
1854 /// Only images that were created with the SetImage() functions can be
1855 /// modified with this function. The previously used palette is destroyed.
1856 
1858 {
1859  TAttImage::SetPalette(palette);
1860 
1861  if (!InitVisual()) {
1862  Warning("SetPalette", "Visual not initiated");
1863  return;
1864  }
1865 
1866  if (!IsValid()) {
1867  Warning("SetPalette", "Image not valid");
1868  return;
1869  }
1870 
1871  if (fImage->alt.vector == 0)
1872  return;
1873 
1874  // copy ROOT palette to asImage palette
1875  const TImagePalette &pal = GetPalette();
1876 
1877  ASVectorPalette asPalette;
1878  asPalette.npoints = pal.fNumPoints;
1879  asPalette.channels[0] = new CARD16 [asPalette.npoints];
1880  asPalette.channels[1] = new CARD16 [asPalette.npoints];
1881  asPalette.channels[2] = new CARD16 [asPalette.npoints];
1882  asPalette.channels[3] = new CARD16 [asPalette.npoints];
1883  memcpy(asPalette.channels[0], pal.fColorBlue, pal.fNumPoints * sizeof(UShort_t));
1884  memcpy(asPalette.channels[1], pal.fColorGreen, pal.fNumPoints * sizeof(UShort_t));
1885  memcpy(asPalette.channels[2], pal.fColorRed, pal.fNumPoints * sizeof(UShort_t));
1886  memcpy(asPalette.channels[3], pal.fColorAlpha, pal.fNumPoints * sizeof(UShort_t));
1887 
1888  asPalette.points = new double[asPalette.npoints];
1889  for (Int_t point = 0; point < Int_t(asPalette.npoints); point++)
1890  asPalette.points[point] = fMinValue + (fMaxValue - fMinValue) * pal.fPoints[point];
1891 
1892  // use the new palette in this image
1893  colorize_asimage_vector(fgVisual, fImage, &asPalette, ASA_ASImage, GetImageQuality());
1894 
1895  delete [] asPalette.points;
1896  for (Int_t col = 0; col < 4; col++)
1897  delete [] asPalette.channels[col];
1898 
1899 
1900  delete fScaledImage;
1901  fScaledImage = 0;
1902 }
1903 
1904 ////////////////////////////////////////////////////////////////////////////////
1905 /// Scale the original image.
1906 /// The size of the image on the screen does not change because it is defined
1907 /// by the size of the pad.
1908 /// This function can be used to change the size of an image before writing
1909 /// it into a file. The colors of the new pixels are interpolated.
1910 /// An image created with the SetImage() functions cannot be modified with
1911 /// the function SetPalette() any more after a call of this function!
1912 
1913 void TASImage::Scale(UInt_t toWidth, UInt_t toHeight)
1914 {
1915  if (!IsValid()) {
1916  Warning("Scale", "Image not initiated");
1917  return;
1918  }
1919 
1920  if (!InitVisual()) {
1921  Warning("Scale", "Visual not initiated");
1922  return;
1923  }
1924 
1925  if (toWidth < 1)
1926  toWidth = 1;
1927  if (toHeight < 1 )
1928  toHeight = 1;
1929  if (toWidth > 30000)
1930  toWidth = 30000;
1931  if (toHeight > 30000)
1932  toHeight = 30000;
1933 
1934  ASImage *img = scale_asimage(fgVisual, fImage, toWidth, toHeight,
1935  ASA_ASImage, GetImageCompression(),
1936  GetImageQuality());
1937  DestroyImage();
1938  fImage = img;
1939  UnZoom();
1941 }
1942 
1943 ////////////////////////////////////////////////////////////////////////////////
1944 /// Another method of enlarging images where corners remain unchanged,
1945 /// but middle part gets tiled.
1946 
1947 void TASImage::Slice(UInt_t xStart, UInt_t xEnd, UInt_t yStart, UInt_t yEnd,
1948  UInt_t toWidth, UInt_t toHeight)
1949 {
1950  if (!IsValid()) {
1951  Warning("Scale", "Image not initiated");
1952  return;
1953  }
1954 
1955  if (!InitVisual()) {
1956  Warning("Scale", "Visual not initiated");
1957  return;
1958  }
1959 
1960  if (toWidth < 1)
1961  toWidth = 1;
1962  if (toHeight < 1 )
1963  toHeight = 1;
1964  if (toWidth > 30000)
1965  toWidth = 30000;
1966  if (toHeight > 30000)
1967  toHeight = 30000;
1968 
1969  ASImage *img = slice_asimage(fgVisual, fImage, xStart, xEnd,
1970  yStart, yEnd, toWidth, toHeight,
1971  ASA_ASImage, GetImageCompression(),
1972  GetImageQuality());
1973 
1974  DestroyImage();
1975  fImage = img;
1976  UnZoom();
1978 }
1979 
1980 ////////////////////////////////////////////////////////////////////////////////
1981 /// Tile the original image.
1982 
1983 void TASImage::Tile(UInt_t toWidth, UInt_t toHeight)
1984 {
1985  if (!IsValid()) {
1986  Warning("Tile", "Image not initiated");
1987  return;
1988  }
1989 
1990  if (!InitVisual()) {
1991  Warning("Tile", "Visual not initiated");
1992  return;
1993  }
1994 
1995  if (toWidth < 1)
1996  toWidth = 1;
1997  if (toHeight < 1 )
1998  toHeight = 1;
1999  if (toWidth > 30000)
2000  toWidth = 30000;
2001  if (toHeight > 30000)
2002  toHeight = 30000;
2003 
2004  ASImage *img = tile_asimage(fgVisual, fImage, 0, 0, toWidth, toHeight, 0,
2005  ASA_ASImage, GetImageCompression(), GetImageQuality());
2006  DestroyImage();
2007  fImage = img;
2008  UnZoom();
2010 }
2011 
2012 ////////////////////////////////////////////////////////////////////////////////
2013 /// The area of an image displayed in a pad is defined by this function.
2014 /// Note: the size on the screen is defined by the size of the pad.
2015 /// The original image is not modified by this function.
2016 /// If width or height is larger than the original image they are reduced to
2017 /// the width and height of the image.
2018 /// If the off values are too large (off + width > image width) than the off
2019 /// values are decreased. For example: offX = image width - width
2020 /// Note: the parameters are always relative to the original image not to the
2021 /// size of an already zoomed image.
2022 
2023 void TASImage::Zoom(UInt_t offX, UInt_t offY, UInt_t width, UInt_t height)
2024 {
2025  if (!IsValid()) {
2026  Warning("Zoom", "Image not valid");
2027  return;
2028  }
2029  fZoomUpdate = kZoom;
2030 
2031  fZoomWidth = (width == 0) ? 1 : ((width > fImage->width) ? fImage->width : width);
2032  fZoomHeight = (height == 0) ? 1 : ((height > fImage->height) ? fImage->height : height);
2033  fZoomOffX = offX;
2034  if (fZoomOffX + fZoomWidth > fImage->width)
2035  fZoomOffX = fImage->width - fZoomWidth;
2036  fZoomOffY = offY;
2037  if (fZoomOffY + fZoomHeight > fImage->height)
2038  fZoomOffY = fImage->height - fZoomHeight;
2039 }
2040 
2041 ////////////////////////////////////////////////////////////////////////////////
2042 /// Un-zoom the image to original size.
2043 /// UnZoom() - performs undo for Zoom,Crop,Scale actions
2044 
2046 {
2047  if (!IsValid()) {
2048  Warning("UnZoom", "Image not valid");
2049  return;
2050  }
2051  fZoomUpdate = kZoom;
2052  fZoomOffX = 0;
2053  fZoomOffY = 0;
2054  fZoomWidth = fImage->width;
2055  fZoomHeight = fImage->height;
2056 
2057  delete fScaledImage;
2058  fScaledImage = 0;
2059 }
2060 
2061 ////////////////////////////////////////////////////////////////////////////////
2062 /// Flip image in place.
2063 ///
2064 /// Flip is either 90, 180, 270, 180 is default.
2065 /// This function manipulates the original image and destroys the
2066 /// scaled and zoomed image which will be recreated at the next call of
2067 /// the Draw function. If the image is zoomed the zoom - coordinates are
2068 /// now relative to the new image.
2069 /// This function cannot be used for images which were created with the
2070 /// SetImage() functions, because the original pixel values would be
2071 /// destroyed.
2072 
2074 {
2075  if (!IsValid()) {
2076  Warning("Flip", "Image not valid");
2077  return;
2078  }
2079  if (!InitVisual()) {
2080  Warning("Flip", "Visual not initiated");
2081  return;
2082  }
2083 
2084  if (fImage->alt.vector) {
2085  Warning("Flip", "flip does not work for data images");
2086  return;
2087  }
2088 
2089  Int_t rflip = flip/90;
2090 
2091  UInt_t w = fImage->width;
2092  UInt_t h = fImage->height;
2093 
2094  if (rflip & 1) {
2095  w = fImage->height;
2096  h = fImage->width;
2097  }
2098 
2099  ASImage *img = flip_asimage(fgVisual, fImage, 0, 0, w, h, rflip,
2100  ASA_ASImage, GetImageCompression(),
2101  GetImageQuality());
2102  DestroyImage();
2103  fImage = img;
2104  UnZoom();
2105 }
2106 
2107 ////////////////////////////////////////////////////////////////////////////////
2108 /// Mirror image in place.
2109 ///
2110 /// If vert is true mirror in vertical axis, horizontal otherwise.
2111 /// Vertical is default.
2112 /// This function manipulates the original image and destroys the
2113 /// scaled and zoomed image which will be recreated at the next call of
2114 /// the Draw function. If the image is zoomed the zoom - coordinates are
2115 /// now relative to the new image.
2116 /// This function cannot be used for images which were created with the
2117 /// SetImage() functions, because the original pixel values would be
2118 /// destroyed.
2119 
2121 {
2122  if (!IsValid()) {
2123  Warning("Mirror", "Image not valid");
2124  return;
2125  }
2126 
2127  if (!InitVisual()) {
2128  Warning("Mirror", "Visual not initiated");
2129  return;
2130  }
2131 
2132  if (fImage->alt.vector) {
2133  Warning("Mirror", "mirror does not work for data images");
2134  return;
2135  }
2136 
2137  ASImage *img = mirror_asimage(fgVisual, fImage, 0, 0,
2138  fImage->width, fImage->height, vert,
2139  ASA_ASImage, GetImageCompression(),
2140  GetImageQuality());
2141  DestroyImage();
2142  fImage = img;
2143  UnZoom();
2144 }
2145 
2146 ////////////////////////////////////////////////////////////////////////////////
2147 /// Return width of original image not of the displayed image.
2148 /// (Number of image pixels)
2149 
2151 {
2152  return fImage ? fImage->width : 0;
2153 }
2154 
2155 ////////////////////////////////////////////////////////////////////////////////
2156 /// Return height of original image not of the displayed image.
2157 /// (Number of image pixels)
2158 
2160 {
2161  return fImage ? fImage->height : 0;
2162 }
2163 
2164 ////////////////////////////////////////////////////////////////////////////////
2165 /// Return width of the displayed image not of the original image.
2166 /// (Number of screen pixels)
2167 
2169 {
2170  return fScaledImage ? fScaledImage->fImage->width : GetWidth();
2171 }
2172 
2173 ////////////////////////////////////////////////////////////////////////////////
2174 /// Return height of the displayed image not of the original image.
2175 /// (Number of screen pixels)
2176 
2178 {
2179  return fScaledImage ? fScaledImage->fImage->height : GetHeight();
2180 }
2181 
2182 ////////////////////////////////////////////////////////////////////////////////
2183 /// Return the zoom parameters.
2184 /// This is useful when the zoom has been done interactively using the mouse.
2185 
2187 {
2188  x = fZoomOffX;
2189  y = fZoomOffY;
2190  w = fZoomWidth;
2191  h = fZoomHeight;
2192 }
2193 
2194 ////////////////////////////////////////////////////////////////////////////////
2195 /// Static function to initialize the ASVisual.
2196 
2198 {
2199  Display *disp;
2200 
2201  Bool_t inbatch = fgVisual && (fgVisual->dpy == (void*)1); // was in batch
2202  Bool_t noX = gROOT->IsBatch() || gVirtualX->InheritsFrom("TGWin32");
2203 
2204  // was in batch, but switched to gui
2205  if (inbatch && !noX) {
2206  destroy_asvisual(fgVisual, kFALSE);
2207  fgVisual = 0;
2208  }
2209 
2210  if (fgVisual && fgVisual->dpy) { // already initialized
2211  return kTRUE;
2212  }
2213 
2214  // batch or win32 mode
2215  if (!fgVisual && noX) {
2216  disp = 0;
2217  fgVisual = create_asvisual(0, 0, 0, 0);
2218  fgVisual->dpy = (Display*)1; //fake (not used)
2219  return kTRUE;
2220  }
2221 
2222 #ifndef WIN32
2223 #ifdef R__HAS_COCOA
2224  fgVisual = create_asvisual(0, 0, 0, 0);
2225  fgVisual->dpy = (Display*)1; //fake (not used)
2226 #else
2227  disp = (Display*) gVirtualX->GetDisplay();
2228  Int_t screen = gVirtualX->GetScreen();
2229  Int_t depth = gVirtualX->GetDepth();
2230  Visual *vis = (Visual*) gVirtualX->GetVisual();
2231  Colormap cmap = (Colormap) gVirtualX->GetColormap();
2232 
2233  if (vis == 0 || cmap == 0) {
2234  fgVisual = create_asvisual(0, 0, 0, 0);
2235  } else {
2236  fgVisual = create_asvisual_for_id(disp, screen, depth,
2237  XVisualIDFromVisual(vis), cmap, 0);
2238  }
2239 #endif
2240 #else
2241  fgVisual = create_asvisual(0, 0, 0, 0);
2242  fgVisual->dpy = (Display*)1; //fake (not used)
2243 #endif
2244 
2245  return kTRUE;
2246 }
2247 
2248 ////////////////////////////////////////////////////////////////////////////////
2249 /// Start palette editor.
2250 
2252 {
2253  if (!IsValid()) {
2254  Warning("StartPaletteEditor", "Image not valid");
2255  return;
2256  }
2257  if (fImage->alt.vector == 0) {
2258  Warning("StartPaletteEditor", "palette can be modified only for data images");
2259  return;
2260  }
2261 
2262  // Opens a GUI to edit the color palette
2264 }
2265 
2266 ////////////////////////////////////////////////////////////////////////////////
2267 /// Returns image pixmap.
2268 /// The pixmap must deleted by user.
2269 
2271 {
2272  if (!InitVisual()) {
2273  Warning("GetPixmap", "Visual not initiated");
2274  return 0;
2275  }
2276 
2277  Pixmap_t ret;
2278 
2279  ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;
2280 
2281  static int x11 = -1;
2282  if (x11 < 0) x11 = gVirtualX->InheritsFrom("TGX11");
2283 
2284  if (x11) { // use builtin version
2285  ret = (Pixmap_t)asimage2pixmap(fgVisual, gVirtualX->GetDefaultRootWindow(),
2286  img, 0, kTRUE);
2287  } else {
2288  if (!fImage->alt.argb32) {
2289  BeginPaint();
2290  }
2291  ret = gVirtualX->CreatePixmapFromData((unsigned char*)fImage->alt.argb32,
2292  fImage->width, fImage->height);
2293  }
2294 
2295  return ret;
2296 }
2297 
2298 ////////////////////////////////////////////////////////////////////////////////
2299 /// Returns image mask pixmap (alpha channel).
2300 /// The pixmap must deleted by user.
2301 
2303 {
2304  Pixmap_t pxmap = 0;
2305 
2306  if (!InitVisual()) {
2307  Warning("GetMask", "Visual not initiated");
2308  return pxmap;
2309  }
2310 
2311  ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;
2312 
2313  if (!img) {
2314  Warning("GetMask", "No image");
2315  return pxmap;
2316  }
2317 
2318  UInt_t hh = img->height;
2319  UInt_t ow = img->width%8;
2320  UInt_t ww = img->width - ow + (ow ? 8 : 0);
2321 
2322  UInt_t bit = 0;
2323  int i = 0;
2324  UInt_t y = 0;
2325  UInt_t x = 0;
2326 
2327  char *bits = new char[ww*hh]; //an array of bits
2328 
2329  ASImageDecoder *imdec = start_image_decoding(fgVisual, img, SCL_DO_ALPHA,
2330  0, 0, ww, 0, 0);
2331  if (!imdec) {
2332  delete [] bits;
2333  return 0;
2334  }
2335 
2336  for (y = 0; y < hh; y++) {
2337  imdec->decode_image_scanline(imdec);
2338  CARD32 *a = imdec->buffer.alpha;
2339 
2340  for (x = 0; x < ww; x++) {
2341  if (a[x]) {
2342  SETBIT(bits[i], bit);
2343  } else {
2344  CLRBIT(bits[i], bit);
2345  }
2346  bit++;
2347  if (bit == 8) {
2348  bit = 0;
2349  i++;
2350  }
2351  }
2352  }
2353 
2354  stop_image_decoding(&imdec);
2355  pxmap = gVirtualX->CreateBitmap(gVirtualX->GetDefaultRootWindow(), (const char *)bits,
2356  ww, hh);
2357  delete [] bits;
2358  return pxmap;
2359 }
2360 
2361 ////////////////////////////////////////////////////////////////////////////////
2362 /// Create image from pixmap.
2363 
2365 {
2366  if (!InitVisual()) {
2367  Warning("SetImage", "Visual not initiated");
2368  return;
2369  }
2370 
2371  DestroyImage();
2372  delete fScaledImage;
2373  fScaledImage = 0;
2374 
2375  Int_t xy;
2376  UInt_t w, h;
2377  gVirtualX->GetWindowSize(pxm, xy, xy, w, h);
2378 
2379  if (fName.IsNull()) fName.Form("img_%dx%d",w, h);
2380 
2381  static int x11 = -1;
2382  if (x11 < 0) x11 = gVirtualX->InheritsFrom("TGX11");
2383 
2384  if (x11) { //use built-in optimized version
2385  fImage = picture2asimage(fgVisual, pxm, mask, 0, 0, w, h, kAllPlanes, 1, 0);
2386  } else {
2387  unsigned char *bits = gVirtualX->GetColorBits(pxm, 0, 0, w, h);
2388  if (!bits) { // error
2389  return;
2390  }
2391 
2392  // no mask
2393  if (!mask) {
2394  fImage = bitmap2asimage(bits, w, h, 0, 0);
2395  delete [] bits;
2396  return;
2397  }
2398  unsigned char *mask_bits = gVirtualX->GetColorBits(mask, 0, 0, w, h);
2399  fImage = bitmap2asimage(bits, w, h, 0, mask_bits);
2400  delete [] mask_bits;
2401  delete [] bits;
2402  }
2403 }
2404 
2405 ////////////////////////////////////////////////////////////////////////////////
2406 /// Return 2D array of machine dependent pixel values.
2407 
2409 {
2410  if (!fImage) {
2411  Warning("GetPixels", "Wrong Image");
2412  return 0;
2413  }
2414 
2415  ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;
2416  ASImageDecoder *imdec;
2417 
2418  width = !width ? img->width : width;
2419  height = !height ? img->height : height;
2420 
2421  if (x < 0) {
2422  width -= x;
2423  x = 0 ;
2424  }
2425  if (y < 0) {
2426  height -= y;
2427  y = 0;
2428  }
2429 
2430  if ((x >= (int)img->width) || (y >= (int)img->height)) {
2431  return 0;
2432  }
2433 
2434  if ((int)(x + width) > (int)img->width) {
2435  width = img->width - x;
2436  }
2437 
2438  if ((int)(y + height) > (int)img->height) {
2439  height = img->height - y;
2440  }
2441 
2442  if ((imdec = start_image_decoding(0, fImage, SCL_DO_ALL, 0, y,
2443  img->width, height, 0)) == 0) {
2444  Warning("GetPixels", "Failed to create image decoder");
2445  return 0;
2446  }
2447 
2448  TArrayL *ret = new TArrayL(width * height);
2449  Int_t r = 0;
2450  Int_t g = 0;
2451  Int_t b = 0;
2452  Long_t p = 0;
2453 
2454  for (UInt_t k = 0; k < height; k++) {
2455  imdec->decode_image_scanline(imdec);
2456 
2457  for (UInt_t i = 0; i < width; ++i) {
2458  if ((r == (Int_t)imdec->buffer.red[i]) &&
2459  (g == (Int_t)imdec->buffer.green[i]) &&
2460  (b == (Int_t)imdec->buffer.blue[i])) {
2461  } else {
2462  r = (Int_t)imdec->buffer.red[i];
2463  g = (Int_t)imdec->buffer.green[i];
2464  b = (Int_t)imdec->buffer.blue[i];
2465  p = (Long_t)TColor::RGB2Pixel(r, g, b);
2466  }
2467  ret->AddAt(p, k*width + i);
2468  }
2469  }
2470 
2471  stop_image_decoding(&imdec);
2472  return ret;
2473 }
2474 
2475 ////////////////////////////////////////////////////////////////////////////////
2476 /// Return a pointer to internal array[width x height] of double values [0,1].
2477 /// This array is directly accessible. That allows to manipulate/change the
2478 /// image.
2479 
2481 {
2482  if (!fImage) {
2483  Warning("GetVecArray", "Bad Image");
2484  return 0;
2485  }
2486  if (fImage->alt.vector) {
2487  return fImage->alt.vector;
2488  }
2489  // vectorize
2490  return 0;
2491 }
2492 
2493 ////////////////////////////////////////////////////////////////////////////////
2494 /// In case of vectorized image return an associated array of doubles
2495 /// otherwise this method creates and returns a 2D array of doubles corresponding to palette.
2496 /// If palette is ZERO a color converted to double value [0, 1] according to formula
2497 /// ~~~ {.cpp}
2498 /// Double_t((r << 16) + (g << 8) + b)/0xFFFFFF
2499 /// ~~~
2500 /// The returned array must be deleted after usage.
2501 
2503 {
2504  if (!fImage) {
2505  Warning("GetArray", "Bad Image");
2506  return 0;
2507  }
2508 
2509  TArrayD *ret;
2510 
2511  if (fImage->alt.vector) {
2512  ret = new TArrayD(fImage->width*fImage->height, fImage->alt.vector);
2513  return ret;
2514  }
2515 
2516  ASImageDecoder *imdec;
2517 
2518  w = w ? w : fImage->width;
2519  h = h ? h : fImage->height;
2520 
2521  if ((fImage->width != w) || (fImage->height != h)) {
2522  Scale(w, h);
2523  }
2524 
2525  ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;
2526 
2527  if ((imdec = start_image_decoding(0, img, SCL_DO_ALL, 0, 0,
2528  img->width, 0, 0)) == 0) {
2529  Warning("GetArray", "Failed to create image decoder");
2530  return 0;
2531  }
2532 
2533  ret = new TArrayD(w * h);
2534  CARD32 r = 0;
2535  CARD32 g = 0;
2536  CARD32 b = 0;
2537  Int_t p = 0;
2538  Double_t v = 0;
2539 
2540  for (UInt_t k = 0; k < h; k++) {
2541  imdec->decode_image_scanline(imdec);
2542 
2543  for (UInt_t i = 0; i < w; ++i) {
2544  if ((r == imdec->buffer.red[i]) &&
2545  (g == imdec->buffer.green[i]) &&
2546  (b == imdec->buffer.blue[i])) {
2547  } else {
2548  r = imdec->buffer.red[i];
2549  g = imdec->buffer.green[i];
2550  b = imdec->buffer.blue[i];
2551  if (palette) p = palette->FindColor(r, g, b);
2552  }
2553  v = palette ? palette->fPoints[p] : Double_t((r << 16) + (g << 8) + b)/0xFFFFFF;
2554  ret->AddAt(v, (h-k-1)*w + i);
2555  }
2556  }
2557 
2558  stop_image_decoding(&imdec);
2559  return ret;
2560 }
2561 
2562 ////////////////////////////////////////////////////////////////////////////////
2563 /// Draw text of size (in pixels for TrueType fonts)
2564 /// at position (x, y) with color specified by hex string.
2565 ///
2566 /// - font_name: TrueType font's filename or X font spec or alias.
2567 /// 3D style of text is one of the following:
2568 /// * 0 plain 2D text,
2569 /// * 1 embossed,
2570 /// * 2 sunken,
2571 /// * 3 shade above,
2572 /// * 4 shade below,
2573 /// * 5 embossed thick,
2574 /// * 6 sunken thick.
2575 /// * 7 outline above,
2576 /// * 8 ouline below,
2577 /// * 9 full ouline.
2578 /// - fore_file specifies foreground texture of text.
2579 
2580 void TASImage::DrawText(Int_t x, Int_t y, const char *text, Int_t size,
2581  const char *color, const char *font_name,
2582  EText3DType type, const char *fore_file, Float_t angle)
2583 {
2584  UInt_t width=0, height=0;
2585  ARGB32 text_color = ARGB32_Black;
2586  ASImage *fore_im = 0;
2587  ASImage *text_im = 0;
2588  Bool_t ttfont = kFALSE;
2589 
2590  if (!InitVisual()) {
2591  Warning("DrawText", "Visual not initiated");
2592  return;
2593  }
2594 
2595  TString fn = font_name;
2596  fn.Strip();
2597 
2598  const char *basename = gSystem->BaseName(fn);
2599 
2600  char *ttfnt = NULL;
2601  int ttindex = 0;
2602 
2603  FcPattern *pat, *match;
2604  FcResult result;
2605 
2606  pat = FcPatternCreate ();
2607 
2608  if (strcmp(basename, "timesi.ttf") == 0 ||
2609  strcmp(basename, "FreeSerifItalic.otf") == 0) {
2610  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freeserif");
2611  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2612  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ITALIC);
2613  }
2614  else if (strcmp(basename, "timesbd.ttf") == 0 ||
2615  strcmp(basename, "FreeSerifBold.otf") == 0) {
2616  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freeserif");
2617  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_BOLD);
2618  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
2619  }
2620  else if (strcmp(basename, "timesbi.ttf") == 0 ||
2621  strcmp(basename, "FreeSerifBoldItalic.otf") == 0) {
2622  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freeserif");
2623  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_BOLD);
2624  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ITALIC);
2625  }
2626  else if (strcmp(basename, "arial.ttf") == 0 ||
2627  strcmp(basename, "FreeSans.otf") == 0) {
2628  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freesans");
2629  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2630  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
2631  }
2632  else if (strcmp(basename, "ariali.ttf") == 0 ||
2633  strcmp(basename, "FreeSansOblique.otf") == 0) {
2634  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freesans");
2635  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2636  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ITALIC);
2637  }
2638  else if (strcmp(basename, "arialbd.ttf") == 0 ||
2639  strcmp(basename, "FreeSansBold.otf") == 0) {
2640  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freesans");
2641  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_BOLD);
2642  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
2643  }
2644  else if (strcmp(basename, "arialbi.ttf") == 0 ||
2645  strcmp(basename, "FreeSansBoldOblique.otf") == 0) {
2646  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freesans");
2647  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_BOLD);
2648  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ITALIC);
2649  }
2650  else if (strcmp(basename, "cour.ttf") == 0 ||
2651  strcmp(basename, "FreeMono.otf") == 0) {
2652  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freemono");
2653  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2654  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
2655  }
2656  else if (strcmp(basename, "couri.ttf") == 0 ||
2657  strcmp(basename, "FreeMonoOblique.otf") == 0) {
2658  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freemono");
2659  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2660  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ITALIC);
2661  }
2662  else if (strcmp(basename, "courbd.ttf") == 0 ||
2663  strcmp(basename, "FreeMonoBold.otf") == 0) {
2664  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freemono");
2665  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_BOLD);
2666  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
2667  }
2668  else if (strcmp(basename, "courbi.ttf") == 0 ||
2669  strcmp(basename, "FreeMonoBoldOblique.otf") == 0) {
2670  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freemono");
2671  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_BOLD);
2672  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ITALIC);
2673  }
2674  else if (strcmp(basename, "symbol.ttf") == 0) {
2675  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"symbol");
2676  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2677  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
2678  }
2679  else if (strcmp(basename, "times.ttf") == 0 ||
2680  strcmp(basename, "FreeSerif.otf") == 0) {
2681  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freeserif");
2682  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2683  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
2684  }
2685  else if (strcmp(basename, "wingding.ttf") == 0) {
2686  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"dingbats");
2687  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2688  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
2689  }
2690  else if (strcmp(basename, "BlackChancery.ttf") == 0) {
2691  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"urwchanceryl");
2692  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2693  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ITALIC);
2694  }
2695  else {
2696  Warning("DrawText", "cannot find a font %s", font_name);
2697  FcPatternAddString (pat, FC_FAMILY, (const FcChar8*)"freemono");
2698  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_REGULAR);
2699  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
2700  }
2701 
2702  FcConfigSubstitute (NULL, pat, FcMatchPattern);
2703  FcDefaultSubstitute (pat);
2704  match = FcFontMatch (NULL, pat, &result);
2705  FcPatternGetString (match, FC_FILE, 0, (FcChar8**)&ttfnt);
2706  FcPatternGetInteger (match, FC_INDEX, 0, &ttindex);
2707 
2708  fn = ttfnt;
2709 
2710  FcPatternDestroy (match);
2711  FcPatternDestroy (pat);
2712 
2713  if (fn.EndsWith(".pfa") || fn.EndsWith(".PFA") || fn.EndsWith(".pfb") || fn.EndsWith(".PFB") || fn.EndsWith(".ttf") || fn.EndsWith(".TTF") || fn.EndsWith(".otf") || fn.EndsWith(".OTF")) {
2714  ttfont = kTRUE;
2715  }
2716 
2717  if (color) {
2718  parse_argb_color(color, &text_color);
2719  }
2720 
2721  if (fImage && fImage->alt.argb32 && ttfont) {
2722  DrawTextTTF(x, y, text, size, text_color, fn.Data(), angle);
2723  return;
2724  }
2725 
2726  if (!gFontManager) {
2727  gFontManager = create_font_manager(fgVisual->dpy, 0, 0);
2728  }
2729 
2730  if (!gFontManager) {
2731  Warning("DrawText", "cannot create Font Manager");
2732  return;
2733  }
2734 
2735  ASFont *font = get_asfont(gFontManager, fn.Data(), ttindex, size, ASF_GuessWho);
2736 
2737  if (!font) {
2738  Warning("DrawText", "cannot find a font %s", font_name);
2739  return;
2740  }
2741 
2742  get_text_size(text, font, (ASText3DType)type, &width, &height);
2743 
2744  if (!fImage) {
2745  fImage = create_asimage(width, height, 0);
2746  fill_asimage(fgVisual, fImage, 0, 0, width, height, 0xFFFFFFFF);
2747  }
2748 
2749  text_im = draw_text(text, font, (ASText3DType)type, 0);
2750 
2751  ASImage *rimg = fImage;
2752 
2753  if (fore_file) {
2754  ASImage *tmp = file2ASImage(fore_file, 0xFFFFFFFF, SCREEN_GAMMA, 0, 0);
2755  if (tmp) {
2756  if ((tmp->width != width) || (tmp->height != height)) {
2757  fore_im = tile_asimage(fgVisual, tmp, 0, 0, width, height, 0,
2758  ASA_ASImage, GetImageCompression(), GetImageQuality());
2759  }
2760  destroy_asimage(&tmp);
2761  } else {
2762  fore_im = tmp;
2763  }
2764  }
2765 
2766  if (fore_im) {
2767  move_asimage_channel(fore_im, IC_ALPHA, text_im, IC_ALPHA);
2768  destroy_asimage(&text_im);
2769  } else {
2770  fore_im = text_im ;
2771  }
2772 
2773  release_font(font);
2774 
2775  if (fore_im) {
2776  ASImage *rendered_im;
2777  ASImageLayer layers[2];
2778 
2779  init_image_layers(&(layers[0]), 2);
2780  fore_im->back_color = text_color;
2781  layers[0].im = rimg;
2782  layers[0].dst_x = 0;
2783  layers[0].dst_y = 0;
2784  layers[0].clip_width = rimg->width;
2785  layers[0].clip_height = rimg->height;
2786  layers[0].bevel = 0;
2787  layers[1].im = fore_im;
2788  layers[1].dst_x = x;
2789  layers[1].dst_y = y;
2790  layers[1].clip_width = fore_im->width;
2791  layers[1].clip_height = fore_im->height;
2792 
2793  rendered_im = merge_layers(fgVisual, &(layers[0]), 2, rimg->width, rimg->height,
2794  ASA_ASImage, GetImageCompression(), GetImageQuality());
2795 
2796  destroy_asimage(&fore_im);
2797  DestroyImage();
2798  fImage = rendered_im;
2799  UnZoom();
2800  }
2801 }
2802 
2803 ////////////////////////////////////////////////////////////////////////////////
2804 /// Merge two images.
2805 ///
2806 /// op is string which specifies overlay operation. Supported operations are:
2807 ///
2808 /// - add - color addition with saturation
2809 /// - alphablend - alpha-blending
2810 /// - allanon - color values averaging
2811 /// - colorize - hue and saturate bottom image same as top image
2812 /// - darken - use lowest color value from both images
2813 /// - diff - use absolute value of the color difference between two images
2814 /// - dissipate - randomly alpha-blend images
2815 /// - hue - hue bottom image same as top image
2816 /// - lighten - use highest color value from both images
2817 /// - overlay - some weird image overlaying(see GIMP)
2818 /// - saturate - saturate bottom image same as top image
2819 /// - screen - another weird image overlaying(see GIMP)
2820 /// - sub - color substraction with saturation
2821 /// - tint - tinting image with image
2822 /// - value - value bottom image same as top image
2823 
2824 void TASImage::Merge(const TImage *im, const char *op, Int_t x, Int_t y)
2825 {
2826  if (!im) return;
2827 
2828  if (!InitVisual()) {
2829  Warning("Merge", "Visual not initiated");
2830  return;
2831  }
2832 
2833  ASImage *rendered_im;
2834  ASImageLayer layers[2];
2835 
2836  init_image_layers(&(layers[0]), 2);
2837  layers[0].im = fImage;
2838  layers[0].dst_x = 0;
2839  layers[0].dst_y = 0;
2840  layers[0].clip_width = fImage->width;
2841  layers[0].clip_height = fImage->height;
2842  layers[0].bevel = 0;
2843  layers[1].im = ((TASImage*)im)->fImage;
2844  layers[1].dst_x = x;
2845  layers[1].dst_y = y;
2846  layers[1].clip_width = im->GetWidth();
2847  layers[1].clip_height = im->GetHeight();
2848  layers[1].merge_scanlines = blend_scanlines_name2func(op ? op : "add");
2849 
2850  rendered_im = merge_layers(fgVisual, &(layers[0]), 2, fImage->width, fImage->height,
2851  ASA_ASImage, GetImageCompression(), GetImageQuality());
2852 
2853  DestroyImage();
2854  fImage = rendered_im;
2855  UnZoom();
2856 }
2857 
2858 ////////////////////////////////////////////////////////////////////////////////
2859 /// Perform Gaussian blur of the image (useful for drop shadows).
2860 /// - hr - horizontal radius of the blur
2861 /// - vr - vertical radius of the blur
2862 
2864 {
2865  if (!InitVisual()) {
2866  Warning("Blur", "Visual not initiated");
2867  return;
2868  }
2869 
2870  if (!fImage) {
2871  fImage = create_asimage(100, 100, 0);
2872 
2873  if (!fImage) {
2874  Warning("Blur", "Failed to create image");
2875  return;
2876  }
2877 
2878  fill_asimage(fgVisual, fImage, 0, 0, fImage->width, fImage->height, ARGB32_White);
2879  }
2880 
2881  ASImage *rendered_im = blur_asimage_gauss(fgVisual, fImage, hr > 0 ? hr : 3,
2882  vr > 0 ? vr : 3, SCL_DO_ALL,
2883  ASA_ASImage, GetImageCompression(), GetImageQuality());
2884  DestroyImage();
2885  fImage = rendered_im;
2886  UnZoom();
2887 }
2888 
2889 ////////////////////////////////////////////////////////////////////////////////
2890 /// Clone image.
2891 
2892 TObject *TASImage::Clone(const char *newname) const
2893 {
2894  if (!InitVisual() || !fImage) {
2895  Warning("Clone", "Image not initiated");
2896  return 0;
2897  }
2898 
2899  TASImage *im = (TASImage*)TImage::Create();
2900 
2901  if (!im) {
2902  Warning("Clone", "Failed to create image");
2903  return 0;
2904  }
2905 
2906  im->SetName(newname);
2907 
2908  im->fImage = clone_asimage(fImage, SCL_DO_ALL);
2909  im->fMaxValue = fMaxValue;
2910  im->fMinValue = fMinValue;
2911  im->fZoomOffX = fZoomOffX;
2912  im->fZoomOffY = fZoomOffY;
2913  im->fZoomWidth = fZoomWidth;
2914  im->fZoomHeight = fZoomHeight;
2915  im->fZoomUpdate = fZoomUpdate;
2917 
2918  if (fImage->alt.argb32) {
2919  UInt_t sz = fImage->width * fImage->height;
2920  im->fImage->alt.argb32 = (ARGB32*)safemalloc(sz*sizeof(ARGB32));
2921  memcpy(im->fImage->alt.argb32, fImage->alt.argb32, sz * sizeof(ARGB32));
2922  }
2923 
2924  return im;
2925 }
2926 
2927 ////////////////////////////////////////////////////////////////////////////////
2928 /// Reduce color-depth of an image and fills vector of "scientific data"
2929 /// [0...1]
2930 ///
2931 /// Colors are reduced by allocating color cells to most used colors first,
2932 /// and then approximating other colors with those allocated.
2933 ///
2934 /// \param[in] max_colors - maximum size of the colormap.
2935 /// \param[in] dither - number of bits to strip off the color data ( 0...7 )
2936 /// \param[in] opaque_threshold - alpha channel threshold at which pixel should be treated as opaque
2937 
2938 Double_t *TASImage::Vectorize(UInt_t max_colors, UInt_t dither, Int_t opaque_threshold)
2939 {
2940  if (!InitVisual()) {
2941  Warning("Vectorize", "Visual not initiated");
2942  return 0;
2943  }
2944 
2945  if (!fImage) {
2946  fImage = create_asimage(100, 100, 0);
2947 
2948  if (!fImage) {
2949  Warning("Vectorize", "Failed to create image");
2950  return 0;
2951  }
2952 
2953  fill_asimage(fgVisual, fImage, 0, 0, fImage->width, fImage->height, ARGB32_White);
2954  }
2955 
2956  ASColormap cmap;
2957  int *res;
2958  UInt_t r=0, g=0, b=0;
2959 
2960  dither = dither > 7 ? 7 : dither;
2961 
2962  res = colormap_asimage(fImage, &cmap, max_colors, dither, opaque_threshold);
2963 
2964  Double_t *vec = new Double_t[fImage->height*fImage->width];
2965  UInt_t v;
2966  Double_t tmp;
2967  fMinValue = 2;
2968  fMaxValue = -1;
2969 
2970  for (UInt_t y = 0; y < fImage->height; y++) {
2971  for (UInt_t x = 0; x < fImage->width; x++) {
2972  int i = y*fImage->width + x;
2973  if (res) {
2974  g = INDEX_SHIFT_GREEN(cmap.entries[res[i]].green);
2975  b = INDEX_SHIFT_BLUE(cmap.entries[res[i]].blue);
2976  r = INDEX_SHIFT_RED(cmap.entries[res[i]].red);
2977  }
2978  v = MAKE_INDEXED_COLOR24(r,g,b);
2979  v = (v>>12)&0x0FFF;
2980  tmp = Double_t(v)/0x0FFF;
2981  vec[(fImage->height - y - 1)*fImage->width + x] = tmp;
2982  if (fMinValue > tmp) fMinValue = tmp;
2983  if (fMaxValue < tmp) fMaxValue = tmp;
2984  }
2985  }
2986  TImagePalette *pal = new TImagePalette(cmap.count);
2987 
2988  for (UInt_t j = 0; j < cmap.count; j++) {
2989  g = INDEX_SHIFT_GREEN(cmap.entries[j].green);
2990  b = INDEX_SHIFT_BLUE(cmap.entries[j].blue);
2991  r = INDEX_SHIFT_RED(cmap.entries[j].red);
2992  v = MAKE_INDEXED_COLOR24(r,g,b);
2993 
2994  v = (v>>12) & 0x0FFF;
2995  pal->fPoints[j] = Double_t(v)/0x0FFF;
2996 
2997  pal->fColorRed[j] = cmap.entries[j].red << 8;
2998  pal->fColorGreen[j] = cmap.entries[j].green << 8;
2999  pal->fColorBlue[j] = cmap.entries[j].blue << 8;
3000  pal->fColorAlpha[j] = 0xFF00;
3001  }
3002 
3003  destroy_colormap(&cmap, kTRUE);
3004 
3005  fPalette = *pal;
3006  fImage->alt.vector = vec;
3007  UnZoom();
3008  if (res) delete res;
3009  return (Double_t*)fImage->alt.vector;
3010 }
3011 
3012 ////////////////////////////////////////////////////////////////////////////////
3013 /// This function will tile original image to specified size with offsets
3014 /// requested, and then it will go though it and adjust hue, saturation and
3015 /// value of those pixels that have specific hue, set by affected_hue/
3016 /// affected_radius parameters. When affected_radius is greater then 180
3017 /// entire image will be adjusted. Note that since grayscale colors have
3018 /// no hue - the will not get adjusted. Only saturation and value will be
3019 /// adjusted in gray pixels.
3020 ///
3021 /// Hue is measured as an angle on a 360 degree circle, The following is
3022 /// relationship of hue values to regular color names :
3023 /// - red - 0
3024 /// - yellow - 60
3025 /// - green - 120
3026 /// - cyan - 180
3027 /// - blue - 240
3028 /// - magenta - 300
3029 /// - red - 360
3030 ///
3031 /// All the hue values in parameters will be adjusted to fall within 0-360 range.
3032 ///
3033 /// \param[in] hue hue in degrees in range 0-360. This allows to limit
3034 /// impact of color adjustment to affect only limited range of hues.
3035 ///
3036 /// \param[in] radius value in degrees to be used in order to
3037 /// calculate the range of affected hues. Range is determined by
3038 /// substracting and adding this value from/to affected_hue.
3039 ///
3040 /// \param[in] H value by which to change hues in affected range.
3041 /// \param[in] S value by which to change saturation of the pixels in affected hue range.
3042 /// \param[in] V value by which to change Value(brightness) of pixels in affected hue range.
3043 ///
3044 /// \param[in] x,y position on infinite surface tiled with original image, of the
3045 /// left-top corner of the area to be used for new image.
3046 ///
3047 /// \param[in] width, height size of the area of the original image to be used for new image.
3048 /// Default is current width, height of the image.
3049 
3050 void TASImage::HSV(UInt_t hue, UInt_t radius, Int_t H, Int_t S, Int_t V,
3051  Int_t x, Int_t y, UInt_t width, UInt_t height)
3052 {
3053  if (!InitVisual()) {
3054  Warning("HSV", "Visual not initiated");
3055  return;
3056  }
3057 
3058  if (!fImage) {
3059  fImage = create_asimage(width ? width : 20, height ? height : 20, 0);
3060 
3061  if (!fImage) {
3062  Warning("HSV", "Failed to create image");
3063  return;
3064  }
3065 
3066  x = 0;
3067  y = 0;
3068  fill_asimage(fgVisual, fImage, 0, 0, fImage->width, fImage->height, ARGB32_White);
3069  }
3070 
3071  width = !width ? fImage->width : width;
3072  height = !height ? fImage->height : height;
3073 
3074  ASImage *rendered_im = 0;
3075 
3076  if (H || S || V) {
3077  rendered_im = adjust_asimage_hsv(fgVisual, fImage, x, y, width, height,
3078  hue, radius, H, S, V, ASA_ASImage, 100,
3079  ASIMAGE_QUALITY_TOP);
3080  }
3081  if (!rendered_im) {
3082  Warning("HSV", "Failed to create rendered image");
3083  return;
3084  }
3085 
3086  DestroyImage();
3087  fImage = rendered_im;
3088  UnZoom();
3089 }
3090 
3091 ////////////////////////////////////////////////////////////////////////////////
3092 /// Render multipoint gradient inside rectangle of size (width, height)
3093 /// at position (x,y) within the existing image.
3094 ///
3095 /// \param[in] angle Given in degrees. Default is 0. This is the
3096 /// direction of the gradient. Currently the only supported
3097 /// values are 0, 45, 90, 135, 180, 225, 270, 315. 0 means left
3098 /// to right, 90 means top to bottom, etc.
3099 ///
3100 /// \param[in] colors Whitespace-separated list of colors. At least two
3101 /// colors are required. Each color in this list will be visited
3102 /// in turn, at the intervals given by the offsets attribute.
3103 ///
3104 /// \param[in] offsets Whitespace-separated list of floating point values
3105 /// ranging from 0.0 to 1.0. The colors from the colors attribute
3106 /// are given these offsets, and the final gradient is rendered
3107 /// from the combination of the two. If both colors and offsets
3108 /// are given but the number of colors and offsets do not match,
3109 /// the minimum of the two will be used, and the other will be
3110 /// truncated to match. If offsets are not given, a smooth
3111 /// stepping from 0.0 to 1.0 will be used.
3112 
3113 void TASImage::Gradient(UInt_t angle, const char *colors, const char *offsets,
3114  Int_t x, Int_t y, UInt_t width, UInt_t height)
3115 {
3116  if (!InitVisual()) {
3117  Warning("Gradient", "Visual not initiated");
3118  return;
3119  }
3120 
3121  ASImage *rendered_im = 0;
3122  ASGradient gradient;
3123 
3124  int reverse = 0, npoints1 = 0, npoints2 = 0;
3125  char *p;
3126  char *pb;
3127  char ch;
3128  TString str = colors;
3129  TString col;
3130 
3131  if ((angle > 2 * 180 * 15 / 16) || (angle < 2 * 180 * 1 / 16)) {
3132  gradient.type = GRADIENT_Left2Right;
3133  } else if (angle < 2 * 180 * 3 / 16) {
3134  gradient.type = GRADIENT_TopLeft2BottomRight;
3135  } else if (angle < 2 * 180 * 5 / 16) {
3136  gradient.type = GRADIENT_Top2Bottom;
3137  } else if (angle < 2 * 180 * 7 / 16) {
3138  gradient.type = GRADIENT_BottomLeft2TopRight; reverse = 1;
3139  } else if (angle < 2 * 180 * 9 / 16) {
3140  gradient.type = GRADIENT_Left2Right; reverse = 1;
3141  } else if (angle < 2 * 180 * 11 / 16) {
3142  gradient.type = GRADIENT_TopLeft2BottomRight; reverse = 1;
3143  } else if (angle < 2 * 180 * 13 / 16) {
3144  gradient.type = GRADIENT_Top2Bottom; reverse = 1;
3145  } else {
3146  gradient.type = GRADIENT_BottomLeft2TopRight;
3147  }
3148 
3149  for (p = (char*)colors; isspace((int)*p); p++) { }
3150 
3151  for (npoints1 = 0; *p; npoints1++) {
3152  if (*p) {
3153  for ( ; *p && !isspace((int)*p); p++) { }
3154  }
3155  for ( ; isspace((int)*p); p++) { }
3156  }
3157  if (offsets) {
3158  for (p = (char*)offsets; isspace((int)*p); p++) { }
3159 
3160  for (npoints2 = 0; *p; npoints2++) {
3161  if (*p) {
3162  for ( ; *p && !isspace((int)*p); p++) { }
3163  }
3164  for ( ; isspace((int)*p); p++) { }
3165  }
3166  }
3167  if (npoints1 > 1) {
3168  int i;
3169  if (offsets && (npoints1 > npoints2)) npoints1 = npoints2;
3170 
3171  if (!width) {
3172  width = fImage ? fImage->width : 20;
3173  }
3174  if (!height) {
3175  height = fImage ? fImage->height : 20;
3176  }
3177 
3178  gradient.color = new ARGB32[npoints1];
3179  gradient.offset = new double[npoints1];
3180 
3181  for (p = (char*)colors; isspace((int)*p); p++) { }
3182 
3183  for (npoints1 = 0; *p; ) {
3184  pb = p;
3185 
3186  if (*p) {
3187  for ( ; *p && !isspace((int)*p); p++) { }
3188  }
3189  for ( ; isspace((int)*p); p++) { }
3190 
3191  col = str(pb - colors, p - pb);
3192 
3193  if (parse_argb_color(col.Data(), gradient.color + npoints1) != col) {
3194  npoints1++;
3195  } else {
3196  Warning("Gradient", "Failed to parse color [%s] - defaulting to black", pb);
3197  }
3198  }
3199 
3200  if (offsets) {
3201  for (p = (char*)offsets; isspace((int)*p); p++) { }
3202 
3203  for (npoints2 = 0; *p; ) {
3204  pb = p;
3205 
3206  if (*p) {
3207  for ( ; *p && !isspace((int)*p); p++) { }
3208  }
3209  ch = *p; *p = '\0';
3210  gradient.offset[npoints2] = strtod(pb, &pb);
3211 
3212  if (pb == p) npoints2++;
3213  *p = ch;
3214  for ( ; isspace((int)*p); p++) { }
3215  }
3216  } else {
3217  for (npoints2 = 0; npoints2 < npoints1; npoints2++) {
3218  gradient.offset[npoints2] = (double)npoints2 / (npoints1 - 1);
3219  }
3220  }
3221  gradient.npoints = npoints1;
3222 
3223  if (npoints2 && (gradient.npoints > npoints2)) {
3224  gradient.npoints = npoints2;
3225  }
3226  if (reverse) {
3227  for (i = 0; i < gradient.npoints/2; i++) {
3228  int i2 = gradient.npoints - 1 - i;
3229  ARGB32 c = gradient.color[i];
3230  double o = gradient.offset[i];
3231  gradient.color[i] = gradient.color[i2];
3232  gradient.color[i2] = c;
3233  gradient.offset[i] = gradient.offset[i2];
3234  gradient.offset[i2] = o;
3235  }
3236  for (i = 0; i < gradient.npoints; i++) {
3237  gradient.offset[i] = 1.0 - gradient.offset[i];
3238  }
3239  }
3240  rendered_im = make_gradient(fgVisual, &gradient, width, height, SCL_DO_ALL,
3241  ASA_ASImage, GetImageCompression(), GetImageQuality());
3242 
3243  delete [] gradient.color;
3244  delete [] gradient.offset;
3245  }
3246 
3247  if (!rendered_im) { // error
3248  Warning("Gradient", "Failed to create gradient image");
3249  return;
3250  }
3251 
3252  if (!fImage) {
3253  fImage = rendered_im;
3254  return;
3255  }
3256 
3257  ASImageLayer layers[2];
3258 
3259  init_image_layers(&(layers[0]), 2);
3260  layers[0].im = fImage;
3261  layers[0].dst_x = 0;
3262  layers[0].dst_y = 0;
3263  layers[0].clip_width = fImage->width;
3264  layers[0].clip_height = fImage->height;
3265  layers[0].bevel = 0;
3266  layers[1].im = rendered_im;
3267  layers[1].dst_x = x;
3268  layers[1].dst_y = y;
3269  layers[1].clip_width = width;
3270  layers[1].clip_height = height;
3271  layers[1].merge_scanlines = alphablend_scanlines;
3272 
3273  ASImage *merge_im = merge_layers(fgVisual, &(layers[0]), 2, fImage->width, fImage->height,
3274  ASA_ASImage, GetImageCompression(), GetImageQuality());
3275  if (!merge_im) {
3276  Warning("Gradient", "Failed to create merged image");
3277  return;
3278  }
3279 
3280  destroy_asimage(&rendered_im);
3281  DestroyImage();
3282  fImage = merge_im;
3283  UnZoom();
3284 }
3285 
3286 ////////////////////////////////////////////////////////////////////////////////
3287 /// Make component hilite.
3288 /// (used internally)
3289 
3290 static CARD8 MakeComponentHilite(int cmp)
3291 {
3292  if (cmp < 51) {
3293  cmp = 51;
3294  }
3295  cmp = (cmp * 12) / 10;
3296 
3297  return (cmp > 255) ? 255 : cmp;
3298 }
3299 
3300 ////////////////////////////////////////////////////////////////////////////////
3301 /// Calculate highlite color.
3302 /// (used internally)
3303 
3304 static ARGB32 GetHilite(ARGB32 background)
3305 {
3306  return ((MakeComponentHilite((background>>24) & 0x000000FF) << 24) & 0xFF000000) |
3307  ((MakeComponentHilite((background & 0x00FF0000) >> 16) << 16) & 0x00FF0000) |
3308  ((MakeComponentHilite((background & 0x0000FF00) >> 8) << 8) & 0x0000FF00) |
3309  ((MakeComponentHilite((background & 0x000000FF))) & 0x000000FF);
3310 }
3311 
3312 ////////////////////////////////////////////////////////////////////////////////
3313 /// Calculate shadow color.
3314 /// (used internally)
3315 
3316 static ARGB32 GetShadow(ARGB32 background)
3317 {
3318  return (background >> 1) & 0x7F7F7F7F;
3319 }
3320 
3321 ////////////////////////////////////////////////////////////////////////////////
3322 /// Get average.
3323 /// (used internally)
3324 
3325 static ARGB32 GetAverage(ARGB32 foreground, ARGB32 background)
3326 {
3327  CARD16 a, r, g, b;
3328 
3329  a = ARGB32_ALPHA8(foreground) + ARGB32_ALPHA8(background);
3330  a = (a<<3)/10;
3331  r = ARGB32_RED8(foreground) + ARGB32_RED8(background);
3332  r = (r<<3)/10;
3333  g = ARGB32_GREEN8(foreground) + ARGB32_GREEN8(background);
3334  g = (g<<3)/10;
3335  b = ARGB32_BLUE8(foreground) + ARGB32_BLUE8(background);
3336  b = (b<<3)/10;
3337 
3338  return MAKE_ARGB32(a, r, g, b);
3339 }
3340 
3341 
3342 ////////////////////////////////////////////////////////////////////////////////
3343 /// Bevel is used to create 3D effect while drawing buttons, or any other
3344 /// image that needs to be framed. Bevel is drawn using 2 primary colors:
3345 /// one for top and left sides - hi color, and another for bottom and
3346 /// right sides - low color. Bevel can be drawn over existing image or
3347 /// as newly created, as it is shown in code below:
3348 /// ~~~ {.cpp}
3349 /// TImage *img = TImage::Create();
3350 /// img->Bevel(0, 0, 400, 300, "#dddddd", "#000000", 3);
3351 /// ~~~
3352 
3353 void TASImage::Bevel(Int_t x, Int_t y, UInt_t width, UInt_t height,
3354  const char *hi_color, const char *lo_color, UShort_t thick,
3355  Bool_t reverse)
3356 {
3357  if (!InitVisual()) {
3358  Warning("Bevel", "Visual not initiated");
3359  return;
3360  }
3361 
3362  ASImageBevel bevel;
3363  bevel.type = 0;
3364 
3365  ARGB32 hi=ARGB32_White, lo=ARGB32_White;
3366  parse_argb_color(hi_color, &hi);
3367  parse_argb_color(lo_color, &lo);
3368 
3369  if (reverse) {
3370  bevel.lo_color = hi;
3371  bevel.lolo_color = GetHilite(hi);
3372  bevel.hi_color = lo;
3373  bevel.hihi_color = GetShadow(lo);
3374  } else {
3375  bevel.hi_color = hi;
3376  bevel.hihi_color = GetHilite(hi);
3377  bevel.lo_color = lo;
3378  bevel.lolo_color = GetShadow(lo);
3379  }
3380  bevel.hilo_color = GetAverage(hi, lo);
3381 
3382  int extra_hilite = 2;
3383  bevel.left_outline = bevel.top_outline = bevel.right_outline = bevel.bottom_outline = thick;
3384  bevel.left_inline = bevel.top_inline = bevel.right_inline = bevel.bottom_inline = extra_hilite + 1;
3385 
3386  if (bevel.top_outline > 1) {
3387  bevel.top_inline += bevel.top_outline - 1;
3388  }
3389 
3390  if (bevel.left_outline > 1) {
3391  bevel.left_inline += bevel.left_outline - 1;
3392  }
3393 
3394  if (bevel.right_outline > 1) {
3395  bevel.right_inline += bevel.right_outline - 1;
3396  }
3397 
3398  if (bevel.bottom_outline > 1) {
3399  bevel.bottom_inline += bevel.bottom_outline - 1;
3400  }
3401 
3402  ASImage *merge_im;
3403  ARGB32 fill = ((hi>>24) != 0xff) || ((lo>>24) != 0xff) ? bevel.hilo_color : (bevel.hilo_color | 0xff000000);
3404 
3405  if (!fImage) {
3406  fImage = create_asimage(width ? width : 20, height ? height : 20, 0);
3407 
3408  if (!fImage) {
3409  Warning("Bevel", "Failed to create image");
3410  return;
3411  }
3412 
3413  x = 0;
3414  y = 0;
3415  fill_asimage(fgVisual, fImage, 0, 0, fImage->width, fImage->height, fill);
3416  }
3417 
3418  width = !width ? fImage->width : width;
3419  height = !height ? fImage->height : height;
3420 
3421  ASImageLayer layers[2];
3422  init_image_layers(&(layers[0]), 2);
3423 
3424  layers[0].im = fImage;
3425  layers[0].dst_x = 0;
3426  layers[0].dst_y = 0;
3427  layers[0].clip_width = fImage->width;
3428  layers[0].clip_height = fImage->height;
3429  layers[0].bevel = 0;
3430 
3431  UInt_t w = width - (bevel.left_outline + bevel.right_outline);
3432  UInt_t h = height - (bevel.top_outline + bevel.bottom_outline);
3433  ASImage *bevel_im = create_asimage(w, h, 0);
3434 
3435  if (!bevel_im) {
3436  Warning("Bevel", "Failed to create bevel image");
3437  return;
3438  }
3439 
3440  layers[1].im = bevel_im;
3441  fill_asimage(fgVisual, bevel_im, 0, 0, w, h, fill);
3442 
3443  layers[1].dst_x = x;
3444  layers[1].dst_y = y;
3445  layers[1].clip_width = width;
3446  layers[1].clip_height = height;
3447  layers[1].bevel = &bevel;
3448  layers[1].merge_scanlines = alphablend_scanlines;
3449 
3450  merge_im = merge_layers(fgVisual, &(layers[0]), 2, fImage->width, fImage->height,
3451  ASA_ASImage, GetImageCompression(), GetImageQuality());
3452  destroy_asimage(&bevel_im);
3453 
3454  if (!merge_im) {
3455  Warning("Bevel", "Failed to image");
3456  return;
3457  }
3458 
3459  DestroyImage();
3460  fImage = merge_im;
3461  UnZoom();
3462 }
3463 
3464 
3465 ////////////////////////////////////////////////////////////////////////////////
3466 /// Enlarge image, padding it with specified color on each side in
3467 /// accordance with requested geometry.
3468 
3469 void TASImage::Pad(const char *col, UInt_t l, UInt_t r, UInt_t t, UInt_t b)
3470 {
3471  Int_t x, y;
3472  UInt_t w, h;
3473 
3474  if (!InitVisual()) {
3475  Warning("Pad", "Visual not initiated");
3476  return;
3477  }
3478 
3479  if (!fImage) {
3480  fImage = create_asimage(100, 100, 0);
3481 
3482  if (!fImage) {
3483  Warning("Pad", "Failed to create image");
3484  return;
3485  }
3486 
3487  x = 0;
3488  y = 0;
3489  fill_asimage(fgVisual, fImage, 0, 0, fImage->width, fImage->height, ARGB32_White);
3490  }
3491 
3492  ARGB32 color = ARGB32_White;
3493  parse_argb_color(col, &color);
3494 
3495  x = l;
3496  y = t;
3497  w = l + fImage->width + r;
3498  h = t + fImage->height + b;
3499 
3500  ASImage *img = pad_asimage(fgVisual, fImage, x, y, w, h, color,
3501  ASA_ASImage, GetImageCompression(), GetImageQuality());
3502 
3503  if (!img) {
3504  Warning("Pad", "Failed to create output image");
3505  return;
3506  }
3507 
3508  DestroyImage();
3509  fImage = img;
3510  UnZoom();
3512 }
3513 
3514 
3515 ////////////////////////////////////////////////////////////////////////////////
3516 /// Crop an image.
3517 
3518 void TASImage::Crop(Int_t x, Int_t y, UInt_t width, UInt_t height)
3519 {
3520  if (!InitVisual()) {
3521  Warning("Crop", "Visual not initiated");
3522  return;
3523  }
3524 
3525  if (!fImage) {
3526  Warning("Crop", "No image");
3527  return;
3528  }
3529 
3530  x = x < 0 ? 0 : x;
3531  y = y < 0 ? 0 : y;
3532 
3533  width = x + width > fImage->width ? fImage->width - x : width;
3534  height = y + height > fImage->height ? fImage->height - y : height;
3535 
3536  if ((width == fImage->width) && (height == fImage->height)) {
3537  Warning("Crop", "input size larger than image");
3538  return;
3539  }
3540  ASImageDecoder *imdec = start_image_decoding(fgVisual, fImage, SCL_DO_ALL,
3541  x, y, width, height, 0);
3542 
3543  if (!imdec) {
3544  Warning("Crop", "Failed to start image decoding");
3545  return;
3546  }
3547 
3548  ASImage *img = create_asimage(width, height, 0);
3549 
3550  if (!img) {
3551  delete [] imdec;
3552  Warning("Crop", "Failed to create image");
3553  return;
3554  }
3555 
3556  ASImageOutput *imout = start_image_output(fgVisual, img, ASA_ASImage,
3558 
3559  if (!imout) {
3560  Warning("Crop", "Failed to start image output");
3561  destroy_asimage(&img);
3562  if (imdec) delete [] imdec;
3563  return;
3564  }
3565 
3566 #ifdef HAVE_MMX
3567  mmx_init();
3568 #endif
3569 
3570  for (UInt_t i = 0; i < height; i++) {
3571  imdec->decode_image_scanline(imdec);
3572  imout->output_image_scanline(imout, &(imdec->buffer), 1);
3573  }
3574 
3575  stop_image_decoding(&imdec);
3576  stop_image_output(&imout);
3577 
3578 #ifdef HAVE_MMX
3579  mmx_off();
3580 #endif
3581 
3582  DestroyImage();
3583  fImage = img;
3584  UnZoom();
3586 }
3587 
3588 ////////////////////////////////////////////////////////////////////////////////
3589 /// Append image.
3590 ///
3591 /// option:
3592 /// - "+" - appends to the right side
3593 /// - "/" - appends to the bottom
3594 
3595 void TASImage::Append(const TImage *im, const char *option, const char *color )
3596 {
3597  if (!im) return;
3598 
3599  if (!InitVisual()) {
3600  Warning("Append", "Visual not initiated");
3601  return;
3602  }
3603 
3604  if (!fImage) {
3605  fImage = ((TASImage*)im)->fImage;
3606  return;
3607  }
3608 
3609  TString opt = option;
3610  opt.Strip();
3611 
3612  UInt_t width = fImage->width;
3613  UInt_t height = fImage->height;
3614 
3615  if (opt == "+") {
3616  Pad(color, 0, im->GetWidth(), 0, 0);
3617  Merge(im, "alphablend", width, 0);
3618  } else if (opt == "/") {
3619  Pad(color, 0, 0, 0, im->GetHeight());
3620  Merge(im, "alphablend", 0, height);
3621  } else {
3622  return;
3623  }
3624 
3625  UnZoom();
3626 }
3627 
3628 ////////////////////////////////////////////////////////////////////////////////
3629 /// BeginPaint initializes internal array[width x height] of ARGB32 pixel
3630 /// values.
3631 ///
3632 /// That provides quick access to image during paint operations.
3633 /// To RLE compress image one needs to call EndPaint method when painting
3634 /// is over.
3635 
3637 {
3638  if (!InitVisual()) {
3639  Warning("BeginPaint", "Visual not initiated");
3640  return;
3641  }
3642 
3643  if (!fImage) {
3644  return;
3645  }
3646 
3647  fPaintMode = mode;
3648 
3649  if (!fPaintMode || fImage->alt.argb32) {
3650  return;
3651  }
3652 
3653  ASImage *img = tile_asimage(fgVisual, fImage, 0, 0, fImage->width, fImage->height,
3654  0, ASA_ARGB32, 0, ASIMAGE_QUALITY_DEFAULT);
3655 
3656  if (!img) {
3657  Warning("BeginPaint", "Failed to create image");
3658  return;
3659  }
3660 
3661  DestroyImage();
3662  fImage = img;
3663 }
3664 
3665 ////////////////////////////////////////////////////////////////////////////////
3666 /// EndPaint does internal RLE compression of image data.
3667 
3669 {
3670  if (!fImage) {
3671  Warning("EndPaint", "no image");
3672  return;
3673  }
3674 
3675  if (!fImage->alt.argb32) return;
3676 
3677  ASImage *img = tile_asimage(fgVisual, fImage, 0, 0, fImage->width, fImage->height,
3678  0, ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT);
3679 
3680  if (!img) {
3681  Warning("EndPaint", "Failed to create image");
3682  return;
3683  }
3684 
3685  fPaintMode = kFALSE;
3686  DestroyImage();
3687  fImage = img;
3688 }
3689 
3690 ////////////////////////////////////////////////////////////////////////////////
3691 /// Return a pointer to internal array[width x height] of ARGB32 values
3692 /// This array is directly accessible. That allows to manipulate/change the
3693 /// image.
3694 
3696 {
3697  if (!fImage) {
3698  Warning("GetArgbArray", "no image");
3699  return 0;
3700  }
3701 
3702  ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;
3703  if (!img) return 0;
3704 
3705  if (!img->alt.argb32) {
3706  if (fScaledImage) {
3708  img = fScaledImage->fImage;
3709  } else {
3710  BeginPaint();
3711  img = fImage;
3712  }
3713  }
3714 
3715  return (UInt_t *)img->alt.argb32;
3716 }
3717 
3718 ////////////////////////////////////////////////////////////////////////////////
3719 /// Return a pointer to an array[width x height] of RGBA32 values.
3720 /// This array is created from internal ARGB32 array,
3721 /// must be deleted after usage.
3722 
3724 {
3725  if (!fImage) {
3726  Warning("GetRgbaArray", "no image");
3727  return 0;
3728  }
3729 
3730  ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;
3731  if (!img) return 0;
3732 
3733  if (!img->alt.argb32) {
3734  if (fScaledImage) {
3736  img = fScaledImage->fImage;
3737  } else {
3738  BeginPaint();
3739  img = fImage;
3740  }
3741  }
3742 
3743  UInt_t i, j;
3744  Int_t y = 0;
3745  Int_t idx = 0;
3746  UInt_t a, rgb, rgba, argb;
3747  y = 0;
3748 
3749  UInt_t *ret = new UInt_t[img->width*img->height];
3750 
3751  for (i = 0; i < img->height; i++) {
3752  for (j = 0; j < img->width; j++) {
3753  idx = Idx(y + j);
3754  argb = img->alt.argb32[idx];
3755  a = argb >> 24;
3756  rgb = argb & 0x00ffffff;
3757  rgba = (rgb << 8) + a;
3758  ret[idx] = rgba;
3759  }
3760  y += img->width;
3761  }
3762 
3763  return ret;
3764 }
3765 
3766 ////////////////////////////////////////////////////////////////////////////////
3767 /// Return a pointer to scan-line.
3768 
3770 {
3771  if (!fImage) {
3772  Warning("GetScanline", "no image");
3773  return 0;
3774  }
3775 
3776  ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;
3777  CARD32 *ret = new CARD32[img->width];
3778 
3779  ASImageDecoder *imdec = start_image_decoding(fgVisual, img, SCL_DO_ALL,
3780  0, y, img->width, 1, 0);
3781 
3782  if (!imdec) {
3783  delete [] ret;
3784  Warning("GetScanline", "Failed to start image decoding");
3785  return 0;
3786  }
3787 
3788 #ifdef HAVE_MMX
3789  mmx_init();
3790 #endif
3791 
3792  imdec->decode_image_scanline(imdec);
3793  memcpy(imdec->buffer.buffer, ret, img->width*sizeof(CARD32));
3794  stop_image_decoding(&imdec);
3795 
3796 #ifdef HAVE_MMX
3797  mmx_off();
3798 #endif
3799 
3800  return (UInt_t*)ret;
3801 }
3802 
3803 
3804 //______________________________________________________________________________
3805 //
3806 // Vector graphics
3807 // a couple of macros which can be "assembler accelerated"
3808 
3809 #if defined(R__GNU) && defined(__i386__) && !defined(__sun)
3810 #define _MEMSET_(dst, lng, val) __asm__("movl %0,%%eax \n"\
3811  "movl %1,%%edi \n" \
3812  "movl %2,%%ecx \n" \
3813  "cld \n" \
3814  "rep \n" \
3815  "stosl \n" \
3816  : /* no output registers */ \
3817  :"g" (val), "g" (dst), "g" (lng) \
3818  :"eax","edi","ecx" \
3819  )
3820 
3821 #else
3822  #define _MEMSET_(dst, lng, val) do {\
3823  for( UInt_t j=0; j < lng; j++) *((dst)+j) = val; } while (0)
3824 
3825 #endif
3826 
3827 #define FillSpansInternal(npt, ppt, widths, color) do {\
3828  UInt_t yy = ppt[0].fY*fImage->width;\
3829  for (UInt_t i = 0; i < npt; i++) {\
3830  _MEMSET_(&fImage->alt.argb32[Idx(yy + ppt[i].fX)], widths[i], color);\
3831  yy += ((i+1 < npt) && (ppt[i].fY != ppt[i+1].fY) ? fImage->width : 0);\
3832  }\
3833 } while (0)
3834 
3835 ////////////////////////////////////////////////////////////////////////////////
3836 /// Fill rectangle of size (width, height) at position (x,y)
3837 /// within the existing image with specified color.
3838 
3840 {
3841 
3842  if (!InitVisual()) {
3843  Warning("FillRectangle", "Visual not initiated");
3844  return;
3845  }
3846 
3847  if (!fImage) {
3848  Warning("FillRectangle", "no image");
3849  return;
3850  }
3851 
3852  if (!fImage->alt.argb32) {
3853  BeginPaint();
3854  }
3855 
3856  if (!fImage->alt.argb32) {
3857  Warning("FillRectangle", "Failed to get pixel array");
3858  return;
3859  }
3860 
3861  ARGB32 color = (ARGB32)col;
3862 
3863  if (width == 0) width = 1;
3864  if (height == 0) height = 1;
3865 
3866  if (x < 0) {
3867  width += x;
3868  x = 0;
3869  }
3870  if (y < 0) {
3871  height += y;
3872  y = 0;
3873  }
3874 
3875  Bool_t has_alpha = (color & 0xff000000) != 0xff000000;
3876 
3877  x = x > (int)fImage->width ? (Int_t)fImage->width : x;
3878  y = y > (int)fImage->height ? (Int_t)fImage->height : y;
3879 
3880  width = x + width > fImage->width ? fImage->width - x : width;
3881  height = y + height > fImage->height ? fImage->height - y : height;
3882 
3883  if (!fImage->alt.argb32) {
3884  fill_asimage(fgVisual, fImage, x, y, width, height, color);
3885  } else {
3886  int yyy = y*fImage->width;
3887  if (!has_alpha) { // use faster memset
3888  ARGB32 *p0 = fImage->alt.argb32 + yyy + x;
3889  ARGB32 *p = p0;
3890  for (UInt_t i = 0; i < height; i++) {
3891  _MEMSET_(p, width, color);
3892  p += fImage->width;
3893  }
3894  } else {
3895  for (UInt_t i = y; i < y + height; i++) {
3896  int j = x + width;
3897  while (j > x) {
3898  j--;
3899  _alphaBlend(&fImage->alt.argb32[Idx(yyy + j)], &color);
3900  }
3901  yyy += fImage->width;
3902  }
3903  }
3904  }
3905 }
3906 
3907 ////////////////////////////////////////////////////////////////////////////////
3908 /// Fill rectangle of size (width, height) at position (x,y)
3909 /// within the existing image with specified color.
3910 ///
3911 /// To create new image with Fill method the following code can be used:
3912 /// ~~~ {.cpp}
3913 /// TImage *img = TImage::Create();
3914 /// img->Fill("#FF00FF", 0, 0, 400, 300);
3915 /// ~~~
3916 
3917 void TASImage::FillRectangle(const char *col, Int_t x, Int_t y, UInt_t width, UInt_t height)
3918 {
3919  if (!InitVisual()) {
3920  Warning("Fill", "Visual not initiated");
3921  return;
3922  }
3923 
3924  ARGB32 color = ARGB32_White;
3925 
3926  if (col) {
3927  parse_argb_color(col, &color);
3928  }
3929 
3930  if (!fImage) {
3931  fImage = create_asimage(width ? width : 20, height ? height : 20, 0);
3932  x = 0;
3933  y = 0;
3934  }
3935 
3936  FillRectangleInternal((UInt_t)color, x, y, width, height);
3937  UnZoom();
3938 }
3939 
3940 ////////////////////////////////////////////////////////////////////////////////
3941 /// Draw a vertical line.
3942 
3944 {
3945  ARGB32 color = (ARGB32)col;
3946  UInt_t half = 0;
3947 
3948  if (!thick) thick = 1;
3949 
3950  if (thick > 1) {
3951  half = thick >> 1;
3952  if (x > half) {
3953  x = x - half;
3954  } else {
3955  x = 0;
3956  thick += (x - half);
3957  }
3958  }
3959 
3960  y2 = y2 >= fImage->height ? fImage->height - 1 : y2;
3961  y1 = y1 >= fImage->height ? fImage->height - 1 : y1;
3962  x = x + thick >= fImage->width ? fImage->width - thick - 1 : x;
3963 
3964  int yy = y1*fImage->width;
3965  for (UInt_t y = y1; y <= y2; y++) {
3966  for (UInt_t w = 0; w < thick; w++) {
3967  if (x + w < fImage->width) {
3968  _alphaBlend(&fImage->alt.argb32[Idx(yy + (x + w))], &color);
3969  }
3970  }
3971  yy += fImage->width;
3972  }
3973 }
3974 
3975 ////////////////////////////////////////////////////////////////////////////////
3976 /// Draw an horizontal line.
3977 
3979 {
3980  ARGB32 color = (ARGB32)col;
3981  UInt_t half = 0;
3982 
3983  if (!thick) thick = 1;
3984 
3985  if (thick > 1) {
3986  half = thick >> 1;
3987  if (y > half) {
3988  y = y - half;
3989  } else {
3990  y = 0;
3991  thick += (y - half);
3992  }
3993  }
3994 
3995  y = y + thick >= fImage->height ? fImage->height - thick - 1 : y;
3996  x2 = x2 >= fImage->width ? fImage->width - 1 : x2;
3997  x1 = x1 >= fImage->width ? fImage->width - 1 : x1;
3998 
3999  int yy = y*fImage->width;
4000  for (UInt_t w = 0; w < thick; w++) {
4001  for (UInt_t x = x1; x <= x2; x++) {
4002  if (y + w < fImage->height) {
4003  _alphaBlend(&fImage->alt.argb32[Idx(yy + x)], &color);
4004  }
4005  }
4006  yy += fImage->width;
4007  }
4008 }
4009 
4010 ////////////////////////////////////////////////////////////////////////////////
4011 /// Draw a line.
4012 
4014  const char *col, UInt_t thick)
4015 {
4016  ARGB32 color = ARGB32_White;
4017  parse_argb_color(col, &color);
4018  DrawLineInternal(x1, y1, x2, y2, (UInt_t)color, thick);
4019 }
4020 
4021 ////////////////////////////////////////////////////////////////////////////////
4022 /// Internal line drawing.
4023 
4025  UInt_t col, UInt_t thick)
4026 {
4027  int dx, dy, d;
4028  int i1, i2;
4029  int x, y, xend, yend;
4030  int xdir, ydir;
4031  int q;
4032  int idx;
4033  int yy;
4034 
4035  if (!InitVisual()) {
4036  Warning("DrawLine", "Visual not initiated");
4037  return;
4038  }
4039 
4040  if (!fImage) {
4041  Warning("DrawLine", "no image");
4042  return;
4043  }
4044 
4045  if (!fImage->alt.argb32) {
4046  BeginPaint();
4047  }
4048 
4049  if (!fImage->alt.argb32) {
4050  Warning("DrawLine", "Failed to get pixel array");
4051  return;
4052  }
4053 
4054  ARGB32 color = (ARGB32)col;
4055 
4056  dx = TMath::Abs(Int_t(x2) - Int_t(x1));
4057  dy = TMath::Abs(Int_t(y2) - Int_t(y1));
4058 
4059  if (!dx) {
4060  DrawVLine(x1, y2 > y1 ? y1 : y2,
4061  y2 > y1 ? y2 : y1, color, thick);
4062  return;
4063  }
4064 
4065  if (!dy) {
4066  DrawHLine(y1, x2 > x1 ? x1 : x2,
4067  x2 > x1 ? x2 : x1, color, thick);
4068  return;
4069  }
4070 
4071  if (thick > 1) {
4072  DrawWideLine(x1, y1, x2, y2, color, thick);
4073  return;
4074  }
4075 
4076  if (dy <= dx) {
4077  UInt_t ddy = dy << 1;
4078  i1 = ddy;
4079  i2 = i1 - (dx << 1);
4080  d = i1 - dx;
4081 
4082  if (x1 > x2) {
4083  x = x2;
4084  y = y2;
4085  ydir = -1;
4086  xend = x1;
4087  } else {
4088  x = x1;
4089  y = y1;
4090  ydir = 1;
4091  xend = x2;
4092  }
4093 
4094  yy = y*fImage->width;
4095  _alphaBlend(&fImage->alt.argb32[Idx(yy + x)], &color);
4096  q = (y2 - y1) * ydir;
4097 
4098  if (q > 0) {
4099  while (x < xend) {
4100 
4101  idx = Idx(yy + x);
4102  _alphaBlend(&fImage->alt.argb32[idx], &color);
4103  x++;
4104 
4105  if (d >= 0) {
4106  yy += fImage->width;
4107  d += i2;
4108  } else {
4109  d += i1;
4110  }
4111  }
4112  } else {
4113  while (x < xend) {
4114  idx = Idx(yy + x);
4115  _alphaBlend(&fImage->alt.argb32[idx], &color);
4116  x++;
4117 
4118  if (d >= 0) {
4119  yy -= fImage->width;
4120  d += i2;
4121  } else {
4122  d += i1;
4123  }
4124  }
4125  }
4126  } else {
4127  UInt_t ddx = dx << 1;
4128  i1 = ddx;
4129  i2 = i1 - (dy << 1);
4130  d = i1 - dy;
4131 
4132  if (y1 > y2) {
4133  y = y2;
4134  x = x2;
4135  yend = y1;
4136  xdir = -1;
4137  } else {
4138  y = y1;
4139  x = x1;
4140  yend = y2;
4141  xdir = 1;
4142  }
4143 
4144  yy = y*fImage->width;
4145  _alphaBlend(&fImage->alt.argb32[Idx(yy + x)], &color);
4146  q = (x2 - x1) * xdir;
4147 
4148  if (q > 0) {
4149  while (y < yend) {
4150  idx = Idx(yy + x);
4151  _alphaBlend(&fImage->alt.argb32[idx], &color);
4152  y++;
4153  yy += fImage->width;
4154 
4155  if (d >= 0) {
4156  x++;
4157  d += i2;
4158  } else {
4159  d += i1;
4160  }
4161  }
4162  } else {
4163  while (y < yend) {
4164  idx = Idx(yy + x);
4165  _alphaBlend(&fImage->alt.argb32[idx], &color);
4166  y++;
4167  yy += fImage->width;
4168 
4169  if (d >= 0) {
4170  x--;
4171  d += i2;
4172  } else {
4173  d += i1;
4174  }
4175  }
4176  }
4177  }
4178 }
4179 
4180 ////////////////////////////////////////////////////////////////////////////////
4181 /// Draw a rectangle.
4182 
4184  const char *col, UInt_t thick)
4185 {
4186  if (!InitVisual()) {
4187  Warning("DrawRectangle", "Visual not initiated");
4188  return;
4189  }
4190 
4191  if (!fImage) {
4192  w = w ? w : 20;
4193  h = h ? h : 20;
4194  x = 0;
4195  y = 0;
4196  fImage = create_asimage(w, h, 0);
4197  FillRectangle(col, 0, 0, w, h);
4198  return;
4199  }
4200 
4201  if (!fImage->alt.argb32) {
4202  BeginPaint();
4203  }
4204 
4205  if (!fImage->alt.argb32) {
4206  Warning("DrawRectangle", "Failed to get pixel array");
4207  return;
4208  }
4209 
4210  ARGB32 color = ARGB32_White;
4211  parse_argb_color(col, &color);
4212 
4213  DrawHLine(y, x, x + w, (UInt_t)color, thick);
4214  DrawVLine(x + w, y, y + h, (UInt_t)color, thick);
4215  DrawHLine(y + h, x, x + w, (UInt_t)color, thick);
4216  DrawVLine(x, y, y + h, (UInt_t)color, thick);
4217  UnZoom();
4218 }
4219 
4220 ////////////////////////////////////////////////////////////////////////////////
4221 /// Draw a box.
4222 
4223 void TASImage::DrawBox(Int_t x1, Int_t y1, Int_t x2, Int_t y2, const char *col,
4224  UInt_t thick, Int_t mode)
4225 {
4226  Int_t x = TMath::Min(x1, x2);
4227  Int_t y = TMath::Min(y1, y2);
4228  Int_t w = TMath::Abs(x2 - x1);
4229  Int_t h = TMath::Abs(y2 - y1);
4230 
4231  ARGB32 color = ARGB32_White;
4232 
4233  if (!fImage) {
4234  w = w ? x+w : x+20;
4235  h = h ? y+h : y+20;
4236  fImage = create_asimage(w, h, 0);
4237  FillRectangle(col, 0, 0, w, h);
4238  return;
4239  }
4240 
4241  if (x1 == x2) {
4242  parse_argb_color(col, &color);
4243  DrawVLine(x1, y1, y2, color, 1);
4244  return;
4245  }
4246 
4247  if (y1 == y2) {
4248  parse_argb_color(col, &color);
4249  DrawHLine(y1, x1, x2, color, 1);
4250  return;
4251  }
4252 
4253 
4254  switch (mode) {
4255  case TVirtualX::kHollow:
4256  DrawRectangle(x, y, w, h, col, thick);
4257  break;
4258 
4259  case TVirtualX::kFilled:
4260  FillRectangle(col, x, y, w, h);
4261  break;
4262 
4263  default:
4264  FillRectangle(col, x, y, w, h);
4265  break;
4266  }
4267 }
4268 
4269 ////////////////////////////////////////////////////////////////////////////////
4270 /// Draw a dashed horizontal line.
4271 
4273  const char *pDash, UInt_t col, UInt_t thick)
4274 {
4275  UInt_t iDash = 0; // index of current dash
4276  int i = 0;
4277 
4278  ARGB32 color = (ARGB32)col;
4279 
4280  UInt_t half = 0;
4281 
4282  if (thick > 1) {
4283  half = thick >> 1;
4284  if (y > half) {
4285  y = y - half;
4286  } else {
4287  y = 0;
4288  thick += (y - half);
4289  }
4290  }
4291  thick = thick <= 0 ? 1 : thick;
4292 
4293  y = y + thick >= fImage->height ? fImage->height - thick - 1 : y;
4294  x2 = x2 >= fImage->width ? fImage->width - 1 : x2;
4295  x1 = x1 >= fImage->width ? fImage->width - 1 : x1;
4296 
4297  // switch x1, x2
4298  UInt_t tmp = x1;
4299  x1 = x2 < x1 ? x2 : x1;
4300  x2 = x2 < tmp ? tmp : x2;
4301 
4302  for (UInt_t x = x1; x <= x2; x++) {
4303  for (UInt_t w = 0; w < thick; w++) {
4304  if (y + w < fImage->height) {
4305  if ((iDash%2)==0) {
4306  _alphaBlend(&fImage->alt.argb32[Idx((y + w)*fImage->width + x)], &color);
4307  }
4308  }
4309  }
4310  i++;
4311 
4312  if (i >= pDash[iDash]) {
4313  iDash++;
4314  i = 0;
4315  }
4316  if (iDash >= nDash) {
4317  iDash = 0;
4318  i = 0;
4319  }
4320  }
4321 }
4322 
4323 ////////////////////////////////////////////////////////////////////////////////
4324 /// Draw a dashed vertical line.
4325 
4327  const char *pDash, UInt_t col, UInt_t thick)
4328 {
4329  UInt_t iDash = 0; // index of current dash
4330  int i = 0;
4331 
4332  ARGB32 color = (ARGB32)col;
4333 
4334  UInt_t half = 0;
4335 
4336  if (thick > 1) {
4337  half = thick >> 1;
4338  if (x > half) {
4339  x = x - half;
4340  } else {
4341  x = 0;
4342  thick += (x - half);
4343  }
4344  }
4345  thick = thick <= 0 ? 1 : thick;
4346 
4347  y2 = y2 >= fImage->height ? fImage->height - 1 : y2;
4348  y1 = y1 >= fImage->height ? fImage->height - 1 : y1;
4349 
4350  // switch x1, x2
4351  UInt_t tmp = y1;
4352  y1 = y2 < y1 ? y2 : y1;
4353  y2 = y2 < tmp ? tmp : y2;
4354 
4355  x = x + thick >= fImage->width ? fImage->width - thick - 1 : x;
4356 
4357  int yy = y1*fImage->width;
4358  for (UInt_t y = y1; y <= y2; y++) {
4359  for (UInt_t w = 0; w < thick; w++) {
4360  if (x + w < fImage->width) {
4361  if ((iDash%2)==0) {
4362  _alphaBlend(&fImage->alt.argb32[Idx(yy + (x + w))], &color);
4363  }
4364  }
4365  }
4366  i++;
4367 
4368  if (i >= pDash[iDash]) {
4369  iDash++;
4370  i = 0;
4371  }
4372  if (iDash >= nDash) {
4373  iDash = 0;
4374  i = 0;
4375  }
4376  yy += fImage->width;
4377  }
4378 }
4379 
4380 ////////////////////////////////////////////////////////////////////////////////
4381 /// Draw a dashed line with one pixel width.
4382 
4384  UInt_t nDash, const char *tDash, UInt_t color)
4385 {
4386  int dx, dy, d;
4387  int i, i1, i2;
4388  int x, y, xend, yend;
4389  int xdir, ydir;
4390  int q;
4391  UInt_t iDash = 0; // index of current dash
4392  int yy;
4393  int idx;
4394 
4395  dx = TMath::Abs(Int_t(x2) - Int_t(x1));
4396  dy = TMath::Abs(Int_t(y2) - Int_t(y1));
4397 
4398  char *pDash = new char[nDash];
4399 
4400  if (dy <= dx) {
4401  double ac = TMath::Cos(TMath::ATan2(dy, dx));
4402 
4403  for (i = 0; i < (int)nDash; i++) {
4404  pDash[i] = TMath::Nint(tDash[i] * ac);
4405  }
4406 
4407  UInt_t ddy = dy << 1;
4408  i1 = ddy;
4409  i2 = i1 - (dx << 1);
4410  d = i1 - dx;
4411  i = 0;
4412 
4413  if (x1 > x2) {
4414  x = x2;
4415  y = y2;
4416  ydir = -1;
4417  xend = x1;
4418  } else {
4419  x = x1;
4420  y = y1;
4421  ydir = 1;
4422  xend = x2;
4423  }
4424 
4425  yy = y*fImage->width;
4426  _alphaBlend(&fImage->alt.argb32[Idx(y*fImage->width + x)], &color);
4427  q = (y2 - y1) * ydir;
4428 
4429  if (q > 0) {
4430  while (x < xend) {
4431  idx = Idx(yy + x);
4432  if ((iDash%2) == 0) {
4433  _alphaBlend(&fImage->alt.argb32[idx], &color);
4434  }
4435  x++;
4436  if (d >= 0) {
4437  yy += fImage->width;
4438  d += i2;
4439  } else {
4440  d += i1;
4441  }
4442 
4443  i++;
4444  if (i >= pDash[iDash]) {
4445  iDash++;
4446  i = 0;
4447  }
4448  if (iDash >= nDash) {
4449  iDash = 0;
4450  i = 0;
4451  }
4452  }
4453  } else {
4454  while (x < xend) {
4455  idx = Idx(yy + x);
4456  if ((iDash%2) == 0) {
4457  _alphaBlend(&fImage->alt.argb32[idx], &color);
4458  }
4459  x++;
4460  if (d >= 0) {
4461  yy -= fImage->width;
4462  d += i2;
4463  } else {
4464  d += i1;
4465  }
4466 
4467  i++;
4468  if (i >= pDash[iDash]) {
4469  iDash++;
4470  i = 0;
4471  }
4472  if (iDash >= nDash) {
4473  iDash = 0;
4474  i = 0;
4475  }
4476  }
4477  }
4478  } else {
4479  double as = TMath::Sin(TMath::ATan2(dy, dx));
4480 
4481  for (i = 0; i < (int)nDash; i++) {
4482  pDash[i] = TMath::Nint(tDash[i] * as);
4483  }
4484 
4485  UInt_t ddx = dx << 1;
4486  i1 = ddx;
4487  i2 = i1 - (dy << 1);
4488  d = i1 - dy;
4489  i = 0;
4490 
4491  if (y1 > y2) {
4492  y = y2;
4493  x = x2;
4494  yend = y1;
4495  xdir = -1;
4496  } else {
4497  y = y1;
4498  x = x1;
4499  yend = y2;
4500  xdir = 1;
4501  }
4502 
4503  yy = y*fImage->width;
4504  _alphaBlend(&fImage->alt.argb32[Idx(y*fImage->width + x)], &color);
4505  q = (x2 - x1) * xdir;
4506 
4507  if (q > 0) {
4508  while (y < yend) {
4509  idx = Idx(yy + x);
4510  if ((iDash%2) == 0) {
4511  _alphaBlend(&fImage->alt.argb32[idx], &color);
4512  }
4513  y++;
4514  yy += fImage->width;
4515 
4516  if (d >= 0) {
4517  x++;
4518  d += i2;
4519  } else {
4520  d += i1;
4521  }
4522 
4523  i++;
4524  if (i >= pDash[iDash]) {
4525  iDash++;
4526  i = 0;
4527  }
4528  if (iDash >= nDash) {
4529  iDash = 0;
4530  i = 0;
4531  }
4532  }
4533  } else {
4534  while (y < yend) {
4535  idx = Idx(yy + x);
4536  if ((iDash%2) == 0) {
4537  _alphaBlend(&fImage->alt.argb32[idx], &color);
4538  }
4539  y++;
4540  yy += fImage->width;
4541 
4542  if (d >= 0) {
4543  x--;
4544  d += i2;
4545  } else {
4546  d += i1;
4547  }
4548 
4549  i++;
4550  if (i >= pDash[iDash]) {
4551  iDash++;
4552  i = 0;
4553  }
4554  if (iDash >= nDash) {
4555  iDash = 0;
4556  i = 0;
4557  }
4558  }
4559  }
4560  }
4561  delete [] pDash;
4562 }
4563 
4564 ////////////////////////////////////////////////////////////////////////////////
4565 /// Draw a dashed line with thick pixel width.
4566 
4568  UInt_t nDash, const char *tDash, UInt_t color, UInt_t thick)
4569 {
4570  int dx, dy;
4571  int i;
4572  double x, y, xend=0, yend=0, x0, y0;
4573  int xdir, ydir;
4574  int q;
4575  UInt_t iDash = 0; // index of current dash
4576 
4577  dx = TMath::Abs(Int_t(x2) - Int_t(x1));
4578  dy = TMath::Abs(Int_t(y2) - Int_t(y1));
4579 
4580  double *xDash = new double[nDash];
4581  double *yDash = new double[nDash];
4582  double a = TMath::ATan2(dy, dx);
4583  double ac = TMath::Cos(a);
4584  double as = TMath::Sin(a);
4585 
4586  for (i = 0; i < (int)nDash; i++) {
4587  xDash[i] = tDash[i] * ac;
4588  yDash[i] = tDash[i] * as;
4589 
4590  // dirty trick (must be fixed)
4591  if ((i%2) == 0) {
4592  xDash[i] = xDash[i]/2;
4593  yDash[i] = yDash[i]/2;
4594  } else {
4595  xDash[i] = xDash[i]*2;
4596  yDash[i] = yDash[i]*2;
4597  }
4598  }
4599 
4600  if (dy <= dx) {
4601  if (x1 > x2) {
4602  x = x2;
4603  y = y2;
4604  ydir = -1;
4605  xend = x1;
4606  } else {
4607  x = x1;
4608  y = y1;
4609  ydir = 1;
4610  xend = x2;
4611  }
4612 
4613  q = (y2 - y1) * ydir;
4614  x0 = x;
4615  y0 = y;
4616  iDash = 0;
4617  yend = y + q;
4618 
4619  if (q > 0) {
4620  while ((x < xend) && (y < yend)) {
4621  x += xDash[iDash];
4622  y += yDash[iDash];
4623 
4624  if ((iDash%2) == 0) {
4626  TMath::Nint(x), TMath::Nint(y), color, thick);
4627  } else {
4628  x0 = x;
4629  y0 = y;
4630  }
4631 
4632  iDash++;
4633 
4634  if (iDash >= nDash) {
4635  iDash = 0;
4636  }
4637  }
4638  } else {
4639  while ((x < xend) && (y > yend)) {
4640  x += xDash[iDash];
4641  y -= yDash[iDash];
4642 
4643  if ((iDash%2) == 0) {
4645  TMath::Nint(x), TMath::Nint(y), color, thick);
4646  } else {
4647  x0 = x;
4648  y0 = y;
4649  }
4650 
4651  iDash++;
4652 
4653  if (iDash >= nDash) {
4654  iDash = 0;
4655  }
4656  }
4657  }
4658  } else {
4659 
4660  if (y1 > y2) {
4661  y = y2;
4662  x = x2;
4663  yend = y1;
4664  xdir = -1;
4665  } else {
4666  y = y1;
4667  x = x1;
4668  yend = y2;
4669  xdir = 1;
4670  }
4671 
4672  q = (x2 - x1) * xdir;
4673  x0 = x;
4674  y0 = y;
4675  iDash = 0;
4676  xend = x + q;
4677 
4678  if (q > 0) {
4679  while ((x < xend) && (y < yend)) {
4680  x += xDash[iDash];
4681  y += yDash[iDash];
4682 
4683  if ((iDash%2) == 0) {
4685  TMath::Nint(x), TMath::Nint(y), color, thick);
4686  } else {
4687  x0 = x;
4688  y0 = y;
4689  }
4690 
4691  iDash++;
4692 
4693  if (iDash >= nDash) {
4694  iDash = 0;
4695  }
4696  }
4697  } else {
4698  while ((x > xend) && (y < yend)) {
4699  x -= xDash[iDash];
4700  y += yDash[iDash];
4701 
4702  if ((iDash%2) == 0) {
4704  TMath::Nint(x), TMath::Nint(y), color, thick);
4705  } else {
4706  x0 = x;
4707  y0 = y;
4708  }
4709 
4710  iDash++;
4711 
4712  if (iDash >= nDash) {
4713  iDash = 0;
4714  }
4715  }
4716  }
4717  }
4718  delete [] xDash;
4719  delete [] yDash;
4720 }
4721 
4722 ////////////////////////////////////////////////////////////////////////////////
4723 /// Draw a dashed line.
4724 
4726  const char *pDash, const char *col, UInt_t thick)
4727 
4728 {
4729  if (!InitVisual()) {
4730  Warning("DrawDashLine", "Visual not initiated");
4731  return;
4732  }
4733 
4734  if (!fImage) {
4735  Warning("DrawDashLine", "no image");
4736  return;
4737  }
4738 
4739  if (!fImage->alt.argb32) {
4740  BeginPaint();
4741  }
4742 
4743  if (!fImage->alt.argb32) {
4744  Warning("DrawDashLine", "Failed to get pixel array");
4745  return;
4746  }
4747 
4748  if ((nDash < 2) || !pDash || (nDash%2)) {
4749  Warning("DrawDashLine", "Wrong input parameters n=%d %ld", nDash, (Long_t)sizeof(pDash)-1);
4750  return;
4751  }
4752 
4753  ARGB32 color = ARGB32_White;
4754  parse_argb_color(col, &color);
4755 
4756  if (x1 == x2) {
4757  DrawDashVLine(x1, y1, y2, nDash, pDash, (UInt_t)color, thick);
4758  } else if (y1 == y2) {
4759  DrawDashHLine(y1, x1, x2, nDash, pDash, (UInt_t)color, thick);
4760  } else {
4761  if (thick < 2) DrawDashZLine(x1, y1, x2, y2, nDash, pDash, (UInt_t)color);
4762  else DrawDashZTLine(x1, y1, x2, y2, nDash, pDash, (UInt_t)color, thick);
4763  }
4764 }
4765 
4766 ////////////////////////////////////////////////////////////////////////////////
4767 /// Draw a polyline.
4768 
4769 void TASImage::DrawPolyLine(UInt_t nn, TPoint *xy, const char *col, UInt_t thick,
4770  TImage::ECoordMode mode)
4771 {
4772  ARGB32 color = ARGB32_White;
4773  parse_argb_color(col, &color);
4774 
4775  Int_t x0 = xy[0].GetX();
4776  Int_t y0 = xy[0].GetY();
4777  Int_t x = 0;
4778  Int_t y = 0;
4779 
4780  for (UInt_t i = 1; i < nn; i++) {
4781  x = (mode == kCoordModePrevious) ? x + xy[i].GetX() : xy[i].GetX();
4782  y = (mode == kCoordModePrevious) ? y + xy[i].GetY() : xy[i].GetY();
4783 
4784  DrawLineInternal(x0, y0, x, y, (UInt_t)color, thick);
4785 
4786  x0 = x;
4787  y0 = y;
4788  }
4789 }
4790 
4791 ////////////////////////////////////////////////////////////////////////////////
4792 /// Draw a point at the specified position.
4793 
4794 void TASImage::PutPixel(Int_t x, Int_t y, const char *col)
4795 {
4796  if (!InitVisual()) {
4797  Warning("PutPixel", "Visual not initiated");
4798  return;
4799  }
4800 
4801  if (!fImage) {
4802  Warning("PutPixel", "no image");
4803  return;
4804  }
4805 
4806  if (!fImage->alt.argb32) {
4807  BeginPaint();
4808  }
4809 
4810  if (!fImage->alt.argb32) {
4811  Warning("PutPixel", "Failed to get pixel array");
4812  return;
4813  }
4814 
4815  ARGB32 color;
4816  parse_argb_color(col, &color);
4817 
4818  if ((x < 0) || (y < 0) || (x >= (int)fImage->width) || (y >= (int)fImage->height)) {
4819  Warning("PutPixel", "Out of range width=%d x=%d, height=%d y=%d",
4820  fImage->width, x, fImage->height, y);
4821  return;
4822  }
4823  _alphaBlend(&fImage->alt.argb32[Idx(y*fImage->width + x)], &color);
4824 }
4825 
4826 ////////////////////////////////////////////////////////////////////////////////
4827 /// Draw a poly point.
4828 
4829 void TASImage::PolyPoint(UInt_t npt, TPoint *ppt, const char *col, TImage::ECoordMode mode)
4830 {
4831  if (!InitVisual()) {
4832  Warning("PolyPoint", "Visual not initiated");
4833  return;
4834  }
4835 
4836  if (!fImage) {
4837  Warning("PolyPoint", "no image");
4838  return;
4839  }
4840 
4841  if (!fImage->alt.argb32) {
4842  BeginPaint();
4843  }
4844 
4845  if (!fImage->alt.argb32) {
4846  Warning("PolyPoint", "Failed to get pixel array");
4847  return;
4848  }
4849 
4850  if (!npt || !ppt) {
4851  Warning("PolyPoint", "No points specified");
4852  return;
4853  }
4854 
4855  TPoint *ipt = 0;
4856  UInt_t i = 0;
4857  ARGB32 color;
4858  parse_argb_color(col, &color);
4859 
4860  //make pointlist origin relative
4861  if (mode == kCoordModePrevious) {
4862  ipt = new TPoint[npt];
4863 
4864  for (i = 0; i < npt; i++) {
4865  ipt[i].fX += ppt[i].fX;
4866  ipt[i].fY += ppt[i].fY;
4867  }
4868  }
4869  int x, y;
4870 
4871  for (i = 0; i < npt; i++) {
4872  x = ipt ? ipt[i].fX : ppt[i].fX;
4873  y = ipt ? ipt[i].fY : ppt[i].fY;
4874 
4875  if ((x < 0) || (y < 0) || (x >= (int)fImage->width) || (y >= (int)fImage->height)) {
4876  continue;
4877  }
4878  _alphaBlend(&fImage->alt.argb32[Idx(y*fImage->width + x)], &color);
4879  }
4880 
4881  if (ipt) {
4882  delete [] ipt;
4883  }
4884 }
4885 
4886 ////////////////////////////////////////////////////////////////////////////////
4887 /// Draw segments.
4888 
4889 void TASImage::DrawSegments(UInt_t nseg, Segment_t *seg, const char *col, UInt_t thick)
4890 {
4891  if (!nseg || !seg) {
4892  Warning("DrawSegments", "Invalid data nseg=%d seg=0x%lx", nseg, (Long_t)seg);
4893  return;
4894  }
4895 
4896  TPoint pt[2];
4897 
4898  for (UInt_t i = 0; i < nseg; i++) {
4899  pt[0].fX = seg->fX1;
4900  pt[1].fX = seg->fX2;
4901  pt[0].fY = seg->fY1;
4902  pt[1].fY = seg->fY2;
4903 
4904  DrawPolyLine(2, pt, col, thick, kCoordModeOrigin);
4905  seg++;
4906  }
4907 }
4908 
4909 ////////////////////////////////////////////////////////////////////////////////
4910 /// Fill spans with specified color or/and stipple.
4911 
4912 void TASImage::FillSpans(UInt_t npt, TPoint *ppt, UInt_t *widths, const char *col,
4913  const char *stipple, UInt_t w, UInt_t h)
4914 {
4915  if (!InitVisual()) {
4916  Warning("FillSpans", "Visual not initiated");
4917  return;
4918  }
4919 
4920  if (!fImage) {
4921  Warning("FillSpans", "no image");
4922  return;
4923  }
4924 
4925  if (!fImage->alt.argb32) {
4926  BeginPaint();
4927  }
4928 
4929  if (!fImage->alt.argb32) {
4930  Warning("FillSpans", "Failed to get pixel array");
4931  return;
4932  }
4933 
4934  if (!npt || !ppt || !widths || (stipple && (!w || !h))) {
4935  Warning("FillSpans", "Invalid input data npt=%d ppt=0x%lx col=%s widths=0x%lx stipple=0x%lx w=%d h=%d",
4936  npt, (Long_t)ppt, col, (Long_t)widths, (Long_t)stipple, w, h);
4937  return;
4938  }
4939 
4940  ARGB32 color;
4941  parse_argb_color(col, &color);
4942  Int_t idx = 0;
4943  UInt_t x = 0;
4944  UInt_t yy;
4945 
4946  for (UInt_t i = 0; i < npt; i++) {
4947  yy = ppt[i].fY*fImage->width;
4948  for (UInt_t j = 0; j < widths[i]; j++) {
4949  if ((ppt[i].fX >= (Int_t)fImage->width) || (ppt[i].fX < 0) ||
4950  (ppt[i].fY >= (Int_t)fImage->height) || (ppt[i].fY < 0)) continue;
4951 
4952  x = ppt[i].fX + j;
4953  idx = Idx(yy + x);
4954 
4955  if (!stipple) {
4956  _alphaBlend(&fImage->alt.argb32[idx], &color);
4957  } else {
4958  Int_t ii = (ppt[i].fY%h)*w + x%w;
4959 
4960  if (stipple[ii >> 3] & (1 << (ii%8))) {
4961  _alphaBlend(&fImage->alt.argb32[idx], &color);
4962  }
4963  }
4964  }
4965  }
4966 }
4967 
4968 ////////////////////////////////////////////////////////////////////////////////
4969 /// Fill spans with tile image.
4970 
4971 void TASImage::FillSpans(UInt_t npt, TPoint *ppt, UInt_t *widths, TImage *tile)
4972 {
4973  if (!InitVisual()) {
4974  Warning("FillSpans", "Visual not initiated");
4975  return;
4976  }
4977 
4978  if (!fImage) {
4979  Warning("FillSpans", "no image");
4980  return;
4981  }
4982 
4983  if (!fImage->alt.argb32) {
4984  BeginPaint();
4985  }
4986 
4987  if (!fImage->alt.argb32) {
4988  Warning("FillSpans", "Failed to get pixel array");
4989  return;
4990  }
4991 
4992  if (!npt || !ppt || !widths || !tile) {
4993  Warning("FillSpans", "Invalid input data npt=%d ppt=0x%lx widths=0x%lx tile=0x%lx",
4994  npt, (Long_t)ppt, (Long_t)widths, (Long_t)tile);
4995  return;
4996  }
4997 
4998  Int_t idx = 0;
4999  Int_t ii = 0;
5000  UInt_t x = 0;
5001  UInt_t *arr = tile->GetArgbArray();
5002  if (!arr) return;
5003  UInt_t xx = 0;
5004  UInt_t yy = 0;
5005  UInt_t yyy = 0;
5006 
5007  for (UInt_t i = 0; i < npt; i++) {
5008  yyy = ppt[i].fY*fImage->width;
5009 
5010  for (UInt_t j = 0; j < widths[i]; j++) {
5011  if ((ppt[i].fX >= (Int_t)fImage->width) || (ppt[i].fX < 0) ||
5012  (ppt[i].fY >= (Int_t)fImage->height) || (ppt[i].fY < 0)) continue;
5013  x = ppt[i].fX + j;
5014  idx = Idx(yyy + x);
5015  xx = x%tile->GetWidth();
5016  yy = ppt[i].fY%tile->GetHeight();
5017  ii = yy*tile->GetWidth() + xx;
5018  _alphaBlend(&fImage->alt.argb32[idx], &arr[ii]);
5019  }
5020  yyy += fImage->width;;
5021  }
5022 }
5023 
5024 ////////////////////////////////////////////////////////////////////////////////
5025 /// Crop spans.
5026 
5027 void TASImage::CropSpans(UInt_t npt, TPoint *ppt, UInt_t *widths)
5028 {
5029  if (!InitVisual()) {
5030  Warning("CropSpans", "Visual not initiated");
5031  return;
5032  }
5033 
5034  if (!fImage) {
5035  Warning("CropSpans", "no image");
5036  return;
5037  }
5038 
5039  if (!fImage->alt.argb32) {
5040  BeginPaint();
5041  }
5042 
5043  if (!fImage->alt.argb32) {
5044  Warning("CropSpans", "Failed to get pixel array");
5045  return;
5046  }
5047 
5048  if (!npt || !ppt || !widths) {
5049  Warning("CropSpans", "No points specified npt=%d ppt=0x%lx widths=0x%lx", npt, (Long_t)ppt, (Long_t)widths);
5050  return;
5051  }
5052 
5053  int y0 = ppt[0].fY;
5054  int y1 = ppt[npt-1].fY;
5055  UInt_t y = 0;
5056  UInt_t x = 0;
5057  UInt_t i = 0;
5058  UInt_t idx = 0;
5059  UInt_t sz = fImage->width*fImage->height;
5060  UInt_t yy = y*fImage->width;
5061 
5062  for (y = 0; (int)y < y0; y++) {
5063  for (x = 0; x < fImage->width; x++) {
5064  idx = Idx(yy + x);
5065  if (idx < sz) fImage->alt.argb32[idx] = 0;
5066  }
5067  yy += fImage->width;
5068  }
5069 
5070  for (i = 0; i < npt; i++) {
5071  for (x = 0; (int)x < ppt[i].fX; x++) {
5072  idx = Idx(ppt[i].fY*fImage->width + x);
5073  if (idx < sz) fImage->alt.argb32[idx] = 0;
5074  }
5075  for (x = ppt[i].fX + widths[i] + 1; x < fImage->width; x++) {
5076  idx = Idx(ppt[i].fY*fImage->width + x);
5077  if (idx < sz) fImage->alt.argb32[idx] = 0;
5078  }
5079  }
5080 
5081  yy = y1*fImage->width;
5082  for (y = y1; y < fImage->height; y++) {
5083  for (x = 0; x < fImage->width; x++) {
5084  idx = Idx(yy + x);
5085  if (idx < sz) fImage->alt.argb32[idx] = 0;
5086  }
5087  yy += fImage->width;
5088  }
5089 }
5090 
5091 ////////////////////////////////////////////////////////////////////////////////
5092 /// Copy source region to the destination image. Copy is done according
5093 /// to specified function:
5094 /// ~~~ {.cpp}
5095 /// enum EGraphicsFunction {
5096 /// kGXclear = 0, // 0
5097 /// kGXand, // src AND dst
5098 /// kGXandReverse, // src AND NOT dst
5099 /// kGXcopy, // src (default)
5100 /// kGXandInverted, // NOT src AND dst
5101 /// kGXnoop, // dst
5102 /// kGXxor, // src XOR dst
5103 /// kGXor, // src OR dst
5104 /// kGXnor, // NOT src AND NOT dst
5105 /// kGXequiv, // NOT src XOR dst
5106 /// kGXinvert, // NOT dst
5107 /// kGXorReverse, // src OR NOT dst
5108 /// kGXcopyInverted, // NOT src
5109 /// kGXorInverted, // NOT src OR dst
5110 /// kGXnand, // NOT src OR NOT dst
5111 /// kGXset // 1
5112 /// };
5113 /// ~~~
5114 
5115 void TASImage::CopyArea(TImage *dst, Int_t xsrc, Int_t ysrc, UInt_t w, UInt_t h,
5116  Int_t xdst, Int_t ydst, Int_t gfunc, EColorChan)
5117 {
5118  if (!InitVisual()) {
5119  Warning("CopyArea", "Visual not initiated");
5120  return;
5121  }
5122 
5123  if (!fImage) {
5124  Warning("CopyArea", "no image");
5125  return;
5126  }
5127  if (!dst) return;
5128 
5129  ASImage *out = ((TASImage*)dst)->GetImage();
5130 
5131  int x = 0;
5132  int y = 0;
5133  int idx = 0;
5134  int idx2 = 0;
5135  xsrc = xsrc < 0 ? 0 : xsrc;
5136  ysrc = ysrc < 0 ? 0 : ysrc;
5137 
5138  if ((xsrc >= (int)fImage->width) || (ysrc >= (int)fImage->height)) return;
5139 
5140  w = xsrc + w > fImage->width ? fImage->width - xsrc : w;
5141  h = ysrc + h > fImage->height ? fImage->height - ysrc : h;
5142  UInt_t yy = (ysrc + y)*fImage->width;
5143 
5144  if (!fImage->alt.argb32) {
5145  BeginPaint();
5146  }
5147  if (!out->alt.argb32) {
5148  dst->BeginPaint();
5149  out = ((TASImage*)dst)->GetImage();
5150  }
5151 
5152  if (fImage->alt.argb32 && out->alt.argb32) {
5153  for (y = 0; y < (int)h; y++) {
5154  for (x = 0; x < (int)w; x++) {
5155  idx = Idx(yy + x + xsrc);
5156  if ((x + xdst < 0) || (ydst + y < 0) ||
5157  (x + xdst >= (int)out->width) || (y + ydst >= (int)out->height) ) continue;
5158 
5159  idx2 = Idx((ydst + y)*out->width + x + xdst);
5160 
5161  switch ((EGraphicsFunction)gfunc) {
5162  case kGXclear:
5163  out->alt.argb32[idx2] = 0;
5164  break;
5165  case kGXand:
5166  out->alt.argb32[idx2] &= fImage->alt.argb32[idx];
5167  break;
5168  case kGXandReverse:
5169  out->alt.argb32[idx2] = fImage->alt.argb32[idx] & (~out->alt.argb32[idx2]);
5170  break;
5171  case kGXandInverted:
5172  out->alt.argb32[idx2] &= ~fImage->alt.argb32[idx];
5173  break;
5174  case kGXnoop:
5175  break;
5176  case kGXxor:
5177  out->alt.argb32[idx2] ^= fImage->alt.argb32[idx];
5178  break;
5179  case kGXor:
5180  out->alt.argb32[idx2] |= fImage->alt.argb32[idx];
5181  break;
5182  case kGXnor:
5183  out->alt.argb32[idx2] = (~fImage->alt.argb32[idx]) & (~out->alt.argb32[idx2]);
5184  break;
5185  case kGXequiv:
5186  out->alt.argb32[idx2] ^= ~fImage->alt.argb32[idx];
5187  break;
5188  case kGXinvert:
5189  out->alt.argb32[idx2] = ~out->alt.argb32[idx2];
5190  break;
5191  case kGXorReverse:
5192  out->alt.argb32[idx2] = fImage->alt.argb32[idx] | (~out->alt.argb32[idx2]);
5193  break;
5194  case kGXcopyInverted:
5195  out->alt.argb32[idx2] = ~fImage->alt.argb32[idx];
5196  break;
5197  case kGXorInverted:
5198  out->alt.argb32[idx2] |= ~fImage->alt.argb32[idx];
5199  break;
5200  case kGXnand:
5201  out->alt.argb32[idx2] = (~fImage->alt.argb32[idx]) | (~out->alt.argb32[idx2]);
5202  break;
5203  case kGXset:
5204  out->alt.argb32[idx2] = 0xFFFFFFFF;
5205  break;
5206  case kGXcopy:
5207  default:
5208  out->alt.argb32[idx2] = fImage->alt.argb32[idx];
5209  break;
5210  }
5211  }
5212  yy += fImage->width;
5213  }
5214  }
5215 }
5216 
5217 ////////////////////////////////////////////////////////////////////////////////
5218 /// Draw a cell array.
5219 ///
5220 /// \param[in] x1,y1 : left down corner
5221 /// \param[in] x2,y2 : right up corner
5222 /// \param[in] nx,ny : array size
5223 /// \param[in] ic : array of ARGB32 colors
5224 ///
5225 /// Draw a cell array. The drawing is done with the pixel precision
5226 /// if (X2-X1)/NX (or Y) is not a exact pixel number the position of
5227 /// the top right corner may be wrong.
5228 
5230  Int_t ny, UInt_t *ic)
5231 {
5232  int i, j, ix, iy, w, h;
5233 
5234  ARGB32 color = 0xFFFFFFFF;
5235  ARGB32 icol;
5236 
5237  w = TMath::Max((x2-x1)/(nx),1);
5238  h = TMath::Max((y1-y2)/(ny),1);
5239  ix = x1;
5240 
5241  for (i = 0; i < nx; i++) {
5242  iy = y1 - h;
5243  for (j = 0; j < ny; j++) {
5244  icol = (ARGB32)ic[i + (nx*j)];
5245  if (icol != color) {
5246  color = icol;
5247  }
5248  FillRectangleInternal((UInt_t)color, ix, iy, w, h);
5249  iy = iy - h;
5250  }
5251  ix = ix + w;
5252  }
5253 }
5254 
5255 ////////////////////////////////////////////////////////////////////////////////
5256 /// Return alpha-blended value computed from bottom and top pixel values.
5257 
5259 {
5260  UInt_t ret = bot;
5261 
5262  _alphaBlend(&ret, &top);
5263  return ret;
5264 }
5265 
5266 ////////////////////////////////////////////////////////////////////////////////
5267 /// Return visual.
5268 
5269 const ASVisual *TASImage::GetVisual()
5270 {
5271  return fgVisual;
5272 }
5273 
5274 ////////////////////////////////////////////////////////////////////////////////
5275 /// Get poly bounds along Y.
5276 
5277 static int GetPolyYBounds(TPoint *pts, int n, int *by, int *ty)
5278 {
5279  TPoint *ptMin;
5280  int ymin, ymax;
5281  TPoint *ptsStart = pts;
5282 
5283  ptMin = pts;
5284  ymin = ymax = (pts++)->fY;
5285 
5286  while (--n > 0) {
5287  if (pts->fY < ymin) {
5288  ptMin = pts;
5289  ymin = pts->fY;
5290  }
5291  if (pts->fY > ymax) {
5292  ymax = pts->fY;
5293  }
5294  pts++;
5295  }
5296 
5297  *by = ymin;
5298  *ty = ymax;
5299  return (ptMin - ptsStart);
5300 }
5301 
5302 ////////////////////////////////////////////////////////////////////////////////
5303 /// The code is based on Xserver/mi/mipolycon.c
5304 /// "Copyright 1987, 1998 The Open Group"
5305 
5307  TPoint **outPoint, UInt_t **outWidth)
5308 {
5309  int xl = 0; // x vals of leftedges
5310  int xr = 0; // x vals of right edges
5311  int dl = 0; // decision variables
5312  int dr = 0; // decision variables
5313  int ml = 0; // left edge slope
5314  int m1l = 0; // left edge slope+1
5315  int mr = 0, m1r = 0; // right edge slope and slope+1
5316  int incr1l = 0, incr2l = 0; // left edge error increments
5317  int incr1r = 0, incr2r = 0; // right edge error increments
5318  int dy; // delta y
5319  int y; // current scanline
5320  int left, right; // indices to first endpoints
5321  int i; // loop counter
5322  int nextleft, nextright; // indices to second endpoints
5323  TPoint *ptsOut; // output buffer
5324  UInt_t *width; // output buffer
5325  TPoint *firstPoint=0;
5326  UInt_t *firstWidth=0;
5327  int imin; // index of smallest vertex (in y)
5328  int ymin; // y-extents of polygon
5329  int ymax;
5330  Bool_t ret = kTRUE;
5331 
5332  *nspans = 0;
5333 
5334  if (!InitVisual()) {
5335  Warning("GetPolygonSpans", "Visual not initiated");
5336  return kFALSE;
5337  }
5338 
5339  if (!fImage) {
5340  Warning("GetPolygonSpans", "no image");
5341  return kFALSE;
5342  }
5343 
5344  if (!fImage->alt.argb32) {
5345  BeginPaint();
5346  }
5347 
5348  if (!fImage->alt.argb32) {
5349  Warning("GetPolygonSpans", "Failed to get pixel array");
5350  return kFALSE;
5351  }
5352 
5353  if ((npt < 3) || !ppt) {
5354  Warning("GetPolygonSpans", "No points specified npt=%d ppt=0x%lx", npt, (Long_t)ppt);
5355  return kFALSE;
5356  }
5357 
5358  // find leftx, bottomy, rightx, topy, and the index
5359  // of bottomy. Also translate the points.
5360  imin = GetPolyYBounds(ppt, npt, &ymin, &ymax);
5361 
5362  dy = ymax - ymin + 1;
5363  if ((npt < 3) || (dy < 0)) return kFALSE;
5364 
5365  ptsOut = firstPoint = new TPoint[dy];
5366  width = firstWidth = new UInt_t[dy];
5367  ret = kTRUE;
5368 
5369  nextleft = nextright = imin;
5370  y = ppt[nextleft].fY;
5371 
5372  // loop through all edges of the polygon
5373  do {
5374  // add a left edge if we need to
5375  if (ppt[nextleft].fY == y) {
5376  left = nextleft;
5377 
5378  // find the next edge, considering the end
5379  // conditions of the array.
5380  nextleft++;
5381  if (nextleft >= (int)npt) {
5382  nextleft = 0;
5383  }
5384 
5385  // now compute all of the random information
5386  // needed to run the iterative algorithm.
5387  BRESINITPGON(ppt[nextleft].fY - ppt[left].fY,
5388  ppt[left].fX, ppt[nextleft].fX,
5389  xl, dl, ml, m1l, incr1l, incr2l);
5390  }
5391 
5392  // add a right edge if we need to
5393  if (ppt[nextright].fY == y) {
5394  right = nextright;
5395 
5396  // find the next edge, considering the end
5397  // conditions of the array.
5398  nextright--;
5399  if (nextright < 0) {
5400  nextright = npt-1;
5401  }
5402 
5403  // now compute all of the random information
5404  // needed to run the iterative algorithm.
5405  BRESINITPGON(ppt[nextright].fY - ppt[right].fY,
5406  ppt[right].fX, ppt[nextright].fX,
5407  xr, dr, mr, m1r, incr1r, incr2r);
5408  }
5409 
5410  // generate scans to fill while we still have
5411  // a right edge as well as a left edge.
5412  i = TMath::Min(ppt[nextleft].fY, ppt[nextright].fY) - y;
5413 
5414  // in case of non-convex polygon
5415  if (i < 0) {
5416  delete [] firstWidth;
5417  delete [] firstPoint;
5418  return kTRUE;
5419  }
5420 
5421  while (i-- > 0) {
5422  ptsOut->fY = y;
5423 
5424  // reverse the edges if necessary
5425  if (xl < xr) {
5426  *(width++) = xr - xl;
5427  (ptsOut++)->fX = xl;
5428  } else {
5429  *(width++) = xl - xr;
5430  (ptsOut++)->fX = xr;
5431  }
5432  y++;
5433 
5434  // increment down the edges
5435  BRESINCRPGON(dl, xl, ml, m1l, incr1l, incr2l);
5436  BRESINCRPGON(dr, xr, mr, m1r, incr1r, incr2r);
5437  }
5438  } while (y != ymax);
5439 
5440  *nspans = UInt_t(ptsOut - firstPoint);
5441  *outPoint = firstPoint;
5442  *outWidth = firstWidth;
5443 
5444  return ret;
5445 }
5446 
5447 ////////////////////////////////////////////////////////////////////////////////
5448 /// Fill a convex polygon with background color or bitmap.
5449 /// For non convex polygon one must use DrawFillArea method
5450 
5451 void TASImage::FillPolygon(UInt_t npt, TPoint *ppt, const char *col,
5452  const char *stipple, UInt_t w, UInt_t h)
5453 {
5454  UInt_t nspans = 0;
5455  TPoint *firstPoint = 0; // output buffer
5456  UInt_t *firstWidth = 0; // output buffer
5457 
5458  Bool_t del = GetPolygonSpans(npt, ppt, &nspans, &firstPoint, &firstWidth);
5459  ARGB32 color = ARGB32_White;
5460  parse_argb_color(col, &color);
5461 
5462  if (nspans) {
5463  if (!stipple && ((color & 0xff000000)==0xff000000)) { //no stipple no alpha
5464  FillSpansInternal(nspans, firstPoint, firstWidth, color);
5465  } else {
5466  FillSpans(nspans, firstPoint, firstWidth, col, stipple, w, h);
5467  }
5468 
5469  if (del) {
5470  delete [] firstWidth;
5471  delete [] firstPoint;
5472  }
5473  } else {
5474  if (firstWidth) delete [] firstWidth;
5475  if (firstPoint) delete [] firstPoint;
5476  }
5477 }
5478 
5479 ////////////////////////////////////////////////////////////////////////////////
5480 /// Fill a convex polygon with background image.
5481 /// For non convex polygon one must use DrawFillArea method
5482 
5484 {
5485  UInt_t nspans = 0;
5486  TPoint *firstPoint = 0; // output buffer
5487  UInt_t *firstWidth = 0; // output buffer
5488 
5489  Bool_t del = GetPolygonSpans(npt, ppt, &nspans, &firstPoint, &firstWidth);
5490 
5491  if (nspans) {
5492  FillSpans(nspans, firstPoint, firstWidth, tile);
5493 
5494  if (del) {
5495  delete [] firstWidth;
5496  delete [] firstPoint;
5497  }
5498  } else {
5499  if (firstWidth) delete [] firstWidth;
5500  if (firstPoint) delete [] firstPoint;
5501  }
5502 }
5503 
5504 ////////////////////////////////////////////////////////////////////////////////
5505 /// Crop a convex polygon.
5506 
5508 {
5509  UInt_t nspans = 0;
5510  TPoint *firstPoint = 0;
5511  UInt_t *firstWidth = 0;
5512 
5513  Bool_t del = GetPolygonSpans(npt, ppt, &nspans, &firstPoint, &firstWidth);
5514 
5515  if (nspans) {
5516  CropSpans(nspans, firstPoint, firstWidth);
5517 
5518  if (del) {
5519  delete [] firstWidth;
5520  delete [] firstPoint;
5521  }
5522  } else {
5523  if (firstWidth) delete [] firstWidth;
5524  if (firstPoint) delete [] firstPoint;
5525  }
5526 }
5527 
5528 static const UInt_t NUMPTSTOBUFFER = 512;
5529 
5530 ////////////////////////////////////////////////////////////////////////////////
5531 /// Fill a polygon (any type convex, non-convex).
5532 
5533 void TASImage::DrawFillArea(UInt_t count, TPoint *ptsIn, const char *col,
5534  const char *stipple, UInt_t w, UInt_t h)
5535 {
5536  if (!InitVisual()) {
5537  Warning("DrawFillArea", "Visual not initiated");
5538  return;
5539  }
5540 
5541  if (!fImage) {
5542  Warning("DrawFillArea", "no image");
5543  return;
5544  }
5545 
5546  if (!fImage->alt.argb32) {
5547  BeginPaint();
5548  }
5549 
5550  if (!fImage->alt.argb32) {
5551  Warning("DrawFillArea", "Failed to get pixel array");
5552  return;
5553  }
5554 
5555  if ((count < 3) || !ptsIn) {
5556  Warning("DrawFillArea", "No points specified npt=%d ppt=0x%lx", count, (Long_t)ptsIn);
5557  return;
5558  }
5559 
5560  if (count < 5) {
5561  FillPolygon(count, ptsIn, col, stipple, w, h);
5562  return;
5563  }
5564 
5565  ARGB32 color = ARGB32_White;
5566  parse_argb_color(col, &color);
5567 
5568  EdgeTableEntry *pAET; // the Active Edge Table
5569  int y; // the current scanline
5570  UInt_t nPts = 0; // number of pts in buffer
5571 
5572  ScanLineList *pSLL; // Current ScanLineList
5573  TPoint *ptsOut; // ptr to output buffers
5574  UInt_t *width;
5575  TPoint firstPoint[NUMPTSTOBUFFER]; // the output buffers
5576  UInt_t firstWidth[NUMPTSTOBUFFER];
5577  EdgeTableEntry *pPrevAET; // previous AET entry
5578  EdgeTable ET; // Edge Table header node
5579  EdgeTableEntry AET; // Active ET header node
5580  EdgeTableEntry *pETEs; // Edge Table Entries buff
5581  ScanLineListBlock SLLBlock; // header for ScanLineList
5582  Bool_t del = kTRUE;
5583 
5584  static const UInt_t gEdgeTableEntryCacheSize = 200;
5585  static EdgeTableEntry gEdgeTableEntryCache[gEdgeTableEntryCacheSize];
5586 
5587  if (count < gEdgeTableEntryCacheSize) {
5588  pETEs = (EdgeTableEntry*)&gEdgeTableEntryCache;
5589  del = kFALSE;
5590  } else {
5591  pETEs = new EdgeTableEntry[count];
5592  del = kTRUE;
5593  }
5594 
5595  ptsOut = firstPoint;
5596  width = firstWidth;
5597  CreateETandAET(count, ptsIn, &ET, &AET, pETEs, &SLLBlock);
5598  pSLL = ET.scanlines.next;
5599 
5600  for (y = ET.ymin; y < ET.ymax; y++) {
5601  if (pSLL && y == pSLL->scanline) {
5602  loadAET(&AET, pSLL->edgelist);
5603  pSLL = pSLL->next;
5604  }
5605  pPrevAET = &AET;
5606  pAET = AET.next;
5607 
5608  while (pAET) {
5609  ptsOut->fX = pAET->bres.minor_axis;
5610  ptsOut->fY = y;
5611  ptsOut++;
5612  nPts++;
5613 
5614  *width++ = pAET->next->bres.minor_axis - pAET->bres.minor_axis;
5615 
5616  if (nPts == NUMPTSTOBUFFER) {
5617  if (!stipple && ((color & 0xff000000)==0xff000000)) { //no stipple, no alpha
5618  FillSpansInternal(nPts, firstPoint, firstWidth, color);
5619  } else {
5620  FillSpans(nPts, firstPoint, firstWidth, col, stipple, w, h);
5621  }
5622  ptsOut = firstPoint;
5623  width = firstWidth;
5624  nPts = 0;
5625  }
5626  EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
5627  EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
5628  }
5629  InsertionSort(&AET);
5630  }
5631 
5632  if (nPts) {
5633  if (!stipple && ((color & 0xff000000)==0xff000000)) { //no stipple, no alpha
5634  FillSpansInternal(nPts, firstPoint, firstWidth, color);
5635  } else {
5636  FillSpans(nPts, firstPoint, firstWidth, col, stipple, w, h);
5637  }
5638  }
5639 
5640  if (del) delete [] pETEs;
5641  FreeStorage(SLLBlock.next);
5642 }
5643 
5644 ////////////////////////////////////////////////////////////////////////////////
5645 /// Fill a polygon (any type convex, non-convex).
5646 
5647 void TASImage::DrawFillArea(UInt_t count, TPoint *ptsIn, TImage *tile)
5648 {
5649  if (!InitVisual()) {
5650  Warning("DrawFillArea", "Visual not initiated");
5651  return;
5652  }
5653 
5654  if (!fImage) {
5655  Warning("DrawFillArea", "no image");
5656  return;
5657  }
5658 
5659  if (!fImage->alt.argb32) {
5660  BeginPaint();
5661  }
5662 
5663  if (!fImage->alt.argb32) {
5664  Warning("DrawFillArea", "Failed to get pixel array");
5665  return;
5666  }
5667 
5668  if ((count < 3) || !ptsIn) {
5669  Warning("DrawFillArea", "No points specified npt=%d ppt=0x%lx", count, (Long_t)ptsIn);
5670  return;
5671  }
5672 
5673  if (count < 5) {
5674  FillPolygon(count, ptsIn, tile);
5675  return;
5676  }
5677 
5678  EdgeTableEntry *pAET; // the Active Edge Table
5679  int y; // the current scanline
5680  UInt_t nPts = 0; // number of pts in buffer
5681 
5682  ScanLineList *pSLL; // Current ScanLineList
5683  TPoint *ptsOut; // ptr to output buffers
5684  UInt_t *width;
5685  TPoint firstPoint[NUMPTSTOBUFFER]; // the output buffers
5686  UInt_t firstWidth[NUMPTSTOBUFFER];
5687  EdgeTableEntry *pPrevAET; // previous AET entry
5688  EdgeTable ET; // Edge Table header node
5689  EdgeTableEntry AET; // Active ET header node
5690  EdgeTableEntry *pETEs; // Edge Table Entries buff
5691  ScanLineListBlock SLLBlock; // header for ScanLineList
5692 
5693  pETEs = new EdgeTableEntry[count];
5694 
5695  ptsOut = firstPoint;
5696  width = firstWidth;
5697  CreateETandAET(count, ptsIn, &ET, &AET, pETEs, &SLLBlock);
5698  pSLL = ET.scanlines.next;
5699 
5700  for (y = ET.ymin; y < ET.ymax; y++) {
5701  if (pSLL && y == pSLL->scanline) {
5702  loadAET(&AET, pSLL->edgelist);
5703  pSLL = pSLL->next;
5704  }
5705  pPrevAET = &AET;
5706  pAET = AET.next;
5707 
5708  while (pAET) {
5709  ptsOut->fX = pAET->bres.minor_axis;
5710  ptsOut->fY = y;
5711  ptsOut++;
5712  nPts++;
5713 
5714  *width++ = pAET->next->bres.minor_axis - pAET->bres.minor_axis;
5715 
5716  if (nPts == NUMPTSTOBUFFER) {
5717  FillSpans(nPts, firstPoint, firstWidth, tile);
5718  ptsOut = firstPoint;
5719  width = firstWidth;
5720  nPts = 0;
5721  }
5722  EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
5723  EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
5724  }
5725  InsertionSort(&AET);
5726  }
5727  FillSpans(nPts, firstPoint, firstWidth, tile);
5728 
5729  delete [] pETEs;
5730  FreeStorage(SLLBlock.next);
5731 }
5732 
5733 ////////////////////////////////////////////////////////////////////////////////
5734 /// Create draw context.
5735 
5736 static ASDrawContext *create_draw_context_argb32(ASImage *im, ASDrawTool *brush)
5737 {
5738  ASDrawContext *ctx = new ASDrawContext;
5739 
5740  ctx->canvas_width = im->width;
5741  ctx->canvas_height = im->height;
5742  ctx->canvas = im->alt.argb32;
5743  ctx->scratch_canvas = 0;
5744 
5745  ctx->flags = ASDrawCTX_CanvasIsARGB;
5746  asim_set_custom_brush_colored( ctx, brush);
5747  return ctx;
5748 }
5749 
5750 ////////////////////////////////////////////////////////////////////////////////
5751 /// Destroy asdraw context32.
5752 
5753 static void destroy_asdraw_context32( ASDrawContext *ctx )
5754 {
5755  if (ctx) {
5756  if (ctx->scratch_canvas) free(ctx->scratch_canvas);
5757  delete ctx;
5758  }
5759 }
5760 
5761 static const UInt_t kBrushCacheSize = 20;
5763 
5764 ////////////////////////////////////////////////////////////////////////////////
5765 /// Draw wide line.
5766 
5768  UInt_t color, UInt_t thick)
5769 {
5770  Int_t sz = thick*thick;
5771  CARD32 *matrix;
5772  Bool_t use_cache = thick < kBrushCacheSize;
5773 
5774  if (use_cache) {
5775  matrix = gBrushCache;
5776  } else {
5777  matrix = new CARD32[sz];
5778  }
5779 
5780  for (int i = 0; i < sz; i++) {
5781  matrix[i] = (CARD32)color;
5782  };
5783 
5784  ASDrawTool brush;
5785  brush.matrix = matrix;
5786  brush.width = thick;
5787  brush.height = thick;
5788  brush.center_y = brush.center_x = thick/2;
5789 
5790  // When the first or last point of a wide line is exactly on the
5791  // window limit the line is drawn vertically or horizontally.
5792  // see https://sft.its.cern.ch/jira/browse/ROOT-8021
5793  UInt_t xx1 = x1;
5794  UInt_t yy1 = y1;
5795  UInt_t xx2 = x2;
5796  UInt_t yy2 = y2;
5797  if (xx1 == fImage->width) --xx1;
5798  if (yy1 == fImage->height) --yy1;
5799  if (xx2 == fImage->width) --xx2;
5800  if (yy2 == fImage->height) --yy2;
5801  ASDrawContext *ctx = create_draw_context_argb32(fImage, &brush);
5802  asim_move_to(ctx, xx1, yy1);
5803  asim_line_to(ctx, xx2, yy2);
5804 
5805  if (!use_cache) {
5806  delete [] matrix;
5807  }
5809 }
5810 
5811 ////////////////////////////////////////////////////////////////////////////////
5812 /// Draw glyph bitmap.
5813 
5814 void TASImage::DrawGlyph(void *bitmap, UInt_t color, Int_t bx, Int_t by)
5815 {
5816  static UInt_t col[5];
5817  Int_t x, y, yy, y0, xx;
5818  Bool_t has_alpha = (color & 0xff000000) != 0xff000000;
5819 
5820  ULong_t r, g, b;
5821  int idx = 0;
5822  FT_Bitmap *source = (FT_Bitmap*)bitmap;
5823  UChar_t d = 0, *s = source->buffer;
5824 
5825  Int_t dots = Int_t(source->width * source->rows);
5826  r = g = b = 0;
5827  Int_t bxx, byy;
5828 
5829  yy = y0 = by > 0 ? by * fImage->width : 0;
5830  for (y = 0; y < (int) source->rows; y++) {
5831  byy = by + y;
5832  if ((byy >= (int)fImage->height) || (byy <0)) continue;
5833 
5834  for (x = 0; x < (int) source->width; x++) {
5835  bxx = bx + x;
5836  if ((bxx >= (int)fImage->width) || (bxx < 0)) continue;
5837 
5838  idx = Idx(bxx + yy);
5839  r += ((fImage->alt.argb32[idx] & 0xff0000) >> 16);
5840  g += ((fImage->alt.argb32[idx] & 0x00ff00) >> 8);
5841  b += (fImage->alt.argb32[idx] & 0x0000ff);
5842  }
5843  yy += fImage->width;
5844  }
5845  if (dots != 0) {
5846  r /= dots;
5847  g /= dots;
5848  b /= dots;
5849  }
5850 
5851  col[0] = (r << 16) + (g << 8) + b;
5852  col[4] = color;
5853  Int_t col4r = (col[4] & 0xff0000) >> 16;
5854  Int_t col4g = (col[4] & 0x00ff00) >> 8;
5855  Int_t col4b = (col[4] & 0x0000ff);
5856 
5857  // interpolate between fore and background colors
5858  for (x = 3; x > 0; x--) {
5859  xx = 4-x;
5860  Int_t colxr = (col4r*x + r*xx) >> 2;
5861  Int_t colxg = (col4g*x + g*xx) >> 2;
5862  Int_t colxb = (col4b*x + b*xx) >> 2;
5863  col[x] = (colxr << 16) + (colxg << 8) + colxb;
5864  }
5865 
5866  yy = y0;
5867  ARGB32 acolor;
5868  for (y = 0; y < (int) source->rows; y++) {
5869  byy = by + y;
5870  if ((byy >= (int)fImage->height) || (byy <0)) continue;
5871 
5872  for (x = 0; x < (int) source->width; x++) {
5873  bxx = bx + x;
5874  //if ((bxx >= (int)fImage->width) || (bxx < 0)) continue;
5875 
5876  d = *s++ & 0xff;
5877  d = ((d + 10) * 5) >> 8;
5878  if (d > 4) d = 4;
5879 
5880  if (d && (x < (int) source->width) && (bxx < (int)fImage->width) && (bxx >= 0)) {
5881  idx = Idx(bxx + yy);
5882  acolor = (ARGB32)col[d];
5883  if (has_alpha) {
5884  _alphaBlend(&fImage->alt.argb32[idx], &acolor);
5885  } else {
5886  fImage->alt.argb32[idx] = acolor;
5887  }
5888  }
5889  }
5890  yy += fImage->width;
5891  }
5892 }
5893 
5894 ////////////////////////////////////////////////////////////////////////////////
5895 /// Draw text at the pixel position (x,y).
5896 
5898 {
5899  if (!text) return;
5900  if (!fImage) return;
5901  if (!gPad) return;
5902 
5903  if (!InitVisual()) {
5904  Warning("DrawText", "Visual not initiated");
5905  return;
5906  }
5907 
5908  if (!fImage->alt.argb32) {
5909  BeginPaint();
5910  }
5911 
5912  if (!TTF::IsInitialized()) TTF::Init();
5913 
5914  // set text font
5915  TTF::SetTextFont(text->GetTextFont());
5916 
5917  Int_t wh = gPad->XtoPixel(gPad->GetX2());
5918  Int_t hh = gPad->YtoPixel(gPad->GetY1());
5919 
5920  // set text size
5921  Float_t ttfsize;
5922  if (wh < hh) {
5923  ttfsize = text->GetTextSize()*wh;
5924  } else {
5925  ttfsize = text->GetTextSize()*hh;
5926  }
5927  TTF::SetTextSize(ttfsize);
5928 
5929  // set text angle
5931 
5932  // set text
5933  const wchar_t *wcsTitle = reinterpret_cast<const wchar_t *>(text->GetWcsTitle());
5934  if (wcsTitle != NULL) {
5935  TTF::PrepareString(wcsTitle);
5936  } else {
5937  TTF::PrepareString(text->GetTitle());
5938  }
5940 
5941  // color
5942  TColor *col = gROOT->GetColor(text->GetTextColor());
5943  if (!col) { // no color, make it black
5944  col = gROOT->GetColor(1);
5945  if (!col) return;
5946  }
5947  ARGB32 color = ARGB32_White;
5948  parse_argb_color(col->AsHexString(), &color);
5949 
5950  // Align()
5951  Int_t align = 0;
5952  Int_t txalh = text->GetTextAlign()/10;
5953  Int_t txalv = text->GetTextAlign()%10;
5954 
5955  switch (txalh) {
5956  case 0 :
5957  case 1 :
5958  switch (txalv) { //left
5959  case 1 :
5960  align = 7; //bottom
5961  break;
5962  case 2 :
5963  align = 4; //center
5964  break;
5965  case 3 :
5966  align = 1; //top
5967  break;
5968  }
5969  break;
5970  case 2 :
5971  switch (txalv) { //center
5972  case 1 :
5973  align = 8; //bottom
5974  break;
5975  case 2 :
5976  align = 5; //center
5977  break;
5978  case 3 :
5979  align = 2; //top
5980  break;
5981  }
5982  break;
5983  case 3 :
5984  switch (txalv) { //right
5985  case 1 :
5986  align = 9; //bottom
5987  break;
5988  case 2 :
5989  align = 6; //center
5990  break;
5991  case 3 :
5992  align = 3; //top
5993  break;
5994  }
5995  break;
5996  }
5997 
5998  FT_Vector ftal;
5999 
6000  // vertical alignment
6001  if (align == 1 || align == 2 || align == 3) {
6002  ftal.y = TTF::GetAscent();
6003  } else if (align == 4 || align == 5 || align == 6) {
6004  ftal.y = TTF::GetAscent()/2;
6005  } else {
6006  ftal.y = 0;
6007  }
6008 
6009  // horizontal alignment
6010  if (align == 3 || align == 6 || align == 9) {
6011  ftal.x = TTF::GetWidth();
6012  } else if (align == 2 || align == 5 || align == 8) {
6013  ftal.x = TTF::GetWidth()/2;
6014  } else {
6015  ftal.x = 0;
6016  }
6017 
6018  FT_Vector_Transform(&ftal, TTF::GetRotMatrix());
6019  ftal.x = (ftal.x >> 6);
6020  ftal.y = (ftal.y >> 6);
6021 
6022  TTF::TTGlyph *glyph = TTF::GetGlyphs();
6023 
6024  for (int n = 0; n < TTF::GetNumGlyphs(); n++, glyph++) {
6025  if (FT_Glyph_To_Bitmap(&glyph->fImage, ft_render_mode_normal, 0, 1 )) continue;
6026 
6027  FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph->fImage;
6028  FT_Bitmap *source = &bitmap->bitmap;
6029 
6030  Int_t bx = x - ftal.x + bitmap->left;
6031  Int_t by = y + ftal.y - bitmap->top;
6032 
6033  DrawGlyph(source, color, bx, by);
6034  }
6035 }
6036 
6037 ////////////////////////////////////////////////////////////////////////////////
6038 /// Draw text using TrueType fonts.
6039 
6040 void TASImage::DrawTextTTF(Int_t x, Int_t y, const char *text, Int_t size,
6041  UInt_t color, const char *font_name, Float_t angle)
6042 {
6043  if (!TTF::IsInitialized()) TTF::Init();
6044 
6045  TTF::SetTextFont(font_name);
6046  TTF::SetTextSize(size);
6047  TTF::SetRotationMatrix(angle);
6048  TTF::PrepareString(text);
6050 
6051  TTF::TTGlyph *glyph = TTF::GetGlyphs();
6052 
6053  // compute the size and position that will contain the text
6054  // Int_t Xoff = 0; if (TTF::GetBox().xMin < 0) Xoff = -TTF::GetBox().xMin;
6055  Int_t Yoff = 0; if (TTF::GetBox().yMin < 0) Yoff = -TTF::GetBox().yMin;
6056  Int_t h = TTF::GetBox().yMax + Yoff;
6057 
6058  for (int n = 0; n < TTF::GetNumGlyphs(); n++, glyph++) {
6059  if (FT_Glyph_To_Bitmap(&glyph->fImage, ft_render_mode_normal, 0, 1 )) continue;
6060 
6061  FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph->fImage;
6062  FT_Bitmap *source = &bitmap->bitmap;
6063 
6064  Int_t bx = x + bitmap->left;
6065  Int_t by = y + h - bitmap->top;
6066  DrawGlyph(source, color, bx, by);
6067  }
6068 }
6069 
6070 ////////////////////////////////////////////////////////////////////////////////
6071 /// Return in-memory buffer compressed according image type.
6072 /// Buffer must be deallocated after usage.
6073 /// This method can be used for sending images over network.
6074 
6075 void TASImage::GetImageBuffer(char **buffer, int *size, EImageFileTypes type)
6076 {
6077  static ASImageExportParams params;
6078  Bool_t ret = kFALSE;
6079  int isize = 0;
6080  char *ibuff = 0;
6081  ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;
6082 
6083  if (!img) return;
6084 
6085  switch (type) {
6086  case TImage::kXpm:
6087  ret = ASImage2xpmRawBuff(img, (CARD8 **)buffer, size, 0);
6088  break;
6089  default:
6090  ret = ASImage2PNGBuff(img, (CARD8 **)buffer, size, &params);
6091  }
6092 
6093  if (!ret) {
6094  *size = isize;
6095  *buffer = ibuff;
6096  }
6097 }
6098 
6099 ////////////////////////////////////////////////////////////////////////////////
6100 /// Create image from compressed buffer.
6101 /// Supported formats:
6102 ///
6103 /// - PNG - by default
6104 /// - XPM - two options exist:
6105 /// 1. xpm as a single string (raw buffer). Such string
6106 /// is returned by GetImageBuffer method.
6107 /// For example:
6108 /// ~~~ {.cpp}
6109 /// char *buf;
6110 /// int sz;
6111 /// im1->GetImageBuffer(&buf, &int, TImage::kXpm); /*raw buffer*/
6112 /// TImage *im2 = TImage::Create();
6113 /// im2->SetImageBuffer(&buf, TImage::kXpm);
6114 /// ~~~
6115 /// 2. xpm as an array of strings (pre-parsed)
6116 /// ~~~ {.cpp}
6117 /// For example:
6118 /// char *xpm[] = {
6119 /// "64 28 58 1",
6120 /// " c #0A030C",
6121 /// ". c #1C171B"
6122 /// ...
6123 /// TImage *im = TImage::Create();
6124 /// im->SetImageBuffer(xpm, TImage::kXpm);
6125 /// ~~~
6126 
6128 {
6129  DestroyImage();
6130 
6131  static ASImageImportParams params;
6132  params.flags = 0;
6133  params.width = 0;
6134  params.height = 0 ;
6135  params.filter = SCL_DO_ALL;
6136  params.gamma = 0;
6137  params.gamma_table = 0;
6138  params.compression = 0;
6139  params.format = ASA_ASImage;
6140  params.search_path = 0;
6141  params.subimage = 0;
6142 
6143  switch (type) {
6144  case TImage::kXpm:
6145  {
6146  char *ptr = buffer[0];
6147  while (isspace((int)*ptr)) ++ptr;
6148  if (atoi(ptr)) { // pre-parsed and preloaded data
6149  fImage = xpm_data2ASImage((const char**)buffer, &params);
6150  } else {
6151  fImage = xpmRawBuff2ASImage((const char*)*buffer, &params);
6152  }
6153  break;
6154  }
6155  default:
6156  fImage = PNGBuff2ASimage((CARD8 *)*buffer, &params);
6157  break;
6158  }
6159 
6160  if (!fImage) {
6161  return kFALSE;
6162  }
6163 
6164  if (fName.IsNull()) {
6165  fName.Form("img_%dx%d.%d", fImage->width, fImage->height, gRandom->Integer(1000));
6166  }
6167  UnZoom();
6168  return kTRUE;
6169 }
6170 
6171 ////////////////////////////////////////////////////////////////////////////////
6172 /// Create image thumbnail.
6173 
6175 {
6176  int size;
6177  const int sz = 64;
6178 
6179  if (!fImage) {
6180  return;
6181  }
6182 
6183  if (!InitVisual()) {
6184  return;
6185  }
6186 
6187  static char *buf = 0;
6188  int w, h;
6189  ASImage *img = 0;
6190 
6191  if (fImage->width > fImage->height) {
6192  w = sz;
6193  h = (fImage->height*sz)/fImage->width;
6194  } else {
6195  h = sz;
6196  w = (fImage->width*sz)/fImage->height;
6197  }
6198 
6199  w = w < 8 ? 8 : w;
6200  h = h < 8 ? 8 : h;
6201 
6202  img = scale_asimage(fgVisual, fImage, w, h, ASA_ASImage,
6204  if (!img) {
6205  return;
6206  }
6207 
6208  // contrasting
6209  ASImage *rendered_im;
6210  ASImageLayer layers[2];
6211  init_image_layers(&(layers[0]), 2);
6212  layers[0].im = img;
6213  layers[0].dst_x = 0;
6214  layers[0].dst_y = 0;
6215  layers[0].clip_width = img->width;
6216  layers[0].clip_height = img->height;
6217  layers[0].bevel = 0;
6218  layers[1].im = img;
6219  layers[1].dst_x = 0;
6220  layers[1].dst_y = 0;
6221  layers[1].clip_width = img->width;
6222  layers[1].clip_height = img->height;
6223  layers[1].merge_scanlines = blend_scanlines_name2func("tint");
6224  rendered_im = merge_layers(fgVisual, &(layers[0]), 2, img->width, img->height,
6225  ASA_ASImage, GetImageCompression(), GetImageQuality());
6226  destroy_asimage(&img);
6227  img = rendered_im;
6228 
6229  // pad image
6230  ASImage *padimg = 0;
6231  int d = 0;
6232 
6233  if (w == sz) {
6234  d = (sz - h) >> 1;
6235  padimg = pad_asimage(fgVisual, img, 0, d, sz, sz, 0x00ffffff,
6236  ASA_ASImage, GetImageCompression(), GetImageQuality());
6237  } else {
6238  d = (sz - w) >> 1;
6239  padimg = pad_asimage(fgVisual, img, d, 0, sz, sz, 0x00ffffff,
6240  ASA_ASImage, GetImageCompression(), GetImageQuality());
6241  }
6242 
6243  if (!padimg) {
6244  destroy_asimage(&img);
6245  return;
6246  }
6247 
6248  void *ptr = &buf;
6249  ASImage2xpmRawBuff(padimg, (CARD8 **)ptr, &size, 0);
6250  fTitle = buf;
6251 
6252  destroy_asimage(&padimg);
6253 }
6254 
6255 ////////////////////////////////////////////////////////////////////////////////
6256 /// Streamer for ROOT I/O.
6257 
6258 void TASImage::Streamer(TBuffer &b)
6259 {
6260  Bool_t image_type = 0;
6261  char *buffer = 0;
6262  int size = 0;
6263  int w, h;
6264  UInt_t R__s, R__c;
6265 
6266  if (b.IsReading()) {
6267  Version_t version = b.ReadVersion(&R__s, &R__c);
6268  if (version == 0) { //dumb prototype for schema evolution
6269  return;
6270  }
6271 
6272  if ( version == 1 ) {
6273  Int_t fileVersion = b.GetVersionOwner();
6274  if (fileVersion > 0 && fileVersion < 50000 ) {
6275  TImage::Streamer(b);
6276  b >> fMaxValue;
6277  b >> fMinValue;
6278  b >> fZoomOffX;
6279  b >> fZoomOffY;
6280  b >> fZoomWidth;
6281  b >> fZoomHeight;
6282  if ( fileVersion < 40200 ) {
6283  Bool_t zoomUpdate;
6284  b >> zoomUpdate;
6285  fZoomUpdate = zoomUpdate;
6286  } else {
6287  b >> fZoomUpdate;
6288  b >> fEditable;
6289  Bool_t paintMode;
6290  b >> paintMode;
6291  fPaintMode = paintMode;
6292  }
6293  b.CheckByteCount(R__s, R__c, TASImage::IsA());
6294  return;
6295  }
6296  }
6297 
6298  TNamed::Streamer(b);
6299  b >> image_type;
6300 
6301  if (image_type != 0) { // read PNG compressed image
6302  b >> size;
6303  buffer = new char[size];
6304  b.ReadFastArray(buffer, size);
6305  SetImageBuffer(&buffer, TImage::kPng);
6306  delete [] buffer;
6307  } else { // read vector with palette
6308  TAttImage::Streamer(b);
6309  b >> w;
6310  b >> h;
6311  size = w*h;
6312  Double_t *vec = new Double_t[size];
6313  b.ReadFastArray(vec, size);
6314  SetImage(vec, w, h, &fPalette);
6315  delete [] vec;
6316  }
6317  b.CheckByteCount(R__s, R__c, TASImage::IsA());
6318  } else {
6319  if (!fImage) {
6320  return;
6321  }
6322  R__c = b.WriteVersion(TASImage::IsA(), kTRUE);
6323 
6324  if (fName.IsNull()) {
6325  fName.Form("img_%dx%d.%d", fImage->width, fImage->height, gRandom->Integer(1000));
6326  }
6327  TNamed::Streamer(b);
6328 
6329  image_type = fImage->alt.vector ? 0 : 1;
6330  b << image_type;
6331 
6332  if (image_type != 0) { // write PNG compressed image
6333  GetImageBuffer(&buffer, &size, TImage::kPng);
6334  b << size;
6335  b.WriteFastArray(buffer, size);
6336  delete buffer;
6337  } else { // write vector with palette
6338  TAttImage::Streamer(b);
6339  b << fImage->width;
6340  b << fImage->height;
6341  b.WriteFastArray(fImage->alt.vector, fImage->width*fImage->height);
6342  }
6343  b.SetByteCount(R__c, kTRUE);
6344  }
6345 }
6346 
6347 ////////////////////////////////////////////////////////////////////////////////
6348 /// Browse image.
6349 
6351 {
6352  if (fImage->alt.vector) {
6353  Draw("n");
6354  } else {
6355  Draw("nxxx");
6356  }
6357  CreateThumbnail();
6358 }
6359 
6360 ////////////////////////////////////////////////////////////////////////////////
6361 /// Title is used to keep 32x32 xpm image's thumbnail.
6362 
6363 const char *TASImage::GetTitle() const
6364 {
6365  if (!gDirectory || !gDirectory->IsWritable()) {
6366  return 0;
6367  }
6368 
6369  TASImage *mutble = (TASImage *)this;
6370 
6371  if (fTitle.IsNull()) {
6372  mutble->SetTitle(fName.Data());
6373  }
6374 
6375  return fTitle.Data();
6376 }
6377 
6378 ////////////////////////////////////////////////////////////////////////////////
6379 /// Set a title for an image.
6380 
6381 void TASImage::SetTitle(const char *title)
6382 {
6383  if (fTitle.IsNull()) {
6384  CreateThumbnail();
6385  }
6386 
6387  if (fTitle.IsNull()) {
6388  return;
6389  }
6390 
6391  int start = fTitle.Index("/*") + 3;
6392  int stop = fTitle.Index("*/") - 1;
6393 
6394  if ((start > 0) && (stop - start > 0)) {
6395  fTitle.Replace(start, stop - start, title);
6396  }
6397 }
6398 
6399 ////////////////////////////////////////////////////////////////////////////////
6400 /// Draw a cubic bezier line.
6401 
6403  Int_t x3, Int_t y3, const char *col, UInt_t thick)
6404 {
6405  Int_t sz = thick*thick;
6406  CARD32 *matrix;
6407  Bool_t use_cache = thick < kBrushCacheSize;
6408 
6409  ARGB32 color = ARGB32_White;
6410  parse_argb_color(col, &color);
6411 
6412  if (use_cache) {
6413  matrix = gBrushCache;
6414  } else {
6415  matrix = new CARD32[sz];
6416  }
6417 
6418  for (int i = 0; i < sz; i++) {
6419  matrix[i] = (CARD32)color;
6420  };
6421 
6422  ASDrawTool brush;
6423  brush.matrix = matrix;
6424  brush.width = thick;
6425  brush.height = thick;
6426  brush.center_y = brush.center_x = thick/2;
6427 
6428  ASDrawContext *ctx = 0;
6429 
6430  ctx = create_draw_context_argb32(fImage, &brush);
6431  asim_cube_bezier(ctx, x1, y1, x2, y2, x3, y3);
6432 
6433  if (!use_cache) {
6434  delete [] matrix;
6435  }
6437 }
6438 
6439 ////////////////////////////////////////////////////////////////////////////////
6440 /// Draw a straight ellipse.
6441 /// If thick < 0 - draw filled ellipse.
6442 
6444  const char *col, Int_t thick)
6445 {
6446  thick = !thick ? 1 : thick;
6447  Int_t sz = thick*thick;
6448  CARD32 *matrix;
6449  Bool_t use_cache = (thick > 0) && ((UInt_t)thick < kBrushCacheSize);
6450 
6451  ARGB32 color = ARGB32_White;
6452  parse_argb_color(col, &color);
6453 
6454  if (use_cache) {
6455  matrix = gBrushCache;
6456  } else {
6457  matrix = new CARD32[sz];
6458  }
6459 
6460  for (int i = 0; i < sz; i++) {
6461  matrix[i] = (CARD32)color;
6462  };
6463 
6464  ASDrawTool brush;
6465  brush.matrix = matrix;
6466  brush.width = thick > 0 ? thick : 1;
6467  brush.height = thick > 0 ? thick : 1;
6468  brush.center_y = brush.center_x = thick > 0 ? thick/2 : 0;
6469 
6470  ASDrawContext *ctx = create_draw_context_argb32(fImage, &brush);
6471  asim_straight_ellips(ctx, x, y, rx, ry, thick < 0);
6472 
6473  if (!use_cache) {
6474  delete [] matrix;
6475  }
6477 }
6478 
6479 ////////////////////////////////////////////////////////////////////////////////
6480 /// Draw a circle.
6481 /// If thick < 0 - draw filled circle
6482 
6483 void TASImage::DrawCircle(Int_t x, Int_t y, Int_t r, const char *col, Int_t thick)
6484 {
6485  thick = !thick ? 1 : thick;
6486  Int_t sz = thick*thick;
6487  CARD32 *matrix;
6488  Bool_t use_cache = (thick > 0) && ((UInt_t)thick < kBrushCacheSize);
6489 
6490  ARGB32 color = ARGB32_White;
6491  parse_argb_color(col, &color);
6492 
6493 ///matrix = new CARD32[sz];
6494  if (use_cache) {
6495  matrix = gBrushCache;
6496  } else {
6497  matrix = new CARD32[sz];
6498  }
6499 
6500  for (int i = 0; i < sz; i++) {
6501  matrix[i] = (CARD32)color;
6502  }
6503 
6504  ASDrawTool brush;
6505  brush.matrix = matrix;
6506  brush.height = brush.width = thick > 0 ? thick : 1;
6507  brush.center_y = brush.center_x = thick > 0 ? thick/2 : 0;
6508 
6509  ASDrawContext *ctx = create_draw_context_argb32(fImage, &brush);
6510  asim_circle(ctx, x, y, r, thick < 0);
6511 
6512 ///free (matrix);
6513  if (!use_cache) {
6514  delete [] matrix;
6515  }
6517 }
6518 
6519 ////////////////////////////////////////////////////////////////////////////////
6520 /// Draw an ellipse.
6521 /// If thick < 0 - draw filled ellips
6522 
6524  const char *col, Int_t thick)
6525 {
6526  thick = !thick ? 1 : thick;
6527  Int_t sz = thick*thick;
6528  CARD32 *matrix;
6529  Bool_t use_cache = (thick > 0) && ((UInt_t)thick < kBrushCacheSize);
6530 
6531  ARGB32 color = ARGB32_White;
6532  parse_argb_color(col, &color);
6533 
6534  if (use_cache) {
6535  matrix = gBrushCache;
6536  } else {
6537  matrix = new CARD32[sz];
6538  }
6539 
6540  for (int i = 0; i < sz; i++) {
6541  matrix[i] = (CARD32)color;
6542  };
6543 
6544  ASDrawTool brush;
6545  brush.matrix = matrix;
6546  brush.width = thick > 0 ? thick : 1;
6547  brush.height = thick > 0 ? thick : 1;
6548  brush.center_y = brush.center_x = thick > 0 ? thick/2 : 0;
6549 
6550  ASDrawContext *ctx = create_draw_context_argb32(fImage, &brush);
6551  asim_ellips(ctx, x, y, rx, ry, angle, thick < 0);
6552 
6553  if (!use_cache) {
6554  delete [] matrix;
6555  }
6557 }
6558 
6559 ////////////////////////////////////////////////////////////////////////////////
6560 /// Draw an ellipse.
6561 /// If thick < 0 - draw filled ellipse.
6562 
6564  const char *col, Int_t thick)
6565 {
6566  thick = !thick ? 1 : thick;
6567  Int_t sz = thick*thick;
6568  CARD32 *matrix;
6569  Bool_t use_cache = (thick > 0) && ((UInt_t)thick < kBrushCacheSize);
6570 
6571  ARGB32 color = ARGB32_White;
6572  parse_argb_color(col, &color);
6573 
6574  if (use_cache) {
6575  matrix = gBrushCache;
6576  } else {
6577  matrix = new CARD32[sz];
6578  }
6579 
6580  for (int i = 0; i < sz; i++) {
6581  matrix[i] = (CARD32)color;
6582  };
6583 
6584  ASDrawTool brush;
6585  brush.matrix = matrix;
6586  brush.width = thick > 0 ? thick : 1;
6587  brush.height = thick > 0 ? thick : 1;
6588  brush.center_y = brush.center_x = thick > 0 ? thick/2 : 0;
6589 
6590  ASDrawContext *ctx = create_draw_context_argb32(fImage, &brush);
6591  asim_ellips2(ctx, x, y, rx, ry, angle, thick < 0);
6592 
6593  if (!use_cache) {
6594  delete [] matrix;
6595  }
6597 }
6598 
6599 ////////////////////////////////////////////////////////////////////////////////
6600 /// Flood fill.
6601 
6602 void TASImage::FloodFill(Int_t /*x*/, Int_t /*y*/, const char * /*col*/,
6603  const char * /*minc*/, const char * /*maxc*/)
6604 {
6605 }
6606 
6607 ////////////////////////////////////////////////////////////////////////////////
6608 /// Convert RGB image to Gray image and vice versa.
6609 
6611 {
6612  if (fIsGray == on) {
6613  return;
6614  }
6615 
6616  if (!IsValid()) {
6617  Warning("Gray", "Image not initiated");
6618  return;
6619  }
6620 
6621  if (!InitVisual()) {
6622  Warning("Gray", "Visual not initiated");
6623  return;
6624  }
6625 
6626  if (!fGrayImage && !on) {
6627  return;
6628  }
6629  ASImage *sav = 0;
6630  delete fScaledImage;
6631  fScaledImage = 0;
6632 
6633  if (fGrayImage) {
6634  sav = fImage;
6635  fImage = fGrayImage;
6636  fGrayImage = sav;
6637  fIsGray = on;
6638  return;
6639  }
6640 
6641  if (!on) return;
6642 
6643  UInt_t l, r, g, b, idx;
6644  int y = 0;
6645  UInt_t i, j;
6646 
6647  if (fImage->alt.argb32) {
6648  fGrayImage = tile_asimage(fgVisual, fImage, 0, 0, fImage->width, fImage->height,
6649  0, ASA_ARGB32, 0, ASIMAGE_QUALITY_DEFAULT);
6650 
6651  for (i = 0; i < fImage->height; i++) {
6652  for (j = 0; j < fImage->width; j++) {
6653  idx = Idx(y + j);
6654 
6655  r = ((fImage->alt.argb32[idx] & 0xff0000) >> 16);
6656  g = ((fImage->alt.argb32[idx] & 0x00ff00) >> 8);
6657  b = (fImage->alt.argb32[idx] & 0x0000ff);
6658  l = (57*r + 181*g + 18*b)/256;
6659  fGrayImage->alt.argb32[idx] = (l << 16) + (l << 8) + l;
6660  }
6661  y += fImage->width;
6662  }
6663  } else {
6664  fGrayImage = create_asimage(fImage->width, fImage->height, 0);
6665 
6666  ASImageDecoder *imdec = start_image_decoding(fgVisual, fImage, SCL_DO_ALL,
6667  0, 0, fImage->width, fImage->height, 0);
6668 
6669  if (!imdec) {
6670  return;
6671  }
6672 #ifdef HAVE_MMX
6673  mmx_init();
6674 #endif
6675  ASImageOutput *imout = start_image_output(fgVisual, fGrayImage, ASA_ASImage,
6677  if (!imout) {
6678  Warning("ToGray", "Failed to start image output");
6679  delete fScaledImage;
6680  fScaledImage = 0;
6681  delete [] imdec;
6682  return;
6683  }
6684 
6685  CARD32 *aa = imdec->buffer.alpha;
6686  CARD32 *rr = imdec->buffer.red;
6687  CARD32 *gg = imdec->buffer.green;
6688  CARD32 *bb = imdec->buffer.blue;
6689 
6690  ASScanline result;
6691  prepare_scanline(fImage->width, 0, &result, fgVisual->BGR_mode);
6692 
6693  for (i = 0; i < fImage->height; i++) {
6694  imdec->decode_image_scanline(imdec);
6695  result.flags = imdec->buffer.flags;
6696  result.back_color = imdec->buffer.back_color;
6697 
6698  for (j = 0; j < fImage->width; j++) {
6699  l = (57*rr[j] + 181*gg[j]+ 18*bb[j])/256;
6700  result.alpha[j] = aa[j];
6701  result.red[j] = l;
6702  result.green[j] = l;
6703  result.blue[j] = l;
6704  }
6705  imout->output_image_scanline(imout, &result, 1);
6706  }
6707 
6708  stop_image_decoding(&imdec);
6709  stop_image_output(&imout);
6710 #ifdef HAVE_MMX
6711  mmx_off();
6712 #endif
6713  }
6714 
6715  sav = fImage;
6716  fImage = fGrayImage;
6717  fGrayImage = sav;
6718  fIsGray = kTRUE;
6719 }
6720 
6721 ////////////////////////////////////////////////////////////////////////////////
6722 /// Create an image (screenshot) from specified window.
6723 
6725 {
6726  Int_t xy;
6727 
6728  x = x < 0 ? 0 : x;
6729  y = y < 0 ? 0 : y;
6730 
6731  // synchronization
6732  gVirtualX->Update(1);
6733  if (!gThreadXAR) {
6735  gSystem->Sleep(10);
6737  }
6738 
6739  if (!w || !h) {
6740  gVirtualX->GetWindowSize(wid, xy, xy, w, h);
6741  }
6742 
6743  if ((x >= (Int_t)w) || (y >= (Int_t)h)) {
6744  return;
6745  }
6746 
6747  if (!InitVisual()) {
6748  Warning("FromWindow", "Visual not initiated");
6749  return;
6750  }
6751 
6752  DestroyImage();
6753  delete fScaledImage;
6754  fScaledImage = 0;
6755 
6756  static int x11 = -1;
6757  if (x11 < 0) x11 = gVirtualX->InheritsFrom("TGX11");
6758 
6759  if (x11) { //use built-in optimized version
6760  fImage = pixmap2asimage(fgVisual, wid, x, y, w, h, kAllPlanes, 0, 0);
6761  } else {
6762  unsigned char *bits = gVirtualX->GetColorBits(wid, 0, 0, w, h);
6763 
6764  if (!bits) { // error
6765  return;
6766  }
6767  fImage = bitmap2asimage(bits, w, h, 0, 0);
6768  delete [] bits;
6769  }
6770 }
6771 
6772 ////////////////////////////////////////////////////////////////////////////////
6773 /// Creates an image (screenshot) from a RGBA buffer.
6774 
6776 {
6777  DestroyImage();
6778  delete fScaledImage;
6779  fScaledImage = 0;
6780 
6781  UChar_t* xx = new UChar_t[4*w];
6782  for (UInt_t i = 0; i < h/2; ++i) {
6783  memcpy(xx, buf + 4*w*i, 4*w);
6784  memcpy(buf + 4*w*i, buf + 4*w*(h-i-1), 4*w);
6785  memcpy(buf + 4*w*(h-i-1), xx, 4*w);
6786  }
6787  delete [] xx;
6788 
6789  fImage = bitmap2asimage(buf, w, h, 0, 0);
6790 }
6791 
6792 ////////////////////////////////////////////////////////////////////////////////
6793 /// Switch on/off the image palette.
6794 /// That also invokes calling vectorization of image.
6795 
6797 {
6798  if (!fImage) {
6799  return;
6800  }
6801 
6802  if (!fImage->alt.vector && on) {
6803  Vectorize();
6804  }
6805  fPaletteEnabled = on;
6806 
6807  if (on) {
6808  Double_t left = gPad->GetLeftMargin();
6809  Double_t right = gPad->GetRightMargin();
6810  Double_t top = gPad->GetTopMargin();
6811  Double_t bottom = gPad->GetBottomMargin();
6812 
6813  gPad->Range(-left / (1.0 - left - right),
6814  -bottom / (1.0 - top - bottom),
6815  1 + right / (1.0 - left - right),
6816  1 + top / ( 1.0 - top - bottom));
6817  gPad->RangeAxis(0, 0, 1, 1);
6818  }
6819 
6820 }
6821 
6822 ////////////////////////////////////////////////////////////////////////////////
6823 /// Save a primitive as a C++ statement(s) on output stream "out".
6824 
6825 void TASImage::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
6826 {
6827  char *buf = 0;
6828  int sz;
6829 
6830  UInt_t w = GetWidth();
6831  UInt_t h = GetHeight();
6832 
6833  if (w > 500) { // workaround CINT limitations
6834  w = 500;
6835  Double_t scale = 500./GetWidth();
6836  h = TMath::Nint(GetHeight()*scale);
6837  Scale(w, h);
6838  }
6839 
6840  GetImageBuffer(&buf, &sz, TImage::kXpm);
6841 
6842  TString name = GetName();
6843  name.ReplaceAll(".", "_");
6844  TString str = buf;
6845  static int ii = 0;
6846  ii++;
6847 
6848  str.ReplaceAll("static", "const");
6849  TString xpm = "xpm_";
6850  xpm += name;
6851  xpm += ii;
6852  str.ReplaceAll("asxpm", xpm.Data());
6853  out << std::endl << str << std::endl << std::endl;
6854 
6855  out << " TImage *";
6856  out << xpm << "_img = TImage::Create();" << std::endl;
6857  out << " " << xpm << "_img->SetImageBuffer( (char **)" << xpm << ", TImage::kXpm);" << std::endl;
6858  out << " " << xpm << "_img->Draw();" << std::endl;
6859 }
6860 
6861 ////////////////////////////////////////////////////////////////////////////////
6862 /// Set an image printing resolution in Dots Per Inch units.
6863 ///
6864 /// \param[in] name - the name of jpeg file.
6865 /// \param[in] set - dpi resolution.
6866 ///
6867 /// Returns kFALSE in case of error.
6868 
6870 {
6871  static char buf[32];
6872  FILE *fp = fopen(name, "rb+");
6873 
6874  if (!fp) {
6875  printf("file %s : failed to open\n", name);
6876  return kFALSE;
6877  }
6878 
6879  if (!fread(buf, 1, 20, fp)) {
6880  fclose(fp);
6881  return kFALSE;
6882  }
6883 
6884  char dpi1 = (set & 0xffff) >> 8;
6885  char dpi2 = set & 0xff;
6886 
6887  int i = 0;
6888 
6889  int dpi = 0; // start of dpi data
6890  for (i = 0; i < 20; i++) {
6891  if ((buf[i] == 0x4a) && (buf[i+1] == 0x46) && (buf[i+2] == 0x49) &&
6892  (buf[i+3] == 0x46) && (buf[i+4] == 0x00) ) {
6893  dpi = i + 7;
6894  break;
6895  }
6896  }
6897 
6898  if (i == 20 || dpi+4 >= 20) { // jpeg maker was not found
6899  fclose(fp);
6900  printf("file %s : wrong JPEG format\n", name);
6901  return kFALSE;
6902  }
6903 
6904  buf[dpi] = 1; // format specified in dots per inch
6905 
6906  // set x density in dpi units
6907  buf[dpi + 1] = dpi1;
6908  buf[dpi + 2] = dpi2;
6909 
6910  // set y density in dpi units
6911  buf[dpi + 3] = dpi1;
6912  buf[dpi + 4] = dpi2;
6913 
6914  rewind(fp);
6915  fwrite(buf, 1, 20, fp);
6916  fclose(fp);
6917 
6918  return kTRUE;
6919 }
6920 
6921 ////////////////////////////////////////////////////////////////////////////////
6922 /// Return a valid index in fImage tables to avoid seg-fault by accessing out of
6923 /// indices out of array's ranges.
6924 
6926 {
6927  // The size of arrays like fImage->alt.argb32 is fImage->width*fImage->height
6928  return TMath::Min(idx,(Int_t)(fImage->width*fImage->height));
6929 }
6930 
Int_t fClipXOrigin
Definition: GuiTypes.h:246
const int nx
Definition: kalman.C:16
TString fTitle
Definition: TNamed.h:37
void SetTitle(const char *title="")
Set a title for an image.
Definition: TASImage.cxx:6381
Double_t * Vectorize(UInt_t max_colors=256, UInt_t dither=4, Int_t opaque_threshold=1)
Reduce color-depth of an image and fills vector of &quot;scientific data&quot; [0...1].
Definition: TASImage.cxx:2938
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:929
Definition: GuiTypes.h:76
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
Definition: TASPolyUtils.c:287
static void Init()
Initialise the TrueType fonts interface.
Definition: TTF.cxx:66
Short_t fX1
Definition: GuiTypes.h:353
Double_t * fPoints
[fNumPoints] value of each anchor point [0..1]
Definition: TAttImage.h:43
UInt_t GetScaledHeight() const
Return height of the displayed image not of the original image.
Definition: TASImage.cxx:2177
static void FreeStorage(ScanLineListBlock *pSLLBlock)
Definition: TASPolyUtils.c:524
void GetZoomPosition(UInt_t &x, UInt_t &y, UInt_t &w, UInt_t &h) const
Return the zoom parameters.
Definition: TASImage.cxx:2186
An array of TObjects.
Definition: TObjArray.h:39
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:421
virtual Float_t GetTextAngle() const
Return the text angle.
Definition: TAttText.h:39
EImageFileTypes
Definition: TImage.h:44
virtual void CellArrayFill(Int_t r, Int_t g, Int_t b)=0
static ASFontManager * gFontManager
Definition: TASImage.cxx:122
static void init_icon_paths()
Set icons paths.
Definition: TASImage.cxx:360
virtual Font_t GetTextFont() const
Return the text font.
Definition: TAttText.h:41
void DrawDashZTLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t nDash, const char *pDash, UInt_t col, UInt_t thick)
Draw a dashed line with thick pixel width.
Definition: TASImage.cxx:4567
Bool_t IsReading() const
Definition: TBuffer.h:83
void PutPixel(Int_t x, Int_t y, const char *col="#000000")
Draw a point at the specified position.
Definition: TASImage.cxx:4794
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class &quot;classname&quot;.
Definition: TObject.cxx:488
static ARGB32 GetAverage(ARGB32 foreground, ARGB32 background)
Get average.
Definition: TASImage.cxx:3325
virtual void Paint(Option_t *option="")=0
This method must be overridden if a class wants to paint itself.
short Version_t
Definition: RtypesCore.h:61
static Bool_t InitVisual()
Static function to initialize the ASVisual.
Definition: TASImage.cxx:2197
Ssiz_t Length() const
Definition: TString.h:390
UInt_t GetWidth() const
Return width of original image not of the displayed image.
Definition: TASImage.cxx:2150
void SetPaletteEnabled(Bool_t on=kTRUE)
Switch on/off the image palette.
Definition: TASImage.cxx:6796
float Float_t
Definition: RtypesCore.h:53
virtual void SetBorderMode(Short_t bordermode)
Definition: TWbox.h:53
Bool_t IsEditable() const
Definition: TASImage.h:97
return c
const char Option_t
Definition: RtypesCore.h:62
void DrawBox(Int_t x1, Int_t y1, Int_t x2, Int_t y2, const char *col="#000000", UInt_t thick=1, Int_t mode=0)
Draw a box.
Definition: TASImage.cxx:4223
Image class.
Definition: TASImage.h:33
float ymin
Definition: THbookFile.cxx:93
Create a Box.
Definition: TBox.h:36
static const TString & GetIconPath()
Get the icon path in the installation. Static utility function.
Definition: TROOT.cxx:2871
const char * GetTitle() const
Title is used to keep 32x32 xpm image&#39;s thumbnail.
Definition: TASImage.cxx:6363
static const ASVisual * GetVisual()
Return visual.
Definition: TASImage.cxx:5269
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
EImageFileTypes GetFileType(const char *ext)
Return file type depending on specified extension.
Definition: TASImage.cxx:817
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
static Bool_t IsInitialized()
Definition: TTF.cxx:801
FT_Glyph fImage
glyph image
Definition: TTF.h:71
UInt_t GetHeight() const
Return height of original image not of the displayed image.
Definition: TASImage.cxx:2159
unsigned short UShort_t
Definition: RtypesCore.h:36
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:131
#define BIT(n)
Definition: Rtypes.h:120
TH1 * h
Definition: legend2.C:5
void Draw(Option_t *option="")
Draw image.
Definition: TASImage.cxx:1169
static unsigned long kAllPlanes
Definition: TASImage.cxx:123
void DrawRectangle(UInt_t x, UInt_t y, UInt_t w, UInt_t h, const char *col="#000000", UInt_t thick=1)
Draw a rectangle.
Definition: TASImage.cxx:4183
void CopyArea(TImage *dst, Int_t xsrc, Int_t ysrc, UInt_t w, UInt_t h, Int_t xdst=0, Int_t ydst=0, Int_t gfunc=3, EColorChan chan=kAllChan)
Copy source region to the destination image.
Definition: TASImage.cxx:5115
virtual const char * HomeDirectory(const char *userName=0)
Return the user&#39;s home directory.
Definition: TSystem.cxx:882
SCoord_t fX
Definition: TPoint.h:37
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:42
virtual UInt_t * GetArgbArray()
Definition: TImage.h:245
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
#define gROOT
Definition: TROOT.h:379
#define H(x, y, z)
Bool_t fEditable
! kTRUE image can be resized, moved by resizing/moving gPad
Definition: TASImage.h:68
UInt_t * GetArgbArray()
Return a pointer to internal array[width x height] of ARGB32 values This array is directly accessible...
Definition: TASImage.cxx:3695
Handle_t GContext_t
Definition: GuiTypes.h:39
virtual UInt_t GetWidth() const
Definition: TImage.h:236
Int_t LoadPlugin()
Load the plugin library for this handler.
SCoord_t fY
Definition: TPoint.h:38
Basic string class.
Definition: TString.h:137
#define CLRBIT(n, i)
Definition: Rtypes.h:122
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1089
void StartPaletteEditor()
Start palette editor.
Definition: TASImage.cxx:2251
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Short_t fY1
Definition: GuiTypes.h:353
TObject * Clone(const char *newname) const
Clone image.
Definition: TASImage.cxx:2892
TArc * a
Definition: textangle.C:12
void ReadImage(const char *file, EImageFileTypes type=TImage::kUnknown)
Read specified image file.
Definition: TASImage.cxx:477
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:255
virtual void SetX1(Double_t x1)
Definition: TBox.h:75
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:44
void Zoom(UInt_t offX, UInt_t offY, UInt_t width, UInt_t height)
The area of an image displayed in a pad is defined by this function.
Definition: TASImage.cxx:2023
virtual void CellArrayEnd()=0
void FromPad(TVirtualPad *pad, Int_t x=0, Int_t y=0, UInt_t w=0, UInt_t h=0)
Create an image from the given pad, afterwards this image can be saved in any of the supported image ...
Definition: TASImage.cxx:1070
Handle_t Drawable_t
Definition: GuiTypes.h:32
Int_t fClipYOrigin
Definition: GuiTypes.h:247
An abstract interface to image processing library.
Definition: TImage.h:37
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:180
void Browse(TBrowser *)
Browse image.
Definition: TASImage.cxx:6350
void CreateThumbnail()
Create image thumbnail.
Definition: TASImage.cxx:6174
Pixmap_t fClipMask
Definition: GuiTypes.h:248
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
void DrawLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, const char *col="#000000", UInt_t thick=1)
Draw a line.
Definition: TASImage.cxx:4013
void DrawCubeBezier(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t x3, Int_t y3, const char *col="#000000", UInt_t thick=1)
Draw a cubic bezier line.
Definition: TASImage.cxx:6402
const char * Class
Definition: TXMLSetup.cxx:64
virtual void SetX2(Double_t x2)
Definition: TBox.h:76
Long_t ExecPlugin(int nargs, const T &...params)
XID Colormap
Definition: TGX11.h:40
#define malloc
Definition: civetweb.c:818
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
Bool_t fPaletteEnabled
! kTRUE - palette is drawn on the image
Definition: TAttImage.h:83
UInt_t * GetScanline(UInt_t y)
Return a pointer to scan-line.
Definition: TASImage.cxx:3769
void DrawTextTTF(Int_t x, Int_t y, const char *text, Int_t size, UInt_t color, const char *font_name, Float_t angle)
Draw text using TrueType fonts.
Definition: TASImage.cxx:6040
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:739
static CARD32 gBrushCache[kBrushCacheSize *kBrushCacheSize]
Definition: TASImage.cxx:5762
static ARGB32 GetShadow(ARGB32 background)
Calculate shadow color.
Definition: TASImage.cxx:3316
UShort_t * fColorRed
[fNumPoints] red color at each anchor point
Definition: TAttImage.h:44
Double_t * GetVecArray()
Return a pointer to internal array[width x height] of double values [0,1].
Definition: TASImage.cxx:2480
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:625
Bool_t SetImageBuffer(char **buffer, EImageFileTypes type=TImage::kPng)
Create image from compressed buffer.
Definition: TASImage.cxx:6127
static THashTable * fgPlugList
! hash table containing loaded plugins
Definition: TASImage.h:72
void PolyPoint(UInt_t npt, TPoint *ppt, const char *col="#000000", TImage::ECoordMode mode=kCoordModeOrigin)
Draw a poly point.
Definition: TASImage.cxx:4829
Short_t fX2
Definition: GuiTypes.h:353
const char * Data() const
Definition: TString.h:349
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Definition: TObjArray.cxx:396
EImageQuality GetImageQuality() const
Definition: TAttImage.h:93
Int_t DistancetoPrimitive(Int_t px, Int_t py)
Is the mouse in the image ?
Definition: TASImage.cxx:1680
void Paint(Option_t *option="")
Paint image.
Definition: TASImage.cxx:1363
const Mask_t kGCClipMask
Definition: GuiTypes.h:306
static const double x2[5]
Int_t Idx(Int_t idx)
Return a valid index in fImage tables to avoid seg-fault by accessing out of indices out of array&#39;s r...
Definition: TASImage.cxx:6925
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition: TAttText.h:38
THashTable implements a hash table to store TObject&#39;s.
Definition: THashTable.h:39
Double_t x[n]
Definition: legend1.C:17
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Definition: TTF.cxx:193
EColorChan
Definition: TImage.h:98
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:442
tuple fill
Definition: fit1_py.py:6
virtual const char * GetName() const =0
Returns name of object.
void BeginPaint(Bool_t fast=kTRUE)
BeginPaint initializes internal array[width x height] of ARGB32 pixel values.
Definition: TASImage.cxx:3636
static void SetTextFont(Font_t fontnumber)
Definition: TTF.cxx:513
virtual Int_t GetVersionOwner() const =0
void EndPaint()
EndPaint does internal RLE compression of image data.
Definition: TASImage.cxx:3668
Short_t fY2
Definition: GuiTypes.h:353
#define BRESINCRPGON(d, minval, m, m1, incr1, incr2)
Definition: TASPolyUtils.c:115
const int ny
Definition: kalman.C:17
static void PrepareString(const char *string)
Put the characters in &quot;string&quot; in the &quot;glyphs&quot; array.
Definition: TTF.cxx:259
virtual Color_t GetTextColor() const
Return the text color.
Definition: TAttText.h:40
void DrawCellArray(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t nx, Int_t ny, UInt_t *ic)
Draw a cell array.
Definition: TASImage.cxx:5229
void MapFileTypes(EImageFileTypes &type, UInt_t &astype, Bool_t toas=kTRUE)
Map file type to/from AfterImage types.
Definition: TASImage.cxx:861
TArrayD * GetArray(UInt_t w=0, UInt_t h=0, TImagePalette *pal=gWebImagePalette)
In case of vectorized image return an associated array of doubles otherwise this method creates and r...
Definition: TASImage.cxx:2502
UInt_t fZoomOffY
! Y - offset for zooming im image pixels
Definition: TASImage.h:64
void Gray(Bool_t on=kTRUE)
Convert RGB image to Gray image and vice versa.
Definition: TASImage.cxx:6610
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
Definition: TRandom.cxx:320
static UInt_t AlphaBlend(UInt_t bot, UInt_t top)
Return alpha-blended value computed from bottom and top pixel values.
Definition: TASImage.cxx:5258
static void loadAET(EdgeTableEntry *AET, EdgeTableEntry *ETEs)
Definition: TASPolyUtils.c:455
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1055
void WriteImage(const char *file, EImageFileTypes type=TImage::kUnknown)
Write image to specified file.
Definition: TASImage.cxx:646
Base class for several text objects.
Definition: TText.h:33
UInt_t GetImageCompression() const
Definition: TAttImage.h:92
virtual void Draw(Option_t *option="")
Draw this frame with its current attributes.
Definition: TFrame.cxx:69
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1965
static TTGlyph * GetGlyphs()
Definition: TTF.cxx:843
static ASDrawContext * create_draw_context_argb32(ASImage *im, ASDrawTool *brush)
Create draw context.
Definition: TASImage.cxx:5736
void DrawFillArea(UInt_t npt, TPoint *ppt, const char *col="#000000", const char *stipple=0, UInt_t w=16, UInt_t h=16)
Fill a polygon (any type convex, non-convex).
Definition: TASImage.cxx:5533
static int GetPolyYBounds(TPoint *pts, int n, int *by, int *ty)
Get poly bounds along Y.
Definition: TASImage.cxx:5277
Double_t ATan2(Double_t, Double_t)
Definition: TMath.h:454
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)
Convert r,g,b to graphics system dependent pixel value.
Definition: TColor.cxx:1954
void Scale(UInt_t width, UInt_t height)
Scale the original image.
Definition: TASImage.cxx:1913
SCoord_t GetY() const
Definition: TPoint.h:50
void DrawGlyph(void *bitmap, UInt_t color, Int_t x, Int_t y)
Draw glyph bitmap.
Definition: TASImage.cxx:5814
virtual Int_t GetPixmapID() const =0
R__EXTERN Int_t(* gThreadXAR)(const char *xact, Int_t nb, void **ar, Int_t *iret)
Definition: TVirtualPad.h:291
void Pad(const char *color="#00FFFFFF", UInt_t left=0, UInt_t right=0, UInt_t top=0, UInt_t bottom=0)
Enlarge image, padding it with specified color on each side in accordance with requested geometry...
Definition: TASImage.cxx:3469
Int_t fPaintMode
! 1 - fast mode, 0 - low memory slow mode
Definition: TASImage.h:69
Definition: TPoint.h:33
virtual UInt_t GetHeight() const
Definition: TImage.h:237
void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream &quot;out&quot;.
Definition: TASImage.cxx:6825
TArrayL * GetPixels(Int_t x=0, Int_t y=0, UInt_t w=0, UInt_t h=0)
Return 2D array of machine dependent pixel values.
Definition: TASImage.cxx:2408
void DrawDashZLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t nDash, const char *pDash, UInt_t col)
Draw a dashed line with one pixel width.
Definition: TASImage.cxx:4383
Element * GetMatrixArray()
Definition: TVectorT.h:84
virtual const TImagePalette & GetPalette() const
Definition: TAttImage.h:94
void DrawDashHLine(UInt_t y, UInt_t x1, UInt_t x2, UInt_t nDash, const char *pDash, UInt_t col, UInt_t thick)
Draw a dashed horizontal line.
Definition: TASImage.cxx:4272
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:46
virtual Int_t UtoPixel(Double_t u) const =0
Bool_t SetJpegDpi(const char *name, UInt_t dpi=72)
Set an image printing resolution in Dots Per Inch units.
Definition: TASImage.cxx:6869
void FillSpans(UInt_t npt, TPoint *ppt, UInt_t *widths, const char *col="#000000", const char *stipple=0, UInt_t w=16, UInt_t h=16)
Fill spans with specified color or/and stipple.
Definition: TASImage.cxx:4912
virtual void Delete(Option_t *option="")
Delete this object.
Definition: TObject.cxx:229
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
void DrawCircle(Int_t x, Int_t y, Int_t r, const char *col="#000000", Int_t thick=1)
Draw a circle.
Definition: TASImage.cxx:6483
RooArgSet S(const RooAbsArg &v1)
R__EXTERN const char * gProgName
Definition: TSystem.h:234
void UnZoom()
Un-zoom the image to original size.
Definition: TASImage.cxx:2045
void FillRectangleInternal(UInt_t col, Int_t x, Int_t y, UInt_t width, UInt_t height)
Fill rectangle of size (width, height) at position (x,y) within the existing image with specified col...
Definition: TASImage.cxx:3839
Bool_t fIsGray
! kTRUE if image is gray
Definition: TASImage.h:71
void SetImage(const Double_t *imageData, UInt_t width, UInt_t height, TImagePalette *palette=0)
Deletes the old image and creates a new image depending on the values of imageData.
Definition: TASImage.cxx:983
float ymax
Definition: THbookFile.cxx:93
virtual void PaintAxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax, Double_t &wmin, Double_t &wmax, Int_t &ndiv, Option_t *chopt="", Double_t gridlength=0, Bool_t drawGridOnly=kFALSE)
Control function to draw an axis.
Definition: TGaxis.cxx:742
static char * gIconPaths[7]
Definition: TASImage.cxx:127
void Append(const TImage *im, const char *option="+", const char *color="#00000000")
Append image.
Definition: TASImage.cxx:3595
void SetPalette(const TImagePalette *palette)
Set a new palette to an image.
Definition: TASImage.cxx:1857
void DrawWideLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t col, UInt_t thick)
Draw wide line.
Definition: TASImage.cxx:5767
TPaveText * pt
static Int_t GetWidth()
Definition: TTF.cxx:808
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2221
TRandom2 r(17)
Double_t fMaxValue
! max value in image
Definition: TASImage.h:61
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
SVector< double, 2 > v
Definition: Dict.h:5
XPoint xy[kMAXMK]
Definition: TGX11.cxx:122
void Merge(const TImage *im, const char *op="alphablend", Int_t x=0, Int_t y=0)
Merge two images.
Definition: TASImage.cxx:2824
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
#define FillSpansInternal(npt, ppt, widths, color)
Definition: TASImage.cxx:3827
const Mask_t kGCClipXOrigin
Definition: GuiTypes.h:304
void FromWindow(Drawable_t wid, Int_t x=0, Int_t y=0, UInt_t w=0, UInt_t h=0)
Create an image (screenshot) from specified window.
Definition: TASImage.cxx:6724
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:482
TImagePalette fPalette
color palette for value -&gt; color conversion
Definition: TAttImage.h:81
void FloodFill(Int_t x, Int_t y, const char *col, const char *min_col, const char *max_col=0)
Flood fill.
Definition: TASImage.cxx:6602
void CropPolygon(UInt_t npt, TPoint *ppt)
Crop a convex polygon.
Definition: TASImage.cxx:5507
static FT_Matrix * GetRotMatrix()
Definition: TTF.cxx:829
void CropSpans(UInt_t npt, TPoint *ppt, UInt_t *widths)
Crop spans.
Definition: TASImage.cxx:5027
UShort_t * fColorAlpha
[fNumPoints] alpha at each anchor point
Definition: TAttImage.h:47
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2322
const char * AsHexString() const
Return color as hexadecimal string.
Definition: TColor.cxx:1174
unsigned int UInt_t
Definition: RtypesCore.h:42
TTF helper class containing glyphs description.
Definition: TTF.h:67
void Slice(UInt_t xStart, UInt_t xEnd, UInt_t yStart, UInt_t yEnd, UInt_t toWidth, UInt_t toHeight)
Another method of enlarging images where corners remain unchanged, but middle part gets tiled...
Definition: TASImage.cxx:1947
char * Form(const char *fmt,...)
const Handle_t kNone
Definition: GuiTypes.h:89
virtual void CellArrayBegin(Int_t W, Int_t H, Double_t x1, Double_t x2, Double_t y1, Double_t y2)=0
Pixmap_t GetMask()
Returns image mask pixmap (alpha channel).
Definition: TASImage.cxx:2302
virtual void SetPalette(const TImagePalette *palette)
Set a new palette for the image.
Definition: TAttImage.cxx:650
Array of longs (32 or 64 bits per element).
Definition: TArrayL.h:29
void AddAt(Long_t c, Int_t i)
Add long c at position i. Check for out of bounds.
Definition: TArrayL.cxx:93
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
const Mask_t kGCClipYOrigin
Definition: GuiTypes.h:305
The axis painter class.
Definition: TGaxis.h:30
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1070
void FillPolygon(UInt_t npt, TPoint *ppt, const char *col="#000000", const char *stipple=0, UInt_t w=16, UInt_t h=16)
Fill a convex polygon with background color or bitmap.
Definition: TASImage.cxx:5451
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
void Blur(Double_t hr=3, Double_t vr=3)
Perform Gaussian blur of the image (useful for drop shadows).
Definition: TASImage.cxx:2863
UInt_t fNumPoints
number of anchor points
Definition: TAttImage.h:42
virtual Int_t GetCanvasID() const =0
UInt_t fZoomOffX
! X - offset for zooming in image pixels
Definition: TASImage.h:63
void MapQuality(EImageQuality &quality, UInt_t &asquality, Bool_t toas=kTRUE)
Map quality to/from AfterImage quality.
Definition: TASImage.cxx:946
Int_t CountChar(Int_t c) const
Return number of times character c occurs in the string.
Definition: TString.cxx:444
Bool_t IsNull() const
Definition: TString.h:387
static void CreateETandAET(int count, TPoint *pts, EdgeTable *ET, EdgeTableEntry *AET, EdgeTableEntry *pETEs, ScanLineListBlock *pSLLBlock)
Definition: TASPolyUtils.c:365
void Flip(Int_t flip=180)
Flip image in place.
Definition: TASImage.cxx:2073
R__EXTERN TRandom * gRandom
Definition: TRandom.h:66
static int InsertionSort(EdgeTableEntry *AET)
Definition: TASPolyUtils.c:485
UShort_t * fColorBlue
[fNumPoints] blue color at each anchor point
Definition: TAttImage.h:46
TString fName
Definition: TNamed.h:36
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
virtual ~TASImage()
Image destructor, clean up image and visual.
Definition: TASImage.cxx:350
#define gVirtualX
Definition: TVirtualX.h:362
static const UInt_t NUMPTSTOBUFFER
Definition: TASImage.cxx:5528
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2241
TASImage * fScaledImage
! temporary scaled and zoomed image produced from original image
Definition: TASImage.h:60
void FillRectangle(const char *col=0, Int_t x=0, Int_t y=0, UInt_t width=0, UInt_t height=0)
Fill rectangle of size (width, height) at position (x,y) within the existing image with specified col...
Definition: TASImage.cxx:3917
Define a Frame.
Definition: TFrame.h:21
Double_t Cos(Double_t)
Definition: TMath.h:424
const Double_t * GetArray() const
Definition: TArrayD.h:45
Int_t GetSize() const
Definition: TArray.h:49
void HSV(UInt_t hue=0, UInt_t radius=360, Int_t H=0, Int_t S=0, Int_t V=0, Int_t x=0, Int_t y=0, UInt_t width=0, UInt_t height=0)
This function will tile original image to specified size with offsets requested, and then it will go ...
Definition: TASImage.cxx:3050
virtual void SetY2(Double_t y2)
Definition: TBox.h:78
Bool_t fConstRatio
keep aspect ratio of image on the screen
Definition: TAttImage.h:80
UInt_t * GetRgbaArray()
Return a pointer to an array[width x height] of RGBA32 values.
Definition: TASImage.cxx:3723
long Long_t
Definition: RtypesCore.h:50
Color * colors
Definition: X3DBuffer.c:19
int Ssiz_t
Definition: RtypesCore.h:63
void Tile(UInt_t width, UInt_t height)
Tile the original image.
Definition: TASImage.cxx:1983
Int_t fZoomUpdate
! kZoom - new zooming required, kZoomOps - other ops in action, kNoZoom - no zooming or ops ...
Definition: TASImage.h:67
void DrawText(Int_t x=0, Int_t y=0, const char *text="", Int_t size=12, const char *color=0, const char *font="fixed", EText3DType type=TImage::kPlain, const char *fore_file=0, Float_t angle=0)
Draw text of size (in pixels for TrueType fonts) at position (x, y) with color specified by hex strin...
Definition: TASImage.cxx:2580
void Bevel(Int_t x=0, Int_t y=0, UInt_t width=0, UInt_t height=0, const char *hi="#ffdddddd", const char *lo="#ff555555", UShort_t thick=1, Bool_t pressed=kFALSE)
Bevel is used to create 3D effect while drawing buttons, or any other image that needs to be framed...
Definition: TASImage.cxx:3353
Bool_t IsValid() const
Definition: TASImage.h:186
void DrawPolyLine(UInt_t nn, TPoint *xy, const char *col="#000000", UInt_t thick=1, TImage::ECoordMode mode=kCoordModeOrigin)
Draw a polyline.
Definition: TASImage.cxx:4769
static const double x1[5]
void Crop(Int_t x=0, Int_t y=0, UInt_t width=0, UInt_t height=0)
Crop an image.
Definition: TASImage.cxx:3518
#define ClassImp(name)
Definition: Rtypes.h:279
struct _EdgeTableEntry EdgeTableEntry
void Mirror(Bool_t vert=kTRUE)
Mirror image in place.
Definition: TASImage.cxx:2120
static Int_t GetAscent()
Definition: TTF.cxx:815
void DrawEllips(Int_t x, Int_t y, Int_t rx, Int_t ry, Int_t angle, const char *col="#000000", Int_t thick=1)
Draw an ellipse.
Definition: TASImage.cxx:6523
double Double_t
Definition: RtypesCore.h:55
void PaintImage(Drawable_t wid, Int_t x, Int_t y, Int_t xsrc=0, Int_t ysrc=0, UInt_t wsrc=0, UInt_t hsrc=0, Option_t *opt="")
Draw image on the drawable wid (pixmap, window) at x,y position.
Definition: TASImage.cxx:1343
TText * text
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
#define free
Definition: civetweb.c:821
unsigned long ULong_t
Definition: RtypesCore.h:51
UInt_t fZoomHeight
! hight of zoomed image in image pixels
Definition: TASImage.h:66
ECoordMode
Definition: TImage.h:93
virtual Int_t FindColor(UShort_t r, UShort_t g, UShort_t b)
Returns an index of the closest color.
Definition: TAttImage.cxx:485
Double_t y[n]
Definition: legend1.C:17
static ARGB32 GetHilite(ARGB32 background)
Calculate highlite color.
Definition: TASImage.cxx:3304
static void destroy_asdraw_context32(ASDrawContext *ctx)
Destroy asdraw context32.
Definition: TASImage.cxx:5753
void Add(TObject *obj)
Add object to the hash table.
Definition: THashTable.cxx:76
void DrawDashLine(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t nDash, const char *pDash, const char *col="#000000", UInt_t thick=1)
Draw a dashed line.
Definition: TASImage.cxx:4725
#define _MEMSET_(dst, lng, val)
Definition: TASImage.cxx:3822
The color creation and management class.
Definition: TColor.h:23
struct _ScanLineListBlock ScanLineListBlock
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:494
static CARD8 MakeComponentHilite(int cmp)
Make component hilite.
Definition: TASImage.cxx:3290
void GetImageBuffer(char **buffer, int *size, EImageFileTypes type=TImage::kPng)
Return in-memory buffer compressed according image type.
Definition: TASImage.cxx:6075
void FromGLBuffer(UChar_t *buf, UInt_t w, UInt_t h)
Creates an image (screenshot) from a RGBA buffer.
Definition: TASImage.cxx:6775
#define _alphaBlend(bot, top)
Definition: TASImage.cxx:153
TImage & operator=(const TImage &img)
Definition: TImage.h:112
A class to define a conversion from pixel values to pixel color.
Definition: TAttImage.h:39
void DrawLineInternal(UInt_t x1, UInt_t y1, UInt_t x2, UInt_t y2, UInt_t col, UInt_t thick)
Internal line drawing.
Definition: TASImage.cxx:4024
Array of doubles (64 bits per element).
Definition: TArrayD.h:29
virtual void Draw(Option_t *option="")
Draw this box with its current attributes.
Definition: TBox.cxx:180
#define SETBIT(n, i)
Definition: Rtypes.h:121
SCoord_t GetX() const
Definition: TPoint.h:49
Mother of all ROOT objects.
Definition: TObject.h:37
Double_t fMinValue
! min value in image
Definition: TASImage.h:62
void DrawDashVLine(UInt_t x, UInt_t y1, UInt_t y2, UInt_t nDash, const char *pDash, UInt_t col, UInt_t thick)
Draw a dashed vertical line.
Definition: TASImage.cxx:4326
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition: TString.cxx:1807
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
Definition: TTF.cxx:351
Int_t GetNoElements() const
Definition: TVectorT.h:82
static ASVisual * fgVisual
pointer to visual structure
Definition: TASImage.h:74
Handle_t Window_t
Definition: GuiTypes.h:30
UShort_t * fColorGreen
[fNumPoints] green color at each anchor point
Definition: TAttImage.h:45
Mask_t fMask
Definition: GuiTypes.h:252
TASImage()
Default image constructor.
Definition: TASImage.cxx:219
void AddAt(Double_t c, Int_t i)
Add double c at position i. Check for out of bounds.
Definition: TArrayD.cxx:93
static Bool_t fgInit
global flag to init afterimage only once
Definition: TASImage.h:75
void DrawEllips2(Int_t x, Int_t y, Int_t rx, Int_t ry, Int_t angle, const char *col="#000000", Int_t thick=1)
Draw an ellipse.
Definition: TASImage.cxx:6563
virtual Int_t VtoPixel(Double_t v) const =0
const Ssiz_t kNPOS
Definition: Rtypes.h:115
const char * TypeFromMagicNumber(const char *file)
Guess the file type from the first byte of file.
Definition: TASImage.cxx:394
void DrawSegments(UInt_t nseg, Segment_t *seg, const char *col="#000000", UInt_t thick=1)
Draw segments.
Definition: TASImage.cxx:4889
Bool_t GetConstRatio() const
Definition: TAttImage.h:91
void DrawStraightEllips(Int_t x, Int_t y, Int_t rx, Int_t ry, const char *col="#000000", Int_t thick=1)
Draw a straight ellipse.
Definition: TASImage.cxx:6443
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
Handle_t Pixmap_t
Definition: GuiTypes.h:31
struct _ScanLineList ScanLineList
Double_t Sin(Double_t)
Definition: TMath.h:421
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashTable.cxx:210
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
virtual void * GetStream() const
Definition: TVirtualPS.h:81
#define NULL
Definition: Rtypes.h:82
#define snprintf
Definition: civetweb.c:822
R__EXTERN TVirtualPS * gVirtualPS
Definition: TVirtualPS.h:91
#define gPad
Definition: TVirtualPad.h:289
virtual void StartPaletteEditor()
Opens a GUI to edit the color palette.
Definition: TAttImage.cxx:779
TASImage & operator=(const TASImage &img)
Image assignment operator.
Definition: TASImage.cxx:316
#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2)
Definition: TASPolyUtils.c:93
static void SetTextSize(Float_t textsize)
Set current text size.
Definition: TTF.cxx:755
float type_of_call hi(const int &, const int &)
#define gDirectory
Definition: TDirectory.h:221
double result[121]
unsigned char UChar_t
Definition: RtypesCore.h:34
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition: TVirtualPS.h:40
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1243
void flip(struct mesh *m, struct behavior *b, struct otri *flipedge)
Definition: triangle.c:7889
const int nn
UInt_t fZoomWidth
! width of zoomed image in image pixels
Definition: TASImage.h:65
ASImage * fGrayImage
! gray image
Definition: TASImage.h:70
EText3DType
Definition: TImage.h:66
static TImage * Create()
Create an image.
Definition: TImage.cxx:36
void DestroyImage()
Destroy image.
Definition: TASImage.cxx:174
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
void DrawHLine(UInt_t y, UInt_t x1, UInt_t x2, UInt_t col, UInt_t thick)
Draw an horizontal line.
Definition: TASImage.cxx:3978
static const UInt_t kBrushCacheSize
Definition: TASImage.cxx:5761
static Int_t GetNumGlyphs()
Definition: TTF.cxx:822
const Bool_t kTRUE
Definition: Rtypes.h:91
float * q
Definition: THbookFile.cxx:87
Float_t GetScreenFactor() const
Definition: TStyle.h:256
Pixmap_t GetPixmap()
Returns image pixmap.
Definition: TASImage.cxx:2270
virtual void SetY1(Double_t y1)
Definition: TBox.h:77
Int_t Nint(T x)
Definition: TMath.h:480
ASImage * fImage
! pointer to image structure of original image
Definition: TASImage.h:59
Bool_t GetPolygonSpans(UInt_t npt, TPoint *ppt, UInt_t *nspans, TPoint **firstPoint, UInt_t **firstWidth)
The code is based on Xserver/mi/mipolycon.c &quot;Copyright 1987, 1998 The Open Group&quot;.
Definition: TASImage.cxx:5306
void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute mouse events.
Definition: TASImage.cxx:1703
const Int_t n
Definition: legend1.C:16
void SetDefaults()
Set default parameters.
Definition: TASImage.cxx:192
EGraphicsFunction
Definition: GuiTypes.h:68
virtual void Open(const char *filename, Int_t type=-111)=0
char * GetObjectInfo(Int_t px, Int_t py) const
Get image pixel coordinates and the pixel value at the mouse pointer.
Definition: TASImage.cxx:1816
To make it possible to use GL for 2D graphic in a TPad/TCanvas.
virtual unsigned char * ReadFile(const char *filename, UInt_t &w, UInt_t &h)=0
char name[80]
Definition: TGX11.cxx:109
static void Image2Drawable(ASImage *im, Drawable_t wid, Int_t x, Int_t y, Int_t xsrc=0, Int_t ysrc=0, UInt_t wsrc=0, UInt_t hsrc=0, Option_t *opt="")
Draw asimage on drawable.
Definition: TASImage.cxx:1221
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:467
const char * cnt
Definition: TXMLSetup.cxx:75
void Gradient(UInt_t angle=0, const char *colors="#FFFFFF #000000", const char *offsets=0, Int_t x=0, Int_t y=0, UInt_t width=0, UInt_t height=0)
Render multipoint gradient inside rectangle of size (width, height) at position (x,y) within the existing image.
Definition: TASImage.cxx:3113
if(line.BeginsWith("/*"))
Definition: HLFactory.cxx:443
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
UInt_t GetScaledWidth() const
Return width of the displayed image not of the original image.
Definition: TASImage.cxx:2168
static const FT_BBox & GetBox()
Definition: TTF.cxx:836
Int_t GetNumber() const
Definition: TColor.h:58
virtual TCanvas * GetCanvas() const =0
const void * GetWcsTitle(void) const
Returns the text as UNICODE.
Definition: TText.cxx:130
static const double x3[11]
void DrawVLine(UInt_t x, UInt_t y1, UInt_t y2, UInt_t col, UInt_t thick)
Draw a vertical line.
Definition: TASImage.cxx:3943
virtual void BeginPaint(Bool_t=kTRUE)
Definition: TImage.h:190
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911