Re: how to use graphics???
On Aug 11, 6:10 pm, "Alf P. Steinbach" <al...@start.no> wrote:
* mohi:
hello everyone,
we have a course on computer graphics and they are teaching various
algorithms to draw lines and circles and all of them
require the classical putpixel() function in c++. As i have learned
from web sources that this function is no longer in existence .is that
true?? and if so what can i use that can provide the same
functionalities, i mean is there a new form of that function or what
should i do??
i use gnu g++ on command line.
You might use the Boost library.
However, the documentation and code seems to be the winner in a contest o=
f
obfuscation and Bad Programming Habits.
I cooked up a usage example, shown below, and if this serves your needs t=
hen you
won't have to confront the full horror of that library! :-)
Disclaimer:
I haven't worked with the graphics part of Boost before, so it may very w=
ell be
that I'm using this in a non-idiomatic way!
<code>
// Visual C++ sillywarnings:
#ifdef _MSC_VER
# pragma warning( disable: 4100 ) // unreferenced a=
rgument
# pragma warning( disable: 4127 ) // constant condi=
tional expression
# pragma warning( disable: 4512 ) // can't gen. ass=
ignment operator
#endif
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
class ImageData: public boost::gil::rgb8_image_t
{
public:
typedef boost::gil::rgb8_image_t Base;
ImageData( size_t w, size_t h ): Base( w, h ) {}
boost::gil::rgb8_view_t view()
{
return boost::gil::view( *this );
}
};
class Image
: protected ImageData // I=
mage data, must be first (init)
, protected boost::gil::rgb8_view_t // Image operation=
s
{
private:
typedef boost::gil::rgb8_view_t ImageOps;
typedef boost::gil::rgb8c_view_t ConstImageOps;
friend class ConstImageOps;
public:
typedef ImageOps::reference PixelRef;
Image( size_t w, size_t h )
: ImageData( w, h )
, ImageOps( ImageData::view() )
{}
PixelRef operator()( size_t x, size_t y )
{
return ImageOps::operator()( x, y );
}
ImageOps const& view() { return *this; }
ConstImageOps view() const { return static_cast<ImageOps const=
&>( *this ); }
};
typedef boost::gil::rgb8_pixel_t ColorRGB;
int main()
{
Image image( 42, 42 );
for( int x = 0; x < 42; ++x )
{
image( x, x ) = ColorRGB( 0xff, 0, 0 );
}
boost::gil::png_write_view( "an_image.png", image.view() );}
</code>
Note: the above doesn't compile cleanly with Visual C++. That's because t=
he PNG
i/o is really really horrible code (adding a notch of horribility (whatev=
er) to
the degree present in the main library). Looks like this:
<diagnostics>
c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io_private.=
hp=ADp(157)
: warning C4611: interaction between '_setjmp' and C++ object destruction=
is
non-portable
c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io_private.=
hp=ADp(319)
: warning C4611: interaction between '_setjmp' and C++ object destruction=
is
non-portable
c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io_private.=
hp=ADp(340)
: warning C4244: 'argument' : conversion from
'boost::gil::image_view<Loc>::y_coord_t' to 'png_uint_32', possible loss =
of data
with
[
Loc=boost::gil::rgb8_loc_t
]
c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io.hpp(202)=
: see
reference to function template instantiation 'void
boost::gil::detail::png_writer::apply<View>(const View &)' being compiled
with
[
View=Image::ImageOps
]
vc_project.cpp(65) : see reference to function templat=
e instantiation
'void boost::gil::png_write_view<Image::ImageOps>(const char *,const View=
&)'
being compiled
with
[
View=Image::ImageOps
]
c:\projects\lib\boost\boost_1_35_0\boost\gil\extension\io\png_io_private.=
hp=ADp(340)
: warning C4244: 'argument' : conversion from
'boost::gil::image_view<Loc>::x_coord_t' to 'png_uint_32', possible loss =
of data
with
[
Loc=boost::gil::rgb8_loc_t
]
</diagnostics>
Especially the diagnostic about 'setjmp' makes alarm bells go off in my b=
rain.
But hey, it's part of Boost. So even if it's not perfect yet, in fact ver=
y far
from perfect, it'll presumably be fixed, at least so it compiles cleanly =
with no
warnings.
Just disregard all those warnings -- if you get any with g++.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Both libpng and jpeglib use setjmp internally and that would require
someone with balls to do code review.