BitMiracle.Tiff2Pdf.T2P.process_jpeg_strip C# (CSharp) 메소드

process_jpeg_strip() 개인적인 정적인 메소드

private static process_jpeg_strip ( byte strip, int striplength, byte buffer, int &bufferoffset, int stripCount, int no, int height ) : bool
strip byte
striplength int
buffer byte
bufferoffset int
stripCount int
no int
height int
리턴 bool
        private static bool process_jpeg_strip(byte[] strip, int striplength, byte[] buffer, ref int bufferoffset, int stripCount, int no, int height)
        {
            int i = 1;
            while (i < striplength)
            {
                switch (strip[i])
                {
                    case 0xd8:
                        i += 2;
                        break;

                    case 0xc0:
                    case 0xc1:
                    case 0xc3:
                    case 0xc9:
                    case 0xca:
                        if (no == 0)
                        {
                            Buffer.BlockCopy(strip, i - 1, buffer, bufferoffset, strip[i + 2] + 2);

                            short v_samp = 1;
                            short h_samp = 1;
                            for (int j = 0; j < buffer[bufferoffset + 9]; j++)
                            {
                                if ((buffer[bufferoffset + 11 + (2 * j)] >> 4) > h_samp)
                                    h_samp = (short)(buffer[bufferoffset + 11 + (2 * j)] >> 4);

                                if ((buffer[bufferoffset + 11 + (2 * j)] & 0x0f) > v_samp)
                                    v_samp = (short)(buffer[bufferoffset + 11 + (2 * j)] & 0x0f);
                            }

                            v_samp *= 8;
                            h_samp *= 8;
                            short ri = (short)((((buffer[bufferoffset + 5] << 8) | buffer[bufferoffset + 6]) + v_samp - 1) / v_samp);
                            ri *= (short)((((buffer[bufferoffset + 7] << 8) | buffer[bufferoffset + 8]) + h_samp - 1) / h_samp);
                            buffer[bufferoffset + 5] = (byte)((height >> 8) & 0xff);
                            buffer[bufferoffset + 6] = (byte)(height & 0xff);
                            bufferoffset += strip[i + 2] + 2;
                            i += strip[i + 2] + 2;

                            if (stripCount > 1)
                            {
                                buffer[bufferoffset++] = 0xff;
                                buffer[bufferoffset++] = 0xdd;
                                buffer[bufferoffset++] = 0x00;
                                buffer[bufferoffset++] = 0x04;
                                buffer[bufferoffset++] = (byte)((ri >> 8) & 0xff);
                                buffer[bufferoffset++] = (byte)(ri & 0xff);
                            }
                        }
                        else
                        {
                            i += strip[i + 2] + 2;
                        }
                        break;

                    case 0xc4:
                    case 0xdb:
                        if (no == 0)
                        {
                            Buffer.BlockCopy(strip, i - 1, buffer, bufferoffset, strip[i + 2] + 2);
                            bufferoffset += strip[i + 2] + 2;
                        }
                        i += strip[i + 2] + 2;
                        break;

                    case 0xda:
                        if (no == 0)
                        {
                            Buffer.BlockCopy(strip, i - 1, buffer, bufferoffset, strip[i + 2] + 2);
                            bufferoffset += strip[i + 2] + 2;
                            i += strip[i + 2] + 2;
                        }
                        else
                        {
                            buffer[bufferoffset++] = 0xff;
                            buffer[bufferoffset++] = (byte)(0xd0 | ((no - 1) % 8));
                            i += strip[i + 2] + 2;
                        }

                        Buffer.BlockCopy(strip, i - 1, buffer, bufferoffset, striplength - i - 1);
                        bufferoffset += striplength - i - 1;
                        return true;

                    default:
                        i += strip[i + 2] + 2;
                        break;
                }
            }

            return false;
        }