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 
84 kFx(kStatus) kImage_ConstructEx(kImage* image, kType pixelType, kSize width, kSize height, kAlloc allocator, kAlloc valueAllocator);
85 
97 kFx(kStatus) kImage_Import(kImage* image, const kChar* fileName, kAlloc allocator);
98 
109 kFx(kStatus) kImage_Export(kImage image, const kChar* fileName);
110 
121 kFx(kStatus) kImage_Allocate(kImage image, kType pixelType, kSize width, kSize height);
122 
137 kFx(kStatus) kImage_Attach(kImage image, void* pixels, kType pixelType, kSize width, kSize height, kSize stride);
138 
156 #define kImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride) \
157  xkImage_AttachT(kImage_image, TPtr_pixels, kType_pixelType, kSize_width, kSize_height, kSize_stride, sizeof(*(TPtr_pixels)))
158 
168 {
169  return xkImage_Assign(image, source, kNULL);
170 }
171 
181 #if defined (K_CPP)
183 {
184  return xkImage_Assign(image, source, context);
185 }
186 #endif
187 
195 kFx(kStatus) kImage_Zero(kImage image);
196 
206 {
207  kObj(kImage, image);
208 
209  obj->format = format;
210 
211  return kOK;
212 }
213 
222 {
223  kObj(kImage, image);
224 
225  return obj->format;
226 }
227 
237 {
238  kObj(kImage, image);
239 
240  obj->cfa = cfa;
241 
242  return kOK;
243 }
244 
253 {
254  kObj(kImage, image);
255 
256  return obj->cfa;
257 }
258 
272 kFx(kStatus) kImage_SetPixel(kImage image, kSize x, kSize y, const void* pixel);
273 
290 #define kImage_SetPixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel) \
291  xkImage_SetPixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel, sizeof(*(TPtr_pixel)))
292 
306 kFx(kStatus) kImage_Pixel(kImage image, kSize x, kSize y, void* pixel);
307 
324 #define kImage_PixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel) \
325  xkImage_PixelT(kImage_image, kSize_x, kSize_y, TPtr_pixel, sizeof(*(TPtr_pixel)))
326 
342 #define kImage_SetAsT(kImage_image, kSize_x, kSize_y, T_value, T) \
343  (kPointer_WriteAs(xkImage_AsT(kImage_image, kSize_x, kSize_y, sizeof(T)), T_value, T), (void)0)
344 
359 #define kImage_AsT(kImage_image, kSize_x, kSize_y, T) \
360  kPointer_ReadAs(xkImage_AsT(kImage_image, kSize_x, kSize_y, sizeof(T)), T)
361 
370 {
371  kObj(kImage, image);
372 
373  return obj->pixels;
374 }
375 
387 #define kImage_DataT(kImage_image, T) \
388  kCast(T*, xkImage_DataT(kImage_image, sizeof(T)))
389 
402 {
403  kObj(kImage, image);
404  kSSize byteOffset = y*(kSSize)obj->stride + x*(kSSize)obj->pixelSize;
405 
406  return kPointer_ByteOffset(obj->pixels, byteOffset);
407 }
408 
424 #define kImage_DataAtT(kImage_image, kSSize_x, kSSize_y, T) \
425  kCast(T*, xkImage_DataAtT(kImage_image, kSSize_x, kSSize_y, sizeof(T)))
426 
435 {
436  kObj(kImage, image);
437 
438  return obj->height * obj->stride;
439 }
440 
453 kInlineFx(void*) kImage_At(kImage image, kSize x, kSize y)
454 {
455 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
456  {
457  kAssert(x < kImage_Width(image));
458  kAssert(y < kImage_Height(image));
459  }
460 # endif
461 
462  return kImage_DataAt(image, (kSSize)x, (kSSize)y);
463 }
464 
479 #define kImage_AtT(kImage_image, kSize_x, kSize_y, T) \
480  kCast(T*, xkImage_AtT(kImage_image, kSize_x, kSize_y, sizeof(T)))
481 
494 {
495 # if !defined(K_FSS_912_DISABLE_BOUNDS_CHECK)
496  {
497  kAssert(y < kImage_Height(image));
498  }
499 # endif
500 
501  return kImage_DataAt(image, (kSSize)0, (kSSize)y);
502 }
503 
517 #define kImage_RowAtT(kImage_image, kSize_y, T) \
518  kCast(T*, xkImage_RowAtT(kImage_image, kSize_y, sizeof(T)))
519 
528 {
529  kObj(kImage, image);
530 
531  return obj->pixelType;
532 }
533 
542 {
543  kObj(kImage, image);
544 
545  return obj->pixelSize;
546 }
547 
556 {
557  kObj(kImage, image);
558 
559  return obj->width;
560 }
561 
570 {
571  kObj(kImage, image);
572 
573  return obj->height;
574 }
575 
586 {
587  kObj(kImage, image);
588 
589  return obj->width * obj->height;
590 }
591 
600 {
601  kObj(kImage, image);
602 
603  return obj->stride;
604 }
605 
614 {
615  kObj(kImage, image);
616 
617  return obj->dataAlloc;
618 }
619 
620 #endif
kStatus kImage_Assign(kImage image, kImage source)
Copies a given source image into this image.
Definition: kImage.h:167
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:493
kPixelFormat kImage_PixelFormat(kImage image)
Gets the optional pixel format descriptor associated with this image.
Definition: kImage.h:221
void * kImage_Data(kImage image)
Returns a pointer to the first row in the pixel buffer.
Definition: kImage.h:369
kStatus kImage_ConstructEx(kImage *image, kType pixelType, kSize width, kSize height, kAlloc allocator, kAlloc valueAllocator)
Constructs a kImage object using a separate allocator for image array memory.
kSize kImage_Area(kImage image)
Returns the area of the image, in pixels.
Definition: kImage.h:585
kSize kImage_PixelSize(kImage image)
Returns the pixel size.
Definition: kImage.h:541
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:401
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:613
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:434
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:453
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:236
#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:3103
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:527
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:555
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:252
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:569
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:205
kSize kImage_Stride(kImage image)
Returns the size of an image row, including alignment padding bytes, in bytes.
Definition: kImage.h:599