Fixed a regression with audio files and seeking, added a few new methods, and more accurately detect the End() of clips.

This commit is contained in:
Jonathan Thomas
2012-10-14 02:36:05 -05:00
parent eace9f5efd
commit b647ff77c8
12 changed files with 309 additions and 269 deletions

View File

@@ -76,133 +76,133 @@ void Player::Play()
cout << setprecision(6);
cout << "START PREPARING SURFACES..." << endl;
for (int stuff = 0; stuff < number_of_cycles; stuff++)
{
// Get pointer to pixels of image.
Frame *f = reader->GetFrame(300 + stuff);
// Create YUV Overlay
SDL_Overlay *bmp;
bmp = SDL_CreateYUVOverlay(reader->info.width, reader->info.height, SDL_YV12_OVERLAY, screen);
SDL_LockYUVOverlay(bmp);
// Get pixels for resized frame (for reduced color needed by YUV420p)
int divider = 2;
const Magick::PixelPacket *reduced_color = f->GetPixels(reader->info.width / divider, reader->info.height / divider, f->number);
int number_of_colors = (reader->info.width / divider) * (reader->info.height / divider);
int pixel_index = 0;
int biggest_y = 0;
int smallest_y = 512;
for (int row = 0; row < screen->h; row++) {
// Get array of pixels for this row
//cout << "row: " << row << endl;
const Magick::PixelPacket *imagepixels = f->GetPixels(row);
// Loop through pixels on this row
for (int column = 0; column < screen->w; column++) {
// Get a pixel from this row
const Magick::PixelPacket *pixel = imagepixels;
// Get the RGB colors
float r = pixel[column].red / 255.0;
float b = pixel[column].blue / 255.0;
float g = pixel[column].green / 255.0;
// Calculate the Y value (brightness or luminance)
float y = (0.299 * r) + (0.587 * g) + (0.114 * b);
// if (y > biggest_y)
// biggest_y = y;
// if (y < smallest_y)
// smallest_y = y;
// Update the Y value for every pixel
bmp->pixels[0][pixel_index] = y;
//bmp->pixels[1][pixel_index] = 0;
//bmp->pixels[2][pixel_index] = 0;
// Increment counter
pixel_index++;
}
}
// cout << "Biggest Y: " << biggest_y << ", Smallest Y: " << smallest_y << endl;
// cout << "ADD COLOR TO YUV OVERLAY" << endl;
// Loop through the UV (color info)
//int color_counter = 511;
//number_of_colors = bmp->pitches[1] * 218;
// int biggest_v = 0;
// int smallest_v = 512;
// int biggest_u = 0;
// int smallest_u = 512;
for (int pixel_index = 0; pixel_index < number_of_colors; pixel_index++)
{
// Get a pixel from this row
const Magick::PixelPacket *pixel = reduced_color;
// Get the RGB colors
float r = pixel[pixel_index].red / 255.0;
float b = pixel[pixel_index].blue / 255.0;
float g = pixel[pixel_index].green / 255.0;
// float r = 100.0;
// float g = 100.0;
// float b = 100.0;
// Calculate UV colors
float v = (0.439 * r) - (0.368 * g) - (0.071 * b) + 128;
float u = (-0.148 * r) - (0.291 * g) + (0.439 * b) + 128;
// // Grey pixel
// if (pixel_index == 40650)
// {
// cout << "GREY FOUND!!!" << endl;
// cout << "r: " << int(r) << ", g: " << int(g) << ", b: " << int(b) << " v: " << int(v) << ", u: " << int(u) << endl;
// }
//for (int stuff = 0; stuff < number_of_cycles; stuff++)
//{
// // Get pointer to pixels of image.
// Frame *f = reader->GetFrame(300 + stuff);
//
// // Pink pixel
// if (pixel_index == 42698)
// {
// cout << "PINK FOUND!!!" << endl;
// cout << "r: " << int(r) << ", g: " << int(g) << ", b: " << int(b) << " v: " << int(v) << ", u: " << int(u) << endl;
// }
// if (v > 255.0 || v <= 0.0)
// cout << "TOO BIG v!!!!" << endl;
// if (u > 255.0 || u <= 0.0)
// cout << "TOO BIG u!!!!" << endl;
// if (v > biggest_v)
// biggest_v = v;
// if (v < smallest_v)
// smallest_v = v;
// // Create YUV Overlay
// SDL_Overlay *bmp;
// bmp = SDL_CreateYUVOverlay(reader->info.width, reader->info.height, SDL_YV12_OVERLAY, screen);
// SDL_LockYUVOverlay(bmp);
//
// if (u > biggest_u)
// biggest_u = u;
// if (u < smallest_u)
// smallest_u = u;
// Update the UV values for every pixel
bmp->pixels[1][pixel_index] = v * 1.0;
bmp->pixels[2][pixel_index] = u * 1.0;
//color_counter++;
}
//cout << "Biggest V: " << biggest_v << ", Smallest V: " << smallest_v << endl;
//cout << "Biggest U: " << biggest_u << ", Smallest U: " << smallest_u << endl;
SDL_UnlockYUVOverlay(bmp);
// Add to vector
overlays.push_back(bmp);
// Update surface.
//SDL_UpdateRect(screen, 0, 0, reader->info.width, reader->info.height);
}
// // Get pixels for resized frame (for reduced color needed by YUV420p)
// int divider = 2;
// //const Magick::PixelPacket *reduced_color = f->GetPixels(reader->info.width / divider, reader->info.height / divider, f->number);
// int number_of_colors = (reader->info.width / divider) * (reader->info.height / divider);
//
// int pixel_index = 0;
// int biggest_y = 0;
// int smallest_y = 512;
// for (int row = 0; row < screen->h; row++) {
// // Get array of pixels for this row
// //cout << "row: " << row << endl;
// const Magick::PixelPacket *imagepixels = f->GetPixels(row);
//
// // Loop through pixels on this row
// for (int column = 0; column < screen->w; column++) {
//
// // Get a pixel from this row
// const Magick::PixelPacket *pixel = imagepixels;
//
// // Get the RGB colors
// float r = pixel[column].red / 255.0;
// float b = pixel[column].blue / 255.0;
// float g = pixel[column].green / 255.0;
//
// // Calculate the Y value (brightness or luminance)
// float y = (0.299 * r) + (0.587 * g) + (0.114 * b);
//
//// if (y > biggest_y)
//// biggest_y = y;
//// if (y < smallest_y)
//// smallest_y = y;
//
// // Update the Y value for every pixel
// bmp->pixels[0][pixel_index] = y;
// //bmp->pixels[1][pixel_index] = 0;
// //bmp->pixels[2][pixel_index] = 0;
//
// // Increment counter
// pixel_index++;
//
// }
// }
//
//// cout << "Biggest Y: " << biggest_y << ", Smallest Y: " << smallest_y << endl;
//// cout << "ADD COLOR TO YUV OVERLAY" << endl;
//
// // Loop through the UV (color info)
// //int color_counter = 511;
// //number_of_colors = bmp->pitches[1] * 218;
//// int biggest_v = 0;
//// int smallest_v = 512;
//// int biggest_u = 0;
//// int smallest_u = 512;
// for (int pixel_index = 0; pixel_index < number_of_colors; pixel_index++)
// {
// // Get a pixel from this row
// const Magick::PixelPacket *pixel = reduced_color;
//
// // Get the RGB colors
// float r = pixel[pixel_index].red / 255.0;
// float b = pixel[pixel_index].blue / 255.0;
// float g = pixel[pixel_index].green / 255.0;
//// float r = 100.0;
//// float g = 100.0;
//// float b = 100.0;
//
// // Calculate UV colors
// float v = (0.439 * r) - (0.368 * g) - (0.071 * b) + 128;
// float u = (-0.148 * r) - (0.291 * g) + (0.439 * b) + 128;
//
//// // Grey pixel
//// if (pixel_index == 40650)
//// {
//// cout << "GREY FOUND!!!" << endl;
//// cout << "r: " << int(r) << ", g: " << int(g) << ", b: " << int(b) << " v: " << int(v) << ", u: " << int(u) << endl;
//// }
////
//// // Pink pixel
//// if (pixel_index == 42698)
//// {
//// cout << "PINK FOUND!!!" << endl;
//// cout << "r: " << int(r) << ", g: " << int(g) << ", b: " << int(b) << " v: " << int(v) << ", u: " << int(u) << endl;
//// }
//
//// if (v > 255.0 || v <= 0.0)
//// cout << "TOO BIG v!!!!" << endl;
//// if (u > 255.0 || u <= 0.0)
//// cout << "TOO BIG u!!!!" << endl;
//
//// if (v > biggest_v)
//// biggest_v = v;
//// if (v < smallest_v)
//// smallest_v = v;
////
//// if (u > biggest_u)
//// biggest_u = u;
//// if (u < smallest_u)
//// smallest_u = u;
//
// // Update the UV values for every pixel
// bmp->pixels[1][pixel_index] = v * 1.0;
// bmp->pixels[2][pixel_index] = u * 1.0;
//
// //color_counter++;
// }
//
// //cout << "Biggest V: " << biggest_v << ", Smallest V: " << smallest_v << endl;
// //cout << "Biggest U: " << biggest_u << ", Smallest U: " << smallest_u << endl;
//
// SDL_UnlockYUVOverlay(bmp);
//
// // Add to vector
// overlays.push_back(bmp);
//
// // Update surface.
// //SDL_UpdateRect(screen, 0, 0, reader->info.width, reader->info.height);
//}
cout << "START DISPLAYING SURFACES..." << endl;