Lines Matching +full:offset +full:- +full:y

1 // SPDX-License-Identifier: MIT
25 //! * <https://github.com/kennytm/qrcode-rust>
69 /// - Error Correction polynomial.
70 /// - Number of blocks in group 1.
71 /// - Number of blocks in group 2.
72 /// - Block size in group 1.
166 /// Version information for format V7-V40.
211 fn from_segments(segments: &[&Segment<'_>]) -> Option<Version> { in from_segments()
220 fn width(&self) -> u8 { in width()
224 fn max_data(&self) -> usize { in max_data()
228 fn ec_size(&self) -> usize { in ec_size()
229 VPARAM[self.0 - 1].0.len() in ec_size()
232 fn g1_blocks(&self) -> usize { in g1_blocks()
233 VPARAM[self.0 - 1].1 as usize in g1_blocks()
236 fn g2_blocks(&self) -> usize { in g2_blocks()
237 VPARAM[self.0 - 1].2 as usize in g2_blocks()
240 fn g1_blk_size(&self) -> usize { in g1_blk_size()
241 VPARAM[self.0 - 1].3 as usize in g1_blk_size()
244 fn alignment_pattern(&self) -> &'static [u8] { in alignment_pattern()
245 &ALIGNMENT_PATTERNS[self.0 - 1] in alignment_pattern()
248 fn poly(&self) -> &'static [u8] { in poly()
249 VPARAM[self.0 - 1].0 in poly()
252 fn version_info(&self) -> u32 { in version_info()
254 VERSION_INFORMATION[self.0 - 7] in version_info()
302 /// Get the next 13 bits of data, starting at specified offset (in bits).
303 fn get_next_13b(data: &[u8], offset: usize) -> Option<(u16, usize)> { in get_next_13b()
304 if offset < data.len() * 8 { in get_next_13b()
305 let size = cmp::min(13, data.len() * 8 - offset); in get_next_13b()
306 let byte_off = offset / 8; in get_next_13b()
307 let bit_off = offset % 8; in get_next_13b()
314 0..=8 => first_byte >> (8 - b), in get_next_13b()
315 9..=16 => (first_byte << (b - 8)) + (data[byte_off + 1] >> (16 - b)) as u16, in get_next_13b()
317 (first_byte << (b - 8)) in get_next_13b()
318 + ((data[byte_off + 1] as u16) << (b - 16)) in get_next_13b()
319 + (data[byte_off + 2] >> (24 - b)) as u16 in get_next_13b()
338 fn get_header(&self) -> (u16, usize) { in get_header()
346 fn length_bits_count(&self, version: Version) -> usize { in length_bits_count()
362 fn character_count(&self) -> usize { in character_count()
377 fn get_length_field(&self, version: Version) -> (u16, usize) { in get_length_field()
384 fn total_size_bits(&self, version: Version) -> usize { in total_size_bits()
396 fn iter(&self) -> SegmentIterator<'_> { in iter()
399 offset: 0, in iter()
408 offset: usize, field
416 fn next(&mut self) -> Option<Self::Item> { in next()
419 if self.offset < data.len() { in next()
420 let byte = data[self.offset] as u16; in next()
421 self.offset += 1; in next()
433 } else if let Some((bits, size)) = get_next_13b(data, self.offset) { in next()
434 self.offset += size; in next()
440 self.carry_len = new_chars + self.carry_len - 3; in next()
442 self.carry * POW10[new_chars - self.carry_len] in next()
482 fn new<'a, 'b>(segments: &[&Segment<'b>], data: &'a mut [u8]) -> Option<EncodedMsg<'a>> { in new()
508 /// Push bits of data at an offset (in bits).
509 fn push(&mut self, offset: &mut usize, bits: (u16, usize)) { in push()
511 let byte_off = *offset / 8; in push()
512 let bit_off = *offset % 8; in push()
517 self.data[byte_off] = (number << (8 - b)) as u8; in push()
520 self.data[byte_off] = (number >> (b - 8)) as u8; in push()
521 self.data[byte_off + 1] = (number << (16 - b)) as u8; in push()
524 self.data[byte_off] |= (number << (8 - b)) as u8; in push()
527 self.data[byte_off] |= (number >> (b - 8)) as u8; in push()
528 self.data[byte_off + 1] = (number << (16 - b)) as u8; in push()
531 self.data[byte_off] |= (number >> (b - 8)) as u8; in push()
532 self.data[byte_off + 1] = (number >> (b - 16)) as u8; in push()
533 self.data[byte_off + 2] = (number << (24 - b)) as u8; in push()
536 *offset += len_bits; in push()
540 let mut offset: usize = 0; in add_segments() localVariable
543 self.push(&mut offset, s.get_header()); in add_segments()
544 self.push(&mut offset, s.get_length_field(self.version)); in add_segments()
546 self.push(&mut offset, bits); in add_segments()
549 self.push(&mut offset, (MODE_STOP, 4)); in add_segments()
551 let pad_offset = (offset + 7) / 8; in add_segments()
557 fn error_code_for_blocks(&mut self, offset: usize, size: usize, ec_offset: usize) { in error_code_for_blocks()
560 tmp[0..size].copy_from_slice(&self.data[offset..offset + size]); in error_code_for_blocks()
576 let mut offset = 0; in compute_error_code() localVariable
580 self.error_code_for_blocks(offset, self.g1_blk_size, ec_offset); in compute_error_code()
581 offset += self.g1_blk_size; in compute_error_code()
585 self.error_code_for_blocks(offset, self.g2_blk_size, ec_offset); in compute_error_code()
586 offset += self.g2_blk_size; in compute_error_code()
596 fn iter(&self) -> EncodedMsgIterator<'_> { in iter()
599 offset: 0, in iter()
607 offset: usize, field
615 fn next(&mut self) -> Option<Self::Item> { in next()
622 if self.offset >= ec_end { in next()
626 let offset = if self.offset < em.g1_blk_size * blocks { in next() localVariable
628 let blk = self.offset % blocks; in next()
629 let blk_off = self.offset / blocks; in next()
633 g1_end + em.g2_blk_size * (blk - em.g1_blocks) + blk_off in next()
635 } else if self.offset < g2_end { in next()
637 let blk2 = self.offset - blocks * em.g1_blk_size; in next()
638 em.g1_blk_size * em.g1_blocks + blk2 * em.g2_blk_size + em.g2_blk_size - 1 in next()
641 let ec_offset = self.offset - g2_end; in next()
647 self.offset += 1; in next()
648 Some(em.data[offset]) in next()
663 fn new<'a, 'b>(em: &'b EncodedMsg<'b>, qrdata: &'a mut [u8]) -> QrImage<'a> { in new()
683 fn set(&mut self, x: u8, y: u8) { in set()
684 let off = y as usize * self.stride as usize + x as usize / 8; in set()
691 fn xor(&mut self, x: u8, y: u8) { in xor()
692 let off = y as usize * self.stride as usize + x as usize / 8; in xor()
696 // Draw a light square at (x, y) top left corner.
697 fn draw_square(&mut self, x: u8, y: u8, size: u8) { in draw_square()
699 self.set(x + k, y); in draw_square()
700 self.set(x, y + k + 1); in draw_square()
701 self.set(x + size, y + k); in draw_square()
702 self.set(x + k + 1, y + size); in draw_square()
709 self.draw_square(self.width - 6, 1, 4); in draw_finders()
710 self.draw_square(1, self.width - 6, 4); in draw_finders()
713 self.set(self.width - k - 1, 7); in draw_finders()
714 self.set(k, self.width - 8); in draw_finders()
718 self.set(self.width - 8, k); in draw_finders()
719 self.set(7, self.width - 1 - k); in draw_finders()
723 fn is_finder(&self, x: u8, y: u8) -> bool { in is_finder()
724 let end = self.width - 8; in is_finder()
725 (x < 8 && y < 8) || (x < 8 && y >= end) || (x >= end && y < 8) in is_finder()
732 for &y in positions.iter() { in draw_alignments()
733 if !self.is_finder(x, y) { in draw_alignments()
734 self.draw_square(x - 1, y - 1, 2); in draw_alignments()
740 fn is_alignment(&self, x: u8, y: u8) -> bool { in is_alignment()
747 if x >= ax - 2 && x <= ax + 2 && y >= ay - 2 && y <= ay + 2 { in is_alignment()
757 let end = self.width - 8; in draw_timing_patterns()
765 fn is_timing(&self, x: u8, y: u8) -> bool { in is_timing()
766 x == 6 || y == 6 in is_timing()
778 if info & (1 << (14 - k)) == 0 { in draw_maskinfo()
780 self.set(8, self.width - 1 - k); in draw_maskinfo()
788 if info & (1 << (7 - k)) == 0 { in draw_maskinfo()
789 self.set(8, 8 - skip - k); in draw_maskinfo()
790 self.set(self.width - 8 + k, 8); in draw_maskinfo()
795 fn is_maskinfo(&self, x: u8, y: u8) -> bool { in is_maskinfo()
796 let end = self.width - 8; in is_maskinfo()
798 (x <= 8 && y == 8) || (y <= 8 && x == 8) || (x == 8 && y >= end) || (x >= end && y == 8) in is_maskinfo()
804 let pos = self.width - 11; in draw_version_info()
808 for y in 0..6 { in draw_version_info()
809 if vinfo & (1 << (x + y * 3)) == 0 { in draw_version_info()
810 self.set(x + pos, y); in draw_version_info()
811 self.set(y, x + pos); in draw_version_info()
818 fn is_version_info(&self, x: u8, y: u8) -> bool { in is_version_info()
820 let pos = self.width - 11; in is_version_info()
822 vinfo != 0 && ((x >= pos && x < pos + 3 && y < 6) || (y >= pos && y < pos + 3 && x < 6)) in is_version_info()
826 fn is_reserved(&self, x: u8, y: u8) -> bool { in is_reserved()
827 self.is_alignment(x, y) in is_reserved()
828 || self.is_finder(x, y) in is_reserved()
829 || self.is_timing(x, y) in is_reserved()
830 || self.is_maskinfo(x, y) in is_reserved()
831 || self.is_version_info(x, y) in is_reserved()
835 fn is_last(&self, x: u8, y: u8) -> bool { in is_last()
836 x == 0 && y == self.width - 1 in is_last()
841 fn next(&self, x: u8, y: u8) -> (u8, u8) { in next()
843 let column_type = (self.width - x_adj) % 4; in next()
846 2 if y > 0 => (x + 1, y - 1), in next()
847 0 if y < self.width - 1 => (x + 1, y + 1), in next()
848 0 | 2 if x == 7 => (x - 2, y), in next()
849 _ => (x - 1, y), in next()
854 fn next_available(&self, x: u8, y: u8) -> (u8, u8) { in next_available()
855 let (mut x, mut y) = self.next(x, y); in next_available()
856 while self.is_reserved(x, y) && !self.is_last(x, y) { in next_available()
857 (x, y) = self.next(x, y); in next_available()
859 (x, y) in next_available()
863 let (mut x, mut y) = (self.width - 1, self.width - 1); in draw_data()
867 self.set(x, y); in draw_data()
869 (x, y) = self.next_available(x, y); in draw_data()
874 while !self.is_last(x, y) { in draw_data()
875 if !self.is_reserved(x, y) { in draw_data()
876 self.set(x, y); in draw_data()
878 (x, y) = self.next(x, y); in draw_data()
882 // Apply checkerboard mask to all non-reserved modules.
885 for y in 0..self.width { in apply_mask()
886 if (x ^ y) % 2 == 0 && !self.is_reserved(x, y) { in apply_mask()
887 self.xor(x, y); in apply_mask()
927 /// * `url` must be null or point at a nul-terminated string.
941 ) -> u8 { in drm_panic_qr_generate()
961 // nul-terminated string. in drm_panic_qr_generate()
978 /// * `version`: QR code version, between 1-40.
985 pub extern "C" fn drm_panic_qr_max_data_size(version: u8, url_len: usize) -> usize { in drm_panic_qr_max_data_size()
996 let max = max_data - url_len - 5; in drm_panic_qr_max_data_size()
1001 max_data - 3 in drm_panic_qr_max_data_size()