~suaweb/nginx/nginx-recipe

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/image/read_image.h

  • Committer: Frans Elliott
  • Date: 2015-06-12 21:15:13 UTC
  • Revision ID: mastergeek.elliott@gmail.com-20150612211513-un4vguj32deibvb0
Added the actual pagespeed library to the ngx_pagespeed module dir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Google Inc.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
// Author: Huibao Lin
 
18
 
 
19
#ifndef PAGESPEED_KERNEL_IMAGE_READ_IMAGE_H_
 
20
#define PAGESPEED_KERNEL_IMAGE_READ_IMAGE_H_
 
21
 
 
22
#include <cstddef>
 
23
#include "pagespeed/kernel/base/string.h"
 
24
#include "pagespeed/kernel/image/image_util.h"
 
25
#include "pagespeed/kernel/image/scanline_status.h"
 
26
 
 
27
namespace net_instaweb {
 
28
class MessageHandler;
 
29
}
 
30
 
 
31
namespace pagespeed {
 
32
 
 
33
namespace image_compression {
 
34
 
 
35
class MultipleFrameReader;
 
36
class MultipleFrameWriter;
 
37
class ScanlineReaderInterface;
 
38
class ScanlineWriterInterface;
 
39
 
 
40
using net_instaweb::MessageHandler;
 
41
 
 
42
////////// Scanline API
 
43
 
 
44
// TODO(huibao): Add an overload function
 
45
// CreateScanlineReader(const void* image_buffer, size_t buffer_length).
 
46
 
 
47
// Returns a scanline image reader. The following formats are supported:
 
48
// IMAGE_PNG, IMAGE_GIF, IMAGE_JPEG, and IMAGE_WEBP
 
49
ScanlineReaderInterface* CreateScanlineReader(ImageFormat image_type,
 
50
                                              const void* image_buffer,
 
51
                                              size_t buffer_length,
 
52
                                              MessageHandler* handler,
 
53
                                              ScanlineStatus* status);
 
54
 
 
55
inline ScanlineReaderInterface* CreateScanlineReader(ImageFormat image_type,
 
56
                                                     const void* image_buffer,
 
57
                                                     size_t buffer_length,
 
58
                                                     MessageHandler* handler) {
 
59
  ScanlineStatus status;
 
60
  return CreateScanlineReader(image_type, image_buffer, buffer_length,
 
61
                              handler, &status);
 
62
}
 
63
 
 
64
// Returns a scanline image writer. The following formats are
 
65
// supported: IMAGE_PNG, IMAGE_JPEG, and IMAGE_WEBP. This function
 
66
// also calls the InitWithStatus() and InitializeWriteWithStatus()
 
67
// methods of the writer.
 
68
ScanlineWriterInterface* CreateScanlineWriter(
 
69
    ImageFormat image_type,     // Type of the image to write
 
70
    PixelFormat pixel_format,   // Pixel format, RGB_888 etc
 
71
    size_t width,               // Width, in pixels, of the image
 
72
    size_t height,              // Height, in pixels, of the image
 
73
    const void* config,         // Configuration for the output image
 
74
    GoogleString* image_data,   // Output image
 
75
    MessageHandler* handler,    // Message handler
 
76
    ScanlineStatus* status);    // Status code
 
77
 
 
78
inline ScanlineWriterInterface* CreateScanlineWriter(ImageFormat image_type,
 
79
                                                     PixelFormat pixel_format,
 
80
                                                     size_t width,
 
81
                                                     size_t height,
 
82
                                                     const void* config,
 
83
                                                     GoogleString* image_data,
 
84
                                                     MessageHandler* handler) {
 
85
  ScanlineStatus status;
 
86
  return CreateScanlineWriter(image_type, pixel_format, width, height,
 
87
                              config, image_data, handler, &status);
 
88
}
 
89
 
 
90
////////// ImageFrame API
 
91
 
 
92
// Returns a MultipleFrameReader after calling its Initialize()
 
93
// method. The following formats are supported: IMAGE_PNG, IMAGE_GIF,
 
94
// IMAGE_JPEG, and IMAGE_WEBP.
 
95
//
 
96
// The caller retains ownership of 'image_buffer', 'handler', and
 
97
// 'status'.
 
98
MultipleFrameReader* CreateImageFrameReader(
 
99
    ImageFormat image_type,
 
100
    const void* image_buffer,
 
101
    size_t buffer_length,
 
102
    MessageHandler* handler,
 
103
    ScanlineStatus* status);
 
104
 
 
105
// Returns a new MultipleFrameWriter after calling its Initialize()
 
106
// method. The following formats are supported: IMAGE_PNG,
 
107
// IMAGE_JPEG, and IMAGE_WEBP.
 
108
//
 
109
// The caller retains ownership of 'config', 'image_data', 'handler',
 
110
// and 'status'.
 
111
MultipleFrameWriter* CreateImageFrameWriter(
 
112
    ImageFormat image_type,     // Type of the image to write
 
113
    const void* config,         // Configuration for the output image
 
114
    GoogleString* image_data,   // Image destination for future writer output
 
115
    MessageHandler* handler,    // Message handler
 
116
    ScanlineStatus* status);    // Status code
 
117
 
 
118
////////// Utilities
 
119
 
 
120
// Decode the image stream and return the image information. Use non-null
 
121
// pointers to retrieve the information you need, and use null pointers to
 
122
// ignore other information.
 
123
//
 
124
// If the input "pixels" is set to a null pointer, the function will finish
 
125
// quicker because the pixel data will not be decoded. If "pixel" is set to
 
126
// a non-null pointer, the function will return a buffer containning the pixel
 
127
// data. You are responsible for destroying the buffer using free().
 
128
//
 
129
// Arguments "width" and "height" indicate the number of pixels along the
 
130
// horizontal and vertical directions, respectively. Argument "stride" indicates
 
131
// the number of bytes between the starting points of adjacent rows. Garbage
 
132
// bytes may be padded to the end of rows in order to make "stride" a multiplier
 
133
// of 4.
 
134
//
 
135
// This function uses the scanline API and supports non-animated
 
136
// images of the following formats: IMAGE_GIF, IMAGE_PNG, IMAGE_JPEG,
 
137
// and IMAGE_WEBP.
 
138
bool ReadImage(ImageFormat image_type,
 
139
               const void* image_buffer,
 
140
               size_t buffer_length,
 
141
               void** pixels,
 
142
               PixelFormat* pixel_format,
 
143
               size_t* width,
 
144
               size_t* height,
 
145
               size_t* stride,
 
146
               MessageHandler* handler);
 
147
 
 
148
}  // namespace image_compression
 
149
 
 
150
}  // namespace pagespeed
 
151
 
 
152
#endif  // PAGESPEED_KERNEL_IMAGE_READ_IMAGE_H_