File: Pixels.cpp

package info (click to toggle)
imagemagick 6:6.0.6.2-2.9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 33,284 kB
  • ctags: 14,844
  • sloc: ansic: 190,790; cpp: 17,203; sh: 8,740; perl: 4,190; makefile: 1,740; tcl: 459
file content (125 lines) | stat: -rw-r--r-- 2,989 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// This may look like C code, but it is really -*- C++ -*-
//
// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
//
// Pixels Implementation
//

#define MAGICK_IMPLEMENTATION

#include "Magick++/Include.h"
#include <string> // This is here to compile with Visual C++
#include "Magick++/Thread.h"
#include "Magick++/Exception.h"
#include "Magick++/Pixels.h"

namespace Magick
{


}

// Construct pixel view using specified image.
Magick::Pixels::Pixels( Magick::Image &image_ )
  : _image(image_),
    _view(OpenCacheView(_image.image())),
    _x(0),
    _y(0),
    _columns(0),
    _rows(0)
{
  if (!_view)
    _image.throwImageException();
}

// Destroy pixel view
Magick::Pixels::~Pixels( void )
{
  if ( _view )
    CloseCacheView( _view );
}

// Transfer pixels from the image to the pixel view as defined by
// the specified region. Modified pixels may be subsequently
// transferred back to the image via sync.
Magick::PixelPacket* Magick::Pixels::get ( const int x_,
					   const int y_,
					   const unsigned int columns_,
					   const unsigned int rows_ )
{
  _x = x_;
  _y = y_;
  _columns = columns_;
  _rows = rows_;

  PixelPacket* pixels = GetCacheView( _view, x_, y_, columns_, rows_ );

  if ( !pixels )
    _image.throwImageException();
  
  return pixels;
}

// Transfer read-only pixels from the image to the pixel view as
// defined by the specified region.
const Magick::PixelPacket* Magick::Pixels::getConst ( const int x_, const int y_,
                                                      const unsigned int columns_,
                                                      const unsigned int rows_ )
{
  _x = x_;
  _y = y_;
  _columns = columns_;
  _rows = rows_;

  ExceptionInfo exception;
  GetExceptionInfo( &exception );

  const PixelPacket* pixels =
    AcquireCacheView(_view, x_, y_, columns_, rows_, &exception );

  if ( !pixels )
    throwException( exception );

  DestroyExceptionInfo( &exception );

    return pixels;
}

// Transfers the image view pixels to the image.
void Magick::Pixels::sync ( void )
{
  if( !SyncCacheView( _view ) )
    _image.throwImageException();
}
    
// Allocate a pixel view region to store image pixels as defined
// by the region rectangle.  This area is subsequently transferred
// from the pixel view to the image via 'sync'.
Magick::PixelPacket* Magick::Pixels::set ( const int x_,
					   const int y_,
					   const unsigned int columns_,
					   const unsigned int rows_ )
{
  _x = x_;
  _y = y_;
  _columns = columns_;
  _rows = rows_;

  PixelPacket* pixels = SetCacheView( _view, static_cast<long>(x_), static_cast<long>(y_),
                                      columns_, rows_ );
  if ( !pixels )
    _image.throwImageException();
  
  return pixels;
}

// Return pixel colormap index array
Magick::IndexPacket* Magick::Pixels::indexes ( void )
{
  IndexPacket* pixel_indexes = GetCacheViewIndexes( _view );

  if ( !pixel_indexes )
    _image.throwImageException();

  return pixel_indexes;
}