ProteoWizard
Image.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2005 Louis Warschaw Prostate Cancer Center
8// Cedars Sinai Medical Center, Los Angeles, California 90048
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23
24#ifndef _IMAGE_HPP_
25#define _IMAGE_HPP_
26
27
29#include <memory>
30#include <string>
31
32
33namespace pwiz {
34namespace util {
35
36
37/// wrapper class for using 'gd' graphics library
39{
40 public:
41
42 /// struct for holding rgb values (in [0,255])
44 {
45 int red;
46 int green;
47 int blue;
48
49 Color(int r=0, int g=0, int b=0) : red(r), green(g), blue(b) {}
50 };
51
52 static Color white() {return Color(255, 255, 255);}
53 static Color black() {return Color(0, 0, 0);}
54
55 /// struct for holding pixel coordinates
57 {
58 int x;
59 int y;
60
61 Point(int _x=0, int _y=0) : x(_x), y(_y) {}
62 };
63
64 enum PWIZ_API_DECL Align {Left=0x01, CenterX=0x02, Right=0x04, Top=0x08, CenterY=0x10, Bottom=0x20};
65 enum PWIZ_API_DECL Size {Tiny, Small, MediumBold, Large, Giant};
66
67 /// create an instance
68 /// optional output_width and output_height allows easy scaling to a desired output
69 /// image size without complicating the drawing code (default is to use logical width and height)
70 static std::auto_ptr<Image> create(int logical_width, int logical_height,
71 int output_width=-1, int output_height=-1); // -1 means use logical
72
73 /// draw pixel
74 virtual void pixel(const Point& point, const Color& color) = 0;
75
76 /// draw string
77 virtual void string(const std::string& text, const Point& point, const Color& color,
78 Size size=Large, int align=Left|Top) = 0;
79
80 /// draw string
81 virtual void stringUp(const std::string& text, const Point& point, const Color& color,
82 Size size=Large, int align=Left|Top) = 0;
83
84 /// draw rectangle
85 virtual void rectangle(const Point& point1, const Point& point2, const Color& color,
86 bool filled=true) = 0;
87
88 /// draw circle
89 virtual void circle(const Point& center, int radius, const Color& color,
90 bool filled=true) = 0;
91
92 /// draw line
93 virtual void line(const Point& point1, const Point& point2, const Color& color) = 0;
94
95 /// set clipping rectangle
96 virtual void clip(const Point& point1, const Point& point2) = 0;
97
98 /// write png file
99 virtual bool writePng(const char* filename) const = 0;
100
101 virtual ~Image(){}
102};
103
104
106{
107 return Image::Point(a.x+b.x, a.y+b.y);
108}
109
110
112{
113 return Image::Point(a.x-b.x, a.y-b.y);
114}
115
116
117} // namespace util
118} // namespace pwiz
119
120
121#endif // _IMAGE_HPP_
#define PWIZ_API_DECL
Definition Export.hpp:32
Right
Definition Image.hpp:64
Large
Definition Image.hpp:65
Tiny
Definition Image.hpp:65
MediumBold
Definition Image.hpp:65
Top
Definition Image.hpp:64
CenterX
Definition Image.hpp:64
Left
Definition Image.hpp:64
CenterY
Definition Image.hpp:64
Small
Definition Image.hpp:65
KernelTraitsBase< Kernel >::space_type::abscissa_type x
KernelTraitsBase< Kernel >::space_type::ordinate_type y
wrapper class for using 'gd' graphics library
Definition Image.hpp:39
virtual ~Image()
Definition Image.hpp:101
virtual void circle(const Point &center, int radius, const Color &color, bool filled=true)=0
draw circle
static Color black()
Definition Image.hpp:53
static std::auto_ptr< Image > create(int logical_width, int logical_height, int output_width=-1, int output_height=-1)
create an instance optional output_width and output_height allows easy scaling to a desired output im...
virtual bool writePng(const char *filename) const =0
write png file
virtual void line(const Point &point1, const Point &point2, const Color &color)=0
draw line
virtual void stringUp(const std::string &text, const Point &point, const Color &color, Size size=Large, int align=Left|Top)=0
draw string
virtual void pixel(const Point &point, const Color &color)=0
draw pixel
virtual void rectangle(const Point &point1, const Point &point2, const Color &color, bool filled=true)=0
draw rectangle
static Color white()
Definition Image.hpp:52
virtual void string(const std::string &text, const Point &point, const Color &color, Size size=Large, int align=Left|Top)=0
draw string
virtual void clip(const Point &point1, const Point &point2)=0
set clipping rectangle
Image::Point operator-(const Image::Point &a, const Image::Point &b)
Definition Image.hpp:111
Image::Point operator+(const Image::Point &a, const Image::Point &b)
Definition Image.hpp:105
struct for holding rgb values (in [0,255])
Definition Image.hpp:44
Color(int r=0, int g=0, int b=0)
Definition Image.hpp:49
struct for holding pixel coordinates
Definition Image.hpp:57
Point(int _x=0, int _y=0)
Definition Image.hpp:61