blob: d0e95b6b3cc24745083f836f0988c16c5338badd [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>
12#include <cstring>
cristy3ed852e2009-09-05 21:47:34 +000013#include "Magick++/Include.h"
14#include <string> // This is here to compile with Visual C++
15#include "Magick++/Thread.h"
16#include "Magick++/Exception.h"
17#include "Magick++/Pixels.h"
18
19namespace Magick
20{
21
22
23}
24
25// Construct pixel view using specified image.
26Magick::Pixels::Pixels( Magick::Image &image_ )
27 : _image(image_),
28 _view(AcquireCacheView(_image.image())),
29 _x(0),
30 _y(0),
31 _columns(0),
32 _rows(0)
33{
34 GetExceptionInfo( &_exception );
35
36 if (!_view)
37 _image.throwImageException();
cristy3ed852e2009-09-05 21:47:34 +000038}
39
40// Destroy pixel view
41Magick::Pixels::~Pixels( void )
42{
43 if ( _view )
44 _view = DestroyCacheView( _view );
45
cristy2040ecb2010-10-19 01:02:48 +000046 (void) DestroyExceptionInfo( &_exception );
cristy3ed852e2009-09-05 21:47:34 +000047}
48
49// Transfer pixels from the image to the pixel view as defined by
50// the specified region. Modified pixels may be subsequently
51// transferred back to the image via sync.
cristy4c08aed2011-07-01 19:47:50 +000052Magick::Quantum* Magick::Pixels::get ( const ssize_t x_,
cristyd99b0962010-05-29 23:14:26 +000053 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +000054 const size_t columns_,
55 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +000056{
57 _x = x_;
58 _y = y_;
59 _columns = columns_;
60 _rows = rows_;
61
cristy4c08aed2011-07-01 19:47:50 +000062 Quantum* pixels = GetCacheViewAuthenticPixels( _view, x_, y_, columns_, rows_, &_exception);
cristy3ed852e2009-09-05 21:47:34 +000063
64 if ( !pixels )
cristy1f1d6372010-10-19 01:08:11 +000065 throwException( _exception );
cristy3ed852e2009-09-05 21:47:34 +000066
67 return pixels;
68}
69
70// Transfer read-only pixels from the image to the pixel view as
71// defined by the specified region.
cristy4c08aed2011-07-01 19:47:50 +000072const Magick::Quantum* Magick::Pixels::getConst ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +000073 const size_t columns_,
74 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +000075{
76 _x = x_;
77 _y = y_;
78 _columns = columns_;
79 _rows = rows_;
80
cristy4c08aed2011-07-01 19:47:50 +000081 const Quantum* pixels =
cristy3ed852e2009-09-05 21:47:34 +000082 GetCacheViewVirtualPixels(_view, x_, y_, columns_, rows_, &_exception );
83
84 if ( !pixels )
85 throwException( _exception );
86
87 return pixels;
88}
89
90// Transfers the image view pixels to the image.
91void Magick::Pixels::sync ( void )
92{
93 if( !SyncCacheViewAuthenticPixels( _view, &_exception ) )
94 throwException( _exception );
95}
96
97// Allocate a pixel view region to store image pixels as defined
98// by the region rectangle. This area is subsequently transferred
99// from the pixel view to the image via 'sync'.
cristy4c08aed2011-07-01 19:47:50 +0000100Magick::Quantum* Magick::Pixels::set ( const ssize_t x_,
cristyd99b0962010-05-29 23:14:26 +0000101 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +0000102 const size_t columns_,
103 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +0000104{
105 _x = x_;
106 _y = y_;
107 _columns = columns_;
108 _rows = rows_;
109
cristy4c08aed2011-07-01 19:47:50 +0000110 Quantum* pixels = QueueCacheViewAuthenticPixels( _view, x_, y_,
cristy3ed852e2009-09-05 21:47:34 +0000111 columns_, rows_, &_exception );
112 if ( !pixels )
113 throwException( _exception );
114
115 return pixels;
116}
117
118// Return pixel colormap index array
cristy4c08aed2011-07-01 19:47:50 +0000119/*
120Magick::void* Magick::Pixels::metacontent ( void )
cristy3ed852e2009-09-05 21:47:34 +0000121{
cristy4c08aed2011-07-01 19:47:50 +0000122 void* pixel_metacontent = GetCacheViewAuthenticMetacontent( _view );
cristy3ed852e2009-09-05 21:47:34 +0000123
cristy4c08aed2011-07-01 19:47:50 +0000124 if ( !pixel_metacontent )
cristy3ed852e2009-09-05 21:47:34 +0000125 _image.throwImageException();
126
cristy4c08aed2011-07-01 19:47:50 +0000127 return pixel_metacontent;
cristy3ed852e2009-09-05 21:47:34 +0000128}
cristy4c08aed2011-07-01 19:47:50 +0000129*/