فهرست منبع

Block quotes in documentation can now mangle some special characters.

David Piuva 4 سال پیش
والد
کامیت
9bb26feaf0
3فایلهای تغییر یافته به همراه80 افزوده شده و 46 حذف شده
  1. 20 10
      Doc/Generator/Input/ImageProcessing.txt
  2. 30 6
      Doc/Generator/main.cpp
  3. 30 30
      Doc/ImageProcessing.html

+ 20 - 10
Doc/Generator/Input/ImageProcessing.txt

@@ -48,7 +48,8 @@ Input images and other resources can be captured by the lambda.
 The returned result is automatically saturated to the resulting color type and written without any need for bound checks.
 
 Adding two grayscale images using <B>filter_mapU8</B>:
-<PRE><BLOCKQUOTE>void addImages_map(ImageU8 targetImage, ImageU8 imageA, ImageU8 imageB) {
+CodeStart:
+void addImages_map(ImageU8 targetImage, ImageU8 imageA, ImageU8 imageB) {
 	// Call your lambda for each pixel in targetImage
 	filter_mapU8(targetImage,
 		[imageA, imageB](int x, int y) {
@@ -57,7 +58,8 @@ Adding two grayscale images using <B>filter_mapU8</B>:
 			return lumaA + lumaB;
 		}
 	);
-}</BLOCKQUOTE></PRE>
+}
+CodeEnd:
 
 ---
 
@@ -73,7 +75,8 @@ When taking inputs, try to allow unaligned images if you don't plan to use it fo
 When returning a result that was just created and not a sub-image let it be aligned or even ordered to describe it as closely as possible.
 
 Adding two grayscale images using <B>filter_generateU8</B>:
-<PRE><BLOCKQUOTE>AlignedImageU8 addImages_generate(ImageU8 imageA, ImageU8 imageB) {
+CodeStart:
+AlignedImageU8 addImages_generate(ImageU8 imageA, ImageU8 imageB) {
 	int width = image_getWidth(imageA);
 	int height = image_getHeight(imageA);
 	// Call your lambda for width times height pixels
@@ -84,7 +87,8 @@ Adding two grayscale images using <B>filter_generateU8</B>:
 			return lumaA + lumaB;
 		}
 	);
-}</BLOCKQUOTE></PRE>
+}
+CodeEnd:
 
 ---
 
@@ -100,7 +104,8 @@ Calling functions that can not be inlined inside of a loop would be very bad for
 Writing the result using image_writePixel will automatically saturate to fit into 8 bits.
 
 Adding two grayscale images using <B>image_writePixel</B>:
-<PRE><BLOCKQUOTE>void addImages_loop(ImageU8 targetImage, ImageU8 imageA, ImageU8 imageB) {
+CodeStart:
+void addImages_loop(ImageU8 targetImage, ImageU8 imageA, ImageU8 imageB) {
 	int width = image_getWidth(targetImage);
 	int height = image_getHeight(targetImage);
 	// Loop over all x, y coordinates yourself
@@ -111,7 +116,8 @@ Adding two grayscale images using <B>image_writePixel</B>:
 			image_writePixel(targetImage, x, y, lumaA + lumaB);
 		}
 	}
-}</BLOCKQUOTE></PRE>
+}
+CodeEnd:
 
 ---
 
@@ -125,7 +131,8 @@ Saturation of the result can be done using an atomic if statement containing a b
 Because we are adding two unsigned images, we do not have to clamp any negative values to zero and only need to clamp values larger than the largest unsigned 8-bit integer (255).
 
 Adding two grayscale images using <B>SafePointer<uint8_t></B>:
-<PRE><BLOCKQUOTE>void addImages_pointer(ImageU8 targetImage, ImageU8 imageA, ImageU8 imageB) {
+CodeStart:
+void addImages_pointer(ImageU8 targetImage, ImageU8 imageA, ImageU8 imageB) {
 	int width = image_getWidth(targetImage);
 	int height = image_getHeight(targetImage);
 	SafePointer<uint8_t> targetRow = image_getSafePointer(targetImage);
@@ -157,7 +164,8 @@ Adding two grayscale images using <B>SafePointer<uint8_t></B>:
 		rowA.increaseBytes(strideA);
 		rowB.increaseBytes(strideB);
 	}
-}</BLOCKQUOTE></PRE>
+}
+CodeEnd:
 
 ---
 
@@ -187,7 +195,8 @@ When adding an integer to a pointer, the address offset is multiplied by the poi
 This means that a pointers of uint32_t for a color pixel only needs to add 4 elements to the pointer to move 16 bytes, while pointers of uint16_t moves 8 elements and pointers of uint8_t moves 16 elements.
 
 Adding two grayscale images using SIMD vectorization</B>:
-<PRE><BLOCKQUOTE>void addImages_simd(AlignedImageU8 targetImage, AlignedImageU8 imageA, AlignedImageU8 imageB) {
+CodeStart:
+void addImages_simd(AlignedImageU8 targetImage, AlignedImageU8 imageA, AlignedImageU8 imageB) {
 	int width = image_getWidth(targetImage);
 	int height = image_getHeight(targetImage);
 	SafePointer<uint8_t> targetRow = image_getSafePointer(targetImage);
@@ -219,6 +228,7 @@ Adding two grayscale images using SIMD vectorization</B>:
 		rowA.increaseBytes(strideA);
 		rowB.increaseBytes(strideB);
 	}
-}</BLOCKQUOTE></PRE>
+}
+CodeEnd:
 
 ---

+ 30 - 6
Doc/Generator/main.cpp

@@ -12,6 +12,24 @@ bool string_beginsWith(const ReadableString &a, const ReadableString &b) {
 	return string_caseInsensitiveMatch(string_before(a, string_length(b)), b);
 }
 
+String substituteCharacters(ReadableString text) {
+	String result;
+	for (int i = 0; i < string_length(text); i++) {
+		DsrChar c = text[i];
+		if (c == U'<') {
+			string_append(result, U"&lt;");
+		} else if (c == U'>') {
+			string_append(result, U"&gt;");
+		} else if (c == U'\\') {
+			string_append(result, U"&bsol;");
+		} else {
+			string_appendChar(result, text[i]);
+		}
+	}
+	return result;
+}
+
+bool codeBlock = false;
 void processContent(String &target, String content) {
 	string_split_callback([&target](ReadableString section) {
 		//printText(U"Processing: ", section, U"\n");
@@ -60,13 +78,19 @@ void processContent(String &target, String content) {
 			ReadableString title = string_from(section, 7);
 			//printText(U"    Title3: ", title, U"\n");
 			string_append(target, U"</P><H3>", title, U"</H3><P>");
-		} else if (string_beginsWith(section, U"Code:")) {
-            // TODO: Find a clean syntax for multi-line quotes in <PRE><BLOCKQUOTE>...</PRE></BLOCKQUOTE>
-			ReadableString code = string_from(section, 5);
-			//printText(U"    Code: ", code, U"\n");
-			string_append(target, U"<blockquote>", code, U"</blockquote>");
+		} else if (string_beginsWith(section, U"CodeStart:")) {
+			ReadableString code = string_from(section, 10);
+			string_append(target, U"<PRE><BLOCKQUOTE>", substituteCharacters(code));
+			codeBlock = true;
+		} else if (string_beginsWith(section, U"CodeEnd:")) {
+			string_append(target, U"</BLOCKQUOTE></PRE>");
+			codeBlock = false;
 		} else {
-			string_append(target, section, U"\n");
+			if (codeBlock) {
+				string_append(target, substituteCharacters(section), U"\n");
+			} else {
+				string_append(target, section, U"\n");
+			}
 		}
 	}, content, U'\n');
 }

+ 30 - 30
Doc/ImageProcessing.html

@@ -97,8 +97,8 @@ Adding two grayscale images using <B>filter_mapU8</B>:
 			return lumaA + lumaB;
 		}
 	);
-}</BLOCKQUOTE></PRE>
-
+}
+</BLOCKQUOTE></PRE>
 </P><P>
 </P><IMG SRC="Images/Border.png"><P>
 
@@ -129,8 +129,8 @@ Adding two grayscale images using <B>filter_generateU8</B>:
 			return lumaA + lumaB;
 		}
 	);
-}</BLOCKQUOTE></PRE>
-
+}
+</BLOCKQUOTE></PRE>
 </P><P>
 </P><IMG SRC="Images/Border.png"><P>
 
@@ -154,15 +154,15 @@ Adding two grayscale images using <B>image_writePixel</B>:
 	int width = image_getWidth(targetImage);
 	int height = image_getHeight(targetImage);
 	// Loop over all x, y coordinates yourself
-	for (int y = 0; y < height; y++) {
-		for (int x = 0; x < width; x++) {
+	for (int y = 0; y &lt; height; y++) {
+		for (int x = 0; x &lt; width; x++) {
 			int lumaA = image_readPixel_clamp(imageA, x, y);
 			int lumaB = image_readPixel_clamp(imageB, x, y);
 			image_writePixel(targetImage, x, y, lumaA + lumaB);
 		}
 	}
-}</BLOCKQUOTE></PRE>
-
+}
+</BLOCKQUOTE></PRE>
 </P><P>
 </P><IMG SRC="Images/Border.png"><P>
 
