ucw.cz
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
List overview
Download
Gfxprim
January 2015
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
gfxprim@ucw.cz
1 participants
2 discussions
Start a n
N
ew thread
[repo.or.cz] gfxprim.git branch master updated: 1.0.0-rc1-128-g1109c295
by metan
16 Jan '15
16 Jan '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 gfxprim.git. The branch, master has been updated discards 3b9e7725969eafa310c5358783ec8547773f04e4 (commit) via 1109c295817003da4e1da28179040c3060dc1326 (commit) This update added new revisions after undoing existing revisions. That is to say, the old revision is not a strict subset of the new revision. This situation occurs when you --force push a change and generate a repository containing something like this: * -- * -- B -- O -- O -- O (3b9e7725969eafa310c5358783ec8547773f04e4) N -- N -- N (1109c295817003da4e1da28179040c3060dc1326) When this happens we assume that you've already had alert emails for all of the O revisions, and so we here report only the revisions in the N branch from the common base, B. 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/1109c295817003da4e1da28179040c3060dc…
commit 1109c295817003da4e1da28179040c3060dc1326 Author: Cyril Hrubis <metan(a)ucw.cz> Date: Fri Jan 16 10:29:10 2015 +0100 filters: Get rid of FilterParams * Remove FilterParams * Rewrite histogram code * Add GP_PixelChannelCount(), GP_PixelChannelBits() and GP_PixelChannelName() Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/build/syms/Filters_symbols.txt b/build/syms/Filters_symbols.txt index d048bdc6..43049197 100644 --- a/build/syms/Filters_symbols.txt +++ b/build/syms/Filters_symbols.txt @@ -57,8 +57,8 @@ GP_FilterHConvolutionMP_Raw GP_FilterHLinearConvolution_Raw GP_FilterHistogram -GP_FilterHistogramAlloc -GP_FilterHistogram_Raw +GP_HistogramAlloc +GP_HistogramFree GP_FilterKernelPrint_Raw @@ -89,27 +89,6 @@ GP_FilterMultiply GP_FilterMultiplyAlloc GP_FilterMultiply_Raw -GP_FilterParamChannel -GP_FilterParamChannels -GP_FilterParamCheckChannels -GP_FilterParamCheckPixelType -GP_FilterParamCreate -GP_FilterParamDestroy -GP_FilterParamFreePtrAll -GP_FilterParamInitChannels -GP_FilterParamPrintFloat -GP_FilterParamPrintInt -GP_FilterParamPrintPtr -GP_FilterParamPrintUInt -GP_FilterParamSetFloat -GP_FilterParamSetFloatAll -GP_FilterParamSetInt -GP_FilterParamSetIntAll -GP_FilterParamSetPtr -GP_FilterParamSetPtrAll -GP_FilterParamSetUInt -GP_FilterParamSetUIntAll - GP_FilterResize GP_FilterResizeAlloc diff --git a/demos/grinder/histogram.c b/demos/grinder/histogram.c index 00bffbdf..9706315b 100644 --- a/demos/grinder/histogram.c +++ b/demos/grinder/histogram.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -24,10 +24,15 @@ void histogram_to_png(const GP_Context *src, const char *filename) { - GP_FILTER_PARAMS(src->pixel_type, params); + GP_Histogram *hist; - GP_FilterHistogramAlloc(src->pixel_type, params); - GP_FilterHistogram(src, params, NULL); + hist = GP_HistogramAlloc(src->pixel_type); + if (!hist) { + fprintf(stderr, "Failed to allocate histogramn"); + return; + } + + GP_FilterHistogram(hist, src, NULL); unsigned int i, j; @@ -35,27 +40,22 @@ void histogram_to_png(const GP_Context *src, const char *filename) GP_Fill(res, 0xffffff); - GP_Histogram *hist_r; - hist_r = (GP_FilterParamChannel(params, "R"))->val.ptr; + GP_HistogramChannel *hist_r = GP_HistogramChannelByName(hist, "R"); for (i = 0; i < hist_r->len; i++) GP_VLineXYH(res, i, 256, -255.00 * hist_r->hist[i] / hist_r->max + 0.5 , 0xff0000); - GP_Histogram *hist_g; - hist_g = (GP_FilterParamChannel(params, "G"))->val.ptr; + GP_HistogramChannel *hist_g = GP_HistogramChannelByName(hist, "G"); for (i = 0; i < hist_g->len; i++) GP_VLineXYH(res, i+257, 256, -255.00 * hist_g->hist[i] / hist_g->max + 0.5 , 0x00ff00); - GP_Histogram *hist_b; - hist_b = (GP_FilterParamChannel(params, "B"))->val.ptr; + GP_HistogramChannel *hist_b = GP_HistogramChannelByName(hist, "B"); for (i = 0; i < hist_b->len; i++) GP_VLineXYH(res, i+514, 256, -255.00 * hist_b->hist[i] / hist_b->max + 0.5 , 0x0000ff); - uint32_t max = GP_MAX(hist_r->max, hist_g->max); - - max = GP_MAX(max, hist_b->max); + uint32_t max = GP_MAX3(hist_r->max, hist_g->max, hist_b->max); for (i = 0; i < hist_r->len; i++) { for (j = 0; j < hist_r->len; j++) { @@ -77,5 +77,5 @@ void histogram_to_png(const GP_Context *src, const char *filename) GP_SavePNG(res, filename, NULL); GP_ContextFree(res); - GP_FilterHistogramFree(params); + GP_HistogramFree(hist); } diff --git a/doc/pixels.txt b/doc/pixels.txt index ffc3fa1e..59462ce7 100644 --- a/doc/pixels.txt +++ b/doc/pixels.txt @@ -87,6 +87,12 @@ const char *GP_PixelTypeName(GP_PixelType type); uint32_t GP_PixelSize(GP_PixelType type); +unsigned int GP_PixelChannelCount(GP_PixelType type); + +uint8_t GP_PixelChannelBits(GP_PixelType type, uint8_t channel); + +const char *GP_PixelChannelName(GP_PixelType type, uint8_t channel); + int GP_PixelHasFlags(GP_PixelType pixel_type, GP_PixelFlags flags); ------------------------------------------------------------------------------- @@ -99,6 +105,12 @@ The 'GP_PixelTypeName()' function returns static string with pixel type name. The 'GP_PixelSize()' returns pixel size in bits. +The 'GP_PixelChannelCount()' returns number of pixel channels. + +The 'GP_PixelChannelBits()' returns number of bits for respective channel. + +The 'GP_PixelChannelName()' returns channel name. + The 'GP_PixelHasFlags()' function returns true if particular pixel type contains the bitmask of pixel flags. diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index bfe7d7fa..1f11a590 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * <jiri.bluebear.dluhos(a)gmail.com> * * * - * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> * * * @@ -153,6 +153,25 @@ static inline const GP_PixelTypeDescription *GP_PixelTypeDesc(GP_PixelType type) return &GP_PixelTypes[type]; } +static inline unsigned int GP_PixelChannelCount(GP_PixelType type) +{ + GP_CHECK_VALID_PIXELTYPE(type); + return GP_PixelTypes[type].numchannels; +} + +static inline uint8_t GP_PixelChannelBits(GP_PixelType type, uint8_t channel) +{ + GP_CHECK_VALID_PIXELTYPE(type); + return GP_PixelTypes[type].channels[channel].size; +} + +static inline const char *GP_PixelChannelName(GP_PixelType type, + uint8_t channel) +{ + GP_CHECK_VALID_PIXELTYPE(type); + return GP_PixelTypes[type].channels[channel].name; +} + /* * Print a human-readable representation of a pixel value to a string. * Arguments as for snprintf(). diff --git a/include/filters/GP_Filter.h b/include/filters/GP_Filter.h index 690a64b8..bc36e2ed 100644 --- a/include/filters/GP_Filter.h +++ b/include/filters/GP_Filter.h @@ -32,6 +32,4 @@ #include "core/GP_Context.h" #include "core/GP_ProgressCallback.h" -#include "GP_FilterParam.h" - #endif /* FILTERS_GP_FILTER_H */ diff --git a/include/filters/GP_FilterParam.h b/include/filters/GP_FilterParam.h deleted file mode 100644 index 31b7ab66..00000000 --- a/include/filters/GP_FilterParam.h +++ /dev/null @@ -1,167 +0,0 @@ -/***************************************************************************** - * 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-2012 Cyril Hrubis <metan(a)ucw.cz> * - * * - *****************************************************************************/ - -/* - - Filter per channel parameter passing code. - - */ - -#ifndef FILTERS_GP_FILTER_PARAM_H -#define FILTERS_GP_FILTER_PARAM_H - -#include "core/GP_Pixel.h" - -#include <stdint.h> - -typedef union GP_FilterParamVal { - float f; - uint32_t ui; - int32_t i; - void *ptr; -} GP_FilterParamVal; - -/* - * Filter parameter structure for one channel. - * - * Filter takes, empty channel name terminated, arrray of these as parameter. - */ -typedef struct GP_FilterParam { - //TODO: this must be > than maximal channel name (now it's 2) - char channel_name[2]; - union GP_FilterParamVal val; -} GP_FilterParam; - -/* - * Creates filter param structure large enough for given pixel_type. - * - * The returned structure has initalized channel_names and terminator. - */ -GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type); - -/* - * Destroys filter param structure. - */ -void GP_FilterParamDestroy(GP_FilterParam *self); - -/* - * Takes array of filter parameters and returns filter parameter by a channel - * name. - * - * Returns NULL if channel wasn't found. - */ -GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[], - const char *channel_name); - -/* - * Returns number of filter channels. - */ -uint32_t GP_FilterParamChannels(GP_FilterParam params[]); - -/* - * Compares param channels and pixel type channels. Returns zero if channels - * match. - */ -int GP_FilterParamCheckPixelType(GP_FilterParam params[], - GP_PixelType pixel_type); - -/* - * Returns zero only if params have exactly same channels as array of - * channel_names. - */ -int GP_FilterParamCheckChannels(GP_FilterParam params[], - const char *channel_names[]); - -/* - * Create and initalize the structure on the stack - */ -#define GP_FILTER_PARAMS(pixel_type, name) - GP_FilterParam name[GP_PixelTypes[pixel_type].numchannels + 1]; - GP_FilterParamInitChannels(name, pixel_type); - -/* - * Initalize param names and terminator. - * - * Sets all values to 0. - */ -void GP_FilterParamInitChannels(GP_FilterParam params[], - GP_PixelType pixel_type); - -/* - * Sets all values to integer value. - */ -void GP_FilterParamSetIntAll(GP_FilterParam params[], int32_t val); - -/* - * Sets integer value. Returns 0 if such value was found, non-zero otherwise. - */ -int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name, - int32_t val); - -/* - * Sets all values to float value. - */ -void GP_FilterParamSetFloatAll(GP_FilterParam params[], float val); - -/* - * Sets float value. Returns 0 if such value was found, non-zero otherwise. - */ -int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name, - float val); - -/* - * Sets all values to unsigned integer value. - */ -void GP_FilterParamSetUIntAll(GP_FilterParam params[], uint32_t val); - -/* - * Sets unsigned integer value. Returns 0 if such value was found, non-zero - * otherwise. - */ -int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name, - uint32_t val); - -/* - * Sets all values to pointer value. - */ -void GP_FilterParamSetPtrAll(GP_FilterParam params[], void *ptr); - -/* - * Sets pointer value. Returns 0 if such value was found, non-zero otherwise. - */ -int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name, - void *ptr); - -/* - * Call free on all pointer values. - */ -void GP_FilterParamFreePtrAll(GP_FilterParam params[]); - -/* - * Functions to print the array. - */ -void GP_FilterParamPrintInt(GP_FilterParam params[]); -void GP_FilterParamPrintUInt(GP_FilterParam params[]); -void GP_FilterParamPrintFloat(GP_FilterParam params[]); -void GP_FilterParamPrintPtr(GP_FilterParam params[]); - -#endif /* FILTERS_GP_FILTER_PARAM_H */ diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h index 3fe7afbd..1b68c71f 100644 --- a/include/filters/GP_Filters.h +++ b/include/filters/GP_Filters.h @@ -32,9 +32,6 @@ #ifndef FILTERS_GP_FILTERS_H #define FILTERS_GP_FILTERS_H -/* Filter per channel parameter passing interface */ -#include "filters/GP_FilterParam.h" - /* Point filters, brightness, contrast ... */ #include "filters/GP_Point.h" diff --git a/include/filters/GP_Stats.h b/include/filters/GP_Stats.h index 6ad62dff..8d780fe2 100644 --- a/include/filters/GP_Stats.h +++ b/include/filters/GP_Stats.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -31,34 +31,39 @@ #include "GP_Filter.h" -typedef struct GP_Histogram { - uint32_t min; - uint32_t max; +typedef struct GP_HistogramChannel { + const char *chan_name; + GP_Pixel min; + GP_Pixel max; uint32_t len; uint32_t hist[]; +} GP_HistogramChannel; + +typedef struct GP_Histogram { + GP_PixelType pixel_type; + GP_HistogramChannel *channels[]; } GP_Histogram; /* - * Histogram filter. - * - * The filter param is expected to hold pointers to struct GP_Histogram + * Allocates histogram for a given pixel type */ -int GP_FilterHistogram(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback); +GP_Histogram *GP_HistogramAlloc(GP_PixelType pixel_type); /* - * Allocate and initalize struct GP_Histogram for each channel and stores the - * pointer to filter params array. The pixel type must match the params[] - * channels. + * Frees histogram. */ -void GP_FilterHistogramAlloc(GP_PixelType type, GP_FilterParam params[]); +void GP_HistogramFree(GP_Histogram *self); /* - * Free the histogram arrays. + * Returns pointer to channel given channel name. */ -static inline void GP_FilterHistogramFree(GP_FilterParam params[]) -{ - GP_FilterParamFreePtrAll(params); -} +GP_HistogramChannel *GP_HistogramChannelByName(GP_Histogram *self, + const char *name); + +/* + * Computes histogram. Returns non-zero on failure (i.e. canceled by callback). + */ +int GP_FilterHistogram(GP_Histogram *self, const GP_Context *src, + GP_ProgressCallback *callback); #endif /* FILTERS_GP_STATS_H */ diff --git a/libs/filters/GP_FilterParam.c b/libs/filters/GP_FilterParam.c deleted file mode 100644 index fe7537c5..00000000 --- a/libs/filters/GP_FilterParam.c +++ /dev/null @@ -1,257 +0,0 @@ -/***************************************************************************** - * 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-2012 Cyril Hrubis <metan(a)ucw.cz> * - * * - *****************************************************************************/ - -#include <string.h> - -#include "core/GP_Debug.h" - -#include "GP_FilterParam.h" - -GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type) -{ - GP_FilterParam *ret; - - ret = malloc((GP_PixelTypes[pixel_type].numchannels + 1) - * sizeof(GP_FilterParam)); - - if (ret == NULL) { - GP_WARN("Malloc Failed"); - return NULL; - } - - GP_FilterParamInitChannels(ret, pixel_type); - - return ret; -} - -void GP_FilterParamDestroy(GP_FilterParam *self) -{ - free(self); -} - -static unsigned int count_channels(GP_FilterParam params[]) -{ - unsigned int i = 0; - - while (params[i].channel_name[0] != '0') - i++; - - return i; -} - -GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[], - const char *channel_name) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - if (!strcmp(params[i].channel_name, channel_name)) - return ¶ms[i]; - - return NULL; -} - -uint32_t GP_FilterParamChannels(GP_FilterParam params[]) -{ - return count_channels(params); -} - -int GP_FilterParamCheckPixelType(GP_FilterParam params[], - GP_PixelType pixel_type) -{ - unsigned int i, num_channels; - const GP_PixelTypeChannel *channels; - - num_channels = GP_PixelTypes[pixel_type].numchannels; - channels = GP_PixelTypes[pixel_type].channels; - - i = count_channels(params); - - if (i != num_channels) - return 1; - - for (i = 0; i < num_channels; i++) - if (GP_FilterParamChannel(params, channels[i].name) == NULL) - return 1; - - return 0; -} - -int GP_FilterParamCheckChannels(GP_FilterParam params[], - const char *channel_names[]) -{ - unsigned int i; - - for (i = 0; channel_names[i] != NULL; i++) - if (GP_FilterParamChannel(params, channel_names[i]) == NULL) - return 1; - - if (i != count_channels(params)) - return 1; - - return 0; -} - -void GP_FilterParamInitChannels(GP_FilterParam params[], - GP_PixelType pixel_type) -{ - unsigned int i, num_channels; - const GP_PixelTypeChannel *channels; - - num_channels = GP_PixelTypes[pixel_type].numchannels; - channels = GP_PixelTypes[pixel_type].channels; - - for (i = 0; i < num_channels; i++) { - strcpy(params[i].channel_name, channels[i].name); - memset(¶ms[i].val, 0, sizeof(GP_FilterParamVal)); - } - - params[i].channel_name[0] = '0'; -} - -void GP_FilterParamSetIntAll(GP_FilterParam params[], - int32_t val) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.i = val; -} - -int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name, - int32_t val) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.i = val; - return 0; -} - -void GP_FilterParamSetFloatAll(GP_FilterParam params[], - float val) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.f = val; -} - -int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name, - float val) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.f = val; - return 0; -} - -void GP_FilterParamSetUIntAll(GP_FilterParam params[], - uint32_t val) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.ui = val; -} - -int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name, - uint32_t val) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.ui = val; - return 0; -} - -void GP_FilterParamSetPtrAll(GP_FilterParam params[], - void *ptr) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.ptr = ptr; -} - -int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name, - void *ptr) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.ptr = ptr; - return 0; -} - -void GP_FilterParamFreePtrAll(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - free(params[i].val.ptr); -} - -void GP_FilterParamPrintInt(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %in", params[i].channel_name, params[i].val.i); -} - -void GP_FilterParamPrintUInt(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %un", params[i].channel_name, params[i].val.ui); -} - -void GP_FilterParamPrintFloat(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %fn", params[i].channel_name, params[i].val.f); -} - -void GP_FilterParamPrintPtr(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %pn", params[i].channel_name, params[i].val.ptr); -} diff --git a/libs/filters/GP_Stats.c b/libs/filters/GP_Histogram.c similarity index 53% rename from libs/filters/GP_Stats.c rename to libs/filters/GP_Histogram.c index 3ed5b683..8657c876 100644 --- a/libs/filters/GP_Stats.c +++ b/libs/filters/GP_Histogram.c @@ -16,72 +16,72 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ #include <string.h> +#include <errno.h> -#include <GP_Debug.h> - +#include <core/GP_Debug.h> #include "GP_Stats.h" -int GP_FilterHistogram_Raw(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback); - -int GP_FilterHistogram(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback) +GP_Histogram *GP_HistogramAlloc(GP_PixelType pixel_type) { - int ret; - - ret = GP_FilterHistogram_Raw(src, histogram, callback); - - if (ret) - return ret; - + size_t hsize, size = 0; unsigned int i; + GP_Histogram *hist; - for (i = 0; histogram[i].channel_name[0] != '0'; i++) { - unsigned int j; - GP_Histogram *hist = histogram[i].val.ptr; + GP_DEBUG(1, "Allocating histogram for %s", + GP_PixelTypeName(pixel_type)); - hist->max = hist->hist[0]; - hist->min = hist->hist[0]; + hsize = sizeof(GP_Histogram) + + GP_PixelChannelCount(pixel_type) * sizeof(void*); - for (j = 1; j < hist->len; j++) { - if (hist->hist[j] > hist->max) - hist->max = hist->hist[j]; - - if (hist->hist[j] < hist->min) - hist->min = hist->hist[j]; - } + for (i = 0; i < GP_PixelChannelCount(pixel_type); i++) { + size += sizeof(GP_HistogramChannel) + + sizeof(uint32_t) * (1<<GP_PixelChannelBits(pixel_type, i)); } - return 0; -} + hist = malloc(hsize + size); + if (!hist) { + GP_WARN("Malloc failed :("); + errno = ENOMEM; + return NULL; + } -void GP_FilterHistogramAlloc(GP_PixelType type, GP_FilterParam params[]) -{ - uint32_t i; + hist->pixel_type = pixel_type; - GP_FilterParamSetPtrAll(params, NULL); + for (i = 0; i < GP_PixelChannelCount(pixel_type); i++) { + size_t chan_size = 1<<GP_PixelChannelBits(pixel_type, i); - const GP_PixelTypeChannel *channels = GP_PixelTypes[type].channels; + hist->channels[i] = (void*)hist + hsize; - for (i = 0; i < GP_PixelTypes[type].numchannels; i++) { - size_t chan_size = 1<<channels[i].size; + hsize += sizeof(GP_HistogramChannel) + + sizeof(uint32_t) * chan_size; - GP_Histogram *hist = malloc(sizeof(struct GP_Histogram) + - sizeof(uint32_t) * chan_size); + hist->channels[i]->len = chan_size; + hist->channels[i]->chan_name = GP_PixelChannelName(pixel_type, i); + } - if (hist == NULL) { - GP_FilterHistogramFree(params); - return; - } + return hist; +} - hist->len = chan_size; - memset(hist->hist, 0, sizeof(uint32_t) * chan_size); +GP_HistogramChannel *GP_HistogramChannelByName(GP_Histogram *self, + const char *name) +{ + unsigned int i; - (GP_FilterParamChannel(params, channels[i].name))->val.ptr = hist; + for (i = 0; i < GP_PixelChannelCount(self->pixel_type); i++) { + if (!strcmp(self->channels[i]->chan_name, name)) + return self->channels[i]; } + + return NULL; +} + +void GP_HistogramFree(GP_Histogram *self) +{ + GP_DEBUG(1, "Freeing histogram %p", self); + free(self); } diff --git a/libs/filters/GP_Histogram.gen.c.t b/libs/filters/GP_Histogram.gen.c.t index 3436aa63..52bfc5c1 100644 --- a/libs/filters/GP_Histogram.gen.c.t +++ b/libs/filters/GP_Histogram.gen.c.t @@ -2,27 +2,34 @@ /* * Histogram filter -- Compute image histogram * - * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz> + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> */ -#include "core/GP_Context.h" -#include "core/GP_Pixel.h" -#include "core/GP_GetPutPixel.h" -#include "core/GP_Debug.h" -#include "GP_Filter.h" +#include <string.h> +#include <errno.h> -#include "GP_Stats.h" +#include <core/GP_Context.h> +#include <core/GP_Pixel.h> +#include <core/GP_GetPutPixel.h> +#include <core/GP_Debug.h> +#include <filters/GP_Filter.h> +#include <filters/GP_Stats.h> @ for pt in pixeltypes: @ if not pt.is_unknown() and not pt.is_palette(): -static int GP_FilterHistogram_{{ pt.name }}(const GP_Context *src, - GP_FilterParam histogram[], GP_ProgressCallback *callback) +static int GP_FilterHistogram_{{ pt.name }}(GP_Histogram *self, + const GP_Context *src, GP_ProgressCallback *callback) { - GP_ASSERT(GP_FilterParamCheckPixelType(histogram, GP_PIXEL_{{ pt.name }}) == 0, - "Invalid params channels for context pixel type"); + if (self->pixel_type != src->pixel_type) { + GP_WARN("Histogram (%s) and context (%s) pixel type must match", + GP_PixelTypeName(self->pixel_type), + GP_PixelTypeName(src->pixel_type)); + errno = EINVAL; + return 1; + } @ for c in pt.chanslist: - GP_Histogram *{{ c.name }}_hist = (GP_FilterParamChannel(histogram, "{{ c.name }}"))->val.ptr; + GP_HistogramChannel *chan_{{ c.name }} = self->channels[{{ c.idx }}]; @ end uint32_t x, y; @@ -35,7 +42,7 @@ static int GP_FilterHistogram_{{ pt.name }}(const GP_Context *src, @ end @ for c in pt.chanslist: - {{ c.name }}_hist->hist[{{ c.name }}]++; + chan_{{ c.name }}->hist[{{ c.name }}]++; @ end } @@ -49,20 +56,50 @@ static int GP_FilterHistogram_{{ pt.name }}(const GP_Context *src, @ end @ -int GP_FilterHistogram_Raw(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback) +int GP_FilterHistogram(GP_Histogram *self, const GP_Context *src, + GP_ProgressCallback *callback) { - GP_DEBUG(1, "Running filter Histogram"); + unsigned int i, j; + int ret; + + GP_DEBUG(1, "Running Histogram filter"); + + for (i = 0; i < GP_PixelChannelCount(self->pixel_type); i++) { + GP_HistogramChannel *chan = self->channels[i]; + printf("CHAN %i %i %pn", i, chan->len, chan->hist); + memset(chan->hist, 0, sizeof(uint32_t) * chan->len); + } switch (src->pixel_type) { @ for pt in pixeltypes: @ if not pt.is_unknown() and not pt.is_palette(): case GP_PIXEL_{{ pt.name }}: - return GP_FilterHistogram_{{ pt.name }}(src, histogram, callback); + ret = GP_FilterHistogram_{{ pt.name }}(self, src, callback); + break; @ end default: + errno = ENOSYS; + return 1; break; } - return 1; + if (ret) + return ret; + + for (i = 0; i < GP_PixelChannelCount(self->pixel_type); i++) { + GP_HistogramChannel *chan = self->channels[i]; + + chan->max = chan->hist[0]; + chan->min = chan->hist[0]; + + for (j = 1; j < chan->len; j++) { + if (chan->hist[j] > chan->max) + chan->max = chan->hist[j]; + + if (chan->hist[j] < chan->min) + chan->min = chan->hist[j]; + } + } + + return 0; } ----------------------------------------------------------------------- Summary of changes: doc/pixels.txt | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive no reply. -- gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
0
0
[repo.or.cz] gfxprim.git branch master updated: 1.0.0-rc1-128-g3b9e7725
by metan
16 Jan '15
16 Jan '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 gfxprim.git. The branch, master has been updated via 3b9e7725969eafa310c5358783ec8547773f04e4 (commit) via b39970be125155a45b6d9b9199e7cde4857b57bd (commit) via f86cf9cc008444620c01b79d1cdffe8352a36825 (commit) via 54959be6241f6fe85a39f72e9ba88e3d42d06835 (commit) via 380af9d42b91493a3cb726a075279e29030ba679 (commit) via 69fbdb92d0f48c5d030d2cc0cb0c475b75464774 (commit) via 80386afaf5cbd6c805140ae1e0f8e37918666e23 (commit) via aefa0cab17b7f75cada9bc97678055313642e1e6 (commit) via 9af41a3215a074981988fbcf5ed8c1f45739b9d4 (commit) from c410d038596cfd83b39c4729dcfaf0e99e3e48b0 (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/3b9e7725969eafa310c5358783ec8547773f…
commit 3b9e7725969eafa310c5358783ec8547773f04e4 Author: Cyril Hrubis <metan(a)ucw.cz> Date: Fri Jan 16 10:29:10 2015 +0100 filters: Get rid of FilterParams * Remove FilterParams * Rewrite histogram code * Add GP_PixelChannelCount(), GP_PixelChannelBits() and GP_PixelChannelName() Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/build/syms/Filters_symbols.txt b/build/syms/Filters_symbols.txt index d048bdc6..43049197 100644 --- a/build/syms/Filters_symbols.txt +++ b/build/syms/Filters_symbols.txt @@ -57,8 +57,8 @@ GP_FilterHConvolutionMP_Raw GP_FilterHLinearConvolution_Raw GP_FilterHistogram -GP_FilterHistogramAlloc -GP_FilterHistogram_Raw +GP_HistogramAlloc +GP_HistogramFree GP_FilterKernelPrint_Raw @@ -89,27 +89,6 @@ GP_FilterMultiply GP_FilterMultiplyAlloc GP_FilterMultiply_Raw -GP_FilterParamChannel -GP_FilterParamChannels -GP_FilterParamCheckChannels -GP_FilterParamCheckPixelType -GP_FilterParamCreate -GP_FilterParamDestroy -GP_FilterParamFreePtrAll -GP_FilterParamInitChannels -GP_FilterParamPrintFloat -GP_FilterParamPrintInt -GP_FilterParamPrintPtr -GP_FilterParamPrintUInt -GP_FilterParamSetFloat -GP_FilterParamSetFloatAll -GP_FilterParamSetInt -GP_FilterParamSetIntAll -GP_FilterParamSetPtr -GP_FilterParamSetPtrAll -GP_FilterParamSetUInt -GP_FilterParamSetUIntAll - GP_FilterResize GP_FilterResizeAlloc diff --git a/demos/grinder/histogram.c b/demos/grinder/histogram.c index 00bffbdf..9706315b 100644 --- a/demos/grinder/histogram.c +++ b/demos/grinder/histogram.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -24,10 +24,15 @@ void histogram_to_png(const GP_Context *src, const char *filename) { - GP_FILTER_PARAMS(src->pixel_type, params); + GP_Histogram *hist; - GP_FilterHistogramAlloc(src->pixel_type, params); - GP_FilterHistogram(src, params, NULL); + hist = GP_HistogramAlloc(src->pixel_type); + if (!hist) { + fprintf(stderr, "Failed to allocate histogramn"); + return; + } + + GP_FilterHistogram(hist, src, NULL); unsigned int i, j; @@ -35,27 +40,22 @@ void histogram_to_png(const GP_Context *src, const char *filename) GP_Fill(res, 0xffffff); - GP_Histogram *hist_r; - hist_r = (GP_FilterParamChannel(params, "R"))->val.ptr; + GP_HistogramChannel *hist_r = GP_HistogramChannelByName(hist, "R"); for (i = 0; i < hist_r->len; i++) GP_VLineXYH(res, i, 256, -255.00 * hist_r->hist[i] / hist_r->max + 0.5 , 0xff0000); - GP_Histogram *hist_g; - hist_g = (GP_FilterParamChannel(params, "G"))->val.ptr; + GP_HistogramChannel *hist_g = GP_HistogramChannelByName(hist, "G"); for (i = 0; i < hist_g->len; i++) GP_VLineXYH(res, i+257, 256, -255.00 * hist_g->hist[i] / hist_g->max + 0.5 , 0x00ff00); - GP_Histogram *hist_b; - hist_b = (GP_FilterParamChannel(params, "B"))->val.ptr; + GP_HistogramChannel *hist_b = GP_HistogramChannelByName(hist, "B"); for (i = 0; i < hist_b->len; i++) GP_VLineXYH(res, i+514, 256, -255.00 * hist_b->hist[i] / hist_b->max + 0.5 , 0x0000ff); - uint32_t max = GP_MAX(hist_r->max, hist_g->max); - - max = GP_MAX(max, hist_b->max); + uint32_t max = GP_MAX3(hist_r->max, hist_g->max, hist_b->max); for (i = 0; i < hist_r->len; i++) { for (j = 0; j < hist_r->len; j++) { @@ -77,5 +77,5 @@ void histogram_to_png(const GP_Context *src, const char *filename) GP_SavePNG(res, filename, NULL); GP_ContextFree(res); - GP_FilterHistogramFree(params); + GP_HistogramFree(hist); } diff --git a/doc/pixels.txt b/doc/pixels.txt index ffc3fa1e..804898b4 100644 --- a/doc/pixels.txt +++ b/doc/pixels.txt @@ -87,6 +87,10 @@ const char *GP_PixelTypeName(GP_PixelType type); uint32_t GP_PixelSize(GP_PixelType type); +unsigned int GP_PixelChannelCount(GP_PixelType type); + +uint8_t GP_PixelChannelBits(GP_PixelType type, uint8_t channel); + int GP_PixelHasFlags(GP_PixelType pixel_type, GP_PixelFlags flags); ------------------------------------------------------------------------------- @@ -99,6 +103,10 @@ The 'GP_PixelTypeName()' function returns static string with pixel type name. The 'GP_PixelSize()' returns pixel size in bits. +The 'GP_PixelChannelCount()' returns number of pixel channels. + +The 'GP_PixelChannelBits()' returns number of bits for respective channel. + The 'GP_PixelHasFlags()' function returns true if particular pixel type contains the bitmask of pixel flags. diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index bfe7d7fa..1f11a590 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * <jiri.bluebear.dluhos(a)gmail.com> * * * - * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> * * * @@ -153,6 +153,25 @@ static inline const GP_PixelTypeDescription *GP_PixelTypeDesc(GP_PixelType type) return &GP_PixelTypes[type]; } +static inline unsigned int GP_PixelChannelCount(GP_PixelType type) +{ + GP_CHECK_VALID_PIXELTYPE(type); + return GP_PixelTypes[type].numchannels; +} + +static inline uint8_t GP_PixelChannelBits(GP_PixelType type, uint8_t channel) +{ + GP_CHECK_VALID_PIXELTYPE(type); + return GP_PixelTypes[type].channels[channel].size; +} + +static inline const char *GP_PixelChannelName(GP_PixelType type, + uint8_t channel) +{ + GP_CHECK_VALID_PIXELTYPE(type); + return GP_PixelTypes[type].channels[channel].name; +} + /* * Print a human-readable representation of a pixel value to a string. * Arguments as for snprintf(). diff --git a/include/filters/GP_Filter.h b/include/filters/GP_Filter.h index 690a64b8..bc36e2ed 100644 --- a/include/filters/GP_Filter.h +++ b/include/filters/GP_Filter.h @@ -32,6 +32,4 @@ #include "core/GP_Context.h" #include "core/GP_ProgressCallback.h" -#include "GP_FilterParam.h" - #endif /* FILTERS_GP_FILTER_H */ diff --git a/include/filters/GP_FilterParam.h b/include/filters/GP_FilterParam.h deleted file mode 100644 index 31b7ab66..00000000 --- a/include/filters/GP_FilterParam.h +++ /dev/null @@ -1,167 +0,0 @@ -/***************************************************************************** - * 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-2012 Cyril Hrubis <metan(a)ucw.cz> * - * * - *****************************************************************************/ - -/* - - Filter per channel parameter passing code. - - */ - -#ifndef FILTERS_GP_FILTER_PARAM_H -#define FILTERS_GP_FILTER_PARAM_H - -#include "core/GP_Pixel.h" - -#include <stdint.h> - -typedef union GP_FilterParamVal { - float f; - uint32_t ui; - int32_t i; - void *ptr; -} GP_FilterParamVal; - -/* - * Filter parameter structure for one channel. - * - * Filter takes, empty channel name terminated, arrray of these as parameter. - */ -typedef struct GP_FilterParam { - //TODO: this must be > than maximal channel name (now it's 2) - char channel_name[2]; - union GP_FilterParamVal val; -} GP_FilterParam; - -/* - * Creates filter param structure large enough for given pixel_type. - * - * The returned structure has initalized channel_names and terminator. - */ -GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type); - -/* - * Destroys filter param structure. - */ -void GP_FilterParamDestroy(GP_FilterParam *self); - -/* - * Takes array of filter parameters and returns filter parameter by a channel - * name. - * - * Returns NULL if channel wasn't found. - */ -GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[], - const char *channel_name); - -/* - * Returns number of filter channels. - */ -uint32_t GP_FilterParamChannels(GP_FilterParam params[]); - -/* - * Compares param channels and pixel type channels. Returns zero if channels - * match. - */ -int GP_FilterParamCheckPixelType(GP_FilterParam params[], - GP_PixelType pixel_type); - -/* - * Returns zero only if params have exactly same channels as array of - * channel_names. - */ -int GP_FilterParamCheckChannels(GP_FilterParam params[], - const char *channel_names[]); - -/* - * Create and initalize the structure on the stack - */ -#define GP_FILTER_PARAMS(pixel_type, name) - GP_FilterParam name[GP_PixelTypes[pixel_type].numchannels + 1]; - GP_FilterParamInitChannels(name, pixel_type); - -/* - * Initalize param names and terminator. - * - * Sets all values to 0. - */ -void GP_FilterParamInitChannels(GP_FilterParam params[], - GP_PixelType pixel_type); - -/* - * Sets all values to integer value. - */ -void GP_FilterParamSetIntAll(GP_FilterParam params[], int32_t val); - -/* - * Sets integer value. Returns 0 if such value was found, non-zero otherwise. - */ -int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name, - int32_t val); - -/* - * Sets all values to float value. - */ -void GP_FilterParamSetFloatAll(GP_FilterParam params[], float val); - -/* - * Sets float value. Returns 0 if such value was found, non-zero otherwise. - */ -int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name, - float val); - -/* - * Sets all values to unsigned integer value. - */ -void GP_FilterParamSetUIntAll(GP_FilterParam params[], uint32_t val); - -/* - * Sets unsigned integer value. Returns 0 if such value was found, non-zero - * otherwise. - */ -int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name, - uint32_t val); - -/* - * Sets all values to pointer value. - */ -void GP_FilterParamSetPtrAll(GP_FilterParam params[], void *ptr); - -/* - * Sets pointer value. Returns 0 if such value was found, non-zero otherwise. - */ -int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name, - void *ptr); - -/* - * Call free on all pointer values. - */ -void GP_FilterParamFreePtrAll(GP_FilterParam params[]); - -/* - * Functions to print the array. - */ -void GP_FilterParamPrintInt(GP_FilterParam params[]); -void GP_FilterParamPrintUInt(GP_FilterParam params[]); -void GP_FilterParamPrintFloat(GP_FilterParam params[]); -void GP_FilterParamPrintPtr(GP_FilterParam params[]); - -#endif /* FILTERS_GP_FILTER_PARAM_H */ diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h index 3fe7afbd..1b68c71f 100644 --- a/include/filters/GP_Filters.h +++ b/include/filters/GP_Filters.h @@ -32,9 +32,6 @@ #ifndef FILTERS_GP_FILTERS_H #define FILTERS_GP_FILTERS_H -/* Filter per channel parameter passing interface */ -#include "filters/GP_FilterParam.h" - /* Point filters, brightness, contrast ... */ #include "filters/GP_Point.h" diff --git a/include/filters/GP_Stats.h b/include/filters/GP_Stats.h index 6ad62dff..8d780fe2 100644 --- a/include/filters/GP_Stats.h +++ b/include/filters/GP_Stats.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -31,34 +31,39 @@ #include "GP_Filter.h" -typedef struct GP_Histogram { - uint32_t min; - uint32_t max; +typedef struct GP_HistogramChannel { + const char *chan_name; + GP_Pixel min; + GP_Pixel max; uint32_t len; uint32_t hist[]; +} GP_HistogramChannel; + +typedef struct GP_Histogram { + GP_PixelType pixel_type; + GP_HistogramChannel *channels[]; } GP_Histogram; /* - * Histogram filter. - * - * The filter param is expected to hold pointers to struct GP_Histogram + * Allocates histogram for a given pixel type */ -int GP_FilterHistogram(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback); +GP_Histogram *GP_HistogramAlloc(GP_PixelType pixel_type); /* - * Allocate and initalize struct GP_Histogram for each channel and stores the - * pointer to filter params array. The pixel type must match the params[] - * channels. + * Frees histogram. */ -void GP_FilterHistogramAlloc(GP_PixelType type, GP_FilterParam params[]); +void GP_HistogramFree(GP_Histogram *self); /* - * Free the histogram arrays. + * Returns pointer to channel given channel name. */ -static inline void GP_FilterHistogramFree(GP_FilterParam params[]) -{ - GP_FilterParamFreePtrAll(params); -} +GP_HistogramChannel *GP_HistogramChannelByName(GP_Histogram *self, + const char *name); + +/* + * Computes histogram. Returns non-zero on failure (i.e. canceled by callback). + */ +int GP_FilterHistogram(GP_Histogram *self, const GP_Context *src, + GP_ProgressCallback *callback); #endif /* FILTERS_GP_STATS_H */ diff --git a/libs/filters/GP_FilterParam.c b/libs/filters/GP_FilterParam.c deleted file mode 100644 index fe7537c5..00000000 --- a/libs/filters/GP_FilterParam.c +++ /dev/null @@ -1,257 +0,0 @@ -/***************************************************************************** - * 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-2012 Cyril Hrubis <metan(a)ucw.cz> * - * * - *****************************************************************************/ - -#include <string.h> - -#include "core/GP_Debug.h" - -#include "GP_FilterParam.h" - -GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type) -{ - GP_FilterParam *ret; - - ret = malloc((GP_PixelTypes[pixel_type].numchannels + 1) - * sizeof(GP_FilterParam)); - - if (ret == NULL) { - GP_WARN("Malloc Failed"); - return NULL; - } - - GP_FilterParamInitChannels(ret, pixel_type); - - return ret; -} - -void GP_FilterParamDestroy(GP_FilterParam *self) -{ - free(self); -} - -static unsigned int count_channels(GP_FilterParam params[]) -{ - unsigned int i = 0; - - while (params[i].channel_name[0] != '0') - i++; - - return i; -} - -GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[], - const char *channel_name) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - if (!strcmp(params[i].channel_name, channel_name)) - return ¶ms[i]; - - return NULL; -} - -uint32_t GP_FilterParamChannels(GP_FilterParam params[]) -{ - return count_channels(params); -} - -int GP_FilterParamCheckPixelType(GP_FilterParam params[], - GP_PixelType pixel_type) -{ - unsigned int i, num_channels; - const GP_PixelTypeChannel *channels; - - num_channels = GP_PixelTypes[pixel_type].numchannels; - channels = GP_PixelTypes[pixel_type].channels; - - i = count_channels(params); - - if (i != num_channels) - return 1; - - for (i = 0; i < num_channels; i++) - if (GP_FilterParamChannel(params, channels[i].name) == NULL) - return 1; - - return 0; -} - -int GP_FilterParamCheckChannels(GP_FilterParam params[], - const char *channel_names[]) -{ - unsigned int i; - - for (i = 0; channel_names[i] != NULL; i++) - if (GP_FilterParamChannel(params, channel_names[i]) == NULL) - return 1; - - if (i != count_channels(params)) - return 1; - - return 0; -} - -void GP_FilterParamInitChannels(GP_FilterParam params[], - GP_PixelType pixel_type) -{ - unsigned int i, num_channels; - const GP_PixelTypeChannel *channels; - - num_channels = GP_PixelTypes[pixel_type].numchannels; - channels = GP_PixelTypes[pixel_type].channels; - - for (i = 0; i < num_channels; i++) { - strcpy(params[i].channel_name, channels[i].name); - memset(¶ms[i].val, 0, sizeof(GP_FilterParamVal)); - } - - params[i].channel_name[0] = '0'; -} - -void GP_FilterParamSetIntAll(GP_FilterParam params[], - int32_t val) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.i = val; -} - -int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name, - int32_t val) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.i = val; - return 0; -} - -void GP_FilterParamSetFloatAll(GP_FilterParam params[], - float val) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.f = val; -} - -int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name, - float val) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.f = val; - return 0; -} - -void GP_FilterParamSetUIntAll(GP_FilterParam params[], - uint32_t val) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.ui = val; -} - -int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name, - uint32_t val) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.ui = val; - return 0; -} - -void GP_FilterParamSetPtrAll(GP_FilterParam params[], - void *ptr) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - params[i].val.ptr = ptr; -} - -int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name, - void *ptr) -{ - GP_FilterParam *param; - param = GP_FilterParamChannel(params, channel_name); - - if (param == NULL) - return 1; - - param->val.ptr = ptr; - return 0; -} - -void GP_FilterParamFreePtrAll(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - free(params[i].val.ptr); -} - -void GP_FilterParamPrintInt(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %in", params[i].channel_name, params[i].val.i); -} - -void GP_FilterParamPrintUInt(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %un", params[i].channel_name, params[i].val.ui); -} - -void GP_FilterParamPrintFloat(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %fn", params[i].channel_name, params[i].val.f); -} - -void GP_FilterParamPrintPtr(GP_FilterParam params[]) -{ - unsigned int i; - - for (i = 0; params[i].channel_name[0] != '0'; i++) - printf("Chann '%s' = %pn", params[i].channel_name, params[i].val.ptr); -} diff --git a/libs/filters/GP_Stats.c b/libs/filters/GP_Histogram.c similarity index 53% rename from libs/filters/GP_Stats.c rename to libs/filters/GP_Histogram.c index 3ed5b683..8657c876 100644 --- a/libs/filters/GP_Stats.c +++ b/libs/filters/GP_Histogram.c @@ -16,72 +16,72 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ #include <string.h> +#include <errno.h> -#include <GP_Debug.h> - +#include <core/GP_Debug.h> #include "GP_Stats.h" -int GP_FilterHistogram_Raw(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback); - -int GP_FilterHistogram(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback) +GP_Histogram *GP_HistogramAlloc(GP_PixelType pixel_type) { - int ret; - - ret = GP_FilterHistogram_Raw(src, histogram, callback); - - if (ret) - return ret; - + size_t hsize, size = 0; unsigned int i; + GP_Histogram *hist; - for (i = 0; histogram[i].channel_name[0] != '0'; i++) { - unsigned int j; - GP_Histogram *hist = histogram[i].val.ptr; + GP_DEBUG(1, "Allocating histogram for %s", + GP_PixelTypeName(pixel_type)); - hist->max = hist->hist[0]; - hist->min = hist->hist[0]; + hsize = sizeof(GP_Histogram) + + GP_PixelChannelCount(pixel_type) * sizeof(void*); - for (j = 1; j < hist->len; j++) { - if (hist->hist[j] > hist->max) - hist->max = hist->hist[j]; - - if (hist->hist[j] < hist->min) - hist->min = hist->hist[j]; - } + for (i = 0; i < GP_PixelChannelCount(pixel_type); i++) { + size += sizeof(GP_HistogramChannel) + + sizeof(uint32_t) * (1<<GP_PixelChannelBits(pixel_type, i)); } - return 0; -} + hist = malloc(hsize + size); + if (!hist) { + GP_WARN("Malloc failed :("); + errno = ENOMEM; + return NULL; + } -void GP_FilterHistogramAlloc(GP_PixelType type, GP_FilterParam params[]) -{ - uint32_t i; + hist->pixel_type = pixel_type; - GP_FilterParamSetPtrAll(params, NULL); + for (i = 0; i < GP_PixelChannelCount(pixel_type); i++) { + size_t chan_size = 1<<GP_PixelChannelBits(pixel_type, i); - const GP_PixelTypeChannel *channels = GP_PixelTypes[type].channels; + hist->channels[i] = (void*)hist + hsize; - for (i = 0; i < GP_PixelTypes[type].numchannels; i++) { - size_t chan_size = 1<<channels[i].size; + hsize += sizeof(GP_HistogramChannel) + + sizeof(uint32_t) * chan_size; - GP_Histogram *hist = malloc(sizeof(struct GP_Histogram) + - sizeof(uint32_t) * chan_size); + hist->channels[i]->len = chan_size; + hist->channels[i]->chan_name = GP_PixelChannelName(pixel_type, i); + } - if (hist == NULL) { - GP_FilterHistogramFree(params); - return; - } + return hist; +} - hist->len = chan_size; - memset(hist->hist, 0, sizeof(uint32_t) * chan_size); +GP_HistogramChannel *GP_HistogramChannelByName(GP_Histogram *self, + const char *name) +{ + unsigned int i; - (GP_FilterParamChannel(params, channels[i].name))->val.ptr = hist; + for (i = 0; i < GP_PixelChannelCount(self->pixel_type); i++) { + if (!strcmp(self->channels[i]->chan_name, name)) + return self->channels[i]; } + + return NULL; +} + +void GP_HistogramFree(GP_Histogram *self) +{ + GP_DEBUG(1, "Freeing histogram %p", self); + free(self); } diff --git a/libs/filters/GP_Histogram.gen.c.t b/libs/filters/GP_Histogram.gen.c.t index 3436aa63..52bfc5c1 100644 --- a/libs/filters/GP_Histogram.gen.c.t +++ b/libs/filters/GP_Histogram.gen.c.t @@ -2,27 +2,34 @@ /* * Histogram filter -- Compute image histogram * - * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz> + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> */ -#include "core/GP_Context.h" -#include "core/GP_Pixel.h" -#include "core/GP_GetPutPixel.h" -#include "core/GP_Debug.h" -#include "GP_Filter.h" +#include <string.h> +#include <errno.h> -#include "GP_Stats.h" +#include <core/GP_Context.h> +#include <core/GP_Pixel.h> +#include <core/GP_GetPutPixel.h> +#include <core/GP_Debug.h> +#include <filters/GP_Filter.h> +#include <filters/GP_Stats.h> @ for pt in pixeltypes: @ if not pt.is_unknown() and not pt.is_palette(): -static int GP_FilterHistogram_{{ pt.name }}(const GP_Context *src, - GP_FilterParam histogram[], GP_ProgressCallback *callback) +static int GP_FilterHistogram_{{ pt.name }}(GP_Histogram *self, + const GP_Context *src, GP_ProgressCallback *callback) { - GP_ASSERT(GP_FilterParamCheckPixelType(histogram, GP_PIXEL_{{ pt.name }}) == 0, - "Invalid params channels for context pixel type"); + if (self->pixel_type != src->pixel_type) { + GP_WARN("Histogram (%s) and context (%s) pixel type must match", + GP_PixelTypeName(self->pixel_type), + GP_PixelTypeName(src->pixel_type)); + errno = EINVAL; + return 1; + } @ for c in pt.chanslist: - GP_Histogram *{{ c.name }}_hist = (GP_FilterParamChannel(histogram, "{{ c.name }}"))->val.ptr; + GP_HistogramChannel *chan_{{ c.name }} = self->channels[{{ c.idx }}]; @ end uint32_t x, y; @@ -35,7 +42,7 @@ static int GP_FilterHistogram_{{ pt.name }}(const GP_Context *src, @ end @ for c in pt.chanslist: - {{ c.name }}_hist->hist[{{ c.name }}]++; + chan_{{ c.name }}->hist[{{ c.name }}]++; @ end } @@ -49,20 +56,50 @@ static int GP_FilterHistogram_{{ pt.name }}(const GP_Context *src, @ end @ -int GP_FilterHistogram_Raw(const GP_Context *src, GP_FilterParam histogram[], - GP_ProgressCallback *callback) +int GP_FilterHistogram(GP_Histogram *self, const GP_Context *src, + GP_ProgressCallback *callback) { - GP_DEBUG(1, "Running filter Histogram"); + unsigned int i, j; + int ret; + + GP_DEBUG(1, "Running Histogram filter"); + + for (i = 0; i < GP_PixelChannelCount(self->pixel_type); i++) { + GP_HistogramChannel *chan = self->channels[i]; + printf("CHAN %i %i %pn", i, chan->len, chan->hist); + memset(chan->hist, 0, sizeof(uint32_t) * chan->len); + } switch (src->pixel_type) { @ for pt in pixeltypes: @ if not pt.is_unknown() and not pt.is_palette(): case GP_PIXEL_{{ pt.name }}: - return GP_FilterHistogram_{{ pt.name }}(src, histogram, callback); + ret = GP_FilterHistogram_{{ pt.name }}(self, src, callback); + break; @ end default: + errno = ENOSYS; + return 1; break; } - return 1; + if (ret) + return ret; + + for (i = 0; i < GP_PixelChannelCount(self->pixel_type); i++) { + GP_HistogramChannel *chan = self->channels[i]; + + chan->max = chan->hist[0]; + chan->min = chan->hist[0]; + + for (j = 1; j < chan->len; j++) { + if (chan->hist[j] > chan->max) + chan->max = chan->hist[j]; + + if (chan->hist[j] < chan->min) + chan->min = chan->hist[j]; + } + } + + return 0; }
http://repo.or.cz/w/gfxprim.git/commit/b39970be125155a45b6d9b9199e7cde4857b…
commit b39970be125155a45b6d9b9199e7cde4857b57bd Author: Cyril Hrubis <metan(a)ucw.cz> Date: Thu Jan 15 20:28:53 2015 +0100 loaders: Get rid of TmpFile. Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt index 0266e70d..79ada509 100644 --- a/build/syms/Loaders_symbols.txt +++ b/build/syms/Loaders_symbols.txt @@ -104,9 +104,6 @@ GP_PSD GP_ReadExif -GP_SaveTmpFile -GP_LoadTmpFile - GP_LoaderBySignature GP_LoaderByFilename GP_LoaderLoadImage diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile index 654df984..13464238 100644 --- a/demos/c_simple/Makefile +++ b/demos/c_simple/Makefile @@ -13,7 +13,7 @@ INCLUDE= LDLIBS+=-lrt APPS=backend_example loaders_example loaders filters_symmetry gfx_koch- virtual_backend_example meta_data tmp_file showimage+ virtual_backend_example meta_data showimage v4l2_show v4l2_grab convolution weighted_median shapetest koch input_example fileview linetest randomshapetest fonttest loaders_register blittest textaligntest sin_AA x11_windows@@ -32,7 +32,6 @@ backend_timers_example: LDLIBS+=-lgfxprim-backends virtual_backend_example: LDLIBS+=-lgfxprim-backends -lm loaders_example: LDLIBS+=-lgfxprim-loaders loaders: LDLIBS+=-lgfxprim-loaders -tmp_file: LDLIBS+=-lgfxprim-loaders filters_symmetry: LDLIBS+=-lgfxprim-loaders gfx_koch: LDLIBS+=-lgfxprim-loaders -lm meta_data: LDLIBS+=-lgfxprim-loaders diff --git a/demos/c_simple/tmp_file.c b/demos/c_simple/tmp_file.c deleted file mode 100644 index 6daf3991..00000000 --- a/demos/c_simple/tmp_file.c +++ /dev/null @@ -1,110 +0,0 @@ -/***************************************************************************** - * 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-2012 Cyril Hrubis <metan(a)ucw.cz> * - * * - *****************************************************************************/ - - /* - - Tmp file is interface for storing GP_Context data on disk in uncompressed - fast but non-portable format (more or less GP_Context dump). - - */ - -#include <stdio.h> -#include <string.h> -#include <errno.h> - -#include <GP.h> - -struct callback_priv { - char *op; - char *name; -}; - -static int progress_callback(GP_ProgressCallback *self) -{ - struct callback_priv *priv = self->priv; - - printf("r%s '%s' %3.1f%%", priv->op, priv->name, self->percentage); - fflush(stdout); - - return 0; -} - -int main(int argc, char *argv[]) -{ - GP_Context *img; - struct callback_priv priv; - GP_ProgressCallback callback = {.callback = progress_callback, - .priv = &priv}; - - if (argc != 2) { - fprintf(stderr, "Takes an image as an parametern"); - return 1; - } - - priv.op = "Loading"; - priv.name = argv[1]; - - img = GP_LoadImage(argv[1], &callback); - - if (img == NULL) { - fprintf(stderr, "Failed to load image '%s':%sn", argv[1], - strerror(errno)); - return 1; - } - - printf("n"); - - priv.op = "Saving"; - priv.name = "tmp.gfx"; - - if (GP_SaveTmpFile(img, priv.name, &callback)) { - fprintf(stderr, "Failed to save temp file %sn", strerror(errno)); - return 1; - } - - printf("n"); - - GP_ContextFree(img); - - priv.op = "Loading"; - - img = GP_LoadTmpFile(priv.name, &callback); - - if (img == NULL) { - fprintf(stderr, "Failed to load temp file %sn", strerror(errno)); - return 1; - } - - priv.op = "Saving"; - priv.name = "out.png"; - - printf("n"); - - if (GP_SavePNG(img, "out.png", &callback)) { - fprintf(stderr, "Failed to save image %sn", strerror(errno)); - return 1; - } - - printf("n"); - - return 0; -} diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h index 4c32ceb5..bb2f6998 100644 --- a/include/loaders/GP_Loaders.h +++ b/include/loaders/GP_Loaders.h @@ -46,8 +46,6 @@ #include "loaders/GP_PSP.h" #include "loaders/GP_PSD.h" -#include "loaders/GP_TmpFile.h" - #include "loaders/GP_DataStorage.h" #include "loaders/GP_Exif.h" diff --git a/include/loaders/GP_TmpFile.h b/include/loaders/GP_TmpFile.h deleted file mode 100644 index 819962ba..00000000 --- a/include/loaders/GP_TmpFile.h +++ /dev/null @@ -1,58 +0,0 @@ -/***************************************************************************** - * 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-2012 Cyril Hrubis <metan(a)ucw.cz> * - * * - *****************************************************************************/ - - /* - - This is interface for saving GP_Context into non-portable uncompressed file, - which is usefull for caching GP_Context to disk. - - */ - -#ifndef LOADERS_GP_TMP_FILE_H -#define LOADERS_GP_TMP_FILE_H - -#include "core/GP_Context.h" -#include "core/GP_ProgressCallback.h" - -/* - * The possible errno values: - * - * - Anything FILE operation may return (fopen(), fclose(), fseek(), ...). - * - EIO for fread()/fwrite() failure - * - ENOMEM from malloc() - * - ECANCELED when call was aborted from callback - */ - -/* - * Opens up and loads file. - * - * On failure NULL is returned and errno is set. - */ -GP_Context *GP_LoadTmpFile(const char *src_path, GP_ProgressCallback *callback); - -/* - * Saves context into a file. On failure non-zero is returned and errno is set. - */ -int GP_SaveTmpFile(const GP_Context *src, const char *dst_path, - GP_ProgressCallback *callback); - -#endif /* LOADERS_GP_TMP_FILE_H */ diff --git a/libs/loaders/GP_TmpFile.c b/libs/loaders/GP_TmpFile.c deleted file mode 100644 index 0dbb5ad7..00000000 --- a/libs/loaders/GP_TmpFile.c +++ /dev/null @@ -1,183 +0,0 @@ -/***************************************************************************** - * 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-2012 Cyril Hrubis <metan(a)ucw.cz> * - * * - *****************************************************************************/ - -#include <stdio.h> -#include <errno.h> -#include <string.h> - -#include "core/GP_Debug.h" - -#include "GP_TmpFile.h" - -static const char file_sig[] = {'G', 'F', 'X', 'p', 'r', 'i', 'm'}; - -GP_Context *GP_LoadTmpFile(const char *src_path, GP_ProgressCallback *callback) -{ - FILE *f; - uint32_t w, h, y; - uint8_t offset, flags; - uint32_t bpr; - enum GP_PixelType pixel_type; - char sig[sizeof(file_sig)]; - GP_Context *ret; - int err, i; - - f = fopen(src_path, "r"); - - if (f == NULL) - return NULL; - - /* Read an signature */ - if (fread(sig, sizeof(sig), 1, f) != 1) { - err = EIO; - goto err0; - } - - if (strncmp(sig, file_sig, sizeof(sig))) { - GP_WARN("Invalid file '%s' signature", src_path); - err = EINVAL; - goto err0; - } - - /* Read context metadata */ - i = fread(&w, sizeof(w), 1, f); - i += fread(&h, sizeof(h), 1, f); - i += fread(&offset, sizeof(offset), 1, f); - i += fread(&bpr, sizeof(bpr), 1, f); - i += fread(&pixel_type, sizeof(pixel_type), 1, f); - i += fread(&flags, 1, 1, f); - - if (i != 6 || ferror(f)) { - err = EIO; - goto err0; - } - - ret = GP_ContextAlloc(w, h, pixel_type); - - if (ret == NULL) { - err = errno; - goto err0; - } - - //TODO: We may disagree here on ill aligned subcontexts - GP_ASSERT(ret->bytes_per_row == bpr, "Invalid bytes per row"); - - ret->offset = offset; - - /* And pixels */ - for (y = 0; y < h; y++) { - if (fread(ret->pixels + bpr * y, bpr, 1, f) != 1) { - err = EIO; - goto err1; - } - - GP_ProgressCallbackReport(callback, y, h, w); - } - - /* Set the rotation flags */ - if (flags & 0x01) - ret->axes_swap = 1; - - if (flags & 0x02) - ret->x_swap = 1; - - if (flags & 0x04) - ret->y_swap = 1; - - fclose(f); - - GP_ProgressCallbackDone(callback); - - return ret; -err1: - GP_ContextFree(ret); -err0: - fclose(f); - errno = err; - return NULL; -} - -int GP_SaveTmpFile(const GP_Context *src, const char *dst_path, - GP_ProgressCallback *callback) -{ - FILE *f; - int err; - uint32_t y, i; - - f = fopen(dst_path, "w"); - - if (f == NULL) - return 1; - - /* Write a signature */ - i = fwrite(file_sig, sizeof(file_sig), 1, f); - - /* Write block of metadata */ - i += fwrite(&src->w, sizeof(src->w), 1, f); - i += fwrite(&src->h, sizeof(src->h), 1, f); - i += fwrite(&src->offset, sizeof(src->offset), 1, f); - i += fwrite(&src->bytes_per_row, sizeof(src->bytes_per_row), 1, f); - i += fwrite(&src->pixel_type, sizeof(src->pixel_type), 1, f); - - uint8_t flags = 0; - - if (src->axes_swap) - flags |= 0x01; - - if (src->x_swap) - flags |= 0x02; - - if (src->y_swap) - flags |= 0x04; - - i += fwrite(&flags, 1, 1, f); - - if (i != 7) { - err = EIO; - goto err1; - } - - /* And pixels */ - for (y = 0; y < src->h; y++) { - if (fwrite(src->pixels + src->bytes_per_row * y, src->bytes_per_row, 1, f) != 1) { - err = EIO; - goto err1; - } - - GP_ProgressCallbackReport(callback, y, src->h, src->w); - } - - if (fclose(f)) { - err = errno; - goto err0; - } - - GP_ProgressCallbackDone(callback); - - return 0; -err1: - fclose(f); -err0: - unlink(dst_path); - errno = err; - return 1; -}
http://repo.or.cz/w/gfxprim.git/commit/f86cf9cc008444620c01b79d1cdffe8352a3…
commit f86cf9cc008444620c01b79d1cdffe8352a36825 Author: Cyril Hrubis <metan(a)ucw.cz> Date: Thu Jan 15 20:14:50 2015 +0100 loaders: Add Ex loading function to container API And fix the ZIP loader as well. Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/include/loaders/GP_Container.h b/include/loaders/GP_Container.h index 2670bc58..c1df3946 100644 --- a/include/loaders/GP_Container.h +++ b/include/loaders/GP_Container.h @@ -33,6 +33,8 @@ #include "core/GP_Context.h" #include "core/GP_ProgressCallback.h" +#include "loaders/GP_DataStorage.h" + struct GP_Container; enum GP_ContainerWhence { @@ -52,8 +54,8 @@ struct GP_ContainerOps { /* * Just loads current image, does not advance to the next image. */ - GP_Context *(*Load)(struct GP_Container *self, - GP_ProgressCallback *callback); + int (*LoadEx)(struct GP_Container *self, GP_Context **img, + GP_DataStorage *storage, GP_ProgressCallback *callback); /* * Close callback, use the inline function defined below. @@ -109,7 +111,18 @@ static inline GP_Context *GP_ContainerLoadNext(GP_Container *self, /* * Just loads current image, does not advance to the next one. */ -GP_Context *GP_ContainerLoad(GP_Container *self, GP_ProgressCallback *callback); +int GP_ContainerLoadEx(GP_Container *self, GP_Context **img, + GP_DataStorage *storage, GP_ProgressCallback *callback); + +static inline GP_Context *GP_ContainerLoad(GP_Container *self, + GP_ProgressCallback *callback) +{ + GP_Context *ret = NULL; + + GP_ContainerLoadEx(self, &ret, NULL, callback); + + return ret; +} int GP_ContainerSeek(GP_Container *self, int offset, enum GP_ContainerWhence whence); diff --git a/libs/loaders/GP_Container.c b/libs/loaders/GP_Container.c index 1a90289b..f2dfcc9b 100644 --- a/libs/loaders/GP_Container.c +++ b/libs/loaders/GP_Container.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -31,20 +31,22 @@ int GP_ContainerSeek(GP_Container *self, int offset, if (!self->ops->Seek) { GP_DEBUG(1, "Seek not implemented in %s container", self->ops->type); + errno = ENOSYS; return ENOSYS; } return self->ops->Seek(self, offset, whence); } -GP_Context *GP_ContainerLoad(GP_Container *self, GP_ProgressCallback *callback) +int GP_ContainerLoadEx(GP_Container *self, GP_Context **img, + GP_DataStorage *storage, GP_ProgressCallback *callback) { - if (!self->ops->Load) { + if (!self->ops->LoadEx) { GP_DEBUG(1, "Load not implemented in %s container", self->ops->type); errno = ENOSYS; - return NULL; + return ENOSYS; } - return self->ops->Load(self, callback); + return self->ops->LoadEx(self, img, storage, callback); } diff --git a/libs/loaders/GP_ZIP.c b/libs/loaders/GP_ZIP.c index 728f3841..f9ae413c 100644 --- a/libs/loaders/GP_ZIP.c +++ b/libs/loaders/GP_ZIP.c @@ -37,8 +37,8 @@ #include <core/GP_Common.h> #include <core/GP_Debug.h> -#include <loaders/GP_Loader.h> -#include <loaders/GP_IOZlib.h> +#include "loaders/GP_Loader.h" +#include "loaders/GP_IOZlib.h" #include "loaders/GP_ZIP.h" #ifdef HAVE_ZLIB @@ -241,11 +241,12 @@ static int zip_read_data_desc(GP_IO *io, struct zip_local_header *header) return 0; } -static GP_Context *zip_next_file(struct zip_priv *priv, - GP_ProgressCallback *callback) +static int zip_next_file(struct zip_priv *priv, GP_Context **img, + GP_DataStorage *storage, + GP_ProgressCallback *callback) { struct zip_local_header header = {.file_name = NULL}; - int err = 0; + int err = 0, res; GP_Context *ret = NULL; GP_IO *io; @@ -302,8 +303,8 @@ static GP_Context *zip_next_file(struct zip_priv *priv, GP_IOMark(priv->io, GP_IO_MARK); - ret = GP_ReadImage(priv->io, callback); - if (errno == ECANCELED) + res = GP_ReadImageEx(priv->io, &ret, storage, callback); + if (res && errno == ECANCELED) err = errno; GP_IOSeek(priv->io, priv->io->mark + header.comp_size, GP_IO_SEEK_SET); @@ -311,26 +312,15 @@ static GP_Context *zip_next_file(struct zip_priv *priv, goto out; break; case COMPRESS_DEFLATE: - /* if ((err = read_deflate(priv->io, &header, &io))) { + io = GP_IOZlib(priv->io, header.comp_size); + if (!io) { err = errno; goto out; } - GP_DEBUG(1, "Reading image"); - ret = GP_ReadImage(io, callback); - if (errno == ECANCELED) - err = errno; - - GP_IOClose(io); - goto out; - */ - - io = GP_IOZlib(priv->io, header.comp_size); - if (!io) - goto out; GP_DEBUG(1, "Reading image"); - ret = GP_ReadImage(io, callback); - if (errno == ECANCELED) + res = GP_ReadImageEx(io, &ret, storage, callback); + if (res && errno == ECANCELED) err = errno; /* @@ -361,7 +351,8 @@ static GP_Context *zip_next_file(struct zip_priv *priv, out: free(header.file_name); errno = err; - return ret; + *img = ret; + return err; } static unsigned int last_offset_idx(struct zip_priv *priv) @@ -421,33 +412,39 @@ static void record_offset(struct zip_priv *priv, long offset) */ } -static GP_Context *zip_load_next(GP_Container *self, - GP_ProgressCallback *callback) +static int zip_load_next(GP_Container *self, GP_Context **img, + GP_DataStorage *storage, + GP_ProgressCallback *callback) { struct zip_priv *priv = GP_CONTAINER_PRIV(self); - GP_Context *ret; - long offset; + int err; GP_DEBUG(1, "Trying to load next image from ZIP container"); - do { - offset = GP_IOTell(priv->io); - ret = zip_next_file(priv, callback); - } while (ret == NULL && errno == 0); + *img = NULL; - if (!ret) - return NULL; + do { + err = zip_next_file(priv, img, storage, callback); + } while (!*img && errno == 0); - if (ret) - record_offset(priv, offset); + if (err) + return 1; record_offset(priv, GP_IOTell(priv->io)); priv->cur_pos++; - //self->cur_img++; self->cur_img = priv->cur_pos; - return ret; + return 0; +} + +static GP_Context *load_next(GP_Container *self, GP_ProgressCallback *callback) +{ + GP_Context *img = NULL; + + zip_load_next(self, &img, NULL, callback); + + return img; } /* Seek to the current position */ @@ -573,19 +570,15 @@ static int zip_seek(GP_Container *self, int offset, return ret; } -static GP_Context *zip_load(GP_Container *self, - GP_ProgressCallback *callback) +static int zip_load(GP_Container *self, GP_Context **img, + GP_DataStorage *storage, GP_ProgressCallback *callback) { - GP_Context *img; - - img = zip_load_next(self, callback); - - if (!img) - return NULL; + if (zip_load_next(self, img, storage, callback)) + return 1; zip_seek(self, -1, GP_CONT_CUR); - return img; + return 0; } static void zip_close(GP_Container *self) @@ -649,8 +642,8 @@ err0: } static const struct GP_ContainerOps zip_ops = { - .LoadNext = zip_load_next, - .Load = zip_load, + .LoadNext = load_next, + .LoadEx = zip_load, .Close = zip_close, .Seek = zip_seek, .type = "ZIP",
http://repo.or.cz/w/gfxprim.git/commit/54959be6241f6fe85a39f72e9ba88e3d42d0…
commit 54959be6241f6fe85a39f72e9ba88e3d42d06835 Author: Cyril Hrubis <metan(a)ucw.cz> Date: Fri Jan 2 11:35:18 2015 +0100 demos: bogoman: Many improvements. * New type of blocks * Rendering optimalizations * Fixed window resize handling Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/demos/bogoman/bogoman.c b/demos/bogoman/bogoman.c index 0f745847..a83cba38 100644 --- a/demos/bogoman/bogoman.c +++ b/demos/bogoman/bogoman.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -27,7 +27,7 @@ #include "bogoman_loader.h" #include "bogoman_render.h" -#define ELEM_SIZE 33 +#define ELEM_SIZE 27 static void save_png(struct bogoman_map *map, unsigned int elem_size, const char *filename) @@ -59,8 +59,10 @@ static void save_png(struct bogoman_map *map, unsigned int elem_size, static struct GP_Backend *backend; -static void event_loop(struct bogoman_map *map) +static void event_loop(struct bogoman_render *render, GP_Backend *backend) { + struct bogoman_map *map = render->map; + while (GP_BackendEventsQueued(backend)) { GP_Event ev; @@ -89,6 +91,19 @@ static void event_loop(struct bogoman_map *map) bogoman_map_player_move(map, 0, 1); break; } + bogoman_render(render, BOGOMAN_RENDER_DIRTY); + break; + case GP_EV_SYS: + switch (ev.code) { + case GP_EV_SYS_RESIZE: + GP_BackendResizeAck(backend); + bogoman_render(render, BOGOMAN_RENDER_ALL); + break; + } + break; + case GP_EV_TMR: + bogoman_map_timer_tick(render->map); + bogoman_render(render, BOGOMAN_RENDER_DIRTY); break; } } @@ -99,6 +114,7 @@ static void event_loop(struct bogoman_map *map) int main(int argc, char *argv[]) { struct bogoman_map *map; + GP_TIMER_DECLARE(timer, 0, 300, "Refresh", NULL, NULL); bogoman_set_dbg_level(10); @@ -129,20 +145,17 @@ int main(int argc, char *argv[]) .map_x_offset = 0, .map_y_offset = 0, .ctx = backend->context, + .backend = backend, .map_elem_size = ELEM_SIZE, }; bogoman_render(&render, BOGOMAN_RENDER_ALL); - GP_BackendFlip(backend); - - for (;;) { - GP_BackendPoll(backend); - event_loop(map); - bogoman_render(&render, BOGOMAN_RENDER_DIRTY); - GP_BackendFlip(backend); + GP_BackendAddTimer(backend, &timer); - usleep(50000); + for (;;) { + GP_BackendWait(backend); + event_loop(&render, backend); } return 0; diff --git a/demos/bogoman/bogoman_loader.c b/demos/bogoman/bogoman_loader.c index 935bc3e3..e4e17c1d 100644 --- a/demos/bogoman/bogoman_loader.c +++ b/demos/bogoman/bogoman_loader.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -81,6 +81,15 @@ static enum bogoman_map_elem_id id_from_char(const char ch) return BOGOMAN_MOVEABLE; case 'E': return BOGOMAN_EDIBLE; + case '(': + case ')': + case 'O': + case 'o': + case '<': + case '>': + case '^': + case 'v': + return BOGOMAN_PARTICLE; } WARN("Unknown map character '%c'", ch); @@ -93,6 +102,7 @@ static enum bogoman_map_elem_id id_from_char(const char ch) struct line { unsigned int len; unsigned char line[LINE_MAX]; + unsigned char input[LINE_MAX]; }; static void get_line(FILE *f, struct line *l) @@ -106,6 +116,7 @@ static void get_line(FILE *f, struct line *l) case 'n': return; default: + l->input[l->len] = ch; l->line[l->len++] = id_from_char(ch); break; } @@ -140,19 +151,19 @@ static void load_map(FILE *f, struct bogoman_map *map) case BOGOMAN_WALL: if (x > 0 && line_cur->line[x - 1] == BOGOMAN_WALL) - elem->flags |= BOGOMAN_WALL_LEFT; + elem->flags |= BOGOMAN_LEFT; if (x + 1 < line_cur->len && line_cur->line[x + 1] == BOGOMAN_WALL) - elem->flags |= BOGOMAN_WALL_RIGHT; + elem->flags |= BOGOMAN_RIGHT; if (y > 0 && - bogoman_map_is_id(map, x, y-1, BOGOMAN_WALL)) - elem->flags |= BOGOMAN_WALL_UP; + bogoman_map_elem_id(map, x, y-1) == BOGOMAN_WALL) + elem->flags |= BOGOMAN_UP; if (x < line_next->len && line_next->line[x] == BOGOMAN_WALL) - elem->flags |= BOGOMAN_WALL_DOWN; + elem->flags |= BOGOMAN_DOWN; break; case BOGOMAN_PLAYER: @@ -168,6 +179,34 @@ static void load_map(FILE *f, struct bogoman_map *map) case BOGOMAN_DIAMOND: map->diamonds_total++; break; + case BOGOMAN_PARTICLE: + switch (line_cur->input[x]) { + case '(': + elem->flags = BOGOMAN_LEFT | BOGOMAN_PARTICLE_ROUND; + break; + case ')': + elem->flags = BOGOMAN_RIGHT | BOGOMAN_PARTICLE_ROUND; + break; + case 'O': + elem->flags = BOGOMAN_UP | BOGOMAN_PARTICLE_ROUND; + break; + case 'o': + elem->flags = BOGOMAN_DOWN | BOGOMAN_PARTICLE_ROUND; + break; + case '<': + elem->flags = BOGOMAN_LEFT | BOGOMAN_PARTICLE_SQUARE; + break; + case '>': + elem->flags = BOGOMAN_RIGHT | BOGOMAN_PARTICLE_SQUARE; + break; + case '^': + elem->flags = BOGOMAN_UP | BOGOMAN_PARTICLE_SQUARE; + break; + case 'v': + elem->flags = BOGOMAN_DOWN | BOGOMAN_PARTICLE_SQUARE; + break; + } + break; default: break; } diff --git a/demos/bogoman/bogoman_map.c b/demos/bogoman/bogoman_map.c index b9117441..2919fc00 100644 --- a/demos/bogoman/bogoman_map.c +++ b/demos/bogoman/bogoman_map.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -30,22 +30,22 @@ static void print_wall(struct bogoman_map_elem *elem) { switch (elem->flags) { - case BOGOMAN_WALL_LEFT: - case BOGOMAN_WALL_RIGHT: - case BOGOMAN_WALL_LEFT | BOGOMAN_WALL_RIGHT: + case BOGOMAN_LEFT: + case BOGOMAN_RIGHT: + case BOGOMAN_LEFT | BOGOMAN_RIGHT: printf("-"); break; - case BOGOMAN_WALL_UP: - case BOGOMAN_WALL_DOWN: - case BOGOMAN_WALL_UP | BOGOMAN_WALL_DOWN: + case BOGOMAN_UP: + case BOGOMAN_DOWN: + case BOGOMAN_UP | BOGOMAN_DOWN: printf("|"); break; - case BOGOMAN_WALL_UP | BOGOMAN_WALL_RIGHT: - case BOGOMAN_WALL_DOWN | BOGOMAN_WALL_LEFT: + case BOGOMAN_UP | BOGOMAN_RIGHT: + case BOGOMAN_DOWN | BOGOMAN_LEFT: printf("\"); break; - case BOGOMAN_WALL_UP | BOGOMAN_WALL_LEFT: - case BOGOMAN_WALL_DOWN | BOGOMAN_WALL_RIGHT: + case BOGOMAN_UP | BOGOMAN_LEFT: + case BOGOMAN_DOWN | BOGOMAN_RIGHT: printf("/"); break; default: @@ -54,6 +54,48 @@ static void print_wall(struct bogoman_map_elem *elem) } } +static void print_particle(struct bogoman_map_elem *elem) +{ + char c = '?'; + int dir = elem->flags & BOGOMAN_DIRECTION_MASK; + + if (elem->flags & BOGOMAN_PARTICLE_ROUND) { + switch (dir) { + case BOGOMAN_LEFT: + c = '('; + break; + case BOGOMAN_RIGHT: + c = ')'; + break; + case BOGOMAN_UP: + c = 'O'; + break; + case BOGOMAN_DOWN: + c = 'o'; + break; + } + } + + if (elem->flags & BOGOMAN_PARTICLE_SQUARE) { + switch (dir) { + case BOGOMAN_LEFT: + c = '<'; + break; + case BOGOMAN_RIGHT: + c = '>'; + break; + case BOGOMAN_UP: + c = '^'; + break; + case BOGOMAN_DOWN: + c = 'v'; + break; + } + } + + putchar(c); +} + void bogoman_map_dump(struct bogoman_map *map) { unsigned int x, y; @@ -83,6 +125,9 @@ void bogoman_map_dump(struct bogoman_map *map) case BOGOMAN_WALL: print_wall(elem); break; + case BOGOMAN_PARTICLE: + print_particle(elem); + break; } } @@ -139,8 +184,6 @@ static void move_get_diamond(struct bogoman_map *map, static int try_move_block(struct bogoman_map *map, int x, int y, int dx, int dy) { - struct bogoman_map_elem *elem = bogoman_get_map_elem(map, x, y); - int new_x = (int)x + dx; int new_y = (int)y + dy; @@ -194,6 +237,7 @@ void bogoman_map_player_move(struct bogoman_map *map, int x, int y) case BOGOMAN_DIAMOND: move_get_diamond(map, px, py); break; + case BOGOMAN_PARTICLE: case BOGOMAN_MOVEABLE: if (!try_move_block(map, px, py, dx, dy)) goto finish_move; @@ -231,15 +275,75 @@ finish_move: void bogoman_map_timer_tick(struct bogoman_map *map) { - unsigned int x, y; + unsigned int x, y, moved; + struct bogoman_map_elem *elem; for (y = 0; y < map->h; y++) { for (x = 0; x < map->w; x++) { struct bogoman_map_elem *elem; - elem = bogoman_get_map_elem(map, x, y); - - //TODO + elem->moved = 0; } } + + do { + moved = 0; + + for (y = 0; y < map->h; y++) { + for (x = 0; x < map->w; x++) { + int dir_x = 0, dir_y = 0; + elem = bogoman_get_map_elem(map, x, y); + + if (elem->id != BOGOMAN_PARTICLE) + continue; + + if (elem->moved) + continue; + + switch (elem->flags & BOGOMAN_DIRECTION_MASK) { + case BOGOMAN_LEFT: + dir_x = -1; + break; + case BOGOMAN_RIGHT: + dir_x = 1; + break; + case BOGOMAN_UP: + dir_y = -1; + break; + case BOGOMAN_DOWN: + dir_y = +1; + break; + default: + continue; + } + + if (!bogoman_is_empty(map, x + dir_x, y + dir_y)) { + if (!(elem->flags & BOGOMAN_PARTICLE_ROUND)) + continue; + + if (dir_x) { + //TODO randomly choose direction + if (bogoman_is_empty(map, x+dir_x, y-1)) + dir_y = -1; + if (bogoman_is_empty(map, x+dir_x, y+1)) + dir_y = 1; + } + + if (dir_y) { + if (bogoman_is_empty(map, x-1, y+dir_y)) + dir_x = -1; + if (bogoman_is_empty(map, x+1, y+dir_y)) + dir_x = 1; + } + + if (!dir_x || !dir_y) + continue; + } + + elem->moved = 1; + bogoman_switch(map, x, y, x + dir_x, y + dir_y); + moved++; + } + } + } while (moved); } diff --git a/demos/bogoman/bogoman_map.h b/demos/bogoman/bogoman_map.h index fe7c1f14..e4d3c096 100644 --- a/demos/bogoman/bogoman_map.h +++ b/demos/bogoman/bogoman_map.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -36,19 +36,27 @@ enum bogoman_map_elem_id { BOGOMAN_MOVEABLE = 0x04, /* like a diamond but doesn't counts to points */ BOGOMAN_EDIBLE = 0x05, + /* particles, move in defined direction unless stoppend by objects */ + BOGOMAN_PARTICLE = 0x06, - BOGOMAN_MAX = BOGOMAN_EDIBLE, + BOGOMAN_MAX = BOGOMAN_PARTICLE, }; /* - * Wall cal be applied as bitflags. Each bitflag determines wall continuation - * in particular direction. + * Lower 8 bits defines continuation for walls, direction for particles, etc. */ -enum bogoman_wall_flags { - BOGOMAN_WALL_LEFT = 0x01, - BOGOMAN_WALL_RIGHT = 0x02, - BOGOMAN_WALL_UP = 0x04, - BOGOMAN_WALL_DOWN = 0x08, +enum bogoman_direction_flags { + BOGOMAN_LEFT = 0x01, + BOGOMAN_RIGHT = 0x02, + BOGOMAN_UP = 0x04, + BOGOMAN_DOWN = 0x08, + + BOGOMAN_DIRECTION_MASK = 0x0f, +}; + +enum bogoman_particle_flags { + BOGOMAN_PARTICLE_ROUND = 0x10, + BOGOMAN_PARTICLE_SQUARE = 0x20, }; struct bogoman_map_elem { @@ -57,6 +65,7 @@ struct bogoman_map_elem { /* the element changed, needs to be redrawn */ unsigned char dirty:1; + unsigned char moved:1; }; struct bogoman_map { @@ -91,13 +100,13 @@ static inline enum bogoman_map_elem_id return elem->id; } -static inline int bogoman_map_is_id(struct bogoman_map *map, - unsigned int x, unsigned int y, - enum bogoman_map_elem_id id) +static inline enum bogoman_map_elem_id + bogoman_map_elem_id(struct bogoman_map *map, + unsigned int x, unsigned int y) { struct bogoman_map_elem *elem = bogoman_get_map_elem(map, x, y); - return elem->id == id; + return elem->id; } static inline int bogoman_coord_in_map(struct bogoman_map *map, int x, int y) @@ -106,12 +115,30 @@ static inline int bogoman_coord_in_map(struct bogoman_map *map, int x, int y) (y >= 0) && ((unsigned)y < map->w); } -static inline int bogoman_is_empty(struct bogoman_map *map, - unsigned int x, unsigned int y) +static inline int bogoman_is_empty(struct bogoman_map *map, int x, int y) { + if (!bogoman_coord_in_map(map, x, y)) + return 0; + return bogoman_get_map_elem_id(map, x, y) == BOGOMAN_NONE; } +static inline void bogoman_switch(struct bogoman_map *map, + int x1, int y1, int x2, int y2) +{ + struct bogoman_map_elem *i, *j, tmp; + + i = bogoman_get_map_elem(map, x1, y1); + j = bogoman_get_map_elem(map, x2, y2); + + tmp = *i; + *i = *j; + *j = tmp; + + i->dirty = 1; + j->dirty = 1; +} + void bogoman_map_player_move(struct bogoman_map *map, int x, int y); void bogoman_map_timer_tick(struct bogoman_map *map); diff --git a/demos/bogoman/bogoman_render.c b/demos/bogoman/bogoman_render.c index c2ebc10b..bc47f7d2 100644 --- a/demos/bogoman/bogoman_render.c +++ b/demos/bogoman/bogoman_render.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -48,19 +48,25 @@ struct render_colors { /* edible color */ GP_Pixel edible; + + /* particle colors */ + GP_Pixel particle; + GP_Pixel particle_dir; }; static struct render_colors colors; static void init_colors(GP_Context *ctx, struct render_colors *colors) { - colors->bg = GP_RGBToContextPixel(0xee, 0xee, 0xee, ctx); - colors->player = GP_RGBToContextPixel(0x00, 0xee, 0x00, ctx); - colors->frames = GP_RGBToContextPixel(0x00, 0x00, 0x00, ctx); - colors->diamond = GP_RGBToContextPixel(0x00, 0x00, 0xee, ctx); - colors->wall = GP_RGBToContextPixel(0x66, 0x66, 0x66, ctx); - colors->moveable = GP_RGBToContextPixel(0xff, 0xff, 0x60, ctx); - colors->edible = GP_RGBToContextPixel(0xff, 0x7f, 0x50, ctx); + colors->bg = GP_RGBToContextPixel(0xee, 0xee, 0xee, ctx); + colors->player = GP_RGBToContextPixel(0x00, 0xee, 0x00, ctx); + colors->frames = GP_RGBToContextPixel(0x00, 0x00, 0x00, ctx); + colors->diamond = GP_RGBToContextPixel(0x00, 0x00, 0xee, ctx); + colors->wall = GP_RGBToContextPixel(0x66, 0x66, 0x66, ctx); + colors->moveable = GP_RGBToContextPixel(0xff, 0xff, 0x60, ctx); + colors->edible = GP_RGBToContextPixel(0xff, 0x7f, 0x50, ctx); + colors->particle = GP_RGBToContextPixel(0xff, 0xff, 0x00, ctx); + colors->particle_dir = GP_RGBToContextPixel(0xff, 0x44, 0x00, ctx); } static void render_none(struct bogoman_render *render, @@ -83,8 +89,9 @@ static void render_player(struct bogoman_render *render, (void) elem; GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); + GP_FillCircle(render->ctx, x + w/2, y + w/2, w/2 - 1, colors.player); - GP_Circle(render->ctx, x + w/2, y + w/2, w/2 - 1, colors.frames); + GP_FillRing(render->ctx, x + w/2, y + w/2, w/2 - 1, w/2 - 2, colors.frames); } static void render_wall(struct bogoman_render *render, @@ -95,17 +102,25 @@ static void render_wall(struct bogoman_render *render, GP_FillRectXYWH(render->ctx, x, y, w, w, colors.wall); - if (!(elem->flags & BOGOMAN_WALL_LEFT)) + if (!(elem->flags & BOGOMAN_LEFT)) { GP_VLineXYH(render->ctx, x, y, w, colors.frames); + GP_VLineXYH(render->ctx, x+1, y, w, colors.frames); + } - if (!(elem->flags & BOGOMAN_WALL_RIGHT)) + if (!(elem->flags & BOGOMAN_RIGHT)) { GP_VLineXYH(render->ctx, x + w - 1, y, w, colors.frames); + GP_VLineXYH(render->ctx, x + w - 2, y, w, colors.frames); + } - if (!(elem->flags & BOGOMAN_WALL_UP)) + if (!(elem->flags & BOGOMAN_UP)) { GP_HLineXYW(render->ctx, x, y, w, colors.frames); + GP_HLineXYW(render->ctx, x, y+1, w, colors.frames); + } - if (!(elem->flags & BOGOMAN_WALL_DOWN)) + if (!(elem->flags & BOGOMAN_DOWN)) { GP_HLineXYW(render->ctx, x, y + w - 1, w, colors.frames); + GP_HLineXYW(render->ctx, x, y + w - 2, w, colors.frames); + } } static void render_diamond(struct bogoman_render *render, @@ -116,11 +131,15 @@ static void render_diamond(struct bogoman_render *render, GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); + (void) elem; + GP_FillTetragon(render->ctx, x + w/2, y, x + w - 1, y + w/2, x + w/2, y + w - 1, x, y + w/2, colors.diamond); GP_Tetragon(render->ctx, x + w/2, y, x + w - 1, y + w/2, x + w/2, y + w - 1, x, y + w/2, colors.frames); + GP_Tetragon(render->ctx, x + w/2, y+1, x + w - 2, y + w/2, + x + w/2, y + w - 2, x+1, y + w/2, colors.frames); } static void render_moveable(struct bogoman_render *render, @@ -129,10 +148,13 @@ static void render_moveable(struct bogoman_render *render, { unsigned int w = render->map_elem_size; + (void) elem; + GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); GP_FillRectXYWH(render->ctx, x + 1, y + 1, w - 2, w - 2, colors.moveable); GP_RectXYWH(render->ctx, x + 1, y + 1, w - 2, w - 2, colors.frames); + GP_RectXYWH(render->ctx, x + 2, y + 2, w - 4, w - 4, colors.frames); } static void render_edible(struct bogoman_render *render, @@ -141,11 +163,62 @@ static void render_edible(struct bogoman_render *render, { unsigned int w = render->map_elem_size; + (void) elem; + GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); GP_FillRectXYWH(render->ctx, x + 1, y + 1, w - 2, w - 2, colors.edible); } +static void render_particle(struct bogoman_render *render, + unsigned int x, unsigned int y, + struct bogoman_map_elem *elem) +{ + unsigned int w = render->map_elem_size; + int dir = elem->flags & BOGOMAN_DIRECTION_MASK; + + GP_FillRectXYWH(render->ctx, x, y, w, w, colors.bg); + + switch (elem->flags & ~BOGOMAN_DIRECTION_MASK) { + case BOGOMAN_PARTICLE_ROUND: + GP_FillCircle(render->ctx, x + w/2, y + w/2, w/2-1, colors.particle); + GP_FillRing(render->ctx, x + w/2, y + w/2, w/2 - 1, w/2 - 2, colors.frames); + break; + case BOGOMAN_PARTICLE_SQUARE: + GP_FillRectXYWH(render->ctx, x+1, y+1, w-2, w-2, colors.particle); + GP_RectXYWH(render->ctx, x+1, y+1, w-2, w-2, colors.frames); + GP_RectXYWH(render->ctx, x+2, y+2, w-4, w-4, colors.frames); + break; + } + + switch (dir) { + case BOGOMAN_LEFT: + GP_FillTriangle(render->ctx, x + w/4, y + w/2, + x + 5*w/8, y + w/4, x + 5*w/8, y + 3*w/4, colors.particle_dir); + GP_Triangle(render->ctx, x + w/4, y + w/2, + x + 5*w/8, y + w/4, x + 5*w/8, y + 3*w/4, colors.frames); + break; + case BOGOMAN_RIGHT: + GP_FillTriangle(render->ctx, x + 3*w/4, y + w/2, + x + 3*w/8, y + w/4, x + 3*w/8, y + 3*w/4, colors.particle_dir); + GP_Triangle(render->ctx, x + 3*w/4, y + w/2, + x + 3*w/8, y + w/4, x + 3*w/8, y + 3*w/4, colors.frames); + break; + case BOGOMAN_UP: + GP_FillTriangle(render->ctx, x + w/2, y + w/4, + x + w/4, y + 5*w/8, x + 3*w/4, y + 5*w/8, colors.particle_dir); + GP_Triangle(render->ctx, x + w/2, y + w/4, + x + w/4, y + 5*w/8, x + 3*w/4, y + 5*w/8, colors.frames); + break; + case BOGOMAN_DOWN: + GP_FillTriangle(render->ctx, x + w/2, y + 3*w/4, + x + w/4, y + 3*w/8, x + 3*w/4, y + 3*w/8, colors.particle_dir); + GP_Triangle(render->ctx, x + w/2, y + 3*w/4, + x + w/4, y + 3*w/8, x + 3*w/4, y + 3*w/8, colors.frames); + break; + } +} + static void (*renders[])(struct bogoman_render *render, unsigned int x, unsigned int y, struct bogoman_map_elem *elem) = @@ -156,6 +229,7 @@ static void (*renders[])(struct bogoman_render *render, render_diamond, render_moveable, render_edible, + render_particle, }; static void render_elem(struct bogoman_render *render, @@ -181,6 +255,12 @@ static void render_elem(struct bogoman_render *render, WARN("Invalid elem ID %u at %ux%un", elem->id, x, y); else renders[elem->id](render, cx, cy, elem); + + if (flags & BOGOMAN_RENDER_DIRTY && render->backend) { + GP_BackendUpdateRect(render->backend, cx, cy, + cx + render->map_elem_size, + cy + render->map_elem_size); + } } void bogoman_render(struct bogoman_render *render, int flags) @@ -190,9 +270,14 @@ void bogoman_render(struct bogoman_render *render, int flags) //TODO: Hack init_colors(render->ctx, &colors); + if (flags & BOGOMAN_RENDER_ALL) + GP_Fill(render->ctx, colors.bg); + for (y = render->map_x_offset; y < render->map->h; y++) { - for (x = render->map_x_offset; x < render->map->w; x++) { + for (x = render->map_x_offset; x < render->map->w; x++) render_elem(render, x, y, flags); - } } + + if (flags & BOGOMAN_RENDER_ALL && render->backend) + GP_BackendFlip(render->backend); } diff --git a/demos/bogoman/bogoman_render.h b/demos/bogoman/bogoman_render.h index f813cdc1..e27744e2 100644 --- a/demos/bogoman/bogoman_render.h +++ b/demos/bogoman/bogoman_render.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> * + * Copyright (C) 2009-2015 Cyril Hrubis <metan(a)ucw.cz> * * * *****************************************************************************/ @@ -37,14 +37,17 @@ struct bogoman_render { /* context to be used for rendering */ struct GP_Context *ctx; + /* if not NULL is used to update screen */ + struct GP_Backend *backend; + /* elem size in pixels */ unsigned int map_elem_size; }; enum bogonam_render_flags { /* renders all map elements, not only dirty ones */ - BOGOMAN_RENDER_ALL = 0x00, - BOGOMAN_RENDER_DIRTY = 0x01, + BOGOMAN_RENDER_ALL = 0x01, + BOGOMAN_RENDER_DIRTY = 0x02, }; void bogoman_render(struct bogoman_render *render, int flags); diff --git a/demos/bogoman/levels/02-paticles.txt b/demos/bogoman/levels/02-paticles.txt new file mode 100644 index 00000000..1c1dbf15 --- /dev/null +++ b/demos/bogoman/levels/02-paticles.txt @@ -0,0 +1,10 @@ +/------------+|$))))E @| +|)))))E | ++------ | +| | +++++-E-++ | ++++/OOO++ | +++/OOOOO+ | +++$$$$$$$| | ++-------+---/ diff --git a/demos/bogoman/map.txt b/demos/bogoman/map.txt index 337d07ca..3e360f91 100644 --- a/demos/bogoman/map.txt +++ b/demos/bogoman/map.txt @@ -1,8 +1,8 @@ +---------+ +----+ | | | | | $ | | +----+ | -| E @ | +|> E @ (<| +--M----------------+ | M | -| |$|$|$| | +|^v |$|$|$| | +----------+-+-+-+--+
http://repo.or.cz/w/gfxprim.git/commit/380af9d42b91493a3cb726a075279e29030b…
commit 380af9d42b91493a3cb726a075279e29030ba679 Author: Cyril Hrubis <metan(a)ucw.cz> Date: Thu Dec 25 19:19:32 2014 +0100 loaders: Loader: Implement missing functions * Implement GP_LoaderReadImageEx() * Add missing LoadImageEx for BMP, PSD and PSP Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt index 794755eb..0266e70d 100644 --- a/build/syms/Loaders_symbols.txt +++ b/build/syms/Loaders_symbols.txt @@ -20,15 +20,17 @@ GP_PNG GP_MatchBMP GP_WriteBMP GP_LoadBMP -GP_ReadBMPEx +GP_LoadBMPEx GP_ReadBMP +GP_ReadBMPEx GP_SaveBMP GP_BMP GP_MatchPSP GP_ReadPSP -GP_LoadPSP GP_ReadPSPEx +GP_LoadPSP +GP_LoadPSPEx GP_PSP GP_MatchGIF @@ -96,6 +98,7 @@ GP_PCX GP_ReadPSD GP_ReadPSDEx GP_LoadPSD +GP_LoadPSDEx GP_MatchPSD GP_PSD @@ -122,6 +125,7 @@ GP_LoaderRegister GP_LoaderUnregister GP_ContainerLoad +GP_ContainerLoadEx GP_ContainerSeek GP_MatchZip diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c index 84d7c97f..8b890f90 100644 --- a/libs/loaders/GP_BMP.c +++ b/libs/loaders/GP_BMP.c @@ -733,6 +733,12 @@ GP_Context *GP_LoadBMP(const char *src_path, GP_ProgressCallback *callback) return GP_LoaderLoadImage(&GP_BMP, src_path, callback); } +int GP_LoadBMPEx(const char *src_path, GP_Context **img, + GP_DataStorage *storage, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImageEx(&GP_BMP, src_path, img, storage, callback); +} + /* * Rows in bmp are four byte aligned. */ diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c index 8bc9caf1..84461f99 100644 --- a/libs/loaders/GP_Loader.c +++ b/libs/loaders/GP_Loader.c @@ -296,7 +296,7 @@ int GP_LoaderLoadImageEx(const GP_Loader *self, const char *src_path, if (!self->Read) { errno = ENOSYS; - return 1; + return ENOSYS; } io = GP_IOFile(src_path, GP_IO_RDONLY); @@ -328,19 +328,30 @@ GP_Context *GP_LoaderReadImage(const GP_Loader *self, GP_IO *io, { GP_Context *ret = NULL; + GP_LoaderReadImageEx(self, io, &ret, NULL, callback); + + return ret; +} + +int GP_LoaderReadImageEx(const GP_Loader *self, GP_IO *io, + GP_Context **img, GP_DataStorage *data, + GP_ProgressCallback *callback) +{ GP_DEBUG(1, "Reading image (I/O %p)", io); - self->Read(io, &ret, NULL, callback); + if (!self->Read) { + errno = ENOSYS; + return ENOSYS; + } - return ret; + return self->Read(io, img, data, callback); } GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback) { - GP_Context *ret; + GP_Context *ret = NULL; - if (GP_LoadImageEx(src_path, &ret, NULL, callback)) - return NULL; + GP_LoadImageEx(src_path, &ret, NULL, callback); return ret; } diff --git a/libs/loaders/GP_PSD.c b/libs/loaders/GP_PSD.c index 0f3970a8..c6308113 100644 --- a/libs/loaders/GP_PSD.c +++ b/libs/loaders/GP_PSD.c @@ -843,6 +843,12 @@ GP_Context *GP_ReadPSD(GP_IO *io, GP_ProgressCallback *callback) return GP_LoaderReadImage(&GP_PSD, io, callback); } +int GP_LoadPSDEx(const char *src_path, GP_Context **img, + GP_DataStorage *storage, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImageEx(&GP_PSD, src_path, img, storage, callback); +} + struct GP_Loader GP_PSD = { .Read = GP_ReadPSDEx, .Match = GP_MatchPSD, diff --git a/libs/loaders/GP_PSP.c b/libs/loaders/GP_PSP.c index 2ace2619..02041632 100644 --- a/libs/loaders/GP_PSP.c +++ b/libs/loaders/GP_PSP.c @@ -524,6 +524,12 @@ GP_Context *GP_ReadPSP(GP_IO *io, GP_ProgressCallback *callback) return GP_LoaderReadImage(&GP_PSP, io, callback); } +int GP_LoadPSPEx(const char *src_path, GP_Context **img, + GP_DataStorage *storage, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImageEx(&GP_PSP, src_path, img, storage, callback); +} + struct GP_Loader GP_PSP = { .Read = GP_ReadPSPEx, .Match = GP_MatchPSP,
http://repo.or.cz/w/gfxprim.git/commit/69fbdb92d0f48c5d030d2cc0cb0c475b7546…
commit 69fbdb92d0f48c5d030d2cc0cb0c475b75464774 Author: Cyril Hrubis <metan(a)ucw.cz> Date: Thu Dec 25 19:08:36 2014 +0100 loaders: PSP: Add some more metadata. Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/libs/loaders/GP_PSP.c b/libs/loaders/GP_PSP.c index 74936f37..2ace2619 100644 --- a/libs/loaders/GP_PSP.c +++ b/libs/loaders/GP_PSP.c @@ -173,8 +173,19 @@ struct psp_img_attrs { uint8_t subblock; void *priv; GP_Context *img; + GP_DataStorage *storage; }; +static void fill_metadata(struct psp_img_attrs *attrs) +{ + GP_DataStorageAddInt(attrs->storage, NULL, "Width", attrs->w); + GP_DataStorageAddInt(attrs->storage, NULL, "Height", attrs->h); + GP_DataStorageAddString(attrs->storage, NULL, "Compression", + psp_comp_type_name(attrs->comp_type)); + GP_DataStorageAddInt(attrs->storage, NULL, "Bit Depth", + attrs->bit_depth); +} + static int psp_read_general_img_attr_chunk(GP_IO *io, struct psp_img_attrs *attrs) { @@ -220,10 +231,13 @@ static int psp_read_general_img_attr_chunk(GP_IO *io, attrs->bit_depth, attrs->grayscale_flag); GP_DEBUG(3, "Image colors=%u, layer_count=%u, active_layer=%u", - attrs->color_count, attrs->layer_count, attrs->active_layer); + attrs->color_count, attrs->layer_count, attrs->active_layer); attrs->is_loaded = 1; + if (attrs->storage) + fill_metadata(attrs); + return 0; } @@ -449,7 +463,7 @@ int GP_ReadPSPEx(GP_IO *io, GP_Context **img, GP_DataStorage *storage, { int err = 0; struct psp_img_attrs attrs = {.is_loaded = 0, .subblock = 0, - .priv = NULL, .img = NULL}; + .priv = NULL, .img = NULL, .storage = storage}; struct psp_version version; uint16_t psp_header[] = {
http://repo.or.cz/w/gfxprim.git/commit/80386afaf5cbd6c805140ae1e0f8e3791866…
commit 80386afaf5cbd6c805140ae1e0f8e37918666e23 Author: Cyril Hrubis <metan(a)ucw.cz> Date: Thu Dec 25 18:21:17 2014 +0100 demos: zip_container: Use clipped blit. Otherwise the example fails on assert() in GP_Blit.c when image is larger than screen window. Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/demos/c_simple/zip_container.c b/demos/c_simple/zip_container.c index 6e241087..1fe5e36f 100644 --- a/demos/c_simple/zip_container.c +++ b/demos/c_simple/zip_container.c @@ -58,7 +58,7 @@ static void load_next(void) return; } - GP_Blit(image, 0, 0, image->w, image->h, backend->context, 0, 0); + GP_Blit_Clipped(image, 0, 0, image->w, image->h, backend->context, 0, 0); GP_BackendFlip(backend); } @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) } /* Blit image into the window and show it */ - GP_Blit(image, 0, 0, image->w, image->h, backend->context, 0, 0); + GP_Blit_Clipped(image, 0, 0, image->w, image->h, backend->context, 0, 0); GP_BackendFlip(backend); /* Wait for events */ @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) case GP_EV_SYS: if (ev.code == GP_EV_SYS_RESIZE) { GP_BackendResizeAck(backend); - GP_Blit(image, 0, 0, image->w, image->h, + GP_Blit_Clipped(image, 0, 0, image->w, image->h, backend->context, 0, 0); GP_BackendFlip(backend); }
http://repo.or.cz/w/gfxprim.git/commit/aefa0cab17b7f75cada9bc97678055313642…
commit aefa0cab17b7f75cada9bc97678055313642e1e6 Author: Cyril Hrubis <metan(a)ucw.cz> Date: Wed Dec 24 16:11:25 2014 +0100 Exif: Fix segfault on loading empty string. Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/libs/loaders/GP_Exif.c b/libs/loaders/GP_Exif.c index b401fc97..f9365893 100644 --- a/libs/loaders/GP_Exif.c +++ b/libs/loaders/GP_Exif.c @@ -341,7 +341,7 @@ static int load_string(GP_IO *io, GP_DataStorage *storage, GP_DataNode *node, /* Short strings are stored in the value directly */ if (num_comp <= 4) { memcpy(buf, val, num_comp); - buf[num_comp - 1] = 0; + buf[num_comp > 0 ? num_comp - 1 : num_comp] = 0; goto add; } @@ -351,9 +351,9 @@ static int load_string(GP_IO *io, GP_DataStorage *storage, GP_DataNode *node, buf[max_len - 1] = '0'; +add: GP_DEBUG(2, "ASCII String value = '%s'", buf); -add: return GP_DataStorageAddString(storage, node, id, buf) != NULL; }
http://repo.or.cz/w/gfxprim.git/commit/9af41a3215a074981988fbcf5ed8c1f45739…
commit 9af41a3215a074981988fbcf5ed8c1f45739b9d4 Author: Cyril Hrubis <metan(a)ucw.cz> Date: Wed Dec 24 13:42:08 2014 +0100 loaders: Add some metadata for JPG and PNM. Signed-off-by: Cyril Hrubis <metan(a)ucw.cz> diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c index 386370fd..4921f246 100644 --- a/libs/loaders/GP_JPG.c +++ b/libs/loaders/GP_JPG.c @@ -207,6 +207,12 @@ static void read_jpg_metadata(struct jpeg_decompress_struct *cinfo, { jpeg_saved_marker_ptr marker; + GP_DataStorageAddInt(storage, NULL, "Width", cinfo->image_width); + GP_DataStorageAddInt(storage, NULL, "Height", cinfo->image_height); + GP_DataStorageAddInt(storage, NULL, "Channels", cinfo->num_components); + GP_DataStorageAddString(storage, NULL, "Color Space", + get_colorspace(cinfo->out_color_space)); + for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) { switch (marker->marker) { case JPEG_COM: { diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c index 588d4300..a9003da1 100644 --- a/libs/loaders/GP_PNM.c +++ b/libs/loaders/GP_PNM.c @@ -700,6 +700,17 @@ err0: return 1; } +static void fill_meta_data(struct pnm_header *header, GP_DataStorage *storage) +{ + if (!storage) + return; + + GP_DataStorageAddInt(storage, NULL, "Width", header->w); + GP_DataStorageAddInt(storage, NULL, "Height", header->h); + GP_DataStorageAddInt(storage, NULL, "Depth", header->depth); + GP_DataStorageAddString(storage, NULL, "Format", pnm_magic_name(header->magic)); +} + int GP_ReadPBMEx(GP_IO *io, GP_Context **img, GP_DataStorage *storage, GP_ProgressCallback *callback) { @@ -707,14 +718,14 @@ int GP_ReadPBMEx(GP_IO *io, GP_Context **img, GP_DataStorage *storage, DECLARE_BUFFER(buf, io); int err; - (void) storage; - err = load_header(&buf, &header); if (err) { errno = err; return 1; } + fill_meta_data(&header, storage); + if (!img) return 0; @@ -864,14 +875,14 @@ int GP_ReadPGMEx(GP_IO *io, GP_Context **img, GP_DataStorage *storage, DECLARE_BUFFER(buf, io); int err; - (void) storage; - err = load_header(&buf, &header); if (err) { errno = err; return 1; } + fill_meta_data(&header, storage); + if (!img) return 0; @@ -990,14 +1001,14 @@ int GP_ReadPPMEx(GP_IO *io, GP_Context **img, GP_DataStorage *storage, DECLARE_BUFFER(buf, io); int err; - (void) storage; - err = load_header(&buf, &header); if (err) { errno = err; return 1; } + fill_meta_data(&header, storage); + if (!img) return 0; @@ -1116,14 +1127,14 @@ int GP_ReadPNMEx(GP_IO *io, GP_Context **img, GP_DataStorage *storage, DECLARE_BUFFER(buf, io); int err, ret = 1; - (void) storage; - err = load_header(&buf, &header); if (err) { errno = err; return 1; } + fill_meta_data(&header, storage); + if (!img) return 0; ----------------------------------------------------------------------- Summary of changes: build/syms/Filters_symbols.txt | 25 +--- build/syms/Loaders_symbols.txt | 11 +- demos/bogoman/bogoman.c | 35 +++-- demos/bogoman/bogoman_loader.c | 51 +++++- demos/bogoman/bogoman_map.c | 138 +++++++++++++-- demos/bogoman/bogoman_map.h | 57 +++++-- demos/bogoman/bogoman_render.c | 115 +++++++++++-- demos/bogoman/bogoman_render.h | 9 +- demos/bogoman/levels/02-paticles.txt | 10 + demos/bogoman/map.txt | 4 +- demos/c_simple/Makefile | 3 +- demos/c_simple/tmp_file.c | 110 ------------ demos/c_simple/zip_container.c | 6 +- demos/grinder/histogram.c | 28 ++-- doc/pixels.txt | 8 + include/core/GP_Pixel.h | 21 ++- include/filters/GP_Filter.h | 2 - include/filters/GP_FilterParam.h | 167 ----------------- include/filters/GP_Filters.h | 3 - include/filters/GP_Stats.h | 41 +++-- include/loaders/GP_Container.h | 19 ++- include/loaders/GP_Loaders.h | 2 - include/loaders/GP_TmpFile.h | 58 ------ libs/filters/GP_FilterParam.c | 257 --------------------------- libs/filters/{GP_Stats.c => GP_Histogram.c} | 90 +++++----- libs/filters/GP_Histogram.gen.c.t | 73 ++++++-- libs/loaders/GP_BMP.c | 6 + libs/loaders/GP_Container.c | 12 +- libs/loaders/GP_Exif.c | 4 +- libs/loaders/GP_JPG.c | 6 + libs/loaders/GP_Loader.c | 23 ++- libs/loaders/GP_PNM.c | 27 ++- libs/loaders/GP_PSD.c | 6 + libs/loaders/GP_PSP.c | 24 +++- libs/loaders/GP_TmpFile.c | 183 ------------------- libs/loaders/GP_ZIP.c | 89 +++++----- 36 files changed, 669 insertions(+), 1054 deletions(-) create mode 100644 demos/bogoman/levels/02-paticles.txt delete mode 100644 demos/c_simple/tmp_file.c delete mode 100644 include/filters/GP_FilterParam.h delete mode 100644 include/loaders/GP_TmpFile.h delete mode 100644 libs/filters/GP_FilterParam.c rename libs/filters/{GP_Stats.c => GP_Histogram.c} (53%) delete mode 100644 libs/loaders/GP_TmpFile.c repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive no reply. -- gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
0
0
Results per page:
10
25
50
100
200