PRS encoder optimization fixed

Originally committed to SVN as r293.
This commit is contained in:
Rodrigo Braz Monteiro 2006-04-03 13:45:47 +00:00
parent fff3fce137
commit 85155bfaa1
2 changed files with 13 additions and 12 deletions

View File

@ -166,7 +166,7 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
if (!curImage.Ok()) continue; if (!curImage.Ok()) continue;
// Optimize image // Optimize image
//OptimizeImage(curImage); OptimizeImage(curImage);
// Insert the image // Insert the image
useFrameN = framen; useFrameN = framen;
@ -182,7 +182,7 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
// Save file // Save file
file.Save((const char*)filename.mb_str(wxConvLocal)); file.Save((const char*)filename.mb_str(wxConvLocal));
wxString filename2 = filename + _T(".prsa"); wxString filename2 = filename + _T(".prsa");
//file.SaveText((const char*)filename2.mb_str(wxConvLocal)); file.SaveText((const char*)filename2.mb_str(wxConvLocal));
#endif #endif
} }
@ -459,7 +459,6 @@ std::vector<int> PRSSubtitleFormat::GetFrameRanges() {
///////////////////////////////////////////// /////////////////////////////////////////////
// Optimize the image by tweaking the colors // 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)) #define IN_ERROR_MARGIN(col1,col2,error) ((col1 > col2 ? ((int)(col1-col2)) : ((int)(col2-col1))) <= (error))
void PRSSubtitleFormat::OptimizeImage(wxImage &image) { void PRSSubtitleFormat::OptimizeImage(wxImage &image) {
@ -507,10 +506,9 @@ void PRSSubtitleFormat::OptimizeImage(wxImage &image) {
if (status[i] != 0) continue; if (status[i] != 0) continue;
// Get error // Get error
error = ERROR_OF_ALPHA(alpha[i]); int a = alpha[i];
c1 = MIN(255,c1 + MIN(128,error/2)); if (a == 0) error = 255;
c2 = MIN(255,c2 + MIN(128,error/2)); else error = 1024/a;
c3 = MIN(255,c3 + MIN(128,error/2));
// Right pixel // Right pixel
if (i != len-1 && status[i+1] == 2) { 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; else if (y > maxy) maxy = y;
// Calculate colour components // Calculate colour components
int mod = MAX(0,128/a-1); //int mod = MAX(0,128/a-1);
r = MAX(0,r1-mod)*255 / a; //r = MAX(0,r1-mod)*255 / a;
g = MAX(0,g1-mod)*255 / a; //g = MAX(0,g1-mod)*255 / a;
b = MAX(0,b1-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 // Write to destination

View File

@ -83,7 +83,7 @@ void PNGWrapper::Read(PRSVideoFrame *frame) {
} }
// Set data reading // 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 // Read data
//png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_STRIP_16, NULL); //png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_STRIP_16, NULL);