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_QUIT 'infq'
#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
#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)
{
fpbitmap = NULL;
fdocumentIndex = 1;
fdocumentCount = 1;
SetViewColor(192, 192, 192);
SetHighColor(0, 0, 0);
@@ -166,12 +168,12 @@ ImageView::SaveImageAtDropLocation(BMessage *pmsg)
{
// Find the location and name of the drop and
// write the image file there
BBitmapStream stream(fpbitmap);
StatusCheck chk;
// throw an exception if this is assigned
// anything other than B_OK
try {
entry_ref dirref;
chk = pmsg->FindRef("directory", &dirref);
@@ -320,8 +322,9 @@ char_format(uint32 num)
// Send information about the currently open image to the
// BApplication object so it can send it to the InfoWindow
void
ImageView::UpdateInfoWindow(const BPath &path, const translator_info &tinfo,
const char *tranname, const char *traninfo, int32 tranversion)
ImageView::UpdateInfoWindow(const BPath &path, BMessage &ioExtension,
const translator_info &tinfo, const char *tranname, const char *traninfo,
int32 tranversion)
{
BMessage msg(M_INFO_WINDOW_TEXT);
BString bstr;
@@ -348,6 +351,15 @@ ImageView::UpdateInfoWindow(const BPath &path, const translator_info &tinfo,
bstr << "Quality: " << tinfo.quality << "\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
bstr << "\nTranslator Used:\n";
bstr << "Name: " << tranname << "\n";
@@ -391,12 +403,16 @@ ImageView::SetImage(BMessage *pmsg)
// Replace current image with the image
// 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;
try {
entry_ref ref;
chk = pmsg->FindRef("refs", &ref);
BFile file(&ref, B_READ_ONLY);
chk = file.InitCheck();
@@ -408,7 +424,9 @@ ImageView::SetImage(BMessage *pmsg)
// determine what type the image is
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);
// get the name and info about the translator
@@ -419,12 +437,20 @@ ImageView::SetImage(BMessage *pmsg)
// perform the actual translation
BBitmapStream outstream;
chk = proster->Translate(&file, &tinfo, NULL, &outstream,
chk = proster->Translate(&file, &tinfo, &ioExtension, &outstream,
B_TRANSLATOR_BITMAP);
BBitmap *pbitmap = NULL;
chk = outstream.DetachBitmap(&pbitmap);
fpbitmap = pbitmap;
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
BWindow *pwin = Window();
@@ -438,7 +464,7 @@ ImageView::SetImage(BMessage *pmsg)
} else
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
// 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 <Bitmap.h>
#include <Path.h>
#include <Entry.h>
#include <TranslatorRoster.h>
class ImageView : public BView {
@@ -54,15 +55,24 @@ public:
void SetImage(BMessage *pmsg);
bool HasImage() { return fpbitmap ? true : false; };
void FirstPage();
void LastPage();
void NextPage();
void PrevPage();
private:
void UpdateInfoWindow(const BPath &path, const translator_info &info,
const char *tranname, const char *traninfo, int32 tranversion);
void UpdateInfoWindow(const BPath &path, BMessage &ioExtension,
const translator_info &info, const char *tranname, const char *traninfo,
int32 tranversion);
void ReDraw();
void AdjustScrollBars();
void SaveImageAtDropLocation(BMessage *pmsg);
BTranslatorRoster *SelectTranslatorRoster(BTranslatorRoster &roster);
entry_ref fcurrentRef;
int32 fdocumentIndex;
int32 fdocumentCount;
BBitmap *fpbitmap;
};
@@ -61,6 +61,26 @@ ImageWindow::ImageWindow(BRect rect, const char *name)
pmnufile->AddItem(pitmquit);
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");
BMenuItem *pitmactives = new BMenuItem("Active Translators",
new BMessage(M_ACTIVE_TRANSLATORS_WINDOW), 'T', 0);
@@ -126,6 +146,19 @@ ImageWindow::MessageReceived(BMessage *pmsg)
fpimageView->SetImage(pmsg);
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:
break;