My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 26 attachment: pdjvu.patch (7.4 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Index: PocketDjVu_root/libdjvu/GScaler.cpp
===================================================================
--- PocketDjVu_root/libdjvu/GScaler.cpp (revision 151)
+++ PocketDjVu_root/libdjvu/GScaler.cpp (working copy)
@@ -673,7 +673,7 @@
GPixel *dest = output[y-desired_output.ymin];
// Loop horizontally
for (int x=desired_output.xmin; x<desired_output.xmax; x++,dest++)
const int n = hcoord[x];
const GPixel *lower = line + (n>>FRACBITS);
const short *deltas = &interp[n&FRACMASK][256];
Index: PocketDjVu_root/PocketDjvu/Page.cpp
===================================================================
--- PocketDjVu_root/PocketDjvu/Page.cpp (revision 151)
+++ PocketDjVu_root/PocketDjvu/Page.cpp (working copy)
@@ -4,13 +4,19 @@
#include "PageLoader.h"

bool CPage::LoadBmpSync()
+ WTL::CRect cr;
+ GetClientRect(m_hWnd, &cr );
+ int client_rotation = (cr.Width() > cr.Height()) ? 3 : 0;
+
CPageLoader bmpLdr( m_hWnd,
m_pDjVuDoc,
m_pageIndex,
m_rc.Width(),
m_rc.Height(),
- m_bWidthMostPrioritized );
+ m_bWidthMostPrioritized,
+ 0,
+ client_rotation);
CPageLoader::RET_CODES res = bmpLdr.LoadBmp();
if ( CPageLoader::RET_OK != res && CPageLoader::RET_EMPTY != res )
return false;
Index: PocketDjVu_root/PocketDjvu/PageLoader.cpp
===================================================================
--- PocketDjVu_root/PocketDjvu/PageLoader.cpp (revision 151)
+++ PocketDjVu_root/PocketDjvu/PageLoader.cpp (working copy)
@@ -14,7 +14,8 @@
int width,
int height,
bool bWidthMostPrioritized,
- int rotation
+ int rotation,
+ int client_rotation
)
: m_hWnd(hWnd)
, m_pDjVuDoc(pDjVuDoc)
@@ -26,6 +27,7 @@
, m_ImgHeight()
, m_pBmp()
, m_rotation(rotation)
+ , m_client_rotation(client_rotation)
{
}

@@ -73,8 +75,12 @@

CalcDimensions( m_ImgWidth, m_ImgHeight, m_Width, m_Height );

- GP<GPixmap> pPixm = pImage->get_pixmap( GRect(0,0,m_Width,m_Height),
- GRect(0,0,m_Width,m_Height) );
+ bool horizontal = m_client_rotation & 1;
+ size_t iWidth = m_Width * (horizontal ? 1 : 3);
+ size_t iHeight = m_Height * (horizontal ? 3 : 1);
+
+ GP<GPixmap> pPixm = pImage->get_pixmap( GRect(0,0,iWidth,iHeight),
+ GRect(0,0,iWidth,iHeight) );
if ( pPixm )
{
if ( !ConstructDIBbyPixmap( m_Width, m_Height, *pPixm ) )
@@ -82,11 +88,11 @@
}
else
{
- GP<GBitmap> pBmp = pImage->get_bitmap( GRect(0,0,m_Width,m_Height),
- GRect(0,0,m_Width,m_Height) );
+ GP<GBitmap> pBmp = pImage->get_bitmap( GRect(0,0,iWidth,iHeight),
+ GRect(0,0,iWidth,iHeight) );
if ( pBmp )
{
return RET_ERROR;
}
else
@@ -164,19 +170,39 @@
for ( int i=0; i<height; ++i )
{
GPixel * pRow = pixm[i];
- memcpy( pPix, pRow, width*3 );
+ for(int x=0;x<width;x++){
+ GPixel pixels[5];
+ if(m_client_rotation & 1){
+ pixels[0] = pixm[(i*3+4)%(height*3)][x];
+ pixels[1] = pixm[(i*3+3)%(height*3)][x];
+ pixels[2] = pixm[i*3+2][x];
+ pixels[3] = pixm[i*3+1][x];
+ pixels[4] = pixm[i*3][x];
+ }else{
+ pixels[0] = pRow[(x*3+4)%(width*3)];
+ pixels[1] = pRow[(x*3+3)%(width*3)];
+ pixels[2] = pRow[x*3+2];
+ pixels[3] = pRow[x*3+1];
+ pixels[4] = pRow[x*3];
+ }
+ pPix[x*3] = (pixels[2].r + pixels[1].r + pixels[0].r)/3;
+ pPix[x*3+1] = (pixels[3].g + pixels[2].g + pixels[1].g)/3;
+ pPix[x*3+2] = (pixels[4].b + pixels[3].b + pixels[2].b)/3;
+ }
+// memcpy( pPix, pRow, width*3 );
pPix += bytesInRow;
}

return true;
}

