summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-09-05 13:37:21 -0400
committerJune McEnroe <june@causal.agency>2018-09-05 13:37:21 -0400
commit33d65d605abcfe904d1c1737b401a71a4befc300 (patch)
treec30e54123d785f5e57c8bf6436a53db9ce798d27
parentZero after mirror (diff)
downloadsrc-33d65d605abcfe904d1c1737b401a71a4befc300.tar.gz
src-33d65d605abcfe904d1c1737b401a71a4befc300.zip
Factor out pixelBits, pixelSize in pngo
Diffstat (limited to '')
-rw-r--r--bin/pngo.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/bin/pngo.c b/bin/pngo.c
index cd9eb7d4..c629c8c1 100644
--- a/bin/pngo.c
+++ b/bin/pngo.c
@@ -132,17 +132,25 @@ static struct PACKED {
 } header;
 static_assert(13 == sizeof(header), "header size");
 
-static size_t lineSize(void) {
+static size_t pixelBits(void) {
 	switch (header.color) {
-		case Grayscale:      return (header.width * 1 * header.depth + 7) / 8;
-		case Truecolor:      return (header.width * 3 * header.depth + 7) / 8;
-		case Indexed:        return (header.width * 1 * header.depth + 7) / 8;
-		case GrayscaleAlpha: return (header.width * 2 * header.depth + 7) / 8;
-		case TruecolorAlpha: return (header.width * 4 * header.depth + 7) / 8;
+		case Grayscale:      return 1 * header.depth;
+		case Truecolor:      return 3 * header.depth;
+		case Indexed:        return 1 * header.depth;
+		case GrayscaleAlpha: return 2 * header.depth;
+		case TruecolorAlpha: return 4 * header.depth;
 		default: abort();
 	}
 }
 
+static size_t pixelSize(void) {
+	return (pixelBits() + 7) / 8;
+}
+
+static size_t lineSize(void) {
+	return (header.width * pixelBits() + 7) / 8;
+}
+
 static size_t dataSize(void) {
 	return (1 + lineSize()) * header.height;
 }
@@ -427,14 +435,12 @@ static void scanlines(void) {
 }
 
 static struct Bytes origBytes(uint32_t y, size_t i) {
-	size_t pixelSize = lineSize() / header.width;
-	if (!pixelSize) pixelSize = 1;
-	bool a = (i >= pixelSize), b = (y > 0), c = (a && b);
+	bool a = (i >= pixelSize()), b = (y > 0), c = (a && b);
 	return (struct Bytes) {
 		.x = lines[y]->data[i],
-		.a = a ? lines[y]->data[i - pixelSize] : 0,
+		.a = a ? lines[y]->data[i - pixelSize()] : 0,
 		.b = b ? lines[y - 1]->data[i] : 0,
-		.c = c ? lines[y - 1]->data[i - pixelSize] : 0,
+		.c = c ? lines[y - 1]->data[i - pixelSize()] : 0,
 	};
 }
 
@@ -469,12 +475,11 @@ static void filterData(void) {
 static void discardAlpha(void) {
 	if (header.color != GrayscaleAlpha && header.color != TruecolorAlpha) return;
 	size_t sampleSize = header.depth / 8;
-	size_t pixelSize = sampleSize * (header.color == GrayscaleAlpha ? 2 : 4);
-	size_t colorSize = pixelSize - sampleSize;
+	size_t colorSize = pixelSize() - sampleSize;
 	for (uint32_t y = 0; y < header.height; ++y) {
 		for (uint32_t x = 0; x < header.width; ++x) {
 			for (size_t i = 0; i < sampleSize; ++i) {
-				if (lines[y]->data[x * pixelSize + colorSize + i] != 0xFF) return;
+				if (lines[y]->data[x * pixelSize() + colorSize + i] != 0xFF) return;
 			}
 		}
 	}
@@ -483,7 +488,7 @@ static void discardAlpha(void) {
 	for (uint32_t y = 0; y < header.height; ++y) {
 		*ptr++ = lines[y]->type;
 		for (uint32_t x = 0; x < header.width; ++x) {
-			memmove(ptr, &lines[y]->data[x * pixelSize], colorSize);
+			memmove(ptr, &lines[y]->data[x * pixelSize()], colorSize);
 			ptr += colorSize;
 		}
 	}
@@ -494,10 +499,9 @@ static void discardAlpha(void) {
 static void discardColor(void) {
 	if (header.color != Truecolor && header.color != TruecolorAlpha) return;
 	size_t sampleSize = header.depth / 8;
-	size_t pixelSize = sampleSize * (header.color == Truecolor ? 3 : 4);
 	for (uint32_t y = 0; y < header.height; ++y) {
 		for (uint32_t x = 0; x < header.width; ++x) {
-			uint8_t *r = &lines[y]->data[x * pixelSize];
+			uint8_t *r = &lines[y]->data[x * pixelSize()];
 			uint8_t *g = r + sampleSize;
 			uint8_t *b = g + sampleSize;
 			if (0 != memcmp(r, g, sampleSize)) return;
@@ -509,7 +513,7 @@ static void discardColor(void) {
 	for (uint32_t y = 0; y < header.height; ++y) {
 		*ptr++ = lines[y]->type;
 		for (uint32_t x = 0; x < header.width; ++x) {
-			uint8_t *pixel = &lines[y]->data[x * pixelSize];
+			uint8_t *pixel = &lines[y]->data[x * pixelSize()];
 			memmove(ptr, pixel, sampleSize);
 			ptr += sampleSize;
 			if (header.color == TruecolorAlpha) {
ref='/cgit-pink/commit/ui-shared.c?id=bb3cc0d9666553608b7c89aef84d21d3312ce488&follow=1'>ui-shared: do not allow negative minutesJason A. Donenfeld Do to timestamp differences, sometimes cgit would should "-0 min", which doesn't make any sense. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-17auth: document tweakables in lua scriptJason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-17repolist: make owner clickable to searchJason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-17ui-shared: move about tab all the way to the leftJason A. Donenfeld There were no objections (at the time of committing this): http://lists.zx2c4.com/pipermail/cgit/2013-May/001393.html http://lists.zx2c4.com/pipermail/cgit/2014-January/001904.html Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-17filter: don't forget to reap the auth filterJason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-17cgit.c: free tmp variableJason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-17Switch to exclusively using global ctxLukas Fleischer Drop the context parameter from the following functions (and all static helpers used by them) and use the global context instead: * cgit_print_http_headers() * cgit_print_docstart() * cgit_print_pageheader() Remove context parameter from all commands Drop the context parameter from the following functions (and all static helpers used by them) and use the global context instead: * cgit_get_cmd() * All cgit command functions. * cgit_clone_info() * cgit_clone_objects() * cgit_clone_head() * cgit_print_plain() * cgit_show_stats() In initialization routines, use the global context variable instead of passing a pointer around locally. Remove callback data parameter for cache slots This is no longer needed since the context is always read from the global context variable. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-16auth: have cgit calculate login addressJason A. Donenfeld This way we're sure to use virtual root, or any other strangeness encountered. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-16auth: lua string comparisons are time invariantJason A. Donenfeld By default, strings are compared by hash, so we can remove this comment. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-16authentication: use hidden form instead of refererJason A. Donenfeld This also gives us some CSRF protection. Note that we make use of the hmac to protect the redirect value. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-16auth: add basic authentication filter frameworkJason A. Donenfeld This leverages the new lua support. See filters/simple-authentication.lua for explaination of how this works. There is also additional documentation in cgitrc.5.txt. Though this is a cookie-based approach, cgit's caching mechanism is preserved for authenticated pages. Very plugable and extendable depending on user needs. The sample script uses an HMAC-SHA1 based cookie to store the currently logged in user, with an expiration date. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2014-01-16t0111: Additions and fixesLukas Fleischer * Rename the capitalize-* filters to dump.* since they also dump the arguments. * Add full argument validation to the email filters. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-16parsing.c: Remove leading space from committerLukas Fleischer