[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16201] branches/soc-2007-joeedh/source/ blender: Commit of an experimental tile-based disk-backed image

Joseph Eagar joeedh at gmail.com
Thu Aug 21 09:59:18 CEST 2008


Revision: 16201
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16201
Author:   joeedh
Date:     2008-08-21 09:59:18 +0200 (Thu, 21 Aug 2008)

Log Message:
-----------
Commit of an experimental tile-based disk-backed image
library I felt like writing.  It does nothing at the moment.

Also, added some UI for soft shadows (which of course
don't work yet, still need to code a good PCF
implementation, as it seems not only is the more
physically-correct method my nonworking code is using 
a lot slower, but it's also not worth it if your
rendering fur).

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c
    branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c
    branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_image.c
    branches/soc-2007-joeedh/source/blender/makesdna/DNA_lamp_types.h
    branches/soc-2007-joeedh/source/blender/render/intern/include/render_types.h
    branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_func.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c
    branches/soc-2007-joeedh/source/blender/src/buttons_shading.c

Added Paths:
-----------
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_imagebuffer.h

Added: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_imagebuffer.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_imagebuffer.h	                        (rev 0)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_imagebuffer.h	2008-08-21 07:59:18 UTC (rev 16201)
@@ -0,0 +1,119 @@
+/**
+ * blenlib/BKE_imagebuffer.h
+ *	
+ * $Id: BKE_imagebuffer.h 15647 2008-07-20 04:39:35Z joeedh $ 
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 BKE_IMAGEBUFFER_H
+#define BKE_IMAGEBUFFER_H
+
+#define USEIMAGEBUFFER	0
+
+#if USEIMAGEBUFFER
+
+#include "BKE_tile.h"
+
+typedef struct TCS_ImageTile {
+	TCS_Tile tile;
+	union {
+		char *c;
+		float *f;
+	} data;
+	int sizex, sizey;
+	int x, y, type, totchannels;
+} TCS_ImageTile;
+
+typedef struct TCS_Image {
+	TCS_TileBuffer buffer;
+	int sizex, sizey;
+	int tilex, tiley;
+	
+	short flags, type;
+	int totchannels;
+	
+	TCS_ImageTile *tilerect;
+} TCS_Image;
+
+/*image types*/
+#define IMAGE_FLOAT	0
+#define IMAGE_BYTE	1
+
+#define TCSIMAGE_MAX_TILESIZE	64
+#define TCSIMAGE_MAX_TOTCHANNELS	4
+#define TCSIMAGE_MAXMEM			75*1024*1024
+
+/*note: initcolor is allowed to be NuLL*/
+TCS_Image *TCSImage_newImage(int sizex, int sizey, int type, int totchannels, 
+                            void *initcolor);
+
+void TCSImage_getPixelf(TCS_Image *img, int x, int y, float *dst_pixel);
+void TCSImage_getPixelub(TCS_Image *img, int x, int y, char *dst_pixel);
+
+void TCSImage_setPixelf(TCS_Image *img, int x, int y, float *src_pixel);
+void TCSImage_setPixelub(TCS_Image *img, int x, int y, char *src_pixel);
+
+/*note, this can't (by it's nature) lock the tile automatically the way the previous
+  two functions can (there's no point) */
+void *TCSImage_getPixel(TCS_Image *img, int x, int y);
+
+/*ok, as much as possible try to use the pixel processor functions, which
+  loops over every pixel in an image and calls a function on these,
+  since they'll automatically do float<->byte conversions for you.
+  
+  also, the processor functions themselves always work in floats*/
+ 
+/*x and y are pixel positions in normalized 0.0 ... 1.0 space.
+  note that fac is always provided. 
+  
+  in is the input pixel, out is the output.  note that out is *not*
+  zeroed, so it may have garbage in it.  totchannels is the number of
+  channels this pixel has.*/
+typedef void (*PixelProc)(float *in, float *out, float *fac, float x, float y, int totchannels);
+
+/*note: fac can be NULL, in which case defaultfac is passed in.  otherwise, defaultfac has 
+        no meaning.*/        
+void TCSImage_Pixel_Processor(TCS_Image *image, TCS_Image *fac, float defaultfac, 
+                                PixelProc proc, int totchannels);
+
+void TCSImage_Scale(TCS_Image *image, int newwidth, int newheight, int scalemode);
+#define SCALEMODE_NORMAL	0
+#define SCALEMODE_FAST		1
+
+void TCSImage_Mix(TCS_Image *dst, TCS_Image *src, TCS_Image *fac, 
+                  float facscale, int mode);
+void TCSImage_AlphaOver(TCS_Image *dst, TCS_Image *src, TCS_Image *fac, 
+                        float facscale, int convertpremul);
+
+/*converts the image stored in *img to the desired type and number of totchannels,
+  if necassary, initializing alpha to defaultalpha as necassary.*/
+void TCSImage_Convert(TCS_Image *img, int type, int totchannels, float defaultalpha);
+
+/*makes a copy of an image*/
+TCS_Image *TCSImage_Copy(TCS_Image *img);
+
+#endif /* BKE_IMAGEBUFFER_H */
+#endif

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c	2008-08-20 21:34:49 UTC (rev 16200)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c	2008-08-21 07:59:18 UTC (rev 16201)
@@ -273,6 +273,7 @@
 			
 			TCS_AddToPool(pool, tile);
 		}
