0.4.1.3 Beta 10/14/2014

--User Changes
 Size is no longer fixed to the window size.
 Size scaling is done differently in the final render dialog. This fixes several bugs.
 Remove Xml saving size from settings and options dialog, it no longer applies.
 Final render can be broken into strips.
 Set default save path to the desktop if none is found in the settings file.
 Set default output size to 1920x1080 if none is found in the settings file.

--Bug Fixes
 Better memory size reporting in final render dialog.

--Code Changes
 Migrate to C++11, Qt 5.3.1, and Visual Studio 2013.
 Change most instances of unsigned int to size_t, and int to intmax_t.
 Add m_OrigPixPerUnit and m_ScaleType to Ember for scaling purposes.
 Replace some sprintf_s() calls in XmlToEmber with ostringstream.
 Move more non-templated members into RendererBase.
 Add CopyVec() overload that takes a per element function pointer.
 Add vector Memset().
 Replace '&' with '+' instead of "&" in XmlToEmber for much faster parsing.
 Break strips rendering out into EmberCommon and call from EmberRender and Fractorium.
 Make AddAndWriteBuffer() just call WriteBuffer().
 Make AddAndWriteImage() delete the existing image first before replacing it.
 Add SetOutputTexture() to RendererCL to support making new textures in response to resize events.
 Remove multiple return statements in RendererCL, and replace with a bool that tracks results.
 Add ToDouble(), MakeEnd(), ToString() and Exists() wrappers in Fractorium.
 Add Size() wrapper in EmberFile.
 Make QString function arguments const QString&, and string with const string&.
 Make ShowCritical() wrapper for invoking a message box from another thread.
 Add combo box to TwoButtonWidget and rename.
This commit is contained in:
mfeemster
2014-10-14 08:53:15 -07:00
parent 44c90abb32
commit 9e94170a70
80 changed files with 4358 additions and 3661 deletions

View File

