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