+		TCS_RunCacher(pool);
 	}
 
 	return (TCS_TileBuffer*) buf;

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c	2008-08-20 21:34:49 UTC (rev 16200)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c	2008-08-21 07:59:18 UTC (rev 16201)
@@ -104,7 +104,7 @@
 
 	tile->pool->memused -= tile->struct_overhead;
 	
-	/*add tile's file position to tile if in fixed tilesize mode.*/
+	/*add tile's file position to the pool if in fixed tilesize mode.*/
 	if (tile->pool->flag & TCS_POOL_TSIZEFIXED) {
 		TCS_FileTileRef *ref = MEM_callocN(sizeof(TCS_POOL_TSIZEFIXED), "TCS_POOL_TSIZEFIXED");
 		ref->file = tile->file;
@@ -554,8 +554,8 @@
 			TCS_fwrite(&tile->compressed_memfile->length, sizeof(unsigned long), 1, tile->file);
 			TCS_fwrite(tile->compressed_memfile->ptr, tile->compressed_memfile->length, 1, tile->file);
 			
-			/*if TCS_POOL_TSIZEFIXED is set, then we have to ensure the entire uncompressed
-			  tile region on the disk is reserved, even if it's not used.*/
+			/*if TCS_POOL_TSIZEFIXED is set, then we have to ensure all the diskspace up to
+			  pool->tilesize (the maxumum tile size in bytes) is in use.*/
 			if (pool->flag & TCS_POOL_TSIZEFIXED) {
 				int diff = pool->tilesize - tile->compressed_memfile->length;
 				int i, zero=0;

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_image.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_image.c	2008-08-20 21:34:49 UTC (rev 16200)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_image.c	2008-08-21 07:59:18 UTC (rev 16201)
@@ -24,6 +24,352 @@
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
 
+#include "BKE_imagebuffer.h"
+#include "MEM_guardedalloc.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#if USEIMAGEBUFFER
+
+static TCS_TilePool *img_float_pool = NULL;
+static TCS_TilePool *img_byte_pool = NULL;
+
+static void tcsimage_pools_check(void)
+{
+	if (img_float_pool == NULL) 
+		img_float_pool = TCS_MakeFixedPool(TCSIMAGE_MAXMEM, "float_image_cache", 
+		    TCSIMAGE_MAX_TILESIZE*TCSIMAGE_MAX_TILESIZE*sizeof(float)*TCSIMAGE_MAX_TOTCHANNELS);
+
+	if (img_byte_pool == NULL) 
+		img_byte_pool = TCS_MakeFixedPool(TCSIMAGE_MAXMEM, "byte_image_cache", 
+		    TCSIMAGE_MAX_TILESIZE*TCSIMAGE_MAX_TILESIZE*TCSIMAGE_MAX_TOTCHANNELS);
+}
+
+static int tilesize_table[2] = {sizeof(float), 1};
+
+static void tcs_imagetile_loadfromcache(TCS_Tile *self, TCS_File *file) {
+	TCS_ImageTile *tile = (TCS_ImageTile*) self;
+	tile->data.c = MEM_mallocN(tilesize_table[tile->type]*tile->sizex*tile->sizey*tile->totchannels, "image tile");
+	TCS_fread(tile->data.c, tilesize_table[tile->type], tile->sizex*tile->sizey*tile->totchannels, file);
+}
+
+static unsigned int tcs_imagetile_savetocache(TCS_Tile *self, TCS_File *file, unsigned long current_position)
+{
+	TCS_ImageTile *tile = (TCS_ImageTile*) self;
+	TCS_fwrite(tile->data.c, tilesize_table[tile->type], tile->sizex*tile->sizey*tile->totchannels, file);
+	return tilesize_table[tile->type]*tile->sizex*tile->sizey*tile->totchannels;
+}
+
+static void tcs_imagetile_freedata(TCS_Tile *self)
+{
+	TCS_ImageTile *tile = (TCS_ImageTile*) self;
+	MEM_freeN(tile->data.c);
+	tile->data.c = NULL;
+}
+
+static unsigned int tcs_imagetile_getlen(TCS_Tile *self)
+{
+	TCS_ImageTile *tile = (TCS_ImageTile*) self;
+	return tilesize_table[tile->type]*tile->sizex*tile->sizey*tile->totchannels;
+}
+	
+TCS_TileType imagetile_type = {
+	tcs_imagetile_loadfromcache,
+	tcs_imagetile_savetocache,
+	tcs_imagetile_freedata,
+	tcs_imagetile_getlen
+};
+
+/*only frees direct data*/
+static void tcsimage_freebuffer(TCS_TileBuffer *self)
+{
+	TCS_Image *img = (TCS_Image*) self;
+	int x, y;
+	
+	for (x=0; x<img->tilex; x++) {
+		for (y=0; y<img->tiley; y++) {
+			TCS_UnlinkTile(&img->tilerect[y*img->tilex+x]);
+			MEM_freeN(img->tilerect[y*img->tilex+x].data.c);
+		}
+	}
+	MEM_freeN(img->tilerect);
+}
+
+static void *tcsimage_get_tile(TCS_TileBuffer *self, int x, int y, int z)
+{
+	TCS_Image *img = (TCS_Image*) self;
+	
+	return &img->tilerect[y*img->tilex+x];
+}
+
+static int tcsimage_get_tile_size(TCS_TileBuffer *self)
+{
+	return TCSIMAGE_MAX_TILESIZE;
+}
+
+static int tcsimage_get_sizex(TCS_TileBuffer *self)
+{
+	TCS_Image *img = (TCS_Image*) self;
+	
+	return img->sizex;
+}
+
+static int tcsimage_get_sizey(TCS_TileBuffer *self)
+{
+	TCS_Image *img = (TCS_Image*) self;
+	
+	return img->sizey;
+}
+
+TCS_TileBuffer TCSImageBufferType = {
+	NULL, NULL,
+	NULL,
+	tcsimage_freebuffer,
+	tcsimage_get_tile,
+	tcsimage_get_tile_size,
+	tcsimage_get_tile_size,
+	tcsimage_get_sizex,
+	tcsimage_get_sizey,
+	0,
+	NULL
+};
+
+TCS_TilePool **pools_table[2] = {&img_float_pool, &img_byte_pool};
+
+/*note: initcolor is allowed to be NuLL*/
+TCS_Image *TCSImage_newImage(int sizex, int sizey, int type, int totchannels, void *initcolor)
+{
+	TCS_Image *img = MEM_callocN(sizeof(TCS_Image), "TCS_Image");
+	TCS_ImageTile *tile;
+	float fac;
+	int x, y, a;
+	
+	img->sizex = sizex;
+	img->sizey = sizey;
+	img->tilex = sizex / TCSIMAGE_MAX_TILESIZE;
+	img->tiley = sizey / TCSIMAGE_MAX_TILESIZE;
+	img->type = type;
+	img->totchannels = totchannels;
+	TCS_InitBuffer(&TCSImageBufferType, img);
+	
+	tcsimage_pools_check();
+	img->buffer.pool = *pools_table[type];
+	
+	if (totchannels > TCSIMAGE_MAX_TOTCHANNELS) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list