add sound icons

This commit is contained in:
David Rose 2005-12-19 04:27:15 +00:00
parent ef4822717f
commit 5eaff58212
13 changed files with 209 additions and 14 deletions

View File

@ -18,14 +18,15 @@
#include "default_index_icons.h"
// This file was generated from left.png, right.png, up.png, and
// movie.png; it provides data for default navigation icons if the -i
// parameter is supplied on the command line.
// This file was generated from left.png, right.png, up.png,
// movie.png, and sound.png; it provides data for default icons if the
// -i parameter is supplied on the command line.
const char *default_left_icon_filename = "left.png";
const char *default_right_icon_filename = "right.png";
const char *default_up_icon_filename = "up.png";
const char *default_movie_icon_filename = "movie.png";
const char *default_sound_icon_filename = "sound.png";
/*
@ -35,6 +36,7 @@ bin2c -n default_left_icon left.png >> default_index_icons.cxx
bin2c -n default_right_icon right.png >> default_index_icons.cxx
bin2c -n default_up_icon up.png >> default_index_icons.cxx
bin2c -n default_movie_icon movie.png >> default_index_icons.cxx
bin2c -n default_sound_icon sound.png >> default_index_icons.cxx
*/
@ -256,3 +258,44 @@ const unsigned char default_movie_icon[] = {
const int default_movie_icon_len = 258;
/*
* This table was generated by the command:
*
* bin2c -n default_sound_icon sound.png
*/
const unsigned char default_sound_icon[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00,
0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x16, 0x04, 0x03, 0x00, 0x00, 0x00, 0x32, 0x6f, 0xa1, 0x35,
0x00, 0x00, 0x00, 0x18, 0x50, 0x4c, 0x54, 0x45, 0xcc, 0xff, 0xff,
0xff, 0x33, 0x33, 0xff, 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x99, 0x99,
0x99, 0x66, 0x00, 0x00, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, 0xfd,
0xef, 0xcf, 0xe1, 0x00, 0x00, 0x00, 0x01, 0x62, 0x4b, 0x47, 0x44,
0x07, 0x16, 0x61, 0x88, 0xeb, 0x00, 0x00, 0x00, 0x6a, 0x49, 0x44,
0x41, 0x54, 0x78, 0xda, 0x63, 0x60, 0xc0, 0x0d, 0x12, 0x18, 0x18,
0x05, 0x20, 0x2c, 0xf6, 0x02, 0x41, 0x06, 0x41, 0x08, 0xb3, 0xa4,
0x80, 0x51, 0x00, 0x22, 0xcc, 0xee, 0x54, 0xc0, 0x20, 0x08, 0x61,
0x96, 0x28, 0x15, 0x08, 0x30, 0x02, 0x55, 0xb0, 0x97, 0x97, 0x3b,
0x29, 0x15, 0x00, 0x05, 0x03, 0x19, 0x4a, 0x5c, 0x5c, 0x94, 0x80,
0x4c, 0x56, 0x10, 0x53, 0x09, 0x08, 0x0a, 0x02, 0x89, 0x63, 0xa6,
0xa4, 0x24, 0x41, 0xb5, 0x01, 0x0d, 0x33, 0x83, 0x1a, 0xc6, 0x90,
0x96, 0x56, 0x9c, 0x04, 0xb1, 0x02, 0x08, 0xd2, 0xcd, 0xe0, 0x16,
0xb3, 0x15, 0x83, 0x9c, 0x03, 0x71, 0x59, 0x3a, 0xc2, 0x91, 0x6c,
0x08, 0xa7, 0x63, 0x00, 0x00, 0xac, 0x1b, 0x1b, 0xa7, 0x07, 0x45,
0x3c, 0x76, 0x00, 0x00, 0x00, 0x56, 0x74, 0x45, 0x58, 0x74, 0x43,
0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x54, 0x68, 0x69, 0x73,
0x20, 0x61, 0x72, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69, 0x6e, 0x20,
0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x20, 0x4b, 0x65, 0x76,
0x69, 0x6e, 0x20, 0x48, 0x75, 0x67, 0x68, 0x65, 0x73, 0x2c, 0x20,
0x6b, 0x65, 0x76, 0x69, 0x6e, 0x68, 0x40, 0x65, 0x69, 0x74, 0x2e,
0x63, 0x6f, 0x6d, 0x2c, 0x20, 0x53, 0x65, 0x70, 0x74, 0x65, 0x6d,
0x62, 0x65, 0x72, 0x20, 0x31, 0x39, 0x39, 0x35, 0x4c, 0xe8, 0xf4,
0xc4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42,
0x60, 0x82
};
const int default_sound_icon_len = 310;

View File

@ -23,6 +23,7 @@ extern const char *default_left_icon_filename;
extern const char *default_right_icon_filename;
extern const char *default_up_icon_filename;
extern const char *default_movie_icon_filename;
extern const char *default_sound_icon_filename;
extern const unsigned char default_left_icon[];
extern const int default_left_icon_len;

View File

@ -205,6 +205,12 @@ generate_images(const Filename &archive_dir, PNMTextMaker *text_maker) {
int icon_y = label_y - movie_icon_image.get_y_size();
index_image.blend_sub_image(movie_icon_image, icon_x, icon_y);
} else if (photo->_has_sound && get_sound_icon().is_valid()) {
const PNMImage &sound_icon_image = get_sound_icon();
int icon_x = label_x - width / 2 - sound_icon_image.get_x_size();
int icon_y = label_y - sound_icon_image.get_y_size();
index_image.blend_sub_image(sound_icon_image, icon_x, icon_y);
}
}
}
@ -457,6 +463,18 @@ copy_reduced(const Filename &archive_dir) {
}
}
}
if (photo->_has_sound) {
// Also copy the sound clip to the reduced directory.
Filename sound_filename(_dir->get_dir(), photo->get_sound());
if (sound_filename.exists()) {
sound_filename.set_binary();
Filename reduced_dir(archive_dir, "reduced/" + _dir->get_basename());
if (!copy_file(sound_filename, reduced_dir)) {
return false;
}
}
}
}
return true;
@ -506,6 +524,7 @@ generate_reduced_html(ostream &html, Photo *photo, int photo_index, int pi,
}
Filename full(full_dir, photo->get_basename());
Filename movie(full_dir, photo->get_movie());
Filename sound(full_dir, photo->get_sound());
Filename reduced_dir("../../reduced", _dir->get_basename());
Filename reduced(reduced_dir, photo->get_basename());
@ -658,6 +677,50 @@ generate_reduced_html(ostream &html, Photo *photo, int photo_index, int pi,
}
}
if (photo->_has_sound) {
html << "<p>";
if (!sound_icon.empty()) {
// Show the sound icon if we got one.
Filename sound_icon_href = compose_href("../..", sound_icon);
html << "<img src=\"" << sound_icon_href << "\" alt=\"\">";
}
// Determine the size of the file.
streampos size = 0;
ifstream stream;
Filename sound_filename(_dir->get_dir(), photo->get_sound());
sound_filename.set_binary();
if (sound_filename.open_read(stream)) {
// Seek to the end and get the stream position there.
stream.seekg(0, ios::end);
size = stream.tellg();
}
static const streampos MB = 1024 * 1024;
static const streampos GB = 1024 * 1024 * 1024;
string size_units;
double size_float;
if (size > GB) {
size_units = "GB";
size_float = (double)size / (double)GB;
} else if (size > MB) {
size_units = "MB";
size_float = (double)size / (double)MB;
}
if (size_units.empty()) {
html
<< "<a href=\"" << sound << "\">Play sound clip</a></p>\n";
} else {
char buffer[128];
sprintf(buffer, "%.1f", size_float);
html
<< "<a href=\"" << sound << "\">Play sound clip ("
<< buffer << " " << size_units << ")</a></p>\n";
}
}
generate_nav_buttons(html, prev_photo_filename, next_photo_filename,
up_href);

View File

@ -44,6 +44,7 @@ Filename prev_icon;
Filename next_icon;
Filename up_icon;
Filename movie_icon;
Filename sound_icon;
////////////////////////////////////////////////////////////////////
// Function: get_movie_icon
@ -68,6 +69,29 @@ get_movie_icon() {
return movie_icon_image;
}
////////////////////////////////////////////////////////////////////
// Function: get_sound_icon
// Description: Reads the sound icon filename and returns it as an
// image, if possible. Returns a valid image if
// successful, an invalid one otherwise.
////////////////////////////////////////////////////////////////////
const PNMImage &
get_sound_icon() {
static PNMImage sound_icon_image;
static bool got_image = false;
if (!got_image) {
if (!sound_icon.empty()) {
Filename icon_filename(archive_dir, sound_icon);
nout << "Reading " << icon_filename << "\n";
sound_icon_image.read(icon_filename);
}
got_image = true;
}
return sound_icon_image;
}
bool force_regenerate = false;
bool format_rose = false;
bool sort_date = false;

View File

@ -81,8 +81,10 @@ extern Filename prev_icon;
extern Filename next_icon;
extern Filename up_icon;
extern Filename movie_icon;
extern Filename sound_icon;
const PNMImage &get_movie_icon();
const PNMImage &get_sound_icon();
// True to regenerate every image, whether it appears to need it or
// not.

