diff options
author | Nicolas Pena <npm@chromium.org> | 2017-06-15 11:13:34 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-15 15:26:57 +0000 |
commit | 65a55343e623924c9c3bbbd953097cf7fd0f5fc6 (patch) | |
tree | 884df6a4b11fe11130742a1f777ab3e6021587ac /core/fxcodec/lbmp/fx_bmp.cpp | |
parent | c71fdcb1c9c4bc4457afff0f0358d3862ef3b8b7 (diff) | |
download | pdfium-65a55343e623924c9c3bbbd953097cf7fd0f5fc6.tar.xz |
Remove unused BMP compressing code
Change-Id: I64e32fc9226f57e1c9adff7809fabc6cd56e7a8f
Reviewed-on: https://pdfium-review.googlesource.com/6611
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'core/fxcodec/lbmp/fx_bmp.cpp')
-rw-r--r-- | core/fxcodec/lbmp/fx_bmp.cpp | 307 |
1 files changed, 0 insertions, 307 deletions
diff --git a/core/fxcodec/lbmp/fx_bmp.cpp b/core/fxcodec/lbmp/fx_bmp.cpp index f785505d22..1febce63eb 100644 --- a/core/fxcodec/lbmp/fx_bmp.cpp +++ b/core/fxcodec/lbmp/fx_bmp.cpp @@ -19,13 +19,6 @@ uint32_t GetDWord_LSBFirst(uint8_t* p) { return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); } -void SetDWord_LSBFirst(uint8_t* p, uint32_t v) { - p[0] = (uint8_t)v; - p[1] = (uint8_t)(v >> 8); - p[2] = (uint8_t)(v >> 16); - p[3] = (uint8_t)(v >> 24); -} - uint8_t HalfRoundUp(uint8_t value) { uint16_t value16 = value; return static_cast<uint8_t>((value16 + 1) / 2); @@ -37,11 +30,6 @@ uint16_t GetWord_LSBFirst(uint8_t* p) { return p[0] | (p[1] << 8); } -void SetWord_LSBFirst(uint8_t* p, uint16_t v) { - p[0] = (uint8_t)v; - p[1] = (uint8_t)(v >> 8); -} - BMPDecompressor* bmp_create_decompress() { BMPDecompressor* bmp_ptr = FX_Alloc(BMPDecompressor, 1); memset(bmp_ptr, 0, sizeof(BMPDecompressor)); @@ -668,298 +656,3 @@ uint32_t BMPDecompressor::GetAvailInput(uint8_t** avail_buf) { } return avail_in; } - -bmp_compress_struct_p bmp_create_compress() { - bmp_compress_struct_p bmp_ptr; - bmp_ptr = FX_Alloc(bmp_compress_struct, 1); - if (bmp_ptr) { - memset(bmp_ptr, 0, sizeof(bmp_compress_struct)); - } - return bmp_ptr; -} -void bmp_destroy_compress(bmp_compress_struct_p bmp_ptr) { - if (bmp_ptr) { - if (bmp_ptr->src_free && bmp_ptr->src_buf) { - FX_Free(bmp_ptr->src_buf); - } - FX_Free(bmp_ptr); - } -} -static void WriteFileHeader(BmpFileHeaderPtr head_ptr, uint8_t* dst_buf) { - uint32_t offset; - offset = 0; - SetWord_LSBFirst(&dst_buf[offset], head_ptr->bfType); - offset += 2; - SetDWord_LSBFirst(&dst_buf[offset], head_ptr->bfSize); - offset += 4; - SetWord_LSBFirst(&dst_buf[offset], head_ptr->bfReserved1); - offset += 2; - SetWord_LSBFirst(&dst_buf[offset], head_ptr->bfReserved2); - offset += 2; - SetDWord_LSBFirst(&dst_buf[offset], head_ptr->bfOffBits); - offset += 4; -} -static void WriteInfoHeader(BmpInfoHeaderPtr info_head_ptr, uint8_t* dst_buf) { - uint32_t offset; - offset = sizeof(BmpFileHeader); - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biSize); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biWidth); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biHeight); - offset += 4; - SetWord_LSBFirst(&dst_buf[offset], info_head_ptr->biPlanes); - offset += 2; - SetWord_LSBFirst(&dst_buf[offset], info_head_ptr->biBitCount); - offset += 2; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biCompression); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biSizeImage); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biXPelsPerMeter); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biYPelsPerMeter); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biClrUsed); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biClrImportant); - offset += 4; -} -static void bmp_encode_bitfields(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - if (bmp_ptr->info_header.biBitCount != 16 && - bmp_ptr->info_header.biBitCount != 32) { - return; - } - uint32_t size, dst_pos, i; - size = bmp_ptr->src_pitch * bmp_ptr->src_row * - bmp_ptr->info_header.biBitCount / 16; - dst_pos = bmp_ptr->file_header.bfOffBits; - dst_size += size; - dst_buf = FX_Realloc(uint8_t, dst_buf, dst_size); - memset(&dst_buf[dst_pos], 0, size); - uint32_t mask_red; - uint32_t mask_green; - uint32_t mask_blue; - mask_red = 0x7C00; - mask_green = 0x03E0; - mask_blue = 0x001F; - if (bmp_ptr->info_header.biCompression == BMP_BITFIELDS) { - if (bmp_ptr->bit_type == BMP_BIT_565) { - mask_red = 0xF800; - mask_green = 0x07E0; - mask_blue = 0x001F; - } - if (bmp_ptr->info_header.biBitCount == 32) { - mask_red = 0xFF0000; - mask_green = 0x00FF00; - mask_blue = 0x0000FF; - } - SetDWord_LSBFirst(&dst_buf[dst_pos], mask_red); - dst_pos += 4; - SetDWord_LSBFirst(&dst_buf[dst_pos], mask_green); - dst_pos += 4; - SetDWord_LSBFirst(&dst_buf[dst_pos], mask_blue); - dst_pos += 4; - bmp_ptr->file_header.bfOffBits = dst_pos; - } - uint8_t blue_bits = 0; - uint8_t green_bits = 0; - uint8_t red_bits = 0; - for (i = 0; i < bmp_ptr->info_header.biBitCount; i++) { - if ((mask_blue >> i) & 0x01) { - blue_bits++; - } - if ((mask_green >> i) & 0x01) { - green_bits++; - } - if ((mask_red >> i) & 0x01) { - red_bits++; - } - } - green_bits += blue_bits; - red_bits += green_bits; - blue_bits = 8 - blue_bits; - green_bits -= 8; - red_bits -= 8; - i = 0; - for (int32_t row_num = bmp_ptr->src_row - 1; row_num > -1; row_num--, i = 0) { - while (i < bmp_ptr->src_width * bmp_ptr->src_bpp / 8) { - uint8_t b = bmp_ptr->src_buf[row_num * bmp_ptr->src_pitch + i++]; - uint8_t g = bmp_ptr->src_buf[row_num * bmp_ptr->src_pitch + i++]; - uint8_t r = bmp_ptr->src_buf[row_num * bmp_ptr->src_pitch + i++]; - if (bmp_ptr->src_bpp == 32) { - i++; - } - uint32_t pix_val = 0; - pix_val |= (b >> blue_bits) & mask_blue; - pix_val |= (g << green_bits) & mask_green; - pix_val |= (r << red_bits) & mask_red; - if (bmp_ptr->info_header.biBitCount == 16) { - SetWord_LSBFirst(&dst_buf[dst_pos], pix_val); - dst_pos += 2; - } else { - SetDWord_LSBFirst(&dst_buf[dst_pos], pix_val); - dst_pos += 4; - } - } - } - dst_size = dst_pos; -} - -static void bmp_encode_rgb(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - if (bmp_ptr->info_header.biBitCount == 16) { - bmp_encode_bitfields(bmp_ptr, dst_buf, dst_size); - return; - } - uint32_t size, dst_pos; - uint32_t dst_pitch = - (bmp_ptr->src_width * bmp_ptr->info_header.biBitCount + 31) / 32 * 4; - size = dst_pitch * bmp_ptr->src_row; - dst_pos = bmp_ptr->file_header.bfOffBits; - dst_size += size; - dst_buf = FX_Realloc(uint8_t, dst_buf, dst_size); - memset(&dst_buf[dst_pos], 0, size); - for (int32_t row_num = bmp_ptr->src_row - 1; row_num > -1; row_num--) { - memcpy(&dst_buf[dst_pos], &bmp_ptr->src_buf[row_num * bmp_ptr->src_pitch], - bmp_ptr->src_pitch); - dst_pos += dst_pitch; - } - dst_size = dst_pos; -} -static uint8_t bmp_rle8_search(const uint8_t* buf, int32_t len) { - uint8_t num; - num = 1; - while (num < len) { - if (buf[num - 1] != buf[num] || num == 0xFF) { - break; - } - num++; - } - return num; -} -static void bmp_encode_rle8(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - uint32_t size, dst_pos, index; - uint8_t rle[2] = {0}; - size = bmp_ptr->src_pitch * bmp_ptr->src_row * 2; - dst_pos = bmp_ptr->file_header.bfOffBits; - dst_size += size; - dst_buf = FX_Realloc(uint8_t, dst_buf, dst_size); - memset(&dst_buf[dst_pos], 0, size); - for (int32_t row_num = bmp_ptr->src_row - 1, i = 0; row_num > -1;) { - index = row_num * bmp_ptr->src_pitch; - rle[0] = bmp_rle8_search(&bmp_ptr->src_buf[index + i], size - index - i); - rle[1] = bmp_ptr->src_buf[index + i]; - if (i + rle[0] >= (int32_t)bmp_ptr->src_pitch) { - rle[0] = uint8_t(bmp_ptr->src_pitch - i); - if (rle[0]) { - dst_buf[dst_pos++] = rle[0]; - dst_buf[dst_pos++] = rle[1]; - } - dst_buf[dst_pos++] = RLE_MARKER; - dst_buf[dst_pos++] = RLE_EOL; - i = 0; - row_num--; - } else { - i += rle[0]; - dst_buf[dst_pos++] = rle[0]; - dst_buf[dst_pos++] = rle[1]; - } - } - dst_buf[dst_pos++] = RLE_MARKER; - dst_buf[dst_pos++] = RLE_EOI; - dst_size = dst_pos; -} -static uint8_t bmp_rle4_search(const uint8_t* buf, int32_t len) { - uint8_t num; - num = 2; - while (num < len) { - if (buf[num - 2] != buf[num] || num == 0xFF) { - break; - } - num++; - } - return num; -} -static void bmp_encode_rle4(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - uint32_t size, dst_pos, index; - uint8_t rle[2] = {0}; - size = bmp_ptr->src_pitch * bmp_ptr->src_row; - dst_pos = bmp_ptr->file_header.bfOffBits; - dst_size += size; - dst_buf = FX_Realloc(uint8_t, dst_buf, dst_size); - memset(&dst_buf[dst_pos], 0, size); - for (int32_t row_num = bmp_ptr->src_row - 1, i = 0; row_num > -1; - rle[1] = 0) { - index = row_num * bmp_ptr->src_pitch; - rle[0] = bmp_rle4_search(&bmp_ptr->src_buf[index + i], size - index - i); - rle[1] |= (bmp_ptr->src_buf[index + i] & 0x0f) << 4; - rle[1] |= bmp_ptr->src_buf[index + i + 1] & 0x0f; - if (i + rle[0] >= (int32_t)bmp_ptr->src_pitch) { - rle[0] = uint8_t(bmp_ptr->src_pitch - i); - if (rle[0]) { - dst_buf[dst_pos++] = rle[0]; - dst_buf[dst_pos++] = rle[1]; - } - dst_buf[dst_pos++] = RLE_MARKER; - dst_buf[dst_pos++] = RLE_EOL; - i = 0; - row_num--; - } else { - i += rle[0]; - dst_buf[dst_pos++] = rle[0]; - dst_buf[dst_pos++] = rle[1]; - } - } - dst_buf[dst_pos++] = RLE_MARKER; - dst_buf[dst_pos++] = RLE_EOI; - dst_size = dst_pos; -} -bool bmp_encode_image(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - uint32_t head_size = sizeof(BmpFileHeader) + sizeof(BmpInfoHeader); - uint32_t pal_size = sizeof(uint32_t) * bmp_ptr->pal_num; - if (bmp_ptr->info_header.biClrUsed > 0 && - bmp_ptr->info_header.biClrUsed < bmp_ptr->pal_num) { - pal_size = sizeof(uint32_t) * bmp_ptr->info_header.biClrUsed; - } - dst_size = head_size + sizeof(uint32_t) * bmp_ptr->pal_num; - dst_buf = FX_TryAlloc(uint8_t, dst_size); - if (!dst_buf) - return false; - - memset(dst_buf, 0, dst_size); - bmp_ptr->file_header.bfOffBits = head_size; - if (bmp_ptr->pal_ptr && pal_size) { - memcpy(&dst_buf[head_size], bmp_ptr->pal_ptr, pal_size); - bmp_ptr->file_header.bfOffBits += pal_size; - } - WriteInfoHeader(&bmp_ptr->info_header, dst_buf); - switch (bmp_ptr->info_header.biCompression) { - case BMP_RGB: - bmp_encode_rgb(bmp_ptr, dst_buf, dst_size); - break; - case BMP_BITFIELDS: - bmp_encode_bitfields(bmp_ptr, dst_buf, dst_size); - break; - case BMP_RLE8: - bmp_encode_rle8(bmp_ptr, dst_buf, dst_size); - break; - case BMP_RLE4: - bmp_encode_rle4(bmp_ptr, dst_buf, dst_size); - break; - default: - break; - } - bmp_ptr->file_header.bfSize = dst_size; - WriteFileHeader(&bmp_ptr->file_header, dst_buf); - return true; -} |