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 gfxprim.git.
The branch, master has been updated via 17fe2ed28b93515ca3cf486e1af6aff088a7d8bd (commit) via 023357e5ae4971313f9a579e5b426039c0e5fb46 (commit) from 62f3b9db48fe5159efdfd4dd01d51242d37e4375 (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 ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/17fe2ed28b93515ca3cf486e1af6aff088a7d...
commit 17fe2ed28b93515ca3cf486e1af6aff088a7d8bd Author: Cyril Hrubis metan@ucw.cz Date: Sun Sep 8 22:53:35 2013 +0200
loaders: Add LineConvert.
Adds LineConvert API for trivial pixel conversions (i.e. RGB888 to BGR888 and so).
Make use of it in BMP and JPG loaders. (more to come)
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt index 9a933e7..e424e98 100644 --- a/build/syms/Loaders_symbols.txt +++ b/build/syms/Loaders_symbols.txt @@ -91,3 +91,6 @@ GP_ContainerSeek
GP_MatchZip GP_OpenZip + +GP_LineConvertible +GP_LineConvertGet diff --git a/include/loaders/GP_LineConvert.h b/include/loaders/GP_LineConvert.h new file mode 100644 index 0000000..c880aad --- /dev/null +++ b/include/loaders/GP_LineConvert.h @@ -0,0 +1,60 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +/* + + Converts a continuous line of pixels from buffer A to a line of pixels in + buffer B. + + Supports only trivial conversions i.e. RGB888 to BGR888 and G1_LE to G1_BE, + etc. + + The code is mainly used in image loaders when saving image from memory buffer + that has exactly same channels (in size and names) but placed differently in + buffer of pixel. + + */ + + +#ifndef LOADERS_LINE_CONVERT_H +#define LOADERS_LINE_CONVERT_H + +#include "core/GP_Pixel.h" + +typedef void (*GP_LineConvert)(const uint8_t *in, uint8_t *out, unsigned int len); + +/* + * The out array is terminated by GP_PIXEL_UNKNOWN. + * + * Returns output pixel type given input pixel type and table of posible output + * types. + * + * Returns GP_PIXEL_UNKNOWN if no conversion is posible. + */ +GP_PixelType GP_LineConvertible(GP_PixelType in, GP_PixelType out[]); + +/* + * Returns pointer to conversion function or NULL if there is none. + */ +GP_LineConvert GP_LineConvertGet(GP_PixelType in, GP_PixelType out); + +#endif /* LOADERS_LINE_CONVERT_H */ diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c index 430e9d7..b6f3a50 100644 --- a/libs/loaders/GP_BMP.c +++ b/libs/loaders/GP_BMP.c @@ -41,6 +41,7 @@ #include "core/GP_GetPutPixel.h"
#include "loaders/GP_ByteUtils.h" +#include "loaders/GP_LineConvert.h" #include "loaders/GP_BMP.h"
#define BMP_HEADER_OFFSET 0x0a /* info header offset - 4 bytes */ @@ -51,7 +52,6 @@ #define BUF_TO_2(buf, off) (buf[off] + (buf[off+1]<<8))
- struct bitmap_info_header { /* * Offset to image data. @@ -771,17 +771,27 @@ static int bmp_write_header(struct bitmap_info_header *header, FILE *f) return 0; }
+static GP_PixelType out_pixel_types[] = { + GP_PIXEL_RGB888, + GP_PIXEL_UNKNOWN, +}; + static int bmp_fill_header(const GP_Context *src, struct bitmap_info_header *header) { + GP_PixelType out_pix; + switch (src->pixel_type) { case GP_PIXEL_RGB888: - case GP_PIXEL_BGR888: header->bpp = 24; break; default: - GP_DEBUG(1, "Unsupported pixel type (%s)", - GP_PixelTypeName(src->pixel_type)); - return ENOSYS; + out_pix = GP_LineConvertible(src->pixel_type, out_pixel_types); + + if (out_pix == GP_PIXEL_UNKNOWN) { + GP_DEBUG(1, "Unsupported pixel type %s", + GP_PixelTypeName(src->pixel_type)); + return ENOSYS; + } }
header->w = src->w; @@ -803,9 +813,12 @@ static int bmp_fill_header(const GP_Context *src, struct bitmap_info_header *hea static int bmp_write_data(FILE *f, const GP_Context *src, GP_ProgressCallback *callback) { int y; - uint32_t padd_len = 0, x; + uint32_t padd_len = 0; char padd[3] = {0}; uint8_t tmp[3 * src->w]; + GP_LineConvert Convert; + + Convert = GP_LineConvertGet(src->pixel_type, GP_PIXEL_RGB888);
if (src->bytes_per_row%4) padd_len = 4 - src->bytes_per_row%4; @@ -813,14 +826,8 @@ static int bmp_write_data(FILE *f, const GP_Context *src, GP_ProgressCallback *c for (y = src->h - 1; y >= 0; y--) { void *row = GP_PIXEL_ADDR(src, 0, y);
- if (src->pixel_type == GP_PIXEL_BGR888) { - memcpy(tmp, row, 3 * src->w); - - for (x = 0; x < src->w; x++) { - uint8_t *pix = tmp + 3 * x; - GP_SWAP(pix[0], pix[2]); - } - + if (src->pixel_type != GP_PIXEL_RGB888) { + Convert(row, tmp, src->w); row = tmp; }
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c index e48c864..3b52821 100644 --- a/libs/loaders/GP_JPG.c +++ b/libs/loaders/GP_JPG.c @@ -37,7 +37,8 @@ #include "../../config.h" #include "core/GP_Debug.h"
-#include "GP_JPG.h" +#include "loaders/GP_LineConvert.h" +#include "loaders/GP_JPG.h"
#ifdef HAVE_JPEG
@@ -345,22 +346,21 @@ int GP_LoadJPGMetaData(const char *src_path, GP_MetaData *data) return ret; }
-static int save_rgb888(struct jpeg_compress_struct *cinfo, - const GP_Context *src, - GP_ProgressCallback *callback) +static int save_convert(struct jpeg_compress_struct *cinfo, + const GP_Context *src, + GP_PixelType out_pix, + GP_ProgressCallback *callback) { - unsigned int x; - uint8_t tmp[3 * src->w]; + uint8_t tmp[(src->w * GP_PixelSize(out_pix)) / 8 + 1]; + GP_LineConvert Convert; + + Convert = GP_LineConvertGet(src->pixel_type, out_pix);
while (cinfo->next_scanline < cinfo->image_height) { uint32_t y = cinfo->next_scanline; + void *in = GP_PIXEL_ADDR(src, 0, y);
- memcpy(tmp, GP_PIXEL_ADDR(src, 0, y), 3 * src->w); - - for (x = 0; x < src->w; x++) { - uint8_t *pix = tmp + 3 * x; - GP_SWAP(pix[0], pix[2]); - } + Convert(in, tmp, src->w);
JSAMPROW row = (void*)tmp; jpeg_write_scanlines(cinfo, &row, 1); @@ -393,26 +393,37 @@ static int save(struct jpeg_compress_struct *cinfo, return 0; }
+static GP_PixelType out_pixel_types[] = { + GP_PIXEL_BGR888, + GP_PIXEL_G8, + GP_PIXEL_UNKNOWN +}; + int GP_SaveJPG(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback) { FILE *f; struct jpeg_compress_struct cinfo; + GP_PixelType out_pix; struct my_jpg_err my_err; int err;
GP_DEBUG(1, "Saving JPG Image '%s'", dst_path);
switch (src->pixel_type) { - case GP_PIXEL_RGB888: case GP_PIXEL_BGR888: case GP_PIXEL_G8: + out_pix = src->pixel_type; break; default: - GP_DEBUG(1, "Unsupported pixel type %s", - GP_PixelTypeName(src->pixel_type)); - errno = ENOSYS; - return 1; + out_pix = GP_LineConvertible(src->pixel_type, out_pixel_types); + + if (out_pix == GP_PIXEL_UNKNOWN) { + GP_DEBUG(1, "Unsupported pixel type %s", + GP_PixelTypeName(src->pixel_type)); + errno = ENOSYS; + return 1; + } }
f = fopen(dst_path, "wb"); @@ -440,8 +451,7 @@ int GP_SaveJPG(const GP_Context *src, const char *dst_path, cinfo.image_width = src->w; cinfo.image_height = src->h;
- switch (src->pixel_type) { - case GP_PIXEL_RGB888: + switch (out_pix) { case GP_PIXEL_BGR888: cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; @@ -458,13 +468,10 @@ int GP_SaveJPG(const GP_Context *src, const char *dst_path,
jpeg_start_compress(&cinfo, TRUE);
- switch (src->pixel_type) { - case GP_PIXEL_RGB888: - err = save_rgb888(&cinfo, src, callback); - break; - default: + if (out_pix != src->pixel_type) + err = save_convert(&cinfo, src, out_pix, callback); + else err = save(&cinfo, src, callback); - }
if (err) goto err3; diff --git a/libs/loaders/GP_LineConvert.c b/libs/loaders/GP_LineConvert.c new file mode 100644 index 0000000..9f3b70c --- /dev/null +++ b/libs/loaders/GP_LineConvert.c @@ -0,0 +1,85 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include "core/GP_Debug.h" +#include "GP_LineConvert.h" + +static void xyz888_to_zyx888(const uint8_t *inbuf, uint8_t *outbuf, unsigned int len) +{ + unsigned int i; + + for (i = 0; i < len; i++) { + outbuf[2] = inbuf[0]; + outbuf[0] = inbuf[2]; + outbuf[1] = inbuf[1]; + + outbuf+=3; + inbuf+=3; + } +} + +GP_LineConvert GP_LineConvertGet(GP_PixelType in, GP_PixelType out) +{ + switch (in) { + case GP_PIXEL_RGB888: + switch (out) { + case GP_PIXEL_BGR888: + return xyz888_to_zyx888; + break; + default: + break; + } + break; + case GP_PIXEL_BGR888: + switch (out) { + case GP_PIXEL_RGB888: + return xyz888_to_zyx888; + break; + default: + break; + } + break; + default: + break; + } + + return NULL; +} + +GP_PixelType GP_LineConvertible(GP_PixelType in, GP_PixelType out[]) +{ + unsigned int i; + + GP_DEBUG(1, "Trying to find conversion for %s", GP_PixelTypeName(in)); + + for (i = 0; out[i] != GP_PIXEL_UNKNOWN; i++) { + if (GP_LineConvertGet(in, out[i])) { + GP_DEBUG(1, "Found %s -> %s", GP_PixelTypeName(in), + GP_PixelTypeName(out[i])); + return out[i]; + } + } + + GP_DEBUG(1, "Not found"); + + return GP_PIXEL_UNKNOWN; +}
http://repo.or.cz/w/gfxprim.git/commit/023357e5ae4971313f9a579e5b426039c0e5f...
commit 023357e5ae4971313f9a579e5b426039c0e5fb46 Author: Cyril Hrubis metan@ucw.cz Date: Sun Sep 8 18:27:15 2013 +0200
backends: Linux FB: Declare local function as static.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/backends/GP_LinuxFB.c b/libs/backends/GP_LinuxFB.c index 2849a7a..c14195f 100644 --- a/libs/backends/GP_LinuxFB.c +++ b/libs/backends/GP_LinuxFB.c @@ -202,7 +202,7 @@ static int allocate_console(struct fb_priv *fb, int flags) return 0; }
-void free_console(struct fb_priv *fb) +static void free_console(struct fb_priv *fb) { /* restore blinking cursor */ if (ioctl(fb->con_fd, KDSETMODE, KD_TEXT))
-----------------------------------------------------------------------
Summary of changes: build/syms/Loaders_symbols.txt | 3 + .../{gfx/GP_HLineAA.h => loaders/GP_LineConvert.h} | 39 +++++---- libs/backends/GP_LinuxFB.c | 2 +- libs/loaders/GP_BMP.c | 35 +++++--- libs/loaders/GP_JPG.c | 57 +++++++------ .../loaders/GP_LineConvert.c | 90 ++++++++++---------- 6 files changed, 125 insertions(+), 101 deletions(-) copy include/{gfx/GP_HLineAA.h => loaders/GP_LineConvert.h} (63%) copy demos/c_simple/gaussian_noise.c => libs/loaders/GP_LineConvert.c (61%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.