{"id":23021026,"url":"https://github.com/b-sullender/blend-pixels","last_synced_at":"2026-03-20T00:15:33.292Z","repository":{"id":190683857,"uuid":"683122841","full_name":"b-sullender/blend-pixels","owner":"b-sullender","description":"Shows how to accurately blend 2 BGRA pixels, using a user-defined alpha input, resulting in a final BGRA pixel.","archived":false,"fork":false,"pushed_at":"2023-08-25T18:11:32.000Z","size":2,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-26T02:49:35.299Z","etag":null,"topics":["blending-images","image-processing","pixels"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/b-sullender.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-25T16:49:47.000Z","updated_at":"2023-09-25T03:23:15.000Z","dependencies_parsed_at":"2023-08-25T23:53:03.595Z","dependency_job_id":null,"html_url":"https://github.com/b-sullender/blend-pixels","commit_stats":null,"previous_names":["b-sullender/blend-pixels"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/b-sullender/blend-pixels","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-sullender%2Fblend-pixels","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-sullender%2Fblend-pixels/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-sullender%2Fblend-pixels/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-sullender%2Fblend-pixels/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b-sullender","download_url":"https://codeload.github.com/b-sullender/blend-pixels/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b-sullender%2Fblend-pixels/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29326078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T02:08:56.257Z","status":"ssl_error","status_checked_at":"2026-02-11T02:08:51.338Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blending-images","image-processing","pixels"],"created_at":"2024-12-15T12:16:12.350Z","updated_at":"2026-02-11T03:04:32.223Z","avatar_url":"https://github.com/b-sullender.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blend Pixels\n\n## About\n\nThis project addresses the challenge of accurately blending two pixels with alpha channels, resulting in a seamless and visually appealing composite image. The solution takes into account both the alpha channels of the pixels being blended and a user-provided alpha value that determines the final alpha channel of the blended pixel.\n\n## Motivation\n\nDuring the search for a solution to accurately blend pixels with alpha channels that results in a RGBA (4-channel) image, I decided to visualize the problem, do the math myself, and develop an algorithm that produces the correct result. The algorithm handles pixel blending and also manages alpha values, resulting in a smooth and controlled blending process.\n\nLICENSE TERMS\n=============\n```\nThis software is provided 'as-is', without any express or implied\nwarranty.  In no event will the authors be held liable for any damages\narising from the use of this software.\n\nPermission is granted to anyone to use this software for any purpose,\nincluding commercial applications, and to alter it and redistribute it\nfreely, subject to the following restrictions:\n\n(1) If any part of the source code or algorithm is used, it is requested that\n    appropriate attribution is given to the authors by providing a link to\n    the original repository or a reference to the authors name.\n(2) Permission for use of this software is granted only if the user accepts\n    full responsibility for any undesirable consequences; the authors accept\n    NO LIABILITY for damages of any kind.\n\nBy using this software, you acknowledge that you have read and understood\nthese terms and agree to abide by them.\n```\n\n## Source Code\n\nC Language:\n```\n// This code shows how to accurately blend pixels in C/C++\n// Algorithm created by Brian Sullender in 2021\n\n#include \u003cstddef.h\u003e\n#include \u003cmath.h\u003e\n\n// Unsigned 8-bits\ntypedef unsigned char U8;\n\n// Unsigned 32-bits\ntypedef unsigned int U32;\n\n// This struct represents a single pixel\n#pragma pack(push, 1)\nstruct PIXEL\n{\n    U8 Blue;\n    U8 Green;\n    U8 Red;\n    U8 Alpha;\n};\n#pragma pack(pop)\n\n// Blends two pixels based on a specified alpha value.\n//   @param desPixel Pointer to the destination pixel.\n//   @param pix2 The second pixel to blend with.\n//   @param Alpha The alpha value for adjusting the result (0-255).\nvoid BlendPixels(struct PIXEL* desPixel, U32 pix2, U8 Alpha)\n{\n    double b1, g1, r1, a1, b2, g2, r2, a2;\n    double Alpha1, Alpha2, Remainder, T1, T2, T3, T4;\n\n    // Convert input alpha to range 0.0 - 1.0\n    Alpha1 = Alpha / 255.0;\n\n    // Convert all the channels to have a range of 0.0 - 1.0\n    b1 = desPixel-\u003eBlue / 255.0;\n    g1 = desPixel-\u003eGreen / 255.0;\n    r1 = desPixel-\u003eRed / 255.0;\n    a1 = desPixel-\u003eAlpha / 255.0;\n\n    b2 = ((pix2 \u003e\u003e (8 * offsetof(struct PIXEL, Blue))) \u0026 0xFF) / 255.0;\n    g2 = ((pix2 \u003e\u003e (8 * offsetof(struct PIXEL, Green))) \u0026 0xFF) / 255.0;\n    r2 = ((pix2 \u003e\u003e (8 * offsetof(struct PIXEL, Red))) \u0026 0xFF) / 255.0;\n    a2 = ((pix2 \u003e\u003e (8 * offsetof(struct PIXEL, Alpha))) \u0026 0xFF) / 255.0;\n\n    // Get the percentage of the source alpha from the user-based alpha and get the remainder\n    Alpha2 = Alpha1 / 1.0;\n    Alpha2 *= a2;\n    Remainder = 1.0 - Alpha2;\n\n    // Save the results in T3 and T4\n    T3 = Remainder;\n    T4 = Alpha2;\n\n    // Adjust the remainder from the destination alpha\n    Remainder *= a1;\n    Remainder /= 1.0;\n\n    // Calculate the new remainder and adjust for the source channels\n    Alpha2 += (T3 - Remainder);\n\n    // Calculate the RGB channels\n    T1 = r1 * Remainder;\n    T2 = r2 * Alpha2;\n    desPixel-\u003eRed = (U8)round(((T1 + T2) / 1.0) * 255.0);\n\n    T1 = g1 * Remainder;\n    T2 = g2 * Alpha2;\n    desPixel-\u003eGreen = (U8)round(((T1 + T2) / 1.0) * 255.0);\n\n    T1 = b1 * Remainder;\n    T2 = b2 * Alpha2;\n    desPixel-\u003eBlue = (U8)round(((T1 + T2) / 1.0) * 255.0);\n\n    // Calculate the new alpha channel\n    desPixel-\u003eAlpha = (U8)round(((a1 + T4 * (1.0 - a1) / 1.0)) * 255.0);\n}\n```\n\n## Contact Me\n\nIf you have questions you can contact me at [sullewarehouse@gmail.com](mailto:sullewarehouse@gmail.com)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb-sullender%2Fblend-pixels","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb-sullender%2Fblend-pixels","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb-sullender%2Fblend-pixels/lists"}