473,385 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

algorith LZX's variation?

Hello, I would like to know if someone can help me to do a bookshop for unpack a few files of textures or at least, that it(he,she) throws a bit of light and indicates me like to begin.
Pardon for the translations of goolge, they are pernicious...
4 bytes - Magic ('RSC')
4 bytes - Type (version - textures has "7")
4 bytes - Flags
From 'flags' value can be calculated sizes of SysSegment and GpuSegment of unpacked data.
Delphi:
Expand|Select|Wrap|Line Numbers
  1. CpuSegSiz := (flags and $7FF) shl (((flags shr 11) and $F) + 8);
  2.   GpuSegSiz := ((flags shr 15) and $7FF) shl (((flags shr 26) and $F) +  8);
C#:
Expand|Select|Wrap|Line Numbers
  1. uint systemSegSize = (flags & 0x7FF) << (((flags >> 11)  & 0xF) + 8);
  2. uint gpuSegSize = ((flags >> 15) & 0x7FF)  << (((flags >> 26) & 0xF) + 8);
. Here it is archive which includes three examples of texture RSC.
http://www.sendspace.com/file/u4dk34
I believe that the compression is LZX's variation.
Thanks
Apr 1 '10 #1

✓ answered by RedSon


10 2927
So... I do not understand what it wants to say...
Nevertheless, you are moderating, it moves or delete the post because really I do not understand what it wants to say. The translator is not very good.

Edit:OH I am sorry, now I realize that it is repeated. Do not be since it has happenedand I do not know like edit it and erase it.
I am sorry, it will not return to happen.
Apr 1 '10 #2
RedSon
5,000 Expert 4TB
You are using a translation software? That would explain why your question is unclear. I guess I didn't read that in your original post.

I do not understand your words "bookshop". I think I understand what "unpack a few files" means but I do not understand "throws a bit of light and indicates me like to begin". I think you mean "shed a little light on my question and help me understand how to begin" but I am not sure.

That website address is a link to a "rar" of textures? What do you want to do with it? Decompress it into something that you can use?

What exactly is your question?
Apr 1 '10 #3
"throws a bit of light and indicates me like to begin" Yes, I believe that it is it what I want to say
"bookshop"=Library?,Dll?
The link is a "rar" of the files that I want to open or unpak, the format is .XTD.
They are textures of a game, attempt to open them and to change them into my textures for personal use but only I know of code what I have written.
If it is out of the procedure of the forum since the post resigns and I sit it (Sorry?)
Apr 1 '10 #4
RedSon
5,000 Expert 4TB
You can try one of these tools:

http://www.gtamodding.com/index.php?...exture_archive
Apr 1 '10 #5
Already I have proved all. None they open it. Only they open the format .WTD and not the format .XTD because of it I asked it of the algorithm because I have seen in sites that they could have opened by the codes that exist post doing a library in C# but nobody says anything to me. Well, do not worry for the post thank you anyhow.
( Probably do not answer because with the translator they do not understand what I want to say...)
Apr 1 '10 #6
RedSon
5,000 Expert 4TB
I get what you want. I don't think it is possible. The game makers intentionally make it difficult for you to steal their game resources. Even games that are defunct are difficult. You would need their proprietary tools to open the files.
Apr 1 '10 #7
In a forum I found a person who managed to open the file and in a little time with the information that I put but to disappear of the forum and it does not answer to the message that I sent. There will be people who him is easy and other one that him is difficult according to the custom that has of working with this type of things.
It has to be difficult enough.
In addition, do not worry, thank you for your help, I do not want to seem to be heavy and you prop, this post always is above and probably not this giving the opportunity to other user's to expose his problems.
Quote from AnthonyFiveSixTwo:
"Well today I got around to looking at the xtd files that were posted and I was able to decompress them. I will make a tool to do it later on once we get a bit more info on the actual format of the decompressed data.
Im kinda tired right now but maybe tomorrow ill post some more info."

