Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
onlyoffice_core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
onlyoffice_core
Commits
46c05a4c
Commit
46c05a4c
authored
Feb 10, 2017
by
Oleg Korshul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug with some jpeg
parent
f3a510bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
PdfWriter/Src/Image.cpp
PdfWriter/Src/Image.cpp
+71
-0
No files found.
PdfWriter/Src/Image.cpp
View file @
46c05a4c
...
...
@@ -36,6 +36,65 @@
#include "../../DesktopEditor/raster/JBig2/source/Encoder/jbig2enc.h"
#include "../../DesktopEditor/raster/JBig2/source/LeptonLib/allheaders.h"
// TODO: write JPG from Photoshop...
#include "../../DesktopEditor/raster/ImageFileFormatChecker.h"
#include "../../DesktopEditor/raster/BgraFrame.h"
#include "../DesktopEditor/cximage/CxImage/ximage.h"
namespace
NSImageReSaver
{
static
void
CorrectImage
(
const
wchar_t
*
wsFileName
,
BYTE
*&
pBuffer
,
int
&
nBufferSize
,
unsigned
int
&
unWidth
,
unsigned
int
&
unHeight
)
{
pBuffer
=
NULL
;
nBufferSize
=
0
;
CImageFileFormatChecker
oChecker
(
wsFileName
);
if
(
oChecker
.
eFileType
!=
_CXIMAGE_FORMAT_JPG
)
return
;
NSFile
::
CFileBinary
oFile
;
if
(
!
oFile
.
OpenFile
(
wsFileName
))
return
;
if
(
20
>
oFile
.
GetFileSize
())
return
;
BYTE
data
[
20
];
DWORD
dwRead
=
0
;
if
(
!
oFile
.
ReadFile
(
data
,
20
,
dwRead
))
return
;
std
::
string
sFind
((
char
*
)
data
,
20
);
oFile
.
CloseFile
();
if
(
std
::
string
::
npos
==
sFind
.
find
(
"Photoshop"
)
&&
std
::
string
::
npos
==
sFind
.
find
(
"photoshop"
))
return
;
CBgraFrame
oFrame
;
if
(
!
oFrame
.
OpenFile
(
wsFileName
))
return
;
int
nImageW
=
oFrame
.
get_Width
();
int
nImageH
=
oFrame
.
get_Height
();
BYTE
*
pData
=
oFrame
.
get_Data
();
int
nStride
=
4
*
nImageW
;
CxImage
oCxImage
;
if
(
!
oCxImage
.
CreateFromArray
(
pData
,
nImageW
,
nImageH
,
32
,
nStride
,
(
oFrame
.
get_Stride
()
>=
0
)
?
true
:
false
))
return
;
oCxImage
.
SetJpegQualityF
(
85.0
f
);
if
(
!
oCxImage
.
Encode
(
pBuffer
,
nBufferSize
,
CXIMAGE_FORMAT_JPG
))
return
;
if
(
!
pBuffer
||
!
nBufferSize
)
return
;
unWidth
=
(
unsigned
int
)
nImageW
;
unHeight
=
(
unsigned
int
)
nImageH
;
}
}
namespace
PdfWriter
{
//----------------------------------------------------------------------------------------
...
...
@@ -48,6 +107,18 @@ namespace PdfWriter
}
void
CImageDict
::
LoadJpeg
(
const
wchar_t
*
wsFilePath
,
unsigned
int
unWidth
,
unsigned
int
unHeight
,
bool
bGrayScale
)
{
BYTE
*
pCorrectBuffer
=
NULL
;
int
nBufferSize
=
0
;
NSImageReSaver
::
CorrectImage
(
wsFilePath
,
pCorrectBuffer
,
nBufferSize
,
unWidth
,
unHeight
);
if
(
pCorrectBuffer
!=
NULL
)
{
this
->
LoadJpeg
(
pCorrectBuffer
,
nBufferSize
,
unWidth
,
unHeight
,
bGrayScale
);
free
(
pCorrectBuffer
);
return
;
}
CImageFileStream
*
pStream
=
new
CImageFileStream
();
if
(
!
pStream
)
return
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment