blob: 5a54ce65efbc4359c5fcd5bfe3291b4a0c9718c5 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001// This may look like C code, but it is really -*- C++ -*-
2//
3// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
4//
5// Pixels Implementation
6//
7
8#define MAGICKCORE_IMPLEMENTATION 1
9#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
10
cristy05065f42011-09-08 01:11:30 +000011#include <cstring>
cristy3ed852e2009-09-05 21:47:34 +000012#include "Magick++/Include.h"
13#include <string> // This is here to compile with Visual C++
14#include "Magick++/Thread.h"
15#include "Magick++/Exception.h"
16#include "Magick++/Pixels.h"
17
18namespace Magick
19{
20
21
22}
23
24// Construct pixel view using specified image.
25Magick::Pixels::Pixels( Magick::Image &image_ )
26 : _image(image_),
27 _view(AcquireCacheView(_image.image())),
28 _x(0),
29 _y(0),
30 _columns(0),
31 _rows(0)
32{
33 GetExceptionInfo( &_exception );
34
35 if (!_view)
36 _image.throwImageException();
cristy3ed852e2009-09-05 21:47:34 +000037}
38
39// Destroy pixel view
40Magick::Pixels::~Pixels( void )
41{
42 if ( _view )
43 _view = DestroyCacheView( _view );
44
cristy2040ecb2010-10-19 01:02:48 +000045 (void) DestroyExceptionInfo( &_exception );
cristy3ed852e2009-09-05 21:47:34 +000046}
47
48// Transfer pixels from the image to the pixel view as defined by
49// the specified region. Modified pixels may be subsequently
50// transferred back to the image via sync.
cristy4c08aed2011-07-01 19:47:50 +000051Magick::Quantum* Magick::Pixels::get ( const ssize_t x_,
cristyd99b0962010-05-29 23:14:26 +000052 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +000053 const size_t columns_,
54 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +000055{
56 _x = x_;
57 _y = y_;
58 _columns = columns_;
59 _rows = rows_;
60
cristy4c08aed2011-07-01 19:47:50 +000061 Quantum* pixels = GetCacheViewAuthenticPixels( _view, x_, y_, columns_, rows_, &_exception);
cristy3ed852e2009-09-05 21:47:34 +000062
63 if ( !pixels )
cristy1f1d6372010-10-19 01:08:11 +000064 throwException( _exception );
cristy3ed852e2009-09-05 21:47:34 +000065
66 return pixels;
67}
68
69// Transfer read-only pixels from the image to the pixel view as
70// defined by the specified region.
cristy4c08aed2011-07-01 19:47:50 +000071const Magick::Quantum* Magick::Pixels::getConst ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +000072 const size_t columns_,
73 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +000074{
75 _x = x_;
76 _y = y_;
77 _columns = columns_;
78 _rows = rows_;
79
cristy4c08aed2011-07-01 19:47:50 +000080 const Quantum* pixels =
cristy3ed852e2009-09-05 21:47:34 +000081 GetCacheViewVirtualPixels(_view, x_, y_, columns_, rows_, &_exception );
82
83 if ( !pixels )
84 throwException( _exception );
85
86 return pixels;
87}
88
89// Transfers the image view pixels to the image.
90void Magick::Pixels::sync ( void )
91{
92 if( !SyncCacheViewAuthenticPixels( _view, &_exception ) )
93 throwException( _exception );
94}
95
96// Allocate a pixel view region to store image pixels as defined
97// by the region rectangle. This area is subsequently transferred
98// from the pixel view to the image via 'sync'.
cristy4c08aed2011-07-01 19:47:50 +000099Magick::Quantum* Magick::Pixels::set ( const ssize_t x_,
cristyd99b0962010-05-29 23:14:26 +0000100 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +0000101 const size_t columns_,
102 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +0000103{
104 _x = x_;
105 _y = y_;
106 _columns = columns_;
107 _rows = rows_;
108
cristy4c08aed2011-07-01 19:47:50 +0000109 Quantum* pixels = QueueCacheViewAuthenticPixels( _view, x_, y_,
cristy3ed852e2009-09-05 21:47:34 +0000110 columns_, rows_, &_exception );
111 if ( !pixels )
112 throwException( _exception );
113
114 return pixels;
115}
116
117// Return pixel colormap index array
cristy4c08aed2011-07-01 19:47:50 +0000118/*
119Magick::void* Magick::Pixels::metacontent ( void )
cristy3ed852e2009-09-05 21:47:34 +0000120{
cristy4c08aed2011-07-01 19:47:50 +0000121 void* pixel_metacontent = GetCacheViewAuthenticMetacontent( _view );
cristy3ed852e2009-09-05 21:47:34 +0000122
cristy4c08aed2011-07-01 19:47:50 +0000123 if ( !pixel_metacontent )
cristy3ed852e2009-09-05 21:47:34 +0000124 _image.throwImageException();
125
cristy4c08aed2011-07-01 19:47:50 +0000126 return pixel_metacontent;
cristy3ed852e2009-09-05 21:47:34 +0000127}
cristy4c08aed2011-07-01 19:47:50 +0000128*/