FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
skia-python/src/skia/Stream.cpp at main · skia-python/skia-python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
skia-python
/
skia-python
Public
Notifications
You must be signed in to change notification settings
Fork
52
Star
322
Code
Issues
44
Pull requests
6
Discussions
Actions
Projects
Security and quality
1
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
skia-python
/
src
/
skia
/
Stream.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
776 lines (715 loc) · 26.7 KB
Breadcrumbs
skia-python
/
src
/
skia
/
Stream.cpp
Copy path
File metadata and controls
776 lines (715 loc) · 26.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
#
include
"
common.h
"
template
<
class
T
= SkStream>
class
PyStream
:
public
T
{
public:
using
T::T;
size_t
read
(
void
* buffer,
size_t
size)
override
{
PYBIND11_OVERLOAD_PURE
(
size_t
, T, read, buffer, size);
}
size_t
peek
(
void
* buffer,
size_t
size)
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, peek, buffer, size);
}
bool
isAtEnd
()
const
override
{
PYBIND11_OVERLOAD_PURE
(
bool
, T, isAtEnd);
}
bool
rewind
()
override
{
PYBIND11_OVERLOAD
(
bool
, T, rewind); }
bool
hasPosition
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasPosition);
}
size_t
getPosition
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getPosition);
}
bool
seek
(
size_t
position)
override
{
PYBIND11_OVERLOAD
(
bool
, T, seek, position);
}
bool
move
(
long
offset)
override
{
PYBIND11_OVERLOAD
(
bool
, T, move, offset);
}
bool
hasLength
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasLength);
}
size_t
getLength
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getLength);
}
const
void
*
getMemoryBase
()
override
{
PYBIND11_OVERLOAD
(
const
void
*, T, getMemoryBase);
}
};
template
<
class
T
= SkStreamRewindable>
class
PyStreamRewindable
:
public
T
{
public:
using
T::T;
size_t
read
(
void
* buffer,
size_t
size)
override
{
PYBIND11_OVERLOAD
(
size_t
, T, read, buffer, size);
}
size_t
peek
(
void
* buffer,
size_t
size)
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, peek, buffer, size);
}
bool
isAtEnd
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, isAtEnd);
}
bool
rewind
()
override
{
PYBIND11_OVERLOAD_PURE
(
bool
, T, rewind); }
bool
hasPosition
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasPosition);
}
size_t
getPosition
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getPosition);
}
bool
seek
(
size_t
position)
override
{
PYBIND11_OVERLOAD
(
bool
, T, seek, position);
}
bool
move
(
long
offset)
override
{
PYBIND11_OVERLOAD
(
bool
, T, move, offset);
}
bool
hasLength
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasLength);
}
size_t
getLength
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getLength);
}
const
void
*
getMemoryBase
()
override
{
PYBIND11_OVERLOAD
(
const
void
*, T, getMemoryBase);
}
};
template
<
class
T
= SkStreamSeekable>
class
PyStreamSeekable
:
public
T
{
public:
using
T::T;
size_t
read
(
void
* buffer,
size_t
size)
override
{
PYBIND11_OVERLOAD
(
size_t
, T, read, buffer, size);
}
size_t
peek
(
void
* buffer,
size_t
size)
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, peek, buffer, size);
}
bool
isAtEnd
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, isAtEnd);
}
bool
rewind
()
override
{
PYBIND11_OVERLOAD
(
bool
, T, rewind); }
bool
hasPosition
()
const
override
{
PYBIND11_OVERLOAD_PURE
(
bool
, T, hasPosition);
}
size_t
getPosition
()
const
override
{
PYBIND11_OVERLOAD_PURE
(
size_t
, T, getPosition);
}
bool
seek
(
size_t
position)
override
{
PYBIND11_OVERLOAD_PURE
(
bool
, T, seek, position);
}
bool
move
(
long
offset)
override
{
PYBIND11_OVERLOAD_PURE
(
bool
, T, move, offset);
}
bool
hasLength
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasLength);
}
size_t
getLength
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getLength);
}
const
void
*
getMemoryBase
()
override
{
PYBIND11_OVERLOAD
(
const
void
*, T, getMemoryBase);
}
};
template
<
class
T
= SkStreamAsset>
class
PyStreamAsset
:
public
T
{
public:
using
T::T;
size_t
read
(
void
* buffer,
size_t
size)
override
{
PYBIND11_OVERLOAD
(
size_t
, T, read, buffer, size);
}
size_t
peek
(
void
* buffer,
size_t
size)
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, peek, buffer, size);
}
bool
isAtEnd
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, isAtEnd);
}
bool
rewind
()
override
{
PYBIND11_OVERLOAD
(
bool
, T, rewind); }
bool
hasPosition
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasPosition);
}
size_t
getPosition
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getPosition);
}
bool
seek
(
size_t
position)
override
{
PYBIND11_OVERLOAD
(
bool
, T, seek, position);
}
bool
move
(
long
offset)
override
{
PYBIND11_OVERLOAD
(
bool
, T, move, offset);
}
bool
hasLength
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasLength);
}
size_t
getLength
()
const
override
{
PYBIND11_OVERLOAD_PURE
(
size_t
, T, getLength);
}
const
void
*
getMemoryBase
()
override
{
PYBIND11_OVERLOAD
(
const
void
*, T, getMemoryBase);
}
};
template
<
class
T
= SkStreamMemory>
class
PyStreamMemory
:
public
T
{
public:
using
T::T;
size_t
read
(
void
* buffer,
size_t
size)
override
{
PYBIND11_OVERLOAD
(
size_t
, T, read, buffer, size);
}
size_t
peek
(
void
* buffer,
size_t
size)
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, peek, buffer, size);
}
bool
isAtEnd
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, isAtEnd);
}
bool
rewind
()
override
{
PYBIND11_OVERLOAD
(
bool
, T, rewind); }
bool
hasPosition
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasPosition);
}
size_t
getPosition
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getPosition);
}
bool
seek
(
size_t
position)
override
{
PYBIND11_OVERLOAD
(
bool
, T, seek, position);
}
bool
move
(
long
offset)
override
{
PYBIND11_OVERLOAD
(
bool
, T, move, offset);
}
bool
hasLength
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasLength);
}
size_t
getLength
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getLength);
}
const
void
*
getMemoryBase
()
override
{
PYBIND11_OVERLOAD_PURE
(
const
void
*, T, getMemoryBase);
}
};
template
<
class
T
= SkWStream>
class
PyWStream
:
public
T
{
public:
using
T::T;
bool
write
(
const
void
* buffer,
size_t
size)
override
{
PYBIND11_OVERLOAD_PURE
(
bool
, T, write, buffer, size);
}
void
flush
()
override
{
PYBIND11_OVERLOAD
(
void
, T, flush); };
size_t
bytesWritten
()
const
override
{
PYBIND11_OVERLOAD_PURE
(
size_t
, T, bytesWritten);
};
};
template
<
class
T
= SkNullWStream>
class
PyWStreamImpl
:
public
T
{
public:
using
T::T;
bool
write
(
const
void
* buffer,
size_t
size)
override
{
PYBIND11_OVERLOAD
(
bool
, T, write, buffer, size);
}
void
flush
()
override
{
PYBIND11_OVERLOAD
(
void
, T, flush); };
size_t
bytesWritten
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, bytesWritten);
};
};
template
<
class
T
= SkFILEStream>
class
PyStreamImpl
:
public
T
{
public:
using
T::T;
size_t
read
(
void
* buffer,
size_t
size)
override
{
PYBIND11_OVERLOAD
(
size_t
, T, read, buffer, size);
}
size_t
peek
(
void
* buffer,
size_t
size)
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, peek, buffer, size);
}
bool
isAtEnd
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, isAtEnd);
}
bool
rewind
()
override
{
PYBIND11_OVERLOAD
(
bool
, T, rewind); }
bool
hasPosition
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasPosition);
}
size_t
getPosition
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getPosition);
}
bool
seek
(
size_t
position)
override
{
PYBIND11_OVERLOAD
(
bool
, T, seek, position);
}
bool
move
(
long
offset)
override
{
PYBIND11_OVERLOAD
(
bool
, T, move, offset);
}
bool
hasLength
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasLength);
}
size_t
getLength
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getLength);
}
const
void
*
getMemoryBase
()
override
{
PYBIND11_OVERLOAD
(
const
void
*, T, getMemoryBase);
}
};
template
<
class
T
= SkMemoryStream>
class
PyMemoryStream
:
public
T
{
public:
using
T::T;
size_t
read
(
void
* buffer,
size_t
size)
override
{
PYBIND11_OVERLOAD
(
size_t
, T, read, buffer, size);
}
size_t
peek
(
void
* buffer,
size_t
size)
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, peek, buffer, size);
}
bool
isAtEnd
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, isAtEnd);
}
bool
rewind
()
override
{
PYBIND11_OVERLOAD
(
bool
, T, rewind); }
bool
hasPosition
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasPosition);
}
size_t
getPosition
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getPosition);
}
bool
seek
(
size_t
position)
override
{
PYBIND11_OVERLOAD
(
bool
, T, seek, position);
}
bool
move
(
long
offset)
override
{
PYBIND11_OVERLOAD
(
bool
, T, move, offset);
}
bool
hasLength
()
const
override
{
PYBIND11_OVERLOAD
(
bool
, T, hasLength);
}
size_t
getLength
()
const
override
{
PYBIND11_OVERLOAD
(
size_t
, T, getLength);
}
const
void
*
getMemoryBase
()
override
{
PYBIND11_OVERLOAD
(
const
void
*, T, getMemoryBase);
}
void
setMemory
(
const
void
* data,
size_t
length,
bool
copyData =
false
)
override
{
PYBIND11_OVERLOAD
(
void
, T, setMemory, data, length, copyData);
}
};
void
initStream
(py::
module
&m) {
py::class_<SkStream, PyStream<>>(m,
"
Stream
"
,
R"docstring(
:py:class:`Stream` – abstraction for a source of bytes.
Subclasses can be backed by memory, or a file, or something else.
NOTE:
Classic "streams" APIs are sort of async, in that on a request for N bytes,
they may return fewer than N bytes on a given call, in which case the caller
can "try again" to get more bytes, eventually (modulo an error) receiving
their total N bytes.
Skia streams behave differently. They are effectively synchronous, and will
always return all N bytes of the request if possible. If they return fewer
(the read() call returns the number of bytes read) then that means there is
no more data (at EOF or hit an error). The caller should not call again in
hopes of fulfilling more of the request.
.. rubric:: Subclasses
.. autosummary::
:nosignatures:
~FILEStream
~MemoryStream
)docstring"
)
.
def
(
"
read
"
,
[] (SkStream& stream, py::buffer b,
size_t
size) {
auto
info = b.
request
(
true
);
size_t
given = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
if
(size ==
0
|| size >= given)
size = given;
return
stream.
read
(info.
ptr
, size);
},
R"docstring(
Reads or skips size number of bytes.
If buffer == NULL, skip size bytes, return how many were skipped. If
buffer != NULL, copy size bytes into buffer, return how many were
copied.
:param buffer: when NULL skip size bytes, otherwise copy size bytes
into buffer
:param size: the number of bytes to skip or copy; may be nullptr
:return: the number of bytes actually read.
Implemented in :py:class:`MemoryStream`, and :py:class:`FILEStream`.
)docstring"
,
py::arg
(
"
buffer
"
),
py::arg
(
"
size
"
) =
0
)
.
def
(
"
skip
"
, &SkStream::skip,
R"docstring(
Skip size number of bytes.
:return: the actual number bytes that could be skipped.
)docstring"
,
py::arg
(
"
size
"
))
.
def
(
"
peek
"
,
[] (SkStream& stream, py::buffer b) {
auto
info = b.
request
(
true
);
size_t
size = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
return
stream.
peek
(info.
ptr
, size);
},
R"docstring(
Attempt to peek at size bytes.
If this stream supports peeking, copy min(size, peekable bytes) into
buffer, and return the number of bytes copied. If the stream does not
support peeking, or cannot peek any bytes, return 0 and leave buffer
unchanged. The stream is guaranteed to be in the same visible state
after this call, regardless of success or failure.
:param buffer: Must not be NULL, and must be at least size bytes.
Destination to copy bytes.
:param size: Number of bytes to copy.
:return: The number of bytes peeked/copied.
Reimplemented in :py:class:`MemoryStream`.
)docstring"
,
py::arg
(
"
buffer
"
))
.
def
(
"
isAtEnd
"
, &SkStream::isAtEnd,
R"docstring(
Returns true when all the bytes in the stream have been read.
This may return true early (when there are no more bytes to be read) or
late (after the first unsuccessful read).
Implemented in :py:class:`MemoryStream`, and :py:class:`FILEStream`.
)docstring"
)
.
def
(
"
readS8
"
,
[] (SkStream& stream) {
int8_t
value;
if
(stream.
readS8
(&value))
return
value;
throw
std::runtime_error
(
"
Failed to read
"
);
})
.
def
(
"
readS16
"
,
[] (SkStream& stream) {
int16_t
value;
if
(stream.
readS16
(&value))
return
value;
throw
std::runtime_error
(
"
Failed to read
"
);
})
.
def
(
"
readS32
"
,
[] (SkStream& stream) {
int32_t
value;
if
(stream.
readS32
(&value))
return
value;
throw
std::runtime_error
(
"
Failed to read
"
);
})
.
def
(
"
readU8
"
,
[] (SkStream& stream) {
uint8_t
value;
if
(stream.
readU8
(&value))
return
value;
throw
std::runtime_error
(
"
Failed to read
"
);
})
.
def
(
"
readU16
"
,
[] (SkStream& stream) {
uint16_t
value;
if
(stream.
readU16
(&value))
return
value;
throw
std::runtime_error
(
"
Failed to read
"
);
})
.
def
(
"
readU32
"
,
[] (SkStream& stream) {
uint32_t
value;
if
(stream.
readU32
(&value))
return
value;
throw
std::runtime_error
(
"
Failed to read
"
);
})
.
def
(
"
readBool
"
,
[] (SkStream& stream) {
bool
value;
if
(stream.
readBool
(&value))
return
value;
throw
std::runtime_error
(
"
Failed to read
"
);
})
.
def
(
"
readScalar
"
,
[] (SkStream& stream) {
SkScalar value;
if
(stream.
readScalar
(&value))
return
value;
throw
std::runtime_error
(
"
Failed to read
"
);
})
.
def
(
"
readPackedUInt
"
,
[] (SkStream& stream) {
size_t
value;
if
(stream.
readPackedUInt
(&value))
return
value;
throw
std::runtime_error
(
"
Failed to read
"
);
})
.
def
(
"
rewind
"
, &SkStream::rewind,
R"docstring(
Rewinds to the beginning of the stream.
Returns true if the stream is known to be at the beginning after this
call returns.
Reimplemented in :py:class:`MemoryStream`, :py:class:`FILEStream`, and
:py:class:`StreamRewindable`.
)docstring"
)
.
def
(
"
duplicate
"
, &SkStream::duplicate,
R"docstring(
Duplicates this stream.
If this cannot be done, returns NULL. The returned stream will be
positioned at the beginning of its data.
)docstring"
)
.
def
(
"
fork
"
, &SkStream::fork,
R"docstring(
Duplicates this stream.
If this cannot be done, returns NULL. The returned stream will be
positioned the same as this stream.
)docstring"
)
.
def
(
"
hasPosition
"
, &SkStream::hasPosition,
R"docstring(
Returns true if this stream can report it's current position.
Reimplemented in :py:class:`StreamSeekable`.
)docstring"
)
.
def
(
"
getPosition
"
, &SkStream::getPosition,
R"docstring(
Returns the current position in the stream.
If this cannot be done, returns 0.
Reimplemented in :py:class:`MemoryStream`, :py:class:`FILEStream`, and
:py:class:`StreamSeekable`.
)docstring"
)
.
def
(
"
seek
"
, &SkStream::seek,
R"docstring(
Seeks to an absolute position in the stream.
If this cannot be done, returns false. If an attempt is made to seek
past the end of the stream, the position will be set to the end of the
stream.
Reimplemented in :py:class:`MemoryStream`, :py:class:`FILEStream`, and
:py:class:`StreamSeekable`.
)docstring"
,
py::arg
(
"
position
"
))
.
def
(
"
move
"
, &SkStream::move,
R"docstring(
Seeks to an relative offset in the stream.
If this cannot be done, returns false. If an attempt is made to move to
a position outside the stream, the position will be set to the closest
point within the stream (beginning or end).
Reimplemented in :py:class:`MemoryStream`, :py:class:`FILEStream`, and
:py:class:`StreamSeekable`.
)docstring"
,
py::arg
(
"
offset
"
))
.
def
(
"
hasLength
"
, &SkStream::hasLength,
R"docstring(
Returns true if this stream can report it's total length.
Reimplemented in :py:class:`StreamAsset`.
)docstring"
)
.
def
(
"
getLength
"
, &SkStream::getLength,
R"docstring(
Returns the total length of the stream.
If this cannot be done, returns 0.
Reimplemented in :py:class:`MemoryStream`, :py:class:`FILEStream`, and
:py:class:`StreamAsset`.
)docstring"
)
.
def
(
"
getMemoryBase
"
, &SkStream::getMemoryBase,
R"docstring(
Returns the starting address for the data.
If this cannot be done, returns NULL.
Reimplemented in :py:class:`MemoryStream`, and :py:class:`StreamMemory`.
)docstring"
)
.
def_static
(
"
MakeFromFile
"
,
[] (
const
std::string& path) {
return
SkStream::MakeFromFile
(path.
c_str
());
},
R"docstring(
Attempts to open the specified file as a stream, returns nullptr on
failure.
)docstring"
,
py::arg
(
"
path
"
))
;
py::class_<SkStreamRewindable, PyStreamRewindable<>, SkStream>(
m,
"
StreamRewindable
"
)
.
def
(
"
duplicate
"
, &SkStreamRewindable::duplicate)
;
py::class_<SkStreamSeekable, PyStreamSeekable<>, SkStreamRewindable>(
m,
"
StreamSeekable
"
)
.
def
(
"
fork
"
, &SkStreamSeekable::fork)
;
py::class_<SkStreamAsset, PyStreamAsset<>, SkStreamSeekable>(
m,
"
StreamAsset
"
)
.
def
(
"
duplicate
"
, &SkStreamSeekable::duplicate)
.
def
(
"
fork
"
, &SkStreamSeekable::fork)
;
py::class_<SkStreamMemory, PyStreamMemory<>, SkStreamAsset>(
m,
"
StreamMemory
"
)
.
def
(
"
duplicate
"
, &SkStreamSeekable::duplicate)
.
def
(
"
fork
"
, &SkStreamSeekable::fork)
;
py::class_<SkWStream, PyWStream<>>(m,
"
WStream
"
,
R"docstring(
.. rubric:: Subclasses
.. autosummary::
:nosignatures:
~FILEWStream
~DynamicMemoryWStream
)docstring"
)
.
def
(
"
write
"
,
[] (SkWStream& stream, py::buffer b) {
auto
info = b.
request
();
size_t
size = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
return
stream.
write
(info.
ptr
, size);
},
R"docstring(
Called to write bytes to a :py:class:`WStream`.
Returns true on success
:param buffer: the address of at least size bytes to be written to the
stream
:param size: The number of bytes in buffer to write to the stream
:return: true on success
Implemented in :py:class:`DynamicMemoryWStream`,
:py:class:`FILEWStream`, and :py:class:`NullWStream`.
)docstring"
,
py::arg
(
"
buffer
"
))
.
def
(
"
flush
"
, &SkWStream::flush,
R"docstring(
Reimplemented in :py:class:`FILEWStream`, and :py:class:`NullWStream`.
)docstring"
)
.
def
(
"
bytesWritten
"
, &SkWStream::bytesWritten)
.
def
(
"
write8
"
, &SkWStream::write8,
py::arg
(
"
value
"
))
.
def
(
"
write16
"
, &SkWStream::write16,
py::arg
(
"
value
"
))
.
def
(
"
write32
"
, &SkWStream::write32,
py::arg
(
"
value
"
))
.
def
(
"
writeText
"
,
[] (SkWStream& stream,
const
std::string& text) {
return
stream.
writeText
(text.
c_str
());
},
py::arg
(
"
text
"
))
.
def
(
"
newline
"
, &SkWStream::newline)
.
def
(
"
writeDecAsText
"
, &SkWStream::writeDecAsText,
py::arg
(
"
value
"
))
.
def
(
"
writeBigDecAsText
"
, &SkWStream::writeBigDecAsText,
py::arg
(
"
value
"
),
py::arg
(
"
minDigits
"
) =
0
)
.
def
(
"
writeHexAsText
"
, &SkWStream::writeHexAsText,
py::arg
(
"
value
"
),
py::arg
(
"
minDigits
"
) =
0
)
.
def
(
"
writeScalarAsText
"
, &SkWStream::writeScalarAsText,
py::arg
(
"
value
"
))
.
def
(
"
writeBool
"
, &SkWStream::writeBool,
py::arg
(
"
value
"
))
.
def
(
"
writeBool
"
, &SkWStream::writeBool,
py::arg
(
"
value
"
))
.
def
(
"
writeScalar
"
, &SkWStream::writeScalar,
py::arg
(
"
value
"
))
.
def
(
"
writePackedUInt
"
, &SkWStream::writePackedUInt,
py::arg
(
"
value
"
))
.
def
(
"
writeStream
"
, &SkWStream::writeStream,
py::arg
(
"
input
"
),
py::arg
(
"
length
"
))
.
def_static
(
"
SizeOfPackedUInt
"
, &SkWStream::SizeOfPackedUInt,
py::arg
(
"
value
"
))
;
py::class_<SkNullWStream, PyWStreamImpl<SkNullWStream>, SkWStream>(
m,
"
NullWStream
"
)
.
def
(py::init<>())
;
py::class_<SkFILEStream, PyStreamImpl<SkFILEStream>, SkStreamAsset>(
m,
"
FILEStream
"
)
.
def
(
"
__enter__
"
, [] (
const
SkFILEStream* stream) {
return
stream; })
.
def
(
"
__exit__
"
,
[] (SkFILEStream& stream, py::object exc_type, py::object exc_value,
py::object traceback) { stream.
close
(); })
.
def
(
py::init
(
[] (
const
std::string& path) {
const
char
* path_ = path.
c_str
();
return
SkFILEStream::Make
(path_);
}),
py::arg
(
"
path
"
))
.
def_static
(
"
Make
"
,
[] (
const
std::string& path) {
const
char
* path_ = path.
c_str
();
return
SkFILEStream::Make
(path_);
},
py::arg
(
"
path
"
))
.
def
(
"
isValid
"
, &SkFILEStream::isValid)
.
def
(
"
close
"
, &SkFILEStream::close)
;
py::class_<SkMemoryStream, PyMemoryStream<>, SkStreamMemory>(m,
"
MemoryStream
"
)
.
def
(py::init<>())
.
def
(py::init<
size_t
>(),
py::arg
(
"
length
"
))
.
def
(
py::init
(
[] (py::buffer b,
bool
copyData) {
auto
info = b.
request
();
size_t
size = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
return
std::unique_ptr<SkMemoryStream>(
new
SkMemoryStream
(info.
ptr
, size, copyData));
}),
py::arg
(
"
data
"
),
py::arg
(
"
copyData
"
) =
false
)
.
def
(py::init<
const
void
*,
size_t
,
bool
>(),
py::arg
(
"
data
"
),
py::arg
(
"
length
"
),
py::arg
(
"
copyData
"
) =
false
)
.
def
(py::init<sk_sp<SkData>>(),
py::arg
(
"
data
"
))
.
def_static
(
"
MakeCopy
"
,
[] (py::buffer b) {
auto
info = b.
request
();
size_t
size = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
return
SkMemoryStream::MakeCopy
(info.
ptr
, size);
},
py::arg
(
"
data
"
))
.
def_static
(
"
MakeDirect
"
,
[] (py::buffer b) {
auto
info = b.
request
();
size_t
size = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
return
SkMemoryStream::MakeDirect
(info.
ptr
, size);
},
py::arg
(
"
data
"
))
.
def_static
(
"
Make
"
, &SkMemoryStream::Make,
py::arg
(
"
data
"
))
.
def
(
"
setMemory
"
,
[] (SkMemoryStream& stream, py::buffer b,
bool
copyData) {
auto
info = b.
request
();
size_t
size = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
stream.
setMemory
(info.
ptr
, size, copyData);
},
py::arg
(
"
data
"
),
py::arg
(
"
copyData
"
) =
false
)
.
def
(
"
asData
"
, &SkMemoryStream::getData)
.
def
(
"
setData
"
, &SkMemoryStream::setData,
py::arg
(
"
data
"
))
.
def
(
"
skipToAlign4
"
,
[] (SkMemoryStream& stream) {
size_t
fOffset
= stream.
getPosition
();
//
cast to remove unary-minus warning
fOffset
+= -(
int
)
fOffset
&
0x03
;
stream.
seek
(
fOffset
);
}
)
.
def
(
"
getAtPos
"
, &SkMemoryStream::getAtPos)
;
py::class_<SkFILEWStream, PyWStreamImpl<SkFILEWStream>, SkWStream>(
m,
"
FILEWStream
"
)
.
def
(
py::init
(
[] (
const
std::string& path) {
return
std::unique_ptr<SkFILEWStream>(
new
SkFILEWStream
(path.
c_str
()));
}),
py::arg
(
"
path
"
))
.
def
(
"
isValid
"
, &SkFILEWStream::isValid)
.
def
(
"
fsync
"
, &SkFILEWStream::fsync)
;
py::class_<SkDynamicMemoryWStream, PyWStreamImpl<SkDynamicMemoryWStream>,
SkWStream>(m,
"
DynamicMemoryWStream
"
)
.
def
(py::init<>())
.
def
(
"
read
"
,
[] (SkDynamicMemoryWStream& stream, py::buffer b,
size_t
offset) {
auto
info = b.
request
(
true
);
size_t
size = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
return
stream.
read
(info.
ptr
, offset, size);
},
py::arg
(
"
data
"
),
py::arg
(
"
offset
"
) =
0
)
.
def
(
"
copyTo
"
,
[] (SkDynamicMemoryWStream& stream, py::buffer b) {
auto
info = b.
request
(
true
);
size_t
size = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
if
(size < stream.
bytesWritten
())
throw
py::value_error
(
"
Buffer is smaller than required
"
);
stream.
copyTo
(info.
ptr
);
},
R"docstring(
More efficient version of read(dst, 0, :py:meth:`bytesWritten`).
)docstring"
,
py::arg
(
"
dst
"
))
.
def
(
"
writeToStream
"
, &SkDynamicMemoryWStream::writeToStream,
py::arg
(
"
dst
"
))
.
def
(
"
copyToAndReset
"
,
[] (SkDynamicMemoryWStream& stream, py::buffer b) {
auto
info = b.
request
(
true
);
size_t
size = (info.
ndim
) ? info.
strides
[
0
] * info.
shape
[
0
] :
0
;
if
(size < stream.
bytesWritten
())
throw
py::value_error
(
"
Buffer is smaller than required
"
);
stream.
copyToAndReset
(info.
ptr
);
},
R"docstring(
Equivalent to :py:meth:`copyTo` followed by :py:meth:`reset`, but may
save memory use.
)docstring"
,
py::arg
(
"
dst
"
))
.
def
(
"
writeToAndReset
"
,
py::overload_cast<SkWStream*>(&SkDynamicMemoryWStream::writeToAndReset),
R"docstring(
Equivalent to :py:meth:`writeToStream` followed by :py:meth:`reset`, but
may save memory use.
)docstring"
,
py::arg
(
"
dst
"
))
.
def
(
"
writeToAndReset
"
,
py::overload_cast<SkDynamicMemoryWStream*>(
&SkDynamicMemoryWStream::writeToAndReset),
R"docstring(
Equivalent to :py:meth:`writeToStream` followed by :py:meth:`reset`, but
may save memory use.
When the dst is also a :py:class:`DynamicMemoryWStream`, the
implementation is constant time.
)docstring"
,
py::arg
(
"
dst
"
))
.
def
(
"
prependToAndReset
"
, &SkDynamicMemoryWStream::prependToAndReset,
R"docstring(
Prepend this stream to dst, resetting this.
)docstring"
,
py::arg
(
"
dst
"
))
.
def
(
"
detachAsData
"
, &SkDynamicMemoryWStream::detachAsData,
R"docstring(
Return the contents as :py:class:`Data`, and then reset the stream.
)docstring"
)
.
def
(
"
detachAsStream
"
, &SkDynamicMemoryWStream::detachAsStream,
R"docstring(
Reset, returning a reader stream with the current content.
)docstring"
)
.
def
(
"
reset
"
, &SkDynamicMemoryWStream::reset)
.
def
(
"
padToAlign4
"
, &SkDynamicMemoryWStream::padToAlign4)
;
}
Back
|
FazBrowse Home
|
New Git URL