blob: 5f755706a2d04d95253eadffdc83a06c004ca844 [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
11#include "Magick++/Include.h"
12#include <string> // This is here to compile with Visual C++
13#include "Magick++/Thread.h"
14#include "Magick++/Exception.h"
15#include "Magick++/Pixels.h"
16
17namespace Magick
18{
19
20
21}
22
23// Construct pixel view using specified image.
24Magick::Pixels::Pixels( Magick::Image &image_ )
25 : _image(image_),
26 _view(AcquireCacheView(_image.image())),
27 _x(0),
28 _y(0),
29 _columns(0),
30 _rows(0)
31{
32 GetExceptionInfo( &_exception );
33
34 if (!_view)
35 _image.throwImageException();
cristy3ed852e2009-09-05 21:47:34 +000036}
37
38// Destroy pixel view
39Magick::Pixels::~Pixels( void )
40{
41 if ( _view )
42 _view = DestroyCacheView( _view );
43
cristy2040ecb2010-10-19 01:02:48 +000044 (void) DestroyExceptionInfo( &_exception );
cristy3ed852e2009-09-05 21:47:34 +000045}
46
47// Transfer pixels from the image to the pixel view as defined by
48// the specified region. Modified pixels may be subsequently
49// transferred back to the image via sync.
cristy4c08aed2011-07-01 19:47:50 +000050Magick::Quantum* Magick::Pixels::get ( const ssize_t x_,
cristyd99b0962010-05-29 23:14:26 +000051 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +000052 const size_t columns_,
53 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +000054{
55 _x = x_;
56 _y = y_;
57 _columns = columns_;
58 _rows = rows_;
59
cristy4c08aed2011-07-01 19:47:50 +000060 Quantum* pixels = GetCacheViewAuthenticPixels( _view, x_, y_, columns_, rows_, &_exception);
cristy3ed852e2009-09-05 21:47:34 +000061
62 if ( !pixels )
cristy1f1d6372010-10-19 01:08:11 +000063 throwException( _exception );
cristy3ed852e2009-09-05 21:47:34 +000064
65 return pixels;
66}
67
68// Transfer read-only pixels from the image to the pixel view as
69// defined by the specified region.
cristy4c08aed2011-07-01 19:47:50 +000070const Magick::Quantum* Magick::Pixels::getConst ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +000071 const size_t columns_,
72 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +000073{
74 _x = x_;
75 _y = y_;
76 _columns = columns_;
77 _rows = rows_;
78
cristy4c08aed2011-07-01 19:47:50 +000079 const Quantum* pixels =
cristy3ed852e2009-09-05 21:47:34 +000080 GetCacheViewVirtualPixels(_view, x_, y_, columns_, rows_, &_exception );
81
82 if ( !pixels )
83 throwException( _exception );
84
85 return pixels;
86}
87
88// Transfers the image view pixels to the image.
89void Magick::Pixels::sync ( void )
90{
91 if( !SyncCacheViewAuthenticPixels( _view, &_exception ) )
92 throwException( _exception );
93}
94
95// Allocate a pixel view region to store image pixels as defined
96// by the region rectangle. This area is subsequently transferred
97// from the pixel view to the image via 'sync'.
cristy4c08aed2011-07-01 19:47:50 +000098Magick::Quantum* Magick::Pixels::set ( const ssize_t x_,
cristyd99b0962010-05-29 23:14:26 +000099 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +0000100 const size_t columns_,
101 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +0000102{
103 _x = x_;
104 _y = y_;
105 _columns = columns_;
106 _rows = rows_;
107
cristy4c08aed2011-07-01 19:47:50 +0000108 Quantum* pixels = QueueCacheViewAuthenticPixels( _view, x_, y_,
cristy3ed852e2009-09-05 21:47:34 +0000109 columns_, rows_, &_exception );
110 if ( !pixels )
111 throwException( _exception );
112
113 return pixels;
114}
115
116// Return pixel colormap index array
cristy4c08aed2011-07-01 19:47:50 +0000117/*
118Magick::void* Magick::Pixels::metacontent ( void )
cristy3ed852e2009-09-05 21:47:34 +0000119{
cristy4c08aed2011-07-01 19:47:50 +0000120 void* pixel_metacontent = GetCacheViewAuthenticMetacontent( _view );
cristy3ed852e2009-09-05 21:47:34 +0000121
cristy4c08aed2011-07-01 19:47:50 +0000122 if ( !pixel_metacontent )
cristy3ed852e2009-09-05 21:47:34 +0000123 _image.throwImageException();
124
cristy4c08aed2011-07-01 19:47:50 +0000125 return pixel_metacontent;
cristy3ed852e2009-09-05 21:47:34 +0000126}
cristy4c08aed2011-07-01 19:47:50 +0000127*/