PPM translator: clang-format
Change-Id: I290f9b369af37d919308759b83c42122f7f309bc Reviewed-on: https://review.haiku-os.org/c/902 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
4bf8cf7a1b
commit
72c5a125f1
@@ -22,12 +22,11 @@
|
|||||||
BPoint get_window_origin();
|
BPoint get_window_origin();
|
||||||
void set_window_origin(BPoint pt);
|
void set_window_origin(BPoint pt);
|
||||||
|
|
||||||
class PPMWindow :
|
class PPMWindow : public BWindow
|
||||||
public BWindow
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PPMWindow(BRect area) :
|
PPMWindow(BRect area)
|
||||||
BWindow(area, B_TRANSLATE("PPM Settings"), B_TITLED_WINDOW,
|
: BWindow(area, B_TRANSLATE("PPM Settings"), B_TITLED_WINDOW,
|
||||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
|
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
|
||||||
{
|
{
|
||||||
BLayoutBuilder::Group<>(this, B_HORIZONTAL);
|
BLayoutBuilder::Group<>(this, B_HORIZONTAL);
|
||||||
@@ -70,10 +69,14 @@ main()
|
|||||||
o.x -= r.Width() / 2;
|
o.x -= r.Width() / 2;
|
||||||
o.y -= r.Height() / 2;
|
o.y -= r.Height() / 2;
|
||||||
/* clamp location to screen */
|
/* clamp location to screen */
|
||||||
if (o.x < f.left) o.x = f.left;
|
if (o.x < f.left)
|
||||||
if (o.y < f.top) o.y = f.top;
|
o.x = f.left;
|
||||||
if (o.x > f.right) o.x = f.right;
|
if (o.y < f.top)
|
||||||
if (o.y > f.bottom) o.y = f.bottom;
|
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);
|
w->MoveTo(o);
|
||||||
@@ -81,4 +84,3 @@ main()
|
|||||||
app.Run();
|
app.Run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,13 +22,13 @@
|
|||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TranslatorAddOn.h>
|
|
||||||
#include <TranslationKit.h>
|
#include <TranslationKit.h>
|
||||||
|
#include <TranslatorAddOn.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#include "colorspace.h"
|
#include "colorspace.h"
|
||||||
@@ -43,11 +43,19 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !defined(_PR3_COMPATIBLE_) /* R4 headers? Else we need to define these constants. */
|
#if !defined(_PR3_COMPATIBLE_) /* R4 headers? Else we need to define these \
|
||||||
#define B_CMY24 ((color_space)0xC001) /* C[7:0] M[7:0] Y[7:0] No gray removal done */
|
constants. */
|
||||||
#define B_CMY32 ((color_space)0xC002) /* C[7:0] M[7:0] Y[7:0] X[7:0] No gray removal done */
|
#define B_CMY24 \
|
||||||
#define B_CMYA32 ((color_space)0xE002) /* C[7:0] M[7:0] Y[7:0] A[7:0] No gray removal done */
|
((color_space) 0xC001) /* C[7:0] M[7:0] Y[7:0] No gray removal \
|
||||||
#define B_CMYK32 ((color_space)0xC003) /* C[7:0] M[7:0] Y[7:0] K[7:0] */
|
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
|
#endif
|
||||||
|
|
||||||
#define PPM_TRANSLATOR_VERSION 0x100
|
#define PPM_TRANSLATOR_VERSION 0x100
|
||||||
@@ -66,18 +74,23 @@ int32 translatorVersion = PPM_TRANSLATOR_VERSION;
|
|||||||
#define PPM_TYPE 'PPM '
|
#define PPM_TYPE 'PPM '
|
||||||
|
|
||||||
|
|
||||||
/* These two data arrays are a really good idea to export from Translators, but not required. */
|
/* These two data arrays are a really good idea to export from Translators, but
|
||||||
translation_format inputFormats[] = {
|
* not required. */
|
||||||
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.4, 0.8, "image/x-be-bitmap", "Be Bitmap Format (PPMTranslator)" },
|
translation_format inputFormats[]
|
||||||
{ PPM_TYPE, B_TRANSLATOR_BITMAP, 0.3, 0.8, "image/x-portable-pixmap", "PPM image" },
|
= {{B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.4, 0.8, "image/x-be-bitmap",
|
||||||
{ 0, 0, 0, 0, "\0", "\0" }
|
"Be Bitmap Format (PPMTranslator)"},
|
||||||
}; /* optional (else Identify is always called) */
|
{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[] = {
|
translation_format outputFormats[]
|
||||||
{ B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.4, 0.8, "image/x-be-bitmap", "Be Bitmap Format (PPMTranslator)" },
|
= {{B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP, 0.4, 0.8, "image/x-be-bitmap",
|
||||||
{ PPM_TYPE, B_TRANSLATOR_BITMAP, 0.3, 0.8, "image/x-portable-pixmap", "PPM image" },
|
"Be Bitmap Format (PPMTranslator)"},
|
||||||
{ 0, 0, 0, 0, "\0", "\0" }
|
{PPM_TYPE, B_TRANSLATOR_BITMAP, 0.3, 0.8, "image/x-portable-pixmap",
|
||||||
}; /* optional (else Translate is called anyway) */
|
"PPM image"},
|
||||||
|
{0, 0, 0, 0, "\0",
|
||||||
|
"\0"}}; /* optional (else Translate is called anyway) */
|
||||||
|
|
||||||
/* Translators that don't export outputFormats */
|
/* Translators that don't export outputFormats */
|
||||||
/* will not be considered by files looking for */
|
/* will not be considered by files looking for */
|
||||||
@@ -96,7 +109,8 @@ static ppm_settings g_settings;
|
|||||||
|
|
||||||
BPoint get_window_origin();
|
BPoint get_window_origin();
|
||||||
void set_window_origin(BPoint pos);
|
void set_window_origin(BPoint pos);
|
||||||
BPoint get_window_origin()
|
BPoint
|
||||||
|
get_window_origin()
|
||||||
{
|
{
|
||||||
BPoint ret;
|
BPoint ret;
|
||||||
g_settings_lock.Lock();
|
g_settings_lock.Lock();
|
||||||
@@ -105,7 +119,8 @@ BPoint get_window_origin()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_window_origin(BPoint pos)
|
void
|
||||||
|
set_window_origin(BPoint pos)
|
||||||
{
|
{
|
||||||
g_settings_lock.Lock();
|
g_settings_lock.Lock();
|
||||||
g_settings.window_pos = pos;
|
g_settings.window_pos = pos;
|
||||||
@@ -114,10 +129,10 @@ void set_window_origin(BPoint pos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PrefsLoader {
|
class PrefsLoader
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
PrefsLoader(
|
PrefsLoader(const char* str)
|
||||||
const char * str)
|
|
||||||
{
|
{
|
||||||
dprintf(("PPMTranslator: PrefsLoader()\n"));
|
dprintf(("PPMTranslator: PrefsLoader()\n"));
|
||||||
/* defaults */
|
/* defaults */
|
||||||
@@ -151,50 +166,53 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sscanf(ptr, "%31[a-zA-Z_0-9] =", name) != 1) {
|
if (sscanf(ptr, "%31[a-zA-Z_0-9] =", name) != 1) {
|
||||||
syslog(LOG_ERR, "unknown PPMTranslator "
|
syslog(LOG_ERR,
|
||||||
"settings line: %s", line);
|
"unknown PPMTranslator "
|
||||||
}
|
"settings line: %s",
|
||||||
else {
|
line);
|
||||||
|
} else {
|
||||||
if (!strcmp(name, "color_space")) {
|
if (!strcmp(name, "color_space")) {
|
||||||
while (*ptr != '=') {
|
while (*ptr != '=') {
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
ptr++;
|
ptr++;
|
||||||
if (sscanf(ptr, "%d",
|
if (sscanf(ptr, "%d", (int*) &g_settings.out_space)
|
||||||
(int*)&g_settings.out_space) != 1) {
|
!= 1) {
|
||||||
syslog(LOG_ERR, "illegal color space "
|
syslog(LOG_ERR,
|
||||||
"in PPMTranslator settings: %s", ptr);
|
"illegal color space "
|
||||||
|
"in PPMTranslator settings: %s",
|
||||||
|
ptr);
|
||||||
}
|
}
|
||||||
}
|
} else if (!strcmp(name, "window_pos")) {
|
||||||
else if (!strcmp(name, "window_pos")) {
|
|
||||||
while (*ptr != '=') {
|
while (*ptr != '=') {
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
ptr++;
|
ptr++;
|
||||||
if (sscanf(ptr, "%f,%f",
|
if (sscanf(ptr, "%f,%f", &g_settings.window_pos.x,
|
||||||
&g_settings.window_pos.x,
|
&g_settings.window_pos.y)
|
||||||
&g_settings.window_pos.y) != 2) {
|
!= 2) {
|
||||||
syslog(LOG_ERR, "illegal window position "
|
syslog(LOG_ERR,
|
||||||
"in PPMTranslator settings: %s", ptr);
|
"illegal window position "
|
||||||
|
"in PPMTranslator settings: %s",
|
||||||
|
ptr);
|
||||||
}
|
}
|
||||||
}
|
} else if (!strcmp(name, "write_ascii")) {
|
||||||
else if (!strcmp(name, "write_ascii")) {
|
|
||||||
while (*ptr != '=') {
|
while (*ptr != '=') {
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
ptr++;
|
ptr++;
|
||||||
int ascii = g_settings.write_ascii;
|
int ascii = g_settings.write_ascii;
|
||||||
if (sscanf(ptr, "%d", &ascii) != 1) {
|
if (sscanf(ptr, "%d", &ascii) != 1) {
|
||||||
syslog(LOG_ERR, "illegal write_ascii value "
|
syslog(LOG_ERR,
|
||||||
"in PPMTranslator settings: %s", ptr);
|
"illegal write_ascii value "
|
||||||
}
|
"in PPMTranslator settings: %s",
|
||||||
else {
|
ptr);
|
||||||
|
} else {
|
||||||
g_settings.write_ascii = ascii;
|
g_settings.write_ascii = ascii;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
syslog(
|
||||||
syslog(LOG_ERR,
|
LOG_ERR, "unknown PPMTranslator setting: %s", line);
|
||||||
"unknown PPMTranslator setting: %s", line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,7 +237,8 @@ public:
|
|||||||
fprintf(f, "color_space = %d\n", g_settings.out_space);
|
fprintf(f, "color_space = %d\n", g_settings.out_space);
|
||||||
fprintf(f, "window_pos = %g,%g\n", g_settings.window_pos.x,
|
fprintf(f, "window_pos = %g,%g\n", g_settings.window_pos.x,
|
||||||
g_settings.window_pos.y);
|
g_settings.window_pos.y);
|
||||||
fprintf(f, "write_ascii = %d\n", g_settings.write_ascii ? 1 : 0);
|
fprintf(
|
||||||
|
f, "write_ascii = %d\n", g_settings.write_ascii ? 1 : 0);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -247,8 +266,7 @@ Identify( /* required */
|
|||||||
BPositionIO* inSource,
|
BPositionIO* inSource,
|
||||||
const translation_format* inFormat, /* can beNULL */
|
const translation_format* inFormat, /* can beNULL */
|
||||||
BMessage* ioExtension, /* can be NULL */
|
BMessage* ioExtension, /* can be NULL */
|
||||||
translator_info * outInfo,
|
translator_info* outInfo, uint32 outType)
|
||||||
uint32 outType)
|
|
||||||
{
|
{
|
||||||
dprintf(("PPMTranslator: Identify()\n"));
|
dprintf(("PPMTranslator: Identify()\n"));
|
||||||
/* Silence compiler warnings. */
|
/* Silence compiler warnings. */
|
||||||
@@ -267,26 +285,30 @@ Identify( /* required */
|
|||||||
int width, rowbytes, height, max;
|
int width, rowbytes, height, max;
|
||||||
bool ascii, is_ppm;
|
bool ascii, is_ppm;
|
||||||
color_space space;
|
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) {
|
if (err != B_OK) {
|
||||||
return err;
|
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;
|
outInfo->group = B_TRANSLATOR_BITMAP;
|
||||||
if (is_ppm) {
|
if (is_ppm) {
|
||||||
outInfo->type = PPM_TYPE;
|
outInfo->type = PPM_TYPE;
|
||||||
outInfo->quality = 0.3; /* no alpha, etc */
|
outInfo->quality = 0.3; /* no alpha, etc */
|
||||||
outInfo->capability = 0.8; /* we're pretty good at PPM reading, though */
|
outInfo->capability
|
||||||
|
= 0.8; /* we're pretty good at PPM reading, though */
|
||||||
strlcpy(outInfo->name, B_TRANSLATE("PPM image"), sizeof(outInfo->name));
|
strlcpy(outInfo->name, B_TRANSLATE("PPM image"), sizeof(outInfo->name));
|
||||||
strcpy(outInfo->MIME, "image/x-portable-pixmap");
|
strcpy(outInfo->MIME, "image/x-portable-pixmap");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
outInfo->type = B_TRANSLATOR_BITMAP;
|
outInfo->type = B_TRANSLATOR_BITMAP;
|
||||||
outInfo->quality = 0.4; /* B_TRANSLATOR_BITMAP can do alpha, at least */
|
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->capability
|
||||||
|
= 0.8; /* and we might not know many variations thereof */
|
||||||
strlcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (PPMTranslator)"),
|
strlcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (PPMTranslator)"),
|
||||||
sizeof(outInfo->name));
|
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_OK;
|
||||||
}
|
}
|
||||||
@@ -300,8 +322,7 @@ Translate( /* required */
|
|||||||
BPositionIO* inSource,
|
BPositionIO* inSource,
|
||||||
const translator_info* /* inInfo*/, /* silence compiler warning */
|
const translator_info* /* inInfo*/, /* silence compiler warning */
|
||||||
BMessage* ioExtension, /* can be NULL */
|
BMessage* ioExtension, /* can be NULL */
|
||||||
uint32 outType,
|
uint32 outType, BPositionIO* outDestination)
|
||||||
BPositionIO * outDestination)
|
|
||||||
{
|
{
|
||||||
dprintf(("PPMTranslator: Translate()\n"));
|
dprintf(("PPMTranslator: Translate()\n"));
|
||||||
inSource->Seek(0, SEEK_SET); /* paranoia */
|
inSource->Seek(0, SEEK_SET); /* paranoia */
|
||||||
@@ -310,7 +331,8 @@ Translate( /* required */
|
|||||||
if (!outType) {
|
if (!outType) {
|
||||||
outType = B_TRANSLATOR_BITMAP;
|
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) {
|
if (outType != B_TRANSLATOR_BITMAP && outType != PPM_TYPE) {
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
@@ -322,7 +344,8 @@ Translate( /* required */
|
|||||||
/* Read_ppm_header() will always return with stream at beginning of data */
|
/* 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. */
|
/* for both B_TRANSLATOR_BITMAP and PPM_TYPE, and indicate what it is. */
|
||||||
char* comment = NULL;
|
char* comment = NULL;
|
||||||
status_t err = read_ppm_header(inSource, &width, &rowbytes, &height, &max, &ascii, &space, &is_ppm, &comment);
|
status_t err = read_ppm_header(inSource, &width, &rowbytes, &height, &max,
|
||||||
|
&ascii, &space, &is_ppm, &comment);
|
||||||
if (comment != NULL) {
|
if (comment != NULL) {
|
||||||
if (ioExtension != NULL) {
|
if (ioExtension != NULL) {
|
||||||
#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
|
#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
|
||||||
@@ -354,16 +377,21 @@ Translate( /* required */
|
|||||||
if (outType == PPM_TYPE) {
|
if (outType == PPM_TYPE) {
|
||||||
out_space = B_RGB24_BIG;
|
out_space = B_RGB24_BIG;
|
||||||
out_rowbytes = 3 * width;
|
out_rowbytes = 3 * width;
|
||||||
}
|
} else { /* When outputting to B_TRANSLATOR_BITMAP, follow user's wishes.
|
||||||
else { /* When outputting to B_TRANSLATOR_BITMAP, follow user's wishes. */
|
*/
|
||||||
#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
|
#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
|
||||||
if (!ioExtension || ioExtension->FindInt32(B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE, (int32*)&out_space) ||
|
if (!ioExtension
|
||||||
|
|| ioExtension->FindInt32(
|
||||||
|
B_TRANSLATOR_EXT_BITMAP_COLOR_SPACE, (int32*) &out_space)
|
||||||
|
||
|
||||||
#else
|
#else
|
||||||
if (!ioExtension || ioExtension->FindInt32("bits/space", (int32*)&out_space) ||
|
if (!ioExtension
|
||||||
|
|| ioExtension->FindInt32("bits/space", (int32*) &out_space) ||
|
||||||
#endif
|
#endif
|
||||||
(out_space == B_NO_COLOR_SPACE)) {
|
(out_space == B_NO_COLOR_SPACE)) {
|
||||||
if (g_settings.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. */
|
switch (space) { /* The 24-bit versions are pretty silly, use 32
|
||||||
|
instead. */
|
||||||
case B_RGB24:
|
case B_RGB24:
|
||||||
case B_RGB24_BIG:
|
case B_RGB24_BIG:
|
||||||
out_space = B_RGB32;
|
out_space = B_RGB32;
|
||||||
@@ -373,8 +401,7 @@ Translate( /* required */
|
|||||||
out_space = space;
|
out_space = space;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
out_space = g_settings.out_space;
|
out_space = g_settings.out_space;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,13 +418,16 @@ Translate( /* required */
|
|||||||
else
|
else
|
||||||
magic = "P6\n";
|
magic = "P6\n";
|
||||||
err = outDestination->Write(magic, strlen(magic));
|
err = outDestination->Write(magic, strlen(magic));
|
||||||
if (err == (long)strlen(magic)) err = 0;
|
if (err == (long) strlen(magic))
|
||||||
|
err = 0;
|
||||||
// comment = NULL;
|
// comment = NULL;
|
||||||
const char* fsComment;
|
const char* fsComment;
|
||||||
#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
|
#if defined(_PR3_COMPATIBLE_) /* R4 headers? */
|
||||||
if ((ioExtension != NULL) && !ioExtension->FindString(B_TRANSLATOR_EXT_COMMENT, &fsComment)) {
|
if ((ioExtension != NULL)
|
||||||
|
&& !ioExtension->FindString(B_TRANSLATOR_EXT_COMMENT, &fsComment)) {
|
||||||
#else
|
#else
|
||||||
if ((ioExtension != NULL) && !ioExtension->FindString("/comment", &fsComment)) {
|
if ((ioExtension != NULL)
|
||||||
|
&& !ioExtension->FindString("/comment", &fsComment)) {
|
||||||
#endif
|
#endif
|
||||||
err = write_comment(fsComment, outDestination);
|
err = write_comment(fsComment, outDestination);
|
||||||
}
|
}
|
||||||
@@ -405,11 +435,11 @@ Translate( /* required */
|
|||||||
char data[40];
|
char data[40];
|
||||||
sprintf(data, "%d %d %d\n", width, height, max);
|
sprintf(data, "%d %d %d\n", width, height, max);
|
||||||
err = outDestination->Write(data, strlen(data));
|
err = outDestination->Write(data, strlen(data));
|
||||||
if (err == (long)strlen(data)) err = 0;
|
if (err == (long) strlen(data))
|
||||||
|
err = 0;
|
||||||
}
|
}
|
||||||
/* header done */
|
/* header done */
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dprintf(("PPMTranslator: write B_TRANSLATOR_BITMAP\n"));
|
dprintf(("PPMTranslator: write B_TRANSLATOR_BITMAP\n"));
|
||||||
/* B_TRANSLATOR_BITMAP header */
|
/* B_TRANSLATOR_BITMAP header */
|
||||||
TranslatorBitmap hdr;
|
TranslatorBitmap hdr;
|
||||||
@@ -421,94 +451,102 @@ Translate( /* required */
|
|||||||
hdr.rowBytes = B_HOST_TO_BENDIAN_INT32(out_rowbytes);
|
hdr.rowBytes = B_HOST_TO_BENDIAN_INT32(out_rowbytes);
|
||||||
hdr.colors = (color_space) B_HOST_TO_BENDIAN_INT32(out_space);
|
hdr.colors = (color_space) B_HOST_TO_BENDIAN_INT32(out_space);
|
||||||
hdr.dataSize = B_HOST_TO_BENDIAN_INT32(out_rowbytes * height);
|
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));
|
dprintf(("rowBytes is %d, width %d, out_space %x, space %x\n",
|
||||||
|
out_rowbytes, width, out_space, space));
|
||||||
err = outDestination->Write(&hdr, sizeof(hdr));
|
err = outDestination->Write(&hdr, sizeof(hdr));
|
||||||
dprintf(("PPMTranslator: Write() returns %" B_PRIx32 "\n", err));
|
dprintf(("PPMTranslator: Write() returns %" B_PRIx32 "\n", err));
|
||||||
#if DEBUG
|
#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());
|
printf("map rb = %" B_PRId32 "\n", map->BytesPerRow());
|
||||||
delete map;
|
delete map;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (err == sizeof(hdr)) err = 0;
|
if (err == sizeof(hdr))
|
||||||
|
err = 0;
|
||||||
/* header done */
|
/* header done */
|
||||||
}
|
}
|
||||||
if (err != B_OK) {
|
if (err != B_OK) {
|
||||||
return err > 0 ? B_IO_ERROR : err;
|
return err > 0 ? B_IO_ERROR : err;
|
||||||
}
|
}
|
||||||
/* Write data. Luckily, PPM and B_TRANSLATOR_BITMAP both scan from left to right, top to bottom. */
|
/* Write data. Luckily, PPM and B_TRANSLATOR_BITMAP both scan from left to
|
||||||
return copy_data(inSource, outDestination, rowbytes, out_rowbytes, height, max, ascii, out_ascii, space, out_space);
|
* right, top to bottom. */
|
||||||
|
return copy_data(inSource, outDestination, rowbytes, out_rowbytes, height,
|
||||||
|
max, ascii, out_ascii, space, out_space);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PPMView :
|
class PPMView : public BView
|
||||||
public BView
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PPMView(
|
PPMView(const char* name, uint32 flags) : BView(name, flags)
|
||||||
const char * name,
|
|
||||||
uint32 flags) :
|
|
||||||
BView(name, flags)
|
|
||||||
{
|
{
|
||||||
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||||
|
|
||||||
fTitle = new BStringView("title",
|
fTitle = new BStringView("title", B_TRANSLATE("PPM image translator"));
|
||||||
B_TRANSLATE("PPM image translator"));
|
|
||||||
fTitle->SetFont(be_bold_font);
|
fTitle->SetFont(be_bold_font);
|
||||||
|
|
||||||
char detail[100];
|
char detail[100];
|
||||||
int ver = static_cast<int>(translatorVersion);
|
int ver = static_cast<int>(translatorVersion);
|
||||||
sprintf(detail, B_TRANSLATE("Version %d.%d.%d, %s"), ver >> 8,
|
sprintf(detail, B_TRANSLATE("Version %d.%d.%d, %s"), ver >> 8,
|
||||||
((ver >> 4) & 0xf),
|
((ver >> 4) & 0xf), (ver & 0xf), __DATE__);
|
||||||
(ver & 0xf), __DATE__);
|
|
||||||
fDetail = new BStringView("detail", detail);
|
fDetail = new BStringView("detail", detail);
|
||||||
|
|
||||||
fBasedOn = new BStringView("basedOn",
|
fBasedOn = new BStringView(
|
||||||
B_TRANSLATE("Based on PPMTranslator sample code"));
|
"basedOn", B_TRANSLATE("Based on PPMTranslator sample code"));
|
||||||
|
|
||||||
fCopyright = new BStringView("copyright",
|
fCopyright = new BStringView("copyright",
|
||||||
B_TRANSLATE("Sample code copyright 1999, Be Incorporated"));
|
B_TRANSLATE("Sample code copyright 1999, Be Incorporated"));
|
||||||
|
|
||||||
fMenu = new BPopUpMenu("Color Space");
|
fMenu = new BPopUpMenu("Color Space");
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("None"),
|
fMenu->AddItem(
|
||||||
CSMessage(B_NO_COLOR_SPACE)));
|
new BMenuItem(B_TRANSLATE("None"), CSMessage(B_NO_COLOR_SPACE)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 8:8:8 32 bits"),
|
fMenu->AddItem(new BMenuItem(
|
||||||
CSMessage(B_RGB32)));
|
B_TRANSLATE("RGB 8:8:8 32 bits"), CSMessage(B_RGB32)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 8:8:8:8 32 "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 8:8:8:8 32 "
|
||||||
"bits"), CSMessage(B_RGBA32)));
|
"bits"),
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 5:5:5 16 bits"),
|
CSMessage(B_RGBA32)));
|
||||||
CSMessage(B_RGB15)));
|
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 "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 5:5:5:1 16 "
|
||||||
"bits"), CSMessage(B_RGBA15)));
|
"bits"),
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 5:6:5 16 bits"),
|
CSMessage(B_RGBA15)));
|
||||||
CSMessage(B_RGB16)));
|
fMenu->AddItem(new BMenuItem(
|
||||||
|
B_TRANSLATE("RGB 5:6:5 16 bits"), CSMessage(B_RGB16)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("System palette 8 "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("System palette 8 "
|
||||||
"bits"), CSMessage(B_CMAP8)));
|
"bits"),
|
||||||
|
CSMessage(B_CMAP8)));
|
||||||
fMenu->AddSeparatorItem();
|
fMenu->AddSeparatorItem();
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("Grayscale 8 bits"),
|
fMenu->AddItem(
|
||||||
CSMessage(B_GRAY8)));
|
new BMenuItem(B_TRANSLATE("Grayscale 8 bits"), CSMessage(B_GRAY8)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("Bitmap 1 bit"),
|
fMenu->AddItem(
|
||||||
CSMessage(B_GRAY1)));
|
new BMenuItem(B_TRANSLATE("Bitmap 1 bit"), CSMessage(B_GRAY1)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMY 8:8:8 32 bits"),
|
fMenu->AddItem(new BMenuItem(
|
||||||
CSMessage(B_CMY32)));
|
B_TRANSLATE("CMY 8:8:8 32 bits"), CSMessage(B_CMY32)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMYA 8:8:8:8 32 "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMYA 8:8:8:8 32 "
|
||||||
"bits"), CSMessage(B_CMYA32)));
|
"bits"),
|
||||||
|
CSMessage(B_CMYA32)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMYK 8:8:8:8 32 "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("CMYK 8:8:8:8 32 "
|
||||||
"bits"), CSMessage(B_CMYK32)));
|
"bits"),
|
||||||
|
CSMessage(B_CMYK32)));
|
||||||
fMenu->AddSeparatorItem();
|
fMenu->AddSeparatorItem();
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 8:8:8 32 bits "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 8:8:8 32 bits "
|
||||||
"big-endian"), CSMessage(B_RGB32_BIG)));
|
"big-endian"),
|
||||||
|
CSMessage(B_RGB32_BIG)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 8:8:8:8 32 "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 8:8:8:8 32 "
|
||||||
"bits big-endian"), CSMessage(B_RGBA32_BIG)));
|
"bits big-endian"),
|
||||||
|
CSMessage(B_RGBA32_BIG)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 5:5:5 16 bits "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 5:5:5 16 bits "
|
||||||
"big-endian"), CSMessage(B_RGB15_BIG)));
|
"big-endian"),
|
||||||
|
CSMessage(B_RGB15_BIG)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 5:5:5:1 16 "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGBA 5:5:5:1 16 "
|
||||||
"bits big-endian"), CSMessage(B_RGBA15_BIG)));
|
"bits big-endian"),
|
||||||
|
CSMessage(B_RGBA15_BIG)));
|
||||||
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 5:6:5 16 bits "
|
fMenu->AddItem(new BMenuItem(B_TRANSLATE("RGB 5:6:5 16 bits "
|
||||||
"big-endian"), CSMessage(B_RGB16)));
|
"big-endian"),
|
||||||
fField = new BMenuField(B_TRANSLATE("Input color space:"),
|
CSMessage(B_RGB16)));
|
||||||
fMenu);
|
fField = new BMenuField(B_TRANSLATE("Input color space:"), fMenu);
|
||||||
fField->SetViewColor(ViewColor());
|
fField->SetViewColor(ViewColor());
|
||||||
SelectColorSpace(g_settings.out_space);
|
SelectColorSpace(g_settings.out_space);
|
||||||
BMessage* msg = new BMessage(CHANGE_ASCII);
|
BMessage* msg = new BMessage(CHANGE_ASCII);
|
||||||
@@ -534,31 +572,22 @@ public:
|
|||||||
|
|
||||||
BFont font;
|
BFont font;
|
||||||
GetFont(&font);
|
GetFont(&font);
|
||||||
SetExplicitPreferredSize(BSize((font.Size() * 350)/12,
|
SetExplicitPreferredSize(
|
||||||
(font.Size() * 200)/12));
|
BSize((font.Size() * 350) / 12, (font.Size() * 200) / 12));
|
||||||
}
|
|
||||||
~PPMView()
|
|
||||||
{
|
|
||||||
/* nothing here */
|
|
||||||
}
|
}
|
||||||
|
~PPMView() { /* nothing here */ }
|
||||||
|
|
||||||
enum {
|
enum { SET_COLOR_SPACE = 'ppm=', CHANGE_ASCII };
|
||||||
SET_COLOR_SPACE = 'ppm=',
|
|
||||||
CHANGE_ASCII
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual void MessageReceived(
|
virtual void MessageReceived(BMessage* message)
|
||||||
BMessage * message)
|
|
||||||
{
|
{
|
||||||
if (message->what == SET_COLOR_SPACE) {
|
if (message->what == SET_COLOR_SPACE) {
|
||||||
SetSettings(message);
|
SetSettings(message);
|
||||||
}
|
} else if (message->what == CHANGE_ASCII) {
|
||||||
else if (message->what == CHANGE_ASCII) {
|
|
||||||
BMessage msg;
|
BMessage msg;
|
||||||
msg.AddBool("ppm /ascii", fAscii->Value());
|
msg.AddBool("ppm /ascii", fAscii->Value());
|
||||||
SetSettings(&msg);
|
SetSettings(&msg);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -576,8 +605,7 @@ virtual void AllAttached()
|
|||||||
fAscii->SetTarget(msgr);
|
fAscii->SetTarget(msgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSettings(
|
void SetSettings(BMessage* message)
|
||||||
BMessage * message)
|
|
||||||
{
|
{
|
||||||
g_settings_lock.Lock();
|
g_settings_lock.Lock();
|
||||||
color_space space;
|
color_space space;
|
||||||
@@ -603,16 +631,14 @@ private:
|
|||||||
BMenuField* fField;
|
BMenuField* fField;
|
||||||
BCheckBox* fAscii;
|
BCheckBox* fAscii;
|
||||||
|
|
||||||
BMessage * CSMessage(
|
BMessage* CSMessage(color_space space)
|
||||||
color_space space)
|
|
||||||
{
|
{
|
||||||
BMessage* ret = new BMessage(SET_COLOR_SPACE);
|
BMessage* ret = new BMessage(SET_COLOR_SPACE);
|
||||||
ret->AddInt32("space", space);
|
ret->AddInt32("space", space);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectColorSpace(
|
void SelectColorSpace(color_space space)
|
||||||
color_space space)
|
|
||||||
{
|
{
|
||||||
for (int ix = 0; ix < fMenu->CountItems(); ix++) {
|
for (int ix = 0; ix < fMenu->CountItems(); ix++) {
|
||||||
int32 s;
|
int32 s;
|
||||||
@@ -641,13 +667,13 @@ private:
|
|||||||
status_t
|
status_t
|
||||||
MakeConfig(/* optional */
|
MakeConfig(/* optional */
|
||||||
BMessage* ioExtension, /* can be NULL */
|
BMessage* ioExtension, /* can be NULL */
|
||||||
BView * * outView,
|
BView** outView, BRect* outExtent)
|
||||||
BRect * outExtent)
|
|
||||||
{
|
{
|
||||||
PPMView * v = new PPMView(B_TRANSLATE("PPMTranslator Settings"),
|
PPMView* v
|
||||||
B_WILL_DRAW);
|
= new PPMView(B_TRANSLATE("PPMTranslator Settings"), B_WILL_DRAW);
|
||||||
*outView = v;
|
*outView = v;
|
||||||
v->ResizeTo(v->ExplicitPreferredSize());;
|
v->ResizeTo(v->ExplicitPreferredSize());
|
||||||
|
;
|
||||||
*outExtent = v->Bounds();
|
*outExtent = v->Bounds();
|
||||||
if (ioExtension) {
|
if (ioExtension) {
|
||||||
v->SetSettings(ioExtension);
|
v->SetSettings(ioExtension);
|
||||||
@@ -678,20 +704,9 @@ GetConfigMessage( /* optional */
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
read_ppm_header(
|
read_ppm_header(BDataIO* inSource, int* width, int* rowbytes, int* height,
|
||||||
BDataIO * inSource,
|
int* max, bool* ascii, color_space* space, bool* is_ppm, char** comment)
|
||||||
int * width,
|
|
||||||
int * rowbytes,
|
|
||||||
int * height,
|
|
||||||
int * max,
|
|
||||||
bool * ascii,
|
|
||||||
color_space * space,
|
|
||||||
bool * is_ppm,
|
|
||||||
char ** comment)
|
|
||||||
{
|
{
|
||||||
/* check for PPM magic number */
|
/* check for PPM magic number */
|
||||||
char ch[2];
|
char ch[2];
|
||||||
@@ -703,18 +718,17 @@ read_ppm_header(
|
|||||||
/* B_TRANSLATOR_BITMAP magic? */
|
/* B_TRANSLATOR_BITMAP magic? */
|
||||||
if (ch[0] == 'b' && ch[1] == 'i') {
|
if (ch[0] == 'b' && ch[1] == 'i') {
|
||||||
*is_ppm = false;
|
*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;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
*is_ppm = true;
|
*is_ppm = true;
|
||||||
if (ch[1] == '6') {
|
if (ch[1] == '6') {
|
||||||
*ascii = false;
|
*ascii = false;
|
||||||
}
|
} else if (ch[1] == '3') {
|
||||||
else if (ch[1] == '3') {
|
|
||||||
*ascii = true;
|
*ascii = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
// status_t err = B_NO_TRANSLATOR;
|
// status_t err = B_NO_TRANSLATOR;
|
||||||
@@ -723,7 +737,8 @@ read_ppm_header(
|
|||||||
scan_height,
|
scan_height,
|
||||||
scan_max,
|
scan_max,
|
||||||
scan_white
|
scan_white
|
||||||
} state = scan_width;
|
} state
|
||||||
|
= scan_width;
|
||||||
int* scan = NULL;
|
int* scan = NULL;
|
||||||
bool in_comment = false;
|
bool in_comment = false;
|
||||||
*space = B_RGB24_BIG;
|
*space = B_RGB24_BIG;
|
||||||
@@ -774,17 +789,17 @@ read_ppm_header(
|
|||||||
*scan = 0;
|
*scan = 0;
|
||||||
}
|
}
|
||||||
*scan = (*scan) * 10 + (ch[0] - '0');
|
*scan = (*scan) * 10 + (ch[0] - '0');
|
||||||
}
|
} else if (isspace(ch[0])) {
|
||||||
else if (isspace(ch[0])) {
|
|
||||||
if (scan) { /* are we done with one value? */
|
if (scan) { /* are we done with one value? */
|
||||||
scan = NULL;
|
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 */
|
if (state == scan_white) { /* we only ever read one whitespace,
|
||||||
return B_OK; /* when reading ASCII, and there is a single whitespace after max in raw mode */
|
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) {
|
if (state != scan_white) {
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
@@ -795,20 +810,13 @@ read_ppm_header(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
read_bits_header(
|
read_bits_header(BDataIO* io, int skipped, int* width, int* rowbytes,
|
||||||
BDataIO * io,
|
int* height, int* max, bool* ascii, color_space* space)
|
||||||
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 */
|
/* read the rest of a possible B_TRANSLATOR_BITMAP header */
|
||||||
if (skipped < 0 || skipped > 4) return B_NO_TRANSLATOR;
|
if (skipped < 0 || skipped > 4)
|
||||||
|
return B_NO_TRANSLATOR;
|
||||||
int rd = sizeof(TranslatorBitmap) - skipped;
|
int rd = sizeof(TranslatorBitmap) - skipped;
|
||||||
TranslatorBitmap hdr;
|
TranslatorBitmap hdr;
|
||||||
/* pre-initialize magic because we might have skipped part of it already */
|
/* pre-initialize magic because we might have skipped part of it already */
|
||||||
@@ -830,7 +838,8 @@ read_bits_header(
|
|||||||
if (hdr.magic != B_TRANSLATOR_BITMAP) {
|
if (hdr.magic != B_TRANSLATOR_BITMAP) {
|
||||||
return B_NO_TRANSLATOR;
|
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;
|
return B_NO_TRANSLATOR;
|
||||||
}
|
}
|
||||||
if (hdr.rowBytes * (hdr.bounds.Height() + 1) > hdr.dataSize) {
|
if (hdr.rowBytes * (hdr.bounds.Height() + 1) > hdr.dataSize) {
|
||||||
@@ -847,11 +856,10 @@ 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
|
status_t
|
||||||
write_comment(
|
write_comment(const char* str, BDataIO* io)
|
||||||
const char * str,
|
|
||||||
BDataIO * io)
|
|
||||||
{
|
{
|
||||||
const char* end = str + strlen(str);
|
const char* end = str + strlen(str);
|
||||||
const char* ptr = str;
|
const char* ptr = str;
|
||||||
@@ -892,11 +900,7 @@ write_comment(
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
read_ascii_line(
|
read_ascii_line(BDataIO* in, int max, unsigned char* data, int rowbytes)
|
||||||
BDataIO * in,
|
|
||||||
int max,
|
|
||||||
unsigned char * data,
|
|
||||||
int rowbytes)
|
|
||||||
{
|
{
|
||||||
char ch;
|
char ch;
|
||||||
status_t err;
|
status_t err;
|
||||||
@@ -913,8 +917,7 @@ read_ascii_line(
|
|||||||
if (isdigit(ch)) {
|
if (isdigit(ch)) {
|
||||||
dig = true;
|
dig = true;
|
||||||
val = val * 10 + (ch - '0');
|
val = val * 10 + (ch - '0');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (dig) {
|
if (dig) {
|
||||||
*(data++) = val * 255 / max;
|
*(data++) = val * 255 / max;
|
||||||
val = 0;
|
val = 0;
|
||||||
@@ -944,10 +947,7 @@ read_ascii_line(
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
write_ascii_line(
|
write_ascii_line(BDataIO* out, unsigned char* data, int rowbytes)
|
||||||
BDataIO * out,
|
|
||||||
unsigned char * data,
|
|
||||||
int rowbytes)
|
|
||||||
{
|
{
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
int linelen = 0;
|
int linelen = 0;
|
||||||
@@ -971,8 +971,7 @@ write_ascii_line(
|
|||||||
|
|
||||||
|
|
||||||
static unsigned char*
|
static unsigned char*
|
||||||
make_scale_data(
|
make_scale_data(int max)
|
||||||
int max)
|
|
||||||
{
|
{
|
||||||
unsigned char* ptr = (unsigned char*) malloc(max);
|
unsigned char* ptr = (unsigned char*) malloc(max);
|
||||||
for (int ix = 0; ix < max; ix++) {
|
for (int ix = 0; ix < max; ix++) {
|
||||||
@@ -983,10 +982,7 @@ make_scale_data(
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
scale_data(
|
scale_data(unsigned char* scale, unsigned char* data, int bytes)
|
||||||
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]];
|
data[ix] = scale[data[ix]];
|
||||||
@@ -995,19 +991,12 @@ scale_data(
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
copy_data(
|
copy_data(BDataIO* in, BDataIO* out, int rowbytes, int out_rowbytes, int height,
|
||||||
BDataIO * in,
|
int max, bool in_ascii, bool out_ascii, color_space in_space,
|
||||||
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)
|
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. */
|
/* We read/write one scanline at a time. */
|
||||||
unsigned char* data = (unsigned char*) malloc(rowbytes);
|
unsigned char* data = (unsigned char*) malloc(rowbytes);
|
||||||
unsigned char* out_data = (unsigned char*) malloc(out_rowbytes);
|
unsigned char* out_data = (unsigned char*) malloc(out_rowbytes);
|
||||||
@@ -1025,8 +1014,7 @@ copy_data(
|
|||||||
while ((height-- > 0) && !err) {
|
while ((height-- > 0) && !err) {
|
||||||
if (in_ascii) {
|
if (in_ascii) {
|
||||||
err = read_ascii_line(in, max, data, rowbytes);
|
err = read_ascii_line(in, max, data, rowbytes);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
err = in->Read(data, rowbytes);
|
err = in->Read(data, rowbytes);
|
||||||
if (err == rowbytes) {
|
if (err == rowbytes) {
|
||||||
err = B_OK;
|
err = B_OK;
|
||||||
@@ -1038,13 +1026,13 @@ copy_data(
|
|||||||
if (err == B_OK) {
|
if (err == B_OK) {
|
||||||
unsigned char* wbuf = data;
|
unsigned char* wbuf = data;
|
||||||
if (in_space != out_space) {
|
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;
|
wbuf = out_data;
|
||||||
}
|
}
|
||||||
if (!err && out_ascii) {
|
if (!err && out_ascii) {
|
||||||
err = write_ascii_line(out, wbuf, out_rowbytes);
|
err = write_ascii_line(out, wbuf, out_rowbytes);
|
||||||
}
|
} else if (!err) {
|
||||||
else if (!err) {
|
|
||||||
err = out->Write(wbuf, out_rowbytes);
|
err = out->Write(wbuf, out_rowbytes);
|
||||||
if (err == out_rowbytes) {
|
if (err == out_rowbytes) {
|
||||||
err = B_OK;
|
err = B_OK;
|
||||||
@@ -1057,5 +1045,3 @@ copy_data(
|
|||||||
free(scale);
|
free(scale);
|
||||||
return err > 0 ? B_IO_ERROR : err;
|
return err > 0 ? B_IO_ERROR : err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,35 +5,42 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <Debug.h>
|
||||||
#include <GraphicsDefs.h>
|
#include <GraphicsDefs.h>
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
#include <Debug.h>
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "colorspace.h"
|
#include "colorspace.h"
|
||||||
|
|
||||||
|
|
||||||
#if !defined(_PR3_COMPATIBLE_)
|
#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_CMY24 \
|
||||||
#define B_CMY32 ((color_space)0xC002) /* C[7:0] M[7:0] Y[7:0] X[7:0] No gray removal done */
|
((color_space) 0xC001) /* C[7:0] M[7:0] Y[7:0] No gray removal \
|
||||||
#define B_CMYA32 ((color_space)0xE002) /* C[7:0] M[7:0] Y[7:0] A[7:0] No gray removal done */
|
done */
|
||||||
#define B_CMYK32 ((color_space)0xC003) /* C[7:0] M[7:0] Y[7:0] K[7:0] */
|
#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
|
#endif
|
||||||
|
|
||||||
int
|
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,
|
color_space from_space,
|
||||||
unsigned char * in_data,
|
unsigned char* in_data, int rowbytes, unsigned char* out_buf)
|
||||||
int rowbytes,
|
|
||||||
unsigned char * out_buf)
|
|
||||||
{
|
{
|
||||||
ASSERT(in_data != out_buf);
|
ASSERT(in_data != out_buf);
|
||||||
|
|
||||||
/* We don't do YUV and friends yet. */
|
/* We don't do YUV and friends yet. */
|
||||||
/* It's important to replicate the most significant component bits to LSB when going 15->24 */
|
/* It's important to replicate the most significant component bits to LSB
|
||||||
|
* when going 15->24 */
|
||||||
unsigned char* in_out = out_buf;
|
unsigned char* in_out = out_buf;
|
||||||
switch (from_space) {
|
switch (from_space) {
|
||||||
case B_RGB32:
|
case B_RGB32:
|
||||||
@@ -198,8 +205,7 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
if (c1 & b) {
|
if (c1 & b) {
|
||||||
ch = 0;
|
ch = 0;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ch = 255;
|
ch = 255;
|
||||||
}
|
}
|
||||||
out_buf[0] = ch;
|
out_buf[0] = ch;
|
||||||
@@ -212,7 +218,8 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
rowbytes -= 1;
|
rowbytes -= 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case B_CMY24: /* We do the "clean" inversion which doesn't correct for printing ink deficiencies. */
|
case B_CMY24: /* We do the "clean" inversion which doesn't correct
|
||||||
|
for printing ink deficiencies. */
|
||||||
while (rowbytes > 2) {
|
while (rowbytes > 2) {
|
||||||
out_buf[0] = 255 - in_data[2];
|
out_buf[0] = 255 - in_data[2];
|
||||||
out_buf[1] = 255 - in_data[1];
|
out_buf[1] = 255 - in_data[1];
|
||||||
@@ -245,7 +252,8 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
rowbytes -= 4;
|
rowbytes -= 4;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case B_CMYK32: /* We assume uniform gray removal, and no under-color-removal. */
|
case B_CMYK32: /* We assume uniform gray removal, and no
|
||||||
|
under-color-removal. */
|
||||||
while (rowbytes > 3) {
|
while (rowbytes > 3) {
|
||||||
int comp = 255 - in_data[2] - in_data[3];
|
int comp = 255 - in_data[2] - in_data[3];
|
||||||
out_buf[0] = comp < 0 ? 0 : comp;
|
out_buf[0] = comp < 0 ? 0 : comp;
|
||||||
@@ -267,18 +275,18 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
collapse_data(
|
collapse_data(unsigned char* in_buf, int num_bytes, color_space out_space,
|
||||||
unsigned char * in_buf,
|
|
||||||
int num_bytes,
|
|
||||||
color_space out_space,
|
|
||||||
unsigned char* out_buf)
|
unsigned char* out_buf)
|
||||||
{
|
{
|
||||||
ASSERT(in_buf != out_buf);
|
ASSERT(in_buf != out_buf);
|
||||||
|
|
||||||
unsigned char* in_out = out_buf;
|
unsigned char* in_out = out_buf;
|
||||||
/* We could increase perceived image quality of down conversions by implementing */
|
/* We could increase perceived image quality of down conversions by
|
||||||
/* dithering. However, someone might want to operate on the images after */
|
* implementing */
|
||||||
/* conversion, in which case dithering would be un-good. Besides, good error */
|
/* 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. */
|
/* diffusion requires more than one scan line to propagate errors to. */
|
||||||
switch (out_space) {
|
switch (out_space) {
|
||||||
case B_RGB32:
|
case B_RGB32:
|
||||||
@@ -299,7 +307,8 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_RGB16:
|
case B_RGB16:
|
||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
uint16 val = (in_buf[0]>>3)|((in_buf[1]<<3)&0x7e0)|((in_buf[2]<<8)&0xf800);
|
uint16 val = (in_buf[0] >> 3) | ((in_buf[1] << 3) & 0x7e0)
|
||||||
|
| ((in_buf[2] << 8) & 0xf800);
|
||||||
out_buf[0] = val;
|
out_buf[0] = val;
|
||||||
out_buf[1] = val >> 8;
|
out_buf[1] = val >> 8;
|
||||||
out_buf += 2;
|
out_buf += 2;
|
||||||
@@ -309,7 +318,8 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_RGB15:
|
case B_RGB15:
|
||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
uint16 val = (in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00)|0x8000;
|
uint16 val = (in_buf[0] >> 3) | ((in_buf[1] << 2) & 0x3e0)
|
||||||
|
| ((in_buf[2] << 7) & 0x7c00) | 0x8000;
|
||||||
out_buf[0] = val;
|
out_buf[0] = val;
|
||||||
out_buf[1] = val >> 8;
|
out_buf[1] = val >> 8;
|
||||||
out_buf += 2;
|
out_buf += 2;
|
||||||
@@ -319,7 +329,8 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_RGBA15:
|
case B_RGBA15:
|
||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
uint16 val = (in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00);
|
uint16 val = (in_buf[0] >> 3) | ((in_buf[1] << 2) & 0x3e0)
|
||||||
|
| ((in_buf[2] << 7) & 0x7c00);
|
||||||
if (in_buf[3] > 127) {
|
if (in_buf[3] > 127) {
|
||||||
val = val | 0x8000;
|
val = val | 0x8000;
|
||||||
}
|
}
|
||||||
@@ -335,20 +346,21 @@ collapse_data(
|
|||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
if (in_buf[3] < 128) {
|
if (in_buf[3] < 128) {
|
||||||
out_buf[0] = B_TRANSPARENT_8_BIT;
|
out_buf[0] = B_TRANSPARENT_8_BIT;
|
||||||
}
|
} else {
|
||||||
else {
|
uint16 val = (in_buf[0] >> 3) | ((in_buf[1] << 2) & 0x3e0)
|
||||||
uint16 val = (in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00);
|
| ((in_buf[2] << 7) & 0x7c00);
|
||||||
out_buf[0] = map->index_map[val];
|
out_buf[0] = map->index_map[val];
|
||||||
}
|
}
|
||||||
out_buf += 1;
|
out_buf += 1;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
num_bytes -= 4;
|
num_bytes -= 4;
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case B_GRAY8:
|
case B_GRAY8:
|
||||||
while (num_bytes > 3) { /* There are better algorithms than Y = .25B+.50G+.25R */
|
while (num_bytes > 3) { /* There are better algorithms than Y =
|
||||||
/* but hardly faster -- and it's still better than (B+G+R)/3 ! */
|
.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[0] = (in_buf[0] + in_buf[1] * 2 + in_buf[2]) >> 2;
|
||||||
out_buf += 1;
|
out_buf += 1;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
@@ -366,7 +378,8 @@ collapse_data(
|
|||||||
cnt = 0;
|
cnt = 0;
|
||||||
ob = 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;
|
ob = ob | c;
|
||||||
cnt++;
|
cnt++;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
@@ -411,7 +424,8 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_RGB16_BIG:
|
case B_RGB16_BIG:
|
||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
uint16 val = (in_buf[0]>>3)|((in_buf[1]<<3)&0x7e0)|((in_buf[2]<<8)&0xf800);
|
uint16 val = (in_buf[0] >> 3) | ((in_buf[1] << 3) & 0x7e0)
|
||||||
|
| ((in_buf[2] << 8) & 0xf800);
|
||||||
out_buf[0] = val >> 8;
|
out_buf[0] = val >> 8;
|
||||||
out_buf[1] = val;
|
out_buf[1] = val;
|
||||||
out_buf += 2;
|
out_buf += 2;
|
||||||
@@ -421,7 +435,8 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_RGB15_BIG:
|
case B_RGB15_BIG:
|
||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
uint16 val = (in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00)|0x8000;
|
uint16 val = (in_buf[0] >> 3) | ((in_buf[1] << 2) & 0x3e0)
|
||||||
|
| ((in_buf[2] << 7) & 0x7c00) | 0x8000;
|
||||||
out_buf[0] = val >> 8;
|
out_buf[0] = val >> 8;
|
||||||
out_buf[1] = val;
|
out_buf[1] = val;
|
||||||
out_buf += 2;
|
out_buf += 2;
|
||||||
@@ -431,7 +446,8 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_RGBA15_BIG:
|
case B_RGBA15_BIG:
|
||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
uint16 val = (in_buf[0]>>3)|((in_buf[1]<<2)&0x3e0)|((in_buf[2]<<7)&0x7c00);
|
uint16 val = (in_buf[0] >> 3) | ((in_buf[1] << 2) & 0x3e0)
|
||||||
|
| ((in_buf[2] << 7) & 0x7c00);
|
||||||
if (in_buf[3] > 127) {
|
if (in_buf[3] > 127) {
|
||||||
val = val | 0x8000;
|
val = val | 0x8000;
|
||||||
}
|
}
|
||||||
@@ -497,9 +513,7 @@ collapse_data(
|
|||||||
|
|
||||||
#if DEBUG_DATA
|
#if DEBUG_DATA
|
||||||
static void
|
static void
|
||||||
print_data(
|
print_data(unsigned char* ptr, int n)
|
||||||
unsigned char * ptr,
|
|
||||||
int n)
|
|
||||||
{
|
{
|
||||||
while (n-- > 0) {
|
while (n-- > 0) {
|
||||||
printf("%02x ", *(ptr++));
|
printf("%02x ", *(ptr++));
|
||||||
@@ -510,19 +524,18 @@ print_data(
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
convert_space(
|
convert_space(color_space in_space, color_space out_space,
|
||||||
color_space in_space,
|
unsigned char* in_data, int rowbytes, unsigned char* out_data)
|
||||||
color_space out_space,
|
|
||||||
unsigned char * in_data,
|
|
||||||
int rowbytes,
|
|
||||||
unsigned char * out_data)
|
|
||||||
{
|
{
|
||||||
ASSERT(in_data != out_data);
|
ASSERT(in_data != out_data);
|
||||||
|
|
||||||
/* Instead of coding each transformation separately, which would create */
|
/* Instead of coding each transformation separately, which would create
|
||||||
/* a very large number of conversion functions, we write one function to */
|
*/
|
||||||
|
/* a very large number of conversion functions, we write one function to
|
||||||
|
*/
|
||||||
/* convert to RGBA32, and another function to convert from RGBA32, and */
|
/* 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. */
|
/* conversion speed. */
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
@@ -536,7 +549,8 @@ convert_space(
|
|||||||
memcpy(out_data, in_data, rowbytes);
|
memcpy(out_data, in_data, rowbytes);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
/* When the input format is RGBA32, we don't need the first conversion. */
|
/* When the input format is RGBA32, we don't need the first conversion.
|
||||||
|
*/
|
||||||
if (in_space == B_RGBA32) {
|
if (in_space == B_RGBA32) {
|
||||||
n = collapse_data(in_data, rowbytes, out_space, out_data);
|
n = collapse_data(in_data, rowbytes, out_space, out_data);
|
||||||
#if DEBUG_DATA
|
#if DEBUG_DATA
|
||||||
@@ -545,7 +559,8 @@ convert_space(
|
|||||||
#endif
|
#endif
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
/* When the output format is RGBA32, we don't need any second conversion. */
|
/* When the output format is RGBA32, we don't need any second conversion.
|
||||||
|
*/
|
||||||
if (out_space == B_RGB32 || out_space == B_RGBA32) {
|
if (out_space == B_RGB32 || out_space == B_RGBA32) {
|
||||||
n = expand_data(in_space, in_data, rowbytes, out_data);
|
n = expand_data(in_space, in_data, rowbytes, out_data);
|
||||||
#if DEBUG_DATA
|
#if DEBUG_DATA
|
||||||
@@ -579,13 +594,12 @@ convert_space(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Figure out what the rowbytes is for a given width in a given color space.
|
||||||
/* Figure out what the rowbytes is for a given width in a given color space. */
|
*/
|
||||||
/* Rowbytes is bytes per pixel times width, rounded up to nearest multiple of 4. */
|
/* Rowbytes is bytes per pixel times width, rounded up to nearest multiple
|
||||||
|
* of 4. */
|
||||||
int
|
int
|
||||||
calc_rowbytes(
|
calc_rowbytes(color_space space, int width)
|
||||||
color_space space,
|
|
||||||
int width)
|
|
||||||
{
|
{
|
||||||
int v = width * 4;
|
int v = width * 4;
|
||||||
switch (space) {
|
switch (space) {
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ status_t convert_space(color_space in_space, color_space out_space,
|
|||||||
|
|
||||||
/* This function expands rowbytes amount of data from in_data into */
|
/* This function expands rowbytes amount of data from in_data into */
|
||||||
/* RGBA32 data in out_buf, which must be big enough. */
|
/* RGBA32 data in out_buf, which must be big enough. */
|
||||||
int expand_data(color_space from_space, unsigned char * in_data,
|
int expand_data(color_space from_space, unsigned char* in_data, int rowbytes,
|
||||||
int rowbytes, unsigned char * out_buf);
|
unsigned char* out_buf);
|
||||||
|
|
||||||
/* This function converts num_bytes bytes of RGBA32 data into some new */
|
/* This function converts num_bytes bytes of RGBA32 data into some new */
|
||||||
/* color space in out_buf, where out_buf must be big enough. */
|
/* color space in out_buf, where out_buf must be big enough. */
|
||||||
int collapse_data(unsigned char * in_buf, int num_bytes,
|
int collapse_data(unsigned char* in_buf, int num_bytes, color_space out_space,
|
||||||
color_space out_space, unsigned char * out_buf);
|
unsigned char* out_buf);
|
||||||
|
|
||||||
/* Given a specific number of pixels in width in the color space space */
|
/* Given a specific number of pixels in width in the color space space */
|
||||||
/* this function calculates what the row_bytes should be. */
|
/* this function calculates what the row_bytes should be. */
|
||||||
|
|||||||
Reference in New Issue
Block a user