Mon, 03 Aug 2009 16:13:27 +0100
remove pt_image (will be adding libgd soon)
Makefile | file | annotate | diff | revisions | |
src/pt_image.c | file | annotate | diff | revisions | |
src/pt_image.h | file | annotate | diff | revisions |
1.1 --- a/Makefile Mon Aug 03 14:21:23 2009 +0100 1.2 +++ b/Makefile Mon Aug 03 16:13:27 2009 +0100 1.3 @@ -103,7 +103,7 @@ 1.4 TARGET = ptouch 1.5 1.6 # source files that produce object files 1.7 -SRC = main.c hexdump.c ptouch.c pt_image.c 1.8 +SRC = main.c hexdump.c ptouch.c 1.9 1.10 # source type - either "c" or "cpp" (C or C++) 1.11 SRC_TYPE = c
2.1 --- a/src/pt_image.c Mon Aug 03 14:21:23 2009 +0100 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,130 +0,0 @@ 2.4 -#include <stdio.h> 2.5 -#include <stdlib.h> 2.6 -#include <string.h> 2.7 -#include "pt_image.h" 2.8 - 2.9 -/** 2.10 - * Create a new pt_Image object. 2.11 - * 2.12 - * Creates a new pt_Image of a specified width and height, and initialises 2.13 - * all the pixels in its buffer to zero. 2.14 - * 2.15 - * @param width The width of the image. 2.16 - * @param height The height of the image. 2.17 - * @return The new pt_Image, or NULL on failure. 2.18 - */ 2.19 -pt_Image *ptimage_Create(unsigned long width, unsigned long height) 2.20 -{ 2.21 - pt_Image *image; 2.22 - 2.23 -#ifdef DEBUG 2.24 - printf("%s[%d]: image size = %u\n", __FILE__, __LINE__, sizeof(pt_Image)); 2.25 - printf("%s[%d]: data size = %u\n", __FILE__, __LINE__, sizeof(image->data[0])); 2.26 - printf("%s[%d]: create %lu x %lu image\n", __FILE__, __LINE__, width, height); 2.27 -#endif 2.28 - 2.29 - // Allocate memory for the new image and its data buffer 2.30 - image = malloc(sizeof(pt_Image)); 2.31 - if (image == NULL) return NULL; 2.32 - 2.33 - image->data = malloc(width * height * sizeof(image->data[0])); 2.34 - if (image->data == NULL) return NULL; 2.35 - 2.36 - // Set the image's parameters 2.37 - image->width = width; 2.38 - image->height = height; 2.39 - 2.40 - // Clear the image's data buffer to "blank" 2.41 - memset(image->data, 0, width * height * sizeof(image->data[0])); 2.42 - 2.43 - return image; 2.44 -} 2.45 - 2.46 -/** 2.47 - * Free a pt_Image object. 2.48 - * 2.49 - * @param image The image object to free. 2.50 - */ 2.51 -void ptimage_Free(pt_Image *image) 2.52 -{ 2.53 - // Make sure image is non-null 2.54 - if (image == NULL) { 2.55 - return; 2.56 - } 2.57 - 2.58 - // Free the image data 2.59 - if (image->data != NULL) { 2.60 - free(image->data); 2.61 - } 2.62 - 2.63 - // Free the image 2.64 - free(image); 2.65 -} 2.66 - 2.67 -/** 2.68 - * Get the value of a pixel in a pt_Image object. 2.69 - * 2.70 - * @param image Image object. 2.71 - * @param x X position of the pixel, zero-based. 2.72 - * @param y Y position of the pixel, zero-based. 2.73 - * @return Value of the pixel, or negative on error. 2.74 - */ 2.75 -int ptimage_GetPixel(pt_Image *image, unsigned long x, unsigned long y) 2.76 -{ 2.77 - // Make sure the image is not null and that the data buffer has been 2.78 - // allocated 2.79 - if (image == NULL) { 2.80 - return -1; // TODO: make constant 2.81 - } 2.82 - 2.83 - if (image->data == NULL) { 2.84 - return -1; // TODO: make constant 2.85 - } 2.86 - 2.87 - // Range-check 2.88 - if ((x < 0) || (x > image->width)) { 2.89 - return -2; // TODO: make constant 2.90 - } 2.91 - if ((y < 0) || (y > image->height)) { 2.92 - return -3; // TODO: make constant 2.93 - } 2.94 - 2.95 - // Return the pixel value 2.96 - return image->data[(y*image->width)+x]; 2.97 -} 2.98 - 2.99 -/** 2.100 - * Set the value of a pixel in a pt_Image object. 2.101 - * 2.102 - * @param image Image object. 2.103 - * @param x X position of the pixel, zero-based. 2.104 - * @param y Y position of the pixel, zero-based. 2.105 - * @param val New value of the pixel. 2.106 - * @return Zero on success, or negative on error. 2.107 - */ 2.108 -int ptimage_SetPixel(pt_Image *image, unsigned long x, unsigned long y, unsigned char val) 2.109 -{ 2.110 - // Make sure the image is not null and that the data buffer has been 2.111 - // allocated 2.112 - if (image == NULL) { 2.113 - return -1; // TODO: make constant 2.114 - } 2.115 - 2.116 - if (image->data == NULL) { 2.117 - return -1; // TODO: make constant 2.118 - } 2.119 - 2.120 - // Range-check 2.121 - if ((x < 0) || (x > image->width)) { 2.122 - return -2; // TODO: make constant 2.123 - } 2.124 - if ((y < 0) || (y > image->height)) { 2.125 - return -3; // TODO: make constant 2.126 - } 2.127 - 2.128 - // Set the pixel value 2.129 - image->data[(y*image->width)+x] = val; 2.130 - 2.131 - return 0; 2.132 -} 2.133 -
3.1 --- a/src/pt_image.h Mon Aug 03 14:21:23 2009 +0100 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,20 +0,0 @@ 3.4 -#ifndef PT_IMAGE_H 3.5 -#define PT_IMAGE_H 3.6 - 3.7 -/** 3.8 - * A storage class for simple images. 3.9 - * 3.10 - * Data is stored as bytes, as this makes the math easier (and modern 3.11 - * computer systems have plenty of RAM anyway). 3.12 - */ 3.13 -typedef struct { 3.14 - unsigned long width, height; 3.15 - unsigned char *data; 3.16 -} pt_Image; 3.17 - 3.18 -pt_Image *ptimage_Create(unsigned long width, unsigned long height); 3.19 -void ptimage_Free(pt_Image *image); 3.20 -int ptimage_GetPixel(pt_Image *image, unsigned long x, unsigned long y); 3.21 -int ptimage_SetPixel(pt_Image *image, unsigned long x, unsigned long y, unsigned char val); 3.22 - 3.23 -#endif // PT_IMAGE_H