LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
GpuBuffer2D.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008 - 2012 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
35 namespace lsst {
36 namespace afw {
37 namespace gpu {
38 namespace detail {
39 
53 template <typename PixelT>
55 {
56 public:
58 
60  int width;
61  int height;
62 
63  GpuBuffer2D() : img(NULL) {}
64 
65  //copying is not allowed except for uninitialized image buffers
67  assert(x.img == NULL);
68  img = NULL;
69  };
70 
71  void Init(const ImageT& image)
72  {
73  assert(img == NULL);
74  this->width = image.getWidth();
75  this->height = image.getHeight();
76  try {
77  img = new PixelT [width*height];
78  } catch(...) {
79  throw LSST_EXCEPT(pexExcept::MemoryError, "GpuBuffer2D:Init - not enough memory");
80  }
81 
82  //copy input image data to buffer
83  for (int i = 0; i < height; ++i) {
84  typename ImageT::x_iterator inPtr = image.x_at(0, i);
85  PixelT* imageDataPtr = img + i * width;
86 
87  for (typename ImageT::x_iterator cnvEnd = inPtr + width; inPtr != cnvEnd;
88  ++inPtr, ++imageDataPtr) {
89  *imageDataPtr = *inPtr;
90  }
91  }
92  }
93 
94  void Init(int width, int height) {
95  assert(img == NULL);
96  this->width = width;
97  this->height = height;
98  try {
99  img = new PixelT [width*height];
100  } catch(...) {
101  throw LSST_EXCEPT(pexExcept::MemoryError, "GpuBuffer2D:Init - not enough memory");
102  }
103  }
104 
106  img = NULL;
107  Init(image);
108  }
109 
111  img = NULL;
112  Init(width, height);
113  }
114 
116  delete[] img;
117  }
118 
119  int Size() const {
120  return width * height;
121  }
122 
124  assert(img != NULL);
125  assert(y >= 0 && y < height);
126  return &img[width*y];
127  }
128  const PixelT* GetImgLinePtr(int y) const {
129  assert(img != NULL);
130  assert(y >= 0 && y < height);
131  return &img[width*y];
132  }
133  PixelT& Pixel(int x, int y) {
134  assert(img != NULL);
135  assert(x >= 0 && x < width);
136  assert(y >= 0 && y < height);
137  return img[x+ y*width];
138  }
139  const PixelT& Pixel(int x, int y) const {
140  assert(img != NULL);
141  assert(x >= 0 && x < width);
142  assert(y >= 0 && y < height);
143  return img[x+ y*width];
144  }
145 
146  void CopyFromBuffer(const GpuBuffer2D<PixelT>& buffer, int startX, int startY)
147  {
148  assert(img != NULL);
149  for (int i = 0; i < height; ++i) {
150  PixelT* inPtr = startX + buffer.GetImgLinePtr(i + startY);
151  PixelT* outPtr = buffer.GetImgLinePtr(i);
152  for (int j = 0; j < width; j++) {
153  *outPtr = *inPtr;
154  inPtr++;
155  outPtr++;
156  }
157  }
158  }
159 
160  void CopyToImage(ImageT outImage, int startX, int startY)
161  {
162  assert(img != NULL);
163  for (int i = 0; i < height; ++i) {
164  PixelT* outPtrImg = &img[width*i];
165 
166  for (typename ImageT::x_iterator cnvPtr = outImage.x_at(startX, i + startY),
167  cnvEnd = cnvPtr + width; cnvPtr != cnvEnd; ++cnvPtr ) {
168  *cnvPtr = *outPtrImg;
169  ++outPtrImg;
170  }
171  }
172  }
173 
174 };
175 
176 }
177 }
178 }
179 } //namespace lsst::afw::math::detail ends
180 
int y
void CopyToImage(ImageT outImage, int startX, int startY)
Definition: GpuBuffer2D.h:160
Class for representing an image or 2D array in general)
Definition: GpuBuffer2D.h:54
lsst::afw::image::Image< PixelT > ImageT
Definition: GpuBuffer2D.h:57
GpuBuffer2D(int width, int height)
Definition: GpuBuffer2D.h:110
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
const PixelT * GetImgLinePtr(int y) const
Definition: GpuBuffer2D.h:128
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:237
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
Definition: Image.h:329
void Init(int width, int height)
Definition: GpuBuffer2D.h:94
int x
GpuBuffer2D(const ImageT &image)
Definition: GpuBuffer2D.h:105
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
const PixelT & Pixel(int x, int y) const
Definition: GpuBuffer2D.h:139
void CopyFromBuffer(const GpuBuffer2D< PixelT > &buffer, int startX, int startY)
Definition: GpuBuffer2D.h:146
GpuBuffer2D(const GpuBuffer2D &x)
Definition: GpuBuffer2D.h:66
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: Image.h:151
void Init(const ImageT &image)
Definition: GpuBuffer2D.h:71
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
PixelT & Pixel(int x, int y)
Definition: GpuBuffer2D.h:133