tbx  0.7.3
jpeg.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 /*
26  * jpeg.h
27  *
28  * Created on: 2 Nov 2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_JPEG_H_
33 #define TBX_JPEG_H_
34 
35 #include "image.h"
36 #include "bbox.h"
37 #include "scalefactors.h"
38 #include "drawtransform.h"
39 #include <string>
40 
41 namespace tbx {
42 
48 class JPEG : public Image
49 {
50 private:
51  unsigned char *_image;
52  int _size;
53  int _flags;
54  int _width;
55  int _height;
56  int _x_density;
57  int _y_density;
58  int _extra_workspace;
59  int _plot_flags;
60 public:
61  JPEG();
62  JPEG(const JPEG &other);
63  virtual ~JPEG();
64 
65  JPEG &operator=(const JPEG &other);
66 
67  // Image override
68  virtual void plot(int x, int y) const;
69  virtual void plot(const Point &pos) const;
70 
71  bool load(const std::string &file_name);
72 
73  void plot(int x, int y, const ScaleFactors &sf);
74  void plot(const BBox &bbox);
75  void plot(const DrawTransform &dt);
76 
77  void dithered(bool dither);
78 
84  bool dithered() const {return ((_plot_flags & 1) != 0);}
85  void error_defused(bool error_defused);
91  bool error_defused() const {return ((_plot_flags & 2) != 0);}
92 
98  bool is_valid() const {return (_image != 0);}
99 
105  int width() const {return _width;}
106 
112  int height() const {return _height;}
113 
119  int x_density() const {return _x_density;}
125  int y_density() const {return _y_density;}
131  int extra_workspace() const {return _extra_workspace;}
132 
138  bool greyscale()const {return ((_flags & 1) != 0);}
144  bool transform_plot_suppoted() const {return ((_flags & 2) == 0);}
150  bool density_simple_ratio() const {return ((_flags & 4) != 0);}
151 
152  static bool IsJPEGFile(const std::string &file_name);
153  static bool GetFileInfo(const std::string &file_name, int *width, int *height, int *x_density, int *y_density, int *workspace, bool *greyscale_image, bool *no_transform_plots, bool *pixel_density_is_simple_ratio);
154 };
155 
156 }
157 
158 #endif /* TBX_JPEG_H_ */
Class to represent Drawing transforms.
Definition: drawtransform.h:59
bool error_defused() const
Return error defused plot flag.
Definition: jpeg.h:91
bool load(const std::string &file_name)
Load JPEG from file.
Definition: jpeg.cc:115
int x_density() const
Get the horizontal pixel density.
Definition: jpeg.h:119
Class to represent a two dimensional bounding box.
Definition: bbox.h:37
int extra_workspace() const
Return the extra memory required to plot this image.
Definition: jpeg.h:131
virtual void plot(int x, int y) const
Plot jpeg to screen.
Definition: jpeg.cc:166
static bool IsJPEGFile(const std::string &file_name)
Check if a file is a JPEG file.
Definition: jpeg.cc:298
Base class image classes providing a consistent interface to plot the to the screen.
Definition: image.h:44
int width() const
Get the width of image.
Definition: jpeg.h:105
Class to represent a position in two dimensional space.
Definition: point.h:36
bool density_simple_ratio() const
Check if this image has a simple density ratio.
Definition: jpeg.h:150
int y_density() const
Get the vertical pixel density.
Definition: jpeg.h:125
bool transform_plot_suppoted() const
Check is transform plots are supported for this image.
Definition: jpeg.h:144
static bool GetFileInfo(const std::string &file_name, int *width, int *height, int *x_density, int *y_density, int *workspace, bool *greyscale_image, bool *no_transform_plots, bool *pixel_density_is_simple_ratio)
Get information on a JPEG file.
Definition: jpeg.cc:326
virtual ~JPEG()
Destroy image data if loaded.
Definition: jpeg.cc:58
bool dithered() const
Return dithered plot flag.
Definition: jpeg.h:84
bool greyscale() const
Check if image is grey scale.
Definition: jpeg.h:138
Class for sprite ScaleFactors.
Definition: scalefactors.h:45
Class to load and display JPEG images.
Definition: jpeg.h:48
JPEG & operator=(const JPEG &other)
Assignment operator.
Definition: jpeg.cc:87
int height() const
Get the height of image.
Definition: jpeg.h:112
bool is_valid() const
Check if JPEG class contains an image.
Definition: jpeg.h:98
JPEG()
Construct an unloaded JPEG image.
Definition: jpeg.cc:42