From 85155bfaa190dd49477b48296e3865115bad8e2e Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 3 Apr 2006 13:45:47 +0000 Subject: [PATCH] PRS encoder optimization fixed Originally committed to SVN as r293. --- core/subtitle_format_prs.cpp | 23 ++++++++++++----------- prs/png_wrap.cpp | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/subtitle_format_prs.cpp b/core/subtitle_format_prs.cpp index 96b20599f..473c27af4 100644 --- a/core/subtitle_format_prs.cpp +++ b/core/subtitle_format_prs.cpp @@ -166,7 +166,7 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) { if (!curImage.Ok()) continue; // Optimize image - //OptimizeImage(curImage); + OptimizeImage(curImage); // Insert the image useFrameN = framen; @@ -182,7 +182,7 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) { // Save file file.Save((const char*)filename.mb_str(wxConvLocal)); wxString filename2 = filename + _T(".prsa"); - //file.SaveText((const char*)filename2.mb_str(wxConvLocal)); + file.SaveText((const char*)filename2.mb_str(wxConvLocal)); #endif } @@ -459,7 +459,6 @@ std::vector PRSSubtitleFormat::GetFrameRanges() { ///////////////////////////////////////////// // Optimize the image by tweaking the colors -#define ERROR_OF_ALPHA(a) ((a) == 0 ? 255 : 512/((int)(a))) #define IN_ERROR_MARGIN(col1,col2,error) ((col1 > col2 ? ((int)(col1-col2)) : ((int)(col2-col1))) <= (error)) void PRSSubtitleFormat::OptimizeImage(wxImage &image) { @@ -507,10 +506,9 @@ void PRSSubtitleFormat::OptimizeImage(wxImage &image) { if (status[i] != 0) continue; // Get error - error = ERROR_OF_ALPHA(alpha[i]); - c1 = MIN(255,c1 + MIN(128,error/2)); - c2 = MIN(255,c2 + MIN(128,error/2)); - c3 = MIN(255,c3 + MIN(128,error/2)); + int a = alpha[i]; + if (a == 0) error = 255; + else error = 1024/a; // Right pixel if (i != len-1 && status[i+1] == 2) { @@ -673,10 +671,13 @@ wxImage PRSSubtitleFormat::CalculateAlpha(const unsigned char* frame1, const uns else if (y > maxy) maxy = y; // Calculate colour components - int mod = MAX(0,128/a-1); - r = MAX(0,r1-mod)*255 / a; - g = MAX(0,g1-mod)*255 / a; - b = MAX(0,b1-mod)*255 / a; + //int mod = MAX(0,128/a-1); + //r = MAX(0,r1-mod)*255 / a; + //g = MAX(0,g1-mod)*255 / a; + //b = MAX(0,b1-mod)*255 / a; + r = r1*255/a; + g = g1*255/a; + b = b1*255/a; } // Write to destination diff --git a/prs/png_wrap.cpp b/prs/png_wrap.cpp index 5f5e80b79..b1a9a5244 100644 --- a/prs/png_wrap.cpp +++ b/prs/png_wrap.cpp @@ -83,7 +83,7 @@ void PNGWrapper::Read(PRSVideoFrame *frame) { } // Set data reading - png_set_read_fn(png_ptr,this,memory_read_data); + png_set_read_fn(png_ptr,this,(png_rw_ptr) memory_read_data); // Read data //png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_STRIP_16, NULL);