added support for multiple images in a single stream, such as in multi-page TIFF files

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3914 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber
2003-07-09 03:21:20 +00:00
parent a08b357442
commit 095b7731f4
4 changed files with 120 additions and 12 deletions
+4 -1
View File
@@ -40,7 +40,10 @@
#define M_INFO_WINDOW 'infw' #define M_INFO_WINDOW 'infw'
#define M_INFO_WINDOW_QUIT 'infq' #define M_INFO_WINDOW_QUIT 'infq'
#define M_INFO_WINDOW_TEXT 'inft' #define M_INFO_WINDOW_TEXT 'inft'
#define M_VIEW_FIRST_PAGE 'vwfp'
#define M_VIEW_LAST_PAGE 'vwlp'
#define M_VIEW_NEXT_PAGE 'vwnp'
#define M_VIEW_PREV_PAGE 'vwpp'
// String constants // String constants
#define APP_SIG "application/x-vnd.OBOS-Inspector" #define APP_SIG "application/x-vnd.OBOS-Inspector"
+71 -9
View File
@@ -63,6 +63,8 @@ ImageView::ImageView(BRect rect, const char *name)
: BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS) : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS)
{ {
fpbitmap = NULL; fpbitmap = NULL;
fdocumentIndex = 1;
fdocumentCount = 1;
SetViewColor(192, 192, 192); SetViewColor(192, 192, 192);
SetHighColor(0, 0, 0); SetHighColor(0, 0, 0);
@@ -166,12 +168,12 @@ ImageView::SaveImageAtDropLocation(BMessage *pmsg)
{ {
// Find the location and name of the drop and // Find the location and name of the drop and
// write the image file there // write the image file there
BBitmapStream stream(fpbitmap); BBitmapStream stream(fpbitmap);
StatusCheck chk; StatusCheck chk;
// throw an exception if this is assigned // throw an exception if this is assigned
// anything other than B_OK // anything other than B_OK
try { try {
entry_ref dirref; entry_ref dirref;
chk = pmsg->FindRef("directory", &dirref); chk = pmsg->FindRef("directory", &dirref);
@@ -320,8 +322,9 @@ char_format(uint32 num)
// Send information about the currently open image to the // Send information about the currently open image to the
// BApplication object so it can send it to the InfoWindow // BApplication object so it can send it to the InfoWindow
void void
ImageView::UpdateInfoWindow(const BPath &path, const translator_info &tinfo, ImageView::UpdateInfoWindow(const BPath &path, BMessage &ioExtension,
const char *tranname, const char *traninfo, int32 tranversion) const translator_info &tinfo, const char *tranname, const char *traninfo,
int32 tranversion)
{ {
BMessage msg(M_INFO_WINDOW_TEXT); BMessage msg(M_INFO_WINDOW_TEXT);
BString bstr; BString bstr;
@@ -348,6 +351,15 @@ ImageView::UpdateInfoWindow(const BPath &path, const translator_info &tinfo,
bstr << "Quality: " << tinfo.quality << "\n"; bstr << "Quality: " << tinfo.quality << "\n";
bstr << "Capability: " << tinfo.capability << "\n"; bstr << "Capability: " << tinfo.capability << "\n";
// Extension Info
bstr << "\nExtension Info:\n";
int32 document_count = 0, document_index = 0;
if (ioExtension.FindInt32("/documentCount", &document_count) == B_OK)
bstr << "Number of Documents: " << document_count << "\n";
if (ioExtension.FindInt32("/documentIndex", &document_index) == B_OK)
bstr << "Selected Document: " << document_index << "\n";
// Translator Info // Translator Info
bstr << "\nTranslator Used:\n"; bstr << "\nTranslator Used:\n";
bstr << "Name: " << tranname << "\n"; bstr << "Name: " << tranname << "\n";
@@ -391,12 +403,16 @@ ImageView::SetImage(BMessage *pmsg)
// Replace current image with the image // Replace current image with the image
// specified in the given BMessage // specified in the given BMessage
entry_ref ref;
if (!pmsg)
ref = fcurrentRef;
else if (pmsg->FindRef("refs", &ref) != B_OK)
// If refs not found, just ignore the message
return;
StatusCheck chk; StatusCheck chk;
try { try {
entry_ref ref;
chk = pmsg->FindRef("refs", &ref);
BFile file(&ref, B_READ_ONLY); BFile file(&ref, B_READ_ONLY);
chk = file.InitCheck(); chk = file.InitCheck();
@@ -408,7 +424,9 @@ ImageView::SetImage(BMessage *pmsg)
// determine what type the image is // determine what type the image is
translator_info tinfo; translator_info tinfo;
chk = proster->Identify(&file, NULL, &tinfo, 0, NULL, BMessage ioExtension;
chk = ioExtension.AddInt32("/documentIndex", fdocumentIndex);
chk = proster->Identify(&file, &ioExtension, &tinfo, 0, NULL,
B_TRANSLATOR_BITMAP); B_TRANSLATOR_BITMAP);
// get the name and info about the translator // get the name and info about the translator
@@ -419,12 +437,20 @@ ImageView::SetImage(BMessage *pmsg)
// perform the actual translation // perform the actual translation
BBitmapStream outstream; BBitmapStream outstream;
chk = proster->Translate(&file, &tinfo, NULL, &outstream, chk = proster->Translate(&file, &tinfo, &ioExtension, &outstream,
B_TRANSLATOR_BITMAP); B_TRANSLATOR_BITMAP);
BBitmap *pbitmap = NULL; BBitmap *pbitmap = NULL;
chk = outstream.DetachBitmap(&pbitmap); chk = outstream.DetachBitmap(&pbitmap);
fpbitmap = pbitmap; fpbitmap = pbitmap;
pbitmap = NULL; pbitmap = NULL;
fcurrentRef = ref;
// need to keep the ref around if user was to switch pages
int32 documentCount = 0;
if (ioExtension.FindInt32("/documentCount", &documentCount) ==
B_OK && documentCount > 0)
fdocumentCount = documentCount;
else
fdocumentCount = 1;
// Set the name of the Window to reflect the file name // Set the name of the Window to reflect the file name
BWindow *pwin = Window(); BWindow *pwin = Window();
@@ -438,7 +464,7 @@ ImageView::SetImage(BMessage *pmsg)
} else } else
pwin->SetTitle(IMAGEWINDOW_TITLE); pwin->SetTitle(IMAGEWINDOW_TITLE);
UpdateInfoWindow(path, tinfo, tranname, traninfo, tranversion); UpdateInfoWindow(path, ioExtension, tinfo, tranname, traninfo, tranversion);
// Resize parent window and set size limits to // Resize parent window and set size limits to
// reflect the size of the new bitmap // reflect the size of the new bitmap
@@ -479,3 +505,39 @@ ImageView::SetImage(BMessage *pmsg)
} }
} }
void
ImageView::FirstPage()
{
if (fdocumentIndex != 1) {
fdocumentIndex = 1;
SetImage(NULL);
}
}
void
ImageView::LastPage()
{
if (fdocumentIndex != fdocumentCount) {
fdocumentIndex = fdocumentCount;
SetImage(NULL);
}
}
void
ImageView::NextPage()
{
if (fdocumentIndex < fdocumentCount) {
fdocumentIndex++;
SetImage(NULL);
}
}
void
ImageView::PrevPage()
{
if (fdocumentIndex > 1) {
fdocumentIndex--;
SetImage(NULL);
}
}
+12 -2
View File
@@ -36,6 +36,7 @@
#include <View.h> #include <View.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Path.h> #include <Path.h>
#include <Entry.h>
#include <TranslatorRoster.h> #include <TranslatorRoster.h>
class ImageView : public BView { class ImageView : public BView {
@@ -54,15 +55,24 @@ public:
void SetImage(BMessage *pmsg); void SetImage(BMessage *pmsg);
bool HasImage() { return fpbitmap ? true : false; }; bool HasImage() { return fpbitmap ? true : false; };
void FirstPage();
void LastPage();
void NextPage();
void PrevPage();
private: private:
void UpdateInfoWindow(const BPath &path, const translator_info &info, void UpdateInfoWindow(const BPath &path, BMessage &ioExtension,
const char *tranname, const char *traninfo, int32 tranversion); const translator_info &info, const char *tranname, const char *traninfo,
int32 tranversion);
void ReDraw(); void ReDraw();
void AdjustScrollBars(); void AdjustScrollBars();
void SaveImageAtDropLocation(BMessage *pmsg); void SaveImageAtDropLocation(BMessage *pmsg);
BTranslatorRoster *SelectTranslatorRoster(BTranslatorRoster &roster); BTranslatorRoster *SelectTranslatorRoster(BTranslatorRoster &roster);
entry_ref fcurrentRef;
int32 fdocumentIndex;
int32 fdocumentCount;
BBitmap *fpbitmap; BBitmap *fpbitmap;
}; };
@@ -61,6 +61,26 @@ ImageWindow::ImageWindow(BRect rect, const char *name)
pmnufile->AddItem(pitmquit); pmnufile->AddItem(pitmquit);
pbar->AddItem(pmnufile); pbar->AddItem(pmnufile);
BMenu *pmnuview = new BMenu("View");
BMenuItem *pitmfirst = new BMenuItem("First Page",
new BMessage(M_VIEW_FIRST_PAGE), 'F', 0);
BMenuItem *pitmlast = new BMenuItem("Last Page",
new BMessage(M_VIEW_LAST_PAGE), 'L', 0);
BMenuItem *pitmnext = new BMenuItem("Next Page",
new BMessage(M_VIEW_NEXT_PAGE), 'N', 0);
BMenuItem *pitmprev = new BMenuItem("Previous Page",
new BMessage(M_VIEW_PREV_PAGE), 'P', 0);
pmnuview->AddItem(pitmfirst);
pmnuview->AddItem(pitmlast);
pmnuview->AddItem(pitmnext);
pmnuview->AddItem(pitmprev);
pbar->AddItem(pmnuview);
BMenu *pmnuwindow = new BMenu("Window"); BMenu *pmnuwindow = new BMenu("Window");
BMenuItem *pitmactives = new BMenuItem("Active Translators", BMenuItem *pitmactives = new BMenuItem("Active Translators",
new BMessage(M_ACTIVE_TRANSLATORS_WINDOW), 'T', 0); new BMessage(M_ACTIVE_TRANSLATORS_WINDOW), 'T', 0);
@@ -126,6 +146,19 @@ ImageWindow::MessageReceived(BMessage *pmsg)
fpimageView->SetImage(pmsg); fpimageView->SetImage(pmsg);
break; break;
case M_VIEW_FIRST_PAGE:
fpimageView->FirstPage();
break;
case M_VIEW_LAST_PAGE:
fpimageView->LastPage();
break;
case M_VIEW_NEXT_PAGE:
fpimageView->NextPage();
break;
case M_VIEW_PREV_PAGE:
fpimageView->PrevPage();
break;
case B_CANCEL: case B_CANCEL:
break; break;