From: Lawrence S. <ljs...@us...> - 2015-05-09 16:22:15
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "An image loading library.". The branch, master has been updated via 0b66623cea623ac7478b501704af432c57e0475a (commit) from 324ededdab421cfefcfd380c2b77f24f2e3d8c5b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0b66623cea623ac7478b501704af432c57e0475a Author: Lawrence Sebald <ljs...@us...> Date: Sat May 9 12:21:59 2015 -0400 Fix libimageload for the new kos-ports. ----------------------------------------------------------------------- Summary of changes: imageload.c | 14 +++--- include/imageload.h | 3 - jitter.c | 4 +- readbmp.c | 116 +++++++++++++++++++++++++-------------------------- readjpeg.c | 21 +++++---- 5 files changed, 77 insertions(+), 81 deletions(-) diff --git a/imageload.c b/imageload.c index d508abb..4e48a49 100644 --- a/imageload.c +++ b/imageload.c @@ -1,4 +1,4 @@ -#include <imageload/imageload.h> +#include "imageload.h" #include <string.h> #include <malloc.h> @@ -31,12 +31,12 @@ img_copy_texture(uint16 *dest, uint8 *source, uint32 channels, uint32 stride, uint16 *destRow; uint8 *pRow; uint8 r,g,b; - + for(i = 0; i < h; i++) { pRow = &source[i*stride]; destRow = &dest[i*w]; - + if (channels == 3) { switch(info->alpha) @@ -233,7 +233,7 @@ int img_load_file(const char *filename, IMG_INFO *info, kos_img_t *img) info->type = img_guess(filename); img_load_data(f,info,img); - + fclose(f); return 0; @@ -244,7 +244,7 @@ int img_load_data(FILE *f, IMG_INFO *info, kos_img_t *img) uint32 channels, rowBytes; uint8 *data = NULL; uint8 allocate = 0; - + if (info == NULL) { allocate = 1; @@ -252,7 +252,7 @@ int img_load_data(FILE *f, IMG_INFO *info, kos_img_t *img) memset(&info,0,sizeof(IMG_INFO)); } - + switch(info->type) { case IMG_FILE_GUESS: @@ -321,6 +321,6 @@ int img_load_data(FILE *f, IMG_INFO *info, kos_img_t *img) img->fmt = KOS_IMG_FMT(KOS_IMG_FMT_ARGB4444, 0); break; } - + return 0; } diff --git a/include/imageload.h b/include/imageload.h index bbe82cb..fec2cc4 100644 --- a/include/imageload.h +++ b/include/imageload.h @@ -2,9 +2,6 @@ #define __IMAGELOAD_H__ #include <kos.h> -#include <imageload/jitterdefs.h> - -#include <stdio.h> typedef enum { diff --git a/jitter.c b/jitter.c index 7a94798..64c9f7f 100644 --- a/jitter.c +++ b/jitter.c @@ -1,4 +1,4 @@ -#include <imageload/jitterdefs.h> +#include "jitterdefs.h" #include <stdlib.h> @@ -22,7 +22,7 @@ unsigned char jitter(unsigned char c, unsigned char n, unsigned char shift, unsi { const unsigned char lowbit = 1 << shift; unsigned int p,q; - + if (c < 248) { p = c % lowbit; diff --git a/readbmp.c b/readbmp.c index 849cb9d..b520d24 100644 --- a/readbmp.c +++ b/readbmp.c @@ -3,8 +3,6 @@ #include <stdio.h> #include <stdlib.h> -#include <imageload/imageload.h> - #pragma pack(1) #define BI_RGB 0 @@ -12,37 +10,37 @@ #define BI_RLE4 2 #define BI_BITFIELDS 3 -typedef struct { - uint16 bfType; - uint32 bfSize; - uint16 bfReserved1; - uint16 bfReserved2; - uint32 bfOffBits; -} BITMAPFILEHEADER; - -typedef struct { - uint32 bcSize; - uint16 bcWidth; - uint16 bcHeight; - uint16 bcPlanes; - uint16 bcBitCount; +typedef struct { + uint16 bfType; + uint32 bfSize; + uint16 bfReserved1; + uint16 bfReserved2; + uint32 bfOffBits; +} BITMAPFILEHEADER; + +typedef struct { + uint32 bcSize; + uint16 bcWidth; + uint16 bcHeight; + uint16 bcPlanes; + uint16 bcBitCount; } BITMAPCOREHEADER; typedef struct tagBITMAPINFOHEADER { - uint32 biSize; - int32 biWidth; - int32 biHeight; - uint16 biPlanes; - uint16 biBitCount; - uint32 biCompression; - uint32 biSizeImage; - int32 biXPelsPerMeter; - int32 biYPelsPerMeter; - uint32 biClrUsed; - uint32 biClrImportant; + uint32 biSize; + int32 biWidth; + int32 biHeight; + uint16 biPlanes; + uint16 biBitCount; + uint32 biCompression; + uint32 biSizeImage; + int32 biXPelsPerMeter; + int32 biYPelsPerMeter; + uint32 biClrUsed; + uint32 biClrImportant; } BITMAPINFOHEADER; - -typedef struct + +typedef struct { uint8 rgbBlue; uint8 rgbGreen; @@ -73,7 +71,7 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, uint32 skip, r, g, b, k; uint32 x, y; uint8 byte; - + /* read the BITMAPFILEHEADER */ uint32 bytesRead = fread(&bitmapFile, 1, sizeof(BITMAPFILEHEADER), bmpfile); if ( bytesRead != sizeof(BITMAPFILEHEADER) || @@ -86,7 +84,7 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, bytesRead = fread(&bitmapInfo, 1, sizeof(BITMAPINFOHEADER), bmpfile); if ( bytesRead != sizeof(BITMAPINFOHEADER) || bitmapInfo.biSize == sizeof(BITMAPCOREHEADER)) - { + { return NULL; } @@ -118,11 +116,11 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, if (bitmapFile.bfOffBits != 0) fseek(bmpfile,bitmapFile.bfOffBits,SEEK_SET); - + imageBuffer = malloc(sizeof(uint8)*bitmapInfo.biSizeImage); buffer = imageBuffer; bytesRead = fread(buffer, 1, bitmapInfo.biSizeImage, bmpfile); - + if ( bytesRead != bitmapInfo.biSizeImage*sizeof(uint8)) { free(colorTable); @@ -135,14 +133,14 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, *pWidth = bitmapInfo.biWidth; *pHeight = bitmapInfo.biHeight; ourbuffer = (uint8*)malloc(*pRowbytes**pHeight); - - if (bitmapInfo.biCompression == BI_BITFIELDS) + + if (bitmapInfo.biCompression == BI_BITFIELDS) { int bit; rmask = ((unsigned int *)colorTable)[0]; gmask = ((unsigned int *)colorTable)[1]; bmask = ((unsigned int *)colorTable)[2]; - for (bit = bitmapInfo.biBitCount - 1; bit >= 0; bit--) + for (bit = bitmapInfo.biBitCount - 1; bit >= 0; bit--) { if (bmask & (1 << bit)) bshift = bit; @@ -150,9 +148,9 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, gshift = bit; if (rmask & (1 << bit)) rshift = bit; - } + } } - else if (bitmapInfo.biBitCount == 16) + else if (bitmapInfo.biBitCount == 16) { rmask = 0x7C00; gmask = 0x03E0; @@ -161,7 +159,7 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, gshift = 5; bshift = 0; } - else if (bitmapInfo.biBitCount == 32) + else if (bitmapInfo.biBitCount == 32) { rmask = 0x00FF0000; gmask = 0x0000FF00; @@ -170,10 +168,10 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, gshift = 8; bshift = 0; } - + /* for now we will not handle RLE encoded data */ - if (bitmapInfo.biBitCount == 4) + if (bitmapInfo.biBitCount == 4) { if (bitmapInfo.biCompression == BI_RLE4) { @@ -183,13 +181,13 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, return NULL; } else - if (bitmapInfo.biCompression == BI_RGB) + if (bitmapInfo.biCompression == BI_RGB) { skip = ((((bitmapInfo.biWidth + 7) / 8) * 8) - bitmapInfo.biWidth) / 2; byte = 0; - for (y = 0; y < bitmapInfo.biHeight; y++) + for (y = 0; y < bitmapInfo.biHeight; y++) { - for (x = 0; x < bitmapInfo.biWidth; x++) + for (x = 0; x < bitmapInfo.biWidth; x++) { if ((x & 1) == 0) byte = *(buffer++); @@ -203,7 +201,7 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, } } } - if (bitmapInfo.biBitCount == 8) + if (bitmapInfo.biBitCount == 8) { if (bitmapInfo.biCompression == BI_RLE8) { @@ -212,13 +210,13 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, free(ourbuffer); return NULL; } - else - if (bitmapInfo.biCompression == BI_RGB) + else + if (bitmapInfo.biCompression == BI_RGB) { skip = (((bitmapInfo.biWidth + 3) / 4) * 4) - bitmapInfo.biWidth; - for (y = 0; y < bitmapInfo.biHeight; y++) + for (y = 0; y < bitmapInfo.biHeight; y++) { - for (x = 0; x < bitmapInfo.biWidth; x++) + for (x = 0; x < bitmapInfo.biWidth; x++) { byte = *(buffer++); ourbuffer[(bitmapInfo.biHeight-y-1)**pRowbytes+3*x] = colorTable[byte].rgbRed; @@ -229,12 +227,12 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, } } } - else if (bitmapInfo.biBitCount == 16) + else if (bitmapInfo.biBitCount == 16) { skip = (((bitmapInfo.biWidth * 16 + 31) / 32) * 4) - (bitmapInfo.biWidth * 2); - for (y = 0; y < bitmapInfo.biHeight; y++) + for (y = 0; y < bitmapInfo.biHeight; y++) { - for (x = 0; x < bitmapInfo.biWidth; x++) + for (x = 0; x < bitmapInfo.biWidth; x++) { r = ((uint16)(*buffer) & rmask) >> rshift; g = ((uint16)(*buffer) & gmask) >> gshift; @@ -247,12 +245,12 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, buffer += skip; } } - else if (bitmapInfo.biBitCount == 24) + else if (bitmapInfo.biBitCount == 24) { skip = (4 - ((bitmapInfo.biWidth * 3) % 4)) & 3; - for (y = 0; y < bitmapInfo.biHeight; y++) + for (y = 0; y < bitmapInfo.biHeight; y++) { - for (x = 0; x < bitmapInfo.biWidth; x++) + for (x = 0; x < bitmapInfo.biWidth; x++) { b = *(buffer++); g = *(buffer++); @@ -265,12 +263,12 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, buffer += skip; } } - else if (bitmapInfo.biBitCount == 32) + else if (bitmapInfo.biBitCount == 32) { skip = (((bitmapInfo.biWidth * 32 + 31) / 32) * 4) - (bitmapInfo.biWidth * 4); - for (y = 0; y < bitmapInfo.biHeight; y++) + for (y = 0; y < bitmapInfo.biHeight; y++) { - for (x = 0; x < bitmapInfo.biWidth; x++) + for (x = 0; x < bitmapInfo.biWidth; x++) { r = ((uint32)(*buffer) & rmask) >> rshift; g = ((uint32)(*buffer) & gmask) >> gshift; @@ -279,7 +277,7 @@ uint8 *readbmp_get_image(uint32 *pChannels, uint32 *pRowbytes, ourbuffer[(bitmapInfo.biHeight-y-1)**pRowbytes+3*x] = r; ourbuffer[(bitmapInfo.biHeight-y-1)**pRowbytes+3*x+1] = g; ourbuffer[(bitmapInfo.biHeight-y-1)**pRowbytes+3*x+2] = b; - + buffer+=2; } buffer += skip; diff --git a/readjpeg.c b/readjpeg.c index 327291a..99c4a52 100644 --- a/readjpeg.c +++ b/readjpeg.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <string.h> -#include "../libjpeg/jpeglib.h" +#include <stdlib.h> +#include <jpeg/jpeglib.h> static struct jpeg_decompress_struct cinfo; static struct jpeg_error_mgr jerr; @@ -8,25 +9,25 @@ static struct jpeg_error_mgr jerr; uint32 readjpeg_init(FILE *infile) { /* Step 1: allocate and initialize JPEG decompression object */ - + /* We set up the normal JPEG error routines */ cinfo.err = jpeg_std_error(&jerr); - + /* Now we can initialize the JPEG decompression object. */ jpeg_create_decompress(&cinfo); - + /* Step 2: specify data source (eg, a file) */ - jpeg_stdio_src(&cinfo, infile); + jpeg_stdio_src(&cinfo, infile); (void) jpeg_read_header(&cinfo, TRUE); - + /* Step 4: set parameters for decompression */ - + cinfo.scale_denom = 1; /* must be 1, 2, 4, or 8 */ /* Step 5: Start decompressor */ (void) jpeg_start_decompress(&cinfo); - + return 0; } @@ -42,7 +43,7 @@ uint8 *readjpeg_get_image(uint32 *pChannels, uint32 *pRowbytes, uint32 *pWidth, *pChannels = cinfo.output_components; *pWidth = cinfo.output_width; *pHeight = cinfo.output_height; - + ourbuffer = (uint8 *)malloc(*pRowbytes**pHeight); buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, *pRowbytes, 1); @@ -52,7 +53,7 @@ uint8 *readjpeg_get_image(uint32 *pChannels, uint32 *pRowbytes, uint32 *pWidth, (void) jpeg_read_scanlines(&cinfo, buffer, 1); memcpy(&ourbuffer[i**pRowbytes], buffer[0], *pRowbytes); } - + return ourbuffer; } hooks/post-receive -- An image loading library. |