/* Cockos WDL - LICE - Lightweight Image Compositing Engine Copyright (C) 2007 and later, Cockos Incorporated File: lice_texgen.cpp (LICE texture generator routines) See lice.h for license and other information */ #ifndef WDL_NO_DEFINE_MINMAX #define WDL_NO_DEFINE_MINMAX #endif #include "lice.h" #include void LICE_TexGen_Marble(LICE_IBitmap *dest, const RECT *rect, float rv, float gv, float bv, float intensity) { int span=dest->getRowSpan(); int w = dest->getWidth(); int h = dest->getHeight(); int x = 0; int y = 0; if(rect) { x = rect->left; y = rect->top; w = rect->right - rect->left; h = rect->bottom - rect->top; } if (x<0) { w+=x; x=0; } if (y<0) { h+=y; y=0; } const int destbm_w = dest->getWidth(), destbm_h = dest->getHeight(); if (w<1 || h < 1 || x >= destbm_w || y >= destbm_h) return; if (w>destbm_w-x) w=destbm_w-x; if (h>destbm_h-y) h=destbm_h-y; LICE_pixel *startp = dest->getBits(); if (dest->isFlipped()) { startp += x + (dest->getHeight()-1-y)*span; span=-span; } else startp += x + y*span; //simple 16bit marble noise generator #define ROL(x,y) ((x<<(y))|(((unsigned short)x)>>(16-(y)))) #define ROR(x,y) ((((unsigned short)x)>>(y))|(x<<(16-(y)))) intensity/=1024.0f; int maxc = 0; { LICE_pixel *p = startp; short n1 = 0, n2 = 0; for(int i=0;i0) { c = p[j-span]; if(j==0) c2 = p[(w-1)-span]; else c2 = p[(j-1)-span]; } int pix = (((c + c2)/2) + val); if(pix>maxc) maxc = pix; p[j] = pix; } p+=span; } } //normalize values and apply gamma { LICE_pixel *p = startp; float sc=255.0f/maxc; for(int i=0;igetRowSpan(); int w = dest->getWidth(); int h = dest->getHeight(); int dx = 0; int dy = 0; if(rect) { dx = rect->left; dy = rect->top; w = rect->right - rect->left; h = rect->bottom - rect->top; } if (dx<0) { w+=dx; dx=0; } if (dy<0) { h+=dy; dy=0; } const int destbm_w = dest->getWidth(), destbm_h = dest->getHeight(); if (w<1 || h < 1 || dx >= destbm_w || dy >= destbm_h) return; if (w>destbm_w-dx) w=destbm_w-dx; if (h>destbm_h-dy) h=destbm_h-dy; LICE_pixel *startp = dest->getBits(); if (dest->isFlipped()) { startp += dx + (dest->getHeight()-1-dy)*span; span=-span; } else startp += dx + dy*span; { LICE_pixel *p = startp; for(int i=0;i=1) { switch(mode) { case NOISE_MODE_NORMAL: val += noise(x/size, y/size)*size; break; case NOISE_MODE_WOOD: val += (float)cos( x/size + noise(x/size,y/size) )*size/2; break; } size /= 2; } float col = (float)fabs(val/smooth)*255; if(col>255) col=255; p[j] = LICE_RGBA((int)(col*rv),(int)(col*gv),(int)(col*bv),255); } p+=span; } } } static float turbulence(int x, int y, float size, float isize) { float value = 0.0; const float initialSize = isize; while(size >= 1) { value += noise(x * isize, y * isize) * size; size *= 0.5f; isize *= 2.0f; } return(128.0f * value * initialSize); } void LICE_TexGen_CircNoise(LICE_IBitmap *dest, const RECT *rect, float rv, float gv, float bv, float nrings, float power, int size) { initNoise(); int span=dest->getRowSpan(); int w = dest->getWidth(); int h = dest->getHeight(); int x = 0; int y = 0; if(rect) { x = rect->left; y = rect->top; w = rect->right - rect->left; h = rect->bottom - rect->top; } if (x<0) { w+=x; x=0; } if (y<0) { h+=y; y=0; } const int destbm_w = dest->getWidth(), destbm_h = dest->getHeight(); if (w<1 || h < 1 || x >= destbm_w || y >= destbm_h) return; if (w>destbm_w-x) w=destbm_w-x; if (h>destbm_h-y) h=destbm_h-y; LICE_pixel *startp = dest->getBits(); if (dest->isFlipped()) { startp += x + (dest->getHeight()-1-y)*span; span=-span; } else startp += x + y*span; float xyPeriod = nrings; float turbPower = power; const float iturbSize = 1.0f/(float)size; const float turbSize = (float)size; { LICE_pixel *p = startp; for(int i=0;i