@ -108,7 +108,7 @@ static bool ParseEmberFile(XmlToEmber<T>& parser, string filename, vector<Ember<
/// <param name="filename">The full path and name of the file</param>
/// <returns>True if success, else false.</returns>
template <typename T>
static bool InitPaletteList(string filename)
static bool InitPaletteList(const string& filename)
{
PaletteList<T> paletteList;//Even though this is local, the members are static so they will remain.
@ -129,7 +129,7 @@ static bool InitPaletteList(string filename)
/// <param name="rgb">The RGB buffer</param>
/// <param name="width">The width of the image in pixels</param>
/// <param name="height">The height of the image in pixels</param>
static void RgbaToRgb(vector<unsigned char>& rgba, vector<unsigned char>& rgb, unsigned int width, unsigned int height)
static void RgbaToRgb(vector<unsigned char>& rgba, vector<unsigned char>& rgb, size_t width, size_t height)
{
rgb.resize(width * height * 3);
@ -143,23 +143,21 @@ static void RgbaToRgb(vector<unsigned char>& rgba, vector<unsigned char>& rgb, u
/// <summary>
/// Calculate the number of strips required if the needed amount of memory
/// is greater than the system memory, or greater than what the user want to allow.
/// is greater than the system memory, or greater than what the user wants to allow.
/// </summary>
/// <param name="mem">Amount of memory required</param>
/// <param name="memAvailable">Amount of memory available on the system</param>
/// <param name="useMem">The maximum amount of memory to use. Use max if 0.</param>
/// <returns>The number of strips to use</returns>
static unsigned int CalcStrips(double mem, double memAvailable, double useMem)
static unsigned int CalcStrips(double memRequired, double memAvailable, double useMem)
{
unsigned int strips;
double memRequired;
if (useMem > 0)
memAvailable = useMem;
else
memAvailable *= 0.8;
memRequired = mem;
if (memAvailable >= memRequired)
return 1;
@ -175,10 +173,11 @@ static unsigned int CalcStrips(double mem, double memAvailable, double useMem)
/// <param name="numerator">The numerator</param>
/// <param name="denominator">The denominator</param>
/// <returns>The next highest divisor if found, else 1.</returns>
static unsigned int NextHighestEvenDiv(unsigned int numerator, unsigned int denominator)
template <typename T>
static T NextHighestEvenDiv(T numerator, T denominator)
{
unsigned int result = 1;
unsigned int numDiv2 = numerator / 2;
T result = 1;
T numDiv2 = numerator / 2;
do
{
@ -202,10 +201,11 @@ static unsigned int NextHighestEvenDiv(unsigned int numerator, unsigned int deno
/// <param name="numerator">The numerator</param>
/// <param name="denominator">The denominator</param>
/// <returns>The next lowest divisor if found, else 1.</returns>
static unsigned int NextLowestEvenDiv(unsigned int numerator, unsigned int denominator)
template <typename T>
static T NextLowestEvenDiv(T numerator, T denominator)
{
unsigned int result = 1;
unsigned int numDiv2 = numerator / 2;
T result = 1;
T numDiv2 = numerator / 2;
denominator--;
@ -242,19 +242,19 @@ template <typename T, typename bucketT>
static Renderer<T, bucketT>* CreateRenderer(eRendererType renderType, unsigned int platform, unsigned int device, bool shared, GLuint texId, EmberReport& errorReport)
{
string s;
auto_ptr<Renderer<T, bucketT>> renderer;
unique_ptr<Renderer<T, bucketT>> renderer;
try
{
if (renderType == CPU_RENDERER)
{
s = "CPU";
renderer = auto_ptr<Renderer<T, bucketT>>(new Renderer<T, bucketT>());
renderer = unique_ptr<Renderer<T, bucketT>>(new Renderer<T, bucketT>());
}
else if (renderType == OPENCL_RENDERER)
{
s = "OpenCL";
renderer = auto_ptr<Renderer<T, bucketT>>(new RendererCL<T>(platform, device, shared, texId));
renderer = unique_ptr<Renderer<T, bucketT>>(new RendererCL<T>(platform, device, shared, texId));
if (!renderer.get() || !renderer->Ok())
{
@ -262,7 +262,7 @@ static Renderer<T, bucketT>* CreateRenderer(eRendererType renderType, unsigned i
errorReport.AddToReport(renderer->ErrorReport());
errorReport.AddToReport("Error initializing OpenCL renderer, using CPU renderer instead.");
renderer = auto_ptr<Renderer<T, bucketT>>(new Renderer<T, bucketT>());
renderer = unique_ptr<Renderer<T, bucketT>>(new Renderer<T, bucketT>());
}
}
}
@ -274,6 +274,116 @@ static Renderer<T, bucketT>* CreateRenderer(eRendererType renderType, unsigned i
return renderer.release();
}
template <typename T>
static bool StripsRender(RendererBase* renderer, Ember<T>& ember, vector<unsigned char>& finalImage, double time, size_t strips, bool yAxisUp,
std::function<void(size_t strip)> perStripStart,
std::function<void(size_t strip)> perStripFinish,
std::function<void(size_t strip)> perStripError,
std::function<void(Ember<T>& finalEmber)> allStripsFinished)
{
bool success = true;
size_t origHeight, realHeight = ember.m_FinalRasH;
T centerY = ember.m_CenterY;
T floatStripH = T(ember.m_FinalRasH) / T(strips);
T zoomScale = pow(T(2), ember.m_Zoom);
T centerBase = centerY - ((strips - 1) * floatStripH) / (2 * ember.m_PixelsPerUnit * zoomScale);
vector<QTIsaac<ISAAC_SIZE, ISAAC_INT>> randVec;
ember.m_Quality *= strips;
ember.m_FinalRasH = (size_t)ceil(floatStripH);
if (strips > 1)
randVec = renderer->RandVec();
for (size_t strip = 0; strip < strips; strip++)
{
size_t stripOffset;
if (yAxisUp)
stripOffset = ember.m_FinalRasH * ((strips - strip) - 1) * renderer->FinalRowSize();
else
stripOffset = ember.m_FinalRasH * strip * renderer->FinalRowSize();
ember.m_CenterY = centerBase + ember.m_FinalRasH * T(strip) / (ember.m_PixelsPerUnit * zoomScale);
if ((ember.m_FinalRasH * (strip + 1)) > realHeight)
{
origHeight = ember.m_FinalRasH;
ember.m_FinalRasH = realHeight - origHeight * strip;
ember.m_CenterY -= (origHeight - ember.m_FinalRasH) * T(0.5) / (ember.m_PixelsPerUnit * zoomScale);
}
ember.m_CenterY;
perStripStart(strip);
if (strips > 1)
{
renderer->RandVec(randVec);//Use the same vector of ISAAC rands for each strip.
renderer->SetEmber(ember);//Set one final time after modifications for strips.
}
if ((renderer->Run(finalImage, time, 0, false, stripOffset) != RENDER_OK) || renderer->Aborted() || finalImage.empty())
{
perStripError(strip);
success = false;
break;
}
else
{
perStripFinish(strip);
}
if (strip == strips - 1)
{
//Restore the ember values to their original values.
if (strips > 1)
{
ember.m_Quality /= strips;
ember.m_FinalRasH = realHeight;
ember.m_CenterY = centerY;
renderer->SetEmber(ember);//Further processing will require the dimensions to match the original ember, so re-assign.
}
allStripsFinished(ember);
}
}
Memset(finalImage);
return success;
}
static size_t VerifyStrips(size_t height, size_t strips,
std::function<void(const string& s)> stripError1,
std::function<void(const string& s)> stripError2,
std::function<void(const string& s)> stripError3)
{
ostringstream os;
if (strips > height)
{
os << "Cannot have more strips than rows: " << strips << " > " << height << ". Setting strips = rows.";
stripError1(os.str()); os.str("");
strips = height;
}
if (height % strips != 0)
{
os << "A strips value of " << strips << " does not divide evenly into a height of " << height << ".";
stripError2(os.str()); os.str("");
strips = NextHighestEvenDiv(height, strips);
if (strips == 1)//No higher divisor, check for a lower one.
strips = NextLowestEvenDiv(height, strips);
os << "Setting strips to " << strips << ".";
stripError3(os.str()); os.str("");
}
return strips;
}
/// <summary>
/// Simple macro to print a string if the --verbose options has been specified.
/// </summary>

View File

@ -12,10 +12,10 @@
/// <param name="width">Width of the image in pixels</param>
/// <param name="height">Height of the image in pixels</param>
/// <returns>True if success, else false</returns>
static bool WritePpm(const char* filename, unsigned char* image, int width, int height)
static bool WritePpm(const char* filename, unsigned char* image, size_t width, size_t height)
{
bool b = false;
unsigned int size = width * height * 3;
size_t size = width * height * 3;
FILE* file;
if (fopen_s(&file, filename, "wb") == 0)
@ -44,7 +44,7 @@ static bool WritePpm(const char* filename, unsigned char* image, int width, int
/// <param name="url">Url of the author</param>
/// <param name="nick">Nickname of the author</param>
/// <returns>True if success, else false</returns>
static bool WriteJpeg(const char* filename, unsigned char* image, unsigned int width, unsigned int height, int quality, bool enableComments, EmberImageComments& comments, string id, string url, string nick)
static bool WriteJpeg(const char* filename, unsigned char* image, size_t width, size_t height, int quality, bool enableComments, EmberImageComments& comments, string id, string url, string nick)
{
bool b = false;
FILE* file;
@ -70,8 +70,8 @@ static bool WriteJpeg(const char* filename, unsigned char* image, unsigned int w
jpeg_stdio_dest(&info, file);
info.in_color_space = JCS_RGB;
info.input_components = 3;
info.image_width = width;
info.image_height = height;
info.image_width = (JDIMENSION)width;
info.image_height = (JDIMENSION)height;
jpeg_set_defaults(&info);
jpeg_set_quality(&info, quality, TRUE);
jpeg_start_compress(&info, TRUE);
@ -135,7 +135,7 @@ static bool WriteJpeg(const char* filename, unsigned char* image, unsigned int w
/// <param name="url">Url of the author</param>
/// <param name="nick">Nickname of the author</param>
/// <returns>True if success, else false</returns>
static bool WritePng(const char* filename, unsigned char* image, unsigned int width, unsigned int height, int bytesPerChannel, bool enableComments, EmberImageComments& comments, string id, string url, string nick)
static bool WritePng(const char* filename, unsigned char* image, size_t width, size_t height, size_t bytesPerChannel, bool enableComments, EmberImageComments& comments, string id, string url, string nick)
{
bool b = false;
FILE* file;
@ -197,7 +197,7 @@ static bool WritePng(const char* filename, unsigned char* image, unsigned int wi
png_init_io(png_ptr, file);
png_set_IHDR(png_ptr, info_ptr, width, height, 8 * bytesPerChannel,
png_set_IHDR(png_ptr, info_ptr, (png_uint_32)width, (png_uint_32)height, 8 * (png_uint_32)bytesPerChannel,
PNG_COLOR_TYPE_RGBA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE,
@ -232,17 +232,17 @@ static bool WritePng(const char* filename, unsigned char* image, unsigned int wi
/// <param name="height">The height.</param>
/// <param name="newSize">The size of the new buffer created</param>
/// <returns>The converted buffer if successful, else NULL.</returns>
static BYTE* ConvertRGBToBMPBuffer(BYTE* buffer, int width, int height, long& newSize)
static BYTE* ConvertRGBToBMPBuffer(BYTE* buffer, size_t width, size_t height, size_t& newSize)
{
if (NULL == buffer || width == 0 || height == 0)
return NULL;
int padding = 0;
int scanlinebytes = width * 3;
size_t padding = 0;
size_t scanlinebytes = width * 3;
while ((scanlinebytes + padding ) % 4 != 0)
padding++;
int psw = scanlinebytes + padding;
size_t psw = scanlinebytes + padding;
newSize = height * psw;
BYTE* newBuf = new BYTE[newSize];
@ -251,12 +251,12 @@ static BYTE* ConvertRGBToBMPBuffer(BYTE* buffer, int width, int height, long& ne
{
memset (newBuf, 0, newSize);
long bufpos = 0;
long newpos = 0;
size_t bufpos = 0;
size_t newpos = 0;
for (int y = 0; y < height; y++)
for (size_t y = 0; y < height; y++)
{
for (int x = 0; x < 3 * width; x += 3)
for (size_t x = 0; x < 3 * width; x += 3)
{
bufpos = y * 3 * width + x; // position in original buffer
newpos = (height - y - 1) * psw + x; // position in padded buffer
@ -286,11 +286,11 @@ static BYTE* ConvertRGBToBMPBuffer(BYTE* buffer, int width, int height, long& ne
/// <param name="height">Height of the image in pixels</param>
/// <param name="paddedSize">Padded size, greater than or equal to total image size.</param>
/// <returns>True if success, else false</returns>
static bool SaveBmp(const char* filename, BYTE* image, int width, int height, long paddedSize)
static bool SaveBmp(const char* filename, BYTE* image, size_t width, size_t height, size_t paddedSize)
{
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER info;
unsigned long bwritten;
DWORD bwritten;
HANDLE file;
memset (&bmfh, 0, sizeof (BITMAPFILEHEADER));
memset (&info, 0, sizeof (BITMAPINFOHEADER));
@ -298,12 +298,12 @@ static bool SaveBmp(const char* filename, BYTE* image, int width, int height, lo
bmfh.bfType = 0x4d42; // 0x4d42 = 'BM'
bmfh.bfReserved1 = 0;
bmfh.bfReserved2 = 0;
bmfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + paddedSize;
bmfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (DWORD)paddedSize;
bmfh.bfOffBits = 0x36;
info.biSize = sizeof(BITMAPINFOHEADER);
info.biWidth = width;
info.biHeight = height;
info.biWidth = (LONG)width;
info.biHeight = (LONG)height;
info.biPlanes = 1;
info.biBitCount = 24;
info.biCompression = BI_RGB;
@ -331,7 +331,7 @@ static bool SaveBmp(const char* filename, BYTE* image, int width, int height, lo
return false;
}
if (WriteFile(file, image, paddedSize, &bwritten, NULL) == false)
if (WriteFile(file, image, (DWORD)paddedSize, &bwritten, NULL) == false)
{
CloseHandle(file);
return false;
@ -349,10 +349,10 @@ static bool SaveBmp(const char* filename, BYTE* image, int width, int height, lo
/// <param name="width">Width of the image in pixels</param>
/// <param name="height">Height of the image in pixels</param>
/// <returns>True if success, else false</returns>
static bool WriteBmp(const char* filename, unsigned char* image, int width, int height)
static bool WriteBmp(const char* filename, unsigned char* image, size_t width, size_t height)
{
bool b = false;
long newSize;
size_t newSize;
auto_ptr<BYTE> bgrBuf(ConvertRGBToBMPBuffer(image, width, height, newSize));
if (bgrBuf.get())