@@ -183,23 +183,23 @@ Adding two grayscale images using <B>SafePointer<uint8_t></B>:
 <PRE><BLOCKQUOTE>void addImages_pointer(ImageU8 targetImage, ImageU8 imageA, ImageU8 imageB) {
 	int width = image_getWidth(targetImage);
 	int height = image_getHeight(targetImage);
-	SafePointer<uint8_t> targetRow = image_getSafePointer(targetImage);
-	SafePointer<uint8_t> rowA = image_getSafePointer(imageA);
-	SafePointer<uint8_t> rowB = image_getSafePointer(imageB);
+	SafePointer&lt;uint8_t&gt; targetRow = image_getSafePointer(targetImage);
+	SafePointer&lt;uint8_t&gt; rowA = image_getSafePointer(imageA);
+	SafePointer&lt;uint8_t&gt; rowB = image_getSafePointer(imageB);
 	int targetStride = image_getStride(targetImage);
 	int strideA = image_getStride(imageA);
 	int strideB = image_getStride(imageB);
-	for (int y = 0; y < height; y++) {
-		SafePointer<uint8_t> targetPixel = targetRow;
-		SafePointer<uint8_t> pixelA = rowA;
-		SafePointer<uint8_t> pixelB = rowB;
-		for (int x = 0; x < width; x++) {
+	for (int y = 0; y &lt; height; y++) {
+		SafePointer&lt;uint8_t&gt; targetPixel = targetRow;
+		SafePointer&lt;uint8_t&gt; pixelA = rowA;
+		SafePointer&lt;uint8_t&gt; pixelB = rowB;
+		for (int x = 0; x &lt; width; x++) {
 			// Read both source pixels and add them
 			int result = *pixelA + *pixelB;
 			// Clamp overflow
-			if (result > 255) result = 255;
+			if (result &gt; 255) result = 255;
 			// Can skip underflow check
-			//if (result < 0) result = 0;
+			//if (result &lt; 0) result = 0;
 			// Write the result
 			*targetPixel = result;
 			// Move pixel pointers to the next pixel
@@ -212,8 +212,8 @@ Adding two grayscale images using <B>SafePointer<uint8_t></B>:
 		rowA.increaseBytes(strideA);
 		rowB.increaseBytes(strideB);
 	}
-}</BLOCKQUOTE></PRE>
-
+}
+</BLOCKQUOTE></PRE>
 </P><P>
 </P><IMG SRC="Images/Border.png"><P>
 
@@ -256,18 +256,18 @@ Adding two grayscale images using SIMD vectorization</B>:
 <PRE><BLOCKQUOTE>void addImages_simd(AlignedImageU8 targetImage, AlignedImageU8 imageA, AlignedImageU8 imageB) {
 	int width = image_getWidth(targetImage);
 	int height = image_getHeight(targetImage);
-	SafePointer<uint8_t> targetRow = image_getSafePointer(targetImage);
-	SafePointer<uint8_t> rowA = image_getSafePointer(imageA);
-	SafePointer<uint8_t> rowB = image_getSafePointer(imageB);
+	SafePointer&lt;uint8_t&gt; targetRow = image_getSafePointer(targetImage);
+	SafePointer&lt;uint8_t&gt; rowA = image_getSafePointer(imageA);
+	SafePointer&lt;uint8_t&gt; rowB = image_getSafePointer(imageB);
 	int targetStride = image_getStride(targetImage);
 	int strideA = image_getStride(imageA);
 	int strideB = image_getStride(imageB);
-	for (int y = 0; y < height; y++) {
-		SafePointer<uint8_t> targetPixel = targetRow;
-		SafePointer<uint8_t> pixelA = rowA;
-		SafePointer<uint8_t> pixelB = rowB;
+	for (int y = 0; y &lt; height; y++) {
+		SafePointer&lt;uint8_t&gt; targetPixel = targetRow;
+		SafePointer&lt;uint8_t&gt; pixelA = rowA;
+		SafePointer&lt;uint8_t&gt; pixelB = rowB;
 		// Assuming that we have ownership of any padding pixels
-		for (int x = 0; x < width; x += 16) {
+		for (int x = 0; x &lt; width; x += 16) {
 			// Read 16 source pixels at a time
 			U8x16 a = U8x16::readAligned(pixelA, "addImages: reading pixelA");
 			U8x16 b = U8x16::readAligned(pixelB, "addImages: reading pixelB");
@@ -285,8 +285,8 @@ Adding two grayscale images using SIMD vectorization</B>:
 		rowA.increaseBytes(strideA);
 		rowB.increaseBytes(strideB);
 	}
-}</BLOCKQUOTE></PRE>
-
+}
+</BLOCKQUOTE></PRE>
 </P><P>
 </P><IMG SRC="Images/Border.png"><P>
 </P>