I repeat: I am sorry to entertain him so much with this topic
Apr 1 '10 #8
RedSon
5,000 Expert 4TB
Hopefully AnthonyFiveSixTwo will be able to help you then.
Apr 1 '10 #9
Impossible already, the post is of August, 2009... Llebo enough time looking now that I realize...
Apr 1 '10 #10
Sorry double post, i canīt edit it.
I have found this in code of a program that serves to open .WTD but that originally was opening .XTD. Archives are in Big endian
Will it use me as something?
It is that have a lot of time looking for the way of opening the files and if the codes serve me, I itself will try to learn to programme though almost all the tutorials are in English...
I sit such a long post.
Expand|Select|Wrap|Line Numbers
  1. using System.IO;
  2.  
  3. namespace RageLib.Common.Resources
  4. {
  5.     internal class ResourceHeader
  6.     {
  7.         private const uint MagicBigEndian = 0x52534305;
  8.         public const uint MagicValue = 0x05435352;
  9.  
  10.         public uint Magic { get; set; }
  11.         public ResourceType Type { get; set; }
  12.         public uint Flags { get; set; }
  13.         public CompressionType CompressCodec { get; set; }
  14.  
  15.         public int GetSystemMemSize()
  16.         {
  17.             return (int)(Flags & 0x7FF) << (int)(((Flags >> 11) & 0xF) + 8);
  18.         }
  19.  
  20.         public int GetGraphicsMemSize()
  21.         {
  22.             return (int)((Flags >> 15) & 0x7FF) << (int)(((Flags >> 26) & 0xF) + 8);
  23.         }
  24.  
  25.         public void SetMemSizes(int systemMemSize, int graphicsMemSize)
  26.         {
  27.             // gfx = a << (b + 8)
  28.             // minimum representable is block of 0x100 bytes
  29.  
  30.             const int maxA = 0x3F;
  31.  
  32.             int sysA = systemMemSize >> 8;
  33.             int sysB = 0;
  34.  
  35.             while(sysA > maxA)
  36.             {
  37.                 if ((sysA & 1) != 0)
  38.                 {
  39.                     sysA += 2;
  40.                 }
  41.                 sysA >>= 1;
  42.                 sysB++;
  43.             }
  44.  
  45.             int gfxA = graphicsMemSize >> 8;
  46.             int gfxB = 0;
  47.  
  48.             while (gfxA > maxA)
  49.             {
  50.                 if ((gfxA & 1) != 0)
  51.                 {
  52.                     gfxA += 2;
  53.                 }
  54.                 gfxA >>= 1;
  55.                 gfxB++;
  56.             }
  57.  
  58.             Flags = (Flags & 0xC0000000) | (uint)(sysA | (sysB << 11) | (gfxA << 15) | (gfxB << 26));
  59.         }
  60.  
  61.         public void Read(BinaryReader br)
  62.         {
  63.             Magic = br.ReadUInt32();
  64.             Type = (ResourceType) br.ReadUInt32();
  65.             Flags = br.ReadUInt32();
  66.             CompressCodec = (CompressionType)br.ReadUInt16();
  67.  
  68.             if (Magic == MagicBigEndian)
  69.             {
  70.                 Magic = DataUtil.SwapEndian(Magic);
  71.                 Type = (ResourceType)DataUtil.SwapEndian((uint)Type);
  72.                 Flags = DataUtil.SwapEndian(Flags);
  73.             }
  74.         }
  75.  
  76.         public void Write(BinaryWriter bw)
  77.         {
  78.             bw.Write( MagicValue );
  79.             bw.Write( (uint)Type );
  80.             bw.Write( Flags );
  81.             bw.Write( (ushort)CompressCodec );
  82.         }
  83.     }
  84. }
