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
ad35addc
Commit
ad35addc
authored
26 years ago
by
Per Hedbor
Browse files
Options
Downloads
Patches
Plain Diff
Added encode
Rev: lib/modules/_Image_XPM.pmod:1.7
parent
0c1d579d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/_Image_XPM.pmod
+107
-8
107 additions, 8 deletions
lib/modules/_Image_XPM.pmod
with
107 additions
and
8 deletions
lib/modules/_Image_XPM.pmod
+
107
−
8
View file @
ad35addc
inherit Image._XPM;
inherit Image._XPM;
#if 0
#if 0
#define TE( X ) w
rite
("XPM profile: %-20s ... ", (X));
#
define TE( X ) w
error
("XPM profile: %-20s ... ", (X));
int old_time,start_time;
int old_time,start_time;
#define TI(X) start_time=old_time=gethrtime();TE(X)
#
define TI(X) start_time=old_time=gethrtime();TE(X)
#define TD( X ) do{\
#
define TD( X ) do{\
w
rite
("%3.02f (%3.02f)\n", (gethrtime()-old_time)/1000000.0,(gethrtime()-start_time)/1000000.0);\
w
error
("%3.02f (%3.02f)\n", (gethrtime()-old_time)/1000000.0,(gethrtime()-start_time)/1000000.0);\
TE(X); \
TE(X); \
old_time = gethrtime(); \
old_time = gethrtime(); \
} while(0);
} while(0);
#else
#else
#define TI(X)
#
define TI(X)
#define TD(X)
#
define TD(X)
#define TE(X)
#
define TE(X)
#endif
#endif
mapping _decode( string what, void|mapping opts )
mapping _decode( string what, void|mapping opts )
{
{
array e;
array e;
...
@@ -85,6 +84,106 @@ mapping _decode( string what, void|mapping opts )
...
@@ -85,6 +84,106 @@ mapping _decode( string what, void|mapping opts )
return retopts;
return retopts;
}
}
array ok = ({
"`", ".", "+", "@", "#", "$", "%", "*", "=", "-", ";", ">", ",",
"'", ")", "!", "~", "{", "]", "^", "/", "(", "_", ":", "<", "[",
"}", "|", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a",
"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A",
"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", " ",
});
array cmap_f, cmap_t;
string encode( object what, mapping|void options )
{
int x,y, q;
TI("Encode init");
if(!options) options = ([]);
if(!cmap_f)
{
cmap_f = allocate( 8100 );
cmap_t = allocate( 8100 );
for(x=0; x<90; x++)
for(y=0; y<90; y++)
cmap_t[q++] = ok[x]+ok[y];
}
TD("Encode CT");
if(!options->colortable)
{
options->colortable = Image.colortable( what, 8089 );
options->colortable->rigid( 25, 25, 25 );
options->colortable->floyd_steinberg();
}
if(!options->name)
options->name = "image";
int alpha_used;
TD("Encode map");
array rows=options->colortable->index(what)/what->xsize();
TD("Encode colors");
int ncolors;
array colors = ({});
int n;
foreach(((string)options->colortable)/3, mixed c)
{
colors += ({sprintf("%s c #%02x%02x%02x",cmap_t[n++],c[0],c[1],c[2])});
ncolors++;
}
TD("Encode alpha");
if(options->alpha)
{
object ac = Image.colortable( ({ Image.color.white, Image.color.black }) );
array q = ac->index( options->alpha )/what->xsize();
string alpha_color = " ";
string minus_ett = " ";
alpha_color[0] = ncolors;
minus_ett[0] = -1;
for(y=0; y<sizeof(q); y++)
rows[y]=replace(rows[y]|replace(q[y],"\1",minus_ett),minus_ett,alpha_color );
}
if(alpha_used)
{
colors += ({cmap_t[ncolors]+" c None"});
ncolors++;
}
TD("Encode color output");
string res =
"/* XPM */\n"+
(options->comment?
"/* "+replace(options->comment, ({"/*", "*/"}), ({"/", "/"}))+" */\n":"")+
"static char* "+options->name+" = {\n"
"\""+what->xsize()+" "+what->ysize()+" "+ncolors+" 2\",\n";
foreach(colors, string c)
res += "\""+c+"\",\n";
TD(sprintf("Encode %d rows", sizeof(rows)));
int q = sizeof(rows);
foreach(rows, string row)
{
string r = "";
int i;
r += "\"";
for(i=0; i<strlen(row); i++)
r += cmap_t[row[i]];
res += r+"\",\n";
}
TD(sprintf("Encoded %d rows", sizeof(rows)));
// foreach(rows, string row)
// res += "\""+replace( row, cmap_f, cmap_t )+"\",\n";
res = res+"};\n";
TE("Done");
return res;
}
object decode( string what )
object decode( string what )
{
{
return _decode(what)->image;
return _decode(what)->image;
...
...
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