{
ATLASSERT( bitmap.columns() == width );
ATLASSERT( bitmap.rows() == height );

- unsigned const HEADER_SIZE = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256;
+#if 0
+ unsigned const HEADER_SIZE = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256;
int bytesInRow = ((width+3)>>2)<<2;
unsigned bitmapSize = HEADER_SIZE + bytesInRow*height;

@@ -202,12 +228,53 @@
m_pBmp->bmiColors[i].rgbRed = 255 - i;
m_pBmp->bmiColors[i].rgbReserved = 0;
}
+#else

+ unsigned const HEADER_SIZE = sizeof(BITMAPINFOHEADER);
+ int bytesInRow = ((width*3+3)>>2)<<2;
+ unsigned bitmapSize = HEADER_SIZE + bytesInRow*height;
+
+ m_pBmp = (BITMAPINFO *)siv_vm::vm_malloc( bitmapSize, 1 );
+ ZeroMemory( m_pBmp, HEADER_SIZE );
+
+ m_pBmp->bmiHeader.biSize = sizeof BITMAPINFOHEADER;
+ m_pBmp->bmiHeader.biWidth = width;
+ m_pBmp->bmiHeader.biHeight = height;
+ m_pBmp->bmiHeader.biPlanes = 1;
+ m_pBmp->bmiHeader.biBitCount = 24;
+ m_pBmp->bmiHeader.biCompression = BI_RGB;
+ m_pBmp->bmiHeader.biSizeImage = 0;
+ m_pBmp->bmiHeader.biXPelsPerMeter = 3600;
+ m_pBmp->bmiHeader.biYPelsPerMeter = 3600;
+ m_pBmp->bmiHeader.biClrUsed = 0;
+ m_pBmp->bmiHeader.biClrImportant = 0;
+
+ int const ct_asseert = 1/int(sizeof(GPixel)==3);
+#endif
+
unsigned char * pPix = (unsigned char*)m_pBmp + HEADER_SIZE;
{
unsigned char * pRow = bitmap[i];
- memcpy( pPix, pRow, width );
+ for(int x=0;x<width;x++){
+ unsigned short pixels[5];
+ if(m_client_rotation & 1){
+ pixels[0] = 255 - bitmap[(i*3+4)%(height*3)][x];
+ pixels[1] = 255 - bitmap[(i*3+3)%(height*3)][x];
+ pixels[2] = 255 - bitmap[i*3+2][x];
+ pixels[3] = 255 - bitmap[i*3+1][x];
+ pixels[4] = 255 - bitmap[i*3][x];
+ }else{
+ pixels[0] = 255 - pRow[(x*3+4)%(width*3)];
+ pixels[1] = 255 - pRow[(x*3+3)%(width*3)];
+ pixels[2] = 255 - pRow[x*3+2];
+ pixels[3] = 255 - pRow[x*3+1];
+ pixels[4] = 255 - pRow[x*3];
+ }
+ pPix[x*3] = (pixels[2] + pixels[1] + pixels[0])/3;
+ pPix[x*3+1] = (pixels[3] + pixels[2] + pixels[1])/3;
+ pPix[x*3+2] = (pixels[4] + pixels[3] + pixels[2])/3;
+ }
pPix += bytesInRow;
}
return true;
Index: PocketDjVu_root/PocketDjvu/PageLoader.h
===================================================================
--- PocketDjVu_root/PocketDjvu/PageLoader.h (revision 151)
+++ PocketDjVu_root/PocketDjvu/PageLoader.h (working copy)
@@ -20,7 +20,8 @@
int width,
int height,
bool bWidthMostPrioritized,
- int rotation = 0 // CCW: 90degree * rotation
+ int rotation = 0, // CCW: 90degree * rotation
+ int client_rotation = 0
);
~CPageLoader();

@@ -65,7 +66,7 @@
int & o_Height );

bool ConstructDIBbyPixmap( int width, int height, GPixmap & pixm );

private:
HWND m_hWnd;
@@ -79,4 +80,5 @@
BITMAPINFO * m_pBmp;
/// CCW: 90degree * m_rotation
int m_rotation;
+ int m_client_rotation;
};
Powered by Google Project Hosting