Don't use private BeOS syscalls.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31044 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
SubDir HAIKU_TOP src apps processcontroller ;
|
SubDir HAIKU_TOP src apps processcontroller ;
|
||||||
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
UsePrivateSystemHeaders ;
|
||||||
|
|
||||||
Application ProcessController :
|
Application ProcessController :
|
||||||
AutoIcon.cpp
|
AutoIcon.cpp
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
|
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
|
||||||
Copyright (C) 2004 beunited.org
|
Copyright (C) 2004 beunited.org
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
#ifndef _PCWORLD_H_
|
#ifndef _PCWORLD_H_
|
||||||
#define _PCWORLD_H_
|
#define _PCWORLD_H_
|
||||||
@@ -42,7 +42,5 @@ extern const char* kPCSemaphoreName;
|
|||||||
|
|
||||||
extern thread_id id;
|
extern thread_id id;
|
||||||
|
|
||||||
extern "C" int _kget_cpu_state_(int cpu);
|
|
||||||
extern "C" int _kset_cpu_state_(int cpu, int enabled);
|
|
||||||
|
|
||||||
#endif // _PCWORLD_H_
|
#endif // _PCWORLD_H_
|
||||||
|
|||||||
@@ -21,18 +21,9 @@
|
|||||||
|
|
||||||
#include "ProcessController.h"
|
#include "ProcessController.h"
|
||||||
|
|
||||||
#include "AutoIcon.h"
|
#include <stdio.h>
|
||||||
#include "Colors.h"
|
#include <stdlib.h>
|
||||||
#include "IconMenuItem.h"
|
#include <string.h>
|
||||||
#include "MemoryBarMenu.h"
|
|
||||||
#include "MemoryBarMenuItem.h"
|
|
||||||
#include "PCWorld.h"
|
|
||||||
#include "Preferences.h"
|
|
||||||
#include "QuitMenu.h"
|
|
||||||
#include "TeamBarMenu.h"
|
|
||||||
#include "TeamBarMenuItem.h"
|
|
||||||
#include "ThreadBarMenu.h"
|
|
||||||
#include "Utilities.h"
|
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
@@ -49,9 +40,21 @@
|
|||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <syscalls.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include "AutoIcon.h"
|
||||||
|
#include "Colors.h"
|
||||||
|
#include "IconMenuItem.h"
|
||||||
|
#include "MemoryBarMenu.h"
|
||||||
|
#include "MemoryBarMenuItem.h"
|
||||||
|
#include "PCWorld.h"
|
||||||
|
#include "Preferences.h"
|
||||||
|
#include "QuitMenu.h"
|
||||||
|
#include "TeamBarMenu.h"
|
||||||
|
#include "TeamBarMenuItem.h"
|
||||||
|
#include "ThreadBarMenu.h"
|
||||||
|
#include "Utilities.h"
|
||||||
|
|
||||||
|
|
||||||
const char* kDeskbarItemName = "ProcessController";
|
const char* kDeskbarItemName = "ProcessController";
|
||||||
const char* kClassName = "ProcessController";
|
const char* kClassName = "ProcessController";
|
||||||
@@ -340,7 +343,7 @@ ProcessController::MessageReceived(BMessage *message)
|
|||||||
if (message->FindInt32 ("cpu", &cpu) == B_OK) {
|
if (message->FindInt32 ("cpu", &cpu) == B_OK) {
|
||||||
bool last = true;
|
bool last = true;
|
||||||
for (int p = 0; p < gCPUcount; p++) {
|
for (int p = 0; p < gCPUcount; p++) {
|
||||||
if (p != cpu && _kget_cpu_state_(p)) {
|
if (p != cpu && _kern_cpu_enabled(p)) {
|
||||||
last = false;
|
last = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -350,7 +353,7 @@ ProcessController::MessageReceived(BMessage *message)
|
|||||||
"That's no Fun!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
"That's no Fun!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
} else
|
} else
|
||||||
_kset_cpu_state_(cpu, !_kget_cpu_state_(cpu));
|
_kern_set_cpu_enabled(cpu, !_kern_cpu_enabled(cpu));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -674,7 +677,7 @@ thread_popup(void *arg)
|
|||||||
BMessage* m = new BMessage ('CPU ');
|
BMessage* m = new BMessage ('CPU ');
|
||||||
m->AddInt32 ("cpu", i);
|
m->AddInt32 ("cpu", i);
|
||||||
item = new IconMenuItem (gPCView->fProcessorIcon, item_name, m);
|
item = new IconMenuItem (gPCView->fProcessorIcon, item_name, m);
|
||||||
if (_kget_cpu_state_(i))
|
if (_kern_cpu_enabled(i))
|
||||||
item->SetMarked (true);
|
item->SetMarked (true);
|
||||||
item->SetTarget(gPCView);
|
item->SetTarget(gPCView);
|
||||||
addtopbottom(item);
|
addtopbottom(item);
|
||||||
|
|||||||
@@ -10,11 +10,16 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "CPUButton.h"
|
#include "CPUButton.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
|
|
||||||
|
#include <syscalls.h>
|
||||||
|
|
||||||
#include "PulseApp.h"
|
#include "PulseApp.h"
|
||||||
#include "PulseView.h"
|
#include "PulseView.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include <interface/Alert.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
|
||||||
CPUButton::CPUButton(BRect rect, const char *name, const char *label, BMessage *message)
|
CPUButton::CPUButton(BRect rect, const char *name, const char *label, BMessage *message)
|
||||||
@@ -173,13 +178,13 @@ status_t
|
|||||||
CPUButton::Invoke(BMessage *message)
|
CPUButton::Invoke(BMessage *message)
|
||||||
{
|
{
|
||||||
if (!LastEnabledCPU(fCPU)) {
|
if (!LastEnabledCPU(fCPU)) {
|
||||||
_kset_cpu_state_(fCPU, Value());
|
_kern_set_cpu_enabled(fCPU, Value());
|
||||||
} else {
|
} else {
|
||||||
BAlert *alert = new BAlert(NULL, "You can't disable the last active CPU.", "OK");
|
BAlert *alert = new BAlert(NULL, "You can't disable the last active CPU.", "OK");
|
||||||
alert->Go(NULL);
|
alert->Go(NULL);
|
||||||
SetValue(!Value());
|
SetValue(!Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +221,7 @@ CPUButton::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
case PV_REPLICANT_PULSE: {
|
case PV_REPLICANT_PULSE: {
|
||||||
// Make sure we're consistent with our CPU
|
// Make sure we're consistent with our CPU
|
||||||
if (_kget_cpu_state_(fCPU) != Value() && !IsTracking())
|
if (_kern_cpu_enabled(fCPU) != Value() && !IsTracking())
|
||||||
SetValue(!Value());
|
SetValue(!Value());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
SubDir HAIKU_TOP src apps pulse ;
|
SubDir HAIKU_TOP src apps pulse ;
|
||||||
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
UsePrivateSystemHeaders ;
|
||||||
|
|
||||||
UsePrivateHeaders shared ;
|
UsePrivateHeaders shared ;
|
||||||
if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
|
if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
|
||||||
UseHeaders [ FDirName $(HAIKU_TOP) headers os kernel ] : true ;
|
UseHeaders [ FDirName $(HAIKU_TOP) headers os kernel ] : true ;
|
||||||
@@ -22,8 +21,8 @@ Application Pulse :
|
|||||||
ProgressBar.cpp
|
ProgressBar.cpp
|
||||||
PulseApp.cpp
|
PulseApp.cpp
|
||||||
PulseView.cpp
|
PulseView.cpp
|
||||||
PulseWindow.cpp
|
PulseWindow.cpp
|
||||||
|
|
||||||
: be
|
: be
|
||||||
: Pulse.rdef
|
: Pulse.rdef
|
||||||
;
|
;
|
||||||
|
|||||||
+15
-12
@@ -12,19 +12,22 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "PulseApp.h"
|
#include "PulseApp.h"
|
||||||
#include "Common.h"
|
|
||||||
#include "PulseWindow.h"
|
|
||||||
#include "DeskbarPulseView.h"
|
|
||||||
|
|
||||||
#include <Alert.h>
|
|
||||||
#include <Rect.h>
|
|
||||||
#include <Deskbar.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
|
#include <Rect.h>
|
||||||
|
#include <Deskbar.h>
|
||||||
|
|
||||||
|
#include <syscalls.h>
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
#include "PulseWindow.h"
|
||||||
|
#include "DeskbarPulseView.h"
|
||||||
|
|
||||||
|
|
||||||
PulseApp::PulseApp(int argc, char **argv)
|
PulseApp::PulseApp(int argc, char **argv)
|
||||||
: BApplication(APP_SIGNATURE)
|
: BApplication(APP_SIGNATURE)
|
||||||
@@ -60,7 +63,7 @@ PulseApp::PulseApp(int argc, char **argv)
|
|||||||
uint32 rgb = strtoul(optarg, NULL, 0);
|
uint32 rgb = strtoul(optarg, NULL, 0);
|
||||||
rgb = rgb << 8;
|
rgb = rgb << 8;
|
||||||
rgb |= 0x000000ff;
|
rgb |= 0x000000ff;
|
||||||
|
|
||||||
switch (option_index) {
|
switch (option_index) {
|
||||||
case 2:
|
case 2:
|
||||||
framecolor = rgb;
|
framecolor = rgb;
|
||||||
@@ -90,7 +93,7 @@ PulseApp::PulseApp(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deskbar) {
|
if (deskbar) {
|
||||||
prefs->window_mode = DESKBAR_MODE;
|
prefs->window_mode = DESKBAR_MODE;
|
||||||
if (activecolor != 0)
|
if (activecolor != 0)
|
||||||
@@ -171,7 +174,7 @@ LastEnabledCPU(int my_cpu)
|
|||||||
for (int x = 0; x < sys_info.cpu_count; x++) {
|
for (int x = 0; x < sys_info.cpu_count; x++) {
|
||||||
if (x == my_cpu)
|
if (x == my_cpu)
|
||||||
continue;
|
continue;
|
||||||
if (_kget_cpu_state_(x) == 1)
|
if (_kern_cpu_enabled(x) == 1)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -211,7 +214,7 @@ LoadInDeskbar()
|
|||||||
delete deskbar;
|
delete deskbar;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must be 16 pixels high, the width is retrieved from the Prefs class
|
// Must be 16 pixels high, the width is retrieved from the Prefs class
|
||||||
int width = pulseapp->prefs->deskbar_icon_width;
|
int width = pulseapp->prefs->deskbar_icon_width;
|
||||||
int min_width = GetMinimumViewWidth();
|
int min_width = GetMinimumViewWidth();
|
||||||
@@ -219,7 +222,7 @@ LoadInDeskbar()
|
|||||||
pulseapp->prefs->deskbar_icon_width = min_width;
|
pulseapp->prefs->deskbar_icon_width = min_width;
|
||||||
width = min_width;
|
width = min_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
BRect rect(0, 0, width - 1, 15);
|
BRect rect(0, 0, width - 1, 15);
|
||||||
DeskbarPulseView *replicant = new DeskbarPulseView(rect);
|
DeskbarPulseView *replicant = new DeskbarPulseView(rect);
|
||||||
status_t err = deskbar->AddItem(replicant);
|
status_t err = deskbar->AddItem(replicant);
|
||||||
|
|||||||
@@ -9,13 +9,19 @@
|
|||||||
//****************************************************************************************
|
//****************************************************************************************
|
||||||
|
|
||||||
#include "PulseView.h"
|
#include "PulseView.h"
|
||||||
#include "Common.h"
|
|
||||||
#include "PulseApp.h"
|
|
||||||
#include <interface/Alert.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
|
|
||||||
|
#include <syscalls.h>
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
#include "PulseApp.h"
|
||||||
|
|
||||||
|
|
||||||
PulseView::PulseView(BRect rect, const char *name) :
|
PulseView::PulseView(BRect rect, const char *name) :
|
||||||
BView(rect, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_PULSE_NEEDED | B_FRAME_EVENTS) {
|
BView(rect, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_PULSE_NEEDED | B_FRAME_EVENTS) {
|
||||||
|
|
||||||
@@ -33,7 +39,7 @@ PulseView::PulseView(BRect rect, const char *name) :
|
|||||||
PulseView::PulseView(BMessage *message) : BView(message) {
|
PulseView::PulseView(BMessage *message) : BView(message) {
|
||||||
SetResizingMode(B_FOLLOW_ALL_SIDES);
|
SetResizingMode(B_FOLLOW_ALL_SIDES);
|
||||||
SetFlags(B_WILL_DRAW | B_PULSE_NEEDED);
|
SetFlags(B_WILL_DRAW | B_PULSE_NEEDED);
|
||||||
|
|
||||||
popupmenu = NULL;
|
popupmenu = NULL;
|
||||||
cpu_menu_items = NULL;
|
cpu_menu_items = NULL;
|
||||||
Init();
|
Init();
|
||||||
@@ -46,14 +52,14 @@ void PulseView::Init() {
|
|||||||
mode2 = new BMenuItem("", NULL, 0, 0);
|
mode2 = new BMenuItem("", NULL, 0, 0);
|
||||||
preferences = new BMenuItem("Preferences" B_UTF8_ELLIPSIS, new BMessage(PV_PREFERENCES), 0, 0);
|
preferences = new BMenuItem("Preferences" B_UTF8_ELLIPSIS, new BMessage(PV_PREFERENCES), 0, 0);
|
||||||
about = new BMenuItem("About Pulse" B_UTF8_ELLIPSIS, new BMessage(PV_ABOUT), 0, 0);
|
about = new BMenuItem("About Pulse" B_UTF8_ELLIPSIS, new BMessage(PV_ABOUT), 0, 0);
|
||||||
|
|
||||||
popupmenu->AddItem(mode1);
|
popupmenu->AddItem(mode1);
|
||||||
popupmenu->AddItem(mode2);
|
popupmenu->AddItem(mode2);
|
||||||
popupmenu->AddSeparatorItem();
|
popupmenu->AddSeparatorItem();
|
||||||
|
|
||||||
system_info sys_info;
|
system_info sys_info;
|
||||||
get_system_info(&sys_info);
|
get_system_info(&sys_info);
|
||||||
|
|
||||||
// Only add menu items to control CPUs on an SMP machine
|
// Only add menu items to control CPUs on an SMP machine
|
||||||
if (sys_info.cpu_count >= 2) {
|
if (sys_info.cpu_count >= 2) {
|
||||||
cpu_menu_items = new BMenuItem *[sys_info.cpu_count];
|
cpu_menu_items = new BMenuItem *[sys_info.cpu_count];
|
||||||
@@ -67,7 +73,7 @@ void PulseView::Init() {
|
|||||||
}
|
}
|
||||||
popupmenu->AddSeparatorItem();
|
popupmenu->AddSeparatorItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
popupmenu->AddItem(preferences);
|
popupmenu->AddItem(preferences);
|
||||||
popupmenu->AddItem(about);
|
popupmenu->AddItem(about);
|
||||||
}
|
}
|
||||||
@@ -77,7 +83,7 @@ void PulseView::MouseDown(BPoint point) {
|
|||||||
uint32 buttons;
|
uint32 buttons;
|
||||||
MakeFocus(true);
|
MakeFocus(true);
|
||||||
GetMouse(&cursor, &buttons, true);
|
GetMouse(&cursor, &buttons, true);
|
||||||
|
|
||||||
if (buttons & B_SECONDARY_MOUSE_BUTTON) {
|
if (buttons & B_SECONDARY_MOUSE_BUTTON) {
|
||||||
ConvertToScreen(&point);
|
ConvertToScreen(&point);
|
||||||
// Use the asynchronous version so we don't interfere with
|
// Use the asynchronous version so we don't interfere with
|
||||||
@@ -98,11 +104,11 @@ void PulseView::Update() {
|
|||||||
if (cpu_time < 0) cpu_time = 0;
|
if (cpu_time < 0) cpu_time = 0;
|
||||||
if (cpu_time > 1) cpu_time = 1;
|
if (cpu_time > 1) cpu_time = 1;
|
||||||
cpu_times[x] = cpu_time;
|
cpu_times[x] = cpu_time;
|
||||||
|
|
||||||
if (sys_info.cpu_count >= 2) {
|
if (sys_info.cpu_count >= 2) {
|
||||||
if (!_kget_cpu_state_(x) && cpu_menu_items[x]->IsMarked())
|
if (!_kern_cpu_enabled(x) && cpu_menu_items[x]->IsMarked())
|
||||||
cpu_menu_items[x]->SetMarked(false);
|
cpu_menu_items[x]->SetMarked(false);
|
||||||
if (_kget_cpu_state_(x) && !cpu_menu_items[x]->IsMarked())
|
if (_kern_cpu_enabled(x) && !cpu_menu_items[x]->IsMarked())
|
||||||
cpu_menu_items[x]->SetMarked(true);
|
cpu_menu_items[x]->SetMarked(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,9 +117,9 @@ void PulseView::Update() {
|
|||||||
|
|
||||||
void PulseView::ChangeCPUState(BMessage *message) {
|
void PulseView::ChangeCPUState(BMessage *message) {
|
||||||
int which = message->FindInt32("which");
|
int which = message->FindInt32("which");
|
||||||
|
|
||||||
if (!LastEnabledCPU(which)) {
|
if (!LastEnabledCPU(which)) {
|
||||||
_kset_cpu_state_(which, (int)!cpu_menu_items[which]->IsMarked());
|
_kern_set_cpu_enabled(which, (int)!cpu_menu_items[which]->IsMarked());
|
||||||
} else {
|
} else {
|
||||||
BAlert *alert = new BAlert(NULL, "You can't disable the last active CPU.", "OK");
|
BAlert *alert = new BAlert(NULL, "You can't disable the last active CPU.", "OK");
|
||||||
alert->Go(NULL);
|
alert->Go(NULL);
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
#include <interface/PopUpMenu.h>
|
#include <interface/PopUpMenu.h>
|
||||||
#include <interface/MenuItem.h>
|
#include <interface/MenuItem.h>
|
||||||
|
|
||||||
extern "C" int _kget_cpu_state_(int cpu);
|
|
||||||
extern "C" int _kset_cpu_state_(int cpu, int enabled);
|
|
||||||
|
|
||||||
class PulseView : public BView {
|
class PulseView : public BView {
|
||||||
public:
|
public:
|
||||||
@@ -25,15 +23,15 @@ class PulseView : public BView {
|
|||||||
~PulseView();
|
~PulseView();
|
||||||
virtual void MouseDown(BPoint point);
|
virtual void MouseDown(BPoint point);
|
||||||
void ChangeCPUState(BMessage *message);
|
void ChangeCPUState(BMessage *message);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Init();
|
void Init();
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
BPopUpMenu *popupmenu;
|
BPopUpMenu *popupmenu;
|
||||||
BMenuItem *mode1, *mode2, *preferences, *about;
|
BMenuItem *mode1, *mode2, *preferences, *about;
|
||||||
BMenuItem **cpu_menu_items;
|
BMenuItem **cpu_menu_items;
|
||||||
|
|
||||||
double cpu_times[B_MAX_CPU_COUNT];
|
double cpu_times[B_MAX_CPU_COUNT];
|
||||||
bigtime_t prev_active[B_MAX_CPU_COUNT];
|
bigtime_t prev_active[B_MAX_CPU_COUNT];
|
||||||
bigtime_t prev_time;
|
bigtime_t prev_time;
|
||||||
|
|||||||
+100
-100
@@ -15,9 +15,9 @@
|
|||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
|
|
||||||
#include "Filter.h"
|
#include <syscalls.h>
|
||||||
|
|
||||||
extern "C" int _kget_cpu_state_(int cpu);
|
#include "Filter.h"
|
||||||
|
|
||||||
|
|
||||||
// Implementation of FilterThread
|
// Implementation of FilterThread
|
||||||
@@ -44,7 +44,7 @@ FilterThread::~FilterThread()
|
|||||||
fFilter->FilterThreadDone();
|
fFilter->FilterThreadDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
FilterThread::worker_thread(void* data)
|
FilterThread::worker_thread(void* data)
|
||||||
{
|
{
|
||||||
FilterThread* thread = (FilterThread*)data;
|
FilterThread* thread = (FilterThread*)data;
|
||||||
@@ -87,12 +87,12 @@ Filter::Filter(BBitmap* image, BMessenger listener, uint32 what)
|
|||||||
, fDestImage(NULL)
|
, fDestImage(NULL)
|
||||||
{
|
{
|
||||||
fCPUCount = NumberOfActiveCPUs();
|
fCPUCount = NumberOfActiveCPUs();
|
||||||
|
|
||||||
fWaitForThreads = create_sem(0, "wait_for_threads");
|
fWaitForThreads = create_sem(0, "wait_for_threads");
|
||||||
|
|
||||||
#if TIME_FILTER
|
#if TIME_FILTER
|
||||||
fStopWatch = NULL;
|
fStopWatch = NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Filter::~Filter()
|
Filter::~Filter()
|
||||||
@@ -123,19 +123,19 @@ void
|
|||||||
Filter::Start(bool async)
|
Filter::Start(bool async)
|
||||||
{
|
{
|
||||||
if (fStarted || fSrcImage == NULL) return;
|
if (fStarted || fSrcImage == NULL) return;
|
||||||
|
|
||||||
#if TIME_FILTER
|
#if TIME_FILTER
|
||||||
fStopWatch = new BStopWatch("Filter Time");
|
fStopWatch = new BStopWatch("Filter Time");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fN = NumberOfThreads();
|
fN = NumberOfThreads();
|
||||||
fNumberOfThreads = fN;
|
fNumberOfThreads = fN;
|
||||||
fIsRunning = true;
|
fIsRunning = true;
|
||||||
fStarted = true;
|
fStarted = true;
|
||||||
|
|
||||||
// start first filter thread
|
// start first filter thread
|
||||||
new FilterThread(this, 0, fN, !async);
|
new FilterThread(this, 0, fN, !async);
|
||||||
|
|
||||||
if (!async) {
|
if (!async) {
|
||||||
Wait();
|
Wait();
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ Filter::NumberOfActiveCPUs() const
|
|||||||
count = info.cpu_count;
|
count = info.cpu_count;
|
||||||
int32 cpuCount = 0;
|
int32 cpuCount = 0;
|
||||||
for (int i = 0; i < count; i ++) {
|
for (int i = 0; i < count; i ++) {
|
||||||
if (_kget_cpu_state_(i))
|
if (_kern_cpu_enabled(i))
|
||||||
cpuCount++;
|
cpuCount++;
|
||||||
}
|
}
|
||||||
if (cpuCount == 0)
|
if (cpuCount == 0)
|
||||||
@@ -271,19 +271,19 @@ Scaler::CreateDestImage(BBitmap* srcImage)
|
|||||||
|
|
||||||
BRect dest(0, 0, fRect.IntegerWidth(), fRect.IntegerHeight());
|
BRect dest(0, 0, fRect.IntegerWidth(), fRect.IntegerHeight());
|
||||||
BBitmap* destImage = new BBitmap(dest, fDither ? B_CMAP8 : srcImage->ColorSpace());
|
BBitmap* destImage = new BBitmap(dest, fDither ? B_CMAP8 : srcImage->ColorSpace());
|
||||||
|
|
||||||
if (!IsBitmapValid(destImage)) {
|
if (!IsBitmapValid(destImage)) {
|
||||||
delete destImage;
|
delete destImage;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDither)
|
if (fDither)
|
||||||
{
|
{
|
||||||
BRect dest_rect(0, 0, fRect.IntegerWidth(), fRect.IntegerHeight());
|
BRect dest_rect(0, 0, fRect.IntegerWidth(), fRect.IntegerHeight());
|
||||||
fScaledImage = new BBitmap(dest_rect, srcImage->ColorSpace());
|
fScaledImage = new BBitmap(dest_rect, srcImage->ColorSpace());
|
||||||
if (!IsBitmapValid(fScaledImage)) {
|
if (!IsBitmapValid(fScaledImage)) {
|
||||||
delete destImage;
|
delete destImage;
|
||||||
delete fScaledImage;
|
delete fScaledImage;
|
||||||
fScaledImage = NULL;
|
fScaledImage = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -330,17 +330,17 @@ Scaler::ScaleBilinear(intType fromRow, int32 toRow)
|
|||||||
|
|
||||||
src = GetSrcImage();
|
src = GetSrcImage();
|
||||||
dest = fScaledImage;
|
dest = fScaledImage;
|
||||||
|
|
||||||
srcW = src->Bounds().IntegerWidth();
|
srcW = src->Bounds().IntegerWidth();
|
||||||
srcH = src->Bounds().IntegerHeight();
|
srcH = src->Bounds().IntegerHeight();
|
||||||
destW = dest->Bounds().IntegerWidth();
|
destW = dest->Bounds().IntegerWidth();
|
||||||
destH = dest->Bounds().IntegerHeight();
|
destH = dest->Bounds().IntegerHeight();
|
||||||
|
|
||||||
srcBits = (uchar*)src->Bits();
|
srcBits = (uchar*)src->Bits();
|
||||||
destBits = (uchar*)dest->Bits();
|
destBits = (uchar*)dest->Bits();
|
||||||
srcBPR = src->BytesPerRow();
|
srcBPR = src->BytesPerRow();
|
||||||
destBPR = dest->BytesPerRow();
|
destBPR = dest->BytesPerRow();
|
||||||
|
|
||||||
columnData = new ColumnData[destW];
|
columnData = new ColumnData[destW];
|
||||||
cd = columnData;
|
cd = columnData;
|
||||||
for (i = 0; i < destW; i ++, cd++) {
|
for (i = 0; i < destW; i ++, cd++) {
|
||||||
@@ -351,7 +351,7 @@ Scaler::ScaleBilinear(intType fromRow, int32 toRow)
|
|||||||
}
|
}
|
||||||
|
|
||||||
destDataRow = destBits + fromRow * destBPR;
|
destDataRow = destBits + fromRow * destBPR;
|
||||||
|
|
||||||
for (y = fromRow; IsRunning() && y <= toRow; y ++, destDataRow += destBPR) {
|
for (y = fromRow; IsRunning() && y <= toRow; y ++, destDataRow += destBPR) {
|
||||||
float row;
|
float row;
|
||||||
intType srcRow;
|
intType srcRow;
|
||||||
@@ -368,7 +368,7 @@ Scaler::ScaleBilinear(intType fromRow, int32 toRow)
|
|||||||
|
|
||||||
srcData = srcBits + srcRow * srcBPR;
|
srcData = srcBits + srcRow * srcBPR;
|
||||||
destData = destDataRow;
|
destData = destDataRow;
|
||||||
|
|
||||||
if (y < destH) {
|
if (y < destH) {
|
||||||
float a0, a1;
|
float a0, a1;
|
||||||
const uchar *a, *b, *c, *d;
|
const uchar *a, *b, *c, *d;
|
||||||
@@ -378,10 +378,10 @@ Scaler::ScaleBilinear(intType fromRow, int32 toRow)
|
|||||||
b = a + kBPP;
|
b = a + kBPP;
|
||||||
c = a + srcBPR;
|
c = a + srcBPR;
|
||||||
d = c + kBPP;
|
d = c + kBPP;
|
||||||
|
|
||||||
a0 = columnData[x].alpha0;
|
a0 = columnData[x].alpha0;
|
||||||
a1 = columnData[x].alpha1;
|
a1 = columnData[x].alpha1;
|
||||||
|
|
||||||
destData[0] = static_cast<uchar>(
|
destData[0] = static_cast<uchar>(
|
||||||
(a[0] * a0 + b[0] * a1) * alpha0 +
|
(a[0] * a0 + b[0] * a1) * alpha0 +
|
||||||
(c[0] * a0 + d[0] * a1) * alpha1);
|
(c[0] * a0 + d[0] * a1) * alpha1);
|
||||||
@@ -395,11 +395,11 @@ Scaler::ScaleBilinear(intType fromRow, int32 toRow)
|
|||||||
(a[3] * a0 + b[3] * a1) * alpha0 +
|
(a[3] * a0 + b[3] * a1) * alpha0 +
|
||||||
(c[3] * a0 + d[3] * a1) * alpha1);
|
(c[3] * a0 + d[3] * a1) * alpha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// right column
|
// right column
|
||||||
a = srcData + srcW * kBPP;
|
a = srcData + srcW * kBPP;
|
||||||
c = a + srcBPR;
|
c = a + srcBPR;
|
||||||
|
|
||||||
destData[0] = static_cast<uchar>(a[0] * alpha0 + c[0] * alpha1);
|
destData[0] = static_cast<uchar>(a[0] * alpha0 + c[0] * alpha1);
|
||||||
destData[1] = static_cast<uchar>(a[1] * alpha0 + c[1] * alpha1);
|
destData[1] = static_cast<uchar>(a[1] * alpha0 + c[1] * alpha1);
|
||||||
destData[2] = static_cast<uchar>(a[2] * alpha0 + c[2] * alpha1);
|
destData[2] = static_cast<uchar>(a[2] * alpha0 + c[2] * alpha1);
|
||||||
@@ -410,16 +410,16 @@ Scaler::ScaleBilinear(intType fromRow, int32 toRow)
|
|||||||
for (x = 0; x < destW; x ++, destData += kBPP) {
|
for (x = 0; x < destW; x ++, destData += kBPP) {
|
||||||
a = srcData + columnData[x].srcColumn * kBPP;
|
a = srcData + columnData[x].srcColumn * kBPP;
|
||||||
b = a + kBPP;
|
b = a + kBPP;
|
||||||
|
|
||||||
a0 = columnData[x].alpha0;
|
a0 = columnData[x].alpha0;
|
||||||
a1 = columnData[x].alpha1;
|
a1 = columnData[x].alpha1;
|
||||||
|
|
||||||
destData[0] = static_cast<uchar>(a[0] * a0 + b[0] * a1);
|
destData[0] = static_cast<uchar>(a[0] * a0 + b[0] * a1);
|
||||||
destData[1] = static_cast<uchar>(a[1] * a0 + b[1] * a1);
|
destData[1] = static_cast<uchar>(a[1] * a0 + b[1] * a1);
|
||||||
destData[2] = static_cast<uchar>(a[2] * a0 + b[2] * a1);
|
destData[2] = static_cast<uchar>(a[2] * a0 + b[2] * a1);
|
||||||
destData[3] = static_cast<uchar>(a[3] * a0 + b[3] * a1);
|
destData[3] = static_cast<uchar>(a[3] * a0 + b[3] * a1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bottom, right pixel
|
// bottom, right pixel
|
||||||
a = srcData + srcW * kBPP;
|
a = srcData + srcW * kBPP;
|
||||||
|
|
||||||
@@ -428,9 +428,9 @@ Scaler::ScaleBilinear(intType fromRow, int32 toRow)
|
|||||||
destData[2] = a[2];
|
destData[2] = a[2];
|
||||||
destData[3] = a[3];
|
destData[3] = a[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] columnData;
|
delete[] columnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,22 +464,22 @@ Scaler::ScaleBilinearFP(intType fromRow, int32 toRow)
|
|||||||
|
|
||||||
src = GetSrcImage();
|
src = GetSrcImage();
|
||||||
dest = fScaledImage;
|
dest = fScaledImage;
|
||||||
|
|
||||||
srcW = src->Bounds().IntegerWidth();
|
srcW = src->Bounds().IntegerWidth();
|
||||||
srcH = src->Bounds().IntegerHeight();
|
srcH = src->Bounds().IntegerHeight();
|
||||||
destW = dest->Bounds().IntegerWidth();
|
destW = dest->Bounds().IntegerWidth();
|
||||||
destH = dest->Bounds().IntegerHeight();
|
destH = dest->Bounds().IntegerHeight();
|
||||||
|
|
||||||
srcBits = (uchar*)src->Bits();
|
srcBits = (uchar*)src->Bits();
|
||||||
destBits = (uchar*)dest->Bits();
|
destBits = (uchar*)dest->Bits();
|
||||||
srcBPR = src->BytesPerRow();
|
srcBPR = src->BytesPerRow();
|
||||||
destBPR = dest->BytesPerRow();
|
destBPR = dest->BytesPerRow();
|
||||||
|
|
||||||
fixed_point fpSrcW = to_fixed_point(srcW);
|
fixed_point fpSrcW = to_fixed_point(srcW);
|
||||||
fixed_point fpDestW = to_fixed_point(destW);
|
fixed_point fpDestW = to_fixed_point(destW);
|
||||||
fixed_point fpSrcH = to_fixed_point(srcH);
|
fixed_point fpSrcH = to_fixed_point(srcH);
|
||||||
fixed_point fpDestH = to_fixed_point(destH);
|
fixed_point fpDestH = to_fixed_point(destH);
|
||||||
|
|
||||||
columnData = new ColumnDataFP[destW];
|
columnData = new ColumnDataFP[destW];
|
||||||
cd = columnData;
|
cd = columnData;
|
||||||
for (i = 0; i < destW; i ++, cd++) {
|
for (i = 0; i < destW; i ++, cd++) {
|
||||||
@@ -490,7 +490,7 @@ Scaler::ScaleBilinearFP(intType fromRow, int32 toRow)
|
|||||||
}
|
}
|
||||||
|
|
||||||
destDataRow = destBits + fromRow * destBPR;
|
destDataRow = destBits + fromRow * destBPR;
|
||||||
|
|
||||||
for (y = fromRow; IsRunning() && y <= toRow; y ++, destDataRow += destBPR) {
|
for (y = fromRow; IsRunning() && y <= toRow; y ++, destDataRow += destBPR) {
|
||||||
fixed_point row;
|
fixed_point row;
|
||||||
intType srcRow;
|
intType srcRow;
|
||||||
@@ -514,7 +514,7 @@ Scaler::ScaleBilinearFP(intType fromRow, int32 toRow)
|
|||||||
(c[i] * a0 + d[i] * a1) * alpha1))
|
(c[i] * a0 + d[i] * a1) * alpha1))
|
||||||
#define V2(i) from_fixed_point(a[i] * alpha0 + c[i] * alpha1);
|
#define V2(i) from_fixed_point(a[i] * alpha0 + c[i] * alpha1);
|
||||||
#define H2(i) from_fixed_point(a[i] * a0 + b[i] * a1);
|
#define H2(i) from_fixed_point(a[i] * a0 + b[i] * a1);
|
||||||
|
|
||||||
if (y < destH) {
|
if (y < destH) {
|
||||||
fixed_point a0, a1;
|
fixed_point a0, a1;
|
||||||
const uchar *a, *b, *c, *d;
|
const uchar *a, *b, *c, *d;
|
||||||
@@ -524,20 +524,20 @@ Scaler::ScaleBilinearFP(intType fromRow, int32 toRow)
|
|||||||
b = a + kBPP;
|
b = a + kBPP;
|
||||||
c = a + srcBPR;
|
c = a + srcBPR;
|
||||||
d = c + kBPP;
|
d = c + kBPP;
|
||||||
|
|
||||||
a0 = columnData[x].alpha0;
|
a0 = columnData[x].alpha0;
|
||||||
a1 = columnData[x].alpha1;
|
a1 = columnData[x].alpha1;
|
||||||
|
|
||||||
destData[0] = I4(0);
|
destData[0] = I4(0);
|
||||||
destData[1] = I4(1);
|
destData[1] = I4(1);
|
||||||
destData[2] = I4(2);
|
destData[2] = I4(2);
|
||||||
destData[3] = I4(3);
|
destData[3] = I4(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// right column
|
// right column
|
||||||
a = srcData + srcW * kBPP;
|
a = srcData + srcW * kBPP;
|
||||||
c = a + srcBPR;
|
c = a + srcBPR;
|
||||||
|
|
||||||
destData[0] = V2(0);
|
destData[0] = V2(0);
|
||||||
destData[1] = V2(1);
|
destData[1] = V2(1);
|
||||||
destData[2] = V2(2);
|
destData[2] = V2(2);
|
||||||
@@ -548,16 +548,16 @@ Scaler::ScaleBilinearFP(intType fromRow, int32 toRow)
|
|||||||
for (x = 0; x < destW; x ++, destData += kBPP) {
|
for (x = 0; x < destW; x ++, destData += kBPP) {
|
||||||
a = srcData + columnData[x].srcColumn * kBPP;
|
a = srcData + columnData[x].srcColumn * kBPP;
|
||||||
b = a + kBPP;
|
b = a + kBPP;
|
||||||
|
|
||||||
a0 = columnData[x].alpha0;
|
a0 = columnData[x].alpha0;
|
||||||
a1 = columnData[x].alpha1;
|
a1 = columnData[x].alpha1;
|
||||||
|
|
||||||
destData[0] = H2(0);
|
destData[0] = H2(0);
|
||||||
destData[1] = H2(1);
|
destData[1] = H2(1);
|
||||||
destData[2] = H2(2);
|
destData[2] = H2(2);
|
||||||
destData[3] = H2(3);
|
destData[3] = H2(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bottom, right pixel
|
// bottom, right pixel
|
||||||
a = srcData + srcW * kBPP;
|
a = srcData + srcW * kBPP;
|
||||||
|
|
||||||
@@ -566,9 +566,9 @@ Scaler::ScaleBilinearFP(intType fromRow, int32 toRow)
|
|||||||
destData[2] = a[2];
|
destData[2] = a[2];
|
||||||
destData[3] = a[3];
|
destData[3] = a[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] columnData;
|
delete[] columnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,15 +578,15 @@ Scaler::RowValues(float* sum, const uchar* src, intType srcW, intType fromX, int
|
|||||||
sum[0] = a0X * src[0];
|
sum[0] = a0X * src[0];
|
||||||
sum[1] = a0X * src[1];
|
sum[1] = a0X * src[1];
|
||||||
sum[2] = a0X * src[2];
|
sum[2] = a0X * src[2];
|
||||||
|
|
||||||
src += kBPP;
|
src += kBPP;
|
||||||
|
|
||||||
for (int32 x = fromX+1; x < toX; x ++, src += kBPP) {
|
for (int32 x = fromX+1; x < toX; x ++, src += kBPP) {
|
||||||
sum[0] += src[0];
|
sum[0] += src[0];
|
||||||
sum[1] += src[1];
|
sum[1] += src[1];
|
||||||
sum[2] += src[2];
|
sum[2] += src[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toX <= srcW) {
|
if (toX <= srcW) {
|
||||||
sum[0] += a1X * src[0];
|
sum[0] += a1X * src[0];
|
||||||
sum[1] += a1X * src[1];
|
sum[1] += a1X * src[1];
|
||||||
@@ -620,19 +620,19 @@ Scaler::DownScaleBilinear(intType fromRow, int32 toRow)
|
|||||||
|
|
||||||
src = GetSrcImage();
|
src = GetSrcImage();
|
||||||
dest = fScaledImage;
|
dest = fScaledImage;
|
||||||
|
|
||||||
srcW = src->Bounds().IntegerWidth();
|
srcW = src->Bounds().IntegerWidth();
|
||||||
srcH = src->Bounds().IntegerHeight();
|
srcH = src->Bounds().IntegerHeight();
|
||||||
destW = dest->Bounds().IntegerWidth();
|
destW = dest->Bounds().IntegerWidth();
|
||||||
destH = dest->Bounds().IntegerHeight();
|
destH = dest->Bounds().IntegerHeight();
|
||||||
|
|
||||||
srcBits = (uchar*)src->Bits();
|
srcBits = (uchar*)src->Bits();
|
||||||
destBits = (uchar*)dest->Bits();
|
destBits = (uchar*)dest->Bits();
|
||||||
srcBPR = src->BytesPerRow();
|
srcBPR = src->BytesPerRow();
|
||||||
destBPR = dest->BytesPerRow();
|
destBPR = dest->BytesPerRow();
|
||||||
|
|
||||||
destDataRow = destBits + fromRow * destBPR;
|
destDataRow = destBits + fromRow * destBPR;
|
||||||
|
|
||||||
const float deltaX = (srcW + 1.0) / (destW + 1.0);
|
const float deltaX = (srcW + 1.0) / (destW + 1.0);
|
||||||
const float deltaY = (srcH + 1.0) / (destH + 1.0);
|
const float deltaY = (srcH + 1.0) / (destH + 1.0);
|
||||||
const float deltaXY = deltaX * deltaY;
|
const float deltaXY = deltaX * deltaY;
|
||||||
@@ -642,61 +642,61 @@ Scaler::DownScaleBilinear(intType fromRow, int32 toRow)
|
|||||||
for (x = 0; x <= destW; x ++, cd ++) {
|
for (x = 0; x <= destW; x ++, cd ++) {
|
||||||
const float fFromX = x * deltaX;
|
const float fFromX = x * deltaX;
|
||||||
const float fToX = fFromX + deltaX;
|
const float fToX = fFromX + deltaX;
|
||||||
|
|
||||||
cd->from = (intType)fFromX;
|
cd->from = (intType)fFromX;
|
||||||
cd->to = (intType)fToX;
|
cd->to = (intType)fToX;
|
||||||
|
|
||||||
cd->alpha0 = 1.0 - (fFromX - cd->from);
|
cd->alpha0 = 1.0 - (fFromX - cd->from);
|
||||||
cd->alpha1 = fToX - cd->to;
|
cd->alpha1 = fToX - cd->to;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (y = fromRow; IsRunning() && y <= toRow; y ++, destDataRow += destBPR) {
|
for (y = fromRow; IsRunning() && y <= toRow; y ++, destDataRow += destBPR) {
|
||||||
const float fFromY = y * deltaY;
|
const float fFromY = y * deltaY;
|
||||||
const float fToY = fFromY + deltaY;
|
const float fToY = fFromY + deltaY;
|
||||||
|
|
||||||
const intType fromY = (intType)fFromY;
|
const intType fromY = (intType)fFromY;
|
||||||
const intType toY = (intType)fToY;
|
const intType toY = (intType)fToY;
|
||||||
|
|
||||||
const float a0Y = 1.0 - (fFromY - fromY);
|
const float a0Y = 1.0 - (fFromY - fromY);
|
||||||
const float a1Y = fToY - toY;
|
const float a1Y = fToY - toY;
|
||||||
|
|
||||||
const uchar* srcDataRow = srcBits + fromY * srcBPR;
|
const uchar* srcDataRow = srcBits + fromY * srcBPR;
|
||||||
destData = destDataRow;
|
destData = destDataRow;
|
||||||
|
|
||||||
cd = columnData;
|
cd = columnData;
|
||||||
for (x = 0; x <= destW; x ++, destData += kBPP, cd ++) {
|
for (x = 0; x <= destW; x ++, destData += kBPP, cd ++) {
|
||||||
const intType fromX = cd->from;
|
const intType fromX = cd->from;
|
||||||
const intType toX = cd->to;
|
const intType toX = cd->to;
|
||||||
|
|
||||||
const float a0X = cd->alpha0;
|
const float a0X = cd->alpha0;
|
||||||
const float a1X = cd->alpha1;
|
const float a1X = cd->alpha1;
|
||||||
|
|
||||||
srcData = srcDataRow + fromX * kBPP;
|
srcData = srcDataRow + fromX * kBPP;
|
||||||
|
|
||||||
float totalSum[3];
|
float totalSum[3];
|
||||||
float sum[3];
|
float sum[3];
|
||||||
|
|
||||||
RowValues(sum, srcData, srcW, fromX, toX, a0X, a1X, kBPP);
|
RowValues(sum, srcData, srcW, fromX, toX, a0X, a1X, kBPP);
|
||||||
totalSum[0] = a0Y * sum[0];
|
totalSum[0] = a0Y * sum[0];
|
||||||
totalSum[1] = a0Y * sum[1];
|
totalSum[1] = a0Y * sum[1];
|
||||||
totalSum[2] = a0Y * sum[2];
|
totalSum[2] = a0Y * sum[2];
|
||||||
|
|
||||||
srcData += srcBPR;
|
srcData += srcBPR;
|
||||||
|
|
||||||
for (int32 r = fromY+1; r < toY; r ++, srcData += srcBPR) {
|
for (int32 r = fromY+1; r < toY; r ++, srcData += srcBPR) {
|
||||||
RowValues(sum, srcData, srcW, fromX, toX, a0X, a1X, kBPP);
|
RowValues(sum, srcData, srcW, fromX, toX, a0X, a1X, kBPP);
|
||||||
totalSum[0] += sum[0];
|
totalSum[0] += sum[0];
|
||||||
totalSum[1] += sum[1];
|
totalSum[1] += sum[1];
|
||||||
totalSum[2] += sum[2];
|
totalSum[2] += sum[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toY <= srcH) {
|
if (toY <= srcH) {
|
||||||
RowValues(sum, srcData, srcW, fromX, toX, a0X, a1X, kBPP);
|
RowValues(sum, srcData, srcW, fromX, toX, a0X, a1X, kBPP);
|
||||||
totalSum[0] += a1Y * sum[0];
|
totalSum[0] += a1Y * sum[0];
|
||||||
totalSum[1] += a1Y * sum[1];
|
totalSum[1] += a1Y * sum[1];
|
||||||
totalSum[2] += a1Y * sum[2];
|
totalSum[2] += a1Y * sum[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
destData[0] = static_cast<uchar>(totalSum[0] / deltaXY);
|
destData[0] = static_cast<uchar>(totalSum[0] / deltaXY);
|
||||||
destData[1] = static_cast<uchar>(totalSum[1] / deltaXY);
|
destData[1] = static_cast<uchar>(totalSum[1] / deltaXY);
|
||||||
destData[2] = static_cast<uchar>(totalSum[2] / deltaXY);
|
destData[2] = static_cast<uchar>(totalSum[2] / deltaXY);
|
||||||
@@ -715,7 +715,7 @@ typedef struct {
|
|||||||
intType error[3];
|
intType error[3];
|
||||||
} DitheringColumnData;
|
} DitheringColumnData;
|
||||||
|
|
||||||
uchar
|
uchar
|
||||||
Scaler::Limit(intType value)
|
Scaler::Limit(intType value)
|
||||||
{
|
{
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
@@ -749,7 +749,7 @@ Scaler::Dither(int32 fromRow, int32 toRow)
|
|||||||
DitheringColumnData* cd;
|
DitheringColumnData* cd;
|
||||||
BScreen screen;
|
BScreen screen;
|
||||||
intType error[3], err[3];
|
intType error[3], err[3];
|
||||||
|
|
||||||
src = fScaledImage;
|
src = fScaledImage;
|
||||||
dest = GetDestImage();
|
dest = GetDestImage();
|
||||||
|
|
||||||
@@ -757,20 +757,20 @@ Scaler::Dither(int32 fromRow, int32 toRow)
|
|||||||
ASSERT(dest->ColorSpace() == B_CMAP8);
|
ASSERT(dest->ColorSpace() == B_CMAP8);
|
||||||
ASSERT(src->Bounds().IntegerWidth() == dest->Bounds().IntegerWidth());
|
ASSERT(src->Bounds().IntegerWidth() == dest->Bounds().IntegerWidth());
|
||||||
ASSERT(src->Bounds().IntegerHeight() == dest->Bounds().IntegerHeight());
|
ASSERT(src->Bounds().IntegerHeight() == dest->Bounds().IntegerHeight());
|
||||||
|
|
||||||
destW = dest->Bounds().IntegerWidth();
|
destW = dest->Bounds().IntegerWidth();
|
||||||
destH = dest->Bounds().IntegerHeight();
|
destH = dest->Bounds().IntegerHeight();
|
||||||
|
|
||||||
srcBits = (uchar*)src->Bits();
|
srcBits = (uchar*)src->Bits();
|
||||||
srcBPR = src->BytesPerRow();
|
srcBPR = src->BytesPerRow();
|
||||||
destBits = (uchar*)dest->Bits();
|
destBits = (uchar*)dest->Bits();
|
||||||
destBPR = dest->BytesPerRow();
|
destBPR = dest->BytesPerRow();
|
||||||
|
|
||||||
// Allocate space for sentinel at left and right bounds,
|
// Allocate space for sentinel at left and right bounds,
|
||||||
// so that columnData[-1] and columnData[destW+1] can be safely accessed
|
// so that columnData[-1] and columnData[destW+1] can be safely accessed
|
||||||
columnData0 = new DitheringColumnData[destW+3];
|
columnData0 = new DitheringColumnData[destW+3];
|
||||||
columnData = columnData0 + 1;
|
columnData = columnData0 + 1;
|
||||||
|
|
||||||
// clear error
|
// clear error
|
||||||
cd = columnData;
|
cd = columnData;
|
||||||
for (x = destW; x >= 0; x --, cd ++) {
|
for (x = destW; x >= 0; x --, cd ++) {
|
||||||
@@ -787,38 +787,38 @@ Scaler::Dither(int32 fromRow, int32 toRow)
|
|||||||
for (x = 0; x <= destW; x ++, srcData += kBPP, destData += 1) {
|
for (x = 0; x <= destW; x ++, srcData += kBPP, destData += 1) {
|
||||||
rgb_color color, actualColor;
|
rgb_color color, actualColor;
|
||||||
uint8 index;
|
uint8 index;
|
||||||
|
|
||||||
color.red = Limit(srcData[2] + error[0] / 16);
|
color.red = Limit(srcData[2] + error[0] / 16);
|
||||||
color.green = Limit(srcData[1] + error[1] / 16);
|
color.green = Limit(srcData[1] + error[1] / 16);
|
||||||
color.blue = Limit(srcData[0] + error[2] / 16);
|
color.blue = Limit(srcData[0] + error[2] / 16);
|
||||||
|
|
||||||
index = screen.IndexForColor(color);
|
index = screen.IndexForColor(color);
|
||||||
actualColor = screen.ColorForIndex(index);
|
actualColor = screen.ColorForIndex(index);
|
||||||
|
|
||||||
*destData = index;
|
*destData = index;
|
||||||
|
|
||||||
err[0] = color.red - actualColor.red;
|
err[0] = color.red - actualColor.red;
|
||||||
err[1] = color.green -actualColor.green;
|
err[1] = color.green -actualColor.green;
|
||||||
err[2] = color.blue -actualColor.blue;
|
err[2] = color.blue -actualColor.blue;
|
||||||
|
|
||||||
// distribute error
|
// distribute error
|
||||||
// get error for next pixel
|
// get error for next pixel
|
||||||
cd = &columnData[x+1];
|
cd = &columnData[x+1];
|
||||||
error[0] = cd->error[0] + 7 * err[0];
|
error[0] = cd->error[0] + 7 * err[0];
|
||||||
error[1] = cd->error[1] + 7 * err[1];
|
error[1] = cd->error[1] + 7 * err[1];
|
||||||
error[2] = cd->error[2] + 7 * err[2];
|
error[2] = cd->error[2] + 7 * err[2];
|
||||||
|
|
||||||
// set error for right pixel below current pixel
|
// set error for right pixel below current pixel
|
||||||
cd->error[0] = err[0];
|
cd->error[0] = err[0];
|
||||||
cd->error[1] = err[1];
|
cd->error[1] = err[1];
|
||||||
cd->error[2] = err[2];
|
cd->error[2] = err[2];
|
||||||
|
|
||||||
// add error for pixel below current pixel
|
// add error for pixel below current pixel
|
||||||
cd --;
|
cd --;
|
||||||
cd->error[0] += 5 * err[0];
|
cd->error[0] += 5 * err[0];
|
||||||
cd->error[1] += 5 * err[1];
|
cd->error[1] += 5 * err[1];
|
||||||
cd->error[2] += 5 * err[2];
|
cd->error[2] += 5 * err[2];
|
||||||
|
|
||||||
// add error for left pixel below current pixel
|
// add error for left pixel below current pixel
|
||||||
cd --;
|
cd --;
|
||||||
cd->error[0] += 3 * err[0];
|
cd->error[0] += 3 * err[0];
|
||||||
@@ -837,38 +837,38 @@ Scaler::Dither(int32 fromRow, int32 toRow)
|
|||||||
for (x = 0; x <= destW; x ++, srcData -= kBPP, destData -= 1) {
|
for (x = 0; x <= destW; x ++, srcData -= kBPP, destData -= 1) {
|
||||||
rgb_color color, actualColor;
|
rgb_color color, actualColor;
|
||||||
uint8 index;
|
uint8 index;
|
||||||
|
|
||||||
color.red = Limit(srcData[2] + error[0] / 16);
|
color.red = Limit(srcData[2] + error[0] / 16);
|
||||||
color.green = Limit(srcData[1] + error[1] / 16);
|
color.green = Limit(srcData[1] + error[1] / 16);
|
||||||
color.blue = Limit(srcData[0] + error[2] / 16);
|
color.blue = Limit(srcData[0] + error[2] / 16);
|
||||||
|
|
||||||
index = screen.IndexForColor(color);
|
index = screen.IndexForColor(color);
|
||||||
actualColor = screen.ColorForIndex(index);
|
actualColor = screen.ColorForIndex(index);
|
||||||
|
|
||||||
*destData = index;
|
*destData = index;
|
||||||
|
|
||||||
err[0] = color.red - actualColor.red;
|
err[0] = color.red - actualColor.red;
|
||||||
err[1] = color.green -actualColor.green;
|
err[1] = color.green -actualColor.green;
|
||||||
err[2] = color.blue -actualColor.blue;
|
err[2] = color.blue -actualColor.blue;
|
||||||
|
|
||||||
// distribute error
|
// distribute error
|
||||||
// get error for next pixel
|
// get error for next pixel
|
||||||
cd = &columnData[x-1];
|
cd = &columnData[x-1];
|
||||||
error[0] = cd->error[0] + 7 * err[0];
|
error[0] = cd->error[0] + 7 * err[0];
|
||||||
error[1] = cd->error[1] + 7 * err[1];
|
error[1] = cd->error[1] + 7 * err[1];
|
||||||
error[2] = cd->error[2] + 7 * err[2];
|
error[2] = cd->error[2] + 7 * err[2];
|
||||||
|
|
||||||
// set error for left pixel below current pixel
|
// set error for left pixel below current pixel
|
||||||
cd->error[0] = err[0];
|
cd->error[0] = err[0];
|
||||||
cd->error[1] = err[1];
|
cd->error[1] = err[1];
|
||||||
cd->error[2] = err[2];
|
cd->error[2] = err[2];
|
||||||
|
|
||||||
// add error for pixel below current pixel
|
// add error for pixel below current pixel
|
||||||
cd ++;
|
cd ++;
|
||||||
cd->error[0] += 5 * err[0];
|
cd->error[0] += 5 * err[0];
|
||||||
cd->error[1] += 5 * err[1];
|
cd->error[1] += 5 * err[1];
|
||||||
cd->error[2] += 5 * err[2];
|
cd->error[2] += 5 * err[2];
|
||||||
|
|
||||||
// add error for right pixel below current pixel
|
// add error for right pixel below current pixel
|
||||||
cd ++;
|
cd ++;
|
||||||
cd->error[0] += 3 * err[0];
|
cd->error[0] += 3 * err[0];
|
||||||
@@ -888,7 +888,7 @@ Scaler::GetNumberOfUnits()
|
|||||||
|
|
||||||
void
|
void
|
||||||
Scaler::Run(int32 i, int32 n)
|
Scaler::Run(int32 i, int32 n)
|
||||||
{
|
{
|
||||||
int32 from, to, height, imageHeight;
|
int32 from, to, height, imageHeight;
|
||||||
imageHeight = GetDestImage()->Bounds().IntegerHeight() + 1;
|
imageHeight = GetDestImage()->Bounds().IntegerHeight() + 1;
|
||||||
height = imageHeight / n;
|
height = imageHeight / n;
|
||||||
@@ -930,28 +930,28 @@ ImageProcessor::CreateDestImage(BBitmap* /* srcImage */)
|
|||||||
color_space cs;
|
color_space cs;
|
||||||
BBitmap* bm;
|
BBitmap* bm;
|
||||||
BRect rect;
|
BRect rect;
|
||||||
|
|
||||||
if (GetSrcImage() == NULL) return NULL;
|
if (GetSrcImage() == NULL) return NULL;
|
||||||
|
|
||||||
cs = GetSrcImage()->ColorSpace();
|
cs = GetSrcImage()->ColorSpace();
|
||||||
fBPP = BytesPerPixel(cs);
|
fBPP = BytesPerPixel(cs);
|
||||||
if (fBPP < 1) return NULL;
|
if (fBPP < 1) return NULL;
|
||||||
|
|
||||||
fWidth = GetSrcImage()->Bounds().IntegerWidth();
|
fWidth = GetSrcImage()->Bounds().IntegerWidth();
|
||||||
fHeight = GetSrcImage()->Bounds().IntegerHeight();
|
fHeight = GetSrcImage()->Bounds().IntegerHeight();
|
||||||
|
|
||||||
if (fOp == kRotateClockwise || fOp == kRotateCounterClockwise) {
|
if (fOp == kRotateClockwise || fOp == kRotateCounterClockwise) {
|
||||||
rect.Set(0, 0, fHeight, fWidth);
|
rect.Set(0, 0, fHeight, fWidth);
|
||||||
} else {
|
} else {
|
||||||
rect.Set(0, 0, fWidth, fHeight);
|
rect.Set(0, 0, fWidth, fHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
bm = new BBitmap(rect, cs);
|
bm = new BBitmap(rect, cs);
|
||||||
if (!IsBitmapValid(bm)) {
|
if (!IsBitmapValid(bm)) {
|
||||||
delete bm;
|
delete bm;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fSrcBPR = GetSrcImage()->BytesPerRow();
|
fSrcBPR = GetSrcImage()->BytesPerRow();
|
||||||
fDestBPR = bm->BytesPerRow();
|
fDestBPR = bm->BytesPerRow();
|
||||||
|
|
||||||
@@ -964,7 +964,7 @@ ImageProcessor::GetNumberOfUnits()
|
|||||||
return GetSrcImage()->Bounds().IntegerHeight() + 1;
|
return GetSrcImage()->Bounds().IntegerHeight() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32
|
int32
|
||||||
ImageProcessor::BytesPerPixel(color_space cs) const
|
ImageProcessor::BytesPerPixel(color_space cs) const
|
||||||
{
|
{
|
||||||
switch (cs) {
|
switch (cs) {
|
||||||
@@ -1042,7 +1042,7 @@ ImageProcessor::Run(int32 i, int32 n)
|
|||||||
} else {
|
} else {
|
||||||
to = from + height - 1;
|
to = from + height - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 x, y, destX, destY;
|
int32 x, y, destX, destY;
|
||||||
const uchar* src = (uchar*)GetSrcImage()->Bits();
|
const uchar* src = (uchar*)GetSrcImage()->Bits();
|
||||||
uchar* dest = (uchar*)GetDestImage()->Bits();
|
uchar* dest = (uchar*)GetDestImage()->Bits();
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
SubDir HAIKU_TOP src apps showimage ;
|
SubDir HAIKU_TOP src apps showimage ;
|
||||||
|
|
||||||
|
UsePrivateSystemHeaders ;
|
||||||
UsePrivateHeaders tracker shared ;
|
UsePrivateHeaders tracker shared ;
|
||||||
UsePublicHeaders [ FDirName be_apps Tracker ] ;
|
UsePublicHeaders [ FDirName be_apps Tracker ] ;
|
||||||
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
|
||||||
|
|
||||||
Application ShowImage :
|
Application ShowImage :
|
||||||
ShowImageApp.cpp
|
ShowImageApp.cpp
|
||||||
ShowImageSettings.cpp
|
ShowImageSettings.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user