Bug 37117 - Add platform-independent JPEG/PNG image encoders
Summary: Add platform-independent JPEG/PNG image encoders
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Minor
Assignee: Yong Li
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-05 15:29 PDT by Yong Li
Modified: 2010-09-16 07:55 PDT (History)
5 users (show)

See Also:


Attachments
the patch (13.58 KB, patch)
2010-04-06 08:34 PDT, Yong Li
no flags Details | Formatted Diff | Diff
fix style errors (13.68 KB, patch)
2010-04-06 09:34 PDT, Yong Li
abarth: review-
Details | Formatted Diff | Diff
Updated again (13.58 KB, patch)
2010-06-23 13:24 PDT, Yong Li
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yong Li 2010-04-05 15:29:41 PDT
1. Add platform-independent JPEG/PNG image encoders

2. Implement toDataURL for ImageBufferOpenVG with platform-independent code
Comment 1 Yong Li 2010-04-06 08:34:13 PDT
Created attachment 52642 [details]
the patch
Comment 2 WebKit Review Bot 2010-04-06 08:38:45 PDT
Attachment 52642 [details] did not pass style-queue:

Failed to run "WebKitTools/Scripts/check-webkit-style" exit_code: 1
WebCore/platform/image-encoders/PNGImageEncoder.h:21:  #ifndef header guard has wrong style, please use: PNGImageEncoder_h  [build/header_guard] [5]
WebCore/platform/image-encoders/PNGImageEncoder.h:27:  Code inside a namespace should not be indented.  [whitespace/indent] [4]
WebCore/platform/image-encoders/PNGImageEncoder.cpp:50:  This { should be at the end of the previous line  [whitespace/braces] [4]
WebCore/platform/image-encoders/PNGImageEncoder.cpp:129:  One space before end of line comments  [whitespace/comments] [5]
WebCore/platform/image-encoders/JPEGImageEncoder.h:22:  #ifndef header guard has wrong style, please use: JPEGImageEncoder_h  [build/header_guard] [5]
WebCore/platform/image-encoders/JPEGImageEncoder.h:28:  Code inside a namespace should not be indented.  [whitespace/indent] [4]
WebCore/platform/image-encoders/JPEGImageEncoder.cpp:28:  Alphabetical sorting problem.  [build/include_order] [4]
WebCore/platform/image-encoders/JPEGImageEncoder.cpp:34:  This { should be at the end of the previous line  [whitespace/braces] [4]
WebCore/platform/image-encoders/JPEGImageEncoder.cpp:47:  This { should be at the end of the previous line  [whitespace/braces] [4]
WebCore/platform/image-encoders/JPEGImageEncoder.cpp:83:  Declaration has space between type name and * in JPEGCompressErrorMgr *err  [whitespace/declaration] [3]
Total errors found: 10 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Yong Li 2010-04-06 09:34:02 PDT
Created attachment 52646 [details]
fix style errors
Comment 4 WebKit Review Bot 2010-04-06 09:39:18 PDT
Attachment 52646 [details] did not pass style-queue:

Failed to run "WebKitTools/Scripts/check-webkit-style" exit_code: 1
WebCore/platform/image-encoders/JPEGImageEncoder.cpp:28:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Yong Li 2010-04-06 09:57:27 PDT
(In reply to comment #4)
> Attachment 52646 [details] did not pass style-queue:
> 
> Failed to run "WebKitTools/Scripts/check-webkit-style" exit_code: 1
> WebCore/platform/image-encoders/JPEGImageEncoder.cpp:28:  Alphabetical sorting
> problem.  [build/include_order] [4]
> Total errors found: 1 in 5 files
> 
> 
> If any of these errors are false positives, please file a bug against
> check-webkit-style.

this style error is a must. we cannot avoid this
Comment 6 Adam Barth 2010-06-20 10:15:58 PDT
Comment on attachment 52646 [details]
fix style errors

This code is nutty, but I think the image decoder libraries force you into some of this nuttiness.  Some nits below.  Please get pkasting to give your revised patch an informal review.

WebCore/platform/image-encoders/JPEGImageEncoder.cpp:39
 +          jpeg_destination_mgr* base = this;
Woah, crazy.  Is this what we're supposed to do here?

WebCore/platform/image-encoders/JPEGImageEncoder.cpp:50
 +          // Zero memory
I like the static cast trick you did above.  Can we do that here?  In principle, we can get in trouble with this code if we add virtual functions to this class.

WebCore/platform/image-encoders/JPEGImageEncoder.cpp:61
 +      dest->next_output_byte  = reinterpret_cast<JOCTET*>(dest->m_buffer.data());
We don't usually align the = sign.  We just have once space.

WebCore/platform/image-encoders/JPEGImageEncoder.cpp:59
 +      JPEGDestinationManager* dest = (JPEGDestinationManager*)compressData->dest;
Please use a C++ style cast like you do below.

WebCore/platform/image-encoders/JPEGImageEncoder.cpp:83
 +      longjmp(err->m_setjmpBuffer, -1);
Crazy!

WebCore/platform/image-encoders/JPEGImageEncoder.cpp:88
 +      struct jpeg_compress_struct compressData= { 0 };
Missing space before =

WebCore/platform/image-encoders/JPEGImageEncoder.cpp:109
 +      Vector<JSAMPLE, 600 * 3> rowBuffer;
No space around *

WebCore/platform/image-encoders/JPEGImageEncoder.cpp:108
 +      // rowBuffer must be defined here so that its destructor is always called even when "setjmp" catches an error.
setjmp/longjmp are insane, especially when mixed with C++ constructs.

WebCore/platform/image-encoders/JPEGImageEncoder.h:21
 +  
Extra blank line here.

WebCore/platform/image-encoders/PNGImageEncoder.cpp:51
 +      Vector<char>* m_out;
Why is this called m_out but the corresponding variable for JPEG is called m_dump?

WebCore/platform/image-encoders/PNGImageEncoder.cpp:62
 +      memcpy(&(*state->m_out)[oldSize], data, size);
&(*state->m_out)[oldSize] is too hard to understand.  Please use temporary variables to explain what this insanity does.

WebCore/platform/image-encoders/PNGImageEncoder.cpp:87
 +      png_struct* pngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
We usually put these sorts of things on one line.
Comment 7 Yong Li 2010-06-23 13:23:59 PDT
(In reply to comment #6)
> (From update of attachment 52646 [details])
> This code is nutty, but I think the image decoder libraries force you into some of this nuttiness.  Some nits below.  Please get pkasting to give your revised patch an informal review.
> 
> WebCore/platform/image-encoders/JPEGImageEncoder.cpp:39
>  +          jpeg_destination_mgr* base = this;
> Woah, crazy.  Is this what we're supposed to do here?
> 
> WebCore/platform/image-encoders/JPEGImageEncoder.cpp:50
>  +          // Zero memory
> I like the static cast trick you did above.  Can we do that here?  In principle, we can get in trouble with this code if we add virtual functions to this class.

This doesn't need a static cast because it casts from child class to the parent class. Implicit cast is safer than static cast in most cases. No matter we add virtual functions to the class or add another parent class, "base" is always pointing to a good jpeg_destination_mgr object.
 
> WebCore/platform/image-encoders/JPEGImageEncoder.cpp:83
>  +      longjmp(err->m_setjmpBuffer, -1);
> Crazy!

:) Yes it is. I don't like it either. But it's the way to handle libjpeg error. JPEG decoder also uses this. 

> WebCore/platform/image-encoders/JPEGImageEncoder.cpp:109
>  +      Vector<JSAMPLE, 600 * 3> rowBuffer;
> No space around *

Are you sure? I don't think check-webkit-style will accept 600*3 with no spaces.

Thanks a lot for reviewing! I'll update the patch according to your suggestions.
Comment 8 Yong Li 2010-06-23 13:24:29 PDT
Created attachment 59557 [details]
Updated again
Comment 9 WebKit Review Bot 2010-06-23 13:29:12 PDT
Attachment 59557 [details] did not pass style-queue:

Failed to run "['WebKitTools/Scripts/check-webkit-style', '--no-squash']" exit_code: 1
WebCore/platform/image-encoders/JPEGImageEncoder.cpp:28:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 Yong Li 2010-06-24 13:09:14 PDT
(In reply to comment #9)
> Attachment 59557 [details] did not pass style-queue:
> Failed to run "['WebKitTools/Scripts/check-webkit-style', '--no-squash']" exit_code: 1
> WebCore/platform/image-encoders/JPEGImageEncoder.cpp:28:  Alphabetical sorting problem.  [build/include_order] [4]
> Total errors found: 1 in 5 files
> If any of these errors are false positives, please file a bug against check-webkit-style.

we cannot avoid this
Comment 11 George Staikos 2010-09-15 11:54:20 PDT
Comment on attachment 59557 [details]
Updated again

Will need a retest since it's so old.
Comment 12 WebKit Commit Bot 2010-09-16 04:48:03 PDT
Comment on attachment 59557 [details]
Updated again

Clearing flags on attachment: 59557

Committed r67606: <http://trac.webkit.org/changeset/67606>
Comment 13 WebKit Commit Bot 2010-09-16 04:48:09 PDT
All reviewed patches have been landed.  Closing bug.