Browse Source

Cleaned up the code a bit using cppcheck.

David Piuva 10 months ago
parent
commit
15d1526231

+ 4 - 4
Source/DFPSR/api/filterAPI.cpp

@@ -770,7 +770,7 @@ static void mapRgbaU8(const ImageRgbaU8& target, const ImageGenRgbaU8& lambda, i
 		targetRow.increaseBytes(targetStride);
 	}
 }
-void filter_mapRgbaU8(const ImageRgbaU8 target, const ImageGenRgbaU8& lambda, int startX, int startY) {
+void filter_mapRgbaU8(const ImageRgbaU8 &target, const ImageGenRgbaU8& lambda, int startX, int startY) {
 	if (image_exists(target)) {
 		mapRgbaU8(target, lambda, startX, startY);
 	}
@@ -799,7 +799,7 @@ static void mapMonochrome(const IMAGE_TYPE& target, const ImageGenI32& lambda, i
 		targetRow.increaseBytes(targetStride);
 	}
 }
-void filter_mapU8(const ImageU8 target, const ImageGenI32& lambda, int startX, int startY) {
+void filter_mapU8(const ImageU8 &target, const ImageGenI32& lambda, int startX, int startY) {
 	if (image_exists(target)) {
 		mapMonochrome<ImageU8, uint8_t, 0, 255>(target, lambda, startX, startY);
 	}
@@ -809,7 +809,7 @@ AlignedImageU8 filter_generateU8(int width, int height, const ImageGenI32& lambd
 	filter_mapU8(result, lambda, startX, startY);
 	return result;
 }
-void filter_mapU16(const ImageU16 target, const ImageGenI32& lambda, int startX, int startY) {
+void filter_mapU16(const ImageU16 &target, const ImageGenI32& lambda, int startX, int startY) {
 	if (image_exists(target)) {
 		mapMonochrome<ImageU16, uint16_t, 0, 65535>(target, lambda, startX, startY);
 	}
@@ -834,7 +834,7 @@ static void mapF32(const ImageF32& target, const ImageGenF32& lambda, int startX
 		targetRow.increaseBytes(targetStride);
 	}
 }
-void filter_mapF32(const ImageF32 target, const ImageGenF32& lambda, int startX, int startY) {
+void filter_mapF32(const ImageF32 &target, const ImageGenF32& lambda, int startX, int startY) {
 	if (image_exists(target)) {
 		mapF32(target, lambda, startX, startY);
 	}

+ 4 - 4
Source/DFPSR/api/filterAPI.h

@@ -56,10 +56,10 @@ namespace dsr {
 	using ImageGenF32 = std::function<float(int x, int y)>;
 	// In-place image generation to an existing image.
 	//   The pixel at the upper left corner gets (startX, startY) as x and y arguments to the function.
-	void filter_mapRgbaU8(const ImageRgbaU8 target, const ImageGenRgbaU8& lambda, int startX = 0, int startY = 0);
-	void filter_mapU8(const ImageU8 target, const ImageGenI32& lambda, int startX = 0, int startY = 0);
-	void filter_mapU16(const ImageU16 target, const ImageGenI32& lambda, int startX = 0, int startY = 0);
-	void filter_mapF32(const ImageF32 target, const ImageGenF32& lambda, int startX = 0, int startY = 0);
+	void filter_mapRgbaU8(const ImageRgbaU8 &target, const ImageGenRgbaU8& lambda, int startX = 0, int startY = 0);
+	void filter_mapU8(const ImageU8 &target, const ImageGenI32& lambda, int startX = 0, int startY = 0);
+	void filter_mapU16(const ImageU16 &target, const ImageGenI32& lambda, int startX = 0, int startY = 0);
+	void filter_mapF32(const ImageF32 &target, const ImageGenF32& lambda, int startX = 0, int startY = 0);
 	// A simpler image generation that constructs the image as a result.
 	// Example:
 	//     int width = 64;

+ 1 - 1
Source/DFPSR/api/stringAPI.cpp

@@ -953,7 +953,7 @@ List<String> dsr::string_split(const ReadableString& source, DsrChar separator,
 }
 
 intptr_t dsr::string_splitCount(const ReadableString& source, DsrChar separator) {
-	intptr_t result;
+	intptr_t result = 0;
 	string_split_callback([&result](ReadableString element) {
 		result++;
 	}, source, separator);

+ 2 - 2
Source/DFPSR/base/heap.cpp

@@ -154,8 +154,8 @@ namespace dsr {
 		static uintptr_t heapAlignment = 0u;
 		if (heapAlignment == 0) {
 			heapAlignment = getCacheLineSize();
-			if (heapAlignment < sizeof(DSR_FLOAT_VECTOR_SIZE)) heapAlignment = sizeof(DSR_FLOAT_VECTOR_SIZE);
-			if (heapAlignment < minimumHeapAlignment) heapAlignment = minimumHeapAlignment;
+			if (heapAlignment < DSR_FLOAT_VECTOR_SIZE) { heapAlignment = DSR_FLOAT_VECTOR_SIZE; }
+			if (heapAlignment < minimumHeapAlignment) { heapAlignment = minimumHeapAlignment; }
 			heapAlignmentAndMask = memory_createAlignmentAndMask(heapAlignment);
 		}
 		return heapAlignment;

+ 1 - 1
Source/DFPSR/implementation/gui/VisualComponent.cpp

@@ -227,7 +227,7 @@ void VisualComponent::draw(ImageRgbaU8& targetImage, const IVector2D& offset) {
 	}
 }
 
-void VisualComponent::drawClipped(ImageRgbaU8 targetImage, const IVector2D& offset, const IRect& clipRegion) {
+void VisualComponent::drawClipped(ImageRgbaU8& targetImage, const IVector2D& offset, const IRect& clipRegion) {
 	IRect finalRegion = IRect::cut(clipRegion, IRect(0, 0, image_getWidth(targetImage), image_getHeight(targetImage)));
 	if (finalRegion.hasArea()) {
 		// TODO: Optimize allocation of sub-images

+ 1 - 1
Source/DFPSR/implementation/gui/VisualComponent.h

@@ -190,7 +190,7 @@ public:
 	//       drawClipped(i, o, IRect(10, 0, 10, 20)) // Right half
 	//   Drawing with the whole target image as a clip region should be equivalent to a corresponding call to draw with the same targetImage and offset.
 	//     draw(i, o) <=> drawClipped(i, o, IRect(0, 0, i.width(), i.height()))
-	void drawClipped(ImageRgbaU8 targetImage, const IVector2D& offset, const IRect& clipRegion);
+	void drawClipped(ImageRgbaU8& targetImage, const IVector2D& offset, const IRect& clipRegion);
 
 	// Add a child component
 	//   Preconditions:

+ 1 - 1
Source/DFPSR/implementation/gui/components/Button.cpp

@@ -60,7 +60,7 @@ bool Button::isContainer() const {
 	return false;
 }
 
-static OrderedImageRgbaU8 generateButtonImage(Button &button, MediaMethod imageGenerator, int pressed, int width, int height, ColorRgbI32 backColor, ColorRgbI32 foreColor, String text, RasterFont font) {
+static OrderedImageRgbaU8 generateButtonImage(Button &button, MediaMethod imageGenerator, int pressed, int width, int height, ColorRgbI32 backColor, ColorRgbI32 foreColor, const ReadableString &text, RasterFont font) {
 	// Create a scaled image
 	OrderedImageRgbaU8 result;
  	component_generateImage(button.getTheme(), imageGenerator, width, height, backColor.red, backColor.green, backColor.blue, pressed)(result);

+ 1 - 1
Source/DFPSR/implementation/render/model/Model.cpp

@@ -115,7 +115,7 @@ int Polygon::getVertexCount() const {
 	}
 }
 
-Part::Part(String name) : name(name) {}
+Part::Part(const ReadableString &name) : name(name) {}
 Part::Part(const TextureRgbaU8 &diffuseMap, const TextureRgbaU8 &lightMap, const List<Polygon> &polygonBuffer, const String &name) :
   diffuseMap(diffuseMap), lightMap(lightMap), polygonBuffer(polygonBuffer), name(name) {}
 Part Part::clone() const { return Part(this->diffuseMap, this->lightMap, this->polygonBuffer, this->name); }

+ 1 - 1
Source/DFPSR/implementation/render/model/Model.h

@@ -67,7 +67,7 @@ struct Part {
 	TextureRgbaU8 diffuseMap, lightMap;
 	List<Polygon> polygonBuffer;
 	String name;
-	explicit Part(String name);
+	explicit Part(const ReadableString &name);
 	Part(const TextureRgbaU8 &diffuseMap, const TextureRgbaU8 &lightMap, const List<Polygon> &polygonBuffer, const String &name);
 	Part clone() const;
 	void render(CommandQueue *commandQueue, ImageRgbaU8* targetImage, ImageF32* depthBuffer, const Transform3D &modelToWorldTransform, const Camera &camera, Filter filter, const ProjectedPoint* projected) const;

+ 2 - 2
Source/DFPSR/implementation/render/renderCore.cpp

@@ -37,7 +37,7 @@ public:
 	float value = 0.0f; // Used by algorithms
 	SubVertex() : cs(FVector3D()), subB(0.0f), subC(0.0f) {}
 	SubVertex(FVector3D cs, float subB, float subC) : cs(cs), subB(subB), subC(subC) {}
-	SubVertex(SubVertex vertexA, SubVertex vertexB, float ratio) {
+	SubVertex(const SubVertex &vertexA, const SubVertex &vertexB, float ratio) {
 		float invRatio = 1.0f - ratio;
 		this->cs = vertexA.cs * invRatio + vertexB.cs * ratio;
 		this->subB = vertexA.subB * invRatio + vertexB.subB * ratio;
@@ -284,7 +284,7 @@ void dsr::renderTriangleFromData(
   CommandQueue *commandQueue, ImageRgbaU8 *targetImage, ImageF32 *depthBuffer,
   const Camera &camera, const ProjectedPoint &posA, const ProjectedPoint &posB, const ProjectedPoint &posC,
   Filter filter, const TextureRgbaU8 *diffuse, const TextureRgbaU8 *light,
-  TriangleTexCoords texCoords, TriangleColors colors) {
+  const TriangleTexCoords &texCoords, const TriangleColors &colors) {
 	// Get dimensions from both buffers
 	int colorWidth = targetImage != nullptr ? image_getWidth(*targetImage) : 0;
 	int colorHeight = targetImage != nullptr ? image_getHeight(*targetImage) : 0;

+ 1 - 1
Source/DFPSR/implementation/render/renderCore.h

@@ -105,7 +105,7 @@ void renderTriangleFromData(
   CommandQueue *commandQueue, ImageRgbaU8 *targetImage, ImageF32 *depthBuffer,
   const Camera &camera, const ProjectedPoint &posA, const ProjectedPoint &posB, const ProjectedPoint &posC,
   Filter filter, const TextureRgbaU8 *diffuse, const TextureRgbaU8 *light,
-  TriangleTexCoords texCoords, TriangleColors colors
+  const TriangleTexCoords &texCoords, const TriangleColors &colors
 );
 void renderTriangleFromDataDepth(ImageF32 *depthBuffer, const Camera &camera, const ProjectedPoint &posA, const ProjectedPoint &posB, const ProjectedPoint &posC);
 

+ 1 - 1
Source/check.sh

@@ -1 +1 @@
-cppcheck . --enable=all
+cppcheck --enable=warning,performance,portability --std=c++14 .