Expand|Select|Wrap|Line Numbers
  1. using System.Reflection;
  2.  
  3. namespace RageLib.Common.Resources
  4. {
  5.     [Obfuscation(StripAfterObfuscation = true, ApplyToMembers = true, Exclude = true)]
  6.     public enum ResourceType
  7.     {
  8.         TextureXBOX = 0x7, // xtd
  9.         ModelXBOX = 0x6D, // xdr
  10.         Generic = 0x01, // xhm / xad (Generic files as rsc?)
  11.         Bounds = 0x20, // xbd, wbd
  12.         Particles = 0x24, // xpfl
  13.         Particles2 = 0x1B, // xpfl
  14.  
  15.         Texture = 0x8, // wtd
  16.         Model = 0x6E, // wdr
  17.         ModelFrag = 0x70, //wft
Expand|Select|Wrap|Line Numbers
  1. // Uncomment the following line to get this Decoder to work for XBOX360 DXT Encoded files
  2. // Note that the data has to be untiled before running the decoder on it
  3.  
  4. //#define XBOX360
  5.  
  6. using System;
  7.  
  8. namespace RageLib.Textures.Decoder
  9. {
  10.     internal static class DXTDecoder
  11.     {
  12.         internal static byte[] DecodeDXT1(byte[] data, int width, int height)
  13.         {
  14.             byte[] pixData = new byte[width * height * 4];
  15.             int xBlocks = width / 4;
  16.             int yBlocks = height / 4;
  17.             for (int y = 0; y < yBlocks; y++)
  18.             {
  19.                 for (int x = 0; x < xBlocks; x++)
  20.                 {
  21.                     int blockDataStart = ((y * xBlocks) + x) * 8;
  22.  
  23. #if XBOX360
  24.                     uint color0 = ((uint)data[blockDataStart + 0] << 8) + data[blockDataStart + 1];
  25.                     uint color1 = ((uint)data[blockDataStart + 2] << 8) + data[blockDataStart + 3];
  26. #else
  27.                     uint color0 = BitConverter.ToUInt16(data, blockDataStart);
  28.                     uint color1 = BitConverter.ToUInt16(data, blockDataStart + 2);
  29. #endif
  30.  
  31.                     uint code = BitConverter.ToUInt32(data, blockDataStart + 4);
  32.  
  33.                     ushort r0 = 0, g0 = 0, b0 = 0, r1 = 0, g1 = 0, b1 = 0;
  34.                     r0 = (ushort)(8 * (color0 & 31));
  35.                     g0 = (ushort)(4 * ((color0 >> 5) & 63));
  36.                     b0 = (ushort)(8 * ((color0 >> 11) & 31));
  37.  
  38.                     r1 = (ushort)(8 * (color1 & 31));
  39.                     g1 = (ushort)(4 * ((color1 >> 5) & 63));
  40.                     b1 = (ushort)(8 * ((color1 >> 11) & 31));
  41.  
  42.                     for (int k = 0; k < 4; k++)
  43.                     {
  44. #if XBOX360
  45.                         int j = k ^ 1;
  46. #else
  47.                         int j = k;
  48. #endif
  49.  
  50.                         for (int i = 0; i < 4; i++)
  51.                         {
  52.                             int pixDataStart = (width * (y * 4 + j) * 4) + ((x * 4 + i) * 4);
  53.                             uint codeDec = code & 0x3;
  54.  
  55.                             switch (codeDec)
  56.                             {
  57.                                 case 0:
  58.                                     pixData[pixDataStart + 0] = (byte)r0;
  59.                                     pixData[pixDataStart + 1] = (byte)g0;
  60.                                     pixData[pixDataStart + 2] = (byte)b0;
  61.                                     pixData[pixDataStart + 3] = 255;
  62.                                     break;
  63.                                 case 1:
  64.                                     pixData[pixDataStart + 0] = (byte)r1;
  65.                                     pixData[pixDataStart + 1] = (byte)g1;
  66.                                     pixData[pixDataStart + 2] = (byte)b1;
  67.                                     pixData[pixDataStart + 3] = 255;
  68.                                     break;
  69.                                 case 2:
  70.                                     pixData[pixDataStart + 3] = 255;
  71.                                     if (color0 > color1)
  72.                                     {
  73.                                         pixData[pixDataStart + 0] = (byte)((2 * r0 + r1) / 3);
  74.                                         pixData[pixDataStart + 1] = (byte)((2 * g0 + g1) / 3);
  75.                                         pixData[pixDataStart + 2] = (byte)((2 * b0 + b1) / 3);
  76.                                     }
  77.                                     else
  78.                                     {
  79.                                         pixData[pixDataStart + 0] = (byte)((r0 + r1) / 2);
  80.                                         pixData[pixDataStart + 1] = (byte)((g0 + g1) / 2);
  81.                                         pixData[pixDataStart + 2] = (byte)((b0 + b1) / 2);
  82.                                     }
  83.                                     break;
  84.                                 case 3:
  85.                                     if (color0 > color1)
  86.                                     {
  87.                                         pixData[pixDataStart + 0] = (byte)((r0 + 2 * r1) / 3);
  88.                                         pixData[pixDataStart + 1] = (byte)((g0 + 2 * g1) / 3);
  89.                                         pixData[pixDataStart + 2] = (byte)((b0 + 2 * b1) / 3);
  90.                                         pixData[pixDataStart + 3] = 255;
  91.                                     }
  92.                                     else
  93.                                     {
  94.                                         pixData[pixDataStart + 0] = 0;
  95.                                         pixData[pixDataStart + 1] = 0;
  96.                                         pixData[pixDataStart + 2] = 0;
  97.                                         pixData[pixDataStart + 3] = 0;
  98.                                     }
  99.                                     break;
  100.                             }
  101.  
  102.                             code >>= 2;
  103.                         }
  104.                     }
  105.  
  106.  
  107.                 }
  108.             }
  109.             return pixData;
  110.         }
  111.  
  112.         internal static byte[] DecodeDXT3(byte[] data, int width, int height)
  113.         {
  114.             byte[] pixData = new byte[width * height * 4];
  115.             int xBlocks = width / 4;
  116.             int yBlocks = height / 4;
  117.             for (int y = 0; y < yBlocks; y++)
  118.             {
  119.                 for (int x = 0; x < xBlocks; x++)
  120.                 {
  121.                     int blockDataStart = ((y * xBlocks) + x) * 16;
  122.                     ushort[] alphaData = new ushort[4];
  123.  
  124. #if XBOX360
  125.                     alphaData[0] = (ushort)((data[blockDataStart + 0] << 8) + data[blockDataStart + 1]);
  126.                     alphaData[1] = (ushort)((data[blockDataStart + 2] << 8) + data[blockDataStart + 3]);
  127.                     alphaData[2] = (ushort)((data[blockDataStart + 4] << 8) + data[blockDataStart + 5]);
  128.                     alphaData[3] = (ushort)((data[blockDataStart + 6] << 8) + data[blockDataStart + 7]);
  129. #else
  130.                     alphaData[0] = BitConverter.ToUInt16(data, blockDataStart + 0);
  131.                     alphaData[1] = BitConverter.ToUInt16(data, blockDataStart + 2);
  132.                     alphaData[2] = BitConverter.ToUInt16(data, blockDataStart + 4);
  133.                     alphaData[3] = BitConverter.ToUInt16(data, blockDataStart + 6);
  134. #endif
  135.  
  136.                     byte[,] alpha = new byte[4, 4];
  137.                     for (int j = 0; j < 4; j++)
  138.                     {
  139.                         for (int i = 0; i < 4; i++)
  140.                         {
  141.                             alpha[i, j] = (byte)((alphaData[j] & 0xF) * 16);
  142.                             alphaData[j] >>= 4;
  143.                         }
  144.                     }
  145.  
  146. #if XBOX360
  147.                     ushort color0 = (ushort)((data[blockDataStart + 8] << 8) + data[blockDataStart + 9]);
  148.                     ushort color1 = (ushort)((data[blockDataStart + 10] << 8) + data[blockDataStart + 11]);
  149. #else
  150.                     ushort color0 = BitConverter.ToUInt16(data, blockDataStart + 8);
  151.                     ushort color1 = BitConverter.ToUInt16(data, blockDataStart + 8 + 2);
  152. #endif
  153.  
  154.                     uint code = BitConverter.ToUInt32(data, blockDataStart + 8 + 4);
  155.  
  156.                     ushort r0 = 0, g0 = 0, b0 = 0, r1 = 0, g1 = 0, b1 = 0;
  157.                     r0 = (ushort)(8 * (color0 & 31));
  158.                     g0 = (ushort)(4 * ((color0 >> 5) & 63));
  159.                     b0 = (ushort)(8 * ((color0 >> 11) & 31));
  160.  
  161.                     r1 = (ushort)(8 * (color1 & 31));
  162.                     g1 = (ushort)(4 * ((color1 >> 5) & 63));
  163.                     b1 = (ushort)(8 * ((color1 >> 11) & 31));
  164.  
  165.                     for (int k = 0; k < 4; k++)
  166.                     {
  167. #if XBOX360
  168.                         int j = k ^ 1;
  169. #else
  170.                         int j = k;
  171. #endif
  172.  
  173.                         for (int i = 0; i < 4; i++)
  174.                         {
  175.                             int pixDataStart = (width * (y * 4 + j) * 4) + ((x * 4 + i) * 4);
  176.                             uint codeDec = code & 0x3;
  177.  
  178.                             pixData[pixDataStart + 3] = alpha[i, j];
  179.  
  180.                             switch (codeDec)
  181.                             {
  182.                                 case 0:
  183.                                     pixData[pixDataStart + 0] = (byte)r0;
  184.                                     pixData[pixDataStart + 1] = (byte)g0;
  185.                                     pixData[pixDataStart + 2] = (byte)b0;
  186.                                     break;
  187.                                 case 1:
  188.                                     pixData[pixDataStart + 0] = (byte)r1;
  189.                                     pixData[pixDataStart + 1] = (byte)g1;
  190.                                     pixData[pixDataStart + 2] = (byte)b1;
  191.                                     break;
  192.                                 case 2:
  193.                                     if (color0 > color1)
  194.                                     {
  195.                                         pixData[pixDataStart + 0] = (byte)((2 * r0 + r1) / 3);
  196.                                         pixData[pixDataStart + 1] = (byte)((2 * g0 + g1) / 3);
  197.                                         pixData[pixDataStart + 2] = (byte)((2 * b0 + b1) / 3);
  198.                                     }
  199.                                     else
  200.                                     {
  201.                                         pixData[pixDataStart + 0] = (byte)((r0 + r1) / 2);
  202.                                         pixData[pixDataStart + 1] = (byte)((g0 + g1) / 2);
  203.                                         pixData[pixDataStart + 2] = (byte)((b0 + b1) / 2);
  204.                                     }
  205.                                     break;
  206.                                 case 3:
  207.                                     if (color0 > color1)
  208.                                     {
  209.                                         pixData[pixDataStart + 0] = (byte)((r0 + 2 * r1) / 3);
  210.                                         pixData[pixDataStart + 1] = (byte)((g0 + 2 * g1) / 3);
  211.                                         pixData[pixDataStart + 2] = (byte)((b0 + 2 * b1) / 3);
  212.                                     }
  213.                                     else
  214.                                     {
  215.                                         pixData[pixDataStart + 0] = 0;
  216.                                         pixData[pixDataStart + 1] = 0;
  217.                                         pixData[pixDataStart + 2] = 0;
  218.                                     }
  219.                                     break;
  220.                             }
  221.  
  222.                             code >>= 2;
  223.                         }
  224.                     }
  225.  
  226.  
  227.                 }
  228.             }
  229.             return pixData;
  230.         }
  231.  
  232.         internal static byte[] DecodeDXT5(byte[] data, int width, int height)
  233.         {
  234.             byte[] pixData = new byte[width * height * 4];
  235.             int xBlocks = width / 4;
  236.             int yBlocks = height / 4;
  237.             for (int y = 0; y < yBlocks; y++)
  238.             {
  239.                 for (int x = 0; x < xBlocks; x++)
  240.                 {
  241.                     int blockDataStart = ((y * xBlocks) + x) * 16;
  242.                     uint[] alphas = new uint[8];
  243.                     ulong alphaMask = 0;
  244.  
  245. #if XBOX360
  246.  
  247.                     alphas[0] = data[blockDataStart + 1];
  248.                     alphas[1] = data[blockDataStart + 0];
  249.  
  250.                     alphaMask |= data[blockDataStart + 6];
  251.                     alphaMask <<= 8;
  252.                     alphaMask |= data[blockDataStart + 7];
  253.                     alphaMask <<= 8;
  254.                     alphaMask |= data[blockDataStart + 4];
  255.                     alphaMask <<= 8;
  256.                     alphaMask |= data[blockDataStart + 5];
  257.                     alphaMask <<= 8;
  258.                     alphaMask |= data[blockDataStart + 2];
  259.                     alphaMask <<= 8;
  260.                     alphaMask |= data[blockDataStart + 3];
  261.  
  262. #else
  263.  
  264.                     alphas[0] = data[blockDataStart + 0];
  265.                     alphas[1] = data[blockDataStart + 1];
  266.  
  267.                     alphaMask |= data[blockDataStart + 7];
  268.                     alphaMask <<= 8;
  269.                     alphaMask |= data[blockDataStart + 6];
  270.                     alphaMask <<= 8;
  271.                     alphaMask |= data[blockDataStart + 5];
  272.                     alphaMask <<= 8;
  273.                     alphaMask |= data[blockDataStart + 4];
  274.                     alphaMask <<= 8;
  275.                     alphaMask |= data[blockDataStart + 3];
  276.                     alphaMask <<= 8;
  277.                     alphaMask |= data[blockDataStart + 2];
  278.  
  279. #endif
  280.  
  281.                     // 8-alpha or 6-alpha block
  282.                     if (alphas[0] > alphas[1])
  283.                     {
  284.                         // 8-alpha block: derive the other 6
  285.                         // Bit code 000 = alpha_0, 001 = alpha_1, others are interpolated.
  286.                         alphas[2] = (byte)((6 * alphas[0] + 1 * alphas[1] + 3) / 7);    // bit code 010
  287.                         alphas[3] = (byte)((5 * alphas[0] + 2 * alphas[1] + 3) / 7);    // bit code 011
  288.                         alphas[4] = (byte)((4 * alphas[0] + 3 * alphas[1] + 3) / 7);    // bit code 100
  289.                         alphas[5] = (byte)((3 * alphas[0] + 4 * alphas[1] + 3) / 7);    // bit code 101
  290.                         alphas[6] = (byte)((2 * alphas[0] + 5 * alphas[1] + 3) / 7);    // bit code 110
  291.                         alphas[7] = (byte)((1 * alphas[0] + 6 * alphas[1] + 3) / 7);    // bit code 111
  292.                     }
  293.                     else
  294.                     {
  295.                         // 6-alpha block.
  296.                         // Bit code 000 = alpha_0, 001 = alpha_1, others are interpolated.
  297.                         alphas[2] = (byte)((4 * alphas[0] + 1 * alphas[1] + 2) / 5);    // Bit code 010
  298.                         alphas[3] = (byte)((3 * alphas[0] + 2 * alphas[1] + 2) / 5);    // Bit code 011
  299.                         alphas[4] = (byte)((2 * alphas[0] + 3 * alphas[1] + 2) / 5);    // Bit code 100
  300.                         alphas[5] = (byte)((1 * alphas[0] + 4 * alphas[1] + 2) / 5);    // Bit code 101
  301.                         alphas[6] = 0x00;                                               // Bit code 110
  302.                         alphas[7] = 0xFF;                                               // Bit code 111
  303.                     }
  304.  
  305.                     byte[,] alpha = new byte[4, 4];
  306.  
  307.                     for (int i = 0; i < 4; i++)
  308.                     {
  309.                         for (int j = 0; j < 4; j++)
  310.                         {
  311.                             alpha[j, i] = (byte)alphas[alphaMask & 7];
  312.                             alphaMask >>= 3;
  313.                         }
  314.                     }
  315.  
  316. #if XBOX360
  317.                     ushort color0 = (ushort)((data[blockDataStart + 8] << 8) + data[blockDataStart + 9]);
  318.                     ushort color1 = (ushort)((data[blockDataStart + 10] << 8) + data[blockDataStart + 11]);
  319. #else
  320.                     ushort color0 = BitConverter.ToUInt16(data, blockDataStart + 8);
  321.                     ushort color1 = BitConverter.ToUInt16(data, blockDataStart + 8 + 2);
  322. #endif
  323.  
  324.                     uint code = BitConverter.ToUInt32(data, blockDataStart + 8 + 4);
  325.  
  326.                     ushort r0 = 0, g0 = 0, b0 = 0, r1 = 0, g1 = 0, b1 = 0;
  327.                     r0 = (ushort)(8 * (color0 & 31));
  328.                     g0 = (ushort)(4 * ((color0 >> 5) & 63));
  329.                     b0 = (ushort)(8 * ((color0 >> 11) & 31));
  330.  
  331.                     r1 = (ushort)(8 * (color1 & 31));
  332.                     g1 = (ushort)(4 * ((color1 >> 5) & 63));
  333.                     b1 = (ushort)(8 * ((color1 >> 11) & 31));
  334.  
  335.                     for (int k = 0; k < 4; k++)
  336.                     {
  337. #if XBOX360
  338.                         int j = k ^ 1;
  339. #else
  340.                         int j = k;
  341. #endif
  342.  
  343.                         for (int i = 0; i < 4; i++)
  344.                         {
  345.                             int pixDataStart = (width * (y * 4 + j) * 4) + ((x * 4 + i) * 4);
  346.                             uint codeDec = code & 0x3;
  347.  
  348.                             pixData[pixDataStart + 3] = alpha[i, j];
  349.  
  350.                             switch (codeDec)
  351.                             {
  352.                                 case 0:
  353.                                     pixData[pixDataStart + 0] = (byte)r0;
  354.                                     pixData[pixDataStart + 1] = (byte)g0;
  355.                                     pixData[pixDataStart + 2] = (byte)b0;
  356.                                     break;
  357.                                 case 1:
  358.                                     pixData[pixDataStart + 0] = (byte)r1;
  359.                                     pixData[pixDataStart + 1] = (byte)g1;
  360.                                     pixData[pixDataStart + 2] = (byte)b1;
  361.                                     break;
  362.                                 case 2:
  363.                                     if (color0 > color1)
  364.                                     {
  365.                                         pixData[pixDataStart + 0] = (byte)((2 * r0 + r1) / 3);
  366.                                         pixData[pixDataStart + 1] = (byte)((2 * g0 + g1) / 3);
  367.                                         pixData[pixDataStart + 2] = (byte)((2 * b0 + b1) / 3);
  368.                                     }
  369.                                     else
  370.                                     {
  371.                                         pixData[pixDataStart + 0] = (byte)((r0 + r1) / 2);
  372.                                         pixData[pixDataStart + 1] = (byte)((g0 + g1) / 2);
  373.                                         pixData[pixDataStart + 2] = (byte)((b0 + b1) / 2);
  374.                                     }
  375.                                     break;
  376.                                 case 3:
  377.                                     if (color0 > color1)
  378.                                     {
  379.                                         pixData[pixDataStart + 0] = (byte)((r0 + 2 * r1) / 3);
  380.                                         pixData[pixDataStart + 1] = (byte)((g0 + 2 * g1) / 3);
  381.                                         pixData[pixDataStart + 2] = (byte)((b0 + 2 * b1) / 3);
  382.                                     }
  383.                                     else
  384.                                     {
  385.                                         pixData[pixDataStart + 0] = 0;
  386.                                         pixData[pixDataStart + 1] = 0;
  387.                                         pixData[pixDataStart + 2] = 0;
  388.                                     }
  389.                                     break;
  390.                             }
  391.  
  392.                             code >>= 2;
  393.                         }
  394.                     }
  395.  
  396.  
  397.                 }
  398.             }
  399.             return pixData;
  400.         }
  401.  
  402.     }
  403. }
Apr 2 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: j0mbolar | last post by:
I would like to see what the majority of people prefer when it comes to elegance, clarity, etc. I'll present the problem first based on having a product, and one product only, at a given time...
0
by: Sakharam Phapale | last post by:
Hi All, I am developing my own text editor using RichTextBox control. I don't want to use RichTextBox Undo and Redo functions. Instead of that I want to develop my own algorithm for Undo & Redo,...
5
by: Eric | last post by:
I am implementing a variation on the Singleton design pattern, that allows up to 8 objects of a class to be instantiated, and returns a null pointer for anything more than 8. I am running into a...
4
by: Branka | last post by:
Hi I have 20 'for' loops to create more than 40 million variations with repetitions. More precisely: I have total of nine factors with three possible levels (3^9) and 11 factors with 2 possible...
27
by: karan.shashi | last post by:
Hey all, I was asked this question in an interview recently: Suppose you have the method signature bool MyPairSum(int array, int sum) the array has all unique values (no repeats), your...
26
by: Fraser Ross | last post by:
template <class OutputIterator, class Size, class T> void fill_n (OutputIterator first, Size n, const T& value) { while (n-- 0) *first++ = value; } If Size must be convertible to an integral...
1
by: spamtrap | last post by:
Hy; I've got a nasty variation of the Guillotine-bug on a three-column layout, sadly the variations of the Holly-hack I tried to apply don't work: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.