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