[hackers] [PATCH] yellow italics everywhere is for colorblind people

2016-01-04 Thread Ivan Tham
Thanks to voidead: god of destroying faggot asscunts
---
 config.def.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.def.h b/config.def.h
index fd09d72..1024766 100644
--- a/config.def.h
+++ b/config.def.h
@@ -127,7 +127,7 @@ static unsigned int mousebg = 0;
  * will reverse too. Another logic would only make the simple feature too
  * complex.
  */
-static unsigned int defaultitalic = 11;
+static unsigned int defaultitalic = 15;
 static unsigned int defaultunderline = 7;
 
 /*
-- 
2.6.4




[hackers] [farbfeld] Fix bugs in farbfeld(5)-example || FRIGN

2016-01-04 Thread git
commit ac1630a81790f5db946d7091e08b758714c8cd19
Author: FRIGN 
AuthorDate: Tue Jan 5 01:39:10 2016 +0100
Commit: FRIGN 
CommitDate: Tue Jan 5 01:39:10 2016 +0100

Fix bugs in farbfeld(5)-example

1) We forgot to write the header out again (no changes, but else the
   format would have obviously been broken)
2) The order of 'size' and 'count' was wrong in the fread- and fwrite-
   calls inside the loops, and the checks were failing.
   now this is fixed.

diff --git a/farbfeld.5 b/farbfeld.5
index 8c8ec31..74bd02c 100644
--- a/farbfeld.5
+++ b/farbfeld.5
@@ -72,9 +72,14 @@ if (memcmp("farbfeld", hdr, strlen("farbfeld"))) {
 width = ntohl(*((uint32_t *)(hdr + 8)));
 height = ntohl(*((uint32_t *)(hdr + 12)));
 
+if (fwrite(hdr, 1, sizeof(hdr), outfile) != sizeof(hdr)) {
+   fprintf(stderr, "write error\\n");
+   exit(1);
+}
+
 for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
-   if (fread(rgba, 4, sizeof(uint16_t), infile) != 4) {
+   if (fread(rgba, sizeof(uint16_t), 4, infile) != 4) {
fprintf(stderr, "unexpected EOF\\n");
exit(1);
}
@@ -90,7 +95,7 @@ for (i = 0; i < height; i++) {
for (k = 0; k < 4; k++) {
rgba[k] = htons(rgba[k]);
}
-   if (fwrite(rgba, 4, sizeof(uint16_t), outfile) != 4) {
+   if (fwrite(rgba, sizeof(uint16_t), 4, outfile) != 4) {
fprintf(stderr, "write error\\n");
exit(1);
}



[hackers] [farbfeld] Update config.mk || FRIGN

2016-01-04 Thread git
commit 86495f8058518f7064f2ddda92314aa42163b4c0
Author: FRIGN 
AuthorDate: Mon Jan 4 23:11:25 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 23:11:37 2016 +0100

Update config.mk

-Wno-clobbered is not supported on OpenBSD. Let's remove it and Wextra
with all its stupid warnings.

diff --git a/config.mk b/config.mk
index 4c48639..6c04982 100644
--- a/config.mk
+++ b/config.mk
@@ -6,12 +6,15 @@ PREFIX = /usr/local
 PNGLIB = /usr/local/lib
 PNGINC = /usr/local/include
 
-INCS = -I${PNGINC}
-LIBS = -L${PNGLIB} -lpng -ljpeg
+JPEGLIB = /usr/local/lib
+JPEGINC = /usr/local/include
+
+INCS = -I${PNGINC} -I${JPEGINC}
+LIBS = -L${PNGLIB} -L${JPEGLIB} -lpng -ljpeg
 
 # flags
 CPPFLAGS = -D_DEFAULT_SOURCE
-CFLAGS   = -std=c99 -pedantic -Wall -Wextra -Wno-clobbered -Os ${INCS} 
${CPPFLAGS}
+CFLAGS   = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
 LDFLAGS  = -s ${LIBS}
 
 # compiler and linker



[hackers] [farbfeld] Fix markup-error in farbfeld.5 || FRIGN

2016-01-04 Thread git
commit 7e4fe77f15ff09bce3240b9ab59fc412fdb5ccca
Author: FRIGN 
AuthorDate: Mon Jan 4 22:50:18 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 22:50:18 2016 +0100

Fix markup-error in farbfeld.5

diff --git a/farbfeld.5 b/farbfeld.5
index 8be12cc..8c8ec31 100644
--- a/farbfeld.5
+++ b/farbfeld.5
@@ -39,7 +39,8 @@ The
 is ".ff" and compression extensions shall be
 appended (e.g. ".ff.bz2").
 .Sh MOTIVATION
-.Nm was created because the author was not satisfied with the boilerplate
+.Nm
+was created because the author was not satisfied with the boilerplate
 and inherent complexity involved in handling common image formats
 (PNG, JPEG, GIF,...), having to rely on bloated libraries not being able
 to focus on the task at hand for a given problem.



[hackers] [farbfeld] Add farbfeld(5) manpage || FRIGN

2016-01-04 Thread git
commit 64139c767f82242b26e3b9543cc3c0c5380019be
Author: FRIGN 
AuthorDate: Mon Jan 4 22:25:52 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 22:25:52 2016 +0100

Add farbfeld(5) manpage

diff --git a/farbfeld.5 b/farbfeld.5
new file mode 100644
index 000..8be12cc
--- /dev/null
+++ b/farbfeld.5
@@ -0,0 +1,106 @@
+.Dd 2016-01-04
+.Dt FARBFELD 5
+.Os suckless.org
+.Sh NAME
+.Nm farbfeld
+.Nd suckless image format
+.Sh DESCRIPTION
+.Nm
+is a
+.Em lossless
+image format which is easy to parse, pipe and compress.
+It has the following format:
+.Bd -literal -offset left
+BYTESDESCRIPTION
+8"farbfeld" magic value
+432-Bit BE unsigned integer (width)
+432-Bit BE unsigned integer (height)
+[]   4*16-Bit BE unsigned integers [RGBA] / pixel, row-aligned
+.Ed
+.sp
+The RGB-data should be sRGB for best interoperability.
+.Sh USAGE
+.Nm
+provides
+.Xr png2ff 1 ,
+.Xr jpg2ff 1 ,
+.Xr 2ff 1 ,
+.Xr ff2png 1
+for
+.Em conversions ;
+.Xr bzip2 1
+is recommended for
+.Em compression ,
+giving results comparable with PNG for photographs and much better results
+for other image types.
+.sp
+The
+.Em file extension
+is ".ff" and compression extensions shall be
+appended (e.g. ".ff.bz2").
+.Sh MOTIVATION
+.Nm was created because the author was not satisfied with the boilerplate
+and inherent complexity involved in handling common image formats
+(PNG, JPEG, GIF,...), having to rely on bloated libraries not being able
+to focus on the task at hand for a given problem.
+.Sh EXAMPLES
+Below is an example for a color inverter. No external libraries other
+than libc are needed to read the image data:
+.Bd -literal -offset left
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+(...)
+
+uint32_t width, height, i, j, k;
+uint16_t rgba[4];
+uint8_t hdr[strlen("farbfeld") + 2 * sizeof(uint32_t)];
+
+if (fread(hdr, 1, sizeof(hdr), infile) != sizeof(hdr)) {
+   fprintf(stderr, "incomplete header\\n");
+   exit(1);
+}
+if (memcmp("farbfeld", hdr, strlen("farbfeld"))) {
+   fprintf(stderr, "invalid magic\\n");
+   exit(1);
+}
+width = ntohl(*((uint32_t *)(hdr + 8)));
+height = ntohl(*((uint32_t *)(hdr + 12)));
+
+for (i = 0; i < height; i++) {
+   for (j = 0; j < width; j++) {
+   if (fread(rgba, 4, sizeof(uint16_t), infile) != 4) {
+   fprintf(stderr, "unexpected EOF\\n");
+   exit(1);
+   }
+   for (k = 0; k < 4; k++) {
+   rgba[k] = ntohs(rgba[k]);
+   }
+
+   /* invert colors */
+   rgba[0] = 65535 - rgba[0];
+   rgba[1] = 65535 - rgba[1];
+   rgba[2] = 65535 - rgba[2];
+
+   for (k = 0; k < 4; k++) {
+   rgba[k] = htons(rgba[k]);
+   }
+   if (fwrite(rgba, 4, sizeof(uint16_t), outfile) != 4) {
+   fprintf(stderr, "write error\\n");
+   exit(1);
+   }
+   }
+}
+.Ed
+.Sh SEE ALSO
+.Xr 2ff 1 ,
+.Xr bzip2 1 ,
+.Xr ff2png 1 ,
+.Xr jpg2ff 1 ,
+.Xr png2ff 1
+.Sh AUTHORS
+.An Laslo Hunhold Aq Mt d...@frign.de



