Zen API
 All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kImage.h
Go to the documentation of this file.
1 
10 #ifndef K_API_IMAGE_H
11 #define K_API_IMAGE_H
12 
13 #include <kApi/kApiDef.h>
14 #include <kApi/Data/kImage.x.h>
15 
58 //typedef kObject kImage; --forward-declared in kApiDef.x.h
59 
71 kFx(kStatus) kImage_Construct(kImage* image, kType pixelType, kSize width, kSize height, kAlloc allocator);
72 
73 #if defined(K_CPP)
74 
87 kInlineFx(kStatus) kImage_ConstructEx(kImage* image, kType pixelType, kSize width, kSize height, kAlloc allocator, kAlloc valueAllocator, kMemoryAlignment valueAlignment = kALIGN_ANY)
88 {
89  return kImage_ConstructEx(image, pixelType, kPIXEL_FORMAT_NULL, width, height, allocator, valueAllocator, valueAlignment);
90 }
91 
105 kInlineFx(kStatus) kImage_ConstructEx(kImage* image, kPixelFormat format, kSize width, kSize height, kAlloc allocator, kAlloc valueAllocator = kNULL, kMemoryAlignment valueAlignment = kALIGN_ANY)
106 {
107  return kImage_ConstructEx(image, kTypeOf(kVoid), format, width, height, allocator, valueAllocator, valueAlignment);
108 }
109 #endif
110 
122 kFx(kStatus) kImage_Import(kImage* image, const kChar* fileName, kAlloc allocator);
123 
134 kFx(kStatus) kImage_Export(kImage image, const kChar* fileName);
135 
146 kFx(kStatus) kImage_Allocate(kImage image, kType pixelType, kSize width, kSize height);
147 
162 kFx(kStatus) kImage_Attach(kImage image, void* pixels, kType pixelType, kSize width, kSize height, kSize stride);
163 
181 #define kImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride) \
182  xkImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride, sizeof(*(TPtr_pixels)))
183 
193 {
194  return xkImage_Assign(image, source, kNULL);
195 }
196 
206 #if defined (K_CPP)
208 {
209  return xkImage_Assign(image, source, context);
210 }
211 #endif
212 
220 kFx(kStatus) kImage_Zero(kImage image);
221 
230 {
231  kObj(kImage, image);
232 
233  return obj->format;
234 }
235 
245 {
246  kObj(kImage, image);
247 
248  obj->cfa = cfa;
249 
250  return kOK;
251 }
252 
261 {
262  kObj(kImage, image);
263 
264  return obj->cfa;
265 }
266 
275 {
276  kObj(kImage, image);
277 
278  return obj->pixels;
279 }
280 
292 #define kImage_DataT(kImage_image, T) \
293  kCast(T*, xkImage_DataT(kImage_image, sizeof(T)))
294 
307 {
308  kObj(kImage, image);
309  kSSize byteOffset = y*(kSSize)obj->stride + x*(kSSize)obj->pixelSize;
310 
311  return kPointer_ByteOffset(obj->pixels, byteOffset);
312 }
313 
329 #define kImage_DataAtT(kImage_image, kSSize_x, kSSize_y, T) \
330  kCast(T*, xkImage_DataAtT(kImage_image, kSSize_x, kSSize_y, sizeof(T)))
331 
340 {
341  kObj(kImage, image);
342 
343  return obj->height * obj->stride;
344 }
345 
358 kInlineFx(void*) kImage_At(kImage image, kSize x, kSize y)
359 {
360 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
361  {
362  kAssert(x < kImage_Width(image));
363  kAssert(y < kImage_Height(image));
364  }
365 # endif
366 
367  return kImage_DataAt(image, (kSSize)x, (kSSize)y);
368 }
369 
384 #define kImage_AtT(kImage_image, kSize_x, kSize_y, T) \
385  kCast(T*, xkImage_AtT(kImage_image, kSize_x, kSize_y, sizeof(T)))
386 
399 {
400 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
401  {
402  kAssert(y < kImage_Height(image));
403  }
404 # endif
405 
406  return kImage_DataAt(image, (kSSize)0, (kSSize)y);
407 }
408 
422 #define kImage_RowAtT(kImage_image, kSize_y, T) \
423  kCast(T*, xkImage_RowAtT(kImage_image, kSize_y, sizeof(T)))
424 
433 {
434  kObj(kImage, image);
435 
436  return obj->pixelType;
437 }
438 
447 {
448  kObj(kImage, image);
449 
450  return obj->pixelSize;
451 }
452 
461 {
462  kObj(kImage, image);
463 
464  return obj->width;
465 }
466 
475 {
476  kObj(kImage, image);
477 
478  return obj->height;
479 }
480 
489 {
490  kObj(kImage, image);
491 
492  return obj->stride;
493 }
494 
503 {
504  kObj(kImage, image);
505 
506  return obj->dataAlloc;
507 }
508 
509 #endif
kStatus kImage_Assign(kImage image, kImage source)
Copies a given source image into this image.
Definition: kImage.h:192
void * kImage_RowAt(kImage image, kSize y)
Returns a pointer to the specified row in the pixel buffer.
Definition: kImage.h:398
kPixelFormat kImage_PixelFormat(kImage image)
Gets the optional pixel format descriptor associated with this image.
Definition: kImage.h:229
void * kImage_Data(kImage image)
Returns a pointer to the first row in the pixel buffer.
Definition: kImage.h:274
#define kPIXEL_FORMAT_NULL
Unknown pixel format.
Definition: kApiDef.h:1649
kSize kImage_PixelSize(kImage image)
Returns the pixel size.
Definition: kImage.h:446
Represents an unsigned integer that can store a pointer address.
Abstract base class for memory allocator types.
kStatus kImage_Construct(kImage *image, kType pixelType, kSize width, kSize height, kAlloc allocator)
Constructs a kImage object.
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:29
void * kImage_DataAt(kImage image, kSSize x, kSSize y)
Calculates an address relative to the start of the pixel buffer.
Definition: kImage.h:306
Represents a single unit (byte) in a UTF-8 character.
kStatus kImage_Import(kImage *image, const kChar *fileName, kAlloc allocator)
Loads an image from file.
kAlloc kImage_DataAlloc(kImage image)
Reports the allocator used for the internal pixel array.
Definition: kImage.h:502
kStatus kImage_Export(kImage image, const kChar *fileName)
Saves an image to file.
kSize kImage_DataSize(kImage image)
Reports the size, in bytes, of the pixel buffer.
Definition: kImage.h:339
Represents a signed integer that can store a pointer address.
void * kImage_At(kImage image, kSize x, kSize y)
Returns a pointer to the specified pixel in the pixel buffer.
Definition: kImage.h:358
Pixel format descriptor.
kStatus kImage_Attach(kImage image, void *pixels, kType pixelType, kSize width, kSize height, kSize stride)
Attaches the image to an external pixel buffer.
kStatus kImage_SetCfa(kImage image, kCfa cfa)
Sets the color filter array type associated with this image.
Definition: kImage.h:244
#define kObj(TypeName_T, T_object)
Declares a local "obj" (this-pointer) variable and initializes it from a type-checked object handle...
Definition: kApiDef.h:3450
Core Zen type declarations.
void * kPointer_ByteOffset(const void *pointer, kSSize offset)
Calculates a pointer address from a base address and a byte offset.
Definition: kApiDef.h:322
kType kImage_PixelType(kImage image)
Returns the pixel type.
Definition: kImage.h:432
#define kTypeOf(SYMBOL)
Returns the kType object associated with the specified class, interface, or value symbol...
Definition: kApiDef.h:2545
kStatus kImage_ConstructEx(kImage *image, kType pixelType, kSize width, kSize height, kAlloc allocator, kAlloc valueAllocator, kMemoryAlignment valueAlignment=kALIGN_ANY)
Constructs a kImage object by pixel type using a separate allocator for image array memory...
Definition: kImage.h:87
kStatus kImage_Allocate(kImage image, kType pixelType, kSize width, kSize height)
Reallocates the internal pixel buffer.
kSize kImage_Width(kImage image)
Returns the width of the image, in pixels.
Definition: kImage.h:460
Represents metadata about a type (class, interface, or value).
#define kAssert(EXPRESSION)
Aborts execution if EXPRESSION is kFALSE.
Definition: kApiDef.h:779
Represents a 2D collection of pixels.
Root of all Zen classes.
#define kOK
Operation successful.
Definition: kApiDef.h:543
kCfa kImage_Cfa(kImage image)
Gets the color filter array type associated with this image.
Definition: kImage.h:260
Represents an error code.
#define kNULL
Null pointer.
Definition: kApiDef.h:311
kSize kImage_Height(kImage image)
Returns the height of the image, in pixels.
Definition: kImage.h:474
Image color filter array type.
kStatus kImage_Zero(kImage image)
Sets all pixel bits to zero.
Represents alignment options for allocations.
kSize kImage_Stride(kImage image)
Returns the size of an image row, including alignment padding bytes, in bytes.
Definition: kImage.h:488