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 #include <kApi/Data/kPixelFormat.h>
16 
56 //typedef kObject kImage; --forward-declared in kApiDef.x.h
57 
69 kFx(kStatus) kImage_Construct(kImage* image, kType pixelType, kSize width, kSize height, kAlloc allocator);
70 
71 #if defined(K_CPP)
72 
85 kInlineFx(kStatus) kImage_ConstructEx(kImage* image, kType pixelType, kSize width, kSize height, kAlloc allocator, kAlloc valueAllocator, kMemoryAlignment valueAlignment = kALIGN_ANY)
86 {
87  return kImage_ConstructEx(image, pixelType, kPIXEL_FORMAT_NULL, width, height, allocator, valueAllocator, valueAlignment);
88 }
89 
103 kInlineFx(kStatus) kImage_ConstructEx(kImage* image, kPixelFormat format, kSize width, kSize height, kAlloc allocator, kAlloc valueAllocator = kNULL, kMemoryAlignment valueAlignment = kALIGN_ANY)
104 {
105  return kImage_ConstructEx(image, kTypeOf(kVoid), format, width, height, allocator, valueAllocator, valueAlignment);
106 }
107 #endif
108 
120 kFx(kStatus) kImage_Import(kImage* image, const kChar* fileName, kAlloc allocator);
121 
132 kFx(kStatus) kImage_Export(kImage image, const kChar* fileName);
133 
144 kFx(kStatus) kImage_Allocate(kImage image, kType pixelType, kSize width, kSize height);
145 
160 kFx(kStatus) kImage_Attach(kImage image, void* pixels, kType pixelType, kSize width, kSize height, kSize stride);
161 
179 #define kImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride) \
180  xkImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride, sizeof(*(TPtr_pixels)))
181 
191 {
192  return xkImage_Assign(image, source, kNULL);
193 }
194 
204 #if defined (K_CPP)
206 {
207  return xkImage_Assign(image, source, context);
208 }
209 #endif
210 
218 kFx(kStatus) kImage_Zero(kImage image);
219 
228 {
229  kObj(kImage, image);
230 
231  return obj->format;
232 }
233 
242 {
243  kObj(kImage, image);
244 
245  return obj->pixels;
246 }
247 
259 #define kImage_DataT(kImage_image, T) \
260  kCast(T*, xkImage_DataT(kImage_image, sizeof(T)))
261 
274 {
275  kObj(kImage, image);
276  kSSize byteOffset = y*(kSSize)obj->stride + x*(kSSize)obj->pixelSize;
277 
278  return kPointer_ByteOffset(obj->pixels, byteOffset);
279 }
280 
296 #define kImage_DataAtT(kImage_image, kSSize_x, kSSize_y, T) \
297  kCast(T*, xkImage_DataAtT(kImage_image, kSSize_x, kSSize_y, sizeof(T)))
298 
307 {
308  kObj(kImage, image);
309 
310  return obj->height * obj->stride;
311 }
312 
325 kInlineFx(void*) kImage_At(kImage image, kSize x, kSize y)
326 {
327 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
328  {
329  kAssert(x < kImage_Width(image));
330  kAssert(y < kImage_Height(image));
331  }
332 # endif
333 
334  return kImage_DataAt(image, (kSSize)x, (kSSize)y);
335 }
336 
351 #define kImage_AtT(kImage_image, kSize_x, kSize_y, T) \
352  kCast(T*, xkImage_AtT(kImage_image, kSize_x, kSize_y, sizeof(T)))
353 
366 {
367 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
368  {
369  kAssert(y < kImage_Height(image));
370  }
371 # endif
372 
373  return kImage_DataAt(image, (kSSize)0, (kSSize)y);
374 }
375 
389 #define kImage_RowAtT(kImage_image, kSize_y, T) \
390  kCast(T*, xkImage_RowAtT(kImage_image, kSize_y, sizeof(T)))
391 
400 {
401  kObj(kImage, image);
402 
403  return obj->width;
404 }
405 
414 {
415  kObj(kImage, image);
416 
417  return obj->height;
418 }
419 
428 {
429  kObj(kImage, image);
430 
431  return obj->stride;
432 }
433 
442 {
443  kObj(kImage, image);
444 
445  return obj->dataAlloc;
446 }
447 
448 #endif
kStatus kImage_Assign(kImage image, kImage source)
Copies a given source image into this image.
Definition: kImage.h:190
void * kImage_RowAt(kImage image, kSize y)
Returns a pointer to the specified row in the pixel buffer.
Definition: kImage.h:365
kPixelFormat kImage_PixelFormat(kImage image)
Gets the optional pixel format descriptor associated with this image.
Definition: kImage.h:227
void * kImage_Data(kImage image)
Returns a pointer to the first row in the pixel buffer.
Definition: kImage.h:241
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 by pixel type (legacy method).
#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:273
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:441
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:306
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:325
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.
#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:3427
Declares the kPixelFormat class.
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
#define kTypeOf(SYMBOL)
Returns the kType object associated with the specified class, interface, or value symbol...
Definition: kApiDef.h:2522
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 (legacy method) using a separate allocator for image array m...
Definition: kImage.h:85
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:399
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.
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:413
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:427