Logo Search packages:      
Sourcecode: f-spot version File versions  Download package

void TagLib::Jpeg::File::ReadDQTSegment ( int  length  )  [inline, private]

Reads the DQT Segment, and Guesstimate the image quality from it.

Parameters:
length The length of the segment that will be read

Definition at line 684 of file File.cs.

References TagLib::File::ReadBlock(), and TagLib::ByteVector::ToUShort().

            {
                  // See CCITT Rec. T.81 (1992 E), B.2.4.1 (p39) for DQT syntax
                  while (length > 0) {

                        byte pqtq = ReadBlock (1)[0]; length --;
                        byte pq = (byte)(pqtq >> 4);  //0 indicates 8-bit Qk, 1 indicates 16-bit Qk
                        byte tq = (byte)(pqtq & 0x0f);      //table index;
                        int [] table = null;
                        switch (tq) {
                        case 0:
                              table = Table.StandardLuminanceQuantization;
                              break;
                        case 1:
                              table = Table.StandardChrominanceQuantization;
                              break;
                        }

                        bool allones = true; //check for all-ones tables (q=100)
                        double cumsf = 0.0;
                        //double cumsf2 = 0.0;
                        for (int row = 0; row < 8; row ++) {
                              for (int col = 0; col < 8; col++) {
                                    ushort val = ReadBlock (pq == 1 ? 2 : 1).ToUShort (); length -= (pq + 1);
                                    if (table != null) {
                                          double x = 100.0 * (double)val / (double)table [row*8+col]; //Scaling factor in percent
                                          cumsf += x;
                                          //cumsf2 += x*x;
                                          allones = allones && (val == 1);
                                    }
                              }
                        }

                        if (table != null) {
                              double local_q;
                              cumsf /= 64.0;          // mean scale factor
                              //cumfs2 /= 64.0;
                              //double variance = cumsf2 - (cumsf * cumsf);

                              if (allones)
                                    local_q = 100.0;
                              else if (cumsf <= 100.0)
                                    local_q = (200.0 - cumsf) / 2.0;
                              else
                                    local_q = 5000.0 / cumsf;
                              quality = Math.Max (quality, (int)local_q);
                        }
                  }
            }


Generated by  Doxygen 1.6.0   Back to index