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,19 +22,18 @@
|
|||||||
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);
|
||||||
}
|
}
|
||||||
~PPMWindow()
|
~PPMWindow()
|
||||||
{
|
{
|
||||||
BPoint pt(0,0);
|
BPoint pt(0, 0);
|
||||||
ConvertToScreen(&pt);
|
ConvertToScreen(&pt);
|
||||||
set_window_origin(pt);
|
set_window_origin(pt);
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
@@ -45,35 +44,39 @@ int
|
|||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
BApplication app("application/x-vnd.Haiku-PPMTranslator");
|
BApplication app("application/x-vnd.Haiku-PPMTranslator");
|
||||||
BView * v = NULL;
|
BView* v = NULL;
|
||||||
BRect r(0, 0, 1, 1);
|
BRect r(0, 0, 1, 1);
|
||||||
if (MakeConfig(NULL, &v, &r)) {
|
if (MakeConfig(NULL, &v, &r)) {
|
||||||
BAlert * err = new BAlert("Error",
|
BAlert* err = new BAlert("Error",
|
||||||
B_TRANSLATE("Something is wrong with the PPMTranslator!"),
|
B_TRANSLATE("Something is wrong with the PPMTranslator!"),
|
||||||
B_TRANSLATE("OK"));
|
B_TRANSLATE("OK"));
|
||||||
err->SetFlags(err->Flags() | B_CLOSE_ON_ESCAPE);
|
err->SetFlags(err->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
err->Go();
|
err->Go();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
PPMWindow *w = new PPMWindow(r);
|
PPMWindow* w = new PPMWindow(r);
|
||||||
v->ResizeTo(r.Width(), r.Height());
|
v->ResizeTo(r.Width(), r.Height());
|
||||||
w->AddChild(v);
|
w->AddChild(v);
|
||||||
BPoint o = get_window_origin();
|
BPoint o = get_window_origin();
|
||||||
{
|
{
|
||||||
BScreen scrn;
|
BScreen scrn;
|
||||||
BRect f = scrn.Frame();
|
BRect f = scrn.Frame();
|
||||||
f.InsetBy(10,23);
|
f.InsetBy(10, 23);
|
||||||
/* if not in a good place, start where the cursor is */
|
/* if not in a good place, start where the cursor is */
|
||||||
if (!f.Contains(o)) {
|
if (!f.Contains(o)) {
|
||||||
uint32 i;
|
uint32 i;
|
||||||
v->GetMouse(&o, &i, false);
|
v->GetMouse(&o, &i, false);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -5,36 +5,43 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
unsigned char * in_out = out_buf;
|
* when going 15->24 */
|
||||||
|
unsigned char* in_out = out_buf;
|
||||||
switch (from_space) {
|
switch (from_space) {
|
||||||
case B_RGB32:
|
case B_RGB32:
|
||||||
while (rowbytes > 3) {
|
while (rowbytes > 3) {
|
||||||
@@ -63,10 +70,10 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
break;
|
break;
|
||||||
case B_RGB15:
|
case B_RGB15:
|
||||||
while (rowbytes > 1) {
|
while (rowbytes > 1) {
|
||||||
uint16 val = in_data[0]+(in_data[1]<<8);
|
uint16 val = in_data[0] + (in_data[1] << 8);
|
||||||
out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
|
out_buf[0] = ((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
||||||
out_buf[1] = ((val&0x3e0)>>2)|((val&0x3e0)>>7);
|
out_buf[1] = ((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
||||||
out_buf[2] = ((val&0x7c00)>>7)|((val&0x7c00)>>12);
|
out_buf[2] = ((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
||||||
out_buf[3] = 255;
|
out_buf[3] = 255;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_data += 2;
|
in_data += 2;
|
||||||
@@ -75,11 +82,11 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
break;
|
break;
|
||||||
case B_RGBA15:
|
case B_RGBA15:
|
||||||
while (rowbytes > 1) {
|
while (rowbytes > 1) {
|
||||||
uint16 val = in_data[0]+(in_data[1]<<8);
|
uint16 val = in_data[0] + (in_data[1] << 8);
|
||||||
out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
|
out_buf[0] = ((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
||||||
out_buf[1] = ((val&0x3e0)>>2)|((val&0x3e0)>>7);
|
out_buf[1] = ((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
||||||
out_buf[2] = ((val&0x7c00)>>7)|((val&0x7c00)>>12);
|
out_buf[2] = ((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
||||||
out_buf[3] = (val&0x8000) ? 255 : 0;
|
out_buf[3] = (val & 0x8000) ? 255 : 0;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_data += 2;
|
in_data += 2;
|
||||||
rowbytes -= 2;
|
rowbytes -= 2;
|
||||||
@@ -87,10 +94,10 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
break;
|
break;
|
||||||
case B_RGB16:
|
case B_RGB16:
|
||||||
while (rowbytes > 1) {
|
while (rowbytes > 1) {
|
||||||
uint16 val = in_data[0]+(in_data[1]<<8);
|
uint16 val = in_data[0] + (in_data[1] << 8);
|
||||||
out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
|
out_buf[0] = ((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
||||||
out_buf[1] = ((val&0x7e0)>>3)|((val&0x7e0)>>9);
|
out_buf[1] = ((val & 0x7e0) >> 3) | ((val & 0x7e0) >> 9);
|
||||||
out_buf[2] = ((val&0xf800)>>8)|((val&0xf800)>>13);
|
out_buf[2] = ((val & 0xf800) >> 8) | ((val & 0xf800) >> 13);
|
||||||
out_buf[3] = 255;
|
out_buf[3] = 255;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_data += 2;
|
in_data += 2;
|
||||||
@@ -132,10 +139,10 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
break;
|
break;
|
||||||
case B_RGB15_BIG:
|
case B_RGB15_BIG:
|
||||||
while (rowbytes > 1) {
|
while (rowbytes > 1) {
|
||||||
uint16 val = in_data[1]+(in_data[0]<<8);
|
uint16 val = in_data[1] + (in_data[0] << 8);
|
||||||
out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
|
out_buf[0] = ((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
||||||
out_buf[1] = ((val&0x3e0)>>2)|((val&0x3e0)>>7);
|
out_buf[1] = ((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
||||||
out_buf[2] = ((val&0x7c00)>>7)|((val&0x7c00)>>12);
|
out_buf[2] = ((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
||||||
out_buf[3] = 255;
|
out_buf[3] = 255;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_data += 2;
|
in_data += 2;
|
||||||
@@ -144,11 +151,11 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
break;
|
break;
|
||||||
case B_RGBA15_BIG:
|
case B_RGBA15_BIG:
|
||||||
while (rowbytes > 1) {
|
while (rowbytes > 1) {
|
||||||
uint16 val = in_data[1]+(in_data[0]<<8);
|
uint16 val = in_data[1] + (in_data[0] << 8);
|
||||||
out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
|
out_buf[0] = ((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
||||||
out_buf[1] = ((val&0x3e0)>>2)|((val&0x3e0)>>7);
|
out_buf[1] = ((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);
|
||||||
out_buf[2] = ((val&0x7c00)>>7)|((val&0x7c00)>>12);
|
out_buf[2] = ((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);
|
||||||
out_buf[3] = (val&0x8000) ? 255 : 0;
|
out_buf[3] = (val & 0x8000) ? 255 : 0;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_data += 2;
|
in_data += 2;
|
||||||
rowbytes -= 2;
|
rowbytes -= 2;
|
||||||
@@ -156,10 +163,10 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
break;
|
break;
|
||||||
case B_RGB16_BIG:
|
case B_RGB16_BIG:
|
||||||
while (rowbytes > 1) {
|
while (rowbytes > 1) {
|
||||||
uint16 val = in_data[1]+(in_data[0]<<8);
|
uint16 val = in_data[1] + (in_data[0] << 8);
|
||||||
out_buf[0] = ((val&0x1f)<<3)|((val&0x1f)>>2);
|
out_buf[0] = ((val & 0x1f) << 3) | ((val & 0x1f) >> 2);
|
||||||
out_buf[1] = ((val&0x7e0)>>3)|((val&0x7e0)>>9);
|
out_buf[1] = ((val & 0x7e0) >> 3) | ((val & 0x7e0) >> 9);
|
||||||
out_buf[2] = ((val&0xf800)>>8)|((val&0xf800)>>13);
|
out_buf[2] = ((val & 0xf800) >> 8) | ((val & 0xf800) >> 13);
|
||||||
out_buf[3] = 255;
|
out_buf[3] = 255;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_data += 2;
|
in_data += 2;
|
||||||
@@ -167,7 +174,7 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case B_CMAP8: {
|
case B_CMAP8: {
|
||||||
const color_map * map = system_colors();
|
const color_map* map = system_colors();
|
||||||
while (rowbytes > 0) {
|
while (rowbytes > 0) {
|
||||||
rgb_color c = map->color_list[in_data[0]];
|
rgb_color c = map->color_list[in_data[0]];
|
||||||
out_buf[0] = c.blue;
|
out_buf[0] = c.blue;
|
||||||
@@ -194,12 +201,11 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
case B_GRAY1:
|
case B_GRAY1:
|
||||||
while (rowbytes > 0) { /* expansion 1->32 is pretty good :-) */
|
while (rowbytes > 0) { /* expansion 1->32 is pretty good :-) */
|
||||||
unsigned char c1 = *in_data;
|
unsigned char c1 = *in_data;
|
||||||
for (int b = 128; b; b = b>>1) {
|
for (int b = 128; b; b = b >> 1) {
|
||||||
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,11 +218,12 @@ 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];
|
||||||
out_buf[2] = 255-in_data[0];
|
out_buf[2] = 255 - in_data[0];
|
||||||
out_buf[3] = 255;
|
out_buf[3] = 255;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_data += 3;
|
in_data += 3;
|
||||||
@@ -225,9 +232,9 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
break;
|
break;
|
||||||
case B_CMY32:
|
case B_CMY32:
|
||||||
while (rowbytes > 3) {
|
while (rowbytes > 3) {
|
||||||
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];
|
||||||
out_buf[2] = 255-in_data[0];
|
out_buf[2] = 255 - in_data[0];
|
||||||
out_buf[3] = 255;
|
out_buf[3] = 255;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_data += 4;
|
in_data += 4;
|
||||||
@@ -236,22 +243,23 @@ expand_data( /* expands to BGRA in the output buffer from <whatever> in the inpu
|
|||||||
break;
|
break;
|
||||||
case B_CMYA32:
|
case B_CMYA32:
|
||||||
while (rowbytes > 3) {
|
while (rowbytes > 3) {
|
||||||
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];
|
||||||
out_buf[2] = 255-in_data[0];
|
out_buf[2] = 255 - in_data[0];
|
||||||
out_buf[3] = in_data[3];
|
out_buf[3] = in_data[3];
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_data += 4;
|
in_data += 4;
|
||||||
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;
|
||||||
comp = 255-in_data[1]-in_data[3];
|
comp = 255 - in_data[1] - in_data[3];
|
||||||
out_buf[1] = comp < 0 ? 0 : comp;
|
out_buf[1] = comp < 0 ? 0 : comp;
|
||||||
comp = 255-in_data[0]-in_data[3];
|
comp = 255 - in_data[0] - in_data[3];
|
||||||
out_buf[2] = comp < 0 ? 0 : comp;
|
out_buf[2] = comp < 0 ? 0 : comp;
|
||||||
out_buf[3] = 255;
|
out_buf[3] = 255;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
@@ -267,20 +275,20 @@ 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,
|
unsigned char* out_buf)
|
||||||
int num_bytes,
|
|
||||||
color_space out_space,
|
|
||||||
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:
|
||||||
memcpy(out_buf, in_buf, num_bytes);
|
memcpy(out_buf, in_buf, num_bytes);
|
||||||
break;
|
break;
|
||||||
@@ -299,9 +307,10 @@ 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;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
num_bytes -= 4;
|
num_bytes -= 4;
|
||||||
@@ -309,9 +318,10 @@ 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;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
num_bytes -= 4;
|
num_bytes -= 4;
|
||||||
@@ -319,37 +329,39 @@ 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;
|
||||||
}
|
}
|
||||||
out_buf[0] = val;
|
out_buf[0] = val;
|
||||||
out_buf[1] = val>>8;
|
out_buf[1] = val >> 8;
|
||||||
out_buf += 2;
|
out_buf += 2;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
num_bytes -= 4;
|
num_bytes -= 4;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case B_CMAP8: {
|
case B_CMAP8: {
|
||||||
const color_map * map = system_colors();
|
const color_map* map = system_colors();
|
||||||
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 */
|
||||||
out_buf[0] = (in_buf[0]+in_buf[1]*2+in_buf[2])>>2;
|
/* 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;
|
out_buf += 1;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
num_bytes -= 4;
|
num_bytes -= 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,8 +424,9 @@ 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)
|
||||||
out_buf[0] = val>>8;
|
| ((in_buf[2] << 8) & 0xf800);
|
||||||
|
out_buf[0] = val >> 8;
|
||||||
out_buf[1] = val;
|
out_buf[1] = val;
|
||||||
out_buf += 2;
|
out_buf += 2;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
@@ -421,8 +435,9 @@ 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)
|
||||||
out_buf[0] = val>>8;
|
| ((in_buf[2] << 7) & 0x7c00) | 0x8000;
|
||||||
|
out_buf[0] = val >> 8;
|
||||||
out_buf[1] = val;
|
out_buf[1] = val;
|
||||||
out_buf += 2;
|
out_buf += 2;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
@@ -431,11 +446,12 @@ 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;
|
||||||
}
|
}
|
||||||
out_buf[0] = val>>8;
|
out_buf[0] = val >> 8;
|
||||||
out_buf[1] = val;
|
out_buf[1] = val;
|
||||||
out_buf += 2;
|
out_buf += 2;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
@@ -444,9 +460,9 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_CMY24:
|
case B_CMY24:
|
||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
out_buf[0] = 255-in_buf[2];
|
out_buf[0] = 255 - in_buf[2];
|
||||||
out_buf[1] = 255-in_buf[1];
|
out_buf[1] = 255 - in_buf[1];
|
||||||
out_buf[2] = 255-in_buf[0];
|
out_buf[2] = 255 - in_buf[0];
|
||||||
out_buf += 3;
|
out_buf += 3;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
num_bytes -= 4;
|
num_bytes -= 4;
|
||||||
@@ -454,9 +470,9 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_CMY32:
|
case B_CMY32:
|
||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
out_buf[0] = 255-in_buf[2];
|
out_buf[0] = 255 - in_buf[2];
|
||||||
out_buf[1] = 255-in_buf[1];
|
out_buf[1] = 255 - in_buf[1];
|
||||||
out_buf[2] = 255-in_buf[0];
|
out_buf[2] = 255 - in_buf[0];
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
num_bytes -= 4;
|
num_bytes -= 4;
|
||||||
@@ -464,9 +480,9 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_CMYA32:
|
case B_CMYA32:
|
||||||
while (num_bytes > 3) {
|
while (num_bytes > 3) {
|
||||||
out_buf[0] = 255-in_buf[2];
|
out_buf[0] = 255 - in_buf[2];
|
||||||
out_buf[1] = 255-in_buf[1];
|
out_buf[1] = 255 - in_buf[1];
|
||||||
out_buf[2] = 255-in_buf[0];
|
out_buf[2] = 255 - in_buf[0];
|
||||||
out_buf[3] = in_buf[3];
|
out_buf[3] = in_buf[3];
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
@@ -475,13 +491,13 @@ collapse_data(
|
|||||||
break;
|
break;
|
||||||
case B_CMYK32:
|
case B_CMYK32:
|
||||||
while (num_bytes > 3) { /* We do direct gray removal */
|
while (num_bytes > 3) { /* We do direct gray removal */
|
||||||
int c = 255-in_buf[2];
|
int c = 255 - in_buf[2];
|
||||||
int m = 255-in_buf[1];
|
int m = 255 - in_buf[1];
|
||||||
int y = 255-in_buf[0];
|
int y = 255 - in_buf[0];
|
||||||
int k = (c>m)?((y>c)?y:c):((y>m)?y:m);
|
int k = (c > m) ? ((y > c) ? y : c) : ((y > m) ? y : m);
|
||||||
out_buf[0] = c-k;
|
out_buf[0] = c - k;
|
||||||
out_buf[1] = m-k;
|
out_buf[1] = m - k;
|
||||||
out_buf[2] = y-k;
|
out_buf[2] = y - k;
|
||||||
out_buf[3] = k;
|
out_buf[3] = k;
|
||||||
out_buf += 4;
|
out_buf += 4;
|
||||||
in_buf += 4;
|
in_buf += 4;
|
||||||
@@ -491,15 +507,13 @@ collapse_data(
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return out_buf-in_out;
|
return out_buf - in_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#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
|
||||||
@@ -559,7 +574,7 @@ convert_space(
|
|||||||
if (in_space == B_GRAY1) {
|
if (in_space == B_GRAY1) {
|
||||||
mul = 32;
|
mul = 32;
|
||||||
}
|
}
|
||||||
unsigned char * buf = (unsigned char *)malloc(rowbytes*mul);
|
unsigned char* buf = (unsigned char*) malloc(rowbytes * mul);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
/* oops! */
|
/* oops! */
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@@ -579,15 +594,14 @@ 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) {
|
||||||
default:
|
default:
|
||||||
/* 4 is fine */
|
/* 4 is fine */
|
||||||
@@ -595,7 +609,7 @@ calc_rowbytes(
|
|||||||
case B_RGB24:
|
case B_RGB24:
|
||||||
case B_CMY24:
|
case B_CMY24:
|
||||||
case B_RGB24_BIG:
|
case B_RGB24_BIG:
|
||||||
v = width*3;
|
v = width * 3;
|
||||||
break;
|
break;
|
||||||
case B_RGB15:
|
case B_RGB15:
|
||||||
case B_RGBA15:
|
case B_RGBA15:
|
||||||
@@ -603,16 +617,16 @@ calc_rowbytes(
|
|||||||
case B_RGB15_BIG:
|
case B_RGB15_BIG:
|
||||||
case B_RGBA15_BIG:
|
case B_RGBA15_BIG:
|
||||||
case B_RGB16_BIG:
|
case B_RGB16_BIG:
|
||||||
v = width*2;
|
v = width * 2;
|
||||||
break;
|
break;
|
||||||
case B_CMAP8:
|
case B_CMAP8:
|
||||||
case B_GRAY8:
|
case B_GRAY8:
|
||||||
v = width;
|
v = width;
|
||||||
break;
|
break;
|
||||||
case B_GRAY1:
|
case B_GRAY1:
|
||||||
v = (width+7)/8; /* whole bytes only, please */
|
v = (width + 7) / 8; /* whole bytes only, please */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
v = (v+3)&~3;
|
v = (v + 3) & ~3;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,17 +13,17 @@
|
|||||||
/* out_data, with enough memory assumed to be in out_data for the */
|
/* out_data, with enough memory assumed to be in out_data for the */
|
||||||
/* converted data. */
|
/* converted data. */
|
||||||
status_t convert_space(color_space in_space, color_space out_space,
|
status_t convert_space(color_space in_space, color_space out_space,
|
||||||
unsigned char * in_data, int rowbytes, unsigned char * out_data);
|
unsigned char* in_data, int rowbytes, unsigned char* out_data);
|
||||||
|
|
||||||
/* 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