[hackers] [farbfeld] Add stricter and clearer error-checking in png2ff and ff2png || FRIGN

2016-01-04 Thread git
commit 6ad3875caa041b3ea716c3b24bee14e748b5c7ff
Author: FRIGN 
AuthorDate: Mon Jan 4 19:17:03 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 19:17:03 2016 +0100

Add stricter and clearer error-checking in png2ff and ff2png

As known from sbase, we want to manually flush stdout to see if all
data has been passed on.

diff --git a/ff2png.c b/ff2png.c
index ad39720..548c7dd 100644
--- a/ff2png.c
+++ b/ff2png.c
@@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -8,17 +9,18 @@
 
 #include 
 
-#define HEADER_FORMAT "farbfeld"
+#define HEADER "farbfeld"
 
 int
 main(int argc, char *argv[])
 {
png_structp png_struct_p;
png_infop png_info_p;
-   uint8_t hdr[16];
-   uint16_t tmp16, *png_row;
-   png_uint_32 width, height, i;
png_size_t png_row_len, j;
+   png_uint_32 width, height, i;
+   int ret = 0;
+   uint16_t tmp16, *png_row;
+   uint8_t hdr[16];
 
if (argc > 1) {
fprintf(stderr, "usage: %s\n", argv[0]);
@@ -26,42 +28,47 @@ main(int argc, char *argv[])
}
 
/* header */
-   if (fread(hdr, 1, strlen(HEADER_FORMAT), stdin) != 
strlen(HEADER_FORMAT)) {
-   fprintf(stderr, "failed to read from stdin or input too 
short\n");
+   if (fread(hdr, 1, strlen(HEADER), stdin) != strlen(HEADER)) {
+   fprintf(stderr, "%s: incomplete header\n", argv[0]);
return 1;
}
if (memcmp("farbfeld", hdr, strlen("farbfeld"))) {
-   fprintf(stderr, "invalid magic in header\n");
+   fprintf(stderr, "%s: invalid magic value\n", argv[0]);
return 1;
}
width = ntohl(*((uint32_t *)(hdr + 8)));
height = ntohl(*((uint32_t *)(hdr + 12)));
 
/* load png */
-   png_struct_p = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, 
NULL, NULL);
+   png_struct_p = png_create_write_struct(PNG_LIBPNG_VER_STRING,
+   NULL, NULL, NULL);
png_info_p = png_create_info_struct(png_struct_p);
 
-   if (!png_struct_p || !png_info_p || setjmp(png_jmpbuf(png_struct_p))) {
-   fprintf(stderr, "failed to initialize libpng\n");
+   if (!png_struct_p || !png_info_p) {
+   fprintf(stderr, "%s: failed to initialize libpng\n", argv[0]);
return 1;
}
+   if (setjmp(png_jmpbuf(png_struct_p)))
+   return 1;
png_init_io(png_struct_p, stdout);
-   png_set_IHDR(png_struct_p, png_info_p, width, height, 16, 
PNG_COLOR_TYPE_RGB_ALPHA,
-PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, 
PNG_FILTER_TYPE_BASE);
+   png_set_IHDR(png_struct_p, png_info_p, width, height, 16,
+PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
+PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_struct_p, png_info_p);
 
/* write rows */
png_row_len = strlen("RGBA") * width * sizeof(uint16_t);
-   png_row = malloc(png_row_len);
-   if (!png_row) {
-   fprintf(stderr, "failed to allocate row-buffer\n");
+   if (!(png_row = malloc(png_row_len))) {
+   fprintf(stderr, "%s: malloc: ", argv[0]);
+   perror(NULL);
return 1;
}
-
for (i = 0; i < height; ++i) {
for (j = 0; j < png_row_len / sizeof(uint16_t); ++j) {
-   if (fread(&tmp16, 1, sizeof(uint16_t), stdin) != 
sizeof(uint16_t)) {
-   fprintf(stderr, "unexpected EOF or row-skew\n");
+   if (fread(&tmp16, 1, sizeof(uint16_t), stdin) !=
+   sizeof(uint16_t)) {
+   fprintf(stderr, "%s: unexpected EOF\n",
+   argv[0]);
return 1;
}
png_row[j] = tmp16;
@@ -70,10 +77,19 @@ main(int argc, char *argv[])
}
png_write_end(png_struct_p, NULL);
 
-   /* clean up */
-   png_free_data(png_struct_p, png_info_p, PNG_FREE_ALL, -1);
png_destroy_write_struct(&png_struct_p, NULL);
-   free(png_row);
 
-   return 0;
+   /* flush output */
+   if (fflush(stdout)) {
+   fprintf(stderr, "%s: fflush stdout: ", argv[0]);
+   perror(NULL);
+   ret = 1;
+   }
+   if (fclose(stdout) && !ret) {
+   fprintf(stderr, "%s: fclose stdout: ", argv[0]);
+   perror(NULL);
+   ret = 1;
+   }
+
+   return ret;
 }
diff --git a/png2ff.c b/png2ff.c
index 0835d34..4f4fc83 100644
--- a/png2ff.c
+++ b/png2ff.c
@@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -13,7 +14,7 @@ main(i

[hackers] [ubase] fix several problems in dd || izabera

2016-01-04 Thread git
commit 3af0bbd564f42d9b70e0f854a6e0ab8add1e7aee
Author: izabera 
AuthorDate: Fri Jan 1 11:05:06 2016 +0100
Commit: sin 
CommitDate: Mon Jan 4 18:07:44 2016 +

fix several problems in dd

diff --git a/dd.c b/dd.c
index 8f802ac..977f0f0 100644
--- a/dd.c
+++ b/dd.c
@@ -33,7 +33,6 @@ struct dd_config {
off_t fsize;
blksize_t bs;
char quiet, nosync, direct;
-   int saved_errno;
time_t t_start, t_end;
 };
 
@@ -52,20 +51,17 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
flo |= O_DIRECT;
}
 
-   if (stat(ddc->in, &st) < 0) {
-   ddc->saved_errno = errno;
-   return -1;
-   }
-
euid = geteuid();
 
if (!euid || st.st_uid == euid)
fli |= O_NOATIME;
 
-   if ((*ifd = open(ddc->in, fli)) < 0) {
-   ddc->saved_errno = errno;
+   if (!ddc->in) *ifd = 0;
+   else if ((*ifd = open(ddc->in, fli)) < 0)
+   return -1;
+
+   if (fstat(*ifd, &st) < 0)
return -1;
-   }
 
ddc->fsize = st.st_size;
 
@@ -90,14 +86,11 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
if (!S_ISREG(st.st_mode)) {
if (S_ISBLK(st.st_mode)) {
if (ioctl(*ifd, BLKGETSIZE64, &ddc->fsize) < 0) {
-   ddc->saved_errno = errno;
close(*ifd);
return -1;
}
} else {
ddc->fsize = (off_t)-1;
-   if (ddc->count)
-   ddc->fsize = ddc->count*ddc->bs;
}
}
 
@@ -107,7 +100,7 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
 
/* skip more bytes than are inside source file? */
if (ddc->fsize != (off_t)-1 && ddc->skip >= (uint64_t)ddc->fsize) {
-   ddc->saved_errno = EINVAL;
+   errno = EINVAL;
close(*ifd);
return -1;
}
@@ -115,14 +108,23 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
if (!ddc->seek)
flo |= O_CREAT|O_TRUNC;
 
-   if ((*ofd = open(ddc->out, flo, st.st_mode)) < 0) {
-   ddc->saved_errno = errno;
+   if (!ddc->out) *ofd = 1;
+   else if ((*ofd = open(ddc->out, flo, st.st_mode)) < 0) {
close(*ifd);
return -1;
}
 
-   lseek(*ifd, ddc->skip, SEEK_SET);
-   lseek(*ofd, ddc->seek, SEEK_SET);
+   if (lseek(*ifd, ddc->skip, SEEK_CUR) < 0) {
+   char buffer[ddc->bs];
+   for (uint64_t i = 0; i < ddc->skip; i += ddc->bs) {
+   if (read(*ifd, &buffer, ddc->bs) < 0) {
+   errno = EINVAL;
+   close(*ifd);
+   return -1;
+   }
+   }
+   }
+   lseek(*ofd, ddc->seek, SEEK_CUR);
posix_fadvise(*ifd, ddc->skip, 0, POSIX_FADV_SEQUENTIAL);
posix_fadvise(*ofd, 0, 0, POSIX_FADV_DONTNEED);
 
@@ -147,7 +149,6 @@ copy_splice(struct dd_config *ddc)
if (prepare_copy(ddc, &ifd, &ofd) < 0)
return -1;
if (pipe(p) < 0) {
-   ddc->saved_errno = errno;
close(ifd); close(ofd);
close(p[0]); close(p[1]);
return -1;
@@ -165,24 +166,18 @@ copy_splice(struct dd_config *ddc)
FD_SET(ifd, &rfd);
FD_SET(ofd, &wfd);
r = select(ifd > ofd ? ifd + 1 : ofd + 1, &rfd, &wfd, NULL, 
NULL);
-   if (r < 0) {
-   ddc->saved_errno = errno;
+   if (r < 0)
break;
-   }
if (FD_ISSET(ifd, &rfd) == 1 && FD_ISSET(ofd, &wfd) == 1) {
if (n > ddc->count - ddc->b_out)
n = ddc->count - ddc->b_out;
r = splice(ifd, NULL, p[1], NULL, n, SPLICE_F_MORE);
-   if (r <= 0) {
-   ddc->saved_errno = errno;
+   if (r <= 0)
break;
-   }
++ddc->rec_in;
r = splice(p[0], NULL, ofd, NULL, r, SPLICE_F_MORE);
-   if (r <= 0) {
-   ddc->saved_errno = errno;
+   if (r <= 0)
break;
-   }
ddc->b_out += r;
++ddc->rec_out;
}
@@ -252,16 +247,16 @@ main(int argc, char *argv[])
argv0 = argv[0];
memset(&config, 0, sizeof(config));
config.bs = 1<<16;
-   config.in = "/dev/stdin";
-   config.out = "/dev/stdout";
+   config.in = NULL;
+   config.out = NULL;
 
/* emulate 'dd' arg

[hackers] [farbfeld] Readd &color || FRIGN

2016-01-04 Thread git
commit d8e77e37dd74d4835977209c3cd57fba3307f6a8
Author: FRIGN 
AuthorDate: Mon Jan 4 18:47:38 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 18:47:38 2016 +0100

Readd &color

Somehow, it broke the depth-value on libpng 1.4.*. Should be worth a
bug-report to the libpng-guys, but I can't be arsed right now.
This fucking library is a pain in the ass.

diff --git a/png2ff.c b/png2ff.c
index 101036d..0835d34 100644
--- a/png2ff.c
+++ b/png2ff.c
@@ -13,7 +13,7 @@ main(int argc, char *argv[])
png_structp png_struct_p;
png_infop png_info_p;
png_bytepp png_row_p;
-   int depth;
+   int depth, color;
uint32_t width, height, png_row_len, tmp32, r, i;
uint16_t tmp16;
 
@@ -43,7 +43,7 @@ main(int argc, char *argv[])
png_read_png(png_struct_p, png_info_p, PNG_TRANSFORM_PACKING |
 PNG_TRANSFORM_EXPAND, NULL);
png_get_IHDR(png_struct_p, png_info_p, &width, &height, &depth,
-NULL, NULL, NULL, NULL);
+&color, NULL, NULL, NULL);
png_row_len = png_get_rowbytes(png_struct_p, png_info_p);
png_row_p = png_get_rows(png_struct_p, png_info_p);
 



[hackers] [farbfeld] Convert depth-check to switch and remove unused variables || FRIGN

2016-01-04 Thread git
commit 06c4b47d0102d2e2205c983c2158b4121c7293ab
Author: FRIGN 
AuthorDate: Mon Jan 4 18:33:42 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 18:33:42 2016 +0100

Convert depth-check to switch and remove unused variables

diff --git a/png2ff.c b/png2ff.c
index 5b75dfa..101036d 100644
--- a/png2ff.c
+++ b/png2ff.c
@@ -13,7 +13,7 @@ main(int argc, char *argv[])
png_structp png_struct_p;
png_infop png_info_p;
png_bytepp png_row_p;
-   int depth, color, interlace;
+   int depth;
uint32_t width, height, png_row_len, tmp32, r, i;
uint16_t tmp16;
 
@@ -43,7 +43,7 @@ main(int argc, char *argv[])
png_read_png(png_struct_p, png_info_p, PNG_TRANSFORM_PACKING |
 PNG_TRANSFORM_EXPAND, NULL);
png_get_IHDR(png_struct_p, png_info_p, &width, &height, &depth,
-&color, &interlace, NULL, NULL);
+NULL, NULL, NULL, NULL);
png_row_len = png_get_rowbytes(png_struct_p, png_info_p);
png_row_p = png_get_rows(png_struct_p, png_info_p);
 
@@ -55,7 +55,8 @@ main(int argc, char *argv[])
fwrite(&tmp32, sizeof(uint32_t), 1, stdout);
 
/* write data */
-   if (depth == 8) {
+   switch(depth) {
+   case 8:
for (r = 0; r < height; ++r) {
for (i = 0; i < png_row_len; i++) {
/* ((2^16-1) / 255) == 257 */
@@ -63,7 +64,8 @@ main(int argc, char *argv[])
fwrite(&tmp16, sizeof(uint16_t), 1, stdout);
}
}
-   } else if (depth == 16) {
+   break;
+   case 16:
for (r = 0; r < height; ++r) {
for (i = 0; i < png_row_len / 2; i++) {
tmp16 = *((uint16_t *)
@@ -71,7 +73,8 @@ main(int argc, char *argv[])
fwrite(&tmp16, sizeof(uint16_t), 1, stdout);
}
}
-   } else {
+   break;
+   default:
fprintf(stderr, "format error\n");
return 1;
}



[hackers] [farbfeld] Clean up png2ff, remove debug leftovers || FRIGN

2016-01-04 Thread git
commit 3ddd2265c4de0ce0b9d9dc7a80dd85aab054d2ae
Author: FRIGN 
AuthorDate: Mon Jan 4 18:29:44 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 18:29:44 2016 +0100

Clean up png2ff, remove debug leftovers

Thanks Dimitris, Hiltjo!

diff --git a/png2ff.c b/png2ff.c
index 9f77344..5b75dfa 100644
--- a/png2ff.c
+++ b/png2ff.c
@@ -18,7 +18,7 @@ main(int argc, char *argv[])
uint16_t tmp16;
 
if (argc > 1) {
-   fprintf(stderr, "usage:%s\n", argv[0]);
+   fprintf(stderr, "usage: %s\n", argv[0]);
return 1;
}
 
@@ -27,10 +27,12 @@ main(int argc, char *argv[])
  NULL, NULL);
png_info_p = png_create_info_struct(png_struct_p);
 
-   if (!png_struct_p || !png_info_p || setjmp(png_jmpbuf(png_struct_p))) {
+   if (!png_struct_p || !png_info_p) {
fprintf(stderr, "failed to initialize libpng\n");
return 1;
}
+   if (setjmp(png_jmpbuf(png_struct_p)))
+   return 1;
png_init_io(png_struct_p, stdin);
if (png_get_valid(png_struct_p, png_info_p, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png_struct_p);
@@ -69,7 +71,6 @@ main(int argc, char *argv[])
fwrite(&tmp16, sizeof(uint16_t), 1, stdout);
}
}
-   fprintf(stderr, "written r=%d, i=%d\n", r, i);
} else {
fprintf(stderr, "format error\n");
return 1;



[hackers] [tabbed] Add configuration option for title truncation string || Quentin Rameau

2016-01-04 Thread git
commit 8920c1ba196df53a8ca06c179a3aa3ee260a6935
Author: Quentin Rameau 
AuthorDate: Mon Jan 4 02:21:04 2016 +0100
Commit: Christoph Lohmann <2...@r-36.net>
CommitDate: Mon Jan 4 18:29:40 2016 +0100

Add configuration option for title truncation string

Permit to use arbitrary string instead of "..." (ie "$") when truncating
client title.

Signed-off-by: Christoph Lohmann <2...@r-36.net>

diff --git a/config.def.h b/config.def.h
index 587ce73..9facec5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -10,6 +10,7 @@ static const char* urgbgcolor   = "#11";
 static const char* urgfgcolor   = "#cc";
 static const char before[]  = "<";
 static const char after[]   = ">";
+static const char titletrim[]   = "...";
 static const int  tabwidth  = 200;
 static const Bool foreground= True;
 static   Bool urgentswitch  = False;
diff --git a/tabbed.c b/tabbed.c
index 5f035c0..eafbec8 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -369,7 +369,7 @@ drawbar(void)
 void
 drawtext(const char *text, unsigned long col[ColLast])
 {
-   int i, x, y, h, len, olen;
+   int i, j, x, y, h, len, olen;
char buf[256];
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
 
@@ -391,8 +391,11 @@ drawtext(const char *text, unsigned long col[ColLast])
return;
 
memcpy(buf, text, len);
-   if (len < olen)
-   for(i = len; i && i > len - 3; buf[--i] = '.');
+   if (len < olen) {
+   for (i = len, j = strlen(titletrim); j && i;
+buf[--i] = titletrim[--j])
+   ;
+   }
 
XSetForeground(dpy, dc.gc, col[ColFG]);
if (dc.font.set)



[hackers] [farbfeld] Update LICENSE || FRIGN

2016-01-04 Thread git
commit d11817909a970e87d3720da64d9be4f8b6305272
Author: FRIGN 
AuthorDate: Mon Jan 4 17:59:03 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 17:59:03 2016 +0100

Update LICENSE

diff --git a/LICENSE b/LICENSE
index fc19dfa..04a34f5 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 ISC-License
 
-(c) 2014-2015 Laslo Hunhold 
+(c) 2014-2016 Laslo Hunhold 
 
 Permission to use, copy, modify, and/or distribute this software for any
 purpose with or without fee is hereby granted, provided that the above



[hackers] [farbfeld] ff2png: Export 16-Bit RGBA PNG's so we don't lose data || FRIGN

2016-01-04 Thread git
commit 8c161ba22e717a82733a6e4192138d153615d3dc
Author: FRIGN 
AuthorDate: Mon Jan 4 17:44:10 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 17:44:10 2016 +0100

ff2png: Export 16-Bit RGBA PNG's so we don't lose data

diff --git a/ff2png.c b/ff2png.c
index 8cded89..ad39720 100644
--- a/ff2png.c
+++ b/ff2png.c
@@ -15,8 +15,8 @@ main(int argc, char *argv[])
 {
png_structp png_struct_p;
png_infop png_info_p;
-   uint8_t hdr[16], *png_row;
-   uint16_t tmp16;
+   uint8_t hdr[16];
+   uint16_t tmp16, *png_row;
png_uint_32 width, height, i;
png_size_t png_row_len, j;
 
@@ -46,12 +46,12 @@ main(int argc, char *argv[])
return 1;
}
png_init_io(png_struct_p, stdout);
-   png_set_IHDR(png_struct_p, png_info_p, width, height, 8, 
PNG_COLOR_TYPE_RGB_ALPHA,
+   png_set_IHDR(png_struct_p, png_info_p, width, height, 16, 
PNG_COLOR_TYPE_RGB_ALPHA,
 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, 
PNG_FILTER_TYPE_BASE);
png_write_info(png_struct_p, png_info_p);
 
/* write rows */
-   png_row_len = strlen("RGBA") * width * sizeof(uint8_t);
+   png_row_len = strlen("RGBA") * width * sizeof(uint16_t);
png_row = malloc(png_row_len);
if (!png_row) {
fprintf(stderr, "failed to allocate row-buffer\n");
@@ -59,15 +59,14 @@ main(int argc, char *argv[])
}
 
for (i = 0; i < height; ++i) {
-   for (j = 0; j < png_row_len; ++j) {
+   for (j = 0; j < png_row_len / sizeof(uint16_t); ++j) {
if (fread(&tmp16, 1, sizeof(uint16_t), stdin) != 
sizeof(uint16_t)) {
fprintf(stderr, "unexpected EOF or row-skew\n");
return 1;
}
-   /* ((2^16-1) / 255) == 257 */
-   png_row[j] = (uint8_t)(ntohs(tmp16) / 257);
+   png_row[j] = tmp16;
}
-   png_write_row(png_struct_p, png_row);
+   png_write_row(png_struct_p, (uint8_t *)png_row);
}
png_write_end(png_struct_p, NULL);
 



[hackers] [farbfeld] Update TODO || FRIGN

2016-01-04 Thread git
commit ca988b274a748afb21e2776964807883c2e537df
Author: FRIGN 
AuthorDate: Mon Jan 4 17:45:50 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 17:45:50 2016 +0100

Update TODO

diff --git a/TODO b/TODO
index 375afde..31accc6 100644
--- a/TODO
+++ b/TODO
@@ -1,2 +1 @@
- o handle truecolor PNG's properly (libpng is painful to use)
  o re-add the old imagefile-tools for gif, ...



[hackers] [farbfeld] png2ff: Convert 16-Bit PNG's losslessly || FRIGN

2016-01-04 Thread git
commit 5bb4be011b6d2857466a2730bb208cad6b839133
Author: FRIGN 
AuthorDate: Mon Jan 4 17:31:10 2016 +0100
Commit: FRIGN 
CommitDate: Mon Jan 4 17:31:10 2016 +0100

png2ff: Convert 16-Bit PNG's losslessly

It took me quite a while to figure out that libpng already gives you
big endian values.
I also tweaked the library functions a bit more to really make sure
that all PNG-types (grayscale, palette, ...) are converted to RGBA
properly.

diff --git a/png2ff.c b/png2ff.c
index e42149d..9f77344 100644
--- a/png2ff.c
+++ b/png2ff.c
@@ -32,10 +32,14 @@ main(int argc, char *argv[])
return 1;
}
png_init_io(png_struct_p, stdin);
-   png_set_add_alpha(png_struct_p, 255, PNG_FILLER_AFTER);
+   if (png_get_valid(png_struct_p, png_info_p, PNG_INFO_tRNS))
+   png_set_tRNS_to_alpha(png_struct_p);
+   png_set_add_alpha(png_struct_p, 255*257, PNG_FILLER_AFTER);
+   png_set_expand_gray_1_2_4_to_8(png_struct_p);
png_set_gray_to_rgb(png_struct_p);
-   png_read_png(png_struct_p, png_info_p, PNG_TRANSFORM_STRIP_16 |
-PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, NULL);
+   png_set_packing(png_struct_p);
+   png_read_png(png_struct_p, png_info_p, PNG_TRANSFORM_PACKING |
+PNG_TRANSFORM_EXPAND, NULL);
png_get_IHDR(png_struct_p, png_info_p, &width, &height, &depth,
 &color, &interlace, NULL, NULL);
png_row_len = png_get_rowbytes(png_struct_p, png_info_p);
@@ -49,16 +53,28 @@ main(int argc, char *argv[])
fwrite(&tmp32, sizeof(uint32_t), 1, stdout);
 
/* write data */
-   /* TODO: allow 16 bit PNGs to be converted losslessly */
-   for (r = 0; r < height; ++r) {
-   for (i = 0; i < png_row_len; i++) {
-   /* ((2^16-1) / 255) == 257 */
-   tmp16 = htons(257 * png_row_p[r][i]);
-   fwrite(&tmp16, sizeof(uint16_t), 1, stdout);
+   if (depth == 8) {
+   for (r = 0; r < height; ++r) {
+   for (i = 0; i < png_row_len; i++) {
+   /* ((2^16-1) / 255) == 257 */
+   tmp16 = htons(257 * png_row_p[r][i]);
+   fwrite(&tmp16, sizeof(uint16_t), 1, stdout);
+   }
}
+   } else if (depth == 16) {
+   for (r = 0; r < height; ++r) {
+   for (i = 0; i < png_row_len / 2; i++) {
+   tmp16 = *((uint16_t *)
+   (png_row_p[r] + 2 * i));
+   fwrite(&tmp16, sizeof(uint16_t), 1, stdout);
+   }
+   }
+   fprintf(stderr, "written r=%d, i=%d\n", r, i);
+   } else {
+   fprintf(stderr, "format error\n");
+   return 1;
}
 
-   /* cleanup */
png_destroy_read_struct(&png_struct_p, &png_info_p, NULL);
 
return 0;