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 
57 //typedef kObject kImage; --forward-declared in kApiDef.x.h
58 
70 kFx(kStatus) kImage_Construct(kImage* image, kType pixelType, kSize width, kSize height, kAlloc allocator);
71 
72 #if defined(K_CPP)
73 
86 kFx(kStatus) kImage_ConstructEx(kImage* image, kType pixelType, kSize width, kSize height, kAlloc allocator, kAlloc valueAllocator, kMemoryAlignment valueAlignment = kALIGN_ANY);
87 #endif
88 
100 kFx(kStatus) kImage_Import(kImage* image, const kChar* fileName, kAlloc allocator);
101 
112 kFx(kStatus) kImage_Export(kImage image, const kChar* fileName);
113 
124 kFx(kStatus) kImage_Allocate(kImage image, kType pixelType, kSize width, kSize height);
125 
140 kFx(kStatus) kImage_Attach(kImage image, void* pixels, kType pixelType, kSize width, kSize height, kSize stride);
141 
159 #define kImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride) \
160  xkImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride, sizeof(*(TPtr_pixels)))
161 
171 {
172  return xkImage_Assign(image, source, kNULL);
173 }
174 
184 #if defined (K_CPP)
186 {
187  return xkImage_Assign(image, source, context);
188 }
189 #endif
190 
198 kFx(kStatus) kImage_Zero(kImage image);
199 
209 {
210  kObj(kImage, image);
211 
212  obj->format = format;
213 
214  return kOK;
215 }
216 
225 {
226  kObj(kImage, image);
227 
228  return obj->format;
229 }
230 
240 {
241  kObj(kImage, image);
242 
243  obj->cfa = cfa;
244 
245  return kOK;
246 }
247 
256 {
257  kObj(kImage, image);
258 
259  return obj->cfa;
260 }
261 
275 kFx(kStatus) kImage_SetPixel(kImage image, kSize x, kSize y, const void* pixel);
276 
293 #define kImage_SetPixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel) \
294  xkImage_SetPixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel, sizeof(*(TPtr_pixel)))
295 
309 kFx(kStatus) kImage_Pixel(kImage image, kSize x, kSize y, void* pixel);
310 
327 #define kImage_PixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel) \
328  xkImage_PixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel, sizeof(*(TPtr_pixel)))
329 
345 #define kImage_SetAsT(kImage_image, kSize_x, kSize_y, T_value, T) \
346  (kPointer_WriteAs(xkImage_AsT(kImage_image, kSize_x, kSize_y, sizeof(T)), T_value, T), (void)0)
347 
362 #define kImage_AsT(kImage_image, kSize_x, kSize_y, T) \
363  kPointer_ReadAs(xkImage_AsT(kImage_image, kSize_x, kSize_y, sizeof(T)), T)
364 
373 {
374  kObj(kImage, image);
375 
376  return obj->pixels;
377 }
378 
390 #define kImage_DataT(kImage_image, T) \
391  kCast(T*, xkImage_DataT(kImage_image, sizeof(T)))
392 
405 {
406  kObj(kImage, image);
407  kSSize byteOffset = y*(kSSize)obj->stride + x*(kSSize)obj->pixelSize;
408 
409  return kPointer_ByteOffset(obj->pixels, byteOffset);
410 }
411 
427 #define kImage_DataAtT(kImage_image, kSSize_x, kSSize_y, T) \
428  kCast(T*, xkImage_DataAtT(kImage_image, kSSize_x, kSSize_y, sizeof(T)))
429 
438 {
439  kObj(kImage, image);
440 
441  return obj->height * obj->stride;
442 }
443 
456 kInlineFx(void*) kImage_At(kImage image, kSize x, kSize y)
457 {
458 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
459  {
460  kAssert(x < kImage_Width(image));
461  kAssert(y < kImage_Height(image));
462  }
463 # endif
464 
465  return kImage_DataAt(image, (kSSize)x, (kSSize)y);
466 }
467 
482 #define kImage_AtT(kImage_image, kSize_x, kSize_y, T) \
483  kCast(T*, xkImage_AtT(kImage_image, kSize_x, kSize_y, sizeof(T)))
484 
497 {
498 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
499  {
500  kAssert(y < kImage_Height(image));
501  }
502 # endif
503 
504  return kImage_DataAt(image, (kSSize)0, (kSSize)y);
505 }
506 
520 #define kImage_RowAtT(kImage_image, kSize_y, T) \
521  kCast(T*, xkImage_RowAtT(kImage_image, kSize_y, sizeof(T)))
522 
531 {
532  kObj(kImage, image);
533 
534  return obj->pixelType;
535 }
536 
545 {
546  kObj(kImage, image);
547 
548  return obj->pixelSize;
549 }
550 
559 {
560  kObj(kImage, image);
561 
562  return obj->width;
563 }
564 
573 {
574  kObj(kImage, image);
575 
576  return obj->height;
577 }
578 
589 {
590  kObj(kImage, image);
591 
592  return obj->width * obj->height;
593 }
594 
603 {
604  kObj(kImage, image);
605 
606  return obj->stride;
607 }
608 
617 {
618  kObj(kImage, image);
619 
620  return obj->dataAlloc;
621 }
622 
623 #endif
kStatus kImage_Assign(kImage image, kImage source)
Copies a given source image into this image.
Definition: kImage.h:170
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:496
kPixelFormat kImage_PixelFormat(kImage image)
Gets the optional pixel format descriptor associated with this image.
Definition: kImage.h:224
void * kImage_Data(kImage image)
Returns a pointer to the first row in the pixel buffer.
Definition: kImage.h:372
kSize kImage_Area(kImage image)
Returns the area of the image, in pixels.
Definition: kImage.h:588
kSize kImage_PixelSize(kImage image)
Returns the pixel size.
Definition: kImage.h:544
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:404
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:616
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:437
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:456
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:239
#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:3383
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:280
kType kImage_PixelType(kImage image)
Returns the pixel type.
Definition: kImage.h:530
kStatus kImage_ConstructEx(kImage *image, kType pixelType, kSize width, kSize height, kAlloc allocator, kAlloc valueAllocator, kMemoryAlignment valueAlignment=kALIGN_ANY)
Constructs a kImage object using a separate allocator for image array memory.
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:558
Represents metadata about a type (class, interface, or value).
#define kAssert(EXPRESSION)
Aborts execution if EXPRESSION is kFALSE.
Definition: kApiDef.h:751
Represents a 2D collection of pixels.
Root of all Zen classes.
#define kOK
Operation successful.
Definition: kApiDef.h:515
kCfa kImage_Cfa(kImage image)
Gets the color filter array type associated with this image.
Definition: kImage.h:255
Represents an error code.
#define kNULL
Null pointer.
Definition: kApiDef.h:269
kSize kImage_Height(kImage image)
Returns the height of the image, in pixels.
Definition: kImage.h:572
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:208
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:602