Im trying to change this program its item editor for sprites in size 32x32px in i want to swap from 32x32px to 64px x 64px
I have something like this
public const byte DefaultSize = 32;
public const ushort RGBPixelsDataSize = 3072; // 32*32*3
public const ushort ARGBPixelsDataSize = 4096; // 32*32*4
i changed to
public const byte DefaultSize = 64;
public const ushort RGBPixelsDataSize = 12288; // 64*64*3
public const ushort ARGBPixelsDataSize = 16384; // 64*64*4
next
i in 32 version i have
for (int y = 0; y < Sprite.DefaultSize; ++y)
{
for (int x = 0; x < Sprite.DefaultSize; ++x)
{
rgbaData[128 * y + x * 4 + 0] = rgbData[(32 - y - 1) * 96 + x * 3 + 2]; // blue
rgbaData[128 * y + x * 4 + 1] = rgbData[(32 - y - 1) * 96 + x * 3 + 1]; // green
rgbaData[128 * y + x * 4 + 2] = rgbData[(32 - y - 1) * 96 + x * 3 + 0]; // red
rgbaData[128 * y + x * 4 + 3] = 0;
}
}
so i have now question:
i should change to ?
i don't know how to calculate this
for (int y = 0; y < Sprite.DefaultSize; ++y)
{
for (int x = 0; x < Sprite.DefaultSize; ++x)
{
rgbaData[256 * y + x * 4 + 0] = rgbData[(64 - y - 1) * 192 + x * 3 + 2]; // blue
rgbaData[256 * y + x * 4 + 1] = rgbData[(64 - y - 1) * 192 + x * 3 + 1]; // green
rgbaData[256 * y + x * 4 + 2] = rgbData[(64 - y - 1) * 192 + x * 3 + 0]; // red
rgbaData[256 * y + x * 4 + 3] = 0;
}
}
I trying with 256, and program work but saved ARGB is black or transparent im not sure. RGB is working property properly. I can se image in RGB. but nor in ARGB ...
and this
for (int i = 0; i < chunkSize; ++i)
{
// Transparent pixel
rgb32x32x3[96 * y + x * 3 + 0] = transparentColor;
rgb32x32x3[96 * y + x * 3 + 1] = transparentColor;
rgb32x32x3[96 * y + x * 3 + 2] = transparentColor;
x++;
if (x >= 32)
{
x = 0;
++y;
}
}
change to
for (int i = 0; i < chunkSize; ++i)
{
// Transparent pixel
rgb32x32x3[192 * y + x * 3 + 0] = transparentColor;
rgb32x32x3[192 * y + x * 3 + 1] = transparentColor;
rgb32x32x3[192 * y + x * 3 + 2] = transparentColor;
x++;
if (x >= 64)
{
x = 0;
++y;
}
}
How to calculate argbData?
It will help to understand how image pixels are stored. Each pixel is 4 bytes in rgba, and 3 bytes in rgb. Pixels are stored row major. The number of bytes in each row of pixels is called the 'stride'. In this case the stride is
imageWidth * bytesPerPixel, but it does not have to be, for most image formats the stride is an explicit image parameter.So
breaks down int
<stride> * y + x * <bytesPerPixel> + <channel>The
(32 - y - 1)part will cause the rows to be mirrored in the horizontal plane. I.e. The bottom row of the input will be copied to the top row of the output. The different channels will also change the image from BGR to RGB, or vice versa.This looks highly suspect to me, since it will presumably set the alpha channel to zero, i.e. fully transparent, and that just seem wrong to me.
I'm not sure what the specific purpose of your program is, as far as I can see it is a correct conversion from 32x32 images to 64x64 images. But if the only purpose is to convert from RGB to RGBA it should probably set the Alpha channel to fully visible, and not do anything like flipping rgb-order or mirroring the image. So I would check that the pixel format of the output buffer is correct.
I would also suggest writing code that is size agnostic, i.e. take the image size as a parameter rather than hard coding values.If you are unsure about the order the rgba values should be in, try setting a channel to byte.MaxValue, and verify with a image editing program that the correct channel was affected. I'm often confused about the order of the channels myself, it does not help that some places use RGB and some use BGR to mean the same exact thing.