WebpUtil.smali
.class public Lcom/facebook/imageutils/WebpUtil;
.super Ljava/lang/Object;
.source "SourceFile"
# static fields
.field private static final VP8L_HEADER:Ljava/lang/String; = "VP8L"
.field private static final VP8X_HEADER:Ljava/lang/String; = "VP8X"
.field private static final VP8_HEADER:Ljava/lang/String; = "VP8 "
# direct methods
.method private constructor <init>()V
.registers 1
.line 34
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.method private static compare([BLjava/lang/String;)Z
.registers 6
.line 158
array-length v0, p0
invoke-virtual {p1}, Ljava/lang/String;->length()I
move-result v1
const/4 v2, 0x0
if-eq v0, v1, :cond_9
return v2
:cond_9
const/4 v0, 0x0
.line 161
:goto_a
array-length v1, p0
if-ge v0, v1, :cond_19
.line 162
invoke-virtual {p1, v0}, Ljava/lang/String;->charAt(I)C
move-result v1
aget-byte v3, p0, v0
if-eq v1, v3, :cond_16
return v2
:cond_16
add-int/lit8 v0, v0, 0x1
goto :goto_a
:cond_19
const/4 p0, 0x1
return p0
.end method
.method public static get2BytesAsInt(Ljava/io/InputStream;)I
.registers 3
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 189
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result v0
int-to-byte v0, v0
.line 190
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result p0
int-to-byte p0, p0
shl-int/lit8 p0, p0, 0x8
const v1, 0xff00
and-int/2addr p0, v1
and-int/lit16 v0, v0, 0xff
or-int/2addr p0, v0
return p0
.end method
.method private static getByte(Ljava/io/InputStream;)B
.registers 1
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 208
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result p0
and-int/lit16 p0, p0, 0xff
int-to-byte p0, p0
return p0
.end method
.method private static getHeader([B)Ljava/lang/String;
.registers 4
.line 170
new-instance v0, Ljava/lang/StringBuilder;
invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
const/4 v1, 0x0
.line 171
:goto_6
array-length v2, p0
if-ge v1, v2, :cond_12
.line 172
aget-byte v2, p0, v1
int-to-char v2, v2
invoke-virtual {v0, v2}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;
add-int/lit8 v1, v1, 0x1
goto :goto_6
.line 174
:cond_12
invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object p0
return-object p0
.end method
.method private static getInt(Ljava/io/InputStream;)I
.registers 5
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 178
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result v0
int-to-byte v0, v0
.line 179
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result v1
int-to-byte v1, v1
.line 180
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result v2
int-to-byte v2, v2
.line 181
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result p0
int-to-byte p0, p0
shl-int/lit8 p0, p0, 0x18
const/high16 v3, -0x1000000
and-int/2addr p0, v3
shl-int/lit8 v2, v2, 0x10
const/high16 v3, 0xff0000
and-int/2addr v2, v3
or-int/2addr p0, v2
shl-int/lit8 v1, v1, 0x8
const v2, 0xff00
and-int/2addr v1, v2
or-int/2addr p0, v1
and-int/lit16 v0, v0, 0xff
or-int/2addr p0, v0
return p0
.end method
.method private static getShort(Ljava/io/InputStream;)S
.registers 1
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 204
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result p0
and-int/lit16 p0, p0, 0xff
int-to-short p0, p0
return p0
.end method
.method public static getSize(Ljava/io/InputStream;)Landroid/util/Pair;
.registers 4
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/io/InputStream;",
")",
"Landroid/util/Pair<",
"Ljava/lang/Integer;",
"Ljava/lang/Integer;",
">;"
}
.end annotation
const/4 v0, 0x4
new-array v0, v0, [B
const/4 v1, 0x0
.line 50
:try_start_4
invoke-virtual {p0, v0}, Ljava/io/InputStream;->read([B)I
const-string v2, "RIFF"
.line 52
invoke-static {v0, v2}, Lcom/facebook/imageutils/WebpUtil;->compare([BLjava/lang/String;)Z
move-result v2
:try_end_d
.catch Ljava/io/IOException; {:try_start_4 .. :try_end_d} :catch_73
.catchall {:try_start_4 .. :try_end_d} :catchall_6c
if-nez v2, :cond_15
if-eqz p0, :cond_14
.line 77
:try_start_11
invoke-virtual {p0}, Ljava/io/InputStream;->close()V
:try_end_14
.catch Ljava/io/IOException; {:try_start_11 .. :try_end_14} :catch_14
:catch_14
:cond_14
return-object v1
.line 56
:cond_15
:try_start_15
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getInt(Ljava/io/InputStream;)I
.line 58
invoke-virtual {p0, v0}, Ljava/io/InputStream;->read([B)I
const-string v2, "WEBP"
.line 59
invoke-static {v0, v2}, Lcom/facebook/imageutils/WebpUtil;->compare([BLjava/lang/String;)Z
move-result v2
:try_end_21
.catch Ljava/io/IOException; {:try_start_15 .. :try_end_21} :catch_73
.catchall {:try_start_15 .. :try_end_21} :catchall_6c
if-nez v2, :cond_29
if-eqz p0, :cond_28
.line 77
:try_start_25
invoke-virtual {p0}, Ljava/io/InputStream;->close()V
:try_end_28
.catch Ljava/io/IOException; {:try_start_25 .. :try_end_28} :catch_28
:catch_28
:cond_28
return-object v1
.line 63
:cond_29
:try_start_29
invoke-virtual {p0, v0}, Ljava/io/InputStream;->read([B)I
.line 64
invoke-static {v0}, Lcom/facebook/imageutils/WebpUtil;->getHeader([B)Ljava/lang/String;
move-result-object v0
const-string v2, "VP8 "
.line 65
invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v2
if-eqz v2, :cond_42
.line 66
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getVP8Dimension(Ljava/io/InputStream;)Landroid/util/Pair;
move-result-object v0
:try_end_3c
.catch Ljava/io/IOException; {:try_start_29 .. :try_end_3c} :catch_73
.catchall {:try_start_29 .. :try_end_3c} :catchall_6c
if-eqz p0, :cond_41
.line 77
:try_start_3e
invoke-virtual {p0}, Ljava/io/InputStream;->close()V
:try_end_41
.catch Ljava/io/IOException; {:try_start_3e .. :try_end_41} :catch_41
:catch_41
:cond_41
return-object v0
:cond_42
:try_start_42
const-string v2, "VP8L"
.line 67
invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v2
if-eqz v2, :cond_54
.line 68
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getVP8LDimension(Ljava/io/InputStream;)Landroid/util/Pair;
move-result-object v0
:try_end_4e
.catch Ljava/io/IOException; {:try_start_42 .. :try_end_4e} :catch_73
.catchall {:try_start_42 .. :try_end_4e} :catchall_6c
if-eqz p0, :cond_53
.line 77
:try_start_50
invoke-virtual {p0}, Ljava/io/InputStream;->close()V
:try_end_53
.catch Ljava/io/IOException; {:try_start_50 .. :try_end_53} :catch_53
:catch_53
:cond_53
return-object v0
:cond_54
:try_start_54
const-string v2, "VP8X"
.line 69
invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v0
if-eqz v0, :cond_66
.line 70
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getVP8XDimension(Ljava/io/InputStream;)Landroid/util/Pair;
move-result-object v0
:try_end_60
.catch Ljava/io/IOException; {:try_start_54 .. :try_end_60} :catch_73
.catchall {:try_start_54 .. :try_end_60} :catchall_6c
if-eqz p0, :cond_65
.line 77
:try_start_62
invoke-virtual {p0}, Ljava/io/InputStream;->close()V
:try_end_65
.catch Ljava/io/IOException; {:try_start_62 .. :try_end_65} :catch_65
:catch_65
:cond_65
return-object v0
:cond_66
if-eqz p0, :cond_77
:goto_68
:try_start_68
invoke-virtual {p0}, Ljava/io/InputStream;->close()V
:try_end_6b
.catch Ljava/io/IOException; {:try_start_68 .. :try_end_6b} :catch_77
goto :goto_77
:catchall_6c
move-exception v0
if-eqz p0, :cond_72
:try_start_6f
invoke-virtual {p0}, Ljava/io/InputStream;->close()V
:try_end_72
.catch Ljava/io/IOException; {:try_start_6f .. :try_end_72} :catch_72
.line 80
:catch_72
:cond_72
throw v0
:catch_73
nop
if-eqz p0, :cond_77
goto :goto_68
:catch_77
:cond_77
:goto_77
return-object v1
.end method
.method private static getVP8Dimension(Ljava/io/InputStream;)Landroid/util/Pair;
.registers 5
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/io/InputStream;",
")",
"Landroid/util/Pair<",
"Ljava/lang/Integer;",
"Ljava/lang/Integer;",
">;"
}
.end annotation
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
const-wide/16 v0, 0x7
.line 97
invoke-virtual {p0, v0, v1}, Ljava/io/InputStream;->skip(J)J
.line 99
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getShort(Ljava/io/InputStream;)S
move-result v0
.line 100
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getShort(Ljava/io/InputStream;)S
move-result v1
.line 101
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getShort(Ljava/io/InputStream;)S
move-result v2
const/16 v3, 0x9d
if-ne v0, v3, :cond_33
const/4 v0, 0x1
if-ne v1, v0, :cond_33
const/16 v0, 0x2a
if-eq v2, v0, :cond_1d
goto :goto_33
.line 107
:cond_1d
new-instance v0, Landroid/util/Pair;
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->get2BytesAsInt(Ljava/io/InputStream;)I
move-result v1
invoke-static {v1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object v1
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->get2BytesAsInt(Ljava/io/InputStream;)I
move-result p0
invoke-static {p0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object p0
invoke-direct {v0, v1, p0}, Landroid/util/Pair;-><init>(Ljava/lang/Object;Ljava/lang/Object;)V
return-object v0
:cond_33
:goto_33
const/4 p0, 0x0
return-object p0
.end method
.method private static getVP8LDimension(Ljava/io/InputStream;)Landroid/util/Pair;
.registers 5
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/io/InputStream;",
")",
"Landroid/util/Pair<",
"Ljava/lang/Integer;",
"Ljava/lang/Integer;",
">;"
}
.end annotation
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 120
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getInt(Ljava/io/InputStream;)I
.line 122
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getByte(Ljava/io/InputStream;)B
move-result v0
const/16 v1, 0x2f
if-eq v0, v1, :cond_d
const/4 p0, 0x0
return-object p0
.line 126
:cond_d
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result v0
int-to-byte v0, v0
and-int/lit16 v0, v0, 0xff
.line 127
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result v1
int-to-byte v1, v1
and-int/lit16 v1, v1, 0xff
.line 128
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result v2
int-to-byte v2, v2
and-int/lit16 v2, v2, 0xff
.line 129
invoke-virtual {p0}, Ljava/io/InputStream;->read()I
move-result p0
int-to-byte p0, p0
and-int/lit16 p0, p0, 0xff
and-int/lit8 v3, v1, 0x3f
shl-int/lit8 v3, v3, 0x8
or-int/2addr v0, v3
add-int/lit8 v0, v0, 0x1
and-int/lit8 p0, p0, 0xf
shl-int/lit8 p0, p0, 0xa
shl-int/lit8 v2, v2, 0x2
or-int/2addr p0, v2
and-int/lit16 v1, v1, 0xc0
shr-int/lit8 v1, v1, 0x6
or-int/2addr p0, v1
add-int/lit8 p0, p0, 0x1
.line 133
new-instance v1, Landroid/util/Pair;
invoke-static {v0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object v0
invoke-static {p0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object p0
invoke-direct {v1, v0, p0}, Landroid/util/Pair;-><init>(Ljava/lang/Object;Ljava/lang/Object;)V
return-object v1
.end method
.method private static getVP8XDimension(Ljava/io/InputStream;)Landroid/util/Pair;
.registers 3
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/io/InputStream;",
")",
"Landroid/util/Pair<",
"Ljava/lang/Integer;",
"Ljava/lang/Integer;",
">;"
}
.end annotation
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
const-wide/16 v0, 0x8
.line 145
invoke-virtual {p0, v0, v1}, Ljava/io/InputStream;->skip(J)J
.line 147
new-instance v0, Landroid/util/Pair;
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->read3Bytes(Ljava/io/InputStream;)I
move-result v1
add-int/lit8 v1, v1, 0x1
invoke-static {v1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object v1
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->read3Bytes(Ljava/io/InputStream;)I
move-result p0
add-int/lit8 p0, p0, 0x1
invoke-static {p0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object p0
invoke-direct {v0, v1, p0}, Landroid/util/Pair;-><init>(Ljava/lang/Object;Ljava/lang/Object;)V
return-object v0
.end method
.method private static isBitOne(BI)Z
.registers 2
.line 212
rem-int/lit8 p1, p1, 0x8
shr-int/2addr p0, p1
const/4 p1, 0x1
and-int/2addr p0, p1
if-ne p0, p1, :cond_8
return p1
:cond_8
const/4 p0, 0x0
return p0
.end method
.method private static read3Bytes(Ljava/io/InputStream;)I
.registers 4
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 195
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getByte(Ljava/io/InputStream;)B
move-result v0
.line 196
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getByte(Ljava/io/InputStream;)B
move-result v1
.line 197
invoke-static {p0}, Lcom/facebook/imageutils/WebpUtil;->getByte(Ljava/io/InputStream;)B
move-result p0
shl-int/lit8 p0, p0, 0x10
const/high16 v2, 0xff0000
and-int/2addr p0, v2
shl-int/lit8 v1, v1, 0x8
const v2, 0xff00
and-int/2addr v1, v2
or-int/2addr p0, v1
and-int/lit16 v0, v0, 0xff
or-int/2addr p0, v0
return p0
.end method