Skip to content

Commit

Permalink
Separate ImageFormat and ImageFormatIndicies headers so library users…
Browse files Browse the repository at this point in the history
… independent of glib macros.
  • Loading branch information
bootchk committed Oct 28, 2015
1 parent a337b10 commit aecd48e
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 54 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -0,0 +1 @@
language: c
2 changes: 2 additions & 0 deletions lib/engine.c
Expand Up @@ -99,6 +99,8 @@ It doesn't make tiles in the target, it makes a target that is suitable as a til

// True header files
#include "imageFormat.h"
#include "imageFormatIndicies.h"

#include "map.h"
#include "engineParams.h"
#include "engine.h"
Expand Down
4 changes: 4 additions & 0 deletions lib/imageBuffer.h
Expand Up @@ -6,6 +6,9 @@ Interpretation of pixels (order and count of pixelels (unsigned bytes)) is given
Rows padded.
*/

#ifndef __SYNTH_IMAGE_BUFFER_H__
#define __SYNTH_IMAGE_BUFFER_H__

typedef struct _ImageBuffer
{
unsigned char * data; // data must be sequential RGBA for image, sequence of bytes for a mask
Expand All @@ -17,3 +20,4 @@ ImageBuffer;

// Mask same as image except only one pixelel per pixel (different, or assumed format code of on pixelel per pixel.)

#endif
1 change: 1 addition & 0 deletions lib/imageFormat.c
Expand Up @@ -34,6 +34,7 @@ The internal Pixel aggregates color, mask, and map pixelels; for memory locality
#include "imageSynthConstants.h"
#include "engineParams.h"
#include "imageFormat.h"
#include "imageFormatIndicies.h"

extern unsigned int
countPixelelsPerPixelForFormat(
Expand Down
56 changes: 3 additions & 53 deletions lib/imageFormat.h
Expand Up @@ -30,66 +30,16 @@ Not depend on Gimp
#ifndef __SYNTH_IMAGE_FORMAT_H__
#define __SYNTH_IMAGE_FORMAT_H__

// Enumerates different layouts of pixelels within pixels, for in images
// This type is exported, needed by callers of library
// The library lays pixelels out in its own internal format
typedef enum ImageFormat
{
T_RGB,
T_RGBA,
T_Gray,
T_GrayA
} TImageFormat;

/*
bpp i.e. count of bytes (channels) per pixel or index thereof.
bpp is bytes per pixel
bip is byte index within pixel.
See data layout in resynth_types.h
*/
typedef unsigned char TPixelelIndex;

/*
Struct of indices of pixelels within pixels in internal image format.
Also flags.
One is used for the target, one for the source.
*/
typedef struct indicesStruct {
TPixelelIndex colorEndBip; /* Index of last color pixelels in target/context image. */
TPixelelIndex alpha_bip; /* Index of target alpha pixelel */
TPixelelIndex map_start_bip; /* Index of map pixelels */
TPixelelIndex map_end_bip;

TPixelelIndex img_match_bpp; /* bpp to match in image. */
TPixelelIndex map_match_bpp; /* bpp to match in map. */
TPixelelIndex total_bpp; /* Total pixelels */

gboolean isAlphaTarget; // Does target have alpha?
gboolean isAlphaSource; // Does source have alpha?
} TFormatIndices;

extern unsigned int
countPixelelsPerPixelForFormat(
TImageFormat format // IN
);

extern int
prepareImageFormatIndicesFromFormatType(
TFormatIndices* indices, // OUT
TImageFormat format // IN
);

extern void
prepareImageFormatIndices(
TFormatIndices* indices, // OUT
guint count_color_channels_target, // Must be same count in source
guint count_color_channels_map,
gboolean is_alpha_target,
gboolean is_alpha_source,
gboolean isMap
);

extern void
prepareDefaultFormatIndices(
TFormatIndices* formatIndices
);

#endif /* __SYNTH_IMAGE_FORMAT_H__ */

87 changes: 87 additions & 0 deletions lib/imageFormatIndicies.h
@@ -0,0 +1,87 @@
/*
Prepare indices into our pixel format.
Synthesizer engine pixel contains mask pixelel and map pixelels
(Not just the color and alpha pixelels.)
IN: Image format (RGB, RGBA, Grey, etc.)
OUT: global index variables.
Not depend on Gimp
Copyright (C) 2010, 2011 Lloyd Konneker
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


#ifndef __SYNTH_IMAGE_FORMAT_INDICIES_H__
#define __SYNTH_IMAGE_FORMAT_INDICIES_H__

/*
bpp i.e. count of bytes (channels) per pixel or index thereof.
bpp is bytes per pixel
bip is byte index within pixel.
See data layout in resynth_types.h
*/
typedef unsigned char TPixelelIndex;

/*
Struct of indices of pixelels within pixels in internal image format.
Also flags.
One is used for the target, one for the source.
*/
typedef struct indicesStruct {
TPixelelIndex colorEndBip; /* Index of last color pixelels in target/context image. */
TPixelelIndex alpha_bip; /* Index of target alpha pixelel */
TPixelelIndex map_start_bip; /* Index of map pixelels */
TPixelelIndex map_end_bip;

TPixelelIndex img_match_bpp; /* bpp to match in image. */
TPixelelIndex map_match_bpp; /* bpp to match in map. */
TPixelelIndex total_bpp; /* Total pixelels */

gboolean isAlphaTarget; // Does target have alpha?
gboolean isAlphaSource; // Does source have alpha?
} TFormatIndices;

extern unsigned int
countPixelelsPerPixelForFormat(
TImageFormat format // IN
);

extern int
prepareImageFormatIndicesFromFormatType(
TFormatIndices* indices, // OUT
TImageFormat format // IN
);

extern void
prepareImageFormatIndices(
TFormatIndices* indices, // OUT
guint count_color_channels_target, // Must be same count in source
guint count_color_channels_map,
gboolean is_alpha_target,
gboolean is_alpha_source,
gboolean isMap
);

extern void
prepareDefaultFormatIndices(
TFormatIndices* formatIndices
);

#endif /* __SYNTH_IMAGE_FORMAT_H__ */

1 change: 1 addition & 0 deletions lib/imageSynth.c
Expand Up @@ -45,6 +45,7 @@ To make:
#include "glibProxy.h" // glibProxy.c

#include "imageFormat.h"
#include "imageFormatIndicies.h"
#include "map.h" // header for mapOps.h included by engine.c
#include "engineParams.h" // engineParams.c
#include "engine.h" // engine.c
Expand Down
3 changes: 2 additions & 1 deletion lib/imageSynth.h
Expand Up @@ -22,9 +22,10 @@ Header for the simple API to libresynthesizer
// The full API takes two images (target and corpus) and can do many things.
// The simple API munges one image into two and calls the full API.

// Type defs of struct you must pass
// Type defs of structs passed to imageSynth()
#include "imageBuffer.h"
#include "imageFormat.h"
#include "engineParams.h"

// Signature of the only simple API function
int
Expand Down
1 change: 1 addition & 0 deletions src/resynthesizer/resynthesizer.c
Expand Up @@ -91,6 +91,7 @@ Types, etc. from resynthesizer (image_synth) library
#include "glibProxy.h"
#endif
#include "imageFormat.h"
#include "imageFormatIndicies.h"
#include "map.h"
#include "engineParams.h"
#include "engine.h" // requires map.h
Expand Down

0 comments on commit aecd48e

Please sign in to comment.