(writeHex): When given several bytes, don't write the first one many times.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@18024 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-11-02 02:11:33 +00:00
parent baa14f193b
commit dbe4650406
2 changed files with 25 additions and 17 deletions

View file

@ -1,3 +1,11 @@
2003-11-02 02:58 Alexander Malmberg <alexander@malmberg.org>
* Source/gsc/GSStreamContext.m Whitespace cleanups.
(writeHex): Use index properly; don't always write the first byte.
Use fputc() instead of fprintf() (was doing the hex conversion
manually anyway, might as well make it efficient).
2003-11-02 02:27 Alexander Malmberg <alexander@malmberg.org> 2003-11-02 02:27 Alexander Malmberg <alexander@malmberg.org>
* Source/gsc/GSStreamContext.m (fpfloat, writeHex): Make static. * Source/gsc/GSStreamContext.m (fpfloat, writeHex): Make static.

View file

@ -278,7 +278,7 @@ fpfloat(FILE *stream, float f)
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
{ {
fprintf(gstream, "/%s glyphshow\n",[font nameOfGlyph: glyphs[i]]); fprintf(gstream, "/%s glyphshow\n", [font nameOfGlyph: glyphs[i]]);
} }
} }
else else
@ -286,7 +286,7 @@ fpfloat(FILE *stream, float f)
/* If backend doesn't handle nameOfGlyph, assume the glyphs are /* If backend doesn't handle nameOfGlyph, assume the glyphs are
just mapped to characters. This is the case for the xlib backend just mapped to characters. This is the case for the xlib backend
(at least for now). */ (at least for now). */
char string[length+1]; char string[length + 1];
unsigned int i; unsigned int i;
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
@ -683,10 +683,10 @@ fpfloat(FILE *stream, float f)
[self DPSsetdash: pattern : count : phase]; [self DPSsetdash: pattern : count : phase];
count = [path elementCount]; count = [path elementCount];
for(i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
type = [path elementAtIndex: i associatedPoints: pts]; type = [path elementAtIndex: i associatedPoints: pts];
switch(type) switch (type)
{ {
case NSMoveToBezierPathElement: case NSMoveToBezierPathElement:
[self DPSmoveto: pts[0].x : pts[0].y]; [self DPSmoveto: pts[0].x : pts[0].y];
@ -795,16 +795,16 @@ fpfloat(FILE *stream, float f)
@end @end
static char *hexdigits = "0123456789abcdef";
static void static void
writeHex(FILE *gstream, const unsigned char *data, int count) writeHex(FILE *gstream, const unsigned char *data, int count)
{ {
static const char *hexdigits = "0123456789abcdef";
int i; int i;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
fprintf(gstream, "%c%c", hexdigits[(int)(data[0]/16)], fputc(hexdigits[(int)(data[i] / 16)], gstream);
hexdigits[(data[0] % 16)]); fputc(hexdigits[(int)(data[i] % 16)], gstream);
if (i && i % 40 == 0) if (i && i % 40 == 0)
fprintf(gstream, "\n"); fprintf(gstream, "\n");
} }
@ -869,7 +869,7 @@ writeHex(FILE *gstream, const unsigned char *data, int count)
pixelsWide, pixelsHigh, bitsPerSample, pixelsWide, pixelsWide, pixelsHigh, bitsPerSample, pixelsWide,
(flipped) ? pixelsHigh : -pixelsHigh, pixelsHigh); (flipped) ? pixelsHigh : -pixelsHigh, pixelsHigh);
fprintf(gstream, "{currentfile %d string readhexstring pop}\n", fprintf(gstream, "{currentfile %d string readhexstring pop}\n",
pixelsWide*spp); pixelsWide * spp);
fprintf(gstream, "false %d colorimage\n", spp); fprintf(gstream, "false %d colorimage\n", spp);
} }
else else
@ -891,23 +891,23 @@ writeHex(FILE *gstream, const unsigned char *data, int count)
int alpha = 0; int alpha = 0;
unsigned char val; unsigned char val;
for(j=0; j<bytes; j++) for (j = 0; j < bytes; j++)
{ {
if(hasAlpha) if (hasAlpha)
{ {
if(isPlanar) if (isPlanar)
alpha = data[spp][j]; alpha = data[spp][j];
else else
alpha = data[0][spp+j*samplesPerPixel]; alpha = data[0][spp + j * samplesPerPixel];
} }
for (i = 0; i < spp; i++) for (i = 0; i < spp; i++)
{ {
if(isPlanar) if (isPlanar)
val = data[i][j]; val = data[i][j];
else else
val = data[0][i+j*samplesPerPixel]; val = data[0][i + j * samplesPerPixel];
if(hasAlpha) if (hasAlpha)
val = 255 - ((255-val)*(long)alpha)/255; val = 255 - ((255 - val) * (long)alpha) / 255;
writeHex(gstream, &val, 1); writeHex(gstream, &val, 1);
} }
if (j && j % 40 == 0) if (j && j % 40 == 0)
@ -918,7 +918,7 @@ writeHex(FILE *gstream, const unsigned char *data, int count)
else else
{ {
// The data is already in the format the context expects it in // The data is already in the format the context expects it in
writeHex(gstream, data[0], bytes*samplesPerPixel); writeHex(gstream, data[0], bytes * samplesPerPixel);
} }
/* Restore original scaling */ /* Restore original scaling */