├── docs
├── webpshop_enc_ui_mac.webp
├── webpshop_enc_ui_windows.webp
├── MAINTENANCE.md
└── NEWS.md
├── mac
├── Info.plist
├── WebPShopUIUtils_mac.h
├── WebPShopUIUtils_mac.mm
├── WebPShopUIDialog_mac.h
├── WebPShopUI_mac.mm
└── WebPShopUIDialog_mac.mm
├── win
├── WebPShopUIResource_windows.h
├── WebPShop.sln
├── WebPShop.rc
├── WebPShop.vcxproj.filters
└── WebPShopUI_windows.cpp
├── common
├── WebPShopSelectorFilterFile.cpp
├── WebPShopTerminology.h
├── WebPShopSelectorWriteLayer.cpp
├── WebPShopUtils.cpp
├── WebPShopSelectorEstimate.cpp
├── WebPShopDimensionsUtils.cpp
├── WebPShopUIUtils.cpp
├── WebPShopDecodeAnimUtils.cpp
├── WebPShopSelectorWrite.cpp
├── WebPShopSelectorOptions.cpp
├── WebPShopDataUtils.cpp
├── WebPShopSelectorReadLayer.cpp
├── WebPShopEncodeAnimUtils.cpp
├── WebPShopSelector.h
├── WebPShopSelectorRead.cpp
├── WebPShopScripting.cpp
├── WebPShopDecodeUtils.cpp
├── WebPShopUI.h
├── WebPShopImageUtils.cpp
├── WebPShop.r
├── WebPShop.cpp
├── WebPShopEncodeUtils.cpp
├── WebPShopCanvasUtils.cpp
└── WebPShop.h
├── CONTRIBUTING.md
├── README.md
└── LICENSE
/docs/webpshop_enc_ui_mac.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webmproject/WebPShop/HEAD/docs/webpshop_enc_ui_mac.webp
--------------------------------------------------------------------------------
/docs/webpshop_enc_ui_windows.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webmproject/WebPShop/HEAD/docs/webpshop_enc_ui_windows.webp
--------------------------------------------------------------------------------
/mac/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleDisplayName
8 | WebPShop
9 | CFBundleExecutable
10 | $(PRODUCT_NAME)
11 | CFBundleGetInfoString
12 | Copyright 2018-2020 Google LLC
13 | CFBundleIdentifier
14 | $(PRODUCT_BUNDLE_IDENTIFIER)
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | 8BIF
19 | CFBundleShortVersionString
20 | 0.4.3
21 | CFBundleSignature
22 | 8BIM
23 | CFBundleVersion
24 | 0.4.3
25 | NSHumanReadableCopyright
26 | Copyright 2018-2020 Google LLC
27 |
28 |
29 |
--------------------------------------------------------------------------------
/docs/MAINTENANCE.md:
--------------------------------------------------------------------------------
1 | # Maintenance
2 |
3 | Here are described some tips on maintaining the Photoshop plug-in "WebPShop".
4 |
5 | ## Updating WebP version
6 |
7 | To update the WebP **library** version linked in the WebPShop binaries, do the
8 | following:
9 |
10 | * Update the About box text in `win/WebPShop.rc` and
11 | `mac/WebPShopUI_mac.mm` to the new WebP library version.
12 |
13 | * Update the WebP library version in `README.md`.
14 |
15 | * Build WebPShop (Release) for each supported OS/plaform pair and upload.
16 |
17 | ## Updating WebPShop version
18 |
19 | To update the WebPShop **plug-in** version, do the following:
20 |
21 | * Update the About box text in `win/WebPShop.rc` and
22 | `mac/WebPShopUI_mac.mm` to the new WebPShop version and to the current
23 | copyright year (also in `common/WebPShop.r`).
24 |
25 | * Update the WebPShop version in `README.md`, `mac/Info.plist` and
26 | `win/project.pbxproj`.
27 |
28 | * Describe the changes in `docs/NEWS`.
29 |
30 | * Build WebPShop (Release) for each supported OS/plaform pair and upload.
31 |
--------------------------------------------------------------------------------
/win/WebPShopUIResource_windows.h:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | //{{NO_DEPENDENCIES}}
16 | // Microsoft Visual C++ generated include file.
17 | // Used by WebPShop.rc
18 | //
19 |
20 | // Next default values for new objects
21 | //
22 | #ifdef APSTUDIO_INVOKED
23 | #ifndef APSTUDIO_READONLY_SYMBOLS
24 | #define _APS_NEXT_RESOURCE_VALUE 101
25 | #define _APS_NEXT_COMMAND_VALUE 40001
26 | #define _APS_NEXT_CONTROL_VALUE 1000
27 | #define _APS_NEXT_SYMED_VALUE 101
28 | #endif
29 | #endif
30 |
--------------------------------------------------------------------------------
/common/WebPShopSelectorFilterFile.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "PIFormat.h"
16 | #include "WebPShop.h"
17 | #include "WebPShopSelector.h"
18 |
19 | //------------------------------------------------------------------------------
20 |
21 | void DoFilterFile(FormatRecordPtr format_record, Data* const data,
22 | int16* const result) {
23 | if (!ReadAndCheckHeader(format_record, result, nullptr)) {
24 | *result = formatCannotRead;
25 | return;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google.com/conduct/).
29 |
--------------------------------------------------------------------------------
/common/WebPShopTerminology.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef __WebPShopTerminology_H__
16 | #define __WebPShopTerminology_H__
17 |
18 | // Used by LoadWriteConfig() and SaveWriteConfig().
19 | #define keyWriteConfig_quality 'wrtq'
20 | #define keyWriteConfig_compression 'wrtc'
21 | #define keyWriteConfig_keep_exif 'wrte'
22 | #define keyWriteConfig_keep_xmp 'wrtx'
23 | #define keyWriteConfig_keep_color_profile 'wrtp'
24 | #define keyWriteConfig_loop_forever 'wrtl'
25 | #define keyUsePOSIX 'useP'
26 |
27 | // Used by AddComment() and WebPShop.r
28 | #define histResource 'hist'
29 | #define kHistoryEntry 16989
30 |
31 | #endif // __WebPShopTerminology_H__
32 |
--------------------------------------------------------------------------------
/mac/WebPShopUIUtils_mac.h:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef __WebPShopUIUtils_mac_H__
16 | #define __WebPShopUIUtils_mac_H__
17 |
18 | #include
19 |
20 | //------------------------------------------------------------------------------
21 | // Function used to draw a grey/white checkerboard (transparency background on
22 | // Photoshop). A possible optimization would be to render an image instead.
23 |
24 | void DrawCheckerboard(CGContextRef cg_context, const NSRect& cg_rect,
25 | const NSSize& tile_size);
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | #endif // __WebPShopUIUtils_mac_H__
30 |
--------------------------------------------------------------------------------
/common/WebPShopSelectorWriteLayer.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "PIFormat.h"
16 | #include "WebPShop.h"
17 | #include "WebPShopSelector.h"
18 |
19 | //------------------------------------------------------------------------------
20 |
21 | void DoWriteLayerStart(FormatRecordPtr format_record, Data* const data,
22 | int16* const result) {}
23 |
24 | //------------------------------------------------------------------------------
25 |
26 | void DoWriteLayerContinue(FormatRecordPtr format_record, Data* const data,
27 | int16* const result) {
28 | Deallocate(&format_record->data);
29 | }
30 |
31 | //------------------------------------------------------------------------------
32 |
33 | void DoWriteLayerFinish(FormatRecordPtr format_record, Data* const data,
34 | int16* const result) {}
35 |
--------------------------------------------------------------------------------
/win/WebPShop.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio Version 16
3 | VisualStudioVersion = 16.0.31112.23
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WebPShop", "WebPShop.vcxproj", "{73C59F9A-C645-4EE5-8F00-AB4332011062}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|ARM64 = Debug|ARM64
10 | Debug|x64 = Debug|x64
11 | Release|ARM64 = Release|ARM64
12 | Release|x64 = Release|x64
13 | EndGlobalSection
14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
15 | {73C59F9A-C645-4EE5-8F00-AB4332011062}.Debug|ARM64.ActiveCfg = Debug|ARM64
16 | {73C59F9A-C645-4EE5-8F00-AB4332011062}.Debug|ARM64.Build.0 = Debug|ARM64
17 | {73C59F9A-C645-4EE5-8F00-AB4332011062}.Debug|x64.ActiveCfg = Debug|x64
18 | {73C59F9A-C645-4EE5-8F00-AB4332011062}.Debug|x64.Build.0 = Debug|x64
19 | {73C59F9A-C645-4EE5-8F00-AB4332011062}.Release|ARM64.ActiveCfg = Release|ARM64
20 | {73C59F9A-C645-4EE5-8F00-AB4332011062}.Release|ARM64.Build.0 = Release|ARM64
21 | {73C59F9A-C645-4EE5-8F00-AB4332011062}.Release|x64.ActiveCfg = Release|x64
22 | {73C59F9A-C645-4EE5-8F00-AB4332011062}.Release|x64.Build.0 = Release|x64
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | GlobalSection(ExtensibilityGlobals) = postSolution
28 | SolutionGuid = {9068977F-2C8C-4E3E-A564-04A104848961}
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/common/WebPShopUtils.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include
16 |
17 | #include
18 |
19 | #include "PIUSuites.h"
20 | #include "WebPShop.h"
21 |
22 | //------------------------------------------------------------------------------
23 |
24 | void AddComment(FormatRecordPtr format_record, Data* const data,
25 | int16* const result) {
26 | time_t ltime;
27 | time(<ime);
28 |
29 | const std::string currentTime = ctime(<ime);
30 |
31 | size_t length = currentTime.size();
32 |
33 | Handle h = sPSHandle->New((int32)length);
34 |
35 | if (h != NULL) {
36 | Boolean oldLock = FALSE;
37 | Ptr p = NULL;
38 | sPSHandle->SetLock(h, true, &p, &oldLock);
39 | if (p != NULL) {
40 | for (size_t a = 0; a < length; a++) *p++ = currentTime.at(a);
41 | format_record->resourceProcs->addProc(histResource, h);
42 | sPSHandle->SetLock(h, false, &p, &oldLock);
43 | }
44 | sPSHandle->Dispose(h);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/common/WebPShopSelectorEstimate.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "PIFormat.h"
16 | #include "WebPShop.h"
17 | #include "WebPShopSelector.h"
18 |
19 | //------------------------------------------------------------------------------
20 |
21 | void DoEstimatePrepare(FormatRecordPtr format_record, Data* const data,
22 | int16* const result) {
23 | format_record->maxData = 0; // The maximum number of bytes Photoshop can free
24 | // up for a plug-in to use.
25 | }
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | void DoEstimateStart(FormatRecordPtr format_record, Data* const data,
30 | int16* const result) {
31 | if (data->encoded_data.bytes != nullptr) {
32 | // Output size is already known.
33 | format_record->minDataBytes = (int32)data->encoded_data.size;
34 | format_record->maxDataBytes = (int32)data->encoded_data.size;
35 | } else {
36 | // Best and worst case estimation.
37 | int32 width = (format_record->HostSupports32BitCoordinates
38 | ? format_record->imageSize32.h
39 | : format_record->imageSize.h);
40 | int32 height = (format_record->HostSupports32BitCoordinates
41 | ? format_record->imageSize32.v
42 | : format_record->imageSize.v);
43 |
44 | format_record->minDataBytes = 20;
45 | format_record->maxDataBytes =
46 | width * height * format_record->planes * format_record->planeBytes;
47 |
48 | if (data->write_config.animation) {
49 | format_record->maxDataBytes *= format_record->layerData;
50 | }
51 |
52 | // Maximum overhead compared to raw.
53 | format_record->maxDataBytes += 200;
54 | }
55 |
56 | format_record->data = nullptr;
57 | }
58 |
59 | //------------------------------------------------------------------------------
60 |
61 | void DoEstimateContinue(FormatRecordPtr format_record, Data* const data,
62 | int16* const result) {}
63 |
64 | //------------------------------------------------------------------------------
65 |
66 | void DoEstimateFinish(FormatRecordPtr format_record, Data* const data,
67 | int16* const result) {}
68 |
--------------------------------------------------------------------------------
/common/WebPShopDimensionsUtils.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "PITypes.h"
16 | #include "WebPShop.h"
17 |
18 | int32 GetWidth(const VRect& rect) { return rect.right - rect.left; }
19 | int32 GetHeight(const VRect& rect) { return rect.bottom - rect.top; }
20 |
21 | //------------------------------------------------------------------------------
22 |
23 | bool ScaleToFit(int32* const width, int32* const height, int32 max_width,
24 | int32 max_height) {
25 | if (width == nullptr || height == nullptr) {
26 | LOG("/!\\ Width or height is null.");
27 | return false;
28 | }
29 | if (*width <= 0 || *height <= 0 || max_width <= 0 || max_height <= 0) {
30 | LOG("/!\\ Invalid input.");
31 | return false;
32 | }
33 | if (*width > max_width || *height > max_height) {
34 | const int32 original_width = *width;
35 | const int32 original_height = *height;
36 | // Try resizing based on width first to see if it fits.
37 | *width = max_width;
38 | *height = (original_height * max_width) / original_width;
39 | *height = (*height < 1) ? 1 : *height;
40 | // If it doesn't, resize based on height.
41 | if (*height > max_height) {
42 | *width = (original_width * max_height) / original_height;
43 | *width = (*width < 1) ? 1 : *width;
44 | *height = max_height;
45 | }
46 | return true;
47 | }
48 | return false;
49 | }
50 |
51 | bool CropToFit(int32* const width, int32* const height, int32 left, int32 top,
52 | int32 max_width, int32 max_height) {
53 | if (width == nullptr || height == nullptr) {
54 | LOG("/!\\ Width or height is null.");
55 | return false;
56 | }
57 | if (*width <= 0 || *height <= 0 || left < 0 || top < 0 || left >= *width ||
58 | top >= *height || max_width <= 0 || max_height <= 0) {
59 | LOG("/!\\ Invalid input.");
60 | return false;
61 | }
62 | if (left == 0 && top == 0 && *width <= max_width && *height <= max_height) {
63 | return false;
64 | }
65 | *width -= left;
66 | *height -= top;
67 | if (*width > max_width) *width = max_width;
68 | if (*height > max_height) *height = max_height;
69 | return true;
70 | }
71 |
72 | VRect ScaleRectFromAreaToArea(const VRect& src, int32 src_area_width,
73 | int32 src_area_height, int32 dst_area_width,
74 | int32 dst_area_height) {
75 | VRect dst;
76 | dst.left = (src.left * dst_area_width) / src_area_width;
77 | dst.right = (src.right * dst_area_width) / src_area_width;
78 | dst.top = (src.top * dst_area_height) / src_area_height;
79 | dst.bottom = (src.bottom * dst_area_height) / src_area_height;
80 | return dst;
81 | }
82 |
--------------------------------------------------------------------------------
/mac/WebPShopUIUtils_mac.mm:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "WebPShopUIUtils_mac.h"
16 |
17 | #include
18 | #include
19 |
20 | //------------------------------------------------------------------------------
21 |
22 | static void DrawTile(CGContextRef cg_context, const NSRect& cg_rect,
23 | CGFloat x, CGFloat y, const NSSize& tile_size) {
24 | const CGFloat right = std::min(x + tile_size.width, cg_rect.size.width);
25 | const CGFloat bottom = std::min(y + tile_size.height, cg_rect.size.height);
26 | NSRect tile_rect = NSMakeRect(x, y, right - x, bottom - y);
27 | tile_rect.origin.y =
28 | cg_rect.size.height - tile_rect.origin.y - tile_rect.size.height;
29 | tile_rect.origin.x += cg_rect.origin.x;
30 | tile_rect.origin.y += cg_rect.origin.y;
31 | CGContextFillRect(cg_context, tile_rect);
32 | }
33 |
34 | void DrawCheckerboard(CGContextRef cg_context, const NSRect& cg_rect,
35 | const NSSize& tile_size) {
36 | CGColorRef white = CGColorCreateGenericRGB(1.0, 1.0, 1.0, 1.0);
37 | CGContextSetFillColorWithColor(cg_context, white);
38 | // Draw all tiles of even rows, even columns in white.
39 | for (CGFloat x = 0; x < cg_rect.size.width; x += 2 * tile_size.width) {
40 | for (CGFloat y = 0; y < cg_rect.size.height; y += 2 * tile_size.height) {
41 | DrawTile(cg_context, cg_rect, x, y, tile_size);
42 | }
43 | }
44 | // Draw all tiles of uneven rows, uneven columns in white.
45 | for (CGFloat x = tile_size.width; x < cg_rect.size.width;
46 | x += 2 * tile_size.width) {
47 | for (CGFloat y = tile_size.height; y < cg_rect.size.height;
48 | y += 2 * tile_size.height) {
49 | DrawTile(cg_context, cg_rect, x, y, tile_size);
50 | }
51 | }
52 | CGColorRelease(white);
53 |
54 | CGColorRef grey = CGColorCreateGenericRGB(0.8, 0.8, 0.8, 1.0);
55 | CGContextSetFillColorWithColor(cg_context, grey);
56 | // Draw all tiles of even rows, uneven columns in grey.
57 | for (CGFloat x = 0; x < cg_rect.size.width; x += 2 * tile_size.width) {
58 | for (CGFloat y = tile_size.height; y < cg_rect.size.height;
59 | y += 2 * tile_size.height) {
60 | DrawTile(cg_context, cg_rect, x, y, tile_size);
61 | }
62 | }
63 | // Draw all tiles of uneven rows, even columns in grey.
64 | for (CGFloat x = tile_size.width; x < cg_rect.size.width;
65 | x += 2 * tile_size.width) {
66 | for (CGFloat y = 0; y < cg_rect.size.height; y += 2 * tile_size.height) {
67 | DrawTile(cg_context, cg_rect, x, y, tile_size);
68 | }
69 | }
70 | CGColorRelease(grey);
71 | }
72 |
73 | //------------------------------------------------------------------------------
74 |
--------------------------------------------------------------------------------
/common/WebPShopUIUtils.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include
16 |
17 | #include "PIFormat.h"
18 | #include "WebPShop.h"
19 |
20 | //------------------------------------------------------------------------------
21 |
22 | VRect NullRect() {
23 | VRect rect;
24 | rect.left = rect.right = rect.top = rect.bottom = 0;
25 | return rect;
26 | }
27 | VRect GetCenteredRectInArea(const VRect& area, int32 width, int32 height) {
28 | VRect rect;
29 | rect.left = (area.left + area.right) / 2 - width / 2;
30 | rect.right = rect.left + width;
31 | rect.top = (area.top + area.bottom) / 2 - height / 2;
32 | rect.bottom = rect.top + height;
33 | return rect;
34 | }
35 |
36 | VRect GetCropAreaRectInWindow(const VRect& proxy_area_rect_in_window) {
37 | VRect crop_rect = proxy_area_rect_in_window;
38 | crop_rect.left = crop_rect.right - (crop_rect.bottom - crop_rect.top);
39 | crop_rect.left += 2; // Leaving room for the selection borders.
40 | crop_rect.right -= 2;
41 | crop_rect.top += 2;
42 | crop_rect.bottom -= 2;
43 | return crop_rect;
44 | }
45 | VRect GetScaleAreaRectInWindow(const VRect& proxy_area_rect_in_window) {
46 | VRect scale_rect = proxy_area_rect_in_window;
47 | scale_rect.right =
48 | GetCropAreaRectInWindow(proxy_area_rect_in_window).left - 5;
49 | scale_rect.left += 2; // Leaving room for the selection borders.
50 | scale_rect.right -= 2;
51 | scale_rect.top += 2;
52 | scale_rect.bottom -= 2;
53 | return scale_rect;
54 | }
55 |
56 | //------------------------------------------------------------------------------
57 |
58 | std::string DataSizeToString(size_t data_size) {
59 | if (data_size < 1024) {
60 | return std::to_string(data_size) + " B";
61 | }
62 | if (data_size < 1024 * 1024) {
63 | return std::to_string(data_size / 1024) + "." +
64 | std::to_string((data_size % 1024) * 1000 / 1024 / 100) + " KB";
65 | }
66 | return std::to_string(data_size / (1024 * 1024)) + "." +
67 | std::to_string((data_size % (1024 * 1024)) * 1000 / (1024 * 1024) /
68 | 100) +
69 | " MB";
70 | }
71 |
72 | void SetErrorString(FormatRecordPtr format_record, const std::string& str) {
73 | if (format_record->errorString != nullptr && str.length() < 255) {
74 | Str255& errorString = *format_record->errorString;
75 | errorString[0] = static_cast(str.length());
76 | std::copy(str.c_str(), str.c_str() + str.length() + 1, // Include '\0'.
77 | reinterpret_cast(errorString + 1));
78 | LOG("errorString: " << str);
79 | } else {
80 | LOG("errorString (not set): " << str);
81 | }
82 | }
83 |
84 | //------------------------------------------------------------------------------
85 |
--------------------------------------------------------------------------------
/mac/WebPShopUIDialog_mac.h:
--------------------------------------------------------------------------------
1 | // Copyright 2019 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef __WebPShopUIDialog_mac_H__
16 | #define __WebPShopUIDialog_mac_H__
17 |
18 | #include
19 | #include