From 91bddf2b13c61644d60ce909123068609769fbf0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 13 May 2011 04:53:20 +0000 Subject: remove imbuf crect and profile_filename when building without LCMS --- source/blender/imbuf/CMakeLists.txt | 4 ++++ source/blender/imbuf/IMB_imbuf_types.h | 9 ++++++--- source/blender/imbuf/SConscript | 3 +++ source/blender/imbuf/intern/allocimbuf.c | 10 ++++++---- 4 files changed, 19 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt index 6404ae3de75..24f04098d0c 100644 --- a/source/blender/imbuf/CMakeLists.txt +++ b/source/blender/imbuf/CMakeLists.txt @@ -146,4 +146,8 @@ if(WITH_IMAGE_HDR) add_definitions(-DWITH_HDR) endif() +if(WITH_LCMS) + add_definitions(-DWITH_LCMS) +endif() + blender_add_lib(bf_imbuf "${SRC}" "${INC}") diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h index 81512adf065..52afe2ed854 100644 --- a/source/blender/imbuf/IMB_imbuf_types.h +++ b/source/blender/imbuf/IMB_imbuf_types.h @@ -84,11 +84,15 @@ typedef struct ImBuf { /* pixels */ unsigned int *rect; /* pixel values stored here */ - unsigned int *crect; /* color corrected pixel values stored here */ float *rect_float; /* floating point Rect equivalent Linear RGB color space - may need gamma correction to sRGB when generating 8bit representations */ - + +#ifdef WITH_LCMS + unsigned int *crect; /* color corrected pixel values stored here */ + char profile_filename[256]; /* to be implemented properly, specific filename for custom profiles */ +#endif + /* tiled pixel storage */ int tilex, tiley; int xtiles, ytiles; @@ -101,7 +105,6 @@ typedef struct ImBuf { /* parameters used by conversion between byte and float */ float dither; /* random dither value, for conversion from float -> byte rect */ short profile; /* color space/profile preset that the byte rect buffer represents */ - char profile_filename[256]; /* to be implemented properly, specific filename for custom profiles */ /* mipmapping */ struct ImBuf *mipmap[IB_MIPMAP_LEVELS]; /* MipMap levels, a series of halved images */ diff --git a/source/blender/imbuf/SConscript b/source/blender/imbuf/SConscript index ecb9a89c274..59b938c3373 100644 --- a/source/blender/imbuf/SConscript +++ b/source/blender/imbuf/SConscript @@ -48,4 +48,7 @@ if env['WITH_BF_QUICKTIME']: incs += ' ../quicktime ' + env['BF_QUICKTIME_INC'] defs.append('WITH_QUICKTIME') +if env['WITH_BF_LCMS']: + defs.append('WITH_LCMS') + env.BlenderLib ( libname = 'bf_imbuf', sources = sources, includes = Split(incs), defines = defs, libtype=['core','player'], priority = [185,115] ) diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index a8b9e21331d..efa37aa1196 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -84,17 +84,19 @@ void imb_freerectfloatImBuf(ImBuf *ibuf) void imb_freerectImBuf(ImBuf *ibuf) { if(ibuf==NULL) return; - + +#ifdef WITH_LCMS if(ibuf->crect) MEM_freeN(ibuf->crect); + ibuf->crect= NULL; +#endif if(ibuf->rect && (ibuf->mall & IB_rect)) MEM_freeN(ibuf->rect); + ibuf->rect= NULL; imb_freemipmapImBuf(ibuf); - - ibuf->rect= NULL; - ibuf->crect= NULL; + ibuf->mall &= ~IB_rect; } -- cgit v1.2.3 From 05d004fd14876d9df0ca1028f77bebcad1580eff Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 13 May 2011 14:27:12 +0000 Subject: support for reading/writing image resolution (dpi), for PNG and TIFF, only RNA access currently 'image.resolution'. --- source/blender/imbuf/IMB_imbuf_types.h | 3 +++ source/blender/imbuf/intern/allocimbuf.c | 1 + source/blender/imbuf/intern/png.c | 18 +++++++++++++- source/blender/imbuf/intern/tiff.c | 39 +++++++++++++++++++++++++++--- source/blender/makesrna/intern/rna_image.c | 36 +++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h index 52afe2ed854..5717a92db54 100644 --- a/source/blender/imbuf/IMB_imbuf_types.h +++ b/source/blender/imbuf/IMB_imbuf_types.h @@ -93,6 +93,9 @@ typedef struct ImBuf { char profile_filename[256]; /* to be implemented properly, specific filename for custom profiles */ #endif + /* resolution - pixels per meter */ + double ppm[2]; + /* tiled pixel storage */ int tilex, tiley; int xtiles, ytiles; diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index efa37aa1196..91583f02a49 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -348,6 +348,7 @@ ImBuf *IMB_allocImBuf(unsigned int x, unsigned int y, uchar d, unsigned int flag ibuf->depth= d; ibuf->ftype= TGA; ibuf->channels= 4; /* float option, is set to other values when buffers get assigned */ + ibuf->ppm[0]= ibuf->ppm[1]= 150.0 / 0.0254; /* 150dpi -> pixels-per-meter */ if(flags & IB_rect) { if(imb_addrectImBuf(ibuf)==FALSE) { diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 200ff0af9af..6b6dcdb88af 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -257,6 +257,10 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) } + if(ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) { + png_set_pHYs(png_ptr, info_ptr, (unsigned int)(ibuf->ppm[0] + 0.5), (unsigned int)(ibuf->ppm[1] + 0.5), PNG_RESOLUTION_METER); + } + // write the file header information png_write_info(png_ptr, info_ptr); @@ -384,7 +388,19 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags) if (ibuf) { ibuf->ftype = PNG; ibuf->profile = IB_PROFILE_SRGB; - } else { + + if (png_get_valid (png_ptr, info_ptr, PNG_INFO_pHYs)) { + int unit_type; + unsigned int xres, yres; + + if(png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type)) + if(unit_type == PNG_RESOLUTION_METER) { + ibuf->ppm[0]= xres; + ibuf->ppm[1]= yres; + } + } + } + else { printf("Couldn't allocate memory for PNG image\n"); } diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c index 67d20d56466..36130aa0dbf 100644 --- a/source/blender/imbuf/intern/tiff.c +++ b/source/blender/imbuf/intern/tiff.c @@ -354,6 +354,25 @@ static void scanline_separate_32bit(float *rectf, float *fbuf, int scanline_w, i rectf[i*4 + chan] = fbuf[i]; } +static void imb_read_tiff_resolution(ImBuf *ibuf, TIFF *image) +{ + uint16 unit; + float xres; + float yres; + + TIFFGetFieldDefaulted(image, TIFFTAG_RESOLUTIONUNIT, &unit); + TIFFGetFieldDefaulted(image, TIFFTAG_XRESOLUTION, &xres); + TIFFGetFieldDefaulted(image, TIFFTAG_YRESOLUTION, &yres); + + if(unit == RESUNIT_CENTIMETER) { + ibuf->ppm[0]= (double)xres * 100.0; + ibuf->ppm[1]= (double)yres * 100.0; + } + else { + ibuf->ppm[0]= (double)xres / 0.0254; + ibuf->ppm[1]= (double)yres / 0.0254; + } +} /* * Use the libTIFF scanline API to read a TIFF image. @@ -369,10 +388,13 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul) int ib_flag=0, row, chan; float *fbuf=NULL; unsigned short *sbuf=NULL; - + TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bitspersample); TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp); /* number of 'channels' */ TIFFGetField(image, TIFFTAG_PLANARCONFIG, &config); + + imb_read_tiff_resolution(ibuf, image); + scanline = TIFFScanlineSize(image); if (bitspersample == 32) { @@ -658,6 +680,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) unsigned char *from = NULL, *to = NULL; unsigned short *pixels16 = NULL, *to16 = NULL; float *fromf = NULL; + float xres, yres; int x, y, from_i, to_i, i; int extraSampleTypes[1] = { EXTRASAMPLE_ASSOCALPHA }; @@ -783,8 +806,18 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE); TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB); TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); - TIFFSetField(image, TIFFTAG_XRESOLUTION, 150.0); - TIFFSetField(image, TIFFTAG_YRESOLUTION, 150.0); + + + if(ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) { + xres= (float)(ibuf->ppm[0] * 0.0254); + yres= (float)(ibuf->ppm[1] * 0.0254); + } + else { + xres= yres= 150.0f; + } + + TIFFSetField(image, TIFFTAG_XRESOLUTION, xres); + TIFFSetField(image, TIFFTAG_YRESOLUTION, yres); TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); if(TIFFWriteEncodedStrip(image, 0, (bitspersample == 16)? (unsigned char*)pixels16: pixels, diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index 5872542d10a..3db90c2de0e 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -221,6 +221,39 @@ static void rna_Image_size_get(PointerRNA *ptr,int *values) BKE_image_release_ibuf(im, lock); } +static void rna_Image_resolution_get(PointerRNA *ptr, float *values) +{ + Image *im= (Image*)ptr->data; + ImBuf *ibuf; + void *lock; + + ibuf = BKE_image_acquire_ibuf(im, NULL , &lock); + if (ibuf) { + values[0]= ibuf->ppm[0]; + values[1]= ibuf->ppm[1]; + } + else { + values[0]= 0; + values[1]= 0; + } + + BKE_image_release_ibuf(im, lock); +} + +static void rna_Image_resolution_set(PointerRNA *ptr, const float *values) +{ + Image *im= (Image*)ptr->data; + ImBuf *ibuf; + void *lock; + + ibuf = BKE_image_acquire_ibuf(im, NULL , &lock); + if (ibuf) { + ibuf->ppm[0]= values[0]; + ibuf->ppm[1]= values[1]; + } + + BKE_image_release_ibuf(im, lock); +} static int rna_Image_depth_get(PointerRNA *ptr) { @@ -557,6 +590,9 @@ static void rna_def_image(BlenderRNA *brna) RNA_def_property_int_funcs(prop, "rna_Image_size_get" , NULL, NULL); RNA_def_property_clear_flag(prop, PROP_EDITABLE); + prop= RNA_def_float_vector(srna, "resolution" , 2 , NULL , 0, 0, "Resolution" , "X/Y pixels per meter" , 0 , 0); + RNA_def_property_float_funcs(prop, "rna_Image_resolution_get" , "rna_Image_resolution_set", NULL); + prop= RNA_def_property(srna, "pixels", PROP_FLOAT, PROP_NONE); RNA_def_property_flag(prop, PROP_DYNAMIC); RNA_def_property_multi_array(prop, 1, NULL); -- cgit v1.2.3 From 62cd927f57b94292139348b0a803288e8eafe850 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 13 May 2011 16:04:20 +0000 Subject: made BLI_edgefill returns the list length since some callers count directly after, also remove 2 unused flags from ScFillVert struct. --- source/blender/blenkernel/intern/displist.c | 11 +---------- source/blender/blenlib/BLI_scanfill.h | 2 +- source/blender/blenlib/intern/scanfill.c | 21 ++++++++++++--------- 3 files changed, 14 insertions(+), 20 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index a8351e0bb1b..54e4bf08ee7 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -981,16 +981,7 @@ void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal) dl= dl->next; } - if(totvert && BLI_edgefill(0)) { // XXX (obedit && obedit->actcol)?(obedit->actcol-1):0)) { - - /* count faces */ - tot= 0; - efa= fillfacebase.first; - while(efa) { - tot++; - efa= efa->next; - } - + if(totvert && (tot= BLI_edgefill(0))) { // XXX (obedit && obedit->actcol)?(obedit->actcol-1):0)) { if(tot) { dlnew= MEM_callocN(sizeof(DispList), "filldisplist"); dlnew->type= DL_INDEX3; diff --git a/source/blender/blenlib/BLI_scanfill.h b/source/blender/blenlib/BLI_scanfill.h index e2f102c20eb..c5acf7b7f70 100644 --- a/source/blender/blenlib/BLI_scanfill.h +++ b/source/blender/blenlib/BLI_scanfill.h @@ -53,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 mat_nr); +int BLI_edgefill(short mat_nr); void BLI_end_edgefill(void); /* These callbacks are needed to make the lib finction properly */ diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 423b9b99569..47a07d86e66 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -85,7 +85,6 @@ typedef struct PolyFill { typedef struct ScFillVert { EditVert *v1; EditEdge *first,*last; - short f,f1; } ScFillVert; @@ -95,9 +94,9 @@ typedef struct ScFillVert { static ScFillVert *scdata; -ListBase fillvertbase = {0,0}; -ListBase filledgebase = {0,0}; -ListBase fillfacebase = {0,0}; +ListBase fillvertbase = {NULL, NULL}; +ListBase filledgebase = {NULL, NULL}; +ListBase fillfacebase = {NULL, NULL}; static short cox, coy; @@ -219,7 +218,7 @@ EditEdge *BLI_addfilledge(EditVert *v1, EditVert *v2) return newed; } -static void addfillface(EditVert *v1, EditVert *v2, EditVert *v3, int mat_nr) +static void addfillface(EditVert *v1, EditVert *v2, EditVert *v3, short mat_nr) { /* does not make edges */ EditFace *evl; @@ -495,7 +494,7 @@ static void splitlist(ListBase *tempve, ListBase *temped, short nr) } -static void scanfill(PolyFill *pf, int mat_nr) +static int scanfill(PolyFill *pf, short mat_nr) { ScFillVert *sc = NULL, *sc1; EditVert *eve,*v1,*v2,*v3; @@ -748,11 +747,13 @@ static void scanfill(PolyFill *pf, int mat_nr) } MEM_freeN(scdata); + + return totface; } -int BLI_edgefill(int mat_nr) +int BLI_edgefill(short mat_nr) { /* - fill works with its own lists, so create that first (no faces!) @@ -760,6 +761,7 @@ int BLI_edgefill(int mat_nr) - struct elements xs en ys are not used here: don't hide stuff in it - edge flag ->f becomes 2 when it's a new edge - mode: & 1 is check for crossings, then create edges (TO DO ) + - returns number of triangle faces added. */ ListBase tempve, temped; EditVert *eve; @@ -767,6 +769,7 @@ int BLI_edgefill(int mat_nr) PolyFill *pflist,*pf; float *minp, *maxp, *v1, *v2, norm[3], len; short a,c,poly=0,ok=0,toggle=0; + int totfaces= 0; /* total faces added */ /* reset variables */ eve= fillvertbase.first; @@ -1030,7 +1033,7 @@ int BLI_edgefill(int mat_nr) for(a=0;aedges>1) { splitlist(&tempve,&temped,pf->nr); - scanfill(pf, mat_nr); + totfaces += scanfill(pf, mat_nr); } pf++; } @@ -1040,6 +1043,6 @@ int BLI_edgefill(int mat_nr) /* FREE */ MEM_freeN(pflist); - return 1; + return totfaces; } -- cgit v1.2.3