View File

@ -144,12 +144,21 @@ Indexify() {
"a link will be generated to play the movie.",
&Indexify::dispatch_string, NULL, &_movie_extension);
add_option
("S", "extension", 0,
"Specifies the filename extension (without a leading dot) to identify "
"sound files within the roll directories. This is normally mp3. If "
"a file exists with the same name as a given photo but with this "
"extension, it is taken to be a sound clip associated with the photo, "
"and a link will be generated to play the clip.",
&Indexify::dispatch_string, NULL, &_sound_extension);
add_option
("i", "", 0,
"Indicates that default navigation icon images should be generated "
"into a directory called \"icons\" which will be created within the "
"directory named by -a. This is meaningful only if -iprev, -inext, "
"-iup, and -imovie are not explicitly specified.",
"-iup, -imovie, and -isound are not explicitly specified.",
&Indexify::dispatch_none, &_generate_icons);
add_option
@ -252,6 +261,13 @@ Indexify() {
"there are one or more movie files found in the directory.",
&Indexify::dispatch_filename, NULL, &movie_icon);
add_option
("isound", "filename", 0,
"Specifies the relative pathname from the archive directory (or "
"absolute pathname) to the \"sound\" icon. This is used only if "
"there are one or more sound files found in the directory.",
&Indexify::dispatch_filename, NULL, &sound_icon);
add_option
("copyreduced", "", 0,
"Instead of generating index files, copy key files (such as "
@ -262,6 +278,7 @@ Indexify() {
_photo_extension = "jpg";
_movie_extension = "mov";
_sound_extension = "mp3";
_text_maker = (PNMTextMaker *)NULL;
_font_aa_factor = 4.0;
}
@ -488,6 +505,22 @@ post_command_line() {
output.write((const char *)default_movie_icon, default_movie_icon_len);
}
}
if (sound_icon.empty()) {
sound_icon = Filename("icons", default_sound_icon_filename);
Filename icon_filename(archive_dir, sound_icon);
if (force_regenerate || !icon_filename.exists()) {
nout << "Generating " << icon_filename << "\n";
icon_filename.make_dir();
icon_filename.set_binary();
ofstream output;
if (!icon_filename.open_write(output)) {
nout << "Unable to write to " << icon_filename << "\n";
exit(1);
}
output.write((const char *)default_sound_icon, default_sound_icon_len);
}
}
}
finalize_parameters();
@ -546,7 +579,7 @@ run() {
RollDirs::iterator di;
for (di = _roll_dirs.begin(); di != _roll_dirs.end(); ++di) {
RollDirectory *roll_dir = (*di);
if (!roll_dir->scan(_photo_extension, _movie_extension)) {
if (!roll_dir->scan(_photo_extension, _movie_extension, _sound_extension)) {
nout << "Unable to read " << *roll_dir << "\n";
all_ok = false;
}

View File

@ -55,6 +55,7 @@ public:
Filename _roll_dir_root;
string _photo_extension;
string _movie_extension;
string _sound_extension;
Filename _font_filename;
bool _generate_icons;
double _font_aa_factor;

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -27,7 +27,8 @@
// Description:
////////////////////////////////////////////////////////////////////
Photo::
Photo(RollDirectory *dir, const Filename &basename, const string &movie_extension) :
Photo(RollDirectory *dir, const Filename &basename,
const string &movie_extension, const string &sound_extension) :
_dir(dir),
_basename(basename)
{
@ -60,6 +61,14 @@ Photo(RollDirectory *dir, const Filename &basename, const string &movie_extensio
_has_movie = true;
}
_has_sound = false;
Filename sound_filename(_dir->get_dir(), _basename);
sound_filename.set_extension(sound_extension);
if (sound_filename.exists()) {
_sound = sound_filename.get_basename();
_has_sound = true;
}
_has_cm = false;
Filename cm_filename(_dir->get_dir(), _basename);
cm_filename.set_extension("cm");
@ -91,6 +100,17 @@ get_movie() const {
return _movie;
}
////////////////////////////////////////////////////////////////////
// Function: Photo::get_sound
// Access: Public
// Description: Returns the filename of the sound clip associated
// with the photo, if any.
////////////////////////////////////////////////////////////////////
const Filename &Photo::
get_sound() const {
return _sound;
}
////////////////////////////////////////////////////////////////////
// Function: Photo::get_cm
// Access: Public

View File

@ -32,10 +32,11 @@ class RollDirectory;
class Photo {
public:
Photo(RollDirectory *dir, const Filename &basename,
const string &movie_extension);
const string &movie_extension, const string &sound_extension);
const Filename &get_basename() const;
const Filename &get_movie() const;
const Filename &get_sound() const;
const Filename &get_cm() const;
const string &get_name() const;
const string &get_frame_number() const;
@ -49,12 +50,14 @@ public:
int _reduced_y_size;
bool _has_reduced;
bool _has_movie;
bool _has_sound;
bool _has_cm;
private:
RollDirectory *_dir;
Filename _basename;
Filename _movie;
Filename _sound;
Filename _cm;
string _name;
string _frame_number;

View File

@ -121,7 +121,8 @@ get_desc() const {
// Description: Scans the directory for all the listed photos.
////////////////////////////////////////////////////////////////////
bool RollDirectory::
scan(const string &photo_extension, const string &movie_extension) {
scan(const string &photo_extension, const string &movie_extension,
const string &sound_extension) {
bool reverse_order = false;
bool explicit_list = false;
@ -191,7 +192,8 @@ scan(const string &photo_extension, const string &movie_extension) {
try_filename = Filename(_dir, _basename + "0" + word + "." + photo_extension);
}
if (try_filename.exists()) {
add_photo(try_filename.get_basename(), movie_extension);
add_photo(try_filename.get_basename(), movie_extension,
sound_extension);
} else {
nout << "Frame " << word << " not found in " << _name << "\n";
}
@ -231,7 +233,7 @@ scan(const string &photo_extension, const string &movie_extension) {
for (ci = contents.begin(); ci != contents.end(); ++ci) {
Filename basename = (*ci);
if (basename.get_extension() == photo_extension) {
add_photo(basename, movie_extension);
add_photo(basename, movie_extension, sound_extension);
}
}
}
@ -692,8 +694,9 @@ insert_html_comment(ostream &html, Filename cm_filename) {
// list.
////////////////////////////////////////////////////////////////////
void RollDirectory::
add_photo(const Filename &basename, const string &movie_extension) {
Photo *photo = new Photo(this, basename, movie_extension);
add_photo(const Filename &basename, const string &movie_extension,
const string &sound_extension) {
Photo *photo = new Photo(this, basename, movie_extension, sound_extension);
_photos.push_back(photo);
}

View File

@ -42,7 +42,8 @@ public:
const string &get_basename() const;
const string &get_name() const;
const string &get_desc() const;
bool scan(const string &photo_extension, const string &movie_extension);
bool scan(const string &photo_extension, const string &movie_extension,
const string &sound_extension);
void collect_index_images();
bool sort_date_before(const RollDirectory &other) const;
@ -70,7 +71,8 @@ public:
static bool insert_html_comment(ostream &html, Filename cm_filename);
private:
void add_photo(const Filename &basename, const string &movie_extension);
void add_photo(const Filename &basename, const string &movie_extension,
const string &sound_extension);
void add_contributing_filename(const Filename &filename);
static bool insert_html_comment_body(ostream &html, istream &cm);
static string format_basename(const string &basename);

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B