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:
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r--source/blender/blenloader/intern/readfile.c102
-rw-r--r--source/blender/blenloader/intern/versioning_260.c6
-rw-r--r--source/blender/blenloader/intern/versioning_270.c58
-rw-r--r--source/blender/blenloader/intern/versioning_defaults.c68
-rw-r--r--source/blender/blenloader/intern/versioning_legacy.c4
-rw-r--r--source/blender/blenloader/intern/writefile.c227
6 files changed, 393 insertions, 72 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 91753158d02..b2e49be1a5e 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -434,8 +434,7 @@ void blo_join_main(ListBase *mainlist)
while ((tojoin = mainl->next)) {
add_main_to_main(mainl, tojoin);
BLI_remlink(mainlist, tojoin);
- MEM_freeN(tojoin->eval_ctx);
- MEM_freeN(tojoin);
+ BKE_main_free(tojoin);
}
}
@@ -1824,6 +1823,7 @@ static void lib_link_brush(FileData *fd, Main *main)
brush->mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mtex.tex);
brush->mask_mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mask_mtex.tex);
brush->clone.image = newlibadr_us(fd, brush->id.lib, brush->clone.image);
+ brush->paint_curve = newlibadr_us(fd, brush->id.lib, brush->paint_curve);
}
}
}
@@ -1834,6 +1834,8 @@ static void direct_link_brush(FileData *fd, Brush *brush)
/* fallof curve */
brush->curve = newdataadr(fd, brush->curve);
+ brush->gradient = newdataadr(fd, brush->gradient);
+
if (brush->curve)
direct_link_curvemapping(fd, brush->curve);
else
@@ -1843,6 +1845,43 @@ static void direct_link_brush(FileData *fd, Brush *brush)
brush->icon_imbuf = NULL;
}
+/* ************ READ Palette *************** */
+static void lib_link_palette(FileData *UNUSED(fd), Main *main)
+{
+ Palette *palette;
+
+ /* only link ID pointers */
+ for (palette = main->palettes.first; palette; palette = palette->id.next) {
+ if (palette->id.flag & LIB_NEED_LINK) {
+ palette->id.flag -= LIB_NEED_LINK;
+ }
+ }
+}
+
+static void direct_link_palette(FileData *fd, Palette *palette)
+{
+ /* palette itself has been read */
+ link_list(fd, &palette->colors);
+}
+
+static void lib_link_paint_curve(FileData *UNUSED(fd), Main *main)
+{
+ PaintCurve *pc;
+
+ /* only link ID pointers */
+ for (pc = main->paintcurves.first; pc; pc = pc->id.next) {
+ if (pc->id.flag & LIB_NEED_LINK) {
+ pc->id.flag -= LIB_NEED_LINK;
+ }
+ }
+}
+
+static void direct_link_paint_curve(FileData *fd, PaintCurve *pc)
+{
+ pc->points = newdataadr(fd, pc->points);
+}
+
+
static void direct_link_script(FileData *UNUSED(fd), Script *script)
{
script->id.us = 1;
@@ -2664,9 +2703,9 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
}
}
else if (ntree->type==NTREE_COMPOSIT) {
- if (ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT))
+ if (ELEM(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT))
direct_link_curvemapping(fd, node->storage);
- else if (ELEM3(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
+ else if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
((ImageUser *)node->storage)->ok = 1;
}
else if ( ntree->type==NTREE_TEXTURE) {
@@ -3516,7 +3555,8 @@ static void direct_link_material(FileData *fd, Material *ma)
for (a = 0; a < MAX_MTEX; a++) {
ma->mtex[a] = newdataadr(fd, ma->mtex[a]);
}
-
+ ma->texpaintslot = NULL;
+
ma->ramp_col = newdataadr(fd, ma->ramp_col);
ma->ramp_spec = newdataadr(fd, ma->ramp_spec);
@@ -5059,6 +5099,7 @@ static void link_paint(FileData *fd, Scene *sce, Paint *p)
{
if (p) {
p->brush = newlibadr_us(fd, sce->id.lib, p->brush);
+ p->palette = newlibadr_us(fd, sce->id.lib, p->palette);
p->paint_cursor = NULL;
}
}
@@ -5107,6 +5148,18 @@ static void lib_link_scene(FileData *fd, Main *main)
sce->toolsettings->sculpt->gravity_object =
newlibadr_us(fd, sce->id.lib, sce->toolsettings->sculpt->gravity_object);
+ if (sce->toolsettings->imapaint.stencil)
+ sce->toolsettings->imapaint.stencil =
+ newlibadr_us(fd, sce->id.lib, sce->toolsettings->imapaint.stencil);
+
+ if (sce->toolsettings->imapaint.clone)
+ sce->toolsettings->imapaint.clone =
+ newlibadr_us(fd, sce->id.lib, sce->toolsettings->imapaint.clone);
+
+ if (sce->toolsettings->imapaint.canvas)
+ sce->toolsettings->imapaint.canvas =
+ newlibadr_us(fd, sce->id.lib, sce->toolsettings->imapaint.canvas);
+
sce->toolsettings->skgen_template = newlibadr(fd, sce->id.lib, sce->toolsettings->skgen_template);
for (base = sce->base.first; base; base = next) {
@@ -5355,7 +5408,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
if (seq->strip && seq->strip->done==0) {
seq->strip->done = true;
- if (ELEM4(seq->type, SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) {
+ if (ELEM(seq->type, SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) {
seq->strip->stripdata = newdataadr(fd, seq->strip->stripdata);
}
else {
@@ -5789,9 +5842,9 @@ static void lib_link_screen(FileData *fd, Main *main)
/* how to handle user count on pointer restore */
typedef enum ePointerUserMode {
- USER_IGNORE, /* ignore user count */
- USER_ONE, /* ensure at least one user (fake also counts) */
- USER_REAL /* ensure at least one real user (fake user ignored) */
+ USER_IGNORE = 0, /* ignore user count */
+ USER_ONE = 1, /* ensure at least one user (fake also counts) */
+ USER_REAL = 2, /* ensure at least one real user (fake user ignored) */
} ePointerUserMode;
static bool restore_pointer(ID *id, ID *newid, ePointerUserMode user)
@@ -5816,9 +5869,9 @@ static bool restore_pointer(ID *id, ID *newid, ePointerUserMode user)
* Only for undo files, or to restore a screen after reading without UI...
*
* user
- * - 0: no usercount change
- * - 1: ensure a user
- * - 2: ensure a real user (even if a fake one is set)
+ * - USER_IGNORE: no usercount change
+ * - USER_ONE: ensure a user
+ * - USER_REAL: ensure a real user (even if a fake one is set)
*/
static void *restore_pointer_by_name(Main *mainp, ID *id, ePointerUserMode user)
{
@@ -5915,8 +5968,12 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
v3d->ob_centre = restore_pointer_by_name(newmain, (ID *)v3d->ob_centre, USER_ONE);
for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
- bgpic->ima = restore_pointer_by_name(newmain, (ID *)bgpic->ima, USER_ONE);
- bgpic->clip = restore_pointer_by_name(newmain, (ID *)bgpic->clip, USER_ONE);
+ if ((bgpic->ima = restore_pointer_by_name(newmain, (ID *)bgpic->ima, USER_IGNORE))) {
+ id_us_plus((ID *)bgpic->ima);
+ }
+ if ((bgpic->clip = restore_pointer_by_name(newmain, (ID *)bgpic->clip, USER_IGNORE))) {
+ id_us_plus((ID *)bgpic->clip);
+ }
}
if (v3d->localvd) {
/*Base *base;*/
@@ -6290,6 +6347,9 @@ static bool direct_link_screen(FileData *fd, bScreen *sc)
else if (sa->spacetype == SPACE_VIEW3D)
blo_do_versions_view3d_split_250(sa->spacedata.first, &sa->regionbase);
+ /* incase we set above */
+ sa->butspacetype = sa->spacetype;
+
for (sl = sa->spacedata.first; sl; sl = sl->next) {
link_list(fd, &(sl->regionbase));
@@ -7138,6 +7198,8 @@ static const char *dataname(short id_code)
case ID_NT: return "Data from NT";
case ID_BR: return "Data from BR";
case ID_PA: return "Data from PA";
+ case ID_PAL: return "Data from PAL";
+ case ID_PC: return "Data from PCRV";
case ID_GD: return "Data from GD";
case ID_WM: return "Data from WM";
case ID_MC: return "Data from MC";
@@ -7323,6 +7385,12 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
case ID_LS:
direct_link_linestyle(fd, (FreestyleLineStyle *)id);
break;
+ case ID_PAL:
+ direct_link_palette(fd, (Palette *)id);
+ break;
+ case ID_PC:
+ direct_link_paint_curve(fd, (PaintCurve *)id);
+ break;
}
oldnewmap_free_unused(fd->datamap);
@@ -7487,8 +7555,9 @@ static void lib_link_all(FileData *fd, Main *main)
/* No load UI for undo memfiles */
if (fd->memfile == NULL) {
lib_link_windowmanager(fd, main);
- lib_link_screen(fd, main);
}
+ /* DO NOT skip screens here, 3Dview may contains pointers to other ID data (like bgpic)! See T41411. */
+ lib_link_screen(fd, main);
lib_link_scene(fd, main);
lib_link_object(fd, main);
lib_link_curve(fd, main);
@@ -7511,6 +7580,8 @@ static void lib_link_all(FileData *fd, Main *main)
lib_link_vfont(fd, main);
lib_link_nodetree(fd, main); /* has to be done after scene/materials, this will verify group nodes */
lib_link_brush(fd, main);
+ lib_link_palette(fd, main);
+ lib_link_paint_curve(fd, main);
lib_link_particlesettings(fd, main);
lib_link_movieclip(fd, main);
lib_link_mask(fd, main);
@@ -8050,6 +8121,7 @@ static void expand_brush(FileData *fd, Main *mainvar, Brush *brush)
expand_doit(fd, mainvar, brush->mtex.tex);
expand_doit(fd, mainvar, brush->mask_mtex.tex);
expand_doit(fd, mainvar, brush->clone.image);
+ expand_doit(fd, mainvar, brush->paint_curve);
}
static void expand_material(FileData *fd, Main *mainvar, Material *ma)
diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c
index 3890e07bb65..7c6b6ec7249 100644
--- a/source/blender/blenloader/intern/versioning_260.c
+++ b/source/blender/blenloader/intern/versioning_260.c
@@ -2454,9 +2454,9 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
if (sl->spacetype == SPACE_OUTLINER) {
SpaceOops *so = (SpaceOops *)sl;
- if (!ELEM11(so->outlinevis, SO_ALL_SCENES, SO_CUR_SCENE, SO_VISIBLE, SO_SELECTED, SO_ACTIVE,
- SO_SAME_TYPE, SO_GROUPS, SO_LIBRARIES, SO_SEQUENCE, SO_DATABLOCKS,
- SO_USERDEF))
+ if (!ELEM(so->outlinevis, SO_ALL_SCENES, SO_CUR_SCENE, SO_VISIBLE, SO_SELECTED, SO_ACTIVE,
+ SO_SAME_TYPE, SO_GROUPS, SO_LIBRARIES, SO_SEQUENCE, SO_DATABLOCKS,
+ SO_USERDEF))
{
so->outlinevis = SO_ALL_SCENES;
}
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 103f9b76ba7..8e760a9c9f6 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -34,6 +34,8 @@
/* allow readfile to use deprecated functionality */
#define DNA_DEPRECATED_ALLOW
+#include "DNA_brush_types.h"
+#include "DNA_cloth_types.h"
#include "DNA_constraint_types.h"
#include "DNA_sdna_types.h"
#include "DNA_space_types.h"
@@ -41,7 +43,9 @@
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_modifier_types.h"
+#include "DNA_particle_types.h"
#include "DNA_linestyle_types.h"
+#include "DNA_actuator_types.h"
#include "DNA_genfile.h"
@@ -308,6 +312,44 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
mat->line_col[3] = mat->alpha;
}
}
+
+ if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
+ Scene *scene;
+ for (scene = main->scene.first; scene; scene = scene->id.next) {
+ scene->r.preview_start_resolution = 64;
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
+ /* init up & track axis property of trackto actuators */
+ Object *ob;
+
+ for (ob = main->object.first; ob; ob = ob->id.next) {
+ bActuator *act;
+ for (act = ob->actuators.first; act; act = act->next) {
+ if (act->type == ACT_EDIT_OBJECT) {
+ bEditObjectActuator *eoact = act->data;
+ eoact->trackflag = ob->trackflag;
+ /* if trackflag is pointing +-Z axis then upflag should point Y axis.
+ * Rest of trackflag cases, upflag should be point z axis */
+ if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
+ eoact->upflag = 1;
+ }
+ else {
+ eoact->upflag = 2;
+ }
+ }
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
+ Brush *br;
+
+ for (br = main->brush.first; br; br = br->id.next) {
+ br->fill_threshold = 0.2f;
+ }
}
if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
@@ -316,4 +358,20 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
scene->r.preview_start_resolution = 64;
}
}
+
+ if (!MAIN_VERSION_ATLEAST(main, 271, 6)) {
+ Object *ob;
+ for (ob = main->object.first; ob; ob = ob->id.next) {
+ ModifierData *md;
+
+ for (md = ob->modifiers.first; md; md = md->next) {
+ if (md->type == eModifierType_ParticleSystem) {
+ ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
+ if (pmd->psys && pmd->psys->clmd) {
+ pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
+ }
+ }
+ }
+ }
+ }
}
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index fdedd3f4edd..217d1f0821f 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -26,8 +26,10 @@
*/
#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
#include "BLI_math.h"
+#include "DNA_brush_types.h"
#include "DNA_freestyle_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_scene_types.h"
@@ -36,14 +38,34 @@
#include "DNA_userdef_types.h"
#include "DNA_mesh_types.h"
#include "DNA_material_types.h"
+#include "DNA_object_types.h"
+#include "BKE_brush.h"
+#include "BKE_library.h"
#include "BKE_main.h"
#include "BLO_readfile.h"
-/* Update defaults in startup.blend, without having to save and embed the file.
+
+/**
+ * Override values in in-memory startup.blend, avoids resaving for small changes.
+ */
+void BLO_update_defaults_userpref_blend(void)
+{
+ /* defaults from T37518 */
+
+ U.uiflag |= USER_ZBUF_CURSOR;
+ U.uiflag |= USER_QUIT_PROMPT;
+ U.uiflag |= USER_CONTINUOUS_MOUSE;
+
+ U.versions = 1;
+ U.savetime = 2;
+}
+
+/**
+ * Update defaults in startup.blend, without having to save and embed the file.
* This function can be emptied each time the startup.blend is updated. */
-void BLO_update_defaults_startup_blend(Main *main)
+void BLO_update_defaults_startup_blend(Main *bmain)
{
Scene *scene;
SceneRenderLayer *srl;
@@ -51,7 +73,7 @@ void BLO_update_defaults_startup_blend(Main *main)
Mesh *me;
Material *mat;
- for (scene = main->scene.first; scene; scene = scene->id.next) {
+ for (scene = bmain->scene.first; scene; scene = scene->id.next) {
scene->r.im_format.planes = R_IMF_PLANES_RGBA;
scene->r.im_format.compress = 15;
@@ -59,9 +81,20 @@ void BLO_update_defaults_startup_blend(Main *main)
srl->freestyleConfig.sphere_radius = 0.1f;
srl->pass_alpha_threshold = 0.5f;
}
+
+ if (scene->toolsettings) {
+ ToolSettings *ts = scene->toolsettings;
+
+ if (ts->sculpt) {
+ Sculpt *sculpt = ts->sculpt;
+ sculpt->paint.symmetry_flags |= PAINT_SYMM_X;
+ sculpt->flags |= SCULPT_DYNTOPO_COLLAPSE;
+ sculpt->detail_size = 12;
+ }
+ }
}
- for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
+ for (linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING | LS_TEXTURE;
linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
linestyle->integration_type = LS_INTEGRATION_MEAN;
@@ -71,27 +104,48 @@ void BLO_update_defaults_startup_blend(Main *main)
{
bScreen *screen;
- for (screen = main->screen.first; screen; screen = screen->id.next) {
+ for (screen = bmain->screen.first; screen; screen = screen->id.next) {
ScrArea *area;
for (area = screen->areabase.first; area; area = area->next) {
SpaceLink *space_link;
+ ARegion *ar;
+
for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
if (space_link->spacetype == SPACE_CLIP) {
SpaceClip *space_clip = (SpaceClip *) space_link;
space_clip->flag &= ~SC_MANUAL_CALIBRATION;
}
}
+
+ /* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */
+ for (ar = area->regionbase.first; ar; ar = ar->next) {
+ BLI_freelistN(&ar->panels);
+ }
}
}
}
- for (me = main->mesh.first; me; me = me->id.next) {
+ for (me = bmain->mesh.first; me; me = me->id.next) {
me->smoothresh = DEG2RADF(180.0f);
+ me->flag &= ~ME_TWOSIDED;
}
- for (mat = main->mat.first; mat; mat = mat->id.next) {
+ for (mat = bmain->mat.first; mat; mat = mat->id.next) {
mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
mat->line_col[3] = 1.0f;
}
+
+ {
+ Brush *br;
+ br = BKE_brush_add(bmain, "Fill");
+ br->imagepaint_tool = PAINT_TOOL_FILL;
+ br->ob_mode = OB_MODE_TEXTURE_PAINT;
+
+ br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Mask");
+ if (br) {
+ br->imagepaint_tool = PAINT_TOOL_MASK;
+ br->ob_mode |= OB_MODE_TEXTURE_PAINT;
+ }
+ }
}
diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c
index 572c6d0a02d..557cc147f19 100644
--- a/source/blender/blenloader/intern/versioning_legacy.c
+++ b/source/blender/blenloader/intern/versioning_legacy.c
@@ -473,7 +473,7 @@ static void do_version_ntree_242_2(bNodeTree *ntree)
if (ntree->type == NTREE_COMPOSIT) {
for (node = ntree->nodes.first; node; node = node->next) {
- if (ELEM3(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
+ if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
/* only image had storage */
if (node->storage) {
NodeImageAnim *nia = node->storage;
@@ -2232,7 +2232,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
if (sce->r.mode & R_PANORAMA) {
- /* all these checks to ensure saved files with svn version keep working... */
+ /* all these checks to ensure saved files between released versions keep working... */
if (sce->r.xsch < sce->r.ysch) {
Object *obc = blo_do_versions_newlibadr(fd, lib, sce->camera);
if (obc && obc->type == OB_CAMERA) {
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index a0198a687a2..59f12657703 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -183,6 +183,114 @@
#define MYWRITE_BUFFER_SIZE 100000
#define MYWRITE_MAX_CHUNK 32768
+
+
+/** \name Small API to handle compression.
+ * \{ */
+
+typedef enum {
+ WW_WRAP_NONE = 1,
+ WW_WRAP_ZLIB,
+} eWriteWrapType;
+
+typedef struct WriteWrap WriteWrap;
+struct WriteWrap {
+ /* callbacks */
+ bool (*open)(WriteWrap *ww, const char *filepath);
+ bool (*close)(WriteWrap *ww);
+ size_t (*write)(WriteWrap *ww, const char *data, size_t data_len);
+
+ /* internal */
+ union {
+ int file_handle;
+ gzFile gz_handle;
+ } _user_data;
+};
+
+/* none */
+#define FILE_HANDLE(ww) \
+ (ww)->_user_data.file_handle
+
+static bool ww_open_none(WriteWrap *ww, const char *filepath)
+{
+ int file;
+
+ file = BLI_open(filepath, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
+
+ if (file != -1) {
+ FILE_HANDLE(ww) = file;
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+static bool ww_close_none(WriteWrap *ww)
+{
+ return (close(FILE_HANDLE(ww)) != -1);
+}
+static size_t ww_write_none(WriteWrap *ww, const char *buf, size_t buf_len)
+{
+ return write(FILE_HANDLE(ww), buf, buf_len);
+}
+#undef FILE_HANDLE
+
+/* zlib */
+#define FILE_HANDLE(ww) \
+ (ww)->_user_data.gz_handle
+
+static bool ww_open_zlib(WriteWrap *ww, const char *filepath)
+{
+ gzFile file;
+
+ file = BLI_gzopen(filepath, "wb1");
+
+ if (file != Z_NULL) {
+ FILE_HANDLE(ww) = file;
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+static bool ww_close_zlib(WriteWrap *ww)
+{
+ return (gzclose(FILE_HANDLE(ww)) == Z_OK);
+}
+static size_t ww_write_zlib(WriteWrap *ww, const char *buf, size_t buf_len)
+{
+ return gzwrite(FILE_HANDLE(ww), buf, buf_len);
+}
+#undef FILE_HANDLE
+
+/* --- end compression types --- */
+
+static void ww_handle_init(eWriteWrapType ww_type, WriteWrap *r_ww)
+{
+ memset(r_ww, 0, sizeof(*r_ww));
+
+ switch (ww_type) {
+ case WW_WRAP_ZLIB:
+ {
+ r_ww->open = ww_open_zlib;
+ r_ww->close = ww_close_zlib;
+ r_ww->write = ww_write_zlib;
+ break;
+ }
+ default:
+ {
+ r_ww->open = ww_open_none;
+ r_ww->close = ww_close_none;
+ r_ww->write = ww_write_none;
+ break;
+ }
+ }
+}
+
+/** \} */
+
+
+
typedef struct {
struct SDNA *sdna;
@@ -192,12 +300,17 @@ typedef struct {
int tot, count, error, memsize;
+ /* Wrap writing, so we can use zlib or
+ * other compression types later, see: G_FILE_COMPRESS
+ * Will be NULL for UNDO. */
+ WriteWrap *ww;
+
#ifdef USE_BMESH_SAVE_AS_COMPAT
char use_mesh_compat; /* option to save with older mesh format */
#endif
} WriteData;
-static WriteData *writedata_new(int file)
+static WriteData *writedata_new(WriteWrap *ww)
{
WriteData *wd= MEM_callocN(sizeof(*wd), "writedata");
@@ -209,7 +322,7 @@ static WriteData *writedata_new(int file)
wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false);
- wd->file= file;
+ wd->ww = ww;
wd->buf= MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf");
@@ -226,9 +339,9 @@ static void writedata_do_write(WriteData *wd, const void *mem, int memlen)
add_memfilechunk(NULL, wd->current, mem, memlen);
}
else {
- if (write(wd->file, mem, memlen) != memlen)
- wd->error= 1;
-
+ if (wd->ww->write(wd->ww, mem, memlen) != memlen) {
+ wd->error = 1;
+ }
}
}
@@ -302,9 +415,9 @@ static void mywrite(WriteData *wd, const void *adr, int len)
* \param current The current memory file (can be NULL).
* \warning Talks to other functions with global parameters
*/
-static WriteData *bgnwrite(int file, MemFile *compare, MemFile *current)
+static WriteData *bgnwrite(WriteWrap *ww, MemFile *compare, MemFile *current)
{
- WriteData *wd= writedata_new(file);
+ WriteData *wd= writedata_new(ww);
if (wd == NULL) return NULL;
@@ -767,7 +880,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree)
writedata(wd, DATA, strlen(nss->bytecode)+1, nss->bytecode);
writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage);
}
- else if (ntree->type==NTREE_COMPOSIT && ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT))
+ else if (ntree->type==NTREE_COMPOSIT && ELEM(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT))
write_curvemapping(wd, node->storage);
else if (ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) )
write_curvemapping(wd, node->storage);
@@ -2256,6 +2369,9 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
case SEQ_TYPE_TRANSFORM:
writestruct(wd, DATA, "TransformVars", 1, seq->effectdata);
break;
+ case SEQ_TYPE_GAUSSIAN_BLUR:
+ writestruct(wd, DATA, "GaussianBlurVars", 1, seq->effectdata);
+ break;
}
}
@@ -2921,6 +3037,38 @@ static void write_brushes(WriteData *wd, ListBase *idbase)
if (brush->curve)
write_curvemapping(wd, brush->curve);
+ if (brush->curve)
+ writestruct(wd, DATA, "ColorBand", 1, brush->gradient);
+ }
+ }
+}
+
+static void write_palettes(WriteData *wd, ListBase *idbase)
+{
+ Palette *palette;
+
+ for (palette = idbase->first; palette; palette = palette->id.next) {
+ if (palette->id.us > 0 || wd->current) {
+ PaletteColor *color;
+ writestruct(wd, ID_PAL, "Palette", 1, palette);
+ if (palette->id.properties) IDP_WriteProperty(palette->id.properties, wd);
+
+ for (color = palette->colors.first; color; color= color->next)
+ writestruct(wd, DATA, "PaletteColor", 1, color);
+ }
+ }
+}
+
+static void write_paintcurves(WriteData *wd, ListBase *idbase)
+{
+ PaintCurve *pc;
+
+ for (pc = idbase->first; pc; pc = pc->id.next) {
+ if (pc->id.us > 0 || wd->current) {
+ writestruct(wd, ID_PC, "PaintCurve", 1, pc);
+
+ writestruct(wd, DATA, "PaintCurvePoint", pc->tot_points, pc->points);
+ if (pc->id.properties) IDP_WriteProperty(pc->id.properties, wd);
}
}
}
@@ -3334,8 +3482,11 @@ static void write_thumb(WriteData *wd, const int *img)
}
/* if MemFile * there's filesave to memory */
-static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFile *current,
- int write_user_block, int write_flags, const int *thumb)
+static int write_file_handle(
+ Main *mainvar,
+ WriteWrap *ww,
+ MemFile *compare, MemFile *current,
+ int write_user_block, int write_flags, const int *thumb)
{
BHead bhead;
ListBase mainlist;
@@ -3344,7 +3495,7 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
blo_split_main(&mainlist, mainvar);
- wd= bgnwrite(handle, compare, current);
+ wd = bgnwrite(ww, compare, current);
#ifdef USE_BMESH_SAVE_AS_COMPAT
wd->use_mesh_compat = (write_flags & G_FILE_MESH_COMPAT) != 0;
@@ -3396,6 +3547,8 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
write_particlesettings(wd, &mainvar->particle);
write_nodetrees(wd, &mainvar->nodetree);
write_brushes (wd, &mainvar->brush);
+ write_palettes (wd, &mainvar->palettes);
+ write_paintcurves (wd, &mainvar->paintcurves);
write_scripts (wd, &mainvar->script);
write_gpencils (wd, &mainvar->gpencil);
write_linestyles(wd, &mainvar->linestyle);
@@ -3468,7 +3621,9 @@ static bool do_history(const char *name, ReportList *reports)
int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportList *reports, const int *thumb)
{
char tempname[FILE_MAX+1];
- int file, err, write_user_block;
+ int err, write_user_block;
+ eWriteWrapType ww_type;
+ WriteWrap ww;
/* path backup/restore */
void *path_list_backup = NULL;
@@ -3477,8 +3632,16 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
/* open temporary file, so we preserve the original in case we crash */
BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
- file = BLI_open(tempname, O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
- if (file == -1) {
+ if (write_flags & G_FILE_COMPRESS) {
+ ww_type = WW_WRAP_ZLIB;
+ }
+ else {
+ ww_type = WW_WRAP_NONE;
+ }
+
+ ww_handle_init(ww_type, &ww);
+
+ if (ww.open(&ww, tempname) == false) {
BKE_reportf(reports, RPT_ERROR, "Cannot open file %s for writing: %s", tempname, strerror(errno));
return 0;
}
@@ -3519,8 +3682,9 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
BKE_bpath_relative_convert(mainvar, filepath, NULL); /* note, making relative to something OTHER then G.main->name */
/* actual file writing */
- err= write_file_handle(mainvar, file, NULL, NULL, write_user_block, write_flags, thumb);
- close(file);
+ err = write_file_handle(mainvar, &ww, NULL, NULL, write_user_block, write_flags, thumb);
+
+ ww.close(&ww);
if (UNLIKELY(path_list_backup)) {
BKE_bpath_list_restore(mainvar, path_list_flag, path_list_backup);
@@ -3544,34 +3708,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
}
}
- if (write_flags & G_FILE_COMPRESS) {
- /* compressed files have the same ending as regular files... only from 2.4!!! */
- char gzname[FILE_MAX+4];
- int ret;
-
- /* first write compressed to separate @.gz */
- BLI_snprintf(gzname, sizeof(gzname), "%s@.gz", filepath);
- ret = BLI_file_gzip(tempname, gzname);
-
- if (0==ret) {
- /* now rename to real file name, and delete temp @ file too */
- if (BLI_rename(gzname, filepath) != 0) {
- BKE_report(reports, RPT_ERROR, "Cannot change old file (file saved with @)");
- return 0;
- }
-
- BLI_delete(tempname, false, false);
- }
- else if (-1==ret) {
- BKE_report(reports, RPT_ERROR, "Failed opening .gz file");
- return 0;
- }
- else if (-2==ret) {
- BKE_report(reports, RPT_ERROR, "Failed opening .blend file for compression");
- return 0;
- }
- }
- else if (BLI_rename(tempname, filepath) != 0) {
+ if (BLI_rename(tempname, filepath) != 0) {
BKE_report(reports, RPT_ERROR, "Cannot change old file (file saved with @)");
return 0;
}
@@ -3584,7 +3721,7 @@ int BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int wr
{
int err;
- err= write_file_handle(mainvar, 0, compare, current, 0, write_flags, NULL);
+ err = write_file_handle(mainvar, NULL, compare, current, 0, write_flags, NULL);
if (err==0) return 1;
return 0;