hrev52800 adds 5 changesets to branch 'master'
old head: 4bf8cf7a1b011c7e8a7fc75f1921fef8379baf9d
new head: 71aec297511d8693eb083236b4aa080342fb137e
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=71aec297511d+%5E4bf8cf7a1b01
----------------------------------------------------------------------------
72c5a125f154: PPM translator: clang-format
Change-Id: I290f9b369af37d919308759b83c42122f7f309bc
Reviewed-on: https://review.haiku-os.org/c/902
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
32c7f1e79f62: MIME db: identify ASCII variant of PPM; PBM, PGM files
Change-Id: I05574601bfae0094b7509a123cfd19d7fb02e7fd
Reviewed-on: https://review.haiku-os.org/c/903
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
5d57984ba5e7: PPM translator: remove pre-R4 support
Change-Id: I26721cdd767bbf0df2936e97a2af322fed49cabf
Reviewed-on: https://review.haiku-os.org/c/904
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
58913f60e8de: PPM translator: read 1-bit and greyscale files
Change-Id: I0d9de6cb6eca99a78aada00c5299c16668c414f8
Reviewed-on: https://review.haiku-os.org/c/905
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
71aec297511d: PPM translator: use a buffer for reading
Reading the file 1 byte at a time from a BFile is very inefficient.
Add a buffer, which makes things a lot faster (parsing a 200x200 image
used to run for a few seconds with 100% CPU use).
Change-Id: Ie2eea819475c9301fbb6102c41fa05ec2d2ca343
Reviewed-on: https://review.haiku-os.org/c/906
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
[ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]
----------------------------------------------------------------------------
7 files changed, 1021 insertions(+), 1050 deletions(-)
src/add-ons/translators/ppm/PPMMain.cpp | 54 +-
src/add-ons/translators/ppm/PPMTranslator.cpp | 1068 ++++++++++-----------
src/add-ons/translators/ppm/colorspace.cpp | 931 +++++++++---------
src/add-ons/translators/ppm/colorspace.h | 12 +-
src/data/mime_db/image/x-portable-bitmap | 2 +-
src/data/mime_db/image/x-portable-graymap | 2 +-
src/data/mime_db/image/x-portable-pixmap | 2 +-
############################################################################
Commit: 72c5a125f1546a09d828d01db9e0d4959dae9596
URL: https://git.haiku-os.org/haiku/commit/?id=72c5a125f154
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Sat Jan 26 13:53:35 2019 UTC
Committer: waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jan 26 20:46:59 2019 UTC
PPM translator: clang-format
Change-Id: I290f9b369af37d919308759b83c42122f7f309bc
Reviewed-on: https://review.haiku-os.org/c/902
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
----------------------------------------------------------------------------
diff --git a/src/add-ons/translators/ppm/PPMMain.cpp
b/src/add-ons/translators/ppm/PPMMain.cpp
index 7a226055ce..52a2d17e38 100644
--- a/src/add-ons/translators/ppm/PPMMain.cpp
+++ b/src/add-ons/translators/ppm/PPMMain.cpp
@@ -22,58 +22,61 @@
BPoint get_window_origin();
void set_window_origin(BPoint pt);
-class PPMWindow :
- public BWindow
+class PPMWindow : public BWindow
{
public:
- PPMWindow(BRect area) :
- BWindow(area, B_TRANSLATE("PPM Settings"), B_TITLED_WINDOW,
- B_NOT_RESIZABLE | B_NOT_ZOOMABLE |
B_AUTO_UPDATE_SIZE_LIMITS)
- {
- BLayoutBuilder::Group<>(this, B_HORIZONTAL);
- }
+ PPMWindow(BRect area)
+ : BWindow(area, B_TRANSLATE("PPM Settings"), B_TITLED_WINDOW,
+ B_NOT_RESIZABLE | B_NOT_ZOOMABLE |
B_AUTO_UPDATE_SIZE_LIMITS)
+ {
+ BLayoutBuilder::Group<>(this, B_HORIZONTAL);
+ }
~PPMWindow()
- {
- BPoint pt(0,0);
- ConvertToScreen(&pt);
- set_window_origin(pt);
- be_app->PostMessage(B_QUIT_REQUESTED);
- }
+ {
+ BPoint pt(0, 0);
+ ConvertToScreen(&pt);
+ set_window_origin(pt);
+ be_app->PostMessage(B_QUIT_REQUESTED);
+ }
};
int
main()
{
BApplication app("application/x-vnd.Haiku-PPMTranslator");
- BView * v = NULL;
+ BView* v = NULL;
BRect r(0, 0, 1, 1);
if (MakeConfig(NULL, &v, &r)) {
- BAlert * err = new BAlert("Error",
- B_TRANSLATE("Something is wrong with the
PPMTranslator!"),
+ BAlert* err = new BAlert("Error",
+ B_TRANSLATE("Something is wrong with the
PPMTranslator!"),
B_TRANSLATE("OK"));
err->SetFlags(err->Flags() | B_CLOSE_ON_ESCAPE);
err->Go();
return 1;
}
- PPMWindow *w = new PPMWindow(r);
+ PPMWindow* w = new PPMWindow(r);
v->ResizeTo(r.Width(), r.Height());
w->AddChild(v);
BPoint o = get_window_origin();
{
BScreen scrn;
BRect f = scrn.Frame();
- f.InsetBy(10,23);
+ f.InsetBy(10, 23);
/* if not in a good place, start where the cursor is */
if (!f.Contains(o)) {
uint32 i;
v->GetMouse(&o, &i, false);
- o.x -= r.Width()/2;
- o.y -= r.Height()/2;
+ o.x -= r.Width() / 2;
+ o.y -= r.Height() / 2;
/* clamp location to screen */
- if (o.x < f.left) o.x = f.left;
- if (o.y < f.top) o.y = f.top;
- if (o.x > f.right) o.x = f.right;
- if (o.y > f.bottom) o.y = f.bottom;
+ if (o.x < f.left)
+ o.x = f.left;
+ if (o.y < f.top)
+ o.y = f.top;
+ if (o.x > f.right)
+ o.x = f.right;
+ if (o.y > f.bottom)
+ o.y = f.bottom;
}
}
w->MoveTo(o);
@@ -81,4 +84,3 @@ main()
app.Run();
return 0;
}
-
diff --git a/src/add-ons/translators/ppm/PPMTranslator.cpp
b/src/add-ons/translators/ppm/PPMTranslator.cpp
index 9301882515..0e2c6d724d 100644
--- a/src/add-ons/translators/ppm/PPMTranslator.cpp
+++ b/src/add-ons/translators/ppm/PPMTranslator.cpp
@@ -22,13 +22,13 @@
#include <PopUpMenu.h>
#include <Screen.h>
#include <StringView.h>
-#include <TranslatorAddOn.h>
#include <TranslationKit.h>
+#include <TranslatorAddOn.h>
#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <syslog.h>
#include "colorspace.h"
@@ -37,17 +37,25 @@
#define B_TRANSLATION_CONTEXT "PPMTranslator"
#if DEBUG
- #define dprintf(x) printf x
+#define dprintf(x) printf x
#else
- #define dprintf(x)
+#define dprintf(x)
#endif
-#if !defined(_PR3_COMPATIBLE_) /* R4 headers? Else we need to define these
constants. */
- #define B_CMY24 ((color_space)0xC001) /* C[7:0] M[7:0] Y[7:0] No
gray removal done */
- #define B_CMY32 ((color_space)0xC002) /* C[7:0] M[7:0] Y[7:0] X[7:0] No
gray removal done */
- #define B_CMYA32 ((color_space)0xE002) /* C[7:0] M[7:0] Y[7:0] A[7:0] No
gray removal done */
- #define B_CMYK32 ((color_space)0xC003) /* C[7:0] M[7:0] Y[7:0] K[7:0]
*/
+#if !defined(_PR3_COMPATIBLE_) /* R4 headers? Else we need to define these \
+ constants. */
+#define B_CMY24 \
+ ((color_space) 0xC001) /* C[7:0] M[7:0] Y[7:0] No gray
removal \
+ done */
+#define B_CMY32 \
+ ((color_space) 0xC002) /* C[7:0] M[7:0] Y[7:0] X[7:0] No gray
removal \
+ done */
+#define B_CMYA32 \
+ ((color_space) 0xE002) /* C[7:0] M[7:0] Y[7:0] A[7:0] No gray
removal \
+ done */
+#define B_CMYK32 \
+ ((color_space) 0xC003) /* C[7:0] M[7:0] Y[7:0] K[7:0] */
#endif
#define PPM_TRANSLATOR_VERSION 0x100
@@ -56,9 +64,9 @@
char translatorName[] = "PPM images";
char translatorInfo[] = "PPM image translator v1.0.0, " __DATE__;
int32 translatorVersion = PPM_TRANSLATOR_VERSION;
- // Revision: lowest 4 bits
- // Minor: next 4 bits
- // Major: highest 24 bits
+// Revision: lowest 4 bits
+// Minor: next 4 bits
+// Major: highest 24 bits
/* Be reserves all codes with non-lowercase letters in them. */
/* Luckily, there is already a reserved code for PPM. If you */
@@ -66,18 +74,23 @@ int32 translatorVersion = PPM_TRANSLATOR_VERSION;
#define PPM_TYPE 'PPM '
-/* These two data arrays are a really good idea to export from Translators,
but not required. */
-translation_format inputFormats[] = {
- { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.4, 0.8,
"image/x-be-bitmap", "Be Bitmap Format (PPMTranslator)" },
- { PPM_TYPE, B_TRANSLATOR_BITMAP, 0.3, 0.8,
"image/x-portable-pixmap", "PPM image" },
- { 0, 0, 0, 0, "\0", "\0" }
-}; /* optional (else Identify is always called) */
-
-translation_format outputFormats[] = {
- { B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.4, 0.8,
"image/x-be-bitmap", "Be Bitmap Format (PPMTranslator)" },
- { PPM_TYPE, B_TRANSLATOR_BITMAP, 0.3, 0.8,
"image/x-portable-pixmap", "PPM image" },
- { 0, 0, 0, 0, "\0", "\0" }
-}; /* optional (else Translate is called anyway) */
+/* These two data arrays are a really good idea to export from Translators, but
+ * not required. */
+translation_format inputFormats[]
+ = {{B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.4, 0.8,
"image/x-be-bitmap",
+ "Be Bitmap Format (PPMTranslator)"},
+ {PPM_TYPE, B_TRANSLATOR_BITMAP, 0.3, 0.8,
"image/x-portable-pixmap",
+ "PPM image"},
+ {0, 0, 0, 0, "\0",
+ "\0"}}; /* optional (else Identify is always
called) */
+
+translation_format outputFormats[]
+ = {{B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.4, 0.8,
"image/x-be-bitmap",
+ "Be Bitmap Format (PPMTranslator)"},
+ {PPM_TYPE, B_TRANSLATOR_BITMAP, 0.3, 0.8,
"image/x-portable-pixmap",
+ "PPM image"},
+ {0, 0, 0, 0, "\0",
+ "\0"}}; /* optional (else Translate is called
anyway) */
/* Translators that don't export outputFormats */
/* will not be considered by files looking for */
@@ -86,17 +99,18 @@ translation_format outputFormats[] = {
/* We keep our settings in a global struct, and wrap a lock around them.
*/
struct ppm_settings {
- color_space out_space;
- BPoint window_pos;
- bool write_ascii;
- bool settings_touched;
+ color_space out_space;
+ BPoint window_pos;
+ bool write_ascii;
+ bool settings_touched;
};
static BLocker g_settings_lock("PPM settings lock");
static ppm_settings g_settings;
BPoint get_window_origin();
void set_window_origin(BPoint pos);
-BPoint get_window_origin()
+BPoint
+get_window_origin()
{
BPoint ret;
g_settings_lock.Lock();
@@ -105,7 +119,8 @@ BPoint get_window_origin()
return ret;
}
-void set_window_origin(BPoint pos)
+void
+set_window_origin(BPoint pos)
{
g_settings_lock.Lock();
g_settings.window_pos = pos;
@@ -114,141 +129,144 @@ void set_window_origin(BPoint pos)
}
-class PrefsLoader {
+class PrefsLoader
+{
public:
- PrefsLoader(
- const char * str)
- {
- dprintf(("PPMTranslator: PrefsLoader()\n"));
- /* defaults */
- g_settings.out_space = B_NO_COLOR_SPACE;
- g_settings.window_pos = B_ORIGIN;
- g_settings.write_ascii = false;
- g_settings.settings_touched = false;
- BPath path;
- if (find_directory(B_USER_SETTINGS_DIRECTORY,
&path)) {
- path.SetTo("/tmp");
+ PrefsLoader(const char* str)
+ {
+ dprintf(("PPMTranslator: PrefsLoader()\n"));
+ /* defaults */
+ g_settings.out_space = B_NO_COLOR_SPACE;
+ g_settings.window_pos = B_ORIGIN;
+ g_settings.write_ascii = false;
+ g_settings.settings_touched = false;
+ BPath path;
+ if (find_directory(B_USER_SETTINGS_DIRECTORY, &path)) {
+ path.SetTo("/tmp");
+ }
+ path.Append(str);
+ FILE* f = fopen(path.Path(), "r");
+ /* parse text settings file -- this should be a library...
*/
+ if (f) {
+ char line[1024];
+ char name[32];
+ char* ptr;
+ while (true) {
+ line[0] = 0;
+ fgets(line, 1024, f);
+ if (!line[0]) {
+ break;
+ }
+ /* remember: line ends with \n, so printf()s
don't have to */
+ ptr = line;
+ while (isspace(*ptr)) {
+ ptr++;
+ }
+ if (*ptr == '#' || !*ptr) { /* comment or blank
*/
+ continue;
}
- path.Append(str);
- FILE * f = fopen(path.Path(), "r");
- /* parse text settings file -- this should
be a library... */
- if (f) {
- char line[1024];
- char name[32];
- char * ptr;
- while (true) {
- line[0] = 0;
- fgets(line, 1024, f);
- if (!line[0]) {
- break;
+ if (sscanf(ptr, "%31[a-zA-Z_0-9] =", name) !=
1) {
+ syslog(LOG_ERR,
+ "unknown PPMTranslator "
+ "settings line: %s",
+ line);
+ } else {
+ if (!strcmp(name, "color_space")) {
+ while (*ptr != '=') {
+ ptr++;
+ }
+ ptr++;
+ if (sscanf(ptr, "%d", (int*)
&g_settings.out_space)
+ != 1) {
+ syslog(LOG_ERR,
+ "illegal color
space "
+ "in
PPMTranslator settings: %s",
+ ptr);
}
- /* remember: line ends with \n,
so printf()s don't have to */
- ptr = line;
- while (isspace(*ptr)) {
+ } else if (!strcmp(name, "window_pos"))
{
+ while (*ptr != '=') {
ptr++;
}
- if (*ptr == '#' || !*ptr) {
/* comment or blank */
- continue;
+ ptr++;
+ if (sscanf(ptr, "%f,%f",
&g_settings.window_pos.x,
+
&g_settings.window_pos.y)
+ != 2) {
+ syslog(LOG_ERR,
+ "illegal window
position "
+ "in
PPMTranslator settings: %s",
+ ptr);
}
- if (sscanf(ptr,
"%31[a-zA-Z_0-9] =", name) != 1) {
- syslog(LOG_ERR,
"unknown PPMTranslator "
-
"settings line: %s", line);
+ } else if (!strcmp(name,
"write_ascii")) {
+ while (*ptr != '=') {
+ ptr++;
}
- else {
- if (!strcmp(name,
"color_space")) {
- while (*ptr !=
'=') {
- ptr++;
- }
- ptr++;
- if (sscanf(ptr,
"%d",
-
(int*)&g_settings.out_space) != 1) {
-
syslog(LOG_ERR, "illegal color space "
-
"in PPMTranslator settings: %s", ptr);
- }
- }
- else if (!strcmp(name,
"window_pos")) {
- while (*ptr !=
'=') {
- ptr++;
- }
- ptr++;
- if (sscanf(ptr,
"%f,%f",
-
&g_settings.window_pos.x,
-
&g_settings.window_pos.y) != 2) {
-
syslog(LOG_ERR, "illegal window position "
-
"in PPMTranslator settings: %s", ptr);
- }
- }
- else if (!strcmp(name,
"write_ascii")) {
- while (*ptr !=
'=') {
- ptr++;
- }
- ptr++;
- int ascii =
g_settings.write_ascii;
- if (sscanf(ptr,
"%d", &ascii) != 1) {
-
syslog(LOG_ERR, "illegal write_ascii value "
-
"in PPMTranslator settings: %s", ptr);
- }
- else {
-
g_settings.write_ascii = ascii;
- }
- }
- else {
- syslog(LOG_ERR,
-
"unknown PPMTranslator setting: %s", line);
- }
+ ptr++;
+ int ascii =
g_settings.write_ascii;
+ if (sscanf(ptr, "%d", &ascii)
!= 1) {
+ syslog(LOG_ERR,
+ "illegal
write_ascii value "
+ "in
PPMTranslator settings: %s",
+ ptr);
+ } else {
+ g_settings.write_ascii
= ascii;
}
+ } else {
+ syslog(
+ LOG_ERR, "unknown
PPMTranslator setting: %s", line);
}
- fclose(f);
}
}
- ~PrefsLoader()
- {
- /* No need writing settings if there
aren't any */
- if (g_settings.settings_touched) {
- BPath path;
- if
(find_directory(B_USER_SETTINGS_DIRECTORY, &path)) {
- path.SetTo("/tmp");
- }
- path.Append("PPMTranslator_Settings");
- FILE * f = fopen(path.Path(), "w");
- if (f) {
- fprintf(f, "# PPMTranslator
settings version %d.%d.%d\n",
-
static_cast<int>(translatorVersion >> 8),
-
static_cast<int>((translatorVersion >> 4) & 0xf),
-
static_cast<int>(translatorVersion & 0xf));
- fprintf(f, "color_space =
%d\n", g_settings.out_space);
- fprintf(f, "window_pos =
%g,%g\n", g_settings.window_pos.x,
-
g_settings.window_pos.y);
- fprintf(f, "write_ascii =
%d\n", g_settings.write_ascii ? 1 : 0);
- fclose(f);
- }
- }
+ fclose(f);
+ }
+ }
+ ~PrefsLoader()
+ {
+ /* No need writing settings if there aren't any */
+ if (g_settings.settings_touched) {
+ BPath path;
+ if (find_directory(B_USER_SETTINGS_DIRECTORY, &path)) {
+ path.SetTo("/tmp");
+ }
+ path.Append("PPMTranslator_Settings");
+ FILE* f = fopen(path.Path(), "w");
+ if (f) {
+ fprintf(f, "# PPMTranslator settings version
%d.%d.%d\n",
+ static_cast<int>(translatorVersion >>
8),
+ static_cast<int>((translatorVersion >>
4) & 0xf),
+ static_cast<int>(translatorVersion &
0xf));
+ fprintf(f, "color_space = %d\n",
g_settings.out_space);
+ fprintf(f, "window_pos = %g,%g\n",
g_settings.window_pos.x,
+ g_settings.window_pos.y);
+ fprintf(
+ f, "write_ascii = %d\n",
g_settings.write_ascii ? 1 : 0);
+ fclose(f);
}
+ }
+ }
};
PrefsLoader g_prefs_loader("PPMTranslator_Settings");
/* Some prototypes for functions we use. */
-status_t read_ppm_header(BDataIO * io, int * width, int * rowbytes, int *
height,
- int * max, bool * ascii, color_space * space, bool * is_ppm, char **
comment);
-status_t read_bits_header(BDataIO * io, int skipped, int * width, int *
rowbytes,
- int * height, int * max, bool * ascii, color_space * space);
-status_t write_comment(const char * str, BDataIO * io);
-status_t copy_data(BDataIO * in, BDataIO * out, int rowbytes, int out_rowbytes,
+status_t read_ppm_header(BDataIO* io, int* width, int* rowbytes, int* height,
+ int* max, bool* ascii, color_space* space, bool* is_ppm, char**
comment);
+status_t read_bits_header(BDataIO* io, int skipped, int* width, int* rowbytes,
+ int* height, int* max, bool* ascii, color_space* space);
+status_t write_comment(const char* str, BDataIO* io);
+status_t copy_data(BDataIO* in, BDataIO* out, int rowbytes, int out_rowbytes,
int height, int max, bool in_ascii, bool out_ascii, color_space
in_space,
color_space out_space);
- /* Return B_NO_TRANSLATOR if not handling this data. */
- /* Even if inputFormats exists, may be called for data without
hints */
- /* If outType is not 0, must be able to export in wanted format
*/
+/* Return B_NO_TRANSLATOR if not handling this data. */
+/* Even if inputFormats exists, may be called for data without hints
*/
+/* If outType is not 0, must be able to export in wanted format */
status_t
-Identify( /* required */
- BPositionIO * inSource,
- const translation_format * inFormat, /* can beNULL */
- BMessage * ioExtension, /* can be NULL */
- translator_info * outInfo,
- uint32 outType)
+Identify(/* required */
+ BPositionIO* inSource,
+ const translation_format* inFormat, /* can beNULL */
+ BMessage* ioExtension, /* can be NULL */
+ translator_info* outInfo, uint32 outType)
{
dprintf(("PPMTranslator: Identify()\n"));
/* Silence compiler warnings. */
@@ -267,50 +285,54 @@ Identify( /* required */
int width, rowbytes, height, max;
bool ascii, is_ppm;
color_space space;
- status_t err = read_ppm_header(inSource, &width, &rowbytes, &height,
&max, &ascii, &space, &is_ppm, NULL);
+ status_t err = read_ppm_header(inSource, &width, &rowbytes, &height,
&max,
+ &ascii, &space, &is_ppm, NULL);
if (err != B_OK) {
return err;
}
- /* Stuff info into info struct -- Translation Kit will do "translator"
for us. */
+ /* Stuff info into info struct -- Translation Kit will do "translator"
for
+ * us. */
outInfo->group = B_TRANSLATOR_BITMAP;
if (is_ppm) {
outInfo->type = PPM_TYPE;
- outInfo->quality = 0.3; /* no alpha, etc */
- outInfo->capability = 0.8; /* we're pretty good at PPM
reading, though */
+ outInfo->quality = 0.3; /* no alpha, etc */
+ outInfo->capability
+ = 0.8; /* we're pretty good at PPM reading, though */
strlcpy(outInfo->name, B_TRANSLATE("PPM image"),
sizeof(outInfo->name));
strcpy(outInfo->MIME, "image/x-portable-pixmap");
- }
- else {
+ } else {
outInfo->type = B_TRANSLATOR_BITMAP;
- outInfo->quality = 0.4; /* B_TRANSLATOR_BITMAP can do
alpha, at least */
- outInfo->capability = 0.8; /* and we might not know many
variations thereof */
+ outInfo->quality = 0.4; /* B_TRANSLATOR_BITMAP can do alpha, at
least */
+ outInfo->capability
+ = 0.8; /* and we might not know many variations thereof
*/
strlcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format
(PPMTranslator)"),
sizeof(outInfo->name));
- strcpy(outInfo->MIME, "image/x-be-bitmap"); /* this is the
MIME type of B_TRANSLATOR_BITMAP */
+ strcpy(outInfo->MIME, "image/x-be-bitmap"); /* this is the MIME
type of
+
B_TRANSLATOR_BITMAP */
}
return B_OK;
}
- /* Return B_NO_TRANSLATOR if not handling the output format
*/
- /* If outputFormats exists, will only be called for those formats
*/
+/* Return B_NO_TRANSLATOR if not handling the output format */
+/* If outputFormats exists, will only be called for those formats */
status_t
-Translate( /* required */
- BPositionIO * inSource,
- const translator_info * /* inInfo*/ , /* silence compiler warning */
- BMessage * ioExtension, /* can be NULL */
- uint32 outType,
- BPositionIO * outDestination)
+Translate(/* required */
+ BPositionIO* inSource,
+ const translator_info* /* inInfo*/, /* silence compiler warning */
+ BMessage* ioExtension, /* can be NULL */
+ uint32 outType, BPositionIO* outDestination)
{
dprintf(("PPMTranslator: Translate()\n"));
- inSource->Seek(0, SEEK_SET); /* paranoia */
-// inInfo = inInfo; /* silence compiler warning */
+ inSource->Seek(0, SEEK_SET); /* paranoia */
+ // inInfo = inInfo; /* silence compiler warning */
/* Check what we're being asked to produce. */
if (!outType) {
outType = B_TRANSLATOR_BITMAP;
}
- dprintf(("PPMTranslator: outType is '%c%c%c%c'\n", char(outType>>24),
char(outType>>16), char(outType>>8), char(outType)));
+ dprintf(("PPMTranslator: outType is '%c%c%c%c'\n", char(outType >> 24),
+ char(outType >> 16), char(outType >> 8), char(outType)));
if (outType != B_TRANSLATOR_BITMAP && outType != PPM_TYPE) {
return B_NO_TRANSLATOR;
}
@@ -321,11 +343,12 @@ Translate( /* required */
color_space space;
/* Read_ppm_header() will always return with stream at beginning of
data */
/* for both B_TRANSLATOR_BITMAP and PPM_TYPE, and indicate what it is.
*/
- char * comment = NULL;
- status_t err = read_ppm_header(inSource, &width, &rowbytes, &height,
&max, &ascii, &space, &is_ppm, &comment);
+ char* comment = NULL;
+ status_t err = read_ppm_header(inSource, &width, &rowbytes, &height,
&max,
+ &ascii, &space, &is_ppm, &comment);
if (comment != NULL) {
if (ioExtension != NULL) {
-#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
+#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
ioExtension->AddString(B_TRANSLATOR_EXT_COMMENT,
comment);
#else
ioExtension->AddString("/comment", comment);
@@ -353,28 +376,32 @@ Translate( /* required */
g_settings_lock.Lock();
if (outType == PPM_TYPE) {
out_space = B_RGB24_BIG;
- out_rowbytes = 3*width;
- }
- else { /* When outputting to B_TRANSLATOR_BITMAP, follow user's
wishes. */
-#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
- if (!ioExtension ||
ioExtension->FindInt32(B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE, (int32*)&out_space)
||
+ out_rowbytes = 3 * width;
+ } else { /* When outputting to B_TRANSLATOR_BITMAP, follow user's
wishes.
+ */
+#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
+ if (!ioExtension
+ || ioExtension->FindInt32(
+ B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE,
(int32*) &out_space)
+ ||
#else
- if (!ioExtension || ioExtension->FindInt32("bits/space",
(int32*)&out_space) ||
+ if (!ioExtension
+ || ioExtension->FindInt32("bits/space", (int32*)
&out_space) ||
#endif
(out_space == B_NO_COLOR_SPACE)) {
if (g_settings.out_space == B_NO_COLOR_SPACE) {
- switch (space) { /* The 24-bit
versions are pretty silly, use 32 instead. */
- case B_RGB24:
- case B_RGB24_BIG:
- out_space = B_RGB32;
- break;
- default:
- /* use whatever is there */
- out_space = space;
- break;
+ switch (space) { /* The 24-bit versions are
pretty silly, use 32
+
instead. */
+ case B_RGB24:
+ case B_RGB24_BIG:
+ out_space = B_RGB32;
+ break;
+ default:
+ /* use whatever is there */
+ out_space = space;
+ break;
}
- }
- else {
+ } else {
out_space = g_settings.out_space;
}
}
@@ -385,19 +412,22 @@ Translate( /* required */
if (outType == PPM_TYPE) {
dprintf(("PPMTranslator: write PPM\n"));
/* begin PPM header */
- const char * magic;
+ const char* magic;
if (out_ascii)
magic = "P3\n";
else
magic = "P6\n";
err = outDestination->Write(magic, strlen(magic));
- if (err == (long)strlen(magic)) err = 0;
- //comment = NULL;
+ if (err == (long) strlen(magic))
+ err = 0;
+ // comment = NULL;
const char* fsComment;
-#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
- if ((ioExtension != NULL) &&
!ioExtension->FindString(B_TRANSLATOR_EXT_COMMENT, &fsComment)) {
+#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
+ if ((ioExtension != NULL)
+ && !ioExtension->FindString(B_TRANSLATOR_EXT_COMMENT,
&fsComment)) {
#else
- if ((ioExtension != NULL) &&
!ioExtension->FindString("/comment", &fsComment)) {
+ if ((ioExtension != NULL)
+ && !ioExtension->FindString("/comment", &fsComment)) {
#endif
err = write_comment(fsComment, outDestination);
}
@@ -405,249 +435,245 @@ Translate( /* required */
char data[40];
sprintf(data, "%d %d %d\n", width, height, max);
err = outDestination->Write(data, strlen(data));
- if (err == (long)strlen(data)) err = 0;
+ if (err == (long) strlen(data))
+ err = 0;
}
/* header done */
- }
- else {
+ } else {
dprintf(("PPMTranslator: write B_TRANSLATOR_BITMAP\n"));
/* B_TRANSLATOR_BITMAP header */
TranslatorBitmap hdr;
hdr.magic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP);
hdr.bounds.left = B_HOST_TO_BENDIAN_FLOAT(0);
hdr.bounds.top = B_HOST_TO_BENDIAN_FLOAT(0);
- hdr.bounds.right = B_HOST_TO_BENDIAN_FLOAT(width-1);
- hdr.bounds.bottom = B_HOST_TO_BENDIAN_FLOAT(height-1);
+ hdr.bounds.right = B_HOST_TO_BENDIAN_FLOAT(width - 1);
+ hdr.bounds.bottom = B_HOST_TO_BENDIAN_FLOAT(height - 1);
hdr.rowBytes = B_HOST_TO_BENDIAN_INT32(out_rowbytes);
- hdr.colors = (color_space)B_HOST_TO_BENDIAN_INT32(out_space);
- hdr.dataSize = B_HOST_TO_BENDIAN_INT32(out_rowbytes*height);
- dprintf(("rowBytes is %d, width %d, out_space %x, space %x\n",
out_rowbytes, width, out_space, space));
+ hdr.colors = (color_space) B_HOST_TO_BENDIAN_INT32(out_space);
+ hdr.dataSize = B_HOST_TO_BENDIAN_INT32(out_rowbytes * height);
+ dprintf(("rowBytes is %d, width %d, out_space %x, space %x\n",
+ out_rowbytes, width, out_space, space));
err = outDestination->Write(&hdr, sizeof(hdr));
dprintf(("PPMTranslator: Write() returns %" B_PRIx32 "\n",
err));
#if DEBUG
{
- BBitmap * map = new
BBitmap(BRect(0,0,width-1,height-1), out_space);
+ BBitmap* map
+ = new BBitmap(BRect(0, 0, width - 1, height -
1), out_space);
printf("map rb = %" B_PRId32 "\n", map->BytesPerRow());
delete map;
}
#endif
- if (err == sizeof(hdr)) err = 0;
+ if (err == sizeof(hdr))
+ err = 0;
/* header done */
}
if (err != B_OK) {
return err > 0 ? B_IO_ERROR : err;
}
- /* Write data. Luckily, PPM and B_TRANSLATOR_BITMAP both scan from left
to right, top to bottom. */
- return copy_data(inSource, outDestination, rowbytes, out_rowbytes,
height, max, ascii, out_ascii, space, out_space);
+ /* Write data. Luckily, PPM and B_TRANSLATOR_BITMAP both scan from left
to
+ * right, top to bottom. */
+ return copy_data(inSource, outDestination, rowbytes, out_rowbytes,
height,
+ max, ascii, out_ascii, space, out_space);
}
-class PPMView :
- public BView
+class PPMView : public BView
{
public:
- PPMView(
- const char * name,
- uint32 flags) :
- BView(name, flags)
- {
- SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
-
- fTitle = new BStringView("title",
- B_TRANSLATE("PPM image translator"));
- fTitle->SetFont(be_bold_font);
-
- char detail[100];
- int ver = static_cast<int>(translatorVersion);
- sprintf(detail, B_TRANSLATE("Version %d.%d.%d,
%s"), ver >> 8,
- ((ver >> 4) & 0xf),
- (ver & 0xf), __DATE__);
- fDetail = new BStringView("detail", detail);
-
- fBasedOn = new BStringView("basedOn",
- B_TRANSLATE("Based on PPMTranslator
sample code"));
-
- fCopyright = new BStringView("copyright",
- B_TRANSLATE("Sample code copyright
1999, Be Incorporated"));
-
- fMenu = new BPopUpMenu("Color Space");
- fMenu->AddItem(new
BMenuItem(B_TRANSLATE("None"),
- CSMessage(B_NO_COLOR_SPACE)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB
8:8:8 32 bits"),
- CSMessage(B_RGB32)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA
8:8:8:8 32 "
- "bits"), CSMessage(B_RGBA32)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB
5:5:5 16 bits"),
- CSMessage(B_RGB15)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA
5:5:5:1 16 "
- "bits"), CSMessage(B_RGBA15)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB
5:6:5 16 bits"),
- CSMessage(B_RGB16)));
- fMenu->AddItem(new
BMenuItem(B_TRANSLATE("System palette 8 "
- "bits"), CSMessage(B_CMAP8)));
- fMenu->AddSeparatorItem();
- fMenu->AddItem(new
BMenuItem(B_TRANSLATE("Grayscale 8 bits"),
- CSMessage(B_GRAY8)));
- fMenu->AddItem(new
BMenuItem(B_TRANSLATE("Bitmap 1 bit"),
- CSMessage(B_GRAY1)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMY
8:8:8 32 bits"),
- CSMessage(B_CMY32)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMYA
8:8:8:8 32 "
- "bits"), CSMessage(B_CMYA32)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMYK
8:8:8:8 32 "
- "bits"), CSMessage(B_CMYK32)));
- fMenu->AddSeparatorItem();
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB
8:8:8 32 bits "
- "big-endian"), CSMessage(B_RGB32_BIG)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA
8:8:8:8 32 "
- "bits big-endian"),
CSMessage(B_RGBA32_BIG)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB
5:5:5 16 bits "
- "big-endian"), CSMessage(B_RGB15_BIG)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA
5:5:5:1 16 "
- "bits big-endian"),
CSMessage(B_RGBA15_BIG)));
- fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB
5:6:5 16 bits "
- "big-endian"), CSMessage(B_RGB16)));
- fField = new BMenuField(B_TRANSLATE("Input
color space:"),
- fMenu);
- fField->SetViewColor(ViewColor());
- SelectColorSpace(g_settings.out_space);
- BMessage * msg = new BMessage(CHANGE_ASCII);
- fAscii = new BCheckBox(B_TRANSLATE("Write
ASCII"), msg);
- if (g_settings.write_ascii)
- fAscii->SetValue(1);
- fAscii->SetViewColor(ViewColor());
-
- // Build the layout
- BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
- .SetInsets(B_USE_DEFAULT_SPACING)
- .Add(fTitle)
- .Add(fDetail)
- .AddGlue()
- .AddGroup(B_HORIZONTAL)
- .Add(fField)
- .AddGlue()
- .End()
- .Add(fAscii)
- .AddGlue()
- .Add(fBasedOn)
- .Add(fCopyright);
-
- BFont font;
- GetFont(&font);
- SetExplicitPreferredSize(BSize((font.Size() *
350)/12,
- (font.Size() * 200)/12));
- }
- ~PPMView()
- {
- /* nothing here */
- }
-
- enum {
- SET_COLOR_SPACE = 'ppm=',
- CHANGE_ASCII
- };
-
-virtual void MessageReceived(
- BMessage * message)
- {
- if (message->what == SET_COLOR_SPACE) {
- SetSettings(message);
- }
- else if (message->what == CHANGE_ASCII) {
- BMessage msg;
- msg.AddBool("ppm /ascii",
fAscii->Value());
- SetSettings(&msg);
- }
- else {
- BView::MessageReceived(message);
- }
- }
-virtual void AllAttached()
- {
- BView::AllAttached();
- BMessenger msgr(this);
- /* Tell all menu items we're the man.
*/
- for (int ix=0; ix<fMenu->CountItems(); ix++) {
- BMenuItem * i = fMenu->ItemAt(ix);
- if (i) {
- i->SetTarget(msgr);
- }
- }
- fAscii->SetTarget(msgr);
+ PPMView(const char* name, uint32 flags) : BView(name, flags)
+ {
+ SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
+
+ fTitle = new BStringView("title", B_TRANSLATE("PPM image
translator"));
+ fTitle->SetFont(be_bold_font);
+
+ char detail[100];
+ int ver = static_cast<int>(translatorVersion);
+ sprintf(detail, B_TRANSLATE("Version %d.%d.%d, %s"), ver >> 8,
+ ((ver >> 4) & 0xf), (ver & 0xf), __DATE__);
+ fDetail = new BStringView("detail", detail);
+
+ fBasedOn = new BStringView(
+ "basedOn", B_TRANSLATE("Based on PPMTranslator sample
code"));
+
+ fCopyright = new BStringView("copyright",
+ B_TRANSLATE("Sample code copyright 1999, Be
Incorporated"));
+
+ fMenu = new BPopUpMenu("Color Space");
+ fMenu->AddItem(
+ new BMenuItem(B_TRANSLATE("None"),
CSMessage(B_NO_COLOR_SPACE)));
+ fMenu->AddItem(new BMenuItem(
+ B_TRANSLATE("RGB 8:8:8 32 bits"), CSMessage(B_RGB32)));
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 8:8:8:8 32 "
+
"bits"),
+ CSMessage(B_RGBA32)));
+ fMenu->AddItem(new BMenuItem(
+ B_TRANSLATE("RGB 5:5:5 16 bits"), CSMessage(B_RGB15)));
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 5:5:5:1 16 "
+
"bits"),
+ CSMessage(B_RGBA15)));
+ fMenu->AddItem(new BMenuItem(
+ B_TRANSLATE("RGB 5:6:5 16 bits"), CSMessage(B_RGB16)));
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("System palette 8 "
+
"bits"),
+ CSMessage(B_CMAP8)));
+ fMenu->AddSeparatorItem();
+ fMenu->AddItem(
+ new BMenuItem(B_TRANSLATE("Grayscale 8 bits"),
CSMessage(B_GRAY8)));
+ fMenu->AddItem(
+ new BMenuItem(B_TRANSLATE("Bitmap 1 bit"),
CSMessage(B_GRAY1)));
+ fMenu->AddItem(new BMenuItem(
+ B_TRANSLATE("CMY 8:8:8 32 bits"), CSMessage(B_CMY32)));
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMYA 8:8:8:8 32 "
+
"bits"),
+ CSMessage(B_CMYA32)));
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMYK 8:8:8:8 32 "
+
"bits"),
+ CSMessage(B_CMYK32)));
+ fMenu->AddSeparatorItem();
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 8:8:8 32 bits "
+
"big-endian"),
+ CSMessage(B_RGB32_BIG)));
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 8:8:8:8 32 "
+
"bits big-endian"),
+ CSMessage(B_RGBA32_BIG)));
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 5:5:5 16 bits "
+
"big-endian"),
+ CSMessage(B_RGB15_BIG)));
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 5:5:5:1 16 "
+
"bits big-endian"),
+ CSMessage(B_RGBA15_BIG)));
+ fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 5:6:5 16 bits "
+
"big-endian"),
+ CSMessage(B_RGB16)));
+ fField = new BMenuField(B_TRANSLATE("Input color space:"),
fMenu);
+ fField->SetViewColor(ViewColor());
+ SelectColorSpace(g_settings.out_space);
+ BMessage* msg = new BMessage(CHANGE_ASCII);
+ fAscii = new BCheckBox(B_TRANSLATE("Write ASCII"), msg);
+ if (g_settings.write_ascii)
+ fAscii->SetValue(1);
+ fAscii->SetViewColor(ViewColor());
+
+ // Build the layout
+ BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
+ .SetInsets(B_USE_DEFAULT_SPACING)
+ .Add(fTitle)
+ .Add(fDetail)
+ .AddGlue()
+ .AddGroup(B_HORIZONTAL)
+ .Add(fField)
+ .AddGlue()
+ .End()
+ .Add(fAscii)
+ .AddGlue()
+ .Add(fBasedOn)
+ .Add(fCopyright);
+
+ BFont font;
+ GetFont(&font);
+ SetExplicitPreferredSize(
+ BSize((font.Size() * 350) / 12, (font.Size() * 200) /
12));
+ }
+ ~PPMView() { /* nothing here */ }
+
+ enum { SET_COLOR_SPACE = 'ppm=', CHANGE_ASCII };
+
+ virtual void MessageReceived(BMessage* message)
+ {
+ if (message->what == SET_COLOR_SPACE) {
+ SetSettings(message);
+ } else if (message->what == CHANGE_ASCII) {
+ BMessage msg;
+ msg.AddBool("ppm /ascii", fAscii->Value());
+ SetSettings(&msg);
+ } else {
+ BView::MessageReceived(message);
+ }
+ }
+ virtual void AllAttached()
+ {
+ BView::AllAttached();
+ BMessenger msgr(this);
+ /* Tell all menu items we're the man. */
+ for (int ix = 0; ix < fMenu->CountItems(); ix++) {
+ BMenuItem* i = fMenu->ItemAt(ix);
+ if (i) {
+ i->SetTarget(msgr);
}
+ }
+ fAscii->SetTarget(msgr);
+ }
- void SetSettings(
- BMessage * message)
- {
- g_settings_lock.Lock();
- color_space space;
- if (!message->FindInt32("space",
(int32*)&space)) {
- g_settings.out_space = space;
- SelectColorSpace(space);
- g_settings.settings_touched = true;
- }
- bool ascii;
- if (!message->FindBool("ppm /ascii", &ascii)) {
- g_settings.write_ascii = ascii;
- g_settings.settings_touched = true;
- }
- g_settings_lock.Unlock();
- }
+ void SetSettings(BMessage* message)
+ {
+ g_settings_lock.Lock();
+ color_space space;
+ if (!message->FindInt32("space", (int32*) &space)) {
+ g_settings.out_space = space;
+ SelectColorSpace(space);
+ g_settings.settings_touched = true;
+ }
+ bool ascii;
+ if (!message->FindBool("ppm /ascii", &ascii)) {
+ g_settings.write_ascii = ascii;
+ g_settings.settings_touched = true;
+ }
+ g_settings_lock.Unlock();
+ }
private:
- BStringView * fTitle;
- BStringView * fDetail;
- BStringView * fBasedOn;
- BStringView * fCopyright;
- BPopUpMenu * fMenu;
- BMenuField * fField;
- BCheckBox * fAscii;
-
- BMessage * CSMessage(
- color_space space)
- {
- BMessage * ret = new BMessage(SET_COLOR_SPACE);
- ret->AddInt32("space", space);
- return ret;
- }
+ BStringView* fTitle;
+ BStringView* fDetail;
+ BStringView* fBasedOn;
+ BStringView* fCopyright;
+ BPopUpMenu* fMenu;
+ BMenuField* fField;
+ BCheckBox* fAscii;
+
+ BMessage* CSMessage(color_space space)
+ {
+ BMessage* ret = new BMessage(SET_COLOR_SPACE);
+ ret->AddInt32("space", space);
+ return ret;
+ }
- void SelectColorSpace(
- color_space space)
- {
- for (int ix=0; ix<fMenu->CountItems(); ix++) {
- int32 s;
- BMenuItem * i = fMenu->ItemAt(ix);
- if (i) {
- BMessage * m = i->Message();
- if (m && !m->FindInt32("space",
&s) && (s == space)) {
-
fMenu->Superitem()->SetLabel(i->Label());
- break;
- }
- }
+ void SelectColorSpace(color_space space)
+ {
+ for (int ix = 0; ix < fMenu->CountItems(); ix++) {
+ int32 s;
+ BMenuItem* i = fMenu->ItemAt(ix);
+ if (i) {
+ BMessage* m = i->Message();
+ if (m && !m->FindInt32("space", &s) && (s ==
space)) {
+
fMenu->Superitem()->SetLabel(i->Label());
+ break;
}
}
+ }
+ }
};
- /* The view will get resized to what the parent thinks is */
- /* reasonable. However, it will still receive MouseDowns etc.
*/
- /* Your view should change settings in the translator immediately,
*/
- /* taking care not to change parameters for a translation that is
*/
- /* currently running. Typically, you'll have a global struct for
*/
- /* settings that is atomically copied into the translator function
*/
- /* as a local when translation starts. */
- /* Store your settings wherever you feel like it. */
+/* The view will get resized to what the parent thinks is */
+/* reasonable. However, it will still receive MouseDowns etc. */
+/* Your view should change settings in the translator immediately,
*/
+/* taking care not to change parameters for a translation that is */
+/* currently running. Typically, you'll have a global struct for */
+/* settings that is atomically copied into the translator function
*/
+/* as a local when translation starts. */
+/* Store your settings wherever you feel like it. */
status_t
-MakeConfig( /* optional */
- BMessage * ioExtension, /* can be NULL */
- BView * * outView,
- BRect * outExtent)
+MakeConfig(/* optional */
+ BMessage* ioExtension, /* can be NULL */
+ BView** outView, BRect* outExtent)
{
- PPMView * v = new PPMView(B_TRANSLATE("PPMTranslator Settings"),
- B_WILL_DRAW);
+ PPMView* v
+ = new PPMView(B_TRANSLATE("PPMTranslator Settings"),
B_WILL_DRAW);
*outView = v;
- v->ResizeTo(v->ExplicitPreferredSize());;
+ v->ResizeTo(v->ExplicitPreferredSize());
+ ;
*outExtent = v->Bounds();
if (ioExtension) {
v->SetSettings(ioExtension);
@@ -656,42 +682,31 @@ MakeConfig( /* optional */
}
- /* Copy your current settings to a BMessage that may be passed
*/
- /* to BTranslators::Translate at some later time when the user
wants to */
- /* use whatever settings you're using right now. */
+/* Copy your current settings to a BMessage that may be passed */
+/* to BTranslators::Translate at some later time when the user wants to
*/
+/* use whatever settings you're using right now. */
status_t
-GetConfigMessage( /* optional */
- BMessage * ioExtension)
+GetConfigMessage(/* optional */
+ BMessage* ioExtension)
{
status_t err = B_OK;
#if defined(_PR3_COMPATIBLE_)
- const char * name = B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE;
+ const char* name = B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE;
#else
- const char * name = B_TRANSLATE_MARK("bits/space");
+ const char* name = B_TRANSLATE_MARK("bits/space");
#endif
g_settings_lock.Lock();
- (void)ioExtension->RemoveName(name);
+ (void) ioExtension->RemoveName(name);
err = ioExtension->AddInt32(name, g_settings.out_space);
g_settings_lock.Unlock();
return err;
}
-
-
-
status_t
-read_ppm_header(
- BDataIO * inSource,
- int * width,
- int * rowbytes,
- int * height,
- int * max,
- bool * ascii,
- color_space * space,
- bool * is_ppm,
- char ** comment)
+read_ppm_header(BDataIO* inSource, int* width, int* rowbytes, int* height,
+ int* max, bool* ascii, color_space* space, bool* is_ppm, char** comment)
{
/* check for PPM magic number */
char ch[2];
@@ -703,18 +718,17 @@ read_ppm_header(
/* B_TRANSLATOR_BITMAP magic? */
if (ch[0] == 'b' && ch[1] == 'i') {
*is_ppm = false;
- return read_bits_header(inSource, 2, width, rowbytes,
height, max, ascii, space);
+ return read_bits_header(
+ inSource, 2, width, rowbytes, height, max,
ascii, space);
}
return B_NO_TRANSLATOR;
}
*is_ppm = true;
if (ch[1] == '6') {
*ascii = false;
- }
- else if (ch[1] == '3') {
+ } else if (ch[1] == '3') {
*ascii = true;
- }
- else {
+ } else {
return B_NO_TRANSLATOR;
}
// status_t err = B_NO_TRANSLATOR;
@@ -723,8 +737,9 @@ read_ppm_header(
scan_height,
scan_max,
scan_white
- } state = scan_width;
- int * scan = NULL;
+ } state
+ = scan_width;
+ int* scan = NULL;
bool in_comment = false;
*space = B_RGB24_BIG;
/* The description of PPM is slightly ambiguous as far as comments */
@@ -734,9 +749,9 @@ read_ppm_header(
int comptr = 0;
while (inSource->Read(ch, 1) == 1) {
if (in_comment && (ch[0] != 10) && (ch[0] != 13)) {
- if (comment) { /* collect comment(s) into comment
string */
- if (comptr >= comlen-1) {
- char * n = (char *)realloc(*comment,
comlen+100);
+ if (comment) { /* collect comment(s) into comment
string */
+ if (comptr >= comlen - 1) {
+ char* n = (char*) realloc(*comment,
comlen + 100);
if (!n) {
free(*comment);
*comment = NULL;
@@ -756,65 +771,58 @@ read_ppm_header(
}
/* once we're done with whitespace after max, we're done with
header */
if (isdigit(ch[0])) {
- if (!scan) { /* first digit for this value */
- switch(state) {
- case scan_width:
- scan = width;
- break;
- case scan_height:
- *rowbytes = *width*3;
- scan = height;
- break;
- case scan_max:
- scan = max;
- break;
- default:
- return B_OK; /* done with header,
all OK */
+ if (!scan) { /* first digit for this value */
+ switch (state) {
+ case scan_width:
+ scan = width;
+ break;
+ case scan_height:
+ *rowbytes = *width * 3;
+ scan = height;
+ break;
+ case scan_max:
+ scan = max;
+ break;
+ default:
+ return B_OK; /* done with
header, all OK */
}
*scan = 0;
}
- *scan = (*scan)*10 + (ch[0]-'0');
- }
- else if (isspace(ch[0])) {
- if (scan) { /* are we done with one value? */
+ *scan = (*scan) * 10 + (ch[0] - '0');
+ } else if (isspace(ch[0])) {
+ if (scan) { /* are we done with one value? */
scan = NULL;
- state = (enum scan_state)(state+1);
+ state = (enum scan_state)(state + 1);
}
- if (state == scan_white) { /* we only ever read
one whitespace, since we skip space */
- return B_OK; /* when reading ASCII, and
there is a single whitespace after max in raw mode */
+ if (state == scan_white) { /* we only ever read one
whitespace,
+
since we skip space */
+ return B_OK; /* when reading ASCII, and there
is a single
+ whitespace
after max in raw mode */
}
- }
- else {
+ } else {
if (state != scan_white) {
return B_NO_TRANSLATOR;
}
- return B_OK; /* header done */
+ return B_OK; /* header done */
}
}
return B_NO_TRANSLATOR;
}
-
status_t
-read_bits_header(
- BDataIO * io,
- int skipped,
- int * width,
- int * rowbytes,
- int * height,
- int * max,
- bool * ascii,
- color_space * space)
+read_bits_header(BDataIO* io, int skipped, int* width, int* rowbytes,
+ int* height, int* max, bool* ascii, color_space* space)
{
/* read the rest of a possible B_TRANSLATOR_BITMAP header */
- if (skipped < 0 || skipped > 4) return B_NO_TRANSLATOR;
- int rd = sizeof(TranslatorBitmap)-skipped;
+ if (skipped < 0 || skipped > 4)
+ return B_NO_TRANSLATOR;
+ int rd = sizeof(TranslatorBitmap) - skipped;
TranslatorBitmap hdr;
/* pre-initialize magic because we might have skipped part of it
already */
hdr.magic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP);
- char * ptr = (char *)&hdr;
- if (io->Read(ptr+skipped, rd) != rd) {
+ char* ptr = (char*) &hdr;
+ if (io->Read(ptr + skipped, rd) != rd) {
return B_NO_TRANSLATOR;
}
/* swap header values */
@@ -824,22 +832,23 @@ read_bits_header(
hdr.bounds.top = B_BENDIAN_TO_HOST_FLOAT(hdr.bounds.top);
hdr.bounds.bottom = B_BENDIAN_TO_HOST_FLOAT(hdr.bounds.bottom);
hdr.rowBytes = B_BENDIAN_TO_HOST_INT32(hdr.rowBytes);
- hdr.colors = (color_space)B_BENDIAN_TO_HOST_INT32(hdr.colors);
+ hdr.colors = (color_space) B_BENDIAN_TO_HOST_INT32(hdr.colors);
hdr.dataSize = B_BENDIAN_TO_HOST_INT32(hdr.dataSize);
/* sanity checking */
if (hdr.magic != B_TRANSLATOR_BITMAP) {
return B_NO_TRANSLATOR;
}
- if (hdr.colors & 0xffff0000) { /* according to <GraphicsDefs.h> this
is a reasonable check. */
+ if (hdr.colors & 0xffff0000) { /* according to <GraphicsDefs.h> this is
a
+
reasonable check. */
return B_NO_TRANSLATOR;
}
- if (hdr.rowBytes * (hdr.bounds.Height()+1) > hdr.dataSize) {
+ if (hdr.rowBytes * (hdr.bounds.Height() + 1) > hdr.dataSize) {
return B_NO_TRANSLATOR;
}
/* return information about the data in the stream */
- *width = (int)hdr.bounds.Width()+1;
+ *width = (int) hdr.bounds.Width() + 1;
*rowbytes = hdr.rowBytes;
- *height = (int)hdr.bounds.Height()+1;
+ *height = (int) hdr.bounds.Height() + 1;
*max = 255;
*ascii = false;
*space = hdr.colors;
@@ -847,28 +856,27 @@ read_bits_header(
}
-/* String may contain newlines, after which we need to insert extra hash
signs. */
+/* String may contain newlines, after which we need to insert extra hash
signs.
+ */
status_t
-write_comment(
- const char * str,
- BDataIO * io)
+write_comment(const char* str, BDataIO* io)
{
- const char * end = str+strlen(str);
- const char * ptr = str;
+ const char* end = str + strlen(str);
+ const char* ptr = str;
status_t err = B_OK;
/* write each line as it's found */
while ((ptr < end) && !err) {
if ((*ptr == 10) || (*ptr == 13)) {
err = io->Write("# ", 2);
if (err == 2) {
- err = io->Write(str, ptr-str);
- if (err == ptr-str) {
+ err = io->Write(str, ptr - str);
+ if (err == ptr - str) {
if (io->Write("\n", 1) == 1) {
err = 0;
}
}
}
- str = ptr+1;
+ str = ptr + 1;
}
ptr++;
}
@@ -876,8 +884,8 @@ write_comment(
if (ptr > str) {
err = io->Write("# ", 2);
if (err == 2) {
- err = io->Write(str, ptr-str);
- if (err == ptr-str) {
+ err = io->Write(str, ptr - str);
+ if (err == ptr - str) {
if (io->Write("\n", 1) == 1) {
err = 0;
}
@@ -892,11 +900,7 @@ write_comment(
static status_t
-read_ascii_line(
- BDataIO * in,
- int max,
- unsigned char * data,
- int rowbytes)
+read_ascii_line(BDataIO* in, int max, unsigned char* data, int rowbytes)
{
char ch;
status_t err;
@@ -913,10 +917,9 @@ read_ascii_line(
if (isdigit(ch)) {
dig = true;
val = val * 10 + (ch - '0');
- }
- else {
+ } else {
if (dig) {
- *(data++) = val*255/max;
+ *(data++) = val * 255 / max;
val = 0;
rowbytes--;
dig = false;
@@ -931,7 +934,7 @@ read_ascii_line(
}
}
if (dig) {
- *(data++) = val*255/max;
+ *(data++) = val * 255 / max;
val = 0;
rowbytes--;
dig = false;
@@ -944,10 +947,7 @@ read_ascii_line(
static status_t
-write_ascii_line(
- BDataIO * out,
- unsigned char * data,
- int rowbytes)
+write_ascii_line(BDataIO* out, unsigned char* data, int rowbytes)
{
char buffer[20];
int linelen = 0;
@@ -965,58 +965,47 @@ write_ascii_line(
linelen += l;
data += 3;
}
- out->Write("\n", 1); /* terminate each scanline */
+ out->Write("\n", 1); /* terminate each scanline */
return B_OK;
}
-static unsigned char *
-make_scale_data(
- int max)
+static unsigned char*
+make_scale_data(int max)
{
- unsigned char * ptr = (unsigned char *)malloc(max);
- for (int ix=0; ix<max; ix++) {
- ptr[ix] = ix*255/max;
+ unsigned char* ptr = (unsigned char*) malloc(max);
+ for (int ix = 0; ix < max; ix++) {
+ ptr[ix] = ix * 255 / max;
}
return ptr;
}
static void
-scale_data(
- unsigned char * scale,
- unsigned char * data,
- int bytes)
+scale_data(unsigned char* scale, unsigned char* data, int bytes)
{
- for (int ix=0; ix<bytes; ix++) {
+ for (int ix = 0; ix < bytes; ix++) {
data[ix] = scale[data[ix]];
}
}
status_t
-copy_data(
- BDataIO * in,
- BDataIO * out,
- int rowbytes,
- int out_rowbytes,
- int height,
- int max,
- bool in_ascii,
- bool out_ascii,
- color_space in_space,
+copy_data(BDataIO* in, BDataIO* out, int rowbytes, int out_rowbytes, int
height,
+ int max, bool in_ascii, bool out_ascii, color_space in_space,
color_space out_space)
{
- dprintf(("copy_data(%x, %x, %x, %x, %x, %x)\n", rowbytes, out_rowbytes,
height, max, in_space, out_space));
+ dprintf(("copy_data(%x, %x, %x, %x, %x, %x)\n", rowbytes, out_rowbytes,
+ height, max, in_space, out_space));
/* We read/write one scanline at a time. */
- unsigned char * data = (unsigned char *)malloc(rowbytes);
- unsigned char * out_data = (unsigned char *)malloc(out_rowbytes);
+ unsigned char* data = (unsigned char*) malloc(rowbytes);
+ unsigned char* out_data = (unsigned char*) malloc(out_rowbytes);
if (data == NULL || out_data == NULL) {
free(data);
free(out_data);
return B_NO_MEMORY;
}
- unsigned char * scale = NULL;
+ unsigned char* scale = NULL;
if (max != 255) {
scale = make_scale_data(max);
}
@@ -1025,26 +1014,25 @@ copy_data(
while ((height-- > 0) && !err) {
if (in_ascii) {
err = read_ascii_line(in, max, data, rowbytes);
- }
- else {
+ } else {
err = in->Read(data, rowbytes);
if (err == rowbytes) {
err = B_OK;
}
- if (scale) { /* for reading PPM that is smaller than
8 bit */
+ if (scale) { /* for reading PPM that is smaller than 8
bit */
scale_data(scale, data, rowbytes);
}
}
if (err == B_OK) {
- unsigned char * wbuf = data;
+ unsigned char* wbuf = data;
if (in_space != out_space) {
- err = convert_space(in_space, out_space, data,
rowbytes, out_data);
+ err = convert_space(
+ in_space, out_space, data, rowbytes,
out_data);
wbuf = out_data;
}
if (!err && out_ascii) {
err = write_ascii_line(out, wbuf, out_rowbytes);
- }
- else if (!err) {
+ } else if (!err) {
err = out->Write(wbuf, out_rowbytes);
if (err == out_rowbytes) {
err = B_OK;
@@ -1057,5 +1045,3 @@ copy_data(
free(scale);
return err > 0 ? B_IO_ERROR : err;
}
-
-
diff --git a/src/add-ons/translators/ppm/colorspace.cpp
b/src/add-ons/translators/ppm/colorspace.cpp
index c64dcc1943..d7d97d2d2e 100644
--- a/src/add-ons/translators/ppm/colorspace.cpp
+++ b/src/add-ons/translators/ppm/colorspace.cpp
@@ -5,169 +5,176 @@
*/
+#include <Debug.h>
#include <GraphicsDefs.h>
#include <InterfaceDefs.h>
-#include <Debug.h>
-#include <string.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include "colorspace.h"
#if !defined(_PR3_COMPATIBLE_)
- #define B_CMY24 ((color_space)0xC001) /* C[7:0] M[7:0] Y[7:0]
No gray removal done */
- #define B_CMY32 ((color_space)0xC002) /* C[7:0] M[7:0] Y[7:0] X[7:0]
No gray removal done */
- #define B_CMYA32 ((color_space)0xE002) /* C[7:0] M[7:0] Y[7:0] A[7:0]
No gray removal done */
- #define B_CMYK32 ((color_space)0xC003) /* C[7:0] M[7:0] Y[7:0] K[7:0]
*/
+#define B_CMY24 \
+ ((color_space) 0xC001) /* C[7:0] M[7:0] Y[7:0] No gray
removal \
+ done */
+#define B_CMY32 \
+ ((color_space) 0xC002) /* C[7:0] M[7:0] Y[7:0] X[7:0] No gray
removal \
+ done */
+#define B_CMYA32 \
+ ((color_space) 0xE002) /* C[7:0] M[7:0] Y[7:0] A[7:0] No gray
removal \
+ done */
+#define B_CMYK32 \
+ ((color_space) 0xC003) /* C[7:0] M[7:0] Y[7:0] K[7:0] */
#endif
int
-expand_data( /* expands to BGRA in the output buffer from <whatever> in the
input buffer */
+expand_data(/* expands to BGRA in the output buffer from <whatever> in the
input
+ buffer */
color_space from_space,
- unsigned char * in_data,
- int rowbytes,
- unsigned char * out_buf)
+ unsigned char* in_data, int rowbytes, unsigned char* out_buf)
{
ASSERT(in_data != out_buf);
/* We don't do YUV and friends yet. */
- /* It's important to replicate the most significant component bits
to LSB when going 15->24 */
- unsigned char * in_out = out_buf;
+ /* It's important to replicate the most significant component bits
to LSB
+ * when going 15->24 */
+ unsigned char* in_out = out_buf;
switch (from_space) {
- case B_RGB32:
- while (rowbytes > 3) {
- out_buf[0] = in_data[0];
- out_buf[1] = in_data[1];
- out_buf[2] = in_data[2];
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 4;
- rowbytes -= 4;
- }
- break;
- case B_RGBA32:
- memcpy(out_buf, in_data, rowbytes);
- break;
- case B_RGB24:
- while (rowbytes > 2) {
- out_buf[0] = in_data[0];
- out_buf[1] = in_data[1];
- out_buf[2] = in_data[2];
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 3;
- rowbytes -= 3;
- }
- break;
- case B_RGB15:
- while (rowbytes > 1) {
- uint16 val = in_data[0]+(in_data[1]<<8);
- out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
- out_buf[1] = ((val&0x3e0)>>2)|((val&0x3e0)>>7);
- out_buf[2] = ((val&0x7c00)>>7)|((val&0x7c00)>>12);
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 2;
- rowbytes -= 2;
- }
- break;
- case B_RGBA15:
- while (rowbytes > 1) {
- uint16 val = in_data[0]+(in_data[1]<<8);
- out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
- out_buf[1] = ((val&0x3e0)>>2)|((val&0x3e0)>>7);
- out_buf[2] = ((val&0x7c00)>>7)|((val&0x7c00)>>12);
- out_buf[3] = (val&0x8000) ? 255 : 0;
- out_buf += 4;
- in_data += 2;
- rowbytes -= 2;
- }
- break;
- case B_RGB16:
- while (rowbytes > 1) {
- uint16 val = in_data[0]+(in_data[1]<<8);
- out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
- out_buf[1] = ((val&0x7e0)>>3)|((val&0x7e0)>>9);
- out_buf[2] = ((val&0xf800)>>8)|((val&0xf800)>>13);
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 2;
- rowbytes -= 2;
- }
- break;
- case B_RGB32_BIG:
- while (rowbytes > 3) {
- out_buf[0] = in_data[3];
- out_buf[1] = in_data[2];
- out_buf[2] = in_data[1];
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 4;
- rowbytes -= 4;
- }
- break;
- case B_RGBA32_BIG:
- while (rowbytes > 3) {
- out_buf[0] = in_data[3];
- out_buf[1] = in_data[2];
- out_buf[2] = in_data[1];
- out_buf[3] = in_data[0];
- out_buf += 4;
- in_data += 4;
- rowbytes -= 4;
- }
- break;
- case B_RGB24_BIG:
- while (rowbytes > 2) {
- out_buf[0] = in_data[2];
- out_buf[1] = in_data[1];
- out_buf[2] = in_data[0];
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 3;
- rowbytes -= 3;
- }
- break;
- case B_RGB15_BIG:
- while (rowbytes > 1) {
- uint16 val = in_data[1]+(in_data[0]<<8);
- out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
- out_buf[1] = ((val&0x3e0)>>2)|((val&0x3e0)>>7);
- out_buf[2] = ((val&0x7c00)>>7)|((val&0x7c00)>>12);
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 2;
- rowbytes -= 2;
- }
- break;
- case B_RGBA15_BIG:
- while (rowbytes > 1) {
- uint16 val = in_data[1]+(in_data[0]<<8);
- out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
- out_buf[1] = ((val&0x3e0)>>2)|((val&0x3e0)>>7);
- out_buf[2] = ((val&0x7c00)>>7)|((val&0x7c00)>>12);
- out_buf[3] = (val&0x8000) ? 255 : 0;
- out_buf += 4;
- in_data += 2;
- rowbytes -= 2;
- }
- break;
- case B_RGB16_BIG:
- while (rowbytes > 1) {
- uint16 val = in_data[1]+(in_data[0]<<8);
- out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
- out_buf[1] = ((val&0x7e0)>>3)|((val&0x7e0)>>9);
- out_buf[2] = ((val&0xf800)>>8)|((val&0xf800)>>13);
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 2;
- rowbytes -= 2;
- }
- break;
- case B_CMAP8: {
- const color_map * map = system_colors();
+ case B_RGB32:
+ while (rowbytes > 3) {
+ out_buf[0] = in_data[0];
+ out_buf[1] = in_data[1];
+ out_buf[2] = in_data[2];
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 4;
+ rowbytes -= 4;
+ }
+ break;
+ case B_RGBA32:
+ memcpy(out_buf, in_data, rowbytes);
+ break;
+ case B_RGB24:
+ while (rowbytes > 2) {
+ out_buf[0] = in_data[0];
+ out_buf[1] = in_data[1];
+ out_buf[2] = in_data[2];
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 3;
+ rowbytes -= 3;
+ }
+ break;
+ case B_RGB15:
+ while (rowbytes > 1) {
+ uint16 val = in_data[0] + (in_data[1] << 8);
+ out_buf[0] = ((val & 0x1f) << 3) | ((val &
0x1f) >> 2);
+ out_buf[1] = ((val & 0x3e0) >> 2) | ((val &
0x3e0) >> 7);
+ out_buf[2] = ((val & 0x7c00) >> 7) | ((val &
0x7c00) >> 12);
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 2;
+ rowbytes -= 2;
+ }
+ break;
+ case B_RGBA15:
+ while (rowbytes > 1) {
+ uint16 val = in_data[0] + (in_data[1] << 8);
+ out_buf[0] = ((val & 0x1f) << 3) | ((val &
0x1f) >> 2);
+ out_buf[1] = ((val & 0x3e0) >> 2) | ((val &
0x3e0) >> 7);
+ out_buf[2] = ((val & 0x7c00) >> 7) | ((val &
0x7c00) >> 12);
+ out_buf[3] = (val & 0x8000) ? 255 : 0;
+ out_buf += 4;
+ in_data += 2;
+ rowbytes -= 2;
+ }
+ break;
+ case B_RGB16:
+ while (rowbytes > 1) {
+ uint16 val = in_data[0] + (in_data[1] << 8);
+ out_buf[0] = ((val & 0x1f) << 3) | ((val &
0x1f) >> 2);
+ out_buf[1] = ((val & 0x7e0) >> 3) | ((val &
0x7e0) >> 9);
+ out_buf[2] = ((val & 0xf800) >> 8) | ((val &
0xf800) >> 13);
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 2;
+ rowbytes -= 2;
+ }
+ break;
+ case B_RGB32_BIG:
+ while (rowbytes > 3) {
+ out_buf[0] = in_data[3];
+ out_buf[1] = in_data[2];
+ out_buf[2] = in_data[1];
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 4;
+ rowbytes -= 4;
+ }
+ break;
+ case B_RGBA32_BIG:
+ while (rowbytes > 3) {
+ out_buf[0] = in_data[3];
+ out_buf[1] = in_data[2];
+ out_buf[2] = in_data[1];
+ out_buf[3] = in_data[0];
+ out_buf += 4;
+ in_data += 4;
+ rowbytes -= 4;
+ }
+ break;
+ case B_RGB24_BIG:
+ while (rowbytes > 2) {
+ out_buf[0] = in_data[2];
+ out_buf[1] = in_data[1];
+ out_buf[2] = in_data[0];
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 3;
+ rowbytes -= 3;
+ }
+ break;
+ case B_RGB15_BIG:
+ while (rowbytes > 1) {
+ uint16 val = in_data[1] + (in_data[0] << 8);
+ out_buf[0] = ((val & 0x1f) << 3) | ((val &
0x1f) >> 2);
+ out_buf[1] = ((val & 0x3e0) >> 2) | ((val &
0x3e0) >> 7);
+ out_buf[2] = ((val & 0x7c00) >> 7) | ((val &
0x7c00) >> 12);
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 2;
+ rowbytes -= 2;
+ }
+ break;
+ case B_RGBA15_BIG:
+ while (rowbytes > 1) {
+ uint16 val = in_data[1] + (in_data[0] << 8);
+ out_buf[0] = ((val & 0x1f) << 3) | ((val &
0x1f) >> 2);
+ out_buf[1] = ((val & 0x3e0) >> 2) | ((val &
0x3e0) >> 7);
+ out_buf[2] = ((val & 0x7c00) >> 7) | ((val &
0x7c00) >> 12);
+ out_buf[3] = (val & 0x8000) ? 255 : 0;
+ out_buf += 4;
+ in_data += 2;
+ rowbytes -= 2;
+ }
+ break;
+ case B_RGB16_BIG:
+ while (rowbytes > 1) {
+ uint16 val = in_data[1] + (in_data[0] << 8);
+ out_buf[0] = ((val & 0x1f) << 3) | ((val &
0x1f) >> 2);
+ out_buf[1] = ((val & 0x7e0) >> 3) | ((val &
0x7e0) >> 9);
+ out_buf[2] = ((val & 0xf800) >> 8) | ((val &
0xf800) >> 13);
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 2;
+ rowbytes -= 2;
+ }
+ break;
+ case B_CMAP8: {
+ const color_map* map = system_colors();
while (rowbytes > 0) {
rgb_color c = map->color_list[in_data[0]];
out_buf[0] = c.blue;
@@ -179,183 +186,188 @@ expand_data( /* expands to BGRA in the output buffer
from <whatever> in the inpu
rowbytes -= 1;
}
} break;
- case B_GRAY8:
- while (rowbytes > 0) {
- unsigned char ch = *in_data;
- out_buf[0] = ch;
- out_buf[1] = ch;
- out_buf[2] = ch;
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 1;
- rowbytes -= 1;
- }
- break;
- case B_GRAY1:
- while (rowbytes > 0) { /* expansion 1->32 is pretty good :-) */
- unsigned char c1 = *in_data;
- for (int b = 128; b; b = b>>1) {
- unsigned char ch;
- if (c1 & b) {
- ch = 0;
- }
- else {
- ch = 255;
- }
+ case B_GRAY8:
+ while (rowbytes > 0) {
+ unsigned char ch = *in_data;
out_buf[0] = ch;
out_buf[1] = ch;
out_buf[2] = ch;
out_buf[3] = 255;
out_buf += 4;
+ in_data += 1;
+ rowbytes -= 1;
+ }
+ break;
+ case B_GRAY1:
+ while (rowbytes > 0) { /* expansion 1->32 is pretty
good :-) */
+ unsigned char c1 = *in_data;
+ for (int b = 128; b; b = b >> 1) {
+ unsigned char ch;
+ if (c1 & b) {
+ ch = 0;
+ } else {
+ ch = 255;
+ }
+ out_buf[0] = ch;
+ out_buf[1] = ch;
+ out_buf[2] = ch;
+ out_buf[3] = 255;
+ out_buf += 4;
+ }
+ in_data += 1;
+ rowbytes -= 1;
+ }
+ break;
+ case B_CMY24: /* We do the "clean" inversion which
doesn't correct
+ for printing ink deficiencies.
*/
+ while (rowbytes > 2) {
+ out_buf[0] = 255 - in_data[2];
+ out_buf[1] = 255 - in_data[1];
+ out_buf[2] = 255 - in_data[0];
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 3;
+ rowbytes -= 3;
+ }
+ break;
+ case B_CMY32:
+ while (rowbytes > 3) {
+ out_buf[0] = 255 - in_data[2];
+ out_buf[1] = 255 - in_data[1];
+ out_buf[2] = 255 - in_data[0];
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 4;
+ rowbytes -= 4;
+ }
+ break;
+ case B_CMYA32:
+ while (rowbytes > 3) {
+ out_buf[0] = 255 - in_data[2];
+ out_buf[1] = 255 - in_data[1];
+ out_buf[2] = 255 - in_data[0];
+ out_buf[3] = in_data[3];
+ out_buf += 4;
+ in_data += 4;
+ rowbytes -= 4;
+ }
+ break;
+ case B_CMYK32: /* We assume uniform gray removal, and no
+ under-color-removal. */
+ while (rowbytes > 3) {
+ int comp = 255 - in_data[2] - in_data[3];
+ out_buf[0] = comp < 0 ? 0 : comp;
+ comp = 255 - in_data[1] - in_data[3];
+ out_buf[1] = comp < 0 ? 0 : comp;
+ comp = 255 - in_data[0] - in_data[3];
+ out_buf[2] = comp < 0 ? 0 : comp;
+ out_buf[3] = 255;
+ out_buf += 4;
+ in_data += 4;
+ rowbytes -= 4;
}
- in_data += 1;
- rowbytes -= 1;
- }
- break;
- case B_CMY24: /* We do the "clean" inversion which doesn't
correct for printing ink deficiencies. */
- while (rowbytes > 2) {
- out_buf[0] = 255-in_data[2];
- out_buf[1] = 255-in_data[1];
- out_buf[2] = 255-in_data[0];
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 3;
- rowbytes -= 3;
- }
- break;
- case B_CMY32:
- while (rowbytes > 3) {
- out_buf[0] = 255-in_data[2];
- out_buf[1] = 255-in_data[1];
- out_buf[2] = 255-in_data[0];
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 4;
- rowbytes -= 4;
- }
- break;
- case B_CMYA32:
- while (rowbytes > 3) {
- out_buf[0] = 255-in_data[2];
- out_buf[1] = 255-in_data[1];
- out_buf[2] = 255-in_data[0];
- out_buf[3] = in_data[3];
- out_buf += 4;
- in_data += 4;
- rowbytes -= 4;
- }
- break;
- case B_CMYK32: /* We assume uniform gray removal, and no
under-color-removal. */
- while (rowbytes > 3) {
- int comp = 255-in_data[2]-in_data[3];
- out_buf[0] = comp < 0 ? 0 : comp;
- comp = 255-in_data[1]-in_data[3];
- out_buf[1] = comp < 0 ? 0 : comp;
- comp = 255-in_data[0]-in_data[3];
- out_buf[2] = comp < 0 ? 0 : comp;
- out_buf[3] = 255;
- out_buf += 4;
- in_data += 4;
- rowbytes -= 4;
- }
- break;
- default:
- break;
+ break;
+ default:
+ break;
}
return out_buf - in_out;
}
int
-collapse_data(
- unsigned char * in_buf,
- int num_bytes,
- color_space out_space,
- unsigned char * out_buf)
+collapse_data(unsigned char* in_buf, int num_bytes, color_space out_space,
+ unsigned char* out_buf)
{
ASSERT(in_buf != out_buf);
- unsigned char * in_out = out_buf;
- /* We could increase perceived image quality of down conversions
by implementing */
- /* dithering. However, someone might want to operate on the images
after */
- /* conversion, in which case dithering would be un-good. Besides,
good error */
+ unsigned char* in_out = out_buf;
+ /* We could increase perceived image quality of down conversions by
+ * implementing */
+ /* dithering. However, someone might want to operate on the images
after
+ */
+ /* conversion, in which case dithering would be un-good. Besides,
good
+ * error */
/* diffusion requires more than one scan line to propagate errors
to. */
- switch(out_space) {
- case B_RGB32:
- memcpy(out_buf, in_buf, num_bytes);
- break;
- case B_RGBA32:
- memcpy(out_buf, in_buf, num_bytes);
- break;
- case B_RGB24:
- while (num_bytes > 3) {
- out_buf[0] = in_buf[0];
- out_buf[1] = in_buf[1];
- out_buf[2] = in_buf[2];
- out_buf += 3;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_RGB16:
- while (num_bytes > 3) {
- uint16 val =
(in_buf[0]>>3)|((in_buf[1]<<3)&0x7e0)|((in_buf[2]<<8)&0xf800);
- out_buf[0] = val;
- out_buf[1] = val>>8;
- out_buf += 2;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_RGB15:
- while (num_bytes > 3) {
- uint16 val =
(in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00)|0x8000;
- out_buf[0] = val;
- out_buf[1] = val>>8;
- out_buf += 2;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_RGBA15:
- while (num_bytes > 3) {
- uint16 val =
(in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00);
- if (in_buf[3] > 127) {
- val = val | 0x8000;
- }
- out_buf[0] = val;
- out_buf[1] = val>>8;
- out_buf += 2;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_CMAP8: {
- const color_map * map = system_colors();
+ switch (out_space) {
+ case B_RGB32:
+ memcpy(out_buf, in_buf, num_bytes);
+ break;
+ case B_RGBA32:
+ memcpy(out_buf, in_buf, num_bytes);
+ break;
+ case B_RGB24:
+ while (num_bytes > 3) {
+ out_buf[0] = in_buf[0];
+ out_buf[1] = in_buf[1];
+ out_buf[2] = in_buf[2];
+ out_buf += 3;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_RGB16:
+ while (num_bytes > 3) {
+ uint16 val = (in_buf[0] >> 3) | ((in_buf[1] <<
3) & 0x7e0)
+ | ((in_buf[2] << 8) & 0xf800);
+ out_buf[0] = val;
+ out_buf[1] = val >> 8;
+ out_buf += 2;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_RGB15:
+ while (num_bytes > 3) {
+ uint16 val = (in_buf[0] >> 3) | ((in_buf[1] <<
2) & 0x3e0)
+ | ((in_buf[2] << 7) & 0x7c00) | 0x8000;
+ out_buf[0] = val;
+ out_buf[1] = val >> 8;
+ out_buf += 2;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_RGBA15:
+ while (num_bytes > 3) {
+ uint16 val = (in_buf[0] >> 3) | ((in_buf[1] <<
2) & 0x3e0)
+ | ((in_buf[2] << 7) & 0x7c00);
+ if (in_buf[3] > 127) {
+ val = val | 0x8000;
+ }
+ out_buf[0] = val;
+ out_buf[1] = val >> 8;
+ out_buf += 2;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_CMAP8: {
+ const color_map* map = system_colors();
while (num_bytes > 3) {
if (in_buf[3] < 128) {
out_buf[0] = B_TRANSPARENT_8_BIT;
- }
- else {
- uint16 val =
(in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00);
+ } else {
+ uint16 val = (in_buf[0] >> 3) |
((in_buf[1] << 2) & 0x3e0)
+ | ((in_buf[2] << 7) & 0x7c00);
out_buf[0] = map->index_map[val];
}
out_buf += 1;
in_buf += 4;
num_bytes -= 4;
}
- }
- break;
- case B_GRAY8:
- while (num_bytes > 3) { /* There are better algorithms
than Y = .25B+.50G+.25R */
- /* but
hardly faster -- and it's still better than (B+G+R)/3 ! */
- out_buf[0] = (in_buf[0]+in_buf[1]*2+in_buf[2])>>2;
- out_buf += 1;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_GRAY1: {
+ } break;
+ case B_GRAY8:
+ while (num_bytes > 3) { /* There are better
algorithms than Y =
+
.25B+.50G+.25R */
+ /* but hardly faster -- and it's still
better than (B+G+R)/3 !
+ */
+ out_buf[0] = (in_buf[0] + in_buf[1] * 2 +
in_buf[2]) >> 2;
+ out_buf += 1;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_GRAY1: {
uchar ob = 0;
int cnt = 0;
uchar c = 0;
@@ -366,7 +378,8 @@ collapse_data(
cnt = 0;
ob = 0;
}
- c =
((in_buf[0]+in_buf[1]*2+in_buf[2])&0x200)>>(2+cnt);
+ c = ((in_buf[0] + in_buf[1] * 2 + in_buf[2]) &
0x200)
+ >> (2 + cnt);
ob = ob | c;
cnt++;
in_buf += 4;
@@ -377,129 +390,130 @@ collapse_data(
out_buf += 1;
}
} break;
- /* big endian version, when the encoding is not endianess independant */
- case B_RGB32_BIG:
- while (num_bytes > 3) {
- out_buf[3] = in_buf[0];
- out_buf[2] = in_buf[1];
- out_buf[1] = in_buf[2];
- out_buf += 4;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_RGBA32_BIG:
- while (num_bytes > 3) {
- out_buf[3] = in_buf[0];
- out_buf[2] = in_buf[1];
- out_buf[1] = in_buf[2];
- out_buf[0] = in_buf[3];
- out_buf += 4;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_RGB24_BIG:
- while (num_bytes > 3) {
- out_buf[2] = in_buf[0];
- out_buf[1] = in_buf[1];
- out_buf[0] = in_buf[2];
- out_buf += 3;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_RGB16_BIG:
- while (num_bytes > 3) {
- uint16 val =
(in_buf[0]>>3)|((in_buf[1]<<3)&0x7e0)|((in_buf[2]<<8)&0xf800);
- out_buf[0] = val>>8;
- out_buf[1] = val;
- out_buf += 2;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_RGB15_BIG:
- while (num_bytes > 3) {
- uint16 val =
(in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00)|0x8000;
- out_buf[0] = val>>8;
- out_buf[1] = val;
- out_buf += 2;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_RGBA15_BIG:
- while (num_bytes > 3) {
- uint16 val =
(in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00);
- if (in_buf[3] > 127) {
- val = val | 0x8000;
- }
- out_buf[0] = val>>8;
- out_buf[1] = val;
- out_buf += 2;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_CMY24:
- while (num_bytes > 3) {
- out_buf[0] = 255-in_buf[2];
- out_buf[1] = 255-in_buf[1];
- out_buf[2] = 255-in_buf[0];
- out_buf += 3;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_CMY32:
- while (num_bytes > 3) {
- out_buf[0] = 255-in_buf[2];
- out_buf[1] = 255-in_buf[1];
- out_buf[2] = 255-in_buf[0];
- out_buf += 4;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_CMYA32:
- while (num_bytes > 3) {
- out_buf[0] = 255-in_buf[2];
- out_buf[1] = 255-in_buf[1];
- out_buf[2] = 255-in_buf[0];
- out_buf[3] = in_buf[3];
- out_buf += 4;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- case B_CMYK32:
- while (num_bytes > 3) { /* We do direct gray removal
*/
- int c = 255-in_buf[2];
- int m = 255-in_buf[1];
- int y = 255-in_buf[0];
- int k = (c>m)?((y>c)?y:c):((y>m)?y:m);
- out_buf[0] = c-k;
- out_buf[1] = m-k;
- out_buf[2] = y-k;
- out_buf[3] = k;
- out_buf += 4;
- in_buf += 4;
- num_bytes -= 4;
- }
- break;
- default:
- break;
+ /* big endian version, when the encoding is not endianess
independant */
+ case B_RGB32_BIG:
+ while (num_bytes > 3) {
+ out_buf[3] = in_buf[0];
+ out_buf[2] = in_buf[1];
+ out_buf[1] = in_buf[2];
+ out_buf += 4;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_RGBA32_BIG:
+ while (num_bytes > 3) {
+ out_buf[3] = in_buf[0];
+ out_buf[2] = in_buf[1];
+ out_buf[1] = in_buf[2];
+ out_buf[0] = in_buf[3];
+ out_buf += 4;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_RGB24_BIG:
+ while (num_bytes > 3) {
+ out_buf[2] = in_buf[0];
+ out_buf[1] = in_buf[1];
+ out_buf[0] = in_buf[2];
+ out_buf += 3;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_RGB16_BIG:
+ while (num_bytes > 3) {
+ uint16 val = (in_buf[0] >> 3) | ((in_buf[1] <<
3) & 0x7e0)
+ | ((in_buf[2] << 8) & 0xf800);
+ out_buf[0] = val >> 8;
+ out_buf[1] = val;
+ out_buf += 2;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_RGB15_BIG:
+ while (num_bytes > 3) {
+ uint16 val = (in_buf[0] >> 3) | ((in_buf[1] <<
2) & 0x3e0)
+ | ((in_buf[2] << 7) & 0x7c00) | 0x8000;
+ out_buf[0] = val >> 8;
+ out_buf[1] = val;
+ out_buf += 2;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_RGBA15_BIG:
+ while (num_bytes > 3) {
+ uint16 val = (in_buf[0] >> 3) | ((in_buf[1] <<
2) & 0x3e0)
+ | ((in_buf[2] << 7) & 0x7c00);
+ if (in_buf[3] > 127) {
+ val = val | 0x8000;
+ }
+ out_buf[0] = val >> 8;
+ out_buf[1] = val;
+ out_buf += 2;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_CMY24:
+ while (num_bytes > 3) {
+ out_buf[0] = 255 - in_buf[2];
+ out_buf[1] = 255 - in_buf[1];
+ out_buf[2] = 255 - in_buf[0];
+ out_buf += 3;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_CMY32:
+ while (num_bytes > 3) {
+ out_buf[0] = 255 - in_buf[2];
+ out_buf[1] = 255 - in_buf[1];
+ out_buf[2] = 255 - in_buf[0];
+ out_buf += 4;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_CMYA32:
+ while (num_bytes > 3) {
+ out_buf[0] = 255 - in_buf[2];
+ out_buf[1] = 255 - in_buf[1];
+ out_buf[2] = 255 - in_buf[0];
+ out_buf[3] = in_buf[3];
+ out_buf += 4;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ case B_CMYK32:
+ while (num_bytes > 3) { /* We do direct gray
removal */
+ int c = 255 - in_buf[2];
+ int m = 255 - in_buf[1];
+ int y = 255 - in_buf[0];
+ int k = (c > m) ? ((y > c) ? y : c) : ((y > m)
? y : m);
+ out_buf[0] = c - k;
+ out_buf[1] = m - k;
+ out_buf[2] = y - k;
+ out_buf[3] = k;
+ out_buf += 4;
+ in_buf += 4;
+ num_bytes -= 4;
+ }
+ break;
+ default:
+ break;
}
- return out_buf-in_out;
+ return out_buf - in_out;
}
#if DEBUG_DATA
static void
-print_data(
- unsigned char * ptr,
- int n)
+print_data(unsigned char* ptr, int n)
{
while (n-- > 0) {
printf("%02x ", *(ptr++));
@@ -510,19 +524,18 @@ print_data(
status_t
-convert_space(
- color_space in_space,
- color_space out_space,
- unsigned char * in_data,
- int rowbytes,
- unsigned char * out_data)
+convert_space(color_space in_space, color_space out_space,
+ unsigned char* in_data, int rowbytes, unsigned char* out_data)
{
ASSERT(in_data != out_data);
- /* Instead of coding each transformation separately, which would
create */
- /* a very large number of conversion functions, we write one
function to */
+ /* Instead of coding each transformation separately, which would
create
+ */
+ /* a very large number of conversion functions, we write one
function to
+ */
/* convert to RGBA32, and another function to convert from RGBA32,
and */
- /* put them together to get a manageable program, at a slight
expense in */
+ /* put them together to get a manageable program, at a slight
expense in
+ */
/* conversion speed. */
int n;
@@ -536,7 +549,8 @@ convert_space(
memcpy(out_data, in_data, rowbytes);
return B_OK;
[ *** diff truncated: 142 lines dropped *** ]
############################################################################
Commit: 32c7f1e79f6244bea92686065bd64a73c6400f12
URL: https://git.haiku-os.org/haiku/commit/?id=32c7f1e79f62
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Sat Jan 26 17:35:21 2019 UTC
Committer: waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jan 26 20:46:59 2019 UTC
MIME db: identify ASCII variant of PPM; PBM, PGM files
Change-Id: I05574601bfae0094b7509a123cfd19d7fb02e7fd
Reviewed-on: https://review.haiku-os.org/c/903
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
----------------------------------------------------------------------------
############################################################################
Commit: 5d57984ba5e7d85cc6bc048699c718b2f5eaeca6
URL: https://git.haiku-os.org/haiku/commit/?id=5d57984ba5e7
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Sat Jan 26 19:18:03 2019 UTC
Committer: waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jan 26 20:46:59 2019 UTC
PPM translator: remove pre-R4 support
Change-Id: I26721cdd767bbf0df2936e97a2af322fed49cabf
Reviewed-on: https://review.haiku-os.org/c/904
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
----------------------------------------------------------------------------
############################################################################
Commit: 58913f60e8de5021abf1913804364f0810b0dd2f
URL: https://git.haiku-os.org/haiku/commit/?id=58913f60e8de
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Sat Jan 26 19:18:27 2019 UTC
Committer: waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jan 26 20:46:59 2019 UTC
PPM translator: read 1-bit and greyscale files
Change-Id: I0d9de6cb6eca99a78aada00c5299c16668c414f8
Reviewed-on: https://review.haiku-os.org/c/905
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
----------------------------------------------------------------------------
############################################################################
Revision: hrev52800
Commit: 71aec297511d8693eb083236b4aa080342fb137e
URL: https://git.haiku-os.org/haiku/commit/?id=71aec297511d
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Sat Jan 26 19:33:01 2019 UTC
Committer: waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jan 26 20:46:59 2019 UTC
PPM translator: use a buffer for reading
Reading the file 1 byte at a time from a BFile is very inefficient.
Add a buffer, which makes things a lot faster (parsing a 200x200 image
used to run for a few seconds with 100% CPU use).
Change-Id: Ie2eea819475c9301fbb6102c41fa05ec2d2ca343
Reviewed-on: https://review.haiku-os.org/c/906
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
----------------------------------------------------------------------------