Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2011-02-27 09:19:40 +0300
committerJoseph Eagar <joeedh@gmail.com>2011-02-27 09:19:40 +0300
commitf01261d040be27337db9f9996d648a279c89b7c4 (patch)
treec448230939b3c90d53ce8852dd00925d6052e3a4 /source/blender/blenlib
parentdcaeda5c4e3a0687251b8511de4f2e8b85ef75c0 (diff)
parent2198cfdb2deec8b2e85e242c74a032f43d0b26ca (diff)
merge with/from trunk at r35190
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_args.h21
-rw-r--r--source/blender/blenlib/BLI_bfile.h143
-rw-r--r--source/blender/blenlib/BLI_blenlib.h20
-rw-r--r--source/blender/blenlib/BLI_boxpack2d.h35
-rw-r--r--source/blender/blenlib/BLI_bpath.h54
-rw-r--r--source/blender/blenlib/BLI_cellalloc.h4
-rw-r--r--source/blender/blenlib/BLI_cpu.h5
-rw-r--r--source/blender/blenlib/BLI_dlrbTree.h7
-rw-r--r--source/blender/blenlib/BLI_dynstr.h26
-rw-r--r--source/blender/blenlib/BLI_edgehash.h10
-rw-r--r--source/blender/blenlib/BLI_editVert.h17
-rw-r--r--source/blender/blenlib/BLI_fileops.h42
-rw-r--r--source/blender/blenlib/BLI_fnmatch.h5
-rw-r--r--source/blender/blenlib/BLI_ghash.h38
-rw-r--r--source/blender/blenlib/BLI_graph.h4
-rw-r--r--source/blender/blenlib/BLI_gsqueue.h9
-rw-r--r--source/blender/blenlib/BLI_heap.h9
-rw-r--r--source/blender/blenlib/BLI_jitter.h12
-rw-r--r--source/blender/blenlib/BLI_kdopbvh.h11
-rw-r--r--source/blender/blenlib/BLI_kdtree.h11
-rw-r--r--source/blender/blenlib/BLI_linklist.h10
-rw-r--r--source/blender/blenlib/BLI_listbase.h23
-rw-r--r--source/blender/blenlib/BLI_math.h49
-rw-r--r--source/blender/blenlib/BLI_math_base.h33
-rw-r--r--source/blender/blenlib/BLI_math_color.h28
-rw-r--r--source/blender/blenlib/BLI_math_geom.h29
-rw-r--r--source/blender/blenlib/BLI_math_inline.h10
-rw-r--r--source/blender/blenlib/BLI_math_matrix.h40
-rw-r--r--source/blender/blenlib/BLI_math_rotation.h86
-rw-r--r--source/blender/blenlib/BLI_math_vector.h76
-rw-r--r--source/blender/blenlib/BLI_memarena.h10
-rw-r--r--source/blender/blenlib/BLI_mempool.h20
-rw-r--r--source/blender/blenlib/BLI_noise.h5
-rw-r--r--source/blender/blenlib/BLI_path_util.h39
-rw-r--r--source/blender/blenlib/BLI_pbvh.h11
-rw-r--r--source/blender/blenlib/BLI_rand.h18
-rw-r--r--source/blender/blenlib/BLI_rect.h4
-rw-r--r--source/blender/blenlib/BLI_scanfill.h17
-rwxr-xr-xsource/blender/blenlib/BLI_smallhash.h2
-rw-r--r--source/blender/blenlib/BLI_storage.h35
-rw-r--r--source/blender/blenlib/BLI_storage_types.h29
-rw-r--r--source/blender/blenlib/BLI_string.h34
-rw-r--r--source/blender/blenlib/BLI_threads.h6
-rw-r--r--source/blender/blenlib/BLI_utildefines.h227
-rw-r--r--source/blender/blenlib/BLI_uvproject.h6
-rw-r--r--source/blender/blenlib/BLI_vfontdata.h13
-rw-r--r--source/blender/blenlib/BLI_voxel.h9
-rw-r--r--source/blender/blenlib/BLI_winstuff.h30
-rw-r--r--source/blender/blenlib/CMakeLists.txt131
-rw-r--r--source/blender/blenlib/Makefile34
-rw-r--r--source/blender/blenlib/PIL_dynlib.h4
-rw-r--r--source/blender/blenlib/PIL_time.h2
-rw-r--r--source/blender/blenlib/SConscript9
-rw-r--r--source/blender/blenlib/intern/BLI_args.c47
-rw-r--r--source/blender/blenlib/intern/BLI_bfile.c372
-rw-r--r--source/blender/blenlib/intern/BLI_callbacks.h4
-rw-r--r--source/blender/blenlib/intern/BLI_cellalloc.c9
-rw-r--r--source/blender/blenlib/intern/BLI_dynstr.c38
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c19
-rw-r--r--source/blender/blenlib/intern/BLI_heap.c4
-rw-r--r--source/blender/blenlib/intern/BLI_kdopbvh.c20
-rw-r--r--source/blender/blenlib/intern/BLI_kdtree.c7
-rw-r--r--source/blender/blenlib/intern/BLI_linklist.c2
-rw-r--r--source/blender/blenlib/intern/BLI_memarena.c2
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c31
-rw-r--r--source/blender/blenlib/intern/DLRB_tree.c2
-rw-r--r--source/blender/blenlib/intern/Makefile62
-rw-r--r--source/blender/blenlib/intern/boxpack2d.c41
-rw-r--r--source/blender/blenlib/intern/bpath.c560
-rw-r--r--source/blender/blenlib/intern/cpu.c2
-rw-r--r--source/blender/blenlib/intern/dynamiclist.h2
-rw-r--r--source/blender/blenlib/intern/dynlib.c9
-rw-r--r--source/blender/blenlib/intern/edgehash.c2
-rw-r--r--source/blender/blenlib/intern/fileops.c110
-rw-r--r--source/blender/blenlib/intern/freetypefont.c26
-rw-r--r--source/blender/blenlib/intern/graph.c15
-rw-r--r--source/blender/blenlib/intern/gsqueue.c2
-rw-r--r--source/blender/blenlib/intern/jitter.c3
-rw-r--r--source/blender/blenlib/intern/listbase.c62
-rw-r--r--source/blender/blenlib/intern/math_base.c5
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c13
-rw-r--r--source/blender/blenlib/intern/math_color.c79
-rw-r--r--source/blender/blenlib/intern/math_geom.c267
-rw-r--r--source/blender/blenlib/intern/math_geom_inline.c8
-rw-r--r--source/blender/blenlib/intern/math_matrix.c181
-rw-r--r--source/blender/blenlib/intern/math_rotation.c337
-rw-r--r--source/blender/blenlib/intern/math_vector.c154
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c83
-rw-r--r--source/blender/blenlib/intern/noise.c16
-rw-r--r--source/blender/blenlib/intern/path_util.c523
-rw-r--r--source/blender/blenlib/intern/pbvh.c34
-rw-r--r--source/blender/blenlib/intern/rand.c2
-rw-r--r--source/blender/blenlib/intern/rct.c3
-rw-r--r--source/blender/blenlib/intern/scanfill.c33
-rw-r--r--source/blender/blenlib/intern/storage.c55
-rw-r--r--source/blender/blenlib/intern/string.c11
-rw-r--r--source/blender/blenlib/intern/threads.c6
-rw-r--r--source/blender/blenlib/intern/time.c5
-rw-r--r--source/blender/blenlib/intern/uvproject.c7
-rw-r--r--source/blender/blenlib/intern/voxel.c5
-rw-r--r--source/blender/blenlib/intern/winstuff.c9
101 files changed, 2882 insertions, 1969 deletions
diff --git a/source/blender/blenlib/BLI_args.h b/source/blender/blenlib/BLI_args.h
index cc4d65980c9..4cdb35dd675 100644
--- a/source/blender/blenlib/BLI_args.h
+++ b/source/blender/blenlib/BLI_args.h
@@ -1,6 +1,4 @@
-/**
- * A general argument parsing module
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -32,28 +30,33 @@
#ifndef BLI_ARGS_H
#define BLI_ARGS_H
+/** \file BLI_args.h
+ * \ingroup bli
+ * \brief A general argument parsing module.
+ */
+
struct bArgs;
typedef struct bArgs bArgs;
/* returns the number of extra arguments consumed by the function. 0 is normal value, -1 stops parsing arguments, other negative indicates skip */
-typedef int (*BA_ArgCallback)(int argc, char **argv, void *data);
+typedef int (*BA_ArgCallback)(int argc, const char **argv, void *data);
-struct bArgs *BLI_argsInit(int argc, char **argv);
+struct bArgs *BLI_argsInit(int argc, const char **argv);
void BLI_argsFree(struct bArgs *ba);
/* pass starts at 1, -1 means valid all the time
* short_arg or long_arg can be null to specify no short or long versions
* */
-void BLI_argsAdd(struct bArgs *ba, int pass, char *short_arg, char *long_arg, char *doc, BA_ArgCallback cb, void *data);
+void BLI_argsAdd(struct bArgs *ba, int pass, const char *short_arg, const char *long_arg, const char *doc, BA_ArgCallback cb, void *data);
/* short_case and long_case specify if those arguments are case specific */
-void BLI_argsAddCase(struct bArgs *ba, int pass, char *short_arg, int short_case, char *long_arg, int long_case, char *doc, BA_ArgCallback cb, void *data);
+void BLI_argsAddCase(struct bArgs *ba, int pass, const char *short_arg, int short_case, const char *long_arg, int long_case, const char *doc, BA_ArgCallback cb, void *data);
void BLI_argsParse(struct bArgs *ba, int pass, BA_ArgCallback default_cb, void *data);
-void BLI_argsPrintArgDoc(struct bArgs *ba, char *arg);
+void BLI_argsPrintArgDoc(struct bArgs *ba, const char *arg);
void BLI_argsPrintOtherDoc(struct bArgs *ba);
void BLI_argsPrint(struct bArgs *ba);
-char **BLI_argsArgv(struct bArgs *ba);
+const char **BLI_argsArgv(struct bArgs *ba);
#endif
diff --git a/source/blender/blenlib/BLI_bfile.h b/source/blender/blenlib/BLI_bfile.h
deleted file mode 100644
index 71e771fb4fa..00000000000
--- a/source/blender/blenlib/BLI_bfile.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/* -*- indent-tabs-mode:t; tab-width:4; -*-
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 by Stichting Blender Foundation.
- * All rights reserved.
- *
- * ***** END GPL LICENSE BLOCK *****
- * BFILE* based abstraction of file access.
- */
-
-#ifndef BLI_BFILE_H
-#define BLI_BFILE_H
-
-/* For fopen's FILE */
-#include <stdio.h>
-
-/**
- Defines for the bflags param.
- */
-/* Special handling, pick one of: */
-/* For "symmetry" of flags */
-#define BFILE_NORMAL (0)
-/* No supervision, just translate // if needed, RISKY */
-#define BFILE_RAW (1<<0)
-/* Path is for current session temp files */
-#define BFILE_TEMP (1<<1)
-/* Path is based in env vars of matching name */
-#define BFILE_CONFIG_BASE (1<<2)
-#define BFILE_CONFIG_DATAFILES (1<<3)
-#define BFILE_CONFIG_PYTHON (1<<4)
-#define BFILE_CONFIG_PLUGINS (1<<5)
-
-/* Config handling, special cases: */
-#define BFILE_USERONLY (1<<6)
-#define BFILE_SYSONLY (1<<7)
-
-/* Compression to apply on close: */
-#define BFILE_GZIP (1<<8)
-#define BFILE_LZMA (1<<9)
-
-/**
- File descriptor for Blender abstracted file access.
- */
-typedef struct {
- FILE *stream;
- int fd;
-
- /* Anything below should not be touched directly */
- int uflags; /* Special options requested by upper level, copy of bflags */
- char *fpath; /* Final/requested path name */
- char *tpath; /* Temp path name if applicable */
- int classf; /* Own flags, common classification of open and fopen */
- int error; /* An op caused an error, unsafe to replace older files */
-} BFILE;
-
-/**
- Open a BFILE* with fopen()-like syntax.
- */
-BFILE *BLI_bfile_fopen(const char *path, const char *mode, int bflags, const char *relpath);
-
-/**
- Open a BFILE* with open()-like syntax.
- */
-BFILE *BLI_bfile_open(const char *pathname, int flags, int bflags, const char *relpath);
-
-/**
- Get the FILE* associated with the BFILE*.
- */
-FILE *BLI_bfile_file_from_bfile(BFILE *bfile);
-
-/**
- Get the fd associated with the BFILE*.
- */
-int BLI_bfile_fd_from_bfile(BFILE *bfile);
-
-/**
- write()-like using BFILE*.
- */
-ssize_t BLI_bfile_write(BFILE *f, const void *buf, size_t count);
-
-/**
- read()-like using BFILE*.
- */
-ssize_t BLI_bfile_read(BFILE *f, void *buf, size_t count);
-
-/**
- fwrite()-like using BFILE*.
- */
-size_t BLI_bfile_fwrite(const void *ptr, size_t size, size_t nmemb, BFILE *f);
-
-/**
- fread()-like using BFILE*.
- */
-size_t BLI_bfile_fread(void *ptr, size_t size, size_t nmemb, BFILE *f);
-
-/**
- Close a BFILE, to match close() and fclose().
- */
-void BLI_bfile_close(BFILE *bfile);
-
-/**
- Clear error status.
- Call it only if the error has been really handled.
- */
-void BLI_bfile_clear_error(BFILE *bfile);
-
-/**
- Set the error status.
- Call it to mark writing by a 3rd party failed (libjpeg reported error, ie).
- */
-void BLI_bfile_set_error(BFILE *bfile, int error);
-
-/*
-TODO
-Maybe also provide more OS/libc things like:
-fflush
-fprintf and related
-fscanf
-fgetc/fputc and related
-fseek and related
-
-Probably good to do:
-readdir (compacted list showing all files for a "directory" (user versions on top of system's))
-*/
-
-#endif /* ifndef BLI_BFILE_H */
diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h
index 3028161734c..59d5b5cdef8 100644
--- a/source/blender/blenlib/BLI_blenlib.h
+++ b/source/blender/blenlib/BLI_blenlib.h
@@ -25,10 +25,14 @@
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file BLI_blenlib.h
+ * \ingroup bli
*
- * @mainpage BLI - Blender LIbrary external interface
+ * \section aboutbli Blender LIbrary external interface
*
- * @section about About the BLI module
+ * \subsection about About the BLI module
*
* This is the external interface of the Blender Library. If you find
* a call to a BLI function that is not prototyped here, please add a
@@ -39,7 +43,7 @@
* allocation/deallocation. There is also a patch to make MS Windows
* behave more or less Posix-compliant.
*
- * @section issues Known issues with BLI
+ * \subsection issues Known issues with BLI
*
* - blenlib is written in C.
* - The posix-compliancy may move to a separate lib that deals with
@@ -51,13 +55,11 @@
* - vectorops.c is close to superfluous. It may disappear in the
* near future.
*
- * @section dependencies Dependencies
+ * \subsection dependencies Dependencies
*
- * - The blenlib uses type defines from makesdna/, and functions from
+ * - The blenlib uses type defines from \ref DNA, and functions from
* standard libraries.
- *
- * $Id$
-*/
+ */
#ifndef BLI_BLENLIB_H
#define BLI_BLENLIB_H
@@ -84,8 +86,6 @@ extern "C" {
#include "BLI_rect.h"
-#include "BLI_scanfill.h"
-
#include "BLI_noise.h"
/**
diff --git a/source/blender/blenlib/BLI_boxpack2d.h b/source/blender/blenlib/BLI_boxpack2d.h
index 4beb2988fb6..886965f66b3 100644
--- a/source/blender/blenlib/BLI_boxpack2d.h
+++ b/source/blender/blenlib/BLI_boxpack2d.h
@@ -1,6 +1,4 @@
-/**
- *
- *
+/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
@@ -27,25 +25,14 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/* Box Packer */
+#ifndef _BLI_BOXPACK2D_H_
+#define _BLI_BOXPACK2D_H_
-/* verts, internal use only */
-typedef struct boxVert {
- float x;
- float y;
- short free;
-
- struct boxPack *trb; /* top right box */
- struct boxPack *blb; /* bottom left box */
- struct boxPack *brb; /* bottom right box */
- struct boxPack *tlb; /* top left box */
-
- /* Store last intersecting boxes here
- * speedup intersection testing */
- struct boxPack *isect_cache[4];
-
- int index;
-} boxVert;
+/** \file BLI_boxpack2d.h
+ * \ingroup bli
+ */
+
+/* Box Packer */
typedef struct boxPack {
float x;
@@ -56,8 +43,10 @@ typedef struct boxPack {
/* Verts this box uses
* (BL,TR,TL,BR) / 0,1,2,3 */
- boxVert *v[4];
+ struct boxVert *v[4];
} boxPack;
-void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height);
+void boxPack2D(boxPack *boxarray, const int len, float *tot_width, float *tot_height);
+
+#endif
diff --git a/source/blender/blenlib/BLI_bpath.h b/source/blender/blenlib/BLI_bpath.h
index 72489a171b9..2200ec70789 100644
--- a/source/blender/blenlib/BLI_bpath.h
+++ b/source/blender/blenlib/BLI_bpath.h
@@ -1,4 +1,4 @@
-/**
+/*
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -26,54 +26,40 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/* Based on ghash, difference is ghash is not a fixed size,
- * so for BPath we dont need to malloc */
+/** \file BLI_bpath.h
+ * \ingroup bli
+ * \attention Based on ghash, difference is ghash is not a fixed size,
+ * so for BPath we dont need to malloc
+ */
#ifndef BLI_BPATH_H
#define BLI_BPATH_H
-struct BPathIteratorSeqData {
- int totseq;
- int seq;
- struct Sequence **seqar; /* Sequence */
- struct Scene *scene; /* Current scene */
-};
-
-struct BPathIterator {
- char* path;
- char* lib;
- char* name;
- void* data;
- int len;
- int type;
-
- void (*setpath_callback)(struct BPathIterator *, char *);
- void (*getpath_callback)(struct BPathIterator *, char *);
-
- char* base_path; /* base path, the directry the blend file is in - normally G.sce */
+struct BPathIterator;
+struct ReportList;
+struct Main;
- /* only for seq data */
- struct BPathIteratorSeqData seqdata;
-};
-
-void BLI_bpathIterator_init (struct BPathIterator *bpi, char *base_path);
+void BLI_bpathIterator_init (struct BPathIterator **bpi, struct Main *bmain, const char *basedir, const int flag);
void BLI_bpathIterator_free (struct BPathIterator *bpi);
-char* BLI_bpathIterator_getLib (struct BPathIterator *bpi);
-char* BLI_bpathIterator_getName (struct BPathIterator *bpi);
+const char* BLI_bpathIterator_getLib (struct BPathIterator *bpi);
+const char* BLI_bpathIterator_getName (struct BPathIterator *bpi);
int BLI_bpathIterator_getType (struct BPathIterator *bpi);
int BLI_bpathIterator_getPathMaxLen (struct BPathIterator *bpi);
+const char* BLI_bpathIterator_getBasePath (struct BPathIterator *bpi);
void BLI_bpathIterator_step (struct BPathIterator *bpi);
int BLI_bpathIterator_isDone (struct BPathIterator *bpi);
void BLI_bpathIterator_getPath (struct BPathIterator *bpi, char *path);
void BLI_bpathIterator_getPathExpanded (struct BPathIterator *bpi, char *path_expanded);
-void BLI_bpathIterator_setPath (struct BPathIterator *bpi, char *path);
+void BLI_bpathIterator_setPath (struct BPathIterator *bpi, const char *path);
/* high level funcs */
/* creates a text file with missing files if there are any */
-void checkMissingFiles(char *basepath, ReportList *reports);
-void makeFilesRelative(char *basepath, ReportList *reports);
-void makeFilesAbsolute(char *basepath, ReportList *reports);
-void findMissingFiles(char *basepath, char *str);
+void checkMissingFiles(struct Main *bmain, struct ReportList *reports);
+void makeFilesRelative(struct Main *bmain, const char *basedir, struct ReportList *reports);
+void makeFilesAbsolute(struct Main *bmain, const char *basedir, struct ReportList *reports);
+void findMissingFiles(struct Main *bmain, const char *str);
+
+#define BPATH_USE_PACKED 1
#endif // BLI_BPATH_H
diff --git a/source/blender/blenlib/BLI_cellalloc.h b/source/blender/blenlib/BLI_cellalloc.h
index d2aa7f9ed55..e0fbc581969 100644
--- a/source/blender/blenlib/BLI_cellalloc.h
+++ b/source/blender/blenlib/BLI_cellalloc.h
@@ -42,8 +42,8 @@
//BMESH_TODO: kill this library before merging with trunk. it's evil! -joeedh
-void *BLI_cellalloc_malloc(long size, char *tag);
-void *BLI_cellalloc_calloc(long size, char *tag);
+void *BLI_cellalloc_malloc(long size, const char *tag);
+void *BLI_cellalloc_calloc(long size, const char *tag);
void BLI_cellalloc_free(void *mem);
void BLI_cellalloc_printleaks(void);
int BLI_cellalloc_get_totblock(void);
diff --git a/source/blender/blenlib/BLI_cpu.h b/source/blender/blenlib/BLI_cpu.h
index d809f1cc594..addcf1273b3 100644
--- a/source/blender/blenlib/BLI_cpu.h
+++ b/source/blender/blenlib/BLI_cpu.h
@@ -1,5 +1,4 @@
/*
- *
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -24,6 +23,10 @@
#ifndef BLI_CPU_H
#define BLI_CPU_H
+/** \file BLI_cpu.h
+ * \ingroup bli
+ */
+
int BLI_cpu_support_sse2(void);
#endif
diff --git a/source/blender/blenlib/BLI_dlrbTree.h b/source/blender/blenlib/BLI_dlrbTree.h
index 4b3768c3547..24c819ada55 100644
--- a/source/blender/blenlib/BLI_dlrbTree.h
+++ b/source/blender/blenlib/BLI_dlrbTree.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -28,6 +28,11 @@
#ifndef BLI_DLRB_TREE_H
#define BLI_DLRB_TREE_H
+/** \file BLI_dlrbTree.h
+ * \ingroup bli
+ * \author Joshua Leung
+ */
+
/* Double-Linked Red-Black Tree Implementation:
*
* This is simply a Red-Black Tree implementation whose nodes can later
diff --git a/source/blender/blenlib/BLI_dynstr.h b/source/blender/blenlib/BLI_dynstr.h
index c5158264e72..ed7a76daa92 100644
--- a/source/blender/blenlib/BLI_dynstr.h
+++ b/source/blender/blenlib/BLI_dynstr.h
@@ -1,12 +1,4 @@
-/**
- * @file BLI_dynstr.h
- *
- * A dynamically sized string ADT.
- * This ADT is designed purely for dynamic string creation
- * through appending, not for general usage, the intent is
- * to build up dynamic strings using a DynStr object, then
- * convert it to a c-string and work with that.
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -38,6 +30,16 @@
#ifndef BLI_DYNSTR_H
#define BLI_DYNSTR_H
+/** \file BLI_dynstr.h
+ * \ingroup bli
+ * \brief A dynamically sized string ADT.
+ * \section aboutdynstr Dynamic String
+ * This ADT is designed purely for dynamic string creation
+ * through appending, not for general usage, the intent is
+ * to build up dynamic strings using a DynStr object, then
+ * convert it to a c-string and work with that.
+ */
+
#include <stdarg.h>
struct DynStr;
@@ -75,7 +77,11 @@ void BLI_dynstr_nappend (DynStr *ds, const char *cstr, int len);
* @param ds The DynStr to append to.
* @param format The printf format string to use.
*/
-void BLI_dynstr_appendf (DynStr *ds, const char *format, ...);
+void BLI_dynstr_appendf (DynStr *ds, const char *format, ...)
+#ifdef __GNUC__
+__attribute__ ((format (printf, 2, 3)));
+#endif
+;
void BLI_dynstr_vappendf (DynStr *ds, const char *format, va_list args);
/**
diff --git a/source/blender/blenlib/BLI_edgehash.h b/source/blender/blenlib/BLI_edgehash.h
index 50189328e68..1827d69dcab 100644
--- a/source/blender/blenlib/BLI_edgehash.h
+++ b/source/blender/blenlib/BLI_edgehash.h
@@ -1,6 +1,4 @@
-/**
- * A general unordered 2-int pair hash table ADT
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -32,6 +30,12 @@
#ifndef BLI_EDGEHASH_H
#define BLI_EDGEHASH_H
+/** \file BLI_storage.h
+ * \ingroup bli
+ * \author Daniel Dunbar
+ * \brief A general unordered 2-int pair hash table ADT.
+ */
+
#include "MEM_guardedalloc.h"
#include "BKE_utildefines.h"
#include "BLI_mempool.h"
diff --git a/source/blender/blenlib/BLI_editVert.h b/source/blender/blenlib/BLI_editVert.h
index 5eefac42ed1..a4fd26d1274 100644
--- a/source/blender/blenlib/BLI_editVert.h
+++ b/source/blender/blenlib/BLI_editVert.h
@@ -1,9 +1,4 @@
-/**
- * blenlib/BLI_editVert.h mar 2001 Nzc
- *
- * Some editing types needed in the lib (unfortunately) for
- * scanfill.c
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -35,6 +30,14 @@
#ifndef BLI_EDITVERT_H
#define BLI_EDITVERT_H
+/** \file BLI_editVert.h
+ * \ingroup bli
+ * \since March 2001
+ * \author nzc
+ * \brief Some editing types needed in the lib (unfortunately) for
+ * scanfill.c
+ */
+
#include "DNA_customdata_types.h"
#include "DNA_mesh_types.h"
@@ -69,7 +72,7 @@ typedef struct EditVert
unsigned char f, h, f1, f2;
float bweight;
short fast; /* only 0 or 1, for editmesh_fastmalloc, do not store temp data here! */
- int hash;
+ int hash; /* internal editmesh.c use only, don't touch! */
int keyindex; /* original index #, for restoring key information */
void *data; /* custom vertex data */
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index 6c98d30e4b1..59c01348c07 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -1,6 +1,4 @@
-/**
- * blenlib/BLI_listBase.h mar 2001 Nzc
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -27,8 +25,12 @@
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
- *
- * More low-level fileops from Daniel Dunbar. Two functions were also
+ */
+
+/** \file BLI_fileops.h
+ * \ingroup bli
+ * \author Daniel Dunbar
+ * \brief More low-level fileops from Daniel Dunbar. Two functions were also
* defined in storage.c. These are the old fop_ prefixes. There is
* definitely some redundancy here!
* */
@@ -36,29 +38,33 @@
#ifndef BLI_FILEOPS_H
#define BLI_FILEOPS_H
-void BLI_recurdir_fileops(char *dirname);
-int BLI_link(char *file, char *to);
-int BLI_is_writable(char *filename);
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void BLI_recurdir_fileops(const char *dirname);
+int BLI_link(const char *file, const char *to);
+int BLI_is_writable(const char *filename);
/**
* @attention Do not confuse with BLI_exist
*/
-int BLI_exists(char *file);
-int BLI_copy_fileops(char *file, char *to);
-int BLI_rename(char *from, char *to);
-int BLI_gzip(char *from, char *to);
-int BLI_delete(char *file, int dir, int recursive);
-int BLI_move(char *file, char *to);
+int BLI_exists(const char *file);
+int BLI_copy_fileops(const char *file, const char *to);
+int BLI_rename(const char *from, const char *to);
+int BLI_gzip(const char *from, const char *to);
+int BLI_delete(const char *file, int dir, int recursive);
+int BLI_move(const char *file, const char *to);
int BLI_touch(const char *file);
-char *BLI_last_slash(const char *string);
-int BLI_add_slash(char *string);
-void BLI_del_slash(char *string);
-char *first_slash(char *string);
/* only for the sane unix world: direct calls to system functions :( */
#ifndef WIN32
void BLI_setCmdCallBack(int (*f)(char*));
#endif
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/source/blender/blenlib/BLI_fnmatch.h b/source/blender/blenlib/BLI_fnmatch.h
index 1dffb285451..94ae741250f 100644
--- a/source/blender/blenlib/BLI_fnmatch.h
+++ b/source/blender/blenlib/BLI_fnmatch.h
@@ -18,9 +18,12 @@ along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _FNMATCH_H
-
#define _FNMATCH_H 1
+/** \file BLI_fnmatch.h
+ * \ingroup bli
+ */
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h
index d1600868d9b..8f2cd02c35e 100644
--- a/source/blender/blenlib/BLI_ghash.h
+++ b/source/blender/blenlib/BLI_ghash.h
@@ -1,6 +1,4 @@
-/**
- * A general (pointer -> pointer) hash table ADT
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -32,22 +30,28 @@
#ifndef BLI_GHASH_H
#define BLI_GHASH_H
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+/** \file BLI_ghash.h
+ * \ingroup bli
+ * \brief A general (pointer -> pointer) hash table ADT
+ */
#ifdef __cplusplus
extern "C" {
#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
#include "BKE_utildefines.h"
#include "MEM_guardedalloc.h"
#include "BLI_mempool.h"
#include "BLI_blenlib.h"
-typedef unsigned int (*GHashHashFP) (void *key);
-typedef int (*GHashCmpFP) (void *a, void *b);
+typedef unsigned int (*GHashHashFP) (const void *key);
+typedef int (*GHashCmpFP) (const void *a, const void *b);
typedef void (*GHashKeyFreeFP) (void *key);
typedef void (*GHashValFreeFP) (void *val);
@@ -137,14 +141,14 @@ int BLI_ghashIterator_isDone (GHashIterator *ghi);
/* *** */
-unsigned int BLI_ghashutil_ptrhash (void *key);
-int BLI_ghashutil_ptrcmp (void *a, void *b);
+unsigned int BLI_ghashutil_ptrhash (const void *key);
+int BLI_ghashutil_ptrcmp (const void *a, const void *b);
-unsigned int BLI_ghashutil_strhash (void *key);
-int BLI_ghashutil_strcmp (void *a, void *b);
+unsigned int BLI_ghashutil_strhash (const void *key);
+int BLI_ghashutil_strcmp (const void *a, const void *b);
-unsigned int BLI_ghashutil_inthash (void *ptr);
-int BLI_ghashutil_intcmp(void *a, void *b);
+unsigned int BLI_ghashutil_inthash (const void *ptr);
+int BLI_ghashutil_intcmp(const void *a, const void *b);
/*begin of macro-inlined functions*/
extern unsigned int hashsizes[];
@@ -160,7 +164,7 @@ BM_INLINE void BLI_ghash_insert(GHash *gh, void *key, void *val) {
gh->buckets[hash]= e;
if (++gh->nentries>(float)gh->nbuckets/2) {
- Entry *e, **old= gh->buckets;
+ Entry **old= gh->buckets;
int i, nold= gh->nbuckets;
gh->nbuckets= hashsizes[++gh->cursize];
@@ -183,7 +187,7 @@ BM_INLINE void BLI_ghash_insert(GHash *gh, void *key, void *val) {
}
}
-BM_INLINE void* BLI_ghash_lookup(GHash *gh, void *key)
+BM_INLINE void* BLI_ghash_lookup(GHash *gh, const void *key)
{
if(gh) {
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
@@ -200,7 +204,7 @@ BM_INLINE int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp,
{
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
Entry *e;
- Entry *p = 0;
+ Entry *p = NULL;
for (e= gh->buckets[hash]; e; e= e->next) {
if (gh->cmpfp(key, e->key)==0) {
diff --git a/source/blender/blenlib/BLI_graph.h b/source/blender/blenlib/BLI_graph.h
index 1dd439468f7..f625c7bb2d4 100644
--- a/source/blender/blenlib/BLI_graph.h
+++ b/source/blender/blenlib/BLI_graph.h
@@ -1,6 +1,10 @@
#ifndef BLI_GRAPH_H_
#define BLI_GRAPH_H_
+/** \file BLI_graph.h
+ * \ingroup bli
+ */
+
#include "DNA_listBase.h"
struct BGraph;
diff --git a/source/blender/blenlib/BLI_gsqueue.h b/source/blender/blenlib/BLI_gsqueue.h
index afc4cb38b10..572c54b7b7e 100644
--- a/source/blender/blenlib/BLI_gsqueue.h
+++ b/source/blender/blenlib/BLI_gsqueue.h
@@ -1,7 +1,4 @@
/*
- * A generic structure queue (a queue for fixed length
- * (generally small) structures.
- *
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -33,6 +30,12 @@
#ifndef BLI_GSQUEUE_H
#define BLI_GSQUEUE_H
+/** \file BLI_gsqueue.h
+ * \ingroup bli
+ * \brief A generic structure queue (a queue for fixed length
+ * (generally small) structures.
+ */
+
typedef struct _GSQueue GSQueue;
/**
diff --git a/source/blender/blenlib/BLI_heap.h b/source/blender/blenlib/BLI_heap.h
index a6663726f8b..3038d026df9 100644
--- a/source/blender/blenlib/BLI_heap.h
+++ b/source/blender/blenlib/BLI_heap.h
@@ -1,6 +1,4 @@
-/**
- * A heap / priority queue ADT
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -32,6 +30,11 @@
#ifndef BLI_HEAP_H
#define BLI_HEAP_H
+/** \file BLI_heap.h
+ * \ingroup bli
+ * \brief A heap / priority queue ADT
+ */
+
struct Heap;
struct HeapNode;
typedef struct Heap Heap;
diff --git a/source/blender/blenlib/BLI_jitter.h b/source/blender/blenlib/BLI_jitter.h
index f626feb2ec8..e0fea9306ff 100644
--- a/source/blender/blenlib/BLI_jitter.h
+++ b/source/blender/blenlib/BLI_jitter.h
@@ -1,6 +1,4 @@
/*
- * jitter.h
- *
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -32,9 +30,13 @@
#ifndef BLI_JITTER_H
#define BLI_JITTER_H
-extern void BLI_initjit(float *jitarr, int num);
-extern void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1);
-extern void BLI_jitterate2(float *jit1, float *jit2, int num, float rad2);
+/** \file BLI_jitter.h
+ * \ingroup bli
+ */
+
+void BLI_initjit(float *jitarr, int num);
+void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1);
+void BLI_jitterate2(float *jit1, float *jit2, int num, float rad2);
#endif
diff --git a/source/blender/blenlib/BLI_kdopbvh.h b/source/blender/blenlib/BLI_kdopbvh.h
index d9e3d7e42c6..d0943408dc5 100644
--- a/source/blender/blenlib/BLI_kdopbvh.h
+++ b/source/blender/blenlib/BLI_kdopbvh.h
@@ -1,5 +1,4 @@
-/**
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -32,6 +31,12 @@
#ifndef BLI_KDOPBVH_H
#define BLI_KDOPBVH_H
+/** \file BLI_kdopbvh.h
+ * \ingroup bli
+ * \author Daniel Genrich
+ * \author Andre Pinto
+ */
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -90,7 +95,7 @@ int BLI_bvhtree_update_node(BVHTree *tree, int index, float *co, float *co_movin
void BLI_bvhtree_update_tree(BVHTree *tree);
/* collision/overlap: check two trees if they overlap, alloc's *overlap with length of the int return value */
-BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, int *result);
+BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int *result);
float BLI_bvhtree_getepsilon(BVHTree *tree);
diff --git a/source/blender/blenlib/BLI_kdtree.h b/source/blender/blenlib/BLI_kdtree.h
index 95f9e6939d0..c607dae386f 100644
--- a/source/blender/blenlib/BLI_kdtree.h
+++ b/source/blender/blenlib/BLI_kdtree.h
@@ -1,6 +1,4 @@
-/**
- * A kd-tree for nearest neighbour search.
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -33,6 +31,13 @@
#ifndef BLI_KDTREE_H
#define BLI_KDTREE_H
+/** \file BLI_kdtree.h
+ * \ingroup bli
+ * \brief A kd-tree for nearest neighbour search.
+ * \author Janne Karhu
+ * \author Brecht van Lommel
+ */
+
struct KDTree;
typedef struct KDTree KDTree;
diff --git a/source/blender/blenlib/BLI_linklist.h b/source/blender/blenlib/BLI_linklist.h
index b10d48e3ee6..95850c44ea1 100644
--- a/source/blender/blenlib/BLI_linklist.h
+++ b/source/blender/blenlib/BLI_linklist.h
@@ -1,7 +1,4 @@
/*
- * Routines for working with singly linked lists
- * of 'links' - pointers to other data.
- *
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -33,6 +30,13 @@
#ifndef BLI_LINKLIST_H
#define BLI_LINKLIST_H
+/** \file BLI_linklist.h
+ * \ingroup bli
+ * \brief Routines for working with singly linked lists
+ * of 'links' - pointers to other data.
+ *
+ */
+
struct MemArena;
typedef void (*LinkNodeFreeFP)(void *link);
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index c4dc0894f80..73af9a3738c 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -25,13 +25,15 @@
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
- *
- * $Id$
*/
#ifndef BLI_LISTBASE_H
#define BLI_LISTBASE_H
+/** \file BLI_listbase.h
+ * \ingroup bli
+ */
+
#include "DNA_listBase.h"
//struct ListBase;
//struct LinkData;
@@ -40,13 +42,12 @@
extern "C" {
#endif
-void addlisttolist(struct ListBase *list1, struct ListBase *list2);
void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);
-void *BLI_findlink(struct ListBase *listbase, int number);
-int BLI_findindex(struct ListBase *listbase, void *vlink);
-void *BLI_findstring(struct ListBase *listbase, const char *id, int offset);
-void *BLI_findstring_ptr(struct ListBase *listbase, const char *id, int offset);
-int BLI_findstringindex(struct ListBase *listbase, const char *id, int offset);
+void *BLI_findlink(const struct ListBase *listbase, int number);
+int BLI_findindex(const struct ListBase *listbase, void *vlink);
+void *BLI_findstring(const struct ListBase *listbase, const char *id, const int offset);
+void *BLI_findstring_ptr(const struct ListBase *listbase, const char *id, const int offset);
+int BLI_findstringindex(const struct ListBase *listbase, const char *id, const int offset);
void BLI_freelistN(struct ListBase *listbase);
void BLI_addtail(struct ListBase *listbase, void *vlink);
void BLI_remlink(struct ListBase *listbase, void *vlink);
@@ -57,9 +58,11 @@ void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnew
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink);
void BLI_sortlist(struct ListBase *listbase, int (*cmp)(void *, void *));
void BLI_freelist(struct ListBase *listbase);
-int BLI_countlist(struct ListBase *listbase);
+int BLI_countlist(const struct ListBase *listbase);
void BLI_freelinkN(struct ListBase *listbase, void *vlink);
-void BLI_duplicatelist(struct ListBase *list1, const struct ListBase *list2);
+
+void BLI_movelisttolist(struct ListBase *dst, struct ListBase *src);
+void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src);
/* create a generic list node containing link to provided data */
struct LinkData *BLI_genericNodeN(void *data);
diff --git a/source/blender/blenlib/BLI_math.h b/source/blender/blenlib/BLI_math.h
index d0fb530e349..890a5ee4018 100644
--- a/source/blender/blenlib/BLI_math.h
+++ b/source/blender/blenlib/BLI_math.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -25,32 +25,33 @@
* ***** END GPL LICENSE BLOCK *****
* */
-#ifndef BLI_MATH
-#define BLI_MATH
+#ifndef BLI_MATH_H
+#define BLI_MATH_H
-/* Abbreviations:
+/** \file BLI_math.h
+ * \ingroup bli
+ * \section mathabbrev Abbreviations
*
- * fl = float
- * db = double
- * v2 = vec2 = vector 2
- * v3 = vec3 = vector 3
- * v4 = vec4 = vector 4
- * qt = quat = quaternion
- * dq = dquat = dual quaternion
- * m2 = mat2 = matrix 2x2
- * m3 = mat3 = matrix 3x3
- * m4 = mat4 = matrix 4x4
- * eul = euler rotation
- * eulO = euler with order
+ * - fl = float
+ * - db = double
+ * - v2 = vec2 = vector 2
+ * - v3 = vec3 = vector 3
+ * - v4 = vec4 = vector 4
+ * - qt = quat = quaternion
+ * - dq = dquat = dual quaternion
+ * - m2 = mat2 = matrix 2x2
+ * - m3 = mat3 = matrix 3x3
+ * - m4 = mat4 = matrix 4x4
+ * - eul = euler rotation
+ * - eulO = euler with order
*
- * Variable Names:
- *
- * f = single value
- * a, b, c = vectors
- * r = result vector
- * A, B, C = matrices
- * R = result matrix
+ * \section mathvarnames Variable Names
*
+ * - f = single value
+ * - a, b, c = vectors
+ * - r = result vector
+ * - A, B, C = matrices
+ * - R = result matrix
*/
#include "BLI_math_base.h"
@@ -60,5 +61,5 @@
#include "BLI_math_vector.h"
#include "BLI_math_geom.h"
-#endif /* BLI_MATH */
+#endif /* BLI_MATH_H */
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index bb20cb7c8e1..6ff57b08724 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -25,12 +25,12 @@
* ***** END GPL LICENSE BLOCK *****
* */
-#ifndef BLI_MATH_BASE
-#define BLI_MATH_BASE
+#ifndef BLI_MATH_BASE_H
+#define BLI_MATH_BASE_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+/** \file BLI_math_base.h
+ * \ingroup bli
+ */
#ifdef WIN32
#define _USE_MATH_DEFINES
@@ -70,6 +70,11 @@ extern "C" {
#define M_LN10 2.30258509299404568402
#endif
+/* non-standard defines, used in some places */
+#ifndef MAXFLOAT
+#define MAXFLOAT ((float)3.40282347e+38)
+#endif
+
#ifndef sqrtf
#define sqrtf(a) ((float)sqrt(a))
#endif
@@ -123,6 +128,7 @@ extern "C" {
#ifndef FREE_WINDOWS
#define isnan(n) _isnan(n)
#define finite _finite
+#define hypot _hypot
#endif
#endif
@@ -134,7 +140,7 @@ extern "C" {
#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c)
#endif
-#ifdef BLI_MATH_INLINE
+#ifdef BLI_MATH_INLINE_H
#include "intern/math_base_inline.c"
#endif
@@ -155,15 +161,18 @@ MINLINE float interpf(float a, float b, float t);
MINLINE float minf(float a, float b);
MINLINE float maxf(float a, float b);
+MINLINE float signf(float f);
+
MINLINE float power_of_2(float f);
MINLINE float shell_angle_to_dist(float angle);
-double double_round(double x, int ndigits);
-
-#ifdef __cplusplus
-}
+#if (defined(WIN32) || defined(WIN64)) && !defined(FREE_WINDOWS)
+extern double copysign(double x, double y);
+extern double round(double x);
#endif
-#endif /* BLI_MATH_BASE */
+double double_round(double x, int ndigits);
+
+#endif /* BLI_MATH_BASE_H */
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index d3f1a842e45..cc443621fa9 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -25,8 +25,12 @@
* ***** END GPL LICENSE BLOCK *****
* */
-#ifndef BLI_MATH_COLOR
-#define BLI_MATH_COLOR
+#ifndef BLI_MATH_COLOR_H
+#define BLI_MATH_COLOR_H
+
+/** \file BLI_math_color.h
+ * \ingroup bli
+ */
#ifdef __cplusplus
extern "C" {
@@ -61,6 +65,7 @@ void cpack_to_rgb(unsigned int col, float *r, float *g, float *b);
void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv);
void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, int colorspace);
void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv);
+void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv);
unsigned int rgb_to_cpack(float r, float g, float b);
unsigned int hsv_to_cpack(float h, float s, float v);
@@ -75,6 +80,12 @@ float srgb_to_linearrgb(float c);
float linearrgb_to_srgb(float c);
void srgb_to_linearrgb_v3_v3(float *col_to, float *col_from);
void linearrgb_to_srgb_v3_v3(float *col_to, float *col_from);
+
+/* rgba buffer convenience functions */
+void srgb_to_linearrgb_rgba_buf(float *col, int tot);
+void linearrgb_to_srgb_rgba_buf(float *col, int tot);
+void srgb_to_linearrgb_rgba_rgba_buf(float *col_to, float *col_from, int tot);
+void linearrgb_to_srgb_rgba_rgba_buf(float *col_to, float *col_from, int tot);
/* rgba buffer convenience functions */
void srgb_to_linearrgb_rgba_buf(float *col, int tot);
@@ -86,17 +97,20 @@ void linearrgb_to_srgb_rgba_rgba_buf(float *col_to, float *col_from, int tot);
int constrain_rgb(float *r, float *g, float *b);
void minmax_rgb(short c[3]);
-
+
+void rgb_float_set_hue_float_offset(float * rgb, float hue_offset);
+void rgb_byte_set_hue_float_offset(unsigned char * rgb, float hue_offset);
+
/***************** lift/gamma/gain / ASC-CDL conversion *****************/
void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power);
-void rgb_byte_to_float(char *in, float *out);
-void rgb_float_to_byte(float *in, char *out);
+void rgb_byte_to_float(const unsigned char *in, float *out);
+void rgb_float_to_byte(const float *in, unsigned char *out);
#ifdef __cplusplus
}
#endif
-#endif /* BLI_MATH_COLOR */
+#endif /* BLI_MATH_COLOR_H */
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 5d84de7531a..8d2f9ffa38b 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -25,8 +25,12 @@
* ***** END GPL LICENSE BLOCK *****
* */
-#ifndef BLI_MATH_GEOM
-#define BLI_MATH_GEOM
+#ifndef BLI_MATH_GEOM_H
+#define BLI_MATH_GEOM_H
+
+/** \file BLI_math_geom.h
+ * \ingroup bli
+ */
#ifdef __cplusplus
extern "C" {
@@ -34,7 +38,7 @@ extern "C" {
#include "BLI_math_inline.h"
-#ifdef BLI_MATH_INLINE
+#ifdef BLI_MATH_INLINE_H
#include "intern/math_geom_inline.c"
#endif
@@ -58,7 +62,8 @@ float dist_to_line_v2(float p[2], float l1[2], float l2[2]);
float dist_to_line_segment_v2(float p[2], float l1[2], float l2[2]);
float dist_to_line_segment_v3(float p[3], float l1[3], float l2[3]);
-float closest_to_line_v3(float r[3], float p[3], float l1[3], float l2[3]);
+float closest_to_line_v3(float r[3], const float p[3], const float l1[3], const float l2[3]);
+float closest_to_line_v2(float r[2], const float p[2], const float l1[2], const float l2[2]);
void closest_to_line_segment_v3(float r[3], float p[3], float l1[3], float l2[3]);
/******************************* Intersection ********************************/
@@ -71,8 +76,9 @@ void closest_to_line_segment_v3(float r[3], float p[3], float l1[3], float l2[3]
#define ISECT_LINE_LINE_EXACT 1
#define ISECT_LINE_LINE_CROSS 2
-int isect_line_line_v2(float a1[2], float a2[2], float b1[2], float b2[2]);
-int isect_line_line_v2_short(short a1[2], short a2[2], short b1[2], short b2[2]);
+int isect_line_line_v2(const float a1[2], const float a2[2], const float b1[2], const float b2[2]);
+int isect_line_line_v2_short(const short a1[2], const short a2[2], const short b1[2], const short b2[2]);
+int isect_seg_seg_v2_point(const float *v1, const float *v2, const float *v3, const float *v4, float vi[2]);
/* Returns the number of point of interests
* 0 - lines are colinear
@@ -96,7 +102,6 @@ int isect_ray_tri_epsilon_v3(float p1[3], float d[3],
float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float epsilon);
/* point in polygon */
-int isect_point_tri_v2(float p[2], float a[2], float b[2], float c[2]);
int isect_point_quad_v2(float p[2], float a[2], float b[2], float c[2], float d[2]);
int isect_point_tri_v2(float v1[2], float v2[2], float v3[2], float pt[2]);
@@ -119,6 +124,8 @@ int isect_aabb_aabb_v3(float min1[3], float max1[3], float min2[3], float max2[3
int clip_line_plane(float clipco[3], float plane[4], float co[3]);
+void plot_line_v2v2i(int p1[2], int p2[2], int (*callback)(int, int, void *), void *userData);
+
/****************************** Interpolation ********************************/
/* tri or quad, d can be NULL */
@@ -149,6 +156,8 @@ void perspective_m4(float mat[4][4], float left, float right,
float bottom, float top, float nearClip, float farClip);
void orthographic_m4(float mat[4][4], float left, float right,
float bottom, float top, float nearClip, float farClip);
+void window_translate_m4(float winmat[][4], float perspmat[][4],
+ float x, float y);
int box_clip_bounds_m4(float boundbox[2][3],
float bounds[4], float winmat[4][4]);
@@ -163,8 +172,8 @@ void map_to_sphere(float *u, float *v, float x, float y, float z);
/********************************* Tangents **********************************/
typedef struct VertexTangent {
- float tang[3], uv[2];
struct VertexTangent *next;
+ float tang[3], uv[2];
} VertexTangent;
float *find_vertex_tangent(VertexTangent *vtang, float *uv);
@@ -205,5 +214,5 @@ float form_factor_hemi_poly(float p[3], float n[3],
}
#endif
-#endif /* BLI_MATH_GEOM */
+#endif /* BLI_MATH_GEOM_H */
diff --git a/source/blender/blenlib/BLI_math_inline.h b/source/blender/blenlib/BLI_math_inline.h
index d002c0880b2..0f8493e25a6 100644
--- a/source/blender/blenlib/BLI_math_inline.h
+++ b/source/blender/blenlib/BLI_math_inline.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -28,14 +28,18 @@
#ifndef BLI_MATH_INLINE_H
#define BLI_MATH_INLINE_H
+/** \file BLI_math_inline.h
+ * \ingroup bli
+ */
+
#ifdef __cplusplus
extern "C" {
#endif
/* add platform/compiler checks here if it is not supported */
-#define BLI_MATH_INLINE
+#define BLI_MATH_INLINE_H
-#ifdef BLI_MATH_INLINE
+#ifdef BLI_MATH_INLINE_H
#ifdef _MSC_VER
#define MINLINE static __forceinline
#define MALWAYS_INLINE MINLINE
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index 77ebcb24975..939c4348461 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -25,8 +25,12 @@
* ***** END GPL LICENSE BLOCK *****
* */
-#ifndef BLI_MATH_MATRIX
-#define BLI_MATH_MATRIX
+#ifndef BLI_MATH_MATRIX_H
+#define BLI_MATH_MATRIX_H
+
+/** \file BLI_math_matrix.h
+ * \ingroup bli
+ */
#ifdef __cplusplus
extern "C" {
@@ -102,7 +106,9 @@ void transpose_m3(float R[3][3]);
void transpose_m4(float R[4][4]);
void normalize_m3(float R[3][3]);
+void normalize_m3_m3(float R[3][3], float A[3][3]);
void normalize_m4(float R[4][4]);
+void normalize_m4_m4(float R[4][4], float A[4][4]);
void orthogonalize_m3(float R[3][3], int axis);
void orthogonalize_m4(float R[4][4], int axis);
@@ -133,36 +139,42 @@ void scale_m4_fl(float R[4][4], float scale);
float mat3_to_scale(float M[3][3]);
float mat4_to_scale(float M[4][4]);
-void size_to_mat3(float R[3][3], float size[3]);
-void size_to_mat4(float R[4][4], float size[3]);
+void size_to_mat3(float R[3][3], const float size[3]);
+void size_to_mat4(float R[4][4], const float size[3]);
void mat3_to_size(float r[3], float M[3][3]);
void mat4_to_size(float r[3], float M[4][4]);
void translate_m4(float mat[4][4], float tx, float ty, float tz);
-void rotate_m4(float mat[4][4], char axis, float angle);
+void rotate_m4(float mat[4][4], const char axis, const float angle);
+
+
+void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[][3]);
+void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[][4]);
void loc_eul_size_to_mat4(float R[4][4],
- float loc[3], float eul[3], float size[3]);
+ const float loc[3], const float eul[3], const float size[3]);
void loc_eulO_size_to_mat4(float R[4][4],
- float loc[3], float eul[3], float size[3], short order);
+ const float loc[3], const float eul[3], const float size[3], const short order);
void loc_quat_size_to_mat4(float R[4][4],
- float loc[3], float quat[4], float size[3]);
+ const float loc[3], const float quat[4], const float size[3]);
+void loc_axisangle_size_to_mat4(float R[4][4],
+ const float loc[3], const float axis[4], const float angle, const float size[3]);
-void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], float t);
-void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], float t);
+void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], const float t);
+void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], const float t);
int is_negative_m3(float mat[3][3]);
int is_negative_m4(float mat[4][4]);
/*********************************** Other ***********************************/
-void print_m3(char *str, float M[3][3]);
-void print_m4(char *str, float M[3][4]);
+void print_m3(const char *str, float M[3][3]);
+void print_m4(const char *str, float M[3][4]);
#ifdef __cplusplus
}
#endif
-#endif /* BLI_MATH_MATRIX */
+#endif /* BLI_MATH_MATRIX_H */
diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h
index ac8ed041ebc..d1f5fa89c3d 100644
--- a/source/blender/blenlib/BLI_math_rotation.h
+++ b/source/blender/blenlib/BLI_math_rotation.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -25,8 +25,12 @@
* ***** END GPL LICENSE BLOCK *****
* */
-#ifndef BLI_MATH_ROTATION
-#define BLI_MATH_ROTATION
+#ifndef BLI_MATH_ROTATION_H
+#define BLI_MATH_ROTATION_H
+
+/** \file BLI_math_rotation.h
+ * \ingroup bli
+ */
#ifdef __cplusplus
extern "C" {
@@ -39,6 +43,7 @@ extern "C" {
/* stored in (w, x, y, z) order */
/* init */
+void unit_axis_angle(float axis[3], float *angle);
void unit_qt(float q[4]);
void copy_qt_qt(float q[4], const float a[4]);
@@ -48,29 +53,30 @@ void mul_qt_v3(const float q[4], float r[3]);
void mul_qt_fl(float q[4], const float f);
void mul_fac_qt_fl(float q[4], const float f);
-void sub_qt_qtqt(float q[4], float a[4], float b[4]);
+void sub_qt_qtqt(float q[4], const float a[4], const float b[4]);
void invert_qt(float q[4]);
-void invert_qt_qt(float *q1, const float *q2);
+void invert_qt_qt(float q1[4], const float q2[4]);
void conjugate_qt(float q[4]);
-float dot_qtqt(float a[4], float b[4]);
-void normalize_qt(float q[4]);
+float dot_qtqt(const float a[4], const float b[4]);
+float normalize_qt(float q[4]);
+float normalize_qt_qt(float q1[4], const float q2[4]);
/* comparison */
int is_zero_qt(float q[4]);
/* interpolation */
-void interp_qt_qtqt(float q[4], float a[4], float b[4], float t);
-void add_qt_qtqt(float q[4], float a[4], float b[4], float t);
+void interp_qt_qtqt(float q[4], const float a[4], const float b[4], const float t);
+void add_qt_qtqt(float q[4], const float a[4], const float b[4], const float t);
/* conversion */
-void quat_to_mat3(float mat[3][3], float q[4]);
-void quat_to_mat4(float mat[4][4], float q[4]);
+void quat_to_mat3(float mat[3][3], const float q[4]);
+void quat_to_mat4(float mat[4][4], const float q[4]);
void mat3_to_quat(float q[4], float mat[3][3]);
void mat4_to_quat(float q[4], float mat[4][4]);
-void tri_to_quat(float q[4], float a[3], float b[3], float c[3]);
-void vec_to_quat(float q[4], float vec[3], short axis, short upflag);
+void tri_to_quat(float q[4], const float a[3], const float b[3], const float c[3]);
+void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag);
/* note: v1 and v2 must be normalized */
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3]);
void rotation_between_quats_to_quat(float q[4], const float q1[4], const float q2[4]);
@@ -84,11 +90,11 @@ void print_qt(char *str, float q[4]);
/******************************** Axis Angle *********************************/
/* conversion */
-void axis_angle_to_quat(float r[4], float axis[3], float angle);
-void axis_angle_to_mat3(float R[3][3], float axis[3], float angle);
-void axis_angle_to_mat4(float R[4][4], float axis[3], float angle);
+void axis_angle_to_quat(float r[4], const float axis[3], float angle);
+void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle);
+void axis_angle_to_mat4(float R[4][4], const float axis[3], const float angle);
-void quat_to_axis_angle(float axis[3], float *angle, float q[4]);
+void quat_to_axis_angle(float axis[3], float *angle, const float q[4]);
void mat3_to_axis_angle(float axis[3], float *angle, float M[3][3]);
void mat4_to_axis_angle(float axis[3], float *angle, float M[4][4]);
@@ -100,24 +106,24 @@ void mat4_to_axis_angle(float axis[3], float *angle, float M[4][4]);
void mat3_to_vec_rot(float vec[3], float *phi, float mat[3][3]);
void mat4_to_vec_rot(float vec[3], float *phi, float mat[4][4]);
-void vec_rot_to_quat(float quat[4], float vec[3], float phi);
-void vec_rot_to_mat3(float mat[3][3], float vec[3], float phi);
-void vec_rot_to_mat4(float mat[4][4], float vec[3], float phi);
+void vec_rot_to_quat(float quat[4], const float vec[3], const float phi);
+void vec_rot_to_mat3(float mat[3][3], const float vec[3], const float phi);
+void vec_rot_to_mat4(float mat[4][4], const float vec[3], const float phi);
/******************************** XYZ Eulers *********************************/
-void eul_to_quat(float quat[4], float eul[3]);
-void eul_to_mat3(float mat[3][3], float eul[3]);
-void eul_to_mat4(float mat[4][4], float eul[3]);
+void eul_to_quat(float quat[4], const float eul[3]);
+void eul_to_mat3(float mat[3][3], const float eul[3]);
+void eul_to_mat4(float mat[4][4], const float eul[3]);
-void quat_to_eul(float eul[3], float quat[4]);
+void quat_to_eul(float eul[3], const float quat[4]);
void mat3_to_eul(float eul[3], float mat[3][3]);
void mat4_to_eul(float eul[3], float mat[4][4]);
-void compatible_eul(float eul[3], float old[3]);
-void mat3_to_compatible_eul(float eul[3], float old[3], float mat[3][3]);
+void compatible_eul(float eul[3], const float old[3]);
+void mat3_to_compatible_eul(float eul[3], const float old[3], float mat[3][3]);
-void rotate_eul(float eul[3], char axis, float angle);
+void rotate_eul(float eul[3], const char axis, const float angle);
/************************** Arbitrary Order Eulers ***************************/
@@ -131,22 +137,23 @@ typedef enum eEulerRotationOrders {
EULER_ORDER_YXZ,
EULER_ORDER_YZX,
EULER_ORDER_ZXY,
- EULER_ORDER_ZYX,
+ EULER_ORDER_ZYX
/* there are 6 more entries with dulpicate entries included */
} eEulerRotationOrders;
-void eulO_to_quat(float quat[4], float eul[3], short order);
-void eulO_to_mat3(float mat[3][3], float eul[3], short order);
-void eulO_to_mat4(float mat[4][4], float eul[3], short order);
-void eulO_to_axis_angle(float axis[3], float *angle, float eul[3], short order);
-void eulO_to_gimbal_axis(float gmat[3][3], float eul[3], short order);
+void eulO_to_quat(float quat[4], const float eul[3], const short order);
+void eulO_to_mat3(float mat[3][3], const float eul[3], const short order);
+void eulO_to_mat4(float mat[4][4], const float eul[3], const short order);
+void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], const short order);
+void eulO_to_gimbal_axis(float gmat[3][3], const float eul[3], const short order);
-void quat_to_eulO(float eul[3], short order, float quat[4]);
-void mat3_to_eulO(float eul[3], short order, float mat[3][3]);
-void mat4_to_eulO(float eul[3], short order, float mat[4][4]);
-void axis_angle_to_eulO(float eul[3], short order, float axis[3], float angle);
+void quat_to_eulO(float eul[3], const short order, const float quat[4]);
+void mat3_to_eulO(float eul[3], const short order, float mat[3][3]);
+void mat4_to_eulO(float eul[3], const short order, float mat[4][4]);
+void axis_angle_to_eulO(float eul[3], const short order, const float axis[3], const float angle);
void mat3_to_compatible_eulO(float eul[3], float old[3], short order, float mat[3][3]);
+void mat4_to_compatible_eulO(float eul[3], float old[3], short order, float mat[4][4]);
void rotate_eulO(float eul[3], short order, char axis, float angle);
@@ -168,6 +175,9 @@ void mul_v3m3_dq(float r[3], float R[3][3], DualQuat *dq);
void mat4_to_dquat(DualQuat *r, float base[4][4], float M[4][4]);
void dquat_to_mat4(float R[4][4], DualQuat *dq);
+void quat_apply_track(float quat[4], short axis, short upflag);
+void vec_apply_track(float vec[3], short axis);
+
float lens_to_angle(float lens);
float angle_to_lens(float angle);
@@ -175,5 +185,5 @@ float angle_to_lens(float angle);
}
#endif
-#endif /* BLI_MATH_ROTATION */
+#endif /* BLI_MATH_ROTATION_H */
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 0749e657f08..1f56694f85b 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -25,8 +25,12 @@
* ***** END GPL LICENSE BLOCK *****
* */
-#ifndef BLI_MATH_VECTOR
-#define BLI_MATH_VECTOR
+#ifndef BLI_MATH_VECTOR_H
+#define BLI_MATH_VECTOR_H
+
+/** \file BLI_math_vector.h
+ * \ingroup bli
+ */
#ifdef __cplusplus
extern "C" {
@@ -34,7 +38,7 @@ extern "C" {
#include "BLI_math_inline.h"
-#ifdef BLI_MATH_INLINE
+#ifdef BLI_MATH_INLINE_H
#include "intern/math_vector_inline.c"
#else
#define MINLINE
@@ -65,6 +69,8 @@ MINLINE void sub_v2_v2(float r[2], const float a[2]);
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]);
MINLINE void sub_v3_v3(float r[3], const float a[3]);
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]);
+MINLINE void sub_v4_v4(float r[4], const float a[4]);
+MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4]);
MINLINE void mul_v2_fl(float r[2], float f);
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f);
@@ -84,6 +90,8 @@ MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f);
MINLINE void negate_v3(float r[3]);
MINLINE void negate_v3_v3(float r[3], const float a[3]);
+MINLINE void negate_v4(float r[4]);
+MINLINE void negate_v4_v4(float r[4], const float a[3]);
MINLINE float dot_v2v2(const float a[2], const float b[2]);
MINLINE float dot_v3v3(const float a[3], const float b[3]);
@@ -97,6 +105,7 @@ MINLINE void star_m3_v3(float R[3][3],float a[3]);
MINLINE float len_v2(const float a[2]);
MINLINE float len_v2v2(const float a[2], const float b[2]);
+MINLINE float len_squared_v2v2(const float a[3], const float b[3]);
MINLINE float len_v3(const float a[3]);
MINLINE float len_v3v3(const float a[3], const float b[3]);
MINLINE float len_squared_v3v3(const float a[3], const float b[3]);
@@ -116,40 +125,47 @@ void interp_v3_v3v3v3v3(float p[3], const float v1[3], const float v2[3], const
void interp_v4_v4v4(float r[4], const float a[4], const float b[4], const float t);
void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float w[3]);
-void mid_v3_v3v3(float r[3], float a[3], float b[3]);
+void mid_v3_v3v3(float r[3], const float a[3], const float b[3]);
/********************************* Comparison ********************************/
-MINLINE int is_zero_v3(float a[3]);
-MINLINE int is_one_v3(float a[3]);
+MINLINE int is_zero_v3(const float a[3]);
+MINLINE int is_zero_v4(const float a[4]);
+MINLINE int is_one_v3(const float a[3]);
+
+MINLINE int equals_v2v2(const float *v1, const float *v2);
+MINLINE int equals_v3v3(const float a[3], const float b[3]);
+MINLINE int compare_v3v3(const float a[3], const float b[3], const float limit);
+MINLINE int compare_len_v3v3(const float a[3], const float b[3], const float limit);
-MINLINE int equals_v3v3(float a[3], float b[3]);
-MINLINE int compare_v3v3(float a[3], float b[3], float limit);
-MINLINE int compare_len_v3v3(float a[3], float b[3], float limit);
+MINLINE int compare_v4v4(const float a[4], const float b[4], const float limit);
+MINLINE int equals_v4v4(const float a[4], const float b[4]);
-MINLINE int compare_v4v4(float a[4], float b[4], float limit);
-MINLINE int equals_v4v4(float a[4], float b[4]);
+MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]);
/********************************** Angles ***********************************/
/* - angle with 2 arguments is angle between vector */
/* - angle with 3 arguments is angle between 3 points at the middle point */
/* - angle_normalized_* is faster equivalent if vectors are normalized */
-float angle_v2v2(float a[2], float b[2]);
-float angle_v2v2v2(float a[2], float b[2], float c[2]);
-float angle_normalized_v2v2(float a[2], float b[2]);
-float angle_v3v3(float a[2], float b[2]);
-float angle_v3v3v3(float a[2], float b[2], float c[2]);
+float angle_v2v2(const float a[2], const float b[2]);
+float angle_v2v2v2(const float a[2], const float b[2], const float c[2]);
+float angle_normalized_v2v2(const float a[2], const float b[2]);
+float angle_v3v3(const float a[3], const float b[3]);
+float angle_v3v3v3(const float a[3], const float b[3], const float c[3]);
float angle_normalized_v3v3(const float v1[3], const float v2[3]);
void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]);
void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
/********************************* Geometry **********************************/
-void project_v3_v3v3(float r[3], float p[3], float n[3]);
-void reflect_v3_v3v3(float r[3], float v[3], float n[3]);
-void ortho_basis_v3v3_v3(float r1[3], float r2[3], float a[3]);
-void bisect_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]);
+void project_v2_v2v2(float c[2], const float v1[2], const float v2[2]);
+void project_v3_v3v3(float r[3], const float p[3], const float n[3]);
+void reflect_v3_v3v3(float r[3], const float v[3], const float n[3]);
+void ortho_basis_v3v3_v3(float r1[3], float r2[3], const float a[3]);
+void bisect_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]);
+void rotate_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle);
+void rotate_normalized_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle);
/*********************************** Other ***********************************/
@@ -160,11 +176,25 @@ void print_v4(const char *str, const float a[4]);
MINLINE void normal_short_to_float_v3(float r[3], const short n[3]);
MINLINE void normal_float_to_short_v3(short r[3], const float n[3]);
-void minmax_v3_v3v3(float r[3], float min[3], float max[3]);
+void minmax_v3v3_v3(float min[3], float max[3], const float vec[3]);
+
+/***************************** Array Functions *******************************/
+/* attempted to follow fixed length vertex functions. names could be improved*/
+void range_vni(int *array, const int size, const int start);
+void negate_vn(float *array_tar, const int size);
+void negate_vn_vn(float *array_tar, const float *array_src, const int size);
+void mul_vn_fl(float *array, const int size, const float f);
+void mul_vn_vn_fl(float *array_tar, const float *array_src, const int size, const float f);
+void add_vn_vn(float *array_tar, const float *array_src, const int size);
+void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size);
+void sub_vn_vn(float *array_tar, const float *array_src, const int size);
+void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size);
+void fill_vni(int *array_tar, const int size, const int val);
+void fill_vn(float *array_tar, const int size, const float val);
#ifdef __cplusplus
}
#endif
-#endif /* BLI_MATH_VECTOR */
+#endif /* BLI_MATH_VECTOR_H */
diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h
index a17c88b70df..f6e919d8d65 100644
--- a/source/blender/blenlib/BLI_memarena.h
+++ b/source/blender/blenlib/BLI_memarena.h
@@ -1,6 +1,4 @@
/*
- * Memory arena ADT
- *
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -27,11 +25,15 @@
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
- *
+ */
+
+/** \file BLI_memarena.h
+ * \ingroup bli
+ * \brief Memory arena ADT.
+ * \section aboutmemarena Memory Arena
* Memory arena's are commonly used when the program
* needs to quickly allocate lots of little bits of
* data, which are all freed at the same moment.
- *
*/
#ifndef BLI_MEMARENA_H
diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h
index 62714defd21..5aa9c196b39 100644
--- a/source/blender/blenlib/BLI_mempool.h
+++ b/source/blender/blenlib/BLI_mempool.h
@@ -1,7 +1,5 @@
-/**
- * Simple fast memory allocator
- *
- *
+/*
+ * $Id$
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
@@ -31,22 +29,24 @@
#ifndef BLI_MEMPOOL_H
#define BLI_MEMPOOL_H
+/** \file BLI_mempool.h
+ * \ingroup bli
+ * \author Geoffrey Bantle
+ * \brief Simple fast memory allocator.
+ */
+
#ifdef __cplusplus
extern "C"
{
#endif
+struct BLI_mempool;
+
#include "BKE_utildefines.h"
#include "BLI_listbase.h"
#include "BLI_blenlib.h"
#include <string.h>
-#ifndef BLI_MEMPOOL_INTERN
-//struct BLI_mempool;
-//struct BLI_mempool_chunk;
-//typedef struct BLI_mempool BLI_mempool;
-#endif
-
typedef struct BLI_freenode{
struct BLI_freenode *next;
int freeword; /*used to identify this as a freed node*/
diff --git a/source/blender/blenlib/BLI_noise.h b/source/blender/blenlib/BLI_noise.h
index 11587262645..bd88529b3dc 100644
--- a/source/blender/blenlib/BLI_noise.h
+++ b/source/blender/blenlib/BLI_noise.h
@@ -31,6 +31,10 @@
#ifndef BLI_NOISE_H
#define BLI_NOISE_H
+/** \file BLI_noise.h
+ * \ingroup bli
+ */
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -57,7 +61,6 @@ void voronoi(float x, float y, float z, float* da, float* pa, float me, int dtyp
float cellNoise(float x, float y, float z);
void cellNoiseV(float x, float y, float z, float *ca);
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index b8c886d95a9..b3d657b7323 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -1,8 +1,4 @@
-/**
- * blenlib/BLI_storage_types.h
- *
- * Some types for dealing with directories
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -33,6 +29,10 @@
#ifndef BLI_PATH_UTIL_H
#define BLI_PATH_UTIL_H
+/** \file BLI_path_util.h
+ * \ingroup bli
+ */
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -42,8 +42,9 @@ struct direntry;
char *BLI_getDefaultDocumentFolder(void);
-char *BLI_get_folder(int folder_id, char *subfolder);
-char *BLI_get_folder_create(int folder_id, char *subfolder);
+char *BLI_get_folder(int folder_id, const char *subfolder);
+char *BLI_get_folder_create(int folder_id, const char *subfolder);
+char *BLI_get_user_folder_notest(int folder_id, const char *subfolder);
/* folder_id */
@@ -87,24 +88,40 @@ char *BLI_get_folder_create(int folder_id, char *subfolder);
#define BLENDER_SYSTEM_FORMAT "%s/blender/%s"
#endif
+#ifdef WIN32
+#define SEP '\\'
+#define ALTSEP '/'
+#else
+#define SEP '/'
+#define ALTSEP '\\'
+#endif
+
void BLI_setenv(const char *env, const char *val);
void BLI_setenv_if_new(const char *env, const char* val);
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
void BLI_make_exist(char *dir);
-void BLI_make_existing_file(char *name);
+void BLI_make_existing_file(const char *name);
void BLI_split_dirfile(const char *string, char *dir, char *file);
-void BLI_join_dirfile(char *string, const char *dir, const char *file);
+void BLI_join_dirfile(char *string, const int maxlen, const char *dir, const char *file);
char *BLI_path_basename(char *path);
int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir);
+char *BLI_last_slash(const char *string);
+int BLI_add_slash(char *string);
+void BLI_del_slash(char *string);
+char *BLI_first_slash(char *string);
+
void BLI_getlastdir(const char* dir, char *last, int maxlen);
int BLI_testextensie(const char *str, const char *ext);
int BLI_testextensie_array(const char *str, const char **ext_array);
+int BLI_testextensie_glob(const char *str, const char *ext_fnmatch);
int BLI_replace_extension(char *path, int maxlen, const char *ext);
void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len);
+int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len);
void BLI_newname(char * name, int add);
int BLI_stringdec(const char *string, char *head, char *start, unsigned short *numlen);
void BLI_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic);
+int BLI_split_name_num(char *left, int *nr, const char *name, const char delim);
void BLI_splitdirstring(char *di,char *fi);
/* make sure path separators conform to system one */
@@ -164,7 +181,7 @@ void BLI_char_switch(char *string, char from, char to);
* @param fullname The full path and full name of the executable
* @param name The name of the executable (usually argv[0]) to be checked
*/
-void BLI_where_am_i(char *fullname, const char *name);
+void BLI_where_am_i(char *fullname, const int maxlen, const char *name);
char *get_install_dir(void);
/**
@@ -175,7 +192,7 @@ char *get_install_dir(void);
*
* @param fullname The full path to the temp directory
*/
-void BLI_where_is_temp(char *fullname, int usertemp);
+void BLI_where_is_temp(char *fullname, const int maxlen, int usertemp);
#ifdef WITH_ICONV
diff --git a/source/blender/blenlib/BLI_pbvh.h b/source/blender/blenlib/BLI_pbvh.h
index 4797aeb2364..bde6bc3ced4 100644
--- a/source/blender/blenlib/BLI_pbvh.h
+++ b/source/blender/blenlib/BLI_pbvh.h
@@ -1,6 +1,4 @@
-/**
- * A BVH for high poly meshes.
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -25,6 +23,11 @@
#ifndef BLI_PBVH_H
#define BLI_PBVH_H
+/** \file BLI_pbvh.h
+ * \ingroup bli
+ * \brief A BVH for high poly meshes.
+ */
+
struct MFace;
struct MVert;
struct DMGridAdjacency;
@@ -119,7 +122,7 @@ void BLI_pbvh_update(PBVH *bvh, int flags, float (*face_nors)[3]);
void BLI_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]);
void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *totface);
void BLI_pbvh_grids_update(PBVH *bvh, struct DMGridData **grids,
- struct DMGridAdjacency *gridadj, void **gridfaces);
+ struct DMGridAdjacency *gridadj, void **gridfaces);;
/* vertex deformer */
float (*BLI_pbvh_get_vertCos(struct PBVH *pbvh))[3];
diff --git a/source/blender/blenlib/BLI_rand.h b/source/blender/blenlib/BLI_rand.h
index eab9f92d7e8..eb6e71acded 100644
--- a/source/blender/blenlib/BLI_rand.h
+++ b/source/blender/blenlib/BLI_rand.h
@@ -1,7 +1,4 @@
-/**
- * @file BLI_rand.h
- *
- * Random number functions.
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -33,10 +30,15 @@
#ifndef BLI_RAND_H
#define BLI_RAND_H
- /* RNG is just an abstract random number generator
- * type that avoids using globals, otherwise identical
- * to BLI_rand functions below.
- */
+/** \file BLI_rand.h
+ * \ingroup bli
+ * \brief Random number functions.
+ */
+
+/** RNG is just an abstract random number generator
+ * type that avoids using globals, otherwise identical
+ * to BLI_rand functions below.
+ */
struct RNG;
typedef struct RNG RNG;
diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h
index 13b12fc4e1e..021ab636d5b 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -31,6 +31,10 @@
#ifndef BLI_RECT_H
#define BLI_RECT_H
+/** \file BLI_rect.h
+ * \ingroup bli
+ */
+
struct rctf;
struct rcti;
diff --git a/source/blender/blenlib/BLI_scanfill.h b/source/blender/blenlib/BLI_scanfill.h
index 0ae40c0b83d..e2f102c20eb 100644
--- a/source/blender/blenlib/BLI_scanfill.h
+++ b/source/blender/blenlib/BLI_scanfill.h
@@ -1,8 +1,4 @@
-/**
- * blenlib/BLI_scanfill.h mar 2001 Nzc
- *
- * Filling meshes.
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -34,6 +30,13 @@
#ifndef BLI_SCANFILL_H
#define BLI_SCANFILL_H
+/** \file BLI_storage.h
+ * \ingroup bli
+ * \since March 2001
+ * \author nzc
+ * \brief Filling meshes.
+ */
+
/**
* @attention Defined in scanfill.c
*/
@@ -50,7 +53,7 @@ extern "C" {
/* scanfill.c: used in displist only... */
struct EditVert *BLI_addfillvert(float *vec);
struct EditEdge *BLI_addfilledge(struct EditVert *v1, struct EditVert *v2);
-int BLI_edgefill(int mode, int mat_nr);
+int BLI_edgefill(int mat_nr);
void BLI_end_edgefill(void);
/* These callbacks are needed to make the lib finction properly */
@@ -61,7 +64,7 @@ void BLI_end_edgefill(void);
* @param f The function to use as callback
* @attention used in creator.c
*/
-void BLI_setErrorCallBack(void (*f)(char*));
+void BLI_setErrorCallBack(void (*f)(const char*));
/**
* Set a function to be able to interrupt the execution of processing
diff --git a/source/blender/blenlib/BLI_smallhash.h b/source/blender/blenlib/BLI_smallhash.h
index 27442b97ae8..2ab365eea0e 100755
--- a/source/blender/blenlib/BLI_smallhash.h
+++ b/source/blender/blenlib/BLI_smallhash.h
@@ -35,7 +35,7 @@
#include "MEM_guardedalloc.h"
#include "BLO_sys_types.h"
-#include "BKE_utildefines.h"
+#include "BLI_utildefines.h"
extern unsigned int hashsizes[];
#define NONHASH -25436536
diff --git a/source/blender/blenlib/BLI_storage.h b/source/blender/blenlib/BLI_storage.h
index 0d9db40fc97..017f9877baf 100644
--- a/source/blender/blenlib/BLI_storage.h
+++ b/source/blender/blenlib/BLI_storage.h
@@ -29,33 +29,32 @@
#ifndef BLI_STORAGE_H
#define BLI_STORAGE_H
-/* NOTE: these have to be defined before including unistd.h! */
-#ifndef __APPLE__
-#ifndef WIN32
-#ifndef _LARGEFILE_SOURCE
-#define _LARGEFILE_SOURCE
-#define _LARGEFILE64_SOURCE
-#define _FILE_OFFSET_BITS 64
-#endif
-#endif
+/** \file BLI_storage.h
+ * \ingroup bli
+ */
+
+#ifdef WIN32
+/* for size_t, only needed on win32 for some reason */
+#include <stddef.h>
#endif
struct direntry;
+
void BLI_adddirstrings(void);
-void BLI_builddir(char *dirname, char *relname);
+void BLI_builddir(const char *dirname, const char *relname);
int BLI_compare(struct direntry *entry1, struct direntry *entry2);
-int BLI_filesize(int file);
-int BLI_filepathsize(const char *path);
-double BLI_diskfree(char *dir);
-char *BLI_getwdN(char *dir);
+size_t BLI_filesize(int file);
+size_t BLI_filepathsize(const char *path);
+double BLI_diskfree(const char *dir);
+char *BLI_getwdN(char *dir, const int maxncpy);
-unsigned int BLI_getdir(char *dirname, struct direntry **filelist);
+unsigned int BLI_getdir(const char *dirname, struct direntry **filelist);
/**
* @attention Do not confuse with BLI_exists
*/
-int BLI_exist(char *name);
+int BLI_exist(const char *name);
/**
* Read a file as ASCII lines. An empty list is
* returned if the file cannot be opened or read.
@@ -67,9 +66,9 @@ int BLI_exist(char *name);
* @retval A list of strings representing the file lines.
*/
-int BLI_is_dir(char *file);
+int BLI_is_dir(const char *file);
-struct LinkNode *BLI_read_file_as_lines(char *name);
+struct LinkNode *BLI_read_file_as_lines(const char *name);
/**
* Free the list returned by BLI_read_file_as_lines.
diff --git a/source/blender/blenlib/BLI_storage_types.h b/source/blender/blenlib/BLI_storage_types.h
index bc3584db03e..0b8746b4c50 100644
--- a/source/blender/blenlib/BLI_storage_types.h
+++ b/source/blender/blenlib/BLI_storage_types.h
@@ -1,8 +1,4 @@
-/**
- * blenlib/BLI_storage_types.h
- *
- * Some types for dealing with directories
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -33,17 +29,12 @@
#ifndef BLI_STORAGE_TYPES_H
#define BLI_STORAGE_TYPES_H
-#include <sys/stat.h>
-
-#define HDRSIZE 512
-#define NAMSIZE 200
+/** \file BLI_storage_types.h
+ * \ingroup bli
+ * \brief Some types for dealing with directories.
+ */
-struct header{
- char name[NAMSIZE];
- unsigned int size;
- unsigned int chksum;
- char fill[HDRSIZE-NAMSIZE-2*sizeof(unsigned int)];
-};
+#include <sys/stat.h>
#if defined(WIN32) && !defined(FREE_WINDOWS)
typedef unsigned int mode_t;
@@ -77,14 +68,6 @@ struct direntry{
struct ImBuf *image;
};
-#define SELECT 1
-#define HIDDEN 1
-#define FIRST 1
-#define DESELECT 0
-#define NOT_YET 0
-#define VISIBLE 0
-#define LAST 0
-
struct dirlink
{
struct dirlink *next,*prev;
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index ccb10190816..36835e0c9ca 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -32,6 +32,10 @@
#ifndef BLI_STRING_H
#define BLI_STRING_H
+/** \file BLI_string.h
+ * \ingroup bli
+ */
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -57,6 +61,14 @@ char *BLI_strdup(const char *str);
char *BLI_strdupn(const char *str, int len);
/**
+ * Appends the two strings, and returns new mallocN'ed string
+ * @param str1 first string for copy
+ * @param str2 second string for append
+ * @retval Returns dst
+ */
+char *BLI_strdupcat(const char *str1, const char *str2);
+
+ /**
* Like strncpy but ensures dst is always
* '\0' terminated.
*
@@ -66,15 +78,7 @@ char *BLI_strdupn(const char *str, int len);
* the size of dst)
* @retval Returns dst
*/
-char *BLI_strdupcat(const char *str1, const char *str2);
-
- /**
- * Appends the two strings, and returns new mallocN'ed string
- * @param str1 first string for copy
- * @param str2 second string for append
- * @retval Returns dst
- */
-char *BLI_strncpy(char *dst, const char *src, int maxncpy);
+char *BLI_strncpy(char *dst, const char *src, const int maxncpy);
/* Makes a copy of the text within the "" that appear after some text 'blahblah'
* i.e. for string 'pose["apples"]' with prefix 'pose[', it should grab "apples"
@@ -102,13 +106,21 @@ char *BLI_replacestr(char *str, const char *oldText, const char *newText);
/*
* Replacement for snprintf
*/
-int BLI_snprintf(char *buffer, size_t count, const char *format, ...);
+int BLI_snprintf(char *buffer, size_t count, const char *format, ...)
+#ifdef __GNUC__
+__attribute__ ((format (printf, 3, 4)));
+#endif
+;
/*
* Print formatted string into a newly mallocN'd string
* and return it.
*/
-char *BLI_sprintfN(const char *format, ...);
+char *BLI_sprintfN(const char *format, ...)
+#ifdef __GNUC__
+__attribute__ ((format (printf, 1, 2)));
+#endif
+;
/**
* Compare two strings
diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h
index 6a0a711404c..5bf5423d312 100644
--- a/source/blender/blenlib/BLI_threads.h
+++ b/source/blender/blenlib/BLI_threads.h
@@ -31,6 +31,10 @@
#ifndef BLI_THREADS_H
#define BLI_THREADS_H
+/** \file BLI_threads.h
+ * \ingroup bli
+ */
+
#include <pthread.h>
/* for tables, button in UI, etc */
@@ -121,7 +125,7 @@ void BLI_insert_work(struct ThreadedWorker *worker, void *param);
typedef struct ThreadQueue ThreadQueue;
-ThreadQueue *BLI_thread_queue_init();
+ThreadQueue *BLI_thread_queue_init(void);
void BLI_thread_queue_free(ThreadQueue *queue);
void BLI_thread_queue_push(ThreadQueue *queue, void *work);
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
new file mode 100644
index 00000000000..b2129a6ab76
--- /dev/null
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -0,0 +1,227 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+*/
+
+#ifndef BLI_UTILDEFINES_H
+#define BLI_UTILDEFINES_H
+
+/** \file BLI_utildefines.h
+ * \ingroup bli
+ */
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+
+#define ELEM(a, b, c) ( (a)==(b) || (a)==(c) )
+#define ELEM3(a, b, c, d) ( ELEM(a, b, c) || (a)==(d) )
+#define ELEM4(a, b, c, d, e) ( ELEM(a, b, c) || ELEM(a, d, e) )
+#define ELEM5(a, b, c, d, e, f) ( ELEM(a, b, c) || ELEM3(a, d, e, f) )
+#define ELEM6(a, b, c, d, e, f, g) ( ELEM(a, b, c) || ELEM4(a, d, e, f, g) )
+#define ELEM7(a, b, c, d, e, f, g, h) ( ELEM3(a, b, c, d) || ELEM4(a, e, f, g, h) )
+#define ELEM8(a, b, c, d, e, f, g, h, i) ( ELEM4(a, b, c, d, e) || ELEM4(a, f, g, h, i) )
+#define ELEM9(a, b, c, d, e, f, g, h, i, j) ( ELEM4(a, b, c, d, e) || ELEM5(a, f, g, h, i, j) )
+#define ELEM10(a, b, c, d, e, f, g, h, i, j, k) ( ELEM4(a, b, c, d, e) || ELEM6(a, f, g, h, i, j, k) )
+#define ELEM11(a, b, c, d, e, f, g, h, i, j, k, l) ( ELEM4(a, b, c, d, e) || ELEM7(a, f, g, h, i, j, k, l) )
+
+/* shift around elements */
+#define SHIFT3(type, a, b, c) { type tmp; tmp = a; a = c; c = b; b = tmp; }
+#define SHIFT4(type, a, b, c, d) { type tmp; tmp = a; a = d; d = c; c = b; b = tmp; }
+
+/* min/max */
+#define MIN2(x,y) ( (x)<(y) ? (x) : (y) )
+#define MIN3(x,y,z) MIN2( MIN2((x),(y)) , (z) )
+#define MIN4(x,y,z,a) MIN2( MIN2((x),(y)) , MIN2((z),(a)) )
+
+#define MAX2(x,y) ( (x)>(y) ? (x) : (y) )
+#define MAX3(x,y,z) MAX2( MAX2((x),(y)) , (z) )
+#define MAX4(x,y,z,a) MAX2( MAX2((x),(y)) , MAX2((z),(a)) )
+
+#define INIT_MINMAX(min, max) { (min)[0]= (min)[1]= (min)[2]= 1.0e30f; (max)[0]= (max)[1]= (max)[2]= -1.0e30f; }
+
+#define INIT_MINMAX2(min, max) { (min)[0]= (min)[1]= 1.0e30f; (max)[0]= (max)[1]= -1.0e30f; }
+
+#define DO_MIN(vec, min) { if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
+ if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
+ if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; } \
+
+#define DO_MAX(vec, max) { if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
+ if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \
+ if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; } \
+
+#define DO_MINMAX(vec, min, max) { if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
+ if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
+ if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; \
+ if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
+ if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \
+ if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; } \
+
+#define DO_MINMAX2(vec, min, max) { if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
+ if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
+ if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
+ if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; }
+
+/* some math and copy defines */
+
+#ifndef SWAP
+#define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; }
+#endif
+
+#define ABS(a) ( (a)<0 ? (-(a)) : (a) )
+
+#define AVG2(x, y) ( 0.5 * ((x) + (y)) )
+
+#define FTOCHAR(val) ((val)<=0.0f)? 0 : (((val)>(1.0f-0.5f/255.0f))? 255 : (char)((255.0f*(val))+0.5f))
+#define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0: (unsigned short)(val*65535.0f + 0.5f))
+
+#define VECCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2);}
+#define VECCOPY2D(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1);}
+#define QUATCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2); *(v1+3)= *(v2+3);}
+#define LONGCOPY(a, b, c) {int lcpc=c, *lcpa=(int *)a, *lcpb=(int *)b; while(lcpc-->0) *(lcpa++)= *(lcpb++);}
+
+
+#define VECADD(v1,v2,v3) {*(v1)= *(v2) + *(v3); *(v1+1)= *(v2+1) + *(v3+1); *(v1+2)= *(v2+2) + *(v3+2);}
+#define VECSUB(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1); *(v1+2)= *(v2+2) - *(v3+2);}
+#define VECSUB2D(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1);}
+#define VECADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac);}
+#define VECSUBFAC(v1,v2,v3,fac) {*(v1)= *(v2) - *(v3)*(fac); *(v1+1)= *(v2+1) - *(v3+1)*(fac); *(v1+2)= *(v2+2) - *(v3+2)*(fac);}
+#define QUATADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac); *(v1+3)= *(v2+3) + *(v3+3)*(fac);}
+
+#define INPR(v1, v2) ( (v1)[0]*(v2)[0] + (v1)[1]*(v2)[1] + (v1)[2]*(v2)[2] )
+
+/* some misc stuff.... */
+#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c)
+#define CLAMPIS(a, b, c) ((a)<(b) ? (b) : (a)>(c) ? (c) : (a))
+#define CLAMPTEST(a, b, c) if((b)<(c)) {CLAMP(a, b, c);} else {CLAMP(a, c, b);}
+
+#define IS_EQ(a,b) ((fabs((double)(a)-(b)) >= (double) FLT_EPSILON) ? 0 : 1)
+
+#define IS_EQT(a, b, c) ((a > b)? (((a-b) <= c)? 1:0) : ((((b-a) <= c)? 1:0)))
+#define IN_RANGE(a, b, c) ((b < c)? ((b<a && a<c)? 1:0) : ((c<a && a<b)? 1:0))
+#define IN_RANGE_INCL(a, b, c) ((b < c)? ((b<=a && a<=c)? 1:0) : ((c<=a && a<=b)? 1:0))
+
+
+/* This one rotates the bytes in an int64, int (32) and short (16) */
+#define SWITCH_INT64(a) { \
+ char s_i, *p_i; \
+ p_i= (char *)&(a); \
+ s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \
+ s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \
+ s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \
+ s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; }
+
+ #define SWITCH_INT(a) { \
+ char s_i, *p_i; \
+ p_i= (char *)&(a); \
+ s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \
+ s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; }
+
+#define SWITCH_SHORT(a) { \
+ char s_i, *p_i; \
+ p_i= (char *)&(a); \
+ s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; }
+
+
+/* Warning-free macros for storing ints in pointers. Use these _only_
+ * for storing an int in a pointer, not a pointer in an int (64bit)! */
+#define SET_INT_IN_POINTER(i) ((void*)(intptr_t)(i))
+#define GET_INT_FROM_POINTER(i) ((int)(intptr_t)(i))
+
+/* Macro to convert a value to string in the preprocessor
+ * STRINGIFY_ARG: gives the defined name in the string
+ * STRINGIFY: gives the defined value. */
+#define STRINGIFY_ARG(x) #x
+#define STRINGIFY(x) STRINGIFY_ARG(x)
+
+/* useful for debugging */
+#define AT __FILE__ ":" STRINGIFY(__LINE__)
+
+/* UNUSED macro, for function argument */
+#ifdef __GNUC__
+# define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
+#else
+# define UNUSED(x) UNUSED_ ## x
+#endif
+
+#ifdef __GNUC__
+# define WARN_UNUSED __attribute__((warn_unused_result))
+#else
+# define WARN_UNUSED
+#endif
+
+/*little macro so inline keyword works*/
+#if defined(_MSC_VER)
+# define BM_INLINE static __forceinline
+#elif defined(__GNUC__)
+# define BM_INLINE static inline __attribute((always_inline))
+#else
+/* #warning "MSC/GNUC defines not found, inline non-functional" */
+# define BM_INLINE static
+#endif
+
+
+/* BLI_assert(), default only to print
+ * for aborting need to define WITH_ASSERT_ABORT
+ */
+#if !defined NDEBUG
+# ifdef WITH_ASSERT_ABORT
+# define _dummy_abort abort
+# else
+# define _dummy_abort() (void)0
+# endif
+# ifdef __GNUC__ /* just want to check if __func__ is available */
+# define BLI_assert(a) \
+do { \
+ if (0 == (a)) { \
+ fprintf(stderr, \
+ "BLI_assert failed: %s, %s(), %d at \'%s\'\n", \
+ __FILE__, __func__, __LINE__, STRINGIFY(a)); \
+ _dummy_abort(); \
+ } \
+} while (0)
+# else
+# define BLI_assert(a) \
+do { \
+ if (0 == (a)) { \
+ fprintf(stderr, \
+ "BLI_assert failed: %s, %d at \'%s\'\n", \
+ __FILE__, __LINE__, STRINGIFY(a)); \
+ _dummy_abort(); \
+ } \
+} while (0)
+# endif
+#else
+# define BLI_assert(a) (void)0
+#endif
+
+#endif // BLI_UTILDEFINES_H
diff --git a/source/blender/blenlib/BLI_uvproject.h b/source/blender/blenlib/BLI_uvproject.h
index cf8bb7cd4b8..54e2090aa50 100644
--- a/source/blender/blenlib/BLI_uvproject.h
+++ b/source/blender/blenlib/BLI_uvproject.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -22,6 +22,10 @@
#ifndef BKE_UVPROJECT_H
#define BKE_UVPROJECT_H
+/** \file BLI_uvproject.h
+ * \ingroup bli
+ */
+
struct UvCameraInfo;
struct Object;
diff --git a/source/blender/blenlib/BLI_vfontdata.h b/source/blender/blenlib/BLI_vfontdata.h
index 77abb15b953..7a03c1c37fa 100644
--- a/source/blender/blenlib/BLI_vfontdata.h
+++ b/source/blender/blenlib/BLI_vfontdata.h
@@ -1,9 +1,4 @@
-/**
- * @file BLI_vfontdata.h
- *
- * A structure to represent vector fonts,
- * and to load them from PostScript fonts.
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -35,6 +30,12 @@
#ifndef BLI_VFONTDATA_H
#define BLI_VFONTDATA_H
+/** \file BLI_vfontdata.h
+ * \ingroup bli
+ * \brief A structure to represent vector fonts,
+ * and to load them from PostScript fonts.
+ */
+
#include "DNA_listBase.h"
struct PackedFile;
diff --git a/source/blender/blenlib/BLI_voxel.h b/source/blender/blenlib/BLI_voxel.h
index 63a6c09b0b4..41f8bfab729 100644
--- a/source/blender/blenlib/BLI_voxel.h
+++ b/source/blender/blenlib/BLI_voxel.h
@@ -1,5 +1,4 @@
-/**
- *
+/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
@@ -29,7 +28,11 @@
#ifndef BLI_VOXEL_H
#define BLI_VOXEL_H
-/* find the index number of a voxel, given x/y/z integer coords and resolution vector */
+/** \file BLI_voxel.h
+ * \ingroup bli
+ */
+
+/** find the index number of a voxel, given x/y/z integer coords and resolution vector */
#define V_I(x, y, z, res) ( (z)*(res)[1]*(res)[0] + (y)*(res)[0] + (x) )
/* all input coordinates must be in bounding box 0.0 - 1.0 */
diff --git a/source/blender/blenlib/BLI_winstuff.h b/source/blender/blenlib/BLI_winstuff.h
index e8689895735..0248a6a6b4d 100644
--- a/source/blender/blenlib/BLI_winstuff.h
+++ b/source/blender/blenlib/BLI_winstuff.h
@@ -1,6 +1,4 @@
-/**
- * Compatibility-like things for windows.
- *
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -32,15 +30,28 @@
#ifndef __WINSTUFF_H__
#define __WINSTUFF_H__
+/** \file BLI_winstuff.h
+ * \ingroup bli
+ * \brief Compatibility-like things for windows.
+ */
+
#ifdef _WIN32
#ifndef FREE_WINDOWS
#pragma warning(once: 4761 4305 4244 4018)
+#else
+#ifdef WINVER
+#undef WINVER
+#endif
+
+/* Some stuff requires WINVER 0x500, but mingw's default is 0x400 */
+#define WINVER 0x0501
#endif
#define WIN32_LEAN_AND_MEAN
#ifndef WIN32_SKIP_HKEY_PROTECTION
+#undef HKEY
#define HKEY WIN32_HKEY // prevent competing definitions
#include <windows.h>
#undef HKEY
@@ -81,15 +92,6 @@ extern "C" {
#endif
/* defines for using ISO C++ conformant names */
-#define open _open
-#define close _close
-#define write _write
-#define read _read
-#define getcwd _getcwd
-#define chdir _chdir
-#define strdup _strdup
-#define lseek _lseek
-#define getpid _getpid
#define snprintf _snprintf
#ifndef FREE_WINDOWS
@@ -133,15 +135,13 @@ void get_default_root(char *root);
int check_file_chars(char *filename);
char *dirname(char *path);
-#ifdef WIN32
int BLI_getInstallationDir(char *str);
-#endif
#ifdef __cplusplus
}
#endif
-#endif
+#endif /* _WIN32 */
#endif /* __WINSTUFF_H__ */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index ae3057acc84..ff024fc9ea4 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -24,28 +24,123 @@
#
# ***** END GPL LICENSE BLOCK *****
-FILE(GLOB SRC intern/*.c)
-
-SET(INC
- . ../makesdna ../blenkernel ../../../intern/guardedalloc ../include
- ../gpu ../../../intern/ghost ../bmesh
+set(INC
+ .
+ ../makesdna
+ ../blenkernel
+ ../blenloader
+ ../gpu
+ ../../../intern/ghost
+ ../../../intern/guardedalloc
+ ${ZLIB_INCLUDE_DIRS}
${FREETYPE_INCLUDE_DIRS}
- ${ZLIB_INC}
)
-IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
-SET(INC
- ${INC}
- ${BINRELOC_INC}
+set(SRC
+ intern/BLI_args.c
+ intern/BLI_dynstr.c
+ intern/BLI_ghash.c
+ intern/BLI_heap.c
+ intern/BLI_kdopbvh.c
+ intern/BLI_kdtree.c
+ intern/BLI_linklist.c
+ intern/BLI_memarena.c
+ intern/BLI_mempool.c
+ intern/BLI_cellalloc.c
+ intern/DLRB_tree.c
+ intern/boxpack2d.c
+ intern/bpath.c
+ intern/cpu.c
+ intern/dynlib.c
+ intern/edgehash.c
+ intern/fileops.c
+ intern/fnmatch.c
+ intern/freetypefont.c
+ intern/graph.c
+ intern/gsqueue.c
+ intern/jitter.c
+ intern/listbase.c
+ intern/math_base.c
+ intern/math_base_inline.c
+ intern/math_color.c
+ intern/math_geom.c
+ intern/math_geom_inline.c
+ intern/math_matrix.c
+ intern/math_rotation.c
+ intern/math_vector.c
+ intern/math_vector_inline.c
+ intern/noise.c
+ intern/path_util.c
+ intern/pbvh.c
+ intern/rand.c
+ intern/rct.c
+ intern/scanfill.c
+ intern/storage.c
+ intern/string.c
+ intern/threads.c
+ intern/time.c
+ intern/uvproject.c
+ intern/voxel.c
+ intern/winstuff.c
+
+ BLI_args.h
+ BLI_blenlib.h
+ BLI_boxpack2d.h
+ BLI_bpath.h
+ BLI_cpu.h
+ BLI_dlrbTree.h
+ BLI_dynstr.h
+ BLI_edgehash.h
+ BLI_editVert.h
+ BLI_fileops.h
+ BLI_fnmatch.h
+ BLI_ghash.h
+ BLI_graph.h
+ BLI_gsqueue.h
+ BLI_heap.h
+ BLI_jitter.h
+ BLI_kdopbvh.h
+ BLI_kdtree.h
+ BLI_linklist.h
+ BLI_listbase.h
+ BLI_math.h
+ BLI_math_base.h
+ BLI_math_color.h
+ BLI_math_geom.h
+ BLI_math_inline.h
+ BLI_math_matrix.h
+ BLI_math_rotation.h
+ BLI_math_vector.h
+ BLI_memarena.h
+ BLI_mempool.h
+ BLI_noise.h
+ BLI_path_util.h
+ BLI_pbvh.h
+ BLI_rand.h
+ BLI_rect.h
+ BLI_scanfill.h
+ BLI_storage.h
+ BLI_storage_types.h
+ BLI_string.h
+ BLI_threads.h
+ BLI_utildefines.h
+ BLI_uvproject.h
+ BLI_vfontdata.h
+ BLI_voxel.h
+ BLI_winstuff.h
+ PIL_dynlib.h
+ PIL_time.h
+ intern/BLI_callbacks.h
+ intern/dynamiclist.h
)
-ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
-IF(WIN32)
- SET(INC ${INC} ${PTHREADS_INC})
-ENDIF(WIN32)
+if(WITH_BINRELOC)
+ add_definitions(-DWITH_BINRELOC)
+ list(APPEND INC "${BINRELOC_INC}")
+endif()
-IF(WITH_OPENMP)
- ADD_DEFINITIONS(-DPARALLEL=1)
-ENDIF(WITH_OPENMP)
+if(WITH_OPENMP)
+ add_definitions(-DPARALLEL=1)
+endif()
-BLENDERLIB(bf_blenlib "${SRC}" "${INC}")
+blender_add_lib(bf_blenlib "${SRC}" "${INC}")
diff --git a/source/blender/blenlib/Makefile b/source/blender/blenlib/Makefile
deleted file mode 100644
index d4dcfaeeabf..00000000000
--- a/source/blender/blenlib/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# $Id$
-#
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): none yet.
-#
-# ***** END GPL LICENSE BLOCK *****
-#
-# Bounces make to subdirectories.
-
-SOURCEDIR = source/blender/blenlib
-DIRS = intern
-
-include nan_subdirs.mk
diff --git a/source/blender/blenlib/PIL_dynlib.h b/source/blender/blenlib/PIL_dynlib.h
index 1a6e1e20184..87eda213fd8 100644
--- a/source/blender/blenlib/PIL_dynlib.h
+++ b/source/blender/blenlib/PIL_dynlib.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -38,7 +38,7 @@ PIL_dynlib_open(
void*
PIL_dynlib_find_symbol(
PILdynlib* lib,
- char *symname);
+ const char *symname);
char*
PIL_dynlib_get_error_as_string(
diff --git a/source/blender/blenlib/PIL_time.h b/source/blender/blenlib/PIL_time.h
index 2d5948c4217..6cb4cf6ffcf 100644
--- a/source/blender/blenlib/PIL_time.h
+++ b/source/blender/blenlib/PIL_time.h
@@ -1,4 +1,4 @@
-/**
+/*
* @file PIL_time.h
*
* Platform independant time functions.
diff --git a/source/blender/blenlib/SConscript b/source/blender/blenlib/SConscript
index c319b1923bd..b84c6866192 100644
--- a/source/blender/blenlib/SConscript
+++ b/source/blender/blenlib/SConscript
@@ -4,16 +4,21 @@ Import ('env')
sources = env.Glob('intern/*.c')
cflags=''
-incs = '. ../makesdna ../blenkernel #/intern/guardedalloc #/intern/ghost ../editors/include ../gpu'
+incs = '. ../makesdna ../blenkernel #/intern/guardedalloc #/intern/ghost ../editors/include ../gpu ../blenloader'
incs += ' ../windowmanager ../bmesh #/extern/glew/include'
incs += ' ' + env['BF_FREETYPE_INC']
incs += ' ' + env['BF_ZLIB_INC']
+<<<<<<< .working
defs = 'GLEW_STATIC'
+=======
+defs = []
+>>>>>>> .merge-right.r35190
-if env['OURPLATFORM'] == 'linux2':
+if env['WITH_BF_BINRELOC']:
cflags='-pthread'
incs += ' ../../../extern/binreloc/include'
+ defs.append('WITH_BINRELOC')
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
incs += ' ' + env['BF_PTHREADS_INC']
diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c
index 8d72311f80b..4c059c62475 100644
--- a/source/blender/blenlib/intern/BLI_args.c
+++ b/source/blender/blenlib/intern/BLI_args.c
@@ -1,4 +1,4 @@
-/**
+/*
* A general argument parsing module
*
* $Id$
@@ -35,22 +35,23 @@
#include "BLI_listbase.h"
#include "BLI_string.h"
+#include "BLI_utildefines.h"
#include "BLI_args.h"
#include "BLI_ghash.h"
-char NO_DOCS[] = "NO DOCUMENTATION SPECIFIED";
+static char NO_DOCS[] = "NO DOCUMENTATION SPECIFIED";
struct bArgDoc;
typedef struct bArgDoc {
struct bArgDoc *next, *prev;
- char *short_arg;
- char *long_arg;
- char *documentation;
+ const char *short_arg;
+ const char *long_arg;
+ const char *documentation;
int done;
} bArgDoc;
typedef struct bAKey {
- char *arg;
+ const char *arg;
uintptr_t pass; /* cast easier */
int case_str; /* case specific or not */
} bAKey;
@@ -66,12 +67,12 @@ struct bArgs {
ListBase docs;
GHash *items;
int argc;
- char **argv;
+ const char **argv;
int *passes;
};
-static unsigned int case_strhash(void *ptr) {
- char *s= ptr;
+static unsigned int case_strhash(const void *ptr) {
+ const char *s= ptr;
unsigned int i= 0;
unsigned char c;
@@ -81,27 +82,27 @@ static unsigned int case_strhash(void *ptr) {
return i;
}
-static unsigned int keyhash(void *ptr)
+static unsigned int keyhash(const void *ptr)
{
- bAKey *k = ptr;
+ const bAKey *k = ptr;
return case_strhash(k->arg); // ^ BLI_ghashutil_inthash((void*)k->pass);
}
-static int keycmp(void *a, void *b)
+static int keycmp(const void *a, const void *b)
{
- bAKey *ka = a;
- bAKey *kb = b;
+ const bAKey *ka = a;
+ const bAKey *kb = b;
if (ka->pass == kb->pass || ka->pass == -1 || kb->pass == -1) { /* -1 is wildcard for pass */
if (ka->case_str == 1 || kb->case_str == 1)
return BLI_strcasecmp(ka->arg, kb->arg);
else
return strcmp(ka->arg, kb->arg);
} else {
- return BLI_ghashutil_intcmp((void*)ka->pass, (void*)kb->pass);
+ return BLI_ghashutil_intcmp((const void*)ka->pass, (const void*)kb->pass);
}
}
-static bArgument *lookUp(struct bArgs *ba, char *arg, int pass, int case_str)
+static bArgument *lookUp(struct bArgs *ba, const char *arg, int pass, int case_str)
{
bAKey key;
@@ -112,7 +113,7 @@ static bArgument *lookUp(struct bArgs *ba, char *arg, int pass, int case_str)
return BLI_ghash_lookup(ba->items, &key);
}
-bArgs *BLI_argsInit(int argc, char **argv)
+bArgs *BLI_argsInit(int argc, const char **argv)
{
bArgs *ba = MEM_callocN(sizeof(bArgs), "bArgs");
ba->passes = MEM_callocN(sizeof(int) * argc, "bArgs passes");
@@ -145,12 +146,12 @@ void BLI_argsPrint(struct bArgs *ba)
}
}
-char **BLI_argsArgv(struct bArgs *ba)
+const char **BLI_argsArgv(struct bArgs *ba)
{
return ba->argv;
}
-static bArgDoc *internalDocs(struct bArgs *ba, char *short_arg, char *long_arg, char *doc)
+static bArgDoc *internalDocs(struct bArgs *ba, const char *short_arg, const char *long_arg, const char *doc)
{
bArgDoc *d;
@@ -168,7 +169,7 @@ static bArgDoc *internalDocs(struct bArgs *ba, char *short_arg, char *long_arg,
return d;
}
-static void internalAdd(struct bArgs *ba, char *arg, int pass, int case_str, BA_ArgCallback cb, void *data, bArgDoc *d)
+static void internalAdd(struct bArgs *ba, const char *arg, int pass, int case_str, BA_ArgCallback cb, void *data, bArgDoc *d)
{
bArgument *a;
bAKey *key;
@@ -196,7 +197,7 @@ static void internalAdd(struct bArgs *ba, char *arg, int pass, int case_str, BA_
BLI_ghash_insert(ba->items, key, a);
}
-void BLI_argsAddCase(struct bArgs *ba, int pass, char *short_arg, int short_case, char *long_arg, int long_case, char *doc, BA_ArgCallback cb, void *data)
+void BLI_argsAddCase(struct bArgs *ba, int pass, const char *short_arg, int short_case, const char *long_arg, int long_case, const char *doc, BA_ArgCallback cb, void *data)
{
bArgDoc *d = internalDocs(ba, short_arg, long_arg, doc);
@@ -209,7 +210,7 @@ void BLI_argsAddCase(struct bArgs *ba, int pass, char *short_arg, int short_case
}
-void BLI_argsAdd(struct bArgs *ba, int pass, char *short_arg, char *long_arg, char *doc, BA_ArgCallback cb, void *data)
+void BLI_argsAdd(struct bArgs *ba, int pass, const char *short_arg, const char *long_arg, const char *doc, BA_ArgCallback cb, void *data)
{
BLI_argsAddCase(ba, pass, short_arg, 0, long_arg, 0, doc, cb, data);
}
@@ -226,7 +227,7 @@ static void internalDocPrint(bArgDoc *d)
printf(" %s\n\n", d->documentation);
}
-void BLI_argsPrintArgDoc(struct bArgs *ba, char *arg)
+void BLI_argsPrintArgDoc(struct bArgs *ba, const char *arg)
{
bArgument *a = lookUp(ba, arg, -1, -1);
diff --git a/source/blender/blenlib/intern/BLI_bfile.c b/source/blender/blenlib/intern/BLI_bfile.c
deleted file mode 100644
index b9ac6875b20..00000000000
--- a/source/blender/blenlib/intern/BLI_bfile.c
+++ /dev/null
@@ -1,372 +0,0 @@
-/* -*- indent-tabs-mode:t; tab-width:4; -*-
- *
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 by Stichting Blender Foundation.
- * All rights reserved.
- *
- * ***** END GPL LICENSE BLOCK *****
- * BFILE* based abstraction for file access.
- */
-
-#include <string.h>
-#include <stdlib.h>
-#ifndef WIN32
- #include <libgen.h>
- #include <unistd.h>
- #include <sys/param.h>
-#else
- #include <io.h>
- #include "BLI_winstuff.h"
- static char* find_in_pathlist(char* filename, char* pathlist);
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include "MEM_guardedalloc.h"
-#include "BKE_utildefines.h"
-#include "BKE_blender.h"
-#include "BLI_path_util.h"
-#include "BLI_fileops.h"
-#include "BLI_storage.h"
-#include "BLI_bfile.h"
-
-/* Internal bfile classification flags */
-#define BCF_OPEN (0)
-#define BCF_FOPEN (1<<0)
-#define BCF_READ (1<<1)
-#define BCF_WRITE (1<<2)
-#define BCF_AT_END (1<<3)
-#define BCF_DISCARD (1<<4)
-
-/* Standard files names */
-#define LAST_SESSION_FILE "last-session"
-#define ENVIRONMENT_FILE "environment"
-
-
-/* Declaration of internal functions */
-static void fill_paths(BFILE *bfile, const char *path, const char *relpath);
-static void free_paths(BFILE* bfile);
-
-
-/*** Exported functions ***/
-
-BFILE *BLI_bfile_fopen(const char *path, const char *mode, int bflags,
- const char *relpath)
-{
- BFILE *bfile;
-
- bfile = MEM_mallocN(sizeof(BFILE), "bfile-fopen");
- bfile->classf = BCF_FOPEN;
- bfile->uflags = bflags;
-
- /* From fopen() doc, we can guess some logic:
- r BCF_READ
- r+ BCF_READ | BCF_WRITE
- w BCF_DISCARD | BCF_WRITE
- w+ BCF_DISCARD | BCF_WRITE | BCF_READ
- a BCF_AT_END | BCF_WRITE
- a+ BCF_AT_END | BCF_WRITE | BCF_READ
- */
- if (strchr(mode, 'r'))
- bfile->classf |= BCF_READ;
- if (strchr(mode, 'w'))
- bfile->classf |= (BCF_DISCARD | BCF_WRITE);
- if (strchr(mode, 'a'))
- bfile->classf |= (BCF_AT_END | BCF_WRITE);
- if (strchr(mode, '+'))
- bfile->classf |= (BCF_READ | BCF_WRITE);
-
- fill_paths(bfile, path, relpath);
-
- bfile->stream = fopen(bfile->tpath, mode);
- if (!(bfile->stream)) {
- free_paths(bfile);
- MEM_freeN(bfile);
- return NULL;
- }
-
- bfile->fd = fileno(bfile->stream);
-
- return bfile;
-}
-
-
-BFILE *BLI_bfile_open(const char *pathname, int flags, int bflags,
- const char *relpath)
-{
- BFILE *bfile;
- char fopen_mode[3];
-
- bfile = MEM_mallocN(sizeof(BFILE), "bfile-open");
- bfile->classf = BCF_OPEN;
- bfile->uflags = bflags;
-
- /* Easy mapping for open() */
- if (flags & O_RDONLY)
- bfile->classf |= BCF_READ;
- if (flags & O_WRONLY)
- bfile->classf |= BCF_WRITE;
- if (flags & O_RDWR)
- bfile->classf |= (BCF_READ | BCF_WRITE);
- if (flags & O_APPEND)
- bfile->classf |= BCF_AT_END;
- if (flags & O_TRUNC)
- bfile->classf |= BCF_DISCARD;
-
- fill_paths(bfile, pathname, relpath);
-
- bfile->fd = open(bfile->tpath, flags);
- if (bfile->fd == -1) {
- free_paths(bfile);
- MEM_freeN(bfile);
- return NULL;
- }
-
- fopen_mode[0] = 'r';
- fopen_mode[1] = '\0';
- fopen_mode[2] = '\0';
- if (bfile->classf & BCF_DISCARD) {
- fopen_mode[0] = 'w';
- if (bfile->classf & BCF_READ) {
- fopen_mode[1] = '+';
- }
- } else if (bfile->classf & BCF_AT_END) {
- fopen_mode[0] = 'a';
- if (bfile->classf & BCF_READ) {
- fopen_mode[1] = '+';
- }
- } else if (bfile->classf & BCF_WRITE) {
- fopen_mode[1] = '+';
- }
-
- bfile->stream = fdopen(bfile->fd, fopen_mode); /* MSWindows _fdopen? */
- if (!(bfile->stream)) {
- free_paths(bfile);
- MEM_freeN(bfile);
- return NULL;
- }
-
- return bfile;
-}
-
-
-FILE *BLI_bfile_file_from_bfile(BFILE *bfile) {
- return bfile->stream;
-}
-
-
-int BLI_bfile_fd_from_bfile(BFILE *bfile) {
- return bfile->fd;
-}
-
-
-ssize_t BLI_bfile_write(BFILE *f, const void *buf, size_t count) {
- ssize_t ret;
-
- ret = write((f->fd), buf, count);
- if (ret == -1) {
- f->error = 1;
- }
-
- return ret;
-}
-
-
-ssize_t BLI_bfile_read(BFILE *f, void *buf, size_t count) {
- ssize_t ret;
-
- ret = read((f->fd), buf, count);
- if (ret == -1) {
- f->error = 1;
- }
-
- return ret;
-}
-
-
-size_t BLI_bfile_fwrite(const void *ptr, size_t size, size_t nmemb,
- BFILE *f)
-{
- size_t ret;
-
- if (f == NULL)
- return 0;
-
- ret = fwrite(ptr, size, nmemb, f->stream);
- if (ret <= 0) {
- f->error = 1;
- }
-
- return ret;
-}
-
-
-size_t BLI_bfile_fread(void *ptr, size_t size, size_t nmemb, BFILE *f) {
- size_t ret;
-
- if (f == NULL)
- return 0;
-
- ret = fread(ptr, size, nmemb, f->stream);
- if ((ret <= 0) && ferror(f->stream)) {
- f->error = 1;
- }
-
- return ret;
-}
-
-
-void BLI_bfile_close(BFILE *bfile) {
- if ((bfile->classf | BCF_WRITE) &&
- !(bfile->uflags | BFILE_RAW)) {
- int error;
- /* Make sure data is on disk */
- error = fsync(bfile->fd);
- /* fsync the directory too? */
- /* Move to final name if no errors */
- if (!(bfile->error) && !error) {
- rename(bfile->tpath, bfile->fpath);
- }
- }
-
- /* Normal close */
-
- /* Cleanup */
- free_paths(bfile);
- MEM_freeN(bfile);
-}
-
-
-void BLI_bfile_clear_error(BFILE *bfile) {
- bfile->error = 0;
-}
-
-
-void BLI_bfile_set_error(BFILE *bfile, int error) {
- /* No cheating, use clear_error() for 0 */
- if (error) {
- bfile->error = error;
- }
-}
-
-
-/*** Internal functions ***/
-
-/**
- Return a full path if the filename exists when combined
- with any item from pathlist. Or NULL otherwise.
- */
-#ifdef WIN32
- #define SEPARATOR ';'
-#else
- #define SEPARATOR ':'
-#endif
-
-#ifdef WIN32
-static char* find_in_pathlist(char* filename, char* pathlist) {
- char first[FILE_MAX + 10];
- char* rest = NULL;
-
- /* Separate first path from rest, use typical separator for current OS */
- rest = strchr(pathlist, SEPARATOR);
- if (rest) {
- strncpy(first, pathlist, rest - pathlist);
- first[rest - pathlist] = '\0';
- /* Skip the separator so it becomes a valid new pathlist */
- rest++;
- } else {
- strcpy(first, pathlist);
- }
-
- /* Check if combination exists */
- BLI_add_slash(first);
- strcat(first, filename);
- if (BLI_exist(first)) {
- return strdup(first);
- }
-
- /* First path failed, try with rest of paths if possible */
- if (rest) {
- return find_in_pathlist(filename, rest);
- } else {
- return NULL;
- }
-}
-#endif
-
-/**
- Setup fpath and tpath based in the needs of the bfile.
- */
-static void fill_paths(BFILE *bfile, const char *path, const char *relpath) {
- char* source_path = NULL;
- char* temp_path = NULL;
- int bflags = bfile->uflags;
-
- if (bflags & BFILE_NORMAL || bflags & BFILE_RAW) {
-// bfile->fpath is path with // replaced
- }
- if (bflags & BFILE_TEMP) {
- temp_path = MEM_mallocN(MAXPATHLEN, "bfile-fpath-1");
- snprintf(temp_path, MAXPATHLEN, "%s/%s", getenv("BLENDER_TEMP"), path);
- bfile->fpath = temp_path;
- }
- if (bflags & (BFILE_CONFIG_BASE | BFILE_CONFIG_DATAFILES |
- BFILE_CONFIG_PYTHON | BFILE_CONFIG_PLUGINS)) {
-// evars
-// bfile->fpath is userdir+version+path
-// source_path is first hit in (if using fallback to older versions)
-// userdir+curversion+path (... userdir+limitversion+path) sysdir+path
-// (limitversion is based in path, using some kind of regex or "tables")
- }
-
- if (bfile->classf & BCF_WRITE && !(bflags & BFILE_RAW)) {
- /* Generate random named path */
- temp_path = MEM_mallocN(MAXPATHLEN, "bfile-fpath-2");
- snprintf(temp_path, MAXPATHLEN, "%s.XXXXXX", path);
- bfile->fd = mkstemp(temp_path);
- bfile->tpath = temp_path;
- /* It will be reopened in upper levels, later */
- close(bfile->fd);
- if (!(bfile->classf & BCF_DISCARD)) {
- /* Copy original data into temp location */
- if (source_path) {
- BLI_copy_fileops(source_path, bfile->tpath);
- } else {
- BLI_copy_fileops(bfile->fpath, bfile->tpath);
- }
- }
- } else {
- bfile->tpath = bfile->fpath;
- }
-}
-
-
-/**
- Free memory used for path strings.
- */
-static void free_paths(BFILE* bfile) {
- if (bfile->fpath) {
- MEM_freeN(bfile->fpath);
- }
- if (bfile->tpath) {
- MEM_freeN(bfile->tpath);
- }
-}
diff --git a/source/blender/blenlib/intern/BLI_callbacks.h b/source/blender/blenlib/intern/BLI_callbacks.h
index 7f85cf16708..71f68d33f2f 100644
--- a/source/blender/blenlib/intern/BLI_callbacks.h
+++ b/source/blender/blenlib/intern/BLI_callbacks.h
@@ -1,4 +1,4 @@
-/**
+/*
* blenlib/BLI_editVert.h mar 2001 Nzc
*
* These callbacks are needed in the lib
@@ -35,7 +35,7 @@
#define BLI_CALLBACKS_H
// This is blenlib internal only
-void callLocalErrorCallBack(char* msg);
+void callLocalErrorCallBack(const char* msg);
#endif
diff --git a/source/blender/blenlib/intern/BLI_cellalloc.c b/source/blender/blenlib/intern/BLI_cellalloc.c
index 715c66fae7b..14237a1285b 100644
--- a/source/blender/blenlib/intern/BLI_cellalloc.c
+++ b/source/blender/blenlib/intern/BLI_cellalloc.c
@@ -149,19 +149,18 @@ void *BLI_cellalloc_dupalloc(void *mem)
{
MemHeader *memh = mem;
void *tmp;
- int slot;
#ifdef USE_GUARDEDALLOC
MEM_freeN(mem);
- return;
+ return NULL;
#endif
if (!memh)
- return;
+ return NULL;
memh--;
if (memh->idcheck != MEMIDCHECK) {
printf("Error in BLI_cellalloc: attempt to free invalid block.\n");
- return;
+ return NULL;
}
tmp = BLI_cellalloc_malloc(memh->size, memh->tag);
@@ -196,4 +195,4 @@ void BLI_cellalloc_destroy(void)
pools[i] = NULL;
}
}
-} \ No newline at end of file
+}
diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c
index 5b61a86305b..dcda7daacb3 100644
--- a/source/blender/blenlib/intern/BLI_dynstr.c
+++ b/source/blender/blenlib/intern/BLI_dynstr.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -41,6 +41,14 @@
#endif
#endif
+#ifndef va_copy
+# ifdef __va_copy
+# define va_copy(a,b) __va_copy(a,b)
+# else /* !__va_copy */
+# define va_copy(a,b) ((a)=(b))
+# endif /* __va_copy */
+#endif /* va_copy */
+
/***/
typedef struct DynStrElem DynStrElem;
@@ -101,15 +109,21 @@ void BLI_dynstr_nappend(DynStr *ds, const char *cstr, int len) {
void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args)
{
char *message, fixedmessage[256];
- int len= 256, maxlen= 65536, retval;
+ int len= sizeof(fixedmessage);
+ const int maxlen= 65536;
+ int retval;
while(1) {
+ va_list args_cpy;
if(len == sizeof(fixedmessage))
message= fixedmessage;
else
- message= MEM_callocN(sizeof(char)*(len+1), "BLI_dynstr_appendf");
+ message= MEM_callocN(sizeof(char) * len, "BLI_dynstr_appendf");
- retval= vsnprintf(message, len, format, args);
+ /* cant reuse the same args, so work on a copy */
+ va_copy(args_cpy, args);
+ retval= vsnprintf(message, len, format, args_cpy);
+ va_end(args_cpy);
if(retval == -1) {
/* -1 means not enough space, but on windows it may also mean
@@ -124,13 +138,14 @@ void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args)
break;
}
}
- else if(retval > len) {
+ else if(retval >= len) {
/* in C99 the actual length required is returned */
if(message != fixedmessage)
MEM_freeN(message);
message= NULL;
- len= retval;
+ /* retval doesnt include \0 terminator */
+ len= retval + 1;
}
else
break;
@@ -148,7 +163,9 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...)
{
va_list args;
char *message, fixedmessage[256];
- int len= 256, maxlen= 65536, retval;
+ int len= sizeof(fixedmessage);
+ const int maxlen= 65536;
+ int retval;
/* note that it's tempting to just call BLI_dynstr_vappendf here
* and avoid code duplication, that crashes on some system because
@@ -158,7 +175,7 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...)
if(len == sizeof(fixedmessage))
message= fixedmessage;
else
- message= MEM_callocN(sizeof(char)*(len+1), "BLI_dynstr_appendf");
+ message= MEM_callocN(sizeof(char)*(len), "BLI_dynstr_appendf");
va_start(args, format);
retval= vsnprintf(message, len, format, args);
@@ -177,13 +194,14 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...)
break;
}
}
- else if(retval > len) {
+ else if(retval >= len) {
/* in C99 the actual length required is returned */
if(message != fixedmessage)
MEM_freeN(message);
message= NULL;
- len= retval;
+ /* retval doesnt include \0 terminator */
+ len= retval + 1;
}
else
break;
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 32818505e5c..9148e356e2a 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -30,6 +30,7 @@
#include "MEM_guardedalloc.h"
+#include "BLI_utildefines.h"
#include "BLI_ghash.h"
#include "BLO_sys_types.h" // for intptr_t support
/***/
@@ -89,7 +90,7 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef
MEM_freeN(gh->buckets);
BLI_mempool_destroy(gh->entrypool);
- gh->buckets = 0;
+ gh->buckets = NULL;
gh->nentries = 0;
gh->nbuckets = 0;
MEM_freeN(gh);
@@ -149,17 +150,17 @@ int BLI_ghashIterator_isDone(GHashIterator *ghi) {
/***/
-unsigned int BLI_ghashutil_ptrhash(void *key) {
+unsigned int BLI_ghashutil_ptrhash(const void *key) {
return (unsigned int)(intptr_t)key;
}
-int BLI_ghashutil_ptrcmp(void *a, void *b) {
+int BLI_ghashutil_ptrcmp(const void *a, const void *b) {
if (a==b)
return 0;
else
return (a<b)?-1:1;
}
-unsigned int BLI_ghashutil_inthash(void *ptr) {
+unsigned int BLI_ghashutil_inthash(const void *ptr) {
uintptr_t key = (uintptr_t)ptr;
key += ~(key << 16);
@@ -172,15 +173,15 @@ unsigned int BLI_ghashutil_inthash(void *ptr) {
return (unsigned int)(key & 0xffffffff);
}
-int BLI_ghashutil_intcmp(void *a, void *b) {
+int BLI_ghashutil_intcmp(const void *a, const void *b) {
if (a==b)
return 0;
else
return (a<b)?-1:1;
}
-unsigned int BLI_ghashutil_strhash(void *ptr) {
- char *s= ptr;
+unsigned int BLI_ghashutil_strhash(const void *ptr) {
+ const char *s= ptr;
unsigned int i= 0;
unsigned char c;
@@ -189,6 +190,6 @@ unsigned int BLI_ghashutil_strhash(void *ptr) {
return i;
}
-int BLI_ghashutil_strcmp(void *a, void *b) {
+int BLI_ghashutil_strcmp(const void *a, const void *b) {
return strcmp(a, b);
}
diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c
index f6616ecb06b..027d3da6499 100644
--- a/source/blender/blenlib/intern/BLI_heap.c
+++ b/source/blender/blenlib/intern/BLI_heap.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -64,7 +64,7 @@ struct Heap {
/***/
-Heap *BLI_heap_new()
+Heap *BLI_heap_new(void)
{
Heap *heap = (Heap*)MEM_callocN(sizeof(Heap), "BLIHeap");
heap->bufsize = 1;
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 4d64f4a50ff..01f2ab4436c 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -1,4 +1,4 @@
-/**
+/*
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -30,7 +30,9 @@
#include "MEM_guardedalloc.h"
-#include "BKE_utildefines.h"
+#include "BLI_utildefines.h"
+
+
#include "BLI_kdopbvh.h"
#include "BLI_math.h"
@@ -159,7 +161,8 @@ static float KDOP_AXES[13][3] =
heap[parent] = element; \
}
-int ADJUST_MEMORY(void *local_memblock, void **memblock, int new_size, int *max_size, int size_per_item)
+#if 0
+static int ADJUST_MEMORY(void *local_memblock, void **memblock, int new_size, int *max_size, int size_per_item)
{
int new_max_size = *max_size * 2;
void *new_memblock = NULL;
@@ -184,7 +187,7 @@ int ADJUST_MEMORY(void *local_memblock, void **memblock, int new_size, int *max_
else
return FALSE;
}
-
+#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Introsort
@@ -1126,19 +1129,20 @@ static void traverse(BVHOverlapData *data, BVHNode *node1, BVHNode *node2)
return;
}
-BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, int *result)
+BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int *result)
{
- int j, total = 0;
+ int j;
+ unsigned int total = 0;
BVHTreeOverlap *overlap = NULL, *to = NULL;
BVHOverlapData **data;
// check for compatibility of both trees (can't compare 14-DOP with 18-DOP)
if((tree1->axis != tree2->axis) && (tree1->axis == 14 || tree2->axis == 14) && (tree1->axis == 18 || tree2->axis == 18))
- return 0;
+ return NULL;
// fast check root nodes for collision before doing big splitting + traversal
if(!tree_overlap(tree1->nodes[tree1->totleaf], tree2->nodes[tree2->totleaf], MIN2(tree1->start_axis, tree2->start_axis), MIN2(tree1->stop_axis, tree2->stop_axis)))
- return 0;
+ return NULL;
data = MEM_callocN(sizeof(BVHOverlapData *)* tree1->tree_type, "BVHOverlapData_star");
diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c
index cf94a0c9ffe..24fe4c081d9 100644
--- a/source/blender/blenlib/intern/BLI_kdtree.c
+++ b/source/blender/blenlib/intern/BLI_kdtree.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -132,6 +132,7 @@ void BLI_kdtree_balance(KDTree *tree)
static float squared_distance(float *v2, float *v1, float *n1, float *n2)
{
float d[3], dist;
+ (void)n1; /* unused */
d[0]= v2[0]-v1[0];
d[1]= v2[1]-v1[1];
@@ -254,7 +255,7 @@ static void add_nearest(KDTreeNearest *ptn, int *found, int n, int index, float
/* finds the nearest n entries in tree to specified coordinates */
int BLI_kdtree_find_n_nearest(KDTree *tree, int n, float *co, float *nor, KDTreeNearest *nearest)
{
- KDTreeNode *root, *node=0;
+ KDTreeNode *root, *node= NULL;
KDTreeNode **stack, *defaultstack[100];
float cur_dist;
int i, totstack, cur=0, found=0;
@@ -369,7 +370,7 @@ static void add_in_range(KDTreeNearest **ptn, int found, int *totfoundstack, int
}
int BLI_kdtree_range_search(KDTree *tree, float range, float *co, float *nor, KDTreeNearest **nearest)
{
- KDTreeNode *root, *node=0;
+ KDTreeNode *root, *node= NULL;
KDTreeNode **stack, *defaultstack[100];
KDTreeNearest *foundstack=NULL;
float range2 = range*range, dist2;
diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c
index c903e66057e..deb4ee79157 100644
--- a/source/blender/blenlib/intern/BLI_linklist.c
+++ b/source/blender/blenlib/intern/BLI_linklist.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c
index de2a73e065f..52638158b18 100644
--- a/source/blender/blenlib/intern/BLI_memarena.c
+++ b/source/blender/blenlib/intern/BLI_memarena.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index 686709d8879..60882e7f1b6 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -1,4 +1,4 @@
-/**
+/*
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -36,6 +36,8 @@
#include "BLI_blenlib.h"
#include "BLI_linklist.h"
+#include "BLI_mempool.h"
+#include "BLI_utildefines.h"
#include "DNA_listBase.h"
#include "DNA_ID.h"
@@ -187,9 +189,11 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr){ //doesnt protect against d
first = pool->chunks.first;
BLI_remlink(&pool->chunks, first);
- for(mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next)
- pool->use_sysmalloc ? free(mpchunk->data) : MEM_freeN(mpchunk->data);
-
+ for(mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) {
+ if(pool->use_sysmalloc) free(mpchunk->data);
+ else MEM_freeN(mpchunk->data);
+ }
+
pool->use_sysmalloc ? BLI_freelist(&(pool->chunks)) : BLI_freelistN(&(pool->chunks));
BLI_addtail(&pool->chunks, first);
@@ -252,9 +256,18 @@ void *BLI_mempool_iterstep(BLI_mempool_iter *iter)
void BLI_mempool_destroy(BLI_mempool *pool)
{
BLI_mempool_chunk *mpchunk=NULL;
- for(mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next)
- pool->use_sysmalloc ? free(mpchunk->data) : MEM_freeN(mpchunk->data);
-
- pool->use_sysmalloc ? BLI_freelist(&(pool->chunks)) : BLI_freelistN(&(pool->chunks));
- pool->use_sysmalloc ? free(pool) : MEM_freeN(pool);
+ if(pool->use_sysmalloc) {
+ for(mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) {
+ free(mpchunk->data);
+ }
+ BLI_freelist(&(pool->chunks));
+ free(pool);
+ }
+ else {
+ for(mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) {
+ MEM_freeN(mpchunk->data);
+ }
+ BLI_freelistN(&(pool->chunks));
+ MEM_freeN(pool);
+ }
}
diff --git a/source/blender/blenlib/intern/DLRB_tree.c b/source/blender/blenlib/intern/DLRB_tree.c
index 69c9cc7e522..fa2edac0897 100644
--- a/source/blender/blenlib/intern/DLRB_tree.c
+++ b/source/blender/blenlib/intern/DLRB_tree.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
diff --git a/source/blender/blenlib/intern/Makefile b/source/blender/blenlib/intern/Makefile
deleted file mode 100644
index 018fd3477df..00000000000
--- a/source/blender/blenlib/intern/Makefile
+++ /dev/null
@@ -1,62 +0,0 @@
-#
-# $Id$
-#
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): none yet.
-#
-# ***** END GPL LICENSE BLOCK *****
-#
-#
-
-LIBNAME = blenlib
-DIR = $(OCGDIR)/blender/$(LIBNAME)
-
-include nan_compile.mk
-
-CFLAGS += $(LEVEL_1_C_WARNINGS)
-
-# path to SDNA types
-CPPFLAGS += -I../../makesdna
-# path to our own external headerfiles
-CPPFLAGS += -I..
-# path to the guarded memory allocator
-CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
-# path to freetype font stuff
-CPPFLAGS += -I$(NAN_FREETYPE)/include
-CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2
-# path to blenkernel
-CPPFLAGS += -I$(SRCHOME)/blender/blenkernel
-CPPFLAGS += -I../../editors/include/
-# path to zlib
-CPPFLAGS += -I$(NAN_ZLIB)/include
-
-CPPFLAGS += -I../../gpu
-
-CPPFLAGS += -I$(NAN_GHOST)/include
-
-ifdef NAN_PTHREADS
- CPPFLAGS += -I$(NAN_PTHREADS)/include
-endif
-ifeq ($(OS),linux)
- CPPFLAGS += -I$(OCGDIR)/extern/binreloc/include
-endif
diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c
index 1c910dbb519..643dcb6efca 100644
--- a/source/blender/blenlib/intern/boxpack2d.c
+++ b/source/blender/blenlib/intern/boxpack2d.c
@@ -30,6 +30,23 @@
*
* The defined Below are for internal use only */
+typedef struct boxVert {
+ float x;
+ float y;
+ short free;
+
+ struct boxPack *trb; /* top right box */
+ struct boxPack *blb; /* bottom left box */
+ struct boxPack *brb; /* bottom right box */
+ struct boxPack *tlb; /* top left box */
+
+ /* Store last intersecting boxes here
+ * speedup intersection testing */
+ struct boxPack *isect_cache[4];
+
+ int index;
+} boxVert;
+
/* free vert flags */
#define eps 0.0000001f
#define BLF 1
@@ -83,12 +100,10 @@
/* qsort function - sort largest to smallest */
static int box_areasort(const void *p1, const void *p2)
{
- const boxPack *b1=p1, *b2=p2;
- float a1, a2;
+ const boxPack *b1= p1, *b2= p2;
+ const float a1= BOXAREA(b1);
+ const float a2= BOXAREA(b2);
- a1 = BOXAREA(b1);
- a2 = BOXAREA(b2);
-
if ( a1 < a2 ) return 1;
else if ( a1 > a2 ) return -1;
return 0;
@@ -132,13 +147,13 @@ static int vertex_sort(const void *p1, const void *p2)
* len - the number of boxes in the array.
* tot_width and tot_height are set so you can normalize the data.
* */
-void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height)
+void boxPack2D(boxPack *boxarray, const int len, float *tot_width, float *tot_height)
{
boxVert *vert; /* the current vert */
int box_index, verts_pack_len, i, j, k, isect;
int quad_flags[4]= {BLF,TRF,TLF,BRF}; /* use for looping */
boxPack *box, *box_test; /*current box and another for intersection tests*/
- int *vertex_pack_indicies; /*an array of indices used for sorting verts*/
+ int *vertex_pack_indices; /*an array of indices used for sorting verts*/
if (!len) {
*tot_width = 0.0f;
@@ -151,7 +166,7 @@ void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height)
/* add verts to the boxes, these are only used internally */
vert = vertarray = MEM_mallocN( len*4*sizeof(boxVert), "boxPack Verts");
- vertex_pack_indicies = MEM_mallocN( len*3*sizeof(int), "boxPack Indices");
+ vertex_pack_indices = MEM_mallocN( len*3*sizeof(int), "boxPack Indices");
for (box=boxarray, box_index=0, i=0; box_index < len; box_index++, box++) {
@@ -208,7 +223,7 @@ void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height)
box->x = box->y = 0.0f;
for (i=0; i<3; i++)
- vertex_pack_indicies[i] = box->v[i+1]->index;
+ vertex_pack_indices[i] = box->v[i+1]->index;
verts_pack_len = 3;
box++; /* next box, needed for the loop below */
/* ...done packing the first box */
@@ -220,14 +235,14 @@ void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height)
box_width = box->w;
box_height = box->h;
- qsort(vertex_pack_indicies, verts_pack_len, sizeof(int), vertex_sort);
+ qsort(vertex_pack_indices, verts_pack_len, sizeof(int), vertex_sort);
/* Pack the box in with the others */
/* sort the verts */
isect = 1;
for (i=0; i<verts_pack_len && isect; i++) {
- vert = vertarray + vertex_pack_indicies[i];
+ vert = vertarray + vertex_pack_indices[i];
/* printf("\ttesting vert %i %i %i %f %f\n", i,
* vert->free, verts_pack_len, vert->x, vert->y); */
@@ -384,7 +399,7 @@ void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height)
for (k=0; k<4; k++) {
if (box->v[k] != vert) {
- vertex_pack_indicies[verts_pack_len] =
+ vertex_pack_indices[verts_pack_len] =
box->v[k]->index;
verts_pack_len++;
}
@@ -406,7 +421,7 @@ void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height)
box = boxarray+box_index;
box->v[0] = box->v[1] = box->v[2] = box->v[3] = NULL;
}
- MEM_freeN(vertex_pack_indicies);
+ MEM_freeN(vertex_pack_indices);
MEM_freeN(vertarray);
}
diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c
index d1a8de14181..7fa88704f2e 100644
--- a/source/blender/blenlib/intern/bpath.c
+++ b/source/blender/blenlib/intern/bpath.c
@@ -1,4 +1,4 @@
-/**
+/*
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -29,6 +29,7 @@
#include <sys/stat.h>
#include <string.h>
+#include <assert.h>
/* path/file handeling stuff */
#ifndef WIN32
@@ -44,6 +45,8 @@
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h" /* to get the current frame */
#include "DNA_image_types.h"
+#include "DNA_texture_types.h"
+#include "DNA_text_types.h"
#include "DNA_sound_types.h"
#include "DNA_sequence_types.h"
#include "DNA_vfont_types.h"
@@ -51,11 +54,12 @@
#include "BLI_blenlib.h"
#include "BLI_bpath.h"
+#include "BLI_utildefines.h"
#include "BKE_global.h"
#include "BKE_image.h" /* so we can check the image's type */
-#include "BKE_main.h" /* so we can access G.main->*.first */
#include "BKE_sequencer.h"
+#include "BKE_main.h"
#include "BKE_utildefines.h"
#include "BKE_report.h"
@@ -65,11 +69,42 @@
//XXX #include "BSE_sequence.h"
//XXX define below from BSE_sequence.h - otherwise potentially odd behaviour
+
+typedef struct BPathIteratorSeqData {
+ int totseq;
+ int seq;
+ struct Sequence **seqar; /* Sequence */
+ struct Scene *scene; /* Current scene */
+} BPathIteratorSeqData;
+
+typedef struct BPathIterator {
+ char* _path; /* never access directly, use BLI_bpathIterator_getPath */
+ const char* _lib;
+ const char* _name;
+ void* data;
+ int len;
+ int type;
+ int flag; /* iterator options */
+
+ void (*setpath_callback)(struct BPathIterator *, const char *);
+ void (*getpath_callback)(struct BPathIterator *, char *);
+
+ const char* base_path; /* base path, the directry the blend file is in - normally bmain->name */
+
+ Main *bmain;
+
+ /* only for seq data */
+ struct BPathIteratorSeqData seqdata;
+} BPathIterator;
+
#define FILE_MAX 240
+
/* TODO - BPATH_PLUGIN, BPATH_SEQ */
enum BPathTypes {
- BPATH_IMAGE = 0,
+ BPATH_IMAGE= 0,
+ BPATH_TEXTURE,
+ BPATH_TEXT,
BPATH_SOUND,
BPATH_FONT,
BPATH_LIB,
@@ -79,52 +114,69 @@ enum BPathTypes {
BPATH_DONE
};
-void BLI_bpathIterator_init( struct BPathIterator *bpi, char *base_path ) {
- bpi->type = BPATH_IMAGE;
- bpi->data = NULL;
+void BLI_bpathIterator_init(struct BPathIterator **bpi_pt, Main *bmain, const char *basedir, const int flag)
+{
+ BPathIterator *bpi;
+
+ bpi= MEM_mallocN(sizeof(BPathIterator), "BLI_bpathIterator_init");
+ *bpi_pt= bpi;
+
+ bpi->type= BPATH_IMAGE;
+ bpi->data= NULL;
- bpi->getpath_callback = NULL;
- bpi->setpath_callback = NULL;
+ bpi->getpath_callback= NULL;
+ bpi->setpath_callback= NULL;
/* Sequencer specific */
- bpi->seqdata.totseq = 0;
- bpi->seqdata.seq = 0;
- bpi->seqdata.seqar = NULL;
- bpi->seqdata.scene = NULL;
-
- bpi->base_path= base_path ? base_path : G.sce;
+ bpi->seqdata.totseq= 0;
+ bpi->seqdata.seq= 0;
+ bpi->seqdata.seqar= NULL;
+ bpi->seqdata.scene= NULL;
+
+ bpi->flag= flag;
+
+ bpi->base_path= basedir; /* normally bmain->name */
+ bpi->bmain= bmain;
BLI_bpathIterator_step(bpi);
}
-void BLI_bpathIterator_free( struct BPathIterator *bpi ) {
+#if 0
+static void BLI_bpathIterator_alloc(struct BPathIterator **bpi) {
+ *bpi= MEM_mallocN(sizeof(BPathIterator), "BLI_bpathIterator_alloc");
+}
+#endif
+
+void BLI_bpathIterator_free(struct BPathIterator *bpi) {
if (bpi->seqdata.seqar)
MEM_freeN((void *)bpi->seqdata.seqar);
- bpi->seqdata.seqar = NULL;
- bpi->seqdata.scene = NULL;
+ bpi->seqdata.seqar= NULL;
+ bpi->seqdata.scene= NULL;
+
+ MEM_freeN(bpi);
}
-void BLI_bpathIterator_getPath( struct BPathIterator *bpi, char *path) {
+void BLI_bpathIterator_getPath(struct BPathIterator *bpi, char *path) {
if (bpi->getpath_callback) {
- bpi->getpath_callback( bpi, path );
+ bpi->getpath_callback(bpi, path);
} else {
- strcpy(path, bpi->path); /* warning, we assume 'path' are long enough */
+ strcpy(path, bpi->_path); /* warning, we assume 'path' are long enough */
}
}
-void BLI_bpathIterator_setPath( struct BPathIterator *bpi, char *path) {
+void BLI_bpathIterator_setPath(struct BPathIterator *bpi, const char *path) {
if (bpi->setpath_callback) {
- bpi->setpath_callback( bpi, path );
+ bpi->setpath_callback(bpi, path);
} else {
- strcpy(bpi->path, path); /* warning, we assume 'path' are long enough */
+ strcpy(bpi->_path, path); /* warning, we assume 'path' are long enough */
}
}
-void BLI_bpathIterator_getPathExpanded( struct BPathIterator *bpi, char *path_expanded) {
- char *libpath;
+void BLI_bpathIterator_getPathExpanded(struct BPathIterator *bpi, char *path_expanded) {
+ const char *libpath;
BLI_bpathIterator_getPath(bpi, path_expanded);
- libpath = BLI_bpathIterator_getLib(bpi);
+ libpath= BLI_bpathIterator_getLib(bpi);
if (libpath) { /* check the files location relative to its library path */
BLI_path_abs(path_expanded, libpath);
@@ -133,68 +185,113 @@ void BLI_bpathIterator_getPathExpanded( struct BPathIterator *bpi, char *path_ex
}
BLI_cleanup_file(NULL, path_expanded);
}
-char* BLI_bpathIterator_getLib( struct BPathIterator *bpi) {
- return bpi->lib;
+const char* BLI_bpathIterator_getLib(struct BPathIterator *bpi) {
+ return bpi->_lib;
}
-char* BLI_bpathIterator_getName( struct BPathIterator *bpi) {
- return bpi->name;
+const char* BLI_bpathIterator_getName(struct BPathIterator *bpi) {
+ return bpi->_name;
}
-int BLI_bpathIterator_getType( struct BPathIterator *bpi) {
+int BLI_bpathIterator_getType(struct BPathIterator *bpi) {
return bpi->type;
}
-int BLI_bpathIterator_getPathMaxLen( struct BPathIterator *bpi) {
+int BLI_bpathIterator_getPathMaxLen(struct BPathIterator *bpi) {
return bpi->len;
}
+const char* BLI_bpathIterator_getBasePath(struct BPathIterator *bpi) {
+ return bpi->base_path;
+}
/* gets the first or the next image that has a path - not a viewer node or generated image */
-static struct Image *ima_stepdata__internal(struct Image *ima, int step_next) {
+static struct Image *ima_stepdata__internal(struct Image *ima, const int step_next, const int flag)
+{
if (ima==NULL)
return NULL;
if (step_next)
- ima = ima->id.next;
+ ima= ima->id.next;
while (ima) {
- if (ima->packedfile==NULL && ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
- break;
+ if (ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
+ if(ima->packedfile==NULL || (flag & BPATH_USE_PACKED)) {
+ break;
+ }
+ }
/* image is not a image with a path, skip it */
- ima = ima->id.next;
+ ima= ima->id.next;
}
return ima;
}
-static struct VFont *vf_stepdata__internal(struct VFont *vf, int step_next) {
+static struct Tex *tex_stepdata__internal(struct Tex *tex, const int step_next, const int UNUSED(flag))
+{
+ if (tex==NULL)
+ return NULL;
+
+ if (step_next)
+ tex= tex->id.next;
+
+ while (tex) {
+ if (tex->type == TEX_VOXELDATA && TEX_VD_IS_SOURCE_PATH(tex->vd->file_format))
+ break;
+ /* image is not a image with a path, skip it */
+ tex= tex->id.next;
+ }
+ return tex;
+}
+
+static struct Text *text_stepdata__internal(struct Text *text, const int step_next, const int UNUSED(flag))
+{
+ if (text==NULL)
+ return NULL;
+
+ if (step_next)
+ text= text->id.next;
+
+ while (text) {
+ if (text->name)
+ break;
+ /* image is not a image with a path, skip it */
+ text= text->id.next;
+ }
+ return text;
+}
+
+static struct VFont *vf_stepdata__internal(struct VFont *vf, const int step_next, const int flag)
+{
if (vf==NULL)
return NULL;
if (step_next)
- vf = vf->id.next;
+ vf= vf->id.next;
while (vf) {
- if (vf->packedfile==NULL && BLI_streq(vf->name, "<builtin>")==0) {
- break;
+ if (strcmp(vf->name, FO_BUILTIN_NAME)!=0) {
+ if(vf->packedfile==NULL || (flag & BPATH_USE_PACKED)) {
+ break;
+ }
}
/* font with no path, skip it */
- vf = vf->id.next;
+ vf= vf->id.next;
}
return vf;
}
-static struct bSound *snd_stepdata__internal(struct bSound *snd, int step_next) {
+static struct bSound *snd_stepdata__internal(struct bSound *snd, int step_next, const int flag)
+{
if (snd==NULL)
return NULL;
if (step_next)
- snd = snd->id.next;
+ snd= snd->id.next;
while (snd) {
- if (snd->packedfile==NULL) {
+ if(snd->packedfile==NULL || (flag & BPATH_USE_PACKED)) {
break;
}
-
+
/* font with no path, skip it */
- snd = snd->id.next;
+ snd= snd->id.next;
}
return snd;
}
@@ -206,7 +303,7 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
/* Initializing */
if (bpi->seqdata.scene==NULL) {
- bpi->seqdata.scene= G.main->scene.first;
+ bpi->seqdata.scene= bpi->bmain->scene.first;
}
if (step_next) {
@@ -219,20 +316,20 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
if (bpi->seqdata.seqar == NULL) {
/* allocate the sequencer array */
seq_array(ed, &bpi->seqdata.seqar, &bpi->seqdata.totseq, 0);
- bpi->seqdata.seq = 0;
+ bpi->seqdata.seq= 0;
}
if (bpi->seqdata.seq >= bpi->seqdata.totseq) {
- seq = NULL;
+ seq= NULL;
} else {
- seq = bpi->seqdata.seqar[bpi->seqdata.seq];
- while (!SEQ_HAS_PATH(seq)) {
+ seq= bpi->seqdata.seqar[bpi->seqdata.seq];
+ while (!SEQ_HAS_PATH(seq) && seq->plugin==NULL) {
bpi->seqdata.seq++;
if (bpi->seqdata.seq >= bpi->seqdata.totseq) {
- seq = NULL;
+ seq= NULL;
break;
}
- seq = bpi->seqdata.seqar[bpi->seqdata.seq];
+ seq= bpi->seqdata.seqar[bpi->seqdata.seq];
}
}
if (seq) {
@@ -241,13 +338,13 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
/* keep looking through the next scene, reallocate seq array */
if (bpi->seqdata.seqar) {
MEM_freeN((void *)bpi->seqdata.seqar);
- bpi->seqdata.seqar = NULL;
+ bpi->seqdata.seqar= NULL;
}
- bpi->seqdata.scene = bpi->seqdata.scene->id.next;
+ bpi->seqdata.scene= bpi->seqdata.scene->id.next;
}
} else {
/* no seq data in this scene, next */
- bpi->seqdata.scene = bpi->seqdata.scene->id.next;
+ bpi->seqdata.scene= bpi->seqdata.scene->id.next;
}
}
@@ -255,10 +352,10 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
}
static void seq_getpath(struct BPathIterator *bpi, char *path) {
- Sequence *seq = (Sequence *)bpi->data;
+ Sequence *seq= (Sequence *)bpi->data;
- path[0] = '\0'; /* incase we cant get the path */
+ path[0]= '\0'; /* incase we cant get the path */
if (seq==NULL) return;
if (SEQ_HAS_PATH(seq)) {
if (ELEM3(seq->type, SEQ_IMAGE, SEQ_MOVIE, SEQ_SOUND)) {
@@ -268,25 +365,52 @@ static void seq_getpath(struct BPathIterator *bpi, char *path) {
/* Using the first image is weak for image sequences */
strcat(path, seq->strip->stripdata->name);
}
- } else {
+ }
+ else {
/* simple case */
BLI_strncpy(seq->strip->dir, path, sizeof(seq->strip->dir));
}
}
+ else if (seq->plugin) {
+ BLI_strncpy(seq->plugin->name, path, sizeof(seq->plugin->name));
+ }
}
-static void seq_setpath(struct BPathIterator *bpi, char *path) {
- Sequence *seq = (Sequence *)bpi->data;
+static void seq_setpath(struct BPathIterator *bpi, const char *path) {
+ Sequence *seq= (Sequence *)bpi->data;
if (seq==NULL) return;
if (SEQ_HAS_PATH(seq)) {
if (ELEM3(seq->type, SEQ_IMAGE, SEQ_MOVIE, SEQ_SOUND)) {
BLI_split_dirfile(path, seq->strip->dir, seq->strip->stripdata->name);
- } else {
+ }
+ else {
/* simple case */
BLI_strncpy(seq->strip->dir, path, sizeof(seq->strip->dir));
}
}
+ else if (seq->plugin) {
+ BLI_strncpy(seq->plugin->name, path, sizeof(seq->plugin->name));
+ }
+}
+
+static void text_getpath(struct BPathIterator *bpi, char *path) {
+ Text *text= (Text *)bpi->data;
+ path[0]= '\0'; /* incase we cant get the path */
+ if(text->name) {
+ strcpy(path, text->name);
+ }
+}
+
+static void text_setpath(struct BPathIterator *bpi, const char *path) {
+ Text *text= (Text *)bpi->data;
+ if (text==NULL) return;
+
+ if(text->name) {
+ MEM_freeN(text->name);
+ }
+
+ text->name= BLI_strdup(path);
}
static struct Mesh *cdata_stepdata__internal(struct Mesh *me, int step_next) {
@@ -294,72 +418,125 @@ static struct Mesh *cdata_stepdata__internal(struct Mesh *me, int step_next) {
return NULL;
if (step_next)
- me = me->id.next;
+ me= me->id.next;
while (me) {
if (me->fdata.external) {
break;
}
- me = me->id.next;
+ me= me->id.next;
}
return me;
}
-static void bpi_type_step__internal( struct BPathIterator *bpi) {
+static void bpi_type_step__internal(struct BPathIterator *bpi) {
bpi->type++; /* advance to the next type */
- bpi->data = NULL;
+ bpi->data= NULL;
switch (bpi->type) {
case BPATH_SEQ:
- bpi->getpath_callback = seq_getpath;
- bpi->setpath_callback = seq_setpath;
+ bpi->getpath_callback= seq_getpath;
+ bpi->setpath_callback= seq_setpath;
+ break;
+ case BPATH_TEXT: /* path is malloc'd */
+ bpi->getpath_callback= text_getpath;
+ bpi->setpath_callback= text_setpath;
break;
default:
- bpi->getpath_callback = NULL;
- bpi->setpath_callback = NULL;
+ bpi->getpath_callback= NULL;
+ bpi->setpath_callback= NULL;
break;
}
}
-void BLI_bpathIterator_step( struct BPathIterator *bpi) {
+void BLI_bpathIterator_step(struct BPathIterator *bpi) {
while (bpi->type != BPATH_DONE) {
if ((bpi->type) == BPATH_IMAGE) {
- /*if (bpi->data) bpi->data = ((ID *)bpi->data)->next;*/
- if (bpi->data) bpi->data = ima_stepdata__internal( (Image *)bpi->data, 1 ); /* must skip images that have no path */
- else bpi->data = ima_stepdata__internal(G.main->image.first, 0);
+ /*if (bpi->data) bpi->data= ((ID *)bpi->data)->next;*/
+ if (bpi->data) bpi->data= ima_stepdata__internal((Image *)bpi->data, 1, bpi->flag); /* must skip images that have no path */
+ else bpi->data= ima_stepdata__internal(bpi->bmain->image.first, 0, bpi->flag);
if (bpi->data) {
/* get the path info from this datatype */
- Image *ima = (Image *)bpi->data;
+ Image *ima= (Image *)bpi->data;
- bpi->lib = ima->id.lib ? ima->id.lib->filepath : NULL;
- bpi->path = ima->name;
- bpi->name = ima->id.name+2;
- bpi->len = sizeof(ima->name);
+ bpi->_lib= ima->id.lib ? ima->id.lib->filepath : NULL;
+ bpi->_path= ima->name;
+ bpi->_name= ima->id.name+2;
+ bpi->len= sizeof(ima->name);
/* we are done, advancing to the next item, this type worked fine */
break;
-
+
} else {
bpi_type_step__internal(bpi);
}
-
-
- } else if ((bpi->type) == BPATH_SOUND) {
- if (bpi->data) bpi->data = snd_stepdata__internal( (bSound *)bpi->data, 1 ); /* must skip images that have no path */
- else bpi->data = snd_stepdata__internal(G.main->sound.first, 0);
-
+ }
+
+ if ((bpi->type) == BPATH_TEXTURE) {
+ /*if (bpi->data) bpi->data= ((ID *)bpi->data)->next;*/
+ if (bpi->data) bpi->data= tex_stepdata__internal( (Tex *)bpi->data, 1, bpi->flag); /* must skip images that have no path */
+ else bpi->data= tex_stepdata__internal(bpi->bmain->tex.first, 0, bpi->flag);
+
if (bpi->data) {
/* get the path info from this datatype */
- bSound *snd = (bSound *)bpi->data;
-
- bpi->lib = snd->id.lib ? snd->id.lib->filepath : NULL;
- bpi->path = snd->name;
- bpi->name = snd->id.name+2;
- bpi->len = sizeof(snd->name);
-
+ Tex *tex= (Tex *)bpi->data;
+
+ if(tex->type == TEX_VOXELDATA) {
+ bpi->_lib= tex->id.lib ? tex->id.lib->filepath : NULL;
+ bpi->_path= tex->vd->source_path;
+ bpi->_name= tex->id.name+2;
+ bpi->len= sizeof(tex->vd->source_path);
+ }
+ else {
+ assert(!"Texture has no path, incorrect step 'tex_stepdata__internal'");
+ }
+
+ /* we are done, advancing to the next item, this type worked fine */
+ break;
+
+ } else {
+ bpi_type_step__internal(bpi);
+ }
+ }
+
+ if ((bpi->type) == BPATH_TEXT) {
+ /*if (bpi->data) bpi->data= ((ID *)bpi->data)->next;*/
+ if (bpi->data) bpi->data= text_stepdata__internal((Text *)bpi->data, 1, bpi->flag); /* must skip images that have no path */
+ else bpi->data= text_stepdata__internal(bpi->bmain->text.first, 0, bpi->flag);
+
+ if (bpi->data) {
+ /* get the path info from this datatype */
+ Text *text= (Text *)bpi->data;
+
+ bpi->_lib= text->id.lib ? text->id.lib->filepath : NULL;
+ bpi->_path= NULL; /* bpi->path= text->name; */ /* get/set functions override. */
+ bpi->_name= text->id.name+2;
+ bpi->len= FILE_MAX; /* malloc'd but limit anyway since large paths may mess up other areas */
+
+ /* we are done, advancing to the next item, this type worked fine */
+ break;
+
+ } else {
+ bpi_type_step__internal(bpi);
+ }
+ }
+
+ else if ((bpi->type) == BPATH_SOUND) {
+ if (bpi->data) bpi->data= snd_stepdata__internal((bSound *)bpi->data, 1, bpi->flag); /* must skip images that have no path */
+ else bpi->data= snd_stepdata__internal(bpi->bmain->sound.first, 0, bpi->flag);
+
+ if (bpi->data) {
+ /* get the path info from this datatype */
+ bSound *snd= (bSound *)bpi->data;
+
+ bpi->_lib= snd->id.lib ? snd->id.lib->filepath : NULL;
+ bpi->_path= snd->name;
+ bpi->_name= snd->id.name+2;
+ bpi->len= sizeof(snd->name);
+
/* we are done, advancing to the next item, this type worked fine */
break;
} else {
@@ -369,36 +546,36 @@ void BLI_bpathIterator_step( struct BPathIterator *bpi) {
} else if ((bpi->type) == BPATH_FONT) {
- if (bpi->data) bpi->data = vf_stepdata__internal( (VFont *)bpi->data, 1 );
- else bpi->data = vf_stepdata__internal( G.main->vfont.first, 0 );
+ if (bpi->data) bpi->data= vf_stepdata__internal((VFont *)bpi->data, 1, bpi->flag);
+ else bpi->data= vf_stepdata__internal(bpi->bmain->vfont.first, 0, bpi->flag);
if (bpi->data) {
/* get the path info from this datatype */
- VFont *vf = (VFont *)bpi->data;
-
- bpi->lib = vf->id.lib ? vf->id.lib->filepath : NULL;
- bpi->path = vf->name;
- bpi->name = vf->id.name+2;
- bpi->len = sizeof(vf->name);
-
+ VFont *vf= (VFont *)bpi->data;
+
+ bpi->_lib= vf->id.lib ? vf->id.lib->filepath : NULL;
+ bpi->_path= vf->name;
+ bpi->_name= vf->id.name+2;
+ bpi->len= sizeof(vf->name);
+
/* we are done, advancing to the next item, this type worked fine */
break;
} else {
bpi_type_step__internal(bpi);
}
-
+
} else if ((bpi->type) == BPATH_LIB) {
- if (bpi->data) bpi->data = ((ID *)bpi->data)->next;
- else bpi->data = G.main->library.first;
+ if (bpi->data) bpi->data= ((ID *)bpi->data)->next;
+ else bpi->data= bpi->bmain->library.first;
if (bpi->data) {
/* get the path info from this datatype */
- Library *lib = (Library *)bpi->data;
+ Library *lib= (Library *)bpi->data;
- bpi->lib = NULL;
- bpi->path = lib->name;
- bpi->name = NULL;
- bpi->len = sizeof(lib->name);
+ bpi->_lib= NULL;
+ bpi->_path= lib->name;
+ bpi->_name= NULL;
+ bpi->len= sizeof(lib->name);
/* we are done, advancing to the next item, this type worked fine */
break;
@@ -406,27 +583,27 @@ void BLI_bpathIterator_step( struct BPathIterator *bpi) {
bpi_type_step__internal(bpi);
}
} else if ((bpi->type) == BPATH_SEQ) {
- if (bpi->data) bpi->data = seq_stepdata__internal( bpi, 1 );
- else bpi->data = seq_stepdata__internal( bpi, 0 );
+ if (bpi->data) bpi->data= seq_stepdata__internal( bpi, 1 );
+ else bpi->data= seq_stepdata__internal( bpi, 0 );
if (bpi->data) {
- Sequence *seq = (Sequence *)bpi->data;
- bpi->lib = NULL;
- bpi->name = seq->name+2;
- bpi->len = sizeof(seq->strip->stripdata->name);
+ Sequence *seq= (Sequence *)bpi->data;
+ bpi->_lib= NULL;
+ bpi->_name= seq->name+2;
+ bpi->len= seq->plugin ? sizeof(seq->plugin->name) : sizeof(seq->strip->dir) + sizeof(seq->strip->stripdata->name);
break;
} else {
bpi_type_step__internal(bpi);
}
} else if ((bpi->type) == BPATH_CDATA) {
- if (bpi->data) bpi->data = cdata_stepdata__internal( bpi->data, 1 );
- else bpi->data = cdata_stepdata__internal( G.main->mesh.first, 0 );
+ if (bpi->data) bpi->data= cdata_stepdata__internal( bpi->data, 1 );
+ else bpi->data= cdata_stepdata__internal( bpi->bmain->mesh.first, 0 );
if (bpi->data) {
- Mesh *me = (Mesh *)bpi->data;
- bpi->lib = me->id.lib ? me->id.lib->filepath : NULL;
- bpi->path = me->fdata.external->filename;
- bpi->name = me->id.name+2;
- bpi->len = sizeof(me->fdata.external->filename);
+ Mesh *me= (Mesh *)bpi->data;
+ bpi->_lib= me->id.lib ? me->id.lib->filepath : NULL;
+ bpi->_path= me->fdata.external->filename;
+ bpi->_name= me->id.name+2;
+ bpi->len= sizeof(me->fdata.external->filename);
break;
} else {
bpi_type_step__internal(bpi);
@@ -442,8 +619,8 @@ int BLI_bpathIterator_isDone( struct BPathIterator *bpi) {
/* include the path argument */
static void bpath_as_report(struct BPathIterator *bpi, const char *message, ReportList *reports)
{
- char *prefix;
- char *name;
+ const char *prefix;
+ const char *name;
char path_expanded[FILE_MAXDIR*2];
if(reports==NULL)
@@ -453,6 +630,12 @@ static void bpath_as_report(struct BPathIterator *bpi, const char *message, Repo
case BPATH_IMAGE:
prefix= "Image";
break;
+ case BPATH_TEXTURE:
+ prefix= "Texture";
+ break;
+ case BPATH_TEXT:
+ prefix= "Text";
+ break;
case BPATH_SOUND:
prefix= "Sound";
break;
@@ -473,7 +656,7 @@ static void bpath_as_report(struct BPathIterator *bpi, const char *message, Repo
break;
}
- name = BLI_bpathIterator_getName(bpi);
+ name= BLI_bpathIterator_getName(bpi);
BLI_bpathIterator_getPathExpanded(bpi, path_expanded);
if(reports) {
@@ -484,37 +667,38 @@ static void bpath_as_report(struct BPathIterator *bpi, const char *message, Repo
}
/* high level function */
-void checkMissingFiles(char *basepath, ReportList *reports) {
- struct BPathIterator bpi;
+void checkMissingFiles(Main *bmain, ReportList *reports) {
+ struct BPathIterator *bpi;
/* be sure there is low chance of the path being too short */
char filepath_expanded[FILE_MAXDIR*2];
- BLI_bpathIterator_init(&bpi, basepath);
- while (!BLI_bpathIterator_isDone(&bpi)) {
- BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded );
+ BLI_bpathIterator_init(&bpi, bmain, bmain->name, 0);
+ while (!BLI_bpathIterator_isDone(bpi)) {
+ BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded);
if (!BLI_exists(filepath_expanded))
- bpath_as_report(&bpi, "file not found", reports);
+ bpath_as_report(bpi, "file not found", reports);
- BLI_bpathIterator_step(&bpi);
+ BLI_bpathIterator_step(bpi);
}
- BLI_bpathIterator_free(&bpi);
+ BLI_bpathIterator_free(bpi);
}
/* dont log any errors at the moment, should probably do this */
-void makeFilesRelative(char *basepath, ReportList *reports) {
+void makeFilesRelative(Main *bmain, const char *basedir, ReportList *reports) {
int tot= 0, changed= 0, failed= 0, linked= 0;
- struct BPathIterator bpi;
- char filepath[FILE_MAX], *libpath;
+ struct BPathIterator *bpi;
+ char filepath[FILE_MAX];
+ const char *libpath;
/* be sure there is low chance of the path being too short */
char filepath_relative[(FILE_MAXDIR * 2) + FILE_MAXFILE];
- BLI_bpathIterator_init(&bpi, basepath);
- while (!BLI_bpathIterator_isDone(&bpi)) {
- BLI_bpathIterator_getPath(&bpi, filepath);
- libpath = BLI_bpathIterator_getLib(&bpi);
+ BLI_bpathIterator_init(&bpi, bmain, basedir, 0);
+ while (!BLI_bpathIterator_isDone(bpi)) {
+ BLI_bpathIterator_getPath(bpi, filepath);
+ libpath= BLI_bpathIterator_getLib(bpi);
if(strncmp(filepath, "//", 2)) {
if (libpath) { /* cant make relative if we are library - TODO, LOG THIS */
@@ -523,27 +707,27 @@ void makeFilesRelative(char *basepath, ReportList *reports) {
BLI_strncpy(filepath_relative, filepath, sizeof(filepath_relative));
/* Important BLI_cleanup_dir runs before the path is made relative
* because it wont work for paths that start with "//../" */
- BLI_cleanup_file(bpi.base_path, filepath_relative); /* fix any /foo/../foo/ */
- BLI_path_rel(filepath_relative, bpi.base_path);
+ BLI_cleanup_file(bpi->base_path, filepath_relative); /* fix any /foo/../foo/ */
+ BLI_path_rel(filepath_relative, bpi->base_path);
/* be safe and check the length */
- if (BLI_bpathIterator_getPathMaxLen(&bpi) <= strlen(filepath_relative)) {
- bpath_as_report(&bpi, "couldn't make path relative (too long)", reports);
+ if (BLI_bpathIterator_getPathMaxLen(bpi) <= strlen(filepath_relative)) {
+ bpath_as_report(bpi, "couldn't make path relative (too long)", reports);
failed++;
} else {
if(strncmp(filepath_relative, "//", 2)==0) {
- BLI_bpathIterator_setPath(&bpi, filepath_relative);
+ BLI_bpathIterator_setPath(bpi, filepath_relative);
changed++;
} else {
- bpath_as_report(&bpi, "couldn't make path relative", reports);
+ bpath_as_report(bpi, "couldn't make path relative", reports);
failed++;
}
}
}
}
- BLI_bpathIterator_step(&bpi);
+ BLI_bpathIterator_step(bpi);
tot++;
}
- BLI_bpathIterator_free(&bpi);
+ BLI_bpathIterator_free(bpi);
if(reports)
BKE_reportf(reports, failed ? RPT_ERROR : RPT_INFO, "Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
@@ -551,46 +735,47 @@ void makeFilesRelative(char *basepath, ReportList *reports) {
/* dont log any errors at the moment, should probably do this -
* Verry similar to makeFilesRelative - keep in sync! */
-void makeFilesAbsolute(char *basepath, ReportList *reports)
+void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports)
{
int tot= 0, changed= 0, failed= 0, linked= 0;
- struct BPathIterator bpi;
- char filepath[FILE_MAX], *libpath;
+ struct BPathIterator *bpi;
+ char filepath[FILE_MAX];
+ const char *libpath;
/* be sure there is low chance of the path being too short */
char filepath_absolute[(FILE_MAXDIR * 2) + FILE_MAXFILE];
- BLI_bpathIterator_init(&bpi, basepath);
- while (!BLI_bpathIterator_isDone(&bpi)) {
- BLI_bpathIterator_getPath(&bpi, filepath);
- libpath = BLI_bpathIterator_getLib(&bpi);
+ BLI_bpathIterator_init(&bpi, bmain, basedir, 0);
+ while (!BLI_bpathIterator_isDone(bpi)) {
+ BLI_bpathIterator_getPath(bpi, filepath);
+ libpath= BLI_bpathIterator_getLib(bpi);
if(strncmp(filepath, "//", 2)==0) {
if (libpath) { /* cant make absolute if we are library - TODO, LOG THIS */
linked++;
} else { /* get the expanded path and check it is relative or too long */
- BLI_bpathIterator_getPathExpanded( &bpi, filepath_absolute );
- BLI_cleanup_file(bpi.base_path, filepath_absolute); /* fix any /foo/../foo/ */
+ BLI_bpathIterator_getPathExpanded(bpi, filepath_absolute);
+ BLI_cleanup_file(bpi->base_path, filepath_absolute); /* fix any /foo/../foo/ */
/* to be safe, check the length */
- if (BLI_bpathIterator_getPathMaxLen(&bpi) <= strlen(filepath_absolute)) {
- bpath_as_report(&bpi, "couldn't make absolute (too long)", reports);
+ if (BLI_bpathIterator_getPathMaxLen(bpi) <= strlen(filepath_absolute)) {
+ bpath_as_report(bpi, "couldn't make absolute (too long)", reports);
failed++;
} else {
if(strncmp(filepath_absolute, "//", 2)) {
- BLI_bpathIterator_setPath(&bpi, filepath_absolute);
+ BLI_bpathIterator_setPath(bpi, filepath_absolute);
changed++;
} else {
- bpath_as_report(&bpi, "couldn't make absolute", reports);
+ bpath_as_report(bpi, "couldn't make absolute", reports);
failed++;
}
}
}
}
- BLI_bpathIterator_step(&bpi);
+ BLI_bpathIterator_step(bpi);
tot++;
}
- BLI_bpathIterator_free(&bpi);
+ BLI_bpathIterator_free(bpi);
if(reports)
BKE_reportf(reports, failed ? RPT_ERROR : RPT_INFO, "Total files %i|Changed %i|Failed %i|Linked %i", tot, changed, failed, linked);
@@ -612,20 +797,20 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char
char path[FILE_MAX];
int size;
- dir = opendir(dirname);
+ dir= opendir(dirname);
- if (dir==0)
+ if (dir==NULL)
return 0;
if (*filesize == -1)
- *filesize = 0; /* dir opened fine */
+ *filesize= 0; /* dir opened fine */
- while ((de = readdir(dir)) != NULL) {
+ while ((de= readdir(dir)) != NULL) {
if (strcmp(".", de->d_name)==0 || strcmp("..", de->d_name)==0)
continue;
- BLI_join_dirfile(path, dirname, de->d_name);
+ BLI_join_dirfile(path, sizeof(path), dirname, de->d_name);
if (stat(path, &status) != 0)
continue; /* cant stat, dont bother with this file, could print debug info here */
@@ -633,9 +818,9 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char
if (S_ISREG(status.st_mode)) { /* is file */
if (strncmp(filename, de->d_name, FILE_MAX)==0) { /* name matches */
/* open the file to read its size */
- size = BLI_filepathsize(path);
+ size= status.st_size;
if ((size > 0) && (size > *filesize)) { /* find the biggest file */
- *filesize = size;
+ *filesize= size;
BLI_strncpy(filename_new, path, FILE_MAX);
}
}
@@ -652,12 +837,13 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char
}
/* high level function - call from fileselector */
-void findMissingFiles(char *basepath, char *str) {
- struct BPathIterator bpi;
+void findMissingFiles(Main *bmain, const char *str) {
+ struct BPathIterator *bpi;
/* be sure there is low chance of the path being too short */
char filepath_expanded[FILE_MAXDIR*2];
- char filepath[FILE_MAX], *libpath;
+ char filepath[FILE_MAX];
+ const char *libpath;
int filesize, recur_depth;
char dirname[FILE_MAX], filename_new[FILE_MAX];
@@ -666,11 +852,11 @@ void findMissingFiles(char *basepath, char *str) {
BLI_split_dirfile(str, dirname, NULL);
- BLI_bpathIterator_init(&bpi, basepath);
+ BLI_bpathIterator_init(&bpi, bmain, bmain->name, 0);
- while (!BLI_bpathIterator_isDone(&bpi)) {
- BLI_bpathIterator_getPath(&bpi, filepath);
- libpath = BLI_bpathIterator_getLib(&bpi);
+ while (!BLI_bpathIterator_isDone(bpi)) {
+ BLI_bpathIterator_getPath(bpi, filepath);
+ libpath= BLI_bpathIterator_getLib(bpi);
/* Check if esc was pressed because searching files can be slow */
/*XXX if (blender_test_break()) {
@@ -679,12 +865,12 @@ void findMissingFiles(char *basepath, char *str) {
if (libpath==NULL) {
- BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded );
+ BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded);
if (!BLI_exists(filepath_expanded)) {
/* can the dir be opened? */
- filesize = -1;
- recur_depth = 0;
+ filesize= -1;
+ recur_depth= 0;
findFileRecursive(filename_new, dirname, BLI_path_basename(filepath), &filesize, &recur_depth);
if (filesize == -1) { /* could not open dir */
@@ -694,21 +880,21 @@ void findMissingFiles(char *basepath, char *str) {
if (filesize > 0) {
- if (BLI_bpathIterator_getPathMaxLen( &bpi ) < strlen(filename_new)) {
+ if (BLI_bpathIterator_getPathMaxLen(bpi) < strlen(filename_new)) {
printf("cannot set path \"%s\" too long!", filename_new);
} else {
/* copy the found path into the old one */
if (G.relbase_valid)
- BLI_path_rel(filename_new, bpi.base_path);
+ BLI_path_rel(filename_new, bpi->base_path);
- BLI_bpathIterator_setPath( &bpi, filename_new );
+ BLI_bpathIterator_setPath(bpi, filename_new);
}
}
}
}
- BLI_bpathIterator_step(&bpi);
+ BLI_bpathIterator_step(bpi);
}
- BLI_bpathIterator_free(&bpi);
+ BLI_bpathIterator_free(bpi);
//XXX waitcursor( 0 );
}
diff --git a/source/blender/blenlib/intern/cpu.c b/source/blender/blenlib/intern/cpu.c
index 65e6b34488c..644b4e72025 100644
--- a/source/blender/blenlib/intern/cpu.c
+++ b/source/blender/blenlib/intern/cpu.c
@@ -1,4 +1,4 @@
-/**
+/*
*
* $Id$
*
diff --git a/source/blender/blenlib/intern/dynamiclist.h b/source/blender/blenlib/intern/dynamiclist.h
index 3bf6e54a79b..03ccca576ff 100644
--- a/source/blender/blenlib/intern/dynamiclist.h
+++ b/source/blender/blenlib/intern/dynamiclist.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
diff --git a/source/blender/blenlib/intern/dynlib.c b/source/blender/blenlib/intern/dynlib.c
index f42b342e326..eb769d19210 100644
--- a/source/blender/blenlib/intern/dynlib.c
+++ b/source/blender/blenlib/intern/dynlib.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -63,7 +63,7 @@ PILdynlib *PIL_dynlib_open(char *name) {
}
}
-void *PIL_dynlib_find_symbol(PILdynlib* lib, char *symname) {
+void *PIL_dynlib_find_symbol(PILdynlib* lib, const char *symname) {
return GetProcAddress(lib->handle, symname);
}
@@ -87,7 +87,7 @@ char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
return buf;
}
- return err;
+ return NULL;
}
void PIL_dynlib_close(PILdynlib *lib) {
@@ -117,11 +117,12 @@ PILdynlib *PIL_dynlib_open(char *name) {
}
}
-void *PIL_dynlib_find_symbol(PILdynlib* lib, char *symname) {
+void *PIL_dynlib_find_symbol(PILdynlib* lib, const char *symname) {
return dlsym(lib->handle, symname);
}
char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
+ (void)lib; /* unused */
return dlerror();
}
diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c
index 44abd13c3fd..f885f7e5b22 100644
--- a/source/blender/blenlib/intern/edgehash.c
+++ b/source/blender/blenlib/intern/edgehash.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index fde770c238c..5ee652264c0 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -41,86 +41,24 @@
#ifdef WIN32
#include <io.h>
#include "BLI_winstuff.h"
+#include "BLI_callbacks.h"
#else
#include <unistd.h> // for read close
#include <sys/param.h>
#endif
-
#include "BLI_blenlib.h"
#include "BKE_utildefines.h"
#include "BLO_sys_types.h" // for intptr_t support
-/* implementations: */
-char *first_slash(char *string) {
- char *ffslash, *fbslash;
-
- ffslash= strchr(string, '/');
- fbslash= strchr(string, '\\');
-
- if (!ffslash) return fbslash;
- else if (!fbslash) return ffslash;
-
- if ((intptr_t)ffslash < (intptr_t)fbslash) return ffslash;
- else return fbslash;
-}
-
-char *BLI_last_slash(const char *string) {
- char *lfslash, *lbslash;
-
- lfslash= strrchr(string, '/');
- lbslash= strrchr(string, '\\');
-
- if (!lfslash) return lbslash;
- else if (!lbslash) return lfslash;
-
- if ((intptr_t)lfslash < (intptr_t)lbslash) return lbslash;
- else return lfslash;
-}
-
-/* adds a slash if there isnt one there already */
-int BLI_add_slash(char *string) {
- int len = strlen(string);
-#ifdef WIN32
- if (len==0 || string[len-1]!='\\') {
- string[len] = '\\';
- string[len+1] = '\0';
- return len+1;
- }
-#else
- if (len==0 || string[len-1]!='/') {
- string[len] = '/';
- string[len+1] = '\0';
- return len+1;
- }
-#endif
- return len;
-}
-
-/* removes a slash if there is one */
-void BLI_del_slash(char *string) {
- int len = strlen(string);
- while (len) {
-#ifdef WIN32
- if (string[len-1]=='\\') {
-#else
- if (string[len-1]=='/') {
-#endif
- string[len-1] = '\0';
- len--;
- } else {
- break;
- }
- }
-}
/* gzip the file in from and write it to "to".
return -1 if zlib fails, -2 if the originating file does not exist
note: will remove the "from" file
*/
-int BLI_gzip(char *from, char *to) {
+int BLI_gzip(const char *from, const char *to) {
char buffer[10240];
int file;
int readsize = 0;
@@ -160,7 +98,7 @@ int BLI_gzip(char *from, char *to) {
}
/* return 1 when file can be written */
-int BLI_is_writable(char *filename)
+int BLI_is_writable(const char *filename)
{
int file;
@@ -205,7 +143,7 @@ int BLI_touch(const char *file)
return 0;
}
-int BLI_exists(char *file) {
+int BLI_exists(const char *file) {
return BLI_exist(file);
}
@@ -213,7 +151,7 @@ int BLI_exists(char *file) {
static char str[MAXPATHLEN+12];
-int BLI_delete(char *file, int dir, int recursive) {
+int BLI_delete(const char *file, int dir, int recursive) {
int err;
if (recursive) {
@@ -230,7 +168,7 @@ int BLI_delete(char *file, int dir, int recursive) {
return err;
}
-int BLI_move(char *file, char *to) {
+int BLI_move(const char *file, const char *to) {
int err;
// windows doesn't support moveing to a directory
@@ -255,7 +193,7 @@ int BLI_move(char *file, char *to) {
}
-int BLI_copy_fileops(char *file, char *to) {
+int BLI_copy_fileops(const char *file, const char *to) {
int err;
// windows doesn't support copying to a directory
@@ -280,13 +218,13 @@ int BLI_copy_fileops(char *file, char *to) {
return err;
}
-int BLI_link(char *file, char *to) {
+int BLI_link(const char *file, const char *to) {
callLocalErrorCallBack("Linking files is unsupported on Windows");
return 1;
}
-void BLI_recurdir_fileops(char *dirname) {
+void BLI_recurdir_fileops(const char *dirname) {
char *lslash;
char tmp[MAXPATHLEN];
@@ -316,7 +254,7 @@ void BLI_recurdir_fileops(char *dirname) {
callLocalErrorCallBack("Unable to create directory\n");
}
-int BLI_rename(char *from, char *to) {
+int BLI_rename(const char *from, const char *to) {
if (!BLI_exists(from)) return 0;
/* make sure the filenames are different (case insensitive) before removing */
@@ -326,55 +264,55 @@ int BLI_rename(char *from, char *to) {
return rename(from, to);
}
-#else /* The weirdo UNIX world */
+#else /* The UNIX world */
/*
* but the UNIX world is tied to the interface, and the system
* timer, and... We implement a callback mechanism. The system will
* have to initialise the callback before the functions will work!
* */
-static char str[MAXPATHLEN+12];
+static char str[12 + (MAXPATHLEN * 2)];
-int BLI_delete(char *file, int dir, int recursive)
+int BLI_delete(const char *file, int dir, int recursive)
{
if(strchr(file, '"')) {
printf("Error: not deleted file %s because of quote!\n", file);
}
else {
if (recursive) {
- sprintf(str, "/bin/rm -rf \"%s\"", file);
+ BLI_snprintf(str, sizeof(str), "/bin/rm -rf \"%s\"", file);
return system(str);
}
else if (dir) {
- sprintf(str, "/bin/rmdir \"%s\"", file);
+ BLI_snprintf(str, sizeof(str), "/bin/rmdir \"%s\"", file);
return system(str);
}
else {
- return remove(file); //sprintf(str, "/bin/rm -f \"%s\"", file);
+ return remove(file); //BLI_snprintf(str, sizeof(str), "/bin/rm -f \"%s\"", file);
}
}
return -1;
}
-int BLI_move(char *file, char *to) {
- sprintf(str, "/bin/mv -f \"%s\" \"%s\"", file, to);
+int BLI_move(const char *file, const char *to) {
+ BLI_snprintf(str, sizeof(str), "/bin/mv -f \"%s\" \"%s\"", file, to);
return system(str);
}
-int BLI_copy_fileops(char *file, char *to) {
- sprintf(str, "/bin/cp -rf \"%s\" \"%s\"", file, to);
+int BLI_copy_fileops(const char *file, const char *to) {
+ BLI_snprintf(str, sizeof(str), "/bin/cp -rf \"%s\" \"%s\"", file, to);
return system(str);
}
-int BLI_link(char *file, char *to) {
- sprintf(str, "/bin/ln -f \"%s\" \"%s\"", file, to);
+int BLI_link(const char *file, const char *to) {
+ BLI_snprintf(str, sizeof(str), "/bin/ln -f \"%s\" \"%s\"", file, to);
return system(str);
}
-void BLI_recurdir_fileops(char *dirname) {
+void BLI_recurdir_fileops(const char *dirname) {
char *lslash;
char tmp[MAXPATHLEN];
@@ -392,7 +330,7 @@ void BLI_recurdir_fileops(char *dirname) {
mkdir(dirname, 0777);
}
-int BLI_rename(char *from, char *to) {
+int BLI_rename(const char *from, const char *to) {
if (!BLI_exists(from)) return 0;
if (BLI_exists(to)) if(BLI_delete(to, 0, 0)) return 1;
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index 6d6abc88999..1b569cf794f 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -46,12 +46,13 @@
#include "BLI_vfontdata.h"
#include "BLI_blenlib.h"
-#include "BLI_math.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
//XXX #include "BIF_toolbox.h"
#include "BKE_font.h"
-#include "BKE_utildefines.h"
+
#include "DNA_vfont_types.h"
#include "DNA_packedFile_types.h"
@@ -126,7 +127,6 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf
// get number of on-curve points for beziertriples (including conic virtual on-points)
for(j = 0; j < ftoutline.n_contours; j++) {
- l = 0;
for(k = 0; k < npoints[j]; k++) {
if(j > 0) l = k + ftoutline.contours[j - 1] + 1; else l = k;
if(ftoutline.tags[l] == FT_Curve_Tag_On)
@@ -252,15 +252,15 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf
}
// get the handles that are aligned, tricky...
- // DistVL2Dfl, check if the three beztriple points are on one line
- // VecLenf, see if there's a distance between the three points
- // VecLenf again, to check the angle between the handles
+ // dist_to_line_v2, check if the three beztriple points are on one line
+ // len_squared_v2v2, see if there's a distance between the three points
+ // len_squared_v2v2 again, to check the angle between the handles
// finally, check if one of them is a vector handle
if((dist_to_line_v2(bezt->vec[0],bezt->vec[1],bezt->vec[2]) < 0.001) &&
- (len_v3v3(bezt->vec[0], bezt->vec[1]) > 0.0001) &&
- (len_v3v3(bezt->vec[1], bezt->vec[2]) > 0.0001) &&
- (len_v3v3(bezt->vec[0], bezt->vec[2]) > 0.0002) &&
- (len_v3v3(bezt->vec[0], bezt->vec[2]) > MAX2(len_v3v3(bezt->vec[0], bezt->vec[1]), len_v3v3(bezt->vec[1], bezt->vec[2]))) &&
+ (len_squared_v2v2(bezt->vec[0], bezt->vec[1]) > 0.0001*0.0001) &&
+ (len_squared_v2v2(bezt->vec[1], bezt->vec[2]) > 0.0001*0.0001) &&
+ (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > 0.0002*0.0001) &&
+ (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > MAX2(len_squared_v2v2(bezt->vec[0], bezt->vec[1]), len_squared_v2v2(bezt->vec[1], bezt->vec[2]))) &&
bezt->h1 != HD_VECT && bezt->h2 != HD_VECT)
{
bezt->h1= bezt->h2= HD_ALIGN;
@@ -367,7 +367,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
// No charmap found from the ttf so we need to figure it out
if(glyph_index == 0)
{
- FT_CharMap found = 0;
+ FT_CharMap found = NULL;
FT_CharMap charmap;
int n;
@@ -477,7 +477,7 @@ VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf)
err = FT_Init_FreeType( &library);
if(err) {
//XXX error("Failed to load the Freetype font library");
- return 0;
+ return NULL;
}
success = check_freetypefont(pf);
diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c
index b1ea058eda1..050effdf5b4 100644
--- a/source/blender/blenlib/intern/graph.c
+++ b/source/blender/blenlib/intern/graph.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -31,8 +31,9 @@
#include "BLI_graph.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
-#include "BKE_utildefines.h"
static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, int total, float axis[3], float limit, int group);
@@ -128,7 +129,7 @@ void BLI_buildAdjacencyList(BGraph *graph)
{
if (node->degree != node->flag)
{
- printf("error in node [%p]. Added only %i arcs out of %i\n", node, node->flag, node->degree);
+ printf("error in node [%p]. Added only %i arcs out of %i\n", (void *)node, node->flag, node->degree);
}
}
}
@@ -161,7 +162,7 @@ void BLI_rebuildAdjacencyListForNode(BGraph* graph, BNode *node)
if (node->degree != node->flag)
{
- printf("error in node [%p]. Added only %i arcs out of %i\n", node, node->flag, node->degree);
+ printf("error in node [%p]. Added only %i arcs out of %i\n", (void *)node, node->flag, node->degree);
}
}
@@ -295,7 +296,7 @@ BNode * BLI_FindNodeByPosition(BGraph *graph, float *p, float limit)
}
/************************************* SUBGRAPH DETECTION **********************************************/
-void flagSubgraph(BNode *node, int subgraph)
+static void flagSubgraph(BNode *node, int subgraph)
{
if (node->subgraph_index == 0)
{
@@ -409,7 +410,7 @@ int BLI_isGraphCyclic(BGraph *graph)
BArc * BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v)
{
- BArc *nextArc = arc->next;
+ BArc *nextArc;
for(nextArc = graph->arcs.first; nextArc; nextArc = nextArc->next)
{
@@ -424,7 +425,7 @@ BArc * BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v)
/*********************************** GRAPH AS TREE FUNCTIONS *******************************************/
-int subtreeShape(BNode *node, BArc *rootArc, int include_root)
+static int subtreeShape(BNode *node, BArc *rootArc, int include_root)
{
int depth = 0;
diff --git a/source/blender/blenlib/intern/gsqueue.c b/source/blender/blenlib/intern/gsqueue.c
index a8b40e187d8..0936759b680 100644
--- a/source/blender/blenlib/intern/gsqueue.c
+++ b/source/blender/blenlib/intern/gsqueue.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
diff --git a/source/blender/blenlib/intern/jitter.c b/source/blender/blenlib/intern/jitter.c
index dfc554394d6..f4305d45735 100644
--- a/source/blender/blenlib/intern/jitter.c
+++ b/source/blender/blenlib/intern/jitter.c
@@ -1,4 +1,4 @@
-/**
+/*
* Jitter offset table
*
* $Id$
@@ -34,6 +34,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_rand.h"
+#include "BLI_jitter.h"
void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1)
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c
index 776f2d085df..975479a3875 100644
--- a/source/blender/blenlib/intern/listbase.c
+++ b/source/blender/blenlib/intern/listbase.c
@@ -46,20 +46,20 @@
/* implementation */
/* Ripped this from blender.c */
-void addlisttolist(ListBase *list1, ListBase *list2)
+void BLI_movelisttolist(ListBase *dst, ListBase *src)
{
- if (list2->first==0) return;
+ if (src->first==NULL) return;
- if (list1->first==0) {
- list1->first= list2->first;
- list1->last= list2->last;
+ if (dst->first==NULL) {
+ dst->first= src->first;
+ dst->last= src->last;
}
else {
- ((Link *)list1->last)->next= list2->first;
- ((Link *)list2->first)->prev= list1->last;
- list1->last= list2->last;
+ ((Link *)dst->last)->next= src->first;
+ ((Link *)src->first)->prev= dst->last;
+ dst->last= src->last;
}
- list2->first= list2->last= 0;
+ src->first= src->last= NULL;
}
void BLI_addhead(ListBase *listbase, void *vlink)
@@ -89,7 +89,7 @@ void BLI_addtail(ListBase *listbase, void *vlink)
link->prev = listbase->last;
if (listbase->last) ((Link *)listbase->last)->next = link;
- if (listbase->first == 0) listbase->first = link;
+ if (listbase->first == NULL) listbase->first = link;
listbase->last = link;
}
@@ -152,7 +152,7 @@ void BLI_insertlink(ListBase *listbase, void *vprevlink, void *vnewlink)
/* insert before first element */
if (prevlink == NULL) {
newlink->next= listbase->first;
- newlink->prev= 0;
+ newlink->prev= NULL;
newlink->next->prev= newlink;
listbase->first= newlink;
return;
@@ -251,7 +251,7 @@ void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink)
/* insert at end of list */
if (nextlink == NULL) {
newlink->prev= listbase->last;
- newlink->next= 0;
+ newlink->next= NULL;
((Link *)listbase->last)->next= newlink;
listbase->last= newlink;
return;
@@ -304,7 +304,7 @@ void BLI_freelistN(ListBase *listbase)
}
-int BLI_countlist(ListBase *listbase)
+int BLI_countlist(const ListBase *listbase)
{
Link *link;
int count = 0;
@@ -319,7 +319,7 @@ int BLI_countlist(ListBase *listbase)
return count;
}
-void *BLI_findlink(ListBase *listbase, int number)
+void *BLI_findlink(const ListBase *listbase, int number)
{
Link *link = NULL;
@@ -334,7 +334,7 @@ void *BLI_findlink(ListBase *listbase, int number)
return link;
}
-int BLI_findindex(ListBase *listbase, void *vlink)
+int BLI_findindex(const ListBase *listbase, void *vlink)
{
Link *link= NULL;
int number= 0;
@@ -354,7 +354,7 @@ int BLI_findindex(ListBase *listbase, void *vlink)
return -1;
}
-void *BLI_findstring(ListBase *listbase, const char *id, int offset)
+void *BLI_findstring(const ListBase *listbase, const char *id, const int offset)
{
Link *link= NULL;
const char *id_iter;
@@ -374,7 +374,7 @@ void *BLI_findstring(ListBase *listbase, const char *id, int offset)
return NULL;
}
-void *BLI_findstring_ptr(ListBase *listbase, const char *id, int offset)
+void *BLI_findstring_ptr(const ListBase *listbase, const char *id, const int offset)
{
Link *link= NULL;
const char *id_iter;
@@ -395,7 +395,7 @@ void *BLI_findstring_ptr(ListBase *listbase, const char *id, int offset)
return NULL;
}
-int BLI_findstringindex(ListBase *listbase, const char *id, int offset)
+int BLI_findstringindex(const ListBase *listbase, const char *id, const int offset)
{
Link *link= NULL;
const char *id_iter;
@@ -416,20 +416,20 @@ int BLI_findstringindex(ListBase *listbase, const char *id, int offset)
return -1;
}
-void BLI_duplicatelist(ListBase *list1, const ListBase *list2)
+void BLI_duplicatelist(ListBase *dst, const ListBase *src)
{
- struct Link *link1, *link2;
-
- /* in this order, to ensure it works if list1 == list2 */
- link2= list2->first;
- list1->first= list1->last= 0;
-
- while(link2) {
- link1= MEM_dupallocN(link2);
- BLI_addtail(list1, link1);
-
- link2= link2->next;
- }
+ struct Link *dst_link, *src_link;
+
+ /* in this order, to ensure it works if dst == src */
+ src_link= src->first;
+ dst->first= dst->last= NULL;
+
+ while(src_link) {
+ dst_link= MEM_dupallocN(src_link);
+ BLI_addtail(dst, dst_link);
+
+ src_link= src_link->next;
+ }
}
/* create a generic list node containing link to provided data */
diff --git a/source/blender/blenlib/intern/math_base.c b/source/blender/blenlib/intern/math_base.c
index 686b35a878e..4f0d4bbeba0 100644
--- a/source/blender/blenlib/intern/math_base.c
+++ b/source/blender/blenlib/intern/math_base.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -52,7 +52,8 @@ double round(double x)
y += 1.0;
return copysign(y, x);
}
-
+#else /* OpenSuse 11.1 seems to need this. */
+double round(double x);
#endif
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index b364ff73e4f..099c14a6556 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -32,8 +32,8 @@
#include "BLI_math.h"
-#ifndef BLI_MATH_BASE_INLINE
-#define BLI_MATH_BASE_INLINE
+#ifndef BLI_MATH_BASE_INLINE_H
+#define BLI_MATH_BASE_INLINE_H
/* A few small defines. Keep'em local! */
#define SMALL_NUMBER 1.e-8
@@ -122,5 +122,10 @@ MINLINE float maxf(float a, float b)
return (a > b)? a: b;
}
-#endif /* BLI_MATH_BASE_INLINE */
+MINLINE float signf(float f)
+{
+ return (f < 0.f)? -1.f: 1.f;
+}
+
+#endif /* BLI_MATH_BASE_INLINE_H */
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 693fd885b50..2f2e8d6fc61 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -25,6 +25,7 @@
* ***** END GPL LICENSE BLOCK *****
* */
+#include <assert.h>
#include "BLI_math.h"
@@ -111,7 +112,7 @@ void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb)
void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, int colorspace)
{
float sr,sg, sb;
- float y, cr, cb;
+ float y = 128.f, cr = 128.f, cb = 128.f;
sr=255.0f*r;
sg=255.0f*g;
@@ -133,6 +134,8 @@ void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, in
cb=(-0.16874f*sr)-(0.33126f*sg)+(0.5f*sb)+128.0f;
cr=(0.5f*sr)-(0.41869f*sg)-(0.08131f*sb)+128.0f;
break;
+ default:
+ assert(!"invalid colorspace");
}
*ly=y;
@@ -141,11 +144,12 @@ void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, in
}
-/* YCC input have a range of 16-235 and 16-240 exepect with JFIF_0_255 where the range is 0-255 */
+/* YCC input have a range of 16-235 and 16-240 except with JFIF_0_255 where the range is 0-255 */
/* RGB outputs are in the range 0 - 1.0f */
+/* FIXME comment above must be wrong because BLI_YCC_ITU_BT601 y 16.0 cr 16.0 -> r -0.7009 */
void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, int colorspace)
{
- float r,g,b;
+ float r = 128.f, g = 128.f, b = 128.f;
switch (colorspace) {
case BLI_YCC_ITU_BT601 :
@@ -163,6 +167,8 @@ void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, in
g=y-0.34414f*cb - 0.71414f*cr + 135.45984f;
b=y+1.772f*cb - 226.816f;
break;
+ default:
+ assert(!"invalid colorspace");
}
*lr=r/255.0f;
*lg=g/255.0f;
@@ -172,13 +178,16 @@ void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, in
void hex_to_rgb(char *hexcol, float *r, float *g, float *b)
{
unsigned int ri, gi, bi;
-
+
if (hexcol[0] == '#') hexcol++;
-
- if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi)) {
+
+ if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi)==3) {
*r = ri / 255.0f;
- *g = gi / 255.0f;
+ *g = gi / 255.0f;
*b = bi / 255.0f;
+ CLAMP(*r, 0.0f, 1.0f);
+ CLAMP(*g, 0.0f, 1.0f);
+ CLAMP(*b, 0.0f, 1.0f);
}
}
@@ -200,7 +209,6 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)
s = (cmax - cmin)/cmax;
else {
s = 0.0f;
- h = 0.0f;
}
if (s == 0.0f)
h = -1.0f;
@@ -227,6 +235,26 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)
*lv = v;
}
+void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv)
+{
+ float orig_h= *lh;
+ float orig_s= *ls;
+
+ rgb_to_hsv(r, g, b, lh, ls, lv);
+
+ if(*lv <= 0.0f) {
+ *lh= orig_h;
+ *ls= orig_s;
+ }
+ else if (*ls <= 0.0f) {
+ *lh= orig_h;
+ }
+
+ if(*lh==0.0f && orig_h >= 1.0f) {
+ *lh= 1.0f;
+ }
+}
+
/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */
void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace)
@@ -298,14 +326,14 @@ void cpack_to_rgb(unsigned int col, float *r, float *g, float *b)
*b /= 255.0f;
}
-void rgb_byte_to_float(char *in, float *out)
+void rgb_byte_to_float(const unsigned char *in, float *out)
{
out[0]= ((float)in[0]) / 255.0f;
out[1]= ((float)in[1]) / 255.0f;
out[2]= ((float)in[2]) / 255.0f;
}
-void rgb_float_to_byte(float *in, char *out)
+void rgb_float_to_byte(const float *in, unsigned char *out)
{
int r, g, b;
@@ -393,6 +421,7 @@ void srgb_to_linearrgb_rgba_rgba_buf(float *col_to, float *col_from, int tot)
{
while(tot--) {
srgb_to_linearrgb_v3_v3(col_to, col_from);
+ col_to[3]= col_from[3];
col_to += 4;
col_from += 4;
}
@@ -402,6 +431,7 @@ void linearrgb_to_srgb_rgba_rgba_buf(float *col_to, float *col_from, int tot)
{
while(tot--) {
linearrgb_to_srgb_v3_v3(col_to, col_from);
+ col_to[3]= col_from[3];
col_to += 4;
col_from += 4;
}
@@ -418,7 +448,7 @@ void minmax_rgb(short c[])
}
/*If the requested RGB shade contains a negative weight for
- one of the primaries, it lies outside the colour gamut
+ one of the primaries, it lies outside the color gamut
accessible from the given triple of primaries. Desaturate
it by adding white, equal quantities of R, G, and B, enough
to make RGB all positive. The function returns 1 if the
@@ -464,3 +494,28 @@ void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *o
}
}
+/* ******************************************** other ************************************************* */
+
+/* Applies an hue offset to a float rgb color */
+void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset)
+{
+ float hsv[3];
+
+ rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
+
+ hsv[0]+= hue_offset;
+ if(hsv[0]>1.0) hsv[0]-=1.0;
+ else if(hsv[0]<0.0) hsv[0]+= 1.0;
+
+ hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
+}
+
+/* Applies an hue offset to a byte rgb color */
+void rgb_byte_set_hue_float_offset(unsigned char rgb[3], float hue_offset)
+{
+ float rgb_float[3];
+
+ rgb_byte_to_float(rgb, rgb_float);
+ rgb_float_set_hue_float_offset(rgb_float, hue_offset);
+ rgb_float_to_byte(rgb_float, rgb);
+}
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 6756f42bf35..2d4935ed4a6 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -30,8 +30,9 @@
#include "BLI_math.h"
#include "BLI_memarena.h"
+#include "BLI_utildefines.h"
+
-#include "BKE_utildefines.h"
/********************************** Polygons *********************************/
@@ -233,53 +234,114 @@ float dist_to_line_segment_v3(float *v1, float *v2, float *v3)
/******************************* Intersection ********************************/
/* intersect Line-Line, shorts */
-int isect_line_line_v2_short(short *v1, short *v2, short *v3, short *v4)
+int isect_line_line_v2_short(const short *v1, const short *v2, const short *v3, const short *v4)
{
- /* return:
- -1: colliniar
- 0: no intersection of segments
- 1: exact intersection of segments
- 2: cross-intersection of segments
- */
float div, labda, mu;
div= (float)((v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0]));
- if(div==0.0f) return -1;
+ if(div==0.0f) return ISECT_LINE_LINE_COLINEAR;
labda= ((float)(v1[1]-v3[1])*(v4[0]-v3[0])-(v1[0]-v3[0])*(v4[1]-v3[1]))/div;
mu= ((float)(v1[1]-v3[1])*(v2[0]-v1[0])-(v1[0]-v3[0])*(v2[1]-v1[1]))/div;
if(labda>=0.0f && labda<=1.0f && mu>=0.0f && mu<=1.0f) {
- if(labda==0.0f || labda==1.0f || mu==0.0f || mu==1.0f) return 1;
- return 2;
+ if(labda==0.0f || labda==1.0f || mu==0.0f || mu==1.0f) return ISECT_LINE_LINE_EXACT;
+ return ISECT_LINE_LINE_CROSS;
}
- return 0;
+ return ISECT_LINE_LINE_NONE;
}
/* intersect Line-Line, floats */
-int isect_line_line_v2(float *v1, float *v2, float *v3, float *v4)
+int isect_line_line_v2(const float *v1, const float *v2, const float *v3, const float *v4)
{
- /* return:
- -1: colliniar
-0: no intersection of segments
-1: exact intersection of segments
-2: cross-intersection of segments
- */
float div, labda, mu;
div= (v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0]);
- if(div==0.0) return -1;
+ if(div==0.0) return ISECT_LINE_LINE_COLINEAR;
labda= ((float)(v1[1]-v3[1])*(v4[0]-v3[0])-(v1[0]-v3[0])*(v4[1]-v3[1]))/div;
mu= ((float)(v1[1]-v3[1])*(v2[0]-v1[0])-(v1[0]-v3[0])*(v2[1]-v1[1]))/div;
if(labda>=0.0 && labda<=1.0 && mu>=0.0 && mu<=1.0) {
- if(labda==0.0 || labda==1.0 || mu==0.0 || mu==1.0) return 1;
- return 2;
+ if(labda==0.0 || labda==1.0 || mu==0.0 || mu==1.0) return ISECT_LINE_LINE_EXACT;
+ return ISECT_LINE_LINE_CROSS;
}
- return 0;
+ return ISECT_LINE_LINE_NONE;
+}
+
+/* get intersection point of two 2D segments and return intersection type:
+ -1: colliniar
+ 1: intersection */
+int isect_seg_seg_v2_point(const float *v1, const float *v2, const float *v3, const float *v4, float vi[2])
+{
+ float a1, a2, b1, b2, c1, c2, d;
+ float u, v;
+ const float eps= 0.000001f;
+
+ a1= v2[0]-v1[0];
+ b1= v4[0]-v3[0];
+ c1= v1[0]-v4[0];
+
+ a2= v2[1]-v1[1];
+ b2= v4[1]-v3[1];
+ c2= v1[1]-v4[1];
+
+ d= a1*b2-a2*b1;
+
+ if(d==0) {
+ if(a1*c2-a2*c1==0.0f && b1*c2-b2*c1==0.0f) { /* equal lines */
+ float a[2], b[2], c[2];
+ float u2;
+
+ if(len_v2v2(v1, v2)==0.0f) {
+ if(len_v2v2(v3, v4)>eps) {
+ /* use non-point segment as basis */
+ SWAP(const float *, v1, v3);
+ SWAP(const float *, v2, v4);
+ } else { /* both of segments are points */
+ if(equals_v2v2(v1, v3)) { /* points are equal */
+ copy_v2_v2(vi, v1);
+ return 1;
+ }
+
+ /* two different points */
+ return -1;
+ }
+ }
+
+ sub_v2_v2v2(a, v3, v1);
+ sub_v2_v2v2(b, v2, v1);
+ sub_v2_v2v2(c, v2, v1);
+ u= dot_v2v2(a, b) / dot_v2v2(c, c);
+
+ sub_v2_v2v2(a, v4, v1);
+ u2= dot_v2v2(a, b) / dot_v2v2(c, c);
+
+ if(u>u2) SWAP(float, u, u2);
+
+ if(u>1.0f+eps || u2<-eps) return -1; /* non-ovlerlapping segments */
+ else if(maxf(0.0f, u) == minf(1.0f, u2)){ /* one common point: can return result */
+ interp_v2_v2v2(vi, v1, v2, maxf(0, u));
+ return 1;
+ }
+ }
+
+ /* lines are colliniar */
+ return -1;
+ }
+
+ u= (c2*b1-b2*c1)/d;
+ v= (c1*a2-a1*c2)/d;
+
+ if(u>=-eps && u<=1.0f+eps && v>=-eps && v<=1.0f+eps) { /* intersection */
+ interp_v2_v2v2(vi, v1, v2, u);
+ return 1;
+ }
+
+ /* out of segment intersection */
+ return -1;
}
/*
@@ -336,20 +398,19 @@ static short IsectLLPt2Df(float x0,float y0,float x1,float y1,
return 1;
} // end Intersect_Lines
-#define SIDE_OF_LINE(pa,pb,pp) ((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1]))
/* point in tri */
-// XXX was called IsectPT2Df
+
int isect_point_tri_v2(float pt[2], float v1[2], float v2[2], float v3[2])
{
- if (SIDE_OF_LINE(v1,v2,pt)>=0.0) {
- if (SIDE_OF_LINE(v2,v3,pt)>=0.0) {
- if (SIDE_OF_LINE(v3,v1,pt)>=0.0) {
+ if (line_point_side_v2(v1,v2,pt)>=0.0) {
+ if (line_point_side_v2(v2,v3,pt)>=0.0) {
+ if (line_point_side_v2(v3,v1,pt)>=0.0) {
return 1;
}
}
} else {
- if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0)) {
- if (! (SIDE_OF_LINE(v3,v1,pt)>=0.0)) {
+ if (! (line_point_side_v2(v2,v3,pt)>=0.0)) {
+ if (! (line_point_side_v2(v3,v1,pt)>=0.0)) {
return -1;
}
}
@@ -360,18 +421,18 @@ int isect_point_tri_v2(float pt[2], float v1[2], float v2[2], float v3[2])
/* point in quad - only convex quads */
int isect_point_quad_v2(float pt[2], float v1[2], float v2[2], float v3[2], float v4[2])
{
- if (SIDE_OF_LINE(v1,v2,pt)>=0.0) {
- if (SIDE_OF_LINE(v2,v3,pt)>=0.0) {
- if (SIDE_OF_LINE(v3,v4,pt)>=0.0) {
- if (SIDE_OF_LINE(v4,v1,pt)>=0.0) {
+ if (line_point_side_v2(v1,v2,pt)>=0.0) {
+ if (line_point_side_v2(v2,v3,pt)>=0.0) {
+ if (line_point_side_v2(v3,v4,pt)>=0.0) {
+ if (line_point_side_v2(v4,v1,pt)>=0.0) {
return 1;
}
}
}
} else {
- if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0)) {
- if (! (SIDE_OF_LINE(v3,v4,pt)>=0.0)) {
- if (! (SIDE_OF_LINE(v4,v1,pt)>=0.0)) {
+ if (! (line_point_side_v2(v2,v3,pt)>=0.0)) {
+ if (! (line_point_side_v2(v3,v4,pt)>=0.0)) {
+ if (! (line_point_side_v2(v4,v1,pt)>=0.0)) {
return -1;
}
}
@@ -557,7 +618,7 @@ static int getLowestRoot(float a, float b, float c, float maxR, float* root)
if (determinant >= 0.0f)
{
// calculate the two roots: (if determinant == 0 then
- // x1==x2 but let’s disregard that slight optimization)
+ // x1==x2 but lets disregard that slight optimization)
float sqrtD = (float)sqrt(determinant);
float r1 = (-b - sqrtD) / (2.0f*a);
float r2 = (-b + sqrtD) / (2.0f*a);
@@ -589,7 +650,7 @@ int isect_sweeping_sphere_tri_v3(float p1[3], float p2[3], float radius, float v
{
float e1[3], e2[3], e3[3], point[3], vel[3], /*dist[3],*/ nor[3], temp[3], bv[3];
float a, b, c, d, e, x, y, z, radius2=radius*radius;
- float elen2,edotv,edotbv,nordotv,vel2;
+ float elen2,edotv,edotbv,nordotv;
float newLambda;
int found_by_sweep=0;
@@ -663,7 +724,7 @@ int isect_sweeping_sphere_tri_v3(float p1[3], float p2[3], float radius, float v
*lambda=1.0f;
/*---test points---*/
- a=vel2=dot_v3v3(vel,vel);
+ a=dot_v3v3(vel,vel);
/*v0*/
sub_v3_v3v3(temp,p1,v0);
@@ -752,10 +813,10 @@ int isect_sweeping_sphere_tri_v3(float p1[3], float p2[3], float radius, float v
}
/*e3*/
- sub_v3_v3v3(bv,v0,p1);
- elen2 = dot_v3v3(e1,e1);
- edotv = dot_v3v3(e1,vel);
- edotbv = dot_v3v3(e1,bv);
+ /* sub_v3_v3v3(bv,v0,p1); */ /* UNUSED */
+ /* elen2 = dot_v3v3(e1,e1); */ /* UNUSED */
+ /* edotv = dot_v3v3(e1,vel); */ /* UNUSED */
+ /* edotbv = dot_v3v3(e1,bv); */ /* UNUSED */
sub_v3_v3v3(bv,v1,p1);
elen2 = dot_v3v3(e3,e3);
@@ -900,7 +961,6 @@ int isect_line_line_strict_v3(float v1[3], float v2[3], float v3[3], float v4[3]
{
float a[3], b[3], c[3], ab[3], cb[3], ca[3], dir1[3], dir2[3];
float d;
- float d1;
sub_v3_v3v3(c, v3, v1);
sub_v3_v3v3(a, v2, v1);
@@ -913,8 +973,6 @@ int isect_line_line_strict_v3(float v1[3], float v2[3], float v3[3], float v4[3]
/* colinear or one vector is zero-length*/
return 0;
}
-
- d1 = d;
cross_v3_v3v3(ab, a, b);
d = dot_v3v3(c, ab);
@@ -961,7 +1019,7 @@ int isect_aabb_aabb_v3(float min1[3], float max1[3], float min2[3], float max2[3
/* find closest point to p on line through l1,l2 and return lambda,
* where (0 <= lambda <= 1) when cp is in the line segement l1,l2
*/
-float closest_to_line_v3(float cp[3],float p[3], float l1[3], float l2[3])
+float closest_to_line_v3(float cp[3], const float p[3], const float l1[3], const float l2[3])
{
float h[3],u[3],lambda;
sub_v3_v3v3(u, l2, l1);
@@ -973,6 +1031,17 @@ float closest_to_line_v3(float cp[3],float p[3], float l1[3], float l2[3])
return lambda;
}
+float closest_to_line_v2(float cp[2],const float p[2], const float l1[2], const float l2[2])
+{
+ float h[2],u[2],lambda;
+ sub_v2_v2v2(u, l2, l1);
+ sub_v2_v2v2(h, p, l1);
+ lambda =dot_v2v2(u,h)/dot_v2v2(u,u);
+ cp[0] = l1[0] + u[0] * lambda;
+ cp[1] = l1[1] + u[1] * lambda;
+ return lambda;
+}
+
#if 0
/* little sister we only need to know lambda */
static float lambda_cp_line(float p[3], float l1[3], float l2[3])
@@ -1289,6 +1358,71 @@ int clip_line_plane(float p1[3], float p2[3], float plane[4])
}
}
+
+void plot_line_v2v2i(int p1[2], int p2[2], int (*callback)(int, int, void *), void *userData)
+{
+ int x1= p1[0];
+ int y1= p1[1];
+ int x2= p2[0];
+ int y2= p2[1];
+
+ signed char ix;
+ signed char iy;
+
+ // if x1 == x2 or y1 == y2, then it does not matter what we set here
+ int delta_x = (x2 > x1?(ix = 1, x2 - x1):(ix = -1, x1 - x2)) << 1;
+ int delta_y = (y2 > y1?(iy = 1, y2 - y1):(iy = -1, y1 - y2)) << 1;
+
+ if(callback(x1, y1, userData) == 0) {
+ return;
+ }
+
+ if (delta_x >= delta_y) {
+ // error may go below zero
+ int error = delta_y - (delta_x >> 1);
+
+ while (x1 != x2) {
+ if (error >= 0) {
+ if (error || (ix > 0)) {
+ y1 += iy;
+ error -= delta_x;
+ }
+ // else do nothing
+ }
+ // else do nothing
+
+ x1 += ix;
+ error += delta_y;
+
+ if(callback(x1, y1, userData) == 0) {
+ return ;
+ }
+ }
+ }
+ else {
+ // error may go below zero
+ int error = delta_x - (delta_y >> 1);
+
+ while (y1 != y2) {
+ if (error >= 0) {
+ if (error || (iy > 0)) {
+ x1 += ix;
+ error -= delta_y;
+ }
+ // else do nothing
+ }
+ // else do nothing
+
+ y1 += iy;
+ error += delta_x;
+
+ if(callback(x1, y1, userData) == 0) {
+ return;
+ }
+ }
+ }
+}
+
/****************************** Interpolation ********************************/
static float tri_signed_area(float *v1, float *v2, float *v3, int i, int j)
@@ -1647,6 +1781,35 @@ void perspective_m4(float mat[][4],float left, float right, float bottom, float
}
+/* translate a matrix created by orthographic_m4 or perspective_m4 in XY coords (used to jitter the view) */
+void window_translate_m4(float winmat[][4], float perspmat[][4], float x, float y)
+{
+ if(winmat[2][3] == -1.0f) {
+ /* in the case of a win-matrix, this means perspective always */
+ float v1[3];
+ float v2[3];
+ float len1, len2;
+
+ v1[0]= perspmat[0][0];
+ v1[1]= perspmat[1][0];
+ v1[2]= perspmat[2][0];
+
+ v2[0]= perspmat[0][1];
+ v2[1]= perspmat[1][1];
+ v2[2]= perspmat[2][1];
+
+ len1= (1.0f / len_v3(v1));
+ len2= (1.0f / len_v3(v2));
+
+ winmat[2][0] += len1 * winmat[0][0] * x;
+ winmat[2][1] += len2 * winmat[1][1] * y;
+ }
+ else {
+ winmat[3][0] += x;
+ winmat[3][1] += y;
+ }
+}
+
static void i_multmatrix(float icand[][4], float Vm[][4])
{
int row, col;
@@ -1676,10 +1839,9 @@ void polarview_m4(float Vm[][4],float dist, float azimuth, float incidence, floa
void lookat_m4(float mat[][4],float vx, float vy, float vz, float px, float py, float pz, float twist)
{
float sine, cosine, hyp, hyp1, dx, dy, dz;
- float mat1[4][4];
+ float mat1[4][4]= MAT4_UNITY;
unit_m4(mat);
- unit_m4(mat1);
rotate_m4(mat, 'Z', -twist);
@@ -1918,7 +2080,7 @@ pointers may be NULL if not needed
*/
/* can't believe there is none in math utils */
-float _det_m3(float m2[3][3])
+static float _det_m3(float m2[3][3])
{
float det = 0.f;
if (m2){
@@ -2469,4 +2631,3 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl
return contrib;
}
-
diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c
index f2d8e27cbd5..11310f25075 100644
--- a/source/blender/blenlib/intern/math_geom_inline.c
+++ b/source/blender/blenlib/intern/math_geom_inline.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -27,8 +27,8 @@
#include "BLI_math.h"
-#ifndef BLI_MATH_GEOM_INLINE
-#define BLI_MATH_GEOM_INLINE
+#ifndef BLI_MATH_GEOM_INLINE_H
+#define BLI_MATH_GEOM_INLINE_H
/****************************** Spherical Harmonics **************************/
@@ -134,5 +134,5 @@ MINLINE void madd_sh_shfl(float r[9], float sh[3], float f)
add_sh_shsh(r, r, tmp);
}
-#endif /* BLI_MATH_GEOM_INLINE */
+#endif /* BLI_MATH_GEOM_INLINE_H */
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 64c3e746982..413ac57dea5 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -25,7 +25,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
-
+#include <assert.h>
#include "BLI_math.h"
/********************************* Init **************************************/
@@ -109,6 +109,20 @@ void copy_m4_m3(float m1[][4], float m2[][3]) /* no clear */
}
+void swap_m3m3(float m1[][3], float m2[][3])
+{
+ float t;
+ int i, j;
+
+ for(i = 0; i < 3; i++) {
+ for (j = 0; j < 3; j++) {
+ t = m1[i][j];
+ m1[i][j] = m2[i][j];
+ m2[i][j] = t;
+ }
+ }
+}
+
void swap_m4m4(float m1[][4], float m2[][4])
{
float t;
@@ -228,7 +242,7 @@ void mul_serie_m3(float answ[][3],
{
float temp[3][3];
- if(m1==0 || m2==0) return;
+ if(m1==NULL || m2==NULL) return;
mul_m3_m3m3(answ, m2, m1);
if(m3) {
@@ -261,7 +275,7 @@ void mul_serie_m4(float answ[][4], float m1[][4],
{
float temp[4][4];
- if(m1==0 || m2==0) return;
+ if(m1==NULL || m2==NULL) return;
mul_m4_m4m4(answ, m2, m1);
if(m3) {
@@ -609,7 +623,11 @@ void orthogonalize_m3(float mat[][3], int axis)
normalize_v3(mat[1]);
cross_v3_v3v3(mat[2], mat[0], mat[1]);
} else {
- float vec[3] = {mat[0][1], mat[0][2], mat[0][0]};
+ float vec[3];
+
+ vec[0]= mat[0][1];
+ vec[1]= mat[0][2];
+ vec[2]= mat[0][0];
cross_v3_v3v3(mat[2], mat[0], vec);
normalize_v3(mat[2]);
@@ -625,7 +643,11 @@ void orthogonalize_m3(float mat[][3], int axis)
normalize_v3(mat[0]);
cross_v3_v3v3(mat[2], mat[0], mat[1]);
} else {
- float vec[3] = {mat[1][1], mat[1][2], mat[1][0]};
+ float vec[3];
+
+ vec[0]= mat[1][1];
+ vec[1]= mat[1][2];
+ vec[2]= mat[1][0];
cross_v3_v3v3(mat[0], mat[1], vec);
normalize_v3(mat[0]);
@@ -641,7 +663,11 @@ void orthogonalize_m3(float mat[][3], int axis)
normalize_v3(mat[0]);
cross_v3_v3v3(mat[1], mat[2], mat[0]);
} else {
- float vec[3] = {mat[2][1], mat[2][2], mat[2][0]};
+ float vec[3];
+
+ vec[0]= mat[2][1];
+ vec[1]= mat[2][2];
+ vec[2]= mat[2][0];
cross_v3_v3v3(mat[0], vec, mat[2]);
normalize_v3(mat[0]);
@@ -670,7 +696,11 @@ void orthogonalize_m4(float mat[][4], int axis)
normalize_v3(mat[1]);
cross_v3_v3v3(mat[2], mat[0], mat[1]);
} else {
- float vec[3] = {mat[0][1], mat[0][2], mat[0][0]};
+ float vec[3];
+
+ vec[0]= mat[0][1];
+ vec[1]= mat[0][2];
+ vec[2]= mat[0][0];
cross_v3_v3v3(mat[2], mat[0], vec);
normalize_v3(mat[2]);
@@ -687,7 +717,11 @@ void orthogonalize_m4(float mat[][4], int axis)
normalize_v3(mat[0]);
cross_v3_v3v3(mat[2], mat[0], mat[1]);
} else {
- float vec[3] = {mat[1][1], mat[1][2], mat[1][0]};
+ float vec[3];
+
+ vec[0]= mat[1][1];
+ vec[1]= mat[1][2];
+ vec[2]= mat[1][0];
cross_v3_v3v3(mat[0], mat[1], vec);
normalize_v3(mat[0]);
@@ -703,7 +737,11 @@ void orthogonalize_m4(float mat[][4], int axis)
normalize_v3(mat[0]);
cross_v3_v3v3(mat[1], mat[2], mat[0]);
} else {
- float vec[3] = {mat[2][1], mat[2][2], mat[2][0]};
+ float vec[3];
+
+ vec[0]= mat[2][1];
+ vec[1]= mat[2][2];
+ vec[2]= mat[2][0];
cross_v3_v3v3(mat[0], vec, mat[2]);
normalize_v3(mat[0]);
@@ -750,6 +788,14 @@ void normalize_m3(float mat[][3])
normalize_v3(mat[2]);
}
+void normalize_m3_m3(float rmat[][3], float mat[][3])
+{
+ normalize_v3_v3(rmat[0], mat[0]);
+ normalize_v3_v3(rmat[1], mat[1]);
+ normalize_v3_v3(rmat[2], mat[2]);
+}
+
+
void normalize_m4(float mat[][4])
{
float len;
@@ -762,6 +808,18 @@ void normalize_m4(float mat[][4])
if(len!=0.0) mat[2][3]/= len;
}
+void normalize_m4_m4(float rmat[][4], float mat[][4])
+{
+ float len;
+
+ len= normalize_v3_v3(rmat[0], mat[0]);
+ if(len!=0.0) rmat[0][3]= mat[0][3] / len;
+ len= normalize_v3_v3(rmat[1], mat[1]);
+ if(len!=0.0) rmat[1][3]= mat[1][3] / len;
+ len= normalize_v3_v3(rmat[2], mat[2]);
+ if(len!=0.0) rmat[2][3]= mat[2][3] / len;;
+}
+
void adjoint_m3_m3(float m1[][3], float m[][3])
{
m1[0][0]=m[1][1]*m[2][2]-m[1][2]*m[2][1];
@@ -878,7 +936,7 @@ float determinant_m4(float m[][4])
/****************************** Transformations ******************************/
-void size_to_mat3(float mat[][3], float *size)
+void size_to_mat3(float mat[][3], const float size[3])
{
mat[0][0]= size[0];
mat[0][1]= 0.0f;
@@ -891,7 +949,7 @@ void size_to_mat3(float mat[][3], float *size)
mat[2][0]= 0.0f;
}
-void size_to_mat4(float mat[][4], float *size)
+void size_to_mat4(float mat[][4], const float size[3])
{
float tmat[3][3];
@@ -932,6 +990,49 @@ float mat4_to_scale(float mat[][4])
return mat3_to_scale(tmat);
}
+
+void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3])
+{
+ float mat3_n[3][3]; /* mat3 -> normalized, 3x3 */
+ float imat3_n[3][3]; /* mat3 -> normalized & inverted, 3x3 */
+
+ /* rotation & scale are linked, we need to create the mat's
+ * for these together since they are related. */
+
+ /* so scale doesnt interfear with rotation [#24291] */
+ /* note: this is a workaround for negative matrix not working for rotation conversion, FIXME */
+ normalize_m3_m3(mat3_n, mat3);
+ if(is_negative_m3(mat3)) {
+ negate_v3(mat3_n[0]);
+ negate_v3(mat3_n[1]);
+ negate_v3(mat3_n[2]);
+ }
+
+ /* rotation */
+ /* keep rot as a 3x3 matrix, the caller can convert into a quat or euler */
+ copy_m3_m3(rot, mat3_n);
+
+ /* scale */
+ /* note: mat4_to_size(ob->size, mat) fails for negative scale */
+ invert_m3_m3(imat3_n, mat3_n);
+ mul_m3_m3m3(mat3, imat3_n, mat3);
+
+ size[0]= mat3[0][0];
+ size[1]= mat3[1][1];
+ size[2]= mat3[2][2];
+}
+
+void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[][4])
+{
+ float mat3[3][3]; /* wmat -> 3x3 */
+
+ copy_m3_m4(mat3, wmat);
+ mat3_to_rot_size(rot, size, mat3);
+
+ /* location */
+ copy_v3_v3(loc, wmat[3]);
+}
+
void scale_m3_fl(float m[][3], float scale)
{
m[0][0]= m[1][1]= m[2][2]= scale;
@@ -963,6 +1064,8 @@ void rotate_m4(float mat[][4], const char axis, const float angle)
float temp[4]= {0.0f, 0.0f, 0.0f, 0.0f};
float cosine, sine;
+ assert(axis >= 'X' && axis <= 'Z');
+
cosine = (float)cos(angle);
sine = (float)sin(angle);
switch(axis){
@@ -995,18 +1098,19 @@ void rotate_m4(float mat[][4], const char axis, const float angle)
}
}
-void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], float srcweight)
+void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], const float srcweight)
{
+ float srot[3][3], drot[3][3];
float squat[4], dquat[4], fquat[4];
- float ssize[3], dsize[3], fsize[4];
+ float ssize[3], dsize[3], fsize[3];
float rmat[3][3], smat[3][3];
- mat3_to_quat(dquat,dst);
- mat3_to_size(dsize,dst);
+ mat3_to_rot_size(drot, dsize, dst);
+ mat3_to_rot_size(srot, ssize, src);
+
+ mat3_to_quat(dquat, drot);
+ mat3_to_quat(squat, srot);
- mat3_to_quat(squat,src);
- mat3_to_size(ssize,src);
-
/* do blending */
interp_qt_qtqt(fquat, dquat, squat, srcweight);
interp_v3_v3v3(fsize, dsize, ssize, srcweight);
@@ -1017,20 +1121,19 @@ void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], float srcweig
mul_m3_m3m3(out, rmat, smat);
}
-void blend_m4_m4m4(float out[][4], float dst[][4], float src[][4], float srcweight)
+void blend_m4_m4m4(float out[][4], float dst[][4], float src[][4], const float srcweight)
{
- float squat[4], dquat[4], fquat[4];
- float ssize[3], dsize[3], fsize[4];
float sloc[3], dloc[3], floc[3];
-
- mat4_to_quat(dquat,dst);
- mat4_to_size(dsize,dst);
- copy_v3_v3(dloc, dst[3]);
+ float srot[3][3], drot[3][3];
+ float squat[4], dquat[4], fquat[4];
+ float ssize[3], dsize[3], fsize[3];
+
+ mat4_to_loc_rot_size(dloc, drot, dsize, dst);
+ mat4_to_loc_rot_size(sloc, srot, ssize, src);
+
+ mat3_to_quat(dquat, drot);
+ mat3_to_quat(squat, srot);
- mat4_to_quat(squat,src);
- mat4_to_size(ssize,src);
- copy_v3_v3(sloc, src[3]);
-
/* do blending */
interp_v3_v3v3(floc, dloc, sloc, srcweight);
interp_qt_qtqt(fquat, dquat, squat, srcweight);
@@ -1058,7 +1161,7 @@ int is_negative_m4(float mat[][4])
/* make a 4x4 matrix out of 3 transform components */
/* matrices are made in the order: scale * rot * loc */
// TODO: need to have a version that allows for rotation order...
-void loc_eul_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float size[3])
+void loc_eul_size_to_mat4(float mat[4][4], const float loc[3], const float eul[3], const float size[3])
{
float rmat[3][3], smat[3][3], tmat[3][3];
@@ -1081,7 +1184,7 @@ void loc_eul_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float siz
/* make a 4x4 matrix out of 3 transform components */
/* matrices are made in the order: scale * rot * loc */
-void loc_eulO_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float size[3], short rotOrder)
+void loc_eulO_size_to_mat4(float mat[4][4], const float loc[3], const float eul[3], const float size[3], const short rotOrder)
{
float rmat[3][3], smat[3][3], tmat[3][3];
@@ -1105,7 +1208,7 @@ void loc_eulO_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float si
/* make a 4x4 matrix out of 3 transform components */
/* matrices are made in the order: scale * rot * loc */
-void loc_quat_size_to_mat4(float mat[4][4], float loc[3], float quat[4], float size[3])
+void loc_quat_size_to_mat4(float mat[4][4], const float loc[3], const float quat[4], const float size[3])
{
float rmat[3][3], smat[3][3], tmat[3][3];
@@ -1126,9 +1229,16 @@ void loc_quat_size_to_mat4(float mat[4][4], float loc[3], float quat[4], float s
mat[3][2] = loc[2];
}
+void loc_axisangle_size_to_mat4(float mat[4][4], const float loc[3], const float axis[3], const float angle, const float size[3])
+{
+ float q[4];
+ axis_angle_to_quat(q, axis, angle);
+ loc_quat_size_to_mat4(mat, loc, q, size);
+}
+
/*********************************** Other ***********************************/
-void print_m3(char *str, float m[][3])
+void print_m3(const char *str, float m[][3])
{
printf("%s\n", str);
printf("%f %f %f\n",m[0][0],m[1][0],m[2][0]);
@@ -1137,7 +1247,7 @@ void print_m3(char *str, float m[][3])
printf("\n");
}
-void print_m4(char *str, float m[][4])
+void print_m4(const char *str, float m[][4])
{
printf("%s\n", str);
printf("%f %f %f %f\n",m[0][0],m[1][0],m[2][0],m[3][0]);
@@ -1361,7 +1471,6 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4])
eps = powf(2.0f,-52.0f);
while (p > 0) {
int kase=0;
- k=0;
// Test for maximum iterations to avoid infinite loop
if(maxiter == 0)
@@ -1599,5 +1708,5 @@ void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon)
transpose_m4(V);
- mul_serie_m4(Ainv, U, Wm, V, 0, 0, 0, 0, 0);
+ mul_serie_m4(Ainv, U, Wm, V, NULL, NULL, NULL, NULL, NULL);
}
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index f72269f6d7b..1160ec9fc3a 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -26,11 +26,25 @@
* */
+#include <assert.h>
#include "BLI_math.h"
/******************************** Quaternions ********************************/
-void unit_qt(float *q)
+/* used to test is a quat is not normalized */
+#define QUAT_EPSILON 0.0001
+
+/* convenience, avoids setting Y axis everywhere */
+void unit_axis_angle(float axis[3], float *angle)
+{
+ axis[0]= 0.0f;
+ axis[1]= 1.0f;
+ axis[2]= 0.0f;
+ *angle= 0.0f;
+}
+
+
+void unit_qt(float q[4])
{
q[0]= 1.0f;
q[1]= q[2]= q[3]= 0.0f;
@@ -88,7 +102,7 @@ void conjugate_qt(float *q)
q[3] = -q[3];
}
-float dot_qtqt(float *q1, float *q2)
+float dot_qtqt(const float q1[4], const float q2[4])
{
return q1[0]*q2[0] + q1[1]*q2[1] + q1[2]*q2[2] + q1[3]*q2[3];
}
@@ -119,11 +133,16 @@ void mul_qt_fl(float *q, const float f)
q[3] *= f;
}
-void sub_qt_qtqt(float *q, float *q1, float *q2)
+void sub_qt_qtqt(float q[4], const float q1[4], const float q2[4])
{
- q2[0]= -q2[0];
- mul_qt_qtqt(q, q1, q2);
- q2[0]= -q2[0];
+ float nq2[4];
+
+ nq2[0]= -q2[0];
+ nq2[1]= q2[1];
+ nq2[2]= q2[2];
+ nq2[3]= q2[3];
+
+ mul_qt_qtqt(q, q1, nq2);
}
/* angular mult factor */
@@ -138,7 +157,8 @@ void mul_fac_qt_fl(float *q, const float fac)
mul_v3_fl(q+1, si);
}
-void quat_to_mat3(float m[][3], float *q)
+/* skip error check, currently only needed by mat3_to_quat_is_ok */
+static void quat_to_mat3_no_error(float m[][3], const float q[4])
{
double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc;
@@ -170,10 +190,29 @@ void quat_to_mat3(float m[][3], float *q)
m[2][2]= (float)(1.0-qaa-qbb);
}
-void quat_to_mat4(float m[][4], float *q)
+
+void quat_to_mat3(float m[][3], const float q[4])
+{
+#ifdef DEBUG
+ float f;
+ if(!((f=dot_qtqt(q, q))==0.0 || (fabs(f-1.0) < QUAT_EPSILON))) {
+ fprintf(stderr, "Warning! quat_to_mat3() called with non-normalized: size %.8f *** report a bug ***\n", f);
+ }
+#endif
+
+ quat_to_mat3_no_error(m, q);
+}
+
+void quat_to_mat4(float m[][4], const float q[4])
{
double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc;
+#ifdef DEBUG
+ if(!((q0=dot_qtqt(q, q))==0.0 || (fabs(q0-1.0) < QUAT_EPSILON))) {
+ fprintf(stderr, "Warning! quat_to_mat4() called with non-normalized: size %.8f *** report a bug ***\n", (float)q0);
+ }
+#endif
+
q0= M_SQRT2 * q[0];
q1= M_SQRT2 * q[1];
q2= M_SQRT2 * q[2];
@@ -294,7 +333,7 @@ void mat3_to_quat_is_ok(float q[4], float wmat[3][3])
q1[3]= -nor[2]*si;
/* rotate back x-axis from mat, using inverse q1 */
- quat_to_mat3( matr,q1);
+ quat_to_mat3_no_error( matr,q1);
invert_m3_m3(matn, matr);
mul_m3_v3(matn, mat[0]);
@@ -312,7 +351,7 @@ void mat3_to_quat_is_ok(float q[4], float wmat[3][3])
}
-void normalize_qt(float *q)
+float normalize_qt(float *q)
{
float len;
@@ -324,6 +363,14 @@ void normalize_qt(float *q)
q[1]= 1.0f;
q[0]= q[2]= q[3]= 0.0f;
}
+
+ return len;
+}
+
+float normalize_qt_qt(float r[4], const float q[4])
+{
+ copy_qt_qt(r, q);
+ return normalize_qt(r);
}
/* note: expects vectors to be normalized */
@@ -356,10 +403,13 @@ void rotation_between_quats_to_quat(float *q, const float q1[4], const float q2[
}
-void vec_to_quat(float *q,float *vec, short axis, short upflag)
+void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
{
float q2[4], nor[3], *fp, mat[3][3], angle, si, co, x2, y2, z2, len1;
+ assert(axis >= 0 && axis <= 5);
+ assert(upflag >= 0 && upflag <= 2);
+
/* first rotate to axis */
if(axis>2) {
x2= vec[0] ; y2= vec[1] ; z2= vec[2];
@@ -491,7 +541,7 @@ void QuatInterpolW(float *result, float *quat1, float *quat2, float t)
}
#endif
-void interp_qt_qtqt(float *result, float *quat1, float *quat2, float t)
+void interp_qt_qtqt(float result[4], const float quat1[4], const float quat2[4], const float t)
{
float quat[4], omega, cosom, sinom, sc1, sc2;
@@ -528,7 +578,7 @@ void interp_qt_qtqt(float *result, float *quat1, float *quat2, float t)
result[3] = sc1 * quat[3] + sc2 * quat2[3];
}
-void add_qt_qtqt(float *result, float *quat1, float *quat2, float t)
+void add_qt_qtqt(float result[4], const float quat1[4], const float quat2[4], const float t)
{
result[0]= quat1[0] + t*quat2[0];
result[1]= quat1[1] + t*quat2[1];
@@ -536,7 +586,7 @@ void add_qt_qtqt(float *result, float *quat1, float *quat2, float t)
result[3]= quat1[3] + t*quat2[3];
}
-void tri_to_quat(float *quat, float *v1, float *v2, float *v3)
+void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const float v3[3])
{
/* imaginary x-axis, y-axis triangle is being rotated */
float vec[3], q1[4], q2[4], n[3], si, co, angle, mat[3][3], imat[3][3];
@@ -588,13 +638,16 @@ void print_qt(char *str, float q[4])
/******************************** Axis Angle *********************************/
/* Axis angle to Quaternions */
-void axis_angle_to_quat(float q[4], float axis[3], float angle)
+void axis_angle_to_quat(float q[4], const float axis[3], float angle)
{
float nor[3];
float si;
- normalize_v3_v3(nor, axis);
-
+ if(normalize_v3_v3(nor, axis) == 0.0f) {
+ unit_qt(q);
+ return;
+ }
+
angle /= 2;
si = (float)sin(angle);
q[0] = (float)cos(angle);
@@ -604,10 +657,16 @@ void axis_angle_to_quat(float q[4], float axis[3], float angle)
}
/* Quaternions to Axis Angle */
-void quat_to_axis_angle(float axis[3], float *angle,float q[4])
+void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
{
float ha, si;
-
+
+#ifdef DEBUG
+ if(!((ha=dot_qtqt(q, q))==0.0 || (fabs(ha-1.0) < QUAT_EPSILON))) {
+ fprintf(stderr, "Warning! quat_to_axis_angle() called with non-normalized: size %.8f *** report a bug ***\n", ha);
+ }
+#endif
+
/* calculate angle/2, and sin(angle/2) */
ha= (float)acos(q[0]);
si= (float)sin(ha);
@@ -625,7 +684,7 @@ void quat_to_axis_angle(float axis[3], float *angle,float q[4])
}
/* Axis Angle to Euler Rotation */
-void axis_angle_to_eulO(float eul[3], short order,float axis[3], float angle)
+void axis_angle_to_eulO(float eul[3], const short order, const float axis[3], const float angle)
{
float q[4];
@@ -635,7 +694,7 @@ void axis_angle_to_eulO(float eul[3], short order,float axis[3], float angle)
}
/* Euler Rotation to Axis Angle */
-void eulO_to_axis_angle(float axis[3], float *angle,float eul[3], short order)
+void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], const short order)
{
float q[4];
@@ -645,12 +704,15 @@ void eulO_to_axis_angle(float axis[3], float *angle,float eul[3], short order)
}
/* axis angle to 3x3 matrix - safer version (normalisation of axis performed) */
-void axis_angle_to_mat3(float mat[3][3],float axis[3], float angle)
+void axis_angle_to_mat3(float mat[3][3], const float axis[3], const float angle)
{
float nor[3], nsi[3], co, si, ico;
/* normalise the axis first (to remove unwanted scaling) */
- normalize_v3_v3(nor, axis);
+ if(normalize_v3_v3(nor, axis) == 0.0f) {
+ unit_m3(mat);
+ return;
+ }
/* now convert this to a 3x3 matrix */
co= (float)cos(angle);
@@ -673,7 +735,7 @@ void axis_angle_to_mat3(float mat[3][3],float axis[3], float angle)
}
/* axis angle to 4x4 matrix - safer version (normalisation of axis performed) */
-void axis_angle_to_mat4(float mat[4][4],float axis[3], float angle)
+void axis_angle_to_mat4(float mat[4][4], const float axis[3], const float angle)
{
float tmat[3][3];
@@ -730,7 +792,7 @@ void mat4_to_vec_rot(float axis[3], float *angle,float mat[4][4])
}
/* axis angle to 3x3 matrix */
-void vec_rot_to_mat3(float mat[][3],float *vec, float phi)
+void vec_rot_to_mat3(float mat[][3], const float vec[3], const float phi)
{
/* rotation of phi radials around vec */
float vx, vx2, vy, vy2, vz, vz2, co, si;
@@ -756,7 +818,7 @@ void vec_rot_to_mat3(float mat[][3],float *vec, float phi)
}
/* axis angle to 4x4 matrix */
-void vec_rot_to_mat4(float mat[][4],float *vec, float phi)
+void vec_rot_to_mat4(float mat[][4], const float vec[3], const float phi)
{
float tmat[3][3];
@@ -766,7 +828,7 @@ void vec_rot_to_mat4(float mat[][4],float *vec, float phi)
}
/* axis angle to quaternion */
-void vec_rot_to_quat(float *quat,float *vec, float phi)
+void vec_rot_to_quat(float *quat, const float vec[3], const float phi)
{
/* rotation of phi radials around vec */
float si;
@@ -790,7 +852,7 @@ void vec_rot_to_quat(float *quat,float *vec, float phi)
/******************************** XYZ Eulers *********************************/
/* XYZ order */
-void eul_to_mat3(float mat[][3], float *eul)
+void eul_to_mat3(float mat[][3], const float eul[3])
{
double ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
@@ -818,7 +880,7 @@ void eul_to_mat3(float mat[][3], float *eul)
}
/* XYZ order */
-void eul_to_mat4(float mat[][4], float *eul)
+void eul_to_mat4(float mat[][4], const float eul[3])
{
double ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
@@ -850,7 +912,7 @@ void eul_to_mat4(float mat[][4], float *eul)
/* returns two euler calculation methods, so we can pick the best */
/* XYZ order */
-static void mat3_to_eul2(float tmat[][3], float *eul1, float *eul2)
+static void mat3_to_eul2(float tmat[][3], float eul1[3], float eul2[3])
{
float cy, quat[4], mat[3][3];
@@ -907,16 +969,16 @@ void mat4_to_eul(float *eul,float tmat[][4])
}
/* XYZ order */
-void quat_to_eul(float *eul,float *quat)
+void quat_to_eul(float *eul, const float quat[4])
{
float mat[3][3];
-
+
quat_to_mat3(mat,quat);
mat3_to_eul(eul,mat);
}
/* XYZ order */
-void eul_to_quat(float *quat,float *eul)
+void eul_to_quat(float *quat, const float eul[3])
{
float ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
@@ -932,10 +994,12 @@ void eul_to_quat(float *quat,float *eul)
}
/* XYZ order */
-void rotate_eul(float *beul, char axis, float ang)
+void rotate_eul(float *beul, const char axis, const float ang)
{
float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];
-
+
+ assert(axis >= 'X' && axis <= 'Z');
+
eul[0]= eul[1]= eul[2]= 0.0f;
if(axis=='X') eul[0]= ang;
else if(axis=='Y') eul[1]= ang;
@@ -952,7 +1016,7 @@ void rotate_eul(float *beul, char axis, float ang)
/* exported to transform.c */
/* order independent! */
-void compatible_eul(float *eul, float *oldrot)
+void compatible_eul(float eul[3], const float oldrot[3])
{
float dx, dy, dz;
@@ -1016,7 +1080,7 @@ void compatible_eul(float *eul, float *oldrot)
/* uses 2 methods to retrieve eulers, and picks the closest */
/* XYZ order */
-void mat3_to_compatible_eul(float *eul, float *oldrot,float mat[][3])
+void mat3_to_compatible_eul(float eul[3], const float oldrot[3], float mat[][3])
{
float eul1[3], eul2[3];
float d1, d2;
@@ -1073,20 +1137,20 @@ static RotOrderInfo rotOrders[]= {
* NOTE: since we start at 1 for the values, but arrays index from 0,
* there is -1 factor involved in this process...
*/
-#define GET_ROTATIONORDER_INFO(order) (((order)>=1) ? &rotOrders[(order)-1] : &rotOrders[0])
+#define GET_ROTATIONORDER_INFO(order) (assert(order>=0 && order<=6), (order < 1) ? &rotOrders[0] : &rotOrders[(order)-1])
/* Construct quaternion from Euler angles (in radians). */
-void eulO_to_quat(float q[4],float e[3], short order)
+void eulO_to_quat(float q[4], const float e[3], const short order)
{
RotOrderInfo *R= GET_ROTATIONORDER_INFO(order);
short i=R->axis[0], j=R->axis[1], k=R->axis[2];
double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
double a[3];
- ti = e[i]/2; tj = e[j]/2; th = e[k]/2;
-
- if (R->parity) e[j] = -e[j];
-
+ ti = e[i] * 0.5f;
+ tj = e[j] * (R->parity ? -0.5f : 0.5f);
+ th = e[k] * 0.5f;
+
ci = cos(ti); cj = cos(tj); ch = cos(th);
si = sin(ti); sj = sin(tj); sh = sin(th);
@@ -1102,11 +1166,11 @@ void eulO_to_quat(float q[4],float e[3], short order)
q[2] = a[1];
q[3] = a[2];
- if (R->parity) q[j] = -q[j];
+ if (R->parity) q[j+1] = -q[j+1];
}
/* Convert quaternion to Euler angles (in radians). */
-void quat_to_eulO(float e[3], short order,float q[4])
+void quat_to_eulO(float e[3], short const order, const float q[4])
{
float M[3][3];
@@ -1115,7 +1179,7 @@ void quat_to_eulO(float e[3], short order,float q[4])
}
/* Construct 3x3 matrix from Euler angles (in radians). */
-void eulO_to_mat3(float M[3][3],float e[3], short order)
+void eulO_to_mat3(float M[3][3], const float e[3], const short order)
{
RotOrderInfo *R= GET_ROTATIONORDER_INFO(order);
short i=R->axis[0], j=R->axis[1], k=R->axis[2];
@@ -1139,53 +1203,6 @@ void eulO_to_mat3(float M[3][3],float e[3], short order)
M[i][k] = -sj; M[j][k] = cj*si; M[k][k] = cj*ci;
}
-/* Construct 4x4 matrix from Euler angles (in radians). */
-void eulO_to_mat4(float M[4][4],float e[3], short order)
-{
- float m[3][3];
-
- /* for now, we'll just do this the slow way (i.e. copying matrices) */
- normalize_m3(m);
- eulO_to_mat3(m,e, order);
- copy_m4_m3(M, m);
-}
-
-/* Convert 3x3 matrix to Euler angles (in radians). */
-void mat3_to_eulO(float e[3], short order,float M[3][3])
-{
- RotOrderInfo *R= GET_ROTATIONORDER_INFO(order);
- short i=R->axis[0], j=R->axis[1], k=R->axis[2];
- double cy = sqrt(M[i][i]*M[i][i] + M[i][j]*M[i][j]);
-
- if (cy > 16*FLT_EPSILON) {
- e[i] = atan2(M[j][k], M[k][k]);
- e[j] = atan2(-M[i][k], cy);
- e[k] = atan2(M[i][j], M[i][i]);
- }
- else {
- e[i] = atan2(-M[k][j], M[j][j]);
- e[j] = atan2(-M[i][k], cy);
- e[k] = 0;
- }
-
- if (R->parity) {
- e[0] = -e[0];
- e[1] = -e[1];
- e[2] = -e[2];
- }
-}
-
-/* Convert 4x4 matrix to Euler angles (in radians). */
-void mat4_to_eulO(float e[3], short order,float M[4][4])
-{
- float m[3][3];
-
- /* for now, we'll just do this the slow way (i.e. copying matrices) */
- copy_m3_m4(m, M);
- normalize_m3(m);
- mat3_to_eulO(e, order,m);
-}
-
/* returns two euler calculation methods, so we can pick the best */
static void mat3_to_eulo2(float M[3][3], float *e1, float *e2, short order)
{
@@ -1228,6 +1245,45 @@ static void mat3_to_eulo2(float M[3][3], float *e1, float *e2, short order)
}
}
+/* Construct 4x4 matrix from Euler angles (in radians). */
+void eulO_to_mat4(float M[4][4], const float e[3], const short order)
+{
+ float m[3][3];
+
+ /* for now, we'll just do this the slow way (i.e. copying matrices) */
+ normalize_m3(m);
+ eulO_to_mat3(m,e, order);
+ copy_m4_m3(M, m);
+}
+
+
+/* Convert 3x3 matrix to Euler angles (in radians). */
+void mat3_to_eulO(float eul[3], const short order,float M[3][3])
+{
+ float eul1[3], eul2[3];
+
+ mat3_to_eulo2(M, eul1, eul2, order);
+
+ /* return best, which is just the one with lowest values it in */
+ if(fabs(eul1[0])+fabs(eul1[1])+fabs(eul1[2]) > fabs(eul2[0])+fabs(eul2[1])+fabs(eul2[2])) {
+ copy_v3_v3(eul, eul2);
+ }
+ else {
+ copy_v3_v3(eul, eul1);
+ }
+}
+
+/* Convert 4x4 matrix to Euler angles (in radians). */
+void mat4_to_eulO(float e[3], const short order,float M[4][4])
+{
+ float m[3][3];
+
+ /* for now, we'll just do this the slow way (i.e. copying matrices) */
+ copy_m3_m4(m, M);
+ normalize_m3(m);
+ mat3_to_eulO(e, order,m);
+}
+
/* uses 2 methods to retrieve eulers, and picks the closest */
void mat3_to_compatible_eulO(float eul[3], float oldrot[3], short order,float mat[3][3])
{
@@ -1249,12 +1305,23 @@ void mat3_to_compatible_eulO(float eul[3], float oldrot[3], short order,float ma
copy_v3_v3(eul, eul1);
}
+void mat4_to_compatible_eulO(float eul[3], float oldrot[3], short order,float M[4][4])
+{
+ float m[3][3];
+
+ /* for now, we'll just do this the slow way (i.e. copying matrices) */
+ copy_m3_m4(m, M);
+ normalize_m3(m);
+ mat3_to_compatible_eulO(eul, oldrot, order, m);
+}
/* rotate the given euler by the given angle on the specified axis */
// NOTE: is this safe to do with different axis orders?
void rotate_eulO(float beul[3], short order, char axis, float ang)
{
float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];
-
+
+ assert(axis >= 'X' && axis <= 'Z');
+
eul[0]= eul[1]= eul[2]= 0.0f;
if (axis=='X')
eul[0]= ang;
@@ -1272,7 +1339,7 @@ void rotate_eulO(float beul[3], short order, char axis, float ang)
}
/* the matrix is written to as 3 axis vectors */
-void eulO_to_gimbal_axis(float gmat[][3], float *eul, short order)
+void eulO_to_gimbal_axis(float gmat[][3], const float eul[3], const short order)
{
RotOrderInfo *R= GET_ROTATIONORDER_INFO(order);
@@ -1364,7 +1431,7 @@ void mat4_to_dquat(DualQuat *dq,float basemat[][4], float mat[][4])
mul_m4_m4m4(S, baseRS, baseRinv);
/* set scaling part */
- mul_serie_m4(dq->scale, basemat, S, baseinv, 0, 0, 0, 0, 0);
+ mul_serie_m4(dq->scale, basemat, S, baseinv, NULL, NULL, NULL, NULL, NULL);
dq->scale_weight= 1.0f;
}
else {
@@ -1385,7 +1452,7 @@ void mat4_to_dquat(DualQuat *dq,float basemat[][4], float mat[][4])
dq->trans[3]= 0.5f*(t[0]*q[2] - t[1]*q[1] + t[2]*q[0]);
}
-void dquat_to_mat4(float mat[][4],DualQuat *dq)
+void dquat_to_mat4(float mat[][4], DualQuat *dq)
{
float len, *t, q0[4];
@@ -1521,7 +1588,79 @@ void copy_dq_dq(DualQuat *dq1, DualQuat *dq2)
memcpy(dq1, dq2, sizeof(DualQuat));
}
-/* lense/angle conversion (radians) */
+/* axis matches eTrackToAxis_Modes */
+void quat_apply_track(float quat[4], short axis, short upflag)
+{
+ /* rotations are hard coded to match vec_to_quat */
+ const float quat_track[][4]= {{0.70710676908493, 0.0, -0.70710676908493, 0.0}, /* pos-y90 */
+ {0.5, 0.5, 0.5, 0.5}, /* Quaternion((1,0,0), radians(90)) * Quaternion((0,1,0), radians(90)) */
+ {0.70710676908493, 0.0, 0.0, 0.70710676908493}, /* pos-z90 */
+ {0.70710676908493, 0.0, 0.70710676908493, 0.0}, /* neg-y90 */
+ {0.5, -0.5, -0.5, 0.5}, /* Quaternion((1,0,0), radians(-90)) * Quaternion((0,1,0), radians(-90)) */
+ {-3.0908619663705394e-08, 0.70710676908493, 0.70710676908493, 3.0908619663705394e-08}}; /* no rotation */
+
+ assert(axis >= 0 && axis <= 5);
+ assert(upflag >= 0 && upflag <= 2);
+
+ mul_qt_qtqt(quat, quat, quat_track[axis]);
+
+ if(axis>2)
+ axis= axis-3;
+
+ /* there are 2 possible up-axis for each axis used, the 'quat_track' applies so the first
+ * up axis is used X->Y, Y->X, Z->X, if this first up axis isn used then rotate 90d
+ * the strange bit shift below just find the low axis {X:Y, Y:X, Z:X} */
+ if(upflag != (2-axis)>>1) {
+ float q[4]= {0.70710676908493, 0.0, 0.0, 0.0}; /* assign 90d rotation axis */
+ q[axis+1] = ((axis==1)) ? 0.70710676908493 : -0.70710676908493; /* flip non Y axis */
+ mul_qt_qtqt(quat, quat, q);
+ }
+}
+
+
+void vec_apply_track(float vec[3], short axis)
+{
+ float tvec[3];
+
+ assert(axis >= 0 && axis <= 5);
+
+ copy_v3_v3(tvec, vec);
+
+ switch(axis) {
+ case 0: /* pos-x */
+ /* vec[0]= 0.0; */
+ vec[1]= tvec[2];
+ vec[2]= -tvec[1];
+ break;
+ case 1: /* pos-y */
+ /* vec[0]= tvec[0]; */
+ /* vec[1]= 0.0; */
+ /* vec[2]= tvec[2]; */
+ break;
+ case 2: /* pos-z */
+ /* vec[0]= tvec[0]; */
+ /* vec[1]= tvec[1]; */
+ // vec[2]= 0.0; */
+ break;
+ case 3: /* neg-x */
+ /* vec[0]= 0.0; */
+ vec[1]= tvec[2];
+ vec[2]= -tvec[1];
+ break;
+ case 4: /* neg-y */
+ vec[0]= -tvec[2];
+ /* vec[1]= 0.0; */
+ vec[2]= tvec[0];
+ break;
+ case 5: /* neg-z */
+ vec[0]= -tvec[0];
+ vec[1]= -tvec[1];
+ /* vec[2]= 0.0; */
+ break;
+ }
+}
+
+/* lens/angle conversion (radians) */
float lens_to_angle(float lens)
{
return 2.0f * atan(16.0f/lens);
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 6d908ddb1cd..6c4000c6142 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -30,7 +30,7 @@
//******************************* Interpolation *******************************/
-void interp_v2_v2v2(float *target, const float *a, const float *b, const float t)
+void interp_v2_v2v2(float target[2], const float a[2], const float b[2], const float t)
{
float s = 1.0f-t;
@@ -91,7 +91,7 @@ void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const fl
p[3] = v1[3]*w[0] + v2[3]*w[1] + v3[3]*w[2];
}
-void mid_v3_v3v3(float *v, float *v1, float *v2)
+void mid_v3_v3v3(float v[3], const float v1[3], const float v2[3])
{
v[0]= 0.5f*(v1[0] + v2[0]);
v[1]= 0.5f*(v1[1] + v2[1]);
@@ -103,7 +103,7 @@ void mid_v3_v3v3(float *v, float *v1, float *v2)
/* Return the angle in radians between vecs 1-2 and 2-3 in radians
If v1 is a shoulder, v2 is the elbow and v3 is the hand,
this would return the angle at the elbow */
-float angle_v3v3v3(float *v1, float *v2, float *v3)
+float angle_v3v3v3(const float v1[3], const float v2[3], const float v3[3])
{
float vec1[3], vec2[3];
@@ -116,7 +116,7 @@ float angle_v3v3v3(float *v1, float *v2, float *v3)
}
/* Return the shortest angle in radians between the 2 vectors */
-float angle_v3v3(float *v1, float *v2)
+float angle_v3v3(const float v1[3], const float v2[3])
{
float vec1[3], vec2[3];
@@ -126,7 +126,7 @@ float angle_v3v3(float *v1, float *v2)
return angle_normalized_v3v3(vec1, vec2);
}
-float angle_v2v2v2(float *v1, float *v2, float *v3)
+float angle_v2v2v2(const float v1[2], const float v2[2], const float v3[2])
{
float vec1[2], vec2[2];
@@ -143,7 +143,7 @@ float angle_v2v2v2(float *v1, float *v2, float *v3)
}
/* Return the shortest angle in radians between the 2 vectors */
-float angle_v2v2(float *v1, float *v2)
+float angle_v2v2(const float v1[2], const float v2[2])
{
float vec1[2], vec2[2];
@@ -175,7 +175,7 @@ float angle_normalized_v3v3(const float v1[3], const float v2[3])
return 2.0f*(float)saasin(len_v3v3(v2, v1)/2.0f);
}
-float angle_normalized_v2v2(float *v1, float *v2)
+float angle_normalized_v2v2(const float v1[2], const float v2[2])
{
/* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
if (dot_v2v2(v1, v2) < 0.0f) {
@@ -231,7 +231,17 @@ void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const
/********************************* Geometry **********************************/
/* Project v1 on v2 */
-void project_v3_v3v3(float *c, float *v1, float *v2)
+void project_v2_v2v2(float c[2], const float v1[2], const float v2[2])
+{
+ float mul;
+ mul = dot_v2v2(v1, v2) / dot_v2v2(v2, v2);
+
+ c[0] = mul * v2[0];
+ c[1] = mul * v2[1];
+}
+
+/* Project v1 on v2 */
+void project_v3_v3v3(float c[3], const float v1[3], const float v2[3])
{
float mul;
mul = dot_v3v3(v1, v2) / dot_v3v3(v2, v2);
@@ -242,7 +252,7 @@ void project_v3_v3v3(float *c, float *v1, float *v2)
}
/* Returns a vector bisecting the angle at v2 formed by v1, v2 and v3 */
-void bisect_v3_v3v3v3(float *out, float *v1, float *v2, float *v3)
+void bisect_v3_v3v3v3(float out[3], const float v1[3], const float v2[3], const float v3[3])
{
float d_12[3], d_23[3];
sub_v3_v3v3(d_12, v2, v1);
@@ -256,7 +266,7 @@ void bisect_v3_v3v3v3(float *out, float *v1, float *v2, float *v3)
/* Returns a reflection vector from a vector and a normal vector
reflect = vec - ((2 * DotVecs(vec, mirror)) * mirror)
*/
-void reflect_v3_v3v3(float *out, float *v1, float *v2)
+void reflect_v3_v3v3(float out[3], const float v1[3], const float v2[3])
{
float vec[3], normal[3];
float reflect[3] = {0.0f, 0.0f, 0.0f};
@@ -274,7 +284,7 @@ void reflect_v3_v3v3(float *out, float *v1, float *v2)
copy_v3_v3(out, reflect);
}
-void ortho_basis_v3v3_v3(float *v1, float *v2, float *v)
+void ortho_basis_v3v3_v3(float v1[3], float v2[3], const float v[3])
{
const float f = (float)sqrt(v[0]*v[0] + v[1]*v[1]);
@@ -296,6 +306,36 @@ void ortho_basis_v3v3_v3(float *v1, float *v2, float *v)
}
}
+/* Rotate a point p by angle theta around an arbitrary axis r
+ http://local.wasp.uwa.edu.au/~pbourke/geometry/
+*/
+void rotate_normalized_v3_v3v3fl(float r[3], const float p[3], const float axis[3], const float angle)
+{
+ const float costheta= cos(angle);
+ const float sintheta= sin(angle);
+
+ r[0]= ((costheta + (1 - costheta) * axis[0] * axis[0]) * p[0]) +
+ (((1 - costheta) * axis[0] * axis[1] - axis[2] * sintheta) * p[1]) +
+ (((1 - costheta) * axis[0] * axis[2] + axis[1] * sintheta) * p[2]);
+
+ r[1]= (((1 - costheta) * axis[0] * axis[1] + axis[2] * sintheta) * p[0]) +
+ ((costheta + (1 - costheta) * axis[1] * axis[1]) * p[1]) +
+ (((1 - costheta) * axis[1] * axis[2] - axis[0] * sintheta) * p[2]);
+
+ r[2]= (((1 - costheta) * axis[0] * axis[2] - axis[1] * sintheta) * p[0]) +
+ (((1 - costheta) * axis[1] * axis[2] + axis[0] * sintheta) * p[1]) +
+ ((costheta + (1 - costheta) * axis[2] * axis[2]) * p[2]);
+}
+
+void rotate_v3_v3v3fl(float r[3], const float p[3], const float axis[3], const float angle)
+{
+ float axis_n[3];
+
+ normalize_v3_v3(axis_n, axis);
+
+ rotate_normalized_v3_v3v3fl(r, p, axis_n, angle);
+}
+
/*********************************** Other ***********************************/
void print_v2(const char *str, const float v[2])
@@ -313,7 +353,7 @@ void print_v4(const char *str, const float v[4])
printf("%s: %.3f %.3f %.3f %.3f\n", str, v[0], v[1], v[2], v[3]);
}
-void minmax_v3_v3v3(float *min, float *max, float *vec)
+void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
{
if(min[0]>vec[0]) min[0]= vec[0];
if(min[1]>vec[1]) min[1]= vec[1];
@@ -324,3 +364,91 @@ void minmax_v3_v3v3(float *min, float *max, float *vec)
if(max[2]<vec[2]) max[2]= vec[2];
}
+
+/***************************** Array Functions *******************************/
+
+void range_vni(int *array_tar, const int size, const int start)
+{
+ int *array_pt= array_tar + (size-1);
+ int j= start + (size-1);
+ int i= size;
+ while(i--) { *(array_pt--) = j--; }
+}
+
+void negate_vn(float *array_tar, const int size)
+{
+ float *array_pt= array_tar + (size-1);
+ int i= size;
+ while(i--) { *(array_pt--) *= -1.0f; }
+}
+
+void negate_vn_vn(float *array_tar, const float *array_src, const int size)
+{
+ float *tar= array_tar + (size-1);
+ const float *src= array_src + (size-1);
+ int i= size;
+ while(i--) { *(tar--) = - *(src--); }
+}
+
+void mul_vn_fl(float *array_tar, const int size, const float f)
+{
+ float *array_pt= array_tar + (size-1);
+ int i= size;
+ while(i--) { *(array_pt--) *= f; }
+}
+
+void mul_vn_vn_fl(float *array_tar, const float *array_src, const int size, const float f)
+{
+ float *tar= array_tar + (size-1);
+ const float *src= array_src + (size-1);
+ int i= size;
+ while(i--) { *(tar--) = *(src--) * f; }
+}
+
+void add_vn_vn(float *array_tar, const float *array_src, const int size)
+{
+ float *tar= array_tar + (size-1);
+ const float *src= array_src + (size-1);
+ int i= size;
+ while(i--) { *(tar--) += *(src--); }
+}
+
+void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size)
+{
+ float *tar= array_tar + (size-1);
+ const float *src_a= array_src_a + (size-1);
+ const float *src_b= array_src_b + (size-1);
+ int i= size;
+ while(i--) { *(tar--) = *(src_a--) + *(src_b--); }
+}
+
+void sub_vn_vn(float *array_tar, const float *array_src, const int size)
+{
+ float *tar= array_tar + (size-1);
+ const float *src= array_src + (size-1);
+ int i= size;
+ while(i--) { *(tar--) -= *(src--); }
+}
+
+void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size)
+{
+ float *tar= array_tar + (size-1);
+ const float *src_a= array_src_a + (size-1);
+ const float *src_b= array_src_b + (size-1);
+ int i= size;
+ while(i--) { *(tar--) = *(src_a--) - *(src_b--); }
+}
+
+void fill_vni(int *array_tar, const int size, const int val)
+{
+ int *tar= array_tar + (size-1);
+ int i= size;
+ while(i--) { *(tar--) = val; }
+}
+
+void fill_vn(float *array_tar, const int size, const float val)
+{
+ float *tar= array_tar + (size-1);
+ int i= size;
+ while(i--) { *(tar--) = val; }
+}
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 76173312b67..52d55ab948b 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -27,8 +27,8 @@
#include "BLI_math.h"
-#ifndef BLI_MATH_VECTOR_INLINE
-#define BLI_MATH_VECTOR_INLINE
+#ifndef BLI_MATH_VECTOR_INLINE_H
+#define BLI_MATH_VECTOR_INLINE_H
/********************************** Init *************************************/
@@ -149,6 +149,23 @@ MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
r[2]= a[2] - b[2];
}
+MINLINE void sub_v4_v4(float r[4], const float a[4])
+{
+ r[0] -= a[0];
+ r[1] -= a[1];
+ r[2] -= a[2];
+ r[3] -= a[3];
+}
+
+MINLINE void sub_v4_v4v4(float r[3], const float a[3], const float b[3])
+{
+ r[0]= a[0] - b[0];
+ r[1]= a[1] - b[1];
+ r[2]= a[2] - b[2];
+ r[3]= a[3] - b[3];
+}
+
+
MINLINE void mul_v2_fl(float *v1, float f)
{
v1[0]*= f;
@@ -265,6 +282,22 @@ MINLINE void negate_v3_v3(float r[3], const float a[3])
r[2]= -a[2];
}
+MINLINE void negate_v4(float r[4])
+{
+ r[0]= -r[0];
+ r[1]= -r[1];
+ r[2]= -r[2];
+ r[3]= -r[3];
+}
+
+MINLINE void negate_v4_v4(float r[4], const float a[4])
+{
+ r[0]= -a[0];
+ r[1]= -a[1];
+ r[2]= -a[2];
+ r[3]= -a[3];
+}
+
MINLINE float dot_v2v2(const float a[2], const float b[2])
{
return a[0]*b[0] + a[1]*b[1];
@@ -302,7 +335,7 @@ MINLINE void star_m3_v3(float mat[][3], float *vec)
MINLINE float len_v2(const float v[2])
{
- return (float)sqrt(v[0]*v[0] + v[1]*v[1]);
+ return (float)sqrtf(v[0]*v[0] + v[1]*v[1]);
}
MINLINE float len_v2v2(const float v1[2], const float v2[2])
@@ -311,7 +344,7 @@ MINLINE float len_v2v2(const float v1[2], const float v2[2])
x = v1[0]-v2[0];
y = v1[1]-v2[1];
- return (float)sqrt(x*x+y*y);
+ return (float)sqrtf(x*x+y*y);
}
MINLINE float len_v3(const float a[3])
@@ -319,6 +352,14 @@ MINLINE float len_v3(const float a[3])
return sqrtf(dot_v3v3(a, a));
}
+MINLINE float len_squared_v2v2(const float a[3], const float b[3])
+{
+ float d[2];
+
+ sub_v2_v2v2(d, b, a);
+ return dot_v2v2(d, d);
+}
+
MINLINE float len_v3v3(const float a[3], const float b[3])
{
float d[3];
@@ -417,27 +458,37 @@ MINLINE void normal_float_to_short_v3(short *out, const float *in)
/********************************* Comparison ********************************/
-MINLINE int is_zero_v3(float *v)
+MINLINE int is_zero_v3(const float v[3])
{
return (v[0] == 0 && v[1] == 0 && v[2] == 0);
}
-MINLINE int is_one_v3(float *v)
+MINLINE int is_zero_v4(const float v[4])
+{
+ return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0);
+}
+
+MINLINE int is_one_v3(const float *v)
{
return (v[0] == 1 && v[1] == 1 && v[2] == 1);
}
-MINLINE int equals_v3v3(float *v1, float *v2)
+MINLINE int equals_v2v2(const float *v1, const float *v2)
+{
+ return ((v1[0]==v2[0]) && (v1[1]==v2[1]));
+}
+
+MINLINE int equals_v3v3(const float *v1, const float *v2)
{
return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]));
}
-MINLINE int equals_v4v4(float *v1, float *v2)
+MINLINE int equals_v4v4(const float *v1, const float *v2)
{
return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]) && (v1[3]==v2[3]));
}
-MINLINE int compare_v3v3(float *v1, float *v2, float limit)
+MINLINE int compare_v3v3(const float *v1, const float *v2, const float limit)
{
if(fabs(v1[0]-v2[0])<limit)
if(fabs(v1[1]-v2[1])<limit)
@@ -447,7 +498,7 @@ MINLINE int compare_v3v3(float *v1, float *v2, float limit)
return 0;
}
-MINLINE int compare_len_v3v3(float *v1, float *v2, float limit)
+MINLINE int compare_len_v3v3(const float *v1, const float *v2, const float limit)
{
float x,y,z;
@@ -458,7 +509,7 @@ MINLINE int compare_len_v3v3(float *v1, float *v2, float limit)
return ((x*x + y*y + z*z) < (limit*limit));
}
-MINLINE int compare_v4v4(float *v1, float *v2, float limit)
+MINLINE int compare_v4v4(const float *v1, const float *v2, const float limit)
{
if(fabs(v1[0]-v2[0])<limit)
if(fabs(v1[1]-v2[1])<limit)
@@ -469,5 +520,11 @@ MINLINE int compare_v4v4(float *v1, float *v2, float limit)
return 0;
}
-#endif /* BLI_MATH_VECTOR_INLINE */
+MINLINE float line_point_side_v2(const float *l1, const float *l2, const float *pt)
+{
+ return ((l1[0]-pt[0]) * (l2[1]-pt[1])) -
+ ((l2[0]-pt[0]) * (l1[1]-pt[1]));
+}
+
+#endif /* BLI_MATH_VECTOR_INLINE_H */
diff --git a/source/blender/blenlib/intern/noise.c b/source/blender/blenlib/intern/noise.c
index 141e5438bc9..9af1532ce4b 100644
--- a/source/blender/blenlib/intern/noise.c
+++ b/source/blender/blenlib/intern/noise.c
@@ -36,6 +36,8 @@
#include <math.h>
+#include "BLI_noise.h"
+
/* local */
static float noise3_perlin(float vec[3]);
//static float turbulence_perlin(float *point, float lofreq, float hifreq);
@@ -388,7 +390,7 @@ static char p[512+2]= {
0xA2,0xA0};
-float g[512+2][3]= {
+static float g[512+2][3]= {
{0.33783, 0.715698, -0.611206},
{-0.944031, -0.326599, -0.045624},
{-0.101074, -0.416443, -0.903503},
@@ -1052,15 +1054,17 @@ float BLI_hnoisep(float noisesize, float x, float y, float z)
/* Camberra omitted, didn't seem useful */
/* distance squared */
-static float dist_Squared(float x, float y, float z, float e) { return (x*x + y*y + z*z); }
+static float dist_Squared(float x, float y, float z, float e) { (void)e; return (x*x + y*y + z*z); }
/* real distance */
-static float dist_Real(float x, float y, float z, float e) { return sqrt(x*x + y*y + z*z); }
+static float dist_Real(float x, float y, float z, float e) { (void)e; return sqrt(x*x + y*y + z*z); }
/* manhattan/taxicab/cityblock distance */
-static float dist_Manhattan(float x, float y, float z, float e) { return (fabs(x) + fabs(y) + fabs(z)); }
+static float dist_Manhattan(float x, float y, float z, float e) { (void)e; return (fabs(x) + fabs(y) + fabs(z)); }
/* Chebychev */
static float dist_Chebychev(float x, float y, float z, float e)
{
float t;
+ (void)e;
+
x = fabs(x);
y = fabs(y);
z = fabs(z);
@@ -1072,12 +1076,14 @@ static float dist_Chebychev(float x, float y, float z, float e)
static float dist_MinkovskyH(float x, float y, float z, float e)
{
float d = sqrt(fabs(x)) + sqrt(fabs(y)) + sqrt(fabs(z));
+ (void)e;
return (d*d);
}
/* minkovsky preset exponent 4 */
static float dist_Minkovsky4(float x, float y, float z, float e)
{
+ (void)e;
x *= x;
y *= y;
z *= z;
@@ -1752,7 +1758,7 @@ float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity
signal = offset - fabs(noisefunc(x, y, z));
signal *= signal;
result = signal;
- weight = 1.f;
+
for( i=1; i<(int)octaves; i++ ) {
x *= lacunarity;
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index cf773d575e5..2359a858d51 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -32,6 +32,7 @@
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
+#include <assert.h>
#include "MEM_guardedalloc.h"
@@ -42,12 +43,19 @@
#include "BLI_string.h"
#include "BLI_storage.h"
#include "BLI_storage_types.h"
+#include "BLI_utildefines.h"
#include "BKE_utildefines.h"
#include "BKE_blender.h" // BLENDER_VERSION
#include "GHOST_Path-api.h"
+#if defined WIN32 && !defined _LIBC
+# include "BLI_fnmatch.h" /* use fnmatch included in blenlib */
+#else
+# define _GNU_SOURCE
+# include <fnmatch.h>
+#endif
#ifdef WIN32
#include <io.h>
@@ -63,13 +71,16 @@
#else /* non windows */
-#ifdef __linux__
+#ifdef WITH_BINRELOC
#include "binreloc.h"
#endif
#endif /* WIN32 */
/* local */
+#define UNIQUE_NAME_MAX 128
+
+extern char bprogname[];
static int add_win32_extension(char *name);
static char *blender_version_decimal(void);
@@ -130,10 +141,41 @@ void BLI_stringenc(char *string, const char *head, const char *tail, unsigned sh
sprintf(string, fmtstr, head, pic, tail);
}
+/* Foo.001 -> "Foo", 1
+ * Returns the length of "Foo" */
+int BLI_split_name_num(char *left, int *nr, const char *name, const char delim)
+{
+ int a;
+
+ *nr= 0;
+ a= strlen(name);
+ memcpy(left, name, (a + 1) * sizeof(char));
+
+ if(a>1 && name[a-1]==delim) return a;
+
+ while(a--) {
+ if( name[a]==delim ) {
+ left[a]= 0;
+ *nr= atol(name+a+1);
+ /* casting down to an int, can overflow for large numbers */
+ if(*nr < 0)
+ *nr= 0;
+ return a;
+ }
+ if( isdigit(name[a])==0 ) break;
+
+ left[a]= 0;
+ }
+
+ for(a= 0; name[a]; a++)
+ left[a]= name[a];
+
+ return a;
+}
void BLI_newname(char *name, int add)
{
- char head[128], tail[128];
+ char head[UNIQUE_NAME_MAX], tail[UNIQUE_NAME_MAX];
int pic;
unsigned short digits;
@@ -153,13 +195,43 @@ void BLI_newname(char *name, int add)
BLI_stringenc(name, head, tail, digits, pic);
}
+
+
+int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len)
+{
+ if(name == '\0') {
+ BLI_strncpy(name, defname, name_len);
+ }
+
+ if(unique_check(arg, name)) {
+ char tempname[UNIQUE_NAME_MAX];
+ char left[UNIQUE_NAME_MAX];
+ int number;
+ int len= BLI_split_name_num(left, &number, name, delim);
+ do {
+ int newlen= BLI_snprintf(tempname, name_len, "%s%c%03d", left, delim, number);
+ if(newlen >= name_len) {
+ len -= ((newlen + 1) - name_len);
+ if(len < 0) len= number= 0;
+ left[len]= '\0';
+ }
+ } while(number++, unique_check(arg, tempname));
+
+ BLI_strncpy(name, tempname, name_len);
+
+ return 1;
+ }
+
+ return 0;
+}
+
/* little helper macro for BLI_uniquename */
#ifndef GIVE_STRADDR
#define GIVE_STRADDR(data, offset) ( ((char *)data) + offset )
#endif
/* Generic function to set a unique name. It is only designed to be used in situations
- * where the name is part of the struct, and also that the name is at most 128 chars long.
+ * where the name is part of the struct, and also that the name is at most UNIQUE_NAME_MAX chars long.
*
* For places where this is used, see constraint.c for example...
*
@@ -168,65 +240,45 @@ void BLI_newname(char *name, int add)
* defname: the name that should be used by default if none is specified already
* delim: the character which acts as a delimeter between parts of the name
*/
-void BLI_uniquename(ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len)
+static int uniquename_find_dupe(ListBase *list, void *vlink, const char *name, short name_offs)
{
Link *link;
- char tempname[128];
- int number = 1, exists = 0;
- char *dot;
-
- /* Make sure length can be handled */
- if ((len < 0) || (len > 128))
- return;
-
- /* See if we are given an empty string */
- if (ELEM(NULL, vlink, defname))
- return;
-
- if (GIVE_STRADDR(vlink, name_offs) == '\0') {
- /* give it default name first */
- BLI_strncpy(GIVE_STRADDR(vlink, name_offs), defname, len);
- }
-
- /* See if we even need to do this */
- if (list == NULL)
- return;
-
+
for (link = list->first; link; link= link->next) {
if (link != vlink) {
- if (!strcmp(GIVE_STRADDR(link, name_offs), GIVE_STRADDR(vlink, name_offs))) {
- exists = 1;
- break;
+ if (!strcmp(GIVE_STRADDR(link, name_offs), name)) {
+ return 1;
}
}
}
- if (exists == 0)
+
+ return 0;
+}
+
+static int uniquename_unique_check(void *arg, const char *name)
+{
+ struct {ListBase *lb; void *vlink; short name_offs;} *data= arg;
+ return uniquename_find_dupe(data->lb, data->vlink, name, data->name_offs);
+}
+
+void BLI_uniquename(ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short name_len)
+{
+ struct {ListBase *lb; void *vlink; short name_offs;} data;
+ data.lb= list;
+ data.vlink= vlink;
+ data.name_offs= name_offs;
+
+ assert((name_len > 1) && (name_len <= UNIQUE_NAME_MAX));
+
+ /* See if we are given an empty string */
+ if (ELEM(NULL, vlink, defname))
return;
- /* Strip off the suffix */
- dot = strrchr(GIVE_STRADDR(vlink, name_offs), delim);
- if (dot)
- *dot=0;
-
- for (number = 1; number <= 999; number++) {
- BLI_snprintf(tempname, sizeof(tempname), "%s%c%03d", GIVE_STRADDR(vlink, name_offs), delim, number);
-
- exists = 0;
- for (link= list->first; link; link= link->next) {
- if (vlink != link) {
- if (!strcmp(GIVE_STRADDR(link, name_offs), tempname)) {
- exists = 1;
- break;
- }
- }
- }
- if (exists == 0) {
- BLI_strncpy(GIVE_STRADDR(vlink, name_offs), tempname, len);
- return;
- }
- }
+ BLI_uniquename_cb(uniquename_unique_check, &data, defname, delim, GIVE_STRADDR(vlink, name_offs), name_len);
}
+
+
/* ******************** string encoding ***************** */
/* This is quite an ugly function... its purpose is to
@@ -311,10 +363,17 @@ void BLI_cleanup_file(const char *relabase, char *dir)
dir[0]= '/';
dir[1]= 0;
return;
- }
+ }
+
+ /* support for odd paths: eg /../home/me --> /home/me
+ * this is a valid path in blender but we cant handle this the useual way below
+ * simply strip this prefix then evaluate the path as useual. pythons os.path.normpath() does this */
+ while((strncmp(dir, "/../", 4)==0)) {
+ memmove( dir, dir + 4, strlen(dir + 4) + 1 );
+ }
while ( (start = strstr(dir, "/../")) ) {
- eind = start + strlen("/../") - 1;
+ eind = start + (4 - 1) /* strlen("/../") - 1 */;
a = start-dir-1;
while (a>0) {
if (dir[a] == '/') break;
@@ -328,12 +387,12 @@ void BLI_cleanup_file(const char *relabase, char *dir)
}
while ( (start = strstr(dir,"/./")) ){
- eind = start + strlen("/./") - 1;
+ eind = start + (3 - 1) /* strlen("/./") - 1 */;
memmove( start, eind, strlen(eind)+1 );
}
while ( (start = strstr(dir,"//" )) ){
- eind = start + strlen("//") - 1;
+ eind = start + (2 - 1) /* strlen("//") - 1 */;
memmove( start, eind, strlen(eind)+1 );
}
@@ -360,8 +419,8 @@ void BLI_path_rel(char *file, const char *relfile)
/* also bail out if relative path is not set */
if (relfile[0] == 0) return;
-#ifdef WIN32
- if (strlen(relfile) > 2 && relfile[1] != ':') {
+#ifdef WIN32
+ if (BLI_strnlen(relfile, 3) > 2 && relfile[1] != ':') {
char* ptemp;
/* fix missing volume name in relative base,
can happen with old recent-files.txt files */
@@ -375,7 +434,7 @@ void BLI_path_rel(char *file, const char *relfile)
BLI_strncpy(temp, relfile, FILE_MAXDIR + FILE_MAXFILE);
}
- if (strlen(file) > 2) {
+ if (BLI_strnlen(file, 3) > 2) {
if ( temp[1] == ':' && file[1] == ':' && temp[0] != file[0] )
return;
}
@@ -400,7 +459,7 @@ void BLI_path_rel(char *file, const char *relfile)
char *p= temp;
char *q= file;
- while ((*p == *q)) {
+ while (*p == *q) {
++p; ++q;
/* dont search beyond the end of the string
* in the rare case they match */
@@ -458,13 +517,9 @@ int BLI_has_parent(char *path)
int BLI_parent_dir(char *path)
{
-#ifdef WIN32
- static char *parent_dir="..\\";
-#else
- static char *parent_dir="../";
-#endif
+ static char parent_dir[]= {'.', '.', SEP, '\0'}; /* "../" or "..\\" */
char tmp[FILE_MAXDIR+FILE_MAXFILE+4];
- BLI_strncpy(tmp, path, sizeof(tmp));
+ BLI_strncpy(tmp, path, sizeof(tmp)-4);
BLI_add_slash(tmp);
strcat(tmp, parent_dir);
BLI_cleanup_dir(NULL, tmp);
@@ -534,9 +589,20 @@ int BLI_path_frame(char *path, int frame, int digits)
ensure_digits(path, digits);
if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */
- char tmp[FILE_MAX], format[64];
+ char tmp[FILE_MAX];
+#if 0 // neat but breaks on non ascii strings.
+ char format[64];
sprintf(format, "%%.%ds%%.%dd%%s", ch_sta, ch_end-ch_sta); /* example result: "%.12s%.5d%s" */
sprintf(tmp, format, path, frame, path+ch_end);
+#else
+ char format[8];
+ char *p;
+ sprintf(format, "%%.%dd", ch_end-ch_sta); /* example result: "%.5d" */
+ memcpy(tmp, path, sizeof(char) * ch_sta);
+ p= tmp + ch_sta;
+ p += sprintf(p, format, frame);
+ memcpy(p, path + ch_end, strlen(path + ch_end));
+#endif
strcpy(path, tmp);
return 1;
}
@@ -552,9 +618,18 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits)
if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */
char tmp[FILE_MAX], format[64];
+#if 0 // neat but breaks on non ascii strings.
sprintf(format, "%%.%ds%%.%dd_%%.%dd%%s", ch_sta, ch_end-ch_sta, ch_end-ch_sta); /* example result: "%.12s%.5d-%.5d%s" */
sprintf(tmp, format, path, sta, end, path+ch_end);
strcpy(path, tmp);
+#else
+ char *tmp_pt;
+ BLI_snprintf(format, sizeof(format), "%%.%dd-%%.%dd%%s", digits, digits);
+ memcpy(tmp, path, ch_sta * sizeof(char));
+ tmp_pt = &tmp[ch_sta];
+ tmp_pt += BLI_snprintf(tmp_pt, sizeof(tmp)-ch_sta, format, sta, end, &path[ch_end]);
+ memcpy(path, tmp, (int)(tmp_pt - tmp) + 1);
+#endif
return 1;
}
return 0;
@@ -677,8 +752,8 @@ int BLI_path_cwd(char *path)
#endif
if (wasrelative==1) {
- char cwd[FILE_MAXDIR + FILE_MAXFILE];
- BLI_getwdN(cwd); /* incase the full path to the blend isnt used */
+ char cwd[FILE_MAXDIR + FILE_MAXFILE]= "";
+ BLI_getwdN(cwd, sizeof(cwd)); /* incase the full path to the blend isnt used */
if (cwd[0] == '\0') {
printf( "Could not get the current working directory - $PWD for an unknown reason.");
@@ -782,11 +857,11 @@ static char *blender_version_decimal(void)
return version_str;
}
-static int test_path(char *targetpath, char *path_base, char *path_sep, char *folder_name)
+static int test_path(char *targetpath, const char *path_base, const char *path_sep, const char *folder_name)
{
char tmppath[FILE_MAX];
- if(path_sep) BLI_join_dirfile(tmppath, path_base, path_sep);
+ if(path_sep) BLI_join_dirfile(tmppath, sizeof(tmppath), path_base, path_sep);
else BLI_strncpy(tmppath, path_base, sizeof(tmppath));
BLI_make_file_string("/", targetpath, tmppath, folder_name);
@@ -806,7 +881,7 @@ static int test_path(char *targetpath, char *path_base, char *path_sep, char *fo
}
}
-static int test_env_path(char *path, char *envvar)
+static int test_env_path(char *path, const char *envvar)
{
char *env = envvar?getenv(envvar):NULL;
if (!env) return 0;
@@ -820,54 +895,32 @@ static int test_env_path(char *path, char *envvar)
}
}
-static int get_path_local(char *targetpath, char *folder_name, char *subfolder_name)
+static int get_path_local(char *targetpath, const char *folder_name, const char *subfolder_name)
{
- extern char bprogname[]; /* argv[0] from creator.c */
char bprogdir[FILE_MAX];
char relfolder[FILE_MAX];
- char cwd[FILE_MAX];
- char *s;
- int i;
#ifdef PATH_DEBUG2
printf("get_path_local...\n");
#endif
if (subfolder_name) {
- BLI_join_dirfile(relfolder, folder_name, subfolder_name);
+ BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
} else {
- BLI_strncpy(relfolder, folder_name, FILE_MAX);
+ BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
}
/* use argv[0] (bprogname) to get the path to the executable */
- s = BLI_last_slash(bprogname);
- i = s - bprogname + 1;
- BLI_strncpy(bprogdir, bprogname, i);
-
- /* try EXECUTABLE_DIR/folder_name */
- if(test_path(targetpath, bprogdir, "", relfolder))
- return 1;
-
- /* try CWD/release/folder_name */
- if(test_path(targetpath, BLI_getwdN(cwd), "release", relfolder))
- return 1;
+ BLI_split_dirfile(bprogname, bprogdir, NULL);
- /* try EXECUTABLE_DIR/release/folder_name */
- if(test_path(targetpath, bprogdir, "release", relfolder))
- return 1;
-
- /* try EXECUTABLE_DIR/2.5/folder_name - new default directory for local blender installed files */
+ /* try EXECUTABLE_DIR/2.5x/folder_name - new default directory for local blender installed files */
if(test_path(targetpath, bprogdir, blender_version_decimal(), relfolder))
return 1;
- /* try ./.blender/folder_name -- DEPRECATED, need to update build systems */
- if(test_path(targetpath, bprogdir, ".blender", relfolder))
- return 1;
-
return 0;
}
-static int get_path_user(char *targetpath, char *folder_name, char *subfolder_name, char *envvar)
+static int get_path_user(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar)
{
char user_path[FILE_MAX];
const char *user_base_path;
@@ -904,11 +957,41 @@ static int get_path_user(char *targetpath, char *folder_name, char *subfolder_na
}
}
-static int get_path_system(char *targetpath, char *folder_name, char *subfolder_name, char *envvar)
+static int get_path_system(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar)
{
char system_path[FILE_MAX];
const char *system_base_path;
+
+ /* first allow developer only overrides to the system path
+ * these are only used when running blender from source */
+ char cwd[FILE_MAX];
+ char relfolder[FILE_MAX];
+ char bprogdir[FILE_MAX];
+
+ /* use argv[0] (bprogname) to get the path to the executable */
+ BLI_split_dirfile(bprogname, bprogdir, NULL);
+
+ if (subfolder_name) {
+ BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
+ } else {
+ BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
+ }
+
+ /* try CWD/release/folder_name */
+ if(BLI_getwdN(cwd, sizeof(cwd))) {
+ if(test_path(targetpath, cwd, "release", relfolder)) {
+ return 1;
+ }
+ }
+
+ /* try EXECUTABLE_DIR/release/folder_name */
+ if(test_path(targetpath, bprogdir, "release", relfolder))
+ return 1;
+ /* end developer overrides */
+
+
+
system_path[0] = '\0';
if (test_env_path(system_path, envvar)) {
@@ -943,7 +1026,7 @@ static int get_path_system(char *targetpath, char *folder_name, char *subfolder_
/* get a folder out of the 'folder_id' presets for paths */
/* returns the path if found, NULL string if not */
-char *BLI_get_folder(int folder_id, char *subfolder)
+char *BLI_get_folder(int folder_id, const char *subfolder)
{
static char path[FILE_MAX] = "";
@@ -1015,7 +1098,7 @@ char *BLI_get_folder(int folder_id, char *subfolder)
return path;
}
-static char *BLI_get_user_folder_notest(int folder_id, char *subfolder)
+char *BLI_get_user_folder_notest(int folder_id, const char *subfolder)
{
static char path[FILE_MAX] = "";
@@ -1029,6 +1112,9 @@ static char *BLI_get_user_folder_notest(int folder_id, char *subfolder)
case BLENDER_USER_AUTOSAVE:
get_path_user(path, "autosave", subfolder, "BLENDER_USER_AUTOSAVE");
break;
+ case BLENDER_USER_SCRIPTS:
+ get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS");
+ break;
}
if ('\0' == path[0]) {
return NULL;
@@ -1036,12 +1122,12 @@ static char *BLI_get_user_folder_notest(int folder_id, char *subfolder)
return path;
}
-char *BLI_get_folder_create(int folder_id, char *subfolder)
+char *BLI_get_folder_create(int folder_id, const char *subfolder)
{
char *path;
/* only for user folders */
- if (!ELEM3(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG, BLENDER_USER_AUTOSAVE))
+ if (!ELEM4(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG, BLENDER_USER_SCRIPTS, BLENDER_USER_AUTOSAVE))
return NULL;
path = BLI_get_folder(folder_id, subfolder);
@@ -1099,8 +1185,9 @@ void BLI_setenv_if_new(const char *env, const char* val)
void BLI_clean(char *path)
{
if(path==0) return;
+
#ifdef WIN32
- if(path && strlen(path)>2) {
+ if(path && BLI_strnlen(path, 3) > 2) {
BLI_char_switch(path+2, '/', '\\');
}
#else
@@ -1120,45 +1207,31 @@ void BLI_char_switch(char *string, char from, char to)
void BLI_make_exist(char *dir) {
int a;
- #ifdef WIN32
- BLI_char_switch(dir, '/', '\\');
- #else
- BLI_char_switch(dir, '\\', '/');
- #endif
-
+ BLI_char_switch(dir, ALTSEP, SEP);
+
a = strlen(dir);
-
-#ifdef WIN32
+
while(BLI_is_dir(dir) == 0){
a --;
- while(dir[a] != '\\'){
+ while(dir[a] != SEP){
a--;
if (a <= 0) break;
}
- if (a >= 0) dir[a+1] = 0;
+ if (a >= 0) {
+ dir[a+1] = '\0';
+ }
else {
- /* defaulting to drive (usually 'C:') of Windows installation */
+#ifdef WIN32
get_default_root(dir);
- break;
- }
- }
#else
- while(BLI_is_dir(dir) == 0){
- a --;
- while(dir[a] != '/'){
- a--;
- if (a <= 0) break;
- }
- if (a >= 0) dir[a+1] = 0;
- else {
strcpy(dir,"/");
+#endif
break;
}
}
-#endif
}
-void BLI_make_existing_file(char *name)
+void BLI_make_existing_file(const char *name)
{
char di[FILE_MAXDIR+FILE_MAXFILE], fi[FILE_MAXFILE];
@@ -1196,15 +1269,14 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir,
/* Get the file name, chop everything past the last slash (ie. the filename) */
strcpy(string, relabase);
- lslash= (strrchr(string, '/')>strrchr(string, '\\'))?strrchr(string, '/'):strrchr(string, '\\');
-
+ lslash= BLI_last_slash(string);
if(lslash) *(lslash+1)= 0;
dir+=2; /* Skip over the relative reference */
}
#ifdef WIN32
else {
- if (strlen(dir) >= 2 && dir[1] == ':' ) {
+ if (BLI_strnlen(dir, 3) >= 2 && dir[1] == ':' ) {
BLI_strncpy(string, dir, 3);
dir += 2;
}
@@ -1250,10 +1322,10 @@ int BLI_testextensie(const char *str, const char *ext)
{
short a, b;
int retval;
-
+
a= strlen(str);
b= strlen(ext);
-
+
if(a==0 || b==0 || b>=a) {
retval = 0;
} else if (BLI_strcasecmp(ext, str + a - b)) {
@@ -1261,7 +1333,7 @@ int BLI_testextensie(const char *str, const char *ext)
} else {
retval = 1;
}
-
+
return (retval);
}
@@ -1278,9 +1350,39 @@ int BLI_testextensie_array(const char *str, const char **ext_array)
return 0;
}
+/* semicolon separated wildcards, eg:
+ * '*.zip;*.py;*.exe' */
+int BLI_testextensie_glob(const char *str, const char *ext_fnmatch)
+{
+ const char *ext_step= ext_fnmatch;
+ char pattern[16];
+
+ while(ext_step[0]) {
+ char *ext_next;
+ int len_ext;
+
+ if((ext_next=strchr(ext_step, ';'))) {
+ len_ext= (int)(ext_next - ext_step) + 1;
+ }
+ else {
+ len_ext= sizeof(pattern);
+ }
+
+ BLI_strncpy(pattern, ext_step, len_ext);
+
+ if(fnmatch(pattern, str, FNM_CASEFOLD)==0) {
+ return 1;
+ }
+ ext_step += len_ext;
+ }
+
+ return 0;
+}
+
+
int BLI_replace_extension(char *path, int maxlen, const char *ext)
{
- int a;
+ unsigned int a;
for(a=strlen(path)-1; a>=0; a--)
if(path[a] == '.' || path[a] == '/' || path[a] == '\\')
@@ -1321,12 +1423,12 @@ void BLI_split_dirfile(const char *string, char *dir, char *file)
}
/* simple appending of filename to dir, does not check for valid path! */
-void BLI_join_dirfile(char *string, const char *dir, const char *file)
+void BLI_join_dirfile(char *string, const int maxlen, const char *dir, const char *file)
{
int sl_dir;
if(string != dir) /* compare pointers */
- BLI_strncpy(string, dir, FILE_MAX);
+ BLI_strncpy(string, dir, maxlen);
if (!file)
return;
@@ -1334,7 +1436,7 @@ void BLI_join_dirfile(char *string, const char *dir, const char *file)
sl_dir= BLI_add_slash(string);
if (sl_dir <FILE_MAX) {
- BLI_strncpy(string + sl_dir, file, FILE_MAX-sl_dir);
+ BLI_strncpy(string + sl_dir, file, maxlen - sl_dir);
}
}
@@ -1409,21 +1511,21 @@ int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char
/* if image is _in_ current .blend file directory */
if (!strcmp(dir, blend_dir)) {
- BLI_join_dirfile(dest_path, dest_dir, base);
+ BLI_join_dirfile(dest_path, sizeof(dest_path), dest_dir, base);
}
/* "below" */
else {
/* rel = image_path_dir - blend_dir */
BLI_strncpy(rel_dir, dir + len, sizeof(rel_dir));
- BLI_join_dirfile(dest_path, dest_dir, rel_dir);
- BLI_join_dirfile(dest_path, dest_path, base);
+ BLI_join_dirfile(dest_path, sizeof(dest_path), dest_dir, rel_dir);
+ BLI_join_dirfile(dest_path, sizeof(dest_path), dest_path, base);
}
}
/* image is out of current directory */
else {
- BLI_join_dirfile(dest_path, dest_dir, base);
+ BLI_join_dirfile(dest_path, sizeof(dest_path), dest_dir, base);
}
if (abs)
@@ -1443,6 +1545,67 @@ int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char
return 1;
}
+char *BLI_first_slash(char *string) {
+ char *ffslash, *fbslash;
+
+ ffslash= strchr(string, '/');
+ fbslash= strchr(string, '\\');
+
+ if (!ffslash) return fbslash;
+ else if (!fbslash) return ffslash;
+
+ if ((intptr_t)ffslash < (intptr_t)fbslash) return ffslash;
+ else return fbslash;
+}
+
+char *BLI_last_slash(const char *string) {
+ char *lfslash, *lbslash;
+
+ lfslash= strrchr(string, '/');
+ lbslash= strrchr(string, '\\');
+
+ if (!lfslash) return lbslash;
+ else if (!lbslash) return lfslash;
+
+ if ((intptr_t)lfslash < (intptr_t)lbslash) return lbslash;
+ else return lfslash;
+}
+
+/* adds a slash if there isnt one there already */
+int BLI_add_slash(char *string) {
+ int len = strlen(string);
+#ifdef WIN32
+ if (len==0 || string[len-1]!='\\') {
+ string[len] = '\\';
+ string[len+1] = '\0';
+ return len+1;
+ }
+#else
+ if (len==0 || string[len-1]!='/') {
+ string[len] = '/';
+ string[len+1] = '\0';
+ return len+1;
+ }
+#endif
+ return len;
+}
+
+/* removes a slash if there is one */
+void BLI_del_slash(char *string) {
+ int len = strlen(string);
+ while (len) {
+#ifdef WIN32
+ if (string[len-1]=='\\') {
+#else
+ if (string[len-1]=='/') {
+#endif
+ string[len-1] = '\0';
+ len--;
+ } else {
+ break;
+ }
+ }
+}
static int add_win32_extension(char *name)
{
@@ -1485,54 +1648,54 @@ static int add_win32_extension(char *name)
return (retval);
}
-void BLI_where_am_i(char *fullname, const char *name)
+/* filename must be FILE_MAX length minimum */
+void BLI_where_am_i(char *fullname, const int maxlen, const char *name)
{
char filename[FILE_MAXDIR+FILE_MAXFILE];
char *path = NULL, *temp;
-
+
#ifdef _WIN32
- char *separator = ";";
- char slash = '\\';
+ const char *separator = ";";
#else
- char *separator = ":";
- char slash = '/';
+ const char *separator = ":";
#endif
-#ifdef __linux__
+#ifdef WITH_BINRELOC
/* linux uses binreloc since argv[0] is not relyable, call br_init( NULL ) first */
path = br_find_exe( NULL );
if (path) {
- BLI_strncpy(fullname, path, FILE_MAXDIR+FILE_MAXFILE);
+ BLI_strncpy(fullname, path, maxlen);
free(path);
return;
}
#endif
#ifdef _WIN32
- if(GetModuleFileName(0, fullname, FILE_MAXDIR+FILE_MAXFILE)) {
- GetShortPathName(fullname, fullname, FILE_MAXDIR+FILE_MAXFILE);
+ if(GetModuleFileName(0, fullname, maxlen)) {
+ GetShortPathName(fullname, fullname, maxlen);
return;
}
#endif
/* unix and non linux */
- if (name && fullname && strlen(name)) {
- strcpy(fullname, name);
+ if (name && name[0]) {
+ BLI_strncpy(fullname, name, maxlen);
if (name[0] == '.') {
- // relative path, prepend cwd
- BLI_getwdN(fullname);
-
+ char wdir[FILE_MAX]= "";
+ BLI_getwdN(wdir, sizeof(wdir)); /* backup cwd to restore after */
+
// not needed but avoids annoying /./ in name
- if(name && name[0]=='.' && name[1]==slash)
- BLI_join_dirfile(fullname, fullname, name+2);
+ if(name[1]==SEP)
+ BLI_join_dirfile(fullname, maxlen, wdir, name+2);
else
- BLI_join_dirfile(fullname, fullname, name);
-
- add_win32_extension(fullname);
- } else if (BLI_last_slash(name)) {
+ BLI_join_dirfile(fullname, maxlen, wdir, name);
+
+ add_win32_extension(fullname); /* XXX, doesnt respect length */
+ }
+ else if (BLI_last_slash(name)) {
// full path
- strcpy(fullname, name);
+ BLI_strncpy(fullname, name, maxlen);
add_win32_extension(fullname);
} else {
// search for binary in $PATH
@@ -1547,15 +1710,15 @@ void BLI_where_am_i(char *fullname, const char *name)
} else {
strncpy(filename, path, sizeof(filename));
}
- BLI_join_dirfile(fullname, fullname, name);
+ BLI_join_dirfile(fullname, maxlen, fullname, name);
if (add_win32_extension(filename)) {
- strcpy(fullname, filename);
+ BLI_strncpy(fullname, filename, maxlen);
break;
}
} while (temp);
}
}
-#ifndef NDEBUG
+#if defined(DEBUG)
if (strcmp(name, fullname)) {
printf("guessing '%s' == '%s'\n", name, fullname);
}
@@ -1567,20 +1730,20 @@ void BLI_where_am_i(char *fullname, const char *name)
// spaces and double-quotes. There's another solution to this
// with spawnv(P_WAIT, bprogname, argv) instead of system() but
// that's even uglier
- GetShortPathName(fullname, fullname, FILE_MAXDIR+FILE_MAXFILE);
-#ifndef NDEBUG
+ GetShortPathName(fullname, fullname, maxlen);
+#if defined(DEBUG)
printf("Shortname = '%s'\n", fullname);
#endif
#endif
}
}
-void BLI_where_is_temp(char *fullname, int usertemp)
+void BLI_where_is_temp(char *fullname, const int maxlen, int usertemp)
{
fullname[0] = '\0';
if (usertemp && BLI_is_dir(U.tempdir)) {
- strcpy(fullname, U.tempdir);
+ BLI_strncpy(fullname, U.tempdir, maxlen);
}
@@ -1588,7 +1751,7 @@ void BLI_where_is_temp(char *fullname, int usertemp)
if (fullname[0] == '\0') {
char *tmp = getenv("TEMP"); /* Windows */
if (tmp && BLI_is_dir(tmp)) {
- strcpy(fullname, tmp);
+ BLI_strncpy(fullname, tmp, maxlen);
}
}
#else
@@ -1596,28 +1759,32 @@ void BLI_where_is_temp(char *fullname, int usertemp)
if (fullname[0] == '\0') {
char *tmp = getenv("TMP");
if (tmp && BLI_is_dir(tmp)) {
- strcpy(fullname, tmp);
+ BLI_strncpy(fullname, tmp, maxlen);
}
}
if (fullname[0] == '\0') {
char *tmp = getenv("TMPDIR");
if (tmp && BLI_is_dir(tmp)) {
- strcpy(fullname, tmp);
+ BLI_strncpy(fullname, tmp, maxlen);
}
}
#endif
if (fullname[0] == '\0') {
- strcpy(fullname, "/tmp/");
+ BLI_strncpy(fullname, "/tmp/", maxlen);
} else {
/* add a trailing slash if needed */
BLI_add_slash(fullname);
+#ifdef WIN32
+ if(U.tempdir != fullname) {
+ BLI_strncpy(U.tempdir, fullname, maxlen); /* also set user pref to show %TEMP%. /tmp/ is just plain confusing for Windows users. */
+ }
+#endif
}
}
char *get_install_dir(void) {
- extern char bprogname[];
char *tmpname = BLI_strdup(bprogname);
char *cut;
diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c
index 9bce8bb4e37..3393a2674e9 100644
--- a/source/blender/blenlib/intern/pbvh.c
+++ b/source/blender/blenlib/intern/pbvh.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -27,6 +27,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_math.h"
+#include "BLI_utildefines.h"
#include "BLI_ghash.h"
#include "BLI_pbvh.h"
@@ -43,25 +44,27 @@
/* Bitmap */
typedef char* BLI_bitmap;
-BLI_bitmap BLI_bitmap_new(int tot)
+static BLI_bitmap BLI_bitmap_new(int tot)
{
return MEM_callocN((tot >> 3) + 1, "BLI bitmap");
}
-int BLI_bitmap_get(BLI_bitmap b, int index)
+static int BLI_bitmap_get(BLI_bitmap b, int index)
{
return b[index >> 3] & (1 << (index & 7));
}
-void BLI_bitmap_set(BLI_bitmap b, int index)
+static void BLI_bitmap_set(BLI_bitmap b, int index)
{
b[index >> 3] |= (1 << (index & 7));
}
-void BLI_bitmap_clear(BLI_bitmap b, int index)
+#if 0 /* UNUSED */
+static void BLI_bitmap_clear(BLI_bitmap b, int index)
{
b[index >> 3] &= ~(1 << (index & 7));
}
+#endif
/* Axis-aligned bounding box */
typedef struct {
@@ -263,7 +266,7 @@ static int partition_indices(int *prim_indices, int lo, int hi, int axis,
}
}
-void check_partitioning(int *prim_indices, int lo, int hi, int axis,
+static void check_partitioning(int *prim_indices, int lo, int hi, int axis,
float mid, BBC *prim_bbc, int index_of_2nd_partition)
{
int i;
@@ -404,7 +407,7 @@ static void build_grids_leaf_node(PBVH *bvh, PBVHNode *node)
offset and start indicate a range in the array of primitive indices
*/
-void build_sub(PBVH *bvh, int node_index, BB *cb, BBC *prim_bbc,
+static void build_sub(PBVH *bvh, int node_index, BB *cb, BBC *prim_bbc,
int offset, int count)
{
int i, axis, end;
@@ -840,7 +843,7 @@ float BLI_pbvh_node_get_tmin(PBVHNode* node)
return node->tmin;
}
-void BLI_pbvh_search_callback_occluded(PBVH *bvh,
+static void BLI_pbvh_search_callback_occluded(PBVH *bvh,
BLI_pbvh_SearchCallback scb, void *search_data,
BLI_pbvh_HitOccludedCallback hcb, void *hit_data)
{
@@ -1400,7 +1403,7 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3],
//#include "BIF_gl.h"
//#include "BIF_glutil.h"
-void BLI_pbvh_node_draw(PBVHNode *node, void *data)
+void BLI_pbvh_node_draw(PBVHNode *node, void *UNUSED(data))
{
#if 0
/* XXX: Just some quick code to show leaf nodes in different colors */
@@ -1520,13 +1523,22 @@ void BLI_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3])
}
if (pbvh->verts) {
+ MVert *mvert= pbvh->verts;
/* copy new verts coords */
- for (a= 0; a < pbvh->totvert; ++a) {
- copy_v3_v3(pbvh->verts[a].co, vertCos[a]);
+ for (a= 0; a < pbvh->totvert; ++a, ++mvert) {
+ copy_v3_v3(mvert->co, vertCos[a]);
+ mvert->flag |= ME_VERT_PBVH_UPDATE;
}
/* coordinates are new -- normals should also be updated */
mesh_calc_normals(pbvh->verts, pbvh->totvert, pbvh->faces, pbvh->totprim, NULL);
+
+ for (a= 0; a < pbvh->totnode; ++a)
+ BLI_pbvh_node_mark_update(&pbvh->nodes[a]);
+
+ BLI_pbvh_update(pbvh, PBVH_UpdateBB, NULL);
+ BLI_pbvh_update(pbvh, PBVH_UpdateOriginalBB, NULL);
+
}
}
diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c
index 7c14cfd3426..8afb9bec3dd 100644
--- a/source/blender/blenlib/intern/rand.c
+++ b/source/blender/blenlib/intern/rand.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index aa424c1c2bb..5fb9842b7a2 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -34,10 +34,13 @@
* ***** END GPL LICENSE BLOCK *****
*
*/
+#include <stdio.h>
+#include <math.h>
#include "DNA_vec_types.h"
#include <stdio.h>
#include <math.h>
+#include "BLI_rect.h"
int BLI_rcti_is_empty(rcti * rect)
{
diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c
index 7ca7dba2746..2054179a7e2 100644
--- a/source/blender/blenlib/intern/scanfill.c
+++ b/source/blender/blenlib/intern/scanfill.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -35,18 +35,18 @@
#include "MEM_guardedalloc.h"
-
+#include "BLI_callbacks.h"
#include "BLI_editVert.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
-
-#include "BKE_utildefines.h"
+#include "BLI_scanfill.h"
+#include "BLI_utildefines.h"
/* callbacks for errors and interrupts and some goo */
-static void (*BLI_localErrorCallBack)(char*) = NULL;
+static void (*BLI_localErrorCallBack)(const char*) = NULL;
static int (*BLI_localInterruptCallBack)(void) = NULL;
-void BLI_setErrorCallBack(void (*f)(char*))
+void BLI_setErrorCallBack(void (*f)(const char *))
{
BLI_localErrorCallBack = f;
}
@@ -57,7 +57,7 @@ void BLI_setInterruptCallBack(int (*f)(void))
}
/* just flush the error to /dev/null if the error handler is missing */
-void callLocalErrorCallBack(char* msg)
+void callLocalErrorCallBack(const char* msg)
{
if (BLI_localErrorCallBack) {
BLI_localErrorCallBack(msg);
@@ -377,7 +377,7 @@ static ScFillVert *addedgetoscanlist(EditEdge *eed, int len)
sc= (ScFillVert *)bsearch(&scsearch,scdata,len,
sizeof(ScFillVert), vergscdata);
- if(sc==0) printf("Error in search edge: %p\n",eed);
+ if(sc==0) printf("Error in search edge: %p\n", (void *)eed);
else if(addedgetoscanvert(sc,eed)==0) return sc;
return 0;
@@ -482,8 +482,8 @@ static void splitlist(ListBase *tempve, ListBase *temped, short nr)
EditVert *eve,*nextve;
EditEdge *eed,*nexted;
- addlisttolist(tempve,&fillvertbase);
- addlisttolist(temped,&filledgebase);
+ BLI_movelisttolist(tempve,&fillvertbase);
+ BLI_movelisttolist(temped,&filledgebase);
eve= tempve->first;
while(eve) {
@@ -516,9 +516,9 @@ static void scanfill(PolyFill *pf, int mat_nr)
short nr, test, twoconnected=0;
nr= pf->nr;
- verts= pf->verts;
/* PRINTS
+ verts= pf->verts;
eve= fillvertbase.first;
while(eve) {
printf("vert: %x co: %f %f\n",eve,eve->co[cox],eve->co[coy]);
@@ -575,7 +575,6 @@ static void scanfill(PolyFill *pf, int mat_nr)
qsort(scdata, verts, sizeof(ScFillVert), vergscdata);
- sc= scdata;
eed= filledgebase.first;
while(eed) {
nexted= eed->next;
@@ -764,7 +763,7 @@ static void scanfill(PolyFill *pf, int mat_nr)
-int BLI_edgefill(int mode, int mat_nr)
+int BLI_edgefill(int mat_nr)
{
/*
- fill works with its own lists, so create that first (no faces!)
@@ -802,7 +801,7 @@ int BLI_edgefill(int mode, int mat_nr)
eve = fillvertbase.first;
- if (mode & 2) {
+ if (1) { //BMESH_TODO this is correct, right? -joeedh //mode & 2) {
/*use shortest diagonal for quad*/
sub_v3_v3v3(vec1, eve->co, eve->next->next->co);
sub_v3_v3v3(vec2, eve->next->co, eve->next->next->next->co);
@@ -1054,8 +1053,8 @@ int BLI_edgefill(int mode, int mat_nr)
MEM_freeN(polycache);
}
- pf= pflist;
/* printf("after merge\n");
+ pf= pflist;
for(a=1;a<=poly;a++) {
printf("poly:%d edges:%d verts:%d flag: %d\n",a,pf->edges,pf->verts,pf->f);
pf++;
@@ -1078,8 +1077,8 @@ int BLI_edgefill(int mode, int mat_nr)
}
pf++;
}
- addlisttolist(&fillvertbase,&tempve);
- addlisttolist(&filledgebase,&temped);
+ BLI_movelisttolist(&fillvertbase,&tempve);
+ BLI_movelisttolist(&filledgebase,&temped);
/* FREE */
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 80310b1ef8a..b7ac571f856 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -71,10 +71,6 @@
#include <pwd.h>
#endif
-#if !defined(__FreeBSD__) && !defined(__APPLE__)
-#include <malloc.h>
-#endif
-
#ifdef WIN32
#include <io.h>
#include <direct.h>
@@ -89,8 +85,10 @@
#include "BLI_listbase.h"
#include "BLI_linklist.h"
+#include "BLI_storage.h"
#include "BLI_storage_types.h"
#include "BLI_string.h"
+
#include "BKE_utildefines.h"
/* vars: */
@@ -101,21 +99,16 @@ static struct ListBase dirbase_={
0,0};
static struct ListBase *dirbase = &dirbase_;
-
-char *BLI_getwdN(char *dir)
+/* can return NULL when the size is not big enough */
+char *BLI_getwdN(char *dir, const int maxncpy)
{
- char *pwd;
-
- if (dir) {
- pwd = getenv("PWD");
- if (pwd){
- strcpy(dir, pwd);
- return(dir);
- }
- /* 160 is FILE_MAXDIR in filesel.c */
- return( getcwd(dir, 160) );
+ const char *pwd= getenv("PWD");
+ if (pwd){
+ BLI_strncpy(dir, pwd, maxncpy);
+ return dir;
}
- return(0);
+
+ return getcwd(dir, maxncpy);
}
@@ -146,7 +139,7 @@ int BLI_compare(struct direntry *entry1, struct direntry *entry2)
}
-double BLI_diskfree(char *dir)
+double BLI_diskfree(const char *dir)
{
#ifdef WIN32
DWORD sectorspc, bytesps, freec, clusters;
@@ -201,11 +194,11 @@ double BLI_diskfree(char *dir)
#endif
}
-void BLI_builddir(char *dirname, char *relname)
+void BLI_builddir(const char *dirname, const char *relname)
{
struct dirent *fname;
struct dirlink *dlink;
- int rellen, newnum = 0, len;
+ int rellen, newnum = 0;
char buf[256];
DIR *dir;
@@ -224,8 +217,6 @@ void BLI_builddir(char *dirname, char *relname)
if ( (dir = (DIR *)opendir(".")) ){
while ((fname = (struct dirent*) readdir(dir)) != NULL) {
- len= strlen(fname->d_name);
-
dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
if (dlink){
strcpy(buf+rellen,fname->d_name);
@@ -289,12 +280,12 @@ void BLI_builddir(char *dirname, char *relname)
}
}
-void BLI_adddirstrings()
+void BLI_adddirstrings(void)
{
char datum[100];
char buf[512];
char size[250];
- static char * types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
+ static const char * types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
int num, mode;
#ifdef WIN32
__int64 st_size;
@@ -397,7 +388,7 @@ void BLI_adddirstrings()
}
}
-unsigned int BLI_getdir(char *dirname, struct direntry **filelist)
+unsigned int BLI_getdir(const char *dirname, struct direntry **filelist)
{
// reset global variables
// memory stored in files is free()'d in
@@ -421,7 +412,7 @@ unsigned int BLI_getdir(char *dirname, struct direntry **filelist)
}
-int BLI_filesize(int file)
+size_t BLI_filesize(int file)
{
struct stat buf;
@@ -430,11 +421,11 @@ int BLI_filesize(int file)
return (buf.st_size);
}
-int BLI_filepathsize(const char *path)
+size_t BLI_filepathsize(const char *path)
{
int size, file = open(path, O_BINARY|O_RDONLY);
- if (file < 0)
+ if (file == -1)
return -1;
size = BLI_filesize(file);
@@ -443,7 +434,7 @@ int BLI_filepathsize(const char *path)
}
-int BLI_exist(char *name)
+int BLI_exist(const char *name)
{
#if defined(WIN32) && !defined(__MINGW32__)
struct _stat64i32 st;
@@ -474,11 +465,11 @@ int BLI_exist(char *name)
}
/* would be better in fileops.c except that it needs stat.h so add here */
-int BLI_is_dir(char *file) {
+int BLI_is_dir(const char *file) {
return S_ISDIR(BLI_exist(file));
}
-LinkNode *BLI_read_file_as_lines(char *name)
+LinkNode *BLI_read_file_as_lines(const char *name)
{
FILE *fp= fopen(name, "r");
LinkNode *lines= NULL;
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 76193ba9a13..d6331d6eeb8 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -66,7 +66,7 @@ char *BLI_strdupcat(const char *str1, const char *str2)
return n;
}
-char *BLI_strncpy(char *dst, const char *src, int maxncpy) {
+char *BLI_strncpy(char *dst, const char *src, const int maxncpy) {
int srclen= strlen(src);
int cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen;
@@ -311,8 +311,13 @@ int BLI_natstrcmp(const char *s1, const char *s2)
c1 = tolower(s1[d1]);
c2 = tolower(s2[d2]);
}
-
- if (c1<c2) {
+
+ /* first check for '.' so "foo.bar" comes before "foo 1.bar" */
+ if(c1=='.' && c2!='.')
+ return -1;
+ if(c1!='.' && c2=='.')
+ return 1;
+ else if (c1<c2) {
return -1;
} else if (c1>c2) {
return 1;
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index 726ed817f8b..f57f6f969ae 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -1,4 +1,4 @@
-/**
+/*
*
* $Id$
*
@@ -442,6 +442,8 @@ ThreadedWorker *BLI_create_worker(void *(*do_thread)(void *), int tot, int sleep
{
ThreadedWorker *worker;
+ (void)sleep_time; /* unused */
+
worker = MEM_callocN(sizeof(ThreadedWorker), "threadedworker");
if (tot > RE_MAX_THREAD)
@@ -518,7 +520,7 @@ struct ThreadQueue {
int nowait;
};
-ThreadQueue *BLI_thread_queue_init()
+ThreadQueue *BLI_thread_queue_init(void)
{
ThreadQueue *queue;
diff --git a/source/blender/blenlib/intern/time.c b/source/blender/blenlib/intern/time.c
index 0992e08b28f..a14f73968bf 100644
--- a/source/blender/blenlib/intern/time.c
+++ b/source/blender/blenlib/intern/time.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -27,8 +27,9 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#ifdef WIN32
#include "PIL_time.h"
+
+#ifdef WIN32
#include <windows.h>
double PIL_check_seconds_timer(void)
diff --git a/source/blender/blenlib/intern/uvproject.c b/source/blender/blenlib/intern/uvproject.c
index cc115d52928..81fe6b26ba4 100644
--- a/source/blender/blenlib/intern/uvproject.c
+++ b/source/blender/blenlib/intern/uvproject.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -28,6 +28,7 @@
#include "DNA_object_types.h"
#include "BLI_math.h"
+#include "BLI_uvproject.h"
typedef struct UvCameraInfo {
float camangle;
@@ -60,7 +61,9 @@ void project_from_camera(float target[2], float source[3], UvCameraInfo *uci)
target[1]= pv4[1] / uci->camsize;
}
else {
- float vec2d[2]= {pv4[0], pv4[2]}; /* 2D position from the camera */
+ float vec2d[2]; /* 2D position from the camera */
+ vec2d[0]= pv4[0];
+ vec2d[1]= pv4[2];
target[0]= angle * (M_PI / uci->camangle);
target[1]= pv4[1] / (len_v2(vec2d) * uci->camsize);
}
diff --git a/source/blender/blenlib/intern/voxel.c b/source/blender/blenlib/intern/voxel.c
index 2b04a49e848..966bf754d69 100644
--- a/source/blender/blenlib/intern/voxel.c
+++ b/source/blender/blenlib/intern/voxel.c
@@ -1,4 +1,4 @@
-/**
+/*
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -27,8 +27,9 @@
*/
#include "BLI_voxel.h"
+#include "BLI_utildefines.h"
+
-#include "BKE_utildefines.h"
BM_INLINE float D(float *data, int *res, int x, int y, int z)
{
diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c
index 81a635205f9..71eac3c86c4 100644
--- a/source/blender/blenlib/intern/winstuff.c
+++ b/source/blender/blenlib/intern/winstuff.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -33,13 +33,16 @@
#include <stdlib.h>
#include <stdio.h>
-
+#include "MEM_guardedalloc.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
+
+#include "BKE_utildefines.h"
+
#define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY
#include "BLI_winstuff.h"
-#include "BKE_utildefines.h" /* FILE_MAXDIR + FILE_MAXFILE */
+ /* FILE_MAXDIR + FILE_MAXFILE */
int BLI_getInstallationDir( char * str ) {
char dir[FILE_MAXDIR];