Some cleanup:

* fixed all warnings.
* moved functions from the header into the source file.
* added a TODO about the incorrect usage of BFont::Size() as font height
  in pixel!!
* renamed some stuff to match our style guide a bit better - could need
  some more work here, it's still pretty messy.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15009 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-17 22:10:58 +00:00
parent 740ccdc27e
commit d8e2fb507a
3 changed files with 575 additions and 664 deletions
File diff suppressed because it is too large Load Diff
+20 -401
View File
@@ -56,12 +56,6 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <jpeglib.h>
//----------------------------------------------------------------------------
//
// Define & Global variables declaration
//
//----------------------------------------------------------------------------
// Settings
#define SETTINGS_FILE "OpenJPEGTranslator"
#define SETTINGS_PATH "/boot/home/config/settings"
@@ -88,21 +82,11 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define VIEW_LABEL_PHOTOSHOPCMYK "Use CMYK code with 0 for 100% ink coverage"
#define VIEW_LABEL_SHOWREADERRORBOX "Show warning messages"
// This will be used true if Settings are running, else false
extern bool AreSettingsRunning;
//----------------------------------------------------------------------------
//
// Classes
//
//----------------------------------------------------------------------------
//---------------------------------------------------
// Settings storage structure
//---------------------------------------------------
struct SETTINGS
{
struct jpeg_settings {
// compression
uchar Smoothing; // default: 0
uchar Quality; // default: 95
@@ -120,8 +104,7 @@ struct SETTINGS
// Slider used in TranslatorView
// With status showing actual value
//---------------------------------------------------
class SSlider : public BSlider
{
class SSlider : public BSlider {
public:
SSlider(BRect frame, const char *name, const char *label, BMessage *message, int32 minValue, int32 maxValue, orientation posture = B_HORIZONTAL, thumb_style thumbType = B_BLOCK_THUMB, uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
char* UpdateText() const;
@@ -135,8 +118,7 @@ class SSlider : public BSlider
//---------------------------------------------------
// Basic view class with resizing to needed size
//---------------------------------------------------
class SView : public BView
{
class SView : public BView {
public:
SView(const char *name, float x = 0, float y = 0)
:BView( BRect(x,y,x,y), name, B_FOLLOW_NONE, B_WILL_DRAW)
@@ -174,15 +156,14 @@ class SView : public BView
//---------------------------------------------------
// Configuration view for reading settings
//---------------------------------------------------
class TranslatorReadView : public SView
{
class TranslatorReadView : public SView {
public:
TranslatorReadView(const char *name, SETTINGS *settings, float x = 0, float y = 0);
TranslatorReadView(const char *name, jpeg_settings *settings, float x = 0, float y = 0);
void AttachedToWindow();
void MessageReceived(BMessage *message);
private:
SETTINGS *Settings;
jpeg_settings *fSettings;
BCheckBox *alwaysrgb32;
BCheckBox *photoshopCMYK;
BCheckBox *showerrorbox;
@@ -191,15 +172,14 @@ class TranslatorReadView : public SView
//---------------------------------------------------
// Configuration view for writing settings
//---------------------------------------------------
class TranslatorWriteView : public SView
{
class TranslatorWriteView : public SView {
public:
TranslatorWriteView(const char *name, SETTINGS *settings, float x = 0, float y = 0);
TranslatorWriteView(const char *name, jpeg_settings *settings, float x = 0, float y = 0);
void AttachedToWindow();
void MessageReceived(BMessage *message);
private:
SETTINGS *Settings;
jpeg_settings *fSettings;
SSlider *quality;
SSlider *smoothing;
BCheckBox *progress;
@@ -211,8 +191,7 @@ class TranslatorWriteView : public SView
//---------------------------------------------------
// About view
//---------------------------------------------------
class TranslatorAboutView : public SView
{
class TranslatorAboutView : public SView {
public:
TranslatorAboutView(const char *name, float x = 0, float y = 0);
};
@@ -220,145 +199,31 @@ class TranslatorAboutView : public SView
//---------------------------------------------------
// Configuration view
//---------------------------------------------------
class TranslatorView : public SView
{
class TranslatorView : public SView {
public:
TranslatorView(const char *name);
~TranslatorView() { AreSettingsRunning = false; };
~TranslatorView();
void AttachedToWindow();
void Draw(BRect updateRect);
void MouseDown(BPoint where);
private:
SETTINGS Settings;
int32 tabWidth;
int32 tabHeight;
int32 activeChild;
jpeg_settings fSettings;
int32 fTabWidth;
int32 fTabHeight;
int32 fActiveChild;
};
//---------------------------------------------------
// Window used for configuration
//---------------------------------------------------
class TranslatorWindow : public BWindow
{
class TranslatorWindow : public BWindow {
public:
TranslatorWindow(bool quit_on_close = true);
TranslatorWindow(bool quitOnClose = true);
};
//----------------------------------------------------------------------------
//
// Functions :: Settings
//
//----------------------------------------------------------------------------
//---------------------------------------------------
// Make Settings to defaults
//---------------------------------------------------
inline void
LoadDefaultSettings(SETTINGS *Settings)
{
Settings->Smoothing = 0;
Settings->Quality = 95;
Settings->Progressive = true;
Settings->OptimizeColors = true;
Settings->SmallerFile = false;
Settings->B_GRAY1_as_B_RGB24 = false;
Settings->Always_B_RGB32 = true;
Settings->PhotoshopCMYK = true;
Settings->ShowReadWarningBox = true;
}
//---------------------------------------------------
// Save Settings to config file
//---------------------------------------------------
inline void
SaveSettings(SETTINGS *Settings)
{
// Make path to settings file
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) {
path.SetTo(SETTINGS_PATH);
path.Append(SETTINGS_FILE);
} else
path.Append(SETTINGS_FILE);
// Open settings file (create it if there's no file) and write settings
FILE *file = NULL;
if ((file = fopen( path.Path(), "wb+"))) {
fwrite(Settings, sizeof(SETTINGS), 1, file);
fclose(file);
}
}
//---------------------------------------------------
// Return true if Settings were run, false if not
//---------------------------------------------------
inline bool
SettingsChangedAlert()
{
// If settings view wasn't already initialized (settings not running)
// and user wants to run settings
if (!AreSettingsRunning && (new BAlert("Different settings file", "JPEG settings were set to default because of incompatible settings file.", "Configure settings", "OK", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go() == 0) {
// Create settings window (with no quit on close!), launch it and wait until it's closed
status_t err;
TranslatorWindow *window = new TranslatorWindow(false);
window->Show();
wait_for_thread(window->Thread(), &err);
return true;
}
return false;
}
//---------------------------------------------------
// Load settings from config file
// If can't find it make them default and try to save
//---------------------------------------------------
inline void
LoadSettings(SETTINGS *Settings)
{
// Make path to settings file
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) {
path.SetTo(SETTINGS_PATH);
path.Append(SETTINGS_FILE);
} else
path.Append(SETTINGS_FILE);
// Open settings file (create it if there's no file) and write settings
FILE *file = NULL;
if ((file = fopen( path.Path(), "rb"))) {
if ( !fread(Settings, sizeof(SETTINGS), 1, file)) {
// Settings struct has changed size
// Load default settings, and Save them
fclose(file);
LoadDefaultSettings(Settings);
SaveSettings(Settings);
// Tell user settings were changed to default, and ask to run settings panel or not
if (SettingsChangedAlert())
// User configured settings, load them again
LoadSettings(Settings);
} else
fclose(file);
} else if ((file = fopen( path.Path(), "wb+"))) {
LoadDefaultSettings(Settings);
fwrite(Settings, sizeof(SETTINGS), 1, file);
fclose(file);
// Tell user settings were changed to default, and ask to run settings panel or not
if (SettingsChangedAlert())
// User configured settings, load them again
LoadSettings(Settings);
}
}
//----------------------------------------------------------------------------
//
// Functions
//
//----------------------------------------------------------------------------
//---------------------------------------------------
// "Initializers" for jpeglib
// based on default ones,
@@ -373,7 +238,7 @@ EXTERN(void) be_jpeg_stdio_dest(j_compress_ptr cinfo, BPositionIO *outfile); //
// modified to use settings
// (so user can decide to show dialog-boxes or not)
//---------------------------------------------------
EXTERN(struct jpeg_error_mgr *) be_jpeg_std_error (struct jpeg_error_mgr * err, SETTINGS * settings); // from "be_jerror.cpp"
EXTERN(struct jpeg_error_mgr *) be_jpeg_std_error (struct jpeg_error_mgr * err, jpeg_settings * settings); // from "be_jerror.cpp"
//---------------------------------------------------
// Main functions of translator :)
@@ -383,250 +248,4 @@ status_t Compress(BPositionIO *in, BPositionIO *out);
status_t Decompress(BPositionIO *in, BPositionIO *out);
status_t Error(j_common_ptr cinfo, status_t error = B_ERROR);
//---------------------------------------------------
// GRAY1 to GRAY8
//---------------------------------------------------
inline void
convert_from_gray1_to_gray8(uchar *in, uchar *out, int in_bytes)
{
const color_map * map = system_colors();
int32 index = 0;
int32 index2 = 0;
while (index < in_bytes) {
unsigned char c = in[index++];
for (int b = 128; b; b = b>>1) {
unsigned char color;
if (c & b)
color = 0;
else
color = 255;
out[index2++] = color;
}
}
}
//---------------------------------------------------
// GRAY1 to RGB 8:8:8
//---------------------------------------------------
inline void
convert_from_gray1_to_24(uchar *in, uchar *out, int in_bytes)
{
const color_map * map = system_colors();
int32 index = 0;
int32 index2 = 0;
while (index < in_bytes) {
unsigned char c = in[index++];
for (int b = 128; b; b = b>>1) {
unsigned char color;
if (c & b)
color = 0;
else
color = 255;
out[index2++] = color;
out[index2++] = color;
out[index2++] = color;
}
}
}
//---------------------------------------------------
// CMAP8 to RGB 8:8:8
//---------------------------------------------------
inline void
convert_from_cmap8_to_24(uchar *in, uchar *out, int in_bytes)
{
const color_map * map = system_colors();
int32 index = 0;
int32 index2 = 0;
while (index < in_bytes) {
rgb_color color = map->color_list[in[index++]];
out[index2++] = color.red;
out[index2++] = color.green;
out[index2++] = color.blue;
}
}
//---------------------------------------------------
// BGR 1:5:5:5 to RGB 8:8:8
//---------------------------------------------------
inline void
convert_from_15_to_24(uchar *in, uchar *out, int in_bytes)
{
int32 index = 0;
int32 index2 = 0;
int16 in_pixel;
while (index < in_bytes) {
in_pixel = in[index] | (in[index+1] << 8);
index += 2;
out[index2++] = (((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12);
out[index2++] = (((in_pixel & 0x3e0)) >> 2) | (((in_pixel & 0x3e0)) >> 7);
out[index2++] = (((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2);
}
}
//---------------------------------------------------
// RGB 1:5:5:5 to RGB 8:8:8
//---------------------------------------------------
inline void
convert_from_15b_to_24(uchar *in, uchar *out, int in_bytes)
{
int32 index = 0;
int32 index2 = 0;
int16 in_pixel;
while (index < in_bytes) {
in_pixel = in[index+1] | (in[index] << 8);
index += 2;
out[index2++] = (((in_pixel & 0x7c00)) >> 7) | (((in_pixel & 0x7c00)) >> 12);
out[index2++] = (((in_pixel & 0x3e0)) >> 2) | (((in_pixel & 0x3e0)) >> 7);
out[index2++] = (((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2);
}
}
//---------------------------------------------------
// BGR 5:6:5 to RGB 8:8:8
//---------------------------------------------------
inline void
convert_from_16_to_24(uchar *in, uchar *out, int in_bytes)
{
int32 index = 0;
int32 index2 = 0;
int16 in_pixel;
while (index < in_bytes) {
in_pixel = in[index] | (in[index+1] << 8);
index += 2;
out[index2++] = (((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0xf800)) >> 13);
out[index2++] = (((in_pixel & 0x7e0)) >> 3) | (((in_pixel & 0x7e0)) >> 9);
out[index2++] = (((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2);
}
}
//---------------------------------------------------
// RGB 5:6:5 to RGB 8:8:8
//---------------------------------------------------
inline void
convert_from_16b_to_24(uchar *in, uchar *out, int in_bytes)
{
int32 index = 0;
int32 index2 = 0;
int16 in_pixel;
while (index < in_bytes) {
in_pixel = in[index+1] | (in[index] << 8);
index += 2;
out[index2++] = (((in_pixel & 0xf800)) >> 8) | (((in_pixel & 0xf800)) >> 13);
out[index2++] = (((in_pixel & 0x7e0)) >> 3) | (((in_pixel & 0x7e0)) >> 9);
out[index2++] = (((in_pixel & 0x1f)) << 3) | (((in_pixel & 0x1f)) >> 2);
}
}
//---------------------------------------------------
// BGR 8:8:8 to RGB 8:8:8
//---------------------------------------------------
inline void
convert_from_24_to_24(uchar *in, uchar *out, int in_bytes)
{
int32 index = 0;
int32 index2 = 0;
while (index < in_bytes) {
out[index2++] = in[index+2];
out[index2++] = in[index+1];
out[index2++] = in[index];
index+=3;
}
}
//---------------------------------------------------
// BGRx 8:8:8:8 to RGB 8:8:8
//---------------------------------------------------
inline void
convert_from_32_to_24(uchar *in, uchar *out, int in_bytes)
{
int32 index = 0;
int32 index2 = 0;
while (index < in_bytes) {
out[index2++] = in[index+2];
out[index2++] = in[index+1];
out[index2++] = in[index];
index+=4;
}
}
//---------------------------------------------------
// xRGB 8:8:8:8 to RGB 8:8:8
//---------------------------------------------------
inline void
convert_from_32b_to_24(uchar *in, uchar *out, int in_bytes)
{
int32 index = 0;
int32 index2 = 0;
while (index < in_bytes) {
index++;
out[index2++] = in[index++];
out[index2++] = in[index++];
out[index2++] = in[index++];
}
}
//---------------------------------------------------
// CMYK 8:8:8:8 to RGB32 8:8:8:8
// Version for Adobe Photoshop files (0 for 100% ink)
//---------------------------------------------------
inline void
convert_from_CMYK_to_32_photoshop (uchar *in, uchar *out, int out_bytes)
{
int32 index = 0;
int32 index2 = 0;
int32 black = 0;
while (index < out_bytes) {
black = in[index2+3];
out[index++] = in[index2+2]*black/255;
out[index++] = in[index2+1]*black/255;
out[index++] = in[index2]*black/255;
out[index++] = 255;
index2 += 4;
}
}
//---------------------------------------------------
// CMYK 8:8:8:8 to RGB32 8:8:8:8
// !!! UNTESTED !!!
//---------------------------------------------------
inline void
convert_from_CMYK_to_32 (uchar *in, uchar *out, int out_bytes)
{
int32 index = 0;
int32 index2 = 0;
int32 black = 0;
while (index < out_bytes) {
black = 255 - in[index2+3];
out[index++] = ((255-in[index2+2])*black)/255;
out[index++] = ((255-in[index2+1])*black)/255;
out[index++] = ((255-in[index2])*black)/255;
out[index++] = 255;
index2 += 4;
}
}
//---------------------------------------------------
// RGB24 8:8:8 to xRGB 8:8:8:8
//---------------------------------------------------
inline void
convert_from_24_to_32(uchar *in, uchar *out, int out_bytes)
{
int32 index = 0;
int32 index2 = 0;
while (index < out_bytes) {
out[index++] = in[index2+2];
out[index++] = in[index2+1];
out[index++] = in[index2];
out[index++] = 255;
index2 += 3;
}
}
#endif // _JPEGTRANSLATOR_H_
+1 -1
View File
@@ -103,7 +103,7 @@ be_output_message (j_common_ptr cinfo)
*/
GLOBAL(struct jpeg_error_mgr *)
be_jpeg_std_error (struct jpeg_error_mgr * err, SETTINGS *settings)
be_jpeg_std_error (struct jpeg_error_mgr * err, jpeg_settings *settings)
{
jpeg_std_error(err);