2
* Copyright 2013 Google Inc.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
19
#ifndef PAGESPEED_KERNEL_IMAGE_READ_IMAGE_H_
20
#define PAGESPEED_KERNEL_IMAGE_READ_IMAGE_H_
23
#include "pagespeed/kernel/base/string.h"
24
#include "pagespeed/kernel/image/image_util.h"
25
#include "pagespeed/kernel/image/scanline_status.h"
27
namespace net_instaweb {
33
namespace image_compression {
35
class MultipleFrameReader;
36
class MultipleFrameWriter;
37
class ScanlineReaderInterface;
38
class ScanlineWriterInterface;
40
using net_instaweb::MessageHandler;
42
////////// Scanline API
44
// TODO(huibao): Add an overload function
45
// CreateScanlineReader(const void* image_buffer, size_t buffer_length).
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,
52
MessageHandler* handler,
53
ScanlineStatus* status);
55
inline ScanlineReaderInterface* CreateScanlineReader(ImageFormat image_type,
56
const void* image_buffer,
58
MessageHandler* handler) {
59
ScanlineStatus status;
60
return CreateScanlineReader(image_type, image_buffer, buffer_length,
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
78
inline ScanlineWriterInterface* CreateScanlineWriter(ImageFormat image_type,
79
PixelFormat pixel_format,
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);
90
////////// ImageFrame API
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.
96
// The caller retains ownership of 'image_buffer', 'handler', and
98
MultipleFrameReader* CreateImageFrameReader(
99
ImageFormat image_type,
100
const void* image_buffer,
101
size_t buffer_length,
102
MessageHandler* handler,
103
ScanlineStatus* status);
105
// Returns a new MultipleFrameWriter after calling its Initialize()
106
// method. The following formats are supported: IMAGE_PNG,
107
// IMAGE_JPEG, and IMAGE_WEBP.
109
// The caller retains ownership of 'config', 'image_data', 'handler',
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
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.
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().
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
135
// This function uses the scanline API and supports non-animated
136
// images of the following formats: IMAGE_GIF, IMAGE_PNG, IMAGE_JPEG,
138
bool ReadImage(ImageFormat image_type,
139
const void* image_buffer,
140
size_t buffer_length,
142
PixelFormat* pixel_format,
146
MessageHandler* handler);
148
} // namespace image_compression
150
} // namespace pagespeed
152
#endif // PAGESPEED_KERNEL_IMAGE_READ_IMAGE_H_