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 
55 //typedef kObject kImage; --forward-declared in kApiDef.x.h
56 
68 kFx(kStatus) kImage_Construct(kImage* image, kType pixelType, kSize width, kSize height, kAlloc allocator);
69 
81 kFx(kStatus) kImage_Import(kImage* image, const kChar* fileName, kAlloc allocator);
82 
93 kFx(kStatus) kImage_Export(kImage image, const kChar* fileName);
94 
105 kFx(kStatus) kImage_Allocate(kImage image, kType pixelType, kSize width, kSize height);
106 
121 kFx(kStatus) kImage_Attach(kImage image, void* pixels, kType pixelType, kSize width, kSize height, kSize stride);
122 
140 #define kImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride) \
141  xkImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride, sizeof(*TPtr_pixels))
142 
151 kFx(kStatus) kImage_Assign(kImage image, kImage source);
152 
160 kFx(kStatus) kImage_Zero(kImage image);
161 
171 {
172  kObj(kImage, image);
173 
174  obj->format = format;
175 
176  return kOK;
177 }
178 
187 {
188  kObj(kImage, image);
189 
190  return obj->format;
191 }
192 
202 {
203  kObj(kImage, image);
204 
205  obj->cfa = cfa;
206 
207  return kOK;
208 }
209 
218 {
219  kObj(kImage, image);
220 
221  return obj->cfa;
222 }
223 
237 kFx(kStatus) kImage_SetPixel(kImage image, kSize x, kSize y, const void* pixel);
238 
255 #define kImage_SetPixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel) \
256  xkImage_SetPixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel, sizeof(*TPtr_pixel))
257 
271 kFx(kStatus) kImage_Pixel(kImage image, kSize x, kSize y, void* pixel);
272 
289 #define kImage_PixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel) \
290  xkImage_PixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel, sizeof(*TPtr_pixel))
291 
307 #define kImage_SetAsT(kImage_image, kSize_x, kSize_y, T_value, T) \
308  (kPointer_WriteAs(xkImage_AsT(kImage_image, kSize_x, kSize_y, sizeof(T)), T_value, T), (void)0)
309 
324 #define kImage_AsT(kImage_image, kSize_x, kSize_y, T) \
325  kPointer_ReadAs(xkImage_AsT(kImage_image, kSize_x, kSize_y, sizeof(T)), T)
326 
335 {
336  kObj(kImage, image);
337 
338  return obj->pixels;
339 }
340 
352 #define kImage_DataT(kImage_image, T) \
353  kCast(T*, xkImage_DataT(kImage_image, sizeof(T)))
354 
367 {
368  kObj(kImage, image);
369  kSSize byteOffset = y*(kSSize)obj->stride + x*(kSSize)obj->pixelSize;
370 
371  return kPointer_ByteOffset(obj->pixels, byteOffset);
372 }
373 
389 #define kImage_DataAtT(kImage_image, kSSize_x, kSSize_y, T) \
390  kCast(T*, xkImage_DataAtT(kImage_image, kSSize_x, kSSize_y, sizeof(T)))
391 
400 {
401  kObj(kImage, image);
402 
403  return obj->height * obj->stride;
404 }
405 
418 kInlineFx(void*) kImage_At(kImage image, kSize x, kSize y)
419 {
420 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
421  {
422  kAssert(x < kImage_Width(image));
423  kAssert(y < kImage_Height(image));
424  }
425 # endif
426 
427  return kImage_DataAt(image, x, y);
428 }
429 
444 #define kImage_AtT(kImage_image, kSize_x, kSize_y, T) \
445  kCast(T*, xkImage_AtT(kImage_image, kSize_x, kSize_y, sizeof(T)))
446 
459 {
460 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
461  {
462  kAssert(y < kImage_Height(image));
463  }
464 # endif
465 
466  return kImage_DataAt(image, 0, y);
467 }
468 
482 #define kImage_RowAtT(kImage_image, kSize_y, T) \
483  kCast(T*, xkImage_RowAtT(kImage_image, kSize_y, sizeof(T)))
484 
493 {
494  kObj(kImage, image);
495 
496  return obj->pixelType;
497 }
498 
507 {
508  kObj(kImage, image);
509 
510  return obj->pixelSize;
511 }
512 
521 {
522  kObj(kImage, image);
523 
524  return obj->width;
525 }
526 
535 {
536  kObj(kImage, image);
537 
538  return obj->height;
539 }
540 
551 {
552  kObj(kImage, image);
553 
554  return obj->width * obj->height;
555 }
556 
565 {
566  kObj(kImage, image);
567 
568  return obj->stride;
569 }
570 
571 #endif
kStatus kImage_Assign(kImage image, kImage source)
Copies a given source image into this image.
kStatus kImage_SetPixel(kImage image, kSize x, kSize y, const void *pixel)
Sets the value of a pixel.
kStatus kImage_Pixel(kImage image, kSize x, kSize y, void *pixel)
Gets the value of a pixel.
void * kImage_RowAt(kImage image, kSize y)
Returns a pointer to the specified row in the pixel buffer.
Definition: kImage.h:458
kPixelFormat kImage_PixelFormat(kImage image)
Gets the optional pixel format descriptor associated with this image.
Definition: kImage.h:186
void * kImage_Data(kImage image)
Returns a pointer to the first row in the pixel buffer.
Definition: kImage.h:334
kSize kImage_Area(kImage image)
Returns the area of the image, in pixels.
Definition: kImage.h:550
kSize kImage_PixelSize(kImage image)
Returns the pixel size.
Definition: kImage.h:506
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:26
void * kImage_DataAt(kImage image, kSSize x, kSSize y)
Calculates an address relative to the start of the pixel buffer.
Definition: kImage.h:366
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.
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:399
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:418
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:201
#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:2858
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:278
kType kImage_PixelType(kImage image)
Returns the pixel type.
Definition: kImage.h:492
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:520
Represents metadata about a type (class, interface, or value).
#define kAssert(EXPRESSION)
Aborts execution if EXPRESSION is kFALSE.
Definition: kApiDef.h:749
Represents a 2D collection of pixels.
#define kOK
Operation successful.
Definition: kApiDef.h:513
kCfa kImage_Cfa(kImage image)
Gets the color filter array type associated with this image.
Definition: kImage.h:217
Represents an error code.
kSize kImage_Height(kImage image)
Returns the height of the image, in pixels.
Definition: kImage.h:534
Image color filter array type.
kStatus kImage_Zero(kImage image)
Sets all pixel bits to zero.
kStatus kImage_SetPixelFormat(kImage image, kPixelFormat format)
Sets the optional pixel format descriptor associated with this image.
Definition: kImage.h:170
kSize kImage_Stride(kImage image)
Returns the size of an image row, including alignment padding bytes, in bytes.
Definition: kImage.h:564