Fill a 2D 8-bit buffer with noise, using inoise8() @param pData the array of data to fill with noise values @param width the width of the 2D buffer @param height the height of the 2D buffer @param octaves the number of octaves to use for noise. More octaves = more noise. @param freq44 starting octave frequency @param amplitude noise amplitude @param skip how many noise maps to skip over, increment
| 716 | /// @param time the time position for the noise field |
| 717 | /// @todo Why isn't this declared in the header (noise.h)? |
| 718 | void fill_raw_2dnoise8(fl::u8 *pData, int width, int height, fl::u8 octaves, fl::q44 freq44, fract8 amplitude, int skip, fl::u16 x, fl::i16 scalex, fl::u16 y, fl::i16 scaley, fl::u16 time) { |
| 719 | if(octaves > 1) { |
| 720 | fill_raw_2dnoise8(pData, width, height, octaves-1, freq44, amplitude, skip+1, x*freq44, freq44 * scalex, y*freq44, freq44 * scaley, time); |
| 721 | } else { |
| 722 | // amplitude is always 255 on the lowest level |
| 723 | amplitude=255; |
| 724 | } |
| 725 | |
| 726 | scalex *= skip; |
| 727 | scaley *= skip; |
| 728 | |
| 729 | fract8 invamp = 255-amplitude; |
| 730 | fl::u16 xx = x; |
| 731 | for(int i = 0; i < height; ++i, y+=scaley) { |
| 732 | fl::u8 *pRow = pData + (i*width); |
| 733 | xx = x; |
| 734 | for(int j = 0; j < width; ++j, xx+=scalex) { |
| 735 | fl::u8 noise_base = inoise8(xx,y,time); |
| 736 | noise_base = (0x80 & noise_base) ? (noise_base - 127) : (127 - noise_base); |
| 737 | noise_base = scale8(noise_base<<1,amplitude); |
| 738 | if(skip == 1) { |
| 739 | pRow[j] = scale8(pRow[j],invamp) + noise_base; |
| 740 | } else { |
| 741 | for(int ii = i; ii<(i+skip) && ii<height; ++ii) { |
| 742 | fl::u8 *pRow = pData + (ii*width); |
| 743 | for(int jj=j; jj<(j+skip) && jj<width; ++jj) { |
| 744 | pRow[jj] = scale8(pRow[jj],invamp) + noise_base; |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | void fill_raw_2dnoise8(fl::u8 *pData, int width, int height, fl::u8 octaves, fl::u16 x, int scalex, fl::u16 y, int scaley, fl::u16 time) { |
| 753 | fill_raw_2dnoise8(pData, width, height, octaves, fl::q44(2,0), 128, 1, x, scalex, y, scaley, time); |
no test coverage detected