Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
5bc8ee95
Commit
5bc8ee95
authored
28 years ago
by
Per Hedbor
Browse files
Options
Downloads
Patches
Plain Diff
Added 8bit colorcube random dither stuff.
Rev: src/modules/Image/x.c:1.2
parent
716f595c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/modules/Image/x.c
+83
-2
83 additions, 2 deletions
src/modules/Image/x.c
with
83 additions
and
2 deletions
src/modules/Image/x.c
+
83
−
2
View file @
5bc8ee95
/* $Id: x.c,v 1.
1
1997/03/2
0 07:56:26 mira
r Exp $ */
/* $Id: x.c,v 1.
2
1997/03/2
1 16:56:40 pe
r Exp $ */
#include
"global.h"
...
...
@@ -7,7 +7,7 @@
#include
"stralloc.h"
#include
"global.h"
RCSID
(
"$Id: x.c,v 1.
1
1997/03/2
0 07:56:26 mira
r Exp $"
);
RCSID
(
"$Id: x.c,v 1.
2
1997/03/2
1 16:56:40 pe
r Exp $"
);
#include
"types.h"
#include
"pike_macros.h"
#include
"object.h"
...
...
@@ -17,6 +17,7 @@ RCSID("$Id: x.c,v 1.1 1997/03/20 07:56:26 mirar Exp $");
#include
"threads.h"
#include
"array.h"
#include
"error.h"
#include
"port.h"
#include
"image.h"
#include
"builtin_functions.h"
...
...
@@ -269,4 +270,84 @@ void image_to8bit_rgbcube(INT32 args)
push_string
(
end_shared_string
(
res
));
}
void
image_to8bit_rgbcube_rdither
(
INT32
args
)
/*
->to8bit_rgbcube_rdither(int red,int green,int blue,
[string map])
gives r+red*g+red*green*b
*/
{
struct
colortable
*
ct
;
struct
pike_string
*
res
=
begin_shared_string
((
THIS
->
xsize
*
THIS
->
ysize
));
unsigned
long
i
;
rgb_group
*
s
;
unsigned
char
*
d
;
unsigned
char
*
map
=
NULL
;
int
red
,
green
,
blue
,
redgreen
,
redgreenblue
,
rmax
,
gmax
,
bmax
;
if
(
!
res
)
error
(
"Out of memory
\n
"
);
if
(
!
THIS
->
img
)
error
(
"No image
\n
"
);
if
(
args
<
3
)
error
(
"Too few arguments to image->to8bit_rgbcube()
\n
"
);
if
(
sp
[
-
args
].
type
!=
T_INT
||
sp
[
1
-
args
].
type
!=
T_INT
||
sp
[
2
-
args
].
type
!=
T_INT
)
error
(
"Illegal argument(s) to image->to8bit_rgbcube()
\n
"
);
red
=
sp
[
-
args
].
u
.
integer
;
rmax
=
red
*
255
;
green
=
sp
[
1
-
args
].
u
.
integer
;
gmax
=
green
*
255
;
blue
=
sp
[
2
-
args
].
u
.
integer
;
bmax
=
blue
*
255
;
redgreen
=
red
*
green
;
redgreenblue
=
red
*
green
*
blue
;
if
(
args
>
3
)
if
(
sp
[
3
-
args
].
type
!=
T_STRING
)
error
(
"Illegal argument 4 to image->to8bit_rgbcube()"
" (expected string or no argument)
\n
"
);
else
if
(
sp
[
3
-
args
].
u
.
string
->
len
<
red
*
green
*
blue
)
error
(
"map string is not long enough to image->to8bit_rgbcube()
\n
"
);
else
map
=
sp
[
3
-
args
].
u
.
string
->
str
;
i
=
THIS
->
xsize
*
THIS
->
ysize
;
s
=
THIS
->
img
;
d
=
res
->
str
;
THREADS_ALLOW
();
if
(
!
map
)
while
(
i
--
)
{
unsigned
int
tal
=
my_rand
();
int
r
=
(
s
->
r
*
red
)
+
(
tal
&
255
);
int
g
=
(
s
->
g
*
green
)
+
((
tal
>>
8
)
&
255
);
int
b
=
(
s
->
b
*
blue
+
((
tal
>>
16
)
&
255
));
if
(
r
>
rmax
)
r
=
rmax
;
if
(
g
>
gmax
)
g
=
gmax
;
if
(
b
>
bmax
)
b
=
bmax
;
*
(
d
++
)
=
(
unsigned
char
)((
r
>>
8
)
+
(
g
>>
8
)
*
red
+
(
b
>>
8
)
*
redgreen
);
s
++
;
}
else
while
(
i
--
)
{
unsigned
int
tal
=
my_rand
();
int
r
=
(
s
->
r
*
red
)
+
(
tal
&
255
);
int
g
=
(
s
->
g
*
green
)
+
((
tal
>>
8
)
&
255
);
int
b
=
(
s
->
b
*
blue
+
((
tal
>>
16
)
&
255
));
if
(
r
>
rmax
)
r
=
rmax
;
if
(
g
>
gmax
)
g
=
gmax
;
if
(
b
>
bmax
)
b
=
bmax
;
*
(
d
++
)
=
map
[
(
r
>>
8
)
+
(
g
>>
8
)
*
red
+
(
b
>>
8
)
*
redgreen
];
s
++
;
}
THREADS_DISALLOW
();
pop_n_elems
(
args
);
push_string
(
end_shared_string
(
res
));
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment