Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for RGBA in encode #251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion C/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It will be overwritten on the next call into the function, so be careful!
* `yComponents` - The number of components in the Y direction. Must be between 1 and 9. 3 to 5 is usually a good range for this.
* `width` - The width in pixels of the supplied image.
* `height` - The height in pixels of the supplied image.
* `rgb` - A pointer to the pixel data. This is supplied in RGB order, with 3 bytes per pixels.
* `rgb` - A pointer to the pixel data. This can either be RGB or RGBA.
* `bytesPerRow` - The number of bytes per row of the RGB pixel data.

## Usage as a command-line tool
Expand Down
8 changes: 5 additions & 3 deletions C/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ static float *multiplyBasisFunction(int xComponent, int yComponent, int width, i
float r = 0, g = 0, b = 0;
float normalisation = (xComponent == 0 && yComponent == 0) ? 1 : 2;

size_t channels = bytesPerRow / width;

for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
float basis = cosf(M_PI * xComponent * x / width) * cosf(M_PI * yComponent * y / height);
r += basis * sRGBToLinear(rgb[3 * x + 0 + y * bytesPerRow]);
g += basis * sRGBToLinear(rgb[3 * x + 1 + y * bytesPerRow]);
b += basis * sRGBToLinear(rgb[3 * x + 2 + y * bytesPerRow]);
r += basis * sRGBToLinear(rgb[channels * x + 0 + y * bytesPerRow]);
g += basis * sRGBToLinear(rgb[channels * x + 1 + y * bytesPerRow]);
b += basis * sRGBToLinear(rgb[channels * x + 2 + y * bytesPerRow]);
}
}

Expand Down