~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to libs/dimg/loaders/ppmloader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
{
62
62
 
63
63
PPMLoader::PPMLoader(DImg* image)
64
 
         : DImgLoader(image)
 
64
    : DImgLoader(image)
65
65
{
66
66
}
67
67
 
68
 
bool PPMLoader::load(const QString& filePath, DImgLoaderObserver *observer)
 
68
bool PPMLoader::load(const QString& filePath, DImgLoaderObserver* observer)
69
69
{
70
70
    //TODO: progress information
71
71
    int  width, height, rgbmax;
72
72
    char nl;
73
73
 
74
 
    FILE *file = fopen(QFile::encodeName(filePath), "rb");
 
74
    FILE* file = fopen(QFile::encodeName(filePath), "rb");
 
75
 
75
76
    if (!file)
76
77
    {
77
78
        kDebug() << "Cannot open image file.";
90
91
    }
91
92
 
92
93
    uchar* c = (uchar*) &header;
 
94
 
93
95
    if (*c != 'P')
94
96
    {
95
97
        kDebug() << "Not a PPM file.";
99
101
    }
100
102
 
101
103
    ++c;
 
104
 
102
105
    if (*c != '6')
103
106
    {
104
107
        kDebug() << "Not a PPM file.";
126
129
    }
127
130
 
128
131
    if (observer)
 
132
    {
129
133
        observer->progressInfo(m_image, 0.1F);
 
134
    }
130
135
 
131
 
    unsigned short *data = 0;
 
136
    unsigned short* data = 0;
132
137
 
133
138
    if (m_loadFlags & LoadImageData)
134
139
    {
135
140
        data = new_short_failureTolerant(width*height*4);
 
141
 
136
142
        if (!data)
137
143
        {
138
144
            kDebug() << "Failed to allocate memory for loading" << filePath;
141
147
            return false;
142
148
        }
143
149
 
144
 
        unsigned short *dst  = data;
 
150
        unsigned short* dst  = data;
145
151
        uchar src[6];
146
152
        float fac = 65535.0 / rgbmax;
147
153
        int checkpoint = 0;
148
154
 
149
 
    #ifdef ENABLE_DEBUG_MESSAGES
 
155
#ifdef ENABLE_DEBUG_MESSAGES
150
156
        kDebug() << "rgbmax=" << rgbmax << "  fac=" << fac;
151
 
    #endif
 
157
#endif
152
158
 
153
159
        for (int h = 0; h < height; ++h)
154
160
        {
156
162
            if (observer && h == checkpoint)
157
163
            {
158
164
                checkpoint += granularity(observer, height, 0.9F);
 
165
 
159
166
                if (!observer->continueQuery(m_image))
160
167
                {
161
168
                    delete [] data;
163
170
                    loadingFailed();
164
171
                    return false;
165
172
                }
 
173
 
166
174
                observer->progressInfo(m_image, 0.1 + (0.9 * ( ((float)h)/((float)height) )));
167
175
            }
168
176